Proofs: Semi-persistent array
These are the human proofs of Semi-persistent array, at full length.
The semi-persistent array gives each valid version its contents full
This proof shows: correctness.
Setting. A state is a shared array of slots together with version records. The abstract model gives each version ever made a fixed sequence of values: the first version has the initial contents, and the version returned by SET has with slot set to . The state is good if there are versions such that:
- (I1) has kind arr, and each with has kind ;
- (I2) , and for , equals with slot set to ;
- (I3) every other version made so far has kind dead.
The valid versions are .
Lemma 1 (get). In a good state, GET returns slot of , and changes nothing.
Proof. GET visits in order. Let be the first index with and , if there is one. For , (I2) gives slot of equal to slot of , since . So slot of equals slot of , which is by (I2), and that is what line L4 returns. If there is no such , the same argument up to gives slot of , which line L6 returns. GET writes nothing.
Lemma 2 (reroot). In a good state, REROOT leaves a good state with valid versions .
Proof. Line L12 collects for with , by (I1). We claim that after line L13 has processed , the array is . Before the loop it is by (I2). The step for sets , which turns into by (I2). After the loop, . Line L14 marks dead, and line L15 makes of kind arr. Now (I1) holds for (the diffs of are untouched), (I2) holds because and the earlier diffs are unchanged, and (I3) holds because the versions removed from the path are dead.
Lemma 3 (set). In a good state, SET returns a new version with equal to with slot set to , and leaves a good state with valid versions .
Proof. By Lemma 2, after line L7 the state is good with newest and . Line L8 makes of kind arr. Line L9 sets to , with read before the write, and line L10 sets . Now , and equals with slot set to the old , which is (I2) for the pair . (I1) and (I3) are clear.
Theorem. After any sequence of operations, the state is good; each GET or TO-LIST on a valid version returns its contents in the model; each operation on a version that is not valid is rejected; and the contents of a valid version never change.
Proof. The first version alone is a good state with . By Lemmas 1 to 3 every operation keeps the state good and returns the right answer. TO-LIST copies and applies the diffs from back to , which yields by the argument of Lemma 2 applied to a copy. A version that is not valid has kind dead by (I3), and lines L1 and L11 reject it. Finally, of a version is fixed by the model, and the good state represents it exactly for each valid version, so a valid version is never seen to change.