Skip to content

Commit ec1db89

Browse files
Prove firstInteraction
1 parent 31f07b9 commit ec1db89

File tree

1 file changed

+16
-54
lines changed

1 file changed

+16
-54
lines changed

theories/DisjointSetUnionCode2.v

Lines changed: 16 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -397,16 +397,9 @@ Lemma mergingLogic (dsu : list Slot) (hL : length dsu = 100) (hL1 : Z.to_nat (ds
397397
(pathCompress dsu (length dsu) (Z.to_nat x)
398398
(ancestor dsu (length dsu) (Z.to_nat x)))
399399
(length dsu) (Z.to_nat y)
400-
(ancestor dsu (length dsu) (Z.to_nat y))) (Ancestor Unit) = Ancestor tree2) whatever whatever2 : invokeContractAux (repeat 1%Z 20) (repeat 0%Z 20) 0 state
400+
(ancestor dsu (length dsu) (Z.to_nat y))) (Ancestor Unit) = Ancestor tree2) whatever whatever2 ignored : invokeContractAux (repeat 1%Z 20) (repeat 0%Z 20) 0 state
401401
(stateAfterInteractions
402-
(λ _0 : arrayIndex0,
403-
match
404-
_0 as _1 return (list (arrayType arrayIndex0 environment0 _1))
405-
with
406-
| arraydef_0__dsu => convertToArray dsu
407-
| arraydef_0__hasBeenInitialized => [1%Z]
408-
| arraydef_0__result => [0%Z]
409-
end) (dsuScore dsu)) [x; y] 1 arrayIndex0
402+
ignored (dsuScore dsu)) [x; y] 1 arrayIndex0
410403
arrayIndexEqualityDecidable0 (arrayType arrayIndex0 environment0)
411404
(λ _0 : arrayIndex0,
412405
match
@@ -782,15 +775,7 @@ Proof.
782775
rewrite Z.mod_small; [| lia]. pose proof sumTwoAncestors dsu (ancestor dsu (length dsu) (Z.to_nat a)) (ancestor dsu (length dsu) (Z.to_nat b)) ltac:(assumption) ltac:(apply ancestorLtLength; (assumption || lia)) ltac:(apply ancestorLtLength; (assumption || lia)) a1 ltac:(assumption) a2 ltac:(assumption). lia. } rewrite solv. unfold donate. rewrite pushDispatch2 bindDispatch unfoldInvoke_S_Donate leftIdentity.
783776
assert (st2 : (getBalance
784777
(stateAfterInteractions
785-
(λ _0 : arrayIndex0,
786-
match
787-
_0 as _1
788-
return (list (arrayType arrayIndex0 environment0 _1))
789-
with
790-
| arraydef_0__dsu => convertToArray dsu
791-
| arraydef_0__hasBeenInitialized => [1]
792-
| arraydef_0__result => [0]
793-
end) (dsuScore dsu) (repeat 0 20)) = 100000 - dsuScore dsu)%Z).
778+
ignored (dsuScore dsu) (repeat 0 20)) = 100000 - dsuScore dsu)%Z).
794779
{ easy. } rewrite st2.
795780
pose proof performMergeScore (pathCompress
796781
(pathCompress dsu (length dsu)
@@ -872,23 +857,9 @@ Proof.
872857
rewrite hsimp. clear hsimp.
873858
assert (hsimp : transferMoney
874859
(stateAfterInteractions
875-
(λ _1 : arrayIndex0,
876-
match
877-
_1 as _2 return (list (arrayType arrayIndex0 environment0 _2))
878-
with
879-
| arraydef_0__dsu => convertToArray dsu
880-
| arraydef_0__hasBeenInitialized => [1%Z]
881-
| arraydef_0__result => [0%Z]
882-
end) (dsuScore dsu)) (repeat 0%Z 20) (repeat 1%Z 20)
860+
ignored (dsuScore dsu)) (repeat 0%Z 20) (repeat 1%Z 20)
883861
(Z.of_nat (leafCount a1) + Z.of_nat (leafCount a2)) = stateAfterInteractions
884-
(λ _1 : arrayIndex0,
885-
match
886-
_1 as _2 return (list (arrayType arrayIndex0 environment0 _2))
887-
with
888-
| arraydef_0__dsu => convertToArray dsu
889-
| arraydef_0__hasBeenInitialized => [1%Z]
890-
| arraydef_0__result => [0%Z]
891-
end) (dsuScore dsu + Z.of_nat (leafCount a1) + Z.of_nat (leafCount a2))).
862+
ignored (dsuScore dsu + Z.of_nat (leafCount a1) + Z.of_nat (leafCount a2))).
892863
{ apply functional_extensionality_dep. intro _1. unfold stateAfterInteractions. unfold transferMoney. unfold update.
893864
repeat case_decide; try (exfalso; easy); try reflexivity.
894865
{ subst _1. exfalso. easy. }
@@ -901,21 +872,8 @@ Proof.
901872
apply functional_extensionality_dep. intro ___1. unfold update. unfold stateAfterInteractions. repeat case_decide; easy.
902873
Qed.
903874

904-
Lemma runUnite (dsu : list Slot) (hL : length dsu = 100) (hL1 : Z.to_nat (dsuLeafCount dsu) = length dsu) (h1 : noIllegalIndices dsu) (h2 : withoutCyclesN dsu (length dsu)) (a b : Z) (hLe1 : Z.le 0 a) (hLt1 : Z.lt a 100) (hLe2 : Z.le 0 b) (hLt2 : Z.lt b 100) : invokeContractAux (repeat 1%Z 20) (repeat 0%Z 20) 0 state
905-
(stateAfterInteractions (λ _0 : arrayIndex0,
906-
match
907-
_0 as _1
908-
return
909-
(list
910-
(arrayType arrayIndex0
911-
environment0 _1))
912-
with
913-
| arraydef_0__dsu =>
914-
convertToArray dsu
915-
| arraydef_0__hasBeenInitialized =>
916-
[1%Z]
917-
| arraydef_0__result => [0%Z]
918-
end)
875+
Lemma runUnite (dsu : list Slot) (hL : length dsu = 100) (hL1 : Z.to_nat (dsuLeafCount dsu) = length dsu) (h1 : noIllegalIndices dsu) (h2 : withoutCyclesN dsu (length dsu)) (a b : Z) (hLe1 : Z.le 0 a) (hLt1 : Z.lt a 100) (hLe2 : Z.le 0 b) (hLt2 : Z.lt b 100) ignored : invokeContractAux (repeat 1%Z 20) (repeat 0%Z 20) 0 state
876+
(stateAfterInteractions ignored
919877
(dsuScore
920878
dsu)) [a; b] 1 arrayIndex0 arrayIndexEqualityDecidable0
921879
(arrayType arrayIndex0 environment0) (λ _0 : arrayIndex0,
@@ -1277,7 +1235,7 @@ Proof.
12771235
apply functional_extensionality_dep. intro x. unfold update. unfold stateAfterInteractions. repeat case_decide; easy.
12781236
Qed.
12791237

1280-
Lemma firstInteraction (a b : Z) (hLt1 : Z.lt a 100) (hLt2 : Z.lt b 100) : invokeContract (repeat 1%Z 20) (repeat 0%Z 20) 0%Z state state [a; b] 1 = Some ([a; b], stateAfterInteractions (fun x => match x with | arraydef_0__result => [0%Z] | arraydef_0__hasBeenInitialized => [1%Z] | arraydef_0__dsu => convertToArray (unite (repeat (Ancestor Unit) 100) (Z.to_nat a) (Z.to_nat b)) end) (dsuScore (unite (repeat (Ancestor Unit) 100) (Z.to_nat a) (Z.to_nat b)))).
1238+
Lemma firstInteraction (a b : Z) (hLe1 : Z.le 0 a) (hLt1 : Z.lt a 100) (hLe2 : Z.le 0 b) (hLt2 : Z.lt b 100) : invokeContract (repeat 1%Z 20) (repeat 0%Z 20) 0%Z state state [a; b] 1 = Some ([a; b], stateAfterInteractions (fun x => match x with | arraydef_0__result => [0%Z] | arraydef_0__hasBeenInitialized => [1%Z] | arraydef_0__dsu => convertToArray (unite (repeat (Ancestor Unit) 100) (Z.to_nat a) (Z.to_nat b)) end) (dsuScore (unite (repeat (Ancestor Unit) 100) (Z.to_nat a) (Z.to_nat b)))).
12811239
Proof.
12821240
unfold invokeContract. rewrite (ltac:(easy) : state (repeat 0%Z 20) = BlockchainContract _ _ _ _ _ _). unfold funcdef_0__main at 2. rewrite !leftIdentity. unfold retrieve at 1. rewrite <- !bindAssoc. pose proof pushDispatch2 (λ _ : varsfuncdef_0__main, false) (λ _ : varsfuncdef_0__main, 0%Z) (λ _ : varsfuncdef_0__main, repeat 0%Z 20) (Retrieve arrayIndex0 (arrayType arrayIndex0 environment0) arraydef_0__hasBeenInitialized 0) as step. autorewrite with combined_unfold in step. rewrite step. clear step. autorewrite with advance_program. case_decide as h; simpl in h; [| lia]. rewrite !leftIdentity. case_bool_decide as h1; cbv in h1; [| lia]. unfold store. pose proof pushDispatch2 (λ _ : varsfuncdef_0__main, false) (λ _ : varsfuncdef_0__main, 0%Z) (λ _ : varsfuncdef_0__main, repeat 0%Z 20) (Store arrayIndex0 (arrayType arrayIndex0 environment0) arraydef_0__hasBeenInitialized 0 (coerceInt 1 8)) as step. autorewrite with combined_unfold in *. rewrite <- !bindAssoc, step. clear step. autorewrite with advance_program. assert (hsimp : (λ _0 : arrayIndex0,
12831241
match
@@ -1329,10 +1287,14 @@ end) = fun (x : arrayIndex0) => match x with | arraydef_0__hasBeenInitialized =>
13291287
case_decide as hw; simpl in hw; [| lia]. rewrite hsimp. clear hsimp. pose proof (fun x => initializeArray a b 100 x ltac:(lia) (repeat 0%Z 100) ltac:(easy)) as step. rewrite step. clear step. rewrite (ltac:(lia) : 100 - 100 = 0). rewrite (ltac:(easy) : take 0 _ = []). rewrite app_nil_l. rewrite !leftIdentity. unfold readByte. pose proof pushDispatch2 (λ _ : varsfuncdef_0__main, false) (λ _ : varsfuncdef_0__main, 0%Z) (λ _ : varsfuncdef_0__main, repeat 0%Z 20) (DoBasicEffect arrayIndex0 (arrayType arrayIndex0 environment0)
13301288
(ReadByte 0)) as step. autorewrite with combined_unfold in step. rewrite step. clear step. autorewrite with advance_program. case_decide as h2; [| simpl in h2; lia]. pose proof pushDispatch2 (λ _ : varsfuncdef_0__main, false) (λ _ : varsfuncdef_0__main, 0%Z) (λ _ : varsfuncdef_0__main, repeat 0%Z 20) (DoBasicEffect arrayIndex0 (arrayType arrayIndex0 environment0) (ReadByte 1)) as step. autorewrite with combined_unfold in step. rewrite <- !bindAssoc, step. clear step. autorewrite with advance_program. rewrite !leftIdentity. rewrite (ltac:(easy) : (nth (Z.to_nat 0) [a; b] 0%Z) = a) (ltac:(easy) : (nth (Z.to_nat 1) [a; b] 0%Z) = b). rewrite (ltac:(apply functional_extensionality_dep; intro x; destruct x; easy) : (update (update (λ _ : varsfuncdef_0__unite, 0%Z) vardef_0__unite_u a) vardef_0__unite_v b) = fun x => match x with | vardef_0__unite_u => a | vardef_0__unite_v => b | _ => 0%Z end).
13311289
case_decide as h3; [| simpl in h3; lia].
1332-
Admitted.
1333-
1334-
Lemma maxScoreIsAttainable : interact state (map (fun x => (0%Z, Z.of_nat x)) (seq 1 99)) = 5049%Z.
1335-
Proof. reflexivity. Qed.
1290+
assert (hR : convertToArray (repeat (Ancestor Unit) 100) = repeat (255%Z) 100).
1291+
{ reflexivity. } rewrite -hR.
1292+
pose proof runUnite (ltac:(reflexivity) : length (repeat (Ancestor Unit) 100) = 100) ltac:(reflexivity) ltac:(intros x y z; rewrite nth_repeat in z; easy) ltac:(rewrite withoutCyclesNIffWithoutCyclesBool; easy) hLe1 hLt1 hLe2 hLt2 (arrays _ environment0) as step.
1293+
assert (hS : (stateAfterInteractions (arrays arrayIndex0 environment0)
1294+
(dsuScore (repeat (Ancestor Unit) 100))) = state).
1295+
{ apply functional_extensionality_dep. intro x. unfold stateAfterInteractions. unfold state. case_decide. { reflexivity. } case_decide. { reflexivity. } reflexivity. }
1296+
rewrite hS in step. rewrite step. reflexivity.
1297+
Qed.
13361298

13371299
Lemma interactEqualsModelScore (x : list (Z * Z)) : interact state x = modelScore x.
13381300
Proof.

0 commit comments

Comments
 (0)