From Stdlib Require Import Strings.String.
From Stdlib Require Import String Ascii.
From Stdlib Require Arith.
From stdpp Require Import base.
From stdpp Require Import fin_maps.
From stdpp Require Import gmap.
From stdpp Require Import base gmultiset.
From Stdlib Require Classical.
From Stdlib Require Import ZArith.
From stdpp.bitvector Require Import definitions tactics.
From Stdlib Require Import Sorting.Sorted.
From Stdlib Require Import Reals.Rbasic_fun.
From Stdlib Require Import Reals.Abstract.ConstructiveAbs.
From Stdlib Require Import Reals.Rdefinitions.
From stdpp Require Import list_relations.
From stdpp Require Import list_numbers.
From stdpp Require Import functions.
From Stdlib Require Import ClassicalEpsilon.
From stdpp Require Import base decidable.
From Stdlib Require Import ZArith.Zeuclid.
From Stdlib Require Import ZArith.Znumtheory.
From stdpp Require Import propset.
From Stdlib Require Import Reals.
Require Import Why3.Base.
Require Import imp.imp.Syntax.
Require Import imp.imp.ConcreteSemantics.
Require Import imp.imp.Svar.
Require Import imp.imp.Constraint.
Require Import imp.imp.SymState.
Require Import imp.imp.FreshSvar.
Require Import imp.imp.SymStateSet.
Open Scope Z_scope.
Axiom compose : (svar -> Z) -> t -> program_var -> option Z.
Axiom compose'def : forall  (rho : svar -> Z) (sigma : t) (x : program_var), compose rho sigma x = (match get sigma x with | Some v => Some (rho v) | None => None end).
Definition state_extends (s : sym_state) (s' : sym_state) := Svar.to_fset (vars s) ⊆ Svar.to_fset (vars s') ∧ (∀(v : svar), v ∈ Svar.to_fset (vars s) -> SymState.rho s v = SymState.rho s' v).
Axiom svar_set_add : svar -> Svar.set -> Svar.set.
Axiom svar_set_add'def : forall  (v : svar) (vs : Svar.set), Svar.to_fset (svar_set_add v vs) = insert_set v (Svar.to_fset vs) ∧ (if decide (v ∈ Svar.to_fset vs) then size (Svar.to_fset (svar_set_add v vs)) = size (Svar.to_fset vs) else Z.of_nat (size (Svar.to_fset (svar_set_add v vs))) = Z.of_nat (size (Svar.to_fset vs)) + 1%Z).
Definition results_extend (s : sym_state) (normals : gset sym_state) (unbounds : gset sym_state) (limits : gset sym_state) := ∀(s' : sym_state), s' ∈ normals ∨ s' ∈ unbounds ∨ s' ∈ limits -> state_extends s s'.
Theorem symbolic_interp_while'vc (ctr : Z) (n : Z) (s : sym_state) (e : expr) (c : cmd) (fact0 : 0%Z ≤ ctr) (fact1 : ctr ≤ n) : (¬ ctr = n -> (∀(sym_cond : symbolic_expr), eval_expr (compose (SymState.rho s) (sigma s)) e (Enormal (interp_symbolic_expr (SymState.rho s) sym_cond)) ∧ (∀(v : svar), v ∈ vars_in_symbolic_expr sym_cond -> (∃(x : program_var), get (sigma s) x = Some v)) -> (let o1 : Svar.set := vars s in let o2 : Constraint.constr := Cconj (SymState.constr s) (Cneq sym_cond (Slit 0%Z)) in let o3 : t := sigma s in (vars_in_constraint o2 ⊆ Svar.to_fset o1 ∧ (∀(x : program_var) (v : svar), get o3 x = Some v -> v ∈ Svar.to_fset o1)) ∧ (∀(s1 : sym_state), sigma s1 = o3 ∧ SymState.constr s1 = o2 ∧ SymState.rho s1 = SymState.rho s ∧ vars s1 = o1 -> (let o4 : Svar.set := vars s in let o5 : Constraint.constr := Cconj (SymState.constr s) (Ceq sym_cond (Slit 0%Z)) in let o6 : t := sigma s in (vars_in_constraint o5 ⊆ Svar.to_fset o4 ∧ (∀(x : program_var) (v : svar), get o6 x = Some v -> v ∈ Svar.to_fset o4)) ∧ (∀(s2 : sym_state), sigma s2 = o6 ∧ SymState.constr s2 = o5 ∧ SymState.rho s2 = SymState.rho s ∧ vars s2 = o4 -> (true = false -> (∀(rho : svar -> Z), ¬ is_solution rho (SymState.constr s1))) -> 0%Z ≤ n ∧ (∀(normals1 : SymStateSet.set) (unbounds1 : SymStateSet.set) (limits1 : SymStateSet.set), results_extend s1 (SymStateSet.to_fset normals1) (SymStateSet.to_fset unbounds1) (SymStateSet.to_fset limits1) ∧ (is_solution (SymState.rho s1) (SymState.constr s1) -> (∀(gamma' : program_var -> option Z) (bhv : behavior), exec_cmd (mk_loop_cnf n) (compose (SymState.rho s1) (sigma s1)) c gamma' bhv -> (∃(s' : sym_state), (match bhv with | Cnormal => s' ∈ SymStateSet.to_fset normals1 | Cunbound_var => s' ∈ SymStateSet.to_fset unbounds1 | Cloop_limit => s' ∈ SymStateSet.to_fset limits1 end) ∧ is_solution (SymState.rho s') (SymState.constr s') ∧ gamma' = compose (SymState.rho s') (sigma s')))) ∧ (∀(bhv : behavior) (s' : sym_state), (match bhv with | Cnormal => s' ∈ SymStateSet.to_fset normals1 | Cunbound_var => s' ∈ SymStateSet.to_fset unbounds1 | Cloop_limit => s' ∈ SymStateSet.to_fset limits1 end) -> is_solution (SymState.rho s') (SymState.constr s') -> is_solution (SymState.rho s1) (SymState.constr s1) ∧ exec_cmd (mk_loop_cnf n) (compose (SymState.rho s1) (sigma s1)) c (compose (SymState.rho s') (sigma s')) bhv) -> (let o7 : list sym_state := to_list normals1 in (∀(e1 : sym_state), (e1 ∈ SymStateSet.to_fset normals1) = (e1 ∈ o7)) -> (let o8 : Z := ctr + 1%Z in (0%Z ≤ n - ctr ∧ n - o8 < n - ctr ∨ n - ctr = n - o8 ∧ 0%Z ≤ 0%Z ∧ Z.of_nat (length o7) < 0%Z) ∧ 0%Z ≤ o8 ∧ o8 ≤ n))))))))) ∧ (∀(normals : SymStateSet.set) (unbounds : SymStateSet.set) (limits : SymStateSet.set), (if decide (ctr = n) then (SymStateSet.to_fset limits = ({[s]} : gset _) ∧ Z.of_nat (size (SymStateSet.to_fset limits)) = 1%Z) ∧ (SymStateSet.to_fset unbounds = (∅ : gset sym_state) ∧ Z.of_nat (size (SymStateSet.to_fset unbounds)) = 0%Z) ∧ SymStateSet.to_fset normals = (∅ : gset sym_state) ∧ Z.of_nat (size (SymStateSet.to_fset normals)) = 0%Z else (∃(sym_cond : symbolic_expr), (eval_expr (compose (SymState.rho s) (sigma s)) e (Enormal (interp_symbolic_expr (SymState.rho s) sym_cond)) ∧ (∀(v : svar), v ∈ vars_in_symbolic_expr sym_cond -> (∃(x : program_var), get (sigma s) x = Some v))) ∧ (∃(s1 : sym_state), (sigma s1 = sigma s ∧ SymState.constr s1 = Cconj (SymState.constr s) (Cneq sym_cond (Slit 0%Z)) ∧ SymState.rho s1 = SymState.rho s ∧ vars s1 = vars s) ∧ (∃(s2 : sym_state), (sigma s2 = sigma s ∧ SymState.constr s2 = Cconj (SymState.constr s) (Ceq sym_cond (Slit 0%Z)) ∧ SymState.rho s2 = SymState.rho s ∧ vars s2 = vars s) ∧ (∃(normals1 : SymStateSet.set) (unbounds1 : SymStateSet.set) (limits1 : SymStateSet.set), (∃(o1 : bool), (o1 = false -> (∀(rho : svar -> Z), ¬ is_solution rho (SymState.constr s1))) ∧ (if decide (o1 = true) then ∃(normals2 : SymStateSet.set) (unbounds2 : SymStateSet.set) (limits2 : SymStateSet.set), (results_extend s1 (SymStateSet.to_fset normals2) (SymStateSet.to_fset unbounds2) (SymStateSet.to_fset limits2) ∧ (is_solution (SymState.rho s1) (SymState.constr s1) -> (∀(gamma' : program_var -> option Z) (bhv : behavior), exec_cmd (mk_loop_cnf n) (compose (SymState.rho s1) (sigma s1)) c gamma' bhv -> (∃(s' : sym_state), (match bhv with | Cnormal => s' ∈ SymStateSet.to_fset normals2 | Cunbound_var => s' ∈ SymStateSet.to_fset unbounds2 | Cloop_limit => s' ∈ SymStateSet.to_fset limits2 end) ∧ is_solution (SymState.rho s') (SymState.constr s') ∧ gamma' = compose (SymState.rho s') (sigma s')))) ∧ (∀(bhv : behavior) (s' : sym_state), (match bhv with | Cnormal => s' ∈ SymStateSet.to_fset normals2 | Cunbound_var => s' ∈ SymStateSet.to_fset unbounds2 | Cloop_limit => s' ∈ SymStateSet.to_fset limits2 end) -> is_solution (SymState.rho s') (SymState.constr s') -> is_solution (SymState.rho s1) (SymState.constr s1) ∧ exec_cmd (mk_loop_cnf n) (compose (SymState.rho s1) (sigma s1)) c (compose (SymState.rho s') (sigma s')) bhv)) ∧ (let o2 : list sym_state := to_list normals2 in (∀(e1 : sym_state), (e1 ∈ SymStateSet.to_fset normals2) = (e1 ∈ o2)) ∧ (let o3 : Z := ctr + 1%Z in ∃(unbounds3 : SymStateSet.set) (limits3 : SymStateSet.set), ((∀(s' : sym_state), s' ∈ SymStateSet.to_fset normals1 ∨ s' ∈ SymStateSet.to_fset unbounds3 ∨ s' ∈ SymStateSet.to_fset limits3 -> (∃(s3 : sym_state), s3 ∈ SymStateSet.to_fset (of_list o2) ∧ state_extends s3 s')) ∧ (∀(s3 : sym_state), s3 ∈ SymStateSet.to_fset (of_list o2) -> is_solution (SymState.rho s3) (SymState.constr s3) -> (∀(gamma' : program_var -> option Z) (bhv : behavior), exec_while (mk_loop_cnf n) o3 (compose (SymState.rho s3) (sigma s3)) e c gamma' bhv -> (∃(s' : sym_state), (match bhv with | Cnormal => s' ∈ SymStateSet.to_fset normals1 | Cunbound_var => s' ∈ SymStateSet.to_fset unbounds3 | Cloop_limit => s' ∈ SymStateSet.to_fset limits3 end) ∧ is_solution (SymState.rho s') (SymState.constr s') ∧ gamma' = compose (SymState.rho s') (sigma s')))) ∧ (∀(bhv : behavior) (s' : sym_state), (match bhv with | Cnormal => s' ∈ SymStateSet.to_fset normals1 | Cunbound_var => s' ∈ SymStateSet.to_fset unbounds3 | Cloop_limit => s' ∈ SymStateSet.to_fset limits3 end) -> is_solution (SymState.rho s') (SymState.constr s') -> (∃(s3 : sym_state), s3 ∈ SymStateSet.to_fset (of_list o2) ∧ is_solution (SymState.rho s3) (SymState.constr s3) ∧ exec_while (mk_loop_cnf n) o3 (compose (SymState.rho s3) (sigma s3)) e c (compose (SymState.rho s') (sigma s')) bhv))) ∧ SymStateSet.to_fset limits1 = SymStateSet.to_fset limits2 ∪ SymStateSet.to_fset limits3 ∧ SymStateSet.to_fset unbounds1 = SymStateSet.to_fset unbounds2 ∪ SymStateSet.to_fset unbounds3)) else (SymStateSet.to_fset limits1 = (∅ : gset sym_state) ∧ Z.of_nat (size (SymStateSet.to_fset limits1)) = 0%Z) ∧ (SymStateSet.to_fset unbounds1 = (∅ : gset sym_state) ∧ Z.of_nat (size (SymStateSet.to_fset unbounds1)) = 0%Z) ∧ SymStateSet.to_fset normals1 = (∅ : gset sym_state) ∧ Z.of_nat (size (SymStateSet.to_fset normals1)) = 0%Z)) ∧ (∃(normals2 : SymStateSet.set) (unbounds2 : SymStateSet.set) (limits2 : SymStateSet.set), (∃(o1 : bool), (o1 = false -> (∀(rho : svar -> Z), ¬ is_solution rho (SymState.constr s2))) ∧ (if decide (o1 = true) then (SymStateSet.to_fset limits2 = (∅ : gset sym_state) ∧ Z.of_nat (size (SymStateSet.to_fset limits2)) = 0%Z) ∧ (SymStateSet.to_fset unbounds2 = (∅ : gset sym_state) ∧ Z.of_nat (size (SymStateSet.to_fset unbounds2)) = 0%Z) ∧ SymStateSet.to_fset normals2 = ({[s2]} : gset _) ∧ Z.of_nat (size (SymStateSet.to_fset normals2)) = 1%Z else (SymStateSet.to_fset limits2 = (∅ : gset sym_state) ∧ Z.of_nat (size (SymStateSet.to_fset limits2)) = 0%Z) ∧ (SymStateSet.to_fset unbounds2 = (∅ : gset sym_state) ∧ Z.of_nat (size (SymStateSet.to_fset unbounds2)) = 0%Z) ∧ SymStateSet.to_fset normals2 = (∅ : gset sym_state) ∧ Z.of_nat (size (SymStateSet.to_fset normals2)) = 0%Z)) ∧ SymStateSet.to_fset limits = SymStateSet.to_fset limits1 ∪ SymStateSet.to_fset limits2 ∧ SymStateSet.to_fset unbounds = SymStateSet.to_fset unbounds1 ∪ SymStateSet.to_fset unbounds2 ∧ SymStateSet.to_fset normals = SymStateSet.to_fset normals1 ∪ SymStateSet.to_fset normals2))))) ∨ eval_expr (compose (SymState.rho s) (sigma s)) e Eunbound_var ∧ (SymStateSet.to_fset limits = (∅ : gset sym_state) ∧ Z.of_nat (size (SymStateSet.to_fset limits)) = 0%Z) ∧ (SymStateSet.to_fset unbounds = ({[s]} : gset _) ∧ Z.of_nat (size (SymStateSet.to_fset unbounds)) = 1%Z) ∧ SymStateSet.to_fset normals = (∅ : gset sym_state) ∧ Z.of_nat (size (SymStateSet.to_fset normals)) = 0%Z) -> results_extend s (SymStateSet.to_fset normals) (SymStateSet.to_fset unbounds) (SymStateSet.to_fset limits) ∧ (is_solution (SymState.rho s) (SymState.constr s) -> (∀(gamma' : program_var -> option Z) (bhv : behavior), exec_while (mk_loop_cnf n) ctr (compose (SymState.rho s) (sigma s)) e c gamma' bhv -> (∃(s' : sym_state), (match bhv with | Cnormal => s' ∈ SymStateSet.to_fset normals | Cunbound_var => s' ∈ SymStateSet.to_fset unbounds | Cloop_limit => s' ∈ SymStateSet.to_fset limits end) ∧ is_solution (SymState.rho s') (SymState.constr s') ∧ gamma' = compose (SymState.rho s') (sigma s')))) ∧ (∀(bhv : behavior) (s' : sym_state), (match bhv with | Cnormal => s' ∈ SymStateSet.to_fset normals | Cunbound_var => s' ∈ SymStateSet.to_fset unbounds | Cloop_limit => s' ∈ SymStateSet.to_fset limits end) -> is_solution (SymState.rho s') (SymState.constr s') -> is_solution (SymState.rho s) (SymState.constr s) ∧ exec_while (mk_loop_cnf n) ctr (compose (SymState.rho s) (sigma s)) e c (compose (SymState.rho s') (sigma s')) bhv)).
Admitted.
