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. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.