diff --git a/CoqOfRust/examples/default/examples/custom/links/loops_free.v b/CoqOfRust/examples/default/examples/custom/links/loops_free.v new file mode 100644 index 000000000..428bdf823 --- /dev/null +++ b/CoqOfRust/examples/default/examples/custom/links/loops_free.v @@ -0,0 +1,46 @@ +Require Import CoqOfRust.CoqOfRust. +Require Import CoqOfRust.links.M. +Require Import examples.default.examples.custom.loops_free. + +Instance run_max2 (a b : U32.t) : Run.Trait max2 [] [] [φ a; φ b] U32.t. +Proof. + constructor. + run_symbolic. +Defined. + +Instance run_abs_i32 (x : I32.t) : Run.Trait abs_i32 [] [] [φ x] I32.t. +Proof. + constructor. + run_symbolic. +Defined. + +Instance run_bool_and (a b : Bool.t) : Run.Trait bool_and [] [] [φ a; φ b] Bool.t. +Proof. + constructor. + run_symbolic. +Defined. + +Instance run_get_or_zero (xs : Array.t U32.t 4) (i : Usize.t) : + Run.Trait get_or_zero [] [] [φ xs; φ i] U32.t. +Proof. + constructor. + run_symbolic. +Defined. + +Instance run_eq2 (a b : Array.t U32.t 2) : Run.Trait eq2 [] [] [φ a; φ b] Bool.t. +Proof. + constructor. + run_symbolic. +Defined. + +Instance run_eq_pair (x y : Prod.t U32.t U32.t) : Run.Trait eq_pair [] [] [φ x; φ y] Bool.t. +Proof. + constructor. + run_symbolic. +Defined. + +Instance run_min3 (a b c : U32.t) : Run.Trait min3 [] [] [φ a; φ b; φ c] U32.t. +Proof. + constructor. + run_symbolic. +Defined. diff --git a/CoqOfRust/examples/default/examples/custom/simulate/loops_free.v b/CoqOfRust/examples/default/examples/custom/simulate/loops_free.v new file mode 100644 index 000000000..1876c83e5 --- /dev/null +++ b/CoqOfRust/examples/default/examples/custom/simulate/loops_free.v @@ -0,0 +1,244 @@ +Require Import CoqOfRust.CoqOfRust. +Require Import CoqOfRust.links.M. +Require Import CoqOfRust.simulate.M. +Require Import core.links.array. +Require Import examples.default.examples.custom.links.loops_free. + +Definition max2 (a b : U32.t) : U32.t := + if a.(Integer.value) + if i =? 0 then + x0 + else if i =? 1 then + x1 + else if i =? 2 then + x2 + else if i =? 3 then + x3 + else + {| Integer.value := 0 |} + end. + +Lemma get_or_zero_eq + (xs : array.t U32.t {| Integer.value := 4 |}) (i : Usize.t) + (H_i : 0 <= i.(Integer.value)) : + let ref_xs := make_ref 0 in + let stack := (xs, tt) in + {{ + SimulateM.eval_f (Stack := [_]) (run_get_or_zero ref_xs i) stack 🌲 + (Output.Success (get_or_zero xs i), stack) + }}. +Proof. + destruct xs as [[x0 [x1 [x2 [x3 []]]]]]. + destruct i as [i]; cbn in H_i. + unfold get_or_zero; cbn. + eapply Run.Call; cbn. { + apply Run.Pure. + } + cbn. + eapply Run.Call; cbn. { + apply Run.Pure. + } + cbn. + destruct (_