23.11.2013 Views

Obfuscation of Abstract Data-Types - Rowan

Obfuscation of Abstract Data-Types - Rowan

Obfuscation of Abstract Data-Types - Rowan

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

CHAPTER 4. SPLITTING HEADACHES 88<br />

We can define a split function as follows:<br />

split B k [ ] = 〈k, [ ], [ ]〉 B<br />

split B 0 (x : xs) = 〈0, [ ],x : xs〉 B<br />

split B (k + 1) (x : xs) = 〈k + 1,x : l,r〉 B<br />

where 〈m,l,r〉 B = split B k xs<br />

The unsplitting function is the same as the k-block split:<br />

unsplit B 〈n,l,r〉 B = l + r<br />

The representation xs ❀ 〈n,l,r〉 B satisfies the invariant<br />

dti ≡ (|r| = 0 ∧ |l| < n) ∨ (|l| = n) (4.27)<br />

By storing the decision value, we will see that the operations that we define<br />

can use this value. Hence, we can choose the decision value randomly and so<br />

on different execution runs, the same list could be split differently. Also, when<br />

performing operation on this split, we can change the decision value as well the<br />

lists themselves.<br />

For instance, we can define a cons operation as follows:<br />

cons ∣ B a 〈k,l,r〉 B<br />

∣ |l| < k = 〈k,a : l,r〉 B<br />

otherwise = 〈k + 1,a : l,r〉 B<br />

The definition for the k-block split required keeping the length <strong>of</strong> the first list<br />

component the same and so the last <strong>of</strong> element <strong>of</strong> the first list was added to<br />

the front <strong>of</strong> the second list. The version <strong>of</strong> cons for the augmented block split is<br />

more efficient as we merely increase the decision value by one. However cons B<br />

cannot be used to build up split lists starting from an empty split list as the list<br />

r will remain empty.<br />

The straightforward list operations are defined as follows:<br />

|〈k,l,r〉 B | B<br />

= |l| + |r|<br />

null B 〈k,l,r〉 B = null l ∧ null r<br />

elem B a 〈k,l,r〉 B = elem a l ∨ elem a r<br />

{ head r if k = 0<br />

head B 〈k,l,r〉 B =<br />

head l otherwise<br />

{<br />

〈k,l, tail r〉B if k = 0<br />

tail B 〈k,l,r〉 B =<br />

〈k − 1, tail l,r〉 B otherwise<br />

map B f 〈k,l,r〉 B = 〈k, map f l, map f r〉 B<br />

All these definitions, with the exception <strong>of</strong> tail, match the definitions for the<br />

k-block split. The definition <strong>of</strong> tail is more efficient as we just decrease the<br />

decision value instead <strong>of</strong> joining the head <strong>of</strong> the second component to the end<br />

<strong>of</strong> the first component.<br />

Here is a possible definition for a concatenation operation:<br />

〈k, [ ], [ ]〉 B + B 〈k ′ ,l ′ ,r ′ 〉 B = 〈k ′ ,l ′ ,r ′ 〉 B<br />

〈k,l,r〉 B + B 〈k ′ ,l ′ ,r ′ 〉 B = 〈|l + r|,l + r,l ′ + r ′ 〉 B

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!