id
int64
1
500
thm_name
stringlengths
5
86
thm_stmt
stringlengths
30
2.63k
lean_root
stringclasses
23 values
rel_path
stringlengths
13
61
imports
listlengths
0
35
used_lib_defs
listlengths
1
144
used_repo_defs
listlengths
1
251
lib_lemmas
listlengths
1
172
repo_lemmas
listlengths
1
148
used_local_defs
listlengths
0
85
used_local_lemmas
listlengths
0
57
local_ctx
stringlengths
35
30.7k
target_theorem
stringlengths
33
1.57k
ground_truth_proof
stringlengths
6
26.5k
nesting_depth
int64
1
27
transitive_dep_count
int64
1
480
subset_aristotle
bool
2 classes
category
stringclasses
5 values
401
evalExact_frame
lemma evalExact_frame (h1 h2 : state) t (Q : val β†’ hProp) : evalExact h1 t (ofhProp Q) β†’ Finmap.Disjoint h1 h2 β†’ evalExact (h1 βˆͺ h2) t (Q βˆ— (tohProp (fun h ↦ h = h2)))
splean
SPLean/Theories/SepLog.lean
[ "import SPLean.Theories.Lang", "import Mathlib.Data.Multiset.Nodup", "import SPLean.Theories.XSimp", "import Mathlib.Data.Finset.Basic", "import Mathlib.Data.Finmap", "import SPLean.Common.State", "import SPLean.Theories.HProp", "import SPLean.Common.Util" ]
[ { "name": "String", "module": "Init.Prelude" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "Finmap", "module": "Mathlib.Data.Finmap" }, { "name": "List", "module": "Init.Prelude" }, { "name": "Finmap.singleton", "module": "Mathlib.Data.Finmap" }, { "name": "Int.natAbs", "module": "Init.Data.Int.Basic" }, { "name": "Finmap.lookup", "module": "Mathlib.Data.Finmap" }, { "name": "Finmap.Disjoint", "module": "Mathlib.Data.Finmap" }, { "name": "seq", "module": "Talk.DemoLeanSSR" }, { "name": "t", "module": "Ssreflect.IntroPats" }, { "name": "elim", "module": "Ssreflect.Elim" }, { "name": "move", "module": "Ssreflect.Basic" }, { "name": "propext", "module": "Init.Core" }, { "name": "sby", "module": "Ssreflect.Done" }, { "name": "scase", "module": "Ssreflect.Elim" }, { "name": "sdone", "module": "Ssreflect.Done" }, { "name": "srw", "module": "Ssreflect.Rewrite" }, { "name": "Iff", "module": "Init.Core" }, { "name": "Finmap.insert", "module": "Mathlib.Data.Finmap" } ]
[ { "name": "syntax \"fun\" ident+ \" => \" lang : lang", "content": "syntax \"fun\" ident+ \" => \" lang : lang\n\nsyntax \"if \" lang \"then \" lang \"end \" : lang\n\nsyntax \" <= \" : bop\n\nsyntax \" >= \" : bop\n\nsyntax \"not\" : uop\n\nsyntax \" := \" : bop\n\nsyntax \"let\" ident \" := \" lang \" in\" ppDedent(ppLine lang) : lang\n\nsyntax \"ref\" ident \" := \" lang \" in\" ppDedent(ppLine lang) : lang\n\nsyntax \"fix\" ident ident+ \" => \" lang : lang\n\nsyntax \"for\" ident \" in \" \"[\" lang \" : \" lang \"]\" \" {\" (ppLine lang) ( \" }\") : lang\n\nsyntax \"while\" lang \" {\" (ppLine lang) ( \" }\") : lang\n\nsyntax \"alloc\" lang \" as \" ident \" in\" ppDedent(ppLine lang) : lang\n\nsyntax \"⟨\" term \"⟩\" : lang\n\nsyntax \"⟨\" term \":\" term \"⟩\" : lang" }, { "name": "macro_rules", "content": "macro_rules\n | `([lang| ()]) => `(trm_val (val_unit))\n | `([lang| $n:num]) => `(trm_val (val_int $n))\n | `([lang| $t1 $t2]) => `(trm_app [lang| $t1] [lang| $t2])\n | `([lang| if $t1 then $t2 else $t3]) => `(trm_if [lang| $t1] [lang| $t2] [lang| $t3])\n | `([lang| if $t1 then $t2 end]) => `(trm_if [lang| $t1] [lang| $t2] (trm_val val_unit))\n | `([lang| let $x := $t1:lang in $t2:lang]) =>\n `(trm_let $(%x) [lang| $t1] [lang| $t2])\n | `([lang| ref $x := $t1:lang in $t2:lang]) =>\n `(trm_ref $(%x) [lang| $t1] [lang| $t2])\n | `([lang| alloc $t1:lang as $x in $t2:lang]) =>\n `(trm_alloc $(%x) [lang| $t1] [lang| $t2])\n | `([lang| $t1 ; $t2]) => `(trm_seq [lang| $t1] [lang| $t2])\n | `([lang| fun_ $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(trm_funs [ $xs,* ] [lang| $t])\n | `([lang| fun $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(val_funs [ $xs,* ] [lang| $t])\n | `([lang| fix_ $f $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(trm_fixs $(%f) [ $xs,* ] [lang| $t])\n | `([lang| fix $f $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(val_fixs $(%f) [ $xs,* ] [lang| $t])\n \n | `([lang| free $t]) => `(trm_val (val_prim val_free) [lang| $t])\n | `([lang| not $t]) => `(trm_val (val_prim val_not) [lang| $t])\n \n | `([lang| !$t]) => `(trm_val val_get [lang| $t])\n | `([lang| $t1 := $t2]) => `(trm_val val_set [lang| $t1] [lang| $t2])\n | `([lang| $t1 + $t2]) => `(trm_val val_add [lang| $t1] [lang| $t2])\n | `([lang| $t1 * $t2]) => `(trm_val val_mul [lang| $t1] [lang| $t2])\n | `([lang| $t1 - $t2]) => `(trm_val val_sub [lang| $t1] [lang| $t2])\n | `([lang| $t1 / $t2]) => `(trm_val val_div [lang| $t1] [lang| $t2])\n | `([lang| $t1 < $t2]) => `(trm_val val_lt [lang| $t1] [lang| $t2])\n | `([lang| $t1 > $t2]) => `(trm_val val_gt [lang| $t1] [lang| $t2])\n | `([lang| $t1 <= $t2]) => `(trm_val val_le [lang| $t1] [lang| $t2])\n | `([lang| $t1 >= $t2]) => `(trm_val val_ge [lang| $t1] [lang| $t2])\n | `([lang| -$t]) => `(trm_val val_opp [lang| $t])\n | `([lang| $t1 = $t2]) => `(trm_val val_eq [lang| $t1] [lang| $t2])\n | `([lang| $t1 != $t2]) => `(trm_val val_neq [lang| $t1] [lang| $t2])\n | `([lang| $t1 mod $t2]) => `(trm_val val_mod [lang| $t1] [lang| $t2])\n | `([lang| $t1 ++ $t2]) => `(trm_val val_ptr_add [lang| $t1] [lang| $t2])\n | `([lang| ($t)]) => `([lang| $t])\n | `([lang| ⟨$t : $tp⟩]) => `(trm_val (($t : $tp)))\n | `([lang| for $x in [$n1 : $n2] { $t } ]) =>\n `(trm_for $(%x) [lang| $n1] [lang| $n2] [lang| $t])\n | `([lang| while $c:lang { $t:lang } ]) =>\n `(trm_while [lang| $c] [lang| $t] )" }, { "name": "macro_rules", "content": "macro_rules\n | `([lang| len $p]) => `(trm_val val_array_length [lang| $p])\n | `([lang| $arr[$i] ]) => `(trm_val val_array_get [lang| $arr] [lang| $i])\n \n | `([lang| $arr[$i] := $v]) => `(trm_app val_array_set [lang| $arr] [lang| $i] [lang| $v])\n | `([lang| mkarr $n:lang $v:lang]) => `(trm_val val_array_make [lang| $n] [lang| $v])" }, { "name": "heap", "content": "abbrev heap := Heap.heap val\n\n inductive val : Type where\n | val_unit : val\n | val_bool : Bool β†’ val\n | val_int : Int β†’ val\n | val_real : ℝ β†’ val\n | val_loc : loc β†’ val\n | val_prim : prim β†’ val\n | val_fun : var -> trm -> val\n | val_fix : var -> var -> trm -> val\n | val_uninit : val\n | val_error : val" }, { "name": "prim", "content": "inductive prim where\n \n | val_get : prim\n | val_set : prim\n \n | val_neg : prim\n | val_opp : prim\n | val_eq : prim\n | val_add : prim\n | val_neq : prim\n | val_sub : prim\n | val_mul : prim\n | val_div : prim\n | val_mod : prim\n \n | val_le : prim\n | val_lt : prim\n | val_ge : prim\n | val_gt : prim\n | val_ptr_add : prim\n\n inductive trm : Type where\n | trm_val : val -> trm\n | trm_var : var -> trm\n | trm_fun : var -> trm -> trm\n | trm_fix : var -> var -> trm -> trm\n | trm_app : trm -> trm -> trm\n | trm_seq : trm -> trm -> trm\n | trm_let : var -> trm -> trm -> trm\n | trm_if : trm -> trm -> trm -> trm\n | trm_for : var -> trm -> trm -> trm -> trm\n | trm_while : trm -> trm -> trm\n | trm_ref : var β†’ trm β†’ trm β†’ trm\n | trm_alloc : var β†’ trm β†’ trm β†’ trm" }, { "name": "var", "content": "abbrev var := String" }, { "name": "loc", "content": "abbrev loc := Nat" }, { "name": "Heap.heap", "content": "abbrev Heap.heap (val : Type) := Finmap (Ξ» _ : loc ↦ val)" }, { "name": "hProp", "content": "def hProp := heap -> Prop" }, { "name": "state", "content": "abbrev state := Finmap (Ξ» _ : loc ↦ val)" }, { "name": "HStar", "content": "class HStar (Ξ± : Type u) (Ξ² : Type v) (Ξ³ : outParam (Type w)) where\n \n hStar : Ξ± β†’ Ξ² β†’ Ξ³" }, { "name": "evalExact", "content": "inductive evalExact : state β†’ trm β†’ (val β†’ state β†’ Prop) -> Prop where\n | val : forall s v,\n evalExact s (trm_val v) (fun v' s' ↦ v' = v ∧ s' = s)\n | fun : forall s x t1,\n evalExact s (trm_fun x t1) (fun v' s' ↦ v' = val_fun x t1 ∧ s' = s)\n | fix : forall s f x t1,\n evalExact s (trm_fix f x t1) (fun v' s' ↦ v' = val_fix f x t1 ∧ s' = s)\n | app_arg1 : forall s1 t1 t2 Q1 Q,\n Β¬ trm_is_val t1 ->\n evalExact s1 t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 (trm_app v1 t2) Q) ->\n evalExact s1 (trm_app t1 t2) Q\n | app_arg2 : forall s1 (v1 : val) t2 Q1 Q,\n Β¬ trm_is_val t2 ->\n evalExact s1 t2 Q1 ->\n (forall v2 s2, Q1 v2 s2 -> evalExact s2 (trm_app v1 v2) Q) ->\n evalExact s1 (trm_app v1 t2) Q\n | app_fun : forall s1 v1 (v2 :val) x t1 Q,\n v1 = val_fun x t1 ->\n evalExact s1 (subst x v2 t1) Q ->\n evalExact s1 (trm_app v1 v2) Q\n | app_fix : forall s (v1 v2 : val) f x t1 Q,\n v1 = val_fix f x t1 ->\n evalExact s (subst x v2 (subst f v1 t1)) Q ->\n evalExact s (trm_app v1 v2) Q\n | seq : forall Q1 s t1 t2 Q,\n evalExact s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 t2 Q) ->\n evalExact s (trm_seq t1 t2) Q\n | let : forall Q1 s x t1 t2 Q,\n evalExact s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 (subst x v1 t2) Q) ->\n evalExact s (trm_let x t1 t2) Q\n | if : forall s (b : Bool) t1 t2 Q,\n evalExact s (if b then t1 else t2) Q ->\n evalExact s (trm_if (val_bool b) t1 t2) Q\n | unop : forall op s v1 P,\n evalunop op v1 P ->\n evalExact s (trm_app op v1) (purepost s P)\n | binop : forall op s (v1 v2 : val) P,\n evalbinop op v1 v2 P ->\n evalExact s (trm_app (trm_app op v1) v2) (purepost s P)\n | ref : forall s x t1 t2 Q Q₁,\n evalExact s t1 Q₁ β†’\n (βˆ€ v1 s1, Q₁ v1 s1 β†’ βˆ€ p βˆ‰ s1,\n evalExact (s1.insert p v1) (subst x p t2) fun v s ↦ Q v (s.erase p)) β†’\n evalExact s (trm_ref x t1 t2) Q\n | get : forall s p,\n p ∈ s ->\n evalExact s (trm_app val_get (val_loc p))\n (fun v' s' ↦ v' = read_state p s ∧ s' = s)\n | set : forall s p v,\n v = trm_val v' ->\n p ∈ s ->\n evalExact s (trm_app (trm_app val_set (val_loc p)) v)\n (fun v'' s' ↦ v'' = val_unit ∧ s' = s.insert p v')\n | alloc_arg : forall s Q₁ Q,\n Β¬ trm_is_val t1 β†’\n evalExact s t1 Q₁ β†’\n (βˆ€ v' s', Q₁ v' s' β†’ evalExact s' (trm_alloc x v' t2) Q) β†’\n evalExact s (trm_alloc x t1 t2) Q\n | alloc : forall (sa : state) (n : β„€) Q,\n n β‰₯ 0 β†’\n (βˆ€ (p : loc) (sb : state),\n sb = conseq (make_list n.natAbs val_uninit) p β†’\n p β‰  null β†’\n Finmap.Disjoint sa sb β†’\n evalExact (sb βˆͺ sa) (subst x p t2) fun v s ↦ Q v (s \\ sb)) β†’\n evalExact sa (trm_alloc x n t2) Q\n \n \n \n \n \n \n | for (n₁ nβ‚‚ : Int) (Q : val -> state -> Prop) :\n evalExact s (if (n₁ < nβ‚‚) then\n (trm_seq (subst x n₁ t₁) (trm_for x (val_int (n₁ + 1)) nβ‚‚ t₁))\n else val_unit) Q ->\n evalExact s (trm_for x n₁ nβ‚‚ t₁) Q\n | while (t₁ tβ‚‚ : trm) (Q Q₁ : val -> state -> Prop) :\n evalExact s t₁ Q₁ ->\n (βˆ€ s v, Q₁ v s -> evalExact s (trm_if v (trm_seq tβ‚‚ (trm_while t₁ tβ‚‚)) val_unit) Q) ->\n evalExact s (trm_while t₁ tβ‚‚) Q" }, { "name": "make_list", "content": "def make_list {A} (n : Nat) (v : A) : List A :=\n match n with\n | 0 => []\n | n' + 1 => v :: make_list n' v" }, { "name": "trm_is_val", "content": "abbrev trm_is_val : trm β†’ Prop\n | trm_val _ => true\n | _ => false" }, { "name": "conseq", "content": "def conseq {B : Type} (vs : List B) (l : Nat) : Finmap (fun _ : Nat ↦ B) :=\n match vs with\n | [] => βˆ…\n | v :: vs' => (Finmap.singleton l v) βˆͺ (conseq vs' (l + 1))" }, { "name": "null", "content": "def null : loc := 0" }, { "name": "evalbinop", "content": "inductive evalbinop : val β†’ val β†’ val β†’ (val->Prop) β†’ Prop where\n | evalbinop_eq : forall v1 v2,\n evalbinop val_eq v1 v2 (fun v => v = val_bool (is_true (v1 = v2)))\n | evalbinop_neq : forall v1 v2,\n evalbinop val_neq v1 v2 (fun v => v = val_bool (is_true (v1 β‰  v2)))\n | evalbinop_add : forall n1 n2,\n evalbinop val_add (val_int n1) (val_int n2)\n (fun v => v = val_int (n1 + n2))\n | evalbinop_addr : forall r₁ rβ‚‚,\n evalbinop val_add (val_real r₁) (val_real rβ‚‚)\n (fun v => v = val_real (r₁ + rβ‚‚))\n | evalbinop_sub : forall n1 n2,\n evalbinop val_sub (val_int n1) (val_int n2)\n (fun v => v = val_int (n1 - n2))\n | evalbinop_subr : forall r1 r2,\n evalbinop val_sub (val_real r1) (val_real r2)\n (fun v => v = val_real (r1 - r2))\n | evalbinop_mul : forall n1 n2,\n evalbinop val_mul (val_int n1) (val_int n2)\n (fun v => v = val_int (n1 * n2))\n | evalbinop_mulr : forall r1 r2,\n evalbinop val_mul (val_real r1) (val_real r2)\n (fun v => v = val_real (r1 * r2))\n | evalbinop_div : forall n1 n2,\n Β¬(n2 = 0) β†’\n evalbinop val_div (val_int n1) (val_int n2)\n (fun v => v = val_int (n1 / n2))\n | evalbinop_divr : forall r1 r2,\n Β¬(r2 = 0) β†’\n evalbinop val_div (val_real r1) (val_real r2)\n (fun v => v = val_real (r1 / r2))\n | evalbinop_mod : forall n1 n2,\n Β¬(n2 = 0) β†’\n evalbinop val_mod (val_int n1) (val_int n2)\n (fun v => v = val_int (n1 % n2))\n | evalbinop_le : forall n1 n2,\n evalbinop val_le (val_int n1) (val_int n2)\n (fun v => v = val_bool (n1 <= n2))\n | evalbinop_ler : forall r1 r2,\n evalbinop val_le (val_real r1) (val_real r2)\n (fun v => v = val_bool (r1 <= r2))\n | evalbinop_lt : forall n1 n2,\n evalbinop val_lt (val_int n1) (val_int n2)\n (fun v => v = val_bool (n1 < n2))\n | evalbinop_ltr : forall r1 r2,\n evalbinop val_lt (val_real r1) (val_real r2)\n (fun v => v = val_bool (r1 < r2))\n | evalbinop_ge : forall n1 n2,\n evalbinop val_ge (val_int n1) (val_int n2)\n (fun v => v = val_bool (n1 >= n2))\n | evalbinop_ger : forall r1 r2,\n evalbinop val_ge (val_real r1) (val_real r2)\n (fun v => v = val_bool (r1 >= r2))\n | evalbinop_gt : forall n1 n2,\n evalbinop val_gt (val_int n1) (val_int n2)\n (fun v => v = val_bool (n1 > n2))\n | evalbinop_gtr : forall r1 r2,\n evalbinop val_gt (val_real r1) (val_real r2)\n (fun v => v = val_bool (r1 > r2))\n\n \n \n \n \n | evalbinop_ptr_add : forall (p1 : loc) (p2 : Int) n,\n p2 = p1 + n ->\n evalbinop val_ptr_add (val_loc p1) (val_int n)\n (fun v => v = val_loc (Int.natAbs p2))" }, { "name": "is_true", "content": "noncomputable def is_true (P : Prop) : Bool :=\n if P then true else false" }, { "name": "evalunop", "content": "inductive evalunop : prim β†’ val β†’ (val β†’ Prop) β†’ Prop where\n | evalunop_neg : forall b1,\n evalunop val_neg (val_bool b1) (fun v => v = val_bool (Β¬ b1))\n | evalunop_opp : forall n1,\n evalunop val_opp (val_int n1) (fun v => v = val_int (- n1))\n | evalunop_oppr : forall r1,\n evalunop val_opp (val_real r1) (fun v => v = val_real (- r1))" }, { "name": "purepost", "content": "def purepost (s : state) (P : val β†’ Prop) : val β†’ state β†’ Prop :=\n fun v s' => P v ∧ s' = s" }, { "name": "read_state", "content": "def read_state (p : loc) (h : state) :=\n match Finmap.lookup p h with\n | some v => v\n | none => default" }, { "name": "subst", "content": "def subst (y : var) (v' : val) (t : trm) : trm :=\n \n let if_y_eq x t1 t2 := if x = y then t1 else t2\n match t with\n | trm_val v => trm_val v\n | trm_var x => if_y_eq x (trm_val v') t\n | trm_fun x t1 => trm_fun x (if_y_eq x t1 (subst y v' t1))\n | trm_fix f x t1 => trm_fix f x (if_y_eq f t1 (if_y_eq x t1 (subst y v' t1)))\n | trm_app t1 t2 => trm_app (subst y v' t1) (subst y v' t2)\n | trm_seq t1 t2 => trm_seq (subst y v' t1) (subst y v' t2)\n | trm_let x t1 t2 => trm_let x (subst y v' t1) (if_y_eq x t2 (subst y v' t2))\n | trm_if t0 t1 t2 => trm_if (subst y v' t0) (subst y v' t1) (subst y v' t2)\n | trm_for x t1 t2 t3 => trm_for x (subst y v' t1) (subst y v' t2) (if_y_eq x t3 (subst y v' t3))\n | trm_while t1 t2 => trm_while (subst y v' t1) (subst y v' t2)\n | trm_ref x t1 t2 => trm_ref x (subst y v' t1) (if_y_eq x t2 (subst y v' t2))\n | trm_alloc x t1 t2 => trm_alloc x (subst y v' t1) (if_y_eq x t2 (subst y v' t2))" }, { "name": "intersect", "content": "def intersect (s1 s2 : state) := s1 \\ (s1 \\ s2)" }, { "name": "hProp.Disjoint", "content": "def hProp.Disjoint (H₁ Hβ‚‚ : hProp) :=\n forall h1 h2, H₁ h1 -> Hβ‚‚ h2 -> h1.Disjoint h2" }, { "name": "qstar", "content": "def qstar {A} (Q : A β†’ hProp) (H : hProp) : A β†’ hProp :=\n fun x => hstar (Q x) H" }, { "name": "hstar", "content": "def hstar (H1 H2 : hProp) : hProp :=\n fun h => exists h1 h2,\n H1 h1 ∧ H2 h2 ∧ Finmap.Disjoint h1 h2 ∧ h = h1 βˆͺ h2" }, { "name": "infixr:55 \" βˆ— \" => HStar.hStar", "content": "infixr:55 \" βˆ— \" => HStar.hStar" } ]
[ { "name": "Finmap.insert_union", "module": "Mathlib.Data.Finmap" }, { "name": "Finmap.Disjoint.symm_iff", "module": "Mathlib.Data.Finmap" }, { "name": "Finmap.disjoint_union_left", "module": "Mathlib.Data.Finmap" }, { "name": "Finmap.mem_iff", "module": "Mathlib.Data.Finmap" }, { "name": "Finmap.union_assoc", "module": "Mathlib.Data.Finmap" }, { "name": "Finmap.union_comm_of_disjoint", "module": "Mathlib.Data.Finmap" } ]
[ { "name": "in_read_union_l", "content": "lemma in_read_union_l (h1 h2 : state) (x : loc) :\n x ∈ h1 β†’ read_state x (h1 βˆͺ h2) = read_state x h1" }, { "name": "disjoint_insert_l", "content": "lemma disjoint_insert_l (h1 h2 : state) (x : loc) (v : val) :\n Finmap.Disjoint h1 h2 β†’\n x ∈ h1 β†’\n Finmap.Disjoint (Finmap.insert x v h1) h2" }, { "name": "union_diff_disjoint_r", "content": "lemma union_diff_disjoint_r (h₁ hβ‚‚ h₃ : state) :\n hβ‚‚.Disjoint h₃ β†’\n (h₁ βˆͺ hβ‚‚) \\ h₃ = (h₁ \\ h₃) βˆͺ hβ‚‚" }, { "name": "lookup_diff", "content": "lemma lookup_diff (h₁ hβ‚‚ : state) :\n p βˆ‰ hβ‚‚ β†’\n (h₁ \\ hβ‚‚).lookup p = h₁.lookup p" }, { "name": "lookup_diff_none", "content": "lemma lookup_diff_none (h₁ hβ‚‚ : state) :\n p ∈ hβ‚‚ β†’\n (h₁ \\ hβ‚‚).lookup p = none" }, { "name": "diff_non_mem", "content": "theorem diff_non_mem (h₁ hβ‚‚ : state) :\n p ∈ hβ‚‚ β†’ p βˆ‰ h₁ \\ hβ‚‚" }, { "name": "union_monotone_r", "content": "lemma union_monotone_r (s₃ s₁ sβ‚‚ : state) :\n s₁ = sβ‚‚ β†’\n s₁ βˆͺ s₃ = sβ‚‚ βˆͺ s₃" }, { "name": "disjoint_update_not_r", "content": "lemma disjoint_update_not_r (h1 h2 : state) (x : loc) (v: val) :\n Finmap.Disjoint h1 h2 β†’\n x βˆ‰ h2 β†’\n Finmap.Disjoint (Finmap.insert x v h1) h2" }, { "name": "evalExact_post_eq", "content": "lemma evalExact_post_eq :\n Q = Q' β†’\n evalExact s t Q β†’\n evalExact s t Q'" }, { "name": "erase_of_non_mem", "content": "lemma erase_of_non_mem (h : state) :\n p βˆ‰ h β†’\n h.erase p = h" }, { "name": "diff_insert_intersect_id", "content": "lemma diff_insert_intersect_id (s₁ sβ‚‚ : state) :\n (s₁ \\ sβ‚‚) βˆͺ (intersect s₁ sβ‚‚) = s₁" }, { "name": "lookup_intersect", "content": "lemma lookup_intersect (s₁ sβ‚‚ : state) :\n p ∈ s₁ ∧ p ∈ sβ‚‚ β†’\n (intersect s₁ sβ‚‚).lookup p = s₁.lookup p" }, { "name": "intersect_disjoint_cancel", "content": "lemma intersect_disjoint_cancel (s₁ sβ‚‚ s₃ : state) :\n s₁.Disjoint s₃ β†’\n (s₁ βˆͺ intersect sβ‚‚ s₃) \\ s₃ = s₁" }, { "name": "remove_not_in_r", "content": "lemma remove_not_in_r (h1 h2 : state) (p : loc) :\n p βˆ‰ h2 β†’\n (h1 βˆͺ h2).erase p = h1.erase p βˆͺ h2" }, { "name": "disjoint_intersect_r", "content": "lemma disjoint_intersect_r (s₁ sβ‚‚ s₃ : state) :\n sβ‚‚.Disjoint s₃ β†’\n (intersect s₁ sβ‚‚).Disjoint s₃" }, { "name": "insert_union", "content": "lemma insert_union (h1 h2 : state) (p : loc) (v : val) :\n p βˆ‰ h1 βˆͺ h2 β†’\n (h1 βˆͺ h2).insert p v = (h1.insert p v) βˆͺ h2" }, { "name": "reinsert_erase_union", "content": "lemma reinsert_erase_union (h1 h2 h3 : state) :\n h3.lookup p = some v β†’\n p βˆ‰ h2 β†’\n h3.erase p = h1 βˆͺ h2 β†’\n h3 = (h1.insert p v) βˆͺ h2" }, { "name": "insert_delete_id", "content": "lemma insert_delete_id (h : state) (p : loc) :\n p βˆ‰ h β†’\n h = (h.insert p v).erase p" }, { "name": "disjoint_disjoint_diff", "content": "lemma disjoint_disjoint_diff (h₁ hβ‚‚ h₃ : state) :\n h₁.Disjoint hβ‚‚ β†’\n (h₁ \\ h₃).Disjoint hβ‚‚" }, { "name": "erase_disjoint", "content": "lemma erase_disjoint (h1 h2 : state) (p : loc) :\n h1.Disjoint h2 β†’\n (h1.erase p).Disjoint h2" } ]
[ { "name": "tohProp", "content": "abbrev tohProp (h : heap -> Prop) : hProp := h" }, { "name": "ofhProp", "content": "abbrev ofhProp (h : val -> hProp) : val -> heap -> Prop := h" } ]
[ { "name": "frame_eq_rw", "content": "lemma frame_eq_rw :\n s.Disjoint h2 β†’\n (fun v' s' ↦ v' = v ∧ s' = s βˆͺ h2) =\n (qstar (fun v' s' ↦ v' = v ∧ s' = s) (tohProp (fun h ↦ h = h2)))" }, { "name": "evalExact_frame_val", "content": "lemma evalExact_frame_val (v : val) (s h2 : state) :\n s.Disjoint h2 β†’\n evalExact (s βˆͺ h2) t (fun v' s' ↦ v' = v ∧ s' = s βˆͺ h2) β†’\n evalExact (s βˆͺ h2) t\n (qstar (fun v' s' ↦ v' = v ∧ s' = s) (tohProp (fun h ↦ h = h2)))" }, { "name": "purepost_frame", "content": "lemma purepost_frame :\n s.Disjoint h2 β†’\n (purepost (s βˆͺ h2) P) =\n (qstar (purepost s P) (tohProp fun h ↦ h = h2))" }, { "name": "evalExact_frame_unop_binop", "content": "lemma evalExact_frame_unop_binop :\n s.Disjoint h2 β†’\n evalExact (s βˆͺ h2) t (purepost (s βˆͺ h2) P) β†’\n evalExact (s βˆͺ h2) t (qstar (purepost s P) (tohProp fun h ↦ h = h2))" }, { "name": "read_state_frame", "content": "lemma read_state_frame :\n s.Disjoint h2 β†’\n p ∈ s β†’\n (fun v' s' ↦ v' = read_state p (s βˆͺ h2) ∧ s' = s βˆͺ h2 ) =\n (qstar (fun v' s' ↦ v' = read_state p s ∧ s' = s) (tohProp fun h ↦ h = h2))" }, { "name": "evalExact_frame_get", "content": "lemma evalExact_frame_get :\n s.Disjoint h2 β†’\n p ∈ s β†’\n evalExact (s βˆͺ h2) t (fun v' s' ↦ v' = read_state p (s βˆͺ h2) ∧ s' = s βˆͺ h2 ) β†’\n evalExact (s βˆͺ h2) t\n (qstar (fun v' s' ↦ v' = read_state p s ∧ s' = s) (tohProp fun h ↦ h = h2))" }, { "name": "insert_frame", "content": "lemma insert_frame :\n s.Disjoint h2 β†’\n p ∈ s β†’\n fun v'' s' ↦ v'' = val_unit ∧ s' = Finmap.insert p v' (s βˆͺ h2) =\n (qstar (fun v'' s' ↦ v'' = val_unit ∧ s' = Finmap.insert p v' s) (tohProp fun h ↦ h = h2))" }, { "name": "evalExact_frame_set", "content": "lemma evalExact_frame_set :\n s.Disjoint h2 β†’\n p ∈ s β†’\n evalExact (s βˆͺ h2) t\n (fun v'' s' ↦ v'' = val_unit ∧ s' = Finmap.insert p v' (s βˆͺ h2)) β†’\n evalExact (s βˆͺ h2) t\n (qstar (fun v'' s' ↦ v'' = val_unit ∧ s' = Finmap.insert p v' s) (tohProp fun h ↦ h = h2))" } ]
import Mathlib.Data.Finmap import Mathlib.Data.Finset.Basic import Mathlib.Data.Multiset.Nodup import SPLean.Common.State import SPLean.Common.Util import SPLean.Theories.HProp import SPLean.Theories.XSimp open trm val prim notation "funloc" p "↦" H => fun (r : val) ↦ hexists (fun p ↦ ⌜r = val_loc p⌝ βˆ— H) section evalProp abbrev tohProp (h : heap -> Prop) : hProp := h abbrev ofhProp (h : val -> hProp) : val -> heap -> Prop := h
lemma evalExact_frame (h1 h2 : state) t (Q : val β†’ hProp) : evalExact h1 t (ofhProp Q) β†’ Finmap.Disjoint h1 h2 β†’ evalExact (h1 βˆͺ h2) t (Q βˆ— (tohProp (fun h ↦ h = h2))) :=
:= by simp [ofhProp] move=> /== heval elim: heval h2 { move=> > * sby apply evalExact_frame_val } { move=> > * sby apply evalExact_frame_val } { move=> > * sby apply evalExact_frame_val } { move=> ???????? ih1 ?? /ih1 ? ; constructor=>// sby move=> ?? ![] } { move=> ???????? ih1 ?? /ih1 ? ; apply evalExact.app_arg2=>// sby move=> ?? ![] } { sby move=> * ; apply evalExact.app_fun } { sby move=> * ; apply evalExact.app_fix } { move=> ??????? ih1 ih2 ? /ih1 ? ; apply evalExact.seq=>// move=> ? s2 ![??? hQ2 *] ; subst s2 hQ2 sby apply ih2 } { move=> ???????? ih1 ih2 ? /ih1 ? ; apply evalExact.let=>// move=> ?? ![??? hQ2 ? hU] ; subst hU hQ2 sby apply ih2} { sby move=> * } { move=> > ? > * apply evalExact_frame_unop_binop=> // sby apply evalExact.unop } { move=> > ? > * apply evalExact_frame_unop_binop=> // sby apply evalExact.binop } { move=> > ; unfold tohProp move=> _ _ ih1 ih2 > /ih1 {}ih1 apply evalExact.ref { apply ih1 } move=> {ih1} > ![>] hQ₁ /= -> ? -> p ? have eqn:(p βˆ‰ w) := by sdone have eqn':((w.insert p v1).Disjoint h2) := by sby apply disjoint_update_not_r move: hQ₁ eqn eqn'=> /ih2 /[apply] /[apply] {ih2} srw insert_union=> // hq apply evalExact_post_eq ; rotate_left ; apply hq apply funext=> v ; apply funext=> h ; apply propext=> ⟨|⟩ { move=> ![>] /= ? -> ? -> exists (w_2.erase p), h2=> ⟨//|/==⟩ ⟨|⟩ apply erase_disjoint=> // sby srw remove_not_in_r } move=> ![>] /= ? -> ? scase: [p ∈ h] { move=> ? ; srw erase_of_non_mem=> // [] exists w_2, h2=> /== ⟨|⟩ // sby srw erase_of_non_mem } move=> /Finmap.mem_iff [v'] /reinsert_erase_union heq herase srw (heq w_2 h2)=> // {heq} exists (w_2.insert p v'), h2=> /== ⟨|⟩ { srw -insert_delete_id=> // have eqn:(p βˆ‰ h.erase p) := by apply Finmap.not_mem_erase_self move: eqn sby srw herase } sby apply disjoint_update_not_r } { move=> > ? > * apply evalExact_frame_get=> // sby apply evalExact.get } { move=> > [] ? > * * ; apply evalExact_frame_set=> // sby apply evalExact.set } -- { move=> * ; apply eval.eval_free=>// -- srw remove_disjoint_union_l ; apply hstar_intro=>// -- sby apply disjoint_remove_l } { move=> > ??? ih1 ih2 > /ih1 {ih1} ? apply evalExact.alloc_arg=> // > sby move=> ![>] } { unfold tohProp=> > ?? ih > ? ; apply evalExact.alloc=> // > move=> /ih /[apply] {}ih /Finmap.disjoint_union_left [] /[dup] /ih {}ih ? srw Finmap.Disjoint.symm_iff -Finmap.union_assoc=> ? have eqn:((sb βˆͺ sa).Disjoint h2) := by sby srw Finmap.disjoint_union_left apply ih in eqn=> {ih} hq ; apply evalExact_post_eq ; rotate_left ; apply hq apply funext=> v ; apply funext=> h ; apply propext=> ⟨|⟩ { move=> ![>] /= ? -> ? -> exists (w \ sb), h2=> /== ⟨|⟩ // ⟨|⟩ { sby apply disjoint_disjoint_diff } apply union_diff_disjoint_r sby apply Finmap.Disjoint.symm } move=> ![>] /= ? -> ? /[dup] heq have eqn:((w βˆͺ h2).Disjoint sb) := by { srw -heq ; unfold Finmap.Disjoint=> /== } move: eqn=> /Finmap.disjoint_union_left [ ? _] move=> /(union_monotone_r (intersect h sb)) srw diff_insert_intersect_id Finmap.union_assoc [2]Finmap.union_comm_of_disjoint rotate_left { apply Finmap.Disjoint.symm ; sby apply disjoint_intersect_r } srw -Finmap.union_assoc=> ? exists (w βˆͺ intersect h sb), h2=> //== ⟨|⟩ { sby srw intersect_disjoint_cancel } constructor=> // srw Finmap.disjoint_union_left ; constructor=> // sby apply disjoint_intersect_r } { move=> // } move=> > ?? ih₁ ihβ‚‚ ??; econstructor { apply ih₁=> // } sby move=> > ![]
6
82
false
Framework
402
Theories.eval_like_trm_apps_funs_pre
lemma eval_like_trm_apps_funs_pre (heqv0 : v0 = trm_funs xs t1) : eval_like t (trm_apps (val_funs xs t1) ts) ∧ -- NOTE: this part do not require `xs.Nodup`, but anyway eval_like (isubst (xs.mkAlist vs) t1) t
splean
SPLean/Theories/WP1.lean
[ "import SPLean.Theories.XChange", "import SPLean.Theories.Lang", "import Mathlib.Data.List.Indexes", "import SPLean.Theories.XSimp", "import SPLean.Theories.SepLog", "import Mathlib.Data.Finmap", "import SPLean.Common.State", "import SPLean.Theories.HProp", "import SPLean.Common.Util", "import Lean", "import SPLean.Theories.WPUtil" ]
[ { "name": "DecidableEq", "module": "Init.Prelude" }, { "name": "List", "module": "Init.Prelude" }, { "name": "AList", "module": "Mathlib.Data.List.AList" }, { "name": "String", "module": "Init.Prelude" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "AList.erase", "module": "Mathlib.Data.List.AList" }, { "name": "AList.lookup", "module": "Mathlib.Data.List.AList" }, { "name": "Finmap", "module": "Mathlib.Data.Finmap" }, { "name": "BEq", "module": "Init.Prelude" }, { "name": "Repr", "module": "Init.Data.Repr" }, { "name": "Vector", "module": "Init.Data.Vector.Basic" }, { "name": "bool", "module": "Init.Control.Basic" }, { "name": "ite", "module": "Init.Prelude" }, { "name": "Computation", "module": "Mathlib.Data.Seq.Computation" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "Max", "module": "Init.Prelude" }, { "name": "Max.max", "module": "Init.Prelude" }, { "name": "And", "module": "Init.Prelude" }, { "name": "move", "module": "Ssreflect.Basic" }, { "name": "sdone", "module": "Ssreflect.Done" }, { "name": "srw", "module": "Ssreflect.Rewrite" }, { "name": "AList.entries", "module": "Mathlib.Data.List.AList" }, { "name": "List.NodupKeys", "module": "Mathlib.Data.List.Sigma" }, { "name": "List.keys", "module": "Mathlib.Data.List.Sigma" }, { "name": "List.map", "module": "Init.Prelude" }, { "name": "List.zip", "module": "Init.Data.List.Basic" }, { "name": "List.zipWith", "module": "Init.Data.List.Basic" }, { "name": "elim", "module": "Ssreflect.Elim" }, { "name": "Sigma", "module": "Init.Core" }, { "name": "t", "module": "Ssreflect.IntroPats" }, { "name": "scase", "module": "Ssreflect.Elim" }, { "name": "AList.insert", "module": "Mathlib.Data.List.AList" }, { "name": "List.kerase", "module": "Mathlib.Data.List.Sigma" }, { "name": "List.kinsert", "module": "Mathlib.Data.List.Sigma" }, { "name": "AList.keys", "module": "Mathlib.Data.List.AList" } ]
[ { "name": "syntax \"fun\" ident+ \" => \" lang : lang", "content": "syntax \"fun\" ident+ \" => \" lang : lang\n\nsyntax \"⟨\" term \"⟩\" : lang\n\nsyntax \"⟨\" term \":\" term \"⟩\" : lang\n\nsyntax \"if \" lang \"then \" lang \"end \" : lang\n\nsyntax \" := \" : bop\n\nsyntax \"let\" ident \" := \" lang \" in\" ppDedent(ppLine lang) : lang\n\nsyntax \" ++ \" : bop\n\nsyntax \"not\" : uop" }, { "name": "macro_rules", "content": "macro_rules\n | `([lang| ()]) => `(trm_val (val_unit))\n | `([lang| $n:num]) => `(trm_val (val_int $n))\n | `([lang| $t1 $t2]) => `(trm_app [lang| $t1] [lang| $t2])\n | `([lang| if $t1 then $t2 else $t3]) => `(trm_if [lang| $t1] [lang| $t2] [lang| $t3])\n | `([lang| if $t1 then $t2 end]) => `(trm_if [lang| $t1] [lang| $t2] (trm_val val_unit))\n | `([lang| let $x := $t1:lang in $t2:lang]) =>\n `(trm_let $(%x) [lang| $t1] [lang| $t2])\n | `([lang| ref $x := $t1:lang in $t2:lang]) =>\n `(trm_ref $(%x) [lang| $t1] [lang| $t2])\n | `([lang| alloc $t1:lang as $x in $t2:lang]) =>\n `(trm_alloc $(%x) [lang| $t1] [lang| $t2])\n | `([lang| $t1 ; $t2]) => `(trm_seq [lang| $t1] [lang| $t2])\n | `([lang| fun_ $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(trm_funs [ $xs,* ] [lang| $t])\n | `([lang| fun $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(val_funs [ $xs,* ] [lang| $t])\n | `([lang| fix_ $f $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(trm_fixs $(%f) [ $xs,* ] [lang| $t])\n | `([lang| fix $f $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(val_fixs $(%f) [ $xs,* ] [lang| $t])\n \n | `([lang| free $t]) => `(trm_val (val_prim val_free) [lang| $t])\n | `([lang| not $t]) => `(trm_val (val_prim val_not) [lang| $t])\n \n | `([lang| !$t]) => `(trm_val val_get [lang| $t])\n | `([lang| $t1 := $t2]) => `(trm_val val_set [lang| $t1] [lang| $t2])\n | `([lang| $t1 + $t2]) => `(trm_val val_add [lang| $t1] [lang| $t2])\n | `([lang| $t1 * $t2]) => `(trm_val val_mul [lang| $t1] [lang| $t2])\n | `([lang| $t1 - $t2]) => `(trm_val val_sub [lang| $t1] [lang| $t2])\n | `([lang| $t1 / $t2]) => `(trm_val val_div [lang| $t1] [lang| $t2])\n | `([lang| $t1 < $t2]) => `(trm_val val_lt [lang| $t1] [lang| $t2])\n | `([lang| $t1 > $t2]) => `(trm_val val_gt [lang| $t1] [lang| $t2])\n | `([lang| $t1 <= $t2]) => `(trm_val val_le [lang| $t1] [lang| $t2])\n | `([lang| $t1 >= $t2]) => `(trm_val val_ge [lang| $t1] [lang| $t2])\n | `([lang| -$t]) => `(trm_val val_opp [lang| $t])\n | `([lang| $t1 = $t2]) => `(trm_val val_eq [lang| $t1] [lang| $t2])\n | `([lang| $t1 != $t2]) => `(trm_val val_neq [lang| $t1] [lang| $t2])\n | `([lang| $t1 mod $t2]) => `(trm_val val_mod [lang| $t1] [lang| $t2])\n | `([lang| $t1 ++ $t2]) => `(trm_val val_ptr_add [lang| $t1] [lang| $t2])\n | `([lang| ($t)]) => `([lang| $t])\n | `([lang| ⟨$t : $tp⟩]) => `(trm_val (($t : $tp)))\n | `([lang| for $x in [$n1 : $n2] { $t } ]) =>\n `(trm_for $(%x) [lang| $n1] [lang| $n2] [lang| $t])\n | `([lang| while $c:lang { $t:lang } ]) =>\n `(trm_while [lang| $c] [lang| $t] )" }, { "name": "macro_rules", "content": "macro_rules\n | `([lang| len $p]) => `(trm_val val_array_length [lang| $p])\n | `([lang| $arr[$i] ]) => `(trm_val val_array_get [lang| $arr] [lang| $i])\n \n | `([lang| $arr[$i] := $v]) => `(trm_app val_array_set [lang| $arr] [lang| $i] [lang| $v])\n | `([lang| mkarr $n:lang $v:lang]) => `(trm_val val_array_make [lang| $n] [lang| $v])\n\n inductive trm : Type where\n | trm_val : val -> trm\n | trm_var : var -> trm\n | trm_fun : var -> trm -> trm\n | trm_fix : var -> var -> trm -> trm\n | trm_app : trm -> trm -> trm\n | trm_seq : trm -> trm -> trm\n | trm_let : var -> trm -> trm -> trm\n | trm_if : trm -> trm -> trm -> trm\n | trm_for : var -> trm -> trm -> trm -> trm\n | trm_while : trm -> trm -> trm\n | trm_ref : var β†’ trm β†’ trm β†’ trm\n | trm_alloc : var β†’ trm β†’ trm β†’ trm\n\n inductive val : Type where\n | val_unit : val\n | val_bool : Bool β†’ val\n | val_int : Int β†’ val\n | val_real : ℝ β†’ val\n | val_loc : loc β†’ val\n | val_prim : prim β†’ val\n | val_fun : var -> trm -> val\n | val_fix : var -> var -> trm -> val\n | val_uninit : val\n | val_error : val" }, { "name": "prim", "content": "inductive prim where\n \n | val_get : prim\n | val_set : prim\n \n | val_neg : prim\n | val_opp : prim\n | val_eq : prim\n | val_add : prim\n | val_neq : prim\n | val_sub : prim\n | val_mul : prim\n | val_div : prim\n | val_mod : prim\n \n | val_le : prim\n | val_lt : prim\n | val_ge : prim\n | val_gt : prim\n | val_ptr_add : prim" }, { "name": "var", "content": "abbrev var := String" }, { "name": "loc", "content": "abbrev loc := Nat" }, { "name": "hempty", "content": "def hempty : hProp :=\n fun h => (h = βˆ…)" }, { "name": "hProp", "content": "def hProp := heap -> Prop" }, { "name": "heap", "content": "abbrev heap := Heap.heap val" }, { "name": "Heap.heap", "content": "abbrev Heap.heap (val : Type) := Finmap (Ξ» _ : loc ↦ val)" }, { "name": "val_funs", "content": "def val_funs (xs:List var) (t:trm) : val :=\n match xs with\n | [] => panic! \"function with zero argumets!\"\n | x1::xs' => val_fun x1 (trm_funs xs' t)" }, { "name": "trm_funs", "content": "def trm_funs (xs:List var) (t:trm) : trm :=\n match xs with\n | [] => t\n | x1::xs' => trm_fun x1 (trm_funs xs' t)" }, { "name": "subst", "content": "def subst (y : var) (v' : val) (t : trm) : trm :=\n \n let if_y_eq x t1 t2 := if x = y then t1 else t2\n match t with\n | trm_val v => trm_val v\n | trm_var x => if_y_eq x (trm_val v') t\n | trm_fun x t1 => trm_fun x (if_y_eq x t1 (subst y v' t1))\n | trm_fix f x t1 => trm_fix f x (if_y_eq f t1 (if_y_eq x t1 (subst y v' t1)))\n | trm_app t1 t2 => trm_app (subst y v' t1) (subst y v' t2)\n | trm_seq t1 t2 => trm_seq (subst y v' t1) (subst y v' t2)\n | trm_let x t1 t2 => trm_let x (subst y v' t1) (if_y_eq x t2 (subst y v' t2))\n | trm_if t0 t1 t2 => trm_if (subst y v' t0) (subst y v' t1) (subst y v' t2)\n | trm_for x t1 t2 t3 => trm_for x (subst y v' t1) (subst y v' t2) (if_y_eq x t3 (subst y v' t3))\n | trm_while t1 t2 => trm_while (subst y v' t1) (subst y v' t2)\n | trm_ref x t1 t2 => trm_ref x (subst y v' t1) (if_y_eq x t2 (subst y v' t2))\n | trm_alloc x t1 t2 => trm_alloc x (subst y v' t1) (if_y_eq x t2 (subst y v' t2))" }, { "name": "trm_apps", "content": "def trm_apps (f:trm) (ts:List trm) : trm :=\n match ts with\n | [] => f\n | ti::ts' => trm_apps (trm_app f ti) ts'" }, { "name": "eval_like", "content": "def eval_like (t1 t2:trm) : Prop :=\n forall s Q, eval s t1 Q -> eval s t2 Q" }, { "name": "eval", "content": "inductive eval : state β†’ trm β†’ (val β†’ state β†’ Prop) -> Prop where\n | eval_val : forall s v Q,\n Q v s ->\n eval s (trm_val v) Q\n | eval_fun : forall s x t1 Q,\n Q (val_fun x t1) s ->\n eval s (trm_fun x t1) Q\n | eval_fix : forall s f x t1 Q,\n Q (val_fix f x t1) s ->\n eval s (trm_fix f x t1) Q\n | eval_app_arg1 : forall s1 t1 t2 Q1 Q,\n Β¬ trm_is_val t1 ->\n eval s1 t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> eval s2 (trm_app v1 t2) Q) ->\n eval s1 (trm_app t1 t2) Q\n | eval_app_arg2 : forall s1 (v1 : val) t2 Q1 Q,\n Β¬ trm_is_val t2 ->\n eval s1 t2 Q1 ->\n (forall v2 s2, Q1 v2 s2 -> eval s2 (trm_app v1 v2) Q) ->\n eval s1 (trm_app v1 t2) Q\n | eval_app_fun : forall s1 v1 (v2 :val) x t1 Q,\n v1 = val_fun x t1 ->\n eval s1 (subst x v2 t1) Q ->\n eval s1 (trm_app v1 v2) Q\n | eval_app_fix : forall s (v1 v2 : val) f x t1 Q,\n v1 = val_fix f x t1 ->\n eval s (subst x v2 (subst f v1 t1)) Q ->\n eval s (trm_app v1 v2) Q\n | eval_seq : forall Q1 s t1 t2 Q,\n eval s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> eval s2 t2 Q) ->\n eval s (trm_seq t1 t2) Q\n | eval_let : forall Q1 s x t1 t2 Q,\n eval s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> eval s2 (subst x v1 t2) Q) ->\n eval s (trm_let x t1 t2) Q\n | eval_if : forall s (b : Bool) t1 t2 Q,\n eval s (if b then t1 else t2) Q ->\n eval s (trm_if (val_bool b) t1 t2) Q\n | eval_unop : forall op s v1 P Q,\n evalunop op v1 P ->\n purepostin s P Q ->\n eval s (trm_app op v1) Q\n | eval_binop : forall op s (v1 v2 : val) P Q,\n evalbinop op v1 v2 P ->\n purepostin s P Q ->\n eval s (trm_app (trm_app op v1) v2) Q\n | eval_ref : forall s x t1 t2 (Q Q₁ : val β†’ state β†’ Prop),\n eval s t1 Q₁ β†’\n (βˆ€ v1 s1, Q₁ v1 s1 β†’ βˆ€ p βˆ‰ s1,\n eval (s1.insert p v1) (subst x p t2) fun v s ↦ Q v (s.erase p)) β†’\n eval s (trm_ref x t1 t2) Q\n | eval_get : forall s p Q,\n p ∈ s ->\n Q (read_state p s) s ->\n eval s (trm_app val_get (val_loc p)) Q\n | eval_set : forall s p v Q,\n v = trm_val v' ->\n p ∈ s ->\n Q val_unit (Finmap.insert p v' s) ->\n eval s (trm_app (trm_app val_set (val_loc p)) v) Q\n | eval_alloc_arg : forall s Q₁ Q,\n Β¬ trm_is_val t1 β†’\n eval s t1 Q₁ β†’\n (βˆ€ v' s', Q₁ v' s' β†’ eval s' (trm_alloc x v' t2) Q) β†’\n eval s (trm_alloc x t1 t2) Q\n | eval_alloc : forall (sa : state) (n : β„€) Q,\n n β‰₯ 0 β†’\n (βˆ€ (p : loc) (sb : state),\n sb = conseq (make_list n.natAbs val_uninit) p β†’\n p β‰  null β†’\n Finmap.Disjoint sa sb β†’\n eval (sb βˆͺ sa) (subst x p t2) fun v s ↦ Q v (s \\ sb)) β†’\n eval sa (trm_alloc x n t2) Q\n \n \n \n \n \n \n \n \n | eval_for (n₁ nβ‚‚ : Int) (Q : val -> state -> Prop) :\n eval s (if (n₁ < nβ‚‚) then\n (trm_seq (subst x n₁ t₁) (trm_for x (val_int (n₁ + 1)) nβ‚‚ t₁))\n else val_unit) Q ->\n eval s (trm_for x n₁ nβ‚‚ t₁) Q\n | eval_while (t₁ tβ‚‚ : trm) (Q : val -> state -> Prop) :\n eval s t₁ Q₁ ->\n (βˆ€ s v, Q₁ v s -> eval s (trm_if v (trm_seq tβ‚‚ (trm_while t₁ tβ‚‚)) val_unit) Q) ->\n eval s (trm_while t₁ tβ‚‚) Q" }, { "name": "trm_is_val", "content": "abbrev trm_is_val : trm β†’ Prop\n | trm_val _ => true\n | _ => false" }, { "name": "notation:max \"emp\" => hempty", "content": "notation:max \"emp\" => hempty" }, { "name": "fun", "content": "notation \"funloc\" p \"↦\" H =>\n fun (r : val) ↦ hexists (fun p ↦ ⌜r = val_loc p⌝ βˆ— H)" } ]
[ { "name": "AList.keys_nodup", "module": "Mathlib.Data.List.AList" }, { "name": "List.dlookup_dedupKeys", "module": "Mathlib.Data.List.Sigma" }, { "name": "List.lookup_ext", "module": "Mathlib.Data.List.Sigma" }, { "name": "List.perm_dlookup", "module": "Mathlib.Data.List.Sigma" }, { "name": "List.perm_nodupKeys", "module": "Mathlib.Data.List.Sigma" }, { "name": "List.map_append", "module": "Init.Data.List.Lemmas" }, { "name": "List.map_zipWith", "module": "Init.Data.List.Zip" }, { "name": "List.nodup_cons", "module": "Init.Data.List.Pairwise" }, { "name": "List.perm_append_singleton", "module": "Init.Data.List.Perm" }, { "name": "List.zip_append", "module": "Init.Data.List.Zip" }, { "name": "List.kerase_cons_ne", "module": "Mathlib.Data.List.Sigma" }, { "name": "List.kerase_kerase", "module": "Mathlib.Data.List.Sigma" }, { "name": "AList.perm_erase", "module": "Mathlib.Data.List.AList" }, { "name": "AList.perm_lookup", "module": "Mathlib.Data.List.AList" }, { "name": "AList.mem_keys", "module": "Mathlib.Data.List.AList" }, { "name": "List.eraseP_of_forall_not", "module": "Init.Data.List.Erase" }, { "name": "AList.erase_erase", "module": "Mathlib.Data.List.AList" }, { "name": "AList.lookup_erase_ne", "module": "Mathlib.Data.List.AList" }, { "name": "AList.lookup_insert_ne", "module": "Mathlib.Data.List.AList" }, { "name": "congrArg", "module": "Init.Prelude" }, { "name": "AList.toAList_cons", "module": "Mathlib.Data.List.AList" }, { "name": "List.nodup_middle", "module": "Mathlib.Data.List.Nodup" } ]
[ { "name": "eval_app_arg1'", "content": "lemma eval_app_arg1' s1 t1 t2 Q1 Q :\n eval s1 t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> eval s2 (trm_app v1 t2) Q) ->\n eval s1 (trm_app t1 t2) Q" } ]
[ { "name": "Theories.trms_to_vals", "content": "@[simp]\ndef trms_to_vals (ts:List trm) : Option (List val) := do\n match ts with\n | [] => return []\n | (trm_val v) :: ts' => v :: (<- trms_to_vals ts')\n | _ => failure" }, { "name": "Theories.ctx", "content": "abbrev ctx := AList (fun _ : var ↦ val)" }, { "name": "Theories.isubst", "content": "def isubst (E : ctx) (t : trm) : trm :=\n match t with\n | trm_val v =>\n v\n | trm_var x =>\n match lookup x E with\n | none => t\n | some v => v\n | trm_fun x t1 =>\n trm_fun x (isubst (erase x E) t1)\n | trm_fix f x t1 =>\n trm_fix f x (isubst (erase x (erase f E)) t1)\n | trm_if t0 t1 t2 =>\n trm_if (isubst E t0) (isubst E t1) (isubst E t2)\n | trm_seq t1 t2 =>\n trm_seq (isubst E t1) (isubst E t2)\n | trm_let x t1 t2 =>\n trm_let x (isubst E t1) (isubst (erase x E) t2)\n | trm_ref x t1 t2 =>\n trm_ref x (isubst E t1) (isubst (erase x E) t2)\n | trm_alloc x t1 t2 =>\n trm_alloc x (isubst E t1) (isubst (erase x E) t2)\n | trm_app t1 t2 =>\n trm_app (isubst E t1) (isubst E t2)\n | trm_for x n1 n2 t =>\n trm_for x (isubst E n1) (isubst E n2) (isubst (erase x E) t)\n | trm_while c t =>\n trm_while (isubst E c) (isubst E t)" } ]
[ { "name": "Theories.trms_to_vals_some_equiv", "content": "lemma trms_to_vals_some_equiv ts vs : trms_to_vals ts = some vs β†’ ts = vs.map trm_val" }, { "name": "Theories.List.toAList_perm", "content": "lemma List.toAList_perm {Ξ± : Type u} {Ξ² : Ξ± β†’ Type v} [DecidableEq Ξ±]\n (es es' : List (Sigma Ξ²)) (hnodup : es.NodupKeys) (hp : es.Perm es') :\n es.toAList.entries.Perm es'.toAList.entries" }, { "name": "Theories.List.mkAlist_snoc_to_cons", "content": "lemma List.mkAlist_snoc_to_cons [DecidableEq Ξ±] (xs : List Ξ±) (vs : List Ξ²)\n (x : Ξ±) (v : Ξ²) : x βˆ‰ xs β†’ xs.length = vs.length β†’ xs.Nodup β†’\n ((xs ++ [x]).mkAlist (vs ++ [v])).entries.Perm (((x :: xs).mkAlist (v :: vs)).entries)" }, { "name": "Theories.AList.erase_insert_cancel", "content": "lemma AList.erase_insert_cancel {Ξ± : Type u} {Ξ² : Ξ± β†’ Type v} [DecidableEq Ξ±] (a : Ξ±) (b : Ξ² a) (l : AList Ξ²) :\n (AList.erase a (AList.insert a b l)).entries.Perm (AList.erase a l).entries" }, { "name": "Theories.AList.erase_insert_swap", "content": "lemma AList.erase_insert_swap {Ξ± : Type u} {Ξ² : Ξ± β†’ Type v} [DecidableEq Ξ±] (a a' : Ξ±) (b : Ξ² a) (l : AList Ξ²) :\n a β‰  a' β†’ (AList.erase a' (AList.insert a b l)).entries.Perm (AList.insert a b (AList.erase a' l)).entries" }, { "name": "Theories.AList.erase_noop", "content": "lemma AList.erase_noop {Ξ± : Type u} {Ξ² : Ξ± β†’ Type v} [DecidableEq Ξ±] (a : Ξ±) (l : AList Ξ²) :\n a βˆ‰ l β†’ (AList.erase a l).entries.Perm l.entries" }, { "name": "Theories.AList.erase_twice", "content": "lemma AList.erase_twice {Ξ± : Type u} {Ξ² : Ξ± β†’ Type v} [DecidableEq Ξ±] (a : Ξ±) (l : AList Ξ²) :\n (AList.erase a (AList.erase a l)).entries.Perm (AList.erase a l).entries" }, { "name": "Theories.AList.erase_empty", "content": "lemma AList.erase_empty {Ξ± : Type u} {Ξ² : Ξ± β†’ Type v} [DecidableEq Ξ±] (a : Ξ±) :\n AList.erase a (βˆ… : AList Ξ²) = βˆ…" }, { "name": "Theories.isubst_empty", "content": "lemma isubst_empty t : isubst βˆ… t = t" }, { "name": "Theories.isubst_perm", "content": "lemma isubst_perm {al al'} t (hp : al.entries.Perm al'.entries) :\n isubst al t = isubst al' t" }, { "name": "Theories.isubst_insert", "content": "lemma isubst_insert (al : ctx) x v t :\n isubst (al.insert x v) t = subst x v (isubst (al.erase x) t)" }, { "name": "Theories.isubst_single", "content": "lemma isubst_single x v t : isubst (List.mkAlist [x] [v]) t = subst x v t" }, { "name": "Theories.trm_apps2", "content": "lemma trm_apps2 :\n trm_apps (trm_app t1 t2) ts = trm_apps t1 (t2::ts)" }, { "name": "Theories.trm_apps_app", "content": "lemma trm_apps_app :\n trm_apps t1 (ts ++ ts') = trm_apps (trm_apps t1 ts) ts'" }, { "name": "Theories.trm_funs_app", "content": "lemma trm_funs_app :\n trm_funs (xs ++ xs') t1 = trm_funs xs (trm_funs xs' t1)" }, { "name": "Theories.eval_like_trm_fun_val_fun", "content": "lemma eval_like_trm_fun_val_fun x t : eval_like (trm_fun x t) (val_fun x t)" }, { "name": "Theories.eval_like_val_fun_trm_fun", "content": "lemma eval_like_val_fun_trm_fun x t : eval_like (val_fun x t) (trm_fun x t)" }, { "name": "Theories.eval_like_trm_app_left", "content": "lemma eval_like_trm_app_left t1 t1' t2 (hsat : βˆƒ s Q, eval s t1 Q) : eval_like t1 t1' β†’ eval_like (trm_app t1 t2) (trm_app t1' t2)" }, { "name": "Theories.eval_like_trm_fun_val_fun_app_left", "content": "lemma eval_like_trm_fun_val_fun_app_left (x : var) (t1 t2 : trm) :\n eval_like (trm_app (trm_fun x t1) t2) (trm_app (val_fun x t1) t2)" }, { "name": "Theories.eval_like_val_fun_trm_fun_app_left", "content": "lemma eval_like_val_fun_trm_fun_app_left (x : var) (t1 t2 : trm) :\n eval_like (trm_app (val_fun x t1) t2) (trm_app (trm_fun x t1) t2)" }, { "name": "Theories.val_funs_snoc", "content": "lemma val_funs_snoc (xs : List var) (x : var) (h : xs β‰  []) (t : trm) :\n val_funs (xs ++ [x]) t = val_funs xs (trm_fun x t)" }, { "name": "Theories.List.not_nil_snoc", "content": "lemma List.not_nil_snoc {Ξ± : Type u} (l : List Ξ±) : l β‰  [] β†’ βˆƒ l' x, l = l' ++ [x]" } ]
import Lean import Mathlib.Data.Finmap import Mathlib.Data.List.Indexes import SPLean.Common.State import SPLean.Common.Util import SPLean.Theories.HProp import SPLean.Theories.XSimp import SPLean.Theories.XChange import SPLean.Theories.SepLog import SPLean.Theories.WPUtil open trm val prim namespace Theories section tactics open Lean Elab Tactic section xapp end xapp end tactics @[simp] def trms_to_vals (ts:List trm) : Option (List val) := do match ts with | [] => return [] | (trm_val v) :: ts' => v :: (<- trms_to_vals ts') | _ => failure open AList abbrev ctx := AList (fun _ : var ↦ val) def isubst (E : ctx) (t : trm) : trm := match t with | trm_val v => v | trm_var x => match lookup x E with | none => t | some v => v | trm_fun x t1 => trm_fun x (isubst (erase x E) t1) | trm_fix f x t1 => trm_fix f x (isubst (erase x (erase f E)) t1) | trm_if t0 t1 t2 => trm_if (isubst E t0) (isubst E t1) (isubst E t2) | trm_seq t1 t2 => trm_seq (isubst E t1) (isubst E t2) | trm_let x t1 t2 => trm_let x (isubst E t1) (isubst (erase x E) t2) | trm_ref x t1 t2 => trm_ref x (isubst E t1) (isubst (erase x E) t2) | trm_alloc x t1 t2 => trm_alloc x (isubst E t1) (isubst (erase x E) t2) | trm_app t1 t2 => trm_app (isubst E t1) (isubst E t2) | trm_for x n1 n2 t => trm_for x (isubst E n1) (isubst E n2) (isubst (erase x E) t) | trm_while c t => trm_while (isubst E c) (isubst E t) section funs_fixs_eval_like variable (xs : List var) (vs : List val) (t : trm) (v0 : trm) (heqt : t = trm_apps v0 ts) (hconv : trms_to_vals ts = vs) (hform : var_funs xs vs.length) -- NOTE: can be relaxed to `vs.length ≀ xs.length`
lemma eval_like_trm_apps_funs_pre (heqv0 : v0 = trm_funs xs t1) : eval_like t (trm_apps (val_funs xs t1) ts) ∧ -- NOTE: this part do not require `xs.Nodup`, but anyway eval_like (isubst (xs.mkAlist vs) t1) t :=
:= by apply trms_to_vals_some_equiv at hconv ; subst_eqs move: hform=> /== hnodup hlen hnotempty move: hnodup vs hlen t1 induction xs using List.list_reverse_induction with | base => sdone | ind xs x ih => move=> { hnotempty } /(List.nodup_middle (lβ‚‚ := [])) /== hnotin hnodup vs hlen t1 by_cases hvs : vs = [] { subst vs ; simp [trm_apps]=> ⟨|//⟩ ; apply eval_like_trm_funs_val_funs=> // } move: hvs=> /List.not_nil_snoc [vs [v ?]] /[tac subst_eqs] simp at hlen ; simp [trm_apps_app, trm_apps] by_cases hxs : xs = [] { subst xs ; simp [val_funs, trm_funs] at * cases vs=> //= { hlen } ; simp [trm_apps] apply And.intro { apply eval_like_trm_fun_val_fun_app_left=> // } -- single subst srw isubst_single trans on_goal 2=> apply eval_like_val_fun_trm_fun_app_left move=> ??? ; apply eval.eval_app_fun=> // } specialize @ih hxs hnodup _ hlen (trm_fun x t1) ; rcases ih with ⟨ih1, ih2⟩ apply And.intro { srw val_funs_snoc // trm_funs_app ; simp [trm_funs] trans on_goal 2=> apply eval_like_trm_app_left on_goal 3=> apply ih1 on_goal 2=> exists βˆ…, (fun _ _ ↦ True) ; apply ih2=> // -- that's why we want to prove things together move=> ??=> // } srw trm_funs_app ; simp [trm_funs, trm_apps] -- ih trans on_goal 2=> apply eval_like_trm_app_left on_goal 3=> apply ih2 on_goal 2=> exists βˆ…, (fun _ _ ↦ True) ; simp [isubst]=> // clear ih1 ih2 ; simp [isubst] -- trm_fun -> val_fun trans on_goal 2=> apply eval_like_val_fun_trm_fun_app_left -- raw eval, then subst reasoning move=> s Q h apply eval.eval_app_fun=> // srw -isubst_insert rw [isubst_perm _ (List.mkAlist_snoc_to_cons xs vs x v hnotin hlen hnodup)] at h apply h
5
102
false
Framework
403
eval_frame
lemma eval_frame (h1 h2 : state) t (Q : val -> hProp) : eval h1 t (ofhProp Q) β†’ Finmap.Disjoint h1 h2 β†’ eval (h1 βˆͺ h2) t (Q βˆ— (tohProp (fun h ↦ h = h2)))
splean
SPLean/Theories/SepLog.lean
[ "import Mathlib.Data.Finmap", "import SPLean.Common.State", "import SPLean.Theories.HProp", "import SPLean.Common.Util", "import Mathlib.Data.Multiset.Nodup", "import SPLean.Theories.XSimp", "import Mathlib.Data.Finset.Basic" ]
[ { "name": "String", "module": "Init.Prelude" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "Finmap", "module": "Mathlib.Data.Finmap" }, { "name": "BEq", "module": "Init.Prelude" }, { "name": "List", "module": "Init.Prelude" }, { "name": "Repr", "module": "Init.Data.Repr" }, { "name": "Vector", "module": "Init.Data.Vector.Basic" }, { "name": "bool", "module": "Init.Control.Basic" }, { "name": "ite", "module": "Init.Prelude" }, { "name": "Computation", "module": "Mathlib.Data.Seq.Computation" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "Max", "module": "Init.Prelude" }, { "name": "Max.max", "module": "Init.Prelude" }, { "name": "Finmap.Disjoint", "module": "Mathlib.Data.Finmap" }, { "name": "t", "module": "Ssreflect.IntroPats" }, { "name": "Finmap.insert", "module": "Mathlib.Data.Finmap" }, { "name": "elim", "module": "Ssreflect.Elim" }, { "name": "move", "module": "Ssreflect.Basic" }, { "name": "sby", "module": "Ssreflect.Done" }, { "name": "srw", "module": "Ssreflect.Rewrite" }, { "name": "Finmap.lookup", "module": "Mathlib.Data.Finmap" } ]
[ { "name": "syntax \"fun\" ident+ \" => \" lang : lang", "content": "syntax \"fun\" ident+ \" => \" lang : lang\n\nsyntax \"⟨\" term \"⟩\" : lang\n\nsyntax \"⟨\" term \":\" term \"⟩\" : lang" }, { "name": "macro_rules", "content": "macro_rules\n | `([lang| ()]) => `(trm_val (val_unit))\n | `([lang| $n:num]) => `(trm_val (val_int $n))\n | `([lang| $t1 $t2]) => `(trm_app [lang| $t1] [lang| $t2])\n | `([lang| if $t1 then $t2 else $t3]) => `(trm_if [lang| $t1] [lang| $t2] [lang| $t3])\n | `([lang| if $t1 then $t2 end]) => `(trm_if [lang| $t1] [lang| $t2] (trm_val val_unit))\n | `([lang| let $x := $t1:lang in $t2:lang]) =>\n `(trm_let $(%x) [lang| $t1] [lang| $t2])\n | `([lang| ref $x := $t1:lang in $t2:lang]) =>\n `(trm_ref $(%x) [lang| $t1] [lang| $t2])\n | `([lang| alloc $t1:lang as $x in $t2:lang]) =>\n `(trm_alloc $(%x) [lang| $t1] [lang| $t2])\n | `([lang| $t1 ; $t2]) => `(trm_seq [lang| $t1] [lang| $t2])\n | `([lang| fun_ $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(trm_funs [ $xs,* ] [lang| $t])\n | `([lang| fun $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(val_funs [ $xs,* ] [lang| $t])\n | `([lang| fix_ $f $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(trm_fixs $(%f) [ $xs,* ] [lang| $t])\n | `([lang| fix $f $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(val_fixs $(%f) [ $xs,* ] [lang| $t])\n \n | `([lang| free $t]) => `(trm_val (val_prim val_free) [lang| $t])\n | `([lang| not $t]) => `(trm_val (val_prim val_not) [lang| $t])\n \n | `([lang| !$t]) => `(trm_val val_get [lang| $t])\n | `([lang| $t1 := $t2]) => `(trm_val val_set [lang| $t1] [lang| $t2])\n | `([lang| $t1 + $t2]) => `(trm_val val_add [lang| $t1] [lang| $t2])\n | `([lang| $t1 * $t2]) => `(trm_val val_mul [lang| $t1] [lang| $t2])\n | `([lang| $t1 - $t2]) => `(trm_val val_sub [lang| $t1] [lang| $t2])\n | `([lang| $t1 / $t2]) => `(trm_val val_div [lang| $t1] [lang| $t2])\n | `([lang| $t1 < $t2]) => `(trm_val val_lt [lang| $t1] [lang| $t2])\n | `([lang| $t1 > $t2]) => `(trm_val val_gt [lang| $t1] [lang| $t2])\n | `([lang| $t1 <= $t2]) => `(trm_val val_le [lang| $t1] [lang| $t2])\n | `([lang| $t1 >= $t2]) => `(trm_val val_ge [lang| $t1] [lang| $t2])\n | `([lang| -$t]) => `(trm_val val_opp [lang| $t])\n | `([lang| $t1 = $t2]) => `(trm_val val_eq [lang| $t1] [lang| $t2])\n | `([lang| $t1 != $t2]) => `(trm_val val_neq [lang| $t1] [lang| $t2])\n | `([lang| $t1 mod $t2]) => `(trm_val val_mod [lang| $t1] [lang| $t2])\n | `([lang| $t1 ++ $t2]) => `(trm_val val_ptr_add [lang| $t1] [lang| $t2])\n | `([lang| ($t)]) => `([lang| $t])\n | `([lang| ⟨$t : $tp⟩]) => `(trm_val (($t : $tp)))\n | `([lang| for $x in [$n1 : $n2] { $t } ]) =>\n `(trm_for $(%x) [lang| $n1] [lang| $n2] [lang| $t])\n | `([lang| while $c:lang { $t:lang } ]) =>\n `(trm_while [lang| $c] [lang| $t] )" }, { "name": "macro_rules", "content": "macro_rules\n | `([lang| len $p]) => `(trm_val val_array_length [lang| $p])\n | `([lang| $arr[$i] ]) => `(trm_val val_array_get [lang| $arr] [lang| $i])\n \n | `([lang| $arr[$i] := $v]) => `(trm_app val_array_set [lang| $arr] [lang| $i] [lang| $v])\n | `([lang| mkarr $n:lang $v:lang]) => `(trm_val val_array_make [lang| $n] [lang| $v])" }, { "name": "heap", "content": "abbrev heap := Heap.heap val\n\n inductive val : Type where\n | val_unit : val\n | val_bool : Bool β†’ val\n | val_int : Int β†’ val\n | val_real : ℝ β†’ val\n | val_loc : loc β†’ val\n | val_prim : prim β†’ val\n | val_fun : var -> trm -> val\n | val_fix : var -> var -> trm -> val\n | val_uninit : val\n | val_error : val" }, { "name": "prim", "content": "inductive prim where\n \n | val_get : prim\n | val_set : prim\n \n | val_neg : prim\n | val_opp : prim\n | val_eq : prim\n | val_add : prim\n | val_neq : prim\n | val_sub : prim\n | val_mul : prim\n | val_div : prim\n | val_mod : prim\n \n | val_le : prim\n | val_lt : prim\n | val_ge : prim\n | val_gt : prim\n | val_ptr_add : prim\n\n inductive trm : Type where\n | trm_val : val -> trm\n | trm_var : var -> trm\n | trm_fun : var -> trm -> trm\n | trm_fix : var -> var -> trm -> trm\n | trm_app : trm -> trm -> trm\n | trm_seq : trm -> trm -> trm\n | trm_let : var -> trm -> trm -> trm\n | trm_if : trm -> trm -> trm -> trm\n | trm_for : var -> trm -> trm -> trm -> trm\n | trm_while : trm -> trm -> trm\n | trm_ref : var β†’ trm β†’ trm β†’ trm\n | trm_alloc : var β†’ trm β†’ trm β†’ trm" }, { "name": "var", "content": "abbrev var := String" }, { "name": "loc", "content": "abbrev loc := Nat" }, { "name": "Heap.heap", "content": "abbrev Heap.heap (val : Type) := Finmap (Ξ» _ : loc ↦ val)" }, { "name": "hProp", "content": "def hProp := heap -> Prop" }, { "name": "state", "content": "abbrev state := Finmap (Ξ» _ : loc ↦ val)" }, { "name": "eval", "content": "inductive eval : state β†’ trm β†’ (val β†’ state β†’ Prop) -> Prop where\n | eval_val : forall s v Q,\n Q v s ->\n eval s (trm_val v) Q\n | eval_fun : forall s x t1 Q,\n Q (val_fun x t1) s ->\n eval s (trm_fun x t1) Q\n | eval_fix : forall s f x t1 Q,\n Q (val_fix f x t1) s ->\n eval s (trm_fix f x t1) Q\n | eval_app_arg1 : forall s1 t1 t2 Q1 Q,\n Β¬ trm_is_val t1 ->\n eval s1 t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> eval s2 (trm_app v1 t2) Q) ->\n eval s1 (trm_app t1 t2) Q\n | eval_app_arg2 : forall s1 (v1 : val) t2 Q1 Q,\n Β¬ trm_is_val t2 ->\n eval s1 t2 Q1 ->\n (forall v2 s2, Q1 v2 s2 -> eval s2 (trm_app v1 v2) Q) ->\n eval s1 (trm_app v1 t2) Q\n | eval_app_fun : forall s1 v1 (v2 :val) x t1 Q,\n v1 = val_fun x t1 ->\n eval s1 (subst x v2 t1) Q ->\n eval s1 (trm_app v1 v2) Q\n | eval_app_fix : forall s (v1 v2 : val) f x t1 Q,\n v1 = val_fix f x t1 ->\n eval s (subst x v2 (subst f v1 t1)) Q ->\n eval s (trm_app v1 v2) Q\n | eval_seq : forall Q1 s t1 t2 Q,\n eval s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> eval s2 t2 Q) ->\n eval s (trm_seq t1 t2) Q\n | eval_let : forall Q1 s x t1 t2 Q,\n eval s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> eval s2 (subst x v1 t2) Q) ->\n eval s (trm_let x t1 t2) Q\n | eval_if : forall s (b : Bool) t1 t2 Q,\n eval s (if b then t1 else t2) Q ->\n eval s (trm_if (val_bool b) t1 t2) Q\n | eval_unop : forall op s v1 P Q,\n evalunop op v1 P ->\n purepostin s P Q ->\n eval s (trm_app op v1) Q\n | eval_binop : forall op s (v1 v2 : val) P Q,\n evalbinop op v1 v2 P ->\n purepostin s P Q ->\n eval s (trm_app (trm_app op v1) v2) Q\n | eval_ref : forall s x t1 t2 (Q Q₁ : val β†’ state β†’ Prop),\n eval s t1 Q₁ β†’\n (βˆ€ v1 s1, Q₁ v1 s1 β†’ βˆ€ p βˆ‰ s1,\n eval (s1.insert p v1) (subst x p t2) fun v s ↦ Q v (s.erase p)) β†’\n eval s (trm_ref x t1 t2) Q\n | eval_get : forall s p Q,\n p ∈ s ->\n Q (read_state p s) s ->\n eval s (trm_app val_get (val_loc p)) Q\n | eval_set : forall s p v Q,\n v = trm_val v' ->\n p ∈ s ->\n Q val_unit (Finmap.insert p v' s) ->\n eval s (trm_app (trm_app val_set (val_loc p)) v) Q\n | eval_alloc_arg : forall s Q₁ Q,\n Β¬ trm_is_val t1 β†’\n eval s t1 Q₁ β†’\n (βˆ€ v' s', Q₁ v' s' β†’ eval s' (trm_alloc x v' t2) Q) β†’\n eval s (trm_alloc x t1 t2) Q\n | eval_alloc : forall (sa : state) (n : β„€) Q,\n n β‰₯ 0 β†’\n (βˆ€ (p : loc) (sb : state),\n sb = conseq (make_list n.natAbs val_uninit) p β†’\n p β‰  null β†’\n Finmap.Disjoint sa sb β†’\n eval (sb βˆͺ sa) (subst x p t2) fun v s ↦ Q v (s \\ sb)) β†’\n eval sa (trm_alloc x n t2) Q\n \n \n \n \n \n \n \n \n | eval_for (n₁ nβ‚‚ : Int) (Q : val -> state -> Prop) :\n eval s (if (n₁ < nβ‚‚) then\n (trm_seq (subst x n₁ t₁) (trm_for x (val_int (n₁ + 1)) nβ‚‚ t₁))\n else val_unit) Q ->\n eval s (trm_for x n₁ nβ‚‚ t₁) Q\n | eval_while (t₁ tβ‚‚ : trm) (Q : val -> state -> Prop) :\n eval s t₁ Q₁ ->\n (βˆ€ s v, Q₁ v s -> eval s (trm_if v (trm_seq tβ‚‚ (trm_while t₁ tβ‚‚)) val_unit) Q) ->\n eval s (trm_while t₁ tβ‚‚) Q" }, { "name": "HStar", "content": "class HStar (Ξ± : Type u) (Ξ² : Type v) (Ξ³ : outParam (Type w)) where\n \n hStar : Ξ± β†’ Ξ² β†’ Ξ³" }, { "name": "qimpl", "content": "def qimpl {A} (Q1 Q2 : A β†’ hProp) : Prop :=\n forall (v:A), Q1 v ==> Q2 v" }, { "name": "himpl", "content": "abbrev himpl (H1 H2 : hProp) : Prop :=\n forall h, H1 h -> H2 h" }, { "name": "purepostin", "content": "def purepostin (s : state) (P : val β†’ Prop) (Q : val β†’ state β†’ Prop) : Prop :=\n \n forall v, P v β†’ Q v s" }, { "name": "evalExact", "content": "inductive evalExact : state β†’ trm β†’ (val β†’ state β†’ Prop) -> Prop where\n | val : forall s v,\n evalExact s (trm_val v) (fun v' s' ↦ v' = v ∧ s' = s)\n | fun : forall s x t1,\n evalExact s (trm_fun x t1) (fun v' s' ↦ v' = val_fun x t1 ∧ s' = s)\n | fix : forall s f x t1,\n evalExact s (trm_fix f x t1) (fun v' s' ↦ v' = val_fix f x t1 ∧ s' = s)\n | app_arg1 : forall s1 t1 t2 Q1 Q,\n Β¬ trm_is_val t1 ->\n evalExact s1 t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 (trm_app v1 t2) Q) ->\n evalExact s1 (trm_app t1 t2) Q\n | app_arg2 : forall s1 (v1 : val) t2 Q1 Q,\n Β¬ trm_is_val t2 ->\n evalExact s1 t2 Q1 ->\n (forall v2 s2, Q1 v2 s2 -> evalExact s2 (trm_app v1 v2) Q) ->\n evalExact s1 (trm_app v1 t2) Q\n | app_fun : forall s1 v1 (v2 :val) x t1 Q,\n v1 = val_fun x t1 ->\n evalExact s1 (subst x v2 t1) Q ->\n evalExact s1 (trm_app v1 v2) Q\n | app_fix : forall s (v1 v2 : val) f x t1 Q,\n v1 = val_fix f x t1 ->\n evalExact s (subst x v2 (subst f v1 t1)) Q ->\n evalExact s (trm_app v1 v2) Q\n | seq : forall Q1 s t1 t2 Q,\n evalExact s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 t2 Q) ->\n evalExact s (trm_seq t1 t2) Q\n | let : forall Q1 s x t1 t2 Q,\n evalExact s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 (subst x v1 t2) Q) ->\n evalExact s (trm_let x t1 t2) Q\n | if : forall s (b : Bool) t1 t2 Q,\n evalExact s (if b then t1 else t2) Q ->\n evalExact s (trm_if (val_bool b) t1 t2) Q\n | unop : forall op s v1 P,\n evalunop op v1 P ->\n evalExact s (trm_app op v1) (purepost s P)\n | binop : forall op s (v1 v2 : val) P,\n evalbinop op v1 v2 P ->\n evalExact s (trm_app (trm_app op v1) v2) (purepost s P)\n | ref : forall s x t1 t2 Q Q₁,\n evalExact s t1 Q₁ β†’\n (βˆ€ v1 s1, Q₁ v1 s1 β†’ βˆ€ p βˆ‰ s1,\n evalExact (s1.insert p v1) (subst x p t2) fun v s ↦ Q v (s.erase p)) β†’\n evalExact s (trm_ref x t1 t2) Q\n | get : forall s p,\n p ∈ s ->\n evalExact s (trm_app val_get (val_loc p))\n (fun v' s' ↦ v' = read_state p s ∧ s' = s)\n | set : forall s p v,\n v = trm_val v' ->\n p ∈ s ->\n evalExact s (trm_app (trm_app val_set (val_loc p)) v)\n (fun v'' s' ↦ v'' = val_unit ∧ s' = s.insert p v')\n | alloc_arg : forall s Q₁ Q,\n Β¬ trm_is_val t1 β†’\n evalExact s t1 Q₁ β†’\n (βˆ€ v' s', Q₁ v' s' β†’ evalExact s' (trm_alloc x v' t2) Q) β†’\n evalExact s (trm_alloc x t1 t2) Q\n | alloc : forall (sa : state) (n : β„€) Q,\n n β‰₯ 0 β†’\n (βˆ€ (p : loc) (sb : state),\n sb = conseq (make_list n.natAbs val_uninit) p β†’\n p β‰  null β†’\n Finmap.Disjoint sa sb β†’\n evalExact (sb βˆͺ sa) (subst x p t2) fun v s ↦ Q v (s \\ sb)) β†’\n evalExact sa (trm_alloc x n t2) Q\n \n \n \n \n \n \n | for (n₁ nβ‚‚ : Int) (Q : val -> state -> Prop) :\n evalExact s (if (n₁ < nβ‚‚) then\n (trm_seq (subst x n₁ t₁) (trm_for x (val_int (n₁ + 1)) nβ‚‚ t₁))\n else val_unit) Q ->\n evalExact s (trm_for x n₁ nβ‚‚ t₁) Q\n | while (t₁ tβ‚‚ : trm) (Q Q₁ : val -> state -> Prop) :\n evalExact s t₁ Q₁ ->\n (βˆ€ s v, Q₁ v s -> evalExact s (trm_if v (trm_seq tβ‚‚ (trm_while t₁ tβ‚‚)) val_unit) Q) ->\n evalExact s (trm_while t₁ tβ‚‚) Q" }, { "name": "read_state", "content": "def read_state (p : loc) (h : state) :=\n match Finmap.lookup p h with\n | some v => v\n | none => default" }, { "name": "infixr:51 \" ==> \" => himpl", "content": "infixr:51 \" ==> \" => himpl" }, { "name": "infixr:51 \" ===> \" => qimpl", "content": "infixr:51 \" ===> \" => qimpl" }, { "name": "infixr:55 \" βˆ— \" => HStar.hStar", "content": "infixr:55 \" βˆ— \" => HStar.hStar" } ]
[ { "name": "Finmap.disjoint_union_left", "module": "Mathlib.Data.Finmap" }, { "name": "Finmap.insert_union", "module": "Mathlib.Data.Finmap" }, { "name": "Finmap.union_assoc", "module": "Mathlib.Data.Finmap" } ]
[ { "name": "union_diff_disjoint_r", "content": "lemma union_diff_disjoint_r (h₁ hβ‚‚ h₃ : state) :\n hβ‚‚.Disjoint h₃ β†’\n (h₁ βˆͺ hβ‚‚) \\ h₃ = (h₁ \\ h₃) βˆͺ hβ‚‚" }, { "name": "lookup_diff", "content": "lemma lookup_diff (h₁ hβ‚‚ : state) :\n p βˆ‰ hβ‚‚ β†’\n (h₁ \\ hβ‚‚).lookup p = h₁.lookup p" }, { "name": "lookup_diff_none", "content": "lemma lookup_diff_none (h₁ hβ‚‚ : state) :\n p ∈ hβ‚‚ β†’\n (h₁ \\ hβ‚‚).lookup p = none" }, { "name": "diff_non_mem", "content": "theorem diff_non_mem (h₁ hβ‚‚ : state) :\n p ∈ hβ‚‚ β†’ p βˆ‰ h₁ \\ hβ‚‚" }, { "name": "disjoint_update_not_r", "content": "lemma disjoint_update_not_r (h1 h2 : state) (x : loc) (v: val) :\n Finmap.Disjoint h1 h2 β†’\n x βˆ‰ h2 β†’\n Finmap.Disjoint (Finmap.insert x v h1) h2" }, { "name": "in_read_union_l", "content": "lemma in_read_union_l (h1 h2 : state) (x : loc) :\n x ∈ h1 β†’ read_state x (h1 βˆͺ h2) = read_state x h1" }, { "name": "remove_not_in_r", "content": "lemma remove_not_in_r (h1 h2 : state) (p : loc) :\n p βˆ‰ h2 β†’\n (h1 βˆͺ h2).erase p = h1.erase p βˆͺ h2" }, { "name": "disjoint_insert_l", "content": "lemma disjoint_insert_l (h1 h2 : state) (x : loc) (v : val) :\n Finmap.Disjoint h1 h2 β†’\n x ∈ h1 β†’\n Finmap.Disjoint (Finmap.insert x v h1) h2" }, { "name": "disjoint_disjoint_diff", "content": "lemma disjoint_disjoint_diff (h₁ hβ‚‚ h₃ : state) :\n h₁.Disjoint hβ‚‚ β†’\n (h₁ \\ h₃).Disjoint hβ‚‚" }, { "name": "erase_disjoint", "content": "lemma erase_disjoint (h1 h2 : state) (p : loc) :\n h1.Disjoint h2 β†’\n (h1.erase p).Disjoint h2" } ]
[ { "name": "tohProp", "content": "abbrev tohProp (h : heap -> Prop) : hProp := h" }, { "name": "ofhProp", "content": "abbrev ofhProp (h : val -> hProp) : val -> heap -> Prop := h" } ]
[ { "name": "eval_conseq", "content": "lemma eval_conseq s t Q1 Q2 :\n eval s t Q1 β†’\n Q1 ===> Q2 β†’\n eval s t Q2" } ]
import Mathlib.Data.Finmap import Mathlib.Data.Finset.Basic import Mathlib.Data.Multiset.Nodup import SPLean.Common.State import SPLean.Common.Util import SPLean.Theories.HProp import SPLean.Theories.XSimp open trm val prim notation "funloc" p "↦" H => fun (r : val) ↦ hexists (fun p ↦ ⌜r = val_loc p⌝ βˆ— H) section evalProp abbrev tohProp (h : heap -> Prop) : hProp := h abbrev ofhProp (h : val -> hProp) : val -> heap -> Prop := h
lemma eval_frame (h1 h2 : state) t (Q : val -> hProp) : eval h1 t (ofhProp Q) β†’ Finmap.Disjoint h1 h2 β†’ eval (h1 βˆͺ h2) t (Q βˆ— (tohProp (fun h ↦ h = h2))) :=
:= by unfold ofhProp tohProp; elim=> // { move=> > ?? _ ih' *; apply eval.eval_app_arg1=> // move=> > ![] ?? ? -> ? ->; aesop } { move=> *; apply eval.eval_app_arg2=> // move=> > ![] ?? ? -> ? ->; aesop } { move=> *; apply eval.eval_app_fun=> // } { move=> *; apply eval.eval_app_fix=> // } { move=> *; apply eval.eval_seq=> // move=> > ![] ?? ? -> ? ->; aesop } { move=> *; apply eval.eval_let=> // move=> > ![] ?? ? -> ? ->; aesop } { move=> > ? Pp *; apply eval.eval_unop=> // move=> ? /Pp ?; exists s, h2 } { move=> > ? Pp *; apply eval.eval_binop=> // move=> ? /Pp ?; exists s, h2 } { move=> > ? _ dj ih' ? constructor; apply dj=> // move=> > ![] s1 ? ? -> dj' -> p /== ?? rw [@Finmap.insert_union] apply eval_conseq; apply ih'=> // { sby apply disjoint_update_not_r s1 h2 p v1 dj' } move=> v s /= ![] h ? /== ? -> ? -> rw [remove_not_in_r h h2 p]=> // exists (h.erase p), h2=> ⟨|⟩//⟨|⟩//⟨|⟩// sby apply erase_disjoint h h2 p } { move=> > *; apply eval.eval_get simp; aesop; exists s, h2=> ⟨|⟩// sby rw [in_read_union_l s h2 p] } { move=> > *; apply eval.eval_set=> // exists (Finmap.insert p v' s), h2=> ⟨|⟩// ⟨|⟩// ⟨|⟩ { apply disjoint_insert_l s h2 p v'=> // } rw [@Finmap.insert_union] } { move=> *; apply eval.eval_alloc_arg=> // move=> > ![] ??? -> ? ->; aesop } { move=> > ? ih ih' dj apply eval.eval_alloc=> // > ?? dj'; srw -Finmap.union_assoc; apply eval_conseq; apply ih'=> // { move: dj'; sby rw [@Finmap.disjoint_union_left] } { move: dj'; srw ?Finmap.disjoint_union_left /===> ? ? ⟨|⟩// sby apply (Finmap.Disjoint.symm h2 sb) } move=> > /= ? /= ![] s ? /= ? -> ? -> exists (s \ sb), h2=> ⟨|⟩//⟨|⟩//⟨|⟩ { sby apply disjoint_disjoint_diff s h2 sb } apply union_diff_disjoint_r=> // move: dj'; sby rw [@Finmap.disjoint_union_left] } move=> *; constructor=> // ?? ![] ??? -> ? ->; aesop
6
55
false
Framework
404
evalExact_WellAlloc
lemma evalExact_WellAlloc : evalExact s t Q β†’ Q v s' β†’ s'.keys = s.keys
splean
SPLean/Theories/SepLog.lean
[ "import Mathlib.Data.Finmap", "import SPLean.Common.State", "import SPLean.Theories.HProp", "import SPLean.Common.Util", "import Mathlib.Data.Multiset.Nodup", "import SPLean.Theories.XSimp", "import Mathlib.Data.Finset.Basic" ]
[ { "name": "List", "module": "Init.Prelude" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "String", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "Finmap", "module": "Mathlib.Data.Finmap" }, { "name": "Finmap.singleton", "module": "Mathlib.Data.Finmap" }, { "name": "Int.natAbs", "module": "Init.Data.Int.Basic" }, { "name": "Finmap.lookup", "module": "Mathlib.Data.Finmap" }, { "name": "Finmap.Disjoint", "module": "Mathlib.Data.Finmap" }, { "name": "seq", "module": "Talk.DemoLeanSSR" }, { "name": "t", "module": "Ssreflect.IntroPats" }, { "name": "elim", "module": "Ssreflect.Elim" }, { "name": "move", "module": "Ssreflect.Basic" }, { "name": "sby", "module": "Ssreflect.Done" }, { "name": "scase", "module": "Ssreflect.Elim" }, { "name": "sdone", "module": "Ssreflect.Done" }, { "name": "srw", "module": "Ssreflect.Rewrite" }, { "name": "sapply", "module": "Ssreflect.ApplyIn" }, { "name": "Finset", "module": "Mathlib.Data.Finset.Defs" }, { "name": "Not", "module": "Init.Prelude" } ]
[ { "name": "syntax \"fun\" ident+ \" => \" lang : lang", "content": "syntax \"fun\" ident+ \" => \" lang : lang\n\nsyntax \"if \" lang \"then \" lang \"end \" : lang\n\nsyntax \" <= \" : bop\n\nsyntax \" >= \" : bop\n\nsyntax \"not\" : uop\n\nsyntax \" := \" : bop\n\nsyntax \"let\" ident \" := \" lang \" in\" ppDedent(ppLine lang) : lang\n\nsyntax \"ref\" ident \" := \" lang \" in\" ppDedent(ppLine lang) : lang\n\nsyntax \"fix\" ident ident+ \" => \" lang : lang\n\nsyntax \"for\" ident \" in \" \"[\" lang \" : \" lang \"]\" \" {\" (ppLine lang) ( \" }\") : lang\n\nsyntax \"while\" lang \" {\" (ppLine lang) ( \" }\") : lang\n\nsyntax \"alloc\" lang \" as \" ident \" in\" ppDedent(ppLine lang) : lang\n\nsyntax \"⟨\" term \"⟩\" : lang\n\nsyntax \"⟨\" term \":\" term \"⟩\" : lang\n\n syntax \"sdo\" num tactic : tactic" }, { "name": "macro_rules", "content": "macro_rules\n | `(term| {| $seq |}) => `(withMainContext do evalTactic $ <- `(tacticSeq| $seq))" }, { "name": "macro_rules", "content": "macro_rules\n | `([lang| ()]) => `(trm_val (val_unit))\n | `([lang| $n:num]) => `(trm_val (val_int $n))\n | `([lang| $t1 $t2]) => `(trm_app [lang| $t1] [lang| $t2])\n | `([lang| if $t1 then $t2 else $t3]) => `(trm_if [lang| $t1] [lang| $t2] [lang| $t3])\n | `([lang| if $t1 then $t2 end]) => `(trm_if [lang| $t1] [lang| $t2] (trm_val val_unit))\n | `([lang| let $x := $t1:lang in $t2:lang]) =>\n `(trm_let $(%x) [lang| $t1] [lang| $t2])\n | `([lang| ref $x := $t1:lang in $t2:lang]) =>\n `(trm_ref $(%x) [lang| $t1] [lang| $t2])\n | `([lang| alloc $t1:lang as $x in $t2:lang]) =>\n `(trm_alloc $(%x) [lang| $t1] [lang| $t2])\n | `([lang| $t1 ; $t2]) => `(trm_seq [lang| $t1] [lang| $t2])\n | `([lang| fun_ $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(trm_funs [ $xs,* ] [lang| $t])\n | `([lang| fun $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(val_funs [ $xs,* ] [lang| $t])\n | `([lang| fix_ $f $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(trm_fixs $(%f) [ $xs,* ] [lang| $t])\n | `([lang| fix $f $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(val_fixs $(%f) [ $xs,* ] [lang| $t])\n \n | `([lang| free $t]) => `(trm_val (val_prim val_free) [lang| $t])\n | `([lang| not $t]) => `(trm_val (val_prim val_not) [lang| $t])\n \n | `([lang| !$t]) => `(trm_val val_get [lang| $t])\n | `([lang| $t1 := $t2]) => `(trm_val val_set [lang| $t1] [lang| $t2])\n | `([lang| $t1 + $t2]) => `(trm_val val_add [lang| $t1] [lang| $t2])\n | `([lang| $t1 * $t2]) => `(trm_val val_mul [lang| $t1] [lang| $t2])\n | `([lang| $t1 - $t2]) => `(trm_val val_sub [lang| $t1] [lang| $t2])\n | `([lang| $t1 / $t2]) => `(trm_val val_div [lang| $t1] [lang| $t2])\n | `([lang| $t1 < $t2]) => `(trm_val val_lt [lang| $t1] [lang| $t2])\n | `([lang| $t1 > $t2]) => `(trm_val val_gt [lang| $t1] [lang| $t2])\n | `([lang| $t1 <= $t2]) => `(trm_val val_le [lang| $t1] [lang| $t2])\n | `([lang| $t1 >= $t2]) => `(trm_val val_ge [lang| $t1] [lang| $t2])\n | `([lang| -$t]) => `(trm_val val_opp [lang| $t])\n | `([lang| $t1 = $t2]) => `(trm_val val_eq [lang| $t1] [lang| $t2])\n | `([lang| $t1 != $t2]) => `(trm_val val_neq [lang| $t1] [lang| $t2])\n | `([lang| $t1 mod $t2]) => `(trm_val val_mod [lang| $t1] [lang| $t2])\n | `([lang| $t1 ++ $t2]) => `(trm_val val_ptr_add [lang| $t1] [lang| $t2])\n | `([lang| ($t)]) => `([lang| $t])\n | `([lang| ⟨$t : $tp⟩]) => `(trm_val (($t : $tp)))\n | `([lang| for $x in [$n1 : $n2] { $t } ]) =>\n `(trm_for $(%x) [lang| $n1] [lang| $n2] [lang| $t])\n | `([lang| while $c:lang { $t:lang } ]) =>\n `(trm_while [lang| $c] [lang| $t] )" }, { "name": "macro_rules", "content": "macro_rules\n | `([lang| len $p]) => `(trm_val val_array_length [lang| $p])\n | `([lang| $arr[$i] ]) => `(trm_val val_array_get [lang| $arr] [lang| $i])\n \n | `([lang| $arr[$i] := $v]) => `(trm_app val_array_set [lang| $arr] [lang| $i] [lang| $v])\n | `([lang| mkarr $n:lang $v:lang]) => `(trm_val val_array_make [lang| $n] [lang| $v])" }, { "name": "evalExact", "content": "inductive evalExact : state β†’ trm β†’ (val β†’ state β†’ Prop) -> Prop where\n | val : forall s v,\n evalExact s (trm_val v) (fun v' s' ↦ v' = v ∧ s' = s)\n | fun : forall s x t1,\n evalExact s (trm_fun x t1) (fun v' s' ↦ v' = val_fun x t1 ∧ s' = s)\n | fix : forall s f x t1,\n evalExact s (trm_fix f x t1) (fun v' s' ↦ v' = val_fix f x t1 ∧ s' = s)\n | app_arg1 : forall s1 t1 t2 Q1 Q,\n Β¬ trm_is_val t1 ->\n evalExact s1 t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 (trm_app v1 t2) Q) ->\n evalExact s1 (trm_app t1 t2) Q\n | app_arg2 : forall s1 (v1 : val) t2 Q1 Q,\n Β¬ trm_is_val t2 ->\n evalExact s1 t2 Q1 ->\n (forall v2 s2, Q1 v2 s2 -> evalExact s2 (trm_app v1 v2) Q) ->\n evalExact s1 (trm_app v1 t2) Q\n | app_fun : forall s1 v1 (v2 :val) x t1 Q,\n v1 = val_fun x t1 ->\n evalExact s1 (subst x v2 t1) Q ->\n evalExact s1 (trm_app v1 v2) Q\n | app_fix : forall s (v1 v2 : val) f x t1 Q,\n v1 = val_fix f x t1 ->\n evalExact s (subst x v2 (subst f v1 t1)) Q ->\n evalExact s (trm_app v1 v2) Q\n | seq : forall Q1 s t1 t2 Q,\n evalExact s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 t2 Q) ->\n evalExact s (trm_seq t1 t2) Q\n | let : forall Q1 s x t1 t2 Q,\n evalExact s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 (subst x v1 t2) Q) ->\n evalExact s (trm_let x t1 t2) Q\n | if : forall s (b : Bool) t1 t2 Q,\n evalExact s (if b then t1 else t2) Q ->\n evalExact s (trm_if (val_bool b) t1 t2) Q\n | unop : forall op s v1 P,\n evalunop op v1 P ->\n evalExact s (trm_app op v1) (purepost s P)\n | binop : forall op s (v1 v2 : val) P,\n evalbinop op v1 v2 P ->\n evalExact s (trm_app (trm_app op v1) v2) (purepost s P)\n | ref : forall s x t1 t2 Q Q₁,\n evalExact s t1 Q₁ β†’\n (βˆ€ v1 s1, Q₁ v1 s1 β†’ βˆ€ p βˆ‰ s1,\n evalExact (s1.insert p v1) (subst x p t2) fun v s ↦ Q v (s.erase p)) β†’\n evalExact s (trm_ref x t1 t2) Q\n | get : forall s p,\n p ∈ s ->\n evalExact s (trm_app val_get (val_loc p))\n (fun v' s' ↦ v' = read_state p s ∧ s' = s)\n | set : forall s p v,\n v = trm_val v' ->\n p ∈ s ->\n evalExact s (trm_app (trm_app val_set (val_loc p)) v)\n (fun v'' s' ↦ v'' = val_unit ∧ s' = s.insert p v')\n | alloc_arg : forall s Q₁ Q,\n Β¬ trm_is_val t1 β†’\n evalExact s t1 Q₁ β†’\n (βˆ€ v' s', Q₁ v' s' β†’ evalExact s' (trm_alloc x v' t2) Q) β†’\n evalExact s (trm_alloc x t1 t2) Q\n | alloc : forall (sa : state) (n : β„€) Q,\n n β‰₯ 0 β†’\n (βˆ€ (p : loc) (sb : state),\n sb = conseq (make_list n.natAbs val_uninit) p β†’\n p β‰  null β†’\n Finmap.Disjoint sa sb β†’\n evalExact (sb βˆͺ sa) (subst x p t2) fun v s ↦ Q v (s \\ sb)) β†’\n evalExact sa (trm_alloc x n t2) Q\n \n \n \n \n \n \n | for (n₁ nβ‚‚ : Int) (Q : val -> state -> Prop) :\n evalExact s (if (n₁ < nβ‚‚) then\n (trm_seq (subst x n₁ t₁) (trm_for x (val_int (n₁ + 1)) nβ‚‚ t₁))\n else val_unit) Q ->\n evalExact s (trm_for x n₁ nβ‚‚ t₁) Q\n | while (t₁ tβ‚‚ : trm) (Q Q₁ : val -> state -> Prop) :\n evalExact s t₁ Q₁ ->\n (βˆ€ s v, Q₁ v s -> evalExact s (trm_if v (trm_seq tβ‚‚ (trm_while t₁ tβ‚‚)) val_unit) Q) ->\n evalExact s (trm_while t₁ tβ‚‚) Q" }, { "name": "make_list", "content": "def make_list {A} (n : Nat) (v : A) : List A :=\n match n with\n | 0 => []\n | n' + 1 => v :: make_list n' v\n\n inductive trm : Type where\n | trm_val : val -> trm\n | trm_var : var -> trm\n | trm_fun : var -> trm -> trm\n | trm_fix : var -> var -> trm -> trm\n | trm_app : trm -> trm -> trm\n | trm_seq : trm -> trm -> trm\n | trm_let : var -> trm -> trm -> trm\n | trm_if : trm -> trm -> trm -> trm\n | trm_for : var -> trm -> trm -> trm -> trm\n | trm_while : trm -> trm -> trm\n | trm_ref : var β†’ trm β†’ trm β†’ trm\n | trm_alloc : var β†’ trm β†’ trm β†’ trm" }, { "name": "trm_is_val", "content": "abbrev trm_is_val : trm β†’ Prop\n | trm_val _ => true\n | _ => false\n\n inductive val : Type where\n | val_unit : val\n | val_bool : Bool β†’ val\n | val_int : Int β†’ val\n | val_real : ℝ β†’ val\n | val_loc : loc β†’ val\n | val_prim : prim β†’ val\n | val_fun : var -> trm -> val\n | val_fix : var -> var -> trm -> val\n | val_uninit : val\n | val_error : val" }, { "name": "prim", "content": "inductive prim where\n \n | val_get : prim\n | val_set : prim\n \n | val_neg : prim\n | val_opp : prim\n | val_eq : prim\n | val_add : prim\n | val_neq : prim\n | val_sub : prim\n | val_mul : prim\n | val_div : prim\n | val_mod : prim\n \n | val_le : prim\n | val_lt : prim\n | val_ge : prim\n | val_gt : prim\n | val_ptr_add : prim" }, { "name": "var", "content": "abbrev var := String" }, { "name": "loc", "content": "abbrev loc := Nat" }, { "name": "conseq", "content": "def conseq {B : Type} (vs : List B) (l : Nat) : Finmap (fun _ : Nat ↦ B) :=\n match vs with\n | [] => βˆ…\n | v :: vs' => (Finmap.singleton l v) βˆͺ (conseq vs' (l + 1))" }, { "name": "null", "content": "def null : loc := 0" }, { "name": "evalbinop", "content": "inductive evalbinop : val β†’ val β†’ val β†’ (val->Prop) β†’ Prop where\n | evalbinop_eq : forall v1 v2,\n evalbinop val_eq v1 v2 (fun v => v = val_bool (is_true (v1 = v2)))\n | evalbinop_neq : forall v1 v2,\n evalbinop val_neq v1 v2 (fun v => v = val_bool (is_true (v1 β‰  v2)))\n | evalbinop_add : forall n1 n2,\n evalbinop val_add (val_int n1) (val_int n2)\n (fun v => v = val_int (n1 + n2))\n | evalbinop_addr : forall r₁ rβ‚‚,\n evalbinop val_add (val_real r₁) (val_real rβ‚‚)\n (fun v => v = val_real (r₁ + rβ‚‚))\n | evalbinop_sub : forall n1 n2,\n evalbinop val_sub (val_int n1) (val_int n2)\n (fun v => v = val_int (n1 - n2))\n | evalbinop_subr : forall r1 r2,\n evalbinop val_sub (val_real r1) (val_real r2)\n (fun v => v = val_real (r1 - r2))\n | evalbinop_mul : forall n1 n2,\n evalbinop val_mul (val_int n1) (val_int n2)\n (fun v => v = val_int (n1 * n2))\n | evalbinop_mulr : forall r1 r2,\n evalbinop val_mul (val_real r1) (val_real r2)\n (fun v => v = val_real (r1 * r2))\n | evalbinop_div : forall n1 n2,\n Β¬(n2 = 0) β†’\n evalbinop val_div (val_int n1) (val_int n2)\n (fun v => v = val_int (n1 / n2))\n | evalbinop_divr : forall r1 r2,\n Β¬(r2 = 0) β†’\n evalbinop val_div (val_real r1) (val_real r2)\n (fun v => v = val_real (r1 / r2))\n | evalbinop_mod : forall n1 n2,\n Β¬(n2 = 0) β†’\n evalbinop val_mod (val_int n1) (val_int n2)\n (fun v => v = val_int (n1 % n2))\n | evalbinop_le : forall n1 n2,\n evalbinop val_le (val_int n1) (val_int n2)\n (fun v => v = val_bool (n1 <= n2))\n | evalbinop_ler : forall r1 r2,\n evalbinop val_le (val_real r1) (val_real r2)\n (fun v => v = val_bool (r1 <= r2))\n | evalbinop_lt : forall n1 n2,\n evalbinop val_lt (val_int n1) (val_int n2)\n (fun v => v = val_bool (n1 < n2))\n | evalbinop_ltr : forall r1 r2,\n evalbinop val_lt (val_real r1) (val_real r2)\n (fun v => v = val_bool (r1 < r2))\n | evalbinop_ge : forall n1 n2,\n evalbinop val_ge (val_int n1) (val_int n2)\n (fun v => v = val_bool (n1 >= n2))\n | evalbinop_ger : forall r1 r2,\n evalbinop val_ge (val_real r1) (val_real r2)\n (fun v => v = val_bool (r1 >= r2))\n | evalbinop_gt : forall n1 n2,\n evalbinop val_gt (val_int n1) (val_int n2)\n (fun v => v = val_bool (n1 > n2))\n | evalbinop_gtr : forall r1 r2,\n evalbinop val_gt (val_real r1) (val_real r2)\n (fun v => v = val_bool (r1 > r2))\n\n \n \n \n \n | evalbinop_ptr_add : forall (p1 : loc) (p2 : Int) n,\n p2 = p1 + n ->\n evalbinop val_ptr_add (val_loc p1) (val_int n)\n (fun v => v = val_loc (Int.natAbs p2))" }, { "name": "is_true", "content": "noncomputable def is_true (P : Prop) : Bool :=\n if P then true else false" }, { "name": "state", "content": "abbrev state := Finmap (Ξ» _ : loc ↦ val)" }, { "name": "evalunop", "content": "inductive evalunop : prim β†’ val β†’ (val β†’ Prop) β†’ Prop where\n | evalunop_neg : forall b1,\n evalunop val_neg (val_bool b1) (fun v => v = val_bool (Β¬ b1))\n | evalunop_opp : forall n1,\n evalunop val_opp (val_int n1) (fun v => v = val_int (- n1))\n | evalunop_oppr : forall r1,\n evalunop val_opp (val_real r1) (fun v => v = val_real (- r1))" }, { "name": "purepost", "content": "def purepost (s : state) (P : val β†’ Prop) : val β†’ state β†’ Prop :=\n fun v s' => P v ∧ s' = s" }, { "name": "read_state", "content": "def read_state (p : loc) (h : state) :=\n match Finmap.lookup p h with\n | some v => v\n | none => default" }, { "name": "subst", "content": "def subst (y : var) (v' : val) (t : trm) : trm :=\n \n let if_y_eq x t1 t2 := if x = y then t1 else t2\n match t with\n | trm_val v => trm_val v\n | trm_var x => if_y_eq x (trm_val v') t\n | trm_fun x t1 => trm_fun x (if_y_eq x t1 (subst y v' t1))\n | trm_fix f x t1 => trm_fix f x (if_y_eq f t1 (if_y_eq x t1 (subst y v' t1)))\n | trm_app t1 t2 => trm_app (subst y v' t1) (subst y v' t2)\n | trm_seq t1 t2 => trm_seq (subst y v' t1) (subst y v' t2)\n | trm_let x t1 t2 => trm_let x (subst y v' t1) (if_y_eq x t2 (subst y v' t2))\n | trm_if t0 t1 t2 => trm_if (subst y v' t0) (subst y v' t1) (subst y v' t2)\n | trm_for x t1 t2 t3 => trm_for x (subst y v' t1) (subst y v' t2) (if_y_eq x t3 (subst y v' t3))\n | trm_while t1 t2 => trm_while (subst y v' t1) (subst y v' t2)\n | trm_ref x t1 t2 => trm_ref x (subst y v' t1) (if_y_eq x t2 (subst y v' t2))\n | trm_alloc x t1 t2 => trm_alloc x (subst y v' t1) (if_y_eq x t2 (subst y v' t2))" }, { "name": "hempty", "content": "def hempty : hProp :=\n fun h => (h = βˆ…)" }, { "name": "hProp", "content": "def hProp := heap -> Prop" }, { "name": "heap", "content": "abbrev heap := Heap.heap val" }, { "name": "Heap.heap", "content": "abbrev Heap.heap (val : Type) := Finmap (Ξ» _ : loc ↦ val)" }, { "name": "notation:max \"emp\" => hempty", "content": "notation:max \"emp\" => hempty" } ]
[ { "name": "Finmap.mem_keys", "module": "Mathlib.Data.Finmap" }, { "name": "Finset.le_max_of_eq", "module": "Mathlib.Data.Finset.Max" }, { "name": "Finset.max_of_nonempty", "module": "Mathlib.Data.Finset.Max" }, { "name": "Finset.nonempty_iff_ne_empty", "module": "Mathlib.Data.Finset.Empty" }, { "name": "Nat.lt_succ_iff", "module": "Init.Data.Nat.Basic" }, { "name": "Finmap.Disjoint.symm_iff", "module": "Mathlib.Data.Finmap" }, { "name": "Finmap.disjoint_union_left", "module": "Mathlib.Data.Finmap" }, { "name": "Finmap.union_comm_of_disjoint", "module": "Mathlib.Data.Finmap" } ]
[ { "name": "non_mem_union", "content": "lemma non_mem_union (h1 h2 : state) :\n a βˆ‰ h1 βˆͺ h2 ↔ a βˆ‰ h1 ∧ a βˆ‰ h2" }, { "name": "insert_mem_keys", "content": "lemma insert_mem_keys (s : state) :\n p ∈ s β†’\n (s.insert p v).keys = s.keys" }, { "name": "insert_same", "content": "lemma insert_same (h1 h2 : state) :\n p βˆ‰ h1 β†’ p βˆ‰ h2 β†’\n (h1.insert p v).keys = (h2.insert p v').keys β†’\n h1.keys = h2.keys" }, { "name": "union_same_keys", "content": "lemma union_same_keys (h₁ hβ‚‚ h₃ : state) :\n h₁.Disjoint h₃ β†’ hβ‚‚.Disjoint h₃ β†’\n (h₁ βˆͺ h₃).keys = (hβ‚‚ βˆͺ h₃).keys β†’\n h₁.keys = hβ‚‚.keys" }, { "name": "insert_delete_id", "content": "lemma insert_delete_id (h : state) (p : loc) :\n p βˆ‰ h β†’\n h = (h.insert p v).erase p" }, { "name": "union_difference_id", "content": "lemma union_difference_id (h₁ hβ‚‚ : state) :\n h₁.Disjoint hβ‚‚ β†’\n (h₁ βˆͺ hβ‚‚) \\ hβ‚‚ = h₁" }, { "name": "insert_disjoint_l", "content": "lemma insert_disjoint_l (h1 h2 : state) (x : loc) (v : val) :\n h2.Disjoint (h1.insert x v) β†’\n x βˆ‰ h2 ∧ h2.Disjoint h1" }, { "name": "remove_not_in_l", "content": "lemma remove_not_in_l (h1 h2 : state) (p : loc) :\n p βˆ‰ h1 β†’\n (h1 βˆͺ h2).erase p = h1 βˆͺ h2.erase p" } ]
[]
[ { "name": "finite_state", "content": "lemma finite_state (s : state) :\n βˆƒ p, p βˆ‰ s" }, { "name": "conseq_ind", "content": "lemma conseq_ind (n : β„•) (v : val) (p : loc) :\n x ∈ conseq (make_list n v) p β†’ x β‰₯ p" }, { "name": "finite_state'", "content": "lemma finite_state' n (s : state) :\n βˆƒ p, p β‰  null ∧\n Finmap.Disjoint s (conseq (make_list n val_uninit) p)" }, { "name": "evalExact_sat", "content": "lemma evalExact_sat :\n evalExact s t Q β†’ βˆƒ v s, Q v s" } ]
import Mathlib.Data.Finmap import Mathlib.Data.Finset.Basic import Mathlib.Data.Multiset.Nodup import SPLean.Common.State import SPLean.Common.Util import SPLean.Theories.HProp import SPLean.Theories.XSimp open trm val prim notation "funloc" p "↦" H => fun (r : val) ↦ hexists (fun p ↦ ⌜r = val_loc p⌝ βˆ— H) section evalProp
lemma evalExact_WellAlloc : evalExact s t Q β†’ Q v s' β†’ s'.keys = s.keys :=
:= by move=> hev elim: hev s' v { sby move=> > [] } { sby move=> > [] } { sby move=> > [] } { move=> > _ /evalExact_sat ![>] /[dup] hQ1 /[swap] _ /[swap] /[apply] heq move: hQ1=> /[swap] /[apply] /[apply] sby srw heq=> {}heq > /heq } { move=> > _ /evalExact_sat ![>] /[dup] hQ1 /[swap] _ /[swap] /[apply] heq move: hQ1=> /[swap] /[apply] /[apply] sby srw heq=> {}heq > /heq } { sby move=> > _ _ ih > /ih } { sby move=> > _ _ ih > /ih } { move=> > /evalExact_sat ![>] /[dup] hQ1 /[swap] _ /[swap] /[apply] heq move: hQ1=> /[swap] /[apply] /[apply] sby srw heq=> {}heq > /heq } { move=> > /evalExact_sat ![>] /[dup] hQ1 /[swap] _ /[swap] /[apply] heq move: hQ1=> /[swap] /[apply] /[apply] sby srw heq=> {}heq > /heq } { sby move=> > _ ih > /ih } { sby unfold purepost } { sby unfold purepost } { move=> > /evalExact_sat ![>] /[dup] hQ₁ /[swap] /[apply] ? ih1 ih2 > move: hQ₁=> /[dup] hQ₁ /ih1 {}ih1 scase: (finite_state (s' βˆͺ w_1))=> p /non_mem_union [] move=> /[dup] /insert_same hins ? /[dup] /hins {}hins move: hQ₁=> /ih2 /[apply] /== {}ih2 srw [1](insert_delete_id s' p)=> // sby move=> /ih2 /hins } { sdone } { move=> > _ ? > /= [] _ [] sby srw insert_mem_keys } { move=> > _ /evalExact_sat ![>] /[dup] hQ₁ /[swap] _ /[swap] /[apply] ? sby move: hQ₁=> /[swap] /[apply] ih > /ih } { move=> > ? _ ih > scase: (finite_state' n.natAbs (sa βˆͺ s')) move=> p [] /ih /== {}ih /Finmap.disjoint_union_left /[dup] hdisj [] /ih {}ih move=> /union_difference_id heq srw -[1]heq=> /ih srw [2]Finmap.union_comm_of_disjoint ; rotate_left { sby srw Finmap.Disjoint.symm_iff } sby move: hdisj=> [] /[swap] /union_same_keys /[apply] } { sby move=> > _ ih > /ih } move=> > /evalExact_sat ![>] /[dup] hQ1 /[swap] _ /[swap] /[apply] heq move: hQ1=> /[swap] /[apply] /[apply] sby srw heq=> {}heq > /heq
6
62
false
Framework
405
evalExact_post
lemma evalExact_post : eval s t Q β†’ evalExact s t Q' β†’ Q' ===> Q
splean
SPLean/Theories/SepLog.lean
[ "import SPLean.Theories.Lang", "import Mathlib.Data.Multiset.Nodup", "import SPLean.Theories.XSimp", "import Mathlib.Data.Finset.Basic", "import Mathlib.Data.Finmap", "import SPLean.Common.State", "import SPLean.Theories.HProp", "import SPLean.Common.Util" ]
[ { "name": "String", "module": "Init.Prelude" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "Finmap", "module": "Mathlib.Data.Finmap" }, { "name": "List", "module": "Init.Prelude" }, { "name": "Finmap.singleton", "module": "Mathlib.Data.Finmap" }, { "name": "Int.natAbs", "module": "Init.Data.Int.Basic" }, { "name": "Finmap.lookup", "module": "Mathlib.Data.Finmap" }, { "name": "Finmap.Disjoint", "module": "Mathlib.Data.Finmap" }, { "name": "seq", "module": "Talk.DemoLeanSSR" }, { "name": "BEq", "module": "Init.Prelude" }, { "name": "Repr", "module": "Init.Data.Repr" }, { "name": "Vector", "module": "Init.Data.Vector.Basic" }, { "name": "bool", "module": "Init.Control.Basic" }, { "name": "ite", "module": "Init.Prelude" }, { "name": "Computation", "module": "Mathlib.Data.Seq.Computation" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "Max", "module": "Init.Prelude" }, { "name": "Max.max", "module": "Init.Prelude" }, { "name": "t", "module": "Ssreflect.IntroPats" }, { "name": "elim", "module": "Ssreflect.Elim" }, { "name": "move", "module": "Ssreflect.Basic" }, { "name": "sby", "module": "Ssreflect.Done" }, { "name": "scase", "module": "Ssreflect.Elim" }, { "name": "srw", "module": "Ssreflect.Rewrite" }, { "name": "sapply", "module": "Ssreflect.ApplyIn" }, { "name": "Finset", "module": "Mathlib.Data.Finset.Defs" }, { "name": "Not", "module": "Init.Prelude" }, { "name": "sdone", "module": "Ssreflect.Done" } ]
[ { "name": "syntax \"fun\" ident+ \" => \" lang : lang", "content": "syntax \"fun\" ident+ \" => \" lang : lang\n\nsyntax \"if \" lang \"then \" lang \"end \" : lang\n\nsyntax \" <= \" : bop\n\nsyntax \" >= \" : bop\n\nsyntax \"not\" : uop\n\nsyntax \" := \" : bop\n\nsyntax \"let\" ident \" := \" lang \" in\" ppDedent(ppLine lang) : lang\n\nsyntax \"ref\" ident \" := \" lang \" in\" ppDedent(ppLine lang) : lang\n\nsyntax \"fix\" ident ident+ \" => \" lang : lang\n\nsyntax \"for\" ident \" in \" \"[\" lang \" : \" lang \"]\" \" {\" (ppLine lang) ( \" }\") : lang\n\nsyntax \"while\" lang \" {\" (ppLine lang) ( \" }\") : lang\n\nsyntax \"alloc\" lang \" as \" ident \" in\" ppDedent(ppLine lang) : lang\n\nsyntax \"⟨\" term \"⟩\" : lang\n\nsyntax \"⟨\" term \":\" term \"⟩\" : lang" }, { "name": "macro_rules", "content": "macro_rules\n | `([lang| ()]) => `(trm_val (val_unit))\n | `([lang| $n:num]) => `(trm_val (val_int $n))\n | `([lang| $t1 $t2]) => `(trm_app [lang| $t1] [lang| $t2])\n | `([lang| if $t1 then $t2 else $t3]) => `(trm_if [lang| $t1] [lang| $t2] [lang| $t3])\n | `([lang| if $t1 then $t2 end]) => `(trm_if [lang| $t1] [lang| $t2] (trm_val val_unit))\n | `([lang| let $x := $t1:lang in $t2:lang]) =>\n `(trm_let $(%x) [lang| $t1] [lang| $t2])\n | `([lang| ref $x := $t1:lang in $t2:lang]) =>\n `(trm_ref $(%x) [lang| $t1] [lang| $t2])\n | `([lang| alloc $t1:lang as $x in $t2:lang]) =>\n `(trm_alloc $(%x) [lang| $t1] [lang| $t2])\n | `([lang| $t1 ; $t2]) => `(trm_seq [lang| $t1] [lang| $t2])\n | `([lang| fun_ $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(trm_funs [ $xs,* ] [lang| $t])\n | `([lang| fun $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(val_funs [ $xs,* ] [lang| $t])\n | `([lang| fix_ $f $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(trm_fixs $(%f) [ $xs,* ] [lang| $t])\n | `([lang| fix $f $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(val_fixs $(%f) [ $xs,* ] [lang| $t])\n \n | `([lang| free $t]) => `(trm_val (val_prim val_free) [lang| $t])\n | `([lang| not $t]) => `(trm_val (val_prim val_not) [lang| $t])\n \n | `([lang| !$t]) => `(trm_val val_get [lang| $t])\n | `([lang| $t1 := $t2]) => `(trm_val val_set [lang| $t1] [lang| $t2])\n | `([lang| $t1 + $t2]) => `(trm_val val_add [lang| $t1] [lang| $t2])\n | `([lang| $t1 * $t2]) => `(trm_val val_mul [lang| $t1] [lang| $t2])\n | `([lang| $t1 - $t2]) => `(trm_val val_sub [lang| $t1] [lang| $t2])\n | `([lang| $t1 / $t2]) => `(trm_val val_div [lang| $t1] [lang| $t2])\n | `([lang| $t1 < $t2]) => `(trm_val val_lt [lang| $t1] [lang| $t2])\n | `([lang| $t1 > $t2]) => `(trm_val val_gt [lang| $t1] [lang| $t2])\n | `([lang| $t1 <= $t2]) => `(trm_val val_le [lang| $t1] [lang| $t2])\n | `([lang| $t1 >= $t2]) => `(trm_val val_ge [lang| $t1] [lang| $t2])\n | `([lang| -$t]) => `(trm_val val_opp [lang| $t])\n | `([lang| $t1 = $t2]) => `(trm_val val_eq [lang| $t1] [lang| $t2])\n | `([lang| $t1 != $t2]) => `(trm_val val_neq [lang| $t1] [lang| $t2])\n | `([lang| $t1 mod $t2]) => `(trm_val val_mod [lang| $t1] [lang| $t2])\n | `([lang| $t1 ++ $t2]) => `(trm_val val_ptr_add [lang| $t1] [lang| $t2])\n | `([lang| ($t)]) => `([lang| $t])\n | `([lang| ⟨$t : $tp⟩]) => `(trm_val (($t : $tp)))\n | `([lang| for $x in [$n1 : $n2] { $t } ]) =>\n `(trm_for $(%x) [lang| $n1] [lang| $n2] [lang| $t])\n | `([lang| while $c:lang { $t:lang } ]) =>\n `(trm_while [lang| $c] [lang| $t] )" }, { "name": "macro_rules", "content": "macro_rules\n | `([lang| len $p]) => `(trm_val val_array_length [lang| $p])\n | `([lang| $arr[$i] ]) => `(trm_val val_array_get [lang| $arr] [lang| $i])\n \n | `([lang| $arr[$i] := $v]) => `(trm_app val_array_set [lang| $arr] [lang| $i] [lang| $v])\n | `([lang| mkarr $n:lang $v:lang]) => `(trm_val val_array_make [lang| $n] [lang| $v])" }, { "name": "HStar", "content": "class HStar (Ξ± : Type u) (Ξ² : Type v) (Ξ³ : outParam (Type w)) where\n \n hStar : Ξ± β†’ Ξ² β†’ Ξ³" }, { "name": "purepostin", "content": "def purepostin (s : state) (P : val β†’ Prop) (Q : val β†’ state β†’ Prop) : Prop :=\n \n forall v, P v β†’ Q v s" }, { "name": "state", "content": "abbrev state := Finmap (Ξ» _ : loc ↦ val)\n\n inductive val : Type where\n | val_unit : val\n | val_bool : Bool β†’ val\n | val_int : Int β†’ val\n | val_real : ℝ β†’ val\n | val_loc : loc β†’ val\n | val_prim : prim β†’ val\n | val_fun : var -> trm -> val\n | val_fix : var -> var -> trm -> val\n | val_uninit : val\n | val_error : val" }, { "name": "prim", "content": "inductive prim where\n \n | val_get : prim\n | val_set : prim\n \n | val_neg : prim\n | val_opp : prim\n | val_eq : prim\n | val_add : prim\n | val_neq : prim\n | val_sub : prim\n | val_mul : prim\n | val_div : prim\n | val_mod : prim\n \n | val_le : prim\n | val_lt : prim\n | val_ge : prim\n | val_gt : prim\n | val_ptr_add : prim\n\n inductive trm : Type where\n | trm_val : val -> trm\n | trm_var : var -> trm\n | trm_fun : var -> trm -> trm\n | trm_fix : var -> var -> trm -> trm\n | trm_app : trm -> trm -> trm\n | trm_seq : trm -> trm -> trm\n | trm_let : var -> trm -> trm -> trm\n | trm_if : trm -> trm -> trm -> trm\n | trm_for : var -> trm -> trm -> trm -> trm\n | trm_while : trm -> trm -> trm\n | trm_ref : var β†’ trm β†’ trm β†’ trm\n | trm_alloc : var β†’ trm β†’ trm β†’ trm" }, { "name": "var", "content": "abbrev var := String" }, { "name": "loc", "content": "abbrev loc := Nat" }, { "name": "evalExact", "content": "inductive evalExact : state β†’ trm β†’ (val β†’ state β†’ Prop) -> Prop where\n | val : forall s v,\n evalExact s (trm_val v) (fun v' s' ↦ v' = v ∧ s' = s)\n | fun : forall s x t1,\n evalExact s (trm_fun x t1) (fun v' s' ↦ v' = val_fun x t1 ∧ s' = s)\n | fix : forall s f x t1,\n evalExact s (trm_fix f x t1) (fun v' s' ↦ v' = val_fix f x t1 ∧ s' = s)\n | app_arg1 : forall s1 t1 t2 Q1 Q,\n Β¬ trm_is_val t1 ->\n evalExact s1 t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 (trm_app v1 t2) Q) ->\n evalExact s1 (trm_app t1 t2) Q\n | app_arg2 : forall s1 (v1 : val) t2 Q1 Q,\n Β¬ trm_is_val t2 ->\n evalExact s1 t2 Q1 ->\n (forall v2 s2, Q1 v2 s2 -> evalExact s2 (trm_app v1 v2) Q) ->\n evalExact s1 (trm_app v1 t2) Q\n | app_fun : forall s1 v1 (v2 :val) x t1 Q,\n v1 = val_fun x t1 ->\n evalExact s1 (subst x v2 t1) Q ->\n evalExact s1 (trm_app v1 v2) Q\n | app_fix : forall s (v1 v2 : val) f x t1 Q,\n v1 = val_fix f x t1 ->\n evalExact s (subst x v2 (subst f v1 t1)) Q ->\n evalExact s (trm_app v1 v2) Q\n | seq : forall Q1 s t1 t2 Q,\n evalExact s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 t2 Q) ->\n evalExact s (trm_seq t1 t2) Q\n | let : forall Q1 s x t1 t2 Q,\n evalExact s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 (subst x v1 t2) Q) ->\n evalExact s (trm_let x t1 t2) Q\n | if : forall s (b : Bool) t1 t2 Q,\n evalExact s (if b then t1 else t2) Q ->\n evalExact s (trm_if (val_bool b) t1 t2) Q\n | unop : forall op s v1 P,\n evalunop op v1 P ->\n evalExact s (trm_app op v1) (purepost s P)\n | binop : forall op s (v1 v2 : val) P,\n evalbinop op v1 v2 P ->\n evalExact s (trm_app (trm_app op v1) v2) (purepost s P)\n | ref : forall s x t1 t2 Q Q₁,\n evalExact s t1 Q₁ β†’\n (βˆ€ v1 s1, Q₁ v1 s1 β†’ βˆ€ p βˆ‰ s1,\n evalExact (s1.insert p v1) (subst x p t2) fun v s ↦ Q v (s.erase p)) β†’\n evalExact s (trm_ref x t1 t2) Q\n | get : forall s p,\n p ∈ s ->\n evalExact s (trm_app val_get (val_loc p))\n (fun v' s' ↦ v' = read_state p s ∧ s' = s)\n | set : forall s p v,\n v = trm_val v' ->\n p ∈ s ->\n evalExact s (trm_app (trm_app val_set (val_loc p)) v)\n (fun v'' s' ↦ v'' = val_unit ∧ s' = s.insert p v')\n | alloc_arg : forall s Q₁ Q,\n Β¬ trm_is_val t1 β†’\n evalExact s t1 Q₁ β†’\n (βˆ€ v' s', Q₁ v' s' β†’ evalExact s' (trm_alloc x v' t2) Q) β†’\n evalExact s (trm_alloc x t1 t2) Q\n | alloc : forall (sa : state) (n : β„€) Q,\n n β‰₯ 0 β†’\n (βˆ€ (p : loc) (sb : state),\n sb = conseq (make_list n.natAbs val_uninit) p β†’\n p β‰  null β†’\n Finmap.Disjoint sa sb β†’\n evalExact (sb βˆͺ sa) (subst x p t2) fun v s ↦ Q v (s \\ sb)) β†’\n evalExact sa (trm_alloc x n t2) Q\n \n \n \n \n \n \n | for (n₁ nβ‚‚ : Int) (Q : val -> state -> Prop) :\n evalExact s (if (n₁ < nβ‚‚) then\n (trm_seq (subst x n₁ t₁) (trm_for x (val_int (n₁ + 1)) nβ‚‚ t₁))\n else val_unit) Q ->\n evalExact s (trm_for x n₁ nβ‚‚ t₁) Q\n | while (t₁ tβ‚‚ : trm) (Q Q₁ : val -> state -> Prop) :\n evalExact s t₁ Q₁ ->\n (βˆ€ s v, Q₁ v s -> evalExact s (trm_if v (trm_seq tβ‚‚ (trm_while t₁ tβ‚‚)) val_unit) Q) ->\n evalExact s (trm_while t₁ tβ‚‚) Q" }, { "name": "make_list", "content": "def make_list {A} (n : Nat) (v : A) : List A :=\n match n with\n | 0 => []\n | n' + 1 => v :: make_list n' v" }, { "name": "trm_is_val", "content": "abbrev trm_is_val : trm β†’ Prop\n | trm_val _ => true\n | _ => false" }, { "name": "conseq", "content": "def conseq {B : Type} (vs : List B) (l : Nat) : Finmap (fun _ : Nat ↦ B) :=\n match vs with\n | [] => βˆ…\n | v :: vs' => (Finmap.singleton l v) βˆͺ (conseq vs' (l + 1))" }, { "name": "null", "content": "def null : loc := 0" }, { "name": "evalbinop", "content": "inductive evalbinop : val β†’ val β†’ val β†’ (val->Prop) β†’ Prop where\n | evalbinop_eq : forall v1 v2,\n evalbinop val_eq v1 v2 (fun v => v = val_bool (is_true (v1 = v2)))\n | evalbinop_neq : forall v1 v2,\n evalbinop val_neq v1 v2 (fun v => v = val_bool (is_true (v1 β‰  v2)))\n | evalbinop_add : forall n1 n2,\n evalbinop val_add (val_int n1) (val_int n2)\n (fun v => v = val_int (n1 + n2))\n | evalbinop_addr : forall r₁ rβ‚‚,\n evalbinop val_add (val_real r₁) (val_real rβ‚‚)\n (fun v => v = val_real (r₁ + rβ‚‚))\n | evalbinop_sub : forall n1 n2,\n evalbinop val_sub (val_int n1) (val_int n2)\n (fun v => v = val_int (n1 - n2))\n | evalbinop_subr : forall r1 r2,\n evalbinop val_sub (val_real r1) (val_real r2)\n (fun v => v = val_real (r1 - r2))\n | evalbinop_mul : forall n1 n2,\n evalbinop val_mul (val_int n1) (val_int n2)\n (fun v => v = val_int (n1 * n2))\n | evalbinop_mulr : forall r1 r2,\n evalbinop val_mul (val_real r1) (val_real r2)\n (fun v => v = val_real (r1 * r2))\n | evalbinop_div : forall n1 n2,\n Β¬(n2 = 0) β†’\n evalbinop val_div (val_int n1) (val_int n2)\n (fun v => v = val_int (n1 / n2))\n | evalbinop_divr : forall r1 r2,\n Β¬(r2 = 0) β†’\n evalbinop val_div (val_real r1) (val_real r2)\n (fun v => v = val_real (r1 / r2))\n | evalbinop_mod : forall n1 n2,\n Β¬(n2 = 0) β†’\n evalbinop val_mod (val_int n1) (val_int n2)\n (fun v => v = val_int (n1 % n2))\n | evalbinop_le : forall n1 n2,\n evalbinop val_le (val_int n1) (val_int n2)\n (fun v => v = val_bool (n1 <= n2))\n | evalbinop_ler : forall r1 r2,\n evalbinop val_le (val_real r1) (val_real r2)\n (fun v => v = val_bool (r1 <= r2))\n | evalbinop_lt : forall n1 n2,\n evalbinop val_lt (val_int n1) (val_int n2)\n (fun v => v = val_bool (n1 < n2))\n | evalbinop_ltr : forall r1 r2,\n evalbinop val_lt (val_real r1) (val_real r2)\n (fun v => v = val_bool (r1 < r2))\n | evalbinop_ge : forall n1 n2,\n evalbinop val_ge (val_int n1) (val_int n2)\n (fun v => v = val_bool (n1 >= n2))\n | evalbinop_ger : forall r1 r2,\n evalbinop val_ge (val_real r1) (val_real r2)\n (fun v => v = val_bool (r1 >= r2))\n | evalbinop_gt : forall n1 n2,\n evalbinop val_gt (val_int n1) (val_int n2)\n (fun v => v = val_bool (n1 > n2))\n | evalbinop_gtr : forall r1 r2,\n evalbinop val_gt (val_real r1) (val_real r2)\n (fun v => v = val_bool (r1 > r2))\n\n \n \n \n \n | evalbinop_ptr_add : forall (p1 : loc) (p2 : Int) n,\n p2 = p1 + n ->\n evalbinop val_ptr_add (val_loc p1) (val_int n)\n (fun v => v = val_loc (Int.natAbs p2))" }, { "name": "is_true", "content": "noncomputable def is_true (P : Prop) : Bool :=\n if P then true else false" }, { "name": "evalunop", "content": "inductive evalunop : prim β†’ val β†’ (val β†’ Prop) β†’ Prop where\n | evalunop_neg : forall b1,\n evalunop val_neg (val_bool b1) (fun v => v = val_bool (Β¬ b1))\n | evalunop_opp : forall n1,\n evalunop val_opp (val_int n1) (fun v => v = val_int (- n1))\n | evalunop_oppr : forall r1,\n evalunop val_opp (val_real r1) (fun v => v = val_real (- r1))" }, { "name": "purepost", "content": "def purepost (s : state) (P : val β†’ Prop) : val β†’ state β†’ Prop :=\n fun v s' => P v ∧ s' = s" }, { "name": "read_state", "content": "def read_state (p : loc) (h : state) :=\n match Finmap.lookup p h with\n | some v => v\n | none => default" }, { "name": "subst", "content": "def subst (y : var) (v' : val) (t : trm) : trm :=\n \n let if_y_eq x t1 t2 := if x = y then t1 else t2\n match t with\n | trm_val v => trm_val v\n | trm_var x => if_y_eq x (trm_val v') t\n | trm_fun x t1 => trm_fun x (if_y_eq x t1 (subst y v' t1))\n | trm_fix f x t1 => trm_fix f x (if_y_eq f t1 (if_y_eq x t1 (subst y v' t1)))\n | trm_app t1 t2 => trm_app (subst y v' t1) (subst y v' t2)\n | trm_seq t1 t2 => trm_seq (subst y v' t1) (subst y v' t2)\n | trm_let x t1 t2 => trm_let x (subst y v' t1) (if_y_eq x t2 (subst y v' t2))\n | trm_if t0 t1 t2 => trm_if (subst y v' t0) (subst y v' t1) (subst y v' t2)\n | trm_for x t1 t2 t3 => trm_for x (subst y v' t1) (subst y v' t2) (if_y_eq x t3 (subst y v' t3))\n | trm_while t1 t2 => trm_while (subst y v' t1) (subst y v' t2)\n | trm_ref x t1 t2 => trm_ref x (subst y v' t1) (if_y_eq x t2 (subst y v' t2))\n | trm_alloc x t1 t2 => trm_alloc x (subst y v' t1) (if_y_eq x t2 (subst y v' t2))" }, { "name": "qimpl", "content": "def qimpl {A} (Q1 Q2 : A β†’ hProp) : Prop :=\n forall (v:A), Q1 v ==> Q2 v" }, { "name": "hProp", "content": "def hProp := heap -> Prop" }, { "name": "heap", "content": "abbrev heap := Heap.heap val" }, { "name": "Heap.heap", "content": "abbrev Heap.heap (val : Type) := Finmap (Ξ» _ : loc ↦ val)" }, { "name": "himpl", "content": "abbrev himpl (H1 H2 : hProp) : Prop :=\n forall h, H1 h -> H2 h" }, { "name": "eval", "content": "inductive eval : state β†’ trm β†’ (val β†’ state β†’ Prop) -> Prop where\n | eval_val : forall s v Q,\n Q v s ->\n eval s (trm_val v) Q\n | eval_fun : forall s x t1 Q,\n Q (val_fun x t1) s ->\n eval s (trm_fun x t1) Q\n | eval_fix : forall s f x t1 Q,\n Q (val_fix f x t1) s ->\n eval s (trm_fix f x t1) Q\n | eval_app_arg1 : forall s1 t1 t2 Q1 Q,\n Β¬ trm_is_val t1 ->\n eval s1 t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> eval s2 (trm_app v1 t2) Q) ->\n eval s1 (trm_app t1 t2) Q\n | eval_app_arg2 : forall s1 (v1 : val) t2 Q1 Q,\n Β¬ trm_is_val t2 ->\n eval s1 t2 Q1 ->\n (forall v2 s2, Q1 v2 s2 -> eval s2 (trm_app v1 v2) Q) ->\n eval s1 (trm_app v1 t2) Q\n | eval_app_fun : forall s1 v1 (v2 :val) x t1 Q,\n v1 = val_fun x t1 ->\n eval s1 (subst x v2 t1) Q ->\n eval s1 (trm_app v1 v2) Q\n | eval_app_fix : forall s (v1 v2 : val) f x t1 Q,\n v1 = val_fix f x t1 ->\n eval s (subst x v2 (subst f v1 t1)) Q ->\n eval s (trm_app v1 v2) Q\n | eval_seq : forall Q1 s t1 t2 Q,\n eval s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> eval s2 t2 Q) ->\n eval s (trm_seq t1 t2) Q\n | eval_let : forall Q1 s x t1 t2 Q,\n eval s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> eval s2 (subst x v1 t2) Q) ->\n eval s (trm_let x t1 t2) Q\n | eval_if : forall s (b : Bool) t1 t2 Q,\n eval s (if b then t1 else t2) Q ->\n eval s (trm_if (val_bool b) t1 t2) Q\n | eval_unop : forall op s v1 P Q,\n evalunop op v1 P ->\n purepostin s P Q ->\n eval s (trm_app op v1) Q\n | eval_binop : forall op s (v1 v2 : val) P Q,\n evalbinop op v1 v2 P ->\n purepostin s P Q ->\n eval s (trm_app (trm_app op v1) v2) Q\n | eval_ref : forall s x t1 t2 (Q Q₁ : val β†’ state β†’ Prop),\n eval s t1 Q₁ β†’\n (βˆ€ v1 s1, Q₁ v1 s1 β†’ βˆ€ p βˆ‰ s1,\n eval (s1.insert p v1) (subst x p t2) fun v s ↦ Q v (s.erase p)) β†’\n eval s (trm_ref x t1 t2) Q\n | eval_get : forall s p Q,\n p ∈ s ->\n Q (read_state p s) s ->\n eval s (trm_app val_get (val_loc p)) Q\n | eval_set : forall s p v Q,\n v = trm_val v' ->\n p ∈ s ->\n Q val_unit (Finmap.insert p v' s) ->\n eval s (trm_app (trm_app val_set (val_loc p)) v) Q\n | eval_alloc_arg : forall s Q₁ Q,\n Β¬ trm_is_val t1 β†’\n eval s t1 Q₁ β†’\n (βˆ€ v' s', Q₁ v' s' β†’ eval s' (trm_alloc x v' t2) Q) β†’\n eval s (trm_alloc x t1 t2) Q\n | eval_alloc : forall (sa : state) (n : β„€) Q,\n n β‰₯ 0 β†’\n (βˆ€ (p : loc) (sb : state),\n sb = conseq (make_list n.natAbs val_uninit) p β†’\n p β‰  null β†’\n Finmap.Disjoint sa sb β†’\n eval (sb βˆͺ sa) (subst x p t2) fun v s ↦ Q v (s \\ sb)) β†’\n eval sa (trm_alloc x n t2) Q\n \n \n \n \n \n \n \n \n | eval_for (n₁ nβ‚‚ : Int) (Q : val -> state -> Prop) :\n eval s (if (n₁ < nβ‚‚) then\n (trm_seq (subst x n₁ t₁) (trm_for x (val_int (n₁ + 1)) nβ‚‚ t₁))\n else val_unit) Q ->\n eval s (trm_for x n₁ nβ‚‚ t₁) Q\n | eval_while (t₁ tβ‚‚ : trm) (Q : val -> state -> Prop) :\n eval s t₁ Q₁ ->\n (βˆ€ s v, Q₁ v s -> eval s (trm_if v (trm_seq tβ‚‚ (trm_while t₁ tβ‚‚)) val_unit) Q) ->\n eval s (trm_while t₁ tβ‚‚) Q" }, { "name": "hempty", "content": "def hempty : hProp :=\n fun h => (h = βˆ…)" }, { "name": "infixr:51 \" ==> \" => himpl", "content": "infixr:51 \" ==> \" => himpl" }, { "name": "infixr:51 \" ===> \" => qimpl", "content": "infixr:51 \" ===> \" => qimpl" }, { "name": "notation:max \"emp\" => hempty", "content": "notation:max \"emp\" => hempty" }, { "name": "infixr:55 \" βˆ— \" => HStar.hStar", "content": "infixr:55 \" βˆ— \" => HStar.hStar" } ]
[ { "name": "Finmap.mem_keys", "module": "Mathlib.Data.Finmap" }, { "name": "Finset.le_max_of_eq", "module": "Mathlib.Data.Finset.Max" }, { "name": "Finset.max_of_nonempty", "module": "Mathlib.Data.Finset.Max" }, { "name": "Finset.nonempty_iff_ne_empty", "module": "Mathlib.Data.Finset.Empty" }, { "name": "Nat.lt_succ_iff", "module": "Init.Data.Nat.Basic" }, { "name": "Finmap.disjoint_union_left", "module": "Mathlib.Data.Finmap" } ]
[ { "name": "non_mem_union", "content": "lemma non_mem_union (h1 h2 : state) :\n a βˆ‰ h1 βˆͺ h2 ↔ a βˆ‰ h1 ∧ a βˆ‰ h2" }, { "name": "evalbinop_unique", "content": "lemma evalbinop_unique :\n evalbinop op v1 v2 P β†’ evalbinop op v1 v2 P' β†’ P = P'" }, { "name": "insert_delete_id", "content": "lemma insert_delete_id (h : state) (p : loc) :\n p βˆ‰ h β†’\n h = (h.insert p v).erase p" }, { "name": "evalunop_unique", "content": "lemma evalunop_unique :\n evalunop op v P β†’ evalunop op v P' β†’ P = P'" }, { "name": "union_difference_id", "content": "lemma union_difference_id (h₁ hβ‚‚ : state) :\n h₁.Disjoint hβ‚‚ β†’\n (h₁ βˆͺ hβ‚‚) \\ hβ‚‚ = h₁" }, { "name": "insert_disjoint_l", "content": "lemma insert_disjoint_l (h1 h2 : state) (x : loc) (v : val) :\n h2.Disjoint (h1.insert x v) β†’\n x βˆ‰ h2 ∧ h2.Disjoint h1" }, { "name": "remove_not_in_l", "content": "lemma remove_not_in_l (h1 h2 : state) (p : loc) :\n p βˆ‰ h1 β†’\n (h1 βˆͺ h2).erase p = h1 βˆͺ h2.erase p" } ]
[]
[ { "name": "finite_state", "content": "lemma finite_state (s : state) :\n βˆƒ p, p βˆ‰ s" }, { "name": "conseq_ind", "content": "lemma conseq_ind (n : β„•) (v : val) (p : loc) :\n x ∈ conseq (make_list n v) p β†’ x β‰₯ p" }, { "name": "finite_state'", "content": "lemma finite_state' n (s : state) :\n βˆƒ p, p β‰  null ∧\n Finmap.Disjoint s (conseq (make_list n val_uninit) p)" }, { "name": "evalExact_sat", "content": "lemma evalExact_sat :\n evalExact s t Q β†’ βˆƒ v s, Q v s" } ]
import Mathlib.Data.Finmap import Mathlib.Data.Finset.Basic import Mathlib.Data.Multiset.Nodup import SPLean.Common.State import SPLean.Common.Util import SPLean.Theories.HProp import SPLean.Theories.XSimp open trm val prim notation "funloc" p "↦" H => fun (r : val) ↦ hexists (fun p ↦ ⌜r = val_loc p⌝ βˆ— H) section evalProp
lemma evalExact_post : eval s t Q β†’ evalExact s t Q' β†’ Q' ===> Q :=
:= by move=> H elim: H Q'=> > -- elim=> > { sby move=> ? > [] v h /== } { sby move=> ? > [] v h /== } { sby move=> ? > [] v h /== } { move=> ??? ih1 ih2 > [] // > { move=> > _ /[dup] h h' apply evalExact_sat in h=> ![] v s' /[dup] hQ1_1 hQ1_1' apply ih1 in h'=> himp hev apply himp in hQ1_1 sby apply hev in hQ1_1'=> ? /ih2 } { move=> ? scase: op=> > ? // scase: a=> > ? // [] // } move=> ? [] // } { move=> ? _ _ ih1 ih2 > [] // > _ /[dup] h h' apply evalExact_sat in h=> ![] v s' /[dup] hQ1_1 hQ1_1' apply ih1 in h'=> himp hev apply himp in hQ1_1 sby apply hev in hQ1_1'=> ? /ih2 } { sby move=> [] ?? > [] } { sby move=> [] ?? > [] } { move=> _ _ ih1 ih2 > [] > /[dup] h h' apply evalExact_sat in h=> ![] v s' > /[dup] hQ1_1 hQ1_1' hev apply ih1 in h'=> himp apply himp in hQ1_1 sby apply hev in hQ1_1'=> ? /ih2 } { move=> _ _ ih1 ih2 > [] > /[dup] h /evalExact_sat ![] v s' move=> /[dup] hQ1_1 hQ1_1' hev apply ih1 in h=> himp apply himp in hQ1_1 sby apply hev in hQ1_1'=> ? /ih2 } { sby move=> _ ih > [] } { unfold purepostin=> hOP ? > [] // apply evalunop_unique in hOP=> hP move=> > /hP [] sby unfold purepost=> ?? } { unfold purepostin=> hOP ? > [] // { scase: op=> > // scase: a=> > // ? > ? [] // } apply evalbinop_unique in hOP=> hP move=> > /hP [] sby unfold purepost=> ?? } { move=> ?? ih1 ih2 > [Q₁'] hevEx hev move=> > h move: hevEx hev move=> /[dup] /ih1 {} ih1 /evalExact_sat ![>] /[dup] /ih1 {}ih1 move=> /[swap] /[apply] scase: (finite_state (h βˆͺ w_1))=> p /non_mem_union [] ? hp move: hp=> /[dup] hp /[swap] /[apply] move: ih1 hp=> /ih2 /[apply] {}ih2 specialize (@ih2 fun v (s : state) ↦ Q' v (s.erase p)) move: ih2=> /[apply] unfold qimpl himpl=> /== ? sby srw (insert_delete_id h p) } { sby move=> ?? > [] // _ ?? } { move=> [] ?? > [] // { move=> > ? [] // } sby move=> > _ [] ?? } { move=> ? _ _ ih1 ih2 > [] // move=> Q₁' ? /[dup] /ih1 {}ih1 /evalExact_sat ![>] /[dup] /ih1 {} ih1 move=> /[swap] /[apply] sby move: ih1=> /ih2 } { move=> ? _ /== ih > hev move=> > h move: hev=> [] // _ /== hev scase: (finite_state' n.natAbs (sa βˆͺ h)) move=> p [] /[dup] /ih {}ih /hev {}hev /Finmap.disjoint_union_left [] move=> /[dup] /hev /[swap] /ih {}ih {hev} /ih {}ih /union_difference_id <- sby move=> /ih } { sby move=> ?? > [] } { move=> ?? ih1 ih2 > [] Q₁' move=> /[dup] /ih1 {}ih1 /evalExact_sat ![>] /[dup] /ih1 {}ih1 move=> /[swap] /[apply] sby move: ih1=> /ih2 }
6
72
false
Framework
406
qwand_equiv
lemma qwand_equiv H A (Q1 Q2 : A β†’ hProp) : H ==> (Q1 -βˆ— Q2) ↔ (Q1 βˆ— H) ===> Q2
splean
SPLean/Theories/HProp.lean
[ "import Mathlib.Data.Finmap", "import SPLean.Common.Heap", "import SPLean.Theories.Lang", "import SPLean.Common.Util", "import Mathlib.Algebra.BigOperators.Group.Finset" ]
[ { "name": "String", "module": "Init.Prelude" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "Finmap", "module": "Mathlib.Data.Finmap" }, { "name": "Iff", "module": "Init.Core" }, { "name": "move", "module": "Ssreflect.Basic" }, { "name": "sby", "module": "Ssreflect.Done" }, { "name": "srw", "module": "Ssreflect.Rewrite" }, { "name": "Finmap.Disjoint", "module": "Mathlib.Data.Finmap" }, { "name": "propext", "module": "Init.Core" }, { "name": "sapply", "module": "Ssreflect.ApplyIn" }, { "name": "And", "module": "Init.Prelude" }, { "name": "Eq", "module": "Init.Prelude" }, { "name": "scase!", "module": "Ssreflect.Elim" } ]
[ { "name": "syntax \"sdo\" num tactic : tactic", "content": "syntax \"sdo\" num tactic : tactic" }, { "name": "notation:max \"emp\" => hempty", "content": "notation:max \"emp\" => hempty\n\nsyntax \"fun\" ident+ \" => \" lang : lang" }, { "name": "notation:max \"⌜\" P \"⌝\" => hpure P", "content": "notation:max \"⌜\" P \"⌝\" => hpure P\n\nsyntax \"⟨\" term \"⟩\" : lang\n\nsyntax \"⟨\" term \":\" term \"⟩\" : lang" }, { "name": "macro_rules", "content": "macro_rules\n | `(term| {| $seq |}) => `(withMainContext do evalTactic $ <- `(tacticSeq| $seq))" }, { "name": "macro_rules", "content": "macro_rules\n | `([lang| ()]) => `(trm_val (val_unit))\n | `([lang| $n:num]) => `(trm_val (val_int $n))\n | `([lang| $t1 $t2]) => `(trm_app [lang| $t1] [lang| $t2])\n | `([lang| if $t1 then $t2 else $t3]) => `(trm_if [lang| $t1] [lang| $t2] [lang| $t3])\n | `([lang| if $t1 then $t2 end]) => `(trm_if [lang| $t1] [lang| $t2] (trm_val val_unit))\n | `([lang| let $x := $t1:lang in $t2:lang]) =>\n `(trm_let $(%x) [lang| $t1] [lang| $t2])\n | `([lang| ref $x := $t1:lang in $t2:lang]) =>\n `(trm_ref $(%x) [lang| $t1] [lang| $t2])\n | `([lang| alloc $t1:lang as $x in $t2:lang]) =>\n `(trm_alloc $(%x) [lang| $t1] [lang| $t2])\n | `([lang| $t1 ; $t2]) => `(trm_seq [lang| $t1] [lang| $t2])\n | `([lang| fun_ $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(trm_funs [ $xs,* ] [lang| $t])\n | `([lang| fun $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(val_funs [ $xs,* ] [lang| $t])\n | `([lang| fix_ $f $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(trm_fixs $(%f) [ $xs,* ] [lang| $t])\n | `([lang| fix $f $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(val_fixs $(%f) [ $xs,* ] [lang| $t])\n \n | `([lang| free $t]) => `(trm_val (val_prim val_free) [lang| $t])\n | `([lang| not $t]) => `(trm_val (val_prim val_not) [lang| $t])\n \n | `([lang| !$t]) => `(trm_val val_get [lang| $t])\n | `([lang| $t1 := $t2]) => `(trm_val val_set [lang| $t1] [lang| $t2])\n | `([lang| $t1 + $t2]) => `(trm_val val_add [lang| $t1] [lang| $t2])\n | `([lang| $t1 * $t2]) => `(trm_val val_mul [lang| $t1] [lang| $t2])\n | `([lang| $t1 - $t2]) => `(trm_val val_sub [lang| $t1] [lang| $t2])\n | `([lang| $t1 / $t2]) => `(trm_val val_div [lang| $t1] [lang| $t2])\n | `([lang| $t1 < $t2]) => `(trm_val val_lt [lang| $t1] [lang| $t2])\n | `([lang| $t1 > $t2]) => `(trm_val val_gt [lang| $t1] [lang| $t2])\n | `([lang| $t1 <= $t2]) => `(trm_val val_le [lang| $t1] [lang| $t2])\n | `([lang| $t1 >= $t2]) => `(trm_val val_ge [lang| $t1] [lang| $t2])\n | `([lang| -$t]) => `(trm_val val_opp [lang| $t])\n | `([lang| $t1 = $t2]) => `(trm_val val_eq [lang| $t1] [lang| $t2])\n | `([lang| $t1 != $t2]) => `(trm_val val_neq [lang| $t1] [lang| $t2])\n | `([lang| $t1 mod $t2]) => `(trm_val val_mod [lang| $t1] [lang| $t2])\n | `([lang| $t1 ++ $t2]) => `(trm_val val_ptr_add [lang| $t1] [lang| $t2])\n | `([lang| ($t)]) => `([lang| $t])\n | `([lang| ⟨$t : $tp⟩]) => `(trm_val (($t : $tp)))\n | `([lang| for $x in [$n1 : $n2] { $t } ]) =>\n `(trm_for $(%x) [lang| $n1] [lang| $n2] [lang| $t])\n | `([lang| while $c:lang { $t:lang } ]) =>\n `(trm_while [lang| $c] [lang| $t] )" }, { "name": "macro_rules", "content": "macro_rules\n | `([lang| len $p]) => `(trm_val val_array_length [lang| $p])\n | `([lang| $arr[$i] ]) => `(trm_val val_array_get [lang| $arr] [lang| $i])\n \n | `([lang| $arr[$i] := $v]) => `(trm_app val_array_set [lang| $arr] [lang| $i] [lang| $v])\n | `([lang| mkarr $n:lang $v:lang]) => `(trm_val val_array_make [lang| $n] [lang| $v])" }, { "name": "macro_rules | `($x βˆ— $y) => `(binop% HStar.hStar $x $y)", "content": "macro_rules | `($x βˆ— $y) => `(binop% HStar.hStar $x $y)" }, { "name": "heap", "content": "abbrev heap := Heap.heap val\n\n inductive val : Type where\n | val_unit : val\n | val_bool : Bool β†’ val\n | val_int : Int β†’ val\n | val_real : ℝ β†’ val\n | val_loc : loc β†’ val\n | val_prim : prim β†’ val\n | val_fun : var -> trm -> val\n | val_fix : var -> var -> trm -> val\n | val_uninit : val\n | val_error : val" }, { "name": "prim", "content": "inductive prim where\n \n | val_get : prim\n | val_set : prim\n \n | val_neg : prim\n | val_opp : prim\n | val_eq : prim\n | val_add : prim\n | val_neq : prim\n | val_sub : prim\n | val_mul : prim\n | val_div : prim\n | val_mod : prim\n \n | val_le : prim\n | val_lt : prim\n | val_ge : prim\n | val_gt : prim\n | val_ptr_add : prim\n\n inductive trm : Type where\n | trm_val : val -> trm\n | trm_var : var -> trm\n | trm_fun : var -> trm -> trm\n | trm_fix : var -> var -> trm -> trm\n | trm_app : trm -> trm -> trm\n | trm_seq : trm -> trm -> trm\n | trm_let : var -> trm -> trm -> trm\n | trm_if : trm -> trm -> trm -> trm\n | trm_for : var -> trm -> trm -> trm -> trm\n | trm_while : trm -> trm -> trm\n | trm_ref : var β†’ trm β†’ trm β†’ trm\n | trm_alloc : var β†’ trm β†’ trm β†’ trm" }, { "name": "var", "content": "abbrev var := String" }, { "name": "loc", "content": "abbrev loc := Nat" }, { "name": "Heap.heap", "content": "abbrev Heap.heap (val : Type) := Finmap (Ξ» _ : loc ↦ val)" }, { "name": "fun", "content": "notation \"funloc\" p \"↦\" H =>\n fun (r : val) ↦ hexists (fun p ↦ ⌜r = val_loc p⌝ βˆ— H)" } ]
[ { "name": "Finmap.union_comm_of_disjoint", "module": "Mathlib.Data.Finmap" }, { "name": "Finmap.disjoint_union_left", "module": "Mathlib.Data.Finmap" }, { "name": "Finmap.disjoint_union_right", "module": "Mathlib.Data.Finmap" }, { "name": "Finmap.union_assoc", "module": "Mathlib.Data.Finmap" }, { "name": "Iff.mpr", "module": "Init.Core" }, { "name": "Finmap.disjoint_empty", "module": "Mathlib.Data.Finmap" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "hProp", "content": "def hProp := heap -> Prop" }, { "name": "himpl", "content": "abbrev himpl (H1 H2 : hProp) : Prop :=\n forall h, H1 h -> H2 h" }, { "name": "qimpl", "content": "def qimpl {A} (Q1 Q2 : A β†’ hProp) : Prop :=\n forall (v:A), Q1 v ==> Q2 v" }, { "name": "hempty", "content": "def hempty : hProp :=\n fun h => (h = βˆ…)" }, { "name": "hstar", "content": "def hstar (H1 H2 : hProp) : hProp :=\n fun h => exists h1 h2,\n H1 h1 ∧ H2 h2 ∧ Finmap.Disjoint h1 h2 ∧ h = h1 βˆͺ h2" }, { "name": "hexists", "content": "def hexists {A} (J : A β†’ hProp) : hProp :=\n fun h => exists x, J x h" }, { "name": "hforall", "content": "def hforall {A} (J : A β†’ hProp) : hProp :=\n fun h => forall x, J x h" }, { "name": "HStar", "content": "class HStar (Ξ± : Type u) (Ξ² : Type v) (Ξ³ : outParam (Type w)) where\n \n hStar : Ξ± β†’ Ξ² β†’ Ξ³" }, { "name": "_inst_HStar", "content": "@[default_instance]\ninstance : HStar hProp hProp hProp where\n hStar := hstar" }, { "name": "hpure", "content": "def hpure (P : Prop) : hProp :=\n hexists (fun (_ : P) => emp)" }, { "name": "hwand", "content": "def hwand (H1 H2 : hProp) : hProp :=\n hexists (fun (H0 : hProp) => H0 βˆ— hpure ((H1 βˆ— H0) ==> H2))" }, { "name": "qwand", "content": "def qwand {A} (Q1 Q2 : A β†’ hProp) : hProp :=\n hforall (fun (x : A) => hwand (Q1 x) (Q2 x))" }, { "name": "qstar", "content": "def qstar {A} (Q : A β†’ hProp) (H : hProp) : A β†’ hProp :=\n fun x => hstar (Q x) H" }, { "name": "_inst_Type", "content": "instance (A : Type) : HStar (A β†’ hProp) hProp (A β†’ hProp) where\n hStar := qstar" }, { "name": "HWand", "content": "class HWand (Ξ± : Type u) (Ξ² : Type v) (Ξ³ : outParam (Type w)) where\n \n hWand : Ξ± β†’ Ξ² β†’ Ξ³" }, { "name": "_inst_HWand", "content": "@[default_instance]\ninstance : HWand hProp hProp hProp where\n hWand := hwand" }, { "name": "_inst_Type", "content": "instance (Ξ± : Type) : HWand (Ξ± β†’ hProp) (Ξ± β†’ hProp) hProp where\n hWand := qwand" } ]
[ { "name": "himpl_trans", "content": "lemma himpl_trans H2 H1 H3 :\n (H1 ==> H2) β†’ (H2 ==> H3) β†’ (H1 ==> H3)" }, { "name": "himpl_antisym", "content": "lemma himpl_antisym H1 H2:\n (H1 ==> H2) β†’ (H2 ==> H1) β†’ (H1 = H2)" }, { "name": "hprop_op_comm", "content": "lemma hprop_op_comm (op : hProp β†’ hProp β†’ hProp) :\n (forall H1 H2, op H1 H2 ==> op H2 H1) β†’\n (forall H1 H2, op H1 H2 = op H2 H1)" }, { "name": "hempty_inv", "content": "lemma hempty_inv h :\n emp h β†’ h = βˆ…" }, { "name": "hstar_inv", "content": "lemma hstar_inv (H1 H2 : hProp) h:\n (H1 βˆ— H2) h β†’\n exists h1 h2, H1 h1 ∧ H2 h2 ∧ Finmap.Disjoint h1 h2 ∧ h = h1 βˆͺ h2" }, { "name": "hstar_comm", "content": "lemma hstar_comm H1 H2 :\n H1 βˆ— H2 = H2 βˆ— H1" }, { "name": "hstar_assoc", "content": "lemma hstar_assoc H1 H2 H3 :\n (H1 βˆ— H2) βˆ— H3 = H1 βˆ— (H2 βˆ— H3)" }, { "name": "hstar_hempty_l", "content": "lemma hstar_hempty_l H :\n emp βˆ— H = H" }, { "name": "hstar_hempty_r", "content": "lemma hstar_hempty_r H :\n H βˆ— emp = H" }, { "name": "hstar_hexists", "content": "lemma hstar_hexists A (J : A β†’ hProp) H :\n (hexists J) βˆ— H = hexists (fun x => (J x) βˆ— H)" }, { "name": "hstar_hforall", "content": "lemma hstar_hforall A (J : A β†’ hProp) H :\n (hforall J) βˆ— H ==> hforall (J βˆ— H)" }, { "name": "himpl_frame_r", "content": "lemma himpl_frame_r H1 H2 H2' :\n H2 ==> H2' β†’\n (H1 βˆ— H2) ==> (H1 βˆ— H2')" }, { "name": "himpl_hstar_trans_l", "content": "lemma himpl_hstar_trans_l H1 H2 H3 H4 :\n H1 ==> H2 β†’\n H2 βˆ— H3 ==> H4 β†’\n H1 βˆ— H3 ==> H4" }, { "name": "hstar_hpure_l", "content": "lemma hstar_hpure_l P H h :\n (⌜P⌝ βˆ— H) h = (P ∧ H h)" }, { "name": "himpl_hempty_hpure", "content": "lemma himpl_hempty_hpure P :\n P β†’ emp ==> ⌜P⌝" }, { "name": "himpl_hstar_hpure_l", "content": "lemma himpl_hstar_hpure_l P H H' :\n (P β†’ H ==> H') β†’\n (⌜P⌝ βˆ— H) ==> H'" }, { "name": "himpl_hexists_l", "content": "lemma himpl_hexists_l A H (J : A β†’ hProp) :\n (forall x, J x ==> H) β†’ (hexists J) ==> H" }, { "name": "himpl_hexists_r", "content": "lemma himpl_hexists_r A (x : A) H (J : A β†’ hProp) :\n (H ==> J x) β†’\n H ==> (hexists J)" }, { "name": "himpl_hforall_r", "content": "lemma himpl_hforall_r A (J : A β†’ hProp) H :\n (forall x, H ==> J x) β†’\n H ==> (hforall J)" }, { "name": "himpl_hforall_l", "content": "lemma himpl_hforall_l A (x : A) (J : A β†’ hProp) H :\n (J x ==> H) β†’\n (hforall J) ==> H" }, { "name": "hwandE", "content": "lemma hwandE :\n H1 -βˆ— H2 = hexists (fun H0 => H0 βˆ— hpure ((H1 βˆ— H0) ==> H2))" }, { "name": "hwand_equiv", "content": "lemma hwand_equiv H0 H1 H2 :\n (H0 ==> H1 -βˆ— H2) ↔ (H1 βˆ— H0 ==> H2)" }, { "name": "himpl_hwand_r_inv", "content": "lemma himpl_hwand_r_inv H1 H2 H3 :\n H1 ==> (H2 -βˆ— H3) β†’\n H2 βˆ— H1 ==> H3" }, { "name": "hwand_cancel", "content": "lemma hwand_cancel H1 H2 :\n H1 βˆ— (H1 -βˆ— H2) ==> H2" }, { "name": "qwandE", "content": "lemma qwandE Ξ± (Q1 Q2 : Ξ± β†’ hProp) :\n Q1 -βˆ— Q2 = hforall (fun x => (Q1 x) -βˆ— (Q2 x))" }, { "name": "qstarE", "content": "lemma qstarE Ξ± (Q1 : Ξ± β†’ hProp) (H : hProp):\n Q1 βˆ— H = fun x => Q1 x βˆ— H" } ]
import Mathlib.Data.Finmap import Mathlib.Algebra.BigOperators.Group.Finset import SPLean.Common.Heap import SPLean.Common.Util import SPLean.Theories.Lang open Classical def hProp := heap -> Prop abbrev himpl (H1 H2 : hProp) : Prop := forall h, H1 h -> H2 h infixr:51 " ==> " => himpl def qimpl {A} (Q1 Q2 : A β†’ hProp) : Prop := forall (v:A), Q1 v ==> Q2 v infixr:51 " ===> " => qimpl def hempty : hProp := fun h => (h = βˆ…) def hstar (H1 H2 : hProp) : hProp := fun h => exists h1 h2, H1 h1 ∧ H2 h2 ∧ Finmap.Disjoint h1 h2 ∧ h = h1 βˆͺ h2 def hexists {A} (J : A β†’ hProp) : hProp := fun h => exists x, J x h def hforall {A} (J : A β†’ hProp) : hProp := fun h => forall x, J x h notation:max "emp" => hempty infixr:60 " ~~> " => hsingle class HStar (Ξ± : Type u) (Ξ² : Type v) (Ξ³ : outParam (Type w)) where hStar : Ξ± β†’ Ξ² β†’ Ξ³ infixr:55 " βˆ— " => HStar.hStar @[default_instance] instance : HStar hProp hProp hProp where hStar := hstar section open Lean.TSyntax.Compat end def hpure (P : Prop) : hProp := hexists (fun (_ : P) => emp) def hwand (H1 H2 : hProp) : hProp := hexists (fun (H0 : hProp) => H0 βˆ— hpure ((H1 βˆ— H0) ==> H2)) def qwand {A} (Q1 Q2 : A β†’ hProp) : hProp := hforall (fun (x : A) => hwand (Q1 x) (Q2 x)) notation:max "⌜" P "⌝" => hpure P notation (priority := high) "⊀" => htop def qstar {A} (Q : A β†’ hProp) (H : hProp) : A β†’ hProp := fun x => hstar (Q x) H instance (A : Type) : HStar (A β†’ hProp) hProp (A β†’ hProp) where hStar := qstar class HWand (Ξ± : Type u) (Ξ² : Type v) (Ξ³ : outParam (Type w)) where hWand : Ξ± β†’ Ξ² β†’ Ξ³ infixr:55 " -βˆ— " => HWand.hWand @[default_instance] instance : HWand hProp hProp hProp where hWand := hwand instance (Ξ± : Type) : HWand (Ξ± β†’ hProp) (Ξ± β†’ hProp) hProp where hWand := qwand
lemma qwand_equiv H A (Q1 Q2 : A β†’ hProp) : H ==> (Q1 -βˆ— Q2) ↔ (Q1 βˆ— H) ===> Q2 :=
:= by srw qwandE ; apply Iff.intro { move=> ? x srw qstarE hstar_comm apply (himpl_hstar_trans_l H (hforall fun x' ↦ Q1 x' -βˆ— Q2 x'))=>// apply (himpl_trans (hforall fun x0 ↦ ((Q1 x0 -βˆ— Q2 x0) βˆ— Q1 x))) apply hstar_hforall ; apply himpl_hforall_l rw [hstar_comm] ; apply hwand_cancel } srw qimpl qstarE => ? apply himpl_hforall_r => ? sby srw hwand_equiv=> ?
7
63
false
Framework
407
Theories.xwp_lemma_funs
lemma xwp_lemma_funs (xs : List _) (vs : List val) : t = trm_apps v0 ts -> v0 = val_funs xs t1 -> trms_to_vals ts = vs -> var_funs xs vs.length -> H ==> wpgen (isubst (xs.mkAlist vs) t1) Q -> triple t H Q
splean
SPLean/Theories/WP1.lean
[ "import SPLean.Theories.XChange", "import SPLean.Theories.Lang", "import Mathlib.Data.List.Indexes", "import SPLean.Theories.XSimp", "import SPLean.Theories.SepLog", "import Mathlib.Data.Finmap", "import SPLean.Common.State", "import SPLean.Theories.HProp", "import SPLean.Common.Util", "import Lean", "import SPLean.Theories.WPUtil" ]
[ { "name": "String", "module": "Init.Prelude" }, { "name": "List", "module": "Init.Prelude" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "AList", "module": "Mathlib.Data.List.AList" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "AList.erase", "module": "Mathlib.Data.List.AList" }, { "name": "AList.lookup", "module": "Mathlib.Data.List.AList" }, { "name": "DecidableEq", "module": "Init.Prelude" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "Finmap", "module": "Mathlib.Data.Finmap" }, { "name": "BEq", "module": "Init.Prelude" }, { "name": "Repr", "module": "Init.Data.Repr" }, { "name": "Vector", "module": "Init.Data.Vector.Basic" }, { "name": "bool", "module": "Init.Control.Basic" }, { "name": "ite", "module": "Init.Prelude" }, { "name": "Computation", "module": "Mathlib.Data.Seq.Computation" }, { "name": "Max", "module": "Init.Prelude" }, { "name": "Max.max", "module": "Init.Prelude" }, { "name": "Finmap.singleton", "module": "Mathlib.Data.Finmap" }, { "name": "L", "module": "Archive.Hairer" }, { "name": "Cont", "module": "Mathlib.Control.Monad.Cont" }, { "name": "liftM", "module": "Init.Prelude" }, { "name": "List.length", "module": "Init.Prelude" }, { "name": "move", "module": "Ssreflect.Basic" }, { "name": "srw", "module": "Ssreflect.Rewrite" }, { "name": "t", "module": "Ssreflect.IntroPats" }, { "name": "sby", "module": "Ssreflect.Done" }, { "name": "And", "module": "Init.Prelude" }, { "name": "sdone", "module": "Ssreflect.Done" }, { "name": "AList.entries", "module": "Mathlib.Data.List.AList" }, { "name": "List.NodupKeys", "module": "Mathlib.Data.List.Sigma" }, { "name": "List.keys", "module": "Mathlib.Data.List.Sigma" }, { "name": "List.map", "module": "Init.Prelude" }, { "name": "List.zip", "module": "Init.Data.List.Basic" }, { "name": "List.zipWith", "module": "Init.Data.List.Basic" }, { "name": "elim", "module": "Ssreflect.Elim" }, { "name": "Sigma", "module": "Init.Core" }, { "name": "scase", "module": "Ssreflect.Elim" }, { "name": "AList.insert", "module": "Mathlib.Data.List.AList" }, { "name": "List.kerase", "module": "Mathlib.Data.List.Sigma" }, { "name": "List.kinsert", "module": "Mathlib.Data.List.Sigma" }, { "name": "AList.keys", "module": "Mathlib.Data.List.AList" }, { "name": "Finmap.Disjoint", "module": "Mathlib.Data.Finmap" } ]
[ { "name": "syntax \" != \" : bop", "content": "syntax \" != \" : bop\n\nsyntax \"fun\" ident+ \" => \" lang : lang\n\nsyntax \"⟨\" term \"⟩\" : lang\n\nsyntax \"⟨\" term \":\" term \"⟩\" : lang\n\nsyntax \" := \" : bop" }, { "name": "notation:max \"emp\" => hempty", "content": "notation:max \"emp\" => hempty\n\nsyntax \"if \" lang \"then \" lang \"end \" : lang" }, { "name": "macro \"βˆƒΚ°\" xs:Lean.explicitBinders \", \" b:term : term => Lea", "content": "macro \"βˆƒΚ°\" xs:Lean.explicitBinders \", \" b:term : term => Lean.expandExplicitBinders ``hexists xs b" }, { "name": "notation:max \"⌜\" P \"⌝\" => hpure P", "content": "notation:max \"⌜\" P \"⌝\" => hpure P\n\nsyntax \"let\" ident \" := \" lang \" in\" ppDedent(ppLine lang) : lang" }, { "name": "macro \"hβˆ€\" xs:Lean.explicitBinders \", \" b:term : term => Lea", "content": "macro \"hβˆ€\" xs:Lean.explicitBinders \", \" b:term : term => Lean.expandExplicitBinders ``hforall xs b\n\nsyntax \" ++ \" : bop\n\nsyntax \"not\" : uop" }, { "name": "macro \"xpull\" : tactic =>", "content": "macro \"xpull\" : tactic =>\n `(tactic| (\n xpull_start\n repeat' xsimp_step\n try rev_pure\n hsimp\n ))\n\n syntax \"sdo\" num tactic : tactic" }, { "name": "macro \"xchange\" l:term : tactic =>", "content": "macro \"xchange\" l:term : tactic =>\n `(tactic| (xchange_core $l; xsimp))" }, { "name": "macro \"xsimp\" : tactic =>", "content": "macro \"xsimp\" : tactic =>\n `(tactic| (\n xsimp_start\n repeat xsimp_step\n try rev_pure\n try hide_mvars\n try hsimp\n rotate_left\n\n ))\n\nsyntax \"while\" lang \" {\" (ppLine lang) ( \" }\") : lang\n\nsyntax \"for\" ident \" in \" \"[\" lang \" : \" lang \"]\" \" {\" (ppLine lang) ( \" }\") : lang" }, { "name": "macro_rules", "content": "macro_rules\n | `(term| {| $seq |}) => `(withMainContext do evalTactic $ <- `(tacticSeq| $seq))" }, { "name": "macro_rules", "content": "macro_rules\n | `([lang| ()]) => `(trm_val (val_unit))\n | `([lang| $n:num]) => `(trm_val (val_int $n))\n | `([lang| $t1 $t2]) => `(trm_app [lang| $t1] [lang| $t2])\n | `([lang| if $t1 then $t2 else $t3]) => `(trm_if [lang| $t1] [lang| $t2] [lang| $t3])\n | `([lang| if $t1 then $t2 end]) => `(trm_if [lang| $t1] [lang| $t2] (trm_val val_unit))\n | `([lang| let $x := $t1:lang in $t2:lang]) =>\n `(trm_let $(%x) [lang| $t1] [lang| $t2])\n | `([lang| ref $x := $t1:lang in $t2:lang]) =>\n `(trm_ref $(%x) [lang| $t1] [lang| $t2])\n | `([lang| alloc $t1:lang as $x in $t2:lang]) =>\n `(trm_alloc $(%x) [lang| $t1] [lang| $t2])\n | `([lang| $t1 ; $t2]) => `(trm_seq [lang| $t1] [lang| $t2])\n | `([lang| fun_ $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(trm_funs [ $xs,* ] [lang| $t])\n | `([lang| fun $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(val_funs [ $xs,* ] [lang| $t])\n | `([lang| fix_ $f $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(trm_fixs $(%f) [ $xs,* ] [lang| $t])\n | `([lang| fix $f $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(val_fixs $(%f) [ $xs,* ] [lang| $t])\n \n | `([lang| free $t]) => `(trm_val (val_prim val_free) [lang| $t])\n | `([lang| not $t]) => `(trm_val (val_prim val_not) [lang| $t])\n \n | `([lang| !$t]) => `(trm_val val_get [lang| $t])\n | `([lang| $t1 := $t2]) => `(trm_val val_set [lang| $t1] [lang| $t2])\n | `([lang| $t1 + $t2]) => `(trm_val val_add [lang| $t1] [lang| $t2])\n | `([lang| $t1 * $t2]) => `(trm_val val_mul [lang| $t1] [lang| $t2])\n | `([lang| $t1 - $t2]) => `(trm_val val_sub [lang| $t1] [lang| $t2])\n | `([lang| $t1 / $t2]) => `(trm_val val_div [lang| $t1] [lang| $t2])\n | `([lang| $t1 < $t2]) => `(trm_val val_lt [lang| $t1] [lang| $t2])\n | `([lang| $t1 > $t2]) => `(trm_val val_gt [lang| $t1] [lang| $t2])\n | `([lang| $t1 <= $t2]) => `(trm_val val_le [lang| $t1] [lang| $t2])\n | `([lang| $t1 >= $t2]) => `(trm_val val_ge [lang| $t1] [lang| $t2])\n | `([lang| -$t]) => `(trm_val val_opp [lang| $t])\n | `([lang| $t1 = $t2]) => `(trm_val val_eq [lang| $t1] [lang| $t2])\n | `([lang| $t1 != $t2]) => `(trm_val val_neq [lang| $t1] [lang| $t2])\n | `([lang| $t1 mod $t2]) => `(trm_val val_mod [lang| $t1] [lang| $t2])\n | `([lang| $t1 ++ $t2]) => `(trm_val val_ptr_add [lang| $t1] [lang| $t2])\n | `([lang| ($t)]) => `([lang| $t])\n | `([lang| ⟨$t : $tp⟩]) => `(trm_val (($t : $tp)))\n | `([lang| for $x in [$n1 : $n2] { $t } ]) =>\n `(trm_for $(%x) [lang| $n1] [lang| $n2] [lang| $t])\n | `([lang| while $c:lang { $t:lang } ]) =>\n `(trm_while [lang| $c] [lang| $t] )" }, { "name": "macro_rules", "content": "macro_rules\n | `([lang| len $p]) => `(trm_val val_array_length [lang| $p])\n | `([lang| $arr[$i] ]) => `(trm_val val_array_get [lang| $arr] [lang| $i])\n \n | `([lang| $arr[$i] := $v]) => `(trm_app val_array_set [lang| $arr] [lang| $i] [lang| $v])\n | `([lang| mkarr $n:lang $v:lang]) => `(trm_val val_array_make [lang| $n] [lang| $v])" }, { "name": "macro_rules | `($x βˆ— $y) => `(binop% HStar.hStar $x $y)", "content": "macro_rules | `($x βˆ— $y) => `(binop% HStar.hStar $x $y)" }, { "name": "var", "content": "abbrev var := String\n\n inductive trm : Type where\n | trm_val : val -> trm\n | trm_var : var -> trm\n | trm_fun : var -> trm -> trm\n | trm_fix : var -> var -> trm -> trm\n | trm_app : trm -> trm -> trm\n | trm_seq : trm -> trm -> trm\n | trm_let : var -> trm -> trm -> trm\n | trm_if : trm -> trm -> trm -> trm\n | trm_for : var -> trm -> trm -> trm -> trm\n | trm_while : trm -> trm -> trm\n | trm_ref : var β†’ trm β†’ trm β†’ trm\n | trm_alloc : var β†’ trm β†’ trm β†’ trm\n\n inductive val : Type where\n | val_unit : val\n | val_bool : Bool β†’ val\n | val_int : Int β†’ val\n | val_real : ℝ β†’ val\n | val_loc : loc β†’ val\n | val_prim : prim β†’ val\n | val_fun : var -> trm -> val\n | val_fix : var -> var -> trm -> val\n | val_uninit : val\n | val_error : val" }, { "name": "prim", "content": "inductive prim where\n \n | val_get : prim\n | val_set : prim\n \n | val_neg : prim\n | val_opp : prim\n | val_eq : prim\n | val_add : prim\n | val_neq : prim\n | val_sub : prim\n | val_mul : prim\n | val_div : prim\n | val_mod : prim\n \n | val_le : prim\n | val_lt : prim\n | val_ge : prim\n | val_gt : prim\n | val_ptr_add : prim" }, { "name": "loc", "content": "abbrev loc := Nat" }, { "name": "hProp", "content": "def hProp := heap -> Prop" }, { "name": "heap", "content": "abbrev heap := Heap.heap val" }, { "name": "Heap.heap", "content": "abbrev Heap.heap (val : Type) := Finmap (Ξ» _ : loc ↦ val)" }, { "name": "HStar", "content": "class HStar (Ξ± : Type u) (Ξ² : Type v) (Ξ³ : outParam (Type w)) where\n \n hStar : Ξ± β†’ Ξ² β†’ Ξ³" }, { "name": "hpure", "content": "def hpure (P : Prop) : hProp :=\n hexists (fun (_ : P) => emp)" }, { "name": "hexists", "content": "def hexists {A} (J : A β†’ hProp) : hProp :=\n fun h => exists x, J x h" }, { "name": "hempty", "content": "def hempty : hProp :=\n fun h => (h = βˆ…)" }, { "name": "eval", "content": "inductive eval : state β†’ trm β†’ (val β†’ state β†’ Prop) -> Prop where\n | eval_val : forall s v Q,\n Q v s ->\n eval s (trm_val v) Q\n | eval_fun : forall s x t1 Q,\n Q (val_fun x t1) s ->\n eval s (trm_fun x t1) Q\n | eval_fix : forall s f x t1 Q,\n Q (val_fix f x t1) s ->\n eval s (trm_fix f x t1) Q\n | eval_app_arg1 : forall s1 t1 t2 Q1 Q,\n Β¬ trm_is_val t1 ->\n eval s1 t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> eval s2 (trm_app v1 t2) Q) ->\n eval s1 (trm_app t1 t2) Q\n | eval_app_arg2 : forall s1 (v1 : val) t2 Q1 Q,\n Β¬ trm_is_val t2 ->\n eval s1 t2 Q1 ->\n (forall v2 s2, Q1 v2 s2 -> eval s2 (trm_app v1 v2) Q) ->\n eval s1 (trm_app v1 t2) Q\n | eval_app_fun : forall s1 v1 (v2 :val) x t1 Q,\n v1 = val_fun x t1 ->\n eval s1 (subst x v2 t1) Q ->\n eval s1 (trm_app v1 v2) Q\n | eval_app_fix : forall s (v1 v2 : val) f x t1 Q,\n v1 = val_fix f x t1 ->\n eval s (subst x v2 (subst f v1 t1)) Q ->\n eval s (trm_app v1 v2) Q\n | eval_seq : forall Q1 s t1 t2 Q,\n eval s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> eval s2 t2 Q) ->\n eval s (trm_seq t1 t2) Q\n | eval_let : forall Q1 s x t1 t2 Q,\n eval s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> eval s2 (subst x v1 t2) Q) ->\n eval s (trm_let x t1 t2) Q\n | eval_if : forall s (b : Bool) t1 t2 Q,\n eval s (if b then t1 else t2) Q ->\n eval s (trm_if (val_bool b) t1 t2) Q\n | eval_unop : forall op s v1 P Q,\n evalunop op v1 P ->\n purepostin s P Q ->\n eval s (trm_app op v1) Q\n | eval_binop : forall op s (v1 v2 : val) P Q,\n evalbinop op v1 v2 P ->\n purepostin s P Q ->\n eval s (trm_app (trm_app op v1) v2) Q\n | eval_ref : forall s x t1 t2 (Q Q₁ : val β†’ state β†’ Prop),\n eval s t1 Q₁ β†’\n (βˆ€ v1 s1, Q₁ v1 s1 β†’ βˆ€ p βˆ‰ s1,\n eval (s1.insert p v1) (subst x p t2) fun v s ↦ Q v (s.erase p)) β†’\n eval s (trm_ref x t1 t2) Q\n | eval_get : forall s p Q,\n p ∈ s ->\n Q (read_state p s) s ->\n eval s (trm_app val_get (val_loc p)) Q\n | eval_set : forall s p v Q,\n v = trm_val v' ->\n p ∈ s ->\n Q val_unit (Finmap.insert p v' s) ->\n eval s (trm_app (trm_app val_set (val_loc p)) v) Q\n | eval_alloc_arg : forall s Q₁ Q,\n Β¬ trm_is_val t1 β†’\n eval s t1 Q₁ β†’\n (βˆ€ v' s', Q₁ v' s' β†’ eval s' (trm_alloc x v' t2) Q) β†’\n eval s (trm_alloc x t1 t2) Q\n | eval_alloc : forall (sa : state) (n : β„€) Q,\n n β‰₯ 0 β†’\n (βˆ€ (p : loc) (sb : state),\n sb = conseq (make_list n.natAbs val_uninit) p β†’\n p β‰  null β†’\n Finmap.Disjoint sa sb β†’\n eval (sb βˆͺ sa) (subst x p t2) fun v s ↦ Q v (s \\ sb)) β†’\n eval sa (trm_alloc x n t2) Q\n \n \n \n \n \n \n \n \n | eval_for (n₁ nβ‚‚ : Int) (Q : val -> state -> Prop) :\n eval s (if (n₁ < nβ‚‚) then\n (trm_seq (subst x n₁ t₁) (trm_for x (val_int (n₁ + 1)) nβ‚‚ t₁))\n else val_unit) Q ->\n eval s (trm_for x n₁ nβ‚‚ t₁) Q\n | eval_while (t₁ tβ‚‚ : trm) (Q : val -> state -> Prop) :\n eval s t₁ Q₁ ->\n (βˆ€ s v, Q₁ v s -> eval s (trm_if v (trm_seq tβ‚‚ (trm_while t₁ tβ‚‚)) val_unit) Q) ->\n eval s (trm_while t₁ tβ‚‚) Q" }, { "name": "hsingle", "content": "def hsingle (p : loc) (v : val) : hProp :=\n fun h => (h = Finmap.singleton p v)" }, { "name": "evalExact", "content": "inductive evalExact : state β†’ trm β†’ (val β†’ state β†’ Prop) -> Prop where\n | val : forall s v,\n evalExact s (trm_val v) (fun v' s' ↦ v' = v ∧ s' = s)\n | fun : forall s x t1,\n evalExact s (trm_fun x t1) (fun v' s' ↦ v' = val_fun x t1 ∧ s' = s)\n | fix : forall s f x t1,\n evalExact s (trm_fix f x t1) (fun v' s' ↦ v' = val_fix f x t1 ∧ s' = s)\n | app_arg1 : forall s1 t1 t2 Q1 Q,\n Β¬ trm_is_val t1 ->\n evalExact s1 t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 (trm_app v1 t2) Q) ->\n evalExact s1 (trm_app t1 t2) Q\n | app_arg2 : forall s1 (v1 : val) t2 Q1 Q,\n Β¬ trm_is_val t2 ->\n evalExact s1 t2 Q1 ->\n (forall v2 s2, Q1 v2 s2 -> evalExact s2 (trm_app v1 v2) Q) ->\n evalExact s1 (trm_app v1 t2) Q\n | app_fun : forall s1 v1 (v2 :val) x t1 Q,\n v1 = val_fun x t1 ->\n evalExact s1 (subst x v2 t1) Q ->\n evalExact s1 (trm_app v1 v2) Q\n | app_fix : forall s (v1 v2 : val) f x t1 Q,\n v1 = val_fix f x t1 ->\n evalExact s (subst x v2 (subst f v1 t1)) Q ->\n evalExact s (trm_app v1 v2) Q\n | seq : forall Q1 s t1 t2 Q,\n evalExact s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 t2 Q) ->\n evalExact s (trm_seq t1 t2) Q\n | let : forall Q1 s x t1 t2 Q,\n evalExact s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 (subst x v1 t2) Q) ->\n evalExact s (trm_let x t1 t2) Q\n | if : forall s (b : Bool) t1 t2 Q,\n evalExact s (if b then t1 else t2) Q ->\n evalExact s (trm_if (val_bool b) t1 t2) Q\n | unop : forall op s v1 P,\n evalunop op v1 P ->\n evalExact s (trm_app op v1) (purepost s P)\n | binop : forall op s (v1 v2 : val) P,\n evalbinop op v1 v2 P ->\n evalExact s (trm_app (trm_app op v1) v2) (purepost s P)\n | ref : forall s x t1 t2 Q Q₁,\n evalExact s t1 Q₁ β†’\n (βˆ€ v1 s1, Q₁ v1 s1 β†’ βˆ€ p βˆ‰ s1,\n evalExact (s1.insert p v1) (subst x p t2) fun v s ↦ Q v (s.erase p)) β†’\n evalExact s (trm_ref x t1 t2) Q\n | get : forall s p,\n p ∈ s ->\n evalExact s (trm_app val_get (val_loc p))\n (fun v' s' ↦ v' = read_state p s ∧ s' = s)\n | set : forall s p v,\n v = trm_val v' ->\n p ∈ s ->\n evalExact s (trm_app (trm_app val_set (val_loc p)) v)\n (fun v'' s' ↦ v'' = val_unit ∧ s' = s.insert p v')\n | alloc_arg : forall s Q₁ Q,\n Β¬ trm_is_val t1 β†’\n evalExact s t1 Q₁ β†’\n (βˆ€ v' s', Q₁ v' s' β†’ evalExact s' (trm_alloc x v' t2) Q) β†’\n evalExact s (trm_alloc x t1 t2) Q\n | alloc : forall (sa : state) (n : β„€) Q,\n n β‰₯ 0 β†’\n (βˆ€ (p : loc) (sb : state),\n sb = conseq (make_list n.natAbs val_uninit) p β†’\n p β‰  null β†’\n Finmap.Disjoint sa sb β†’\n evalExact (sb βˆͺ sa) (subst x p t2) fun v s ↦ Q v (s \\ sb)) β†’\n evalExact sa (trm_alloc x n t2) Q\n \n \n \n \n \n \n | for (n₁ nβ‚‚ : Int) (Q : val -> state -> Prop) :\n evalExact s (if (n₁ < nβ‚‚) then\n (trm_seq (subst x n₁ t₁) (trm_for x (val_int (n₁ + 1)) nβ‚‚ t₁))\n else val_unit) Q ->\n evalExact s (trm_for x n₁ nβ‚‚ t₁) Q\n | while (t₁ tβ‚‚ : trm) (Q Q₁ : val -> state -> Prop) :\n evalExact s t₁ Q₁ ->\n (βˆ€ s v, Q₁ v s -> evalExact s (trm_if v (trm_seq tβ‚‚ (trm_while t₁ tβ‚‚)) val_unit) Q) ->\n evalExact s (trm_while t₁ tβ‚‚) Q" }, { "name": "subst", "content": "def subst (y : var) (v' : val) (t : trm) : trm :=\n \n let if_y_eq x t1 t2 := if x = y then t1 else t2\n match t with\n | trm_val v => trm_val v\n | trm_var x => if_y_eq x (trm_val v') t\n | trm_fun x t1 => trm_fun x (if_y_eq x t1 (subst y v' t1))\n | trm_fix f x t1 => trm_fix f x (if_y_eq f t1 (if_y_eq x t1 (subst y v' t1)))\n | trm_app t1 t2 => trm_app (subst y v' t1) (subst y v' t2)\n | trm_seq t1 t2 => trm_seq (subst y v' t1) (subst y v' t2)\n | trm_let x t1 t2 => trm_let x (subst y v' t1) (if_y_eq x t2 (subst y v' t2))\n | trm_if t0 t1 t2 => trm_if (subst y v' t0) (subst y v' t1) (subst y v' t2)\n | trm_for x t1 t2 t3 => trm_for x (subst y v' t1) (subst y v' t2) (if_y_eq x t3 (subst y v' t3))\n | trm_while t1 t2 => trm_while (subst y v' t1) (subst y v' t2)\n | trm_ref x t1 t2 => trm_ref x (subst y v' t1) (if_y_eq x t2 (subst y v' t2))\n | trm_alloc x t1 t2 => trm_alloc x (subst y v' t1) (if_y_eq x t2 (subst y v' t2))" }, { "name": "HWand", "content": "class HWand (Ξ± : Type u) (Ξ² : Type v) (Ξ³ : outParam (Type w)) where\n \n hWand : Ξ± β†’ Ξ² β†’ Ξ³" }, { "name": "protect", "content": "@[heapSimp]\ndef protect (x : Ξ±) := x" }, { "name": "himpl", "content": "abbrev himpl (H1 H2 : hProp) : Prop :=\n forall h, H1 h -> H2 h" }, { "name": "make_list", "content": "def make_list {A} (n : Nat) (v : A) : List A :=\n match n with\n | 0 => []\n | n' + 1 => v :: make_list n' v" }, { "name": "hrange", "content": "def hrange (L : List val) (p : loc) : hProp :=\n match L with\n | [] => emp\n | x :: L' => (p ~~> x) βˆ— (hrange L' (p + 1))" }, { "name": "null", "content": "def null : loc := 0" }, { "name": "triple", "content": "abbrev triple (t : trm) (H : hProp) (Q : val β†’ hProp) : Prop :=\n forall s, H s β†’ eval s t Q" }, { "name": "wp", "content": "def wp (t : trm) (Q : val β†’ hProp) : hProp :=\n fun s ↦ eval s t Q" }, { "name": "val_funs", "content": "def val_funs (xs:List var) (t:trm) : val :=\n match xs with\n | [] => panic! \"function with zero argumets!\"\n | x1::xs' => val_fun x1 (trm_funs xs' t)" }, { "name": "trm_funs", "content": "def trm_funs (xs:List var) (t:trm) : trm :=\n match xs with\n | [] => t\n | x1::xs' => trm_fun x1 (trm_funs xs' t)" }, { "name": "trm_apps", "content": "def trm_apps (f:trm) (ts:List trm) : trm :=\n match ts with\n | [] => f\n | ti::ts' => trm_apps (trm_app f ti) ts'" }, { "name": "eval_like", "content": "def eval_like (t1 t2:trm) : Prop :=\n forall s Q, eval s t1 Q -> eval s t2 Q" }, { "name": "trm_is_val", "content": "abbrev trm_is_val : trm β†’ Prop\n | trm_val _ => true\n | _ => false" }, { "name": "purepostin", "content": "def purepostin (s : state) (P : val β†’ Prop) (Q : val β†’ state β†’ Prop) : Prop :=\n \n forall v, P v β†’ Q v s" }, { "name": "state", "content": "abbrev state := Finmap (Ξ» _ : loc ↦ val)" }, { "name": "qimpl", "content": "def qimpl {A} (Q1 Q2 : A β†’ hProp) : Prop :=\n forall (v:A), Q1 v ==> Q2 v" }, { "name": "hforall", "content": "def hforall {A} (J : A β†’ hProp) : hProp :=\n fun h => forall x, J x h" }, { "name": "tohProp", "content": "abbrev tohProp (h : heap -> Prop) : hProp := h" }, { "name": "ofhProp", "content": "abbrev ofhProp (h : val -> hProp) : val -> heap -> Prop := h" }, { "name": "conseq", "content": "def conseq {B : Type} (vs : List B) (l : Nat) : Finmap (fun _ : Nat ↦ B) :=\n match vs with\n | [] => βˆ…\n | v :: vs' => (Finmap.singleton l v) βˆͺ (conseq vs' (l + 1))" }, { "name": "infixr:51 \" ==> \" => himpl", "content": "infixr:51 \" ==> \" => himpl" }, { "name": "infixr:51 \" ===> \" => qimpl", "content": "infixr:51 \" ===> \" => qimpl" }, { "name": "notation:max \"emp\" => hempty", "content": "notation:max \"emp\" => hempty" }, { "name": "infixr:60 \" ~~> \" => hsingle", "content": "infixr:60 \" ~~> \" => hsingle" }, { "name": "infixr:55 \" βˆ— \" => HStar.hStar", "content": "infixr:55 \" βˆ— \" => HStar.hStar" }, { "name": "notation:max \"⌜\" P \"⌝\" => hpure P", "content": "notation:max \"⌜\" P \"⌝\" => hpure P" }, { "name": "infixr:55 \" -βˆ— \" => HWand.hWand", "content": "infixr:55 \" -βˆ— \" => HWand.hWand" }, { "name": "fun", "content": "notation \"funloc\" p \"↦\" H =>\n fun (r : val) ↦ hexists (fun p ↦ ⌜r = val_loc p⌝ βˆ— H)" } ]
[ { "name": "AList.keys_nodup", "module": "Mathlib.Data.List.AList" }, { "name": "List.dlookup_dedupKeys", "module": "Mathlib.Data.List.Sigma" }, { "name": "List.lookup_ext", "module": "Mathlib.Data.List.Sigma" }, { "name": "List.perm_dlookup", "module": "Mathlib.Data.List.Sigma" }, { "name": "List.perm_nodupKeys", "module": "Mathlib.Data.List.Sigma" }, { "name": "List.map_append", "module": "Init.Data.List.Lemmas" }, { "name": "List.map_zipWith", "module": "Init.Data.List.Zip" }, { "name": "List.nodup_cons", "module": "Init.Data.List.Pairwise" }, { "name": "List.perm_append_singleton", "module": "Init.Data.List.Perm" }, { "name": "List.zip_append", "module": "Init.Data.List.Zip" }, { "name": "List.kerase_cons_ne", "module": "Mathlib.Data.List.Sigma" }, { "name": "List.kerase_kerase", "module": "Mathlib.Data.List.Sigma" }, { "name": "AList.perm_erase", "module": "Mathlib.Data.List.AList" }, { "name": "AList.perm_lookup", "module": "Mathlib.Data.List.AList" }, { "name": "AList.mem_keys", "module": "Mathlib.Data.List.AList" }, { "name": "List.eraseP_of_forall_not", "module": "Init.Data.List.Erase" }, { "name": "AList.erase_erase", "module": "Mathlib.Data.List.AList" }, { "name": "AList.lookup_erase_ne", "module": "Mathlib.Data.List.AList" }, { "name": "AList.lookup_insert_ne", "module": "Mathlib.Data.List.AList" }, { "name": "congrArg", "module": "Init.Prelude" }, { "name": "AList.toAList_cons", "module": "Mathlib.Data.List.AList" }, { "name": "List.nodup_middle", "module": "Mathlib.Data.List.Nodup" }, { "name": "Finmap.union_comm_of_disjoint", "module": "Mathlib.Data.Finmap" }, { "name": "Finmap.Disjoint.symm_iff", "module": "Mathlib.Data.Finmap" } ]
[ { "name": "eval_app_arg1'", "content": "lemma eval_app_arg1' s1 t1 t2 Q1 Q :\n eval s1 t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> eval s2 (trm_app v1 t2) Q) ->\n eval s1 (trm_app t1 t2) Q" }, { "name": "eval_conseq", "content": "lemma eval_conseq s t Q1 Q2 :\n eval s t Q1 β†’\n Q1 ===> Q2 β†’\n eval s t Q2" }, { "name": "hwand_inv", "content": "lemma hwand_inv h1 h2 H1 H2 :\n (H1 -βˆ— H2) h2 β†’\n H1 h1 β†’\n Finmap.Disjoint h1 h2 β†’\n H2 (h1 βˆͺ h2)" }, { "name": "hsingl_inv", "content": "lemma hsingl_inv p v h :\n (p ~~> v) h β†’\n h = Finmap.singleton p v" }, { "name": "hforall_inv", "content": "lemma hforall_inv A (J : A β†’ hProp) h :\n (hforall J) h β†’ forall x, J x h" }, { "name": "union_singleton_eq_insert", "content": "lemma union_singleton_eq_insert (h : state) :\n Finmap.singleton p v βˆͺ h = h.insert p v" }, { "name": "insert_delete_id", "content": "lemma insert_delete_id (h : state) (p : loc) :\n p βˆ‰ h β†’\n h = (h.insert p v).erase p" }, { "name": "himpl_trans", "content": "lemma himpl_trans H2 H1 H3 :\n (H1 ==> H2) β†’ (H2 ==> H3) β†’ (H1 ==> H3)" }, { "name": "himpl_hforall_l", "content": "lemma himpl_hforall_l A (x : A) (J : A β†’ hProp) H :\n (J x ==> H) β†’\n (hforall J) ==> H" }, { "name": "hwand_hpure_l", "content": "lemma hwand_hpure_l P H :\n P β†’ (⌜P⌝ -βˆ— H) = H" }, { "name": "himpl_antisym", "content": "lemma himpl_antisym H1 H2:\n (H1 ==> H2) β†’ (H2 ==> H1) β†’ (H1 = H2)" }, { "name": "himpl_hstar_hpure_l", "content": "lemma himpl_hstar_hpure_l P H H' :\n (P β†’ H ==> H') β†’\n (⌜P⌝ βˆ— H) ==> H'" }, { "name": "hstar_hpure_l", "content": "lemma hstar_hpure_l P H h :\n (⌜P⌝ βˆ— H) h = (P ∧ H h)" }, { "name": "hstar_hempty_l", "content": "lemma hstar_hempty_l H :\n emp βˆ— H = H" }, { "name": "hempty_inv", "content": "lemma hempty_inv h :\n emp h β†’ h = βˆ…" }, { "name": "hstar_hexists", "content": "lemma hstar_hexists A (J : A β†’ hProp) H :\n (hexists J) βˆ— H = hexists (fun x => (J x) βˆ— H)" }, { "name": "himpl_hstar_hpure_r", "content": "lemma himpl_hstar_hpure_r P H H' :\n P β†’\n (H ==> H') β†’\n H ==> ⌜P⌝ βˆ— H'" }, { "name": "himpl_refl", "content": "lemma himpl_refl H : H ==> H" }, { "name": "hwand_cancel", "content": "lemma hwand_cancel H1 H2 :\n H1 βˆ— (H1 -βˆ— H2) ==> H2" }, { "name": "himpl_hwand_r_inv", "content": "lemma himpl_hwand_r_inv H1 H2 H3 :\n H1 ==> (H2 -βˆ— H3) β†’\n H2 βˆ— H1 ==> H3" }, { "name": "hwand_equiv", "content": "lemma hwand_equiv H0 H1 H2 :\n (H0 ==> H1 -βˆ— H2) ↔ (H1 βˆ— H0 ==> H2)" }, { "name": "hstar_assoc", "content": "lemma hstar_assoc H1 H2 H3 :\n (H1 βˆ— H2) βˆ— H3 = H1 βˆ— (H2 βˆ— H3)" }, { "name": "himpl_hstar_trans_l", "content": "lemma himpl_hstar_trans_l H1 H2 H3 H4 :\n H1 ==> H2 β†’\n H2 βˆ— H3 ==> H4 β†’\n H1 βˆ— H3 ==> H4" }, { "name": "hstar_comm", "content": "lemma hstar_comm H1 H2 :\n H1 βˆ— H2 = H2 βˆ— H1" }, { "name": "hprop_op_comm", "content": "lemma hprop_op_comm (op : hProp β†’ hProp β†’ hProp) :\n (forall H1 H2, op H1 H2 ==> op H2 H1) β†’\n (forall H1 H2, op H1 H2 = op H2 H1)" }, { "name": "hstar_inv", "content": "lemma hstar_inv (H1 H2 : hProp) h:\n (H1 βˆ— H2) h β†’\n exists h1 h2, H1 h1 ∧ H2 h2 ∧ Finmap.Disjoint h1 h2 ∧ h = h1 βˆͺ h2" }, { "name": "himpl_hempty_hpure", "content": "lemma himpl_hempty_hpure P :\n P β†’ emp ==> ⌜P⌝" }, { "name": "himpl_hexists_r", "content": "lemma himpl_hexists_r A (x : A) H (J : A β†’ hProp) :\n (H ==> J x) β†’\n H ==> (hexists J)" }, { "name": "hwandE", "content": "lemma hwandE :\n H1 -βˆ— H2 = hexists (fun H0 => H0 βˆ— hpure ((H1 βˆ— H0) ==> H2))" }, { "name": "himpl_frame_r", "content": "lemma himpl_frame_r H1 H2 H2' :\n H2 ==> H2' β†’\n (H1 βˆ— H2) ==> (H1 βˆ— H2')" }, { "name": "hstar_hempty_r", "content": "lemma hstar_hempty_r H :\n H βˆ— emp = H" }, { "name": "himpl_hexists_l", "content": "lemma himpl_hexists_l A H (J : A β†’ hProp) :\n (forall x, J x ==> H) β†’ (hexists J) ==> H" }, { "name": "qstarE", "content": "lemma qstarE Ξ± (Q1 : Ξ± β†’ hProp) (H : hProp):\n Q1 βˆ— H = fun x => Q1 x βˆ— H" }, { "name": "eval_frame", "content": "lemma eval_frame (h1 h2 : state) t (Q : val -> hProp) :\n eval h1 t (ofhProp Q) β†’\n Finmap.Disjoint h1 h2 β†’\n eval (h1 βˆͺ h2) t (Q βˆ— (tohProp (fun h ↦ h = h2)))" }, { "name": "qwand_cancel", "content": "lemma qwand_cancel A (Q1 Q2 : A β†’ hProp) :\n Q1 βˆ— (Q1 -βˆ— Q2) ===> Q2" }, { "name": "qwand_equiv", "content": "lemma qwand_equiv H A (Q1 Q2 : A β†’ hProp) :\n H ==> (Q1 -βˆ— Q2) ↔ (Q1 βˆ— H) ===> Q2" }, { "name": "hstar_hforall", "content": "lemma hstar_hforall A (J : A β†’ hProp) H :\n (hforall J) βˆ— H ==> hforall (J βˆ— H)" }, { "name": "himpl_hforall_r", "content": "lemma himpl_hforall_r A (J : A β†’ hProp) H :\n (forall x, H ==> J x) β†’\n H ==> (hforall J)" }, { "name": "qwandE", "content": "lemma qwandE Ξ± (Q1 Q2 : Ξ± β†’ hProp) :\n Q1 -βˆ— Q2 = hforall (fun x => (Q1 x) -βˆ— (Q2 x))" }, { "name": "hpure_inv", "content": "lemma hpure_inv P h :\n ⌜P⌝ h β†’\n P ∧ h = βˆ…" }, { "name": "hrange_eq_conseq", "content": "lemma hrange_eq_conseq (L : List val) (n : β„€) (p : loc) (s : state) :\n L.length = n β†’\n hrange L p s β†’\n s.keys = (conseq (make_list n.natAbs val_uninit) p).keys" }, { "name": "int_eq_sub", "content": "lemma int_eq_sub (l m n : β„€) :\n l + m = n β†’ l = n - m" }, { "name": "list_inc_natabs", "content": "lemma list_inc_natabs {Ξ± : Type} (L : List Ξ±) :\n ((L.length : β„€) + 1).natAbs = (L.length : β„€).natAbs + 1" }, { "name": "hexists_inv", "content": "lemma hexists_inv A (J : A β†’ hProp) h :\n (hexists J) h β†’ exists x, J x h" }, { "name": "diff_disjoint_eq", "content": "lemma diff_disjoint_eq (s₁ sβ‚‚ s₃ : state) :\n s₁.Disjoint sβ‚‚ β†’\n sβ‚‚.keys = s₃.keys β†’\n (s₁ βˆͺ sβ‚‚) \\ s₃ = s₁" }, { "name": "lookup_diff", "content": "lemma lookup_diff (h₁ hβ‚‚ : state) :\n p βˆ‰ hβ‚‚ β†’\n (h₁ \\ hβ‚‚).lookup p = h₁.lookup p" }, { "name": "lookup_diff_none", "content": "lemma lookup_diff_none (h₁ hβ‚‚ : state) :\n p ∈ hβ‚‚ β†’\n (h₁ \\ hβ‚‚).lookup p = none" }, { "name": "diff_non_mem", "content": "theorem diff_non_mem (h₁ hβ‚‚ : state) :\n p ∈ hβ‚‚ β†’ p βˆ‰ h₁ \\ hβ‚‚" } ]
[ { "name": "Theories.wp", "content": "def wp (t : trm) (Q : val β†’ hProp) : hProp :=\n fun s ↦ eval s t Q" }, { "name": "Theories.formula", "content": "abbrev formula := (val β†’ hProp) β†’ hProp" }, { "name": "Theories.mkstruct", "content": "def mkstruct (F : formula) :=\n fun (Q : val -> hProp) ↦ βˆƒΚ° Q', F Q' βˆ— (Q' -βˆ— Q)" }, { "name": "Theories.wpgen_val", "content": "def wpgen_val (v : val) : formula :=\n fun Q ↦ Q v" }, { "name": "Theories.wpgen_fun", "content": "def wpgen_fun (Fof : val β†’ formula) : formula :=\n fun Q ↦ hβˆ€ vf, ⌜forall vx Q', Fof vx Q' ==>\n wp (trm_app (trm_val vf) (trm_val vx)) Q'⌝ -βˆ— Q vf" }, { "name": "Theories.wpgen_fix", "content": "def wpgen_fix (Fof : val β†’ val β†’ formula) : formula :=\n fun Q ↦ hβˆ€ vf, ⌜forall vx Q', Fof vf vx Q' ==>\n wp (trm_app vf vx) Q'⌝ -βˆ— Q vf" }, { "name": "Theories.wpgen_seq", "content": "def wpgen_seq (F1 F2 : formula) : formula :=\n fun Q ↦ F1 (fun _ ↦ F2 Q)" }, { "name": "Theories.wpgen_let", "content": "def wpgen_let (F1 : formula) (F2of : val β†’ formula) : formula :=\n fun Q ↦ F1 (fun v ↦ F2of v Q)" }, { "name": "Theories.wpgen_if", "content": "def wpgen_if (t : trm) (F1 F2 : formula) : formula :=\n fun Q ↦ βˆƒΚ° (b : Bool),\n ⌜t = trm_val (val_bool b)⌝ βˆ— (if b then F1 Q else F2 Q)" }, { "name": "Theories.wpgen_app", "content": "@[simp]\ndef wpgen_app (t : trm) : formula :=\n fun Q ↦ βˆƒΚ° H, H βˆ— ⌜triple t H Q⌝" }, { "name": "Theories.wpgen_ref", "content": "def wpgen_ref (x : var) (t1 t2 : trm) : formula :=\n fun Q ↦ βˆƒΚ° v, ⌜t1 = trm_val v⌝ βˆ—\n hβˆ€ p, (p ~~> v) -βˆ— protect (wp (subst x p t2) (fun hv ↦ Q hv βˆ— βˆƒΚ° u, p ~~> u))" }, { "name": "Theories.wpgen_alloc", "content": "def wpgen_alloc (x : var) (t1 t2 : trm) : formula :=\n fun Q ↦ βˆƒΚ° n : β„€,\n ⌜n β‰₯ 0 ∧ t1 = trm_val n⌝ βˆ—\n hβˆ€ p,\n (hrange (make_list n.natAbs val_uninit) p) -βˆ—\n protect wp (subst x p t2) (Q βˆ— ⌜p β‰  null⌝ βˆ— βˆƒΚ° L, ⌜L.length = n⌝ βˆ— hrange L p)" }, { "name": "Theories.wpgen", "content": "def wpgen (t : trm) : formula :=\n mkstruct (match t with\n | trm_val v => wpgen_val v\n | trm_fun x t1 => wpgen_fun (fun v ↦ wp $ subst x v t1)\n | trm_fix f x t1 => wpgen_fix\n (fun vf v => wp $ subst x v $ subst f vf t1)\n | trm_if t0 t1 t2 => wpgen_if t0 (wp t1) (wp t2)\n | trm_seq t1 t2 => wpgen_seq (wp t1) (wp t2)\n | trm_let x t1 t2 => wpgen_let (wp t1) (fun v ↦ wp $ subst x v t2)\n | trm_app _ _ => wpgen_app t\n \n \n | trm_ref x t1 t2 => wpgen_ref x t1 t2\n | trm_alloc x t1 t2 => wpgen_alloc x t1 t2\n | _ => wp t\n )" }, { "name": "Theories.formula_sound", "content": "def formula_sound (t : trm) (F : formula) : Prop :=\n forall Q, F Q ==> wp t Q" }, { "name": "Theories.var_funs", "content": "@[simp]\nabbrev var_funs (xs:List var) (n:Nat) : Prop :=\n xs.Nodup\n /\\ xs.length = n\n /\\ xs != []" }, { "name": "Theories.trms_to_vals", "content": "@[simp]\ndef trms_to_vals (ts:List trm) : Option (List val) := do\n match ts with\n | [] => return []\n | (trm_val v) :: ts' => v :: (<- trms_to_vals ts')\n | _ => failure" }, { "name": "Theories.ctx", "content": "abbrev ctx := AList (fun _ : var ↦ val)" }, { "name": "Theories.isubst", "content": "def isubst (E : ctx) (t : trm) : trm :=\n match t with\n | trm_val v =>\n v\n | trm_var x =>\n match lookup x E with\n | none => t\n | some v => v\n | trm_fun x t1 =>\n trm_fun x (isubst (erase x E) t1)\n | trm_fix f x t1 =>\n trm_fix f x (isubst (erase x (erase f E)) t1)\n | trm_if t0 t1 t2 =>\n trm_if (isubst E t0) (isubst E t1) (isubst E t2)\n | trm_seq t1 t2 =>\n trm_seq (isubst E t1) (isubst E t2)\n | trm_let x t1 t2 =>\n trm_let x (isubst E t1) (isubst (erase x E) t2)\n | trm_ref x t1 t2 =>\n trm_ref x (isubst E t1) (isubst (erase x E) t2)\n | trm_alloc x t1 t2 =>\n trm_alloc x (isubst E t1) (isubst (erase x E) t2)\n | trm_app t1 t2 =>\n trm_app (isubst E t1) (isubst E t2)\n | trm_for x n1 n2 t =>\n trm_for x (isubst E n1) (isubst E n2) (isubst (erase x E) t)\n | trm_while c t =>\n trm_while (isubst E c) (isubst E t)" } ]
[ { "name": "Theories.wp_equiv", "content": "lemma wp_equiv t H Q :\n (H ==> wp t Q) ↔ triple t H Q" }, { "name": "Theories.wp_conseq", "content": "lemma wp_conseq t Q1 Q2 :\n Q1 ===> Q2 β†’\n wp t Q1 ==> wp t Q2" }, { "name": "Theories.wp_frame", "content": "lemma wp_frame t H Q :\n (wp t Q) βˆ— H ==> wp t (Q βˆ— H)" }, { "name": "Theories.wp_ramified", "content": "lemma wp_ramified t (Q1 Q2 : val -> hProp) :\n (wp t Q1) βˆ— (Q1 -βˆ— Q2) ==> (wp t Q2)" }, { "name": "Theories.wp_eval_like", "content": "lemma wp_eval_like t1 t2 Q :\n eval_like t1 t2 β†’\n wp t1 Q ==> wp t2 Q" }, { "name": "Theories.wp_val", "content": "lemma wp_val v Q :\n Q v ==> wp (trm_val v) Q" }, { "name": "Theories.wp_fun", "content": "lemma wp_fun x t Q :\n Q (val_fun x t) ==> wp (trm_fun x t) Q" }, { "name": "Theories.wp_fix", "content": "lemma wp_fix f x t Q :\n Q (val_fix f x t) ==> wp (trm_fix f x t) Q" }, { "name": "Theories.wp_app_fun", "content": "lemma wp_app_fun x v1 v2 t1 Q :\n v1 = val_fun x t1 β†’\n wp (subst x v2 t1) Q ==> wp (trm_app v1 v2) Q" }, { "name": "Theories.wp_app_fix", "content": "lemma wp_app_fix f x v1 v2 t1 Q :\n v1 = val_fix f x t1 β†’\n wp (subst x v2 (subst f v1 t1)) Q ==> wp (trm_app v1 v2) Q" }, { "name": "Theories.wp_seq", "content": "lemma wp_seq t1 t2 Q :\n wp t1 (fun _ ↦ wp t2 Q) ==> wp (trm_seq t1 t2) Q" }, { "name": "Theories.wp_let", "content": "lemma wp_let x t1 t2 Q :\n wp t1 (fun v ↦ wp (subst x v t2) Q) ==> wp (trm_let x t1 t2) Q" }, { "name": "Theories.wp_ref", "content": "lemma wp_ref x v t Q :\n (hβˆ€ p, (p ~~> v) -βˆ— wp (subst x p t) (Q βˆ— βˆƒΚ° v', (p ~~> v'))) ==>\n wp (trm_ref x v t) Q" }, { "name": "Theories.mem_conseq", "content": "lemma mem_conseq :\n x ∈ conseq L p β†’ p ≀ x" }, { "name": "Theories.hrange_of_conseq", "content": "lemma hrange_of_conseq :\n (hrange L p) (conseq L p)" }, { "name": "Theories.wp_alloc", "content": "lemma wp_alloc x (n : β„€) t Q :\n n β‰₯ 0 β†’\n (hβˆ€ p, (hrange (make_list n.natAbs val_uninit) p) -βˆ—\n wp (subst x p t) (Q βˆ— ⌜p β‰  null⌝ βˆ— βˆƒΚ° L, ⌜L.length = n⌝ βˆ— hrange L p)) ==>\n wp (trm_alloc x n t) Q" }, { "name": "Theories.mkstruct_erase", "content": "lemma mkstruct_erase Q F :\n F Q ==> mkstruct F Q" }, { "name": "Theories.mkstruct_monotone", "content": "lemma mkstruct_monotone F1 F2 Q :\n (forall Q, F1 Q ==> F2 Q) β†’\n mkstruct F1 Q ==> mkstruct F2 Q" }, { "name": "Theories.mkstruct_wp", "content": "lemma mkstruct_wp t :\n mkstruct (wp t) = wp t" }, { "name": "Theories.mkstruct_sound", "content": "lemma mkstruct_sound t F :\n formula_sound t F β†’\n formula_sound t (mkstruct F)" }, { "name": "Theories.wpgen_val_sound", "content": "lemma wpgen_val_sound v :\n formula_sound (trm_val v) (wpgen_val v)" }, { "name": "Theories.wpgen_fun_sound", "content": "lemma wpgen_fun_sound x t1 Fof :\n (forall vx, formula_sound (subst x vx t1) (Fof vx)) β†’\n formula_sound (trm_fun x t1) (wpgen_fun Fof)" }, { "name": "Theories.wpgen_fix_sound", "content": "lemma wpgen_fix_sound f x t1 Fof :\n (forall vf vx, formula_sound (subst x vx (subst f vf t1)) (Fof vf vx)) β†’\n formula_sound (trm_fix f x t1) (wpgen_fix Fof)" }, { "name": "Theories.wpgen_seq_sound", "content": "lemma wpgen_seq_sound F1 F2 t1 t2 :\n formula_sound t1 F1 β†’\n formula_sound t2 F2 β†’\n formula_sound (trm_seq t1 t2) (wpgen_seq F1 F2)" }, { "name": "Theories.wpgen_let_sound", "content": "lemma wpgen_let_sound F1 F2of x t1 t2 :\n formula_sound t1 F1 β†’\n (forall v, formula_sound (subst x v t2) (F2of v)) β†’\n formula_sound (trm_let x t1 t2) (wpgen_let F1 F2of)" }, { "name": "Theories.wpgen_if_sound", "content": "lemma wpgen_if_sound F1 F2 t0 t1 t2 :\n formula_sound t1 F1 β†’\n formula_sound t2 F2 β†’\n formula_sound (trm_if t0 t1 t2) (wpgen_if t0 F1 F2)" }, { "name": "Theories.wpgen_app_sound", "content": "lemma wpgen_app_sound t :\n formula_sound t (wpgen_app t)" }, { "name": "Theories.wpgen_ref_sound", "content": "lemma wpgen_ref_sound x t1 t2 :\n formula_sound (trm_ref x t1 t2) (wpgen_ref x t1 t2)" }, { "name": "Theories.wpgen_alloc_sound", "content": "lemma wpgen_alloc_sound x t1 t2 :\n formula_sound (trm_alloc x t1 t2) (wpgen_alloc x t1 t2)" }, { "name": "Theories.wpgen_sound", "content": "lemma wpgen_sound t :\n formula_sound t (wpgen t)" }, { "name": "Theories.himpl_wpgen_wp", "content": "lemma himpl_wpgen_wp t Q :\n wpgen t Q ==> wp t Q" }, { "name": "Theories.triple_of_wpgen", "content": "lemma triple_of_wpgen t H Q :\n H ==> wpgen t Q β†’\n triple t H Q" }, { "name": "Theories.wp_of_wpgen", "content": "lemma wp_of_wpgen :\n H ==> wpgen t Q β†’\n H ==> wp t Q" }, { "name": "Theories.trms_to_vals_some_equiv", "content": "lemma trms_to_vals_some_equiv ts vs : trms_to_vals ts = some vs β†’ ts = vs.map trm_val" }, { "name": "Theories.List.toAList_perm", "content": "lemma List.toAList_perm {Ξ± : Type u} {Ξ² : Ξ± β†’ Type v} [DecidableEq Ξ±]\n (es es' : List (Sigma Ξ²)) (hnodup : es.NodupKeys) (hp : es.Perm es') :\n es.toAList.entries.Perm es'.toAList.entries" }, { "name": "Theories.List.mkAlist_snoc_to_cons", "content": "lemma List.mkAlist_snoc_to_cons [DecidableEq Ξ±] (xs : List Ξ±) (vs : List Ξ²)\n (x : Ξ±) (v : Ξ²) : x βˆ‰ xs β†’ xs.length = vs.length β†’ xs.Nodup β†’\n ((xs ++ [x]).mkAlist (vs ++ [v])).entries.Perm (((x :: xs).mkAlist (v :: vs)).entries)" }, { "name": "Theories.AList.erase_insert_cancel", "content": "lemma AList.erase_insert_cancel {Ξ± : Type u} {Ξ² : Ξ± β†’ Type v} [DecidableEq Ξ±] (a : Ξ±) (b : Ξ² a) (l : AList Ξ²) :\n (AList.erase a (AList.insert a b l)).entries.Perm (AList.erase a l).entries" }, { "name": "Theories.AList.erase_insert_swap", "content": "lemma AList.erase_insert_swap {Ξ± : Type u} {Ξ² : Ξ± β†’ Type v} [DecidableEq Ξ±] (a a' : Ξ±) (b : Ξ² a) (l : AList Ξ²) :\n a β‰  a' β†’ (AList.erase a' (AList.insert a b l)).entries.Perm (AList.insert a b (AList.erase a' l)).entries" }, { "name": "Theories.AList.erase_noop", "content": "lemma AList.erase_noop {Ξ± : Type u} {Ξ² : Ξ± β†’ Type v} [DecidableEq Ξ±] (a : Ξ±) (l : AList Ξ²) :\n a βˆ‰ l β†’ (AList.erase a l).entries.Perm l.entries" }, { "name": "Theories.AList.erase_twice", "content": "lemma AList.erase_twice {Ξ± : Type u} {Ξ² : Ξ± β†’ Type v} [DecidableEq Ξ±] (a : Ξ±) (l : AList Ξ²) :\n (AList.erase a (AList.erase a l)).entries.Perm (AList.erase a l).entries" }, { "name": "Theories.AList.erase_empty", "content": "lemma AList.erase_empty {Ξ± : Type u} {Ξ² : Ξ± β†’ Type v} [DecidableEq Ξ±] (a : Ξ±) :\n AList.erase a (βˆ… : AList Ξ²) = βˆ…" }, { "name": "Theories.isubst_empty", "content": "lemma isubst_empty t : isubst βˆ… t = t" }, { "name": "Theories.isubst_perm", "content": "lemma isubst_perm {al al'} t (hp : al.entries.Perm al'.entries) :\n isubst al t = isubst al' t" }, { "name": "Theories.isubst_insert", "content": "lemma isubst_insert (al : ctx) x v t :\n isubst (al.insert x v) t = subst x v (isubst (al.erase x) t)" }, { "name": "Theories.isubst_single", "content": "lemma isubst_single x v t : isubst (List.mkAlist [x] [v]) t = subst x v t" }, { "name": "Theories.trm_apps2", "content": "lemma trm_apps2 :\n trm_apps (trm_app t1 t2) ts = trm_apps t1 (t2::ts)" }, { "name": "Theories.trm_apps_app", "content": "lemma trm_apps_app :\n trm_apps t1 (ts ++ ts') = trm_apps (trm_apps t1 ts) ts'" }, { "name": "Theories.trm_funs_app", "content": "lemma trm_funs_app :\n trm_funs (xs ++ xs') t1 = trm_funs xs (trm_funs xs' t1)" }, { "name": "Theories.eval_like_trm_fun_val_fun", "content": "lemma eval_like_trm_fun_val_fun x t : eval_like (trm_fun x t) (val_fun x t)" }, { "name": "Theories.eval_like_val_fun_trm_fun", "content": "lemma eval_like_val_fun_trm_fun x t : eval_like (val_fun x t) (trm_fun x t)" }, { "name": "Theories.eval_like_trm_app_left", "content": "lemma eval_like_trm_app_left t1 t1' t2 (hsat : βˆƒ s Q, eval s t1 Q) : eval_like t1 t1' β†’ eval_like (trm_app t1 t2) (trm_app t1' t2)" }, { "name": "Theories.eval_like_trm_fun_val_fun_app_left", "content": "lemma eval_like_trm_fun_val_fun_app_left (x : var) (t1 t2 : trm) :\n eval_like (trm_app (trm_fun x t1) t2) (trm_app (val_fun x t1) t2)" }, { "name": "Theories.eval_like_val_fun_trm_fun_app_left", "content": "lemma eval_like_val_fun_trm_fun_app_left (x : var) (t1 t2 : trm) :\n eval_like (trm_app (val_fun x t1) t2) (trm_app (trm_fun x t1) t2)" }, { "name": "Theories.val_funs_snoc", "content": "lemma val_funs_snoc (xs : List var) (x : var) (h : xs β‰  []) (t : trm) :\n val_funs (xs ++ [x]) t = val_funs xs (trm_fun x t)" }, { "name": "Theories.List.not_nil_snoc", "content": "lemma List.not_nil_snoc {Ξ± : Type u} (l : List Ξ±) : l β‰  [] β†’ βˆƒ l' x, l = l' ++ [x]" }, { "name": "Theories.eval_like_trm_apps_funs_pre", "content": "lemma eval_like_trm_apps_funs_pre (heqv0 : v0 = trm_funs xs t1) :\n eval_like t (trm_apps (val_funs xs t1) ts) ∧ -- NOTE: this part do not require `xs.Nodup`, but anyway\n eval_like (isubst (xs.mkAlist vs) t1) t" }, { "name": "Theories.eval_like_trm_apps_funs", "content": "lemma eval_like_trm_apps_funs (heqv0 : v0 = trm_funs xs t1) :\n eval_like (isubst (xs.mkAlist vs) t1) (trm_apps (val_funs xs t1) ts)" } ]
import Lean import Mathlib.Data.Finmap import Mathlib.Data.List.Indexes import SPLean.Common.State import SPLean.Common.Util import SPLean.Theories.HProp import SPLean.Theories.XSimp import SPLean.Theories.XChange import SPLean.Theories.SepLog import SPLean.Theories.WPUtil open trm val prim namespace Theories def wp (t : trm) (Q : val β†’ hProp) : hProp := fun s ↦ eval s t Q abbrev formula := (val β†’ hProp) β†’ hProp def mkstruct (F : formula) := fun (Q : val -> hProp) ↦ βˆƒΚ° Q', F Q' βˆ— (Q' -βˆ— Q) def wpgen_val (v : val) : formula := fun Q ↦ Q v def wpgen_fun (Fof : val β†’ formula) : formula := fun Q ↦ hβˆ€ vf, ⌜forall vx Q', Fof vx Q' ==> wp (trm_app (trm_val vf) (trm_val vx)) Q'⌝ -βˆ— Q vf def wpgen_fix (Fof : val β†’ val β†’ formula) : formula := fun Q ↦ hβˆ€ vf, ⌜forall vx Q', Fof vf vx Q' ==> wp (trm_app vf vx) Q'⌝ -βˆ— Q vf def wpgen_seq (F1 F2 : formula) : formula := fun Q ↦ F1 (fun _ ↦ F2 Q) def wpgen_let (F1 : formula) (F2of : val β†’ formula) : formula := fun Q ↦ F1 (fun v ↦ F2of v Q) def wpgen_if (t : trm) (F1 F2 : formula) : formula := fun Q ↦ βˆƒΚ° (b : Bool), ⌜t = trm_val (val_bool b)⌝ βˆ— (if b then F1 Q else F2 Q) @[simp] def wpgen_app (t : trm) : formula := fun Q ↦ βˆƒΚ° H, H βˆ— ⌜triple t H Q⌝ def wpgen_ref (x : var) (t1 t2 : trm) : formula := fun Q ↦ βˆƒΚ° v, ⌜t1 = trm_val v⌝ βˆ— hβˆ€ p, (p ~~> v) -βˆ— protect (wp (subst x p t2) (fun hv ↦ Q hv βˆ— βˆƒΚ° u, p ~~> u)) def wpgen_alloc (x : var) (t1 t2 : trm) : formula := fun Q ↦ βˆƒΚ° n : β„€, ⌜n β‰₯ 0 ∧ t1 = trm_val n⌝ βˆ— hβˆ€ p, (hrange (make_list n.natAbs val_uninit) p) -βˆ— protect wp (subst x p t2) (Q βˆ— ⌜p β‰  null⌝ βˆ— βˆƒΚ° L, ⌜L.length = n⌝ βˆ— hrange L p) def wpgen (t : trm) : formula := mkstruct (match t with | trm_val v => wpgen_val v | trm_fun x t1 => wpgen_fun (fun v ↦ wp $ subst x v t1) | trm_fix f x t1 => wpgen_fix (fun vf v => wp $ subst x v $ subst f vf t1) | trm_if t0 t1 t2 => wpgen_if t0 (wp t1) (wp t2) | trm_seq t1 t2 => wpgen_seq (wp t1) (wp t2) | trm_let x t1 t2 => wpgen_let (wp t1) (fun v ↦ wp $ subst x v t2) | trm_app _ _ => wpgen_app t | trm_ref x t1 t2 => wpgen_ref x t1 t2 | trm_alloc x t1 t2 => wpgen_alloc x t1 t2 | _ => wp t ) def formula_sound (t : trm) (F : formula) : Prop := forall Q, F Q ==> wp t Q section tactics open Lean Elab Tactic section xapp end xapp end tactics @[simp] abbrev var_funs (xs:List var) (n:Nat) : Prop := xs.Nodup /\ xs.length = n /\ xs != [] @[simp] def trms_to_vals (ts:List trm) : Option (List val) := do match ts with | [] => return [] | (trm_val v) :: ts' => v :: (<- trms_to_vals ts') | _ => failure open AList abbrev ctx := AList (fun _ : var ↦ val) def isubst (E : ctx) (t : trm) : trm := match t with | trm_val v => v | trm_var x => match lookup x E with | none => t | some v => v | trm_fun x t1 => trm_fun x (isubst (erase x E) t1) | trm_fix f x t1 => trm_fix f x (isubst (erase x (erase f E)) t1) | trm_if t0 t1 t2 => trm_if (isubst E t0) (isubst E t1) (isubst E t2) | trm_seq t1 t2 => trm_seq (isubst E t1) (isubst E t2) | trm_let x t1 t2 => trm_let x (isubst E t1) (isubst (erase x E) t2) | trm_ref x t1 t2 => trm_ref x (isubst E t1) (isubst (erase x E) t2) | trm_alloc x t1 t2 => trm_alloc x (isubst E t1) (isubst (erase x E) t2) | trm_app t1 t2 => trm_app (isubst E t1) (isubst E t2) | trm_for x n1 n2 t => trm_for x (isubst E n1) (isubst E n2) (isubst (erase x E) t) | trm_while c t => trm_while (isubst E c) (isubst E t) section funs_fixs_eval_like variable (xs : List var) (vs : List val) (t : trm) (v0 : trm) (heqt : t = trm_apps v0 ts) (hconv : trms_to_vals ts = vs) (hform : var_funs xs vs.length) -- NOTE: can be relaxed to `vs.length ≀ xs.length` variable (f : var) (hf : f βˆ‰ xs) end funs_fixs_eval_like
lemma xwp_lemma_funs (xs : List _) (vs : List val) : t = trm_apps v0 ts -> v0 = val_funs xs t1 -> trms_to_vals ts = vs -> var_funs xs vs.length -> H ==> wpgen (isubst (xs.mkAlist vs) t1) Q -> triple t H Q :=
:= by move=> -> -> ?? h srw -wp_equiv ; apply himpl_trans ; apply (wp_of_wpgen h) apply wp_eval_like apply eval_like_trm_apps_funs=> //
11
228
false
Framework
408
Theories.xapp_simpl_lemma
lemma xapp_simpl_lemma (F : formula) : H ==> F Q -> H ==> F Q βˆ— (Q -βˆ— protect Q)
splean
SPLean/Theories/WP1.lean
[ "import SPLean.Theories.XChange", "import Mathlib.Data.List.Indexes", "import SPLean.Theories.XSimp", "import SPLean.Theories.SepLog", "import Mathlib.Data.Finmap", "import SPLean.Common.State", "import SPLean.Theories.HProp", "import SPLean.Common.Util", "import Lean", "import SPLean.Theories.WPUtil" ]
[ { "name": "String", "module": "Init.Prelude" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "Finmap", "module": "Mathlib.Data.Finmap" }, { "name": "move", "module": "Ssreflect.Basic" } ]
[ { "name": "macro \"xsimp\" : tactic =>", "content": "macro \"xsimp\" : tactic =>\n `(tactic| (\n xsimp_start\n repeat xsimp_step\n try rev_pure\n try hide_mvars\n try hsimp\n rotate_left\n\n ))" }, { "name": "hProp", "content": "def hProp := heap -> Prop" }, { "name": "heap", "content": "abbrev heap := Heap.heap val\n\n inductive val : Type where\n | val_unit : val\n | val_bool : Bool β†’ val\n | val_int : Int β†’ val\n | val_real : ℝ β†’ val\n | val_loc : loc β†’ val\n | val_prim : prim β†’ val\n | val_fun : var -> trm -> val\n | val_fix : var -> var -> trm -> val\n | val_uninit : val\n | val_error : val" }, { "name": "prim", "content": "inductive prim where\n \n | val_get : prim\n | val_set : prim\n \n | val_neg : prim\n | val_opp : prim\n | val_eq : prim\n | val_add : prim\n | val_neq : prim\n | val_sub : prim\n | val_mul : prim\n | val_div : prim\n | val_mod : prim\n \n | val_le : prim\n | val_lt : prim\n | val_ge : prim\n | val_gt : prim\n | val_ptr_add : prim\n\n inductive trm : Type where\n | trm_val : val -> trm\n | trm_var : var -> trm\n | trm_fun : var -> trm -> trm\n | trm_fix : var -> var -> trm -> trm\n | trm_app : trm -> trm -> trm\n | trm_seq : trm -> trm -> trm\n | trm_let : var -> trm -> trm -> trm\n | trm_if : trm -> trm -> trm -> trm\n | trm_for : var -> trm -> trm -> trm -> trm\n | trm_while : trm -> trm -> trm\n | trm_ref : var β†’ trm β†’ trm β†’ trm\n | trm_alloc : var β†’ trm β†’ trm β†’ trm" }, { "name": "var", "content": "abbrev var := String" }, { "name": "loc", "content": "abbrev loc := Nat" }, { "name": "Heap.heap", "content": "abbrev Heap.heap (val : Type) := Finmap (Ξ» _ : loc ↦ val)" }, { "name": "HWand", "content": "class HWand (Ξ± : Type u) (Ξ² : Type v) (Ξ³ : outParam (Type w)) where\n \n hWand : Ξ± β†’ Ξ² β†’ Ξ³" }, { "name": "protect", "content": "@[heapSimp]\ndef protect (x : Ξ±) := x" }, { "name": "HStar", "content": "class HStar (Ξ± : Type u) (Ξ² : Type v) (Ξ³ : outParam (Type w)) where\n \n hStar : Ξ± β†’ Ξ² β†’ Ξ³" }, { "name": "himpl", "content": "abbrev himpl (H1 H2 : hProp) : Prop :=\n forall h, H1 h -> H2 h" }, { "name": "infixr:51 \" ==> \" => himpl", "content": "infixr:51 \" ==> \" => himpl" }, { "name": "infixr:55 \" βˆ— \" => HStar.hStar", "content": "infixr:55 \" βˆ— \" => HStar.hStar" }, { "name": "infixr:55 \" -βˆ— \" => HWand.hWand", "content": "infixr:55 \" -βˆ— \" => HWand.hWand" } ]
[ { "name": "...", "module": "" } ]
[ { "name": "himpl_trans", "content": "lemma himpl_trans H2 H1 H3 :\n (H1 ==> H2) β†’ (H2 ==> H3) β†’ (H1 ==> H3)" }, { "name": "himpl_hempty_hwand_same", "content": "lemma himpl_hempty_hwand_same H :\n emp ==> (H -βˆ— H)" } ]
[ { "name": "Theories.formula", "content": "abbrev formula := (val β†’ hProp) β†’ hProp" } ]
[]
import Lean import Mathlib.Data.Finmap import Mathlib.Data.List.Indexes import SPLean.Common.State import SPLean.Common.Util import SPLean.Theories.HProp import SPLean.Theories.XSimp import SPLean.Theories.XChange import SPLean.Theories.SepLog import SPLean.Theories.WPUtil open trm val prim namespace Theories abbrev formula := (val β†’ hProp) β†’ hProp section tactics open Lean Elab Tactic
lemma xapp_simpl_lemma (F : formula) : H ==> F Q -> H ==> F Q βˆ— (Q -βˆ— protect Q) :=
:= by move=> hh; apply himpl_trans ; apply hh ; xsimp
7
20
false
Framework
409
hseg_focus_relative
lemma hseg_focus_relative (k : Nat) L p j (v : 0 <= k ∧ k < L.length): hseg L p j ==> hcell L[k]! p (j + k) βˆ— (hβˆ€ w, hcell w p (j + k) -βˆ— hseg (L.set k w) p j)
splean
SPLean/Theories/Arrays.lean
[ "import SPLean.Theories.XChange", "import SPLean.Theories.Lang", "import SPLean.Theories.WP1", "import SPLean.Theories.XSimp", "import SPLean.Theories.SepLog", "import SPLean.Common.State", "import SPLean.Theories.HProp", "import SPLean.Common.Util" ]
[ { "name": "String", "module": "Init.Prelude" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "Finmap", "module": "Mathlib.Data.Finmap" }, { "name": "Finmap.singleton", "module": "Mathlib.Data.Finmap" }, { "name": "Int.natAbs", "module": "Init.Data.Int.Basic" }, { "name": "List", "module": "Init.Prelude" }, { "name": "L", "module": "Archive.Hairer" }, { "name": "Eq", "module": "Init.Prelude" }, { "name": "move", "module": "Ssreflect.Basic" }, { "name": "sby", "module": "Ssreflect.Done" }, { "name": "sdone", "module": "Ssreflect.Done" }, { "name": "srw", "module": "Ssreflect.Rewrite" }, { "name": "Inhabited", "module": "Init.Prelude" }, { "name": "elim", "module": "Ssreflect.Elim" } ]
[ { "name": "notation:max \"emp\" => hempty", "content": "notation:max \"emp\" => hempty\n\nsyntax \"fun\" ident+ \" => \" lang : lang\n\nsyntax \" >= \" : bop" }, { "name": "notation:max \"⌜\" P \"⌝\" => hpure P", "content": "notation:max \"⌜\" P \"⌝\" => hpure P\n\nsyntax \"if \" lang \"then \" lang \"end \" : lang\n\nsyntax \" := \" : bop\n\nsyntax \"let\" ident \" := \" lang \" in\" ppDedent(ppLine lang) : lang\n\nsyntax \" ++ \" : bop" }, { "name": "macro \"hsimp\" : tactic => `(tactic| (simp only [heapSimp]; t", "content": "macro \"hsimp\" : tactic => `(tactic| (simp only [heapSimp]; try dsimp))\n\nsyntax \" <= \" : bop" }, { "name": "macro \"xsimp\" : tactic =>", "content": "macro \"xsimp\" : tactic =>\n `(tactic| (\n xsimp_start\n repeat xsimp_step\n try rev_pure\n try hide_mvars\n try hsimp\n rotate_left\n\n ))" }, { "name": "macro \"hβˆ€\" xs:Lean.explicitBinders \", \" b:term : term => Lea", "content": "macro \"hβˆ€\" xs:Lean.explicitBinders \", \" b:term : term => Lean.expandExplicitBinders ``hforall xs b" }, { "name": "macro_rules", "content": "macro_rules\n | `([lang| ()]) => `(trm_val (val_unit))\n | `([lang| $n:num]) => `(trm_val (val_int $n))\n | `([lang| $t1 $t2]) => `(trm_app [lang| $t1] [lang| $t2])\n | `([lang| if $t1 then $t2 else $t3]) => `(trm_if [lang| $t1] [lang| $t2] [lang| $t3])\n | `([lang| if $t1 then $t2 end]) => `(trm_if [lang| $t1] [lang| $t2] (trm_val val_unit))\n | `([lang| let $x := $t1:lang in $t2:lang]) =>\n `(trm_let $(%x) [lang| $t1] [lang| $t2])\n | `([lang| ref $x := $t1:lang in $t2:lang]) =>\n `(trm_ref $(%x) [lang| $t1] [lang| $t2])\n | `([lang| alloc $t1:lang as $x in $t2:lang]) =>\n `(trm_alloc $(%x) [lang| $t1] [lang| $t2])\n | `([lang| $t1 ; $t2]) => `(trm_seq [lang| $t1] [lang| $t2])\n | `([lang| fun_ $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(trm_funs [ $xs,* ] [lang| $t])\n | `([lang| fun $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(val_funs [ $xs,* ] [lang| $t])\n | `([lang| fix_ $f $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(trm_fixs $(%f) [ $xs,* ] [lang| $t])\n | `([lang| fix $f $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(val_fixs $(%f) [ $xs,* ] [lang| $t])\n \n | `([lang| free $t]) => `(trm_val (val_prim val_free) [lang| $t])\n | `([lang| not $t]) => `(trm_val (val_prim val_not) [lang| $t])\n \n | `([lang| !$t]) => `(trm_val val_get [lang| $t])\n | `([lang| $t1 := $t2]) => `(trm_val val_set [lang| $t1] [lang| $t2])\n | `([lang| $t1 + $t2]) => `(trm_val val_add [lang| $t1] [lang| $t2])\n | `([lang| $t1 * $t2]) => `(trm_val val_mul [lang| $t1] [lang| $t2])\n | `([lang| $t1 - $t2]) => `(trm_val val_sub [lang| $t1] [lang| $t2])\n | `([lang| $t1 / $t2]) => `(trm_val val_div [lang| $t1] [lang| $t2])\n | `([lang| $t1 < $t2]) => `(trm_val val_lt [lang| $t1] [lang| $t2])\n | `([lang| $t1 > $t2]) => `(trm_val val_gt [lang| $t1] [lang| $t2])\n | `([lang| $t1 <= $t2]) => `(trm_val val_le [lang| $t1] [lang| $t2])\n | `([lang| $t1 >= $t2]) => `(trm_val val_ge [lang| $t1] [lang| $t2])\n | `([lang| -$t]) => `(trm_val val_opp [lang| $t])\n | `([lang| $t1 = $t2]) => `(trm_val val_eq [lang| $t1] [lang| $t2])\n | `([lang| $t1 != $t2]) => `(trm_val val_neq [lang| $t1] [lang| $t2])\n | `([lang| $t1 mod $t2]) => `(trm_val val_mod [lang| $t1] [lang| $t2])\n | `([lang| $t1 ++ $t2]) => `(trm_val val_ptr_add [lang| $t1] [lang| $t2])\n | `([lang| ($t)]) => `([lang| $t])\n | `([lang| ⟨$t : $tp⟩]) => `(trm_val (($t : $tp)))\n | `([lang| for $x in [$n1 : $n2] { $t } ]) =>\n `(trm_for $(%x) [lang| $n1] [lang| $n2] [lang| $t])\n | `([lang| while $c:lang { $t:lang } ]) =>\n `(trm_while [lang| $c] [lang| $t] )" }, { "name": "macro_rules", "content": "macro_rules\n | `([lang| len $p]) => `(trm_val val_array_length [lang| $p])\n | `([lang| $arr[$i] ]) => `(trm_val val_array_get [lang| $arr] [lang| $i])\n \n | `([lang| $arr[$i] := $v]) => `(trm_app val_array_set [lang| $arr] [lang| $i] [lang| $v])\n | `([lang| mkarr $n:lang $v:lang]) => `(trm_val val_array_make [lang| $n] [lang| $v])" }, { "name": "macro_rules | `($x βˆ— $y) => `(binop% HStar.hStar $x $y)", "content": "macro_rules | `($x βˆ— $y) => `(binop% HStar.hStar $x $y)" }, { "name": "HStar", "content": "class HStar (Ξ± : Type u) (Ξ² : Type v) (Ξ³ : outParam (Type w)) where\n \n hStar : Ξ± β†’ Ξ² β†’ Ξ³" }, { "name": "hseg", "content": "def hseg (L : List val) (p : loc) (j : Int) : hProp :=\n match L with\n | [] => emp\n | x :: L' => (hcell x p j) βˆ— (hseg L' p (j + 1))" }, { "name": "hcell", "content": "def hcell (v : val) (p : loc) (i : Int) : hProp :=\n ((p + 1 + (Int.natAbs i)) ~~> v) βˆ— ⌜i >= 0⌝" }, { "name": "hsingle", "content": "def hsingle (p : loc) (v : val) : hProp :=\n fun h => (h = Finmap.singleton p v)" }, { "name": "hProp", "content": "def hProp := heap -> Prop" }, { "name": "heap", "content": "abbrev heap := Heap.heap val\n\n inductive val : Type where\n | val_unit : val\n | val_bool : Bool β†’ val\n | val_int : Int β†’ val\n | val_real : ℝ β†’ val\n | val_loc : loc β†’ val\n | val_prim : prim β†’ val\n | val_fun : var -> trm -> val\n | val_fix : var -> var -> trm -> val\n | val_uninit : val\n | val_error : val" }, { "name": "prim", "content": "inductive prim where\n \n | val_get : prim\n | val_set : prim\n \n | val_neg : prim\n | val_opp : prim\n | val_eq : prim\n | val_add : prim\n | val_neq : prim\n | val_sub : prim\n | val_mul : prim\n | val_div : prim\n | val_mod : prim\n \n | val_le : prim\n | val_lt : prim\n | val_ge : prim\n | val_gt : prim\n | val_ptr_add : prim\n\n inductive trm : Type where\n | trm_val : val -> trm\n | trm_var : var -> trm\n | trm_fun : var -> trm -> trm\n | trm_fix : var -> var -> trm -> trm\n | trm_app : trm -> trm -> trm\n | trm_seq : trm -> trm -> trm\n | trm_let : var -> trm -> trm -> trm\n | trm_if : trm -> trm -> trm -> trm\n | trm_for : var -> trm -> trm -> trm -> trm\n | trm_while : trm -> trm -> trm\n | trm_ref : var β†’ trm β†’ trm β†’ trm\n | trm_alloc : var β†’ trm β†’ trm β†’ trm" }, { "name": "var", "content": "abbrev var := String" }, { "name": "loc", "content": "abbrev loc := Nat" }, { "name": "Heap.heap", "content": "abbrev Heap.heap (val : Type) := Finmap (Ξ» _ : loc ↦ val)" }, { "name": "evalExact", "content": "inductive evalExact : state β†’ trm β†’ (val β†’ state β†’ Prop) -> Prop where\n | val : forall s v,\n evalExact s (trm_val v) (fun v' s' ↦ v' = v ∧ s' = s)\n | fun : forall s x t1,\n evalExact s (trm_fun x t1) (fun v' s' ↦ v' = val_fun x t1 ∧ s' = s)\n | fix : forall s f x t1,\n evalExact s (trm_fix f x t1) (fun v' s' ↦ v' = val_fix f x t1 ∧ s' = s)\n | app_arg1 : forall s1 t1 t2 Q1 Q,\n Β¬ trm_is_val t1 ->\n evalExact s1 t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 (trm_app v1 t2) Q) ->\n evalExact s1 (trm_app t1 t2) Q\n | app_arg2 : forall s1 (v1 : val) t2 Q1 Q,\n Β¬ trm_is_val t2 ->\n evalExact s1 t2 Q1 ->\n (forall v2 s2, Q1 v2 s2 -> evalExact s2 (trm_app v1 v2) Q) ->\n evalExact s1 (trm_app v1 t2) Q\n | app_fun : forall s1 v1 (v2 :val) x t1 Q,\n v1 = val_fun x t1 ->\n evalExact s1 (subst x v2 t1) Q ->\n evalExact s1 (trm_app v1 v2) Q\n | app_fix : forall s (v1 v2 : val) f x t1 Q,\n v1 = val_fix f x t1 ->\n evalExact s (subst x v2 (subst f v1 t1)) Q ->\n evalExact s (trm_app v1 v2) Q\n | seq : forall Q1 s t1 t2 Q,\n evalExact s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 t2 Q) ->\n evalExact s (trm_seq t1 t2) Q\n | let : forall Q1 s x t1 t2 Q,\n evalExact s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 (subst x v1 t2) Q) ->\n evalExact s (trm_let x t1 t2) Q\n | if : forall s (b : Bool) t1 t2 Q,\n evalExact s (if b then t1 else t2) Q ->\n evalExact s (trm_if (val_bool b) t1 t2) Q\n | unop : forall op s v1 P,\n evalunop op v1 P ->\n evalExact s (trm_app op v1) (purepost s P)\n | binop : forall op s (v1 v2 : val) P,\n evalbinop op v1 v2 P ->\n evalExact s (trm_app (trm_app op v1) v2) (purepost s P)\n | ref : forall s x t1 t2 Q Q₁,\n evalExact s t1 Q₁ β†’\n (βˆ€ v1 s1, Q₁ v1 s1 β†’ βˆ€ p βˆ‰ s1,\n evalExact (s1.insert p v1) (subst x p t2) fun v s ↦ Q v (s.erase p)) β†’\n evalExact s (trm_ref x t1 t2) Q\n | get : forall s p,\n p ∈ s ->\n evalExact s (trm_app val_get (val_loc p))\n (fun v' s' ↦ v' = read_state p s ∧ s' = s)\n | set : forall s p v,\n v = trm_val v' ->\n p ∈ s ->\n evalExact s (trm_app (trm_app val_set (val_loc p)) v)\n (fun v'' s' ↦ v'' = val_unit ∧ s' = s.insert p v')\n | alloc_arg : forall s Q₁ Q,\n Β¬ trm_is_val t1 β†’\n evalExact s t1 Q₁ β†’\n (βˆ€ v' s', Q₁ v' s' β†’ evalExact s' (trm_alloc x v' t2) Q) β†’\n evalExact s (trm_alloc x t1 t2) Q\n | alloc : forall (sa : state) (n : β„€) Q,\n n β‰₯ 0 β†’\n (βˆ€ (p : loc) (sb : state),\n sb = conseq (make_list n.natAbs val_uninit) p β†’\n p β‰  null β†’\n Finmap.Disjoint sa sb β†’\n evalExact (sb βˆͺ sa) (subst x p t2) fun v s ↦ Q v (s \\ sb)) β†’\n evalExact sa (trm_alloc x n t2) Q\n \n \n \n \n \n \n | for (n₁ nβ‚‚ : Int) (Q : val -> state -> Prop) :\n evalExact s (if (n₁ < nβ‚‚) then\n (trm_seq (subst x n₁ t₁) (trm_for x (val_int (n₁ + 1)) nβ‚‚ t₁))\n else val_unit) Q ->\n evalExact s (trm_for x n₁ nβ‚‚ t₁) Q\n | while (t₁ tβ‚‚ : trm) (Q Q₁ : val -> state -> Prop) :\n evalExact s t₁ Q₁ ->\n (βˆ€ s v, Q₁ v s -> evalExact s (trm_if v (trm_seq tβ‚‚ (trm_while t₁ tβ‚‚)) val_unit) Q) ->\n evalExact s (trm_while t₁ tβ‚‚) Q" }, { "name": "hpure", "content": "def hpure (P : Prop) : hProp :=\n hexists (fun (_ : P) => emp)" }, { "name": "hexists", "content": "def hexists {A} (J : A β†’ hProp) : hProp :=\n fun h => exists x, J x h" }, { "name": "hempty", "content": "def hempty : hProp :=\n fun h => (h = βˆ…)" }, { "name": "subst", "content": "def subst (y : var) (v' : val) (t : trm) : trm :=\n \n let if_y_eq x t1 t2 := if x = y then t1 else t2\n match t with\n | trm_val v => trm_val v\n | trm_var x => if_y_eq x (trm_val v') t\n | trm_fun x t1 => trm_fun x (if_y_eq x t1 (subst y v' t1))\n | trm_fix f x t1 => trm_fix f x (if_y_eq f t1 (if_y_eq x t1 (subst y v' t1)))\n | trm_app t1 t2 => trm_app (subst y v' t1) (subst y v' t2)\n | trm_seq t1 t2 => trm_seq (subst y v' t1) (subst y v' t2)\n | trm_let x t1 t2 => trm_let x (subst y v' t1) (if_y_eq x t2 (subst y v' t2))\n | trm_if t0 t1 t2 => trm_if (subst y v' t0) (subst y v' t1) (subst y v' t2)\n | trm_for x t1 t2 t3 => trm_for x (subst y v' t1) (subst y v' t2) (if_y_eq x t3 (subst y v' t3))\n | trm_while t1 t2 => trm_while (subst y v' t1) (subst y v' t2)\n | trm_ref x t1 t2 => trm_ref x (subst y v' t1) (if_y_eq x t2 (subst y v' t2))\n | trm_alloc x t1 t2 => trm_alloc x (subst y v' t1) (if_y_eq x t2 (subst y v' t2))" }, { "name": "HWand", "content": "class HWand (Ξ± : Type u) (Ξ² : Type v) (Ξ³ : outParam (Type w)) where\n \n hWand : Ξ± β†’ Ξ² β†’ Ξ³" }, { "name": "himpl", "content": "abbrev himpl (H1 H2 : hProp) : Prop :=\n forall h, H1 h -> H2 h" }, { "name": "hforall", "content": "def hforall {A} (J : A β†’ hProp) : hProp :=\n fun h => forall x, J x h" }, { "name": "infixr:51 \" ==> \" => himpl", "content": "infixr:51 \" ==> \" => himpl" }, { "name": "notation:max \"emp\" => hempty", "content": "notation:max \"emp\" => hempty" }, { "name": "infixr:60 \" ~~> \" => hsingle", "content": "infixr:60 \" ~~> \" => hsingle" }, { "name": "infixr:55 \" βˆ— \" => HStar.hStar", "content": "infixr:55 \" βˆ— \" => HStar.hStar" }, { "name": "notation:max \"⌜\" P \"⌝\" => hpure P", "content": "notation:max \"⌜\" P \"⌝\" => hpure P" }, { "name": "infixr:55 \" -βˆ— \" => HWand.hWand", "content": "infixr:55 \" -βˆ— \" => HWand.hWand" }, { "name": "fun", "content": "notation \"funloc\" p \"↦\" H =>\n fun (r : val) ↦ hexists (fun p ↦ ⌜r = val_loc p⌝ βˆ— H)" } ]
[ { "name": "add_assoc", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "add_comm", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "List.concat_append", "module": "Init.Data.List.Lemmas" } ]
[ { "name": "hstar_comm_assoc", "content": "lemma hstar_comm_assoc (H1 H2 H3 : hProp) :\n H1 βˆ— H2 βˆ— H3 = H2 βˆ— H1 βˆ— H3" }, { "name": "himpl_frame_r", "content": "lemma himpl_frame_r H1 H2 H2' :\n H2 ==> H2' β†’\n (H1 βˆ— H2) ==> (H1 βˆ— H2')" }, { "name": "himpl_hforall_r", "content": "lemma himpl_hforall_r A (J : A β†’ hProp) H :\n (forall x, H ==> J x) β†’\n H ==> (hforall J)" } ]
[]
[ { "name": "hseg_cons", "content": "lemma hseg_cons v p j L :\n hseg (v :: L) p j = hcell v p j βˆ— hseg L p (j + 1)" }, { "name": "hseg_app", "content": "lemma hseg_app L1 L2 p j :\n hseg (L1 ++ L2) p j =\n hseg L1 p j βˆ— hseg L2 p (j + L1.length)" }, { "name": "list_cons_length", "content": "lemma list_cons_length (A : Type) (x : A) (L : List A) :\n (x :: L).length = 1 + L.length" }, { "name": "list_middle_inv", "content": "lemma list_middle_inv (A : Type) (n : Nat) (l : List A) :\n n < l.length β†’\n exists (x : A) (l1 l2 : List A),\n l = l1 ++ x :: l2 ∧ l1.length = n" }, { "name": "nth_app_r", "content": "lemma nth_app_r {A : Type} (_ : Inhabited A) n (l1 l2 : List A) :\n n β‰₯ l1.length β†’\n (l1 ++ l2)[n]! = l2[n - l1.length]!" }, { "name": "nth_middle", "content": "lemma nth_middle (A : Type) (IA : Inhabited A) (n : Nat)\n (l1 l2 : List A) (x : A) :\n n = l1.length β†’ (l1 ++ x :: l2)[n]! = x" }, { "name": "update_middle", "content": "lemma update_middle (A : Type) (_ : Inhabited A) (n : Nat)\n (l1 l2 : List A) (x v : A) :\n n = l1.length β†’ (l1 ++ x :: l2).set n v = (l1.concat v) ++ l2" } ]
import SPLean.Common.State import SPLean.Theories.XSimp import SPLean.Theories.XChange import SPLean.Common.Util import SPLean.Theories.SepLog import SPLean.Theories.WP1 import SPLean.Theories.Lang open val trm prim open Theories
lemma hseg_focus_relative (k : Nat) L p j (v : 0 <= k ∧ k < L.length): hseg L p j ==> hcell L[k]! p (j + k) βˆ— (hβˆ€ w, hcell w p (j + k) -βˆ— hseg (L.set k w) p j) :=
:= by move: v=> [] ? /list_middle_inv ![> ?] hlen move: (Eq.symm hlen) => /nth_middle hmid subst L ; srw (hmid _ w_2 w) hseg_app hseg_cons hlen -hstar_comm_assoc apply himpl_frame_r apply himpl_hforall_r => ? move: (Eq.symm hlen) => /(update_middle val _ k w_1 w_2 w) hset srw hset ?List.concat_append ?hseg_app ?hseg_cons ?hlen { sby xsimp } sdone
9
49
false
Framework
410
triple_ref
lemma triple_ref (v : val) : (forall (p : loc), triple (subst x p t2) (H βˆ— (p ~~> v)) (Q βˆ— βˆƒΚ° v, p ~~> v)) β†’ triple (trm_ref x (trm_val v) t2) H Q
splean
SPLean/Theories/SepLog.lean
[ "import Mathlib.Data.Multiset.Nodup", "import SPLean.Theories.XSimp", "import Mathlib.Data.Finset.Basic", "import Mathlib.Data.Finmap", "import SPLean.Common.State", "import SPLean.Theories.HProp", "import SPLean.Common.Util" ]
[ { "name": "String", "module": "Init.Prelude" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "Finmap", "module": "Mathlib.Data.Finmap" }, { "name": "BEq", "module": "Init.Prelude" }, { "name": "List", "module": "Init.Prelude" }, { "name": "Repr", "module": "Init.Data.Repr" }, { "name": "Vector", "module": "Init.Data.Vector.Basic" }, { "name": "bool", "module": "Init.Control.Basic" }, { "name": "ite", "module": "Init.Prelude" }, { "name": "Computation", "module": "Mathlib.Data.Seq.Computation" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "Max", "module": "Init.Prelude" }, { "name": "Max.max", "module": "Init.Prelude" }, { "name": "Finmap.singleton", "module": "Mathlib.Data.Finmap" }, { "name": "move", "module": "Ssreflect.Basic" }, { "name": "sby", "module": "Ssreflect.Done" }, { "name": "t", "module": "Ssreflect.IntroPats" }, { "name": "srw", "module": "Ssreflect.Rewrite" }, { "name": "elim", "module": "Ssreflect.Elim" } ]
[ { "name": "syntax \"if \" lang \"then \" lang \"end \" : lang", "content": "syntax \"if \" lang \"then \" lang \"end \" : lang\n\nsyntax \" := \" : bop\n\nsyntax \"let\" ident \" := \" lang \" in\" ppDedent(ppLine lang) : lang\n\nsyntax \"fun\" ident+ \" => \" lang : lang" }, { "name": "macro \"βˆƒΚ°\" xs:Lean.explicitBinders \", \" b:term : term => Lea", "content": "macro \"βˆƒΚ°\" xs:Lean.explicitBinders \", \" b:term : term => Lean.expandExplicitBinders ``hexists xs b\n\nsyntax \"⟨\" term \"⟩\" : lang\n\nsyntax \"⟨\" term \":\" term \"⟩\" : lang" }, { "name": "macro_rules", "content": "macro_rules\n | `([lang| ()]) => `(trm_val (val_unit))\n | `([lang| $n:num]) => `(trm_val (val_int $n))\n | `([lang| $t1 $t2]) => `(trm_app [lang| $t1] [lang| $t2])\n | `([lang| if $t1 then $t2 else $t3]) => `(trm_if [lang| $t1] [lang| $t2] [lang| $t3])\n | `([lang| if $t1 then $t2 end]) => `(trm_if [lang| $t1] [lang| $t2] (trm_val val_unit))\n | `([lang| let $x := $t1:lang in $t2:lang]) =>\n `(trm_let $(%x) [lang| $t1] [lang| $t2])\n | `([lang| ref $x := $t1:lang in $t2:lang]) =>\n `(trm_ref $(%x) [lang| $t1] [lang| $t2])\n | `([lang| alloc $t1:lang as $x in $t2:lang]) =>\n `(trm_alloc $(%x) [lang| $t1] [lang| $t2])\n | `([lang| $t1 ; $t2]) => `(trm_seq [lang| $t1] [lang| $t2])\n | `([lang| fun_ $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(trm_funs [ $xs,* ] [lang| $t])\n | `([lang| fun $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(val_funs [ $xs,* ] [lang| $t])\n | `([lang| fix_ $f $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(trm_fixs $(%f) [ $xs,* ] [lang| $t])\n | `([lang| fix $f $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(val_fixs $(%f) [ $xs,* ] [lang| $t])\n \n | `([lang| free $t]) => `(trm_val (val_prim val_free) [lang| $t])\n | `([lang| not $t]) => `(trm_val (val_prim val_not) [lang| $t])\n \n | `([lang| !$t]) => `(trm_val val_get [lang| $t])\n | `([lang| $t1 := $t2]) => `(trm_val val_set [lang| $t1] [lang| $t2])\n | `([lang| $t1 + $t2]) => `(trm_val val_add [lang| $t1] [lang| $t2])\n | `([lang| $t1 * $t2]) => `(trm_val val_mul [lang| $t1] [lang| $t2])\n | `([lang| $t1 - $t2]) => `(trm_val val_sub [lang| $t1] [lang| $t2])\n | `([lang| $t1 / $t2]) => `(trm_val val_div [lang| $t1] [lang| $t2])\n | `([lang| $t1 < $t2]) => `(trm_val val_lt [lang| $t1] [lang| $t2])\n | `([lang| $t1 > $t2]) => `(trm_val val_gt [lang| $t1] [lang| $t2])\n | `([lang| $t1 <= $t2]) => `(trm_val val_le [lang| $t1] [lang| $t2])\n | `([lang| $t1 >= $t2]) => `(trm_val val_ge [lang| $t1] [lang| $t2])\n | `([lang| -$t]) => `(trm_val val_opp [lang| $t])\n | `([lang| $t1 = $t2]) => `(trm_val val_eq [lang| $t1] [lang| $t2])\n | `([lang| $t1 != $t2]) => `(trm_val val_neq [lang| $t1] [lang| $t2])\n | `([lang| $t1 mod $t2]) => `(trm_val val_mod [lang| $t1] [lang| $t2])\n | `([lang| $t1 ++ $t2]) => `(trm_val val_ptr_add [lang| $t1] [lang| $t2])\n | `([lang| ($t)]) => `([lang| $t])\n | `([lang| ⟨$t : $tp⟩]) => `(trm_val (($t : $tp)))\n | `([lang| for $x in [$n1 : $n2] { $t } ]) =>\n `(trm_for $(%x) [lang| $n1] [lang| $n2] [lang| $t])\n | `([lang| while $c:lang { $t:lang } ]) =>\n `(trm_while [lang| $c] [lang| $t] )" }, { "name": "macro_rules", "content": "macro_rules\n | `([lang| len $p]) => `(trm_val val_array_length [lang| $p])\n | `([lang| $arr[$i] ]) => `(trm_val val_array_get [lang| $arr] [lang| $i])\n \n | `([lang| $arr[$i] := $v]) => `(trm_app val_array_set [lang| $arr] [lang| $i] [lang| $v])\n | `([lang| mkarr $n:lang $v:lang]) => `(trm_val val_array_make [lang| $n] [lang| $v])" }, { "name": "macro_rules | `($x βˆ— $y) => `(binop% HStar.hStar $x $y)", "content": "macro_rules | `($x βˆ— $y) => `(binop% HStar.hStar $x $y)\n\n inductive trm : Type where\n | trm_val : val -> trm\n | trm_var : var -> trm\n | trm_fun : var -> trm -> trm\n | trm_fix : var -> var -> trm -> trm\n | trm_app : trm -> trm -> trm\n | trm_seq : trm -> trm -> trm\n | trm_let : var -> trm -> trm -> trm\n | trm_if : trm -> trm -> trm -> trm\n | trm_for : var -> trm -> trm -> trm -> trm\n | trm_while : trm -> trm -> trm\n | trm_ref : var β†’ trm β†’ trm β†’ trm\n | trm_alloc : var β†’ trm β†’ trm β†’ trm\n\n inductive val : Type where\n | val_unit : val\n | val_bool : Bool β†’ val\n | val_int : Int β†’ val\n | val_real : ℝ β†’ val\n | val_loc : loc β†’ val\n | val_prim : prim β†’ val\n | val_fun : var -> trm -> val\n | val_fix : var -> var -> trm -> val\n | val_uninit : val\n | val_error : val" }, { "name": "prim", "content": "inductive prim where\n \n | val_get : prim\n | val_set : prim\n \n | val_neg : prim\n | val_opp : prim\n | val_eq : prim\n | val_add : prim\n | val_neq : prim\n | val_sub : prim\n | val_mul : prim\n | val_div : prim\n | val_mod : prim\n \n | val_le : prim\n | val_lt : prim\n | val_ge : prim\n | val_gt : prim\n | val_ptr_add : prim" }, { "name": "var", "content": "abbrev var := String" }, { "name": "loc", "content": "abbrev loc := Nat" }, { "name": "hProp", "content": "def hProp := heap -> Prop" }, { "name": "heap", "content": "abbrev heap := Heap.heap val" }, { "name": "Heap.heap", "content": "abbrev Heap.heap (val : Type) := Finmap (Ξ» _ : loc ↦ val)" }, { "name": "eval", "content": "inductive eval : state β†’ trm β†’ (val β†’ state β†’ Prop) -> Prop where\n | eval_val : forall s v Q,\n Q v s ->\n eval s (trm_val v) Q\n | eval_fun : forall s x t1 Q,\n Q (val_fun x t1) s ->\n eval s (trm_fun x t1) Q\n | eval_fix : forall s f x t1 Q,\n Q (val_fix f x t1) s ->\n eval s (trm_fix f x t1) Q\n | eval_app_arg1 : forall s1 t1 t2 Q1 Q,\n Β¬ trm_is_val t1 ->\n eval s1 t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> eval s2 (trm_app v1 t2) Q) ->\n eval s1 (trm_app t1 t2) Q\n | eval_app_arg2 : forall s1 (v1 : val) t2 Q1 Q,\n Β¬ trm_is_val t2 ->\n eval s1 t2 Q1 ->\n (forall v2 s2, Q1 v2 s2 -> eval s2 (trm_app v1 v2) Q) ->\n eval s1 (trm_app v1 t2) Q\n | eval_app_fun : forall s1 v1 (v2 :val) x t1 Q,\n v1 = val_fun x t1 ->\n eval s1 (subst x v2 t1) Q ->\n eval s1 (trm_app v1 v2) Q\n | eval_app_fix : forall s (v1 v2 : val) f x t1 Q,\n v1 = val_fix f x t1 ->\n eval s (subst x v2 (subst f v1 t1)) Q ->\n eval s (trm_app v1 v2) Q\n | eval_seq : forall Q1 s t1 t2 Q,\n eval s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> eval s2 t2 Q) ->\n eval s (trm_seq t1 t2) Q\n | eval_let : forall Q1 s x t1 t2 Q,\n eval s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> eval s2 (subst x v1 t2) Q) ->\n eval s (trm_let x t1 t2) Q\n | eval_if : forall s (b : Bool) t1 t2 Q,\n eval s (if b then t1 else t2) Q ->\n eval s (trm_if (val_bool b) t1 t2) Q\n | eval_unop : forall op s v1 P Q,\n evalunop op v1 P ->\n purepostin s P Q ->\n eval s (trm_app op v1) Q\n | eval_binop : forall op s (v1 v2 : val) P Q,\n evalbinop op v1 v2 P ->\n purepostin s P Q ->\n eval s (trm_app (trm_app op v1) v2) Q\n | eval_ref : forall s x t1 t2 (Q Q₁ : val β†’ state β†’ Prop),\n eval s t1 Q₁ β†’\n (βˆ€ v1 s1, Q₁ v1 s1 β†’ βˆ€ p βˆ‰ s1,\n eval (s1.insert p v1) (subst x p t2) fun v s ↦ Q v (s.erase p)) β†’\n eval s (trm_ref x t1 t2) Q\n | eval_get : forall s p Q,\n p ∈ s ->\n Q (read_state p s) s ->\n eval s (trm_app val_get (val_loc p)) Q\n | eval_set : forall s p v Q,\n v = trm_val v' ->\n p ∈ s ->\n Q val_unit (Finmap.insert p v' s) ->\n eval s (trm_app (trm_app val_set (val_loc p)) v) Q\n | eval_alloc_arg : forall s Q₁ Q,\n Β¬ trm_is_val t1 β†’\n eval s t1 Q₁ β†’\n (βˆ€ v' s', Q₁ v' s' β†’ eval s' (trm_alloc x v' t2) Q) β†’\n eval s (trm_alloc x t1 t2) Q\n | eval_alloc : forall (sa : state) (n : β„€) Q,\n n β‰₯ 0 β†’\n (βˆ€ (p : loc) (sb : state),\n sb = conseq (make_list n.natAbs val_uninit) p β†’\n p β‰  null β†’\n Finmap.Disjoint sa sb β†’\n eval (sb βˆͺ sa) (subst x p t2) fun v s ↦ Q v (s \\ sb)) β†’\n eval sa (trm_alloc x n t2) Q\n \n \n \n \n \n \n \n \n | eval_for (n₁ nβ‚‚ : Int) (Q : val -> state -> Prop) :\n eval s (if (n₁ < nβ‚‚) then\n (trm_seq (subst x n₁ t₁) (trm_for x (val_int (n₁ + 1)) nβ‚‚ t₁))\n else val_unit) Q ->\n eval s (trm_for x n₁ nβ‚‚ t₁) Q\n | eval_while (t₁ tβ‚‚ : trm) (Q : val -> state -> Prop) :\n eval s t₁ Q₁ ->\n (βˆ€ s v, Q₁ v s -> eval s (trm_if v (trm_seq tβ‚‚ (trm_while t₁ tβ‚‚)) val_unit) Q) ->\n eval s (trm_while t₁ tβ‚‚) Q" }, { "name": "HStar", "content": "class HStar (Ξ± : Type u) (Ξ² : Type v) (Ξ³ : outParam (Type w)) where\n \n hStar : Ξ± β†’ Ξ² β†’ Ξ³" }, { "name": "hsingle", "content": "def hsingle (p : loc) (v : val) : hProp :=\n fun h => (h = Finmap.singleton p v)" }, { "name": "evalExact", "content": "inductive evalExact : state β†’ trm β†’ (val β†’ state β†’ Prop) -> Prop where\n | val : forall s v,\n evalExact s (trm_val v) (fun v' s' ↦ v' = v ∧ s' = s)\n | fun : forall s x t1,\n evalExact s (trm_fun x t1) (fun v' s' ↦ v' = val_fun x t1 ∧ s' = s)\n | fix : forall s f x t1,\n evalExact s (trm_fix f x t1) (fun v' s' ↦ v' = val_fix f x t1 ∧ s' = s)\n | app_arg1 : forall s1 t1 t2 Q1 Q,\n Β¬ trm_is_val t1 ->\n evalExact s1 t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 (trm_app v1 t2) Q) ->\n evalExact s1 (trm_app t1 t2) Q\n | app_arg2 : forall s1 (v1 : val) t2 Q1 Q,\n Β¬ trm_is_val t2 ->\n evalExact s1 t2 Q1 ->\n (forall v2 s2, Q1 v2 s2 -> evalExact s2 (trm_app v1 v2) Q) ->\n evalExact s1 (trm_app v1 t2) Q\n | app_fun : forall s1 v1 (v2 :val) x t1 Q,\n v1 = val_fun x t1 ->\n evalExact s1 (subst x v2 t1) Q ->\n evalExact s1 (trm_app v1 v2) Q\n | app_fix : forall s (v1 v2 : val) f x t1 Q,\n v1 = val_fix f x t1 ->\n evalExact s (subst x v2 (subst f v1 t1)) Q ->\n evalExact s (trm_app v1 v2) Q\n | seq : forall Q1 s t1 t2 Q,\n evalExact s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 t2 Q) ->\n evalExact s (trm_seq t1 t2) Q\n | let : forall Q1 s x t1 t2 Q,\n evalExact s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 (subst x v1 t2) Q) ->\n evalExact s (trm_let x t1 t2) Q\n | if : forall s (b : Bool) t1 t2 Q,\n evalExact s (if b then t1 else t2) Q ->\n evalExact s (trm_if (val_bool b) t1 t2) Q\n | unop : forall op s v1 P,\n evalunop op v1 P ->\n evalExact s (trm_app op v1) (purepost s P)\n | binop : forall op s (v1 v2 : val) P,\n evalbinop op v1 v2 P ->\n evalExact s (trm_app (trm_app op v1) v2) (purepost s P)\n | ref : forall s x t1 t2 Q Q₁,\n evalExact s t1 Q₁ β†’\n (βˆ€ v1 s1, Q₁ v1 s1 β†’ βˆ€ p βˆ‰ s1,\n evalExact (s1.insert p v1) (subst x p t2) fun v s ↦ Q v (s.erase p)) β†’\n evalExact s (trm_ref x t1 t2) Q\n | get : forall s p,\n p ∈ s ->\n evalExact s (trm_app val_get (val_loc p))\n (fun v' s' ↦ v' = read_state p s ∧ s' = s)\n | set : forall s p v,\n v = trm_val v' ->\n p ∈ s ->\n evalExact s (trm_app (trm_app val_set (val_loc p)) v)\n (fun v'' s' ↦ v'' = val_unit ∧ s' = s.insert p v')\n | alloc_arg : forall s Q₁ Q,\n Β¬ trm_is_val t1 β†’\n evalExact s t1 Q₁ β†’\n (βˆ€ v' s', Q₁ v' s' β†’ evalExact s' (trm_alloc x v' t2) Q) β†’\n evalExact s (trm_alloc x t1 t2) Q\n | alloc : forall (sa : state) (n : β„€) Q,\n n β‰₯ 0 β†’\n (βˆ€ (p : loc) (sb : state),\n sb = conseq (make_list n.natAbs val_uninit) p β†’\n p β‰  null β†’\n Finmap.Disjoint sa sb β†’\n evalExact (sb βˆͺ sa) (subst x p t2) fun v s ↦ Q v (s \\ sb)) β†’\n evalExact sa (trm_alloc x n t2) Q\n \n \n \n \n \n \n | for (n₁ nβ‚‚ : Int) (Q : val -> state -> Prop) :\n evalExact s (if (n₁ < nβ‚‚) then\n (trm_seq (subst x n₁ t₁) (trm_for x (val_int (n₁ + 1)) nβ‚‚ t₁))\n else val_unit) Q ->\n evalExact s (trm_for x n₁ nβ‚‚ t₁) Q\n | while (t₁ tβ‚‚ : trm) (Q Q₁ : val -> state -> Prop) :\n evalExact s t₁ Q₁ ->\n (βˆ€ s v, Q₁ v s -> evalExact s (trm_if v (trm_seq tβ‚‚ (trm_while t₁ tβ‚‚)) val_unit) Q) ->\n evalExact s (trm_while t₁ tβ‚‚) Q" }, { "name": "subst", "content": "def subst (y : var) (v' : val) (t : trm) : trm :=\n \n let if_y_eq x t1 t2 := if x = y then t1 else t2\n match t with\n | trm_val v => trm_val v\n | trm_var x => if_y_eq x (trm_val v') t\n | trm_fun x t1 => trm_fun x (if_y_eq x t1 (subst y v' t1))\n | trm_fix f x t1 => trm_fix f x (if_y_eq f t1 (if_y_eq x t1 (subst y v' t1)))\n | trm_app t1 t2 => trm_app (subst y v' t1) (subst y v' t2)\n | trm_seq t1 t2 => trm_seq (subst y v' t1) (subst y v' t2)\n | trm_let x t1 t2 => trm_let x (subst y v' t1) (if_y_eq x t2 (subst y v' t2))\n | trm_if t0 t1 t2 => trm_if (subst y v' t0) (subst y v' t1) (subst y v' t2)\n | trm_for x t1 t2 t3 => trm_for x (subst y v' t1) (subst y v' t2) (if_y_eq x t3 (subst y v' t3))\n | trm_while t1 t2 => trm_while (subst y v' t1) (subst y v' t2)\n | trm_ref x t1 t2 => trm_ref x (subst y v' t1) (if_y_eq x t2 (subst y v' t2))\n | trm_alloc x t1 t2 => trm_alloc x (subst y v' t1) (if_y_eq x t2 (subst y v' t2))" }, { "name": "qimpl", "content": "def qimpl {A} (Q1 Q2 : A β†’ hProp) : Prop :=\n forall (v:A), Q1 v ==> Q2 v" }, { "name": "himpl", "content": "abbrev himpl (H1 H2 : hProp) : Prop :=\n forall h, H1 h -> H2 h" }, { "name": "purepostin", "content": "def purepostin (s : state) (P : val β†’ Prop) (Q : val β†’ state β†’ Prop) : Prop :=\n \n forall v, P v β†’ Q v s" }, { "name": "state", "content": "abbrev state := Finmap (Ξ» _ : loc ↦ val)" }, { "name": "hexists", "content": "def hexists {A} (J : A β†’ hProp) : hProp :=\n fun h => exists x, J x h" }, { "name": "infixr:51 \" ==> \" => himpl", "content": "infixr:51 \" ==> \" => himpl" }, { "name": "infixr:51 \" ===> \" => qimpl", "content": "infixr:51 \" ===> \" => qimpl" }, { "name": "infixr:60 \" ~~> \" => hsingle", "content": "infixr:60 \" ~~> \" => hsingle" }, { "name": "infixr:55 \" βˆ— \" => HStar.hStar", "content": "infixr:55 \" βˆ— \" => HStar.hStar" } ]
[ { "name": "...", "module": "" } ]
[ { "name": "disjoint_single", "content": "lemma disjoint_single (h : state) :\n p βˆ‰ h β†’\n h.Disjoint (Finmap.singleton p v)" }, { "name": "hsingl_inv", "content": "lemma hsingl_inv p v h :\n (p ~~> v) h β†’\n h = Finmap.singleton p v" }, { "name": "union_singleton_eq_erase", "content": "lemma union_singleton_eq_erase (h h' : state) :\n h.Disjoint (Finmap.singleton p v) β†’\n h' = h βˆͺ Finmap.singleton p v β†’\n h = h'.erase p" }, { "name": "hexists_inv", "content": "lemma hexists_inv A (J : A β†’ hProp) h :\n (hexists J) h β†’ exists x, J x h" }, { "name": "hsingle_intro", "content": "lemma hsingle_intro p v :\n (p ~~> v) (Finmap.singleton p v)" }, { "name": "insert_eq_union_single", "content": "lemma insert_eq_union_single (h : state) :\n p βˆ‰ h β†’\n h.insert p v = h βˆͺ (Finmap.singleton p v)" } ]
[ { "name": "triple", "content": "abbrev triple (t : trm) (H : hProp) (Q : val β†’ hProp) : Prop :=\n forall s, H s β†’ eval s t Q" } ]
[ { "name": "eval_conseq", "content": "lemma eval_conseq s t Q1 Q2 :\n eval s t Q1 β†’\n Q1 ===> Q2 β†’\n eval s t Q2" }, { "name": "triple_conseq", "content": "lemma triple_conseq t H' Q' H Q :\n triple t H' Q' β†’\n H ==> H'β†’\n Q' ===> Q β†’\n triple t H Q" } ]
import Mathlib.Data.Finmap import Mathlib.Data.Finset.Basic import Mathlib.Data.Multiset.Nodup import SPLean.Common.State import SPLean.Common.Util import SPLean.Theories.HProp import SPLean.Theories.XSimp open trm val prim abbrev triple (t : trm) (H : hProp) (Q : val β†’ hProp) : Prop := forall s, H s β†’ eval s t Q notation "funloc" p "↦" H => fun (r : val) ↦ hexists (fun p ↦ ⌜r = val_loc p⌝ βˆ— H) section evalProp end evalProp
lemma triple_ref (v : val) : (forall (p : loc), triple (subst x p t2) (H βˆ— (p ~~> v)) (Q βˆ— βˆƒΚ° v, p ~~> v)) β†’ triple (trm_ref x (trm_val v) t2) H Q :=
:= by move=> htriple h ? apply eval.eval_ref { sby apply (eval.eval_val h v (fun v' h' ↦ v' = v ∧ h' = h)) } move=> > [->->] > ? move: (htriple p)=> /triple_conseq {}htriple have eqn:(triple (subst x p t2) (H βˆ— p ~~> v) fun v s ↦ Q v (s.erase p)) := by apply htriple=> // move=> > h /= ![>] ? /hexists_inv [v'] /hsingl_inv -> sby move=> /union_singleton_eq_erase /[apply] <- move=> {htriple} apply eqn exists h, Finmap.singleton p v move=> ⟨//|⟩ ⟨|⟩ apply hsingle_intro=> ⟨|⟩ apply disjoint_single=>// sby apply insert_eq_union_single=> //
5
48
false
Framework
411
triple_alloc
lemma triple_alloc (n : Int) : n β‰₯ 0 β†’ (βˆ€ (p : loc), triple (subst x p t) (H βˆ— ⌜p β‰  null⌝ βˆ— hrange (make_list n.natAbs val_uninit) p) (Q βˆ— ⌜p β‰  null⌝ βˆ— βˆƒΚ° L, ⌜L.length = n⌝ βˆ— hrange L p) ) β†’ triple (trm_alloc x n t) H Q
splean
SPLean/Theories/SepLog.lean
[ "import SPLean.Theories.Lang", "import Mathlib.Data.Multiset.Nodup", "import SPLean.Theories.XSimp", "import Mathlib.Data.Finset.Basic", "import Mathlib.Data.Finmap", "import SPLean.Common.State", "import SPLean.Theories.HProp", "import SPLean.Common.Util" ]
[ { "name": "String", "module": "Init.Prelude" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "Finmap", "module": "Mathlib.Data.Finmap" }, { "name": "Finmap.singleton", "module": "Mathlib.Data.Finmap" }, { "name": "List", "module": "Init.Prelude" }, { "name": "BEq", "module": "Init.Prelude" }, { "name": "Repr", "module": "Init.Data.Repr" }, { "name": "Vector", "module": "Init.Data.Vector.Basic" }, { "name": "bool", "module": "Init.Control.Basic" }, { "name": "ite", "module": "Init.Prelude" }, { "name": "Computation", "module": "Mathlib.Data.Seq.Computation" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "Max", "module": "Init.Prelude" }, { "name": "Max.max", "module": "Init.Prelude" }, { "name": "L", "module": "Archive.Hairer" }, { "name": "t", "module": "Ssreflect.IntroPats" }, { "name": "Finmap.Disjoint", "module": "Mathlib.Data.Finmap" }, { "name": "move", "module": "Ssreflect.Basic" }, { "name": "sby", "module": "Ssreflect.Done" }, { "name": "sdone", "module": "Ssreflect.Done" }, { "name": "srw", "module": "Ssreflect.Rewrite" }, { "name": "Finset", "module": "Mathlib.Data.Finset.Defs" }, { "name": "elim", "module": "Ssreflect.Elim" } ]
[ { "name": "notation:max \"emp\" => hempty", "content": "notation:max \"emp\" => hempty\n\nsyntax \"if \" lang \"then \" lang \"end \" : lang\n\nsyntax \" := \" : bop\n\nsyntax \"let\" ident \" := \" lang \" in\" ppDedent(ppLine lang) : lang\n\nsyntax \"fun\" ident+ \" => \" lang : lang\n\nsyntax \"⟨\" term \"⟩\" : lang\n\nsyntax \"⟨\" term \":\" term \"⟩\" : lang" }, { "name": "notation:max \"⌜\" P \"⌝\" => hpure P", "content": "notation:max \"⌜\" P \"⌝\" => hpure P" }, { "name": "macro \"βˆƒΚ°\" xs:Lean.explicitBinders \", \" b:term : term => Lea", "content": "macro \"βˆƒΚ°\" xs:Lean.explicitBinders \", \" b:term : term => Lean.expandExplicitBinders ``hexists xs b" }, { "name": "macro_rules", "content": "macro_rules\n | `([lang| ()]) => `(trm_val (val_unit))\n | `([lang| $n:num]) => `(trm_val (val_int $n))\n | `([lang| $t1 $t2]) => `(trm_app [lang| $t1] [lang| $t2])\n | `([lang| if $t1 then $t2 else $t3]) => `(trm_if [lang| $t1] [lang| $t2] [lang| $t3])\n | `([lang| if $t1 then $t2 end]) => `(trm_if [lang| $t1] [lang| $t2] (trm_val val_unit))\n | `([lang| let $x := $t1:lang in $t2:lang]) =>\n `(trm_let $(%x) [lang| $t1] [lang| $t2])\n | `([lang| ref $x := $t1:lang in $t2:lang]) =>\n `(trm_ref $(%x) [lang| $t1] [lang| $t2])\n | `([lang| alloc $t1:lang as $x in $t2:lang]) =>\n `(trm_alloc $(%x) [lang| $t1] [lang| $t2])\n | `([lang| $t1 ; $t2]) => `(trm_seq [lang| $t1] [lang| $t2])\n | `([lang| fun_ $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(trm_funs [ $xs,* ] [lang| $t])\n | `([lang| fun $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(val_funs [ $xs,* ] [lang| $t])\n | `([lang| fix_ $f $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(trm_fixs $(%f) [ $xs,* ] [lang| $t])\n | `([lang| fix $f $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(val_fixs $(%f) [ $xs,* ] [lang| $t])\n \n | `([lang| free $t]) => `(trm_val (val_prim val_free) [lang| $t])\n | `([lang| not $t]) => `(trm_val (val_prim val_not) [lang| $t])\n \n | `([lang| !$t]) => `(trm_val val_get [lang| $t])\n | `([lang| $t1 := $t2]) => `(trm_val val_set [lang| $t1] [lang| $t2])\n | `([lang| $t1 + $t2]) => `(trm_val val_add [lang| $t1] [lang| $t2])\n | `([lang| $t1 * $t2]) => `(trm_val val_mul [lang| $t1] [lang| $t2])\n | `([lang| $t1 - $t2]) => `(trm_val val_sub [lang| $t1] [lang| $t2])\n | `([lang| $t1 / $t2]) => `(trm_val val_div [lang| $t1] [lang| $t2])\n | `([lang| $t1 < $t2]) => `(trm_val val_lt [lang| $t1] [lang| $t2])\n | `([lang| $t1 > $t2]) => `(trm_val val_gt [lang| $t1] [lang| $t2])\n | `([lang| $t1 <= $t2]) => `(trm_val val_le [lang| $t1] [lang| $t2])\n | `([lang| $t1 >= $t2]) => `(trm_val val_ge [lang| $t1] [lang| $t2])\n | `([lang| -$t]) => `(trm_val val_opp [lang| $t])\n | `([lang| $t1 = $t2]) => `(trm_val val_eq [lang| $t1] [lang| $t2])\n | `([lang| $t1 != $t2]) => `(trm_val val_neq [lang| $t1] [lang| $t2])\n | `([lang| $t1 mod $t2]) => `(trm_val val_mod [lang| $t1] [lang| $t2])\n | `([lang| $t1 ++ $t2]) => `(trm_val val_ptr_add [lang| $t1] [lang| $t2])\n | `([lang| ($t)]) => `([lang| $t])\n | `([lang| ⟨$t : $tp⟩]) => `(trm_val (($t : $tp)))\n | `([lang| for $x in [$n1 : $n2] { $t } ]) =>\n `(trm_for $(%x) [lang| $n1] [lang| $n2] [lang| $t])\n | `([lang| while $c:lang { $t:lang } ]) =>\n `(trm_while [lang| $c] [lang| $t] )" }, { "name": "macro_rules", "content": "macro_rules\n | `([lang| len $p]) => `(trm_val val_array_length [lang| $p])\n | `([lang| $arr[$i] ]) => `(trm_val val_array_get [lang| $arr] [lang| $i])\n \n | `([lang| $arr[$i] := $v]) => `(trm_app val_array_set [lang| $arr] [lang| $i] [lang| $v])\n | `([lang| mkarr $n:lang $v:lang]) => `(trm_val val_array_make [lang| $n] [lang| $v])" }, { "name": "macro_rules | `($x βˆ— $y) => `(binop% HStar.hStar $x $y)", "content": "macro_rules | `($x βˆ— $y) => `(binop% HStar.hStar $x $y)" }, { "name": "HStar", "content": "class HStar (Ξ± : Type u) (Ξ² : Type v) (Ξ³ : outParam (Type w)) where\n \n hStar : Ξ± β†’ Ξ² β†’ Ξ³" }, { "name": "hsingle", "content": "def hsingle (p : loc) (v : val) : hProp :=\n fun h => (h = Finmap.singleton p v)" }, { "name": "hProp", "content": "def hProp := heap -> Prop" }, { "name": "heap", "content": "abbrev heap := Heap.heap val\n\n inductive val : Type where\n | val_unit : val\n | val_bool : Bool β†’ val\n | val_int : Int β†’ val\n | val_real : ℝ β†’ val\n | val_loc : loc β†’ val\n | val_prim : prim β†’ val\n | val_fun : var -> trm -> val\n | val_fix : var -> var -> trm -> val\n | val_uninit : val\n | val_error : val" }, { "name": "prim", "content": "inductive prim where\n \n | val_get : prim\n | val_set : prim\n \n | val_neg : prim\n | val_opp : prim\n | val_eq : prim\n | val_add : prim\n | val_neq : prim\n | val_sub : prim\n | val_mul : prim\n | val_div : prim\n | val_mod : prim\n \n | val_le : prim\n | val_lt : prim\n | val_ge : prim\n | val_gt : prim\n | val_ptr_add : prim\n\n inductive trm : Type where\n | trm_val : val -> trm\n | trm_var : var -> trm\n | trm_fun : var -> trm -> trm\n | trm_fix : var -> var -> trm -> trm\n | trm_app : trm -> trm -> trm\n | trm_seq : trm -> trm -> trm\n | trm_let : var -> trm -> trm -> trm\n | trm_if : trm -> trm -> trm -> trm\n | trm_for : var -> trm -> trm -> trm -> trm\n | trm_while : trm -> trm -> trm\n | trm_ref : var β†’ trm β†’ trm β†’ trm\n | trm_alloc : var β†’ trm β†’ trm β†’ trm" }, { "name": "var", "content": "abbrev var := String" }, { "name": "loc", "content": "abbrev loc := Nat" }, { "name": "Heap.heap", "content": "abbrev Heap.heap (val : Type) := Finmap (Ξ» _ : loc ↦ val)" }, { "name": "evalExact", "content": "inductive evalExact : state β†’ trm β†’ (val β†’ state β†’ Prop) -> Prop where\n | val : forall s v,\n evalExact s (trm_val v) (fun v' s' ↦ v' = v ∧ s' = s)\n | fun : forall s x t1,\n evalExact s (trm_fun x t1) (fun v' s' ↦ v' = val_fun x t1 ∧ s' = s)\n | fix : forall s f x t1,\n evalExact s (trm_fix f x t1) (fun v' s' ↦ v' = val_fix f x t1 ∧ s' = s)\n | app_arg1 : forall s1 t1 t2 Q1 Q,\n Β¬ trm_is_val t1 ->\n evalExact s1 t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 (trm_app v1 t2) Q) ->\n evalExact s1 (trm_app t1 t2) Q\n | app_arg2 : forall s1 (v1 : val) t2 Q1 Q,\n Β¬ trm_is_val t2 ->\n evalExact s1 t2 Q1 ->\n (forall v2 s2, Q1 v2 s2 -> evalExact s2 (trm_app v1 v2) Q) ->\n evalExact s1 (trm_app v1 t2) Q\n | app_fun : forall s1 v1 (v2 :val) x t1 Q,\n v1 = val_fun x t1 ->\n evalExact s1 (subst x v2 t1) Q ->\n evalExact s1 (trm_app v1 v2) Q\n | app_fix : forall s (v1 v2 : val) f x t1 Q,\n v1 = val_fix f x t1 ->\n evalExact s (subst x v2 (subst f v1 t1)) Q ->\n evalExact s (trm_app v1 v2) Q\n | seq : forall Q1 s t1 t2 Q,\n evalExact s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 t2 Q) ->\n evalExact s (trm_seq t1 t2) Q\n | let : forall Q1 s x t1 t2 Q,\n evalExact s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 (subst x v1 t2) Q) ->\n evalExact s (trm_let x t1 t2) Q\n | if : forall s (b : Bool) t1 t2 Q,\n evalExact s (if b then t1 else t2) Q ->\n evalExact s (trm_if (val_bool b) t1 t2) Q\n | unop : forall op s v1 P,\n evalunop op v1 P ->\n evalExact s (trm_app op v1) (purepost s P)\n | binop : forall op s (v1 v2 : val) P,\n evalbinop op v1 v2 P ->\n evalExact s (trm_app (trm_app op v1) v2) (purepost s P)\n | ref : forall s x t1 t2 Q Q₁,\n evalExact s t1 Q₁ β†’\n (βˆ€ v1 s1, Q₁ v1 s1 β†’ βˆ€ p βˆ‰ s1,\n evalExact (s1.insert p v1) (subst x p t2) fun v s ↦ Q v (s.erase p)) β†’\n evalExact s (trm_ref x t1 t2) Q\n | get : forall s p,\n p ∈ s ->\n evalExact s (trm_app val_get (val_loc p))\n (fun v' s' ↦ v' = read_state p s ∧ s' = s)\n | set : forall s p v,\n v = trm_val v' ->\n p ∈ s ->\n evalExact s (trm_app (trm_app val_set (val_loc p)) v)\n (fun v'' s' ↦ v'' = val_unit ∧ s' = s.insert p v')\n | alloc_arg : forall s Q₁ Q,\n Β¬ trm_is_val t1 β†’\n evalExact s t1 Q₁ β†’\n (βˆ€ v' s', Q₁ v' s' β†’ evalExact s' (trm_alloc x v' t2) Q) β†’\n evalExact s (trm_alloc x t1 t2) Q\n | alloc : forall (sa : state) (n : β„€) Q,\n n β‰₯ 0 β†’\n (βˆ€ (p : loc) (sb : state),\n sb = conseq (make_list n.natAbs val_uninit) p β†’\n p β‰  null β†’\n Finmap.Disjoint sa sb β†’\n evalExact (sb βˆͺ sa) (subst x p t2) fun v s ↦ Q v (s \\ sb)) β†’\n evalExact sa (trm_alloc x n t2) Q\n \n \n \n \n \n \n | for (n₁ nβ‚‚ : Int) (Q : val -> state -> Prop) :\n evalExact s (if (n₁ < nβ‚‚) then\n (trm_seq (subst x n₁ t₁) (trm_for x (val_int (n₁ + 1)) nβ‚‚ t₁))\n else val_unit) Q ->\n evalExact s (trm_for x n₁ nβ‚‚ t₁) Q\n | while (t₁ tβ‚‚ : trm) (Q Q₁ : val -> state -> Prop) :\n evalExact s t₁ Q₁ ->\n (βˆ€ s v, Q₁ v s -> evalExact s (trm_if v (trm_seq tβ‚‚ (trm_while t₁ tβ‚‚)) val_unit) Q) ->\n evalExact s (trm_while t₁ tβ‚‚) Q" }, { "name": "hempty", "content": "def hempty : hProp :=\n fun h => (h = βˆ…)" }, { "name": "eval", "content": "inductive eval : state β†’ trm β†’ (val β†’ state β†’ Prop) -> Prop where\n | eval_val : forall s v Q,\n Q v s ->\n eval s (trm_val v) Q\n | eval_fun : forall s x t1 Q,\n Q (val_fun x t1) s ->\n eval s (trm_fun x t1) Q\n | eval_fix : forall s f x t1 Q,\n Q (val_fix f x t1) s ->\n eval s (trm_fix f x t1) Q\n | eval_app_arg1 : forall s1 t1 t2 Q1 Q,\n Β¬ trm_is_val t1 ->\n eval s1 t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> eval s2 (trm_app v1 t2) Q) ->\n eval s1 (trm_app t1 t2) Q\n | eval_app_arg2 : forall s1 (v1 : val) t2 Q1 Q,\n Β¬ trm_is_val t2 ->\n eval s1 t2 Q1 ->\n (forall v2 s2, Q1 v2 s2 -> eval s2 (trm_app v1 v2) Q) ->\n eval s1 (trm_app v1 t2) Q\n | eval_app_fun : forall s1 v1 (v2 :val) x t1 Q,\n v1 = val_fun x t1 ->\n eval s1 (subst x v2 t1) Q ->\n eval s1 (trm_app v1 v2) Q\n | eval_app_fix : forall s (v1 v2 : val) f x t1 Q,\n v1 = val_fix f x t1 ->\n eval s (subst x v2 (subst f v1 t1)) Q ->\n eval s (trm_app v1 v2) Q\n | eval_seq : forall Q1 s t1 t2 Q,\n eval s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> eval s2 t2 Q) ->\n eval s (trm_seq t1 t2) Q\n | eval_let : forall Q1 s x t1 t2 Q,\n eval s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> eval s2 (subst x v1 t2) Q) ->\n eval s (trm_let x t1 t2) Q\n | eval_if : forall s (b : Bool) t1 t2 Q,\n eval s (if b then t1 else t2) Q ->\n eval s (trm_if (val_bool b) t1 t2) Q\n | eval_unop : forall op s v1 P Q,\n evalunop op v1 P ->\n purepostin s P Q ->\n eval s (trm_app op v1) Q\n | eval_binop : forall op s (v1 v2 : val) P Q,\n evalbinop op v1 v2 P ->\n purepostin s P Q ->\n eval s (trm_app (trm_app op v1) v2) Q\n | eval_ref : forall s x t1 t2 (Q Q₁ : val β†’ state β†’ Prop),\n eval s t1 Q₁ β†’\n (βˆ€ v1 s1, Q₁ v1 s1 β†’ βˆ€ p βˆ‰ s1,\n eval (s1.insert p v1) (subst x p t2) fun v s ↦ Q v (s.erase p)) β†’\n eval s (trm_ref x t1 t2) Q\n | eval_get : forall s p Q,\n p ∈ s ->\n Q (read_state p s) s ->\n eval s (trm_app val_get (val_loc p)) Q\n | eval_set : forall s p v Q,\n v = trm_val v' ->\n p ∈ s ->\n Q val_unit (Finmap.insert p v' s) ->\n eval s (trm_app (trm_app val_set (val_loc p)) v) Q\n | eval_alloc_arg : forall s Q₁ Q,\n Β¬ trm_is_val t1 β†’\n eval s t1 Q₁ β†’\n (βˆ€ v' s', Q₁ v' s' β†’ eval s' (trm_alloc x v' t2) Q) β†’\n eval s (trm_alloc x t1 t2) Q\n | eval_alloc : forall (sa : state) (n : β„€) Q,\n n β‰₯ 0 β†’\n (βˆ€ (p : loc) (sb : state),\n sb = conseq (make_list n.natAbs val_uninit) p β†’\n p β‰  null β†’\n Finmap.Disjoint sa sb β†’\n eval (sb βˆͺ sa) (subst x p t2) fun v s ↦ Q v (s \\ sb)) β†’\n eval sa (trm_alloc x n t2) Q\n \n \n \n \n \n \n \n \n | eval_for (n₁ nβ‚‚ : Int) (Q : val -> state -> Prop) :\n eval s (if (n₁ < nβ‚‚) then\n (trm_seq (subst x n₁ t₁) (trm_for x (val_int (n₁ + 1)) nβ‚‚ t₁))\n else val_unit) Q ->\n eval s (trm_for x n₁ nβ‚‚ t₁) Q\n | eval_while (t₁ tβ‚‚ : trm) (Q : val -> state -> Prop) :\n eval s t₁ Q₁ ->\n (βˆ€ s v, Q₁ v s -> eval s (trm_if v (trm_seq tβ‚‚ (trm_while t₁ tβ‚‚)) val_unit) Q) ->\n eval s (trm_while t₁ tβ‚‚) Q" }, { "name": "make_list", "content": "def make_list {A} (n : Nat) (v : A) : List A :=\n match n with\n | 0 => []\n | n' + 1 => v :: make_list n' v" }, { "name": "subst", "content": "def subst (y : var) (v' : val) (t : trm) : trm :=\n \n let if_y_eq x t1 t2 := if x = y then t1 else t2\n match t with\n | trm_val v => trm_val v\n | trm_var x => if_y_eq x (trm_val v') t\n | trm_fun x t1 => trm_fun x (if_y_eq x t1 (subst y v' t1))\n | trm_fix f x t1 => trm_fix f x (if_y_eq f t1 (if_y_eq x t1 (subst y v' t1)))\n | trm_app t1 t2 => trm_app (subst y v' t1) (subst y v' t2)\n | trm_seq t1 t2 => trm_seq (subst y v' t1) (subst y v' t2)\n | trm_let x t1 t2 => trm_let x (subst y v' t1) (if_y_eq x t2 (subst y v' t2))\n | trm_if t0 t1 t2 => trm_if (subst y v' t0) (subst y v' t1) (subst y v' t2)\n | trm_for x t1 t2 t3 => trm_for x (subst y v' t1) (subst y v' t2) (if_y_eq x t3 (subst y v' t3))\n | trm_while t1 t2 => trm_while (subst y v' t1) (subst y v' t2)\n | trm_ref x t1 t2 => trm_ref x (subst y v' t1) (if_y_eq x t2 (subst y v' t2))\n | trm_alloc x t1 t2 => trm_alloc x (subst y v' t1) (if_y_eq x t2 (subst y v' t2))" }, { "name": "null", "content": "def null : loc := 0" }, { "name": "hpure", "content": "def hpure (P : Prop) : hProp :=\n hexists (fun (_ : P) => emp)" }, { "name": "hexists", "content": "def hexists {A} (J : A β†’ hProp) : hProp :=\n fun h => exists x, J x h" }, { "name": "state", "content": "abbrev state := Finmap (Ξ» _ : loc ↦ val)" }, { "name": "conseq", "content": "def conseq {B : Type} (vs : List B) (l : Nat) : Finmap (fun _ : Nat ↦ B) :=\n match vs with\n | [] => βˆ…\n | v :: vs' => (Finmap.singleton l v) βˆͺ (conseq vs' (l + 1))" }, { "name": "qimpl", "content": "def qimpl {A} (Q1 Q2 : A β†’ hProp) : Prop :=\n forall (v:A), Q1 v ==> Q2 v" }, { "name": "himpl", "content": "abbrev himpl (H1 H2 : hProp) : Prop :=\n forall h, H1 h -> H2 h" }, { "name": "purepostin", "content": "def purepostin (s : state) (P : val β†’ Prop) (Q : val β†’ state β†’ Prop) : Prop :=\n \n forall v, P v β†’ Q v s" }, { "name": "infixr:51 \" ==> \" => himpl", "content": "infixr:51 \" ==> \" => himpl" }, { "name": "infixr:51 \" ===> \" => qimpl", "content": "infixr:51 \" ===> \" => qimpl" }, { "name": "notation:max \"emp\" => hempty", "content": "notation:max \"emp\" => hempty" }, { "name": "infixr:60 \" ~~> \" => hsingle", "content": "infixr:60 \" ~~> \" => hsingle" }, { "name": "infixr:55 \" βˆ— \" => HStar.hStar", "content": "infixr:55 \" βˆ— \" => HStar.hStar" }, { "name": "notation:max \"⌜\" P \"⌝\" => hpure P", "content": "notation:max \"⌜\" P \"⌝\" => hpure P" } ]
[ { "name": "Finmap.mem_keys", "module": "Mathlib.Data.Finmap" }, { "name": "Finset.ext_iff", "module": "Mathlib.Data.Finset.Defs" }, { "name": "Finmap.Disjoint.symm_iff", "module": "Mathlib.Data.Finmap" }, { "name": "Finmap.union_comm_of_disjoint", "module": "Mathlib.Data.Finmap" } ]
[ { "name": "hempty_inv", "content": "lemma hempty_inv h :\n emp h β†’ h = βˆ…" }, { "name": "hsingl_inv", "content": "lemma hsingl_inv p v h :\n (p ~~> v) h β†’\n h = Finmap.singleton p v" }, { "name": "hstar_intro", "content": "lemma hstar_intro (H1 H2 : hProp) h1 h2 :\n H1 h1 β†’\n H2 h2 β†’\n Finmap.Disjoint h1 h2 β†’\n (H1 βˆ— H2) (h1 βˆͺ h2)" }, { "name": "disjoint_single_conseq", "content": "lemma disjoint_single_conseq B l l' L (v : B) :\n (l < l') ∨ (l β‰₯ l' + L.length) β†’\n Finmap.Disjoint (Finmap.singleton l v) (conseq L l')" }, { "name": "conseq_cons", "content": "lemma conseq_cons B (l : Nat) (v : B) (vs : List B) :\n conseq (v :: vs) l = (Finmap.singleton l v) βˆͺ (conseq vs (l + 1))" }, { "name": "conseq_nil", "content": "lemma conseq_nil B (l : Nat) :\n conseq ([] : List B) l = βˆ…" }, { "name": "hexists_inv", "content": "lemma hexists_inv A (J : A β†’ hProp) h :\n (hexists J) h β†’ exists x, J x h" }, { "name": "hpure_inv", "content": "lemma hpure_inv P h :\n ⌜P⌝ h β†’\n P ∧ h = βˆ…" }, { "name": "diff_disjoint_eq", "content": "lemma diff_disjoint_eq (s₁ sβ‚‚ s₃ : state) :\n s₁.Disjoint sβ‚‚ β†’\n sβ‚‚.keys = s₃.keys β†’\n (s₁ βˆͺ sβ‚‚) \\ s₃ = s₁" }, { "name": "lookup_diff", "content": "lemma lookup_diff (h₁ hβ‚‚ : state) :\n p βˆ‰ hβ‚‚ β†’\n (h₁ \\ hβ‚‚).lookup p = h₁.lookup p" }, { "name": "lookup_diff_none", "content": "lemma lookup_diff_none (h₁ hβ‚‚ : state) :\n p ∈ hβ‚‚ β†’\n (h₁ \\ hβ‚‚).lookup p = none" }, { "name": "diff_non_mem", "content": "theorem diff_non_mem (h₁ hβ‚‚ : state) :\n p ∈ hβ‚‚ β†’ p βˆ‰ h₁ \\ hβ‚‚" } ]
[ { "name": "triple", "content": "abbrev triple (t : trm) (H : hProp) (Q : val β†’ hProp) : Prop :=\n forall s, H s β†’ eval s t Q" }, { "name": "hrange", "content": "def hrange (L : List val) (p : loc) : hProp :=\n match L with\n | [] => emp\n | x :: L' => (p ~~> x) βˆ— (hrange L' (p + 1))" } ]
[ { "name": "eval_conseq", "content": "lemma eval_conseq s t Q1 Q2 :\n eval s t Q1 β†’\n Q1 ===> Q2 β†’\n eval s t Q2" }, { "name": "triple_conseq", "content": "lemma triple_conseq t H' Q' H Q :\n triple t H' Q' β†’\n H ==> H'β†’\n Q' ===> Q β†’\n triple t H Q" }, { "name": "hrange_intro", "content": "lemma hrange_intro L p :\n (hrange L p) (conseq L p)" }, { "name": "int_eq_sub", "content": "lemma int_eq_sub (l m n : β„€) :\n l + m = n β†’ l = n - m" }, { "name": "list_inc_natabs", "content": "lemma list_inc_natabs {Ξ± : Type} (L : List Ξ±) :\n ((L.length : β„€) + 1).natAbs = (L.length : β„€).natAbs + 1" }, { "name": "hrange_eq_conseq", "content": "lemma hrange_eq_conseq (L : List val) (n : β„€) (p : loc) (s : state) :\n L.length = n β†’\n hrange L p s β†’\n s.keys = (conseq (make_list n.natAbs val_uninit) p).keys" } ]
import Mathlib.Data.Finmap import Mathlib.Data.Finset.Basic import Mathlib.Data.Multiset.Nodup import SPLean.Common.State import SPLean.Common.Util import SPLean.Theories.HProp import SPLean.Theories.XSimp open trm val prim abbrev triple (t : trm) (H : hProp) (Q : val β†’ hProp) : Prop := forall s, H s β†’ eval s t Q notation "funloc" p "↦" H => fun (r : val) ↦ hexists (fun p ↦ ⌜r = val_loc p⌝ βˆ— H) section evalProp end evalProp def hrange (L : List val) (p : loc) : hProp := match L with | [] => emp | x :: L' => (p ~~> x) βˆ— (hrange L' (p + 1))
lemma triple_alloc (n : Int) : n β‰₯ 0 β†’ (βˆ€ (p : loc), triple (subst x p t) (H βˆ— ⌜p β‰  null⌝ βˆ— hrange (make_list n.natAbs val_uninit) p) (Q βˆ— ⌜p β‰  null⌝ βˆ— βˆƒΚ° L, ⌜L.length = n⌝ βˆ— hrange L p) ) β†’ triple (trm_alloc x n t) H Q :=
:= by move=> ? htriple h ? apply eval.eval_alloc=> // > * move: (htriple p)=> /triple_conseq {}htriple specialize (htriple (H βˆ— ⌜p β‰  null⌝ βˆ— hrange (make_list n.natAbs val_uninit) p)) specialize (htriple (fun v s ↦ Q v (s \ sb))) have eqn:(triple (subst x p t) (H βˆ— ⌜p β‰  null⌝ βˆ— hrange (make_list n.natAbs val_uninit) p) fun v s ↦ Q v (s \ sb)) := by { apply htriple=> // {htriple} move=> > s ![>] ? ![>] /hpure_inv [] _ -> move=> /hexists_inv [L] ![>] /hpure_inv [] ? -> ? _ move=> /== -> _ -> ? -> srw diff_disjoint_eq=> // subst sb ; sby apply hrange_eq_conseq } move=> {htriple} apply eqn exists h, sb=> ⟨//|⟩ ⟨|⟩ { exists βˆ…, sb => ⟨//|/==⟩ ⟨|⟩ subst sb ; apply hrange_intro sdone } constructor=> // sby srw Finmap.union_comm_of_disjoint Finmap.Disjoint.symm_iff
8
72
false
Framework
412
Theories.wp_alloc
lemma wp_alloc x (n : β„€) t Q : n β‰₯ 0 β†’ (hβˆ€ p, (hrange (make_list n.natAbs val_uninit) p) -βˆ— wp (subst x p t) (Q βˆ— ⌜p β‰  null⌝ βˆ— βˆƒΚ° L, ⌜L.length = n⌝ βˆ— hrange L p)) ==> wp (trm_alloc x n t) Q
splean
SPLean/Theories/WP1.lean
[ "import SPLean.Theories.XChange", "import Mathlib.Data.List.Indexes", "import SPLean.Theories.XSimp", "import SPLean.Theories.SepLog", "import Mathlib.Data.Finmap", "import SPLean.Common.State", "import SPLean.Theories.HProp", "import SPLean.Common.Util", "import Lean", "import SPLean.Theories.WPUtil" ]
[ { "name": "String", "module": "Init.Prelude" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "Finmap", "module": "Mathlib.Data.Finmap" }, { "name": "BEq", "module": "Init.Prelude" }, { "name": "List", "module": "Init.Prelude" }, { "name": "Repr", "module": "Init.Data.Repr" }, { "name": "Vector", "module": "Init.Data.Vector.Basic" }, { "name": "bool", "module": "Init.Control.Basic" }, { "name": "ite", "module": "Init.Prelude" }, { "name": "Computation", "module": "Mathlib.Data.Seq.Computation" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "Max", "module": "Init.Prelude" }, { "name": "Max.max", "module": "Init.Prelude" }, { "name": "Finmap.singleton", "module": "Mathlib.Data.Finmap" }, { "name": "L", "module": "Archive.Hairer" }, { "name": "t", "module": "Ssreflect.IntroPats" }, { "name": "Finmap.Disjoint", "module": "Mathlib.Data.Finmap" }, { "name": "move", "module": "Ssreflect.Basic" }, { "name": "sby", "module": "Ssreflect.Done" }, { "name": "srw", "module": "Ssreflect.Rewrite" }, { "name": "elim", "module": "Ssreflect.Elim" } ]
[ { "name": "notation:max \"emp\" => hempty", "content": "notation:max \"emp\" => hempty\n\nsyntax \"if \" lang \"then \" lang \"end \" : lang\n\nsyntax \" := \" : bop\n\nsyntax \"let\" ident \" := \" lang \" in\" ppDedent(ppLine lang) : lang\n\nsyntax \"fun\" ident+ \" => \" lang : lang\n\nsyntax \"⟨\" term \"⟩\" : lang\n\nsyntax \"⟨\" term \":\" term \"⟩\" : lang" }, { "name": "notation:max \"⌜\" P \"⌝\" => hpure P", "content": "notation:max \"⌜\" P \"⌝\" => hpure P" }, { "name": "macro \"hβˆ€\" xs:Lean.explicitBinders \", \" b:term : term => Lea", "content": "macro \"hβˆ€\" xs:Lean.explicitBinders \", \" b:term : term => Lean.expandExplicitBinders ``hforall xs b" }, { "name": "macro \"βˆƒΚ°\" xs:Lean.explicitBinders \", \" b:term : term => Lea", "content": "macro \"βˆƒΚ°\" xs:Lean.explicitBinders \", \" b:term : term => Lean.expandExplicitBinders ``hexists xs b" }, { "name": "macro_rules", "content": "macro_rules\n | `([lang| ()]) => `(trm_val (val_unit))\n | `([lang| $n:num]) => `(trm_val (val_int $n))\n | `([lang| $t1 $t2]) => `(trm_app [lang| $t1] [lang| $t2])\n | `([lang| if $t1 then $t2 else $t3]) => `(trm_if [lang| $t1] [lang| $t2] [lang| $t3])\n | `([lang| if $t1 then $t2 end]) => `(trm_if [lang| $t1] [lang| $t2] (trm_val val_unit))\n | `([lang| let $x := $t1:lang in $t2:lang]) =>\n `(trm_let $(%x) [lang| $t1] [lang| $t2])\n | `([lang| ref $x := $t1:lang in $t2:lang]) =>\n `(trm_ref $(%x) [lang| $t1] [lang| $t2])\n | `([lang| alloc $t1:lang as $x in $t2:lang]) =>\n `(trm_alloc $(%x) [lang| $t1] [lang| $t2])\n | `([lang| $t1 ; $t2]) => `(trm_seq [lang| $t1] [lang| $t2])\n | `([lang| fun_ $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(trm_funs [ $xs,* ] [lang| $t])\n | `([lang| fun $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(val_funs [ $xs,* ] [lang| $t])\n | `([lang| fix_ $f $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(trm_fixs $(%f) [ $xs,* ] [lang| $t])\n | `([lang| fix $f $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(val_fixs $(%f) [ $xs,* ] [lang| $t])\n \n | `([lang| free $t]) => `(trm_val (val_prim val_free) [lang| $t])\n | `([lang| not $t]) => `(trm_val (val_prim val_not) [lang| $t])\n \n | `([lang| !$t]) => `(trm_val val_get [lang| $t])\n | `([lang| $t1 := $t2]) => `(trm_val val_set [lang| $t1] [lang| $t2])\n | `([lang| $t1 + $t2]) => `(trm_val val_add [lang| $t1] [lang| $t2])\n | `([lang| $t1 * $t2]) => `(trm_val val_mul [lang| $t1] [lang| $t2])\n | `([lang| $t1 - $t2]) => `(trm_val val_sub [lang| $t1] [lang| $t2])\n | `([lang| $t1 / $t2]) => `(trm_val val_div [lang| $t1] [lang| $t2])\n | `([lang| $t1 < $t2]) => `(trm_val val_lt [lang| $t1] [lang| $t2])\n | `([lang| $t1 > $t2]) => `(trm_val val_gt [lang| $t1] [lang| $t2])\n | `([lang| $t1 <= $t2]) => `(trm_val val_le [lang| $t1] [lang| $t2])\n | `([lang| $t1 >= $t2]) => `(trm_val val_ge [lang| $t1] [lang| $t2])\n | `([lang| -$t]) => `(trm_val val_opp [lang| $t])\n | `([lang| $t1 = $t2]) => `(trm_val val_eq [lang| $t1] [lang| $t2])\n | `([lang| $t1 != $t2]) => `(trm_val val_neq [lang| $t1] [lang| $t2])\n | `([lang| $t1 mod $t2]) => `(trm_val val_mod [lang| $t1] [lang| $t2])\n | `([lang| $t1 ++ $t2]) => `(trm_val val_ptr_add [lang| $t1] [lang| $t2])\n | `([lang| ($t)]) => `([lang| $t])\n | `([lang| ⟨$t : $tp⟩]) => `(trm_val (($t : $tp)))\n | `([lang| for $x in [$n1 : $n2] { $t } ]) =>\n `(trm_for $(%x) [lang| $n1] [lang| $n2] [lang| $t])\n | `([lang| while $c:lang { $t:lang } ]) =>\n `(trm_while [lang| $c] [lang| $t] )" }, { "name": "macro_rules", "content": "macro_rules\n | `([lang| len $p]) => `(trm_val val_array_length [lang| $p])\n | `([lang| $arr[$i] ]) => `(trm_val val_array_get [lang| $arr] [lang| $i])\n \n | `([lang| $arr[$i] := $v]) => `(trm_app val_array_set [lang| $arr] [lang| $i] [lang| $v])\n | `([lang| mkarr $n:lang $v:lang]) => `(trm_val val_array_make [lang| $n] [lang| $v])" }, { "name": "macro_rules | `($x βˆ— $y) => `(binop% HStar.hStar $x $y)", "content": "macro_rules | `($x βˆ— $y) => `(binop% HStar.hStar $x $y)\n\n inductive trm : Type where\n | trm_val : val -> trm\n | trm_var : var -> trm\n | trm_fun : var -> trm -> trm\n | trm_fix : var -> var -> trm -> trm\n | trm_app : trm -> trm -> trm\n | trm_seq : trm -> trm -> trm\n | trm_let : var -> trm -> trm -> trm\n | trm_if : trm -> trm -> trm -> trm\n | trm_for : var -> trm -> trm -> trm -> trm\n | trm_while : trm -> trm -> trm\n | trm_ref : var β†’ trm β†’ trm β†’ trm\n | trm_alloc : var β†’ trm β†’ trm β†’ trm\n\n inductive val : Type where\n | val_unit : val\n | val_bool : Bool β†’ val\n | val_int : Int β†’ val\n | val_real : ℝ β†’ val\n | val_loc : loc β†’ val\n | val_prim : prim β†’ val\n | val_fun : var -> trm -> val\n | val_fix : var -> var -> trm -> val\n | val_uninit : val\n | val_error : val" }, { "name": "prim", "content": "inductive prim where\n \n | val_get : prim\n | val_set : prim\n \n | val_neg : prim\n | val_opp : prim\n | val_eq : prim\n | val_add : prim\n | val_neq : prim\n | val_sub : prim\n | val_mul : prim\n | val_div : prim\n | val_mod : prim\n \n | val_le : prim\n | val_lt : prim\n | val_ge : prim\n | val_gt : prim\n | val_ptr_add : prim" }, { "name": "var", "content": "abbrev var := String" }, { "name": "loc", "content": "abbrev loc := Nat" }, { "name": "hProp", "content": "def hProp := heap -> Prop" }, { "name": "heap", "content": "abbrev heap := Heap.heap val" }, { "name": "Heap.heap", "content": "abbrev Heap.heap (val : Type) := Finmap (Ξ» _ : loc ↦ val)" }, { "name": "eval", "content": "inductive eval : state β†’ trm β†’ (val β†’ state β†’ Prop) -> Prop where\n | eval_val : forall s v Q,\n Q v s ->\n eval s (trm_val v) Q\n | eval_fun : forall s x t1 Q,\n Q (val_fun x t1) s ->\n eval s (trm_fun x t1) Q\n | eval_fix : forall s f x t1 Q,\n Q (val_fix f x t1) s ->\n eval s (trm_fix f x t1) Q\n | eval_app_arg1 : forall s1 t1 t2 Q1 Q,\n Β¬ trm_is_val t1 ->\n eval s1 t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> eval s2 (trm_app v1 t2) Q) ->\n eval s1 (trm_app t1 t2) Q\n | eval_app_arg2 : forall s1 (v1 : val) t2 Q1 Q,\n Β¬ trm_is_val t2 ->\n eval s1 t2 Q1 ->\n (forall v2 s2, Q1 v2 s2 -> eval s2 (trm_app v1 v2) Q) ->\n eval s1 (trm_app v1 t2) Q\n | eval_app_fun : forall s1 v1 (v2 :val) x t1 Q,\n v1 = val_fun x t1 ->\n eval s1 (subst x v2 t1) Q ->\n eval s1 (trm_app v1 v2) Q\n | eval_app_fix : forall s (v1 v2 : val) f x t1 Q,\n v1 = val_fix f x t1 ->\n eval s (subst x v2 (subst f v1 t1)) Q ->\n eval s (trm_app v1 v2) Q\n | eval_seq : forall Q1 s t1 t2 Q,\n eval s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> eval s2 t2 Q) ->\n eval s (trm_seq t1 t2) Q\n | eval_let : forall Q1 s x t1 t2 Q,\n eval s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> eval s2 (subst x v1 t2) Q) ->\n eval s (trm_let x t1 t2) Q\n | eval_if : forall s (b : Bool) t1 t2 Q,\n eval s (if b then t1 else t2) Q ->\n eval s (trm_if (val_bool b) t1 t2) Q\n | eval_unop : forall op s v1 P Q,\n evalunop op v1 P ->\n purepostin s P Q ->\n eval s (trm_app op v1) Q\n | eval_binop : forall op s (v1 v2 : val) P Q,\n evalbinop op v1 v2 P ->\n purepostin s P Q ->\n eval s (trm_app (trm_app op v1) v2) Q\n | eval_ref : forall s x t1 t2 (Q Q₁ : val β†’ state β†’ Prop),\n eval s t1 Q₁ β†’\n (βˆ€ v1 s1, Q₁ v1 s1 β†’ βˆ€ p βˆ‰ s1,\n eval (s1.insert p v1) (subst x p t2) fun v s ↦ Q v (s.erase p)) β†’\n eval s (trm_ref x t1 t2) Q\n | eval_get : forall s p Q,\n p ∈ s ->\n Q (read_state p s) s ->\n eval s (trm_app val_get (val_loc p)) Q\n | eval_set : forall s p v Q,\n v = trm_val v' ->\n p ∈ s ->\n Q val_unit (Finmap.insert p v' s) ->\n eval s (trm_app (trm_app val_set (val_loc p)) v) Q\n | eval_alloc_arg : forall s Q₁ Q,\n Β¬ trm_is_val t1 β†’\n eval s t1 Q₁ β†’\n (βˆ€ v' s', Q₁ v' s' β†’ eval s' (trm_alloc x v' t2) Q) β†’\n eval s (trm_alloc x t1 t2) Q\n | eval_alloc : forall (sa : state) (n : β„€) Q,\n n β‰₯ 0 β†’\n (βˆ€ (p : loc) (sb : state),\n sb = conseq (make_list n.natAbs val_uninit) p β†’\n p β‰  null β†’\n Finmap.Disjoint sa sb β†’\n eval (sb βˆͺ sa) (subst x p t2) fun v s ↦ Q v (s \\ sb)) β†’\n eval sa (trm_alloc x n t2) Q\n \n \n \n \n \n \n \n \n | eval_for (n₁ nβ‚‚ : Int) (Q : val -> state -> Prop) :\n eval s (if (n₁ < nβ‚‚) then\n (trm_seq (subst x n₁ t₁) (trm_for x (val_int (n₁ + 1)) nβ‚‚ t₁))\n else val_unit) Q ->\n eval s (trm_for x n₁ nβ‚‚ t₁) Q\n | eval_while (t₁ tβ‚‚ : trm) (Q : val -> state -> Prop) :\n eval s t₁ Q₁ ->\n (βˆ€ s v, Q₁ v s -> eval s (trm_if v (trm_seq tβ‚‚ (trm_while t₁ tβ‚‚)) val_unit) Q) ->\n eval s (trm_while t₁ tβ‚‚) Q" }, { "name": "HStar", "content": "class HStar (Ξ± : Type u) (Ξ² : Type v) (Ξ³ : outParam (Type w)) where\n \n hStar : Ξ± β†’ Ξ² β†’ Ξ³" }, { "name": "make_list", "content": "def make_list {A} (n : Nat) (v : A) : List A :=\n match n with\n | 0 => []\n | n' + 1 => v :: make_list n' v" }, { "name": "hrange", "content": "def hrange (L : List val) (p : loc) : hProp :=\n match L with\n | [] => emp\n | x :: L' => (p ~~> x) βˆ— (hrange L' (p + 1))" }, { "name": "wpgen_alloc", "content": "def wpgen_alloc (x : var) (t1 t2 : trm) : formula :=\n fun Q ↦ βˆƒΚ° n : β„€,\n ⌜n β‰₯ 0 ∧ t1 = trm_val n⌝ βˆ—\n hβˆ€ p,\n (hrange (make_list n.natAbs val_uninit) p) -βˆ—\n protect wp (subst x p t2) (Q βˆ— ⌜p β‰  null⌝ βˆ— βˆƒΚ° L, ⌜L.length = n⌝ βˆ— hrange L p)" }, { "name": "wpgen", "content": "def wpgen (t : trm) : formula :=\n mkstruct (match t with\n | trm_val v => wpgen_val v\n | trm_fun x t1 => wpgen_fun (fun v ↦ wp $ subst x v t1)\n | trm_fix f x t1 => wpgen_fix\n (fun vf v => wp $ subst x v $ subst f vf t1)\n | trm_if t0 t1 t2 => wpgen_if t0 (wp t1) (wp t2)\n | trm_seq t1 t2 => wpgen_seq (wp t1) (wp t2)\n | trm_let x t1 t2 => wpgen_let (wp t1) (fun v ↦ wp $ subst x v t2)\n | trm_app _ _ => wpgen_app t\n \n \n | trm_ref x t1 t2 => wpgen_ref x t1 t2\n | trm_alloc x t1 t2 => wpgen_alloc x t1 t2\n | _ => wp t\n )" }, { "name": "hsingle", "content": "def hsingle (p : loc) (v : val) : hProp :=\n fun h => (h = Finmap.singleton p v)" }, { "name": "evalExact", "content": "inductive evalExact : state β†’ trm β†’ (val β†’ state β†’ Prop) -> Prop where\n | val : forall s v,\n evalExact s (trm_val v) (fun v' s' ↦ v' = v ∧ s' = s)\n | fun : forall s x t1,\n evalExact s (trm_fun x t1) (fun v' s' ↦ v' = val_fun x t1 ∧ s' = s)\n | fix : forall s f x t1,\n evalExact s (trm_fix f x t1) (fun v' s' ↦ v' = val_fix f x t1 ∧ s' = s)\n | app_arg1 : forall s1 t1 t2 Q1 Q,\n Β¬ trm_is_val t1 ->\n evalExact s1 t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 (trm_app v1 t2) Q) ->\n evalExact s1 (trm_app t1 t2) Q\n | app_arg2 : forall s1 (v1 : val) t2 Q1 Q,\n Β¬ trm_is_val t2 ->\n evalExact s1 t2 Q1 ->\n (forall v2 s2, Q1 v2 s2 -> evalExact s2 (trm_app v1 v2) Q) ->\n evalExact s1 (trm_app v1 t2) Q\n | app_fun : forall s1 v1 (v2 :val) x t1 Q,\n v1 = val_fun x t1 ->\n evalExact s1 (subst x v2 t1) Q ->\n evalExact s1 (trm_app v1 v2) Q\n | app_fix : forall s (v1 v2 : val) f x t1 Q,\n v1 = val_fix f x t1 ->\n evalExact s (subst x v2 (subst f v1 t1)) Q ->\n evalExact s (trm_app v1 v2) Q\n | seq : forall Q1 s t1 t2 Q,\n evalExact s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 t2 Q) ->\n evalExact s (trm_seq t1 t2) Q\n | let : forall Q1 s x t1 t2 Q,\n evalExact s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 (subst x v1 t2) Q) ->\n evalExact s (trm_let x t1 t2) Q\n | if : forall s (b : Bool) t1 t2 Q,\n evalExact s (if b then t1 else t2) Q ->\n evalExact s (trm_if (val_bool b) t1 t2) Q\n | unop : forall op s v1 P,\n evalunop op v1 P ->\n evalExact s (trm_app op v1) (purepost s P)\n | binop : forall op s (v1 v2 : val) P,\n evalbinop op v1 v2 P ->\n evalExact s (trm_app (trm_app op v1) v2) (purepost s P)\n | ref : forall s x t1 t2 Q Q₁,\n evalExact s t1 Q₁ β†’\n (βˆ€ v1 s1, Q₁ v1 s1 β†’ βˆ€ p βˆ‰ s1,\n evalExact (s1.insert p v1) (subst x p t2) fun v s ↦ Q v (s.erase p)) β†’\n evalExact s (trm_ref x t1 t2) Q\n | get : forall s p,\n p ∈ s ->\n evalExact s (trm_app val_get (val_loc p))\n (fun v' s' ↦ v' = read_state p s ∧ s' = s)\n | set : forall s p v,\n v = trm_val v' ->\n p ∈ s ->\n evalExact s (trm_app (trm_app val_set (val_loc p)) v)\n (fun v'' s' ↦ v'' = val_unit ∧ s' = s.insert p v')\n | alloc_arg : forall s Q₁ Q,\n Β¬ trm_is_val t1 β†’\n evalExact s t1 Q₁ β†’\n (βˆ€ v' s', Q₁ v' s' β†’ evalExact s' (trm_alloc x v' t2) Q) β†’\n evalExact s (trm_alloc x t1 t2) Q\n | alloc : forall (sa : state) (n : β„€) Q,\n n β‰₯ 0 β†’\n (βˆ€ (p : loc) (sb : state),\n sb = conseq (make_list n.natAbs val_uninit) p β†’\n p β‰  null β†’\n Finmap.Disjoint sa sb β†’\n evalExact (sb βˆͺ sa) (subst x p t2) fun v s ↦ Q v (s \\ sb)) β†’\n evalExact sa (trm_alloc x n t2) Q\n \n \n \n \n \n \n | for (n₁ nβ‚‚ : Int) (Q : val -> state -> Prop) :\n evalExact s (if (n₁ < nβ‚‚) then\n (trm_seq (subst x n₁ t₁) (trm_for x (val_int (n₁ + 1)) nβ‚‚ t₁))\n else val_unit) Q ->\n evalExact s (trm_for x n₁ nβ‚‚ t₁) Q\n | while (t₁ tβ‚‚ : trm) (Q Q₁ : val -> state -> Prop) :\n evalExact s t₁ Q₁ ->\n (βˆ€ s v, Q₁ v s -> evalExact s (trm_if v (trm_seq tβ‚‚ (trm_while t₁ tβ‚‚)) val_unit) Q) ->\n evalExact s (trm_while t₁ tβ‚‚) Q" }, { "name": "hempty", "content": "def hempty : hProp :=\n fun h => (h = βˆ…)" }, { "name": "subst", "content": "def subst (y : var) (v' : val) (t : trm) : trm :=\n \n let if_y_eq x t1 t2 := if x = y then t1 else t2\n match t with\n | trm_val v => trm_val v\n | trm_var x => if_y_eq x (trm_val v') t\n | trm_fun x t1 => trm_fun x (if_y_eq x t1 (subst y v' t1))\n | trm_fix f x t1 => trm_fix f x (if_y_eq f t1 (if_y_eq x t1 (subst y v' t1)))\n | trm_app t1 t2 => trm_app (subst y v' t1) (subst y v' t2)\n | trm_seq t1 t2 => trm_seq (subst y v' t1) (subst y v' t2)\n | trm_let x t1 t2 => trm_let x (subst y v' t1) (if_y_eq x t2 (subst y v' t2))\n | trm_if t0 t1 t2 => trm_if (subst y v' t0) (subst y v' t1) (subst y v' t2)\n | trm_for x t1 t2 t3 => trm_for x (subst y v' t1) (subst y v' t2) (if_y_eq x t3 (subst y v' t3))\n | trm_while t1 t2 => trm_while (subst y v' t1) (subst y v' t2)\n | trm_ref x t1 t2 => trm_ref x (subst y v' t1) (if_y_eq x t2 (subst y v' t2))\n | trm_alloc x t1 t2 => trm_alloc x (subst y v' t1) (if_y_eq x t2 (subst y v' t2))" }, { "name": "null", "content": "def null : loc := 0" }, { "name": "HWand", "content": "class HWand (Ξ± : Type u) (Ξ² : Type v) (Ξ³ : outParam (Type w)) where\n \n hWand : Ξ± β†’ Ξ² β†’ Ξ³" }, { "name": "hpure", "content": "def hpure (P : Prop) : hProp :=\n hexists (fun (_ : P) => emp)" }, { "name": "hexists", "content": "def hexists {A} (J : A β†’ hProp) : hProp :=\n fun h => exists x, J x h" }, { "name": "himpl", "content": "abbrev himpl (H1 H2 : hProp) : Prop :=\n forall h, H1 h -> H2 h" }, { "name": "conseq", "content": "def conseq {B : Type} (vs : List B) (l : Nat) : Finmap (fun _ : Nat ↦ B) :=\n match vs with\n | [] => βˆ…\n | v :: vs' => (Finmap.singleton l v) βˆͺ (conseq vs' (l + 1))" }, { "name": "purepostin", "content": "def purepostin (s : state) (P : val β†’ Prop) (Q : val β†’ state β†’ Prop) : Prop :=\n \n forall v, P v β†’ Q v s" }, { "name": "state", "content": "abbrev state := Finmap (Ξ» _ : loc ↦ val)" }, { "name": "qimpl", "content": "def qimpl {A} (Q1 Q2 : A β†’ hProp) : Prop :=\n forall (v:A), Q1 v ==> Q2 v" }, { "name": "hforall", "content": "def hforall {A} (J : A β†’ hProp) : hProp :=\n fun h => forall x, J x h" }, { "name": "infixr:51 \" ==> \" => himpl", "content": "infixr:51 \" ==> \" => himpl" }, { "name": "infixr:51 \" ===> \" => qimpl", "content": "infixr:51 \" ===> \" => qimpl" }, { "name": "notation:max \"emp\" => hempty", "content": "notation:max \"emp\" => hempty" }, { "name": "infixr:60 \" ~~> \" => hsingle", "content": "infixr:60 \" ~~> \" => hsingle" }, { "name": "infixr:55 \" βˆ— \" => HStar.hStar", "content": "infixr:55 \" βˆ— \" => HStar.hStar" }, { "name": "notation:max \"⌜\" P \"⌝\" => hpure P", "content": "notation:max \"⌜\" P \"⌝\" => hpure P" }, { "name": "infixr:55 \" -βˆ— \" => HWand.hWand", "content": "infixr:55 \" -βˆ— \" => HWand.hWand" }, { "name": "fun", "content": "notation \"funloc\" p \"↦\" H =>\n fun (r : val) ↦ hexists (fun p ↦ ⌜r = val_loc p⌝ βˆ— H)" } ]
[ { "name": "Finmap.Disjoint.symm_iff", "module": "Mathlib.Data.Finmap" } ]
[ { "name": "eval_conseq", "content": "lemma eval_conseq s t Q1 Q2 :\n eval s t Q1 β†’\n Q1 ===> Q2 β†’\n eval s t Q2" }, { "name": "hpure_inv", "content": "lemma hpure_inv P h :\n ⌜P⌝ h β†’\n P ∧ h = βˆ…" }, { "name": "hwand_inv", "content": "lemma hwand_inv h1 h2 H1 H2 :\n (H1 -βˆ— H2) h2 β†’\n H1 h1 β†’\n Finmap.Disjoint h1 h2 β†’\n H2 (h1 βˆͺ h2)" }, { "name": "hrange_eq_conseq", "content": "lemma hrange_eq_conseq (L : List val) (n : β„€) (p : loc) (s : state) :\n L.length = n β†’\n hrange L p s β†’\n s.keys = (conseq (make_list n.natAbs val_uninit) p).keys" }, { "name": "hseg_eq_hrange", "content": "lemma hseg_eq_hrange L p (k : Nat) :\n hseg L p k = hrange L (p + 1 + k)" }, { "name": "hrange_intro", "content": "lemma hrange_intro L p :\n (hrange L p) (conseq L p)" }, { "name": "int_eq_sub", "content": "lemma int_eq_sub (l m n : β„€) :\n l + m = n β†’ l = n - m" }, { "name": "list_inc_natabs", "content": "lemma list_inc_natabs {Ξ± : Type} (L : List Ξ±) :\n ((L.length : β„€) + 1).natAbs = (L.length : β„€).natAbs + 1" }, { "name": "nonneg_eq_abs", "content": "lemma nonneg_eq_abs (n : Int) :\n 0 ≀ n β†’ n.natAbs = n" }, { "name": "neg_mul_abs", "content": "lemma neg_mul_abs (n : Int) :\n n < 0 β†’ -1 * n = n.natAbs" }, { "name": "triple_abs", "content": "lemma triple_abs (i : Int) :\n triple [lang| val_abs i]\n emp\n (fun r ↦ ⌜r = val_int i.natAbs⌝)" }, { "name": "add_Int.natAbs", "content": "lemma add_Int.natAbs i j :\n 0 <= i - j β†’ j + Int.natAbs (i - j) = i" }, { "name": "hseg_focus", "content": "lemma hseg_focus (i j : Int) L p (v : 0 <= i - j ∧ i - j < L.length) :\n 0 <= i - j ∧ i - j < L.length β†’\n hseg L p j ==>\n hcell L[(i - j).natAbs]! p i\n βˆ— (hβˆ€ w, hcell w p i -βˆ— hseg (L.set (i - j).natAbs w) p j)" }, { "name": "harray_focus", "content": "lemma harray_focus i L p (v : 0 <= i ∧ i < L.length) :\n 0 <= i ∧ i < L.length β†’\n harray L p ==>\n hcell L[Int.natAbs i]! p i\n βˆ— (hβˆ€ w, hcell w p i -βˆ— harray (L.set (Int.natAbs i) w) p)" }, { "name": "natabs_eq", "content": "lemma natabs_eq (a : Nat) :\n a = (Int.ofNat a).natAbs" }, { "name": "set_nth_same", "content": "lemma set_nth_same (A : Type) (IA : Inhabited A) (n : Nat) (l : List A) :\n n < l.length β†’ l.set n l[n]! = l" }, { "name": "harray_focus_read", "content": "lemma harray_focus_read i L p :\n 0 <= i ∧ i < L.length β†’\n harray L p ==>\n hcell L[Int.natAbs i]! p i βˆ— (hcell L[Int.natAbs i]! p i -βˆ— harray L p)" }, { "name": "hforall_inv", "content": "lemma hforall_inv A (J : A β†’ hProp) h :\n (hforall J) h β†’ forall x, J x h" }, { "name": "hexists_inv", "content": "lemma hexists_inv A (J : A β†’ hProp) h :\n (hexists J) h β†’ exists x, J x h" }, { "name": "diff_disjoint_eq", "content": "lemma diff_disjoint_eq (s₁ sβ‚‚ s₃ : state) :\n s₁.Disjoint sβ‚‚ β†’\n sβ‚‚.keys = s₃.keys β†’\n (s₁ βˆͺ sβ‚‚) \\ s₃ = s₁" }, { "name": "lookup_diff", "content": "lemma lookup_diff (h₁ hβ‚‚ : state) :\n p βˆ‰ hβ‚‚ β†’\n (h₁ \\ hβ‚‚).lookup p = h₁.lookup p" }, { "name": "lookup_diff_none", "content": "lemma lookup_diff_none (h₁ hβ‚‚ : state) :\n p ∈ hβ‚‚ β†’\n (h₁ \\ hβ‚‚).lookup p = none" }, { "name": "diff_non_mem", "content": "theorem diff_non_mem (h₁ hβ‚‚ : state) :\n p ∈ hβ‚‚ β†’ p βˆ‰ h₁ \\ hβ‚‚" }, { "name": "triple", "content": "abbrev triple (t : trm) (H : hProp) (Q : val β†’ hProp) : Prop :=\n forall s, H s β†’ eval s t Q" }, { "name": "triple_alloc", "content": "lemma triple_alloc (n : Int) :\n n β‰₯ 0 β†’\n (βˆ€ (p : loc), triple (subst x p t)\n (H βˆ— ⌜p β‰  null⌝ βˆ— hrange (make_list n.natAbs val_uninit) p)\n (Q βˆ— ⌜p β‰  null⌝ βˆ— βˆƒΚ° L, ⌜L.length = n⌝ βˆ— hrange L p) ) β†’\n triple (trm_alloc x n t) H Q" }, { "name": "hstar_comm", "content": "lemma hstar_comm H1 H2 :\n H1 βˆ— H2 = H2 βˆ— H1" }, { "name": "hstar_assoc", "content": "lemma hstar_assoc H1 H2 H3 :\n (H1 βˆ— H2) βˆ— H3 = H1 βˆ— (H2 βˆ— H3)" }, { "name": "hstar_comm_assoc", "content": "lemma hstar_comm_assoc (H1 H2 H3 : hProp) :\n H1 βˆ— H2 βˆ— H3 = H2 βˆ— H1 βˆ— H3" }, { "name": "hwand_cancel", "content": "lemma hwand_cancel H1 H2 :\n H1 βˆ— (H1 -βˆ— H2) ==> H2" }, { "name": "himpl_trans", "content": "lemma himpl_trans H2 H1 H3 :\n (H1 ==> H2) β†’ (H2 ==> H3) β†’ (H1 ==> H3)" }, { "name": "himpl_hstar_hpure_l", "content": "lemma himpl_hstar_hpure_l P H H' :\n (P β†’ H ==> H') β†’\n (⌜P⌝ βˆ— H) ==> H'" }, { "name": "hforall_specialize", "content": "lemma hforall_specialize A (x : A) (J : A β†’ hProp) :\n (hforall J) ==> (J x)" }, { "name": "himpl_frame_r", "content": "lemma himpl_frame_r H1 H2 H2' :\n H2 ==> H2' β†’\n (H1 βˆ— H2) ==> (H1 βˆ— H2')" }, { "name": "finite_state'", "content": "lemma finite_state' n (s : state) :\n βˆƒ p, p β‰  null ∧\n Finmap.Disjoint s (conseq (make_list n val_uninit) p)" }, { "name": "conseq_nil", "content": "lemma conseq_nil B (l : Nat) :\n conseq ([] : List B) l = βˆ…" }, { "name": "conseq_cons", "content": "lemma conseq_cons B (l : Nat) (v : B) (vs : List B) :\n conseq (v :: vs) l = (Finmap.singleton l v) βˆͺ (conseq vs (l + 1))" }, { "name": "disjoint_single_conseq", "content": "lemma disjoint_single_conseq B l l' L (v : B) :\n (l < l') ∨ (l β‰₯ l' + L.length) β†’\n Finmap.Disjoint (Finmap.singleton l v) (conseq L l')" }, { "name": "union_difference_id", "content": "lemma union_difference_id (h₁ hβ‚‚ : state) :\n h₁.Disjoint hβ‚‚ β†’\n (h₁ βˆͺ hβ‚‚) \\ hβ‚‚ = h₁" }, { "name": "hstar_hempty_l", "content": "lemma hstar_hempty_l H :\n emp βˆ— H = H" }, { "name": "hstar_hempty_r", "content": "lemma hstar_hempty_r H :\n H βˆ— emp = H" }, { "name": "himpl_refl", "content": "lemma himpl_refl H : H ==> H" }, { "name": "hstar_intro", "content": "lemma hstar_intro (H1 H2 : hProp) h1 h2 :\n H1 h1 β†’\n H2 h2 β†’\n Finmap.Disjoint h1 h2 β†’\n (H1 βˆ— H2) (h1 βˆͺ h2)" }, { "name": "hstar_inv", "content": "lemma hstar_inv (H1 H2 : hProp) h:\n (H1 βˆ— H2) h β†’\n exists h1 h2, H1 h1 ∧ H2 h2 ∧ Finmap.Disjoint h1 h2 ∧ h = h1 βˆͺ h2" }, { "name": "diff_disjoint_eq", "content": "lemma diff_disjoint_eq (s₁ sβ‚‚ s₃ : state) :\n s₁.Disjoint sβ‚‚ β†’\n sβ‚‚.keys = s₃.keys β†’\n (s₁ βˆͺ sβ‚‚) \\ s₃ = s₁" }, { "name": "qstar_simp", "content": "lemma qstar_simp (Q1 : Ξ± -> hProp) :\n (Q1 βˆ— H) x = Q1 x βˆ— H" }, { "name": "himpl_hexists_l", "content": "lemma himpl_hexists_l A H (J : A β†’ hProp) :\n (forall x, J x ==> H) β†’ (hexists J) ==> H" }, { "name": "himpl_hexists_r", "content": "lemma himpl_hexists_r A (x : A) H (J : A β†’ hProp) :\n (H ==> J x) β†’\n H ==> (hexists J)" }, { "name": "triple_conseq", "content": "lemma triple_conseq t H' Q' H Q :\n triple t H' Q' β†’\n H ==> H'β†’\n Q' ===> Q β†’\n triple t H Q" }, { "name": "triple_frame", "content": "lemma triple_frame t H (Q : val -> hProp) H' :\n triple t H Q β†’\n triple t (H βˆ— H') (Q βˆ— H')" }, { "name": "triple_hpure", "content": "lemma triple_hpure t P H Q :\n (P β†’ triple t H Q) β†’\n triple t (⌜P⌝ βˆ— H) Q" }, { "name": "triple_hexists", "content": "lemma triple_hexists t A (J : A β†’ hProp) Q :\n (forall x, triple t (J x) Q) β†’\n triple t (hexists J) Q" }, { "name": "hwand_equiv", "content": "lemma hwand_equiv H0 H1 H2 :\n (H0 ==> H1 -βˆ— H2) ↔ (H1 βˆ— H0 ==> H2)" }, { "name": "himpl_hwand_r", "content": "lemma himpl_hwand_r H1 H2 H3 :\n H2 βˆ— H1 ==> H3 β†’\n H1 ==> (H2 -βˆ— H3)" }, { "name": "himpl_hwand_r_inv", "content": "lemma himpl_hwand_r_inv H1 H2 H3 :\n H1 ==> (H2 -βˆ— H3) β†’\n H2 βˆ— H1 ==> H3" }, { "name": "hwand_hempty_l", "content": "lemma hwand_hempty_l H :\n (emp -βˆ— H) = H" }, { "name": "himpl_hforall_r", "content": "lemma himpl_hforall_r A (J : A β†’ hProp) H :\n (forall x, H ==> J x) β†’\n H ==> (hforall J)" }, { "name": "himpl_hforall_l", "content": "lemma himpl_hforall_l A (x : A) (J : A β†’ hProp) H :\n (J x ==> H) β†’\n (hforall J) ==> H" } ]
[ { "name": "Theories.wp", "content": "def wp (t : trm) (Q : val β†’ hProp) : hProp :=\n fun s ↦ eval s t Q" } ]
[ { "name": "Theories.mem_conseq", "content": "lemma mem_conseq :\n x ∈ conseq L p β†’ p ≀ x" }, { "name": "Theories.hrange_of_conseq", "content": "lemma hrange_of_conseq :\n (hrange L p) (conseq L p)" } ]
import Lean import Mathlib.Data.Finmap import Mathlib.Data.List.Indexes import SPLean.Common.State import SPLean.Common.Util import SPLean.Theories.HProp import SPLean.Theories.XSimp import SPLean.Theories.XChange import SPLean.Theories.SepLog import SPLean.Theories.WPUtil open trm val prim namespace Theories def wp (t : trm) (Q : val β†’ hProp) : hProp := fun s ↦ eval s t Q
lemma wp_alloc x (n : β„€) t Q : n β‰₯ 0 β†’ (hβˆ€ p, (hrange (make_list n.natAbs val_uninit) p) -βˆ— wp (subst x p t) (Q βˆ— ⌜p β‰  null⌝ βˆ— βˆƒΚ° L, ⌜L.length = n⌝ βˆ— hrange L p)) ==> wp (trm_alloc x n t) Q :=
:= by move=> ? h /hforall_inv hwp apply eval.eval_alloc=> // > * apply (eval_conseq _ _ (Q βˆ— ⌜p β‰  null⌝ βˆ— βˆƒΚ° L, βŒœβ†‘L.length = n⌝ βˆ— hrange L p)) { move: (hwp p)=> /(hwand_inv sb) srw Finmap.Disjoint.symm_iff=> {}hwp apply hwp=> // ; subst sb apply hrange_of_conseq } move=> > s ![>] ? ![>] /hpure_inv [_ ->] /== move=> /hexists_inv [L] ![>] /hpure_inv [? ->] /== ? _ -> _ -> ? -> srw diff_disjoint_eq=> // ; subst sb sby apply hrange_eq_conseq
5
65
false
Framework
413
xfor_lemma
lemma xfor_lemma (z n : β„€) (x : var) (I : β„€ -> hProp) : z <= n -> (H ==> H' βˆ— I z) -> (βˆ€ i, z <= i -> i < n -> I i ==> wp (subst x i F1) (fun _ => I (i + 1))) -> ((fun _ => I n βˆ— H') ===> Q) -> H ==> wp (trm_for x z n F1) Q
splean
SPLean/Theories/WP1.lean
[ "import SPLean.Theories.XChange", "import Mathlib.Data.List.Indexes", "import SPLean.Theories.XSimp", "import SPLean.Theories.SepLog", "import Mathlib.Data.Finmap", "import SPLean.Common.State", "import SPLean.Theories.HProp", "import SPLean.Common.Util", "import Lean", "import SPLean.Theories.WPUtil" ]
[ { "name": "String", "module": "Init.Prelude" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "Finmap", "module": "Mathlib.Data.Finmap" }, { "name": "BEq", "module": "Init.Prelude" }, { "name": "List", "module": "Init.Prelude" }, { "name": "Repr", "module": "Init.Data.Repr" }, { "name": "Vector", "module": "Init.Data.Vector.Basic" }, { "name": "bool", "module": "Init.Control.Basic" }, { "name": "ite", "module": "Init.Prelude" }, { "name": "Computation", "module": "Mathlib.Data.Seq.Computation" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "Max", "module": "Init.Prelude" }, { "name": "Max.max", "module": "Init.Prelude" }, { "name": "DecidableEq", "module": "Init.Prelude" }, { "name": "Fin", "module": "Init.Prelude" }, { "name": "Inhabited", "module": "Init.Prelude" }, { "name": "Lean.ToExpr", "module": "Lean.ToExpr" }, { "name": "Id", "module": "Init.Control.Id" }, { "name": "BitVec", "module": "Init.Prelude" }, { "name": "Hashable", "module": "Init.Prelude" }, { "name": "move", "module": "Ssreflect.Basic" }, { "name": "sdone", "module": "Ssreflect.Done" }, { "name": "srw", "module": "Ssreflect.Rewrite" }, { "name": "t", "module": "Ssreflect.IntroPats" }, { "name": "sby", "module": "Ssreflect.Done" }, { "name": "Finmap.Disjoint", "module": "Mathlib.Data.Finmap" } ]
[ { "name": "syntax \"if \" lang \"then \" lang \"end \" : lang", "content": "syntax \"if \" lang \"then \" lang \"end \" : lang\n\nsyntax \" := \" : bop\n\nsyntax \"let\" ident \" := \" lang \" in\" ppDedent(ppLine lang) : lang\n\nsyntax \"fun\" ident+ \" => \" lang : lang\n\nsyntax \"⟨\" term \"⟩\" : lang\n\nsyntax \"⟨\" term \":\" term \"⟩\" : lang" }, { "name": "macro \"xsimp\" : tactic =>", "content": "macro \"xsimp\" : tactic =>\n `(tactic| (\n xsimp_start\n repeat xsimp_step\n try rev_pure\n try hide_mvars\n try hsimp\n rotate_left\n\n ))\n\n syntax \"sdo\" num tactic : tactic" }, { "name": "notation:max \"emp\" => hempty", "content": "notation:max \"emp\" => hempty" }, { "name": "notation:max \"⌜\" P \"⌝\" => hpure P", "content": "notation:max \"⌜\" P \"⌝\" => hpure P\n\nsyntax \" <= \" : bop" }, { "name": "macro \"xchange\" l:term : tactic =>", "content": "macro \"xchange\" l:term : tactic =>\n `(tactic| (xchange_core $l; xsimp))" }, { "name": "macro_rules", "content": "macro_rules\n | `(term| {| $seq |}) => `(withMainContext do evalTactic $ <- `(tacticSeq| $seq))" }, { "name": "macro_rules", "content": "macro_rules\n | `([lang| ()]) => `(trm_val (val_unit))\n | `([lang| $n:num]) => `(trm_val (val_int $n))\n | `([lang| $t1 $t2]) => `(trm_app [lang| $t1] [lang| $t2])\n | `([lang| if $t1 then $t2 else $t3]) => `(trm_if [lang| $t1] [lang| $t2] [lang| $t3])\n | `([lang| if $t1 then $t2 end]) => `(trm_if [lang| $t1] [lang| $t2] (trm_val val_unit))\n | `([lang| let $x := $t1:lang in $t2:lang]) =>\n `(trm_let $(%x) [lang| $t1] [lang| $t2])\n | `([lang| ref $x := $t1:lang in $t2:lang]) =>\n `(trm_ref $(%x) [lang| $t1] [lang| $t2])\n | `([lang| alloc $t1:lang as $x in $t2:lang]) =>\n `(trm_alloc $(%x) [lang| $t1] [lang| $t2])\n | `([lang| $t1 ; $t2]) => `(trm_seq [lang| $t1] [lang| $t2])\n | `([lang| fun_ $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(trm_funs [ $xs,* ] [lang| $t])\n | `([lang| fun $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(val_funs [ $xs,* ] [lang| $t])\n | `([lang| fix_ $f $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(trm_fixs $(%f) [ $xs,* ] [lang| $t])\n | `([lang| fix $f $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(val_fixs $(%f) [ $xs,* ] [lang| $t])\n \n | `([lang| free $t]) => `(trm_val (val_prim val_free) [lang| $t])\n | `([lang| not $t]) => `(trm_val (val_prim val_not) [lang| $t])\n \n | `([lang| !$t]) => `(trm_val val_get [lang| $t])\n | `([lang| $t1 := $t2]) => `(trm_val val_set [lang| $t1] [lang| $t2])\n | `([lang| $t1 + $t2]) => `(trm_val val_add [lang| $t1] [lang| $t2])\n | `([lang| $t1 * $t2]) => `(trm_val val_mul [lang| $t1] [lang| $t2])\n | `([lang| $t1 - $t2]) => `(trm_val val_sub [lang| $t1] [lang| $t2])\n | `([lang| $t1 / $t2]) => `(trm_val val_div [lang| $t1] [lang| $t2])\n | `([lang| $t1 < $t2]) => `(trm_val val_lt [lang| $t1] [lang| $t2])\n | `([lang| $t1 > $t2]) => `(trm_val val_gt [lang| $t1] [lang| $t2])\n | `([lang| $t1 <= $t2]) => `(trm_val val_le [lang| $t1] [lang| $t2])\n | `([lang| $t1 >= $t2]) => `(trm_val val_ge [lang| $t1] [lang| $t2])\n | `([lang| -$t]) => `(trm_val val_opp [lang| $t])\n | `([lang| $t1 = $t2]) => `(trm_val val_eq [lang| $t1] [lang| $t2])\n | `([lang| $t1 != $t2]) => `(trm_val val_neq [lang| $t1] [lang| $t2])\n | `([lang| $t1 mod $t2]) => `(trm_val val_mod [lang| $t1] [lang| $t2])\n | `([lang| $t1 ++ $t2]) => `(trm_val val_ptr_add [lang| $t1] [lang| $t2])\n | `([lang| ($t)]) => `([lang| $t])\n | `([lang| ⟨$t : $tp⟩]) => `(trm_val (($t : $tp)))\n | `([lang| for $x in [$n1 : $n2] { $t } ]) =>\n `(trm_for $(%x) [lang| $n1] [lang| $n2] [lang| $t])\n | `([lang| while $c:lang { $t:lang } ]) =>\n `(trm_while [lang| $c] [lang| $t] )" }, { "name": "macro_rules", "content": "macro_rules\n | `([lang| len $p]) => `(trm_val val_array_length [lang| $p])\n | `([lang| $arr[$i] ]) => `(trm_val val_array_get [lang| $arr] [lang| $i])\n \n | `([lang| $arr[$i] := $v]) => `(trm_app val_array_set [lang| $arr] [lang| $i] [lang| $v])\n | `([lang| mkarr $n:lang $v:lang]) => `(trm_val val_array_make [lang| $n] [lang| $v])" }, { "name": "macro_rules | `($x βˆ— $y) => `(binop% HStar.hStar $x $y)", "content": "macro_rules | `($x βˆ— $y) => `(binop% HStar.hStar $x $y)\n\n inductive trm : Type where\n | trm_val : val -> trm\n | trm_var : var -> trm\n | trm_fun : var -> trm -> trm\n | trm_fix : var -> var -> trm -> trm\n | trm_app : trm -> trm -> trm\n | trm_seq : trm -> trm -> trm\n | trm_let : var -> trm -> trm -> trm\n | trm_if : trm -> trm -> trm -> trm\n | trm_for : var -> trm -> trm -> trm -> trm\n | trm_while : trm -> trm -> trm\n | trm_ref : var β†’ trm β†’ trm β†’ trm\n | trm_alloc : var β†’ trm β†’ trm β†’ trm\n\n inductive val : Type where\n | val_unit : val\n | val_bool : Bool β†’ val\n | val_int : Int β†’ val\n | val_real : ℝ β†’ val\n | val_loc : loc β†’ val\n | val_prim : prim β†’ val\n | val_fun : var -> trm -> val\n | val_fix : var -> var -> trm -> val\n | val_uninit : val\n | val_error : val" }, { "name": "prim", "content": "inductive prim where\n \n | val_get : prim\n | val_set : prim\n \n | val_neg : prim\n | val_opp : prim\n | val_eq : prim\n | val_add : prim\n | val_neq : prim\n | val_sub : prim\n | val_mul : prim\n | val_div : prim\n | val_mod : prim\n \n | val_le : prim\n | val_lt : prim\n | val_ge : prim\n | val_gt : prim\n | val_ptr_add : prim" }, { "name": "var", "content": "abbrev var := String" }, { "name": "loc", "content": "abbrev loc := Nat" }, { "name": "hProp", "content": "def hProp := heap -> Prop" }, { "name": "heap", "content": "abbrev heap := Heap.heap val" }, { "name": "Heap.heap", "content": "abbrev Heap.heap (val : Type) := Finmap (Ξ» _ : loc ↦ val)" }, { "name": "eval", "content": "inductive eval : state β†’ trm β†’ (val β†’ state β†’ Prop) -> Prop where\n | eval_val : forall s v Q,\n Q v s ->\n eval s (trm_val v) Q\n | eval_fun : forall s x t1 Q,\n Q (val_fun x t1) s ->\n eval s (trm_fun x t1) Q\n | eval_fix : forall s f x t1 Q,\n Q (val_fix f x t1) s ->\n eval s (trm_fix f x t1) Q\n | eval_app_arg1 : forall s1 t1 t2 Q1 Q,\n Β¬ trm_is_val t1 ->\n eval s1 t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> eval s2 (trm_app v1 t2) Q) ->\n eval s1 (trm_app t1 t2) Q\n | eval_app_arg2 : forall s1 (v1 : val) t2 Q1 Q,\n Β¬ trm_is_val t2 ->\n eval s1 t2 Q1 ->\n (forall v2 s2, Q1 v2 s2 -> eval s2 (trm_app v1 v2) Q) ->\n eval s1 (trm_app v1 t2) Q\n | eval_app_fun : forall s1 v1 (v2 :val) x t1 Q,\n v1 = val_fun x t1 ->\n eval s1 (subst x v2 t1) Q ->\n eval s1 (trm_app v1 v2) Q\n | eval_app_fix : forall s (v1 v2 : val) f x t1 Q,\n v1 = val_fix f x t1 ->\n eval s (subst x v2 (subst f v1 t1)) Q ->\n eval s (trm_app v1 v2) Q\n | eval_seq : forall Q1 s t1 t2 Q,\n eval s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> eval s2 t2 Q) ->\n eval s (trm_seq t1 t2) Q\n | eval_let : forall Q1 s x t1 t2 Q,\n eval s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> eval s2 (subst x v1 t2) Q) ->\n eval s (trm_let x t1 t2) Q\n | eval_if : forall s (b : Bool) t1 t2 Q,\n eval s (if b then t1 else t2) Q ->\n eval s (trm_if (val_bool b) t1 t2) Q\n | eval_unop : forall op s v1 P Q,\n evalunop op v1 P ->\n purepostin s P Q ->\n eval s (trm_app op v1) Q\n | eval_binop : forall op s (v1 v2 : val) P Q,\n evalbinop op v1 v2 P ->\n purepostin s P Q ->\n eval s (trm_app (trm_app op v1) v2) Q\n | eval_ref : forall s x t1 t2 (Q Q₁ : val β†’ state β†’ Prop),\n eval s t1 Q₁ β†’\n (βˆ€ v1 s1, Q₁ v1 s1 β†’ βˆ€ p βˆ‰ s1,\n eval (s1.insert p v1) (subst x p t2) fun v s ↦ Q v (s.erase p)) β†’\n eval s (trm_ref x t1 t2) Q\n | eval_get : forall s p Q,\n p ∈ s ->\n Q (read_state p s) s ->\n eval s (trm_app val_get (val_loc p)) Q\n | eval_set : forall s p v Q,\n v = trm_val v' ->\n p ∈ s ->\n Q val_unit (Finmap.insert p v' s) ->\n eval s (trm_app (trm_app val_set (val_loc p)) v) Q\n | eval_alloc_arg : forall s Q₁ Q,\n Β¬ trm_is_val t1 β†’\n eval s t1 Q₁ β†’\n (βˆ€ v' s', Q₁ v' s' β†’ eval s' (trm_alloc x v' t2) Q) β†’\n eval s (trm_alloc x t1 t2) Q\n | eval_alloc : forall (sa : state) (n : β„€) Q,\n n β‰₯ 0 β†’\n (βˆ€ (p : loc) (sb : state),\n sb = conseq (make_list n.natAbs val_uninit) p β†’\n p β‰  null β†’\n Finmap.Disjoint sa sb β†’\n eval (sb βˆͺ sa) (subst x p t2) fun v s ↦ Q v (s \\ sb)) β†’\n eval sa (trm_alloc x n t2) Q\n \n \n \n \n \n \n \n \n | eval_for (n₁ nβ‚‚ : Int) (Q : val -> state -> Prop) :\n eval s (if (n₁ < nβ‚‚) then\n (trm_seq (subst x n₁ t₁) (trm_for x (val_int (n₁ + 1)) nβ‚‚ t₁))\n else val_unit) Q ->\n eval s (trm_for x n₁ nβ‚‚ t₁) Q\n | eval_while (t₁ tβ‚‚ : trm) (Q : val -> state -> Prop) :\n eval s t₁ Q₁ ->\n (βˆ€ s v, Q₁ v s -> eval s (trm_if v (trm_seq tβ‚‚ (trm_while t₁ tβ‚‚)) val_unit) Q) ->\n eval s (trm_while t₁ tβ‚‚) Q" }, { "name": "HStar", "content": "class HStar (Ξ± : Type u) (Ξ² : Type v) (Ξ³ : outParam (Type w)) where\n \n hStar : Ξ± β†’ Ξ² β†’ Ξ³" }, { "name": "subst", "content": "def subst (y : var) (v' : val) (t : trm) : trm :=\n \n let if_y_eq x t1 t2 := if x = y then t1 else t2\n match t with\n | trm_val v => trm_val v\n | trm_var x => if_y_eq x (trm_val v') t\n | trm_fun x t1 => trm_fun x (if_y_eq x t1 (subst y v' t1))\n | trm_fix f x t1 => trm_fix f x (if_y_eq f t1 (if_y_eq x t1 (subst y v' t1)))\n | trm_app t1 t2 => trm_app (subst y v' t1) (subst y v' t2)\n | trm_seq t1 t2 => trm_seq (subst y v' t1) (subst y v' t2)\n | trm_let x t1 t2 => trm_let x (subst y v' t1) (if_y_eq x t2 (subst y v' t2))\n | trm_if t0 t1 t2 => trm_if (subst y v' t0) (subst y v' t1) (subst y v' t2)\n | trm_for x t1 t2 t3 => trm_for x (subst y v' t1) (subst y v' t2) (if_y_eq x t3 (subst y v' t3))\n | trm_while t1 t2 => trm_while (subst y v' t1) (subst y v' t2)\n | trm_ref x t1 t2 => trm_ref x (subst y v' t1) (if_y_eq x t2 (subst y v' t2))\n | trm_alloc x t1 t2 => trm_alloc x (subst y v' t1) (if_y_eq x t2 (subst y v' t2))" }, { "name": "qimpl", "content": "def qimpl {A} (Q1 Q2 : A β†’ hProp) : Prop :=\n forall (v:A), Q1 v ==> Q2 v" }, { "name": "himpl", "content": "abbrev himpl (H1 H2 : hProp) : Prop :=\n forall h, H1 h -> H2 h" }, { "name": "step", "content": "inductive step : state β†’ trm β†’ state β†’ trm β†’ Prop where\n\n \n | step_seq_ctx : forall s1 s2 t1 t1' t2,\n step s1 t1 s2 t1' β†’\n step s1 (trm_seq t1 t2) s2 (trm_seq t1' t2)\n | step_let_ctx : forall s1 s2 x t1 t1' t2,\n step s1 t1 s2 t1' β†’\n step s1 (trm_let x t1 t2) s2 (trm_let x t1' t2)\n | step_app_arg_1 : forall s1 s2 t1 t1' t2,\n step s1 t1 s2 t1' β†’\n step s1 (trm_app t1 t2) s2 (trm_app t1' t2)\n | step_app_arg2 : forall s1 s2 v1 t2 t2',\n step s1 t2 s2 t2' β†’\n step s1 (trm_app v1 t2) s2 (trm_app v1 t2')\n\n \n | step_fun : forall s x t1,\n step s (trm_fun x t1) s (val_fun x t1)\n | step_fix : forall s f x t1,\n step s (trm_fix f x t1) s (val_fix f x t1)\n | step_app_fun : forall s v1 v2 x t1,\n v1 = val_fun x t1 β†’\n v2 = trm_val v2' β†’\n step s (trm_app v1 v2) s (subst x v2' t1)\n | step_app_fix : forall s v1 v2 f x t1,\n v1 = val_fix f x t1 β†’\n v2 = trm_val v2' β†’\n step s (trm_app v1 v2) s (subst x v2' (subst f v1 t1))\n | step_if : forall s b t1 t2,\n step s (trm_if (val_bool b) t1 t2) s (if b then t1 else t2)\n | step_seq : forall s t2 v1,\n step s (trm_seq v1 t2) s t2\n | step_let : forall s x t2 v1,\n v1 = trm_val v1' β†’\n step s (trm_let x v1 t2) s (subst x v1' t2)\n\n \n | step_neg : forall s b,\n step s (trm_app val_neg (val_bool b)) s (val_bool (Β¬ b))\n | step_opp : forall s n,\n step s (trm_app val_opp (val_int n)) s (val_int (- n))\n \n \n \n\n \n | step_eq : forall s v1 v2,\n step s (trm_app (trm_app val_eq v1) v2) s (val_bool (is_true (v1 = v2)))\n | step_neq : forall s v1 v2,\n step s (trm_app (trm_app val_neq v1) v2) s (val_bool (is_true (v1 β‰  v2)))\n | step_add : forall s n1 n2,\n step s (trm_app (trm_app val_add (val_int n1)) (val_int n2)) s\n (val_int (n1 + n2))\n | step_sub : forall s n1 n2,\n step s (trm_app (trm_app val_sub (val_int n1)) (val_int n2)) s\n (val_int (n1 - n2))\n | step_mul : forall s n1 n2,\n step s (trm_app (trm_app val_mul (val_int n1)) (val_int n2)) s\n (val_int (n1 * n2))\n | step_div : forall s n1 n2,\n n2 β‰  0 β†’\n step s (trm_app (trm_app val_div (val_int n1)) (val_int n2)) s\n (n1 / n2)\n | step_mod : forall s n1 n2,\n n2 β‰  0 β†’\n step s (trm_app (trm_app val_mod (val_int n1)) (val_int n2)) s\n (n1 % n2)\n | step_le : forall s n1 n2,\n step s (trm_app (trm_app val_le (val_int n1)) (val_int n2)) s\n (val_bool (n1 <= n2))\n | step_lt : forall s n1 n2,\n step s (trm_app (trm_app val_lt (val_int n1)) (val_int n2)) s\n (val_bool (n1 < n2))\n | step_ge : forall s n1 n2,\n step s (trm_app (trm_app val_ge (val_int n1)) (val_int n2)) s\n (val_bool (n1 >= n2))\n | step_gt : forall s n1 n2,\n step s (trm_app (trm_app val_gt (val_int n1)) (val_int n2)) s\n (val_bool (n1 > n2))\n | step_ptr_add : forall s p1 p2 n,\n (p2:β„€) = (p1:loc) + n β†’\n step s (trm_app (trm_app val_ptr_add (val_loc p1)) (val_int n)) s\n (val_loc (Int.toNat p2))\n\n \n | step_ref : forall s v p,\n Β¬ p ∈ s β†’\n v = trm_val v' β†’\n step s (trm_app val_ref v) (Finmap.insert p v' s) (val_loc p)\n | step_get : forall s p,\n p ∈ s β†’\n step s (trm_app val_get (val_loc p)) s (read_state p s)\n | step_set : forall s p v,\n p ∈ s ->\n v = trm_val v' β†’\n step s (trm_app (trm_app val_set (val_loc p)) v)\n (Finmap.insert p v' s) val_unit\n | step_free : forall s p,\n p ∈ s β†’\n step s (trm_app val_free (val_loc p)) (Finmap.erase p s) val_unit\n\nsyntax ident : lang" }, { "name": "HWand", "content": "class HWand (Ξ± : Type u) (Ξ² : Type v) (Ξ³ : outParam (Type w)) where\n \n hWand : Ξ± β†’ Ξ² β†’ Ξ³" }, { "name": "purepostin", "content": "def purepostin (s : state) (P : val β†’ Prop) (Q : val β†’ state β†’ Prop) : Prop :=\n \n forall v, P v β†’ Q v s" }, { "name": "state", "content": "abbrev state := Finmap (Ξ» _ : loc ↦ val)" }, { "name": "tohProp", "content": "abbrev tohProp (h : heap -> Prop) : hProp := h" }, { "name": "ofhProp", "content": "abbrev ofhProp (h : val -> hProp) : val -> heap -> Prop := h" }, { "name": "hforall", "content": "def hforall {A} (J : A β†’ hProp) : hProp :=\n fun h => forall x, J x h" }, { "name": "hempty", "content": "def hempty : hProp :=\n fun h => (h = βˆ…)" }, { "name": "hpure", "content": "def hpure (P : Prop) : hProp :=\n hexists (fun (_ : P) => emp)" }, { "name": "hexists", "content": "def hexists {A} (J : A β†’ hProp) : hProp :=\n fun h => exists x, J x h" }, { "name": "infixr:51 \" ==> \" => himpl", "content": "infixr:51 \" ==> \" => himpl" }, { "name": "infixr:51 \" ===> \" => qimpl", "content": "infixr:51 \" ===> \" => qimpl" }, { "name": "notation:max \"emp\" => hempty", "content": "notation:max \"emp\" => hempty" }, { "name": "infixr:55 \" βˆ— \" => HStar.hStar", "content": "infixr:55 \" βˆ— \" => HStar.hStar" }, { "name": "notation:max \"⌜\" P \"⌝\" => hpure P", "content": "notation:max \"⌜\" P \"⌝\" => hpure P" }, { "name": "infixr:55 \" -βˆ— \" => HWand.hWand", "content": "infixr:55 \" -βˆ— \" => HWand.hWand" }, { "name": "fun", "content": "notation \"funloc\" p \"↦\" H =>\n fun (r : val) ↦ hexists (fun p ↦ ⌜r = val_loc p⌝ βˆ— H)" } ]
[ { "name": "Int.le_induction_down", "module": "Mathlib.Data.Int.Init" }, { "name": "if_pos", "module": "Init.Core" } ]
[ { "name": "eval_conseq", "content": "lemma eval_conseq s t Q1 Q2 :\n eval s t Q1 β†’\n Q1 ===> Q2 β†’\n eval s t Q2" }, { "name": "qstarE", "content": "lemma qstarE Ξ± (Q1 : Ξ± β†’ hProp) (H : hProp):\n Q1 βˆ— H = fun x => Q1 x βˆ— H" }, { "name": "eval_frame", "content": "lemma eval_frame (h1 h2 : state) t (Q : val -> hProp) :\n eval h1 t (ofhProp Q) β†’\n Finmap.Disjoint h1 h2 β†’\n eval (h1 βˆͺ h2) t (Q βˆ— (tohProp (fun h ↦ h = h2)))" }, { "name": "qwand_cancel", "content": "lemma qwand_cancel A (Q1 Q2 : A β†’ hProp) :\n Q1 βˆ— (Q1 -βˆ— Q2) ===> Q2" }, { "name": "qwand_equiv", "content": "lemma qwand_equiv H A (Q1 Q2 : A β†’ hProp) :\n H ==> (Q1 -βˆ— Q2) ↔ (Q1 βˆ— H) ===> Q2" }, { "name": "hstar_hforall", "content": "lemma hstar_hforall A (J : A β†’ hProp) H :\n (hforall J) βˆ— H ==> hforall (J βˆ— H)" }, { "name": "hstar_comm", "content": "lemma hstar_comm H1 H2 :\n H1 βˆ— H2 = H2 βˆ— H1" }, { "name": "hprop_op_comm", "content": "lemma hprop_op_comm (op : hProp β†’ hProp β†’ hProp) :\n (forall H1 H2, op H1 H2 ==> op H2 H1) β†’\n (forall H1 H2, op H1 H2 = op H2 H1)" }, { "name": "himpl_antisym", "content": "lemma himpl_antisym H1 H2:\n (H1 ==> H2) β†’ (H2 ==> H1) β†’ (H1 = H2)" }, { "name": "hstar_inv", "content": "lemma hstar_inv (H1 H2 : hProp) h:\n (H1 βˆ— H2) h β†’\n exists h1 h2, H1 h1 ∧ H2 h2 ∧ Finmap.Disjoint h1 h2 ∧ h = h1 βˆͺ h2" }, { "name": "himpl_hstar_trans_l", "content": "lemma himpl_hstar_trans_l H1 H2 H3 H4 :\n H1 ==> H2 β†’\n H2 βˆ— H3 ==> H4 β†’\n H1 βˆ— H3 ==> H4" }, { "name": "himpl_hforall_l", "content": "lemma himpl_hforall_l A (x : A) (J : A β†’ hProp) H :\n (J x ==> H) β†’\n (hforall J) ==> H" }, { "name": "himpl_hforall_r", "content": "lemma himpl_hforall_r A (J : A β†’ hProp) H :\n (forall x, H ==> J x) β†’\n H ==> (hforall J)" }, { "name": "hwand_equiv", "content": "lemma hwand_equiv H0 H1 H2 :\n (H0 ==> H1 -βˆ— H2) ↔ (H1 βˆ— H0 ==> H2)" }, { "name": "hstar_assoc", "content": "lemma hstar_assoc H1 H2 H3 :\n (H1 βˆ— H2) βˆ— H3 = H1 βˆ— (H2 βˆ— H3)" }, { "name": "himpl_hstar_hpure_l", "content": "lemma himpl_hstar_hpure_l P H H' :\n (P β†’ H ==> H') β†’\n (⌜P⌝ βˆ— H) ==> H'" }, { "name": "hstar_hpure_l", "content": "lemma hstar_hpure_l P H h :\n (⌜P⌝ βˆ— H) h = (P ∧ H h)" }, { "name": "hstar_hempty_l", "content": "lemma hstar_hempty_l H :\n emp βˆ— H = H" }, { "name": "hempty_inv", "content": "lemma hempty_inv h :\n emp h β†’ h = βˆ…" }, { "name": "hstar_hexists", "content": "lemma hstar_hexists A (J : A β†’ hProp) H :\n (hexists J) βˆ— H = hexists (fun x => (J x) βˆ— H)" }, { "name": "himpl_hempty_hpure", "content": "lemma himpl_hempty_hpure P :\n P β†’ emp ==> ⌜P⌝" }, { "name": "himpl_hexists_r", "content": "lemma himpl_hexists_r A (x : A) H (J : A β†’ hProp) :\n (H ==> J x) β†’\n H ==> (hexists J)" }, { "name": "hwandE", "content": "lemma hwandE :\n H1 -βˆ— H2 = hexists (fun H0 => H0 βˆ— hpure ((H1 βˆ— H0) ==> H2))" }, { "name": "himpl_frame_r", "content": "lemma himpl_frame_r H1 H2 H2' :\n H2 ==> H2' β†’\n (H1 βˆ— H2) ==> (H1 βˆ— H2')" }, { "name": "hstar_hempty_r", "content": "lemma hstar_hempty_r H :\n H βˆ— emp = H" }, { "name": "himpl_hexists_l", "content": "lemma himpl_hexists_l A H (J : A β†’ hProp) :\n (forall x, J x ==> H) β†’ (hexists J) ==> H" }, { "name": "qwandE", "content": "lemma qwandE Ξ± (Q1 Q2 : Ξ± β†’ hProp) :\n Q1 -βˆ— Q2 = hforall (fun x => (Q1 x) -βˆ— (Q2 x))" }, { "name": "hwand_cancel", "content": "lemma hwand_cancel H1 H2 :\n H1 βˆ— (H1 -βˆ— H2) ==> H2" }, { "name": "himpl_hwand_r_inv", "content": "lemma himpl_hwand_r_inv H1 H2 H3 :\n H1 ==> (H2 -βˆ— H3) β†’\n H2 βˆ— H1 ==> H3" }, { "name": "himpl_trans", "content": "lemma himpl_trans H2 H1 H3 :\n (H1 ==> H2) β†’ (H2 ==> H3) β†’ (H1 ==> H3)" }, { "name": "himpl_trans_r", "content": "lemma himpl_trans_r H2 H1 H3:\n H2 ==> H3 β†’ H1 ==> H2 β†’ H1 ==> H3" } ]
[ { "name": "Theories.wp", "content": "def wp (t : trm) (Q : val β†’ hProp) : hProp :=\n fun s ↦ eval s t Q" } ]
[ { "name": "Theories.wp_conseq", "content": "lemma wp_conseq t Q1 Q2 :\n Q1 ===> Q2 β†’\n wp t Q1 ==> wp t Q2" }, { "name": "Theories.wp_frame", "content": "lemma wp_frame t H Q :\n (wp t Q) βˆ— H ==> wp t (Q βˆ— H)" }, { "name": "Theories.wp_ramified", "content": "lemma wp_ramified t (Q1 Q2 : val -> hProp) :\n (wp t Q1) βˆ— (Q1 -βˆ— Q2) ==> (wp t Q2)" }, { "name": "Theories.wp_conseq_frame", "content": "lemma wp_conseq_frame t H (Q1 Q2 : val -> hProp) :\n Q1 βˆ— H ===> Q2 β†’\n (wp t Q1) βˆ— H ==> (wp t Q2)" } ]
import Lean import Mathlib.Data.Finmap import Mathlib.Data.List.Indexes import SPLean.Common.State import SPLean.Common.Util import SPLean.Theories.HProp import SPLean.Theories.XSimp import SPLean.Theories.XChange import SPLean.Theories.SepLog import SPLean.Theories.WPUtil open trm val prim namespace Theories def wp (t : trm) (Q : val β†’ hProp) : hProp := fun s ↦ eval s t Q section tactics open Lean Elab Tactic section xapp end xapp end tactics open AList section funs_fixs_eval_like variable (xs : List var) (vs : List val) (t : trm) (v0 : trm) (heqt : t = trm_apps v0 ts) (hconv : trms_to_vals ts = vs) (hform : var_funs xs vs.length) -- NOTE: can be relaxed to `vs.length ≀ xs.length` variable (f : var) (hf : f βˆ‰ xs) end funs_fixs_eval_like end Theories open Theories open Lean.Elab.Tactic in
lemma xfor_lemma (z n : β„€) (x : var) (I : β„€ -> hProp) : z <= n -> (H ==> H' βˆ— I z) -> (βˆ€ i, z <= i -> i < n -> I i ==> wp (subst x i F1) (fun _ => I (i + 1))) -> ((fun _ => I n βˆ— H') ===> Q) -> H ==> wp (trm_for x z n F1) Q :=
:= by move=> ? hini hstep hfin xchange hini apply himpl_trans_r; apply wp_conseq_frame=> // xsimp move: z hfin {hini}=> z; apply Int.le_induction_down { move=> ?? ?? constructor=> /==;constructor; aesop } move=> j ? ih step hfin move=> ??; constructor=> /==; srw if_pos; rotate_left; omega constructor { apply step <;> try omega sdone } move=> _ > ?; apply ih=> // * apply step <;> omega
9
90
false
Framework
414
Theories.isubst_insert
lemma isubst_insert (al : ctx) x v t : isubst (al.insert x v) t = subst x v (isubst (al.erase x) t)
splean
SPLean/Theories/WP1.lean
[ "import SPLean.Theories.XChange", "import Mathlib.Data.List.Indexes", "import SPLean.Theories.XSimp", "import SPLean.Theories.SepLog", "import Mathlib.Data.Finmap", "import SPLean.Common.State", "import SPLean.Theories.HProp", "import SPLean.Common.Util", "import Lean", "import SPLean.Theories.WPUtil" ]
[ { "name": "AList", "module": "Mathlib.Data.List.AList" }, { "name": "String", "module": "Init.Prelude" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "AList.erase", "module": "Mathlib.Data.List.AList" }, { "name": "AList.lookup", "module": "Mathlib.Data.List.AList" }, { "name": "t", "module": "Ssreflect.IntroPats" }, { "name": "move", "module": "Ssreflect.Basic" }, { "name": "scase", "module": "Ssreflect.Elim" }, { "name": "AList.entries", "module": "Mathlib.Data.List.AList" }, { "name": "AList.insert", "module": "Mathlib.Data.List.AList" }, { "name": "DecidableEq", "module": "Init.Prelude" }, { "name": "List", "module": "Init.Prelude" }, { "name": "List.kerase", "module": "Mathlib.Data.List.Sigma" }, { "name": "List.kinsert", "module": "Mathlib.Data.List.Sigma" }, { "name": "srw", "module": "Ssreflect.Rewrite" }, { "name": "AList.keys", "module": "Mathlib.Data.List.AList" }, { "name": "List.keys", "module": "Mathlib.Data.List.Sigma" } ]
[ { "name": "syntax \"fun\" ident+ \" => \" lang : lang", "content": "syntax \"fun\" ident+ \" => \" lang : lang\n\nsyntax \"if \" lang \"then \" lang \"end \" : lang\n\nsyntax \" := \" : bop\n\nsyntax \"let\" ident \" := \" lang \" in\" ppDedent(ppLine lang) : lang\n\nsyntax \"⟨\" term \"⟩\" : lang\n\nsyntax \"⟨\" term \":\" term \"⟩\" : lang" }, { "name": "macro_rules", "content": "macro_rules\n | `([lang| ()]) => `(trm_val (val_unit))\n | `([lang| $n:num]) => `(trm_val (val_int $n))\n | `([lang| $t1 $t2]) => `(trm_app [lang| $t1] [lang| $t2])\n | `([lang| if $t1 then $t2 else $t3]) => `(trm_if [lang| $t1] [lang| $t2] [lang| $t3])\n | `([lang| if $t1 then $t2 end]) => `(trm_if [lang| $t1] [lang| $t2] (trm_val val_unit))\n | `([lang| let $x := $t1:lang in $t2:lang]) =>\n `(trm_let $(%x) [lang| $t1] [lang| $t2])\n | `([lang| ref $x := $t1:lang in $t2:lang]) =>\n `(trm_ref $(%x) [lang| $t1] [lang| $t2])\n | `([lang| alloc $t1:lang as $x in $t2:lang]) =>\n `(trm_alloc $(%x) [lang| $t1] [lang| $t2])\n | `([lang| $t1 ; $t2]) => `(trm_seq [lang| $t1] [lang| $t2])\n | `([lang| fun_ $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(trm_funs [ $xs,* ] [lang| $t])\n | `([lang| fun $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(val_funs [ $xs,* ] [lang| $t])\n | `([lang| fix_ $f $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(trm_fixs $(%f) [ $xs,* ] [lang| $t])\n | `([lang| fix $f $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(val_fixs $(%f) [ $xs,* ] [lang| $t])\n \n | `([lang| free $t]) => `(trm_val (val_prim val_free) [lang| $t])\n | `([lang| not $t]) => `(trm_val (val_prim val_not) [lang| $t])\n \n | `([lang| !$t]) => `(trm_val val_get [lang| $t])\n | `([lang| $t1 := $t2]) => `(trm_val val_set [lang| $t1] [lang| $t2])\n | `([lang| $t1 + $t2]) => `(trm_val val_add [lang| $t1] [lang| $t2])\n | `([lang| $t1 * $t2]) => `(trm_val val_mul [lang| $t1] [lang| $t2])\n | `([lang| $t1 - $t2]) => `(trm_val val_sub [lang| $t1] [lang| $t2])\n | `([lang| $t1 / $t2]) => `(trm_val val_div [lang| $t1] [lang| $t2])\n | `([lang| $t1 < $t2]) => `(trm_val val_lt [lang| $t1] [lang| $t2])\n | `([lang| $t1 > $t2]) => `(trm_val val_gt [lang| $t1] [lang| $t2])\n | `([lang| $t1 <= $t2]) => `(trm_val val_le [lang| $t1] [lang| $t2])\n | `([lang| $t1 >= $t2]) => `(trm_val val_ge [lang| $t1] [lang| $t2])\n | `([lang| -$t]) => `(trm_val val_opp [lang| $t])\n | `([lang| $t1 = $t2]) => `(trm_val val_eq [lang| $t1] [lang| $t2])\n | `([lang| $t1 != $t2]) => `(trm_val val_neq [lang| $t1] [lang| $t2])\n | `([lang| $t1 mod $t2]) => `(trm_val val_mod [lang| $t1] [lang| $t2])\n | `([lang| $t1 ++ $t2]) => `(trm_val val_ptr_add [lang| $t1] [lang| $t2])\n | `([lang| ($t)]) => `([lang| $t])\n | `([lang| ⟨$t : $tp⟩]) => `(trm_val (($t : $tp)))\n | `([lang| for $x in [$n1 : $n2] { $t } ]) =>\n `(trm_for $(%x) [lang| $n1] [lang| $n2] [lang| $t])\n | `([lang| while $c:lang { $t:lang } ]) =>\n `(trm_while [lang| $c] [lang| $t] )" }, { "name": "macro_rules", "content": "macro_rules\n | `([lang| len $p]) => `(trm_val val_array_length [lang| $p])\n | `([lang| $arr[$i] ]) => `(trm_val val_array_get [lang| $arr] [lang| $i])\n \n | `([lang| $arr[$i] := $v]) => `(trm_app val_array_set [lang| $arr] [lang| $i] [lang| $v])\n | `([lang| mkarr $n:lang $v:lang]) => `(trm_val val_array_make [lang| $n] [lang| $v])\n\n inductive trm : Type where\n | trm_val : val -> trm\n | trm_var : var -> trm\n | trm_fun : var -> trm -> trm\n | trm_fix : var -> var -> trm -> trm\n | trm_app : trm -> trm -> trm\n | trm_seq : trm -> trm -> trm\n | trm_let : var -> trm -> trm -> trm\n | trm_if : trm -> trm -> trm -> trm\n | trm_for : var -> trm -> trm -> trm -> trm\n | trm_while : trm -> trm -> trm\n | trm_ref : var β†’ trm β†’ trm β†’ trm\n | trm_alloc : var β†’ trm β†’ trm β†’ trm\n\n inductive val : Type where\n | val_unit : val\n | val_bool : Bool β†’ val\n | val_int : Int β†’ val\n | val_real : ℝ β†’ val\n | val_loc : loc β†’ val\n | val_prim : prim β†’ val\n | val_fun : var -> trm -> val\n | val_fix : var -> var -> trm -> val\n | val_uninit : val\n | val_error : val" }, { "name": "prim", "content": "inductive prim where\n \n | val_get : prim\n | val_set : prim\n \n | val_neg : prim\n | val_opp : prim\n | val_eq : prim\n | val_add : prim\n | val_neq : prim\n | val_sub : prim\n | val_mul : prim\n | val_div : prim\n | val_mod : prim\n \n | val_le : prim\n | val_lt : prim\n | val_ge : prim\n | val_gt : prim\n | val_ptr_add : prim" }, { "name": "var", "content": "abbrev var := String" }, { "name": "loc", "content": "abbrev loc := Nat" }, { "name": "subst", "content": "def subst (y : var) (v' : val) (t : trm) : trm :=\n \n let if_y_eq x t1 t2 := if x = y then t1 else t2\n match t with\n | trm_val v => trm_val v\n | trm_var x => if_y_eq x (trm_val v') t\n | trm_fun x t1 => trm_fun x (if_y_eq x t1 (subst y v' t1))\n | trm_fix f x t1 => trm_fix f x (if_y_eq f t1 (if_y_eq x t1 (subst y v' t1)))\n | trm_app t1 t2 => trm_app (subst y v' t1) (subst y v' t2)\n | trm_seq t1 t2 => trm_seq (subst y v' t1) (subst y v' t2)\n | trm_let x t1 t2 => trm_let x (subst y v' t1) (if_y_eq x t2 (subst y v' t2))\n | trm_if t0 t1 t2 => trm_if (subst y v' t0) (subst y v' t1) (subst y v' t2)\n | trm_for x t1 t2 t3 => trm_for x (subst y v' t1) (subst y v' t2) (if_y_eq x t3 (subst y v' t3))\n | trm_while t1 t2 => trm_while (subst y v' t1) (subst y v' t2)\n | trm_ref x t1 t2 => trm_ref x (subst y v' t1) (if_y_eq x t2 (subst y v' t2))\n | trm_alloc x t1 t2 => trm_alloc x (subst y v' t1) (if_y_eq x t2 (subst y v' t2))" }, { "name": "fun", "content": "notation \"funloc\" p \"↦\" H =>\n fun (r : val) ↦ hexists (fun p ↦ ⌜r = val_loc p⌝ βˆ— H)" } ]
[ { "name": "List.kerase_cons_ne", "module": "Mathlib.Data.List.Sigma" }, { "name": "List.kerase_kerase", "module": "Mathlib.Data.List.Sigma" }, { "name": "AList.perm_erase", "module": "Mathlib.Data.List.AList" }, { "name": "AList.perm_lookup", "module": "Mathlib.Data.List.AList" }, { "name": "AList.mem_keys", "module": "Mathlib.Data.List.AList" }, { "name": "List.eraseP_of_forall_not", "module": "Init.Data.List.Erase" }, { "name": "AList.erase_erase", "module": "Mathlib.Data.List.AList" }, { "name": "AList.lookup_erase_ne", "module": "Mathlib.Data.List.AList" }, { "name": "AList.lookup_insert_ne", "module": "Mathlib.Data.List.AList" }, { "name": "congrArg", "module": "Init.Prelude" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "Theories.ctx", "content": "abbrev ctx := AList (fun _ : var ↦ val)" }, { "name": "Theories.isubst", "content": "def isubst (E : ctx) (t : trm) : trm :=\n match t with\n | trm_val v =>\n v\n | trm_var x =>\n match lookup x E with\n | none => t\n | some v => v\n | trm_fun x t1 =>\n trm_fun x (isubst (erase x E) t1)\n | trm_fix f x t1 =>\n trm_fix f x (isubst (erase x (erase f E)) t1)\n | trm_if t0 t1 t2 =>\n trm_if (isubst E t0) (isubst E t1) (isubst E t2)\n | trm_seq t1 t2 =>\n trm_seq (isubst E t1) (isubst E t2)\n | trm_let x t1 t2 =>\n trm_let x (isubst E t1) (isubst (erase x E) t2)\n | trm_ref x t1 t2 =>\n trm_ref x (isubst E t1) (isubst (erase x E) t2)\n | trm_alloc x t1 t2 =>\n trm_alloc x (isubst E t1) (isubst (erase x E) t2)\n | trm_app t1 t2 =>\n trm_app (isubst E t1) (isubst E t2)\n | trm_for x n1 n2 t =>\n trm_for x (isubst E n1) (isubst E n2) (isubst (erase x E) t)\n | trm_while c t =>\n trm_while (isubst E c) (isubst E t)" } ]
[ { "name": "Theories.AList.erase_insert_cancel", "content": "lemma AList.erase_insert_cancel {Ξ± : Type u} {Ξ² : Ξ± β†’ Type v} [DecidableEq Ξ±] (a : Ξ±) (b : Ξ² a) (l : AList Ξ²) :\n (AList.erase a (AList.insert a b l)).entries.Perm (AList.erase a l).entries" }, { "name": "Theories.AList.erase_insert_swap", "content": "lemma AList.erase_insert_swap {Ξ± : Type u} {Ξ² : Ξ± β†’ Type v} [DecidableEq Ξ±] (a a' : Ξ±) (b : Ξ² a) (l : AList Ξ²) :\n a β‰  a' β†’ (AList.erase a' (AList.insert a b l)).entries.Perm (AList.insert a b (AList.erase a' l)).entries" }, { "name": "Theories.AList.erase_noop", "content": "lemma AList.erase_noop {Ξ± : Type u} {Ξ² : Ξ± β†’ Type v} [DecidableEq Ξ±] (a : Ξ±) (l : AList Ξ²) :\n a βˆ‰ l β†’ (AList.erase a l).entries.Perm l.entries" }, { "name": "Theories.AList.erase_twice", "content": "lemma AList.erase_twice {Ξ± : Type u} {Ξ² : Ξ± β†’ Type v} [DecidableEq Ξ±] (a : Ξ±) (l : AList Ξ²) :\n (AList.erase a (AList.erase a l)).entries.Perm (AList.erase a l).entries" }, { "name": "Theories.isubst_perm", "content": "lemma isubst_perm {al al'} t (hp : al.entries.Perm al'.entries) :\n isubst al t = isubst al' t" } ]
import Lean import Mathlib.Data.Finmap import Mathlib.Data.List.Indexes import SPLean.Common.State import SPLean.Common.Util import SPLean.Theories.HProp import SPLean.Theories.XSimp import SPLean.Theories.XChange import SPLean.Theories.SepLog import SPLean.Theories.WPUtil open trm val prim namespace Theories section tactics open Lean Elab Tactic section xapp end xapp end tactics open AList abbrev ctx := AList (fun _ : var ↦ val) def isubst (E : ctx) (t : trm) : trm := match t with | trm_val v => v | trm_var x => match lookup x E with | none => t | some v => v | trm_fun x t1 => trm_fun x (isubst (erase x E) t1) | trm_fix f x t1 => trm_fix f x (isubst (erase x (erase f E)) t1) | trm_if t0 t1 t2 => trm_if (isubst E t0) (isubst E t1) (isubst E t2) | trm_seq t1 t2 => trm_seq (isubst E t1) (isubst E t2) | trm_let x t1 t2 => trm_let x (isubst E t1) (isubst (erase x E) t2) | trm_ref x t1 t2 => trm_ref x (isubst E t1) (isubst (erase x E) t2) | trm_alloc x t1 t2 => trm_alloc x (isubst E t1) (isubst (erase x E) t2) | trm_app t1 t2 => trm_app (isubst E t1) (isubst E t2) | trm_for x n1 n2 t => trm_for x (isubst E n1) (isubst E n2) (isubst (erase x E) t) | trm_while c t => trm_while (isubst E c) (isubst E t)
lemma isubst_insert (al : ctx) x v t : isubst (al.insert x v) t = subst x v (isubst (al.erase x) t) :=
:= by move: al induction t using (subst.induct x v)=> > all_goals (simp [isubst, subst]=> //) all_goals (split_ands=> //) all_goals ((try split_ifs=> //) <;> (try subst_eqs)) all_goals (try srw (fun t => isubst_perm t (AList.erase_twice x al))) all_goals (try srw (fun v t => isubst_perm t (AList.erase_insert_cancel x v al))) all_goals (try solve | srw (fun x' hneq v t => isubst_perm t (AList.erase_insert_swap x x' v al hneq)) <;> (try solve | aesop) ; -- `aesop` does autorewrite here (try simp [*]) apply congrArg ; srw AList.erase_erase) all_goals (try apply isubst_perm) { rename_i x' ; by_cases h : x' = x { subst x' ; simp [subst] } { srw AList.lookup_insert_ne // AList.lookup_erase_ne // scase: (lookup x' al)=> //= simp [subst, h] } } { apply AList.perm_erase trans ; apply AList.erase_insert_cancel ; symm ; apply AList.erase_twice } { srw [2]AList.erase_erase [1]AList.erase_erase apply AList.perm_erase trans ; apply AList.erase_insert_cancel ; symm ; apply AList.erase_twice } { rename_i ih ha hb srw [3]AList.erase_erase [2]AList.erase_erase -ih apply isubst_perm trans on_goal 2=> apply AList.erase_insert_swap ; aesop apply AList.perm_erase apply AList.erase_insert_swap ; aesop }
5
42
false
Framework
415
Perm.kmerge
theorem Perm.kmerge {l₁ lβ‚‚ l₃ lβ‚„ : List (Sigma (fun _ : loc => val))} (nd₁ : l₁.NodupKeys) /- nd₁ is necessary -/ (nd₃ : l₃.NodupKeys) (p₁₂ : l₁.Perm lβ‚‚) (p₃₄ : l₃.Perm lβ‚„) : (kmerge l₁ l₃).Perm $ kmerge lβ‚‚ lβ‚„
splean
SPLean/Common/Heap.lean
[ "import Mathlib.Algebra.BigOperators.Group.Finset", "import Mathlib.Algebra.BigOperators.Intervals", "import Mathlib.Algebra.Group.Basic", "import Ssreflect.Lang", "import Mathlib.Data.Finmap", "import Mathlib.Order.Interval.Finset.Basic", "import Mathlib.Data.Int.Interval", "import Lean", "import Batteries.Data.List.Perm" ]
[ { "name": "Nat", "module": "Init.Prelude" }, { "name": "List", "module": "Init.Prelude" }, { "name": "List.NodupKeys", "module": "Mathlib.Data.List.Sigma" }, { "name": "List.Perm", "module": "Init.Data.List.Basic" }, { "name": "List.keys", "module": "Mathlib.Data.List.Sigma" }, { "name": "move", "module": "Ssreflect.Basic" }, { "name": "srw", "module": "Ssreflect.Rewrite" }, { "name": "Sigma", "module": "Init.Core" }, { "name": "elim", "module": "Ssreflect.Elim" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "Option.merge", "module": "Init.Data.Option.Basic" }, { "name": "List.kerase", "module": "Mathlib.Data.List.Sigma" }, { "name": "scase", "module": "Ssreflect.Elim" }, { "name": "DecidableEq", "module": "Init.Prelude" } ]
[ { "name": "...", "content": "..." } ]
[ { "name": "List.NodupKeys.kerase", "module": "Mathlib.Data.List.Sigma" }, { "name": "List.kerase_cons_eq", "module": "Mathlib.Data.List.Sigma" }, { "name": "List.kerase_cons_ne", "module": "Mathlib.Data.List.Sigma" }, { "name": "List.mem_keys_of_mem", "module": "Mathlib.Data.List.Sigma" }, { "name": "List.NodupKeys.nodup", "module": "Mathlib.Data.List.Sigma" }, { "name": "List.Perm.map", "module": "Init.Data.List.Perm" }, { "name": "List.Perm.mem_iff", "module": "Init.Data.List.Perm" }, { "name": "List.perm_dlookup", "module": "Mathlib.Data.List.Sigma" }, { "name": "List.perm_ext_iff_of_nodup", "module": "Batteries.Data.List.Perm" }, { "name": "List.perm_nodupKeys", "module": "Mathlib.Data.List.Sigma" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "loc", "content": "abbrev loc := Nat" }, { "name": "kmerge1", "content": "private def kmerge1 (l : loc) (v : val) (lβ‚‚ : List (Sigma (fun _ : loc => val))) : val :=\n match lβ‚‚.dlookup l with\n | .some v' => v + v'\n | _ => v" }, { "name": "kmerge", "content": "@[simp]\ndef kmerge : List (Sigma (fun _ : loc => val)) β†’ List (Sigma (fun _ : loc => val)) β†’ List (Sigma (fun _ : loc => val))\n | [], lβ‚‚ => lβ‚‚\n | s :: l₁, lβ‚‚ =>\n (if s.1 ∈ lβ‚‚.keys then\n ⟨s.1, kmerge1 s.1 s.2 lβ‚‚βŸ© :: kmerge l₁ (lβ‚‚.kerase s.1)\n else s :: kmerge l₁ lβ‚‚)" } ]
[ { "name": "List.kerase_noterased", "content": "lemma List.kerase_noterased {Ξ± : Type u} {Ξ² : Ξ± β†’ Type v} [DecidableEq Ξ±] (l : List (Sigma Ξ²))\n (a a' : Ξ±) (hneq : a β‰  a') (b : Ξ² a) : ⟨a, b⟩ ∈ l ↔ ⟨a, b⟩ ∈ List.kerase a' l" }, { "name": "kmerge_mem2", "content": "lemma kmerge_mem2 (l₁ lβ‚‚ : List (Sigma (fun _ : loc => val))) (nd₁ : l₁.NodupKeys) (ndβ‚‚ : lβ‚‚.NodupKeys) -- necessary\n (a : Sigma (fun _ : loc => val)) : a ∈ (kmerge l₁ lβ‚‚) ↔\n if a.1 ∈ l₁.keys\n then (if a.1 ∈ lβ‚‚.keys then Option.merge (Β· + Β·) (l₁.dlookup a.1) (lβ‚‚.dlookup a.1) = .some a.2 else a ∈ l₁)\n else a ∈ lβ‚‚" }, { "name": "kmerge_NodupKeys", "content": "lemma kmerge_NodupKeys (l₁ lβ‚‚ : List (Sigma (fun _ : loc => val))) (nd₁ : l₁.NodupKeys) (ndβ‚‚ : lβ‚‚.NodupKeys) : (kmerge l₁ lβ‚‚).NodupKeys" } ]
import Lean import Mathlib.Data.Finmap import Mathlib.Algebra.Group.Basic import Mathlib.Algebra.BigOperators.Group.Finset import Mathlib.Algebra.BigOperators.Intervals import Mathlib.Data.Int.Interval import Mathlib.Order.Interval.Finset.Basic import Batteries.Data.List.Perm import Ssreflect.Lang open Classical abbrev loc := Nat section Option.merge variable {Ξ± : Type u} (f : Ξ± β†’ Ξ± β†’ Ξ±) end Option.merge open PartialCommMonoid (valid) section variable {val : Type} [PartialCommMonoid val] -- [Inhabited val] local notation "heap" => Heap.heap val private def kmerge1 (l : loc) (v : val) (lβ‚‚ : List (Sigma (fun _ : loc => val))) : val := match lβ‚‚.dlookup l with | .some v' => v + v' | _ => v @[simp] def kmerge : List (Sigma (fun _ : loc => val)) β†’ List (Sigma (fun _ : loc => val)) β†’ List (Sigma (fun _ : loc => val)) | [], lβ‚‚ => lβ‚‚ | s :: l₁, lβ‚‚ => (if s.1 ∈ lβ‚‚.keys then ⟨s.1, kmerge1 s.1 s.2 lβ‚‚βŸ© :: kmerge l₁ (lβ‚‚.kerase s.1) else s :: kmerge l₁ lβ‚‚)
theorem Perm.kmerge {l₁ lβ‚‚ l₃ lβ‚„ : List (Sigma (fun _ : loc => val))} (nd₁ : l₁.NodupKeys) /- nd₁ is necessary -/ (nd₃ : l₃.NodupKeys) (p₁₂ : l₁.Perm lβ‚‚) (p₃₄ : l₃.Perm lβ‚„) : (kmerge l₁ l₃).Perm $ kmerge lβ‚‚ lβ‚„ :=
:= by have ndβ‚‚ := nd₁ rw [List.perm_nodupKeys p₁₂] at ndβ‚‚ have ndβ‚„ := nd₃ rw [List.perm_nodupKeys p₃₄] at ndβ‚„ rw [List.perm_ext_iff_of_nodup] <;> try (apply List.NodupKeys.nodup ; apply kmerge_NodupKeys=> //) move=> [] l v srw !kmerge_mem2 // (List.perm_dlookup _ nd₁ ndβ‚‚ p₁₂) // (List.perm_dlookup _ nd₃ ndβ‚„ p₃₄) dsimp [List.keys] srw (List.Perm.mem_iff (List.Perm.map Sigma.fst p₁₂)) (List.Perm.mem_iff (List.Perm.map Sigma.fst p₃₄)) (List.Perm.mem_iff p₁₂) (List.Perm.mem_iff p₃₄)
3
30
false
Framework
416
validInter_hop_distr_l
lemma validInter_hop_distr_l (h₁ hβ‚‚ h₃ : heap) : (h₁ +Κ° hβ‚‚) βŠ₯Κ° h₃ -> (h₁ βŠ₯Κ° h₃ ∧ hβ‚‚ βŠ₯Κ° h₃)
splean
SPLean/Common/Heap.lean
[ "import Mathlib.Algebra.BigOperators.Group.Finset", "import Mathlib.Algebra.BigOperators.Intervals", "import Mathlib.Algebra.Group.Basic", "import SPLean/Theories/HProp.lean", "import Ssreflect.Lang", "import Mathlib.Data.Finmap", "import Mathlib.Order.Interval.Finset.Basic", "import Mathlib.Data.Int.Interval", "import Lean", "import Batteries.Data.List.Perm" ]
[ { "name": "Nat", "module": "Init.Prelude" }, { "name": "List", "module": "Init.Prelude" }, { "name": "Sigma", "module": "Init.Core" }, { "name": "AList", "module": "Mathlib.Data.List.AList" }, { "name": "scase", "module": "Ssreflect.Elim" }, { "name": "Finmap", "module": "Mathlib.Data.Finmap" }, { "name": "Finmap.liftOnβ‚‚", "module": "Mathlib.Data.Finmap" }, { "name": "move", "module": "Ssreflect.Basic" }, { "name": "srw", "module": "Ssreflect.Rewrite" }, { "name": "String", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "Finmap.lookup", "module": "Mathlib.Data.Finmap" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "Option.merge", "module": "Init.Data.Option.Basic" }, { "name": "HAdd", "module": "Init.Prelude" }, { "name": "HAdd.hAdd", "module": "Init.Prelude" }, { "name": "instHAdd", "module": "Init.Prelude" }, { "name": "sdone", "module": "Ssreflect.Done" } ]
[ { "name": "heap", "content": "abbrev heap := Heap.heap val\n\n inductive val : Type where\n | val_unit : val\n | val_bool : Bool β†’ val\n | val_int : Int β†’ val\n | val_real : ℝ β†’ val\n | val_loc : loc β†’ val\n | val_prim : prim β†’ val\n | val_fun : var -> trm -> val\n | val_fix : var -> var -> trm -> val\n | val_uninit : val\n | val_error : val" }, { "name": "prim", "content": "inductive prim where\n \n | val_get : prim\n | val_set : prim\n \n | val_neg : prim\n | val_opp : prim\n | val_eq : prim\n | val_add : prim\n | val_neq : prim\n | val_sub : prim\n | val_mul : prim\n | val_div : prim\n | val_mod : prim\n \n | val_le : prim\n | val_lt : prim\n | val_ge : prim\n | val_gt : prim\n | val_ptr_add : prim\n\n inductive trm : Type where\n | trm_val : val -> trm\n | trm_var : var -> trm\n | trm_fun : var -> trm -> trm\n | trm_fix : var -> var -> trm -> trm\n | trm_app : trm -> trm -> trm\n | trm_seq : trm -> trm -> trm\n | trm_let : var -> trm -> trm -> trm\n | trm_if : trm -> trm -> trm -> trm\n | trm_for : var -> trm -> trm -> trm -> trm\n | trm_while : trm -> trm -> trm\n | trm_ref : var β†’ trm β†’ trm β†’ trm\n | trm_alloc : var β†’ trm β†’ trm β†’ trm" }, { "name": "scoped instance : PartialCommMonoid val where", "content": "scoped instance : PartialCommMonoid val where\n add := add\n add_assoc := by admit /- proof elided -/" }, { "name": "add", "content": "@[simp]\nabbrev add : val -> val -> val\n | .val_int i, .val_int j => val.val_int (i + j)\n | _, _ => val.val_unit" }, { "name": "evalExact", "content": "inductive evalExact : state β†’ trm β†’ (val β†’ state β†’ Prop) -> Prop where\n | val : forall s v,\n evalExact s (trm_val v) (fun v' s' ↦ v' = v ∧ s' = s)\n | fun : forall s x t1,\n evalExact s (trm_fun x t1) (fun v' s' ↦ v' = val_fun x t1 ∧ s' = s)\n | fix : forall s f x t1,\n evalExact s (trm_fix f x t1) (fun v' s' ↦ v' = val_fix f x t1 ∧ s' = s)\n | app_arg1 : forall s1 t1 t2 Q1 Q,\n Β¬ trm_is_val t1 ->\n evalExact s1 t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 (trm_app v1 t2) Q) ->\n evalExact s1 (trm_app t1 t2) Q\n | app_arg2 : forall s1 (v1 : val) t2 Q1 Q,\n Β¬ trm_is_val t2 ->\n evalExact s1 t2 Q1 ->\n (forall v2 s2, Q1 v2 s2 -> evalExact s2 (trm_app v1 v2) Q) ->\n evalExact s1 (trm_app v1 t2) Q\n | app_fun : forall s1 v1 (v2 :val) x t1 Q,\n v1 = val_fun x t1 ->\n evalExact s1 (subst x v2 t1) Q ->\n evalExact s1 (trm_app v1 v2) Q\n | app_fix : forall s (v1 v2 : val) f x t1 Q,\n v1 = val_fix f x t1 ->\n evalExact s (subst x v2 (subst f v1 t1)) Q ->\n evalExact s (trm_app v1 v2) Q\n | seq : forall Q1 s t1 t2 Q,\n evalExact s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 t2 Q) ->\n evalExact s (trm_seq t1 t2) Q\n | let : forall Q1 s x t1 t2 Q,\n evalExact s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 (subst x v1 t2) Q) ->\n evalExact s (trm_let x t1 t2) Q\n | if : forall s (b : Bool) t1 t2 Q,\n evalExact s (if b then t1 else t2) Q ->\n evalExact s (trm_if (val_bool b) t1 t2) Q\n | unop : forall op s v1 P,\n evalunop op v1 P ->\n evalExact s (trm_app op v1) (purepost s P)\n | binop : forall op s (v1 v2 : val) P,\n evalbinop op v1 v2 P ->\n evalExact s (trm_app (trm_app op v1) v2) (purepost s P)\n | ref : forall s x t1 t2 Q Q₁,\n evalExact s t1 Q₁ β†’\n (βˆ€ v1 s1, Q₁ v1 s1 β†’ βˆ€ p βˆ‰ s1,\n evalExact (s1.insert p v1) (subst x p t2) fun v s ↦ Q v (s.erase p)) β†’\n evalExact s (trm_ref x t1 t2) Q\n | get : forall s p,\n p ∈ s ->\n evalExact s (trm_app val_get (val_loc p))\n (fun v' s' ↦ v' = read_state p s ∧ s' = s)\n | set : forall s p v,\n v = trm_val v' ->\n p ∈ s ->\n evalExact s (trm_app (trm_app val_set (val_loc p)) v)\n (fun v'' s' ↦ v'' = val_unit ∧ s' = s.insert p v')\n | alloc_arg : forall s Q₁ Q,\n Β¬ trm_is_val t1 β†’\n evalExact s t1 Q₁ β†’\n (βˆ€ v' s', Q₁ v' s' β†’ evalExact s' (trm_alloc x v' t2) Q) β†’\n evalExact s (trm_alloc x t1 t2) Q\n | alloc : forall (sa : state) (n : β„€) Q,\n n β‰₯ 0 β†’\n (βˆ€ (p : loc) (sb : state),\n sb = conseq (make_list n.natAbs val_uninit) p β†’\n p β‰  null β†’\n Finmap.Disjoint sa sb β†’\n evalExact (sb βˆͺ sa) (subst x p t2) fun v s ↦ Q v (s \\ sb)) β†’\n evalExact sa (trm_alloc x n t2) Q\n \n \n \n \n \n \n | for (n₁ nβ‚‚ : Int) (Q : val -> state -> Prop) :\n evalExact s (if (n₁ < nβ‚‚) then\n (trm_seq (subst x n₁ t₁) (trm_for x (val_int (n₁ + 1)) nβ‚‚ t₁))\n else val_unit) Q ->\n evalExact s (trm_for x n₁ nβ‚‚ t₁) Q\n | while (t₁ tβ‚‚ : trm) (Q Q₁ : val -> state -> Prop) :\n evalExact s t₁ Q₁ ->\n (βˆ€ s v, Q₁ v s -> evalExact s (trm_if v (trm_seq tβ‚‚ (trm_while t₁ tβ‚‚)) val_unit) Q) ->\n evalExact s (trm_while t₁ tβ‚‚) Q" }, { "name": "valid", "content": "@[simp]\nabbrev valid : val -> Prop\n | .val_int _ => True\n | _ => False" }, { "name": "PartialCommMonoid", "content": "class PartialCommMonoid (Ξ± : Type) extends AddCommSemigroup Ξ± where\n valid : Ξ± -> Prop\n valid_add : βˆ€ x, valid (x + y) -> valid x\n add_valid : βˆ€ x y, valid x -> valid y -> valid (x + y)" }, { "name": "scoped instance inst : PartialCommMonoidWRT val add valid wh", "content": "scoped instance inst : PartialCommMonoidWRT val add valid where\n validE := by admit /- proof elided -/" }, { "name": "AddCommMonoidWRT", "content": "class AddCommMonoidWRT (Ξ± : Type) (add' : semiOutParam $ Ξ± -> Ξ± -> Ξ±) extends AddCommMonoid Ξ± where\n addE : (Β· + Β·) = add'" }, { "name": "scoped instance : PartialCommMonoid val where", "content": "scoped instance : PartialCommMonoid val where\n add := add\n add_assoc := by admit /- proof elided -/" }, { "name": "add", "content": "@[simp]\nabbrev add : val -> val -> val\n | .val_bool i, .val_bool j => val.val_bool (i || j)\n | _, _ => val.val_unit" }, { "name": "valid", "content": "@[simp]\nabbrev valid : val -> Prop\n | .val_bool _ => True\n | _ => False" }, { "name": "scoped instance : PartialCommMonoid val where", "content": "scoped instance : PartialCommMonoid val where\n add := add\n add_assoc := by admit /- proof elided -/" }, { "name": "add", "content": "@[simp]\nabbrev add : val -> val -> val\n | .val_real i, .val_real j => val.val_real (i + j)\n | _, _ => val.val_unit" }, { "name": "valid", "content": "@[simp]\nabbrev valid : val -> Prop\n | .val_real _ => True\n | _ => False" } ]
[ { "name": "Finmap.mem_iff", "module": "Mathlib.Data.Finmap" }, { "name": "add_assoc", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "add_comm", "module": "Mathlib.Algebra.Group.Defs" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "loc", "content": "abbrev loc := Nat" }, { "name": "var", "content": "abbrev var := String" }, { "name": "Heap.heap", "content": "abbrev Heap.heap (val : Type) := Finmap (Ξ» _ : loc ↦ val)" }, { "name": "PartialCommMonoid", "content": "class PartialCommMonoid (Ξ± : Type) extends AddCommSemigroup Ξ± where\n valid : Ξ± -> Prop\n valid_add : βˆ€ x, valid (x + y) -> valid x\n add_valid : βˆ€ x y, valid x -> valid y -> valid (x + y)" }, { "name": "kmerge1", "content": "private def kmerge1 (l : loc) (v : val) (lβ‚‚ : List (Sigma (fun _ : loc => val))) : val :=\n match lβ‚‚.dlookup l with\n | .some v' => v + v'\n | _ => v" }, { "name": "kmerge", "content": "@[simp]\ndef kmerge : List (Sigma (fun _ : loc => val)) β†’ List (Sigma (fun _ : loc => val)) β†’ List (Sigma (fun _ : loc => val))\n | [], lβ‚‚ => lβ‚‚\n | s :: l₁, lβ‚‚ =>\n (if s.1 ∈ lβ‚‚.keys then\n ⟨s.1, kmerge1 s.1 s.2 lβ‚‚βŸ© :: kmerge l₁ (lβ‚‚.kerase s.1)\n else s :: kmerge l₁ lβ‚‚)" }, { "name": "AList.merge", "content": "noncomputable def AList.merge (h₁ hβ‚‚ : AList (fun _ : loc => val)) : AList (fun _ : loc => val) :=\n ⟨kmerge h₁.entries hβ‚‚.entries, by admit /- proof elided -/\n ⟩" }, { "name": "Heap.add", "content": "noncomputable def Heap.add (h₁ hβ‚‚ : heap) : heap :=\n Finmap.liftOnβ‚‚ h₁ hβ‚‚ (fun h₁ hβ‚‚ => (h₁.merge hβ‚‚).toFinmap) (by admit /- proof elided -/\n )" }, { "name": "validInter", "content": "def validInter (h₁ hβ‚‚ : heap) : Prop :=\n βˆ€ l ∈ h₁, l ∈ hβ‚‚ -> ((h₁ +Κ° hβ‚‚).lookup l).any (valid (Ξ± := val))" } ]
[]
import Lean import Mathlib.Data.Finmap import Mathlib.Algebra.Group.Basic import Mathlib.Algebra.BigOperators.Group.Finset import Mathlib.Algebra.BigOperators.Intervals import Mathlib.Data.Int.Interval import Mathlib.Order.Interval.Finset.Basic import Batteries.Data.List.Perm import Ssreflect.Lang open Classical abbrev loc := Nat abbrev var := String section Option.merge variable {Ξ± : Type u} (f : Ξ± β†’ Ξ± β†’ Ξ±) end Option.merge abbrev Heap.heap (val : Type) := Finmap (Ξ» _ : loc ↦ val) class PartialCommMonoid (Ξ± : Type) extends AddCommSemigroup Ξ± where valid : Ξ± -> Prop valid_add : βˆ€ x, valid (x + y) -> valid x add_valid : βˆ€ x y, valid x -> valid y -> valid (x + y) open PartialCommMonoid (valid) section variable {val : Type} [PartialCommMonoid val] -- [Inhabited val] local notation "heap" => Heap.heap val private def kmerge1 (l : loc) (v : val) (lβ‚‚ : List (Sigma (fun _ : loc => val))) : val := match lβ‚‚.dlookup l with | .some v' => v + v' | _ => v @[simp] def kmerge : List (Sigma (fun _ : loc => val)) β†’ List (Sigma (fun _ : loc => val)) β†’ List (Sigma (fun _ : loc => val)) | [], lβ‚‚ => lβ‚‚ | s :: l₁, lβ‚‚ => (if s.1 ∈ lβ‚‚.keys then ⟨s.1, kmerge1 s.1 s.2 lβ‚‚βŸ© :: kmerge l₁ (lβ‚‚.kerase s.1) else s :: kmerge l₁ lβ‚‚) noncomputable def AList.merge (h₁ hβ‚‚ : AList (fun _ : loc => val)) : AList (fun _ : loc => val) := ⟨kmerge h₁.entries hβ‚‚.entries, by admit /- proof elided -/ ⟩ noncomputable def Heap.add (h₁ hβ‚‚ : heap) : heap := Finmap.liftOnβ‚‚ h₁ hβ‚‚ (fun h₁ hβ‚‚ => (h₁.merge hβ‚‚).toFinmap) (by admit /- proof elided -/ ) infixr:55 " +Κ° " => Heap.add def validInter (h₁ hβ‚‚ : heap) : Prop := βˆ€ l ∈ h₁, l ∈ hβ‚‚ -> ((h₁ +Κ° hβ‚‚).lookup l).any (valid (Ξ± := val)) infixr:55 " βŠ₯Κ° " => validInter
lemma validInter_hop_distr_l (h₁ hβ‚‚ h₃ : heap) : (h₁ +Κ° hβ‚‚) βŠ₯Κ° h₃ -> (h₁ βŠ₯Κ° h₃ ∧ hβ‚‚ βŠ₯Κ° h₃) :=
:= by simp [validInter] move=> h ⟨|⟩ l /[tac (specialize h l)]-- | [] h1 h2 l [] /[tac (specialize h1 l; specialize h2 l)] ⟩ all_goals (move=> /[dup] hin1 /[swap] /[dup] hin2) all_goals (srw [1]Finmap.mem_iff=> []v3 hv3 ; srw Finmap.mem_iff=> []v hv) all_goals (srw hv hv3 at h ⊒) all_goals (dsimp [Option.merge]; try solve | aesop) { move: h; scase: (Finmap.lookup l hβ‚‚)=> > //== all_goals (simp [Option.merge]=> //) srw add_assoc (add_comm _ v3) -add_assoc have hq := fun y => PartialCommMonoid.valid_add (v + v3) (y := y) aesop } { move: h; scase: (Finmap.lookup l h₁)=> > //== all_goals (simp [Option.merge]=> //) srw add_assoc [1]add_comm have hq := fun y => PartialCommMonoid.valid_add (v + v3) (y := y) aesop }
6
31
false
Framework
417
xwhile_inv_basic_lemma
lemma xwhile_inv_basic_lemma (I : Bool -> Ξ± -> hProp) R -- (F1 F2 : formula) : WellFounded R -> -- structural F1 -> -- structural F2 -> (H ==> H' βˆ— βˆƒΚ° b a, I b a) -> (βˆ€ b X, I b X ==> wp F1 (fun bv => I b X βˆ— ⌜bv = b⌝)) -> (βˆ€ X, I true X ==> wp F2 (fun _ => βˆƒΚ° b X', ⌜R X' X⌝ βˆ— I b X')) -> H ==> wp (trm_while F1 F2) (fun _ => H' βˆ— βˆƒΚ° a, I false a)
splean
SPLean/Theories/WP1.lean
[ "import SPLean.Theories.XChange", "import Mathlib.Data.List.Indexes", "import SPLean.Theories.XSimp", "import SPLean.Theories.SepLog", "import Mathlib.Data.Finmap", "import SPLean.Common.State", "import SPLean.Theories.HProp", "import SPLean.Common.Util", "import Lean", "import SPLean.Theories.WPUtil" ]
[ { "name": "String", "module": "Init.Prelude" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "Finmap", "module": "Mathlib.Data.Finmap" }, { "name": "BEq", "module": "Init.Prelude" }, { "name": "List", "module": "Init.Prelude" }, { "name": "Repr", "module": "Init.Data.Repr" }, { "name": "Vector", "module": "Init.Data.Vector.Basic" }, { "name": "bool", "module": "Init.Control.Basic" }, { "name": "ite", "module": "Init.Prelude" }, { "name": "Computation", "module": "Mathlib.Data.Seq.Computation" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "Max", "module": "Init.Prelude" }, { "name": "Max.max", "module": "Init.Prelude" }, { "name": "WellFounded", "module": "Init.WF" }, { "name": "move", "module": "Ssreflect.Basic" }, { "name": "sapply", "module": "Ssreflect.ApplyIn" }, { "name": "srw", "module": "Ssreflect.Rewrite" }, { "name": "t", "module": "Ssreflect.IntroPats" }, { "name": "sby", "module": "Ssreflect.Done" }, { "name": "Finmap.Disjoint", "module": "Mathlib.Data.Finmap" } ]
[ { "name": "notation:max \"emp\" => hempty", "content": "notation:max \"emp\" => hempty\n\nsyntax \"fun\" ident+ \" => \" lang : lang\n\nsyntax \"⟨\" term \"⟩\" : lang\n\nsyntax \"⟨\" term \":\" term \"⟩\" : lang" }, { "name": "macro \"xsimp\" : tactic =>", "content": "macro \"xsimp\" : tactic =>\n `(tactic| (\n xsimp_start\n repeat xsimp_step\n try rev_pure\n try hide_mvars\n try hsimp\n rotate_left\n\n ))" }, { "name": "macro \"xif\" : tactic => do", "content": "macro \"xif\" : tactic => do\n `(tactic|\n (xseq_xlet_if_needed; xstruct_if_needed; apply xif_lemma))" }, { "name": "macro \"xif\" : tactic => `(tactic| (xwp; xif))", "content": "macro \"xif\" : tactic => `(tactic| (xwp; xif))\n\nsyntax \" := \" : bop" }, { "name": "macro \"xstruct\" : tactic => do", "content": "macro \"xstruct\" : tactic => do\n `(tactic| apply xstruct_lemma)" }, { "name": "macro \"xval\" : tactic => do", "content": "macro \"xval\" : tactic => do\n `(tactic| (xstruct_if_needed; apply xval_lemma))" }, { "name": "macro \"xval\" : tactic => `(tactic| (xwp; xval))", "content": "macro \"xval\" : tactic => `(tactic| (xwp; xval))" }, { "name": "macro \"xapp\" : tactic =>", "content": "macro \"xapp\" : tactic =>\n `(tactic|\n (xapp_nosubst;\n try xapp_try_subst\n first\n | done\n | all_goals try srw wp_equiv\n all_goals try subst_vars))" }, { "name": "notation:max \"⌜\" P \"⌝\" => hpure P", "content": "notation:max \"⌜\" P \"⌝\" => hpure P" }, { "name": "macro \"xwp\" : tactic =>", "content": "macro \"xwp\" : tactic =>\n `(tactic|\n (intros\n first | apply xwp_lemma_fix; rfl\n | apply xwp_lemma_fun; rfl))" }, { "name": "macro \"xwp\" : tactic =>", "content": "macro \"xwp\" : tactic =>\n `(tactic|\n (intros\n try srw trm_apps1\n srw ?trm_apps2\n first\n \n | (apply xwp_lemma_funs; rfl; rfl; rfl; sdone)=> //\n | apply wp_of_wpgen\n all_goals try simp [wpgen, subst, isubst, subst, trm_apps, AList.lookup, List.dlookup]))" }, { "name": "macro \"xseq\" : tactic => do", "content": "macro \"xseq\" : tactic => do\n `(tactic| (xstruct_if_needed; apply xseq_lemma))" }, { "name": "macro \"xchange\" l:term : tactic =>", "content": "macro \"xchange\" l:term : tactic =>\n `(tactic| (xchange_core $l; xsimp))" }, { "name": "macro \"βˆƒΚ°\" xs:Lean.explicitBinders \", \" b:term : term => Lea", "content": "macro \"βˆƒΚ°\" xs:Lean.explicitBinders \", \" b:term : term => Lean.expandExplicitBinders ``hexists xs b" }, { "name": "macro \"xpull\" : tactic =>", "content": "macro \"xpull\" : tactic =>\n `(tactic| (\n xpull_start\n repeat' xsimp_step\n try rev_pure\n hsimp\n ))" }, { "name": "macro_rules", "content": "macro_rules\n | `([lang| ()]) => `(trm_val (val_unit))\n | `([lang| $n:num]) => `(trm_val (val_int $n))\n | `([lang| $t1 $t2]) => `(trm_app [lang| $t1] [lang| $t2])\n | `([lang| if $t1 then $t2 else $t3]) => `(trm_if [lang| $t1] [lang| $t2] [lang| $t3])\n | `([lang| if $t1 then $t2 end]) => `(trm_if [lang| $t1] [lang| $t2] (trm_val val_unit))\n | `([lang| let $x := $t1:lang in $t2:lang]) =>\n `(trm_let $(%x) [lang| $t1] [lang| $t2])\n | `([lang| ref $x := $t1:lang in $t2:lang]) =>\n `(trm_ref $(%x) [lang| $t1] [lang| $t2])\n | `([lang| alloc $t1:lang as $x in $t2:lang]) =>\n `(trm_alloc $(%x) [lang| $t1] [lang| $t2])\n | `([lang| $t1 ; $t2]) => `(trm_seq [lang| $t1] [lang| $t2])\n | `([lang| fun_ $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(trm_funs [ $xs,* ] [lang| $t])\n | `([lang| fun $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(val_funs [ $xs,* ] [lang| $t])\n | `([lang| fix_ $f $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(trm_fixs $(%f) [ $xs,* ] [lang| $t])\n | `([lang| fix $f $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(val_fixs $(%f) [ $xs,* ] [lang| $t])\n \n | `([lang| free $t]) => `(trm_val (val_prim val_free) [lang| $t])\n | `([lang| not $t]) => `(trm_val (val_prim val_not) [lang| $t])\n \n | `([lang| !$t]) => `(trm_val val_get [lang| $t])\n | `([lang| $t1 := $t2]) => `(trm_val val_set [lang| $t1] [lang| $t2])\n | `([lang| $t1 + $t2]) => `(trm_val val_add [lang| $t1] [lang| $t2])\n | `([lang| $t1 * $t2]) => `(trm_val val_mul [lang| $t1] [lang| $t2])\n | `([lang| $t1 - $t2]) => `(trm_val val_sub [lang| $t1] [lang| $t2])\n | `([lang| $t1 / $t2]) => `(trm_val val_div [lang| $t1] [lang| $t2])\n | `([lang| $t1 < $t2]) => `(trm_val val_lt [lang| $t1] [lang| $t2])\n | `([lang| $t1 > $t2]) => `(trm_val val_gt [lang| $t1] [lang| $t2])\n | `([lang| $t1 <= $t2]) => `(trm_val val_le [lang| $t1] [lang| $t2])\n | `([lang| $t1 >= $t2]) => `(trm_val val_ge [lang| $t1] [lang| $t2])\n | `([lang| -$t]) => `(trm_val val_opp [lang| $t])\n | `([lang| $t1 = $t2]) => `(trm_val val_eq [lang| $t1] [lang| $t2])\n | `([lang| $t1 != $t2]) => `(trm_val val_neq [lang| $t1] [lang| $t2])\n | `([lang| $t1 mod $t2]) => `(trm_val val_mod [lang| $t1] [lang| $t2])\n | `([lang| $t1 ++ $t2]) => `(trm_val val_ptr_add [lang| $t1] [lang| $t2])\n | `([lang| ($t)]) => `([lang| $t])\n | `([lang| ⟨$t : $tp⟩]) => `(trm_val (($t : $tp)))\n | `([lang| for $x in [$n1 : $n2] { $t } ]) =>\n `(trm_for $(%x) [lang| $n1] [lang| $n2] [lang| $t])\n | `([lang| while $c:lang { $t:lang } ]) =>\n `(trm_while [lang| $c] [lang| $t] )" }, { "name": "macro_rules", "content": "macro_rules\n | `([lang| len $p]) => `(trm_val val_array_length [lang| $p])\n | `([lang| $arr[$i] ]) => `(trm_val val_array_get [lang| $arr] [lang| $i])\n \n | `([lang| $arr[$i] := $v]) => `(trm_app val_array_set [lang| $arr] [lang| $i] [lang| $v])\n | `([lang| mkarr $n:lang $v:lang]) => `(trm_val val_array_make [lang| $n] [lang| $v])" }, { "name": "macro_rules", "content": "macro_rules\n | `({ $P }[$t:lang]{$v, $Q}) => `(triple [lang| $t] $P (fun $v => $Q))\n | `({ $P }[$t:lang]{$Q}) => `(triple [lang| $t] $P (fun _ => $Q))\n | `(WP[$t:lang]{$v, $Q}) => `(wp [lang| $t] (fun $v => $Q))\n | `(WP[$t:lang]{$Q}) => `(wp [lang| $t] (fun _ => $Q))" }, { "name": "macro_rules", "content": "macro_rules\n | `(tactic| xstep $(t)? ) => `(tactic| (xwp; xapp $(t)?))" }, { "name": "macro_rules | `($x βˆ— $y) => `(binop% HStar.hStar $x $y)", "content": "macro_rules | `($x βˆ— $y) => `(binop% HStar.hStar $x $y)\n\n inductive trm : Type where\n | trm_val : val -> trm\n | trm_var : var -> trm\n | trm_fun : var -> trm -> trm\n | trm_fix : var -> var -> trm -> trm\n | trm_app : trm -> trm -> trm\n | trm_seq : trm -> trm -> trm\n | trm_let : var -> trm -> trm -> trm\n | trm_if : trm -> trm -> trm -> trm\n | trm_for : var -> trm -> trm -> trm -> trm\n | trm_while : trm -> trm -> trm\n | trm_ref : var β†’ trm β†’ trm β†’ trm\n | trm_alloc : var β†’ trm β†’ trm β†’ trm\n\n inductive val : Type where\n | val_unit : val\n | val_bool : Bool β†’ val\n | val_int : Int β†’ val\n | val_real : ℝ β†’ val\n | val_loc : loc β†’ val\n | val_prim : prim β†’ val\n | val_fun : var -> trm -> val\n | val_fix : var -> var -> trm -> val\n | val_uninit : val\n | val_error : val" }, { "name": "prim", "content": "inductive prim where\n \n | val_get : prim\n | val_set : prim\n \n | val_neg : prim\n | val_opp : prim\n | val_eq : prim\n | val_add : prim\n | val_neq : prim\n | val_sub : prim\n | val_mul : prim\n | val_div : prim\n | val_mod : prim\n \n | val_le : prim\n | val_lt : prim\n | val_ge : prim\n | val_gt : prim\n | val_ptr_add : prim" }, { "name": "var", "content": "abbrev var := String" }, { "name": "loc", "content": "abbrev loc := Nat" }, { "name": "hProp", "content": "def hProp := heap -> Prop" }, { "name": "heap", "content": "abbrev heap := Heap.heap val" }, { "name": "Heap.heap", "content": "abbrev Heap.heap (val : Type) := Finmap (Ξ» _ : loc ↦ val)" }, { "name": "eval", "content": "inductive eval : state β†’ trm β†’ (val β†’ state β†’ Prop) -> Prop where\n | eval_val : forall s v Q,\n Q v s ->\n eval s (trm_val v) Q\n | eval_fun : forall s x t1 Q,\n Q (val_fun x t1) s ->\n eval s (trm_fun x t1) Q\n | eval_fix : forall s f x t1 Q,\n Q (val_fix f x t1) s ->\n eval s (trm_fix f x t1) Q\n | eval_app_arg1 : forall s1 t1 t2 Q1 Q,\n Β¬ trm_is_val t1 ->\n eval s1 t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> eval s2 (trm_app v1 t2) Q) ->\n eval s1 (trm_app t1 t2) Q\n | eval_app_arg2 : forall s1 (v1 : val) t2 Q1 Q,\n Β¬ trm_is_val t2 ->\n eval s1 t2 Q1 ->\n (forall v2 s2, Q1 v2 s2 -> eval s2 (trm_app v1 v2) Q) ->\n eval s1 (trm_app v1 t2) Q\n | eval_app_fun : forall s1 v1 (v2 :val) x t1 Q,\n v1 = val_fun x t1 ->\n eval s1 (subst x v2 t1) Q ->\n eval s1 (trm_app v1 v2) Q\n | eval_app_fix : forall s (v1 v2 : val) f x t1 Q,\n v1 = val_fix f x t1 ->\n eval s (subst x v2 (subst f v1 t1)) Q ->\n eval s (trm_app v1 v2) Q\n | eval_seq : forall Q1 s t1 t2 Q,\n eval s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> eval s2 t2 Q) ->\n eval s (trm_seq t1 t2) Q\n | eval_let : forall Q1 s x t1 t2 Q,\n eval s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> eval s2 (subst x v1 t2) Q) ->\n eval s (trm_let x t1 t2) Q\n | eval_if : forall s (b : Bool) t1 t2 Q,\n eval s (if b then t1 else t2) Q ->\n eval s (trm_if (val_bool b) t1 t2) Q\n | eval_unop : forall op s v1 P Q,\n evalunop op v1 P ->\n purepostin s P Q ->\n eval s (trm_app op v1) Q\n | eval_binop : forall op s (v1 v2 : val) P Q,\n evalbinop op v1 v2 P ->\n purepostin s P Q ->\n eval s (trm_app (trm_app op v1) v2) Q\n | eval_ref : forall s x t1 t2 (Q Q₁ : val β†’ state β†’ Prop),\n eval s t1 Q₁ β†’\n (βˆ€ v1 s1, Q₁ v1 s1 β†’ βˆ€ p βˆ‰ s1,\n eval (s1.insert p v1) (subst x p t2) fun v s ↦ Q v (s.erase p)) β†’\n eval s (trm_ref x t1 t2) Q\n | eval_get : forall s p Q,\n p ∈ s ->\n Q (read_state p s) s ->\n eval s (trm_app val_get (val_loc p)) Q\n | eval_set : forall s p v Q,\n v = trm_val v' ->\n p ∈ s ->\n Q val_unit (Finmap.insert p v' s) ->\n eval s (trm_app (trm_app val_set (val_loc p)) v) Q\n | eval_alloc_arg : forall s Q₁ Q,\n Β¬ trm_is_val t1 β†’\n eval s t1 Q₁ β†’\n (βˆ€ v' s', Q₁ v' s' β†’ eval s' (trm_alloc x v' t2) Q) β†’\n eval s (trm_alloc x t1 t2) Q\n | eval_alloc : forall (sa : state) (n : β„€) Q,\n n β‰₯ 0 β†’\n (βˆ€ (p : loc) (sb : state),\n sb = conseq (make_list n.natAbs val_uninit) p β†’\n p β‰  null β†’\n Finmap.Disjoint sa sb β†’\n eval (sb βˆͺ sa) (subst x p t2) fun v s ↦ Q v (s \\ sb)) β†’\n eval sa (trm_alloc x n t2) Q\n \n \n \n \n \n \n \n \n | eval_for (n₁ nβ‚‚ : Int) (Q : val -> state -> Prop) :\n eval s (if (n₁ < nβ‚‚) then\n (trm_seq (subst x n₁ t₁) (trm_for x (val_int (n₁ + 1)) nβ‚‚ t₁))\n else val_unit) Q ->\n eval s (trm_for x n₁ nβ‚‚ t₁) Q\n | eval_while (t₁ tβ‚‚ : trm) (Q : val -> state -> Prop) :\n eval s t₁ Q₁ ->\n (βˆ€ s v, Q₁ v s -> eval s (trm_if v (trm_seq tβ‚‚ (trm_while t₁ tβ‚‚)) val_unit) Q) ->\n eval s (trm_while t₁ tβ‚‚) Q" }, { "name": "HStar", "content": "class HStar (Ξ± : Type u) (Ξ² : Type v) (Ξ³ : outParam (Type w)) where\n \n hStar : Ξ± β†’ Ξ² β†’ Ξ³" }, { "name": "hpure", "content": "def hpure (P : Prop) : hProp :=\n hexists (fun (_ : P) => emp)" }, { "name": "hexists", "content": "def hexists {A} (J : A β†’ hProp) : hProp :=\n fun h => exists x, J x h" }, { "name": "hempty", "content": "def hempty : hProp :=\n fun h => (h = βˆ…)" }, { "name": "himpl", "content": "abbrev himpl (H1 H2 : hProp) : Prop :=\n forall h, H1 h -> H2 h" }, { "name": "qimpl", "content": "def qimpl {A} (Q1 Q2 : A β†’ hProp) : Prop :=\n forall (v:A), Q1 v ==> Q2 v" }, { "name": "purepostin", "content": "def purepostin (s : state) (P : val β†’ Prop) (Q : val β†’ state β†’ Prop) : Prop :=\n \n forall v, P v β†’ Q v s" }, { "name": "state", "content": "abbrev state := Finmap (Ξ» _ : loc ↦ val)" }, { "name": "tohProp", "content": "abbrev tohProp (h : heap -> Prop) : hProp := h" }, { "name": "ofhProp", "content": "abbrev ofhProp (h : val -> hProp) : val -> heap -> Prop := h" }, { "name": "infixr:51 \" ==> \" => himpl", "content": "infixr:51 \" ==> \" => himpl" }, { "name": "infixr:51 \" ===> \" => qimpl", "content": "infixr:51 \" ===> \" => qimpl" }, { "name": "notation:max \"emp\" => hempty", "content": "notation:max \"emp\" => hempty" }, { "name": "infixr:55 \" βˆ— \" => HStar.hStar", "content": "infixr:55 \" βˆ— \" => HStar.hStar" }, { "name": "notation:max \"⌜\" P \"⌝\" => hpure P", "content": "notation:max \"⌜\" P \"⌝\" => hpure P" }, { "name": "fun", "content": "notation \"funloc\" p \"↦\" H =>\n fun (r : val) ↦ hexists (fun p ↦ ⌜r = val_loc p⌝ βˆ— H)" } ]
[ { "name": "...", "module": "" } ]
[ { "name": "eval_conseq", "content": "lemma eval_conseq s t Q1 Q2 :\n eval s t Q1 β†’\n Q1 ===> Q2 β†’\n eval s t Q2" }, { "name": "qstarE", "content": "lemma qstarE Ξ± (Q1 : Ξ± β†’ hProp) (H : hProp):\n Q1 βˆ— H = fun x => Q1 x βˆ— H" }, { "name": "eval_frame", "content": "lemma eval_frame (h1 h2 : state) t (Q : val -> hProp) :\n eval h1 t (ofhProp Q) β†’\n Finmap.Disjoint h1 h2 β†’\n eval (h1 βˆͺ h2) t (Q βˆ— (tohProp (fun h ↦ h = h2)))" }, { "name": "hstar_comm", "content": "lemma hstar_comm H1 H2 :\n H1 βˆ— H2 = H2 βˆ— H1" }, { "name": "hprop_op_comm", "content": "lemma hprop_op_comm (op : hProp β†’ hProp β†’ hProp) :\n (forall H1 H2, op H1 H2 ==> op H2 H1) β†’\n (forall H1 H2, op H1 H2 = op H2 H1)" }, { "name": "himpl_antisym", "content": "lemma himpl_antisym H1 H2:\n (H1 ==> H2) β†’ (H2 ==> H1) β†’ (H1 = H2)" }, { "name": "hstar_inv", "content": "lemma hstar_inv (H1 H2 : hProp) h:\n (H1 βˆ— H2) h β†’\n exists h1 h2, H1 h1 ∧ H2 h2 ∧ Finmap.Disjoint h1 h2 ∧ h = h1 βˆͺ h2" }, { "name": "himpl_trans", "content": "lemma himpl_trans H2 H1 H3 :\n (H1 ==> H2) β†’ (H2 ==> H3) β†’ (H1 ==> H3)" } ]
[ { "name": "Theories.wp", "content": "def wp (t : trm) (Q : val β†’ hProp) : hProp :=\n fun s ↦ eval s t Q" } ]
[ { "name": "Theories.wp_conseq", "content": "lemma wp_conseq t Q1 Q2 :\n Q1 ===> Q2 β†’\n wp t Q1 ==> wp t Q2" }, { "name": "Theories.wp_frame", "content": "lemma wp_frame t H Q :\n (wp t Q) βˆ— H ==> wp t (Q βˆ— H)" } ]
import Lean import Mathlib.Data.Finmap import Mathlib.Data.List.Indexes import SPLean.Common.State import SPLean.Common.Util import SPLean.Theories.HProp import SPLean.Theories.XSimp import SPLean.Theories.XChange import SPLean.Theories.SepLog import SPLean.Theories.WPUtil open trm val prim namespace Theories def wp (t : trm) (Q : val β†’ hProp) : hProp := fun s ↦ eval s t Q section tactics open Lean Elab Tactic section xapp end xapp end tactics open AList section funs_fixs_eval_like variable (xs : List var) (vs : List val) (t : trm) (v0 : trm) (heqt : t = trm_apps v0 ts) (hconv : trms_to_vals ts = vs) (hform : var_funs xs vs.length) -- NOTE: can be relaxed to `vs.length ≀ xs.length` variable (f : var) (hf : f βˆ‰ xs) end funs_fixs_eval_like end Theories open Theories open Lean.Elab.Tactic in
lemma xwhile_inv_basic_lemma (I : Bool -> Ξ± -> hProp) R -- (F1 F2 : formula) : WellFounded R -> -- structural F1 -> -- structural F2 -> (H ==> H' βˆ— βˆƒΚ° b a, I b a) -> (βˆ€ b X, I b X ==> wp F1 (fun bv => I b X βˆ— ⌜bv = b⌝)) -> (βˆ€ X, I true X ==> wp F2 (fun _ => βˆƒΚ° b X', ⌜R X' X⌝ βˆ— I b X')) -> H ==> wp (trm_while F1 F2) (fun _ => H' βˆ— βˆƒΚ° a, I false a) :=
:= by move=> wf hini hf1 hf2 xchange hini=> b sR move: b apply WellFounded.induction wf sR=> X ih [] -- apply eval.eval_while -- unfold wpgen_while ; unfold_let ; xstruct ; xsimp=> [] sR hstep; rename_i wfR -- frame H' out, using `structural`? { xchange hf1 apply himpl_trans; rotate_left { srw hstar_comm; apply wp_frame } xsimp apply himpl_trans; rotate_left { move=> ? H apply eval.eval_while; apply H move=> > // } apply wp_conseq=> ? /=; xpull xwp; xif=> // _; xwp; xval; xsimp } -- move: sR -- apply himpl_trans; rotate_left -- { srw hstar_comm; apply wp_frame } -- xsimp apply himpl_trans; rotate_left { move=> ? H apply eval.eval_while; apply H move=> > // } xchange hf1 apply himpl_trans; apply wp_frame apply wp_conseq=> ? /==; srw qstarE /=; xpull xwp; xif=> // _ xwp; xseq; xapp hf2=> // ?? /ih; srw [2]hstar_comm //; sapply
5
52
false
Framework
418
kmerge_assoc_perm
lemma kmerge_assoc_perm (l₁ lβ‚‚ l₃ : List (Sigma (fun _ : loc => val))) (nd₁ : l₁.NodupKeys) (ndβ‚‚ : lβ‚‚.NodupKeys) (nd₃ : l₃.NodupKeys) : (kmerge (kmerge l₁ lβ‚‚) l₃).Perm $ (kmerge l₁ (kmerge lβ‚‚ l₃))
splean
SPLean/Common/Heap.lean
[ "import Mathlib.Algebra.BigOperators.Group.Finset", "import Mathlib.Algebra.BigOperators.Intervals", "import Mathlib.Algebra.Group.Basic", "import Ssreflect.Lang", "import Mathlib.Data.Finmap", "import Mathlib.Order.Interval.Finset.Basic", "import Mathlib.Data.Int.Interval", "import Lean", "import Batteries.Data.List.Perm" ]
[ { "name": "Nat", "module": "Init.Prelude" }, { "name": "List", "module": "Init.Prelude" }, { "name": "Sigma", "module": "Init.Core" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "move", "module": "Ssreflect.Basic" }, { "name": "srw", "module": "Ssreflect.Rewrite" }, { "name": "Option.merge", "module": "Init.Data.Option.Basic" }, { "name": "elim", "module": "Ssreflect.Elim" }, { "name": "scase", "module": "Ssreflect.Elim" }, { "name": "List.NodupKeys", "module": "Mathlib.Data.List.Sigma" }, { "name": "List.kerase", "module": "Mathlib.Data.List.Sigma" }, { "name": "DecidableEq", "module": "Init.Prelude" } ]
[ { "name": "...", "content": "..." } ]
[ { "name": "List.mem_keys_kerase_of_ne", "module": "Mathlib.Data.List.Sigma" }, { "name": "List.kerase_cons_eq", "module": "Mathlib.Data.List.Sigma" }, { "name": "List.kerase_cons_ne", "module": "Mathlib.Data.List.Sigma" }, { "name": "List.NodupKeys.kerase", "module": "Mathlib.Data.List.Sigma" }, { "name": "List.mem_keys_of_mem", "module": "Mathlib.Data.List.Sigma" }, { "name": "List.dlookup_eq_none", "module": "Mathlib.Data.List.Sigma" }, { "name": "List.mem_dlookup", "module": "Mathlib.Data.List.Sigma" }, { "name": "List.of_mem_dlookup", "module": "Mathlib.Data.List.Sigma" }, { "name": "List.lookup_ext", "module": "Mathlib.Data.List.Sigma" }, { "name": "add_assoc", "module": "Mathlib.Algebra.Group.Defs" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "loc", "content": "abbrev loc := Nat" }, { "name": "kmerge1", "content": "private def kmerge1 (l : loc) (v : val) (lβ‚‚ : List (Sigma (fun _ : loc => val))) : val :=\n match lβ‚‚.dlookup l with\n | .some v' => v + v'\n | _ => v" }, { "name": "kmerge", "content": "@[simp]\ndef kmerge : List (Sigma (fun _ : loc => val)) β†’ List (Sigma (fun _ : loc => val)) β†’ List (Sigma (fun _ : loc => val))\n | [], lβ‚‚ => lβ‚‚\n | s :: l₁, lβ‚‚ =>\n (if s.1 ∈ lβ‚‚.keys then\n ⟨s.1, kmerge1 s.1 s.2 lβ‚‚βŸ© :: kmerge l₁ (lβ‚‚.kerase s.1)\n else s :: kmerge l₁ lβ‚‚)" } ]
[ { "name": "List.kerase_noterased", "content": "lemma List.kerase_noterased {Ξ± : Type u} {Ξ² : Ξ± β†’ Type v} [DecidableEq Ξ±] (l : List (Sigma Ξ²))\n (a a' : Ξ±) (hneq : a β‰  a') (b : Ξ² a) : ⟨a, b⟩ ∈ l ↔ ⟨a, b⟩ ∈ List.kerase a' l" }, { "name": "Option.merge_assoc", "content": "lemma Option.merge_assoc (h : Associative f) (a b c : Option Ξ±) :\n Option.merge f (Option.merge f a b) c = Option.merge f a (Option.merge f b c)" }, { "name": "kmerge_mem", "content": "@[simp]\nlemma kmerge_mem (l₁ : List (Sigma (fun _ : loc => val))) : l ∈ (kmerge l₁ lβ‚‚).keys ↔ l ∈ l₁.keys ∨ l ∈ lβ‚‚.keys" }, { "name": "kmerge_mem2", "content": "lemma kmerge_mem2 (l₁ lβ‚‚ : List (Sigma (fun _ : loc => val))) (nd₁ : l₁.NodupKeys) (ndβ‚‚ : lβ‚‚.NodupKeys) -- necessary\n (a : Sigma (fun _ : loc => val)) : a ∈ (kmerge l₁ lβ‚‚) ↔\n if a.1 ∈ l₁.keys\n then (if a.1 ∈ lβ‚‚.keys then Option.merge (Β· + Β·) (l₁.dlookup a.1) (lβ‚‚.dlookup a.1) = .some a.2 else a ∈ l₁)\n else a ∈ lβ‚‚" }, { "name": "kmerge_dlookup", "content": "lemma kmerge_dlookup (l₁ lβ‚‚ : List (Sigma (fun _ : loc => val))) (nd₁ : l₁.NodupKeys) (ndβ‚‚ : lβ‚‚.NodupKeys)\n (a : loc) : (kmerge l₁ lβ‚‚).dlookup a = Option.merge (Β· + Β·) (l₁.dlookup a) (lβ‚‚.dlookup a)" }, { "name": "kmerge_NodupKeys", "content": "lemma kmerge_NodupKeys (l₁ lβ‚‚ : List (Sigma (fun _ : loc => val))) (nd₁ : l₁.NodupKeys) (ndβ‚‚ : lβ‚‚.NodupKeys) : (kmerge l₁ lβ‚‚).NodupKeys" } ]
import Lean import Mathlib.Data.Finmap import Mathlib.Algebra.Group.Basic import Mathlib.Algebra.BigOperators.Group.Finset import Mathlib.Algebra.BigOperators.Intervals import Mathlib.Data.Int.Interval import Mathlib.Order.Interval.Finset.Basic import Batteries.Data.List.Perm import Ssreflect.Lang open Classical abbrev loc := Nat section Option.merge variable {Ξ± : Type u} (f : Ξ± β†’ Ξ± β†’ Ξ±) end Option.merge open PartialCommMonoid (valid) section variable {val : Type} [PartialCommMonoid val] -- [Inhabited val] local notation "heap" => Heap.heap val private def kmerge1 (l : loc) (v : val) (lβ‚‚ : List (Sigma (fun _ : loc => val))) : val := match lβ‚‚.dlookup l with | .some v' => v + v' | _ => v @[simp] def kmerge : List (Sigma (fun _ : loc => val)) β†’ List (Sigma (fun _ : loc => val)) β†’ List (Sigma (fun _ : loc => val)) | [], lβ‚‚ => lβ‚‚ | s :: l₁, lβ‚‚ => (if s.1 ∈ lβ‚‚.keys then ⟨s.1, kmerge1 s.1 s.2 lβ‚‚βŸ© :: kmerge l₁ (lβ‚‚.kerase s.1) else s :: kmerge l₁ lβ‚‚)
lemma kmerge_assoc_perm (l₁ lβ‚‚ l₃ : List (Sigma (fun _ : loc => val))) (nd₁ : l₁.NodupKeys) (ndβ‚‚ : lβ‚‚.NodupKeys) (nd₃ : l₃.NodupKeys) : (kmerge (kmerge l₁ lβ‚‚) l₃).Perm $ (kmerge l₁ (kmerge lβ‚‚ l₃)) :=
:= by apply List.lookup_ext <;> try (repeat'(apply kmerge_NodupKeys=> //)) move=> l v (srw !kmerge_dlookup=> //) <;> try (repeat'(apply kmerge_NodupKeys=> //)) rw [Option.merge_assoc]=> // ; apply add_assoc
4
31
false
Framework
419
validInter_assoc_r
lemma validInter_assoc_r (h₁ hβ‚‚ h₃ : heap) : hβ‚‚ βŠ₯Κ° h₃ -> h₁ βŠ₯Κ° (hβ‚‚ +Κ° h₃) -> (h₁ +Κ° hβ‚‚) βŠ₯Κ° h₃
splean
SPLean/Common/Heap.lean
[ "import Mathlib.Algebra.BigOperators.Group.Finset", "import Mathlib.Algebra.BigOperators.Intervals", "import Mathlib.Algebra.Group.Basic", "import SPLean/Theories/HProp.lean", "import Ssreflect.Lang", "import Mathlib.Data.Finmap", "import Mathlib.Order.Interval.Finset.Basic", "import Mathlib.Data.Int.Interval", "import Lean", "import Batteries.Data.List.Perm" ]
[ { "name": "Nat", "module": "Init.Prelude" }, { "name": "List", "module": "Init.Prelude" }, { "name": "Sigma", "module": "Init.Core" }, { "name": "AList", "module": "Mathlib.Data.List.AList" }, { "name": "scase", "module": "Ssreflect.Elim" }, { "name": "Finmap", "module": "Mathlib.Data.Finmap" }, { "name": "Finmap.liftOnβ‚‚", "module": "Mathlib.Data.Finmap" }, { "name": "move", "module": "Ssreflect.Basic" }, { "name": "srw", "module": "Ssreflect.Rewrite" }, { "name": "String", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "Finmap.lookup", "module": "Mathlib.Data.Finmap" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "Or", "module": "Init.Prelude" }, { "name": "Option.merge", "module": "Init.Data.Option.Basic" }, { "name": "HAdd", "module": "Init.Prelude" }, { "name": "HAdd.hAdd", "module": "Init.Prelude" }, { "name": "instHAdd", "module": "Init.Prelude" }, { "name": "sdone", "module": "Ssreflect.Done" } ]
[ { "name": "heap", "content": "abbrev heap := Heap.heap val\n\n inductive val : Type where\n | val_unit : val\n | val_bool : Bool β†’ val\n | val_int : Int β†’ val\n | val_real : ℝ β†’ val\n | val_loc : loc β†’ val\n | val_prim : prim β†’ val\n | val_fun : var -> trm -> val\n | val_fix : var -> var -> trm -> val\n | val_uninit : val\n | val_error : val" }, { "name": "prim", "content": "inductive prim where\n \n | val_get : prim\n | val_set : prim\n \n | val_neg : prim\n | val_opp : prim\n | val_eq : prim\n | val_add : prim\n | val_neq : prim\n | val_sub : prim\n | val_mul : prim\n | val_div : prim\n | val_mod : prim\n \n | val_le : prim\n | val_lt : prim\n | val_ge : prim\n | val_gt : prim\n | val_ptr_add : prim\n\n inductive trm : Type where\n | trm_val : val -> trm\n | trm_var : var -> trm\n | trm_fun : var -> trm -> trm\n | trm_fix : var -> var -> trm -> trm\n | trm_app : trm -> trm -> trm\n | trm_seq : trm -> trm -> trm\n | trm_let : var -> trm -> trm -> trm\n | trm_if : trm -> trm -> trm -> trm\n | trm_for : var -> trm -> trm -> trm -> trm\n | trm_while : trm -> trm -> trm\n | trm_ref : var β†’ trm β†’ trm β†’ trm\n | trm_alloc : var β†’ trm β†’ trm β†’ trm" }, { "name": "scoped instance : PartialCommMonoid val where", "content": "scoped instance : PartialCommMonoid val where\n add := add\n add_assoc := by admit /- proof elided -/" }, { "name": "add", "content": "@[simp]\nabbrev add : val -> val -> val\n | .val_int i, .val_int j => val.val_int (i + j)\n | _, _ => val.val_unit" }, { "name": "evalExact", "content": "inductive evalExact : state β†’ trm β†’ (val β†’ state β†’ Prop) -> Prop where\n | val : forall s v,\n evalExact s (trm_val v) (fun v' s' ↦ v' = v ∧ s' = s)\n | fun : forall s x t1,\n evalExact s (trm_fun x t1) (fun v' s' ↦ v' = val_fun x t1 ∧ s' = s)\n | fix : forall s f x t1,\n evalExact s (trm_fix f x t1) (fun v' s' ↦ v' = val_fix f x t1 ∧ s' = s)\n | app_arg1 : forall s1 t1 t2 Q1 Q,\n Β¬ trm_is_val t1 ->\n evalExact s1 t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 (trm_app v1 t2) Q) ->\n evalExact s1 (trm_app t1 t2) Q\n | app_arg2 : forall s1 (v1 : val) t2 Q1 Q,\n Β¬ trm_is_val t2 ->\n evalExact s1 t2 Q1 ->\n (forall v2 s2, Q1 v2 s2 -> evalExact s2 (trm_app v1 v2) Q) ->\n evalExact s1 (trm_app v1 t2) Q\n | app_fun : forall s1 v1 (v2 :val) x t1 Q,\n v1 = val_fun x t1 ->\n evalExact s1 (subst x v2 t1) Q ->\n evalExact s1 (trm_app v1 v2) Q\n | app_fix : forall s (v1 v2 : val) f x t1 Q,\n v1 = val_fix f x t1 ->\n evalExact s (subst x v2 (subst f v1 t1)) Q ->\n evalExact s (trm_app v1 v2) Q\n | seq : forall Q1 s t1 t2 Q,\n evalExact s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 t2 Q) ->\n evalExact s (trm_seq t1 t2) Q\n | let : forall Q1 s x t1 t2 Q,\n evalExact s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 (subst x v1 t2) Q) ->\n evalExact s (trm_let x t1 t2) Q\n | if : forall s (b : Bool) t1 t2 Q,\n evalExact s (if b then t1 else t2) Q ->\n evalExact s (trm_if (val_bool b) t1 t2) Q\n | unop : forall op s v1 P,\n evalunop op v1 P ->\n evalExact s (trm_app op v1) (purepost s P)\n | binop : forall op s (v1 v2 : val) P,\n evalbinop op v1 v2 P ->\n evalExact s (trm_app (trm_app op v1) v2) (purepost s P)\n | ref : forall s x t1 t2 Q Q₁,\n evalExact s t1 Q₁ β†’\n (βˆ€ v1 s1, Q₁ v1 s1 β†’ βˆ€ p βˆ‰ s1,\n evalExact (s1.insert p v1) (subst x p t2) fun v s ↦ Q v (s.erase p)) β†’\n evalExact s (trm_ref x t1 t2) Q\n | get : forall s p,\n p ∈ s ->\n evalExact s (trm_app val_get (val_loc p))\n (fun v' s' ↦ v' = read_state p s ∧ s' = s)\n | set : forall s p v,\n v = trm_val v' ->\n p ∈ s ->\n evalExact s (trm_app (trm_app val_set (val_loc p)) v)\n (fun v'' s' ↦ v'' = val_unit ∧ s' = s.insert p v')\n | alloc_arg : forall s Q₁ Q,\n Β¬ trm_is_val t1 β†’\n evalExact s t1 Q₁ β†’\n (βˆ€ v' s', Q₁ v' s' β†’ evalExact s' (trm_alloc x v' t2) Q) β†’\n evalExact s (trm_alloc x t1 t2) Q\n | alloc : forall (sa : state) (n : β„€) Q,\n n β‰₯ 0 β†’\n (βˆ€ (p : loc) (sb : state),\n sb = conseq (make_list n.natAbs val_uninit) p β†’\n p β‰  null β†’\n Finmap.Disjoint sa sb β†’\n evalExact (sb βˆͺ sa) (subst x p t2) fun v s ↦ Q v (s \\ sb)) β†’\n evalExact sa (trm_alloc x n t2) Q\n \n \n \n \n \n \n | for (n₁ nβ‚‚ : Int) (Q : val -> state -> Prop) :\n evalExact s (if (n₁ < nβ‚‚) then\n (trm_seq (subst x n₁ t₁) (trm_for x (val_int (n₁ + 1)) nβ‚‚ t₁))\n else val_unit) Q ->\n evalExact s (trm_for x n₁ nβ‚‚ t₁) Q\n | while (t₁ tβ‚‚ : trm) (Q Q₁ : val -> state -> Prop) :\n evalExact s t₁ Q₁ ->\n (βˆ€ s v, Q₁ v s -> evalExact s (trm_if v (trm_seq tβ‚‚ (trm_while t₁ tβ‚‚)) val_unit) Q) ->\n evalExact s (trm_while t₁ tβ‚‚) Q" }, { "name": "valid", "content": "@[simp]\nabbrev valid : val -> Prop\n | .val_int _ => True\n | _ => False" }, { "name": "PartialCommMonoid", "content": "class PartialCommMonoid (Ξ± : Type) extends AddCommSemigroup Ξ± where\n valid : Ξ± -> Prop\n valid_add : βˆ€ x, valid (x + y) -> valid x\n add_valid : βˆ€ x y, valid x -> valid y -> valid (x + y)" }, { "name": "scoped instance inst : PartialCommMonoidWRT val add valid wh", "content": "scoped instance inst : PartialCommMonoidWRT val add valid where\n validE := by admit /- proof elided -/" }, { "name": "AddCommMonoidWRT", "content": "class AddCommMonoidWRT (Ξ± : Type) (add' : semiOutParam $ Ξ± -> Ξ± -> Ξ±) extends AddCommMonoid Ξ± where\n addE : (Β· + Β·) = add'" }, { "name": "scoped instance : PartialCommMonoid val where", "content": "scoped instance : PartialCommMonoid val where\n add := add\n add_assoc := by admit /- proof elided -/" }, { "name": "add", "content": "@[simp]\nabbrev add : val -> val -> val\n | .val_bool i, .val_bool j => val.val_bool (i || j)\n | _, _ => val.val_unit" }, { "name": "valid", "content": "@[simp]\nabbrev valid : val -> Prop\n | .val_bool _ => True\n | _ => False" }, { "name": "scoped instance : PartialCommMonoid val where", "content": "scoped instance : PartialCommMonoid val where\n add := add\n add_assoc := by admit /- proof elided -/" }, { "name": "add", "content": "@[simp]\nabbrev add : val -> val -> val\n | .val_real i, .val_real j => val.val_real (i + j)\n | _, _ => val.val_unit" }, { "name": "valid", "content": "@[simp]\nabbrev valid : val -> Prop\n | .val_real _ => True\n | _ => False" } ]
[ { "name": "Finmap.mem_of_lookup_eq_some", "module": "Mathlib.Data.Finmap" }, { "name": "Or.intro_right", "module": "Init.Prelude" }, { "name": "add_assoc", "module": "Mathlib.Algebra.Group.Defs" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "loc", "content": "abbrev loc := Nat" }, { "name": "var", "content": "abbrev var := String" }, { "name": "Heap.heap", "content": "abbrev Heap.heap (val : Type) := Finmap (Ξ» _ : loc ↦ val)" }, { "name": "PartialCommMonoid", "content": "class PartialCommMonoid (Ξ± : Type) extends AddCommSemigroup Ξ± where\n valid : Ξ± -> Prop\n valid_add : βˆ€ x, valid (x + y) -> valid x\n add_valid : βˆ€ x y, valid x -> valid y -> valid (x + y)" }, { "name": "kmerge1", "content": "private def kmerge1 (l : loc) (v : val) (lβ‚‚ : List (Sigma (fun _ : loc => val))) : val :=\n match lβ‚‚.dlookup l with\n | .some v' => v + v'\n | _ => v" }, { "name": "kmerge", "content": "@[simp]\ndef kmerge : List (Sigma (fun _ : loc => val)) β†’ List (Sigma (fun _ : loc => val)) β†’ List (Sigma (fun _ : loc => val))\n | [], lβ‚‚ => lβ‚‚\n | s :: l₁, lβ‚‚ =>\n (if s.1 ∈ lβ‚‚.keys then\n ⟨s.1, kmerge1 s.1 s.2 lβ‚‚βŸ© :: kmerge l₁ (lβ‚‚.kerase s.1)\n else s :: kmerge l₁ lβ‚‚)" }, { "name": "AList.merge", "content": "noncomputable def AList.merge (h₁ hβ‚‚ : AList (fun _ : loc => val)) : AList (fun _ : loc => val) :=\n ⟨kmerge h₁.entries hβ‚‚.entries, by admit /- proof elided -/\n ⟩" }, { "name": "Heap.add", "content": "noncomputable def Heap.add (h₁ hβ‚‚ : heap) : heap :=\n Finmap.liftOnβ‚‚ h₁ hβ‚‚ (fun h₁ hβ‚‚ => (h₁.merge hβ‚‚).toFinmap) (by admit /- proof elided -/\n )" }, { "name": "validInter", "content": "def validInter (h₁ hβ‚‚ : heap) : Prop :=\n βˆ€ l ∈ h₁, l ∈ hβ‚‚ -> ((h₁ +Κ° hβ‚‚).lookup l).any (valid (Ξ± := val))" } ]
[ { "name": "Option.merge_none_l", "content": "lemma Option.merge_none_l (a : Option Ξ±) : Option.merge f none a = a" }, { "name": "Option.merge_assoc", "content": "lemma Option.merge_assoc (h : Associative f) (a b c : Option Ξ±) :\n Option.merge f (Option.merge f a b) c = Option.merge f a (Option.merge f b c)" } ]
import Lean import Mathlib.Data.Finmap import Mathlib.Algebra.Group.Basic import Mathlib.Algebra.BigOperators.Group.Finset import Mathlib.Algebra.BigOperators.Intervals import Mathlib.Data.Int.Interval import Mathlib.Order.Interval.Finset.Basic import Batteries.Data.List.Perm import Ssreflect.Lang open Classical abbrev loc := Nat abbrev var := String section Option.merge variable {Ξ± : Type u} (f : Ξ± β†’ Ξ± β†’ Ξ±) end Option.merge abbrev Heap.heap (val : Type) := Finmap (Ξ» _ : loc ↦ val) class PartialCommMonoid (Ξ± : Type) extends AddCommSemigroup Ξ± where valid : Ξ± -> Prop valid_add : βˆ€ x, valid (x + y) -> valid x add_valid : βˆ€ x y, valid x -> valid y -> valid (x + y) open PartialCommMonoid (valid) section variable {val : Type} [PartialCommMonoid val] -- [Inhabited val] local notation "heap" => Heap.heap val private def kmerge1 (l : loc) (v : val) (lβ‚‚ : List (Sigma (fun _ : loc => val))) : val := match lβ‚‚.dlookup l with | .some v' => v + v' | _ => v @[simp] def kmerge : List (Sigma (fun _ : loc => val)) β†’ List (Sigma (fun _ : loc => val)) β†’ List (Sigma (fun _ : loc => val)) | [], lβ‚‚ => lβ‚‚ | s :: l₁, lβ‚‚ => (if s.1 ∈ lβ‚‚.keys then ⟨s.1, kmerge1 s.1 s.2 lβ‚‚βŸ© :: kmerge l₁ (lβ‚‚.kerase s.1) else s :: kmerge l₁ lβ‚‚) noncomputable def AList.merge (h₁ hβ‚‚ : AList (fun _ : loc => val)) : AList (fun _ : loc => val) := ⟨kmerge h₁.entries hβ‚‚.entries, by admit /- proof elided -/ ⟩ noncomputable def Heap.add (h₁ hβ‚‚ : heap) : heap := Finmap.liftOnβ‚‚ h₁ hβ‚‚ (fun h₁ hβ‚‚ => (h₁.merge hβ‚‚).toFinmap) (by admit /- proof elided -/ ) infixr:55 " +Κ° " => Heap.add def validInter (h₁ hβ‚‚ : heap) : Prop := βˆ€ l ∈ h₁, l ∈ hβ‚‚ -> ((h₁ +Κ° hβ‚‚).lookup l).any (valid (Ξ± := val)) infixr:55 " βŠ₯Κ° " => validInter
lemma validInter_assoc_r (h₁ hβ‚‚ h₃ : heap) : hβ‚‚ βŠ₯Κ° h₃ -> h₁ βŠ₯Κ° (hβ‚‚ +Κ° h₃) -> (h₁ +Κ° hβ‚‚) βŠ₯Κ° h₃ :=
:= by simp [validInter] move=> h1' h2' l /[swap] hin3 /[tac (have h1 := (fun H => h1' _ H hin3) ; have h2 := (fun H => h2' _ H (Or.intro_right _ hin3)) ; clear h1' h2')] [ hin1 | hin2 ] { rw [Option.merge_assoc, h2]=> // apply add_assoc } { rcases h : Finmap.lookup l h₁ { rw [Option.merge_none_l] ; aesop } { srw h at h2 ; rw [Option.merge_assoc, h2] ; apply Finmap.mem_of_lookup_eq_some at h=> // apply add_assoc } }
6
34
false
Framework
420
hrange_eq_conseq
lemma hrange_eq_conseq (L : List val) (n : β„€) (p : loc) (s : state) : L.length = n β†’ hrange L p s β†’ s.keys = (conseq (make_list n.natAbs val_uninit) p).keys
splean
SPLean/Theories/SepLog.lean
[ "import Mathlib.Data.Finmap", "import SPLean.Common.State", "import SPLean.Theories.HProp", "import SPLean.Common.Util", "import Mathlib.Data.Multiset.Nodup", "import SPLean.Theories.XSimp", "import Mathlib.Data.Finset.Basic" ]
[ { "name": "String", "module": "Init.Prelude" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "Finmap", "module": "Mathlib.Data.Finmap" }, { "name": "Finmap.singleton", "module": "Mathlib.Data.Finmap" }, { "name": "List", "module": "Init.Prelude" }, { "name": "Finset", "module": "Mathlib.Data.Finset.Defs" }, { "name": "elim", "module": "Ssreflect.Elim" }, { "name": "move", "module": "Ssreflect.Basic" }, { "name": "sby", "module": "Ssreflect.Done" }, { "name": "srw", "module": "Ssreflect.Rewrite" } ]
[ { "name": "notation:max \"emp\" => hempty", "content": "notation:max \"emp\" => hempty\n\nsyntax \"fun\" ident+ \" => \" lang : lang" }, { "name": "macro_rules", "content": "macro_rules\n | `([lang| ()]) => `(trm_val (val_unit))\n | `([lang| $n:num]) => `(trm_val (val_int $n))\n | `([lang| $t1 $t2]) => `(trm_app [lang| $t1] [lang| $t2])\n | `([lang| if $t1 then $t2 else $t3]) => `(trm_if [lang| $t1] [lang| $t2] [lang| $t3])\n | `([lang| if $t1 then $t2 end]) => `(trm_if [lang| $t1] [lang| $t2] (trm_val val_unit))\n | `([lang| let $x := $t1:lang in $t2:lang]) =>\n `(trm_let $(%x) [lang| $t1] [lang| $t2])\n | `([lang| ref $x := $t1:lang in $t2:lang]) =>\n `(trm_ref $(%x) [lang| $t1] [lang| $t2])\n | `([lang| alloc $t1:lang as $x in $t2:lang]) =>\n `(trm_alloc $(%x) [lang| $t1] [lang| $t2])\n | `([lang| $t1 ; $t2]) => `(trm_seq [lang| $t1] [lang| $t2])\n | `([lang| fun_ $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(trm_funs [ $xs,* ] [lang| $t])\n | `([lang| fun $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(val_funs [ $xs,* ] [lang| $t])\n | `([lang| fix_ $f $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(trm_fixs $(%f) [ $xs,* ] [lang| $t])\n | `([lang| fix $f $xs* => $t]) => do\n let xs <- xs.mapM fun x => `(term| $(%x))\n `(val_fixs $(%f) [ $xs,* ] [lang| $t])\n \n | `([lang| free $t]) => `(trm_val (val_prim val_free) [lang| $t])\n | `([lang| not $t]) => `(trm_val (val_prim val_not) [lang| $t])\n \n | `([lang| !$t]) => `(trm_val val_get [lang| $t])\n | `([lang| $t1 := $t2]) => `(trm_val val_set [lang| $t1] [lang| $t2])\n | `([lang| $t1 + $t2]) => `(trm_val val_add [lang| $t1] [lang| $t2])\n | `([lang| $t1 * $t2]) => `(trm_val val_mul [lang| $t1] [lang| $t2])\n | `([lang| $t1 - $t2]) => `(trm_val val_sub [lang| $t1] [lang| $t2])\n | `([lang| $t1 / $t2]) => `(trm_val val_div [lang| $t1] [lang| $t2])\n | `([lang| $t1 < $t2]) => `(trm_val val_lt [lang| $t1] [lang| $t2])\n | `([lang| $t1 > $t2]) => `(trm_val val_gt [lang| $t1] [lang| $t2])\n | `([lang| $t1 <= $t2]) => `(trm_val val_le [lang| $t1] [lang| $t2])\n | `([lang| $t1 >= $t2]) => `(trm_val val_ge [lang| $t1] [lang| $t2])\n | `([lang| -$t]) => `(trm_val val_opp [lang| $t])\n | `([lang| $t1 = $t2]) => `(trm_val val_eq [lang| $t1] [lang| $t2])\n | `([lang| $t1 != $t2]) => `(trm_val val_neq [lang| $t1] [lang| $t2])\n | `([lang| $t1 mod $t2]) => `(trm_val val_mod [lang| $t1] [lang| $t2])\n | `([lang| $t1 ++ $t2]) => `(trm_val val_ptr_add [lang| $t1] [lang| $t2])\n | `([lang| ($t)]) => `([lang| $t])\n | `([lang| ⟨$t : $tp⟩]) => `(trm_val (($t : $tp)))\n | `([lang| for $x in [$n1 : $n2] { $t } ]) =>\n `(trm_for $(%x) [lang| $n1] [lang| $n2] [lang| $t])\n | `([lang| while $c:lang { $t:lang } ]) =>\n `(trm_while [lang| $c] [lang| $t] )" }, { "name": "macro_rules", "content": "macro_rules\n | `([lang| len $p]) => `(trm_val val_array_length [lang| $p])\n | `([lang| $arr[$i] ]) => `(trm_val val_array_get [lang| $arr] [lang| $i])\n \n | `([lang| $arr[$i] := $v]) => `(trm_app val_array_set [lang| $arr] [lang| $i] [lang| $v])\n | `([lang| mkarr $n:lang $v:lang]) => `(trm_val val_array_make [lang| $n] [lang| $v])" }, { "name": "macro_rules | `($x βˆ— $y) => `(binop% HStar.hStar $x $y)", "content": "macro_rules | `($x βˆ— $y) => `(binop% HStar.hStar $x $y)" }, { "name": "HStar", "content": "class HStar (Ξ± : Type u) (Ξ² : Type v) (Ξ³ : outParam (Type w)) where\n \n hStar : Ξ± β†’ Ξ² β†’ Ξ³" }, { "name": "hsingle", "content": "def hsingle (p : loc) (v : val) : hProp :=\n fun h => (h = Finmap.singleton p v)" }, { "name": "hProp", "content": "def hProp := heap -> Prop" }, { "name": "heap", "content": "abbrev heap := Heap.heap val\n\n inductive val : Type where\n | val_unit : val\n | val_bool : Bool β†’ val\n | val_int : Int β†’ val\n | val_real : ℝ β†’ val\n | val_loc : loc β†’ val\n | val_prim : prim β†’ val\n | val_fun : var -> trm -> val\n | val_fix : var -> var -> trm -> val\n | val_uninit : val\n | val_error : val" }, { "name": "prim", "content": "inductive prim where\n \n | val_get : prim\n | val_set : prim\n \n | val_neg : prim\n | val_opp : prim\n | val_eq : prim\n | val_add : prim\n | val_neq : prim\n | val_sub : prim\n | val_mul : prim\n | val_div : prim\n | val_mod : prim\n \n | val_le : prim\n | val_lt : prim\n | val_ge : prim\n | val_gt : prim\n | val_ptr_add : prim\n\n inductive trm : Type where\n | trm_val : val -> trm\n | trm_var : var -> trm\n | trm_fun : var -> trm -> trm\n | trm_fix : var -> var -> trm -> trm\n | trm_app : trm -> trm -> trm\n | trm_seq : trm -> trm -> trm\n | trm_let : var -> trm -> trm -> trm\n | trm_if : trm -> trm -> trm -> trm\n | trm_for : var -> trm -> trm -> trm -> trm\n | trm_while : trm -> trm -> trm\n | trm_ref : var β†’ trm β†’ trm β†’ trm\n | trm_alloc : var β†’ trm β†’ trm β†’ trm" }, { "name": "var", "content": "abbrev var := String" }, { "name": "loc", "content": "abbrev loc := Nat" }, { "name": "Heap.heap", "content": "abbrev Heap.heap (val : Type) := Finmap (Ξ» _ : loc ↦ val)" }, { "name": "evalExact", "content": "inductive evalExact : state β†’ trm β†’ (val β†’ state β†’ Prop) -> Prop where\n | val : forall s v,\n evalExact s (trm_val v) (fun v' s' ↦ v' = v ∧ s' = s)\n | fun : forall s x t1,\n evalExact s (trm_fun x t1) (fun v' s' ↦ v' = val_fun x t1 ∧ s' = s)\n | fix : forall s f x t1,\n evalExact s (trm_fix f x t1) (fun v' s' ↦ v' = val_fix f x t1 ∧ s' = s)\n | app_arg1 : forall s1 t1 t2 Q1 Q,\n Β¬ trm_is_val t1 ->\n evalExact s1 t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 (trm_app v1 t2) Q) ->\n evalExact s1 (trm_app t1 t2) Q\n | app_arg2 : forall s1 (v1 : val) t2 Q1 Q,\n Β¬ trm_is_val t2 ->\n evalExact s1 t2 Q1 ->\n (forall v2 s2, Q1 v2 s2 -> evalExact s2 (trm_app v1 v2) Q) ->\n evalExact s1 (trm_app v1 t2) Q\n | app_fun : forall s1 v1 (v2 :val) x t1 Q,\n v1 = val_fun x t1 ->\n evalExact s1 (subst x v2 t1) Q ->\n evalExact s1 (trm_app v1 v2) Q\n | app_fix : forall s (v1 v2 : val) f x t1 Q,\n v1 = val_fix f x t1 ->\n evalExact s (subst x v2 (subst f v1 t1)) Q ->\n evalExact s (trm_app v1 v2) Q\n | seq : forall Q1 s t1 t2 Q,\n evalExact s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 t2 Q) ->\n evalExact s (trm_seq t1 t2) Q\n | let : forall Q1 s x t1 t2 Q,\n evalExact s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 (subst x v1 t2) Q) ->\n evalExact s (trm_let x t1 t2) Q\n | if : forall s (b : Bool) t1 t2 Q,\n evalExact s (if b then t1 else t2) Q ->\n evalExact s (trm_if (val_bool b) t1 t2) Q\n | unop : forall op s v1 P,\n evalunop op v1 P ->\n evalExact s (trm_app op v1) (purepost s P)\n | binop : forall op s (v1 v2 : val) P,\n evalbinop op v1 v2 P ->\n evalExact s (trm_app (trm_app op v1) v2) (purepost s P)\n | ref : forall s x t1 t2 Q Q₁,\n evalExact s t1 Q₁ β†’\n (βˆ€ v1 s1, Q₁ v1 s1 β†’ βˆ€ p βˆ‰ s1,\n evalExact (s1.insert p v1) (subst x p t2) fun v s ↦ Q v (s.erase p)) β†’\n evalExact s (trm_ref x t1 t2) Q\n | get : forall s p,\n p ∈ s ->\n evalExact s (trm_app val_get (val_loc p))\n (fun v' s' ↦ v' = read_state p s ∧ s' = s)\n | set : forall s p v,\n v = trm_val v' ->\n p ∈ s ->\n evalExact s (trm_app (trm_app val_set (val_loc p)) v)\n (fun v'' s' ↦ v'' = val_unit ∧ s' = s.insert p v')\n | alloc_arg : forall s Q₁ Q,\n Β¬ trm_is_val t1 β†’\n evalExact s t1 Q₁ β†’\n (βˆ€ v' s', Q₁ v' s' β†’ evalExact s' (trm_alloc x v' t2) Q) β†’\n evalExact s (trm_alloc x t1 t2) Q\n | alloc : forall (sa : state) (n : β„€) Q,\n n β‰₯ 0 β†’\n (βˆ€ (p : loc) (sb : state),\n sb = conseq (make_list n.natAbs val_uninit) p β†’\n p β‰  null β†’\n Finmap.Disjoint sa sb β†’\n evalExact (sb βˆͺ sa) (subst x p t2) fun v s ↦ Q v (s \\ sb)) β†’\n evalExact sa (trm_alloc x n t2) Q\n \n \n \n \n \n \n | for (n₁ nβ‚‚ : Int) (Q : val -> state -> Prop) :\n evalExact s (if (n₁ < nβ‚‚) then\n (trm_seq (subst x n₁ t₁) (trm_for x (val_int (n₁ + 1)) nβ‚‚ t₁))\n else val_unit) Q ->\n evalExact s (trm_for x n₁ nβ‚‚ t₁) Q\n | while (t₁ tβ‚‚ : trm) (Q Q₁ : val -> state -> Prop) :\n evalExact s t₁ Q₁ ->\n (βˆ€ s v, Q₁ v s -> evalExact s (trm_if v (trm_seq tβ‚‚ (trm_while t₁ tβ‚‚)) val_unit) Q) ->\n evalExact s (trm_while t₁ tβ‚‚) Q" }, { "name": "hempty", "content": "def hempty : hProp :=\n fun h => (h = βˆ…)" }, { "name": "state", "content": "abbrev state := Finmap (Ξ» _ : loc ↦ val)" }, { "name": "make_list", "content": "def make_list {A} (n : Nat) (v : A) : List A :=\n match n with\n | 0 => []\n | n' + 1 => v :: make_list n' v" }, { "name": "conseq", "content": "def conseq {B : Type} (vs : List B) (l : Nat) : Finmap (fun _ : Nat ↦ B) :=\n match vs with\n | [] => βˆ…\n | v :: vs' => (Finmap.singleton l v) βˆͺ (conseq vs' (l + 1))" }, { "name": "notation:max \"emp\" => hempty", "content": "notation:max \"emp\" => hempty" }, { "name": "infixr:60 \" ~~> \" => hsingle", "content": "infixr:60 \" ~~> \" => hsingle" }, { "name": "infixr:55 \" βˆ— \" => HStar.hStar", "content": "infixr:55 \" βˆ— \" => HStar.hStar" } ]
[ { "name": "Finmap.mem_keys", "module": "Mathlib.Data.Finmap" }, { "name": "Finset.ext_iff", "module": "Mathlib.Data.Finset.Defs" } ]
[ { "name": "hempty_inv", "content": "lemma hempty_inv h :\n emp h β†’ h = βˆ…" }, { "name": "hsingl_inv", "content": "lemma hsingl_inv p v h :\n (p ~~> v) h β†’\n h = Finmap.singleton p v" } ]
[ { "name": "hrange", "content": "def hrange (L : List val) (p : loc) : hProp :=\n match L with\n | [] => emp\n | x :: L' => (p ~~> x) βˆ— (hrange L' (p + 1))" } ]
[ { "name": "int_eq_sub", "content": "lemma int_eq_sub (l m n : β„€) :\n l + m = n β†’ l = n - m" }, { "name": "list_inc_natabs", "content": "lemma list_inc_natabs {Ξ± : Type} (L : List Ξ±) :\n ((L.length : β„€) + 1).natAbs = (L.length : β„€).natAbs + 1" } ]
import Mathlib.Data.Finmap import Mathlib.Data.Finset.Basic import Mathlib.Data.Multiset.Nodup import SPLean.Common.State import SPLean.Common.Util import SPLean.Theories.HProp import SPLean.Theories.XSimp open trm val prim notation "funloc" p "↦" H => fun (r : val) ↦ hexists (fun p ↦ ⌜r = val_loc p⌝ βˆ— H) section evalProp end evalProp def hrange (L : List val) (p : loc) : hProp := match L with | [] => emp | x :: L' => (p ~~> x) βˆ— (hrange L' (p + 1))
lemma hrange_eq_conseq (L : List val) (n : β„€) (p : loc) (s : state) : L.length = n β†’ hrange L p s β†’ s.keys = (conseq (make_list n.natAbs val_uninit) p).keys :=
:= by elim: L n p s=> > ; unfold hrange { sby move=> /= <- /= /hempty_inv -> } move=> ih > /== /[dup] /int_eq_sub /[dup] hn /ih {}ih <- srw -hn at ih move: ih=> /= ih {hn} unfold hrange=> ![>] /hsingl_inv ? /ih {}ih ? -> unfold conseq make_list srw list_inc_natabs=> /== > move: ih sby srw ?Finset.ext_iff Finmap.mem_keys=> ?
8
34
false
Framework
421
validInter_assoc_l
lemma validInter_assoc_l (h₁ hβ‚‚ h₃ : heap) : h₁ βŠ₯Κ° hβ‚‚ -> (h₁ +Κ° hβ‚‚) βŠ₯Κ° h₃ -> h₁ βŠ₯Κ° (hβ‚‚ +Κ° h₃)
splean
SPLean/Common/Heap.lean
[ "import Mathlib.Algebra.BigOperators.Group.Finset", "import Mathlib.Algebra.BigOperators.Intervals", "import Mathlib.Algebra.Group.Basic", "import SPLean/Theories/HProp.lean", "import Ssreflect.Lang", "import Mathlib.Data.Finmap", "import Mathlib.Order.Interval.Finset.Basic", "import Mathlib.Data.Int.Interval", "import Lean", "import Batteries.Data.List.Perm" ]
[ { "name": "Nat", "module": "Init.Prelude" }, { "name": "List", "module": "Init.Prelude" }, { "name": "Sigma", "module": "Init.Core" }, { "name": "AList", "module": "Mathlib.Data.List.AList" }, { "name": "scase", "module": "Ssreflect.Elim" }, { "name": "Finmap", "module": "Mathlib.Data.Finmap" }, { "name": "Finmap.liftOnβ‚‚", "module": "Mathlib.Data.Finmap" }, { "name": "move", "module": "Ssreflect.Basic" }, { "name": "srw", "module": "Ssreflect.Rewrite" }, { "name": "String", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "Finmap.lookup", "module": "Mathlib.Data.Finmap" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "Or", "module": "Init.Prelude" }, { "name": "Option.merge", "module": "Init.Data.Option.Basic" }, { "name": "HAdd", "module": "Init.Prelude" }, { "name": "HAdd.hAdd", "module": "Init.Prelude" }, { "name": "instHAdd", "module": "Init.Prelude" }, { "name": "sdone", "module": "Ssreflect.Done" } ]
[ { "name": "heap", "content": "abbrev heap := Heap.heap val\n\n inductive val : Type where\n | val_unit : val\n | val_bool : Bool β†’ val\n | val_int : Int β†’ val\n | val_real : ℝ β†’ val\n | val_loc : loc β†’ val\n | val_prim : prim β†’ val\n | val_fun : var -> trm -> val\n | val_fix : var -> var -> trm -> val\n | val_uninit : val\n | val_error : val" }, { "name": "prim", "content": "inductive prim where\n \n | val_get : prim\n | val_set : prim\n \n | val_neg : prim\n | val_opp : prim\n | val_eq : prim\n | val_add : prim\n | val_neq : prim\n | val_sub : prim\n | val_mul : prim\n | val_div : prim\n | val_mod : prim\n \n | val_le : prim\n | val_lt : prim\n | val_ge : prim\n | val_gt : prim\n | val_ptr_add : prim\n\n inductive trm : Type where\n | trm_val : val -> trm\n | trm_var : var -> trm\n | trm_fun : var -> trm -> trm\n | trm_fix : var -> var -> trm -> trm\n | trm_app : trm -> trm -> trm\n | trm_seq : trm -> trm -> trm\n | trm_let : var -> trm -> trm -> trm\n | trm_if : trm -> trm -> trm -> trm\n | trm_for : var -> trm -> trm -> trm -> trm\n | trm_while : trm -> trm -> trm\n | trm_ref : var β†’ trm β†’ trm β†’ trm\n | trm_alloc : var β†’ trm β†’ trm β†’ trm" }, { "name": "scoped instance : PartialCommMonoid val where", "content": "scoped instance : PartialCommMonoid val where\n add := add\n add_assoc := by admit /- proof elided -/" }, { "name": "add", "content": "@[simp]\nabbrev add : val -> val -> val\n | .val_int i, .val_int j => val.val_int (i + j)\n | _, _ => val.val_unit" }, { "name": "evalExact", "content": "inductive evalExact : state β†’ trm β†’ (val β†’ state β†’ Prop) -> Prop where\n | val : forall s v,\n evalExact s (trm_val v) (fun v' s' ↦ v' = v ∧ s' = s)\n | fun : forall s x t1,\n evalExact s (trm_fun x t1) (fun v' s' ↦ v' = val_fun x t1 ∧ s' = s)\n | fix : forall s f x t1,\n evalExact s (trm_fix f x t1) (fun v' s' ↦ v' = val_fix f x t1 ∧ s' = s)\n | app_arg1 : forall s1 t1 t2 Q1 Q,\n Β¬ trm_is_val t1 ->\n evalExact s1 t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 (trm_app v1 t2) Q) ->\n evalExact s1 (trm_app t1 t2) Q\n | app_arg2 : forall s1 (v1 : val) t2 Q1 Q,\n Β¬ trm_is_val t2 ->\n evalExact s1 t2 Q1 ->\n (forall v2 s2, Q1 v2 s2 -> evalExact s2 (trm_app v1 v2) Q) ->\n evalExact s1 (trm_app v1 t2) Q\n | app_fun : forall s1 v1 (v2 :val) x t1 Q,\n v1 = val_fun x t1 ->\n evalExact s1 (subst x v2 t1) Q ->\n evalExact s1 (trm_app v1 v2) Q\n | app_fix : forall s (v1 v2 : val) f x t1 Q,\n v1 = val_fix f x t1 ->\n evalExact s (subst x v2 (subst f v1 t1)) Q ->\n evalExact s (trm_app v1 v2) Q\n | seq : forall Q1 s t1 t2 Q,\n evalExact s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 t2 Q) ->\n evalExact s (trm_seq t1 t2) Q\n | let : forall Q1 s x t1 t2 Q,\n evalExact s t1 Q1 ->\n (forall v1 s2, Q1 v1 s2 -> evalExact s2 (subst x v1 t2) Q) ->\n evalExact s (trm_let x t1 t2) Q\n | if : forall s (b : Bool) t1 t2 Q,\n evalExact s (if b then t1 else t2) Q ->\n evalExact s (trm_if (val_bool b) t1 t2) Q\n | unop : forall op s v1 P,\n evalunop op v1 P ->\n evalExact s (trm_app op v1) (purepost s P)\n | binop : forall op s (v1 v2 : val) P,\n evalbinop op v1 v2 P ->\n evalExact s (trm_app (trm_app op v1) v2) (purepost s P)\n | ref : forall s x t1 t2 Q Q₁,\n evalExact s t1 Q₁ β†’\n (βˆ€ v1 s1, Q₁ v1 s1 β†’ βˆ€ p βˆ‰ s1,\n evalExact (s1.insert p v1) (subst x p t2) fun v s ↦ Q v (s.erase p)) β†’\n evalExact s (trm_ref x t1 t2) Q\n | get : forall s p,\n p ∈ s ->\n evalExact s (trm_app val_get (val_loc p))\n (fun v' s' ↦ v' = read_state p s ∧ s' = s)\n | set : forall s p v,\n v = trm_val v' ->\n p ∈ s ->\n evalExact s (trm_app (trm_app val_set (val_loc p)) v)\n (fun v'' s' ↦ v'' = val_unit ∧ s' = s.insert p v')\n | alloc_arg : forall s Q₁ Q,\n Β¬ trm_is_val t1 β†’\n evalExact s t1 Q₁ β†’\n (βˆ€ v' s', Q₁ v' s' β†’ evalExact s' (trm_alloc x v' t2) Q) β†’\n evalExact s (trm_alloc x t1 t2) Q\n | alloc : forall (sa : state) (n : β„€) Q,\n n β‰₯ 0 β†’\n (βˆ€ (p : loc) (sb : state),\n sb = conseq (make_list n.natAbs val_uninit) p β†’\n p β‰  null β†’\n Finmap.Disjoint sa sb β†’\n evalExact (sb βˆͺ sa) (subst x p t2) fun v s ↦ Q v (s \\ sb)) β†’\n evalExact sa (trm_alloc x n t2) Q\n \n \n \n \n \n \n | for (n₁ nβ‚‚ : Int) (Q : val -> state -> Prop) :\n evalExact s (if (n₁ < nβ‚‚) then\n (trm_seq (subst x n₁ t₁) (trm_for x (val_int (n₁ + 1)) nβ‚‚ t₁))\n else val_unit) Q ->\n evalExact s (trm_for x n₁ nβ‚‚ t₁) Q\n | while (t₁ tβ‚‚ : trm) (Q Q₁ : val -> state -> Prop) :\n evalExact s t₁ Q₁ ->\n (βˆ€ s v, Q₁ v s -> evalExact s (trm_if v (trm_seq tβ‚‚ (trm_while t₁ tβ‚‚)) val_unit) Q) ->\n evalExact s (trm_while t₁ tβ‚‚) Q" }, { "name": "valid", "content": "@[simp]\nabbrev valid : val -> Prop\n | .val_int _ => True\n | _ => False" }, { "name": "PartialCommMonoid", "content": "class PartialCommMonoid (Ξ± : Type) extends AddCommSemigroup Ξ± where\n valid : Ξ± -> Prop\n valid_add : βˆ€ x, valid (x + y) -> valid x\n add_valid : βˆ€ x y, valid x -> valid y -> valid (x + y)" }, { "name": "scoped instance inst : PartialCommMonoidWRT val add valid wh", "content": "scoped instance inst : PartialCommMonoidWRT val add valid where\n validE := by admit /- proof elided -/" }, { "name": "AddCommMonoidWRT", "content": "class AddCommMonoidWRT (Ξ± : Type) (add' : semiOutParam $ Ξ± -> Ξ± -> Ξ±) extends AddCommMonoid Ξ± where\n addE : (Β· + Β·) = add'" }, { "name": "scoped instance : PartialCommMonoid val where", "content": "scoped instance : PartialCommMonoid val where\n add := add\n add_assoc := by admit /- proof elided -/" }, { "name": "add", "content": "@[simp]\nabbrev add : val -> val -> val\n | .val_bool i, .val_bool j => val.val_bool (i || j)\n | _, _ => val.val_unit" }, { "name": "valid", "content": "@[simp]\nabbrev valid : val -> Prop\n | .val_bool _ => True\n | _ => False" }, { "name": "scoped instance : PartialCommMonoid val where", "content": "scoped instance : PartialCommMonoid val where\n add := add\n add_assoc := by admit /- proof elided -/" }, { "name": "add", "content": "@[simp]\nabbrev add : val -> val -> val\n | .val_real i, .val_real j => val.val_real (i + j)\n | _, _ => val.val_unit" }, { "name": "valid", "content": "@[simp]\nabbrev valid : val -> Prop\n | .val_real _ => True\n | _ => False" } ]
[ { "name": "Finmap.mem_of_lookup_eq_some", "module": "Mathlib.Data.Finmap" }, { "name": "Or.intro_left", "module": "Init.Prelude" }, { "name": "add_assoc", "module": "Mathlib.Algebra.Group.Defs" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "loc", "content": "abbrev loc := Nat" }, { "name": "var", "content": "abbrev var := String" }, { "name": "Heap.heap", "content": "abbrev Heap.heap (val : Type) := Finmap (Ξ» _ : loc ↦ val)" }, { "name": "PartialCommMonoid", "content": "class PartialCommMonoid (Ξ± : Type) extends AddCommSemigroup Ξ± where\n valid : Ξ± -> Prop\n valid_add : βˆ€ x, valid (x + y) -> valid x\n add_valid : βˆ€ x y, valid x -> valid y -> valid (x + y)" }, { "name": "kmerge1", "content": "private def kmerge1 (l : loc) (v : val) (lβ‚‚ : List (Sigma (fun _ : loc => val))) : val :=\n match lβ‚‚.dlookup l with\n | .some v' => v + v'\n | _ => v" }, { "name": "kmerge", "content": "@[simp]\ndef kmerge : List (Sigma (fun _ : loc => val)) β†’ List (Sigma (fun _ : loc => val)) β†’ List (Sigma (fun _ : loc => val))\n | [], lβ‚‚ => lβ‚‚\n | s :: l₁, lβ‚‚ =>\n (if s.1 ∈ lβ‚‚.keys then\n ⟨s.1, kmerge1 s.1 s.2 lβ‚‚βŸ© :: kmerge l₁ (lβ‚‚.kerase s.1)\n else s :: kmerge l₁ lβ‚‚)" }, { "name": "AList.merge", "content": "noncomputable def AList.merge (h₁ hβ‚‚ : AList (fun _ : loc => val)) : AList (fun _ : loc => val) :=\n ⟨kmerge h₁.entries hβ‚‚.entries, by admit /- proof elided -/\n ⟩" }, { "name": "Heap.add", "content": "noncomputable def Heap.add (h₁ hβ‚‚ : heap) : heap :=\n Finmap.liftOnβ‚‚ h₁ hβ‚‚ (fun h₁ hβ‚‚ => (h₁.merge hβ‚‚).toFinmap) (by admit /- proof elided -/\n )" }, { "name": "validInter", "content": "def validInter (h₁ hβ‚‚ : heap) : Prop :=\n βˆ€ l ∈ h₁, l ∈ hβ‚‚ -> ((h₁ +Κ° hβ‚‚).lookup l).any (valid (Ξ± := val))" } ]
[ { "name": "Option.merge_none_r", "content": "lemma Option.merge_none_r (a : Option Ξ±) : Option.merge f a none = a" }, { "name": "Option.merge_assoc", "content": "lemma Option.merge_assoc (h : Associative f) (a b c : Option Ξ±) :\n Option.merge f (Option.merge f a b) c = Option.merge f a (Option.merge f b c)" } ]
import Lean import Mathlib.Data.Finmap import Mathlib.Algebra.Group.Basic import Mathlib.Algebra.BigOperators.Group.Finset import Mathlib.Algebra.BigOperators.Intervals import Mathlib.Data.Int.Interval import Mathlib.Order.Interval.Finset.Basic import Batteries.Data.List.Perm import Ssreflect.Lang open Classical abbrev loc := Nat abbrev var := String section Option.merge variable {Ξ± : Type u} (f : Ξ± β†’ Ξ± β†’ Ξ±) end Option.merge abbrev Heap.heap (val : Type) := Finmap (Ξ» _ : loc ↦ val) class PartialCommMonoid (Ξ± : Type) extends AddCommSemigroup Ξ± where valid : Ξ± -> Prop valid_add : βˆ€ x, valid (x + y) -> valid x add_valid : βˆ€ x y, valid x -> valid y -> valid (x + y) open PartialCommMonoid (valid) section variable {val : Type} [PartialCommMonoid val] -- [Inhabited val] local notation "heap" => Heap.heap val private def kmerge1 (l : loc) (v : val) (lβ‚‚ : List (Sigma (fun _ : loc => val))) : val := match lβ‚‚.dlookup l with | .some v' => v + v' | _ => v @[simp] def kmerge : List (Sigma (fun _ : loc => val)) β†’ List (Sigma (fun _ : loc => val)) β†’ List (Sigma (fun _ : loc => val)) | [], lβ‚‚ => lβ‚‚ | s :: l₁, lβ‚‚ => (if s.1 ∈ lβ‚‚.keys then ⟨s.1, kmerge1 s.1 s.2 lβ‚‚βŸ© :: kmerge l₁ (lβ‚‚.kerase s.1) else s :: kmerge l₁ lβ‚‚) noncomputable def AList.merge (h₁ hβ‚‚ : AList (fun _ : loc => val)) : AList (fun _ : loc => val) := ⟨kmerge h₁.entries hβ‚‚.entries, by admit /- proof elided -/ ⟩ noncomputable def Heap.add (h₁ hβ‚‚ : heap) : heap := Finmap.liftOnβ‚‚ h₁ hβ‚‚ (fun h₁ hβ‚‚ => (h₁.merge hβ‚‚).toFinmap) (by admit /- proof elided -/ ) infixr:55 " +Κ° " => Heap.add def validInter (h₁ hβ‚‚ : heap) : Prop := βˆ€ l ∈ h₁, l ∈ hβ‚‚ -> ((h₁ +Κ° hβ‚‚).lookup l).any (valid (Ξ± := val)) infixr:55 " βŠ₯Κ° " => validInter
lemma validInter_assoc_l (h₁ hβ‚‚ h₃ : heap) : h₁ βŠ₯Κ° hβ‚‚ -> (h₁ +Κ° hβ‚‚) βŠ₯Κ° h₃ -> h₁ βŠ₯Κ° (hβ‚‚ +Κ° h₃) :=
:= by simp [validInter] move=> h1 h2 l hin1 /[tac (specialize h1 _ hin1 ; specialize h2 _ (Or.intro_left _ hin1))] [ hin2 | hin3 ] { rcases h : Finmap.lookup l h₃ { rw [Option.merge_none_r] ; aesop } { srw h at h2 ; rw [← Option.merge_assoc, h2] ; apply Finmap.mem_of_lookup_eq_some at h=> // apply add_assoc } } { rw [← Option.merge_assoc, h2]=> // apply add_assoc }
6
34
false
Framework
422
wtPar
theorem wtPar {Ξ“} {a b A : Term} (r : a β‡’ b) (h : Ξ“ ⊒ a ∢ A) : Ξ“ ⊒ b ∢ A
TTBFL
src/safety.lean
[ "import Β«srcΒ».typing", "import src.syntactics", "import src.reduction", "import src.typing" ]
[ { "name": "Inhabited", "module": "Init.Prelude" }, { "name": "Lean.ToExpr", "module": "Lean.ToExpr" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Repr", "module": "Init.Data.Repr" }, { "name": "DecidableEq", "module": "Init.Prelude" }, { "name": "List", "module": "Init.Prelude" }, { "name": "String", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "Nat.sub", "module": "Init.Prelude" }, { "name": "Nat.succ", "module": "Init.Prelude" }, { "name": "Nat.zero", "module": "Init.Prelude" } ]
[ { "name": "notation:40 Ξ”:41 \"⊒\" ΞΎ:41 \"∢\" Ξ“:41 => wRename ΞΎ Ξ“ Ξ”", "content": "notation:40 Ξ”:41 \"⊒\" ΞΎ:41 \"∢\" Ξ“:41 => wRename ΞΎ Ξ“ Ξ”" }, { "name": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“", "content": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“" }, { "name": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A", "content": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A" }, { "name": "notation:40 Ξ”:41 \"⊒\" Οƒ:41 \"∢\" Ξ“:41 => wSubst Οƒ Ξ“ Ξ”", "content": "notation:40 Ξ”:41 \"⊒\" Οƒ:41 \"∢\" Ξ“:41 => wSubst Οƒ Ξ“ Ξ”" }, { "name": "notation:40 Ξ“:41 \"βˆ‹\" x:41 \"∢\" A:41 => In x A Ξ“", "content": "notation:40 Ξ“:41 \"βˆ‹\" x:41 \"∢\" A:41 => In x A Ξ“" }, { "name": "Term", "content": "inductive Term : Type where\n | var : Nat β†’ Term\n | 𝒰 : Term β†’ Term\n | pi : Term β†’ Term β†’ Term\n | abs : Term β†’ Term β†’ Term\n | app : Term β†’ Term β†’ Term\n | mty : Term\n | exf : Term β†’ Term β†’ Term\n | lvl : Term β†’ Term\n | lof : lc.L β†’ Term" }, { "name": "Wt", "content": "inductive Wt : Ctxt β†’ Term β†’ Term β†’ Prop where\n | var {Ξ“ x A} :\n ⊒ Ξ“ β†’\n Ξ“ βˆ‹ x ∢ A β†’\n \n Ξ“ ⊒ var x ∢ A\n | 𝒰 {Ξ“ j k} :\n Ξ“ ⊒ j ∢ lvl k β†’\n \n Ξ“ ⊒ 𝒰 j ∢ 𝒰 k\n | pi {Ξ“ A B k} :\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n Ξ“ ∷ A ⊒ B ∢ 𝒰 (rename succ k) β†’\n \n Ξ“ ⊒ pi A B ∢ 𝒰 k\n | abs {Ξ“ A B b k} :\n Ξ“ ⊒ pi A B ∢ 𝒰 k β†’\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n Ξ“ ∷ A ⊒ b ∢ B β†’\n \n Ξ“ ⊒ abs A b ∢ pi A B\n | app {Ξ“ A B b a} :\n Ξ“ ⊒ b ∢ pi A B β†’\n Ξ“ ⊒ a ∢ A β†’\n \n Ξ“ ⊒ app b a ∢ subst (a +: var) B\n | mty {Ξ“ j k} :\n Ξ“ ⊒ 𝒰 j ∢ 𝒰 k β†’\n \n Ξ“ ⊒ mty ∢ 𝒰 j\n | exf {Ξ“ A b k} :\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n Ξ“ ⊒ b ∢ mty β†’\n \n Ξ“ ⊒ exf A b ∢ A\n | lvl {Ξ“ a b j k} :\n Ξ“ ⊒ a ∢ lvl b β†’\n Ξ“ ⊒ 𝒰 j ∢ 𝒰 k β†’\n \n Ξ“ ⊒ lvl a ∢ 𝒰 j\n | lof {Ξ“ j k} :\n ⊒ Ξ“ β†’\n j < k β†’\n \n Ξ“ ⊒ lof j ∢ lvl (lof k)\n | trans {Ξ“ i j k} :\n Ξ“ ⊒ i ∢ lvl j β†’\n Ξ“ ⊒ j ∢ lvl k β†’\n \n Ξ“ ⊒ i ∢ lvl k\n | conv {Ξ“ A B a k} :\n A β‰ˆ B β†’\n Ξ“ ⊒ a ∢ A β†’\n Ξ“ ⊒ B ∢ 𝒰 k β†’\n \n Ξ“ ⊒ a ∢ B\n | sub {Ξ“ j k A} :\n Ξ“ ⊒ j ∢ lvl k β†’\n Ξ“ ⊒ A ∢ 𝒰 j β†’\n \n Ξ“ ⊒ A ∢ 𝒰 k" }, { "name": "Par", "content": "inductive Par : Term β†’ Term β†’ Prop where\n | Ξ² {b b' a a' c} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app (abs c b) a β‡’ subst (a' +: var) b'\n | var s : var s β‡’ var s\n | 𝒰 {a a'} :\n a β‡’ a' β†’\n \n 𝒰 a β‡’ 𝒰 a'\n | pi {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n pi a b β‡’ pi a' b'\n | abs {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n abs a b β‡’ abs a' b'\n | app {b b' a a'} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app b a β‡’ app b' a'\n | mty : mty β‡’ mty\n | exf {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n exf a b β‡’ exf a' b'\n | lvl {a a'} :\n a β‡’ a' β†’\n \n lvl a β‡’ lvl a'\n | lof k : lof k β‡’ lof k" }, { "name": "Wf", "content": "inductive Wf : Ctxt β†’ Prop where\n | nil : ⊒ ⬝\n | cons {Ξ“ A k} :\n ⊒ Ξ“ β†’\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n \n ⊒ Ξ“ ∷ A" }, { "name": "Ctxt", "content": "inductive Ctxt : Type where\n | nil : Ctxt\n | cons : Ctxt β†’ Term β†’ Ctxt" }, { "name": "subst", "content": "@[simp]\ndef subst (Οƒ : Nat β†’ Term) : Term β†’ Term\n | var s => Οƒ s\n | 𝒰 a => 𝒰 (subst Οƒ a)\n | pi a b => pi (subst Οƒ a) (subst (⇑ Οƒ) b)\n | abs a b => abs (subst Οƒ a) (subst (⇑ Οƒ) b)\n | app b a => app (subst Οƒ b) (subst Οƒ a)\n | mty => mty\n | exf a b => exf (subst Οƒ a) (subst Οƒ b)\n | lvl a => lvl (subst Οƒ a)\n | lof k => lof k" }, { "name": "up", "content": "@[simp]\ndef up (Οƒ : Nat β†’ Term) : Nat β†’ Term :=\n var 0 +: (rename succ ∘ Οƒ)" }, { "name": "rename", "content": "@[simp]\ndef rename (ΞΎ : Nat β†’ Nat) : Term β†’ Term\n | var s => var (ΞΎ s)\n | 𝒰 a => 𝒰 (rename ΞΎ a)\n | pi a b => pi (rename ΞΎ a) (rename (lift ΞΎ) b)\n | abs a b => abs (rename ΞΎ a) (rename (lift ΞΎ) b)\n | app b a => app (rename ΞΎ b) (rename ΞΎ a)\n | mty => mty\n | exf a b => exf (rename ΞΎ a) (rename ΞΎ b)\n | lvl a => lvl (rename ΞΎ a)\n | lof k => lof k" }, { "name": "lift", "content": "@[simp]\ndef lift (ΞΎ : Nat β†’ Nat) : Nat β†’ Nat :=\n zero +: (succ ∘ ΞΎ)" }, { "name": "cons", "content": "@[simp]\ndef cons {A : Type} (x : A) (ΞΎ : Nat β†’ A) : Nat β†’ A\n | 0 => x\n | n + 1 => ΞΎ n" }, { "name": "In", "content": "inductive In : Nat β†’ Term β†’ Ctxt β†’ Prop where\n | here {Ξ“ A} : In 0 (rename succ A) (Ξ“ ∷ A)\n | there {Ξ“ x A B} : In x A Ξ“ β†’ In (succ x) (rename succ A) (Ξ“ ∷ B)" }, { "name": "Eqv", "content": "inductive Eqv : Term β†’ Term β†’ Prop where\n | Ξ² {b a c} : app (abs c b) a β‰ˆ subst (a +: var) b\n | 𝒰 {a a'} :\n a β‰ˆ a' β†’\n \n 𝒰 a β‰ˆ 𝒰 a'\n | pi {a a' b b'} :\n a β‰ˆ a' β†’\n b β‰ˆ b' β†’\n \n pi a b β‰ˆ pi a' b'\n | abs {a a' b b'} :\n a β‰ˆ a' β†’\n b β‰ˆ b' β†’\n \n abs a b β‰ˆ abs a' b'\n | app {b b' a a'} :\n b β‰ˆ b' β†’\n a β‰ˆ a' β†’\n \n app b a β‰ˆ app b' a'\n | exf {a a' b b'} :\n a β‰ˆ a' β†’\n b β‰ˆ b' β†’\n \n exf a b β‰ˆ exf a' b'\n | lvl {a a'} :\n a β‰ˆ a' β†’\n \n lvl a β‰ˆ lvl a'\n | refl {a} : a β‰ˆ a\n | sym {a b} :\n a β‰ˆ b β†’\n \n b β‰ˆ a\n | trans {a b c} :\n a β‰ˆ b β†’\n b β‰ˆ c β†’\n \n a β‰ˆ c" }, { "name": "Conv", "content": "def Conv (a : Term) (b : Term) : Prop := βˆƒ c, a ⇒⋆ c ∧ b ⇒⋆ c" }, { "name": "Pars", "content": "inductive Pars : Term β†’ Term β†’ Prop where\n | refl a : a ⇒⋆ a\n | trans {a b c} : a β‡’ b β†’ b ⇒⋆ c β†’ a ⇒⋆ c" }, { "name": "substRename", "content": "def substRename ΞΎ Οƒ : βˆ€ s, subst Οƒ (rename ΞΎ s) = subst (Οƒ ∘ ΞΎ) s :=\n substRename' _ _ (Οƒ ∘ ΞΎ) (by admit /- proof elided -/\n )" }, { "name": "renameSubst", "content": "def renameSubst ΞΎ Οƒ : βˆ€ s, rename ΞΎ (subst Οƒ s) = subst (rename ΞΎ ∘ Οƒ) s :=\n renameSubst' _ _ (rename ΞΎ ∘ Οƒ) (by admit /- proof elided -/\n )" }, { "name": "substComp", "content": "def substComp Οƒ Ο„ : βˆ€ s, (subst Οƒ ∘ subst Ο„) s = subst (subst Οƒ ∘ Ο„) s :=\n substComp' _ _ (subst Οƒ ∘ Ο„) (by admit /- proof elided -/\n )" }, { "name": "substId", "content": "def substId : βˆ€ s, subst var s = s :=\n substId' var (by admit /- proof elided -/\n )" }, { "name": "infix:40 \"β‡’\" => Par", "content": "infix:40 \"β‡’\" => Par" }, { "name": "infix:40 \"⇒⋆\" => Pars", "content": "infix:40 \"⇒⋆\" => Pars" }, { "name": "infix:40 \"⇔\" => Conv", "content": "infix:40 \"⇔\" => Conv" }, { "name": "infixr:50 \"+:\" => cons", "content": "infixr:50 \"+:\" => cons" }, { "name": "prefix:95 \"⇑\" => up", "content": "prefix:95 \"⇑\" => up" }, { "name": "notation:50 \"⬝\" => Ctxt.nil", "content": "notation:50 \"⬝\" => Ctxt.nil" }, { "name": "infixl:50 \"∷\" => Ctxt.cons", "content": "infixl:50 \"∷\" => Ctxt.cons" }, { "name": "notation:40 Ξ“:41 \"βˆ‹\" x:41 \"∢\" A:41 => In x A Ξ“", "content": "notation:40 Ξ“:41 \"βˆ‹\" x:41 \"∢\" A:41 => In x A Ξ“" }, { "name": "infix:40 (priority := 1001) \"β‰ˆ\" => Eqv", "content": "infix:40 (priority := 1001) \"β‰ˆ\" => Eqv" }, { "name": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“", "content": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“" }, { "name": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A", "content": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A" } ]
[ { "name": "trans", "module": "Mathlib.Order.Defs.Unbundled" } ]
[ { "name": "renameLiftRename", "content": "theorem renameLiftRename ΞΎ a : rename succ (rename ΞΎ a) = rename (lift ΞΎ) (rename succ a)" }, { "name": "liftSucc", "content": "omit lc in\ntheorem liftSucc ΞΎ : βˆ€ x, (lift ΞΎ ∘ succ) x = (succ ∘ ΞΎ) x" }, { "name": "renameComp", "content": "theorem renameComp ΞΎ ΞΆ s : rename ΞΎ (rename ΞΆ s) = rename (ΞΎ ∘ ΞΆ) s" }, { "name": "renameComp'", "content": "theorem renameComp' ΞΎ ΞΆ Ο‚ (h : βˆ€ x, (ΞΎ ∘ ΞΆ) x = Ο‚ x) : βˆ€ s, (rename ΞΎ ∘ rename ΞΆ) s = rename Ο‚ s" }, { "name": "liftComp", "content": "omit lc in\ntheorem liftComp ΞΎ ΞΆ Ο‚ (h : βˆ€ x, (ΞΎ ∘ ΞΆ) x = Ο‚ x) :\n βˆ€ x, (lift ΞΎ ∘ lift ΞΆ) x = lift Ο‚ x" }, { "name": "renameExt", "content": "theorem renameExt ΞΎ ΞΆ (h : βˆ€ x, ΞΎ x = ΞΆ x) : βˆ€ s, rename ΞΎ s = rename ΞΆ s" }, { "name": "liftExt", "content": "omit lc in\ntheorem liftExt ΞΎ ΞΆ (h : βˆ€ x, ΞΎ x = ΞΆ x) : βˆ€ x, lift ΞΎ x = lift ΞΆ x" }, { "name": "wtfPiInvA", "content": "theorem wtfPiInvA {Ξ“ A B 𝒰'}\n (h : Ξ“ ⊒ pi A B ∢ 𝒰') :\n βˆƒ j, Ξ“ ⊒ A ∢ 𝒰 j" }, { "name": "wtfPiInvA𝒰", "content": "theorem wtfPiInvA𝒰 {Ξ“ A B 𝒰'}\n (h : Ξ“ ⊒ pi A B ∢ 𝒰') :\n βˆƒ j, Ξ“ ⊒ A ∢ 𝒰 j ∧ 𝒰 j β‰ˆ 𝒰'" }, { "name": "eqvConv", "content": "theorem eqvConv {a b} (r : a β‰ˆ b) : a ⇔ b" }, { "name": "convRename", "content": "theorem convRename {a b} ΞΎ : a ⇔ b β†’ rename ΞΎ a ⇔ rename ΞΎ b" }, { "name": "parsRename", "content": "theorem parsRename {a b} ΞΎ (r : a ⇒⋆ b) : rename ΞΎ a ⇒⋆ rename ΞΎ b" }, { "name": "parRename", "content": "theorem parRename {a b} ΞΎ (r : a β‡’ b) : rename ΞΎ a β‡’ rename ΞΎ b" }, { "name": "renameDist", "content": "theorem renameDist ΞΎ a s : subst (rename ΞΎ a +: var) (rename (lift ΞΎ) s) = rename ΞΎ (subst (a +: var) s)" }, { "name": "substExt", "content": "theorem substExt Οƒ Ο„ (h : βˆ€ x, Οƒ x = Ο„ x) : βˆ€ s, subst Οƒ s = subst Ο„ s" }, { "name": "upExt", "content": "theorem upExt Οƒ Ο„ (h : βˆ€ x, Οƒ x = Ο„ x) : βˆ€ x, (⇑ Οƒ) x = (⇑ Ο„) x" }, { "name": "wRenameLift", "content": "theorem wRenameLift {ΞΎ : β„• β†’ β„•} {Ξ“ Ξ” A}\n (h : Ξ” ⊒ ΞΎ ∢ Ξ“) :\n Ξ” ∷ (rename ΞΎ A) ⊒ lift ΞΎ ∢ Ξ“ ∷ A" }, { "name": "inHere", "content": "theorem inHere {Ξ“ A A'} (e : A' = rename succ A) : (Ξ“ ∷ A) βˆ‹ 0 ∢ A'" }, { "name": "inThere", "content": "theorem inThere {Ξ“ x A A' B} (h : Ξ“ βˆ‹ x ∢ A) (e : A' = rename succ A) : Ξ“ ∷ B βˆ‹ succ x ∢ A'" }, { "name": "convEqv", "content": "theorem convEqv {a b} : a ⇔ b β†’ a β‰ˆ b" }, { "name": "parsEqv", "content": "theorem parsEqv {a b} (r : a ⇒⋆ b) : a β‰ˆ b" }, { "name": "parEqv", "content": "theorem parEqv {a b} (r : a β‡’ b) : a β‰ˆ b" }, { "name": "wRenameSucc", "content": "theorem wRenameSucc {Ξ“ A} : Ξ“ ∷ A ⊒ succ ∢ Ξ“" }, { "name": "renameUpSubst", "content": "theorem renameUpSubst Οƒ a : rename succ (subst Οƒ a) = subst (⇑ Οƒ) (rename succ a)" }, { "name": "upSucc", "content": "theorem upSucc Οƒ : βˆ€ x, (⇑ Οƒ ∘ succ) x = (rename succ ∘ Οƒ) x" }, { "name": "wtWf", "content": "theorem wtWf {Ξ“} {a A : Term} (h : Ξ“ ⊒ a ∢ A) : ⊒ Ξ“" }, { "name": "convSubst", "content": "theorem convSubst {a b} Οƒ : a ⇔ b β†’ subst Οƒ a ⇔ subst Οƒ b" }, { "name": "parsSubst", "content": "theorem parsSubst {a b} Οƒ (r : a ⇒⋆ b) : subst Οƒ a ⇒⋆ subst Οƒ b" }, { "name": "parSubst", "content": "theorem parSubst {a b} Οƒ (r : a β‡’ b) : subst Οƒ a β‡’ subst Οƒ b" }, { "name": "parRefl", "content": "theorem parRefl a : a β‡’ a" }, { "name": "parMorphing", "content": "theorem parMorphing {a b} Οƒ Ο„ (h : βˆ€ x, Οƒ x β‡’ Ο„ x) (r : a β‡’ b) : subst Οƒ a β‡’ subst Ο„ b" }, { "name": "parLift", "content": "theorem parLift Οƒ Ο„ (h : βˆ€ x, Οƒ x β‡’ Ο„ x) : βˆ€ x, (⇑ Οƒ) x β‡’ (⇑ Ο„) x" }, { "name": "substDist", "content": "theorem substDist Οƒ a s : subst (subst Οƒ a +: var) (subst (⇑ Οƒ) s) = subst Οƒ (subst (a +: var) s)" }, { "name": "substUnion", "content": "theorem substUnion Οƒ a s : subst (a +: Οƒ) s = subst (a +: var) (subst (⇑ Οƒ) s)" }, { "name": "substDropAll", "content": "theorem substDropAll a b : b = subst (a +: var) (rename succ b)" }, { "name": "wtfLvlInv", "content": "theorem wtfLvlInv {Ξ“ a 𝒰'}\n (h : Ξ“ ⊒ lvl a ∢ 𝒰') :\n βˆƒ b k, Ξ“ ⊒ a ∢ lvl b ∧ 𝒰 k β‰ˆ 𝒰'" }, { "name": "wtfPiInvB", "content": "theorem wtfPiInvB {Ξ“ A B 𝒰'}\n (h : Ξ“ ⊒ pi A B ∢ 𝒰') :\n βˆƒ j, Ξ“ ∷ A ⊒ B ∢ 𝒰 j" }, { "name": "convSym", "content": "theorem convSym {a b} : a ⇔ b β†’ b ⇔ a" }, { "name": "parCong", "content": "theorem parCong {a a' b b'} (ra : a β‡’ a') (rb : b β‡’ b') : subst (a +: var) b β‡’ subst (a' +: var) b'" }, { "name": "wtfAbsInv", "content": "theorem wtfAbsInv {Ξ“ A' b C}\n (h : Ξ“ ⊒ abs A' b ∢ C) :\n βˆƒ A B, Ξ“ ∷ A ⊒ b ∢ B ∧ A β‰ˆ A' ∧ pi A B β‰ˆ C" }, { "name": "convCong", "content": "theorem convCong {a a' b b'} : a ⇔ a' β†’ b ⇔ b' β†’ subst (a +: var) b ⇔ subst (a' +: var) b'" }, { "name": "parsCong", "content": "theorem parsCong {a a' b b'} (ra : a ⇒⋆ a') (rb : b ⇒⋆ b') : subst (a +: var) b ⇒⋆ subst (a' +: var) b'" }, { "name": "convPiInv", "content": "theorem convPiInv {a₁ aβ‚‚ b₁ bβ‚‚} : pi a₁ b₁ ⇔ pi aβ‚‚ bβ‚‚ β†’ a₁ ⇔ aβ‚‚ ∧ b₁ ⇔ bβ‚‚" }, { "name": "parsPiInv", "content": "theorem parsPiInv {a b c} (r : pi a b ⇒⋆ c) : βˆƒ a' b', c = pi a' b' ∧ a ⇒⋆ a' ∧ b ⇒⋆ b'" }, { "name": "parConv", "content": "theorem parConv {a b} (r : a β‡’ b) : a ⇔ b" }, { "name": "parPars", "content": "theorem parPars {a b} (r : a β‡’ b) : a ⇒⋆ b" }, { "name": "parsConv", "content": "theorem parsConv {a b} (r : a ⇒⋆ b) : a ⇔ b" } ]
[]
[ { "name": "wtRename", "content": "theorem wtRename {ΞΎ : β„• β†’ β„•} {Ξ“ Ξ”} {a A : Term}\n (hΞΎ : Ξ” ⊒ ΞΎ ∢ Ξ“) (hΞ” : ⊒ Ξ”) (h : Ξ“ ⊒ a ∢ A) :\n Ξ” ⊒ rename ΞΎ a ∢ rename ΞΎ A" }, { "name": "wtWeaken", "content": "theorem wtWeaken {Ξ“ k} {a A B : Term}\n (hΞ“ : ⊒ Ξ“) (hB : Ξ“ ⊒ B ∢ 𝒰 k) (h : Ξ“ ⊒ a ∢ A) :\n Ξ“ ∷ B ⊒ rename succ a ∢ rename succ A" }, { "name": "wSubstUp", "content": "theorem wSubstUp {Οƒ Ξ” Ξ“ k A}\n (hA : Ξ” ⊒ subst Οƒ A ∢ 𝒰 k)\n (h : Ξ” ⊒ Οƒ ∢ Ξ“) :\n Ξ” ∷ subst Οƒ A ⊒ ⇑ Οƒ ∢ Ξ“ ∷ A" }, { "name": "wSubstCons", "content": "theorem wSubstCons {Ξ“} {a A : Term}\n (h : Ξ“ ⊒ a ∢ A) :\n Ξ“ ⊒ a +: var ∢ Ξ“ ∷ A" }, { "name": "wtMorph", "content": "theorem wtMorph {Οƒ : β„• β†’ Term} {Ξ“ Ξ”} {a A : Term}\n (hΟƒ : Ξ” ⊒ Οƒ ∢ Ξ“) (hΞ” : ⊒ Ξ”) (h : Ξ“ ⊒ a ∢ A) :\n Ξ” ⊒ subst Οƒ a ∢ subst Οƒ A" }, { "name": "wtSubst", "content": "theorem wtSubst {Ξ“} {a A b B : Term}\n (hb : Ξ“ ⊒ b ∢ B) (h : Ξ“ ∷ B ⊒ a ∢ A) :\n Ξ“ ⊒ subst (b +: var) a ∢ subst (b +: var) A" }, { "name": "wtReplace", "content": "theorem wtReplace {Ξ“} {A B c C k : Term}\n (e : A β‰ˆ B)\n (hB : Ξ“ ⊒ B ∢ 𝒰 k)\n (h : Ξ“ ∷ A ⊒ c ∢ C) :\n Ξ“ ∷ B ⊒ c ∢ C" }, { "name": "wtMem", "content": "theorem wtMem {Ξ“ x A} (mem : Ξ“ βˆ‹ x ∢ A) (h : ⊒ Ξ“) : βˆƒ k, Ξ“ ⊒ A ∢ 𝒰 k" }, { "name": "wtRegularity", "content": "theorem wtRegularity {Ξ“} {a A : Term} (h : Ξ“ ⊒ a ∢ A) : βˆƒ k, Ξ“ ⊒ A ∢ 𝒰 k" } ]
import Β«srcΒ».typing open Nat open Term variable [LevelClass] notation:40 Ξ”:41 "⊒" Οƒ:41 "∢" Ξ“:41 => wSubst Οƒ Ξ“ Ξ”
theorem wtPar {Ξ“} {a b A : Term} (r : a β‡’ b) (h : Ξ“ ⊒ a ∢ A) : Ξ“ ⊒ b ∢ A :=
:= by induction h generalizing b case var => cases r; constructor <;> assumption case 𝒰 ih => cases r with | 𝒰 r' => exact Wt.𝒰 (ih r') case pi ihA ihB => cases r with | pi ra rb => let ihA' := ihA ra exact Wt.pi ihA' (wtReplace (parEqv ra) ihA' (ihB rb)) case abs B _ _ hPi _ _ ihPi ihA ihb => cases r with | abs rA rb => let rPi := Par.pi rA (parRefl B) let hb := wtReplace (convEqv (parConv rA)) (ihA rA) (ihb rb) exact Wt.conv (convEqv (convSym (parConv rPi))) (Wt.abs (ihPi rPi) (ihA rA) hb) hPi case app hb ha ihb iha => cases r case Ξ² rb ra => let ⟨_, hA⟩ := wtRegularity ha let ⟨_, hPi⟩ := wtRegularity hb let ⟨_, hB⟩ := wtfPiInvB hPi let ⟨A', B', hb', _, e⟩ := wtfAbsInv (ihb (Par.abs (parRefl _) rb)) let ⟨eA, eB⟩ := convPiInv (eqvConv e) exact Wt.conv (convEqv (convCong (convSym (parConv ra)) eB)) (wtSubst (iha ra) (wtReplace (convEqv eA) hA hb')) (wtSubst ha hB) case app rb ra => let ⟨k, hBa⟩ := wtRegularity (Wt.app hb ha) exact Wt.conv (convEqv (convSym (parConv (parCong ra (parRefl _))))) (Wt.app (ihb rb) (iha ra)) hBa case mty ih => cases r; exact Wt.mty (ih (parRefl _)) case exf hA _ ihA ihb => cases r with | exf rA rb => exact Wt.conv (convEqv (convSym (parConv rA))) (Wt.exf (ihA rA) (ihb rb)) hA case lvl hj iha _ => cases r with | lvl r' => exact Wt.lvl (iha r') hj case lof => cases r; constructor <;> assumption case trans hj ihi _ => exact Wt.trans (ihi r) hj case conv e _ hB iha _ => exact Wt.conv e (iha r) hB case sub hj _ _ ihA => exact Wt.sub hj (ihA r)
10
88
false
Type systems
423
wtMorph
theorem wtMorph {Οƒ : β„• β†’ Term} {Ξ“ Ξ”} {a A : Term} (hΟƒ : Ξ” ⊒ Οƒ ∢ Ξ“) (hΞ” : ⊒ Ξ”) (h : Ξ“ ⊒ a ∢ A) : Ξ” ⊒ subst Οƒ a ∢ subst Οƒ A
TTBFL
src/safety.lean
[ "import Β«srcΒ».typing", "import src.syntactics", "import src.reduction", "import src.typing" ]
[ { "name": "Inhabited", "module": "Init.Prelude" }, { "name": "Lean.ToExpr", "module": "Lean.ToExpr" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Repr", "module": "Init.Data.Repr" }, { "name": "DecidableEq", "module": "Init.Prelude" }, { "name": "List", "module": "Init.Prelude" }, { "name": "String", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "Nat.sub", "module": "Init.Prelude" }, { "name": "Nat.succ", "module": "Init.Prelude" }, { "name": "Nat.zero", "module": "Init.Prelude" } ]
[ { "name": "notation:40 Ξ”:41 \"⊒\" ΞΎ:41 \"∢\" Ξ“:41 => wRename ΞΎ Ξ“ Ξ”", "content": "notation:40 Ξ”:41 \"⊒\" ΞΎ:41 \"∢\" Ξ“:41 => wRename ΞΎ Ξ“ Ξ”" }, { "name": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“", "content": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“" }, { "name": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A", "content": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A" }, { "name": "notation:40 Ξ”:41 \"⊒\" Οƒ:41 \"∢\" Ξ“:41 => wSubst Οƒ Ξ“ Ξ”", "content": "notation:40 Ξ”:41 \"⊒\" Οƒ:41 \"∢\" Ξ“:41 => wSubst Οƒ Ξ“ Ξ”" }, { "name": "notation:40 Ξ“:41 \"βˆ‹\" x:41 \"∢\" A:41 => In x A Ξ“", "content": "notation:40 Ξ“:41 \"βˆ‹\" x:41 \"∢\" A:41 => In x A Ξ“" }, { "name": "Term", "content": "inductive Term : Type where\n | var : Nat β†’ Term\n | 𝒰 : Term β†’ Term\n | pi : Term β†’ Term β†’ Term\n | abs : Term β†’ Term β†’ Term\n | app : Term β†’ Term β†’ Term\n | mty : Term\n | exf : Term β†’ Term β†’ Term\n | lvl : Term β†’ Term\n | lof : lc.L β†’ Term" }, { "name": "Wt", "content": "inductive Wt : Ctxt β†’ Term β†’ Term β†’ Prop where\n | var {Ξ“ x A} :\n ⊒ Ξ“ β†’\n Ξ“ βˆ‹ x ∢ A β†’\n \n Ξ“ ⊒ var x ∢ A\n | 𝒰 {Ξ“ j k} :\n Ξ“ ⊒ j ∢ lvl k β†’\n \n Ξ“ ⊒ 𝒰 j ∢ 𝒰 k\n | pi {Ξ“ A B k} :\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n Ξ“ ∷ A ⊒ B ∢ 𝒰 (rename succ k) β†’\n \n Ξ“ ⊒ pi A B ∢ 𝒰 k\n | abs {Ξ“ A B b k} :\n Ξ“ ⊒ pi A B ∢ 𝒰 k β†’\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n Ξ“ ∷ A ⊒ b ∢ B β†’\n \n Ξ“ ⊒ abs A b ∢ pi A B\n | app {Ξ“ A B b a} :\n Ξ“ ⊒ b ∢ pi A B β†’\n Ξ“ ⊒ a ∢ A β†’\n \n Ξ“ ⊒ app b a ∢ subst (a +: var) B\n | mty {Ξ“ j k} :\n Ξ“ ⊒ 𝒰 j ∢ 𝒰 k β†’\n \n Ξ“ ⊒ mty ∢ 𝒰 j\n | exf {Ξ“ A b k} :\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n Ξ“ ⊒ b ∢ mty β†’\n \n Ξ“ ⊒ exf A b ∢ A\n | lvl {Ξ“ a b j k} :\n Ξ“ ⊒ a ∢ lvl b β†’\n Ξ“ ⊒ 𝒰 j ∢ 𝒰 k β†’\n \n Ξ“ ⊒ lvl a ∢ 𝒰 j\n | lof {Ξ“ j k} :\n ⊒ Ξ“ β†’\n j < k β†’\n \n Ξ“ ⊒ lof j ∢ lvl (lof k)\n | trans {Ξ“ i j k} :\n Ξ“ ⊒ i ∢ lvl j β†’\n Ξ“ ⊒ j ∢ lvl k β†’\n \n Ξ“ ⊒ i ∢ lvl k\n | conv {Ξ“ A B a k} :\n A β‰ˆ B β†’\n Ξ“ ⊒ a ∢ A β†’\n Ξ“ ⊒ B ∢ 𝒰 k β†’\n \n Ξ“ ⊒ a ∢ B\n | sub {Ξ“ j k A} :\n Ξ“ ⊒ j ∢ lvl k β†’\n Ξ“ ⊒ A ∢ 𝒰 j β†’\n \n Ξ“ ⊒ A ∢ 𝒰 k" }, { "name": "Wf", "content": "inductive Wf : Ctxt β†’ Prop where\n | nil : ⊒ ⬝\n | cons {Ξ“ A k} :\n ⊒ Ξ“ β†’\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n \n ⊒ Ξ“ ∷ A" }, { "name": "Ctxt", "content": "inductive Ctxt : Type where\n | nil : Ctxt\n | cons : Ctxt β†’ Term β†’ Ctxt" }, { "name": "subst", "content": "@[simp]\ndef subst (Οƒ : Nat β†’ Term) : Term β†’ Term\n | var s => Οƒ s\n | 𝒰 a => 𝒰 (subst Οƒ a)\n | pi a b => pi (subst Οƒ a) (subst (⇑ Οƒ) b)\n | abs a b => abs (subst Οƒ a) (subst (⇑ Οƒ) b)\n | app b a => app (subst Οƒ b) (subst Οƒ a)\n | mty => mty\n | exf a b => exf (subst Οƒ a) (subst Οƒ b)\n | lvl a => lvl (subst Οƒ a)\n | lof k => lof k" }, { "name": "Par", "content": "inductive Par : Term β†’ Term β†’ Prop where\n | Ξ² {b b' a a' c} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app (abs c b) a β‡’ subst (a' +: var) b'\n | var s : var s β‡’ var s\n | 𝒰 {a a'} :\n a β‡’ a' β†’\n \n 𝒰 a β‡’ 𝒰 a'\n | pi {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n pi a b β‡’ pi a' b'\n | abs {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n abs a b β‡’ abs a' b'\n | app {b b' a a'} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app b a β‡’ app b' a'\n | mty : mty β‡’ mty\n | exf {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n exf a b β‡’ exf a' b'\n | lvl {a a'} :\n a β‡’ a' β†’\n \n lvl a β‡’ lvl a'\n | lof k : lof k β‡’ lof k" }, { "name": "up", "content": "@[simp]\ndef up (Οƒ : Nat β†’ Term) : Nat β†’ Term :=\n var 0 +: (rename succ ∘ Οƒ)" }, { "name": "rename", "content": "@[simp]\ndef rename (ΞΎ : Nat β†’ Nat) : Term β†’ Term\n | var s => var (ΞΎ s)\n | 𝒰 a => 𝒰 (rename ΞΎ a)\n | pi a b => pi (rename ΞΎ a) (rename (lift ΞΎ) b)\n | abs a b => abs (rename ΞΎ a) (rename (lift ΞΎ) b)\n | app b a => app (rename ΞΎ b) (rename ΞΎ a)\n | mty => mty\n | exf a b => exf (rename ΞΎ a) (rename ΞΎ b)\n | lvl a => lvl (rename ΞΎ a)\n | lof k => lof k" }, { "name": "lift", "content": "@[simp]\ndef lift (ΞΎ : Nat β†’ Nat) : Nat β†’ Nat :=\n zero +: (succ ∘ ΞΎ)" }, { "name": "cons", "content": "@[simp]\ndef cons {A : Type} (x : A) (ΞΎ : Nat β†’ A) : Nat β†’ A\n | 0 => x\n | n + 1 => ΞΎ n" }, { "name": "In", "content": "inductive In : Nat β†’ Term β†’ Ctxt β†’ Prop where\n | here {Ξ“ A} : In 0 (rename succ A) (Ξ“ ∷ A)\n | there {Ξ“ x A B} : In x A Ξ“ β†’ In (succ x) (rename succ A) (Ξ“ ∷ B)" }, { "name": "Eqv", "content": "inductive Eqv : Term β†’ Term β†’ Prop where\n | Ξ² {b a c} : app (abs c b) a β‰ˆ subst (a +: var) b\n | 𝒰 {a a'} :\n a β‰ˆ a' β†’\n \n 𝒰 a β‰ˆ 𝒰 a'\n | pi {a a' b b'} :\n a β‰ˆ a' β†’\n b β‰ˆ b' β†’\n \n pi a b β‰ˆ pi a' b'\n | abs {a a' b b'} :\n a β‰ˆ a' β†’\n b β‰ˆ b' β†’\n \n abs a b β‰ˆ abs a' b'\n | app {b b' a a'} :\n b β‰ˆ b' β†’\n a β‰ˆ a' β†’\n \n app b a β‰ˆ app b' a'\n | exf {a a' b b'} :\n a β‰ˆ a' β†’\n b β‰ˆ b' β†’\n \n exf a b β‰ˆ exf a' b'\n | lvl {a a'} :\n a β‰ˆ a' β†’\n \n lvl a β‰ˆ lvl a'\n | refl {a} : a β‰ˆ a\n | sym {a b} :\n a β‰ˆ b β†’\n \n b β‰ˆ a\n | trans {a b c} :\n a β‰ˆ b β†’\n b β‰ˆ c β†’\n \n a β‰ˆ c" }, { "name": "Conv", "content": "def Conv (a : Term) (b : Term) : Prop := βˆƒ c, a ⇒⋆ c ∧ b ⇒⋆ c" }, { "name": "Pars", "content": "inductive Pars : Term β†’ Term β†’ Prop where\n | refl a : a ⇒⋆ a\n | trans {a b c} : a β‡’ b β†’ b ⇒⋆ c β†’ a ⇒⋆ c" }, { "name": "substRename", "content": "def substRename ΞΎ Οƒ : βˆ€ s, subst Οƒ (rename ΞΎ s) = subst (Οƒ ∘ ΞΎ) s :=\n substRename' _ _ (Οƒ ∘ ΞΎ) (by admit /- proof elided -/\n )" }, { "name": "renameSubst", "content": "def renameSubst ΞΎ Οƒ : βˆ€ s, rename ΞΎ (subst Οƒ s) = subst (rename ΞΎ ∘ Οƒ) s :=\n renameSubst' _ _ (rename ΞΎ ∘ Οƒ) (by admit /- proof elided -/\n )" }, { "name": "substComp", "content": "def substComp Οƒ Ο„ : βˆ€ s, (subst Οƒ ∘ subst Ο„) s = subst (subst Οƒ ∘ Ο„) s :=\n substComp' _ _ (subst Οƒ ∘ Ο„) (by admit /- proof elided -/\n )" }, { "name": "substId", "content": "def substId : βˆ€ s, subst var s = s :=\n substId' var (by admit /- proof elided -/\n )" }, { "name": "infix:40 \"β‡’\" => Par", "content": "infix:40 \"β‡’\" => Par" }, { "name": "infix:40 \"⇒⋆\" => Pars", "content": "infix:40 \"⇒⋆\" => Pars" }, { "name": "infix:40 \"⇔\" => Conv", "content": "infix:40 \"⇔\" => Conv" }, { "name": "infixr:50 \"+:\" => cons", "content": "infixr:50 \"+:\" => cons" }, { "name": "prefix:95 \"⇑\" => up", "content": "prefix:95 \"⇑\" => up" }, { "name": "notation:50 \"⬝\" => Ctxt.nil", "content": "notation:50 \"⬝\" => Ctxt.nil" }, { "name": "infixl:50 \"∷\" => Ctxt.cons", "content": "infixl:50 \"∷\" => Ctxt.cons" }, { "name": "notation:40 Ξ“:41 \"βˆ‹\" x:41 \"∢\" A:41 => In x A Ξ“", "content": "notation:40 Ξ“:41 \"βˆ‹\" x:41 \"∢\" A:41 => In x A Ξ“" }, { "name": "infix:40 (priority := 1001) \"β‰ˆ\" => Eqv", "content": "infix:40 (priority := 1001) \"β‰ˆ\" => Eqv" }, { "name": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“", "content": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“" }, { "name": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A", "content": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A" } ]
[ { "name": "trans", "module": "Mathlib.Order.Defs.Unbundled" } ]
[ { "name": "renameLiftRename", "content": "theorem renameLiftRename ΞΎ a : rename succ (rename ΞΎ a) = rename (lift ΞΎ) (rename succ a)" }, { "name": "liftSucc", "content": "omit lc in\ntheorem liftSucc ΞΎ : βˆ€ x, (lift ΞΎ ∘ succ) x = (succ ∘ ΞΎ) x" }, { "name": "renameComp", "content": "theorem renameComp ΞΎ ΞΆ s : rename ΞΎ (rename ΞΆ s) = rename (ΞΎ ∘ ΞΆ) s" }, { "name": "renameComp'", "content": "theorem renameComp' ΞΎ ΞΆ Ο‚ (h : βˆ€ x, (ΞΎ ∘ ΞΆ) x = Ο‚ x) : βˆ€ s, (rename ΞΎ ∘ rename ΞΆ) s = rename Ο‚ s" }, { "name": "liftComp", "content": "omit lc in\ntheorem liftComp ΞΎ ΞΆ Ο‚ (h : βˆ€ x, (ΞΎ ∘ ΞΆ) x = Ο‚ x) :\n βˆ€ x, (lift ΞΎ ∘ lift ΞΆ) x = lift Ο‚ x" }, { "name": "renameExt", "content": "theorem renameExt ΞΎ ΞΆ (h : βˆ€ x, ΞΎ x = ΞΆ x) : βˆ€ s, rename ΞΎ s = rename ΞΆ s" }, { "name": "liftExt", "content": "omit lc in\ntheorem liftExt ΞΎ ΞΆ (h : βˆ€ x, ΞΎ x = ΞΆ x) : βˆ€ x, lift ΞΎ x = lift ΞΆ x" }, { "name": "wtfPiInvA", "content": "theorem wtfPiInvA {Ξ“ A B 𝒰'}\n (h : Ξ“ ⊒ pi A B ∢ 𝒰') :\n βˆƒ j, Ξ“ ⊒ A ∢ 𝒰 j" }, { "name": "wtfPiInvA𝒰", "content": "theorem wtfPiInvA𝒰 {Ξ“ A B 𝒰'}\n (h : Ξ“ ⊒ pi A B ∢ 𝒰') :\n βˆƒ j, Ξ“ ⊒ A ∢ 𝒰 j ∧ 𝒰 j β‰ˆ 𝒰'" }, { "name": "eqvConv", "content": "theorem eqvConv {a b} (r : a β‰ˆ b) : a ⇔ b" }, { "name": "convRename", "content": "theorem convRename {a b} ΞΎ : a ⇔ b β†’ rename ΞΎ a ⇔ rename ΞΎ b" }, { "name": "parsRename", "content": "theorem parsRename {a b} ΞΎ (r : a ⇒⋆ b) : rename ΞΎ a ⇒⋆ rename ΞΎ b" }, { "name": "parRename", "content": "theorem parRename {a b} ΞΎ (r : a β‡’ b) : rename ΞΎ a β‡’ rename ΞΎ b" }, { "name": "renameDist", "content": "theorem renameDist ΞΎ a s : subst (rename ΞΎ a +: var) (rename (lift ΞΎ) s) = rename ΞΎ (subst (a +: var) s)" }, { "name": "substExt", "content": "theorem substExt Οƒ Ο„ (h : βˆ€ x, Οƒ x = Ο„ x) : βˆ€ s, subst Οƒ s = subst Ο„ s" }, { "name": "upExt", "content": "theorem upExt Οƒ Ο„ (h : βˆ€ x, Οƒ x = Ο„ x) : βˆ€ x, (⇑ Οƒ) x = (⇑ Ο„) x" }, { "name": "wRenameLift", "content": "theorem wRenameLift {ΞΎ : β„• β†’ β„•} {Ξ“ Ξ” A}\n (h : Ξ” ⊒ ΞΎ ∢ Ξ“) :\n Ξ” ∷ (rename ΞΎ A) ⊒ lift ΞΎ ∢ Ξ“ ∷ A" }, { "name": "inHere", "content": "theorem inHere {Ξ“ A A'} (e : A' = rename succ A) : (Ξ“ ∷ A) βˆ‹ 0 ∢ A'" }, { "name": "inThere", "content": "theorem inThere {Ξ“ x A A' B} (h : Ξ“ βˆ‹ x ∢ A) (e : A' = rename succ A) : Ξ“ ∷ B βˆ‹ succ x ∢ A'" }, { "name": "convEqv", "content": "theorem convEqv {a b} : a ⇔ b β†’ a β‰ˆ b" }, { "name": "parsEqv", "content": "theorem parsEqv {a b} (r : a ⇒⋆ b) : a β‰ˆ b" }, { "name": "parEqv", "content": "theorem parEqv {a b} (r : a β‡’ b) : a β‰ˆ b" }, { "name": "wRenameSucc", "content": "theorem wRenameSucc {Ξ“ A} : Ξ“ ∷ A ⊒ succ ∢ Ξ“" }, { "name": "renameUpSubst", "content": "theorem renameUpSubst Οƒ a : rename succ (subst Οƒ a) = subst (⇑ Οƒ) (rename succ a)" }, { "name": "upSucc", "content": "theorem upSucc Οƒ : βˆ€ x, (⇑ Οƒ ∘ succ) x = (rename succ ∘ Οƒ) x" }, { "name": "wtWf", "content": "theorem wtWf {Ξ“} {a A : Term} (h : Ξ“ ⊒ a ∢ A) : ⊒ Ξ“" }, { "name": "convSubst", "content": "theorem convSubst {a b} Οƒ : a ⇔ b β†’ subst Οƒ a ⇔ subst Οƒ b" }, { "name": "parsSubst", "content": "theorem parsSubst {a b} Οƒ (r : a ⇒⋆ b) : subst Οƒ a ⇒⋆ subst Οƒ b" }, { "name": "parSubst", "content": "theorem parSubst {a b} Οƒ (r : a β‡’ b) : subst Οƒ a β‡’ subst Οƒ b" }, { "name": "parRefl", "content": "theorem parRefl a : a β‡’ a" }, { "name": "parMorphing", "content": "theorem parMorphing {a b} Οƒ Ο„ (h : βˆ€ x, Οƒ x β‡’ Ο„ x) (r : a β‡’ b) : subst Οƒ a β‡’ subst Ο„ b" }, { "name": "parLift", "content": "theorem parLift Οƒ Ο„ (h : βˆ€ x, Οƒ x β‡’ Ο„ x) : βˆ€ x, (⇑ Οƒ) x β‡’ (⇑ Ο„) x" }, { "name": "substDist", "content": "theorem substDist Οƒ a s : subst (subst Οƒ a +: var) (subst (⇑ Οƒ) s) = subst Οƒ (subst (a +: var) s)" }, { "name": "substUnion", "content": "theorem substUnion Οƒ a s : subst (a +: Οƒ) s = subst (a +: var) (subst (⇑ Οƒ) s)" }, { "name": "substDropAll", "content": "theorem substDropAll a b : b = subst (a +: var) (rename succ b)" } ]
[]
[ { "name": "wtRename", "content": "theorem wtRename {ΞΎ : β„• β†’ β„•} {Ξ“ Ξ”} {a A : Term}\n (hΞΎ : Ξ” ⊒ ΞΎ ∢ Ξ“) (hΞ” : ⊒ Ξ”) (h : Ξ“ ⊒ a ∢ A) :\n Ξ” ⊒ rename ΞΎ a ∢ rename ΞΎ A" }, { "name": "wtWeaken", "content": "theorem wtWeaken {Ξ“ k} {a A B : Term}\n (hΞ“ : ⊒ Ξ“) (hB : Ξ“ ⊒ B ∢ 𝒰 k) (h : Ξ“ ⊒ a ∢ A) :\n Ξ“ ∷ B ⊒ rename succ a ∢ rename succ A" }, { "name": "wSubstUp", "content": "theorem wSubstUp {Οƒ Ξ” Ξ“ k A}\n (hA : Ξ” ⊒ subst Οƒ A ∢ 𝒰 k)\n (h : Ξ” ⊒ Οƒ ∢ Ξ“) :\n Ξ” ∷ subst Οƒ A ⊒ ⇑ Οƒ ∢ Ξ“ ∷ A" } ]
import Β«srcΒ».typing open Nat open Term variable [LevelClass] notation:40 Ξ”:41 "⊒" Οƒ:41 "∢" Ξ“:41 => wSubst Οƒ Ξ“ Ξ”
theorem wtMorph {Οƒ : β„• β†’ Term} {Ξ“ Ξ”} {a A : Term} (hΟƒ : Ξ” ⊒ Οƒ ∢ Ξ“) (hΞ” : ⊒ Ξ”) (h : Ξ“ ⊒ a ∢ A) : Ξ” ⊒ subst Οƒ a ∢ subst Οƒ A :=
:= by induction h generalizing Οƒ Ξ” case var mem _ => exact hΟƒ _ _ mem case 𝒰 ih => exact Wt.𝒰 (ih hΟƒ hΞ”) case pi ihA ihB => let ihA' := ihA hΟƒ hΞ” refine Wt.pi ihA' ?_ rw [renameUpSubst] exact ihB (wSubstUp ihA' hΟƒ) (Wf.cons hΞ” ihA') case abs ihPi ihA ihb => let ihPi' := ihPi hΟƒ hΞ” let ⟨k, hA⟩ := wtfPiInvA ihPi' exact Wt.abs ihPi' (ihA hΟƒ hΞ”) (ihb (wSubstUp hA hΟƒ) (Wf.cons hΞ” hA)) case app ihb iha => rw [← substDist]; exact Wt.app (ihb hΟƒ hΞ”) (iha hΟƒ hΞ”) case mty ih => exact Wt.mty (ih hΟƒ hΞ”) case exf ihb ihA => exact Wt.exf (ihb hΟƒ hΞ”) (ihA hΟƒ hΞ”) case lvl iha ihj => exact Wt.lvl (iha hΟƒ hΞ”) (ihj hΟƒ hΞ”) case lof => constructor <;> assumption case trans ihi ihj => exact Wt.trans (ihi hΟƒ hΞ”) (ihj hΟƒ hΞ”) case conv e _ _ iha ihA => refine Wt.conv (convEqv (convSubst Οƒ (eqvConv e))) (iha hΟƒ hΞ”) (ihA hΟƒ hΞ”) case sub ihj ihA => exact Wt.sub (ihj hΟƒ hΞ”) (ihA hΟƒ hΞ”)
8
69
false
Type systems
424
antirenaming
theorem antirenaming {ΞΎ a b'} (r : rename ΞΎ a β‡’ b') : βˆƒ b, b' = rename ΞΎ b ∧ a β‡’ b
TTBFL
src/reduction.lean
[ "import src.syntactics", "import Β«srcΒ».syntactics", "import Β«srcΒ».tactics" ]
[ { "name": "Inhabited", "module": "Init.Prelude" }, { "name": "Lean.ToExpr", "module": "Lean.ToExpr" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Repr", "module": "Init.Data.Repr" }, { "name": "String", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "Nat.succ", "module": "Init.Prelude" }, { "name": "Nat.zero", "module": "Init.Prelude" } ]
[ { "name": "Term", "content": "inductive Term : Type where\n | var : Nat β†’ Term\n | 𝒰 : Term β†’ Term\n | pi : Term β†’ Term β†’ Term\n | abs : Term β†’ Term β†’ Term\n | app : Term β†’ Term β†’ Term\n | mty : Term\n | exf : Term β†’ Term β†’ Term\n | lvl : Term β†’ Term\n | lof : lc.L β†’ Term" }, { "name": "subst", "content": "@[simp]\ndef subst (Οƒ : Nat β†’ Term) : Term β†’ Term\n | var s => Οƒ s\n | 𝒰 a => 𝒰 (subst Οƒ a)\n | pi a b => pi (subst Οƒ a) (subst (⇑ Οƒ) b)\n | abs a b => abs (subst Οƒ a) (subst (⇑ Οƒ) b)\n | app b a => app (subst Οƒ b) (subst Οƒ a)\n | mty => mty\n | exf a b => exf (subst Οƒ a) (subst Οƒ b)\n | lvl a => lvl (subst Οƒ a)\n | lof k => lof k" }, { "name": "Par", "content": "inductive Par : Term β†’ Term β†’ Prop where\n | Ξ² {b b' a a' c} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app (abs c b) a β‡’ subst (a' +: var) b'\n | var s : var s β‡’ var s\n | 𝒰 {a a'} :\n a β‡’ a' β†’\n \n 𝒰 a β‡’ 𝒰 a'\n | pi {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n pi a b β‡’ pi a' b'\n | abs {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n abs a b β‡’ abs a' b'\n | app {b b' a a'} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app b a β‡’ app b' a'\n | mty : mty β‡’ mty\n | exf {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n exf a b β‡’ exf a' b'\n | lvl {a a'} :\n a β‡’ a' β†’\n \n lvl a β‡’ lvl a'\n | lof k : lof k β‡’ lof k" }, { "name": "Pars", "content": "inductive Pars : Term β†’ Term β†’ Prop where\n | refl a : a ⇒⋆ a\n | trans {a b c} : a β‡’ b β†’ b ⇒⋆ c β†’ a ⇒⋆ c" }, { "name": "infix:40 \"⇒⋆\" => Pars", "content": "infix:40 \"⇒⋆\" => Pars" }, { "name": "nf", "content": "@[simp]\ndef nf : Term β†’ Prop\n | 𝒰 a => nf a\n | pi a b => nf a ∧ nf b\n | abs a b => nf a ∧ nf b\n | app b a => ne b ∧ nf a\n | exf a b => nf a ∧ ne b\n | lvl a => nf a\n | _ => True" }, { "name": "ne", "content": "@[simp]\ndef ne : Term β†’ Prop\n | var _ => True\n | app b a => ne b ∧ nf a\n | exf a b => nf a ∧ ne b\n | _ => False" }, { "name": "wnf", "content": "@[simp] def wnf (a : Term) : Prop := βˆƒ b, nf b ∧ a ⇒⋆ b" }, { "name": "wne", "content": "@[simp] def wne (a : Term) : Prop := βˆƒ b, ne b ∧ a ⇒⋆ b" }, { "name": "rename", "content": "@[simp]\ndef rename (ΞΎ : Nat β†’ Nat) : Term β†’ Term\n | var s => var (ΞΎ s)\n | 𝒰 a => 𝒰 (rename ΞΎ a)\n | pi a b => pi (rename ΞΎ a) (rename (lift ΞΎ) b)\n | abs a b => abs (rename ΞΎ a) (rename (lift ΞΎ) b)\n | app b a => app (rename ΞΎ b) (rename ΞΎ a)\n | mty => mty\n | exf a b => exf (rename ΞΎ a) (rename ΞΎ b)\n | lvl a => lvl (rename ΞΎ a)\n | lof k => lof k" }, { "name": "lift", "content": "@[simp]\ndef lift (ΞΎ : Nat β†’ Nat) : Nat β†’ Nat :=\n zero +: (succ ∘ ΞΎ)" }, { "name": "cons", "content": "@[simp]\ndef cons {A : Type} (x : A) (ΞΎ : Nat β†’ A) : Nat β†’ A\n | 0 => x\n | n + 1 => ΞΎ n" }, { "name": "substRename", "content": "def substRename ΞΎ Οƒ : βˆ€ s, subst Οƒ (rename ΞΎ s) = subst (Οƒ ∘ ΞΎ) s :=\n substRename' _ _ (Οƒ ∘ ΞΎ) (by admit /- proof elided -/\n )" }, { "name": "renameSubst", "content": "def renameSubst ΞΎ Οƒ : βˆ€ s, rename ΞΎ (subst Οƒ s) = subst (rename ΞΎ ∘ Οƒ) s :=\n renameSubst' _ _ (rename ΞΎ ∘ Οƒ) (by admit /- proof elided -/\n )" }, { "name": "up", "content": "@[simp]\ndef up (Οƒ : Nat β†’ Term) : Nat β†’ Term :=\n var 0 +: (rename succ ∘ Οƒ)" }, { "name": "infixr:50 \"+:\" => cons", "content": "infixr:50 \"+:\" => cons" }, { "name": "prefix:95 \"⇑\" => up", "content": "prefix:95 \"⇑\" => up" } ]
[ { "name": "...", "module": "" } ]
[ { "name": "liftExt", "content": "theorem liftExt ΞΎ ΞΆ (h : βˆ€ x, ΞΎ x = ΞΆ x) : βˆ€ x, lift ΞΎ x = lift ΞΆ x" }, { "name": "liftId", "content": "theorem liftId ΞΎ (h : βˆ€ x, ΞΎ x = x) : βˆ€ x, lift ΞΎ x = x" }, { "name": "liftSucc", "content": "theorem liftSucc ΞΎ : βˆ€ x, (lift ΞΎ ∘ succ) x = (succ ∘ ΞΎ) x" }, { "name": "renameExt", "content": "theorem renameExt ΞΎ ΞΆ (h : βˆ€ x, ΞΎ x = ΞΆ x) : βˆ€ s, rename ΞΎ s = rename ΞΆ s" }, { "name": "renameId", "content": "theorem renameId s : rename id s = s" }, { "name": "renameComp", "content": "theorem renameComp ΞΎ ΞΆ s : rename ΞΎ (rename ΞΆ s) = rename (ΞΎ ∘ ΞΆ) s" }, { "name": "upExt", "content": "theorem upExt Οƒ Ο„ (h : βˆ€ x, Οƒ x = Ο„ x) : βˆ€ x, (⇑ Οƒ) x = (⇑ Ο„) x" }, { "name": "upSucc", "content": "theorem upSucc Οƒ : βˆ€ x, (⇑ Οƒ ∘ succ) x = (rename succ ∘ Οƒ) x" }, { "name": "substExt", "content": "theorem substExt Οƒ Ο„ (h : βˆ€ x, Οƒ x = Ο„ x) : βˆ€ s, subst Οƒ s = subst Ο„ s" }, { "name": "substId'", "content": "theorem substId' Οƒ (h : βˆ€ x, Οƒ x = var x) : βˆ€ s, subst Οƒ s = s" }, { "name": "substRename'", "content": "theorem substRename' ΞΎ Οƒ Ο„ (h : βˆ€ x, (Οƒ ∘ ΞΎ) x = Ο„ x) : βˆ€ s, subst Οƒ (rename ΞΎ s) = subst Ο„ s" }, { "name": "renameSubst'", "content": "theorem renameSubst' ΞΎ Οƒ Ο„ (h : βˆ€ x, (rename ΞΎ ∘ Οƒ) x = Ο„ x) : βˆ€ s, rename ΞΎ (subst Οƒ s) = subst Ο„ s" }, { "name": "renameDist", "content": "theorem renameDist ΞΎ a s : subst (rename ΞΎ a +: var) (rename (lift ΞΎ) s) = rename ΞΎ (subst (a +: var) s)" }, { "name": "substDrop", "content": "theorem substDrop Οƒ a b : subst (a +: Οƒ) (rename succ b) = subst Οƒ b" }, { "name": "substUnion", "content": "theorem substUnion Οƒ a s : subst (a +: Οƒ) s = subst (a +: var) (subst (⇑ Οƒ) s)" }, { "name": "neNf", "content": "theorem neNf {a} : ne a β†’ nf a" }, { "name": "nfPars", "content": "theorem nfPars {a b} (r : a ⇒⋆ b) : nf a β†’ nf b" }, { "name": "nePars", "content": "theorem nePars {a b} (r : a ⇒⋆ b) : ne a β†’ ne b" }, { "name": "wnfRename", "content": "theorem wnfRename {ΞΎ a} : wnf (rename ΞΎ a) β†’ wnf a" }, { "name": "wneRename", "content": "theorem wneRename {ΞΎ a} : wne (rename ΞΎ a) β†’ wne a" }, { "name": "renameToSubst", "content": "theorem renameToSubst ΞΎ : βˆ€ s, rename ΞΎ s = subst (var ∘ ΞΎ) s" }, { "name": "renameLiftRename", "content": "theorem renameLiftRename ΞΎ a : rename succ (rename ΞΎ a) = rename (lift ΞΎ) (rename succ a)" }, { "name": "renameUpSubst", "content": "theorem renameUpSubst Οƒ a : rename succ (subst Οƒ a) = subst (⇑ Οƒ) (rename succ a)" }, { "name": "substDropAll", "content": "theorem substDropAll a b : b = subst (a +: var) (rename succ b)" }, { "name": "wnfBwds", "content": "theorem wnfBwds {a b} (r : a ⇒⋆ b) : wnf b β†’ wnf a" }, { "name": "wneBwds", "content": "theorem wneBwds {a b} (r : a ⇒⋆ b) : wne b β†’ wne a" }, { "name": "wnfFwds", "content": "theorem wnfFwds {a b} (r : a ⇒⋆ b) : wnf a β†’ wnf b" }, { "name": "wneFwds", "content": "theorem wneFwds {a b} (r : a ⇒⋆ b) : wne a β†’ wne b" } ]
[ { "name": "Par", "content": "inductive Par : Term β†’ Term β†’ Prop where\n | Ξ² {b b' a a' c} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app (abs c b) a β‡’ subst (a' +: var) b'\n | var s : var s β‡’ var s\n | 𝒰 {a a'} :\n a β‡’ a' β†’\n \n 𝒰 a β‡’ 𝒰 a'\n | pi {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n pi a b β‡’ pi a' b'\n | abs {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n abs a b β‡’ abs a' b'\n | app {b b' a a'} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app b a β‡’ app b' a'\n | mty : mty β‡’ mty\n | exf {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n exf a b β‡’ exf a' b'\n | lvl {a a'} :\n a β‡’ a' β†’\n \n lvl a β‡’ lvl a'\n | lof k : lof k β‡’ lof k" } ]
[ { "name": "parRefl", "content": "theorem parRefl a : a β‡’ a" } ]
import Β«srcΒ».tactics import Β«srcΒ».syntactics open Term variable [LevelClass] section inductive Par : Term β†’ Term β†’ Prop where | Ξ² {b b' a a' c} : b β‡’ b' β†’ a β‡’ a' β†’ app (abs c b) a β‡’ subst (a' +: var) b' | var s : var s β‡’ var s | 𝒰 {a a'} : a β‡’ a' β†’ 𝒰 a β‡’ 𝒰 a' | pi {a a' b b'} : a β‡’ a' β†’ b β‡’ b' β†’ pi a b β‡’ pi a' b' | abs {a a' b b'} : a β‡’ a' β†’ b β‡’ b' β†’ abs a b β‡’ abs a' b' | app {b b' a a'} : b β‡’ b' β†’ a β‡’ a' β†’ app b a β‡’ app b' a' | mty : mty β‡’ mty | exf {a a' b b'} : a β‡’ a' β†’ b β‡’ b' β†’ exf a b β‡’ exf a' b' | lvl {a a'} : a β‡’ a' β†’ lvl a β‡’ lvl a' | lof k : lof k β‡’ lof k end infix:40 "β‡’" => Par
theorem antirenaming {ΞΎ a b'} (r : rename ΞΎ a β‡’ b') : βˆƒ b, b' = rename ΞΎ b ∧ a β‡’ b :=
:= by generalize e : rename ΞΎ a = a' at r induction r generalizing ΞΎ a all_goals cases a <;> injections; subst_eqs; specialize_rfls case Ξ² ihb b _ e _ iha => cases b <;> injections; subst_eqs; specialize_rfls let ⟨a, ea, ra⟩ := iha let ⟨b, eb, rb⟩ := ihb subst ea; subst eb exact ⟨subst (a +: var) b, renameDist ΞΎ a b, Par.Ξ² rb ra⟩ case var => exact ⟨var _, rfl, parRefl _⟩ case 𝒰 ih => let ⟨a, e, r⟩ := ih subst e exact βŸ¨π’° a, rfl, Par.𝒰 r⟩ case pi iha ihb => let ⟨a, ea, ra⟩ := iha let ⟨b, eb, rb⟩ := ihb subst ea; subst eb exact ⟨pi a b, rfl, Par.pi ra rb⟩ case abs iha ihb => let ⟨a, ea, ra⟩ := iha let ⟨b, eb, rb⟩ := ihb subst ea; subst eb exact ⟨abs a b, rfl, Par.abs ra rb⟩ case app ihb iha => let ⟨a, ea, ra⟩ := iha let ⟨b, eb, rb⟩ := ihb subst ea; subst eb exact ⟨app b a, rfl, Par.app rb ra⟩ case mty => exact ⟨mty, rfl, Par.mty⟩ case exf iha ihb => let ⟨a, ea, ra⟩ := iha let ⟨b, eb, rb⟩ := ihb subst ea; subst eb exact ⟨exf a b, rfl, Par.exf ra rb⟩ case lvl ih => let ⟨a, e, r⟩ := ih subst e exact ⟨lvl a, rfl, Par.lvl r⟩ case lof => exact ⟨lof _, rfl, parRefl _⟩
4
23
false
Type systems
425
wtRegularity
theorem wtRegularity {Ξ“} {a A : Term} (h : Ξ“ ⊒ a ∢ A) : βˆƒ k, Ξ“ ⊒ A ∢ 𝒰 k
TTBFL
src/safety.lean
[ "import Β«srcΒ».typing", "import src.syntactics", "import src.reduction", "import src.typing" ]
[ { "name": "DecidableEq", "module": "Init.Prelude" }, { "name": "Lean.ToExpr", "module": "Lean.ToExpr" }, { "name": "List", "module": "Init.Prelude" }, { "name": "Repr", "module": "Init.Data.Repr" }, { "name": "Inhabited", "module": "Init.Prelude" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "String", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "Nat.sub", "module": "Init.Prelude" }, { "name": "Nat.succ", "module": "Init.Prelude" }, { "name": "Nat.zero", "module": "Init.Prelude" } ]
[ { "name": "notation:40 Ξ”:41 \"⊒\" ΞΎ:41 \"∢\" Ξ“:41 => wRename ΞΎ Ξ“ Ξ”", "content": "notation:40 Ξ”:41 \"⊒\" ΞΎ:41 \"∢\" Ξ“:41 => wRename ΞΎ Ξ“ Ξ”" }, { "name": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“", "content": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“" }, { "name": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A", "content": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A" }, { "name": "notation:40 Ξ”:41 \"⊒\" Οƒ:41 \"∢\" Ξ“:41 => wSubst Οƒ Ξ“ Ξ”", "content": "notation:40 Ξ”:41 \"⊒\" Οƒ:41 \"∢\" Ξ“:41 => wSubst Οƒ Ξ“ Ξ”" }, { "name": "notation:40 Ξ“:41 \"βˆ‹\" x:41 \"∢\" A:41 => In x A Ξ“", "content": "notation:40 Ξ“:41 \"βˆ‹\" x:41 \"∢\" A:41 => In x A Ξ“" }, { "name": "Term", "content": "inductive Term : Type where\n | var : Nat β†’ Term\n | 𝒰 : Term β†’ Term\n | pi : Term β†’ Term β†’ Term\n | abs : Term β†’ Term β†’ Term\n | app : Term β†’ Term β†’ Term\n | mty : Term\n | exf : Term β†’ Term β†’ Term\n | lvl : Term β†’ Term\n | lof : lc.L β†’ Term" }, { "name": "Wf", "content": "inductive Wf : Ctxt β†’ Prop where\n | nil : ⊒ ⬝\n | cons {Ξ“ A k} :\n ⊒ Ξ“ β†’\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n \n ⊒ Ξ“ ∷ A" }, { "name": "Ctxt", "content": "inductive Ctxt : Type where\n | nil : Ctxt\n | cons : Ctxt β†’ Term β†’ Ctxt" }, { "name": "subst", "content": "@[simp]\ndef subst (Οƒ : Nat β†’ Term) : Term β†’ Term\n | var s => Οƒ s\n | 𝒰 a => 𝒰 (subst Οƒ a)\n | pi a b => pi (subst Οƒ a) (subst (⇑ Οƒ) b)\n | abs a b => abs (subst Οƒ a) (subst (⇑ Οƒ) b)\n | app b a => app (subst Οƒ b) (subst Οƒ a)\n | mty => mty\n | exf a b => exf (subst Οƒ a) (subst Οƒ b)\n | lvl a => lvl (subst Οƒ a)\n | lof k => lof k" }, { "name": "Par", "content": "inductive Par : Term β†’ Term β†’ Prop where\n | Ξ² {b b' a a' c} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app (abs c b) a β‡’ subst (a' +: var) b'\n | var s : var s β‡’ var s\n | 𝒰 {a a'} :\n a β‡’ a' β†’\n \n 𝒰 a β‡’ 𝒰 a'\n | pi {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n pi a b β‡’ pi a' b'\n | abs {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n abs a b β‡’ abs a' b'\n | app {b b' a a'} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app b a β‡’ app b' a'\n | mty : mty β‡’ mty\n | exf {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n exf a b β‡’ exf a' b'\n | lvl {a a'} :\n a β‡’ a' β†’\n \n lvl a β‡’ lvl a'\n | lof k : lof k β‡’ lof k" }, { "name": "Wt", "content": "inductive Wt : Ctxt β†’ Term β†’ Term β†’ Prop where\n | var {Ξ“ x A} :\n ⊒ Ξ“ β†’\n Ξ“ βˆ‹ x ∢ A β†’\n \n Ξ“ ⊒ var x ∢ A\n | 𝒰 {Ξ“ j k} :\n Ξ“ ⊒ j ∢ lvl k β†’\n \n Ξ“ ⊒ 𝒰 j ∢ 𝒰 k\n | pi {Ξ“ A B k} :\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n Ξ“ ∷ A ⊒ B ∢ 𝒰 (rename succ k) β†’\n \n Ξ“ ⊒ pi A B ∢ 𝒰 k\n | abs {Ξ“ A B b k} :\n Ξ“ ⊒ pi A B ∢ 𝒰 k β†’\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n Ξ“ ∷ A ⊒ b ∢ B β†’\n \n Ξ“ ⊒ abs A b ∢ pi A B\n | app {Ξ“ A B b a} :\n Ξ“ ⊒ b ∢ pi A B β†’\n Ξ“ ⊒ a ∢ A β†’\n \n Ξ“ ⊒ app b a ∢ subst (a +: var) B\n | mty {Ξ“ j k} :\n Ξ“ ⊒ 𝒰 j ∢ 𝒰 k β†’\n \n Ξ“ ⊒ mty ∢ 𝒰 j\n | exf {Ξ“ A b k} :\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n Ξ“ ⊒ b ∢ mty β†’\n \n Ξ“ ⊒ exf A b ∢ A\n | lvl {Ξ“ a b j k} :\n Ξ“ ⊒ a ∢ lvl b β†’\n Ξ“ ⊒ 𝒰 j ∢ 𝒰 k β†’\n \n Ξ“ ⊒ lvl a ∢ 𝒰 j\n | lof {Ξ“ j k} :\n ⊒ Ξ“ β†’\n j < k β†’\n \n Ξ“ ⊒ lof j ∢ lvl (lof k)\n | trans {Ξ“ i j k} :\n Ξ“ ⊒ i ∢ lvl j β†’\n Ξ“ ⊒ j ∢ lvl k β†’\n \n Ξ“ ⊒ i ∢ lvl k\n | conv {Ξ“ A B a k} :\n A β‰ˆ B β†’\n Ξ“ ⊒ a ∢ A β†’\n Ξ“ ⊒ B ∢ 𝒰 k β†’\n \n Ξ“ ⊒ a ∢ B\n | sub {Ξ“ j k A} :\n Ξ“ ⊒ j ∢ lvl k β†’\n Ξ“ ⊒ A ∢ 𝒰 j β†’\n \n Ξ“ ⊒ A ∢ 𝒰 k" }, { "name": "up", "content": "@[simp]\ndef up (Οƒ : Nat β†’ Term) : Nat β†’ Term :=\n var 0 +: (rename succ ∘ Οƒ)" }, { "name": "rename", "content": "@[simp]\ndef rename (ΞΎ : Nat β†’ Nat) : Term β†’ Term\n | var s => var (ΞΎ s)\n | 𝒰 a => 𝒰 (rename ΞΎ a)\n | pi a b => pi (rename ΞΎ a) (rename (lift ΞΎ) b)\n | abs a b => abs (rename ΞΎ a) (rename (lift ΞΎ) b)\n | app b a => app (rename ΞΎ b) (rename ΞΎ a)\n | mty => mty\n | exf a b => exf (rename ΞΎ a) (rename ΞΎ b)\n | lvl a => lvl (rename ΞΎ a)\n | lof k => lof k" }, { "name": "lift", "content": "@[simp]\ndef lift (ΞΎ : Nat β†’ Nat) : Nat β†’ Nat :=\n zero +: (succ ∘ ΞΎ)" }, { "name": "cons", "content": "@[simp]\ndef cons {A : Type} (x : A) (ΞΎ : Nat β†’ A) : Nat β†’ A\n | 0 => x\n | n + 1 => ΞΎ n" }, { "name": "In", "content": "inductive In : Nat β†’ Term β†’ Ctxt β†’ Prop where\n | here {Ξ“ A} : In 0 (rename succ A) (Ξ“ ∷ A)\n | there {Ξ“ x A B} : In x A Ξ“ β†’ In (succ x) (rename succ A) (Ξ“ ∷ B)" }, { "name": "Eqv", "content": "inductive Eqv : Term β†’ Term β†’ Prop where\n | Ξ² {b a c} : app (abs c b) a β‰ˆ subst (a +: var) b\n | 𝒰 {a a'} :\n a β‰ˆ a' β†’\n \n 𝒰 a β‰ˆ 𝒰 a'\n | pi {a a' b b'} :\n a β‰ˆ a' β†’\n b β‰ˆ b' β†’\n \n pi a b β‰ˆ pi a' b'\n | abs {a a' b b'} :\n a β‰ˆ a' β†’\n b β‰ˆ b' β†’\n \n abs a b β‰ˆ abs a' b'\n | app {b b' a a'} :\n b β‰ˆ b' β†’\n a β‰ˆ a' β†’\n \n app b a β‰ˆ app b' a'\n | exf {a a' b b'} :\n a β‰ˆ a' β†’\n b β‰ˆ b' β†’\n \n exf a b β‰ˆ exf a' b'\n | lvl {a a'} :\n a β‰ˆ a' β†’\n \n lvl a β‰ˆ lvl a'\n | refl {a} : a β‰ˆ a\n | sym {a b} :\n a β‰ˆ b β†’\n \n b β‰ˆ a\n | trans {a b c} :\n a β‰ˆ b β†’\n b β‰ˆ c β†’\n \n a β‰ˆ c" }, { "name": "Conv", "content": "def Conv (a : Term) (b : Term) : Prop := βˆƒ c, a ⇒⋆ c ∧ b ⇒⋆ c" }, { "name": "Pars", "content": "inductive Pars : Term β†’ Term β†’ Prop where\n | refl a : a ⇒⋆ a\n | trans {a b c} : a β‡’ b β†’ b ⇒⋆ c β†’ a ⇒⋆ c" }, { "name": "substRename", "content": "def substRename ΞΎ Οƒ : βˆ€ s, subst Οƒ (rename ΞΎ s) = subst (Οƒ ∘ ΞΎ) s :=\n substRename' _ _ (Οƒ ∘ ΞΎ) (by admit /- proof elided -/\n )" }, { "name": "renameSubst", "content": "def renameSubst ΞΎ Οƒ : βˆ€ s, rename ΞΎ (subst Οƒ s) = subst (rename ΞΎ ∘ Οƒ) s :=\n renameSubst' _ _ (rename ΞΎ ∘ Οƒ) (by admit /- proof elided -/\n )" }, { "name": "substComp", "content": "def substComp Οƒ Ο„ : βˆ€ s, (subst Οƒ ∘ subst Ο„) s = subst (subst Οƒ ∘ Ο„) s :=\n substComp' _ _ (subst Οƒ ∘ Ο„) (by admit /- proof elided -/\n )" }, { "name": "substId", "content": "def substId : βˆ€ s, subst var s = s :=\n substId' var (by admit /- proof elided -/\n )" }, { "name": "infix:40 \"β‡’\" => Par", "content": "infix:40 \"β‡’\" => Par" }, { "name": "infix:40 \"⇒⋆\" => Pars", "content": "infix:40 \"⇒⋆\" => Pars" }, { "name": "infix:40 \"⇔\" => Conv", "content": "infix:40 \"⇔\" => Conv" }, { "name": "infixr:50 \"+:\" => cons", "content": "infixr:50 \"+:\" => cons" }, { "name": "prefix:95 \"⇑\" => up", "content": "prefix:95 \"⇑\" => up" }, { "name": "notation:50 \"⬝\" => Ctxt.nil", "content": "notation:50 \"⬝\" => Ctxt.nil" }, { "name": "infixl:50 \"∷\" => Ctxt.cons", "content": "infixl:50 \"∷\" => Ctxt.cons" }, { "name": "notation:40 Ξ“:41 \"βˆ‹\" x:41 \"∢\" A:41 => In x A Ξ“", "content": "notation:40 Ξ“:41 \"βˆ‹\" x:41 \"∢\" A:41 => In x A Ξ“" }, { "name": "infix:40 (priority := 1001) \"β‰ˆ\" => Eqv", "content": "infix:40 (priority := 1001) \"β‰ˆ\" => Eqv" }, { "name": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“", "content": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“" }, { "name": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A", "content": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A" } ]
[ { "name": "trans", "module": "Mathlib.Order.Defs.Unbundled" } ]
[ { "name": "renameLiftRename", "content": "theorem renameLiftRename ΞΎ a : rename succ (rename ΞΎ a) = rename (lift ΞΎ) (rename succ a)" }, { "name": "liftSucc", "content": "omit lc in\ntheorem liftSucc ΞΎ : βˆ€ x, (lift ΞΎ ∘ succ) x = (succ ∘ ΞΎ) x" }, { "name": "renameComp", "content": "theorem renameComp ΞΎ ΞΆ s : rename ΞΎ (rename ΞΆ s) = rename (ΞΎ ∘ ΞΆ) s" }, { "name": "renameComp'", "content": "theorem renameComp' ΞΎ ΞΆ Ο‚ (h : βˆ€ x, (ΞΎ ∘ ΞΆ) x = Ο‚ x) : βˆ€ s, (rename ΞΎ ∘ rename ΞΆ) s = rename Ο‚ s" }, { "name": "liftComp", "content": "omit lc in\ntheorem liftComp ΞΎ ΞΆ Ο‚ (h : βˆ€ x, (ΞΎ ∘ ΞΆ) x = Ο‚ x) :\n βˆ€ x, (lift ΞΎ ∘ lift ΞΆ) x = lift Ο‚ x" }, { "name": "renameExt", "content": "theorem renameExt ΞΎ ΞΆ (h : βˆ€ x, ΞΎ x = ΞΆ x) : βˆ€ s, rename ΞΎ s = rename ΞΆ s" }, { "name": "liftExt", "content": "omit lc in\ntheorem liftExt ΞΎ ΞΆ (h : βˆ€ x, ΞΎ x = ΞΆ x) : βˆ€ x, lift ΞΎ x = lift ΞΆ x" }, { "name": "wtfPiInvA", "content": "theorem wtfPiInvA {Ξ“ A B 𝒰'}\n (h : Ξ“ ⊒ pi A B ∢ 𝒰') :\n βˆƒ j, Ξ“ ⊒ A ∢ 𝒰 j" }, { "name": "wtfPiInvA𝒰", "content": "theorem wtfPiInvA𝒰 {Ξ“ A B 𝒰'}\n (h : Ξ“ ⊒ pi A B ∢ 𝒰') :\n βˆƒ j, Ξ“ ⊒ A ∢ 𝒰 j ∧ 𝒰 j β‰ˆ 𝒰'" }, { "name": "eqvConv", "content": "theorem eqvConv {a b} (r : a β‰ˆ b) : a ⇔ b" }, { "name": "convRename", "content": "theorem convRename {a b} ΞΎ : a ⇔ b β†’ rename ΞΎ a ⇔ rename ΞΎ b" }, { "name": "parsRename", "content": "theorem parsRename {a b} ΞΎ (r : a ⇒⋆ b) : rename ΞΎ a ⇒⋆ rename ΞΎ b" }, { "name": "parRename", "content": "theorem parRename {a b} ΞΎ (r : a β‡’ b) : rename ΞΎ a β‡’ rename ΞΎ b" }, { "name": "renameDist", "content": "theorem renameDist ΞΎ a s : subst (rename ΞΎ a +: var) (rename (lift ΞΎ) s) = rename ΞΎ (subst (a +: var) s)" }, { "name": "substExt", "content": "theorem substExt Οƒ Ο„ (h : βˆ€ x, Οƒ x = Ο„ x) : βˆ€ s, subst Οƒ s = subst Ο„ s" }, { "name": "upExt", "content": "theorem upExt Οƒ Ο„ (h : βˆ€ x, Οƒ x = Ο„ x) : βˆ€ x, (⇑ Οƒ) x = (⇑ Ο„) x" }, { "name": "wRenameLift", "content": "theorem wRenameLift {ΞΎ : β„• β†’ β„•} {Ξ“ Ξ” A}\n (h : Ξ” ⊒ ΞΎ ∢ Ξ“) :\n Ξ” ∷ (rename ΞΎ A) ⊒ lift ΞΎ ∢ Ξ“ ∷ A" }, { "name": "inHere", "content": "theorem inHere {Ξ“ A A'} (e : A' = rename succ A) : (Ξ“ ∷ A) βˆ‹ 0 ∢ A'" }, { "name": "inThere", "content": "theorem inThere {Ξ“ x A A' B} (h : Ξ“ βˆ‹ x ∢ A) (e : A' = rename succ A) : Ξ“ ∷ B βˆ‹ succ x ∢ A'" }, { "name": "convEqv", "content": "theorem convEqv {a b} : a ⇔ b β†’ a β‰ˆ b" }, { "name": "parsEqv", "content": "theorem parsEqv {a b} (r : a ⇒⋆ b) : a β‰ˆ b" }, { "name": "parEqv", "content": "theorem parEqv {a b} (r : a β‡’ b) : a β‰ˆ b" }, { "name": "wRenameSucc", "content": "theorem wRenameSucc {Ξ“ A} : Ξ“ ∷ A ⊒ succ ∢ Ξ“" }, { "name": "renameUpSubst", "content": "theorem renameUpSubst Οƒ a : rename succ (subst Οƒ a) = subst (⇑ Οƒ) (rename succ a)" }, { "name": "upSucc", "content": "theorem upSucc Οƒ : βˆ€ x, (⇑ Οƒ ∘ succ) x = (rename succ ∘ Οƒ) x" }, { "name": "wtWf", "content": "theorem wtWf {Ξ“} {a A : Term} (h : Ξ“ ⊒ a ∢ A) : ⊒ Ξ“" }, { "name": "convSubst", "content": "theorem convSubst {a b} Οƒ : a ⇔ b β†’ subst Οƒ a ⇔ subst Οƒ b" }, { "name": "parsSubst", "content": "theorem parsSubst {a b} Οƒ (r : a ⇒⋆ b) : subst Οƒ a ⇒⋆ subst Οƒ b" }, { "name": "parSubst", "content": "theorem parSubst {a b} Οƒ (r : a β‡’ b) : subst Οƒ a β‡’ subst Οƒ b" }, { "name": "parRefl", "content": "theorem parRefl a : a β‡’ a" }, { "name": "parMorphing", "content": "theorem parMorphing {a b} Οƒ Ο„ (h : βˆ€ x, Οƒ x β‡’ Ο„ x) (r : a β‡’ b) : subst Οƒ a β‡’ subst Ο„ b" }, { "name": "parLift", "content": "theorem parLift Οƒ Ο„ (h : βˆ€ x, Οƒ x β‡’ Ο„ x) : βˆ€ x, (⇑ Οƒ) x β‡’ (⇑ Ο„) x" }, { "name": "substDist", "content": "theorem substDist Οƒ a s : subst (subst Οƒ a +: var) (subst (⇑ Οƒ) s) = subst Οƒ (subst (a +: var) s)" }, { "name": "substUnion", "content": "theorem substUnion Οƒ a s : subst (a +: Οƒ) s = subst (a +: var) (subst (⇑ Οƒ) s)" }, { "name": "substDropAll", "content": "theorem substDropAll a b : b = subst (a +: var) (rename succ b)" }, { "name": "wtfLvlInv", "content": "theorem wtfLvlInv {Ξ“ a 𝒰'}\n (h : Ξ“ ⊒ lvl a ∢ 𝒰') :\n βˆƒ b k, Ξ“ ⊒ a ∢ lvl b ∧ 𝒰 k β‰ˆ 𝒰'" }, { "name": "wtfPiInvB", "content": "theorem wtfPiInvB {Ξ“ A B 𝒰'}\n (h : Ξ“ ⊒ pi A B ∢ 𝒰') :\n βˆƒ j, Ξ“ ∷ A ⊒ B ∢ 𝒰 j" } ]
[]
[ { "name": "wtRename", "content": "theorem wtRename {ΞΎ : β„• β†’ β„•} {Ξ“ Ξ”} {a A : Term}\n (hΞΎ : Ξ” ⊒ ΞΎ ∢ Ξ“) (hΞ” : ⊒ Ξ”) (h : Ξ“ ⊒ a ∢ A) :\n Ξ” ⊒ rename ΞΎ a ∢ rename ΞΎ A" }, { "name": "wtWeaken", "content": "theorem wtWeaken {Ξ“ k} {a A B : Term}\n (hΞ“ : ⊒ Ξ“) (hB : Ξ“ ⊒ B ∢ 𝒰 k) (h : Ξ“ ⊒ a ∢ A) :\n Ξ“ ∷ B ⊒ rename succ a ∢ rename succ A" }, { "name": "wSubstUp", "content": "theorem wSubstUp {Οƒ Ξ” Ξ“ k A}\n (hA : Ξ” ⊒ subst Οƒ A ∢ 𝒰 k)\n (h : Ξ” ⊒ Οƒ ∢ Ξ“) :\n Ξ” ∷ subst Οƒ A ⊒ ⇑ Οƒ ∢ Ξ“ ∷ A" }, { "name": "wSubstCons", "content": "theorem wSubstCons {Ξ“} {a A : Term}\n (h : Ξ“ ⊒ a ∢ A) :\n Ξ“ ⊒ a +: var ∢ Ξ“ ∷ A" }, { "name": "wtMorph", "content": "theorem wtMorph {Οƒ : β„• β†’ Term} {Ξ“ Ξ”} {a A : Term}\n (hΟƒ : Ξ” ⊒ Οƒ ∢ Ξ“) (hΞ” : ⊒ Ξ”) (h : Ξ“ ⊒ a ∢ A) :\n Ξ” ⊒ subst Οƒ a ∢ subst Οƒ A" }, { "name": "wtSubst", "content": "theorem wtSubst {Ξ“} {a A b B : Term}\n (hb : Ξ“ ⊒ b ∢ B) (h : Ξ“ ∷ B ⊒ a ∢ A) :\n Ξ“ ⊒ subst (b +: var) a ∢ subst (b +: var) A" }, { "name": "wtMem", "content": "theorem wtMem {Ξ“ x A} (mem : Ξ“ βˆ‹ x ∢ A) (h : ⊒ Ξ“) : βˆƒ k, Ξ“ ⊒ A ∢ 𝒰 k" } ]
import Β«srcΒ».typing open Nat open Term variable [LevelClass] notation:40 Ξ”:41 "⊒" Οƒ:41 "∢" Ξ“:41 => wSubst Οƒ Ξ“ Ξ”
theorem wtRegularity {Ξ“} {a A : Term} (h : Ξ“ ⊒ a ∢ A) : βˆƒ k, Ξ“ ⊒ A ∢ 𝒰 k :=
:= by induction h case var wf mem _ => exact wtMem mem wf case pi ih _ | trans ih => exact ih case abs h _ _ _ _ _ | exf h _ _ _ | conv h _ _ => exact ⟨_, h⟩ case 𝒰 ih => let ⟨_, ihk⟩ := ih let ⟨l, _, hk, _⟩ := wtfLvlInv ihk exact ⟨l, Wt.𝒰 hk⟩ case app ha ihb _ => let ⟨_, hPi⟩ := ihb let ⟨k, hB⟩ := wtfPiInvB hPi exact ⟨subst _ k, wtSubst ha hB⟩ case mty hj _ => exact ⟨_, hj⟩ case lvl hj _ _ => exact ⟨_, hj⟩ case lof k wf _ _ => let ⟨l, klgt⟩ := exists_gt k let ⟨m, lmgt⟩ := exists_gt l refine ⟨lof l, ?_⟩ apply Wt.lvl (Wt.lof wf klgt) apply Wt.𝒰 (Wt.lof wf lmgt) case sub ih _ => let ⟨_, ihk⟩ := ih let ⟨l, _, hk, _⟩ := wtfLvlInv ihk exact ⟨l, Wt.𝒰 hk⟩
10
75
false
Type systems
426
wtProgress
theorem wtProgress {a A : Term} (h : ⬝ ⊒ a ∢ A) : Nonempty (Value a) ∨ βˆƒ b, a β‡’Ξ² b
TTBFL
src/safety.lean
[ "import Β«srcΒ».typing", "import src.reduction", "import src.typing" ]
[ { "name": "Inhabited", "module": "Init.Prelude" }, { "name": "Lean.ToExpr", "module": "Lean.ToExpr" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Repr", "module": "Init.Data.Repr" }, { "name": "String", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "DecidableEq", "module": "Init.Prelude" }, { "name": "List", "module": "Init.Prelude" }, { "name": "Nonempty", "module": "Init.Prelude" }, { "name": "Or", "module": "Init.Prelude" }, { "name": "Or.inr", "module": "Init.Prelude" } ]
[ { "name": "notation:40 Ξ”:41 \"⊒\" ΞΎ:41 \"∢\" Ξ“:41 => wRename ΞΎ Ξ“ Ξ”", "content": "notation:40 Ξ”:41 \"⊒\" ΞΎ:41 \"∢\" Ξ“:41 => wRename ΞΎ Ξ“ Ξ”" }, { "name": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“", "content": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“" }, { "name": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A", "content": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A" }, { "name": "notation:40 Ξ”:41 \"⊒\" Οƒ:41 \"∢\" Ξ“:41 => wSubst Οƒ Ξ“ Ξ”", "content": "notation:40 Ξ”:41 \"⊒\" Οƒ:41 \"∢\" Ξ“:41 => wSubst Οƒ Ξ“ Ξ”" }, { "name": "Term", "content": "inductive Term : Type where\n | var : Nat β†’ Term\n | 𝒰 : Term β†’ Term\n | pi : Term β†’ Term β†’ Term\n | abs : Term β†’ Term β†’ Term\n | app : Term β†’ Term β†’ Term\n | mty : Term\n | exf : Term β†’ Term β†’ Term\n | lvl : Term β†’ Term\n | lof : lc.L β†’ Term" }, { "name": "subst", "content": "@[simp]\ndef subst (Οƒ : Nat β†’ Term) : Term β†’ Term\n | var s => Οƒ s\n | 𝒰 a => 𝒰 (subst Οƒ a)\n | pi a b => pi (subst Οƒ a) (subst (⇑ Οƒ) b)\n | abs a b => abs (subst Οƒ a) (subst (⇑ Οƒ) b)\n | app b a => app (subst Οƒ b) (subst Οƒ a)\n | mty => mty\n | exf a b => exf (subst Οƒ a) (subst Οƒ b)\n | lvl a => lvl (subst Οƒ a)\n | lof k => lof k" }, { "name": "Par", "content": "inductive Par : Term β†’ Term β†’ Prop where\n | Ξ² {b b' a a' c} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app (abs c b) a β‡’ subst (a' +: var) b'\n | var s : var s β‡’ var s\n | 𝒰 {a a'} :\n a β‡’ a' β†’\n \n 𝒰 a β‡’ 𝒰 a'\n | pi {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n pi a b β‡’ pi a' b'\n | abs {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n abs a b β‡’ abs a' b'\n | app {b b' a a'} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app b a β‡’ app b' a'\n | mty : mty β‡’ mty\n | exf {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n exf a b β‡’ exf a' b'\n | lvl {a a'} :\n a β‡’ a' β†’\n \n lvl a β‡’ lvl a'\n | lof k : lof k β‡’ lof k" }, { "name": "Wf", "content": "inductive Wf : Ctxt β†’ Prop where\n | nil : ⊒ ⬝\n | cons {Ξ“ A k} :\n ⊒ Ξ“ β†’\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n \n ⊒ Ξ“ ∷ A" }, { "name": "Ctxt", "content": "inductive Ctxt : Type where\n | nil : Ctxt\n | cons : Ctxt β†’ Term β†’ Ctxt" }, { "name": "Eqv", "content": "inductive Eqv : Term β†’ Term β†’ Prop where\n | Ξ² {b a c} : app (abs c b) a β‰ˆ subst (a +: var) b\n | 𝒰 {a a'} :\n a β‰ˆ a' β†’\n \n 𝒰 a β‰ˆ 𝒰 a'\n | pi {a a' b b'} :\n a β‰ˆ a' β†’\n b β‰ˆ b' β†’\n \n pi a b β‰ˆ pi a' b'\n | abs {a a' b b'} :\n a β‰ˆ a' β†’\n b β‰ˆ b' β†’\n \n abs a b β‰ˆ abs a' b'\n | app {b b' a a'} :\n b β‰ˆ b' β†’\n a β‰ˆ a' β†’\n \n app b a β‰ˆ app b' a'\n | exf {a a' b b'} :\n a β‰ˆ a' β†’\n b β‰ˆ b' β†’\n \n exf a b β‰ˆ exf a' b'\n | lvl {a a'} :\n a β‰ˆ a' β†’\n \n lvl a β‰ˆ lvl a'\n | refl {a} : a β‰ˆ a\n | sym {a b} :\n a β‰ˆ b β†’\n \n b β‰ˆ a\n | trans {a b c} :\n a β‰ˆ b β†’\n b β‰ˆ c β†’\n \n a β‰ˆ c" }, { "name": "Wt", "content": "inductive Wt : Ctxt β†’ Term β†’ Term β†’ Prop where\n | var {Ξ“ x A} :\n ⊒ Ξ“ β†’\n Ξ“ βˆ‹ x ∢ A β†’\n \n Ξ“ ⊒ var x ∢ A\n | 𝒰 {Ξ“ j k} :\n Ξ“ ⊒ j ∢ lvl k β†’\n \n Ξ“ ⊒ 𝒰 j ∢ 𝒰 k\n | pi {Ξ“ A B k} :\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n Ξ“ ∷ A ⊒ B ∢ 𝒰 (rename succ k) β†’\n \n Ξ“ ⊒ pi A B ∢ 𝒰 k\n | abs {Ξ“ A B b k} :\n Ξ“ ⊒ pi A B ∢ 𝒰 k β†’\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n Ξ“ ∷ A ⊒ b ∢ B β†’\n \n Ξ“ ⊒ abs A b ∢ pi A B\n | app {Ξ“ A B b a} :\n Ξ“ ⊒ b ∢ pi A B β†’\n Ξ“ ⊒ a ∢ A β†’\n \n Ξ“ ⊒ app b a ∢ subst (a +: var) B\n | mty {Ξ“ j k} :\n Ξ“ ⊒ 𝒰 j ∢ 𝒰 k β†’\n \n Ξ“ ⊒ mty ∢ 𝒰 j\n | exf {Ξ“ A b k} :\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n Ξ“ ⊒ b ∢ mty β†’\n \n Ξ“ ⊒ exf A b ∢ A\n | lvl {Ξ“ a b j k} :\n Ξ“ ⊒ a ∢ lvl b β†’\n Ξ“ ⊒ 𝒰 j ∢ 𝒰 k β†’\n \n Ξ“ ⊒ lvl a ∢ 𝒰 j\n | lof {Ξ“ j k} :\n ⊒ Ξ“ β†’\n j < k β†’\n \n Ξ“ ⊒ lof j ∢ lvl (lof k)\n | trans {Ξ“ i j k} :\n Ξ“ ⊒ i ∢ lvl j β†’\n Ξ“ ⊒ j ∢ lvl k β†’\n \n Ξ“ ⊒ i ∢ lvl k\n | conv {Ξ“ A B a k} :\n A β‰ˆ B β†’\n Ξ“ ⊒ a ∢ A β†’\n Ξ“ ⊒ B ∢ 𝒰 k β†’\n \n Ξ“ ⊒ a ∢ B\n | sub {Ξ“ j k A} :\n Ξ“ ⊒ j ∢ lvl k β†’\n Ξ“ ⊒ A ∢ 𝒰 j β†’\n \n Ξ“ ⊒ A ∢ 𝒰 k" }, { "name": "Conv", "content": "def Conv (a : Term) (b : Term) : Prop := βˆƒ c, a ⇒⋆ c ∧ b ⇒⋆ c" }, { "name": "Pars", "content": "inductive Pars : Term β†’ Term β†’ Prop where\n | refl a : a ⇒⋆ a\n | trans {a b c} : a β‡’ b β†’ b ⇒⋆ c β†’ a ⇒⋆ c" }, { "name": "infix:40 \"β‡’\" => Par", "content": "infix:40 \"β‡’\" => Par" }, { "name": "infix:40 \"⇒⋆\" => Pars", "content": "infix:40 \"⇒⋆\" => Pars" }, { "name": "infix:40 \"⇔\" => Conv", "content": "infix:40 \"⇔\" => Conv" }, { "name": "notation:50 \"⬝\" => Ctxt.nil", "content": "notation:50 \"⬝\" => Ctxt.nil" }, { "name": "infixl:50 \"∷\" => Ctxt.cons", "content": "infixl:50 \"∷\" => Ctxt.cons" }, { "name": "infix:40 (priority := 1001) \"β‰ˆ\" => Eqv", "content": "infix:40 (priority := 1001) \"β‰ˆ\" => Eqv" }, { "name": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“", "content": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“" }, { "name": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A", "content": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A" } ]
[ { "name": "trans", "module": "Mathlib.Order.Defs.Unbundled" } ]
[ { "name": "wtfLvlInv", "content": "theorem wtfLvlInv {Ξ“ a 𝒰'}\n (h : Ξ“ ⊒ lvl a ∢ 𝒰') :\n βˆƒ b k, Ξ“ ⊒ a ∢ lvl b ∧ 𝒰 k β‰ˆ 𝒰'" }, { "name": "eqvConv", "content": "theorem eqvConv {a b} (r : a β‰ˆ b) : a ⇔ b" }, { "name": "wtfMtyInv", "content": "theorem wtfMtyInv {Ξ“ 𝒰'}\n (h : Ξ“ ⊒ mty ∢ 𝒰') :\n βˆƒ k, 𝒰 k β‰ˆ 𝒰'" }, { "name": "wtfPiInv𝒰", "content": "theorem wtfPiInv𝒰 {Ξ“ A B 𝒰'}\n (h : Ξ“ ⊒ pi A B ∢ 𝒰') :\n βˆƒ j, 𝒰 j β‰ˆ 𝒰'" }, { "name": "wtfPiInvA𝒰", "content": "theorem wtfPiInvA𝒰 {Ξ“ A B 𝒰'}\n (h : Ξ“ ⊒ pi A B ∢ 𝒰') :\n βˆƒ j, Ξ“ ⊒ A ∢ 𝒰 j ∧ 𝒰 j β‰ˆ 𝒰'" }, { "name": "wtfAbsInv", "content": "theorem wtfAbsInv {Ξ“ A' b C}\n (h : Ξ“ ⊒ abs A' b ∢ C) :\n βˆƒ A B, Ξ“ ∷ A ⊒ b ∢ B ∧ A β‰ˆ A' ∧ pi A B β‰ˆ C" }, { "name": "wtfLofInv", "content": "theorem wtfLofInv {Ξ“ j 𝒰'}\n (h : Ξ“ ⊒ lof j ∢ 𝒰') :\n βˆƒ k, lvl k β‰ˆ 𝒰'" }, { "name": "wtf𝒰Inv", "content": "theorem wtf𝒰Inv {Ξ“ j 𝒰'}\n (h : Ξ“ ⊒ 𝒰 j ∢ 𝒰') :\n βˆƒ k, 𝒰 k β‰ˆ 𝒰'" }, { "name": "conv𝒰Pi", "content": "theorem conv𝒰Pi {c a b} : Β¬ 𝒰 c ⇔ pi a b" }, { "name": "parsPiInv", "content": "theorem parsPiInv {a b c} (r : pi a b ⇒⋆ c) : βˆƒ a' b', c = pi a' b' ∧ a ⇒⋆ a' ∧ b ⇒⋆ b'" }, { "name": "pars𝒰Inv", "content": "theorem pars𝒰Inv {a b} (r : 𝒰 a ⇒⋆ b) : βˆƒ a', b = 𝒰 a' ∧ a ⇒⋆ a'" }, { "name": "convLvlPi", "content": "theorem convLvlPi {a b k} : Β¬ lvl k ⇔ pi a b" }, { "name": "parsLvlInv", "content": "theorem parsLvlInv {i b} (r : lvl i ⇒⋆ b) : βˆƒ j, b = lvl j ∧ i ⇒⋆ j" } ]
[ { "name": "Value", "content": "inductive Value : Term β†’ Type where\n | 𝒰 {k} : Value (𝒰 k)\n | pi {a b} : Value (pi a b)\n | abs {a b} : Value (abs a b)\n | mty : Value mty\n | lvl {k} : Value (lvl k)\n | lof {k} : Value (lof k)" }, { "name": "CBN", "content": "inductive CBN : Term β†’ Term β†’ Prop where\n | Ξ² {b a c} : app (abs c b) a β‡’Ξ² subst (a +: var) b\n | app {b b' a} : b β‡’Ξ² b' β†’ app b a β‡’Ξ² app b' a\n | exf {a b b'} : b β‡’Ξ² b' β†’ exf a b β‡’Ξ² exf a b'" }, { "name": "valueType", "content": "@[simp] \ndef valueType {a} (A : Term) : Value a β†’ Prop\n | Value.𝒰 | Value.pi | Value.mty | Value.lvl => βˆƒ k, 𝒰 k β‰ˆ A\n | Value.abs => βˆƒ B C, pi B C β‰ˆ A\n | Value.lof => βˆƒ k, lvl k β‰ˆ A" } ]
[ { "name": "wtValue", "content": "theorem wtValue {Ξ“} {a A B : Term} (h : Ξ“ ⊒ a ∢ A) (e : A β‰ˆ B) : (v : Value a) β†’ valueType B v\n | Value.𝒰 => let ⟨_, eπ’°βŸ©" }, { "name": "wtAbs", "content": "theorem wtAbs {Ξ“} {b A B : Term} (v : Value b) (h : Ξ“ ⊒ b ∢ pi A B) : βˆƒ a' b', b = abs a' b'" } ]
import Β«srcΒ».typing open Nat open Term variable [LevelClass] notation:40 Ξ”:41 "⊒" Οƒ:41 "∢" Ξ“:41 => wSubst Οƒ Ξ“ Ξ” inductive Value : Term β†’ Type where | 𝒰 {k} : Value (𝒰 k) | pi {a b} : Value (pi a b) | abs {a b} : Value (abs a b) | mty : Value mty | lvl {k} : Value (lvl k) | lof {k} : Value (lof k) section inductive CBN : Term β†’ Term β†’ Prop where | Ξ² {b a c} : app (abs c b) a β‡’Ξ² subst (a +: var) b | app {b b' a} : b β‡’Ξ² b' β†’ app b a β‡’Ξ² app b' a | exf {a b b'} : b β‡’Ξ² b' β†’ exf a b β‡’Ξ² exf a b' end infix:40 "β‡’Ξ²" => CBN infix:40 "⇒β⋆" => CBNs @[simp] def valueType {a} (A : Term) : Value a β†’ Prop | Value.𝒰 | Value.pi | Value.mty | Value.lvl => βˆƒ k, 𝒰 k β‰ˆ A | Value.abs => βˆƒ B C, pi B C β‰ˆ A | Value.lof => βˆƒ k, lvl k β‰ˆ A
theorem wtProgress {a A : Term} (h : ⬝ ⊒ a ∢ A) : Nonempty (Value a) ∨ βˆƒ b, a β‡’Ξ² b :=
:= by generalize e : (⬝) = Ξ“ at h induction h all_goals subst e; specialize_rfls case var mem => cases mem case 𝒰 | pi | abs | mty | lvl | lof => repeat constructor case trans ih _ | conv ih _ | sub ih => exact ih case app hb _ ihb _ => cases ihb case inl v => cases v with | intro v => let ⟨_, _, e⟩ := wtAbs v hb; subst e exact Or.inr ⟨_, CBN.β⟩ case inr r => let ⟨_, r⟩ := r; exact Or.inr ⟨_, CBN.app r⟩ case exf _ hb _ ihb => cases ihb case inl v => cases v with | intro v => cases wtMty v hb case inr r => let ⟨_, r⟩ := r; exact Or.inr ⟨_, CBN.exf r⟩
6
40
false
Type systems
427
interpDet'
theorem interpDet' {i I a P Q} (hP : ⟦ a ⟧ i , I β†˜ P) (hQ : ⟦ a ⟧ i , I β†˜ Q) : P = Q
TTBFL
src/candidates.lean
[ "import Β«srcΒ».normal", "import src.reduction", "import src.normal" ]
[ { "name": "Inhabited", "module": "Init.Prelude" }, { "name": "Lean.ToExpr", "module": "Lean.ToExpr" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Repr", "module": "Init.Data.Repr" }, { "name": "String", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "propext", "module": "Init.Core" }, { "name": "Nat.succ", "module": "Init.Prelude" }, { "name": "Nat.zero", "module": "Init.Prelude" }, { "name": "Or", "module": "Init.Prelude" }, { "name": "Or.inl", "module": "Init.Prelude" }, { "name": "Or.inr", "module": "Init.Prelude" } ]
[ { "name": "notation:40 \"⟦\" a \"⟧\" i \",\" I \"β†˜\" P => Interp i I a P", "content": "notation:40 \"⟦\" a \"⟧\" i \",\" I \"β†˜\" P => Interp i I a P" }, { "name": "notation:40 \"⟦\" a \"⟧\" i \"β†˜\" P => Interps i a P", "content": "notation:40 \"⟦\" a \"⟧\" i \"β†˜\" P => Interps i a P" }, { "name": "Pars", "content": "inductive Pars : Term β†’ Term β†’ Prop where\n | refl a : a ⇒⋆ a\n | trans {a b c} : a β‡’ b β†’ b ⇒⋆ c β†’ a ⇒⋆ c" }, { "name": "Par", "content": "inductive Par : Term β†’ Term β†’ Prop where\n | Ξ² {b b' a a' c} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app (abs c b) a β‡’ subst (a' +: var) b'\n | var s : var s β‡’ var s\n | 𝒰 {a a'} :\n a β‡’ a' β†’\n \n 𝒰 a β‡’ 𝒰 a'\n | pi {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n pi a b β‡’ pi a' b'\n | abs {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n abs a b β‡’ abs a' b'\n | app {b b' a a'} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app b a β‡’ app b' a'\n | mty : mty β‡’ mty\n | exf {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n exf a b β‡’ exf a' b'\n | lvl {a a'} :\n a β‡’ a' β†’\n \n lvl a β‡’ lvl a'\n | lof k : lof k β‡’ lof k" }, { "name": "Term", "content": "inductive Term : Type where\n | var : Nat β†’ Term\n | 𝒰 : Term β†’ Term\n | pi : Term β†’ Term β†’ Term\n | abs : Term β†’ Term β†’ Term\n | app : Term β†’ Term β†’ Term\n | mty : Term\n | exf : Term β†’ Term β†’ Term\n | lvl : Term β†’ Term\n | lof : lc.L β†’ Term" }, { "name": "subst", "content": "@[simp]\ndef subst (Οƒ : Nat β†’ Term) : Term β†’ Term\n | var s => Οƒ s\n | 𝒰 a => 𝒰 (subst Οƒ a)\n | pi a b => pi (subst Οƒ a) (subst (⇑ Οƒ) b)\n | abs a b => abs (subst Οƒ a) (subst (⇑ Οƒ) b)\n | app b a => app (subst Οƒ b) (subst Οƒ a)\n | mty => mty\n | exf a b => exf (subst Οƒ a) (subst Οƒ b)\n | lvl a => lvl (subst Οƒ a)\n | lof k => lof k" }, { "name": "nf", "content": "@[simp]\ndef nf : Term β†’ Prop\n | 𝒰 a => nf a\n | pi a b => nf a ∧ nf b\n | abs a b => nf a ∧ nf b\n | app b a => ne b ∧ nf a\n | exf a b => nf a ∧ ne b\n | lvl a => nf a\n | _ => True" }, { "name": "ne", "content": "@[simp]\ndef ne : Term β†’ Prop\n | var _ => True\n | app b a => ne b ∧ nf a\n | exf a b => nf a ∧ ne b\n | _ => False" }, { "name": "LevelClass", "content": "class LevelClass where\n L : Type\n lc : LevelClasses L" }, { "name": "wne", "content": "@[simp] def wne (a : Term) : Prop := βˆƒ b, ne b ∧ a ⇒⋆ b" }, { "name": "up", "content": "@[simp]\ndef up (Οƒ : Nat β†’ Term) : Nat β†’ Term :=\n var 0 +: (rename succ ∘ Οƒ)" }, { "name": "rename", "content": "@[simp]\ndef rename (ΞΎ : Nat β†’ Nat) : Term β†’ Term\n | var s => var (ΞΎ s)\n | 𝒰 a => 𝒰 (rename ΞΎ a)\n | pi a b => pi (rename ΞΎ a) (rename (lift ΞΎ) b)\n | abs a b => abs (rename ΞΎ a) (rename (lift ΞΎ) b)\n | app b a => app (rename ΞΎ b) (rename ΞΎ a)\n | mty => mty\n | exf a b => exf (rename ΞΎ a) (rename ΞΎ b)\n | lvl a => lvl (rename ΞΎ a)\n | lof k => lof k" }, { "name": "lift", "content": "@[simp]\ndef lift (ΞΎ : Nat β†’ Nat) : Nat β†’ Nat :=\n zero +: (succ ∘ ΞΎ)" }, { "name": "cons", "content": "@[simp]\ndef cons {A : Type} (x : A) (ΞΎ : Nat β†’ A) : Nat β†’ A\n | 0 => x\n | n + 1 => ΞΎ n" }, { "name": "wnf", "content": "@[simp] def wnf (a : Term) : Prop := βˆƒ b, nf b ∧ a ⇒⋆ b" }, { "name": "taka", "content": "@[simp]\ndef taka : Term β†’ Term\n | 𝒰 a => 𝒰 (taka a)\n | pi a b => pi (taka a) (taka b)\n | abs a b => abs (taka a) (taka b)\n | app b a => match b with\n | abs _ b => subst (taka a +: var) (taka b)\n | b => app (taka b) (taka a)\n | exf a b => exf (taka a) (taka b)\n | lvl a => lvl (taka a)\n | t => t" }, { "name": "infix:40 \"β‡’\" => Par", "content": "infix:40 \"β‡’\" => Par" }, { "name": "infix:40 \"⇒⋆\" => Pars", "content": "infix:40 \"⇒⋆\" => Pars" }, { "name": "infixr:50 \"+:\" => cons", "content": "infixr:50 \"+:\" => cons" }, { "name": "prefix:95 \"⇑\" => up", "content": "prefix:95 \"⇑\" => up" } ]
[ { "name": "...", "module": "" } ]
[ { "name": "parCong", "content": "theorem parCong {a a' b b'} (ra : a β‡’ a') (rb : b β‡’ b') : subst (a +: var) b β‡’ subst (a' +: var) b'" }, { "name": "parMorphing", "content": "theorem parMorphing {a b} Οƒ Ο„ (h : βˆ€ x, Οƒ x β‡’ Ο„ x) (r : a β‡’ b) : subst Οƒ a β‡’ subst Ο„ b" }, { "name": "parLift", "content": "theorem parLift Οƒ Ο„ (h : βˆ€ x, Οƒ x β‡’ Ο„ x) : βˆ€ x, (⇑ Οƒ) x β‡’ (⇑ Ο„) x" }, { "name": "parRename", "content": "theorem parRename {a b} ΞΎ (r : a β‡’ b) : rename ΞΎ a β‡’ rename ΞΎ b" }, { "name": "parRefl", "content": "theorem parRefl a : a β‡’ a" }, { "name": "nePar", "content": "theorem nePar {a b} (r : a β‡’ b) : ne a β†’ ne b" }, { "name": "nfPar", "content": "theorem nfPar {a b} (r : a β‡’ b) : nf a β†’ nf b" }, { "name": "diacon", "content": "theorem diacon {a b c} (r₁ : a ⇒⋆ b) (rβ‚‚ : a β‡’ c) : βˆƒ d, b ⇒⋆ d ∧ c ⇒⋆ d" }, { "name": "diamond", "content": "theorem diamond {a b c} (r₁ : a β‡’ b) (rβ‚‚ : a β‡’ c) : βˆƒ d, b β‡’ d ∧ c β‡’ d" }, { "name": "parTaka", "content": "theorem parTaka {a b} (r : a β‡’ b) : b β‡’ taka a" }, { "name": "parPars", "content": "theorem parPars {a b} (r : a β‡’ b) : a ⇒⋆ b" }, { "name": "parsLofInv", "content": "theorem parsLofInv {j b} (r : lof j ⇒⋆ b) : b = lof j" }, { "name": "wnfBwds", "content": "theorem wnfBwds {a b} (r : a ⇒⋆ b) : wnf b β†’ wnf a" }, { "name": "nfWnf", "content": "theorem nfWnf {a} (nfa : nf a) : wnf a" }, { "name": "nfPars", "content": "theorem nfPars {a b} (r : a ⇒⋆ b) : nf a β†’ nf b" } ]
[ { "name": "Interp", "content": "inductive Interp (i : lc.L) (I : βˆ€ j, j < i β†’ Term β†’ Prop) : Term β†’ (Term β†’ Prop) β†’ Prop where\n | ne a : ne a β†’ Interp i I a wne\n | pi a b Pa (Pf : Term β†’ (Term β†’ Prop) β†’ Prop) :\n Interp i I a Pa β†’\n (βˆ€ x, Pa x β†’ βˆƒ Pb, Pf x Pb) β†’\n (βˆ€ x Pb, Pf x Pb β†’ Interp i I (subst (x +: var) b) Pb) β†’\n Interp i I (pi a b) (Ξ» f ↦ βˆ€ x Pb, Pa x β†’ Pf x Pb β†’ Pb (app f x))\n | 𝒰 j (lt : j < i) : Interp i I (𝒰 (lof j)) (I j lt)\n | mty : Interp i I mty wne\n | lvl b : nf b β†’ Interp i I (lvl b)\n (Ξ» a ↦ (βˆƒ j k, j < k ∧ a ⇒⋆ lof j ∧ b ⇒⋆ lof k) ∨ wne a)\n | step a b P :\n a β‡’ b β†’\n Interp i I b P β†’\n Interp i I a P" } ]
[ { "name": "interpLvlEq", "content": "theorem interpLvlEq {b c} (r : b β‡’ c) :\n (Ξ» a ↦ (βˆƒ j k, j < k ∧ a ⇒⋆ lof j ∧ b ⇒⋆ lof k) ∨ wne a) =\n (Ξ» a ↦ (βˆƒ j k, j < k ∧ a ⇒⋆ lof j ∧ c ⇒⋆ lof k) ∨ wne a)" }, { "name": "interpNeInv", "content": "theorem interpNeInv {i I a P} (h : ⟦ a ⟧ i , I β†˜ P) :\n ne a β†’ P = wne" }, { "name": "interpPiInv", "content": "theorem interpPiInv {i I a b P} (h : ⟦ pi a b ⟧ i , I β†˜ P) :\n βˆƒ (Pa : Term β†’ Prop) (Pf : Term β†’ (Term β†’ Prop) β†’ Prop),\n (⟦ a ⟧ i , I β†˜ Pa) ∧\n (βˆ€ x, Pa x β†’ βˆƒ Pb, Pf x Pb) ∧\n (βˆ€ x Pb, Pf x Pb β†’ ⟦ subst (x +: var) b ⟧ i, I β†˜ Pb) ∧\n P = (Ξ» f ↦ βˆ€ x Pb, Pa x β†’ Pf x Pb β†’ Pb (app f x))" }, { "name": "interp𝒰Inv", "content": "theorem interp𝒰Inv {i I a P} (h : ⟦ 𝒰 a ⟧ i , I β†˜ P) :\n βˆƒ j lt, a ⇒⋆ lof j ∧ P = I j lt" }, { "name": "interpMtyInv", "content": "theorem interpMtyInv {i I P} (h : ⟦ mty ⟧ i , I β†˜ P) : P = wne" }, { "name": "interpLvlInv", "content": "theorem interpLvlInv {i I b P} (h : ⟦ lvl b ⟧ i , I β†˜ P) :\n wnf b ∧ P = (Ξ» a ↦ (βˆƒ j k, j < k ∧ a ⇒⋆ lof j ∧ b ⇒⋆ lof k) ∨ wne a)" }, { "name": "interpFwd", "content": "theorem interpFwd {i I a b P} (r : a β‡’ b) (h : ⟦ a ⟧ i , I β†˜ P) : ⟦ b ⟧ i , I β†˜ P" } ]
import Β«srcΒ».normal open Term variable [lc : LevelClass] inductive Interp (i : lc.L) (I : βˆ€ j, j < i β†’ Term β†’ Prop) : Term β†’ (Term β†’ Prop) β†’ Prop where | ne a : ne a β†’ Interp i I a wne | pi a b Pa (Pf : Term β†’ (Term β†’ Prop) β†’ Prop) : Interp i I a Pa β†’ (βˆ€ x, Pa x β†’ βˆƒ Pb, Pf x Pb) β†’ (βˆ€ x Pb, Pf x Pb β†’ Interp i I (subst (x +: var) b) Pb) β†’ Interp i I (pi a b) (Ξ» f ↦ βˆ€ x Pb, Pa x β†’ Pf x Pb β†’ Pb (app f x)) | 𝒰 j (lt : j < i) : Interp i I (𝒰 (lof j)) (I j lt) | mty : Interp i I mty wne | lvl b : nf b β†’ Interp i I (lvl b) (Ξ» a ↦ (βˆƒ j k, j < k ∧ a ⇒⋆ lof j ∧ b ⇒⋆ lof k) ∨ wne a) | step a b P : a β‡’ b β†’ Interp i I b P β†’ Interp i I a P notation:40 "⟦" a "⟧" i "," I "β†˜" P => Interp i I a P notation:40 "⟦" a "⟧" i "β†˜" P => Interps i a P
theorem interpDet' {i I a P Q} (hP : ⟦ a ⟧ i , I β†˜ P) (hQ : ⟦ a ⟧ i , I β†˜ Q) : P = Q :=
:= by induction hP generalizing Q case ne nea => exact symm (interpNeInv hQ nea) case pi Pa Pf _ hPf _ iha ihb => let ⟨Pa', Pf', ha', hPf', hb', e⟩ := interpPiInv hQ subst e; apply funext; intro f apply propext; constructor . intro h x Pb' Pax' PfxPb' have Pax : Pa x := by rw [iha ha']; exact Pax' let ⟨Pb, PfxPb⟩ := hPf x Pax rw [← ihb x Pb PfxPb (hb' x Pb' PfxPb')] exact h x Pb Pax PfxPb . intro h x Pb Pax PfxPb have Pax' : Pa' x := by rw [← iha ha']; exact Pax let ⟨Pb', PfxPb'⟩ := hPf' x Pax' rw [ihb x Pb PfxPb (hb' x Pb' PfxPb')] exact h x Pb' Pax' PfxPb' case 𝒰 => let ⟨j, _, r, e⟩ := interp𝒰Inv hQ injection (parsLofInv r) with ej; subst ej; simp [e] case mty => simp [interpMtyInv hQ] case lvl => let ⟨_, e⟩ := interpLvlInv hQ; rw [e] case step r _ ih => exact ih (interpFwd r hQ)
8
51
false
Type systems
428
wtMty
theorem wtMty {Ξ“} {b : Term} (v : Value b) (h : Ξ“ ⊒ b ∢ mty) : False
TTBFL
src/safety.lean
[ "import Β«srcΒ».typing", "import src.reduction", "import src.typing" ]
[ { "name": "Inhabited", "module": "Init.Prelude" }, { "name": "Lean.ToExpr", "module": "Lean.ToExpr" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Repr", "module": "Init.Data.Repr" }, { "name": "DecidableEq", "module": "Init.Prelude" }, { "name": "List", "module": "Init.Prelude" }, { "name": "String", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" } ]
[ { "name": "notation:40 Ξ”:41 \"⊒\" ΞΎ:41 \"∢\" Ξ“:41 => wRename ΞΎ Ξ“ Ξ”", "content": "notation:40 Ξ”:41 \"⊒\" ΞΎ:41 \"∢\" Ξ“:41 => wRename ΞΎ Ξ“ Ξ”" }, { "name": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“", "content": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“" }, { "name": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A", "content": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A" }, { "name": "notation:40 Ξ”:41 \"⊒\" Οƒ:41 \"∢\" Ξ“:41 => wSubst Οƒ Ξ“ Ξ”", "content": "notation:40 Ξ”:41 \"⊒\" Οƒ:41 \"∢\" Ξ“:41 => wSubst Οƒ Ξ“ Ξ”" }, { "name": "Term", "content": "inductive Term : Type where\n | var : Nat β†’ Term\n | 𝒰 : Term β†’ Term\n | pi : Term β†’ Term β†’ Term\n | abs : Term β†’ Term β†’ Term\n | app : Term β†’ Term β†’ Term\n | mty : Term\n | exf : Term β†’ Term β†’ Term\n | lvl : Term β†’ Term\n | lof : lc.L β†’ Term" }, { "name": "Wf", "content": "inductive Wf : Ctxt β†’ Prop where\n | nil : ⊒ ⬝\n | cons {Ξ“ A k} :\n ⊒ Ξ“ β†’\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n \n ⊒ Ξ“ ∷ A" }, { "name": "Ctxt", "content": "inductive Ctxt : Type where\n | nil : Ctxt\n | cons : Ctxt β†’ Term β†’ Ctxt" }, { "name": "subst", "content": "@[simp]\ndef subst (Οƒ : Nat β†’ Term) : Term β†’ Term\n | var s => Οƒ s\n | 𝒰 a => 𝒰 (subst Οƒ a)\n | pi a b => pi (subst Οƒ a) (subst (⇑ Οƒ) b)\n | abs a b => abs (subst Οƒ a) (subst (⇑ Οƒ) b)\n | app b a => app (subst Οƒ b) (subst Οƒ a)\n | mty => mty\n | exf a b => exf (subst Οƒ a) (subst Οƒ b)\n | lvl a => lvl (subst Οƒ a)\n | lof k => lof k" }, { "name": "Par", "content": "inductive Par : Term β†’ Term β†’ Prop where\n | Ξ² {b b' a a' c} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app (abs c b) a β‡’ subst (a' +: var) b'\n | var s : var s β‡’ var s\n | 𝒰 {a a'} :\n a β‡’ a' β†’\n \n 𝒰 a β‡’ 𝒰 a'\n | pi {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n pi a b β‡’ pi a' b'\n | abs {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n abs a b β‡’ abs a' b'\n | app {b b' a a'} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app b a β‡’ app b' a'\n | mty : mty β‡’ mty\n | exf {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n exf a b β‡’ exf a' b'\n | lvl {a a'} :\n a β‡’ a' β†’\n \n lvl a β‡’ lvl a'\n | lof k : lof k β‡’ lof k" }, { "name": "Eqv", "content": "inductive Eqv : Term β†’ Term β†’ Prop where\n | Ξ² {b a c} : app (abs c b) a β‰ˆ subst (a +: var) b\n | 𝒰 {a a'} :\n a β‰ˆ a' β†’\n \n 𝒰 a β‰ˆ 𝒰 a'\n | pi {a a' b b'} :\n a β‰ˆ a' β†’\n b β‰ˆ b' β†’\n \n pi a b β‰ˆ pi a' b'\n | abs {a a' b b'} :\n a β‰ˆ a' β†’\n b β‰ˆ b' β†’\n \n abs a b β‰ˆ abs a' b'\n | app {b b' a a'} :\n b β‰ˆ b' β†’\n a β‰ˆ a' β†’\n \n app b a β‰ˆ app b' a'\n | exf {a a' b b'} :\n a β‰ˆ a' β†’\n b β‰ˆ b' β†’\n \n exf a b β‰ˆ exf a' b'\n | lvl {a a'} :\n a β‰ˆ a' β†’\n \n lvl a β‰ˆ lvl a'\n | refl {a} : a β‰ˆ a\n | sym {a b} :\n a β‰ˆ b β†’\n \n b β‰ˆ a\n | trans {a b c} :\n a β‰ˆ b β†’\n b β‰ˆ c β†’\n \n a β‰ˆ c" }, { "name": "Wt", "content": "inductive Wt : Ctxt β†’ Term β†’ Term β†’ Prop where\n | var {Ξ“ x A} :\n ⊒ Ξ“ β†’\n Ξ“ βˆ‹ x ∢ A β†’\n \n Ξ“ ⊒ var x ∢ A\n | 𝒰 {Ξ“ j k} :\n Ξ“ ⊒ j ∢ lvl k β†’\n \n Ξ“ ⊒ 𝒰 j ∢ 𝒰 k\n | pi {Ξ“ A B k} :\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n Ξ“ ∷ A ⊒ B ∢ 𝒰 (rename succ k) β†’\n \n Ξ“ ⊒ pi A B ∢ 𝒰 k\n | abs {Ξ“ A B b k} :\n Ξ“ ⊒ pi A B ∢ 𝒰 k β†’\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n Ξ“ ∷ A ⊒ b ∢ B β†’\n \n Ξ“ ⊒ abs A b ∢ pi A B\n | app {Ξ“ A B b a} :\n Ξ“ ⊒ b ∢ pi A B β†’\n Ξ“ ⊒ a ∢ A β†’\n \n Ξ“ ⊒ app b a ∢ subst (a +: var) B\n | mty {Ξ“ j k} :\n Ξ“ ⊒ 𝒰 j ∢ 𝒰 k β†’\n \n Ξ“ ⊒ mty ∢ 𝒰 j\n | exf {Ξ“ A b k} :\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n Ξ“ ⊒ b ∢ mty β†’\n \n Ξ“ ⊒ exf A b ∢ A\n | lvl {Ξ“ a b j k} :\n Ξ“ ⊒ a ∢ lvl b β†’\n Ξ“ ⊒ 𝒰 j ∢ 𝒰 k β†’\n \n Ξ“ ⊒ lvl a ∢ 𝒰 j\n | lof {Ξ“ j k} :\n ⊒ Ξ“ β†’\n j < k β†’\n \n Ξ“ ⊒ lof j ∢ lvl (lof k)\n | trans {Ξ“ i j k} :\n Ξ“ ⊒ i ∢ lvl j β†’\n Ξ“ ⊒ j ∢ lvl k β†’\n \n Ξ“ ⊒ i ∢ lvl k\n | conv {Ξ“ A B a k} :\n A β‰ˆ B β†’\n Ξ“ ⊒ a ∢ A β†’\n Ξ“ ⊒ B ∢ 𝒰 k β†’\n \n Ξ“ ⊒ a ∢ B\n | sub {Ξ“ j k A} :\n Ξ“ ⊒ j ∢ lvl k β†’\n Ξ“ ⊒ A ∢ 𝒰 j β†’\n \n Ξ“ ⊒ A ∢ 𝒰 k" }, { "name": "Conv", "content": "def Conv (a : Term) (b : Term) : Prop := βˆƒ c, a ⇒⋆ c ∧ b ⇒⋆ c" }, { "name": "Pars", "content": "inductive Pars : Term β†’ Term β†’ Prop where\n | refl a : a ⇒⋆ a\n | trans {a b c} : a β‡’ b β†’ b ⇒⋆ c β†’ a ⇒⋆ c" }, { "name": "infix:40 \"β‡’\" => Par", "content": "infix:40 \"β‡’\" => Par" }, { "name": "infix:40 \"⇒⋆\" => Pars", "content": "infix:40 \"⇒⋆\" => Pars" }, { "name": "infix:40 \"⇔\" => Conv", "content": "infix:40 \"⇔\" => Conv" }, { "name": "notation:50 \"⬝\" => Ctxt.nil", "content": "notation:50 \"⬝\" => Ctxt.nil" }, { "name": "infixl:50 \"∷\" => Ctxt.cons", "content": "infixl:50 \"∷\" => Ctxt.cons" }, { "name": "infix:40 (priority := 1001) \"β‰ˆ\" => Eqv", "content": "infix:40 (priority := 1001) \"β‰ˆ\" => Eqv" }, { "name": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“", "content": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“" }, { "name": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A", "content": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A" } ]
[ { "name": "...", "module": "" } ]
[ { "name": "wtfLvlInv", "content": "theorem wtfLvlInv {Ξ“ a 𝒰'}\n (h : Ξ“ ⊒ lvl a ∢ 𝒰') :\n βˆƒ b k, Ξ“ ⊒ a ∢ lvl b ∧ 𝒰 k β‰ˆ 𝒰'" }, { "name": "eqvConv", "content": "theorem eqvConv {a b} (r : a β‰ˆ b) : a ⇔ b" }, { "name": "wtfMtyInv", "content": "theorem wtfMtyInv {Ξ“ 𝒰'}\n (h : Ξ“ ⊒ mty ∢ 𝒰') :\n βˆƒ k, 𝒰 k β‰ˆ 𝒰'" }, { "name": "wtfPiInv𝒰", "content": "theorem wtfPiInv𝒰 {Ξ“ A B 𝒰'}\n (h : Ξ“ ⊒ pi A B ∢ 𝒰') :\n βˆƒ j, 𝒰 j β‰ˆ 𝒰'" }, { "name": "wtfPiInvA𝒰", "content": "theorem wtfPiInvA𝒰 {Ξ“ A B 𝒰'}\n (h : Ξ“ ⊒ pi A B ∢ 𝒰') :\n βˆƒ j, Ξ“ ⊒ A ∢ 𝒰 j ∧ 𝒰 j β‰ˆ 𝒰'" }, { "name": "wtfAbsInv", "content": "theorem wtfAbsInv {Ξ“ A' b C}\n (h : Ξ“ ⊒ abs A' b ∢ C) :\n βˆƒ A B, Ξ“ ∷ A ⊒ b ∢ B ∧ A β‰ˆ A' ∧ pi A B β‰ˆ C" }, { "name": "wtfLofInv", "content": "theorem wtfLofInv {Ξ“ j 𝒰'}\n (h : Ξ“ ⊒ lof j ∢ 𝒰') :\n βˆƒ k, lvl k β‰ˆ 𝒰'" }, { "name": "wtf𝒰Inv", "content": "theorem wtf𝒰Inv {Ξ“ j 𝒰'}\n (h : Ξ“ ⊒ 𝒰 j ∢ 𝒰') :\n βˆƒ k, 𝒰 k β‰ˆ 𝒰'" }, { "name": "conv𝒰Mty", "content": "theorem conv𝒰Mty {a} : Β¬ 𝒰 a ⇔ mty" }, { "name": "parsMtyInv", "content": "theorem parsMtyInv {b} (r : mty ⇒⋆ b) : b = mty" }, { "name": "pars𝒰Inv", "content": "theorem pars𝒰Inv {a b} (r : 𝒰 a ⇒⋆ b) : βˆƒ a', b = 𝒰 a' ∧ a ⇒⋆ a'" }, { "name": "convMtyPi", "content": "theorem convMtyPi {a b} : Β¬ mty ⇔ pi a b" }, { "name": "parsPiInv", "content": "theorem parsPiInv {a b c} (r : pi a b ⇒⋆ c) : βˆƒ a' b', c = pi a' b' ∧ a ⇒⋆ a' ∧ b ⇒⋆ b'" }, { "name": "convLvlMty", "content": "theorem convLvlMty {j} : Β¬ lvl j ⇔ mty" }, { "name": "parsLvlInv", "content": "theorem parsLvlInv {i b} (r : lvl i ⇒⋆ b) : βˆƒ j, b = lvl j ∧ i ⇒⋆ j" } ]
[ { "name": "Value", "content": "inductive Value : Term β†’ Type where\n | 𝒰 {k} : Value (𝒰 k)\n | pi {a b} : Value (pi a b)\n | abs {a b} : Value (abs a b)\n | mty : Value mty\n | lvl {k} : Value (lvl k)\n | lof {k} : Value (lof k)" }, { "name": "valueType", "content": "@[simp] \ndef valueType {a} (A : Term) : Value a β†’ Prop\n | Value.𝒰 | Value.pi | Value.mty | Value.lvl => βˆƒ k, 𝒰 k β‰ˆ A\n | Value.abs => βˆƒ B C, pi B C β‰ˆ A\n | Value.lof => βˆƒ k, lvl k β‰ˆ A" } ]
[ { "name": "wtValue", "content": "theorem wtValue {Ξ“} {a A B : Term} (h : Ξ“ ⊒ a ∢ A) (e : A β‰ˆ B) : (v : Value a) β†’ valueType B v\n | Value.𝒰 => let ⟨_, eπ’°βŸ©" } ]
import Β«srcΒ».typing open Nat open Term variable [LevelClass] notation:40 Ξ”:41 "⊒" Οƒ:41 "∢" Ξ“:41 => wSubst Οƒ Ξ“ Ξ” inductive Value : Term β†’ Type where | 𝒰 {k} : Value (𝒰 k) | pi {a b} : Value (pi a b) | abs {a b} : Value (abs a b) | mty : Value mty | lvl {k} : Value (lvl k) | lof {k} : Value (lof k) section end infix:40 "β‡’Ξ²" => CBN infix:40 "⇒β⋆" => CBNs @[simp] def valueType {a} (A : Term) : Value a β†’ Prop | Value.𝒰 | Value.pi | Value.mty | Value.lvl => βˆƒ k, 𝒰 k β‰ˆ A | Value.abs => βˆƒ B C, pi B C β‰ˆ A | Value.lof => βˆƒ k, lvl k β‰ˆ A
theorem wtMty {Ξ“} {b : Term} (v : Value b) (h : Ξ“ ⊒ b ∢ mty) : False :=
:= by generalize e : mty = T at h induction h all_goals try first | subst e | injection e case var | app | exf => contradiction case conv h v emty _ _ => let _e := wtValue h emty v cases v <;> let ⟨_, e⟩ := _e case 𝒰 | pi | mty | lvl => cases conv𝒰Mty (eqvConv e) case abs => let ⟨_, e⟩ := e; cases convMtyPi (eqvConv (Eqv.sym e)) case lof => cases convLvlMty (eqvConv e)
5
36
false
Type systems
429
interpDet'
theorem interpDet' {i I a P Q} (hP : ⟦ a ⟧ i , I β†˜ P) (hQ : ⟦ a ⟧ i , I β†˜ Q) : P = Q
TTBFL
src/semantics.lean
[ "import src.reduction", "import Β«srcΒ».reduction" ]
[ { "name": "Inhabited", "module": "Init.Prelude" }, { "name": "Lean.ToExpr", "module": "Lean.ToExpr" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Repr", "module": "Init.Data.Repr" }, { "name": "String", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "propext", "module": "Init.Core" }, { "name": "Nat.succ", "module": "Init.Prelude" }, { "name": "Nat.zero", "module": "Init.Prelude" } ]
[ { "name": "notation:40 \"⟦\" a \"⟧\" i \",\" I \"β†˜\" P => Interp i I a P", "content": "notation:40 \"⟦\" a \"⟧\" i \",\" I \"β†˜\" P => Interp i I a P" }, { "name": "notation:40 \"⟦\" a \"⟧\" i \"β†˜\" P => Interps i a P", "content": "notation:40 \"⟦\" a \"⟧\" i \"β†˜\" P => Interps i a P" }, { "name": "Pars", "content": "inductive Pars : Term β†’ Term β†’ Prop where\n | refl a : a ⇒⋆ a\n | trans {a b c} : a β‡’ b β†’ b ⇒⋆ c β†’ a ⇒⋆ c" }, { "name": "Par", "content": "inductive Par : Term β†’ Term β†’ Prop where\n | Ξ² {b b' a a' c} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app (abs c b) a β‡’ subst (a' +: var) b'\n | var s : var s β‡’ var s\n | 𝒰 {a a'} :\n a β‡’ a' β†’\n \n 𝒰 a β‡’ 𝒰 a'\n | pi {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n pi a b β‡’ pi a' b'\n | abs {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n abs a b β‡’ abs a' b'\n | app {b b' a a'} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app b a β‡’ app b' a'\n | mty : mty β‡’ mty\n | exf {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n exf a b β‡’ exf a' b'\n | lvl {a a'} :\n a β‡’ a' β†’\n \n lvl a β‡’ lvl a'\n | lof k : lof k β‡’ lof k" }, { "name": "Term", "content": "inductive Term : Type where\n | var : Nat β†’ Term\n | 𝒰 : Term β†’ Term\n | pi : Term β†’ Term β†’ Term\n | abs : Term β†’ Term β†’ Term\n | app : Term β†’ Term β†’ Term\n | mty : Term\n | exf : Term β†’ Term β†’ Term\n | lvl : Term β†’ Term\n | lof : lc.L β†’ Term" }, { "name": "subst", "content": "@[simp]\ndef subst (Οƒ : Nat β†’ Term) : Term β†’ Term\n | var s => Οƒ s\n | 𝒰 a => 𝒰 (subst Οƒ a)\n | pi a b => pi (subst Οƒ a) (subst (⇑ Οƒ) b)\n | abs a b => abs (subst Οƒ a) (subst (⇑ Οƒ) b)\n | app b a => app (subst Οƒ b) (subst Οƒ a)\n | mty => mty\n | exf a b => exf (subst Οƒ a) (subst Οƒ b)\n | lvl a => lvl (subst Οƒ a)\n | lof k => lof k" }, { "name": "LevelClass", "content": "class LevelClass where\n L : Type\n lc : LevelClasses L" }, { "name": "up", "content": "@[simp]\ndef up (Οƒ : Nat β†’ Term) : Nat β†’ Term :=\n var 0 +: (rename succ ∘ Οƒ)" }, { "name": "rename", "content": "@[simp]\ndef rename (ΞΎ : Nat β†’ Nat) : Term β†’ Term\n | var s => var (ΞΎ s)\n | 𝒰 a => 𝒰 (rename ΞΎ a)\n | pi a b => pi (rename ΞΎ a) (rename (lift ΞΎ) b)\n | abs a b => abs (rename ΞΎ a) (rename (lift ΞΎ) b)\n | app b a => app (rename ΞΎ b) (rename ΞΎ a)\n | mty => mty\n | exf a b => exf (rename ΞΎ a) (rename ΞΎ b)\n | lvl a => lvl (rename ΞΎ a)\n | lof k => lof k" }, { "name": "lift", "content": "@[simp]\ndef lift (ΞΎ : Nat β†’ Nat) : Nat β†’ Nat :=\n zero +: (succ ∘ ΞΎ)" }, { "name": "cons", "content": "@[simp]\ndef cons {A : Type} (x : A) (ΞΎ : Nat β†’ A) : Nat β†’ A\n | 0 => x\n | n + 1 => ΞΎ n" }, { "name": "taka", "content": "@[simp]\ndef taka : Term β†’ Term\n | 𝒰 a => 𝒰 (taka a)\n | pi a b => pi (taka a) (taka b)\n | abs a b => abs (taka a) (taka b)\n | app b a => match b with\n | abs _ b => subst (taka a +: var) (taka b)\n | b => app (taka b) (taka a)\n | exf a b => exf (taka a) (taka b)\n | lvl a => lvl (taka a)\n | t => t" }, { "name": "infix:40 \"β‡’\" => Par", "content": "infix:40 \"β‡’\" => Par" }, { "name": "infix:40 \"⇒⋆\" => Pars", "content": "infix:40 \"⇒⋆\" => Pars" }, { "name": "infixr:50 \"+:\" => cons", "content": "infixr:50 \"+:\" => cons" }, { "name": "prefix:95 \"⇑\" => up", "content": "prefix:95 \"⇑\" => up" } ]
[ { "name": "...", "module": "" } ]
[ { "name": "parCong", "content": "theorem parCong {a a' b b'} (ra : a β‡’ a') (rb : b β‡’ b') : subst (a +: var) b β‡’ subst (a' +: var) b'" }, { "name": "parMorphing", "content": "theorem parMorphing {a b} Οƒ Ο„ (h : βˆ€ x, Οƒ x β‡’ Ο„ x) (r : a β‡’ b) : subst Οƒ a β‡’ subst Ο„ b" }, { "name": "parLift", "content": "theorem parLift Οƒ Ο„ (h : βˆ€ x, Οƒ x β‡’ Ο„ x) : βˆ€ x, (⇑ Οƒ) x β‡’ (⇑ Ο„) x" }, { "name": "parRename", "content": "theorem parRename {a b} ΞΎ (r : a β‡’ b) : rename ΞΎ a β‡’ rename ΞΎ b" }, { "name": "parRefl", "content": "theorem parRefl a : a β‡’ a" }, { "name": "diamond", "content": "theorem diamond {a b c} (r₁ : a β‡’ b) (rβ‚‚ : a β‡’ c) : βˆƒ d, b β‡’ d ∧ c β‡’ d" }, { "name": "parTaka", "content": "theorem parTaka {a b} (r : a β‡’ b) : b β‡’ taka a" }, { "name": "parsLofInv", "content": "theorem parsLofInv {j b} (r : lof j ⇒⋆ b) : b = lof j" } ]
[ { "name": "Interp", "content": "inductive Interp (i : lc.L) (I : βˆ€ j, j < i β†’ Term β†’ Prop) : Term β†’ (Term β†’ Prop) β†’ Prop where\n | pi a b Pa (Pf : Term β†’ (Term β†’ Prop) β†’ Prop) :\n Interp i I a Pa β†’\n (βˆ€ x, Pa x β†’ βˆƒ Pb, Pf x Pb) β†’\n (βˆ€ x Pb, Pf x Pb β†’ Interp i I (subst (x +: var) b) Pb) β†’\n Interp i I (pi a b) (Ξ» f ↦ βˆ€ x Pb, Pa x β†’ Pf x Pb β†’ Pb (app f x))\n | 𝒰 j (lt : j < i) : Interp i I (𝒰 (lof j)) (I j lt)\n | mty : Interp i I mty (Ξ» _ ↦ False)\n | lvl k : Interp i I (lvl (lof k)) (Ξ» a ↦ βˆƒ j, a ⇒⋆ lof j ∧ j < k)\n | step a b P :\n a β‡’ b β†’\n Interp i I b P β†’\n Interp i I a P" } ]
[ { "name": "interpPiInv", "content": "theorem interpPiInv {i I a b P} (h : ⟦ pi a b ⟧ i , I β†˜ P) :\n βˆƒ (Pa : Term β†’ Prop) (Pf : Term β†’ (Term β†’ Prop) β†’ Prop),\n (⟦ a ⟧ i , I β†˜ Pa) ∧\n (βˆ€ x, Pa x β†’ βˆƒ Pb, Pf x Pb) ∧\n (βˆ€ x Pb, Pf x Pb β†’ ⟦ subst (x +: var) b ⟧ i, I β†˜ Pb) ∧\n P = (Ξ» f ↦ βˆ€ x Pb, Pa x β†’ Pf x Pb β†’ Pb (app f x))" }, { "name": "interp𝒰Inv", "content": "theorem interp𝒰Inv {i I a P} (h : ⟦ 𝒰 a ⟧ i , I β†˜ P) :\n βˆƒ j lt, a ⇒⋆ lof j ∧ P = I j lt" }, { "name": "interpMtyInv", "content": "theorem interpMtyInv {i I P} (h : ⟦ mty ⟧ i , I β†˜ P) : P = (Ξ» _ ↦ False)" }, { "name": "interpLvlInv", "content": "theorem interpLvlInv {i I a P} (h : ⟦ lvl a ⟧ i , I β†˜ P) :\n βˆƒ k, a ⇒⋆ lof k ∧ P = (Ξ» a ↦ βˆƒ j, a ⇒⋆ lof j ∧ j < k)" }, { "name": "interpFwd", "content": "theorem interpFwd {i I a b P} (r : a β‡’ b) (h : ⟦ a ⟧ i , I β†˜ P) : ⟦ b ⟧ i , I β†˜ P" } ]
import Β«srcΒ».reduction open Term variable [lc : LevelClass] inductive Interp (i : lc.L) (I : βˆ€ j, j < i β†’ Term β†’ Prop) : Term β†’ (Term β†’ Prop) β†’ Prop where | pi a b Pa (Pf : Term β†’ (Term β†’ Prop) β†’ Prop) : Interp i I a Pa β†’ (βˆ€ x, Pa x β†’ βˆƒ Pb, Pf x Pb) β†’ (βˆ€ x Pb, Pf x Pb β†’ Interp i I (subst (x +: var) b) Pb) β†’ Interp i I (pi a b) (Ξ» f ↦ βˆ€ x Pb, Pa x β†’ Pf x Pb β†’ Pb (app f x)) | 𝒰 j (lt : j < i) : Interp i I (𝒰 (lof j)) (I j lt) | mty : Interp i I mty (Ξ» _ ↦ False) | lvl k : Interp i I (lvl (lof k)) (Ξ» a ↦ βˆƒ j, a ⇒⋆ lof j ∧ j < k) | step a b P : a β‡’ b β†’ Interp i I b P β†’ Interp i I a P notation:40 "⟦" a "⟧" i "," I "β†˜" P => Interp i I a P notation:40 "⟦" a "⟧" i "β†˜" P => Interps i a P
theorem interpDet' {i I a P Q} (hP : ⟦ a ⟧ i , I β†˜ P) (hQ : ⟦ a ⟧ i , I β†˜ Q) : P = Q :=
:= by induction hP generalizing Q case pi Pa Pf _ hPf _ iha ihb => let ⟨Pa', Pf', ha', hPf', hb', e⟩ := interpPiInv hQ subst e; apply funext; intro f apply propext; constructor . intro h x Pb' Pax' PfxPb' have Pax : Pa x := by rw [iha ha']; exact Pax' let ⟨Pb, PfxPb⟩ := hPf x Pax rw [← ihb x Pb PfxPb (hb' x Pb' PfxPb')] exact h x Pb Pax PfxPb . intro h x Pb Pax PfxPb have Pax' : Pa' x := by rw [← iha ha']; exact Pax let ⟨Pb', PfxPb'⟩ := hPf' x Pax' rw [ihb x Pb PfxPb (hb' x Pb' PfxPb')] exact h x Pb' Pax' PfxPb' case 𝒰 => let ⟨j, _, r, e⟩ := interp𝒰Inv hQ injection (parsLofInv r) with ej; subst ej; simp [e] case mty => simp [interpMtyInv hQ] case lvl => let ⟨k, r, e⟩ := interpLvlInv hQ injection (parsLofInv r) with ek; subst ek; simp [e] case step r _ ih => exact ih (interpFwd r hQ)
8
34
false
Type systems
430
interpFwd
theorem interpFwd {i I a b P} (r : a β‡’ b) (h : ⟦ a ⟧ i , I β†˜ P) : ⟦ b ⟧ i , I β†˜ P
TTBFL
src/candidates.lean
[ "import Β«srcΒ».normal", "import src.reduction", "import src.normal" ]
[ { "name": "Inhabited", "module": "Init.Prelude" }, { "name": "Lean.ToExpr", "module": "Lean.ToExpr" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Repr", "module": "Init.Data.Repr" }, { "name": "String", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "Or", "module": "Init.Prelude" }, { "name": "Or.inl", "module": "Init.Prelude" }, { "name": "Or.inr", "module": "Init.Prelude" }, { "name": "propext", "module": "Init.Core" }, { "name": "Nat.succ", "module": "Init.Prelude" }, { "name": "Nat.zero", "module": "Init.Prelude" } ]
[ { "name": "notation:40 \"⟦\" a \"⟧\" i \",\" I \"β†˜\" P => Interp i I a P", "content": "notation:40 \"⟦\" a \"⟧\" i \",\" I \"β†˜\" P => Interp i I a P" }, { "name": "notation:40 \"⟦\" a \"⟧\" i \"β†˜\" P => Interps i a P", "content": "notation:40 \"⟦\" a \"⟧\" i \"β†˜\" P => Interps i a P" }, { "name": "Pars", "content": "inductive Pars : Term β†’ Term β†’ Prop where\n | refl a : a ⇒⋆ a\n | trans {a b c} : a β‡’ b β†’ b ⇒⋆ c β†’ a ⇒⋆ c" }, { "name": "Par", "content": "inductive Par : Term β†’ Term β†’ Prop where\n | Ξ² {b b' a a' c} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app (abs c b) a β‡’ subst (a' +: var) b'\n | var s : var s β‡’ var s\n | 𝒰 {a a'} :\n a β‡’ a' β†’\n \n 𝒰 a β‡’ 𝒰 a'\n | pi {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n pi a b β‡’ pi a' b'\n | abs {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n abs a b β‡’ abs a' b'\n | app {b b' a a'} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app b a β‡’ app b' a'\n | mty : mty β‡’ mty\n | exf {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n exf a b β‡’ exf a' b'\n | lvl {a a'} :\n a β‡’ a' β†’\n \n lvl a β‡’ lvl a'\n | lof k : lof k β‡’ lof k" }, { "name": "Term", "content": "inductive Term : Type where\n | var : Nat β†’ Term\n | 𝒰 : Term β†’ Term\n | pi : Term β†’ Term β†’ Term\n | abs : Term β†’ Term β†’ Term\n | app : Term β†’ Term β†’ Term\n | mty : Term\n | exf : Term β†’ Term β†’ Term\n | lvl : Term β†’ Term\n | lof : lc.L β†’ Term" }, { "name": "subst", "content": "@[simp]\ndef subst (Οƒ : Nat β†’ Term) : Term β†’ Term\n | var s => Οƒ s\n | 𝒰 a => 𝒰 (subst Οƒ a)\n | pi a b => pi (subst Οƒ a) (subst (⇑ Οƒ) b)\n | abs a b => abs (subst Οƒ a) (subst (⇑ Οƒ) b)\n | app b a => app (subst Οƒ b) (subst Οƒ a)\n | mty => mty\n | exf a b => exf (subst Οƒ a) (subst Οƒ b)\n | lvl a => lvl (subst Οƒ a)\n | lof k => lof k" }, { "name": "nf", "content": "@[simp]\ndef nf : Term β†’ Prop\n | 𝒰 a => nf a\n | pi a b => nf a ∧ nf b\n | abs a b => nf a ∧ nf b\n | app b a => ne b ∧ nf a\n | exf a b => nf a ∧ ne b\n | lvl a => nf a\n | _ => True" }, { "name": "ne", "content": "@[simp]\ndef ne : Term β†’ Prop\n | var _ => True\n | app b a => ne b ∧ nf a\n | exf a b => nf a ∧ ne b\n | _ => False" }, { "name": "LevelClass", "content": "class LevelClass where\n L : Type\n lc : LevelClasses L" }, { "name": "wne", "content": "@[simp] def wne (a : Term) : Prop := βˆƒ b, ne b ∧ a ⇒⋆ b" }, { "name": "taka", "content": "@[simp]\ndef taka : Term β†’ Term\n | 𝒰 a => 𝒰 (taka a)\n | pi a b => pi (taka a) (taka b)\n | abs a b => abs (taka a) (taka b)\n | app b a => match b with\n | abs _ b => subst (taka a +: var) (taka b)\n | b => app (taka b) (taka a)\n | exf a b => exf (taka a) (taka b)\n | lvl a => lvl (taka a)\n | t => t" }, { "name": "up", "content": "@[simp]\ndef up (Οƒ : Nat β†’ Term) : Nat β†’ Term :=\n var 0 +: (rename succ ∘ Οƒ)" }, { "name": "rename", "content": "@[simp]\ndef rename (ΞΎ : Nat β†’ Nat) : Term β†’ Term\n | var s => var (ΞΎ s)\n | 𝒰 a => 𝒰 (rename ΞΎ a)\n | pi a b => pi (rename ΞΎ a) (rename (lift ΞΎ) b)\n | abs a b => abs (rename ΞΎ a) (rename (lift ΞΎ) b)\n | app b a => app (rename ΞΎ b) (rename ΞΎ a)\n | mty => mty\n | exf a b => exf (rename ΞΎ a) (rename ΞΎ b)\n | lvl a => lvl (rename ΞΎ a)\n | lof k => lof k" }, { "name": "lift", "content": "@[simp]\ndef lift (ΞΎ : Nat β†’ Nat) : Nat β†’ Nat :=\n zero +: (succ ∘ ΞΎ)" }, { "name": "cons", "content": "@[simp]\ndef cons {A : Type} (x : A) (ΞΎ : Nat β†’ A) : Nat β†’ A\n | 0 => x\n | n + 1 => ΞΎ n" }, { "name": "infix:40 \"β‡’\" => Par", "content": "infix:40 \"β‡’\" => Par" }, { "name": "infix:40 \"⇒⋆\" => Pars", "content": "infix:40 \"⇒⋆\" => Pars" }, { "name": "infixr:50 \"+:\" => cons", "content": "infixr:50 \"+:\" => cons" }, { "name": "prefix:95 \"⇑\" => up", "content": "prefix:95 \"⇑\" => up" } ]
[ { "name": "...", "module": "" } ]
[ { "name": "diacon", "content": "theorem diacon {a b c} (r₁ : a ⇒⋆ b) (rβ‚‚ : a β‡’ c) : βˆƒ d, b ⇒⋆ d ∧ c ⇒⋆ d" }, { "name": "diamond", "content": "theorem diamond {a b c} (r₁ : a β‡’ b) (rβ‚‚ : a β‡’ c) : βˆƒ d, b β‡’ d ∧ c β‡’ d" }, { "name": "parTaka", "content": "theorem parTaka {a b} (r : a β‡’ b) : b β‡’ taka a" }, { "name": "parCong", "content": "theorem parCong {a a' b b'} (ra : a β‡’ a') (rb : b β‡’ b') : subst (a +: var) b β‡’ subst (a' +: var) b'" }, { "name": "parMorphing", "content": "theorem parMorphing {a b} Οƒ Ο„ (h : βˆ€ x, Οƒ x β‡’ Ο„ x) (r : a β‡’ b) : subst Οƒ a β‡’ subst Ο„ b" }, { "name": "parLift", "content": "theorem parLift Οƒ Ο„ (h : βˆ€ x, Οƒ x β‡’ Ο„ x) : βˆ€ x, (⇑ Οƒ) x β‡’ (⇑ Ο„) x" }, { "name": "parRename", "content": "theorem parRename {a b} ΞΎ (r : a β‡’ b) : rename ΞΎ a β‡’ rename ΞΎ b" }, { "name": "parPars", "content": "theorem parPars {a b} (r : a β‡’ b) : a ⇒⋆ b" }, { "name": "parsLofInv", "content": "theorem parsLofInv {j b} (r : lof j ⇒⋆ b) : b = lof j" }, { "name": "nfPars", "content": "theorem nfPars {a b} (r : a ⇒⋆ b) : nf a β†’ nf b" }, { "name": "nfPar", "content": "theorem nfPar {a b} (r : a β‡’ b) : nf a β†’ nf b" }, { "name": "nePar", "content": "theorem nePar {a b} (r : a β‡’ b) : ne a β†’ ne b" }, { "name": "parRefl", "content": "theorem parRefl a : a β‡’ a" } ]
[ { "name": "Interp", "content": "inductive Interp (i : lc.L) (I : βˆ€ j, j < i β†’ Term β†’ Prop) : Term β†’ (Term β†’ Prop) β†’ Prop where\n | ne a : ne a β†’ Interp i I a wne\n | pi a b Pa (Pf : Term β†’ (Term β†’ Prop) β†’ Prop) :\n Interp i I a Pa β†’\n (βˆ€ x, Pa x β†’ βˆƒ Pb, Pf x Pb) β†’\n (βˆ€ x Pb, Pf x Pb β†’ Interp i I (subst (x +: var) b) Pb) β†’\n Interp i I (pi a b) (Ξ» f ↦ βˆ€ x Pb, Pa x β†’ Pf x Pb β†’ Pb (app f x))\n | 𝒰 j (lt : j < i) : Interp i I (𝒰 (lof j)) (I j lt)\n | mty : Interp i I mty wne\n | lvl b : nf b β†’ Interp i I (lvl b)\n (Ξ» a ↦ (βˆƒ j k, j < k ∧ a ⇒⋆ lof j ∧ b ⇒⋆ lof k) ∨ wne a)\n | step a b P :\n a β‡’ b β†’\n Interp i I b P β†’\n Interp i I a P" } ]
[ { "name": "interpLvlEq", "content": "theorem interpLvlEq {b c} (r : b β‡’ c) :\n (Ξ» a ↦ (βˆƒ j k, j < k ∧ a ⇒⋆ lof j ∧ b ⇒⋆ lof k) ∨ wne a) =\n (Ξ» a ↦ (βˆƒ j k, j < k ∧ a ⇒⋆ lof j ∧ c ⇒⋆ lof k) ∨ wne a)" } ]
import Β«srcΒ».normal open Term variable [lc : LevelClass] inductive Interp (i : lc.L) (I : βˆ€ j, j < i β†’ Term β†’ Prop) : Term β†’ (Term β†’ Prop) β†’ Prop where | ne a : ne a β†’ Interp i I a wne | pi a b Pa (Pf : Term β†’ (Term β†’ Prop) β†’ Prop) : Interp i I a Pa β†’ (βˆ€ x, Pa x β†’ βˆƒ Pb, Pf x Pb) β†’ (βˆ€ x Pb, Pf x Pb β†’ Interp i I (subst (x +: var) b) Pb) β†’ Interp i I (pi a b) (Ξ» f ↦ βˆ€ x Pb, Pa x β†’ Pf x Pb β†’ Pb (app f x)) | 𝒰 j (lt : j < i) : Interp i I (𝒰 (lof j)) (I j lt) | mty : Interp i I mty wne | lvl b : nf b β†’ Interp i I (lvl b) (Ξ» a ↦ (βˆƒ j k, j < k ∧ a ⇒⋆ lof j ∧ b ⇒⋆ lof k) ∨ wne a) | step a b P : a β‡’ b β†’ Interp i I b P β†’ Interp i I a P notation:40 "⟦" a "⟧" i "," I "β†˜" P => Interp i I a P notation:40 "⟦" a "⟧" i "β†˜" P => Interps i a P
theorem interpFwd {i I a b P} (r : a β‡’ b) (h : ⟦ a ⟧ i , I β†˜ P) : ⟦ b ⟧ i , I β†˜ P :=
:= by induction h generalizing b case pi iha ihb => cases r; constructor all_goals intros; apply_rules [parCong, parRefl] case ne nea => constructor; exact nePar r nea case 𝒰 => cases r; case 𝒰 r => cases r; constructor case mty => cases r; exact Interp.mty case lvl => cases r; case lvl nfb _ r => rw [interpLvlEq r]; constructor; exact nfPars (parPars r) nfb case step r' _ ih => let ⟨c, rc, rc'⟩ := diamond r r' constructor <;> apply_rules
11
42
false
Type systems
431
wtReplace
theorem wtReplace {Ξ“} {A B c C k : Term} (e : A β‰ˆ B) (hB : Ξ“ ⊒ B ∢ 𝒰 k) (h : Ξ“ ∷ A ⊒ c ∢ C) : Ξ“ ∷ B ⊒ c ∢ C
TTBFL
src/safety.lean
[ "import Β«srcΒ».typing", "import src.syntactics", "import src.reduction", "import src.typing" ]
[ { "name": "Inhabited", "module": "Init.Prelude" }, { "name": "Lean.ToExpr", "module": "Lean.ToExpr" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Repr", "module": "Init.Data.Repr" }, { "name": "DecidableEq", "module": "Init.Prelude" }, { "name": "List", "module": "Init.Prelude" }, { "name": "String", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "Nat.succ", "module": "Init.Prelude" }, { "name": "Nat.sub", "module": "Init.Prelude" }, { "name": "Nat.zero", "module": "Init.Prelude" } ]
[ { "name": "notation:40 Ξ”:41 \"⊒\" ΞΎ:41 \"∢\" Ξ“:41 => wRename ΞΎ Ξ“ Ξ”", "content": "notation:40 Ξ”:41 \"⊒\" ΞΎ:41 \"∢\" Ξ“:41 => wRename ΞΎ Ξ“ Ξ”" }, { "name": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“", "content": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“" }, { "name": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A", "content": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A" }, { "name": "notation:40 Ξ”:41 \"⊒\" Οƒ:41 \"∢\" Ξ“:41 => wSubst Οƒ Ξ“ Ξ”", "content": "notation:40 Ξ”:41 \"⊒\" Οƒ:41 \"∢\" Ξ“:41 => wSubst Οƒ Ξ“ Ξ”" }, { "name": "notation:40 Ξ“:41 \"βˆ‹\" x:41 \"∢\" A:41 => In x A Ξ“", "content": "notation:40 Ξ“:41 \"βˆ‹\" x:41 \"∢\" A:41 => In x A Ξ“" }, { "name": "In", "content": "inductive In : Nat β†’ Term β†’ Ctxt β†’ Prop where\n | here {Ξ“ A} : In 0 (rename succ A) (Ξ“ ∷ A)\n | there {Ξ“ x A B} : In x A Ξ“ β†’ In (succ x) (rename succ A) (Ξ“ ∷ B)" }, { "name": "Wf", "content": "inductive Wf : Ctxt β†’ Prop where\n | nil : ⊒ ⬝\n | cons {Ξ“ A k} :\n ⊒ Ξ“ β†’\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n \n ⊒ Ξ“ ∷ A" }, { "name": "Term", "content": "inductive Term : Type where\n | var : Nat β†’ Term\n | 𝒰 : Term β†’ Term\n | pi : Term β†’ Term β†’ Term\n | abs : Term β†’ Term β†’ Term\n | app : Term β†’ Term β†’ Term\n | mty : Term\n | exf : Term β†’ Term β†’ Term\n | lvl : Term β†’ Term\n | lof : lc.L β†’ Term" }, { "name": "Ctxt", "content": "inductive Ctxt : Type where\n | nil : Ctxt\n | cons : Ctxt β†’ Term β†’ Ctxt" }, { "name": "Wt", "content": "inductive Wt : Ctxt β†’ Term β†’ Term β†’ Prop where\n | var {Ξ“ x A} :\n ⊒ Ξ“ β†’\n Ξ“ βˆ‹ x ∢ A β†’\n \n Ξ“ ⊒ var x ∢ A\n | 𝒰 {Ξ“ j k} :\n Ξ“ ⊒ j ∢ lvl k β†’\n \n Ξ“ ⊒ 𝒰 j ∢ 𝒰 k\n | pi {Ξ“ A B k} :\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n Ξ“ ∷ A ⊒ B ∢ 𝒰 (rename succ k) β†’\n \n Ξ“ ⊒ pi A B ∢ 𝒰 k\n | abs {Ξ“ A B b k} :\n Ξ“ ⊒ pi A B ∢ 𝒰 k β†’\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n Ξ“ ∷ A ⊒ b ∢ B β†’\n \n Ξ“ ⊒ abs A b ∢ pi A B\n | app {Ξ“ A B b a} :\n Ξ“ ⊒ b ∢ pi A B β†’\n Ξ“ ⊒ a ∢ A β†’\n \n Ξ“ ⊒ app b a ∢ subst (a +: var) B\n | mty {Ξ“ j k} :\n Ξ“ ⊒ 𝒰 j ∢ 𝒰 k β†’\n \n Ξ“ ⊒ mty ∢ 𝒰 j\n | exf {Ξ“ A b k} :\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n Ξ“ ⊒ b ∢ mty β†’\n \n Ξ“ ⊒ exf A b ∢ A\n | lvl {Ξ“ a b j k} :\n Ξ“ ⊒ a ∢ lvl b β†’\n Ξ“ ⊒ 𝒰 j ∢ 𝒰 k β†’\n \n Ξ“ ⊒ lvl a ∢ 𝒰 j\n | lof {Ξ“ j k} :\n ⊒ Ξ“ β†’\n j < k β†’\n \n Ξ“ ⊒ lof j ∢ lvl (lof k)\n | trans {Ξ“ i j k} :\n Ξ“ ⊒ i ∢ lvl j β†’\n Ξ“ ⊒ j ∢ lvl k β†’\n \n Ξ“ ⊒ i ∢ lvl k\n | conv {Ξ“ A B a k} :\n A β‰ˆ B β†’\n Ξ“ ⊒ a ∢ A β†’\n Ξ“ ⊒ B ∢ 𝒰 k β†’\n \n Ξ“ ⊒ a ∢ B\n | sub {Ξ“ j k A} :\n Ξ“ ⊒ j ∢ lvl k β†’\n Ξ“ ⊒ A ∢ 𝒰 j β†’\n \n Ξ“ ⊒ A ∢ 𝒰 k" }, { "name": "substId", "content": "def substId : βˆ€ s, subst var s = s :=\n substId' var (by admit /- proof elided -/\n )" }, { "name": "subst", "content": "@[simp]\ndef subst (Οƒ : Nat β†’ Term) : Term β†’ Term\n | var s => Οƒ s\n | 𝒰 a => 𝒰 (subst Οƒ a)\n | pi a b => pi (subst Οƒ a) (subst (⇑ Οƒ) b)\n | abs a b => abs (subst Οƒ a) (subst (⇑ Οƒ) b)\n | app b a => app (subst Οƒ b) (subst Οƒ a)\n | mty => mty\n | exf a b => exf (subst Οƒ a) (subst Οƒ b)\n | lvl a => lvl (subst Οƒ a)\n | lof k => lof k" }, { "name": "Par", "content": "inductive Par : Term β†’ Term β†’ Prop where\n | Ξ² {b b' a a' c} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app (abs c b) a β‡’ subst (a' +: var) b'\n | var s : var s β‡’ var s\n | 𝒰 {a a'} :\n a β‡’ a' β†’\n \n 𝒰 a β‡’ 𝒰 a'\n | pi {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n pi a b β‡’ pi a' b'\n | abs {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n abs a b β‡’ abs a' b'\n | app {b b' a a'} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app b a β‡’ app b' a'\n | mty : mty β‡’ mty\n | exf {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n exf a b β‡’ exf a' b'\n | lvl {a a'} :\n a β‡’ a' β†’\n \n lvl a β‡’ lvl a'\n | lof k : lof k β‡’ lof k" }, { "name": "up", "content": "@[simp]\ndef up (Οƒ : Nat β†’ Term) : Nat β†’ Term :=\n var 0 +: (rename succ ∘ Οƒ)" }, { "name": "rename", "content": "@[simp]\ndef rename (ΞΎ : Nat β†’ Nat) : Term β†’ Term\n | var s => var (ΞΎ s)\n | 𝒰 a => 𝒰 (rename ΞΎ a)\n | pi a b => pi (rename ΞΎ a) (rename (lift ΞΎ) b)\n | abs a b => abs (rename ΞΎ a) (rename (lift ΞΎ) b)\n | app b a => app (rename ΞΎ b) (rename ΞΎ a)\n | mty => mty\n | exf a b => exf (rename ΞΎ a) (rename ΞΎ b)\n | lvl a => lvl (rename ΞΎ a)\n | lof k => lof k" }, { "name": "lift", "content": "@[simp]\ndef lift (ΞΎ : Nat β†’ Nat) : Nat β†’ Nat :=\n zero +: (succ ∘ ΞΎ)" }, { "name": "cons", "content": "@[simp]\ndef cons {A : Type} (x : A) (ΞΎ : Nat β†’ A) : Nat β†’ A\n | 0 => x\n | n + 1 => ΞΎ n" }, { "name": "Eqv", "content": "inductive Eqv : Term β†’ Term β†’ Prop where\n | Ξ² {b a c} : app (abs c b) a β‰ˆ subst (a +: var) b\n | 𝒰 {a a'} :\n a β‰ˆ a' β†’\n \n 𝒰 a β‰ˆ 𝒰 a'\n | pi {a a' b b'} :\n a β‰ˆ a' β†’\n b β‰ˆ b' β†’\n \n pi a b β‰ˆ pi a' b'\n | abs {a a' b b'} :\n a β‰ˆ a' β†’\n b β‰ˆ b' β†’\n \n abs a b β‰ˆ abs a' b'\n | app {b b' a a'} :\n b β‰ˆ b' β†’\n a β‰ˆ a' β†’\n \n app b a β‰ˆ app b' a'\n | exf {a a' b b'} :\n a β‰ˆ a' β†’\n b β‰ˆ b' β†’\n \n exf a b β‰ˆ exf a' b'\n | lvl {a a'} :\n a β‰ˆ a' β†’\n \n lvl a β‰ˆ lvl a'\n | refl {a} : a β‰ˆ a\n | sym {a b} :\n a β‰ˆ b β†’\n \n b β‰ˆ a\n | trans {a b c} :\n a β‰ˆ b β†’\n b β‰ˆ c β†’\n \n a β‰ˆ c" }, { "name": "Conv", "content": "def Conv (a : Term) (b : Term) : Prop := βˆƒ c, a ⇒⋆ c ∧ b ⇒⋆ c" }, { "name": "Pars", "content": "inductive Pars : Term β†’ Term β†’ Prop where\n | refl a : a ⇒⋆ a\n | trans {a b c} : a β‡’ b β†’ b ⇒⋆ c β†’ a ⇒⋆ c" }, { "name": "substRename", "content": "def substRename ΞΎ Οƒ : βˆ€ s, subst Οƒ (rename ΞΎ s) = subst (Οƒ ∘ ΞΎ) s :=\n substRename' _ _ (Οƒ ∘ ΞΎ) (by admit /- proof elided -/\n )" }, { "name": "renameSubst", "content": "def renameSubst ΞΎ Οƒ : βˆ€ s, rename ΞΎ (subst Οƒ s) = subst (rename ΞΎ ∘ Οƒ) s :=\n renameSubst' _ _ (rename ΞΎ ∘ Οƒ) (by admit /- proof elided -/\n )" }, { "name": "substComp", "content": "def substComp Οƒ Ο„ : βˆ€ s, (subst Οƒ ∘ subst Ο„) s = subst (subst Οƒ ∘ Ο„) s :=\n substComp' _ _ (subst Οƒ ∘ Ο„) (by admit /- proof elided -/\n )" }, { "name": "infix:40 \"β‡’\" => Par", "content": "infix:40 \"β‡’\" => Par" }, { "name": "infix:40 \"⇒⋆\" => Pars", "content": "infix:40 \"⇒⋆\" => Pars" }, { "name": "infix:40 \"⇔\" => Conv", "content": "infix:40 \"⇔\" => Conv" }, { "name": "infixr:50 \"+:\" => cons", "content": "infixr:50 \"+:\" => cons" }, { "name": "prefix:95 \"⇑\" => up", "content": "prefix:95 \"⇑\" => up" }, { "name": "notation:50 \"⬝\" => Ctxt.nil", "content": "notation:50 \"⬝\" => Ctxt.nil" }, { "name": "infixl:50 \"∷\" => Ctxt.cons", "content": "infixl:50 \"∷\" => Ctxt.cons" }, { "name": "notation:40 Ξ“:41 \"βˆ‹\" x:41 \"∢\" A:41 => In x A Ξ“", "content": "notation:40 Ξ“:41 \"βˆ‹\" x:41 \"∢\" A:41 => In x A Ξ“" }, { "name": "infix:40 (priority := 1001) \"β‰ˆ\" => Eqv", "content": "infix:40 (priority := 1001) \"β‰ˆ\" => Eqv" }, { "name": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“", "content": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“" }, { "name": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A", "content": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A" } ]
[ { "name": "trans", "module": "Mathlib.Order.Defs.Unbundled" } ]
[ { "name": "renameLiftRename", "content": "theorem renameLiftRename ΞΎ a : rename succ (rename ΞΎ a) = rename (lift ΞΎ) (rename succ a)" }, { "name": "liftSucc", "content": "omit lc in\ntheorem liftSucc ΞΎ : βˆ€ x, (lift ΞΎ ∘ succ) x = (succ ∘ ΞΎ) x" }, { "name": "renameComp", "content": "theorem renameComp ΞΎ ΞΆ s : rename ΞΎ (rename ΞΆ s) = rename (ΞΎ ∘ ΞΆ) s" }, { "name": "renameComp'", "content": "theorem renameComp' ΞΎ ΞΆ Ο‚ (h : βˆ€ x, (ΞΎ ∘ ΞΆ) x = Ο‚ x) : βˆ€ s, (rename ΞΎ ∘ rename ΞΆ) s = rename Ο‚ s" }, { "name": "liftComp", "content": "omit lc in\ntheorem liftComp ΞΎ ΞΆ Ο‚ (h : βˆ€ x, (ΞΎ ∘ ΞΆ) x = Ο‚ x) :\n βˆ€ x, (lift ΞΎ ∘ lift ΞΆ) x = lift Ο‚ x" }, { "name": "renameExt", "content": "theorem renameExt ΞΎ ΞΆ (h : βˆ€ x, ΞΎ x = ΞΆ x) : βˆ€ s, rename ΞΎ s = rename ΞΆ s" }, { "name": "liftExt", "content": "omit lc in\ntheorem liftExt ΞΎ ΞΆ (h : βˆ€ x, ΞΎ x = ΞΆ x) : βˆ€ x, lift ΞΎ x = lift ΞΆ x" }, { "name": "wtfPiInvA", "content": "theorem wtfPiInvA {Ξ“ A B 𝒰'}\n (h : Ξ“ ⊒ pi A B ∢ 𝒰') :\n βˆƒ j, Ξ“ ⊒ A ∢ 𝒰 j" }, { "name": "wtfPiInvA𝒰", "content": "theorem wtfPiInvA𝒰 {Ξ“ A B 𝒰'}\n (h : Ξ“ ⊒ pi A B ∢ 𝒰') :\n βˆƒ j, Ξ“ ⊒ A ∢ 𝒰 j ∧ 𝒰 j β‰ˆ 𝒰'" }, { "name": "eqvConv", "content": "theorem eqvConv {a b} (r : a β‰ˆ b) : a ⇔ b" }, { "name": "convRename", "content": "theorem convRename {a b} ΞΎ : a ⇔ b β†’ rename ΞΎ a ⇔ rename ΞΎ b" }, { "name": "parsRename", "content": "theorem parsRename {a b} ΞΎ (r : a ⇒⋆ b) : rename ΞΎ a ⇒⋆ rename ΞΎ b" }, { "name": "parRename", "content": "theorem parRename {a b} ΞΎ (r : a β‡’ b) : rename ΞΎ a β‡’ rename ΞΎ b" }, { "name": "renameDist", "content": "theorem renameDist ΞΎ a s : subst (rename ΞΎ a +: var) (rename (lift ΞΎ) s) = rename ΞΎ (subst (a +: var) s)" }, { "name": "substExt", "content": "theorem substExt Οƒ Ο„ (h : βˆ€ x, Οƒ x = Ο„ x) : βˆ€ s, subst Οƒ s = subst Ο„ s" }, { "name": "upExt", "content": "theorem upExt Οƒ Ο„ (h : βˆ€ x, Οƒ x = Ο„ x) : βˆ€ x, (⇑ Οƒ) x = (⇑ Ο„) x" }, { "name": "wRenameLift", "content": "theorem wRenameLift {ΞΎ : β„• β†’ β„•} {Ξ“ Ξ” A}\n (h : Ξ” ⊒ ΞΎ ∢ Ξ“) :\n Ξ” ∷ (rename ΞΎ A) ⊒ lift ΞΎ ∢ Ξ“ ∷ A" }, { "name": "inHere", "content": "theorem inHere {Ξ“ A A'} (e : A' = rename succ A) : (Ξ“ ∷ A) βˆ‹ 0 ∢ A'" }, { "name": "inThere", "content": "theorem inThere {Ξ“ x A A' B} (h : Ξ“ βˆ‹ x ∢ A) (e : A' = rename succ A) : Ξ“ ∷ B βˆ‹ succ x ∢ A'" }, { "name": "convEqv", "content": "theorem convEqv {a b} : a ⇔ b β†’ a β‰ˆ b" }, { "name": "parsEqv", "content": "theorem parsEqv {a b} (r : a ⇒⋆ b) : a β‰ˆ b" }, { "name": "parEqv", "content": "theorem parEqv {a b} (r : a β‡’ b) : a β‰ˆ b" }, { "name": "wRenameSucc", "content": "theorem wRenameSucc {Ξ“ A} : Ξ“ ∷ A ⊒ succ ∢ Ξ“" }, { "name": "renameUpSubst", "content": "theorem renameUpSubst Οƒ a : rename succ (subst Οƒ a) = subst (⇑ Οƒ) (rename succ a)" }, { "name": "upSucc", "content": "theorem upSucc Οƒ : βˆ€ x, (⇑ Οƒ ∘ succ) x = (rename succ ∘ Οƒ) x" }, { "name": "wtWf", "content": "theorem wtWf {Ξ“} {a A : Term} (h : Ξ“ ⊒ a ∢ A) : ⊒ Ξ“" }, { "name": "convSubst", "content": "theorem convSubst {a b} Οƒ : a ⇔ b β†’ subst Οƒ a ⇔ subst Οƒ b" }, { "name": "parsSubst", "content": "theorem parsSubst {a b} Οƒ (r : a ⇒⋆ b) : subst Οƒ a ⇒⋆ subst Οƒ b" }, { "name": "parSubst", "content": "theorem parSubst {a b} Οƒ (r : a β‡’ b) : subst Οƒ a β‡’ subst Οƒ b" }, { "name": "parRefl", "content": "theorem parRefl a : a β‡’ a" }, { "name": "parMorphing", "content": "theorem parMorphing {a b} Οƒ Ο„ (h : βˆ€ x, Οƒ x β‡’ Ο„ x) (r : a β‡’ b) : subst Οƒ a β‡’ subst Ο„ b" }, { "name": "parLift", "content": "theorem parLift Οƒ Ο„ (h : βˆ€ x, Οƒ x β‡’ Ο„ x) : βˆ€ x, (⇑ Οƒ) x β‡’ (⇑ Ο„) x" }, { "name": "substDist", "content": "theorem substDist Οƒ a s : subst (subst Οƒ a +: var) (subst (⇑ Οƒ) s) = subst Οƒ (subst (a +: var) s)" }, { "name": "substUnion", "content": "theorem substUnion Οƒ a s : subst (a +: Οƒ) s = subst (a +: var) (subst (⇑ Οƒ) s)" }, { "name": "substDropAll", "content": "theorem substDropAll a b : b = subst (a +: var) (rename succ b)" }, { "name": "convSym", "content": "theorem convSym {a b} : a ⇔ b β†’ b ⇔ a" } ]
[]
[ { "name": "wtRename", "content": "theorem wtRename {ΞΎ : β„• β†’ β„•} {Ξ“ Ξ”} {a A : Term}\n (hΞΎ : Ξ” ⊒ ΞΎ ∢ Ξ“) (hΞ” : ⊒ Ξ”) (h : Ξ“ ⊒ a ∢ A) :\n Ξ” ⊒ rename ΞΎ a ∢ rename ΞΎ A" }, { "name": "wtWeaken", "content": "theorem wtWeaken {Ξ“ k} {a A B : Term}\n (hΞ“ : ⊒ Ξ“) (hB : Ξ“ ⊒ B ∢ 𝒰 k) (h : Ξ“ ⊒ a ∢ A) :\n Ξ“ ∷ B ⊒ rename succ a ∢ rename succ A" }, { "name": "wSubstUp", "content": "theorem wSubstUp {Οƒ Ξ” Ξ“ k A}\n (hA : Ξ” ⊒ subst Οƒ A ∢ 𝒰 k)\n (h : Ξ” ⊒ Οƒ ∢ Ξ“) :\n Ξ” ∷ subst Οƒ A ⊒ ⇑ Οƒ ∢ Ξ“ ∷ A" }, { "name": "wtMorph", "content": "theorem wtMorph {Οƒ : β„• β†’ Term} {Ξ“ Ξ”} {a A : Term}\n (hΟƒ : Ξ” ⊒ Οƒ ∢ Ξ“) (hΞ” : ⊒ Ξ”) (h : Ξ“ ⊒ a ∢ A) :\n Ξ” ⊒ subst Οƒ a ∢ subst Οƒ A" } ]
import Β«srcΒ».typing open Nat open Term variable [LevelClass] notation:40 Ξ”:41 "⊒" Οƒ:41 "∢" Ξ“:41 => wSubst Οƒ Ξ“ Ξ”
theorem wtReplace {Ξ“} {A B c C k : Term} (e : A β‰ˆ B) (hB : Ξ“ ⊒ B ∢ 𝒰 k) (h : Ξ“ ∷ A ⊒ c ∢ C) : Ξ“ ∷ B ⊒ c ∢ C :=
:= by cases wtWf h with | cons wfΞ“ hA => let wfΞ“B := Wf.cons wfΞ“ hB rw [← substId c, ← substId C] refine wtMorph ?_ wfΞ“B h intro x A mem; rw [substId]; cases mem case here => exact Wt.conv (convEqv (convRename succ (convSym (eqvConv e)))) (Wt.var wfΞ“B In.here) (wtWeaken wfΞ“ hB hA) case there mem => exact Wt.var wfΞ“B (In.there mem)
9
71
false
Type systems
432
wtAbs
theorem wtAbs {Ξ“} {b A B : Term} (v : Value b) (h : Ξ“ ⊒ b ∢ pi A B) : βˆƒ a' b', b = abs a' b'
TTBFL
src/safety.lean
[ "import Β«srcΒ».typing", "import src.reduction", "import src.typing" ]
[ { "name": "Inhabited", "module": "Init.Prelude" }, { "name": "Lean.ToExpr", "module": "Lean.ToExpr" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Repr", "module": "Init.Data.Repr" }, { "name": "DecidableEq", "module": "Init.Prelude" }, { "name": "List", "module": "Init.Prelude" }, { "name": "String", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" } ]
[ { "name": "notation:40 Ξ”:41 \"⊒\" ΞΎ:41 \"∢\" Ξ“:41 => wRename ΞΎ Ξ“ Ξ”", "content": "notation:40 Ξ”:41 \"⊒\" ΞΎ:41 \"∢\" Ξ“:41 => wRename ΞΎ Ξ“ Ξ”" }, { "name": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“", "content": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“" }, { "name": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A", "content": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A" }, { "name": "notation:40 Ξ”:41 \"⊒\" Οƒ:41 \"∢\" Ξ“:41 => wSubst Οƒ Ξ“ Ξ”", "content": "notation:40 Ξ”:41 \"⊒\" Οƒ:41 \"∢\" Ξ“:41 => wSubst Οƒ Ξ“ Ξ”" }, { "name": "Term", "content": "inductive Term : Type where\n | var : Nat β†’ Term\n | 𝒰 : Term β†’ Term\n | pi : Term β†’ Term β†’ Term\n | abs : Term β†’ Term β†’ Term\n | app : Term β†’ Term β†’ Term\n | mty : Term\n | exf : Term β†’ Term β†’ Term\n | lvl : Term β†’ Term\n | lof : lc.L β†’ Term" }, { "name": "Wf", "content": "inductive Wf : Ctxt β†’ Prop where\n | nil : ⊒ ⬝\n | cons {Ξ“ A k} :\n ⊒ Ξ“ β†’\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n \n ⊒ Ξ“ ∷ A" }, { "name": "Ctxt", "content": "inductive Ctxt : Type where\n | nil : Ctxt\n | cons : Ctxt β†’ Term β†’ Ctxt" }, { "name": "subst", "content": "@[simp]\ndef subst (Οƒ : Nat β†’ Term) : Term β†’ Term\n | var s => Οƒ s\n | 𝒰 a => 𝒰 (subst Οƒ a)\n | pi a b => pi (subst Οƒ a) (subst (⇑ Οƒ) b)\n | abs a b => abs (subst Οƒ a) (subst (⇑ Οƒ) b)\n | app b a => app (subst Οƒ b) (subst Οƒ a)\n | mty => mty\n | exf a b => exf (subst Οƒ a) (subst Οƒ b)\n | lvl a => lvl (subst Οƒ a)\n | lof k => lof k" }, { "name": "Par", "content": "inductive Par : Term β†’ Term β†’ Prop where\n | Ξ² {b b' a a' c} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app (abs c b) a β‡’ subst (a' +: var) b'\n | var s : var s β‡’ var s\n | 𝒰 {a a'} :\n a β‡’ a' β†’\n \n 𝒰 a β‡’ 𝒰 a'\n | pi {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n pi a b β‡’ pi a' b'\n | abs {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n abs a b β‡’ abs a' b'\n | app {b b' a a'} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app b a β‡’ app b' a'\n | mty : mty β‡’ mty\n | exf {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n exf a b β‡’ exf a' b'\n | lvl {a a'} :\n a β‡’ a' β†’\n \n lvl a β‡’ lvl a'\n | lof k : lof k β‡’ lof k" }, { "name": "Eqv", "content": "inductive Eqv : Term β†’ Term β†’ Prop where\n | Ξ² {b a c} : app (abs c b) a β‰ˆ subst (a +: var) b\n | 𝒰 {a a'} :\n a β‰ˆ a' β†’\n \n 𝒰 a β‰ˆ 𝒰 a'\n | pi {a a' b b'} :\n a β‰ˆ a' β†’\n b β‰ˆ b' β†’\n \n pi a b β‰ˆ pi a' b'\n | abs {a a' b b'} :\n a β‰ˆ a' β†’\n b β‰ˆ b' β†’\n \n abs a b β‰ˆ abs a' b'\n | app {b b' a a'} :\n b β‰ˆ b' β†’\n a β‰ˆ a' β†’\n \n app b a β‰ˆ app b' a'\n | exf {a a' b b'} :\n a β‰ˆ a' β†’\n b β‰ˆ b' β†’\n \n exf a b β‰ˆ exf a' b'\n | lvl {a a'} :\n a β‰ˆ a' β†’\n \n lvl a β‰ˆ lvl a'\n | refl {a} : a β‰ˆ a\n | sym {a b} :\n a β‰ˆ b β†’\n \n b β‰ˆ a\n | trans {a b c} :\n a β‰ˆ b β†’\n b β‰ˆ c β†’\n \n a β‰ˆ c" }, { "name": "Wt", "content": "inductive Wt : Ctxt β†’ Term β†’ Term β†’ Prop where\n | var {Ξ“ x A} :\n ⊒ Ξ“ β†’\n Ξ“ βˆ‹ x ∢ A β†’\n \n Ξ“ ⊒ var x ∢ A\n | 𝒰 {Ξ“ j k} :\n Ξ“ ⊒ j ∢ lvl k β†’\n \n Ξ“ ⊒ 𝒰 j ∢ 𝒰 k\n | pi {Ξ“ A B k} :\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n Ξ“ ∷ A ⊒ B ∢ 𝒰 (rename succ k) β†’\n \n Ξ“ ⊒ pi A B ∢ 𝒰 k\n | abs {Ξ“ A B b k} :\n Ξ“ ⊒ pi A B ∢ 𝒰 k β†’\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n Ξ“ ∷ A ⊒ b ∢ B β†’\n \n Ξ“ ⊒ abs A b ∢ pi A B\n | app {Ξ“ A B b a} :\n Ξ“ ⊒ b ∢ pi A B β†’\n Ξ“ ⊒ a ∢ A β†’\n \n Ξ“ ⊒ app b a ∢ subst (a +: var) B\n | mty {Ξ“ j k} :\n Ξ“ ⊒ 𝒰 j ∢ 𝒰 k β†’\n \n Ξ“ ⊒ mty ∢ 𝒰 j\n | exf {Ξ“ A b k} :\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n Ξ“ ⊒ b ∢ mty β†’\n \n Ξ“ ⊒ exf A b ∢ A\n | lvl {Ξ“ a b j k} :\n Ξ“ ⊒ a ∢ lvl b β†’\n Ξ“ ⊒ 𝒰 j ∢ 𝒰 k β†’\n \n Ξ“ ⊒ lvl a ∢ 𝒰 j\n | lof {Ξ“ j k} :\n ⊒ Ξ“ β†’\n j < k β†’\n \n Ξ“ ⊒ lof j ∢ lvl (lof k)\n | trans {Ξ“ i j k} :\n Ξ“ ⊒ i ∢ lvl j β†’\n Ξ“ ⊒ j ∢ lvl k β†’\n \n Ξ“ ⊒ i ∢ lvl k\n | conv {Ξ“ A B a k} :\n A β‰ˆ B β†’\n Ξ“ ⊒ a ∢ A β†’\n Ξ“ ⊒ B ∢ 𝒰 k β†’\n \n Ξ“ ⊒ a ∢ B\n | sub {Ξ“ j k A} :\n Ξ“ ⊒ j ∢ lvl k β†’\n Ξ“ ⊒ A ∢ 𝒰 j β†’\n \n Ξ“ ⊒ A ∢ 𝒰 k" }, { "name": "Conv", "content": "def Conv (a : Term) (b : Term) : Prop := βˆƒ c, a ⇒⋆ c ∧ b ⇒⋆ c" }, { "name": "Pars", "content": "inductive Pars : Term β†’ Term β†’ Prop where\n | refl a : a ⇒⋆ a\n | trans {a b c} : a β‡’ b β†’ b ⇒⋆ c β†’ a ⇒⋆ c" }, { "name": "infix:40 \"β‡’\" => Par", "content": "infix:40 \"β‡’\" => Par" }, { "name": "infix:40 \"⇒⋆\" => Pars", "content": "infix:40 \"⇒⋆\" => Pars" }, { "name": "infix:40 \"⇔\" => Conv", "content": "infix:40 \"⇔\" => Conv" }, { "name": "notation:50 \"⬝\" => Ctxt.nil", "content": "notation:50 \"⬝\" => Ctxt.nil" }, { "name": "infixl:50 \"∷\" => Ctxt.cons", "content": "infixl:50 \"∷\" => Ctxt.cons" }, { "name": "infix:40 (priority := 1001) \"β‰ˆ\" => Eqv", "content": "infix:40 (priority := 1001) \"β‰ˆ\" => Eqv" }, { "name": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“", "content": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“" }, { "name": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A", "content": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A" } ]
[ { "name": "...", "module": "" } ]
[ { "name": "wtfLvlInv", "content": "theorem wtfLvlInv {Ξ“ a 𝒰'}\n (h : Ξ“ ⊒ lvl a ∢ 𝒰') :\n βˆƒ b k, Ξ“ ⊒ a ∢ lvl b ∧ 𝒰 k β‰ˆ 𝒰'" }, { "name": "eqvConv", "content": "theorem eqvConv {a b} (r : a β‰ˆ b) : a ⇔ b" }, { "name": "wtfMtyInv", "content": "theorem wtfMtyInv {Ξ“ 𝒰'}\n (h : Ξ“ ⊒ mty ∢ 𝒰') :\n βˆƒ k, 𝒰 k β‰ˆ 𝒰'" }, { "name": "wtfPiInv𝒰", "content": "theorem wtfPiInv𝒰 {Ξ“ A B 𝒰'}\n (h : Ξ“ ⊒ pi A B ∢ 𝒰') :\n βˆƒ j, 𝒰 j β‰ˆ 𝒰'" }, { "name": "wtfPiInvA𝒰", "content": "theorem wtfPiInvA𝒰 {Ξ“ A B 𝒰'}\n (h : Ξ“ ⊒ pi A B ∢ 𝒰') :\n βˆƒ j, Ξ“ ⊒ A ∢ 𝒰 j ∧ 𝒰 j β‰ˆ 𝒰'" }, { "name": "wtfAbsInv", "content": "theorem wtfAbsInv {Ξ“ A' b C}\n (h : Ξ“ ⊒ abs A' b ∢ C) :\n βˆƒ A B, Ξ“ ∷ A ⊒ b ∢ B ∧ A β‰ˆ A' ∧ pi A B β‰ˆ C" }, { "name": "wtfLofInv", "content": "theorem wtfLofInv {Ξ“ j 𝒰'}\n (h : Ξ“ ⊒ lof j ∢ 𝒰') :\n βˆƒ k, lvl k β‰ˆ 𝒰'" }, { "name": "wtf𝒰Inv", "content": "theorem wtf𝒰Inv {Ξ“ j 𝒰'}\n (h : Ξ“ ⊒ 𝒰 j ∢ 𝒰') :\n βˆƒ k, 𝒰 k β‰ˆ 𝒰'" }, { "name": "conv𝒰Pi", "content": "theorem conv𝒰Pi {c a b} : Β¬ 𝒰 c ⇔ pi a b" }, { "name": "parsPiInv", "content": "theorem parsPiInv {a b c} (r : pi a b ⇒⋆ c) : βˆƒ a' b', c = pi a' b' ∧ a ⇒⋆ a' ∧ b ⇒⋆ b'" }, { "name": "pars𝒰Inv", "content": "theorem pars𝒰Inv {a b} (r : 𝒰 a ⇒⋆ b) : βˆƒ a', b = 𝒰 a' ∧ a ⇒⋆ a'" }, { "name": "convLvlPi", "content": "theorem convLvlPi {a b k} : Β¬ lvl k ⇔ pi a b" }, { "name": "parsLvlInv", "content": "theorem parsLvlInv {i b} (r : lvl i ⇒⋆ b) : βˆƒ j, b = lvl j ∧ i ⇒⋆ j" } ]
[ { "name": "Value", "content": "inductive Value : Term β†’ Type where\n | 𝒰 {k} : Value (𝒰 k)\n | pi {a b} : Value (pi a b)\n | abs {a b} : Value (abs a b)\n | mty : Value mty\n | lvl {k} : Value (lvl k)\n | lof {k} : Value (lof k)" }, { "name": "valueType", "content": "@[simp] \ndef valueType {a} (A : Term) : Value a β†’ Prop\n | Value.𝒰 | Value.pi | Value.mty | Value.lvl => βˆƒ k, 𝒰 k β‰ˆ A\n | Value.abs => βˆƒ B C, pi B C β‰ˆ A\n | Value.lof => βˆƒ k, lvl k β‰ˆ A" } ]
[ { "name": "wtValue", "content": "theorem wtValue {Ξ“} {a A B : Term} (h : Ξ“ ⊒ a ∢ A) (e : A β‰ˆ B) : (v : Value a) β†’ valueType B v\n | Value.𝒰 => let ⟨_, eπ’°βŸ©" } ]
import Β«srcΒ».typing open Nat open Term variable [LevelClass] notation:40 Ξ”:41 "⊒" Οƒ:41 "∢" Ξ“:41 => wSubst Οƒ Ξ“ Ξ” inductive Value : Term β†’ Type where | 𝒰 {k} : Value (𝒰 k) | pi {a b} : Value (pi a b) | abs {a b} : Value (abs a b) | mty : Value mty | lvl {k} : Value (lvl k) | lof {k} : Value (lof k) section end infix:40 "β‡’Ξ²" => CBN infix:40 "⇒β⋆" => CBNs @[simp] def valueType {a} (A : Term) : Value a β†’ Prop | Value.𝒰 | Value.pi | Value.mty | Value.lvl => βˆƒ k, 𝒰 k β‰ˆ A | Value.abs => βˆƒ B C, pi B C β‰ˆ A | Value.lof => βˆƒ k, lvl k β‰ˆ A
theorem wtAbs {Ξ“} {b A B : Term} (v : Value b) (h : Ξ“ ⊒ b ∢ pi A B) : βˆƒ a' b', b = abs a' b' :=
:= by generalize e : pi A B = T at h induction h all_goals try first | subst e | injection e case var | app | exf => contradiction case abs => exact ⟨_, _, rfl⟩ case conv h v epi _ _ => let _e := wtValue h epi v cases v <;> let ⟨_, e⟩ := _e case 𝒰 | pi | mty | lvl => cases conv𝒰Pi (eqvConv e) case abs => exact ⟨_, _, rfl⟩ case lof => cases convLvlPi (eqvConv e)
5
34
false
Type systems
433
interpsBwdsP
theorem interpsBwdsP {i a x y P} (r : x ⇒⋆ y) (h : ⟦ a ⟧ i β†˜ P) : P y β†’ P x
TTBFL
src/candidates.lean
[ "import Β«srcΒ».normal", "import src.reduction", "import src.normal" ]
[ { "name": "Inhabited", "module": "Init.Prelude" }, { "name": "Lean.ToExpr", "module": "Lean.ToExpr" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Repr", "module": "Init.Data.Repr" }, { "name": "String", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "Or", "module": "Init.Prelude" }, { "name": "Or.inl", "module": "Init.Prelude" }, { "name": "Or.inr", "module": "Init.Prelude" } ]
[ { "name": "notation:40 \"⟦\" a \"⟧\" i \",\" I \"β†˜\" P => Interp i I a P", "content": "notation:40 \"⟦\" a \"⟧\" i \",\" I \"β†˜\" P => Interp i I a P" }, { "name": "notation:40 \"⟦\" a \"⟧\" i \"β†˜\" P => Interps i a P", "content": "notation:40 \"⟦\" a \"⟧\" i \"β†˜\" P => Interps i a P" }, { "name": "Pars", "content": "inductive Pars : Term β†’ Term β†’ Prop where\n | refl a : a ⇒⋆ a\n | trans {a b c} : a β‡’ b β†’ b ⇒⋆ c β†’ a ⇒⋆ c" }, { "name": "Par", "content": "inductive Par : Term β†’ Term β†’ Prop where\n | Ξ² {b b' a a' c} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app (abs c b) a β‡’ subst (a' +: var) b'\n | var s : var s β‡’ var s\n | 𝒰 {a a'} :\n a β‡’ a' β†’\n \n 𝒰 a β‡’ 𝒰 a'\n | pi {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n pi a b β‡’ pi a' b'\n | abs {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n abs a b β‡’ abs a' b'\n | app {b b' a a'} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app b a β‡’ app b' a'\n | mty : mty β‡’ mty\n | exf {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n exf a b β‡’ exf a' b'\n | lvl {a a'} :\n a β‡’ a' β†’\n \n lvl a β‡’ lvl a'\n | lof k : lof k β‡’ lof k" }, { "name": "Term", "content": "inductive Term : Type where\n | var : Nat β†’ Term\n | 𝒰 : Term β†’ Term\n | pi : Term β†’ Term β†’ Term\n | abs : Term β†’ Term β†’ Term\n | app : Term β†’ Term β†’ Term\n | mty : Term\n | exf : Term β†’ Term β†’ Term\n | lvl : Term β†’ Term\n | lof : lc.L β†’ Term" }, { "name": "subst", "content": "@[simp]\ndef subst (Οƒ : Nat β†’ Term) : Term β†’ Term\n | var s => Οƒ s\n | 𝒰 a => 𝒰 (subst Οƒ a)\n | pi a b => pi (subst Οƒ a) (subst (⇑ Οƒ) b)\n | abs a b => abs (subst Οƒ a) (subst (⇑ Οƒ) b)\n | app b a => app (subst Οƒ b) (subst Οƒ a)\n | mty => mty\n | exf a b => exf (subst Οƒ a) (subst Οƒ b)\n | lvl a => lvl (subst Οƒ a)\n | lof k => lof k" }, { "name": "nf", "content": "@[simp]\ndef nf : Term β†’ Prop\n | 𝒰 a => nf a\n | pi a b => nf a ∧ nf b\n | abs a b => nf a ∧ nf b\n | app b a => ne b ∧ nf a\n | exf a b => nf a ∧ ne b\n | lvl a => nf a\n | _ => True" }, { "name": "ne", "content": "@[simp]\ndef ne : Term β†’ Prop\n | var _ => True\n | app b a => ne b ∧ nf a\n | exf a b => nf a ∧ ne b\n | _ => False" }, { "name": "LevelClass", "content": "class LevelClass where\n L : Type\n lc : LevelClasses L" }, { "name": "wne", "content": "@[simp] def wne (a : Term) : Prop := βˆƒ b, ne b ∧ a ⇒⋆ b" }, { "name": "infix:40 \"β‡’\" => Par", "content": "infix:40 \"β‡’\" => Par" }, { "name": "infix:40 \"⇒⋆\" => Pars", "content": "infix:40 \"⇒⋆\" => Pars" } ]
[ { "name": "...", "module": "" } ]
[ { "name": "wneBwds", "content": "theorem wneBwds {a b} (r : a ⇒⋆ b) : wne b β†’ wne a" }, { "name": "parsApp", "content": "theorem parsApp {a a' b b'} (rb : b ⇒⋆ b') (ra : a ⇒⋆ a') : app b a ⇒⋆ app b' a'" }, { "name": "parRefl", "content": "theorem parRefl a : a β‡’ a" }, { "name": "parsTrans", "content": "theorem parsTrans {a b c} (r₁ : a ⇒⋆ b) (rβ‚‚ : b ⇒⋆ c) : a ⇒⋆ c" } ]
[ { "name": "Interp", "content": "inductive Interp (i : lc.L) (I : βˆ€ j, j < i β†’ Term β†’ Prop) : Term β†’ (Term β†’ Prop) β†’ Prop where\n | ne a : ne a β†’ Interp i I a wne\n | pi a b Pa (Pf : Term β†’ (Term β†’ Prop) β†’ Prop) :\n Interp i I a Pa β†’\n (βˆ€ x, Pa x β†’ βˆƒ Pb, Pf x Pb) β†’\n (βˆ€ x Pb, Pf x Pb β†’ Interp i I (subst (x +: var) b) Pb) β†’\n Interp i I (pi a b) (Ξ» f ↦ βˆ€ x Pb, Pa x β†’ Pf x Pb β†’ Pb (app f x))\n | 𝒰 j (lt : j < i) : Interp i I (𝒰 (lof j)) (I j lt)\n | mty : Interp i I mty wne\n | lvl b : nf b β†’ Interp i I (lvl b)\n (Ξ» a ↦ (βˆƒ j k, j < k ∧ a ⇒⋆ lof j ∧ b ⇒⋆ lof k) ∨ wne a)\n | step a b P :\n a β‡’ b β†’\n Interp i I b P β†’\n Interp i I a P" }, { "name": "Interps", "content": "def Interps (i : lc.L) : Term β†’ (Term β†’ Prop) β†’ Prop :=\n Interp i (Ξ» j _ a ↦ βˆƒ P, Interps j a P)\ntermination_by i" } ]
[ { "name": "interpsBwd", "content": "theorem interpsBwd {i a b P} (r : a β‡’ b) (h : ⟦ b ⟧ i β†˜ P) : ⟦ a ⟧ i β†˜ P" }, { "name": "interpsBwds", "content": "theorem interpsBwds {i a b P} (r : a ⇒⋆ b) (h : ⟦ b ⟧ i β†˜ P) : ⟦ a ⟧ i β†˜ P" } ]
import Β«srcΒ».normal open Term variable [lc : LevelClass] inductive Interp (i : lc.L) (I : βˆ€ j, j < i β†’ Term β†’ Prop) : Term β†’ (Term β†’ Prop) β†’ Prop where | ne a : ne a β†’ Interp i I a wne | pi a b Pa (Pf : Term β†’ (Term β†’ Prop) β†’ Prop) : Interp i I a Pa β†’ (βˆ€ x, Pa x β†’ βˆƒ Pb, Pf x Pb) β†’ (βˆ€ x Pb, Pf x Pb β†’ Interp i I (subst (x +: var) b) Pb) β†’ Interp i I (pi a b) (Ξ» f ↦ βˆ€ x Pb, Pa x β†’ Pf x Pb β†’ Pb (app f x)) | 𝒰 j (lt : j < i) : Interp i I (𝒰 (lof j)) (I j lt) | mty : Interp i I mty wne | lvl b : nf b β†’ Interp i I (lvl b) (Ξ» a ↦ (βˆƒ j k, j < k ∧ a ⇒⋆ lof j ∧ b ⇒⋆ lof k) ∨ wne a) | step a b P : a β‡’ b β†’ Interp i I b P β†’ Interp i I a P notation:40 "⟦" a "⟧" i "," I "β†˜" P => Interp i I a P def Interps (i : lc.L) : Term β†’ (Term β†’ Prop) β†’ Prop := Interp i (Ξ» j _ a ↦ βˆƒ P, Interps j a P) termination_by i notation:40 "⟦" a "⟧" i "β†˜" P => Interps i a P
theorem interpsBwdsP {i a x y P} (r : x ⇒⋆ y) (h : ⟦ a ⟧ i β†˜ P) : P y β†’ P x :=
:= by unfold Interps at h; induction h generalizing x y case ne => exact wneBwds r case pi ihb => intro h x Pb Pax PfxPb exact ihb x Pb PfxPb (parsApp r (Pars.refl x)) (h x Pb Pax PfxPb) case 𝒰 => exact Ξ» ⟨P, h⟩ ↦ ⟨P, interpsBwds r h⟩ case mty => exact wneBwds r case lvl => intro Py; rcases Py with ⟨j, k, lt, rj, rk⟩ | wney . exact Or.inl ⟨j, k, lt, parsTrans r rj, rk⟩ . exact Or.inr (wneBwds r wney) case step ih => exact ih r
4
27
false
Type systems
434
interpsBwdsP
theorem interpsBwdsP {i a x y P} (r : x ⇒⋆ y) (h : ⟦ a ⟧ i β†˜ P) : P y β†’ P x
TTBFL
src/semantics.lean
[ "import src.reduction", "import Β«srcΒ».reduction" ]
[ { "name": "Inhabited", "module": "Init.Prelude" }, { "name": "Lean.ToExpr", "module": "Lean.ToExpr" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Repr", "module": "Init.Data.Repr" }, { "name": "String", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" } ]
[ { "name": "notation:40 \"⟦\" a \"⟧\" i \",\" I \"β†˜\" P => Interp i I a P", "content": "notation:40 \"⟦\" a \"⟧\" i \",\" I \"β†˜\" P => Interp i I a P" }, { "name": "notation:40 \"⟦\" a \"⟧\" i \"β†˜\" P => Interps i a P", "content": "notation:40 \"⟦\" a \"⟧\" i \"β†˜\" P => Interps i a P" }, { "name": "Pars", "content": "inductive Pars : Term β†’ Term β†’ Prop where\n | refl a : a ⇒⋆ a\n | trans {a b c} : a β‡’ b β†’ b ⇒⋆ c β†’ a ⇒⋆ c" }, { "name": "Par", "content": "inductive Par : Term β†’ Term β†’ Prop where\n | Ξ² {b b' a a' c} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app (abs c b) a β‡’ subst (a' +: var) b'\n | var s : var s β‡’ var s\n | 𝒰 {a a'} :\n a β‡’ a' β†’\n \n 𝒰 a β‡’ 𝒰 a'\n | pi {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n pi a b β‡’ pi a' b'\n | abs {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n abs a b β‡’ abs a' b'\n | app {b b' a a'} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app b a β‡’ app b' a'\n | mty : mty β‡’ mty\n | exf {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n exf a b β‡’ exf a' b'\n | lvl {a a'} :\n a β‡’ a' β†’\n \n lvl a β‡’ lvl a'\n | lof k : lof k β‡’ lof k" }, { "name": "Term", "content": "inductive Term : Type where\n | var : Nat β†’ Term\n | 𝒰 : Term β†’ Term\n | pi : Term β†’ Term β†’ Term\n | abs : Term β†’ Term β†’ Term\n | app : Term β†’ Term β†’ Term\n | mty : Term\n | exf : Term β†’ Term β†’ Term\n | lvl : Term β†’ Term\n | lof : lc.L β†’ Term" }, { "name": "subst", "content": "@[simp]\ndef subst (Οƒ : Nat β†’ Term) : Term β†’ Term\n | var s => Οƒ s\n | 𝒰 a => 𝒰 (subst Οƒ a)\n | pi a b => pi (subst Οƒ a) (subst (⇑ Οƒ) b)\n | abs a b => abs (subst Οƒ a) (subst (⇑ Οƒ) b)\n | app b a => app (subst Οƒ b) (subst Οƒ a)\n | mty => mty\n | exf a b => exf (subst Οƒ a) (subst Οƒ b)\n | lvl a => lvl (subst Οƒ a)\n | lof k => lof k" }, { "name": "LevelClass", "content": "class LevelClass where\n L : Type\n lc : LevelClasses L" }, { "name": "infix:40 \"β‡’\" => Par", "content": "infix:40 \"β‡’\" => Par" }, { "name": "infix:40 \"⇒⋆\" => Pars", "content": "infix:40 \"⇒⋆\" => Pars" } ]
[ { "name": "...", "module": "" } ]
[ { "name": "parsApp", "content": "theorem parsApp {a a' b b'} (rb : b ⇒⋆ b') (ra : a ⇒⋆ a') : app b a ⇒⋆ app b' a'" }, { "name": "parRefl", "content": "theorem parRefl a : a β‡’ a" }, { "name": "parsTrans", "content": "theorem parsTrans {a b c} (r₁ : a ⇒⋆ b) (rβ‚‚ : b ⇒⋆ c) : a ⇒⋆ c" } ]
[ { "name": "Interp", "content": "inductive Interp (i : lc.L) (I : βˆ€ j, j < i β†’ Term β†’ Prop) : Term β†’ (Term β†’ Prop) β†’ Prop where\n | pi a b Pa (Pf : Term β†’ (Term β†’ Prop) β†’ Prop) :\n Interp i I a Pa β†’\n (βˆ€ x, Pa x β†’ βˆƒ Pb, Pf x Pb) β†’\n (βˆ€ x Pb, Pf x Pb β†’ Interp i I (subst (x +: var) b) Pb) β†’\n Interp i I (pi a b) (Ξ» f ↦ βˆ€ x Pb, Pa x β†’ Pf x Pb β†’ Pb (app f x))\n | 𝒰 j (lt : j < i) : Interp i I (𝒰 (lof j)) (I j lt)\n | mty : Interp i I mty (Ξ» _ ↦ False)\n | lvl k : Interp i I (lvl (lof k)) (Ξ» a ↦ βˆƒ j, a ⇒⋆ lof j ∧ j < k)\n | step a b P :\n a β‡’ b β†’\n Interp i I b P β†’\n Interp i I a P" }, { "name": "Interps", "content": "def Interps (i : lc.L) : Term β†’ (Term β†’ Prop) β†’ Prop :=\n Interp i (Ξ» j _ a ↦ βˆƒ P, Interps j a P)\ntermination_by i" } ]
[ { "name": "interpsBwd", "content": "theorem interpsBwd {i a b P} (r : a β‡’ b) (h : ⟦ b ⟧ i β†˜ P) : ⟦ a ⟧ i β†˜ P" }, { "name": "interpsBwds", "content": "theorem interpsBwds {i a b P} (r : a ⇒⋆ b) (h : ⟦ b ⟧ i β†˜ P) : ⟦ a ⟧ i β†˜ P" } ]
import Β«srcΒ».reduction open Term variable [lc : LevelClass] inductive Interp (i : lc.L) (I : βˆ€ j, j < i β†’ Term β†’ Prop) : Term β†’ (Term β†’ Prop) β†’ Prop where | pi a b Pa (Pf : Term β†’ (Term β†’ Prop) β†’ Prop) : Interp i I a Pa β†’ (βˆ€ x, Pa x β†’ βˆƒ Pb, Pf x Pb) β†’ (βˆ€ x Pb, Pf x Pb β†’ Interp i I (subst (x +: var) b) Pb) β†’ Interp i I (pi a b) (Ξ» f ↦ βˆ€ x Pb, Pa x β†’ Pf x Pb β†’ Pb (app f x)) | 𝒰 j (lt : j < i) : Interp i I (𝒰 (lof j)) (I j lt) | mty : Interp i I mty (Ξ» _ ↦ False) | lvl k : Interp i I (lvl (lof k)) (Ξ» a ↦ βˆƒ j, a ⇒⋆ lof j ∧ j < k) | step a b P : a β‡’ b β†’ Interp i I b P β†’ Interp i I a P notation:40 "⟦" a "⟧" i "," I "β†˜" P => Interp i I a P def Interps (i : lc.L) : Term β†’ (Term β†’ Prop) β†’ Prop := Interp i (Ξ» j _ a ↦ βˆƒ P, Interps j a P) termination_by i notation:40 "⟦" a "⟧" i "β†˜" P => Interps i a P
theorem interpsBwdsP {i a x y P} (r : x ⇒⋆ y) (h : ⟦ a ⟧ i β†˜ P) : P y β†’ P x :=
:= by unfold Interps at h; induction h generalizing x y case pi ihb => intro h x Pb Pax PfxPb exact ihb x Pb PfxPb (parsApp r (Pars.refl x)) (h x Pb Pax PfxPb) case 𝒰 => exact Ξ» ⟨P, h⟩ ↦ ⟨P, interpsBwds r h⟩ case mty => simp case lvl => intro ⟨j, rβ‚‚, lt⟩ exact ⟨j, parsTrans r rβ‚‚, lt⟩ case step ih => exact ih r
3
19
false
Type systems
435
wtfAbsInv
theorem wtfAbsInv {Ξ“ A' b C} (h : Ξ“ ⊒ abs A' b ∢ C) : βˆƒ A B, Ξ“ ∷ A ⊒ b ∢ B ∧ A β‰ˆ A' ∧ pi A B β‰ˆ C
TTBFL
src/typing.lean
[ "import src.reduction", "import Β«srcΒ».reduction" ]
[ { "name": "DecidableEq", "module": "Init.Prelude" }, { "name": "Lean.ToExpr", "module": "Lean.ToExpr" }, { "name": "List", "module": "Init.Prelude" }, { "name": "Repr", "module": "Init.Data.Repr" }, { "name": "Nat.sub", "module": "Init.Prelude" }, { "name": "Inhabited", "module": "Init.Prelude" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "String", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "Nat.succ", "module": "Init.Prelude" }, { "name": "Nat.zero", "module": "Init.Prelude" } ]
[ { "name": "notation:40 Ξ”:41 \"⊒\" ΞΎ:41 \"∢\" Ξ“:41 => wRename ΞΎ Ξ“ Ξ”", "content": "notation:40 Ξ”:41 \"⊒\" ΞΎ:41 \"∢\" Ξ“:41 => wRename ΞΎ Ξ“ Ξ”" }, { "name": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“", "content": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“" }, { "name": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A", "content": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A" }, { "name": "notation:40 Ξ”:41 \"⊒\" Οƒ:41 \"∢\" Ξ“:41 => wSubst Οƒ Ξ“ Ξ”", "content": "notation:40 Ξ”:41 \"⊒\" Οƒ:41 \"∢\" Ξ“:41 => wSubst Οƒ Ξ“ Ξ”" }, { "name": "Ctxt", "content": "inductive Ctxt : Type where\n | nil : Ctxt\n | cons : Ctxt β†’ Term β†’ Ctxt" }, { "name": "Term", "content": "inductive Term : Type where\n | var : Nat β†’ Term\n | 𝒰 : Term β†’ Term\n | pi : Term β†’ Term β†’ Term\n | abs : Term β†’ Term β†’ Term\n | app : Term β†’ Term β†’ Term\n | mty : Term\n | exf : Term β†’ Term β†’ Term\n | lvl : Term β†’ Term\n | lof : lc.L β†’ Term" }, { "name": "Par", "content": "inductive Par : Term β†’ Term β†’ Prop where\n | Ξ² {b b' a a' c} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app (abs c b) a β‡’ subst (a' +: var) b'\n | var s : var s β‡’ var s\n | 𝒰 {a a'} :\n a β‡’ a' β†’\n \n 𝒰 a β‡’ 𝒰 a'\n | pi {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n pi a b β‡’ pi a' b'\n | abs {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n abs a b β‡’ abs a' b'\n | app {b b' a a'} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app b a β‡’ app b' a'\n | mty : mty β‡’ mty\n | exf {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n exf a b β‡’ exf a' b'\n | lvl {a a'} :\n a β‡’ a' β†’\n \n lvl a β‡’ lvl a'\n | lof k : lof k β‡’ lof k" }, { "name": "Conv", "content": "def Conv (a : Term) (b : Term) : Prop := βˆƒ c, a ⇒⋆ c ∧ b ⇒⋆ c" }, { "name": "Pars", "content": "inductive Pars : Term β†’ Term β†’ Prop where\n | refl a : a ⇒⋆ a\n | trans {a b c} : a β‡’ b β†’ b ⇒⋆ c β†’ a ⇒⋆ c" }, { "name": "subst", "content": "@[simp]\ndef subst (Οƒ : Nat β†’ Term) : Term β†’ Term\n | var s => Οƒ s\n | 𝒰 a => 𝒰 (subst Οƒ a)\n | pi a b => pi (subst Οƒ a) (subst (⇑ Οƒ) b)\n | abs a b => abs (subst Οƒ a) (subst (⇑ Οƒ) b)\n | app b a => app (subst Οƒ b) (subst Οƒ a)\n | mty => mty\n | exf a b => exf (subst Οƒ a) (subst Οƒ b)\n | lvl a => lvl (subst Οƒ a)\n | lof k => lof k" }, { "name": "taka", "content": "@[simp]\ndef taka : Term β†’ Term\n | 𝒰 a => 𝒰 (taka a)\n | pi a b => pi (taka a) (taka b)\n | abs a b => abs (taka a) (taka b)\n | app b a => match b with\n | abs _ b => subst (taka a +: var) (taka b)\n | b => app (taka b) (taka a)\n | exf a b => exf (taka a) (taka b)\n | lvl a => lvl (taka a)\n | t => t" }, { "name": "up", "content": "@[simp]\ndef up (Οƒ : Nat β†’ Term) : Nat β†’ Term :=\n var 0 +: (rename succ ∘ Οƒ)" }, { "name": "rename", "content": "@[simp]\ndef rename (ΞΎ : Nat β†’ Nat) : Term β†’ Term\n | var s => var (ΞΎ s)\n | 𝒰 a => 𝒰 (rename ΞΎ a)\n | pi a b => pi (rename ΞΎ a) (rename (lift ΞΎ) b)\n | abs a b => abs (rename ΞΎ a) (rename (lift ΞΎ) b)\n | app b a => app (rename ΞΎ b) (rename ΞΎ a)\n | mty => mty\n | exf a b => exf (rename ΞΎ a) (rename ΞΎ b)\n | lvl a => lvl (rename ΞΎ a)\n | lof k => lof k" }, { "name": "lift", "content": "@[simp]\ndef lift (ΞΎ : Nat β†’ Nat) : Nat β†’ Nat :=\n zero +: (succ ∘ ΞΎ)" }, { "name": "cons", "content": "@[simp]\ndef cons {A : Type} (x : A) (ΞΎ : Nat β†’ A) : Nat β†’ A\n | 0 => x\n | n + 1 => ΞΎ n" }, { "name": "infix:40 \"β‡’\" => Par", "content": "infix:40 \"β‡’\" => Par" }, { "name": "infix:40 \"⇒⋆\" => Pars", "content": "infix:40 \"⇒⋆\" => Pars" }, { "name": "infix:40 \"⇔\" => Conv", "content": "infix:40 \"⇔\" => Conv" }, { "name": "infixr:50 \"+:\" => cons", "content": "infixr:50 \"+:\" => cons" }, { "name": "prefix:95 \"⇑\" => up", "content": "prefix:95 \"⇑\" => up" }, { "name": "notation:50 \"⬝\" => Ctxt.nil", "content": "notation:50 \"⬝\" => Ctxt.nil" }, { "name": "infixl:50 \"∷\" => Ctxt.cons", "content": "infixl:50 \"∷\" => Ctxt.cons" } ]
[ { "name": "refl", "module": "Mathlib.Order.Defs.Unbundled" }, { "name": "trans", "module": "Mathlib.Order.Defs.Unbundled" } ]
[ { "name": "conv𝒰", "content": "theorem conv𝒰 {a a'} : a ⇔ a' β†’ 𝒰 a ⇔ 𝒰 a'" }, { "name": "pars𝒰", "content": "theorem pars𝒰 {a a'} (r : a ⇒⋆ a') : 𝒰 a ⇒⋆ 𝒰 a'" }, { "name": "convAbs", "content": "theorem convAbs {a a' b b'} : a ⇔ a' β†’ b ⇔ b' β†’ abs a b ⇔ abs a' b'" }, { "name": "parsAbs", "content": "theorem parsAbs {a a' b b'} (ra : a ⇒⋆ a') (rb : b ⇒⋆ b') : abs a b ⇒⋆ abs a' b'" }, { "name": "parRefl", "content": "theorem parRefl a : a β‡’ a" }, { "name": "convPi", "content": "theorem convPi {a a' b b'} : a ⇔ a' β†’ b ⇔ b' β†’ pi a b ⇔ pi a' b'" }, { "name": "parsPi", "content": "theorem parsPi {a a' b b'} (ra : a ⇒⋆ a') (rb : b ⇒⋆ b') : pi a b ⇒⋆ pi a' b'" }, { "name": "convApp", "content": "theorem convApp {b b' a a'} : b ⇔ b' β†’ a ⇔ a' β†’ app b a ⇔ app b' a'" }, { "name": "parsApp", "content": "theorem parsApp {a a' b b'} (rb : b ⇒⋆ b') (ra : a ⇒⋆ a') : app b a ⇒⋆ app b' a'" }, { "name": "convSym", "content": "theorem convSym {a b} : a ⇔ b β†’ b ⇔ a" }, { "name": "convTrans", "content": "theorem convTrans {a b c} : a ⇔ b β†’ b ⇔ c β†’ a ⇔ c" }, { "name": "confluence", "content": "theorem confluence {a b c} (r₁ : a ⇒⋆ b) (rβ‚‚ : a ⇒⋆ c) : βˆƒ d, b ⇒⋆ d ∧ c ⇒⋆ d" }, { "name": "diacon", "content": "theorem diacon {a b c} (r₁ : a ⇒⋆ b) (rβ‚‚ : a β‡’ c) : βˆƒ d, b ⇒⋆ d ∧ c ⇒⋆ d" }, { "name": "diamond", "content": "theorem diamond {a b c} (r₁ : a β‡’ b) (rβ‚‚ : a β‡’ c) : βˆƒ d, b β‡’ d ∧ c β‡’ d" }, { "name": "parTaka", "content": "theorem parTaka {a b} (r : a β‡’ b) : b β‡’ taka a" }, { "name": "parCong", "content": "theorem parCong {a a' b b'} (ra : a β‡’ a') (rb : b β‡’ b') : subst (a +: var) b β‡’ subst (a' +: var) b'" }, { "name": "parMorphing", "content": "theorem parMorphing {a b} Οƒ Ο„ (h : βˆ€ x, Οƒ x β‡’ Ο„ x) (r : a β‡’ b) : subst Οƒ a β‡’ subst Ο„ b" }, { "name": "parLift", "content": "theorem parLift Οƒ Ο„ (h : βˆ€ x, Οƒ x β‡’ Ο„ x) : βˆ€ x, (⇑ Οƒ) x β‡’ (⇑ Ο„) x" }, { "name": "parRename", "content": "theorem parRename {a b} ΞΎ (r : a β‡’ b) : rename ΞΎ a β‡’ rename ΞΎ b" }, { "name": "parPars", "content": "theorem parPars {a b} (r : a β‡’ b) : a ⇒⋆ b" }, { "name": "parsTrans", "content": "theorem parsTrans {a b c} (r₁ : a ⇒⋆ b) (rβ‚‚ : b ⇒⋆ c) : a ⇒⋆ c" }, { "name": "convExf", "content": "theorem convExf {a a' b b'} : a ⇔ a' β†’ b ⇔ b' β†’ exf a b ⇔ exf a' b'" }, { "name": "parsExf", "content": "theorem parsExf {a a' b b'} (ra : a ⇒⋆ a') (rb : b ⇒⋆ b') : exf a b ⇒⋆ exf a' b'" }, { "name": "convRefl", "content": "theorem convRefl {a} : a ⇔ a" }, { "name": "parConv", "content": "theorem parConv {a b} (r : a β‡’ b) : a ⇔ b" }, { "name": "parsConv", "content": "theorem parsConv {a b} (r : a ⇒⋆ b) : a ⇔ b" }, { "name": "convLvl", "content": "theorem convLvl {a a'} : a ⇔ a' β†’ lvl a ⇔ lvl a'" }, { "name": "parsLvl", "content": "theorem parsLvl {a a'} (r : a ⇒⋆ a') : lvl a ⇒⋆ lvl a'" }, { "name": "conv𝒰Pi", "content": "theorem conv𝒰Pi {c a b} : Β¬ 𝒰 c ⇔ pi a b" }, { "name": "parsPiInv", "content": "theorem parsPiInv {a b c} (r : pi a b ⇒⋆ c) : βˆƒ a' b', c = pi a' b' ∧ a ⇒⋆ a' ∧ b ⇒⋆ b'" }, { "name": "pars𝒰Inv", "content": "theorem pars𝒰Inv {a b} (r : 𝒰 a ⇒⋆ b) : βˆƒ a', b = 𝒰 a' ∧ a ⇒⋆ a'" }, { "name": "convLvlPi", "content": "theorem convLvlPi {a b k} : Β¬ lvl k ⇔ pi a b" }, { "name": "parsLvlInv", "content": "theorem parsLvlInv {i b} (r : lvl i ⇒⋆ b) : βˆƒ j, b = lvl j ∧ i ⇒⋆ j" } ]
[ { "name": "Eqv", "content": "inductive Eqv : Term β†’ Term β†’ Prop where\n | Ξ² {b a c} : app (abs c b) a β‰ˆ subst (a +: var) b\n | 𝒰 {a a'} :\n a β‰ˆ a' β†’\n \n 𝒰 a β‰ˆ 𝒰 a'\n | pi {a a' b b'} :\n a β‰ˆ a' β†’\n b β‰ˆ b' β†’\n \n pi a b β‰ˆ pi a' b'\n | abs {a a' b b'} :\n a β‰ˆ a' β†’\n b β‰ˆ b' β†’\n \n abs a b β‰ˆ abs a' b'\n | app {b b' a a'} :\n b β‰ˆ b' β†’\n a β‰ˆ a' β†’\n \n app b a β‰ˆ app b' a'\n | exf {a a' b b'} :\n a β‰ˆ a' β†’\n b β‰ˆ b' β†’\n \n exf a b β‰ˆ exf a' b'\n | lvl {a a'} :\n a β‰ˆ a' β†’\n \n lvl a β‰ˆ lvl a'\n | refl {a} : a β‰ˆ a\n | sym {a b} :\n a β‰ˆ b β†’\n \n b β‰ˆ a\n | trans {a b c} :\n a β‰ˆ b β†’\n b β‰ˆ c β†’\n \n a β‰ˆ c" }, { "name": "Wf", "content": "inductive Wf : Ctxt β†’ Prop where\n | nil : ⊒ ⬝\n | cons {Ξ“ A k} :\n ⊒ Ξ“ β†’\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n \n ⊒ Ξ“ ∷ A" }, { "name": "Wt", "content": "inductive Wt : Ctxt β†’ Term β†’ Term β†’ Prop where\n | var {Ξ“ x A} :\n ⊒ Ξ“ β†’\n Ξ“ βˆ‹ x ∢ A β†’\n \n Ξ“ ⊒ var x ∢ A\n | 𝒰 {Ξ“ j k} :\n Ξ“ ⊒ j ∢ lvl k β†’\n \n Ξ“ ⊒ 𝒰 j ∢ 𝒰 k\n | pi {Ξ“ A B k} :\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n Ξ“ ∷ A ⊒ B ∢ 𝒰 (rename succ k) β†’\n \n Ξ“ ⊒ pi A B ∢ 𝒰 k\n | abs {Ξ“ A B b k} :\n Ξ“ ⊒ pi A B ∢ 𝒰 k β†’\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n Ξ“ ∷ A ⊒ b ∢ B β†’\n \n Ξ“ ⊒ abs A b ∢ pi A B\n | app {Ξ“ A B b a} :\n Ξ“ ⊒ b ∢ pi A B β†’\n Ξ“ ⊒ a ∢ A β†’\n \n Ξ“ ⊒ app b a ∢ subst (a +: var) B\n | mty {Ξ“ j k} :\n Ξ“ ⊒ 𝒰 j ∢ 𝒰 k β†’\n \n Ξ“ ⊒ mty ∢ 𝒰 j\n | exf {Ξ“ A b k} :\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n Ξ“ ⊒ b ∢ mty β†’\n \n Ξ“ ⊒ exf A b ∢ A\n | lvl {Ξ“ a b j k} :\n Ξ“ ⊒ a ∢ lvl b β†’\n Ξ“ ⊒ 𝒰 j ∢ 𝒰 k β†’\n \n Ξ“ ⊒ lvl a ∢ 𝒰 j\n | lof {Ξ“ j k} :\n ⊒ Ξ“ β†’\n j < k β†’\n \n Ξ“ ⊒ lof j ∢ lvl (lof k)\n | trans {Ξ“ i j k} :\n Ξ“ ⊒ i ∢ lvl j β†’\n Ξ“ ⊒ j ∢ lvl k β†’\n \n Ξ“ ⊒ i ∢ lvl k\n | conv {Ξ“ A B a k} :\n A β‰ˆ B β†’\n Ξ“ ⊒ a ∢ A β†’\n Ξ“ ⊒ B ∢ 𝒰 k β†’\n \n Ξ“ ⊒ a ∢ B\n | sub {Ξ“ j k A} :\n Ξ“ ⊒ j ∢ lvl k β†’\n Ξ“ ⊒ A ∢ 𝒰 j β†’\n \n Ξ“ ⊒ A ∢ 𝒰 k" } ]
[ { "name": "eqvConv", "content": "theorem eqvConv {a b} (r : a β‰ˆ b) : a ⇔ b" } ]
import Β«srcΒ».reduction open Nat open Term variable [LevelClass] section inductive Eqv : Term β†’ Term β†’ Prop where | Ξ² {b a c} : app (abs c b) a β‰ˆ subst (a +: var) b | 𝒰 {a a'} : a β‰ˆ a' β†’ 𝒰 a β‰ˆ 𝒰 a' | pi {a a' b b'} : a β‰ˆ a' β†’ b β‰ˆ b' β†’ pi a b β‰ˆ pi a' b' | abs {a a' b b'} : a β‰ˆ a' β†’ b β‰ˆ b' β†’ abs a b β‰ˆ abs a' b' | app {b b' a a'} : b β‰ˆ b' β†’ a β‰ˆ a' β†’ app b a β‰ˆ app b' a' | exf {a a' b b'} : a β‰ˆ a' β†’ b β‰ˆ b' β†’ exf a b β‰ˆ exf a' b' | lvl {a a'} : a β‰ˆ a' β†’ lvl a β‰ˆ lvl a' | refl {a} : a β‰ˆ a | sym {a b} : a β‰ˆ b β†’ b β‰ˆ a | trans {a b c} : a β‰ˆ b β†’ b β‰ˆ c β†’ a β‰ˆ c end infix:40 (priority := 1001) "β‰ˆ" => Eqv section inductive Wf : Ctxt β†’ Prop where | nil : ⊒ ⬝ | cons {Ξ“ A k} : ⊒ Ξ“ β†’ Ξ“ ⊒ A ∢ 𝒰 k β†’ ⊒ Ξ“ ∷ A inductive Wt : Ctxt β†’ Term β†’ Term β†’ Prop where | var {Ξ“ x A} : ⊒ Ξ“ β†’ Ξ“ βˆ‹ x ∢ A β†’ Ξ“ ⊒ var x ∢ A | 𝒰 {Ξ“ j k} : Ξ“ ⊒ j ∢ lvl k β†’ Ξ“ ⊒ 𝒰 j ∢ 𝒰 k | pi {Ξ“ A B k} : Ξ“ ⊒ A ∢ 𝒰 k β†’ Ξ“ ∷ A ⊒ B ∢ 𝒰 (rename succ k) β†’ Ξ“ ⊒ pi A B ∢ 𝒰 k | abs {Ξ“ A B b k} : Ξ“ ⊒ pi A B ∢ 𝒰 k β†’ Ξ“ ⊒ A ∢ 𝒰 k β†’ Ξ“ ∷ A ⊒ b ∢ B β†’ Ξ“ ⊒ abs A b ∢ pi A B | app {Ξ“ A B b a} : Ξ“ ⊒ b ∢ pi A B β†’ Ξ“ ⊒ a ∢ A β†’ Ξ“ ⊒ app b a ∢ subst (a +: var) B | mty {Ξ“ j k} : Ξ“ ⊒ 𝒰 j ∢ 𝒰 k β†’ Ξ“ ⊒ mty ∢ 𝒰 j | exf {Ξ“ A b k} : Ξ“ ⊒ A ∢ 𝒰 k β†’ Ξ“ ⊒ b ∢ mty β†’ Ξ“ ⊒ exf A b ∢ A | lvl {Ξ“ a b j k} : Ξ“ ⊒ a ∢ lvl b β†’ Ξ“ ⊒ 𝒰 j ∢ 𝒰 k β†’ Ξ“ ⊒ lvl a ∢ 𝒰 j | lof {Ξ“ j k} : ⊒ Ξ“ β†’ j < k β†’ Ξ“ ⊒ lof j ∢ lvl (lof k) | trans {Ξ“ i j k} : Ξ“ ⊒ i ∢ lvl j β†’ Ξ“ ⊒ j ∢ lvl k β†’ Ξ“ ⊒ i ∢ lvl k | conv {Ξ“ A B a k} : A β‰ˆ B β†’ Ξ“ ⊒ a ∢ A β†’ Ξ“ ⊒ B ∢ 𝒰 k β†’ Ξ“ ⊒ a ∢ B | sub {Ξ“ j k A} : Ξ“ ⊒ j ∢ lvl k β†’ Ξ“ ⊒ A ∢ 𝒰 j β†’ Ξ“ ⊒ A ∢ 𝒰 k end end notation:40 "⊒" Ξ“:40 => Wf Ξ“ notation:40 Ξ“:41 "⊒" a:41 "∢" A:41 => Wt Ξ“ a A
theorem wtfAbsInv {Ξ“ A' b C} (h : Ξ“ ⊒ abs A' b ∢ C) : βˆƒ A B, Ξ“ ∷ A ⊒ b ∢ B ∧ A β‰ˆ A' ∧ pi A B β‰ˆ C :=
:= by generalize e : abs A' b = t at h induction h all_goals injections <;> subst_eqs <;> specialize_rfls case abs hb _ => exact ⟨_, _, hb, Eqv.refl, Eqv.refl⟩ case trans ih => let ⟨_, _, _, _, eC⟩ := ih cases convLvlPi (convSym (eqvConv eC)) case conv DC _ _ _ ih => let ⟨A, B, hb, AA', ABD⟩ := ih exact ⟨A, B, hb, AA', Eqv.trans ABD DC⟩ case sub ih => let ⟨_, _, _, _, e⟩ := ih cases conv𝒰Pi (convSym (eqvConv e))
13
62
false
Type systems
436
interpLvlInv
theorem interpLvlInv {i I b P} (h : ⟦ lvl b ⟧ i , I β†˜ P) : wnf b ∧ P = (Ξ» a ↦ (βˆƒ j k, j < k ∧ a ⇒⋆ lof j ∧ b ⇒⋆ lof k) ∨ wne a)
TTBFL
src/candidates.lean
[ "import Β«srcΒ».normal", "import src.reduction", "import src.normal" ]
[ { "name": "Inhabited", "module": "Init.Prelude" }, { "name": "Lean.ToExpr", "module": "Lean.ToExpr" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Repr", "module": "Init.Data.Repr" }, { "name": "String", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "Or", "module": "Init.Prelude" }, { "name": "Or.inl", "module": "Init.Prelude" }, { "name": "Or.inr", "module": "Init.Prelude" }, { "name": "propext", "module": "Init.Core" }, { "name": "Nat.succ", "module": "Init.Prelude" }, { "name": "Nat.zero", "module": "Init.Prelude" } ]
[ { "name": "notation:40 \"⟦\" a \"⟧\" i \",\" I \"β†˜\" P => Interp i I a P", "content": "notation:40 \"⟦\" a \"⟧\" i \",\" I \"β†˜\" P => Interp i I a P" }, { "name": "notation:40 \"⟦\" a \"⟧\" i \"β†˜\" P => Interps i a P", "content": "notation:40 \"⟦\" a \"⟧\" i \"β†˜\" P => Interps i a P" }, { "name": "Pars", "content": "inductive Pars : Term β†’ Term β†’ Prop where\n | refl a : a ⇒⋆ a\n | trans {a b c} : a β‡’ b β†’ b ⇒⋆ c β†’ a ⇒⋆ c" }, { "name": "Par", "content": "inductive Par : Term β†’ Term β†’ Prop where\n | Ξ² {b b' a a' c} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app (abs c b) a β‡’ subst (a' +: var) b'\n | var s : var s β‡’ var s\n | 𝒰 {a a'} :\n a β‡’ a' β†’\n \n 𝒰 a β‡’ 𝒰 a'\n | pi {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n pi a b β‡’ pi a' b'\n | abs {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n abs a b β‡’ abs a' b'\n | app {b b' a a'} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app b a β‡’ app b' a'\n | mty : mty β‡’ mty\n | exf {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n exf a b β‡’ exf a' b'\n | lvl {a a'} :\n a β‡’ a' β†’\n \n lvl a β‡’ lvl a'\n | lof k : lof k β‡’ lof k" }, { "name": "Term", "content": "inductive Term : Type where\n | var : Nat β†’ Term\n | 𝒰 : Term β†’ Term\n | pi : Term β†’ Term β†’ Term\n | abs : Term β†’ Term β†’ Term\n | app : Term β†’ Term β†’ Term\n | mty : Term\n | exf : Term β†’ Term β†’ Term\n | lvl : Term β†’ Term\n | lof : lc.L β†’ Term" }, { "name": "subst", "content": "@[simp]\ndef subst (Οƒ : Nat β†’ Term) : Term β†’ Term\n | var s => Οƒ s\n | 𝒰 a => 𝒰 (subst Οƒ a)\n | pi a b => pi (subst Οƒ a) (subst (⇑ Οƒ) b)\n | abs a b => abs (subst Οƒ a) (subst (⇑ Οƒ) b)\n | app b a => app (subst Οƒ b) (subst Οƒ a)\n | mty => mty\n | exf a b => exf (subst Οƒ a) (subst Οƒ b)\n | lvl a => lvl (subst Οƒ a)\n | lof k => lof k" }, { "name": "nf", "content": "@[simp]\ndef nf : Term β†’ Prop\n | 𝒰 a => nf a\n | pi a b => nf a ∧ nf b\n | abs a b => nf a ∧ nf b\n | app b a => ne b ∧ nf a\n | exf a b => nf a ∧ ne b\n | lvl a => nf a\n | _ => True" }, { "name": "ne", "content": "@[simp]\ndef ne : Term β†’ Prop\n | var _ => True\n | app b a => ne b ∧ nf a\n | exf a b => nf a ∧ ne b\n | _ => False" }, { "name": "LevelClass", "content": "class LevelClass where\n L : Type\n lc : LevelClasses L" }, { "name": "wne", "content": "@[simp] def wne (a : Term) : Prop := βˆƒ b, ne b ∧ a ⇒⋆ b" }, { "name": "wnf", "content": "@[simp] def wnf (a : Term) : Prop := βˆƒ b, nf b ∧ a ⇒⋆ b" }, { "name": "taka", "content": "@[simp]\ndef taka : Term β†’ Term\n | 𝒰 a => 𝒰 (taka a)\n | pi a b => pi (taka a) (taka b)\n | abs a b => abs (taka a) (taka b)\n | app b a => match b with\n | abs _ b => subst (taka a +: var) (taka b)\n | b => app (taka b) (taka a)\n | exf a b => exf (taka a) (taka b)\n | lvl a => lvl (taka a)\n | t => t" }, { "name": "up", "content": "@[simp]\ndef up (Οƒ : Nat β†’ Term) : Nat β†’ Term :=\n var 0 +: (rename succ ∘ Οƒ)" }, { "name": "rename", "content": "@[simp]\ndef rename (ΞΎ : Nat β†’ Nat) : Term β†’ Term\n | var s => var (ΞΎ s)\n | 𝒰 a => 𝒰 (rename ΞΎ a)\n | pi a b => pi (rename ΞΎ a) (rename (lift ΞΎ) b)\n | abs a b => abs (rename ΞΎ a) (rename (lift ΞΎ) b)\n | app b a => app (rename ΞΎ b) (rename ΞΎ a)\n | mty => mty\n | exf a b => exf (rename ΞΎ a) (rename ΞΎ b)\n | lvl a => lvl (rename ΞΎ a)\n | lof k => lof k" }, { "name": "lift", "content": "@[simp]\ndef lift (ΞΎ : Nat β†’ Nat) : Nat β†’ Nat :=\n zero +: (succ ∘ ΞΎ)" }, { "name": "cons", "content": "@[simp]\ndef cons {A : Type} (x : A) (ΞΎ : Nat β†’ A) : Nat β†’ A\n | 0 => x\n | n + 1 => ΞΎ n" }, { "name": "infix:40 \"β‡’\" => Par", "content": "infix:40 \"β‡’\" => Par" }, { "name": "infix:40 \"⇒⋆\" => Pars", "content": "infix:40 \"⇒⋆\" => Pars" }, { "name": "infixr:50 \"+:\" => cons", "content": "infixr:50 \"+:\" => cons" }, { "name": "prefix:95 \"⇑\" => up", "content": "prefix:95 \"⇑\" => up" } ]
[ { "name": "...", "module": "" } ]
[ { "name": "diacon", "content": "theorem diacon {a b c} (r₁ : a ⇒⋆ b) (rβ‚‚ : a β‡’ c) : βˆƒ d, b ⇒⋆ d ∧ c ⇒⋆ d" }, { "name": "diamond", "content": "theorem diamond {a b c} (r₁ : a β‡’ b) (rβ‚‚ : a β‡’ c) : βˆƒ d, b β‡’ d ∧ c β‡’ d" }, { "name": "parTaka", "content": "theorem parTaka {a b} (r : a β‡’ b) : b β‡’ taka a" }, { "name": "parCong", "content": "theorem parCong {a a' b b'} (ra : a β‡’ a') (rb : b β‡’ b') : subst (a +: var) b β‡’ subst (a' +: var) b'" }, { "name": "parMorphing", "content": "theorem parMorphing {a b} Οƒ Ο„ (h : βˆ€ x, Οƒ x β‡’ Ο„ x) (r : a β‡’ b) : subst Οƒ a β‡’ subst Ο„ b" }, { "name": "parLift", "content": "theorem parLift Οƒ Ο„ (h : βˆ€ x, Οƒ x β‡’ Ο„ x) : βˆ€ x, (⇑ Οƒ) x β‡’ (⇑ Ο„) x" }, { "name": "parRename", "content": "theorem parRename {a b} ΞΎ (r : a β‡’ b) : rename ΞΎ a β‡’ rename ΞΎ b" }, { "name": "parPars", "content": "theorem parPars {a b} (r : a β‡’ b) : a ⇒⋆ b" }, { "name": "parsLofInv", "content": "theorem parsLofInv {j b} (r : lof j ⇒⋆ b) : b = lof j" }, { "name": "wnfBwds", "content": "theorem wnfBwds {a b} (r : a ⇒⋆ b) : wnf b β†’ wnf a" }, { "name": "nfWnf", "content": "theorem nfWnf {a} (nfa : nf a) : wnf a" } ]
[ { "name": "Interp", "content": "inductive Interp (i : lc.L) (I : βˆ€ j, j < i β†’ Term β†’ Prop) : Term β†’ (Term β†’ Prop) β†’ Prop where\n | ne a : ne a β†’ Interp i I a wne\n | pi a b Pa (Pf : Term β†’ (Term β†’ Prop) β†’ Prop) :\n Interp i I a Pa β†’\n (βˆ€ x, Pa x β†’ βˆƒ Pb, Pf x Pb) β†’\n (βˆ€ x Pb, Pf x Pb β†’ Interp i I (subst (x +: var) b) Pb) β†’\n Interp i I (pi a b) (Ξ» f ↦ βˆ€ x Pb, Pa x β†’ Pf x Pb β†’ Pb (app f x))\n | 𝒰 j (lt : j < i) : Interp i I (𝒰 (lof j)) (I j lt)\n | mty : Interp i I mty wne\n | lvl b : nf b β†’ Interp i I (lvl b)\n (Ξ» a ↦ (βˆƒ j k, j < k ∧ a ⇒⋆ lof j ∧ b ⇒⋆ lof k) ∨ wne a)\n | step a b P :\n a β‡’ b β†’\n Interp i I b P β†’\n Interp i I a P" } ]
[ { "name": "interpLvlEq", "content": "theorem interpLvlEq {b c} (r : b β‡’ c) :\n (Ξ» a ↦ (βˆƒ j k, j < k ∧ a ⇒⋆ lof j ∧ b ⇒⋆ lof k) ∨ wne a) =\n (Ξ» a ↦ (βˆƒ j k, j < k ∧ a ⇒⋆ lof j ∧ c ⇒⋆ lof k) ∨ wne a)" } ]
import Β«srcΒ».normal open Term variable [lc : LevelClass] inductive Interp (i : lc.L) (I : βˆ€ j, j < i β†’ Term β†’ Prop) : Term β†’ (Term β†’ Prop) β†’ Prop where | ne a : ne a β†’ Interp i I a wne | pi a b Pa (Pf : Term β†’ (Term β†’ Prop) β†’ Prop) : Interp i I a Pa β†’ (βˆ€ x, Pa x β†’ βˆƒ Pb, Pf x Pb) β†’ (βˆ€ x Pb, Pf x Pb β†’ Interp i I (subst (x +: var) b) Pb) β†’ Interp i I (pi a b) (Ξ» f ↦ βˆ€ x Pb, Pa x β†’ Pf x Pb β†’ Pb (app f x)) | 𝒰 j (lt : j < i) : Interp i I (𝒰 (lof j)) (I j lt) | mty : Interp i I mty wne | lvl b : nf b β†’ Interp i I (lvl b) (Ξ» a ↦ (βˆƒ j k, j < k ∧ a ⇒⋆ lof j ∧ b ⇒⋆ lof k) ∨ wne a) | step a b P : a β‡’ b β†’ Interp i I b P β†’ Interp i I a P notation:40 "⟦" a "⟧" i "," I "β†˜" P => Interp i I a P notation:40 "⟦" a "⟧" i "β†˜" P => Interps i a P
theorem interpLvlInv {i I b P} (h : ⟦ lvl b ⟧ i , I β†˜ P) : wnf b ∧ P = (Ξ» a ↦ (βˆƒ j k, j < k ∧ a ⇒⋆ lof j ∧ b ⇒⋆ lof k) ∨ wne a) :=
:= by generalize e : lvl b = c at h induction h generalizing b case ne => subst e; contradiction case lvl nfb => injection e with e; subst e; exact ⟨nfWnf nfb, rfl⟩ case step r _ ih => subst e; let (Par.lvl r₁) := r let ⟨nfc, e⟩ := ih rfl; subst e rw [interpLvlEq r₁] exact ⟨wnfBwds (parPars r₁) nfc, rfl⟩ all_goals contradiction
11
41
false
Type systems
437
wtfLvlInv
theorem wtfLvlInv {Ξ“ a 𝒰'} (h : Ξ“ ⊒ lvl a ∢ 𝒰') : βˆƒ b k, Ξ“ ⊒ a ∢ lvl b ∧ 𝒰 k β‰ˆ 𝒰'
TTBFL
src/typing.lean
[ "import src.reduction", "import Β«srcΒ».reduction" ]
[ { "name": "DecidableEq", "module": "Init.Prelude" }, { "name": "Lean.ToExpr", "module": "Lean.ToExpr" }, { "name": "List", "module": "Init.Prelude" }, { "name": "Repr", "module": "Init.Data.Repr" }, { "name": "Nat.sub", "module": "Init.Prelude" }, { "name": "Inhabited", "module": "Init.Prelude" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "String", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "Nat.succ", "module": "Init.Prelude" }, { "name": "Nat.zero", "module": "Init.Prelude" } ]
[ { "name": "notation:40 Ξ”:41 \"⊒\" ΞΎ:41 \"∢\" Ξ“:41 => wRename ΞΎ Ξ“ Ξ”", "content": "notation:40 Ξ”:41 \"⊒\" ΞΎ:41 \"∢\" Ξ“:41 => wRename ΞΎ Ξ“ Ξ”" }, { "name": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“", "content": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“" }, { "name": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A", "content": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A" }, { "name": "notation:40 Ξ”:41 \"⊒\" Οƒ:41 \"∢\" Ξ“:41 => wSubst Οƒ Ξ“ Ξ”", "content": "notation:40 Ξ”:41 \"⊒\" Οƒ:41 \"∢\" Ξ“:41 => wSubst Οƒ Ξ“ Ξ”" }, { "name": "Ctxt", "content": "inductive Ctxt : Type where\n | nil : Ctxt\n | cons : Ctxt β†’ Term β†’ Ctxt" }, { "name": "Term", "content": "inductive Term : Type where\n | var : Nat β†’ Term\n | 𝒰 : Term β†’ Term\n | pi : Term β†’ Term β†’ Term\n | abs : Term β†’ Term β†’ Term\n | app : Term β†’ Term β†’ Term\n | mty : Term\n | exf : Term β†’ Term β†’ Term\n | lvl : Term β†’ Term\n | lof : lc.L β†’ Term" }, { "name": "Par", "content": "inductive Par : Term β†’ Term β†’ Prop where\n | Ξ² {b b' a a' c} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app (abs c b) a β‡’ subst (a' +: var) b'\n | var s : var s β‡’ var s\n | 𝒰 {a a'} :\n a β‡’ a' β†’\n \n 𝒰 a β‡’ 𝒰 a'\n | pi {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n pi a b β‡’ pi a' b'\n | abs {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n abs a b β‡’ abs a' b'\n | app {b b' a a'} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app b a β‡’ app b' a'\n | mty : mty β‡’ mty\n | exf {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n exf a b β‡’ exf a' b'\n | lvl {a a'} :\n a β‡’ a' β†’\n \n lvl a β‡’ lvl a'\n | lof k : lof k β‡’ lof k" }, { "name": "Conv", "content": "def Conv (a : Term) (b : Term) : Prop := βˆƒ c, a ⇒⋆ c ∧ b ⇒⋆ c" }, { "name": "Pars", "content": "inductive Pars : Term β†’ Term β†’ Prop where\n | refl a : a ⇒⋆ a\n | trans {a b c} : a β‡’ b β†’ b ⇒⋆ c β†’ a ⇒⋆ c" }, { "name": "subst", "content": "@[simp]\ndef subst (Οƒ : Nat β†’ Term) : Term β†’ Term\n | var s => Οƒ s\n | 𝒰 a => 𝒰 (subst Οƒ a)\n | pi a b => pi (subst Οƒ a) (subst (⇑ Οƒ) b)\n | abs a b => abs (subst Οƒ a) (subst (⇑ Οƒ) b)\n | app b a => app (subst Οƒ b) (subst Οƒ a)\n | mty => mty\n | exf a b => exf (subst Οƒ a) (subst Οƒ b)\n | lvl a => lvl (subst Οƒ a)\n | lof k => lof k" }, { "name": "taka", "content": "@[simp]\ndef taka : Term β†’ Term\n | 𝒰 a => 𝒰 (taka a)\n | pi a b => pi (taka a) (taka b)\n | abs a b => abs (taka a) (taka b)\n | app b a => match b with\n | abs _ b => subst (taka a +: var) (taka b)\n | b => app (taka b) (taka a)\n | exf a b => exf (taka a) (taka b)\n | lvl a => lvl (taka a)\n | t => t" }, { "name": "up", "content": "@[simp]\ndef up (Οƒ : Nat β†’ Term) : Nat β†’ Term :=\n var 0 +: (rename succ ∘ Οƒ)" }, { "name": "rename", "content": "@[simp]\ndef rename (ΞΎ : Nat β†’ Nat) : Term β†’ Term\n | var s => var (ΞΎ s)\n | 𝒰 a => 𝒰 (rename ΞΎ a)\n | pi a b => pi (rename ΞΎ a) (rename (lift ΞΎ) b)\n | abs a b => abs (rename ΞΎ a) (rename (lift ΞΎ) b)\n | app b a => app (rename ΞΎ b) (rename ΞΎ a)\n | mty => mty\n | exf a b => exf (rename ΞΎ a) (rename ΞΎ b)\n | lvl a => lvl (rename ΞΎ a)\n | lof k => lof k" }, { "name": "lift", "content": "@[simp]\ndef lift (ΞΎ : Nat β†’ Nat) : Nat β†’ Nat :=\n zero +: (succ ∘ ΞΎ)" }, { "name": "cons", "content": "@[simp]\ndef cons {A : Type} (x : A) (ΞΎ : Nat β†’ A) : Nat β†’ A\n | 0 => x\n | n + 1 => ΞΎ n" }, { "name": "infix:40 \"β‡’\" => Par", "content": "infix:40 \"β‡’\" => Par" }, { "name": "infix:40 \"⇒⋆\" => Pars", "content": "infix:40 \"⇒⋆\" => Pars" }, { "name": "infix:40 \"⇔\" => Conv", "content": "infix:40 \"⇔\" => Conv" }, { "name": "infixr:50 \"+:\" => cons", "content": "infixr:50 \"+:\" => cons" }, { "name": "prefix:95 \"⇑\" => up", "content": "prefix:95 \"⇑\" => up" }, { "name": "notation:50 \"⬝\" => Ctxt.nil", "content": "notation:50 \"⬝\" => Ctxt.nil" }, { "name": "infixl:50 \"∷\" => Ctxt.cons", "content": "infixl:50 \"∷\" => Ctxt.cons" } ]
[ { "name": "refl", "module": "Mathlib.Order.Defs.Unbundled" }, { "name": "trans", "module": "Mathlib.Order.Defs.Unbundled" } ]
[ { "name": "conv𝒰", "content": "theorem conv𝒰 {a a'} : a ⇔ a' β†’ 𝒰 a ⇔ 𝒰 a'" }, { "name": "pars𝒰", "content": "theorem pars𝒰 {a a'} (r : a ⇒⋆ a') : 𝒰 a ⇒⋆ 𝒰 a'" }, { "name": "convAbs", "content": "theorem convAbs {a a' b b'} : a ⇔ a' β†’ b ⇔ b' β†’ abs a b ⇔ abs a' b'" }, { "name": "parsAbs", "content": "theorem parsAbs {a a' b b'} (ra : a ⇒⋆ a') (rb : b ⇒⋆ b') : abs a b ⇒⋆ abs a' b'" }, { "name": "parRefl", "content": "theorem parRefl a : a β‡’ a" }, { "name": "convPi", "content": "theorem convPi {a a' b b'} : a ⇔ a' β†’ b ⇔ b' β†’ pi a b ⇔ pi a' b'" }, { "name": "parsPi", "content": "theorem parsPi {a a' b b'} (ra : a ⇒⋆ a') (rb : b ⇒⋆ b') : pi a b ⇒⋆ pi a' b'" }, { "name": "convApp", "content": "theorem convApp {b b' a a'} : b ⇔ b' β†’ a ⇔ a' β†’ app b a ⇔ app b' a'" }, { "name": "parsApp", "content": "theorem parsApp {a a' b b'} (rb : b ⇒⋆ b') (ra : a ⇒⋆ a') : app b a ⇒⋆ app b' a'" }, { "name": "convSym", "content": "theorem convSym {a b} : a ⇔ b β†’ b ⇔ a" }, { "name": "convTrans", "content": "theorem convTrans {a b c} : a ⇔ b β†’ b ⇔ c β†’ a ⇔ c" }, { "name": "confluence", "content": "theorem confluence {a b c} (r₁ : a ⇒⋆ b) (rβ‚‚ : a ⇒⋆ c) : βˆƒ d, b ⇒⋆ d ∧ c ⇒⋆ d" }, { "name": "diacon", "content": "theorem diacon {a b c} (r₁ : a ⇒⋆ b) (rβ‚‚ : a β‡’ c) : βˆƒ d, b ⇒⋆ d ∧ c ⇒⋆ d" }, { "name": "diamond", "content": "theorem diamond {a b c} (r₁ : a β‡’ b) (rβ‚‚ : a β‡’ c) : βˆƒ d, b β‡’ d ∧ c β‡’ d" }, { "name": "parTaka", "content": "theorem parTaka {a b} (r : a β‡’ b) : b β‡’ taka a" }, { "name": "parCong", "content": "theorem parCong {a a' b b'} (ra : a β‡’ a') (rb : b β‡’ b') : subst (a +: var) b β‡’ subst (a' +: var) b'" }, { "name": "parMorphing", "content": "theorem parMorphing {a b} Οƒ Ο„ (h : βˆ€ x, Οƒ x β‡’ Ο„ x) (r : a β‡’ b) : subst Οƒ a β‡’ subst Ο„ b" }, { "name": "parLift", "content": "theorem parLift Οƒ Ο„ (h : βˆ€ x, Οƒ x β‡’ Ο„ x) : βˆ€ x, (⇑ Οƒ) x β‡’ (⇑ Ο„) x" }, { "name": "parRename", "content": "theorem parRename {a b} ΞΎ (r : a β‡’ b) : rename ΞΎ a β‡’ rename ΞΎ b" }, { "name": "parPars", "content": "theorem parPars {a b} (r : a β‡’ b) : a ⇒⋆ b" }, { "name": "parsTrans", "content": "theorem parsTrans {a b c} (r₁ : a ⇒⋆ b) (rβ‚‚ : b ⇒⋆ c) : a ⇒⋆ c" }, { "name": "convExf", "content": "theorem convExf {a a' b b'} : a ⇔ a' β†’ b ⇔ b' β†’ exf a b ⇔ exf a' b'" }, { "name": "parsExf", "content": "theorem parsExf {a a' b b'} (ra : a ⇒⋆ a') (rb : b ⇒⋆ b') : exf a b ⇒⋆ exf a' b'" }, { "name": "convRefl", "content": "theorem convRefl {a} : a ⇔ a" }, { "name": "parConv", "content": "theorem parConv {a b} (r : a β‡’ b) : a ⇔ b" }, { "name": "parsConv", "content": "theorem parsConv {a b} (r : a ⇒⋆ b) : a ⇔ b" }, { "name": "convLvl", "content": "theorem convLvl {a a'} : a ⇔ a' β†’ lvl a ⇔ lvl a'" }, { "name": "parsLvl", "content": "theorem parsLvl {a a'} (r : a ⇒⋆ a') : lvl a ⇒⋆ lvl a'" }, { "name": "convLvl𝒰", "content": "theorem convLvl𝒰 {j k} : Β¬ lvl j ⇔ 𝒰 k" }, { "name": "parsLvlInv", "content": "theorem parsLvlInv {i b} (r : lvl i ⇒⋆ b) : βˆƒ j, b = lvl j ∧ i ⇒⋆ j" }, { "name": "pars𝒰Inv", "content": "theorem pars𝒰Inv {a b} (r : 𝒰 a ⇒⋆ b) : βˆƒ a', b = 𝒰 a' ∧ a ⇒⋆ a'" } ]
[ { "name": "Eqv", "content": "inductive Eqv : Term β†’ Term β†’ Prop where\n | Ξ² {b a c} : app (abs c b) a β‰ˆ subst (a +: var) b\n | 𝒰 {a a'} :\n a β‰ˆ a' β†’\n \n 𝒰 a β‰ˆ 𝒰 a'\n | pi {a a' b b'} :\n a β‰ˆ a' β†’\n b β‰ˆ b' β†’\n \n pi a b β‰ˆ pi a' b'\n | abs {a a' b b'} :\n a β‰ˆ a' β†’\n b β‰ˆ b' β†’\n \n abs a b β‰ˆ abs a' b'\n | app {b b' a a'} :\n b β‰ˆ b' β†’\n a β‰ˆ a' β†’\n \n app b a β‰ˆ app b' a'\n | exf {a a' b b'} :\n a β‰ˆ a' β†’\n b β‰ˆ b' β†’\n \n exf a b β‰ˆ exf a' b'\n | lvl {a a'} :\n a β‰ˆ a' β†’\n \n lvl a β‰ˆ lvl a'\n | refl {a} : a β‰ˆ a\n | sym {a b} :\n a β‰ˆ b β†’\n \n b β‰ˆ a\n | trans {a b c} :\n a β‰ˆ b β†’\n b β‰ˆ c β†’\n \n a β‰ˆ c" }, { "name": "Wf", "content": "inductive Wf : Ctxt β†’ Prop where\n | nil : ⊒ ⬝\n | cons {Ξ“ A k} :\n ⊒ Ξ“ β†’\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n \n ⊒ Ξ“ ∷ A" }, { "name": "Wt", "content": "inductive Wt : Ctxt β†’ Term β†’ Term β†’ Prop where\n | var {Ξ“ x A} :\n ⊒ Ξ“ β†’\n Ξ“ βˆ‹ x ∢ A β†’\n \n Ξ“ ⊒ var x ∢ A\n | 𝒰 {Ξ“ j k} :\n Ξ“ ⊒ j ∢ lvl k β†’\n \n Ξ“ ⊒ 𝒰 j ∢ 𝒰 k\n | pi {Ξ“ A B k} :\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n Ξ“ ∷ A ⊒ B ∢ 𝒰 (rename succ k) β†’\n \n Ξ“ ⊒ pi A B ∢ 𝒰 k\n | abs {Ξ“ A B b k} :\n Ξ“ ⊒ pi A B ∢ 𝒰 k β†’\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n Ξ“ ∷ A ⊒ b ∢ B β†’\n \n Ξ“ ⊒ abs A b ∢ pi A B\n | app {Ξ“ A B b a} :\n Ξ“ ⊒ b ∢ pi A B β†’\n Ξ“ ⊒ a ∢ A β†’\n \n Ξ“ ⊒ app b a ∢ subst (a +: var) B\n | mty {Ξ“ j k} :\n Ξ“ ⊒ 𝒰 j ∢ 𝒰 k β†’\n \n Ξ“ ⊒ mty ∢ 𝒰 j\n | exf {Ξ“ A b k} :\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n Ξ“ ⊒ b ∢ mty β†’\n \n Ξ“ ⊒ exf A b ∢ A\n | lvl {Ξ“ a b j k} :\n Ξ“ ⊒ a ∢ lvl b β†’\n Ξ“ ⊒ 𝒰 j ∢ 𝒰 k β†’\n \n Ξ“ ⊒ lvl a ∢ 𝒰 j\n | lof {Ξ“ j k} :\n ⊒ Ξ“ β†’\n j < k β†’\n \n Ξ“ ⊒ lof j ∢ lvl (lof k)\n | trans {Ξ“ i j k} :\n Ξ“ ⊒ i ∢ lvl j β†’\n Ξ“ ⊒ j ∢ lvl k β†’\n \n Ξ“ ⊒ i ∢ lvl k\n | conv {Ξ“ A B a k} :\n A β‰ˆ B β†’\n Ξ“ ⊒ a ∢ A β†’\n Ξ“ ⊒ B ∢ 𝒰 k β†’\n \n Ξ“ ⊒ a ∢ B\n | sub {Ξ“ j k A} :\n Ξ“ ⊒ j ∢ lvl k β†’\n Ξ“ ⊒ A ∢ 𝒰 j β†’\n \n Ξ“ ⊒ A ∢ 𝒰 k" } ]
[ { "name": "eqvConv", "content": "theorem eqvConv {a b} (r : a β‰ˆ b) : a ⇔ b" } ]
import Β«srcΒ».reduction open Nat open Term variable [LevelClass] section inductive Eqv : Term β†’ Term β†’ Prop where | Ξ² {b a c} : app (abs c b) a β‰ˆ subst (a +: var) b | 𝒰 {a a'} : a β‰ˆ a' β†’ 𝒰 a β‰ˆ 𝒰 a' | pi {a a' b b'} : a β‰ˆ a' β†’ b β‰ˆ b' β†’ pi a b β‰ˆ pi a' b' | abs {a a' b b'} : a β‰ˆ a' β†’ b β‰ˆ b' β†’ abs a b β‰ˆ abs a' b' | app {b b' a a'} : b β‰ˆ b' β†’ a β‰ˆ a' β†’ app b a β‰ˆ app b' a' | exf {a a' b b'} : a β‰ˆ a' β†’ b β‰ˆ b' β†’ exf a b β‰ˆ exf a' b' | lvl {a a'} : a β‰ˆ a' β†’ lvl a β‰ˆ lvl a' | refl {a} : a β‰ˆ a | sym {a b} : a β‰ˆ b β†’ b β‰ˆ a | trans {a b c} : a β‰ˆ b β†’ b β‰ˆ c β†’ a β‰ˆ c end infix:40 (priority := 1001) "β‰ˆ" => Eqv section inductive Wf : Ctxt β†’ Prop where | nil : ⊒ ⬝ | cons {Ξ“ A k} : ⊒ Ξ“ β†’ Ξ“ ⊒ A ∢ 𝒰 k β†’ ⊒ Ξ“ ∷ A inductive Wt : Ctxt β†’ Term β†’ Term β†’ Prop where | var {Ξ“ x A} : ⊒ Ξ“ β†’ Ξ“ βˆ‹ x ∢ A β†’ Ξ“ ⊒ var x ∢ A | 𝒰 {Ξ“ j k} : Ξ“ ⊒ j ∢ lvl k β†’ Ξ“ ⊒ 𝒰 j ∢ 𝒰 k | pi {Ξ“ A B k} : Ξ“ ⊒ A ∢ 𝒰 k β†’ Ξ“ ∷ A ⊒ B ∢ 𝒰 (rename succ k) β†’ Ξ“ ⊒ pi A B ∢ 𝒰 k | abs {Ξ“ A B b k} : Ξ“ ⊒ pi A B ∢ 𝒰 k β†’ Ξ“ ⊒ A ∢ 𝒰 k β†’ Ξ“ ∷ A ⊒ b ∢ B β†’ Ξ“ ⊒ abs A b ∢ pi A B | app {Ξ“ A B b a} : Ξ“ ⊒ b ∢ pi A B β†’ Ξ“ ⊒ a ∢ A β†’ Ξ“ ⊒ app b a ∢ subst (a +: var) B | mty {Ξ“ j k} : Ξ“ ⊒ 𝒰 j ∢ 𝒰 k β†’ Ξ“ ⊒ mty ∢ 𝒰 j | exf {Ξ“ A b k} : Ξ“ ⊒ A ∢ 𝒰 k β†’ Ξ“ ⊒ b ∢ mty β†’ Ξ“ ⊒ exf A b ∢ A | lvl {Ξ“ a b j k} : Ξ“ ⊒ a ∢ lvl b β†’ Ξ“ ⊒ 𝒰 j ∢ 𝒰 k β†’ Ξ“ ⊒ lvl a ∢ 𝒰 j | lof {Ξ“ j k} : ⊒ Ξ“ β†’ j < k β†’ Ξ“ ⊒ lof j ∢ lvl (lof k) | trans {Ξ“ i j k} : Ξ“ ⊒ i ∢ lvl j β†’ Ξ“ ⊒ j ∢ lvl k β†’ Ξ“ ⊒ i ∢ lvl k | conv {Ξ“ A B a k} : A β‰ˆ B β†’ Ξ“ ⊒ a ∢ A β†’ Ξ“ ⊒ B ∢ 𝒰 k β†’ Ξ“ ⊒ a ∢ B | sub {Ξ“ j k A} : Ξ“ ⊒ j ∢ lvl k β†’ Ξ“ ⊒ A ∢ 𝒰 j β†’ Ξ“ ⊒ A ∢ 𝒰 k end end notation:40 "⊒" Ξ“:40 => Wf Ξ“ notation:40 Ξ“:41 "⊒" a:41 "∢" A:41 => Wt Ξ“ a A
theorem wtfLvlInv {Ξ“ a 𝒰'} (h : Ξ“ ⊒ lvl a ∢ 𝒰') : βˆƒ b k, Ξ“ ⊒ a ∢ lvl b ∧ 𝒰 k β‰ˆ 𝒰' :=
:= by generalize e : lvl a = t at h induction h all_goals injections <;> subst_eqs <;> specialize_rfls case lvl ha _ => exact ⟨_, _, ha, Eqv.refl⟩ case trans ih => let ⟨_, _, _, e⟩ := ih cases convLvl𝒰 (convSym (eqvConv e)) case conv e₁ _ _ _ ih => let ⟨b, _, ha, eβ‚‚βŸ© := ih exact ⟨b, _, ha, Eqv.trans eβ‚‚ eβ‚βŸ© case sub ih => let ⟨b, _, ha, _⟩ := ih exact ⟨b, _, ha, Eqv.refl⟩
13
60
false
Type systems
438
wtfMtyInv
theorem wtfMtyInv {Ξ“ 𝒰'} (h : Ξ“ ⊒ mty ∢ 𝒰') : βˆƒ k, 𝒰 k β‰ˆ 𝒰'
TTBFL
src/typing.lean
[ "import src.reduction", "import Β«srcΒ».reduction" ]
[ { "name": "DecidableEq", "module": "Init.Prelude" }, { "name": "Lean.ToExpr", "module": "Lean.ToExpr" }, { "name": "List", "module": "Init.Prelude" }, { "name": "Repr", "module": "Init.Data.Repr" }, { "name": "Inhabited", "module": "Init.Prelude" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "String", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "Nat.succ", "module": "Init.Prelude" }, { "name": "Nat.zero", "module": "Init.Prelude" } ]
[ { "name": "notation:40 Ξ”:41 \"⊒\" ΞΎ:41 \"∢\" Ξ“:41 => wRename ΞΎ Ξ“ Ξ”", "content": "notation:40 Ξ”:41 \"⊒\" ΞΎ:41 \"∢\" Ξ“:41 => wRename ΞΎ Ξ“ Ξ”" }, { "name": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“", "content": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“" }, { "name": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A", "content": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A" }, { "name": "notation:40 Ξ”:41 \"⊒\" Οƒ:41 \"∢\" Ξ“:41 => wSubst Οƒ Ξ“ Ξ”", "content": "notation:40 Ξ”:41 \"⊒\" Οƒ:41 \"∢\" Ξ“:41 => wSubst Οƒ Ξ“ Ξ”" }, { "name": "Ctxt", "content": "inductive Ctxt : Type where\n | nil : Ctxt\n | cons : Ctxt β†’ Term β†’ Ctxt" }, { "name": "Term", "content": "inductive Term : Type where\n | var : Nat β†’ Term\n | 𝒰 : Term β†’ Term\n | pi : Term β†’ Term β†’ Term\n | abs : Term β†’ Term β†’ Term\n | app : Term β†’ Term β†’ Term\n | mty : Term\n | exf : Term β†’ Term β†’ Term\n | lvl : Term β†’ Term\n | lof : lc.L β†’ Term" }, { "name": "Par", "content": "inductive Par : Term β†’ Term β†’ Prop where\n | Ξ² {b b' a a' c} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app (abs c b) a β‡’ subst (a' +: var) b'\n | var s : var s β‡’ var s\n | 𝒰 {a a'} :\n a β‡’ a' β†’\n \n 𝒰 a β‡’ 𝒰 a'\n | pi {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n pi a b β‡’ pi a' b'\n | abs {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n abs a b β‡’ abs a' b'\n | app {b b' a a'} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app b a β‡’ app b' a'\n | mty : mty β‡’ mty\n | exf {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n exf a b β‡’ exf a' b'\n | lvl {a a'} :\n a β‡’ a' β†’\n \n lvl a β‡’ lvl a'\n | lof k : lof k β‡’ lof k" }, { "name": "Conv", "content": "def Conv (a : Term) (b : Term) : Prop := βˆƒ c, a ⇒⋆ c ∧ b ⇒⋆ c" }, { "name": "Pars", "content": "inductive Pars : Term β†’ Term β†’ Prop where\n | refl a : a ⇒⋆ a\n | trans {a b c} : a β‡’ b β†’ b ⇒⋆ c β†’ a ⇒⋆ c" }, { "name": "subst", "content": "@[simp]\ndef subst (Οƒ : Nat β†’ Term) : Term β†’ Term\n | var s => Οƒ s\n | 𝒰 a => 𝒰 (subst Οƒ a)\n | pi a b => pi (subst Οƒ a) (subst (⇑ Οƒ) b)\n | abs a b => abs (subst Οƒ a) (subst (⇑ Οƒ) b)\n | app b a => app (subst Οƒ b) (subst Οƒ a)\n | mty => mty\n | exf a b => exf (subst Οƒ a) (subst Οƒ b)\n | lvl a => lvl (subst Οƒ a)\n | lof k => lof k" }, { "name": "taka", "content": "@[simp]\ndef taka : Term β†’ Term\n | 𝒰 a => 𝒰 (taka a)\n | pi a b => pi (taka a) (taka b)\n | abs a b => abs (taka a) (taka b)\n | app b a => match b with\n | abs _ b => subst (taka a +: var) (taka b)\n | b => app (taka b) (taka a)\n | exf a b => exf (taka a) (taka b)\n | lvl a => lvl (taka a)\n | t => t" }, { "name": "up", "content": "@[simp]\ndef up (Οƒ : Nat β†’ Term) : Nat β†’ Term :=\n var 0 +: (rename succ ∘ Οƒ)" }, { "name": "rename", "content": "@[simp]\ndef rename (ΞΎ : Nat β†’ Nat) : Term β†’ Term\n | var s => var (ΞΎ s)\n | 𝒰 a => 𝒰 (rename ΞΎ a)\n | pi a b => pi (rename ΞΎ a) (rename (lift ΞΎ) b)\n | abs a b => abs (rename ΞΎ a) (rename (lift ΞΎ) b)\n | app b a => app (rename ΞΎ b) (rename ΞΎ a)\n | mty => mty\n | exf a b => exf (rename ΞΎ a) (rename ΞΎ b)\n | lvl a => lvl (rename ΞΎ a)\n | lof k => lof k" }, { "name": "lift", "content": "@[simp]\ndef lift (ΞΎ : Nat β†’ Nat) : Nat β†’ Nat :=\n zero +: (succ ∘ ΞΎ)" }, { "name": "cons", "content": "@[simp]\ndef cons {A : Type} (x : A) (ΞΎ : Nat β†’ A) : Nat β†’ A\n | 0 => x\n | n + 1 => ΞΎ n" }, { "name": "infix:40 \"β‡’\" => Par", "content": "infix:40 \"β‡’\" => Par" }, { "name": "infix:40 \"⇒⋆\" => Pars", "content": "infix:40 \"⇒⋆\" => Pars" }, { "name": "infix:40 \"⇔\" => Conv", "content": "infix:40 \"⇔\" => Conv" }, { "name": "infixr:50 \"+:\" => cons", "content": "infixr:50 \"+:\" => cons" }, { "name": "prefix:95 \"⇑\" => up", "content": "prefix:95 \"⇑\" => up" }, { "name": "notation:50 \"⬝\" => Ctxt.nil", "content": "notation:50 \"⬝\" => Ctxt.nil" }, { "name": "infixl:50 \"∷\" => Ctxt.cons", "content": "infixl:50 \"∷\" => Ctxt.cons" } ]
[ { "name": "refl", "module": "Mathlib.Order.Defs.Unbundled" }, { "name": "trans", "module": "Mathlib.Order.Defs.Unbundled" } ]
[ { "name": "conv𝒰", "content": "theorem conv𝒰 {a a'} : a ⇔ a' β†’ 𝒰 a ⇔ 𝒰 a'" }, { "name": "pars𝒰", "content": "theorem pars𝒰 {a a'} (r : a ⇒⋆ a') : 𝒰 a ⇒⋆ 𝒰 a'" }, { "name": "convAbs", "content": "theorem convAbs {a a' b b'} : a ⇔ a' β†’ b ⇔ b' β†’ abs a b ⇔ abs a' b'" }, { "name": "parsAbs", "content": "theorem parsAbs {a a' b b'} (ra : a ⇒⋆ a') (rb : b ⇒⋆ b') : abs a b ⇒⋆ abs a' b'" }, { "name": "parRefl", "content": "theorem parRefl a : a β‡’ a" }, { "name": "convPi", "content": "theorem convPi {a a' b b'} : a ⇔ a' β†’ b ⇔ b' β†’ pi a b ⇔ pi a' b'" }, { "name": "parsPi", "content": "theorem parsPi {a a' b b'} (ra : a ⇒⋆ a') (rb : b ⇒⋆ b') : pi a b ⇒⋆ pi a' b'" }, { "name": "convApp", "content": "theorem convApp {b b' a a'} : b ⇔ b' β†’ a ⇔ a' β†’ app b a ⇔ app b' a'" }, { "name": "parsApp", "content": "theorem parsApp {a a' b b'} (rb : b ⇒⋆ b') (ra : a ⇒⋆ a') : app b a ⇒⋆ app b' a'" }, { "name": "convSym", "content": "theorem convSym {a b} : a ⇔ b β†’ b ⇔ a" }, { "name": "convTrans", "content": "theorem convTrans {a b c} : a ⇔ b β†’ b ⇔ c β†’ a ⇔ c" }, { "name": "confluence", "content": "theorem confluence {a b c} (r₁ : a ⇒⋆ b) (rβ‚‚ : a ⇒⋆ c) : βˆƒ d, b ⇒⋆ d ∧ c ⇒⋆ d" }, { "name": "diacon", "content": "theorem diacon {a b c} (r₁ : a ⇒⋆ b) (rβ‚‚ : a β‡’ c) : βˆƒ d, b ⇒⋆ d ∧ c ⇒⋆ d" }, { "name": "diamond", "content": "theorem diamond {a b c} (r₁ : a β‡’ b) (rβ‚‚ : a β‡’ c) : βˆƒ d, b β‡’ d ∧ c β‡’ d" }, { "name": "parTaka", "content": "theorem parTaka {a b} (r : a β‡’ b) : b β‡’ taka a" }, { "name": "parCong", "content": "theorem parCong {a a' b b'} (ra : a β‡’ a') (rb : b β‡’ b') : subst (a +: var) b β‡’ subst (a' +: var) b'" }, { "name": "parMorphing", "content": "theorem parMorphing {a b} Οƒ Ο„ (h : βˆ€ x, Οƒ x β‡’ Ο„ x) (r : a β‡’ b) : subst Οƒ a β‡’ subst Ο„ b" }, { "name": "parLift", "content": "theorem parLift Οƒ Ο„ (h : βˆ€ x, Οƒ x β‡’ Ο„ x) : βˆ€ x, (⇑ Οƒ) x β‡’ (⇑ Ο„) x" }, { "name": "parRename", "content": "theorem parRename {a b} ΞΎ (r : a β‡’ b) : rename ΞΎ a β‡’ rename ΞΎ b" }, { "name": "parPars", "content": "theorem parPars {a b} (r : a β‡’ b) : a ⇒⋆ b" }, { "name": "parsTrans", "content": "theorem parsTrans {a b c} (r₁ : a ⇒⋆ b) (rβ‚‚ : b ⇒⋆ c) : a ⇒⋆ c" }, { "name": "convExf", "content": "theorem convExf {a a' b b'} : a ⇔ a' β†’ b ⇔ b' β†’ exf a b ⇔ exf a' b'" }, { "name": "parsExf", "content": "theorem parsExf {a a' b b'} (ra : a ⇒⋆ a') (rb : b ⇒⋆ b') : exf a b ⇒⋆ exf a' b'" }, { "name": "convRefl", "content": "theorem convRefl {a} : a ⇔ a" }, { "name": "parConv", "content": "theorem parConv {a b} (r : a β‡’ b) : a ⇔ b" }, { "name": "parsConv", "content": "theorem parsConv {a b} (r : a ⇒⋆ b) : a ⇔ b" }, { "name": "convLvl", "content": "theorem convLvl {a a'} : a ⇔ a' β†’ lvl a ⇔ lvl a'" }, { "name": "parsLvl", "content": "theorem parsLvl {a a'} (r : a ⇒⋆ a') : lvl a ⇒⋆ lvl a'" }, { "name": "convLvl𝒰", "content": "theorem convLvl𝒰 {j k} : Β¬ lvl j ⇔ 𝒰 k" }, { "name": "parsLvlInv", "content": "theorem parsLvlInv {i b} (r : lvl i ⇒⋆ b) : βˆƒ j, b = lvl j ∧ i ⇒⋆ j" }, { "name": "pars𝒰Inv", "content": "theorem pars𝒰Inv {a b} (r : 𝒰 a ⇒⋆ b) : βˆƒ a', b = 𝒰 a' ∧ a ⇒⋆ a'" } ]
[ { "name": "Eqv", "content": "inductive Eqv : Term β†’ Term β†’ Prop where\n | Ξ² {b a c} : app (abs c b) a β‰ˆ subst (a +: var) b\n | 𝒰 {a a'} :\n a β‰ˆ a' β†’\n \n 𝒰 a β‰ˆ 𝒰 a'\n | pi {a a' b b'} :\n a β‰ˆ a' β†’\n b β‰ˆ b' β†’\n \n pi a b β‰ˆ pi a' b'\n | abs {a a' b b'} :\n a β‰ˆ a' β†’\n b β‰ˆ b' β†’\n \n abs a b β‰ˆ abs a' b'\n | app {b b' a a'} :\n b β‰ˆ b' β†’\n a β‰ˆ a' β†’\n \n app b a β‰ˆ app b' a'\n | exf {a a' b b'} :\n a β‰ˆ a' β†’\n b β‰ˆ b' β†’\n \n exf a b β‰ˆ exf a' b'\n | lvl {a a'} :\n a β‰ˆ a' β†’\n \n lvl a β‰ˆ lvl a'\n | refl {a} : a β‰ˆ a\n | sym {a b} :\n a β‰ˆ b β†’\n \n b β‰ˆ a\n | trans {a b c} :\n a β‰ˆ b β†’\n b β‰ˆ c β†’\n \n a β‰ˆ c" }, { "name": "Wf", "content": "inductive Wf : Ctxt β†’ Prop where\n | nil : ⊒ ⬝\n | cons {Ξ“ A k} :\n ⊒ Ξ“ β†’\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n \n ⊒ Ξ“ ∷ A" }, { "name": "Wt", "content": "inductive Wt : Ctxt β†’ Term β†’ Term β†’ Prop where\n | var {Ξ“ x A} :\n ⊒ Ξ“ β†’\n Ξ“ βˆ‹ x ∢ A β†’\n \n Ξ“ ⊒ var x ∢ A\n | 𝒰 {Ξ“ j k} :\n Ξ“ ⊒ j ∢ lvl k β†’\n \n Ξ“ ⊒ 𝒰 j ∢ 𝒰 k\n | pi {Ξ“ A B k} :\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n Ξ“ ∷ A ⊒ B ∢ 𝒰 (rename succ k) β†’\n \n Ξ“ ⊒ pi A B ∢ 𝒰 k\n | abs {Ξ“ A B b k} :\n Ξ“ ⊒ pi A B ∢ 𝒰 k β†’\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n Ξ“ ∷ A ⊒ b ∢ B β†’\n \n Ξ“ ⊒ abs A b ∢ pi A B\n | app {Ξ“ A B b a} :\n Ξ“ ⊒ b ∢ pi A B β†’\n Ξ“ ⊒ a ∢ A β†’\n \n Ξ“ ⊒ app b a ∢ subst (a +: var) B\n | mty {Ξ“ j k} :\n Ξ“ ⊒ 𝒰 j ∢ 𝒰 k β†’\n \n Ξ“ ⊒ mty ∢ 𝒰 j\n | exf {Ξ“ A b k} :\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n Ξ“ ⊒ b ∢ mty β†’\n \n Ξ“ ⊒ exf A b ∢ A\n | lvl {Ξ“ a b j k} :\n Ξ“ ⊒ a ∢ lvl b β†’\n Ξ“ ⊒ 𝒰 j ∢ 𝒰 k β†’\n \n Ξ“ ⊒ lvl a ∢ 𝒰 j\n | lof {Ξ“ j k} :\n ⊒ Ξ“ β†’\n j < k β†’\n \n Ξ“ ⊒ lof j ∢ lvl (lof k)\n | trans {Ξ“ i j k} :\n Ξ“ ⊒ i ∢ lvl j β†’\n Ξ“ ⊒ j ∢ lvl k β†’\n \n Ξ“ ⊒ i ∢ lvl k\n | conv {Ξ“ A B a k} :\n A β‰ˆ B β†’\n Ξ“ ⊒ a ∢ A β†’\n Ξ“ ⊒ B ∢ 𝒰 k β†’\n \n Ξ“ ⊒ a ∢ B\n | sub {Ξ“ j k A} :\n Ξ“ ⊒ j ∢ lvl k β†’\n Ξ“ ⊒ A ∢ 𝒰 j β†’\n \n Ξ“ ⊒ A ∢ 𝒰 k" } ]
[ { "name": "eqvConv", "content": "theorem eqvConv {a b} (r : a β‰ˆ b) : a ⇔ b" } ]
import Β«srcΒ».reduction open Nat open Term variable [LevelClass] section inductive Eqv : Term β†’ Term β†’ Prop where | Ξ² {b a c} : app (abs c b) a β‰ˆ subst (a +: var) b | 𝒰 {a a'} : a β‰ˆ a' β†’ 𝒰 a β‰ˆ 𝒰 a' | pi {a a' b b'} : a β‰ˆ a' β†’ b β‰ˆ b' β†’ pi a b β‰ˆ pi a' b' | abs {a a' b b'} : a β‰ˆ a' β†’ b β‰ˆ b' β†’ abs a b β‰ˆ abs a' b' | app {b b' a a'} : b β‰ˆ b' β†’ a β‰ˆ a' β†’ app b a β‰ˆ app b' a' | exf {a a' b b'} : a β‰ˆ a' β†’ b β‰ˆ b' β†’ exf a b β‰ˆ exf a' b' | lvl {a a'} : a β‰ˆ a' β†’ lvl a β‰ˆ lvl a' | refl {a} : a β‰ˆ a | sym {a b} : a β‰ˆ b β†’ b β‰ˆ a | trans {a b c} : a β‰ˆ b β†’ b β‰ˆ c β†’ a β‰ˆ c end infix:40 (priority := 1001) "β‰ˆ" => Eqv section inductive Wf : Ctxt β†’ Prop where | nil : ⊒ ⬝ | cons {Ξ“ A k} : ⊒ Ξ“ β†’ Ξ“ ⊒ A ∢ 𝒰 k β†’ ⊒ Ξ“ ∷ A inductive Wt : Ctxt β†’ Term β†’ Term β†’ Prop where | var {Ξ“ x A} : ⊒ Ξ“ β†’ Ξ“ βˆ‹ x ∢ A β†’ Ξ“ ⊒ var x ∢ A | 𝒰 {Ξ“ j k} : Ξ“ ⊒ j ∢ lvl k β†’ Ξ“ ⊒ 𝒰 j ∢ 𝒰 k | pi {Ξ“ A B k} : Ξ“ ⊒ A ∢ 𝒰 k β†’ Ξ“ ∷ A ⊒ B ∢ 𝒰 (rename succ k) β†’ Ξ“ ⊒ pi A B ∢ 𝒰 k | abs {Ξ“ A B b k} : Ξ“ ⊒ pi A B ∢ 𝒰 k β†’ Ξ“ ⊒ A ∢ 𝒰 k β†’ Ξ“ ∷ A ⊒ b ∢ B β†’ Ξ“ ⊒ abs A b ∢ pi A B | app {Ξ“ A B b a} : Ξ“ ⊒ b ∢ pi A B β†’ Ξ“ ⊒ a ∢ A β†’ Ξ“ ⊒ app b a ∢ subst (a +: var) B | mty {Ξ“ j k} : Ξ“ ⊒ 𝒰 j ∢ 𝒰 k β†’ Ξ“ ⊒ mty ∢ 𝒰 j | exf {Ξ“ A b k} : Ξ“ ⊒ A ∢ 𝒰 k β†’ Ξ“ ⊒ b ∢ mty β†’ Ξ“ ⊒ exf A b ∢ A | lvl {Ξ“ a b j k} : Ξ“ ⊒ a ∢ lvl b β†’ Ξ“ ⊒ 𝒰 j ∢ 𝒰 k β†’ Ξ“ ⊒ lvl a ∢ 𝒰 j | lof {Ξ“ j k} : ⊒ Ξ“ β†’ j < k β†’ Ξ“ ⊒ lof j ∢ lvl (lof k) | trans {Ξ“ i j k} : Ξ“ ⊒ i ∢ lvl j β†’ Ξ“ ⊒ j ∢ lvl k β†’ Ξ“ ⊒ i ∢ lvl k | conv {Ξ“ A B a k} : A β‰ˆ B β†’ Ξ“ ⊒ a ∢ A β†’ Ξ“ ⊒ B ∢ 𝒰 k β†’ Ξ“ ⊒ a ∢ B | sub {Ξ“ j k A} : Ξ“ ⊒ j ∢ lvl k β†’ Ξ“ ⊒ A ∢ 𝒰 j β†’ Ξ“ ⊒ A ∢ 𝒰 k end end notation:40 "⊒" Ξ“:40 => Wf Ξ“ notation:40 Ξ“:41 "⊒" a:41 "∢" A:41 => Wt Ξ“ a A
theorem wtfMtyInv {Ξ“ 𝒰'} (h : Ξ“ ⊒ mty ∢ 𝒰') : βˆƒ k, 𝒰 k β‰ˆ 𝒰' :=
:= by generalize e : mty = t at h induction h all_goals injections <;> subst_eqs <;> specialize_rfls case mty | sub => exact ⟨_, Eqv.refl⟩ case trans ih => let ⟨_, e⟩ := ih cases convLvl𝒰 (convSym (eqvConv e)) case conv e₁ _ _ _ ih => let ⟨_, eβ‚‚βŸ© := ih exact ⟨_, Eqv.trans eβ‚‚ eβ‚βŸ©
13
59
false
Type systems
439
parsAntirenaming
theorem parsAntirenaming {ΞΎ a b'} (r : rename ΞΎ a ⇒⋆ b') : βˆƒ b, b' = rename ΞΎ b ∧ a ⇒⋆ b
TTBFL
src/reduction.lean
[ "import src.syntactics", "import Β«srcΒ».syntactics", "import Β«srcΒ».tactics" ]
[ { "name": "Inhabited", "module": "Init.Prelude" }, { "name": "Lean.ToExpr", "module": "Lean.ToExpr" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Repr", "module": "Init.Data.Repr" }, { "name": "String", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "Nat.succ", "module": "Init.Prelude" }, { "name": "Nat.zero", "module": "Init.Prelude" } ]
[ { "name": "Term", "content": "inductive Term : Type where\n | var : Nat β†’ Term\n | 𝒰 : Term β†’ Term\n | pi : Term β†’ Term β†’ Term\n | abs : Term β†’ Term β†’ Term\n | app : Term β†’ Term β†’ Term\n | mty : Term\n | exf : Term β†’ Term β†’ Term\n | lvl : Term β†’ Term\n | lof : lc.L β†’ Term" }, { "name": "subst", "content": "@[simp]\ndef subst (Οƒ : Nat β†’ Term) : Term β†’ Term\n | var s => Οƒ s\n | 𝒰 a => 𝒰 (subst Οƒ a)\n | pi a b => pi (subst Οƒ a) (subst (⇑ Οƒ) b)\n | abs a b => abs (subst Οƒ a) (subst (⇑ Οƒ) b)\n | app b a => app (subst Οƒ b) (subst Οƒ a)\n | mty => mty\n | exf a b => exf (subst Οƒ a) (subst Οƒ b)\n | lvl a => lvl (subst Οƒ a)\n | lof k => lof k" }, { "name": "Par", "content": "inductive Par : Term β†’ Term β†’ Prop where\n | Ξ² {b b' a a' c} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app (abs c b) a β‡’ subst (a' +: var) b'\n | var s : var s β‡’ var s\n | 𝒰 {a a'} :\n a β‡’ a' β†’\n \n 𝒰 a β‡’ 𝒰 a'\n | pi {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n pi a b β‡’ pi a' b'\n | abs {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n abs a b β‡’ abs a' b'\n | app {b b' a a'} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app b a β‡’ app b' a'\n | mty : mty β‡’ mty\n | exf {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n exf a b β‡’ exf a' b'\n | lvl {a a'} :\n a β‡’ a' β†’\n \n lvl a β‡’ lvl a'\n | lof k : lof k β‡’ lof k" }, { "name": "rename", "content": "@[simp]\ndef rename (ΞΎ : Nat β†’ Nat) : Term β†’ Term\n | var s => var (ΞΎ s)\n | 𝒰 a => 𝒰 (rename ΞΎ a)\n | pi a b => pi (rename ΞΎ a) (rename (lift ΞΎ) b)\n | abs a b => abs (rename ΞΎ a) (rename (lift ΞΎ) b)\n | app b a => app (rename ΞΎ b) (rename ΞΎ a)\n | mty => mty\n | exf a b => exf (rename ΞΎ a) (rename ΞΎ b)\n | lvl a => lvl (rename ΞΎ a)\n | lof k => lof k" }, { "name": "lift", "content": "@[simp]\ndef lift (ΞΎ : Nat β†’ Nat) : Nat β†’ Nat :=\n zero +: (succ ∘ ΞΎ)" }, { "name": "cons", "content": "@[simp]\ndef cons {A : Type} (x : A) (ΞΎ : Nat β†’ A) : Nat β†’ A\n | 0 => x\n | n + 1 => ΞΎ n" }, { "name": "substRename", "content": "def substRename ΞΎ Οƒ : βˆ€ s, subst Οƒ (rename ΞΎ s) = subst (Οƒ ∘ ΞΎ) s :=\n substRename' _ _ (Οƒ ∘ ΞΎ) (by admit /- proof elided -/\n )" }, { "name": "renameSubst", "content": "def renameSubst ΞΎ Οƒ : βˆ€ s, rename ΞΎ (subst Οƒ s) = subst (rename ΞΎ ∘ Οƒ) s :=\n renameSubst' _ _ (rename ΞΎ ∘ Οƒ) (by admit /- proof elided -/\n )" }, { "name": "up", "content": "@[simp]\ndef up (Οƒ : Nat β†’ Term) : Nat β†’ Term :=\n var 0 +: (rename succ ∘ Οƒ)" }, { "name": "infixr:50 \"+:\" => cons", "content": "infixr:50 \"+:\" => cons" }, { "name": "prefix:95 \"⇑\" => up", "content": "prefix:95 \"⇑\" => up" } ]
[ { "name": "...", "module": "" } ]
[ { "name": "renameDist", "content": "theorem renameDist ΞΎ a s : subst (rename ΞΎ a +: var) (rename (lift ΞΎ) s) = rename ΞΎ (subst (a +: var) s)" }, { "name": "substExt", "content": "theorem substExt Οƒ Ο„ (h : βˆ€ x, Οƒ x = Ο„ x) : βˆ€ s, subst Οƒ s = subst Ο„ s" }, { "name": "upExt", "content": "theorem upExt Οƒ Ο„ (h : βˆ€ x, Οƒ x = Ο„ x) : βˆ€ x, (⇑ Οƒ) x = (⇑ Ο„) x" } ]
[ { "name": "Par", "content": "inductive Par : Term β†’ Term β†’ Prop where\n | Ξ² {b b' a a' c} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app (abs c b) a β‡’ subst (a' +: var) b'\n | var s : var s β‡’ var s\n | 𝒰 {a a'} :\n a β‡’ a' β†’\n \n 𝒰 a β‡’ 𝒰 a'\n | pi {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n pi a b β‡’ pi a' b'\n | abs {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n abs a b β‡’ abs a' b'\n | app {b b' a a'} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app b a β‡’ app b' a'\n | mty : mty β‡’ mty\n | exf {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n exf a b β‡’ exf a' b'\n | lvl {a a'} :\n a β‡’ a' β†’\n \n lvl a β‡’ lvl a'\n | lof k : lof k β‡’ lof k" }, { "name": "Pars", "content": "inductive Pars : Term β†’ Term β†’ Prop where\n | refl a : a ⇒⋆ a\n | trans {a b c} : a β‡’ b β†’ b ⇒⋆ c β†’ a ⇒⋆ c" } ]
[ { "name": "parRefl", "content": "theorem parRefl a : a β‡’ a" }, { "name": "antirenaming", "content": "theorem antirenaming {ΞΎ a b'} (r : rename ΞΎ a β‡’ b') : βˆƒ b, b' = rename ΞΎ b ∧ a β‡’ b" } ]
import Β«srcΒ».tactics import Β«srcΒ».syntactics open Term variable [LevelClass] section inductive Par : Term β†’ Term β†’ Prop where | Ξ² {b b' a a' c} : b β‡’ b' β†’ a β‡’ a' β†’ app (abs c b) a β‡’ subst (a' +: var) b' | var s : var s β‡’ var s | 𝒰 {a a'} : a β‡’ a' β†’ 𝒰 a β‡’ 𝒰 a' | pi {a a' b b'} : a β‡’ a' β†’ b β‡’ b' β†’ pi a b β‡’ pi a' b' | abs {a a' b b'} : a β‡’ a' β†’ b β‡’ b' β†’ abs a b β‡’ abs a' b' | app {b b' a a'} : b β‡’ b' β†’ a β‡’ a' β†’ app b a β‡’ app b' a' | mty : mty β‡’ mty | exf {a a' b b'} : a β‡’ a' β†’ b β‡’ b' β†’ exf a b β‡’ exf a' b' | lvl {a a'} : a β‡’ a' β†’ lvl a β‡’ lvl a' | lof k : lof k β‡’ lof k end infix:40 "β‡’" => Par section inductive Pars : Term β†’ Term β†’ Prop where | refl a : a ⇒⋆ a | trans {a b c} : a β‡’ b β†’ b ⇒⋆ c β†’ a ⇒⋆ c end infix:40 "⇒⋆" => Pars open Pars
theorem parsAntirenaming {ΞΎ a b'} (r : rename ΞΎ a ⇒⋆ b') : βˆƒ b, b' = rename ΞΎ b ∧ a ⇒⋆ b :=
:= by generalize e : rename ξ a = a' at r induction r generalizing ξ a <;> subst e case refl => exact ⟨a, rfl, Pars.refl a⟩ case trans ih ra => let ⟨b, eb, rb⟩ := antirenaming ra; subst eb let ⟨c, ec, rc⟩ := ih rfl exact ⟨c, ec, Pars.trans rb rc⟩
5
25
false
Type systems
440
substUnion
theorem substUnion Οƒ a s : subst (a +: Οƒ) s = subst (a +: var) (subst (⇑ Οƒ) s)
TTBFL
src/syntactics.lean
[ "import Β«srcΒ».level" ]
[ { "name": "Nat", "module": "Init.Prelude" }, { "name": "Nat.succ", "module": "Init.Prelude" }, { "name": "Nat.zero", "module": "Init.Prelude" } ]
[ { "name": "LevelClass", "content": "class LevelClass where\n L : Type\n lc : LevelClasses L" } ]
[ { "name": "...", "module": "" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "cons", "content": "@[simp]\ndef cons {A : Type} (x : A) (ΞΎ : Nat β†’ A) : Nat β†’ A\n | 0 => x\n | n + 1 => ΞΎ n" }, { "name": "Term", "content": "inductive Term : Type where\n | var : Nat β†’ Term\n | 𝒰 : Term β†’ Term\n | pi : Term β†’ Term β†’ Term\n | abs : Term β†’ Term β†’ Term\n | app : Term β†’ Term β†’ Term\n | mty : Term\n | exf : Term β†’ Term β†’ Term\n | lvl : Term β†’ Term\n | lof : lc.L β†’ Term" }, { "name": "lift", "content": "@[simp]\ndef lift (ΞΎ : Nat β†’ Nat) : Nat β†’ Nat :=\n zero +: (succ ∘ ΞΎ)" }, { "name": "rename", "content": "@[simp]\ndef rename (ΞΎ : Nat β†’ Nat) : Term β†’ Term\n | var s => var (ΞΎ s)\n | 𝒰 a => 𝒰 (rename ΞΎ a)\n | pi a b => pi (rename ΞΎ a) (rename (lift ΞΎ) b)\n | abs a b => abs (rename ΞΎ a) (rename (lift ΞΎ) b)\n | app b a => app (rename ΞΎ b) (rename ΞΎ a)\n | mty => mty\n | exf a b => exf (rename ΞΎ a) (rename ΞΎ b)\n | lvl a => lvl (rename ΞΎ a)\n | lof k => lof k" }, { "name": "up", "content": "@[simp]\ndef up (Οƒ : Nat β†’ Term) : Nat β†’ Term :=\n var 0 +: (rename succ ∘ Οƒ)" }, { "name": "subst", "content": "@[simp]\ndef subst (Οƒ : Nat β†’ Term) : Term β†’ Term\n | var s => Οƒ s\n | 𝒰 a => 𝒰 (subst Οƒ a)\n | pi a b => pi (subst Οƒ a) (subst (⇑ Οƒ) b)\n | abs a b => abs (subst Οƒ a) (subst (⇑ Οƒ) b)\n | app b a => app (subst Οƒ b) (subst Οƒ a)\n | mty => mty\n | exf a b => exf (subst Οƒ a) (subst Οƒ b)\n | lvl a => lvl (subst Οƒ a)\n | lof k => lof k" }, { "name": "substId", "content": "def substId : βˆ€ s, subst var s = s :=\n substId' var (by admit /- proof elided -/\n )" }, { "name": "substRename", "content": "def substRename ΞΎ Οƒ : βˆ€ s, subst Οƒ (rename ΞΎ s) = subst (Οƒ ∘ ΞΎ) s :=\n substRename' _ _ (Οƒ ∘ ΞΎ) (by admit /- proof elided -/\n )" }, { "name": "substComp", "content": "def substComp Οƒ Ο„ : βˆ€ s, (subst Οƒ ∘ subst Ο„) s = subst (subst Οƒ ∘ Ο„) s :=\n substComp' _ _ (subst Οƒ ∘ Ο„) (by admit /- proof elided -/\n )" } ]
[ { "name": "upExt", "content": "theorem upExt Οƒ Ο„ (h : βˆ€ x, Οƒ x = Ο„ x) : βˆ€ x, (⇑ Οƒ) x = (⇑ Ο„) x" }, { "name": "substExt", "content": "theorem substExt Οƒ Ο„ (h : βˆ€ x, Οƒ x = Ο„ x) : βˆ€ s, subst Οƒ s = subst Ο„ s" }, { "name": "substDropAll", "content": "theorem substDropAll a b : b = subst (a +: var) (rename succ b)" } ]
import Β«srcΒ».level open Nat variable [lc : LevelClass] @[simp] def cons {A : Type} (x : A) (ΞΎ : Nat β†’ A) : Nat β†’ A | 0 => x | n + 1 => ΞΎ n infixr:50 "+:" => cons inductive Term : Type where | var : Nat β†’ Term | 𝒰 : Term β†’ Term | pi : Term β†’ Term β†’ Term | abs : Term β†’ Term β†’ Term | app : Term β†’ Term β†’ Term | mty : Term | exf : Term β†’ Term β†’ Term | lvl : Term β†’ Term | lof : lc.L β†’ Term open Term @[simp] def lift (ΞΎ : Nat β†’ Nat) : Nat β†’ Nat := zero +: (succ ∘ ΞΎ) @[simp] def rename (ΞΎ : Nat β†’ Nat) : Term β†’ Term | var s => var (ΞΎ s) | 𝒰 a => 𝒰 (rename ΞΎ a) | pi a b => pi (rename ΞΎ a) (rename (lift ΞΎ) b) | abs a b => abs (rename ΞΎ a) (rename (lift ΞΎ) b) | app b a => app (rename ΞΎ b) (rename ΞΎ a) | mty => mty | exf a b => exf (rename ΞΎ a) (rename ΞΎ b) | lvl a => lvl (rename ΞΎ a) | lof k => lof k @[simp] def up (Οƒ : Nat β†’ Term) : Nat β†’ Term := var 0 +: (rename succ ∘ Οƒ) prefix:95 "⇑" => up @[simp] def subst (Οƒ : Nat β†’ Term) : Term β†’ Term | var s => Οƒ s | 𝒰 a => 𝒰 (subst Οƒ a) | pi a b => pi (subst Οƒ a) (subst (⇑ Οƒ) b) | abs a b => abs (subst Οƒ a) (subst (⇑ Οƒ) b) | app b a => app (subst Οƒ b) (subst Οƒ a) | mty => mty | exf a b => exf (subst Οƒ a) (subst Οƒ b) | lvl a => lvl (subst Οƒ a) | lof k => lof k def substId : βˆ€ s, subst var s = s := substId' var (by admit /- proof elided -/ ) def substRename ΞΎ Οƒ : βˆ€ s, subst Οƒ (rename ΞΎ s) = subst (Οƒ ∘ ΞΎ) s := substRename' _ _ (Οƒ ∘ ΞΎ) (by admit /- proof elided -/ ) def substComp Οƒ Ο„ : βˆ€ s, (subst Οƒ ∘ subst Ο„) s = subst (subst Οƒ ∘ Ο„) s := substComp' _ _ (subst Οƒ ∘ Ο„) (by admit /- proof elided -/ )
theorem substUnion Οƒ a s : subst (a +: Οƒ) s = subst (a +: var) (subst (⇑ Οƒ) s) :=
:= by calc subst (a +: Οƒ) s = subst (subst (a +: var) ∘ (var 0 +: (rename succ ∘ Οƒ))) s := by apply substExt; intro n; cases n <;> simp; rw [← substDropAll] _ = subst (a +: var) (subst (⇑ Οƒ) s) := by rw [← substComp]; rfl
4
16
false
Type systems
441
substDist
theorem substDist Οƒ a s : subst (subst Οƒ a +: var) (subst (⇑ Οƒ) s) = subst Οƒ (subst (a +: var) s)
TTBFL
src/syntactics.lean
[ "import Β«srcΒ».level" ]
[ { "name": "Nat", "module": "Init.Prelude" }, { "name": "Nat.succ", "module": "Init.Prelude" }, { "name": "Nat.zero", "module": "Init.Prelude" } ]
[ { "name": "LevelClass", "content": "class LevelClass where\n L : Type\n lc : LevelClasses L" } ]
[ { "name": "...", "module": "" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "cons", "content": "@[simp]\ndef cons {A : Type} (x : A) (ΞΎ : Nat β†’ A) : Nat β†’ A\n | 0 => x\n | n + 1 => ΞΎ n" }, { "name": "Term", "content": "inductive Term : Type where\n | var : Nat β†’ Term\n | 𝒰 : Term β†’ Term\n | pi : Term β†’ Term β†’ Term\n | abs : Term β†’ Term β†’ Term\n | app : Term β†’ Term β†’ Term\n | mty : Term\n | exf : Term β†’ Term β†’ Term\n | lvl : Term β†’ Term\n | lof : lc.L β†’ Term" }, { "name": "lift", "content": "@[simp]\ndef lift (ΞΎ : Nat β†’ Nat) : Nat β†’ Nat :=\n zero +: (succ ∘ ΞΎ)" }, { "name": "rename", "content": "@[simp]\ndef rename (ΞΎ : Nat β†’ Nat) : Term β†’ Term\n | var s => var (ΞΎ s)\n | 𝒰 a => 𝒰 (rename ΞΎ a)\n | pi a b => pi (rename ΞΎ a) (rename (lift ΞΎ) b)\n | abs a b => abs (rename ΞΎ a) (rename (lift ΞΎ) b)\n | app b a => app (rename ΞΎ b) (rename ΞΎ a)\n | mty => mty\n | exf a b => exf (rename ΞΎ a) (rename ΞΎ b)\n | lvl a => lvl (rename ΞΎ a)\n | lof k => lof k" }, { "name": "up", "content": "@[simp]\ndef up (Οƒ : Nat β†’ Term) : Nat β†’ Term :=\n var 0 +: (rename succ ∘ Οƒ)" }, { "name": "subst", "content": "@[simp]\ndef subst (Οƒ : Nat β†’ Term) : Term β†’ Term\n | var s => Οƒ s\n | 𝒰 a => 𝒰 (subst Οƒ a)\n | pi a b => pi (subst Οƒ a) (subst (⇑ Οƒ) b)\n | abs a b => abs (subst Οƒ a) (subst (⇑ Οƒ) b)\n | app b a => app (subst Οƒ b) (subst Οƒ a)\n | mty => mty\n | exf a b => exf (subst Οƒ a) (subst Οƒ b)\n | lvl a => lvl (subst Οƒ a)\n | lof k => lof k" }, { "name": "substId", "content": "def substId : βˆ€ s, subst var s = s :=\n substId' var (by admit /- proof elided -/\n )" }, { "name": "substRename", "content": "def substRename ΞΎ Οƒ : βˆ€ s, subst Οƒ (rename ΞΎ s) = subst (Οƒ ∘ ΞΎ) s :=\n substRename' _ _ (Οƒ ∘ ΞΎ) (by admit /- proof elided -/\n )" }, { "name": "substComp", "content": "def substComp Οƒ Ο„ : βˆ€ s, (subst Οƒ ∘ subst Ο„) s = subst (subst Οƒ ∘ Ο„) s :=\n substComp' _ _ (subst Οƒ ∘ Ο„) (by admit /- proof elided -/\n )" } ]
[ { "name": "upExt", "content": "theorem upExt Οƒ Ο„ (h : βˆ€ x, Οƒ x = Ο„ x) : βˆ€ x, (⇑ Οƒ) x = (⇑ Ο„) x" }, { "name": "substExt", "content": "theorem substExt Οƒ Ο„ (h : βˆ€ x, Οƒ x = Ο„ x) : βˆ€ s, subst Οƒ s = subst Ο„ s" }, { "name": "substDropAll", "content": "theorem substDropAll a b : b = subst (a +: var) (rename succ b)" }, { "name": "substUnion", "content": "theorem substUnion Οƒ a s : subst (a +: Οƒ) s = subst (a +: var) (subst (⇑ Οƒ) s)" } ]
import Β«srcΒ».level open Nat variable [lc : LevelClass] @[simp] def cons {A : Type} (x : A) (ΞΎ : Nat β†’ A) : Nat β†’ A | 0 => x | n + 1 => ΞΎ n infixr:50 "+:" => cons inductive Term : Type where | var : Nat β†’ Term | 𝒰 : Term β†’ Term | pi : Term β†’ Term β†’ Term | abs : Term β†’ Term β†’ Term | app : Term β†’ Term β†’ Term | mty : Term | exf : Term β†’ Term β†’ Term | lvl : Term β†’ Term | lof : lc.L β†’ Term open Term @[simp] def lift (ΞΎ : Nat β†’ Nat) : Nat β†’ Nat := zero +: (succ ∘ ΞΎ) @[simp] def rename (ΞΎ : Nat β†’ Nat) : Term β†’ Term | var s => var (ΞΎ s) | 𝒰 a => 𝒰 (rename ΞΎ a) | pi a b => pi (rename ΞΎ a) (rename (lift ΞΎ) b) | abs a b => abs (rename ΞΎ a) (rename (lift ΞΎ) b) | app b a => app (rename ΞΎ b) (rename ΞΎ a) | mty => mty | exf a b => exf (rename ΞΎ a) (rename ΞΎ b) | lvl a => lvl (rename ΞΎ a) | lof k => lof k @[simp] def up (Οƒ : Nat β†’ Term) : Nat β†’ Term := var 0 +: (rename succ ∘ Οƒ) prefix:95 "⇑" => up @[simp] def subst (Οƒ : Nat β†’ Term) : Term β†’ Term | var s => Οƒ s | 𝒰 a => 𝒰 (subst Οƒ a) | pi a b => pi (subst Οƒ a) (subst (⇑ Οƒ) b) | abs a b => abs (subst Οƒ a) (subst (⇑ Οƒ) b) | app b a => app (subst Οƒ b) (subst Οƒ a) | mty => mty | exf a b => exf (subst Οƒ a) (subst Οƒ b) | lvl a => lvl (subst Οƒ a) | lof k => lof k def substId : βˆ€ s, subst var s = s := substId' var (by admit /- proof elided -/ ) def substRename ΞΎ Οƒ : βˆ€ s, subst Οƒ (rename ΞΎ s) = subst (Οƒ ∘ ΞΎ) s := substRename' _ _ (Οƒ ∘ ΞΎ) (by admit /- proof elided -/ ) def substComp Οƒ Ο„ : βˆ€ s, (subst Οƒ ∘ subst Ο„) s = subst (subst Οƒ ∘ Ο„) s := substComp' _ _ (subst Οƒ ∘ Ο„) (by admit /- proof elided -/ )
theorem substDist Οƒ a s : subst (subst Οƒ a +: var) (subst (⇑ Οƒ) s) = subst Οƒ (subst (a +: var) s) :=
:= by calc subst (subst Οƒ a +: var) (subst (⇑ Οƒ) s) = subst (subst Οƒ a +: Οƒ) s := by rw [← substUnion] _ = subst (subst Οƒ ∘ (a +: var)) s := by apply substExt; intro n; cases n <;> rfl _ = (subst Οƒ ∘ subst (a +: var)) s := by rw [← substComp]
4
17
false
Type systems
442
wtfLofInv
theorem wtfLofInv {Ξ“ j 𝒰'} (h : Ξ“ ⊒ lof j ∢ 𝒰') : βˆƒ k, lvl k β‰ˆ 𝒰'
TTBFL
src/typing.lean
[ "import src.reduction", "import Β«srcΒ».reduction" ]
[ { "name": "DecidableEq", "module": "Init.Prelude" }, { "name": "Lean.ToExpr", "module": "Lean.ToExpr" }, { "name": "List", "module": "Init.Prelude" }, { "name": "Repr", "module": "Init.Data.Repr" }, { "name": "Nat.sub", "module": "Init.Prelude" }, { "name": "Inhabited", "module": "Init.Prelude" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "String", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "Nat.succ", "module": "Init.Prelude" }, { "name": "Nat.zero", "module": "Init.Prelude" } ]
[ { "name": "notation:40 Ξ”:41 \"⊒\" ΞΎ:41 \"∢\" Ξ“:41 => wRename ΞΎ Ξ“ Ξ”", "content": "notation:40 Ξ”:41 \"⊒\" ΞΎ:41 \"∢\" Ξ“:41 => wRename ΞΎ Ξ“ Ξ”" }, { "name": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“", "content": "notation:40 \"⊒\" Ξ“:40 => Wf Ξ“" }, { "name": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A", "content": "notation:40 Ξ“:41 \"⊒\" a:41 \"∢\" A:41 => Wt Ξ“ a A" }, { "name": "notation:40 Ξ”:41 \"⊒\" Οƒ:41 \"∢\" Ξ“:41 => wSubst Οƒ Ξ“ Ξ”", "content": "notation:40 Ξ”:41 \"⊒\" Οƒ:41 \"∢\" Ξ“:41 => wSubst Οƒ Ξ“ Ξ”" }, { "name": "Ctxt", "content": "inductive Ctxt : Type where\n | nil : Ctxt\n | cons : Ctxt β†’ Term β†’ Ctxt" }, { "name": "Term", "content": "inductive Term : Type where\n | var : Nat β†’ Term\n | 𝒰 : Term β†’ Term\n | pi : Term β†’ Term β†’ Term\n | abs : Term β†’ Term β†’ Term\n | app : Term β†’ Term β†’ Term\n | mty : Term\n | exf : Term β†’ Term β†’ Term\n | lvl : Term β†’ Term\n | lof : lc.L β†’ Term" }, { "name": "Par", "content": "inductive Par : Term β†’ Term β†’ Prop where\n | Ξ² {b b' a a' c} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app (abs c b) a β‡’ subst (a' +: var) b'\n | var s : var s β‡’ var s\n | 𝒰 {a a'} :\n a β‡’ a' β†’\n \n 𝒰 a β‡’ 𝒰 a'\n | pi {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n pi a b β‡’ pi a' b'\n | abs {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n abs a b β‡’ abs a' b'\n | app {b b' a a'} :\n b β‡’ b' β†’\n a β‡’ a' β†’\n \n app b a β‡’ app b' a'\n | mty : mty β‡’ mty\n | exf {a a' b b'} :\n a β‡’ a' β†’\n b β‡’ b' β†’\n \n exf a b β‡’ exf a' b'\n | lvl {a a'} :\n a β‡’ a' β†’\n \n lvl a β‡’ lvl a'\n | lof k : lof k β‡’ lof k" }, { "name": "Conv", "content": "def Conv (a : Term) (b : Term) : Prop := βˆƒ c, a ⇒⋆ c ∧ b ⇒⋆ c" }, { "name": "Pars", "content": "inductive Pars : Term β†’ Term β†’ Prop where\n | refl a : a ⇒⋆ a\n | trans {a b c} : a β‡’ b β†’ b ⇒⋆ c β†’ a ⇒⋆ c" }, { "name": "subst", "content": "@[simp]\ndef subst (Οƒ : Nat β†’ Term) : Term β†’ Term\n | var s => Οƒ s\n | 𝒰 a => 𝒰 (subst Οƒ a)\n | pi a b => pi (subst Οƒ a) (subst (⇑ Οƒ) b)\n | abs a b => abs (subst Οƒ a) (subst (⇑ Οƒ) b)\n | app b a => app (subst Οƒ b) (subst Οƒ a)\n | mty => mty\n | exf a b => exf (subst Οƒ a) (subst Οƒ b)\n | lvl a => lvl (subst Οƒ a)\n | lof k => lof k" }, { "name": "taka", "content": "@[simp]\ndef taka : Term β†’ Term\n | 𝒰 a => 𝒰 (taka a)\n | pi a b => pi (taka a) (taka b)\n | abs a b => abs (taka a) (taka b)\n | app b a => match b with\n | abs _ b => subst (taka a +: var) (taka b)\n | b => app (taka b) (taka a)\n | exf a b => exf (taka a) (taka b)\n | lvl a => lvl (taka a)\n | t => t" }, { "name": "up", "content": "@[simp]\ndef up (Οƒ : Nat β†’ Term) : Nat β†’ Term :=\n var 0 +: (rename succ ∘ Οƒ)" }, { "name": "rename", "content": "@[simp]\ndef rename (ΞΎ : Nat β†’ Nat) : Term β†’ Term\n | var s => var (ΞΎ s)\n | 𝒰 a => 𝒰 (rename ΞΎ a)\n | pi a b => pi (rename ΞΎ a) (rename (lift ΞΎ) b)\n | abs a b => abs (rename ΞΎ a) (rename (lift ΞΎ) b)\n | app b a => app (rename ΞΎ b) (rename ΞΎ a)\n | mty => mty\n | exf a b => exf (rename ΞΎ a) (rename ΞΎ b)\n | lvl a => lvl (rename ΞΎ a)\n | lof k => lof k" }, { "name": "lift", "content": "@[simp]\ndef lift (ΞΎ : Nat β†’ Nat) : Nat β†’ Nat :=\n zero +: (succ ∘ ΞΎ)" }, { "name": "cons", "content": "@[simp]\ndef cons {A : Type} (x : A) (ΞΎ : Nat β†’ A) : Nat β†’ A\n | 0 => x\n | n + 1 => ΞΎ n" }, { "name": "infix:40 \"β‡’\" => Par", "content": "infix:40 \"β‡’\" => Par" }, { "name": "infix:40 \"⇒⋆\" => Pars", "content": "infix:40 \"⇒⋆\" => Pars" }, { "name": "infix:40 \"⇔\" => Conv", "content": "infix:40 \"⇔\" => Conv" }, { "name": "infixr:50 \"+:\" => cons", "content": "infixr:50 \"+:\" => cons" }, { "name": "prefix:95 \"⇑\" => up", "content": "prefix:95 \"⇑\" => up" }, { "name": "notation:50 \"⬝\" => Ctxt.nil", "content": "notation:50 \"⬝\" => Ctxt.nil" }, { "name": "infixl:50 \"∷\" => Ctxt.cons", "content": "infixl:50 \"∷\" => Ctxt.cons" } ]
[ { "name": "refl", "module": "Mathlib.Order.Defs.Unbundled" }, { "name": "trans", "module": "Mathlib.Order.Defs.Unbundled" } ]
[ { "name": "conv𝒰", "content": "theorem conv𝒰 {a a'} : a ⇔ a' β†’ 𝒰 a ⇔ 𝒰 a'" }, { "name": "pars𝒰", "content": "theorem pars𝒰 {a a'} (r : a ⇒⋆ a') : 𝒰 a ⇒⋆ 𝒰 a'" }, { "name": "convAbs", "content": "theorem convAbs {a a' b b'} : a ⇔ a' β†’ b ⇔ b' β†’ abs a b ⇔ abs a' b'" }, { "name": "parsAbs", "content": "theorem parsAbs {a a' b b'} (ra : a ⇒⋆ a') (rb : b ⇒⋆ b') : abs a b ⇒⋆ abs a' b'" }, { "name": "parRefl", "content": "theorem parRefl a : a β‡’ a" }, { "name": "convPi", "content": "theorem convPi {a a' b b'} : a ⇔ a' β†’ b ⇔ b' β†’ pi a b ⇔ pi a' b'" }, { "name": "parsPi", "content": "theorem parsPi {a a' b b'} (ra : a ⇒⋆ a') (rb : b ⇒⋆ b') : pi a b ⇒⋆ pi a' b'" }, { "name": "convApp", "content": "theorem convApp {b b' a a'} : b ⇔ b' β†’ a ⇔ a' β†’ app b a ⇔ app b' a'" }, { "name": "parsApp", "content": "theorem parsApp {a a' b b'} (rb : b ⇒⋆ b') (ra : a ⇒⋆ a') : app b a ⇒⋆ app b' a'" }, { "name": "convSym", "content": "theorem convSym {a b} : a ⇔ b β†’ b ⇔ a" }, { "name": "convTrans", "content": "theorem convTrans {a b c} : a ⇔ b β†’ b ⇔ c β†’ a ⇔ c" }, { "name": "confluence", "content": "theorem confluence {a b c} (r₁ : a ⇒⋆ b) (rβ‚‚ : a ⇒⋆ c) : βˆƒ d, b ⇒⋆ d ∧ c ⇒⋆ d" }, { "name": "diacon", "content": "theorem diacon {a b c} (r₁ : a ⇒⋆ b) (rβ‚‚ : a β‡’ c) : βˆƒ d, b ⇒⋆ d ∧ c ⇒⋆ d" }, { "name": "diamond", "content": "theorem diamond {a b c} (r₁ : a β‡’ b) (rβ‚‚ : a β‡’ c) : βˆƒ d, b β‡’ d ∧ c β‡’ d" }, { "name": "parTaka", "content": "theorem parTaka {a b} (r : a β‡’ b) : b β‡’ taka a" }, { "name": "parCong", "content": "theorem parCong {a a' b b'} (ra : a β‡’ a') (rb : b β‡’ b') : subst (a +: var) b β‡’ subst (a' +: var) b'" }, { "name": "parMorphing", "content": "theorem parMorphing {a b} Οƒ Ο„ (h : βˆ€ x, Οƒ x β‡’ Ο„ x) (r : a β‡’ b) : subst Οƒ a β‡’ subst Ο„ b" }, { "name": "parLift", "content": "theorem parLift Οƒ Ο„ (h : βˆ€ x, Οƒ x β‡’ Ο„ x) : βˆ€ x, (⇑ Οƒ) x β‡’ (⇑ Ο„) x" }, { "name": "parRename", "content": "theorem parRename {a b} ΞΎ (r : a β‡’ b) : rename ΞΎ a β‡’ rename ΞΎ b" }, { "name": "parPars", "content": "theorem parPars {a b} (r : a β‡’ b) : a ⇒⋆ b" }, { "name": "parsTrans", "content": "theorem parsTrans {a b c} (r₁ : a ⇒⋆ b) (rβ‚‚ : b ⇒⋆ c) : a ⇒⋆ c" }, { "name": "convExf", "content": "theorem convExf {a a' b b'} : a ⇔ a' β†’ b ⇔ b' β†’ exf a b ⇔ exf a' b'" }, { "name": "parsExf", "content": "theorem parsExf {a a' b b'} (ra : a ⇒⋆ a') (rb : b ⇒⋆ b') : exf a b ⇒⋆ exf a' b'" }, { "name": "convRefl", "content": "theorem convRefl {a} : a ⇔ a" }, { "name": "parConv", "content": "theorem parConv {a b} (r : a β‡’ b) : a ⇔ b" }, { "name": "parsConv", "content": "theorem parsConv {a b} (r : a ⇒⋆ b) : a ⇔ b" }, { "name": "convLvl", "content": "theorem convLvl {a a'} : a ⇔ a' β†’ lvl a ⇔ lvl a'" }, { "name": "parsLvl", "content": "theorem parsLvl {a a'} (r : a ⇒⋆ a') : lvl a ⇒⋆ lvl a'" }, { "name": "convLvl𝒰", "content": "theorem convLvl𝒰 {j k} : Β¬ lvl j ⇔ 𝒰 k" }, { "name": "parsLvlInv", "content": "theorem parsLvlInv {i b} (r : lvl i ⇒⋆ b) : βˆƒ j, b = lvl j ∧ i ⇒⋆ j" }, { "name": "pars𝒰Inv", "content": "theorem pars𝒰Inv {a b} (r : 𝒰 a ⇒⋆ b) : βˆƒ a', b = 𝒰 a' ∧ a ⇒⋆ a'" } ]
[ { "name": "Eqv", "content": "inductive Eqv : Term β†’ Term β†’ Prop where\n | Ξ² {b a c} : app (abs c b) a β‰ˆ subst (a +: var) b\n | 𝒰 {a a'} :\n a β‰ˆ a' β†’\n \n 𝒰 a β‰ˆ 𝒰 a'\n | pi {a a' b b'} :\n a β‰ˆ a' β†’\n b β‰ˆ b' β†’\n \n pi a b β‰ˆ pi a' b'\n | abs {a a' b b'} :\n a β‰ˆ a' β†’\n b β‰ˆ b' β†’\n \n abs a b β‰ˆ abs a' b'\n | app {b b' a a'} :\n b β‰ˆ b' β†’\n a β‰ˆ a' β†’\n \n app b a β‰ˆ app b' a'\n | exf {a a' b b'} :\n a β‰ˆ a' β†’\n b β‰ˆ b' β†’\n \n exf a b β‰ˆ exf a' b'\n | lvl {a a'} :\n a β‰ˆ a' β†’\n \n lvl a β‰ˆ lvl a'\n | refl {a} : a β‰ˆ a\n | sym {a b} :\n a β‰ˆ b β†’\n \n b β‰ˆ a\n | trans {a b c} :\n a β‰ˆ b β†’\n b β‰ˆ c β†’\n \n a β‰ˆ c" }, { "name": "Wf", "content": "inductive Wf : Ctxt β†’ Prop where\n | nil : ⊒ ⬝\n | cons {Ξ“ A k} :\n ⊒ Ξ“ β†’\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n \n ⊒ Ξ“ ∷ A" }, { "name": "Wt", "content": "inductive Wt : Ctxt β†’ Term β†’ Term β†’ Prop where\n | var {Ξ“ x A} :\n ⊒ Ξ“ β†’\n Ξ“ βˆ‹ x ∢ A β†’\n \n Ξ“ ⊒ var x ∢ A\n | 𝒰 {Ξ“ j k} :\n Ξ“ ⊒ j ∢ lvl k β†’\n \n Ξ“ ⊒ 𝒰 j ∢ 𝒰 k\n | pi {Ξ“ A B k} :\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n Ξ“ ∷ A ⊒ B ∢ 𝒰 (rename succ k) β†’\n \n Ξ“ ⊒ pi A B ∢ 𝒰 k\n | abs {Ξ“ A B b k} :\n Ξ“ ⊒ pi A B ∢ 𝒰 k β†’\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n Ξ“ ∷ A ⊒ b ∢ B β†’\n \n Ξ“ ⊒ abs A b ∢ pi A B\n | app {Ξ“ A B b a} :\n Ξ“ ⊒ b ∢ pi A B β†’\n Ξ“ ⊒ a ∢ A β†’\n \n Ξ“ ⊒ app b a ∢ subst (a +: var) B\n | mty {Ξ“ j k} :\n Ξ“ ⊒ 𝒰 j ∢ 𝒰 k β†’\n \n Ξ“ ⊒ mty ∢ 𝒰 j\n | exf {Ξ“ A b k} :\n Ξ“ ⊒ A ∢ 𝒰 k β†’\n Ξ“ ⊒ b ∢ mty β†’\n \n Ξ“ ⊒ exf A b ∢ A\n | lvl {Ξ“ a b j k} :\n Ξ“ ⊒ a ∢ lvl b β†’\n Ξ“ ⊒ 𝒰 j ∢ 𝒰 k β†’\n \n Ξ“ ⊒ lvl a ∢ 𝒰 j\n | lof {Ξ“ j k} :\n ⊒ Ξ“ β†’\n j < k β†’\n \n Ξ“ ⊒ lof j ∢ lvl (lof k)\n | trans {Ξ“ i j k} :\n Ξ“ ⊒ i ∢ lvl j β†’\n Ξ“ ⊒ j ∢ lvl k β†’\n \n Ξ“ ⊒ i ∢ lvl k\n | conv {Ξ“ A B a k} :\n A β‰ˆ B β†’\n Ξ“ ⊒ a ∢ A β†’\n Ξ“ ⊒ B ∢ 𝒰 k β†’\n \n Ξ“ ⊒ a ∢ B\n | sub {Ξ“ j k A} :\n Ξ“ ⊒ j ∢ lvl k β†’\n Ξ“ ⊒ A ∢ 𝒰 j β†’\n \n Ξ“ ⊒ A ∢ 𝒰 k" } ]
[ { "name": "eqvConv", "content": "theorem eqvConv {a b} (r : a β‰ˆ b) : a ⇔ b" } ]
import Β«srcΒ».reduction open Nat open Term variable [LevelClass] section inductive Eqv : Term β†’ Term β†’ Prop where | Ξ² {b a c} : app (abs c b) a β‰ˆ subst (a +: var) b | 𝒰 {a a'} : a β‰ˆ a' β†’ 𝒰 a β‰ˆ 𝒰 a' | pi {a a' b b'} : a β‰ˆ a' β†’ b β‰ˆ b' β†’ pi a b β‰ˆ pi a' b' | abs {a a' b b'} : a β‰ˆ a' β†’ b β‰ˆ b' β†’ abs a b β‰ˆ abs a' b' | app {b b' a a'} : b β‰ˆ b' β†’ a β‰ˆ a' β†’ app b a β‰ˆ app b' a' | exf {a a' b b'} : a β‰ˆ a' β†’ b β‰ˆ b' β†’ exf a b β‰ˆ exf a' b' | lvl {a a'} : a β‰ˆ a' β†’ lvl a β‰ˆ lvl a' | refl {a} : a β‰ˆ a | sym {a b} : a β‰ˆ b β†’ b β‰ˆ a | trans {a b c} : a β‰ˆ b β†’ b β‰ˆ c β†’ a β‰ˆ c end infix:40 (priority := 1001) "β‰ˆ" => Eqv section inductive Wf : Ctxt β†’ Prop where | nil : ⊒ ⬝ | cons {Ξ“ A k} : ⊒ Ξ“ β†’ Ξ“ ⊒ A ∢ 𝒰 k β†’ ⊒ Ξ“ ∷ A inductive Wt : Ctxt β†’ Term β†’ Term β†’ Prop where | var {Ξ“ x A} : ⊒ Ξ“ β†’ Ξ“ βˆ‹ x ∢ A β†’ Ξ“ ⊒ var x ∢ A | 𝒰 {Ξ“ j k} : Ξ“ ⊒ j ∢ lvl k β†’ Ξ“ ⊒ 𝒰 j ∢ 𝒰 k | pi {Ξ“ A B k} : Ξ“ ⊒ A ∢ 𝒰 k β†’ Ξ“ ∷ A ⊒ B ∢ 𝒰 (rename succ k) β†’ Ξ“ ⊒ pi A B ∢ 𝒰 k | abs {Ξ“ A B b k} : Ξ“ ⊒ pi A B ∢ 𝒰 k β†’ Ξ“ ⊒ A ∢ 𝒰 k β†’ Ξ“ ∷ A ⊒ b ∢ B β†’ Ξ“ ⊒ abs A b ∢ pi A B | app {Ξ“ A B b a} : Ξ“ ⊒ b ∢ pi A B β†’ Ξ“ ⊒ a ∢ A β†’ Ξ“ ⊒ app b a ∢ subst (a +: var) B | mty {Ξ“ j k} : Ξ“ ⊒ 𝒰 j ∢ 𝒰 k β†’ Ξ“ ⊒ mty ∢ 𝒰 j | exf {Ξ“ A b k} : Ξ“ ⊒ A ∢ 𝒰 k β†’ Ξ“ ⊒ b ∢ mty β†’ Ξ“ ⊒ exf A b ∢ A | lvl {Ξ“ a b j k} : Ξ“ ⊒ a ∢ lvl b β†’ Ξ“ ⊒ 𝒰 j ∢ 𝒰 k β†’ Ξ“ ⊒ lvl a ∢ 𝒰 j | lof {Ξ“ j k} : ⊒ Ξ“ β†’ j < k β†’ Ξ“ ⊒ lof j ∢ lvl (lof k) | trans {Ξ“ i j k} : Ξ“ ⊒ i ∢ lvl j β†’ Ξ“ ⊒ j ∢ lvl k β†’ Ξ“ ⊒ i ∢ lvl k | conv {Ξ“ A B a k} : A β‰ˆ B β†’ Ξ“ ⊒ a ∢ A β†’ Ξ“ ⊒ B ∢ 𝒰 k β†’ Ξ“ ⊒ a ∢ B | sub {Ξ“ j k A} : Ξ“ ⊒ j ∢ lvl k β†’ Ξ“ ⊒ A ∢ 𝒰 j β†’ Ξ“ ⊒ A ∢ 𝒰 k end end notation:40 "⊒" Ξ“:40 => Wf Ξ“ notation:40 Ξ“:41 "⊒" a:41 "∢" A:41 => Wt Ξ“ a A
theorem wtfLofInv {Ξ“ j 𝒰'} (h : Ξ“ ⊒ lof j ∢ 𝒰') : βˆƒ k, lvl k β‰ˆ 𝒰' :=
:= by generalize e : lof j = t at h induction h all_goals injections <;> subst_eqs <;> specialize_rfls case lof | trans => exact ⟨_, Eqv.refl⟩ case conv e₁ _ _ _ ih => let ⟨_, eβ‚‚βŸ© := ih exact ⟨_, Eqv.trans eβ‚‚ eβ‚βŸ© case sub ih => let ⟨_, e⟩ := ih cases convLvl𝒰 (eqvConv e)
13
60
false
Type systems
443
StateT.set_get
theorem set_get : (do let s ← @StateT.get Οƒ m _; StateT.set s) = pure ⟨⟩
VCV-io
ToMathlib/Control/Lawful/MonadState.lean
[]
[ { "name": "StateT", "module": "Init.Control.State" }, { "name": "StateT.get", "module": "Init.Control.State" }, { "name": "StateT.bind", "module": "Init.Control.State" }, { "name": "StateT.instMonad", "module": "Init.Control.State" } ]
[ { "name": "...", "content": "..." } ]
[ { "name": "...", "module": "" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[]
[]
namespace LawfulMonadStateOf variable {Οƒ : Type u} {m : Type u β†’ Type v} variable [Monad m] [LawfulMonad m] [MonadStateOf Οƒ m] [LawfulMonadStateOf Οƒ m] end LawfulMonadStateOf namespace LawfulMonadState variable {Οƒ : Type u} {m : Type u β†’ Type v} [Monad m] [LawfulMonad m] [LawfulMonadState Οƒ m] end LawfulMonadState namespace StateT variable {Οƒ : Type u} {m : Type u β†’ Type v} [Monad m] [LawfulMonad m]
theorem set_get : (do let s ← @StateT.get Οƒ m _; StateT.set s) = pure ⟨⟩ :=
:= by unfold StateT.get StateT.instMonad StateT.bind StateT.set StateT.pure simp only [bind_pure_comp, map_pure]
1
4
false
Applied verif.
444
triple_forIn_deacreasing
theorem triple_forIn_deacreasing {Ξ²} {measure : Ξ² -> β„•} {init : Ξ²} {f : Ξ² β†’ m (ForInStep Ξ²)} (inv : Ξ² β†’ l) (hstep : βˆ€ b, measure b <= measure init -> triple (inv b) (f b) (fun | .yield b' => inv b' βŠ“ ⌜measure b' < measure b⌝ | .done b' => ⌜ measure b' = 0 ⌝ βŠ“ inv b')) : triple (inv init) (forIn [0:measure init] init (fun _ => f)) (fun b => inv b βŠ“ ⌜measure b = 0⌝)
loom
Loom/MonadAlgebras/WP/Gen.lean
[ "import Loom.MonadAlgebras.WP.Liberal", "import Mathlib.Order.Lattice", "import Mathlib.Order.Basic", "import Loom.MonadAlgebras.WP.DoNames'", "import Mathlib.Order.CompleteBooleanAlgebra", "import Mathlib.Logic.Function.Basic", "import Loom.MonadAlgebras.WP.Basic" ]
[ { "name": "Cont", "module": "Mathlib.Control.Monad.Cont" }, { "name": "liftM", "module": "Init.Prelude" }, { "name": "ForInStep", "module": "Init.Core" }, { "name": "Std.Range", "module": "Init.Data.Range.Basic" }, { "name": "List", "module": "Init.Prelude" }, { "name": "List.range'", "module": "Init.Data.List.Basic" } ]
[ { "name": "macro \"⌜\" p:term \"⌝\" : term => `(LE.pure $p)", "content": "macro \"⌜\" p:term \"⌝\" : term => `(LE.pure $p)" }, { "name": "Kind", "content": "inductive Kind where\n | regular\n | forIn\n | forInWithReturn\n | nestedBC\n | nestedPR\n | nestedSBC\n | nestedPRBC" }, { "name": "triple", "content": "def triple (pre : l) (c : m Ξ±) (post : Ξ± -> l) : Prop :=\n pre ≀ wp c post" }, { "name": "wp", "content": "def wp (c : m Ξ±) (post : Ξ± -> l) : l := liftM (n := Cont l) c post" }, { "name": "LogicLift", "content": "class LogicLift (l : outParam (Type u)) ( k : Type u) [CompleteLattice l] [CompleteLattice k] where\n [lift : MonadLift (Cont l) (Cont k)]\n lift_top {Ξ± : Type u} :\n monadLift (m := Cont l) (n := Cont k) (fun (_ : Ξ± -> l) => ⊀) = ⊀\n lift_bot {Ξ± : Type u} :\n monadLift (m := Cont l) (n := Cont k) (fun (_ : Ξ± -> l) => βŠ₯) = βŠ₯" }, { "name": "triple", "content": "notation \"{\" P \"}\" c \"{\" v \",\" Q \"}\" => triple P c (fun v => Q)" } ]
[ { "name": "le_trans", "module": "Mathlib.Order.Defs.PartialOrder" }, { "name": "le_trans'", "module": "Mathlib.Order.Basic" } ]
[ { "name": "wp_cons", "content": "lemma wp_cons (x : m Ξ±) (post post' : Ξ± -> l) :\n (βˆ€ y, post y ≀ post' y) ->\n wp x post ≀ wp x post'" }, { "name": "triple_forIn_range_step1", "content": "theorem triple_forIn_range_step1 {Ξ²}\n {xs : Std.Range} {init : Ξ²} {f : β„• β†’ Ξ² β†’ m (ForInStep Ξ²)}\n (inv : β„• β†’ Ξ² β†’ l)\n (hstep : βˆ€ i b,\n triple\n (inv i b)\n (f i b)\n (fun | .yield b' => inv (i + xs.step) b' | .done b' => inv xs.stop b')) :\n xs.step = 1 ->\n xs.start <= xs.stop ->\n triple (inv xs.start init) (forIn xs init f) (inv xs.stop)" }, { "name": "triple_forIn_range", "content": "theorem triple_forIn_range {Ξ²}\n (xs : Std.Range) (init : Ξ²) (f : β„• β†’ Ξ² β†’ m (ForInStep Ξ²))\n (inv : β„• β†’ Ξ² β†’ l)\n (hstep : βˆ€ i b,\n triple\n (inv i b)\n (f i b)\n (fun | .yield b' => inv (i + xs.step) b' | .done b' => inv (xs.start + ((xs.stop - xs.start + xs.step - 1) / xs.step) * xs.step) b')) :\n triple (inv xs.start init) (forIn xs init f) (inv (xs.start + ((xs.stop - xs.start + xs.step - 1) / xs.step) * xs.step))" }, { "name": "triple_forIn_range'", "content": "theorem triple_forIn_range' {Ξ²}\n {xstart : β„•} {step : β„•} (n : β„•) {init : Ξ²} {f : β„• β†’ Ξ² β†’ m (ForInStep Ξ²)}\n (inv : β„• β†’ Ξ² β†’ l)\n (hstep : βˆ€ i b,\n triple\n (inv i b)\n (f i b)\n (fun | .yield b' => inv (i + step) b' | .done b' => inv (xstart + n * step) b')) :\n triple (inv xstart init) (forIn (List.range' xstart n step) init f) (inv (xstart + n * step))" }, { "name": "triple_forIn_range'_aux", "content": "theorem triple_forIn_range'_aux {Ξ²}\n {xstart : β„•} {step : β„•} (n : β„•) (init : Ξ²) {f : β„• β†’ Ξ² β†’ m (ForInStep Ξ²)}\n (inv : β„• β†’ Ξ² β†’ l)\n (hstep : βˆ€ i b,\n triple\n (inv i b)\n (f i b)\n (fun | .yield b' => inv (i + step) b' | .done b' => inv (xstart + n * step) b')) :\n i <= n ->\n triple (inv (xstart + (n - i) * step) init) (forIn (List.range' (xstart + (n - i) * step) i step) init f) (inv (xstart + n * step))" }, { "name": "triple_bind", "content": "lemma triple_bind {Ξ²} (pre : l) (x : m Ξ±) (cut : Ξ± -> l)\n (f : Ξ± -> m Ξ²) (post : Ξ² -> l) :\n triple pre x cut ->\n (βˆ€ y, triple (cut y) (f y) post) ->\n triple pre (x >>= f) post" }, { "name": "wp_bind", "content": "lemma wp_bind {Ξ²} (x : m Ξ±) (f : Ξ± -> m Ξ²) (post : Ξ² -> l) :\n wp (x >>= f) post = wp x (fun x => wp (f x) post)" }, { "name": "triple_pure", "content": "lemma triple_pure (pre : l) (x : Ξ±) (post : Ξ± -> l) :\n triple pre (pure (f := m) x) post <-> pre ≀ (post x)" } ]
[]
[]
import Mathlib.Logic.Function.Basic import Mathlib.Order.CompleteBooleanAlgebra import Mathlib.Order.Lattice import Mathlib.Order.Basic import Loom.MonadAlgebras.WP.Basic import Loom.MonadAlgebras.WP.Liberal import Loom.MonadAlgebras.WP.DoNames' open Lean Meta Elab Command Term section variable {m : Type u -> Type v} [Monad m] [LawfulMonad m] {Ξ± : Type u} {l : Type u} [CompleteLattice l] variable [MAlgOrdered m l]
theorem triple_forIn_deacreasing {Ξ²} {measure : Ξ² -> β„•} {init : Ξ²} {f : Ξ² β†’ m (ForInStep Ξ²)} (inv : Ξ² β†’ l) (hstep : βˆ€ b, measure b <= measure init -> triple (inv b) (f b) (fun | .yield b' => inv b' βŠ“ ⌜measure b' < measure b⌝ | .done b' => ⌜ measure b' = 0 ⌝ βŠ“ inv b')) : triple (inv init) (forIn [0:measure init] init (fun _ => f)) (fun b => inv b βŠ“ ⌜measure b = 0⌝) :=
:= by apply le_trans'; apply wp_cons; rotate_left 2; apply le_trans; rotate_left 1 apply triple_forIn_range_step1 (inv := fun i b => ⌜ measure b + i <= measure init ⌝ βŠ“ inv b) <;> try solve | aesop { simp; intro i b by_cases h : measure b + i ≀ measure init <;> simp [h, triple] apply le_trans; apply hstep; omega apply wp_cons; rintro (b'|b') <;> simp by_cases h: measure b' = 0 <;> simp [h] by_cases h': measure b' < measure b <;> simp [h'] have : measure b' + (i + 1) ≀ measure init := by omega simp [this] } { simp; intro b by_cases h : measure b + measure init ≀ measure init <;> simp [h] by_cases h' : measure b = 0 <;> simp [h'] omega } simp
6
20
true
Framework
445
OracleComp.evalDist_liftComp
@[simp] lemma evalDist_liftComp [spec.FiniteRange] [superSpec.FiniteRange] (oa : OracleComp spec Ξ±) : evalDist (liftComp oa superSpec) = evalDist oa
VCV-io
VCVio/OracleComp/Coercions/SubSpec.lean
[ "import VCVio.OracleComp.Constructions.UniformSelect", "import VCVio.OracleComp.DistSemantics.EvalDist", "import VCVio.OracleComp.SimSemantics.SimulateQ" ]
[ { "name": "inline", "module": "Init.Core" }, { "name": "impl", "module": "Mathlib.Deprecated.MLList.BestFirst" }, { "name": "Bind", "module": "Init.Prelude" }, { "name": "Pure", "module": "Init.Prelude" }, { "name": "OptionT", "module": "Init.Control.Option" }, { "name": "AlternativeMonad", "module": "Batteries.Control.AlternativeMonad" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "Option.getM", "module": "Init.Data.Option.Basic" }, { "name": "MonadLift", "module": "Init.Prelude" }, { "name": "liftM", "module": "Init.Prelude" }, { "name": "Fintype", "module": "Mathlib.Data.Fintype.Defs" }, { "name": "Inhabited", "module": "Init.Prelude" }, { "name": "StateT", "module": "Init.Control.State" }, { "name": "StateT.run", "module": "Init.Control.State" }, { "name": "Vector", "module": "Init.Data.Vector.Basic" }, { "name": "Vector.insertIdx", "module": "Init.Data.Vector.Basic" }, { "name": "Nonempty", "module": "Init.Prelude" }, { "name": "OptionT.lift", "module": "Init.Control.Option" }, { "name": "PMF", "module": "Mathlib.Probability.ProbabilityMassFunction.Basic" }, { "name": "PMF.uniformOfFintype", "module": "Mathlib.Probability.Distributions.Uniform" } ]
[ { "name": "simulateQ", "content": "def simulateQ [AlternativeMonad m] (so : QueryImpl spec m) (oa : OracleComp spec Ξ±) : m Ξ± :=\n do Option.getM (← FreeMonad.mapM oa.run so.impl)" }, { "name": "QueryImpl.Inhabited", "content": "instance QueryImpl.Inhabited [βˆ€ i, Inhabited (spec.range i)] [Pure m] :\n Inhabited (QueryImpl spec m) := ⟨{impl q := pure q.defaultOutput}⟩" }, { "name": "OracleSpec", "content": "def OracleSpec (ΞΉ : Type u) : Type (max u (v + 1)) :=\n (i : ΞΉ) β†’ Type v Γ— Type v" }, { "name": "OracleQuery", "content": "inductive OracleQuery {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) : Type v β†’ Type (max u v)\n | query (i : ΞΉ) (t : spec.domain i) : OracleQuery spec (spec.range i)" }, { "name": "domain", "content": "@[inline, reducible]\nprotected def domain (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type v := (spec i).1" }, { "name": "range", "content": "@[inline, reducible]\nprotected def range (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type w := (spec i).2" }, { "name": "mapM", "content": "protected def mapM [Pure m] [Bind m] :\n (oa : FreeMonad f Ξ±) β†’ (s : {Ξ± : Type u} β†’ f Ξ± β†’ m Ξ±) β†’ m Ξ±\n | .pure x, _ => pure x\n | .roll x r, s => s x >>= Ξ» u ↦ (r u).mapM s" }, { "name": "FreeMonad", "content": "inductive FreeMonad (f : Type u β†’ Type v) (Ξ± : Type w) : Type (max (u + 1) v w)\n | protected pure (x : Ξ±) : FreeMonad f Ξ±\n | roll {Ξ² : Type u} (x : f Ξ²) (r : Ξ² β†’ FreeMonad f Ξ±) : FreeMonad f Ξ±" }, { "name": "OracleComp", "content": "def OracleComp {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) :\n Type w β†’ Type (max u (v + 1) w) :=\n OptionT (FreeMonad (OracleQuery.{u,v} spec))" }, { "name": "HasEvalDist", "content": "class HasEvalDist (m : Type u β†’ Type v) [Monad m] where\n evalDist {Ξ± : Type u} (mx : m Ξ±) : SPMF Ξ±\n evalDist_pure {Ξ± : Type u} (x : Ξ±) : evalDist (pure x : m Ξ±) = pure x\n evalDist_bind {Ξ± Ξ² : Type u} (mx : m Ξ±) (my : Ξ± β†’ m Ξ²) :\n evalDist (mx >>= my) = evalDist mx >>= fun x => evalDist (my x)" }, { "name": "inductionOn", "content": "@[elab_as_elim]\nprotected def inductionOn {C : OracleComp spec Ξ± β†’ Prop}\n (pure : (a : Ξ±) β†’ C (pure a))\n (query_bind : (i : ΞΉ) β†’ (t : spec.domain i) β†’\n (oa : spec.range i β†’ OracleComp spec Ξ±) β†’ (βˆ€ u, C (oa u)) β†’ C (query i t >>= oa))\n (failure : C failure) (oa : OracleComp spec Ξ±) : C oa :=\n FreeMonad.inductionOn (Option.rec failure pure) (Ξ» (query i t) ↦ query_bind i t) oa" }, { "name": "inductionOn", "content": "@[elab_as_elim]\nprotected def inductionOn {C : FreeMonad f Ξ± β†’ Prop}\n (pure : βˆ€ x, C (pure x))\n (roll : βˆ€ {Ξ²} (x : f Ξ²), (r : Ξ² β†’ FreeMonad f Ξ±) β†’\n (βˆ€ y, C (r y)) β†’ C (x >>= r)) :\n (oa : FreeMonad f Ξ±) β†’ C oa\n | FreeMonad.pure x => pure x\n | FreeMonad.roll x r => roll x _ (Ξ» u ↦\n FreeMonad.inductionOn pure roll (r u))" }, { "name": "induction", "content": "@[elab_as_elim]\nprotected def induction {C : OracleComp spec Ξ± β†’ Prop}\n (oa : OracleComp spec Ξ±) (pure : (a : Ξ±) β†’ C (pure a))\n (query_bind : (i : ΞΉ) β†’ (t : spec.domain i) β†’\n (oa : spec.range i β†’ OracleComp spec Ξ±) β†’ (βˆ€ u, C (oa u)) β†’ C (query i t >>= oa))\n (failure : C failure) : C oa :=\n FreeMonad.inductionOn (Option.rec failure pure) (Ξ» (query i t) ↦ query_bind i t) oa" }, { "name": "FiniteRange", "content": "class FiniteRange (spec : OracleSpec ΞΉ) where\n range_inhabited' (i : ΞΉ) : Inhabited (spec.range i)\n range_fintype' (i : ΞΉ) : Fintype (spec.range i)" }, { "name": "cases", "content": "def cases {Ξ±} {motive : {n : β„•} β†’ Vector Ξ± n β†’ Sort*} (v_empty : motive #v[])\n (v_insert : {n : β„•} β†’ (hd : Ξ±) β†’ (tl : Vector Ξ± n) β†’ motive (tl.insertIdx 0 hd)) {m : β„•} :\n (v : Vector Ξ± m) β†’ motive v := match hm : m with\n | 0 => fun v => match v with | ⟨⟨[]⟩, rfl⟩ => v_empty\n | n + 1 => fun v => match hv : v with\n | ⟨⟨hd :: tl⟩, hSize⟩ => by admit /- proof elided -/" } ]
[ { "name": "Function.comp_apply", "module": "Init.Core" }, { "name": "StateT.run'_eq", "module": "Init.Control.Lawful.Instances" }, { "name": "StateT.run_bind", "module": "Init.Control.Lawful.Instances" }, { "name": "StateT.run_monadLift", "module": "Init.Control.Lawful.Instances" }, { "name": "bind_map_left", "module": "Init.Control.Lawful.Basic" }, { "name": "congr_arg", "module": "Batteries.Logic" }, { "name": "map_bind", "module": "Init.Control.Lawful.Basic" } ]
[ { "name": "simulateQ_bind", "content": "@[simp] lemma simulateQ_bind (oa : OracleComp spec Ξ±) (ob : Ξ± β†’ OracleComp spec Ξ²) :\n simulateQ so (oa >>= ob) = simulateQ so oa >>= (simulateQ so ∘ ob)" }, { "name": "simulateQ_query_bind", "content": "@[simp] lemma simulateQ_query_bind (q : OracleQuery spec Ξ±) (ob : Ξ± β†’ OracleComp spec Ξ²) :\n simulateQ so (liftM q >>= ob) = so.impl q >>= (simulateQ so ∘ ob)" }, { "name": "evalDist_liftM", "content": "@[simp]\nlemma evalDist_liftM [Nonempty Ξ±] [Fintype Ξ±] (q : OracleQuery spec Ξ±) :\n evalDist (q : OracleComp spec Ξ±) = OptionT.lift (PMF.uniformOfFintype Ξ±)" }, { "name": "simulateQ_query", "content": "@[simp] lemma simulateQ_query (q : OracleQuery spec Ξ±) : simulateQ so q = so.impl q" } ]
[ { "name": "OracleSpec.SubSpec", "content": "class SubSpec (spec : OracleSpec.{u,w} ΞΉ) (superSpec : OracleSpec Ο„)\n extends MonadLift (OracleQuery spec) (OracleQuery superSpec) where" }, { "name": "OracleComp.liftComp", "content": "def liftComp (oa : OracleComp spec Ξ±) (superSpec : OracleSpec Ο„)\n [h : MonadLift (OracleQuery spec) (OracleQuery superSpec)] :\n OracleComp superSpec Ξ± := simulateQ ⟨liftM⟩ oa" } ]
[ { "name": "OracleComp.liftComp_pure", "content": "@[simp]\nlemma liftComp_pure (x : Ξ±) : liftComp (pure x : OracleComp spec Ξ±) superSpec = pure x" } ]
import VCVio.OracleComp.SimSemantics.SimulateQ import VCVio.OracleComp.Constructions.UniformSelect open OracleSpec OracleComp BigOperators ENNReal variable {ΞΉ : Type u} {Ο„ : Type v} {spec : OracleSpec ΞΉ} {superSpec : OracleSpec Ο„} {Ξ± Ξ² Ξ³ : Type w} namespace OracleSpec infix : 50 " βŠ‚β‚’ " => SubSpec namespace SubSpec variable [h : MonadLift (OracleQuery spec) (OracleQuery superSpec)] end SubSpec end OracleSpec namespace OracleComp section liftComp def liftComp (oa : OracleComp spec Ξ±) (superSpec : OracleSpec Ο„) [h : MonadLift (OracleQuery spec) (OracleQuery superSpec)] : OracleComp superSpec Ξ± := simulateQ ⟨liftM⟩ oa variable (superSpec : OracleSpec Ο„) [h : MonadLift (OracleQuery spec) (OracleQuery superSpec)]
@[simp] lemma evalDist_liftComp [spec.FiniteRange] [superSpec.FiniteRange] (oa : OracleComp spec Ξ±) : evalDist (liftComp oa superSpec) = evalDist oa :=
:= by induction oa using OracleComp.inductionOn with | pure x => simp [liftComp_pure] | query_bind i t oa hoa => simp only [liftComp, simulateQ_bind, simulateQ_query, StateT.run'_eq, StateT.run_bind, StateT.run_monadLift, SubSpec.liftM_query_eq_liftM_liftM, bind_pure_comp, Function.comp_apply, bind_map_left, map_bind, evalDist_bind, OracleComp.evalDist_liftM] refine congr_arg (_ >>= Β·) (funext Ξ» u ↦ ?_) simpa [StateT.run, liftComp] using hoa u | failure => simp
6
46
true
Applied verif.
446
OracleComp.pure_eq_bind_iff
@[simp] lemma pure_eq_bind_iff (oa : OracleComp spec Ξ±) (ob : Ξ± β†’ OracleComp spec Ξ²) (y : Ξ²) : pure y = oa >>= ob ↔ βˆƒ x : Ξ±, oa = pure x ∧ ob x = pure y
VCV-io
VCVio/OracleComp/OracleComp.lean
[ "import ToMathlib.Control.AlternativeMonad", "import ToMathlib.Control.Monad.Free", "import VCVio.OracleComp.OracleSpec", "import ToMathlib.Control.WriterT", "import Mathlib.Control.Lawful", "import ToMathlib.Control.OptionT" ]
[ { "name": "inline", "module": "Init.Core" }, { "name": "OptionT", "module": "Init.Control.Option" }, { "name": "Option", "module": "Init.Prelude" } ]
[ { "name": "domain", "content": "@[inline, reducible]\nprotected def domain (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type v := (spec i).1" }, { "name": "OracleSpec", "content": "def OracleSpec (ΞΉ : Type u) : Type (max u (v + 1)) :=\n (i : ΞΉ) β†’ Type v Γ— Type v" }, { "name": "range", "content": "@[inline, reducible]\nprotected def range (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type w := (spec i).2" }, { "name": "FreeMonad", "content": "inductive FreeMonad (f : Type u β†’ Type v) (Ξ± : Type w) : Type (max (u + 1) v w)\n | protected pure (x : Ξ±) : FreeMonad f Ξ±\n | roll {Ξ² : Type u} (x : f Ξ²) (r : Ξ² β†’ FreeMonad f Ξ±) : FreeMonad f Ξ±" }, { "name": "inductionOn", "content": "@[elab_as_elim]\nprotected def inductionOn {C : FreeMonad f Ξ± β†’ Prop}\n (pure : βˆ€ x, C (pure x))\n (roll : βˆ€ {Ξ²} (x : f Ξ²), (r : Ξ² β†’ FreeMonad f Ξ±) β†’\n (βˆ€ y, C (r y)) β†’ C (x >>= r)) :\n (oa : FreeMonad f Ξ±) β†’ C oa\n | FreeMonad.pure x => pure x\n | FreeMonad.roll x r => roll x _ (Ξ» u ↦\n FreeMonad.inductionOn pure roll (r u))" } ]
[ { "name": "eq_comm", "module": "Init.Core" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "OracleSpec.OracleQuery", "content": "inductive OracleQuery {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) : Type v β†’ Type (max u v)\n | query (i : ΞΉ) (t : spec.domain i) : OracleQuery spec (spec.range i)" }, { "name": "OracleComp", "content": "def OracleComp {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) :\n Type w β†’ Type (max u (v + 1) w) :=\n OptionT (FreeMonad (OracleQuery.{u,v} spec))" }, { "name": "OracleComp.induction", "content": "@[elab_as_elim]\nprotected def induction {C : OracleComp spec Ξ± β†’ Prop}\n (oa : OracleComp spec Ξ±) (pure : (a : Ξ±) β†’ C (pure a))\n (query_bind : (i : ΞΉ) β†’ (t : spec.domain i) β†’\n (oa : spec.range i β†’ OracleComp spec Ξ±) β†’ (βˆ€ u, C (oa u)) β†’ C (query i t >>= oa))\n (failure : C failure) : C oa :=\n FreeMonad.inductionOn (Option.rec failure pure) (Ξ» (query i t) ↦ query_bind i t) oa" } ]
[ { "name": "OracleComp.bind_eq_pure_iff", "content": "@[simp]\nlemma bind_eq_pure_iff (oa : OracleComp spec Ξ±) (ob : Ξ± β†’ OracleComp spec Ξ²) (y : Ξ²) :\n oa >>= ob = pure y ↔ βˆƒ x : Ξ±, oa = pure x ∧ ob x = pure y" } ]
import ToMathlib.Control.Monad.Free import ToMathlib.Control.WriterT import ToMathlib.Control.AlternativeMonad import ToMathlib.Control.OptionT import Mathlib.Control.Lawful import VCVio.OracleComp.OracleSpec namespace OracleSpec inductive OracleQuery {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) : Type v β†’ Type (max u v) | query (i : ΞΉ) (t : spec.domain i) : OracleQuery spec (spec.range i) namespace OracleQuery variable {ΞΉ : Type u} {spec : OracleSpec ΞΉ} {Ξ± Ξ² : Type v} end OracleQuery end OracleSpec open OracleSpec def OracleComp {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) : Type w β†’ Type (max u (v + 1) w) := OptionT (FreeMonad (OracleQuery.{u,v} spec)) namespace OracleComp variable {ΞΉ : Type u} {spec : OracleSpec ΞΉ} {Ξ± Ξ² : Type v} section lift end lift notation "$[0.." n "]" => uniformFin n notation:50 "$[" n "β‹―" m "]" => uniformFin' n m example : OracleComp probSpec β„• := do let x ← $[314β‹―31415]; let y ← $[0β‹―x] return x + 2 * y @[elab_as_elim] protected def induction {C : OracleComp spec Ξ± β†’ Prop} (oa : OracleComp spec Ξ±) (pure : (a : Ξ±) β†’ C (pure a)) (query_bind : (i : ΞΉ) β†’ (t : spec.domain i) β†’ (oa : spec.range i β†’ OracleComp spec Ξ±) β†’ (βˆ€ u, C (oa u)) β†’ C (query i t >>= oa)) (failure : C failure) : C oa := FreeMonad.inductionOn (Option.rec failure pure) (Ξ» (query i t) ↦ query_bind i t) oa section construct variable {C : OracleComp spec Ξ± β†’ Type w} (h_pure : (a : Ξ±) β†’ C (pure a)) (h_query_bind : {Ξ² : Type v} β†’ (q : OracleQuery spec Ξ²) β†’ (oa : Ξ² β†’ OracleComp spec Ξ±) β†’ ((u : Ξ²) β†’ C (oa u)) β†’ C (q >>= oa)) (h_failure : C failure) (oa : OracleComp spec Ξ±) end construct section noConfusion variable (x : Ξ±) (y : Ξ²) (q : OracleQuery spec Ξ²) (oa : Ξ² β†’ OracleComp spec Ξ±) end noConfusion section mapM variable {m : Type v β†’ Type w} [Monad m] (fail : {Ξ± : Type v} β†’ m Ξ±) (qm : {Ξ± : Type v} β†’ OracleQuery spec Ξ± β†’ m Ξ±) end mapM section inj
@[simp] lemma pure_eq_bind_iff (oa : OracleComp spec Ξ±) (ob : Ξ± β†’ OracleComp spec Ξ²) (y : Ξ²) : pure y = oa >>= ob ↔ βˆƒ x : Ξ±, oa = pure x ∧ ob x = pure y :=
:= by apply eq_comm.trans (bind_eq_pure_iff oa ob y) alias ⟨_, bind_eq_pure⟩ := bind_eq_pure_iff alias ⟨_, pure_eq_bind⟩ := pure_eq_bind_iff
4
13
true
Applied verif.
447
OracleComp.evalDist_uniformSelectFinset
@[simp] lemma evalDist_uniformSelectFinset [DecidableEq Ξ±] (s : Finset Ξ±) : evalDist ($ s) = if hs : s.Nonempty then OptionT.lift (PMF.uniformOfFinset s hs) else failure
VCV-io
VCVio/OracleComp/Constructions/UniformSelect.lean
[ "import Batteries.Control.OptionT", "import VCVio.OracleComp.DistSemantics.Prod", "import VCVio.OracleComp.DistSemantics.EvalDist", "import ToMathlib.General" ]
[ { "name": "inline", "module": "Init.Core" }, { "name": "Finset", "module": "Mathlib.Data.Finset.Defs" }, { "name": "OptionT", "module": "Init.Control.Option" }, { "name": "OptionT.lift", "module": "Init.Control.Option" }, { "name": "PMF", "module": "Mathlib.Probability.ProbabilityMassFunction.Basic" }, { "name": "PMF.uniformOfFinset", "module": "Mathlib.Probability.Distributions.Uniform" }, { "name": "ENNReal", "module": "Mathlib.Data.ENNReal.Basic" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "OptionT.mk", "module": "Init.Control.Option" }, { "name": "reduceDIte", "module": "Lean.Meta.Tactic.Simp.BuiltinSimprocs.Core" }, { "name": "PEmpty", "module": "Init.Prelude" }, { "name": "PUnit", "module": "Init.Prelude" }, { "name": "IsEmpty", "module": "Mathlib.Logic.IsEmpty" }, { "name": "List", "module": "Init.Prelude" }, { "name": "List.count", "module": "Init.Data.List.Basic" }, { "name": "Fin", "module": "Init.Prelude" }, { "name": "Unit", "module": "Init.Prelude" }, { "name": "Fintype", "module": "Mathlib.Data.Fintype.Defs" }, { "name": "Vector", "module": "Init.Data.Vector.Basic" }, { "name": "Vector.insertIdx", "module": "Init.Data.Vector.Basic" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Pure", "module": "Init.Prelude" } ]
[ { "name": "probFailure", "content": "notation \"[βŠ₯\" \"|\" oa \"]\" => probFailure oa" }, { "name": "emptySpec", "content": "notation \"[]β‚’\" => emptySpec" }, { "name": "uniformFin", "content": "notation \"$[0..\" n \"]\" => uniformFin n" }, { "name": "notation:50 \"$[\" n \"β‹―\" m \"]\" => uniformFin' n m", "content": "notation:50 \"$[\" n \"β‹―\" m \"]\" => uniformFin' n m\n\nexample : OracleComp probSpec β„• := do\n let x ← $[314β‹―31415]; let y ← $[0β‹―x]\n return x + 2 * y" }, { "name": "probOutput", "content": "notation \"[=\" x \"|\" oa \"]\" => probOutput oa x" }, { "name": "HasEvalDist", "content": "class HasEvalDist (m : Type u β†’ Type v) [Monad m] where\n evalDist {Ξ± : Type u} (mx : m Ξ±) : SPMF Ξ±\n evalDist_pure {Ξ± : Type u} (x : Ξ±) : evalDist (pure x : m Ξ±) = pure x\n evalDist_bind {Ξ± Ξ² : Type u} (mx : m Ξ±) (my : Ξ± β†’ m Ξ²) :\n evalDist (mx >>= my) = evalDist mx >>= fun x => evalDist (my x)" }, { "name": "DecidableEq", "content": "protected class DecidableEq (spec : OracleSpec ΞΉ) where\n domain_decidableEq' (i : ΞΉ) : DecidableEq (spec.domain i)\n range_decidableEq' (i : ΞΉ) : DecidableEq (spec.range i)" }, { "name": "OracleSpec", "content": "def OracleSpec (ΞΉ : Type u) : Type (max u (v + 1)) :=\n (i : ΞΉ) β†’ Type v Γ— Type v" }, { "name": "domain", "content": "@[inline, reducible]\nprotected def domain (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type v := (spec i).1" }, { "name": "range", "content": "@[inline, reducible]\nprotected def range (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type w := (spec i).2" }, { "name": "probFailure", "content": "noncomputable def probFailure (oa : OracleComp spec Ξ±) : ℝβ‰₯0∞ :=\n (evalDist oa).run none" }, { "name": "OracleComp", "content": "def OracleComp {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) :\n Type w β†’ Type (max u (v + 1) w) :=\n OptionT (FreeMonad (OracleQuery.{u,v} spec))" }, { "name": "OracleQuery", "content": "inductive OracleQuery {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) : Type v β†’ Type (max u v)\n | query (i : ΞΉ) (t : spec.domain i) : OracleQuery spec (spec.range i)" }, { "name": "FreeMonad", "content": "inductive FreeMonad (f : Type u β†’ Type v) (Ξ± : Type w) : Type (max (u + 1) v w)\n | protected pure (x : Ξ±) : FreeMonad f Ξ±\n | roll {Ξ² : Type u} (x : f Ξ²) (r : Ξ² β†’ FreeMonad f Ξ±) : FreeMonad f Ξ±" }, { "name": "probOutput", "content": "noncomputable def probOutput (oa : OracleComp spec Ξ±) (x : Ξ±) : ℝβ‰₯0∞ :=\n (evalDist oa).run (some x)" }, { "name": "isEmpty", "content": "instance isEmpty : IsEmpty (OracleQuery []β‚’ Ξ±) where false | query i t => i.elim" }, { "name": "emptySpec", "content": "@[inline, reducible]\ndef emptySpec : OracleSpec PEmpty := Ξ» _ ↦ (PUnit, PUnit)" }, { "name": "uniformFin", "content": "@[reducible, inline] def uniformFin (n : β„•) : ProbComp (Fin (n + 1)) :=\n unifSpec.query n ()" }, { "name": "ProbComp", "content": "abbrev ProbComp : Type z β†’ Type (max z 1) := OracleComp unifSpec" }, { "name": "unifSpec", "content": "@[inline, reducible] def unifSpec : OracleSpec.{0,0} β„• :=\n Ξ» n ↦ (Unit, Fin (n + 1))" }, { "name": "uniformFin'", "content": "@[reducible, inline] def uniformFin' (n m : β„•) : OracleComp probSpec (Fin (m + 1)) :=\n probSpec.query m n" }, { "name": "probSpec", "content": "def probSpec : OracleSpec.{0,0} β„• :=\n fun n => (β„•, Fin (n + 1))" }, { "name": "induction", "content": "@[elab_as_elim]\ndef induction {Ξ±} {motive : {n : β„•} β†’ Vector Ξ± n β†’ Sort*} (v_empty : motive #v[])\n (v_insert : {n : β„•} β†’ (hd : Ξ±) β†’ (tl : Vector Ξ± n) β†’ motive tl β†’ motive (tl.insertIdx 0 hd))\n {m : β„•} : (v : Vector Ξ± m) β†’ motive v :=" }, { "name": "probOutput", "content": "notation \"Pr[=\" x \"|\" mx \"]\" => probOutput mx x" }, { "name": "probFailure", "content": "notation \"Pr[βŠ₯\" \"|\" mx \"]\" => probFailure mx" }, { "name": "probOutput", "content": "notation \"[=\" x \"|\" oa \"]\" => probOutput oa x" }, { "name": "probFailure", "content": "notation \"[βŠ₯\" \"|\" oa \"]\" => probFailure oa" }, { "name": "uniformFin", "content": "notation \"$[0..\" n \"]\" => uniformFin n" }, { "name": "notation:50 \"$[\" n \"β‹―\" m \"]\" => uniformFin' n m", "content": "notation:50 \"$[\" n \"β‹―\" m \"]\" => uniformFin' n m\n\nexample : OracleComp probSpec β„• := do\n let x ← $[314β‹―31415]; let y ← $[0β‹―x]\n return x + 2 * y" }, { "name": "emptySpec", "content": "notation \"[]β‚’\" => emptySpec" } ]
[ { "name": "Finset.nonempty_iff_ne_empty", "module": "Mathlib.Data.Finset.Empty" }, { "name": "div_eq_mul_inv", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "eq_comm", "module": "Init.Core" }, { "name": "Finset.mem_toList", "module": "Mathlib.Data.Finset.Dedup" }, { "name": "List.isEmpty_eq_false_iff_exists_mem", "module": "Init.Data.List.Lemmas" }, { "name": "ENNReal.inv_eq_zero", "module": "Mathlib.Data.ENNReal.Inv" }, { "name": "ENNReal.natCast_ne_top", "module": "Mathlib.Data.ENNReal.Basic" }, { "name": "Finset.not_nonempty_iff_eq_empty", "module": "Mathlib.Data.Finset.Empty" }, { "name": "PMF.bind_apply", "module": "Mathlib.Probability.ProbabilityMassFunction.Monad" }, { "name": "PMF.pure_apply", "module": "Mathlib.Probability.ProbabilityMassFunction.Monad" }, { "name": "PMF.uniformOfFinset_apply", "module": "Mathlib.Probability.Distributions.Uniform" }, { "name": "imp_false", "module": "Init.Core" }, { "name": "ite_eq_ite", "module": "Init.PropLemmas" }, { "name": "ite_eq_right_iff", "module": "Init.PropLemmas" }, { "name": "mul_ite", "module": "Mathlib.Algebra.Notation.Defs" }, { "name": "mul_one", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "ne_eq", "module": "Init.SimpLemmas" }, { "name": "symm", "module": "Mathlib.Order.Defs.Unbundled" }, { "name": "tsum_eq_single", "module": "Mathlib.Topology.Algebra.InfiniteSum.Basic" } ]
[ { "name": "probOutput_map_eq_sum_fintype_ite", "content": "lemma probOutput_map_eq_sum_fintype_ite [Fintype Ξ±] [DecidableEq Ξ²] (y : Ξ²) :\n [= y | f <$> oa] = βˆ‘ x : Ξ±, if y = f x then [= x | oa] else 0" }, { "name": "probOutput_map_eq_tsum_ite", "content": "lemma probOutput_map_eq_tsum_ite [DecidableEq Ξ²] (y : Ξ²) :\n [= y | f <$> oa] = βˆ‘' x : Ξ±, if y = f x then [= x | oa] else 0" }, { "name": "probOutput_bind_eq_tsum", "content": "lemma probOutput_bind_eq_tsum (y : Ξ²) :\n [= y | oa >>= ob] = βˆ‘' x : Ξ±, [= x | oa] * [= y | ob x]" }, { "name": "probOutput_pure", "content": "@[simp]\nlemma probOutput_pure [DecidableEq Ξ±] (y : Ξ±) :\n [= y | (pure x : OracleComp spec Ξ±)] = if y = x then 1 else 0" }, { "name": "List.countP_eq_sum_fin_ite", "content": "lemma List.countP_eq_sum_fin_ite {Ξ± : Type*} (xs : List Ξ±) (p : Ξ± β†’ Bool) :\n (βˆ‘ i : Fin xs.length, if p xs[i] then 1 else 0) = xs.countP p" }, { "name": "PMF.monad_pure_eq_pure", "content": "@[simp]\nlemma PMF.monad_pure_eq_pure {Ξ± : Type u} (x : Ξ±) :\n (Pure.pure x : PMF Ξ±) = PMF.pure x" }, { "name": "PMF.monad_bind_eq_bind", "content": "@[simp]\nlemma PMF.monad_bind_eq_bind {Ξ± Ξ² : Type u}\n (p : PMF Ξ±) (q : Ξ± β†’ PMF Ξ²) : p >>= q = p.bind q" } ]
[]
[ { "name": "OracleComp.uniformSelectList_cons", "content": "lemma uniformSelectList_cons (x : Ξ±) (xs : List Ξ±) :\n ($ x :: xs : ProbComp Ξ±) = ((x :: xs)[Β·]) <$> $[0..xs.length]" }, { "name": "OracleComp.probOutput_uniformSelectList", "content": "@[simp] lemma probOutput_uniformSelectList [DecidableEq Ξ±] (xs : List Ξ±) (x : Ξ±) :\n [= x | $ xs] = if xs.isEmpty then 0 else (xs.count x : ℝβ‰₯0∞) / xs.length" }, { "name": "OracleComp.uniformSelectFinset_def", "content": "lemma uniformSelectFinset_def {Ξ± : Type} [DecidableEq Ξ±] (s : Finset Ξ±) :\n ($ s) = ($ s.toList)" }, { "name": "OracleComp.probOutput_uniformSelectFinset", "content": "@[simp] lemma probOutput_uniformSelectFinset [DecidableEq Ξ±] (s : Finset Ξ±) (x : Ξ±) :\n [= x | $ s] = if x ∈ s then (s.card : ℝβ‰₯0∞)⁻¹ else 0" }, { "name": "OracleComp.probFailure_uniformSelectFinset", "content": "@[simp] lemma probFailure_uniformSelectFinset [DecidableEq Ξ±] (s : Finset Ξ±) :\n [βŠ₯ | $ s] = if s.Nonempty then 0 else 1" } ]
import VCVio.OracleComp.DistSemantics.Prod import Batteries.Control.OptionT open OracleSpec BigOperators ENNReal namespace OracleComp section uniformSelect prefix : 50 "$" => uniformSelect _ variable {cont Ξ² : Type} [h : HasUniformSelect cont Ξ²] end uniformSelect section uniformSelectList variable {Ξ± : Type} end uniformSelectList section uniformSelectVector end uniformSelectVector section uniformSelectFinset variable {Ξ± : Type}
@[simp] lemma evalDist_uniformSelectFinset [DecidableEq Ξ±] (s : Finset Ξ±) : evalDist ($ s) = if hs : s.Nonempty then OptionT.lift (PMF.uniformOfFinset s hs) else failure :=
:= by refine PMF.ext Ξ» x ↦ ?_ by_cases hs : s.Nonempty Β· cases x with | none => refine (probFailure_uniformSelectFinset _).trans ?_ simp [hs, OptionT.lift, OptionT.mk] | some x => simp only [hs, ↓reduceDIte] refine (probOutput_uniformSelectFinset _ _).trans ?_ simp only [OptionT.lift, OptionT.mk, PMF.monad_pure_eq_pure, PMF.monad_bind_eq_bind, PMF.bind_apply, PMF.uniformOfFinset_apply, PMF.pure_apply, Option.some.injEq, mul_ite, mul_one, mul_zero] refine symm <| (tsum_eq_single x ?_).trans ?_ Β· simp only [ne_eq, @eq_comm _ x, ite_eq_right_iff, ENNReal.inv_eq_zero, natCast_ne_top, imp_false] intros tauto Β· simp only [↓reduceIte, ite_eq_ite] Β· simp only [Finset.not_nonempty_iff_eq_empty] at hs simp [hs, uniformSelectFinset_def]
7
71
true
Applied verif.
448
OracleComp.query_bind_eq_roll
lemma query_bind_eq_roll (q : OracleQuery spec Ξ±) (ob : Ξ± β†’ OracleComp spec Ξ²) : (q : OracleComp spec Ξ±) >>= ob = OptionT.mk (FreeMonad.roll q ob) := rfl
VCV-io
VCVio/OracleComp/OracleComp.lean
[ "import ToMathlib.Control.AlternativeMonad", "import ToMathlib.Control.Monad.Free", "import VCVio.OracleComp.OracleSpec", "import ToMathlib.Control.WriterT", "import Mathlib.Control.Lawful", "import ToMathlib.Control.OptionT" ]
[ { "name": "inline", "module": "Init.Core" }, { "name": "OptionT", "module": "Init.Control.Option" }, { "name": "OptionT.mk", "module": "Init.Control.Option" } ]
[ { "name": "domain", "content": "@[inline, reducible]\nprotected def domain (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type v := (spec i).1" }, { "name": "OracleSpec", "content": "def OracleSpec (ΞΉ : Type u) : Type (max u (v + 1)) :=\n (i : ΞΉ) β†’ Type v Γ— Type v" }, { "name": "range", "content": "@[inline, reducible]\nprotected def range (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type w := (spec i).2" }, { "name": "FreeMonad", "content": "inductive FreeMonad (f : Type u β†’ Type v) (Ξ± : Type w) : Type (max (u + 1) v w)\n | protected pure (x : Ξ±) : FreeMonad f Ξ±\n | roll {Ξ² : Type u} (x : f Ξ²) (r : Ξ² β†’ FreeMonad f Ξ±) : FreeMonad f Ξ±" } ]
[ { "name": "...", "module": "" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "OracleSpec.OracleQuery", "content": "inductive OracleQuery {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) : Type v β†’ Type (max u v)\n | query (i : ΞΉ) (t : spec.domain i) : OracleQuery spec (spec.range i)" }, { "name": "OracleComp", "content": "def OracleComp {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) :\n Type w β†’ Type (max u (v + 1) w) :=\n OptionT (FreeMonad (OracleQuery.{u,v} spec))" } ]
[]
import ToMathlib.Control.Monad.Free import ToMathlib.Control.WriterT import ToMathlib.Control.AlternativeMonad import ToMathlib.Control.OptionT import Mathlib.Control.Lawful import VCVio.OracleComp.OracleSpec namespace OracleSpec inductive OracleQuery {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) : Type v β†’ Type (max u v) | query (i : ΞΉ) (t : spec.domain i) : OracleQuery spec (spec.range i) namespace OracleQuery variable {ΞΉ : Type u} {spec : OracleSpec ΞΉ} {Ξ± Ξ² : Type v} end OracleQuery end OracleSpec open OracleSpec def OracleComp {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) : Type w β†’ Type (max u (v + 1) w) := OptionT (FreeMonad (OracleQuery.{u,v} spec)) namespace OracleComp variable {ΞΉ : Type u} {spec : OracleSpec ΞΉ} {Ξ± Ξ² : Type v} section lift
lemma query_bind_eq_roll (q : OracleQuery spec Ξ±) (ob : Ξ± β†’ OracleComp spec Ξ²) : (q : OracleComp spec Ξ±) >>= ob = OptionT.mk (FreeMonad.roll q ob) :=
:= rfl
3
9
false
Applied verif.
449
OracleComp.queryBind_inj
@[simp] lemma queryBind_inj (q q' : OracleQuery spec Ξ±) (ob ob' : Ξ± β†’ OracleComp spec Ξ²) : (q : OracleComp spec Ξ±) >>= ob = (q' : OracleComp spec Ξ±) >>= ob' ↔ q = q' ∧ ob = ob'
VCV-io
VCVio/OracleComp/OracleComp.lean
[ "import ToMathlib.Control.AlternativeMonad", "import ToMathlib.Control.Monad.Free", "import VCVio.OracleComp.OracleSpec", "import ToMathlib.Control.WriterT", "import Mathlib.Control.Lawful", "import ToMathlib.Control.OptionT" ]
[ { "name": "inline", "module": "Init.Core" }, { "name": "OptionT", "module": "Init.Control.Option" }, { "name": "OptionT.bind", "module": "Init.Control.Option" }, { "name": "OptionT.lift", "module": "Init.Control.Option" }, { "name": "OptionT.mk", "module": "Init.Control.Option" } ]
[ { "name": "domain", "content": "@[inline, reducible]\nprotected def domain (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type v := (spec i).1" }, { "name": "OracleSpec", "content": "def OracleSpec (ΞΉ : Type u) : Type (max u (v + 1)) :=\n (i : ΞΉ) β†’ Type v Γ— Type v" }, { "name": "range", "content": "@[inline, reducible]\nprotected def range (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type w := (spec i).2" }, { "name": "FreeMonad", "content": "inductive FreeMonad (f : Type u β†’ Type v) (Ξ± : Type w) : Type (max (u + 1) v w)\n | protected pure (x : Ξ±) : FreeMonad f Ξ±\n | roll {Ξ² : Type u} (x : f Ξ²) (r : Ξ² β†’ FreeMonad f Ξ±) : FreeMonad f Ξ±" }, { "name": "lift", "content": "@[always_inline, inline]\ndef lift (x : f Ξ±) : FreeMonad f Ξ± := FreeMonad.roll x FreeMonad.pure" }, { "name": "bind", "content": "@[always_inline, inline]\nprotected def bind : FreeMonad f Ξ± β†’ (Ξ± β†’ FreeMonad f Ξ²) β†’ FreeMonad f Ξ²\n | FreeMonad.pure x, g => g x\n | FreeMonad.roll x r, g => FreeMonad.roll x (Ξ» u ↦ FreeMonad.bind (r u) g)" }, { "name": "notation:50 m₁ \" >>=β‚• \" mβ‚‚ => bind m₁ mβ‚‚", "content": "notation:50 m₁ \" >>=β‚• \" mβ‚‚ => bind m₁ mβ‚‚" } ]
[ { "name": "heq_eq_eq", "module": "Init.SimpLemmas" }, { "name": "true_and", "module": "Init.SimpLemmas" } ]
[ { "name": "bind_pure", "content": "@[simp]\nlemma bind_pure (x : Ξ±) (r : Ξ± β†’ FreeMonad f Ξ²) :\n FreeMonad.bind (FreeMonad.pure x) r = r x" }, { "name": "monad_bind_def", "content": "@[simp]\nlemma monad_bind_def (x : FreeMonad f Ξ±) (g : Ξ± β†’ FreeMonad f Ξ²) :\n x >>= g = FreeMonad.bind x g" }, { "name": "bind_lift", "content": "@[simp]\nlemma bind_lift (x : f Ξ±) (r : Ξ± β†’ FreeMonad f Ξ²) :\n FreeMonad.bind (FreeMonad.lift x) r = FreeMonad.roll x r" }, { "name": "bind_roll", "content": "@[simp]\nlemma bind_roll (x : f Ξ±) (r : Ξ± β†’ FreeMonad f Ξ²) (g : Ξ² β†’ FreeMonad f Ξ³) :\n FreeMonad.bind (FreeMonad.roll x r) g = FreeMonad.roll x (Ξ» u ↦ FreeMonad.bind (r u) g)" }, { "name": "monad_pure_def", "content": "@[simp]\nlemma monad_pure_def (x : Ξ±) : (pure x : FreeMonad f Ξ±) = FreeMonad.pure x" } ]
[ { "name": "OracleSpec.OracleQuery", "content": "inductive OracleQuery {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) : Type v β†’ Type (max u v)\n | query (i : ΞΉ) (t : spec.domain i) : OracleQuery spec (spec.range i)" }, { "name": "OracleComp", "content": "def OracleComp {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) :\n Type w β†’ Type (max u (v + 1) w) :=\n OptionT (FreeMonad (OracleQuery.{u,v} spec))" } ]
[ { "name": "OracleComp.liftM_def", "content": "protected lemma liftM_def (q : OracleQuery spec Ξ±) :\n (q : OracleComp spec Ξ±) = OptionT.lift (FreeMonad.lift q)" }, { "name": "OracleComp.bind_def", "content": "protected lemma bind_def (oa : OracleComp spec Ξ±) (ob : Ξ± β†’ OracleComp spec Ξ²) :\n oa >>= ob = OptionT.bind oa ob" } ]
import ToMathlib.Control.Monad.Free import ToMathlib.Control.WriterT import ToMathlib.Control.AlternativeMonad import ToMathlib.Control.OptionT import Mathlib.Control.Lawful import VCVio.OracleComp.OracleSpec namespace OracleSpec inductive OracleQuery {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) : Type v β†’ Type (max u v) | query (i : ΞΉ) (t : spec.domain i) : OracleQuery spec (spec.range i) namespace OracleQuery variable {ΞΉ : Type u} {spec : OracleSpec ΞΉ} {Ξ± Ξ² : Type v} end OracleQuery end OracleSpec open OracleSpec def OracleComp {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) : Type w β†’ Type (max u (v + 1) w) := OptionT (FreeMonad (OracleQuery.{u,v} spec)) namespace OracleComp variable {ΞΉ : Type u} {spec : OracleSpec ΞΉ} {Ξ± Ξ² : Type v} section lift end lift notation "$[0.." n "]" => uniformFin n notation:50 "$[" n "β‹―" m "]" => uniformFin' n m example : OracleComp probSpec β„• := do let x ← $[314β‹―31415]; let y ← $[0β‹―x] return x + 2 * y section construct variable {C : OracleComp spec Ξ± β†’ Type w} (h_pure : (a : Ξ±) β†’ C (pure a)) (h_query_bind : {Ξ² : Type v} β†’ (q : OracleQuery spec Ξ²) β†’ (oa : Ξ² β†’ OracleComp spec Ξ±) β†’ ((u : Ξ²) β†’ C (oa u)) β†’ C (q >>= oa)) (h_failure : C failure) (oa : OracleComp spec Ξ±) end construct section noConfusion variable (x : Ξ±) (y : Ξ²) (q : OracleQuery spec Ξ²) (oa : Ξ² β†’ OracleComp spec Ξ±) end noConfusion section mapM variable {m : Type v β†’ Type w} [Monad m] (fail : {Ξ± : Type v} β†’ m Ξ±) (qm : {Ξ± : Type v} β†’ OracleQuery spec Ξ± β†’ m Ξ±) end mapM section inj
@[simp] lemma queryBind_inj (q q' : OracleQuery spec Ξ±) (ob ob' : Ξ± β†’ OracleComp spec Ξ²) : (q : OracleComp spec Ξ±) >>= ob = (q' : OracleComp spec Ξ±) >>= ob' ↔ q = q' ∧ ob = ob' :=
:= by simp only [OracleComp.liftM_def, OptionT.lift, OptionT.mk, FreeMonad.monad_pure_def, FreeMonad.monad_bind_def, FreeMonad.bind_lift, OracleComp.bind_def, OptionT.bind, FreeMonad.bind_roll, FreeMonad.bind_pure] rw [FreeMonad.roll.injEq] simp only [heq_eq_eq, true_and]
3
22
false
Applied verif.
450
OracleComp.probFailure_bind_eq_sub_mul
lemma probFailure_bind_eq_sub_mul {oa : OracleComp spec Ξ±} {ob : Ξ± β†’ OracleComp spec Ξ²} (r : ℝβ‰₯0∞) (h : βˆ€ x, [βŠ₯ | ob x] = r) : [βŠ₯ | oa >>= ob] = 1 - (1 - [βŠ₯ | oa]) * (1 - r)
VCV-io
VCVio/OracleComp/DistSemantics/EvalDist.lean
[ "import Mathlib.Probability.Distributions.Uniform", "import VCVio.OracleComp.SimSemantics.SimulateQ", "import VCVio.OracleComp.Traversal", "import ToMathlib.General" ]
[ { "name": "inline", "module": "Init.Core" }, { "name": "OptionT", "module": "Init.Control.Option" }, { "name": "AddLECancellable", "module": "Mathlib.Algebra.Order.Monoid.Unbundled.Basic" }, { "name": "ENNReal", "module": "Mathlib.Data.ENNReal.Basic" }, { "name": "Eq", "module": "Init.Prelude" }, { "name": "Vector", "module": "Init.Data.Vector.Basic" }, { "name": "Vector.insertIdx", "module": "Init.Data.Vector.Basic" }, { "name": "AddCommMonoid", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "ContinuousAdd", "module": "Mathlib.Topology.Algebra.Monoid.Defs" }, { "name": "Function.update", "module": "Mathlib.Logic.Function.Basic" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "Summable", "module": "Mathlib.Topology.Algebra.InfiniteSum.Defs" }, { "name": "T2Space", "module": "Mathlib.Topology.Separation.Hausdorff" }, { "name": "TopologicalSpace", "module": "Mathlib.Topology.Defs.Basic" }, { "name": "Option.elimM", "module": "Init.Data.Option.Basic" }, { "name": "PMF", "module": "Mathlib.Probability.ProbabilityMassFunction.Basic" } ]
[ { "name": "probFailure", "content": "notation \"[βŠ₯\" \"|\" oa \"]\" => probFailure oa" }, { "name": "probOutput", "content": "notation \"[=\" x \"|\" oa \"]\" => probOutput oa x" }, { "name": "HasEvalDist", "content": "class HasEvalDist (m : Type u β†’ Type v) [Monad m] where\n evalDist {Ξ± : Type u} (mx : m Ξ±) : SPMF Ξ±\n evalDist_pure {Ξ± : Type u} (x : Ξ±) : evalDist (pure x : m Ξ±) = pure x\n evalDist_bind {Ξ± Ξ² : Type u} (mx : m Ξ±) (my : Ξ± β†’ m Ξ²) :\n evalDist (mx >>= my) = evalDist mx >>= fun x => evalDist (my x)" }, { "name": "OracleComp", "content": "def OracleComp {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) :\n Type w β†’ Type (max u (v + 1) w) :=\n OptionT (FreeMonad (OracleQuery.{u,v} spec))" }, { "name": "OracleQuery", "content": "inductive OracleQuery {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) : Type v β†’ Type (max u v)\n | query (i : ΞΉ) (t : spec.domain i) : OracleQuery spec (spec.range i)" }, { "name": "domain", "content": "@[inline, reducible]\nprotected def domain (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type v := (spec i).1" }, { "name": "OracleSpec", "content": "def OracleSpec (ΞΉ : Type u) : Type (max u (v + 1)) :=\n (i : ΞΉ) β†’ Type v Γ— Type v" }, { "name": "range", "content": "@[inline, reducible]\nprotected def range (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type w := (spec i).2" }, { "name": "FreeMonad", "content": "inductive FreeMonad (f : Type u β†’ Type v) (Ξ± : Type w) : Type (max (u + 1) v w)\n | protected pure (x : Ξ±) : FreeMonad f Ξ±\n | roll {Ξ² : Type u} (x : f Ξ²) (r : Ξ² β†’ FreeMonad f Ξ±) : FreeMonad f Ξ±" }, { "name": "cases", "content": "def cases {Ξ±} {motive : {n : β„•} β†’ Vector Ξ± n β†’ Sort*} (v_empty : motive #v[])\n (v_insert : {n : β„•} β†’ (hd : Ξ±) β†’ (tl : Vector Ξ± n) β†’ motive (tl.insertIdx 0 hd)) {m : β„•} :\n (v : Vector Ξ± m) β†’ motive v := match hm : m with\n | 0 => fun v => match v with | ⟨⟨[]⟩, rfl⟩ => v_empty\n | n + 1 => fun v => match hv : v with\n | ⟨⟨hd :: tl⟩, hSize⟩ => by admit /- proof elided -/" } ]
[ { "name": "ENNReal.summable", "module": "Mathlib.Topology.Instances.ENNReal.Lemmas" }, { "name": "symm", "module": "Mathlib.Order.Defs.Unbundled" }, { "name": "le_add_self", "module": "Mathlib.Algebra.Order.Monoid.Canonical.Defs" }, { "name": "le_of_le_of_eq", "module": "Init.Core" }, { "name": "ENNReal.eq_sub_of_add_eq", "module": "Mathlib.Data.ENNReal.Operations" }, { "name": "ENNReal.one_ne_top", "module": "Mathlib.Data.ENNReal.Basic" }, { "name": "ne_top_of_le_ne_top", "module": "Mathlib.Order.BoundedOrder.Basic" }, { "name": "PMF.coe_le_one", "module": "Mathlib.Probability.ProbabilityMassFunction.Basic" }, { "name": "PMF.apply_ne_top", "module": "Mathlib.Probability.ProbabilityMassFunction.Basic" }, { "name": "add_comm", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "AddLECancellable.tsub_tsub_assoc", "module": "Mathlib.Algebra.Order.Sub.Unbundled.Basic" }, { "name": "ENNReal.mul_sub", "module": "Mathlib.Data.ENNReal.Operations" }, { "name": "ENNReal.tsum_add", "module": "Mathlib.Topology.Instances.ENNReal.Lemmas" }, { "name": "ENNReal.tsum_le_tsum", "module": "Mathlib.Topology.Instances.ENNReal.Lemmas" }, { "name": "ENNReal.tsum_mul_right", "module": "Mathlib.Topology.Instances.ENNReal.Lemmas" }, { "name": "congr_arg", "module": "Batteries.Logic" }, { "name": "le_rfl", "module": "Mathlib.Order.Defs.PartialOrder" }, { "name": "le_trans", "module": "Mathlib.Order.Defs.PartialOrder" }, { "name": "mul_le_mul'", "module": "Mathlib.Algebra.Order.Monoid.Unbundled.Basic" }, { "name": "mul_one", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "tsub_add_cancel_of_le", "module": "Mathlib.Algebra.Order.Sub.Unbundled.Basic" }, { "name": "tsum_congr", "module": "Mathlib.Topology.Algebra.InfiniteSum.Basic" } ]
[ { "name": "tsum_option", "content": "lemma tsum_option {Ξ± Ξ² : Type*} [AddCommMonoid Ξ±] [TopologicalSpace Ξ±]\n [ContinuousAdd Ξ±] [T2Space Ξ±]\n (f : Option Ξ² β†’ Ξ±) (hf : Summable (Function.update f none 0)) :\n βˆ‘' x : Option Ξ², f x = f none + βˆ‘' x : Ξ², f (some x)" } ]
[ { "name": "OracleComp.probOutput", "content": "noncomputable def probOutput (oa : OracleComp spec Ξ±) (x : Ξ±) : ℝβ‰₯0∞ :=\n (evalDist oa).run (some x)" }, { "name": "OracleComp.probFailure", "content": "noncomputable def probFailure (oa : OracleComp spec Ξ±) : ℝβ‰₯0∞ :=\n (evalDist oa).run none" } ]
[ { "name": "OracleComp.probOutput_def", "content": "lemma probOutput_def (oa : OracleComp spec Ξ±) (x : Ξ±) :\n [= x | oa] = (evalDist oa).run (some x)" }, { "name": "OracleComp.probFailure_add_tsum_probOutput", "content": "@[simp]\nlemma probFailure_add_tsum_probOutput (oa : OracleComp spec Ξ±) :\n [βŠ₯ | oa] + βˆ‘' x, [= x | oa] = 1" }, { "name": "OracleComp.tsum_probOutput_add_probFailure", "content": "@[simp]\nlemma tsum_probOutput_add_probFailure (oa : OracleComp spec Ξ±) :\n βˆ‘' x, [= x | oa] + [βŠ₯ | oa] = 1" }, { "name": "OracleComp.probFailure_le_one", "content": "@[simp] lemma probFailure_le_one : [βŠ₯ | oa] ≀ 1" }, { "name": "OracleComp.tsum_probOutput_le_one", "content": "@[simp] lemma tsum_probOutput_le_one : βˆ‘' x : Ξ±, [= x | oa] ≀ 1" }, { "name": "OracleComp.probOutput_ne_top", "content": "@[simp] lemma probOutput_ne_top : [= x | oa] β‰  ∞" }, { "name": "OracleComp.probFailure_ne_top", "content": "@[simp] lemma probFailure_ne_top : [βŠ₯ | oa] β‰  ∞" }, { "name": "OracleComp.tsum_probOutput_eq_sub", "content": "lemma tsum_probOutput_eq_sub (oa : OracleComp spec Ξ±) :\n βˆ‘' x : Ξ±, [= x | oa] = 1 - [βŠ₯ | oa]" }, { "name": "OracleComp.probFailure_eq_sub_tsum", "content": "lemma probFailure_eq_sub_tsum (oa : OracleComp spec Ξ±) :\n [βŠ₯ | oa] = 1 - βˆ‘' x : Ξ±, [= x | oa]" }, { "name": "OracleComp.probFailure_bind_eq_tsum", "content": "lemma probFailure_bind_eq_tsum :\n [βŠ₯ | oa >>= ob] = [βŠ₯ | oa] + βˆ‘' x : Ξ±, [= x | oa] * [βŠ₯ | ob x]" } ]
import VCVio.OracleComp.Traversal import VCVio.OracleComp.SimSemantics.SimulateQ import Mathlib.Probability.Distributions.Uniform import ToMathlib.General open OracleSpec Option ENNReal BigOperators namespace OracleComp variable {ΞΉ : Type u} {spec : OracleSpec ΞΉ} {ΞΉ' : Type v} {spec' : OracleSpec ΞΉ'} {Ξ± Ξ² Ξ³ : Type w} [spec.FiniteRange] [spec'.FiniteRange] section evalDist end evalDist noncomputable def probOutput (oa : OracleComp spec Ξ±) (x : Ξ±) : ℝβ‰₯0∞ := (evalDist oa).run (some x) notation "[=" x "|" oa "]" => probOutput oa x noncomputable def probFailure (oa : OracleComp spec Ξ±) : ℝβ‰₯0∞ := (evalDist oa).run none notation "[βŠ₯" "|" oa "]" => probFailure oa notation "[" p "|" oa "]" => probEvent oa p section bounds variable {oa : OracleComp spec Ξ±} {x : Ξ±} {p : Ξ± β†’ Prop} end bounds section support variable (oa : OracleComp spec Ξ±) (x : Ξ±) (p q : Ξ± β†’ Prop) variable {oa x p q} end support section sums variable (oa : OracleComp spec Ξ±) (p : Ξ± β†’ Prop) end sums section pure variable (x : Ξ±) end pure section bind variable (oa : OracleComp spec Ξ±) (ob : Ξ± β†’ OracleComp spec Ξ²)
lemma probFailure_bind_eq_sub_mul {oa : OracleComp spec Ξ±} {ob : Ξ± β†’ OracleComp spec Ξ²} (r : ℝβ‰₯0∞) (h : βˆ€ x, [βŠ₯ | ob x] = r) : [βŠ₯ | oa >>= ob] = 1 - (1 - [βŠ₯ | oa]) * (1 - r) :=
:= by rw [probFailure_bind_eq_tsum] rw [← tsum_probOutput_eq_sub] rw [← ENNReal.tsum_mul_right] have hl : βˆ€ x, [=x|oa] * [βŠ₯|ob x] ≀ [=x|oa] := Ξ» x ↦ le_of_le_of_eq (mul_le_mul' le_rfl probFailure_le_one) (mul_one _) calc [βŠ₯ | oa] + βˆ‘' x, [= x | oa] * [βŠ₯ | ob x] _ = 1 - (βˆ‘' x, [= x | oa]) + (βˆ‘' x, [= x | oa] * [βŠ₯ | ob x]) := by rw [probFailure_eq_sub_tsum] _ = 1 - (βˆ‘' x, [= x | oa] - βˆ‘' x, [= x | oa] * [βŠ₯ | ob x]) := by exact Eq.symm (AddLECancellable.tsub_tsub_assoc (by simp) tsum_probOutput_le_one (ENNReal.tsum_le_tsum hl)) _ = 1 - βˆ‘' x, ([= x | oa] - [= x | oa] * [βŠ₯ | ob x]) := by refine congr_arg (1 - Β·) (ENNReal.eq_sub_of_add_eq ?_ ?_).symm Β· refine ne_top_of_le_ne_top one_ne_top ?_ refine le_trans ?_ (@tsum_probOutput_le_one _ _ _ _ oa) refine ENNReal.tsum_le_tsum Ξ» x ↦ ?_ exact hl x rw [← ENNReal.tsum_add] refine tsum_congr Ξ» x ↦ tsub_add_cancel_of_le (hl x) _ = 1 - βˆ‘' x : Ξ±, [= x | oa] * (1 - r) := by refine congr_arg (1 - Β·) (tsum_congr Ξ» x ↦ ?_) rw [ENNReal.mul_sub (Ξ» _ _ ↦ probOutput_ne_top), mul_one, ← h x]
5
56
true
Applied verif.
451
BindEquiv.map_bind_inv
@[simp] lemma map_bind_inv (f : BindEquiv m n) {Ξ± Ξ² : Type u} (x : n Ξ±) (y : Ξ± β†’ n Ξ²) : f.invFun (x >>= y) = f.invFun x >>= (fun a => f.invFun (y a))
VCV-io
ToMathlib/Control/Monad/Equiv.lean
[ "import Mathlib.Logic.Function.Defs", "import ToMathlib.Control.Monad.Hom" ]
[ { "name": "Function.LeftInverse", "module": "Init.Data.Function" }, { "name": "Function.RightInverse", "module": "Init.Data.Function" }, { "name": "Bind", "module": "Init.Prelude" } ]
[ { "name": "NatHom", "content": "structure NatHom (m : Type u β†’ Type v) (n : Type u β†’ Type w) where\n toFun : {Ξ± : Type u} β†’ m Ξ± β†’ n Ξ±" } ]
[ { "name": "Function.LeftInverse.injective", "module": "Init.Data.Function" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "NatEquiv", "content": "structure NatEquiv (m : Type u β†’ Type v) (n : Type u β†’ Type w) where\n toFun : {Ξ± : Type u} β†’ m Ξ± β†’ n Ξ±\n invFun : {Ξ± : Type u} β†’ n Ξ± β†’ m Ξ±\n left_inv : βˆ€ {Ξ±}, Function.LeftInverse (@invFun Ξ±) (@toFun Ξ±) := by admit /- proof elided -/" }, { "name": "BindEquiv", "content": "structure BindEquiv (m : Type u β†’ Type v) [Bind m] (n : Type u β†’ Type w) [Bind n]\n extends NatEquiv m n where\n map_bind' {Ξ± Ξ² : Type u} (x : m Ξ±) (y : Ξ± β†’ m Ξ²) :\n toFun (x >>= y) = toFun x >>= (fun a => toFun (y a))" } ]
[]
import ToMathlib.Control.Monad.Hom import Mathlib.Logic.Function.Defs structure NatEquiv (m : Type u β†’ Type v) (n : Type u β†’ Type w) where toFun : {Ξ± : Type u} β†’ m Ξ± β†’ n Ξ± invFun : {Ξ± : Type u} β†’ n Ξ± β†’ m Ξ± left_inv : βˆ€ {Ξ±}, Function.LeftInverse (@invFun Ξ±) (@toFun Ξ±) := by admit /- proof elided -/ namespace NatEquiv variable {m : Type u β†’ Type v} {n : Type u β†’ Type w} {p : Type u β†’ Type z} end NatEquiv namespace PureEquiv variable {m : Type u β†’ Type v} [Pure m] {n : Type u β†’ Type w} [Pure n] end PureEquiv structure BindEquiv (m : Type u β†’ Type v) [Bind m] (n : Type u β†’ Type w) [Bind n] extends NatEquiv m n where map_bind' {Ξ± Ξ² : Type u} (x : m Ξ±) (y : Ξ± β†’ m Ξ²) : toFun (x >>= y) = toFun x >>= (fun a => toFun (y a)) namespace BindEquiv variable {m : Type u β†’ Type v} [Bind m] {n : Type u β†’ Type w} [Bind n]
@[simp] lemma map_bind_inv (f : BindEquiv m n) {Ξ± Ξ² : Type u} (x : n Ξ±) (y : Ξ± β†’ n Ξ²) : f.invFun (x >>= y) = f.invFun x >>= (fun a => f.invFun (y a)) :=
:= by -- We'll show f.toFun applied to both sides gives the same result have h1 : f.toFun (f.invFun (x >>= y)) = x >>= y := f.right_inv (x >>= y) have h2 : f.toFun (f.invFun x >>= (fun a => f.invFun (y a))) = f.toFun (f.invFun x) >>= (fun a => f.toFun (f.invFun (y a))) := f.map_bind' _ _ have h3 : f.toFun (f.invFun x) = x := f.right_inv x have h4 : βˆ€ a, f.toFun (f.invFun (y a)) = y a := fun a => f.right_inv (y a) have h5 : f.toFun (f.invFun x >>= (fun a => f.invFun (y a))) = x >>= y := by rw [h2, h3] congr 1 ext a exact h4 a have h6 : f.toFun (f.invFun (x >>= y)) = f.toFun (f.invFun x >>= (fun a => f.invFun (y a))) := by rw [h1, h5] exact Function.LeftInverse.injective f.left_inv h6
2
7
true
Applied verif.
452
OracleComp.mul_le_probEvent_bind
lemma mul_le_probEvent_bind {oa : OracleComp spec Ξ±} {ob : Ξ± β†’ OracleComp spec Ξ²} {p : Ξ± β†’ Prop} {q : Ξ² β†’ Prop} {r r' : ℝβ‰₯0∞} (h : r ≀ [p | oa]) (h' : βˆ€ x ∈ oa.support, p x β†’ r' ≀ [q | ob x]) : r * r' ≀ [q | oa >>= ob]
VCV-io
VCVio/OracleComp/DistSemantics/EvalDist.lean
[ "import Mathlib.Probability.Distributions.Uniform", "import VCVio.OracleComp.SimSemantics.SimulateQ", "import VCVio.OracleComp.Traversal", "import ToMathlib.General" ]
[ { "name": "inline", "module": "Init.Core" }, { "name": "OptionT", "module": "Init.Control.Option" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "Set", "module": "Mathlib.Data.Set.Defs" }, { "name": "Set.univ", "module": "Mathlib.Data.Set.Defs" }, { "name": "ENNReal", "module": "Mathlib.Data.ENNReal.Basic" }, { "name": "Option.elimM", "module": "Init.Data.Option.Basic" }, { "name": "PMF", "module": "Mathlib.Probability.ProbabilityMassFunction.Basic" }, { "name": "Vector", "module": "Init.Data.Vector.Basic" }, { "name": "Vector.insertIdx", "module": "Init.Data.Vector.Basic" }, { "name": "AddCommMonoid", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "ContinuousAdd", "module": "Mathlib.Topology.Algebra.Monoid.Defs" }, { "name": "Function.update", "module": "Mathlib.Logic.Function.Basic" }, { "name": "Summable", "module": "Mathlib.Topology.Algebra.InfiniteSum.Defs" }, { "name": "T2Space", "module": "Mathlib.Topology.Separation.Hausdorff" }, { "name": "TopologicalSpace", "module": "Mathlib.Topology.Defs.Basic" } ]
[ { "name": "probOutput", "content": "notation \"[=\" x \"|\" oa \"]\" => probOutput oa x" }, { "name": "support", "content": "def support (oa : OracleComp spec Ξ±) : Set Ξ± :=\n oa.supportWhen fun _ => Set.univ" }, { "name": "supportWhen", "content": "def supportWhen (oa : OracleComp spec Ξ±)\n (possible_outputs : {Ξ± : Type v} β†’ OracleQuery spec Ξ± β†’ Set Ξ±) : Set Ξ± :=" }, { "name": "induction", "content": "@[elab_as_elim]\nprotected def induction {C : OracleComp spec Ξ± β†’ Prop}\n (oa : OracleComp spec Ξ±) (pure : (a : Ξ±) β†’ C (pure a))\n (query_bind : (i : ΞΉ) β†’ (t : spec.domain i) β†’\n (oa : spec.range i β†’ OracleComp spec Ξ±) β†’ (βˆ€ u, C (oa u)) β†’ C (query i t >>= oa))\n (failure : C failure) : C oa :=\n FreeMonad.inductionOn (Option.rec failure pure) (Ξ» (query i t) ↦ query_bind i t) oa" }, { "name": "OracleQuery", "content": "inductive OracleQuery {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) : Type v β†’ Type (max u v)\n | query (i : ΞΉ) (t : spec.domain i) : OracleQuery spec (spec.range i)" }, { "name": "OracleComp", "content": "def OracleComp {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) :\n Type w β†’ Type (max u (v + 1) w) :=\n OptionT (FreeMonad (OracleQuery.{u,v} spec))" }, { "name": "domain", "content": "@[inline, reducible]\nprotected def domain (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type v := (spec i).1" }, { "name": "OracleSpec", "content": "def OracleSpec (ΞΉ : Type u) : Type (max u (v + 1)) :=\n (i : ΞΉ) β†’ Type v Γ— Type v" }, { "name": "range", "content": "@[inline, reducible]\nprotected def range (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type w := (spec i).2" }, { "name": "FreeMonad", "content": "inductive FreeMonad (f : Type u β†’ Type v) (Ξ± : Type w) : Type (max (u + 1) v w)\n | protected pure (x : Ξ±) : FreeMonad f Ξ±\n | roll {Ξ² : Type u} (x : f Ξ²) (r : Ξ² β†’ FreeMonad f Ξ±) : FreeMonad f Ξ±" }, { "name": "inductionOn", "content": "@[elab_as_elim]\nprotected def inductionOn {C : FreeMonad f Ξ± β†’ Prop}\n (pure : βˆ€ x, C (pure x))\n (roll : βˆ€ {Ξ²} (x : f Ξ²), (r : Ξ² β†’ FreeMonad f Ξ±) β†’\n (βˆ€ y, C (r y)) β†’ C (x >>= r)) :\n (oa : FreeMonad f Ξ±) β†’ C oa\n | FreeMonad.pure x => pure x\n | FreeMonad.roll x r => roll x _ (Ξ» u ↦\n FreeMonad.inductionOn pure roll (r u))" }, { "name": "construct", "content": "@[elab_as_elim]\nprotected def construct {C : OracleComp spec Ξ± β†’ Type*}\n (pure : (a : Ξ±) β†’ C (pure a))\n (query_bind : {Ξ² : Type v} β†’ (q : OracleQuery spec Ξ²) β†’\n (oa : Ξ² β†’ OracleComp spec Ξ±) β†’ ((u : Ξ²) β†’ C (oa u)) β†’ C (q >>= oa))\n (failure : C failure) (oa : OracleComp spec Ξ±) : C oa :=\n FreeMonad.construct (Option.rec failure pure) query_bind oa" }, { "name": "construct", "content": "@[elab_as_elim]\nprotected def construct {C : FreeMonad f Ξ± β†’ Type*}\n (pure : (x : Ξ±) β†’ C (pure x))\n (roll : {Ξ² : Type u} β†’ (x : f Ξ²) β†’ (r : Ξ² β†’ FreeMonad f Ξ±) β†’\n ((y : Ξ²) β†’ C (r y)) β†’ C (x >>= r)) :\n (oa : FreeMonad f Ξ±) β†’ C oa\n | .pure x => pure x\n | .roll x r => roll x _ (Ξ» u ↦ FreeMonad.construct pure roll (r u))" }, { "name": "HasEvalDist", "content": "class HasEvalDist (m : Type u β†’ Type v) [Monad m] where\n evalDist {Ξ± : Type u} (mx : m Ξ±) : SPMF Ξ±\n evalDist_pure {Ξ± : Type u} (x : Ξ±) : evalDist (pure x : m Ξ±) = pure x\n evalDist_bind {Ξ± Ξ² : Type u} (mx : m Ξ±) (my : Ξ± β†’ m Ξ²) :\n evalDist (mx >>= my) = evalDist mx >>= fun x => evalDist (my x)" }, { "name": "cases", "content": "def cases {Ξ±} {motive : {n : β„•} β†’ Vector Ξ± n β†’ Sort*} (v_empty : motive #v[])\n (v_insert : {n : β„•} β†’ (hd : Ξ±) β†’ (tl : Vector Ξ± n) β†’ motive (tl.insertIdx 0 hd)) {m : β„•} :\n (v : Vector Ξ± m) β†’ motive v := match hm : m with\n | 0 => fun v => match v with | ⟨⟨[]⟩, rfl⟩ => v_empty\n | n + 1 => fun v => match hv : v with\n | ⟨⟨hd :: tl⟩, hSize⟩ => by admit /- proof elided -/" } ]
[ { "name": "ENNReal.summable", "module": "Mathlib.Topology.Instances.ENNReal.Lemmas" }, { "name": "PMF.toOuterMeasure_bind_apply", "module": "Mathlib.Probability.ProbabilityMassFunction.Monad" }, { "name": "PMF.apply_ne_top", "module": "Mathlib.Probability.ProbabilityMassFunction.Basic" }, { "name": "Option.some_injective", "module": "Mathlib.Data.Option.Basic" }, { "name": "PMF.toOuterMeasure_apply", "module": "Mathlib.Probability.ProbabilityMassFunction.Basic" }, { "name": "Set.indicator_image", "module": "Mathlib.Algebra.Notation.Indicator" }, { "name": "ENNReal.mul_le_mul_left", "module": "Mathlib.Data.ENNReal.Operations" }, { "name": "ENNReal.tsum_le_tsum", "module": "Mathlib.Topology.Instances.ENNReal.Lemmas" }, { "name": "ENNReal.tsum_mul_right", "module": "Mathlib.Topology.Instances.ENNReal.Lemmas" }, { "name": "Set.indicator_apply_le'", "module": "Mathlib.Algebra.Order.Group.Indicator" }, { "name": "Set.indicator_mul_const", "module": "Mathlib.Algebra.GroupWithZero.Indicator" }, { "name": "mul_le_mul_right'", "module": "Mathlib.Algebra.Order.Monoid.Unbundled.Basic" }, { "name": "zero_le'", "module": "Mathlib.Algebra.Order.GroupWithZero.Canonical" } ]
[ { "name": "tsum_option", "content": "lemma tsum_option {Ξ± Ξ² : Type*} [AddCommMonoid Ξ±] [TopologicalSpace Ξ±]\n [ContinuousAdd Ξ±] [T2Space Ξ±]\n (f : Option Ξ² β†’ Ξ±) (hf : Summable (Function.update f none 0)) :\n βˆ‘' x : Option Ξ², f x = f none + βˆ‘' x : Ξ², f (some x)" } ]
[ { "name": "OracleComp.probOutput", "content": "noncomputable def probOutput (oa : OracleComp spec Ξ±) (x : Ξ±) : ℝβ‰₯0∞ :=\n (evalDist oa).run (some x)" } ]
[ { "name": "OracleComp.evalDist_apply_some", "content": "lemma evalDist_apply_some (oa : OracleComp spec Ξ±) (x : Ξ±) :\n (evalDist oa).run (some x) = [= x | oa]" }, { "name": "OracleComp.probEvent_def", "content": "lemma probEvent_def (oa : OracleComp spec Ξ±) (p : Ξ± β†’ Prop) :\n [p | oa] = (evalDist oa).run.toOuterMeasure (Option.some '' {x | p x})" }, { "name": "OracleComp.probEvent_eq_tsum_indicator", "content": "lemma probEvent_eq_tsum_indicator (oa : OracleComp spec Ξ±) (p : Ξ± β†’ Prop) :\n [p | oa] = βˆ‘' x : Ξ±, {x | p x}.indicator ([= Β· | oa]) x" }, { "name": "OracleComp.probOutput_ne_top", "content": "@[simp] lemma probOutput_ne_top : [= x | oa] β‰  ∞" }, { "name": "OracleComp.probOutput_ne_zero", "content": "lemma probOutput_ne_zero (h : x ∈ oa.support) : [= x | oa] β‰  0" }, { "name": "OracleComp.probEvent_bind_eq_tsum", "content": "lemma probEvent_bind_eq_tsum (q : Ξ² β†’ Prop) :\n [q | oa >>= ob] = βˆ‘' x : Ξ±, [= x | oa] * [q | ob x]" } ]
import VCVio.OracleComp.Traversal import VCVio.OracleComp.SimSemantics.SimulateQ import Mathlib.Probability.Distributions.Uniform import ToMathlib.General open OracleSpec Option ENNReal BigOperators namespace OracleComp variable {ΞΉ : Type u} {spec : OracleSpec ΞΉ} {ΞΉ' : Type v} {spec' : OracleSpec ΞΉ'} {Ξ± Ξ² Ξ³ : Type w} [spec.FiniteRange] [spec'.FiniteRange] section evalDist end evalDist noncomputable def probOutput (oa : OracleComp spec Ξ±) (x : Ξ±) : ℝβ‰₯0∞ := (evalDist oa).run (some x) notation "[=" x "|" oa "]" => probOutput oa x notation "[βŠ₯" "|" oa "]" => probFailure oa notation "[" p "|" oa "]" => probEvent oa p section bounds variable {oa : OracleComp spec Ξ±} {x : Ξ±} {p : Ξ± β†’ Prop} end bounds section support variable (oa : OracleComp spec Ξ±) (x : Ξ±) (p q : Ξ± β†’ Prop) variable {oa x p q} end support section sums variable (oa : OracleComp spec Ξ±) (p : Ξ± β†’ Prop) end sums section pure variable (x : Ξ±) end pure section bind variable (oa : OracleComp spec Ξ±) (ob : Ξ± β†’ OracleComp spec Ξ²) end bind section mul_le_probEvent_bind
lemma mul_le_probEvent_bind {oa : OracleComp spec Ξ±} {ob : Ξ± β†’ OracleComp spec Ξ²} {p : Ξ± β†’ Prop} {q : Ξ² β†’ Prop} {r r' : ℝβ‰₯0∞} (h : r ≀ [p | oa]) (h' : βˆ€ x ∈ oa.support, p x β†’ r' ≀ [q | ob x]) : r * r' ≀ [q | oa >>= ob] :=
:= by rw [probEvent_bind_eq_tsum] refine (mul_le_mul_right' h r').trans ?_ rw [probEvent_eq_tsum_indicator, ← ENNReal.tsum_mul_right] refine ENNReal.tsum_le_tsum fun x => ?_ rw [← Set.indicator_mul_const] by_cases hx : x ∈ oa.support Β· refine Set.indicator_apply_le' (fun h => ?_) (fun _ => zero_le') exact (ENNReal.mul_le_mul_left (probOutput_ne_zero _ _ hx) probOutput_ne_top).mpr (h' x hx h) Β· simp [probOutput_eq_zero _ _ hx]
5
48
true
Applied verif.
453
OracleComp.probEvent_seq_map_eq_mul
lemma probEvent_seq_map_eq_mul {ΞΉ : Type u} {spec : OracleSpec ΞΉ} {Ξ± Ξ² Ξ³ : Type v} (f : Ξ± β†’ Ξ² β†’ Ξ³) [spec.FiniteRange] (oa : OracleComp spec Ξ±) (ob : OracleComp spec Ξ²) (p : Ξ³ β†’ Prop) (q1 : Ξ± β†’ Prop) (q2 : Ξ² β†’ Prop) (h : βˆ€ x ∈ oa.support, βˆ€ y ∈ ob.support, p (f x y) ↔ q1 x ∧ q2 y) : [p | f <$> oa <*> ob] = [q1 | oa] * [q2 | ob]
VCV-io
VCVio/OracleComp/DistSemantics/Seq.lean
[ "import VCVio.OracleComp.DistSemantics.Monad", "import VCVio.OracleComp.DistSemantics.EvalDist", "import VCVio.OracleComp.Support", "import ToMathlib.General" ]
[ { "name": "inline", "module": "Init.Core" }, { "name": "OptionT", "module": "Init.Control.Option" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "Set", "module": "Mathlib.Data.Set.Defs" }, { "name": "Set.univ", "module": "Mathlib.Data.Set.Defs" }, { "name": "Fintype", "module": "Mathlib.Data.Fintype.Defs" }, { "name": "Inhabited", "module": "Init.Prelude" }, { "name": "Classical.decPred", "module": "Mathlib.Logic.Basic" }, { "name": "DecidablePred", "module": "Init.Prelude" }, { "name": "ENNReal", "module": "Mathlib.Data.ENNReal.Basic" }, { "name": "Prod", "module": "Init.Prelude" }, { "name": "Prod.mk", "module": "Init.Prelude" }, { "name": "Function.comp", "module": "Init.Prelude" }, { "name": "Functor", "module": "Init.Prelude" }, { "name": "Set.image2", "module": "Mathlib.Data.Set.Operations" }, { "name": "Vector", "module": "Init.Data.Vector.Basic" }, { "name": "Vector.insertIdx", "module": "Init.Data.Vector.Basic" }, { "name": "Fin", "module": "Init.Prelude" }, { "name": "Unit", "module": "Init.Prelude" }, { "name": "Function.Injective2", "module": "Mathlib.Logic.Function.Basic" } ]
[ { "name": "probOutput", "content": "notation \"[=\" x \"|\" oa \"]\" => probOutput oa x" }, { "name": "uniformFin", "content": "notation \"$[0..\" n \"]\" => uniformFin n" }, { "name": "notation:50 \"$[\" n \"β‹―\" m \"]\" => uniformFin' n m", "content": "notation:50 \"$[\" n \"β‹―\" m \"]\" => uniformFin' n m\n\nexample : OracleComp probSpec β„• := do\n let x ← $[314β‹―31415]; let y ← $[0β‹―x]\n return x + 2 * y" }, { "name": "probFailure", "content": "notation \"[βŠ₯\" \"|\" oa \"]\" => probFailure oa" }, { "name": "OracleSpec", "content": "def OracleSpec (ΞΉ : Type u) : Type (max u (v + 1)) :=\n (i : ΞΉ) β†’ Type v Γ— Type v" }, { "name": "probOutput", "content": "noncomputable def probOutput (oa : OracleComp spec Ξ±) (x : Ξ±) : ℝβ‰₯0∞ :=\n (evalDist oa).run (some x)" }, { "name": "HasEvalDist", "content": "class HasEvalDist (m : Type u β†’ Type v) [Monad m] where\n evalDist {Ξ± : Type u} (mx : m Ξ±) : SPMF Ξ±\n evalDist_pure {Ξ± : Type u} (x : Ξ±) : evalDist (pure x : m Ξ±) = pure x\n evalDist_bind {Ξ± Ξ² : Type u} (mx : m Ξ±) (my : Ξ± β†’ m Ξ²) :\n evalDist (mx >>= my) = evalDist mx >>= fun x => evalDist (my x)" }, { "name": "OracleComp", "content": "def OracleComp {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) :\n Type w β†’ Type (max u (v + 1) w) :=\n OptionT (FreeMonad (OracleQuery.{u,v} spec))" }, { "name": "OracleQuery", "content": "inductive OracleQuery {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) : Type v β†’ Type (max u v)\n | query (i : ΞΉ) (t : spec.domain i) : OracleQuery spec (spec.range i)" }, { "name": "domain", "content": "@[inline, reducible]\nprotected def domain (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type v := (spec i).1" }, { "name": "range", "content": "@[inline, reducible]\nprotected def range (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type w := (spec i).2" }, { "name": "FreeMonad", "content": "inductive FreeMonad (f : Type u β†’ Type v) (Ξ± : Type w) : Type (max (u + 1) v w)\n | protected pure (x : Ξ±) : FreeMonad f Ξ±\n | roll {Ξ² : Type u} (x : f Ξ²) (r : Ξ² β†’ FreeMonad f Ξ±) : FreeMonad f Ξ±" }, { "name": "support", "content": "def support (oa : OracleComp spec Ξ±) : Set Ξ± :=\n oa.supportWhen fun _ => Set.univ" }, { "name": "supportWhen", "content": "def supportWhen (oa : OracleComp spec Ξ±)\n (possible_outputs : {Ξ± : Type v} β†’ OracleQuery spec Ξ± β†’ Set Ξ±) : Set Ξ± :=" }, { "name": "induction", "content": "@[elab_as_elim]\nprotected def induction {C : OracleComp spec Ξ± β†’ Prop}\n (oa : OracleComp spec Ξ±) (pure : (a : Ξ±) β†’ C (pure a))\n (query_bind : (i : ΞΉ) β†’ (t : spec.domain i) β†’\n (oa : spec.range i β†’ OracleComp spec Ξ±) β†’ (βˆ€ u, C (oa u)) β†’ C (query i t >>= oa))\n (failure : C failure) : C oa :=\n FreeMonad.inductionOn (Option.rec failure pure) (Ξ» (query i t) ↦ query_bind i t) oa" }, { "name": "inductionOn", "content": "@[elab_as_elim]\nprotected def inductionOn {C : FreeMonad f Ξ± β†’ Prop}\n (pure : βˆ€ x, C (pure x))\n (roll : βˆ€ {Ξ²} (x : f Ξ²), (r : Ξ² β†’ FreeMonad f Ξ±) β†’\n (βˆ€ y, C (r y)) β†’ C (x >>= r)) :\n (oa : FreeMonad f Ξ±) β†’ C oa\n | FreeMonad.pure x => pure x\n | FreeMonad.roll x r => roll x _ (Ξ» u ↦\n FreeMonad.inductionOn pure roll (r u))" }, { "name": "construct", "content": "@[elab_as_elim]\nprotected def construct {C : OracleComp spec Ξ± β†’ Type*}\n (pure : (a : Ξ±) β†’ C (pure a))\n (query_bind : {Ξ² : Type v} β†’ (q : OracleQuery spec Ξ²) β†’\n (oa : Ξ² β†’ OracleComp spec Ξ±) β†’ ((u : Ξ²) β†’ C (oa u)) β†’ C (q >>= oa))\n (failure : C failure) (oa : OracleComp spec Ξ±) : C oa :=\n FreeMonad.construct (Option.rec failure pure) query_bind oa" }, { "name": "construct", "content": "@[elab_as_elim]\nprotected def construct {C : FreeMonad f Ξ± β†’ Type*}\n (pure : (x : Ξ±) β†’ C (pure x))\n (roll : {Ξ² : Type u} β†’ (x : f Ξ²) β†’ (r : Ξ² β†’ FreeMonad f Ξ±) β†’\n ((y : Ξ²) β†’ C (r y)) β†’ C (x >>= r)) :\n (oa : FreeMonad f Ξ±) β†’ C oa\n | .pure x => pure x\n | .roll x r => roll x _ (Ξ» u ↦ FreeMonad.construct pure roll (r u))" }, { "name": "FiniteRange", "content": "class FiniteRange (spec : OracleSpec ΞΉ) where\n range_inhabited' (i : ΞΉ) : Inhabited (spec.range i)\n range_fintype' (i : ΞΉ) : Fintype (spec.range i)" }, { "name": "inductionOn", "content": "@[elab_as_elim]\nprotected def inductionOn {C : OracleComp spec Ξ± β†’ Prop}\n (pure : (a : Ξ±) β†’ C (pure a))\n (query_bind : (i : ΞΉ) β†’ (t : spec.domain i) β†’\n (oa : spec.range i β†’ OracleComp spec Ξ±) β†’ (βˆ€ u, C (oa u)) β†’ C (query i t >>= oa))\n (failure : C failure) (oa : OracleComp spec Ξ±) : C oa :=\n FreeMonad.inductionOn (Option.rec failure pure) (Ξ» (query i t) ↦ query_bind i t) oa" }, { "name": "probEvent", "content": "noncomputable def probEvent (oa : OracleComp spec Ξ±) (p : Ξ± β†’ Prop) : ℝβ‰₯0∞ :=\n (evalDist oa).run.toOuterMeasure (Option.some '' {x | p x})" }, { "name": "cases", "content": "def cases {Ξ±} {motive : {n : β„•} β†’ Vector Ξ± n β†’ Sort*} (v_empty : motive #v[])\n (v_insert : {n : β„•} β†’ (hd : Ξ±) β†’ (tl : Vector Ξ± n) β†’ motive (tl.insertIdx 0 hd)) {m : β„•} :\n (v : Vector Ξ± m) β†’ motive v := match hm : m with\n | 0 => fun v => match v with | ⟨⟨[]⟩, rfl⟩ => v_empty\n | n + 1 => fun v => match hv : v with\n | ⟨⟨hd :: tl⟩, hSize⟩ => by admit /- proof elided -/" }, { "name": "probFailure", "content": "noncomputable def probFailure (oa : OracleComp spec Ξ±) : ℝβ‰₯0∞ :=\n (evalDist oa).run none" }, { "name": "uniformFin", "content": "@[reducible, inline] def uniformFin (n : β„•) : ProbComp (Fin (n + 1)) :=\n unifSpec.query n ()" }, { "name": "ProbComp", "content": "abbrev ProbComp : Type z β†’ Type (max z 1) := OracleComp unifSpec" }, { "name": "unifSpec", "content": "@[inline, reducible] def unifSpec : OracleSpec.{0,0} β„• :=\n Ξ» n ↦ (Unit, Fin (n + 1))" }, { "name": "uniformFin'", "content": "@[reducible, inline] def uniformFin' (n m : β„•) : OracleComp probSpec (Fin (m + 1)) :=\n probSpec.query m n" }, { "name": "probSpec", "content": "def probSpec : OracleSpec.{0,0} β„• :=\n fun n => (β„•, Fin (n + 1))" }, { "name": "probOutput", "content": "notation \"Pr[=\" x \"|\" mx \"]\" => probOutput mx x" }, { "name": "probEvent", "content": "notation \"Pr[\" p \"|\" mx \"]\" => probEvent mx p" }, { "name": "probFailure", "content": "notation \"Pr[βŠ₯\" \"|\" mx \"]\" => probFailure mx" }, { "name": "probOutput", "content": "notation \"[=\" x \"|\" oa \"]\" => probOutput oa x" }, { "name": "probFailure", "content": "notation \"[βŠ₯\" \"|\" oa \"]\" => probFailure oa" }, { "name": "probEvent", "content": "notation \"[\" p \"|\" oa \"]\" => probEvent oa p" }, { "name": "uniformFin", "content": "notation \"$[0..\" n \"]\" => uniformFin n" }, { "name": "notation:50 \"$[\" n \"β‹―\" m \"]\" => uniformFin' n m", "content": "notation:50 \"$[\" n \"β‹―\" m \"]\" => uniformFin' n m\n\nexample : OracleComp probSpec β„• := do\n let x ← $[314β‹―31415]; let y ← $[0β‹―x]\n return x + 2 * y" } ]
[ { "name": "ENNReal.tsum_mul_left", "module": "Mathlib.Topology.Instances.ENNReal.Lemmas" }, { "name": "map_eq_bind_pure_comp", "module": "Mathlib.Control.Monad.Basic" }, { "name": "mul_assoc", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "seq_eq_bind", "module": "Init.Control.Lawful.Basic" }, { "name": "ENNReal.tsum_prod", "module": "Mathlib.Topology.Instances.ENNReal.Lemmas" }, { "name": "Prod.eq_iff_fst_eq_snd_eq", "module": "Mathlib.Data.Prod.Basic" }, { "name": "mul_one", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "tsum_eq_single", "module": "Mathlib.Topology.Algebra.InfiniteSum.Basic" }, { "name": "seq_eq_bind_map", "module": "Init.Control.Lawful.Basic" }, { "name": "Set.biUnion_and'", "module": "Mathlib.Data.Set.Lattice" }, { "name": "Set.ext_iff", "module": "Mathlib.Data.Set.Defs" }, { "name": "Set.iUnion_exists", "module": "Mathlib.Data.Set.Lattice" }, { "name": "Set.iUnion_iUnion_eq_right", "module": "Mathlib.Data.Set.Lattice" }, { "name": "Set.mem_iUnion", "module": "Mathlib.Order.SetNotation" }, { "name": "Set.mem_image", "module": "Mathlib.Data.Set.Operations" }, { "name": "Set.mem_image2", "module": "Mathlib.Data.Set.Operations" }, { "name": "exists_prop", "module": "Init.PropLemmas" }, { "name": "implies_true", "module": "Init.SimpLemmas" }, { "name": "Function.uncurry_apply_pair", "module": "Init.Data.Function" }, { "name": "Functor.map_map", "module": "Init.Control.Lawful.Basic" }, { "name": "Set.image2_mk_eq_prod", "module": "Mathlib.Data.Set.NAry" }, { "name": "Set.image_uncurry_prod", "module": "Mathlib.Data.Set.NAry" }, { "name": "congr_arg", "module": "Batteries.Logic" }, { "name": "map_seq", "module": "Mathlib.Control.Basic" }, { "name": "ENNReal.tsum_mul_right", "module": "Mathlib.Topology.Instances.ENNReal.Lemmas" }, { "name": "ENNReal.tsum_prod'", "module": "Mathlib.Topology.Instances.ENNReal.Lemmas" }, { "name": "ite_mul", "module": "Mathlib.Algebra.Notation.Defs" }, { "name": "tsum_congr", "module": "Mathlib.Topology.Algebra.InfiniteSum.Basic" } ]
[ { "name": "probOutput_bind_eq_tsum", "content": "lemma probOutput_bind_eq_tsum (y : Ξ²) :\n [= y | oa >>= ob] = βˆ‘' x : Ξ±, [= x | oa] * [= y | ob x]" }, { "name": "probEvent_pure", "content": "@[simp]\nlemma probEvent_pure (p : Ξ± β†’ Prop) [DecidablePred p] :\n [p | (pure x : OracleComp spec Ξ±)] = if p x then 1 else 0" }, { "name": "probOutput_pure_self", "content": "@[simp]\nlemma probOutput_pure_self (x : Ξ±) : [= x | (pure x : OracleComp spec Ξ±)] = 1" }, { "name": "support_map", "content": "@[simp] lemma support_map (oa : OracleComp spec Ξ±) (f : Ξ± β†’ Ξ²) :\n (f <$> oa).support = f '' oa.support" }, { "name": "support_bind", "content": "@[simp] lemma support_bind (oa : OracleComp spec Ξ±) (ob : Ξ± β†’ OracleComp spec Ξ²) :\n (oa >>= ob).support = ⋃ x ∈ oa.support, (ob x).support" }, { "name": "support_pure", "content": "@[simp] lemma support_pure (x : Ξ±) :\n (pure x : OracleComp spec Ξ±).support = {x}" }, { "name": "probEvent_congr'", "content": "lemma probEvent_congr' {p q : Ξ± β†’ Prop} {oa : OracleComp spec Ξ±} {oa' : OracleComp spec' Ξ±}\n (h1 : βˆ€ x, x ∈ oa.support β†’ x ∈ oa'.support β†’ (p x ↔ q x))\n (h2 : evalDist oa = evalDist oa') : [p | oa] = [q | oa']" }, { "name": "mem_support_iff_of_evalDist_eq", "content": "lemma mem_support_iff_of_evalDist_eq {oa : OracleComp spec Ξ±} {oa' : OracleComp spec' Ξ±}\n (h : evalDist oa = evalDist oa') (x : Ξ±) : x ∈ oa.support ↔ x ∈ oa'.support" }, { "name": "mem_support_iff_probOutput_ne_zero", "content": "lemma mem_support_iff_probOutput_ne_zero : x ∈ oa.support ↔ [= x | oa] β‰  0" }, { "name": "probOutput_eq_zero_iff", "content": "@[simp low]\nlemma probOutput_eq_zero_iff : [= x | oa] = 0 ↔ x βˆ‰ oa.support" }, { "name": "mem_support_evalDist_iff", "content": "@[simp]\nlemma mem_support_evalDist_iff (oa : OracleComp spec Ξ±) (x : Ξ±) :\n some x ∈ (evalDist oa).run.support ↔ x ∈ oa.support" }, { "name": "probOutput_def", "content": "lemma probOutput_def (oa : OracleComp spec Ξ±) (x : Ξ±) :\n [= x | oa] = (evalDist oa).run (some x)" }, { "name": "probEvent_eq_tsum_indicator", "content": "lemma probEvent_eq_tsum_indicator (oa : OracleComp spec Ξ±) (p : Ξ± β†’ Prop) :\n [p | oa] = βˆ‘' x : Ξ±, {x | p x}.indicator ([= Β· | oa]) x" }, { "name": "probEvent_def", "content": "lemma probEvent_def (oa : OracleComp spec Ξ±) (p : Ξ± β†’ Prop) :\n [p | oa] = (evalDist oa).run.toOuterMeasure (Option.some '' {x | p x})" }, { "name": "probOutput_congr", "content": "lemma probOutput_congr {x y : Ξ±} {oa : OracleComp spec Ξ±} {oa' : OracleComp spec' Ξ±}\n (h1 : x = y) (h2 : evalDist oa = evalDist oa') : [= x | oa] = [= y | oa']" }, { "name": "probEvent_comp", "content": "lemma probEvent_comp (q : Ξ² β†’ Prop) : [q ∘ f | oa] = [q | f <$> oa]" }, { "name": "probEvent_map", "content": "@[simp]\nlemma probEvent_map (q : Ξ² β†’ Prop) : [q | f <$> oa] = [q ∘ f | oa]" }, { "name": "evalDist_map", "content": "@[simp]\nlemma evalDist_map (oa : OracleComp spec Ξ±) (f : Ξ± β†’ Ξ²) :\n evalDist (f <$> oa) = f <$> (evalDist oa)" }, { "name": "probEvent_eq_tsum_ite", "content": "lemma probEvent_eq_tsum_ite (oa : OracleComp spec Ξ±) (p : Ξ± β†’ Prop) [DecidablePred p] :\n [p | oa] = βˆ‘' x : Ξ±, if p x then [= x | oa] else 0" }, { "name": "probEvent_ext", "content": "lemma probEvent_ext (h : βˆ€ x ∈ oa.support, p x ↔ q x) : [p | oa] = [q | oa]" }, { "name": "probEvent_mono", "content": "lemma probEvent_mono (h : βˆ€ x ∈ oa.support, p x β†’ q x) : [p | oa] ≀ [q | oa]" }, { "name": "evalDist_apply_eq_zero_iff", "content": "@[simp]\nlemma evalDist_apply_eq_zero_iff (x : Option Ξ±) :\n (evalDist oa).run x = 0 ↔ x.rec ([βŠ₯ | oa] = 0) (Β· βˆ‰ oa.support)" }, { "name": "probFailure_def", "content": "lemma probFailure_def (oa : OracleComp spec Ξ±) :\n [βŠ₯ | oa] = (evalDist oa).run none" }, { "name": "Prod.mk.injective2", "content": "lemma Prod.mk.injective2 {Ξ± Ξ² : Type*} :\n Function.Injective2 (Prod.mk : Ξ± β†’ Ξ² β†’ Ξ± Γ— Ξ²)" }, { "name": "probEvent_bind_eq_tsum", "content": "lemma probEvent_bind_eq_tsum (q : Ξ² β†’ Prop) :\n [q | oa >>= ob] = βˆ‘' x : Ξ±, [= x | oa] * [q | ob x]" } ]
[]
[ { "name": "OracleComp.support_seq", "content": "@[simp low]\nlemma support_seq : (og <*> oa).support = ⋃ g ∈ og.support, g '' oa.support" }, { "name": "OracleComp.support_seq_map_eq_image2", "content": "@[simp low + 1]\nlemma support_seq_map_eq_image2 :\n (f <$> oa <*> ob).support = Set.image2 f oa.support ob.support" }, { "name": "OracleComp.probOutput_seq_map_eq_tsum", "content": "lemma probOutput_seq_map_eq_tsum [spec.FiniteRange]\n (z : Ξ³) : [= z | f <$> oa <*> ob] = βˆ‘' (x : Ξ±) (y : Ξ²),\n [= x | oa] * [= y | ob] * [= z | (pure (f x y) : OracleComp spec Ξ³)]" }, { "name": "OracleComp.probEvent_seq_map_eq_probEvent_comp_uncurry", "content": "lemma probEvent_seq_map_eq_probEvent_comp_uncurry [spec.FiniteRange]\n (p : Ξ³ β†’ Prop) : [p | f <$> oa <*> ob] =\n [p ∘ f.uncurry | Prod.mk <$> oa <*> ob]" }, { "name": "OracleComp.probEvent_seq_map_eq_probEvent", "content": "lemma probEvent_seq_map_eq_probEvent [spec.FiniteRange] (p : Ξ³ β†’ Prop) :\n [p | f <$> oa <*> ob] = [Ξ» z ↦ p (f z.1 z.2) | Prod.mk <$> oa <*> ob]" }, { "name": "OracleComp.probOutput_seq_map_eq_mul_of_injective2", "content": "lemma probOutput_seq_map_eq_mul_of_injective2 [spec.FiniteRange]\n (hf : f.Injective2) (x : Ξ±) (y : Ξ²) :\n [= f x y | f <$> oa <*> ob] = [= x | oa] * [= y | ob]" } ]
import VCVio.OracleComp.DistSemantics.Monad namespace OracleComp variable {ΞΉ : Type u} {spec : OracleSpec ΞΉ} {Ξ± Ξ² Ξ³ : Type v} variable (oa : OracleComp spec Ξ±) (og : OracleComp spec (Ξ± β†’ Ξ²)) section seq_map variable (oa : OracleComp spec Ξ±) (ob : OracleComp spec Ξ²) (f : Ξ± β†’ Ξ² β†’ Ξ³) section swap end swap section injective2 end injective2
lemma probEvent_seq_map_eq_mul {ΞΉ : Type u} {spec : OracleSpec ΞΉ} {Ξ± Ξ² Ξ³ : Type v} (f : Ξ± β†’ Ξ² β†’ Ξ³) [spec.FiniteRange] (oa : OracleComp spec Ξ±) (ob : OracleComp spec Ξ²) (p : Ξ³ β†’ Prop) (q1 : Ξ± β†’ Prop) (q2 : Ξ² β†’ Prop) (h : βˆ€ x ∈ oa.support, βˆ€ y ∈ ob.support, p (f x y) ↔ q1 x ∧ q2 y) : [p | f <$> oa <*> ob] = [q1 | oa] * [q2 | ob] :=
:= by have : DecidablePred q1 := Classical.decPred q1 have : DecidablePred q2 := Classical.decPred q2 rw [probEvent_seq_map_eq_probEvent] calc [Ξ» z : Ξ± Γ— Ξ² ↦ p (f z.1 z.2) | Prod.mk <$> oa <*> ob] = [Ξ» z ↦ q1 z.1 ∧ q2 z.2 | Prod.mk <$> oa <*> ob] := probEvent_ext <| by simpa using Ξ» x y hx hy ↦ h x hx y hy _ = βˆ‘' (x : Ξ±) (y : Ξ²), if q1 x ∧ q2 y then [= (x, y) | Prod.mk <$> oa <*> ob] else 0 := by rw [probEvent_eq_tsum_ite, ENNReal.tsum_prod'] _ = βˆ‘' (x : Ξ±) (y : Ξ²), if q1 x ∧ q2 y then [= x | oa] * [= y | ob] else 0 := by simp_rw [probOutput_seq_map_eq_mul_of_injective2 oa ob Prod.mk Prod.mk.injective2] _ = βˆ‘' x : Ξ±, if q1 x then [= x | oa] * (βˆ‘' y : Ξ², if q2 y then [= y | ob] else 0) else 0 := tsum_congr (Ξ» x ↦ by by_cases hx : q1 x <;> simp [hx, ← ENNReal.tsum_mul_left]) _ = βˆ‘' x : Ξ±, if q1 x then [= x | oa] * [q2 | ob] else 0 := by rw [probEvent_eq_tsum_ite] _ = [q1 | oa] * [q2 | ob] := by simp only [probEvent_eq_tsum_ite oa, ← ENNReal.tsum_mul_right, ite_mul, zero_mul]
8
96
true
Applied verif.
454
PMF.probOutput_eq
@[simp] lemma probOutput_eq : probOutput p = p
VCV-io
VCVio/EvalDist/Basic.lean
[ "import ToMathlib.General", "import Mathlib.Probability.ProbabilityMassFunction.Monad" ]
[ { "name": "OptionT", "module": "Init.Control.Option" }, { "name": "PMF", "module": "Mathlib.Probability.ProbabilityMassFunction.Basic" }, { "name": "Monad", "module": "Init.Prelude" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "liftM", "module": "Init.Prelude" }, { "name": "Pure", "module": "Init.Prelude" }, { "name": "id", "module": "Init.Prelude" } ]
[ { "name": "probEvent", "content": "notation \"Pr[\" p \"|\" mx \"]\" => probEvent mx p" }, { "name": "probOutput", "content": "notation \"Pr[=\" x \"|\" mx \"]\" => probOutput mx x" }, { "name": "macro_rules (kind := probEventBinding1)", "content": "macro_rules (kind := probEventBinding1)\n | `(Pr[$cond:term | $var:ident ← $src:term]) => `(Pr[fun $var => $cond | $src])" }, { "name": "macro_rules (kind := probEventBinding2)", "content": "macro_rules (kind := probEventBinding2)\n \n | `(Pr{{$items*}}[$t]) => `(probOutput (do $items:doSeqItem* return $t:term) True)\n \n | `(Pr{$items*}[$t]) => `(probOutput (do $items:doSeqItem* return $t:term) True)" }, { "name": "probOutput", "content": "notation \"[=\" x \"|\" oa \"]\" => probOutput oa x" }, { "name": "probEvent", "content": "notation \"[\" p \"|\" oa \"]\" => probEvent oa p" } ]
[ { "name": "OptionT.run_mk", "module": "Init.Control.Lawful.Instances" }, { "name": "PMF.map_apply", "module": "Mathlib.Probability.ProbabilityMassFunction.Constructions" }, { "name": "PMF.pure_apply", "module": "Mathlib.Probability.ProbabilityMassFunction.Monad" }, { "name": "mul_ite", "module": "Mathlib.Algebra.Notation.Defs" }, { "name": "mul_one", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "tsum_eq_single", "module": "Mathlib.Topology.Algebra.InfiniteSum.Basic" } ]
[ { "name": "PMF.monad_pure_eq_pure", "content": "@[simp]\nlemma PMF.monad_pure_eq_pure {Ξ± : Type u} (x : Ξ±) :\n (Pure.pure x : PMF Ξ±) = PMF.pure x" }, { "name": "PMF.monad_bind_eq_bind", "content": "@[simp]\nlemma PMF.monad_bind_eq_bind {Ξ± Ξ² : Type u}\n (p : PMF Ξ±) (q : Ξ± β†’ PMF Ξ²) : p >>= q = p.bind q" } ]
[ { "name": "SPMF", "content": "@[reducible] def SPMF : Type u β†’ Type u := OptionT PMF" }, { "name": "HasEvalDist", "content": "class HasEvalDist (m : Type u β†’ Type v) [Monad m] where\n evalDist {Ξ± : Type u} (mx : m Ξ±) : SPMF Ξ±\n evalDist_pure {Ξ± : Type u} (x : Ξ±) : evalDist (pure x : m Ξ±) = pure x\n evalDist_bind {Ξ± Ξ² : Type u} (mx : m Ξ±) (my : Ξ± β†’ m Ξ²) :\n evalDist (mx >>= my) = evalDist mx >>= fun x => evalDist (my x)" }, { "name": "probOutput", "content": "def probOutput [HasEvalDist m] (mx : m Ξ±) (x : Ξ±) : ℝβ‰₯0∞ := evalDist mx x" }, { "name": "probEvent", "content": "noncomputable def probEvent [HasEvalDist m] (mx : m Ξ±) (p : Ξ± β†’ Prop) : ℝβ‰₯0∞ :=\n (evalDist mx).run.toOuterMeasure (some '' {x | p x})" }, { "name": "SPMF.hasEvalDist", "content": "instance hasEvalDist : HasEvalDist SPMF where\n evalDist := id\n evalDist_pure _ := rfl\n evalDist_bind _ _ := rfl" }, { "name": "PMF.hasEvalDist", "content": "noncomputable instance hasEvalDist : HasEvalDist PMF where\n evalDist p := OptionT.mk p\n evalDist_pure _ := by admit /- proof elided -/" } ]
[ { "name": "probOutput_def", "content": "lemma probOutput_def (mx : m Ξ±) (x : Ξ±) : Pr[= x | mx] = (evalDist mx).run (some x)" }, { "name": "PMF.evalDist_eq", "content": "@[simp] lemma evalDist_eq : evalDist p = liftM p" } ]
import Mathlib.Probability.ProbabilityMassFunction.Monad import ToMathlib.General open ENNReal variable {Ξ± Ξ² Ξ³ : Type u} {m : Type u β†’ Type v} [Monad m] @[reducible] def SPMF : Type u β†’ Type u := OptionT PMF namespace SPMF end SPMF class HasEvalDist (m : Type u β†’ Type v) [Monad m] where evalDist {Ξ± : Type u} (mx : m Ξ±) : SPMF Ξ± evalDist_pure {Ξ± : Type u} (x : Ξ±) : evalDist (pure x : m Ξ±) = pure x evalDist_bind {Ξ± Ξ² : Type u} (mx : m Ξ±) (my : Ξ± β†’ m Ξ²) : evalDist (mx >>= my) = evalDist mx >>= fun x => evalDist (my x) def probOutput [HasEvalDist m] (mx : m Ξ±) (x : Ξ±) : ℝβ‰₯0∞ := evalDist mx x noncomputable def probEvent [HasEvalDist m] (mx : m Ξ±) (p : Ξ± β†’ Prop) : ℝβ‰₯0∞ := (evalDist mx).run.toOuterMeasure (some '' {x | p x}) notation "Pr[=" x "|" mx "]" => probOutput mx x notation "Pr[" p "|" mx "]" => probEvent mx p notation "Pr[βŠ₯" "|" mx "]" => probFailure mx variable [HasEvalDist m] section sums end sums section bounds variable {mx : m Ξ±} {mxe : OptionT m Ξ±} {x : Ξ±} {p : Ξ± β†’ Prop} end bounds section bind variable (mx : m Ξ±) (my : Ξ± β†’ m Ξ²) end bind namespace SPMF instance hasEvalDist : HasEvalDist SPMF where evalDist := id evalDist_pure _ := rfl evalDist_bind _ _ := rfl variable (p : SPMF Ξ±) (x : Ξ±) end SPMF namespace PMF noncomputable instance hasEvalDist : HasEvalDist PMF where evalDist p := OptionT.mk p evalDist_pure _ := by admit /- proof elided -/ variable (p : PMF Ξ±) (x : Ξ±)
@[simp] lemma probOutput_eq : probOutput p = p :=
:= by refine funext fun x => ?_ simp only [probOutput_def, evalDist_eq, monad_pure_eq_pure, monad_bind_eq_bind, OptionT.run_mk, pure_apply, Option.some.injEq, mul_ite, mul_one, mul_zero] simp refine (PMF.map_apply _ _ _).trans ?_ refine (tsum_eq_single x ?_).trans ?_ Β· simp refine fun x h h' => ?_ refine (h h'.symm).elim simp only [↓reduceIte]
2
20
true
Applied verif.
455
OracleComp.probEvent_congr'
lemma probEvent_congr' {p q : Ξ± β†’ Prop} {oa : OracleComp spec Ξ±} {oa' : OracleComp spec' Ξ±} (h1 : βˆ€ x, x ∈ oa.support β†’ x ∈ oa'.support β†’ (p x ↔ q x)) (h2 : evalDist oa = evalDist oa') : [p | oa] = [q | oa']
VCV-io
VCVio/OracleComp/DistSemantics/EvalDist.lean
[ "import Mathlib.Probability.Distributions.Uniform", "import VCVio.OracleComp.SimSemantics.SimulateQ", "import VCVio.OracleComp.Traversal", "import ToMathlib.General" ]
[ { "name": "inline", "module": "Init.Core" }, { "name": "OptionT", "module": "Init.Control.Option" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "Set", "module": "Mathlib.Data.Set.Defs" }, { "name": "Set.univ", "module": "Mathlib.Data.Set.Defs" }, { "name": "Set.indicator", "module": "Mathlib.Algebra.Notation.Indicator" }, { "name": "PMF", "module": "Mathlib.Probability.ProbabilityMassFunction.Basic" }, { "name": "Option.elimM", "module": "Init.Data.Option.Basic" }, { "name": "OptionT.lift", "module": "Init.Control.Option" }, { "name": "ENNReal", "module": "Mathlib.Data.ENNReal.Basic" }, { "name": "Vector", "module": "Init.Data.Vector.Basic" }, { "name": "Vector.insertIdx", "module": "Init.Data.Vector.Basic" }, { "name": "AddCommMonoid", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "ContinuousAdd", "module": "Mathlib.Topology.Algebra.Monoid.Defs" }, { "name": "Function.update", "module": "Mathlib.Logic.Function.Basic" }, { "name": "Summable", "module": "Mathlib.Topology.Algebra.InfiniteSum.Defs" }, { "name": "T2Space", "module": "Mathlib.Topology.Separation.Hausdorff" }, { "name": "TopologicalSpace", "module": "Mathlib.Topology.Defs.Basic" } ]
[ { "name": "probOutput", "content": "notation \"[=\" x \"|\" oa \"]\" => probOutput oa x" }, { "name": "HasEvalDist", "content": "class HasEvalDist (m : Type u β†’ Type v) [Monad m] where\n evalDist {Ξ± : Type u} (mx : m Ξ±) : SPMF Ξ±\n evalDist_pure {Ξ± : Type u} (x : Ξ±) : evalDist (pure x : m Ξ±) = pure x\n evalDist_bind {Ξ± Ξ² : Type u} (mx : m Ξ±) (my : Ξ± β†’ m Ξ²) :\n evalDist (mx >>= my) = evalDist mx >>= fun x => evalDist (my x)" }, { "name": "OracleComp", "content": "def OracleComp {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) :\n Type w β†’ Type (max u (v + 1) w) :=\n OptionT (FreeMonad (OracleQuery.{u,v} spec))" }, { "name": "OracleQuery", "content": "inductive OracleQuery {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) : Type v β†’ Type (max u v)\n | query (i : ΞΉ) (t : spec.domain i) : OracleQuery spec (spec.range i)" }, { "name": "domain", "content": "@[inline, reducible]\nprotected def domain (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type v := (spec i).1" }, { "name": "OracleSpec", "content": "def OracleSpec (ΞΉ : Type u) : Type (max u (v + 1)) :=\n (i : ΞΉ) β†’ Type v Γ— Type v" }, { "name": "range", "content": "@[inline, reducible]\nprotected def range (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type w := (spec i).2" }, { "name": "FreeMonad", "content": "inductive FreeMonad (f : Type u β†’ Type v) (Ξ± : Type w) : Type (max (u + 1) v w)\n | protected pure (x : Ξ±) : FreeMonad f Ξ±\n | roll {Ξ² : Type u} (x : f Ξ²) (r : Ξ² β†’ FreeMonad f Ξ±) : FreeMonad f Ξ±" }, { "name": "support", "content": "def support (oa : OracleComp spec Ξ±) : Set Ξ± :=\n oa.supportWhen fun _ => Set.univ" }, { "name": "supportWhen", "content": "def supportWhen (oa : OracleComp spec Ξ±)\n (possible_outputs : {Ξ± : Type v} β†’ OracleQuery spec Ξ± β†’ Set Ξ±) : Set Ξ± :=" }, { "name": "induction", "content": "@[elab_as_elim]\nprotected def induction {C : OracleComp spec Ξ± β†’ Prop}\n (oa : OracleComp spec Ξ±) (pure : (a : Ξ±) β†’ C (pure a))\n (query_bind : (i : ΞΉ) β†’ (t : spec.domain i) β†’\n (oa : spec.range i β†’ OracleComp spec Ξ±) β†’ (βˆ€ u, C (oa u)) β†’ C (query i t >>= oa))\n (failure : C failure) : C oa :=\n FreeMonad.inductionOn (Option.rec failure pure) (Ξ» (query i t) ↦ query_bind i t) oa" }, { "name": "inductionOn", "content": "@[elab_as_elim]\nprotected def inductionOn {C : FreeMonad f Ξ± β†’ Prop}\n (pure : βˆ€ x, C (pure x))\n (roll : βˆ€ {Ξ²} (x : f Ξ²), (r : Ξ² β†’ FreeMonad f Ξ±) β†’\n (βˆ€ y, C (r y)) β†’ C (x >>= r)) :\n (oa : FreeMonad f Ξ±) β†’ C oa\n | FreeMonad.pure x => pure x\n | FreeMonad.roll x r => roll x _ (Ξ» u ↦\n FreeMonad.inductionOn pure roll (r u))" }, { "name": "construct", "content": "@[elab_as_elim]\nprotected def construct {C : OracleComp spec Ξ± β†’ Type*}\n (pure : (a : Ξ±) β†’ C (pure a))\n (query_bind : {Ξ² : Type v} β†’ (q : OracleQuery spec Ξ²) β†’\n (oa : Ξ² β†’ OracleComp spec Ξ±) β†’ ((u : Ξ²) β†’ C (oa u)) β†’ C (q >>= oa))\n (failure : C failure) (oa : OracleComp spec Ξ±) : C oa :=\n FreeMonad.construct (Option.rec failure pure) query_bind oa" }, { "name": "construct", "content": "@[elab_as_elim]\nprotected def construct {C : FreeMonad f Ξ± β†’ Type*}\n (pure : (x : Ξ±) β†’ C (pure x))\n (roll : {Ξ² : Type u} β†’ (x : f Ξ²) β†’ (r : Ξ² β†’ FreeMonad f Ξ±) β†’\n ((y : Ξ²) β†’ C (r y)) β†’ C (x >>= r)) :\n (oa : FreeMonad f Ξ±) β†’ C oa\n | .pure x => pure x\n | .roll x r => roll x _ (Ξ» u ↦ FreeMonad.construct pure roll (r u))" }, { "name": "inductionOn", "content": "@[elab_as_elim]\nprotected def inductionOn {C : OracleComp spec Ξ± β†’ Prop}\n (pure : (a : Ξ±) β†’ C (pure a))\n (query_bind : (i : ΞΉ) β†’ (t : spec.domain i) β†’\n (oa : spec.range i β†’ OracleComp spec Ξ±) β†’ (βˆ€ u, C (oa u)) β†’ C (query i t >>= oa))\n (failure : C failure) (oa : OracleComp spec Ξ±) : C oa :=\n FreeMonad.inductionOn (Option.rec failure pure) (Ξ» (query i t) ↦ query_bind i t) oa" }, { "name": "cases", "content": "def cases {Ξ±} {motive : {n : β„•} β†’ Vector Ξ± n β†’ Sort*} (v_empty : motive #v[])\n (v_insert : {n : β„•} β†’ (hd : Ξ±) β†’ (tl : Vector Ξ± n) β†’ motive (tl.insertIdx 0 hd)) {m : β„•} :\n (v : Vector Ξ± m) β†’ motive v := match hm : m with\n | 0 => fun v => match v with | ⟨⟨[]⟩, rfl⟩ => v_empty\n | n + 1 => fun v => match hv : v with\n | ⟨⟨hd :: tl⟩, hSize⟩ => by admit /- proof elided -/" } ]
[ { "name": "PMF.apply_eq_zero_iff", "module": "Mathlib.Probability.ProbabilityMassFunction.Basic" }, { "name": "ne_eq", "module": "Init.SimpLemmas" }, { "name": "ENNReal.summable", "module": "Mathlib.Topology.Instances.ENNReal.Lemmas" }, { "name": "Option.some_injective", "module": "Mathlib.Data.Option.Basic" }, { "name": "PMF.toOuterMeasure_apply", "module": "Mathlib.Probability.ProbabilityMassFunction.Basic" }, { "name": "Set.indicator_image", "module": "Mathlib.Algebra.Notation.Indicator" }, { "name": "if_neg", "module": "Init.Core" }, { "name": "tsum_congr", "module": "Mathlib.Topology.Algebra.InfiniteSum.Basic" } ]
[ { "name": "tsum_option", "content": "lemma tsum_option {Ξ± Ξ² : Type*} [AddCommMonoid Ξ±] [TopologicalSpace Ξ±]\n [ContinuousAdd Ξ±] [T2Space Ξ±]\n (f : Option Ξ² β†’ Ξ±) (hf : Summable (Function.update f none 0)) :\n βˆ‘' x : Option Ξ², f x = f none + βˆ‘' x : Ξ², f (some x)" } ]
[ { "name": "OracleComp.probOutput", "content": "noncomputable def probOutput (oa : OracleComp spec Ξ±) (x : Ξ±) : ℝβ‰₯0∞ :=\n (evalDist oa).run (some x)" } ]
[ { "name": "OracleComp.probOutput_def", "content": "lemma probOutput_def (oa : OracleComp spec Ξ±) (x : Ξ±) :\n [= x | oa] = (evalDist oa).run (some x)" }, { "name": "OracleComp.probEvent_def", "content": "lemma probEvent_def (oa : OracleComp spec Ξ±) (p : Ξ± β†’ Prop) :\n [p | oa] = (evalDist oa).run.toOuterMeasure (Option.some '' {x | p x})" }, { "name": "OracleComp.probEvent_eq_tsum_indicator", "content": "lemma probEvent_eq_tsum_indicator (oa : OracleComp spec Ξ±) (p : Ξ± β†’ Prop) :\n [p | oa] = βˆ‘' x : Ξ±, {x | p x}.indicator ([= Β· | oa]) x" }, { "name": "OracleComp.mem_support_evalDist_iff", "content": "@[simp]\nlemma mem_support_evalDist_iff (oa : OracleComp spec Ξ±) (x : Ξ±) :\n some x ∈ (evalDist oa).run.support ↔ x ∈ oa.support" }, { "name": "OracleComp.probOutput_eq_zero_iff", "content": "@[simp low]\nlemma probOutput_eq_zero_iff : [= x | oa] = 0 ↔ x βˆ‰ oa.support" }, { "name": "OracleComp.mem_support_iff_probOutput_ne_zero", "content": "lemma mem_support_iff_probOutput_ne_zero : x ∈ oa.support ↔ [= x | oa] β‰  0" }, { "name": "OracleComp.mem_support_iff_of_evalDist_eq", "content": "lemma mem_support_iff_of_evalDist_eq {oa : OracleComp spec Ξ±} {oa' : OracleComp spec' Ξ±}\n (h : evalDist oa = evalDist oa') (x : Ξ±) : x ∈ oa.support ↔ x ∈ oa'.support" }, { "name": "OracleComp.probOutput_congr", "content": "lemma probOutput_congr {x y : Ξ±} {oa : OracleComp spec Ξ±} {oa' : OracleComp spec' Ξ±}\n (h1 : x = y) (h2 : evalDist oa = evalDist oa') : [= x | oa] = [= y | oa']" } ]
import VCVio.OracleComp.Traversal import VCVio.OracleComp.SimSemantics.SimulateQ import Mathlib.Probability.Distributions.Uniform import ToMathlib.General open OracleSpec Option ENNReal BigOperators namespace OracleComp variable {ΞΉ : Type u} {spec : OracleSpec ΞΉ} {ΞΉ' : Type v} {spec' : OracleSpec ΞΉ'} {Ξ± Ξ² Ξ³ : Type w} [spec.FiniteRange] [spec'.FiniteRange] section evalDist end evalDist noncomputable def probOutput (oa : OracleComp spec Ξ±) (x : Ξ±) : ℝβ‰₯0∞ := (evalDist oa).run (some x) notation "[=" x "|" oa "]" => probOutput oa x notation "[βŠ₯" "|" oa "]" => probFailure oa notation "[" p "|" oa "]" => probEvent oa p section bounds variable {oa : OracleComp spec Ξ±} {x : Ξ±} {p : Ξ± β†’ Prop} end bounds section support variable (oa : OracleComp spec Ξ±) (x : Ξ±) (p q : Ξ± β†’ Prop) variable {oa x p q} end support section sums variable (oa : OracleComp spec Ξ±) (p : Ξ± β†’ Prop) end sums
lemma probEvent_congr' {p q : Ξ± β†’ Prop} {oa : OracleComp spec Ξ±} {oa' : OracleComp spec' Ξ±} (h1 : βˆ€ x, x ∈ oa.support β†’ x ∈ oa'.support β†’ (p x ↔ q x)) (h2 : evalDist oa = evalDist oa') : [p | oa] = [q | oa'] :=
:= by have h : βˆ€ x, x ∈ oa.support ↔ x ∈ oa'.support := mem_support_iff_of_evalDist_eq h2 have h' : βˆ€ x, [= x | oa] = [= x | oa'] := Ξ» x ↦ probOutput_congr rfl h2 rw [probEvent_eq_tsum_indicator, probEvent_eq_tsum_indicator] refine tsum_congr Ξ» x ↦ ?_ simp [Set.indicator, h'] by_cases hp : p x Β· by_cases hq : q x Β· simp [hp, hq] Β· simp [hp, hq, h] refine Ξ» hoa ↦ hq ?_ refine (h1 _ ?_ hoa).1 hp refine (h _).2 hoa Β· by_cases hq : q x Β· simp [hp, hq] simp [h] at h1 intro hoa specialize h1 _ hoa tauto Β· rw [if_neg hp, if_neg hq]
5
48
true
Applied verif.
456
PureEquiv.map_pure_inv
@[simp] lemma map_pure_inv (f : PureEquiv m n) {Ξ± : Type u} (x : Ξ±) : f.invFun (pure x) = (pure x : m Ξ±)
VCV-io
ToMathlib/Control/Monad/Equiv.lean
[ "import Mathlib.Logic.Function.Defs", "import ToMathlib.Control.Monad.Hom" ]
[ { "name": "Function.LeftInverse", "module": "Init.Data.Function" }, { "name": "Function.RightInverse", "module": "Init.Data.Function" }, { "name": "Pure", "module": "Init.Prelude" } ]
[ { "name": "NatHom", "content": "structure NatHom (m : Type u β†’ Type v) (n : Type u β†’ Type w) where\n toFun : {Ξ± : Type u} β†’ m Ξ± β†’ n Ξ±" } ]
[ { "name": "Function.LeftInverse.injective", "module": "Init.Data.Function" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "NatEquiv", "content": "structure NatEquiv (m : Type u β†’ Type v) (n : Type u β†’ Type w) where\n toFun : {Ξ± : Type u} β†’ m Ξ± β†’ n Ξ±\n invFun : {Ξ± : Type u} β†’ n Ξ± β†’ m Ξ±\n left_inv : βˆ€ {Ξ±}, Function.LeftInverse (@invFun Ξ±) (@toFun Ξ±) := by admit /- proof elided -/" }, { "name": "PureEquiv", "content": "structure PureEquiv (m : Type u β†’ Type v) [Pure m] (n : Type u β†’ Type w) [Pure n]\n extends NatEquiv m n where\n map_pure' {Ξ± : Type u} (x : Ξ±) : toFun (pure x) = (pure x : n Ξ±)" } ]
[]
import ToMathlib.Control.Monad.Hom import Mathlib.Logic.Function.Defs structure NatEquiv (m : Type u β†’ Type v) (n : Type u β†’ Type w) where toFun : {Ξ± : Type u} β†’ m Ξ± β†’ n Ξ± invFun : {Ξ± : Type u} β†’ n Ξ± β†’ m Ξ± left_inv : βˆ€ {Ξ±}, Function.LeftInverse (@invFun Ξ±) (@toFun Ξ±) := by admit /- proof elided -/ namespace NatEquiv variable {m : Type u β†’ Type v} {n : Type u β†’ Type w} {p : Type u β†’ Type z} end NatEquiv structure PureEquiv (m : Type u β†’ Type v) [Pure m] (n : Type u β†’ Type w) [Pure n] extends NatEquiv m n where map_pure' {Ξ± : Type u} (x : Ξ±) : toFun (pure x) = (pure x : n Ξ±) namespace PureEquiv variable {m : Type u β†’ Type v} [Pure m] {n : Type u β†’ Type w} [Pure n]
@[simp] lemma map_pure_inv (f : PureEquiv m n) {Ξ± : Type u} (x : Ξ±) : f.invFun (pure x) = (pure x : m Ξ±) :=
:= by have h1 : f.toFun (f.invFun (pure x)) = pure x := f.right_inv (pure x) have h2 : f.toFun (pure x) = pure x := f.map_pure' x have h3 : f.toFun (f.invFun (pure x)) = f.toFun (pure x) := by rw [h1, h2] exact Function.LeftInverse.injective f.left_inv h3
1
7
true
Applied verif.
457
OracleComp.isQueryBound_iff_probEvent
lemma isQueryBound_iff_probEvent [spec.FiniteRange] {oa : OracleComp spec Ξ±} {qb : ΞΉ β†’ β„•} : IsQueryBound oa qb ↔ [(Β· ≀ qb) | snd <$> (simulateQ countingOracle oa).run <|> return 0] = 1
VCV-io
VCVio/OracleComp/QueryBound.lean
[ "import VCVio.OracleComp.DistSemantics.Alternative", "import VCVio.OracleComp.DistSemantics.EvalDist", "import VCVio.OracleComp.QueryTracking.CountingOracle" ]
[ { "name": "inline", "module": "Init.Core" }, { "name": "impl", "module": "Mathlib.Deprecated.MLList.BestFirst" }, { "name": "Bind", "module": "Init.Prelude" }, { "name": "Pure", "module": "Init.Prelude" }, { "name": "OptionT", "module": "Init.Control.Option" }, { "name": "AlternativeMonad", "module": "Batteries.Control.AlternativeMonad" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "Option.getM", "module": "Init.Data.Option.Basic" }, { "name": "WriterT", "module": "Mathlib.Control.Monad.Writer" }, { "name": "Prod.snd", "module": "Init.Prelude" }, { "name": "Fintype", "module": "Mathlib.Data.Fintype.Defs" }, { "name": "Inhabited", "module": "Init.Prelude" }, { "name": "Iff", "module": "Init.Core" }, { "name": "Prod", "module": "Init.Prelude" }, { "name": "Set", "module": "Mathlib.Data.Set.Defs" }, { "name": "Set.univ", "module": "Mathlib.Data.Set.Defs" } ]
[ { "name": "probFailure", "content": "notation \"[βŠ₯\" \"|\" oa \"]\" => probFailure oa" }, { "name": "simulateQ", "content": "def simulateQ [AlternativeMonad m] (so : QueryImpl spec m) (oa : OracleComp spec Ξ±) : m Ξ± :=\n do Option.getM (← FreeMonad.mapM oa.run so.impl)" }, { "name": "QueryImpl.Inhabited", "content": "instance QueryImpl.Inhabited [βˆ€ i, Inhabited (spec.range i)] [Pure m] :\n Inhabited (QueryImpl spec m) := ⟨{impl q := pure q.defaultOutput}⟩" }, { "name": "OracleSpec", "content": "def OracleSpec (ΞΉ : Type u) : Type (max u (v + 1)) :=\n (i : ΞΉ) β†’ Type v Γ— Type v" }, { "name": "OracleQuery", "content": "inductive OracleQuery {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) : Type v β†’ Type (max u v)\n | query (i : ΞΉ) (t : spec.domain i) : OracleQuery spec (spec.range i)" }, { "name": "domain", "content": "@[inline, reducible]\nprotected def domain (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type v := (spec i).1" }, { "name": "range", "content": "@[inline, reducible]\nprotected def range (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type w := (spec i).2" }, { "name": "mapM", "content": "protected def mapM [Pure m] [Bind m] :\n (oa : FreeMonad f Ξ±) β†’ (s : {Ξ± : Type u} β†’ f Ξ± β†’ m Ξ±) β†’ m Ξ±\n | .pure x, _ => pure x\n | .roll x r, s => s x >>= Ξ» u ↦ (r u).mapM s" }, { "name": "FreeMonad", "content": "inductive FreeMonad (f : Type u β†’ Type v) (Ξ± : Type w) : Type (max (u + 1) v w)\n | protected pure (x : Ξ±) : FreeMonad f Ξ±\n | roll {Ξ² : Type u} (x : f Ξ²) (r : Ξ² β†’ FreeMonad f Ξ±) : FreeMonad f Ξ±" }, { "name": "OracleComp", "content": "def OracleComp {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) :\n Type w β†’ Type (max u (v + 1) w) :=\n OptionT (FreeMonad (OracleQuery.{u,v} spec))" }, { "name": "countingOracle", "content": "def countingOracle : QueryImpl spec (WriterT (QueryCount spec) (OracleComp spec)) :=\n idOracle.withCounting" }, { "name": "QueryCount", "content": "@[reducible] def QueryCount (_spec : OracleSpec ΞΉ) : Type u := ΞΉ β†’ β„•" }, { "name": "FiniteRange", "content": "class FiniteRange (spec : OracleSpec ΞΉ) where\n range_inhabited' (i : ΞΉ) : Inhabited (spec.range i)\n range_fintype' (i : ΞΉ) : Fintype (spec.range i)" }, { "name": "probFailure", "content": "noncomputable def probFailure (oa : OracleComp spec Ξ±) : ℝβ‰₯0∞ :=\n (evalDist oa).run none" }, { "name": "HasEvalDist", "content": "class HasEvalDist (m : Type u β†’ Type v) [Monad m] where\n evalDist {Ξ± : Type u} (mx : m Ξ±) : SPMF Ξ±\n evalDist_pure {Ξ± : Type u} (x : Ξ±) : evalDist (pure x : m Ξ±) = pure x\n evalDist_bind {Ξ± Ξ² : Type u} (mx : m Ξ±) (my : Ξ± β†’ m Ξ²) :\n evalDist (mx >>= my) = evalDist mx >>= fun x => evalDist (my x)" }, { "name": "probEvent", "content": "noncomputable def probEvent (oa : OracleComp spec Ξ±) (p : Ξ± β†’ Prop) : ℝβ‰₯0∞ :=\n (evalDist oa).run.toOuterMeasure (Option.some '' {x | p x})" }, { "name": "support", "content": "def support (oa : OracleComp spec Ξ±) : Set Ξ± :=\n oa.supportWhen fun _ => Set.univ" }, { "name": "supportWhen", "content": "def supportWhen (oa : OracleComp spec Ξ±)\n (possible_outputs : {Ξ± : Type v} β†’ OracleQuery spec Ξ± β†’ Set Ξ±) : Set Ξ± :=" }, { "name": "induction", "content": "@[elab_as_elim]\nprotected def induction {C : OracleComp spec Ξ± β†’ Prop}\n (oa : OracleComp spec Ξ±) (pure : (a : Ξ±) β†’ C (pure a))\n (query_bind : (i : ΞΉ) β†’ (t : spec.domain i) β†’\n (oa : spec.range i β†’ OracleComp spec Ξ±) β†’ (βˆ€ u, C (oa u)) β†’ C (query i t >>= oa))\n (failure : C failure) : C oa :=\n FreeMonad.inductionOn (Option.rec failure pure) (Ξ» (query i t) ↦ query_bind i t) oa" }, { "name": "inductionOn", "content": "@[elab_as_elim]\nprotected def inductionOn {C : FreeMonad f Ξ± β†’ Prop}\n (pure : βˆ€ x, C (pure x))\n (roll : βˆ€ {Ξ²} (x : f Ξ²), (r : Ξ² β†’ FreeMonad f Ξ±) β†’\n (βˆ€ y, C (r y)) β†’ C (x >>= r)) :\n (oa : FreeMonad f Ξ±) β†’ C oa\n | FreeMonad.pure x => pure x\n | FreeMonad.roll x r => roll x _ (Ξ» u ↦\n FreeMonad.inductionOn pure roll (r u))" }, { "name": "construct", "content": "@[elab_as_elim]\nprotected def construct {C : OracleComp spec Ξ± β†’ Type*}\n (pure : (a : Ξ±) β†’ C (pure a))\n (query_bind : {Ξ² : Type v} β†’ (q : OracleQuery spec Ξ²) β†’\n (oa : Ξ² β†’ OracleComp spec Ξ±) β†’ ((u : Ξ²) β†’ C (oa u)) β†’ C (q >>= oa))\n (failure : C failure) (oa : OracleComp spec Ξ±) : C oa :=\n FreeMonad.construct (Option.rec failure pure) query_bind oa" }, { "name": "construct", "content": "@[elab_as_elim]\nprotected def construct {C : FreeMonad f Ξ± β†’ Type*}\n (pure : (x : Ξ±) β†’ C (pure x))\n (roll : {Ξ² : Type u} β†’ (x : f Ξ²) β†’ (r : Ξ² β†’ FreeMonad f Ξ±) β†’\n ((y : Ξ²) β†’ C (r y)) β†’ C (x >>= r)) :\n (oa : FreeMonad f Ξ±) β†’ C oa\n | .pure x => pure x\n | .roll x r => roll x _ (Ξ» u ↦ FreeMonad.construct pure roll (r u))" }, { "name": "probEvent", "content": "notation \"Pr[\" p \"|\" mx \"]\" => probEvent mx p" }, { "name": "probFailure", "content": "notation \"Pr[βŠ₯\" \"|\" mx \"]\" => probFailure mx" }, { "name": "probFailure", "content": "notation \"[βŠ₯\" \"|\" oa \"]\" => probFailure oa" }, { "name": "probEvent", "content": "notation \"[\" p \"|\" oa \"]\" => probEvent oa p" } ]
[ { "name": "Set.mem_image", "module": "Mathlib.Data.Set.Operations" }, { "name": "Set.mem_insert_iff", "module": "Mathlib.Data.Set.Insert" }, { "name": "exists_eq_right", "module": "Init.PropLemmas" }, { "name": "forall_eq_or_imp", "module": "Init.PropLemmas" }, { "name": "forall_exists_index", "module": "Init.PropLemmas" }, { "name": "true_and", "module": "Init.SimpLemmas" }, { "name": "zero_le", "module": "Mathlib.Algebra.Order.Monoid.Canonical.Defs" } ]
[ { "name": "probEvent_eq_one_iff", "content": "@[simp low]\nlemma probEvent_eq_one_iff : [p | oa] = 1 ↔ [βŠ₯ | oa] = 0 ∧ βˆ€ x ∈ oa.support, p x" }, { "name": "support_evalDist", "content": "lemma support_evalDist : (evalDist oa).run.support = if [βŠ₯ | oa] = 0 then\n some '' oa.support else insert none (some '' oa.support)" }, { "name": "probFailure_def", "content": "lemma probFailure_def (oa : OracleComp spec Ξ±) :\n [βŠ₯ | oa] = (evalDist oa).run none" }, { "name": "evalDist_orElse", "content": "@[simp]\nlemma evalDist_orElse [h : spec.FiniteRange] (oa oa' : OracleComp spec Ξ±) :\n evalDist (oa <|> oa') = (evalDist oa <|> evalDist oa')" }, { "name": "probFailure_orElse", "content": "@[simp]\nlemma probFailure_orElse {ΞΉ : Type u} {spec : OracleSpec ΞΉ} {Ξ± : Type u} [h : spec.FiniteRange]\n (oa oa' : OracleComp spec Ξ±) : [βŠ₯ | oa <|> oa'] = [βŠ₯ | oa] * [βŠ₯ | oa']" }, { "name": "support_orElse", "content": "@[simp]\nlemma support_orElse {ΞΉ : Type u} {spec : OracleSpec ΞΉ} {Ξ± : Type u}\n (oa oa' : OracleComp spec Ξ±) [Decidable oa.neverFails] : (oa <|> oa').support =\n if oa.neverFails then oa.support else oa.support βˆͺ oa'.support" }, { "name": "probFailure_run_simulateQ", "content": "@[simp]\nlemma probFailure_run_simulateQ [spec.FiniteRange] (oa : OracleComp spec Ξ±) :\n [βŠ₯ | (simulateQ countingOracle oa).run] = [βŠ₯ | oa]" }, { "name": "neverFails_run_simulateQ_iff", "content": "@[simp]\nlemma neverFails_run_simulateQ_iff (oa : OracleComp spec Ξ±) :\n neverFails (simulateQ countingOracle oa).run ↔ neverFails oa" } ]
[ { "name": "OracleComp.IsQueryBound", "content": "def IsQueryBound (oa : OracleComp spec Ξ±) (qb : ΞΉ β†’ β„•) : Prop :=\n βˆ€ qc ∈ (snd <$> (simulateQ countingOracle oa).run).support, qc ≀ qb" } ]
[ { "name": "OracleComp.isQueryBound_def", "content": "lemma isQueryBound_def (oa : OracleComp spec Ξ±) (qb : QueryCount spec) :\n IsQueryBound oa qb ↔ βˆ€ qc ∈ (snd <$> (simulateQ countingOracle oa).run).support, qc ≀ qb" } ]
import VCVio.OracleComp.QueryTracking.CountingOracle import VCVio.OracleComp.DistSemantics.Alternative open OracleSpec Prod namespace OracleComp section IsQueryBound variable {ΞΉ : Type u} [DecidableEq ΞΉ] {spec : OracleSpec ΞΉ} {Ξ± Ξ² Ξ³ : Type u} def IsQueryBound (oa : OracleComp spec Ξ±) (qb : ΞΉ β†’ β„•) : Prop := βˆ€ qc ∈ (snd <$> (simulateQ countingOracle oa).run).support, qc ≀ qb
lemma isQueryBound_iff_probEvent [spec.FiniteRange] {oa : OracleComp spec Ξ±} {qb : ΞΉ β†’ β„•} : IsQueryBound oa qb ↔ [(Β· ≀ qb) | snd <$> (simulateQ countingOracle oa).run <|> return 0] = 1 :=
:= by simp [probEvent_eq_one_iff, isQueryBound_def] apply Iff.intro · intro a x a_1 split at a_1 next h => simp_all only [Set.mem_image, Prod.exists, exists_eq_right] obtain ⟨w, h_1⟩ := a_1 apply a · exact h_1 next h => simp_all only [Set.mem_insert_iff, Set.mem_image, Prod.exists, exists_eq_right] cases a_1 with | inl h_1 => subst h_1 simp_all only [zero_le] | inr h_2 => obtain ⟨w, h_1⟩ := h_2 apply a · exact h_1 · intro a qc x h split at a next h_1 => simp_all only [Set.mem_image, Prod.exists, exists_eq_right, forall_exists_index] apply a · exact h next h_1 => simp_all only [Set.mem_insert_iff, Set.mem_image, Prod.exists, exists_eq_right, forall_eq_or_imp, zero_le, forall_exists_index, true_and] apply a · exact h
6
49
true
Applied verif.
458
OracleComp.probEvent_uniformFin
@[simp] lemma probEvent_uniformFin (p : Fin (n + 1) β†’ Prop) [DecidablePred p] : [p | $[0..n]] = (Finset.univ.filter p).card * (n + 1 : ℝβ‰₯0∞)⁻¹
VCV-io
VCVio/OracleComp/DistSemantics/EvalDist.lean
[ "import Mathlib.Probability.Distributions.Uniform", "import VCVio.OracleComp.SimSemantics.SimulateQ", "import VCVio.OracleComp.Traversal", "import ToMathlib.General", "import VCVio.OracleComp.Support" ]
[ { "name": "inline", "module": "Init.Core" }, { "name": "OptionT", "module": "Init.Control.Option" }, { "name": "Fin", "module": "Init.Prelude" }, { "name": "Unit", "module": "Init.Prelude" }, { "name": "DecidablePred", "module": "Init.Prelude" }, { "name": "Finset", "module": "Mathlib.Data.Finset.Defs" }, { "name": "Finset.filter", "module": "Mathlib.Data.Finset.Filter" }, { "name": "Finset.univ", "module": "Mathlib.Data.Fintype.Defs" }, { "name": "Fintype", "module": "Mathlib.Data.Fintype.Defs" }, { "name": "Fintype.card", "module": "Mathlib.Data.Fintype.Card" }, { "name": "Inhabited", "module": "Init.Prelude" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "OptionT.lift", "module": "Init.Control.Option" }, { "name": "PMF", "module": "Mathlib.Probability.ProbabilityMassFunction.Basic" }, { "name": "ENNReal", "module": "Mathlib.Data.ENNReal.Basic" }, { "name": "Set", "module": "Mathlib.Data.Set.Defs" }, { "name": "Set.indicator", "module": "Mathlib.Algebra.Notation.Indicator" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "Vector", "module": "Init.Data.Vector.Basic" }, { "name": "Vector.insertIdx", "module": "Init.Data.Vector.Basic" }, { "name": "AddCommMonoid", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "ContinuousAdd", "module": "Mathlib.Topology.Algebra.Monoid.Defs" }, { "name": "Function.update", "module": "Mathlib.Logic.Function.Basic" }, { "name": "Summable", "module": "Mathlib.Topology.Algebra.InfiniteSum.Defs" }, { "name": "T2Space", "module": "Mathlib.Topology.Separation.Hausdorff" }, { "name": "TopologicalSpace", "module": "Mathlib.Topology.Defs.Basic" }, { "name": "Set.univ", "module": "Mathlib.Data.Set.Defs" }, { "name": "Bool", "module": "Init.Prelude" } ]
[ { "name": "probOutput", "content": "notation \"[=\" x \"|\" oa \"]\" => probOutput oa x" }, { "name": "uniformFin", "content": "notation \"$[0..\" n \"]\" => uniformFin n" }, { "name": "notation:50 \"$[\" n \"β‹―\" m \"]\" => uniformFin' n m", "content": "notation:50 \"$[\" n \"β‹―\" m \"]\" => uniformFin' n m\n\nexample : OracleComp probSpec β„• := do\n let x ← $[314β‹―31415]; let y ← $[0β‹―x]\n return x + 2 * y" }, { "name": "probFailure", "content": "notation \"[βŠ₯\" \"|\" oa \"]\" => probFailure oa" }, { "name": "uniformFin", "content": "@[reducible, inline] def uniformFin (n : β„•) : ProbComp (Fin (n + 1)) :=\n unifSpec.query n ()" }, { "name": "ProbComp", "content": "abbrev ProbComp : Type z β†’ Type (max z 1) := OracleComp unifSpec" }, { "name": "OracleComp", "content": "def OracleComp {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) :\n Type w β†’ Type (max u (v + 1) w) :=\n OptionT (FreeMonad (OracleQuery.{u,v} spec))" }, { "name": "OracleQuery", "content": "inductive OracleQuery {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) : Type v β†’ Type (max u v)\n | query (i : ΞΉ) (t : spec.domain i) : OracleQuery spec (spec.range i)" }, { "name": "domain", "content": "@[inline, reducible]\nprotected def domain (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type v := (spec i).1" }, { "name": "OracleSpec", "content": "def OracleSpec (ΞΉ : Type u) : Type (max u (v + 1)) :=\n (i : ΞΉ) β†’ Type v Γ— Type v" }, { "name": "range", "content": "@[inline, reducible]\nprotected def range (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type w := (spec i).2" }, { "name": "FreeMonad", "content": "inductive FreeMonad (f : Type u β†’ Type v) (Ξ± : Type w) : Type (max (u + 1) v w)\n | protected pure (x : Ξ±) : FreeMonad f Ξ±\n | roll {Ξ² : Type u} (x : f Ξ²) (r : Ξ² β†’ FreeMonad f Ξ±) : FreeMonad f Ξ±" }, { "name": "unifSpec", "content": "@[inline, reducible] def unifSpec : OracleSpec.{0,0} β„• :=\n Ξ» n ↦ (Unit, Fin (n + 1))" }, { "name": "uniformFin'", "content": "@[reducible, inline] def uniformFin' (n m : β„•) : OracleComp probSpec (Fin (m + 1)) :=\n probSpec.query m n" }, { "name": "probSpec", "content": "def probSpec : OracleSpec.{0,0} β„• :=\n fun n => (β„•, Fin (n + 1))" }, { "name": "HasEvalDist", "content": "class HasEvalDist (m : Type u β†’ Type v) [Monad m] where\n evalDist {Ξ± : Type u} (mx : m Ξ±) : SPMF Ξ±\n evalDist_pure {Ξ± : Type u} (x : Ξ±) : evalDist (pure x : m Ξ±) = pure x\n evalDist_bind {Ξ± Ξ² : Type u} (mx : m Ξ±) (my : Ξ± β†’ m Ξ²) :\n evalDist (mx >>= my) = evalDist mx >>= fun x => evalDist (my x)" }, { "name": "DecidableEq", "content": "protected class DecidableEq (spec : OracleSpec ΞΉ) where\n domain_decidableEq' (i : ΞΉ) : DecidableEq (spec.domain i)\n range_decidableEq' (i : ΞΉ) : DecidableEq (spec.range i)" }, { "name": "cases", "content": "def cases {Ξ±} {motive : {n : β„•} β†’ Vector Ξ± n β†’ Sort*} (v_empty : motive #v[])\n (v_insert : {n : β„•} β†’ (hd : Ξ±) β†’ (tl : Vector Ξ± n) β†’ motive (tl.insertIdx 0 hd)) {m : β„•} :\n (v : Vector Ξ± m) β†’ motive v := match hm : m with\n | 0 => fun v => match v with | ⟨⟨[]⟩, rfl⟩ => v_empty\n | n + 1 => fun v => match hv : v with\n | ⟨⟨hd :: tl⟩, hSize⟩ => by admit /- proof elided -/" }, { "name": "support", "content": "def support (oa : OracleComp spec Ξ±) : Set Ξ± :=\n oa.supportWhen fun _ => Set.univ" }, { "name": "supportWhen", "content": "def supportWhen (oa : OracleComp spec Ξ±)\n (possible_outputs : {Ξ± : Type v} β†’ OracleQuery spec Ξ± β†’ Set Ξ±) : Set Ξ± :=" }, { "name": "induction", "content": "@[elab_as_elim]\nprotected def induction {C : OracleComp spec Ξ± β†’ Prop}\n (oa : OracleComp spec Ξ±) (pure : (a : Ξ±) β†’ C (pure a))\n (query_bind : (i : ΞΉ) β†’ (t : spec.domain i) β†’\n (oa : spec.range i β†’ OracleComp spec Ξ±) β†’ (βˆ€ u, C (oa u)) β†’ C (query i t >>= oa))\n (failure : C failure) : C oa :=\n FreeMonad.inductionOn (Option.rec failure pure) (Ξ» (query i t) ↦ query_bind i t) oa" }, { "name": "inductionOn", "content": "@[elab_as_elim]\nprotected def inductionOn {C : FreeMonad f Ξ± β†’ Prop}\n (pure : βˆ€ x, C (pure x))\n (roll : βˆ€ {Ξ²} (x : f Ξ²), (r : Ξ² β†’ FreeMonad f Ξ±) β†’\n (βˆ€ y, C (r y)) β†’ C (x >>= r)) :\n (oa : FreeMonad f Ξ±) β†’ C oa\n | FreeMonad.pure x => pure x\n | FreeMonad.roll x r => roll x _ (Ξ» u ↦\n FreeMonad.inductionOn pure roll (r u))" }, { "name": "construct", "content": "@[elab_as_elim]\nprotected def construct {C : OracleComp spec Ξ± β†’ Type*}\n (pure : (a : Ξ±) β†’ C (pure a))\n (query_bind : {Ξ² : Type v} β†’ (q : OracleQuery spec Ξ²) β†’\n (oa : Ξ² β†’ OracleComp spec Ξ±) β†’ ((u : Ξ²) β†’ C (oa u)) β†’ C (q >>= oa))\n (failure : C failure) (oa : OracleComp spec Ξ±) : C oa :=\n FreeMonad.construct (Option.rec failure pure) query_bind oa" }, { "name": "construct", "content": "@[elab_as_elim]\nprotected def construct {C : FreeMonad f Ξ± β†’ Type*}\n (pure : (x : Ξ±) β†’ C (pure x))\n (roll : {Ξ² : Type u} β†’ (x : f Ξ²) β†’ (r : Ξ² β†’ FreeMonad f Ξ±) β†’\n ((y : Ξ²) β†’ C (r y)) β†’ C (x >>= r)) :\n (oa : FreeMonad f Ξ±) β†’ C oa\n | .pure x => pure x\n | .roll x r => roll x _ (Ξ» u ↦ FreeMonad.construct pure roll (r u))" }, { "name": "finSupport", "content": "def finSupport [βˆ€ i, Fintype (spec.range i)] [DecidableEq Ξ±] (oa : OracleComp spec Ξ±) : Finset Ξ± :=\n oa.finSupportWhen fun | query _ _ => Finset.univ" }, { "name": "finSupportWhen", "content": "def finSupportWhen [DecidableEq Ξ±] (oa : OracleComp spec Ξ±)\n (possible_outputs : {Ξ± : Type v} β†’ OracleQuery spec Ξ± β†’ Finset Ξ±) : Finset Ξ± :=" }, { "name": "coin", "content": "@[reducible, inline] def coin : OracleComp coinSpec Bool :=\n coinSpec.query () ()" }, { "name": "coinSpec", "content": "@[inline, reducible] def coinSpec : OracleSpec.{0,0} Unit := Unit β†’β‚’ Bool" }, { "name": "FiniteRange", "content": "class FiniteRange (spec : OracleSpec ΞΉ) where\n range_inhabited' (i : ΞΉ) : Inhabited (spec.range i)\n range_fintype' (i : ΞΉ) : Fintype (spec.range i)" }, { "name": "uniformFin", "content": "notation \"$[0..\" n \"]\" => uniformFin n" }, { "name": "notation:50 \"$[\" n \"β‹―\" m \"]\" => uniformFin' n m", "content": "notation:50 \"$[\" n \"β‹―\" m \"]\" => uniformFin' n m\n\nexample : OracleComp probSpec β„• := do\n let x ← $[314β‹―31415]; let y ← $[0β‹―x]\n return x + 2 * y" } ]
[ { "name": "Nat.cast_inj", "module": "Mathlib.Algebra.CharZero.Defs" }, { "name": "PMF.monad_map_eq_map", "module": "Mathlib.Probability.ProbabilityMassFunction.Constructions" }, { "name": "inv_inj", "module": "Mathlib.Algebra.Group.Basic" }, { "name": "not_imp_not", "module": "Mathlib.Logic.Basic" }, { "name": "tsum_eq_single", "module": "Mathlib.Topology.Algebra.InfiniteSum.Basic" }, { "name": "ENNReal.summable", "module": "Mathlib.Topology.Instances.ENNReal.Lemmas" }, { "name": "PMF.toOuterMeasure_apply", "module": "Mathlib.Probability.ProbabilityMassFunction.Basic" }, { "name": "Finset.mem_filter", "module": "Mathlib.Data.Finset.Filter" }, { "name": "Finset.sum_congr", "module": "Mathlib.Algebra.BigOperators.Group.Finset.Basic" }, { "name": "if_pos", "module": "Init.Core" }, { "name": "tsum_eq_sum'", "module": "Mathlib.Topology.Algebra.InfiniteSum.Basic" }, { "name": "Finset.sum_const", "module": "Mathlib.Algebra.BigOperators.Group.Finset.Basic" }, { "name": "nsmul_eq_mul", "module": "Mathlib.Algebra.Ring.Defs" } ]
[ { "name": "tsum_option", "content": "lemma tsum_option {Ξ± Ξ² : Type*} [AddCommMonoid Ξ±] [TopologicalSpace Ξ±]\n [ContinuousAdd Ξ±] [T2Space Ξ±]\n (f : Option Ξ² β†’ Ξ±) (hf : Summable (Function.update f none 0)) :\n βˆ‘' x : Option Ξ², f x = f none + βˆ‘' x : Ξ², f (some x)" }, { "name": "finSupport_uniformFin", "content": "@[simp] lemma finSupport_uniformFin (n : β„•) : ($[0..n]).finSupport = Finset.univ" }, { "name": "finSupport_query", "content": "lemma finSupport_query [spec.FiniteRange] [DecidableEq Ξ±] (q : OracleQuery spec Ξ±) :\n (q : OracleComp spec _).finSupport = match q with" }, { "name": "finSupportWhen_query", "content": "@[simp] lemma finSupportWhen_query [DecidableEq Ξ±] (q : OracleQuery spec Ξ±) :\n (q : OracleComp spec Ξ±).finSupportWhen fin_poss = fin_poss q" }, { "name": "finSupport_def", "content": "lemma finSupport_def [βˆ€ i, Fintype (spec.range i)] [DecidableEq Ξ±] (oa : OracleComp spec Ξ±) :\n oa.finSupport = oa.finSupportWhen fun" } ]
[ { "name": "OracleComp.probOutput", "content": "noncomputable def probOutput (oa : OracleComp spec Ξ±) (x : Ξ±) : ℝβ‰₯0∞ :=\n (evalDist oa).run (some x)" }, { "name": "OracleComp.probFailure", "content": "noncomputable def probFailure (oa : OracleComp spec Ξ±) : ℝβ‰₯0∞ :=\n (evalDist oa).run none" } ]
[ { "name": "OracleComp.probOutput_def", "content": "lemma probOutput_def (oa : OracleComp spec Ξ±) (x : Ξ±) :\n [= x | oa] = (evalDist oa).run (some x)" }, { "name": "OracleComp.probEvent_def", "content": "lemma probEvent_def (oa : OracleComp spec Ξ±) (p : Ξ± β†’ Prop) :\n [p | oa] = (evalDist oa).run.toOuterMeasure (Option.some '' {x | p x})" }, { "name": "OracleComp.probEvent_eq_tsum_ite", "content": "lemma probEvent_eq_tsum_ite (oa : OracleComp spec Ξ±) (p : Ξ± β†’ Prop) [DecidablePred p] :\n [p | oa] = βˆ‘' x : Ξ±, if p x then [= x | oa] else 0" }, { "name": "OracleComp.probEvent_eq_sum_filter_finSupport", "content": "lemma probEvent_eq_sum_filter_finSupport [spec.DecidableEq] [DecidablePred p] [DecidableEq Ξ±] :\n [p | oa] = βˆ‘ x ∈ oa.finSupport.filter p, [= x | oa]" }, { "name": "OracleComp.probOutput_liftM", "content": "@[simp]\nlemma probOutput_liftM [Fintype Ξ±] (q : OracleQuery spec Ξ±) (u : Ξ±) :\n [= u | (q : OracleComp spec Ξ±)] = (Fintype.card Ξ± : ℝβ‰₯0∞)⁻¹" }, { "name": "OracleComp.probOutput_query", "content": "lemma probOutput_query (u : spec.range i) :\n [= u | (query i t : OracleComp spec _)] = (Fintype.card (spec.range i) : ℝβ‰₯0∞)⁻¹" }, { "name": "OracleComp.probOutput_uniformFin", "content": "@[simp]\nlemma probOutput_uniformFin (x : Fin (n + 1)) : [= x | $[0..n]] = ((n : ℝβ‰₯0∞) + 1)⁻¹" } ]
import VCVio.OracleComp.Traversal import VCVio.OracleComp.SimSemantics.SimulateQ import Mathlib.Probability.Distributions.Uniform import ToMathlib.General open OracleSpec Option ENNReal BigOperators namespace OracleComp variable {ΞΉ : Type u} {spec : OracleSpec ΞΉ} {ΞΉ' : Type v} {spec' : OracleSpec ΞΉ'} {Ξ± Ξ² Ξ³ : Type w} [spec.FiniteRange] [spec'.FiniteRange] section evalDist end evalDist noncomputable def probOutput (oa : OracleComp spec Ξ±) (x : Ξ±) : ℝβ‰₯0∞ := (evalDist oa).run (some x) notation "[=" x "|" oa "]" => probOutput oa x noncomputable def probFailure (oa : OracleComp spec Ξ±) : ℝβ‰₯0∞ := (evalDist oa).run none notation "[βŠ₯" "|" oa "]" => probFailure oa notation "[" p "|" oa "]" => probEvent oa p section bounds variable {oa : OracleComp spec Ξ±} {x : Ξ±} {p : Ξ± β†’ Prop} end bounds section support variable (oa : OracleComp spec Ξ±) (x : Ξ±) (p q : Ξ± β†’ Prop) variable {oa x p q} end support section sums variable (oa : OracleComp spec Ξ±) (p : Ξ± β†’ Prop) end sums section pure variable (x : Ξ±) end pure section bind variable (oa : OracleComp spec Ξ±) (ob : Ξ± β†’ OracleComp spec Ξ²) end bind section mul_le_probEvent_bind end mul_le_probEvent_bind section bind_const variable (oa : OracleComp spec Ξ±) (ob : OracleComp spec Ξ²) end bind_const section query variable (i : ΞΉ) (t : spec.domain i) end query section failure end failure section map variable (oa : OracleComp spec Ξ±) (f : Ξ± β†’ Ξ²) end map section neverFails end neverFails section unit end unit section bool end bool section eqRec variable (oa : OracleComp spec Ξ±) (h : Ξ± = Ξ²) end eqRec section ite variable (p : Prop) [Decidable p] (oa oa' : OracleComp spec Ξ±) end ite section coin end coin section uniformFin variable (n : β„•)
@[simp] lemma probEvent_uniformFin (p : Fin (n + 1) β†’ Prop) [DecidablePred p] : [p | $[0..n]] = (Finset.univ.filter p).card * (n + 1 : ℝβ‰₯0∞)⁻¹ :=
:= by simp only [probEvent_eq_sum_filter_finSupport, finSupport_uniformFin, probOutput_uniformFin, Finset.sum_const, nsmul_eq_mul]
6
77
true
Applied verif.
459
OracleComp.probFailure_bind_of_const
lemma probFailure_bind_of_const [Nonempty Ξ±] (r : ℝβ‰₯0∞) (h : βˆ€ x, [βŠ₯ | ob x] = r) : [βŠ₯ | oa >>= ob] = [βŠ₯ | oa] + r - [βŠ₯ | oa] * r
VCV-io
VCVio/OracleComp/DistSemantics/EvalDist.lean
[ "import Mathlib.Probability.Distributions.Uniform", "import VCVio.OracleComp.SimSemantics.SimulateQ", "import VCVio.OracleComp.Traversal", "import ToMathlib.General" ]
[ { "name": "inline", "module": "Init.Core" }, { "name": "OptionT", "module": "Init.Control.Option" }, { "name": "Nonempty", "module": "Init.Prelude" }, { "name": "AddLECancellable", "module": "Mathlib.Algebra.Order.Monoid.Unbundled.Basic" }, { "name": "Classical.arbitrary", "module": "Mathlib.Logic.Nonempty" }, { "name": "ENNReal", "module": "Mathlib.Data.ENNReal.Basic" }, { "name": "PMF", "module": "Mathlib.Probability.ProbabilityMassFunction.Basic" }, { "name": "Option.elimM", "module": "Init.Data.Option.Basic" }, { "name": "Vector", "module": "Init.Data.Vector.Basic" }, { "name": "Vector.insertIdx", "module": "Init.Data.Vector.Basic" }, { "name": "AddCommMonoid", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "ContinuousAdd", "module": "Mathlib.Topology.Algebra.Monoid.Defs" }, { "name": "Function.update", "module": "Mathlib.Logic.Function.Basic" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "Summable", "module": "Mathlib.Topology.Algebra.InfiniteSum.Defs" }, { "name": "T2Space", "module": "Mathlib.Topology.Separation.Hausdorff" }, { "name": "TopologicalSpace", "module": "Mathlib.Topology.Defs.Basic" } ]
[ { "name": "probFailure", "content": "notation \"[βŠ₯\" \"|\" oa \"]\" => probFailure oa" }, { "name": "probOutput", "content": "notation \"[=\" x \"|\" oa \"]\" => probOutput oa x" }, { "name": "HasEvalDist", "content": "class HasEvalDist (m : Type u β†’ Type v) [Monad m] where\n evalDist {Ξ± : Type u} (mx : m Ξ±) : SPMF Ξ±\n evalDist_pure {Ξ± : Type u} (x : Ξ±) : evalDist (pure x : m Ξ±) = pure x\n evalDist_bind {Ξ± Ξ² : Type u} (mx : m Ξ±) (my : Ξ± β†’ m Ξ²) :\n evalDist (mx >>= my) = evalDist mx >>= fun x => evalDist (my x)" }, { "name": "OracleComp", "content": "def OracleComp {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) :\n Type w β†’ Type (max u (v + 1) w) :=\n OptionT (FreeMonad (OracleQuery.{u,v} spec))" }, { "name": "OracleQuery", "content": "inductive OracleQuery {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) : Type v β†’ Type (max u v)\n | query (i : ΞΉ) (t : spec.domain i) : OracleQuery spec (spec.range i)" }, { "name": "domain", "content": "@[inline, reducible]\nprotected def domain (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type v := (spec i).1" }, { "name": "OracleSpec", "content": "def OracleSpec (ΞΉ : Type u) : Type (max u (v + 1)) :=\n (i : ΞΉ) β†’ Type v Γ— Type v" }, { "name": "range", "content": "@[inline, reducible]\nprotected def range (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type w := (spec i).2" }, { "name": "FreeMonad", "content": "inductive FreeMonad (f : Type u β†’ Type v) (Ξ± : Type w) : Type (max (u + 1) v w)\n | protected pure (x : Ξ±) : FreeMonad f Ξ±\n | roll {Ξ² : Type u} (x : f Ξ²) (r : Ξ² β†’ FreeMonad f Ξ±) : FreeMonad f Ξ±" }, { "name": "cases", "content": "def cases {Ξ±} {motive : {n : β„•} β†’ Vector Ξ± n β†’ Sort*} (v_empty : motive #v[])\n (v_insert : {n : β„•} β†’ (hd : Ξ±) β†’ (tl : Vector Ξ± n) β†’ motive (tl.insertIdx 0 hd)) {m : β„•} :\n (v : Vector Ξ± m) β†’ motive v := match hm : m with\n | 0 => fun v => match v with | ⟨⟨[]⟩, rfl⟩ => v_empty\n | n + 1 => fun v => match hv : v with\n | ⟨⟨hd :: tl⟩, hSize⟩ => by admit /- proof elided -/" } ]
[ { "name": "PMF.coe_le_one", "module": "Mathlib.Probability.ProbabilityMassFunction.Basic" }, { "name": "ENNReal.summable", "module": "Mathlib.Topology.Instances.ENNReal.Lemmas" }, { "name": "symm", "module": "Mathlib.Order.Defs.Unbundled" }, { "name": "add_comm", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "PMF.apply_ne_top", "module": "Mathlib.Probability.ProbabilityMassFunction.Basic" }, { "name": "ENNReal.eq_sub_of_add_eq", "module": "Mathlib.Data.ENNReal.Operations" }, { "name": "AddLECancellable.add_tsub_assoc_of_le", "module": "Mathlib.Algebra.Order.Sub.Unbundled.Basic" }, { "name": "ENNReal.addLECancellable_iff_ne", "module": "Mathlib.Data.ENNReal.Operations" }, { "name": "ENNReal.div_self", "module": "Mathlib.Data.ENNReal.Inv" }, { "name": "ENNReal.mul_le_of_le_div", "module": "Mathlib.Data.ENNReal.Inv" }, { "name": "ENNReal.mul_ne_top", "module": "Mathlib.Data.ENNReal.Operations" }, { "name": "ENNReal.sub_mul", "module": "Mathlib.Data.ENNReal.Operations" }, { "name": "ENNReal.tsum_mul_right", "module": "Mathlib.Topology.Instances.ENNReal.Lemmas" }, { "name": "le_of_le_of_eq", "module": "Init.Core" }, { "name": "le_refl", "module": "Mathlib.Order.Defs.PartialOrder" }, { "name": "one_mul", "module": "Mathlib.Algebra.Group.Defs" } ]
[ { "name": "tsum_option", "content": "lemma tsum_option {Ξ± Ξ² : Type*} [AddCommMonoid Ξ±] [TopologicalSpace Ξ±]\n [ContinuousAdd Ξ±] [T2Space Ξ±]\n (f : Option Ξ² β†’ Ξ±) (hf : Summable (Function.update f none 0)) :\n βˆ‘' x : Option Ξ², f x = f none + βˆ‘' x : Ξ², f (some x)" } ]
[ { "name": "OracleComp.probOutput", "content": "noncomputable def probOutput (oa : OracleComp spec Ξ±) (x : Ξ±) : ℝβ‰₯0∞ :=\n (evalDist oa).run (some x)" }, { "name": "OracleComp.probFailure", "content": "noncomputable def probFailure (oa : OracleComp spec Ξ±) : ℝβ‰₯0∞ :=\n (evalDist oa).run none" } ]
[ { "name": "OracleComp.probOutput_def", "content": "lemma probOutput_def (oa : OracleComp spec Ξ±) (x : Ξ±) :\n [= x | oa] = (evalDist oa).run (some x)" }, { "name": "OracleComp.probFailure_add_tsum_probOutput", "content": "@[simp]\nlemma probFailure_add_tsum_probOutput (oa : OracleComp spec Ξ±) :\n [βŠ₯ | oa] + βˆ‘' x, [= x | oa] = 1" }, { "name": "OracleComp.tsum_probOutput_add_probFailure", "content": "@[simp]\nlemma tsum_probOutput_add_probFailure (oa : OracleComp spec Ξ±) :\n βˆ‘' x, [= x | oa] + [βŠ₯ | oa] = 1" }, { "name": "OracleComp.probFailure_le_one", "content": "@[simp] lemma probFailure_le_one : [βŠ₯ | oa] ≀ 1" }, { "name": "OracleComp.probFailure_ne_top", "content": "@[simp] lemma probFailure_ne_top : [βŠ₯ | oa] β‰  ∞" }, { "name": "OracleComp.tsum_probOutput_eq_sub", "content": "lemma tsum_probOutput_eq_sub (oa : OracleComp spec Ξ±) :\n βˆ‘' x : Ξ±, [= x | oa] = 1 - [βŠ₯ | oa]" }, { "name": "OracleComp.probFailure_bind_eq_tsum", "content": "lemma probFailure_bind_eq_tsum :\n [βŠ₯ | oa >>= ob] = [βŠ₯ | oa] + βˆ‘' x : Ξ±, [= x | oa] * [βŠ₯ | ob x]" } ]
import VCVio.OracleComp.Traversal import VCVio.OracleComp.SimSemantics.SimulateQ import Mathlib.Probability.Distributions.Uniform import ToMathlib.General open OracleSpec Option ENNReal BigOperators namespace OracleComp variable {ΞΉ : Type u} {spec : OracleSpec ΞΉ} {ΞΉ' : Type v} {spec' : OracleSpec ΞΉ'} {Ξ± Ξ² Ξ³ : Type w} [spec.FiniteRange] [spec'.FiniteRange] section evalDist end evalDist noncomputable def probOutput (oa : OracleComp spec Ξ±) (x : Ξ±) : ℝβ‰₯0∞ := (evalDist oa).run (some x) notation "[=" x "|" oa "]" => probOutput oa x noncomputable def probFailure (oa : OracleComp spec Ξ±) : ℝβ‰₯0∞ := (evalDist oa).run none notation "[βŠ₯" "|" oa "]" => probFailure oa notation "[" p "|" oa "]" => probEvent oa p section bounds variable {oa : OracleComp spec Ξ±} {x : Ξ±} {p : Ξ± β†’ Prop} end bounds section support variable (oa : OracleComp spec Ξ±) (x : Ξ±) (p q : Ξ± β†’ Prop) variable {oa x p q} end support section sums variable (oa : OracleComp spec Ξ±) (p : Ξ± β†’ Prop) end sums section pure variable (x : Ξ±) end pure section bind variable (oa : OracleComp spec Ξ±) (ob : Ξ± β†’ OracleComp spec Ξ²)
lemma probFailure_bind_of_const [Nonempty Ξ±] (r : ℝβ‰₯0∞) (h : βˆ€ x, [βŠ₯ | ob x] = r) : [βŠ₯ | oa >>= ob] = [βŠ₯ | oa] + r - [βŠ₯ | oa] * r :=
:= by have : r β‰  ⊀ := Ξ» hr ↦ probFailure_ne_top ((h (Classical.arbitrary Ξ±)).trans hr) simp [probFailure_bind_eq_tsum, h, ENNReal.tsum_mul_right, tsum_probOutput_eq_sub] rw [ENNReal.sub_mul Ξ» _ _ ↦ this, one_mul] refine symm (AddLECancellable.add_tsub_assoc_of_le ?_ ?_ _) Β· refine ENNReal.addLECancellable_iff_ne.2 (ENNReal.mul_ne_top probFailure_ne_top this) Β· by_cases hr : r = 0 Β· simp only [hr, mul_zero, le_refl] refine mul_le_of_le_div (le_of_le_of_eq probFailure_le_one ?_) refine symm (ENNReal.div_self hr this)
5
48
true
Applied verif.
460
OracleComp.probEvent_seq_map_eq_probEvent_comp_uncurry
lemma probEvent_seq_map_eq_probEvent_comp_uncurry [spec.FiniteRange] (p : Ξ³ β†’ Prop) : [p | f <$> oa <*> ob] = [p ∘ f.uncurry | Prod.mk <$> oa <*> ob]
VCV-io
VCVio/OracleComp/DistSemantics/Seq.lean
[ "import VCVio.OracleComp.DistSemantics.Monad", "import VCVio.OracleComp.DistSemantics.EvalDist", "import VCVio.OracleComp.Support" ]
[ { "name": "inline", "module": "Init.Core" }, { "name": "Fintype", "module": "Mathlib.Data.Fintype.Defs" }, { "name": "Inhabited", "module": "Init.Prelude" }, { "name": "Prod", "module": "Init.Prelude" }, { "name": "Prod.mk", "module": "Init.Prelude" }, { "name": "Function.comp", "module": "Init.Prelude" }, { "name": "Functor", "module": "Init.Prelude" }, { "name": "Set", "module": "Mathlib.Data.Set.Defs" }, { "name": "OptionT", "module": "Init.Control.Option" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "Set.univ", "module": "Mathlib.Data.Set.Defs" }, { "name": "Set.image2", "module": "Mathlib.Data.Set.Operations" }, { "name": "Vector", "module": "Init.Data.Vector.Basic" }, { "name": "Vector.insertIdx", "module": "Init.Data.Vector.Basic" } ]
[ { "name": "probOutput", "content": "notation \"[=\" x \"|\" oa \"]\" => probOutput oa x" }, { "name": "HasEvalDist", "content": "class HasEvalDist (m : Type u β†’ Type v) [Monad m] where\n evalDist {Ξ± : Type u} (mx : m Ξ±) : SPMF Ξ±\n evalDist_pure {Ξ± : Type u} (x : Ξ±) : evalDist (pure x : m Ξ±) = pure x\n evalDist_bind {Ξ± Ξ² : Type u} (mx : m Ξ±) (my : Ξ± β†’ m Ξ²) :\n evalDist (mx >>= my) = evalDist mx >>= fun x => evalDist (my x)" }, { "name": "FiniteRange", "content": "class FiniteRange (spec : OracleSpec ΞΉ) where\n range_inhabited' (i : ΞΉ) : Inhabited (spec.range i)\n range_fintype' (i : ΞΉ) : Fintype (spec.range i)" }, { "name": "OracleSpec", "content": "def OracleSpec (ΞΉ : Type u) : Type (max u (v + 1)) :=\n (i : ΞΉ) β†’ Type v Γ— Type v" }, { "name": "range", "content": "@[inline, reducible]\nprotected def range (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type w := (spec i).2" }, { "name": "support", "content": "def support (oa : OracleComp spec Ξ±) : Set Ξ± :=\n oa.supportWhen fun _ => Set.univ" }, { "name": "supportWhen", "content": "def supportWhen (oa : OracleComp spec Ξ±)\n (possible_outputs : {Ξ± : Type v} β†’ OracleQuery spec Ξ± β†’ Set Ξ±) : Set Ξ± :=" }, { "name": "induction", "content": "@[elab_as_elim]\nprotected def induction {C : OracleComp spec Ξ± β†’ Prop}\n (oa : OracleComp spec Ξ±) (pure : (a : Ξ±) β†’ C (pure a))\n (query_bind : (i : ΞΉ) β†’ (t : spec.domain i) β†’\n (oa : spec.range i β†’ OracleComp spec Ξ±) β†’ (βˆ€ u, C (oa u)) β†’ C (query i t >>= oa))\n (failure : C failure) : C oa :=\n FreeMonad.inductionOn (Option.rec failure pure) (Ξ» (query i t) ↦ query_bind i t) oa" }, { "name": "OracleQuery", "content": "inductive OracleQuery {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) : Type v β†’ Type (max u v)\n | query (i : ΞΉ) (t : spec.domain i) : OracleQuery spec (spec.range i)" }, { "name": "OracleComp", "content": "def OracleComp {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) :\n Type w β†’ Type (max u (v + 1) w) :=\n OptionT (FreeMonad (OracleQuery.{u,v} spec))" }, { "name": "domain", "content": "@[inline, reducible]\nprotected def domain (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type v := (spec i).1" }, { "name": "FreeMonad", "content": "inductive FreeMonad (f : Type u β†’ Type v) (Ξ± : Type w) : Type (max (u + 1) v w)\n | protected pure (x : Ξ±) : FreeMonad f Ξ±\n | roll {Ξ² : Type u} (x : f Ξ²) (r : Ξ² β†’ FreeMonad f Ξ±) : FreeMonad f Ξ±" }, { "name": "inductionOn", "content": "@[elab_as_elim]\nprotected def inductionOn {C : FreeMonad f Ξ± β†’ Prop}\n (pure : βˆ€ x, C (pure x))\n (roll : βˆ€ {Ξ²} (x : f Ξ²), (r : Ξ² β†’ FreeMonad f Ξ±) β†’\n (βˆ€ y, C (r y)) β†’ C (x >>= r)) :\n (oa : FreeMonad f Ξ±) β†’ C oa\n | FreeMonad.pure x => pure x\n | FreeMonad.roll x r => roll x _ (Ξ» u ↦\n FreeMonad.inductionOn pure roll (r u))" }, { "name": "construct", "content": "@[elab_as_elim]\nprotected def construct {C : OracleComp spec Ξ± β†’ Type*}\n (pure : (a : Ξ±) β†’ C (pure a))\n (query_bind : {Ξ² : Type v} β†’ (q : OracleQuery spec Ξ²) β†’\n (oa : Ξ² β†’ OracleComp spec Ξ±) β†’ ((u : Ξ²) β†’ C (oa u)) β†’ C (q >>= oa))\n (failure : C failure) (oa : OracleComp spec Ξ±) : C oa :=\n FreeMonad.construct (Option.rec failure pure) query_bind oa" }, { "name": "construct", "content": "@[elab_as_elim]\nprotected def construct {C : FreeMonad f Ξ± β†’ Type*}\n (pure : (x : Ξ±) β†’ C (pure x))\n (roll : {Ξ² : Type u} β†’ (x : f Ξ²) β†’ (r : Ξ² β†’ FreeMonad f Ξ±) β†’\n ((y : Ξ²) β†’ C (r y)) β†’ C (x >>= r)) :\n (oa : FreeMonad f Ξ±) β†’ C oa\n | .pure x => pure x\n | .roll x r => roll x _ (Ξ» u ↦ FreeMonad.construct pure roll (r u))" }, { "name": "probOutput", "content": "noncomputable def probOutput (oa : OracleComp spec Ξ±) (x : Ξ±) : ℝβ‰₯0∞ :=\n (evalDist oa).run (some x)" }, { "name": "inductionOn", "content": "@[elab_as_elim]\nprotected def inductionOn {C : OracleComp spec Ξ± β†’ Prop}\n (pure : (a : Ξ±) β†’ C (pure a))\n (query_bind : (i : ΞΉ) β†’ (t : spec.domain i) β†’\n (oa : spec.range i β†’ OracleComp spec Ξ±) β†’ (βˆ€ u, C (oa u)) β†’ C (query i t >>= oa))\n (failure : C failure) (oa : OracleComp spec Ξ±) : C oa :=\n FreeMonad.inductionOn (Option.rec failure pure) (Ξ» (query i t) ↦ query_bind i t) oa" }, { "name": "probEvent", "content": "noncomputable def probEvent (oa : OracleComp spec Ξ±) (p : Ξ± β†’ Prop) : ℝβ‰₯0∞ :=\n (evalDist oa).run.toOuterMeasure (Option.some '' {x | p x})" }, { "name": "cases", "content": "def cases {Ξ±} {motive : {n : β„•} β†’ Vector Ξ± n β†’ Sort*} (v_empty : motive #v[])\n (v_insert : {n : β„•} β†’ (hd : Ξ±) β†’ (tl : Vector Ξ± n) β†’ motive (tl.insertIdx 0 hd)) {m : β„•} :\n (v : Vector Ξ± m) β†’ motive v := match hm : m with\n | 0 => fun v => match v with | ⟨⟨[]⟩, rfl⟩ => v_empty\n | n + 1 => fun v => match hv : v with\n | ⟨⟨hd :: tl⟩, hSize⟩ => by admit /- proof elided -/" }, { "name": "probOutput", "content": "notation \"Pr[=\" x \"|\" mx \"]\" => probOutput mx x" }, { "name": "probEvent", "content": "notation \"Pr[\" p \"|\" mx \"]\" => probEvent mx p" }, { "name": "probOutput", "content": "notation \"[=\" x \"|\" oa \"]\" => probOutput oa x" }, { "name": "probEvent", "content": "notation \"[\" p \"|\" oa \"]\" => probEvent oa p" } ]
[ { "name": "seq_eq_bind_map", "module": "Init.Control.Lawful.Basic" }, { "name": "Set.biUnion_and'", "module": "Mathlib.Data.Set.Lattice" }, { "name": "Set.ext_iff", "module": "Mathlib.Data.Set.Defs" }, { "name": "Set.iUnion_exists", "module": "Mathlib.Data.Set.Lattice" }, { "name": "Set.iUnion_iUnion_eq_right", "module": "Mathlib.Data.Set.Lattice" }, { "name": "Set.mem_iUnion", "module": "Mathlib.Order.SetNotation" }, { "name": "Set.mem_image", "module": "Mathlib.Data.Set.Operations" }, { "name": "Set.mem_image2", "module": "Mathlib.Data.Set.Operations" }, { "name": "exists_prop", "module": "Init.PropLemmas" }, { "name": "implies_true", "module": "Init.SimpLemmas" }, { "name": "Function.uncurry_apply_pair", "module": "Init.Data.Function" }, { "name": "Functor.map_map", "module": "Init.Control.Lawful.Basic" }, { "name": "Set.image2_mk_eq_prod", "module": "Mathlib.Data.Set.NAry" }, { "name": "Set.image_uncurry_prod", "module": "Mathlib.Data.Set.NAry" }, { "name": "congr_arg", "module": "Batteries.Logic" }, { "name": "map_seq", "module": "Mathlib.Control.Basic" } ]
[ { "name": "support_map", "content": "@[simp] lemma support_map (oa : OracleComp spec Ξ±) (f : Ξ± β†’ Ξ²) :\n (f <$> oa).support = f '' oa.support" }, { "name": "support_bind", "content": "@[simp] lemma support_bind (oa : OracleComp spec Ξ±) (ob : Ξ± β†’ OracleComp spec Ξ²) :\n (oa >>= ob).support = ⋃ x ∈ oa.support, (ob x).support" }, { "name": "support_pure", "content": "@[simp] lemma support_pure (x : Ξ±) :\n (pure x : OracleComp spec Ξ±).support = {x}" }, { "name": "probEvent_congr'", "content": "lemma probEvent_congr' {p q : Ξ± β†’ Prop} {oa : OracleComp spec Ξ±} {oa' : OracleComp spec' Ξ±}\n (h1 : βˆ€ x, x ∈ oa.support β†’ x ∈ oa'.support β†’ (p x ↔ q x))\n (h2 : evalDist oa = evalDist oa') : [p | oa] = [q | oa']" }, { "name": "mem_support_iff_of_evalDist_eq", "content": "lemma mem_support_iff_of_evalDist_eq {oa : OracleComp spec Ξ±} {oa' : OracleComp spec' Ξ±}\n (h : evalDist oa = evalDist oa') (x : Ξ±) : x ∈ oa.support ↔ x ∈ oa'.support" }, { "name": "mem_support_iff_probOutput_ne_zero", "content": "lemma mem_support_iff_probOutput_ne_zero : x ∈ oa.support ↔ [= x | oa] β‰  0" }, { "name": "probOutput_eq_zero_iff", "content": "@[simp low]\nlemma probOutput_eq_zero_iff : [= x | oa] = 0 ↔ x βˆ‰ oa.support" }, { "name": "mem_support_evalDist_iff", "content": "@[simp]\nlemma mem_support_evalDist_iff (oa : OracleComp spec Ξ±) (x : Ξ±) :\n some x ∈ (evalDist oa).run.support ↔ x ∈ oa.support" }, { "name": "probOutput_def", "content": "lemma probOutput_def (oa : OracleComp spec Ξ±) (x : Ξ±) :\n [= x | oa] = (evalDist oa).run (some x)" }, { "name": "probEvent_eq_tsum_indicator", "content": "lemma probEvent_eq_tsum_indicator (oa : OracleComp spec Ξ±) (p : Ξ± β†’ Prop) :\n [p | oa] = βˆ‘' x : Ξ±, {x | p x}.indicator ([= Β· | oa]) x" }, { "name": "probEvent_def", "content": "lemma probEvent_def (oa : OracleComp spec Ξ±) (p : Ξ± β†’ Prop) :\n [p | oa] = (evalDist oa).run.toOuterMeasure (Option.some '' {x | p x})" }, { "name": "probOutput_congr", "content": "lemma probOutput_congr {x y : Ξ±} {oa : OracleComp spec Ξ±} {oa' : OracleComp spec' Ξ±}\n (h1 : x = y) (h2 : evalDist oa = evalDist oa') : [= x | oa] = [= y | oa']" }, { "name": "probEvent_comp", "content": "lemma probEvent_comp (q : Ξ² β†’ Prop) : [q ∘ f | oa] = [q | f <$> oa]" }, { "name": "probEvent_map", "content": "@[simp]\nlemma probEvent_map (q : Ξ² β†’ Prop) : [q | f <$> oa] = [q ∘ f | oa]" }, { "name": "evalDist_map", "content": "@[simp]\nlemma evalDist_map (oa : OracleComp spec Ξ±) (f : Ξ± β†’ Ξ²) :\n evalDist (f <$> oa) = f <$> (evalDist oa)" } ]
[]
[ { "name": "OracleComp.support_seq", "content": "@[simp low]\nlemma support_seq : (og <*> oa).support = ⋃ g ∈ og.support, g '' oa.support" }, { "name": "OracleComp.support_seq_map_eq_image2", "content": "@[simp low + 1]\nlemma support_seq_map_eq_image2 :\n (f <$> oa <*> ob).support = Set.image2 f oa.support ob.support" } ]
import VCVio.OracleComp.DistSemantics.Monad namespace OracleComp variable {ΞΉ : Type u} {spec : OracleSpec ΞΉ} {Ξ± Ξ² Ξ³ : Type v} variable (oa : OracleComp spec Ξ±) (og : OracleComp spec (Ξ± β†’ Ξ²)) section seq_map variable (oa : OracleComp spec Ξ±) (ob : OracleComp spec Ξ²) (f : Ξ± β†’ Ξ² β†’ Ξ³)
lemma probEvent_seq_map_eq_probEvent_comp_uncurry [spec.FiniteRange] (p : Ξ³ β†’ Prop) : [p | f <$> oa <*> ob] = [p ∘ f.uncurry | Prod.mk <$> oa <*> ob] :=
:= by rw [probEvent_comp] refine probEvent_congr' ?_ (congr_arg evalDist ?_) Β· simp only [support_seq_map_eq_image2, Set.mem_image2, support_map, Set.image2_mk_eq_prod, Set.image_uncurry_prod, implies_true] Β· simp only [map_seq, Function.comp, Functor.map_map, Function.uncurry_apply_pair] rfl
6
60
true
Applied verif.
461
OracleComp.liftM_inj
@[simp] lemma liftM_inj (q q' : OracleQuery spec Ξ±) : (q : OracleComp spec Ξ±) = q' ↔ q = q'
VCV-io
VCVio/OracleComp/OracleComp.lean
[ "import ToMathlib.Control.AlternativeMonad", "import ToMathlib.Control.Monad.Free", "import VCVio.OracleComp.OracleSpec", "import ToMathlib.Control.WriterT", "import Mathlib.Control.Lawful", "import ToMathlib.Control.OptionT" ]
[ { "name": "inline", "module": "Init.Core" }, { "name": "OptionT", "module": "Init.Control.Option" }, { "name": "OptionT.lift", "module": "Init.Control.Option" }, { "name": "OptionT.mk", "module": "Init.Control.Option" } ]
[ { "name": "domain", "content": "@[inline, reducible]\nprotected def domain (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type v := (spec i).1" }, { "name": "OracleSpec", "content": "def OracleSpec (ΞΉ : Type u) : Type (max u (v + 1)) :=\n (i : ΞΉ) β†’ Type v Γ— Type v" }, { "name": "range", "content": "@[inline, reducible]\nprotected def range (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type w := (spec i).2" }, { "name": "FreeMonad", "content": "inductive FreeMonad (f : Type u β†’ Type v) (Ξ± : Type w) : Type (max (u + 1) v w)\n | protected pure (x : Ξ±) : FreeMonad f Ξ±\n | roll {Ξ² : Type u} (x : f Ξ²) (r : Ξ² β†’ FreeMonad f Ξ±) : FreeMonad f Ξ±" }, { "name": "lift", "content": "@[always_inline, inline]\ndef lift (x : f Ξ±) : FreeMonad f Ξ± := FreeMonad.roll x FreeMonad.pure" }, { "name": "bind", "content": "@[always_inline, inline]\nprotected def bind : FreeMonad f Ξ± β†’ (Ξ± β†’ FreeMonad f Ξ²) β†’ FreeMonad f Ξ²\n | FreeMonad.pure x, g => g x\n | FreeMonad.roll x r, g => FreeMonad.roll x (Ξ» u ↦ FreeMonad.bind (r u) g)" }, { "name": "notation:50 m₁ \" >>=β‚• \" mβ‚‚ => bind m₁ mβ‚‚", "content": "notation:50 m₁ \" >>=β‚• \" mβ‚‚ => bind m₁ mβ‚‚" } ]
[ { "name": "and_true", "module": "Init.SimpLemmas" }, { "name": "heq_eq_eq", "module": "Init.SimpLemmas" }, { "name": "true_and", "module": "Init.SimpLemmas" } ]
[ { "name": "monad_bind_def", "content": "@[simp]\nlemma monad_bind_def (x : FreeMonad f Ξ±) (g : Ξ± β†’ FreeMonad f Ξ²) :\n x >>= g = FreeMonad.bind x g" }, { "name": "bind_lift", "content": "@[simp]\nlemma bind_lift (x : f Ξ±) (r : Ξ± β†’ FreeMonad f Ξ²) :\n FreeMonad.bind (FreeMonad.lift x) r = FreeMonad.roll x r" }, { "name": "monad_pure_def", "content": "@[simp]\nlemma monad_pure_def (x : Ξ±) : (pure x : FreeMonad f Ξ±) = FreeMonad.pure x" } ]
[ { "name": "OracleSpec.OracleQuery", "content": "inductive OracleQuery {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) : Type v β†’ Type (max u v)\n | query (i : ΞΉ) (t : spec.domain i) : OracleQuery spec (spec.range i)" }, { "name": "OracleComp", "content": "def OracleComp {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) :\n Type w β†’ Type (max u (v + 1) w) :=\n OptionT (FreeMonad (OracleQuery.{u,v} spec))" } ]
[ { "name": "OracleComp.liftM_def", "content": "protected lemma liftM_def (q : OracleQuery spec Ξ±) :\n (q : OracleComp spec Ξ±) = OptionT.lift (FreeMonad.lift q)" } ]
import ToMathlib.Control.Monad.Free import ToMathlib.Control.WriterT import ToMathlib.Control.AlternativeMonad import ToMathlib.Control.OptionT import Mathlib.Control.Lawful import VCVio.OracleComp.OracleSpec namespace OracleSpec inductive OracleQuery {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) : Type v β†’ Type (max u v) | query (i : ΞΉ) (t : spec.domain i) : OracleQuery spec (spec.range i) namespace OracleQuery variable {ΞΉ : Type u} {spec : OracleSpec ΞΉ} {Ξ± Ξ² : Type v} end OracleQuery end OracleSpec open OracleSpec def OracleComp {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) : Type w β†’ Type (max u (v + 1) w) := OptionT (FreeMonad (OracleQuery.{u,v} spec)) namespace OracleComp variable {ΞΉ : Type u} {spec : OracleSpec ΞΉ} {Ξ± Ξ² : Type v} section lift end lift notation "$[0.." n "]" => uniformFin n notation:50 "$[" n "β‹―" m "]" => uniformFin' n m example : OracleComp probSpec β„• := do let x ← $[314β‹―31415]; let y ← $[0β‹―x] return x + 2 * y section construct variable {C : OracleComp spec Ξ± β†’ Type w} (h_pure : (a : Ξ±) β†’ C (pure a)) (h_query_bind : {Ξ² : Type v} β†’ (q : OracleQuery spec Ξ²) β†’ (oa : Ξ² β†’ OracleComp spec Ξ±) β†’ ((u : Ξ²) β†’ C (oa u)) β†’ C (q >>= oa)) (h_failure : C failure) (oa : OracleComp spec Ξ±) end construct section noConfusion variable (x : Ξ±) (y : Ξ²) (q : OracleQuery spec Ξ²) (oa : Ξ² β†’ OracleComp spec Ξ±) end noConfusion section mapM variable {m : Type v β†’ Type w} [Monad m] (fail : {Ξ± : Type v} β†’ m Ξ±) (qm : {Ξ± : Type v} β†’ OracleQuery spec Ξ± β†’ m Ξ±) end mapM section inj
@[simp] lemma liftM_inj (q q' : OracleQuery spec Ξ±) : (q : OracleComp spec Ξ±) = q' ↔ q = q' :=
:= by simp only [OracleComp.liftM_def, OptionT.lift, OptionT.mk, FreeMonad.monad_pure_def, FreeMonad.monad_bind_def, FreeMonad.bind_lift] rw [FreeMonad.roll.injEq] simp only [heq_eq_eq, and_true, true_and]
3
19
false
Applied verif.
462
PFunctor.Lens.prodPair_fst_snd
@[simp] theorem prodPair_fst_snd : Lens.prodPair Lens.fst Lens.snd = Lens.id.{max uA₁ uAβ‚‚, max uB₁ uBβ‚‚} (P * Q)
VCV-io
ToMathlib/PFunctor/Lens/Basic.lean
[ "import ToMathlib.PFunctor.Basic" ]
[ { "name": "PFunctor", "module": "Mathlib.Data.PFunctor.Univariate.Basic" }, { "name": "Sum", "module": "Init.Core" }, { "name": "Sum.elim", "module": "Init.Data.Sum.Basic" }, { "name": "Prod", "module": "Init.Prelude" }, { "name": "Prod.snd", "module": "Init.Prelude" }, { "name": "Sum.inr", "module": "Init.Core" }, { "name": "Prod.fst", "module": "Init.Prelude" }, { "name": "Sum.inl", "module": "Init.Core" } ]
[ { "name": "prodPair", "content": "notation \"⟨\" l₁ \",\" lβ‚‚ \"βŸ©β‚—\" => prodPair l₁ lβ‚‚" }, { "name": "Lens", "content": "structure Lens (P : PFunctor.{uA₁, uB₁}) (Q : PFunctor.{uAβ‚‚, uBβ‚‚}) where\n toFunA : P.A β†’ Q.A\n toFunB : βˆ€ a, Q.B (toFunA a) β†’ P.B a" }, { "name": "Chart", "content": "structure Chart (P : PFunctor.{uA₁, uB₁}) (Q : PFunctor.{uAβ‚‚, uBβ‚‚}) where\n toFunA : P.A β†’ Q.A\n toFunB : βˆ€ a, P.B a β†’ Q.B (toFunA a)" } ]
[ { "name": "...", "module": "" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "PFunctor.Lens.prodPair", "content": "def prodPair {P : PFunctor.{uA₁, uB₁}} {Q : PFunctor.{uAβ‚‚, uBβ‚‚}} {R : PFunctor.{uA₃, uB₃}}\n (l₁ : Lens P Q) (lβ‚‚ : Lens P R) :\n Lens.{uA₁, uB₁, max uAβ‚‚ uA₃, max uBβ‚‚ uB₃} P (Q * R) :=\n (fun p => (l₁.toFunA p, lβ‚‚.toFunA p)) ⇆\n (fun p => Sum.elim (l₁.toFunB p) (lβ‚‚.toFunB p))" } ]
[ { "name": "PFunctor.Lens.ext", "content": "@[ext (iff := false)]\ntheorem ext {P : PFunctor.{uA₁, uB₁}} {Q : PFunctor.{uAβ‚‚, uBβ‚‚}} (l₁ lβ‚‚ : Lens P Q)\n (h₁ : βˆ€ a, l₁.toFunA a = lβ‚‚.toFunA a) (hβ‚‚ : βˆ€ a, l₁.toFunB a = (h₁ a) β–Έ lβ‚‚.toFunB a) :\n l₁ = lβ‚‚" } ]
import ToMathlib.PFunctor.Basic section find_home variable {Ξ± : Sort u} {Ξ² : Ξ± β†’ Sort v} {Ξ³ : Ξ± β†’ Sort v} end find_home namespace PFunctor namespace Lens @[inherit_doc] infixl:75 " βˆ˜β‚— " => comp @[inherit_doc] infix:50 " ≃ₗ " => Equiv namespace Equiv end Equiv def prodPair {P : PFunctor.{uA₁, uB₁}} {Q : PFunctor.{uAβ‚‚, uBβ‚‚}} {R : PFunctor.{uA₃, uB₃}} (l₁ : Lens P Q) (lβ‚‚ : Lens P R) : Lens.{uA₁, uB₁, max uAβ‚‚ uA₃, max uBβ‚‚ uB₃} P (Q * R) := (fun p => (l₁.toFunA p, lβ‚‚.toFunA p)) ⇆ (fun p => Sum.elim (l₁.toFunB p) (lβ‚‚.toFunB p)) @[inherit_doc] infixl:75 " β—ƒβ‚— " => compMap @[inherit_doc] infixl:75 " Γ—β‚— " => prodMap @[inherit_doc] infixl:75 " βŠŽβ‚— " => sumMap @[inherit_doc] infixl:75 " βŠ—β‚— " => tensorMap notation "[" l₁ "," lβ‚‚ "]β‚—" => sumPair l₁ lβ‚‚ notation "⟨" l₁ "," lβ‚‚ "βŸ©β‚—" => prodPair l₁ lβ‚‚ section Coprod variable {P : PFunctor.{uA₁, uB₁}} {Q : PFunctor.{uAβ‚‚, uB₁}} {R : PFunctor.{uA₃, uB₃}} {W : PFunctor.{uAβ‚„, uB₃}} {X : PFunctor.{uAβ‚…, uBβ‚…}} namespace Equiv variable {P : PFunctor.{uA₁, uB}} {Q : PFunctor.{uAβ‚‚, uB}} {R : PFunctor.{uA₃, uB}} end Equiv end Coprod section Prod variable {P : PFunctor.{uA₁, uB₁}} {Q : PFunctor.{uAβ‚‚, uBβ‚‚}} {R : PFunctor.{uA₃, uB₃}} {W : PFunctor.{uAβ‚„, uBβ‚„}} {X : PFunctor.{uAβ‚…, uBβ‚…}}
@[simp] theorem prodPair_fst_snd : Lens.prodPair Lens.fst Lens.snd = Lens.id.{max uA₁ uAβ‚‚, max uB₁ uBβ‚‚} (P * Q) :=
:= by ext a x Β· rfl Β· cases x <;> rfl
2
15
true
Applied verif.
463
OracleSpec.QuerySeed.eq_takeAtIndex_length_iff
lemma eq_takeAtIndex_length_iff (seed seed' : QuerySeed spec) (i : ΞΉ) : seed = seed'.takeAtIndex i (seed i).length ↔ seed' = seed.addValues ((seed' i).drop (seed i).length)
VCV-io
VCVio/OracleComp/QueryTracking/Structures.lean
[ "import VCVio.OracleComp.SimSemantics.SimulateQ" ]
[ { "name": "inline", "module": "Init.Core" }, { "name": "List", "module": "Init.Prelude" }, { "name": "Function.update", "module": "Mathlib.Logic.Function.Basic" }, { "name": "OptionT", "module": "Init.Control.Option" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "List.length", "module": "Init.Prelude" }, { "name": "DFunLike", "module": "Mathlib.Data.FunLike.Basic" } ]
[ { "name": "OracleSpec", "content": "def OracleSpec (ΞΉ : Type u) : Type (max u (v + 1)) :=\n (i : ΞΉ) β†’ Type v Γ— Type v" }, { "name": "range", "content": "@[inline, reducible]\nprotected def range (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type w := (spec i).2" }, { "name": "DecidableEq", "content": "protected class DecidableEq (spec : OracleSpec ΞΉ) where\n domain_decidableEq' (i : ΞΉ) : DecidableEq (spec.domain i)\n range_decidableEq' (i : ΞΉ) : DecidableEq (spec.range i)" }, { "name": "domain", "content": "@[inline, reducible]\nprotected def domain (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type v := (spec i).1" }, { "name": "induction", "content": "@[elab_as_elim]\nprotected def induction {C : OracleComp spec Ξ± β†’ Prop}\n (oa : OracleComp spec Ξ±) (pure : (a : Ξ±) β†’ C (pure a))\n (query_bind : (i : ΞΉ) β†’ (t : spec.domain i) β†’\n (oa : spec.range i β†’ OracleComp spec Ξ±) β†’ (βˆ€ u, C (oa u)) β†’ C (query i t >>= oa))\n (failure : C failure) : C oa :=\n FreeMonad.inductionOn (Option.rec failure pure) (Ξ» (query i t) ↦ query_bind i t) oa" }, { "name": "OracleQuery", "content": "inductive OracleQuery {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) : Type v β†’ Type (max u v)\n | query (i : ΞΉ) (t : spec.domain i) : OracleQuery spec (spec.range i)" }, { "name": "OracleComp", "content": "def OracleComp {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) :\n Type w β†’ Type (max u (v + 1) w) :=\n OptionT (FreeMonad (OracleQuery.{u,v} spec))" }, { "name": "FreeMonad", "content": "inductive FreeMonad (f : Type u β†’ Type v) (Ξ± : Type w) : Type (max (u + 1) v w)\n | protected pure (x : Ξ±) : FreeMonad f Ξ±\n | roll {Ξ² : Type u} (x : f Ξ²) (r : Ξ² β†’ FreeMonad f Ξ±) : FreeMonad f Ξ±" }, { "name": "inductionOn", "content": "@[elab_as_elim]\nprotected def inductionOn {C : FreeMonad f Ξ± β†’ Prop}\n (pure : βˆ€ x, C (pure x))\n (roll : βˆ€ {Ξ²} (x : f Ξ²), (r : Ξ² β†’ FreeMonad f Ξ±) β†’\n (βˆ€ y, C (r y)) β†’ C (x >>= r)) :\n (oa : FreeMonad f Ξ±) β†’ C oa\n | FreeMonad.pure x => pure x\n | FreeMonad.roll x r => roll x _ (Ξ» u ↦\n FreeMonad.inductionOn pure roll (r u))\n\n/-- Add a list of values to the query seed.-/\ndef addValues [DecidableEq ΞΉ] {i : ΞΉ}\n (us : List (spec.range i)) (seed : QuerySeed spec) : QuerySeed spec :=\n Function.update seed i (seed i ++ us)\n\n/-- Take only the first `n` values of the seed at index `i`. -/\ndef takeAtIndex [DecidableEq ΞΉ] (seed : QuerySeed spec) (i : ΞΉ) (n : β„•) : QuerySeed spec :=\n Function.update seed i ((seed i).take n)" } ]
[ { "name": "congr_arg", "module": "Batteries.Logic" }, { "name": "congr_fun", "module": "Batteries.Logic" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "OracleSpec.QuerySeed", "content": "def QuerySeed (spec : OracleSpec ΞΉ) : Type _ :=\n (i : ΞΉ) β†’ List (spec.range i)" } ]
[]
import VCVio.OracleComp.SimSemantics.SimulateQ open OracleSpec OracleComp namespace OracleSpec variable {ΞΉ : Type u} {spec : OracleSpec ΞΉ} namespace QueryCache variable [spec.DecidableEq] [DecidableEq ΞΉ] (cache : QueryCache spec) end QueryCache namespace QueryCount end QueryCount namespace QueryLog section getQ variable [DecidableEq ΞΉ] end getQ section countQ variable [DecidableEq ΞΉ] end countQ section prod variable {ι₁ ΞΉβ‚‚ : Type*} {spec₁ : OracleSpec ι₁} {specβ‚‚ : OracleSpec ΞΉβ‚‚} end prod end QueryLog def QuerySeed (spec : OracleSpec ΞΉ) : Type _ := (i : ΞΉ) β†’ List (spec.range i) namespace QuerySeed section addValues variable [DecidableEq ΞΉ] {i : ΞΉ} (seed : QuerySeed spec) (us : List (spec.range i)) end addValues section takeAtIndex variable [DecidableEq ΞΉ] (seed : QuerySeed spec) (i : ΞΉ) (n : β„•)
lemma eq_takeAtIndex_length_iff (seed seed' : QuerySeed spec) (i : ΞΉ) : seed = seed'.takeAtIndex i (seed i).length ↔ seed' = seed.addValues ((seed' i).drop (seed i).length) :=
:= by refine ⟨λ h ↦ QuerySeed.ext _ _ (Ξ» j ↦ ?_), Ξ» h ↦ ?_⟩ Β· by_cases hj : j = i Β· induction hj rw [h] suffices (seed j).length ≀ (seed' j).length by simp [this] simpa using congr_arg List.length (congr_fun h j) Β· rw [h] simp [hj] Β· rw [h] simp
4
21
false
Applied verif.
464
OracleComp.allWhen_bind_iff
@[simp] lemma allWhen_bind_iff (oa : OracleComp spec Ξ±) (ob : Ξ± β†’ OracleComp spec Ξ²) : (oa >>= ob).allWhen Q F possible_outputs ↔ oa.allWhen Q F possible_outputs ∧ βˆ€ x ∈ oa.supportWhen possible_outputs, (ob x).allWhen Q F possible_outputs
VCV-io
VCVio/OracleComp/Traversal.lean
[ "import VCVio.OracleComp.Support" ]
[ { "name": "inline", "module": "Init.Core" }, { "name": "OptionT", "module": "Init.Control.Option" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "Set", "module": "Mathlib.Data.Set.Defs" }, { "name": "Or", "module": "Init.Prelude" } ]
[ { "name": "induction", "content": "@[elab_as_elim]\nprotected def induction {C : OracleComp spec Ξ± β†’ Prop}\n (oa : OracleComp spec Ξ±) (pure : (a : Ξ±) β†’ C (pure a))\n (query_bind : (i : ΞΉ) β†’ (t : spec.domain i) β†’\n (oa : spec.range i β†’ OracleComp spec Ξ±) β†’ (βˆ€ u, C (oa u)) β†’ C (query i t >>= oa))\n (failure : C failure) : C oa :=\n FreeMonad.inductionOn (Option.rec failure pure) (Ξ» (query i t) ↦ query_bind i t) oa" }, { "name": "OracleQuery", "content": "inductive OracleQuery {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) : Type v β†’ Type (max u v)\n | query (i : ΞΉ) (t : spec.domain i) : OracleQuery spec (spec.range i)" }, { "name": "OracleComp", "content": "def OracleComp {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) :\n Type w β†’ Type (max u (v + 1) w) :=\n OptionT (FreeMonad (OracleQuery.{u,v} spec))" }, { "name": "domain", "content": "@[inline, reducible]\nprotected def domain (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type v := (spec i).1" }, { "name": "OracleSpec", "content": "def OracleSpec (ΞΉ : Type u) : Type (max u (v + 1)) :=\n (i : ΞΉ) β†’ Type v Γ— Type v" }, { "name": "range", "content": "@[inline, reducible]\nprotected def range (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type w := (spec i).2" }, { "name": "FreeMonad", "content": "inductive FreeMonad (f : Type u β†’ Type v) (Ξ± : Type w) : Type (max (u + 1) v w)\n | protected pure (x : Ξ±) : FreeMonad f Ξ±\n | roll {Ξ² : Type u} (x : f Ξ²) (r : Ξ² β†’ FreeMonad f Ξ±) : FreeMonad f Ξ±" }, { "name": "inductionOn", "content": "@[elab_as_elim]\nprotected def inductionOn {C : FreeMonad f Ξ± β†’ Prop}\n (pure : βˆ€ x, C (pure x))\n (roll : βˆ€ {Ξ²} (x : f Ξ²), (r : Ξ² β†’ FreeMonad f Ξ±) β†’\n (βˆ€ y, C (r y)) β†’ C (x >>= r)) :\n (oa : FreeMonad f Ξ±) β†’ C oa\n | FreeMonad.pure x => pure x\n | FreeMonad.roll x r => roll x _ (Ξ» u ↦\n FreeMonad.inductionOn pure roll (r u))" }, { "name": "construct", "content": "@[elab_as_elim]\nprotected def construct {C : OracleComp spec Ξ± β†’ Type*}\n (pure : (a : Ξ±) β†’ C (pure a))\n (query_bind : {Ξ² : Type v} β†’ (q : OracleQuery spec Ξ²) β†’\n (oa : Ξ² β†’ OracleComp spec Ξ±) β†’ ((u : Ξ²) β†’ C (oa u)) β†’ C (q >>= oa))\n (failure : C failure) (oa : OracleComp spec Ξ±) : C oa :=\n FreeMonad.construct (Option.rec failure pure) query_bind oa" }, { "name": "construct", "content": "@[elab_as_elim]\nprotected def construct {C : FreeMonad f Ξ± β†’ Type*}\n (pure : (x : Ξ±) β†’ C (pure x))\n (roll : {Ξ² : Type u} β†’ (x : f Ξ²) β†’ (r : Ξ² β†’ FreeMonad f Ξ±) β†’\n ((y : Ξ²) β†’ C (r y)) β†’ C (x >>= r)) :\n (oa : FreeMonad f Ξ±) β†’ C oa\n | .pure x => pure x\n | .roll x r => roll x _ (Ξ» u ↦ FreeMonad.construct pure roll (r u))" }, { "name": "supportWhen", "content": "def supportWhen (oa : OracleComp spec Ξ±)\n (possible_outputs : {Ξ± : Type v} β†’ OracleQuery spec Ξ± β†’ Set Ξ±) : Set Ξ± :=" }, { "name": "inductionOn", "content": "@[elab_as_elim]\nprotected def inductionOn {C : OracleComp spec Ξ± β†’ Prop}\n (pure : (a : Ξ±) β†’ C (pure a))\n (query_bind : (i : ΞΉ) β†’ (t : spec.domain i) β†’\n (oa : spec.range i β†’ OracleComp spec Ξ±) β†’ (βˆ€ u, C (oa u)) β†’ C (query i t >>= oa))\n (failure : C failure) (oa : OracleComp spec Ξ±) : C oa :=\n FreeMonad.inductionOn (Option.rec failure pure) (Ξ» (query i t) ↦ query_bind i t) oa" } ]
[ { "name": "...", "module": "" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "OracleComp.allWhen", "content": "def allWhen (possible_outputs : {Ξ± : Type v} β†’ OracleQuery spec Ξ± β†’ Set Ξ±)\n (oa : OracleComp spec Ξ±) : Prop :=" } ]
[ { "name": "OracleComp.allWhen_query_bind", "content": "@[simp] lemma allWhen_query_bind (q : OracleQuery spec Ξ±) (oa : Ξ± β†’ OracleComp spec Ξ²) :\n ((q : OracleComp spec Ξ±) >>= oa).allWhen Q F possible_outputs ↔\n Q q ∧ βˆ€ x ∈ possible_outputs q, (oa x).allWhen Q F possible_outputs" } ]
import VCVio.OracleComp.Support open OracleSpec namespace OracleComp variable {ΞΉ : Type u} {spec : OracleSpec ΞΉ} {Ξ± Ξ² Ξ³ : Type v} section When variable (Q : {Ξ± : Type v} β†’ OracleQuery spec Ξ± β†’ Prop) (F : Prop) (oa : OracleComp spec Ξ±) (possible_outputs : {Ξ± : Type v} β†’ OracleQuery spec Ξ± β†’ Set Ξ±) def allWhen (possible_outputs : {Ξ± : Type v} β†’ OracleQuery spec Ξ± β†’ Set Ξ±) (oa : OracleComp spec Ξ±) : Prop :=
@[simp] lemma allWhen_bind_iff (oa : OracleComp spec Ξ±) (ob : Ξ± β†’ OracleComp spec Ξ²) : (oa >>= ob).allWhen Q F possible_outputs ↔ oa.allWhen Q F possible_outputs ∧ βˆ€ x ∈ oa.supportWhen possible_outputs, (ob x).allWhen Q F possible_outputs :=
:= by induction oa using OracleComp.inductionOn with | pure x => { simp [supportWhen] } | failure => { simp [supportWhen] } | query_bind i t oa h => { rw [bind_assoc, allWhen_query_bind] simp [h, supportWhen] grind only [cases Or] }
4
19
false
Applied verif.
465
OracleComp.probFailure_liftM
@[simp] lemma probFailure_liftM (q : OracleQuery spec Ξ±) : [βŠ₯ | (q : OracleComp spec _)] = 0
VCV-io
VCVio/OracleComp/DistSemantics/EvalDist.lean
[ "import Mathlib.Probability.Distributions.Uniform", "import VCVio.OracleComp.SimSemantics.SimulateQ", "import VCVio.OracleComp.Traversal", "import ToMathlib.General" ]
[ { "name": "inline", "module": "Init.Core" }, { "name": "OptionT", "module": "Init.Control.Option" }, { "name": "ENNReal", "module": "Mathlib.Data.ENNReal.Basic" }, { "name": "Fintype", "module": "Mathlib.Data.Fintype.Defs" }, { "name": "Inhabited", "module": "Init.Prelude" }, { "name": "PMF", "module": "Mathlib.Probability.ProbabilityMassFunction.Basic" }, { "name": "Vector", "module": "Init.Data.Vector.Basic" }, { "name": "Vector.insertIdx", "module": "Init.Data.Vector.Basic" }, { "name": "Nonempty", "module": "Init.Prelude" }, { "name": "OptionT.lift", "module": "Init.Control.Option" }, { "name": "PMF.uniformOfFintype", "module": "Mathlib.Probability.Distributions.Uniform" }, { "name": "Finset", "module": "Mathlib.Data.Finset.Defs" }, { "name": "Finset.card", "module": "Mathlib.Data.Finset.Card" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "impl", "module": "Mathlib.Deprecated.MLList.BestFirst" }, { "name": "Bind", "module": "Init.Prelude" }, { "name": "Pure", "module": "Init.Prelude" }, { "name": "AlternativeMonad", "module": "Batteries.Control.AlternativeMonad" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "Option.getM", "module": "Init.Data.Option.Basic" } ]
[ { "name": "probFailure", "content": "notation \"[βŠ₯\" \"|\" oa \"]\" => probFailure oa" }, { "name": "HasEvalDist", "content": "class HasEvalDist (m : Type u β†’ Type v) [Monad m] where\n evalDist {Ξ± : Type u} (mx : m Ξ±) : SPMF Ξ±\n evalDist_pure {Ξ± : Type u} (x : Ξ±) : evalDist (pure x : m Ξ±) = pure x\n evalDist_bind {Ξ± Ξ² : Type u} (mx : m Ξ±) (my : Ξ± β†’ m Ξ²) :\n evalDist (mx >>= my) = evalDist mx >>= fun x => evalDist (my x)" }, { "name": "OracleComp", "content": "def OracleComp {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) :\n Type w β†’ Type (max u (v + 1) w) :=\n OptionT (FreeMonad (OracleQuery.{u,v} spec))" }, { "name": "OracleQuery", "content": "inductive OracleQuery {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) : Type v β†’ Type (max u v)\n | query (i : ΞΉ) (t : spec.domain i) : OracleQuery spec (spec.range i)" }, { "name": "domain", "content": "@[inline, reducible]\nprotected def domain (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type v := (spec i).1" }, { "name": "OracleSpec", "content": "def OracleSpec (ΞΉ : Type u) : Type (max u (v + 1)) :=\n (i : ΞΉ) β†’ Type v Γ— Type v" }, { "name": "range", "content": "@[inline, reducible]\nprotected def range (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type w := (spec i).2" }, { "name": "FreeMonad", "content": "inductive FreeMonad (f : Type u β†’ Type v) (Ξ± : Type w) : Type (max (u + 1) v w)\n | protected pure (x : Ξ±) : FreeMonad f Ξ±\n | roll {Ξ² : Type u} (x : f Ξ²) (r : Ξ² β†’ FreeMonad f Ξ±) : FreeMonad f Ξ±" }, { "name": "cases", "content": "def cases {Ξ±} {motive : {n : β„•} β†’ Vector Ξ± n β†’ Sort*} (v_empty : motive #v[])\n (v_insert : {n : β„•} β†’ (hd : Ξ±) β†’ (tl : Vector Ξ± n) β†’ motive (tl.insertIdx 0 hd)) {m : β„•} :\n (v : Vector Ξ± m) β†’ motive v := match hm : m with\n | 0 => fun v => match v with | ⟨⟨[]⟩, rfl⟩ => v_empty\n | n + 1 => fun v => match hv : v with\n | ⟨⟨hd :: tl⟩, hSize⟩ => by admit /- proof elided -/" }, { "name": "simulateQ", "content": "def simulateQ [AlternativeMonad m] (so : QueryImpl spec m) (oa : OracleComp spec Ξ±) : m Ξ± :=\n do Option.getM (← FreeMonad.mapM oa.run so.impl)" }, { "name": "QueryImpl.Inhabited", "content": "instance QueryImpl.Inhabited [βˆ€ i, Inhabited (spec.range i)] [Pure m] :\n Inhabited (QueryImpl spec m) := ⟨{impl q := pure q.defaultOutput}⟩" }, { "name": "mapM", "content": "protected def mapM [Pure m] [Bind m] :\n (oa : FreeMonad f Ξ±) β†’ (s : {Ξ± : Type u} β†’ f Ξ± β†’ m Ξ±) β†’ m Ξ±\n | .pure x, _ => pure x\n | .roll x r, s => s x >>= Ξ» u ↦ (r u).mapM s" } ]
[ { "name": "Nat.cast_inj", "module": "Mathlib.Algebra.CharZero.Defs" }, { "name": "PMF.uniformOfFintype_apply", "module": "Mathlib.Probability.Distributions.Uniform" }, { "name": "congr_arg", "module": "Batteries.Logic" }, { "name": "inv_inj", "module": "Mathlib.Algebra.Group.Basic" }, { "name": "monadLift_self", "module": "Init.Control.Lawful.Basic" }, { "name": "ENNReal.inv_eq_zero", "module": "Mathlib.Data.ENNReal.Inv" }, { "name": "ENNReal.natCast_ne_top", "module": "Mathlib.Data.ENNReal.Basic" }, { "name": "ENNReal.tsum_eq_zero", "module": "Mathlib.Topology.Instances.ENNReal.Lemmas" }, { "name": "PMF.bind_apply", "module": "Mathlib.Probability.ProbabilityMassFunction.Monad" }, { "name": "PMF.pure_apply", "module": "Mathlib.Probability.ProbabilityMassFunction.Monad" }, { "name": "false_or", "module": "Init.SimpLemmas" }, { "name": "mul_eq_zero", "module": "Mathlib.Algebra.GroupWithZero.Defs" } ]
[ { "name": "simulateQ_query", "content": "@[simp] lemma simulateQ_query (q : OracleQuery spec Ξ±) : simulateQ so q = so.impl q" } ]
[ { "name": "OracleComp.probFailure", "content": "noncomputable def probFailure (oa : OracleComp spec Ξ±) : ℝβ‰₯0∞ :=\n (evalDist oa).run none" } ]
[ { "name": "OracleComp.evalDist_liftM", "content": "@[simp]\nlemma evalDist_liftM [Nonempty Ξ±] [Fintype Ξ±] (q : OracleQuery spec Ξ±) :\n evalDist (q : OracleComp spec Ξ±) = OptionT.lift (PMF.uniformOfFintype Ξ±)" } ]
import VCVio.OracleComp.Traversal import VCVio.OracleComp.SimSemantics.SimulateQ import Mathlib.Probability.Distributions.Uniform import ToMathlib.General open OracleSpec Option ENNReal BigOperators namespace OracleComp variable {ΞΉ : Type u} {spec : OracleSpec ΞΉ} {ΞΉ' : Type v} {spec' : OracleSpec ΞΉ'} {Ξ± Ξ² Ξ³ : Type w} [spec.FiniteRange] [spec'.FiniteRange] section evalDist end evalDist notation "[=" x "|" oa "]" => probOutput oa x noncomputable def probFailure (oa : OracleComp spec Ξ±) : ℝβ‰₯0∞ := (evalDist oa).run none notation "[βŠ₯" "|" oa "]" => probFailure oa notation "[" p "|" oa "]" => probEvent oa p section bounds variable {oa : OracleComp spec Ξ±} {x : Ξ±} {p : Ξ± β†’ Prop} end bounds section support variable (oa : OracleComp spec Ξ±) (x : Ξ±) (p q : Ξ± β†’ Prop) variable {oa x p q} end support section sums variable (oa : OracleComp spec Ξ±) (p : Ξ± β†’ Prop) end sums section pure variable (x : Ξ±) end pure section bind variable (oa : OracleComp spec Ξ±) (ob : Ξ± β†’ OracleComp spec Ξ²) end bind section mul_le_probEvent_bind end mul_le_probEvent_bind section bind_const variable (oa : OracleComp spec Ξ±) (ob : OracleComp spec Ξ²) end bind_const section query variable (i : ΞΉ) (t : spec.domain i)
@[simp] lemma probFailure_liftM (q : OracleQuery spec Ξ±) : [βŠ₯ | (q : OracleComp spec _)] = 0 :=
:= by have : Fintype Ξ± := q.rangeFintype have : Inhabited Ξ± := q.rangeInhabited simp only [probFailure, evalDist_liftM] erw [PMF.bind_apply] simp only [PMF.uniformOfFintype_apply, ENNReal.tsum_eq_zero, mul_eq_zero, ENNReal.inv_eq_zero, natCast_ne_top, false_or] intro i erw [PMF.pure_apply] simp
5
43
false
Applied verif.
466
OracleComp.probOutput_seq_map_eq_mul
lemma probOutput_seq_map_eq_mul [spec.FiniteRange] (x : Ξ±) (y : Ξ²) (z : Ξ³) (h : βˆ€ x' ∈ oa.support, βˆ€ y' ∈ ob.support, z = f x' y' ↔ x' = x ∧ y' = y) : [= z | f <$> oa <*> ob] = [= x | oa] * [= y | ob]
VCV-io
VCVio/OracleComp/DistSemantics/Seq.lean
[ "import VCVio.OracleComp.DistSemantics.Monad", "import VCVio.OracleComp.DistSemantics.EvalDist" ]
[ { "name": "inline", "module": "Init.Core" }, { "name": "OptionT", "module": "Init.Control.Option" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "Set", "module": "Mathlib.Data.Set.Defs" }, { "name": "Set.univ", "module": "Mathlib.Data.Set.Defs" }, { "name": "Fintype", "module": "Mathlib.Data.Fintype.Defs" }, { "name": "Inhabited", "module": "Init.Prelude" }, { "name": "Classical.decEq", "module": "Mathlib.Logic.Basic" }, { "name": "DecidableEq", "module": "Init.Prelude" }, { "name": "ENNReal", "module": "Mathlib.Data.ENNReal.Basic" }, { "name": "Prod", "module": "Init.Prelude" }, { "name": "Prod.mk", "module": "Init.Prelude" }, { "name": "Function.comp", "module": "Init.Prelude" } ]
[ { "name": "probOutput", "content": "notation \"[=\" x \"|\" oa \"]\" => probOutput oa x" }, { "name": "probOutput", "content": "noncomputable def probOutput (oa : OracleComp spec Ξ±) (x : Ξ±) : ℝβ‰₯0∞ :=\n (evalDist oa).run (some x)" }, { "name": "HasEvalDist", "content": "class HasEvalDist (m : Type u β†’ Type v) [Monad m] where\n evalDist {Ξ± : Type u} (mx : m Ξ±) : SPMF Ξ±\n evalDist_pure {Ξ± : Type u} (x : Ξ±) : evalDist (pure x : m Ξ±) = pure x\n evalDist_bind {Ξ± Ξ² : Type u} (mx : m Ξ±) (my : Ξ± β†’ m Ξ²) :\n evalDist (mx >>= my) = evalDist mx >>= fun x => evalDist (my x)" }, { "name": "OracleComp", "content": "def OracleComp {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) :\n Type w β†’ Type (max u (v + 1) w) :=\n OptionT (FreeMonad (OracleQuery.{u,v} spec))" }, { "name": "OracleQuery", "content": "inductive OracleQuery {ΞΉ : Type u} (spec : OracleSpec.{u,v} ΞΉ) : Type v β†’ Type (max u v)\n | query (i : ΞΉ) (t : spec.domain i) : OracleQuery spec (spec.range i)" }, { "name": "domain", "content": "@[inline, reducible]\nprotected def domain (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type v := (spec i).1" }, { "name": "OracleSpec", "content": "def OracleSpec (ΞΉ : Type u) : Type (max u (v + 1)) :=\n (i : ΞΉ) β†’ Type v Γ— Type v" }, { "name": "range", "content": "@[inline, reducible]\nprotected def range (spec : OracleSpec ΞΉ) (i : ΞΉ) : Type w := (spec i).2" }, { "name": "FreeMonad", "content": "inductive FreeMonad (f : Type u β†’ Type v) (Ξ± : Type w) : Type (max (u + 1) v w)\n | protected pure (x : Ξ±) : FreeMonad f Ξ±\n | roll {Ξ² : Type u} (x : f Ξ²) (r : Ξ² β†’ FreeMonad f Ξ±) : FreeMonad f Ξ±" }, { "name": "support", "content": "def support (oa : OracleComp spec Ξ±) : Set Ξ± :=\n oa.supportWhen fun _ => Set.univ" }, { "name": "supportWhen", "content": "def supportWhen (oa : OracleComp spec Ξ±)\n (possible_outputs : {Ξ± : Type v} β†’ OracleQuery spec Ξ± β†’ Set Ξ±) : Set Ξ± :=" }, { "name": "induction", "content": "@[elab_as_elim]\nprotected def induction {C : OracleComp spec Ξ± β†’ Prop}\n (oa : OracleComp spec Ξ±) (pure : (a : Ξ±) β†’ C (pure a))\n (query_bind : (i : ΞΉ) β†’ (t : spec.domain i) β†’\n (oa : spec.range i β†’ OracleComp spec Ξ±) β†’ (βˆ€ u, C (oa u)) β†’ C (query i t >>= oa))\n (failure : C failure) : C oa :=\n FreeMonad.inductionOn (Option.rec failure pure) (Ξ» (query i t) ↦ query_bind i t) oa" }, { "name": "inductionOn", "content": "@[elab_as_elim]\nprotected def inductionOn {C : FreeMonad f Ξ± β†’ Prop}\n (pure : βˆ€ x, C (pure x))\n (roll : βˆ€ {Ξ²} (x : f Ξ²), (r : Ξ² β†’ FreeMonad f Ξ±) β†’\n (βˆ€ y, C (r y)) β†’ C (x >>= r)) :\n (oa : FreeMonad f Ξ±) β†’ C oa\n | FreeMonad.pure x => pure x\n | FreeMonad.roll x r => roll x _ (Ξ» u ↦\n FreeMonad.inductionOn pure roll (r u))" }, { "name": "construct", "content": "@[elab_as_elim]\nprotected def construct {C : OracleComp spec Ξ± β†’ Type*}\n (pure : (a : Ξ±) β†’ C (pure a))\n (query_bind : {Ξ² : Type v} β†’ (q : OracleQuery spec Ξ²) β†’\n (oa : Ξ² β†’ OracleComp spec Ξ±) β†’ ((u : Ξ²) β†’ C (oa u)) β†’ C (q >>= oa))\n (failure : C failure) (oa : OracleComp spec Ξ±) : C oa :=\n FreeMonad.construct (Option.rec failure pure) query_bind oa" }, { "name": "construct", "content": "@[elab_as_elim]\nprotected def construct {C : FreeMonad f Ξ± β†’ Type*}\n (pure : (x : Ξ±) β†’ C (pure x))\n (roll : {Ξ² : Type u} β†’ (x : f Ξ²) β†’ (r : Ξ² β†’ FreeMonad f Ξ±) β†’\n ((y : Ξ²) β†’ C (r y)) β†’ C (x >>= r)) :\n (oa : FreeMonad f Ξ±) β†’ C oa\n | .pure x => pure x\n | .roll x r => roll x _ (Ξ» u ↦ FreeMonad.construct pure roll (r u))" }, { "name": "FiniteRange", "content": "class FiniteRange (spec : OracleSpec ΞΉ) where\n range_inhabited' (i : ΞΉ) : Inhabited (spec.range i)\n range_fintype' (i : ΞΉ) : Fintype (spec.range i)" }, { "name": "DecidableEq", "content": "protected class DecidableEq (spec : OracleSpec ΞΉ) where\n domain_decidableEq' (i : ΞΉ) : DecidableEq (spec.domain i)\n range_decidableEq' (i : ΞΉ) : DecidableEq (spec.range i)" }, { "name": "inductionOn", "content": "@[elab_as_elim]\nprotected def inductionOn {C : OracleComp spec Ξ± β†’ Prop}\n (pure : (a : Ξ±) β†’ C (pure a))\n (query_bind : (i : ΞΉ) β†’ (t : spec.domain i) β†’\n (oa : spec.range i β†’ OracleComp spec Ξ±) β†’ (βˆ€ u, C (oa u)) β†’ C (query i t >>= oa))\n (failure : C failure) (oa : OracleComp spec Ξ±) : C oa :=\n FreeMonad.inductionOn (Option.rec failure pure) (Ξ» (query i t) ↦ query_bind i t) oa" }, { "name": "probOutput", "content": "notation \"Pr[=\" x \"|\" mx \"]\" => probOutput mx x" }, { "name": "probOutput", "content": "notation \"[=\" x \"|\" oa \"]\" => probOutput oa x" } ]
[ { "name": "ENNReal.tsum_mul_left", "module": "Mathlib.Topology.Instances.ENNReal.Lemmas" }, { "name": "map_eq_bind_pure_comp", "module": "Mathlib.Control.Monad.Basic" }, { "name": "mul_assoc", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "seq_eq_bind", "module": "Init.Control.Lawful.Basic" }, { "name": "mul_ite", "module": "Mathlib.Algebra.Notation.Defs" }, { "name": "mul_one", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "ENNReal.tsum_prod", "module": "Mathlib.Topology.Instances.ENNReal.Lemmas" }, { "name": "ite_eq_left_iff", "module": "Init.PropLemmas" }, { "name": "ite_eq_right_iff", "module": "Init.PropLemmas" }, { "name": "mul_eq_zero", "module": "Mathlib.Algebra.GroupWithZero.Defs" }, { "name": "ne_eq", "module": "Init.SimpLemmas" }, { "name": "not_and_or", "module": "Mathlib.Logic.Basic" }, { "name": "tsum_eq_single", "module": "Mathlib.Topology.Algebra.InfiniteSum.Basic" }, { "name": "zero_eq_mul", "module": "Mathlib.Algebra.GroupWithZero.Defs" } ]
[ { "name": "probOutput_bind_eq_tsum", "content": "lemma probOutput_bind_eq_tsum (y : Ξ²) :\n [= y | oa >>= ob] = βˆ‘' x : Ξ±, [= x | oa] * [= y | ob x]" }, { "name": "probOutput_pure", "content": "@[simp]\nlemma probOutput_pure [DecidableEq Ξ±] (y : Ξ±) :\n [= y | (pure x : OracleComp spec Ξ±)] = if y = x then 1 else 0" }, { "name": "probOutput_eq_zero_iff", "content": "@[simp low]\nlemma probOutput_eq_zero_iff : [= x | oa] = 0 ↔ x βˆ‰ oa.support" }, { "name": "mem_support_evalDist_iff", "content": "@[simp]\nlemma mem_support_evalDist_iff (oa : OracleComp spec Ξ±) (x : Ξ±) :\n some x ∈ (evalDist oa).run.support ↔ x ∈ oa.support" } ]
[]
[ { "name": "OracleComp.probOutput_seq_map_eq_tsum", "content": "lemma probOutput_seq_map_eq_tsum [spec.FiniteRange]\n (z : Ξ³) : [= z | f <$> oa <*> ob] = βˆ‘' (x : Ξ±) (y : Ξ²),\n [= x | oa] * [= y | ob] * [= z | (pure (f x y) : OracleComp spec Ξ³)]" }, { "name": "OracleComp.probOutput_seq_map_eq_tsum_ite", "content": "lemma probOutput_seq_map_eq_tsum_ite [spec.FiniteRange] [DecidableEq Ξ³]\n (z : Ξ³) : [= z | f <$> oa <*> ob] =\n βˆ‘' (x : Ξ±) (y : Ξ²), if z = f x y then [= x | oa] * [= y | ob] else 0" } ]
import VCVio.OracleComp.DistSemantics.Monad namespace OracleComp variable {ΞΉ : Type u} {spec : OracleSpec ΞΉ} {Ξ± Ξ² Ξ³ : Type v} variable (oa : OracleComp spec Ξ±) (og : OracleComp spec (Ξ± β†’ Ξ²)) section seq_map variable (oa : OracleComp spec Ξ±) (ob : OracleComp spec Ξ²) (f : Ξ± β†’ Ξ² β†’ Ξ³) section swap end swap section injective2 end injective2
lemma probOutput_seq_map_eq_mul [spec.FiniteRange] (x : Ξ±) (y : Ξ²) (z : Ξ³) (h : βˆ€ x' ∈ oa.support, βˆ€ y' ∈ ob.support, z = f x' y' ↔ x' = x ∧ y' = y) : [= z | f <$> oa <*> ob] = [= x | oa] * [= y | ob] :=
:= by have : DecidableEq Ξ³ := Classical.decEq Ξ³ rw [probOutput_seq_map_eq_tsum_ite, ← ENNReal.tsum_prod] refine (tsum_eq_single (x, y) (Ξ» (x', y') ↦ ?_)).trans ?_ Β· simp only [ne_eq, Prod.mk.injEq, ite_eq_right_iff, mul_eq_zero, probOutput_eq_zero_iff, ← not_and_or] exact Ξ» h1 h2 h3 ↦ h1 ((h x' h3.1 y' h3.2).1 h2) Β· simp only [ite_eq_left_iff, zero_eq_mul, probOutput_eq_zero_iff, ← not_and_or] intro h1 h2 refine h1 ((h x h2.1 y h2.2).2 ⟨rfl, rfl⟩)
5
50
true
Applied verif.
467
PFunctor.Lens.sumPair_inl_inr
@[simp] theorem sumPair_inl_inr : Lens.sumPair Lens.inl Lens.inr = Lens.id.{max uA₁ uAβ‚‚, uB₁} (P + Q)
VCV-io
ToMathlib/PFunctor/Lens/Basic.lean
[ "import ToMathlib.PFunctor.Basic" ]
[ { "name": "PFunctor", "module": "Mathlib.Data.PFunctor.Univariate.Basic" }, { "name": "Sum", "module": "Init.Core" }, { "name": "Sum.inl", "module": "Init.Core" }, { "name": "Sum.elim", "module": "Init.Data.Sum.Basic" }, { "name": "Sum.inr", "module": "Init.Core" } ]
[ { "name": "prodPair", "content": "notation \"⟨\" l₁ \",\" lβ‚‚ \"βŸ©β‚—\" => prodPair l₁ lβ‚‚" }, { "name": "Lens", "content": "structure Lens (P : PFunctor.{uA₁, uB₁}) (Q : PFunctor.{uAβ‚‚, uBβ‚‚}) where\n toFunA : P.A β†’ Q.A\n toFunB : βˆ€ a, Q.B (toFunA a) β†’ P.B a" }, { "name": "Chart", "content": "structure Chart (P : PFunctor.{uA₁, uB₁}) (Q : PFunctor.{uAβ‚‚, uBβ‚‚}) where\n toFunA : P.A β†’ Q.A\n toFunB : βˆ€ a, P.B a β†’ Q.B (toFunA a)" } ]
[ { "name": "...", "module": "" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "PFunctor.Lens.prodPair", "content": "def prodPair {P : PFunctor.{uA₁, uB₁}} {Q : PFunctor.{uAβ‚‚, uBβ‚‚}} {R : PFunctor.{uA₃, uB₃}}\n (l₁ : Lens P Q) (lβ‚‚ : Lens P R) :\n Lens.{uA₁, uB₁, max uAβ‚‚ uA₃, max uBβ‚‚ uB₃} P (Q * R) :=\n (fun p => (l₁.toFunA p, lβ‚‚.toFunA p)) ⇆\n (fun p => Sum.elim (l₁.toFunB p) (lβ‚‚.toFunB p))" } ]
[ { "name": "PFunctor.Lens.ext", "content": "@[ext (iff := false)]\ntheorem ext {P : PFunctor.{uA₁, uB₁}} {Q : PFunctor.{uAβ‚‚, uBβ‚‚}} (l₁ lβ‚‚ : Lens P Q)\n (h₁ : βˆ€ a, l₁.toFunA a = lβ‚‚.toFunA a) (hβ‚‚ : βˆ€ a, l₁.toFunB a = (h₁ a) β–Έ lβ‚‚.toFunB a) :\n l₁ = lβ‚‚" } ]
import ToMathlib.PFunctor.Basic section find_home variable {Ξ± : Sort u} {Ξ² : Ξ± β†’ Sort v} {Ξ³ : Ξ± β†’ Sort v} end find_home namespace PFunctor namespace Lens @[inherit_doc] infixl:75 " βˆ˜β‚— " => comp @[inherit_doc] infix:50 " ≃ₗ " => Equiv namespace Equiv end Equiv def prodPair {P : PFunctor.{uA₁, uB₁}} {Q : PFunctor.{uAβ‚‚, uBβ‚‚}} {R : PFunctor.{uA₃, uB₃}} (l₁ : Lens P Q) (lβ‚‚ : Lens P R) : Lens.{uA₁, uB₁, max uAβ‚‚ uA₃, max uBβ‚‚ uB₃} P (Q * R) := (fun p => (l₁.toFunA p, lβ‚‚.toFunA p)) ⇆ (fun p => Sum.elim (l₁.toFunB p) (lβ‚‚.toFunB p)) @[inherit_doc] infixl:75 " β—ƒβ‚— " => compMap @[inherit_doc] infixl:75 " Γ—β‚— " => prodMap @[inherit_doc] infixl:75 " βŠŽβ‚— " => sumMap @[inherit_doc] infixl:75 " βŠ—β‚— " => tensorMap notation "[" l₁ "," lβ‚‚ "]β‚—" => sumPair l₁ lβ‚‚ notation "⟨" l₁ "," lβ‚‚ "βŸ©β‚—" => prodPair l₁ lβ‚‚ section Coprod variable {P : PFunctor.{uA₁, uB₁}} {Q : PFunctor.{uAβ‚‚, uB₁}} {R : PFunctor.{uA₃, uB₃}} {W : PFunctor.{uAβ‚„, uB₃}} {X : PFunctor.{uAβ‚…, uBβ‚…}}
@[simp] theorem sumPair_inl_inr : Lens.sumPair Lens.inl Lens.inr = Lens.id.{max uA₁ uAβ‚‚, uB₁} (P + Q) :=
:= by ext a <;> rcases a <;> rfl
2
13
true
Applied verif.
468
Veil.bind_terminates
theorem bind_terminates m (act : Wp m Οƒ ρ) (act' : ρ -> Wp m Οƒ ρ') s [LawfulAction act] : pre s -> act.alwaysSuccessfullyTerminates pre β†’ (act.bind act').alwaysSuccessfullyTerminates pre -> act.toBigStep s r' s' -> (act' r').alwaysSuccessfullyTerminates (Β· = s')
veil
Veil/DSL/Action/Theory.lean
[ "import Veil.DSL.Base" ]
[ { "name": "r", "module": "Test.Playground.WHNFExamples" }, { "name": "BEq", "module": "Init.Prelude" }, { "name": "p", "module": "Smt.Reconstruct.Certified.ModusPonens" }, { "name": "Inhabited", "module": "Init.Prelude" }, { "name": "impl", "module": "Mathlib.Deprecated.MLList.BestFirst" }, { "name": "t", "module": "Test.Unit.Normalize" }, { "name": "Unit", "module": "Init.Prelude" }, { "name": "semiOutParam", "module": "Init.Prelude" } ]
[ { "name": "syntax (name:= assumption) \"assumptionDef\" : attr", "content": "syntax (name:= assumption) \"assumptionDef\" : attr" } ]
[ { "name": "...", "module": "" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "Veil.Mode", "content": "inductive Mode where\n | internal : Mode\n | external : Mode\nderiving BEq" }, { "name": "Veil.SProp", "content": "@[inline] abbrev SProp := Οƒ -> Prop" }, { "name": "Veil.RProp", "content": "@[inline] abbrev RProp (ρ : Type u) := ρ β†’ SProp Οƒ" }, { "name": "Veil.Wp", "content": "abbrev Wp (m : Mode) (Οƒ ρ : Type) := Οƒ -> RProp Οƒ ρ -> Prop" }, { "name": "Veil.Wlp", "content": "abbrev Wlp (m : Mode) (Οƒ ρ : Type) := Οƒ -> RProp Οƒ ρ -> Prop" }, { "name": "Veil.BigStep", "content": "abbrev BigStep := Οƒ -> ρ -> Οƒ -> Prop" }, { "name": "Veil.Wp.bind", "content": "@[actSimp] def Wp.bind (wp : Wp m Οƒ ρ) (wp_cont : ρ -> Wp m Οƒ ρ') : Wp m Οƒ ρ' :=\n fun s post => wp s (fun r s' => wp_cont r s' post)" }, { "name": "Veil.Wp.get", "content": "@[actSimp] def Wp.get : Wp m Οƒ Οƒ := fun s post => post s s" }, { "name": "Veil.Wp.set", "content": "@[actSimp] def Wp.set (s' : Οƒ) : Wp m Οƒ Unit := fun _ post => post () s'" }, { "name": "Veil.Wp.modifyGet", "content": "@[actSimp] def Wp.modifyGet (act : Οƒ -> ρ Γ— Οƒ) : Wp m Οƒ ρ := fun s post => let (ret, s') := act s ; post ret s'" }, { "name": "Veil.IsSubStateOf", "content": "class IsSubStateOf (Οƒ : semiOutParam Type) (Οƒ' : Type) where\n \n setIn : Οƒ -> Οƒ' -> Οƒ'\n \n getFrom : Οƒ' -> Οƒ\n\n setIn_getFrom_idempotent : βˆ€ Οƒ', setIn (getFrom Οƒ') Οƒ' = Οƒ'\n getFrom_setIn_idempotent : βˆ€ Οƒ Οƒ', getFrom (setIn Οƒ Οƒ') = Οƒ" }, { "name": "Veil.Wp.lift", "content": "@[actSimp] def Wp.lift {Οƒ Οƒ'} [IsSubStateOf Οƒ Οƒ'] (act : Wp m Οƒ ρ) : Wp m Οƒ' ρ :=\n fun s' post => act (getFrom s') (fun r s => post r (setIn s s'))" }, { "name": "Veil.BigStep.bind", "content": "def BigStep.bind (act : BigStep Οƒ ρ) (act' : ρ -> BigStep Οƒ ρ') : BigStep Οƒ ρ' :=\n fun s r' s' => βˆƒ r s'', act s r s'' ∧ act' r s'' r' s'" }, { "name": "Veil.Wp.toWlp", "content": "@[actSimp]\nabbrev Wp.toWlp {Οƒ ρ : Type} {m : Mode} (wp : Wp m Οƒ ρ) : Wlp m Οƒ ρ :=\n \n fun (s : Οƒ) (post : RProp Οƒ ρ) => Β¬ wp s (fun r s' => Β¬ post r s')" }, { "name": "Veil.Wp.toBigStep", "content": "@[actSimp]\ndef Wp.toBigStep {Οƒ} (wp : Wp m Οƒ ρ) : BigStep Οƒ ρ :=\n fun s r' s' =>\n wp.toWlp s (fun rβ‚€ sβ‚€ => r' = rβ‚€ ∧ s' = sβ‚€)" }, { "name": "Veil.Wp.triple", "content": "abbrev Wp.triple {Οƒ ρ} (req : SProp Οƒ) (act : Wp m Οƒ ρ) (ens : RProp Οƒ ρ) : Prop :=\n βˆ€ s, req s -> act s ens" }, { "name": "Veil.Wp.alwaysSuccessfullyTerminates", "content": "abbrev Wp.alwaysSuccessfullyTerminates {Οƒ } (req : SProp Οƒ) (act : Wp m Οƒ ρ) : Prop :=\n βˆ€ s, req s -> act s (fun _ _ => True)" }, { "name": "Veil.BigStep.triple", "content": "abbrev BigStep.triple {Οƒ } (req : SProp Οƒ) (act : BigStep Οƒ ρ) (ens : RProp Οƒ ρ) : Prop :=\n βˆ€ s r' s', req s -> act s r' s' -> ens r' s'" }, { "name": "Veil.LawfulAction", "content": "class LawfulAction {Οƒ ρ : Type} (act : Wp m Οƒ ρ) where\n inter {Ο„ : Type} [Inhabited Ο„] (post : Ο„ -> RProp Οƒ ρ) :\n βˆ€ s : Οƒ, (βˆ€ t : Ο„, act s (post t)) -> act s (βˆ€ t, post t Β· Β·)\n\n impl (post post' : RProp Οƒ ρ) : βˆ€ s,\n (βˆ€ r s, post r s -> post' r s) -> act s post -> act s post'" }, { "name": "Veil.pure_lawful", "content": "instance pure_lawful : LawfulAction (Wp.pure (Οƒ := Οƒ) (m := m) r) where\n inter := by admit /- proof elided -/" }, { "name": "Veil.bind_lawful", "content": "instance bind_lawful (act : Wp m' Οƒ ρ) (act' : ρ -> Wp m Οƒ ρ') [LawfulAction act] [βˆ€ r, LawfulAction (act' r)] : LawfulAction (Wp.bind (m := m) act act') where\n inter := by admit /- proof elided -/" }, { "name": "Veil.internal_sound", "content": "instance (priority := low) internal_sound (act : Wp m Οƒ ρ) [inst : LawfulAction (m := .internal) act] : LawfulAction (m := .external) act where\n inter := inst.inter\n impl := inst.impl" }, { "name": "Veil.assume_lawful", "content": "instance assume_lawful : LawfulAction (Wp.assume (m := m) (Οƒ := Οƒ) rq) where\n inter := by admit /- proof elided -/" }, { "name": "Veil.assert_lawful", "content": "instance assert_lawful : LawfulAction (Wp.assert (m := m) (Οƒ := Οƒ) rq) where\n inter := by admit /- proof elided -/" }, { "name": "Veil.require_lawful", "content": "instance require_lawful : LawfulAction (Wp.require (m := m) (Οƒ := Οƒ) rq) where\n inter := by admit /- proof elided -/" }, { "name": "Veil.fresh_lawful", "content": "instance fresh_lawful : LawfulAction (Wp.fresh (m := m) (Οƒ := Οƒ) Ο„) where\n inter := by admit /- proof elided -/" }, { "name": "Veil.spec_lawful", "content": "instance spec_lawful : LawfulAction (Wp.spec (m := m) req ens) where\n inter := by admit /- proof elided -/" }, { "name": "Veil._inst_Οƒ", "content": "instance (r : Οƒ -> Οƒ -> Prop) : LawfulAction (r.toWp (m := m)) where\n inter := by admit /- proof elided -/" }, { "name": "Veil.get_lawful", "content": "instance get_lawful : LawfulAction (Wp.get (m := m) (Οƒ := Οƒ)) where\n inter := by admit /- proof elided -/" }, { "name": "Veil.set_lawful", "content": "instance set_lawful (s : Οƒ) : LawfulAction (Wp.set s (m := m)) where\n inter := by admit /- proof elided -/" }, { "name": "Veil.modifyGet_lawful", "content": "instance modifyGet_lawful : LawfulAction (Wp.modifyGet f (m := m) (Οƒ := Οƒ) (ρ := ρ)) where\n inter := by admit /- proof elided -/" }, { "name": "Veil.if_lawful", "content": "instance if_lawful [Decidable c] [instT: LawfulAction t] [instS : LawfulAction e] : LawfulAction (ite c t e) where\n inter := by admit /- proof elided -/" }, { "name": "Veil.lift_lawful", "content": "instance lift_lawful (act : Wp m Οƒ ρ) [IsSubStateOf Οƒ Οƒ'] [LawfulAction act] :\n LawfulAction (act.lift (Οƒ' := Οƒ')) where\n inter := by admit /- proof elided -/" }, { "name": "Veil.GenBigStep", "content": "class GenBigStep (Οƒ ρ : Type) (wp : Wp .external Οƒ ρ) (tr : outParam (BigStep Οƒ ρ)) where\n lawful : LawfulAction wp\n equiv pre :\n wp.alwaysSuccessfullyTerminates pre -> βˆ€ s, pre s -> tr s = wp.toBigStep s" }, { "name": "Veil._inst_GenBigStep", "content": "instance : GenBigStep Οƒ ρ (Wp.pure r) (BigStep.pure r) where\n lawful := inferInstance\n equiv := by admit /- proof elided -/" }, { "name": "Veil._inst_GenBigStep", "content": "instance : GenBigStep Οƒ PUnit (Wp.assume asm) (BigStep.assume asm) where\n lawful := inferInstance\n equiv := by admit /- proof elided -/" }, { "name": "Veil._inst_GenBigStep", "content": "instance : GenBigStep Οƒ PUnit (Wp.assert asm) (BigStep.assert asm) where\n lawful := inferInstance\n equiv := by admit /- proof elided -/" }, { "name": "Veil._inst_GenBigStep", "content": "instance : GenBigStep Οƒ PUnit (Wp.require rq) (BigStep.assume rq) where\n lawful := inferInstance\n equiv := by admit /- proof elided -/" }, { "name": "Veil._inst_GenBigStep", "content": "instance : GenBigStep Οƒ Ο„ (Wp.fresh Ο„) (BigStep.fresh Ο„) where\n lawful := inferInstance\n equiv := by admit /- proof elided -/" }, { "name": "Veil._inst_GenBigStep", "content": "instance : GenBigStep Οƒ Unit (Wp.set s) (BigStep.set s) where\n lawful := inferInstance\n equiv := by admit /- proof elided -/" }, { "name": "Veil._inst_GenBigStep", "content": "instance : GenBigStep Οƒ Οƒ (Wp.get) (BigStep.get) where\n lawful := inferInstance\n equiv := by admit /- proof elided -/" }, { "name": "Veil._inst_GenBigStep", "content": "instance : GenBigStep Οƒ ρ (Wp.modifyGet act) (BigStep.modifyGet act) where\n lawful := inferInstance\n equiv := by admit /- proof elided -/" }, { "name": "Veil._inst_GenBigStep", "content": "instance : GenBigStep Οƒ ρ (Wp.spec req ens) (BigStep.spec req ens) where\n lawful := inferInstance\n equiv := by admit /- proof elided -/" }, { "name": "Veil._inst_GenBigStep", "content": "instance [inst : GenBigStep Οƒ ρ act actTr] : LawfulAction act := inst.lawful" } ]
[ { "name": "Veil.big_step_sound'", "content": "theorem big_step_sound' [LawfulAction act] (req : SProp Οƒ) (ens : RProp Οƒ ρ) :\n act.triple req ens β†’ act.toBigStep.triple req ens" } ]
import Veil.DSL.Base namespace Veil section Veil open Classical section Types inductive Mode where | internal : Mode | external : Mode deriving BEq variable (m : Mode) (Οƒ ρ : Type) @[inline] abbrev SProp := Οƒ -> Prop @[inline] abbrev RProp (ρ : Type u) := ρ β†’ SProp Οƒ abbrev Wp (m : Mode) (Οƒ ρ : Type) := Οƒ -> RProp Οƒ ρ -> Prop abbrev Wlp (m : Mode) (Οƒ ρ : Type) := Οƒ -> RProp Οƒ ρ -> Prop abbrev BigStep := Οƒ -> ρ -> Οƒ -> Prop end Types section Theory variable {Οƒ ρ : Type} @[actSimp] def Wp.bind (wp : Wp m Οƒ ρ) (wp_cont : ρ -> Wp m Οƒ ρ') : Wp m Οƒ ρ' := fun s post => wp s (fun r s' => wp_cont r s' post) @[actSimp] def Wp.get : Wp m Οƒ Οƒ := fun s post => post s s @[actSimp] def Wp.set (s' : Οƒ) : Wp m Οƒ Unit := fun _ post => post () s' @[actSimp] def Wp.modifyGet (act : Οƒ -> ρ Γ— Οƒ) : Wp m Οƒ ρ := fun s post => let (ret, s') := act s ; post ret s' class IsSubStateOf (Οƒ : semiOutParam Type) (Οƒ' : Type) where setIn : Οƒ -> Οƒ' -> Οƒ' getFrom : Οƒ' -> Οƒ setIn_getFrom_idempotent : βˆ€ Οƒ', setIn (getFrom Οƒ') Οƒ' = Οƒ' getFrom_setIn_idempotent : βˆ€ Οƒ Οƒ', getFrom (setIn Οƒ Οƒ') = Οƒ @[actSimp] def Wp.lift {Οƒ Οƒ'} [IsSubStateOf Οƒ Οƒ'] (act : Wp m Οƒ ρ) : Wp m Οƒ' ρ := fun s' post => act (getFrom s') (fun r s => post r (setIn s s')) def BigStep.bind (act : BigStep Οƒ ρ) (act' : ρ -> BigStep Οƒ ρ') : BigStep Οƒ ρ' := fun s r' s' => βˆƒ r s'', act s r s'' ∧ act' r s'' r' s' @[actSimp] abbrev Wp.toWlp {Οƒ ρ : Type} {m : Mode} (wp : Wp m Οƒ ρ) : Wlp m Οƒ ρ := fun (s : Οƒ) (post : RProp Οƒ ρ) => Β¬ wp s (fun r s' => Β¬ post r s') @[actSimp] def Wp.toBigStep {Οƒ} (wp : Wp m Οƒ ρ) : BigStep Οƒ ρ := fun s r' s' => wp.toWlp s (fun rβ‚€ sβ‚€ => r' = rβ‚€ ∧ s' = sβ‚€) abbrev Wp.triple {Οƒ ρ} (req : SProp Οƒ) (act : Wp m Οƒ ρ) (ens : RProp Οƒ ρ) : Prop := βˆ€ s, req s -> act s ens abbrev Wp.alwaysSuccessfullyTerminates {Οƒ } (req : SProp Οƒ) (act : Wp m Οƒ ρ) : Prop := βˆ€ s, req s -> act s (fun _ _ => True) abbrev BigStep.triple {Οƒ } (req : SProp Οƒ) (act : BigStep Οƒ ρ) (ens : RProp Οƒ ρ) : Prop := βˆ€ s r' s', req s -> act s r' s' -> ens r' s' class LawfulAction {Οƒ ρ : Type} (act : Wp m Οƒ ρ) where inter {Ο„ : Type} [Inhabited Ο„] (post : Ο„ -> RProp Οƒ ρ) : βˆ€ s : Οƒ, (βˆ€ t : Ο„, act s (post t)) -> act s (βˆ€ t, post t Β· Β·) impl (post post' : RProp Οƒ ρ) : βˆ€ s, (βˆ€ r s, post r s -> post' r s) -> act s post -> act s post' section TwoStateSoundness end TwoStateSoundness section BigStepSoundness end BigStepSoundness section LawfulActionInstances instance pure_lawful : LawfulAction (Wp.pure (Οƒ := Οƒ) (m := m) r) where inter := by admit /- proof elided -/ instance bind_lawful (act : Wp m' Οƒ ρ) (act' : ρ -> Wp m Οƒ ρ') [LawfulAction act] [βˆ€ r, LawfulAction (act' r)] : LawfulAction (Wp.bind (m := m) act act') where inter := by admit /- proof elided -/ instance (priority := low) internal_sound (act : Wp m Οƒ ρ) [inst : LawfulAction (m := .internal) act] : LawfulAction (m := .external) act where inter := inst.inter impl := inst.impl instance assume_lawful : LawfulAction (Wp.assume (m := m) (Οƒ := Οƒ) rq) where inter := by admit /- proof elided -/ instance assert_lawful : LawfulAction (Wp.assert (m := m) (Οƒ := Οƒ) rq) where inter := by admit /- proof elided -/ instance require_lawful : LawfulAction (Wp.require (m := m) (Οƒ := Οƒ) rq) where inter := by admit /- proof elided -/ instance fresh_lawful : LawfulAction (Wp.fresh (m := m) (Οƒ := Οƒ) Ο„) where inter := by admit /- proof elided -/ instance spec_lawful : LawfulAction (Wp.spec (m := m) req ens) where inter := by admit /- proof elided -/ instance (r : Οƒ -> Οƒ -> Prop) : LawfulAction (r.toWp (m := m)) where inter := by admit /- proof elided -/ instance get_lawful : LawfulAction (Wp.get (m := m) (Οƒ := Οƒ)) where inter := by admit /- proof elided -/ instance set_lawful (s : Οƒ) : LawfulAction (Wp.set s (m := m)) where inter := by admit /- proof elided -/ instance modifyGet_lawful : LawfulAction (Wp.modifyGet f (m := m) (Οƒ := Οƒ) (ρ := ρ)) where inter := by admit /- proof elided -/ instance if_lawful [Decidable c] [instT: LawfulAction t] [instS : LawfulAction e] : LawfulAction (ite c t e) where inter := by admit /- proof elided -/ instance lift_lawful (act : Wp m Οƒ ρ) [IsSubStateOf Οƒ Οƒ'] [LawfulAction act] : LawfulAction (act.lift (Οƒ' := Οƒ')) where inter := by admit /- proof elided -/ end LawfulActionInstances section GenBigStepInstances class GenBigStep (Οƒ ρ : Type) (wp : Wp .external Οƒ ρ) (tr : outParam (BigStep Οƒ ρ)) where lawful : LawfulAction wp equiv pre : wp.alwaysSuccessfullyTerminates pre -> βˆ€ s, pre s -> tr s = wp.toBigStep s instance : GenBigStep Οƒ ρ (Wp.pure r) (BigStep.pure r) where lawful := inferInstance equiv := by admit /- proof elided -/ instance : GenBigStep Οƒ PUnit (Wp.assume asm) (BigStep.assume asm) where lawful := inferInstance equiv := by admit /- proof elided -/ instance : GenBigStep Οƒ PUnit (Wp.assert asm) (BigStep.assert asm) where lawful := inferInstance equiv := by admit /- proof elided -/ instance : GenBigStep Οƒ PUnit (Wp.require rq) (BigStep.assume rq) where lawful := inferInstance equiv := by admit /- proof elided -/ instance : GenBigStep Οƒ Ο„ (Wp.fresh Ο„) (BigStep.fresh Ο„) where lawful := inferInstance equiv := by admit /- proof elided -/ instance : GenBigStep Οƒ Unit (Wp.set s) (BigStep.set s) where lawful := inferInstance equiv := by admit /- proof elided -/ instance : GenBigStep Οƒ Οƒ (Wp.get) (BigStep.get) where lawful := inferInstance equiv := by admit /- proof elided -/ instance : GenBigStep Οƒ ρ (Wp.modifyGet act) (BigStep.modifyGet act) where lawful := inferInstance equiv := by admit /- proof elided -/ instance : GenBigStep Οƒ ρ (Wp.spec req ens) (BigStep.spec req ens) where lawful := inferInstance equiv := by admit /- proof elided -/ instance [inst : GenBigStep Οƒ ρ act actTr] : LawfulAction act := inst.lawful
theorem bind_terminates m (act : Wp m Οƒ ρ) (act' : ρ -> Wp m Οƒ ρ') s [LawfulAction act] : pre s -> act.alwaysSuccessfullyTerminates pre β†’ (act.bind act').alwaysSuccessfullyTerminates pre -> act.toBigStep s r' s' -> (act' r').alwaysSuccessfullyTerminates (Β· = s') :=
:= by unfold Wp.alwaysSuccessfullyTerminates Wp.toBigStep Wp.toWlp Wp.bind intros hpre actT act'T have actT := actT s hpre have act'T := act'T s hpre have act''T := big_step_sound' (act := act) (req := (Β· = s)) unfold Wp.triple BigStep.triple Wp.toBigStep Wp.toWlp at act''T simp at act''T; specialize act''T _ act'T s r' s' rfl simp_all
3
21
true
Framework
469
Veil.lift_transition_big_step'
theorem lift_transition_big_step' {Οƒ Οƒ'} [IsSubStateOf Οƒ Οƒ'] (m : Mode) (r : Wp m Οƒ ρ) [LawfulAction r] (st : Οƒ') : r.alwaysSuccessfullyTerminates (Β· = getFrom st) β†’ (@Wp.lift _ m Οƒ Οƒ' _ r).toBigStep st = fun r' st' => r.toBigStep (getFrom st) r' (getFrom st') ∧ st' = (setIn (@getFrom Οƒ Οƒ' _ st') st)
veil
Veil/DSL/Action/Theory.lean
[ "import Veil.DSL.Base" ]
[ { "name": "semiOutParam", "module": "Init.Prelude" }, { "name": "BEq", "module": "Init.Prelude" }, { "name": "p", "module": "Smt.Reconstruct.Certified.ModusPonens" }, { "name": "r", "module": "Test.Playground.WHNFExamples" }, { "name": "Unit", "module": "Init.Prelude" }, { "name": "Inhabited", "module": "Init.Prelude" }, { "name": "impl", "module": "Mathlib.Deprecated.MLList.BestFirst" }, { "name": "t", "module": "Test.Unit.Normalize" }, { "name": "Decidable", "module": "Init.Prelude" } ]
[ { "name": "syntax (name:= assumption) \"assumptionDef\" : attr", "content": "syntax (name:= assumption) \"assumptionDef\" : attr" } ]
[ { "name": "Classical.not_forall", "module": "Init.Classical" }, { "name": "Decidable.not_not", "module": "Init.PropLemmas" }, { "name": "and_true", "module": "Init.SimpLemmas" }, { "name": "eq_iff_iff", "module": "Init.Core" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "Veil.Mode", "content": "inductive Mode where\n | internal : Mode\n | external : Mode\nderiving BEq" }, { "name": "Veil.SProp", "content": "@[inline] abbrev SProp := Οƒ -> Prop" }, { "name": "Veil.RProp", "content": "@[inline] abbrev RProp (ρ : Type u) := ρ β†’ SProp Οƒ" }, { "name": "Veil.TwoState", "content": "@[inline] abbrev TwoState := Οƒ -> Οƒ -> Prop" }, { "name": "Veil.Wp", "content": "abbrev Wp (m : Mode) (Οƒ ρ : Type) := Οƒ -> RProp Οƒ ρ -> Prop" }, { "name": "Veil.Wlp", "content": "abbrev Wlp (m : Mode) (Οƒ ρ : Type) := Οƒ -> RProp Οƒ ρ -> Prop" }, { "name": "Veil.BigStep", "content": "abbrev BigStep := Οƒ -> ρ -> Οƒ -> Prop" }, { "name": "Veil.Wp.bind", "content": "@[actSimp] def Wp.bind (wp : Wp m Οƒ ρ) (wp_cont : ρ -> Wp m Οƒ ρ') : Wp m Οƒ ρ' :=\n fun s post => wp s (fun r s' => wp_cont r s' post)" }, { "name": "Veil.Wp.get", "content": "@[actSimp] def Wp.get : Wp m Οƒ Οƒ := fun s post => post s s" }, { "name": "Veil.Wp.set", "content": "@[actSimp] def Wp.set (s' : Οƒ) : Wp m Οƒ Unit := fun _ post => post () s'" }, { "name": "Veil.Wp.modifyGet", "content": "@[actSimp] def Wp.modifyGet (act : Οƒ -> ρ Γ— Οƒ) : Wp m Οƒ ρ := fun s post => let (ret, s') := act s ; post ret s'" }, { "name": "Veil.IsSubStateOf", "content": "class IsSubStateOf (Οƒ : semiOutParam Type) (Οƒ' : Type) where\n \n setIn : Οƒ -> Οƒ' -> Οƒ'\n \n getFrom : Οƒ' -> Οƒ\n\n setIn_getFrom_idempotent : βˆ€ Οƒ', setIn (getFrom Οƒ') Οƒ' = Οƒ'\n getFrom_setIn_idempotent : βˆ€ Οƒ Οƒ', getFrom (setIn Οƒ Οƒ') = Οƒ" }, { "name": "Veil.Wp.lift", "content": "@[actSimp] def Wp.lift {Οƒ Οƒ'} [IsSubStateOf Οƒ Οƒ'] (act : Wp m Οƒ ρ) : Wp m Οƒ' ρ :=\n fun s' post => act (getFrom s') (fun r s => post r (setIn s s'))" }, { "name": "Veil.BigStep.lift", "content": "def BigStep.lift [IsSubStateOf Οƒ Οƒ'] (act : BigStep Οƒ ρ) : BigStep Οƒ' ρ :=\n fun st r' st' => act (getFrom st) r' (getFrom st') ∧ st' = (setIn (@getFrom Οƒ Οƒ' _ st') st)" }, { "name": "Veil.Wp.toWlp", "content": "@[actSimp]\nabbrev Wp.toWlp {Οƒ ρ : Type} {m : Mode} (wp : Wp m Οƒ ρ) : Wlp m Οƒ ρ :=\n \n fun (s : Οƒ) (post : RProp Οƒ ρ) => Β¬ wp s (fun r s' => Β¬ post r s')" }, { "name": "Veil.Wp.toBigStep", "content": "@[actSimp]\ndef Wp.toBigStep {Οƒ} (wp : Wp m Οƒ ρ) : BigStep Οƒ ρ :=\n fun s r' s' =>\n wp.toWlp s (fun rβ‚€ sβ‚€ => r' = rβ‚€ ∧ s' = sβ‚€)" }, { "name": "Veil.BigStep.toWp", "content": "@[actSimp]\ndef BigStep.toWp {Οƒ} (act : BigStep Οƒ ρ) : Wp .internal Οƒ ρ :=\n fun s post => βˆ€ r s', act s r s' -> post r s'" }, { "name": "Veil._root_.Function.toWp", "content": "@[actSimp]\ndef _root_.Function.toWp (m : Mode) (r : TwoState Οƒ) : Wp m Οƒ Unit :=\n fun s post => βˆ€ s', r s s' -> post () s'" }, { "name": "Veil.Wp.triple", "content": "abbrev Wp.triple {Οƒ ρ} (req : SProp Οƒ) (act : Wp m Οƒ ρ) (ens : RProp Οƒ ρ) : Prop :=\n βˆ€ s, req s -> act s ens" }, { "name": "Veil.Wp.alwaysSuccessfullyTerminates", "content": "abbrev Wp.alwaysSuccessfullyTerminates {Οƒ } (req : SProp Οƒ) (act : Wp m Οƒ ρ) : Prop :=\n βˆ€ s, req s -> act s (fun _ _ => True)" }, { "name": "Veil.LawfulAction", "content": "class LawfulAction {Οƒ ρ : Type} (act : Wp m Οƒ ρ) where\n inter {Ο„ : Type} [Inhabited Ο„] (post : Ο„ -> RProp Οƒ ρ) :\n βˆ€ s : Οƒ, (βˆ€ t : Ο„, act s (post t)) -> act s (βˆ€ t, post t Β· Β·)\n\n impl (post post' : RProp Οƒ ρ) : βˆ€ s,\n (βˆ€ r s, post r s -> post' r s) -> act s post -> act s post'" }, { "name": "Veil.pure_lawful", "content": "instance pure_lawful : LawfulAction (Wp.pure (Οƒ := Οƒ) (m := m) r) where\n inter := by admit /- proof elided -/" }, { "name": "Veil.bind_lawful", "content": "instance bind_lawful (act : Wp m' Οƒ ρ) (act' : ρ -> Wp m Οƒ ρ') [LawfulAction act] [βˆ€ r, LawfulAction (act' r)] : LawfulAction (Wp.bind (m := m) act act') where\n inter := by admit /- proof elided -/" }, { "name": "Veil.internal_sound", "content": "instance (priority := low) internal_sound (act : Wp m Οƒ ρ) [inst : LawfulAction (m := .internal) act] : LawfulAction (m := .external) act where\n inter := inst.inter\n impl := inst.impl" }, { "name": "Veil.assume_lawful", "content": "instance assume_lawful : LawfulAction (Wp.assume (m := m) (Οƒ := Οƒ) rq) where\n inter := by admit /- proof elided -/" }, { "name": "Veil.assert_lawful", "content": "instance assert_lawful : LawfulAction (Wp.assert (m := m) (Οƒ := Οƒ) rq) where\n inter := by admit /- proof elided -/" }, { "name": "Veil.require_lawful", "content": "instance require_lawful : LawfulAction (Wp.require (m := m) (Οƒ := Οƒ) rq) where\n inter := by admit /- proof elided -/" }, { "name": "Veil.fresh_lawful", "content": "instance fresh_lawful : LawfulAction (Wp.fresh (m := m) (Οƒ := Οƒ) Ο„) where\n inter := by admit /- proof elided -/" }, { "name": "Veil.spec_lawful", "content": "instance spec_lawful : LawfulAction (Wp.spec (m := m) req ens) where\n inter := by admit /- proof elided -/" }, { "name": "Veil._inst_Οƒ", "content": "instance (r : Οƒ -> Οƒ -> Prop) : LawfulAction (r.toWp (m := m)) where\n inter := by admit /- proof elided -/" }, { "name": "Veil.get_lawful", "content": "instance get_lawful : LawfulAction (Wp.get (m := m) (Οƒ := Οƒ)) where\n inter := by admit /- proof elided -/" }, { "name": "Veil.set_lawful", "content": "instance set_lawful (s : Οƒ) : LawfulAction (Wp.set s (m := m)) where\n inter := by admit /- proof elided -/" }, { "name": "Veil.modifyGet_lawful", "content": "instance modifyGet_lawful : LawfulAction (Wp.modifyGet f (m := m) (Οƒ := Οƒ) (ρ := ρ)) where\n inter := by admit /- proof elided -/" }, { "name": "Veil.if_lawful", "content": "instance if_lawful [Decidable c] [instT: LawfulAction t] [instS : LawfulAction e] : LawfulAction (ite c t e) where\n inter := by admit /- proof elided -/" }, { "name": "Veil.lift_lawful", "content": "instance lift_lawful (act : Wp m Οƒ ρ) [IsSubStateOf Οƒ Οƒ'] [LawfulAction act] :\n LawfulAction (act.lift (Οƒ' := Οƒ')) where\n inter := by admit /- proof elided -/" }, { "name": "Veil.GenBigStep", "content": "class GenBigStep (Οƒ ρ : Type) (wp : Wp .external Οƒ ρ) (tr : outParam (BigStep Οƒ ρ)) where\n lawful : LawfulAction wp\n equiv pre :\n wp.alwaysSuccessfullyTerminates pre -> βˆ€ s, pre s -> tr s = wp.toBigStep s" }, { "name": "Veil._inst_GenBigStep", "content": "instance : GenBigStep Οƒ ρ (Wp.pure r) (BigStep.pure r) where\n lawful := inferInstance\n equiv := by admit /- proof elided -/" }, { "name": "Veil._inst_GenBigStep", "content": "instance : GenBigStep Οƒ PUnit (Wp.assume asm) (BigStep.assume asm) where\n lawful := inferInstance\n equiv := by admit /- proof elided -/" }, { "name": "Veil._inst_GenBigStep", "content": "instance : GenBigStep Οƒ PUnit (Wp.assert asm) (BigStep.assert asm) where\n lawful := inferInstance\n equiv := by admit /- proof elided -/" }, { "name": "Veil._inst_GenBigStep", "content": "instance : GenBigStep Οƒ PUnit (Wp.require rq) (BigStep.assume rq) where\n lawful := inferInstance\n equiv := by admit /- proof elided -/" }, { "name": "Veil._inst_GenBigStep", "content": "instance : GenBigStep Οƒ Ο„ (Wp.fresh Ο„) (BigStep.fresh Ο„) where\n lawful := inferInstance\n equiv := by admit /- proof elided -/" }, { "name": "Veil._inst_GenBigStep", "content": "instance : GenBigStep Οƒ Unit (Wp.set s) (BigStep.set s) where\n lawful := inferInstance\n equiv := by admit /- proof elided -/" }, { "name": "Veil._inst_GenBigStep", "content": "instance : GenBigStep Οƒ Οƒ (Wp.get) (BigStep.get) where\n lawful := inferInstance\n equiv := by admit /- proof elided -/" }, { "name": "Veil._inst_GenBigStep", "content": "instance : GenBigStep Οƒ ρ (Wp.modifyGet act) (BigStep.modifyGet act) where\n lawful := inferInstance\n equiv := by admit /- proof elided -/" }, { "name": "Veil._inst_GenBigStep", "content": "instance : GenBigStep Οƒ ρ (Wp.spec req ens) (BigStep.spec req ens) where\n lawful := inferInstance\n equiv := by admit /- proof elided -/" }, { "name": "Veil._inst_GenBigStep", "content": "instance [inst : GenBigStep Οƒ ρ act actTr] : LawfulAction act := inst.lawful" } ]
[ { "name": "Veil.lift_transition_big_step", "content": "theorem lift_transition_big_step {Οƒ Οƒ'} [IsSubStateOf Οƒ Οƒ'] (m : Mode) (tr : BigStep Οƒ ρ) :\n (@Wp.lift _ m Οƒ Οƒ' _ tr.toWp).toBigStep =\n fun st r' st' =>\n tr (getFrom st) r' (getFrom st') ∧\n st' = (setIn (@getFrom Οƒ Οƒ' _ st') st)" }, { "name": "Veil.big_step_sound", "content": "theorem big_step_sound [LawfulAction act] (req : SProp Οƒ) (ens : RProp Οƒ ρ) :\n (Β¬ βˆ€ r s, ens r s) ->\n act.toBigStep.triple req ens -> act.triple req ens" }, { "name": "Veil.big_step_sound'", "content": "theorem big_step_sound' [LawfulAction act] (req : SProp Οƒ) (ens : RProp Οƒ ρ) :\n act.triple req ens β†’ act.toBigStep.triple req ens" }, { "name": "Veil.big_step_always_terminating_sound", "content": "theorem big_step_always_terminating_sound [LawfulAction act] (req : SProp Οƒ) (ens : RProp Οƒ ρ) :\n act.alwaysSuccessfullyTerminates req ->\n act.toBigStep.triple req ens -> act.triple req ens" }, { "name": "Veil.big_step_to_wp", "content": "theorem big_step_to_wp (act : Wp m Οƒ ρ) [LawfulAction act] (req : SProp Οƒ) :\n act.alwaysSuccessfullyTerminates req ->\n req s ->\n act s = act.toBigStep.toWp s" } ]
import Veil.DSL.Base namespace Veil section Veil open Classical section Types inductive Mode where | internal : Mode | external : Mode deriving BEq variable (m : Mode) (Οƒ ρ : Type) @[inline] abbrev SProp := Οƒ -> Prop @[inline] abbrev RProp (ρ : Type u) := ρ β†’ SProp Οƒ @[inline] abbrev TwoState := Οƒ -> Οƒ -> Prop abbrev Wp (m : Mode) (Οƒ ρ : Type) := Οƒ -> RProp Οƒ ρ -> Prop abbrev Wlp (m : Mode) (Οƒ ρ : Type) := Οƒ -> RProp Οƒ ρ -> Prop abbrev BigStep := Οƒ -> ρ -> Οƒ -> Prop end Types section Theory variable {Οƒ ρ : Type} @[actSimp] def Wp.bind (wp : Wp m Οƒ ρ) (wp_cont : ρ -> Wp m Οƒ ρ') : Wp m Οƒ ρ' := fun s post => wp s (fun r s' => wp_cont r s' post) @[actSimp] def Wp.get : Wp m Οƒ Οƒ := fun s post => post s s @[actSimp] def Wp.set (s' : Οƒ) : Wp m Οƒ Unit := fun _ post => post () s' @[actSimp] def Wp.modifyGet (act : Οƒ -> ρ Γ— Οƒ) : Wp m Οƒ ρ := fun s post => let (ret, s') := act s ; post ret s' class IsSubStateOf (Οƒ : semiOutParam Type) (Οƒ' : Type) where setIn : Οƒ -> Οƒ' -> Οƒ' getFrom : Οƒ' -> Οƒ setIn_getFrom_idempotent : βˆ€ Οƒ', setIn (getFrom Οƒ') Οƒ' = Οƒ' getFrom_setIn_idempotent : βˆ€ Οƒ Οƒ', getFrom (setIn Οƒ Οƒ') = Οƒ @[actSimp] def Wp.lift {Οƒ Οƒ'} [IsSubStateOf Οƒ Οƒ'] (act : Wp m Οƒ ρ) : Wp m Οƒ' ρ := fun s' post => act (getFrom s') (fun r s => post r (setIn s s')) def BigStep.lift [IsSubStateOf Οƒ Οƒ'] (act : BigStep Οƒ ρ) : BigStep Οƒ' ρ := fun st r' st' => act (getFrom st) r' (getFrom st') ∧ st' = (setIn (@getFrom Οƒ Οƒ' _ st') st) @[actSimp] abbrev Wp.toWlp {Οƒ ρ : Type} {m : Mode} (wp : Wp m Οƒ ρ) : Wlp m Οƒ ρ := fun (s : Οƒ) (post : RProp Οƒ ρ) => Β¬ wp s (fun r s' => Β¬ post r s') @[actSimp] def Wp.toBigStep {Οƒ} (wp : Wp m Οƒ ρ) : BigStep Οƒ ρ := fun s r' s' => wp.toWlp s (fun rβ‚€ sβ‚€ => r' = rβ‚€ ∧ s' = sβ‚€) @[actSimp] def BigStep.toWp {Οƒ} (act : BigStep Οƒ ρ) : Wp .internal Οƒ ρ := fun s post => βˆ€ r s', act s r s' -> post r s' @[actSimp] def _root_.Function.toWp (m : Mode) (r : TwoState Οƒ) : Wp m Οƒ Unit := fun s post => βˆ€ s', r s s' -> post () s' abbrev Wp.triple {Οƒ ρ} (req : SProp Οƒ) (act : Wp m Οƒ ρ) (ens : RProp Οƒ ρ) : Prop := βˆ€ s, req s -> act s ens abbrev Wp.alwaysSuccessfullyTerminates {Οƒ } (req : SProp Οƒ) (act : Wp m Οƒ ρ) : Prop := βˆ€ s, req s -> act s (fun _ _ => True) class LawfulAction {Οƒ ρ : Type} (act : Wp m Οƒ ρ) where inter {Ο„ : Type} [Inhabited Ο„] (post : Ο„ -> RProp Οƒ ρ) : βˆ€ s : Οƒ, (βˆ€ t : Ο„, act s (post t)) -> act s (βˆ€ t, post t Β· Β·) impl (post post' : RProp Οƒ ρ) : βˆ€ s, (βˆ€ r s, post r s -> post' r s) -> act s post -> act s post' section TwoStateSoundness end TwoStateSoundness section BigStepSoundness end BigStepSoundness section LawfulActionInstances instance pure_lawful : LawfulAction (Wp.pure (Οƒ := Οƒ) (m := m) r) where inter := by admit /- proof elided -/ instance bind_lawful (act : Wp m' Οƒ ρ) (act' : ρ -> Wp m Οƒ ρ') [LawfulAction act] [βˆ€ r, LawfulAction (act' r)] : LawfulAction (Wp.bind (m := m) act act') where inter := by admit /- proof elided -/ instance (priority := low) internal_sound (act : Wp m Οƒ ρ) [inst : LawfulAction (m := .internal) act] : LawfulAction (m := .external) act where inter := inst.inter impl := inst.impl instance assume_lawful : LawfulAction (Wp.assume (m := m) (Οƒ := Οƒ) rq) where inter := by admit /- proof elided -/ instance assert_lawful : LawfulAction (Wp.assert (m := m) (Οƒ := Οƒ) rq) where inter := by admit /- proof elided -/ instance require_lawful : LawfulAction (Wp.require (m := m) (Οƒ := Οƒ) rq) where inter := by admit /- proof elided -/ instance fresh_lawful : LawfulAction (Wp.fresh (m := m) (Οƒ := Οƒ) Ο„) where inter := by admit /- proof elided -/ instance spec_lawful : LawfulAction (Wp.spec (m := m) req ens) where inter := by admit /- proof elided -/ instance (r : Οƒ -> Οƒ -> Prop) : LawfulAction (r.toWp (m := m)) where inter := by admit /- proof elided -/ instance get_lawful : LawfulAction (Wp.get (m := m) (Οƒ := Οƒ)) where inter := by admit /- proof elided -/ instance set_lawful (s : Οƒ) : LawfulAction (Wp.set s (m := m)) where inter := by admit /- proof elided -/ instance modifyGet_lawful : LawfulAction (Wp.modifyGet f (m := m) (Οƒ := Οƒ) (ρ := ρ)) where inter := by admit /- proof elided -/ instance if_lawful [Decidable c] [instT: LawfulAction t] [instS : LawfulAction e] : LawfulAction (ite c t e) where inter := by admit /- proof elided -/ instance lift_lawful (act : Wp m Οƒ ρ) [IsSubStateOf Οƒ Οƒ'] [LawfulAction act] : LawfulAction (act.lift (Οƒ' := Οƒ')) where inter := by admit /- proof elided -/ end LawfulActionInstances section GenBigStepInstances class GenBigStep (Οƒ ρ : Type) (wp : Wp .external Οƒ ρ) (tr : outParam (BigStep Οƒ ρ)) where lawful : LawfulAction wp equiv pre : wp.alwaysSuccessfullyTerminates pre -> βˆ€ s, pre s -> tr s = wp.toBigStep s instance : GenBigStep Οƒ ρ (Wp.pure r) (BigStep.pure r) where lawful := inferInstance equiv := by admit /- proof elided -/ instance : GenBigStep Οƒ PUnit (Wp.assume asm) (BigStep.assume asm) where lawful := inferInstance equiv := by admit /- proof elided -/ instance : GenBigStep Οƒ PUnit (Wp.assert asm) (BigStep.assert asm) where lawful := inferInstance equiv := by admit /- proof elided -/ instance : GenBigStep Οƒ PUnit (Wp.require rq) (BigStep.assume rq) where lawful := inferInstance equiv := by admit /- proof elided -/ instance : GenBigStep Οƒ Ο„ (Wp.fresh Ο„) (BigStep.fresh Ο„) where lawful := inferInstance equiv := by admit /- proof elided -/ instance : GenBigStep Οƒ Unit (Wp.set s) (BigStep.set s) where lawful := inferInstance equiv := by admit /- proof elided -/ instance : GenBigStep Οƒ Οƒ (Wp.get) (BigStep.get) where lawful := inferInstance equiv := by admit /- proof elided -/ instance : GenBigStep Οƒ ρ (Wp.modifyGet act) (BigStep.modifyGet act) where lawful := inferInstance equiv := by admit /- proof elided -/ instance : GenBigStep Οƒ ρ (Wp.spec req ens) (BigStep.spec req ens) where lawful := inferInstance equiv := by admit /- proof elided -/ instance [inst : GenBigStep Οƒ ρ act actTr] : LawfulAction act := inst.lawful
theorem lift_transition_big_step' {Οƒ Οƒ'} [IsSubStateOf Οƒ Οƒ'] (m : Mode) (r : Wp m Οƒ ρ) [LawfulAction r] (st : Οƒ') : r.alwaysSuccessfullyTerminates (Β· = getFrom st) β†’ (@Wp.lift _ m Οƒ Οƒ' _ r).toBigStep st = fun r' st' => r.toBigStep (getFrom st) r' (getFrom st') ∧ st' = (setIn (@getFrom Οƒ Οƒ' _ st') st) :=
:= by intro term have rEq : r.lift.toBigStep st = (r.toBigStep.toWp.lift.toBigStep st) := by { unfold Wp.lift Wp.toBigStep Wp.toWlp; ext; simp rw [big_step_to_wp (act := r) (req := (fun x => x = getFrom st))] <;> try simp [*] unfold Wp.toBigStep Wp.toWlp; simp } rw [rEq, lift_transition_big_step]
5
35
true
Framework
470
Veil.big_step_to_wp
theorem big_step_to_wp (act : Wp m Οƒ ρ) [LawfulAction act] (req : SProp Οƒ) : act.alwaysSuccessfullyTerminates req -> req s -> act s = act.toBigStep.toWp s
veil
Veil/DSL/Action/Theory.lean
[ "import Veil.DSL.Base" ]
[ { "name": "BEq", "module": "Init.Prelude" }, { "name": "Unit", "module": "Init.Prelude" }, { "name": "r", "module": "Test.Playground.WHNFExamples" }, { "name": "p", "module": "Smt.Reconstruct.Certified.ModusPonens" }, { "name": "Inhabited", "module": "Init.Prelude" }, { "name": "impl", "module": "Mathlib.Deprecated.MLList.BestFirst" }, { "name": "t", "module": "Test.Unit.Normalize" }, { "name": "semiOutParam", "module": "Init.Prelude" } ]
[ { "name": "syntax (name:= assumption) \"assumptionDef\" : attr", "content": "syntax (name:= assumption) \"assumptionDef\" : attr" } ]
[ { "name": "...", "module": "" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "Veil.Mode", "content": "inductive Mode where\n | internal : Mode\n | external : Mode\nderiving BEq" }, { "name": "Veil.SProp", "content": "@[inline] abbrev SProp := Οƒ -> Prop" }, { "name": "Veil.RProp", "content": "@[inline] abbrev RProp (ρ : Type u) := ρ β†’ SProp Οƒ" }, { "name": "Veil.TwoState", "content": "@[inline] abbrev TwoState := Οƒ -> Οƒ -> Prop" }, { "name": "Veil.Wp", "content": "abbrev Wp (m : Mode) (Οƒ ρ : Type) := Οƒ -> RProp Οƒ ρ -> Prop" }, { "name": "Veil.Wlp", "content": "abbrev Wlp (m : Mode) (Οƒ ρ : Type) := Οƒ -> RProp Οƒ ρ -> Prop" }, { "name": "Veil.BigStep", "content": "abbrev BigStep := Οƒ -> ρ -> Οƒ -> Prop" }, { "name": "Veil.Wp.bind", "content": "@[actSimp] def Wp.bind (wp : Wp m Οƒ ρ) (wp_cont : ρ -> Wp m Οƒ ρ') : Wp m Οƒ ρ' :=\n fun s post => wp s (fun r s' => wp_cont r s' post)" }, { "name": "Veil.Wp.get", "content": "@[actSimp] def Wp.get : Wp m Οƒ Οƒ := fun s post => post s s" }, { "name": "Veil.Wp.set", "content": "@[actSimp] def Wp.set (s' : Οƒ) : Wp m Οƒ Unit := fun _ post => post () s'" }, { "name": "Veil.Wp.modifyGet", "content": "@[actSimp] def Wp.modifyGet (act : Οƒ -> ρ Γ— Οƒ) : Wp m Οƒ ρ := fun s post => let (ret, s') := act s ; post ret s'" }, { "name": "Veil.IsSubStateOf", "content": "class IsSubStateOf (Οƒ : semiOutParam Type) (Οƒ' : Type) where\n \n setIn : Οƒ -> Οƒ' -> Οƒ'\n \n getFrom : Οƒ' -> Οƒ\n\n setIn_getFrom_idempotent : βˆ€ Οƒ', setIn (getFrom Οƒ') Οƒ' = Οƒ'\n getFrom_setIn_idempotent : βˆ€ Οƒ Οƒ', getFrom (setIn Οƒ Οƒ') = Οƒ" }, { "name": "Veil.Wp.lift", "content": "@[actSimp] def Wp.lift {Οƒ Οƒ'} [IsSubStateOf Οƒ Οƒ'] (act : Wp m Οƒ ρ) : Wp m Οƒ' ρ :=\n fun s' post => act (getFrom s') (fun r s => post r (setIn s s'))" }, { "name": "Veil.Wp.toWlp", "content": "@[actSimp]\nabbrev Wp.toWlp {Οƒ ρ : Type} {m : Mode} (wp : Wp m Οƒ ρ) : Wlp m Οƒ ρ :=\n \n fun (s : Οƒ) (post : RProp Οƒ ρ) => Β¬ wp s (fun r s' => Β¬ post r s')" }, { "name": "Veil.Wp.toBigStep", "content": "@[actSimp]\ndef Wp.toBigStep {Οƒ} (wp : Wp m Οƒ ρ) : BigStep Οƒ ρ :=\n fun s r' s' =>\n wp.toWlp s (fun rβ‚€ sβ‚€ => r' = rβ‚€ ∧ s' = sβ‚€)" }, { "name": "Veil.BigStep.toWp", "content": "@[actSimp]\ndef BigStep.toWp {Οƒ} (act : BigStep Οƒ ρ) : Wp .internal Οƒ ρ :=\n fun s post => βˆ€ r s', act s r s' -> post r s'" }, { "name": "Veil._root_.Function.toWp", "content": "@[actSimp]\ndef _root_.Function.toWp (m : Mode) (r : TwoState Οƒ) : Wp m Οƒ Unit :=\n fun s post => βˆ€ s', r s s' -> post () s'" }, { "name": "Veil.Wp.triple", "content": "abbrev Wp.triple {Οƒ ρ} (req : SProp Οƒ) (act : Wp m Οƒ ρ) (ens : RProp Οƒ ρ) : Prop :=\n βˆ€ s, req s -> act s ens" }, { "name": "Veil.Wp.alwaysSuccessfullyTerminates", "content": "abbrev Wp.alwaysSuccessfullyTerminates {Οƒ } (req : SProp Οƒ) (act : Wp m Οƒ ρ) : Prop :=\n βˆ€ s, req s -> act s (fun _ _ => True)" }, { "name": "Veil.LawfulAction", "content": "class LawfulAction {Οƒ ρ : Type} (act : Wp m Οƒ ρ) where\n inter {Ο„ : Type} [Inhabited Ο„] (post : Ο„ -> RProp Οƒ ρ) :\n βˆ€ s : Οƒ, (βˆ€ t : Ο„, act s (post t)) -> act s (βˆ€ t, post t Β· Β·)\n\n impl (post post' : RProp Οƒ ρ) : βˆ€ s,\n (βˆ€ r s, post r s -> post' r s) -> act s post -> act s post'" } ]
[ { "name": "Veil.big_step_sound", "content": "theorem big_step_sound [LawfulAction act] (req : SProp Οƒ) (ens : RProp Οƒ ρ) :\n (Β¬ βˆ€ r s, ens r s) ->\n act.toBigStep.triple req ens -> act.triple req ens" }, { "name": "Veil.big_step_sound'", "content": "theorem big_step_sound' [LawfulAction act] (req : SProp Οƒ) (ens : RProp Οƒ ρ) :\n act.triple req ens β†’ act.toBigStep.triple req ens" }, { "name": "Veil.big_step_always_terminating_sound", "content": "theorem big_step_always_terminating_sound [LawfulAction act] (req : SProp Οƒ) (ens : RProp Οƒ ρ) :\n act.alwaysSuccessfullyTerminates req ->\n act.toBigStep.triple req ens -> act.triple req ens" } ]
import Veil.DSL.Base namespace Veil section Veil open Classical section Types inductive Mode where | internal : Mode | external : Mode deriving BEq variable (m : Mode) (Οƒ ρ : Type) @[inline] abbrev SProp := Οƒ -> Prop @[inline] abbrev RProp (ρ : Type u) := ρ β†’ SProp Οƒ @[inline] abbrev TwoState := Οƒ -> Οƒ -> Prop abbrev Wp (m : Mode) (Οƒ ρ : Type) := Οƒ -> RProp Οƒ ρ -> Prop abbrev Wlp (m : Mode) (Οƒ ρ : Type) := Οƒ -> RProp Οƒ ρ -> Prop abbrev BigStep := Οƒ -> ρ -> Οƒ -> Prop end Types section Theory variable {Οƒ ρ : Type} @[actSimp] def Wp.bind (wp : Wp m Οƒ ρ) (wp_cont : ρ -> Wp m Οƒ ρ') : Wp m Οƒ ρ' := fun s post => wp s (fun r s' => wp_cont r s' post) @[actSimp] def Wp.get : Wp m Οƒ Οƒ := fun s post => post s s @[actSimp] def Wp.set (s' : Οƒ) : Wp m Οƒ Unit := fun _ post => post () s' @[actSimp] def Wp.modifyGet (act : Οƒ -> ρ Γ— Οƒ) : Wp m Οƒ ρ := fun s post => let (ret, s') := act s ; post ret s' class IsSubStateOf (Οƒ : semiOutParam Type) (Οƒ' : Type) where setIn : Οƒ -> Οƒ' -> Οƒ' getFrom : Οƒ' -> Οƒ setIn_getFrom_idempotent : βˆ€ Οƒ', setIn (getFrom Οƒ') Οƒ' = Οƒ' getFrom_setIn_idempotent : βˆ€ Οƒ Οƒ', getFrom (setIn Οƒ Οƒ') = Οƒ @[actSimp] def Wp.lift {Οƒ Οƒ'} [IsSubStateOf Οƒ Οƒ'] (act : Wp m Οƒ ρ) : Wp m Οƒ' ρ := fun s' post => act (getFrom s') (fun r s => post r (setIn s s')) @[actSimp] abbrev Wp.toWlp {Οƒ ρ : Type} {m : Mode} (wp : Wp m Οƒ ρ) : Wlp m Οƒ ρ := fun (s : Οƒ) (post : RProp Οƒ ρ) => Β¬ wp s (fun r s' => Β¬ post r s') @[actSimp] def Wp.toBigStep {Οƒ} (wp : Wp m Οƒ ρ) : BigStep Οƒ ρ := fun s r' s' => wp.toWlp s (fun rβ‚€ sβ‚€ => r' = rβ‚€ ∧ s' = sβ‚€) @[actSimp] def BigStep.toWp {Οƒ} (act : BigStep Οƒ ρ) : Wp .internal Οƒ ρ := fun s post => βˆ€ r s', act s r s' -> post r s' @[actSimp] def _root_.Function.toWp (m : Mode) (r : TwoState Οƒ) : Wp m Οƒ Unit := fun s post => βˆ€ s', r s s' -> post () s' abbrev Wp.triple {Οƒ ρ} (req : SProp Οƒ) (act : Wp m Οƒ ρ) (ens : RProp Οƒ ρ) : Prop := βˆ€ s, req s -> act s ens abbrev Wp.alwaysSuccessfullyTerminates {Οƒ } (req : SProp Οƒ) (act : Wp m Οƒ ρ) : Prop := βˆ€ s, req s -> act s (fun _ _ => True) class LawfulAction {Οƒ ρ : Type} (act : Wp m Οƒ ρ) where inter {Ο„ : Type} [Inhabited Ο„] (post : Ο„ -> RProp Οƒ ρ) : βˆ€ s : Οƒ, (βˆ€ t : Ο„, act s (post t)) -> act s (βˆ€ t, post t Β· Β·) impl (post post' : RProp Οƒ ρ) : βˆ€ s, (βˆ€ r s, post r s -> post' r s) -> act s post -> act s post' section TwoStateSoundness end TwoStateSoundness section BigStepSoundness
theorem big_step_to_wp (act : Wp m Οƒ ρ) [LawfulAction act] (req : SProp Οƒ) : act.alwaysSuccessfullyTerminates req -> req s -> act s = act.toBigStep.toWp s :=
:= by intro hterm hreq; ext post; constructor { simp [BigStep.toWp]; intro _ _ _ solve_by_elim [big_step_sound'] } simp [BigStep.toWp] intro h; apply big_step_always_terminating_sound (req := (s = Β·)) <;> try simp { solve_by_elim } intro; simp_all
3
24
false
Framework
471
Veil.big_step_always_terminating_sound
theorem big_step_always_terminating_sound [LawfulAction act] (req : SProp Οƒ) (ens : RProp Οƒ ρ) : act.alwaysSuccessfullyTerminates req -> act.toBigStep.triple req ens -> act.triple req ens
veil
Veil/DSL/Action/Theory.lean
[ "import Veil.DSL.Base" ]
[ { "name": "BEq", "module": "Init.Prelude" }, { "name": "Inhabited", "module": "Init.Prelude" }, { "name": "impl", "module": "Mathlib.Deprecated.MLList.BestFirst" }, { "name": "r", "module": "Test.Playground.WHNFExamples" }, { "name": "t", "module": "Test.Unit.Normalize" }, { "name": "Unit", "module": "Init.Prelude" }, { "name": "semiOutParam", "module": "Init.Prelude" } ]
[ { "name": "...", "content": "..." } ]
[ { "name": "...", "module": "" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "Veil.Mode", "content": "inductive Mode where\n | internal : Mode\n | external : Mode\nderiving BEq" }, { "name": "Veil.SProp", "content": "@[inline] abbrev SProp := Οƒ -> Prop" }, { "name": "Veil.RProp", "content": "@[inline] abbrev RProp (ρ : Type u) := ρ β†’ SProp Οƒ" }, { "name": "Veil.Wp", "content": "abbrev Wp (m : Mode) (Οƒ ρ : Type) := Οƒ -> RProp Οƒ ρ -> Prop" }, { "name": "Veil.Wp.bind", "content": "@[actSimp] def Wp.bind (wp : Wp m Οƒ ρ) (wp_cont : ρ -> Wp m Οƒ ρ') : Wp m Οƒ ρ' :=\n fun s post => wp s (fun r s' => wp_cont r s' post)" }, { "name": "Veil.Wp.get", "content": "@[actSimp] def Wp.get : Wp m Οƒ Οƒ := fun s post => post s s" }, { "name": "Veil.Wp.set", "content": "@[actSimp] def Wp.set (s' : Οƒ) : Wp m Οƒ Unit := fun _ post => post () s'" }, { "name": "Veil.Wp.modifyGet", "content": "@[actSimp] def Wp.modifyGet (act : Οƒ -> ρ Γ— Οƒ) : Wp m Οƒ ρ := fun s post => let (ret, s') := act s ; post ret s'" }, { "name": "Veil.IsSubStateOf", "content": "class IsSubStateOf (Οƒ : semiOutParam Type) (Οƒ' : Type) where\n \n setIn : Οƒ -> Οƒ' -> Οƒ'\n \n getFrom : Οƒ' -> Οƒ\n\n setIn_getFrom_idempotent : βˆ€ Οƒ', setIn (getFrom Οƒ') Οƒ' = Οƒ'\n getFrom_setIn_idempotent : βˆ€ Οƒ Οƒ', getFrom (setIn Οƒ Οƒ') = Οƒ" }, { "name": "Veil.Wp.lift", "content": "@[actSimp] def Wp.lift {Οƒ Οƒ'} [IsSubStateOf Οƒ Οƒ'] (act : Wp m Οƒ ρ) : Wp m Οƒ' ρ :=\n fun s' post => act (getFrom s') (fun r s => post r (setIn s s'))" }, { "name": "Veil.LawfulAction", "content": "class LawfulAction {Οƒ ρ : Type} (act : Wp m Οƒ ρ) where\n inter {Ο„ : Type} [Inhabited Ο„] (post : Ο„ -> RProp Οƒ ρ) :\n βˆ€ s : Οƒ, (βˆ€ t : Ο„, act s (post t)) -> act s (βˆ€ t, post t Β· Β·)\n\n impl (post post' : RProp Οƒ ρ) : βˆ€ s,\n (βˆ€ r s, post r s -> post' r s) -> act s post -> act s post'" } ]
[ { "name": "Veil.big_step_sound", "content": "theorem big_step_sound [LawfulAction act] (req : SProp Οƒ) (ens : RProp Οƒ ρ) :\n (Β¬ βˆ€ r s, ens r s) ->\n act.toBigStep.triple req ens -> act.triple req ens" } ]
import Veil.DSL.Base namespace Veil section Veil open Classical section Types inductive Mode where | internal : Mode | external : Mode deriving BEq variable (m : Mode) (Οƒ ρ : Type) @[inline] abbrev SProp := Οƒ -> Prop @[inline] abbrev RProp (ρ : Type u) := ρ β†’ SProp Οƒ abbrev Wp (m : Mode) (Οƒ ρ : Type) := Οƒ -> RProp Οƒ ρ -> Prop end Types section Theory variable {Οƒ ρ : Type} @[actSimp] def Wp.bind (wp : Wp m Οƒ ρ) (wp_cont : ρ -> Wp m Οƒ ρ') : Wp m Οƒ ρ' := fun s post => wp s (fun r s' => wp_cont r s' post) @[actSimp] def Wp.get : Wp m Οƒ Οƒ := fun s post => post s s @[actSimp] def Wp.set (s' : Οƒ) : Wp m Οƒ Unit := fun _ post => post () s' @[actSimp] def Wp.modifyGet (act : Οƒ -> ρ Γ— Οƒ) : Wp m Οƒ ρ := fun s post => let (ret, s') := act s ; post ret s' class IsSubStateOf (Οƒ : semiOutParam Type) (Οƒ' : Type) where setIn : Οƒ -> Οƒ' -> Οƒ' getFrom : Οƒ' -> Οƒ setIn_getFrom_idempotent : βˆ€ Οƒ', setIn (getFrom Οƒ') Οƒ' = Οƒ' getFrom_setIn_idempotent : βˆ€ Οƒ Οƒ', getFrom (setIn Οƒ Οƒ') = Οƒ @[actSimp] def Wp.lift {Οƒ Οƒ'} [IsSubStateOf Οƒ Οƒ'] (act : Wp m Οƒ ρ) : Wp m Οƒ' ρ := fun s' post => act (getFrom s') (fun r s => post r (setIn s s')) class LawfulAction {Οƒ ρ : Type} (act : Wp m Οƒ ρ) where inter {Ο„ : Type} [Inhabited Ο„] (post : Ο„ -> RProp Οƒ ρ) : βˆ€ s : Οƒ, (βˆ€ t : Ο„, act s (post t)) -> act s (βˆ€ t, post t Β· Β·) impl (post post' : RProp Οƒ ρ) : βˆ€ s, (βˆ€ r s, post r s -> post' r s) -> act s post -> act s post' section TwoStateSoundness end TwoStateSoundness section BigStepSoundness
theorem big_step_always_terminating_sound [LawfulAction act] (req : SProp Οƒ) (ens : RProp Οƒ ρ) : act.alwaysSuccessfullyTerminates req -> act.toBigStep.triple req ens -> act.triple req ens :=
:= by intro ensTaut htriple s hreq by_cases h: (Β¬ βˆ€ r s, ens r s) { solve_by_elim [big_step_sound] } apply LawfulAction.impl (post := fun _ _ => True) <;> try simp_all
4
11
true
Framework
472
Veil.TwoState_sound'_ret_unit
theorem TwoState_sound'_ret_unit [LawfulAction act] (req : SProp Οƒ) (ens : RProp Οƒ PUnit) : act.triple req ens β†’ act.toTwoState.triple req (ens () Β·)
veil
Veil/DSL/Action/Theory.lean
[ "import Veil.DSL.Base" ]
[ { "name": "BEq", "module": "Init.Prelude" }, { "name": "Inhabited", "module": "Init.Prelude" }, { "name": "impl", "module": "Mathlib.Deprecated.MLList.BestFirst" }, { "name": "r", "module": "Test.Playground.WHNFExamples" }, { "name": "t", "module": "Test.Unit.Normalize" }, { "name": "PUnit", "module": "Init.Prelude" }, { "name": "PUnit.unit", "module": "Init.Prelude" }, { "name": "Unit", "module": "Init.Prelude" }, { "name": "semiOutParam", "module": "Init.Prelude" } ]
[ { "name": "syntax (name:= assumption) \"assumptionDef\" : attr", "content": "syntax (name:= assumption) \"assumptionDef\" : attr" } ]
[ { "name": "...", "module": "" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "Veil.Mode", "content": "inductive Mode where\n | internal : Mode\n | external : Mode\nderiving BEq" }, { "name": "Veil.SProp", "content": "@[inline] abbrev SProp := Οƒ -> Prop" }, { "name": "Veil.RProp", "content": "@[inline] abbrev RProp (ρ : Type u) := ρ β†’ SProp Οƒ" }, { "name": "Veil.Wp", "content": "abbrev Wp (m : Mode) (Οƒ ρ : Type) := Οƒ -> RProp Οƒ ρ -> Prop" }, { "name": "Veil.Wp.bind", "content": "@[actSimp] def Wp.bind (wp : Wp m Οƒ ρ) (wp_cont : ρ -> Wp m Οƒ ρ') : Wp m Οƒ ρ' :=\n fun s post => wp s (fun r s' => wp_cont r s' post)" }, { "name": "Veil.Wp.get", "content": "@[actSimp] def Wp.get : Wp m Οƒ Οƒ := fun s post => post s s" }, { "name": "Veil.Wp.set", "content": "@[actSimp] def Wp.set (s' : Οƒ) : Wp m Οƒ Unit := fun _ post => post () s'" }, { "name": "Veil.Wp.modifyGet", "content": "@[actSimp] def Wp.modifyGet (act : Οƒ -> ρ Γ— Οƒ) : Wp m Οƒ ρ := fun s post => let (ret, s') := act s ; post ret s'" }, { "name": "Veil.IsSubStateOf", "content": "class IsSubStateOf (Οƒ : semiOutParam Type) (Οƒ' : Type) where\n \n setIn : Οƒ -> Οƒ' -> Οƒ'\n \n getFrom : Οƒ' -> Οƒ\n\n setIn_getFrom_idempotent : βˆ€ Οƒ', setIn (getFrom Οƒ') Οƒ' = Οƒ'\n getFrom_setIn_idempotent : βˆ€ Οƒ Οƒ', getFrom (setIn Οƒ Οƒ') = Οƒ" }, { "name": "Veil.Wp.lift", "content": "@[actSimp] def Wp.lift {Οƒ Οƒ'} [IsSubStateOf Οƒ Οƒ'] (act : Wp m Οƒ ρ) : Wp m Οƒ' ρ :=\n fun s' post => act (getFrom s') (fun r s => post r (setIn s s'))" }, { "name": "Veil.Wp.triple", "content": "abbrev Wp.triple {Οƒ ρ} (req : SProp Οƒ) (act : Wp m Οƒ ρ) (ens : RProp Οƒ ρ) : Prop :=\n βˆ€ s, req s -> act s ens" }, { "name": "Veil.LawfulAction", "content": "class LawfulAction {Οƒ ρ : Type} (act : Wp m Οƒ ρ) where\n inter {Ο„ : Type} [Inhabited Ο„] (post : Ο„ -> RProp Οƒ ρ) :\n βˆ€ s : Οƒ, (βˆ€ t : Ο„, act s (post t)) -> act s (βˆ€ t, post t Β· Β·)\n\n impl (post post' : RProp Οƒ ρ) : βˆ€ s,\n (βˆ€ r s, post r s -> post' r s) -> act s post -> act s post'" } ]
[ { "name": "Veil.TwoState_sound'", "content": "theorem TwoState_sound' [LawfulAction act] (req : SProp Οƒ) (ens : RProp Οƒ ρ) :\n act.triple req ens β†’ act.toTwoState.triple req (βˆƒ r, ens r Β·)" }, { "name": "Veil.exists_over_PUnit", "content": "theorem exists_over_PUnit (p : PUnit β†’ Prop) : (βˆƒ (u : PUnit), p u) = p ()" } ]
import Veil.DSL.Base namespace Veil section Veil open Classical section Types inductive Mode where | internal : Mode | external : Mode deriving BEq variable (m : Mode) (Οƒ ρ : Type) @[inline] abbrev SProp := Οƒ -> Prop @[inline] abbrev RProp (ρ : Type u) := ρ β†’ SProp Οƒ abbrev Wp (m : Mode) (Οƒ ρ : Type) := Οƒ -> RProp Οƒ ρ -> Prop abbrev Wlp (m : Mode) (Οƒ ρ : Type) := Οƒ -> RProp Οƒ ρ -> Prop return value `r : ρ` and a post-state `s' : Οƒ` -/ abbrev BigStep := Οƒ -> ρ -> Οƒ -> Prop end Types section Theory variable {Οƒ ρ : Type} @[actSimp] def Wp.bind (wp : Wp m Οƒ ρ) (wp_cont : ρ -> Wp m Οƒ ρ') : Wp m Οƒ ρ' := fun s post => wp s (fun r s' => wp_cont r s' post) @[actSimp] def Wp.get : Wp m Οƒ Οƒ := fun s post => post s s @[actSimp] def Wp.set (s' : Οƒ) : Wp m Οƒ Unit := fun _ post => post () s' @[actSimp] def Wp.modifyGet (act : Οƒ -> ρ Γ— Οƒ) : Wp m Οƒ ρ := fun s post => let (ret, s') := act s ; post ret s' class IsSubStateOf (Οƒ : semiOutParam Type) (Οƒ' : Type) where setIn : Οƒ -> Οƒ' -> Οƒ' getFrom : Οƒ' -> Οƒ setIn_getFrom_idempotent : βˆ€ Οƒ', setIn (getFrom Οƒ') Οƒ' = Οƒ' getFrom_setIn_idempotent : βˆ€ Οƒ Οƒ', getFrom (setIn Οƒ Οƒ') = Οƒ @[actSimp] def Wp.lift {Οƒ Οƒ'} [IsSubStateOf Οƒ Οƒ'] (act : Wp m Οƒ ρ) : Wp m Οƒ' ρ := fun s' post => act (getFrom s') (fun r s => post r (setIn s s')) abbrev Wp.triple {Οƒ ρ} (req : SProp Οƒ) (act : Wp m Οƒ ρ) (ens : RProp Οƒ ρ) : Prop := βˆ€ s, req s -> act s ens class LawfulAction {Οƒ ρ : Type} (act : Wp m Οƒ ρ) where inter {Ο„ : Type} [Inhabited Ο„] (post : Ο„ -> RProp Οƒ ρ) : βˆ€ s : Οƒ, (βˆ€ t : Ο„, act s (post t)) -> act s (βˆ€ t, post t Β· Β·) impl (post post' : RProp Οƒ ρ) : βˆ€ s, (βˆ€ r s, post r s -> post' r s) -> act s post -> act s post' @[actSimp] abbrev Wp.toWlp {Οƒ ρ : Type} {m : Mode} (wp : Wp m Οƒ ρ) : Wlp m Οƒ ρ := -- `wlp(P, Ο†, s) = Β¬ wp(P, ¬φ, s)` fun (s : Οƒ) (post : RProp Οƒ ρ) => Β¬ wp s (fun r s' => Β¬ post r s') @[actSimp] def Wp.toBigStep {Οƒ} (wp : Wp m Οƒ ρ) : BigStep Οƒ ρ := fun s r' s' => wp.toWlp s (fun rβ‚€ sβ‚€ => r' = rβ‚€ ∧ s' = sβ‚€) @[actSimp] def Wp.toTwoState {Οƒ} (wp : Wp m Οƒ ρ) : TwoState Οƒ := fun s s' => wp.toWlp s (fun _ sβ‚€ => (s' = sβ‚€)) @[actSimp] def BigStep.toWp {Οƒ} (act : BigStep Οƒ ρ) : Wp .internal Οƒ ρ := fun s post => βˆ€ r s', act s r s' -> post r s' @[actSimp] def _root_.Function.toWp (m : Mode) (r : TwoState Οƒ) : Wp m Οƒ Unit := fun s post => βˆ€ s', r s s' -> post () s' abbrev refines {Οƒ ρ} (act : Wp m Οƒ ρ) (act' : Wp m Οƒ ρ) : Prop := βˆ€ s post, act s post -> act' s post instance : LE (Wp m Οƒ ρ) where le := refines abbrev Wp.triple {Οƒ ρ} (req : SProp Οƒ) (act : Wp m Οƒ ρ) (ens : RProp Οƒ ρ) : Prop := βˆ€ s, req s -> act s ens abbrev Wp.alwaysSuccessfullyTerminates {Οƒ } (req : SProp Οƒ) (act : Wp m Οƒ ρ) : Prop := βˆ€ s, req s -> act s (fun _ _ => True) abbrev TwoState.triple {Οƒ } (req : SProp Οƒ) (act : TwoState Οƒ) (ens : SProp Οƒ) : Prop := βˆ€ s s', req s -> act s s' -> ens s' abbrev BigStep.triple {Οƒ } (req : SProp Οƒ) (act : BigStep Οƒ ρ) (ens : RProp Οƒ ρ) : Prop := βˆ€ s r' s', req s -> act s r' s' -> ens r' s' section TwoStateSoundness
theorem TwoState_sound'_ret_unit [LawfulAction act] (req : SProp Οƒ) (ens : RProp Οƒ PUnit) : act.triple req ens β†’ act.toTwoState.triple req (ens () Β·) :=
:= by have heq : (ens () Β·) = (βˆƒ r, ens r Β·) := by ext ; rw [exists_over_PUnit] rw [heq] ; apply TwoState_sound'
4
15
true
Framework
473
FBA.slice_blocks_ne
theorem slice_blocks_ne : βˆ€ n S I, intact (inst := inst) I β†’ n ∈ I β†’ blocks_slices S n β†’ S ∩ I β‰  βˆ…
veil
Examples/StellarConsensus/SCPTheory.lean
[ "import Mathlib.Data.Set.Basic" ]
[ { "name": "Set", "module": "Mathlib.Data.Set.Defs" }, { "name": "p", "module": "Smt.Reconstruct.Certified.ModusPonens" } ]
[ { "name": "syntax (name:= assumption) \"assumptionDef\" : attr", "content": "syntax (name:= assumption) \"assumptionDef\" : attr" } ]
[ { "name": "Set.nonempty_iff_ne_empty", "module": "Mathlib.Data.Set.Basic" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "FBA.project", "content": "def project {Ξ± Ξ² : Type} (slices : Ξ² β†’ Set (Set Ξ±)) (S : Set Ξ±) : Ξ² β†’ Set (Set Ξ±) :=\n fun n => { Sl ∩ S | Sl ∈ slices n }" }, { "name": "FBA.System", "content": "class System (Node : Type) where\n \n W : Set Node\n slices : Node β†’ Set (Set Node)\n \n slices_ne : βˆ€ p ∈ W, slices p β‰  βˆ…" }, { "name": "FBA.System.project", "content": "def System.project (sys : System Node) (I : Set Node) : System Node :=\n { W := sys.W\n slices := FBA.project sys.slices I\n slices_ne := by admit /- proof elided -/" }, { "name": "FBA.quorum", "content": "def quorum (Q : Set Node) : Prop := βˆ€ p ∈ Q ∩ W, βˆƒ Sl ∈ slices p, Sl βŠ† Q" }, { "name": "FBA.blocks_slices", "content": "def blocks_slices (S : Set Node) (p : Node) : Prop :=\n βˆ€ Sl ∈ slices p, Sl ∩ S β‰  βˆ…" }, { "name": "FBA.intertwined", "content": "structure intertwined (S : Set Node) where\n well_behaved : S βŠ† W\n \n q_inter : (βˆ€ Q Q',\n quorum (inst := inst.project S) Q β†’\n quorum (inst := inst.project S) Q' β†’\n Q ∩ S β‰  βˆ… β†’ Q' ∩ S β‰  βˆ… β†’ Q ∩ Q' ∩ S β‰  βˆ…)" }, { "name": "FBA.intact", "content": "structure intact (I : Set Node) extends intertwined I where\n \n q_avail : quorum (inst := inst) I" } ]
[ { "name": "Set.ne_empty_iff_exists_mem", "content": "theorem Set.ne_empty_iff_exists_mem {Ξ± : Type u} {s : Set Ξ±} : s β‰  βˆ… ↔ βˆƒ a, a ∈ s" }, { "name": "FBA.intact_implies_intertwined", "content": "theorem intact_implies_intertwined : βˆ€ I, intact (inst := inst) I β†’ intertwined I" }, { "name": "FBA.intertwined_node_is_well_behaved", "content": "theorem intertwined_node_is_well_behaved : βˆ€ n S, intertwined (inst := inst) S β†’ n ∈ S β†’ n ∈ W" }, { "name": "FBA.intact_node_is_well_behaved", "content": "theorem intact_node_is_well_behaved : βˆ€ n I, intact (inst := inst) I β†’ n ∈ I β†’ n ∈ W" } ]
import Mathlib.Data.Set.Basic namespace FBA def project {Ξ± Ξ² : Type} (slices : Ξ² β†’ Set (Set Ξ±)) (S : Set Ξ±) : Ξ² β†’ Set (Set Ξ±) := fun n => { Sl ∩ S | Sl ∈ slices n } class System (Node : Type) where W : Set Node slices : Node β†’ Set (Set Node) slices_ne : βˆ€ p ∈ W, slices p β‰  βˆ… variable {Node : Type} def System.project (sys : System Node) (I : Set Node) : System Node := { W := sys.W slices := FBA.project sys.slices I slices_ne := by admit /- proof elided -/ variable [inst : System Node] open System def quorum (Q : Set Node) : Prop := βˆ€ p ∈ Q ∩ W, βˆƒ Sl ∈ slices p, Sl βŠ† Q def blocks_slices (S : Set Node) (p : Node) : Prop := βˆ€ Sl ∈ slices p, Sl ∩ S β‰  βˆ… structure intertwined (S : Set Node) where well_behaved : S βŠ† W q_inter : (βˆ€ Q Q', quorum (inst := inst.project S) Q β†’ quorum (inst := inst.project S) Q' β†’ Q ∩ S β‰  βˆ… β†’ Q' ∩ S β‰  βˆ… β†’ Q ∩ Q' ∩ S β‰  βˆ…) structure intact (I : Set Node) extends intertwined I where q_avail : quorum (inst := inst) I
theorem slice_blocks_ne : βˆ€ n S I, intact (inst := inst) I β†’ n ∈ I β†’ blocks_slices S n β†’ S ∩ I β‰  βˆ… :=
:= by intro n S I hI hin hblock unfold blocks_slices at hblock have h := hI.q_avail ; unfold quorum at h simp at h ; specialize h _ hin (intact_node_is_well_behaved _ _ hI hin) rcases h with ⟨Sl, hSl, h⟩ ; specialize hblock _ hSl rw [Set.ne_empty_iff_exists_mem] at hblock ⊒ ; simp at hblock ⊒ aesop
3
14
true
Framework
474
Term.lower_ite_hEquiv
theorem lower_ite_hEquiv {cond : Term .bool} {pos neg : Term Ο„} (hc : cond β‰ˆ lower cond) (hp : pos β‰ˆ lower pos) (hn : neg β‰ˆ lower neg) : ite cond pos neg β‰ˆ lower (ite cond pos neg)
verified-compiler
VerifiedCompiler.lean
[]
[ { "name": "Nat", "module": "Init.Prelude" }, { "name": "List", "module": "Init.Prelude" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "bool", "module": "Init.Control.Basic" }, { "name": "cond", "module": "Init.Prelude" }, { "name": "List.next", "module": "Mathlib.Data.List.Cycle" } ]
[ { "name": "...", "content": "..." } ]
[ { "name": "List.cons_append", "module": "Init.Data.List.Basic" }, { "name": "List.append_nil", "module": "Init.Data.List.Basic" }, { "name": "List.append_assoc", "module": "Init.Data.List.Basic" }, { "name": "List.length_append", "module": "Init.Data.List.Basic" }, { "name": "List.length_singleton", "module": "Init.Data.List.Basic" }, { "name": "List.singleton_append", "module": "Init.Data.List.Lemmas" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "Ty", "content": "inductive Ty\n | bool\n | nat" }, { "name": "Value", "content": "inductive Value : Ty β†’ Type\n | bool : Bool β†’ Value .bool\n | nat : Nat β†’ Value .nat" }, { "name": "Term", "content": "inductive Term : Ty β†’ Type\n | val (v : Value Ο„) : Term Ο„\n | ite (cond : Term .bool) (pos neg : Term Ο„) : Term Ο„\n | and (lhs rhs : Term .bool) : Term .bool" }, { "name": "Term.eval", "content": "def eval : Term Ο„ β†’ Value Ο„\n | val v => v\n | ite cond pos neg =>\n match eval cond with\n | true => eval pos\n | false => eval neg\n | and lhs rhs =>\n match eval lhs, eval rhs with\n | true, true => true\n | _, _ => false" }, { "name": "Instruction", "content": "inductive Instruction\n | const (n : Nat)\n | and\n | jmp (offset : Nat)\n | jez (offset : Nat)" }, { "name": "Program", "content": "abbrev Program := List Instruction" }, { "name": "Stack", "content": "abbrev Stack := List Nat" }, { "name": "Nat.conj", "content": "def Nat.conj : Nat β†’ Nat β†’ Nat\n | 0, _ | _, 0 => 0\n | _, _ => 1" }, { "name": "Instruction.Result", "content": "structure Instruction.Result where\n stack : Stack\n offset := 0" }, { "name": "Instruction.exec", "content": "def Instruction.exec : Instruction β†’ Stack β†’ Option Instruction.Result\n | .const n, stack => some { stack := n :: stack }\n | .and, r :: l :: tl => some { stack := (l.conj r) :: tl }\n | .and, _ => none\n | .jmp offset, stack => some { stack, offset }\n | .jez offset, 0 :: tl => some { stack := tl, offset }\n | .jez _, _ :: tl => some { stack := tl }\n | .jez _, _ => none" }, { "name": "Program.goto", "content": "def goto : Program β†’ Nat β†’ Option Program\n | prog, 0 => prog\n | [], _ + 1 => none\n | _ :: tl, offset + 1 => goto tl offset" }, { "name": "Program.exec", "content": "def exec : Program β†’ Stack β†’ Option Stack\n | [], stack => stack\n | hd :: tl, stack =>\n match Instruction.exec hd stack with\n | none => none\n | some { stack, offset } =>\n match h : goto tl offset with\n | none => none\n | some p => exec p stack\ntermination_by p => p.length\ndecreasing_by simp +arith [goto_decreasing h]" }, { "name": "Value.toNat", "content": "def Value.toNat : Value Ο„ β†’ Nat\n | bool false => 0\n | bool true => 1\n | nat n => n" }, { "name": "Term.lower", "content": "def Term.lower : Term Ο„ β†’ Program\n | val v => [.const v.toNat]\n | and lhs rhs => (lower lhs) ++ (lower rhs) ++ [.and]\n | ite cond pos neg =>\n let p := lower pos\n let n := lower neg\n lower cond ++ [.jez (p.length + 1)] ++ p ++ [.jmp n.length] ++ n" }, { "name": "HEquiv", "content": "def HEquiv (t : Term Ο„) (prog : Program) : Prop :=\n prog.exec [] = some [t.eval.toNat]" } ]
[ { "name": "Instruction.jmp_def", "content": "@[simp]\ntheorem jmp_def (offset s) : exec (.jmp offset) s = some ⟨s, offset⟩" }, { "name": "Instruction.jez_zero", "content": "@[simp]\ntheorem jez_zero (offset s) : exec (.jez offset) (0 :: s) = some ⟨s, offset⟩" }, { "name": "Instruction.jez_succ", "content": "@[simp]\ntheorem jez_succ (n offset s) : exec (.jez offset) ((n + 1) :: s) = some ⟨s, 0⟩" }, { "name": "Program.goto_zero", "content": "@[simp]\ntheorem goto_zero (prog : Program) : goto prog 0 = some prog" }, { "name": "Program.goto_suffix", "content": "@[simp]\ntheorem goto_suffix (prog₁ progβ‚‚ : Program) : goto (prog₁ ++ progβ‚‚) prog₁.length = some progβ‚‚" }, { "name": "Program.goto_end", "content": "@[simp]\ntheorem goto_end {prog : Program} (h : offset = prog.length) : goto prog offset = some []" }, { "name": "Program.exec_goto", "content": "theorem exec_goto (hi : i.exec s₁ = some ⟨sβ‚‚, offset⟩) (hg : goto prog₁ offset = some progβ‚‚) :\n exec (i :: prog₁) s₁ = exec progβ‚‚ sβ‚‚" }, { "name": "Program.goto_mono", "content": "theorem goto_mono (progβ‚‚ : Program) (h : goto prog₁ offset = some prog₁') :\n goto (prog₁ ++ progβ‚‚) offset = some (prog₁' ++ progβ‚‚)" }, { "name": "Program.exec_prog_mono", "content": "@[simp]\ntheorem exec_prog_mono (progβ‚‚ : Program) (h : exec prog₁ s₁ = some sβ‚‚) :\n exec (prog₁ ++ progβ‚‚) s₁ = exec progβ‚‚ sβ‚‚" }, { "name": "Term.eq_false_of_toNat_eq_zero", "content": "theorem eq_false_of_toNat_eq_zero {v : Value .bool} (h : v.toNat = 0) : v = false" }, { "name": "Term.eq_true_of_toNat_eq_succ", "content": "theorem eq_true_of_toNat_eq_succ {v : Value .bool} (h : v.toNat = n + 1) : v = true" } ]
inductive Ty | bool | nat inductive Value : Ty β†’ Type | bool : Bool β†’ Value .bool | nat : Nat β†’ Value .nat inductive Term : Ty β†’ Type | val (v : Value Ο„) : Term Ο„ | ite (cond : Term .bool) (pos neg : Term Ο„) : Term Ο„ | and (lhs rhs : Term .bool) : Term .bool namespace Term def eval : Term Ο„ β†’ Value Ο„ | val v => v | ite cond pos neg => match eval cond with | true => eval pos | false => eval neg | and lhs rhs => match eval lhs, eval rhs with | true, true => true | _, _ => false namespace Equiv infixl:50 " ~ " => Equiv end Equiv end Term open Term (eval) inductive Instruction | const (n : Nat) | and | jmp (offset : Nat) | jez (offset : Nat) abbrev Program := List Instruction abbrev Stack := List Nat def Nat.conj : Nat β†’ Nat β†’ Nat | 0, _ | _, 0 => 0 | _, _ => 1 structure Instruction.Result where stack : Stack offset := 0 def Instruction.exec : Instruction β†’ Stack β†’ Option Instruction.Result | .const n, stack => some { stack := n :: stack } | .and, r :: l :: tl => some { stack := (l.conj r) :: tl } | .and, _ => none | .jmp offset, stack => some { stack, offset } | .jez offset, 0 :: tl => some { stack := tl, offset } | .jez _, _ :: tl => some { stack := tl } | .jez _, _ => none namespace Program def goto : Program β†’ Nat β†’ Option Program | prog, 0 => prog | [], _ + 1 => none | _ :: tl, offset + 1 => goto tl offset def exec : Program β†’ Stack β†’ Option Stack | [], stack => stack | hd :: tl, stack => match Instruction.exec hd stack with | none => none | some { stack, offset } => match h : goto tl offset with | none => none | some p => exec p stack termination_by p => p.length decreasing_by simp +arith [goto_decreasing h] end Program def Value.toNat : Value Ο„ β†’ Nat | bool false => 0 | bool true => 1 | nat n => n def Term.lower : Term Ο„ β†’ Program | val v => [.const v.toNat] | and lhs rhs => (lower lhs) ++ (lower rhs) ++ [.and] | ite cond pos neg => let p := lower pos let n := lower neg lower cond ++ [.jez (p.length + 1)] ++ p ++ [.jmp n.length] ++ n def HEquiv (t : Term Ο„) (prog : Program) : Prop := prog.exec [] = some [t.eval.toNat] infixl:60 " β‰ˆ " => HEquiv namespace Instruction end Instruction namespace Program end Program namespace Term open Program List open Instruction hiding exec
theorem lower_ite_hEquiv {cond : Term .bool} {pos neg : Term Ο„} (hc : cond β‰ˆ lower cond) (hp : pos β‰ˆ lower pos) (hn : neg β‰ˆ lower neg) : ite cond pos neg β‰ˆ lower (ite cond pos neg) :=
:= by rw [HEquiv, lower, append_assoc, append_assoc, append_assoc] at * -- Give names to terms needed later. let pl := pos.lower.length + 1 let nl := neg.lower.length let prog₃ := [.jmp nl] ++ neg.lower let progβ‚‚ := pos.lower ++ prog₃ let prog₁ := [.jez pl] ++ progβ‚‚ -- Peel off the leading `lower cond`. rw [exec_prog_mono prog₁ hc] -- Continue differently depending on what's on top of the stack. cases h : cond.eval.toNat case zero => -- Peel off the leading `jez`. have hg := goto_suffix (pos.lower ++ [jmp nl]) neg.lower simp only [length_append, length_singleton, append_assoc] at hg have he := exec_goto (jez_zero pl []) hg simp only [prog₁, singleton_append, he] -- Close the goal by establishing that `eval` yields `neg.eval`. simp_all only [progβ‚‚, prog₃, eval, eq_false_of_toNat_eq_zero h] case succ n => -- Peel off the leading `jez`. have he := exec_goto (jez_succ n pl []) (goto_zero progβ‚‚) simp only [prog₁, singleton_append, he] -- Peel off the leading `lower pos`. rw [exec_prog_mono prog₃ hp] -- Peel off the leading `jmp`. have he := exec_goto (jmp_def nl [pos.eval.toNat]) (goto_end rfl) simp only [prog₃, singleton_append, he] -- Close the goal by establishing that `eval` yields `pos.eval`. simp only [eval, exec, eq_true_of_toNat_eq_succ h]
3
39
false
Compiler
475
Term.lower_and_hEquiv
theorem lower_and_hEquiv (hl : lhs β‰ˆ lower lhs) (hr : rhs β‰ˆ lower rhs) : and lhs rhs β‰ˆ lower (and lhs rhs)
verified-compiler
VerifiedCompiler.lean
[]
[ { "name": "Nat", "module": "Init.Prelude" }, { "name": "List", "module": "Init.Prelude" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "bool", "module": "Init.Control.Basic" }, { "name": "cond", "module": "Init.Prelude" }, { "name": "List.next", "module": "Mathlib.Data.List.Cycle" } ]
[ { "name": "...", "content": "..." } ]
[ { "name": "List.cons_append", "module": "Init.Data.List.Basic" }, { "name": "List.nil_append", "module": "Init.Data.List.Basic" }, { "name": "List.singleton_append", "module": "Init.Data.List.Lemmas" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "Ty", "content": "inductive Ty\n | bool\n | nat" }, { "name": "Value", "content": "inductive Value : Ty β†’ Type\n | bool : Bool β†’ Value .bool\n | nat : Nat β†’ Value .nat" }, { "name": "Term", "content": "inductive Term : Ty β†’ Type\n | val (v : Value Ο„) : Term Ο„\n | ite (cond : Term .bool) (pos neg : Term Ο„) : Term Ο„\n | and (lhs rhs : Term .bool) : Term .bool" }, { "name": "Term.eval", "content": "def eval : Term Ο„ β†’ Value Ο„\n | val v => v\n | ite cond pos neg =>\n match eval cond with\n | true => eval pos\n | false => eval neg\n | and lhs rhs =>\n match eval lhs, eval rhs with\n | true, true => true\n | _, _ => false" }, { "name": "Instruction", "content": "inductive Instruction\n | const (n : Nat)\n | and\n | jmp (offset : Nat)\n | jez (offset : Nat)" }, { "name": "Program", "content": "abbrev Program := List Instruction" }, { "name": "Stack", "content": "abbrev Stack := List Nat" }, { "name": "Nat.conj", "content": "def Nat.conj : Nat β†’ Nat β†’ Nat\n | 0, _ | _, 0 => 0\n | _, _ => 1" }, { "name": "Instruction.Result", "content": "structure Instruction.Result where\n stack : Stack\n offset := 0" }, { "name": "Instruction.exec", "content": "def Instruction.exec : Instruction β†’ Stack β†’ Option Instruction.Result\n | .const n, stack => some { stack := n :: stack }\n | .and, r :: l :: tl => some { stack := (l.conj r) :: tl }\n | .and, _ => none\n | .jmp offset, stack => some { stack, offset }\n | .jez offset, 0 :: tl => some { stack := tl, offset }\n | .jez _, _ :: tl => some { stack := tl }\n | .jez _, _ => none" }, { "name": "Program.goto", "content": "def goto : Program β†’ Nat β†’ Option Program\n | prog, 0 => prog\n | [], _ + 1 => none\n | _ :: tl, offset + 1 => goto tl offset" }, { "name": "Program.exec", "content": "def exec : Program β†’ Stack β†’ Option Stack\n | [], stack => stack\n | hd :: tl, stack =>\n match Instruction.exec hd stack with\n | none => none\n | some { stack, offset } =>\n match h : goto tl offset with\n | none => none\n | some p => exec p stack\ntermination_by p => p.length\ndecreasing_by simp +arith [goto_decreasing h]" }, { "name": "Value.toNat", "content": "def Value.toNat : Value Ο„ β†’ Nat\n | bool false => 0\n | bool true => 1\n | nat n => n" }, { "name": "Term.lower", "content": "def Term.lower : Term Ο„ β†’ Program\n | val v => [.const v.toNat]\n | and lhs rhs => (lower lhs) ++ (lower rhs) ++ [.and]\n | ite cond pos neg =>\n let p := lower pos\n let n := lower neg\n lower cond ++ [.jez (p.length + 1)] ++ p ++ [.jmp n.length] ++ n" }, { "name": "HEquiv", "content": "def HEquiv (t : Term Ο„) (prog : Program) : Prop :=\n prog.exec [] = some [t.eval.toNat]" } ]
[ { "name": "Instruction.exec_stack_mono", "content": "@[simp]\ntheorem exec_stack_mono (s : Stack) (h : exec inst s₁ = some ⟨sβ‚‚, o⟩) :\n exec inst (s₁ ++ s) = some ⟨sβ‚‚ ++ s, o⟩" }, { "name": "Program.goto_mono", "content": "theorem goto_mono (progβ‚‚ : Program) (h : goto prog₁ offset = some prog₁') :\n goto (prog₁ ++ progβ‚‚) offset = some (prog₁' ++ progβ‚‚)" }, { "name": "Program.exec_stack_mono", "content": "@[simp]\ntheorem exec_stack_mono (s : Stack) (h : exec prog s₁ = some sβ‚‚) :\n exec prog (s₁ ++ s) = sβ‚‚ ++ s" }, { "name": "Program.exec_prog_mono", "content": "@[simp]\ntheorem exec_prog_mono (progβ‚‚ : Program) (h : exec prog₁ s₁ = some sβ‚‚) :\n exec (prog₁ ++ progβ‚‚) s₁ = exec progβ‚‚ sβ‚‚" } ]
inductive Ty | bool | nat inductive Value : Ty β†’ Type | bool : Bool β†’ Value .bool | nat : Nat β†’ Value .nat inductive Term : Ty β†’ Type | val (v : Value Ο„) : Term Ο„ | ite (cond : Term .bool) (pos neg : Term Ο„) : Term Ο„ | and (lhs rhs : Term .bool) : Term .bool namespace Term def eval : Term Ο„ β†’ Value Ο„ | val v => v | ite cond pos neg => match eval cond with | true => eval pos | false => eval neg | and lhs rhs => match eval lhs, eval rhs with | true, true => true | _, _ => false namespace Equiv infixl:50 " ~ " => Equiv end Equiv end Term open Term (eval) inductive Instruction | const (n : Nat) | and | jmp (offset : Nat) | jez (offset : Nat) abbrev Program := List Instruction abbrev Stack := List Nat def Nat.conj : Nat β†’ Nat β†’ Nat | 0, _ | _, 0 => 0 | _, _ => 1 structure Instruction.Result where stack : Stack offset := 0 def Instruction.exec : Instruction β†’ Stack β†’ Option Instruction.Result | .const n, stack => some { stack := n :: stack } | .and, r :: l :: tl => some { stack := (l.conj r) :: tl } | .and, _ => none | .jmp offset, stack => some { stack, offset } | .jez offset, 0 :: tl => some { stack := tl, offset } | .jez _, _ :: tl => some { stack := tl } | .jez _, _ => none namespace Program def goto : Program β†’ Nat β†’ Option Program | prog, 0 => prog | [], _ + 1 => none | _ :: tl, offset + 1 => goto tl offset def exec : Program β†’ Stack β†’ Option Stack | [], stack => stack | hd :: tl, stack => match Instruction.exec hd stack with | none => none | some { stack, offset } => match h : goto tl offset with | none => none | some p => exec p stack termination_by p => p.length decreasing_by simp +arith [goto_decreasing h] end Program def Value.toNat : Value Ο„ β†’ Nat | bool false => 0 | bool true => 1 | nat n => n def Term.lower : Term Ο„ β†’ Program | val v => [.const v.toNat] | and lhs rhs => (lower lhs) ++ (lower rhs) ++ [.and] | ite cond pos neg => let p := lower pos let n := lower neg lower cond ++ [.jez (p.length + 1)] ++ p ++ [.jmp n.length] ++ n def HEquiv (t : Term Ο„) (prog : Program) : Prop := prog.exec [] = some [t.eval.toNat] infixl:60 " β‰ˆ " => HEquiv namespace Instruction end Instruction namespace Program end Program namespace Term open Program List open Instruction hiding exec
theorem lower_and_hEquiv (hl : lhs β‰ˆ lower lhs) (hr : rhs β‰ˆ lower rhs) : and lhs rhs β‰ˆ lower (and lhs rhs) :=
:= by have h₁ := exec_prog_mono (lower rhs ++ [.and]) hl have hβ‚‚ := exec_stack_mono [lhs.eval.toNat] hr simp only [nil_append, singleton_append] at hβ‚‚ have h₃ := exec_prog_mono [.and] hβ‚‚ simp [h₁, h₃, HEquiv, lower, exec, goto, Instruction.exec]
4
28
false
Compiler
476
Term.lower_hEquiv
theorem lower_hEquiv (t : Term Ο„) : t β‰ˆ lower t
verified-compiler
VerifiedCompiler.lean
[]
[ { "name": "Nat", "module": "Init.Prelude" }, { "name": "List", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "bool", "module": "Init.Control.Basic" }, { "name": "cond", "module": "Init.Prelude" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "List.next", "module": "Mathlib.Data.List.Cycle" } ]
[ { "name": "...", "content": "..." } ]
[ { "name": "List.cons_append", "module": "Init.Data.List.Basic" }, { "name": "List.nil_append", "module": "Init.Data.List.Basic" }, { "name": "List.singleton_append", "module": "Init.Data.List.Lemmas" }, { "name": "List.append_nil", "module": "Init.Data.List.Basic" }, { "name": "List.append_assoc", "module": "Init.Data.List.Basic" }, { "name": "List.length_append", "module": "Init.Data.List.Basic" }, { "name": "List.length_singleton", "module": "Init.Data.List.Basic" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "Ty", "content": "inductive Ty\n | bool\n | nat" }, { "name": "Value", "content": "inductive Value : Ty β†’ Type\n | bool : Bool β†’ Value .bool\n | nat : Nat β†’ Value .nat" }, { "name": "Term", "content": "inductive Term : Ty β†’ Type\n | val (v : Value Ο„) : Term Ο„\n | ite (cond : Term .bool) (pos neg : Term Ο„) : Term Ο„\n | and (lhs rhs : Term .bool) : Term .bool" }, { "name": "Term.eval", "content": "def eval : Term Ο„ β†’ Value Ο„\n | val v => v\n | ite cond pos neg =>\n match eval cond with\n | true => eval pos\n | false => eval neg\n | and lhs rhs =>\n match eval lhs, eval rhs with\n | true, true => true\n | _, _ => false" }, { "name": "Instruction", "content": "inductive Instruction\n | const (n : Nat)\n | and\n | jmp (offset : Nat)\n | jez (offset : Nat)" }, { "name": "Program", "content": "abbrev Program := List Instruction" }, { "name": "Stack", "content": "abbrev Stack := List Nat" }, { "name": "Nat.conj", "content": "def Nat.conj : Nat β†’ Nat β†’ Nat\n | 0, _ | _, 0 => 0\n | _, _ => 1" }, { "name": "Instruction.Result", "content": "structure Instruction.Result where\n stack : Stack\n offset := 0" }, { "name": "Instruction.exec", "content": "def Instruction.exec : Instruction β†’ Stack β†’ Option Instruction.Result\n | .const n, stack => some { stack := n :: stack }\n | .and, r :: l :: tl => some { stack := (l.conj r) :: tl }\n | .and, _ => none\n | .jmp offset, stack => some { stack, offset }\n | .jez offset, 0 :: tl => some { stack := tl, offset }\n | .jez _, _ :: tl => some { stack := tl }\n | .jez _, _ => none" }, { "name": "Program.goto", "content": "def goto : Program β†’ Nat β†’ Option Program\n | prog, 0 => prog\n | [], _ + 1 => none\n | _ :: tl, offset + 1 => goto tl offset" }, { "name": "Program.exec", "content": "def exec : Program β†’ Stack β†’ Option Stack\n | [], stack => stack\n | hd :: tl, stack =>\n match Instruction.exec hd stack with\n | none => none\n | some { stack, offset } =>\n match h : goto tl offset with\n | none => none\n | some p => exec p stack\ntermination_by p => p.length\ndecreasing_by simp +arith [goto_decreasing h]" }, { "name": "Value.toNat", "content": "def Value.toNat : Value Ο„ β†’ Nat\n | bool false => 0\n | bool true => 1\n | nat n => n" }, { "name": "Term.lower", "content": "def Term.lower : Term Ο„ β†’ Program\n | val v => [.const v.toNat]\n | and lhs rhs => (lower lhs) ++ (lower rhs) ++ [.and]\n | ite cond pos neg =>\n let p := lower pos\n let n := lower neg\n lower cond ++ [.jez (p.length + 1)] ++ p ++ [.jmp n.length] ++ n" }, { "name": "HEquiv", "content": "def HEquiv (t : Term Ο„) (prog : Program) : Prop :=\n prog.exec [] = some [t.eval.toNat]" } ]
[ { "name": "Instruction.jmp_def", "content": "@[simp]\ntheorem jmp_def (offset s) : exec (.jmp offset) s = some ⟨s, offset⟩" }, { "name": "Instruction.jez_zero", "content": "@[simp]\ntheorem jez_zero (offset s) : exec (.jez offset) (0 :: s) = some ⟨s, offset⟩" }, { "name": "Instruction.jez_succ", "content": "@[simp]\ntheorem jez_succ (n offset s) : exec (.jez offset) ((n + 1) :: s) = some ⟨s, 0⟩" }, { "name": "Instruction.exec_stack_mono", "content": "@[simp]\ntheorem exec_stack_mono (s : Stack) (h : exec inst s₁ = some ⟨sβ‚‚, o⟩) :\n exec inst (s₁ ++ s) = some ⟨sβ‚‚ ++ s, o⟩" }, { "name": "Program.goto_zero", "content": "@[simp]\ntheorem goto_zero (prog : Program) : goto prog 0 = some prog" }, { "name": "Program.goto_suffix", "content": "@[simp]\ntheorem goto_suffix (prog₁ progβ‚‚ : Program) : goto (prog₁ ++ progβ‚‚) prog₁.length = some progβ‚‚" }, { "name": "Program.goto_end", "content": "@[simp]\ntheorem goto_end {prog : Program} (h : offset = prog.length) : goto prog offset = some []" }, { "name": "Program.exec_goto", "content": "theorem exec_goto (hi : i.exec s₁ = some ⟨sβ‚‚, offset⟩) (hg : goto prog₁ offset = some progβ‚‚) :\n exec (i :: prog₁) s₁ = exec progβ‚‚ sβ‚‚" }, { "name": "Program.goto_mono", "content": "theorem goto_mono (progβ‚‚ : Program) (h : goto prog₁ offset = some prog₁') :\n goto (prog₁ ++ progβ‚‚) offset = some (prog₁' ++ progβ‚‚)" }, { "name": "Program.exec_stack_mono", "content": "@[simp]\ntheorem exec_stack_mono (s : Stack) (h : exec prog s₁ = some sβ‚‚) :\n exec prog (s₁ ++ s) = sβ‚‚ ++ s" }, { "name": "Program.exec_prog_mono", "content": "@[simp]\ntheorem exec_prog_mono (progβ‚‚ : Program) (h : exec prog₁ s₁ = some sβ‚‚) :\n exec (prog₁ ++ progβ‚‚) s₁ = exec progβ‚‚ sβ‚‚" }, { "name": "Term.eq_false_of_toNat_eq_zero", "content": "theorem eq_false_of_toNat_eq_zero {v : Value .bool} (h : v.toNat = 0) : v = false" }, { "name": "Term.eq_true_of_toNat_eq_succ", "content": "theorem eq_true_of_toNat_eq_succ {v : Value .bool} (h : v.toNat = n + 1) : v = true" }, { "name": "Term.lower_val_hEquiv", "content": "theorem lower_val_hEquiv (v : Value Ο„) : val v β‰ˆ lower (val v)" }, { "name": "Term.lower_and_hEquiv", "content": "theorem lower_and_hEquiv (hl : lhs β‰ˆ lower lhs) (hr : rhs β‰ˆ lower rhs) :\n and lhs rhs β‰ˆ lower (and lhs rhs)" }, { "name": "Term.lower_ite_hEquiv", "content": "theorem lower_ite_hEquiv {cond : Term .bool} {pos neg : Term Ο„}\n (hc : cond β‰ˆ lower cond) (hp : pos β‰ˆ lower pos) (hn : neg β‰ˆ lower neg) :\n ite cond pos neg β‰ˆ lower (ite cond pos neg)" } ]
inductive Ty | bool | nat inductive Value : Ty β†’ Type | bool : Bool β†’ Value .bool | nat : Nat β†’ Value .nat inductive Term : Ty β†’ Type | val (v : Value Ο„) : Term Ο„ | ite (cond : Term .bool) (pos neg : Term Ο„) : Term Ο„ | and (lhs rhs : Term .bool) : Term .bool namespace Term def eval : Term Ο„ β†’ Value Ο„ | val v => v | ite cond pos neg => match eval cond with | true => eval pos | false => eval neg | and lhs rhs => match eval lhs, eval rhs with | true, true => true | _, _ => false namespace Equiv infixl:50 " ~ " => Equiv end Equiv end Term open Term (eval) inductive Instruction | const (n : Nat) | and | jmp (offset : Nat) | jez (offset : Nat) abbrev Program := List Instruction abbrev Stack := List Nat def Nat.conj : Nat β†’ Nat β†’ Nat | 0, _ | _, 0 => 0 | _, _ => 1 structure Instruction.Result where stack : Stack offset := 0 def Instruction.exec : Instruction β†’ Stack β†’ Option Instruction.Result | .const n, stack => some { stack := n :: stack } | .and, r :: l :: tl => some { stack := (l.conj r) :: tl } | .and, _ => none | .jmp offset, stack => some { stack, offset } | .jez offset, 0 :: tl => some { stack := tl, offset } | .jez _, _ :: tl => some { stack := tl } | .jez _, _ => none namespace Program def goto : Program β†’ Nat β†’ Option Program | prog, 0 => prog | [], _ + 1 => none | _ :: tl, offset + 1 => goto tl offset def exec : Program β†’ Stack β†’ Option Stack | [], stack => stack | hd :: tl, stack => match Instruction.exec hd stack with | none => none | some { stack, offset } => match h : goto tl offset with | none => none | some p => exec p stack termination_by p => p.length decreasing_by simp +arith [goto_decreasing h] end Program def Value.toNat : Value Ο„ β†’ Nat | bool false => 0 | bool true => 1 | nat n => n def Term.lower : Term Ο„ β†’ Program | val v => [.const v.toNat] | and lhs rhs => (lower lhs) ++ (lower rhs) ++ [.and] | ite cond pos neg => let p := lower pos let n := lower neg lower cond ++ [.jez (p.length + 1)] ++ p ++ [.jmp n.length] ++ n def HEquiv (t : Term Ο„) (prog : Program) : Prop := prog.exec [] = some [t.eval.toNat] infixl:60 " β‰ˆ " => HEquiv namespace Instruction end Instruction namespace Program end Program namespace Term open Program List open Instruction hiding exec
theorem lower_hEquiv (t : Term Ο„) : t β‰ˆ lower t :=
:= by induction t case val => exact lower_val_hEquiv _ case and hl hr => exact lower_and_hEquiv hl hr case ite hc hp hn => exact lower_ite_hEquiv hc hp hn
4
44
false
Compiler
477
Term.constFold_equiv
theorem constFold_equiv (t : Term Ο„) : t ~ constFold t
verified-compiler
VerifiedCompiler.lean
[]
[ { "name": "Bool", "module": "Init.Prelude" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "bool", "module": "Init.Control.Basic" }, { "name": "cond", "module": "Init.Prelude" } ]
[ { "name": "...", "content": "..." } ]
[ { "name": "...", "module": "" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "Ty", "content": "inductive Ty\n | bool\n | nat" }, { "name": "Value", "content": "inductive Value : Ty β†’ Type\n | bool : Bool β†’ Value .bool\n | nat : Nat β†’ Value .nat" }, { "name": "Term", "content": "inductive Term : Ty β†’ Type\n | val (v : Value Ο„) : Term Ο„\n | ite (cond : Term .bool) (pos neg : Term Ο„) : Term Ο„\n | and (lhs rhs : Term .bool) : Term .bool" }, { "name": "Term.eval", "content": "def eval : Term Ο„ β†’ Value Ο„\n | val v => v\n | ite cond pos neg =>\n match eval cond with\n | true => eval pos\n | false => eval neg\n | and lhs rhs =>\n match eval lhs, eval rhs with\n | true, true => true\n | _, _ => false" }, { "name": "Term.constFold", "content": "def constFold : Term Ο„ β†’ Term Ο„\n | val v => val v\n | ite cond pos neg => ite (constFold cond) (constFold pos) (constFold neg)\n | and true true => true\n | and (Value.bool _) (Value.bool _) => false\n | and lhs rhs => and (constFold lhs) (constFold rhs)" }, { "name": "Term.Equiv", "content": "def Equiv (t₁ tβ‚‚ : Term Ο„) : Prop :=\n eval t₁ = eval tβ‚‚" } ]
[]
inductive Ty | bool | nat inductive Value : Ty β†’ Type | bool : Bool β†’ Value .bool | nat : Nat β†’ Value .nat inductive Term : Ty β†’ Type | val (v : Value Ο„) : Term Ο„ | ite (cond : Term .bool) (pos neg : Term Ο„) : Term Ο„ | and (lhs rhs : Term .bool) : Term .bool namespace Term def eval : Term Ο„ β†’ Value Ο„ | val v => v | ite cond pos neg => match eval cond with | true => eval pos | false => eval neg | and lhs rhs => match eval lhs, eval rhs with | true, true => true | _, _ => false def constFold : Term Ο„ β†’ Term Ο„ | val v => val v | ite cond pos neg => ite (constFold cond) (constFold pos) (constFold neg) | and true true => true | and (Value.bool _) (Value.bool _) => false | and lhs rhs => and (constFold lhs) (constFold rhs) def Equiv (t₁ tβ‚‚ : Term Ο„) : Prop := eval t₁ = eval tβ‚‚ namespace Equiv infixl:50 " ~ " => Equiv end Equiv
theorem constFold_equiv (t : Term Ο„) : t ~ constFold t :=
:= by induction t case val v => rfl case ite hc hp hn => exact Equiv.ite_congr hc hp hn case and lhs rhs hl hr => unfold constFold cases lhs <;> cases rhs case val.val v₁ vβ‚‚ => cases v₁; cases vβ‚‚; cases β€ΉBoolβ€Ί <;> cases β€ΉBoolβ€Ί <;> simp all_goals simp only [Equiv.and_congr hl hr]
3
12
false
Compiler
478
Program.exec_prog_mono
@[simp] theorem exec_prog_mono (progβ‚‚ : Program) (h : exec prog₁ s₁ = some sβ‚‚) : exec (prog₁ ++ progβ‚‚) s₁ = exec progβ‚‚ sβ‚‚
verified-compiler
VerifiedCompiler.lean
[]
[ { "name": "Nat", "module": "Init.Prelude" }, { "name": "List", "module": "Init.Prelude" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "List.next", "module": "Mathlib.Data.List.Cycle" } ]
[ { "name": "...", "content": "..." } ]
[ { "name": "List.cons_append", "module": "Init.Data.List.Basic" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "Instruction", "content": "inductive Instruction\n | const (n : Nat)\n | and\n | jmp (offset : Nat)\n | jez (offset : Nat)" }, { "name": "Program", "content": "abbrev Program := List Instruction" }, { "name": "Stack", "content": "abbrev Stack := List Nat" }, { "name": "Nat.conj", "content": "def Nat.conj : Nat β†’ Nat β†’ Nat\n | 0, _ | _, 0 => 0\n | _, _ => 1" }, { "name": "Instruction.Result", "content": "structure Instruction.Result where\n stack : Stack\n offset := 0" }, { "name": "Instruction.exec", "content": "def Instruction.exec : Instruction β†’ Stack β†’ Option Instruction.Result\n | .const n, stack => some { stack := n :: stack }\n | .and, r :: l :: tl => some { stack := (l.conj r) :: tl }\n | .and, _ => none\n | .jmp offset, stack => some { stack, offset }\n | .jez offset, 0 :: tl => some { stack := tl, offset }\n | .jez _, _ :: tl => some { stack := tl }\n | .jez _, _ => none" }, { "name": "Program.goto", "content": "def goto : Program β†’ Nat β†’ Option Program\n | prog, 0 => prog\n | [], _ + 1 => none\n | _ :: tl, offset + 1 => goto tl offset" }, { "name": "Program.exec", "content": "def exec : Program β†’ Stack β†’ Option Stack\n | [], stack => stack\n | hd :: tl, stack =>\n match Instruction.exec hd stack with\n | none => none\n | some { stack, offset } =>\n match h : goto tl offset with\n | none => none\n | some p => exec p stack\ntermination_by p => p.length\ndecreasing_by simp +arith [goto_decreasing h]" } ]
[ { "name": "Program.goto_mono", "content": "theorem goto_mono (progβ‚‚ : Program) (h : goto prog₁ offset = some prog₁') :\n goto (prog₁ ++ progβ‚‚) offset = some (prog₁' ++ progβ‚‚)" } ]
namespace Term namespace Equiv infixl:50 " ~ " => Equiv end Equiv end Term open Term (eval) inductive Instruction | const (n : Nat) | and | jmp (offset : Nat) | jez (offset : Nat) abbrev Program := List Instruction abbrev Stack := List Nat def Nat.conj : Nat β†’ Nat β†’ Nat | 0, _ | _, 0 => 0 | _, _ => 1 structure Instruction.Result where stack : Stack offset := 0 def Instruction.exec : Instruction β†’ Stack β†’ Option Instruction.Result | .const n, stack => some { stack := n :: stack } | .and, r :: l :: tl => some { stack := (l.conj r) :: tl } | .and, _ => none | .jmp offset, stack => some { stack, offset } | .jez offset, 0 :: tl => some { stack := tl, offset } | .jez _, _ :: tl => some { stack := tl } | .jez _, _ => none namespace Program def goto : Program β†’ Nat β†’ Option Program | prog, 0 => prog | [], _ + 1 => none | _ :: tl, offset + 1 => goto tl offset def exec : Program β†’ Stack β†’ Option Stack | [], stack => stack | hd :: tl, stack => match Instruction.exec hd stack with | none => none | some { stack, offset } => match h : goto tl offset with | none => none | some p => exec p stack termination_by p => p.length decreasing_by simp +arith [goto_decreasing h] end Program infixl:60 " β‰ˆ " => HEquiv namespace Instruction end Instruction namespace Program
@[simp] theorem exec_prog_mono (progβ‚‚ : Program) (h : exec prog₁ s₁ = some sβ‚‚) : exec (prog₁ ++ progβ‚‚) s₁ = exec progβ‚‚ sβ‚‚ :=
:= by induction prog₁, s₁ using exec.induct <;> try (simp_all [exec]; done) next hh hg => simp only [exec, hh] at h rw [hg] at h contradiction next hh _ hg hi => simp only [exec, hh, List.cons_append] at * rw [hg] at h rw [Program.goto_mono _ hg, ←(hi h)]
3
14
false
Compiler
479
Program.exec_stack_mono
@[simp] theorem exec_stack_mono (s : Stack) (h : exec prog s₁ = some sβ‚‚) : exec prog (s₁ ++ s) = sβ‚‚ ++ s
verified-compiler
VerifiedCompiler.lean
[]
[ { "name": "List", "module": "Init.Prelude" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "List.next", "module": "Mathlib.Data.List.Cycle" } ]
[ { "name": "...", "content": "..." } ]
[ { "name": "...", "module": "" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "Instruction", "content": "inductive Instruction\n | const (n : Nat)\n | and\n | jmp (offset : Nat)\n | jez (offset : Nat)" }, { "name": "Program", "content": "abbrev Program := List Instruction" }, { "name": "Stack", "content": "abbrev Stack := List Nat" }, { "name": "Nat.conj", "content": "def Nat.conj : Nat β†’ Nat β†’ Nat\n | 0, _ | _, 0 => 0\n | _, _ => 1" }, { "name": "Instruction.Result", "content": "structure Instruction.Result where\n stack : Stack\n offset := 0" }, { "name": "Instruction.exec", "content": "def Instruction.exec : Instruction β†’ Stack β†’ Option Instruction.Result\n | .const n, stack => some { stack := n :: stack }\n | .and, r :: l :: tl => some { stack := (l.conj r) :: tl }\n | .and, _ => none\n | .jmp offset, stack => some { stack, offset }\n | .jez offset, 0 :: tl => some { stack := tl, offset }\n | .jez _, _ :: tl => some { stack := tl }\n | .jez _, _ => none" }, { "name": "Program.goto", "content": "def goto : Program β†’ Nat β†’ Option Program\n | prog, 0 => prog\n | [], _ + 1 => none\n | _ :: tl, offset + 1 => goto tl offset" }, { "name": "Program.exec", "content": "def exec : Program β†’ Stack β†’ Option Stack\n | [], stack => stack\n | hd :: tl, stack =>\n match Instruction.exec hd stack with\n | none => none\n | some { stack, offset } =>\n match h : goto tl offset with\n | none => none\n | some p => exec p stack\ntermination_by p => p.length\ndecreasing_by simp +arith [goto_decreasing h]" } ]
[ { "name": "Instruction.exec_stack_mono", "content": "@[simp]\ntheorem exec_stack_mono (s : Stack) (h : exec inst s₁ = some ⟨sβ‚‚, o⟩) :\n exec inst (s₁ ++ s) = some ⟨sβ‚‚ ++ s, o⟩" } ]
namespace Term namespace Equiv infixl:50 " ~ " => Equiv end Equiv end Term open Term (eval) inductive Instruction | const (n : Nat) | and | jmp (offset : Nat) | jez (offset : Nat) abbrev Program := List Instruction abbrev Stack := List Nat def Nat.conj : Nat β†’ Nat β†’ Nat | 0, _ | _, 0 => 0 | _, _ => 1 structure Instruction.Result where stack : Stack offset := 0 def Instruction.exec : Instruction β†’ Stack β†’ Option Instruction.Result | .const n, stack => some { stack := n :: stack } | .and, r :: l :: tl => some { stack := (l.conj r) :: tl } | .and, _ => none | .jmp offset, stack => some { stack, offset } | .jez offset, 0 :: tl => some { stack := tl, offset } | .jez _, _ :: tl => some { stack := tl } | .jez _, _ => none namespace Program def goto : Program β†’ Nat β†’ Option Program | prog, 0 => prog | [], _ + 1 => none | _ :: tl, offset + 1 => goto tl offset def exec : Program β†’ Stack β†’ Option Stack | [], stack => stack | hd :: tl, stack => match Instruction.exec hd stack with | none => none | some { stack, offset } => match h : goto tl offset with | none => none | some p => exec p stack termination_by p => p.length decreasing_by simp +arith [goto_decreasing h] end Program infixl:60 " β‰ˆ " => HEquiv namespace Instruction end Instruction namespace Program
@[simp] theorem exec_stack_mono (s : Stack) (h : exec prog s₁ = some sβ‚‚) : exec prog (s₁ ++ s) = sβ‚‚ ++ s :=
:= by induction prog, s₁ using exec.induct <;> try (simp_all [exec]; done) next hh hg => simp only [exec, hh] at h rw [hg] at h contradiction next hh _ hg hi => simp only [exec, hh, Instruction.exec_stack_mono _ hh] at * rw [hg] at h ⊒ exact hi h
5
13
false
Compiler
480
Intmax.lemma4
lemma lemma4 (h : π₁ ≀ Ο€β‚‚) : Bal π₁ bs ≀ Bal Ο€β‚‚ bs
FVIntmax
FVIntmax/Lemma4.lean
[ "import FVIntmax.Wheels.Dictionary", "import FVIntmax.Wheels", "import FVIntmax.Balance" ]
[ { "name": "DecidableEq", "module": "Init.Prelude" }, { "name": "Preorder", "module": "Mathlib.Order.Defs.PartialOrder" }, { "name": "Zero", "module": "Init.Prelude" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "Set", "module": "Mathlib.Data.Set.Defs" }, { "name": "IsGLB", "module": "Mathlib.Order.Bounds.Defs" }, { "name": "And", "module": "Init.Prelude" }, { "name": "IsGreatest", "module": "Mathlib.Order.Bounds.Defs" }, { "name": "lowerBounds", "module": "Mathlib.Order.Bounds.Defs" }, { "name": "upperBounds", "module": "Mathlib.Order.Bounds.Defs" }, { "name": "InfSet", "module": "Mathlib.Order.SetNotation" }, { "name": "iInf", "module": "Mathlib.Order.SetNotation" }, { "name": "List", "module": "Init.Prelude" }, { "name": "Vector", "module": "Init.Data.Vector.Basic" }, { "name": "Finite", "module": "Mathlib.Data.Finite.Defs" }, { "name": "Fin", "module": "Init.Prelude" }, { "name": "Finset", "module": "Mathlib.Data.Finset.Defs" }, { "name": "Classical.arbitrary", "module": "Mathlib.Logic.Nonempty" }, { "name": "Monotone", "module": "Mathlib.Order.Monotone.Defs" }, { "name": "Finset.sort", "module": "Mathlib.Data.Finset.Sort" }, { "name": "LE", "module": "Init.Prelude" }, { "name": "List.length", "module": "Init.Prelude" }, { "name": "List.map", "module": "Init.Prelude" }, { "name": "Subtype", "module": "Init.Prelude" }, { "name": "flip", "module": "Init.Core" }, { "name": "LE.le", "module": "Init.Prelude" } ]
[ { "name": "local macro:max (priority := high) \"β†ͺ\" b:term : term => `(⟨$", "content": "local macro:max (priority := high) \"β†ͺ\" b:term : term => `(⟨$b, by admit /- proof elided -/\n⟩)" }, { "name": "S", "content": "abbrev S (K₁ Kβ‚‚ V : Type) [PreWithZero V] := { s : S' K₁ Kβ‚‚ V // s.isValid }" }, { "name": "S'", "content": "abbrev S' (K₁ Kβ‚‚ V : Type) := Kbar K₁ Kβ‚‚ β†’ V" }, { "name": "Kbar", "content": "inductive Kbar (K₁ Kβ‚‚ : Type) where\n | key (k : Key K₁ Kβ‚‚)\n | Source\nderiving DecidableEq" }, { "name": "Key", "content": "abbrev Key (K₁ Kβ‚‚ : Type) := K₁ βŠ• Kβ‚‚" }, { "name": "abbrev", "content": "class abbrev PreWithZero (Ξ± : Type) := Preorder Ξ±, Zero Ξ±" }, { "name": "fStar", "content": "def fStar (Ts : List (Ξ€ K₁ Kβ‚‚ V)) (sβ‚€ : S K₁ Kβ‚‚ V) : S K₁ Kβ‚‚ V :=\n Ts.foldl f sβ‚€" }, { "name": "f", "content": "def f (b : S K₁ Kβ‚‚ V) (T : Ξ€ K₁ Kβ‚‚ V) : S K₁ Kβ‚‚ V :=\n ⟨\n Ξ» k ↦\n have : InfSet V := infV b T k\n β¨… x : boundedBelow b T, fc x.1 k,\n by admit /- proof elided -/\n ⟩" }, { "name": "infV", "content": "def infV (b : S K₁ Kβ‚‚ V) (T : Ξ€ K₁ Kβ‚‚ V) (k : Kbar K₁ Kβ‚‚) :\n InfSet V where\n sInf := Ξ» s ↦ if s = V' b T k\n then (exists_inf b T).1 k\n else 0" }, { "name": "exists_inf", "content": "def exists_inf (b : S K₁ Kβ‚‚ V) (T : Ξ€ K₁ Kβ‚‚ V) : { s : S K₁ Kβ‚‚ V // βˆ€ k, IsGLB (V' b T k) (s k) } :=\n ⟨\n f' b T,\n Ξ» k ↦\n have f'_codomain : (f' b T) k ∈ V' b T k := by admit /- proof elided -/\n ⟩" }, { "name": "fc", "content": "def fc (Ο„cXb : Ξ€c K₁ Kβ‚‚ V Γ— S K₁ Kβ‚‚ V) : S K₁ Kβ‚‚ V :=\n ⟨λ k : Kbar K₁ Kβ‚‚ ↦\n match Ο„cXb with\n | ⟨⟨⟨⟨s, r, v⟩, _⟩, hΟ„βŸ©, b⟩ =>\n let v' := v' (v.get hΟ„) b s\n b k + (e r - e s) k β€’ v',\n by admit /- proof elided -/\n ⟩" }, { "name": "e", "content": "def e (i : Kbar K₁ Kβ‚‚) : Kbar K₁ Kβ‚‚ β†’ β„€ := Ξ» j ↦ if i = j then 1 else 0" }, { "name": "Ξ€c", "content": "abbrev Ξ€c (K₁ Kβ‚‚ V : Type) [PreWithZero V] : Type := { Ο„ : Ξ€ K₁ Kβ‚‚ V // Ο„.isComplete }" }, { "name": "Ξ€", "content": "abbrev Ξ€ (K₁ Kβ‚‚ V : Type) [PreWithZero V] := { Ο„ : Ξ€' K₁ Kβ‚‚ V // Ο„.isValid }" }, { "name": "Ξ€'", "content": "abbrev Ξ€' (K₁ Kβ‚‚ V : Type) [PreWithZero V] := Kbar K₁ Kβ‚‚ Γ— Kbar K₁ Kβ‚‚ Γ— Option Vβ‚Š" }, { "name": "NonNeg", "content": "def NonNeg (Ξ± : Type) [PreWithZero Ξ±] := { a : Ξ± // 0 ≀ a }" }, { "name": "boundedBelow", "content": "abbrev boundedBelow (b : S K₁ Kβ‚‚ V) (T : Ξ€ K₁ Kβ‚‚ V) :=\n { a : Ξ€c K₁ Kβ‚‚ V Γ— S K₁ Kβ‚‚ V | (T, b) ≀ (↑a.1, a.2) }" }, { "name": "f'", "content": "def f' (b : S K₁ Kβ‚‚ V) (T : Ξ€ K₁ Kβ‚‚ V) : S K₁ Kβ‚‚ V := \n ⟨\n Ξ» k ↦\n match h : T with\n | ⟨(_, _, .some _), hT⟩ => fc (⟨T, by admit /- proof elided -/\n ⟩, b) k\n | ⟨(s, _, .none), _⟩ => if k = s then 0 else b k,\n by admit /- proof elided -/\n ⟩" }, { "name": "Injective", "content": "class Injective {Ξ± Ο‰ : Type} (f : Ξ± β†’ Ο‰) where\n h : ComputationallyInfeasible (Β¬ Function.Injective f)" }, { "name": "V'", "content": "def V' (b : S K₁ Kβ‚‚ V) (T : Ξ€ K₁ Kβ‚‚ V) (k : Kbar K₁ Kβ‚‚) : Set V :=\n { v : V | v ∈ (fc Β· k) '' boundedBelow b T }" }, { "name": "isComplete", "content": "def isComplete (Ο„ : Ξ€ K₁ Kβ‚‚ V) :=\n match Ο„ with | ⟨(_, _, v), _⟩ => v.isSome" }, { "name": "BalanceProof", "content": "abbrev BalanceProof (K₁ Kβ‚‚ : Type) [Finite K₁] [Finite Kβ‚‚]\n (C Pi V : Type) [PreWithZero V] : Type :=\n Dict (C Γ— Kβ‚‚) ((Pi Γ— ExtraDataT) Γ— TransactionBatch K₁ Kβ‚‚ V) " }, { "name": "TransactionBatch", "content": "abbrev TransactionBatch (K₁ : Type) [Finite K₁]\n (Kβ‚‚ : Type) [Finite Kβ‚‚]\n (V : Type) [PreWithZero V] :=\n Key K₁ Kβ‚‚ β†’ Vβ‚Š" }, { "name": "ExtraDataT", "content": "abbrev ExtraDataT : Type := β„•" }, { "name": "Dict", "content": "abbrev Dict (Ξ± Ο‰ : Type) : Type := Ξ± β†’ Option Ο‰" }, { "name": "TransactionsInBlocks", "content": "def TransactionsInBlocks\n (Ο€ : BalanceProof K₁ Kβ‚‚ C Pi V) (bs : List (Block K₁ Kβ‚‚ C Sigma V)) : List (Ξ€ K₁ Kβ‚‚ V) :=\n (bs.map (TransactionsInBlock Ο€)).flatten" }, { "name": "TransactionsInBlock", "content": "def TransactionsInBlock (Ο€ : BalanceProof K₁ Kβ‚‚ C Pi V) (b : Block K₁ Kβ‚‚ C Sigma V) : List (Ξ€ K₁ Kβ‚‚ V) := \n match h : b with\n | .deposit .. => TransactionsInBlock_deposit β†ͺb\n | .transfer .. => TransactionsInBlock_transfer Ο€ β†ͺb\n | .withdrawal .. => TransactionsInBlock_withdrawal β†ͺb" }, { "name": "TransactionsInBlock_withdrawal", "content": "def TransactionsInBlock_withdrawal \n (b : { b : Block K₁ Kβ‚‚ C Sigma V // b.isWithdrawalBlock }) : List (Ξ€ K₁ Kβ‚‚ V) :=\n match h : b.1 with\n | .withdrawal withdrawals =>\n \n let k₁InOrder := { s | s : K₁ }.toFinset.sort (·≀·)\n k₁InOrder.attach.map Ξ» s : K₁ ↦ ⟨(s, .Source, withdrawals s), by admit /- proof elided -/\n ⟩\n | .deposit r v | .transfer .. => by admit /- proof elided -/" }, { "name": "Block", "content": "inductive Block (K₁ Kβ‚‚ : Type) (C Sigma : Type) (V : Type) [PreWithZero V] where\n \n | deposit (recipient : Kβ‚‚) (amount : Vβ‚Š)\n \n | transfer (aggregator : K₁) (extradata : ExtraDataT) (commitment : C) (senders : List Kβ‚‚) (sigma : Sigma)\n \n | withdrawal (withdrawals : K₁ β†’ Vβ‚Š)" }, { "name": "isWithdrawalBlock", "content": "abbrev isWithdrawalBlock (b : Block K₁ Kβ‚‚ C Sigma V) := b matches (Block.withdrawal _)" }, { "name": "attach", "content": "noncomputable def attach (Ξ± : Type) [Finite Ξ±] : UniquelyIndexed Ξ± :=\n have := Finite.exists_equiv_fin Ξ±\n this.choose_spec.some.toEmbedding" }, { "name": "UniquelyIndexed", "content": "abbrev UniquelyIndexed (Ξ± : Type) [Finite Ξ±] : Type := Ξ± β†ͺ !Ξ±" }, { "name": "UniqueTokenT", "content": "abbrev UniqueTokenT (Ξ± : Type) [Finite Ξ±] : Type := Fin (Finite.exists_equiv_fin Ξ± |>.choose)" }, { "name": "TransactionsInBlock_transfer", "content": "def TransactionsInBlock_transfer \n (Ο€ : BalanceProof K₁ Kβ‚‚ C Pi V) (b : { b : Block K₁ Kβ‚‚ C Sigma V // b.isTransferBlock }) : List (Ξ€ K₁ Kβ‚‚ V) :=\n match h : b.1 with\n | .transfer _ _ commitment S _ =>\n \n let senderRecipient : Finset (Kβ‚‚ Γ— Key K₁ Kβ‚‚) := { (kβ‚‚, k) | (kβ‚‚ : Kβ‚‚) (k : Key K₁ Kβ‚‚) (_h : kβ‚‚ β‰ β‚– k) }\n let sorted : List (Kβ‚‚ Γ— Key K₁ Kβ‚‚) := senderRecipient.sort Key.lexLe \n \n let v (s : Kβ‚‚) (r : Key K₁ Kβ‚‚) : Option Vβ‚Š :=\n if s βˆ‰ S\n then .some 0\n else \n if h : (commitment, s) ∈ Ο€.keys\n then let (_, t) := Ο€[(commitment, s)]\n t r\n else .none\n sorted.attach.map Ξ» ⟨(s, r), h⟩ ↦ ⟨(s, r, v s r), by admit /- proof elided -/\n ⟩\n | .deposit .. | .withdrawal .. => by admit /- proof elided -/" }, { "name": "lexLe", "content": "def lexLe (a b : Kβ‚‚ Γ— Key K₁ Kβ‚‚) : Prop :=\n a.1 < b.1 ∨ (a.1 = b.1 ∧ a.2 ≀ b.2)" }, { "name": "isTransferBlock", "content": "abbrev isTransferBlock (b : Block K₁ Kβ‚‚ C Sigma V) := b matches (Block.transfer _ _ _ _ _)" }, { "name": "keys", "content": "def keys (m : Dict Ξ± Ο‰) : Set Ξ± := { x | Dict.is_mem m x }" }, { "name": "Dict.is_mem", "content": "def Dict.is_mem (m : Dict Ξ± Ο‰) (x : Ξ±) : Prop := (m x).isSome" }, { "name": "keys", "content": "abbrev keys (ct : CommitT C K Pi) := ct.dict.keys" }, { "name": "CommitT", "content": "structure CommitT (C K Pi : Type) where\n commitment : C\n dict : Dict K Pi" }, { "name": "keysUneq", "content": "abbrev keysUneq (kβ‚‚ : Kβ‚‚) (k : Key K₁ Kβ‚‚) : Prop :=\n match k with\n | .inl _ => True\n | .inr kβ‚‚' => kβ‚‚ β‰  kβ‚‚'" }, { "name": "TransactionsInBlock_deposit", "content": "def TransactionsInBlock_deposit\n (b : { b : Block K₁ Kβ‚‚ C Sigma V // b.isDepositBlock }) : List (Ξ€ K₁ Kβ‚‚ V) :=\n match h : b.1 with\n | .deposit r v => [⟨(.Source, r, v), by admit /- proof elided -/\n ⟩]\n | .withdrawal .. | .transfer .. => by admit /- proof elided -/" }, { "name": "isDepositBlock", "content": "abbrev isDepositBlock (b : Block K₁ Kβ‚‚ C Sigma V) := b matches (Block.deposit _ _) " }, { "name": "initial", "content": "def initial (K₁ Kβ‚‚ V : Type) [PreWithZero V] : S K₁ Kβ‚‚ V :=\n ⟨S'.initial K₁ Kβ‚‚ V, S'.isValid_initial⟩" }, { "name": "Bal", "content": "def Bal (Ο€ : BalanceProof K₁ Kβ‚‚ C Pi V) (bs : List (Block K₁ Kβ‚‚ C Sigma V)) : S K₁ Kβ‚‚ V :=\n fStar (TransactionsInBlocks Ο€ bs) (.initial K₁ Kβ‚‚ V)" }, { "name": "initial", "content": "def initial : Scontract K₁ Kβ‚‚ V C Sigma := []" }, { "name": "Scontract", "content": "abbrev Scontract (K₁ Kβ‚‚ V : Type) [PreWithZero V] (C Sigma : Type) :=\n List (Block K₁ Kβ‚‚ C Sigma V)" }, { "name": "le", "content": "def le (v₁ vβ‚‚ : Vector Ξ± n) :=\n βˆ€ x ∈ (v₁.1.zip vβ‚‚.1), x.1 ≀ x.2" }, { "name": "v'", "content": "def v' (v : Vβ‚Š) (b : S K₁ Kβ‚‚ V) (s : Kbar K₁ Kβ‚‚) : Vβ‚Š :=\n match h : s with\n | .Source => v\n | .key _ => ⟨v βŠ“ b s, by admit /- proof elided -/\n ⟩" }, { "name": "(priority", "content": "instance (priority := high) vectorPreorder : Preorder (Vector Ξ± n) where\n le_refl := Ξ» _ ↦ Vec.le_refl\n le_trans := Ξ» _ _ _ ↦ Vec.le_trans" }, { "name": "infix:50 \" β‰ β‚– \" => Key.keysUneq ", "content": "infix:50 \" β‰ β‚– \" => Key.keysUneq " }, { "name": "prefix:max \"!\" => UniqueTokenT", "content": "prefix:max \"!\" => UniqueTokenT" }, { "name": "postfix:max \"β‚Š\" => NonNeg", "content": "postfix:max \"β‚Š\" => NonNeg" } ]
[ { "name": "not_and_or", "module": "Mathlib.Logic.Basic" }, { "name": "congr_fun", "module": "Batteries.Logic" }, { "name": "List.ext_get_iff", "module": "Mathlib.Data.List.Basic" }, { "name": "le_isGLB_iff", "module": "Mathlib.Order.Bounds.Basic" }, { "name": "mem_lowerBounds", "module": "Mathlib.Order.Bounds.Basic" }, { "name": "le_refl", "module": "Mathlib.Order.Defs.PartialOrder" }, { "name": "Monotone.comp", "module": "Mathlib.Order.Monotone.Defs" } ]
[ { "name": "le_of_ext_le", "content": "lemma le_of_ext_le {Ξ± : Type} [Preorder Ξ±] {v₁ vβ‚‚ : Vector Ξ± n}\n (h : βˆ€ i : Fin n, v₁.1[i] ≀ vβ‚‚.1[i]) : v₁ ≀ vβ‚‚" }, { "name": "mem_dict_iff_mem_keys", "content": "lemma mem_dict_iff_mem_keys {dict : Dict Ξ± Ο‰} : k ∈ dict ↔ k ∈ dict.keys" }, { "name": "eq_of_BalanceProof_le", "content": "lemma eq_of_BalanceProof_le (h : Ο€ ≀ Ο€') (h₁ : k ∈ Ο€) (hβ‚‚ : k ∈ Ο€') :\n ((Ο€ k).get h₁).2 = ((Ο€' k).get hβ‚‚).2" }, { "name": "mem_of_BalanceProof_le", "content": "lemma mem_of_BalanceProof_le (h : Ο€ ≀ Ο€') (h₁ : k ∈ Ο€) : k ∈ Ο€'" }, { "name": "notin_of_BalanceProof_le_notin", "content": "lemma notin_of_BalanceProof_le_notin (h : Ο€ ≀ Ο€') (h₁ : k βˆ‰ Ο€') : k βˆ‰ Ο€" }, { "name": "length_TransactionsInBlock_transfer", "content": "lemma length_TransactionsInBlock_transfer\n {b : { b : Block K₁ Kβ‚‚ C Sigma V // b.isTransferBlock }} :\n βˆ€ (π₁ Ο€β‚‚ : BalanceProof K₁ Kβ‚‚ C Pi V),\n (TransactionsInBlock_transfer π₁ b).length =\n (TransactionsInBlock_transfer Ο€β‚‚ b).length" }, { "name": "length_transactionsInBlock", "content": "lemma length_transactionsInBlock :\n (TransactionsInBlock π₁ b).length = (TransactionsInBlock Ο€β‚‚ b).length" }, { "name": "map_join_unnecessarily_specific", "content": "lemma map_join_unnecessarily_specific\n {Ξ± Ξ² Ξ³ Ξ΄ Pi : Type}\n [LE Ξ΄]\n [LE Pi]\n {l : List Ξ±}\n {P : (Ξ² Γ— Ξ³ Γ— Ξ΄) β†’ Prop}\n {Ο€ Ο€' : Pi}\n {f : Pi β†’ Ξ± β†’ List (Subtype P)}\n {i : β„•}\n (hβ‚€ : (List.length ∘ f Ο€) = (List.length ∘ f Ο€'))\n (h₁ : βˆ€ (a : Ξ±)\n (i : β„•) (h : i < (f Ο€ a).length),\n (f Ο€ a)[i].1.2.2 ≀ ((f Ο€' a)[i]'(by apply congr_fun at hβ‚€; aesop)).1.2.2)\n (h) :\n ((List.map (f Ο€) l).flatten[i]'h).1.2.2 ≀\n ((List.map (f Ο€') l).flatten[i]'(by aesop)).1.2.2" }, { "name": "map_eq_project_triple", "content": "lemma map_eq_project_triple {Ξ² Ξ³ Ξ΄ : Type}\n {s : Ξ²} {r : Ξ³} {v : Ξ΄}\n {i : β„•}\n {P : (Ξ² Γ— Ξ³ Γ— Ξ΄) β†’ Prop}\n {l : List (Subtype P)}\n {hβ‚€}\n {h : i < l.length} : \n l[i]'h = ⟨(s, r, v), hβ‚€βŸ© β†’ (l[i]'h).1.2.2 = v" }, { "name": "receiver_transactionsInBlocks", "content": "lemma receiver_transactionsInBlocks {bs : List (Block K₁ Kβ‚‚ C Sigma V)}\n {π₁ Ο€β‚‚ : BalanceProof K₁ Kβ‚‚ C Pi V} :\n (TransactionsInBlocks π₁ bs).map (Ξ» s ↦ s.1.2.1) =\n (TransactionsInBlocks Ο€β‚‚ bs).map (Ξ» s ↦ s.1.2.1)" }, { "name": "receiver_transactionsInBlock", "content": "lemma receiver_transactionsInBlock :\n (TransactionsInBlock π₁ b).map (Ξ» s ↦ s.1.2.1) =\n (TransactionsInBlock Ο€β‚‚ b).map (Ξ» s ↦ s.1.2.1)" }, { "name": "length_transactionsInBlocks", "content": "lemma length_transactionsInBlocks {bs : List (Block K₁ Kβ‚‚ C Sigma V)}\n {π₁ Ο€β‚‚ : BalanceProof K₁ Kβ‚‚ C Pi V} :\n (TransactionsInBlocks π₁ bs).length = (TransactionsInBlocks Ο€β‚‚ bs).length" }, { "name": "sender_transactionsInBlocks", "content": "lemma sender_transactionsInBlocks {bs : List (Block K₁ Kβ‚‚ C Sigma V)}\n {π₁ Ο€β‚‚ : BalanceProof K₁ Kβ‚‚ C Pi V} :\n (TransactionsInBlocks π₁ bs).map (Ξ» s ↦ s.1.1) =\n (TransactionsInBlocks Ο€β‚‚ bs).map (Ξ» s ↦ s.1.1)" }, { "name": "sender_transactionsInBlock", "content": "lemma sender_transactionsInBlock :\n (TransactionsInBlock π₁ b).map (Ξ» s ↦ s.1.1) =\n (TransactionsInBlock Ο€β‚‚ b).map (Ξ» s ↦ s.1.1)" }, { "name": "V'_sset_V'_of_le", "content": "lemma V'_sset_V'_of_le {b₁ bβ‚‚ : S K₁ Kβ‚‚ V} {T₁ Tβ‚‚ : Ξ€ K₁ Kβ‚‚ V} {k : Kbar K₁ Kβ‚‚}\n (h : b₁ ≀ bβ‚‚) (h₁ : T₁ ≀ Tβ‚‚) : \n V' bβ‚‚ Tβ‚‚ k βŠ† V' b₁ T₁ k" }, { "name": "boundedBelow_sset_boundedBelow_of_le", "content": "lemma boundedBelow_sset_boundedBelow_of_le {b₁ bβ‚‚ : S K₁ Kβ‚‚ V} {T₁ Tβ‚‚ : Ξ€ K₁ Kβ‚‚ V}\n (h : b₁ ≀ bβ‚‚) (h₁ : T₁ ≀ Tβ‚‚) : boundedBelow bβ‚‚ Tβ‚‚ βŠ† boundedBelow b₁ T₁" }, { "name": "f_IsGLB_of_V'", "content": "lemma f_IsGLB_of_V' {b : S K₁ Kβ‚‚ V} {T : Ξ€ K₁ Kβ‚‚ V} {k : Kbar K₁ Kβ‚‚} :\n IsGLB (V' b T k) (f b T k)" }, { "name": "le_cons", "content": "lemma le_cons\n (eq₁ : v₁ = ⟨hd₁ :: tl₁, lenβ‚βŸ©) (eqβ‚‚ : vβ‚‚ = ⟨hdβ‚‚ :: tlβ‚‚, lenβ‚‚βŸ©)\n (h : v₁ ≀ vβ‚‚) : hd₁ ≀ hdβ‚‚ ∧\n @LE.le (Vector Ξ± n) vectorPreorder.toLE ⟨tl₁, by simp at len₁; assumption⟩ ⟨tlβ‚‚, by simp at lenβ‚‚; assumption⟩" }, { "name": "le_cons_aux", "content": "private lemma le_cons_aux \n (eq₁ : v₁ = ⟨hd₁ :: tl₁, lenβ‚βŸ©) (eqβ‚‚ : vβ‚‚ = ⟨hdβ‚‚ :: tlβ‚‚, lenβ‚‚βŸ©)\n (h : v₁ ≀ vβ‚‚) : hd₁ ≀ hdβ‚‚ ∧\n le ⟨tl₁, by simp at len₁; assumption⟩ ⟨tlβ‚‚, by simp at lenβ‚‚; assumption⟩" } ]
[ { "name": "Intmax.length_of_TransactionsInBlocks", "content": "private abbrev length_of_TransactionsInBlocks (bs : List (Block K₁ Kβ‚‚ C Sigma V)) :\n { n : β„• // n = (TransactionsInBlocks (Classical.arbitrary _ : BalanceProof K₁ Kβ‚‚ C Pi V) bs).length } :=\n ⟨(TransactionsInBlocks (Classical.arbitrary _ : BalanceProof K₁ Kβ‚‚ C Pi V) bs).length, rfl⟩" }, { "name": "Intmax.TransactionsInBlocksFixed", "content": "private def TransactionsInBlocksFixed (Ο€ : BalanceProof K₁ Kβ‚‚ C Pi V) (bs : List (Block K₁ Kβ‚‚ C Sigma V)) :\n Vector (Ξ€ K₁ Kβ‚‚ V) (length_of_TransactionsInBlocks (Pi := Pi) bs).1 :=\n ⟨TransactionsInBlocks Ο€ bs, by admit /- proof elided -/\n ⟩" }, { "name": "Intmax.Bal'", "content": "private def Bal' (bs : List (Block K₁ Kβ‚‚ C Sigma V)) : BalanceProof K₁ Kβ‚‚ C Pi V β†’ S K₁ Kβ‚‚ V :=\n fStar (sβ‚€ := S.initial K₁ Kβ‚‚ V) ∘ TransactionsInBlocks (bs := bs)" }, { "name": "Intmax.fStarFixed", "content": "private def fStarFixed {n : β„•}\n (Ts : Vector (Ξ€ K₁ Kβ‚‚ V) n) (sβ‚€ : S K₁ Kβ‚‚ V) : S K₁ Kβ‚‚ V :=\n fStar Ts.1 sβ‚€" }, { "name": "Intmax.BalFixed", "content": "private def BalFixed (bs : List (Block K₁ Kβ‚‚ C Sigma V)) : BalanceProof K₁ Kβ‚‚ C Pi V β†’ S K₁ Kβ‚‚ V :=\n Ξ» Ο€ ↦ fStarFixed (sβ‚€ := S.initial K₁ Kβ‚‚ V) (TransactionsInBlocksFixed Ο€ bs)" }, { "name": "Intmax.BalFixed'", "content": "private def BalFixed' (bs : List (Block K₁ Kβ‚‚ C Sigma V)) : BalanceProof K₁ Kβ‚‚ C Pi V β†’ S K₁ Kβ‚‚ V :=\n fStarFixed (n := (length_of_TransactionsInBlocks (Pi := Pi) bs).1)\n (sβ‚€ := S.initial K₁ Kβ‚‚ V) ∘ TransactionsInBlocksFixed (Pi := Pi) (bs := bs)" } ]
[ { "name": "Intmax.Bal'_eq_Bal", "content": "private lemma Bal'_eq_Bal : Bal' bs Ο€ = Bal Ο€ bs" }, { "name": "Intmax.BalFixed_eq_BalFixed'", "content": "private lemma BalFixed_eq_BalFixed' : BalFixed bs Ο€ = BalFixed' bs Ο€" }, { "name": "Intmax.TransactionsInBlocksFixed_le_of_TransactionsInBlocks", "content": "lemma TransactionsInBlocksFixed_le_of_TransactionsInBlocks\n (h : βˆ€ i : Fin (length_of_TransactionsInBlocks bs).1,\n (TransactionsInBlocks Ο€ bs)[i]'(by blast with Ο€ i) ≀\n (TransactionsInBlocks Ο€' bs)[i]'(by blast with Ο€' i)) :\n TransactionsInBlocksFixed Ο€ bs ≀ TransactionsInBlocksFixed Ο€' bs" }, { "name": "Intmax.senderReceiver_transactionsInBlocks", "content": "lemma senderReceiver_transactionsInBlocks {s r v} {s' r' v'} {eq₁ eqβ‚‚} {i}\n (hβ‚€ : i < (TransactionsInBlocks Ο€ bs).length)\n (h₁ : (TransactionsInBlocks Ο€ bs)[i] = ⟨(s, r, v), eqβ‚βŸ©)\n (hβ‚‚ : (TransactionsInBlocks Ο€' bs)[i]'(by blast with Ο€) = ⟨(s', r', v'), eqβ‚‚βŸ©) :\n s = s' ∧ r = r'" }, { "name": "Intmax.delta_TransactionsInBlock_transfer", "content": "private lemma delta_TransactionsInBlock_transfer\n {b : { b : Block K₁ Kβ‚‚ C Sigma V // b.isTransferBlock }}\n (h : Ο€ ≀ Ο€') : \n βˆ€ i : β„•, (hlen : i < (TransactionsInBlock_transfer Ο€ b).length) β†’\n (TransactionsInBlock_transfer Ο€ b)[i]'hlen =\n (TransactionsInBlock_transfer Ο€' b)[i]'(by rwa [length_TransactionsInBlock_transfer _ Ο€]) ∨\n ((TransactionsInBlock_transfer Ο€ b)[i]'hlen).1.2.2.isNone" }, { "name": "Intmax.v_transactionsInBlocks", "content": "lemma v_transactionsInBlocks {s r v v'} {eq₁ eqβ‚‚} {i}\n (h : Ο€ ≀ Ο€')\n (hβ‚€ : i < (TransactionsInBlocks Ο€ Bstar).length)\n (h₁ : (TransactionsInBlocks Ο€ Bstar)[i] = ⟨(s, r, v), eqβ‚βŸ©)\n (hβ‚‚ : (TransactionsInBlocks Ο€' Bstar)[i]'(by blast with Ο€) = ⟨(s, r, v'), eqβ‚‚βŸ©) :\n v ≀ v'" }, { "name": "Intmax.monotone_TransactionsInBlocksFixed", "content": "lemma monotone_TransactionsInBlocksFixed :\n Monotone Ξ» (Ο€ : BalanceProof K₁ Kβ‚‚ C Pi V) ↦ TransactionsInBlocksFixed Ο€ Bstar" }, { "name": "Intmax.monotone_f", "content": "lemma monotone_f (h₁ : b₁ ≀ bβ‚‚) (hβ‚‚ : T₁ ≀ Tβ‚‚) : f b₁ T₁ k ≀ f bβ‚‚ Tβ‚‚ k" }, { "name": "Intmax.monotone_fStarFixed_aux", "content": "private theorem monotone_fStarFixed_aux (h : v₁ ≀ vβ‚‚) (hβ‚‚ : b₁ ≀ bβ‚‚) :\n v₁.1.foldl f b₁ ≀ vβ‚‚.1.foldl f bβ‚‚" }, { "name": "Intmax.monotone_fStarFixed", "content": "lemma monotone_fStarFixed :\n Monotone Ξ» (Ts : Vector (Ξ€ K₁ Kβ‚‚ V) n) ↦ Intmax.fStarFixed Ts (S.initial K₁ Kβ‚‚ V)" } ]
import FVIntmax.Balance namespace Intmax open Mathlib noncomputable section Lemma4 section HicSuntDracones section variable {Pi C Sigma : Type} {K₁ : Type} [Finite K₁] [LinearOrder K₁] {Kβ‚‚ : Type} [Finite Kβ‚‚] [LinearOrder Kβ‚‚] {V : Type} [AddCommGroup V] [Lattice V] {Ο€ Ο€' : BalanceProof K₁ Kβ‚‚ C Pi V} {bs : List (Block K₁ Kβ‚‚ C Sigma V)} section HelperFunctionsToAppeaseLean open Mathlib private abbrev length_of_TransactionsInBlocks (bs : List (Block K₁ Kβ‚‚ C Sigma V)) : { n : β„• // n = (TransactionsInBlocks (Classical.arbitrary _ : BalanceProof K₁ Kβ‚‚ C Pi V) bs).length } := ⟨(TransactionsInBlocks (Classical.arbitrary _ : BalanceProof K₁ Kβ‚‚ C Pi V) bs).length, rfl⟩ open Lean.Elab.Tactic in private def TransactionsInBlocksFixed (Ο€ : BalanceProof K₁ Kβ‚‚ C Pi V) (bs : List (Block K₁ Kβ‚‚ C Sigma V)) : Vector (Ξ€ K₁ Kβ‚‚ V) (length_of_TransactionsInBlocks (Pi := Pi) bs).1 := ⟨TransactionsInBlocks Ο€ bs, by admit /- proof elided -/ ⟩ section variable {Pi C Sigma : Type} {K₁ : Type} [Finite K₁] [LinearOrder K₁] {Kβ‚‚ : Type} [Finite Kβ‚‚] [LinearOrder Kβ‚‚] {V : Type} [Lattice V] [AddCommGroup V] [CovariantClass V V (Β· + Β·) (Β· ≀ Β·)] [CovariantClass V V (Function.swap (Β· + Β·)) (Β· ≀ Β·)] {Ο€ Ο€' : BalanceProof K₁ Kβ‚‚ C Pi V} {bs : List (Block K₁ Kβ‚‚ C Sigma V)} private def Bal' (bs : List (Block K₁ Kβ‚‚ C Sigma V)) : BalanceProof K₁ Kβ‚‚ C Pi V β†’ S K₁ Kβ‚‚ V := fStar (sβ‚€ := S.initial K₁ Kβ‚‚ V) ∘ TransactionsInBlocks (bs := bs) private def fStarFixed {n : β„•} (Ts : Vector (Ξ€ K₁ Kβ‚‚ V) n) (sβ‚€ : S K₁ Kβ‚‚ V) : S K₁ Kβ‚‚ V := fStar Ts.1 sβ‚€ private def BalFixed (bs : List (Block K₁ Kβ‚‚ C Sigma V)) : BalanceProof K₁ Kβ‚‚ C Pi V β†’ S K₁ Kβ‚‚ V := Ξ» Ο€ ↦ fStarFixed (sβ‚€ := S.initial K₁ Kβ‚‚ V) (TransactionsInBlocksFixed Ο€ bs) private def BalFixed' (bs : List (Block K₁ Kβ‚‚ C Sigma V)) : BalanceProof K₁ Kβ‚‚ C Pi V β†’ S K₁ Kβ‚‚ V := fStarFixed (n := (length_of_TransactionsInBlocks (Pi := Pi) bs).1) (sβ‚€ := S.initial K₁ Kβ‚‚ V) ∘ TransactionsInBlocksFixed (Pi := Pi) (bs := bs) end end HelperFunctionsToAppeaseLean end section variable {Pi C Sigma : Type} {K₁ : Type} [Finite K₁] [LinearOrder K₁] {Kβ‚‚ : Type} [Finite Kβ‚‚] [LinearOrder Kβ‚‚] {V : Type} [Lattice V] [AddCommGroup V] {Ο€ Ο€' : BalanceProof K₁ Kβ‚‚ C Pi V} {bs Bstar : List (Block K₁ Kβ‚‚ C Sigma V)} end end HicSuntDracones section variable {n : β„•} {Pi C Sigma : Type} {K₁ : Type} [Finite K₁] {Kβ‚‚ : Type} [Finite Kβ‚‚] {V : Type} [Lattice V] [AddCommGroup V] [CovariantClass V V (Β· + Β·) (Β· ≀ Β·)] [CovariantClass V V (Function.swap (Β· + Β·)) (Β· ≀ Β·)] {Ο€ Ο€' : BalanceProof K₁ Kβ‚‚ C Pi V} {bs Bstar : List (Block K₁ Kβ‚‚ C Sigma V)} section Monotone variable {b₁ bβ‚‚ : S K₁ Kβ‚‚ V} {T₁ Tβ‚‚ : Ξ€ K₁ Kβ‚‚ V} {k : Kbar K₁ Kβ‚‚} {v₁ vβ‚‚ : Vector (Ξ€ K₁ Kβ‚‚ V) n} end Monotone end variable {n : β„•} {Pi C Sigma : Type} {K₁ : Type} [Finite K₁] [LinearOrder K₁] {Kβ‚‚ : Type} [Finite Kβ‚‚] [LinearOrder Kβ‚‚] {V : Type} [Lattice V] [AddCommGroup V] [CovariantClass V V (Β· + Β·) (Β· ≀ Β·)] [CovariantClass V V (Function.swap (Β· + Β·)) (Β· ≀ Β·)] {Ο€ Ο€' : BalanceProof K₁ Kβ‚‚ C Pi V} {bs Bstar : List (Block K₁ Kβ‚‚ C Sigma V)}
lemma lemma4 (h : π₁ ≀ Ο€β‚‚) : Bal π₁ bs ≀ Bal Ο€β‚‚ bs :=
:= by simp only [←Bal'_eq_Bal] suffices BalFixed bs π₁ ≀ BalFixed bs Ο€β‚‚ by aesop rw [BalFixed_eq_BalFixed', BalFixed_eq_BalFixed'] exact Monotone.comp monotone_fStarFixed monotone_TransactionsInBlocksFixed h
11
117
false
Applied verif.
481
add_aux1
theorem add_aux1 (x : UInt128) : 4 * (x.cast : F).valMinAbs.natAbs < PRIME
wadray_verification
WadrayVerification/WadraySigned.lean
[ "import WadrayVerification.Aux", "import WadrayVerification.Wadray" ]
[ { "name": "Sierra.UInt128", "module": "Aegis.Types" }, { "name": "Unit", "module": "Init.Prelude" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Bool.toSierraBool", "module": "Aegis.Aux.Bool" }, { "name": "Bool.xor", "module": "Init.Data.Bool" }, { "name": "SierraBool.toBool", "module": "Aegis.Aux.Bool" }, { "name": "Sierra.F", "module": "Aegis.Types" }, { "name": "Sierra.PRIME", "module": "Aegis.Types" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Option", "module": "Init.Prelude" }, { "name": "Sierra.U128_MOD", "module": "Aegis.Types" }, { "name": "Sierra.aegis_prove", "module": "Aegis.Commands" }, { "name": "Sum", "module": "Init.Core" }, { "name": "Sum.inl", "module": "Init.Core" }, { "name": "ZMod", "module": "Mathlib.Data.ZMod.Defs" }, { "name": "NeZero", "module": "Init.Data.NeZero" }, { "name": "Inhabited", "module": "Init.Prelude" } ]
[ { "name": "RAY_SCALE", "content": "def RAY_SCALE : β„• := 1000000000000000000000000000" }, { "name": "div", "content": "protected def div : SignedRay :=\n⟨Ray.div (w₁.1 : Ray) (wβ‚‚.1 : Ray), Bool.toSierraBool (Bool.xor (SierraBool.toBool w₁.2) (SierraBool.toBool wβ‚‚.2))⟩" }, { "name": "SignedRay", "content": "def SignedRay := UInt128 Γ— (Unit βŠ• Unit)" }, { "name": "div", "content": "protected def div : Ray := (r.toZMod.val * RAY_SCALE / r'.toZMod.val : UInt128)" }, { "name": "Ray", "content": "def Ray : Type := UInt128" }, { "name": "toRat", "content": "protected def toRat : β„š := w.toZMod.val / WAD_SCALE" }, { "name": "WAD_SCALE", "content": "def WAD_SCALE : β„• := 1000000000000000000" }, { "name": "toRat", "content": "def toRat : β„š := if SierraBool.toBool w.2 then -(Ray.toRat w.1) else Ray.toRat w.1" }, { "name": "toRat", "content": "protected def toRat : β„š := r.toZMod.val / RAY_SCALE" }, { "name": "div", "content": "protected def div : Wad := (w.toZMod.val * WAD_SCALE / w'.toZMod.val : UInt128)" }, { "name": "Wad", "content": "def Wad : Type := UInt128" }, { "name": "mul", "content": "protected def mul : Wad := (w.toZMod.val * w'.toZMod.val / WAD_SCALE : UInt128)" }, { "name": "toZMod", "content": "protected def toZMod : UInt128 := w" }, { "name": "toRat", "content": "def toRat : β„š := if w.2 then -(Wad.toRat w.1) else Wad.toRat w.1" }, { "name": "mul", "content": "protected def mul : Ray := (r.toZMod.val * r'.toZMod.val / RAY_SCALE : UInt128)" }, { "name": "add", "content": "protected def add : Ray := r.toZMod + r'.toZMod" }, { "name": "toZMod", "content": "protected def toZMod : UInt128 := r" }, { "name": "DIFF", "content": "def DIFF : β„• := 1000000000" }, { "name": "div", "content": "protected def div : SignedWad :=\n⟨Wad.div (w₁.1 : Wad) (wβ‚‚.1 : Wad), Bool.toSierraBool (Bool.xor (SierraBool.toBool w₁.2) (SierraBool.toBool wβ‚‚.2))⟩" }, { "name": "SignedWad", "content": "def SignedWad := UInt128 Γ— (Unit βŠ• Unit)" }, { "name": "mul", "content": "protected def mul : SignedWad :=\n⟨Wad.mul (w₁.1 : Wad) (wβ‚‚.1 : Wad), Bool.toSierraBool (Bool.xor (SierraBool.toBool w₁.2) (SierraBool.toBool wβ‚‚.2))⟩" }, { "name": "sub", "content": "protected def sub : Ray := r.toZMod - r'.toZMod" }, { "name": "mul", "content": "protected def mul : SignedRay :=\n⟨Ray.mul w₁.1 wβ‚‚.1, Bool.toSierraBool (Bool.xor (SierraBool.toBool w₁.2) (SierraBool.toBool wβ‚‚.2))⟩" } ]
[ { "name": "le_of_lt", "module": "Mathlib.Order.Defs.PartialOrder" }, { "name": "Int.cast_abs", "module": "Mathlib.Algebra.Order.Ring.Cast" }, { "name": "Int.cast_add", "module": "Mathlib.Data.Int.Cast.Basic" }, { "name": "Int.cast_natAbs", "module": "Mathlib.Algebra.Order.Ring.Cast" }, { "name": "Int.cast_neg", "module": "Mathlib.Data.Int.Cast.Basic" }, { "name": "Int.natAbs_neg", "module": "Init.Data.Int.Order" }, { "name": "Nat.abs_cast", "module": "Mathlib.Data.Nat.Cast.Order.Ring" }, { "name": "Nat.cast_add", "module": "Mathlib.Data.Nat.Cast.Defs" }, { "name": "Nat.cast_le", "module": "Mathlib.Data.Nat.Cast.Order.Basic" }, { "name": "Nat.cast_lt", "module": "Mathlib.Data.Nat.Cast.Order.Basic" }, { "name": "Nat.mul_lt_mul_of_pos_left", "module": "Init.Data.Nat.Basic" }, { "name": "SierraBool_toBool_inl", "module": "Aegis.Aux.Bool" }, { "name": "SierraBool_toBool_inr", "module": "Aegis.Aux.Bool" }, { "name": "Sum.getLeft?_inl", "module": "Init.Data.Sum.Basic" }, { "name": "Sum.getLeft?_inr", "module": "Init.Data.Sum.Basic" }, { "name": "Sum.isLeft_inl", "module": "Init.Data.Sum.Basic" }, { "name": "Sum.isLeft_inr", "module": "Init.Data.Sum.Basic" }, { "name": "Sum.isRight_inl", "module": "Init.Data.Sum.Basic" }, { "name": "Sum.isRight_inr", "module": "Init.Data.Sum.Basic" }, { "name": "ZMod.intCast_cast", "module": "Mathlib.Data.ZMod.Basic" }, { "name": "ZMod.natCast_val", "module": "Mathlib.Data.ZMod.Basic" }, { "name": "ZMod.valMinAbs_neg_of_ne_half", "module": "Mathlib.Data.ZMod.ValMinAbs" }, { "name": "ZMod.val_lt", "module": "Mathlib.Data.ZMod.Basic" }, { "name": "abs_div", "module": "Mathlib.Algebra.Order.Field.Basic" }, { "name": "abs_neg", "module": "Mathlib.Algebra.Order.Group.Unbundled.Abs" }, { "name": "add_div", "module": "Mathlib.Algebra.Field.Basic" }, { "name": "and_false", "module": "Init.SimpLemmas" }, { "name": "and_true", "module": "Init.SimpLemmas" }, { "name": "div_lt_div_of_pos_right", "module": "Mathlib.Algebra.Order.GroupWithZero.Unbundled.Basic" }, { "name": "false_and", "module": "Init.SimpLemmas" }, { "name": "false_or", "module": "Init.SimpLemmas" }, { "name": "ite_false", "module": "Init.SimpLemmas" }, { "name": "ite_prop_iff_or", "module": "Mathlib.Logic.Basic" }, { "name": "ite_true", "module": "Init.SimpLemmas" }, { "name": "lt_of_lt_of_le", "module": "Mathlib.Order.Defs.PartialOrder" }, { "name": "lt_trans", "module": "Mathlib.Order.Defs.PartialOrder" }, { "name": "ne_of_lt", "module": "Mathlib.Order.Defs.PartialOrder" }, { "name": "neg_add", "module": "Mathlib.Algebra.Group.Basic" }, { "name": "neg_div", "module": "Mathlib.Algebra.Ring.Basic" }, { "name": "neg_neg", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "not_lt", "module": "Mathlib.Order.Defs.LinearOrder" }, { "name": "or_false", "module": "Init.SimpLemmas" }, { "name": "sub_eq_add_neg", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "sub_neg_eq_add", "module": "Mathlib.Algebra.Group.Basic" }, { "name": "true_and", "module": "Init.SimpLemmas" }, { "name": "two_pos", "module": "Mathlib.Algebra.Order.Monoid.NatCast" } ]
[ { "name": "mul_def", "content": "protected theorem mul_def :\n r * r' = (r.toZMod.val * r'.toZMod.val / RAY_SCALE : UInt128)" }, { "name": "mul_def", "content": "theorem mul_def :\n w₁ * wβ‚‚ = ⟨Ray.mul w₁.1 wβ‚‚.1, Bool.toSierraBool (Bool.xor (SierraBool.toBool w₁.2) (SierraBool.toBool wβ‚‚.2))⟩" }, { "name": "ZMod.valMinAbs_add_of_four_lt", "content": "theorem ZMod.valMinAbs_add_of_four_lt [NeZero m] {a b : ZMod m}\n (ha : 4 * a.valMinAbs.natAbs < m) (hb : 4 * b.valMinAbs.natAbs < m) :\n (a + b).valMinAbs = a.valMinAbs + b.valMinAbs" }, { "name": "ZMod.valMinAbs_add_of_two_lt", "content": "theorem ZMod.valMinAbs_add_of_two_lt [NeZero m] {a b : ZMod m}\n (h : 2 * (a.valMinAbs.natAbs + b.valMinAbs.natAbs) < m) :\n (a + b).valMinAbs = a.valMinAbs + b.valMinAbs" }, { "name": "ZMod.valMinAbs_cast_of_lt_half", "content": "theorem ZMod.valMinAbs_cast_of_lt_half [NeZero m] (hm : 2 * m < n) (a : ZMod m) :\n (a.cast : ZMod n).valMinAbs = a.val" }, { "name": "mul_def", "content": "protected theorem mul_def :\n w * w' = (w.toZMod.val * w'.toZMod.val / WAD_SCALE : UInt128)" }, { "name": "div_def", "content": "protected theorem div_def :\n r / r' = (r.toZMod.val * RAY_SCALE / r'.toZMod.val : UInt128)" }, { "name": "mul_def", "content": "theorem mul_def :\n w₁ * wβ‚‚ = ⟨Wad.mul (w₁.1 : Wad) (wβ‚‚.1 : Wad), Bool.toSierraBool (Bool.xor (SierraBool.toBool w₁.2) (SierraBool.toBool wβ‚‚.2))⟩" }, { "name": "ZMod.val_cast_lt", "content": "theorem ZMod.val_cast_lt [NeZero m] (n : β„•) [NeZero n] (a : ZMod m) : (a.cast : ZMod n).val < m" }, { "name": "div_def", "content": "protected theorem div_def :\n w / w' = (w.toZMod.val * WAD_SCALE / w'.toZMod.val : UInt128)" }, { "name": "div_def", "content": "theorem div_def :\n w₁ / wβ‚‚ = ⟨Ray.div (w₁.1 : Ray) (wβ‚‚.1 : Ray), Bool.toSierraBool (Bool.xor (SierraBool.toBool w₁.2) (SierraBool.toBool wβ‚‚.2))⟩" }, { "name": "Option.get!_none", "content": "@[simp]\ntheorem Option.get!_none [Inhabited Ξ±] : (.none : Option Ξ±).get! = default" }, { "name": "Option.get!_some", "content": "@[simp]\ntheorem Option.get!_some [Inhabited Ξ±] (a : Ξ±) : (Option.some a).get! = a" }, { "name": "div_def", "content": "theorem div_def :\n w₁ / wβ‚‚ = ⟨Wad.div (w₁.1 : Wad) (wβ‚‚.1 : Wad), Bool.toSierraBool (Bool.xor (SierraBool.toBool w₁.2) (SierraBool.toBool wβ‚‚.2))⟩" } ]
[]
[ { "name": "two_U128_MOD_lt_PRIME", "content": "theorem two_U128_MOD_lt_PRIME : 2 * U128_MOD < PRIME" }, { "name": "four_U128_MOD_lt_PRIME", "content": "theorem four_U128_MOD_lt_PRIME : 4 * U128_MOD < PRIME" }, { "name": "four_U128_MOD_le_PRIME", "content": "theorem four_U128_MOD_le_PRIME : 4 * U128_MOD ≀ PRIME" } ]
import WadrayVerification.Aux import WadrayVerification.Wadray open Sierra aegis_spec "wadray::wadray_signed::SignedWadZeroable::zero" := fun _ (ρ : SignedWad) => ρ = 0 aegis_prove "wadray::wadray_signed::SignedWadZeroable::zero" := fun _ (ρ : SignedWad) => by rintro rfl rfl aegis_spec "wadray::wadray_signed::SignedRayZeroable::zero" := fun _ (ρ : SignedRay) => ρ = 0 aegis_prove "wadray::wadray_signed::SignedRayZeroable::zero" := fun _ (ρ : SignedRay) => by rintro rfl rfl aegis_spec "wadray::wadray_signed::SignedWadOneable::one" := fun _ (ρ : SignedWad) => ρ = 1 aegis_prove "wadray::wadray_signed::SignedWadOneable::one" := fun _ (ρ : SignedWad) => by rintro rfl rfl aegis_spec "wadray::wadray_signed::SignedRayOneable::one" := fun _ (ρ : SignedRay) => ρ = 1 aegis_prove "wadray::wadray_signed::SignedRayOneable::one" := fun _ (ρ : SignedRay) => by rintro rfl rfl aegis_spec "wadray::wadray_signed::SignedWadPartialEq::eq" := fun _ (a b : SignedWad) ρ => ρ = Bool.toSierraBool (a.toRat = b.toRat) aegis_prove "wadray::wadray_signed::SignedWadPartialEq::eq" := fun _ (a b : SignedWad) ρ => by unfold Β«spec_wadray::wadray_signed::SignedWadPartialEq::eqΒ» rename_i x intro h_auto aesop (add safe forward [SignedWad.val_eq_of_toRat_eq, SignedWad.val_eq_zero_of_toRat_neg, SignedWad.val_eq_zero_of_toRat_neg']) aegis_spec "wadray::wadray_signed::SignedRayPartialEq::eq" := fun _ (a b : SignedRay) ρ => ρ = Bool.toSierraBool (a.toRat = b.toRat) aegis_prove "wadray::wadray_signed::SignedRayPartialEq::eq" := fun _ (a b : SignedRay) ρ => by unfold Β«spec_wadray::wadray_signed::SignedRayPartialEq::eqΒ» rename_i x intro h_auto aesop (add safe forward [SignedRay.val_eq_of_toRat_eq, SignedRay.val_eq_zero_of_toRat_neg, SignedRay.val_eq_zero_of_toRat_neg']) aegis_spec "wadray::wadray_signed::SignedWadPartialEq::ne" := fun _ (a b : SignedWad) ρ => ρ = Bool.toSierraBool (a.toRat β‰  b.toRat) aegis_prove "wadray::wadray_signed::SignedWadPartialEq::ne" := fun _ (a b : SignedWad) ρ => by unfold Β«spec_wadray::wadray_signed::SignedWadPartialEq::neΒ» rintro rfl simp aegis_spec "wadray::wadray_signed::SignedRayPartialEq::ne" := fun _ (a b : SignedRay) ρ => ρ = Bool.toSierraBool (a.toRat β‰  b.toRat) aegis_prove "wadray::wadray_signed::SignedRayPartialEq::ne" := fun _ (a b : SignedRay) ρ => by unfold Β«spec_wadray::wadray_signed::SignedRayPartialEq::neΒ» rintro rfl simp aegis_spec "wadray::wadray_signed::SignedWadSigned::is_positive" := fun _ _ (a : SignedWad) _ ρ => ρ = Bool.toSierraBool (a.toRat > 0) aegis_prove "wadray::wadray_signed::SignedWadSigned::is_positive" := fun _ _ (a : SignedWad) _ ρ => by unfold Β«spec_wadray::wadray_signed::SignedWadSigned::is_positiveΒ» rintro ⟨w,s,rfl,(⟨h,rfl⟩|⟨h,rfl⟩)⟩ Β· aesop (add simp [SignedWad.toRat, Wad.toRat]) Β· rcases s with (s|s) Β· simp_all only [Int.ofNat_eq_coe, CharP.cast_eq_zero, Int.cast_zero, ZMod.val_zero, SierraBool_toBool_inl, Bool.not_false, Bool.toSierraBool_true, SignedWad.toRat, Wad.toRat, Wad.toZMod, ZMod.natCast_val, ite_false, gt_iff_lt, Bool.toSierraBool_decide_inr'] rw [lt_div_iff (by norm_num [Wad.WAD_SCALE]), zero_mul] apply Ne.lt_of_le _ (ZMod.cast_rat_nonneg _) intro he rw [eq_comm, ZMod.cast_rat_eq_zero_iff] at he; subst he simp at h Β· simp [SignedWad.toRat, Wad.toRat] rw [le_div_iff (by norm_num [Wad.WAD_SCALE]), zero_mul] apply ZMod.cast_rat_nonneg aegis_spec "wadray::wadray_signed::SignedRaySigned::is_positive" := fun _ _ (a : SignedRay) _ ρ => ρ = Bool.toSierraBool (a.toRat > 0) aegis_prove "wadray::wadray_signed::SignedRaySigned::is_positive" := fun _ _ (a : SignedWad) _ ρ => by unfold Β«spec_wadray::wadray_signed::SignedRaySigned::is_positiveΒ» rintro ⟨w,s,rfl,(⟨h,rfl⟩|⟨h,rfl⟩)⟩ Β· aesop (add simp [SignedRay.toRat, Ray.toRat]) Β· rcases s with (s|s) Β· simp_all only [Int.ofNat_eq_coe, CharP.cast_eq_zero, Int.cast_zero, ZMod.val_zero, SierraBool_toBool_inl, Bool.not_false, Bool.toSierraBool_true, SignedRay.toRat, Ray.toRat, Ray.toZMod, ZMod.natCast_val, ite_false, gt_iff_lt, Bool.toSierraBool_decide_inr'] rw [lt_div_iff (by norm_num [Ray.RAY_SCALE]), zero_mul] apply Ne.lt_of_le _ (ZMod.cast_rat_nonneg _) intro he rw [eq_comm, ZMod.cast_rat_eq_zero_iff] at he; subst he simp at h Β· simp [SignedRay.toRat, Ray.toRat] rw [le_div_iff (by norm_num [Ray.RAY_SCALE]), zero_mul] apply ZMod.cast_rat_nonneg aegis_spec "wadray::wadray_signed::SignedWadSigned::is_negative" := fun _ _ (a : SignedWad) _ ρ => ρ = Bool.toSierraBool (a.toRat < 0) aegis_prove "wadray::wadray_signed::SignedWadSigned::is_negative" := fun _ _ (a : SignedWad) _ ρ => by unfold Β«spec_wadray::wadray_signed::SignedWadSigned::is_negativeΒ» rintro ⟨w,s,rfl,(⟨h,rfl⟩|⟨h,rfl⟩)⟩ Β· aesop (add simp [SignedWad.toRat, Wad.toRat]) Β· have : 0 < (Wad.WAD_SCALE : β„š) := by norm_num [Wad.WAD_SCALE] rcases s with (s|s) <;> aesop (add simp [SignedWad.toRat, Wad.toRat, lt_div_iff, le_div_iff, Wad.toZMod, ZMod.cast_rat_nonneg], safe apply [Ne.lt_of_le]) aegis_spec "wadray::wadray_signed::SignedRaySigned::is_negative" := fun _ _ (a : SignedRay) _ ρ => ρ = Bool.toSierraBool (a.toRat < 0) aegis_prove "wadray::wadray_signed::SignedRaySigned::is_negative" := fun _ _ (a : SignedRay) _ ρ => by unfold Β«spec_wadray::wadray_signed::SignedRaySigned::is_negativeΒ» rintro ⟨w,s,rfl,(⟨h,rfl⟩|⟨h,rfl⟩)⟩ Β· aesop (add simp [SignedRay.toRat, Ray.toRat]) Β· have : 0 < (Ray.RAY_SCALE : β„š) := by norm_num [Ray.RAY_SCALE] rcases s with (s|s) <;> aesop (add simp [SignedRay.toRat, Ray.toRat, lt_div_iff, le_div_iff, Ray.toZMod, ZMod.cast_rat_nonneg], safe apply [Ne.lt_of_le]) aegis_spec "wadray::wadray_signed::SignedWadZeroable::is_zero" := fun _ (a : SignedWad) ρ => ρ = Bool.toSierraBool (a.toRat = 0) aegis_prove "wadray::wadray_signed::SignedWadZeroable::is_zero" := fun _ (a : SignedWad) ρ => by unfold Β«spec_wadray::wadray_signed::SignedWadZeroable::is_zeroΒ» have : Β¬ (Wad.WAD_SCALE = 0) := by norm_num [Wad.WAD_SCALE] aesop (add simp [SignedWad.toRat, Wad.toRat]) aegis_spec "wadray::wadray_signed::SignedRayZeroable::is_zero" := fun _ (a : SignedRay) ρ => ρ = Bool.toSierraBool (a.toRat = 0) aegis_prove "wadray::wadray_signed::SignedRayZeroable::is_zero" := fun _ (a : SignedRay) ρ => by unfold Β«spec_wadray::wadray_signed::SignedRayZeroable::is_zeroΒ» have : Β¬ (Ray.RAY_SCALE = 0) := by norm_num [Ray.RAY_SCALE] aesop (add simp [SignedRay.toRat, Ray.toRat]) aegis_spec "wadray::wadray_signed::SignedWadZeroable::is_non_zero" := fun _ (a : SignedWad) ρ => ρ = Bool.toSierraBool (a.toRat β‰  0) aegis_prove "wadray::wadray_signed::SignedWadZeroable::is_non_zero" := fun _ (a : SignedWad) ρ => by unfold Β«spec_wadray::wadray_signed::SignedWadZeroable::is_non_zeroΒ» aesop (add simp [SignedWad.toRat, Wad.toRat, Wad.toZMod]) aegis_spec "wadray::wadray_signed::SignedRayZeroable::is_non_zero" := fun _ (a : SignedRay) ρ => ρ = Bool.toSierraBool (a.toRat β‰  0) aegis_prove "wadray::wadray_signed::SignedRayZeroable::is_non_zero" := fun _ (a : SignedRay) ρ => by unfold Β«spec_wadray::wadray_signed::SignedRayZeroable::is_non_zeroΒ» aesop (add simp [SignedRay.toRat, Ray.toRat, Ray.toZMod]) aegis_spec "wadray::wadray_signed::SignedWadOneable::is_one" := fun _ (a : SignedWad) ρ => ρ = Bool.toSierraBool (a.toRat = 1) aegis_prove "wadray::wadray_signed::SignedWadOneable::is_one" := fun _ (a : SignedWad) ρ => by unfold Β«spec_wadray::wadray_signed::SignedWadOneable::is_oneΒ» rintro ⟨w,s,h⟩ have : 1000000000000000000 = ((1000000000000000000 : Sierra.UInt128).cast : β„š) := by rw [ZMod.cast_eq_val]; aesop have : (1000000000000000000 : β„š) β‰  0 := by norm_num have : Β¬ (-(w.cast : β„š) = 1000000000000000000) := by apply ne_of_lt (lt_of_le_of_lt (b := 0) _ (by norm_num)) simp only [Left.neg_nonpos_iff, ZMod.cast_rat_nonneg] aesop (add simp [SignedWad.toRat, Wad.toRat, Wad.toZMod, Wad.WAD_SCALE, div_eq_iff, neg_div'], safe forward [ZMod.cast_rat_injective]) aegis_spec "wadray::wadray_signed::SignedRayOneable::is_one" := fun _ (a : SignedRay) ρ => ρ = Bool.toSierraBool (a.toRat = 1) aegis_prove "wadray::wadray_signed::SignedRayOneable::is_one" := fun _ (a : SignedWad) ρ => by unfold Β«spec_wadray::wadray_signed::SignedRayOneable::is_oneΒ» rintro ⟨w,s,h⟩ have : 1000000000000000000000000000 = ((1000000000000000000000000000 : Sierra.UInt128).cast : β„š) := by rw [ZMod.cast_eq_val]; aesop have : (1000000000000000000000000000 : β„š) β‰  0 := by norm_num have : Β¬ (-(w.cast : β„š) = 1000000000000000000000000000) := by apply ne_of_lt (lt_of_le_of_lt (b := 0) _ (by norm_num)) simp only [Left.neg_nonpos_iff, ZMod.cast_rat_nonneg] aesop (add simp [SignedRay.toRat, Ray.toRat, Ray.toZMod, Ray.RAY_SCALE, div_eq_iff, neg_div'], safe forward [ZMod.cast_rat_injective]) aegis_spec "wadray::wadray_signed::SignedWadOneable::is_non_one" := fun _ (a : SignedWad) ρ => ρ = Bool.toSierraBool (a.toRat β‰  1) aegis_prove "wadray::wadray_signed::SignedWadOneable::is_non_one" := fun _ (a : SignedWad) ρ => by unfold Β«spec_wadray::wadray_signed::SignedWadOneable::is_non_oneΒ» rintro ⟨w,s,rfl,h⟩ have : Β¬ (-(w.cast : β„š) = 1000000000000000000) := by apply ne_of_lt (lt_of_le_of_lt (b := 0) _ (by norm_num)) simp only [Left.neg_nonpos_iff, ZMod.cast_rat_nonneg] have : Β¬w = 1000000000000000000 β†’ Β¬(w.cast : β„š) = 1000000000000000000 := by have hn : 1000000000000000000 = ((1000000000000000000 : Sierra.UInt128).cast : β„š) := by rw [ZMod.cast_eq_val]; aesop intros he hee; rw [hn] at hee; have := ZMod.cast_rat_injective hee; contradiction aesop (add simp [SignedWad.toRat, Wad.toRat, Wad.toZMod, Wad.WAD_SCALE, div_eq_iff, neg_div'], safe forward [ZMod.cast_rat_injective]) aegis_spec "wadray::wadray_signed::SignedRayOneable::is_non_one" := fun _ (a : SignedRay) ρ => ρ = Bool.toSierraBool (a.toRat β‰  1) aegis_prove "wadray::wadray_signed::SignedRayOneable::is_non_one" := fun _ (a : SignedRay) ρ => by unfold Β«spec_wadray::wadray_signed::SignedRayOneable::is_non_oneΒ» rintro ⟨w,s,rfl,h⟩ have : Β¬ (-(w.cast : β„š) = 1000000000000000000000000000) := by apply ne_of_lt (lt_of_le_of_lt (b := 0) _ (by norm_num)) simp only [Left.neg_nonpos_iff, ZMod.cast_rat_nonneg] have : Β¬w = 1000000000000000000000000000 β†’ Β¬(w.cast : β„š) = 1000000000000000000000000000 := by have hn : 1000000000000000000000000000 = ((1000000000000000000000000000 : Sierra.UInt128).cast : β„š) := by rw [ZMod.cast_eq_val]; aesop intros he hee; rw [hn] at hee; have := ZMod.cast_rat_injective hee; contradiction aesop (add simp [SignedRay.toRat, Ray.toRat, Ray.toZMod, Ray.RAY_SCALE, div_eq_iff, neg_div'], safe forward [ZMod.cast_rat_injective]) aegis_spec "wadray::wadray_signed::BoundedSignedWad::max" := fun _ ρ => ρ = ((U128_MOD - 1 : UInt128), .inl ()) aegis_prove "wadray::wadray_signed::BoundedSignedWad::max" := fun _ ρ => by rintro rfl rfl aegis_spec "wadray::wadray_signed::BoundedSignedRay::max" := fun _ ρ => ρ = ((U128_MOD - 1 : UInt128), .inl ()) aegis_prove "wadray::wadray_signed::BoundedSignedRay::max" := fun _ ρ => by rintro rfl rfl aegis_spec "wadray::wadray_signed::BoundedSignedWad::min" := fun _ ρ => ρ = ((U128_MOD - 1 : UInt128), .inr ()) aegis_prove "wadray::wadray_signed::BoundedSignedWad::min" := fun _ ρ => by rintro rfl rfl aegis_spec "wadray::wadray_signed::BoundedSignedRay::min" := fun _ ρ => ρ = ((U128_MOD - 1 : UInt128), .inr ()) aegis_prove "wadray::wadray_signed::BoundedSignedRay::min" := fun _ ρ => by rintro rfl rfl aegis_spec "wadray::wadray_signed::SignedWadPartialOrd::gt" := fun _ _ (a b : SignedWad) _ ρ => ρ = Bool.toSierraBool (b.toRat < a.toRat) aegis_prove "wadray::wadray_signed::SignedWadPartialOrd::gt" := fun _ _ (a b : SignedWad) _ ρ => by unfold Β«spec_wadray::wadray_signed::SignedWadPartialOrd::gtΒ» have : 0 < (Wad.WAD_SCALE : β„š) := by norm_num [Wad.WAD_SCALE] rintro ⟨w₁,s₁,wβ‚‚,sβ‚‚,u₁,uβ‚‚,u₃,uβ‚„,uβ‚…,u₆,rfl,rfl,(h|h)⟩ <;> (cases u₁; cases uβ‚‚; cases u₃; cases uβ‚„; cases uβ‚…; cases u₆) Β· rcases h with ⟨rfl,(h|h)⟩ Β· rcases h with ⟨rfl,(⟨hne,h⟩|⟨rfl,rfl,rfl⟩)⟩ Β· rcases h with (⟨hle,rfl⟩|⟨hlt,rfl⟩) Β· simp [SignedWad.toRat_le_toRat_of_val_le_val_inl hle] Β· simp only [SierraBool_toBool_inr, SierraBool_toBool_inl, Bool.xor_false, Bool.toSierraBool_true, Bool.toSierraBool_decide_inr'] apply lt_of_le_of_ne Β· apply SignedWad.toRat_le_toRat_of_val_le_val_inl simp [Wad.toZMod, le_of_lt hlt] Β· intro he exact hne (SignedWad.val_eq_of_toRat_eq _ _ he).symm Β· simp only [lt_self_iff_false, decide_False, Bool.toSierraBool_false] Β· rcases h with ⟨rfl,(⟨hne,rfl,rfl⟩|h)⟩ Β· simp only [SierraBool_toBool_inl, Bool.not_false, Bool.toSierraBool_true, Bool.toSierraBool_decide_inr'] apply lt_of_le_of_ne Β· simp [SignedWad.toRat_inr_le_toRat_inl] Β· intro he exact hne (SignedWad.val_eq_of_toRat_eq _ _ he).symm Β· rcases h with ⟨rfl,(⟨h,rfl,rfl⟩|⟨h,rfl,rfl⟩)⟩ Β· simp only [Nat.cast_pos, Bool.toSierraBool_decide_inl', SierraBool_toBool_inl, Bool.not_false, Bool.toSierraBool_true, Bool.toSierraBool_decide_inr'] at * apply lt_of_lt_of_le (b := 0) Β· apply lt_of_le_of_ne Β· simp [SignedWad.toRat, Wad.toRat_nonneg] Β· simpa [SignedWad.toRat] Β· simp [SignedWad.toRat, Wad.toRat_nonneg] Β· simp only [Nat.cast_pos, SignedWad.toRat, SierraBool_toBool_inl, ite_false, Bool.toSierraBool_decide_inr', SierraBool_toBool_inr, ite_true, neg_lt_self_iff, Bool.toSierraBool_decide_inl', not_lt] at * apply le_of_eq h Β· rcases h with ⟨rfl,(h|h)⟩ Β· rcases h with ⟨h',(h|⟨rfl,rfl,rfl⟩)⟩ <;> rcases sβ‚‚ with (_|sβ‚‚); Β· simp at h' Β· simp at h' rcases h with ⟨hne,(⟨hle,rfl⟩|⟨h,rfl⟩)⟩ Β· simp at * Β· cases sβ‚‚ apply lt_of_le_of_ne Β· apply SignedWad.toRat_le_toRat_of_val_ge_val_inr hle Β· intro he exact hne (SignedWad.val_eq_of_toRat_eq _ _ he).symm Β· simp at * apply SignedWad.toRat_le_toRat_of_val_ge_val_inr (le_of_lt h) Β· simp at * Β· simp at * Β· rcases h with ⟨h',h⟩ rcases sβ‚‚ with (sβ‚‚|sβ‚‚) <;> cases sβ‚‚ Β· rcases h with (⟨_,rfl,rfl⟩|⟨rfl,(⟨_,rfl,rfl⟩|⟨_,rfl,rfl⟩)⟩) <;> simp [SignedWad.toRat_inr_le_toRat_inl] Β· simp at h' aegis_spec "wadray::wadray_signed::SignedWadPartialOrd::lt" := fun _ _ (a b : SignedWad) _ ρ => ρ = Bool.toSierraBool (a.toRat < b.toRat) aegis_prove "wadray::wadray_signed::SignedWadPartialOrd::lt" := fun _ _ (a b : SignedWad) _ ρ => by unfold Β«spec_wadray::wadray_signed::SignedWadPartialOrd::ltΒ» have : 0 < (Wad.WAD_SCALE : β„š) := by norm_num [Wad.WAD_SCALE] rintro ⟨w₁,s₁,wβ‚‚,sβ‚‚,u₁,uβ‚‚,u₃,uβ‚„,uβ‚…,u₆,rfl,rfl,(h|h)⟩ <;> (cases u₁; cases uβ‚‚; cases u₃; cases uβ‚„; cases uβ‚…; cases u₆) Β· rcases h with ⟨rfl,(h|h)⟩ Β· rcases h with ⟨rfl,(⟨hne,h⟩|⟨rfl,rfl,rfl⟩)⟩ Β· rcases h with (⟨hle,rfl⟩|⟨hlt,rfl⟩) Β· simp [SignedWad.toRat_le_toRat_of_val_le_val_inl hle] Β· simp only [SierraBool_toBool_inr, SierraBool_toBool_inl, Bool.xor_false, Bool.toSierraBool_true, Bool.toSierraBool_decide_inr'] apply lt_of_le_of_ne Β· apply SignedWad.toRat_le_toRat_of_val_le_val_inl simp [Wad.toZMod, le_of_lt hlt] Β· intro he exact hne (SignedWad.val_eq_of_toRat_eq _ _ he) Β· simp only [lt_self_iff_false, decide_False, Bool.toSierraBool_false] Β· rcases h with ⟨rfl,(⟨_,rfl,rfl⟩|⟨rfl,(⟨_,rfl,rfl⟩|⟨_,rfl,rfl⟩)⟩)⟩ <;> simp [SignedWad.toRat_inr_le_toRat_inl] Β· rcases h with ⟨rfl,(h|h)⟩ Β· rcases h with ⟨h',(h|⟨rfl,rfl,rfl⟩)⟩ <;> rcases sβ‚‚ with (_|sβ‚‚); Β· simp at h' Β· simp at h' rcases h with ⟨hne,(⟨hle,rfl⟩|⟨h,rfl⟩)⟩ Β· simp at * Β· cases sβ‚‚ apply lt_of_le_of_ne Β· apply SignedWad.toRat_le_toRat_of_val_ge_val_inr hle Β· intro he exact hne (SignedWad.val_eq_of_toRat_eq _ _ he) Β· simp at * apply SignedWad.toRat_le_toRat_of_val_ge_val_inr (le_of_lt h) Β· simp at * Β· simp at * Β· rcases h with ⟨h',h⟩ rcases sβ‚‚ with (sβ‚‚|sβ‚‚) <;> cases sβ‚‚ Β· rcases h with (⟨hne,rfl,rfl⟩|⟨rfl,h⟩) Β· simp apply lt_of_le_of_ne Β· apply SignedWad.toRat_inr_le_toRat_inl Β· intro he exact hne (SignedWad.val_eq_of_toRat_eq _ _ he) Β· rcases h with (⟨h,rfl,rfl⟩|⟨h,rfl,rfl⟩) Β· simp at * apply lt_of_lt_of_le (b := 0) Β· apply lt_of_le_of_ne Β· simp [SignedWad.toRat, Wad.toRat_nonneg] Β· exact h Β· simp [SignedWad.toRat, Wad.toRat_nonneg] Β· simp only [Nat.cast_pos, SierraBool_toBool_inl, Bool.not_false, Bool.toSierraBool_true, SignedWad.toRat, SierraBool_toBool_inr, ite_true, neg_eq_zero, Bool.toSierraBool_decide_inr', ite_false, neg_lt_self_iff, Bool.toSierraBool_decide_inl', not_lt] at * simp [h] Β· simp at h' aegis_spec "wadray::wadray_signed::SignedWadPartialOrd::ge" := fun _ _ (a b : SignedWad) _ ρ => ρ = Bool.toSierraBool (b.toRat ≀ a.toRat) aegis_prove "wadray::wadray_signed::SignedWadPartialOrd::ge" := fun _ _ (a b : SignedWad) _ ρ => by unfold Β«spec_wadray::wadray_signed::SignedWadPartialOrd::geΒ» rintro rfl simp only [← not_lt] rw [decide_not] simp only [Bool.coe_toSierraBool, Bool.toSierraBool_not] aegis_spec "wadray::wadray_signed::SignedWadPartialOrd::le" := fun _ _ (a b : SignedWad) _ ρ => ρ = Bool.toSierraBool (a.toRat ≀ b.toRat) aegis_prove "wadray::wadray_signed::SignedWadPartialOrd::le" := fun _ _ (a b : SignedWad) _ ρ => by unfold Β«spec_wadray::wadray_signed::SignedWadPartialOrd::leΒ» rintro rfl simp only [← not_lt] rw [decide_not] simp only [Bool.coe_toSierraBool, Bool.toSierraBool_not] aegis_spec "wadray::wadray_signed::SignedRayPartialOrd::gt" := fun _ _ (a b : SignedRay) _ ρ => ρ = Bool.toSierraBool (b.toRat < a.toRat) aegis_prove "wadray::wadray_signed::SignedRayPartialOrd::gt" := fun _ _ (a b : SignedRay) _ ρ => by unfold Β«spec_wadray::wadray_signed::SignedRayPartialOrd::gtΒ» have : 0 < (Ray.RAY_SCALE : β„š) := by norm_num [Ray.RAY_SCALE] rintro ⟨w₁,s₁,wβ‚‚,sβ‚‚,u₁,uβ‚‚,u₃,uβ‚„,uβ‚…,u₆,rfl,rfl,(h|h)⟩ <;> (cases u₁; cases uβ‚‚; cases u₃; cases uβ‚„; cases uβ‚…; cases u₆) Β· rcases h with ⟨rfl,(h|h)⟩ Β· rcases h with ⟨rfl,(⟨hne,h⟩|⟨rfl,rfl,rfl⟩)⟩ Β· rcases h with (⟨hle,rfl⟩|⟨hlt,rfl⟩) Β· simp [SignedRay.toRat_le_toRat_of_val_le_val_inl hle] Β· simp only [SierraBool_toBool_inr, SierraBool_toBool_inl, Bool.xor_false, Bool.toSierraBool_true, Bool.toSierraBool_decide_inr'] apply lt_of_le_of_ne Β· apply SignedRay.toRat_le_toRat_of_val_le_val_inl simp [Ray.toZMod, le_of_lt hlt] Β· intro he exact hne (SignedRay.val_eq_of_toRat_eq _ _ he).symm Β· simp only [lt_self_iff_false, decide_False, Bool.toSierraBool_false] Β· rcases h with ⟨rfl,(⟨hne,rfl,rfl⟩|h)⟩ Β· simp only [SierraBool_toBool_inl, Bool.not_false, Bool.toSierraBool_true, Bool.toSierraBool_decide_inr'] apply lt_of_le_of_ne Β· simp [SignedRay.toRat_inr_le_toRat_inl] Β· intro he exact hne (SignedRay.val_eq_of_toRat_eq _ _ he).symm Β· rcases h with ⟨rfl,(⟨h,rfl,rfl⟩|⟨h,rfl,rfl⟩)⟩ Β· simp only [Nat.cast_pos, Bool.toSierraBool_decide_inl', SierraBool_toBool_inl, Bool.not_false, Bool.toSierraBool_true, Bool.toSierraBool_decide_inr'] at * apply lt_of_lt_of_le (b := 0) Β· apply lt_of_le_of_ne Β· simp [SignedRay.toRat, Ray.toRat_nonneg] Β· simpa [SignedRay.toRat] Β· simp [SignedRay.toRat, Ray.toRat_nonneg] Β· simp only [Nat.cast_pos, SignedRay.toRat, SierraBool_toBool_inl, ite_false, Bool.toSierraBool_decide_inr', SierraBool_toBool_inr, ite_true, neg_lt_self_iff, Bool.toSierraBool_decide_inl', not_lt] at * apply le_of_eq h Β· rcases h with ⟨rfl,(h|h)⟩ Β· rcases h with ⟨h',(h|⟨rfl,rfl,rfl⟩)⟩ <;> rcases sβ‚‚ with (_|sβ‚‚); Β· simp at h' Β· simp at h' rcases h with ⟨hne,(⟨hle,rfl⟩|⟨h,rfl⟩)⟩ Β· simp at * Β· cases sβ‚‚ apply lt_of_le_of_ne Β· apply SignedRay.toRat_le_toRat_of_val_ge_val_inr hle Β· intro he exact hne (SignedRay.val_eq_of_toRat_eq _ _ he).symm Β· simp at * apply SignedRay.toRat_le_toRat_of_val_ge_val_inr (le_of_lt h) Β· simp at * Β· simp at * Β· rcases h with ⟨h',h⟩ rcases sβ‚‚ with (sβ‚‚|sβ‚‚) <;> cases sβ‚‚ Β· rcases h with (⟨_,rfl,rfl⟩|⟨rfl,(⟨_,rfl,rfl⟩|⟨_,rfl,rfl⟩)⟩) <;> simp [SignedRay.toRat_inr_le_toRat_inl] Β· simp at h' aegis_spec "wadray::wadray_signed::SignedRayPartialOrd::lt" := fun _ _ (a b : SignedRay) _ ρ => ρ = Bool.toSierraBool (a.toRat < b.toRat) aegis_prove "wadray::wadray_signed::SignedRayPartialOrd::lt" := fun _ _ (a b : SignedRay) _ ρ => by unfold Β«spec_wadray::wadray_signed::SignedRayPartialOrd::ltΒ» have : 0 < (Ray.RAY_SCALE : β„š) := by norm_num [Ray.RAY_SCALE] rintro ⟨w₁,s₁,wβ‚‚,sβ‚‚,u₁,uβ‚‚,u₃,uβ‚„,uβ‚…,u₆,rfl,rfl,(h|h)⟩ <;> (cases u₁; cases uβ‚‚; cases u₃; cases uβ‚„; cases uβ‚…; cases u₆) Β· rcases h with ⟨rfl,(h|h)⟩ Β· rcases h with ⟨rfl,(⟨hne,h⟩|⟨rfl,rfl,rfl⟩)⟩ Β· rcases h with (⟨hle,rfl⟩|⟨hlt,rfl⟩) Β· simp [SignedRay.toRat_le_toRat_of_val_le_val_inl hle] Β· simp only [SierraBool_toBool_inr, SierraBool_toBool_inl, Bool.xor_false, Bool.toSierraBool_true, Bool.toSierraBool_decide_inr'] apply lt_of_le_of_ne Β· apply SignedRay.toRat_le_toRat_of_val_le_val_inl simp [Ray.toZMod, le_of_lt hlt] Β· intro he exact hne (SignedRay.val_eq_of_toRat_eq _ _ he) Β· simp only [lt_self_iff_false, decide_False, Bool.toSierraBool_false] Β· rcases h with ⟨rfl,(⟨_,rfl,rfl⟩|⟨rfl,(⟨_,rfl,rfl⟩|⟨_,rfl,rfl⟩)⟩)⟩ <;> simp [SignedRay.toRat_inr_le_toRat_inl] Β· rcases h with ⟨rfl,(h|h)⟩ Β· rcases h with ⟨h',(h|⟨rfl,rfl,rfl⟩)⟩ <;> rcases sβ‚‚ with (_|sβ‚‚); Β· simp at h' Β· simp at h' rcases h with ⟨hne,(⟨hle,rfl⟩|⟨h,rfl⟩)⟩ Β· simp at * Β· cases sβ‚‚ apply lt_of_le_of_ne Β· apply SignedRay.toRat_le_toRat_of_val_ge_val_inr hle Β· intro he exact hne (SignedRay.val_eq_of_toRat_eq _ _ he) Β· simp at * apply SignedRay.toRat_le_toRat_of_val_ge_val_inr (le_of_lt h) Β· simp at * Β· simp at * Β· rcases h with ⟨h',h⟩ rcases sβ‚‚ with (sβ‚‚|sβ‚‚) <;> cases sβ‚‚ Β· rcases h with (⟨hne,rfl,rfl⟩|⟨rfl,h⟩) Β· simp apply lt_of_le_of_ne Β· apply SignedRay.toRat_inr_le_toRat_inl Β· intro he exact hne (SignedRay.val_eq_of_toRat_eq _ _ he) Β· rcases h with (⟨h,rfl,rfl⟩|⟨h,rfl,rfl⟩) Β· simp at * apply lt_of_lt_of_le (b := 0) Β· apply lt_of_le_of_ne Β· simp [SignedRay.toRat, Ray.toRat_nonneg] Β· exact h Β· simp [SignedRay.toRat, Ray.toRat_nonneg] Β· simp only [Nat.cast_pos, SierraBool_toBool_inl, Bool.not_false, Bool.toSierraBool_true, SignedRay.toRat, SierraBool_toBool_inr, ite_true, neg_eq_zero, Bool.toSierraBool_decide_inr', ite_false, neg_lt_self_iff, Bool.toSierraBool_decide_inl', not_lt] at * simp [h] Β· simp at h' aegis_spec "wadray::wadray_signed::SignedRayPartialOrd::ge" := fun _ _ (a b : SignedRay) _ ρ => ρ = Bool.toSierraBool (b.toRat ≀ a.toRat) aegis_prove "wadray::wadray_signed::SignedRayPartialOrd::ge" := fun _ _ (a b : SignedRay) _ ρ => by unfold Β«spec_wadray::wadray_signed::SignedRayPartialOrd::geΒ» rintro rfl simp only [← not_lt] rw [decide_not] simp only [Bool.coe_toSierraBool, Bool.toSierraBool_not] aegis_spec "wadray::wadray_signed::SignedRayPartialOrd::le" := fun _ _ (a b : SignedRay) _ ρ => ρ = Bool.toSierraBool (a.toRat ≀ b.toRat) aegis_prove "wadray::wadray_signed::SignedRayPartialOrd::le" := fun _ _ (a b : SignedRay) _ ρ => by unfold Β«spec_wadray::wadray_signed::SignedRayPartialOrd::leΒ» rintro rfl simp only [← not_lt] rw [decide_not] simp only [Bool.coe_toSierraBool, Bool.toSierraBool_not] aegis_spec "wadray::wadray_signed::SignedWadTryIntoWad::try_into" := fun _ (a : SignedWad) (ρ : Wad βŠ• _) => ρ = if SierraBool.toBool a.2 then .inr () else .inl a.1 aegis_prove "wadray::wadray_signed::SignedWadTryIntoWad::try_into" := fun _ (a : SignedWad) (ρ : Wad βŠ• _) => by unfold Β«spec_wadray::wadray_signed::SignedWadTryIntoWad::try_intoΒ» aesop aegis_spec "wadray::wadray_signed::SignedRayTryIntoRay::try_into" := fun _ (a : SignedRay) (ρ : Ray βŠ• _) => ρ = if SierraBool.toBool a.2 then .inr () else .inl a.1 aegis_prove "wadray::wadray_signed::SignedRayTryIntoRay::try_into" := fun _ (a : SignedRay) (ρ : Ray βŠ• _) => by unfold Β«spec_wadray::wadray_signed::SignedRayTryIntoRay::try_intoΒ» aesop aegis_spec "wadray::wadray_signed::_felt_sign" := fun _ _ a _ ρ => ρ = Bool.toSierraBool (a.valMinAbs < 0) aegis_prove "wadray::wadray_signed::_felt_sign" := fun _ _ a _ ρ => by unfold Β«spec_wadray::wadray_signed::_felt_signΒ» rintro ⟨x : UInt256, y : UInt256, h₁, hβ‚‚, rfl⟩ have : (1809251394333065606848661391547535052811553607665798349986546028067936010240 : F).val = PRIME / 2 := rfl simp only [Int.ofNat_eq_coe, Nat.cast_ofNat, Int.cast_ofNat] at hβ‚‚ simp only [UInt256.val, hβ‚‚, h₁, ← not_le (b := a.valMinAbs) (a := 0), ZMod.valMinAbs_nonneg_iff] congr; apply propext rw [not_le, ← this, ← hβ‚‚, UInt256.val, ← h₁, UInt256.val] aegis_spec "wadray::wadray_signed::_felt_abs" := fun _ _ a _ ρ => ρ = a.valMinAbs.natAbs aegis_prove "wadray::wadray_signed::_felt_abs" := fun _ _ a _ ρ => by unfold Β«spec_wadray::wadray_signed::_felt_absΒ» sierra_simp' rw [← not_le, ZMod.valMinAbs_nonneg_iff, not_le, not_lt, ZMod.natCast_natAbs_valMinAbs a] aesop aegis_spec "wadray::wadray_signed::sign_from_mul" := fun _ a b ρ => ρ = Bool.toSierraBool (xor (SierraBool.toBool a) (SierraBool.toBool b)) aegis_prove "wadray::wadray_signed::sign_from_mul" := fun _ a b ρ => by unfold Β«spec_wadray::wadray_signed::sign_from_mulΒ» aesop aegis_spec "wadray::wadray_signed::signed_wad_from_felt" := fun _ _ a _ (ρ : SignedWad βŠ• _) => if a.valMinAbs.natAbs < U128_MOD then ρ.isLeft ∧ ρ.getLeft?.get!.toRat = a.valMinAbs / Wad.WAD_SCALE else ρ.isRight aegis_prove "wadray::wadray_signed::signed_wad_from_felt" := fun _ _ a _ (ρ : SignedWad βŠ• _) => by have hlt : a.valMinAbs.natAbs < PRIME := by apply lt_of_le_of_lt (ZMod.natAbs_valMinAbs_le a) norm_num [PRIME] unfold Β«spec_wadray::wadray_signed::signed_wad_from_feltΒ» rintro ⟨_,_,_,(⟨h₁,rfl⟩|⟨h₁,rfl⟩),(⟨hβ‚‚,rfl⟩|⟨hβ‚‚,rfl⟩)⟩ Β· cases hβ‚‚ rw [ZMod.val_natCast_of_lt hlt] at h₁ simp only [SignedWad.toRat] split_ifs with h₃ Β· simp_all only [Option.get!, ZMod.cast_nat_cast_of_lt hlt, Sum.getLeft?_inl, Bool.coe_toSierraBool, decide_eq_true_eq, decide_True, Bool.toSierraBool_true, Sum.isLeft_inl, Wad.toRat, Wad.toZMod, ZMod.val_natCast, Nat.mod_eq_of_lt h₁, neg_div', true_and] congr rw [Nat.cast_natAbs, Int.cast_abs, neg_eq_iff_eq_neg] simp only [abs_eq_neg_self, Int.cast_nonpos] exact le_of_lt h₃ Β· simp_all only [Option.get!, Sum.getLeft?_inl, Bool.coe_toSierraBool, decide_eq_true_eq, not_lt, Sum.isLeft_inl, Wad.toRat, Wad.toZMod, ZMod.natCast_val, true_and, ZMod.cast_nat_cast_of_lt hlt, ZMod.cast_nat_cast_of_lt h₁] congr rw [Nat.cast_natAbs] aesop Β· simp at hβ‚‚ Β· simp at hβ‚‚ Β· cases hβ‚‚ rw [ZMod.val_natCast_of_lt hlt, ← not_lt] at h₁ simp [h₁] aegis_spec "wadray::wadray_signed::signed_ray_from_felt" := fun _ _ a _ (ρ : SignedRay βŠ• _) => if a.valMinAbs.natAbs < U128_MOD then ρ.isLeft ∧ ρ.getLeft?.get!.toRat = a.valMinAbs / Ray.RAY_SCALE else ρ.isRight aegis_prove "wadray::wadray_signed::signed_ray_from_felt" := fun _ _ a _ (ρ : SignedRay βŠ• _) => by have hlt : a.valMinAbs.natAbs < PRIME := by apply lt_of_le_of_lt (ZMod.natAbs_valMinAbs_le a) norm_num [PRIME] unfold Β«spec_wadray::wadray_signed::signed_ray_from_feltΒ» rintro ⟨_,_,_,(⟨h₁,rfl⟩|⟨h₁,rfl⟩),(⟨hβ‚‚,rfl⟩|⟨hβ‚‚,rfl⟩)⟩ Β· cases hβ‚‚ rw [ZMod.val_natCast_of_lt hlt] at h₁ simp only [SignedRay.toRat] split_ifs with h₃ Β· simp_all only [Option.get!, ZMod.cast_nat_cast_of_lt hlt, Sum.getLeft?_inl, Bool.coe_toSierraBool, decide_eq_true_eq, decide_True, Bool.toSierraBool_true, Sum.isLeft_inl, Ray.toRat, Ray.toZMod, ZMod.val_natCast, Nat.mod_eq_of_lt h₁, neg_div', true_and] congr rw [Nat.cast_natAbs, Int.cast_abs, neg_eq_iff_eq_neg] simp only [abs_eq_neg_self, Int.cast_nonpos] exact le_of_lt h₃ Β· simp_all only [Option.get!, Sum.getLeft?_inl, Bool.coe_toSierraBool, decide_eq_true_eq, not_lt, Sum.isLeft_inl, Ray.toRat, Ray.toZMod, ZMod.natCast_val, true_and, ZMod.cast_nat_cast_of_lt hlt, ZMod.cast_nat_cast_of_lt h₁] congr rw [Nat.cast_natAbs] aesop Β· simp at hβ‚‚ Β· simp at hβ‚‚ Β· cases hβ‚‚ rw [ZMod.val_natCast_of_lt hlt, ← not_lt] at h₁ simp [h₁] aegis_spec "wadray::wadray_signed::SignedWadIntoFelt252::into" := fun _ (a : SignedWad) ρ => ρ = if SierraBool.toBool a.2 then -a.1.cast else a.1.cast aegis_prove "wadray::wadray_signed::SignedWadIntoFelt252::into" := fun _ (a : SignedWad) ρ => by unfold Β«spec_wadray::wadray_signed::SignedWadIntoFelt252::intoΒ» aesop aegis_spec "wadray::wadray_signed::SignedRayIntoFelt252::into" := fun _ (a : SignedRay) ρ => ρ = if SierraBool.toBool a.2 then -a.1.cast else a.1.cast aegis_prove "wadray::wadray_signed::SignedRayIntoFelt252::into" := fun _ (a : SignedRay) ρ => by unfold Β«spec_wadray::wadray_signed::SignedRayIntoFelt252::intoΒ» aesop aegis_spec "wadray::wadray_signed::SignedWadAdd::add" := fun _ _ (a b : SignedWad) _ (ρ : SignedWad βŠ• _) => if |a.toRat + b.toRat| < U128_MOD / Wad.WAD_SCALE then ρ.isLeft ∧ ρ.getLeft?.get!.toRat = a.toRat + b.toRat else ρ.isRight
theorem add_aux1 (x : UInt128) : 4 * (x.cast : F).valMinAbs.natAbs < PRIME :=
:= by rw [ZMod.valMinAbs_cast_of_lt_half two_U128_MOD_lt_PRIME, Int.natAbs_ofNat] apply lt_of_lt_of_le _ four_U128_MOD_le_PRIME apply Nat.mul_lt_mul_of_pos_left (ZMod.val_lt _) (by norm_num) aegis_prove "wadray::wadray_signed::SignedWadAdd::add" := fun _ _ (a b : SignedWad) _ (ρ : SignedWad βŠ• _) => by unfold Β«spec_wadray::wadray_signed::SignedWadAdd::addΒ» rcases a with ⟨va,sa⟩ rcases b with ⟨vb,sb⟩ have hS : 0 < (Wad.WAD_SCALE : β„š) := by norm_num [Wad.WAD_SCALE] have hane : 2 * (va.cast : ZMod PRIME).val β‰  PRIME := by apply ne_of_lt (lt_trans (Nat.mul_lt_mul_of_pos_left (ZMod.val_cast_lt PRIME va) two_pos) two_U128_MOD_lt_PRIME) have hbne : 2 * (vb.cast : ZMod PRIME).val β‰  PRIME := by apply ne_of_lt (lt_trans (Nat.mul_lt_mul_of_pos_left (ZMod.val_cast_lt PRIME vb) two_pos) two_U128_MOD_lt_PRIME) have ha : 4 * (va.cast : F).valMinAbs.natAbs < PRIME := add_aux1 va have hb : 4 * (vb.cast : F).valMinAbs.natAbs < PRIME := add_aux1 vb have ha' : 4 * (- (va.cast : F)).valMinAbs.natAbs < PRIME := by rwa [ZMod.valMinAbs_neg_of_ne_half hane, Int.natAbs_neg] have hb' : 4 * (- (vb.cast : F)).valMinAbs.natAbs < PRIME := by rwa [ZMod.valMinAbs_neg_of_ne_half hbne, Int.natAbs_neg] rintro ⟨x,y,z,h₁,(⟨rfl,rfl⟩|⟨rfl,rfl⟩)⟩ <;> dsimp only at h₁ Β· simp only [Sum.isLeft_inl, Sum.getLeft?_inl, Option.get!_some, true_and, Sum.isRight_inl, ite_prop_iff_or, not_lt, and_false, or_false] at h₁ ⊒ rcases sa with (sa|sa) <;> cases sa <;> rcases sb with (sb|sb) <;> cases sb <;> simp only [SierraBool_toBool_inl, SierraBool_toBool_inr, ite_false, ite_true] at h₁ <;> rcases h₁ with ⟨h₁,hβ‚‚βŸ© Β· simp only [ZMod.valMinAbs_add_of_four_lt ha hb, Int.natAbs_ofNat, ZMod.valMinAbs_cast_of_lt_half two_U128_MOD_lt_PRIME, ← Nat.cast_add] at h₁ hβ‚‚ push_cast at hβ‚‚; rw [hβ‚‚] simp only [SignedWad.toRat, SierraBool_toBool_inl, Wad.toRat, Wad.toZMod, ite_false, and_true, add_div] rw [← add_div, ← Nat.cast_add, abs_div, Nat.abs_cast] apply div_lt_div_of_pos_right _ hS rwa [Nat.cast_lt] Β· simp only [ZMod.valMinAbs_add_of_four_lt ha hb', ZMod.valMinAbs_neg_of_ne_half hbne, ZMod.valMinAbs_cast_of_lt_half two_U128_MOD_lt_PRIME] at h₁ hβ‚‚ push_cast at hβ‚‚; rw [hβ‚‚] simp only [SignedWad.toRat, SierraBool_toBool_inl, Wad.toRat, Wad.toZMod, ite_false, SierraBool_toBool_inr, ite_true, add_div, neg_div, and_true] rw [← neg_div, ← add_div, abs_div, Nat.abs_cast] apply div_lt_div_of_pos_right _ hS simp only [← Nat.cast_lt (Ξ± := β„š), Int.cast_natAbs, Int.cast_abs, Int.cast_add, ZMod.natCast_val, ZMod.intCast_cast, Int.cast_neg] at h₁ ⊒ assumption Β· simp only [ZMod.valMinAbs_add_of_four_lt ha' hb, ZMod.valMinAbs_neg_of_ne_half hane, ZMod.valMinAbs_cast_of_lt_half two_U128_MOD_lt_PRIME] at h₁ hβ‚‚ push_cast at hβ‚‚; rw [hβ‚‚] simp only [SignedWad.toRat, SierraBool_toBool_inl, Wad.toRat, Wad.toZMod, ite_false, SierraBool_toBool_inr, ite_true, add_div, neg_div, and_true] rw [← neg_div, ← add_div, abs_div, Nat.abs_cast] apply div_lt_div_of_pos_right _ hS simp only [← Nat.cast_lt (Ξ± := β„š), Int.cast_natAbs, Int.cast_abs, Int.cast_add, ZMod.natCast_val, ZMod.intCast_cast, Int.cast_neg] at h₁ ⊒ assumption Β· simp only [ZMod.valMinAbs_add_of_four_lt ha' hb', ZMod.valMinAbs_neg_of_ne_half hbne, ZMod.valMinAbs_neg_of_ne_half hane, ZMod.valMinAbs_cast_of_lt_half two_U128_MOD_lt_PRIME, neg_add] at h₁ hβ‚‚ push_cast at hβ‚‚; rw [hβ‚‚] simp only [SignedWad.toRat, SierraBool_toBool_inr, Wad.toRat, Wad.toZMod, ite_true, add_div, neg_div, and_true] rw [← neg_div, ← neg_div, ← add_div, abs_div, Nat.abs_cast] apply div_lt_div_of_pos_right _ hS rw [← neg_add, abs_neg, ← Nat.cast_add, Nat.abs_cast, Nat.cast_lt] rwa [← neg_add, ← Nat.cast_add, Int.natAbs_neg, Int.natAbs_ofNat] at h₁ Β· simp only [Sum.isLeft_inr, Sum.getLeft?_inr, Option.get!_none, false_and, Sum.isRight_inr, ite_prop_iff_or, and_false, not_lt, and_true, false_or] at h₁ ⊒ rcases sa with (sa|sa) <;> cases sa <;> rcases sb with (sb|sb) <;> cases sb <;> simp only [SierraBool_toBool_inl, SierraBool_toBool_inr, ite_false, ite_true, ZMod.valMinAbs_add_of_four_lt ha hb, ZMod.valMinAbs_add_of_four_lt ha' hb, ZMod.valMinAbs_add_of_four_lt ha hb', ZMod.valMinAbs_add_of_four_lt ha' hb', ZMod.valMinAbs_neg_of_ne_half hane, ZMod.valMinAbs_neg_of_ne_half hbne, ZMod.valMinAbs_cast_of_lt_half two_U128_MOD_lt_PRIME, ← Nat.cast_le (Ξ± := β„š), Int.cast_natAbs, Int.cast_abs, Int.cast_add, ZMod.natCast_val, ZMod.intCast_cast, Int.cast_neg] at h₁ <;> simpa [SignedWad.toRat, Wad.toRat, Wad.toZMod, ← neg_div, ← add_div, abs_div, div_le_div_right hS] aegis_spec "wadray::wadray_signed::SignedWadAddEq::add_eq" := fun _ _ (a b : SignedWad) _ (ρ : SignedWad Γ— Unit βŠ• _) => if |a.toRat + b.toRat| < U128_MOD / Wad.WAD_SCALE then ρ.isLeft ∧ ρ.getLeft?.get!.1.toRat = a.toRat + b.toRat else ρ.isRight aegis_prove "wadray::wadray_signed::SignedWadAddEq::add_eq" := fun _ _ (a b : SignedWad) _ (ρ : SignedWad Γ— Unit βŠ• _) => by unfold Β«spec_wadray::wadray_signed::SignedWadAddEq::add_eqΒ» aesop aegis_spec "wadray::wadray_signed::SignedRayAdd::add" := fun _ _ (a b : SignedRay) _ (ρ : SignedRay βŠ• _) => if |a.toRat + b.toRat| < U128_MOD / Ray.RAY_SCALE then ρ.isLeft ∧ ρ.getLeft?.get!.toRat = a.toRat + b.toRat else ρ.isRight aegis_prove "wadray::wadray_signed::SignedRayAdd::add" := fun _ _ (a b : SignedRay) _ (ρ : SignedRay βŠ• _) => by unfold Β«spec_wadray::wadray_signed::SignedRayAdd::addΒ» rcases a with ⟨va,sa⟩ rcases b with ⟨vb,sb⟩ have hS : 0 < (Ray.RAY_SCALE : β„š) := by norm_num [Ray.RAY_SCALE] have hane : 2 * (va.cast : ZMod PRIME).val β‰  PRIME := by apply ne_of_lt (lt_trans (Nat.mul_lt_mul_of_pos_left (ZMod.val_cast_lt PRIME va) two_pos) two_U128_MOD_lt_PRIME) have hbne : 2 * (vb.cast : ZMod PRIME).val β‰  PRIME := by apply ne_of_lt (lt_trans (Nat.mul_lt_mul_of_pos_left (ZMod.val_cast_lt PRIME vb) two_pos) two_U128_MOD_lt_PRIME) have ha : 4 * (va.cast : F).valMinAbs.natAbs < PRIME := add_aux1 va have hb : 4 * (vb.cast : F).valMinAbs.natAbs < PRIME := add_aux1 vb have ha' : 4 * (-(va.cast : F)).valMinAbs.natAbs < PRIME := by rwa [ZMod.valMinAbs_neg_of_ne_half hane, Int.natAbs_neg] have hb' : 4 * (-(vb.cast : F)).valMinAbs.natAbs < PRIME := by rwa [ZMod.valMinAbs_neg_of_ne_half hbne, Int.natAbs_neg] rintro ⟨x,y,z,h₁,(⟨rfl,rfl⟩|⟨rfl,rfl⟩)⟩ <;> dsimp only at h₁ Β· simp only [Sum.isLeft_inl, Sum.getLeft?_inl, Option.get!_some, true_and, Sum.isRight_inl, ite_prop_iff_or, not_lt, and_false, or_false] at h₁ ⊒ rcases sa with (sa|sa) <;> cases sa <;> rcases sb with (sb|sb) <;> cases sb <;> simp only [SierraBool_toBool_inl, SierraBool_toBool_inr, ite_false, ite_true] at h₁ <;> rcases h₁ with ⟨h₁,hβ‚‚βŸ© Β· simp only [ZMod.valMinAbs_add_of_four_lt ha hb, Int.natAbs_ofNat, ZMod.valMinAbs_cast_of_lt_half two_U128_MOD_lt_PRIME, ← Nat.cast_add] at h₁ hβ‚‚ push_cast at hβ‚‚; rw [hβ‚‚] simp only [SignedRay.toRat, SierraBool_toBool_inl, Ray.toRat, Ray.toZMod, ite_false, and_true, add_div] rw [← add_div, ← Nat.cast_add, abs_div, Nat.abs_cast] apply div_lt_div_of_pos_right _ hS rwa [Nat.cast_lt] Β· simp only [ZMod.valMinAbs_add_of_four_lt ha hb', ZMod.valMinAbs_neg_of_ne_half hbne, ZMod.valMinAbs_cast_of_lt_half two_U128_MOD_lt_PRIME] at h₁ hβ‚‚ push_cast at hβ‚‚; rw [hβ‚‚] simp only [SignedRay.toRat, SierraBool_toBool_inl, Ray.toRat, Ray.toZMod, ite_false, SierraBool_toBool_inr, ite_true, add_div, neg_div, and_true] rw [← neg_div, ← add_div, abs_div, Nat.abs_cast] apply div_lt_div_of_pos_right _ hS simp only [← Nat.cast_lt (Ξ± := β„š), Int.cast_natAbs, Int.cast_abs, Int.cast_add, ZMod.natCast_val, ZMod.intCast_cast, Int.cast_neg] at h₁ ⊒ assumption Β· simp only [ZMod.valMinAbs_add_of_four_lt ha' hb, ZMod.valMinAbs_neg_of_ne_half hane, ZMod.valMinAbs_cast_of_lt_half two_U128_MOD_lt_PRIME] at h₁ hβ‚‚ push_cast at hβ‚‚; rw [hβ‚‚] simp only [SignedRay.toRat, SierraBool_toBool_inl, Ray.toRat, Ray.toZMod, ite_false, SierraBool_toBool_inr, ite_true, add_div, neg_div, and_true] rw [← neg_div, ← add_div, abs_div, Nat.abs_cast] apply div_lt_div_of_pos_right _ hS simp only [← Nat.cast_lt (Ξ± := β„š), Int.cast_natAbs, Int.cast_abs, Int.cast_add, ZMod.natCast_val, ZMod.intCast_cast, Int.cast_neg] at h₁ ⊒ assumption Β· simp only [ZMod.valMinAbs_add_of_four_lt ha' hb', ZMod.valMinAbs_neg_of_ne_half hbne, ZMod.valMinAbs_neg_of_ne_half hane, ZMod.valMinAbs_cast_of_lt_half two_U128_MOD_lt_PRIME, neg_add] at h₁ hβ‚‚ push_cast at hβ‚‚; rw [hβ‚‚] simp only [SignedRay.toRat, SierraBool_toBool_inr, Ray.toRat, Ray.toZMod, ite_true, add_div, neg_div, and_true] rw [← neg_div, ← neg_div, ← add_div, abs_div, Nat.abs_cast] apply div_lt_div_of_pos_right _ hS rw [← neg_add, abs_neg, ← Nat.cast_add, Nat.abs_cast, Nat.cast_lt] rwa [← neg_add, ← Nat.cast_add, Int.natAbs_neg, Int.natAbs_ofNat] at h₁ Β· simp only [Sum.isLeft_inr, Sum.getLeft?_inr, Option.get!_none, false_and, Sum.isRight_inr, ite_prop_iff_or, and_false, not_lt, and_true, false_or] at h₁ ⊒ rcases sa with (sa|sa) <;> cases sa <;> rcases sb with (sb|sb) <;> cases sb <;> simp only [SierraBool_toBool_inl, SierraBool_toBool_inr, ite_false, ite_true, ZMod.valMinAbs_add_of_four_lt ha hb, ZMod.valMinAbs_add_of_four_lt ha' hb, ZMod.valMinAbs_add_of_four_lt ha hb', ZMod.valMinAbs_add_of_four_lt ha' hb', ZMod.valMinAbs_neg_of_ne_half hane, ZMod.valMinAbs_neg_of_ne_half hbne, ZMod.valMinAbs_cast_of_lt_half two_U128_MOD_lt_PRIME, ← Nat.cast_le (Ξ± := β„š), Int.cast_natAbs, Int.cast_abs, Int.cast_add, ZMod.natCast_val, ZMod.intCast_cast, Int.cast_neg] at h₁ <;> simpa [SignedRay.toRat, Ray.toRat, Ray.toZMod, ← neg_div, ← add_div, abs_div, div_le_div_right hS] aegis_spec "wadray::wadray_signed::SignedWadSub::sub" := fun _ _ (a b : SignedWad) _ (ρ : SignedWad βŠ• _) => if |a.toRat - b.toRat| < U128_MOD / Wad.WAD_SCALE then ρ.isLeft ∧ ρ.getLeft?.get!.toRat = a.toRat - b.toRat else ρ.isRight aegis_prove "wadray::wadray_signed::SignedWadSub::sub" := fun _ _ (a b : SignedWad) _ (ρ : SignedWad βŠ• _) => by unfold Β«spec_wadray::wadray_signed::SignedWadSub::subΒ» rcases a with ⟨va,sa⟩ rcases b with ⟨vb,sb⟩ have hS : 0 < (Wad.WAD_SCALE : β„š) := by norm_num [Wad.WAD_SCALE] have hane : 2 * (va.cast : ZMod PRIME).val β‰  PRIME := by apply ne_of_lt (lt_trans (Nat.mul_lt_mul_of_pos_left (ZMod.val_cast_lt PRIME va) two_pos) two_U128_MOD_lt_PRIME) have hbne : 2 * (vb.cast : ZMod PRIME).val β‰  PRIME := by apply ne_of_lt (lt_trans (Nat.mul_lt_mul_of_pos_left (ZMod.val_cast_lt PRIME vb) two_pos) two_U128_MOD_lt_PRIME) have ha : 4 * (va.cast : F).valMinAbs.natAbs < PRIME := add_aux1 va have hb : 4 * (vb.cast : F).valMinAbs.natAbs < PRIME := add_aux1 vb have ha' : 4 * (- (va.cast : F)).valMinAbs.natAbs < PRIME := by rwa [ZMod.valMinAbs_neg_of_ne_half hane, Int.natAbs_neg] have hb' : 4 * (- (vb.cast : F)).valMinAbs.natAbs < PRIME := by rwa [ZMod.valMinAbs_neg_of_ne_half hbne, Int.natAbs_neg] rintro ⟨x,y,z,h₁,(⟨rfl,rfl⟩|⟨rfl,rfl⟩)⟩ <;> dsimp only at h₁ Β· simp only [Sum.isLeft_inl, Sum.getLeft?_inl, Option.get!_some, true_and, Sum.isRight_inl, ite_prop_iff_or, not_lt, and_false, or_false] at h₁ ⊒ rcases sa with (sa|sa) <;> cases sa <;> rcases sb with (sb|sb) <;> cases sb <;> simp only [SierraBool_toBool_inl, SierraBool_toBool_inr, ite_false, ite_true] at h₁ <;> rcases h₁ with ⟨h₁,hβ‚‚βŸ© Β· rw [sub_eq_add_neg] at h₁ hβ‚‚ ⊒ simp only [ZMod.valMinAbs_add_of_four_lt ha hb', ZMod.valMinAbs_neg_of_ne_half hbne, ZMod.valMinAbs_cast_of_lt_half two_U128_MOD_lt_PRIME] at h₁ hβ‚‚ push_cast at hβ‚‚; rw [hβ‚‚] simp only [SignedWad.toRat, SierraBool_toBool_inl, Wad.toRat, Wad.toZMod, ite_false, SierraBool_toBool_inr, ite_true, add_div, neg_div, and_true] rw [← neg_div, ← add_div, abs_div, Nat.abs_cast] apply div_lt_div_of_pos_right _ hS simp only [← Nat.cast_lt (Ξ± := β„š), Int.cast_natAbs, Int.cast_abs, Int.cast_add, ZMod.natCast_val, ZMod.intCast_cast, Int.cast_neg] at h₁ ⊒ assumption Β· rw [sub_neg_eq_add] at h₁ hβ‚‚; rw [sub_eq_add_neg] simp only [ZMod.valMinAbs_add_of_four_lt ha hb, Int.natAbs_ofNat, ZMod.valMinAbs_cast_of_lt_half two_U128_MOD_lt_PRIME, ← Nat.cast_add] at h₁ hβ‚‚ push_cast at hβ‚‚; rw [hβ‚‚] simp only [SignedWad.toRat, SierraBool_toBool_inl, Wad.toRat, Wad.toZMod, ite_false, SierraBool_toBool_inr, ite_true, neg_neg, add_div, and_true] rw [← add_div, ← Nat.cast_add, abs_div, Nat.abs_cast] apply div_lt_div_of_pos_right _ hS rwa [Nat.cast_lt] Β· rw [sub_eq_add_neg] at h₁ hβ‚‚ ⊒ simp only [ZMod.valMinAbs_add_of_four_lt ha' hb', ZMod.valMinAbs_neg_of_ne_half hbne, ZMod.valMinAbs_neg_of_ne_half hane, ZMod.valMinAbs_cast_of_lt_half two_U128_MOD_lt_PRIME, neg_add] at h₁ hβ‚‚ push_cast at hβ‚‚; rw [hβ‚‚] simp only [SignedWad.toRat, SierraBool_toBool_inr, Wad.toRat, Wad.toZMod, ite_true, SierraBool_toBool_inl, ite_false, add_div, neg_div, and_true] rw [← neg_div, ← neg_div, ← add_div, abs_div, Nat.abs_cast] apply div_lt_div_of_pos_right _ hS rw [← neg_add, abs_neg, ← Nat.cast_add, Nat.abs_cast, Nat.cast_lt] rwa [← neg_add, ← Nat.cast_add, Int.natAbs_neg, Int.natAbs_ofNat] at h₁ Β· rw [sub_neg_eq_add] at h₁ hβ‚‚; rw [sub_eq_add_neg] simp only [ZMod.valMinAbs_add_of_four_lt ha' hb, ZMod.valMinAbs_neg_of_ne_half hane, ZMod.valMinAbs_cast_of_lt_half two_U128_MOD_lt_PRIME] at h₁ hβ‚‚ push_cast at hβ‚‚; rw [hβ‚‚] simp only [SignedWad.toRat, SierraBool_toBool_inr, Wad.toRat, Wad.toZMod, ite_true, neg_neg, add_div, neg_div, and_true] rw [← neg_div, ← add_div, abs_div, Nat.abs_cast] apply div_lt_div_of_pos_right _ hS simp only [← Nat.cast_lt (Ξ± := β„š), Int.cast_natAbs, Int.cast_abs, Int.cast_add, ZMod.natCast_val, ZMod.intCast_cast, Int.cast_neg] at h₁ ⊒ assumption Β· simp only [Sum.isLeft_inr, Sum.getLeft?_inr, Option.get!_none, false_and, Sum.isRight_inr, ite_prop_iff_or, and_false, not_lt, and_true, false_or] at h₁ ⊒ rw [sub_eq_add_neg] at h₁ ⊒ rcases sa with (sa|sa) <;> cases sa <;> rcases sb with (sb|sb) <;> cases sb <;> simp only [SierraBool_toBool_inl, SierraBool_toBool_inr, ite_false, ite_true, ZMod.valMinAbs_add_of_four_lt ha hb, ZMod.valMinAbs_add_of_four_lt ha' hb, ZMod.valMinAbs_add_of_four_lt ha hb', ZMod.valMinAbs_add_of_four_lt ha' hb', ZMod.valMinAbs_neg_of_ne_half hane, ZMod.valMinAbs_neg_of_ne_half hbne, ZMod.valMinAbs_cast_of_lt_half two_U128_MOD_lt_PRIME, ← Nat.cast_le (Ξ± := β„š), Int.cast_natAbs, Int.cast_abs, Int.cast_add, ZMod.natCast_val, ZMod.intCast_cast, Int.cast_neg, neg_neg] at h₁ <;> simpa [SignedWad.toRat, Wad.toRat, Wad.toZMod, ← neg_div, ← add_div, abs_div, div_le_div_right hS] aegis_spec "wadray::wadray_signed::SignedWadSubEq::sub_eq" := fun _ _ (a b : SignedWad) _ (ρ : SignedWad Γ— Unit βŠ• _) => if |a.toRat - b.toRat| < U128_MOD / Wad.WAD_SCALE then ρ.isLeft ∧ ρ.getLeft?.get!.1.toRat = a.toRat - b.toRat else ρ.isRight aegis_prove "wadray::wadray_signed::SignedWadSubEq::sub_eq" := fun _ _ (a b : SignedWad) _ (ρ : SignedWad Γ— Unit βŠ• _) => by unfold Β«spec_wadray::wadray_signed::SignedWadSubEq::sub_eqΒ» aesop aegis_spec "wadray::wadray_signed::SignedRaySub::sub" := fun _ _ (a b : SignedRay) _ (ρ : SignedRay βŠ• _) => if |a.toRat - b.toRat| < U128_MOD / Ray.RAY_SCALE then ρ.isLeft ∧ ρ.getLeft?.get!.toRat = a.toRat - b.toRat else ρ.isRight aegis_prove "wadray::wadray_signed::SignedRaySub::sub" := fun _ _ (a b : SignedRay) _ (ρ : SignedRay βŠ• _) => by unfold Β«spec_wadray::wadray_signed::SignedRaySub::subΒ» rcases a with ⟨va,sa⟩ rcases b with ⟨vb,sb⟩ have hS : 0 < (Ray.RAY_SCALE : β„š) := by norm_num [Ray.RAY_SCALE] have hane : 2 * (va.cast : ZMod PRIME).val β‰  PRIME := by apply ne_of_lt (lt_trans (Nat.mul_lt_mul_of_pos_left (ZMod.val_cast_lt PRIME va) two_pos) two_U128_MOD_lt_PRIME) have hbne : 2 * (vb.cast : ZMod PRIME).val β‰  PRIME := by apply ne_of_lt (lt_trans (Nat.mul_lt_mul_of_pos_left (ZMod.val_cast_lt PRIME vb) two_pos) two_U128_MOD_lt_PRIME) have ha : 4 * (va.cast : F).valMinAbs.natAbs < PRIME := add_aux1 va have hb : 4 * (vb.cast : F).valMinAbs.natAbs < PRIME := add_aux1 vb have ha' : 4 * (- (va.cast : F)).valMinAbs.natAbs < PRIME := by rwa [ZMod.valMinAbs_neg_of_ne_half hane, Int.natAbs_neg] have hb' : 4 * (- (vb.cast : F)).valMinAbs.natAbs < PRIME := by rwa [ZMod.valMinAbs_neg_of_ne_half hbne, Int.natAbs_neg] rintro ⟨x,y,z,h₁,(⟨rfl,rfl⟩|⟨rfl,rfl⟩)⟩ <;> dsimp only at h₁ Β· simp only [Sum.isLeft_inl, Sum.getLeft?_inl, Option.get!_some, true_and, Sum.isRight_inl, ite_prop_iff_or, not_lt, and_false, or_false] at h₁ ⊒ rcases sa with (sa|sa) <;> cases sa <;> rcases sb with (sb|sb) <;> cases sb <;> simp only [SierraBool_toBool_inl, SierraBool_toBool_inr, ite_false, ite_true] at h₁ <;> rcases h₁ with ⟨h₁,hβ‚‚βŸ© Β· rw [sub_eq_add_neg] at h₁ hβ‚‚ ⊒ simp only [ZMod.valMinAbs_add_of_four_lt ha hb', ZMod.valMinAbs_neg_of_ne_half hbne, ZMod.valMinAbs_cast_of_lt_half two_U128_MOD_lt_PRIME] at h₁ hβ‚‚ push_cast at hβ‚‚; rw [hβ‚‚] simp only [SignedRay.toRat, SierraBool_toBool_inl, Ray.toRat, Ray.toZMod, ite_false, SierraBool_toBool_inr, ite_true, add_div, neg_div, and_true] rw [← neg_div, ← add_div, abs_div, Nat.abs_cast] apply div_lt_div_of_pos_right _ hS simp only [← Nat.cast_lt (Ξ± := β„š), Int.cast_natAbs, Int.cast_abs, Int.cast_add, ZMod.natCast_val, ZMod.intCast_cast, Int.cast_neg] at h₁ ⊒ assumption Β· rw [sub_neg_eq_add] at h₁ hβ‚‚; rw [sub_eq_add_neg] simp only [ZMod.valMinAbs_add_of_four_lt ha hb, Int.natAbs_ofNat, ZMod.valMinAbs_cast_of_lt_half two_U128_MOD_lt_PRIME, ← Nat.cast_add] at h₁ hβ‚‚ push_cast at hβ‚‚; rw [hβ‚‚] simp only [SignedRay.toRat, SierraBool_toBool_inl, Ray.toRat, Ray.toZMod, ite_false, SierraBool_toBool_inr, ite_true, neg_neg, add_div, and_true] rw [← add_div, ← Nat.cast_add, abs_div, Nat.abs_cast] apply div_lt_div_of_pos_right _ hS rwa [Nat.cast_lt] Β· rw [sub_eq_add_neg] at h₁ hβ‚‚ ⊒ simp only [ZMod.valMinAbs_add_of_four_lt ha' hb', ZMod.valMinAbs_neg_of_ne_half hbne, ZMod.valMinAbs_neg_of_ne_half hane, ZMod.valMinAbs_cast_of_lt_half two_U128_MOD_lt_PRIME, neg_add] at h₁ hβ‚‚ push_cast at hβ‚‚; rw [hβ‚‚] simp only [SignedRay.toRat, SierraBool_toBool_inr, Ray.toRat, Ray.toZMod, ite_true, SierraBool_toBool_inl, ite_false, add_div, neg_div, and_true] rw [← neg_div, ← neg_div, ← add_div, abs_div, Nat.abs_cast] apply div_lt_div_of_pos_right _ hS rw [← neg_add, abs_neg, ← Nat.cast_add, Nat.abs_cast, Nat.cast_lt] rwa [← neg_add, ← Nat.cast_add, Int.natAbs_neg, Int.natAbs_ofNat] at h₁ Β· rw [sub_neg_eq_add] at h₁ hβ‚‚; rw [sub_eq_add_neg] simp only [ZMod.valMinAbs_add_of_four_lt ha' hb, ZMod.valMinAbs_neg_of_ne_half hane, ZMod.valMinAbs_cast_of_lt_half two_U128_MOD_lt_PRIME] at h₁ hβ‚‚ push_cast at hβ‚‚; rw [hβ‚‚] simp only [SignedRay.toRat, SierraBool_toBool_inr, Ray.toRat, Ray.toZMod, ite_true, neg_neg, add_div, neg_div, and_true] rw [← neg_div, ← add_div, abs_div, Nat.abs_cast] apply div_lt_div_of_pos_right _ hS simp only [← Nat.cast_lt (Ξ± := β„š), Int.cast_natAbs, Int.cast_abs, Int.cast_add, ZMod.natCast_val, ZMod.intCast_cast, Int.cast_neg] at h₁ ⊒ assumption Β· simp only [Sum.isLeft_inr, Sum.getLeft?_inr, Option.get!_none, false_and, Sum.isRight_inr, ite_prop_iff_or, and_false, not_lt, and_true, false_or] at h₁ ⊒ rw [sub_eq_add_neg] at h₁ ⊒ rcases sa with (sa|sa) <;> cases sa <;> rcases sb with (sb|sb) <;> cases sb <;> simp only [SierraBool_toBool_inl, SierraBool_toBool_inr, ite_false, ite_true, ZMod.valMinAbs_add_of_four_lt ha hb, ZMod.valMinAbs_add_of_four_lt ha' hb, ZMod.valMinAbs_add_of_four_lt ha hb', ZMod.valMinAbs_add_of_four_lt ha' hb', ZMod.valMinAbs_neg_of_ne_half hane, ZMod.valMinAbs_neg_of_ne_half hbne, ZMod.valMinAbs_cast_of_lt_half two_U128_MOD_lt_PRIME, ← Nat.cast_le (Ξ± := β„š), Int.cast_natAbs, Int.cast_abs, Int.cast_add, ZMod.natCast_val, ZMod.intCast_cast, Int.cast_neg, neg_neg] at h₁ <;> simpa [SignedRay.toRat, Ray.toRat, Ray.toZMod, ← neg_div, ← add_div, abs_div, div_le_div_right hS] aegis_spec "wadray::wadray_signed::SignedWadMul::mul" := fun _ _ (a b : SignedWad) _ (ρ : SignedWad βŠ• _) => a.1.val * b.1.val / Wad.WAD_SCALE < U128_MOD ∧ ρ = .inl (a * b) ∨ U128_MOD ≀ a.1.val * b.1.val / Wad.WAD_SCALE ∧ ρ.isRight aegis_prove "wadray::wadray_signed::SignedWadMul::mul" := fun _ _ (a b : SignedWad) _ (ρ : SignedWad βŠ• _) => by unfold Β«spec_wadray::wadray_signed::SignedWadMul::mulΒ» rintro ⟨va,sa,vb,sb,_,_,_,rfl,rfl,h₁,hβ‚‚βŸ© rcases h₁ with (⟨h₁,rfl⟩|⟨h₁,h₁'⟩) Β· simp only [Sum.inl.injEq, false_and, or_false] at hβ‚‚ rcases hβ‚‚ with ⟨rfl,rfl⟩ simp [h₁, SignedWad.mul_def, Wad.mul, Wad.toZMod] Β· rcases hβ‚‚ with (⟨rfl,rfl⟩|⟨rfl,rfl⟩) Β· simp at h₁' Β· simp [h₁] aegis_spec "wadray::wadray_signed::SignedRayMul::mul" := fun _ _ (a b : SignedRay) _ (ρ : SignedRay βŠ• _) => a.1.val * b.1.val / Ray.RAY_SCALE < U128_MOD ∧ ρ = .inl (a * b) ∨ U128_MOD ≀ a.1.val * b.1.val / Ray.RAY_SCALE ∧ ρ.isRight aegis_prove "wadray::wadray_signed::SignedRayMul::mul" := fun _ _ (a b : SignedRay) _ (ρ : SignedRay βŠ• _) => by unfold Β«spec_wadray::wadray_signed::SignedRayMul::mulΒ» rintro ⟨va,sa,vb,sb,_,_,_,rfl,rfl,h₁,hβ‚‚βŸ© rcases h₁ with (⟨h₁,rfl⟩|⟨h₁,h₁'⟩) Β· simp only [Sum.inl.injEq, false_and, or_false] at hβ‚‚ rcases hβ‚‚ with ⟨rfl,rfl⟩ simp [h₁, SignedRay.mul_def, Ray.mul, Ray.toZMod] Β· rcases hβ‚‚ with (⟨rfl,rfl⟩|⟨rfl,rfl⟩) Β· simp at h₁' Β· simp [h₁] aegis_spec "wadray::wadray_signed::SignedWadMulEq::mul_eq" := fun _ _ (a b : SignedWad) _ (ρ : SignedWad Γ— Unit βŠ• _) => a.1.val * b.1.val / Wad.WAD_SCALE < U128_MOD ∧ ρ = .inl (a * b, ()) ∨ U128_MOD ≀ a.1.val * b.1.val / Wad.WAD_SCALE ∧ ρ.isRight aegis_prove "wadray::wadray_signed::SignedWadMulEq::mul_eq" := fun _ _ (a b : SignedWad) _ (ρ : SignedWad Γ— Unit βŠ• _) => by unfold Β«spec_wadray::wadray_signed::SignedWadMulEq::mul_eqΒ» rename_i x x_1 x_2 intro h_auto aesop aegis_spec "wadray::wadray_signed::SignedWadDiv::div" := fun _ _ (a b : SignedWad) _ (ρ : SignedWad βŠ• _) => a.1.val * Wad.WAD_SCALE / b.1.val < U128_MOD ∧ b.1.val β‰  0 ∧ ρ = .inl (a / b) ∨ (U128_MOD ≀ a.1.val * Wad.WAD_SCALE / b.1.val ∨ b.1.val = 0) ∧ ρ.isRight aegis_prove "wadray::wadray_signed::SignedWadDiv::div" := fun _ _ (a b : SignedWad) _ (ρ : SignedWad βŠ• _) => by unfold Β«spec_wadray::wadray_signed::SignedWadDiv::divΒ» rintro ⟨va,sa,vb,sb,_,_,_,rfl,rfl,h₁,hβ‚‚βŸ© rcases h₁ with (⟨h₁,hne,rfl⟩|⟨h₁,h₁'⟩) Β· simp only [Sum.inl.injEq, false_and, or_false] at hβ‚‚ rcases hβ‚‚ with ⟨rfl,rfl⟩ simp_all [h₁, Wad.toZMod, SignedWad.div_def, Wad.div, Wad.div_def] Β· rcases hβ‚‚ with (⟨rfl,rfl⟩|⟨rfl,rfl⟩) Β· simp at h₁' Β· simp_all [Wad.toZMod] aegis_spec "wadray::wadray_signed::SignedRayDiv::div" := fun _ _ (a b : SignedRay) _ (ρ : SignedRay βŠ• _) => a.1.val * Ray.RAY_SCALE / b.1.val < U128_MOD ∧ b.1.val β‰  0 ∧ ρ = .inl (a / b) ∨ (U128_MOD ≀ a.1.val * Ray.RAY_SCALE / b.1.val ∨ b.1.val = 0) ∧ ρ.isRight aegis_prove "wadray::wadray_signed::SignedRayDiv::div" := fun _ _ (a b : SignedRay) _ (ρ : SignedRay βŠ• _) => by unfold Β«spec_wadray::wadray_signed::SignedRayDiv::divΒ» rintro ⟨va,sa,vb,sb,_,_,_,rfl,rfl,h₁,hβ‚‚βŸ© rcases h₁ with (⟨h₁,hne,rfl⟩|⟨h₁,h₁'⟩) Β· simp only [Sum.inl.injEq, false_and, or_false] at hβ‚‚ rcases hβ‚‚ with ⟨rfl,rfl⟩ simp_all [h₁, Ray.toZMod, SignedRay.div_def, Ray.div, Ray.div_def] Β· rcases hβ‚‚ with (⟨rfl,rfl⟩|⟨rfl,rfl⟩) Β· simp at h₁' Β· simp_all [Ray.toZMod] aegis_spec "wadray::wadray_signed::SignedWadDivEq::div_eq" := fun _ _ (a b : SignedWad) _ (ρ : SignedWad Γ— Unit βŠ• _) => a.1.val * Wad.WAD_SCALE / b.1.val < U128_MOD ∧ b.1.val β‰  0 ∧ ρ = .inl (a / b, ()) ∨ (U128_MOD ≀ a.1.val * Wad.WAD_SCALE / b.1.val ∨ b.1.val = 0) ∧ ρ.isRight aegis_prove "wadray::wadray_signed::SignedWadDivEq::div_eq" := fun _ _ (a b : SignedWad) _ (ρ : SignedWad Γ— Unit βŠ• _) => by unfold Β«spec_wadray::wadray_signed::SignedWadDivEq::div_eqΒ» rename_i x x_1 x_2 intro h_auto aesop aegis_spec "wadray::wadray_signed::U128IntoSignedWad::into" := fun _ a (ρ : SignedWad) => ρ = ⟨a, Bool.toSierraBool .false⟩ aegis_prove "wadray::wadray_signed::U128IntoSignedWad::into" := fun _ a (ρ : SignedWad) => by rintro rfl rfl aegis_spec "wadray::wadray_signed::U128IntoSignedRay::into" := fun _ a (ρ : SignedRay) => ρ = ⟨a, Bool.toSierraBool .false⟩ aegis_prove "wadray::wadray_signed::U128IntoSignedRay::into" := fun _ a (ρ : SignedRay) => by rintro rfl rfl aegis_spec "wadray::wadray_signed::WadIntoSignedWad::into" := fun _ (a : Wad) (ρ : SignedWad) => ρ = ⟨a, Bool.toSierraBool .false⟩ aegis_prove "wadray::wadray_signed::WadIntoSignedWad::into" := fun _ (a : Wad) (ρ : SignedWad) => by rintro rfl rfl aegis_spec "wadray::wadray_signed::RayIntoSignedRay::into" := fun _ (a : Ray) (ρ : SignedRay) => ρ = ⟨a, Bool.toSierraBool .false⟩ aegis_prove "wadray::wadray_signed::RayIntoSignedRay::into" := fun _ (a : Ray) (ρ : SignedRay) => by rintro rfl rfl aegis_spec "wadray::wadray_signed::WadIntoSignedRay::into" := fun _ _ (a : Wad) _ (ρ : SignedRay βŠ• _) => if a.toZMod.val * Ray.DIFF < U128_MOD then ρ = .inl ⟨a.toZMod * Ray.DIFF, Bool.toSierraBool .false⟩ else ρ.isRight aegis_prove "wadray::wadray_signed::WadIntoSignedRay::into" := fun _ _ (a : Wad) _ (ρ : SignedRay βŠ• _) => by unfold Β«spec_wadray::wadray_signed::WadIntoSignedRay::intoΒ» rintro ⟨_,_,_,h₁,hβ‚‚βŸ© aesop
3
104
false
Applied verif.
482
RAY_SCALE_val
theorem RAY_SCALE_val : (1000000000000000000000000000 : UInt128).val = 1000000000000000000000000000 := rfl aegis_spec "wadray::wadray::u128_rmul"
wadray_verification
WadrayVerification/Wadray.lean
[ "import WadrayVerification.Load", "import WadrayVerification.Aux", "import CorelibVerification" ]
[ { "name": "Sierra.UInt128", "module": "Aegis.Types" }, { "name": "SierraBool.toBool", "module": "Aegis.Aux.Bool" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Bool.toSierraBool", "module": "Aegis.Aux.Bool" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "List", "module": "Init.Prelude" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Prod", "module": "Init.Prelude" }, { "name": "Prod.mk", "module": "Init.Prelude" }, { "name": "Sierra.U128_MOD", "module": "Aegis.Types" }, { "name": "Sierra.U256_MOD", "module": "CorelibVerification.Aux.UInt256" }, { "name": "Sierra.aegis_prove", "module": "Aegis.Commands" }, { "name": "Sum", "module": "Init.Core" }, { "name": "Sum.inl", "module": "Init.Core" }, { "name": "Sum.inr", "module": "Init.Core" }, { "name": "ZMod", "module": "Mathlib.Data.ZMod.Defs" }, { "name": "ZMod.ndiv", "module": "Aegis.Aux.ZMod.DivMod" }, { "name": "ZMod.val", "module": "Mathlib.Data.ZMod.Basic" }, { "name": "sierra_simp'", "module": "CorelibVerification.Corelib.Integer" }, { "name": "Unit", "module": "Init.Prelude" }, { "name": "Bool.xor", "module": "Init.Data.Bool" } ]
[ { "name": "RAY_SCALE", "content": "def RAY_SCALE : β„• := 1000000000000000000000000000" }, { "name": "add", "content": "protected def add : Ray := r.toZMod + r'.toZMod" }, { "name": "toZMod", "content": "protected def toZMod : UInt128 := r" }, { "name": "Ray", "content": "def Ray : Type := UInt128" }, { "name": "toRat", "content": "protected def toRat : β„š := w.toZMod.val / WAD_SCALE" }, { "name": "WAD_SCALE", "content": "def WAD_SCALE : β„• := 1000000000000000000" }, { "name": "toRat", "content": "protected def toRat : β„š := r.toZMod.val / RAY_SCALE" }, { "name": "Wad.toRay", "content": "def Wad.toRay (w : Wad) : Ray := w.toZMod * (Ray.DIFF : UInt128)" }, { "name": "DIFF", "content": "def DIFF : β„• := 1000000000" }, { "name": "toZMod", "content": "protected def toZMod : UInt128 := w" }, { "name": "toRat", "content": "def toRat : β„š := if SierraBool.toBool w.2 then -(Ray.toRat w.1) else Ray.toRat w.1" }, { "name": "sub", "content": "protected def sub : Ray := r.toZMod - r'.toZMod" }, { "name": "ofZMod", "content": "protected def ofZMod (a : UInt128) : Ray := a" }, { "name": "Wad.MAX_CONVERTIBLE_WAD", "content": "def Wad.MAX_CONVERTIBLE_WAD : β„• := 340282366920938463463374607431" }, { "name": "ofZMod", "content": "protected def ofZMod (a : UInt128) : Wad := a" }, { "name": "Wad", "content": "def Wad : Type := UInt128" }, { "name": "toWad", "content": "def toWad : Wad := r.toZMod.ndiv DIFF" }, { "name": "toRat", "content": "def toRat : β„š := if w.2 then -(Wad.toRat w.1) else Wad.toRat w.1" }, { "name": "SignedWad", "content": "def SignedWad := UInt128 Γ— (Unit βŠ• Unit)" }, { "name": "SignedRay", "content": "def SignedRay := UInt128 Γ— (Unit βŠ• Unit)" }, { "name": "mul", "content": "protected def mul : Ray := (r.toZMod.val * r'.toZMod.val / RAY_SCALE : UInt128)" }, { "name": "mul", "content": "protected def mul : Wad := (w.toZMod.val * w'.toZMod.val / WAD_SCALE : UInt128)" }, { "name": "div", "content": "protected def div : Ray := (r.toZMod.val * RAY_SCALE / r'.toZMod.val : UInt128)" }, { "name": "div", "content": "protected def div : Wad := (w.toZMod.val * WAD_SCALE / w'.toZMod.val : UInt128)" } ]
[ { "name": "Aesop.BuiltinRules.not_intro", "module": "Aesop.BuiltinRules" }, { "name": "Bool.false_eq_true", "module": "Init.Data.Bool" }, { "name": "Int.cast_ofNat", "module": "Mathlib.Data.Int.Cast.Basic" }, { "name": "Int.ofNat_eq_coe", "module": "Init.Data.Int.Basic" }, { "name": "List.nil_append", "module": "Init.Data.List.Basic" }, { "name": "Nat.cast_ofNat", "module": "Mathlib.Data.Nat.Cast.Defs" }, { "name": "Nat.div_le_div_left", "module": "Init.Data.Nat.Div.Lemmas" }, { "name": "Nat.div_le_div_right", "module": "Init.Data.Nat.Lemmas" }, { "name": "Nat.eq_zero_of_mul_lt_right", "module": "CorelibVerification.Aux.ZMod" }, { "name": "Nat.lt_of_add_lt", "module": "CorelibVerification.Aux.ZMod" }, { "name": "Nat.mul_le_mul_right", "module": "Init.Data.Nat.Basic" }, { "name": "Nat.pos_of_ne_zero", "module": "Init.Data.Nat.Basic" }, { "name": "Sierra.U256_MOD_div", "module": "CorelibVerification.Aux.UInt256" }, { "name": "Sum.isRight_inl", "module": "Init.Data.Sum.Basic" }, { "name": "Sum.isRight_inr", "module": "Init.Data.Sum.Basic" }, { "name": "ZMod.cast_rat_eq_zero_iff", "module": "CorelibVerification.Aux.ZMod" }, { "name": "ZMod.intCast_zmod_eq_zero_iff_dvd", "module": "Mathlib.Data.ZMod.Basic" }, { "name": "ZMod.natCast_zmod_val", "module": "Mathlib.Data.ZMod.Basic" }, { "name": "ZMod.val_eq_zero", "module": "Mathlib.Data.ZMod.Basic" }, { "name": "ZMod.val_injective", "module": "Mathlib.Data.ZMod.Basic" }, { "name": "ZMod.val_mul_val_eq_hmul", "module": "CorelibVerification.Aux.ZMod" }, { "name": "ZMod.val_zero", "module": "Mathlib.Data.ZMod.Basic" }, { "name": "add_zero", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "and_false", "module": "Init.SimpLemmas" }, { "name": "and_true", "module": "Init.SimpLemmas" }, { "name": "exists_and_left", "module": "Init.PropLemmas" }, { "name": "exists_and_right", "module": "Init.PropLemmas" }, { "name": "exists_const", "module": "Init.PropLemmas" }, { "name": "exists_eq_left", "module": "Init.PropLemmas" }, { "name": "exists_eq_left'", "module": "Init.PropLemmas" }, { "name": "exists_false", "module": "Init.PropLemmas" }, { "name": "false_and", "module": "Init.SimpLemmas" }, { "name": "false_or", "module": "Init.SimpLemmas" }, { "name": "le_of_lt", "module": "Mathlib.Order.Defs.PartialOrder" }, { "name": "le_trans", "module": "Mathlib.Order.Defs.PartialOrder" }, { "name": "mul_comm", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "ne_eq", "module": "Init.SimpLemmas" }, { "name": "not_true", "module": "Init.Core" }, { "name": "or_false", "module": "Init.SimpLemmas" }, { "name": "true_and", "module": "Init.SimpLemmas" }, { "name": "zero_add", "module": "Mathlib.Algebra.Group.Defs" } ]
[ { "name": "toRat_lt_toRat_of_val_lt_val", "content": "theorem toRat_lt_toRat_of_val_lt_val (h : @ZMod.val U128_MOD r < @ZMod.val U128_MOD r') :\n r.toRat < r'.toRat" }, { "name": "RAY_SCALE_rat_pos", "content": "theorem RAY_SCALE_rat_pos : 0 < (RAY_SCALE : β„š)" }, { "name": "toRat_lt_toRat_of_val_lt_val", "content": "theorem toRat_lt_toRat_of_val_lt_val (h : @ZMod.val U128_MOD w < @ZMod.val U128_MOD w') :\n w.toRat < w'.toRat" }, { "name": "WAD_SCALE_rat_pos", "content": "theorem WAD_SCALE_rat_pos : 0 < (WAD_SCALE : β„š)" }, { "name": "toRat_le_toRat_of_val_le_val", "content": "theorem toRat_le_toRat_of_val_le_val (h : @ZMod.val U128_MOD r ≀ @ZMod.val U128_MOD r') :\n r.toRat ≀ r'.toRat" }, { "name": "toRat_le_toRat_of_val_le_val", "content": "theorem toRat_le_toRat_of_val_le_val (h : @ZMod.val U128_MOD w ≀ @ZMod.val U128_MOD w') :\n w.toRat ≀ w'.toRat" }, { "name": "zero_def", "content": "theorem zero_def : (0 : SignedWad) = (0, false.toSierraBool)" }, { "name": "zero_def", "content": "theorem zero_def : (0 : SignedRay) = (0, false.toSierraBool)" }, { "name": "mul_def", "content": "protected theorem mul_def :\n r * r' = (r.toZMod.val * r'.toZMod.val / RAY_SCALE : UInt128)" }, { "name": "mul_def", "content": "theorem mul_def :\n w₁ * wβ‚‚ = ⟨Ray.mul w₁.1 wβ‚‚.1, Bool.toSierraBool (Bool.xor (SierraBool.toBool w₁.2) (SierraBool.toBool wβ‚‚.2))⟩" }, { "name": "mul_def", "content": "protected theorem mul_def :\n w * w' = (w.toZMod.val * w'.toZMod.val / WAD_SCALE : UInt128)" }, { "name": "div_def", "content": "protected theorem div_def :\n r / r' = (r.toZMod.val * RAY_SCALE / r'.toZMod.val : UInt128)" }, { "name": "mul_def", "content": "theorem mul_def :\n w₁ * wβ‚‚ = ⟨Wad.mul (w₁.1 : Wad) (wβ‚‚.1 : Wad), Bool.toSierraBool (Bool.xor (SierraBool.toBool w₁.2) (SierraBool.toBool wβ‚‚.2))⟩" }, { "name": "div_def", "content": "protected theorem div_def :\n w / w' = (w.toZMod.val * WAD_SCALE / w'.toZMod.val : UInt128)" }, { "name": "div_def", "content": "theorem div_def :\n w₁ / wβ‚‚ = ⟨Ray.div (w₁.1 : Ray) (wβ‚‚.1 : Ray), Bool.toSierraBool (Bool.xor (SierraBool.toBool w₁.2) (SierraBool.toBool wβ‚‚.2))⟩" }, { "name": "RAY_SCALE_pos", "content": "theorem RAY_SCALE_pos : 0 < RAY_SCALE" }, { "name": "div_def", "content": "theorem div_def :\n w₁ / wβ‚‚ = ⟨Wad.div (w₁.1 : Wad) (wβ‚‚.1 : Wad), Bool.toSierraBool (Bool.xor (SierraBool.toBool w₁.2) (SierraBool.toBool wβ‚‚.2))⟩" } ]
[]
[ { "name": "Bool.toSierraBool_def", "content": "theorem Bool.toSierraBool_def (b : Bool) : b.toSierraBool = if b then .inr () else .inl ()" } ]
import CorelibVerification import WadrayVerification.Aux import WadrayVerification.Load open Sierra
theorem RAY_SCALE_val : (1000000000000000000000000000 : UInt128).val = 1000000000000000000000000000 :=
:= rfl aegis_spec "wadray::wadray::u128_rmul" := fun _ _ a b _ ρ => (a.val * b.val / Ray.RAY_SCALE < U128_MOD ∧ ρ = .inl (a.val * b.val / Ray.RAY_SCALE)) ∨ (U128_MOD ≀ a.val * b.val / Ray.RAY_SCALE ∧ ρ.isRight) aegis_prove "wadray::wadray::u128_rmul" := fun _ _ a b _ ρ => by unfold Β«spec_wadray::wadray::u128_rmulΒ» sierra_simp' rintro ⟨_,(⟨h₁,rfl⟩|⟨h₁,h₁'⟩),hβ‚‚βŸ© Β· simp only [UInt256.val, ZMod.val_zero, mul_zero, zero_add] at h₁ rcases hβ‚‚ with (⟨_,_,hβ‚‚,h₃,hβ‚„βŸ©|hβ‚‚) Β· injection hβ‚‚ with hβ‚‚; subst hβ‚‚ rcases h₃ with (⟨_,_,rfl,hβ‚…βŸ©|⟨h₃,_⟩) Β· rcases hβ‚„ with (⟨⟨wβ‚—,wβ‚•βŸ©,v,hβ‚„,h₆,hβ‚‡βŸ©|hβ‚„) Β· injection hβ‚„ with hβ‚„; subst hβ‚„ simp [UInt256.val, UInt256.mul_def, ← ZMod.val_mul_val_eq_hmul] at hβ‚… -- TODO rw [UInt256.val_lt_U128_MOD_iff, UInt256.U128_MOD_le_val_iff] at h₆ rcases h₆ with (⟨rfl,rfl⟩|⟨h₆,rfl⟩) Β· rw [ZMod.val_zero, mul_zero, zero_add] at hβ‚… simp only [Sum.inl.injEq, exists_eq_left, Nat.cast_ofNat, Int.cast_ofNat, List.nil_append, false_and, exists_const, or_false] at h₇; cases h₇ erw [← hβ‚…] simp only [wβ‚—.val_lt, Sum.inl.injEq, true_and, Sum.isRight_inl, and_false, or_false] rw [@ZMod.natCast_zmod_val] Β· simp only [false_and, exists_const, Nat.cast_ofNat, Int.cast_ofNat, List.nil_append, true_and, false_or] at h₇; cases h₇ rw [← UInt256.U128_MOD_le_val_iff] at h₆ erw [← hβ‚…] refine .inr ⟨h₆, ?_⟩ simp Β· simp only [false_and, exists_false] at hβ‚„ Β· injection h₃ with h₃ rw [ZMod.intCast_zmod_eq_zero_iff_dvd] at h₃ norm_num[U128_MOD] at h₃ Β· simp at hβ‚‚ Β· simp only [UInt256.val, ZMod.val_zero, mul_zero, zero_add] at h₁ right constructor Β· rw [Nat.le_div_iff_mul_le' Ray.RAY_SCALE_pos] apply le_trans _ h₁ norm_num [U128_MOD, Ray.RAY_SCALE, U256_MOD] Β· aesop aegis_spec "wadray::wadray::rmul" := fun _ _ (a b : Ray) _ (ρ : Ray βŠ• _) => (a.toZMod.val * b.toZMod.val / Ray.RAY_SCALE < U128_MOD ∧ ρ = .inl (a * b)) ∨ (U128_MOD ≀ a.toZMod.val * b.toZMod.val / Ray.RAY_SCALE ∧ ρ.isRight) aegis_prove "wadray::wadray::rmul" := fun _ _ (a b : Ray) _ (ρ : Ray βŠ• _) => by unfold Β«spec_wadray::wadray::rmulΒ» sierra_simp' aesop aegis_spec "wadray::wadray::WadSub::sub" := fun _ _ (a b : Wad) _ (ρ : Wad βŠ• _) => (b.toRat ≀ a.toRat ∧ ρ = .inl (a - b)) ∨ (a.toRat < b.toRat ∧ ρ.isRight) aegis_prove "wadray::wadray::WadSub::sub" := fun _ _ (a b : Wad) _ (ρ : Wad βŠ• _) => by unfold Β«spec_wadray::wadray::WadSub::subΒ» aesop (add safe forward [Wad.toRat_le_toRat_of_val_le_val, Wad.toRat_lt_toRat_of_val_lt_val]) aegis_spec "wadray::wadray::WadAdd::add" := fun _ _ (a b : Wad) _ (ρ : Wad βŠ• _) => (a.toZMod.val + b.toZMod.val < U128_MOD ∧ ρ = .inl (a + b)) ∨ (U128_MOD ≀ a.toZMod.val + b.toZMod.val ∧ ρ.isRight) aegis_prove "wadray::wadray::WadAdd::add" := fun _ _ (a b : Wad) _ (ρ : Wad βŠ• _) => by unfold Β«spec_wadray::wadray::WadAdd::addΒ» aesop aegis_spec "wadray::wadray::RaySub::sub" := fun _ _ (a b : Ray) _ (ρ : Ray βŠ• _) => (b.toRat ≀ a.toRat ∧ ρ = .inl (a - b)) ∨ (a.toRat < b.toRat ∧ ρ.isRight) aegis_prove "wadray::wadray::RaySub::sub" := fun _ _ (a b : Ray) _ (ρ : Ray βŠ• _) => by unfold Β«spec_wadray::wadray::RaySub::subΒ» aesop (add safe forward [Ray.toRat_le_toRat_of_val_le_val, Ray.toRat_lt_toRat_of_val_lt_val]) aegis_spec "wadray::wadray::RayAdd::add" := fun _ _ (a b : Ray) _ (ρ : Ray βŠ• _) => (a.toZMod.val + b.toZMod.val < U128_MOD ∧ ρ = .inl (a + b)) ∨ (U128_MOD ≀ a.toZMod.val + b.toZMod.val ∧ ρ.isRight) aegis_prove "wadray::wadray::RayAdd::add" := fun _ _ (a b : Ray) _ (ρ : Ray βŠ• _) => by unfold Β«spec_wadray::wadray::RayAdd::addΒ» aesop aegis_spec "wadray::wadray::WadZeroable::is_non_zero" := fun _ (a : Wad) ρ => ρ = Bool.toSierraBool (a.toRat β‰  0) aegis_prove "wadray::wadray::WadZeroable::is_non_zero" := fun _ (a : Wad) ρ => by unfold Β«spec_wadray::wadray::WadZeroable::is_non_zeroΒ» aesop (add simp norm [Wad.toRat, Wad.toZMod, ZMod.cast_rat_eq_zero_iff]) aegis_spec "wadray::wadray::WadZeroable::is_zero" := fun _ (a : Wad) ρ => ρ = Bool.toSierraBool (a.toRat = 0) aegis_prove "wadray::wadray::WadZeroable::is_zero" := fun _ (a : Wad) ρ => by unfold Β«spec_wadray::wadray::WadZeroable::is_zeroΒ» aesop (add simp norm [Bool.toSierraBool_def, Wad.toRat, ZMod.cast_rat_eq_zero_iff, Wad.toZMod]) aegis_spec "wadray::wadray::RayZeroable::is_zero" := fun _ (a : Ray) ρ => ρ = Bool.toSierraBool (a.toRat = 0) aegis_prove "wadray::wadray::RayZeroable::is_zero" := fun _ (a : Ray) ρ => by unfold Β«spec_wadray::wadray::RayZeroable::is_zeroΒ» aesop (add simp norm [Bool.toSierraBool_def, Ray.toRat, ZMod.cast_rat_eq_zero_iff, Ray.toZMod]) aegis_spec "wadray::wadray::RayZeroable::is_non_zero" := fun _ (a : Ray) ρ => ρ = Bool.toSierraBool (a.toRat β‰  0) aegis_prove "wadray::wadray::RayZeroable::is_non_zero" := fun _ (a : Ray) ρ => by unfold Β«spec_wadray::wadray::RayZeroable::is_non_zeroΒ» aesop (add simp norm [Ray.toRat, Ray.toZMod, ZMod.cast_rat_eq_zero_iff]) aegis_spec "wadray::wadray::BoundedWad::min" := fun _ ρ => ρ = 0 aegis_prove "wadray::wadray::BoundedWad::min" := fun _ ρ => by rintro rfl rfl aegis_spec "wadray::wadray::BoundedRay::min" := fun _ ρ => ρ = 0 aegis_prove "wadray::wadray::BoundedRay::min" := fun _ ρ => by rintro rfl rfl aegis_spec "wadray::wadray::BoundedWad::max" := fun _ ρ => ρ = U128_MOD - 1 aegis_prove "wadray::wadray::BoundedWad::max" := fun _ ρ => by rintro rfl rfl aegis_spec "wadray::wadray::BoundedRay::max" := fun _ ρ => ρ = U128_MOD - 1 aegis_prove "wadray::wadray::BoundedRay::max" := fun _ ρ => by rintro rfl rfl aegis_spec "wadray::wadray::WadAddEq::add_eq" := fun _ _ (a b : Wad) _ (ρ : Wad Γ— _ βŠ• _) => (a.toZMod.val + b.toZMod.val < U128_MOD ∧ ρ = .inl (a + b, ())) ∨ (U128_MOD ≀ a.toZMod.val + b.toZMod.val ∧ ρ.isRight) aegis_prove "wadray::wadray::WadAddEq::add_eq" := fun _ _ (a b : Wad) _ (ρ : Wad Γ— _ βŠ• _) => by unfold Β«spec_wadray::wadray::WadAddEq::add_eqΒ» aesop aegis_spec "wadray::wadray::WadSubEq::sub_eq" := fun _ _ (a b : Wad) _ (ρ : Wad Γ— _ βŠ• _) => (b.toRat ≀ a.toRat ∧ ρ = .inl (a - b, ())) ∨ (a.toRat < b.toRat ∧ ρ.isRight) aegis_prove "wadray::wadray::WadSubEq::sub_eq" := fun _ _ (a b : Wad) _ (ρ : Wad Γ— _ βŠ• _) => by unfold Β«spec_wadray::wadray::WadSubEq::sub_eqΒ» aesop aegis_spec "wadray::wadray::WadMulEq::mul_eq" := fun _ _ (a b : Wad) _ (ρ : Wad Γ— _ βŠ• _) => (a.toZMod.val * b.toZMod.val / Wad.WAD_SCALE < U128_MOD ∧ ρ = .inl (a * b, ())) ∨ (U128_MOD ≀ a.toZMod.val * b.toZMod.val / Wad.WAD_SCALE ∧ ρ.isRight) aegis_prove "wadray::wadray::WadMulEq::mul_eq" := fun _ _ (a b : Wad) _ (ρ : Wad Γ— _ βŠ• _) => by unfold Β«spec_wadray::wadray::WadMulEq::mul_eqΒ» aesop aegis_spec "wadray::wadray::TIntoWad<core::integer::u128, core::traits::TIntoT<core::integer::u128>>::into" := fun _ a (ρ : Wad) => ρ = a aegis_prove "wadray::wadray::TIntoWad<core::integer::u128, core::traits::TIntoT<core::integer::u128>>::into" := fun _ a (ρ : Wad) => by unfold Β«spec_wadray::wadray::TIntoWad<core::integer::u128, core::traits::TIntoT<core::integer::u128>>::intoΒ» aesop aegis_spec "wadray::wadray::TIntoRay<core::integer::u128, core::traits::TIntoT<core::integer::u128>>::into" := fun _ a (ρ : Ray) => ρ = a aegis_prove "wadray::wadray::TIntoRay<core::integer::u128, core::traits::TIntoT<core::integer::u128>>::into" := fun _ a (ρ : Ray) => by unfold Β«spec_wadray::wadray::TIntoRay<core::integer::u128, core::traits::TIntoT<core::integer::u128>>::intoΒ» aesop aegis_spec "wadray::wadray::u128_wdiv" := fun _ _ (a b : Wad) _ (ρ : Wad βŠ• _) => a.toZMod.val * Wad.WAD_SCALE / b.toZMod.val < U128_MOD ∧ b.toZMod.val β‰  0 ∧ ρ = .inl (a / b) ∨ (U128_MOD ≀ a.toZMod.val * Wad.WAD_SCALE / b.toZMod.val ∨ b.toZMod.val = 0) ∧ ρ.isRight aegis_prove "wadray::wadray::u128_wdiv" := fun _ _ (a b : Wad) _ (ρ : Wad βŠ• _) => by sierra_simp' unfold Β«spec_wadray::wadray::u128_wdivΒ» rintro ⟨(x|x),h₁,hβ‚‚βŸ© Β· simp_all only [Nat.cast_ofNat, Int.cast_ofNat, Sum.inl.injEq, Sum.isRight_inl, Bool.false_eq_true, and_false, or_false, ne_eq, exists_and_left, List.nil_append, exists_and_right, Sum.exists, exists_eq_left, exists_const, false_and, and_true, false_or, true_and, Prod.exists, exists_eq_left', Prod.mk.injEq, Sum.isRight_inr, Sum.inr.injEq, UInt256.val_mul_of_low, ZMod.val_eq_zero] rcases h₁ with ⟨h₁,rfl⟩ simp only [UInt256.val, ZMod.val_zero, mul_zero, zero_add] at h₁ rcases hβ‚‚ with (⟨_,_,⟨hβ‚‚,hβ‚„βŸ©,_,_,⟨rfl,rfl⟩,hβ‚ƒβŸ©|⟨hβ‚‚,_,_,rfl⟩) Β· simp [hβ‚„, UInt256.val] at h₃ simp only [UInt256.val, ZMod.val_zero, mul_zero, zero_add, UInt256.mul_def, mul_zero, add_zero, zero_mul] at hβ‚„ rcases ρ with (ρ|ρ) Β· simp only [Sum.inl.injEq, Sum.isRight_inl, and_false, or_false] at h₃ ⊒ rcases h₃ with ⟨_,⟨h₃,rfl⟩,rfl⟩ refine ⟨?_,?_,?_⟩ Β· rwa [hβ‚„] at h₃ Β· simp only [UInt256.zero_def] at hβ‚‚ simp only [Wad.toZMod] apply Aesop.BuiltinRules.not_intro intro h subst h simp_all only [not_true] Β· simp only [Wad.div_def, Wad.WAD_SCALE] erw [← hβ‚„]; clear hβ‚„ simp [Nat.eq_zero_of_mul_lt_right (Nat.lt_of_add_lt h₃)] Β· simp only [and_false, exists_false, Sum.inr.injEq, false_or] at h₃ simp only [and_false, Sum.isRight_inr, and_true, false_or] left rcases h₃ with ⟨h₃,rfl⟩ rwa [hβ‚„] at h₃ Β· simp only [and_false, Sum.isRight_inr, and_true, false_or] right injection hβ‚‚ Β· simp_all only [Nat.cast_ofNat, Int.cast_ofNat, and_false, Sum.isRight_inr, and_true, false_or, ne_eq, exists_and_left, List.nil_append, exists_and_right, Sum.exists, Sum.inl.injEq, or_false, exists_eq_left, exists_const, false_and, true_and, Prod.exists, Sum.inr.injEq, ZMod.val_eq_zero] subst hβ‚‚ simp only [and_false, Sum.isRight_inr, and_true, false_or] by_cases h₃ : b.toZMod.val = 0 Β· right rwa [ZMod.val_eq_zero] at h₃ Β· left conv => lhs; rw [← U256_MOD_div] trans; apply Nat.div_le_div_left (le_of_lt b.toZMod.val_lt) (Nat.pos_of_ne_zero h₃) simp only [UInt256.val, ZMod.val_zero, mul_zero, zero_add] at h₁ apply Nat.div_le_div_right h₁ aegis_spec "wadray::wadray::u128_rdiv" := fun _ _ (a b : Ray) _ (ρ : Ray βŠ• _) => (a.toZMod.val * Ray.RAY_SCALE / b.toZMod.val < U128_MOD ∧ b.toZMod.val β‰  0 ∧ ρ = .inl (a / b)) ∨ ((U128_MOD ≀ a.toZMod.val * Ray.RAY_SCALE / b.toZMod.val ∨ b.toZMod.val = 0) ∧ ρ.isRight) aegis_prove "wadray::wadray::u128_rdiv" := fun _ _ (a b : Ray) _ (ρ : Ray βŠ• _) => by sierra_simp' unfold Β«spec_wadray::wadray::u128_rdivΒ» rintro ⟨(x|x),h₁,hβ‚‚βŸ© Β· simp_all only [Nat.cast_ofNat, Int.cast_ofNat, Sum.inl.injEq, Sum.isRight_inl, Bool.false_eq_true, and_false, or_false, ne_eq, exists_and_left, List.nil_append, exists_and_right, Sum.exists, exists_eq_left, exists_const, false_and, and_true, false_or, true_and, Prod.exists, exists_eq_left', Prod.mk.injEq, Sum.isRight_inr, Sum.inr.injEq, UInt256.val_mul_of_low, ZMod.val_eq_zero] rcases h₁ with ⟨h₁,rfl⟩ simp only [UInt256.val, ZMod.val_zero, mul_zero, zero_add] at h₁ rcases hβ‚‚ with (⟨_,_,⟨hβ‚‚,hβ‚„βŸ©,_,_,⟨rfl,rfl⟩,hβ‚ƒβŸ©|⟨hβ‚‚,_,_,rfl⟩) Β· simp [hβ‚„, UInt256.val] at h₃ simp only [UInt256.val, ZMod.val_zero, mul_zero, zero_add, UInt256.mul_def, mul_zero, add_zero, zero_mul] at hβ‚„ rcases ρ with (ρ|ρ) Β· simp only [Sum.inl.injEq, Sum.isRight_inl, and_false, or_false] at h₃ ⊒ rcases h₃ with ⟨_,⟨h₃,rfl⟩,rfl⟩ refine ⟨?_,?_,?_⟩ Β· rwa [hβ‚„] at h₃ Β· simp only [UInt256.zero_def] at hβ‚‚ simp only [Ray.toZMod] apply Aesop.BuiltinRules.not_intro intro h subst h simp_all only [not_true] Β· simp only [Ray.div_def, Ray.RAY_SCALE] erw [← hβ‚„]; clear hβ‚„ simp [Nat.eq_zero_of_mul_lt_right (Nat.lt_of_add_lt h₃)] Β· simp only [and_false, exists_false, Sum.inr.injEq, false_or] at h₃ simp only [and_false, Sum.isRight_inr, and_true, false_or] left rcases h₃ with ⟨h₃,rfl⟩ rwa [hβ‚„] at h₃ Β· simp only [and_false, Sum.isRight_inr, and_true, false_or] right injection hβ‚‚ Β· simp_all only [Nat.cast_ofNat, Int.cast_ofNat, and_false, Sum.isRight_inr, and_true, false_or, ne_eq, exists_and_left, List.nil_append, exists_and_right, Sum.exists, Sum.inl.injEq, or_false, exists_eq_left, exists_const, false_and, true_and, Prod.exists, Sum.inr.injEq, ZMod.val_eq_zero] subst hβ‚‚ simp only [and_false, Sum.isRight_inr, and_true, false_or] by_cases h₃ : b.toZMod.val = 0 Β· right rwa [ZMod.val_eq_zero] at h₃ Β· left conv => lhs; rw [← U256_MOD_div] trans; apply Nat.div_le_div_left (le_of_lt b.toZMod.val_lt) (Nat.pos_of_ne_zero h₃) simp only [UInt256.val, ZMod.val_zero, mul_zero, zero_add] at h₁ apply Nat.div_le_div_right h₁ aegis_spec "wadray::wadray::wdiv" := fun _ _ (a b : Wad) _ (ρ : Wad βŠ• _) => (a.toZMod.val * Wad.WAD_SCALE / b.toZMod.val < U128_MOD ∧ b.toZMod.val β‰  0 ∧ ρ = .inl (a / b)) ∨ ((U128_MOD ≀ a.toZMod.val * Wad.WAD_SCALE / b.toZMod.val ∨ b.toZMod.val = 0) ∧ ρ.isRight) aegis_prove "wadray::wadray::wdiv" := fun _ _ (a b : Wad) _ (ρ : Wad βŠ• _) => by unfold Β«spec_wadray::wadray::wdivΒ» aesop aegis_spec "wadray::wadray::WadDivEq::div_eq" := fun _ _ (a b : Wad) _ (ρ : (Wad Γ— _) βŠ• _) => (a.toZMod.val * Wad.WAD_SCALE / b.toZMod.val < U128_MOD ∧ b.toZMod.val β‰  0 ∧ ρ = .inl (a / b, ())) ∨ ((U128_MOD ≀ a.toZMod.val * Wad.WAD_SCALE / b.toZMod.val ∨ b.toZMod.val = 0) ∧ ρ.isRight) aegis_prove "wadray::wadray::WadDivEq::div_eq" := fun _ _ (a b : Wad) _ (ρ : (Wad Γ— _) βŠ• _) => by unfold Β«spec_wadray::wadray::WadDivEq::div_eqΒ» aesop aegis_spec "wadray::wadray::rdiv" := fun _ _ (a b : Ray) _ (ρ : Ray βŠ• _) => (a.toZMod.val * Ray.RAY_SCALE / b.toZMod.val < U128_MOD ∧ b.toZMod.val β‰  0 ∧ ρ = .inl (a / b)) ∨ ((U128_MOD ≀ a.toZMod.val * Ray.RAY_SCALE / b.toZMod.val ∨ b.toZMod.val = 0) ∧ ρ.isRight) aegis_prove "wadray::wadray::rdiv" := fun _ _ (a b : Ray) _ (ρ : Ray βŠ• _) => by unfold Β«spec_wadray::wadray::rdivΒ» aesop aegis_spec "wadray::wadray::RayIntoWad::into" := fun _ _ (a : Ray) _ ρ => ρ = .inl a.toWad aegis_prove "wadray::wadray::RayIntoWad::into" := fun _ _ (a : Ray) _ ρ => by unfold Β«spec_wadray::wadray::RayIntoWad::intoΒ» rintro ⟨_,_,_,(h|h),h'⟩ Β· rcases h' with (⟨rfl,rfl⟩|⟨rfl,rfl⟩) Β· rcases h with ⟨_,ρ',h₁,hβ‚‚βŸ© cases h₁ congr simp only [Ray.toWad, ZMod.ndiv, U128_MOD] apply ZMod.val_injective exact hβ‚‚ Β· simp at h Β· rcases h with ⟨h,-⟩ rw [ZMod.intCast_zmod_eq_zero_iff_dvd] at h norm_num [U128_MOD] at h aegis_spec "wadray::wadray::WadIntoU256::into" := fun _ a ρ => ρ = (a, 0) aegis_prove "wadray::wadray::WadIntoU256::into" := fun _ a ρ => by unfold Β«spec_wadray::wadray::WadIntoU256::intoΒ» rintro rfl rfl aegis_spec "wadray::wadray::U256TryIntoWad::try_into" := fun _ (a : UInt256) ρ => (a.val < U128_MOD ∧ ρ = .inl a.1) ∨ (U128_MOD ≀ a.val ∧ ρ = .inr ()) aegis_prove "wadray::wadray::U256TryIntoWad::try_into" := fun _ (a : UInt256) ρ => by unfold Β«spec_wadray::wadray::U256TryIntoWad::try_intoΒ» aesop aegis_spec "wadray::wadray::TIntoRay<core::integer::u64, core::integer::UpcastableInto<core::integer::u64, core::integer::u128, core::integer::UpcastableU64U128>>::into" := fun _ a ρ => ρ = a.cast aegis_prove "wadray::wadray::TIntoRay<core::integer::u64, core::integer::UpcastableInto<core::integer::u64, core::integer::u128, core::integer::UpcastableU64U128>>::into" := fun _ a ρ => by rintro rfl rfl aegis_spec "wadray::wadray::TIntoRay<core::integer::u32, core::integer::UpcastableInto<core::integer::u32, core::integer::u128, core::integer::UpcastableU32U128>>::into" := fun _ a ρ => ρ = a.cast aegis_prove "wadray::wadray::TIntoRay<core::integer::u32, core::integer::UpcastableInto<core::integer::u32, core::integer::u128, core::integer::UpcastableU32U128>>::into" := fun _ a ρ => by rintro rfl rfl aegis_spec "wadray::wadray::TIntoRay<core::integer::u16, core::integer::UpcastableInto<core::integer::u16, core::integer::u128, core::integer::UpcastableU16U128>>::into" := fun _ a ρ => ρ = a.cast aegis_prove "wadray::wadray::TIntoRay<core::integer::u16, core::integer::UpcastableInto<core::integer::u16, core::integer::u128, core::integer::UpcastableU16U128>>::into" := fun _ a ρ => by rintro rfl rfl aegis_spec "wadray::wadray::TIntoRay<core::integer::u8, core::integer::UpcastableInto<core::integer::u8, core::integer::u128, core::integer::UpcastableU8U128>>::into" := fun _ a ρ => ρ = a.cast aegis_prove "wadray::wadray::TIntoRay<core::integer::u8, core::integer::UpcastableInto<core::integer::u8, core::integer::u128, core::integer::UpcastableU8U128>>::into" := fun _ a ρ => by rintro rfl rfl aegis_spec "wadray::wadray::TIntoWad<core::integer::u64, core::integer::UpcastableInto<core::integer::u64, core::integer::u128, core::integer::UpcastableU64U128>>::into" := fun _ a ρ => ρ = a.cast aegis_prove "wadray::wadray::TIntoWad<core::integer::u64, core::integer::UpcastableInto<core::integer::u64, core::integer::u128, core::integer::UpcastableU64U128>>::into" := fun _ a ρ => by rintro rfl rfl aegis_spec "wadray::wadray::TIntoWad<core::integer::u32, core::integer::UpcastableInto<core::integer::u32, core::integer::u128, core::integer::UpcastableU32U128>>::into" := fun _ a ρ => ρ = a.cast aegis_prove "wadray::wadray::TIntoWad<core::integer::u32, core::integer::UpcastableInto<core::integer::u32, core::integer::u128, core::integer::UpcastableU32U128>>::into" := fun _ a ρ => by rintro rfl rfl aegis_spec "wadray::wadray::TIntoWad<core::integer::u16, core::integer::UpcastableInto<core::integer::u16, core::integer::u128, core::integer::UpcastableU16U128>>::into" := fun _ a ρ => ρ = a.cast aegis_prove "wadray::wadray::TIntoWad<core::integer::u16, core::integer::UpcastableInto<core::integer::u16, core::integer::u128, core::integer::UpcastableU16U128>>::into" := fun _ a ρ => by rintro rfl rfl aegis_spec "wadray::wadray::TIntoWad<core::integer::u8, core::integer::UpcastableInto<core::integer::u8, core::integer::u128, core::integer::UpcastableU8U128>>::into" := fun _ a ρ => ρ = a.cast aegis_prove "wadray::wadray::TIntoWad<core::integer::u8, core::integer::UpcastableInto<core::integer::u8, core::integer::u128, core::integer::UpcastableU8U128>>::into" := fun _ a ρ => by rintro rfl rfl aegis_spec "wadray::wadray::WadTryIntoRay::try_into" := fun _ _ (a : Wad) _ (ρ : (Ray βŠ• _) βŠ• _) => ρ = if (a.toZMod.val ≀ Wad.MAX_CONVERTIBLE_WAD) then .inl (.inl a.toRay) else .inl (.inr ()) aegis_prove "wadray::wadray::WadTryIntoRay::try_into" := fun _ _ (a : Wad) _ (ρ : (Ray βŠ• _) βŠ• _) => by unfold Β«spec_wadray::wadray::WadTryIntoRay::try_intoΒ» have h₁ : ZMod.val (340282366920938463463374607431 : UInt128) = Wad.MAX_CONVERTIBLE_WAD := rfl have hβ‚‚ : ZMod.val (1000000000 : UInt128) = 1000000000 := rfl rintro ⟨_,_,_,(h|h)⟩ Β· rcases h with ⟨h₃,(hβ‚„|hβ‚„),hβ‚…βŸ© Β· aesop Β· rcases hβ‚… with (hβ‚…|⟨rfl,rfl⟩) Β· aesop Β· simp only [Int.ofNat_eq_coe, Nat.cast_ofNat, Int.cast_ofNat, Sum.isRight_inr, and_true] at h₃ hβ‚„ rw [hβ‚‚] at hβ‚„ rw [h₁] at h₃ replace hβ‚„ := hβ‚„.trans (Nat.mul_le_mul_right 1000000000 h₃) norm_num [U128_MOD, Wad.MAX_CONVERTIBLE_WAD] at hβ‚„ Β· aesop aegis_spec "wadray::wadray::scale_u128_by_ray" := fun _ _ a (b : Ray) _ ρ => (a.val * b.toZMod.val / Ray.RAY_SCALE < U128_MOD ∧ ρ = .inl (a.val * b.toZMod.val / Ray.RAY_SCALE)) ∨ (U128_MOD ≀ a.val * b.toZMod.val / Ray.RAY_SCALE ∧ ρ.isRight) aegis_prove "wadray::wadray::scale_u128_by_ray" := fun _ _ a (b : Ray) _ ρ => by unfold Β«spec_wadray::wadray::scale_u128_by_rayΒ» aesop aegis_spec "wadray::wadray::div_u128_by_ray" := fun _ _ a (b : Ray) _ ρ => a.val * Ray.RAY_SCALE / b.toZMod.val < U128_MOD ∧ b.toZMod.val β‰  0 ∧ ρ = .inl (a.val * Ray.RAY_SCALE / b.toZMod.val) ∨ (U128_MOD ≀ a.val * Ray.RAY_SCALE / b.toZMod.val ∨ b.toZMod.val = 0) ∧ ρ.isRight aegis_prove "wadray::wadray::div_u128_by_ray" := fun _ _ a (b : Ray) _ ρ => by unfold Β«spec_wadray::wadray::div_u128_by_rayΒ» aesop aegis_spec "wadray::wadray::wmul_wr" := fun _ _ (a : Wad) (b : Ray) _ (ρ : Ray βŠ• _) => a.toZMod.val * b.toZMod.val / Wad.WAD_SCALE < U128_MOD ∧ ρ = .inl (Ray.ofZMod (a.toZMod.val * b.toZMod.val / Wad.WAD_SCALE)) ∨ U128_MOD ≀ a.toZMod.val * b.toZMod.val / Wad.WAD_SCALE ∧ ρ.isRight aegis_prove "wadray::wadray::wmul_wr" := fun _ _ (a : Wad) (b : Ray) _ (ρ : Ray βŠ• _) => by unfold Β«spec_wadray::wadray::wmul_wrΒ» aesop aegis_spec "wadray::wadray::wmul_rw" := fun _ _ (a : Ray) (b : Wad) _ (ρ : Ray βŠ• _) => a.toZMod.val * b.toZMod.val / Wad.WAD_SCALE < U128_MOD ∧ ρ = .inl (Ray.ofZMod (a.toZMod.val * b.toZMod.val / Wad.WAD_SCALE)) ∨ U128_MOD ≀ a.toZMod.val * b.toZMod.val / Wad.WAD_SCALE ∧ ρ.isRight aegis_prove "wadray::wadray::wmul_rw" := fun _ _ (a : Ray) (b : Wad) _ (ρ : Ray βŠ• _) => by unfold Β«spec_wadray::wadray::wmul_rwΒ» aesop (add simp [mul_comm]) aegis_spec "wadray::wadray::rmul_rw" := fun _ _ (a : Ray) (b : Wad) _ (ρ : Wad βŠ• _) => a.toZMod.val * b.toZMod.val / Ray.RAY_SCALE < U128_MOD ∧ ρ = .inl (Ray.ofZMod (a.toZMod.val * b.toZMod.val / Ray.RAY_SCALE)) ∨ U128_MOD ≀ a.toZMod.val * b.toZMod.val / Ray.RAY_SCALE ∧ ρ.isRight aegis_prove "wadray::wadray::rmul_rw" := fun _ _ (a : Ray) (b : Wad) _ (ρ : Ray βŠ• _) => by unfold Β«spec_wadray::wadray::rmul_rwΒ» aesop (add simp [mul_comm]) aegis_spec "wadray::wadray::rmul_wr" := fun _ _ (a : Wad) (b : Ray) _ (ρ : Wad βŠ• _) => a.toZMod.val * b.toZMod.val / Ray.RAY_SCALE < U128_MOD ∧ ρ = .inl (Ray.ofZMod (a.toZMod.val * b.toZMod.val / Ray.RAY_SCALE)) ∨ U128_MOD ≀ a.toZMod.val * b.toZMod.val / Ray.RAY_SCALE ∧ ρ.isRight aegis_prove "wadray::wadray::rmul_wr" := fun _ _ (a : Ray) (b : Wad) _ (ρ : Ray βŠ• _) => by unfold Β«spec_wadray::wadray::rmul_wrΒ» aesop (add simp [mul_comm]) aegis_spec "wadray::wadray::rdiv_wr" := fun _ _ (a : Wad) (b : Ray) _ (ρ : Wad βŠ• _) => a.toZMod.val * Ray.RAY_SCALE / b.toZMod.val < U128_MOD ∧ b.toZMod.val β‰  0 ∧ ρ = .inl (Wad.ofZMod (a.toZMod.val * Ray.RAY_SCALE / b.toZMod.val)) ∨ (U128_MOD ≀ a.toZMod.val * Ray.RAY_SCALE / b.toZMod.val ∨ b.toZMod.val = 0) ∧ ρ.isRight aegis_prove "wadray::wadray::rdiv_wr" := fun _ _ (a : Wad) (b : Ray) _ (ρ : Wad βŠ• _) => by unfold Β«spec_wadray::wadray::rdiv_wrΒ» aesop aegis_spec "wadray::wadray::wdiv_rw" := fun _ _ (a : Ray) (b : Wad) _ (ρ : Ray βŠ• _) => a.toZMod.val * Wad.WAD_SCALE / b.toZMod.val < U128_MOD ∧ b.toZMod.val β‰  0 ∧ ρ = .inl (Ray.ofZMod (a.toZMod.val * Wad.WAD_SCALE / b.toZMod.val)) ∨ (U128_MOD ≀ a.toZMod.val * Wad.WAD_SCALE / b.toZMod.val ∨ b.toZMod.val = 0) ∧ ρ.isRight aegis_prove "wadray::wadray::wdiv_rw" := fun _ _ (a : Ray) (b : Wad) _ (ρ : Wad βŠ• _) => by unfold Β«spec_wadray::wadray::wdiv_rwΒ» aesop aegis_spec "wadray::wadray::rdiv_ww" := fun _ _ (a b : Wad) _ (ρ : Ray βŠ• _) => a.toZMod.val * Ray.RAY_SCALE / b.toZMod.val < U128_MOD ∧ b.toZMod.val β‰  0 ∧ ρ = .inl (Wad.ofZMod (a.toZMod.val * Ray.RAY_SCALE / b.toZMod.val)) ∨ (U128_MOD ≀ a.toZMod.val * Ray.RAY_SCALE / b.toZMod.val ∨ b.toZMod.val = 0) ∧ ρ.isRight aegis_prove "wadray::wadray::rdiv_ww" := fun _ _ (a b : Wad) _ (ρ : Ray βŠ• _) => by unfold Β«spec_wadray::wadray::rdiv_wwΒ» aesop
3
104
false
Applied verif.
483
Wad.toRat_div
theorem toRat_div (h : w.toZMod.val * WAD_SCALE / w'.toZMod.val < U128_MOD) (h' : w'.toZMod.val β‰  0) : |(w / w').toRat - w.toRat / w'.toRat| < 1 / WAD_SCALE
wadray_verification
WadrayVerification/Aux.lean
[ "import Aegis.Aux.Bool", "import CorelibVerification.Aux.ZMod", "import Aegis.Aux.ZMod.DivMod" ]
[ { "name": "Sierra.UInt128", "module": "Aegis.Types" }, { "name": "Sierra.U128_MOD", "module": "Aegis.Types" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Rat", "module": "Init.Data.Rat.Basic" }, { "name": "ZMod", "module": "Mathlib.Data.ZMod.Defs" } ]
[ { "name": "Wad.div", "content": "protected def Wad.div : Wad := (w.toZMod.val * WAD_SCALE / w'.toZMod.val : UInt128)" }, { "name": "", "content": "instance : Div Wad := ⟨Wad.div⟩" } ]
[ { "name": "Nat.cast_div", "module": "Mathlib.Data.Nat.Cast.Field" }, { "name": "Nat.cast_ne_zero", "module": "Mathlib.Algebra.CharZero.Defs" }, { "name": "Nat.cast_sub", "module": "Mathlib.Data.Int.Cast.Basic" }, { "name": "Nat.div_eq_sub_mod_div", "module": "Init.Data.Nat.Lemmas" }, { "name": "Nat.dvd_sub_mod", "module": "Init.Data.Nat.Lemmas" }, { "name": "Nat.mod_le", "module": "Init.Data.Nat.Div.Basic" }, { "name": "sub_div", "module": "Mathlib.Algebra.Field.Basic" }, { "name": "Nat.abs_cast", "module": "Mathlib.Data.Nat.Cast.Order.Ring" }, { "name": "Nat.cast_lt", "module": "Mathlib.Data.Nat.Cast.Order.Basic" }, { "name": "Nat.cast_mul", "module": "Mathlib.Data.Nat.Cast.Basic" }, { "name": "Nat.cast_pos", "module": "Mathlib.Data.Nat.Cast.Order.Ring" }, { "name": "Nat.mod_eq_of_lt", "module": "Init.Data.Nat.Div.Basic" }, { "name": "Nat.mod_lt", "module": "Init.Prelude" }, { "name": "Nat.pos_of_ne_zero", "module": "Init.Data.Nat.Basic" }, { "name": "ZMod.val_natCast", "module": "Mathlib.Data.ZMod.Basic" }, { "name": "abs_div", "module": "Mathlib.Algebra.Order.Field.Basic" }, { "name": "abs_neg", "module": "Mathlib.Algebra.Order.Group.Unbundled.Abs" }, { "name": "div_div", "module": "Mathlib.Algebra.Group.Basic" }, { "name": "div_div_div_cancel_right", "module": "Mathlib.Algebra.Group.Basic" }, { "name": "div_lt_one", "module": "Mathlib.Algebra.Order.Field.Basic" }, { "name": "mul_div_mul_right", "module": "Mathlib.Algebra.GroupWithZero.Units.Basic" }, { "name": "sub_sub_cancel_left", "module": "Mathlib.Algebra.Group.Basic" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "Wad", "content": "def Wad : Type := UInt128" }, { "name": "Wad.WAD_SCALE", "content": "def WAD_SCALE : β„• := 1000000000000000000" }, { "name": "Wad.toZMod", "content": "protected def toZMod : UInt128 := w" }, { "name": "Wad.toRat", "content": "protected def toRat : β„š := w.toZMod.val / WAD_SCALE" } ]
[ { "name": "Rat.nat_cast_div_eq", "content": "theorem Rat.nat_cast_div_eq {a b : β„•} :\n ↑(a / b) = (a : β„š) / (b : β„š) - ↑(a % b) / (b : β„š)" }, { "name": "Wad.WAD_SCALE_rat_pos", "content": "theorem WAD_SCALE_rat_pos : 0 < (WAD_SCALE : β„š)" }, { "name": "Wad.WAD_SCALE_rat_ne_zero", "content": "theorem WAD_SCALE_rat_ne_zero : (WAD_SCALE : β„š) β‰  0" }, { "name": "Wad.div_def", "content": "protected theorem div_def :\n w / w' = (w.toZMod.val * WAD_SCALE / w'.toZMod.val : UInt128)" } ]
import CorelibVerification.Aux.ZMod import Aegis.Aux.Bool import Aegis.Aux.ZMod.DivMod open Sierra def Wad : Type := UInt128 namespace Wad def WAD_SCALE : β„• := 1000000000000000000 variable (w w' : Wad) protected def toZMod : UInt128 := w protected def toRat : β„š := w.toZMod.val / WAD_SCALE
theorem toRat_div (h : w.toZMod.val * WAD_SCALE / w'.toZMod.val < U128_MOD) (h' : w'.toZMod.val β‰  0) : |(w / w').toRat - w.toRat / w'.toRat| < 1 / WAD_SCALE :=
:= by have h'' : 0 < w'.toZMod.val := Nat.pos_of_ne_zero h' have h''' : (0 : β„š) < w'.toZMod.val := Nat.cast_pos.mpr h'' simp only [Wad.toRat, Wad.toZMod, Wad.div_def, ZMod.val_natCast] at * rw [Nat.mod_eq_of_lt h, Rat.nat_cast_div_eq, sub_div, Nat.cast_mul, div_div, mul_div_mul_right _ _ WAD_SCALE_rat_ne_zero, div_div_div_cancel_right _ WAD_SCALE_rat_ne_zero, sub_sub_cancel_left, abs_neg, abs_div, Nat.abs_cast, div_lt_div_right WAD_SCALE_rat_pos, abs_div, Nat.abs_cast, Nat.abs_cast, div_lt_one h''', Nat.cast_lt] apply Nat.mod_lt _ h''
2
34
false
Applied verif.
484
SignedWad.toRat_mul
theorem toRat_mul (h₁ : w₁.1.val * wβ‚‚.1.val / Wad.WAD_SCALE < U128_MOD ): |SignedWad.toRat (w₁ * wβ‚‚) - SignedWad.toRat w₁ * SignedWad.toRat wβ‚‚| < 1 / Wad.WAD_SCALE
wadray_verification
WadrayVerification/Aux.lean
[ "import Aegis.Aux.Bool", "import CorelibVerification.Aux.ZMod", "import Aegis.Aux.ZMod.DivMod" ]
[ { "name": "Sierra.UInt128", "module": "Aegis.Types" }, { "name": "Sierra.U128_MOD", "module": "Aegis.Types" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Rat", "module": "Init.Data.Rat.Basic" }, { "name": "ZMod", "module": "Mathlib.Data.ZMod.Defs" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Bool.toSierraBool", "module": "Aegis.Aux.Bool" }, { "name": "Bool.xor", "module": "Init.Data.Bool" }, { "name": "SierraBool.toBool", "module": "Aegis.Aux.Bool" } ]
[ { "name": "...", "content": "..." } ]
[ { "name": "Nat.cast_div", "module": "Mathlib.Data.Nat.Cast.Field" }, { "name": "Nat.cast_ne_zero", "module": "Mathlib.Algebra.CharZero.Defs" }, { "name": "Nat.cast_sub", "module": "Mathlib.Data.Int.Cast.Basic" }, { "name": "Nat.div_eq_sub_mod_div", "module": "Init.Data.Nat.Lemmas" }, { "name": "Nat.dvd_sub_mod", "module": "Init.Data.Nat.Lemmas" }, { "name": "Nat.mod_le", "module": "Init.Data.Nat.Div.Basic" }, { "name": "sub_div", "module": "Mathlib.Algebra.Field.Basic" }, { "name": "Nat.abs_cast", "module": "Mathlib.Data.Nat.Cast.Order.Ring" }, { "name": "Nat.cast_lt", "module": "Mathlib.Data.Nat.Cast.Order.Basic" }, { "name": "Nat.cast_mul", "module": "Mathlib.Data.Nat.Cast.Basic" }, { "name": "Nat.mod_eq_of_lt", "module": "Init.Data.Nat.Div.Basic" }, { "name": "Nat.mod_lt", "module": "Init.Prelude" }, { "name": "ZMod.natCast_val", "module": "Mathlib.Data.ZMod.Basic" }, { "name": "abs_div", "module": "Mathlib.Algebra.Order.Field.Basic" }, { "name": "abs_neg", "module": "Mathlib.Algebra.Order.Group.Unbundled.Abs" }, { "name": "div_lt_one", "module": "Mathlib.Algebra.Order.Field.Basic" }, { "name": "div_mul_eq_mul_div", "module": "Mathlib.Algebra.Group.Basic" }, { "name": "mul_div_assoc", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "neg_sub", "module": "Mathlib.Algebra.Group.Basic" }, { "name": "one_div", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "sub_add_cancel", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "sub_right_comm", "module": "Mathlib.Algebra.Group.Basic" }, { "name": "sub_self", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "zero_sub", "module": "Mathlib.Algebra.Group.Defs" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "Wad", "content": "def Wad : Type := UInt128" }, { "name": "Wad.WAD_SCALE", "content": "def WAD_SCALE : β„• := 1000000000000000000" }, { "name": "Wad.toZMod", "content": "protected def toZMod : UInt128 := w" }, { "name": "Wad.toRat", "content": "protected def toRat : β„š := w.toZMod.val / WAD_SCALE" }, { "name": "Wad.mul", "content": "protected def mul : Wad := (w.toZMod.val * w'.toZMod.val / WAD_SCALE : UInt128)" }, { "name": "SignedWad", "content": "def SignedWad := UInt128 Γ— (Unit βŠ• Unit)" }, { "name": "SignedWad.toRat", "content": "def toRat : β„š := if w.2 then -(Wad.toRat w.1) else Wad.toRat w.1" } ]
[ { "name": "Rat.nat_cast_div_eq", "content": "theorem Rat.nat_cast_div_eq {a b : β„•} :\n ↑(a / b) = (a : β„š) / (b : β„š) - ↑(a % b) / (b : β„š)" }, { "name": "Wad.WAD_SCALE_pos", "content": "theorem WAD_SCALE_pos : 0 < WAD_SCALE" }, { "name": "Wad.WAD_SCALE_rat_pos", "content": "theorem WAD_SCALE_rat_pos : 0 < (WAD_SCALE : β„š)" }, { "name": "SignedWad.mul_def", "content": "theorem mul_def :\n w₁ * wβ‚‚ = ⟨Wad.mul (w₁.1 : Wad) (wβ‚‚.1 : Wad), Bool.toSierraBool (Bool.xor (SierraBool.toBool w₁.2) (SierraBool.toBool wβ‚‚.2))⟩" } ]
import CorelibVerification.Aux.ZMod import Aegis.Aux.Bool import Aegis.Aux.ZMod.DivMod open Sierra def Wad : Type := UInt128 namespace Wad def WAD_SCALE : β„• := 1000000000000000000 variable (w w' : Wad) protected def toZMod : UInt128 := w protected def toRat : β„š := w.toZMod.val / WAD_SCALE protected def mul : Wad := (w.toZMod.val * w'.toZMod.val / WAD_SCALE : UInt128) end Wad namespace Ray variable (r r' : Ray) end Ray def SignedWad := UInt128 Γ— (Unit βŠ• Unit) namespace SignedWad instance : Inhabited SignedWad := ⟨default, default⟩ variable (w w₁ wβ‚‚ : SignedWad) def sign : β„€ := if SierraBool.toBool w.2 then -1 else 1 instance : Zero SignedWad := ⟨(0, false.toSierraBool)⟩ def toRat : β„š := if w.2 then -(Wad.toRat w.1) else Wad.toRat w.1 protected def mul : SignedWad := ⟨Wad.mul (w₁.1 : Wad) (wβ‚‚.1 : Wad), Bool.toSierraBool (Bool.xor (SierraBool.toBool w₁.2) (SierraBool.toBool wβ‚‚.2))⟩ instance : Mul SignedWad := ⟨SignedWad.mul⟩
theorem toRat_mul (h₁ : w₁.1.val * wβ‚‚.1.val / Wad.WAD_SCALE < U128_MOD ): |SignedWad.toRat (w₁ * wβ‚‚) - SignedWad.toRat w₁ * SignedWad.toRat wβ‚‚| < 1 / Wad.WAD_SCALE :=
:= by rcases w₁ with ⟨w₁, sβ‚βŸ© rcases wβ‚‚ with ⟨wβ‚‚, sβ‚‚βŸ© rcases s₁ with (⟨⟨⟩⟩|⟨⟨⟩⟩) <;> rcases sβ‚‚ with (⟨⟨⟩⟩|⟨⟨⟩⟩) <;> dsimp only at h₁ <;> simp [mul_def, toRat, Wad.mul, Wad.toRat, Wad.toZMod, Nat.mod_eq_of_lt h₁, -one_div] <;> rw [Rat.nat_cast_div_eq, Nat.cast_mul, ZMod.natCast_val, ZMod.natCast_val, mul_div_assoc, sub_div, div_mul_eq_mul_div] <;> [rw [sub_right_comm, sub_self, zero_sub, abs_neg]; rw [neg_sub, sub_add_cancel]; rw [neg_sub, sub_add_cancel]; rw [sub_right_comm, sub_self, zero_sub, abs_neg]] <;> rw [abs_div, Nat.abs_cast, div_lt_div_right Wad.WAD_SCALE_rat_pos, abs_div, Nat.abs_cast, Nat.abs_cast, div_lt_one Wad.WAD_SCALE_rat_pos, Nat.cast_lt] <;> apply Nat.mod_lt _ Wad.WAD_SCALE_pos
2
43
false
Applied verif.
485
SignedRay.toRat_mul
theorem toRat_mul (h₁ : w₁.1.val * wβ‚‚.1.val / Ray.RAY_SCALE < U128_MOD ): |SignedRay.toRat (w₁ * wβ‚‚) - SignedRay.toRat w₁ * SignedRay.toRat wβ‚‚| < 1 / Ray.RAY_SCALE
wadray_verification
WadrayVerification/Aux.lean
[ "import Aegis.Aux.Bool", "import CorelibVerification.Aux.ZMod", "import Aegis.Aux.ZMod.DivMod" ]
[ { "name": "Sierra.UInt128", "module": "Aegis.Types" }, { "name": "SierraBool.toBool", "module": "Aegis.Aux.Bool" }, { "name": "Sierra.U128_MOD", "module": "Aegis.Types" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Rat", "module": "Init.Data.Rat.Basic" }, { "name": "ZMod", "module": "Mathlib.Data.ZMod.Defs" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Bool.toSierraBool", "module": "Aegis.Aux.Bool" }, { "name": "Bool.xor", "module": "Init.Data.Bool" } ]
[ { "name": "...", "content": "..." } ]
[ { "name": "Nat.cast_div", "module": "Mathlib.Data.Nat.Cast.Field" }, { "name": "Nat.cast_ne_zero", "module": "Mathlib.Algebra.CharZero.Defs" }, { "name": "Nat.cast_sub", "module": "Mathlib.Data.Int.Cast.Basic" }, { "name": "Nat.div_eq_sub_mod_div", "module": "Init.Data.Nat.Lemmas" }, { "name": "Nat.dvd_sub_mod", "module": "Init.Data.Nat.Lemmas" }, { "name": "Nat.mod_le", "module": "Init.Data.Nat.Div.Basic" }, { "name": "sub_div", "module": "Mathlib.Algebra.Field.Basic" }, { "name": "Nat.abs_cast", "module": "Mathlib.Data.Nat.Cast.Order.Ring" }, { "name": "Nat.cast_lt", "module": "Mathlib.Data.Nat.Cast.Order.Basic" }, { "name": "Nat.cast_mul", "module": "Mathlib.Data.Nat.Cast.Basic" }, { "name": "Nat.mod_eq_of_lt", "module": "Init.Data.Nat.Div.Basic" }, { "name": "Nat.mod_lt", "module": "Init.Prelude" }, { "name": "ZMod.natCast_val", "module": "Mathlib.Data.ZMod.Basic" }, { "name": "abs_div", "module": "Mathlib.Algebra.Order.Field.Basic" }, { "name": "abs_neg", "module": "Mathlib.Algebra.Order.Group.Unbundled.Abs" }, { "name": "div_lt_one", "module": "Mathlib.Algebra.Order.Field.Basic" }, { "name": "div_mul_eq_mul_div", "module": "Mathlib.Algebra.Group.Basic" }, { "name": "mul_div_assoc", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "neg_sub", "module": "Mathlib.Algebra.Group.Basic" }, { "name": "one_div", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "sub_add_cancel", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "sub_right_comm", "module": "Mathlib.Algebra.Group.Basic" }, { "name": "sub_self", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "zero_sub", "module": "Mathlib.Algebra.Group.Defs" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "Ray", "content": "def Ray : Type := UInt128" }, { "name": "Ray.RAY_SCALE", "content": "def RAY_SCALE : β„• := 1000000000000000000000000000" }, { "name": "Ray.toZMod", "content": "protected def toZMod : UInt128 := r" }, { "name": "Ray.toRat", "content": "protected def toRat : β„š := r.toZMod.val / RAY_SCALE" }, { "name": "Ray.mul", "content": "protected def mul : Ray := (r.toZMod.val * r'.toZMod.val / RAY_SCALE : UInt128)" }, { "name": "SignedRay", "content": "def SignedRay := UInt128 Γ— (Unit βŠ• Unit)" }, { "name": "SignedRay.toRat", "content": "def toRat : β„š := if SierraBool.toBool w.2 then -(Ray.toRat w.1) else Ray.toRat w.1" } ]
[ { "name": "Rat.nat_cast_div_eq", "content": "theorem Rat.nat_cast_div_eq {a b : β„•} :\n ↑(a / b) = (a : β„š) / (b : β„š) - ↑(a % b) / (b : β„š)" }, { "name": "Ray.RAY_SCALE_pos", "content": "theorem RAY_SCALE_pos : 0 < RAY_SCALE" }, { "name": "Ray.RAY_SCALE_rat_pos", "content": "theorem RAY_SCALE_rat_pos : 0 < (RAY_SCALE : β„š)" }, { "name": "SignedRay.mul_def", "content": "theorem mul_def :\n w₁ * wβ‚‚ = ⟨Ray.mul w₁.1 wβ‚‚.1, Bool.toSierraBool (Bool.xor (SierraBool.toBool w₁.2) (SierraBool.toBool wβ‚‚.2))⟩" } ]
import CorelibVerification.Aux.ZMod import Aegis.Aux.Bool import Aegis.Aux.ZMod.DivMod open Sierra namespace Wad variable (w w' : Wad) end Wad def Ray : Type := UInt128 namespace Ray def RAY_SCALE : β„• := 1000000000000000000000000000 variable (r r' : Ray) protected def toZMod : UInt128 := r protected def toRat : β„š := r.toZMod.val / RAY_SCALE protected def mul : Ray := (r.toZMod.val * r'.toZMod.val / RAY_SCALE : UInt128) end Ray namespace SignedWad variable (w w₁ wβ‚‚ : SignedWad) end SignedWad def SignedRay := UInt128 Γ— (Unit βŠ• Unit) namespace SignedRay instance : Inhabited SignedRay := ⟨default, default⟩ variable (w w₁ wβ‚‚ : SignedRay) def sign : β„€ := if SierraBool.toBool w.2 then -1 else 1 instance : Zero SignedRay := ⟨(0, false.toSierraBool)⟩ def toRat : β„š := if SierraBool.toBool w.2 then -(Ray.toRat w.1) else Ray.toRat w.1 protected def mul : SignedRay := ⟨Ray.mul w₁.1 wβ‚‚.1, Bool.toSierraBool (Bool.xor (SierraBool.toBool w₁.2) (SierraBool.toBool wβ‚‚.2))⟩ instance : Mul SignedRay := ⟨SignedRay.mul⟩
theorem toRat_mul (h₁ : w₁.1.val * wβ‚‚.1.val / Ray.RAY_SCALE < U128_MOD ): |SignedRay.toRat (w₁ * wβ‚‚) - SignedRay.toRat w₁ * SignedRay.toRat wβ‚‚| < 1 / Ray.RAY_SCALE :=
:= by rcases w₁ with ⟨w₁, sβ‚βŸ© rcases wβ‚‚ with ⟨wβ‚‚, sβ‚‚βŸ© rcases s₁ with (⟨⟨⟩⟩|⟨⟨⟩⟩) <;> rcases sβ‚‚ with (⟨⟨⟩⟩|⟨⟨⟩⟩) <;> dsimp only at h₁ <;> simp [mul_def, toRat, Ray.mul, Ray.toRat, Ray.toZMod, Nat.mod_eq_of_lt h₁, -one_div] <;> rw [Rat.nat_cast_div_eq, Nat.cast_mul, ZMod.natCast_val, ZMod.natCast_val, mul_div_assoc, sub_div, div_mul_eq_mul_div] <;> [rw [sub_right_comm, sub_self, zero_sub, abs_neg]; rw [neg_sub, sub_add_cancel]; rw [neg_sub, sub_add_cancel]; rw [sub_right_comm, sub_self, zero_sub, abs_neg]] <;> rw [abs_div, Nat.abs_cast, div_lt_div_right Ray.RAY_SCALE_rat_pos, abs_div, Nat.abs_cast, Nat.abs_cast, div_lt_one Ray.RAY_SCALE_rat_pos, Nat.cast_lt] <;> apply Nat.mod_lt _ Ray.RAY_SCALE_pos
2
43
false
Applied verif.
486
Wad.toRat_mul
theorem toRat_mul (h : w.toZMod.val * w'.toZMod.val / WAD_SCALE < U128_MOD) : |(w * w').toRat - w.toRat * w'.toRat| < 1 / WAD_SCALE
wadray_verification
WadrayVerification/Aux.lean
[ "import Aegis.Aux.Bool", "import CorelibVerification.Aux.ZMod", "import Aegis.Aux.ZMod.DivMod" ]
[ { "name": "Sierra.UInt128", "module": "Aegis.Types" }, { "name": "Sierra.U128_MOD", "module": "Aegis.Types" }, { "name": "Int", "module": "Init.Data.Int.Basic" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Rat", "module": "Init.Data.Rat.Basic" }, { "name": "ZMod", "module": "Mathlib.Data.ZMod.Defs" } ]
[ { "name": "Wad.mul", "content": "protected def Wad.mul : Wad := (w.toZMod.val * w'.toZMod.val / WAD_SCALE : UInt128)" }, { "name": "", "content": "instance : Mul Wad := ⟨Wad.mul⟩" } ]
[ { "name": "Nat.cast_div", "module": "Mathlib.Data.Nat.Cast.Field" }, { "name": "Nat.cast_ne_zero", "module": "Mathlib.Algebra.CharZero.Defs" }, { "name": "Nat.cast_sub", "module": "Mathlib.Data.Int.Cast.Basic" }, { "name": "Nat.div_eq_sub_mod_div", "module": "Init.Data.Nat.Lemmas" }, { "name": "Nat.dvd_sub_mod", "module": "Init.Data.Nat.Lemmas" }, { "name": "Nat.mod_le", "module": "Init.Data.Nat.Div.Basic" }, { "name": "sub_div", "module": "Mathlib.Algebra.Field.Basic" }, { "name": "Int.natCast_natAbs", "module": "Mathlib.Algebra.Order.Group.Unbundled.Int" }, { "name": "Nat.abs_cast", "module": "Mathlib.Data.Nat.Cast.Order.Ring" }, { "name": "Nat.cast_lt", "module": "Mathlib.Data.Nat.Cast.Order.Basic" }, { "name": "Nat.cast_mul", "module": "Mathlib.Data.Nat.Cast.Basic" }, { "name": "Nat.mod_eq_of_lt", "module": "Init.Data.Nat.Div.Basic" }, { "name": "Nat.mod_lt", "module": "Init.Prelude" }, { "name": "ZMod.natCast_val", "module": "Mathlib.Data.ZMod.Basic" }, { "name": "ZMod.val_natCast", "module": "Mathlib.Data.ZMod.Basic" }, { "name": "abs_div", "module": "Mathlib.Algebra.Order.Field.Basic" }, { "name": "abs_neg", "module": "Mathlib.Algebra.Order.Group.Unbundled.Abs" }, { "name": "div_div", "module": "Mathlib.Algebra.Group.Basic" }, { "name": "div_lt_one", "module": "Mathlib.Algebra.Order.Field.Basic" }, { "name": "div_mul_div_comm", "module": "Mathlib.Algebra.Group.Basic" }, { "name": "sub_sub_cancel_left", "module": "Mathlib.Algebra.Group.Basic" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "Wad", "content": "def Wad : Type := UInt128" }, { "name": "Wad.WAD_SCALE", "content": "def WAD_SCALE : β„• := 1000000000000000000" }, { "name": "Wad.toZMod", "content": "protected def toZMod : UInt128 := w" }, { "name": "Wad.toRat", "content": "protected def toRat : β„š := w.toZMod.val / WAD_SCALE" } ]
[ { "name": "Rat.nat_cast_div_eq", "content": "theorem Rat.nat_cast_div_eq {a b : β„•} :\n ↑(a / b) = (a : β„š) / (b : β„š) - ↑(a % b) / (b : β„š)" }, { "name": "Wad.WAD_SCALE_pos", "content": "theorem WAD_SCALE_pos : 0 < WAD_SCALE" }, { "name": "Wad.WAD_SCALE_rat_pos", "content": "theorem WAD_SCALE_rat_pos : 0 < (WAD_SCALE : β„š)" }, { "name": "Wad.mul_def", "content": "protected theorem mul_def :\n w * w' = (w.toZMod.val * w'.toZMod.val / WAD_SCALE : UInt128)" } ]
import CorelibVerification.Aux.ZMod import Aegis.Aux.Bool import Aegis.Aux.ZMod.DivMod open Sierra def Wad : Type := UInt128 namespace Wad def WAD_SCALE : β„• := 1000000000000000000 variable (w w' : Wad) protected def toZMod : UInt128 := w protected def toRat : β„š := w.toZMod.val / WAD_SCALE
theorem toRat_mul (h : w.toZMod.val * w'.toZMod.val / WAD_SCALE < U128_MOD) : |(w * w').toRat - w.toRat * w'.toRat| < 1 / WAD_SCALE :=
:= by simp only [Wad.toRat, Wad.toZMod, Wad.mul_def, Int.natCast_natAbs] at * simp only [ZMod.val_natCast, ZMod.natCast_val] at * rw [Nat.mod_eq_of_lt h, div_mul_div_comm, ← div_div, ← sub_div, abs_div, Nat.abs_cast, div_lt_div_right WAD_SCALE_rat_pos, Rat.nat_cast_div_eq] simp only [Nat.cast_mul, ZMod.natCast_val, sub_sub_cancel_left, abs_neg] rw [abs_div, Nat.abs_cast, Nat.abs_cast, div_lt_one WAD_SCALE_rat_pos, Nat.cast_lt] apply Nat.mod_lt _ WAD_SCALE_pos
2
34
false
Applied verif.
487
Ray.toRat_mul
theorem toRat_mul (h : r.toZMod.val * r'.toZMod.val / RAY_SCALE < U128_MOD) : |(r * r').toRat - r.toRat * r'.toRat| < 1 / RAY_SCALE
wadray_verification
WadrayVerification/Aux.lean
[ "import Aegis.Aux.Bool", "import CorelibVerification.Aux.ZMod", "import Aegis.Aux.ZMod.DivMod" ]
[ { "name": "Sierra.UInt128", "module": "Aegis.Types" }, { "name": "Sierra.U128_MOD", "module": "Aegis.Types" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Rat", "module": "Init.Data.Rat.Basic" }, { "name": "ZMod", "module": "Mathlib.Data.ZMod.Defs" } ]
[ { "name": "Ray.mul", "content": "protected def Ray.mul : Ray := (r.toZMod.val * r'.toZMod.val / RAY_SCALE : UInt128)" }, { "name": "", "content": "instance : Mul Ray := ⟨Ray.mul⟩" } ]
[ { "name": "Nat.cast_div", "module": "Mathlib.Data.Nat.Cast.Field" }, { "name": "Nat.cast_ne_zero", "module": "Mathlib.Algebra.CharZero.Defs" }, { "name": "Nat.cast_sub", "module": "Mathlib.Data.Int.Cast.Basic" }, { "name": "Nat.div_eq_sub_mod_div", "module": "Init.Data.Nat.Lemmas" }, { "name": "Nat.dvd_sub_mod", "module": "Init.Data.Nat.Lemmas" }, { "name": "Nat.mod_le", "module": "Init.Data.Nat.Div.Basic" }, { "name": "sub_div", "module": "Mathlib.Algebra.Field.Basic" }, { "name": "Nat.abs_cast", "module": "Mathlib.Data.Nat.Cast.Order.Ring" }, { "name": "Nat.cast_lt", "module": "Mathlib.Data.Nat.Cast.Order.Basic" }, { "name": "Nat.cast_mul", "module": "Mathlib.Data.Nat.Cast.Basic" }, { "name": "Nat.mod_eq_of_lt", "module": "Init.Data.Nat.Div.Basic" }, { "name": "Nat.mod_lt", "module": "Init.Prelude" }, { "name": "ZMod.val_natCast", "module": "Mathlib.Data.ZMod.Basic" }, { "name": "abs_div", "module": "Mathlib.Algebra.Order.Field.Basic" }, { "name": "abs_neg", "module": "Mathlib.Algebra.Order.Group.Unbundled.Abs" }, { "name": "div_div", "module": "Mathlib.Algebra.Group.Basic" }, { "name": "div_lt_one", "module": "Mathlib.Algebra.Order.Field.Basic" }, { "name": "div_mul_div_comm", "module": "Mathlib.Algebra.Group.Basic" }, { "name": "sub_sub_cancel_left", "module": "Mathlib.Algebra.Group.Basic" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "Ray", "content": "def Ray : Type := UInt128" }, { "name": "Ray.RAY_SCALE", "content": "def RAY_SCALE : β„• := 1000000000000000000000000000" }, { "name": "Ray.toZMod", "content": "protected def toZMod : UInt128 := r" }, { "name": "Ray.toRat", "content": "protected def toRat : β„š := r.toZMod.val / RAY_SCALE" } ]
[ { "name": "Rat.nat_cast_div_eq", "content": "theorem Rat.nat_cast_div_eq {a b : β„•} :\n ↑(a / b) = (a : β„š) / (b : β„š) - ↑(a % b) / (b : β„š)" }, { "name": "Ray.RAY_SCALE_pos", "content": "theorem RAY_SCALE_pos : 0 < RAY_SCALE" }, { "name": "Ray.RAY_SCALE_rat_pos", "content": "theorem RAY_SCALE_rat_pos : 0 < (RAY_SCALE : β„š)" }, { "name": "Ray.mul_def", "content": "protected theorem mul_def :\n r * r' = (r.toZMod.val * r'.toZMod.val / RAY_SCALE : UInt128)" } ]
import CorelibVerification.Aux.ZMod import Aegis.Aux.Bool import Aegis.Aux.ZMod.DivMod open Sierra namespace Wad variable (w w' : Wad) end Wad def Ray : Type := UInt128 namespace Ray def RAY_SCALE : β„• := 1000000000000000000000000000 variable (r r' : Ray) protected def toZMod : UInt128 := r protected def toRat : β„š := r.toZMod.val / RAY_SCALE
theorem toRat_mul (h : r.toZMod.val * r'.toZMod.val / RAY_SCALE < U128_MOD) : |(r * r').toRat - r.toRat * r'.toRat| < 1 / RAY_SCALE :=
:= by simp only [Ray.toRat, Ray.toZMod, Ray.mul_def] at * simp only [ZMod.val_natCast] rw [Nat.mod_eq_of_lt h, div_mul_div_comm, ← div_div, ← sub_div, abs_div, Nat.abs_cast, div_lt_div_right RAY_SCALE_rat_pos, Rat.nat_cast_div_eq] simp only [Nat.cast_mul, ZMod.val_natCast, sub_sub_cancel_left, abs_neg] rw [abs_div, Nat.abs_cast, Nat.abs_cast, div_lt_one RAY_SCALE_rat_pos, Nat.cast_lt] apply Nat.mod_lt _ RAY_SCALE_pos
2
31
false
Applied verif.
488
SignedWad.toRat_div
theorem toRat_div (h₁ : w₁.1.val * Wad.WAD_SCALE / wβ‚‚.1.val < U128_MOD) (hβ‚‚ : wβ‚‚.1.val β‰  0): |SignedWad.toRat (w₁ / wβ‚‚) - SignedWad.toRat w₁ / SignedWad.toRat wβ‚‚| < 1 / Wad.WAD_SCALE
wadray_verification
WadrayVerification/Aux.lean
[ "import Aegis.Aux.Bool", "import CorelibVerification.Aux.ZMod", "import Aegis.Aux.ZMod.DivMod" ]
[ { "name": "Sierra.UInt128", "module": "Aegis.Types" }, { "name": "Sierra.U128_MOD", "module": "Aegis.Types" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Rat", "module": "Init.Data.Rat.Basic" }, { "name": "ZMod", "module": "Mathlib.Data.ZMod.Defs" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Bool.toSierraBool", "module": "Aegis.Aux.Bool" }, { "name": "Bool.xor", "module": "Init.Data.Bool" }, { "name": "SierraBool.toBool", "module": "Aegis.Aux.Bool" } ]
[ { "name": "SignedWad.div", "content": "protected def SignedWad.div : SignedWad :=\n⟨Wad.div (w₁.1 : Wad) (wβ‚‚.1 : Wad), Bool.toSierraBool (Bool.xor (SierraBool.toBool w₁.2) (SierraBool.toBool wβ‚‚.2))⟩" }, { "name": "", "content": "instance : Div SignedWad := ⟨SignedWad.div⟩" } ]
[ { "name": "Nat.cast_div", "module": "Mathlib.Data.Nat.Cast.Field" }, { "name": "Nat.cast_ne_zero", "module": "Mathlib.Algebra.CharZero.Defs" }, { "name": "Nat.cast_sub", "module": "Mathlib.Data.Int.Cast.Basic" }, { "name": "Nat.div_eq_sub_mod_div", "module": "Init.Data.Nat.Lemmas" }, { "name": "Nat.dvd_sub_mod", "module": "Init.Data.Nat.Lemmas" }, { "name": "Nat.mod_le", "module": "Init.Data.Nat.Div.Basic" }, { "name": "sub_div", "module": "Mathlib.Algebra.Field.Basic" }, { "name": "Nat.abs_cast", "module": "Mathlib.Data.Nat.Cast.Order.Ring" }, { "name": "Nat.cast_lt", "module": "Mathlib.Data.Nat.Cast.Order.Basic" }, { "name": "Nat.cast_mul", "module": "Mathlib.Data.Nat.Cast.Basic" }, { "name": "Nat.cast_zero", "module": "Mathlib.Data.Nat.Cast.Defs" }, { "name": "Nat.mod_eq_of_lt", "module": "Init.Data.Nat.Div.Basic" }, { "name": "Nat.mod_lt", "module": "Init.Prelude" }, { "name": "Nat.pos_of_ne_zero", "module": "Init.Data.Nat.Basic" }, { "name": "ZMod.natCast_val", "module": "Mathlib.Data.ZMod.Basic" }, { "name": "abs_div", "module": "Mathlib.Algebra.Order.Field.Basic" }, { "name": "abs_neg", "module": "Mathlib.Algebra.Order.Group.Unbundled.Abs" }, { "name": "div_div", "module": "Mathlib.Algebra.Group.Basic" }, { "name": "div_div_div_cancel_right", "module": "Mathlib.Algebra.Group.Basic" }, { "name": "div_lt_one", "module": "Mathlib.Algebra.Order.Field.Basic" }, { "name": "div_neg", "module": "Mathlib.Algebra.Ring.Basic" }, { "name": "mul_div_mul_right", "module": "Mathlib.Algebra.GroupWithZero.Units.Basic" }, { "name": "neg_div", "module": "Mathlib.Algebra.Ring.Basic" }, { "name": "neg_sub", "module": "Mathlib.Algebra.Group.Basic" }, { "name": "one_div", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "sub_add_cancel", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "sub_neg_eq_add", "module": "Mathlib.Algebra.Group.Basic" }, { "name": "sub_right_comm", "module": "Mathlib.Algebra.Group.Basic" }, { "name": "sub_self", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "zero_sub", "module": "Mathlib.Algebra.Group.Defs" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "Wad", "content": "def Wad : Type := UInt128" }, { "name": "Wad.WAD_SCALE", "content": "def WAD_SCALE : β„• := 1000000000000000000" }, { "name": "Wad.toZMod", "content": "protected def toZMod : UInt128 := w" }, { "name": "Wad.toRat", "content": "protected def toRat : β„š := w.toZMod.val / WAD_SCALE" }, { "name": "Wad.div", "content": "protected def div : Wad := (w.toZMod.val * WAD_SCALE / w'.toZMod.val : UInt128)" }, { "name": "SignedWad", "content": "def SignedWad := UInt128 Γ— (Unit βŠ• Unit)" }, { "name": "SignedWad.toRat", "content": "def toRat : β„š := if w.2 then -(Wad.toRat w.1) else Wad.toRat w.1" } ]
[ { "name": "Rat.nat_cast_div_eq", "content": "theorem Rat.nat_cast_div_eq {a b : β„•} :\n ↑(a / b) = (a : β„š) / (b : β„š) - ↑(a % b) / (b : β„š)" }, { "name": "Wad.WAD_SCALE_rat_pos", "content": "theorem WAD_SCALE_rat_pos : 0 < (WAD_SCALE : β„š)" }, { "name": "Wad.WAD_SCALE_rat_ne_zero", "content": "theorem WAD_SCALE_rat_ne_zero : (WAD_SCALE : β„š) β‰  0" }, { "name": "SignedWad.div_def", "content": "theorem div_def :\n w₁ / wβ‚‚ = ⟨Wad.div (w₁.1 : Wad) (wβ‚‚.1 : Wad), Bool.toSierraBool (Bool.xor (SierraBool.toBool w₁.2) (SierraBool.toBool wβ‚‚.2))⟩" } ]
import CorelibVerification.Aux.ZMod import Aegis.Aux.Bool import Aegis.Aux.ZMod.DivMod open Sierra def Wad : Type := UInt128 namespace Wad def WAD_SCALE : β„• := 1000000000000000000 variable (w w' : Wad) protected def toZMod : UInt128 := w protected def toRat : β„š := w.toZMod.val / WAD_SCALE protected def div : Wad := (w.toZMod.val * WAD_SCALE / w'.toZMod.val : UInt128) end Wad namespace Ray variable (r r' : Ray) end Ray def SignedWad := UInt128 Γ— (Unit βŠ• Unit) namespace SignedWad variable (w w₁ wβ‚‚ : SignedWad) def toRat : β„š := if w.2 then -(Wad.toRat w.1) else Wad.toRat w.1
theorem toRat_div (h₁ : w₁.1.val * Wad.WAD_SCALE / wβ‚‚.1.val < U128_MOD) (hβ‚‚ : wβ‚‚.1.val β‰  0): |SignedWad.toRat (w₁ / wβ‚‚) - SignedWad.toRat w₁ / SignedWad.toRat wβ‚‚| < 1 / Wad.WAD_SCALE :=
:= by rcases w₁ with ⟨w₁, sβ‚βŸ© rcases wβ‚‚ with ⟨wβ‚‚, sβ‚‚βŸ© rcases s₁ with (⟨⟨⟩⟩|⟨⟨⟩⟩) <;> rcases sβ‚‚ with (⟨⟨⟩⟩|⟨⟨⟩⟩) <;> dsimp only at h₁ hβ‚‚ <;> simp [div_def, toRat, Wad.div, Wad.toRat, Wad.toZMod, Nat.mod_eq_of_lt h₁, -one_div] <;> rw [Rat.nat_cast_div_eq, Nat.cast_mul, ZMod.natCast_val, ZMod.natCast_val, sub_div] <;> [rw [div_div_div_cancel_right _ Wad.WAD_SCALE_rat_ne_zero, div_div, mul_div_mul_right _ _ Wad.WAD_SCALE_rat_ne_zero, sub_right_comm, sub_self, zero_sub, abs_neg]; rw [neg_sub, div_neg, sub_neg_eq_add, div_div_div_cancel_right _ Wad.WAD_SCALE_rat_ne_zero, div_div (w₁.cast * _), mul_div_mul_right _ _ Wad.WAD_SCALE_rat_ne_zero, sub_add_cancel]; rw [neg_sub, neg_div, sub_neg_eq_add, div_div_div_cancel_right _ Wad.WAD_SCALE_rat_ne_zero, div_div (w₁.cast * _), mul_div_mul_right _ _ Wad.WAD_SCALE_rat_ne_zero, sub_add_cancel]; rw [div_div_div_cancel_right _ Wad.WAD_SCALE_rat_ne_zero, div_div, mul_div_mul_right _ _ Wad.WAD_SCALE_rat_ne_zero, sub_right_comm, sub_self, zero_sub, abs_neg]] <;> rw [abs_div, Nat.abs_cast, div_lt_div_right Wad.WAD_SCALE_rat_pos, abs_div, ← ZMod.natCast_val, Nat.abs_cast, Nat.abs_cast, div_lt_one (by rw [← Nat.cast_zero, Nat.cast_lt]; apply Nat.pos_of_ne_zero hβ‚‚), Nat.cast_lt] <;> apply Nat.mod_lt _ (Nat.pos_of_ne_zero hβ‚‚)
2
49
false
Applied verif.
489
SignedRay.toRat_div
theorem toRat_div (h₁ : w₁.1.val * Ray.RAY_SCALE / wβ‚‚.1.val < U128_MOD) (hβ‚‚ : wβ‚‚.1.val β‰  0): |SignedRay.toRat (w₁ / wβ‚‚) - SignedRay.toRat w₁ / SignedRay.toRat wβ‚‚| < 1 / Ray.RAY_SCALE
wadray_verification
WadrayVerification/Aux.lean
[ "import Aegis.Aux.Bool", "import CorelibVerification.Aux.ZMod", "import Aegis.Aux.ZMod.DivMod" ]
[ { "name": "SierraBool.toBool", "module": "Aegis.Aux.Bool" }, { "name": "Sierra.UInt128", "module": "Aegis.Types" }, { "name": "Sierra.U128_MOD", "module": "Aegis.Types" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Rat", "module": "Init.Data.Rat.Basic" }, { "name": "ZMod", "module": "Mathlib.Data.ZMod.Defs" }, { "name": "Bool", "module": "Init.Prelude" }, { "name": "Bool.toSierraBool", "module": "Aegis.Aux.Bool" }, { "name": "Bool.xor", "module": "Init.Data.Bool" } ]
[ { "name": "SignedRay.div", "content": "protected def SignedRay.div : SignedRay :=\n⟨Ray.div (w₁.1 : Ray) (wβ‚‚.1 : Ray), Bool.toSierraBool (Bool.xor (SierraBool.toBool w₁.2) (SierraBool.toBool wβ‚‚.2))⟩" }, { "name": "", "content": "instance : Div SignedRay := ⟨SignedRay.div⟩" } ]
[ { "name": "Nat.cast_div", "module": "Mathlib.Data.Nat.Cast.Field" }, { "name": "Nat.cast_ne_zero", "module": "Mathlib.Algebra.CharZero.Defs" }, { "name": "Nat.cast_sub", "module": "Mathlib.Data.Int.Cast.Basic" }, { "name": "Nat.div_eq_sub_mod_div", "module": "Init.Data.Nat.Lemmas" }, { "name": "Nat.dvd_sub_mod", "module": "Init.Data.Nat.Lemmas" }, { "name": "Nat.mod_le", "module": "Init.Data.Nat.Div.Basic" }, { "name": "sub_div", "module": "Mathlib.Algebra.Field.Basic" }, { "name": "Nat.abs_cast", "module": "Mathlib.Data.Nat.Cast.Order.Ring" }, { "name": "Nat.cast_lt", "module": "Mathlib.Data.Nat.Cast.Order.Basic" }, { "name": "Nat.cast_mul", "module": "Mathlib.Data.Nat.Cast.Basic" }, { "name": "Nat.cast_zero", "module": "Mathlib.Data.Nat.Cast.Defs" }, { "name": "Nat.mod_eq_of_lt", "module": "Init.Data.Nat.Div.Basic" }, { "name": "Nat.mod_lt", "module": "Init.Prelude" }, { "name": "Nat.pos_of_ne_zero", "module": "Init.Data.Nat.Basic" }, { "name": "ZMod.natCast_val", "module": "Mathlib.Data.ZMod.Basic" }, { "name": "abs_div", "module": "Mathlib.Algebra.Order.Field.Basic" }, { "name": "abs_neg", "module": "Mathlib.Algebra.Order.Group.Unbundled.Abs" }, { "name": "div_div", "module": "Mathlib.Algebra.Group.Basic" }, { "name": "div_div_div_cancel_right", "module": "Mathlib.Algebra.Group.Basic" }, { "name": "div_lt_one", "module": "Mathlib.Algebra.Order.Field.Basic" }, { "name": "div_neg", "module": "Mathlib.Algebra.Ring.Basic" }, { "name": "mul_div_mul_right", "module": "Mathlib.Algebra.GroupWithZero.Units.Basic" }, { "name": "neg_div", "module": "Mathlib.Algebra.Ring.Basic" }, { "name": "neg_sub", "module": "Mathlib.Algebra.Group.Basic" }, { "name": "one_div", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "sub_add_cancel", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "sub_neg_eq_add", "module": "Mathlib.Algebra.Group.Basic" }, { "name": "sub_right_comm", "module": "Mathlib.Algebra.Group.Basic" }, { "name": "sub_self", "module": "Mathlib.Algebra.Group.Defs" }, { "name": "zero_sub", "module": "Mathlib.Algebra.Group.Defs" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "Ray", "content": "def Ray : Type := UInt128" }, { "name": "Ray.RAY_SCALE", "content": "def RAY_SCALE : β„• := 1000000000000000000000000000" }, { "name": "Ray.toZMod", "content": "protected def toZMod : UInt128 := r" }, { "name": "Ray.toRat", "content": "protected def toRat : β„š := r.toZMod.val / RAY_SCALE" }, { "name": "Ray.div", "content": "protected def div : Ray := (r.toZMod.val * RAY_SCALE / r'.toZMod.val : UInt128)" }, { "name": "SignedRay", "content": "def SignedRay := UInt128 Γ— (Unit βŠ• Unit)" }, { "name": "SignedRay.toRat", "content": "def toRat : β„š := if SierraBool.toBool w.2 then -(Ray.toRat w.1) else Ray.toRat w.1" } ]
[ { "name": "Rat.nat_cast_div_eq", "content": "theorem Rat.nat_cast_div_eq {a b : β„•} :\n ↑(a / b) = (a : β„š) / (b : β„š) - ↑(a % b) / (b : β„š)" }, { "name": "Ray.RAY_SCALE_rat_pos", "content": "theorem RAY_SCALE_rat_pos : 0 < (RAY_SCALE : β„š)" }, { "name": "Ray.RAY_SCALE_rat_ne_zero", "content": "theorem RAY_SCALE_rat_ne_zero : (RAY_SCALE : β„š) β‰  0" }, { "name": "SignedRay.div_def", "content": "theorem div_def :\n w₁ / wβ‚‚ = ⟨Ray.div (w₁.1 : Ray) (wβ‚‚.1 : Ray), Bool.toSierraBool (Bool.xor (SierraBool.toBool w₁.2) (SierraBool.toBool wβ‚‚.2))⟩" } ]
import CorelibVerification.Aux.ZMod import Aegis.Aux.Bool import Aegis.Aux.ZMod.DivMod open Sierra namespace Wad variable (w w' : Wad) end Wad def Ray : Type := UInt128 namespace Ray def RAY_SCALE : β„• := 1000000000000000000000000000 variable (r r' : Ray) protected def toZMod : UInt128 := r protected def toRat : β„š := r.toZMod.val / RAY_SCALE protected def div : Ray := (r.toZMod.val * RAY_SCALE / r'.toZMod.val : UInt128) end Ray namespace SignedWad variable (w w₁ wβ‚‚ : SignedWad) end SignedWad def SignedRay := UInt128 Γ— (Unit βŠ• Unit) namespace SignedRay variable (w w₁ wβ‚‚ : SignedRay) def toRat : β„š := if SierraBool.toBool w.2 then -(Ray.toRat w.1) else Ray.toRat w.1
theorem toRat_div (h₁ : w₁.1.val * Ray.RAY_SCALE / wβ‚‚.1.val < U128_MOD) (hβ‚‚ : wβ‚‚.1.val β‰  0): |SignedRay.toRat (w₁ / wβ‚‚) - SignedRay.toRat w₁ / SignedRay.toRat wβ‚‚| < 1 / Ray.RAY_SCALE :=
:= by rcases w₁ with ⟨w₁, sβ‚βŸ© rcases wβ‚‚ with ⟨wβ‚‚, sβ‚‚βŸ© rcases s₁ with (⟨⟨⟩⟩|⟨⟨⟩⟩) <;> rcases sβ‚‚ with (⟨⟨⟩⟩|⟨⟨⟩⟩) <;> dsimp only at h₁ hβ‚‚ <;> simp [div_def, toRat, Ray.div, Ray.toRat, Ray.toZMod, Nat.mod_eq_of_lt h₁, -one_div] <;> rw [Rat.nat_cast_div_eq, Nat.cast_mul, ZMod.natCast_val, ZMod.natCast_val, sub_div] <;> [rw [div_div_div_cancel_right _ Ray.RAY_SCALE_rat_ne_zero, div_div, mul_div_mul_right _ _ Ray.RAY_SCALE_rat_ne_zero, sub_right_comm, sub_self, zero_sub, abs_neg]; rw [neg_sub, div_neg, sub_neg_eq_add, div_div_div_cancel_right _ Ray.RAY_SCALE_rat_ne_zero, div_div (w₁.cast * _), mul_div_mul_right _ _ Ray.RAY_SCALE_rat_ne_zero, sub_add_cancel]; rw [neg_sub, neg_div, sub_neg_eq_add, div_div_div_cancel_right _ Ray.RAY_SCALE_rat_ne_zero, div_div (w₁.cast * _), mul_div_mul_right _ _ Ray.RAY_SCALE_rat_ne_zero, sub_add_cancel]; rw [div_div_div_cancel_right _ Ray.RAY_SCALE_rat_ne_zero, div_div, mul_div_mul_right _ _ Ray.RAY_SCALE_rat_ne_zero, sub_right_comm, sub_self, zero_sub, abs_neg]] <;> rw [abs_div, Nat.abs_cast, div_lt_div_right Ray.RAY_SCALE_rat_pos, abs_div, ← ZMod.natCast_val, Nat.abs_cast, Nat.abs_cast, div_lt_one (by rw [← Nat.cast_zero, Nat.cast_lt]; apply Nat.pos_of_ne_zero hβ‚‚), Nat.cast_lt] <;> apply Nat.mod_lt _ (Nat.pos_of_ne_zero hβ‚‚)
2
49
false
Applied verif.
490
Wad.toRat_nonneg
theorem toRat_nonneg : 0 ≀ w.toRat
wadray_verification
WadrayVerification/Aux.lean
[ "import Aegis.Aux.Bool", "import CorelibVerification.Aux.ZMod", "import Aegis.Aux.ZMod.DivMod" ]
[ { "name": "Sierra.UInt128", "module": "Aegis.Types" }, { "name": "ZMod", "module": "Mathlib.Data.ZMod.Defs" }, { "name": "NeZero", "module": "Init.Data.NeZero" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "ZMod.cast", "module": "Mathlib.Data.ZMod.Basic" }, { "name": "ZMod.val", "module": "Mathlib.Data.ZMod.Basic" } ]
[ { "name": "...", "content": "..." } ]
[ { "name": "Nat.cast_eq_zero", "module": "Mathlib.Algebra.CharZero.Defs" }, { "name": "Nat.cast_nonneg", "module": "Mathlib.Data.Nat.Cast.Order.Ring" }, { "name": "NeZero.ne", "module": "Init.Data.NeZero" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "Wad", "content": "def Wad : Type := UInt128" }, { "name": "Wad.WAD_SCALE", "content": "def WAD_SCALE : β„• := 1000000000000000000" }, { "name": "Wad.toZMod", "content": "protected def toZMod : UInt128 := w" }, { "name": "Wad.toRat", "content": "protected def toRat : β„š := w.toZMod.val / WAD_SCALE" } ]
[ { "name": "ZMod.cast_rat_nonneg", "content": "theorem ZMod.cast_rat_nonneg [NeZero n] (a : ZMod n) : 0 ≀ (a.cast : β„š)" }, { "name": "Wad.WAD_SCALE_rat_pos", "content": "theorem WAD_SCALE_rat_pos : 0 < (WAD_SCALE : β„š)" } ]
import CorelibVerification.Aux.ZMod import Aegis.Aux.Bool import Aegis.Aux.ZMod.DivMod open Sierra def Wad : Type := UInt128 namespace Wad def WAD_SCALE : β„• := 1000000000000000000 variable (w w' : Wad) protected def toZMod : UInt128 := w protected def toRat : β„š := w.toZMod.val / WAD_SCALE
theorem toRat_nonneg : 0 ≀ w.toRat :=
:= by simp [Wad.toRat] rw [le_div_iff WAD_SCALE_rat_pos, zero_mul] exact ZMod.cast_rat_nonneg (Wad.toZMod w)
2
14
false
Applied verif.
491
SignedWad.val_eq_of_toRat_eq
theorem val_eq_of_toRat_eq : w₁.toRat = wβ‚‚.toRat β†’ w₁.1 = wβ‚‚.1
wadray_verification
WadrayVerification/Aux.lean
[ "import Aegis.Aux.Bool", "import CorelibVerification.Aux.ZMod", "import Aegis.Aux.ZMod.DivMod" ]
[ { "name": "Sierra.UInt128", "module": "Aegis.Types" }, { "name": "Function.Injective", "module": "Init.Data.Function" }, { "name": "ZMod", "module": "Mathlib.Data.ZMod.Defs" }, { "name": "Sierra.U128_MOD", "module": "Aegis.Types" }, { "name": "ZMod.val", "module": "Mathlib.Data.ZMod.Basic" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "NeZero", "module": "Init.Data.NeZero" }, { "name": "ZMod.cast", "module": "Mathlib.Data.ZMod.Basic" } ]
[ { "name": "...", "content": "..." } ]
[ { "name": "Nat.cast_lt", "module": "Mathlib.Data.Nat.Cast.Order.Basic" }, { "name": "Nat.cast_nonneg", "module": "Mathlib.Data.Nat.Cast.Order.Ring" }, { "name": "le_of_eq", "module": "Mathlib.Order.Defs.PartialOrder" }, { "name": "ZMod.val_injective", "module": "Mathlib.Data.ZMod.Basic" }, { "name": "ne_of_lt", "module": "Mathlib.Order.Defs.PartialOrder" }, { "name": "Nat.cast_eq_zero", "module": "Mathlib.Algebra.CharZero.Defs" }, { "name": "NeZero.ne", "module": "Init.Data.NeZero" }, { "name": "Left.neg_nonpos_iff", "module": "Mathlib.Algebra.Order.Group.Unbundled.Basic" }, { "name": "SierraBool_toBool_inl", "module": "Aegis.Aux.Bool" }, { "name": "SierraBool_toBool_inr", "module": "Aegis.Aux.Bool" }, { "name": "eq_comm", "module": "Init.Core" }, { "name": "ite_false", "module": "Init.SimpLemmas" }, { "name": "ite_true", "module": "Init.SimpLemmas" }, { "name": "le_antisymm", "module": "Mathlib.Order.Defs.PartialOrder" }, { "name": "neg_inj", "module": "Mathlib.Algebra.Group.Basic" }, { "name": "zero_eq_neg", "module": "Mathlib.Algebra.Group.Basic" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "Wad", "content": "def Wad : Type := UInt128" }, { "name": "Wad.WAD_SCALE", "content": "def WAD_SCALE : β„• := 1000000000000000000" }, { "name": "Wad.toZMod", "content": "protected def toZMod : UInt128 := w" }, { "name": "Wad.toRat", "content": "protected def toRat : β„š := w.toZMod.val / WAD_SCALE" }, { "name": "Ray", "content": "def Ray : Type := UInt128" }, { "name": "Ray.toZMod", "content": "protected def toZMod : UInt128 := r" }, { "name": "SignedWad", "content": "def SignedWad := UInt128 Γ— (Unit βŠ• Unit)" }, { "name": "SignedWad.toRat", "content": "def toRat : β„š := if w.2 then -(Wad.toRat w.1) else Wad.toRat w.1" } ]
[ { "name": "ZMod.cast_rat_nonneg", "content": "theorem ZMod.cast_rat_nonneg [NeZero n] (a : ZMod n) : 0 ≀ (a.cast : β„š)" }, { "name": "Wad.WAD_SCALE_rat_pos", "content": "theorem WAD_SCALE_rat_pos : 0 < (WAD_SCALE : β„š)" }, { "name": "Wad.toRat_lt_toRat_of_val_lt_val", "content": "theorem toRat_lt_toRat_of_val_lt_val (h : @ZMod.val U128_MOD w < @ZMod.val U128_MOD w') :\n w.toRat < w'.toRat" }, { "name": "Wad.toRat_injective", "content": "theorem toRat_injective : Function.Injective Wad.toRat" }, { "name": "Wad.toRat_nonneg", "content": "theorem toRat_nonneg : 0 ≀ w.toRat" }, { "name": "Wad.toRat_zero", "content": "@[simp]\ntheorem toRat_zero : (0 : Wad).toRat = 0" } ]
import CorelibVerification.Aux.ZMod import Aegis.Aux.Bool import Aegis.Aux.ZMod.DivMod open Sierra def Wad : Type := UInt128 namespace Wad def WAD_SCALE : β„• := 1000000000000000000 variable (w w' : Wad) protected def toZMod : UInt128 := w protected def toRat : β„š := w.toZMod.val / WAD_SCALE end Wad def Ray : Type := UInt128 namespace Ray variable (r r' : Ray) protected def toZMod : UInt128 := r end Ray def SignedWad := UInt128 Γ— (Unit βŠ• Unit) namespace SignedWad variable (w w₁ wβ‚‚ : SignedWad) def toRat : β„š := if w.2 then -(Wad.toRat w.1) else Wad.toRat w.1
theorem val_eq_of_toRat_eq : w₁.toRat = wβ‚‚.toRat β†’ w₁.1 = wβ‚‚.1 :=
:= by rcases w₁ with ⟨w₁, sβ‚βŸ© rcases wβ‚‚ with ⟨wβ‚‚, sβ‚‚βŸ© intro h cases s₁ <;> cases sβ‚‚ Β· have := Wad.toRat_injective h cases this rfl Β· simp only [toRat, SierraBool_toBool_inl, ite_false, SierraBool_toBool_inr, ite_true] at * have h' : Wad.toRat w₁ = 0 := by apply le_antisymm _ _ Β· rw [h, Left.neg_nonpos_iff] apply Wad.toRat_nonneg Β· apply Wad.toRat_nonneg rw [h', zero_eq_neg, ← Wad.toRat_zero] at h have := Wad.toRat_injective h; cases this rw [← Wad.toRat_zero] at h' have := Wad.toRat_injective h'; cases this rfl Β· simp only [toRat, SierraBool_toBool_inr, ite_true, SierraBool_toBool_inl, ite_false] at * have h' : Wad.toRat wβ‚‚ = 0 := by apply le_antisymm _ _ Β· rw [← h, Left.neg_nonpos_iff] apply Wad.toRat_nonneg Β· apply Wad.toRat_nonneg rw [h', eq_comm, zero_eq_neg, ← Wad.toRat_zero] at h have := Wad.toRat_injective h; cases this rw [← Wad.toRat_zero] at h' have := Wad.toRat_injective h'; cases this rfl Β· simp only [toRat, SierraBool_toBool_inr, ite_true, neg_inj] at h have := Wad.toRat_injective h cases this rfl
3
36
false
Applied verif.
492
SignedRay.val_eq_of_toRat_eq
theorem val_eq_of_toRat_eq : w₁.toRat = wβ‚‚.toRat β†’ w₁.1 = wβ‚‚.1
wadray_verification
WadrayVerification/Aux.lean
[ "import Aegis.Aux.Bool", "import CorelibVerification.Aux.ZMod", "import Aegis.Aux.ZMod.DivMod" ]
[ { "name": "SierraBool.toBool", "module": "Aegis.Aux.Bool" }, { "name": "Sierra.UInt128", "module": "Aegis.Types" }, { "name": "Function.Injective", "module": "Init.Data.Function" }, { "name": "ZMod", "module": "Mathlib.Data.ZMod.Defs" }, { "name": "Sierra.U128_MOD", "module": "Aegis.Types" }, { "name": "ZMod.val", "module": "Mathlib.Data.ZMod.Basic" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "NeZero", "module": "Init.Data.NeZero" }, { "name": "ZMod.cast", "module": "Mathlib.Data.ZMod.Basic" } ]
[ { "name": "...", "content": "..." } ]
[ { "name": "Nat.cast_lt", "module": "Mathlib.Data.Nat.Cast.Order.Basic" }, { "name": "Nat.cast_nonneg", "module": "Mathlib.Data.Nat.Cast.Order.Ring" }, { "name": "le_of_eq", "module": "Mathlib.Order.Defs.PartialOrder" }, { "name": "ZMod.val_injective", "module": "Mathlib.Data.ZMod.Basic" }, { "name": "ne_of_lt", "module": "Mathlib.Order.Defs.PartialOrder" }, { "name": "Nat.cast_eq_zero", "module": "Mathlib.Algebra.CharZero.Defs" }, { "name": "NeZero.ne", "module": "Init.Data.NeZero" }, { "name": "Left.neg_nonpos_iff", "module": "Mathlib.Algebra.Order.Group.Unbundled.Basic" }, { "name": "SierraBool_toBool_inl", "module": "Aegis.Aux.Bool" }, { "name": "SierraBool_toBool_inr", "module": "Aegis.Aux.Bool" }, { "name": "eq_comm", "module": "Init.Core" }, { "name": "ite_false", "module": "Init.SimpLemmas" }, { "name": "ite_true", "module": "Init.SimpLemmas" }, { "name": "le_antisymm", "module": "Mathlib.Order.Defs.PartialOrder" }, { "name": "neg_inj", "module": "Mathlib.Algebra.Group.Basic" }, { "name": "zero_eq_neg", "module": "Mathlib.Algebra.Group.Basic" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "Wad", "content": "def Wad : Type := UInt128" }, { "name": "Wad.toZMod", "content": "protected def toZMod : UInt128 := w" }, { "name": "Ray", "content": "def Ray : Type := UInt128" }, { "name": "Ray.RAY_SCALE", "content": "def RAY_SCALE : β„• := 1000000000000000000000000000" }, { "name": "Ray.toZMod", "content": "protected def toZMod : UInt128 := r" }, { "name": "Ray.toRat", "content": "protected def toRat : β„š := r.toZMod.val / RAY_SCALE" }, { "name": "SignedRay", "content": "def SignedRay := UInt128 Γ— (Unit βŠ• Unit)" }, { "name": "SignedRay.toRat", "content": "def toRat : β„š := if SierraBool.toBool w.2 then -(Ray.toRat w.1) else Ray.toRat w.1" } ]
[ { "name": "ZMod.cast_rat_nonneg", "content": "theorem ZMod.cast_rat_nonneg [NeZero n] (a : ZMod n) : 0 ≀ (a.cast : β„š)" }, { "name": "Ray.RAY_SCALE_rat_pos", "content": "theorem RAY_SCALE_rat_pos : 0 < (RAY_SCALE : β„š)" }, { "name": "Ray.toRat_lt_toRat_of_val_lt_val", "content": "theorem toRat_lt_toRat_of_val_lt_val (h : @ZMod.val U128_MOD r < @ZMod.val U128_MOD r') :\n r.toRat < r'.toRat" }, { "name": "Ray.toRat_injective", "content": "theorem toRat_injective : Function.Injective Ray.toRat" }, { "name": "Ray.toRat_nonneg", "content": "theorem toRat_nonneg : 0 ≀ r.toRat" }, { "name": "Ray.toRat_zero", "content": " @[simp]\ntheorem toRat_zero : (0 : Ray).toRat = 0" } ]
import CorelibVerification.Aux.ZMod import Aegis.Aux.Bool import Aegis.Aux.ZMod.DivMod open Sierra def Wad : Type := UInt128 namespace Wad variable (w w' : Wad) protected def toZMod : UInt128 := w end Wad def Ray : Type := UInt128 namespace Ray def RAY_SCALE : β„• := 1000000000000000000000000000 variable (r r' : Ray) protected def toZMod : UInt128 := r protected def toRat : β„š := r.toZMod.val / RAY_SCALE end Ray namespace SignedWad variable (w w₁ wβ‚‚ : SignedWad) end SignedWad def SignedRay := UInt128 Γ— (Unit βŠ• Unit) namespace SignedRay variable (w w₁ wβ‚‚ : SignedRay) def toRat : β„š := if SierraBool.toBool w.2 then -(Ray.toRat w.1) else Ray.toRat w.1
theorem val_eq_of_toRat_eq : w₁.toRat = wβ‚‚.toRat β†’ w₁.1 = wβ‚‚.1 :=
:= by rcases w₁ with ⟨w₁, sβ‚βŸ© rcases wβ‚‚ with ⟨wβ‚‚, sβ‚‚βŸ© intro h cases s₁ <;> cases sβ‚‚ Β· have := Ray.toRat_injective h cases this rfl Β· simp only [toRat, SierraBool_toBool_inl, ite_false, SierraBool_toBool_inr, ite_true] at * have h' : Ray.toRat w₁ = 0 := by apply le_antisymm _ _ Β· rw [h, Left.neg_nonpos_iff] apply Ray.toRat_nonneg Β· apply Ray.toRat_nonneg rw [h', zero_eq_neg, ← Ray.toRat_zero] at h have := Ray.toRat_injective h; cases this rw [← Ray.toRat_zero] at h' have := Ray.toRat_injective h'; cases this rfl Β· simp only [toRat, SierraBool_toBool_inr, ite_true, SierraBool_toBool_inl, ite_false] at * have h' : Ray.toRat wβ‚‚ = 0 := by apply le_antisymm _ _ Β· rw [← h, Left.neg_nonpos_iff] apply Ray.toRat_nonneg Β· apply Ray.toRat_nonneg rw [h', eq_comm, zero_eq_neg, ← Ray.toRat_zero] at h have := Ray.toRat_injective h; cases this rw [← Ray.toRat_zero] at h' have := Ray.toRat_injective h'; cases this rfl Β· simp only [toRat, SierraBool_toBool_inr, ite_true, neg_inj] at h have := Ray.toRat_injective h cases this rfl
3
37
false
Applied verif.
493
Ray.toRat_nonneg
theorem toRat_nonneg : 0 ≀ r.toRat
wadray_verification
WadrayVerification/Aux.lean
[ "import Aegis.Aux.Bool", "import CorelibVerification.Aux.ZMod", "import Aegis.Aux.ZMod.DivMod" ]
[ { "name": "Sierra.UInt128", "module": "Aegis.Types" }, { "name": "ZMod", "module": "Mathlib.Data.ZMod.Defs" }, { "name": "NeZero", "module": "Init.Data.NeZero" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "ZMod.cast", "module": "Mathlib.Data.ZMod.Basic" }, { "name": "ZMod.val", "module": "Mathlib.Data.ZMod.Basic" } ]
[ { "name": "...", "content": "..." } ]
[ { "name": "Nat.cast_eq_zero", "module": "Mathlib.Algebra.CharZero.Defs" }, { "name": "Nat.cast_nonneg", "module": "Mathlib.Data.Nat.Cast.Order.Ring" }, { "name": "NeZero.ne", "module": "Init.Data.NeZero" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "Ray", "content": "def Ray : Type := UInt128" }, { "name": "Ray.RAY_SCALE", "content": "def RAY_SCALE : β„• := 1000000000000000000000000000" }, { "name": "Ray.toZMod", "content": "protected def toZMod : UInt128 := r" }, { "name": "Ray.toRat", "content": "protected def toRat : β„š := r.toZMod.val / RAY_SCALE" } ]
[ { "name": "ZMod.cast_rat_nonneg", "content": "theorem ZMod.cast_rat_nonneg [NeZero n] (a : ZMod n) : 0 ≀ (a.cast : β„š)" }, { "name": "Ray.RAY_SCALE_rat_pos", "content": "theorem RAY_SCALE_rat_pos : 0 < (RAY_SCALE : β„š)" } ]
import CorelibVerification.Aux.ZMod import Aegis.Aux.Bool import Aegis.Aux.ZMod.DivMod open Sierra namespace Wad variable (w w' : Wad) end Wad def Ray : Type := UInt128 namespace Ray def RAY_SCALE : β„• := 1000000000000000000000000000 variable (r r' : Ray) protected def toZMod : UInt128 := r protected def toRat : β„š := r.toZMod.val / RAY_SCALE
theorem toRat_nonneg : 0 ≀ r.toRat :=
:= by simp [Ray.toRat] rw [le_div_iff RAY_SCALE_rat_pos, zero_mul] exact ZMod.cast_rat_nonneg (Ray.toZMod r)
2
14
false
Applied verif.
494
Ray.toRat_div
theorem toRat_div (h : r.toZMod.val * RAY_SCALE / r'.toZMod.val < U128_MOD) (h' : r'.toZMod.val β‰  0) : |(r / r').toRat - r.toRat / r'.toRat| < 1 / RAY_SCALE
wadray_verification
WadrayVerification/Aux.lean
[ "import Aegis.Aux.Bool", "import CorelibVerification.Aux.ZMod", "import Aegis.Aux.ZMod.DivMod" ]
[ { "name": "Sierra.UInt128", "module": "Aegis.Types" }, { "name": "Sierra.U128_MOD", "module": "Aegis.Types" }, { "name": "Nat", "module": "Init.Prelude" }, { "name": "Rat", "module": "Init.Data.Rat.Basic" }, { "name": "ZMod", "module": "Mathlib.Data.ZMod.Defs" }, { "name": "ZMod.val", "module": "Mathlib.Data.ZMod.Basic" } ]
[ { "name": "Ray.div", "content": "protected def Ray.div : Ray := (r.toZMod.val * RAY_SCALE / r'.toZMod.val : UInt128)" }, { "name": "", "content": "instance : Div Ray := ⟨Ray.div⟩" } ]
[ { "name": "Nat.cast_div", "module": "Mathlib.Data.Nat.Cast.Field" }, { "name": "Nat.cast_ne_zero", "module": "Mathlib.Algebra.CharZero.Defs" }, { "name": "Nat.cast_sub", "module": "Mathlib.Data.Int.Cast.Basic" }, { "name": "Nat.div_eq_sub_mod_div", "module": "Init.Data.Nat.Lemmas" }, { "name": "Nat.dvd_sub_mod", "module": "Init.Data.Nat.Lemmas" }, { "name": "Nat.mod_le", "module": "Init.Data.Nat.Div.Basic" }, { "name": "sub_div", "module": "Mathlib.Algebra.Field.Basic" }, { "name": "Nat.abs_cast", "module": "Mathlib.Data.Nat.Cast.Order.Ring" }, { "name": "Nat.cast_lt", "module": "Mathlib.Data.Nat.Cast.Order.Basic" }, { "name": "Nat.cast_mul", "module": "Mathlib.Data.Nat.Cast.Basic" }, { "name": "Nat.cast_pos", "module": "Mathlib.Data.Nat.Cast.Order.Ring" }, { "name": "Nat.mod_eq_of_lt", "module": "Init.Data.Nat.Div.Basic" }, { "name": "Nat.mod_lt", "module": "Init.Prelude" }, { "name": "Nat.pos_of_ne_zero", "module": "Init.Data.Nat.Basic" }, { "name": "ZMod.val_natCast", "module": "Mathlib.Data.ZMod.Basic" }, { "name": "abs_div", "module": "Mathlib.Algebra.Order.Field.Basic" }, { "name": "abs_neg", "module": "Mathlib.Algebra.Order.Group.Unbundled.Abs" }, { "name": "div_div", "module": "Mathlib.Algebra.Group.Basic" }, { "name": "div_div_div_cancel_right", "module": "Mathlib.Algebra.Group.Basic" }, { "name": "div_lt_one", "module": "Mathlib.Algebra.Order.Field.Basic" }, { "name": "mul_div_mul_right", "module": "Mathlib.Algebra.GroupWithZero.Units.Basic" }, { "name": "sub_sub_cancel_left", "module": "Mathlib.Algebra.Group.Basic" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "Ray", "content": "def Ray : Type := UInt128" }, { "name": "Ray.RAY_SCALE", "content": "def RAY_SCALE : β„• := 1000000000000000000000000000" }, { "name": "Ray.toZMod", "content": "protected def toZMod : UInt128 := r" }, { "name": "Ray.toRat", "content": "protected def toRat : β„š := r.toZMod.val / RAY_SCALE" } ]
[ { "name": "Rat.nat_cast_div_eq", "content": "theorem Rat.nat_cast_div_eq {a b : β„•} :\n ↑(a / b) = (a : β„š) / (b : β„š) - ↑(a % b) / (b : β„š)" }, { "name": "Ray.RAY_SCALE_rat_pos", "content": "theorem RAY_SCALE_rat_pos : 0 < (RAY_SCALE : β„š)" }, { "name": "Ray.RAY_SCALE_rat_ne_zero", "content": "theorem RAY_SCALE_rat_ne_zero : (RAY_SCALE : β„š) β‰  0" }, { "name": "Ray.div_def", "content": "protected theorem div_def :\n r / r' = (r.toZMod.val * RAY_SCALE / r'.toZMod.val : UInt128)" } ]
import CorelibVerification.Aux.ZMod import Aegis.Aux.Bool import Aegis.Aux.ZMod.DivMod open Sierra namespace Wad variable (w w' : Wad) end Wad def Ray : Type := UInt128 namespace Ray def RAY_SCALE : β„• := 1000000000000000000000000000 variable (r r' : Ray) protected def toZMod : UInt128 := r protected def toRat : β„š := r.toZMod.val / RAY_SCALE
theorem toRat_div (h : r.toZMod.val * RAY_SCALE / r'.toZMod.val < U128_MOD) (h' : r'.toZMod.val β‰  0) : |(r / r').toRat - r.toRat / r'.toRat| < 1 / RAY_SCALE :=
:= by have h'' : 0 < r'.toZMod.val := Nat.pos_of_ne_zero h' have h''' : (0 : β„š) < r'.toZMod.val := Nat.cast_pos.mpr h'' simp only [Ray.toRat, Ray.toZMod, Ray.div_def, ZMod.val_natCast] at * rw [Nat.mod_eq_of_lt h, Rat.nat_cast_div_eq, sub_div, Nat.cast_mul, div_div, mul_div_mul_right _ _ RAY_SCALE_rat_ne_zero, div_div_div_cancel_right _ RAY_SCALE_rat_ne_zero, sub_sub_cancel_left, abs_neg, abs_div, Nat.abs_cast, div_lt_div_right RAY_SCALE_rat_pos, abs_div, Nat.abs_cast, Nat.abs_cast, div_lt_one h''', Nat.cast_lt] apply Nat.mod_lt _ h''
2
34
false
Applied verif.
495
SignedWad.toRat_eq_zero_iff
theorem toRat_eq_zero_iff : w.toRat = 0 ↔ w.1 = 0
wadray_verification
WadrayVerification/Aux.lean
[ "import Aegis.Aux.Bool", "import CorelibVerification.Aux.ZMod", "import Aegis.Aux.ZMod.DivMod" ]
[ { "name": "Sierra.UInt128", "module": "Aegis.Types" }, { "name": "ZMod", "module": "Mathlib.Data.ZMod.Defs" } ]
[ { "name": "...", "content": "..." } ]
[ { "name": "ZMod.cast_rat_eq_zero_iff", "module": "CorelibVerification.Aux.ZMod" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "Wad", "content": "def Wad : Type := UInt128" }, { "name": "Wad.WAD_SCALE", "content": "def WAD_SCALE : β„• := 1000000000000000000" }, { "name": "Wad.toZMod", "content": "protected def toZMod : UInt128 := w" }, { "name": "Wad.toRat", "content": "protected def toRat : β„š := w.toZMod.val / WAD_SCALE" }, { "name": "Ray", "content": "def Ray : Type := UInt128" }, { "name": "Ray.toZMod", "content": "protected def toZMod : UInt128 := r" }, { "name": "Ray.add", "content": "protected def add : Ray := r.toZMod + r'.toZMod" }, { "name": "SignedWad", "content": "def SignedWad := UInt128 Γ— (Unit βŠ• Unit)" }, { "name": "SignedWad.toRat", "content": "def toRat : β„š := if w.2 then -(Wad.toRat w.1) else Wad.toRat w.1" } ]
[ { "name": "Wad.WAD_SCALE_pos", "content": "theorem WAD_SCALE_pos : 0 < WAD_SCALE" } ]
import CorelibVerification.Aux.ZMod import Aegis.Aux.Bool import Aegis.Aux.ZMod.DivMod open Sierra def Wad : Type := UInt128 namespace Wad def WAD_SCALE : β„• := 1000000000000000000 variable (w w' : Wad) protected def toZMod : UInt128 := w protected def toRat : β„š := w.toZMod.val / WAD_SCALE end Wad def Ray : Type := UInt128 namespace Ray variable (r r' : Ray) protected def toZMod : UInt128 := r protected def add : Ray := r.toZMod + r'.toZMod end Ray def SignedWad := UInt128 Γ— (Unit βŠ• Unit) namespace SignedWad variable (w w₁ wβ‚‚ : SignedWad) def toRat : β„š := if w.2 then -(Wad.toRat w.1) else Wad.toRat w.1
theorem toRat_eq_zero_iff : w.toRat = 0 ↔ w.1 = 0 :=
:= by have := Wad.WAD_SCALE_pos rcases w with ⟨w, (s|s)⟩ <;> cases s <;> simp only [SignedWad.toRat, Wad.toRat, Wad.toZMod] <;> aesop (add simp ZMod.cast_rat_eq_zero_iff)
2
11
false
Applied verif.
496
SignedRay.toRat_eq_zero_iff
theorem toRat_eq_zero_iff : w.toRat = 0 ↔ w.1 = 0
wadray_verification
WadrayVerification/Aux.lean
[ "import Aegis.Aux.Bool", "import CorelibVerification.Aux.ZMod", "import Aegis.Aux.ZMod.DivMod" ]
[ { "name": "Sierra.UInt128", "module": "Aegis.Types" }, { "name": "SierraBool.toBool", "module": "Aegis.Aux.Bool" }, { "name": "ZMod", "module": "Mathlib.Data.ZMod.Defs" } ]
[ { "name": "...", "content": "..." } ]
[ { "name": "ZMod.cast_rat_eq_zero_iff", "module": "CorelibVerification.Aux.ZMod" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "Ray", "content": "def Ray : Type := UInt128" }, { "name": "Ray.RAY_SCALE", "content": "def RAY_SCALE : β„• := 1000000000000000000000000000" }, { "name": "Ray.toZMod", "content": "protected def toZMod : UInt128 := r" }, { "name": "Ray.toRat", "content": "protected def toRat : β„š := r.toZMod.val / RAY_SCALE" }, { "name": "Ray.add", "content": "protected def add : Ray := r.toZMod + r'.toZMod" }, { "name": "SignedRay", "content": "def SignedRay := UInt128 Γ— (Unit βŠ• Unit)" }, { "name": "SignedRay.toRat", "content": "def toRat : β„š := if SierraBool.toBool w.2 then -(Ray.toRat w.1) else Ray.toRat w.1" } ]
[ { "name": "Ray.RAY_SCALE_pos", "content": "theorem RAY_SCALE_pos : 0 < RAY_SCALE" } ]
import CorelibVerification.Aux.ZMod import Aegis.Aux.Bool import Aegis.Aux.ZMod.DivMod open Sierra namespace Wad variable (w w' : Wad) end Wad def Ray : Type := UInt128 namespace Ray def RAY_SCALE : β„• := 1000000000000000000000000000 variable (r r' : Ray) protected def toZMod : UInt128 := r protected def toRat : β„š := r.toZMod.val / RAY_SCALE protected def add : Ray := r.toZMod + r'.toZMod end Ray namespace SignedWad variable (w w₁ wβ‚‚ : SignedWad) end SignedWad def SignedRay := UInt128 Γ— (Unit βŠ• Unit) namespace SignedRay variable (w w₁ wβ‚‚ : SignedRay) def toRat : β„š := if SierraBool.toBool w.2 then -(Ray.toRat w.1) else Ray.toRat w.1
theorem toRat_eq_zero_iff : w.toRat = 0 ↔ w.1 = 0 :=
:= by have := Ray.RAY_SCALE_pos rcases w with ⟨w, (s|s)⟩ <;> cases s <;> simp only [SignedRay.toRat, Ray.toRat, Ray.toZMod] <;> aesop (add simp ZMod.cast_rat_eq_zero_iff)
3
11
false
Applied verif.
497
SignedWad.val_eq_zero_of_toRat_neg
theorem val_eq_zero_of_toRat_neg (x : Wad) (p q : Unit) (h : SignedWad.toRat ((x, .inl p) : SignedWad) = SignedWad.toRat ((x, .inr q) : SignedWad)) : x = 0
wadray_verification
WadrayVerification/Aux.lean
[ "import Aegis.Aux.Bool", "import CorelibVerification.Aux.ZMod", "import Aegis.Aux.ZMod.DivMod" ]
[ { "name": "Sierra.UInt128", "module": "Aegis.Types" }, { "name": "Unit", "module": "Init.Prelude" }, { "name": "Function.Injective", "module": "Init.Data.Function" }, { "name": "ZMod", "module": "Mathlib.Data.ZMod.Defs" }, { "name": "Sierra.U128_MOD", "module": "Aegis.Types" }, { "name": "ZMod.val", "module": "Mathlib.Data.ZMod.Basic" }, { "name": "Nat", "module": "Init.Prelude" } ]
[ { "name": "...", "content": "..." } ]
[ { "name": "Nat.cast_lt", "module": "Mathlib.Data.Nat.Cast.Order.Basic" }, { "name": "Nat.cast_nonneg", "module": "Mathlib.Data.Nat.Cast.Order.Ring" }, { "name": "le_of_eq", "module": "Mathlib.Order.Defs.PartialOrder" }, { "name": "ZMod.val_injective", "module": "Mathlib.Data.ZMod.Basic" }, { "name": "ne_of_lt", "module": "Mathlib.Order.Defs.PartialOrder" }, { "name": "SierraBool_toBool_inl", "module": "Aegis.Aux.Bool" }, { "name": "SierraBool_toBool_inr", "module": "Aegis.Aux.Bool" }, { "name": "ite_false", "module": "Init.SimpLemmas" }, { "name": "ite_true", "module": "Init.SimpLemmas" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "Wad", "content": "def Wad : Type := UInt128" }, { "name": "Wad.WAD_SCALE", "content": "def WAD_SCALE : β„• := 1000000000000000000" }, { "name": "Wad.toZMod", "content": "protected def toZMod : UInt128 := w" }, { "name": "Wad.toRat", "content": "protected def toRat : β„š := w.toZMod.val / WAD_SCALE" }, { "name": "Ray", "content": "def Ray : Type := UInt128" }, { "name": "Ray.toZMod", "content": "protected def toZMod : UInt128 := r" }, { "name": "SignedWad", "content": "def SignedWad := UInt128 Γ— (Unit βŠ• Unit)" }, { "name": "SignedWad.toRat", "content": "def toRat : β„š := if w.2 then -(Wad.toRat w.1) else Wad.toRat w.1" } ]
[ { "name": "Wad.WAD_SCALE_rat_pos", "content": "theorem WAD_SCALE_rat_pos : 0 < (WAD_SCALE : β„š)" }, { "name": "Wad.toRat_lt_toRat_of_val_lt_val", "content": "theorem toRat_lt_toRat_of_val_lt_val (h : @ZMod.val U128_MOD w < @ZMod.val U128_MOD w') :\n w.toRat < w'.toRat" }, { "name": "Wad.toRat_injective", "content": "theorem toRat_injective : Function.Injective Wad.toRat" }, { "name": "Wad.toRat_zero", "content": "@[simp]\ntheorem toRat_zero : (0 : Wad).toRat = 0" } ]
import CorelibVerification.Aux.ZMod import Aegis.Aux.Bool import Aegis.Aux.ZMod.DivMod open Sierra def Wad : Type := UInt128 namespace Wad def WAD_SCALE : β„• := 1000000000000000000 variable (w w' : Wad) protected def toZMod : UInt128 := w protected def toRat : β„š := w.toZMod.val / WAD_SCALE end Wad def Ray : Type := UInt128 namespace Ray variable (r r' : Ray) protected def toZMod : UInt128 := r end Ray def SignedWad := UInt128 Γ— (Unit βŠ• Unit) namespace SignedWad variable (w w₁ wβ‚‚ : SignedWad) def toRat : β„š := if w.2 then -(Wad.toRat w.1) else Wad.toRat w.1
theorem val_eq_zero_of_toRat_neg (x : Wad) (p q : Unit) (h : SignedWad.toRat ((x, .inl p) : SignedWad) = SignedWad.toRat ((x, .inr q) : SignedWad)) : x = 0 :=
:= by simp only [toRat, SierraBool_toBool_inl, ite_false, SierraBool_toBool_inr, ite_true, eq_neg_self_iff] at h rw [← Wad.toRat_zero] at h exact Wad.toRat_injective h
3
26
false
Applied verif.
498
SignedWad.val_eq_zero_of_toRat_neg'
theorem val_eq_zero_of_toRat_neg' (x : Wad) (p q : Unit) (h : SignedWad.toRat ((x, .inr p) : SignedWad) = SignedWad.toRat ((x, .inl q) : SignedWad)) : x = 0
wadray_verification
WadrayVerification/Aux.lean
[ "import Aegis.Aux.Bool", "import CorelibVerification.Aux.ZMod", "import Aegis.Aux.ZMod.DivMod" ]
[ { "name": "Sierra.UInt128", "module": "Aegis.Types" }, { "name": "Unit", "module": "Init.Prelude" }, { "name": "Function.Injective", "module": "Init.Data.Function" }, { "name": "ZMod", "module": "Mathlib.Data.ZMod.Defs" }, { "name": "Sierra.U128_MOD", "module": "Aegis.Types" }, { "name": "ZMod.val", "module": "Mathlib.Data.ZMod.Basic" }, { "name": "Nat", "module": "Init.Prelude" } ]
[ { "name": "...", "content": "..." } ]
[ { "name": "Nat.cast_lt", "module": "Mathlib.Data.Nat.Cast.Order.Basic" }, { "name": "Nat.cast_nonneg", "module": "Mathlib.Data.Nat.Cast.Order.Ring" }, { "name": "le_of_eq", "module": "Mathlib.Order.Defs.PartialOrder" }, { "name": "ZMod.val_injective", "module": "Mathlib.Data.ZMod.Basic" }, { "name": "ne_of_lt", "module": "Mathlib.Order.Defs.PartialOrder" }, { "name": "SierraBool_toBool_inl", "module": "Aegis.Aux.Bool" }, { "name": "SierraBool_toBool_inr", "module": "Aegis.Aux.Bool" }, { "name": "ite_false", "module": "Init.SimpLemmas" }, { "name": "ite_true", "module": "Init.SimpLemmas" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "Wad", "content": "def Wad : Type := UInt128" }, { "name": "Wad.WAD_SCALE", "content": "def WAD_SCALE : β„• := 1000000000000000000" }, { "name": "Wad.toZMod", "content": "protected def toZMod : UInt128 := w" }, { "name": "Wad.toRat", "content": "protected def toRat : β„š := w.toZMod.val / WAD_SCALE" }, { "name": "Ray", "content": "def Ray : Type := UInt128" }, { "name": "Ray.toZMod", "content": "protected def toZMod : UInt128 := r" }, { "name": "SignedWad", "content": "def SignedWad := UInt128 Γ— (Unit βŠ• Unit)" }, { "name": "SignedWad.toRat", "content": "def toRat : β„š := if w.2 then -(Wad.toRat w.1) else Wad.toRat w.1" } ]
[ { "name": "Wad.WAD_SCALE_rat_pos", "content": "theorem WAD_SCALE_rat_pos : 0 < (WAD_SCALE : β„š)" }, { "name": "Wad.toRat_lt_toRat_of_val_lt_val", "content": "theorem toRat_lt_toRat_of_val_lt_val (h : @ZMod.val U128_MOD w < @ZMod.val U128_MOD w') :\n w.toRat < w'.toRat" }, { "name": "Wad.toRat_injective", "content": "theorem toRat_injective : Function.Injective Wad.toRat" }, { "name": "Wad.toRat_zero", "content": "@[simp]\ntheorem toRat_zero : (0 : Wad).toRat = 0" } ]
import CorelibVerification.Aux.ZMod import Aegis.Aux.Bool import Aegis.Aux.ZMod.DivMod open Sierra def Wad : Type := UInt128 namespace Wad def WAD_SCALE : β„• := 1000000000000000000 variable (w w' : Wad) protected def toZMod : UInt128 := w protected def toRat : β„š := w.toZMod.val / WAD_SCALE end Wad def Ray : Type := UInt128 namespace Ray variable (r r' : Ray) protected def toZMod : UInt128 := r end Ray def SignedWad := UInt128 Γ— (Unit βŠ• Unit) namespace SignedWad variable (w w₁ wβ‚‚ : SignedWad) def toRat : β„š := if w.2 then -(Wad.toRat w.1) else Wad.toRat w.1
theorem val_eq_zero_of_toRat_neg' (x : Wad) (p q : Unit) (h : SignedWad.toRat ((x, .inr p) : SignedWad) = SignedWad.toRat ((x, .inl q) : SignedWad)) : x = 0 :=
:= by simp only [toRat, SierraBool_toBool_inr, ite_true, SierraBool_toBool_inl, ite_false, neg_eq_self_iff] at h rw [← Wad.toRat_zero] at h exact Wad.toRat_injective h
3
26
false
Applied verif.
499
Wad.toRat_le_toRat_of_val_le_val
theorem toRat_le_toRat_of_val_le_val (h : @ZMod.val U128_MOD w ≀ @ZMod.val U128_MOD w') : w.toRat ≀ w'.toRat
wadray_verification
WadrayVerification/Aux.lean
[ "import Aegis.Aux.Bool", "import CorelibVerification.Aux.ZMod", "import Aegis.Aux.ZMod.DivMod" ]
[ { "name": "Sierra.UInt128", "module": "Aegis.Types" }, { "name": "Sierra.U128_MOD", "module": "Aegis.Types" }, { "name": "ZMod", "module": "Mathlib.Data.ZMod.Defs" }, { "name": "ZMod.val", "module": "Mathlib.Data.ZMod.Basic" }, { "name": "Nat", "module": "Init.Prelude" } ]
[ { "name": "...", "content": "..." } ]
[ { "name": "Nat.cast_le", "module": "Mathlib.Data.Nat.Cast.Order.Basic" }, { "name": "Nat.cast_nonneg", "module": "Mathlib.Data.Nat.Cast.Order.Ring" }, { "name": "le_of_eq", "module": "Mathlib.Order.Defs.PartialOrder" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "Wad", "content": "def Wad : Type := UInt128" }, { "name": "Wad.WAD_SCALE", "content": "def WAD_SCALE : β„• := 1000000000000000000" }, { "name": "Wad.toZMod", "content": "protected def toZMod : UInt128 := w" }, { "name": "Wad.toRat", "content": "protected def toRat : β„š := w.toZMod.val / WAD_SCALE" } ]
[ { "name": "Wad.WAD_SCALE_rat_pos", "content": "theorem WAD_SCALE_rat_pos : 0 < (WAD_SCALE : β„š)" } ]
import CorelibVerification.Aux.ZMod import Aegis.Aux.Bool import Aegis.Aux.ZMod.DivMod open Sierra def Wad : Type := UInt128 namespace Wad def WAD_SCALE : β„• := 1000000000000000000 variable (w w' : Wad) protected def toZMod : UInt128 := w protected def toRat : β„š := w.toZMod.val / WAD_SCALE
theorem toRat_le_toRat_of_val_le_val (h : @ZMod.val U128_MOD w ≀ @ZMod.val U128_MOD w') : w.toRat ≀ w'.toRat :=
:= by simp only [Wad.toRat] apply div_le_div Β· exact Nat.cast_nonneg (ZMod.val (Wad.toZMod w')) Β· rwa [Nat.cast_le] Β· exact WAD_SCALE_rat_pos Β· apply le_of_eq; rfl
2
12
false
Applied verif.
500
Wad.toRat_lt_toRat_of_val_lt_val
theorem toRat_lt_toRat_of_val_lt_val (h : @ZMod.val U128_MOD w < @ZMod.val U128_MOD w') : w.toRat < w'.toRat
wadray_verification
WadrayVerification/Aux.lean
[ "import Aegis.Aux.Bool", "import CorelibVerification.Aux.ZMod", "import Aegis.Aux.ZMod.DivMod" ]
[ { "name": "Sierra.UInt128", "module": "Aegis.Types" }, { "name": "Sierra.U128_MOD", "module": "Aegis.Types" }, { "name": "ZMod", "module": "Mathlib.Data.ZMod.Defs" }, { "name": "ZMod.val", "module": "Mathlib.Data.ZMod.Basic" }, { "name": "Nat", "module": "Init.Prelude" } ]
[ { "name": "...", "content": "..." } ]
[ { "name": "Nat.cast_lt", "module": "Mathlib.Data.Nat.Cast.Order.Basic" }, { "name": "Nat.cast_nonneg", "module": "Mathlib.Data.Nat.Cast.Order.Ring" }, { "name": "le_of_eq", "module": "Mathlib.Order.Defs.PartialOrder" } ]
[ { "name": "List.getElem_append_left{Ξ±", "content": "theorem List.getElem_append_left{Ξ± : Type u_1} {l₁ lβ‚‚ : List Ξ±} {i : Nat} (hn : i < l₁.length) :\\n(l₁ ++ lβ‚‚)[i] = l₁[i]" } ]
[ { "name": "Wad", "content": "def Wad : Type := UInt128" }, { "name": "Wad.WAD_SCALE", "content": "def WAD_SCALE : β„• := 1000000000000000000" }, { "name": "Wad.toZMod", "content": "protected def toZMod : UInt128 := w" }, { "name": "Wad.toRat", "content": "protected def toRat : β„š := w.toZMod.val / WAD_SCALE" } ]
[ { "name": "Wad.WAD_SCALE_rat_pos", "content": "theorem WAD_SCALE_rat_pos : 0 < (WAD_SCALE : β„š)" } ]
import CorelibVerification.Aux.ZMod import Aegis.Aux.Bool import Aegis.Aux.ZMod.DivMod open Sierra def Wad : Type := UInt128 namespace Wad def WAD_SCALE : β„• := 1000000000000000000 variable (w w' : Wad) protected def toZMod : UInt128 := w protected def toRat : β„š := w.toZMod.val / WAD_SCALE
theorem toRat_lt_toRat_of_val_lt_val (h : @ZMod.val U128_MOD w < @ZMod.val U128_MOD w') : w.toRat < w'.toRat :=
:= by simp only [Wad.toRat] apply div_lt_div Β· rwa [Nat.cast_lt, Wad.toZMod, Wad.toZMod] Β· apply le_of_eq; rfl Β· apply Nat.cast_nonneg Β· exact WAD_SCALE_rat_pos
2
12
false
Applied verif.