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 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
201 | Intmax.isLUB_union_Merge_of_isLUB_isLUB_compat | lemma isLUB_union_Merge_of_isLUB_isLUB_compat {A B : Set (BalanceProof Kβ Kβ C Pi V)}
(hβ : IsLUB A jβ) (hβ : IsLUB B jβ) (hβ : jβ <β
> jβ) : IsLUB (A βͺ B) (jβ <+> jβ) | FVIntmax | FVIntmax/Theorem1.lean | [
"import FVIntmax.Lemma5",
"import FVIntmax.Wheels.AuthenticatedDictionary",
"import FVIntmax.Request",
"import FVIntmax.AttackGame",
"import FVIntmax.Wheels",
"import FVIntmax.Propositions",
"import Mathlib",
"import FVIntmax.Balance",
"import FVIntmax.Lemma4",
"import FVIntmax.Wheels.SignatureAggregation",
"import FVIntmax.Lemma3"
] | [
{
"name": "Preorder",
"module": "Mathlib.Order.Defs.PartialOrder"
},
{
"name": "Zero",
"module": "Init.Prelude"
},
{
"name": "Finite",
"module": "Mathlib.Data.Finite.Defs"
},
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "IsLUB",
"module": "Mathlib.Order.Bounds.Defs"
},
{
"name": "Set",
"module": "Mathlib.Data.Set.Defs"
},
{
"name": "IsLeast",
"module": "Mathlib.Order.Bounds.Defs"
},
{
"name": "LE",
"module": "Init.Prelude"
},
{
"name": "LE.le",
"module": "Init.Prelude"
},
{
"name": "Prod",
"module": "Init.Prelude"
},
{
"name": "lowerBounds",
"module": "Mathlib.Order.Bounds.Defs"
},
{
"name": "upperBounds",
"module": "Mathlib.Order.Bounds.Defs"
},
{
"name": "Vector",
"module": "Init.Data.Vector.Basic"
},
{
"name": "Preorder.toLE",
"module": "Mathlib.Order.Defs.PartialOrder"
}
] | [
{
"name": "notation:51 (priority := high) a:52 \" β
\" b:52 => iso a b",
"content": "notation:51 (priority := high) a:52 \" β
\" b:52 => iso a b"
},
{
"name": "notation:51 Οβ:52 \" <β
> \" Οβ:52 => BalanceProof.compat Οβ Οβ",
"content": "notation:51 Οβ:52 \" <β
> \" Οβ:52 => BalanceProof.compat Οβ Οβ"
},
{
"name": "notation:65 Οβ:65 \" <+> \" Οβ:66 => Dict.Merge Οβ Οβ",
"content": "notation:65 Οβ:65 \" <+> \" Οβ:66 => Dict.Merge Οβ Οβ"
},
{
"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": "Key",
"content": "abbrev Key (Kβ Kβ : Type) := Kβ β Kβ"
},
{
"name": "abbrev",
"content": "class abbrev PreWithZero (Ξ± : Type) := Preorder Ξ±, Zero Ξ±"
},
{
"name": "NonNeg",
"content": "def NonNeg (Ξ± : Type) [PreWithZero Ξ±] := { a : Ξ± // 0 β€ a }"
},
{
"name": "ExtraDataT",
"content": "abbrev ExtraDataT : Type := β"
},
{
"name": "Dict",
"content": "abbrev Dict (Ξ± Ο : Type) : Type := Ξ± β Option Ο"
},
{
"name": "Merge",
"content": "def Merge (Dβ Dβ : Dict Ξ± Ο) : Dict Ξ± Ο := D\n where D := Ξ» x β¦ First (Dβ x) (Dβ x)"
},
{
"name": "First",
"content": "def First (xβ xβ : Option Ξ±) : Option Ξ± :=\n match xβ, xβ with\n | .some x, .none => .some x\n | .some x, .some _ => .some x\n | .none, .some y => .some y\n | .none, .none => .none"
},
{
"name": "Setoid'",
"content": "class Setoid' (X : Type) extends Preorder X where\n isEquiv : IsEquivRel (X := X)"
},
{
"name": "IsEquivRel",
"content": "def IsEquivRel {X : Type} [Preorder X] := β a b : X, a β€ b β a β
b"
},
{
"name": "iso",
"content": "def iso {X : Type} [Preorder X] (a b : X) := a β€ b β§ b β€ a"
},
{
"name": "trivialPreorder",
"content": "def trivialPreorder {Ξ± : Type} : Preorder Ξ± :=\n {\n lt := Ξ» _ _ β¦ False\n le := Ξ» _ _ β¦ True\n le_refl := by admit /- proof elided -/"
},
{
"name": "le",
"content": "def le (vβ vβ : Vector Ξ± n) :=\n β x β (vβ.1.zip vβ.1), x.1 β€ x.2"
},
{
"name": "notation:51 (priority := high) a:52 \" β
\" b:52 => iso a b",
"content": "notation:51 (priority := high) a:52 \" β
\" b:52 => iso a b"
},
{
"name": "postfix:max \"β\" => NonNeg",
"content": "postfix:max \"β\" => NonNeg"
}
] | [
{
"name": "Set.mem_insert_iff",
"module": "Mathlib.Data.Set.Insert"
},
{
"name": "Set.mem_setOf_eq",
"module": "Mathlib.Data.Set.Operations"
},
{
"name": "Set.mem_singleton_iff",
"module": "Mathlib.Data.Set.Insert"
},
{
"name": "Set.mem_union",
"module": "Mathlib.Data.Set.Basic"
},
{
"name": "and_imp",
"module": "Init.SimpLemmas"
},
{
"name": "forall_eq",
"module": "Init.PropLemmas"
},
{
"name": "forall_eq_or_imp",
"module": "Init.PropLemmas"
}
] | [
{
"name": "proposition6",
"content": "lemma proposition6 [Setoid' Y] {Dβ Dβ : Dict X Y} :\n (β join, IsLUB {Dβ, Dβ} join) β β x, Dβ x β .none β§ Dβ x β .none β Dβ x β
Dβ x"
},
{
"name": "proposition4",
"content": "lemma proposition4 [Setoid' X] {x y : Option X} :\n (β join : Option X, IsLUB {x, y, .none} join) β (x β .none β§ y β .none β x β
y)"
},
{
"name": "proposition2",
"content": "lemma proposition2 [Setoid' X] {x y : X} :\n (β join : X, IsLUB {x, y} join) β x β
y"
},
{
"name": "iso_rfl",
"content": "@[simp, refl]\nlemma iso_rfl : a β
a"
},
{
"name": "iso_trans",
"content": "@[trans]\nlemma iso_trans : (a β
b) β (b β
c) β a β
c"
},
{
"name": "proposition2'",
"content": "lemma proposition2' [Setoid' X] {join x y : X} (h : IsLUB {x, y} join) :\n (x β
join) β§ y β
join"
},
{
"name": "proposition3'",
"content": "lemma proposition3' : \n (β join : X, IsLUB {x, y} join) β (β join : Option X, IsLUB {.some x, .some y, .none} join)"
},
{
"name": "proposition5",
"content": "lemma proposition5 [Preorder Y] {f g : X β Y} {join : X β Y} :\n IsLUB {f, g} join β β x : X, IsLUB {f x, g x} (join x)"
},
{
"name": "proposition6_aux",
"content": "lemma proposition6_aux [Setoid' Y] {Dβ Dβ : Dict X Y}\n (h : β k, Dβ k β .none β§ Dβ k β .none β Dβ k β
Dβ k) : IsLUB {Dβ, Dβ} (Dict.Merge Dβ Dβ)"
},
{
"name": "proposition6'",
"content": "lemma proposition6' [Setoid' Y] {Dβ Dβ join : Dict X Y} (h : IsLUB {Dβ, Dβ} join) :\n join β
Dict.Merge Dβ Dβ"
},
{
"name": "iso_symm",
"content": "@[symm]\nlemma iso_symm : (a β
b) β b β
a"
},
{
"name": "proposition4'",
"content": "lemma proposition4' [Setoid' X] {join x y : Option X} (h : IsLUB {x, y, .none} join) :\n join β
Dict.First x y"
},
{
"name": "proposition5'",
"content": "lemma proposition5' [Preorder Y] {f g h join' : X β Y}\n (hβ : IsLUB {f, g} join')\n (hβ : β x, h x β
join' x) :\n join' β
h"
},
{
"name": "discretePreorder_eq_equality_Pi_Prod_ExtraDataT",
"content": "@[simp]\nlemma discretePreorder_eq_equality_Pi_Prod_ExtraDataT {a b : (Pi Γ ExtraDataT)} : a β€ b"
},
{
"name": "BalanceProof.snd_discrete",
"content": "@[simp]\nlemma BalanceProof.snd_discrete {x y : TransactionBatch Kβ Kβ V} :\n @LE.le (TransactionBatch Kβ Kβ V) Preorder.toLE x y β x = y"
}
] | [] | [
{
"name": "Intmax.existsLUB_iff_compat",
"content": "lemma existsLUB_iff_compat :\n (β join, IsLUB {Οβ, Οβ} join) β Οβ <β
> Οβ"
},
{
"name": "Intmax.merge_le",
"content": "lemma merge_le (hβ : Οβ β€ Οβ) (hβ : Οβ β€ Οβ) : Οβ <+> Οβ β€ Οβ"
}
] | import FVIntmax.AttackGame
import FVIntmax.Lemma3
import FVIntmax.Lemma4
import FVIntmax.Lemma5
import FVIntmax.Propositions
import FVIntmax.Request
import FVIntmax.Wheels
import FVIntmax.Wheels.AuthenticatedDictionary
import FVIntmax.Wheels.SignatureAggregation
import Mathlib
namespace Intmax
open Classical
noncomputable section Intmax
noncomputable section theorem1
section AttackGame
variable {Sigma Pi M : Type}
{C : Type} [Nonempty C]
{V : Type}
[Lattice V] [AddCommGroup V]
[CovariantClass V V (Β· + Β·) (Β· β€ Β·)]
[CovariantClass V V (Function.swap (Β· + Β·)) (Β· β€ Β·)]
{Kβ : Type} [Nonempty Kβ] [Finite Kβ] [LinearOrder Kβ]
{Kβ : Type} [Finite Kβ] [LinearOrder Kβ]
{Kβ : Type} [Nonempty Kβ]
{Kβ : Type} [Nonempty Kβ]
section MergeLemmas
variable {acc Ο : BalanceProof Kβ Kβ C Pi V} {Οs Οs : List (BalanceProof Kβ Kβ C Pi V)}
end MergeLemmas
notation:51 Οβ:52 " <β
> " Οβ:52 => BalanceProof.compat Οβ Οβ
notation:65 Οβ:65 " <+> " Οβ:66 => Dict.Merge Οβ Οβ
section Compat
variable {Οβ Οβ Οβ : BalanceProof Kβ Kβ C Pi V}
end Compat | lemma isLUB_union_Merge_of_isLUB_isLUB_compat {A B : Set (BalanceProof Kβ Kβ C Pi V)}
(hβ : IsLUB A jβ) (hβ : IsLUB B jβ) (hβ : jβ <β
> jβ) : IsLUB (A βͺ B) (jβ <+> jβ) := | := by
have hβ'' := hβ
obtain β¨j, hββ© := existsLUB_iff_compat.2 hβ
split_ands
Β· simp only [IsLUB, IsLeast, upperBounds, Set.mem_insert_iff, Set.mem_singleton_iff,
forall_eq_or_imp, forall_eq, Set.mem_setOf_eq, lowerBounds, and_imp, Set.mem_union] at hβ hβ hβ β’
rcases hβ with β¨hβ, hβ'β©
rcases hβ with β¨hβ, hβ'β©
rintro Dβ (hDβ | hDβ)
Β· simp [-Prod.forall, (Β·β€Β·)]
intros x
unfold Dict.Merge Dict.Merge.D Dict.First
specialize hβ hDβ
simp [-Prod.forall, (Β·β€Β·)] at hβ
specialize hβ x
set dβ := Dβ x with eqX
set dβ := jβ x with eqY
set dβ := jβ x with eqZ
rcases dβ with _ | dβ <;> rcases dβ with _ | dβ <;> rcases dβ with _ | dβ <;> simp
Β· simp at hβ
Β· simp at hβ
Β· simp at hβ
exact hβ
Β· simp at hβ
exact hβ
Β· simp only [LE.le, discretePreorder_eq_equality_Pi_Prod_ExtraDataT, BalanceProof.snd_discrete,]
intros x
unfold Dict.Merge Dict.Merge.D Dict.First
have eqβ : Dβ β€ jβ := hβ hDβ
simp [-Prod.forall, (Β·β€Β·)] at eqβ
specialize eqβ x
set dβ := Dβ x with eqX
set dβ := jβ x with eqY
set dβ := jβ x with eqZ
rcases dβ with _ | dβ <;> rcases dβ with _ | dβ <;> rcases dβ with _ | dβ <;> simp
Β· simp at eqβ
Β· simp at eqβ
exact eqβ
Β· simp at eqβ
Β· simp at eqβ
specialize hβ'' x
rw [βeqY, βeqZ] at hβ''
simp at hβ''
exact iso_trans eqβ hβ''.symm
Β· exact Ξ» _ hΟ β¦ merge_le (hβ.right Ξ» _ hd β¦ hΟ (by tauto))
(hβ.right Ξ» _ hd β¦ hΟ (by tauto)) | 7 | 52 | false | Applied verif. |
202 | Intmax.Vec.le_trans | lemma le_trans (hβ : vβ β€ vβ) (hβ : vβ β€ vβ) : vβ β€ vβ | FVIntmax | FVIntmax/Wheels.lean | [
"import Mathlib.Logic.Embedding.Basic",
"import FVIntmax.Wheels.Wheels",
"import Mathlib.Tactic",
"import Mathlib.Algebra.Order.Ring.Unbundled.Nonneg",
"import Mathlib.Data.Finmap",
"import Mathlib.Data.Set.Image",
"import Mathlib.Data.Finite.Defs",
"import Mathlib.Data.List.Intervals"
] | [
{
"name": "Vector",
"module": "Init.Data.Vector.Basic"
}
] | [
{
"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": "Intmax.CryptoAssumptions.Injective",
"content": "class Injective {Ξ± Ο : Type} (f : Ξ± β Ο) where\n h : ComputationallyInfeasible (Β¬ Function.Injective f)"
},
{
"name": "Intmax.Vec.le",
"content": "def le (vβ vβ : Vector Ξ± n) :=\n β x β (vβ.1.zip vβ.1), x.1 β€ x.2"
}
] | [] | import Mathlib.Algebra.Order.Ring.Unbundled.Nonneg
import Mathlib.Data.Finite.Defs
import Mathlib.Data.Finmap
import Mathlib.Data.List.Intervals
import Mathlib.Data.Set.Image
import Mathlib.Logic.Embedding.Basic
import Mathlib.Tactic
import FVIntmax.Wheels.Wheels
namespace Intmax
namespace CryptoAssumptions
section Hashing
class Injective {Ξ± Ο : Type} (f : Ξ± β Ο) where
h : ComputationallyInfeasible (Β¬ Function.Injective f)
end Hashing
end CryptoAssumptions
section UniquelyIndexed
prefix:max "!" => UniqueTokenT
namespace UniquelyIndexed
end UniquelyIndexed
end UniquelyIndexed
section NonNeg
postfix:max "β" => NonNeg
section Nonneg
variable {Ξ± : Type} [PreWithZero Ξ±] {v : Ξ±β}
end Nonneg
end NonNeg
section Order
section VectorPreorder
open Mathlib
variable {Ξ± : Type} [Preorder Ξ±] {n : β}
{vβ vβ vβ : Vector Ξ± n}
namespace Vec
def le (vβ vβ : Vector Ξ± n) :=
β x β (vβ.1.zip vβ.1), x.1 β€ x.2 | lemma le_trans (hβ : vβ β€ vβ) (hβ : vβ β€ vβ) : vβ β€ vβ := | := by
dsimp [(Β·β€Β·), le] at *
rcases vβ with β¨lβ, hlββ©
rcases vβ with β¨lβ, hlββ©
rcases vβ with β¨lβ, hlββ©
simp at *
induction' lβ with hdβ tlβ ih generalizing lβ lβ n
Β· rcases lβ; exact hβ; simp_all; omega
Β· rcases lβ with _ | β¨hdβ, tlββ© <;> [simp; skip]
rcases lβ with _ | β¨hdβ, tlββ© <;> simp at *
intros a b h
rcases h with β¨hβ, hββ© | h
Β· transitivity hdβ <;> tauto
Β· specialize @ih tlβ.length tlβ rfl (by aesop) tlβ (by aesop)
aesop | 2 | 3 | false | Applied verif. |
203 | Intmax.monotone_TransactionsInBlocksFixed | lemma monotone_TransactionsInBlocksFixed :
Monotone Ξ» (Ο : BalanceProof Kβ Kβ C Pi V) β¦ TransactionsInBlocksFixed Ο Bstar | FVIntmax | FVIntmax/Lemma4.lean | [
"import FVIntmax.Wheels.Dictionary",
"import FVIntmax.Wheels",
"import FVIntmax.Balance"
] | [
{
"name": "Preorder",
"module": "Mathlib.Order.Defs.PartialOrder"
},
{
"name": "Zero",
"module": "Init.Prelude"
},
{
"name": "Finite",
"module": "Mathlib.Data.Finite.Defs"
},
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "DecidableEq",
"module": "Init.Prelude"
},
{
"name": "Set",
"module": "Mathlib.Data.Set.Defs"
},
{
"name": "Finset",
"module": "Mathlib.Data.Finset.Defs"
},
{
"name": "Classical.arbitrary",
"module": "Mathlib.Logic.Nonempty"
},
{
"name": "Vector",
"module": "Init.Data.Vector.Basic"
},
{
"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": "local macro:max (priority := high) \"βͺ\" b:term : term => `(β¨$",
"content": "local macro:max (priority := high) \"βͺ\" b:term : term => `(β¨$b, by admit /- proof elided -/\nβ©)"
},
{
"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": "Key",
"content": "abbrev Key (Kβ Kβ : Type) := Kβ β Kβ"
},
{
"name": "abbrev",
"content": "class abbrev PreWithZero (Ξ± : Type) := Preorder Ξ±, Zero Ξ±"
},
{
"name": "NonNeg",
"content": "def NonNeg (Ξ± : Type) [PreWithZero Ξ±] := { a : Ξ± // 0 β€ a }"
},
{
"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": "Ξ€",
"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": "Kbar",
"content": "inductive Kbar (Kβ Kβ : Type) where\n | key (k : Key Kβ Kβ)\n | Source\nderiving DecidableEq"
},
{
"name": "Injective",
"content": "class Injective {Ξ± Ο : Type} (f : Ξ± β Ο) where\n h : ComputationallyInfeasible (Β¬ Function.Injective f)"
},
{
"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": "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": "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": "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_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": "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.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'"
}
] | 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)}
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)} | lemma monotone_TransactionsInBlocksFixed :
Monotone Ξ» (Ο : BalanceProof Kβ Kβ C Pi V) β¦ TransactionsInBlocksFixed Ο Bstar := | := by
intros Ο Ο' h
dsimp
apply TransactionsInBlocksFixed_le_of_TransactionsInBlocks; rintro β¨i, hiβ©; simp
generalize eq : (TransactionsInBlocks Ο Bstar)[i]'(by blast with Ο) = Tstar
generalize eq' : (TransactionsInBlocks Ο' Bstar)[i]'(by clear eq; blast with Ο') = Tstar'
rcases Tstar with β¨β¨s, r, vβ©, hββ©
rcases Tstar' with β¨β¨s', r', v'β©, hββ©
obtain β¨β¨β©, β¨β©β© := senderReceiver_transactionsInBlocks _ eq eq'; simp
exact v_transactionsInBlocks h _ eq eq' | 9 | 73 | false | Applied verif. |
204 | Intmax.compat_merge_of_compat | lemma compat_merge_of_compat :
(β Ο', Ο' β Οs β Ο <β
> Ο') β Ο <β
> (mergeR'' Οs .initial) | FVIntmax | FVIntmax/Theorem1.lean | [
"import FVIntmax.Lemma5",
"import FVIntmax.Wheels.AuthenticatedDictionary",
"import FVIntmax.Request",
"import FVIntmax.AttackGame",
"import FVIntmax.Wheels",
"import FVIntmax.Propositions",
"import Mathlib",
"import FVIntmax.Lemma4",
"import FVIntmax.Wheels.Dictionary",
"import FVIntmax.Wheels.SignatureAggregation",
"import FVIntmax.Lemma3"
] | [
{
"name": "Preorder",
"module": "Mathlib.Order.Defs.PartialOrder"
},
{
"name": "Zero",
"module": "Init.Prelude"
},
{
"name": "Finite",
"module": "Mathlib.Data.Finite.Defs"
},
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
}
] | [
{
"name": "notation:51 (priority := high) a:52 \" β
\" b:52 => iso a b",
"content": "notation:51 (priority := high) a:52 \" β
\" b:52 => iso a b"
},
{
"name": "notation:51 Οβ:52 \" <β
> \" Οβ:52 => BalanceProof.compat Οβ Οβ",
"content": "notation:51 Οβ:52 \" <β
> \" Οβ:52 => BalanceProof.compat Οβ Οβ"
},
{
"name": "notation:65 Οβ:65 \" <+> \" Οβ:66 => Dict.Merge Οβ Οβ",
"content": "notation:65 Οβ:65 \" <+> \" Οβ:66 => Dict.Merge Οβ Οβ"
},
{
"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": "Key",
"content": "abbrev Key (Kβ Kβ : Type) := Kβ β Kβ"
},
{
"name": "abbrev",
"content": "class abbrev PreWithZero (Ξ± : Type) := Preorder Ξ±, Zero Ξ±"
},
{
"name": "NonNeg",
"content": "def NonNeg (Ξ± : Type) [PreWithZero Ξ±] := { a : Ξ± // 0 β€ a }"
},
{
"name": "ExtraDataT",
"content": "abbrev ExtraDataT : Type := β"
},
{
"name": "Dict",
"content": "abbrev Dict (Ξ± Ο : Type) : Type := Ξ± β Option Ο"
},
{
"name": "Merge",
"content": "def Merge (Dβ Dβ : Dict Ξ± Ο) : Dict Ξ± Ο := D\n where D := Ξ» x β¦ First (Dβ x) (Dβ x)"
},
{
"name": "First",
"content": "def First (xβ xβ : Option Ξ±) : Option Ξ± :=\n match xβ, xβ with\n | .some x, .none => .some x\n | .some x, .some _ => .some x\n | .none, .some y => .some y\n | .none, .none => .none"
},
{
"name": "BalanceProof.initial",
"content": "def BalanceProof.initial : BalanceProof Kβ Kβ C Pi V := Ξ» _ β¦ .none"
},
{
"name": "Injective",
"content": "class Injective {Ξ± Ο : Type} (f : Ξ± β Ο) where\n h : ComputationallyInfeasible (Β¬ Function.Injective f)"
},
{
"name": "postfix:max \"β\" => NonNeg",
"content": "postfix:max \"β\" => NonNeg"
}
] | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "Merge_assoc",
"content": "lemma Merge_assoc {Dβ : Dict Ξ± Ο} :\n Merge (Merge Dβ Dβ) Dβ = Merge Dβ (Merge Dβ Dβ)"
}
] | [
{
"name": "Intmax.mergeR''",
"content": "def mergeR'' (Οs : List (BalanceProof Kβ Kβ C Pi V)) (acc : BalanceProof Kβ Kβ C Pi V) : BalanceProof Kβ Kβ C Pi V :=\n match Οs with\n | [] => acc\n | Ο :: Οs => Dict.Merge acc (mergeR'' Οs Ο)"
},
{
"name": "Intmax.BalanceProof.compat",
"content": "def BalanceProof.compat (Οβ Οβ : BalanceProof Kβ Kβ C Pi V) : Prop :=\n β k, Οβ k β none β§ Οβ k β none β Οβ k β
Οβ k"
}
] | [
{
"name": "Intmax.merge_lem_aux",
"content": "private lemma merge_lem_aux :\n mergeR'' (Ο :: Οs) acc = acc <+> Ο <+> (mergeR'' Οs BalanceProof.initial)"
},
{
"name": "Intmax.merge_lem",
"content": "lemma merge_lem :\n mergeR'' (Ο :: Οs) BalanceProof.initial = Ο <+> (mergeR'' Οs BalanceProof.initial)"
},
{
"name": "Intmax.compat_lem",
"content": "lemma compat_lem {Ο Ο' Ο'': BalanceProof Kβ Kβ C Pi V} :\n Ο <β
> Ο' β Ο <β
> Ο'' β Ο <β
> (Ο' <+> Ο'')"
}
] | import FVIntmax.AttackGame
import FVIntmax.Lemma3
import FVIntmax.Lemma4
import FVIntmax.Lemma5
import FVIntmax.Propositions
import FVIntmax.Request
import FVIntmax.Wheels
import FVIntmax.Wheels.AuthenticatedDictionary
import FVIntmax.Wheels.SignatureAggregation
import Mathlib
namespace Intmax
open Classical
noncomputable section Intmax
noncomputable section theorem1
section AttackGame
variable {Sigma Pi M : Type}
{C : Type} [Nonempty C]
{V : Type}
[Lattice V] [AddCommGroup V]
[CovariantClass V V (Β· + Β·) (Β· β€ Β·)]
[CovariantClass V V (Function.swap (Β· + Β·)) (Β· β€ Β·)]
{Kβ : Type} [Nonempty Kβ] [Finite Kβ] [LinearOrder Kβ]
{Kβ : Type} [Finite Kβ] [LinearOrder Kβ]
{Kβ : Type} [Nonempty Kβ]
{Kβ : Type} [Nonempty Kβ]
def mergeR'' (Οs : List (BalanceProof Kβ Kβ C Pi V)) (acc : BalanceProof Kβ Kβ C Pi V) : BalanceProof Kβ Kβ C Pi V :=
match Οs with
| [] => acc
| Ο :: Οs => Dict.Merge acc (mergeR'' Οs Ο)
section MergeLemmas
variable {acc Ο : BalanceProof Kβ Kβ C Pi V} {Οs Οs : List (BalanceProof Kβ Kβ C Pi V)}
end MergeLemmas
def BalanceProof.compat (Οβ Οβ : BalanceProof Kβ Kβ C Pi V) : Prop :=
β k, Οβ k β none β§ Οβ k β none β Οβ k β
Οβ k
notation:51 Οβ:52 " <β
> " Οβ:52 => BalanceProof.compat Οβ Οβ
notation:65 Οβ:65 " <+> " Οβ:66 => Dict.Merge Οβ Οβ
section Compat
variable {Οβ Οβ Οβ : BalanceProof Kβ Kβ C Pi V}
end Compat
section MergeLemmas
variable {Ο acc : BalanceProof Kβ Kβ C Pi V}
{Οs : List (BalanceProof Kβ Kβ C Pi V)}
end MergeLemmas
variable [AD : ADScheme Kβ (C Γ Kβ Γ ExtraDataT) C Pi]
section MergeLemmas
variable {Ο acc : BalanceProof Kβ Kβ C Pi V}
{Οs : List (BalanceProof Kβ Kβ C Pi V)} | lemma compat_merge_of_compat :
(β Ο', Ο' β Οs β Ο <β
> Ο') β Ο <β
> (mergeR'' Οs .initial) := | := by
induction Οs generalizing Ο with
| nil =>
intros Ο
unfold BalanceProof.compat BalanceProof.initial
simp
| cons Ο Οs ih =>
intros Ο_1 h
rw [merge_lem]
apply compat_lem <;> aesop | 5 | 22 | false | Applied verif. |
205 | Intmax.aggregateDeposits_cons | @[simp]
lemma aggregateDeposits_cons {hd} {tl : List (Block Kβ Kβ C Sigma V)} :
aggregateDeposits (hd :: tl) =
(if h : hd.isDepositBlock
then (hd.getDeposit h).2.1
else 0) +
aggregateDeposits tl | FVIntmax | FVIntmax/AttackGame.lean | [
"import FVIntmax.Wheels.AuthenticatedDictionary",
"import FVIntmax.Request",
"import FVIntmax.Block",
"import FVIntmax.Wheels.SignatureAggregation",
"import FVIntmax.BalanceProof",
"import FVIntmax.Wheels"
] | [
{
"name": "Preorder",
"module": "Mathlib.Order.Defs.PartialOrder"
},
{
"name": "Zero",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Sigma",
"module": "Init.Core"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Finset",
"module": "Mathlib.Data.Finset.Defs"
},
{
"name": "Finset.range",
"module": "Mathlib.Data.Finset.Range"
}
] | [
{
"name": "Injective",
"content": "class Injective {Ξ± Ο : Type} (f : Ξ± β Ο) where\n h : ComputationallyInfeasible (Β¬ Function.Injective f)"
},
{
"name": "Scontract",
"content": "abbrev Scontract (Kβ Kβ V : Type) [PreWithZero V] (C Sigma : Type) :=\n List (Block Kβ Kβ C Sigma V)"
},
{
"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": "ExtraDataT",
"content": "abbrev ExtraDataT : Type := β"
},
{
"name": "abbrev",
"content": "class abbrev PreWithZero (Ξ± : Type) := Preorder Ξ±, Zero Ξ±"
},
{
"name": "NonNeg",
"content": "def NonNeg (Ξ± : Type) [PreWithZero Ξ±] := { a : Ξ± // 0 β€ a }"
},
{
"name": "isDepositBlock",
"content": "abbrev isDepositBlock (b : Block Kβ Kβ C Sigma V) := b matches (Block.deposit _ _) "
},
{
"name": "getDeposit",
"content": "def getDeposit (b : Block Kβ Kβ C Sigma V) (_h : b.isDepositBlock) : Kβ Γ Vβ :=\n match b with | deposit r v => (r, v)"
},
{
"name": "postfix:max \"β\" => NonNeg",
"content": "postfix:max \"β\" => NonNeg"
}
] | [
{
"name": "Finset.mem_range",
"module": "Mathlib.Data.Finset.Range"
},
{
"name": "Finset.sum_bij",
"module": "Mathlib.Algebra.BigOperators.Group.Finset.Defs"
},
{
"name": "Finset.sum_dite_of_true",
"module": "Mathlib.Algebra.BigOperators.Group.Finset.Piecewise"
},
{
"name": "Finset.sum_eq_sum_diff_singleton_add",
"module": "Mathlib.Algebra.BigOperators.Group.Finset.Piecewise"
},
{
"name": "Finset.sum_fin_eq_sum_range",
"module": "Mathlib.Data.Fintype.BigOperators"
},
{
"name": "Finset.univ_eq_attach",
"module": "Mathlib.Data.Fintype.Sets"
},
{
"name": "List.getElem_cons_zero",
"module": "Init.GetElem"
},
{
"name": "add_comm",
"module": "Mathlib.Algebra.Group.Defs"
},
{
"name": "dif_pos",
"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": "Intmax.aggregateDeposits",
"content": "def aggregateDeposits (Ο : Scontract Kβ Kβ V C Sigma) : V :=\n β i : Fin Ο.length,\n if h : Ο[i].isDepositBlock\n then (Ο[i.1].getDeposit h).2.1\n else 0"
},
{
"name": "Intmax.reindex",
"content": "@[simp]\nprivate def reindex : (a : β) β a β Finset.range (k + 1) \\ {0} β β :=\n Ξ» a _ β¦ a.pred"
}
] | [
{
"name": "Intmax.reindex_mem",
"content": "private lemma reindex_mem :\n β (a : β) (ha : a β Finset.range (k + 1) \\ {0}), reindex a ha β Finset.range k"
},
{
"name": "Intmax.reindex_inj",
"content": "private lemma reindex_inj :\n β (aβ : β) (haβ : aβ β Finset.range (k + 1) \\ {0})\n (aβ : β) (haβ : aβ β Finset.range (k + 1) \\ {0}),\n reindex aβ haβ = reindex aβ haβ β aβ = aβ"
}
] | import FVIntmax.Wheels.AuthenticatedDictionary
import FVIntmax.Wheels.SignatureAggregation
import FVIntmax.BalanceProof
import FVIntmax.Block
import FVIntmax.Request
import FVIntmax.Wheels
namespace Intmax
noncomputable section Intmax
section RollupContract
open Classical
section
variable {C : Type} [Nonempty C]
{V : Type} [Lattice V] [AddCommGroup V]
{Kβ : Type} [Finite Kβ] [Nonempty Kβ]
{Kβ : Type} [Finite Kβ]
{Sigma : Type}
[ADScheme Kβ (C Γ Kβ Γ ExtraDataT) C Pi]
[SA : SignatureAggregation (C Γ Kβ Γ ExtraDataT) Kβ KβT Sigma]
end
section
variable {C : Type}
{V : Type} [Lattice V] [AddCommGroup V]
{Kβ : Type} [Finite Kβ]
{Kβ : Type}
{Sigma : Type}
{block : Block Kβ Kβ C Sigma V}
{v : V}
section Lemmas
end Lemmas
namespace Scontract
section
variable [LinearOrder Kβ] [Nonempty Kβ]
[LinearOrder Kβ] [Finite Kβ]
[Nonempty C]
[CovariantClass V V (Β· + Β·) (Β· β€ Β·)]
[CovariantClass V V (Function.swap (Β· + Β·)) (Β· β€ Β·)]
[ADScheme Kβ (C Γ Kβ Γ ExtraDataT) C Pi]
[SignatureAggregation (C Γ Kβ Γ ExtraDataT) Kβ KβT Sigma]
section appendBlock
variable {Ο : Scontract Kβ Kβ V C Sigma} {request : Request Kβ Kβ C Sigma Pi V}
end appendBlock
end
section
variable [LinearOrder Kβ]
[Finite Kβ] [LinearOrder Kβ]
{Ο : Scontract Kβ Kβ V C Sigma}
{request : Request Kβ Kβ C Sigma Pi V}
[CovariantClass V V (Β· + Β·) (Β· β€ Β·)]
[CovariantClass V V (Function.swap (Β· + Β·)) (Β· β€ Β·)]
end
end Scontract
end
end RollupContract
section AttackGameDefs
variable {Kβ : Type} [Finite Kβ] [LinearOrder Kβ] [Nonempty Kβ]
{Kβ : Type} [Finite Kβ] [LinearOrder Kβ]
{V : Type} [Lattice V] [AddCommGroup V]
[CovariantClass V V (Β· + Β·) (Β· β€ Β·)]
[CovariantClass V V (Function.swap (Β· + Β·)) (Β· β€ Β·)]
{Sigma : Type}
{C : Type} [Nonempty C]
[ADScheme Kβ (C Γ Kβ Γ ExtraDataT) C Pi]
[SignatureAggregation (C Γ Kβ Γ ExtraDataT) Kβ KβT Sigma]
(requests : List (Request Kβ Kβ C Sigma Pi V))
(Ο : Scontract Kβ Kβ V C Sigma)
def aggregateDeposits (Ο : Scontract Kβ Kβ V C Sigma) : V :=
β i : Fin Ο.length,
if h : Ο[i].isDepositBlock
then (Ο[i.1].getDeposit h).2.1
else 0
end AttackGameDefs
section AttackGameLemmas
variable {Kβ Kβ Sigma C : Type}
{V : Type} [Lattice V] [AddCommGroup V]
[CovariantClass V V (Β· + Β·) (Β· β€ Β·)]
[ADScheme Kβ (C Γ Kβ Γ ExtraDataT) C Pi]
section computeBalanceSum
variable {k : β}
@[simp]
private def reindex : (a : β) β a β Finset.range (k + 1) \ {0} β β :=
Ξ» a _ β¦ a.pred
end computeBalanceSum | @[simp]
lemma aggregateDeposits_cons {hd} {tl : List (Block Kβ Kβ C Sigma V)} :
aggregateDeposits (hd :: tl) =
(if h : hd.isDepositBlock
then (hd.getDeposit h).2.1
else 0) +
aggregateDeposits tl := | := by
simp [aggregateDeposits]
rw [
Finset.sum_fin_eq_sum_range,
Finset.sum_eq_sum_diff_singleton_add (i := 0),
dif_pos (show 0 < tl.length + 1 by omega)
]
simp_rw [List.getElem_cons_zero (h := _)]; case h => exact Finset.mem_range.2 (by omega)
let F : β β V := Ξ» i β¦
if h : i < tl.length
then if h_1 : tl[i].isDepositBlock = true
then (tl[i].getDeposit h_1).2
else 0
else 0
rw [Finset.sum_bij (t := Finset.range tl.length)
(g := F)
(i := reindex)
(hi := reindex_mem)
(i_inj := reindex_inj)
(i_surj := Ξ» b hb β¦ by use b.succ; simp; exact Finset.mem_range.1 hb)
(h := Ξ» n hn β¦ by simp at hn; simp [hn]
rcases n with _ | n <;> [omega; simp [F, reindex]]
nth_rw 2 [dif_pos (by rcases hn with β¨hn, _β©; omega)])]
unfold F
rw [Finset.sum_dite_of_true (Ξ» _ β¦ (Finset.mem_range.1 Β·)), Finset.sum_fin_eq_sum_range, Finset.univ_eq_attach]
nth_rw 2 [Finset.sum_dite_of_true]; case h => exact Ξ» _ β¦ (Finset.mem_range.1 Β·)
rw [add_comm]; simp | 5 | 28 | false | Applied verif. |
206 | Intmax.f_transfer_source'' | lemma f_transfer_source''
(h : b.isTransferBlock) (hβ : T β TransactionsInBlock Ο b) :
(f Ο T) .Source = Ο .Source := f_transfer_source β¨β¨b, hβ©, hββ© | FVIntmax | FVIntmax/Balance.lean | [
"import FVIntmax.BalanceProof",
"import FVIntmax.Wheels",
"import FVIntmax.Propositions",
"import Mathlib",
"import FVIntmax.Key",
"import FVIntmax.Block",
"import Mathlib.Algebra.Group.Int",
"import FVIntmax.Wheels.Dictionary",
"import FVIntmax.State",
"import FVIntmax.Transaction"
] | [
{
"name": "Preorder",
"module": "Mathlib.Order.Defs.PartialOrder"
},
{
"name": "Zero",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Finite",
"module": "Mathlib.Data.Finite.Defs"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "DecidableEq",
"module": "Init.Prelude"
},
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "Set",
"module": "Mathlib.Data.Set.Defs"
},
{
"name": "Finset",
"module": "Mathlib.Data.Finset.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": "Prod",
"module": "Init.Prelude"
},
{
"name": "Prod.mk",
"module": "Init.Prelude"
},
{
"name": "Subtype",
"module": "Init.Prelude"
},
{
"name": "Subtype.mk",
"module": "Init.Prelude"
},
{
"name": "Sum",
"module": "Init.Core"
},
{
"name": "Sum.inl",
"module": "Init.Core"
},
{
"name": "Sum.inr",
"module": "Init.Core"
},
{
"name": "reduceCtorEq",
"module": "Lean.Meta.Tactic.Simp.BuiltinSimprocs.Core"
},
{
"name": "Set.range",
"module": "Mathlib.Data.Set.Operations"
}
] | [
{
"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": "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": "ExtraDataT",
"content": "abbrev ExtraDataT : Type := β"
},
{
"name": "abbrev",
"content": "class abbrev PreWithZero (Ξ± : Type) := Preorder Ξ±, Zero Ξ±"
},
{
"name": "NonNeg",
"content": "def NonNeg (Ξ± : Type) [PreWithZero Ξ±] := { a : Ξ± // 0 β€ a }"
},
{
"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": "Ξ€",
"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": "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": "Injective",
"content": "class Injective {Ξ± Ο : Type} (f : Ξ± β Ο) where\n h : ComputationallyInfeasible (Β¬ Function.Injective f)"
},
{
"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": "Dict",
"content": "abbrev Dict (Ξ± Ο : Type) : Type := Ξ± β Option Ο"
},
{
"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": "isDepositBlock",
"content": "abbrev isDepositBlock (b : Block Kβ Kβ C Sigma V) := b matches (Block.deposit _ _) "
},
{
"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": "Ξ€c",
"content": "abbrev Ξ€c (Kβ Kβ V : Type) [PreWithZero V] : Type := { Ο : Ξ€ Kβ Kβ V // Ο.isComplete }"
},
{
"name": "isComplete",
"content": "def isComplete (Ο : Ξ€ Kβ Kβ V) :=\n match Ο with | β¨(_, _, v), _β© => v.isSome"
},
{
"name": "value",
"content": "def value (Ο : Ξ€ Kβ Kβ V) : Option Vβ := Ο.1.2.2"
},
{
"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": "Set.image_eq_range",
"module": "Mathlib.Data.Set.Image"
},
{
"name": "if_pos",
"module": "Init.Core"
},
{
"name": "Finset.mem_filter",
"module": "Mathlib.Data.Finset.Filter"
},
{
"name": "Finset.mem_sort",
"module": "Mathlib.Data.Finset.Sort"
},
{
"name": "Finset.mem_univ",
"module": "Mathlib.Data.Fintype.Defs"
},
{
"name": "List.mem_attach",
"module": "Init.Data.List.Attach"
},
{
"name": "List.mem_map",
"module": "Init.Data.List.Lemmas"
},
{
"name": "and_false",
"module": "Init.SimpLemmas"
},
{
"name": "and_true",
"module": "Init.SimpLemmas"
},
{
"name": "exists_and_left",
"module": "Init.PropLemmas"
},
{
"name": "exists_const",
"module": "Init.PropLemmas"
},
{
"name": "exists_eq",
"module": "Init.PropLemmas"
},
{
"name": "exists_eq_right",
"module": "Init.PropLemmas"
},
{
"name": "exists_eq_right_right",
"module": "Init.PropLemmas"
},
{
"name": "exists_false",
"module": "Init.PropLemmas"
},
{
"name": "exists_prop",
"module": "Init.PropLemmas"
},
{
"name": "exists_true_left",
"module": "Init.PropLemmas"
},
{
"name": "false_or",
"module": "Init.SimpLemmas"
},
{
"name": "ite_not",
"module": "Init.PropLemmas"
},
{
"name": "or_false",
"module": "Init.SimpLemmas"
},
{
"name": "true_and",
"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": "Intmax.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": "Intmax.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": "Intmax.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": "Intmax.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": "Intmax.e",
"content": "def e (i : Kbar Kβ Kβ) : Kbar Kβ Kβ β β€ := Ξ» j β¦ if i = j then 1 else 0"
},
{
"name": "Intmax.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": "Intmax.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": "Intmax.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": "Intmax.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": "Intmax.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": "Intmax.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": "Intmax.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": "Intmax.V'_eq_range",
"content": "private lemma V'_eq_range {b : S Kβ Kβ V} {T : Ξ€ Kβ Kβ V} {k : Kbar Kβ Kβ} :\n V' b T k =\n Set.range Ξ» (x : { x : (Ξ€c Kβ Kβ V Γ S Kβ Kβ V) // (T, b) β€ (βx.1, x.2) }) β¦ fc βx k"
},
{
"name": "Intmax.f_eq_f'",
"content": "lemma f_eq_f' : f = f' (Kβ := Kβ) (Kβ := Kβ) (V := V)"
},
{
"name": "Intmax.f_transfer_source",
"content": "lemma f_transfer_source\n (h : β block : {b : Block Kβ Kβ C Sigma V // b.isTransferBlock},\n T β TransactionsInBlock Ο block.1) :\n (f Ο T) .Source = Ο .Source"
}
] | import Mathlib
import Mathlib.Algebra.Group.Int
import FVIntmax.BalanceProof
import FVIntmax.Block
import FVIntmax.Key
import FVIntmax.Propositions
import FVIntmax.State
import FVIntmax.Transaction
import FVIntmax.Wheels
import FVIntmax.Wheels.Dictionary
namespace Intmax
noncomputable section
open Classical
section Balance
variable {Pi Kβ Kβ V C Sigma : Type}
section Extraction
section Deposit
variable [PreWithZero V]
def TransactionsInBlock_deposit
(b : { b : Block Kβ Kβ C Sigma V // b.isDepositBlock }) : List (Ξ€ Kβ Kβ V) :=
match h : b.1 with
| .deposit r v => [β¨(.Source, r, v), by admit /- proof elided -/
β©]
| .withdrawal .. | .transfer .. => by admit /- proof elided -/
end Deposit
section Transfer
variable [Finite Kβ] [Finite Kβ]
[LinearOrder Kβ] [LinearOrder Kβ] [PreWithZero V]
def TransactionsInBlock_transfer
(Ο : BalanceProof Kβ Kβ C Pi V) (b : { b : Block Kβ Kβ C Sigma V // b.isTransferBlock }) : List (Ξ€ Kβ Kβ V) :=
match h : b.1 with
| .transfer _ _ commitment S _ =>
let senderRecipient : Finset (Kβ Γ Key Kβ Kβ) := { (kβ, k) | (kβ : Kβ) (k : Key Kβ Kβ) (_h : kβ β β k) }
let sorted : List (Kβ Γ Key Kβ Kβ) := senderRecipient.sort Key.lexLe
let v (s : Kβ) (r : Key Kβ Kβ) : Option Vβ :=
if s β S
then .some 0
else
if h : (commitment, s) β Ο.keys
then let (_, t) := Ο[(commitment, s)]
t r
else .none
sorted.attach.map Ξ» β¨(s, r), hβ© β¦ β¨(s, r, v s r), by admit /- proof elided -/
β©
| .deposit .. | .withdrawal .. => by admit /- proof elided -/
end Transfer
section Withdrawal
variable [LinearOrder Kβ] [Finite Kβ] [PreWithZero V]
def TransactionsInBlock_withdrawal
(b : { b : Block Kβ Kβ C Sigma V // b.isWithdrawalBlock }) : List (Ξ€ Kβ Kβ V) :=
match h : b.1 with
| .withdrawal withdrawals =>
let kβInOrder := { s | s : Kβ }.toFinset.sort (Β·β€Β·)
kβInOrder.attach.map Ξ» s : Kβ β¦ β¨(s, .Source, withdrawals s), by admit /- proof elided -/
β©
| .deposit r v | .transfer .. => by admit /- proof elided -/
end Withdrawal
variable [Finite Kβ] [LinearOrder Kβ]
[Finite Kβ] [LinearOrder Kβ]
[PreWithZero V]
{b : Block Kβ Kβ C Sigma V}
{bs : List (Block Kβ Kβ C Sigma V)}
{Οβ Οβ : BalanceProof Kβ Kβ C Pi V}
def TransactionsInBlock (Ο : BalanceProof Kβ Kβ C Pi V) (b : Block Kβ Kβ C Sigma V) : List (Ξ€ Kβ Kβ V) :=
match h : b with
| .deposit .. => TransactionsInBlock_deposit βͺb
| .transfer .. => TransactionsInBlock_transfer Ο βͺb
| .withdrawal .. => TransactionsInBlock_withdrawal βͺb
end Extraction
section e
def e (i : Kbar Kβ Kβ) : Kbar Kβ Kβ β β€ := Ξ» j β¦ if i = j then 1 else 0
variable {i j : Kbar Kβ Kβ}
end e
section WithStructuredTypes
section v'
variable [Zero V] [Lattice V] -- NB `PreWithZero V` is implied as `CompleteLattice V` gives `Preorder V`.
variable {v : Vβ} {b : S Kβ Kβ V} {s : Kbar Kβ Kβ}
end v'
section Fc
variable [Lattice V]
[AddCommGroup V]
[CovariantClass V V (Β· + Β·) (Β· β€ Β·)]
[CovariantClass V V (Function.swap (Β· + Β·)) (Β· β€ Β·)]
def fc (ΟcXb : Ξ€c Kβ Kβ V Γ S Kβ Kβ V) : S Kβ Kβ V :=
β¨Ξ» k : Kbar Kβ Kβ β¦
match ΟcXb with
| β¨β¨β¨β¨s, r, vβ©, _β©, hΟβ©, bβ© =>
let v' := v' (v.get hΟ) b s
b k + (e r - e s) k β’ v',
by admit /- proof elided -/
β©
variable {Οc : Ξ€c Kβ Kβ V} {b : S Kβ Kβ V}
end Fc
section Order
variable [Lattice V] [AddCommGroup V]
end Order
section BoundedBelow
variable [Lattice V] [AddCommGroup V]
abbrev boundedBelow (b : S Kβ Kβ V) (T : Ξ€ Kβ Kβ V) :=
{ a : Ξ€c Kβ Kβ V Γ S Kβ Kβ V | (T, b) β€ (βa.1, a.2) }
end BoundedBelow
section LGroup
variable [Lattice V] [AddCommGroup V]
[CovariantClass V V (Β· + Β·) (Β· β€ Β·)]
[CovariantClass V V (Function.swap (Β· + Β·)) (Β· β€ Β·)]
def V' (b : S Kβ Kβ V) (T : Ξ€ Kβ Kβ V) (k : Kbar Kβ Kβ) : Set V :=
{ v : V | v β (fc Β· k) '' boundedBelow b T }
section f
def f' (b : S Kβ Kβ V) (T : Ξ€ Kβ Kβ V) : S Kβ Kβ V :=
β¨
Ξ» k β¦
match h : T with
| β¨(_, _, .some _), hTβ© => fc (β¨T, by admit /- proof elided -/
β©, b) k
| β¨(s, _, .none), _β© => if k = s then 0 else b k,
by admit /- proof elided -/
β©
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) } :=
β¨
f' b T,
Ξ» k β¦
have f'_codomain : (f' b T) k β V' b T k := by admit /- proof elided -/
β©
def infV (b : S Kβ Kβ V) (T : Ξ€ Kβ Kβ V) (k : Kbar Kβ Kβ) :
InfSet V where
sInf := Ξ» s β¦ if s = V' b T k
then (exists_inf b T).1 k
else 0
def f (b : S Kβ Kβ V) (T : Ξ€ Kβ Kβ V) : S Kβ Kβ V :=
β¨
Ξ» k β¦
have : InfSet V := infV b T k
β¨
x : boundedBelow b T, fc x.1 k,
by admit /- proof elided -/
β©
end f
section fStar
variable {s : S Kβ Kβ V}
end fStar
variable [Finite Kβ] [LinearOrder Kβ]
[Finite Kβ] [LinearOrder Kβ]
section LocalProperties
variable {Ο : S Kβ Kβ V}
{Ο : BalanceProof Kβ Kβ C Pi V}
{T : Ξ€ Kβ Kβ V}
{b : Block Kβ Kβ C Sigma V}
{Sigma : Type} | lemma f_transfer_source''
(h : b.isTransferBlock) (hβ : T β TransactionsInBlock Ο b) :
(f Ο T) .Source = Ο .Source := | := f_transfer_source β¨β¨b, hβ©, hββ© | 6 | 90 | false | Applied verif. |
207 | Intmax.sum_f_le_sum | lemma sum_f_le_sum : β (k : Kbar Kβ Kβ), f b T k β€ β (k : Kbar Kβ Kβ), b k | FVIntmax | FVIntmax/Lemma3.lean | [
"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": "Finset",
"module": "Mathlib.Data.Finset.Defs"
}
] | [
{
"name": "isComplete",
"content": "def isComplete (Ο : Ξ€ Kβ Kβ V) :=\n match Ο with | β¨(_, _, v), _β© => v.isSome"
},
{
"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": "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": "NonNeg",
"content": "def NonNeg (Ξ± : Type) [PreWithZero Ξ±] := { a : Ξ± // 0 β€ a }"
},
{
"name": "Ξ€c",
"content": "abbrev Ξ€c (Kβ Kβ V : Type) [PreWithZero V] : Type := { Ο : Ξ€ Kβ Kβ V // Ο.isComplete }"
},
{
"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": "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": "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": "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": "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": "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": "postfix:max \"β\" => NonNeg",
"content": "postfix:max \"β\" => NonNeg"
}
] | [
{
"name": "Finset.sum_add_distrib",
"module": "Mathlib.Algebra.BigOperators.Group.Finset.Basic"
},
{
"name": "Finset.sum_smul",
"module": "Mathlib.Algebra.Module.BigOperators"
},
{
"name": "Finset.sum_le_sum",
"module": "Mathlib.Algebra.Order.BigOperators.Group.Finset"
},
{
"name": "Set.mem_image",
"module": "Mathlib.Data.Set.Operations"
}
] | [
{
"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": "Intmax.sum_fc_eq_sum",
"content": "@[simp]\nlemma sum_fc_eq_sum : β (k : Kbar Kβ Kβ), fc (Tc, b) k = β (k : Kbar Kβ Kβ), b k"
}
] | import FVIntmax.Balance
namespace Intmax
section Lemma3
variable
{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 (Β· + Β·)) (Β· β€ Β·)]
variable {Tc : Ξ€c Kβ Kβ V} {T : Ξ€ Kβ Kβ V} {b : S Kβ Kβ V} {Tstar : List (Ξ€ Kβ Kβ V)} | lemma sum_f_le_sum : β (k : Kbar Kβ Kβ), f b T k β€ β (k : Kbar Kβ Kβ), b k := | := by
by_cases eq : T.isComplete
Β· conv_rhs => rw [βsum_fc_eq_sum (Tc := β¨T, eqβ©)]
refine' Finset.sum_le_sum (Ξ» k _ β¦ _)
have fcInV' : fc (β¨T, eqβ©, b) k β V' b T k := by
dsimp [V']
rw [Set.mem_image]
use (β¨T, eqβ©, b)
simp
exact f_IsGLB_of_V'.1 fcInV'
Β· rcases T with β¨β¨s, r, vβ©, hβ©
let Tc : Ξ€c Kβ Kβ V := β¨β¨(s, r, some 0), by validβ©, by simpβ©
conv_rhs => rw [βsum_fc_eq_sum (Tc := Tc)]
refine' (Finset.sum_le_sum (Ξ» k _ β¦ _))
have fcInV' : fc (Tc, b) k β V' b β¨(s, r, v), hβ© k := by
dsimp [V']
rw [Set.mem_image]
use (β¨β¨(s, r, some 0), by validβ©, by validβ©, b)
have : v = none := by aesop
simp [this, (Β·β€Β·)]
exact f_IsGLB_of_V'.1 fcInV' | 5 | 38 | false | Applied verif. |
208 | Intmax.v_transactionsInBlocks | lemma v_transactionsInBlocks {s r v v'} {eqβ eqβ} {i}
(h : Ο β€ Ο')
(hβ : i < (TransactionsInBlocks Ο Bstar).length)
(hβ : (TransactionsInBlocks Ο Bstar)[i] = β¨(s, r, v), eqββ©)
(hβ : (TransactionsInBlocks Ο' Bstar)[i]'(by blast with Ο) = β¨(s, r, v'), eqββ©) :
v β€ v' | FVIntmax | FVIntmax/Lemma4.lean | [
"import FVIntmax.Wheels.Dictionary",
"import FVIntmax.Wheels",
"import FVIntmax.Balance"
] | [
{
"name": "Preorder",
"module": "Mathlib.Order.Defs.PartialOrder"
},
{
"name": "Zero",
"module": "Init.Prelude"
},
{
"name": "DecidableEq",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Finite",
"module": "Mathlib.Data.Finite.Defs"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "Set",
"module": "Mathlib.Data.Set.Defs"
},
{
"name": "Finset",
"module": "Mathlib.Data.Finset.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": "local macro:max (priority := high) \"βͺ\" b:term : term => `(β¨$",
"content": "local macro:max (priority := high) \"βͺ\" b:term : term => `(β¨$b, by admit /- proof elided -/\nβ©)"
},
{
"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": "Injective",
"content": "class Injective {Ξ± Ο : Type} (f : Ξ± β Ο) where\n h : ComputationallyInfeasible (Β¬ Function.Injective f)"
},
{
"name": "NonNeg",
"content": "def NonNeg (Ξ± : Type) [PreWithZero Ξ±] := { a : Ξ± // 0 β€ a }"
},
{
"name": "abbrev",
"content": "class abbrev PreWithZero (Ξ± : Type) := Preorder Ξ±, Zero Ξ±"
},
{
"name": "Kbar",
"content": "inductive Kbar (Kβ Kβ : Type) where\n | key (k : Key Kβ Kβ)\n | Source\nderiving DecidableEq"
},
{
"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": "Key",
"content": "abbrev Key (Kβ Kβ : Type) := Kβ β Kβ"
},
{
"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": "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": "isWithdrawalBlock",
"content": "abbrev isWithdrawalBlock (b : Block Kβ Kβ C Sigma V) := b matches (Block.withdrawal _)"
},
{
"name": "ExtraDataT",
"content": "abbrev ExtraDataT : Type := β"
},
{
"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": "Ξ€",
"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": "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": "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": "Dict",
"content": "abbrev Dict (Ξ± Ο : Type) : Type := Ξ± β Option Ο"
},
{
"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": "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": "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": "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"
}
] | 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
open Lean.Elab.Tactic in
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)}
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)} | lemma v_transactionsInBlocks {s r v v'} {eqβ eqβ} {i}
(h : Ο β€ Ο')
(hβ : i < (TransactionsInBlocks Ο Bstar).length)
(hβ : (TransactionsInBlocks Ο Bstar)[i] = β¨(s, r, v), eqββ©)
(hβ : (TransactionsInBlocks Ο' Bstar)[i]'(by blast with Ο) = β¨(s, r, v'), eqββ©) :
v β€ v' := | := by
unfold TransactionsInBlocks at hβ hβ
apply List.map_eq_project_triple at hβ
apply List.map_eq_project_triple at hβ
rw [βhβ, βhβ]
apply List.map_join_unnecessarily_specific (by ext x; simp; rw [length_transactionsInBlock])
intros b i hβ
unfold TransactionsInBlock
match h' : b with
| Block.transfer .. =>
rcases delta_TransactionsInBlock_transfer (b := β¨b, by aesopβ©) h i (by aesop) <;>
[aesop; (simp [(Β·β€Β·)]; aesop)]
| Block.deposit .. | Block.withdrawal .. => simp | 7 | 57 | false | Applied verif. |
209 | Intmax.lemma3 | lemma lemma3 : Bal Ο bs .Source β€ 0 | FVIntmax | FVIntmax/Lemma3.lean | [
"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": "Finite",
"module": "Mathlib.Data.Finite.Defs"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Finset",
"module": "Mathlib.Data.Finset.Defs"
},
{
"name": "Finset.univ",
"module": "Mathlib.Data.Fintype.Defs"
}
] | [
{
"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": "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": "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": "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": "abbrev",
"content": "class abbrev PreWithZero (Ξ± : Type) := Preorder Ξ±, Zero Ξ±"
},
{
"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": "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": "ExtraDataT",
"content": "abbrev ExtraDataT : Type := β"
},
{
"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": "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": "Dict",
"content": "abbrev Dict (Ξ± Ο : Type) : Type := Ξ± β Option Ο"
},
{
"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": "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": "initial",
"content": "def initial (Kβ Kβ V : Type) [PreWithZero V] : S Kβ Kβ V :=\n β¨S'.initial Kβ Kβ V, S'.isValid_initialβ©"
},
{
"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": "Finset.sum_add_distrib",
"module": "Mathlib.Algebra.BigOperators.Group.Finset.Basic"
},
{
"name": "Finset.sum_smul",
"module": "Mathlib.Algebra.Module.BigOperators"
},
{
"name": "Finset.sum_le_sum",
"module": "Mathlib.Algebra.Order.BigOperators.Group.Finset"
},
{
"name": "Set.mem_image",
"module": "Mathlib.Data.Set.Operations"
},
{
"name": "le_trans",
"module": "Mathlib.Order.Defs.PartialOrder"
},
{
"name": "Finset.sum_nonneg",
"module": "Mathlib.Algebra.Order.BigOperators.Group.Finset"
},
{
"name": "Finset.sum_singleton",
"module": "Mathlib.Algebra.BigOperators.Group.Finset.Basic"
},
{
"name": "sub_nonpos",
"module": "Mathlib.Algebra.Order.Group.Unbundled.Basic"
}
] | [
{
"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": "Intmax.sum_fc_eq_sum",
"content": "@[simp]\nlemma sum_fc_eq_sum : β (k : Kbar Kβ Kβ), fc (Tc, b) k = β (k : Kbar Kβ Kβ), b k"
},
{
"name": "Intmax.sum_f_le_sum",
"content": "lemma sum_f_le_sum : β (k : Kbar Kβ Kβ), f b T k β€ β (k : Kbar Kβ Kβ), b k"
},
{
"name": "Intmax.sum_fStar_le_zero_aux",
"content": "private lemma sum_fStar_le_zero_aux (h : β (k : Kbar Kβ Kβ), b k β€ 0) :\n β (k : Kbar Kβ Kβ), fStar Tstar b k β€ 0"
}
] | import FVIntmax.Balance
namespace Intmax
section Lemma3
variable
{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 (Β· + Β·)) (Β· β€ Β·)]
variable {Tc : Ξ€c Kβ Kβ V} {T : Ξ€ Kβ Kβ V} {b : S Kβ Kβ V} {Tstar : List (Ξ€ Kβ Kβ V)}
variable [LinearOrder Kβ] [LinearOrder Kβ]
{Ο : BalanceProof Kβ Kβ C Pi V}
{bs : List (Block Kβ Kβ C Sigma V)} | lemma lemma3 : Bal Ο bs .Source β€ 0 := | := by
dsimp [Bal]
generalize eq : TransactionsInBlocks Ο _ = blocks
generalize eqβ : S.initial Kβ Kβ V = sβ
generalize eqβ : fStar blocks sβ = f
have : β x β {Kbar.Source}, f x =
β x : Kbar Kβ Kβ, f x - β x β Finset.univ \ {Kbar.Source}, f x := by simp
rw [βFinset.sum_singleton (a := Kbar.Source) (f := f), this, sub_nonpos]
have := sum_fStar_le_zero_aux (Tstar := blocks) (b := sβ)
have eqβ : β x : Kbar Kβ Kβ, f x β€ 0 := by aesop
have eqβ : 0 β€ β x β Finset.univ \ {Kbar.Source}, f x := Finset.sum_nonneg Ξ» i β¦ by rcases i <;> aesop
exact le_trans eqβ eqβ | 9 | 75 | false | Applied verif. |
210 | Intmax.proposition4 | lemma proposition4 [Setoid' X] {x y : Option X} :
(β join : Option X, IsLUB {x, y, .none} join) β (x β .none β§ y β .none β x β
y) | FVIntmax | FVIntmax/Propositions.lean | [
"import Mathlib.Order.Bounds.Basic",
"import FVIntmax.Wheels.Dictionary",
"import Aesop",
"import Mathlib.Order.Bounds.Defs",
"import Mathlib.Order.Defs"
] | [
{
"name": "Preorder",
"module": "Mathlib.Order.Defs.PartialOrder"
},
{
"name": "IsLUB",
"module": "Mathlib.Order.Bounds.Defs"
},
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "Iff",
"module": "Init.Core"
},
{
"name": "IsLeast",
"module": "Mathlib.Order.Bounds.Defs"
},
{
"name": "lowerBounds",
"module": "Mathlib.Order.Bounds.Defs"
},
{
"name": "upperBounds",
"module": "Mathlib.Order.Bounds.Defs"
},
{
"name": "Set",
"module": "Mathlib.Data.Set.Defs"
},
{
"name": "Set.Ici",
"module": "Mathlib.Order.Interval.Set.Defs"
}
] | [
{
"name": "notation:51 (priority := high) a:52 \" β
\" b:52 => iso a b",
"content": "notation:51 (priority := high) a:52 \" β
\" b:52 => iso a b"
}
] | [
{
"name": "le_trans",
"module": "Mathlib.Order.Defs.PartialOrder"
},
{
"name": "mem_upperBounds",
"module": "Mathlib.Order.Bounds.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": "Intmax.iso",
"content": "def iso {X : Type} [Preorder X] (a b : X) := a β€ b β§ b β€ a"
},
{
"name": "Intmax.IsEquivRel",
"content": "def IsEquivRel {X : Type} [Preorder X] := β a b : X, a β€ b β a β
b"
},
{
"name": "Intmax.Setoid'",
"content": "class Setoid' (X : Type) extends Preorder X where\n isEquiv : IsEquivRel (X := X)"
}
] | [
{
"name": "Intmax.iso_rfl",
"content": "@[simp, refl]\nlemma iso_rfl : a β
a"
},
{
"name": "Intmax.iso_trans",
"content": "@[trans]\nlemma iso_trans : (a β
b) β (b β
c) β a β
c"
},
{
"name": "Intmax.proposition2",
"content": "lemma proposition2 [Setoid' X] {x y : X} :\n (β join : X, IsLUB {x, y} join) β x β
y"
},
{
"name": "Intmax.proposition2'",
"content": "lemma proposition2' [Setoid' X] {join x y : X} (h : IsLUB {x, y} join) :\n (x β
join) β§ y β
join"
},
{
"name": "Intmax.proposition3'",
"content": "lemma proposition3' : \n (β join : X, IsLUB {x, y} join) β (β join : Option X, IsLUB {.some x, .some y, .none} join)"
}
] | import Mathlib.Order.Bounds.Basic
import Mathlib.Order.Bounds.Defs
import Mathlib.Order.Defs
import Aesop
import FVIntmax.Wheels.Dictionary
namespace Intmax
def iso {X : Type} [Preorder X] (a b : X) := a β€ b β§ b β€ a
notation:51 (priority := high) a:52 " β
" b:52 => iso a b
section iso
variable {X : Type} [Preorder X]
{a b c : X}
end iso
def IsEquivRel {X : Type} [Preorder X] := β a b : X, a β€ b β a β
b
class Setoid' (X : Type) extends Preorder X where
isEquiv : IsEquivRel (X := X)
section Automation
variable {Ξ± : Type} [Preorder Ξ±]
{x y : Ξ±}
end Automation
section Propositions
variable {X Y : Type}
section proposition3
variable [Preorder X]
{x? y? join? join'? : Option X}
{x y join join' : X}
end proposition3
section Automation
variable {X : Type} [Setoid' X]
{x y : X}
{x? y? : Option X}
end Automation | lemma proposition4 [Setoid' X] {x y : Option X} :
(β join : Option X, IsLUB {x, y, .none} join) β (x β .none β§ y β .none β x β
y) := | := by
refine' Iff.intro (Ξ» h β¨hβ, hββ© β¦ _) (Ξ» h β¦ _)
Β· rcases x with _ | x <;> rcases y with _ | y <;> [rfl; simp at hβ; simp at hβ; skip]
simp
rw [βproposition3'] at h
rcases h with β¨join, hβ©
obtain β¨hβ, hββ© := proposition2' h
exact iso_trans hβ hβ.symm
Β· rcases x with _ | x <;> rcases y with _ | y
Β· use .none; simp
Β· use .some y; simp
Β· use .some x; simp
Β· simp at h
simp_rw [βproposition3']
exact proposition2.2 h | 3 | 19 | false | Applied verif. |
211 | Intmax.sender_transactionsInBlock | lemma sender_transactionsInBlock :
(TransactionsInBlock Οβ b).map (Ξ» s β¦ s.1.1) =
(TransactionsInBlock Οβ b).map (Ξ» s β¦ s.1.1) | FVIntmax | FVIntmax/Balance.lean | [
"import FVIntmax.BalanceProof",
"import FVIntmax.Wheels",
"import FVIntmax.Propositions",
"import Mathlib",
"import FVIntmax.Key",
"import FVIntmax.Block",
"import Mathlib.Algebra.Group.Int",
"import FVIntmax.Wheels.Dictionary",
"import FVIntmax.State",
"import FVIntmax.Transaction"
] | [
{
"name": "Preorder",
"module": "Mathlib.Order.Defs.PartialOrder"
},
{
"name": "Zero",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Finite",
"module": "Mathlib.Data.Finite.Defs"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "DecidableEq",
"module": "Init.Prelude"
},
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "Set",
"module": "Mathlib.Data.Set.Defs"
},
{
"name": "Finset",
"module": "Mathlib.Data.Finset.Defs"
},
{
"name": "Sum",
"module": "Init.Core"
}
] | [
{
"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": "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": "ExtraDataT",
"content": "abbrev ExtraDataT : Type := β"
},
{
"name": "abbrev",
"content": "class abbrev PreWithZero (Ξ± : Type) := Preorder Ξ±, Zero Ξ±"
},
{
"name": "NonNeg",
"content": "def NonNeg (Ξ± : Type) [PreWithZero Ξ±] := { a : Ξ± // 0 β€ a }"
},
{
"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": "Ξ€",
"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": "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": "Injective",
"content": "class Injective {Ξ± Ο : Type} (f : Ξ± β Ο) where\n h : ComputationallyInfeasible (Β¬ Function.Injective f)"
},
{
"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": "Dict",
"content": "abbrev Dict (Ξ± Ο : Type) : Type := Ξ± β Option Ο"
},
{
"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": "isDepositBlock",
"content": "abbrev isDepositBlock (b : Block Kβ Kβ C Sigma V) := b matches (Block.deposit _ _) "
},
{
"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": "Finset.length_sort",
"module": "Mathlib.Data.Finset.Sort"
},
{
"name": "List.length_attach",
"module": "Init.Data.List.Attach"
},
{
"name": "List.length_map",
"module": "Init.Data.List.Lemmas"
},
{
"name": "exists_and_left",
"module": "Init.PropLemmas"
},
{
"name": "exists_prop",
"module": "Init.PropLemmas"
},
{
"name": "ite_not",
"module": "Init.PropLemmas"
},
{
"name": "true_and",
"module": "Init.SimpLemmas"
},
{
"name": "List.ext_get",
"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": "Intmax.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": "Intmax.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": "Intmax.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": "Intmax.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": "Intmax.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": "Intmax.length_transactionsInBlock",
"content": "lemma length_transactionsInBlock :\n (TransactionsInBlock Οβ b).length = (TransactionsInBlock Οβ b).length"
}
] | import Mathlib
import Mathlib.Algebra.Group.Int
import FVIntmax.BalanceProof
import FVIntmax.Block
import FVIntmax.Key
import FVIntmax.Propositions
import FVIntmax.State
import FVIntmax.Transaction
import FVIntmax.Wheels
import FVIntmax.Wheels.Dictionary
namespace Intmax
noncomputable section
open Classical
section Balance
variable {Pi Kβ Kβ V C Sigma : Type}
section Extraction
section Deposit
variable [PreWithZero V]
def TransactionsInBlock_deposit
(b : { b : Block Kβ Kβ C Sigma V // b.isDepositBlock }) : List (Ξ€ Kβ Kβ V) :=
match h : b.1 with
| .deposit r v => [β¨(.Source, r, v), by admit /- proof elided -/
β©]
| .withdrawal .. | .transfer .. => by admit /- proof elided -/
end Deposit
section Transfer
variable [Finite Kβ] [Finite Kβ]
[LinearOrder Kβ] [LinearOrder Kβ] [PreWithZero V]
def TransactionsInBlock_transfer
(Ο : BalanceProof Kβ Kβ C Pi V) (b : { b : Block Kβ Kβ C Sigma V // b.isTransferBlock }) : List (Ξ€ Kβ Kβ V) :=
match h : b.1 with
| .transfer _ _ commitment S _ =>
let senderRecipient : Finset (Kβ Γ Key Kβ Kβ) := { (kβ, k) | (kβ : Kβ) (k : Key Kβ Kβ) (_h : kβ β β k) }
let sorted : List (Kβ Γ Key Kβ Kβ) := senderRecipient.sort Key.lexLe
let v (s : Kβ) (r : Key Kβ Kβ) : Option Vβ :=
if s β S
then .some 0
else
if h : (commitment, s) β Ο.keys
then let (_, t) := Ο[(commitment, s)]
t r
else .none
sorted.attach.map Ξ» β¨(s, r), hβ© β¦ β¨(s, r, v s r), by admit /- proof elided -/
β©
| .deposit .. | .withdrawal .. => by admit /- proof elided -/
end Transfer
section Withdrawal
variable [LinearOrder Kβ] [Finite Kβ] [PreWithZero V]
def TransactionsInBlock_withdrawal
(b : { b : Block Kβ Kβ C Sigma V // b.isWithdrawalBlock }) : List (Ξ€ Kβ Kβ V) :=
match h : b.1 with
| .withdrawal withdrawals =>
let kβInOrder := { s | s : Kβ }.toFinset.sort (Β·β€Β·)
kβInOrder.attach.map Ξ» s : Kβ β¦ β¨(s, .Source, withdrawals s), by admit /- proof elided -/
β©
| .deposit r v | .transfer .. => by admit /- proof elided -/
end Withdrawal
variable [Finite Kβ] [LinearOrder Kβ]
[Finite Kβ] [LinearOrder Kβ]
[PreWithZero V]
{b : Block Kβ Kβ C Sigma V}
{bs : List (Block Kβ Kβ C Sigma V)}
{Οβ Οβ : BalanceProof Kβ Kβ C Pi V}
def TransactionsInBlock (Ο : BalanceProof Kβ Kβ C Pi V) (b : Block Kβ Kβ C Sigma V) : List (Ξ€ Kβ Kβ V) :=
match h : b with
| .deposit .. => TransactionsInBlock_deposit βͺb
| .transfer .. => TransactionsInBlock_transfer Ο βͺb
| .withdrawal .. => TransactionsInBlock_withdrawal βͺb | lemma sender_transactionsInBlock :
(TransactionsInBlock Οβ b).map (Ξ» s β¦ s.1.1) =
(TransactionsInBlock Οβ b).map (Ξ» s β¦ s.1.1) := | := by
apply List.ext_get (by simp; rw [length_transactionsInBlock])
intros n hβ hβ
simp; unfold TransactionsInBlock
match b with
| Block.deposit .. => simp [TransactionsInBlock_deposit]
| Block.transfer .. => simp [TransactionsInBlock_transfer]
| Block.withdrawal .. => simp [TransactionsInBlock_withdrawal] | 5 | 48 | false | Applied verif. |
212 | Intmax.receiver_transactionsInBlock | lemma receiver_transactionsInBlock :
(TransactionsInBlock Οβ b).map (Ξ» s β¦ s.1.2.1) =
(TransactionsInBlock Οβ b).map (Ξ» s β¦ s.1.2.1) | FVIntmax | FVIntmax/Balance.lean | [
"import FVIntmax.BalanceProof",
"import FVIntmax.Wheels",
"import FVIntmax.Propositions",
"import Mathlib",
"import FVIntmax.Key",
"import FVIntmax.Block",
"import Mathlib.Algebra.Group.Int",
"import FVIntmax.Wheels.Dictionary",
"import FVIntmax.State",
"import FVIntmax.Transaction"
] | [
{
"name": "Preorder",
"module": "Mathlib.Order.Defs.PartialOrder"
},
{
"name": "Zero",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Finite",
"module": "Mathlib.Data.Finite.Defs"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "DecidableEq",
"module": "Init.Prelude"
},
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "Set",
"module": "Mathlib.Data.Set.Defs"
},
{
"name": "Finset",
"module": "Mathlib.Data.Finset.Defs"
},
{
"name": "Sum",
"module": "Init.Core"
}
] | [
{
"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": "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": "ExtraDataT",
"content": "abbrev ExtraDataT : Type := β"
},
{
"name": "abbrev",
"content": "class abbrev PreWithZero (Ξ± : Type) := Preorder Ξ±, Zero Ξ±"
},
{
"name": "NonNeg",
"content": "def NonNeg (Ξ± : Type) [PreWithZero Ξ±] := { a : Ξ± // 0 β€ a }"
},
{
"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": "Ξ€",
"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": "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": "Injective",
"content": "class Injective {Ξ± Ο : Type} (f : Ξ± β Ο) where\n h : ComputationallyInfeasible (Β¬ Function.Injective f)"
},
{
"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": "Dict",
"content": "abbrev Dict (Ξ± Ο : Type) : Type := Ξ± β Option Ο"
},
{
"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": "isDepositBlock",
"content": "abbrev isDepositBlock (b : Block Kβ Kβ C Sigma V) := b matches (Block.deposit _ _) "
},
{
"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": "Finset.length_sort",
"module": "Mathlib.Data.Finset.Sort"
},
{
"name": "List.length_attach",
"module": "Init.Data.List.Attach"
},
{
"name": "List.length_map",
"module": "Init.Data.List.Lemmas"
},
{
"name": "exists_and_left",
"module": "Init.PropLemmas"
},
{
"name": "exists_prop",
"module": "Init.PropLemmas"
},
{
"name": "ite_not",
"module": "Init.PropLemmas"
},
{
"name": "true_and",
"module": "Init.SimpLemmas"
},
{
"name": "List.ext_get",
"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": "Intmax.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": "Intmax.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": "Intmax.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": "Intmax.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": "Intmax.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": "Intmax.length_transactionsInBlock",
"content": "lemma length_transactionsInBlock :\n (TransactionsInBlock Οβ b).length = (TransactionsInBlock Οβ b).length"
}
] | import Mathlib
import Mathlib.Algebra.Group.Int
import FVIntmax.BalanceProof
import FVIntmax.Block
import FVIntmax.Key
import FVIntmax.Propositions
import FVIntmax.State
import FVIntmax.Transaction
import FVIntmax.Wheels
import FVIntmax.Wheels.Dictionary
namespace Intmax
noncomputable section
open Classical
section Balance
variable {Pi Kβ Kβ V C Sigma : Type}
section Extraction
section Deposit
variable [PreWithZero V]
def TransactionsInBlock_deposit
(b : { b : Block Kβ Kβ C Sigma V // b.isDepositBlock }) : List (Ξ€ Kβ Kβ V) :=
match h : b.1 with
| .deposit r v => [β¨(.Source, r, v), by admit /- proof elided -/
β©]
| .withdrawal .. | .transfer .. => by admit /- proof elided -/
end Deposit
section Transfer
variable [Finite Kβ] [Finite Kβ]
[LinearOrder Kβ] [LinearOrder Kβ] [PreWithZero V]
def TransactionsInBlock_transfer
(Ο : BalanceProof Kβ Kβ C Pi V) (b : { b : Block Kβ Kβ C Sigma V // b.isTransferBlock }) : List (Ξ€ Kβ Kβ V) :=
match h : b.1 with
| .transfer _ _ commitment S _ =>
let senderRecipient : Finset (Kβ Γ Key Kβ Kβ) := { (kβ, k) | (kβ : Kβ) (k : Key Kβ Kβ) (_h : kβ β β k) }
let sorted : List (Kβ Γ Key Kβ Kβ) := senderRecipient.sort Key.lexLe
let v (s : Kβ) (r : Key Kβ Kβ) : Option Vβ :=
if s β S
then .some 0
else
if h : (commitment, s) β Ο.keys
then let (_, t) := Ο[(commitment, s)]
t r
else .none
sorted.attach.map Ξ» β¨(s, r), hβ© β¦ β¨(s, r, v s r), by admit /- proof elided -/
β©
| .deposit .. | .withdrawal .. => by admit /- proof elided -/
end Transfer
section Withdrawal
variable [LinearOrder Kβ] [Finite Kβ] [PreWithZero V]
def TransactionsInBlock_withdrawal
(b : { b : Block Kβ Kβ C Sigma V // b.isWithdrawalBlock }) : List (Ξ€ Kβ Kβ V) :=
match h : b.1 with
| .withdrawal withdrawals =>
let kβInOrder := { s | s : Kβ }.toFinset.sort (Β·β€Β·)
kβInOrder.attach.map Ξ» s : Kβ β¦ β¨(s, .Source, withdrawals s), by admit /- proof elided -/
β©
| .deposit r v | .transfer .. => by admit /- proof elided -/
end Withdrawal
variable [Finite Kβ] [LinearOrder Kβ]
[Finite Kβ] [LinearOrder Kβ]
[PreWithZero V]
{b : Block Kβ Kβ C Sigma V}
{bs : List (Block Kβ Kβ C Sigma V)}
{Οβ Οβ : BalanceProof Kβ Kβ C Pi V}
def TransactionsInBlock (Ο : BalanceProof Kβ Kβ C Pi V) (b : Block Kβ Kβ C Sigma V) : List (Ξ€ Kβ Kβ V) :=
match h : b with
| .deposit .. => TransactionsInBlock_deposit βͺb
| .transfer .. => TransactionsInBlock_transfer Ο βͺb
| .withdrawal .. => TransactionsInBlock_withdrawal βͺb | lemma receiver_transactionsInBlock :
(TransactionsInBlock Οβ b).map (Ξ» s β¦ s.1.2.1) =
(TransactionsInBlock Οβ b).map (Ξ» s β¦ s.1.2.1) := | := by
apply List.ext_get (by simp; rw [length_transactionsInBlock])
intros n hβ hβ
simp; unfold TransactionsInBlock
match b with
| Block.deposit .. => simp [TransactionsInBlock_deposit]
| Block.transfer .. => simp [TransactionsInBlock_transfer]
| Block.withdrawal .. => simp [TransactionsInBlock_withdrawal] | 5 | 48 | false | Applied verif. |
213 | Intmax.f_withdrawal_block_source | lemma f_withdrawal_block_source (h : b.isWithdrawalBlock) :
((TransactionsInBlock Ο b).foldl f Ο) .Source = Ο .Source + β k : Kβ, (b.getWithdrawal h k).1 β Ο k | FVIntmax | FVIntmax/Balance.lean | [
"import FVIntmax.BalanceProof",
"import FVIntmax.Wheels",
"import FVIntmax.Propositions",
"import Mathlib",
"import FVIntmax.Key",
"import FVIntmax.Block",
"import Mathlib.Algebra.Group.Int",
"import FVIntmax.Wheels.Dictionary",
"import FVIntmax.State",
"import FVIntmax.Transaction"
] | [
{
"name": "Preorder",
"module": "Mathlib.Order.Defs.PartialOrder"
},
{
"name": "Zero",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Finite",
"module": "Mathlib.Data.Finite.Defs"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "DecidableEq",
"module": "Init.Prelude"
},
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "Set",
"module": "Mathlib.Data.Set.Defs"
},
{
"name": "Finset",
"module": "Mathlib.Data.Finset.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": "LinearOrder",
"module": "Mathlib.Order.Defs.LinearOrder"
},
{
"name": "List.foldl",
"module": "Init.Prelude"
},
{
"name": "List.map",
"module": "Init.Prelude"
},
{
"name": "Sum",
"module": "Init.Core"
},
{
"name": "Sum.inl",
"module": "Init.Core"
},
{
"name": "reduceCtorEq",
"module": "Lean.Meta.Tactic.Simp.BuiltinSimprocs.Core"
},
{
"name": "Set.range",
"module": "Mathlib.Data.Set.Operations"
}
] | [
{
"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": "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": "ExtraDataT",
"content": "abbrev ExtraDataT : Type := β"
},
{
"name": "abbrev",
"content": "class abbrev PreWithZero (Ξ± : Type) := Preorder Ξ±, Zero Ξ±"
},
{
"name": "NonNeg",
"content": "def NonNeg (Ξ± : Type) [PreWithZero Ξ±] := { a : Ξ± // 0 β€ a }"
},
{
"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": "Ξ€",
"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": "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": "Injective",
"content": "class Injective {Ξ± Ο : Type} (f : Ξ± β Ο) where\n h : ComputationallyInfeasible (Β¬ Function.Injective f)"
},
{
"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": "Dict",
"content": "abbrev Dict (Ξ± Ο : Type) : Type := Ξ± β Option Ο"
},
{
"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": "isDepositBlock",
"content": "abbrev isDepositBlock (b : Block Kβ Kβ C Sigma V) := b matches (Block.deposit _ _) "
},
{
"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": "Ξ€c",
"content": "abbrev Ξ€c (Kβ Kβ V : Type) [PreWithZero V] : Type := { Ο : Ξ€ Kβ Kβ V // Ο.isComplete }"
},
{
"name": "isComplete",
"content": "def isComplete (Ο : Ξ€ Kβ Kβ V) :=\n match Ο with | β¨(_, _, v), _β© => v.isSome"
},
{
"name": "getWithdrawal",
"content": "def getWithdrawal (b : Block Kβ Kβ C Sigma V) (_h : b.isWithdrawalBlock) : Kβ β Vβ :=\n match b with | .withdrawal B => B"
},
{
"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": "Finset.filter_eq'",
"module": "Mathlib.Data.Finset.Basic"
},
{
"name": "Finset.filter_or",
"module": "Mathlib.Data.Finset.Basic"
},
{
"name": "Finset.mem_univ",
"module": "Mathlib.Data.Fintype.Defs"
},
{
"name": "Finset.sum_congr",
"module": "Mathlib.Algebra.BigOperators.Group.Finset.Basic"
},
{
"name": "Finset.sum_const_zero",
"module": "Mathlib.Algebra.BigOperators.Group.Finset.Defs"
},
{
"name": "Finset.sum_ite",
"module": "Mathlib.Algebra.BigOperators.Group.Finset.Piecewise"
},
{
"name": "Finset.sum_singleton",
"module": "Mathlib.Algebra.BigOperators.Group.Finset.Basic"
},
{
"name": "Finset.sum_union",
"module": "Mathlib.Algebra.BigOperators.Group.Finset.Basic"
},
{
"name": "List.foldl_cons",
"module": "Init.Data.List.Basic"
},
{
"name": "List.map_cons",
"module": "Init.Data.List.Basic"
},
{
"name": "List.mem_cons",
"module": "Init.Data.List.Lemmas"
},
{
"name": "Option.get_some",
"module": "Init.Data.Option.Basic"
},
{
"name": "add_assoc",
"module": "Mathlib.Algebra.Group.Defs"
},
{
"name": "add_left_inj",
"module": "Mathlib.Algebra.Group.Defs"
},
{
"name": "add_right_inj",
"module": "Mathlib.Algebra.Group.Defs"
},
{
"name": "add_zero",
"module": "Mathlib.Algebra.Group.Defs"
},
{
"name": "ite_smul",
"module": "Mathlib.Algebra.Group.Basic"
},
{
"name": "neg_smul",
"module": "Mathlib.Algebra.Module.Defs"
},
{
"name": "not_or",
"module": "Init.PropLemmas"
},
{
"name": "one_smul",
"module": "Mathlib.Algebra.Group.Action.Defs"
},
{
"name": "sub_zero",
"module": "Mathlib.Algebra.Group.Basic"
},
{
"name": "zero_smul",
"module": "Mathlib.Algebra.GroupWithZero.Action.Defs"
},
{
"name": "zero_sub",
"module": "Mathlib.Algebra.Group.Defs"
},
{
"name": "Set.image_eq_range",
"module": "Mathlib.Data.Set.Image"
},
{
"name": "if_pos",
"module": "Init.Core"
},
{
"name": "Finset.mem_sort",
"module": "Mathlib.Data.Finset.Sort"
},
{
"name": "List.bind_eq_flatMap",
"module": "Mathlib.Data.List.Basic"
},
{
"name": "List.flatMap_singleton'",
"module": "Init.Data.List.Lemmas"
},
{
"name": "List.flatMap_subtype",
"module": "Init.Data.List.Attach"
},
{
"name": "List.pure_def",
"module": "Mathlib.Data.List.Monad"
},
{
"name": "List.unattach_attach",
"module": "Init.Data.List.Attach"
},
{
"name": "Set.setOf_true",
"module": "Mathlib.Data.Set.Basic"
},
{
"name": "Set.toFinset_univ",
"module": "Mathlib.Data.Fintype.Sets"
},
{
"name": "exists_eq",
"module": "Init.PropLemmas"
},
{
"name": "forall_const",
"module": "Init.PropLemmas"
}
] | [
{
"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": "Intmax.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": "Intmax.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": "Intmax.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": "Intmax.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": "Intmax.e",
"content": "def e (i : Kbar Kβ Kβ) : Kbar Kβ Kβ β β€ := Ξ» j β¦ if i = j then 1 else 0"
},
{
"name": "Intmax.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": "Intmax.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": "Intmax.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": "Intmax.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": "Intmax.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": "Intmax.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": "Intmax.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": "Intmax.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": "Intmax.e_def",
"content": "@[simp]\nlemma e_def : e i = Ξ» j β¦ if i = j then 1 else 0"
},
{
"name": "Intmax.v'_key_eq_meet",
"content": "@[simp]\nlemma v'_key_eq_meet {k : Key Kβ Kβ} : v' v b (Kbar.key k) = β¨v β b k, by simpβ©"
},
{
"name": "Intmax.V'_eq_range",
"content": "private lemma V'_eq_range {b : S Kβ Kβ V} {T : Ξ€ Kβ Kβ V} {k : Kbar Kβ Kβ} :\n V' b T k =\n Set.range Ξ» (x : { x : (Ξ€c Kβ Kβ V Γ S Kβ Kβ V) // (T, b) β€ (βx.1, x.2) }) β¦ fc βx k"
},
{
"name": "Intmax.f_eq_f'",
"content": "lemma f_eq_f' : f = f' (Kβ := Kβ) (Kβ := Kβ) (V := V)"
},
{
"name": "Intmax.f_withdrawal_block_source_aux",
"content": "omit [Finite Kβ] [LinearOrder Kβ] in\nprivate lemma f_withdrawal_block_source_aux {l : List Kβ}\n (hβ : l.Nodup) (h : b.isWithdrawalBlock) :\n (List.foldl f' Ο\n (List.map (Ξ» s : Kβ β¦ β¨(s, Kbar.Source, some (b.getWithdrawal h s)), by unfold Ξ€'.isValid; aesopβ©) l)).1\n .Source = Ο .Source + β x : Kβ, if x β l then (β(b.getWithdrawal h x) β Ο x) else 0"
}
] | import Mathlib
import Mathlib.Algebra.Group.Int
import FVIntmax.BalanceProof
import FVIntmax.Block
import FVIntmax.Key
import FVIntmax.Propositions
import FVIntmax.State
import FVIntmax.Transaction
import FVIntmax.Wheels
import FVIntmax.Wheels.Dictionary
namespace Intmax
noncomputable section
open Classical
section Balance
variable {Pi Kβ Kβ V C Sigma : Type}
section Extraction
section Deposit
variable [PreWithZero V]
def TransactionsInBlock_deposit
(b : { b : Block Kβ Kβ C Sigma V // b.isDepositBlock }) : List (Ξ€ Kβ Kβ V) :=
match h : b.1 with
| .deposit r v => [β¨(.Source, r, v), by admit /- proof elided -/
β©]
| .withdrawal .. | .transfer .. => by admit /- proof elided -/
end Deposit
section Transfer
variable [Finite Kβ] [Finite Kβ]
[LinearOrder Kβ] [LinearOrder Kβ] [PreWithZero V]
def TransactionsInBlock_transfer
(Ο : BalanceProof Kβ Kβ C Pi V) (b : { b : Block Kβ Kβ C Sigma V // b.isTransferBlock }) : List (Ξ€ Kβ Kβ V) :=
match h : b.1 with
| .transfer _ _ commitment S _ =>
let senderRecipient : Finset (Kβ Γ Key Kβ Kβ) := { (kβ, k) | (kβ : Kβ) (k : Key Kβ Kβ) (_h : kβ β β k) }
let sorted : List (Kβ Γ Key Kβ Kβ) := senderRecipient.sort Key.lexLe
let v (s : Kβ) (r : Key Kβ Kβ) : Option Vβ :=
if s β S
then .some 0
else
if h : (commitment, s) β Ο.keys
then let (_, t) := Ο[(commitment, s)]
t r
else .none
sorted.attach.map Ξ» β¨(s, r), hβ© β¦ β¨(s, r, v s r), by admit /- proof elided -/
β©
| .deposit .. | .withdrawal .. => by admit /- proof elided -/
end Transfer
section Withdrawal
variable [LinearOrder Kβ] [Finite Kβ] [PreWithZero V]
def TransactionsInBlock_withdrawal
(b : { b : Block Kβ Kβ C Sigma V // b.isWithdrawalBlock }) : List (Ξ€ Kβ Kβ V) :=
match h : b.1 with
| .withdrawal withdrawals =>
let kβInOrder := { s | s : Kβ }.toFinset.sort (Β·β€Β·)
kβInOrder.attach.map Ξ» s : Kβ β¦ β¨(s, .Source, withdrawals s), by admit /- proof elided -/
β©
| .deposit r v | .transfer .. => by admit /- proof elided -/
end Withdrawal
variable [Finite Kβ] [LinearOrder Kβ]
[Finite Kβ] [LinearOrder Kβ]
[PreWithZero V]
{b : Block Kβ Kβ C Sigma V}
{bs : List (Block Kβ Kβ C Sigma V)}
{Οβ Οβ : BalanceProof Kβ Kβ C Pi V}
def TransactionsInBlock (Ο : BalanceProof Kβ Kβ C Pi V) (b : Block Kβ Kβ C Sigma V) : List (Ξ€ Kβ Kβ V) :=
match h : b with
| .deposit .. => TransactionsInBlock_deposit βͺb
| .transfer .. => TransactionsInBlock_transfer Ο βͺb
| .withdrawal .. => TransactionsInBlock_withdrawal βͺb
end Extraction
section e
def e (i : Kbar Kβ Kβ) : Kbar Kβ Kβ β β€ := Ξ» j β¦ if i = j then 1 else 0
variable {i j : Kbar Kβ Kβ}
end e
section WithStructuredTypes
section v'
variable [Zero V] [Lattice V] -- NB `PreWithZero V` is implied as `CompleteLattice V` gives `Preorder V`.
def v' (v : Vβ) (b : S Kβ Kβ V) (s : Kbar Kβ Kβ) : Vβ :=
match h : s with
| .Source => v
| .key _ => β¨v β b s, by admit /- proof elided -/
β©
variable {v : Vβ} {b : S Kβ Kβ V} {s : Kbar Kβ Kβ}
end v'
section Fc
variable [Lattice V]
[AddCommGroup V]
[CovariantClass V V (Β· + Β·) (Β· β€ Β·)]
[CovariantClass V V (Function.swap (Β· + Β·)) (Β· β€ Β·)]
def fc (ΟcXb : Ξ€c Kβ Kβ V Γ S Kβ Kβ V) : S Kβ Kβ V :=
β¨Ξ» k : Kbar Kβ Kβ β¦
match ΟcXb with
| β¨β¨β¨β¨s, r, vβ©, _β©, hΟβ©, bβ© =>
let v' := v' (v.get hΟ) b s
b k + (e r - e s) k β’ v',
by admit /- proof elided -/
β©
variable {Οc : Ξ€c Kβ Kβ V} {b : S Kβ Kβ V}
end Fc
section Order
variable [Lattice V] [AddCommGroup V]
end Order
section BoundedBelow
variable [Lattice V] [AddCommGroup V]
abbrev boundedBelow (b : S Kβ Kβ V) (T : Ξ€ Kβ Kβ V) :=
{ a : Ξ€c Kβ Kβ V Γ S Kβ Kβ V | (T, b) β€ (βa.1, a.2) }
end BoundedBelow
section LGroup
variable [Lattice V] [AddCommGroup V]
[CovariantClass V V (Β· + Β·) (Β· β€ Β·)]
[CovariantClass V V (Function.swap (Β· + Β·)) (Β· β€ Β·)]
def V' (b : S Kβ Kβ V) (T : Ξ€ Kβ Kβ V) (k : Kbar Kβ Kβ) : Set V :=
{ v : V | v β (fc Β· k) '' boundedBelow b T }
section f
def f' (b : S Kβ Kβ V) (T : Ξ€ Kβ Kβ V) : S Kβ Kβ V :=
β¨
Ξ» k β¦
match h : T with
| β¨(_, _, .some _), hTβ© => fc (β¨T, by admit /- proof elided -/
β©, b) k
| β¨(s, _, .none), _β© => if k = s then 0 else b k,
by admit /- proof elided -/
β©
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) } :=
β¨
f' b T,
Ξ» k β¦
have f'_codomain : (f' b T) k β V' b T k := by admit /- proof elided -/
β©
def infV (b : S Kβ Kβ V) (T : Ξ€ Kβ Kβ V) (k : Kbar Kβ Kβ) :
InfSet V where
sInf := Ξ» s β¦ if s = V' b T k
then (exists_inf b T).1 k
else 0
def f (b : S Kβ Kβ V) (T : Ξ€ Kβ Kβ V) : S Kβ Kβ V :=
β¨
Ξ» k β¦
have : InfSet V := infV b T k
β¨
x : boundedBelow b T, fc x.1 k,
by admit /- proof elided -/
β©
end f
section fStar
variable {s : S Kβ Kβ V}
end fStar
variable [Finite Kβ] [LinearOrder Kβ]
[Finite Kβ] [LinearOrder Kβ]
section LocalProperties
variable {Ο : S Kβ Kβ V}
{Ο : BalanceProof Kβ Kβ C Pi V}
{T : Ξ€ Kβ Kβ V}
{b : Block Kβ Kβ C Sigma V}
{Sigma : Type} | lemma f_withdrawal_block_source (h : b.isWithdrawalBlock) :
((TransactionsInBlock Ο b).foldl f Ο) .Source = Ο .Source + β k : Kβ, (b.getWithdrawal h k).1 β Ο k := | := by
simp only [TransactionsInBlock]
split <;> [simp at h; simp at h; skip]
next B =>
simp only [f_eq_f', TransactionsInBlock_withdrawal, List.pure_def, List.bind_eq_flatMap,
exists_eq, Set.setOf_true, Set.toFinset_univ, Finset.mem_sort, Finset.mem_univ, forall_const,
List.flatMap_subtype, List.unattach_attach, List.flatMap_singleton', Block.getWithdrawal]
have : (Block.withdrawal B).getWithdrawal h = B := by ext k; simp [Block.getWithdrawal]
simp_rw [βthis]
rw [f_withdrawal_block_source_aux (by simp)]
simp [Finset.mem_sort] | 6 | 105 | false | Applied verif. |
214 | Intmax.monotone_f | lemma monotone_f (hβ : bβ β€ bβ) (hβ : Tβ β€ Tβ) : f bβ Tβ k β€ f bβ Tβ k | FVIntmax | FVIntmax/Lemma4.lean | [
"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": "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": "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": "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": "abbrev",
"content": "class abbrev PreWithZero (Ξ± : Type) := Preorder Ξ±, Zero Ξ±"
},
{
"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": "postfix:max \"β\" => NonNeg",
"content": "postfix:max \"β\" => NonNeg"
}
] | [
{
"name": "le_isGLB_iff",
"module": "Mathlib.Order.Bounds.Basic"
},
{
"name": "mem_lowerBounds",
"module": "Mathlib.Order.Bounds.Basic"
}
] | [
{
"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)"
}
] | [] | [] | 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
open Lean.Elab.Tactic in
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)}
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} | lemma monotone_f (hβ : bβ β€ bβ) (hβ : Tβ β€ Tβ) : f bβ Tβ k β€ f bβ Tβ k := | := by
obtain β¨infβ, -β© := f_IsGLB_of_V' (b := bβ) (T := Tβ) (k := k)
have infβ := f_IsGLB_of_V' (b := bβ) (T := Tβ) (k := k)
have := V'_sset_V'_of_le (k := k) hβ hβ
rw [le_isGLB_iff infβ, mem_lowerBounds]
aesop | 8 | 36 | false | Applied verif. |
215 | Intmax.proposition6 | lemma proposition6 [Setoid' Y] {Dβ Dβ : Dict X Y} :
(β join, IsLUB {Dβ, Dβ} join) β β x, Dβ x β .none β§ Dβ x β .none β Dβ x β
Dβ x | FVIntmax | FVIntmax/Propositions.lean | [
"import Mathlib.Order.Bounds.Basic",
"import FVIntmax.Wheels.Dictionary",
"import Aesop",
"import Mathlib.Order.Bounds.Defs",
"import Mathlib.Order.Defs"
] | [
{
"name": "Preorder",
"module": "Mathlib.Order.Defs.PartialOrder"
},
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "IsLUB",
"module": "Mathlib.Order.Bounds.Defs"
},
{
"name": "IsLeast",
"module": "Mathlib.Order.Bounds.Defs"
},
{
"name": "Prod",
"module": "Init.Prelude"
},
{
"name": "lowerBounds",
"module": "Mathlib.Order.Bounds.Defs"
},
{
"name": "Iff",
"module": "Init.Core"
},
{
"name": "upperBounds",
"module": "Mathlib.Order.Bounds.Defs"
},
{
"name": "Set",
"module": "Mathlib.Data.Set.Defs"
},
{
"name": "Set.Ici",
"module": "Mathlib.Order.Interval.Set.Defs"
},
{
"name": "Function.eval",
"module": "Mathlib.Logic.Function.Basic"
},
{
"name": "Set.image",
"module": "Mathlib.Data.Set.Defs"
}
] | [
{
"name": "notation:51 (priority := high) a:52 \" β
\" b:52 => iso a b",
"content": "notation:51 (priority := high) a:52 \" β
\" b:52 => iso a b"
},
{
"name": "Merge",
"content": "def Merge (Dβ Dβ : Dict Ξ± Ο) : Dict Ξ± Ο := D\n where D := Ξ» x β¦ First (Dβ x) (Dβ x)"
},
{
"name": "First",
"content": "def First (xβ xβ : Option Ξ±) : Option Ξ± :=\n match xβ, xβ with\n | .some x, .none => .some x\n | .some x, .some _ => .some x\n | .none, .some y => .some y\n | .none, .none => .none"
},
{
"name": "Dict",
"content": "abbrev Dict (Ξ± Ο : Type) : Type := Ξ± β Option Ο"
},
{
"name": "notation:65 Οβ:65 \" <+> \" Οβ:66 => Dict.Merge Οβ Οβ",
"content": "notation:65 Οβ:65 \" <+> \" Οβ:66 => Dict.Merge Οβ Οβ"
}
] | [
{
"name": "le_trans",
"module": "Mathlib.Order.Defs.PartialOrder"
},
{
"name": "mem_upperBounds",
"module": "Mathlib.Order.Bounds.Basic"
},
{
"name": "isLUB_pi",
"module": "Mathlib.Order.Bounds.Image"
}
] | [
{
"name": "mem_iff_isSome",
"content": "lemma mem_iff_isSome {m : Dict Ξ± Ο} {x : Ξ±} : x β m β (m x).isSome"
}
] | [
{
"name": "Intmax.iso",
"content": "def iso {X : Type} [Preorder X] (a b : X) := a β€ b β§ b β€ a"
},
{
"name": "Intmax.IsEquivRel",
"content": "def IsEquivRel {X : Type} [Preorder X] := β a b : X, a β€ b β a β
b"
},
{
"name": "Intmax.Setoid'",
"content": "class Setoid' (X : Type) extends Preorder X where\n isEquiv : IsEquivRel (X := X)"
}
] | [
{
"name": "Intmax.iso_rfl",
"content": "@[simp, refl]\nlemma iso_rfl : a β
a"
},
{
"name": "Intmax.iso_trans",
"content": "@[trans]\nlemma iso_trans : (a β
b) β (b β
c) β a β
c"
},
{
"name": "Intmax.proposition2",
"content": "lemma proposition2 [Setoid' X] {x y : X} :\n (β join : X, IsLUB {x, y} join) β x β
y"
},
{
"name": "Intmax.proposition2'",
"content": "lemma proposition2' [Setoid' X] {join x y : X} (h : IsLUB {x, y} join) :\n (x β
join) β§ y β
join"
},
{
"name": "Intmax.proposition3'",
"content": "lemma proposition3' : \n (β join : X, IsLUB {x, y} join) β (β join : Option X, IsLUB {.some x, .some y, .none} join)"
},
{
"name": "Intmax.proposition4",
"content": "lemma proposition4 [Setoid' X] {x y : Option X} :\n (β join : Option X, IsLUB {x, y, .none} join) β (x β .none β§ y β .none β x β
y)"
},
{
"name": "Intmax.proposition5",
"content": "lemma proposition5 [Preorder Y] {f g : X β Y} {join : X β Y} :\n IsLUB {f, g} join β β x : X, IsLUB {f x, g x} (join x)"
},
{
"name": "Intmax.proposition6_aux",
"content": "lemma proposition6_aux [Setoid' Y] {Dβ Dβ : Dict X Y}\n (h : β k, Dβ k β .none β§ Dβ k β .none β Dβ k β
Dβ k) : IsLUB {Dβ, Dβ} (Dict.Merge Dβ Dβ)"
}
] | import Mathlib.Order.Bounds.Basic
import Mathlib.Order.Bounds.Defs
import Mathlib.Order.Defs
import Aesop
import FVIntmax.Wheels.Dictionary
namespace Intmax
def iso {X : Type} [Preorder X] (a b : X) := a β€ b β§ b β€ a
notation:51 (priority := high) a:52 " β
" b:52 => iso a b
section iso
variable {X : Type} [Preorder X]
{a b c : X}
end iso
def IsEquivRel {X : Type} [Preorder X] := β a b : X, a β€ b β a β
b
class Setoid' (X : Type) extends Preorder X where
isEquiv : IsEquivRel (X := X)
section Automation
variable {Ξ± : Type} [Preorder Ξ±]
{x y : Ξ±}
end Automation
section Propositions
variable {X Y : Type}
section proposition3
variable [Preorder X]
{x? y? join? join'? : Option X}
{x y join join' : X}
end proposition3
section Automation
variable {X : Type} [Setoid' X]
{x y : X}
{x? y? : Option X}
end Automation | lemma proposition6 [Setoid' Y] {Dβ Dβ : Dict X Y} :
(β join, IsLUB {Dβ, Dβ} join) β β x, Dβ x β .none β§ Dβ x β .none β Dβ x β
Dβ x := | := by
refine' β¨Ξ» h β¦ _, Ξ» h β¦ _β©
simp_rw [proposition5] at h
simp_rw [βproposition4]
aesop
use Dβ.Merge Dβ
exact proposition6_aux h | 4 | 30 | false | Applied verif. |
216 | Intmax.proposition6' | lemma proposition6' [Setoid' Y] {Dβ Dβ join : Dict X Y} (h : IsLUB {Dβ, Dβ} join) :
join β
Dict.Merge Dβ Dβ | FVIntmax | FVIntmax/Propositions.lean | [
"import Mathlib.Order.Bounds.Basic",
"import FVIntmax.Wheels.Dictionary",
"import Aesop",
"import Mathlib.Order.Bounds.Defs",
"import Mathlib.Order.Defs"
] | [
{
"name": "Preorder",
"module": "Mathlib.Order.Defs.PartialOrder"
},
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "IsLUB",
"module": "Mathlib.Order.Bounds.Defs"
},
{
"name": "Function.eval",
"module": "Mathlib.Logic.Function.Basic"
},
{
"name": "Set",
"module": "Mathlib.Data.Set.Defs"
},
{
"name": "Set.image",
"module": "Mathlib.Data.Set.Defs"
},
{
"name": "Iff",
"module": "Init.Core"
},
{
"name": "IsLeast",
"module": "Mathlib.Order.Bounds.Defs"
},
{
"name": "lowerBounds",
"module": "Mathlib.Order.Bounds.Defs"
},
{
"name": "upperBounds",
"module": "Mathlib.Order.Bounds.Defs"
},
{
"name": "Set.Ici",
"module": "Mathlib.Order.Interval.Set.Defs"
}
] | [
{
"name": "notation:51 (priority := high) a:52 \" β
\" b:52 => iso a b",
"content": "notation:51 (priority := high) a:52 \" β
\" b:52 => iso a b"
},
{
"name": "Merge",
"content": "def Merge (Dβ Dβ : Dict Ξ± Ο) : Dict Ξ± Ο := D\n where D := Ξ» x β¦ First (Dβ x) (Dβ x)"
},
{
"name": "First",
"content": "def First (xβ xβ : Option Ξ±) : Option Ξ± :=\n match xβ, xβ with\n | .some x, .none => .some x\n | .some x, .some _ => .some x\n | .none, .some y => .some y\n | .none, .none => .none"
},
{
"name": "Dict",
"content": "abbrev Dict (Ξ± Ο : Type) : Type := Ξ± β Option Ο"
},
{
"name": "notation:65 Οβ:65 \" <+> \" Οβ:66 => Dict.Merge Οβ Οβ",
"content": "notation:65 Οβ:65 \" <+> \" Οβ:66 => Dict.Merge Οβ Οβ"
}
] | [
{
"name": "isLUB_pi",
"module": "Mathlib.Order.Bounds.Image"
},
{
"name": "le_trans",
"module": "Mathlib.Order.Defs.PartialOrder"
},
{
"name": "mem_upperBounds",
"module": "Mathlib.Order.Bounds.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": "Intmax.iso",
"content": "def iso {X : Type} [Preorder X] (a b : X) := a β€ b β§ b β€ a"
},
{
"name": "Intmax.IsEquivRel",
"content": "def IsEquivRel {X : Type} [Preorder X] := β a b : X, a β€ b β a β
b"
},
{
"name": "Intmax.Setoid'",
"content": "class Setoid' (X : Type) extends Preorder X where\n isEquiv : IsEquivRel (X := X)"
}
] | [
{
"name": "Intmax.iso_rfl",
"content": "@[simp, refl]\nlemma iso_rfl : a β
a"
},
{
"name": "Intmax.iso_symm",
"content": "@[symm]\nlemma iso_symm : (a β
b) β b β
a"
},
{
"name": "Intmax.iso_trans",
"content": "@[trans]\nlemma iso_trans : (a β
b) β (b β
c) β a β
c"
},
{
"name": "Intmax.proposition2",
"content": "lemma proposition2 [Setoid' X] {x y : X} :\n (β join : X, IsLUB {x, y} join) β x β
y"
},
{
"name": "Intmax.proposition2'",
"content": "lemma proposition2' [Setoid' X] {join x y : X} (h : IsLUB {x, y} join) :\n (x β
join) β§ y β
join"
},
{
"name": "Intmax.proposition3'",
"content": "lemma proposition3' : \n (β join : X, IsLUB {x, y} join) β (β join : Option X, IsLUB {.some x, .some y, .none} join)"
},
{
"name": "Intmax.proposition4",
"content": "lemma proposition4 [Setoid' X] {x y : Option X} :\n (β join : Option X, IsLUB {x, y, .none} join) β (x β .none β§ y β .none β x β
y)"
},
{
"name": "Intmax.proposition4'",
"content": "lemma proposition4' [Setoid' X] {join x y : Option X} (h : IsLUB {x, y, .none} join) :\n join β
Dict.First x y"
},
{
"name": "Intmax.proposition5",
"content": "lemma proposition5 [Preorder Y] {f g : X β Y} {join : X β Y} :\n IsLUB {f, g} join β β x : X, IsLUB {f x, g x} (join x)"
},
{
"name": "Intmax.proposition5'",
"content": "lemma proposition5' [Preorder Y] {f g h join' : X β Y}\n (hβ : IsLUB {f, g} join')\n (hβ : β x, h x β
join' x) :\n join' β
h"
}
] | import Mathlib.Order.Bounds.Basic
import Mathlib.Order.Bounds.Defs
import Mathlib.Order.Defs
import Aesop
import FVIntmax.Wheels.Dictionary
namespace Intmax
def iso {X : Type} [Preorder X] (a b : X) := a β€ b β§ b β€ a
notation:51 (priority := high) a:52 " β
" b:52 => iso a b
section iso
variable {X : Type} [Preorder X]
{a b c : X}
end iso
def IsEquivRel {X : Type} [Preorder X] := β a b : X, a β€ b β a β
b
class Setoid' (X : Type) extends Preorder X where
isEquiv : IsEquivRel (X := X)
section Automation
variable {Ξ± : Type} [Preorder Ξ±]
{x y : Ξ±}
end Automation
section Propositions
variable {X Y : Type}
section proposition3
variable [Preorder X]
{x? y? join? join'? : Option X}
{x y join join' : X}
end proposition3
section Automation
variable {X : Type} [Setoid' X]
{x y : X}
{x? y? : Option X}
end Automation | lemma proposition6' [Setoid' Y] {Dβ Dβ join : Dict X Y} (h : IsLUB {Dβ, Dβ} join) :
join β
Dict.Merge Dβ Dβ := | := by
unfold Dict.Merge Dict.Merge.D
apply proposition5' (hβ := h)
intros x
rw [iso_symm]
apply proposition4'
revert x
rw [proposition5] at h
simpa | 5 | 30 | false | Applied verif. |
217 | Intmax.computeBalance'_eq_zero | lemma computeBalance'_eq_zero : computeBalance' Ο v = v + computeBalance' Ο 0 | FVIntmax | FVIntmax/AttackGame.lean | [
"import FVIntmax.Wheels.AuthenticatedDictionary",
"import FVIntmax.Request",
"import FVIntmax.Block",
"import FVIntmax.Wheels.SignatureAggregation",
"import FVIntmax.BalanceProof",
"import FVIntmax.Wheels"
] | [
{
"name": "Sigma",
"module": "Init.Core"
},
{
"name": "Preorder",
"module": "Mathlib.Order.Defs.PartialOrder"
},
{
"name": "Zero",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
}
] | [
{
"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": "Scontract",
"content": "abbrev Scontract (Kβ Kβ V : Type) [PreWithZero V] (C Sigma : Type) :=\n List (Block Kβ Kβ C Sigma V)"
},
{
"name": "ExtraDataT",
"content": "abbrev ExtraDataT : Type := β"
},
{
"name": "abbrev",
"content": "class abbrev PreWithZero (Ξ± : Type) := Preorder Ξ±, Zero Ξ±"
},
{
"name": "NonNeg",
"content": "def NonNeg (Ξ± : Type) [PreWithZero Ξ±] := { a : Ξ± // 0 β€ a }"
},
{
"name": "postfix:max \"β\" => NonNeg",
"content": "postfix:max \"β\" => NonNeg"
}
] | [
{
"name": "sub_eq_add_neg",
"module": "Mathlib.Algebra.Group.Defs"
},
{
"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": "Intmax.Block.updateBalance",
"content": "def Block.updateBalance (bal : V) (block : Block Kβ Kβ C Sigma V) : V :=\n match block with\n \n | .deposit _ v => bal + v\n \n | .transfer .. => bal\n \n | .withdrawal B => bal - β k : Kβ, (B k).1"
},
{
"name": "Intmax.computeBalance'",
"content": "def computeBalance' (blocks : Scontract Kβ Kβ V C Sigma) (acc : V) : V :=\n blocks.foldl Block.updateBalance acc"
}
] | [
{
"name": "Intmax.Block.updateBalance_eq_zero",
"content": "lemma Block.updateBalance_eq_zero :\n block.updateBalance v = v + block.updateBalance 0"
},
{
"name": "Intmax.computeBalance'_cons",
"content": "@[simp]\nlemma computeBalance'_cons : computeBalance' (hd :: Ο) v =\n computeBalance' Ο (Block.updateBalance v hd)"
}
] | import FVIntmax.Wheels.AuthenticatedDictionary
import FVIntmax.Wheels.SignatureAggregation
import FVIntmax.BalanceProof
import FVIntmax.Block
import FVIntmax.Request
import FVIntmax.Wheels
namespace Intmax
noncomputable section Intmax
section RollupContract
open Classical
section
variable {C : Type} [Nonempty C]
{V : Type} [Lattice V] [AddCommGroup V]
{Kβ : Type} [Finite Kβ] [Nonempty Kβ]
{Kβ : Type} [Finite Kβ]
{Sigma : Type}
[ADScheme Kβ (C Γ Kβ Γ ExtraDataT) C Pi]
[SA : SignatureAggregation (C Γ Kβ Γ ExtraDataT) Kβ KβT Sigma]
def Block.updateBalance (bal : V) (block : Block Kβ Kβ C Sigma V) : V :=
match block with
| .deposit _ v => bal + v
| .transfer .. => bal
| .withdrawal B => bal - β k : Kβ, (B k).1
end
section
variable {C : Type}
{V : Type} [Lattice V] [AddCommGroup V]
{Kβ : Type} [Finite Kβ]
{Kβ : Type}
{Sigma : Type}
{block : Block Kβ Kβ C Sigma V}
{v : V}
section Lemmas
end Lemmas
namespace Scontract
section
variable [LinearOrder Kβ] [Nonempty Kβ]
[LinearOrder Kβ] [Finite Kβ]
[Nonempty C]
[CovariantClass V V (Β· + Β·) (Β· β€ Β·)]
[CovariantClass V V (Function.swap (Β· + Β·)) (Β· β€ Β·)]
[ADScheme Kβ (C Γ Kβ Γ ExtraDataT) C Pi]
[SignatureAggregation (C Γ Kβ Γ ExtraDataT) Kβ KβT Sigma]
section appendBlock
variable {Ο : Scontract Kβ Kβ V C Sigma} {request : Request Kβ Kβ C Sigma Pi V}
end appendBlock
end
section
variable [LinearOrder Kβ]
[Finite Kβ] [LinearOrder Kβ]
{Ο : Scontract Kβ Kβ V C Sigma}
{request : Request Kβ Kβ C Sigma Pi V}
[CovariantClass V V (Β· + Β·) (Β· β€ Β·)]
[CovariantClass V V (Function.swap (Β· + Β·)) (Β· β€ Β·)]
end
end Scontract
end
end RollupContract
section AttackGameDefs
variable {Kβ : Type} [Finite Kβ] [LinearOrder Kβ] [Nonempty Kβ]
{Kβ : Type} [Finite Kβ] [LinearOrder Kβ]
{V : Type} [Lattice V] [AddCommGroup V]
[CovariantClass V V (Β· + Β·) (Β· β€ Β·)]
[CovariantClass V V (Function.swap (Β· + Β·)) (Β· β€ Β·)]
{Sigma : Type}
{C : Type} [Nonempty C]
[ADScheme Kβ (C Γ Kβ Γ ExtraDataT) C Pi]
[SignatureAggregation (C Γ Kβ Γ ExtraDataT) Kβ KβT Sigma]
(requests : List (Request Kβ Kβ C Sigma Pi V))
(Ο : Scontract Kβ Kβ V C Sigma)
def computeBalance' (blocks : Scontract Kβ Kβ V C Sigma) (acc : V) : V :=
blocks.foldl Block.updateBalance acc
end AttackGameDefs
section AttackGameLemmas
variable {Kβ Kβ Sigma C : Type}
{V : Type} [Lattice V] [AddCommGroup V]
[CovariantClass V V (Β· + Β·) (Β· β€ Β·)]
[ADScheme Kβ (C Γ Kβ Γ ExtraDataT) C Pi]
section computeBalanceSum
variable {k : β}
end computeBalanceSum
variable [Finite Kβ]
end AttackGameLemmas
section ComputeLemmas
variable {Kβ : Type} [Finite Kβ] {Kβ Sigma C : Type}
{V : Type} [Lattice V] [AddCommGroup V]
{Ο : Scontract Kβ Kβ V C Sigma}
[ADScheme Kβ (C Γ Kβ Γ ExtraDataT) C Pi] | lemma computeBalance'_eq_zero : computeBalance' Ο v = v + computeBalance' Ο 0 := | := by
induction' Ο with hd tl ih generalizing v
Β· simp
Β· rw [computeBalance'_cons, computeBalance'_cons, ih, Block.updateBalance_eq_zero]
nth_rw 2 [ih]
exact add_assoc v _ _ | 3 | 15 | false | Applied verif. |
218 | evalFuel_sound | theorem evalFuel_sound : evalFuel n c = some v β c β€³β v | IntroEffects | IntroEffects/Eval.lean | [
"import IntroEffects.SmallStep"
] | [
{
"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.Prelude"
},
{
"name": "Int",
"module": "Init.Data.Int.Basic"
},
{
"name": "String",
"module": "Init.Prelude"
},
{
"name": "bool",
"module": "Init.Control.Basic"
},
{
"name": "ite",
"module": "Init.Prelude"
},
{
"name": "Nat",
"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": "scoped syntax num : embedded",
"content": "scoped syntax num : embedded"
},
{
"name": "instantiateComp",
"content": "def instantiateComp (what : Value) (comp : Computation) : Computation :=\n instantiateComputationLvl what 0 comp"
},
{
"name": "instantiateComputationLvl",
"content": "def instantiateComputationLvl (what : Value) (level : Nat) : Computation β Computation\n| .ret v => .ret <| instantiateValueLvl what level v\n| .opCall op v c => .opCall op (instantiateValueLvl what level v) (instantiateComputationLvl what (level+1) c)\n| .bind cβ cβ => .bind (instantiateComputationLvl what level cβ) (instantiateComputationLvl what (level+1) cβ)\n| .ite v cβ cβ => .ite (instantiateValueLvl what level v) (instantiateComputationLvl what level cβ) (instantiateComputationLvl what level cβ)\n| .app vβ vβ => .app (instantiateValueLvl what level vβ) (instantiateValueLvl what level vβ)\n| .handle v c => .handle (instantiateValueLvl what level v) (instantiateComputationLvl what level c)\n| .join vβ vβ => .join (instantiateValueLvl what level vβ) (instantiateValueLvl what level vβ)\n| .fst v => .fst (instantiateValueLvl what level v)\n| .snd v => .snd (instantiateValueLvl what level v)\n| .add vβ vβ => .add (instantiateValueLvl what level vβ) (instantiateValueLvl what level vβ)\n| .sub vβ vβ => .sub (instantiateValueLvl what level vβ) (instantiateValueLvl what level vβ)\n| .max vβ vβ => .max (instantiateValueLvl what level vβ) (instantiateValueLvl what level vβ)\n| .lt vβ vβ => .lt (instantiateValueLvl what level vβ) (instantiateValueLvl what level vβ)\n| .mul vβ vβ => .mul (instantiateValueLvl what level vβ) (instantiateValueLvl what level vβ)\n| .eq vβ vβ => .eq (instantiateValueLvl what level vβ) (instantiateValueLvl what level vβ)\ntermination_by c => sizeOf c\ndecreasing_by\n all_goals simp\n all_goals grind"
},
{
"name": "instantiateValueLvl",
"content": "def instantiateValueLvl (what : Value) (level : Nat) : Value β Value\n| var@(.var (.bvar bvarLevel)) => if bvarLevel = level then what else var\n| .lam c => .lam <| instantiateComputationLvl what (level + 1) c\n| .hdl h => .hdl <| instantiateHandlerLvl what level h\n| .pair vβ vβ => .pair (instantiateValueLvl what level vβ) (instantiateValueLvl what level vβ)\n| .recfun c => .recfun <| instantiateComputationLvl what (level + 2) c\n| .string s => .string s\n| .bool b => .bool b\n| .unit => .unit\n| .var v => .var v\n| .num n => .num n\ntermination_by v => sizeOf v\ndecreasing_by\n all_goals simp\n all_goals grind"
},
{
"name": "instantiateHandlerLvl",
"content": "def instantiateHandlerLvl (what : Value) (level : Nat) : Handler β Handler\n| β¨ret, ops'β© =>\n β¨instantiateComputationLvl what (level+1) ret, instantiateOps what level ops'β©\ntermination_by h => sizeOf h\ndecreasing_by\n all_goals simp\n all_goals grind"
},
{
"name": "instantiateOps",
"content": "def instantiateOps (what : Value) (level : Nat) : List OpClause β List OpClause\n| [] => []\n| β¨op, bodyβ© :: ls =>\n β¨op, instantiateComputationLvl what (level+2) bodyβ© :: instantiateOps what level ls\ntermination_by l => sizeOf l"
},
{
"name": "OpClause",
"content": "structure OpClause where\n op : Name\n \n body : Computation\nderiving Repr, BEq"
},
{
"name": "Computation",
"content": "inductive Computation where\n| ret : Value β Computation\n \n| opCall : Name β Value β Computation β Computation\n \n| bind : Computation β Computation β Computation\n| ite (val : Value) (trueBranch falseBranch : Computation)\n| app : Value β Value β Computation\n \n| handle : Value β Computation β Computation\n| join : Value β Value β Computation\n| fst : Value β Computation\n| snd : Value β Computation\n| add : Value β Value β Computation\n| sub : Value β Value β Computation\n| mul : Value β Value β Computation\n| max : Value β Value β Computation\n| lt : Value β Value β Computation\n| eq : Value β Value β Computation\nderiving BEq"
},
{
"name": "Value",
"content": "inductive Value where\n| var : Var β Value\n| bool : Bool β Value\n| string : String β Value\n| num : Int β Value\n| unit : Value\n| pair : Value β Value β Value\n \n| lam : Computation β Value\n \n| recfun : Computation β Value\n| hdl : Handler β Value\nderiving BEq"
},
{
"name": "Handler",
"content": "structure Handler where\n \n ret : Computation\n ops : List OpClause\nderiving Repr, BEq"
},
{
"name": "Var",
"content": "inductive Var where\n| fvar : Name β Var\n| bvar : Nat β Var\nderiving Repr, DecidableEq"
},
{
"name": "Name",
"content": "abbrev Name := String"
},
{
"name": "Step",
"content": "@[grind cases]\ninductive Step : Computation β Computation β Prop\n \n| beta v body : Step (.app (.lam body) v) (instantiateComp v body)\n \n| recBeta v body : Step (.app (.recfun body) v) (instantiate2 (.recfun body) v body)\n \n| iteTrue cβ cβ : Step (.ite (.bool true) cβ cβ) cβ\n \n| iteFalse cβ cβ : Step (.ite (.bool false) cβ cβ) cβ\n \n| bindStep cβ cβ' cβ (h : Step cβ cβ') : Step (.bind cβ cβ) (.bind cβ' cβ)\n \n| bindReturn v c : Step (.bind (.ret v) c) (instantiateComp v c)\n \n| bindOp op v body c : Step (.bind (.opCall op v body) c) (.opCall op v (.bind body c))\n \n| handleInner h cβ cβ (hβ : Step cβ cβ) : Step (.handle (.hdl h) cβ) (.handle (.hdl h) cβ)\n \n| handleReturn h v :\n Step (.handle (.hdl h) (.ret v)) (instantiateComp v h.ret)\n \n| handleOpHit h op v body c (hop : h.lookup op = some β¨op, cβ©) :\n Step (.handle (.hdl h) (.opCall op v body))\n (instantiate2 v (.lam (.handle (.hdl h) body)) c)\n \n| handleOpMiss h op v body (hop : h.lookup op = none) :\n Step (.handle (.hdl h) (.opCall op v body)) (.opCall op v (.handle (.hdl h) body))\n \n| join sβ sβ : Step (.join (.string sβ) (.string sβ)) (.ret (.string (strAppend sβ sβ)))\n \n| fstStep vβ vβ : Step (.fst (.pair vβ vβ)) (.ret vβ)\n \n| sndStep vβ vβ : Step (.snd (.pair vβ vβ)) (.ret vβ)\n| add vβ vβ : Step (.add (.num vβ) (.num vβ)) (.ret (.num (vβ + vβ)))\n| sub vβ vβ : Step (.sub (.num vβ) (.num vβ)) (.ret (.num (vβ - vβ)))\n| max vβ vβ : Step (.max (.num vβ) (.num vβ)) (.ret (.num (Max.max vβ vβ)))\n| lt vβ vβ : Step (.lt (.num vβ) (.num vβ)) (.ret (.bool (vβ < vβ)))\n| mul vβ vβ : Step (.mul (.num vβ) (.num vβ)) (.ret (.num (vβ * vβ)))\n| eq vβ vβ : Step (.eq vβ vβ) (.ret (.bool (vβ == vβ)))"
},
{
"name": "instantiate2",
"content": "def instantiate2 (arg cont : Value) (body : Computation) : Computation :=\n instantiateComputationLvl arg 1 (instantiateComputationLvl cont 0 body)"
},
{
"name": "strAppend",
"content": "def strAppend : String β String β String\n| \"\", s => s\n| s, \"\" => s\n| sβ, sβ => sβ ++ \" \" ++ sβ"
},
{
"name": "StepStar",
"content": "@[grind cases]\ninductive StepStar : Computation β Computation β Prop\n| refl (c) : StepStar c c\n| trans : Step cβ cβ β StepStar cβ cβ β StepStar cβ cβ"
},
{
"name": "Handler.lookup",
"content": "def Handler.lookup (hdl : Handler) (name : Name) :=\n hdl.ops.find? (Β·.op == name)"
},
{
"name": "infix:50 \" β€³ \" => Step",
"content": "infix:50 \" β€³ \" => Step"
},
{
"name": "infix:50 \" β€³β \" => StepStar",
"content": "infix:50 \" β€³β \" => StepStar"
}
] | [
{
"name": "List.find?_some",
"module": "Init.Data.List.Find"
}
] | [
{
"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": "evalSingleStep",
"content": "def evalSingleStep : Computation β Option Computation\n \n| .app (.lam body) v => some <| instantiateComp v body\n \n| .app (.recfun body) v => some <| instantiate2 (.recfun body) v body\n| .ite (.bool true) cβ _ => some cβ\n| .ite (.bool false) _ cβ => some cβ\n \n| .bind (.ret v) c => some <| instantiateComp v c\n \n| .bind (.opCall op v body) c => some <| .opCall op v (.bind body c)\n| .bind cβ cβ => (evalSingleStep cβ).map (fun cβ' => .bind cβ' cβ)\n \n| .handle (.hdl h) (.ret v) => some <| instantiateComp v h.ret\n| .handle (.hdl h) (.opCall op v body) =>\n match h.lookup op with\n \n | some β¨_, cβ© =>\n let cont := .lam (.handle (.hdl h) body)\n some <| instantiate2 v cont c\n \n | none => some <| .opCall op v (.handle (.hdl h) body)\n| .handle (.hdl h) c =>\n (evalSingleStep c).map (fun c' => .handle (.hdl h) c')\n| .join (.string sβ) (.string sβ) => some <| .ret (.string (strAppend sβ sβ))\n| .fst (.pair vβ _) => some <| .ret vβ\n| .snd (.pair _ vβ) => some <| .ret vβ\n| .add (.num vβ) (.num vβ) => some <| .ret (.num (vβ + vβ))\n| .sub (.num vβ) (.num vβ) => some <| .ret (.num (vβ - vβ))\n| .max (.num vβ) (.num vβ) => some <| .ret (.num (Max.max vβ vβ))\n| .lt (.num vβ) (.num vβ) => some <| .ret (.bool (vβ < vβ))\n| .mul (.num vβ) (.num vβ) => some <| .ret (.num (vβ * vβ))\n| .eq vβ vβ => some <| .ret (.bool (vβ == vβ))\n| _ => none"
},
{
"name": "evalFuel",
"content": "def evalFuel : Nat β Computation β Option Computation\n| 0, _ => none\n| _+1, .ret v => some <| .ret v\n| _+1, .opCall n v c => some <| .opCall n v c\n| n+1, c =>\n match evalSingleStep c with\n | some c' => evalFuel n c'\n | none => none"
}
] | [
{
"name": "evalSingleStep_sound",
"content": "theorem evalSingleStep_sound {c c' : Computation} :\n evalSingleStep c = some c' β c β€³ c'"
}
] | import IntroEffects.SmallStep
def evalSingleStep : Computation β Option Computation
| .app (.lam body) v => some <| instantiateComp v body
| .app (.recfun body) v => some <| instantiate2 (.recfun body) v body
| .ite (.bool true) cβ _ => some cβ
| .ite (.bool false) _ cβ => some cβ
| .bind (.ret v) c => some <| instantiateComp v c
| .bind (.opCall op v body) c => some <| .opCall op v (.bind body c)
| .bind cβ cβ => (evalSingleStep cβ).map (fun cβ' => .bind cβ' cβ)
| .handle (.hdl h) (.ret v) => some <| instantiateComp v h.ret
| .handle (.hdl h) (.opCall op v body) =>
match h.lookup op with
| some β¨_, cβ© =>
let cont := .lam (.handle (.hdl h) body)
some <| instantiate2 v cont c
| none => some <| .opCall op v (.handle (.hdl h) body)
| .handle (.hdl h) c =>
(evalSingleStep c).map (fun c' => .handle (.hdl h) c')
| .join (.string sβ) (.string sβ) => some <| .ret (.string (strAppend sβ sβ))
| .fst (.pair vβ _) => some <| .ret vβ
| .snd (.pair _ vβ) => some <| .ret vβ
| .add (.num vβ) (.num vβ) => some <| .ret (.num (vβ + vβ))
| .sub (.num vβ) (.num vβ) => some <| .ret (.num (vβ - vβ))
| .max (.num vβ) (.num vβ) => some <| .ret (.num (Max.max vβ vβ))
| .lt (.num vβ) (.num vβ) => some <| .ret (.bool (vβ < vβ))
| .mul (.num vβ) (.num vβ) => some <| .ret (.num (vβ * vβ))
| .eq vβ vβ => some <| .ret (.bool (vβ == vβ))
| _ => none
def evalFuel : Nat β Computation β Option Computation
| 0, _ => none
| _+1, .ret v => some <| .ret v
| _+1, .opCall n v c => some <| .opCall n v c
| n+1, c =>
match evalSingleStep c with
| some c' => evalFuel n c'
| none => none | theorem evalFuel_sound : evalFuel n c = some v β c β€³β v := | := by
induction h : n generalizing c with
| zero => simp [evalFuel]
| succ n ih =>
cases hstep : evalSingleStep c with
| none =>
cases c <;> try grind [evalFuel]
all_goals
( simp [evalFuel]
intro h; rw [βh]; constructor)
| some c' =>
cases c with
| ret | opCall =>
simp [evalFuel]
intro h; rw [βh]; constructor
| _ =>
simp [evalFuel, hstep]
intro h
exact StepStar.trans (evalSingleStep_sound hstep) (evalFuel_sound h) | 8 | 34 | false | Semantics |
219 | evalFuelRet_complete_aux | theorem evalFuelRet_complete_aux (h : c β€³β r) :
βv, r= .ret v β βn, evalFuel n c = some (.ret v) | IntroEffects | IntroEffects/Eval.lean | [
"import IntroEffects.SmallStep"
] | [
{
"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.Prelude"
},
{
"name": "Int",
"module": "Init.Data.Int.Basic"
},
{
"name": "String",
"module": "Init.Prelude"
},
{
"name": "bool",
"module": "Init.Control.Basic"
},
{
"name": "ite",
"module": "Init.Prelude"
},
{
"name": "Nat",
"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": "scoped syntax num : embedded",
"content": "scoped syntax num : embedded"
},
{
"name": "instantiateComp",
"content": "def instantiateComp (what : Value) (comp : Computation) : Computation :=\n instantiateComputationLvl what 0 comp"
},
{
"name": "instantiateComputationLvl",
"content": "def instantiateComputationLvl (what : Value) (level : Nat) : Computation β Computation\n| .ret v => .ret <| instantiateValueLvl what level v\n| .opCall op v c => .opCall op (instantiateValueLvl what level v) (instantiateComputationLvl what (level+1) c)\n| .bind cβ cβ => .bind (instantiateComputationLvl what level cβ) (instantiateComputationLvl what (level+1) cβ)\n| .ite v cβ cβ => .ite (instantiateValueLvl what level v) (instantiateComputationLvl what level cβ) (instantiateComputationLvl what level cβ)\n| .app vβ vβ => .app (instantiateValueLvl what level vβ) (instantiateValueLvl what level vβ)\n| .handle v c => .handle (instantiateValueLvl what level v) (instantiateComputationLvl what level c)\n| .join vβ vβ => .join (instantiateValueLvl what level vβ) (instantiateValueLvl what level vβ)\n| .fst v => .fst (instantiateValueLvl what level v)\n| .snd v => .snd (instantiateValueLvl what level v)\n| .add vβ vβ => .add (instantiateValueLvl what level vβ) (instantiateValueLvl what level vβ)\n| .sub vβ vβ => .sub (instantiateValueLvl what level vβ) (instantiateValueLvl what level vβ)\n| .max vβ vβ => .max (instantiateValueLvl what level vβ) (instantiateValueLvl what level vβ)\n| .lt vβ vβ => .lt (instantiateValueLvl what level vβ) (instantiateValueLvl what level vβ)\n| .mul vβ vβ => .mul (instantiateValueLvl what level vβ) (instantiateValueLvl what level vβ)\n| .eq vβ vβ => .eq (instantiateValueLvl what level vβ) (instantiateValueLvl what level vβ)\ntermination_by c => sizeOf c\ndecreasing_by\n all_goals simp\n all_goals grind"
},
{
"name": "instantiateValueLvl",
"content": "def instantiateValueLvl (what : Value) (level : Nat) : Value β Value\n| var@(.var (.bvar bvarLevel)) => if bvarLevel = level then what else var\n| .lam c => .lam <| instantiateComputationLvl what (level + 1) c\n| .hdl h => .hdl <| instantiateHandlerLvl what level h\n| .pair vβ vβ => .pair (instantiateValueLvl what level vβ) (instantiateValueLvl what level vβ)\n| .recfun c => .recfun <| instantiateComputationLvl what (level + 2) c\n| .string s => .string s\n| .bool b => .bool b\n| .unit => .unit\n| .var v => .var v\n| .num n => .num n\ntermination_by v => sizeOf v\ndecreasing_by\n all_goals simp\n all_goals grind"
},
{
"name": "instantiateHandlerLvl",
"content": "def instantiateHandlerLvl (what : Value) (level : Nat) : Handler β Handler\n| β¨ret, ops'β© =>\n β¨instantiateComputationLvl what (level+1) ret, instantiateOps what level ops'β©\ntermination_by h => sizeOf h\ndecreasing_by\n all_goals simp\n all_goals grind"
},
{
"name": "instantiateOps",
"content": "def instantiateOps (what : Value) (level : Nat) : List OpClause β List OpClause\n| [] => []\n| β¨op, bodyβ© :: ls =>\n β¨op, instantiateComputationLvl what (level+2) bodyβ© :: instantiateOps what level ls\ntermination_by l => sizeOf l"
},
{
"name": "OpClause",
"content": "structure OpClause where\n op : Name\n \n body : Computation\nderiving Repr, BEq"
},
{
"name": "Computation",
"content": "inductive Computation where\n| ret : Value β Computation\n \n| opCall : Name β Value β Computation β Computation\n \n| bind : Computation β Computation β Computation\n| ite (val : Value) (trueBranch falseBranch : Computation)\n| app : Value β Value β Computation\n \n| handle : Value β Computation β Computation\n| join : Value β Value β Computation\n| fst : Value β Computation\n| snd : Value β Computation\n| add : Value β Value β Computation\n| sub : Value β Value β Computation\n| mul : Value β Value β Computation\n| max : Value β Value β Computation\n| lt : Value β Value β Computation\n| eq : Value β Value β Computation\nderiving BEq"
},
{
"name": "Value",
"content": "inductive Value where\n| var : Var β Value\n| bool : Bool β Value\n| string : String β Value\n| num : Int β Value\n| unit : Value\n| pair : Value β Value β Value\n \n| lam : Computation β Value\n \n| recfun : Computation β Value\n| hdl : Handler β Value\nderiving BEq"
},
{
"name": "Handler",
"content": "structure Handler where\n \n ret : Computation\n ops : List OpClause\nderiving Repr, BEq"
},
{
"name": "Var",
"content": "inductive Var where\n| fvar : Name β Var\n| bvar : Nat β Var\nderiving Repr, DecidableEq"
},
{
"name": "Name",
"content": "abbrev Name := String"
},
{
"name": "Step",
"content": "@[grind cases]\ninductive Step : Computation β Computation β Prop\n \n| beta v body : Step (.app (.lam body) v) (instantiateComp v body)\n \n| recBeta v body : Step (.app (.recfun body) v) (instantiate2 (.recfun body) v body)\n \n| iteTrue cβ cβ : Step (.ite (.bool true) cβ cβ) cβ\n \n| iteFalse cβ cβ : Step (.ite (.bool false) cβ cβ) cβ\n \n| bindStep cβ cβ' cβ (h : Step cβ cβ') : Step (.bind cβ cβ) (.bind cβ' cβ)\n \n| bindReturn v c : Step (.bind (.ret v) c) (instantiateComp v c)\n \n| bindOp op v body c : Step (.bind (.opCall op v body) c) (.opCall op v (.bind body c))\n \n| handleInner h cβ cβ (hβ : Step cβ cβ) : Step (.handle (.hdl h) cβ) (.handle (.hdl h) cβ)\n \n| handleReturn h v :\n Step (.handle (.hdl h) (.ret v)) (instantiateComp v h.ret)\n \n| handleOpHit h op v body c (hop : h.lookup op = some β¨op, cβ©) :\n Step (.handle (.hdl h) (.opCall op v body))\n (instantiate2 v (.lam (.handle (.hdl h) body)) c)\n \n| handleOpMiss h op v body (hop : h.lookup op = none) :\n Step (.handle (.hdl h) (.opCall op v body)) (.opCall op v (.handle (.hdl h) body))\n \n| join sβ sβ : Step (.join (.string sβ) (.string sβ)) (.ret (.string (strAppend sβ sβ)))\n \n| fstStep vβ vβ : Step (.fst (.pair vβ vβ)) (.ret vβ)\n \n| sndStep vβ vβ : Step (.snd (.pair vβ vβ)) (.ret vβ)\n| add vβ vβ : Step (.add (.num vβ) (.num vβ)) (.ret (.num (vβ + vβ)))\n| sub vβ vβ : Step (.sub (.num vβ) (.num vβ)) (.ret (.num (vβ - vβ)))\n| max vβ vβ : Step (.max (.num vβ) (.num vβ)) (.ret (.num (Max.max vβ vβ)))\n| lt vβ vβ : Step (.lt (.num vβ) (.num vβ)) (.ret (.bool (vβ < vβ)))\n| mul vβ vβ : Step (.mul (.num vβ) (.num vβ)) (.ret (.num (vβ * vβ)))\n| eq vβ vβ : Step (.eq vβ vβ) (.ret (.bool (vβ == vβ)))"
},
{
"name": "instantiate2",
"content": "def instantiate2 (arg cont : Value) (body : Computation) : Computation :=\n instantiateComputationLvl arg 1 (instantiateComputationLvl cont 0 body)"
},
{
"name": "strAppend",
"content": "def strAppend : String β String β String\n| \"\", s => s\n| s, \"\" => s\n| sβ, sβ => sβ ++ \" \" ++ sβ"
},
{
"name": "StepStar",
"content": "@[grind cases]\ninductive StepStar : Computation β Computation β Prop\n| refl (c) : StepStar c c\n| trans : Step cβ cβ β StepStar cβ cβ β StepStar cβ cβ"
},
{
"name": "infix:50 \" β€³ \" => Step",
"content": "infix:50 \" β€³ \" => Step"
},
{
"name": "infix:50 \" β€³β \" => StepStar",
"content": "infix:50 \" β€³β \" => StepStar"
}
] | [
{
"name": "trans",
"module": "Mathlib.Order.Defs.Unbundled"
}
] | [
{
"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": "evalSingleStep",
"content": "def evalSingleStep : Computation β Option Computation\n \n| .app (.lam body) v => some <| instantiateComp v body\n \n| .app (.recfun body) v => some <| instantiate2 (.recfun body) v body\n| .ite (.bool true) cβ _ => some cβ\n| .ite (.bool false) _ cβ => some cβ\n \n| .bind (.ret v) c => some <| instantiateComp v c\n \n| .bind (.opCall op v body) c => some <| .opCall op v (.bind body c)\n| .bind cβ cβ => (evalSingleStep cβ).map (fun cβ' => .bind cβ' cβ)\n \n| .handle (.hdl h) (.ret v) => some <| instantiateComp v h.ret\n| .handle (.hdl h) (.opCall op v body) =>\n match h.lookup op with\n \n | some β¨_, cβ© =>\n let cont := .lam (.handle (.hdl h) body)\n some <| instantiate2 v cont c\n \n | none => some <| .opCall op v (.handle (.hdl h) body)\n| .handle (.hdl h) c =>\n (evalSingleStep c).map (fun c' => .handle (.hdl h) c')\n| .join (.string sβ) (.string sβ) => some <| .ret (.string (strAppend sβ sβ))\n| .fst (.pair vβ _) => some <| .ret vβ\n| .snd (.pair _ vβ) => some <| .ret vβ\n| .add (.num vβ) (.num vβ) => some <| .ret (.num (vβ + vβ))\n| .sub (.num vβ) (.num vβ) => some <| .ret (.num (vβ - vβ))\n| .max (.num vβ) (.num vβ) => some <| .ret (.num (Max.max vβ vβ))\n| .lt (.num vβ) (.num vβ) => some <| .ret (.bool (vβ < vβ))\n| .mul (.num vβ) (.num vβ) => some <| .ret (.num (vβ * vβ))\n| .eq vβ vβ => some <| .ret (.bool (vβ == vβ))\n| _ => none"
},
{
"name": "evalFuel",
"content": "def evalFuel : Nat β Computation β Option Computation\n| 0, _ => none\n| _+1, .ret v => some <| .ret v\n| _+1, .opCall n v c => some <| .opCall n v c\n| n+1, c =>\n match evalSingleStep c with\n | some c' => evalFuel n c'\n | none => none"
}
] | [
{
"name": "evalSingleStep_complete",
"content": "theorem evalSingleStep_complete {c c' : Computation} :\n c β€³ c' β evalSingleStep c = (some c')"
},
{
"name": "evalFuel_step",
"content": "theorem evalFuel_step (h : c β€³ c') : evalFuel (n + 1) c = evalFuel n c'"
}
] | import IntroEffects.SmallStep
def evalSingleStep : Computation β Option Computation
| .app (.lam body) v => some <| instantiateComp v body
| .app (.recfun body) v => some <| instantiate2 (.recfun body) v body
| .ite (.bool true) cβ _ => some cβ
| .ite (.bool false) _ cβ => some cβ
| .bind (.ret v) c => some <| instantiateComp v c
| .bind (.opCall op v body) c => some <| .opCall op v (.bind body c)
| .bind cβ cβ => (evalSingleStep cβ).map (fun cβ' => .bind cβ' cβ)
| .handle (.hdl h) (.ret v) => some <| instantiateComp v h.ret
| .handle (.hdl h) (.opCall op v body) =>
match h.lookup op with
| some β¨_, cβ© =>
let cont := .lam (.handle (.hdl h) body)
some <| instantiate2 v cont c
| none => some <| .opCall op v (.handle (.hdl h) body)
| .handle (.hdl h) c =>
(evalSingleStep c).map (fun c' => .handle (.hdl h) c')
| .join (.string sβ) (.string sβ) => some <| .ret (.string (strAppend sβ sβ))
| .fst (.pair vβ _) => some <| .ret vβ
| .snd (.pair _ vβ) => some <| .ret vβ
| .add (.num vβ) (.num vβ) => some <| .ret (.num (vβ + vβ))
| .sub (.num vβ) (.num vβ) => some <| .ret (.num (vβ - vβ))
| .max (.num vβ) (.num vβ) => some <| .ret (.num (Max.max vβ vβ))
| .lt (.num vβ) (.num vβ) => some <| .ret (.bool (vβ < vβ))
| .mul (.num vβ) (.num vβ) => some <| .ret (.num (vβ * vβ))
| .eq vβ vβ => some <| .ret (.bool (vβ == vβ))
| _ => none
def evalFuel : Nat β Computation β Option Computation
| 0, _ => none
| _+1, .ret v => some <| .ret v
| _+1, .opCall n v c => some <| .opCall n v c
| n+1, c =>
match evalSingleStep c with
| some c' => evalFuel n c'
| none => none | theorem evalFuelRet_complete_aux (h : c β€³β r) :
βv, r= .ret v β βn, evalFuel n c = some (.ret v) := | := by
induction h with
| refl c' =>
intro v hv
exact β¨1, by grind [evalFuel]β©
| @trans c1 c2 c3 hStep hTail ih =>
intro v hv
obtain β¨n, ihFuelβ© := ih v hv
refine β¨n+1, ?_β©
simp [evalFuel_step hStep, ihFuel] | 8 | 34 | false | Semantics |
220 | evalFuelOpCall_complete_aux | theorem evalFuelOpCall_complete_aux (h : c β€³β r) :
βv, r = .opCall name v comp β βn, evalFuel n c = some (.opCall name v comp) | IntroEffects | IntroEffects/Eval.lean | [
"import IntroEffects.SmallStep"
] | [
{
"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.Prelude"
},
{
"name": "Int",
"module": "Init.Data.Int.Basic"
},
{
"name": "String",
"module": "Init.Prelude"
},
{
"name": "bool",
"module": "Init.Control.Basic"
},
{
"name": "ite",
"module": "Init.Prelude"
},
{
"name": "Nat",
"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": "scoped syntax num : embedded",
"content": "scoped syntax num : embedded"
},
{
"name": "instantiateComp",
"content": "def instantiateComp (what : Value) (comp : Computation) : Computation :=\n instantiateComputationLvl what 0 comp"
},
{
"name": "instantiateComputationLvl",
"content": "def instantiateComputationLvl (what : Value) (level : Nat) : Computation β Computation\n| .ret v => .ret <| instantiateValueLvl what level v\n| .opCall op v c => .opCall op (instantiateValueLvl what level v) (instantiateComputationLvl what (level+1) c)\n| .bind cβ cβ => .bind (instantiateComputationLvl what level cβ) (instantiateComputationLvl what (level+1) cβ)\n| .ite v cβ cβ => .ite (instantiateValueLvl what level v) (instantiateComputationLvl what level cβ) (instantiateComputationLvl what level cβ)\n| .app vβ vβ => .app (instantiateValueLvl what level vβ) (instantiateValueLvl what level vβ)\n| .handle v c => .handle (instantiateValueLvl what level v) (instantiateComputationLvl what level c)\n| .join vβ vβ => .join (instantiateValueLvl what level vβ) (instantiateValueLvl what level vβ)\n| .fst v => .fst (instantiateValueLvl what level v)\n| .snd v => .snd (instantiateValueLvl what level v)\n| .add vβ vβ => .add (instantiateValueLvl what level vβ) (instantiateValueLvl what level vβ)\n| .sub vβ vβ => .sub (instantiateValueLvl what level vβ) (instantiateValueLvl what level vβ)\n| .max vβ vβ => .max (instantiateValueLvl what level vβ) (instantiateValueLvl what level vβ)\n| .lt vβ vβ => .lt (instantiateValueLvl what level vβ) (instantiateValueLvl what level vβ)\n| .mul vβ vβ => .mul (instantiateValueLvl what level vβ) (instantiateValueLvl what level vβ)\n| .eq vβ vβ => .eq (instantiateValueLvl what level vβ) (instantiateValueLvl what level vβ)\ntermination_by c => sizeOf c\ndecreasing_by\n all_goals simp\n all_goals grind"
},
{
"name": "instantiateValueLvl",
"content": "def instantiateValueLvl (what : Value) (level : Nat) : Value β Value\n| var@(.var (.bvar bvarLevel)) => if bvarLevel = level then what else var\n| .lam c => .lam <| instantiateComputationLvl what (level + 1) c\n| .hdl h => .hdl <| instantiateHandlerLvl what level h\n| .pair vβ vβ => .pair (instantiateValueLvl what level vβ) (instantiateValueLvl what level vβ)\n| .recfun c => .recfun <| instantiateComputationLvl what (level + 2) c\n| .string s => .string s\n| .bool b => .bool b\n| .unit => .unit\n| .var v => .var v\n| .num n => .num n\ntermination_by v => sizeOf v\ndecreasing_by\n all_goals simp\n all_goals grind"
},
{
"name": "instantiateHandlerLvl",
"content": "def instantiateHandlerLvl (what : Value) (level : Nat) : Handler β Handler\n| β¨ret, ops'β© =>\n β¨instantiateComputationLvl what (level+1) ret, instantiateOps what level ops'β©\ntermination_by h => sizeOf h\ndecreasing_by\n all_goals simp\n all_goals grind"
},
{
"name": "instantiateOps",
"content": "def instantiateOps (what : Value) (level : Nat) : List OpClause β List OpClause\n| [] => []\n| β¨op, bodyβ© :: ls =>\n β¨op, instantiateComputationLvl what (level+2) bodyβ© :: instantiateOps what level ls\ntermination_by l => sizeOf l"
},
{
"name": "OpClause",
"content": "structure OpClause where\n op : Name\n \n body : Computation\nderiving Repr, BEq"
},
{
"name": "Computation",
"content": "inductive Computation where\n| ret : Value β Computation\n \n| opCall : Name β Value β Computation β Computation\n \n| bind : Computation β Computation β Computation\n| ite (val : Value) (trueBranch falseBranch : Computation)\n| app : Value β Value β Computation\n \n| handle : Value β Computation β Computation\n| join : Value β Value β Computation\n| fst : Value β Computation\n| snd : Value β Computation\n| add : Value β Value β Computation\n| sub : Value β Value β Computation\n| mul : Value β Value β Computation\n| max : Value β Value β Computation\n| lt : Value β Value β Computation\n| eq : Value β Value β Computation\nderiving BEq"
},
{
"name": "Value",
"content": "inductive Value where\n| var : Var β Value\n| bool : Bool β Value\n| string : String β Value\n| num : Int β Value\n| unit : Value\n| pair : Value β Value β Value\n \n| lam : Computation β Value\n \n| recfun : Computation β Value\n| hdl : Handler β Value\nderiving BEq"
},
{
"name": "Handler",
"content": "structure Handler where\n \n ret : Computation\n ops : List OpClause\nderiving Repr, BEq"
},
{
"name": "Var",
"content": "inductive Var where\n| fvar : Name β Var\n| bvar : Nat β Var\nderiving Repr, DecidableEq"
},
{
"name": "Name",
"content": "abbrev Name := String"
},
{
"name": "Step",
"content": "@[grind cases]\ninductive Step : Computation β Computation β Prop\n \n| beta v body : Step (.app (.lam body) v) (instantiateComp v body)\n \n| recBeta v body : Step (.app (.recfun body) v) (instantiate2 (.recfun body) v body)\n \n| iteTrue cβ cβ : Step (.ite (.bool true) cβ cβ) cβ\n \n| iteFalse cβ cβ : Step (.ite (.bool false) cβ cβ) cβ\n \n| bindStep cβ cβ' cβ (h : Step cβ cβ') : Step (.bind cβ cβ) (.bind cβ' cβ)\n \n| bindReturn v c : Step (.bind (.ret v) c) (instantiateComp v c)\n \n| bindOp op v body c : Step (.bind (.opCall op v body) c) (.opCall op v (.bind body c))\n \n| handleInner h cβ cβ (hβ : Step cβ cβ) : Step (.handle (.hdl h) cβ) (.handle (.hdl h) cβ)\n \n| handleReturn h v :\n Step (.handle (.hdl h) (.ret v)) (instantiateComp v h.ret)\n \n| handleOpHit h op v body c (hop : h.lookup op = some β¨op, cβ©) :\n Step (.handle (.hdl h) (.opCall op v body))\n (instantiate2 v (.lam (.handle (.hdl h) body)) c)\n \n| handleOpMiss h op v body (hop : h.lookup op = none) :\n Step (.handle (.hdl h) (.opCall op v body)) (.opCall op v (.handle (.hdl h) body))\n \n| join sβ sβ : Step (.join (.string sβ) (.string sβ)) (.ret (.string (strAppend sβ sβ)))\n \n| fstStep vβ vβ : Step (.fst (.pair vβ vβ)) (.ret vβ)\n \n| sndStep vβ vβ : Step (.snd (.pair vβ vβ)) (.ret vβ)\n| add vβ vβ : Step (.add (.num vβ) (.num vβ)) (.ret (.num (vβ + vβ)))\n| sub vβ vβ : Step (.sub (.num vβ) (.num vβ)) (.ret (.num (vβ - vβ)))\n| max vβ vβ : Step (.max (.num vβ) (.num vβ)) (.ret (.num (Max.max vβ vβ)))\n| lt vβ vβ : Step (.lt (.num vβ) (.num vβ)) (.ret (.bool (vβ < vβ)))\n| mul vβ vβ : Step (.mul (.num vβ) (.num vβ)) (.ret (.num (vβ * vβ)))\n| eq vβ vβ : Step (.eq vβ vβ) (.ret (.bool (vβ == vβ)))"
},
{
"name": "instantiate2",
"content": "def instantiate2 (arg cont : Value) (body : Computation) : Computation :=\n instantiateComputationLvl arg 1 (instantiateComputationLvl cont 0 body)"
},
{
"name": "strAppend",
"content": "def strAppend : String β String β String\n| \"\", s => s\n| s, \"\" => s\n| sβ, sβ => sβ ++ \" \" ++ sβ"
},
{
"name": "StepStar",
"content": "@[grind cases]\ninductive StepStar : Computation β Computation β Prop\n| refl (c) : StepStar c c\n| trans : Step cβ cβ β StepStar cβ cβ β StepStar cβ cβ"
},
{
"name": "infix:50 \" β€³ \" => Step",
"content": "infix:50 \" β€³ \" => Step"
},
{
"name": "infix:50 \" β€³β \" => StepStar",
"content": "infix:50 \" β€³β \" => StepStar"
}
] | [
{
"name": "trans",
"module": "Mathlib.Order.Defs.Unbundled"
}
] | [
{
"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": "evalSingleStep",
"content": "def evalSingleStep : Computation β Option Computation\n \n| .app (.lam body) v => some <| instantiateComp v body\n \n| .app (.recfun body) v => some <| instantiate2 (.recfun body) v body\n| .ite (.bool true) cβ _ => some cβ\n| .ite (.bool false) _ cβ => some cβ\n \n| .bind (.ret v) c => some <| instantiateComp v c\n \n| .bind (.opCall op v body) c => some <| .opCall op v (.bind body c)\n| .bind cβ cβ => (evalSingleStep cβ).map (fun cβ' => .bind cβ' cβ)\n \n| .handle (.hdl h) (.ret v) => some <| instantiateComp v h.ret\n| .handle (.hdl h) (.opCall op v body) =>\n match h.lookup op with\n \n | some β¨_, cβ© =>\n let cont := .lam (.handle (.hdl h) body)\n some <| instantiate2 v cont c\n \n | none => some <| .opCall op v (.handle (.hdl h) body)\n| .handle (.hdl h) c =>\n (evalSingleStep c).map (fun c' => .handle (.hdl h) c')\n| .join (.string sβ) (.string sβ) => some <| .ret (.string (strAppend sβ sβ))\n| .fst (.pair vβ _) => some <| .ret vβ\n| .snd (.pair _ vβ) => some <| .ret vβ\n| .add (.num vβ) (.num vβ) => some <| .ret (.num (vβ + vβ))\n| .sub (.num vβ) (.num vβ) => some <| .ret (.num (vβ - vβ))\n| .max (.num vβ) (.num vβ) => some <| .ret (.num (Max.max vβ vβ))\n| .lt (.num vβ) (.num vβ) => some <| .ret (.bool (vβ < vβ))\n| .mul (.num vβ) (.num vβ) => some <| .ret (.num (vβ * vβ))\n| .eq vβ vβ => some <| .ret (.bool (vβ == vβ))\n| _ => none"
},
{
"name": "evalFuel",
"content": "def evalFuel : Nat β Computation β Option Computation\n| 0, _ => none\n| _+1, .ret v => some <| .ret v\n| _+1, .opCall n v c => some <| .opCall n v c\n| n+1, c =>\n match evalSingleStep c with\n | some c' => evalFuel n c'\n | none => none"
}
] | [
{
"name": "evalSingleStep_complete",
"content": "theorem evalSingleStep_complete {c c' : Computation} :\n c β€³ c' β evalSingleStep c = (some c')"
},
{
"name": "evalFuel_step",
"content": "theorem evalFuel_step (h : c β€³ c') : evalFuel (n + 1) c = evalFuel n c'"
}
] | import IntroEffects.SmallStep
def evalSingleStep : Computation β Option Computation
| .app (.lam body) v => some <| instantiateComp v body
| .app (.recfun body) v => some <| instantiate2 (.recfun body) v body
| .ite (.bool true) cβ _ => some cβ
| .ite (.bool false) _ cβ => some cβ
| .bind (.ret v) c => some <| instantiateComp v c
| .bind (.opCall op v body) c => some <| .opCall op v (.bind body c)
| .bind cβ cβ => (evalSingleStep cβ).map (fun cβ' => .bind cβ' cβ)
| .handle (.hdl h) (.ret v) => some <| instantiateComp v h.ret
| .handle (.hdl h) (.opCall op v body) =>
match h.lookup op with
| some β¨_, cβ© =>
let cont := .lam (.handle (.hdl h) body)
some <| instantiate2 v cont c
| none => some <| .opCall op v (.handle (.hdl h) body)
| .handle (.hdl h) c =>
(evalSingleStep c).map (fun c' => .handle (.hdl h) c')
| .join (.string sβ) (.string sβ) => some <| .ret (.string (strAppend sβ sβ))
| .fst (.pair vβ _) => some <| .ret vβ
| .snd (.pair _ vβ) => some <| .ret vβ
| .add (.num vβ) (.num vβ) => some <| .ret (.num (vβ + vβ))
| .sub (.num vβ) (.num vβ) => some <| .ret (.num (vβ - vβ))
| .max (.num vβ) (.num vβ) => some <| .ret (.num (Max.max vβ vβ))
| .lt (.num vβ) (.num vβ) => some <| .ret (.bool (vβ < vβ))
| .mul (.num vβ) (.num vβ) => some <| .ret (.num (vβ * vβ))
| .eq vβ vβ => some <| .ret (.bool (vβ == vβ))
| _ => none
def evalFuel : Nat β Computation β Option Computation
| 0, _ => none
| _+1, .ret v => some <| .ret v
| _+1, .opCall n v c => some <| .opCall n v c
| n+1, c =>
match evalSingleStep c with
| some c' => evalFuel n c'
| none => none | theorem evalFuelOpCall_complete_aux (h : c β€³β r) :
βv, r = .opCall name v comp β βn, evalFuel n c = some (.opCall name v comp) := | := by
induction h with
| refl c' =>
intro v hv
exact β¨1, by grind [evalFuel]β©
| @trans c1 c2 c3 hStep hTail ih =>
intro v hv
obtain β¨n, ihFuelβ© := ih v hv
refine β¨n+1, ?_β©
simp [evalFuel_step hStep, ihFuel] | 8 | 34 | false | Semantics |
221 | Iris.Agree.op_inv | theorem Agree.op_inv {x y : Agree Ξ±} : (x.op y).valid β x β‘ y | iris-lean | src/Iris/Algebra/Agree.lean | [
"import Iris.Algebra.CMRA",
"import src.Iris.Algebra.CMRA",
"import src.Iris.Algebra.OFE",
"import Iris.Algebra.OFE"
] | [
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "Option.merge",
"module": "Init.Data.Option.Basic"
},
{
"name": "id",
"module": "Init.Prelude"
}
] | [
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y"
},
{
"name": "notation:50 \"β{\" n \"} \" x:51 => ValidN n x",
"content": "notation:50 \"β{\" n \"} \" x:51 => ValidN n x"
},
{
"name": "notation:50 x \" βΌ{\" n \"} \" y:51 => IncludedN n x y",
"content": "notation:50 x \" βΌ{\" n \"} \" y:51 => IncludedN n x y"
},
{
"name": "Agree",
"content": "@[ext]\nstructure Agree where\n car : List Ξ±\n not_nil : car β []"
},
{
"name": "LeibnizO",
"content": "@[ext] structure LeibnizO (Ξ± : Type _) where\n car : Ξ±"
},
{
"name": "op",
"content": "abbrev op (x y : Ξ± Γ Ξ²) : Ξ± Γ Ξ² :=\n (x.1 β’ y.1, x.2 β’ y.2)"
},
{
"name": "valid",
"content": "def valid : DFrac F β Prop\n | .own f => Proper f\n | .discard => True\n | .ownDiscard f => Fractional f"
},
{
"name": "DFrac",
"content": "inductive DFrac (F : Type _) where\n \n| own (f : F) : DFrac F\n \n| discard : DFrac F\n \n| ownDiscard (f : F) : DFrac F"
},
{
"name": "Fractional",
"content": "def Fractional [Fraction Ξ±] (a : Ξ±) : Prop := β b, Proper (a + b)"
},
{
"name": "Fraction",
"content": "class Fraction (Ξ± : Type _) extends Add Ξ± where\n \n Proper : Ξ± β Prop\n add_comm : β a b : Ξ±, a + b = b + a\n add_assoc : β a b c : Ξ±, a + (b + c) = (a + b) + c\n add_left_cancel : β {a b c : Ξ±}, a + b = a + c β b = c\n \n add_ne : β {a b : Ξ±}, a β b + a\n proper_add_mono_left : β {a b : Ξ±}, Proper (a + b) β Proper a"
},
{
"name": "CMRA",
"content": "class CMRA (Ξ± : Type _) extends OFE Ξ± where\n pcore : Ξ± β Option Ξ±\n op : Ξ± β Ξ± β Ξ±\n ValidN : Nat β Ξ± β Prop\n Valid : Ξ± β Prop\n\n op_ne : NonExpansive (op x)\n pcore_ne : x β‘{n}β‘ y β pcore x = some cx β\n β cy, pcore y = some cy β§ cx β‘{n}β‘ cy\n validN_ne : x β‘{n}β‘ y β ValidN n x β ValidN n y\n\n valid_iff_validN : Valid x β β n, ValidN n x\n validN_succ : ValidN n.succ x β ValidN n x\n validN_op_left : ValidN n (op x y) β ValidN n x\n\n assoc : op x (op y z) β‘ op (op x y) z\n comm : op x y β‘ op y x\n\n pcore_op_left : pcore x = some cx β op cx x β‘ x\n pcore_idem : pcore x = some cx β pcore cx β‘ some cx\n pcore_op_mono : pcore x = some cx β β y, β cy, pcore (op x y) β‘ some (op cx cy)\n\n extend : ValidN n x β x β‘{n}β‘ op yβ yβ β\n Ξ£' zβ zβ, x β‘ op zβ zβ β§ zβ β‘{n}β‘ yβ β§ zβ β‘{n}β‘ yβ"
},
{
"name": "OFE.ContractiveHom.fixpoint_ne",
"content": "instance OFE.ContractiveHom.fixpoint_ne [COFE Ξ±] [Inhabited Ξ±] :\n NonExpansive (ContractiveHom.fixpoint (Ξ± := Ξ±)) where\n ne n f1 f2 H := by admit /- proof elided -/"
},
{
"name": "op",
"content": "def op : DFrac F β DFrac F β DFrac F\n | .discard, .discard => discard\n | own f, .discard\n | ownDiscard f, .discard\n | .discard, own f\n | .discard, ownDiscard f => ownDiscard f\n | own f, own f' => own (f + f')\n | own f, ownDiscard f'\n | ownDiscard f, own f'\n | ownDiscard f, ownDiscard f' => ownDiscard (f + f')"
},
{
"name": "Iso.symm",
"content": "def Iso.symm [OFE Ξ±] [OFE Ξ²] (iso : Iso Ξ± Ξ²) : Iso Ξ² Ξ± where\n hom := iso.inv\n inv := iso.hom\n hom_inv := by admit /- proof elided -/"
},
{
"name": "Iso",
"content": "@[ext] structure Iso (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] where\n hom : Ξ± -n> Ξ²\n inv : Ξ² -n> Ξ±\n hom_inv : hom (inv x) β‘ x\n inv_hom : inv (hom x) β‘ x"
},
{
"name": "OFE.Option.some.ne",
"content": "instance OFE.Option.some.ne [OFE Ξ±] : OFE.NonExpansive (some : Ξ± β Option Ξ±) := β¨fun _ _ _ => idβ©"
},
{
"name": "Option.merge_ne",
"content": "instance Option.merge_ne [OFE Ξ±] {op : Ξ± β Ξ± β Ξ±} [NonExpansiveβ op] :\n NonExpansiveβ (Option.merge op) where\n ne n x1 x2 Hx y1 y2 Hy := by admit /- proof elided -/"
},
{
"name": "NonExpansiveβ",
"content": "class NonExpansiveβ [OFE Ξ±] [OFE Ξ²] [OFE Ξ³] (f : Ξ± β Ξ² β Ξ³) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β β β¦yβ yββ¦, yβ β‘{n}β‘ yβ β f xβ yβ β‘{n}β‘ f xβ yβ"
},
{
"name": "ContractiveHom",
"content": "@[ext] structure ContractiveHom (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] extends Hom Ξ± Ξ² where\n [contractive : Contractive f]\n ne := ne_of_contractive f"
},
{
"name": "NonExpansive",
"content": "class NonExpansive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β f xβ β‘{n}β‘ f xβ"
},
{
"name": "Included",
"content": "def Included (x y : Ξ±) : Prop := β z, y β‘ x β’ z"
},
{
"name": "Reflexive",
"content": "class Reflexive (R : Relation Ξ±) where\n refl {x : Ξ±} : R x x"
},
{
"name": "Commutative",
"content": "class Commutative (R : Relation Ξ±) (f : Ξ² β Ξ² β Ξ±) where\n comm {x y : Ξ²} : R (f x y) (f y x)"
},
{
"name": "scoped infix:40 \" β‘ \" => OFE.Equiv",
"content": "scoped infix:40 \" β‘ \" => OFE.Equiv"
},
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y"
},
{
"name": "infixr:25 \" -c> \" => ContractiveHom",
"content": "infixr:25 \" -c> \" => ContractiveHom"
},
{
"name": "infix:60 \" β’ \" => op",
"content": "infix:60 \" β’ \" => op"
},
{
"name": "infix:50 \" βΌ \" => Included",
"content": "infix:50 \" βΌ \" => Included"
}
] | [
{
"name": "List.mem_append",
"module": "Init.Data.List.Lemmas"
}
] | [
{
"name": "_root_.Iris.OFE.Dist.validN",
"content": "theorem _root_.Iris.OFE.Dist.validN : (x : Ξ±) β‘{n}β‘ y β (β{n} x β β{n} y)"
},
{
"name": "validN_iff",
"content": "theorem validN_iff {x y : Ξ±} (e : x β‘{n}β‘ y) : β{n} x β β{n} y"
},
{
"name": "IncludedN.validN",
"content": "theorem IncludedN.validN {n} {x y : Ξ±} : x βΌ{n} y β β{n} y β β{n} x"
},
{
"name": "validN_of_incN",
"content": "theorem validN_of_incN {n} {x y : Ξ±} : x βΌ{n} y β β{n} y β β{n} x"
},
{
"name": "Included.validN",
"content": "theorem Included.validN {n} {x y : Ξ±} : x βΌ y β β{n} y β β{n} x"
},
{
"name": "validN_of_inc",
"content": "theorem validN_of_inc {n} {x y : Ξ±} : x βΌ y β β{n} y β β{n} x"
},
{
"name": "Valid.validN",
"content": "theorem Valid.validN : β (x : Ξ±) β β{n} x"
},
{
"name": "Dist.rfl",
"content": "@[simp, refl] theorem Dist.rfl [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ x"
},
{
"name": "_root_.Iris.OFE.Dist.op",
"content": "theorem _root_.Iris.OFE.Dist.op {x x' y y' : Ξ±}\n (ex : x β‘{n}β‘ x') (ey : y β‘{n}β‘ y') : x β’ y β‘{n}β‘ x' β’ y'"
},
{
"name": "Included.trans",
"content": "theorem Included.trans : (x : Ξ±) βΌ y β y βΌ z β x βΌ z"
},
{
"name": "inc_trans",
"content": "theorem inc_trans {x y z : Ξ±} : x βΌ y β y βΌ z β x βΌ z"
},
{
"name": "op_left_eqv",
"content": "theorem op_left_eqv {x y : Ξ±} (z : Ξ±) (e : x β‘ y) : x β’ z β‘ y β’ z"
},
{
"name": "_root_.Iris.OFE.Dist.op_r",
"content": "theorem _root_.Iris.OFE.Dist.op_r {x y z : Ξ±} : y β‘{n}β‘ z β x β’ y β‘{n}β‘ x β’ z"
},
{
"name": "op_right_dist",
"content": "theorem op_right_dist (x : Ξ±) {y z : Ξ±} (e : y β‘{n}β‘ z) : x β’ y β‘{n}β‘ x β’ z"
},
{
"name": "_root_.Iris.OFE.Equiv.op_r",
"content": "theorem _root_.Iris.OFE.Equiv.op_r {x y z : Ξ±} : y β‘ z β x β’ y β‘ x β’ z"
},
{
"name": "op_right_eqv",
"content": "theorem op_right_eqv (x : Ξ±) {y z : Ξ±} (e : y β‘ z) : x β’ y β‘ x β’ z"
},
{
"name": "IncludedN.trans",
"content": "theorem IncludedN.trans : (x : Ξ±) βΌ{n} y β y βΌ{n} z β x βΌ{n} z"
},
{
"name": "incN_trans",
"content": "theorem incN_trans {x y z : Ξ±} : x βΌ{n} y β y βΌ{n} z β x βΌ{n} z"
},
{
"name": "op_left_dist",
"content": "theorem op_left_dist {x y : Ξ±} (z : Ξ±) (e : x β‘{n}β‘ y) : x β’ z β‘{n}β‘ y β’ z"
},
{
"name": "_root_.Iris.OFE.Dist.op_l",
"content": "theorem _root_.Iris.OFE.Dist.op_l {x y z : Ξ±} : x β‘{n}β‘ y β x β’ z β‘{n}β‘ y β’ z"
},
{
"name": "_root_.Iris.OFE.Equiv.op_l",
"content": "theorem _root_.Iris.OFE.Equiv.op_l {x y z : Ξ±} : x β‘ y β x β’ z β‘ y β’ z"
},
{
"name": "_root_.Iris.OFE.Equiv.op",
"content": "theorem _root_.Iris.OFE.Equiv.op : (x : Ξ±) β‘ x' β y β‘ y' β x β’ y β‘ x' β’ y'"
},
{
"name": "op_eqv",
"content": "theorem op_eqv {x x' y y' : Ξ±} (ex : x β‘ x') (ey : y β‘ y') : x β’ y β‘ x' β’ y'"
}
] | [
{
"name": "Iris.Agree",
"content": "@[ext]\nstructure Agree where\n car : List Ξ±\n not_nil : car β []"
},
{
"name": "Iris.Agree.dist",
"content": "def Agree.dist (n : Nat) (x y : Agree Ξ±) : Prop :=\n (β a β x.car, β b β y.car, a β‘{n}β‘ b) β§\n (β b β y.car, β a β x.car, a β‘{n}β‘ b)"
},
{
"name": "Iris.Agree.validN",
"content": "def Agree.validN (n : Nat) (x : Agree Ξ±) : Prop :=\n match x.car with\n | [_] => True\n | _ => β a β x.car, β b β x.car, a β‘{n}β‘ b"
},
{
"name": "Iris.Agree.op",
"content": "def Agree.op (x y : Agree Ξ±) : Agree Ξ± :=\n β¨x.car ++ y.car, by admit /- proof elided -/\n β©"
}
] | [
{
"name": "Iris.mem_of_agree",
"content": "theorem mem_of_agree (x : Agree Ξ±) : β a, a β x.car"
},
{
"name": "Iris.Agree.equiv_def",
"content": "theorem Agree.equiv_def {x y : Agree Ξ±} : x β‘ y β β n, Agree.dist n x y"
},
{
"name": "Iris.Agree.validN_iff",
"content": "theorem Agree.validN_iff {x : Agree Ξ±} :\n x.validN n β β a β x.car, β b β x.car, a β‘{n}β‘ b"
},
{
"name": "Iris.Agree.op_invN",
"content": "theorem Agree.op_invN {x y : Agree Ξ±} : (x.op y).validN n β x β‘{n}β‘ y"
}
] | import Iris.Algebra.CMRA
import Iris.Algebra.OFE
namespace Iris
section agree
variable {Ξ± : Type u}
variable (Ξ±) in
@[ext]
structure Agree where
car : List Ξ±
not_nil : car β []
variable [OFE Ξ±]
def Agree.dist (n : Nat) (x y : Agree Ξ±) : Prop :=
(β a β x.car, β b β y.car, a β‘{n}β‘ b) β§
(β b β y.car, β a β x.car, a β‘{n}β‘ b)
def Agree.validN (n : Nat) (x : Agree Ξ±) : Prop :=
match x.car with
| [_] => True
| _ => β a β x.car, β b β x.car, a β‘{n}β‘ b
def Agree.valid (x : Agree Ξ±) : Prop := β n, x.validN n
def Agree.op (x y : Agree Ξ±) : Agree Ξ± :=
β¨x.car ++ y.car, by admit /- proof elided -/
β© | theorem Agree.op_inv {x y : Agree Ξ±} : (x.op y).valid β x β‘ y := | := by
simp [valid, equiv_def]
intro h n
exact op_invN (h n) | 8 | 58 | false | Framework |
222 | Iris.OFE.ContractiveHom.fixpoint_ind | @[elab_as_elim]
theorem OFE.ContractiveHom.fixpoint_ind [COFE Ξ±] [Inhabited Ξ±] (f : Ξ± -c> Ξ±)
(P : Ξ± β Prop) (HProper : β A B : Ξ±, A β‘ B β P A β P B) (x : Ξ±) (Hbase : P x)
(Hind : β x, P x β P (f x)) (Hlim : LimitPreserving P) :
P f.fixpoint | iris-lean | src/Iris/Algebra/OFE.lean | [
"import src/Iris/Algebra/Excl.lean",
"import src/Iris/Algebra/Agree.lean",
"import src/Iris/Algebra/UPred.lean",
"import src/Iris/Algebra/COFESolver.lean",
"import src/Iris/Instances/UPred/Instance.lean",
"import src/Iris/Algebra/Agree_task.lean",
"import src/Iris/Algebra/CMRA.lean",
"import src/Iris/Algebra/Heap.lean"
] | [
{
"name": "Equivalence",
"module": "Init.Core"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "m",
"module": "QqTest.matching"
},
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "Option.merge",
"module": "Init.Data.Option.Basic"
},
{
"name": "id",
"module": "Init.Prelude"
},
{
"name": "Inhabited",
"module": "Init.Prelude"
},
{
"name": "Dist",
"module": "Mathlib.Topology.MetricSpace.Pseudo.Defs"
},
{
"name": "Equiv",
"module": "Mathlib.Logic.Equiv.Defs"
},
{
"name": "Nat.succ",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "k",
"module": "QqTest.matching"
}
] | [
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y"
},
{
"name": "notation:50 x \" βΌ{\" n \"} \" y:51 => IncludedN n x y",
"content": "notation:50 x \" βΌ{\" n \"} \" y:51 => IncludedN n x y"
},
{
"name": "Transitive",
"content": "class Transitive (R : Relation Ξ±) where\n trans {x y z : Ξ±} : R x y β R y z β R x z"
},
{
"name": "Reflexive",
"content": "class Reflexive (R : Relation Ξ±) where\n refl {x : Ξ±} : R x x"
},
{
"name": "",
"content": "instance : OFE.Discrete (DFrac F) := β¨congrArg idβ©"
},
{
"name": "Agree.dist",
"content": "def Agree.dist (n : Nat) (x y : Agree Ξ±) : Prop :=\n (β a β x.car, β b β y.car, a β‘{n}β‘ b) β§\n (β b β y.car, β a β x.car, a β‘{n}β‘ b)"
},
{
"name": "",
"content": "instance : OFE (Tower F) where\n Equiv f g := β k, f k β‘ g k\n Dist n f g := β k, f k β‘{n}β‘ g k\n dist_eqv := {\n refl _ _ := dist_eqv.refl _\n symm h _ := dist_eqv.symm (h _)\n trans h1 h2 _ := dist_eqv.trans (h1 _) (h2 _)\n }\n equiv_dist {_ _} := by admit /- proof elided -/"
},
{
"name": "",
"content": "instance : OFE.NonExpansive (BUpd.bupd (PROP := UPred M)) := bupd_ne"
},
{
"name": "bupd_ne",
"content": "instance bupd_ne : OFE.NonExpansive (bupd : UPred M β UPred M) where\n ne n x1 x2 Hx m y Hm Hv := by admit /- proof elided -/"
},
{
"name": "CMRA",
"content": "class CMRA (Ξ± : Type _) extends OFE Ξ± where\n pcore : Ξ± β Option Ξ±\n op : Ξ± β Ξ± β Ξ±\n ValidN : Nat β Ξ± β Prop\n Valid : Ξ± β Prop\n\n op_ne : NonExpansive (op x)\n pcore_ne : x β‘{n}β‘ y β pcore x = some cx β\n β cy, pcore y = some cy β§ cx β‘{n}β‘ cy\n validN_ne : x β‘{n}β‘ y β ValidN n x β ValidN n y\n\n valid_iff_validN : Valid x β β n, ValidN n x\n validN_succ : ValidN n.succ x β ValidN n x\n validN_op_left : ValidN n (op x y) β ValidN n x\n\n assoc : op x (op y z) β‘ op (op x y) z\n comm : op x y β‘ op y x\n\n pcore_op_left : pcore x = some cx β op cx x β‘ x\n pcore_idem : pcore x = some cx β pcore cx β‘ some cx\n pcore_op_mono : pcore x = some cx β β y, β cy, pcore (op x y) β‘ some (op cx cy)\n\n extend : ValidN n x β x β‘{n}β‘ op yβ yβ β\n Ξ£' zβ zβ, x β‘ op zβ zβ β§ zβ β‘{n}β‘ yβ β§ zβ β‘{n}β‘ yβ"
},
{
"name": "later_contractive",
"content": "instance later_contractive : OFE.Contractive UPred.later (Ξ± := UPred M) where\n distLater_dist {n x y} Hl :=\n match n with\n | 0 => by admit /- proof elided -/\n | n + 1 => fun\n | 0 => by admit /- proof elided -/\n | n' + 1 => fun x' Hn' Hx' => Hl _ Hn' _ _ (Nat.le_refl _) (CMRA.validN_succ Hx')"
},
{
"name": "later",
"content": "protected def later (P : UPred M) : UPred M where\n holds n x := match n with | 0 => True | Nat.succ n' => P n' x\n mono {nβ nβ} := by admit /- proof elided -/"
},
{
"name": "BIPlainly",
"content": "class BIPlainly (PROP : Type _) [Iris.BI PROP] extends Plainly PROP where\n [ne : Iris.OFE.NonExpansive (Plainly.plainly (PROP := PROP))]\n mono {P Q : PROP} : (P β’ Q) β β P β’ β Q\n elim_persistently {P : PROP} : β P β’ <pers> P\n idem {P : PROP} : β P β’ β β P\n plainly_sForall_2 {Ξ¦ : PROP β Prop} : (β p, βΞ¦ pβ β β p) β’ β sForall Ξ¦\n plainly_impl_plainly {P Q : PROP} : (β P β β Q) β’ β (β P β Q)\n emp_intro {P : PROP} : P β’ β emp\n plainly_absorb {P Q : PROP} : β P β Q β’ β P\n later_plainly {P : PROP} : β· β P β£β’ β β· P"
},
{
"name": "BIUpdate",
"content": "class BIUpdate (PROP : Type _) [BI PROP] extends BUpd PROP where\n [bupd_ne : OFE.NonExpansive (BUpd.bupd (PROP := PROP))]\n intro {P : PROP} : iprop(P β’ |==> P)\n mono {P Q : PROP} : iprop(P β’ Q) β iprop(|==> P β’ |==> Q)\n trans {P : PROP} : iprop(|==> |==> P β’ |==> P)\n frame_r {P R : PROP} : iprop((|==> P) β R β’ |==> (P β R))"
},
{
"name": "UPred",
"content": "@[ext]\nstructure UPred (M : Type _) [UCMRA M] where\n holds : Nat β M β Prop\n mono {n1 n2 x1 x2} : holds n1 x1 β x1 βΌ{n2} x2 β n2 β€ n1 β holds n2 x2"
},
{
"name": "IsModal",
"content": "class IsModal [BI PROP1] [BI PROP2] (M : PROP1 β PROP2)\n (iaction saction : ModalityAction PROP1 PROP2) where\n spec_intuitionistic : iaction.intuitionistic_action_spec M\n spec_spatial : saction.spatial_action_spec M\n emp : iprop(emp) β’ M iprop(emp)\n mono : β {P Q}, (P β’ Q) β M P β’ M Q\n sep : β {P Q}, iprop(M P β M Q) β’ M iprop(P β Q)"
},
{
"name": "UCMRA",
"content": "class UCMRA (Ξ± : Type _) extends CMRA Ξ± where\n unit : Ξ±\n unit_valid : β unit\n unit_left_id : unit β’ x β‘ x\n pcore_unit : pcore unit β‘ some unit"
},
{
"name": "pcore",
"content": "def pcore : DFrac F β Option (DFrac F)\n | own _ => none\n | .discard => some discard\n | ownDiscard _ => some discard"
},
{
"name": "DFrac",
"content": "inductive DFrac (F : Type _) where\n \n| own (f : F) : DFrac F\n \n| discard : DFrac F\n \n| ownDiscard (f : F) : DFrac F"
},
{
"name": "op",
"content": "def op : DFrac F β DFrac F β DFrac F\n | .discard, .discard => discard\n | own f, .discard\n | ownDiscard f, .discard\n | .discard, own f\n | .discard, ownDiscard f => ownDiscard f\n | own f, own f' => own (f + f')\n | own f, ownDiscard f'\n | ownDiscard f, own f'\n | ownDiscard f, ownDiscard f' => ownDiscard (f + f')"
},
{
"name": "Associative",
"content": "class Associative (R : Relation Ξ±) (f : Ξ± β Ξ± β Ξ±) where\n assoc {x y z : Ξ±} : R (f (f x y) z) (f x (f y z))"
},
{
"name": "Commutative",
"content": "class Commutative (R : Relation Ξ±) (f : Ξ² β Ξ² β Ξ±) where\n comm {x y : Ξ²} : R (f x y) (f y x)"
},
{
"name": "Included",
"content": "def Included (x y : Ξ±) : Prop := β z, y β‘ x β’ z"
},
{
"name": "instOFE",
"content": "instance instOFE [Store T K V] [OFE V] : OFE T where\n Equiv s0 s1 := get s0 β‘ get s1\n Dist n s0 s1 := get s0 β‘{n}β‘ get s1\n dist_eqv := β¨fun _ => .of_eq rfl, (Β·.symm), (Β·.trans Β·)β©\n equiv_dist := equiv_dist\n dist_lt := dist_lt"
},
{
"name": "Store.Equiv",
"content": "@[simp] def Store.Equiv [Store T K V] (t1 t2 : T) : Prop := get t1 = get t2"
},
{
"name": "Store.Equiv_trans",
"content": "instance Store.Equiv_trans [Store T K V] : Trans Equiv (Equiv (T := T)) Equiv := β¨by admit /- proof elided -/\nβ©"
},
{
"name": "[CMRA",
"content": "instance [CMRA Ξ²] : OFE (Ξ± -C> Ξ²) where\n Equiv f g := f.toHom β‘ g.toHom\n Dist n f g := f.toHom β‘{n}β‘ g.toHom\n dist_eqv := {\n refl _ := dist_eqv.refl _\n symm h := dist_eqv.symm h\n trans h1 h2 := dist_eqv.trans h1 h2\n }\n equiv_dist := equiv_dist\n dist_lt := dist_lt"
},
{
"name": "[OFE",
"content": "instance [OFE Ξ±] [IsCOFE Ξ±] : IsCOFE (Excl Ξ±) where\n compl c := (c 0).map fun x => IsCOFE.compl (exclChain c x)\n conv_compl {n} c := by admit /- proof elided -/"
},
{
"name": "toAgree",
"content": "def toAgree (a : Ξ±) : Agree Ξ± := β¨[a], by admit /- proof elided -/\nβ©"
},
{
"name": "Agree",
"content": "@[ext]\nstructure Agree where\n car : List Ξ±\n not_nil : car β []"
},
{
"name": "(k",
"content": "instance (k : Nat) : NonExpansive (fun X : Tower F => X.val k) := β¨fun _ _ _ => (Β· _)β©"
},
{
"name": "[OFE",
"content": "instance [OFE Ξ±] : NonExpansive excl (Ξ± := Ξ±) where\n ne _ _ _ a := a"
},
{
"name": "get_ne",
"content": "instance get_ne [Store T K V] [OFE V] (k : K) : NonExpansive (get Β· k : T β V) where\n ne {_ _ _} Ht := Ht k"
},
{
"name": "[Store",
"content": "instance [Store T1 K V1] [Store T2 K V2] [OFE V1] [OFE V2] (f : K β V1 β V2)\n [β k, NonExpansive (f k)] [HasStoreMap T1 T2 K V1 V2] : NonExpansive (dmap f : T1 β T2) where\n ne _ {_ _} H k := by admit /- proof elided -/"
},
{
"name": "HasStoreMap",
"content": "class HasStoreMap (T1 T2 : Type _) (K V1 V2 : outParam (Type _)) [Store T1 K V1] [Store T2 K V2] where\n \n dmap (f : K β V1 β V2) : T1 β T2\n get_dmap : get (dmap f t) k = f k (get t k)"
},
{
"name": "",
"content": "instance : NonExpansive (pcore (Ξ± := Ξ±)) where\n ne n x {y} e := by admit /- proof elided -/"
},
{
"name": "[Heap",
"content": "instance [Heap T K V] [OFE V] (op : V β V β V) [NonExpansiveβ op] :\n NonExpansiveβ (merge (T := T) op) where\n ne _ {_ _} Ht {_ _} Hs k := by admit /- proof elided -/"
},
{
"name": "Heap.instCOFE",
"content": "instance Heap.instCOFE [Heap T K V] [COFE V] : COFE T where\n compl c := hmap (fun _ => COFE.compl <| c.map β¨_, Store.get_ne Β·β©) (c 0)\n conv_compl {_ c} k := by admit /- proof elided -/"
},
{
"name": "infix:60 \" β’ \" => op",
"content": "infix:60 \" β’ \" => op"
},
{
"name": "infix:50 \" βΌ \" => Included",
"content": "infix:50 \" βΌ \" => Included"
},
{
"name": "@[inherit_doc]",
"content": "@[inherit_doc]\ninfixr:25 \" -C> \" => Hom"
}
] | [
{
"name": "Nat.lt_of_le_of_ne",
"module": "Init.Prelude"
},
{
"name": "Nat.le_of_lt_succ",
"module": "Init.Prelude"
},
{
"name": "Nat.lt_succ_self",
"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": "Iris.OFE",
"content": "class OFE (Ξ± : Type _) where\n Equiv : Ξ± β Ξ± β Prop\n Dist : Nat β Ξ± β Ξ± β Prop\n dist_eqv : Equivalence (Dist n)\n equiv_dist : Equiv x y β β n, Dist n x y\n dist_lt : Dist n x y β m < n β Dist m x y"
},
{
"name": "Iris.OFE.NonExpansive",
"content": "class NonExpansive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β f xβ β‘{n}β‘ f xβ"
},
{
"name": "Iris.OFE.id_ne",
"content": "instance id_ne [OFE Ξ±] : NonExpansive (@id Ξ±) := β¨fun _ _ _ h => hβ©"
},
{
"name": "Iris.OFE.NonExpansiveβ",
"content": "class NonExpansiveβ [OFE Ξ±] [OFE Ξ²] [OFE Ξ³] (f : Ξ± β Ξ² β Ξ³) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β β β¦yβ yββ¦, yβ β‘{n}β‘ yβ β f xβ yβ β‘{n}β‘ f xβ yβ"
},
{
"name": "Iris.OFE.DistLater",
"content": "def DistLater [OFE Ξ±] (n : Nat) (x y : Ξ±) : Prop := β m, m < n β x β‘{m}β‘ y"
},
{
"name": "Iris.OFE.Contractive",
"content": "class Contractive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) where\n distLater_dist : DistLater n x y β f x β‘{n}β‘ f y"
},
{
"name": "Iris.OFE.ne_of_contractive",
"content": "instance ne_of_contractive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) [Contractive f] : NonExpansive f where\n ne := fun _ _ _ h => Contractive.distLater_dist (Dist.distLater h)"
},
{
"name": "Iris.OFE._inst_Ξ²",
"content": "instance [OFE Ξ±] [OFE Ξ²] {x : Ξ²} : Contractive (fun _ : Ξ± => x) where\n distLater_dist := fun _ => Dist.rfl"
},
{
"name": "Iris.OFE.Hom",
"content": "@[ext] structure Hom (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] where\n f : Ξ± β Ξ²\n ne : NonExpansive f"
},
{
"name": "Iris.OFE._inst_Ξ±",
"content": "instance [OFE Ξ±] [OFE Ξ²] (f : Ξ± -n> Ξ²) : NonExpansive f := f.ne"
},
{
"name": "Iris.OFE.ContractiveHom",
"content": "@[ext] structure ContractiveHom (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] extends Hom Ξ± Ξ² where\n [contractive : Contractive f]\n ne := ne_of_contractive f"
},
{
"name": "Iris.OFE._inst_Ξ±",
"content": "instance [OFE Ξ±] [OFE Ξ²] (f : Ξ± -c> Ξ²) : Contractive f := f.contractive"
},
{
"name": "Iris.OFE._inst_OFE",
"content": "instance : OFE Unit where\n Equiv _ _ := True\n Dist _ _ _ := True\n dist_eqv := β¨fun _ => β¨β©, id, fun _ => idβ©\n equiv_dist := by admit /- proof elided -/"
},
{
"name": "Iris.OFE._inst_OFE",
"content": "instance [OFE Ξ±] : OFE (ULift Ξ±) where\n Equiv x y := x.down β‘ y.down\n Dist n x y := x.down β‘{n}β‘ y.down\n dist_eqv := InvImage.equivalence dist_eqv\n equiv_dist := equiv_dist\n dist_lt := dist_lt"
},
{
"name": "Iris.OFE._inst_OFE",
"content": "instance [OFE Ξ±] : OFE (Option Ξ±) where\n Equiv := Option.Forallβ Equiv\n Dist n := Option.Forallβ (Dist n)\n dist_eqv := Option.Forallβ.equivalence dist_eqv\n equiv_dist {x y} := by admit /- proof elided -/"
},
{
"name": "Iris.OFE._inst_OFE",
"content": "instance [OFE Ξ±] [OFE.Discrete Ξ±] : OFE.Discrete (Option Ξ±) where\n discrete_0 {mx my} e :=\n match mx, my with\n | none, none => e\n | none, some _ => e\n | some _, none => e\n | some x, some y => show x β‘ y from discrete_0 e"
},
{
"name": "Iris.OFE.OFE",
"content": "instance OFE.Option.some.ne [OFE Ξ±] : OFE.NonExpansive (some : Ξ± β Option Ξ±) := β¨fun _ _ _ => idβ©"
},
{
"name": "Iris.OFE.Option",
"content": "instance Option.merge_ne [OFE Ξ±] {op : Ξ± β Ξ± β Ξ±} [NonExpansiveβ op] :\n NonExpansiveβ (Option.merge op) where\n ne n x1 x2 Hx y1 y2 Hy := by admit /- proof elided -/"
},
{
"name": "Iris.OFE._inst_Ξ±",
"content": "instance [OFEFun (Ξ² : Ξ± β _)] : OFE ((x : Ξ±) β Ξ² x) where\n Equiv f g := β x, f x β‘ g x\n Dist n f g := β x, f x β‘{n}β‘ g x\n dist_eqv := {\n refl _ _ := dist_eqv.refl _\n symm h _ := dist_eqv.symm (h _)\n trans h1 h2 _ := dist_eqv.trans (h1 _) (h2 _)\n }\n equiv_dist {_ _} := by admit /- proof elided -/"
},
{
"name": "Iris.OFE._inst_OFE",
"content": "instance [OFE Ξ±] [OFE Ξ²] : OFE (Ξ± -n> Ξ²) where\n Equiv f g := f.f β‘ g.f\n Dist n f g := f.f β‘{n}β‘ g.f\n dist_eqv := {\n refl _ := dist_eqv.refl _\n symm h := dist_eqv.symm h\n trans h1 h2 := dist_eqv.trans h1 h2\n }\n equiv_dist := equiv_dist\n dist_lt := dist_lt"
},
{
"name": "Iris.OFE._inst_OFE",
"content": "instance [OFE Ξ±] [OFE Ξ²] : OFE (Ξ± -c> Ξ²) where\n Equiv f g := Equiv f.toHom g.toHom\n Dist n f g := Dist n f.toHom g.toHom\n dist_eqv := {\n refl _ := dist_eqv.refl _\n symm h := dist_eqv.symm h\n trans h1 h2 := dist_eqv.trans h1 h2\n }\n equiv_dist := equiv_dist\n dist_lt := dist_lt"
},
{
"name": "Iris.OFE._inst_OFE",
"content": "instance [OFE Ξ±] [OFE Ξ²] : OFE (Ξ± Γ Ξ²) where\n Equiv a b := a.1 β‘ b.1 β§ a.2 β‘ b.2\n Dist n a b := a.1 β‘{n}β‘ b.1 β§ a.2 β‘{n}β‘ b.2\n dist_eqv := {\n refl _ := β¨dist_eqv.refl _, dist_eqv.refl _β©\n symm h := β¨dist_eqv.symm h.1, dist_eqv.symm h.2β©\n trans h1 h2 := β¨dist_eqv.trans h1.1 h2.1, dist_eqv.trans h1.2 h2.2β©\n }\n equiv_dist {_ _} := by admit /- proof elided -/"
},
{
"name": "Iris.OFE.Iso",
"content": "@[ext] structure Iso (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] where\n hom : Ξ± -n> Ξ²\n inv : Ξ² -n> Ξ±\n hom_inv : hom (inv x) β‘ x\n inv_hom : inv (hom x) β‘ x"
},
{
"name": "Iris.OFE._inst_Iso",
"content": "instance [OFE Ξ±] [OFE Ξ²] (iso : Iso Ξ± Ξ²) : NonExpansive iso.hom := iso.hom.ne"
},
{
"name": "Iris.OFE._inst_Iso",
"content": "instance [OFE Ξ±] [OFE Ξ²] (iso : Iso Ξ± Ξ²) : NonExpansive iso.inv := iso.inv.ne"
},
{
"name": "Iris.OFE.Iso.symm",
"content": "def Iso.symm [OFE Ξ±] [OFE Ξ²] (iso : Iso Ξ± Ξ²) : Iso Ξ² Ξ± where\n hom := iso.inv\n inv := iso.hom\n hom_inv := by admit /- proof elided -/"
},
{
"name": "Iris.Chain",
"content": "structure Chain (Ξ± : Type _) [OFE Ξ±] where\n chain : Nat β Ξ±\n cauchy : n β€ i β chain i β‘{n}β‘ chain n"
},
{
"name": "Iris.IsCOFE",
"content": "class IsCOFE (Ξ± : Type _) [OFE Ξ±] where\n compl : Chain Ξ± β Ξ±\n conv_compl {c : Chain Ξ±} : compl c β‘{n}β‘ c n"
},
{
"name": "Iris.LeibnizO",
"content": "@[ext] structure LeibnizO (Ξ± : Type _) where\n car : Ξ±"
},
{
"name": "Iris.optionChain",
"content": "def optionChain (c : Chain (Option Ξ±)) (x : Ξ±) : Chain Ξ± :="
},
{
"name": "Iris.isCOFE_option",
"content": "instance isCOFE_option [IsCOFE Ξ±] : IsCOFE (Option Ξ±) where\n compl c := (c 0).map fun x => IsCOFE.compl (optionChain c x)\n conv_compl {n} c := by admit /- proof elided -/"
},
{
"name": "Iris.LimitPreserving",
"content": "def LimitPreserving [COFE Ξ±] (P : Ξ± β Prop) : Prop :=\n β (c : Chain Ξ±), (β n, P (c n)) β P (COFE.compl c)"
},
{
"name": "Iris.Fixpoint.chain",
"content": "def Fixpoint.chain [OFE Ξ±] [Inhabited Ξ±] (f : Ξ± β Ξ±) [Contractive f] : Chain Ξ± where\n chain n := Nat.repeat f (n + 1) default\n cauchy {n} := by admit /- proof elided -/"
},
{
"name": "Iris.fixpoint",
"content": "def fixpoint [COFE Ξ±] [Inhabited Ξ±] (f : Ξ± β Ξ±) [Contractive f] : Ξ± :=\n COFE.compl <| Fixpoint.chain f\n\nnonrec abbrev OFE.ContractiveHom.fixpoint [COFE Ξ±] [Inhabited Ξ±] (f : Ξ± -c> Ξ±) : Ξ± := fixpoint f.f"
},
{
"name": "Iris.OFE",
"content": "instance OFE.ContractiveHom.fixpoint_ne [COFE Ξ±] [Inhabited Ξ±] :\n NonExpansive (ContractiveHom.fixpoint (Ξ± := Ξ±)) where\n ne n f1 f2 H := by admit /- proof elided -/"
}
] | [
{
"name": "Iris.OFE.Dist.lt",
"content": "theorem Dist.lt [OFE Ξ±] {m n} {x y : Ξ±} : x β‘{n}β‘ y β m < n β x β‘{m}β‘ y"
},
{
"name": "Iris.OFE.Dist.le",
"content": "theorem Dist.le [OFE Ξ±] {m n} {x y : Ξ±} (h : x β‘{n}β‘ y) (h' : m β€ n) : x β‘{m}β‘ y"
},
{
"name": "Iris.OFE.Dist.rfl",
"content": "@[simp, refl] theorem Dist.rfl [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ x"
},
{
"name": "Iris.OFE.Dist.symm",
"content": "@[symm] theorem Dist.symm [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ y β y β‘{n}β‘ x"
},
{
"name": "Iris.OFE.Dist.trans",
"content": "theorem Dist.trans [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ y β y β‘{n}β‘ z β x β‘{n}β‘ z"
},
{
"name": "Iris.OFE.equiv_eqv",
"content": "theorem equiv_eqv [ofe : OFE Ξ±] : Equivalence ofe.Equiv"
},
{
"name": "Iris.OFE.Equiv.symm",
"content": "@[symm] theorem Equiv.symm [OFE Ξ±] {x : Ξ±} : x β‘ y β y β‘ x"
},
{
"name": "Iris.OFE.Equiv.trans",
"content": "theorem Equiv.trans [OFE Ξ±] {x : Ξ±} : x β‘ y β y β‘ z β x β‘ z"
},
{
"name": "Iris.OFE.Equiv.dist",
"content": "theorem Equiv.dist [OFE Ξ±] {x : Ξ±} : x β‘ y β x β‘{n}β‘ y"
},
{
"name": "Iris.OFE.DistLater.symm",
"content": "@[symm] theorem DistLater.symm [OFE Ξ±] {n} {x : Ξ±} (h : DistLater n x y) : DistLater n y x"
},
{
"name": "Iris.OFE.DistLater.trans",
"content": "theorem DistLater.trans [OFE Ξ±] {n} {x : Ξ±} (h1 : DistLater n x y) (h2 : DistLater n y z) :\n DistLater n x z"
},
{
"name": "Iris.OFE.distLater_zero",
"content": "@[simp] theorem distLater_zero [OFE Ξ±] {x y : Ξ±} : DistLater 0 x y"
},
{
"name": "Iris.OFE.distLater_succ",
"content": "theorem distLater_succ [OFE Ξ±] {n} {x y : Ξ±} : DistLater n.succ x y β x β‘{n}β‘ y"
},
{
"name": "Iris.OFE.Contractive.zero",
"content": "@[simp] theorem Contractive.zero [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) [Contractive f] {x y} :\n f x β‘{0}β‘ f y"
},
{
"name": "Iris.OFE.Contractive.succ",
"content": "theorem Contractive.succ [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) [Contractive f] {n x y}\n (h : x β‘{n}β‘ y) : f x β‘{n.succ}β‘ f y"
},
{
"name": "Iris.fixpoint_unfold",
"content": "theorem fixpoint_unfold [COFE Ξ±] [Inhabited Ξ±] (f : Ξ± -c> Ξ±) :\n fixpoint f β‘ f (fixpoint f)"
},
{
"name": "Iris.fixpoint_unique",
"content": "theorem fixpoint_unique [COFE Ξ±] [Inhabited Ξ±] {f : Ξ± -c> Ξ±} {x : Ξ±} (H : x β‘ f x) :\n x β‘ fixpoint f"
}
] | namespace Iris
class OFE (Ξ± : Type _) where
Equiv : Ξ± β Ξ± β Prop
Dist : Nat β Ξ± β Ξ± β Prop
dist_eqv : Equivalence (Dist n)
equiv_dist : Equiv x y β β n, Dist n x y
dist_lt : Dist n x y β m < n β Dist m x y
open OFE
scoped infix:40 " β‘ " => OFE.Equiv
scoped notation:40 x " β‘{" n "}β‘ " y:41 => OFE.Dist n x y
namespace OFE
class NonExpansive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) where
ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β f xβ β‘{n}β‘ f xβ
instance id_ne [OFE Ξ±] : NonExpansive (@id Ξ±) := β¨fun _ _ _ h => hβ©
class NonExpansiveβ [OFE Ξ±] [OFE Ξ²] [OFE Ξ³] (f : Ξ± β Ξ² β Ξ³) where
ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β β β¦yβ yββ¦, yβ β‘{n}β‘ yβ β f xβ yβ β‘{n}β‘ f xβ yβ
def DistLater [OFE Ξ±] (n : Nat) (x y : Ξ±) : Prop := β m, m < n β x β‘{m}β‘ y
class Contractive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) where
distLater_dist : DistLater n x y β f x β‘{n}β‘ f y
instance ne_of_contractive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) [Contractive f] : NonExpansive f where
ne := fun _ _ _ h => Contractive.distLater_dist (Dist.distLater h)
instance [OFE Ξ±] [OFE Ξ²] {x : Ξ²} : Contractive (fun _ : Ξ± => x) where
distLater_dist := fun _ => Dist.rfl
@[ext] structure Hom (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] where
f : Ξ± β Ξ²
ne : NonExpansive f
@[inherit_doc]
infixr:25 " -n> " => Hom
instance [OFE Ξ±] [OFE Ξ²] (f : Ξ± -n> Ξ²) : NonExpansive f := f.ne
@[ext] structure ContractiveHom (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] extends Hom Ξ± Ξ² where
[contractive : Contractive f]
ne := ne_of_contractive f
infixr:25 " -c> " => ContractiveHom
instance [OFE Ξ±] [OFE Ξ²] (f : Ξ± -c> Ξ²) : Contractive f := f.contractive
instance : OFE Unit where
Equiv _ _ := True
Dist _ _ _ := True
dist_eqv := β¨fun _ => β¨β©, id, fun _ => idβ©
equiv_dist := by admit /- proof elided -/
instance [OFE Ξ±] : OFE (ULift Ξ±) where
Equiv x y := x.down β‘ y.down
Dist n x y := x.down β‘{n}β‘ y.down
dist_eqv := InvImage.equivalence dist_eqv
equiv_dist := equiv_dist
dist_lt := dist_lt
instance [OFE Ξ±] : OFE (Option Ξ±) where
Equiv := Option.Forallβ Equiv
Dist n := Option.Forallβ (Dist n)
dist_eqv := Option.Forallβ.equivalence dist_eqv
equiv_dist {x y} := by admit /- proof elided -/
instance [OFE Ξ±] [OFE.Discrete Ξ±] : OFE.Discrete (Option Ξ±) where
discrete_0 {mx my} e :=
match mx, my with
| none, none => e
| none, some _ => e
| some _, none => e
| some x, some y => show x β‘ y from discrete_0 e
instance OFE.Option.some.ne [OFE Ξ±] : OFE.NonExpansive (some : Ξ± β Option Ξ±) := β¨fun _ _ _ => idβ©
instance Option.merge_ne [OFE Ξ±] {op : Ξ± β Ξ± β Ξ±} [NonExpansiveβ op] :
NonExpansiveβ (Option.merge op) where
ne n x1 x2 Hx y1 y2 Hy := by admit /- proof elided -/
instance [OFEFun (Ξ² : Ξ± β _)] : OFE ((x : Ξ±) β Ξ² x) where
Equiv f g := β x, f x β‘ g x
Dist n f g := β x, f x β‘{n}β‘ g x
dist_eqv := {
refl _ _ := dist_eqv.refl _
symm h _ := dist_eqv.symm (h _)
trans h1 h2 _ := dist_eqv.trans (h1 _) (h2 _)
}
equiv_dist {_ _} := by admit /- proof elided -/
instance [OFE Ξ±] [OFE Ξ²] : OFE (Ξ± -n> Ξ²) where
Equiv f g := f.f β‘ g.f
Dist n f g := f.f β‘{n}β‘ g.f
dist_eqv := {
refl _ := dist_eqv.refl _
symm h := dist_eqv.symm h
trans h1 h2 := dist_eqv.trans h1 h2
}
equiv_dist := equiv_dist
dist_lt := dist_lt
instance [OFE Ξ±] [OFE Ξ²] : OFE (Ξ± -c> Ξ²) where
Equiv f g := Equiv f.toHom g.toHom
Dist n f g := Dist n f.toHom g.toHom
dist_eqv := {
refl _ := dist_eqv.refl _
symm h := dist_eqv.symm h
trans h1 h2 := dist_eqv.trans h1 h2
}
equiv_dist := equiv_dist
dist_lt := dist_lt
instance [OFE Ξ±] [OFE Ξ²] : OFE (Ξ± Γ Ξ²) where
Equiv a b := a.1 β‘ b.1 β§ a.2 β‘ b.2
Dist n a b := a.1 β‘{n}β‘ b.1 β§ a.2 β‘{n}β‘ b.2
dist_eqv := {
refl _ := β¨dist_eqv.refl _, dist_eqv.refl _β©
symm h := β¨dist_eqv.symm h.1, dist_eqv.symm h.2β©
trans h1 h2 := β¨dist_eqv.trans h1.1 h2.1, dist_eqv.trans h1.2 h2.2β©
}
equiv_dist {_ _} := by admit /- proof elided -/
@[ext] structure Iso (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] where
hom : Ξ± -n> Ξ²
inv : Ξ² -n> Ξ±
hom_inv : hom (inv x) β‘ x
inv_hom : inv (hom x) β‘ x
instance [OFE Ξ±] [OFE Ξ²] (iso : Iso Ξ± Ξ²) : NonExpansive iso.hom := iso.hom.ne
instance [OFE Ξ±] [OFE Ξ²] (iso : Iso Ξ± Ξ²) : NonExpansive iso.inv := iso.inv.ne
def Iso.symm [OFE Ξ±] [OFE Ξ²] (iso : Iso Ξ± Ξ²) : Iso Ξ² Ξ± where
hom := iso.inv
inv := iso.hom
hom_inv := by admit /- proof elided -/
end OFE
structure Chain (Ξ± : Type _) [OFE Ξ±] where
chain : Nat β Ξ±
cauchy : n β€ i β chain i β‘{n}β‘ chain n
namespace Chain
end Chain
class IsCOFE (Ξ± : Type _) [OFE Ξ±] where
compl : Chain Ξ± β Ξ±
conv_compl {c : Chain Ξ±} : compl c β‘{n}β‘ c n
namespace COFE
end COFE
@[ext] structure LeibnizO (Ξ± : Type _) where
car : Ξ±
section DiscreteFunOF
open COFE
end DiscreteFunOF
section Option
variable [OFE Ξ±]
def optionChain (c : Chain (Option Ξ±)) (x : Ξ±) : Chain Ξ± :=
instance isCOFE_option [IsCOFE Ξ±] : IsCOFE (Option Ξ±) where
compl c := (c 0).map fun x => IsCOFE.compl (optionChain c x)
conv_compl {n} c := by admit /- proof elided -/
end Option
section OptionOF
open COFE
variable (F : OFunctorPre)
end OptionOF
section Fixpoint
def LimitPreserving [COFE Ξ±] (P : Ξ± β Prop) : Prop :=
β (c : Chain Ξ±), (β n, P (c n)) β P (COFE.compl c)
def Fixpoint.chain [OFE Ξ±] [Inhabited Ξ±] (f : Ξ± β Ξ±) [Contractive f] : Chain Ξ± where
chain n := Nat.repeat f (n + 1) default
cauchy {n} := by admit /- proof elided -/
def fixpoint [COFE Ξ±] [Inhabited Ξ±] (f : Ξ± β Ξ±) [Contractive f] : Ξ± :=
COFE.compl <| Fixpoint.chain f
nonrec abbrev OFE.ContractiveHom.fixpoint [COFE Ξ±] [Inhabited Ξ±] (f : Ξ± -c> Ξ±) : Ξ± := fixpoint f.f
instance OFE.ContractiveHom.fixpoint_ne [COFE Ξ±] [Inhabited Ξ±] :
NonExpansive (ContractiveHom.fixpoint (Ξ± := Ξ±)) where
ne n f1 f2 H := by admit /- proof elided -/ | @[elab_as_elim]
theorem OFE.ContractiveHom.fixpoint_ind [COFE Ξ±] [Inhabited Ξ±] (f : Ξ± -c> Ξ±)
(P : Ξ± β Prop) (HProper : β A B : Ξ±, A β‘ B β P A β P B) (x : Ξ±) (Hbase : P x)
(Hind : β x, P x β P (f x)) (Hlim : LimitPreserving P) :
P f.fixpoint := | := by
let chain : Chain Ξ± := by
refine β¨fun i => Nat.repeat f (i + 1) x, fun {n i} H => ?_β©
induction n generalizing i with
| zero => simp [Nat.repeat]
| succ _ IH =>
cases i <;> simp at H
exact Contractive.succ _ <| IH H
refine HProper _ _ (fixpoint_unique (x := COFE.compl chain) ?_) ?_
Β· refine equiv_dist.mpr fun n => ?_
apply COFE.conv_compl.trans
refine .trans ?_ (f.ne.ne COFE.conv_compl).symm
induction n
Β· exact Contractive.zero f.f
Β· rename_i IH; apply Contractive.succ _ IH
Β· apply Hlim; intro n
induction n with
| zero => exact Hind (Nat.repeat f.f 0 x) Hbase
| succ _ IH => apply Hind (Nat.repeat f.f _ x) IH | 5 | 47 | true | Framework |
223 | Iris.BI.wand_iff_exists_persistently | theorem wand_iff_exists_persistently [BI PROP] [BIAffine PROP] {P Q : PROP} :
(P -β Q) β£β’ β R, R β <pers> (P β R β Q) | iris-lean | src/Iris/BI/DerivedLaws.lean | [
"import Iris.BI.Extensions",
"import Iris.Std.TC",
"import Iris.Std.Classes",
"import Iris.BI.BI",
"import src.Iris.Algebra.OFE",
"import src.Iris.BI.BI",
"import Iris.BI.Classes",
"import Iris.Std.Rewrite"
] | [
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "Option.merge",
"module": "Init.Data.Option.Basic"
},
{
"name": "id",
"module": "Init.Prelude"
},
{
"name": "Equivalence",
"module": "Init.Core"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "m",
"module": "QqTest.matching"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Bool",
"module": "Init.Prelude"
}
] | [
{
"name": "macro \"β\" xs:explicitBinders \", \" b:term : term => do",
"content": "macro \"β\" xs:explicitBinders \", \" b:term : term => do\n return β¨β expandExplicitBinders ``BIBase.exists xs bβ©"
},
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y\n\nsyntax:max \"<pers> \" term:40 : term"
},
{
"name": "macro:25 P:term:29 \" β’ \" Q:term:25 : term => ``(BIBase.Entai",
"content": "macro:25 P:term:29 \" β’ \" Q:term:25 : term => ``(BIBase.Entails iprop($P) iprop($Q))\n\ndelab_rule BIBase.Entails\n | `($_ $P $Q) => do ``($(β unpackIprop P) β’ $(β unpackIprop Q))"
},
{
"name": "macro:25 P:term:29 \" β£β’ \" Q:term:29 : term => ``(BiEntails i",
"content": "macro:25 P:term:29 \" β£β’ \" Q:term:29 : term => ``(BiEntails iprop($P) iprop($Q))\n\ndelab_rule BIBase.Entails\n | `($_ iprop(emp) $P) => do ``(β’ $(β unpackIprop P))\n\ndelab_rule BIBase.BiEntails\n | `($_ $P $Q) => do ``($(β unpackIprop P) β£β’ $(β unpackIprop Q))\n\nsyntax \"β\" term \"β\" : term\n\nsyntax:max \"β· \" term:40 : term\n\nsyntax:max \"<absorb> \" term:40 : term"
},
{
"name": "macro:max \"iprop(\" P:term \" : \" t:term \")\" : term => `((ipro",
"content": "macro:max \"iprop(\" P:term \" : \" t:term \")\" : term => `((iprop($P) : $t))\n\nsyntax:max \"iprop(\" term \")\" : term\n\nsyntax:max \"<affine> \" term:40 : term\n\nsyntax:max \"β‘ \" term:40 : term"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(term($t))) => pure t\n | `(iprop($t)) => pure t"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(($P))) => ``((iprop($P)))\n | `(iprop(if $c then $t else $e)) => ``(if $c then iprop($t) else iprop($e))\n | `(iprop(($P : $t))) => ``((iprop($P) : $t))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(emp)) => ``(BIBase.emp)\n | `(iprop(β$Οβ)) => ``(BIBase.pure $Ο)\n | `(iprop($P β§ $Q)) => ``(BIBase.and iprop($P) iprop($Q))\n | `(iprop($P β¨ $Q)) => ``(BIBase.or iprop($P) iprop($Q))\n | `(iprop($P β $Q)) => ``(BIBase.imp iprop($P) iprop($Q))\n | `(iprop(β $xs, $Ξ¨)) => do expandExplicitBinders ``BIBase.exists xs (β ``(iprop($Ξ¨)))\n | `(iprop($P β $Q)) => ``(BIBase.sep iprop($P) iprop($Q))\n | `(iprop($P -β $Q)) => ``(BIBase.wand iprop($P) iprop($Q))\n | `(iprop(<pers> $P)) => ``(BIBase.persistently iprop($P))\n | `(iprop(β· $P)) => ``(BIBase.later iprop($P))\n\ndelab_rule BIBase.emp\n | `($_) => ``(iprop($(mkIdent `emp)))\ndelab_rule BIBase.pure\n | `($_ $Ο) => ``(iprop(β$Οβ))\ndelab_rule BIBase.and\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β§ $(β unpackIprop Q)))\ndelab_rule BIBase.or\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β¨ $(β unpackIprop Q)))\ndelab_rule BIBase.imp\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule BIBase.forall\n | `($_ fun $x:ident => iprop(β $y:ident $[$z:ident]*, $Ξ¨)) => do\n ``(iprop(β $x:ident $y:ident $[$z:ident]*, $Ξ¨))\n | `($_ fun $x:ident => $Ξ¨) => do ``(iprop(β $x:ident, $(β unpackIprop Ξ¨)))\ndelab_rule BIBase.exists\n | `($_ fun $x:ident => iprop(β $y:ident $[$z:ident]*, $Ξ¨)) => do\n ``(iprop(β $x:ident $y:ident $[$z:ident]*, $Ξ¨))\n | `($_ fun $x:ident => $Ξ¨) => do ``(iprop(β $x:ident, $(β unpackIprop Ξ¨)))\ndelab_rule BIBase.sep\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule BIBase.wand\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) -β $(β unpackIprop Q)))\ndelab_rule BIBase.persistently\n | `($_ $P) => do ``(iprop(<pers> $(β unpackIprop P)))\n\ndelab_rule BIBase.pure\n | `($_ True) => ``(iprop($(mkIdent `True)))\n | `($_ False) => ``(iprop($(mkIdent `False)))\ndelab_rule BIBase.imp\n | `($_ $P iprop(False)) => do ``(iprop(Β¬$(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β _%$tk, $Ξ¨)) => ``(BIBase.forall (fun _%$tk => iprop($Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $x:ident, $Ξ¨)) => ``(BIBase.forall (fun $x => iprop($Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β (_%$tk : $t), $Ξ¨)) => ``(BIBase.forall (fun (_%$tk : $t) => iprop($Ξ¨)))\n | `(iprop(β (_%$tk $xs* : $t), $Ξ¨)) =>\n ``(BIBase.forall (fun (_%$tk : $t) => iprop(β ($xs* : $t), $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β ($x:ident : $t), $Ξ¨)) => ``(BIBase.forall (fun ($x : $t) => iprop($Ξ¨)))\n | `(iprop(β ($x:ident $xs* : $t), $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop(β ($xs* : $t), $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β {_%$tk : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun {_%$tk : $t} => iprop($Ξ¨)))\n | `(iprop(β {_%$tk $xs* : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun {_%$tk : $t} => iprop(β {$xs* : $t}, $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β {$x:ident : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop($Ξ¨)))\n | `(iprop(β {$x:ident $xs* : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop(β {$xs* : $t}, $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $x $y $xs*, $Ξ¨)) => ``(iprop(β $x, β $y $xs*, $Ξ¨))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(True)) => ``(BIBase.pure True)\n | `(iprop(False)) => ``(BIBase.pure False)\n | `(iprop(Β¬$P)) => ``(iprop($P β False))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop($P β $Q)) => ``(iff iprop($P) iprop($Q))\n | `(iprop($P β-β $Q)) => ``(wandIff iprop($P) iprop($Q))\n\ndelab_rule iff\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule wandIff\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β-β $(β unpackIprop Q)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(<affine> $P)) => ``(affinely iprop($P))\n | `(iprop(<absorb> $P)) => ``(absorbingly iprop($P))\n\ndelab_rule affinely\n | `($_ $P) => do ``(iprop(<affine> $(β unpackIprop P)))\ndelab_rule absorbingly\n | `($_ $P) => do ``(iprop(<absorb> $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β‘ $P)) => ``(intuitionistically iprop($P))\n\ndelab_rule intuitionistically\n | `($_ $P) => do ``(iprop(β‘ $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(<pers>?$p $P)) => ``(persistentlyIf $p iprop($P))\n | `(iprop(<affine>?$p $P)) => ``(affinelyIf $p iprop($P))\n | `(iprop(<absorb>?$p $P)) => ``(absorbinglyIf $p iprop($P))\n | `(iprop(β‘?$p $P)) => ``(intuitionisticallyIf $p iprop($P))\n\ndelab_rule persistentlyIf\n | `($_ $p $P) => do ``(iprop(<pers>?$p $(β unpackIprop P)))\ndelab_rule affinelyIf\n | `($_ $p $P) => do ``(iprop(<affine>?$p $(β unpackIprop P)))\ndelab_rule absorbinglyIf\n | `($_ $p $P) => do ``(iprop(<absorb>?$p $(β unpackIprop P)))\ndelab_rule intuitionisticallyIf\n | `($_ $p $P) => do ``(iprop(β‘?$p $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β·^[$n] $P)) => ``(laterN $n iprop($P))\n\ndelab_rule laterN\n | `($_ $n $P) => do ``(iprop(β·^[$n] $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $P)) => ``(except0 iprop($P))\n\ndelab_rule except0\n | `($_ $P) => do ``(iprop(β $(β unpackIprop P)))"
},
{
"name": "LawfulBigOp",
"content": "class LawfulBigOp (f : PROP β PROP β PROP) (unit : outParam PROP)\n (eq : outParam (PROP β PROP β Prop)) where\n refl : eq a a\n symm : eq a b β eq b a\n trans : eq a b β eq b c β eq a c\n comm : eq (f a b) (f b a)\n assoc : eq (f (f a b) c) (f a (f b c))\n left_id : eq (f unit a) a\n congr_l : eq a a' β eq (f a b) (f a' b)"
},
{
"name": "BIBase",
"content": "class BIBase (PROP : Type u) where\n Entails : PROP β PROP β Prop\n emp : PROP\n pure : Prop β PROP\n and : PROP β PROP β PROP\n or : PROP β PROP β PROP\n imp : PROP β PROP β PROP\n sForall : (PROP β Prop) β PROP\n sExists : (PROP β Prop) β PROP\n sep : PROP β PROP β PROP\n wand : PROP β PROP β PROP\n persistently : PROP β PROP\n later : PROP β PROP"
},
{
"name": "BI",
"content": "class BI (PROP : Type _) extends COFE PROP, BI.BIBase PROP where\n Equiv P Q := P β£β’ Q\n\n entails_preorder : Preorder Entails\n equiv_iff {P Q : PROP} : (P β‘ Q) β P β£β’ Q := by admit /- proof elided -/"
},
{
"name": "liftRel",
"content": "def liftRel (R : Ξ± β Ξ² β Prop) (A : Ξ± β Prop) (B : Ξ² β Prop) : Prop :=\n (β a, A a β β b, B b β§ R a b) β§ (β b, B b β β a, A a β§ R a b)"
},
{
"name": "Preorder",
"content": "class Preorder (R : Relation Ξ±) extends Reflexive R, Transitive R"
},
{
"name": "Reflexive",
"content": "class Reflexive (R : Relation Ξ±) where\n refl {x : Ξ±} : R x x"
},
{
"name": "Relation",
"content": "abbrev Relation (Ξ± : Type _) := Ξ± β Ξ± β Prop"
},
{
"name": "Transitive",
"content": "class Transitive (R : Relation Ξ±) where\n trans {x y z : Ξ±} : R x y β R y z β R x z"
},
{
"name": "NonExpansiveβ",
"content": "class NonExpansiveβ [OFE Ξ±] [OFE Ξ²] [OFE Ξ³] (f : Ξ± β Ξ² β Ξ³) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β β β¦yβ yββ¦, yβ β‘{n}β‘ yβ β f xβ yβ β‘{n}β‘ f xβ yβ"
},
{
"name": "OFE.ContractiveHom.fixpoint_ne",
"content": "instance OFE.ContractiveHom.fixpoint_ne [COFE Ξ±] [Inhabited Ξ±] :\n NonExpansive (ContractiveHom.fixpoint (Ξ± := Ξ±)) where\n ne n f1 f2 H := by admit /- proof elided -/"
},
{
"name": "ContractiveHom",
"content": "@[ext] structure ContractiveHom (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] extends Hom Ξ± Ξ² where\n [contractive : Contractive f]\n ne := ne_of_contractive f"
},
{
"name": "OFE.Option.some.ne",
"content": "instance OFE.Option.some.ne [OFE Ξ±] : OFE.NonExpansive (some : Ξ± β Option Ξ±) := β¨fun _ _ _ => idβ©"
},
{
"name": "Option.merge_ne",
"content": "instance Option.merge_ne [OFE Ξ±] {op : Ξ± β Ξ± β Ξ±} [NonExpansiveβ op] :\n NonExpansiveβ (Option.merge op) where\n ne n x1 x2 Hx y1 y2 Hy := by admit /- proof elided -/"
},
{
"name": "NonExpansive",
"content": "class NonExpansive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β f xβ β‘{n}β‘ f xβ"
},
{
"name": "COFE.OFunctor.constOF_RFunctor",
"content": "instance COFE.OFunctor.constOF_RFunctor [CMRA B] : RFunctor (constOF B) where\n map f g := by admit /- proof elided -/"
},
{
"name": "IsCOFE",
"content": "class IsCOFE (Ξ± : Type _) [OFE Ξ±] where\n compl : Chain Ξ± β Ξ±\n conv_compl {c : Chain Ξ±} : compl c β‘{n}β‘ c n"
},
{
"name": "Chain",
"content": "structure Chain (Ξ± : Type _) [OFE Ξ±] where\n chain : Nat β Ξ±\n cauchy : n β€ i β chain i β‘{n}β‘ chain n"
},
{
"name": "BIAffine",
"content": "class BIAffine (PROP : Type _) [BI PROP] where\n affine (P : PROP) : Affine P"
},
{
"name": "Affine",
"content": "class Affine [BI PROP] (P : PROP) where\n affine : P β’ emp"
},
{
"name": "Absorbing",
"content": "class Absorbing [BI PROP] (P : PROP) where\n absorbing : <absorb> P β’ P"
},
{
"name": "inductive",
"content": "class inductive TCOr (T U : Sort _)\n | l [t : T] : TCOr T U\n | r [u : U] : TCOr T U"
},
{
"name": "intuitionistically",
"content": "def intuitionistically [BIBase PROP] (P : PROP) : PROP := iprop(<affine> <pers> P)"
},
{
"name": "bigAnd",
"content": "def bigAnd [BIBase PROP] (Ps : List PROP) : PROP := bigOp and iprop(True) Ps"
},
{
"name": "bigOp",
"content": "def bigOp (f : PROP β PROP β PROP) (unit : PROP) : List PROP β PROP\n | [] => unit\n | [P] => P\n | P :: Ps => f P (bigOp f unit Ps)"
},
{
"name": "absorbingly",
"content": "def absorbingly [BIBase PROP] (P : PROP) : PROP := iprop(True β P)"
},
{
"name": "BiEntails",
"content": "structure BiEntails [BIBase PROP] (P Q : PROP) where\n mp : P β’ Q\n mpr : Q β’ P"
},
{
"name": "persistentlyIf",
"content": "def persistentlyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then <pers> P else P)"
},
{
"name": "intuitionisticallyIf",
"content": "def intuitionisticallyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then β‘ P else P)"
},
{
"name": "bigSep",
"content": "def bigSep [BIBase PROP] (Ps : List PROP) : PROP := bigOp sep iprop(emp) Ps"
},
{
"name": "affinely",
"content": "def affinely [BIBase PROP] (P : PROP) : PROP := iprop(emp β§ P)"
},
{
"name": "bigOr",
"content": "def bigOr [BIBase PROP] (Ps : List PROP) : PROP := bigOp or iprop(False) Ps"
},
{
"name": "absorbinglyIf",
"content": "def absorbinglyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then <absorb> P else P)"
},
{
"name": "affinelyIf",
"content": "def affinelyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then <affine> P else P)"
},
{
"name": "wandIff",
"content": "def wandIff [BIBase PROP] (P Q : PROP) : PROP := iprop((P -β Q) β§ (Q -β P))"
},
{
"name": "scoped infix:40 \" β‘ \" => OFE.Equiv",
"content": "scoped infix:40 \" β‘ \" => OFE.Equiv"
},
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y"
},
{
"name": "infixr:25 \" -c> \" => ContractiveHom",
"content": "infixr:25 \" -c> \" => ContractiveHom"
},
{
"name": "notation:40 \"[β§] \" Ps:max => bigAnd Ps",
"content": "notation:40 \"[β§] \" Ps:max => bigAnd Ps"
},
{
"name": "notation:40 \"[β¨] \" Ps:max => bigOr Ps",
"content": "notation:40 \"[β¨] \" Ps:max => bigOr Ps"
},
{
"name": "notation:40 \"[β] \" Ps:max => bigSep Ps",
"content": "notation:40 \"[β] \" Ps:max => bigSep Ps"
}
] | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "Dist.trans",
"content": "theorem Dist.trans [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ y β y β‘{n}β‘ z β x β‘{n}β‘ z"
},
{
"name": "BIBase.BiEntails.trans",
"content": "theorem BIBase.BiEntails.trans [BI PROP] {P Q R : PROP} (h1 : P β£β’ Q) (h2 : Q β£β’ R) : P β£β’ R"
},
{
"name": "BIBase.Entails.trans",
"content": "theorem BIBase.Entails.trans [BI PROP] {P Q R : PROP} (h1 : P β’ Q) (h2 : Q β’ R) : P β’ R"
},
{
"name": "Equiv.trans",
"content": "theorem Equiv.trans [OFE Ξ±] {x : Ξ±} : x β‘ y β y β‘ z β x β‘ z"
},
{
"name": "equiv_eqv",
"content": "theorem equiv_eqv [ofe : OFE Ξ±] : Equivalence ofe.Equiv"
},
{
"name": "Dist.symm",
"content": "@[symm] theorem Dist.symm [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ y β y β‘{n}β‘ x"
},
{
"name": "Dist.rfl",
"content": "@[simp, refl] theorem Dist.rfl [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ x"
},
{
"name": "DistLater.trans",
"content": "theorem DistLater.trans [OFE Ξ±] {n} {x : Ξ±} (h1 : DistLater n x y) (h2 : DistLater n y z) :\n DistLater n x z"
}
] | [] | [
{
"name": "Iris.BI.and_elim_l'",
"content": "theorem and_elim_l' [BI PROP] {P Q R : PROP} (h : P β’ R) : P β§ Q β’ R"
},
{
"name": "Iris.BI.and_elim_r'",
"content": "theorem and_elim_r' [BI PROP] {P Q R : PROP} (h : Q β’ R) : P β§ Q β’ R"
},
{
"name": "Iris.BI.imp_elim'",
"content": "theorem imp_elim' [BI PROP] {P Q R : PROP} (h : Q β’ P β R) : P β§ Q β’ R"
},
{
"name": "Iris.BI.imp_elim_r",
"content": "theorem imp_elim_r [BI PROP] {P Q : PROP} : P β§ (P β Q) β’ Q"
},
{
"name": "Iris.BI.true_intro",
"content": "theorem true_intro [BI PROP] {P : PROP} : P β’ True"
},
{
"name": "Iris.BI.and_mono",
"content": "@[rw_mono_rule]\ntheorem and_mono [BI PROP] {P P' Q Q' : PROP} (h1 : P β’ Q) (h2 : P' β’ Q') : P β§ P' β’ Q β§ Q'"
},
{
"name": "Iris.BI.and_mono_r",
"content": "theorem and_mono_r [BI PROP] {P Q Q' : PROP} (h : Q β’ Q') : P β§ Q β’ P β§ Q'"
},
{
"name": "Iris.BI.exists_intro",
"content": "theorem exists_intro [BI PROP] {Ξ¨ : Ξ± β PROP} (a : Ξ±) : Ξ¨ a β’ β a, Ξ¨ a"
},
{
"name": "Iris.BI.exists_elim",
"content": "theorem exists_elim [BI PROP] {Ξ¦ : Ξ± β PROP} {Q : PROP} (h : β a, Ξ¦ a β’ Q) : (β a, Ξ¦ a) β’ Q"
},
{
"name": "Iris.BI.sep_mono_l",
"content": "theorem sep_mono_l [BI PROP] {P P' Q : PROP} (h : P β’ P') : P β Q β’ P' β Q"
},
{
"name": "Iris.BI.sep_mono_r",
"content": "theorem sep_mono_r [BI PROP] {P Q Q' : PROP} (h : Q β’ Q') : P β Q β’ P β Q'"
},
{
"name": "Iris.BI.sep_congr",
"content": "@[rw_mono_rule]\ntheorem sep_congr [BI PROP] {P P' Q Q' : PROP} (h1 : P β£β’ Q) (h2 : P' β£β’ Q') :\n (P β P') β£β’ (Q β Q')"
},
{
"name": "Iris.BI.sep_congr_l",
"content": "theorem sep_congr_l [BI PROP] {P P' Q : PROP} (h : P β£β’ P') : P β Q β£β’ P' β Q"
},
{
"name": "Iris.BI.sep_congr_r",
"content": "theorem sep_congr_r [BI PROP] {P Q Q' : PROP} (h : Q β£β’ Q') : P β Q β£β’ P β Q'"
},
{
"name": "Iris.BI.sep_comm",
"content": "theorem sep_comm [BI PROP] {P Q : PROP} : P β Q β£β’ Q β P"
},
{
"name": "Iris.BI.sep_assoc",
"content": "theorem sep_assoc [BI PROP] {P Q R : PROP} : (P β Q) β R β£β’ P β Q β R"
},
{
"name": "Iris.BI.sep_emp",
"content": "theorem sep_emp [BI PROP] {P : PROP} : P β emp β£β’ P"
},
{
"name": "Iris.BI.true_sep_2",
"content": "theorem true_sep_2 [BI PROP] {P : PROP} : P β’ True β P"
},
{
"name": "Iris.BI.wand_intro'",
"content": "theorem wand_intro' [BI PROP] {P Q R : PROP} (h : Q β P β’ R) : P β’ Q -β R"
},
{
"name": "Iris.BI.wand_elim'",
"content": "theorem wand_elim' [BI PROP] {P Q R : PROP} (h : Q β’ P -β R) : P β Q β’ R"
},
{
"name": "Iris.BI.wand_elim_r",
"content": "theorem wand_elim_r [BI PROP] {P Q : PROP} : P β (P -β Q) β’ Q"
},
{
"name": "Iris.BI.absorbingly_intro",
"content": "theorem absorbingly_intro [BI PROP] {P : PROP} : P β’ <absorb> P"
},
{
"name": "Iris.BI.absorbingly_pure",
"content": "theorem absorbingly_pure {Ο : Prop} [BI PROP] : <absorb> βΟβ β£β’ (βΟβ : PROP)"
},
{
"name": "Iris.BI.sep_elim_l",
"content": "theorem sep_elim_l [BI PROP] {P Q : PROP} : [TCOr (Affine Q) (Absorbing P)] β P β Q β’ P\n | TCOr.l => (sep_mono_r affine).trans sep_emp.1\n | TCOr.r => (sep_mono_r true_intro).trans <| sep_comm.1.trans absorbing"
},
{
"name": "Iris.BI.sep_elim_r",
"content": "theorem sep_elim_r [BI PROP] {P Q : PROP} [TCOr (Affine P) (Absorbing Q)] : P β Q β’ Q"
},
{
"name": "Iris.BI.sep_and",
"content": "theorem sep_and [BI PROP] {P Q : PROP}\n [TCOr (Affine P) (Absorbing Q)] [TCOr (Affine Q) (Absorbing P)] : P β Q β’ P β§ Q"
},
{
"name": "Iris.BI.true_sep",
"content": "theorem true_sep [BI PROP] {P : PROP} [Absorbing P] : True β P β£β’ P"
},
{
"name": "Iris.BI.sep_true",
"content": "theorem sep_true [BI PROP] {P : PROP} [Absorbing P] : P β True β£β’ P"
},
{
"name": "Iris.BI.persistently_absorb_r",
"content": "theorem persistently_absorb_r [BI PROP] {P Q : PROP} : P β <pers> Q β’ <pers> Q"
},
{
"name": "Iris.BI.absorbingly_persistently",
"content": "theorem absorbingly_persistently [BI PROP] {P : PROP} : <absorb> <pers> P β£β’ <pers> P"
},
{
"name": "Iris.BI.persistently_emp_intro",
"content": "theorem persistently_emp_intro [BI PROP] {P : PROP} : P β’ <pers> emp"
},
{
"name": "Iris.BI.persistently_emp",
"content": "theorem persistently_emp [BI PROP] : <pers> (emp : PROP) β£β’ True"
},
{
"name": "Iris.BI.persistently_true",
"content": "theorem persistently_true [BI PROP] : <pers> (True : PROP) β£β’ True"
},
{
"name": "Iris.BI.persistently_elim",
"content": "theorem persistently_elim [BI PROP] {P : PROP} [Absorbing P] : <pers> P β’ P"
},
{
"name": "Iris.BI.persistently_idem",
"content": "theorem persistently_idem [BI PROP] {P : PROP} : <pers> <pers> P β£β’ <pers> P"
},
{
"name": "Iris.BI.persistently_intro'",
"content": "theorem persistently_intro' [BI PROP] {P Q : PROP} (h : <pers> P β’ Q) : <pers> P β’ <pers> Q"
},
{
"name": "Iris.BI.persistently_pure",
"content": "theorem persistently_pure {Ο : Prop} [BI PROP] : <pers> βΟβ β£β’ (βΟβ : PROP)"
},
{
"name": "Iris.BI.and_persistently_imp_sep",
"content": "theorem and_persistently_imp_sep [BI PROP] {P Q : PROP} : P β§ <pers> Q β’ P β <pers> Q"
},
{
"name": "Iris.BI.and_persistently_iff_sep",
"content": "theorem and_persistently_iff_sep [BI PROP] [BIAffine PROP] {P Q : PROP} :\n P β§ <pers> Q β£β’ P β <pers> Q"
}
] | import Iris.BI.Classes
import Iris.BI.Extensions
import Iris.BI.BI
import Iris.Std.Classes
import Iris.Std.Rewrite
import Iris.Std.TC
namespace Iris.BI
open Iris.Std BI | theorem wand_iff_exists_persistently [BI PROP] [BIAffine PROP] {P Q : PROP} :
(P -β Q) β£β’ β R, R β <pers> (P β R β Q) := | := by
constructor
Β· refine (sep_true.2.trans ?_).trans (exists_intro iprop(P -β Q))
exact sep_mono_r <| persistently_pure.2.trans <| persistently_intro' <|
imp_intro <| (and_mono persistently_pure.1 wand_elim_r).trans and_elim_r
Β· exact exists_elim fun R => wand_intro' <| sep_assoc.2.trans <|
and_persistently_iff_sep.2.trans <| (and_mono_r persistently_elim).trans imp_elim_r | 6 | 89 | false | Framework |
224 | Iris.COFE.OFunctor.Fix.Impl.Tower.embed_up | theorem Tower.embed_up (x : A F k) :
Tower.embed (k+1) (up F k x) β‘ Tower.embed k x | iris-lean | src/Iris/Algebra/COFESolver.lean | [
"import Iris.Algebra.OFE"
] | [
{
"name": "Equivalence",
"module": "Init.Core"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "m",
"module": "QqTest.matching"
},
{
"name": "ULift",
"module": "Init.Prelude"
},
{
"name": "Unit",
"module": "Init.Prelude"
},
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "Option.merge",
"module": "Init.Data.Option.Basic"
},
{
"name": "id",
"module": "Init.Prelude"
},
{
"name": "Inhabited.default",
"module": "Init.Prelude"
},
{
"name": "k",
"module": "QqTest.matching"
},
{
"name": "Nat.succ",
"module": "Init.Prelude"
}
] | [
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y"
},
{
"name": "COFE.OFunctor.constOF_RFunctor",
"content": "instance COFE.OFunctor.constOF_RFunctor [CMRA B] : RFunctor (constOF B) where\n map f g := by admit /- proof elided -/"
},
{
"name": "OFE.ContractiveHom.fixpoint_ne",
"content": "instance OFE.ContractiveHom.fixpoint_ne [COFE Ξ±] [Inhabited Ξ±] :\n NonExpansive (ContractiveHom.fixpoint (Ξ± := Ξ±)) where\n ne n f1 f2 H := by admit /- proof elided -/"
},
{
"name": "IsCOFE",
"content": "class IsCOFE (Ξ± : Type _) [OFE Ξ±] where\n compl : Chain Ξ± β Ξ±\n conv_compl {c : Chain Ξ±} : compl c β‘{n}β‘ c n"
},
{
"name": "Chain",
"content": "structure Chain (Ξ± : Type _) [OFE Ξ±] where\n chain : Nat β Ξ±\n cauchy : n β€ i β chain i β‘{n}β‘ chain n"
},
{
"name": "Hom",
"content": "@[ext] structure Hom (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] where\n f : Ξ± β Ξ²\n ne : NonExpansive f"
},
{
"name": "ContractiveHom",
"content": "@[ext] structure ContractiveHom (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] extends Hom Ξ± Ξ² where\n [contractive : Contractive f]\n ne := ne_of_contractive f"
},
{
"name": "NonExpansive",
"content": "class NonExpansive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β f xβ β‘{n}β‘ f xβ"
},
{
"name": "OFE.Option.some.ne",
"content": "instance OFE.Option.some.ne [OFE Ξ±] : OFE.NonExpansive (some : Ξ± β Option Ξ±) := β¨fun _ _ _ => idβ©"
},
{
"name": "Option.merge_ne",
"content": "instance Option.merge_ne [OFE Ξ±] {op : Ξ± β Ξ± β Ξ±} [NonExpansiveβ op] :\n NonExpansiveβ (Option.merge op) where\n ne n x1 x2 Hx y1 y2 Hy := by admit /- proof elided -/"
},
{
"name": "NonExpansiveβ",
"content": "class NonExpansiveβ [OFE Ξ±] [OFE Ξ²] [OFE Ξ³] (f : Ξ± β Ξ² β Ξ³) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β β β¦yβ yββ¦, yβ β‘{n}β‘ yβ β f xβ yβ β‘{n}β‘ f xβ yβ"
},
{
"name": "Hom.comp",
"content": "protected def Hom.comp [OFE Ξ±] [OFE Ξ²] [OFE Ξ³] (g : Ξ² -n> Ξ³) (f : Ξ± -n> Ξ²) : Ξ± -n> Ξ³ where\n f := g.f β f.f\n ne.1 _ _ _ h := g.ne.1 (f.ne.1 h)"
},
{
"name": "scoped infix:40 \" β‘ \" => OFE.Equiv",
"content": "scoped infix:40 \" β‘ \" => OFE.Equiv"
},
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y"
},
{
"name": "@[inherit_doc]",
"content": "@[inherit_doc]\ninfixr:25 \" -n> \" => Hom"
},
{
"name": "infixr:25 \" -c> \" => ContractiveHom",
"content": "infixr:25 \" -c> \" => ContractiveHom"
},
{
"name": "@[inherit_doc]",
"content": "@[inherit_doc]\ninfixr:25 \" -C> \" => Hom"
}
] | [
{
"name": "congrArg",
"module": "Init.Prelude"
},
{
"name": "symm",
"module": "Mathlib.Order.Defs.Unbundled"
},
{
"name": "Nat.add_assoc",
"module": "Init.Data.Nat.Basic"
},
{
"name": "Nat.add_left_cancel",
"module": "Init.Data.Nat.Basic"
},
{
"name": "Nat.add_left_cancel_iff",
"module": "Init.Data.Nat.Lemmas"
},
{
"name": "Nat.add_right_comm",
"module": "Init.Data.Nat.Basic"
},
{
"name": "Nat.le_antisymm",
"module": "Init.Prelude"
},
{
"name": "Nat.le_of_succ_le",
"module": "Init.Data.Nat.Basic"
},
{
"name": "Nat.not_lt",
"module": "Init.Data.Nat.Basic"
}
] | [
{
"name": "exact",
"content": "theorem exact [BI PROP] (Q : PROP) : Q β’ Q"
}
] | [
{
"name": "Iris.COFE.OFunctor.Fix.Impl.A'",
"content": "def A' : Nat β Ξ£ Ξ± : Type u, COFE Ξ±\n | 0 => β¨ULift Unit, inferInstanceβ©\n | n+1 => let β¨A, _β© := A' n; β¨F A A, inferInstanceβ©"
},
{
"name": "Iris.COFE.OFunctor.Fix.Impl.A",
"content": "def A (n : Nat) : Type u := (A' F n).1"
},
{
"name": "Iris.COFE.OFunctor.Fix.Impl.up",
"content": "def up : β k, A F k -n> A F (k+1)\n | 0 => β¨fun _ => inh.default, β¨fun _ _ _ _ => .rflβ©β©\n | k+1 => map (down k) (up k)"
},
{
"name": "Iris.COFE.OFunctor.Fix.Impl.down",
"content": "def down : β k, A F (k+1) -n> A F k\n | 0 => β¨fun _ => β¨()β©, β¨fun _ _ _ _ => .rflβ©β©\n | k+1 => map (up k) (down k)"
},
{
"name": "Iris.COFE.OFunctor.Fix.Impl.Tower",
"content": "@[ext] structure Tower : Type u where\n val k : A F k\n protected down {k} : down F k (val (k+1)) β‘ val k"
},
{
"name": "Iris.COFE.OFunctor.Fix.Impl.upN",
"content": "def upN {k} : β n, A F k -n> A F (k + n)\n | 0 => .id\n | n+1 => (up F (k + n)).comp (upN n)"
},
{
"name": "Iris.COFE.OFunctor.Fix.Impl.downN",
"content": "def downN {k} : β n, A F (k + n) -n> A F k\n | 0 => .id\n | n+1 => (downN n).comp (down F (k + n))"
},
{
"name": "Iris.COFE.OFunctor.Fix.Impl.eqToHom",
"content": "def eqToHom (e : i = k) : A F i -n> A F k := e βΈ .id"
},
{
"name": "Iris.COFE.OFunctor.Fix.Impl.embed",
"content": "def embed : A F k -n> A F i :=\n if h : k β€ i then (eqToHom (Nat.add_sub_cancel' h)).comp (upN ..)\n else (downN ..).comp (eqToHom (Nat.add_sub_cancel' (Nat.le_of_not_ge h)).symm)"
},
{
"name": "Iris.COFE.OFunctor.Fix.Impl.Tower.embed",
"content": "protected def Tower.embed (k) : A F k -n> Tower F :="
}
] | [
{
"name": "Iris.COFE.OFunctor.Fix.Impl.down_up",
"content": "theorem down_up : β {k} x, down F k (up F k x) β‘ x\n | 0, β¨()β© => .rfl\n | _+1, _ => (map_comp ..).symm.trans <|\n (map_ne.eqv down_up down_up _).trans (map_id _)"
},
{
"name": "Iris.COFE.OFunctor.Fix.Impl.eqToHom_up",
"content": "theorem eqToHom_up {k k'} {x : A F k} (e : k = k') :\n eqToHom (congrArg Nat.succ e) (up F k x) = up F k' (eqToHom e x)"
}
] | import Iris.Algebra.OFE
namespace Iris.COFE.OFunctor
open OFE
variable {F : β Ξ± Ξ² [OFE Ξ±] [OFE Ξ²], Type u} [OFunctorContractive F]
variable [β Ξ± [COFE Ξ±], IsCOFE (F Ξ± Ξ±)]
variable [inh : Inhabited (F (ULift Unit) (ULift Unit))]
namespace Fix.Impl
variable (F) in
def A' : Nat β Ξ£ Ξ± : Type u, COFE Ξ±
| 0 => β¨ULift Unit, inferInstanceβ©
| n+1 => let β¨A, _β© := A' n; β¨F A A, inferInstanceβ©
variable (F) in
def A (n : Nat) : Type u := (A' F n).1
variable (F) in
def up : β k, A F k -n> A F (k+1)
| 0 => β¨fun _ => inh.default, β¨fun _ _ _ _ => .rflβ©β©
| k+1 => map (down k) (up k)
def down : β k, A F (k+1) -n> A F k
| 0 => β¨fun _ => β¨()β©, β¨fun _ _ _ _ => .rflβ©β©
| k+1 => map (up k) (down k)
end
open OFunctorContractive in exact match k with
| 0 => map_contractive.zero (x := (_, _)) (y := (_, _)) _ _
| k+1 => map_contractive.succ (x := (_, _)) (y := (_, _)) _ β¨up_down, up_downβ© _
variable (F) in
@[ext] structure Tower : Type u where
val k : A F k
protected down {k} : down F k (val (k+1)) β‘ val k
variable (F) in
def upN {k} : β n, A F k -n> A F (k + n)
| 0 => .id
| n+1 => (up F (k + n)).comp (upN n)
variable (F) in
def downN {k} : β n, A F (k + n) -n> A F k
| 0 => .id
| n+1 => (downN n).comp (down F (k + n))
def eqToHom (e : i = k) : A F i -n> A F k := e βΈ .id
def embed : A F k -n> A F i :=
if h : k β€ i then (eqToHom (Nat.add_sub_cancel' h)).comp (upN ..)
else (downN ..).comp (eqToHom (Nat.add_sub_cancel' (Nat.le_of_not_ge h)).symm)
protected def Tower.embed (k) : A F k -n> Tower F := | theorem Tower.embed_up (x : A F k) :
Tower.embed (k+1) (up F k x) β‘ Tower.embed k x := | := by
refine equiv_dist.2 fun n i => ?_
dsimp [Tower.embed, embed]; split <;> rename_i hβ
Β· simp [Nat.le_of_succ_le hβ]
suffices β a b (eβ : k + 1 + a = i) (eβ : k+b = i),
eqToHom eβ (upN F a (up F k x)) = eqToHom eβ (upN F b x) from this .. βΈ .rfl
rintro a b eq rfl
rw [Nat.add_right_comm, Nat.add_assoc, Nat.add_left_cancel_iff] at eq; subst b
show _ = up F (k + a) (upN F a x); clear hβ
induction a with
| zero => rfl
| succ a ih =>
dsimp [upN, Hom.comp]
rw [eqToHom_up (by omega : k + 1 + a = k + (a + 1))]; congr 1; apply ih
Β· split <;> rename_i hβ
Β· cases Nat.le_antisymm hβ (Nat.not_lt.1 hβ)
have {a b} {eβ : k+1 = k+a} {eβ : k+b = k+0} :
downN F a (eqToHom eβ (up F k x)) β‘{n}β‘ eqToHom eβ (upN F b x) := by
cases Nat.add_left_cancel eβ; cases Nat.add_left_cancel eβ
exact (down_up ..).dist
exact this
Β· dsimp [Hom.comp]
suffices β a b (eβ : k + 1 = i + a) (eβ : k = i + b),
downN F a (eqToHom eβ (up F k x)) β‘{n}β‘
downN F b (eqToHom eβ x) from this ..
rintro a b eq rfl; cases Nat.add_left_cancel (m := b+1) eq
exact (downN ..).ne.1 (down_up x).dist | 8 | 43 | false | Framework |
225 | Iris.not_add_le_self | theorem not_add_le_self {a b : Ξ±} : Β¬ a + b β€ a | iris-lean | src/Iris/Algebra/Frac.lean | [
"import Iris.Algebra.CMRA",
"import Iris.Algebra.OFE"
] | [
{
"name": "structure BitVec (w : Nat) where",
"module": ""
},
{
"name": "/-- Construct a `BitVec w` from a number less than `2^w`.",
"module": ""
},
{
"name": "O(1), because we use `Fin` as the internal representation of a bitvector. -/",
"module": ""
},
{
"name": "ofFin ::",
"module": ""
},
{
"name": "/-- Interpret a bitvector as a number less than `2^w`.",
"module": ""
},
{
"name": "O(1), because we use `Fin` as the internal representation of a bitvector. -/",
"module": ""
},
{
"name": "toFin : Fin (hPow 2 w)",
"module": ""
}
] | [
{
"name": "...",
"content": "..."
}
] | [
{
"name": "mt",
"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": "Iris.NumericFraction",
"content": "class NumericFraction (Ξ± : Type _) extends One Ξ±, Add Ξ±, LE Ξ±, LT Ξ± where\n add_comm : β a b : Ξ±, a + b = b + a\n add_assoc : β a b c : Ξ±, a + (b + c) = (a + b) + c\n add_left_cancel : β {a b c : Ξ±}, a + b = a + c β b = c\n le_def : β {a b : Ξ±}, a β€ b β a = b β¨ a < b\n lt_def : β {a b : Ξ±}, a < b β β c : Ξ±, a + c = b\n lt_irrefl : β {a : Ξ±}, Β¬a < a"
}
] | [
{
"name": "Iris.add_ne_self",
"content": "theorem add_ne_self {a b : Ξ±} : a + b β a"
},
{
"name": "Iris.not_add_lt_self",
"content": "theorem not_add_lt_self {a b : Ξ±} : Β¬a + b < a"
}
] | import Iris.Algebra.CMRA
import Iris.Algebra.OFE
namespace Iris
namespace Fraction
variable [Fraction Ξ±]
end Fraction
open Fraction OFE CMRA
section NumericFraction
class NumericFraction (Ξ± : Type _) extends One Ξ±, Add Ξ±, LE Ξ±, LT Ξ± where
add_comm : β a b : Ξ±, a + b = b + a
add_assoc : β a b c : Ξ±, a + (b + c) = (a + b) + c
add_left_cancel : β {a b c : Ξ±}, a + b = a + c β b = c
le_def : β {a b : Ξ±}, a β€ b β a = b β¨ a < b
lt_def : β {a b : Ξ±}, a < b β β c : Ξ±, a + c = b
lt_irrefl : β {a : Ξ±}, Β¬a < a
variable {Ξ±} [NumericFraction Ξ±]
open NumericFraction | theorem not_add_le_self {a b : Ξ±} : Β¬ a + b β€ a := | := fun H => by
obtain H | H := le_def.mp H
Β· exact add_ne_self H
Β· exact not_add_lt_self H | 3 | 4 | false | Framework |
226 | Iris.BI.imp_iff_exists_persistently | theorem imp_iff_exists_persistently [BI PROP] [BIAffine PROP] {P Q : PROP} :
(P β Q) β£β’ β R, R β§ <pers> (P β§ R -β Q) | iris-lean | src/Iris/BI/DerivedLaws.lean | [
"import Iris.BI.Extensions",
"import Iris.Std.TC",
"import Iris.Std.Classes",
"import Iris.BI.BI",
"import src.Iris.Algebra.OFE",
"import src.Iris.BI.BI",
"import Iris.BI.Classes",
"import Iris.Std.Rewrite"
] | [
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "Option.merge",
"module": "Init.Data.Option.Basic"
},
{
"name": "id",
"module": "Init.Prelude"
},
{
"name": "Equivalence",
"module": "Init.Core"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "m",
"module": "QqTest.matching"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Bool",
"module": "Init.Prelude"
}
] | [
{
"name": "macro \"β\" xs:explicitBinders \", \" b:term : term => do",
"content": "macro \"β\" xs:explicitBinders \", \" b:term : term => do\n return β¨β expandExplicitBinders ``BIBase.exists xs bβ©"
},
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y\n\nsyntax:max \"<pers> \" term:40 : term"
},
{
"name": "macro:25 P:term:29 \" β’ \" Q:term:25 : term => ``(BIBase.Entai",
"content": "macro:25 P:term:29 \" β’ \" Q:term:25 : term => ``(BIBase.Entails iprop($P) iprop($Q))\n\ndelab_rule BIBase.Entails\n | `($_ $P $Q) => do ``($(β unpackIprop P) β’ $(β unpackIprop Q))"
},
{
"name": "macro:25 P:term:29 \" β£β’ \" Q:term:29 : term => ``(BiEntails i",
"content": "macro:25 P:term:29 \" β£β’ \" Q:term:29 : term => ``(BiEntails iprop($P) iprop($Q))\n\ndelab_rule BIBase.Entails\n | `($_ iprop(emp) $P) => do ``(β’ $(β unpackIprop P))\n\ndelab_rule BIBase.BiEntails\n | `($_ $P $Q) => do ``($(β unpackIprop P) β£β’ $(β unpackIprop Q))\n\nsyntax \"β\" term \"β\" : term\n\nsyntax:max \"β· \" term:40 : term\n\nsyntax:max \"<affine> \" term:40 : term"
},
{
"name": "macro:max \"iprop(\" P:term \" : \" t:term \")\" : term => `((ipro",
"content": "macro:max \"iprop(\" P:term \" : \" t:term \")\" : term => `((iprop($P) : $t))\n\nsyntax:max \"iprop(\" term \")\" : term\n\nsyntax:max \"β‘ \" term:40 : term\n\nsyntax:max \"<absorb> \" term:40 : term"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(term($t))) => pure t\n | `(iprop($t)) => pure t"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(($P))) => ``((iprop($P)))\n | `(iprop(if $c then $t else $e)) => ``(if $c then iprop($t) else iprop($e))\n | `(iprop(($P : $t))) => ``((iprop($P) : $t))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(emp)) => ``(BIBase.emp)\n | `(iprop(β$Οβ)) => ``(BIBase.pure $Ο)\n | `(iprop($P β§ $Q)) => ``(BIBase.and iprop($P) iprop($Q))\n | `(iprop($P β¨ $Q)) => ``(BIBase.or iprop($P) iprop($Q))\n | `(iprop($P β $Q)) => ``(BIBase.imp iprop($P) iprop($Q))\n | `(iprop(β $xs, $Ξ¨)) => do expandExplicitBinders ``BIBase.exists xs (β ``(iprop($Ξ¨)))\n | `(iprop($P β $Q)) => ``(BIBase.sep iprop($P) iprop($Q))\n | `(iprop($P -β $Q)) => ``(BIBase.wand iprop($P) iprop($Q))\n | `(iprop(<pers> $P)) => ``(BIBase.persistently iprop($P))\n | `(iprop(β· $P)) => ``(BIBase.later iprop($P))\n\ndelab_rule BIBase.emp\n | `($_) => ``(iprop($(mkIdent `emp)))\ndelab_rule BIBase.pure\n | `($_ $Ο) => ``(iprop(β$Οβ))\ndelab_rule BIBase.and\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β§ $(β unpackIprop Q)))\ndelab_rule BIBase.or\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β¨ $(β unpackIprop Q)))\ndelab_rule BIBase.imp\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule BIBase.forall\n | `($_ fun $x:ident => iprop(β $y:ident $[$z:ident]*, $Ξ¨)) => do\n ``(iprop(β $x:ident $y:ident $[$z:ident]*, $Ξ¨))\n | `($_ fun $x:ident => $Ξ¨) => do ``(iprop(β $x:ident, $(β unpackIprop Ξ¨)))\ndelab_rule BIBase.exists\n | `($_ fun $x:ident => iprop(β $y:ident $[$z:ident]*, $Ξ¨)) => do\n ``(iprop(β $x:ident $y:ident $[$z:ident]*, $Ξ¨))\n | `($_ fun $x:ident => $Ξ¨) => do ``(iprop(β $x:ident, $(β unpackIprop Ξ¨)))\ndelab_rule BIBase.sep\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule BIBase.wand\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) -β $(β unpackIprop Q)))\ndelab_rule BIBase.persistently\n | `($_ $P) => do ``(iprop(<pers> $(β unpackIprop P)))\n\ndelab_rule BIBase.pure\n | `($_ True) => ``(iprop($(mkIdent `True)))\n | `($_ False) => ``(iprop($(mkIdent `False)))\ndelab_rule BIBase.imp\n | `($_ $P iprop(False)) => do ``(iprop(Β¬$(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β _%$tk, $Ξ¨)) => ``(BIBase.forall (fun _%$tk => iprop($Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $x:ident, $Ξ¨)) => ``(BIBase.forall (fun $x => iprop($Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β (_%$tk : $t), $Ξ¨)) => ``(BIBase.forall (fun (_%$tk : $t) => iprop($Ξ¨)))\n | `(iprop(β (_%$tk $xs* : $t), $Ξ¨)) =>\n ``(BIBase.forall (fun (_%$tk : $t) => iprop(β ($xs* : $t), $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β ($x:ident : $t), $Ξ¨)) => ``(BIBase.forall (fun ($x : $t) => iprop($Ξ¨)))\n | `(iprop(β ($x:ident $xs* : $t), $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop(β ($xs* : $t), $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β {_%$tk : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun {_%$tk : $t} => iprop($Ξ¨)))\n | `(iprop(β {_%$tk $xs* : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun {_%$tk : $t} => iprop(β {$xs* : $t}, $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β {$x:ident : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop($Ξ¨)))\n | `(iprop(β {$x:ident $xs* : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop(β {$xs* : $t}, $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $x $y $xs*, $Ξ¨)) => ``(iprop(β $x, β $y $xs*, $Ξ¨))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(True)) => ``(BIBase.pure True)\n | `(iprop(False)) => ``(BIBase.pure False)\n | `(iprop(Β¬$P)) => ``(iprop($P β False))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop($P β $Q)) => ``(iff iprop($P) iprop($Q))\n | `(iprop($P β-β $Q)) => ``(wandIff iprop($P) iprop($Q))\n\ndelab_rule iff\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule wandIff\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β-β $(β unpackIprop Q)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(<affine> $P)) => ``(affinely iprop($P))\n | `(iprop(<absorb> $P)) => ``(absorbingly iprop($P))\n\ndelab_rule affinely\n | `($_ $P) => do ``(iprop(<affine> $(β unpackIprop P)))\ndelab_rule absorbingly\n | `($_ $P) => do ``(iprop(<absorb> $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β‘ $P)) => ``(intuitionistically iprop($P))\n\ndelab_rule intuitionistically\n | `($_ $P) => do ``(iprop(β‘ $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(<pers>?$p $P)) => ``(persistentlyIf $p iprop($P))\n | `(iprop(<affine>?$p $P)) => ``(affinelyIf $p iprop($P))\n | `(iprop(<absorb>?$p $P)) => ``(absorbinglyIf $p iprop($P))\n | `(iprop(β‘?$p $P)) => ``(intuitionisticallyIf $p iprop($P))\n\ndelab_rule persistentlyIf\n | `($_ $p $P) => do ``(iprop(<pers>?$p $(β unpackIprop P)))\ndelab_rule affinelyIf\n | `($_ $p $P) => do ``(iprop(<affine>?$p $(β unpackIprop P)))\ndelab_rule absorbinglyIf\n | `($_ $p $P) => do ``(iprop(<absorb>?$p $(β unpackIprop P)))\ndelab_rule intuitionisticallyIf\n | `($_ $p $P) => do ``(iprop(β‘?$p $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β·^[$n] $P)) => ``(laterN $n iprop($P))\n\ndelab_rule laterN\n | `($_ $n $P) => do ``(iprop(β·^[$n] $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $P)) => ``(except0 iprop($P))\n\ndelab_rule except0\n | `($_ $P) => do ``(iprop(β $(β unpackIprop P)))"
},
{
"name": "LawfulBigOp",
"content": "class LawfulBigOp (f : PROP β PROP β PROP) (unit : outParam PROP)\n (eq : outParam (PROP β PROP β Prop)) where\n refl : eq a a\n symm : eq a b β eq b a\n trans : eq a b β eq b c β eq a c\n comm : eq (f a b) (f b a)\n assoc : eq (f (f a b) c) (f a (f b c))\n left_id : eq (f unit a) a\n congr_l : eq a a' β eq (f a b) (f a' b)"
},
{
"name": "BIBase",
"content": "class BIBase (PROP : Type u) where\n Entails : PROP β PROP β Prop\n emp : PROP\n pure : Prop β PROP\n and : PROP β PROP β PROP\n or : PROP β PROP β PROP\n imp : PROP β PROP β PROP\n sForall : (PROP β Prop) β PROP\n sExists : (PROP β Prop) β PROP\n sep : PROP β PROP β PROP\n wand : PROP β PROP β PROP\n persistently : PROP β PROP\n later : PROP β PROP"
},
{
"name": "BI",
"content": "class BI (PROP : Type _) extends COFE PROP, BI.BIBase PROP where\n Equiv P Q := P β£β’ Q\n\n entails_preorder : Preorder Entails\n equiv_iff {P Q : PROP} : (P β‘ Q) β P β£β’ Q := by admit /- proof elided -/"
},
{
"name": "liftRel",
"content": "def liftRel (R : Ξ± β Ξ² β Prop) (A : Ξ± β Prop) (B : Ξ² β Prop) : Prop :=\n (β a, A a β β b, B b β§ R a b) β§ (β b, B b β β a, A a β§ R a b)"
},
{
"name": "Preorder",
"content": "class Preorder (R : Relation Ξ±) extends Reflexive R, Transitive R"
},
{
"name": "Reflexive",
"content": "class Reflexive (R : Relation Ξ±) where\n refl {x : Ξ±} : R x x"
},
{
"name": "Relation",
"content": "abbrev Relation (Ξ± : Type _) := Ξ± β Ξ± β Prop"
},
{
"name": "Transitive",
"content": "class Transitive (R : Relation Ξ±) where\n trans {x y z : Ξ±} : R x y β R y z β R x z"
},
{
"name": "NonExpansiveβ",
"content": "class NonExpansiveβ [OFE Ξ±] [OFE Ξ²] [OFE Ξ³] (f : Ξ± β Ξ² β Ξ³) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β β β¦yβ yββ¦, yβ β‘{n}β‘ yβ β f xβ yβ β‘{n}β‘ f xβ yβ"
},
{
"name": "OFE.ContractiveHom.fixpoint_ne",
"content": "instance OFE.ContractiveHom.fixpoint_ne [COFE Ξ±] [Inhabited Ξ±] :\n NonExpansive (ContractiveHom.fixpoint (Ξ± := Ξ±)) where\n ne n f1 f2 H := by admit /- proof elided -/"
},
{
"name": "ContractiveHom",
"content": "@[ext] structure ContractiveHom (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] extends Hom Ξ± Ξ² where\n [contractive : Contractive f]\n ne := ne_of_contractive f"
},
{
"name": "OFE.Option.some.ne",
"content": "instance OFE.Option.some.ne [OFE Ξ±] : OFE.NonExpansive (some : Ξ± β Option Ξ±) := β¨fun _ _ _ => idβ©"
},
{
"name": "Option.merge_ne",
"content": "instance Option.merge_ne [OFE Ξ±] {op : Ξ± β Ξ± β Ξ±} [NonExpansiveβ op] :\n NonExpansiveβ (Option.merge op) where\n ne n x1 x2 Hx y1 y2 Hy := by admit /- proof elided -/"
},
{
"name": "NonExpansive",
"content": "class NonExpansive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β f xβ β‘{n}β‘ f xβ"
},
{
"name": "COFE.OFunctor.constOF_RFunctor",
"content": "instance COFE.OFunctor.constOF_RFunctor [CMRA B] : RFunctor (constOF B) where\n map f g := by admit /- proof elided -/"
},
{
"name": "IsCOFE",
"content": "class IsCOFE (Ξ± : Type _) [OFE Ξ±] where\n compl : Chain Ξ± β Ξ±\n conv_compl {c : Chain Ξ±} : compl c β‘{n}β‘ c n"
},
{
"name": "Chain",
"content": "structure Chain (Ξ± : Type _) [OFE Ξ±] where\n chain : Nat β Ξ±\n cauchy : n β€ i β chain i β‘{n}β‘ chain n"
},
{
"name": "BIAffine",
"content": "class BIAffine (PROP : Type _) [BI PROP] where\n affine (P : PROP) : Affine P"
},
{
"name": "Affine",
"content": "class Affine [BI PROP] (P : PROP) where\n affine : P β’ emp"
},
{
"name": "intuitionistically",
"content": "def intuitionistically [BIBase PROP] (P : PROP) : PROP := iprop(<affine> <pers> P)"
},
{
"name": "bigAnd",
"content": "def bigAnd [BIBase PROP] (Ps : List PROP) : PROP := bigOp and iprop(True) Ps"
},
{
"name": "bigOp",
"content": "def bigOp (f : PROP β PROP β PROP) (unit : PROP) : List PROP β PROP\n | [] => unit\n | [P] => P\n | P :: Ps => f P (bigOp f unit Ps)"
},
{
"name": "absorbingly",
"content": "def absorbingly [BIBase PROP] (P : PROP) : PROP := iprop(True β P)"
},
{
"name": "BiEntails",
"content": "structure BiEntails [BIBase PROP] (P Q : PROP) where\n mp : P β’ Q\n mpr : Q β’ P"
},
{
"name": "persistentlyIf",
"content": "def persistentlyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then <pers> P else P)"
},
{
"name": "intuitionisticallyIf",
"content": "def intuitionisticallyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then β‘ P else P)"
},
{
"name": "bigSep",
"content": "def bigSep [BIBase PROP] (Ps : List PROP) : PROP := bigOp sep iprop(emp) Ps"
},
{
"name": "affinely",
"content": "def affinely [BIBase PROP] (P : PROP) : PROP := iprop(emp β§ P)"
},
{
"name": "bigOr",
"content": "def bigOr [BIBase PROP] (Ps : List PROP) : PROP := bigOp or iprop(False) Ps"
},
{
"name": "absorbinglyIf",
"content": "def absorbinglyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then <absorb> P else P)"
},
{
"name": "affinelyIf",
"content": "def affinelyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then <affine> P else P)"
},
{
"name": "wandIff",
"content": "def wandIff [BIBase PROP] (P Q : PROP) : PROP := iprop((P -β Q) β§ (Q -β P))"
},
{
"name": "scoped infix:40 \" β‘ \" => OFE.Equiv",
"content": "scoped infix:40 \" β‘ \" => OFE.Equiv"
},
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y"
},
{
"name": "infixr:25 \" -c> \" => ContractiveHom",
"content": "infixr:25 \" -c> \" => ContractiveHom"
},
{
"name": "notation:40 \"[β§] \" Ps:max => bigAnd Ps",
"content": "notation:40 \"[β§] \" Ps:max => bigAnd Ps"
},
{
"name": "notation:40 \"[β¨] \" Ps:max => bigOr Ps",
"content": "notation:40 \"[β¨] \" Ps:max => bigOr Ps"
},
{
"name": "notation:40 \"[β] \" Ps:max => bigSep Ps",
"content": "notation:40 \"[β] \" Ps:max => bigSep Ps"
}
] | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "Dist.trans",
"content": "theorem Dist.trans [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ y β y β‘{n}β‘ z β x β‘{n}β‘ z"
},
{
"name": "BIBase.BiEntails.trans",
"content": "theorem BIBase.BiEntails.trans [BI PROP] {P Q R : PROP} (h1 : P β£β’ Q) (h2 : Q β£β’ R) : P β£β’ R"
},
{
"name": "BIBase.Entails.trans",
"content": "theorem BIBase.Entails.trans [BI PROP] {P Q R : PROP} (h1 : P β’ Q) (h2 : Q β’ R) : P β’ R"
},
{
"name": "Equiv.trans",
"content": "theorem Equiv.trans [OFE Ξ±] {x : Ξ±} : x β‘ y β y β‘ z β x β‘ z"
},
{
"name": "equiv_eqv",
"content": "theorem equiv_eqv [ofe : OFE Ξ±] : Equivalence ofe.Equiv"
},
{
"name": "Dist.symm",
"content": "@[symm] theorem Dist.symm [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ y β y β‘{n}β‘ x"
},
{
"name": "Dist.rfl",
"content": "@[simp, refl] theorem Dist.rfl [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ x"
},
{
"name": "DistLater.trans",
"content": "theorem DistLater.trans [OFE Ξ±] {n} {x : Ξ±} (h1 : DistLater n x y) (h2 : DistLater n y z) :\n DistLater n x z"
}
] | [] | [
{
"name": "Iris.BI.and_elim_l'",
"content": "theorem and_elim_l' [BI PROP] {P Q R : PROP} (h : P β’ R) : P β§ Q β’ R"
},
{
"name": "Iris.BI.and_elim_r'",
"content": "theorem and_elim_r' [BI PROP] {P Q R : PROP} (h : Q β’ R) : P β§ Q β’ R"
},
{
"name": "Iris.BI.and_symm",
"content": "theorem and_symm [BI PROP] {P Q : PROP} : P β§ Q β’ Q β§ P"
},
{
"name": "Iris.BI.imp_intro'",
"content": "theorem imp_intro' [BI PROP] {P Q R : PROP} (h : Q β§ P β’ R) : P β’ Q β R"
},
{
"name": "Iris.BI.imp_elim'",
"content": "theorem imp_elim' [BI PROP] {P Q R : PROP} (h : Q β’ P β R) : P β§ Q β’ R"
},
{
"name": "Iris.BI.imp_elim_r",
"content": "theorem imp_elim_r [BI PROP] {P Q : PROP} : P β§ (P β Q) β’ Q"
},
{
"name": "Iris.BI.true_intro",
"content": "theorem true_intro [BI PROP] {P : PROP} : P β’ True"
},
{
"name": "Iris.BI.and_mono",
"content": "@[rw_mono_rule]\ntheorem and_mono [BI PROP] {P P' Q Q' : PROP} (h1 : P β’ Q) (h2 : P' β’ Q') : P β§ P' β’ Q β§ Q'"
},
{
"name": "Iris.BI.and_mono_l",
"content": "theorem and_mono_l [BI PROP] {P P' Q : PROP} (h : P β’ P') : P β§ Q β’ P' β§ Q"
},
{
"name": "Iris.BI.and_mono_r",
"content": "theorem and_mono_r [BI PROP] {P Q Q' : PROP} (h : Q β’ Q') : P β§ Q β’ P β§ Q'"
},
{
"name": "Iris.BI.exists_intro",
"content": "theorem exists_intro [BI PROP] {Ξ¨ : Ξ± β PROP} (a : Ξ±) : Ξ¨ a β’ β a, Ξ¨ a"
},
{
"name": "Iris.BI.exists_elim",
"content": "theorem exists_elim [BI PROP] {Ξ¦ : Ξ± β PROP} {Q : PROP} (h : β a, Ξ¦ a β’ Q) : (β a, Ξ¦ a) β’ Q"
},
{
"name": "Iris.BI.and_comm",
"content": "theorem and_comm [BI PROP] {P Q : PROP} : P β§ Q β£β’ Q β§ P"
},
{
"name": "Iris.BI.true_and",
"content": "theorem true_and [BI PROP] {P : PROP} : True β§ P β£β’ P"
},
{
"name": "Iris.BI.and_true",
"content": "theorem and_true [BI PROP] {P : PROP} : P β§ True β£β’ P"
},
{
"name": "Iris.BI.and_assoc",
"content": "theorem and_assoc [BI PROP] {P Q R : PROP} : (P β§ Q) β§ R β£β’ P β§ Q β§ R"
},
{
"name": "Iris.BI.sep_mono_l",
"content": "theorem sep_mono_l [BI PROP] {P P' Q : PROP} (h : P β’ P') : P β Q β’ P' β Q"
},
{
"name": "Iris.BI.sep_mono_r",
"content": "theorem sep_mono_r [BI PROP] {P Q Q' : PROP} (h : Q β’ Q') : P β Q β’ P β Q'"
},
{
"name": "Iris.BI.sep_comm",
"content": "theorem sep_comm [BI PROP] {P Q : PROP} : P β Q β£β’ Q β P"
},
{
"name": "Iris.BI.sep_emp",
"content": "theorem sep_emp [BI PROP] {P : PROP} : P β emp β£β’ P"
},
{
"name": "Iris.BI.wand_elim'",
"content": "theorem wand_elim' [BI PROP] {P Q R : PROP} (h : Q β’ P -β R) : P β Q β’ R"
},
{
"name": "Iris.BI.wand_elim_r",
"content": "theorem wand_elim_r [BI PROP] {P Q : PROP} : P β (P -β Q) β’ Q"
},
{
"name": "Iris.BI.affinely_elim",
"content": "theorem affinely_elim [BI PROP] {P : PROP} : <affine> P β’ P"
},
{
"name": "Iris.BI.persistently_emp_intro",
"content": "theorem persistently_emp_intro [BI PROP] {P : PROP} : P β’ <pers> emp"
},
{
"name": "Iris.BI.persistently_emp",
"content": "theorem persistently_emp [BI PROP] : <pers> (emp : PROP) β£β’ True"
},
{
"name": "Iris.BI.intuitionistically_elim",
"content": "theorem intuitionistically_elim [BI PROP] {P : PROP} : β‘ P β’ P"
},
{
"name": "Iris.BI.persistently_and_intuitionistically_sep_r",
"content": "theorem persistently_and_intuitionistically_sep_r [BI PROP] {P Q : PROP} :\n P β§ <pers> Q β£β’ P β β‘ Q"
}
] | import Iris.BI.Classes
import Iris.BI.Extensions
import Iris.BI.BI
import Iris.Std.Classes
import Iris.Std.Rewrite
import Iris.Std.TC
namespace Iris.BI
open Iris.Std BI | theorem imp_iff_exists_persistently [BI PROP] [BIAffine PROP] {P Q : PROP} :
(P β Q) β£β’ β R, R β§ <pers> (P β§ R -β Q) := | := by
constructor
Β· refine (and_true.2.trans ?_).trans (exists_intro iprop(P β Q))
exact and_mono_r <| persistently_emp.2.trans <| persistently_mono <|
wand_intro <| emp_sep.1.trans imp_elim_r
Β· exact exists_elim fun R => imp_intro' <| and_assoc.2.trans <|
persistently_and_intuitionistically_sep_r.1.trans <|
(sep_mono_r intuitionistically_elim).trans wand_elim_r | 5 | 75 | false | Framework |
227 | Iris.COFE.OFunctor.Fix.Impl.downN_upN | theorem downN_upN {k} (x : A F k) : β {i}, downN F i (upN F i x) β‘ x
| 0 => .rfl
| n+1 => ((downN F n).ne.eqv (down_up ..)).trans (downN_upN _) | iris-lean | src/Iris/Algebra/COFESolver.lean | [
"import Iris.Algebra.OFE"
] | [
{
"name": "Equivalence",
"module": "Init.Core"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "m",
"module": "QqTest.matching"
},
{
"name": "ULift",
"module": "Init.Prelude"
},
{
"name": "Unit",
"module": "Init.Prelude"
},
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "Option.merge",
"module": "Init.Data.Option.Basic"
},
{
"name": "id",
"module": "Init.Prelude"
},
{
"name": "Inhabited.default",
"module": "Init.Prelude"
}
] | [
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y"
},
{
"name": "COFE.OFunctor.constOF_RFunctor",
"content": "instance COFE.OFunctor.constOF_RFunctor [CMRA B] : RFunctor (constOF B) where\n map f g := by admit /- proof elided -/"
},
{
"name": "OFE.ContractiveHom.fixpoint_ne",
"content": "instance OFE.ContractiveHom.fixpoint_ne [COFE Ξ±] [Inhabited Ξ±] :\n NonExpansive (ContractiveHom.fixpoint (Ξ± := Ξ±)) where\n ne n f1 f2 H := by admit /- proof elided -/"
},
{
"name": "IsCOFE",
"content": "class IsCOFE (Ξ± : Type _) [OFE Ξ±] where\n compl : Chain Ξ± β Ξ±\n conv_compl {c : Chain Ξ±} : compl c β‘{n}β‘ c n"
},
{
"name": "Chain",
"content": "structure Chain (Ξ± : Type _) [OFE Ξ±] where\n chain : Nat β Ξ±\n cauchy : n β€ i β chain i β‘{n}β‘ chain n"
},
{
"name": "Hom",
"content": "@[ext] structure Hom (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] where\n f : Ξ± β Ξ²\n ne : NonExpansive f"
},
{
"name": "ContractiveHom",
"content": "@[ext] structure ContractiveHom (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] extends Hom Ξ± Ξ² where\n [contractive : Contractive f]\n ne := ne_of_contractive f"
},
{
"name": "NonExpansive",
"content": "class NonExpansive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β f xβ β‘{n}β‘ f xβ"
},
{
"name": "OFE.Option.some.ne",
"content": "instance OFE.Option.some.ne [OFE Ξ±] : OFE.NonExpansive (some : Ξ± β Option Ξ±) := β¨fun _ _ _ => idβ©"
},
{
"name": "Option.merge_ne",
"content": "instance Option.merge_ne [OFE Ξ±] {op : Ξ± β Ξ± β Ξ±} [NonExpansiveβ op] :\n NonExpansiveβ (Option.merge op) where\n ne n x1 x2 Hx y1 y2 Hy := by admit /- proof elided -/"
},
{
"name": "NonExpansiveβ",
"content": "class NonExpansiveβ [OFE Ξ±] [OFE Ξ²] [OFE Ξ³] (f : Ξ± β Ξ² β Ξ³) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β β β¦yβ yββ¦, yβ β‘{n}β‘ yβ β f xβ yβ β‘{n}β‘ f xβ yβ"
},
{
"name": "scoped infix:40 \" β‘ \" => OFE.Equiv",
"content": "scoped infix:40 \" β‘ \" => OFE.Equiv"
},
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y"
},
{
"name": "@[inherit_doc]",
"content": "@[inherit_doc]\ninfixr:25 \" -n> \" => Hom"
},
{
"name": "infixr:25 \" -c> \" => ContractiveHom",
"content": "infixr:25 \" -c> \" => ContractiveHom"
},
{
"name": "@[inherit_doc]",
"content": "@[inherit_doc]\ninfixr:25 \" -C> \" => Hom"
}
] | [
{
"name": "symm",
"module": "Mathlib.Order.Defs.Unbundled"
}
] | [
{
"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": "Iris.COFE.OFunctor.Fix.Impl.A'",
"content": "def A' : Nat β Ξ£ Ξ± : Type u, COFE Ξ±\n | 0 => β¨ULift Unit, inferInstanceβ©\n | n+1 => let β¨A, _β© := A' n; β¨F A A, inferInstanceβ©"
},
{
"name": "Iris.COFE.OFunctor.Fix.Impl.A",
"content": "def A (n : Nat) : Type u := (A' F n).1"
},
{
"name": "Iris.COFE.OFunctor.Fix.Impl.up",
"content": "def up : β k, A F k -n> A F (k+1)\n | 0 => β¨fun _ => inh.default, β¨fun _ _ _ _ => .rflβ©β©\n | k+1 => map (down k) (up k)"
},
{
"name": "Iris.COFE.OFunctor.Fix.Impl.down",
"content": "def down : β k, A F (k+1) -n> A F k\n | 0 => β¨fun _ => β¨()β©, β¨fun _ _ _ _ => .rflβ©β©\n | k+1 => map (up k) (down k)"
},
{
"name": "Iris.COFE.OFunctor.Fix.Impl.upN",
"content": "def upN {k} : β n, A F k -n> A F (k + n)\n | 0 => .id\n | n+1 => (up F (k + n)).comp (upN n)"
},
{
"name": "Iris.COFE.OFunctor.Fix.Impl.downN",
"content": "def downN {k} : β n, A F (k + n) -n> A F k\n | 0 => .id\n | n+1 => (downN n).comp (down F (k + n))"
}
] | [
{
"name": "Iris.COFE.OFunctor.Fix.Impl.down_up",
"content": "theorem down_up : β {k} x, down F k (up F k x) β‘ x\n | 0, β¨()β© => .rfl\n | _+1, _ => (map_comp ..).symm.trans <|\n (map_ne.eqv down_up down_up _).trans (map_id _)"
}
] | import Iris.Algebra.OFE
namespace Iris.COFE.OFunctor
open OFE
variable {F : β Ξ± Ξ² [OFE Ξ±] [OFE Ξ²], Type u} [OFunctorContractive F]
variable [β Ξ± [COFE Ξ±], IsCOFE (F Ξ± Ξ±)]
variable [inh : Inhabited (F (ULift Unit) (ULift Unit))]
namespace Fix.Impl
variable (F) in
def A' : Nat β Ξ£ Ξ± : Type u, COFE Ξ±
| 0 => β¨ULift Unit, inferInstanceβ©
| n+1 => let β¨A, _β© := A' n; β¨F A A, inferInstanceβ©
variable (F) in
def A (n : Nat) : Type u := (A' F n).1
variable (F) in
def up : β k, A F k -n> A F (k+1)
| 0 => β¨fun _ => inh.default, β¨fun _ _ _ _ => .rflβ©β©
| k+1 => map (down k) (up k)
def down : β k, A F (k+1) -n> A F k
| 0 => β¨fun _ => β¨()β©, β¨fun _ _ _ _ => .rflβ©β©
| k+1 => map (up k) (down k)
end
open OFunctorContractive in exact match k with
| 0 => map_contractive.zero (x := (_, _)) (y := (_, _)) _ _
| k+1 => map_contractive.succ (x := (_, _)) (y := (_, _)) _ β¨up_down, up_downβ© _
variable (F) in
variable (F) in
def upN {k} : β n, A F k -n> A F (k + n)
| 0 => .id
| n+1 => (up F (k + n)).comp (upN n)
variable (F) in
def downN {k} : β n, A F (k + n) -n> A F k
| 0 => .id
| n+1 => (downN n).comp (down F (k + n)) | theorem downN_upN {k} (x : A F k) : β {i}, downN F i (upN F i x) β‘ x := | | 0 => .rfl
| n+1 => ((downN F n).ne.eqv (down_up ..)).trans (downN_upN _) | 8 | 27 | false | Framework |
228 | Iris.BI.persistently_sep | theorem persistently_sep [BI PROP] [BIPositive PROP] {P Q : PROP} :
<pers> (P β Q) β£β’ <pers> P β <pers> Q | iris-lean | src/Iris/BI/DerivedLaws.lean | [
"import Iris.BI.Extensions",
"import Iris.Std.TC",
"import Iris.Std.Classes",
"import Iris.BI.BI",
"import src.Iris.Algebra.OFE",
"import src.Iris.BI.BI",
"import Iris.BI.Classes",
"import Iris.Std.Rewrite"
] | [
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "Option.merge",
"module": "Init.Data.Option.Basic"
},
{
"name": "id",
"module": "Init.Prelude"
},
{
"name": "Equivalence",
"module": "Init.Core"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "m",
"module": "QqTest.matching"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Bool",
"module": "Init.Prelude"
}
] | [
{
"name": "macro \"β\" xs:explicitBinders \", \" b:term : term => do",
"content": "macro \"β\" xs:explicitBinders \", \" b:term : term => do\n return β¨β expandExplicitBinders ``BIBase.exists xs bβ©"
},
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y\n\nsyntax:max \"<pers> \" term:40 : term"
},
{
"name": "macro:25 P:term:29 \" β’ \" Q:term:25 : term => ``(BIBase.Entai",
"content": "macro:25 P:term:29 \" β’ \" Q:term:25 : term => ``(BIBase.Entails iprop($P) iprop($Q))\n\ndelab_rule BIBase.Entails\n | `($_ $P $Q) => do ``($(β unpackIprop P) β’ $(β unpackIprop Q))"
},
{
"name": "macro:25 P:term:29 \" β£β’ \" Q:term:29 : term => ``(BiEntails i",
"content": "macro:25 P:term:29 \" β£β’ \" Q:term:29 : term => ``(BiEntails iprop($P) iprop($Q))\n\ndelab_rule BIBase.Entails\n | `($_ iprop(emp) $P) => do ``(β’ $(β unpackIprop P))\n\ndelab_rule BIBase.BiEntails\n | `($_ $P $Q) => do ``($(β unpackIprop P) β£β’ $(β unpackIprop Q))\n\nsyntax \"β\" term \"β\" : term\n\nsyntax:max \"β· \" term:40 : term\n\nsyntax:max \"<affine> \" term:40 : term"
},
{
"name": "macro:max \"iprop(\" P:term \" : \" t:term \")\" : term => `((ipro",
"content": "macro:max \"iprop(\" P:term \" : \" t:term \")\" : term => `((iprop($P) : $t))\n\nsyntax:max \"iprop(\" term \")\" : term\n\nsyntax:max \"β‘ \" term:40 : term\n\nsyntax:max \"<absorb> \" term:40 : term"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(term($t))) => pure t\n | `(iprop($t)) => pure t"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(($P))) => ``((iprop($P)))\n | `(iprop(if $c then $t else $e)) => ``(if $c then iprop($t) else iprop($e))\n | `(iprop(($P : $t))) => ``((iprop($P) : $t))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(emp)) => ``(BIBase.emp)\n | `(iprop(β$Οβ)) => ``(BIBase.pure $Ο)\n | `(iprop($P β§ $Q)) => ``(BIBase.and iprop($P) iprop($Q))\n | `(iprop($P β¨ $Q)) => ``(BIBase.or iprop($P) iprop($Q))\n | `(iprop($P β $Q)) => ``(BIBase.imp iprop($P) iprop($Q))\n | `(iprop(β $xs, $Ξ¨)) => do expandExplicitBinders ``BIBase.exists xs (β ``(iprop($Ξ¨)))\n | `(iprop($P β $Q)) => ``(BIBase.sep iprop($P) iprop($Q))\n | `(iprop($P -β $Q)) => ``(BIBase.wand iprop($P) iprop($Q))\n | `(iprop(<pers> $P)) => ``(BIBase.persistently iprop($P))\n | `(iprop(β· $P)) => ``(BIBase.later iprop($P))\n\ndelab_rule BIBase.emp\n | `($_) => ``(iprop($(mkIdent `emp)))\ndelab_rule BIBase.pure\n | `($_ $Ο) => ``(iprop(β$Οβ))\ndelab_rule BIBase.and\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β§ $(β unpackIprop Q)))\ndelab_rule BIBase.or\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β¨ $(β unpackIprop Q)))\ndelab_rule BIBase.imp\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule BIBase.forall\n | `($_ fun $x:ident => iprop(β $y:ident $[$z:ident]*, $Ξ¨)) => do\n ``(iprop(β $x:ident $y:ident $[$z:ident]*, $Ξ¨))\n | `($_ fun $x:ident => $Ξ¨) => do ``(iprop(β $x:ident, $(β unpackIprop Ξ¨)))\ndelab_rule BIBase.exists\n | `($_ fun $x:ident => iprop(β $y:ident $[$z:ident]*, $Ξ¨)) => do\n ``(iprop(β $x:ident $y:ident $[$z:ident]*, $Ξ¨))\n | `($_ fun $x:ident => $Ξ¨) => do ``(iprop(β $x:ident, $(β unpackIprop Ξ¨)))\ndelab_rule BIBase.sep\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule BIBase.wand\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) -β $(β unpackIprop Q)))\ndelab_rule BIBase.persistently\n | `($_ $P) => do ``(iprop(<pers> $(β unpackIprop P)))\n\ndelab_rule BIBase.pure\n | `($_ True) => ``(iprop($(mkIdent `True)))\n | `($_ False) => ``(iprop($(mkIdent `False)))\ndelab_rule BIBase.imp\n | `($_ $P iprop(False)) => do ``(iprop(Β¬$(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β _%$tk, $Ξ¨)) => ``(BIBase.forall (fun _%$tk => iprop($Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $x:ident, $Ξ¨)) => ``(BIBase.forall (fun $x => iprop($Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β (_%$tk : $t), $Ξ¨)) => ``(BIBase.forall (fun (_%$tk : $t) => iprop($Ξ¨)))\n | `(iprop(β (_%$tk $xs* : $t), $Ξ¨)) =>\n ``(BIBase.forall (fun (_%$tk : $t) => iprop(β ($xs* : $t), $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β ($x:ident : $t), $Ξ¨)) => ``(BIBase.forall (fun ($x : $t) => iprop($Ξ¨)))\n | `(iprop(β ($x:ident $xs* : $t), $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop(β ($xs* : $t), $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β {_%$tk : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun {_%$tk : $t} => iprop($Ξ¨)))\n | `(iprop(β {_%$tk $xs* : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun {_%$tk : $t} => iprop(β {$xs* : $t}, $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β {$x:ident : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop($Ξ¨)))\n | `(iprop(β {$x:ident $xs* : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop(β {$xs* : $t}, $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $x $y $xs*, $Ξ¨)) => ``(iprop(β $x, β $y $xs*, $Ξ¨))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(True)) => ``(BIBase.pure True)\n | `(iprop(False)) => ``(BIBase.pure False)\n | `(iprop(Β¬$P)) => ``(iprop($P β False))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop($P β $Q)) => ``(iff iprop($P) iprop($Q))\n | `(iprop($P β-β $Q)) => ``(wandIff iprop($P) iprop($Q))\n\ndelab_rule iff\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule wandIff\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β-β $(β unpackIprop Q)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(<affine> $P)) => ``(affinely iprop($P))\n | `(iprop(<absorb> $P)) => ``(absorbingly iprop($P))\n\ndelab_rule affinely\n | `($_ $P) => do ``(iprop(<affine> $(β unpackIprop P)))\ndelab_rule absorbingly\n | `($_ $P) => do ``(iprop(<absorb> $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β‘ $P)) => ``(intuitionistically iprop($P))\n\ndelab_rule intuitionistically\n | `($_ $P) => do ``(iprop(β‘ $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(<pers>?$p $P)) => ``(persistentlyIf $p iprop($P))\n | `(iprop(<affine>?$p $P)) => ``(affinelyIf $p iprop($P))\n | `(iprop(<absorb>?$p $P)) => ``(absorbinglyIf $p iprop($P))\n | `(iprop(β‘?$p $P)) => ``(intuitionisticallyIf $p iprop($P))\n\ndelab_rule persistentlyIf\n | `($_ $p $P) => do ``(iprop(<pers>?$p $(β unpackIprop P)))\ndelab_rule affinelyIf\n | `($_ $p $P) => do ``(iprop(<affine>?$p $(β unpackIprop P)))\ndelab_rule absorbinglyIf\n | `($_ $p $P) => do ``(iprop(<absorb>?$p $(β unpackIprop P)))\ndelab_rule intuitionisticallyIf\n | `($_ $p $P) => do ``(iprop(β‘?$p $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β·^[$n] $P)) => ``(laterN $n iprop($P))\n\ndelab_rule laterN\n | `($_ $n $P) => do ``(iprop(β·^[$n] $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $P)) => ``(except0 iprop($P))\n\ndelab_rule except0\n | `($_ $P) => do ``(iprop(β $(β unpackIprop P)))"
},
{
"name": "LawfulBigOp",
"content": "class LawfulBigOp (f : PROP β PROP β PROP) (unit : outParam PROP)\n (eq : outParam (PROP β PROP β Prop)) where\n refl : eq a a\n symm : eq a b β eq b a\n trans : eq a b β eq b c β eq a c\n comm : eq (f a b) (f b a)\n assoc : eq (f (f a b) c) (f a (f b c))\n left_id : eq (f unit a) a\n congr_l : eq a a' β eq (f a b) (f a' b)"
},
{
"name": "BIBase",
"content": "class BIBase (PROP : Type u) where\n Entails : PROP β PROP β Prop\n emp : PROP\n pure : Prop β PROP\n and : PROP β PROP β PROP\n or : PROP β PROP β PROP\n imp : PROP β PROP β PROP\n sForall : (PROP β Prop) β PROP\n sExists : (PROP β Prop) β PROP\n sep : PROP β PROP β PROP\n wand : PROP β PROP β PROP\n persistently : PROP β PROP\n later : PROP β PROP"
},
{
"name": "BI",
"content": "class BI (PROP : Type _) extends COFE PROP, BI.BIBase PROP where\n Equiv P Q := P β£β’ Q\n\n entails_preorder : Preorder Entails\n equiv_iff {P Q : PROP} : (P β‘ Q) β P β£β’ Q := by admit /- proof elided -/"
},
{
"name": "liftRel",
"content": "def liftRel (R : Ξ± β Ξ² β Prop) (A : Ξ± β Prop) (B : Ξ² β Prop) : Prop :=\n (β a, A a β β b, B b β§ R a b) β§ (β b, B b β β a, A a β§ R a b)"
},
{
"name": "Preorder",
"content": "class Preorder (R : Relation Ξ±) extends Reflexive R, Transitive R"
},
{
"name": "Reflexive",
"content": "class Reflexive (R : Relation Ξ±) where\n refl {x : Ξ±} : R x x"
},
{
"name": "Relation",
"content": "abbrev Relation (Ξ± : Type _) := Ξ± β Ξ± β Prop"
},
{
"name": "Transitive",
"content": "class Transitive (R : Relation Ξ±) where\n trans {x y z : Ξ±} : R x y β R y z β R x z"
},
{
"name": "NonExpansiveβ",
"content": "class NonExpansiveβ [OFE Ξ±] [OFE Ξ²] [OFE Ξ³] (f : Ξ± β Ξ² β Ξ³) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β β β¦yβ yββ¦, yβ β‘{n}β‘ yβ β f xβ yβ β‘{n}β‘ f xβ yβ"
},
{
"name": "OFE.ContractiveHom.fixpoint_ne",
"content": "instance OFE.ContractiveHom.fixpoint_ne [COFE Ξ±] [Inhabited Ξ±] :\n NonExpansive (ContractiveHom.fixpoint (Ξ± := Ξ±)) where\n ne n f1 f2 H := by admit /- proof elided -/"
},
{
"name": "ContractiveHom",
"content": "@[ext] structure ContractiveHom (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] extends Hom Ξ± Ξ² where\n [contractive : Contractive f]\n ne := ne_of_contractive f"
},
{
"name": "OFE.Option.some.ne",
"content": "instance OFE.Option.some.ne [OFE Ξ±] : OFE.NonExpansive (some : Ξ± β Option Ξ±) := β¨fun _ _ _ => idβ©"
},
{
"name": "Option.merge_ne",
"content": "instance Option.merge_ne [OFE Ξ±] {op : Ξ± β Ξ± β Ξ±} [NonExpansiveβ op] :\n NonExpansiveβ (Option.merge op) where\n ne n x1 x2 Hx y1 y2 Hy := by admit /- proof elided -/"
},
{
"name": "NonExpansive",
"content": "class NonExpansive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β f xβ β‘{n}β‘ f xβ"
},
{
"name": "COFE.OFunctor.constOF_RFunctor",
"content": "instance COFE.OFunctor.constOF_RFunctor [CMRA B] : RFunctor (constOF B) where\n map f g := by admit /- proof elided -/"
},
{
"name": "IsCOFE",
"content": "class IsCOFE (Ξ± : Type _) [OFE Ξ±] where\n compl : Chain Ξ± β Ξ±\n conv_compl {c : Chain Ξ±} : compl c β‘{n}β‘ c n"
},
{
"name": "Chain",
"content": "structure Chain (Ξ± : Type _) [OFE Ξ±] where\n chain : Nat β Ξ±\n cauchy : n β€ i β chain i β‘{n}β‘ chain n"
},
{
"name": "BIPositive",
"content": "class BIPositive (PROP : Type _) [BI PROP] where\n affinely_sep_l {P Q : PROP} : <affine> (P β Q) β’ <affine> P β Q"
},
{
"name": "Affine",
"content": "class Affine [BI PROP] (P : PROP) where\n affine : P β’ emp"
},
{
"name": "intuitionistically",
"content": "def intuitionistically [BIBase PROP] (P : PROP) : PROP := iprop(<affine> <pers> P)"
},
{
"name": "bigAnd",
"content": "def bigAnd [BIBase PROP] (Ps : List PROP) : PROP := bigOp and iprop(True) Ps"
},
{
"name": "bigOp",
"content": "def bigOp (f : PROP β PROP β PROP) (unit : PROP) : List PROP β PROP\n | [] => unit\n | [P] => P\n | P :: Ps => f P (bigOp f unit Ps)"
},
{
"name": "absorbingly",
"content": "def absorbingly [BIBase PROP] (P : PROP) : PROP := iprop(True β P)"
},
{
"name": "BiEntails",
"content": "structure BiEntails [BIBase PROP] (P Q : PROP) where\n mp : P β’ Q\n mpr : Q β’ P"
},
{
"name": "persistentlyIf",
"content": "def persistentlyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then <pers> P else P)"
},
{
"name": "intuitionisticallyIf",
"content": "def intuitionisticallyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then β‘ P else P)"
},
{
"name": "bigSep",
"content": "def bigSep [BIBase PROP] (Ps : List PROP) : PROP := bigOp sep iprop(emp) Ps"
},
{
"name": "affinely",
"content": "def affinely [BIBase PROP] (P : PROP) : PROP := iprop(emp β§ P)"
},
{
"name": "bigOr",
"content": "def bigOr [BIBase PROP] (Ps : List PROP) : PROP := bigOp or iprop(False) Ps"
},
{
"name": "absorbinglyIf",
"content": "def absorbinglyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then <absorb> P else P)"
},
{
"name": "affinelyIf",
"content": "def affinelyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then <affine> P else P)"
},
{
"name": "wandIff",
"content": "def wandIff [BIBase PROP] (P Q : PROP) : PROP := iprop((P -β Q) β§ (Q -β P))"
},
{
"name": "scoped infix:40 \" β‘ \" => OFE.Equiv",
"content": "scoped infix:40 \" β‘ \" => OFE.Equiv"
},
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y"
},
{
"name": "infixr:25 \" -c> \" => ContractiveHom",
"content": "infixr:25 \" -c> \" => ContractiveHom"
},
{
"name": "notation:40 \"[β§] \" Ps:max => bigAnd Ps",
"content": "notation:40 \"[β§] \" Ps:max => bigAnd Ps"
},
{
"name": "notation:40 \"[β¨] \" Ps:max => bigOr Ps",
"content": "notation:40 \"[β¨] \" Ps:max => bigOr Ps"
},
{
"name": "notation:40 \"[β] \" Ps:max => bigSep Ps",
"content": "notation:40 \"[β] \" Ps:max => bigSep Ps"
}
] | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "Dist.trans",
"content": "theorem Dist.trans [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ y β y β‘{n}β‘ z β x β‘{n}β‘ z"
},
{
"name": "BIBase.BiEntails.trans",
"content": "theorem BIBase.BiEntails.trans [BI PROP] {P Q R : PROP} (h1 : P β£β’ Q) (h2 : Q β£β’ R) : P β£β’ R"
},
{
"name": "BIBase.Entails.trans",
"content": "theorem BIBase.Entails.trans [BI PROP] {P Q R : PROP} (h1 : P β’ Q) (h2 : Q β’ R) : P β’ R"
},
{
"name": "Equiv.trans",
"content": "theorem Equiv.trans [OFE Ξ±] {x : Ξ±} : x β‘ y β y β‘ z β x β‘ z"
},
{
"name": "equiv_eqv",
"content": "theorem equiv_eqv [ofe : OFE Ξ±] : Equivalence ofe.Equiv"
},
{
"name": "Dist.symm",
"content": "@[symm] theorem Dist.symm [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ y β y β‘{n}β‘ x"
},
{
"name": "Dist.rfl",
"content": "@[simp, refl] theorem Dist.rfl [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ x"
},
{
"name": "DistLater.trans",
"content": "theorem DistLater.trans [OFE Ξ±] {n} {x : Ξ±} (h1 : DistLater n x y) (h2 : DistLater n y z) :\n DistLater n x z"
}
] | [] | [
{
"name": "Iris.BI.and_elim_l'",
"content": "theorem and_elim_l' [BI PROP] {P Q R : PROP} (h : P β’ R) : P β§ Q β’ R"
},
{
"name": "Iris.BI.and_elim_r'",
"content": "theorem and_elim_r' [BI PROP] {P Q R : PROP} (h : Q β’ R) : P β§ Q β’ R"
},
{
"name": "Iris.BI.and_symm",
"content": "theorem and_symm [BI PROP] {P Q : PROP} : P β§ Q β’ Q β§ P"
},
{
"name": "Iris.BI.true_intro",
"content": "theorem true_intro [BI PROP] {P : PROP} : P β’ True"
},
{
"name": "Iris.BI.and_mono",
"content": "@[rw_mono_rule]\ntheorem and_mono [BI PROP] {P P' Q Q' : PROP} (h1 : P β’ Q) (h2 : P' β’ Q') : P β§ P' β’ Q β§ Q'"
},
{
"name": "Iris.BI.and_mono_l",
"content": "theorem and_mono_l [BI PROP] {P P' Q : PROP} (h : P β’ P') : P β§ Q β’ P' β§ Q"
},
{
"name": "Iris.BI.and_mono_r",
"content": "theorem and_mono_r [BI PROP] {P Q Q' : PROP} (h : Q β’ Q') : P β§ Q β’ P β§ Q'"
},
{
"name": "Iris.BI.and_congr",
"content": "@[rw_mono_rule]\ntheorem and_congr [BI PROP] {P P' Q Q' : PROP} (h1 : P β£β’ Q) (h2 : P' β£β’ Q') : P β§ P' β£β’ Q β§ Q'"
},
{
"name": "Iris.BI.and_congr_l",
"content": "theorem and_congr_l [BI PROP] {P P' Q : PROP} (h : P β£β’ P') : P β§ Q β£β’ P' β§ Q"
},
{
"name": "Iris.BI.and_self",
"content": "theorem and_self [BI PROP] {P : PROP} : P β§ P β£β’ P"
},
{
"name": "Iris.BI.and_comm",
"content": "theorem and_comm [BI PROP] {P Q : PROP} : P β§ Q β£β’ Q β§ P"
},
{
"name": "Iris.BI.and_assoc",
"content": "theorem and_assoc [BI PROP] {P Q R : PROP} : (P β§ Q) β§ R β£β’ P β§ Q β§ R"
},
{
"name": "Iris.BI.sep_mono_l",
"content": "theorem sep_mono_l [BI PROP] {P P' Q : PROP} (h : P β’ P') : P β Q β’ P' β Q"
},
{
"name": "Iris.BI.sep_mono_r",
"content": "theorem sep_mono_r [BI PROP] {P Q Q' : PROP} (h : Q β’ Q') : P β Q β’ P β Q'"
},
{
"name": "Iris.BI.sep_congr",
"content": "@[rw_mono_rule]\ntheorem sep_congr [BI PROP] {P P' Q Q' : PROP} (h1 : P β£β’ Q) (h2 : P' β£β’ Q') :\n (P β P') β£β’ (Q β Q')"
},
{
"name": "Iris.BI.sep_congr_l",
"content": "theorem sep_congr_l [BI PROP] {P P' Q : PROP} (h : P β£β’ P') : P β Q β£β’ P' β Q"
},
{
"name": "Iris.BI.sep_congr_r",
"content": "theorem sep_congr_r [BI PROP] {P Q Q' : PROP} (h : Q β£β’ Q') : P β Q β£β’ P β Q'"
},
{
"name": "Iris.BI.sep_comm",
"content": "theorem sep_comm [BI PROP] {P Q : PROP} : P β Q β£β’ Q β P"
},
{
"name": "Iris.BI.sep_assoc",
"content": "theorem sep_assoc [BI PROP] {P Q R : PROP} : (P β Q) β R β£β’ P β Q β R"
},
{
"name": "Iris.BI.sep_emp",
"content": "theorem sep_emp [BI PROP] {P : PROP} : P β emp β£β’ P"
},
{
"name": "Iris.BI.true_sep_2",
"content": "theorem true_sep_2 [BI PROP] {P : PROP} : P β’ True β P"
},
{
"name": "Iris.BI.affinely_elim_emp",
"content": "theorem affinely_elim_emp [BI PROP] {P : PROP} : <affine> P β’ emp"
},
{
"name": "Iris.BI.affinely_elim",
"content": "theorem affinely_elim [BI PROP] {P : PROP} : <affine> P β’ P"
},
{
"name": "Iris.BI.affinely_mono",
"content": "@[rw_mono_rule]\ntheorem affinely_mono [BI PROP] {P Q : PROP} : (P β’ Q) β <affine> P β’ <affine> Q"
},
{
"name": "Iris.BI.affinely_idem",
"content": "theorem affinely_idem [BI PROP] {P : PROP} : <affine> <affine> P β£β’ <affine> P"
},
{
"name": "Iris.BI.affinely_sep_2",
"content": "theorem affinely_sep_2 [BI PROP] {P Q : PROP} : <affine> P β <affine> Q β’ <affine> (P β Q)"
},
{
"name": "Iris.BI.affinely_sep_r",
"content": "theorem affinely_sep_r [BI PROP] [BIPositive PROP] {P Q : PROP} :\n <affine> (P β Q) β’ P β <affine> Q"
},
{
"name": "Iris.BI.affinely_sep",
"content": "theorem affinely_sep [BI PROP] [BIPositive PROP] {P Q : PROP} :\n <affine> (P β Q) β£β’ <affine> P β <affine> Q"
},
{
"name": "Iris.BI.absorbingly_intro",
"content": "theorem absorbingly_intro [BI PROP] {P : PROP} : P β’ <absorb> P"
},
{
"name": "Iris.BI.persistently_absorb_r",
"content": "theorem persistently_absorb_r [BI PROP] {P Q : PROP} : P β <pers> Q β’ <pers> Q"
},
{
"name": "Iris.BI.absorbingly_persistently",
"content": "theorem absorbingly_persistently [BI PROP] {P : PROP} : <absorb> <pers> P β£β’ <pers> P"
},
{
"name": "Iris.BI.persistently_and",
"content": "theorem persistently_and [BI PROP] {P Q : PROP} : <pers> (P β§ Q) β£β’ <pers> P β§ <pers> Q"
},
{
"name": "Iris.BI.persistently_emp_intro",
"content": "theorem persistently_emp_intro [BI PROP] {P : PROP} : P β’ <pers> emp"
},
{
"name": "Iris.BI.persistently_affinely",
"content": "theorem persistently_affinely [BI PROP] {P : PROP} : <pers> <affine> P β£β’ <pers> P"
},
{
"name": "Iris.BI.persistently_and_sep_assoc",
"content": "theorem persistently_and_sep_assoc [BI PROP] {P Q R : PROP} :\n <pers> P β§ (Q β R) β£β’ (<pers> P β§ Q) β R"
},
{
"name": "Iris.BI.intuitionistically_elim",
"content": "theorem intuitionistically_elim [BI PROP] {P : PROP} : β‘ P β’ P"
},
{
"name": "Iris.BI.persistently_idem",
"content": "theorem persistently_idem [BI PROP] {P : PROP} : <pers> <pers> P β£β’ <pers> P"
},
{
"name": "Iris.BI.persistently_and_imp_sep",
"content": "theorem persistently_and_imp_sep [BI PROP] {P Q : PROP} : <pers> P β§ Q β’ <pers> P β Q"
},
{
"name": "Iris.BI.persistently_and_sep",
"content": "theorem persistently_and_sep [BI PROP] {P Q : PROP} : <pers> (P β§ Q) β’ <pers> (P β Q)"
},
{
"name": "Iris.BI.persistently_and_persistently_sep",
"content": "theorem persistently_and_persistently_sep [BI PROP] {P Q : PROP} :\n <pers> P β§ <pers> Q β£β’ <pers> P β <pers> Q"
},
{
"name": "Iris.BI.persistently_sep_2",
"content": "theorem persistently_sep_2 [BI PROP] {P Q : PROP} : <pers> P β <pers> Q β’ <pers> (P β Q)"
}
] | import Iris.BI.Classes
import Iris.BI.Extensions
import Iris.BI.BI
import Iris.Std.Classes
import Iris.Std.Rewrite
import Iris.Std.TC
namespace Iris.BI
open Iris.Std BI | theorem persistently_sep [BI PROP] [BIPositive PROP] {P Q : PROP} :
<pers> (P β Q) β£β’ <pers> P β <pers> Q := | := by
refine β¨persistently_affinely.2.trans ?_, persistently_sep_2β©
refine persistently_mono affinely_sep.1 |>.trans ?_ |>.trans persistently_and_persistently_sep.1
exact and_intro
(persistently_mono <| (sep_mono_r affinely_elim_emp).trans <| sep_emp.1.trans affinely_elim)
(persistently_mono <| (sep_mono_l affinely_elim_emp).trans <| emp_sep.1.trans affinely_elim) | 7 | 89 | false | Framework |
229 | Iris.BI.loeb_wand_intuitionistically | theorem loeb_wand_intuitionistically [BI PROP] [BILoeb PROP] {P : PROP} :
β‘ (β‘ β· P -β P) β’ P | iris-lean | src/Iris/BI/DerivedLaws.lean | [
"import Iris.BI.Extensions",
"import Iris.Std.TC",
"import Iris.Std.Classes",
"import Iris.BI.BI",
"import src.Iris.Algebra.OFE",
"import src.Iris.BI.BI",
"import Iris.BI.Classes",
"import Iris.Std.Rewrite"
] | [
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "Option.merge",
"module": "Init.Data.Option.Basic"
},
{
"name": "id",
"module": "Init.Prelude"
},
{
"name": "Equivalence",
"module": "Init.Core"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "m",
"module": "QqTest.matching"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Bool",
"module": "Init.Prelude"
},
{
"name": "Function.const",
"module": "Init.Prelude"
}
] | [
{
"name": "macro \"β\" xs:explicitBinders \", \" b:term : term => do",
"content": "macro \"β\" xs:explicitBinders \", \" b:term : term => do\n return β¨β expandExplicitBinders ``BIBase.exists xs bβ©"
},
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y\n\nsyntax:max \"<pers> \" term:40 : term"
},
{
"name": "macro:25 P:term:29 \" β’ \" Q:term:25 : term => ``(BIBase.Entai",
"content": "macro:25 P:term:29 \" β’ \" Q:term:25 : term => ``(BIBase.Entails iprop($P) iprop($Q))\n\ndelab_rule BIBase.Entails\n | `($_ $P $Q) => do ``($(β unpackIprop P) β’ $(β unpackIprop Q))"
},
{
"name": "macro:25 P:term:29 \" β£β’ \" Q:term:29 : term => ``(BiEntails i",
"content": "macro:25 P:term:29 \" β£β’ \" Q:term:29 : term => ``(BiEntails iprop($P) iprop($Q))\n\ndelab_rule BIBase.Entails\n | `($_ iprop(emp) $P) => do ``(β’ $(β unpackIprop P))\n\ndelab_rule BIBase.BiEntails\n | `($_ $P $Q) => do ``($(β unpackIprop P) β£β’ $(β unpackIprop Q))\n\nsyntax \"β\" term \"β\" : term\n\nsyntax:max \"β· \" term:40 : term\n\nsyntax:max \"<affine> \" term:40 : term\n\nsyntax:max \"β‘ \" term:40 : term"
},
{
"name": "macro:max \"iprop(\" P:term \" : \" t:term \")\" : term => `((ipro",
"content": "macro:max \"iprop(\" P:term \" : \" t:term \")\" : term => `((iprop($P) : $t))\n\nsyntax:max \"iprop(\" term \")\" : term\n\nsyntax:max \"<absorb> \" term:40 : term"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(term($t))) => pure t\n | `(iprop($t)) => pure t"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(($P))) => ``((iprop($P)))\n | `(iprop(if $c then $t else $e)) => ``(if $c then iprop($t) else iprop($e))\n | `(iprop(($P : $t))) => ``((iprop($P) : $t))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(emp)) => ``(BIBase.emp)\n | `(iprop(β$Οβ)) => ``(BIBase.pure $Ο)\n | `(iprop($P β§ $Q)) => ``(BIBase.and iprop($P) iprop($Q))\n | `(iprop($P β¨ $Q)) => ``(BIBase.or iprop($P) iprop($Q))\n | `(iprop($P β $Q)) => ``(BIBase.imp iprop($P) iprop($Q))\n | `(iprop(β $xs, $Ξ¨)) => do expandExplicitBinders ``BIBase.exists xs (β ``(iprop($Ξ¨)))\n | `(iprop($P β $Q)) => ``(BIBase.sep iprop($P) iprop($Q))\n | `(iprop($P -β $Q)) => ``(BIBase.wand iprop($P) iprop($Q))\n | `(iprop(<pers> $P)) => ``(BIBase.persistently iprop($P))\n | `(iprop(β· $P)) => ``(BIBase.later iprop($P))\n\ndelab_rule BIBase.emp\n | `($_) => ``(iprop($(mkIdent `emp)))\ndelab_rule BIBase.pure\n | `($_ $Ο) => ``(iprop(β$Οβ))\ndelab_rule BIBase.and\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β§ $(β unpackIprop Q)))\ndelab_rule BIBase.or\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β¨ $(β unpackIprop Q)))\ndelab_rule BIBase.imp\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule BIBase.forall\n | `($_ fun $x:ident => iprop(β $y:ident $[$z:ident]*, $Ξ¨)) => do\n ``(iprop(β $x:ident $y:ident $[$z:ident]*, $Ξ¨))\n | `($_ fun $x:ident => $Ξ¨) => do ``(iprop(β $x:ident, $(β unpackIprop Ξ¨)))\ndelab_rule BIBase.exists\n | `($_ fun $x:ident => iprop(β $y:ident $[$z:ident]*, $Ξ¨)) => do\n ``(iprop(β $x:ident $y:ident $[$z:ident]*, $Ξ¨))\n | `($_ fun $x:ident => $Ξ¨) => do ``(iprop(β $x:ident, $(β unpackIprop Ξ¨)))\ndelab_rule BIBase.sep\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule BIBase.wand\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) -β $(β unpackIprop Q)))\ndelab_rule BIBase.persistently\n | `($_ $P) => do ``(iprop(<pers> $(β unpackIprop P)))\n\ndelab_rule BIBase.pure\n | `($_ True) => ``(iprop($(mkIdent `True)))\n | `($_ False) => ``(iprop($(mkIdent `False)))\ndelab_rule BIBase.imp\n | `($_ $P iprop(False)) => do ``(iprop(Β¬$(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β _%$tk, $Ξ¨)) => ``(BIBase.forall (fun _%$tk => iprop($Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $x:ident, $Ξ¨)) => ``(BIBase.forall (fun $x => iprop($Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β (_%$tk : $t), $Ξ¨)) => ``(BIBase.forall (fun (_%$tk : $t) => iprop($Ξ¨)))\n | `(iprop(β (_%$tk $xs* : $t), $Ξ¨)) =>\n ``(BIBase.forall (fun (_%$tk : $t) => iprop(β ($xs* : $t), $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β ($x:ident : $t), $Ξ¨)) => ``(BIBase.forall (fun ($x : $t) => iprop($Ξ¨)))\n | `(iprop(β ($x:ident $xs* : $t), $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop(β ($xs* : $t), $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β {_%$tk : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun {_%$tk : $t} => iprop($Ξ¨)))\n | `(iprop(β {_%$tk $xs* : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun {_%$tk : $t} => iprop(β {$xs* : $t}, $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β {$x:ident : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop($Ξ¨)))\n | `(iprop(β {$x:ident $xs* : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop(β {$xs* : $t}, $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $x $y $xs*, $Ξ¨)) => ``(iprop(β $x, β $y $xs*, $Ξ¨))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(True)) => ``(BIBase.pure True)\n | `(iprop(False)) => ``(BIBase.pure False)\n | `(iprop(Β¬$P)) => ``(iprop($P β False))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop($P β $Q)) => ``(iff iprop($P) iprop($Q))\n | `(iprop($P β-β $Q)) => ``(wandIff iprop($P) iprop($Q))\n\ndelab_rule iff\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule wandIff\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β-β $(β unpackIprop Q)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(<affine> $P)) => ``(affinely iprop($P))\n | `(iprop(<absorb> $P)) => ``(absorbingly iprop($P))\n\ndelab_rule affinely\n | `($_ $P) => do ``(iprop(<affine> $(β unpackIprop P)))\ndelab_rule absorbingly\n | `($_ $P) => do ``(iprop(<absorb> $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β‘ $P)) => ``(intuitionistically iprop($P))\n\ndelab_rule intuitionistically\n | `($_ $P) => do ``(iprop(β‘ $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(<pers>?$p $P)) => ``(persistentlyIf $p iprop($P))\n | `(iprop(<affine>?$p $P)) => ``(affinelyIf $p iprop($P))\n | `(iprop(<absorb>?$p $P)) => ``(absorbinglyIf $p iprop($P))\n | `(iprop(β‘?$p $P)) => ``(intuitionisticallyIf $p iprop($P))\n\ndelab_rule persistentlyIf\n | `($_ $p $P) => do ``(iprop(<pers>?$p $(β unpackIprop P)))\ndelab_rule affinelyIf\n | `($_ $p $P) => do ``(iprop(<affine>?$p $(β unpackIprop P)))\ndelab_rule absorbinglyIf\n | `($_ $p $P) => do ``(iprop(<absorb>?$p $(β unpackIprop P)))\ndelab_rule intuitionisticallyIf\n | `($_ $p $P) => do ``(iprop(β‘?$p $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β·^[$n] $P)) => ``(laterN $n iprop($P))\n\ndelab_rule laterN\n | `($_ $n $P) => do ``(iprop(β·^[$n] $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $P)) => ``(except0 iprop($P))\n\ndelab_rule except0\n | `($_ $P) => do ``(iprop(β $(β unpackIprop P)))"
},
{
"name": "BIBase",
"content": "class BIBase (PROP : Type u) where\n Entails : PROP β PROP β Prop\n emp : PROP\n pure : Prop β PROP\n and : PROP β PROP β PROP\n or : PROP β PROP β PROP\n imp : PROP β PROP β PROP\n sForall : (PROP β Prop) β PROP\n sExists : (PROP β Prop) β PROP\n sep : PROP β PROP β PROP\n wand : PROP β PROP β PROP\n persistently : PROP β PROP\n later : PROP β PROP"
},
{
"name": "BI",
"content": "class BI (PROP : Type _) extends COFE PROP, BI.BIBase PROP where\n Equiv P Q := P β£β’ Q\n\n entails_preorder : Preorder Entails\n equiv_iff {P Q : PROP} : (P β‘ Q) β P β£β’ Q := by admit /- proof elided -/"
},
{
"name": "BILoeb",
"content": "class BILoeb (PROP : Type _) [BI PROP] where\n loeb_weak {P : PROP} : (β· P β’ P) β True β’ P"
},
{
"name": "liftRel",
"content": "def liftRel (R : Ξ± β Ξ² β Prop) (A : Ξ± β Prop) (B : Ξ² β Prop) : Prop :=\n (β a, A a β β b, B b β§ R a b) β§ (β b, B b β β a, A a β§ R a b)"
},
{
"name": "Preorder",
"content": "class Preorder (R : Relation Ξ±) extends Reflexive R, Transitive R"
},
{
"name": "Reflexive",
"content": "class Reflexive (R : Relation Ξ±) where\n refl {x : Ξ±} : R x x"
},
{
"name": "Relation",
"content": "abbrev Relation (Ξ± : Type _) := Ξ± β Ξ± β Prop"
},
{
"name": "Transitive",
"content": "class Transitive (R : Relation Ξ±) where\n trans {x y z : Ξ±} : R x y β R y z β R x z"
},
{
"name": "NonExpansiveβ",
"content": "class NonExpansiveβ [OFE Ξ±] [OFE Ξ²] [OFE Ξ³] (f : Ξ± β Ξ² β Ξ³) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β β β¦yβ yββ¦, yβ β‘{n}β‘ yβ β f xβ yβ β‘{n}β‘ f xβ yβ"
},
{
"name": "OFE.ContractiveHom.fixpoint_ne",
"content": "instance OFE.ContractiveHom.fixpoint_ne [COFE Ξ±] [Inhabited Ξ±] :\n NonExpansive (ContractiveHom.fixpoint (Ξ± := Ξ±)) where\n ne n f1 f2 H := by admit /- proof elided -/"
},
{
"name": "ContractiveHom",
"content": "@[ext] structure ContractiveHom (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] extends Hom Ξ± Ξ² where\n [contractive : Contractive f]\n ne := ne_of_contractive f"
},
{
"name": "OFE.Option.some.ne",
"content": "instance OFE.Option.some.ne [OFE Ξ±] : OFE.NonExpansive (some : Ξ± β Option Ξ±) := β¨fun _ _ _ => idβ©"
},
{
"name": "Option.merge_ne",
"content": "instance Option.merge_ne [OFE Ξ±] {op : Ξ± β Ξ± β Ξ±} [NonExpansiveβ op] :\n NonExpansiveβ (Option.merge op) where\n ne n x1 x2 Hx y1 y2 Hy := by admit /- proof elided -/"
},
{
"name": "NonExpansive",
"content": "class NonExpansive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β f xβ β‘{n}β‘ f xβ"
},
{
"name": "COFE.OFunctor.constOF_RFunctor",
"content": "instance COFE.OFunctor.constOF_RFunctor [CMRA B] : RFunctor (constOF B) where\n map f g := by admit /- proof elided -/"
},
{
"name": "IsCOFE",
"content": "class IsCOFE (Ξ± : Type _) [OFE Ξ±] where\n compl : Chain Ξ± β Ξ±\n conv_compl {c : Chain Ξ±} : compl c β‘{n}β‘ c n"
},
{
"name": "Chain",
"content": "structure Chain (Ξ± : Type _) [OFE Ξ±] where\n chain : Nat β Ξ±\n cauchy : n β€ i β chain i β‘{n}β‘ chain n"
},
{
"name": "Affine",
"content": "class Affine [BI PROP] (P : PROP) where\n affine : P β’ emp"
},
{
"name": "LawfulBigOp",
"content": "class LawfulBigOp (f : PROP β PROP β PROP) (unit : outParam PROP)\n (eq : outParam (PROP β PROP β Prop)) where\n refl : eq a a\n symm : eq a b β eq b a\n trans : eq a b β eq b c β eq a c\n comm : eq (f a b) (f b a)\n assoc : eq (f (f a b) c) (f a (f b c))\n left_id : eq (f unit a) a\n congr_l : eq a a' β eq (f a b) (f a' b)"
},
{
"name": "intuitionistically",
"content": "def intuitionistically [BIBase PROP] (P : PROP) : PROP := iprop(<affine> <pers> P)"
},
{
"name": "bigAnd",
"content": "def bigAnd [BIBase PROP] (Ps : List PROP) : PROP := bigOp and iprop(True) Ps"
},
{
"name": "bigOp",
"content": "def bigOp (f : PROP β PROP β PROP) (unit : PROP) : List PROP β PROP\n | [] => unit\n | [P] => P\n | P :: Ps => f P (bigOp f unit Ps)"
},
{
"name": "absorbingly",
"content": "def absorbingly [BIBase PROP] (P : PROP) : PROP := iprop(True β P)"
},
{
"name": "BiEntails",
"content": "structure BiEntails [BIBase PROP] (P Q : PROP) where\n mp : P β’ Q\n mpr : Q β’ P"
},
{
"name": "persistentlyIf",
"content": "def persistentlyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then <pers> P else P)"
},
{
"name": "intuitionisticallyIf",
"content": "def intuitionisticallyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then β‘ P else P)"
},
{
"name": "bigSep",
"content": "def bigSep [BIBase PROP] (Ps : List PROP) : PROP := bigOp sep iprop(emp) Ps"
},
{
"name": "affinely",
"content": "def affinely [BIBase PROP] (P : PROP) : PROP := iprop(emp β§ P)"
},
{
"name": "bigOr",
"content": "def bigOr [BIBase PROP] (Ps : List PROP) : PROP := bigOp or iprop(False) Ps"
},
{
"name": "absorbinglyIf",
"content": "def absorbinglyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then <absorb> P else P)"
},
{
"name": "affinelyIf",
"content": "def affinelyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then <affine> P else P)"
},
{
"name": "wandIff",
"content": "def wandIff [BIBase PROP] (P Q : PROP) : PROP := iprop((P -β Q) β§ (Q -β P))"
},
{
"name": "scoped infix:40 \" β‘ \" => OFE.Equiv",
"content": "scoped infix:40 \" β‘ \" => OFE.Equiv"
},
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y"
},
{
"name": "infixr:25 \" -c> \" => ContractiveHom",
"content": "infixr:25 \" -c> \" => ContractiveHom"
},
{
"name": "notation:40 \"[β§] \" Ps:max => bigAnd Ps",
"content": "notation:40 \"[β§] \" Ps:max => bigAnd Ps"
},
{
"name": "notation:40 \"[β¨] \" Ps:max => bigOr Ps",
"content": "notation:40 \"[β¨] \" Ps:max => bigOr Ps"
},
{
"name": "notation:40 \"[β] \" Ps:max => bigSep Ps",
"content": "notation:40 \"[β] \" Ps:max => bigSep Ps"
}
] | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "Dist.trans",
"content": "theorem Dist.trans [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ y β y β‘{n}β‘ z β x β‘{n}β‘ z"
},
{
"name": "BIBase.BiEntails.trans",
"content": "theorem BIBase.BiEntails.trans [BI PROP] {P Q R : PROP} (h1 : P β£β’ Q) (h2 : Q β£β’ R) : P β£β’ R"
},
{
"name": "BIBase.Entails.trans",
"content": "theorem BIBase.Entails.trans [BI PROP] {P Q R : PROP} (h1 : P β’ Q) (h2 : Q β’ R) : P β’ R"
},
{
"name": "Equiv.trans",
"content": "theorem Equiv.trans [OFE Ξ±] {x : Ξ±} : x β‘ y β y β‘ z β x β‘ z"
},
{
"name": "equiv_eqv",
"content": "theorem equiv_eqv [ofe : OFE Ξ±] : Equivalence ofe.Equiv"
},
{
"name": "Dist.symm",
"content": "@[symm] theorem Dist.symm [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ y β y β‘{n}β‘ x"
},
{
"name": "Dist.rfl",
"content": "@[simp, refl] theorem Dist.rfl [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ x"
},
{
"name": "DistLater.trans",
"content": "theorem DistLater.trans [OFE Ξ±] {n} {x : Ξ±} (h1 : DistLater n x y) (h2 : DistLater n y z) :\n DistLater n x z"
}
] | [] | [
{
"name": "Iris.BI.and_elim_l'",
"content": "theorem and_elim_l' [BI PROP] {P Q R : PROP} (h : P β’ R) : P β§ Q β’ R"
},
{
"name": "Iris.BI.and_elim_r'",
"content": "theorem and_elim_r' [BI PROP] {P Q R : PROP} (h : Q β’ R) : P β§ Q β’ R"
},
{
"name": "Iris.BI.and_symm",
"content": "theorem and_symm [BI PROP] {P Q : PROP} : P β§ Q β’ Q β§ P"
},
{
"name": "Iris.BI.imp_intro'",
"content": "theorem imp_intro' [BI PROP] {P Q R : PROP} (h : Q β§ P β’ R) : P β’ Q β R"
},
{
"name": "Iris.BI.imp_elim'",
"content": "theorem imp_elim' [BI PROP] {P Q R : PROP} (h : Q β’ P β R) : P β§ Q β’ R"
},
{
"name": "Iris.BI.imp_elim_l",
"content": "theorem imp_elim_l [BI PROP] {P Q : PROP} : (P β Q) β§ P β’ Q"
},
{
"name": "Iris.BI.imp_elim_r",
"content": "theorem imp_elim_r [BI PROP] {P Q : PROP} : P β§ (P β Q) β’ Q"
},
{
"name": "Iris.BI.true_intro",
"content": "theorem true_intro [BI PROP] {P : PROP} : P β’ True"
},
{
"name": "Iris.BI.and_mono",
"content": "@[rw_mono_rule]\ntheorem and_mono [BI PROP] {P P' Q Q' : PROP} (h1 : P β’ Q) (h2 : P' β’ Q') : P β§ P' β’ Q β§ Q'"
},
{
"name": "Iris.BI.and_mono_l",
"content": "theorem and_mono_l [BI PROP] {P P' Q : PROP} (h : P β’ P') : P β§ Q β’ P' β§ Q"
},
{
"name": "Iris.BI.and_mono_r",
"content": "theorem and_mono_r [BI PROP] {P Q Q' : PROP} (h : Q β’ Q') : P β§ Q β’ P β§ Q'"
},
{
"name": "Iris.BI.and_congr",
"content": "@[rw_mono_rule]\ntheorem and_congr [BI PROP] {P P' Q Q' : PROP} (h1 : P β£β’ Q) (h2 : P' β£β’ Q') : P β§ P' β£β’ Q β§ Q'"
},
{
"name": "Iris.BI.and_congr_r",
"content": "theorem and_congr_r [BI PROP] {P Q Q' : PROP} (h : Q β£β’ Q') : P β§ Q β£β’ P β§ Q'"
},
{
"name": "Iris.BI.and_self",
"content": "theorem and_self [BI PROP] {P : PROP} : P β§ P β£β’ P"
},
{
"name": "Iris.BI.and_comm",
"content": "theorem and_comm [BI PROP] {P Q : PROP} : P β§ Q β£β’ Q β§ P"
},
{
"name": "Iris.BI.and_assoc",
"content": "theorem and_assoc [BI PROP] {P Q R : PROP} : (P β§ Q) β§ R β£β’ P β§ Q β§ R"
},
{
"name": "Iris.BI.sep_mono_l",
"content": "theorem sep_mono_l [BI PROP] {P P' Q : PROP} (h : P β’ P') : P β Q β’ P' β Q"
},
{
"name": "Iris.BI.sep_comm",
"content": "theorem sep_comm [BI PROP] {P Q : PROP} : P β Q β£β’ Q β P"
},
{
"name": "Iris.BI.sep_emp",
"content": "theorem sep_emp [BI PROP] {P : PROP} : P β emp β£β’ P"
},
{
"name": "Iris.BI.true_sep_2",
"content": "theorem true_sep_2 [BI PROP] {P : PROP} : P β’ True β P"
},
{
"name": "Iris.BI.wand_elim'",
"content": "theorem wand_elim' [BI PROP] {P Q R : PROP} (h : Q β’ P -β R) : P β Q β’ R"
},
{
"name": "Iris.BI.wand_elim_r",
"content": "theorem wand_elim_r [BI PROP] {P Q : PROP} : P β (P -β Q) β’ Q"
},
{
"name": "Iris.BI.pure_elim",
"content": "theorem pure_elim [BI PROP] (Ο : Prop) {Q R : PROP} (h1 : Q β’ βΟβ) (h2 : Ο β Q β’ R) : Q β’ R"
},
{
"name": "Iris.BI.pure_elim_l",
"content": "theorem pure_elim_l [BI PROP] {Ο : Prop} {Q R : PROP} (h : Ο β Q β’ R) : βΟβ β§ Q β’ R"
},
{
"name": "Iris.BI.pure_elim_r",
"content": "theorem pure_elim_r [BI PROP] {Ο : Prop} {Q R : PROP} (h : Ο β Q β’ R) : Q β§ βΟβ β’ R"
},
{
"name": "Iris.BI.affinely_congr",
"content": "@[rw_mono_rule]\ntheorem affinely_congr [BI PROP] {P P' : PROP} (h : P β£β’ P') :\n <affine> P β£β’ <affine> P'"
},
{
"name": "Iris.BI.affinely_elim",
"content": "theorem affinely_elim [BI PROP] {P : PROP} : <affine> P β’ P"
},
{
"name": "Iris.BI.affinely_mono",
"content": "@[rw_mono_rule]\ntheorem affinely_mono [BI PROP] {P Q : PROP} : (P β’ Q) β <affine> P β’ <affine> Q"
},
{
"name": "Iris.BI.absorbingly_intro",
"content": "theorem absorbingly_intro [BI PROP] {P : PROP} : P β’ <absorb> P"
},
{
"name": "Iris.BI.persistently_absorb_r",
"content": "theorem persistently_absorb_r [BI PROP] {P Q : PROP} : P β <pers> Q β’ <pers> Q"
},
{
"name": "Iris.BI.absorbingly_persistently",
"content": "theorem absorbingly_persistently [BI PROP] {P : PROP} : <absorb> <pers> P β£β’ <pers> P"
},
{
"name": "Iris.BI.persistently_and",
"content": "theorem persistently_and [BI PROP] {P Q : PROP} : <pers> (P β§ Q) β£β’ <pers> P β§ <pers> Q"
},
{
"name": "Iris.BI.persistently_emp_intro",
"content": "theorem persistently_emp_intro [BI PROP] {P : PROP} : P β’ <pers> emp"
},
{
"name": "Iris.BI.persistently_affinely",
"content": "theorem persistently_affinely [BI PROP] {P : PROP} : <pers> <affine> P β£β’ <pers> P"
},
{
"name": "Iris.BI.intuitionistically_elim",
"content": "theorem intuitionistically_elim [BI PROP] {P : PROP} : β‘ P β’ P"
},
{
"name": "Iris.BI.persistently_idem",
"content": "theorem persistently_idem [BI PROP] {P : PROP} : <pers> <pers> P β£β’ <pers> P"
},
{
"name": "Iris.BI.intuitionistically_mono",
"content": "@[rw_mono_rule]\ntheorem intuitionistically_mono [BI PROP] {P Q : PROP} (h : P β’ Q) : β‘ P β’ β‘ Q"
},
{
"name": "Iris.BI.intuitionistically_idem",
"content": "theorem intuitionistically_idem [BI PROP] {P : PROP} : β‘ β‘ P β£β’ β‘ P"
},
{
"name": "Iris.BI.persistently_of_intuitionistically",
"content": "theorem persistently_of_intuitionistically [BI PROP] {P : PROP} : β‘ P β’ <pers> P"
},
{
"name": "Iris.BI.later_impl",
"content": "theorem later_impl [BI PROP] {P Q : PROP} : β· (P β Q) β’ β· P β β· Q"
},
{
"name": "Iris.BI.entails_impl_true",
"content": "theorem entails_impl_true [BI PROP] {P Q : PROP} :\n (P β’ Q) β iprop((True : PROP) β’ (P β Q))"
},
{
"name": "Iris.BI.loeb",
"content": "theorem loeb [BI PROP] [BILoeb PROP] {P : PROP} : (β· P β P) β’ P"
}
] | import Iris.BI.Classes
import Iris.BI.Extensions
import Iris.BI.BI
import Iris.Std.Classes
import Iris.Std.Rewrite
import Iris.Std.TC
namespace Iris.BI
open Iris.Std BI | theorem loeb_wand_intuitionistically [BI PROP] [BILoeb PROP] {P : PROP} :
β‘ (β‘ β· P -β P) β’ P := | := by
refine .trans ?_ intuitionistically_elim
refine .trans ?_ loeb
refine imp_intro' ?_
refine (and_mono (later_mono persistently_of_intuitionistically) .rfl).trans ?_
refine (and_mono later_persistently.mp .rfl).trans ?_
refine persistently_and_intuitionistically_sep_l.mp.trans ?_
refine (sep_mono intuitionistically_idem.mpr .rfl).trans ?_
exact intuitionistically_sep_2.trans (intuitionistically_mono wand_elim_r) | 6 | 91 | false | Framework |
230 | Iris.BI.plainly_persistently_elim | theorem plainly_persistently_elim : β <pers> P β£β’ β P | iris-lean | src/Iris/BI/Plainly.lean | [
"import Iris.Algebra",
"import Iris.BI.DerivedLaws",
"import src.Iris.Algebra.CMRA",
"import src.Iris.Algebra.OFE",
"import src.Iris.BI.BI",
"import src.Iris.BI.DerivedLaws",
"import src/Iris/Instances/UPred/Instance.lean",
"import Iris.BI.BI",
"import Iris.BI.Classes"
] | [
{
"name": "Lean.MonadQuotation",
"module": "Init.Prelude"
},
{
"name": "Lean.MonadRef",
"module": "Init.Prelude"
},
{
"name": "Monad",
"module": "Init.Prelude"
},
{
"name": "m",
"module": "QqTest.matching"
},
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "Option.merge",
"module": "Init.Data.Option.Basic"
},
{
"name": "id",
"module": "Init.Prelude"
},
{
"name": "Equivalence",
"module": "Init.Core"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Bool",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
}
] | [
{
"name": "syntax term:26 \" ==β \" term:25 : term",
"content": "syntax term:26 \" ==β \" term:25 : term\n\nsyntax term \"={ \" term \" , \" term \" }=β \" term : term\n\nsyntax term \"={ \" term \" }=β \" term : term\n\nsyntax term \"={ \" term \" }[ \" term \" ]β·=β \" term : term\n\nsyntax term \"={ \" term \" }β·=β \" term : term\n\nsyntax term \"={ \" term \" }[ \" term \" ]β·^\" term \"=β \" term : term\n\nsyntax term \"={ \" term \" }β·^\" term \"=β \" term : term"
},
{
"name": "macro:max \"iprop(\" P:term \" : \" t:term \")\" : term => `((ipro",
"content": "macro:max \"iprop(\" P:term \" : \" t:term \")\" : term => `((iprop($P) : $t))\n\nsyntax:max \"iprop(\" term \")\" : term"
},
{
"name": "macro \"β\" xs:explicitBinders \", \" b:term : term => do",
"content": "macro \"β\" xs:explicitBinders \", \" b:term : term => do\n return β¨β expandExplicitBinders ``BIBase.exists xs bβ©"
},
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y\n\nsyntax:max \"<pers> \" term:40 : term"
},
{
"name": "macro:25 P:term:29 \" β’ \" Q:term:25 : term => ``(BIBase.Entai",
"content": "macro:25 P:term:29 \" β’ \" Q:term:25 : term => ``(BIBase.Entails iprop($P) iprop($Q))\n\ndelab_rule BIBase.Entails\n | `($_ $P $Q) => do ``($(β unpackIprop P) β’ $(β unpackIprop Q))"
},
{
"name": "macro:25 P:term:29 \" β£β’ \" Q:term:29 : term => ``(BiEntails i",
"content": "macro:25 P:term:29 \" β£β’ \" Q:term:29 : term => ``(BiEntails iprop($P) iprop($Q))\n\ndelab_rule BIBase.Entails\n | `($_ iprop(emp) $P) => do ``(β’ $(β unpackIprop P))\n\ndelab_rule BIBase.BiEntails\n | `($_ $P $Q) => do ``($(β unpackIprop P) β£β’ $(β unpackIprop Q))\n\nsyntax \"β\" term \"β\" : term\n\nsyntax:max \"β· \" term:40 : term\n\nsyntax \"β \" term:40 : term"
},
{
"name": "notation:50 x \" βΌ{\" n \"} \" y:51 => IncludedN n x y",
"content": "notation:50 x \" βΌ{\" n \"} \" y:51 => IncludedN n x y\n\nsyntax:max \"<affine> \" term:40 : term\n\nsyntax:max \"β‘ \" term:40 : term\n\nsyntax:max \"<absorb> \" term:40 : term"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(|==> $P)) => ``(BUpd.bupd iprop($P))\n | `(iprop($P ==β $Q)) => ``(BIBase.wand iprop($P) (BUpd.bupd iprop($Q)))\n\ndelab_rule BUpd.bupd\n | `($_ $P) => do ``(iprop(|==> $(β Iris.BI.unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(|={ $E1 , $E2 }=> $P)) => ``(FUpd.fupd $E1 $E2 iprop($P))\n | `(iprop($P ={ $E1 , $E2 }=β $Q)) => ``(BIBase.wand iprop($P) (FUpd.fupd $E1 $E2 iprop($Q)))\n | `(iprop(|={ $E1 }=> $P)) => ``(FUpd.fupd $E1 $E1 iprop($P))\n | `(iprop($P ={ $E1 }=β $Q)) => ``(BIBase.wand iprop($P) (FUpd.fupd $E1 $E1 iprop($Q)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(|={ $E1 }[ $E2 ]β·=> $P)) => ``(iprop(|={$E1, $E2}=> β· (|={ $E2, $E1 }=> iprop($P))))\n | `(iprop($P ={ $E1 }[ $E2 ]β·=β $Q)) => ``(iprop(iprop($P) -β |={$E1}[$E2]β·=> iprop($Q)))\n | `(iprop(|={ $E1 }β·=> $P)) => ``(iprop(|={$E1}[$E1]β·=> iprop($P)))\n | `(iprop($P ={ $E1 }β·=β $Q)) => ``(iprop(iprop($P) ={$E1}[$E1]β·=β iprop($Q)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(|={ $E1 }[ $E2 ]β·^$n=> $P)) => ``(iprop(|={$E1, $E2}=> β·^[$n] (|={ $E2, $E1 }=> iprop($P))))\n | `(iprop($P ={ $E1 }[ $E2 ]β·^$n=β $Q)) => ``(iprop(iprop($P) -β |={$E1}[$E2]β·^$n=> iprop($Q)))\n | `(iprop(|={ $E1 }β·^$n=> $P)) => ``(iprop(|={$E1}[$E1]β·^$n=> iprop($P)))\n | `(iprop($P ={ $E1 }β·^$n=β $Q)) => ``(iprop(iprop($P) ={$E1}[$E1]β·^$n=β iprop($Q)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(emp)) => ``(BIBase.emp)\n | `(iprop(β$Οβ)) => ``(BIBase.pure $Ο)\n | `(iprop($P β§ $Q)) => ``(BIBase.and iprop($P) iprop($Q))\n | `(iprop($P β¨ $Q)) => ``(BIBase.or iprop($P) iprop($Q))\n | `(iprop($P β $Q)) => ``(BIBase.imp iprop($P) iprop($Q))\n | `(iprop(β $xs, $Ξ¨)) => do expandExplicitBinders ``BIBase.exists xs (β ``(iprop($Ξ¨)))\n | `(iprop($P β $Q)) => ``(BIBase.sep iprop($P) iprop($Q))\n | `(iprop($P -β $Q)) => ``(BIBase.wand iprop($P) iprop($Q))\n | `(iprop(<pers> $P)) => ``(BIBase.persistently iprop($P))\n | `(iprop(β· $P)) => ``(BIBase.later iprop($P))\n\ndelab_rule BIBase.emp\n | `($_) => ``(iprop($(mkIdent `emp)))\ndelab_rule BIBase.pure\n | `($_ $Ο) => ``(iprop(β$Οβ))\ndelab_rule BIBase.and\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β§ $(β unpackIprop Q)))\ndelab_rule BIBase.or\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β¨ $(β unpackIprop Q)))\ndelab_rule BIBase.imp\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule BIBase.forall\n | `($_ fun $x:ident => iprop(β $y:ident $[$z:ident]*, $Ξ¨)) => do\n ``(iprop(β $x:ident $y:ident $[$z:ident]*, $Ξ¨))\n | `($_ fun $x:ident => $Ξ¨) => do ``(iprop(β $x:ident, $(β unpackIprop Ξ¨)))\ndelab_rule BIBase.exists\n | `($_ fun $x:ident => iprop(β $y:ident $[$z:ident]*, $Ξ¨)) => do\n ``(iprop(β $x:ident $y:ident $[$z:ident]*, $Ξ¨))\n | `($_ fun $x:ident => $Ξ¨) => do ``(iprop(β $x:ident, $(β unpackIprop Ξ¨)))\ndelab_rule BIBase.sep\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule BIBase.wand\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) -β $(β unpackIprop Q)))\ndelab_rule BIBase.persistently\n | `($_ $P) => do ``(iprop(<pers> $(β unpackIprop P)))\n\ndelab_rule BIBase.pure\n | `($_ True) => ``(iprop($(mkIdent `True)))\n | `($_ False) => ``(iprop($(mkIdent `False)))\ndelab_rule BIBase.imp\n | `($_ $P iprop(False)) => do ``(iprop(Β¬$(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β _%$tk, $Ξ¨)) => ``(BIBase.forall (fun _%$tk => iprop($Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $x:ident, $Ξ¨)) => ``(BIBase.forall (fun $x => iprop($Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β (_%$tk : $t), $Ξ¨)) => ``(BIBase.forall (fun (_%$tk : $t) => iprop($Ξ¨)))\n | `(iprop(β (_%$tk $xs* : $t), $Ξ¨)) =>\n ``(BIBase.forall (fun (_%$tk : $t) => iprop(β ($xs* : $t), $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β ($x:ident : $t), $Ξ¨)) => ``(BIBase.forall (fun ($x : $t) => iprop($Ξ¨)))\n | `(iprop(β ($x:ident $xs* : $t), $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop(β ($xs* : $t), $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β {_%$tk : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun {_%$tk : $t} => iprop($Ξ¨)))\n | `(iprop(β {_%$tk $xs* : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun {_%$tk : $t} => iprop(β {$xs* : $t}, $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β {$x:ident : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop($Ξ¨)))\n | `(iprop(β {$x:ident $xs* : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop(β {$xs* : $t}, $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $x $y $xs*, $Ξ¨)) => ``(iprop(β $x, β $y $xs*, $Ξ¨))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(True)) => ``(BIBase.pure True)\n | `(iprop(False)) => ``(BIBase.pure False)\n | `(iprop(Β¬$P)) => ``(iprop($P β False))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop($P β $Q)) => ``(iff iprop($P) iprop($Q))\n | `(iprop($P β-β $Q)) => ``(wandIff iprop($P) iprop($Q))\n\ndelab_rule iff\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule wandIff\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β-β $(β unpackIprop Q)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(<affine> $P)) => ``(affinely iprop($P))\n | `(iprop(<absorb> $P)) => ``(absorbingly iprop($P))\n\ndelab_rule affinely\n | `($_ $P) => do ``(iprop(<affine> $(β unpackIprop P)))\ndelab_rule absorbingly\n | `($_ $P) => do ``(iprop(<absorb> $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β‘ $P)) => ``(intuitionistically iprop($P))\n\ndelab_rule intuitionistically\n | `($_ $P) => do ``(iprop(β‘ $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(<pers>?$p $P)) => ``(persistentlyIf $p iprop($P))\n | `(iprop(<affine>?$p $P)) => ``(affinelyIf $p iprop($P))\n | `(iprop(<absorb>?$p $P)) => ``(absorbinglyIf $p iprop($P))\n | `(iprop(β‘?$p $P)) => ``(intuitionisticallyIf $p iprop($P))\n\ndelab_rule persistentlyIf\n | `($_ $p $P) => do ``(iprop(<pers>?$p $(β unpackIprop P)))\ndelab_rule affinelyIf\n | `($_ $p $P) => do ``(iprop(<affine>?$p $(β unpackIprop P)))\ndelab_rule absorbinglyIf\n | `($_ $p $P) => do ``(iprop(<absorb>?$p $(β unpackIprop P)))\ndelab_rule intuitionisticallyIf\n | `($_ $p $P) => do ``(iprop(β‘?$p $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β·^[$n] $P)) => ``(laterN $n iprop($P))\n\ndelab_rule laterN\n | `($_ $n $P) => do ``(iprop(β·^[$n] $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $P)) => ``(except0 iprop($P))\n\ndelab_rule except0\n | `($_ $P) => do ``(iprop(β $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $P)) => ``(Plainly.plainly iprop($P))\n\ndelab_rule Plainly.plainly\n | `($_ $P) => do ``(iprop(β $(β Iris.BI.unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β ? $p $P)) => ``(Plainly.plainlyIf $p iprop($P))\n\ndelab_rule Plainly.plainlyIf\n | `($_ $p $P) => do ``(iprop(β ? $p $(β Iris.BI.unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(term($t))) => pure t\n | `(iprop($t)) => pure t"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(($P))) => ``((iprop($P)))\n | `(iprop(if $c then $t else $e)) => ``(if $c then iprop($t) else iprop($e))\n | `(iprop(($P : $t))) => ``((iprop($P) : $t))"
},
{
"name": "unpackIprop",
"content": "partial def unpackIprop [Monad m] [MonadRef m] [MonadQuotation m] : Term β m Term\n | `(iprop($P)) => do `($P)\n | `($P:ident) => do `($P)\n | `(?$P:ident) => do `(?$P)\n | `(($P)) => do `(($(β unpackIprop P)))\n | `($P $[ $Q]*) => do ``($P $[ $Q]*)\n | `(if $c then $t else $e) => do\n let t β unpackIprop t\n let e β unpackIprop e\n `(if $c then $t else $e)\n | `(($P : $t)) => do ``(($(β unpackIprop P) : $t))\n | `($t) => `($t:term)"
},
{
"name": "BIBase",
"content": "class BIBase (PROP : Type u) where\n Entails : PROP β PROP β Prop\n emp : PROP\n pure : Prop β PROP\n and : PROP β PROP β PROP\n or : PROP β PROP β PROP\n imp : PROP β PROP β PROP\n sForall : (PROP β Prop) β PROP\n sExists : (PROP β Prop) β PROP\n sep : PROP β PROP β PROP\n wand : PROP β PROP β PROP\n persistently : PROP β PROP\n later : PROP β PROP"
},
{
"name": "BI",
"content": "class BI (PROP : Type _) extends COFE PROP, BI.BIBase PROP where\n Equiv P Q := P β£β’ Q\n\n entails_preorder : Preorder Entails\n equiv_iff {P Q : PROP} : (P β‘ Q) β P β£β’ Q := by admit /- proof elided -/"
},
{
"name": "liftRel",
"content": "def liftRel (R : Ξ± β Ξ² β Prop) (A : Ξ± β Prop) (B : Ξ² β Prop) : Prop :=\n (β a, A a β β b, B b β§ R a b) β§ (β b, B b β β a, A a β§ R a b)"
},
{
"name": "Preorder",
"content": "class Preorder (R : Relation Ξ±) extends Reflexive R, Transitive R"
},
{
"name": "Reflexive",
"content": "class Reflexive (R : Relation Ξ±) where\n refl {x : Ξ±} : R x x"
},
{
"name": "Relation",
"content": "abbrev Relation (Ξ± : Type _) := Ξ± β Ξ± β Prop"
},
{
"name": "Transitive",
"content": "class Transitive (R : Relation Ξ±) where\n trans {x y z : Ξ±} : R x y β R y z β R x z"
},
{
"name": "NonExpansiveβ",
"content": "class NonExpansiveβ [OFE Ξ±] [OFE Ξ²] [OFE Ξ³] (f : Ξ± β Ξ² β Ξ³) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β β β¦yβ yββ¦, yβ β‘{n}β‘ yβ β f xβ yβ β‘{n}β‘ f xβ yβ"
},
{
"name": "OFE.ContractiveHom.fixpoint_ne",
"content": "instance OFE.ContractiveHom.fixpoint_ne [COFE Ξ±] [Inhabited Ξ±] :\n NonExpansive (ContractiveHom.fixpoint (Ξ± := Ξ±)) where\n ne n f1 f2 H := by admit /- proof elided -/"
},
{
"name": "ContractiveHom",
"content": "@[ext] structure ContractiveHom (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] extends Hom Ξ± Ξ² where\n [contractive : Contractive f]\n ne := ne_of_contractive f"
},
{
"name": "OFE.Option.some.ne",
"content": "instance OFE.Option.some.ne [OFE Ξ±] : OFE.NonExpansive (some : Ξ± β Option Ξ±) := β¨fun _ _ _ => idβ©"
},
{
"name": "Option.merge_ne",
"content": "instance Option.merge_ne [OFE Ξ±] {op : Ξ± β Ξ± β Ξ±} [NonExpansiveβ op] :\n NonExpansiveβ (Option.merge op) where\n ne n x1 x2 Hx y1 y2 Hy := by admit /- proof elided -/"
},
{
"name": "NonExpansive",
"content": "class NonExpansive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β f xβ β‘{n}β‘ f xβ"
},
{
"name": "COFE.OFunctor.constOF_RFunctor",
"content": "instance COFE.OFunctor.constOF_RFunctor [CMRA B] : RFunctor (constOF B) where\n map f g := by admit /- proof elided -/"
},
{
"name": "IsCOFE",
"content": "class IsCOFE (Ξ± : Type _) [OFE Ξ±] where\n compl : Chain Ξ± β Ξ±\n conv_compl {c : Chain Ξ±} : compl c β‘{n}β‘ c n"
},
{
"name": "Chain",
"content": "structure Chain (Ξ± : Type _) [OFE Ξ±] where\n chain : Nat β Ξ±\n cauchy : n β€ i β chain i β‘{n}β‘ chain n"
},
{
"name": "LawfulBigOp",
"content": "class LawfulBigOp (f : PROP β PROP β PROP) (unit : outParam PROP)\n (eq : outParam (PROP β PROP β Prop)) where\n refl : eq a a\n symm : eq a b β eq b a\n trans : eq a b β eq b c β eq a c\n comm : eq (f a b) (f b a)\n assoc : eq (f (f a b) c) (f a (f b c))\n left_id : eq (f unit a) a\n congr_l : eq a a' β eq (f a b) (f a' b)"
},
{
"name": "Included",
"content": "def Included (x y : Ξ±) : Prop := β z, y β‘ x β’ z"
},
{
"name": "CMRA",
"content": "class CMRA (Ξ± : Type _) extends OFE Ξ± where\n pcore : Ξ± β Option Ξ±\n op : Ξ± β Ξ± β Ξ±\n ValidN : Nat β Ξ± β Prop\n Valid : Ξ± β Prop\n\n op_ne : NonExpansive (op x)\n pcore_ne : x β‘{n}β‘ y β pcore x = some cx β\n β cy, pcore y = some cy β§ cx β‘{n}β‘ cy\n validN_ne : x β‘{n}β‘ y β ValidN n x β ValidN n y\n\n valid_iff_validN : Valid x β β n, ValidN n x\n validN_succ : ValidN n.succ x β ValidN n x\n validN_op_left : ValidN n (op x y) β ValidN n x\n\n assoc : op x (op y z) β‘ op (op x y) z\n comm : op x y β‘ op y x\n\n pcore_op_left : pcore x = some cx β op cx x β‘ x\n pcore_idem : pcore x = some cx β pcore cx β‘ some cx\n pcore_op_mono : pcore x = some cx β β y, β cy, pcore (op x y) β‘ some (op cx cy)\n\n extend : ValidN n x β x β‘{n}β‘ op yβ yβ β\n Ξ£' zβ zβ, x β‘ op zβ zβ β§ zβ β‘{n}β‘ yβ β§ zβ β‘{n}β‘ yβ"
},
{
"name": "Commutative",
"content": "class Commutative (R : Relation Ξ±) (f : Ξ² β Ξ² β Ξ±) where\n comm {x y : Ξ²} : R (f x y) (f y x)"
},
{
"name": "intuitionistically",
"content": "def intuitionistically [BIBase PROP] (P : PROP) : PROP := iprop(<affine> <pers> P)"
},
{
"name": "Affine",
"content": "class Affine [BI PROP] (P : PROP) where\n affine : P β’ emp"
},
{
"name": "bigAnd",
"content": "def bigAnd [BIBase PROP] (Ps : List PROP) : PROP := bigOp and iprop(True) Ps"
},
{
"name": "bigOp",
"content": "def bigOp (f : PROP β PROP β PROP) (unit : PROP) : List PROP β PROP\n | [] => unit\n | [P] => P\n | P :: Ps => f P (bigOp f unit Ps)"
},
{
"name": "absorbingly",
"content": "def absorbingly [BIBase PROP] (P : PROP) : PROP := iprop(True β P)"
},
{
"name": "BiEntails",
"content": "structure BiEntails [BIBase PROP] (P Q : PROP) where\n mp : P β’ Q\n mpr : Q β’ P"
},
{
"name": "persistentlyIf",
"content": "def persistentlyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then <pers> P else P)"
},
{
"name": "intuitionisticallyIf",
"content": "def intuitionisticallyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then β‘ P else P)"
},
{
"name": "bigSep",
"content": "def bigSep [BIBase PROP] (Ps : List PROP) : PROP := bigOp sep iprop(emp) Ps"
},
{
"name": "affinely",
"content": "def affinely [BIBase PROP] (P : PROP) : PROP := iprop(emp β§ P)"
},
{
"name": "bigOr",
"content": "def bigOr [BIBase PROP] (Ps : List PROP) : PROP := bigOp or iprop(False) Ps"
},
{
"name": "absorbinglyIf",
"content": "def absorbinglyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then <absorb> P else P)"
},
{
"name": "affinelyIf",
"content": "def affinelyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then <affine> P else P)"
},
{
"name": "wandIff",
"content": "def wandIff [BIBase PROP] (P Q : PROP) : PROP := iprop((P -β Q) β§ (Q -β P))"
},
{
"name": "",
"content": "instance : Plainly (UPred M) := β¨UPred.plainlyβ©"
},
{
"name": "plainly",
"content": "protected def plainly (P : UPred M) : UPred M where\n holds n _ := P n UCMRA.unit\n mono H _ Hn := P.mono H (CMRA.incN_refl UCMRA.unit) Hn"
},
{
"name": "BIUpdate",
"content": "class BIUpdate (PROP : Type _) [BI PROP] extends BUpd PROP where\n [bupd_ne : OFE.NonExpansive (BUpd.bupd (PROP := PROP))]\n intro {P : PROP} : iprop(P β’ |==> P)\n mono {P Q : PROP} : iprop(P β’ Q) β iprop(|==> P β’ |==> Q)\n trans {P : PROP} : iprop(|==> |==> P β’ |==> P)\n frame_r {P R : PROP} : iprop((|==> P) β R β’ |==> (P β R))"
},
{
"name": "UPred",
"content": "@[ext]\nstructure UPred (M : Type _) [UCMRA M] where\n holds : Nat β M β Prop\n mono {n1 n2 x1 x2} : holds n1 x1 β x1 βΌ{n2} x2 β n2 β€ n1 β holds n2 x2"
},
{
"name": "IsModal",
"content": "class IsModal [BI PROP1] [BI PROP2] (M : PROP1 β PROP2)\n (iaction saction : ModalityAction PROP1 PROP2) where\n spec_intuitionistic : iaction.intuitionistic_action_spec M\n spec_spatial : saction.spatial_action_spec M\n emp : iprop(emp) β’ M iprop(emp)\n mono : β {P Q}, (P β’ Q) β M P β’ M Q\n sep : β {P Q}, iprop(M P β M Q) β’ M iprop(P β Q)"
},
{
"name": "UCMRA",
"content": "class UCMRA (Ξ± : Type _) extends CMRA Ξ± where\n unit : Ξ±\n unit_valid : β unit\n unit_left_id : unit β’ x β‘ x\n pcore_unit : pcore unit β‘ some unit"
},
{
"name": "pcore",
"content": "def pcore : DFrac F β Option (DFrac F)\n | own _ => none\n | .discard => some discard\n | ownDiscard _ => some discard"
},
{
"name": "DFrac",
"content": "inductive DFrac (F : Type _) where\n \n| own (f : F) : DFrac F\n \n| discard : DFrac F\n \n| ownDiscard (f : F) : DFrac F"
},
{
"name": "op",
"content": "def op : DFrac F β DFrac F β DFrac F\n | .discard, .discard => discard\n | own f, .discard\n | ownDiscard f, .discard\n | .discard, own f\n | .discard, ownDiscard f => ownDiscard f\n | own f, own f' => own (f + f')\n | own f, ownDiscard f'\n | ownDiscard f, own f'\n | ownDiscard f, ownDiscard f' => ownDiscard (f + f')"
},
{
"name": "Associative",
"content": "class Associative (R : Relation Ξ±) (f : Ξ± β Ξ± β Ξ±) where\n assoc {x y z : Ξ±} : R (f (f x y) z) (f x (f y z))"
},
{
"name": "",
"content": "instance : BIPlainly (UPred M) where\n mono H _ _ _ := H _ _ CMRA.unit_validN\n elim_persistently {P} n x Hx := by admit /- proof elided -/"
},
{
"name": "persistently",
"content": "protected def persistently (P : UPred M) : UPred M where\n holds n x := P n (CMRA.core x)\n mono H Hx Hn := P.mono H (CMRA.core_incN_core Hx) Hn"
},
{
"name": "core",
"content": "def core (x : Ξ±) := (pcore x).getD x"
},
{
"name": "BIPlainly",
"content": "class BIPlainly (PROP : Type _) [Iris.BI PROP] extends Plainly PROP where\n [ne : Iris.OFE.NonExpansive (Plainly.plainly (PROP := PROP))]\n mono {P Q : PROP} : (P β’ Q) β β P β’ β Q\n elim_persistently {P : PROP} : β P β’ <pers> P\n idem {P : PROP} : β P β’ β β P\n plainly_sForall_2 {Ξ¦ : PROP β Prop} : (β p, βΞ¦ pβ β β p) β’ β sForall Ξ¦\n plainly_impl_plainly {P Q : PROP} : (β P β β Q) β’ β (β P β Q)\n emp_intro {P : PROP} : P β’ β emp\n plainly_absorb {P Q : PROP} : β P β Q β’ β P\n later_plainly {P : PROP} : β· β P β£β’ β β· P"
},
{
"name": "Idempotent",
"content": "class Idempotent (R : Relation Ξ±) (f : Ξ± β Ξ± β Ξ±) where\n idem {x : Ξ±} : R (f x x) x"
},
{
"name": "",
"content": "instance : BIPlainlyExists (UPred M) where\n plainly_sExists_1 _ _ _ := fun β¨_, hpβ© => β¨_, β¨_, rflβ©, hpβ©"
},
{
"name": "BIPlainlyExists",
"content": "class BIPlainlyExists (PROP : Type _) [Iris.BI PROP] [BIPlainly PROP] where\n plainly_sExists_1 {Ξ¦ : PROP β Prop} : β sExists Ξ¦ β’ β p, βΞ¦ pβ β§ β p"
},
{
"name": "scoped infix:40 \" β‘ \" => OFE.Equiv",
"content": "scoped infix:40 \" β‘ \" => OFE.Equiv"
},
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y"
},
{
"name": "infixr:25 \" -c> \" => ContractiveHom",
"content": "infixr:25 \" -c> \" => ContractiveHom"
},
{
"name": "notation:40 \"[β§] \" Ps:max => bigAnd Ps",
"content": "notation:40 \"[β§] \" Ps:max => bigAnd Ps"
},
{
"name": "notation:40 \"[β¨] \" Ps:max => bigOr Ps",
"content": "notation:40 \"[β¨] \" Ps:max => bigOr Ps"
},
{
"name": "notation:40 \"[β] \" Ps:max => bigSep Ps",
"content": "notation:40 \"[β] \" Ps:max => bigSep Ps"
},
{
"name": "infix:60 \" β’ \" => op",
"content": "infix:60 \" β’ \" => op"
},
{
"name": "infix:50 \" βΌ \" => Included",
"content": "infix:50 \" βΌ \" => Included"
}
] | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "imp_intro'",
"content": "theorem imp_intro' [BI PROP] {P Q R : PROP} (h : Q β§ P β’ R) : P β’ Q β R"
},
{
"name": "and_comm",
"content": "theorem and_comm [BI PROP] {P Q : PROP} : P β§ Q β£β’ Q β§ P"
},
{
"name": "and_symm",
"content": "theorem and_symm [BI PROP] {P Q : PROP} : P β§ Q β’ Q β§ P"
},
{
"name": "imp_elim'",
"content": "theorem imp_elim' [BI PROP] {P Q R : PROP} (h : Q β’ P β R) : P β§ Q β’ R"
},
{
"name": "pure_elim",
"content": "theorem pure_elim [BI PROP] (Ο : Prop) {Q R : PROP} (h1 : Q β’ βΟβ) (h2 : Ο β Q β’ R) : Q β’ R"
},
{
"name": "and_self",
"content": "theorem and_self [BI PROP] {P : PROP} : P β§ P β£β’ P"
},
{
"name": "forall_intro",
"content": "theorem forall_intro [BI PROP] {P : PROP} {Ξ¨ : Ξ± β PROP} (h : β a, P β’ Ξ¨ a) : P β’ β a, Ξ¨ a"
},
{
"name": "forall_elim",
"content": "theorem forall_elim [BI PROP] {Ξ¨ : Ξ± β PROP} (a : Ξ±) : (β a, Ξ¨ a) β’ Ξ¨ a"
},
{
"name": "Included.trans",
"content": "theorem Included.trans : (x : Ξ±) βΌ y β y βΌ z β x βΌ z"
},
{
"name": "inc_trans",
"content": "theorem inc_trans {x y z : Ξ±} : x βΌ y β y βΌ z β x βΌ z"
},
{
"name": "op_left_eqv",
"content": "theorem op_left_eqv {x y : Ξ±} (z : Ξ±) (e : x β‘ y) : x β’ z β‘ y β’ z"
},
{
"name": "_root_.Iris.OFE.Dist.op_r",
"content": "theorem _root_.Iris.OFE.Dist.op_r {x y z : Ξ±} : y β‘{n}β‘ z β x β’ y β‘{n}β‘ x β’ z"
},
{
"name": "op_right_dist",
"content": "theorem op_right_dist (x : Ξ±) {y z : Ξ±} (e : y β‘{n}β‘ z) : x β’ y β‘{n}β‘ x β’ z"
},
{
"name": "_root_.Iris.OFE.Equiv.op_r",
"content": "theorem _root_.Iris.OFE.Equiv.op_r {x y z : Ξ±} : y β‘ z β x β’ y β‘ x β’ z"
},
{
"name": "op_right_eqv",
"content": "theorem op_right_eqv (x : Ξ±) {y z : Ξ±} (e : y β‘ z) : x β’ y β‘ x β’ z"
},
{
"name": "IncludedN.trans",
"content": "theorem IncludedN.trans : (x : Ξ±) βΌ{n} y β y βΌ{n} z β x βΌ{n} z"
},
{
"name": "incN_trans",
"content": "theorem incN_trans {x y z : Ξ±} : x βΌ{n} y β y βΌ{n} z β x βΌ{n} z"
},
{
"name": "op_left_dist",
"content": "theorem op_left_dist {x y : Ξ±} (z : Ξ±) (e : x β‘{n}β‘ y) : x β’ z β‘{n}β‘ y β’ z"
},
{
"name": "Dist.trans",
"content": "theorem Dist.trans [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ y β y β‘{n}β‘ z β x β‘{n}β‘ z"
},
{
"name": "BIBase.BiEntails.trans",
"content": "theorem BIBase.BiEntails.trans [BI PROP] {P Q R : PROP} (h1 : P β£β’ Q) (h2 : Q β£β’ R) : P β£β’ R"
},
{
"name": "BIBase.Entails.trans",
"content": "theorem BIBase.Entails.trans [BI PROP] {P Q R : PROP} (h1 : P β’ Q) (h2 : Q β’ R) : P β’ R"
},
{
"name": "persistently_and_emp_elim",
"content": "theorem persistently_and_emp_elim {P : PROP} [BI PROP] : emp β§ <pers> P β’ P"
},
{
"name": "sep_emp",
"content": "theorem sep_emp [BI PROP] {P : PROP} : P β emp β£β’ P"
},
{
"name": "Equiv.trans",
"content": "theorem Equiv.trans [OFE Ξ±] {x : Ξ±} : x β‘ y β y β‘ z β x β‘ z"
},
{
"name": "equiv_eqv",
"content": "theorem equiv_eqv [ofe : OFE Ξ±] : Equivalence ofe.Equiv"
},
{
"name": "Dist.symm",
"content": "@[symm] theorem Dist.symm [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ y β y β‘{n}β‘ x"
},
{
"name": "Dist.rfl",
"content": "@[simp, refl] theorem Dist.rfl [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ x"
},
{
"name": "and_forall_bool",
"content": "theorem and_forall_bool [BI PROP] {P Q : PROP} :\n P β§ Q β£β’ Β«forallΒ» (fun b : Bool => if b then P else Q)"
},
{
"name": "DistLater.trans",
"content": "theorem DistLater.trans [OFE Ξ±] {n} {x : Ξ±} (h1 : DistLater n x y) (h2 : DistLater n y z) :\n DistLater n x z"
},
{
"name": "true_and",
"content": "theorem true_and [BI PROP] {P : PROP} : True β§ P β£β’ P"
},
{
"name": "forall_mono",
"content": "@[rw_mono_rule]\ntheorem forall_mono [BI PROP] {Ξ¦ Ξ¨ : Ξ± β PROP} (h : β a, Ξ¦ a β’ Ξ¨ a) : (β a, Ξ¦ a) β’ β a, Ξ¨ a"
},
{
"name": "and_mono",
"content": "@[rw_mono_rule]\ntheorem and_mono [BI PROP] {P P' Q Q' : PROP} (h1 : P β’ Q) (h2 : P' β’ Q') : P β§ P' β’ Q β§ Q'"
},
{
"name": "and_elim_l'",
"content": "theorem and_elim_l' [BI PROP] {P Q R : PROP} (h : P β’ R) : P β§ Q β’ R"
},
{
"name": "and_elim_r'",
"content": "theorem and_elim_r' [BI PROP] {P Q R : PROP} (h : Q β’ R) : P β§ Q β’ R"
}
] | [
{
"name": "Iris.Plainly",
"content": "class Plainly (PROP : Type _) where\n plainly : PROP β PROP"
},
{
"name": "Iris.Plainly.plainlyIf",
"content": "def Plainly.plainlyIf [Iris.BI.BIBase PROP] [Plainly PROP] (p : Bool) (P : PROP) : PROP :=\n iprop(if p then β P else P)"
},
{
"name": "Iris.BIPlainly",
"content": "class BIPlainly (PROP : Type _) [Iris.BI PROP] extends Plainly PROP where\n [ne : Iris.OFE.NonExpansive (Plainly.plainly (PROP := PROP))]\n mono {P Q : PROP} : (P β’ Q) β β P β’ β Q\n elim_persistently {P : PROP} : β P β’ <pers> P\n idem {P : PROP} : β P β’ β β P\n plainly_sForall_2 {Ξ¦ : PROP β Prop} : (β p, βΞ¦ pβ β β p) β’ β sForall Ξ¦\n plainly_impl_plainly {P Q : PROP} : (β P β β Q) β’ β (β P β Q)\n emp_intro {P : PROP} : P β’ β emp\n plainly_absorb {P Q : PROP} : β P β Q β’ β P\n later_plainly {P : PROP} : β· β P β£β’ β β· P"
},
{
"name": "Iris.BIPlainlyExists",
"content": "class BIPlainlyExists (PROP : Type _) [Iris.BI PROP] [BIPlainly PROP] where\n plainly_sExists_1 {Ξ¦ : PROP β Prop} : β sExists Ξ¦ β’ β p, βΞ¦ pβ β§ β p"
}
] | [
{
"name": "Iris.BI.plainly_forall_2",
"content": "theorem plainly_forall_2 {Ξ¨ : Ξ± β PROP} : (β a, β (Ξ¨ a)) β’ β (β a, Ξ¨ a)"
}
] | import Iris.BI.Classes
import Iris.BI.BI
import Iris.BI.DerivedLaws
import Iris.Algebra
namespace Iris
open BI
class Plainly (PROP : Type _) where
plainly : PROP β PROP
def Plainly.plainlyIf [Iris.BI.BIBase PROP] [Plainly PROP] (p : Bool) (P : PROP) : PROP :=
iprop(if p then β P else P)
class BIPlainly (PROP : Type _) [Iris.BI PROP] extends Plainly PROP where
[ne : Iris.OFE.NonExpansive (Plainly.plainly (PROP := PROP))]
mono {P Q : PROP} : (P β’ Q) β β P β’ β Q
elim_persistently {P : PROP} : β P β’ <pers> P
idem {P : PROP} : β P β’ β β P
plainly_sForall_2 {Ξ¦ : PROP β Prop} : (β p, βΞ¦ pβ β β p) β’ β sForall Ξ¦
plainly_impl_plainly {P Q : PROP} : (β P β β Q) β’ β (β P β Q)
emp_intro {P : PROP} : P β’ β emp
plainly_absorb {P Q : PROP} : β P β Q β’ β P
later_plainly {P : PROP} : β· β P β£β’ β β· P
class BIPlainlyExists (PROP : Type _) [Iris.BI PROP] [BIPlainly PROP] where
plainly_sExists_1 {Ξ¦ : PROP β Prop} : β sExists Ξ¦ β’ β p, βΞ¦ pβ β§ β p
namespace BI
open Iris.Std
section PlainlyLaws
open BIPlainly
variable [BI PROP] [BIPlainly PROP]
variable {P Q R : PROP} | theorem plainly_persistently_elim : β <pers> P β£β’ β P := | := by
constructor
Β· refine (true_and.2.trans <| and_mono emp_intro .rfl).trans ?_
refine .trans ?_ (mono <| and_forall_bool.2.trans persistently_and_emp_elim)
refine and_forall_bool.1.trans ?_
refine .trans ?_ plainly_forall_2
refine forall_mono ?_
exact (Β·.casesOn .rfl .rfl)
Β· exact idem.trans <| mono elim_persistently | 6 | 75 | false | Framework |
231 | Iris.fixpoint_unique | theorem fixpoint_unique [COFE Ξ±] [Inhabited Ξ±] {f : Ξ± -c> Ξ±} {x : Ξ±} (H : x β‘ f x) :
x β‘ fixpoint f | iris-lean | src/Iris/Algebra/OFE.lean | [
"import src/Iris/Algebra/Excl.lean",
"import src/Iris/Instances/UPred/Instance.lean",
"import src/Iris/Algebra/UPred.lean",
"import src/Iris/Algebra/CMRA.lean",
"import src/Iris/Algebra/Agree_task.lean",
"import src/Iris/Algebra/COFESolver.lean",
"import src/Iris/Algebra/Heap.lean"
] | [
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "Option.merge",
"module": "Init.Data.Option.Basic"
},
{
"name": "id",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "m",
"module": "QqTest.matching"
},
{
"name": "Equivalence",
"module": "Init.Core"
},
{
"name": "Inhabited",
"module": "Init.Prelude"
},
{
"name": "Dist",
"module": "Mathlib.Topology.MetricSpace.Pseudo.Defs"
},
{
"name": "Equiv",
"module": "Mathlib.Logic.Equiv.Defs"
},
{
"name": "Nat.succ",
"module": "Init.Prelude"
},
{
"name": "k",
"module": "QqTest.matching"
}
] | [
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y"
},
{
"name": "notation:50 x \" βΌ{\" n \"} \" y:51 => IncludedN n x y",
"content": "notation:50 x \" βΌ{\" n \"} \" y:51 => IncludedN n x y"
},
{
"name": "Transitive",
"content": "class Transitive (R : Relation Ξ±) where\n trans {x y z : Ξ±} : R x y β R y z β R x z"
},
{
"name": "Reflexive",
"content": "class Reflexive (R : Relation Ξ±) where\n refl {x : Ξ±} : R x x"
},
{
"name": "",
"content": "instance : OFE.Discrete (DFrac F) := β¨congrArg idβ©"
},
{
"name": "Agree.dist",
"content": "def Agree.dist (n : Nat) (x y : Agree Ξ±) : Prop :=\n (β a β x.car, β b β y.car, a β‘{n}β‘ b) β§\n (β b β y.car, β a β x.car, a β‘{n}β‘ b)"
},
{
"name": "",
"content": "instance : OFE (Tower F) where\n Equiv f g := β k, f k β‘ g k\n Dist n f g := β k, f k β‘{n}β‘ g k\n dist_eqv := {\n refl _ _ := dist_eqv.refl _\n symm h _ := dist_eqv.symm (h _)\n trans h1 h2 _ := dist_eqv.trans (h1 _) (h2 _)\n }\n equiv_dist {_ _} := by admit /- proof elided -/"
},
{
"name": "",
"content": "instance : OFE.NonExpansive (BUpd.bupd (PROP := UPred M)) := bupd_ne"
},
{
"name": "bupd_ne",
"content": "instance bupd_ne : OFE.NonExpansive (bupd : UPred M β UPred M) where\n ne n x1 x2 Hx m y Hm Hv := by admit /- proof elided -/"
},
{
"name": "CMRA",
"content": "class CMRA (Ξ± : Type _) extends OFE Ξ± where\n pcore : Ξ± β Option Ξ±\n op : Ξ± β Ξ± β Ξ±\n ValidN : Nat β Ξ± β Prop\n Valid : Ξ± β Prop\n\n op_ne : NonExpansive (op x)\n pcore_ne : x β‘{n}β‘ y β pcore x = some cx β\n β cy, pcore y = some cy β§ cx β‘{n}β‘ cy\n validN_ne : x β‘{n}β‘ y β ValidN n x β ValidN n y\n\n valid_iff_validN : Valid x β β n, ValidN n x\n validN_succ : ValidN n.succ x β ValidN n x\n validN_op_left : ValidN n (op x y) β ValidN n x\n\n assoc : op x (op y z) β‘ op (op x y) z\n comm : op x y β‘ op y x\n\n pcore_op_left : pcore x = some cx β op cx x β‘ x\n pcore_idem : pcore x = some cx β pcore cx β‘ some cx\n pcore_op_mono : pcore x = some cx β β y, β cy, pcore (op x y) β‘ some (op cx cy)\n\n extend : ValidN n x β x β‘{n}β‘ op yβ yβ β\n Ξ£' zβ zβ, x β‘ op zβ zβ β§ zβ β‘{n}β‘ yβ β§ zβ β‘{n}β‘ yβ"
},
{
"name": "later_contractive",
"content": "instance later_contractive : OFE.Contractive UPred.later (Ξ± := UPred M) where\n distLater_dist {n x y} Hl :=\n match n with\n | 0 => by admit /- proof elided -/\n | n + 1 => fun\n | 0 => by admit /- proof elided -/\n | n' + 1 => fun x' Hn' Hx' => Hl _ Hn' _ _ (Nat.le_refl _) (CMRA.validN_succ Hx')"
},
{
"name": "later",
"content": "protected def later (P : UPred M) : UPred M where\n holds n x := match n with | 0 => True | Nat.succ n' => P n' x\n mono {nβ nβ} := by admit /- proof elided -/"
},
{
"name": "BIPlainly",
"content": "class BIPlainly (PROP : Type _) [Iris.BI PROP] extends Plainly PROP where\n [ne : Iris.OFE.NonExpansive (Plainly.plainly (PROP := PROP))]\n mono {P Q : PROP} : (P β’ Q) β β P β’ β Q\n elim_persistently {P : PROP} : β P β’ <pers> P\n idem {P : PROP} : β P β’ β β P\n plainly_sForall_2 {Ξ¦ : PROP β Prop} : (β p, βΞ¦ pβ β β p) β’ β sForall Ξ¦\n plainly_impl_plainly {P Q : PROP} : (β P β β Q) β’ β (β P β Q)\n emp_intro {P : PROP} : P β’ β emp\n plainly_absorb {P Q : PROP} : β P β Q β’ β P\n later_plainly {P : PROP} : β· β P β£β’ β β· P"
},
{
"name": "BIUpdate",
"content": "class BIUpdate (PROP : Type _) [BI PROP] extends BUpd PROP where\n [bupd_ne : OFE.NonExpansive (BUpd.bupd (PROP := PROP))]\n intro {P : PROP} : iprop(P β’ |==> P)\n mono {P Q : PROP} : iprop(P β’ Q) β iprop(|==> P β’ |==> Q)\n trans {P : PROP} : iprop(|==> |==> P β’ |==> P)\n frame_r {P R : PROP} : iprop((|==> P) β R β’ |==> (P β R))"
},
{
"name": "UPred",
"content": "@[ext]\nstructure UPred (M : Type _) [UCMRA M] where\n holds : Nat β M β Prop\n mono {n1 n2 x1 x2} : holds n1 x1 β x1 βΌ{n2} x2 β n2 β€ n1 β holds n2 x2"
},
{
"name": "IsModal",
"content": "class IsModal [BI PROP1] [BI PROP2] (M : PROP1 β PROP2)\n (iaction saction : ModalityAction PROP1 PROP2) where\n spec_intuitionistic : iaction.intuitionistic_action_spec M\n spec_spatial : saction.spatial_action_spec M\n emp : iprop(emp) β’ M iprop(emp)\n mono : β {P Q}, (P β’ Q) β M P β’ M Q\n sep : β {P Q}, iprop(M P β M Q) β’ M iprop(P β Q)"
},
{
"name": "UCMRA",
"content": "class UCMRA (Ξ± : Type _) extends CMRA Ξ± where\n unit : Ξ±\n unit_valid : β unit\n unit_left_id : unit β’ x β‘ x\n pcore_unit : pcore unit β‘ some unit"
},
{
"name": "pcore",
"content": "def pcore : DFrac F β Option (DFrac F)\n | own _ => none\n | .discard => some discard\n | ownDiscard _ => some discard"
},
{
"name": "DFrac",
"content": "inductive DFrac (F : Type _) where\n \n| own (f : F) : DFrac F\n \n| discard : DFrac F\n \n| ownDiscard (f : F) : DFrac F"
},
{
"name": "op",
"content": "def op : DFrac F β DFrac F β DFrac F\n | .discard, .discard => discard\n | own f, .discard\n | ownDiscard f, .discard\n | .discard, own f\n | .discard, ownDiscard f => ownDiscard f\n | own f, own f' => own (f + f')\n | own f, ownDiscard f'\n | ownDiscard f, own f'\n | ownDiscard f, ownDiscard f' => ownDiscard (f + f')"
},
{
"name": "Associative",
"content": "class Associative (R : Relation Ξ±) (f : Ξ± β Ξ± β Ξ±) where\n assoc {x y z : Ξ±} : R (f (f x y) z) (f x (f y z))"
},
{
"name": "Commutative",
"content": "class Commutative (R : Relation Ξ±) (f : Ξ² β Ξ² β Ξ±) where\n comm {x y : Ξ²} : R (f x y) (f y x)"
},
{
"name": "Included",
"content": "def Included (x y : Ξ±) : Prop := β z, y β‘ x β’ z"
},
{
"name": "instOFE",
"content": "instance instOFE [Store T K V] [OFE V] : OFE T where\n Equiv s0 s1 := get s0 β‘ get s1\n Dist n s0 s1 := get s0 β‘{n}β‘ get s1\n dist_eqv := β¨fun _ => .of_eq rfl, (Β·.symm), (Β·.trans Β·)β©\n equiv_dist := equiv_dist\n dist_lt := dist_lt"
},
{
"name": "Store.Equiv",
"content": "@[simp] def Store.Equiv [Store T K V] (t1 t2 : T) : Prop := get t1 = get t2"
},
{
"name": "Store.Equiv_trans",
"content": "instance Store.Equiv_trans [Store T K V] : Trans Equiv (Equiv (T := T)) Equiv := β¨by admit /- proof elided -/\nβ©"
},
{
"name": "[CMRA",
"content": "instance [CMRA Ξ²] : OFE (Ξ± -C> Ξ²) where\n Equiv f g := f.toHom β‘ g.toHom\n Dist n f g := f.toHom β‘{n}β‘ g.toHom\n dist_eqv := {\n refl _ := dist_eqv.refl _\n symm h := dist_eqv.symm h\n trans h1 h2 := dist_eqv.trans h1 h2\n }\n equiv_dist := equiv_dist\n dist_lt := dist_lt"
},
{
"name": "[OFE",
"content": "instance [OFE Ξ±] [IsCOFE Ξ±] : IsCOFE (Excl Ξ±) where\n compl c := (c 0).map fun x => IsCOFE.compl (exclChain c x)\n conv_compl {n} c := by admit /- proof elided -/"
},
{
"name": "(k",
"content": "instance (k : Nat) : NonExpansive (fun X : Tower F => X.val k) := β¨fun _ _ _ => (Β· _)β©"
},
{
"name": "[OFE",
"content": "instance [OFE Ξ±] : NonExpansive excl (Ξ± := Ξ±) where\n ne _ _ _ a := a"
},
{
"name": "get_ne",
"content": "instance get_ne [Store T K V] [OFE V] (k : K) : NonExpansive (get Β· k : T β V) where\n ne {_ _ _} Ht := Ht k"
},
{
"name": "[Store",
"content": "instance [Store T1 K V1] [Store T2 K V2] [OFE V1] [OFE V2] (f : K β V1 β V2)\n [β k, NonExpansive (f k)] [HasStoreMap T1 T2 K V1 V2] : NonExpansive (dmap f : T1 β T2) where\n ne _ {_ _} H k := by admit /- proof elided -/"
},
{
"name": "HasStoreMap",
"content": "class HasStoreMap (T1 T2 : Type _) (K V1 V2 : outParam (Type _)) [Store T1 K V1] [Store T2 K V2] where\n \n dmap (f : K β V1 β V2) : T1 β T2\n get_dmap : get (dmap f t) k = f k (get t k)"
},
{
"name": "",
"content": "instance : NonExpansive (pcore (Ξ± := Ξ±)) where\n ne n x {y} e := by admit /- proof elided -/"
},
{
"name": "[Heap",
"content": "instance [Heap T K V] [OFE V] (op : V β V β V) [NonExpansiveβ op] :\n NonExpansiveβ (merge (T := T) op) where\n ne _ {_ _} Ht {_ _} Hs k := by admit /- proof elided -/"
},
{
"name": "Heap.instCOFE",
"content": "instance Heap.instCOFE [Heap T K V] [COFE V] : COFE T where\n compl c := hmap (fun _ => COFE.compl <| c.map β¨_, Store.get_ne Β·β©) (c 0)\n conv_compl {_ c} k := by admit /- proof elided -/"
},
{
"name": "infix:60 \" β’ \" => op",
"content": "infix:60 \" β’ \" => op"
},
{
"name": "infix:50 \" βΌ \" => Included",
"content": "infix:50 \" βΌ \" => Included"
},
{
"name": "@[inherit_doc]",
"content": "@[inherit_doc]\ninfixr:25 \" -C> \" => Hom"
}
] | [
{
"name": "Nat.lt_of_le_of_ne",
"module": "Init.Prelude"
},
{
"name": "Nat.le_of_lt_succ",
"module": "Init.Prelude"
},
{
"name": "Nat.lt_succ_self",
"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": "Iris.OFE",
"content": "class OFE (Ξ± : Type _) where\n Equiv : Ξ± β Ξ± β Prop\n Dist : Nat β Ξ± β Ξ± β Prop\n dist_eqv : Equivalence (Dist n)\n equiv_dist : Equiv x y β β n, Dist n x y\n dist_lt : Dist n x y β m < n β Dist m x y"
},
{
"name": "Iris.OFE.NonExpansive",
"content": "class NonExpansive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β f xβ β‘{n}β‘ f xβ"
},
{
"name": "Iris.OFE.id_ne",
"content": "instance id_ne [OFE Ξ±] : NonExpansive (@id Ξ±) := β¨fun _ _ _ h => hβ©"
},
{
"name": "Iris.OFE.NonExpansiveβ",
"content": "class NonExpansiveβ [OFE Ξ±] [OFE Ξ²] [OFE Ξ³] (f : Ξ± β Ξ² β Ξ³) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β β β¦yβ yββ¦, yβ β‘{n}β‘ yβ β f xβ yβ β‘{n}β‘ f xβ yβ"
},
{
"name": "Iris.OFE.DistLater",
"content": "def DistLater [OFE Ξ±] (n : Nat) (x y : Ξ±) : Prop := β m, m < n β x β‘{m}β‘ y"
},
{
"name": "Iris.OFE.Contractive",
"content": "class Contractive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) where\n distLater_dist : DistLater n x y β f x β‘{n}β‘ f y"
},
{
"name": "Iris.OFE.ne_of_contractive",
"content": "instance ne_of_contractive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) [Contractive f] : NonExpansive f where\n ne := fun _ _ _ h => Contractive.distLater_dist (Dist.distLater h)"
},
{
"name": "Iris.OFE._inst_Ξ²",
"content": "instance [OFE Ξ±] [OFE Ξ²] {x : Ξ²} : Contractive (fun _ : Ξ± => x) where\n distLater_dist := fun _ => Dist.rfl"
},
{
"name": "Iris.OFE.Hom",
"content": "@[ext] structure Hom (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] where\n f : Ξ± β Ξ²\n ne : NonExpansive f"
},
{
"name": "Iris.OFE._inst_Ξ±",
"content": "instance [OFE Ξ±] [OFE Ξ²] (f : Ξ± -n> Ξ²) : NonExpansive f := f.ne"
},
{
"name": "Iris.OFE.ContractiveHom",
"content": "@[ext] structure ContractiveHom (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] extends Hom Ξ± Ξ² where\n [contractive : Contractive f]\n ne := ne_of_contractive f"
},
{
"name": "Iris.OFE._inst_Ξ±",
"content": "instance [OFE Ξ±] [OFE Ξ²] (f : Ξ± -c> Ξ²) : Contractive f := f.contractive"
},
{
"name": "Iris.OFE._inst_OFE",
"content": "instance : OFE Unit where\n Equiv _ _ := True\n Dist _ _ _ := True\n dist_eqv := β¨fun _ => β¨β©, id, fun _ => idβ©\n equiv_dist := by admit /- proof elided -/"
},
{
"name": "Iris.OFE._inst_OFE",
"content": "instance [OFE Ξ±] : OFE (ULift Ξ±) where\n Equiv x y := x.down β‘ y.down\n Dist n x y := x.down β‘{n}β‘ y.down\n dist_eqv := InvImage.equivalence dist_eqv\n equiv_dist := equiv_dist\n dist_lt := dist_lt"
},
{
"name": "Iris.OFE._inst_OFE",
"content": "instance [OFE Ξ±] : OFE (Option Ξ±) where\n Equiv := Option.Forallβ Equiv\n Dist n := Option.Forallβ (Dist n)\n dist_eqv := Option.Forallβ.equivalence dist_eqv\n equiv_dist {x y} := by admit /- proof elided -/"
},
{
"name": "Iris.OFE._inst_OFE",
"content": "instance [OFE Ξ±] [OFE.Discrete Ξ±] : OFE.Discrete (Option Ξ±) where\n discrete_0 {mx my} e :=\n match mx, my with\n | none, none => e\n | none, some _ => e\n | some _, none => e\n | some x, some y => show x β‘ y from discrete_0 e"
},
{
"name": "Iris.OFE.OFE",
"content": "instance OFE.Option.some.ne [OFE Ξ±] : OFE.NonExpansive (some : Ξ± β Option Ξ±) := β¨fun _ _ _ => idβ©"
},
{
"name": "Iris.OFE.Option",
"content": "instance Option.merge_ne [OFE Ξ±] {op : Ξ± β Ξ± β Ξ±} [NonExpansiveβ op] :\n NonExpansiveβ (Option.merge op) where\n ne n x1 x2 Hx y1 y2 Hy := by admit /- proof elided -/"
},
{
"name": "Iris.OFE._inst_Ξ±",
"content": "instance [OFEFun (Ξ² : Ξ± β _)] : OFE ((x : Ξ±) β Ξ² x) where\n Equiv f g := β x, f x β‘ g x\n Dist n f g := β x, f x β‘{n}β‘ g x\n dist_eqv := {\n refl _ _ := dist_eqv.refl _\n symm h _ := dist_eqv.symm (h _)\n trans h1 h2 _ := dist_eqv.trans (h1 _) (h2 _)\n }\n equiv_dist {_ _} := by admit /- proof elided -/"
},
{
"name": "Iris.OFE._inst_OFE",
"content": "instance [OFE Ξ±] [OFE Ξ²] : OFE (Ξ± -n> Ξ²) where\n Equiv f g := f.f β‘ g.f\n Dist n f g := f.f β‘{n}β‘ g.f\n dist_eqv := {\n refl _ := dist_eqv.refl _\n symm h := dist_eqv.symm h\n trans h1 h2 := dist_eqv.trans h1 h2\n }\n equiv_dist := equiv_dist\n dist_lt := dist_lt"
},
{
"name": "Iris.OFE._inst_OFE",
"content": "instance [OFE Ξ±] [OFE Ξ²] : OFE (Ξ± -c> Ξ²) where\n Equiv f g := Equiv f.toHom g.toHom\n Dist n f g := Dist n f.toHom g.toHom\n dist_eqv := {\n refl _ := dist_eqv.refl _\n symm h := dist_eqv.symm h\n trans h1 h2 := dist_eqv.trans h1 h2\n }\n equiv_dist := equiv_dist\n dist_lt := dist_lt"
},
{
"name": "Iris.OFE._inst_OFE",
"content": "instance [OFE Ξ±] [OFE Ξ²] : OFE (Ξ± Γ Ξ²) where\n Equiv a b := a.1 β‘ b.1 β§ a.2 β‘ b.2\n Dist n a b := a.1 β‘{n}β‘ b.1 β§ a.2 β‘{n}β‘ b.2\n dist_eqv := {\n refl _ := β¨dist_eqv.refl _, dist_eqv.refl _β©\n symm h := β¨dist_eqv.symm h.1, dist_eqv.symm h.2β©\n trans h1 h2 := β¨dist_eqv.trans h1.1 h2.1, dist_eqv.trans h1.2 h2.2β©\n }\n equiv_dist {_ _} := by admit /- proof elided -/"
},
{
"name": "Iris.OFE.Iso",
"content": "@[ext] structure Iso (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] where\n hom : Ξ± -n> Ξ²\n inv : Ξ² -n> Ξ±\n hom_inv : hom (inv x) β‘ x\n inv_hom : inv (hom x) β‘ x"
},
{
"name": "Iris.OFE._inst_Iso",
"content": "instance [OFE Ξ±] [OFE Ξ²] (iso : Iso Ξ± Ξ²) : NonExpansive iso.hom := iso.hom.ne"
},
{
"name": "Iris.OFE._inst_Iso",
"content": "instance [OFE Ξ±] [OFE Ξ²] (iso : Iso Ξ± Ξ²) : NonExpansive iso.inv := iso.inv.ne"
},
{
"name": "Iris.OFE.Iso.symm",
"content": "def Iso.symm [OFE Ξ±] [OFE Ξ²] (iso : Iso Ξ± Ξ²) : Iso Ξ² Ξ± where\n hom := iso.inv\n inv := iso.hom\n hom_inv := by admit /- proof elided -/"
},
{
"name": "Iris.Chain",
"content": "structure Chain (Ξ± : Type _) [OFE Ξ±] where\n chain : Nat β Ξ±\n cauchy : n β€ i β chain i β‘{n}β‘ chain n"
},
{
"name": "Iris.IsCOFE",
"content": "class IsCOFE (Ξ± : Type _) [OFE Ξ±] where\n compl : Chain Ξ± β Ξ±\n conv_compl {c : Chain Ξ±} : compl c β‘{n}β‘ c n"
},
{
"name": "Iris.LeibnizO",
"content": "@[ext] structure LeibnizO (Ξ± : Type _) where\n car : Ξ±"
},
{
"name": "Iris.optionChain",
"content": "def optionChain (c : Chain (Option Ξ±)) (x : Ξ±) : Chain Ξ± :="
},
{
"name": "Iris.isCOFE_option",
"content": "instance isCOFE_option [IsCOFE Ξ±] : IsCOFE (Option Ξ±) where\n compl c := (c 0).map fun x => IsCOFE.compl (optionChain c x)\n conv_compl {n} c := by admit /- proof elided -/"
},
{
"name": "Iris.Fixpoint.chain",
"content": "def Fixpoint.chain [OFE Ξ±] [Inhabited Ξ±] (f : Ξ± β Ξ±) [Contractive f] : Chain Ξ± where\n chain n := Nat.repeat f (n + 1) default\n cauchy {n} := by admit /- proof elided -/"
},
{
"name": "Iris.fixpoint",
"content": "def fixpoint [COFE Ξ±] [Inhabited Ξ±] (f : Ξ± β Ξ±) [Contractive f] : Ξ± :=\n COFE.compl <| Fixpoint.chain f\n\nnonrec abbrev OFE.ContractiveHom.fixpoint [COFE Ξ±] [Inhabited Ξ±] (f : Ξ± -c> Ξ±) : Ξ± := fixpoint f.f"
}
] | [
{
"name": "Iris.OFE.Dist.lt",
"content": "theorem Dist.lt [OFE Ξ±] {m n} {x y : Ξ±} : x β‘{n}β‘ y β m < n β x β‘{m}β‘ y"
},
{
"name": "Iris.OFE.Dist.le",
"content": "theorem Dist.le [OFE Ξ±] {m n} {x y : Ξ±} (h : x β‘{n}β‘ y) (h' : m β€ n) : x β‘{m}β‘ y"
},
{
"name": "Iris.OFE.Dist.rfl",
"content": "@[simp, refl] theorem Dist.rfl [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ x"
},
{
"name": "Iris.OFE.Dist.symm",
"content": "@[symm] theorem Dist.symm [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ y β y β‘{n}β‘ x"
},
{
"name": "Iris.OFE.Dist.trans",
"content": "theorem Dist.trans [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ y β y β‘{n}β‘ z β x β‘{n}β‘ z"
},
{
"name": "Iris.OFE.equiv_eqv",
"content": "theorem equiv_eqv [ofe : OFE Ξ±] : Equivalence ofe.Equiv"
},
{
"name": "Iris.OFE.Equiv.symm",
"content": "@[symm] theorem Equiv.symm [OFE Ξ±] {x : Ξ±} : x β‘ y β y β‘ x"
},
{
"name": "Iris.OFE.Equiv.trans",
"content": "theorem Equiv.trans [OFE Ξ±] {x : Ξ±} : x β‘ y β y β‘ z β x β‘ z"
},
{
"name": "Iris.OFE.Equiv.dist",
"content": "theorem Equiv.dist [OFE Ξ±] {x : Ξ±} : x β‘ y β x β‘{n}β‘ y"
},
{
"name": "Iris.OFE.DistLater.symm",
"content": "@[symm] theorem DistLater.symm [OFE Ξ±] {n} {x : Ξ±} (h : DistLater n x y) : DistLater n y x"
},
{
"name": "Iris.OFE.DistLater.trans",
"content": "theorem DistLater.trans [OFE Ξ±] {n} {x : Ξ±} (h1 : DistLater n x y) (h2 : DistLater n y z) :\n DistLater n x z"
},
{
"name": "Iris.OFE.distLater_zero",
"content": "@[simp] theorem distLater_zero [OFE Ξ±] {x y : Ξ±} : DistLater 0 x y"
},
{
"name": "Iris.OFE.distLater_succ",
"content": "theorem distLater_succ [OFE Ξ±] {n} {x y : Ξ±} : DistLater n.succ x y β x β‘{n}β‘ y"
},
{
"name": "Iris.OFE.Contractive.zero",
"content": "@[simp] theorem Contractive.zero [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) [Contractive f] {x y} :\n f x β‘{0}β‘ f y"
},
{
"name": "Iris.OFE.Contractive.succ",
"content": "theorem Contractive.succ [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) [Contractive f] {n x y}\n (h : x β‘{n}β‘ y) : f x β‘{n.succ}β‘ f y"
},
{
"name": "Iris.fixpoint_unfold",
"content": "theorem fixpoint_unfold [COFE Ξ±] [Inhabited Ξ±] (f : Ξ± -c> Ξ±) :\n fixpoint f β‘ f (fixpoint f)"
}
] | namespace Iris
class OFE (Ξ± : Type _) where
Equiv : Ξ± β Ξ± β Prop
Dist : Nat β Ξ± β Ξ± β Prop
dist_eqv : Equivalence (Dist n)
equiv_dist : Equiv x y β β n, Dist n x y
dist_lt : Dist n x y β m < n β Dist m x y
open OFE
scoped infix:40 " β‘ " => OFE.Equiv
scoped notation:40 x " β‘{" n "}β‘ " y:41 => OFE.Dist n x y
namespace OFE
class NonExpansive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) where
ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β f xβ β‘{n}β‘ f xβ
instance id_ne [OFE Ξ±] : NonExpansive (@id Ξ±) := β¨fun _ _ _ h => hβ©
class NonExpansiveβ [OFE Ξ±] [OFE Ξ²] [OFE Ξ³] (f : Ξ± β Ξ² β Ξ³) where
ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β β β¦yβ yββ¦, yβ β‘{n}β‘ yβ β f xβ yβ β‘{n}β‘ f xβ yβ
def DistLater [OFE Ξ±] (n : Nat) (x y : Ξ±) : Prop := β m, m < n β x β‘{m}β‘ y
class Contractive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) where
distLater_dist : DistLater n x y β f x β‘{n}β‘ f y
instance ne_of_contractive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) [Contractive f] : NonExpansive f where
ne := fun _ _ _ h => Contractive.distLater_dist (Dist.distLater h)
instance [OFE Ξ±] [OFE Ξ²] {x : Ξ²} : Contractive (fun _ : Ξ± => x) where
distLater_dist := fun _ => Dist.rfl
@[ext] structure Hom (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] where
f : Ξ± β Ξ²
ne : NonExpansive f
@[inherit_doc]
infixr:25 " -n> " => Hom
instance [OFE Ξ±] [OFE Ξ²] (f : Ξ± -n> Ξ²) : NonExpansive f := f.ne
@[ext] structure ContractiveHom (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] extends Hom Ξ± Ξ² where
[contractive : Contractive f]
ne := ne_of_contractive f
infixr:25 " -c> " => ContractiveHom
instance [OFE Ξ±] [OFE Ξ²] (f : Ξ± -c> Ξ²) : Contractive f := f.contractive
instance : OFE Unit where
Equiv _ _ := True
Dist _ _ _ := True
dist_eqv := β¨fun _ => β¨β©, id, fun _ => idβ©
equiv_dist := by admit /- proof elided -/
instance [OFE Ξ±] : OFE (ULift Ξ±) where
Equiv x y := x.down β‘ y.down
Dist n x y := x.down β‘{n}β‘ y.down
dist_eqv := InvImage.equivalence dist_eqv
equiv_dist := equiv_dist
dist_lt := dist_lt
instance [OFE Ξ±] : OFE (Option Ξ±) where
Equiv := Option.Forallβ Equiv
Dist n := Option.Forallβ (Dist n)
dist_eqv := Option.Forallβ.equivalence dist_eqv
equiv_dist {x y} := by admit /- proof elided -/
instance [OFE Ξ±] [OFE.Discrete Ξ±] : OFE.Discrete (Option Ξ±) where
discrete_0 {mx my} e :=
match mx, my with
| none, none => e
| none, some _ => e
| some _, none => e
| some x, some y => show x β‘ y from discrete_0 e
instance OFE.Option.some.ne [OFE Ξ±] : OFE.NonExpansive (some : Ξ± β Option Ξ±) := β¨fun _ _ _ => idβ©
instance Option.merge_ne [OFE Ξ±] {op : Ξ± β Ξ± β Ξ±} [NonExpansiveβ op] :
NonExpansiveβ (Option.merge op) where
ne n x1 x2 Hx y1 y2 Hy := by admit /- proof elided -/
instance [OFEFun (Ξ² : Ξ± β _)] : OFE ((x : Ξ±) β Ξ² x) where
Equiv f g := β x, f x β‘ g x
Dist n f g := β x, f x β‘{n}β‘ g x
dist_eqv := {
refl _ _ := dist_eqv.refl _
symm h _ := dist_eqv.symm (h _)
trans h1 h2 _ := dist_eqv.trans (h1 _) (h2 _)
}
equiv_dist {_ _} := by admit /- proof elided -/
instance [OFE Ξ±] [OFE Ξ²] : OFE (Ξ± -n> Ξ²) where
Equiv f g := f.f β‘ g.f
Dist n f g := f.f β‘{n}β‘ g.f
dist_eqv := {
refl _ := dist_eqv.refl _
symm h := dist_eqv.symm h
trans h1 h2 := dist_eqv.trans h1 h2
}
equiv_dist := equiv_dist
dist_lt := dist_lt
instance [OFE Ξ±] [OFE Ξ²] : OFE (Ξ± -c> Ξ²) where
Equiv f g := Equiv f.toHom g.toHom
Dist n f g := Dist n f.toHom g.toHom
dist_eqv := {
refl _ := dist_eqv.refl _
symm h := dist_eqv.symm h
trans h1 h2 := dist_eqv.trans h1 h2
}
equiv_dist := equiv_dist
dist_lt := dist_lt
instance [OFE Ξ±] [OFE Ξ²] : OFE (Ξ± Γ Ξ²) where
Equiv a b := a.1 β‘ b.1 β§ a.2 β‘ b.2
Dist n a b := a.1 β‘{n}β‘ b.1 β§ a.2 β‘{n}β‘ b.2
dist_eqv := {
refl _ := β¨dist_eqv.refl _, dist_eqv.refl _β©
symm h := β¨dist_eqv.symm h.1, dist_eqv.symm h.2β©
trans h1 h2 := β¨dist_eqv.trans h1.1 h2.1, dist_eqv.trans h1.2 h2.2β©
}
equiv_dist {_ _} := by admit /- proof elided -/
@[ext] structure Iso (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] where
hom : Ξ± -n> Ξ²
inv : Ξ² -n> Ξ±
hom_inv : hom (inv x) β‘ x
inv_hom : inv (hom x) β‘ x
instance [OFE Ξ±] [OFE Ξ²] (iso : Iso Ξ± Ξ²) : NonExpansive iso.hom := iso.hom.ne
instance [OFE Ξ±] [OFE Ξ²] (iso : Iso Ξ± Ξ²) : NonExpansive iso.inv := iso.inv.ne
def Iso.symm [OFE Ξ±] [OFE Ξ²] (iso : Iso Ξ± Ξ²) : Iso Ξ² Ξ± where
hom := iso.inv
inv := iso.hom
hom_inv := by admit /- proof elided -/
end OFE
structure Chain (Ξ± : Type _) [OFE Ξ±] where
chain : Nat β Ξ±
cauchy : n β€ i β chain i β‘{n}β‘ chain n
namespace Chain
end Chain
class IsCOFE (Ξ± : Type _) [OFE Ξ±] where
compl : Chain Ξ± β Ξ±
conv_compl {c : Chain Ξ±} : compl c β‘{n}β‘ c n
namespace COFE
end COFE
@[ext] structure LeibnizO (Ξ± : Type _) where
car : Ξ±
section DiscreteFunOF
open COFE
end DiscreteFunOF
section Option
variable [OFE Ξ±]
def optionChain (c : Chain (Option Ξ±)) (x : Ξ±) : Chain Ξ± :=
instance isCOFE_option [IsCOFE Ξ±] : IsCOFE (Option Ξ±) where
compl c := (c 0).map fun x => IsCOFE.compl (optionChain c x)
conv_compl {n} c := by admit /- proof elided -/
end Option
section OptionOF
open COFE
variable (F : OFunctorPre)
end OptionOF
section Fixpoint
def Fixpoint.chain [OFE Ξ±] [Inhabited Ξ±] (f : Ξ± β Ξ±) [Contractive f] : Chain Ξ± where
chain n := Nat.repeat f (n + 1) default
cauchy {n} := by admit /- proof elided -/
def fixpoint [COFE Ξ±] [Inhabited Ξ±] (f : Ξ± β Ξ±) [Contractive f] : Ξ± :=
COFE.compl <| Fixpoint.chain f
nonrec abbrev OFE.ContractiveHom.fixpoint [COFE Ξ±] [Inhabited Ξ±] (f : Ξ± -c> Ξ±) : Ξ± := fixpoint f.f | theorem fixpoint_unique [COFE Ξ±] [Inhabited Ξ±] {f : Ξ± -c> Ξ±} {x : Ξ±} (H : x β‘ f x) :
x β‘ fixpoint f := | := by
refine equiv_dist.mpr fun n => ?_
induction n with refine H.dist.trans <| .trans ?_ (fixpoint_unfold f).dist.symm
| zero => exact Contractive.zero f.f
| succ _ IH => exact Contractive.succ f.f IH | 6 | 45 | false | Framework |
232 | Iris.fixpoint_unfold | theorem fixpoint_unfold [COFE Ξ±] [Inhabited Ξ±] (f : Ξ± -c> Ξ±) :
fixpoint f β‘ f (fixpoint f) | iris-lean | src/Iris/Algebra/OFE.lean | [
"import src/Iris/Algebra/Excl.lean",
"import src/Iris/Instances/UPred/Instance.lean",
"import src/Iris/Algebra/UPred.lean",
"import src/Iris/Algebra/CMRA.lean",
"import src/Iris/Algebra/Agree_task.lean",
"import src/Iris/Algebra/COFESolver.lean",
"import src/Iris/Algebra/Heap.lean"
] | [
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "Option.merge",
"module": "Init.Data.Option.Basic"
},
{
"name": "id",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "m",
"module": "QqTest.matching"
},
{
"name": "Equivalence",
"module": "Init.Core"
},
{
"name": "Inhabited",
"module": "Init.Prelude"
},
{
"name": "Dist",
"module": "Mathlib.Topology.MetricSpace.Pseudo.Defs"
},
{
"name": "Equiv",
"module": "Mathlib.Logic.Equiv.Defs"
},
{
"name": "Nat.succ",
"module": "Init.Prelude"
},
{
"name": "k",
"module": "QqTest.matching"
}
] | [
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y"
},
{
"name": "notation:50 x \" βΌ{\" n \"} \" y:51 => IncludedN n x y",
"content": "notation:50 x \" βΌ{\" n \"} \" y:51 => IncludedN n x y"
},
{
"name": "Transitive",
"content": "class Transitive (R : Relation Ξ±) where\n trans {x y z : Ξ±} : R x y β R y z β R x z"
},
{
"name": "Reflexive",
"content": "class Reflexive (R : Relation Ξ±) where\n refl {x : Ξ±} : R x x"
},
{
"name": "",
"content": "instance : OFE.Discrete (DFrac F) := β¨congrArg idβ©"
},
{
"name": "Agree.dist",
"content": "def Agree.dist (n : Nat) (x y : Agree Ξ±) : Prop :=\n (β a β x.car, β b β y.car, a β‘{n}β‘ b) β§\n (β b β y.car, β a β x.car, a β‘{n}β‘ b)"
},
{
"name": "",
"content": "instance : OFE (Tower F) where\n Equiv f g := β k, f k β‘ g k\n Dist n f g := β k, f k β‘{n}β‘ g k\n dist_eqv := {\n refl _ _ := dist_eqv.refl _\n symm h _ := dist_eqv.symm (h _)\n trans h1 h2 _ := dist_eqv.trans (h1 _) (h2 _)\n }\n equiv_dist {_ _} := by admit /- proof elided -/"
},
{
"name": "",
"content": "instance : OFE.NonExpansive (BUpd.bupd (PROP := UPred M)) := bupd_ne"
},
{
"name": "bupd_ne",
"content": "instance bupd_ne : OFE.NonExpansive (bupd : UPred M β UPred M) where\n ne n x1 x2 Hx m y Hm Hv := by admit /- proof elided -/"
},
{
"name": "CMRA",
"content": "class CMRA (Ξ± : Type _) extends OFE Ξ± where\n pcore : Ξ± β Option Ξ±\n op : Ξ± β Ξ± β Ξ±\n ValidN : Nat β Ξ± β Prop\n Valid : Ξ± β Prop\n\n op_ne : NonExpansive (op x)\n pcore_ne : x β‘{n}β‘ y β pcore x = some cx β\n β cy, pcore y = some cy β§ cx β‘{n}β‘ cy\n validN_ne : x β‘{n}β‘ y β ValidN n x β ValidN n y\n\n valid_iff_validN : Valid x β β n, ValidN n x\n validN_succ : ValidN n.succ x β ValidN n x\n validN_op_left : ValidN n (op x y) β ValidN n x\n\n assoc : op x (op y z) β‘ op (op x y) z\n comm : op x y β‘ op y x\n\n pcore_op_left : pcore x = some cx β op cx x β‘ x\n pcore_idem : pcore x = some cx β pcore cx β‘ some cx\n pcore_op_mono : pcore x = some cx β β y, β cy, pcore (op x y) β‘ some (op cx cy)\n\n extend : ValidN n x β x β‘{n}β‘ op yβ yβ β\n Ξ£' zβ zβ, x β‘ op zβ zβ β§ zβ β‘{n}β‘ yβ β§ zβ β‘{n}β‘ yβ"
},
{
"name": "later_contractive",
"content": "instance later_contractive : OFE.Contractive UPred.later (Ξ± := UPred M) where\n distLater_dist {n x y} Hl :=\n match n with\n | 0 => by admit /- proof elided -/\n | n + 1 => fun\n | 0 => by admit /- proof elided -/\n | n' + 1 => fun x' Hn' Hx' => Hl _ Hn' _ _ (Nat.le_refl _) (CMRA.validN_succ Hx')"
},
{
"name": "later",
"content": "protected def later (P : UPred M) : UPred M where\n holds n x := match n with | 0 => True | Nat.succ n' => P n' x\n mono {nβ nβ} := by admit /- proof elided -/"
},
{
"name": "BIPlainly",
"content": "class BIPlainly (PROP : Type _) [Iris.BI PROP] extends Plainly PROP where\n [ne : Iris.OFE.NonExpansive (Plainly.plainly (PROP := PROP))]\n mono {P Q : PROP} : (P β’ Q) β β P β’ β Q\n elim_persistently {P : PROP} : β P β’ <pers> P\n idem {P : PROP} : β P β’ β β P\n plainly_sForall_2 {Ξ¦ : PROP β Prop} : (β p, βΞ¦ pβ β β p) β’ β sForall Ξ¦\n plainly_impl_plainly {P Q : PROP} : (β P β β Q) β’ β (β P β Q)\n emp_intro {P : PROP} : P β’ β emp\n plainly_absorb {P Q : PROP} : β P β Q β’ β P\n later_plainly {P : PROP} : β· β P β£β’ β β· P"
},
{
"name": "BIUpdate",
"content": "class BIUpdate (PROP : Type _) [BI PROP] extends BUpd PROP where\n [bupd_ne : OFE.NonExpansive (BUpd.bupd (PROP := PROP))]\n intro {P : PROP} : iprop(P β’ |==> P)\n mono {P Q : PROP} : iprop(P β’ Q) β iprop(|==> P β’ |==> Q)\n trans {P : PROP} : iprop(|==> |==> P β’ |==> P)\n frame_r {P R : PROP} : iprop((|==> P) β R β’ |==> (P β R))"
},
{
"name": "UPred",
"content": "@[ext]\nstructure UPred (M : Type _) [UCMRA M] where\n holds : Nat β M β Prop\n mono {n1 n2 x1 x2} : holds n1 x1 β x1 βΌ{n2} x2 β n2 β€ n1 β holds n2 x2"
},
{
"name": "IsModal",
"content": "class IsModal [BI PROP1] [BI PROP2] (M : PROP1 β PROP2)\n (iaction saction : ModalityAction PROP1 PROP2) where\n spec_intuitionistic : iaction.intuitionistic_action_spec M\n spec_spatial : saction.spatial_action_spec M\n emp : iprop(emp) β’ M iprop(emp)\n mono : β {P Q}, (P β’ Q) β M P β’ M Q\n sep : β {P Q}, iprop(M P β M Q) β’ M iprop(P β Q)"
},
{
"name": "UCMRA",
"content": "class UCMRA (Ξ± : Type _) extends CMRA Ξ± where\n unit : Ξ±\n unit_valid : β unit\n unit_left_id : unit β’ x β‘ x\n pcore_unit : pcore unit β‘ some unit"
},
{
"name": "pcore",
"content": "def pcore : DFrac F β Option (DFrac F)\n | own _ => none\n | .discard => some discard\n | ownDiscard _ => some discard"
},
{
"name": "DFrac",
"content": "inductive DFrac (F : Type _) where\n \n| own (f : F) : DFrac F\n \n| discard : DFrac F\n \n| ownDiscard (f : F) : DFrac F"
},
{
"name": "op",
"content": "def op : DFrac F β DFrac F β DFrac F\n | .discard, .discard => discard\n | own f, .discard\n | ownDiscard f, .discard\n | .discard, own f\n | .discard, ownDiscard f => ownDiscard f\n | own f, own f' => own (f + f')\n | own f, ownDiscard f'\n | ownDiscard f, own f'\n | ownDiscard f, ownDiscard f' => ownDiscard (f + f')"
},
{
"name": "Associative",
"content": "class Associative (R : Relation Ξ±) (f : Ξ± β Ξ± β Ξ±) where\n assoc {x y z : Ξ±} : R (f (f x y) z) (f x (f y z))"
},
{
"name": "Commutative",
"content": "class Commutative (R : Relation Ξ±) (f : Ξ² β Ξ² β Ξ±) where\n comm {x y : Ξ²} : R (f x y) (f y x)"
},
{
"name": "Included",
"content": "def Included (x y : Ξ±) : Prop := β z, y β‘ x β’ z"
},
{
"name": "instOFE",
"content": "instance instOFE [Store T K V] [OFE V] : OFE T where\n Equiv s0 s1 := get s0 β‘ get s1\n Dist n s0 s1 := get s0 β‘{n}β‘ get s1\n dist_eqv := β¨fun _ => .of_eq rfl, (Β·.symm), (Β·.trans Β·)β©\n equiv_dist := equiv_dist\n dist_lt := dist_lt"
},
{
"name": "Store.Equiv",
"content": "@[simp] def Store.Equiv [Store T K V] (t1 t2 : T) : Prop := get t1 = get t2"
},
{
"name": "Store.Equiv_trans",
"content": "instance Store.Equiv_trans [Store T K V] : Trans Equiv (Equiv (T := T)) Equiv := β¨by admit /- proof elided -/\nβ©"
},
{
"name": "[CMRA",
"content": "instance [CMRA Ξ²] : OFE (Ξ± -C> Ξ²) where\n Equiv f g := f.toHom β‘ g.toHom\n Dist n f g := f.toHom β‘{n}β‘ g.toHom\n dist_eqv := {\n refl _ := dist_eqv.refl _\n symm h := dist_eqv.symm h\n trans h1 h2 := dist_eqv.trans h1 h2\n }\n equiv_dist := equiv_dist\n dist_lt := dist_lt"
},
{
"name": "[OFE",
"content": "instance [OFE Ξ±] [IsCOFE Ξ±] : IsCOFE (Excl Ξ±) where\n compl c := (c 0).map fun x => IsCOFE.compl (exclChain c x)\n conv_compl {n} c := by admit /- proof elided -/"
},
{
"name": "(k",
"content": "instance (k : Nat) : NonExpansive (fun X : Tower F => X.val k) := β¨fun _ _ _ => (Β· _)β©"
},
{
"name": "[OFE",
"content": "instance [OFE Ξ±] : NonExpansive excl (Ξ± := Ξ±) where\n ne _ _ _ a := a"
},
{
"name": "get_ne",
"content": "instance get_ne [Store T K V] [OFE V] (k : K) : NonExpansive (get Β· k : T β V) where\n ne {_ _ _} Ht := Ht k"
},
{
"name": "[Store",
"content": "instance [Store T1 K V1] [Store T2 K V2] [OFE V1] [OFE V2] (f : K β V1 β V2)\n [β k, NonExpansive (f k)] [HasStoreMap T1 T2 K V1 V2] : NonExpansive (dmap f : T1 β T2) where\n ne _ {_ _} H k := by admit /- proof elided -/"
},
{
"name": "HasStoreMap",
"content": "class HasStoreMap (T1 T2 : Type _) (K V1 V2 : outParam (Type _)) [Store T1 K V1] [Store T2 K V2] where\n \n dmap (f : K β V1 β V2) : T1 β T2\n get_dmap : get (dmap f t) k = f k (get t k)"
},
{
"name": "",
"content": "instance : NonExpansive (pcore (Ξ± := Ξ±)) where\n ne n x {y} e := by admit /- proof elided -/"
},
{
"name": "[Heap",
"content": "instance [Heap T K V] [OFE V] (op : V β V β V) [NonExpansiveβ op] :\n NonExpansiveβ (merge (T := T) op) where\n ne _ {_ _} Ht {_ _} Hs k := by admit /- proof elided -/"
},
{
"name": "Heap.instCOFE",
"content": "instance Heap.instCOFE [Heap T K V] [COFE V] : COFE T where\n compl c := hmap (fun _ => COFE.compl <| c.map β¨_, Store.get_ne Β·β©) (c 0)\n conv_compl {_ c} k := by admit /- proof elided -/"
},
{
"name": "infix:60 \" β’ \" => op",
"content": "infix:60 \" β’ \" => op"
},
{
"name": "infix:50 \" βΌ \" => Included",
"content": "infix:50 \" βΌ \" => Included"
},
{
"name": "@[inherit_doc]",
"content": "@[inherit_doc]\ninfixr:25 \" -C> \" => Hom"
}
] | [
{
"name": "Nat.lt_of_le_of_ne",
"module": "Init.Prelude"
},
{
"name": "Nat.le_of_lt_succ",
"module": "Init.Prelude"
},
{
"name": "Nat.lt_succ_self",
"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": "Iris.OFE",
"content": "class OFE (Ξ± : Type _) where\n Equiv : Ξ± β Ξ± β Prop\n Dist : Nat β Ξ± β Ξ± β Prop\n dist_eqv : Equivalence (Dist n)\n equiv_dist : Equiv x y β β n, Dist n x y\n dist_lt : Dist n x y β m < n β Dist m x y"
},
{
"name": "Iris.OFE.NonExpansive",
"content": "class NonExpansive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β f xβ β‘{n}β‘ f xβ"
},
{
"name": "Iris.OFE.id_ne",
"content": "instance id_ne [OFE Ξ±] : NonExpansive (@id Ξ±) := β¨fun _ _ _ h => hβ©"
},
{
"name": "Iris.OFE.NonExpansiveβ",
"content": "class NonExpansiveβ [OFE Ξ±] [OFE Ξ²] [OFE Ξ³] (f : Ξ± β Ξ² β Ξ³) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β β β¦yβ yββ¦, yβ β‘{n}β‘ yβ β f xβ yβ β‘{n}β‘ f xβ yβ"
},
{
"name": "Iris.OFE.DistLater",
"content": "def DistLater [OFE Ξ±] (n : Nat) (x y : Ξ±) : Prop := β m, m < n β x β‘{m}β‘ y"
},
{
"name": "Iris.OFE.Contractive",
"content": "class Contractive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) where\n distLater_dist : DistLater n x y β f x β‘{n}β‘ f y"
},
{
"name": "Iris.OFE.ne_of_contractive",
"content": "instance ne_of_contractive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) [Contractive f] : NonExpansive f where\n ne := fun _ _ _ h => Contractive.distLater_dist (Dist.distLater h)"
},
{
"name": "Iris.OFE._inst_Ξ²",
"content": "instance [OFE Ξ±] [OFE Ξ²] {x : Ξ²} : Contractive (fun _ : Ξ± => x) where\n distLater_dist := fun _ => Dist.rfl"
},
{
"name": "Iris.OFE.Hom",
"content": "@[ext] structure Hom (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] where\n f : Ξ± β Ξ²\n ne : NonExpansive f"
},
{
"name": "Iris.OFE._inst_Ξ±",
"content": "instance [OFE Ξ±] [OFE Ξ²] (f : Ξ± -n> Ξ²) : NonExpansive f := f.ne"
},
{
"name": "Iris.OFE.ContractiveHom",
"content": "@[ext] structure ContractiveHom (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] extends Hom Ξ± Ξ² where\n [contractive : Contractive f]\n ne := ne_of_contractive f"
},
{
"name": "Iris.OFE._inst_Ξ±",
"content": "instance [OFE Ξ±] [OFE Ξ²] (f : Ξ± -c> Ξ²) : Contractive f := f.contractive"
},
{
"name": "Iris.OFE._inst_OFE",
"content": "instance : OFE Unit where\n Equiv _ _ := True\n Dist _ _ _ := True\n dist_eqv := β¨fun _ => β¨β©, id, fun _ => idβ©\n equiv_dist := by admit /- proof elided -/"
},
{
"name": "Iris.OFE._inst_OFE",
"content": "instance [OFE Ξ±] : OFE (ULift Ξ±) where\n Equiv x y := x.down β‘ y.down\n Dist n x y := x.down β‘{n}β‘ y.down\n dist_eqv := InvImage.equivalence dist_eqv\n equiv_dist := equiv_dist\n dist_lt := dist_lt"
},
{
"name": "Iris.OFE._inst_OFE",
"content": "instance [OFE Ξ±] : OFE (Option Ξ±) where\n Equiv := Option.Forallβ Equiv\n Dist n := Option.Forallβ (Dist n)\n dist_eqv := Option.Forallβ.equivalence dist_eqv\n equiv_dist {x y} := by admit /- proof elided -/"
},
{
"name": "Iris.OFE._inst_OFE",
"content": "instance [OFE Ξ±] [OFE.Discrete Ξ±] : OFE.Discrete (Option Ξ±) where\n discrete_0 {mx my} e :=\n match mx, my with\n | none, none => e\n | none, some _ => e\n | some _, none => e\n | some x, some y => show x β‘ y from discrete_0 e"
},
{
"name": "Iris.OFE.OFE",
"content": "instance OFE.Option.some.ne [OFE Ξ±] : OFE.NonExpansive (some : Ξ± β Option Ξ±) := β¨fun _ _ _ => idβ©"
},
{
"name": "Iris.OFE.Option",
"content": "instance Option.merge_ne [OFE Ξ±] {op : Ξ± β Ξ± β Ξ±} [NonExpansiveβ op] :\n NonExpansiveβ (Option.merge op) where\n ne n x1 x2 Hx y1 y2 Hy := by admit /- proof elided -/"
},
{
"name": "Iris.OFE._inst_Ξ±",
"content": "instance [OFEFun (Ξ² : Ξ± β _)] : OFE ((x : Ξ±) β Ξ² x) where\n Equiv f g := β x, f x β‘ g x\n Dist n f g := β x, f x β‘{n}β‘ g x\n dist_eqv := {\n refl _ _ := dist_eqv.refl _\n symm h _ := dist_eqv.symm (h _)\n trans h1 h2 _ := dist_eqv.trans (h1 _) (h2 _)\n }\n equiv_dist {_ _} := by admit /- proof elided -/"
},
{
"name": "Iris.OFE._inst_OFE",
"content": "instance [OFE Ξ±] [OFE Ξ²] : OFE (Ξ± -n> Ξ²) where\n Equiv f g := f.f β‘ g.f\n Dist n f g := f.f β‘{n}β‘ g.f\n dist_eqv := {\n refl _ := dist_eqv.refl _\n symm h := dist_eqv.symm h\n trans h1 h2 := dist_eqv.trans h1 h2\n }\n equiv_dist := equiv_dist\n dist_lt := dist_lt"
},
{
"name": "Iris.OFE._inst_OFE",
"content": "instance [OFE Ξ±] [OFE Ξ²] : OFE (Ξ± -c> Ξ²) where\n Equiv f g := Equiv f.toHom g.toHom\n Dist n f g := Dist n f.toHom g.toHom\n dist_eqv := {\n refl _ := dist_eqv.refl _\n symm h := dist_eqv.symm h\n trans h1 h2 := dist_eqv.trans h1 h2\n }\n equiv_dist := equiv_dist\n dist_lt := dist_lt"
},
{
"name": "Iris.OFE._inst_OFE",
"content": "instance [OFE Ξ±] [OFE Ξ²] : OFE (Ξ± Γ Ξ²) where\n Equiv a b := a.1 β‘ b.1 β§ a.2 β‘ b.2\n Dist n a b := a.1 β‘{n}β‘ b.1 β§ a.2 β‘{n}β‘ b.2\n dist_eqv := {\n refl _ := β¨dist_eqv.refl _, dist_eqv.refl _β©\n symm h := β¨dist_eqv.symm h.1, dist_eqv.symm h.2β©\n trans h1 h2 := β¨dist_eqv.trans h1.1 h2.1, dist_eqv.trans h1.2 h2.2β©\n }\n equiv_dist {_ _} := by admit /- proof elided -/"
},
{
"name": "Iris.OFE.Iso",
"content": "@[ext] structure Iso (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] where\n hom : Ξ± -n> Ξ²\n inv : Ξ² -n> Ξ±\n hom_inv : hom (inv x) β‘ x\n inv_hom : inv (hom x) β‘ x"
},
{
"name": "Iris.OFE._inst_Iso",
"content": "instance [OFE Ξ±] [OFE Ξ²] (iso : Iso Ξ± Ξ²) : NonExpansive iso.hom := iso.hom.ne"
},
{
"name": "Iris.OFE._inst_Iso",
"content": "instance [OFE Ξ±] [OFE Ξ²] (iso : Iso Ξ± Ξ²) : NonExpansive iso.inv := iso.inv.ne"
},
{
"name": "Iris.OFE.Iso.symm",
"content": "def Iso.symm [OFE Ξ±] [OFE Ξ²] (iso : Iso Ξ± Ξ²) : Iso Ξ² Ξ± where\n hom := iso.inv\n inv := iso.hom\n hom_inv := by admit /- proof elided -/"
},
{
"name": "Iris.Chain",
"content": "structure Chain (Ξ± : Type _) [OFE Ξ±] where\n chain : Nat β Ξ±\n cauchy : n β€ i β chain i β‘{n}β‘ chain n"
},
{
"name": "Iris.IsCOFE",
"content": "class IsCOFE (Ξ± : Type _) [OFE Ξ±] where\n compl : Chain Ξ± β Ξ±\n conv_compl {c : Chain Ξ±} : compl c β‘{n}β‘ c n"
},
{
"name": "Iris.LeibnizO",
"content": "@[ext] structure LeibnizO (Ξ± : Type _) where\n car : Ξ±"
},
{
"name": "Iris.optionChain",
"content": "def optionChain (c : Chain (Option Ξ±)) (x : Ξ±) : Chain Ξ± :="
},
{
"name": "Iris.isCOFE_option",
"content": "instance isCOFE_option [IsCOFE Ξ±] : IsCOFE (Option Ξ±) where\n compl c := (c 0).map fun x => IsCOFE.compl (optionChain c x)\n conv_compl {n} c := by admit /- proof elided -/"
},
{
"name": "Iris.Fixpoint.chain",
"content": "def Fixpoint.chain [OFE Ξ±] [Inhabited Ξ±] (f : Ξ± β Ξ±) [Contractive f] : Chain Ξ± where\n chain n := Nat.repeat f (n + 1) default\n cauchy {n} := by admit /- proof elided -/"
},
{
"name": "Iris.fixpoint",
"content": "def fixpoint [COFE Ξ±] [Inhabited Ξ±] (f : Ξ± β Ξ±) [Contractive f] : Ξ± :=\n COFE.compl <| Fixpoint.chain f\n\nnonrec abbrev OFE.ContractiveHom.fixpoint [COFE Ξ±] [Inhabited Ξ±] (f : Ξ± -c> Ξ±) : Ξ± := fixpoint f.f"
}
] | [
{
"name": "Iris.OFE.Dist.lt",
"content": "theorem Dist.lt [OFE Ξ±] {m n} {x y : Ξ±} : x β‘{n}β‘ y β m < n β x β‘{m}β‘ y"
},
{
"name": "Iris.OFE.Dist.le",
"content": "theorem Dist.le [OFE Ξ±] {m n} {x y : Ξ±} (h : x β‘{n}β‘ y) (h' : m β€ n) : x β‘{m}β‘ y"
},
{
"name": "Iris.OFE.Dist.rfl",
"content": "@[simp, refl] theorem Dist.rfl [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ x"
},
{
"name": "Iris.OFE.Dist.symm",
"content": "@[symm] theorem Dist.symm [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ y β y β‘{n}β‘ x"
},
{
"name": "Iris.OFE.Dist.trans",
"content": "theorem Dist.trans [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ y β y β‘{n}β‘ z β x β‘{n}β‘ z"
},
{
"name": "Iris.OFE.equiv_eqv",
"content": "theorem equiv_eqv [ofe : OFE Ξ±] : Equivalence ofe.Equiv"
},
{
"name": "Iris.OFE.Equiv.symm",
"content": "@[symm] theorem Equiv.symm [OFE Ξ±] {x : Ξ±} : x β‘ y β y β‘ x"
},
{
"name": "Iris.OFE.DistLater.symm",
"content": "@[symm] theorem DistLater.symm [OFE Ξ±] {n} {x : Ξ±} (h : DistLater n x y) : DistLater n y x"
},
{
"name": "Iris.OFE.distLater_zero",
"content": "@[simp] theorem distLater_zero [OFE Ξ±] {x y : Ξ±} : DistLater 0 x y"
},
{
"name": "Iris.OFE.distLater_succ",
"content": "theorem distLater_succ [OFE Ξ±] {n} {x y : Ξ±} : DistLater n.succ x y β x β‘{n}β‘ y"
},
{
"name": "Iris.OFE.Contractive.zero",
"content": "@[simp] theorem Contractive.zero [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) [Contractive f] {x y} :\n f x β‘{0}β‘ f y"
},
{
"name": "Iris.OFE.Contractive.succ",
"content": "theorem Contractive.succ [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) [Contractive f] {n x y}\n (h : x β‘{n}β‘ y) : f x β‘{n.succ}β‘ f y"
}
] | namespace Iris
class OFE (Ξ± : Type _) where
Equiv : Ξ± β Ξ± β Prop
Dist : Nat β Ξ± β Ξ± β Prop
dist_eqv : Equivalence (Dist n)
equiv_dist : Equiv x y β β n, Dist n x y
dist_lt : Dist n x y β m < n β Dist m x y
open OFE
scoped infix:40 " β‘ " => OFE.Equiv
scoped notation:40 x " β‘{" n "}β‘ " y:41 => OFE.Dist n x y
namespace OFE
class NonExpansive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) where
ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β f xβ β‘{n}β‘ f xβ
instance id_ne [OFE Ξ±] : NonExpansive (@id Ξ±) := β¨fun _ _ _ h => hβ©
class NonExpansiveβ [OFE Ξ±] [OFE Ξ²] [OFE Ξ³] (f : Ξ± β Ξ² β Ξ³) where
ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β β β¦yβ yββ¦, yβ β‘{n}β‘ yβ β f xβ yβ β‘{n}β‘ f xβ yβ
def DistLater [OFE Ξ±] (n : Nat) (x y : Ξ±) : Prop := β m, m < n β x β‘{m}β‘ y
class Contractive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) where
distLater_dist : DistLater n x y β f x β‘{n}β‘ f y
instance ne_of_contractive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) [Contractive f] : NonExpansive f where
ne := fun _ _ _ h => Contractive.distLater_dist (Dist.distLater h)
instance [OFE Ξ±] [OFE Ξ²] {x : Ξ²} : Contractive (fun _ : Ξ± => x) where
distLater_dist := fun _ => Dist.rfl
@[ext] structure Hom (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] where
f : Ξ± β Ξ²
ne : NonExpansive f
@[inherit_doc]
infixr:25 " -n> " => Hom
instance [OFE Ξ±] [OFE Ξ²] (f : Ξ± -n> Ξ²) : NonExpansive f := f.ne
@[ext] structure ContractiveHom (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] extends Hom Ξ± Ξ² where
[contractive : Contractive f]
ne := ne_of_contractive f
infixr:25 " -c> " => ContractiveHom
instance [OFE Ξ±] [OFE Ξ²] (f : Ξ± -c> Ξ²) : Contractive f := f.contractive
instance : OFE Unit where
Equiv _ _ := True
Dist _ _ _ := True
dist_eqv := β¨fun _ => β¨β©, id, fun _ => idβ©
equiv_dist := by admit /- proof elided -/
instance [OFE Ξ±] : OFE (ULift Ξ±) where
Equiv x y := x.down β‘ y.down
Dist n x y := x.down β‘{n}β‘ y.down
dist_eqv := InvImage.equivalence dist_eqv
equiv_dist := equiv_dist
dist_lt := dist_lt
instance [OFE Ξ±] : OFE (Option Ξ±) where
Equiv := Option.Forallβ Equiv
Dist n := Option.Forallβ (Dist n)
dist_eqv := Option.Forallβ.equivalence dist_eqv
equiv_dist {x y} := by admit /- proof elided -/
instance [OFE Ξ±] [OFE.Discrete Ξ±] : OFE.Discrete (Option Ξ±) where
discrete_0 {mx my} e :=
match mx, my with
| none, none => e
| none, some _ => e
| some _, none => e
| some x, some y => show x β‘ y from discrete_0 e
instance OFE.Option.some.ne [OFE Ξ±] : OFE.NonExpansive (some : Ξ± β Option Ξ±) := β¨fun _ _ _ => idβ©
instance Option.merge_ne [OFE Ξ±] {op : Ξ± β Ξ± β Ξ±} [NonExpansiveβ op] :
NonExpansiveβ (Option.merge op) where
ne n x1 x2 Hx y1 y2 Hy := by admit /- proof elided -/
instance [OFEFun (Ξ² : Ξ± β _)] : OFE ((x : Ξ±) β Ξ² x) where
Equiv f g := β x, f x β‘ g x
Dist n f g := β x, f x β‘{n}β‘ g x
dist_eqv := {
refl _ _ := dist_eqv.refl _
symm h _ := dist_eqv.symm (h _)
trans h1 h2 _ := dist_eqv.trans (h1 _) (h2 _)
}
equiv_dist {_ _} := by admit /- proof elided -/
instance [OFE Ξ±] [OFE Ξ²] : OFE (Ξ± -n> Ξ²) where
Equiv f g := f.f β‘ g.f
Dist n f g := f.f β‘{n}β‘ g.f
dist_eqv := {
refl _ := dist_eqv.refl _
symm h := dist_eqv.symm h
trans h1 h2 := dist_eqv.trans h1 h2
}
equiv_dist := equiv_dist
dist_lt := dist_lt
instance [OFE Ξ±] [OFE Ξ²] : OFE (Ξ± -c> Ξ²) where
Equiv f g := Equiv f.toHom g.toHom
Dist n f g := Dist n f.toHom g.toHom
dist_eqv := {
refl _ := dist_eqv.refl _
symm h := dist_eqv.symm h
trans h1 h2 := dist_eqv.trans h1 h2
}
equiv_dist := equiv_dist
dist_lt := dist_lt
instance [OFE Ξ±] [OFE Ξ²] : OFE (Ξ± Γ Ξ²) where
Equiv a b := a.1 β‘ b.1 β§ a.2 β‘ b.2
Dist n a b := a.1 β‘{n}β‘ b.1 β§ a.2 β‘{n}β‘ b.2
dist_eqv := {
refl _ := β¨dist_eqv.refl _, dist_eqv.refl _β©
symm h := β¨dist_eqv.symm h.1, dist_eqv.symm h.2β©
trans h1 h2 := β¨dist_eqv.trans h1.1 h2.1, dist_eqv.trans h1.2 h2.2β©
}
equiv_dist {_ _} := by admit /- proof elided -/
@[ext] structure Iso (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] where
hom : Ξ± -n> Ξ²
inv : Ξ² -n> Ξ±
hom_inv : hom (inv x) β‘ x
inv_hom : inv (hom x) β‘ x
instance [OFE Ξ±] [OFE Ξ²] (iso : Iso Ξ± Ξ²) : NonExpansive iso.hom := iso.hom.ne
instance [OFE Ξ±] [OFE Ξ²] (iso : Iso Ξ± Ξ²) : NonExpansive iso.inv := iso.inv.ne
def Iso.symm [OFE Ξ±] [OFE Ξ²] (iso : Iso Ξ± Ξ²) : Iso Ξ² Ξ± where
hom := iso.inv
inv := iso.hom
hom_inv := by admit /- proof elided -/
end OFE
structure Chain (Ξ± : Type _) [OFE Ξ±] where
chain : Nat β Ξ±
cauchy : n β€ i β chain i β‘{n}β‘ chain n
namespace Chain
end Chain
class IsCOFE (Ξ± : Type _) [OFE Ξ±] where
compl : Chain Ξ± β Ξ±
conv_compl {c : Chain Ξ±} : compl c β‘{n}β‘ c n
namespace COFE
end COFE
@[ext] structure LeibnizO (Ξ± : Type _) where
car : Ξ±
section DiscreteFunOF
open COFE
end DiscreteFunOF
section Option
variable [OFE Ξ±]
def optionChain (c : Chain (Option Ξ±)) (x : Ξ±) : Chain Ξ± :=
instance isCOFE_option [IsCOFE Ξ±] : IsCOFE (Option Ξ±) where
compl c := (c 0).map fun x => IsCOFE.compl (optionChain c x)
conv_compl {n} c := by admit /- proof elided -/
end Option
section OptionOF
open COFE
variable (F : OFunctorPre)
end OptionOF
section Fixpoint
def Fixpoint.chain [OFE Ξ±] [Inhabited Ξ±] (f : Ξ± β Ξ±) [Contractive f] : Chain Ξ± where
chain n := Nat.repeat f (n + 1) default
cauchy {n} := by admit /- proof elided -/
def fixpoint [COFE Ξ±] [Inhabited Ξ±] (f : Ξ± β Ξ±) [Contractive f] : Ξ± :=
COFE.compl <| Fixpoint.chain f
nonrec abbrev OFE.ContractiveHom.fixpoint [COFE Ξ±] [Inhabited Ξ±] (f : Ξ± -c> Ξ±) : Ξ± := fixpoint f.f | theorem fixpoint_unfold [COFE Ξ±] [Inhabited Ξ±] (f : Ξ± -c> Ξ±) :
fixpoint f β‘ f (fixpoint f) := | := by
refine equiv_dist.mpr fun n => ?_
apply COFE.conv_compl.trans
refine .trans ?_ (NonExpansive.ne COFE.conv_compl.symm)
induction n with
| zero => exact Contractive.zero f.f
| succ _ IH => exact (Contractive.succ f.f IH.symm).symm | 4 | 41 | false | Framework |
233 | Iris.BI.loeb | theorem loeb [BI PROP] [BILoeb PROP] {P : PROP} : (β· P β P) β’ P | iris-lean | src/Iris/BI/DerivedLaws.lean | [
"import Iris.BI.Extensions",
"import Iris.Std.TC",
"import Iris.Std.Classes",
"import Iris.BI.BI",
"import src.Iris.Algebra.OFE",
"import src.Iris.BI.BI",
"import Iris.BI.Classes",
"import Iris.Std.Rewrite"
] | [
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "Option.merge",
"module": "Init.Data.Option.Basic"
},
{
"name": "id",
"module": "Init.Prelude"
},
{
"name": "Equivalence",
"module": "Init.Core"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "m",
"module": "QqTest.matching"
},
{
"name": "Function.const",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Bool",
"module": "Init.Prelude"
}
] | [
{
"name": "macro \"β\" xs:explicitBinders \", \" b:term : term => do",
"content": "macro \"β\" xs:explicitBinders \", \" b:term : term => do\n return β¨β expandExplicitBinders ``BIBase.exists xs bβ©"
},
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y\n\nsyntax:max \"<pers> \" term:40 : term"
},
{
"name": "macro:25 P:term:29 \" β’ \" Q:term:25 : term => ``(BIBase.Entai",
"content": "macro:25 P:term:29 \" β’ \" Q:term:25 : term => ``(BIBase.Entails iprop($P) iprop($Q))\n\ndelab_rule BIBase.Entails\n | `($_ $P $Q) => do ``($(β unpackIprop P) β’ $(β unpackIprop Q))"
},
{
"name": "macro:25 P:term:29 \" β£β’ \" Q:term:29 : term => ``(BiEntails i",
"content": "macro:25 P:term:29 \" β£β’ \" Q:term:29 : term => ``(BiEntails iprop($P) iprop($Q))\n\ndelab_rule BIBase.Entails\n | `($_ iprop(emp) $P) => do ``(β’ $(β unpackIprop P))\n\ndelab_rule BIBase.BiEntails\n | `($_ $P $Q) => do ``($(β unpackIprop P) β£β’ $(β unpackIprop Q))\n\nsyntax \"β\" term \"β\" : term\n\nsyntax:max \"β· \" term:40 : term"
},
{
"name": "macro:max \"iprop(\" P:term \" : \" t:term \")\" : term => `((ipro",
"content": "macro:max \"iprop(\" P:term \" : \" t:term \")\" : term => `((iprop($P) : $t))\n\nsyntax:max \"iprop(\" term \")\" : term\n\nsyntax:max \"<affine> \" term:40 : term\n\nsyntax:max \"β‘ \" term:40 : term\n\nsyntax:max \"<absorb> \" term:40 : term"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(term($t))) => pure t\n | `(iprop($t)) => pure t"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(($P))) => ``((iprop($P)))\n | `(iprop(if $c then $t else $e)) => ``(if $c then iprop($t) else iprop($e))\n | `(iprop(($P : $t))) => ``((iprop($P) : $t))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(emp)) => ``(BIBase.emp)\n | `(iprop(β$Οβ)) => ``(BIBase.pure $Ο)\n | `(iprop($P β§ $Q)) => ``(BIBase.and iprop($P) iprop($Q))\n | `(iprop($P β¨ $Q)) => ``(BIBase.or iprop($P) iprop($Q))\n | `(iprop($P β $Q)) => ``(BIBase.imp iprop($P) iprop($Q))\n | `(iprop(β $xs, $Ξ¨)) => do expandExplicitBinders ``BIBase.exists xs (β ``(iprop($Ξ¨)))\n | `(iprop($P β $Q)) => ``(BIBase.sep iprop($P) iprop($Q))\n | `(iprop($P -β $Q)) => ``(BIBase.wand iprop($P) iprop($Q))\n | `(iprop(<pers> $P)) => ``(BIBase.persistently iprop($P))\n | `(iprop(β· $P)) => ``(BIBase.later iprop($P))\n\ndelab_rule BIBase.emp\n | `($_) => ``(iprop($(mkIdent `emp)))\ndelab_rule BIBase.pure\n | `($_ $Ο) => ``(iprop(β$Οβ))\ndelab_rule BIBase.and\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β§ $(β unpackIprop Q)))\ndelab_rule BIBase.or\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β¨ $(β unpackIprop Q)))\ndelab_rule BIBase.imp\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule BIBase.forall\n | `($_ fun $x:ident => iprop(β $y:ident $[$z:ident]*, $Ξ¨)) => do\n ``(iprop(β $x:ident $y:ident $[$z:ident]*, $Ξ¨))\n | `($_ fun $x:ident => $Ξ¨) => do ``(iprop(β $x:ident, $(β unpackIprop Ξ¨)))\ndelab_rule BIBase.exists\n | `($_ fun $x:ident => iprop(β $y:ident $[$z:ident]*, $Ξ¨)) => do\n ``(iprop(β $x:ident $y:ident $[$z:ident]*, $Ξ¨))\n | `($_ fun $x:ident => $Ξ¨) => do ``(iprop(β $x:ident, $(β unpackIprop Ξ¨)))\ndelab_rule BIBase.sep\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule BIBase.wand\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) -β $(β unpackIprop Q)))\ndelab_rule BIBase.persistently\n | `($_ $P) => do ``(iprop(<pers> $(β unpackIprop P)))\n\ndelab_rule BIBase.pure\n | `($_ True) => ``(iprop($(mkIdent `True)))\n | `($_ False) => ``(iprop($(mkIdent `False)))\ndelab_rule BIBase.imp\n | `($_ $P iprop(False)) => do ``(iprop(Β¬$(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β _%$tk, $Ξ¨)) => ``(BIBase.forall (fun _%$tk => iprop($Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $x:ident, $Ξ¨)) => ``(BIBase.forall (fun $x => iprop($Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β (_%$tk : $t), $Ξ¨)) => ``(BIBase.forall (fun (_%$tk : $t) => iprop($Ξ¨)))\n | `(iprop(β (_%$tk $xs* : $t), $Ξ¨)) =>\n ``(BIBase.forall (fun (_%$tk : $t) => iprop(β ($xs* : $t), $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β ($x:ident : $t), $Ξ¨)) => ``(BIBase.forall (fun ($x : $t) => iprop($Ξ¨)))\n | `(iprop(β ($x:ident $xs* : $t), $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop(β ($xs* : $t), $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β {_%$tk : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun {_%$tk : $t} => iprop($Ξ¨)))\n | `(iprop(β {_%$tk $xs* : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun {_%$tk : $t} => iprop(β {$xs* : $t}, $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β {$x:ident : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop($Ξ¨)))\n | `(iprop(β {$x:ident $xs* : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop(β {$xs* : $t}, $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $x $y $xs*, $Ξ¨)) => ``(iprop(β $x, β $y $xs*, $Ξ¨))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(True)) => ``(BIBase.pure True)\n | `(iprop(False)) => ``(BIBase.pure False)\n | `(iprop(Β¬$P)) => ``(iprop($P β False))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop($P β $Q)) => ``(iff iprop($P) iprop($Q))\n | `(iprop($P β-β $Q)) => ``(wandIff iprop($P) iprop($Q))\n\ndelab_rule iff\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule wandIff\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β-β $(β unpackIprop Q)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(<affine> $P)) => ``(affinely iprop($P))\n | `(iprop(<absorb> $P)) => ``(absorbingly iprop($P))\n\ndelab_rule affinely\n | `($_ $P) => do ``(iprop(<affine> $(β unpackIprop P)))\ndelab_rule absorbingly\n | `($_ $P) => do ``(iprop(<absorb> $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β‘ $P)) => ``(intuitionistically iprop($P))\n\ndelab_rule intuitionistically\n | `($_ $P) => do ``(iprop(β‘ $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(<pers>?$p $P)) => ``(persistentlyIf $p iprop($P))\n | `(iprop(<affine>?$p $P)) => ``(affinelyIf $p iprop($P))\n | `(iprop(<absorb>?$p $P)) => ``(absorbinglyIf $p iprop($P))\n | `(iprop(β‘?$p $P)) => ``(intuitionisticallyIf $p iprop($P))\n\ndelab_rule persistentlyIf\n | `($_ $p $P) => do ``(iprop(<pers>?$p $(β unpackIprop P)))\ndelab_rule affinelyIf\n | `($_ $p $P) => do ``(iprop(<affine>?$p $(β unpackIprop P)))\ndelab_rule absorbinglyIf\n | `($_ $p $P) => do ``(iprop(<absorb>?$p $(β unpackIprop P)))\ndelab_rule intuitionisticallyIf\n | `($_ $p $P) => do ``(iprop(β‘?$p $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β·^[$n] $P)) => ``(laterN $n iprop($P))\n\ndelab_rule laterN\n | `($_ $n $P) => do ``(iprop(β·^[$n] $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $P)) => ``(except0 iprop($P))\n\ndelab_rule except0\n | `($_ $P) => do ``(iprop(β $(β unpackIprop P)))"
},
{
"name": "BIBase",
"content": "class BIBase (PROP : Type u) where\n Entails : PROP β PROP β Prop\n emp : PROP\n pure : Prop β PROP\n and : PROP β PROP β PROP\n or : PROP β PROP β PROP\n imp : PROP β PROP β PROP\n sForall : (PROP β Prop) β PROP\n sExists : (PROP β Prop) β PROP\n sep : PROP β PROP β PROP\n wand : PROP β PROP β PROP\n persistently : PROP β PROP\n later : PROP β PROP"
},
{
"name": "BI",
"content": "class BI (PROP : Type _) extends COFE PROP, BI.BIBase PROP where\n Equiv P Q := P β£β’ Q\n\n entails_preorder : Preorder Entails\n equiv_iff {P Q : PROP} : (P β‘ Q) β P β£β’ Q := by admit /- proof elided -/"
},
{
"name": "BILoeb",
"content": "class BILoeb (PROP : Type _) [BI PROP] where\n loeb_weak {P : PROP} : (β· P β’ P) β True β’ P"
},
{
"name": "liftRel",
"content": "def liftRel (R : Ξ± β Ξ² β Prop) (A : Ξ± β Prop) (B : Ξ² β Prop) : Prop :=\n (β a, A a β β b, B b β§ R a b) β§ (β b, B b β β a, A a β§ R a b)"
},
{
"name": "Preorder",
"content": "class Preorder (R : Relation Ξ±) extends Reflexive R, Transitive R"
},
{
"name": "Reflexive",
"content": "class Reflexive (R : Relation Ξ±) where\n refl {x : Ξ±} : R x x"
},
{
"name": "Relation",
"content": "abbrev Relation (Ξ± : Type _) := Ξ± β Ξ± β Prop"
},
{
"name": "Transitive",
"content": "class Transitive (R : Relation Ξ±) where\n trans {x y z : Ξ±} : R x y β R y z β R x z"
},
{
"name": "NonExpansiveβ",
"content": "class NonExpansiveβ [OFE Ξ±] [OFE Ξ²] [OFE Ξ³] (f : Ξ± β Ξ² β Ξ³) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β β β¦yβ yββ¦, yβ β‘{n}β‘ yβ β f xβ yβ β‘{n}β‘ f xβ yβ"
},
{
"name": "OFE.ContractiveHom.fixpoint_ne",
"content": "instance OFE.ContractiveHom.fixpoint_ne [COFE Ξ±] [Inhabited Ξ±] :\n NonExpansive (ContractiveHom.fixpoint (Ξ± := Ξ±)) where\n ne n f1 f2 H := by admit /- proof elided -/"
},
{
"name": "ContractiveHom",
"content": "@[ext] structure ContractiveHom (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] extends Hom Ξ± Ξ² where\n [contractive : Contractive f]\n ne := ne_of_contractive f"
},
{
"name": "OFE.Option.some.ne",
"content": "instance OFE.Option.some.ne [OFE Ξ±] : OFE.NonExpansive (some : Ξ± β Option Ξ±) := β¨fun _ _ _ => idβ©"
},
{
"name": "Option.merge_ne",
"content": "instance Option.merge_ne [OFE Ξ±] {op : Ξ± β Ξ± β Ξ±} [NonExpansiveβ op] :\n NonExpansiveβ (Option.merge op) where\n ne n x1 x2 Hx y1 y2 Hy := by admit /- proof elided -/"
},
{
"name": "NonExpansive",
"content": "class NonExpansive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β f xβ β‘{n}β‘ f xβ"
},
{
"name": "COFE.OFunctor.constOF_RFunctor",
"content": "instance COFE.OFunctor.constOF_RFunctor [CMRA B] : RFunctor (constOF B) where\n map f g := by admit /- proof elided -/"
},
{
"name": "IsCOFE",
"content": "class IsCOFE (Ξ± : Type _) [OFE Ξ±] where\n compl : Chain Ξ± β Ξ±\n conv_compl {c : Chain Ξ±} : compl c β‘{n}β‘ c n"
},
{
"name": "Chain",
"content": "structure Chain (Ξ± : Type _) [OFE Ξ±] where\n chain : Nat β Ξ±\n cauchy : n β€ i β chain i β‘{n}β‘ chain n"
},
{
"name": "LawfulBigOp",
"content": "class LawfulBigOp (f : PROP β PROP β PROP) (unit : outParam PROP)\n (eq : outParam (PROP β PROP β Prop)) where\n refl : eq a a\n symm : eq a b β eq b a\n trans : eq a b β eq b c β eq a c\n comm : eq (f a b) (f b a)\n assoc : eq (f (f a b) c) (f a (f b c))\n left_id : eq (f unit a) a\n congr_l : eq a a' β eq (f a b) (f a' b)"
},
{
"name": "intuitionistically",
"content": "def intuitionistically [BIBase PROP] (P : PROP) : PROP := iprop(<affine> <pers> P)"
},
{
"name": "Affine",
"content": "class Affine [BI PROP] (P : PROP) where\n affine : P β’ emp"
},
{
"name": "bigAnd",
"content": "def bigAnd [BIBase PROP] (Ps : List PROP) : PROP := bigOp and iprop(True) Ps"
},
{
"name": "bigOp",
"content": "def bigOp (f : PROP β PROP β PROP) (unit : PROP) : List PROP β PROP\n | [] => unit\n | [P] => P\n | P :: Ps => f P (bigOp f unit Ps)"
},
{
"name": "absorbingly",
"content": "def absorbingly [BIBase PROP] (P : PROP) : PROP := iprop(True β P)"
},
{
"name": "BiEntails",
"content": "structure BiEntails [BIBase PROP] (P Q : PROP) where\n mp : P β’ Q\n mpr : Q β’ P"
},
{
"name": "persistentlyIf",
"content": "def persistentlyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then <pers> P else P)"
},
{
"name": "intuitionisticallyIf",
"content": "def intuitionisticallyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then β‘ P else P)"
},
{
"name": "bigSep",
"content": "def bigSep [BIBase PROP] (Ps : List PROP) : PROP := bigOp sep iprop(emp) Ps"
},
{
"name": "affinely",
"content": "def affinely [BIBase PROP] (P : PROP) : PROP := iprop(emp β§ P)"
},
{
"name": "bigOr",
"content": "def bigOr [BIBase PROP] (Ps : List PROP) : PROP := bigOp or iprop(False) Ps"
},
{
"name": "absorbinglyIf",
"content": "def absorbinglyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then <absorb> P else P)"
},
{
"name": "affinelyIf",
"content": "def affinelyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then <affine> P else P)"
},
{
"name": "wandIff",
"content": "def wandIff [BIBase PROP] (P Q : PROP) : PROP := iprop((P -β Q) β§ (Q -β P))"
},
{
"name": "scoped infix:40 \" β‘ \" => OFE.Equiv",
"content": "scoped infix:40 \" β‘ \" => OFE.Equiv"
},
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y"
},
{
"name": "infixr:25 \" -c> \" => ContractiveHom",
"content": "infixr:25 \" -c> \" => ContractiveHom"
},
{
"name": "notation:40 \"[β§] \" Ps:max => bigAnd Ps",
"content": "notation:40 \"[β§] \" Ps:max => bigAnd Ps"
},
{
"name": "notation:40 \"[β¨] \" Ps:max => bigOr Ps",
"content": "notation:40 \"[β¨] \" Ps:max => bigOr Ps"
},
{
"name": "notation:40 \"[β] \" Ps:max => bigSep Ps",
"content": "notation:40 \"[β] \" Ps:max => bigSep Ps"
}
] | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "Dist.trans",
"content": "theorem Dist.trans [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ y β y β‘{n}β‘ z β x β‘{n}β‘ z"
},
{
"name": "BIBase.BiEntails.trans",
"content": "theorem BIBase.BiEntails.trans [BI PROP] {P Q R : PROP} (h1 : P β£β’ Q) (h2 : Q β£β’ R) : P β£β’ R"
},
{
"name": "BIBase.Entails.trans",
"content": "theorem BIBase.Entails.trans [BI PROP] {P Q R : PROP} (h1 : P β’ Q) (h2 : Q β’ R) : P β’ R"
},
{
"name": "Equiv.trans",
"content": "theorem Equiv.trans [OFE Ξ±] {x : Ξ±} : x β‘ y β y β‘ z β x β‘ z"
},
{
"name": "equiv_eqv",
"content": "theorem equiv_eqv [ofe : OFE Ξ±] : Equivalence ofe.Equiv"
},
{
"name": "Dist.symm",
"content": "@[symm] theorem Dist.symm [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ y β y β‘{n}β‘ x"
},
{
"name": "Dist.rfl",
"content": "@[simp, refl] theorem Dist.rfl [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ x"
},
{
"name": "DistLater.trans",
"content": "theorem DistLater.trans [OFE Ξ±] {n} {x : Ξ±} (h1 : DistLater n x y) (h2 : DistLater n y z) :\n DistLater n x z"
}
] | [] | [
{
"name": "Iris.BI.and_elim_l'",
"content": "theorem and_elim_l' [BI PROP] {P Q R : PROP} (h : P β’ R) : P β§ Q β’ R"
},
{
"name": "Iris.BI.and_elim_r'",
"content": "theorem and_elim_r' [BI PROP] {P Q R : PROP} (h : Q β’ R) : P β§ Q β’ R"
},
{
"name": "Iris.BI.and_symm",
"content": "theorem and_symm [BI PROP] {P Q : PROP} : P β§ Q β’ Q β§ P"
},
{
"name": "Iris.BI.imp_intro'",
"content": "theorem imp_intro' [BI PROP] {P Q R : PROP} (h : Q β§ P β’ R) : P β’ Q β R"
},
{
"name": "Iris.BI.imp_elim'",
"content": "theorem imp_elim' [BI PROP] {P Q R : PROP} (h : Q β’ P β R) : P β§ Q β’ R"
},
{
"name": "Iris.BI.imp_elim_l",
"content": "theorem imp_elim_l [BI PROP] {P Q : PROP} : (P β Q) β§ P β’ Q"
},
{
"name": "Iris.BI.imp_elim_r",
"content": "theorem imp_elim_r [BI PROP] {P Q : PROP} : P β§ (P β Q) β’ Q"
},
{
"name": "Iris.BI.true_intro",
"content": "theorem true_intro [BI PROP] {P : PROP} : P β’ True"
},
{
"name": "Iris.BI.and_mono",
"content": "@[rw_mono_rule]\ntheorem and_mono [BI PROP] {P P' Q Q' : PROP} (h1 : P β’ Q) (h2 : P' β’ Q') : P β§ P' β’ Q β§ Q'"
},
{
"name": "Iris.BI.and_mono_l",
"content": "theorem and_mono_l [BI PROP] {P P' Q : PROP} (h : P β’ P') : P β§ Q β’ P' β§ Q"
},
{
"name": "Iris.BI.and_mono_r",
"content": "theorem and_mono_r [BI PROP] {P Q Q' : PROP} (h : Q β’ Q') : P β§ Q β’ P β§ Q'"
},
{
"name": "Iris.BI.and_self",
"content": "theorem and_self [BI PROP] {P : PROP} : P β§ P β£β’ P"
},
{
"name": "Iris.BI.and_comm",
"content": "theorem and_comm [BI PROP] {P Q : PROP} : P β§ Q β£β’ Q β§ P"
},
{
"name": "Iris.BI.and_assoc",
"content": "theorem and_assoc [BI PROP] {P Q R : PROP} : (P β§ Q) β§ R β£β’ P β§ Q β§ R"
},
{
"name": "Iris.BI.pure_elim",
"content": "theorem pure_elim [BI PROP] (Ο : Prop) {Q R : PROP} (h1 : Q β’ βΟβ) (h2 : Ο β Q β’ R) : Q β’ R"
},
{
"name": "Iris.BI.pure_elim_l",
"content": "theorem pure_elim_l [BI PROP] {Ο : Prop} {Q R : PROP} (h : Ο β Q β’ R) : βΟβ β§ Q β’ R"
},
{
"name": "Iris.BI.pure_elim_r",
"content": "theorem pure_elim_r [BI PROP] {Ο : Prop} {Q R : PROP} (h : Ο β Q β’ R) : Q β§ βΟβ β’ R"
},
{
"name": "Iris.BI.later_impl",
"content": "theorem later_impl [BI PROP] {P Q : PROP} : β· (P β Q) β’ β· P β β· Q"
},
{
"name": "Iris.BI.entails_impl_true",
"content": "theorem entails_impl_true [BI PROP] {P Q : PROP} :\n (P β’ Q) β iprop((True : PROP) β’ (P β Q))"
}
] | import Iris.BI.Classes
import Iris.BI.Extensions
import Iris.BI.BI
import Iris.Std.Classes
import Iris.Std.Rewrite
import Iris.Std.TC
namespace Iris.BI
open Iris.Std BI | theorem loeb [BI PROP] [BILoeb PROP] {P : PROP} : (β· P β P) β’ P := | := by
apply entails_impl_true.mpr
apply BILoeb.loeb_weak
apply imp_intro
apply (and_mono .rfl and_self.mpr).trans
apply (and_mono .rfl (and_mono later_intro .rfl)).trans
apply (and_mono later_impl .rfl).trans
apply and_assoc.mpr.trans
apply (and_mono imp_elim_l .rfl).trans
exact imp_elim_r | 7 | 68 | false | Framework |
234 | Iris.BI.plainly_and_sep | theorem plainly_and_sep : β (P β§ Q) β’ β (P β Q) | iris-lean | src/Iris/BI/Plainly.lean | [
"import Iris.Algebra",
"import src.Iris.BI.DerivedLaws",
"import src/Iris/Instances/UPred/Instance.lean",
"import Iris.BI.DerivedLaws",
"import Iris.BI.BI",
"import src.Iris.BI.BI",
"import Iris.BI.Classes"
] | [
{
"name": "Lean.MonadQuotation",
"module": "Init.Prelude"
},
{
"name": "Lean.MonadRef",
"module": "Init.Prelude"
},
{
"name": "Monad",
"module": "Init.Prelude"
},
{
"name": "m",
"module": "QqTest.matching"
},
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "Option.merge",
"module": "Init.Data.Option.Basic"
},
{
"name": "id",
"module": "Init.Prelude"
},
{
"name": "Equivalence",
"module": "Init.Core"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Bool",
"module": "Init.Prelude"
}
] | [
{
"name": "syntax term:26 \" ==β \" term:25 : term",
"content": "syntax term:26 \" ==β \" term:25 : term\n\nsyntax term \"={ \" term \" , \" term \" }=β \" term : term\n\nsyntax term \"={ \" term \" }=β \" term : term\n\nsyntax term \"={ \" term \" }[ \" term \" ]β·=β \" term : term\n\nsyntax term \"={ \" term \" }β·=β \" term : term\n\nsyntax term \"={ \" term \" }[ \" term \" ]β·^\" term \"=β \" term : term\n\nsyntax term \"={ \" term \" }β·^\" term \"=β \" term : term"
},
{
"name": "macro:max \"iprop(\" P:term \" : \" t:term \")\" : term => `((ipro",
"content": "macro:max \"iprop(\" P:term \" : \" t:term \")\" : term => `((iprop($P) : $t))\n\nsyntax:max \"iprop(\" term \")\" : term"
},
{
"name": "macro \"β\" xs:explicitBinders \", \" b:term : term => do",
"content": "macro \"β\" xs:explicitBinders \", \" b:term : term => do\n return β¨β expandExplicitBinders ``BIBase.exists xs bβ©"
},
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y\n\nsyntax:max \"<pers> \" term:40 : term"
},
{
"name": "macro:25 P:term:29 \" β’ \" Q:term:25 : term => ``(BIBase.Entai",
"content": "macro:25 P:term:29 \" β’ \" Q:term:25 : term => ``(BIBase.Entails iprop($P) iprop($Q))\n\ndelab_rule BIBase.Entails\n | `($_ $P $Q) => do ``($(β unpackIprop P) β’ $(β unpackIprop Q))"
},
{
"name": "macro:25 P:term:29 \" β£β’ \" Q:term:29 : term => ``(BiEntails i",
"content": "macro:25 P:term:29 \" β£β’ \" Q:term:29 : term => ``(BiEntails iprop($P) iprop($Q))\n\ndelab_rule BIBase.Entails\n | `($_ iprop(emp) $P) => do ``(β’ $(β unpackIprop P))\n\ndelab_rule BIBase.BiEntails\n | `($_ $P $Q) => do ``($(β unpackIprop P) β£β’ $(β unpackIprop Q))\n\nsyntax \"β\" term \"β\" : term\n\nsyntax:max \"β· \" term:40 : term\n\nsyntax \"β \" term:40 : term"
},
{
"name": "notation:50 x \" βΌ{\" n \"} \" y:51 => IncludedN n x y",
"content": "notation:50 x \" βΌ{\" n \"} \" y:51 => IncludedN n x y"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(|==> $P)) => ``(BUpd.bupd iprop($P))\n | `(iprop($P ==β $Q)) => ``(BIBase.wand iprop($P) (BUpd.bupd iprop($Q)))\n\ndelab_rule BUpd.bupd\n | `($_ $P) => do ``(iprop(|==> $(β Iris.BI.unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(|={ $E1 , $E2 }=> $P)) => ``(FUpd.fupd $E1 $E2 iprop($P))\n | `(iprop($P ={ $E1 , $E2 }=β $Q)) => ``(BIBase.wand iprop($P) (FUpd.fupd $E1 $E2 iprop($Q)))\n | `(iprop(|={ $E1 }=> $P)) => ``(FUpd.fupd $E1 $E1 iprop($P))\n | `(iprop($P ={ $E1 }=β $Q)) => ``(BIBase.wand iprop($P) (FUpd.fupd $E1 $E1 iprop($Q)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(|={ $E1 }[ $E2 ]β·=> $P)) => ``(iprop(|={$E1, $E2}=> β· (|={ $E2, $E1 }=> iprop($P))))\n | `(iprop($P ={ $E1 }[ $E2 ]β·=β $Q)) => ``(iprop(iprop($P) -β |={$E1}[$E2]β·=> iprop($Q)))\n | `(iprop(|={ $E1 }β·=> $P)) => ``(iprop(|={$E1}[$E1]β·=> iprop($P)))\n | `(iprop($P ={ $E1 }β·=β $Q)) => ``(iprop(iprop($P) ={$E1}[$E1]β·=β iprop($Q)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(|={ $E1 }[ $E2 ]β·^$n=> $P)) => ``(iprop(|={$E1, $E2}=> β·^[$n] (|={ $E2, $E1 }=> iprop($P))))\n | `(iprop($P ={ $E1 }[ $E2 ]β·^$n=β $Q)) => ``(iprop(iprop($P) -β |={$E1}[$E2]β·^$n=> iprop($Q)))\n | `(iprop(|={ $E1 }β·^$n=> $P)) => ``(iprop(|={$E1}[$E1]β·^$n=> iprop($P)))\n | `(iprop($P ={ $E1 }β·^$n=β $Q)) => ``(iprop(iprop($P) ={$E1}[$E1]β·^$n=β iprop($Q)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(emp)) => ``(BIBase.emp)\n | `(iprop(β$Οβ)) => ``(BIBase.pure $Ο)\n | `(iprop($P β§ $Q)) => ``(BIBase.and iprop($P) iprop($Q))\n | `(iprop($P β¨ $Q)) => ``(BIBase.or iprop($P) iprop($Q))\n | `(iprop($P β $Q)) => ``(BIBase.imp iprop($P) iprop($Q))\n | `(iprop(β $xs, $Ξ¨)) => do expandExplicitBinders ``BIBase.exists xs (β ``(iprop($Ξ¨)))\n | `(iprop($P β $Q)) => ``(BIBase.sep iprop($P) iprop($Q))\n | `(iprop($P -β $Q)) => ``(BIBase.wand iprop($P) iprop($Q))\n | `(iprop(<pers> $P)) => ``(BIBase.persistently iprop($P))\n | `(iprop(β· $P)) => ``(BIBase.later iprop($P))\n\ndelab_rule BIBase.emp\n | `($_) => ``(iprop($(mkIdent `emp)))\ndelab_rule BIBase.pure\n | `($_ $Ο) => ``(iprop(β$Οβ))\ndelab_rule BIBase.and\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β§ $(β unpackIprop Q)))\ndelab_rule BIBase.or\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β¨ $(β unpackIprop Q)))\ndelab_rule BIBase.imp\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule BIBase.forall\n | `($_ fun $x:ident => iprop(β $y:ident $[$z:ident]*, $Ξ¨)) => do\n ``(iprop(β $x:ident $y:ident $[$z:ident]*, $Ξ¨))\n | `($_ fun $x:ident => $Ξ¨) => do ``(iprop(β $x:ident, $(β unpackIprop Ξ¨)))\ndelab_rule BIBase.exists\n | `($_ fun $x:ident => iprop(β $y:ident $[$z:ident]*, $Ξ¨)) => do\n ``(iprop(β $x:ident $y:ident $[$z:ident]*, $Ξ¨))\n | `($_ fun $x:ident => $Ξ¨) => do ``(iprop(β $x:ident, $(β unpackIprop Ξ¨)))\ndelab_rule BIBase.sep\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule BIBase.wand\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) -β $(β unpackIprop Q)))\ndelab_rule BIBase.persistently\n | `($_ $P) => do ``(iprop(<pers> $(β unpackIprop P)))\n\ndelab_rule BIBase.pure\n | `($_ True) => ``(iprop($(mkIdent `True)))\n | `($_ False) => ``(iprop($(mkIdent `False)))\ndelab_rule BIBase.imp\n | `($_ $P iprop(False)) => do ``(iprop(Β¬$(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β _%$tk, $Ξ¨)) => ``(BIBase.forall (fun _%$tk => iprop($Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $x:ident, $Ξ¨)) => ``(BIBase.forall (fun $x => iprop($Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β (_%$tk : $t), $Ξ¨)) => ``(BIBase.forall (fun (_%$tk : $t) => iprop($Ξ¨)))\n | `(iprop(β (_%$tk $xs* : $t), $Ξ¨)) =>\n ``(BIBase.forall (fun (_%$tk : $t) => iprop(β ($xs* : $t), $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β ($x:ident : $t), $Ξ¨)) => ``(BIBase.forall (fun ($x : $t) => iprop($Ξ¨)))\n | `(iprop(β ($x:ident $xs* : $t), $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop(β ($xs* : $t), $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β {_%$tk : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun {_%$tk : $t} => iprop($Ξ¨)))\n | `(iprop(β {_%$tk $xs* : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun {_%$tk : $t} => iprop(β {$xs* : $t}, $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β {$x:ident : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop($Ξ¨)))\n | `(iprop(β {$x:ident $xs* : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop(β {$xs* : $t}, $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $x $y $xs*, $Ξ¨)) => ``(iprop(β $x, β $y $xs*, $Ξ¨))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(True)) => ``(BIBase.pure True)\n | `(iprop(False)) => ``(BIBase.pure False)\n | `(iprop(Β¬$P)) => ``(iprop($P β False))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop($P β $Q)) => ``(iff iprop($P) iprop($Q))\n | `(iprop($P β-β $Q)) => ``(wandIff iprop($P) iprop($Q))\n\ndelab_rule iff\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule wandIff\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β-β $(β unpackIprop Q)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(<affine> $P)) => ``(affinely iprop($P))\n | `(iprop(<absorb> $P)) => ``(absorbingly iprop($P))\n\ndelab_rule affinely\n | `($_ $P) => do ``(iprop(<affine> $(β unpackIprop P)))\ndelab_rule absorbingly\n | `($_ $P) => do ``(iprop(<absorb> $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β‘ $P)) => ``(intuitionistically iprop($P))\n\ndelab_rule intuitionistically\n | `($_ $P) => do ``(iprop(β‘ $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(<pers>?$p $P)) => ``(persistentlyIf $p iprop($P))\n | `(iprop(<affine>?$p $P)) => ``(affinelyIf $p iprop($P))\n | `(iprop(<absorb>?$p $P)) => ``(absorbinglyIf $p iprop($P))\n | `(iprop(β‘?$p $P)) => ``(intuitionisticallyIf $p iprop($P))\n\ndelab_rule persistentlyIf\n | `($_ $p $P) => do ``(iprop(<pers>?$p $(β unpackIprop P)))\ndelab_rule affinelyIf\n | `($_ $p $P) => do ``(iprop(<affine>?$p $(β unpackIprop P)))\ndelab_rule absorbinglyIf\n | `($_ $p $P) => do ``(iprop(<absorb>?$p $(β unpackIprop P)))\ndelab_rule intuitionisticallyIf\n | `($_ $p $P) => do ``(iprop(β‘?$p $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β·^[$n] $P)) => ``(laterN $n iprop($P))\n\ndelab_rule laterN\n | `($_ $n $P) => do ``(iprop(β·^[$n] $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $P)) => ``(except0 iprop($P))\n\ndelab_rule except0\n | `($_ $P) => do ``(iprop(β $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $P)) => ``(Plainly.plainly iprop($P))\n\ndelab_rule Plainly.plainly\n | `($_ $P) => do ``(iprop(β $(β Iris.BI.unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β ? $p $P)) => ``(Plainly.plainlyIf $p iprop($P))\n\ndelab_rule Plainly.plainlyIf\n | `($_ $p $P) => do ``(iprop(β ? $p $(β Iris.BI.unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(term($t))) => pure t\n | `(iprop($t)) => pure t"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(($P))) => ``((iprop($P)))\n | `(iprop(if $c then $t else $e)) => ``(if $c then iprop($t) else iprop($e))\n | `(iprop(($P : $t))) => ``((iprop($P) : $t))"
},
{
"name": "unpackIprop",
"content": "partial def unpackIprop [Monad m] [MonadRef m] [MonadQuotation m] : Term β m Term\n | `(iprop($P)) => do `($P)\n | `($P:ident) => do `($P)\n | `(?$P:ident) => do `(?$P)\n | `(($P)) => do `(($(β unpackIprop P)))\n | `($P $[ $Q]*) => do ``($P $[ $Q]*)\n | `(if $c then $t else $e) => do\n let t β unpackIprop t\n let e β unpackIprop e\n `(if $c then $t else $e)\n | `(($P : $t)) => do ``(($(β unpackIprop P) : $t))\n | `($t) => `($t:term)"
},
{
"name": "BIBase",
"content": "class BIBase (PROP : Type u) where\n Entails : PROP β PROP β Prop\n emp : PROP\n pure : Prop β PROP\n and : PROP β PROP β PROP\n or : PROP β PROP β PROP\n imp : PROP β PROP β PROP\n sForall : (PROP β Prop) β PROP\n sExists : (PROP β Prop) β PROP\n sep : PROP β PROP β PROP\n wand : PROP β PROP β PROP\n persistently : PROP β PROP\n later : PROP β PROP"
},
{
"name": "BI",
"content": "class BI (PROP : Type _) extends COFE PROP, BI.BIBase PROP where\n Equiv P Q := P β£β’ Q\n\n entails_preorder : Preorder Entails\n equiv_iff {P Q : PROP} : (P β‘ Q) β P β£β’ Q := by admit /- proof elided -/"
},
{
"name": "liftRel",
"content": "def liftRel (R : Ξ± β Ξ² β Prop) (A : Ξ± β Prop) (B : Ξ² β Prop) : Prop :=\n (β a, A a β β b, B b β§ R a b) β§ (β b, B b β β a, A a β§ R a b)"
},
{
"name": "Preorder",
"content": "class Preorder (R : Relation Ξ±) extends Reflexive R, Transitive R"
},
{
"name": "Reflexive",
"content": "class Reflexive (R : Relation Ξ±) where\n refl {x : Ξ±} : R x x"
},
{
"name": "Relation",
"content": "abbrev Relation (Ξ± : Type _) := Ξ± β Ξ± β Prop"
},
{
"name": "Transitive",
"content": "class Transitive (R : Relation Ξ±) where\n trans {x y z : Ξ±} : R x y β R y z β R x z"
},
{
"name": "NonExpansiveβ",
"content": "class NonExpansiveβ [OFE Ξ±] [OFE Ξ²] [OFE Ξ³] (f : Ξ± β Ξ² β Ξ³) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β β β¦yβ yββ¦, yβ β‘{n}β‘ yβ β f xβ yβ β‘{n}β‘ f xβ yβ"
},
{
"name": "OFE.ContractiveHom.fixpoint_ne",
"content": "instance OFE.ContractiveHom.fixpoint_ne [COFE Ξ±] [Inhabited Ξ±] :\n NonExpansive (ContractiveHom.fixpoint (Ξ± := Ξ±)) where\n ne n f1 f2 H := by admit /- proof elided -/"
},
{
"name": "ContractiveHom",
"content": "@[ext] structure ContractiveHom (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] extends Hom Ξ± Ξ² where\n [contractive : Contractive f]\n ne := ne_of_contractive f"
},
{
"name": "OFE.Option.some.ne",
"content": "instance OFE.Option.some.ne [OFE Ξ±] : OFE.NonExpansive (some : Ξ± β Option Ξ±) := β¨fun _ _ _ => idβ©"
},
{
"name": "Option.merge_ne",
"content": "instance Option.merge_ne [OFE Ξ±] {op : Ξ± β Ξ± β Ξ±} [NonExpansiveβ op] :\n NonExpansiveβ (Option.merge op) where\n ne n x1 x2 Hx y1 y2 Hy := by admit /- proof elided -/"
},
{
"name": "NonExpansive",
"content": "class NonExpansive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β f xβ β‘{n}β‘ f xβ"
},
{
"name": "COFE.OFunctor.constOF_RFunctor",
"content": "instance COFE.OFunctor.constOF_RFunctor [CMRA B] : RFunctor (constOF B) where\n map f g := by admit /- proof elided -/"
},
{
"name": "IsCOFE",
"content": "class IsCOFE (Ξ± : Type _) [OFE Ξ±] where\n compl : Chain Ξ± β Ξ±\n conv_compl {c : Chain Ξ±} : compl c β‘{n}β‘ c n"
},
{
"name": "Chain",
"content": "structure Chain (Ξ± : Type _) [OFE Ξ±] where\n chain : Nat β Ξ±\n cauchy : n β€ i β chain i β‘{n}β‘ chain n"
},
{
"name": "Idempotent",
"content": "class Idempotent (R : Relation Ξ±) (f : Ξ± β Ξ± β Ξ±) where\n idem {x : Ξ±} : R (f x x) x"
},
{
"name": "LawfulBigOp",
"content": "class LawfulBigOp (f : PROP β PROP β PROP) (unit : outParam PROP)\n (eq : outParam (PROP β PROP β Prop)) where\n refl : eq a a\n symm : eq a b β eq b a\n trans : eq a b β eq b c β eq a c\n comm : eq (f a b) (f b a)\n assoc : eq (f (f a b) c) (f a (f b c))\n left_id : eq (f unit a) a\n congr_l : eq a a' β eq (f a b) (f a' b)"
},
{
"name": "",
"content": "instance : BIPlainly (UPred M) where\n mono H _ _ _ := H _ _ CMRA.unit_validN\n elim_persistently {P} n x Hx := by admit /- proof elided -/"
},
{
"name": "persistently",
"content": "protected def persistently (P : UPred M) : UPred M where\n holds n x := P n (CMRA.core x)\n mono H Hx Hn := P.mono H (CMRA.core_incN_core Hx) Hn"
},
{
"name": "BIUpdate",
"content": "class BIUpdate (PROP : Type _) [BI PROP] extends BUpd PROP where\n [bupd_ne : OFE.NonExpansive (BUpd.bupd (PROP := PROP))]\n intro {P : PROP} : iprop(P β’ |==> P)\n mono {P Q : PROP} : iprop(P β’ Q) β iprop(|==> P β’ |==> Q)\n trans {P : PROP} : iprop(|==> |==> P β’ |==> P)\n frame_r {P R : PROP} : iprop((|==> P) β R β’ |==> (P β R))"
},
{
"name": "UPred",
"content": "@[ext]\nstructure UPred (M : Type _) [UCMRA M] where\n holds : Nat β M β Prop\n mono {n1 n2 x1 x2} : holds n1 x1 β x1 βΌ{n2} x2 β n2 β€ n1 β holds n2 x2"
},
{
"name": "IsModal",
"content": "class IsModal [BI PROP1] [BI PROP2] (M : PROP1 β PROP2)\n (iaction saction : ModalityAction PROP1 PROP2) where\n spec_intuitionistic : iaction.intuitionistic_action_spec M\n spec_spatial : saction.spatial_action_spec M\n emp : iprop(emp) β’ M iprop(emp)\n mono : β {P Q}, (P β’ Q) β M P β’ M Q\n sep : β {P Q}, iprop(M P β M Q) β’ M iprop(P β Q)"
},
{
"name": "core",
"content": "def core (x : Ξ±) := (pcore x).getD x"
},
{
"name": "CMRA",
"content": "class CMRA (Ξ± : Type _) extends OFE Ξ± where\n pcore : Ξ± β Option Ξ±\n op : Ξ± β Ξ± β Ξ±\n ValidN : Nat β Ξ± β Prop\n Valid : Ξ± β Prop\n\n op_ne : NonExpansive (op x)\n pcore_ne : x β‘{n}β‘ y β pcore x = some cx β\n β cy, pcore y = some cy β§ cx β‘{n}β‘ cy\n validN_ne : x β‘{n}β‘ y β ValidN n x β ValidN n y\n\n valid_iff_validN : Valid x β β n, ValidN n x\n validN_succ : ValidN n.succ x β ValidN n x\n validN_op_left : ValidN n (op x y) β ValidN n x\n\n assoc : op x (op y z) β‘ op (op x y) z\n comm : op x y β‘ op y x\n\n pcore_op_left : pcore x = some cx β op cx x β‘ x\n pcore_idem : pcore x = some cx β pcore cx β‘ some cx\n pcore_op_mono : pcore x = some cx β β y, β cy, pcore (op x y) β‘ some (op cx cy)\n\n extend : ValidN n x β x β‘{n}β‘ op yβ yβ β\n Ξ£' zβ zβ, x β‘ op zβ zβ β§ zβ β‘{n}β‘ yβ β§ zβ β‘{n}β‘ yβ"
},
{
"name": "UCMRA",
"content": "class UCMRA (Ξ± : Type _) extends CMRA Ξ± where\n unit : Ξ±\n unit_valid : β unit\n unit_left_id : unit β’ x β‘ x\n pcore_unit : pcore unit β‘ some unit"
},
{
"name": "pcore",
"content": "def pcore : DFrac F β Option (DFrac F)\n | own _ => none\n | .discard => some discard\n | ownDiscard _ => some discard"
},
{
"name": "DFrac",
"content": "inductive DFrac (F : Type _) where\n \n| own (f : F) : DFrac F\n \n| discard : DFrac F\n \n| ownDiscard (f : F) : DFrac F"
},
{
"name": "op",
"content": "def op : DFrac F β DFrac F β DFrac F\n | .discard, .discard => discard\n | own f, .discard\n | ownDiscard f, .discard\n | .discard, own f\n | .discard, ownDiscard f => ownDiscard f\n | own f, own f' => own (f + f')\n | own f, ownDiscard f'\n | ownDiscard f, own f'\n | ownDiscard f, ownDiscard f' => ownDiscard (f + f')"
},
{
"name": "Associative",
"content": "class Associative (R : Relation Ξ±) (f : Ξ± β Ξ± β Ξ±) where\n assoc {x y z : Ξ±} : R (f (f x y) z) (f x (f y z))"
},
{
"name": "Commutative",
"content": "class Commutative (R : Relation Ξ±) (f : Ξ² β Ξ² β Ξ±) where\n comm {x y : Ξ²} : R (f x y) (f y x)"
},
{
"name": "Included",
"content": "def Included (x y : Ξ±) : Prop := β z, y β‘ x β’ z"
},
{
"name": "plainly",
"content": "protected def plainly (P : UPred M) : UPred M where\n holds n _ := P n UCMRA.unit\n mono H _ Hn := P.mono H (CMRA.incN_refl UCMRA.unit) Hn"
},
{
"name": "BIPlainly",
"content": "class BIPlainly (PROP : Type _) [Iris.BI PROP] extends Plainly PROP where\n [ne : Iris.OFE.NonExpansive (Plainly.plainly (PROP := PROP))]\n mono {P Q : PROP} : (P β’ Q) β β P β’ β Q\n elim_persistently {P : PROP} : β P β’ <pers> P\n idem {P : PROP} : β P β’ β β P\n plainly_sForall_2 {Ξ¦ : PROP β Prop} : (β p, βΞ¦ pβ β β p) β’ β sForall Ξ¦\n plainly_impl_plainly {P Q : PROP} : (β P β β Q) β’ β (β P β Q)\n emp_intro {P : PROP} : P β’ β emp\n plainly_absorb {P Q : PROP} : β P β Q β’ β P\n later_plainly {P : PROP} : β· β P β£β’ β β· P"
},
{
"name": "",
"content": "instance : BIPlainlyExists (UPred M) where\n plainly_sExists_1 _ _ _ := fun β¨_, hpβ© => β¨_, β¨_, rflβ©, hpβ©"
},
{
"name": "BIPlainlyExists",
"content": "class BIPlainlyExists (PROP : Type _) [Iris.BI PROP] [BIPlainly PROP] where\n plainly_sExists_1 {Ξ¦ : PROP β Prop} : β sExists Ξ¦ β’ β p, βΞ¦ pβ β§ β p"
},
{
"name": "",
"content": "instance : Plainly (UPred M) := β¨UPred.plainlyβ©"
},
{
"name": "scoped infix:40 \" β‘ \" => OFE.Equiv",
"content": "scoped infix:40 \" β‘ \" => OFE.Equiv"
},
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y"
},
{
"name": "infixr:25 \" -c> \" => ContractiveHom",
"content": "infixr:25 \" -c> \" => ContractiveHom"
},
{
"name": "infix:60 \" β’ \" => op",
"content": "infix:60 \" β’ \" => op"
},
{
"name": "infix:50 \" βΌ \" => Included",
"content": "infix:50 \" βΌ \" => Included"
}
] | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "persistently_and_sep_assoc",
"content": "theorem persistently_and_sep_assoc [BI PROP] {P Q R : PROP} :\n <pers> P β§ (Q β R) β£β’ (<pers> P β§ Q) β R"
},
{
"name": "and_mono_l",
"content": "theorem and_mono_l [BI PROP] {P P' Q : PROP} (h : P β’ P') : P β§ Q β’ P' β§ Q"
},
{
"name": "and_mono",
"content": "@[rw_mono_rule]\ntheorem and_mono [BI PROP] {P P' Q Q' : PROP} (h1 : P β’ Q) (h2 : P' β’ Q') : P β§ P' β’ Q β§ Q'"
},
{
"name": "and_elim_r'",
"content": "theorem and_elim_r' [BI PROP] {P Q R : PROP} (h : Q β’ R) : P β§ Q β’ R"
},
{
"name": "and_elim_l'",
"content": "theorem and_elim_l' [BI PROP] {P Q R : PROP} (h : P β’ R) : P β§ Q β’ R"
},
{
"name": "sep_assoc",
"content": "theorem sep_assoc [BI PROP] {P Q R : PROP} : (P β Q) β R β£β’ P β Q β R"
},
{
"name": "sep_congr_l",
"content": "theorem sep_congr_l [BI PROP] {P P' Q : PROP} (h : P β£β’ P') : P β Q β£β’ P' β Q"
},
{
"name": "sep_congr",
"content": "@[rw_mono_rule]\ntheorem sep_congr [BI PROP] {P P' Q Q' : PROP} (h1 : P β£β’ Q) (h2 : P' β£β’ Q') :\n (P β P') β£β’ (Q β Q')"
},
{
"name": "sep_congr_r",
"content": "theorem sep_congr_r [BI PROP] {P Q Q' : PROP} (h : Q β£β’ Q') : P β Q β£β’ P β Q'"
},
{
"name": "sep_mono_l",
"content": "theorem sep_mono_l [BI PROP] {P P' Q : PROP} (h : P β’ P') : P β Q β’ P' β Q"
},
{
"name": "BIBase.Entails.rfl",
"content": "@[simp] theorem BIBase.Entails.rfl [BI PROP] {P : PROP} : P β’ P"
},
{
"name": "imp_intro'",
"content": "theorem imp_intro' [BI PROP] {P Q R : PROP} (h : Q β§ P β’ R) : P β’ Q β R"
},
{
"name": "and_comm",
"content": "theorem and_comm [BI PROP] {P Q : PROP} : P β§ Q β£β’ Q β§ P"
},
{
"name": "and_symm",
"content": "theorem and_symm [BI PROP] {P Q : PROP} : P β§ Q β’ Q β§ P"
},
{
"name": "imp_elim'",
"content": "theorem imp_elim' [BI PROP] {P Q R : PROP} (h : Q β’ P β R) : P β§ Q β’ R"
},
{
"name": "pure_elim",
"content": "theorem pure_elim [BI PROP] (Ο : Prop) {Q R : PROP} (h1 : Q β’ βΟβ) (h2 : Ο β Q β’ R) : Q β’ R"
},
{
"name": "and_self",
"content": "theorem and_self [BI PROP] {P : PROP} : P β§ P β£β’ P"
},
{
"name": "forall_intro",
"content": "theorem forall_intro [BI PROP] {P : PROP} {Ξ¨ : Ξ± β PROP} (h : β a, P β’ Ξ¨ a) : P β’ β a, Ξ¨ a"
},
{
"name": "forall_elim",
"content": "theorem forall_elim [BI PROP] {Ξ¨ : Ξ± β PROP} (a : Ξ±) : (β a, Ξ¨ a) β’ Ξ¨ a"
},
{
"name": "forall_mono",
"content": "@[rw_mono_rule]\ntheorem forall_mono [BI PROP] {Ξ¦ Ξ¨ : Ξ± β PROP} (h : β a, Ξ¦ a β’ Ξ¨ a) : (β a, Ξ¦ a) β’ β a, Ξ¨ a"
},
{
"name": "and_forall_bool",
"content": "theorem and_forall_bool [BI PROP] {P Q : PROP} :\n P β§ Q β£β’ Β«forallΒ» (fun b : Bool => if b then P else Q)"
},
{
"name": "persistently_and_emp_elim",
"content": "theorem persistently_and_emp_elim {P : PROP} [BI PROP] : emp β§ <pers> P β’ P"
},
{
"name": "sep_emp",
"content": "theorem sep_emp [BI PROP] {P : PROP} : P β emp β£β’ P"
}
] | [
{
"name": "Iris.Plainly",
"content": "class Plainly (PROP : Type _) where\n plainly : PROP β PROP"
},
{
"name": "Iris.Plainly.plainlyIf",
"content": "def Plainly.plainlyIf [Iris.BI.BIBase PROP] [Plainly PROP] (p : Bool) (P : PROP) : PROP :=\n iprop(if p then β P else P)"
},
{
"name": "Iris.BIPlainly",
"content": "class BIPlainly (PROP : Type _) [Iris.BI PROP] extends Plainly PROP where\n [ne : Iris.OFE.NonExpansive (Plainly.plainly (PROP := PROP))]\n mono {P Q : PROP} : (P β’ Q) β β P β’ β Q\n elim_persistently {P : PROP} : β P β’ <pers> P\n idem {P : PROP} : β P β’ β β P\n plainly_sForall_2 {Ξ¦ : PROP β Prop} : (β p, βΞ¦ pβ β β p) β’ β sForall Ξ¦\n plainly_impl_plainly {P Q : PROP} : (β P β β Q) β’ β (β P β Q)\n emp_intro {P : PROP} : P β’ β emp\n plainly_absorb {P Q : PROP} : β P β Q β’ β P\n later_plainly {P : PROP} : β· β P β£β’ β β· P"
},
{
"name": "Iris.BIPlainlyExists",
"content": "class BIPlainlyExists (PROP : Type _) [Iris.BI PROP] [BIPlainly PROP] where\n plainly_sExists_1 {Ξ¦ : PROP β Prop} : β sExists Ξ¦ β’ β p, βΞ¦ pβ β§ β p"
}
] | [
{
"name": "Iris.BI.persistently_elim_plainly",
"content": "theorem persistently_elim_plainly : <pers> β P β£β’ β P"
},
{
"name": "Iris.BI.plainly_forall_2",
"content": "theorem plainly_forall_2 {Ξ¨ : Ξ± β PROP} : (β a, β (Ξ¨ a)) β’ β (β a, Ξ¨ a)"
},
{
"name": "Iris.BI.plainly_and_sep_assoc",
"content": "theorem plainly_and_sep_assoc : β P β§ (Q β R) β£β’ (β P β§ Q) β R"
},
{
"name": "Iris.BI.plainly_and_emp_elim",
"content": "theorem plainly_and_emp_elim : emp β§ β P β’ P"
},
{
"name": "Iris.BI.plainly_forall",
"content": "theorem plainly_forall {Ξ¨ : Ξ± β PROP} : β (β a, Ξ¨ a) β£β’ β a, β (Ξ¨ a)"
},
{
"name": "Iris.BI.plainly_and",
"content": "theorem plainly_and : β (P β§ Q) β£β’ β P β§ β Q"
}
] | import Iris.BI.Classes
import Iris.BI.BI
import Iris.BI.DerivedLaws
import Iris.Algebra
namespace Iris
open BI
class Plainly (PROP : Type _) where
plainly : PROP β PROP
def Plainly.plainlyIf [Iris.BI.BIBase PROP] [Plainly PROP] (p : Bool) (P : PROP) : PROP :=
iprop(if p then β P else P)
class BIPlainly (PROP : Type _) [Iris.BI PROP] extends Plainly PROP where
[ne : Iris.OFE.NonExpansive (Plainly.plainly (PROP := PROP))]
mono {P Q : PROP} : (P β’ Q) β β P β’ β Q
elim_persistently {P : PROP} : β P β’ <pers> P
idem {P : PROP} : β P β’ β β P
plainly_sForall_2 {Ξ¦ : PROP β Prop} : (β p, βΞ¦ pβ β β p) β’ β sForall Ξ¦
plainly_impl_plainly {P Q : PROP} : (β P β β Q) β’ β (β P β Q)
emp_intro {P : PROP} : P β’ β emp
plainly_absorb {P Q : PROP} : β P β Q β’ β P
later_plainly {P : PROP} : β· β P β£β’ β β· P
class BIPlainlyExists (PROP : Type _) [Iris.BI PROP] [BIPlainly PROP] where
plainly_sExists_1 {Ξ¦ : PROP β Prop} : β sExists Ξ¦ β’ β p, βΞ¦ pβ β§ β p
namespace BI
open Iris.Std
section PlainlyLaws
open BIPlainly
variable [BI PROP] [BIPlainly PROP]
variable {P Q R : PROP} | theorem plainly_and_sep : β (P β§ Q) β’ β (P β Q) := | := by
refine (plainly_and.mp.trans <| (and_mono idem .rfl).trans plainly_and.mpr).trans ?_
refine (mono <| and_mono .rfl emp_sep.mpr).trans ?_
refine (mono <| plainly_and_sep_assoc.1).trans ?_
refine (mono <| sep_mono and_comm.mp .rfl).trans ?_
exact (mono <| sep_mono plainly_and_emp_elim .rfl).trans .rfl | 6 | 55 | false | Framework |
235 | Iris.BI.later_exists_false | theorem later_exists_false [BI PROP] {Ξ¦ : Ξ± β PROP} :
(β· β a, Ξ¦ a) β’ β· False β¨ β a, β· Ξ¦ a | iris-lean | src/Iris/BI/DerivedLaws.lean | [
"import Iris.BI.Extensions",
"import Iris.Std.TC",
"import Iris.Std.Classes",
"import Iris.BI.BI",
"import src.Iris.Algebra.OFE",
"import src.Iris.BI.BI",
"import Iris.BI.Classes",
"import Iris.Std.Rewrite"
] | [
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "Option.merge",
"module": "Init.Data.Option.Basic"
},
{
"name": "id",
"module": "Init.Prelude"
},
{
"name": "Equivalence",
"module": "Init.Core"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "m",
"module": "QqTest.matching"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Bool",
"module": "Init.Prelude"
}
] | [
{
"name": "macro \"β\" xs:explicitBinders \", \" b:term : term => do",
"content": "macro \"β\" xs:explicitBinders \", \" b:term : term => do\n return β¨β expandExplicitBinders ``BIBase.exists xs bβ©"
},
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y\n\nsyntax:max \"<pers> \" term:40 : term"
},
{
"name": "macro:25 P:term:29 \" β’ \" Q:term:25 : term => ``(BIBase.Entai",
"content": "macro:25 P:term:29 \" β’ \" Q:term:25 : term => ``(BIBase.Entails iprop($P) iprop($Q))\n\ndelab_rule BIBase.Entails\n | `($_ $P $Q) => do ``($(β unpackIprop P) β’ $(β unpackIprop Q))"
},
{
"name": "macro:25 P:term:29 \" β£β’ \" Q:term:29 : term => ``(BiEntails i",
"content": "macro:25 P:term:29 \" β£β’ \" Q:term:29 : term => ``(BiEntails iprop($P) iprop($Q))\n\ndelab_rule BIBase.Entails\n | `($_ iprop(emp) $P) => do ``(β’ $(β unpackIprop P))\n\ndelab_rule BIBase.BiEntails\n | `($_ $P $Q) => do ``($(β unpackIprop P) β£β’ $(β unpackIprop Q))\n\nsyntax \"β\" term \"β\" : term\n\nsyntax:max \"β· \" term:40 : term"
},
{
"name": "macro:max \"iprop(\" P:term \" : \" t:term \")\" : term => `((ipro",
"content": "macro:max \"iprop(\" P:term \" : \" t:term \")\" : term => `((iprop($P) : $t))\n\nsyntax:max \"iprop(\" term \")\" : term\n\nsyntax:max \"<affine> \" term:40 : term\n\nsyntax:max \"β‘ \" term:40 : term\n\nsyntax:max \"<absorb> \" term:40 : term"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(term($t))) => pure t\n | `(iprop($t)) => pure t"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(($P))) => ``((iprop($P)))\n | `(iprop(if $c then $t else $e)) => ``(if $c then iprop($t) else iprop($e))\n | `(iprop(($P : $t))) => ``((iprop($P) : $t))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(emp)) => ``(BIBase.emp)\n | `(iprop(β$Οβ)) => ``(BIBase.pure $Ο)\n | `(iprop($P β§ $Q)) => ``(BIBase.and iprop($P) iprop($Q))\n | `(iprop($P β¨ $Q)) => ``(BIBase.or iprop($P) iprop($Q))\n | `(iprop($P β $Q)) => ``(BIBase.imp iprop($P) iprop($Q))\n | `(iprop(β $xs, $Ξ¨)) => do expandExplicitBinders ``BIBase.exists xs (β ``(iprop($Ξ¨)))\n | `(iprop($P β $Q)) => ``(BIBase.sep iprop($P) iprop($Q))\n | `(iprop($P -β $Q)) => ``(BIBase.wand iprop($P) iprop($Q))\n | `(iprop(<pers> $P)) => ``(BIBase.persistently iprop($P))\n | `(iprop(β· $P)) => ``(BIBase.later iprop($P))\n\ndelab_rule BIBase.emp\n | `($_) => ``(iprop($(mkIdent `emp)))\ndelab_rule BIBase.pure\n | `($_ $Ο) => ``(iprop(β$Οβ))\ndelab_rule BIBase.and\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β§ $(β unpackIprop Q)))\ndelab_rule BIBase.or\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β¨ $(β unpackIprop Q)))\ndelab_rule BIBase.imp\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule BIBase.forall\n | `($_ fun $x:ident => iprop(β $y:ident $[$z:ident]*, $Ξ¨)) => do\n ``(iprop(β $x:ident $y:ident $[$z:ident]*, $Ξ¨))\n | `($_ fun $x:ident => $Ξ¨) => do ``(iprop(β $x:ident, $(β unpackIprop Ξ¨)))\ndelab_rule BIBase.exists\n | `($_ fun $x:ident => iprop(β $y:ident $[$z:ident]*, $Ξ¨)) => do\n ``(iprop(β $x:ident $y:ident $[$z:ident]*, $Ξ¨))\n | `($_ fun $x:ident => $Ξ¨) => do ``(iprop(β $x:ident, $(β unpackIprop Ξ¨)))\ndelab_rule BIBase.sep\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule BIBase.wand\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) -β $(β unpackIprop Q)))\ndelab_rule BIBase.persistently\n | `($_ $P) => do ``(iprop(<pers> $(β unpackIprop P)))\n\ndelab_rule BIBase.pure\n | `($_ True) => ``(iprop($(mkIdent `True)))\n | `($_ False) => ``(iprop($(mkIdent `False)))\ndelab_rule BIBase.imp\n | `($_ $P iprop(False)) => do ``(iprop(Β¬$(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β _%$tk, $Ξ¨)) => ``(BIBase.forall (fun _%$tk => iprop($Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $x:ident, $Ξ¨)) => ``(BIBase.forall (fun $x => iprop($Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β (_%$tk : $t), $Ξ¨)) => ``(BIBase.forall (fun (_%$tk : $t) => iprop($Ξ¨)))\n | `(iprop(β (_%$tk $xs* : $t), $Ξ¨)) =>\n ``(BIBase.forall (fun (_%$tk : $t) => iprop(β ($xs* : $t), $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β ($x:ident : $t), $Ξ¨)) => ``(BIBase.forall (fun ($x : $t) => iprop($Ξ¨)))\n | `(iprop(β ($x:ident $xs* : $t), $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop(β ($xs* : $t), $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β {_%$tk : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun {_%$tk : $t} => iprop($Ξ¨)))\n | `(iprop(β {_%$tk $xs* : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun {_%$tk : $t} => iprop(β {$xs* : $t}, $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β {$x:ident : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop($Ξ¨)))\n | `(iprop(β {$x:ident $xs* : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop(β {$xs* : $t}, $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $x $y $xs*, $Ξ¨)) => ``(iprop(β $x, β $y $xs*, $Ξ¨))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(True)) => ``(BIBase.pure True)\n | `(iprop(False)) => ``(BIBase.pure False)\n | `(iprop(Β¬$P)) => ``(iprop($P β False))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop($P β $Q)) => ``(iff iprop($P) iprop($Q))\n | `(iprop($P β-β $Q)) => ``(wandIff iprop($P) iprop($Q))\n\ndelab_rule iff\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule wandIff\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β-β $(β unpackIprop Q)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(<affine> $P)) => ``(affinely iprop($P))\n | `(iprop(<absorb> $P)) => ``(absorbingly iprop($P))\n\ndelab_rule affinely\n | `($_ $P) => do ``(iprop(<affine> $(β unpackIprop P)))\ndelab_rule absorbingly\n | `($_ $P) => do ``(iprop(<absorb> $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β‘ $P)) => ``(intuitionistically iprop($P))\n\ndelab_rule intuitionistically\n | `($_ $P) => do ``(iprop(β‘ $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(<pers>?$p $P)) => ``(persistentlyIf $p iprop($P))\n | `(iprop(<affine>?$p $P)) => ``(affinelyIf $p iprop($P))\n | `(iprop(<absorb>?$p $P)) => ``(absorbinglyIf $p iprop($P))\n | `(iprop(β‘?$p $P)) => ``(intuitionisticallyIf $p iprop($P))\n\ndelab_rule persistentlyIf\n | `($_ $p $P) => do ``(iprop(<pers>?$p $(β unpackIprop P)))\ndelab_rule affinelyIf\n | `($_ $p $P) => do ``(iprop(<affine>?$p $(β unpackIprop P)))\ndelab_rule absorbinglyIf\n | `($_ $p $P) => do ``(iprop(<absorb>?$p $(β unpackIprop P)))\ndelab_rule intuitionisticallyIf\n | `($_ $p $P) => do ``(iprop(β‘?$p $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β·^[$n] $P)) => ``(laterN $n iprop($P))\n\ndelab_rule laterN\n | `($_ $n $P) => do ``(iprop(β·^[$n] $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $P)) => ``(except0 iprop($P))\n\ndelab_rule except0\n | `($_ $P) => do ``(iprop(β $(β unpackIprop P)))"
},
{
"name": "BIBase",
"content": "class BIBase (PROP : Type u) where\n Entails : PROP β PROP β Prop\n emp : PROP\n pure : Prop β PROP\n and : PROP β PROP β PROP\n or : PROP β PROP β PROP\n imp : PROP β PROP β PROP\n sForall : (PROP β Prop) β PROP\n sExists : (PROP β Prop) β PROP\n sep : PROP β PROP β PROP\n wand : PROP β PROP β PROP\n persistently : PROP β PROP\n later : PROP β PROP"
},
{
"name": "BI",
"content": "class BI (PROP : Type _) extends COFE PROP, BI.BIBase PROP where\n Equiv P Q := P β£β’ Q\n\n entails_preorder : Preorder Entails\n equiv_iff {P Q : PROP} : (P β‘ Q) β P β£β’ Q := by admit /- proof elided -/"
},
{
"name": "liftRel",
"content": "def liftRel (R : Ξ± β Ξ² β Prop) (A : Ξ± β Prop) (B : Ξ² β Prop) : Prop :=\n (β a, A a β β b, B b β§ R a b) β§ (β b, B b β β a, A a β§ R a b)"
},
{
"name": "Preorder",
"content": "class Preorder (R : Relation Ξ±) extends Reflexive R, Transitive R"
},
{
"name": "Reflexive",
"content": "class Reflexive (R : Relation Ξ±) where\n refl {x : Ξ±} : R x x"
},
{
"name": "Relation",
"content": "abbrev Relation (Ξ± : Type _) := Ξ± β Ξ± β Prop"
},
{
"name": "Transitive",
"content": "class Transitive (R : Relation Ξ±) where\n trans {x y z : Ξ±} : R x y β R y z β R x z"
},
{
"name": "NonExpansiveβ",
"content": "class NonExpansiveβ [OFE Ξ±] [OFE Ξ²] [OFE Ξ³] (f : Ξ± β Ξ² β Ξ³) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β β β¦yβ yββ¦, yβ β‘{n}β‘ yβ β f xβ yβ β‘{n}β‘ f xβ yβ"
},
{
"name": "OFE.ContractiveHom.fixpoint_ne",
"content": "instance OFE.ContractiveHom.fixpoint_ne [COFE Ξ±] [Inhabited Ξ±] :\n NonExpansive (ContractiveHom.fixpoint (Ξ± := Ξ±)) where\n ne n f1 f2 H := by admit /- proof elided -/"
},
{
"name": "ContractiveHom",
"content": "@[ext] structure ContractiveHom (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] extends Hom Ξ± Ξ² where\n [contractive : Contractive f]\n ne := ne_of_contractive f"
},
{
"name": "OFE.Option.some.ne",
"content": "instance OFE.Option.some.ne [OFE Ξ±] : OFE.NonExpansive (some : Ξ± β Option Ξ±) := β¨fun _ _ _ => idβ©"
},
{
"name": "Option.merge_ne",
"content": "instance Option.merge_ne [OFE Ξ±] {op : Ξ± β Ξ± β Ξ±} [NonExpansiveβ op] :\n NonExpansiveβ (Option.merge op) where\n ne n x1 x2 Hx y1 y2 Hy := by admit /- proof elided -/"
},
{
"name": "NonExpansive",
"content": "class NonExpansive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β f xβ β‘{n}β‘ f xβ"
},
{
"name": "COFE.OFunctor.constOF_RFunctor",
"content": "instance COFE.OFunctor.constOF_RFunctor [CMRA B] : RFunctor (constOF B) where\n map f g := by admit /- proof elided -/"
},
{
"name": "IsCOFE",
"content": "class IsCOFE (Ξ± : Type _) [OFE Ξ±] where\n compl : Chain Ξ± β Ξ±\n conv_compl {c : Chain Ξ±} : compl c β‘{n}β‘ c n"
},
{
"name": "Chain",
"content": "structure Chain (Ξ± : Type _) [OFE Ξ±] where\n chain : Nat β Ξ±\n cauchy : n β€ i β chain i β‘{n}β‘ chain n"
},
{
"name": "LawfulBigOp",
"content": "class LawfulBigOp (f : PROP β PROP β PROP) (unit : outParam PROP)\n (eq : outParam (PROP β PROP β Prop)) where\n refl : eq a a\n symm : eq a b β eq b a\n trans : eq a b β eq b c β eq a c\n comm : eq (f a b) (f b a)\n assoc : eq (f (f a b) c) (f a (f b c))\n left_id : eq (f unit a) a\n congr_l : eq a a' β eq (f a b) (f a' b)"
},
{
"name": "intuitionistically",
"content": "def intuitionistically [BIBase PROP] (P : PROP) : PROP := iprop(<affine> <pers> P)"
},
{
"name": "Affine",
"content": "class Affine [BI PROP] (P : PROP) where\n affine : P β’ emp"
},
{
"name": "bigAnd",
"content": "def bigAnd [BIBase PROP] (Ps : List PROP) : PROP := bigOp and iprop(True) Ps"
},
{
"name": "bigOp",
"content": "def bigOp (f : PROP β PROP β PROP) (unit : PROP) : List PROP β PROP\n | [] => unit\n | [P] => P\n | P :: Ps => f P (bigOp f unit Ps)"
},
{
"name": "absorbingly",
"content": "def absorbingly [BIBase PROP] (P : PROP) : PROP := iprop(True β P)"
},
{
"name": "BiEntails",
"content": "structure BiEntails [BIBase PROP] (P Q : PROP) where\n mp : P β’ Q\n mpr : Q β’ P"
},
{
"name": "persistentlyIf",
"content": "def persistentlyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then <pers> P else P)"
},
{
"name": "intuitionisticallyIf",
"content": "def intuitionisticallyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then β‘ P else P)"
},
{
"name": "bigSep",
"content": "def bigSep [BIBase PROP] (Ps : List PROP) : PROP := bigOp sep iprop(emp) Ps"
},
{
"name": "affinely",
"content": "def affinely [BIBase PROP] (P : PROP) : PROP := iprop(emp β§ P)"
},
{
"name": "bigOr",
"content": "def bigOr [BIBase PROP] (Ps : List PROP) : PROP := bigOp or iprop(False) Ps"
},
{
"name": "absorbinglyIf",
"content": "def absorbinglyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then <absorb> P else P)"
},
{
"name": "affinelyIf",
"content": "def affinelyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then <affine> P else P)"
},
{
"name": "wandIff",
"content": "def wandIff [BIBase PROP] (P Q : PROP) : PROP := iprop((P -β Q) β§ (Q -β P))"
},
{
"name": "scoped infix:40 \" β‘ \" => OFE.Equiv",
"content": "scoped infix:40 \" β‘ \" => OFE.Equiv"
},
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y"
},
{
"name": "infixr:25 \" -c> \" => ContractiveHom",
"content": "infixr:25 \" -c> \" => ContractiveHom"
},
{
"name": "notation:40 \"[β§] \" Ps:max => bigAnd Ps",
"content": "notation:40 \"[β§] \" Ps:max => bigAnd Ps"
},
{
"name": "notation:40 \"[β¨] \" Ps:max => bigOr Ps",
"content": "notation:40 \"[β¨] \" Ps:max => bigOr Ps"
},
{
"name": "notation:40 \"[β] \" Ps:max => bigSep Ps",
"content": "notation:40 \"[β] \" Ps:max => bigSep Ps"
}
] | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "Dist.trans",
"content": "theorem Dist.trans [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ y β y β‘{n}β‘ z β x β‘{n}β‘ z"
},
{
"name": "BIBase.BiEntails.trans",
"content": "theorem BIBase.BiEntails.trans [BI PROP] {P Q R : PROP} (h1 : P β£β’ Q) (h2 : Q β£β’ R) : P β£β’ R"
},
{
"name": "BIBase.Entails.trans",
"content": "theorem BIBase.Entails.trans [BI PROP] {P Q R : PROP} (h1 : P β’ Q) (h2 : Q β’ R) : P β’ R"
},
{
"name": "Equiv.trans",
"content": "theorem Equiv.trans [OFE Ξ±] {x : Ξ±} : x β‘ y β y β‘ z β x β‘ z"
},
{
"name": "equiv_eqv",
"content": "theorem equiv_eqv [ofe : OFE Ξ±] : Equivalence ofe.Equiv"
},
{
"name": "Dist.symm",
"content": "@[symm] theorem Dist.symm [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ y β y β‘{n}β‘ x"
},
{
"name": "Dist.rfl",
"content": "@[simp, refl] theorem Dist.rfl [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ x"
},
{
"name": "DistLater.trans",
"content": "theorem DistLater.trans [OFE Ξ±] {n} {x : Ξ±} (h1 : DistLater n x y) (h2 : DistLater n y z) :\n DistLater n x z"
}
] | [] | [
{
"name": "Iris.BI.or_intro_r'",
"content": "theorem or_intro_r' [BI PROP] {P Q R : PROP} (h : P β’ R) : P β’ Q β¨ R"
},
{
"name": "Iris.BI.imp_intro'",
"content": "theorem imp_intro' [BI PROP] {P Q R : PROP} (h : Q β§ P β’ R) : P β’ Q β R"
},
{
"name": "Iris.BI.exists_intro",
"content": "theorem exists_intro [BI PROP] {Ξ¨ : Ξ± β PROP} (a : Ξ±) : Ξ¨ a β’ β a, Ξ¨ a"
},
{
"name": "Iris.BI.exists_elim",
"content": "theorem exists_elim [BI PROP] {Ξ¦ : Ξ± β PROP} {Q : PROP} (h : β a, Ξ¦ a β’ Q) : (β a, Ξ¦ a) β’ Q"
},
{
"name": "Iris.BI.exists_intro'",
"content": "theorem exists_intro' [BI PROP] {P : PROP} {Ξ¨ : Ξ± β PROP} (a : Ξ±) (h : P β’ Ξ¨ a) : P β’ β a, Ξ¨ a"
}
] | import Iris.BI.Classes
import Iris.BI.Extensions
import Iris.BI.BI
import Iris.Std.Classes
import Iris.Std.Rewrite
import Iris.Std.TC
namespace Iris.BI
open Iris.Std BI | theorem later_exists_false [BI PROP] {Ξ¦ : Ξ± β PROP} :
(β· β a, Ξ¦ a) β’ β· False β¨ β a, β· Ξ¦ a := | := by
apply later_sExists_false.trans
apply or_elim
Β· apply or_intro_l
Β· refine or_intro_r' <| exists_elim ?_
intro P
refine imp_elim <| pure_elim' ?_
rintro β¨a, rflβ©
exact imp_intro' <| exists_intro' a and_elim_l | 4 | 52 | false | Framework |
236 | Iris.DFrac.update_discard | theorem DFrac.update_discard {dq : DFrac F} : dq ~~> .discard | iris-lean | src/Iris/Algebra/DFrac.lean | [
"import Iris.Algebra.CMRA",
"import Iris.Algebra.Updates",
"import src.Iris.Algebra.Frac",
"import Iris.Algebra.OFE",
"import Iris.Algebra.LocalUpdates",
"import src.Iris.Algebra.CMRA",
"import Iris.Algebra.Frac"
] | [
{
"name": "Add",
"module": "Init.Prelude"
},
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "Equivalence",
"module": "Init.Core"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "m",
"module": "QqTest.matching"
},
{
"name": "Option.merge",
"module": "Init.Data.Option.Basic"
},
{
"name": "id",
"module": "Init.Prelude"
}
] | [
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y"
},
{
"name": "notation:50 \"β{\" n \"} \" x:51 => ValidN n x",
"content": "notation:50 \"β{\" n \"} \" x:51 => ValidN n x"
},
{
"name": "Fractional",
"content": "def Fractional [Fraction Ξ±] (a : Ξ±) : Prop := β b, Proper (a + b)"
},
{
"name": "Fraction",
"content": "class Fraction (Ξ± : Type _) extends Add Ξ± where\n \n Proper : Ξ± β Prop\n add_comm : β a b : Ξ±, a + b = b + a\n add_assoc : β a b c : Ξ±, a + (b + c) = (a + b) + c\n add_left_cancel : β {a b c : Ξ±}, a + b = a + c β b = c\n \n add_ne : β {a b : Ξ±}, a β b + a\n proper_add_mono_left : β {a b : Ξ±}, Proper (a + b) β Proper a"
},
{
"name": "NumericFraction",
"content": "class NumericFraction (Ξ± : Type _) extends One Ξ±, Add Ξ±, LE Ξ±, LT Ξ± where\n add_comm : β a b : Ξ±, a + b = b + a\n add_assoc : β a b c : Ξ±, a + (b + c) = (a + b) + c\n add_left_cancel : β {a b c : Ξ±}, a + b = a + c β b = c\n le_def : β {a b : Ξ±}, a β€ b β a = b β¨ a < b\n lt_def : β {a b : Ξ±}, a < b β β c : Ξ±, a + c = b\n lt_irrefl : β {a : Ξ±}, Β¬a < a"
},
{
"name": "CMRA",
"content": "class CMRA (Ξ± : Type _) extends OFE Ξ± where\n pcore : Ξ± β Option Ξ±\n op : Ξ± β Ξ± β Ξ±\n ValidN : Nat β Ξ± β Prop\n Valid : Ξ± β Prop\n\n op_ne : NonExpansive (op x)\n pcore_ne : x β‘{n}β‘ y β pcore x = some cx β\n β cy, pcore y = some cy β§ cx β‘{n}β‘ cy\n validN_ne : x β‘{n}β‘ y β ValidN n x β ValidN n y\n\n valid_iff_validN : Valid x β β n, ValidN n x\n validN_succ : ValidN n.succ x β ValidN n x\n validN_op_left : ValidN n (op x y) β ValidN n x\n\n assoc : op x (op y z) β‘ op (op x y) z\n comm : op x y β‘ op y x\n\n pcore_op_left : pcore x = some cx β op cx x β‘ x\n pcore_idem : pcore x = some cx β pcore cx β‘ some cx\n pcore_op_mono : pcore x = some cx β β y, β cy, pcore (op x y) β‘ some (op cx cy)\n\n extend : ValidN n x β x β‘{n}β‘ op yβ yβ β\n Ξ£' zβ zβ, x β‘ op zβ zβ β§ zβ β‘{n}β‘ yβ β§ zβ β‘{n}β‘ yβ"
},
{
"name": "Update",
"content": "def Update [CMRA Ξ±] (x y : Ξ±) := β n mz,\n β{n} (x β’? mz) β β{n} (y β’? mz)"
},
{
"name": "Associative",
"content": "class Associative (R : Relation Ξ±) (f : Ξ± β Ξ± β Ξ±) where\n assoc {x y z : Ξ±} : R (f (f x y) z) (f x (f y z))"
},
{
"name": "OFE.ContractiveHom.fixpoint_ne",
"content": "instance OFE.ContractiveHom.fixpoint_ne [COFE Ξ±] [Inhabited Ξ±] :\n NonExpansive (ContractiveHom.fixpoint (Ξ± := Ξ±)) where\n ne n f1 f2 H := by admit /- proof elided -/"
},
{
"name": "Option.merge_ne",
"content": "instance Option.merge_ne [OFE Ξ±] {op : Ξ± β Ξ± β Ξ±} [NonExpansiveβ op] :\n NonExpansiveβ (Option.merge op) where\n ne n x1 x2 Hx y1 y2 Hy := by admit /- proof elided -/"
},
{
"name": "NonExpansiveβ",
"content": "class NonExpansiveβ [OFE Ξ±] [OFE Ξ²] [OFE Ξ³] (f : Ξ± β Ξ² β Ξ³) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β β β¦yβ yββ¦, yβ β‘{n}β‘ yβ β f xβ yβ β‘{n}β‘ f xβ yβ"
},
{
"name": "ContractiveHom",
"content": "@[ext] structure ContractiveHom (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] extends Hom Ξ± Ξ² where\n [contractive : Contractive f]\n ne := ne_of_contractive f"
},
{
"name": "OFE.Option.some.ne",
"content": "instance OFE.Option.some.ne [OFE Ξ±] : OFE.NonExpansive (some : Ξ± β Option Ξ±) := β¨fun _ _ _ => idβ©"
},
{
"name": "NonExpansive",
"content": "class NonExpansive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β f xβ β‘{n}β‘ f xβ"
},
{
"name": "Commutative",
"content": "class Commutative (R : Relation Ξ±) (f : Ξ² β Ξ² β Ξ±) where\n comm {x y : Ξ²} : R (f x y) (f y x)"
},
{
"name": "op?",
"content": "def op? [CMRA Ξ±] (x : Ξ±) : Option Ξ± β Ξ±\n | some y => x β’ y\n | none => x"
},
{
"name": "Discrete",
"content": "class Discrete (Ξ± : Type _) [CMRA Ξ±] extends OFE.Discrete Ξ± where\n discrete_valid {x : Ξ±} : β{0} x β β x"
},
{
"name": "Discrete",
"content": "class Discrete (Ξ± : Type _) [OFE Ξ±] where\n discrete_0 {x y : Ξ±} : x β‘{0}β‘ y β x β‘ y"
},
{
"name": "infixr:50 \" ~~> \" => Update",
"content": "infixr:50 \" ~~> \" => Update"
},
{
"name": "scoped infix:40 \" β‘ \" => OFE.Equiv",
"content": "scoped infix:40 \" β‘ \" => OFE.Equiv"
},
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y"
},
{
"name": "infixr:25 \" -c> \" => ContractiveHom",
"content": "infixr:25 \" -c> \" => ContractiveHom"
},
{
"name": "infix:60 \" β’? \" => op?",
"content": "infix:60 \" β’? \" => op?"
}
] | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "Fractional.of_add_right",
"content": "theorem Fractional.of_add_right {a a' : Ξ±} (H : Fractional (a + a')) : Fractional a'"
},
{
"name": "valid_iff_validN'",
"content": "theorem valid_iff_validN' [Discrete Ξ±] (n) {x : Ξ±} : β x β β{n} x"
},
{
"name": "validN_of_le",
"content": "theorem validN_of_le {n n'} {x : Ξ±} : n' β€ n β β{n} x β β{n'} x"
},
{
"name": "Valid.validN",
"content": "theorem Valid.validN : β (x : Ξ±) β β{n} x"
}
] | [
{
"name": "Iris.DFrac",
"content": "inductive DFrac (F : Type _) where\n \n| own (f : F) : DFrac F\n \n| discard : DFrac F\n \n| ownDiscard (f : F) : DFrac F"
},
{
"name": "Iris.valid",
"content": "def valid : DFrac F β Prop\n | .own f => Proper f\n | .discard => True\n | .ownDiscard f => Fractional f"
},
{
"name": "Iris.pcore",
"content": "def pcore : DFrac F β Option (DFrac F)\n | own _ => none\n | .discard => some discard\n | ownDiscard _ => some discard"
},
{
"name": "Iris.op",
"content": "def op : DFrac F β DFrac F β DFrac F\n | .discard, .discard => discard\n | own f, .discard\n | ownDiscard f, .discard\n | .discard, own f\n | .discard, ownDiscard f => ownDiscard f\n | own f, own f' => own (f + f')\n | own f, ownDiscard f'\n | ownDiscard f, own f'\n | ownDiscard f, ownDiscard f' => ownDiscard (f + f')"
}
] | [
{
"name": "Iris.valid_op_own",
"content": "theorem valid_op_own {dq : DFrac F} {q : F} : β dq β’ own q β Fractional q"
}
] | import Iris.Algebra.CMRA
import Iris.Algebra.OFE
import Iris.Algebra.Frac
import Iris.Algebra.Updates
import Iris.Algebra.LocalUpdates
namespace Iris
inductive DFrac (F : Type _) where
| own (f : F) : DFrac F
| discard : DFrac F
| ownDiscard (f : F) : DFrac F
section dfrac
open DFrac Fraction OFE.Discrete
variable [UFraction F]
def valid : DFrac F β Prop
| .own f => Proper f
| .discard => True
| .ownDiscard f => Fractional f
def pcore : DFrac F β Option (DFrac F)
| own _ => none
| .discard => some discard
| ownDiscard _ => some discard
def op : DFrac F β DFrac F β DFrac F
| .discard, .discard => discard
| own f, .discard
| ownDiscard f, .discard
| .discard, own f
| .discard, ownDiscard f => ownDiscard f
| own f, own f' => own (f + f')
| own f, ownDiscard f'
| ownDiscard f, own f'
| ownDiscard f, ownDiscard f' => ownDiscard (f + f') | theorem DFrac.update_discard {dq : DFrac F} : dq ~~> .discard := | := by
intros n q H
apply (CMRA.valid_iff_validN' n).mp
have H' := (CMRA.valid_iff_validN' n).mpr H
simp [CMRA.op?] at H' β’
rcases q with (_|β¨q|_|qβ©) <;> simp [CMRA.Valid, valid, CMRA.op, op]
Β· cases dq <;> first | exact valid_op_own H | exact H
Β· cases dq <;> first | exact Fractional.of_add_right H | exact H | 3 | 31 | false | Framework |
237 | Iris.local_update_unital_discrete | theorem local_update_unital_discrete [CMRA.Discrete Ξ±] (x y x' y' : Ξ±) :
(x, y) ~l~> (x', y') β β z, β x β x β‘ y β’ z β (β x' β§ x' β‘ y' β’ z) | iris-lean | src/Iris/Algebra/LocalUpdates.lean | [
"import Iris.Algebra.CMRA",
"import src.Iris.Algebra.CMRA",
"import src.Iris.Algebra.OFE"
] | [
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "Equivalence",
"module": "Init.Core"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "m",
"module": "QqTest.matching"
},
{
"name": "Option.merge",
"module": "Init.Data.Option.Basic"
},
{
"name": "id",
"module": "Init.Prelude"
}
] | [
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y"
},
{
"name": "notation:50 \"β{\" n \"} \" x:51 => ValidN n x",
"content": "notation:50 \"β{\" n \"} \" x:51 => ValidN n x"
},
{
"name": "notation:50 x \" βΌ{\" n \"} \" y:51 => IncludedN n x y",
"content": "notation:50 x \" βΌ{\" n \"} \" y:51 => IncludedN n x y"
},
{
"name": "CMRA",
"content": "class CMRA (Ξ± : Type _) extends OFE Ξ± where\n pcore : Ξ± β Option Ξ±\n op : Ξ± β Ξ± β Ξ±\n ValidN : Nat β Ξ± β Prop\n Valid : Ξ± β Prop\n\n op_ne : NonExpansive (op x)\n pcore_ne : x β‘{n}β‘ y β pcore x = some cx β\n β cy, pcore y = some cy β§ cx β‘{n}β‘ cy\n validN_ne : x β‘{n}β‘ y β ValidN n x β ValidN n y\n\n valid_iff_validN : Valid x β β n, ValidN n x\n validN_succ : ValidN n.succ x β ValidN n x\n validN_op_left : ValidN n (op x y) β ValidN n x\n\n assoc : op x (op y z) β‘ op (op x y) z\n comm : op x y β‘ op y x\n\n pcore_op_left : pcore x = some cx β op cx x β‘ x\n pcore_idem : pcore x = some cx β pcore cx β‘ some cx\n pcore_op_mono : pcore x = some cx β β y, β cy, pcore (op x y) β‘ some (op cx cy)\n\n extend : ValidN n x β x β‘{n}β‘ op yβ yβ β\n Ξ£' zβ zβ, x β‘ op zβ zβ β§ zβ β‘{n}β‘ yβ β§ zβ β‘{n}β‘ yβ"
},
{
"name": "pcore",
"content": "def pcore : DFrac F β Option (DFrac F)\n | own _ => none\n | .discard => some discard\n | ownDiscard _ => some discard"
},
{
"name": "DFrac",
"content": "inductive DFrac (F : Type _) where\n \n| own (f : F) : DFrac F\n \n| discard : DFrac F\n \n| ownDiscard (f : F) : DFrac F"
},
{
"name": "op",
"content": "def op : DFrac F β DFrac F β DFrac F\n | .discard, .discard => discard\n | own f, .discard\n | ownDiscard f, .discard\n | .discard, own f\n | .discard, ownDiscard f => ownDiscard f\n | own f, own f' => own (f + f')\n | own f, ownDiscard f'\n | ownDiscard f, own f'\n | ownDiscard f, ownDiscard f' => ownDiscard (f + f')"
},
{
"name": "Associative",
"content": "class Associative (R : Relation Ξ±) (f : Ξ± β Ξ± β Ξ±) where\n assoc {x y z : Ξ±} : R (f (f x y) z) (f x (f y z))"
},
{
"name": "OFE.ContractiveHom.fixpoint_ne",
"content": "instance OFE.ContractiveHom.fixpoint_ne [COFE Ξ±] [Inhabited Ξ±] :\n NonExpansive (ContractiveHom.fixpoint (Ξ± := Ξ±)) where\n ne n f1 f2 H := by admit /- proof elided -/"
},
{
"name": "Option.merge_ne",
"content": "instance Option.merge_ne [OFE Ξ±] {op : Ξ± β Ξ± β Ξ±} [NonExpansiveβ op] :\n NonExpansiveβ (Option.merge op) where\n ne n x1 x2 Hx y1 y2 Hy := by admit /- proof elided -/"
},
{
"name": "NonExpansiveβ",
"content": "class NonExpansiveβ [OFE Ξ±] [OFE Ξ²] [OFE Ξ³] (f : Ξ± β Ξ² β Ξ³) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β β β¦yβ yββ¦, yβ β‘{n}β‘ yβ β f xβ yβ β‘{n}β‘ f xβ yβ"
},
{
"name": "ContractiveHom",
"content": "@[ext] structure ContractiveHom (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] extends Hom Ξ± Ξ² where\n [contractive : Contractive f]\n ne := ne_of_contractive f"
},
{
"name": "OFE.Option.some.ne",
"content": "instance OFE.Option.some.ne [OFE Ξ±] : OFE.NonExpansive (some : Ξ± β Option Ξ±) := β¨fun _ _ _ => idβ©"
},
{
"name": "NonExpansive",
"content": "class NonExpansive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β f xβ β‘{n}β‘ f xβ"
},
{
"name": "Commutative",
"content": "class Commutative (R : Relation Ξ±) (f : Ξ² β Ξ² β Ξ±) where\n comm {x y : Ξ²} : R (f x y) (f y x)"
},
{
"name": "Discrete",
"content": "class Discrete (Ξ± : Type _) [CMRA Ξ±] extends OFE.Discrete Ξ± where\n discrete_valid {x : Ξ±} : β{0} x β β x"
},
{
"name": "Discrete",
"content": "class Discrete (Ξ± : Type _) [OFE Ξ±] where\n discrete_0 {x y : Ξ±} : x β‘{0}β‘ y β x β‘ y"
},
{
"name": "Included",
"content": "def Included (x y : Ξ±) : Prop := β z, y β‘ x β’ z"
},
{
"name": "Reflexive",
"content": "class Reflexive (R : Relation Ξ±) where\n refl {x : Ξ±} : R x x"
},
{
"name": "UCMRA",
"content": "class UCMRA (Ξ± : Type _) extends CMRA Ξ± where\n unit : Ξ±\n unit_valid : β unit\n unit_left_id : unit β’ x β‘ x\n pcore_unit : pcore unit β‘ some unit"
},
{
"name": "Iso.symm",
"content": "def Iso.symm [OFE Ξ±] [OFE Ξ²] (iso : Iso Ξ± Ξ²) : Iso Ξ² Ξ± where\n hom := iso.inv\n inv := iso.hom\n hom_inv := by admit /- proof elided -/"
},
{
"name": "Iso",
"content": "@[ext] structure Iso (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] where\n hom : Ξ± -n> Ξ²\n inv : Ξ² -n> Ξ±\n hom_inv : hom (inv x) β‘ x\n inv_hom : inv (hom x) β‘ x"
},
{
"name": "scoped infix:40 \" β‘ \" => OFE.Equiv",
"content": "scoped infix:40 \" β‘ \" => OFE.Equiv"
},
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y"
},
{
"name": "infixr:25 \" -c> \" => ContractiveHom",
"content": "infixr:25 \" -c> \" => ContractiveHom"
},
{
"name": "infix:60 \" β’ \" => op",
"content": "infix:60 \" β’ \" => op"
},
{
"name": "infix:50 \" βΌ \" => Included",
"content": "infix:50 \" βΌ \" => Included"
}
] | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "Dist.trans",
"content": "theorem Dist.trans [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ y β y β‘{n}β‘ z β x β‘{n}β‘ z"
},
{
"name": "Included.trans",
"content": "theorem Included.trans : (x : Ξ±) βΌ y β y βΌ z β x βΌ z"
},
{
"name": "inc_trans",
"content": "theorem inc_trans {x y z : Ξ±} : x βΌ y β y βΌ z β x βΌ z"
},
{
"name": "op_left_eqv",
"content": "theorem op_left_eqv {x y : Ξ±} (z : Ξ±) (e : x β‘ y) : x β’ z β‘ y β’ z"
},
{
"name": "_root_.Iris.OFE.Dist.op_r",
"content": "theorem _root_.Iris.OFE.Dist.op_r {x y z : Ξ±} : y β‘{n}β‘ z β x β’ y β‘{n}β‘ x β’ z"
},
{
"name": "op_right_dist",
"content": "theorem op_right_dist (x : Ξ±) {y z : Ξ±} (e : y β‘{n}β‘ z) : x β’ y β‘{n}β‘ x β’ z"
},
{
"name": "_root_.Iris.OFE.Equiv.op_r",
"content": "theorem _root_.Iris.OFE.Equiv.op_r {x y z : Ξ±} : y β‘ z β x β’ y β‘ x β’ z"
},
{
"name": "op_right_eqv",
"content": "theorem op_right_eqv (x : Ξ±) {y z : Ξ±} (e : y β‘ z) : x β’ y β‘ x β’ z"
},
{
"name": "IncludedN.trans",
"content": "theorem IncludedN.trans : (x : Ξ±) βΌ{n} y β y βΌ{n} z β x βΌ{n} z"
},
{
"name": "incN_trans",
"content": "theorem incN_trans {x y z : Ξ±} : x βΌ{n} y β y βΌ{n} z β x βΌ{n} z"
},
{
"name": "op_left_dist",
"content": "theorem op_left_dist {x y : Ξ±} (z : Ξ±) (e : x β‘{n}β‘ y) : x β’ z β‘{n}β‘ y β’ z"
},
{
"name": "Equiv.trans",
"content": "theorem Equiv.trans [OFE Ξ±] {x : Ξ±} : x β‘ y β y β‘ z β x β‘ z"
},
{
"name": "equiv_eqv",
"content": "theorem equiv_eqv [ofe : OFE Ξ±] : Equivalence ofe.Equiv"
},
{
"name": "Dist.symm",
"content": "@[symm] theorem Dist.symm [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ y β y β‘{n}β‘ x"
},
{
"name": "Dist.rfl",
"content": "@[simp, refl] theorem Dist.rfl [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ x"
},
{
"name": "DistLater.trans",
"content": "theorem DistLater.trans [OFE Ξ±] {n} {x : Ξ±} (h1 : DistLater n x y) (h2 : DistLater n y z) :\n DistLater n x z"
},
{
"name": "unit_right_id_dist",
"content": "theorem unit_right_id_dist (x : Ξ±) : x β’ unit β‘{n}β‘ x"
},
{
"name": "unit_left_id_dist",
"content": "theorem unit_left_id_dist {n} (x : Ξ±) : unit β’ x β‘{n}β‘ x"
},
{
"name": "Equiv.dist",
"content": "theorem Equiv.dist [OFE Ξ±] {x : Ξ±} : x β‘ y β x β‘{n}β‘ y"
},
{
"name": "valid_iff_validN'",
"content": "theorem valid_iff_validN' [Discrete Ξ±] (n) {x : Ξ±} : β x β β{n} x"
},
{
"name": "validN_of_le",
"content": "theorem validN_of_le {n n'} {x : Ξ±} : n' β€ n β β{n} x β β{n'} x"
},
{
"name": "Valid.validN",
"content": "theorem Valid.validN : β (x : Ξ±) β β{n} x"
},
{
"name": "IncludedN.validN",
"content": "theorem IncludedN.validN {n} {x y : Ξ±} : x βΌ{n} y β β{n} y β β{n} x"
},
{
"name": "validN_of_incN",
"content": "theorem validN_of_incN {n} {x y : Ξ±} : x βΌ{n} y β β{n} y β β{n} x"
},
{
"name": "_root_.Iris.OFE.Dist.validN",
"content": "theorem _root_.Iris.OFE.Dist.validN : (x : Ξ±) β‘{n}β‘ y β (β{n} x β β{n} y)"
},
{
"name": "validN_iff",
"content": "theorem validN_iff {x y : Ξ±} (e : x β‘{n}β‘ y) : β{n} x β β{n} y"
},
{
"name": "Included.validN",
"content": "theorem Included.validN {n} {x y : Ξ±} : x βΌ y β β{n} y β β{n} x"
},
{
"name": "validN_of_inc",
"content": "theorem validN_of_inc {n} {x y : Ξ±} : x βΌ y β β{n} y β β{n} x"
}
] | [
{
"name": "Iris.LocalUpdate",
"content": "def LocalUpdate [CMRA Ξ±] (x y : Ξ± Γ Ξ±) : Prop :=\n βn mz, β{n} x.1 β x.1 β‘{n}β‘ x.2 β’? mz β β{n} y.1 β§ y.1 β‘{n}β‘ y.2 β’? mz"
}
] | [
{
"name": "Iris.local_update_unital",
"content": "theorem local_update_unital {x y x' y' : Ξ±} :\n (x, y) ~l~> (x', y') β β n z, β{n} x β x β‘{n}β‘ y β’ z β (β{n} x' β§ x' β‘{n}β‘ y' β’ z)"
}
] | import Iris.Algebra.CMRA
namespace Iris
def LocalUpdate [CMRA Ξ±] (x y : Ξ± Γ Ξ±) : Prop :=
βn mz, β{n} x.1 β x.1 β‘{n}β‘ x.2 β’? mz β β{n} y.1 β§ y.1 β‘{n}β‘ y.2 β’? mz
infixr:50 " ~l~> " => LocalUpdate
section localUpdate
section CMRA
variable [CMRA Ξ±]
end CMRA
section UCMRA
variable [UCMRA Ξ±] | theorem local_update_unital_discrete [CMRA.Discrete Ξ±] (x y x' y' : Ξ±) :
(x, y) ~l~> (x', y') β β z, β x β x β‘ y β’ z β (β x' β§ x' β‘ y' β’ z) := | where
mp h z vx e :=
have β¨vx', e'β© := h 0 (some z) (CMRA.Valid.validN vx) e.dist
β¨CMRA.discrete_valid vx', OFE.discrete_0 e'β©
mpr h := by
refine local_update_unital.mpr fun n z vnx e => ?_
have β¨vx', e'β© := h z ((CMRA.valid_iff_validN' n).mpr vnx) (OFE.discrete e)
exact β¨vx'.validN, e'.distβ© | 5 | 51 | false | Framework |
238 | Iris.BI.persistently_and_sep_assoc | theorem persistently_and_sep_assoc [BI PROP] {P Q R : PROP} :
<pers> P β§ (Q β R) β£β’ (<pers> P β§ Q) β R | iris-lean | src/Iris/BI/DerivedLaws.lean | [
"import Iris.BI.Extensions",
"import Iris.Std.TC",
"import Iris.Std.Classes",
"import Iris.BI.BI",
"import src.Iris.Algebra.OFE",
"import src.Iris.BI.BI",
"import Iris.BI.Classes",
"import Iris.Std.Rewrite"
] | [
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "Option.merge",
"module": "Init.Data.Option.Basic"
},
{
"name": "id",
"module": "Init.Prelude"
},
{
"name": "Equivalence",
"module": "Init.Core"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "m",
"module": "QqTest.matching"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Bool",
"module": "Init.Prelude"
}
] | [
{
"name": "macro \"β\" xs:explicitBinders \", \" b:term : term => do",
"content": "macro \"β\" xs:explicitBinders \", \" b:term : term => do\n return β¨β expandExplicitBinders ``BIBase.exists xs bβ©"
},
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y\n\nsyntax:max \"<pers> \" term:40 : term"
},
{
"name": "macro:25 P:term:29 \" β’ \" Q:term:25 : term => ``(BIBase.Entai",
"content": "macro:25 P:term:29 \" β’ \" Q:term:25 : term => ``(BIBase.Entails iprop($P) iprop($Q))\n\ndelab_rule BIBase.Entails\n | `($_ $P $Q) => do ``($(β unpackIprop P) β’ $(β unpackIprop Q))"
},
{
"name": "macro:25 P:term:29 \" β£β’ \" Q:term:29 : term => ``(BiEntails i",
"content": "macro:25 P:term:29 \" β£β’ \" Q:term:29 : term => ``(BiEntails iprop($P) iprop($Q))\n\ndelab_rule BIBase.Entails\n | `($_ iprop(emp) $P) => do ``(β’ $(β unpackIprop P))\n\ndelab_rule BIBase.BiEntails\n | `($_ $P $Q) => do ``($(β unpackIprop P) β£β’ $(β unpackIprop Q))\n\nsyntax \"β\" term \"β\" : term\n\nsyntax:max \"β· \" term:40 : term"
},
{
"name": "macro:max \"iprop(\" P:term \" : \" t:term \")\" : term => `((ipro",
"content": "macro:max \"iprop(\" P:term \" : \" t:term \")\" : term => `((iprop($P) : $t))\n\nsyntax:max \"iprop(\" term \")\" : term\n\nsyntax:max \"<affine> \" term:40 : term\n\nsyntax:max \"β‘ \" term:40 : term\n\nsyntax:max \"<absorb> \" term:40 : term"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(term($t))) => pure t\n | `(iprop($t)) => pure t"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(($P))) => ``((iprop($P)))\n | `(iprop(if $c then $t else $e)) => ``(if $c then iprop($t) else iprop($e))\n | `(iprop(($P : $t))) => ``((iprop($P) : $t))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(emp)) => ``(BIBase.emp)\n | `(iprop(β$Οβ)) => ``(BIBase.pure $Ο)\n | `(iprop($P β§ $Q)) => ``(BIBase.and iprop($P) iprop($Q))\n | `(iprop($P β¨ $Q)) => ``(BIBase.or iprop($P) iprop($Q))\n | `(iprop($P β $Q)) => ``(BIBase.imp iprop($P) iprop($Q))\n | `(iprop(β $xs, $Ξ¨)) => do expandExplicitBinders ``BIBase.exists xs (β ``(iprop($Ξ¨)))\n | `(iprop($P β $Q)) => ``(BIBase.sep iprop($P) iprop($Q))\n | `(iprop($P -β $Q)) => ``(BIBase.wand iprop($P) iprop($Q))\n | `(iprop(<pers> $P)) => ``(BIBase.persistently iprop($P))\n | `(iprop(β· $P)) => ``(BIBase.later iprop($P))\n\ndelab_rule BIBase.emp\n | `($_) => ``(iprop($(mkIdent `emp)))\ndelab_rule BIBase.pure\n | `($_ $Ο) => ``(iprop(β$Οβ))\ndelab_rule BIBase.and\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β§ $(β unpackIprop Q)))\ndelab_rule BIBase.or\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β¨ $(β unpackIprop Q)))\ndelab_rule BIBase.imp\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule BIBase.forall\n | `($_ fun $x:ident => iprop(β $y:ident $[$z:ident]*, $Ξ¨)) => do\n ``(iprop(β $x:ident $y:ident $[$z:ident]*, $Ξ¨))\n | `($_ fun $x:ident => $Ξ¨) => do ``(iprop(β $x:ident, $(β unpackIprop Ξ¨)))\ndelab_rule BIBase.exists\n | `($_ fun $x:ident => iprop(β $y:ident $[$z:ident]*, $Ξ¨)) => do\n ``(iprop(β $x:ident $y:ident $[$z:ident]*, $Ξ¨))\n | `($_ fun $x:ident => $Ξ¨) => do ``(iprop(β $x:ident, $(β unpackIprop Ξ¨)))\ndelab_rule BIBase.sep\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule BIBase.wand\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) -β $(β unpackIprop Q)))\ndelab_rule BIBase.persistently\n | `($_ $P) => do ``(iprop(<pers> $(β unpackIprop P)))\n\ndelab_rule BIBase.pure\n | `($_ True) => ``(iprop($(mkIdent `True)))\n | `($_ False) => ``(iprop($(mkIdent `False)))\ndelab_rule BIBase.imp\n | `($_ $P iprop(False)) => do ``(iprop(Β¬$(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β _%$tk, $Ξ¨)) => ``(BIBase.forall (fun _%$tk => iprop($Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $x:ident, $Ξ¨)) => ``(BIBase.forall (fun $x => iprop($Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β (_%$tk : $t), $Ξ¨)) => ``(BIBase.forall (fun (_%$tk : $t) => iprop($Ξ¨)))\n | `(iprop(β (_%$tk $xs* : $t), $Ξ¨)) =>\n ``(BIBase.forall (fun (_%$tk : $t) => iprop(β ($xs* : $t), $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β ($x:ident : $t), $Ξ¨)) => ``(BIBase.forall (fun ($x : $t) => iprop($Ξ¨)))\n | `(iprop(β ($x:ident $xs* : $t), $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop(β ($xs* : $t), $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β {_%$tk : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun {_%$tk : $t} => iprop($Ξ¨)))\n | `(iprop(β {_%$tk $xs* : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun {_%$tk : $t} => iprop(β {$xs* : $t}, $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β {$x:ident : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop($Ξ¨)))\n | `(iprop(β {$x:ident $xs* : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop(β {$xs* : $t}, $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $x $y $xs*, $Ξ¨)) => ``(iprop(β $x, β $y $xs*, $Ξ¨))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(True)) => ``(BIBase.pure True)\n | `(iprop(False)) => ``(BIBase.pure False)\n | `(iprop(Β¬$P)) => ``(iprop($P β False))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop($P β $Q)) => ``(iff iprop($P) iprop($Q))\n | `(iprop($P β-β $Q)) => ``(wandIff iprop($P) iprop($Q))\n\ndelab_rule iff\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule wandIff\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β-β $(β unpackIprop Q)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(<affine> $P)) => ``(affinely iprop($P))\n | `(iprop(<absorb> $P)) => ``(absorbingly iprop($P))\n\ndelab_rule affinely\n | `($_ $P) => do ``(iprop(<affine> $(β unpackIprop P)))\ndelab_rule absorbingly\n | `($_ $P) => do ``(iprop(<absorb> $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β‘ $P)) => ``(intuitionistically iprop($P))\n\ndelab_rule intuitionistically\n | `($_ $P) => do ``(iprop(β‘ $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(<pers>?$p $P)) => ``(persistentlyIf $p iprop($P))\n | `(iprop(<affine>?$p $P)) => ``(affinelyIf $p iprop($P))\n | `(iprop(<absorb>?$p $P)) => ``(absorbinglyIf $p iprop($P))\n | `(iprop(β‘?$p $P)) => ``(intuitionisticallyIf $p iprop($P))\n\ndelab_rule persistentlyIf\n | `($_ $p $P) => do ``(iprop(<pers>?$p $(β unpackIprop P)))\ndelab_rule affinelyIf\n | `($_ $p $P) => do ``(iprop(<affine>?$p $(β unpackIprop P)))\ndelab_rule absorbinglyIf\n | `($_ $p $P) => do ``(iprop(<absorb>?$p $(β unpackIprop P)))\ndelab_rule intuitionisticallyIf\n | `($_ $p $P) => do ``(iprop(β‘?$p $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β·^[$n] $P)) => ``(laterN $n iprop($P))\n\ndelab_rule laterN\n | `($_ $n $P) => do ``(iprop(β·^[$n] $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $P)) => ``(except0 iprop($P))\n\ndelab_rule except0\n | `($_ $P) => do ``(iprop(β $(β unpackIprop P)))"
},
{
"name": "BI",
"content": "class BI (PROP : Type _) extends COFE PROP, BI.BIBase PROP where\n Equiv P Q := P β£β’ Q\n\n entails_preorder : Preorder Entails\n equiv_iff {P Q : PROP} : (P β‘ Q) β P β£β’ Q := by admit /- proof elided -/"
},
{
"name": "LawfulBigOp",
"content": "class LawfulBigOp (f : PROP β PROP β PROP) (unit : outParam PROP)\n (eq : outParam (PROP β PROP β Prop)) where\n refl : eq a a\n symm : eq a b β eq b a\n trans : eq a b β eq b c β eq a c\n comm : eq (f a b) (f b a)\n assoc : eq (f (f a b) c) (f a (f b c))\n left_id : eq (f unit a) a\n congr_l : eq a a' β eq (f a b) (f a' b)"
},
{
"name": "BIBase",
"content": "class BIBase (PROP : Type u) where\n Entails : PROP β PROP β Prop\n emp : PROP\n pure : Prop β PROP\n and : PROP β PROP β PROP\n or : PROP β PROP β PROP\n imp : PROP β PROP β PROP\n sForall : (PROP β Prop) β PROP\n sExists : (PROP β Prop) β PROP\n sep : PROP β PROP β PROP\n wand : PROP β PROP β PROP\n persistently : PROP β PROP\n later : PROP β PROP"
},
{
"name": "liftRel",
"content": "def liftRel (R : Ξ± β Ξ² β Prop) (A : Ξ± β Prop) (B : Ξ² β Prop) : Prop :=\n (β a, A a β β b, B b β§ R a b) β§ (β b, B b β β a, A a β§ R a b)"
},
{
"name": "Preorder",
"content": "class Preorder (R : Relation Ξ±) extends Reflexive R, Transitive R"
},
{
"name": "Reflexive",
"content": "class Reflexive (R : Relation Ξ±) where\n refl {x : Ξ±} : R x x"
},
{
"name": "Relation",
"content": "abbrev Relation (Ξ± : Type _) := Ξ± β Ξ± β Prop"
},
{
"name": "Transitive",
"content": "class Transitive (R : Relation Ξ±) where\n trans {x y z : Ξ±} : R x y β R y z β R x z"
},
{
"name": "NonExpansiveβ",
"content": "class NonExpansiveβ [OFE Ξ±] [OFE Ξ²] [OFE Ξ³] (f : Ξ± β Ξ² β Ξ³) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β β β¦yβ yββ¦, yβ β‘{n}β‘ yβ β f xβ yβ β‘{n}β‘ f xβ yβ"
},
{
"name": "OFE.ContractiveHom.fixpoint_ne",
"content": "instance OFE.ContractiveHom.fixpoint_ne [COFE Ξ±] [Inhabited Ξ±] :\n NonExpansive (ContractiveHom.fixpoint (Ξ± := Ξ±)) where\n ne n f1 f2 H := by admit /- proof elided -/"
},
{
"name": "ContractiveHom",
"content": "@[ext] structure ContractiveHom (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] extends Hom Ξ± Ξ² where\n [contractive : Contractive f]\n ne := ne_of_contractive f"
},
{
"name": "OFE.Option.some.ne",
"content": "instance OFE.Option.some.ne [OFE Ξ±] : OFE.NonExpansive (some : Ξ± β Option Ξ±) := β¨fun _ _ _ => idβ©"
},
{
"name": "Option.merge_ne",
"content": "instance Option.merge_ne [OFE Ξ±] {op : Ξ± β Ξ± β Ξ±} [NonExpansiveβ op] :\n NonExpansiveβ (Option.merge op) where\n ne n x1 x2 Hx y1 y2 Hy := by admit /- proof elided -/"
},
{
"name": "NonExpansive",
"content": "class NonExpansive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β f xβ β‘{n}β‘ f xβ"
},
{
"name": "COFE.OFunctor.constOF_RFunctor",
"content": "instance COFE.OFunctor.constOF_RFunctor [CMRA B] : RFunctor (constOF B) where\n map f g := by admit /- proof elided -/"
},
{
"name": "IsCOFE",
"content": "class IsCOFE (Ξ± : Type _) [OFE Ξ±] where\n compl : Chain Ξ± β Ξ±\n conv_compl {c : Chain Ξ±} : compl c β‘{n}β‘ c n"
},
{
"name": "Chain",
"content": "structure Chain (Ξ± : Type _) [OFE Ξ±] where\n chain : Nat β Ξ±\n cauchy : n β€ i β chain i β‘{n}β‘ chain n"
},
{
"name": "intuitionistically",
"content": "def intuitionistically [BIBase PROP] (P : PROP) : PROP := iprop(<affine> <pers> P)"
},
{
"name": "Affine",
"content": "class Affine [BI PROP] (P : PROP) where\n affine : P β’ emp"
},
{
"name": "bigAnd",
"content": "def bigAnd [BIBase PROP] (Ps : List PROP) : PROP := bigOp and iprop(True) Ps"
},
{
"name": "bigOp",
"content": "def bigOp (f : PROP β PROP β PROP) (unit : PROP) : List PROP β PROP\n | [] => unit\n | [P] => P\n | P :: Ps => f P (bigOp f unit Ps)"
},
{
"name": "absorbingly",
"content": "def absorbingly [BIBase PROP] (P : PROP) : PROP := iprop(True β P)"
},
{
"name": "BiEntails",
"content": "structure BiEntails [BIBase PROP] (P Q : PROP) where\n mp : P β’ Q\n mpr : Q β’ P"
},
{
"name": "persistentlyIf",
"content": "def persistentlyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then <pers> P else P)"
},
{
"name": "intuitionisticallyIf",
"content": "def intuitionisticallyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then β‘ P else P)"
},
{
"name": "bigSep",
"content": "def bigSep [BIBase PROP] (Ps : List PROP) : PROP := bigOp sep iprop(emp) Ps"
},
{
"name": "affinely",
"content": "def affinely [BIBase PROP] (P : PROP) : PROP := iprop(emp β§ P)"
},
{
"name": "bigOr",
"content": "def bigOr [BIBase PROP] (Ps : List PROP) : PROP := bigOp or iprop(False) Ps"
},
{
"name": "absorbinglyIf",
"content": "def absorbinglyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then <absorb> P else P)"
},
{
"name": "affinelyIf",
"content": "def affinelyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then <affine> P else P)"
},
{
"name": "wandIff",
"content": "def wandIff [BIBase PROP] (P Q : PROP) : PROP := iprop((P -β Q) β§ (Q -β P))"
},
{
"name": "scoped infix:40 \" β‘ \" => OFE.Equiv",
"content": "scoped infix:40 \" β‘ \" => OFE.Equiv"
},
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y"
},
{
"name": "infixr:25 \" -c> \" => ContractiveHom",
"content": "infixr:25 \" -c> \" => ContractiveHom"
},
{
"name": "notation:40 \"[β§] \" Ps:max => bigAnd Ps",
"content": "notation:40 \"[β§] \" Ps:max => bigAnd Ps"
},
{
"name": "notation:40 \"[β¨] \" Ps:max => bigOr Ps",
"content": "notation:40 \"[β¨] \" Ps:max => bigOr Ps"
},
{
"name": "notation:40 \"[β] \" Ps:max => bigSep Ps",
"content": "notation:40 \"[β] \" Ps:max => bigSep Ps"
}
] | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "Dist.trans",
"content": "theorem Dist.trans [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ y β y β‘{n}β‘ z β x β‘{n}β‘ z"
},
{
"name": "BIBase.BiEntails.trans",
"content": "theorem BIBase.BiEntails.trans [BI PROP] {P Q R : PROP} (h1 : P β£β’ Q) (h2 : Q β£β’ R) : P β£β’ R"
},
{
"name": "BIBase.Entails.trans",
"content": "theorem BIBase.Entails.trans [BI PROP] {P Q R : PROP} (h1 : P β’ Q) (h2 : Q β’ R) : P β’ R"
},
{
"name": "Equiv.trans",
"content": "theorem Equiv.trans [OFE Ξ±] {x : Ξ±} : x β‘ y β y β‘ z β x β‘ z"
},
{
"name": "equiv_eqv",
"content": "theorem equiv_eqv [ofe : OFE Ξ±] : Equivalence ofe.Equiv"
},
{
"name": "Dist.symm",
"content": "@[symm] theorem Dist.symm [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ y β y β‘{n}β‘ x"
},
{
"name": "Dist.rfl",
"content": "@[simp, refl] theorem Dist.rfl [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ x"
},
{
"name": "DistLater.trans",
"content": "theorem DistLater.trans [OFE Ξ±] {n} {x : Ξ±} (h1 : DistLater n x y) (h2 : DistLater n y z) :\n DistLater n x z"
}
] | [] | [
{
"name": "Iris.BI.and_elim_l'",
"content": "theorem and_elim_l' [BI PROP] {P Q R : PROP} (h : P β’ R) : P β§ Q β’ R"
},
{
"name": "Iris.BI.and_elim_r'",
"content": "theorem and_elim_r' [BI PROP] {P Q R : PROP} (h : Q β’ R) : P β§ Q β’ R"
},
{
"name": "Iris.BI.and_mono",
"content": "@[rw_mono_rule]\ntheorem and_mono [BI PROP] {P P' Q Q' : PROP} (h1 : P β’ Q) (h2 : P' β’ Q') : P β§ P' β’ Q β§ Q'"
},
{
"name": "Iris.BI.and_mono_l",
"content": "theorem and_mono_l [BI PROP] {P P' Q : PROP} (h : P β’ P') : P β§ Q β’ P' β§ Q"
},
{
"name": "Iris.BI.sep_mono_l",
"content": "theorem sep_mono_l [BI PROP] {P P' Q : PROP} (h : P β’ P') : P β Q β’ P' β Q"
},
{
"name": "Iris.BI.sep_congr",
"content": "@[rw_mono_rule]\ntheorem sep_congr [BI PROP] {P P' Q Q' : PROP} (h1 : P β£β’ Q) (h2 : P' β£β’ Q') :\n (P β P') β£β’ (Q β Q')"
},
{
"name": "Iris.BI.sep_congr_l",
"content": "theorem sep_congr_l [BI PROP] {P P' Q : PROP} (h : P β£β’ P') : P β Q β£β’ P' β Q"
},
{
"name": "Iris.BI.sep_congr_r",
"content": "theorem sep_congr_r [BI PROP] {P Q Q' : PROP} (h : Q β£β’ Q') : P β Q β£β’ P β Q'"
},
{
"name": "Iris.BI.sep_assoc",
"content": "theorem sep_assoc [BI PROP] {P Q R : PROP} : (P β Q) β R β£β’ P β Q β R"
}
] | import Iris.BI.Classes
import Iris.BI.Extensions
import Iris.BI.BI
import Iris.Std.Classes
import Iris.Std.Rewrite
import Iris.Std.TC
namespace Iris.BI
open Iris.Std BI | theorem persistently_and_sep_assoc [BI PROP] {P Q R : PROP} :
<pers> P β§ (Q β R) β£β’ (<pers> P β§ Q) β R := | := by
constructor
Β· refine (and_mono_l persistently_idem_2).trans <| persistently_and_affinely_sep.trans <|
sep_assoc.2.trans <| sep_mono_l <| and_intro ?_ ?_
Β· exact (sep_mono_l and_elim_r).trans persistently_absorb_l
Β· exact (sep_mono_l and_elim_l).trans emp_sep.1
Β· exact and_intro ((sep_mono_l and_elim_l).trans persistently_absorb_l) (sep_mono_l and_elim_r) | 4 | 56 | false | Framework |
239 | Iris.UpdateP.iso | theorem UpdateP.iso
(gf : β x, g (f x) β‘ x)
(g_op : β y1 y2, g (y1 β’ y2) β‘ g y1 β’ g y2)
(g_validN : β n y, β{n} (g y) β β{n} y)
(uyp : y ~~>: P)
(pq : β y', P y' β Q (g y')) :
g y ~~>: Q | iris-lean | src/Iris/Algebra/Updates.lean | [
"import Iris.Algebra.CMRA",
"import src.Iris.Algebra.CMRA",
"import src.Iris.Algebra.OFE"
] | [
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "Equivalence",
"module": "Init.Core"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "m",
"module": "QqTest.matching"
},
{
"name": "Option.merge",
"module": "Init.Data.Option.Basic"
},
{
"name": "id",
"module": "Init.Prelude"
},
{
"name": "Option.map",
"module": "Init.Prelude"
}
] | [
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y"
},
{
"name": "notation:50 \"β{\" n \"} \" x:51 => ValidN n x",
"content": "notation:50 \"β{\" n \"} \" x:51 => ValidN n x"
},
{
"name": "CMRA",
"content": "class CMRA (Ξ± : Type _) extends OFE Ξ± where\n pcore : Ξ± β Option Ξ±\n op : Ξ± β Ξ± β Ξ±\n ValidN : Nat β Ξ± β Prop\n Valid : Ξ± β Prop\n\n op_ne : NonExpansive (op x)\n pcore_ne : x β‘{n}β‘ y β pcore x = some cx β\n β cy, pcore y = some cy β§ cx β‘{n}β‘ cy\n validN_ne : x β‘{n}β‘ y β ValidN n x β ValidN n y\n\n valid_iff_validN : Valid x β β n, ValidN n x\n validN_succ : ValidN n.succ x β ValidN n x\n validN_op_left : ValidN n (op x y) β ValidN n x\n\n assoc : op x (op y z) β‘ op (op x y) z\n comm : op x y β‘ op y x\n\n pcore_op_left : pcore x = some cx β op cx x β‘ x\n pcore_idem : pcore x = some cx β pcore cx β‘ some cx\n pcore_op_mono : pcore x = some cx β β y, β cy, pcore (op x y) β‘ some (op cx cy)\n\n extend : ValidN n x β x β‘{n}β‘ op yβ yβ β\n Ξ£' zβ zβ, x β‘ op zβ zβ β§ zβ β‘{n}β‘ yβ β§ zβ β‘{n}β‘ yβ"
},
{
"name": "pcore",
"content": "def pcore : DFrac F β Option (DFrac F)\n | own _ => none\n | .discard => some discard\n | ownDiscard _ => some discard"
},
{
"name": "DFrac",
"content": "inductive DFrac (F : Type _) where\n \n| own (f : F) : DFrac F\n \n| discard : DFrac F\n \n| ownDiscard (f : F) : DFrac F"
},
{
"name": "op",
"content": "def op : DFrac F β DFrac F β DFrac F\n | .discard, .discard => discard\n | own f, .discard\n | ownDiscard f, .discard\n | .discard, own f\n | .discard, ownDiscard f => ownDiscard f\n | own f, own f' => own (f + f')\n | own f, ownDiscard f'\n | ownDiscard f, own f'\n | ownDiscard f, ownDiscard f' => ownDiscard (f + f')"
},
{
"name": "Associative",
"content": "class Associative (R : Relation Ξ±) (f : Ξ± β Ξ± β Ξ±) where\n assoc {x y z : Ξ±} : R (f (f x y) z) (f x (f y z))"
},
{
"name": "OFE.ContractiveHom.fixpoint_ne",
"content": "instance OFE.ContractiveHom.fixpoint_ne [COFE Ξ±] [Inhabited Ξ±] :\n NonExpansive (ContractiveHom.fixpoint (Ξ± := Ξ±)) where\n ne n f1 f2 H := by admit /- proof elided -/"
},
{
"name": "Option.merge_ne",
"content": "instance Option.merge_ne [OFE Ξ±] {op : Ξ± β Ξ± β Ξ±} [NonExpansiveβ op] :\n NonExpansiveβ (Option.merge op) where\n ne n x1 x2 Hx y1 y2 Hy := by admit /- proof elided -/"
},
{
"name": "NonExpansiveβ",
"content": "class NonExpansiveβ [OFE Ξ±] [OFE Ξ²] [OFE Ξ³] (f : Ξ± β Ξ² β Ξ³) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β β β¦yβ yββ¦, yβ β‘{n}β‘ yβ β f xβ yβ β‘{n}β‘ f xβ yβ"
},
{
"name": "ContractiveHom",
"content": "@[ext] structure ContractiveHom (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] extends Hom Ξ± Ξ² where\n [contractive : Contractive f]\n ne := ne_of_contractive f"
},
{
"name": "OFE.Option.some.ne",
"content": "instance OFE.Option.some.ne [OFE Ξ±] : OFE.NonExpansive (some : Ξ± β Option Ξ±) := β¨fun _ _ _ => idβ©"
},
{
"name": "NonExpansive",
"content": "class NonExpansive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β f xβ β‘{n}β‘ f xβ"
},
{
"name": "Commutative",
"content": "class Commutative (R : Relation Ξ±) (f : Ξ² β Ξ² β Ξ±) where\n comm {x y : Ξ²} : R (f x y) (f y x)"
},
{
"name": "map",
"content": "def map [OFE Ξ±] [OFE Ξ²] (f : Ξ± -n> Ξ²) (c : Chain Ξ±) : Chain Ξ² where\n chain n := f (c n)\n cauchy h := f.ne.1 (c.cauchy h)"
},
{
"name": "Chain",
"content": "structure Chain (Ξ± : Type _) [OFE Ξ±] where\n chain : Nat β Ξ±\n cauchy : n β€ i β chain i β‘{n}β‘ chain n"
},
{
"name": "Hom",
"content": "@[ext] structure Hom (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] where\n f : Ξ± β Ξ²\n ne : NonExpansive f"
},
{
"name": "Reflexive",
"content": "class Reflexive (R : Relation Ξ±) where\n refl {x : Ξ±} : R x x"
},
{
"name": "scoped infix:40 \" β‘ \" => OFE.Equiv",
"content": "scoped infix:40 \" β‘ \" => OFE.Equiv"
},
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y"
},
{
"name": "@[inherit_doc]",
"content": "@[inherit_doc]\ninfixr:25 \" -n> \" => Hom"
},
{
"name": "infixr:25 \" -c> \" => ContractiveHom",
"content": "infixr:25 \" -c> \" => ContractiveHom"
},
{
"name": "infix:60 \" β’ \" => op",
"content": "infix:60 \" β’ \" => op"
},
{
"name": "@[inherit_doc]",
"content": "@[inherit_doc]\ninfixr:25 \" -C> \" => Hom"
}
] | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "op_right_eqv",
"content": "theorem op_right_eqv (x : Ξ±) {y z : Ξ±} (e : y β‘ z) : x β’ y β‘ x β’ z"
},
{
"name": "Equiv.rfl",
"content": "@[simp, refl] theorem Equiv.rfl [OFE Ξ±] {x : Ξ±} : x β‘ x"
},
{
"name": "equiv_eqv",
"content": "theorem equiv_eqv [ofe : OFE Ξ±] : Equivalence ofe.Equiv"
},
{
"name": "Dist.symm",
"content": "@[symm] theorem Dist.symm [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ y β y β‘{n}β‘ x"
},
{
"name": "Dist.trans",
"content": "theorem Dist.trans [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ y β y β‘{n}β‘ z β x β‘{n}β‘ z"
},
{
"name": "Dist.rfl",
"content": "@[simp, refl] theorem Dist.rfl [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ x"
}
] | [
{
"name": "Iris.UpdateP",
"content": "def UpdateP [CMRA Ξ±] (x : Ξ±) (P : Ξ± β Prop) := β n mz,\n β{n} (x β’? mz) β β y, P y β§ β{n} (y β’? mz)"
},
{
"name": "Iris.Update",
"content": "def Update [CMRA Ξ±] (x y : Ξ±) := β n mz,\n β{n} (x β’? mz) β β{n} (y β’? mz)"
}
] | [] | import Iris.Algebra.CMRA
namespace Iris
def UpdateP [CMRA Ξ±] (x : Ξ±) (P : Ξ± β Prop) := β n mz,
β{n} (x β’? mz) β β y, P y β§ β{n} (y β’? mz)
infixr:50 " ~~>: " => UpdateP
def Update [CMRA Ξ±] (x y : Ξ±) := β n mz,
β{n} (x β’? mz) β β{n} (y β’? mz)
infixr:50 " ~~> " => Update
section updates
variable [CMRA Ξ±] [CMRA Ξ²] (f : Ξ± β Ξ²) (g : Ξ² β Ξ±) | theorem UpdateP.iso
(gf : β x, g (f x) β‘ x)
(g_op : β y1 y2, g (y1 β’ y2) β‘ g y1 β’ g y2)
(g_validN : β n y, β{n} (g y) β β{n} y)
(uyp : y ~~>: P)
(pq : β y', P y' β Q (g y')) :
g y ~~>: Q := | := by
intro n mz v
have : β{n} y β’? Option.map f mz :=
match mz with
| none => (g_validN n _).mp v
| some z =>
have : g y β’ z β‘ g (y β’ f z) :=
(CMRA.op_right_eqv _ (gf z).symm).trans (g_op y (f z)).symm
(g_validN n _).mp (CMRA.validN_ne this.dist v)
have β¨x, px, vxβ© := uyp n (mz.map f) this
have : g (x β’? Option.map f mz) β‘ g x β’? mz :=
match mz with
| none => OFE.Equiv.rfl
| some z => (g_op x (f z)).trans (CMRA.op_right_eqv (g x) (gf z))
exact β¨g x, pq x px, CMRA.validN_ne this.dist ((g_validN n _).mpr vx)β© | 4 | 31 | false | Framework |
240 | Iris.OFE.equiv_eqv | theorem equiv_eqv [ofe : OFE Ξ±] : Equivalence ofe.Equiv | iris-lean | src/Iris/Algebra/OFE.lean | [
"import src/Iris/Algebra/CMRA.lean",
"import src/Iris/Instances/UPred/Instance.lean",
"import src/Iris/Algebra/Agree_task.lean",
"import src/Iris/Algebra/COFESolver.lean",
"import src/Iris/Algebra/Heap.lean"
] | [
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "Option.merge",
"module": "Init.Data.Option.Basic"
},
{
"name": "id",
"module": "Init.Prelude"
},
{
"name": "Equivalence",
"module": "Init.Core"
},
{
"name": "Dist",
"module": "Mathlib.Topology.MetricSpace.Pseudo.Defs"
},
{
"name": "Equiv",
"module": "Mathlib.Logic.Equiv.Defs"
},
{
"name": "m",
"module": "QqTest.matching"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Nat.succ",
"module": "Init.Prelude"
},
{
"name": "k",
"module": "QqTest.matching"
}
] | [
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y"
},
{
"name": "notation:50 x \" βΌ{\" n \"} \" y:51 => IncludedN n x y",
"content": "notation:50 x \" βΌ{\" n \"} \" y:51 => IncludedN n x y"
},
{
"name": "Reflexive",
"content": "class Reflexive (R : Relation Ξ±) where\n refl {x : Ξ±} : R x x"
},
{
"name": "",
"content": "instance : OFE.Discrete (DFrac F) := β¨congrArg idβ©"
},
{
"name": "Agree.dist",
"content": "def Agree.dist (n : Nat) (x y : Agree Ξ±) : Prop :=\n (β a β x.car, β b β y.car, a β‘{n}β‘ b) β§\n (β b β y.car, β a β x.car, a β‘{n}β‘ b)"
},
{
"name": "OFE.ContractiveHom.fixpoint_ne",
"content": "instance OFE.ContractiveHom.fixpoint_ne [COFE Ξ±] [Inhabited Ξ±] :\n NonExpansive (ContractiveHom.fixpoint (Ξ± := Ξ±)) where\n ne n f1 f2 H := by admit /- proof elided -/"
},
{
"name": "",
"content": "instance : OFE (Tower F) where\n Equiv f g := β k, f k β‘ g k\n Dist n f g := β k, f k β‘{n}β‘ g k\n dist_eqv := {\n refl _ _ := dist_eqv.refl _\n symm h _ := dist_eqv.symm (h _)\n trans h1 h2 _ := dist_eqv.trans (h1 _) (h2 _)\n }\n equiv_dist {_ _} := by admit /- proof elided -/"
},
{
"name": "Transitive",
"content": "class Transitive (R : Relation Ξ±) where\n trans {x y z : Ξ±} : R x y β R y z β R x z"
},
{
"name": "",
"content": "instance : OFE.NonExpansive (BUpd.bupd (PROP := UPred M)) := bupd_ne"
},
{
"name": "bupd_ne",
"content": "instance bupd_ne : OFE.NonExpansive (bupd : UPred M β UPred M) where\n ne n x1 x2 Hx m y Hm Hv := by admit /- proof elided -/"
},
{
"name": "CMRA",
"content": "class CMRA (Ξ± : Type _) extends OFE Ξ± where\n pcore : Ξ± β Option Ξ±\n op : Ξ± β Ξ± β Ξ±\n ValidN : Nat β Ξ± β Prop\n Valid : Ξ± β Prop\n\n op_ne : NonExpansive (op x)\n pcore_ne : x β‘{n}β‘ y β pcore x = some cx β\n β cy, pcore y = some cy β§ cx β‘{n}β‘ cy\n validN_ne : x β‘{n}β‘ y β ValidN n x β ValidN n y\n\n valid_iff_validN : Valid x β β n, ValidN n x\n validN_succ : ValidN n.succ x β ValidN n x\n validN_op_left : ValidN n (op x y) β ValidN n x\n\n assoc : op x (op y z) β‘ op (op x y) z\n comm : op x y β‘ op y x\n\n pcore_op_left : pcore x = some cx β op cx x β‘ x\n pcore_idem : pcore x = some cx β pcore cx β‘ some cx\n pcore_op_mono : pcore x = some cx β β y, β cy, pcore (op x y) β‘ some (op cx cy)\n\n extend : ValidN n x β x β‘{n}β‘ op yβ yβ β\n Ξ£' zβ zβ, x β‘ op zβ zβ β§ zβ β‘{n}β‘ yβ β§ zβ β‘{n}β‘ yβ"
},
{
"name": "later_contractive",
"content": "instance later_contractive : OFE.Contractive UPred.later (Ξ± := UPred M) where\n distLater_dist {n x y} Hl :=\n match n with\n | 0 => by admit /- proof elided -/\n | n + 1 => fun\n | 0 => by admit /- proof elided -/\n | n' + 1 => fun x' Hn' Hx' => Hl _ Hn' _ _ (Nat.le_refl _) (CMRA.validN_succ Hx')"
},
{
"name": "later",
"content": "protected def later (P : UPred M) : UPred M where\n holds n x := match n with | 0 => True | Nat.succ n' => P n' x\n mono {nβ nβ} := by admit /- proof elided -/"
},
{
"name": "BIPlainly",
"content": "class BIPlainly (PROP : Type _) [Iris.BI PROP] extends Plainly PROP where\n [ne : Iris.OFE.NonExpansive (Plainly.plainly (PROP := PROP))]\n mono {P Q : PROP} : (P β’ Q) β β P β’ β Q\n elim_persistently {P : PROP} : β P β’ <pers> P\n idem {P : PROP} : β P β’ β β P\n plainly_sForall_2 {Ξ¦ : PROP β Prop} : (β p, βΞ¦ pβ β β p) β’ β sForall Ξ¦\n plainly_impl_plainly {P Q : PROP} : (β P β β Q) β’ β (β P β Q)\n emp_intro {P : PROP} : P β’ β emp\n plainly_absorb {P Q : PROP} : β P β Q β’ β P\n later_plainly {P : PROP} : β· β P β£β’ β β· P"
},
{
"name": "BIUpdate",
"content": "class BIUpdate (PROP : Type _) [BI PROP] extends BUpd PROP where\n [bupd_ne : OFE.NonExpansive (BUpd.bupd (PROP := PROP))]\n intro {P : PROP} : iprop(P β’ |==> P)\n mono {P Q : PROP} : iprop(P β’ Q) β iprop(|==> P β’ |==> Q)\n trans {P : PROP} : iprop(|==> |==> P β’ |==> P)\n frame_r {P R : PROP} : iprop((|==> P) β R β’ |==> (P β R))"
},
{
"name": "UPred",
"content": "@[ext]\nstructure UPred (M : Type _) [UCMRA M] where\n holds : Nat β M β Prop\n mono {n1 n2 x1 x2} : holds n1 x1 β x1 βΌ{n2} x2 β n2 β€ n1 β holds n2 x2"
},
{
"name": "IsModal",
"content": "class IsModal [BI PROP1] [BI PROP2] (M : PROP1 β PROP2)\n (iaction saction : ModalityAction PROP1 PROP2) where\n spec_intuitionistic : iaction.intuitionistic_action_spec M\n spec_spatial : saction.spatial_action_spec M\n emp : iprop(emp) β’ M iprop(emp)\n mono : β {P Q}, (P β’ Q) β M P β’ M Q\n sep : β {P Q}, iprop(M P β M Q) β’ M iprop(P β Q)"
},
{
"name": "UCMRA",
"content": "class UCMRA (Ξ± : Type _) extends CMRA Ξ± where\n unit : Ξ±\n unit_valid : β unit\n unit_left_id : unit β’ x β‘ x\n pcore_unit : pcore unit β‘ some unit"
},
{
"name": "pcore",
"content": "def pcore : DFrac F β Option (DFrac F)\n | own _ => none\n | .discard => some discard\n | ownDiscard _ => some discard"
},
{
"name": "DFrac",
"content": "inductive DFrac (F : Type _) where\n \n| own (f : F) : DFrac F\n \n| discard : DFrac F\n \n| ownDiscard (f : F) : DFrac F"
},
{
"name": "op",
"content": "def op : DFrac F β DFrac F β DFrac F\n | .discard, .discard => discard\n | own f, .discard\n | ownDiscard f, .discard\n | .discard, own f\n | .discard, ownDiscard f => ownDiscard f\n | own f, own f' => own (f + f')\n | own f, ownDiscard f'\n | ownDiscard f, own f'\n | ownDiscard f, ownDiscard f' => ownDiscard (f + f')"
},
{
"name": "Associative",
"content": "class Associative (R : Relation Ξ±) (f : Ξ± β Ξ± β Ξ±) where\n assoc {x y z : Ξ±} : R (f (f x y) z) (f x (f y z))"
},
{
"name": "Commutative",
"content": "class Commutative (R : Relation Ξ±) (f : Ξ² β Ξ² β Ξ±) where\n comm {x y : Ξ²} : R (f x y) (f y x)"
},
{
"name": "Included",
"content": "def Included (x y : Ξ±) : Prop := β z, y β‘ x β’ z"
},
{
"name": "instOFE",
"content": "instance instOFE [Store T K V] [OFE V] : OFE T where\n Equiv s0 s1 := get s0 β‘ get s1\n Dist n s0 s1 := get s0 β‘{n}β‘ get s1\n dist_eqv := β¨fun _ => .of_eq rfl, (Β·.symm), (Β·.trans Β·)β©\n equiv_dist := equiv_dist\n dist_lt := dist_lt"
},
{
"name": "Store.Equiv",
"content": "@[simp] def Store.Equiv [Store T K V] (t1 t2 : T) : Prop := get t1 = get t2"
},
{
"name": "Store.Equiv_trans",
"content": "instance Store.Equiv_trans [Store T K V] : Trans Equiv (Equiv (T := T)) Equiv := β¨by admit /- proof elided -/\nβ©"
},
{
"name": "[CMRA",
"content": "instance [CMRA Ξ²] : OFE (Ξ± -C> Ξ²) where\n Equiv f g := f.toHom β‘ g.toHom\n Dist n f g := f.toHom β‘{n}β‘ g.toHom\n dist_eqv := {\n refl _ := dist_eqv.refl _\n symm h := dist_eqv.symm h\n trans h1 h2 := dist_eqv.trans h1 h2\n }\n equiv_dist := equiv_dist\n dist_lt := dist_lt"
},
{
"name": "[Store",
"content": "instance [Store T1 K V1] [Store T2 K V2] [OFE V1] [OFE V2] (f : K β V1 β V2)\n [β k, NonExpansive (f k)] [HasStoreMap T1 T2 K V1 V2] : NonExpansive (dmap f : T1 β T2) where\n ne _ {_ _} H k := by admit /- proof elided -/"
},
{
"name": "[Heap",
"content": "instance [Heap T K V] [OFE V] (op : V β V β V) [NonExpansiveβ op] :\n NonExpansiveβ (merge (T := T) op) where\n ne _ {_ _} Ht {_ _} Hs k := by admit /- proof elided -/"
},
{
"name": "Heap.instCOFE",
"content": "instance Heap.instCOFE [Heap T K V] [COFE V] : COFE T where\n compl c := hmap (fun _ => COFE.compl <| c.map β¨_, Store.get_ne Β·β©) (c 0)\n conv_compl {_ c} k := by admit /- proof elided -/"
},
{
"name": "infix:60 \" β’ \" => op",
"content": "infix:60 \" β’ \" => op"
},
{
"name": "infix:50 \" βΌ \" => Included",
"content": "infix:50 \" βΌ \" => Included"
}
] | [
{
"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": "Iris.OFE",
"content": "class OFE (Ξ± : Type _) where\n Equiv : Ξ± β Ξ± β Prop\n Dist : Nat β Ξ± β Ξ± β Prop\n dist_eqv : Equivalence (Dist n)\n equiv_dist : Equiv x y β β n, Dist n x y\n dist_lt : Dist n x y β m < n β Dist m x y"
}
] | [
{
"name": "Iris.OFE.Dist.rfl",
"content": "@[simp, refl] theorem Dist.rfl [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ x"
},
{
"name": "Iris.OFE.Dist.symm",
"content": "@[symm] theorem Dist.symm [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ y β y β‘{n}β‘ x"
},
{
"name": "Iris.OFE.Dist.trans",
"content": "theorem Dist.trans [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ y β y β‘{n}β‘ z β x β‘{n}β‘ z"
}
] | namespace Iris
class OFE (Ξ± : Type _) where
Equiv : Ξ± β Ξ± β Prop
Dist : Nat β Ξ± β Ξ± β Prop
dist_eqv : Equivalence (Dist n)
equiv_dist : Equiv x y β β n, Dist n x y
dist_lt : Dist n x y β m < n β Dist m x y
open OFE
scoped infix:40 " β‘ " => OFE.Equiv
scoped notation:40 x " β‘{" n "}β‘ " y:41 => OFE.Dist n x y
namespace OFE | theorem equiv_eqv [ofe : OFE Ξ±] : Equivalence ofe.Equiv := | := by
constructor
Β· rintro x; rw [ofe.equiv_dist]; rintro n; exact Dist.rfl
Β· rintro x y; simp [ofe.equiv_dist]; rintro h n; exact Dist.symm (h n)
Β· rintro x y z; simp [ofe.equiv_dist]; rintro hβ hβ n; exact Dist.trans (hβ n) (hβ n) | 3 | 14 | false | Framework |
241 | Iris.BI.plainly_sep | theorem plainly_sep [BIPositive PROP] : β (P β Q) β£β’ β P β β Q | iris-lean | src/Iris/BI/Plainly.lean | [
"import Iris.Algebra",
"import src.Iris.BI.DerivedLaws",
"import src/Iris/Instances/UPred/Instance.lean",
"import Iris.BI.DerivedLaws",
"import Iris.BI.BI",
"import src.Iris.BI.BI",
"import Iris.BI.Classes"
] | [
{
"name": "Lean.MonadQuotation",
"module": "Init.Prelude"
},
{
"name": "Lean.MonadRef",
"module": "Init.Prelude"
},
{
"name": "Monad",
"module": "Init.Prelude"
},
{
"name": "m",
"module": "QqTest.matching"
},
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "Option.merge",
"module": "Init.Data.Option.Basic"
},
{
"name": "id",
"module": "Init.Prelude"
},
{
"name": "Equivalence",
"module": "Init.Core"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Bool",
"module": "Init.Prelude"
}
] | [
{
"name": "syntax term:26 \" ==β \" term:25 : term",
"content": "syntax term:26 \" ==β \" term:25 : term\n\nsyntax term \"={ \" term \" , \" term \" }=β \" term : term\n\nsyntax term \"={ \" term \" }=β \" term : term\n\nsyntax term \"={ \" term \" }[ \" term \" ]β·=β \" term : term\n\nsyntax term \"={ \" term \" }β·=β \" term : term\n\nsyntax term \"={ \" term \" }[ \" term \" ]β·^\" term \"=β \" term : term\n\nsyntax term \"={ \" term \" }β·^\" term \"=β \" term : term"
},
{
"name": "macro:max \"iprop(\" P:term \" : \" t:term \")\" : term => `((ipro",
"content": "macro:max \"iprop(\" P:term \" : \" t:term \")\" : term => `((iprop($P) : $t))\n\nsyntax:max \"iprop(\" term \")\" : term"
},
{
"name": "macro \"β\" xs:explicitBinders \", \" b:term : term => do",
"content": "macro \"β\" xs:explicitBinders \", \" b:term : term => do\n return β¨β expandExplicitBinders ``BIBase.exists xs bβ©"
},
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y\n\nsyntax:max \"<pers> \" term:40 : term"
},
{
"name": "macro:25 P:term:29 \" β’ \" Q:term:25 : term => ``(BIBase.Entai",
"content": "macro:25 P:term:29 \" β’ \" Q:term:25 : term => ``(BIBase.Entails iprop($P) iprop($Q))\n\ndelab_rule BIBase.Entails\n | `($_ $P $Q) => do ``($(β unpackIprop P) β’ $(β unpackIprop Q))"
},
{
"name": "macro:25 P:term:29 \" β£β’ \" Q:term:29 : term => ``(BiEntails i",
"content": "macro:25 P:term:29 \" β£β’ \" Q:term:29 : term => ``(BiEntails iprop($P) iprop($Q))\n\ndelab_rule BIBase.Entails\n | `($_ iprop(emp) $P) => do ``(β’ $(β unpackIprop P))\n\ndelab_rule BIBase.BiEntails\n | `($_ $P $Q) => do ``($(β unpackIprop P) β£β’ $(β unpackIprop Q))\n\nsyntax \"β\" term \"β\" : term\n\nsyntax:max \"β· \" term:40 : term\n\nsyntax \"β \" term:40 : term\n\nsyntax:max \"<affine> \" term:40 : term"
},
{
"name": "notation:50 x \" βΌ{\" n \"} \" y:51 => IncludedN n x y",
"content": "notation:50 x \" βΌ{\" n \"} \" y:51 => IncludedN n x y"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(|==> $P)) => ``(BUpd.bupd iprop($P))\n | `(iprop($P ==β $Q)) => ``(BIBase.wand iprop($P) (BUpd.bupd iprop($Q)))\n\ndelab_rule BUpd.bupd\n | `($_ $P) => do ``(iprop(|==> $(β Iris.BI.unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(|={ $E1 , $E2 }=> $P)) => ``(FUpd.fupd $E1 $E2 iprop($P))\n | `(iprop($P ={ $E1 , $E2 }=β $Q)) => ``(BIBase.wand iprop($P) (FUpd.fupd $E1 $E2 iprop($Q)))\n | `(iprop(|={ $E1 }=> $P)) => ``(FUpd.fupd $E1 $E1 iprop($P))\n | `(iprop($P ={ $E1 }=β $Q)) => ``(BIBase.wand iprop($P) (FUpd.fupd $E1 $E1 iprop($Q)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(|={ $E1 }[ $E2 ]β·=> $P)) => ``(iprop(|={$E1, $E2}=> β· (|={ $E2, $E1 }=> iprop($P))))\n | `(iprop($P ={ $E1 }[ $E2 ]β·=β $Q)) => ``(iprop(iprop($P) -β |={$E1}[$E2]β·=> iprop($Q)))\n | `(iprop(|={ $E1 }β·=> $P)) => ``(iprop(|={$E1}[$E1]β·=> iprop($P)))\n | `(iprop($P ={ $E1 }β·=β $Q)) => ``(iprop(iprop($P) ={$E1}[$E1]β·=β iprop($Q)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(|={ $E1 }[ $E2 ]β·^$n=> $P)) => ``(iprop(|={$E1, $E2}=> β·^[$n] (|={ $E2, $E1 }=> iprop($P))))\n | `(iprop($P ={ $E1 }[ $E2 ]β·^$n=β $Q)) => ``(iprop(iprop($P) -β |={$E1}[$E2]β·^$n=> iprop($Q)))\n | `(iprop(|={ $E1 }β·^$n=> $P)) => ``(iprop(|={$E1}[$E1]β·^$n=> iprop($P)))\n | `(iprop($P ={ $E1 }β·^$n=β $Q)) => ``(iprop(iprop($P) ={$E1}[$E1]β·^$n=β iprop($Q)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(emp)) => ``(BIBase.emp)\n | `(iprop(β$Οβ)) => ``(BIBase.pure $Ο)\n | `(iprop($P β§ $Q)) => ``(BIBase.and iprop($P) iprop($Q))\n | `(iprop($P β¨ $Q)) => ``(BIBase.or iprop($P) iprop($Q))\n | `(iprop($P β $Q)) => ``(BIBase.imp iprop($P) iprop($Q))\n | `(iprop(β $xs, $Ξ¨)) => do expandExplicitBinders ``BIBase.exists xs (β ``(iprop($Ξ¨)))\n | `(iprop($P β $Q)) => ``(BIBase.sep iprop($P) iprop($Q))\n | `(iprop($P -β $Q)) => ``(BIBase.wand iprop($P) iprop($Q))\n | `(iprop(<pers> $P)) => ``(BIBase.persistently iprop($P))\n | `(iprop(β· $P)) => ``(BIBase.later iprop($P))\n\ndelab_rule BIBase.emp\n | `($_) => ``(iprop($(mkIdent `emp)))\ndelab_rule BIBase.pure\n | `($_ $Ο) => ``(iprop(β$Οβ))\ndelab_rule BIBase.and\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β§ $(β unpackIprop Q)))\ndelab_rule BIBase.or\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β¨ $(β unpackIprop Q)))\ndelab_rule BIBase.imp\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule BIBase.forall\n | `($_ fun $x:ident => iprop(β $y:ident $[$z:ident]*, $Ξ¨)) => do\n ``(iprop(β $x:ident $y:ident $[$z:ident]*, $Ξ¨))\n | `($_ fun $x:ident => $Ξ¨) => do ``(iprop(β $x:ident, $(β unpackIprop Ξ¨)))\ndelab_rule BIBase.exists\n | `($_ fun $x:ident => iprop(β $y:ident $[$z:ident]*, $Ξ¨)) => do\n ``(iprop(β $x:ident $y:ident $[$z:ident]*, $Ξ¨))\n | `($_ fun $x:ident => $Ξ¨) => do ``(iprop(β $x:ident, $(β unpackIprop Ξ¨)))\ndelab_rule BIBase.sep\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule BIBase.wand\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) -β $(β unpackIprop Q)))\ndelab_rule BIBase.persistently\n | `($_ $P) => do ``(iprop(<pers> $(β unpackIprop P)))\n\ndelab_rule BIBase.pure\n | `($_ True) => ``(iprop($(mkIdent `True)))\n | `($_ False) => ``(iprop($(mkIdent `False)))\ndelab_rule BIBase.imp\n | `($_ $P iprop(False)) => do ``(iprop(Β¬$(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β _%$tk, $Ξ¨)) => ``(BIBase.forall (fun _%$tk => iprop($Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $x:ident, $Ξ¨)) => ``(BIBase.forall (fun $x => iprop($Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β (_%$tk : $t), $Ξ¨)) => ``(BIBase.forall (fun (_%$tk : $t) => iprop($Ξ¨)))\n | `(iprop(β (_%$tk $xs* : $t), $Ξ¨)) =>\n ``(BIBase.forall (fun (_%$tk : $t) => iprop(β ($xs* : $t), $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β ($x:ident : $t), $Ξ¨)) => ``(BIBase.forall (fun ($x : $t) => iprop($Ξ¨)))\n | `(iprop(β ($x:ident $xs* : $t), $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop(β ($xs* : $t), $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β {_%$tk : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun {_%$tk : $t} => iprop($Ξ¨)))\n | `(iprop(β {_%$tk $xs* : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun {_%$tk : $t} => iprop(β {$xs* : $t}, $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β {$x:ident : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop($Ξ¨)))\n | `(iprop(β {$x:ident $xs* : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop(β {$xs* : $t}, $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $x $y $xs*, $Ξ¨)) => ``(iprop(β $x, β $y $xs*, $Ξ¨))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(True)) => ``(BIBase.pure True)\n | `(iprop(False)) => ``(BIBase.pure False)\n | `(iprop(Β¬$P)) => ``(iprop($P β False))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop($P β $Q)) => ``(iff iprop($P) iprop($Q))\n | `(iprop($P β-β $Q)) => ``(wandIff iprop($P) iprop($Q))\n\ndelab_rule iff\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule wandIff\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β-β $(β unpackIprop Q)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(<affine> $P)) => ``(affinely iprop($P))\n | `(iprop(<absorb> $P)) => ``(absorbingly iprop($P))\n\ndelab_rule affinely\n | `($_ $P) => do ``(iprop(<affine> $(β unpackIprop P)))\ndelab_rule absorbingly\n | `($_ $P) => do ``(iprop(<absorb> $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β‘ $P)) => ``(intuitionistically iprop($P))\n\ndelab_rule intuitionistically\n | `($_ $P) => do ``(iprop(β‘ $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(<pers>?$p $P)) => ``(persistentlyIf $p iprop($P))\n | `(iprop(<affine>?$p $P)) => ``(affinelyIf $p iprop($P))\n | `(iprop(<absorb>?$p $P)) => ``(absorbinglyIf $p iprop($P))\n | `(iprop(β‘?$p $P)) => ``(intuitionisticallyIf $p iprop($P))\n\ndelab_rule persistentlyIf\n | `($_ $p $P) => do ``(iprop(<pers>?$p $(β unpackIprop P)))\ndelab_rule affinelyIf\n | `($_ $p $P) => do ``(iprop(<affine>?$p $(β unpackIprop P)))\ndelab_rule absorbinglyIf\n | `($_ $p $P) => do ``(iprop(<absorb>?$p $(β unpackIprop P)))\ndelab_rule intuitionisticallyIf\n | `($_ $p $P) => do ``(iprop(β‘?$p $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β·^[$n] $P)) => ``(laterN $n iprop($P))\n\ndelab_rule laterN\n | `($_ $n $P) => do ``(iprop(β·^[$n] $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $P)) => ``(except0 iprop($P))\n\ndelab_rule except0\n | `($_ $P) => do ``(iprop(β $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $P)) => ``(Plainly.plainly iprop($P))\n\ndelab_rule Plainly.plainly\n | `($_ $P) => do ``(iprop(β $(β Iris.BI.unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β ? $p $P)) => ``(Plainly.plainlyIf $p iprop($P))\n\ndelab_rule Plainly.plainlyIf\n | `($_ $p $P) => do ``(iprop(β ? $p $(β Iris.BI.unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(term($t))) => pure t\n | `(iprop($t)) => pure t"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(($P))) => ``((iprop($P)))\n | `(iprop(if $c then $t else $e)) => ``(if $c then iprop($t) else iprop($e))\n | `(iprop(($P : $t))) => ``((iprop($P) : $t))"
},
{
"name": "unpackIprop",
"content": "partial def unpackIprop [Monad m] [MonadRef m] [MonadQuotation m] : Term β m Term\n | `(iprop($P)) => do `($P)\n | `($P:ident) => do `($P)\n | `(?$P:ident) => do `(?$P)\n | `(($P)) => do `(($(β unpackIprop P)))\n | `($P $[ $Q]*) => do ``($P $[ $Q]*)\n | `(if $c then $t else $e) => do\n let t β unpackIprop t\n let e β unpackIprop e\n `(if $c then $t else $e)\n | `(($P : $t)) => do ``(($(β unpackIprop P) : $t))\n | `($t) => `($t:term)"
},
{
"name": "BIBase",
"content": "class BIBase (PROP : Type u) where\n Entails : PROP β PROP β Prop\n emp : PROP\n pure : Prop β PROP\n and : PROP β PROP β PROP\n or : PROP β PROP β PROP\n imp : PROP β PROP β PROP\n sForall : (PROP β Prop) β PROP\n sExists : (PROP β Prop) β PROP\n sep : PROP β PROP β PROP\n wand : PROP β PROP β PROP\n persistently : PROP β PROP\n later : PROP β PROP"
},
{
"name": "BI",
"content": "class BI (PROP : Type _) extends COFE PROP, BI.BIBase PROP where\n Equiv P Q := P β£β’ Q\n\n entails_preorder : Preorder Entails\n equiv_iff {P Q : PROP} : (P β‘ Q) β P β£β’ Q := by admit /- proof elided -/"
},
{
"name": "liftRel",
"content": "def liftRel (R : Ξ± β Ξ² β Prop) (A : Ξ± β Prop) (B : Ξ² β Prop) : Prop :=\n (β a, A a β β b, B b β§ R a b) β§ (β b, B b β β a, A a β§ R a b)"
},
{
"name": "Preorder",
"content": "class Preorder (R : Relation Ξ±) extends Reflexive R, Transitive R"
},
{
"name": "Reflexive",
"content": "class Reflexive (R : Relation Ξ±) where\n refl {x : Ξ±} : R x x"
},
{
"name": "Relation",
"content": "abbrev Relation (Ξ± : Type _) := Ξ± β Ξ± β Prop"
},
{
"name": "Transitive",
"content": "class Transitive (R : Relation Ξ±) where\n trans {x y z : Ξ±} : R x y β R y z β R x z"
},
{
"name": "NonExpansiveβ",
"content": "class NonExpansiveβ [OFE Ξ±] [OFE Ξ²] [OFE Ξ³] (f : Ξ± β Ξ² β Ξ³) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β β β¦yβ yββ¦, yβ β‘{n}β‘ yβ β f xβ yβ β‘{n}β‘ f xβ yβ"
},
{
"name": "OFE.ContractiveHom.fixpoint_ne",
"content": "instance OFE.ContractiveHom.fixpoint_ne [COFE Ξ±] [Inhabited Ξ±] :\n NonExpansive (ContractiveHom.fixpoint (Ξ± := Ξ±)) where\n ne n f1 f2 H := by admit /- proof elided -/"
},
{
"name": "ContractiveHom",
"content": "@[ext] structure ContractiveHom (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] extends Hom Ξ± Ξ² where\n [contractive : Contractive f]\n ne := ne_of_contractive f"
},
{
"name": "OFE.Option.some.ne",
"content": "instance OFE.Option.some.ne [OFE Ξ±] : OFE.NonExpansive (some : Ξ± β Option Ξ±) := β¨fun _ _ _ => idβ©"
},
{
"name": "Option.merge_ne",
"content": "instance Option.merge_ne [OFE Ξ±] {op : Ξ± β Ξ± β Ξ±} [NonExpansiveβ op] :\n NonExpansiveβ (Option.merge op) where\n ne n x1 x2 Hx y1 y2 Hy := by admit /- proof elided -/"
},
{
"name": "NonExpansive",
"content": "class NonExpansive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β f xβ β‘{n}β‘ f xβ"
},
{
"name": "COFE.OFunctor.constOF_RFunctor",
"content": "instance COFE.OFunctor.constOF_RFunctor [CMRA B] : RFunctor (constOF B) where\n map f g := by admit /- proof elided -/"
},
{
"name": "IsCOFE",
"content": "class IsCOFE (Ξ± : Type _) [OFE Ξ±] where\n compl : Chain Ξ± β Ξ±\n conv_compl {c : Chain Ξ±} : compl c β‘{n}β‘ c n"
},
{
"name": "Chain",
"content": "structure Chain (Ξ± : Type _) [OFE Ξ±] where\n chain : Nat β Ξ±\n cauchy : n β€ i β chain i β‘{n}β‘ chain n"
},
{
"name": "BIPositive",
"content": "class BIPositive (PROP : Type _) [BI PROP] where\n affinely_sep_l {P Q : PROP} : <affine> (P β Q) β’ <affine> P β Q"
},
{
"name": "Affine",
"content": "class Affine [BI PROP] (P : PROP) where\n affine : P β’ emp"
},
{
"name": "Idempotent",
"content": "class Idempotent (R : Relation Ξ±) (f : Ξ± β Ξ± β Ξ±) where\n idem {x : Ξ±} : R (f x x) x"
},
{
"name": "LawfulBigOp",
"content": "class LawfulBigOp (f : PROP β PROP β PROP) (unit : outParam PROP)\n (eq : outParam (PROP β PROP β Prop)) where\n refl : eq a a\n symm : eq a b β eq b a\n trans : eq a b β eq b c β eq a c\n comm : eq (f a b) (f b a)\n assoc : eq (f (f a b) c) (f a (f b c))\n left_id : eq (f unit a) a\n congr_l : eq a a' β eq (f a b) (f a' b)"
},
{
"name": "",
"content": "instance : BIPlainly (UPred M) where\n mono H _ _ _ := H _ _ CMRA.unit_validN\n elim_persistently {P} n x Hx := by admit /- proof elided -/"
},
{
"name": "persistently",
"content": "protected def persistently (P : UPred M) : UPred M where\n holds n x := P n (CMRA.core x)\n mono H Hx Hn := P.mono H (CMRA.core_incN_core Hx) Hn"
},
{
"name": "BIUpdate",
"content": "class BIUpdate (PROP : Type _) [BI PROP] extends BUpd PROP where\n [bupd_ne : OFE.NonExpansive (BUpd.bupd (PROP := PROP))]\n intro {P : PROP} : iprop(P β’ |==> P)\n mono {P Q : PROP} : iprop(P β’ Q) β iprop(|==> P β’ |==> Q)\n trans {P : PROP} : iprop(|==> |==> P β’ |==> P)\n frame_r {P R : PROP} : iprop((|==> P) β R β’ |==> (P β R))"
},
{
"name": "UPred",
"content": "@[ext]\nstructure UPred (M : Type _) [UCMRA M] where\n holds : Nat β M β Prop\n mono {n1 n2 x1 x2} : holds n1 x1 β x1 βΌ{n2} x2 β n2 β€ n1 β holds n2 x2"
},
{
"name": "IsModal",
"content": "class IsModal [BI PROP1] [BI PROP2] (M : PROP1 β PROP2)\n (iaction saction : ModalityAction PROP1 PROP2) where\n spec_intuitionistic : iaction.intuitionistic_action_spec M\n spec_spatial : saction.spatial_action_spec M\n emp : iprop(emp) β’ M iprop(emp)\n mono : β {P Q}, (P β’ Q) β M P β’ M Q\n sep : β {P Q}, iprop(M P β M Q) β’ M iprop(P β Q)"
},
{
"name": "core",
"content": "def core (x : Ξ±) := (pcore x).getD x"
},
{
"name": "CMRA",
"content": "class CMRA (Ξ± : Type _) extends OFE Ξ± where\n pcore : Ξ± β Option Ξ±\n op : Ξ± β Ξ± β Ξ±\n ValidN : Nat β Ξ± β Prop\n Valid : Ξ± β Prop\n\n op_ne : NonExpansive (op x)\n pcore_ne : x β‘{n}β‘ y β pcore x = some cx β\n β cy, pcore y = some cy β§ cx β‘{n}β‘ cy\n validN_ne : x β‘{n}β‘ y β ValidN n x β ValidN n y\n\n valid_iff_validN : Valid x β β n, ValidN n x\n validN_succ : ValidN n.succ x β ValidN n x\n validN_op_left : ValidN n (op x y) β ValidN n x\n\n assoc : op x (op y z) β‘ op (op x y) z\n comm : op x y β‘ op y x\n\n pcore_op_left : pcore x = some cx β op cx x β‘ x\n pcore_idem : pcore x = some cx β pcore cx β‘ some cx\n pcore_op_mono : pcore x = some cx β β y, β cy, pcore (op x y) β‘ some (op cx cy)\n\n extend : ValidN n x β x β‘{n}β‘ op yβ yβ β\n Ξ£' zβ zβ, x β‘ op zβ zβ β§ zβ β‘{n}β‘ yβ β§ zβ β‘{n}β‘ yβ"
},
{
"name": "UCMRA",
"content": "class UCMRA (Ξ± : Type _) extends CMRA Ξ± where\n unit : Ξ±\n unit_valid : β unit\n unit_left_id : unit β’ x β‘ x\n pcore_unit : pcore unit β‘ some unit"
},
{
"name": "pcore",
"content": "def pcore : DFrac F β Option (DFrac F)\n | own _ => none\n | .discard => some discard\n | ownDiscard _ => some discard"
},
{
"name": "DFrac",
"content": "inductive DFrac (F : Type _) where\n \n| own (f : F) : DFrac F\n \n| discard : DFrac F\n \n| ownDiscard (f : F) : DFrac F"
},
{
"name": "op",
"content": "def op : DFrac F β DFrac F β DFrac F\n | .discard, .discard => discard\n | own f, .discard\n | ownDiscard f, .discard\n | .discard, own f\n | .discard, ownDiscard f => ownDiscard f\n | own f, own f' => own (f + f')\n | own f, ownDiscard f'\n | ownDiscard f, own f'\n | ownDiscard f, ownDiscard f' => ownDiscard (f + f')"
},
{
"name": "Associative",
"content": "class Associative (R : Relation Ξ±) (f : Ξ± β Ξ± β Ξ±) where\n assoc {x y z : Ξ±} : R (f (f x y) z) (f x (f y z))"
},
{
"name": "Commutative",
"content": "class Commutative (R : Relation Ξ±) (f : Ξ² β Ξ² β Ξ±) where\n comm {x y : Ξ²} : R (f x y) (f y x)"
},
{
"name": "Included",
"content": "def Included (x y : Ξ±) : Prop := β z, y β‘ x β’ z"
},
{
"name": "plainly",
"content": "protected def plainly (P : UPred M) : UPred M where\n holds n _ := P n UCMRA.unit\n mono H _ Hn := P.mono H (CMRA.incN_refl UCMRA.unit) Hn"
},
{
"name": "BIPlainly",
"content": "class BIPlainly (PROP : Type _) [Iris.BI PROP] extends Plainly PROP where\n [ne : Iris.OFE.NonExpansive (Plainly.plainly (PROP := PROP))]\n mono {P Q : PROP} : (P β’ Q) β β P β’ β Q\n elim_persistently {P : PROP} : β P β’ <pers> P\n idem {P : PROP} : β P β’ β β P\n plainly_sForall_2 {Ξ¦ : PROP β Prop} : (β p, βΞ¦ pβ β β p) β’ β sForall Ξ¦\n plainly_impl_plainly {P Q : PROP} : (β P β β Q) β’ β (β P β Q)\n emp_intro {P : PROP} : P β’ β emp\n plainly_absorb {P Q : PROP} : β P β Q β’ β P\n later_plainly {P : PROP} : β· β P β£β’ β β· P"
},
{
"name": "",
"content": "instance : BIPlainlyExists (UPred M) where\n plainly_sExists_1 _ _ _ := fun β¨_, hpβ© => β¨_, β¨_, rflβ©, hpβ©"
},
{
"name": "BIPlainlyExists",
"content": "class BIPlainlyExists (PROP : Type _) [Iris.BI PROP] [BIPlainly PROP] where\n plainly_sExists_1 {Ξ¦ : PROP β Prop} : β sExists Ξ¦ β’ β p, βΞ¦ pβ β§ β p"
},
{
"name": "",
"content": "instance : Plainly (UPred M) := β¨UPred.plainlyβ©"
},
{
"name": "scoped infix:40 \" β‘ \" => OFE.Equiv",
"content": "scoped infix:40 \" β‘ \" => OFE.Equiv"
},
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y"
},
{
"name": "infixr:25 \" -c> \" => ContractiveHom",
"content": "infixr:25 \" -c> \" => ContractiveHom"
},
{
"name": "infix:60 \" β’ \" => op",
"content": "infix:60 \" β’ \" => op"
},
{
"name": "infix:50 \" βΌ \" => Included",
"content": "infix:50 \" βΌ \" => Included"
}
] | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "persistently_and_sep_assoc",
"content": "theorem persistently_and_sep_assoc [BI PROP] {P Q R : PROP} :\n <pers> P β§ (Q β R) β£β’ (<pers> P β§ Q) β R"
},
{
"name": "and_mono_l",
"content": "theorem and_mono_l [BI PROP] {P P' Q : PROP} (h : P β’ P') : P β§ Q β’ P' β§ Q"
},
{
"name": "and_mono",
"content": "@[rw_mono_rule]\ntheorem and_mono [BI PROP] {P P' Q Q' : PROP} (h1 : P β’ Q) (h2 : P' β’ Q') : P β§ P' β’ Q β§ Q'"
},
{
"name": "and_elim_r'",
"content": "theorem and_elim_r' [BI PROP] {P Q R : PROP} (h : Q β’ R) : P β§ Q β’ R"
},
{
"name": "and_elim_l'",
"content": "theorem and_elim_l' [BI PROP] {P Q R : PROP} (h : P β’ R) : P β§ Q β’ R"
},
{
"name": "sep_assoc",
"content": "theorem sep_assoc [BI PROP] {P Q R : PROP} : (P β Q) β R β£β’ P β Q β R"
},
{
"name": "sep_congr_l",
"content": "theorem sep_congr_l [BI PROP] {P P' Q : PROP} (h : P β£β’ P') : P β Q β£β’ P' β Q"
},
{
"name": "sep_congr",
"content": "@[rw_mono_rule]\ntheorem sep_congr [BI PROP] {P P' Q Q' : PROP} (h1 : P β£β’ Q) (h2 : P' β£β’ Q') :\n (P β P') β£β’ (Q β Q')"
},
{
"name": "sep_congr_r",
"content": "theorem sep_congr_r [BI PROP] {P Q Q' : PROP} (h : Q β£β’ Q') : P β Q β£β’ P β Q'"
},
{
"name": "sep_mono_l",
"content": "theorem sep_mono_l [BI PROP] {P P' Q : PROP} (h : P β’ P') : P β Q β’ P' β Q"
},
{
"name": "BIBase.Entails.rfl",
"content": "@[simp] theorem BIBase.Entails.rfl [BI PROP] {P : PROP} : P β’ P"
},
{
"name": "imp_intro'",
"content": "theorem imp_intro' [BI PROP] {P Q R : PROP} (h : Q β§ P β’ R) : P β’ Q β R"
},
{
"name": "and_comm",
"content": "theorem and_comm [BI PROP] {P Q : PROP} : P β§ Q β£β’ Q β§ P"
},
{
"name": "and_symm",
"content": "theorem and_symm [BI PROP] {P Q : PROP} : P β§ Q β’ Q β§ P"
},
{
"name": "imp_elim'",
"content": "theorem imp_elim' [BI PROP] {P Q R : PROP} (h : Q β’ P β R) : P β§ Q β’ R"
},
{
"name": "pure_elim",
"content": "theorem pure_elim [BI PROP] (Ο : Prop) {Q R : PROP} (h1 : Q β’ βΟβ) (h2 : Ο β Q β’ R) : Q β’ R"
},
{
"name": "and_self",
"content": "theorem and_self [BI PROP] {P : PROP} : P β§ P β£β’ P"
},
{
"name": "forall_intro",
"content": "theorem forall_intro [BI PROP] {P : PROP} {Ξ¨ : Ξ± β PROP} (h : β a, P β’ Ξ¨ a) : P β’ β a, Ξ¨ a"
},
{
"name": "forall_elim",
"content": "theorem forall_elim [BI PROP] {Ξ¨ : Ξ± β PROP} (a : Ξ±) : (β a, Ξ¨ a) β’ Ξ¨ a"
},
{
"name": "forall_mono",
"content": "@[rw_mono_rule]\ntheorem forall_mono [BI PROP] {Ξ¦ Ξ¨ : Ξ± β PROP} (h : β a, Ξ¦ a β’ Ξ¨ a) : (β a, Ξ¦ a) β’ β a, Ξ¨ a"
},
{
"name": "and_forall_bool",
"content": "theorem and_forall_bool [BI PROP] {P Q : PROP} :\n P β§ Q β£β’ Β«forallΒ» (fun b : Bool => if b then P else Q)"
},
{
"name": "persistently_and_emp_elim",
"content": "theorem persistently_and_emp_elim {P : PROP} [BI PROP] : emp β§ <pers> P β’ P"
},
{
"name": "sep_emp",
"content": "theorem sep_emp [BI PROP] {P : PROP} : P β emp β£β’ P"
},
{
"name": "affinely_elim_emp",
"content": "theorem affinely_elim_emp [BI PROP] {P : PROP} : <affine> P β’ emp"
},
{
"name": "affinely_sep",
"content": "theorem affinely_sep [BI PROP] [BIPositive PROP] {P Q : PROP} :\n <affine> (P β Q) β£β’ <affine> P β <affine> Q"
},
{
"name": "affinely_idem",
"content": "theorem affinely_idem [BI PROP] {P : PROP} : <affine> <affine> P β£β’ <affine> P"
},
{
"name": "and_assoc",
"content": "theorem and_assoc [BI PROP] {P Q R : PROP} : (P β§ Q) β§ R β£β’ P β§ Q β§ R"
},
{
"name": "and_mono_r",
"content": "theorem and_mono_r [BI PROP] {P Q Q' : PROP} (h : Q β’ Q') : P β§ Q β’ P β§ Q'"
},
{
"name": "and_congr_l",
"content": "theorem and_congr_l [BI PROP] {P P' Q : PROP} (h : P β£β’ P') : P β§ Q β£β’ P' β§ Q"
},
{
"name": "and_congr",
"content": "@[rw_mono_rule]\ntheorem and_congr [BI PROP] {P P' Q Q' : PROP} (h1 : P β£β’ Q) (h2 : P' β£β’ Q') : P β§ P' β£β’ Q β§ Q'"
},
{
"name": "affinely_mono",
"content": "@[rw_mono_rule]\ntheorem affinely_mono [BI PROP] {P Q : PROP} : (P β’ Q) β <affine> P β’ <affine> Q"
},
{
"name": "affinely_sep_2",
"content": "theorem affinely_sep_2 [BI PROP] {P Q : PROP} : <affine> P β <affine> Q β’ <affine> (P β Q)"
},
{
"name": "affinely_elim",
"content": "theorem affinely_elim [BI PROP] {P : PROP} : <affine> P β’ P"
},
{
"name": "affinely_sep_r",
"content": "theorem affinely_sep_r [BI PROP] [BIPositive PROP] {P Q : PROP} :\n <affine> (P β Q) β’ P β <affine> Q"
}
] | [
{
"name": "Iris.Plainly",
"content": "class Plainly (PROP : Type _) where\n plainly : PROP β PROP"
},
{
"name": "Iris.Plainly.plainlyIf",
"content": "def Plainly.plainlyIf [Iris.BI.BIBase PROP] [Plainly PROP] (p : Bool) (P : PROP) : PROP :=\n iprop(if p then β P else P)"
},
{
"name": "Iris.BIPlainly",
"content": "class BIPlainly (PROP : Type _) [Iris.BI PROP] extends Plainly PROP where\n [ne : Iris.OFE.NonExpansive (Plainly.plainly (PROP := PROP))]\n mono {P Q : PROP} : (P β’ Q) β β P β’ β Q\n elim_persistently {P : PROP} : β P β’ <pers> P\n idem {P : PROP} : β P β’ β β P\n plainly_sForall_2 {Ξ¦ : PROP β Prop} : (β p, βΞ¦ pβ β β p) β’ β sForall Ξ¦\n plainly_impl_plainly {P Q : PROP} : (β P β β Q) β’ β (β P β Q)\n emp_intro {P : PROP} : P β’ β emp\n plainly_absorb {P Q : PROP} : β P β Q β’ β P\n later_plainly {P : PROP} : β· β P β£β’ β β· P"
},
{
"name": "Iris.BIPlainlyExists",
"content": "class BIPlainlyExists (PROP : Type _) [Iris.BI PROP] [BIPlainly PROP] where\n plainly_sExists_1 {Ξ¦ : PROP β Prop} : β sExists Ξ¦ β’ β p, βΞ¦ pβ β§ β p"
}
] | [
{
"name": "Iris.BI.persistently_elim_plainly",
"content": "theorem persistently_elim_plainly : <pers> β P β£β’ β P"
},
{
"name": "Iris.BI.plainly_forall_2",
"content": "theorem plainly_forall_2 {Ξ¨ : Ξ± β PROP} : (β a, β (Ξ¨ a)) β’ β (β a, Ξ¨ a)"
},
{
"name": "Iris.BI.plainly_and_sep_assoc",
"content": "theorem plainly_and_sep_assoc : β P β§ (Q β R) β£β’ (β P β§ Q) β R"
},
{
"name": "Iris.BI.plainly_and_emp_elim",
"content": "theorem plainly_and_emp_elim : emp β§ β P β’ P"
},
{
"name": "Iris.BI.plainly_forall",
"content": "theorem plainly_forall {Ξ¨ : Ξ± β PROP} : β (β a, Ξ¨ a) β£β’ β a, β (Ξ¨ a)"
},
{
"name": "Iris.BI.plainly_and",
"content": "theorem plainly_and : β (P β§ Q) β£β’ β P β§ β Q"
},
{
"name": "Iris.BI.plainly_and_sep_l_1",
"content": "theorem plainly_and_sep_l_1 : β P β§ Q β’ β P β Q"
},
{
"name": "Iris.BI.plainly_and_sep",
"content": "theorem plainly_and_sep : β (P β§ Q) β’ β (P β Q)"
},
{
"name": "Iris.BI.and_sep_plainly",
"content": "theorem and_sep_plainly : β P β§ β Q β£β’ β P β β Q"
},
{
"name": "Iris.BI.plainly_sep_2",
"content": "theorem plainly_sep_2 : β P β β Q β’ β (P β Q)"
}
] | import Iris.BI.Classes
import Iris.BI.BI
import Iris.BI.DerivedLaws
import Iris.Algebra
namespace Iris
open BI
class Plainly (PROP : Type _) where
plainly : PROP β PROP
def Plainly.plainlyIf [Iris.BI.BIBase PROP] [Plainly PROP] (p : Bool) (P : PROP) : PROP :=
iprop(if p then β P else P)
class BIPlainly (PROP : Type _) [Iris.BI PROP] extends Plainly PROP where
[ne : Iris.OFE.NonExpansive (Plainly.plainly (PROP := PROP))]
mono {P Q : PROP} : (P β’ Q) β β P β’ β Q
elim_persistently {P : PROP} : β P β’ <pers> P
idem {P : PROP} : β P β’ β β P
plainly_sForall_2 {Ξ¦ : PROP β Prop} : (β p, βΞ¦ pβ β β p) β’ β sForall Ξ¦
plainly_impl_plainly {P Q : PROP} : (β P β β Q) β’ β (β P β Q)
emp_intro {P : PROP} : P β’ β emp
plainly_absorb {P Q : PROP} : β P β Q β’ β P
later_plainly {P : PROP} : β· β P β£β’ β β· P
class BIPlainlyExists (PROP : Type _) [Iris.BI PROP] [BIPlainly PROP] where
plainly_sExists_1 {Ξ¦ : PROP β Prop} : β sExists Ξ¦ β’ β p, βΞ¦ pβ β§ β p
namespace BI
open Iris.Std
section PlainlyLaws
open BIPlainly
variable [BI PROP] [BIPlainly PROP]
variable {P Q R : PROP} | theorem plainly_sep [BIPositive PROP] : β (P β Q) β£β’ β P β β Q := | := by
refine β¨?_, plainly_sep_2β©
refine plainly_affinely_elim.mpr.trans ?_
refine (mono <| affinely_sep.mp).trans ?_
refine .trans ?_ and_sep_plainly.mp
refine and_intro (mono ?_) (mono ?_)
Β· exact ((sep_mono .rfl affinely_elim_emp).trans sep_emp.mp).trans affinely_elim
Β· exact ((sep_mono affinely_elim_emp .rfl).trans emp_sep.mp).trans affinely_elim | 7 | 72 | false | Framework |
242 | Iris.Agree.toAgree_uninj | theorem Agree.toAgree_uninj {x : Agree Ξ±} : β x β β a, toAgree a β‘ x | iris-lean | src/Iris/Algebra/Agree.lean | [
"import Iris.Algebra.CMRA",
"import src.Iris.Algebra.CMRA",
"import src.Iris.Algebra.OFE",
"import Iris.Algebra.OFE"
] | [
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "Option.merge",
"module": "Init.Data.Option.Basic"
},
{
"name": "id",
"module": "Init.Prelude"
},
{
"name": "Equivalence",
"module": "Init.Core"
},
{
"name": "m",
"module": "QqTest.matching"
}
] | [
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y"
},
{
"name": "notation:50 \"β{\" n \"} \" x:51 => ValidN n x",
"content": "notation:50 \"β{\" n \"} \" x:51 => ValidN n x"
},
{
"name": "notation:50 x \" βΌ{\" n \"} \" y:51 => IncludedN n x y",
"content": "notation:50 x \" βΌ{\" n \"} \" y:51 => IncludedN n x y"
},
{
"name": "OFE.ContractiveHom.fixpoint_ne",
"content": "instance OFE.ContractiveHom.fixpoint_ne [COFE Ξ±] [Inhabited Ξ±] :\n NonExpansive (ContractiveHom.fixpoint (Ξ± := Ξ±)) where\n ne n f1 f2 H := by admit /- proof elided -/"
},
{
"name": "valid",
"content": "def valid : DFrac F β Prop\n | .own f => Proper f\n | .discard => True\n | .ownDiscard f => Fractional f"
},
{
"name": "DFrac",
"content": "inductive DFrac (F : Type _) where\n \n| own (f : F) : DFrac F\n \n| discard : DFrac F\n \n| ownDiscard (f : F) : DFrac F"
},
{
"name": "Fractional",
"content": "def Fractional [Fraction Ξ±] (a : Ξ±) : Prop := β b, Proper (a + b)"
},
{
"name": "Fraction",
"content": "class Fraction (Ξ± : Type _) extends Add Ξ± where\n \n Proper : Ξ± β Prop\n add_comm : β a b : Ξ±, a + b = b + a\n add_assoc : β a b c : Ξ±, a + (b + c) = (a + b) + c\n add_left_cancel : β {a b c : Ξ±}, a + b = a + c β b = c\n \n add_ne : β {a b : Ξ±}, a β b + a\n proper_add_mono_left : β {a b : Ξ±}, Proper (a + b) β Proper a"
},
{
"name": "Agree",
"content": "@[ext]\nstructure Agree where\n car : List Ξ±\n not_nil : car β []"
},
{
"name": "LeibnizO",
"content": "@[ext] structure LeibnizO (Ξ± : Type _) where\n car : Ξ±"
},
{
"name": "CMRA",
"content": "class CMRA (Ξ± : Type _) extends OFE Ξ± where\n pcore : Ξ± β Option Ξ±\n op : Ξ± β Ξ± β Ξ±\n ValidN : Nat β Ξ± β Prop\n Valid : Ξ± β Prop\n\n op_ne : NonExpansive (op x)\n pcore_ne : x β‘{n}β‘ y β pcore x = some cx β\n β cy, pcore y = some cy β§ cx β‘{n}β‘ cy\n validN_ne : x β‘{n}β‘ y β ValidN n x β ValidN n y\n\n valid_iff_validN : Valid x β β n, ValidN n x\n validN_succ : ValidN n.succ x β ValidN n x\n validN_op_left : ValidN n (op x y) β ValidN n x\n\n assoc : op x (op y z) β‘ op (op x y) z\n comm : op x y β‘ op y x\n\n pcore_op_left : pcore x = some cx β op cx x β‘ x\n pcore_idem : pcore x = some cx β pcore cx β‘ some cx\n pcore_op_mono : pcore x = some cx β β y, β cy, pcore (op x y) β‘ some (op cx cy)\n\n extend : ValidN n x β x β‘{n}β‘ op yβ yβ β\n Ξ£' zβ zβ, x β‘ op zβ zβ β§ zβ β‘{n}β‘ yβ β§ zβ β‘{n}β‘ yβ"
},
{
"name": "Iso.symm",
"content": "def Iso.symm [OFE Ξ±] [OFE Ξ²] (iso : Iso Ξ± Ξ²) : Iso Ξ² Ξ± where\n hom := iso.inv\n inv := iso.hom\n hom_inv := by admit /- proof elided -/"
},
{
"name": "Iso",
"content": "@[ext] structure Iso (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] where\n hom : Ξ± -n> Ξ²\n inv : Ξ² -n> Ξ±\n hom_inv : hom (inv x) β‘ x\n inv_hom : inv (hom x) β‘ x"
},
{
"name": "OFE.Option.some.ne",
"content": "instance OFE.Option.some.ne [OFE Ξ±] : OFE.NonExpansive (some : Ξ± β Option Ξ±) := β¨fun _ _ _ => idβ©"
},
{
"name": "Option.merge_ne",
"content": "instance Option.merge_ne [OFE Ξ±] {op : Ξ± β Ξ± β Ξ±} [NonExpansiveβ op] :\n NonExpansiveβ (Option.merge op) where\n ne n x1 x2 Hx y1 y2 Hy := by admit /- proof elided -/"
},
{
"name": "NonExpansiveβ",
"content": "class NonExpansiveβ [OFE Ξ±] [OFE Ξ²] [OFE Ξ³] (f : Ξ± β Ξ² β Ξ³) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β β β¦yβ yββ¦, yβ β‘{n}β‘ yβ β f xβ yβ β‘{n}β‘ f xβ yβ"
},
{
"name": "ContractiveHom",
"content": "@[ext] structure ContractiveHom (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] extends Hom Ξ± Ξ² where\n [contractive : Contractive f]\n ne := ne_of_contractive f"
},
{
"name": "NonExpansive",
"content": "class NonExpansive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β f xβ β‘{n}β‘ f xβ"
},
{
"name": "Included",
"content": "def Included (x y : Ξ±) : Prop := β z, y β‘ x β’ z"
},
{
"name": "Reflexive",
"content": "class Reflexive (R : Relation Ξ±) where\n refl {x : Ξ±} : R x x"
},
{
"name": "pcore",
"content": "def pcore : DFrac F β Option (DFrac F)\n | own _ => none\n | .discard => some discard\n | ownDiscard _ => some discard"
},
{
"name": "op",
"content": "def op : DFrac F β DFrac F β DFrac F\n | .discard, .discard => discard\n | own f, .discard\n | ownDiscard f, .discard\n | .discard, own f\n | .discard, ownDiscard f => ownDiscard f\n | own f, own f' => own (f + f')\n | own f, ownDiscard f'\n | ownDiscard f, own f'\n | ownDiscard f, ownDiscard f' => ownDiscard (f + f')"
},
{
"name": "Associative",
"content": "class Associative (R : Relation Ξ±) (f : Ξ± β Ξ± β Ξ±) where\n assoc {x y z : Ξ±} : R (f (f x y) z) (f x (f y z))"
},
{
"name": "Commutative",
"content": "class Commutative (R : Relation Ξ±) (f : Ξ² β Ξ² β Ξ±) where\n comm {x y : Ξ²} : R (f x y) (f y x)"
},
{
"name": "Hom",
"content": "@[ext] structure Hom (Ξ± Ξ² : Type _) [CMRA Ξ±] [CMRA Ξ²] extends OFE.Hom Ξ± Ξ² where\n protected validN {n x} : β{n} x β β{n} (f x)\n protected pcore x : (pcore x).map f β‘ pcore (f x)\n protected op x y : f (x β’ y) β‘ f x β’ f y"
},
{
"name": "Hom",
"content": "@[ext] structure Hom (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] where\n f : Ξ± β Ξ²\n ne : NonExpansive f"
},
{
"name": "scoped infix:40 \" β‘ \" => OFE.Equiv",
"content": "scoped infix:40 \" β‘ \" => OFE.Equiv"
},
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y"
},
{
"name": "@[inherit_doc]",
"content": "@[inherit_doc]\ninfixr:25 \" -n> \" => Hom"
},
{
"name": "infixr:25 \" -c> \" => ContractiveHom",
"content": "infixr:25 \" -c> \" => ContractiveHom"
},
{
"name": "infix:60 \" β’ \" => op",
"content": "infix:60 \" β’ \" => op"
},
{
"name": "infix:50 \" βΌ \" => Included",
"content": "infix:50 \" βΌ \" => Included"
},
{
"name": "@[inherit_doc]",
"content": "@[inherit_doc]\ninfixr:25 \" -C> \" => Hom"
}
] | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "_root_.Iris.OFE.Dist.validN",
"content": "theorem _root_.Iris.OFE.Dist.validN : (x : Ξ±) β‘{n}β‘ y β (β{n} x β β{n} y)"
},
{
"name": "validN_iff",
"content": "theorem validN_iff {x y : Ξ±} (e : x β‘{n}β‘ y) : β{n} x β β{n} y"
},
{
"name": "IncludedN.validN",
"content": "theorem IncludedN.validN {n} {x y : Ξ±} : x βΌ{n} y β β{n} y β β{n} x"
},
{
"name": "validN_of_incN",
"content": "theorem validN_of_incN {n} {x y : Ξ±} : x βΌ{n} y β β{n} y β β{n} x"
},
{
"name": "Included.validN",
"content": "theorem Included.validN {n} {x y : Ξ±} : x βΌ y β β{n} y β β{n} x"
},
{
"name": "validN_of_inc",
"content": "theorem validN_of_inc {n} {x y : Ξ±} : x βΌ y β β{n} y β β{n} x"
},
{
"name": "Valid.validN",
"content": "theorem Valid.validN : β (x : Ξ±) β β{n} x"
},
{
"name": "Dist.rfl",
"content": "@[simp, refl] theorem Dist.rfl [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ x"
},
{
"name": "_root_.Iris.OFE.Equiv.valid",
"content": "theorem _root_.Iris.OFE.Equiv.valid : (x : Ξ±) β‘ y β (β x β β y)"
},
{
"name": "valid_iff",
"content": "theorem valid_iff {x y : Ξ±} (e : x β‘ y) : β x β β y"
},
{
"name": "valid_of_eqv",
"content": "theorem valid_of_eqv {x y : Ξ±} : x β‘ y β β x β β y"
},
{
"name": "valid_mapN",
"content": "theorem valid_mapN {x y : Ξ±} (f : β n, β{n} x β β{n} y) (v : β x) : β y"
},
{
"name": "validN_of_eqv",
"content": "theorem validN_of_eqv {x y : Ξ±} : x β‘ y β β{n} x β β{n} y"
},
{
"name": "Hom.valid",
"content": "protected theorem Hom.valid [CMRA Ξ²] (f : Ξ± -C> Ξ²) {x : Ξ±} (H : β x) : β f x"
}
] | [
{
"name": "Iris.Agree",
"content": "@[ext]\nstructure Agree where\n car : List Ξ±\n not_nil : car β []"
},
{
"name": "Iris.toAgree",
"content": "def toAgree (a : Ξ±) : Agree Ξ± := β¨[a], by admit /- proof elided -/\nβ©"
},
{
"name": "Iris.Agree.dist",
"content": "def Agree.dist (n : Nat) (x y : Agree Ξ±) : Prop :=\n (β a β x.car, β b β y.car, a β‘{n}β‘ b) β§\n (β b β y.car, β a β x.car, a β‘{n}β‘ b)"
},
{
"name": "Iris.Agree.validN",
"content": "def Agree.validN (n : Nat) (x : Agree Ξ±) : Prop :=\n match x.car with\n | [_] => True\n | _ => β a β x.car, β b β x.car, a β‘{n}β‘ b"
},
{
"name": "Iris.Agree.valid",
"content": "def Agree.valid (x : Agree Ξ±) : Prop := β n, x.validN n"
}
] | [
{
"name": "Iris.mem_of_agree",
"content": "theorem mem_of_agree (x : Agree Ξ±) : β a, a β x.car"
},
{
"name": "Iris.Agree.equiv_def",
"content": "theorem Agree.equiv_def {x y : Agree Ξ±} : x β‘ y β β n, Agree.dist n x y"
},
{
"name": "Iris.Agree.validN_iff",
"content": "theorem Agree.validN_iff {x : Agree Ξ±} :\n x.validN n β β a β x.car, β b β x.car, a β‘{n}β‘ b"
},
{
"name": "Iris.Agree.valid_def",
"content": "theorem Agree.valid_def {x : Agree Ξ±} : β x β x.valid"
}
] | import Iris.Algebra.CMRA
import Iris.Algebra.OFE
namespace Iris
section agree
variable {Ξ± : Type u}
variable (Ξ±) in
@[ext]
structure Agree where
car : List Ξ±
not_nil : car β []
def toAgree (a : Ξ±) : Agree Ξ± := β¨[a], by admit /- proof elided -/
β©
variable [OFE Ξ±]
def Agree.dist (n : Nat) (x y : Agree Ξ±) : Prop :=
(β a β x.car, β b β y.car, a β‘{n}β‘ b) β§
(β b β y.car, β a β x.car, a β‘{n}β‘ b)
def Agree.validN (n : Nat) (x : Agree Ξ±) : Prop :=
match x.car with
| [_] => True
| _ => β a β x.car, β b β x.car, a β‘{n}β‘ b
def Agree.valid (x : Agree Ξ±) : Prop := β n, x.validN n | theorem Agree.toAgree_uninj {x : Agree Ξ±} : β x β β a, toAgree a β‘ x := | := by
simp only [valid_def, valid, validN_iff, equiv_def]
obtain β¨a, haβ© := mem_of_agree x
intro h; exists a; intro n
constructor <;> intros
Β· exists a; simp_all [toAgree]
Β· simp_all [toAgree] | 7 | 53 | false | Framework |
243 | Iris.BI.plainly_sep_dup | theorem plainly_sep_dup : β P β£β’ β P β β P | iris-lean | src/Iris/BI/Plainly.lean | [
"import Iris.Algebra",
"import Iris.BI.DerivedLaws",
"import src.Iris.Algebra.CMRA",
"import src.Iris.Algebra.OFE",
"import src.Iris.BI.BI",
"import src.Iris.BI.DerivedLaws",
"import src/Iris/Instances/UPred/Instance.lean",
"import Iris.BI.BI",
"import Iris.BI.Classes"
] | [
{
"name": "Lean.MonadQuotation",
"module": "Init.Prelude"
},
{
"name": "Lean.MonadRef",
"module": "Init.Prelude"
},
{
"name": "Monad",
"module": "Init.Prelude"
},
{
"name": "m",
"module": "QqTest.matching"
},
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "Option.merge",
"module": "Init.Data.Option.Basic"
},
{
"name": "id",
"module": "Init.Prelude"
},
{
"name": "Equivalence",
"module": "Init.Core"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Bool",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
}
] | [
{
"name": "syntax term:26 \" ==β \" term:25 : term",
"content": "syntax term:26 \" ==β \" term:25 : term\n\nsyntax term \"={ \" term \" , \" term \" }=β \" term : term\n\nsyntax term \"={ \" term \" }=β \" term : term\n\nsyntax term \"={ \" term \" }[ \" term \" ]β·=β \" term : term\n\nsyntax term \"={ \" term \" }β·=β \" term : term\n\nsyntax term \"={ \" term \" }[ \" term \" ]β·^\" term \"=β \" term : term\n\nsyntax term \"={ \" term \" }β·^\" term \"=β \" term : term"
},
{
"name": "macro:max \"iprop(\" P:term \" : \" t:term \")\" : term => `((ipro",
"content": "macro:max \"iprop(\" P:term \" : \" t:term \")\" : term => `((iprop($P) : $t))\n\nsyntax:max \"iprop(\" term \")\" : term"
},
{
"name": "macro \"β\" xs:explicitBinders \", \" b:term : term => do",
"content": "macro \"β\" xs:explicitBinders \", \" b:term : term => do\n return β¨β expandExplicitBinders ``BIBase.exists xs bβ©"
},
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y\n\nsyntax:max \"<pers> \" term:40 : term"
},
{
"name": "macro:25 P:term:29 \" β’ \" Q:term:25 : term => ``(BIBase.Entai",
"content": "macro:25 P:term:29 \" β’ \" Q:term:25 : term => ``(BIBase.Entails iprop($P) iprop($Q))\n\ndelab_rule BIBase.Entails\n | `($_ $P $Q) => do ``($(β unpackIprop P) β’ $(β unpackIprop Q))"
},
{
"name": "macro:25 P:term:29 \" β£β’ \" Q:term:29 : term => ``(BiEntails i",
"content": "macro:25 P:term:29 \" β£β’ \" Q:term:29 : term => ``(BiEntails iprop($P) iprop($Q))\n\ndelab_rule BIBase.Entails\n | `($_ iprop(emp) $P) => do ``(β’ $(β unpackIprop P))\n\ndelab_rule BIBase.BiEntails\n | `($_ $P $Q) => do ``($(β unpackIprop P) β£β’ $(β unpackIprop Q))\n\nsyntax \"β\" term \"β\" : term\n\nsyntax:max \"β· \" term:40 : term\n\nsyntax \"β \" term:40 : term"
},
{
"name": "notation:50 x \" βΌ{\" n \"} \" y:51 => IncludedN n x y",
"content": "notation:50 x \" βΌ{\" n \"} \" y:51 => IncludedN n x y\n\nsyntax:max \"<affine> \" term:40 : term\n\nsyntax:max \"β‘ \" term:40 : term\n\nsyntax:max \"<absorb> \" term:40 : term"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(|==> $P)) => ``(BUpd.bupd iprop($P))\n | `(iprop($P ==β $Q)) => ``(BIBase.wand iprop($P) (BUpd.bupd iprop($Q)))\n\ndelab_rule BUpd.bupd\n | `($_ $P) => do ``(iprop(|==> $(β Iris.BI.unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(|={ $E1 , $E2 }=> $P)) => ``(FUpd.fupd $E1 $E2 iprop($P))\n | `(iprop($P ={ $E1 , $E2 }=β $Q)) => ``(BIBase.wand iprop($P) (FUpd.fupd $E1 $E2 iprop($Q)))\n | `(iprop(|={ $E1 }=> $P)) => ``(FUpd.fupd $E1 $E1 iprop($P))\n | `(iprop($P ={ $E1 }=β $Q)) => ``(BIBase.wand iprop($P) (FUpd.fupd $E1 $E1 iprop($Q)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(|={ $E1 }[ $E2 ]β·=> $P)) => ``(iprop(|={$E1, $E2}=> β· (|={ $E2, $E1 }=> iprop($P))))\n | `(iprop($P ={ $E1 }[ $E2 ]β·=β $Q)) => ``(iprop(iprop($P) -β |={$E1}[$E2]β·=> iprop($Q)))\n | `(iprop(|={ $E1 }β·=> $P)) => ``(iprop(|={$E1}[$E1]β·=> iprop($P)))\n | `(iprop($P ={ $E1 }β·=β $Q)) => ``(iprop(iprop($P) ={$E1}[$E1]β·=β iprop($Q)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(|={ $E1 }[ $E2 ]β·^$n=> $P)) => ``(iprop(|={$E1, $E2}=> β·^[$n] (|={ $E2, $E1 }=> iprop($P))))\n | `(iprop($P ={ $E1 }[ $E2 ]β·^$n=β $Q)) => ``(iprop(iprop($P) -β |={$E1}[$E2]β·^$n=> iprop($Q)))\n | `(iprop(|={ $E1 }β·^$n=> $P)) => ``(iprop(|={$E1}[$E1]β·^$n=> iprop($P)))\n | `(iprop($P ={ $E1 }β·^$n=β $Q)) => ``(iprop(iprop($P) ={$E1}[$E1]β·^$n=β iprop($Q)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(emp)) => ``(BIBase.emp)\n | `(iprop(β$Οβ)) => ``(BIBase.pure $Ο)\n | `(iprop($P β§ $Q)) => ``(BIBase.and iprop($P) iprop($Q))\n | `(iprop($P β¨ $Q)) => ``(BIBase.or iprop($P) iprop($Q))\n | `(iprop($P β $Q)) => ``(BIBase.imp iprop($P) iprop($Q))\n | `(iprop(β $xs, $Ξ¨)) => do expandExplicitBinders ``BIBase.exists xs (β ``(iprop($Ξ¨)))\n | `(iprop($P β $Q)) => ``(BIBase.sep iprop($P) iprop($Q))\n | `(iprop($P -β $Q)) => ``(BIBase.wand iprop($P) iprop($Q))\n | `(iprop(<pers> $P)) => ``(BIBase.persistently iprop($P))\n | `(iprop(β· $P)) => ``(BIBase.later iprop($P))\n\ndelab_rule BIBase.emp\n | `($_) => ``(iprop($(mkIdent `emp)))\ndelab_rule BIBase.pure\n | `($_ $Ο) => ``(iprop(β$Οβ))\ndelab_rule BIBase.and\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β§ $(β unpackIprop Q)))\ndelab_rule BIBase.or\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β¨ $(β unpackIprop Q)))\ndelab_rule BIBase.imp\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule BIBase.forall\n | `($_ fun $x:ident => iprop(β $y:ident $[$z:ident]*, $Ξ¨)) => do\n ``(iprop(β $x:ident $y:ident $[$z:ident]*, $Ξ¨))\n | `($_ fun $x:ident => $Ξ¨) => do ``(iprop(β $x:ident, $(β unpackIprop Ξ¨)))\ndelab_rule BIBase.exists\n | `($_ fun $x:ident => iprop(β $y:ident $[$z:ident]*, $Ξ¨)) => do\n ``(iprop(β $x:ident $y:ident $[$z:ident]*, $Ξ¨))\n | `($_ fun $x:ident => $Ξ¨) => do ``(iprop(β $x:ident, $(β unpackIprop Ξ¨)))\ndelab_rule BIBase.sep\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule BIBase.wand\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) -β $(β unpackIprop Q)))\ndelab_rule BIBase.persistently\n | `($_ $P) => do ``(iprop(<pers> $(β unpackIprop P)))\n\ndelab_rule BIBase.pure\n | `($_ True) => ``(iprop($(mkIdent `True)))\n | `($_ False) => ``(iprop($(mkIdent `False)))\ndelab_rule BIBase.imp\n | `($_ $P iprop(False)) => do ``(iprop(Β¬$(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β _%$tk, $Ξ¨)) => ``(BIBase.forall (fun _%$tk => iprop($Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $x:ident, $Ξ¨)) => ``(BIBase.forall (fun $x => iprop($Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β (_%$tk : $t), $Ξ¨)) => ``(BIBase.forall (fun (_%$tk : $t) => iprop($Ξ¨)))\n | `(iprop(β (_%$tk $xs* : $t), $Ξ¨)) =>\n ``(BIBase.forall (fun (_%$tk : $t) => iprop(β ($xs* : $t), $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β ($x:ident : $t), $Ξ¨)) => ``(BIBase.forall (fun ($x : $t) => iprop($Ξ¨)))\n | `(iprop(β ($x:ident $xs* : $t), $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop(β ($xs* : $t), $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β {_%$tk : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun {_%$tk : $t} => iprop($Ξ¨)))\n | `(iprop(β {_%$tk $xs* : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun {_%$tk : $t} => iprop(β {$xs* : $t}, $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β {$x:ident : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop($Ξ¨)))\n | `(iprop(β {$x:ident $xs* : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop(β {$xs* : $t}, $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $x $y $xs*, $Ξ¨)) => ``(iprop(β $x, β $y $xs*, $Ξ¨))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(True)) => ``(BIBase.pure True)\n | `(iprop(False)) => ``(BIBase.pure False)\n | `(iprop(Β¬$P)) => ``(iprop($P β False))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop($P β $Q)) => ``(iff iprop($P) iprop($Q))\n | `(iprop($P β-β $Q)) => ``(wandIff iprop($P) iprop($Q))\n\ndelab_rule iff\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule wandIff\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β-β $(β unpackIprop Q)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(<affine> $P)) => ``(affinely iprop($P))\n | `(iprop(<absorb> $P)) => ``(absorbingly iprop($P))\n\ndelab_rule affinely\n | `($_ $P) => do ``(iprop(<affine> $(β unpackIprop P)))\ndelab_rule absorbingly\n | `($_ $P) => do ``(iprop(<absorb> $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β‘ $P)) => ``(intuitionistically iprop($P))\n\ndelab_rule intuitionistically\n | `($_ $P) => do ``(iprop(β‘ $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(<pers>?$p $P)) => ``(persistentlyIf $p iprop($P))\n | `(iprop(<affine>?$p $P)) => ``(affinelyIf $p iprop($P))\n | `(iprop(<absorb>?$p $P)) => ``(absorbinglyIf $p iprop($P))\n | `(iprop(β‘?$p $P)) => ``(intuitionisticallyIf $p iprop($P))\n\ndelab_rule persistentlyIf\n | `($_ $p $P) => do ``(iprop(<pers>?$p $(β unpackIprop P)))\ndelab_rule affinelyIf\n | `($_ $p $P) => do ``(iprop(<affine>?$p $(β unpackIprop P)))\ndelab_rule absorbinglyIf\n | `($_ $p $P) => do ``(iprop(<absorb>?$p $(β unpackIprop P)))\ndelab_rule intuitionisticallyIf\n | `($_ $p $P) => do ``(iprop(β‘?$p $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β·^[$n] $P)) => ``(laterN $n iprop($P))\n\ndelab_rule laterN\n | `($_ $n $P) => do ``(iprop(β·^[$n] $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $P)) => ``(except0 iprop($P))\n\ndelab_rule except0\n | `($_ $P) => do ``(iprop(β $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $P)) => ``(Plainly.plainly iprop($P))\n\ndelab_rule Plainly.plainly\n | `($_ $P) => do ``(iprop(β $(β Iris.BI.unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β ? $p $P)) => ``(Plainly.plainlyIf $p iprop($P))\n\ndelab_rule Plainly.plainlyIf\n | `($_ $p $P) => do ``(iprop(β ? $p $(β Iris.BI.unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(term($t))) => pure t\n | `(iprop($t)) => pure t"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(($P))) => ``((iprop($P)))\n | `(iprop(if $c then $t else $e)) => ``(if $c then iprop($t) else iprop($e))\n | `(iprop(($P : $t))) => ``((iprop($P) : $t))"
},
{
"name": "unpackIprop",
"content": "partial def unpackIprop [Monad m] [MonadRef m] [MonadQuotation m] : Term β m Term\n | `(iprop($P)) => do `($P)\n | `($P:ident) => do `($P)\n | `(?$P:ident) => do `(?$P)\n | `(($P)) => do `(($(β unpackIprop P)))\n | `($P $[ $Q]*) => do ``($P $[ $Q]*)\n | `(if $c then $t else $e) => do\n let t β unpackIprop t\n let e β unpackIprop e\n `(if $c then $t else $e)\n | `(($P : $t)) => do ``(($(β unpackIprop P) : $t))\n | `($t) => `($t:term)"
},
{
"name": "BIBase",
"content": "class BIBase (PROP : Type u) where\n Entails : PROP β PROP β Prop\n emp : PROP\n pure : Prop β PROP\n and : PROP β PROP β PROP\n or : PROP β PROP β PROP\n imp : PROP β PROP β PROP\n sForall : (PROP β Prop) β PROP\n sExists : (PROP β Prop) β PROP\n sep : PROP β PROP β PROP\n wand : PROP β PROP β PROP\n persistently : PROP β PROP\n later : PROP β PROP"
},
{
"name": "liftRel",
"content": "def liftRel (R : Ξ± β Ξ² β Prop) (A : Ξ± β Prop) (B : Ξ² β Prop) : Prop :=\n (β a, A a β β b, B b β§ R a b) β§ (β b, B b β β a, A a β§ R a b)"
},
{
"name": "BI",
"content": "class BI (PROP : Type _) extends COFE PROP, BI.BIBase PROP where\n Equiv P Q := P β£β’ Q\n\n entails_preorder : Preorder Entails\n equiv_iff {P Q : PROP} : (P β‘ Q) β P β£β’ Q := by admit /- proof elided -/\n\n and_ne : OFE.NonExpansiveβ and\n or_ne : OFE.NonExpansiveβ or\n imp_ne : OFE.NonExpansiveβ imp\n sForall_ne {Pβ Pβ} : liftRel (Β· β‘{n}β‘ Β·) Pβ Pβ β sForall Pβ β‘{n}β‘ sForall Pβ\n sExists_ne {Pβ Pβ} : liftRel (Β· β‘{n}β‘ Β·) Pβ Pβ β sExists Pβ β‘{n}β‘ sExists Pβ\n sep_ne : OFE.NonExpansiveβ sep\n wand_ne : OFE.NonExpansiveβ wand\n persistently_ne : OFE.NonExpansive persistently\n later_ne : OFE.NonExpansive later\n\n pure_intro {Ο : Prop} {P : PROP} : Ο β P β’ βΟβ\n pure_elim' {Ο : Prop} {P : PROP} : (Ο β True β’ P) β βΟβ β’ P\n\n and_elim_l {P Q : PROP} : P β§ Q β’ P\n and_elim_r {P Q : PROP} : P β§ Q β’ Q\n and_intro {P Q R : PROP} : (P β’ Q) β (P β’ R) β P β’ Q β§ R\n\n or_intro_l {P Q : PROP} : P β’ P β¨ Q\n or_intro_r {P Q : PROP} : Q β’ P β¨ Q\n or_elim {P Q R : PROP} : (P β’ R) β (Q β’ R) β P β¨ Q β’ R\n\n imp_intro {P Q R : PROP} : (P β§ Q β’ R) β P β’ Q β R\n imp_elim {P Q R : PROP} : (P β’ Q β R) β P β§ Q β’ R\n\n sForall_intro {P : PROP} {Ξ¨ : PROP β Prop} : (β p, Ξ¨ p β P β’ p) β P β’ sForall Ξ¨\n sForall_elim {Ξ¨ : PROP β Prop} {p : PROP} : Ξ¨ p β sForall Ξ¨ β’ p\n\n sExists_intro {Ξ¨ : PROP β Prop} {p : PROP} : Ξ¨ p β p β’ sExists Ξ¨\n sExists_elim {Ξ¦ : PROP β Prop} {Q : PROP} : (β p, Ξ¦ p β p β’ Q) β sExists Ξ¦ β’ Q\n\n sep_mono {P P' Q Q' : PROP} : (P β’ Q) β (P' β’ Q') β P β P' β’ Q β Q'\n emp_sep {P : PROP} : emp β P β£β’ P\n sep_symm {P Q : PROP} : P β Q β’ Q β P\n sep_assoc_l {P Q R : PROP} : (P β Q) β R β’ P β (Q β R)\n\n wand_intro {P Q R : PROP} : (P β Q β’ R) β P β’ Q -β R\n wand_elim {P Q R : PROP} : (P β’ Q -β R) β P β Q β’ R\n\n persistently_mono {P Q : PROP} : (P β’ Q) β <pers> P β’ <pers> Q\n persistently_idem_2 {P : PROP} : <pers> P β’ <pers> <pers> P\n persistently_emp_2 : (emp : PROP) β’ <pers> emp\n persistently_and_2 {P Q : PROP} : (<pers> P) β§ (<pers> Q) β’ <pers> (P β§ Q)\n persistently_sExists_1 {Ξ¨ : PROP β Prop} : <pers> (sExists Ξ¨) β’ β p, βΞ¨ pβ β§ <pers> p\n persistently_absorb_l {P Q : PROP} : <pers> P β Q β’ <pers> P\n persistently_and_l {P Q : PROP} : <pers> P β§ Q β’ P β Q\n\n later_mono {P Q : PROP} : (P β’ Q) β β· P β’ β· Q\n later_intro {P : PROP} : P β’ β· P\n\n later_sForall_2 {Ξ¦ : PROP β Prop} : (β p, βΞ¦ pβ β β· p) β’ β· sForall Ξ¦\n later_sExists_false {Ξ¦ : PROP β Prop} : (β· sExists Ξ¦) β’ β· False β¨ β p, βΞ¦ pβ β§ β· p\n later_sep {P Q : PROP} : β· (P β Q) β£β’ β· P β β· Q\n later_persistently {P : PROP} : β· <pers> P β£β’ <pers> β· P\n later_false_em {P : PROP} : β· P β’ β· False β¨ (β· False β P)"
},
{
"name": "Preorder",
"content": "class Preorder (R : Relation Ξ±) extends Reflexive R, Transitive R"
},
{
"name": "Reflexive",
"content": "class Reflexive (R : Relation Ξ±) where\n refl {x : Ξ±} : R x x"
},
{
"name": "Relation",
"content": "abbrev Relation (Ξ± : Type _) := Ξ± β Ξ± β Prop"
},
{
"name": "Transitive",
"content": "class Transitive (R : Relation Ξ±) where\n trans {x y z : Ξ±} : R x y β R y z β R x z"
},
{
"name": "NonExpansiveβ",
"content": "class NonExpansiveβ [OFE Ξ±] [OFE Ξ²] [OFE Ξ³] (f : Ξ± β Ξ² β Ξ³) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β β β¦yβ yββ¦, yβ β‘{n}β‘ yβ β f xβ yβ β‘{n}β‘ f xβ yβ"
},
{
"name": "OFE.ContractiveHom.fixpoint_ne",
"content": "instance OFE.ContractiveHom.fixpoint_ne [COFE Ξ±] [Inhabited Ξ±] :\n NonExpansive (ContractiveHom.fixpoint (Ξ± := Ξ±)) where\n ne n f1 f2 H := by admit /- proof elided -/"
},
{
"name": "ContractiveHom",
"content": "@[ext] structure ContractiveHom (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] extends Hom Ξ± Ξ² where\n [contractive : Contractive f]\n ne := ne_of_contractive f"
},
{
"name": "OFE.Option.some.ne",
"content": "instance OFE.Option.some.ne [OFE Ξ±] : OFE.NonExpansive (some : Ξ± β Option Ξ±) := β¨fun _ _ _ => idβ©"
},
{
"name": "Option.merge_ne",
"content": "instance Option.merge_ne [OFE Ξ±] {op : Ξ± β Ξ± β Ξ±} [NonExpansiveβ op] :\n NonExpansiveβ (Option.merge op) where\n ne n x1 x2 Hx y1 y2 Hy := by admit /- proof elided -/"
},
{
"name": "NonExpansive",
"content": "class NonExpansive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β f xβ β‘{n}β‘ f xβ"
},
{
"name": "COFE.OFunctor.constOF_RFunctor",
"content": "instance COFE.OFunctor.constOF_RFunctor [CMRA B] : RFunctor (constOF B) where\n map f g := by admit /- proof elided -/"
},
{
"name": "IsCOFE",
"content": "class IsCOFE (Ξ± : Type _) [OFE Ξ±] where\n compl : Chain Ξ± β Ξ±\n conv_compl {c : Chain Ξ±} : compl c β‘{n}β‘ c n"
},
{
"name": "Chain",
"content": "structure Chain (Ξ± : Type _) [OFE Ξ±] where\n chain : Nat β Ξ±\n cauchy : n β€ i β chain i β‘{n}β‘ chain n"
},
{
"name": "LawfulBigOp",
"content": "class LawfulBigOp (f : PROP β PROP β PROP) (unit : outParam PROP)\n (eq : outParam (PROP β PROP β Prop)) where\n refl : eq a a\n symm : eq a b β eq b a\n trans : eq a b β eq b c β eq a c\n comm : eq (f a b) (f b a)\n assoc : eq (f (f a b) c) (f a (f b c))\n left_id : eq (f unit a) a\n congr_l : eq a a' β eq (f a b) (f a' b)"
},
{
"name": "Included",
"content": "def Included (x y : Ξ±) : Prop := β z, y β‘ x β’ z"
},
{
"name": "CMRA",
"content": "class CMRA (Ξ± : Type _) extends OFE Ξ± where\n pcore : Ξ± β Option Ξ±\n op : Ξ± β Ξ± β Ξ±\n ValidN : Nat β Ξ± β Prop\n Valid : Ξ± β Prop\n\n op_ne : NonExpansive (op x)\n pcore_ne : x β‘{n}β‘ y β pcore x = some cx β\n β cy, pcore y = some cy β§ cx β‘{n}β‘ cy\n validN_ne : x β‘{n}β‘ y β ValidN n x β ValidN n y\n\n valid_iff_validN : Valid x β β n, ValidN n x\n validN_succ : ValidN n.succ x β ValidN n x\n validN_op_left : ValidN n (op x y) β ValidN n x\n\n assoc : op x (op y z) β‘ op (op x y) z\n comm : op x y β‘ op y x\n\n pcore_op_left : pcore x = some cx β op cx x β‘ x\n pcore_idem : pcore x = some cx β pcore cx β‘ some cx\n pcore_op_mono : pcore x = some cx β β y, β cy, pcore (op x y) β‘ some (op cx cy)\n\n extend : ValidN n x β x β‘{n}β‘ op yβ yβ β\n Ξ£' zβ zβ, x β‘ op zβ zβ β§ zβ β‘{n}β‘ yβ β§ zβ β‘{n}β‘ yβ"
},
{
"name": "Commutative",
"content": "class Commutative (R : Relation Ξ±) (f : Ξ² β Ξ² β Ξ±) where\n comm {x y : Ξ²} : R (f x y) (f y x)"
},
{
"name": "intuitionistically",
"content": "def intuitionistically [BIBase PROP] (P : PROP) : PROP := iprop(<affine> <pers> P)"
},
{
"name": "Affine",
"content": "class Affine [BI PROP] (P : PROP) where\n affine : P β’ emp"
},
{
"name": "Absorbing",
"content": "class Absorbing [BI PROP] (P : PROP) where\n absorbing : <absorb> P β’ P"
},
{
"name": "bigAnd",
"content": "def bigAnd [BIBase PROP] (Ps : List PROP) : PROP := bigOp and iprop(True) Ps"
},
{
"name": "bigOp",
"content": "def bigOp (f : PROP β PROP β PROP) (unit : PROP) : List PROP β PROP\n | [] => unit\n | [P] => P\n | P :: Ps => f P (bigOp f unit Ps)"
},
{
"name": "absorbingly",
"content": "def absorbingly [BIBase PROP] (P : PROP) : PROP := iprop(True β P)"
},
{
"name": "BiEntails",
"content": "structure BiEntails [BIBase PROP] (P Q : PROP) where\n mp : P β’ Q\n mpr : Q β’ P"
},
{
"name": "persistentlyIf",
"content": "def persistentlyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then <pers> P else P)"
},
{
"name": "intuitionisticallyIf",
"content": "def intuitionisticallyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then β‘ P else P)"
},
{
"name": "bigSep",
"content": "def bigSep [BIBase PROP] (Ps : List PROP) : PROP := bigOp sep iprop(emp) Ps"
},
{
"name": "affinely",
"content": "def affinely [BIBase PROP] (P : PROP) : PROP := iprop(emp β§ P)"
},
{
"name": "bigOr",
"content": "def bigOr [BIBase PROP] (Ps : List PROP) : PROP := bigOp or iprop(False) Ps"
},
{
"name": "absorbinglyIf",
"content": "def absorbinglyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then <absorb> P else P)"
},
{
"name": "affinelyIf",
"content": "def affinelyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then <affine> P else P)"
},
{
"name": "wandIff",
"content": "def wandIff [BIBase PROP] (P Q : PROP) : PROP := iprop((P -β Q) β§ (Q -β P))"
},
{
"name": "",
"content": "instance : BIPlainly (UPred M) where\n mono H _ _ _ := H _ _ CMRA.unit_validN\n elim_persistently {P} n x Hx := by admit /- proof elided -/"
},
{
"name": "persistently",
"content": "protected def persistently (P : UPred M) : UPred M where\n holds n x := P n (CMRA.core x)\n mono H Hx Hn := P.mono H (CMRA.core_incN_core Hx) Hn"
},
{
"name": "BIUpdate",
"content": "class BIUpdate (PROP : Type _) [BI PROP] extends BUpd PROP where\n [bupd_ne : OFE.NonExpansive (BUpd.bupd (PROP := PROP))]\n intro {P : PROP} : iprop(P β’ |==> P)\n mono {P Q : PROP} : iprop(P β’ Q) β iprop(|==> P β’ |==> Q)\n trans {P : PROP} : iprop(|==> |==> P β’ |==> P)\n frame_r {P R : PROP} : iprop((|==> P) β R β’ |==> (P β R))"
},
{
"name": "UPred",
"content": "@[ext]\nstructure UPred (M : Type _) [UCMRA M] where\n holds : Nat β M β Prop\n mono {n1 n2 x1 x2} : holds n1 x1 β x1 βΌ{n2} x2 β n2 β€ n1 β holds n2 x2"
},
{
"name": "IsModal",
"content": "class IsModal [BI PROP1] [BI PROP2] (M : PROP1 β PROP2)\n (iaction saction : ModalityAction PROP1 PROP2) where\n spec_intuitionistic : iaction.intuitionistic_action_spec M\n spec_spatial : saction.spatial_action_spec M\n emp : iprop(emp) β’ M iprop(emp)\n mono : β {P Q}, (P β’ Q) β M P β’ M Q\n sep : β {P Q}, iprop(M P β M Q) β’ M iprop(P β Q)"
},
{
"name": "core",
"content": "def core (x : Ξ±) := (pcore x).getD x"
},
{
"name": "UCMRA",
"content": "class UCMRA (Ξ± : Type _) extends CMRA Ξ± where\n unit : Ξ±\n unit_valid : β unit\n unit_left_id : unit β’ x β‘ x\n pcore_unit : pcore unit β‘ some unit"
},
{
"name": "pcore",
"content": "def pcore : DFrac F β Option (DFrac F)\n | own _ => none\n | .discard => some discard\n | ownDiscard _ => some discard"
},
{
"name": "DFrac",
"content": "inductive DFrac (F : Type _) where\n \n| own (f : F) : DFrac F\n \n| discard : DFrac F\n \n| ownDiscard (f : F) : DFrac F"
},
{
"name": "op",
"content": "def op : DFrac F β DFrac F β DFrac F\n | .discard, .discard => discard\n | own f, .discard\n | ownDiscard f, .discard\n | .discard, own f\n | .discard, ownDiscard f => ownDiscard f\n | own f, own f' => own (f + f')\n | own f, ownDiscard f'\n | ownDiscard f, own f'\n | ownDiscard f, ownDiscard f' => ownDiscard (f + f')"
},
{
"name": "Associative",
"content": "class Associative (R : Relation Ξ±) (f : Ξ± β Ξ± β Ξ±) where\n assoc {x y z : Ξ±} : R (f (f x y) z) (f x (f y z))"
},
{
"name": "plainly",
"content": "protected def plainly (P : UPred M) : UPred M where\n holds n _ := P n UCMRA.unit\n mono H _ Hn := P.mono H (CMRA.incN_refl UCMRA.unit) Hn"
},
{
"name": "BIPlainly",
"content": "class BIPlainly (PROP : Type _) [Iris.BI PROP] extends Plainly PROP where\n [ne : Iris.OFE.NonExpansive (Plainly.plainly (PROP := PROP))]\n mono {P Q : PROP} : (P β’ Q) β β P β’ β Q\n elim_persistently {P : PROP} : β P β’ <pers> P\n idem {P : PROP} : β P β’ β β P\n plainly_sForall_2 {Ξ¦ : PROP β Prop} : (β p, βΞ¦ pβ β β p) β’ β sForall Ξ¦\n plainly_impl_plainly {P Q : PROP} : (β P β β Q) β’ β (β P β Q)\n emp_intro {P : PROP} : P β’ β emp\n plainly_absorb {P Q : PROP} : β P β Q β’ β P\n later_plainly {P : PROP} : β· β P β£β’ β β· P"
},
{
"name": "Idempotent",
"content": "class Idempotent (R : Relation Ξ±) (f : Ξ± β Ξ± β Ξ±) where\n idem {x : Ξ±} : R (f x x) x"
},
{
"name": "",
"content": "instance : BIPlainlyExists (UPred M) where\n plainly_sExists_1 _ _ _ := fun β¨_, hpβ© => β¨_, β¨_, rflβ©, hpβ©"
},
{
"name": "BIPlainlyExists",
"content": "class BIPlainlyExists (PROP : Type _) [Iris.BI PROP] [BIPlainly PROP] where\n plainly_sExists_1 {Ξ¦ : PROP β Prop} : β sExists Ξ¦ β’ β p, βΞ¦ pβ β§ β p"
},
{
"name": "",
"content": "instance : Plainly (UPred M) := β¨UPred.plainlyβ©"
},
{
"name": "scoped infix:40 \" β‘ \" => OFE.Equiv",
"content": "scoped infix:40 \" β‘ \" => OFE.Equiv"
},
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y"
},
{
"name": "infixr:25 \" -c> \" => ContractiveHom",
"content": "infixr:25 \" -c> \" => ContractiveHom"
},
{
"name": "notation:40 \"[β§] \" Ps:max => bigAnd Ps",
"content": "notation:40 \"[β§] \" Ps:max => bigAnd Ps"
},
{
"name": "notation:40 \"[β¨] \" Ps:max => bigOr Ps",
"content": "notation:40 \"[β¨] \" Ps:max => bigOr Ps"
},
{
"name": "notation:40 \"[β] \" Ps:max => bigSep Ps",
"content": "notation:40 \"[β] \" Ps:max => bigSep Ps"
},
{
"name": "infix:60 \" β’ \" => op",
"content": "infix:60 \" β’ \" => op"
},
{
"name": "infix:50 \" βΌ \" => Included",
"content": "infix:50 \" βΌ \" => Included"
}
] | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "persistently_and_sep_assoc",
"content": "theorem persistently_and_sep_assoc [BI PROP] {P Q R : PROP} :\n <pers> P β§ (Q β R) β£β’ (<pers> P β§ Q) β R"
},
{
"name": "and_mono_l",
"content": "theorem and_mono_l [BI PROP] {P P' Q : PROP} (h : P β’ P') : P β§ Q β’ P' β§ Q"
},
{
"name": "and_mono",
"content": "@[rw_mono_rule]\ntheorem and_mono [BI PROP] {P P' Q Q' : PROP} (h1 : P β’ Q) (h2 : P' β’ Q') : P β§ P' β’ Q β§ Q'"
},
{
"name": "and_elim_r'",
"content": "theorem and_elim_r' [BI PROP] {P Q R : PROP} (h : Q β’ R) : P β§ Q β’ R"
},
{
"name": "and_elim_l'",
"content": "theorem and_elim_l' [BI PROP] {P Q R : PROP} (h : P β’ R) : P β§ Q β’ R"
},
{
"name": "sep_assoc",
"content": "theorem sep_assoc [BI PROP] {P Q R : PROP} : (P β Q) β R β£β’ P β Q β R"
},
{
"name": "sep_congr_l",
"content": "theorem sep_congr_l [BI PROP] {P P' Q : PROP} (h : P β£β’ P') : P β Q β£β’ P' β Q"
},
{
"name": "sep_congr",
"content": "@[rw_mono_rule]\ntheorem sep_congr [BI PROP] {P P' Q Q' : PROP} (h1 : P β£β’ Q) (h2 : P' β£β’ Q') :\n (P β P') β£β’ (Q β Q')"
},
{
"name": "sep_congr_r",
"content": "theorem sep_congr_r [BI PROP] {P Q Q' : PROP} (h : Q β£β’ Q') : P β Q β£β’ P β Q'"
},
{
"name": "sep_mono_l",
"content": "theorem sep_mono_l [BI PROP] {P P' Q : PROP} (h : P β’ P') : P β Q β’ P' β Q"
},
{
"name": "BIBase.Entails.rfl",
"content": "@[simp] theorem BIBase.Entails.rfl [BI PROP] {P : PROP} : P β’ P"
},
{
"name": "Included.trans",
"content": "theorem Included.trans : (x : Ξ±) βΌ y β y βΌ z β x βΌ z"
},
{
"name": "inc_trans",
"content": "theorem inc_trans {x y z : Ξ±} : x βΌ y β y βΌ z β x βΌ z"
},
{
"name": "op_left_eqv",
"content": "theorem op_left_eqv {x y : Ξ±} (z : Ξ±) (e : x β‘ y) : x β’ z β‘ y β’ z"
},
{
"name": "_root_.Iris.OFE.Dist.op_r",
"content": "theorem _root_.Iris.OFE.Dist.op_r {x y z : Ξ±} : y β‘{n}β‘ z β x β’ y β‘{n}β‘ x β’ z"
},
{
"name": "op_right_dist",
"content": "theorem op_right_dist (x : Ξ±) {y z : Ξ±} (e : y β‘{n}β‘ z) : x β’ y β‘{n}β‘ x β’ z"
},
{
"name": "_root_.Iris.OFE.Equiv.op_r",
"content": "theorem _root_.Iris.OFE.Equiv.op_r {x y z : Ξ±} : y β‘ z β x β’ y β‘ x β’ z"
},
{
"name": "op_right_eqv",
"content": "theorem op_right_eqv (x : Ξ±) {y z : Ξ±} (e : y β‘ z) : x β’ y β‘ x β’ z"
},
{
"name": "IncludedN.trans",
"content": "theorem IncludedN.trans : (x : Ξ±) βΌ{n} y β y βΌ{n} z β x βΌ{n} z"
},
{
"name": "incN_trans",
"content": "theorem incN_trans {x y z : Ξ±} : x βΌ{n} y β y βΌ{n} z β x βΌ{n} z"
},
{
"name": "op_left_dist",
"content": "theorem op_left_dist {x y : Ξ±} (z : Ξ±) (e : x β‘{n}β‘ y) : x β’ z β‘{n}β‘ y β’ z"
},
{
"name": "Dist.trans",
"content": "theorem Dist.trans [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ y β y β‘{n}β‘ z β x β‘{n}β‘ z"
},
{
"name": "BIBase.BiEntails.trans",
"content": "theorem BIBase.BiEntails.trans [BI PROP] {P Q R : PROP} (h1 : P β£β’ Q) (h2 : Q β£β’ R) : P β£β’ R"
},
{
"name": "BIBase.Entails.trans",
"content": "theorem BIBase.Entails.trans [BI PROP] {P Q R : PROP} (h1 : P β’ Q) (h2 : Q β’ R) : P β’ R"
},
{
"name": "Equiv.trans",
"content": "theorem Equiv.trans [OFE Ξ±] {x : Ξ±} : x β‘ y β y β‘ z β x β‘ z"
},
{
"name": "equiv_eqv",
"content": "theorem equiv_eqv [ofe : OFE Ξ±] : Equivalence ofe.Equiv"
},
{
"name": "Dist.symm",
"content": "@[symm] theorem Dist.symm [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ y β y β‘{n}β‘ x"
},
{
"name": "Dist.rfl",
"content": "@[simp, refl] theorem Dist.rfl [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ x"
},
{
"name": "DistLater.trans",
"content": "theorem DistLater.trans [OFE Ξ±] {n} {x : Ξ±} (h1 : DistLater n x y) (h2 : DistLater n y z) :\n DistLater n x z"
},
{
"name": "and_self",
"content": "theorem and_self [BI PROP] {P : PROP} : P β§ P β£β’ P"
},
{
"name": "emp_sep",
"content": "theorem emp_sep [BI PROP] {P : PROP} : emp β P β£β’ P"
},
{
"name": "sep_mono_r",
"content": "theorem sep_mono_r [BI PROP] {P Q Q' : PROP} (h : Q β’ Q') : P β Q β’ P β Q'"
},
{
"name": "sep_mono",
"content": "@[rw_mono_rule]\ntheorem sep_mono [BI PROP] {P P' Q Q' : PROP} (h1 : P β’ Q) (h2 : P' β’ Q') : P β P' β’ Q β Q'"
},
{
"name": "sep_comm",
"content": "theorem sep_comm [BI PROP] {P Q : PROP} : P β Q β£β’ Q β P"
},
{
"name": "sep_elim_r",
"content": "theorem sep_elim_r [BI PROP] {P Q : PROP} [TCOr (Affine P) (Absorbing Q)] : P β Q β’ Q"
},
{
"name": "absorbingly_of_persistently",
"content": "theorem absorbingly_of_persistently [BI PROP] {P : PROP} : <pers> P β’ <absorb> P"
},
{
"name": "persistently_elim",
"content": "theorem persistently_elim [BI PROP] {P : PROP} [Absorbing P] : <pers> P β’ P"
},
{
"name": "persistently_entails_r",
"content": "theorem persistently_entails_r [BI PROP] {P Q : PROP} (h : P β’ <pers> Q) : P β’ P β <pers> Q"
}
] | [
{
"name": "Iris.Plainly",
"content": "class Plainly (PROP : Type _) where\n plainly : PROP β PROP"
},
{
"name": "Iris.Plainly.plainlyIf",
"content": "def Plainly.plainlyIf [Iris.BI.BIBase PROP] [Plainly PROP] (p : Bool) (P : PROP) : PROP :=\n iprop(if p then β P else P)"
},
{
"name": "Iris.BIPlainly",
"content": "class BIPlainly (PROP : Type _) [Iris.BI PROP] extends Plainly PROP where\n [ne : Iris.OFE.NonExpansive (Plainly.plainly (PROP := PROP))]\n mono {P Q : PROP} : (P β’ Q) β β P β’ β Q\n elim_persistently {P : PROP} : β P β’ <pers> P\n idem {P : PROP} : β P β’ β β P\n plainly_sForall_2 {Ξ¦ : PROP β Prop} : (β p, βΞ¦ pβ β β p) β’ β sForall Ξ¦\n plainly_impl_plainly {P Q : PROP} : (β P β β Q) β’ β (β P β Q)\n emp_intro {P : PROP} : P β’ β emp\n plainly_absorb {P Q : PROP} : β P β Q β’ β P\n later_plainly {P : PROP} : β· β P β£β’ β β· P"
},
{
"name": "Iris.BIPlainlyExists",
"content": "class BIPlainlyExists (PROP : Type _) [Iris.BI PROP] [BIPlainly PROP] where\n plainly_sExists_1 {Ξ¦ : PROP β Prop} : β sExists Ξ¦ β’ β p, βΞ¦ pβ β§ β p"
}
] | [
{
"name": "Iris.BI.persistently_elim_plainly",
"content": "theorem persistently_elim_plainly : <pers> β P β£β’ β P"
},
{
"name": "Iris.BI.plainly_and_sep_assoc",
"content": "theorem plainly_and_sep_assoc : β P β§ (Q β R) β£β’ (β P β§ Q) β R"
}
] | import Iris.BI.Classes
import Iris.BI.BI
import Iris.BI.DerivedLaws
import Iris.Algebra
namespace Iris
open BI
class Plainly (PROP : Type _) where
plainly : PROP β PROP
def Plainly.plainlyIf [Iris.BI.BIBase PROP] [Plainly PROP] (p : Bool) (P : PROP) : PROP :=
iprop(if p then β P else P)
class BIPlainly (PROP : Type _) [Iris.BI PROP] extends Plainly PROP where
[ne : Iris.OFE.NonExpansive (Plainly.plainly (PROP := PROP))]
mono {P Q : PROP} : (P β’ Q) β β P β’ β Q
elim_persistently {P : PROP} : β P β’ <pers> P
idem {P : PROP} : β P β’ β β P
plainly_sForall_2 {Ξ¦ : PROP β Prop} : (β p, βΞ¦ pβ β β p) β’ β sForall Ξ¦
plainly_impl_plainly {P Q : PROP} : (β P β β Q) β’ β (β P β Q)
emp_intro {P : PROP} : P β’ β emp
plainly_absorb {P Q : PROP} : β P β Q β’ β P
later_plainly {P : PROP} : β· β P β£β’ β β· P
class BIPlainlyExists (PROP : Type _) [Iris.BI PROP] [BIPlainly PROP] where
plainly_sExists_1 {Ξ¦ : PROP β Prop} : β sExists Ξ¦ β’ β p, βΞ¦ pβ β§ β p
namespace BI
open Iris.Std
section PlainlyLaws
open BIPlainly
variable [BI PROP] [BIPlainly PROP]
variable {P Q R : PROP} | theorem plainly_sep_dup : β P β£β’ β P β β P := | := by
refine β¨?_, plainly_absorbβ©
refine and_self.2.trans ?_
refine ((and_mono .rfl emp_sep.2).trans plainly_and_sep_assoc.1).trans ?_
exact (sep_mono and_elim_l .rfl).trans .rfl | 6 | 72 | false | Framework |
244 | Iris.BI.later_and | theorem later_and [BI PROP] {P Q : PROP} : β· (P β§ Q) β£β’ β· P β§ β· Q | iris-lean | src/Iris/BI/DerivedLaws.lean | [
"import Iris.BI.Extensions",
"import Iris.Std.TC",
"import Iris.Std.Classes",
"import Iris.BI.BI",
"import src.Iris.Algebra.OFE",
"import src.Iris.BI.BI",
"import Iris.BI.Classes",
"import Iris.Std.Rewrite"
] | [
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "Option.merge",
"module": "Init.Data.Option.Basic"
},
{
"name": "id",
"module": "Init.Prelude"
},
{
"name": "Equivalence",
"module": "Init.Core"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "m",
"module": "QqTest.matching"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Bool",
"module": "Init.Prelude"
}
] | [
{
"name": "macro \"β\" xs:explicitBinders \", \" b:term : term => do",
"content": "macro \"β\" xs:explicitBinders \", \" b:term : term => do\n return β¨β expandExplicitBinders ``BIBase.exists xs bβ©"
},
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y\n\nsyntax:max \"<pers> \" term:40 : term"
},
{
"name": "macro:25 P:term:29 \" β’ \" Q:term:25 : term => ``(BIBase.Entai",
"content": "macro:25 P:term:29 \" β’ \" Q:term:25 : term => ``(BIBase.Entails iprop($P) iprop($Q))\n\ndelab_rule BIBase.Entails\n | `($_ $P $Q) => do ``($(β unpackIprop P) β’ $(β unpackIprop Q))"
},
{
"name": "macro:25 P:term:29 \" β£β’ \" Q:term:29 : term => ``(BiEntails i",
"content": "macro:25 P:term:29 \" β£β’ \" Q:term:29 : term => ``(BiEntails iprop($P) iprop($Q))\n\ndelab_rule BIBase.Entails\n | `($_ iprop(emp) $P) => do ``(β’ $(β unpackIprop P))\n\ndelab_rule BIBase.BiEntails\n | `($_ $P $Q) => do ``($(β unpackIprop P) β£β’ $(β unpackIprop Q))\n\nsyntax \"β\" term \"β\" : term\n\nsyntax:max \"β· \" term:40 : term"
},
{
"name": "macro:max \"iprop(\" P:term \" : \" t:term \")\" : term => `((ipro",
"content": "macro:max \"iprop(\" P:term \" : \" t:term \")\" : term => `((iprop($P) : $t))\n\nsyntax:max \"iprop(\" term \")\" : term\n\nsyntax:max \"<affine> \" term:40 : term\n\nsyntax:max \"β‘ \" term:40 : term\n\nsyntax:max \"<absorb> \" term:40 : term"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(term($t))) => pure t\n | `(iprop($t)) => pure t"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(($P))) => ``((iprop($P)))\n | `(iprop(if $c then $t else $e)) => ``(if $c then iprop($t) else iprop($e))\n | `(iprop(($P : $t))) => ``((iprop($P) : $t))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(emp)) => ``(BIBase.emp)\n | `(iprop(β$Οβ)) => ``(BIBase.pure $Ο)\n | `(iprop($P β§ $Q)) => ``(BIBase.and iprop($P) iprop($Q))\n | `(iprop($P β¨ $Q)) => ``(BIBase.or iprop($P) iprop($Q))\n | `(iprop($P β $Q)) => ``(BIBase.imp iprop($P) iprop($Q))\n | `(iprop(β $xs, $Ξ¨)) => do expandExplicitBinders ``BIBase.exists xs (β ``(iprop($Ξ¨)))\n | `(iprop($P β $Q)) => ``(BIBase.sep iprop($P) iprop($Q))\n | `(iprop($P -β $Q)) => ``(BIBase.wand iprop($P) iprop($Q))\n | `(iprop(<pers> $P)) => ``(BIBase.persistently iprop($P))\n | `(iprop(β· $P)) => ``(BIBase.later iprop($P))\n\ndelab_rule BIBase.emp\n | `($_) => ``(iprop($(mkIdent `emp)))\ndelab_rule BIBase.pure\n | `($_ $Ο) => ``(iprop(β$Οβ))\ndelab_rule BIBase.and\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β§ $(β unpackIprop Q)))\ndelab_rule BIBase.or\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β¨ $(β unpackIprop Q)))\ndelab_rule BIBase.imp\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule BIBase.forall\n | `($_ fun $x:ident => iprop(β $y:ident $[$z:ident]*, $Ξ¨)) => do\n ``(iprop(β $x:ident $y:ident $[$z:ident]*, $Ξ¨))\n | `($_ fun $x:ident => $Ξ¨) => do ``(iprop(β $x:ident, $(β unpackIprop Ξ¨)))\ndelab_rule BIBase.exists\n | `($_ fun $x:ident => iprop(β $y:ident $[$z:ident]*, $Ξ¨)) => do\n ``(iprop(β $x:ident $y:ident $[$z:ident]*, $Ξ¨))\n | `($_ fun $x:ident => $Ξ¨) => do ``(iprop(β $x:ident, $(β unpackIprop Ξ¨)))\ndelab_rule BIBase.sep\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule BIBase.wand\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) -β $(β unpackIprop Q)))\ndelab_rule BIBase.persistently\n | `($_ $P) => do ``(iprop(<pers> $(β unpackIprop P)))\n\ndelab_rule BIBase.pure\n | `($_ True) => ``(iprop($(mkIdent `True)))\n | `($_ False) => ``(iprop($(mkIdent `False)))\ndelab_rule BIBase.imp\n | `($_ $P iprop(False)) => do ``(iprop(Β¬$(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β _%$tk, $Ξ¨)) => ``(BIBase.forall (fun _%$tk => iprop($Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $x:ident, $Ξ¨)) => ``(BIBase.forall (fun $x => iprop($Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β (_%$tk : $t), $Ξ¨)) => ``(BIBase.forall (fun (_%$tk : $t) => iprop($Ξ¨)))\n | `(iprop(β (_%$tk $xs* : $t), $Ξ¨)) =>\n ``(BIBase.forall (fun (_%$tk : $t) => iprop(β ($xs* : $t), $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β ($x:ident : $t), $Ξ¨)) => ``(BIBase.forall (fun ($x : $t) => iprop($Ξ¨)))\n | `(iprop(β ($x:ident $xs* : $t), $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop(β ($xs* : $t), $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β {_%$tk : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun {_%$tk : $t} => iprop($Ξ¨)))\n | `(iprop(β {_%$tk $xs* : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun {_%$tk : $t} => iprop(β {$xs* : $t}, $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β {$x:ident : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop($Ξ¨)))\n | `(iprop(β {$x:ident $xs* : $t}, $Ξ¨)) =>\n ``(BIBase.forall (fun ($x : $t) => iprop(β {$xs* : $t}, $Ξ¨)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $x $y $xs*, $Ξ¨)) => ``(iprop(β $x, β $y $xs*, $Ξ¨))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(True)) => ``(BIBase.pure True)\n | `(iprop(False)) => ``(BIBase.pure False)\n | `(iprop(Β¬$P)) => ``(iprop($P β False))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop($P β $Q)) => ``(iff iprop($P) iprop($Q))\n | `(iprop($P β-β $Q)) => ``(wandIff iprop($P) iprop($Q))\n\ndelab_rule iff\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β $(β unpackIprop Q)))\ndelab_rule wandIff\n | `($_ $P $Q) => do ``(iprop($(β unpackIprop P) β-β $(β unpackIprop Q)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(<affine> $P)) => ``(affinely iprop($P))\n | `(iprop(<absorb> $P)) => ``(absorbingly iprop($P))\n\ndelab_rule affinely\n | `($_ $P) => do ``(iprop(<affine> $(β unpackIprop P)))\ndelab_rule absorbingly\n | `($_ $P) => do ``(iprop(<absorb> $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β‘ $P)) => ``(intuitionistically iprop($P))\n\ndelab_rule intuitionistically\n | `($_ $P) => do ``(iprop(β‘ $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(<pers>?$p $P)) => ``(persistentlyIf $p iprop($P))\n | `(iprop(<affine>?$p $P)) => ``(affinelyIf $p iprop($P))\n | `(iprop(<absorb>?$p $P)) => ``(absorbinglyIf $p iprop($P))\n | `(iprop(β‘?$p $P)) => ``(intuitionisticallyIf $p iprop($P))\n\ndelab_rule persistentlyIf\n | `($_ $p $P) => do ``(iprop(<pers>?$p $(β unpackIprop P)))\ndelab_rule affinelyIf\n | `($_ $p $P) => do ``(iprop(<affine>?$p $(β unpackIprop P)))\ndelab_rule absorbinglyIf\n | `($_ $p $P) => do ``(iprop(<absorb>?$p $(β unpackIprop P)))\ndelab_rule intuitionisticallyIf\n | `($_ $p $P) => do ``(iprop(β‘?$p $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β·^[$n] $P)) => ``(laterN $n iprop($P))\n\ndelab_rule laterN\n | `($_ $n $P) => do ``(iprop(β·^[$n] $(β unpackIprop P)))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(iprop(β $P)) => ``(except0 iprop($P))\n\ndelab_rule except0\n | `($_ $P) => do ``(iprop(β $(β unpackIprop P)))"
},
{
"name": "BIBase",
"content": "class BIBase (PROP : Type u) where\n Entails : PROP β PROP β Prop\n emp : PROP\n pure : Prop β PROP\n and : PROP β PROP β PROP\n or : PROP β PROP β PROP\n imp : PROP β PROP β PROP\n sForall : (PROP β Prop) β PROP\n sExists : (PROP β Prop) β PROP\n sep : PROP β PROP β PROP\n wand : PROP β PROP β PROP\n persistently : PROP β PROP\n later : PROP β PROP"
},
{
"name": "BI",
"content": "class BI (PROP : Type _) extends COFE PROP, BI.BIBase PROP where\n Equiv P Q := P β£β’ Q\n\n entails_preorder : Preorder Entails\n equiv_iff {P Q : PROP} : (P β‘ Q) β P β£β’ Q := by admit /- proof elided -/"
},
{
"name": "liftRel",
"content": "def liftRel (R : Ξ± β Ξ² β Prop) (A : Ξ± β Prop) (B : Ξ² β Prop) : Prop :=\n (β a, A a β β b, B b β§ R a b) β§ (β b, B b β β a, A a β§ R a b)"
},
{
"name": "Preorder",
"content": "class Preorder (R : Relation Ξ±) extends Reflexive R, Transitive R"
},
{
"name": "Reflexive",
"content": "class Reflexive (R : Relation Ξ±) where\n refl {x : Ξ±} : R x x"
},
{
"name": "Relation",
"content": "abbrev Relation (Ξ± : Type _) := Ξ± β Ξ± β Prop"
},
{
"name": "Transitive",
"content": "class Transitive (R : Relation Ξ±) where\n trans {x y z : Ξ±} : R x y β R y z β R x z"
},
{
"name": "NonExpansiveβ",
"content": "class NonExpansiveβ [OFE Ξ±] [OFE Ξ²] [OFE Ξ³] (f : Ξ± β Ξ² β Ξ³) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β β β¦yβ yββ¦, yβ β‘{n}β‘ yβ β f xβ yβ β‘{n}β‘ f xβ yβ"
},
{
"name": "OFE.ContractiveHom.fixpoint_ne",
"content": "instance OFE.ContractiveHom.fixpoint_ne [COFE Ξ±] [Inhabited Ξ±] :\n NonExpansive (ContractiveHom.fixpoint (Ξ± := Ξ±)) where\n ne n f1 f2 H := by admit /- proof elided -/"
},
{
"name": "ContractiveHom",
"content": "@[ext] structure ContractiveHom (Ξ± Ξ² : Type _) [OFE Ξ±] [OFE Ξ²] extends Hom Ξ± Ξ² where\n [contractive : Contractive f]\n ne := ne_of_contractive f"
},
{
"name": "OFE.Option.some.ne",
"content": "instance OFE.Option.some.ne [OFE Ξ±] : OFE.NonExpansive (some : Ξ± β Option Ξ±) := β¨fun _ _ _ => idβ©"
},
{
"name": "Option.merge_ne",
"content": "instance Option.merge_ne [OFE Ξ±] {op : Ξ± β Ξ± β Ξ±} [NonExpansiveβ op] :\n NonExpansiveβ (Option.merge op) where\n ne n x1 x2 Hx y1 y2 Hy := by admit /- proof elided -/"
},
{
"name": "NonExpansive",
"content": "class NonExpansive [OFE Ξ±] [OFE Ξ²] (f : Ξ± β Ξ²) where\n ne : β β¦n xβ xββ¦, xβ β‘{n}β‘ xβ β f xβ β‘{n}β‘ f xβ"
},
{
"name": "COFE.OFunctor.constOF_RFunctor",
"content": "instance COFE.OFunctor.constOF_RFunctor [CMRA B] : RFunctor (constOF B) where\n map f g := by admit /- proof elided -/"
},
{
"name": "IsCOFE",
"content": "class IsCOFE (Ξ± : Type _) [OFE Ξ±] where\n compl : Chain Ξ± β Ξ±\n conv_compl {c : Chain Ξ±} : compl c β‘{n}β‘ c n"
},
{
"name": "Chain",
"content": "structure Chain (Ξ± : Type _) [OFE Ξ±] where\n chain : Nat β Ξ±\n cauchy : n β€ i β chain i β‘{n}β‘ chain n"
},
{
"name": "LawfulBigOp",
"content": "class LawfulBigOp (f : PROP β PROP β PROP) (unit : outParam PROP)\n (eq : outParam (PROP β PROP β Prop)) where\n refl : eq a a\n symm : eq a b β eq b a\n trans : eq a b β eq b c β eq a c\n comm : eq (f a b) (f b a)\n assoc : eq (f (f a b) c) (f a (f b c))\n left_id : eq (f unit a) a\n congr_l : eq a a' β eq (f a b) (f a' b)"
},
{
"name": "intuitionistically",
"content": "def intuitionistically [BIBase PROP] (P : PROP) : PROP := iprop(<affine> <pers> P)"
},
{
"name": "Affine",
"content": "class Affine [BI PROP] (P : PROP) where\n affine : P β’ emp"
},
{
"name": "bigAnd",
"content": "def bigAnd [BIBase PROP] (Ps : List PROP) : PROP := bigOp and iprop(True) Ps"
},
{
"name": "bigOp",
"content": "def bigOp (f : PROP β PROP β PROP) (unit : PROP) : List PROP β PROP\n | [] => unit\n | [P] => P\n | P :: Ps => f P (bigOp f unit Ps)"
},
{
"name": "absorbingly",
"content": "def absorbingly [BIBase PROP] (P : PROP) : PROP := iprop(True β P)"
},
{
"name": "BiEntails",
"content": "structure BiEntails [BIBase PROP] (P Q : PROP) where\n mp : P β’ Q\n mpr : Q β’ P"
},
{
"name": "persistentlyIf",
"content": "def persistentlyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then <pers> P else P)"
},
{
"name": "intuitionisticallyIf",
"content": "def intuitionisticallyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then β‘ P else P)"
},
{
"name": "bigSep",
"content": "def bigSep [BIBase PROP] (Ps : List PROP) : PROP := bigOp sep iprop(emp) Ps"
},
{
"name": "affinely",
"content": "def affinely [BIBase PROP] (P : PROP) : PROP := iprop(emp β§ P)"
},
{
"name": "bigOr",
"content": "def bigOr [BIBase PROP] (Ps : List PROP) : PROP := bigOp or iprop(False) Ps"
},
{
"name": "absorbinglyIf",
"content": "def absorbinglyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then <absorb> P else P)"
},
{
"name": "affinelyIf",
"content": "def affinelyIf [BIBase PROP] (p : Bool) (P : PROP) : PROP := iprop(if p then <affine> P else P)"
},
{
"name": "wandIff",
"content": "def wandIff [BIBase PROP] (P Q : PROP) : PROP := iprop((P -β Q) β§ (Q -β P))"
},
{
"name": "scoped infix:40 \" β‘ \" => OFE.Equiv",
"content": "scoped infix:40 \" β‘ \" => OFE.Equiv"
},
{
"name": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y",
"content": "scoped notation:40 x \" β‘{\" n \"}β‘ \" y:41 => OFE.Dist n x y"
},
{
"name": "infixr:25 \" -c> \" => ContractiveHom",
"content": "infixr:25 \" -c> \" => ContractiveHom"
},
{
"name": "notation:40 \"[β§] \" Ps:max => bigAnd Ps",
"content": "notation:40 \"[β§] \" Ps:max => bigAnd Ps"
},
{
"name": "notation:40 \"[β¨] \" Ps:max => bigOr Ps",
"content": "notation:40 \"[β¨] \" Ps:max => bigOr Ps"
},
{
"name": "notation:40 \"[β] \" Ps:max => bigSep Ps",
"content": "notation:40 \"[β] \" Ps:max => bigSep Ps"
}
] | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "Dist.trans",
"content": "theorem Dist.trans [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ y β y β‘{n}β‘ z β x β‘{n}β‘ z"
},
{
"name": "BIBase.BiEntails.trans",
"content": "theorem BIBase.BiEntails.trans [BI PROP] {P Q R : PROP} (h1 : P β£β’ Q) (h2 : Q β£β’ R) : P β£β’ R"
},
{
"name": "BIBase.Entails.trans",
"content": "theorem BIBase.Entails.trans [BI PROP] {P Q R : PROP} (h1 : P β’ Q) (h2 : Q β’ R) : P β’ R"
},
{
"name": "Equiv.trans",
"content": "theorem Equiv.trans [OFE Ξ±] {x : Ξ±} : x β‘ y β y β‘ z β x β‘ z"
},
{
"name": "equiv_eqv",
"content": "theorem equiv_eqv [ofe : OFE Ξ±] : Equivalence ofe.Equiv"
},
{
"name": "Dist.symm",
"content": "@[symm] theorem Dist.symm [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ y β y β‘{n}β‘ x"
},
{
"name": "Dist.rfl",
"content": "@[simp, refl] theorem Dist.rfl [OFE Ξ±] {n} {x : Ξ±} : x β‘{n}β‘ x"
},
{
"name": "DistLater.trans",
"content": "theorem DistLater.trans [OFE Ξ±] {n} {x : Ξ±} (h1 : DistLater n x y) (h2 : DistLater n y z) :\n DistLater n x z"
}
] | [] | [
{
"name": "Iris.BI.and_symm",
"content": "theorem and_symm [BI PROP] {P Q : PROP} : P β§ Q β’ Q β§ P"
},
{
"name": "Iris.BI.imp_intro'",
"content": "theorem imp_intro' [BI PROP] {P Q R : PROP} (h : Q β§ P β’ R) : P β’ Q β R"
},
{
"name": "Iris.BI.imp_elim'",
"content": "theorem imp_elim' [BI PROP] {P Q R : PROP} (h : Q β’ P β R) : P β§ Q β’ R"
},
{
"name": "Iris.BI.forall_intro",
"content": "theorem forall_intro [BI PROP] {P : PROP} {Ξ¨ : Ξ± β PROP} (h : β a, P β’ Ξ¨ a) : P β’ β a, Ξ¨ a"
},
{
"name": "Iris.BI.forall_elim",
"content": "theorem forall_elim [BI PROP] {Ξ¨ : Ξ± β PROP} (a : Ξ±) : (β a, Ξ¨ a) β’ Ξ¨ a"
},
{
"name": "Iris.BI.forall_mono",
"content": "@[rw_mono_rule]\ntheorem forall_mono [BI PROP] {Ξ¦ Ξ¨ : Ξ± β PROP} (h : β a, Ξ¦ a β’ Ξ¨ a) : (β a, Ξ¦ a) β’ β a, Ξ¨ a"
},
{
"name": "Iris.BI.and_self",
"content": "theorem and_self [BI PROP] {P : PROP} : P β§ P β£β’ P"
},
{
"name": "Iris.BI.and_comm",
"content": "theorem and_comm [BI PROP] {P Q : PROP} : P β§ Q β£β’ Q β§ P"
},
{
"name": "Iris.BI.pure_elim",
"content": "theorem pure_elim [BI PROP] (Ο : Prop) {Q R : PROP} (h1 : Q β’ βΟβ) (h2 : Ο β Q β’ R) : Q β’ R"
},
{
"name": "Iris.BI.and_forall_bool",
"content": "theorem and_forall_bool [BI PROP] {P Q : PROP} :\n P β§ Q β£β’ Β«forallΒ» (fun b : Bool => if b then P else Q)"
},
{
"name": "Iris.BI.later_forall_2",
"content": "theorem later_forall_2 [BI PROP] {Ξ±} {Ξ¦ : Ξ± β PROP} : (β a, β· Ξ¦ a) β’ β· β a, Ξ¦ a"
},
{
"name": "Iris.BI.later_forall",
"content": "theorem later_forall [BI PROP] {Ξ¦ : Ξ± β PROP} :\n β· (β a, Ξ¦ a) β£β’ (β a, β· Ξ¦ a)"
}
] | import Iris.BI.Classes
import Iris.BI.Extensions
import Iris.BI.BI
import Iris.Std.Classes
import Iris.Std.Rewrite
import Iris.Std.TC
namespace Iris.BI
open Iris.Std BI | theorem later_and [BI PROP] {P Q : PROP} : β· (P β§ Q) β£β’ β· P β§ β· Q := | := by
constructor
Β· refine (later_mono and_forall_bool.mp).trans ?_
refine .trans ?_ and_forall_bool.mpr
refine (later_forall).mp.trans (forall_mono ?_)
exact (Β·.casesOn .rfl .rfl)
Β· refine .trans ?_ (later_mono and_forall_bool.mpr)
refine and_forall_bool.mp.trans ?_
refine .trans (forall_mono ?_) later_forall.mpr
exact (Β·.casesOn .rfl .rfl) | 6 | 59 | false | Framework |
245 | Juvix.Core.Main.Value.Approx.Indexed.preserved_step | lemma Value.Approx.Indexed.preserved_step {k} :
(β k' < k, Preservation k') β Preservation k | juvix-lean | Juvix/Core/Main/Semantics/Approx/Indexed.lean | [
"import Juvix.Utils",
"import Juvix.Core.Main.Semantics.Eval.Indexed",
"import Mathlib.Tactic.Linarith",
"import Mathlib.Data.List.Forall2",
"import Juvix.Core.Main.Semantics.Eval",
"import Aesop"
] | [
{
"name": "BEq",
"module": "Init.Prelude"
},
{
"name": "DecidableEq",
"module": "Init.Prelude"
},
{
"name": "Inhabited",
"module": "Init.Prelude"
},
{
"name": "Int",
"module": "Init.Data.Int.Basic"
},
{
"name": "String",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "closure",
"module": "Mathlib.Topology.Defs.Basic"
},
{
"name": "List.Forallβ",
"module": "Batteries.Data.List.Basic"
},
{
"name": "List.map",
"module": "Init.Prelude"
},
{
"name": "Prod",
"module": "Init.Prelude"
},
{
"name": "reduceCtorEq",
"module": "Lean.Meta.Tactic.Simp.BuiltinSimprocs.Core"
},
{
"name": "List.Forallβ.cons",
"module": "Batteries.Data.List.Basic"
},
{
"name": "List.Forallβ.nil",
"module": "Batteries.Data.List.Basic"
}
] | [
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β\" => Eval.Defined env e",
"content": "notation:40 env:40 \" β’ \" e:40 \" β\" => Eval.Defined env e"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Inde",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Indexed n env e v"
},
{
"name": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Inde",
"content": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Indexed n v v'"
},
{
"name": "notation:40 e:40 \" β²(\" n:40 \")β¨\" env:40 \", \" env':40 \"β© \" e'",
"content": "notation:40 e:40 \" β²(\" n:40 \")β¨\" env:40 \", \" env':40 \"β© \" e':40 => Expr.Approx.Param.Indexed n env env' e e'"
},
{
"name": "notation:40 envβ:40 \" β²β'(\" n:40 \") \" envβ:40 => Env.Approx.",
"content": "notation:40 envβ:40 \" β²β'(\" n:40 \") \" envβ:40 => Env.Approx.Indexed' n envβ envβ\n\nsyntax:100 expr:100 ppSpace expr:101 : expr\n\nsyntax:50 expr:50 \" + \" expr:51 : expr\n\nsyntax:50 expr:50 \" - \" expr:50 : expr\n\nsyntax:60 expr:60 \" * \" expr:61 : expr\n\nsyntax:60 expr:60 \" / \" expr:60 : expr"
},
{
"name": "notation:40 e:40 \" β²'(\" n:40 \") \" e':40 => Expr.Approx.Index",
"content": "notation:40 e:40 \" β²'(\" n:40 \") \" e':40 => Expr.Approx.Indexed' n e e'"
},
{
"name": "notation:40 v:40 \" β²β'(\" n:40 \") \" v':40 => Object.Approx.In",
"content": "notation:40 v:40 \" β²β'(\" n:40 \") \" v':40 => Object.Approx.Indexed' n v v'\n\nsyntax \"case \" expr \" of \" cases \" end\" : expr"
},
{
"name": "notation:40 argsβ:40 \" β²β(\" n:40 \") \" argsβ:40 => List.Foral",
"content": "notation:40 argsβ:40 \" β²β(\" n:40 \") \" argsβ:40 => List.Forallβ (Value.Approx.Indexed n) argsβ argsβ"
},
{
"name": "macro \"invert\" h:term : tactic => `(tactic| (cases ($h).inve",
"content": "macro \"invert\" h:term : tactic => `(tactic| (cases ($h).invert <;> try clear $h))\n\nsyntax \"let \" ident \" := \" expr \" in \" expr : expr"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(βͺ$s:ident β― $i:numβ«) => `(Expr.var $(Lean.Syntax.mkStrLit s.getId.toString) $i)\n | `(βͺ$num:numβ«) => `(Expr.const (Constant.int $num))\n | `(βͺ$s:strβ«) => `(Expr.const (Constant.string $s))\n | `(βͺΟ
β«) => `(Expr.unit)\n | `(βͺ$eβ:expr $eβ:exprβ«) => `(Expr.app βͺ$eββ« βͺ$eββ«)\n | `(βͺΞ» $s:ident $e:exprβ«) => `(Expr.lambda $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eβ«)\n | `(βͺΞ» $ss:ident* . $e:exprβ«) => mkLambdas ss e\n | `(βͺ $s:ident β«) => `(Expr.constr $(Lean.Syntax.mkStrLit s.getId.toString))\n | `(βͺ $s:ident $es:expr* β«) => mkConstrApp s es\n | `(βͺ$eβ + $eββ«) => `(Expr.binop BinaryOp.add_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ - $eββ«) => `(Expr.binop BinaryOp.sub_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ * $eββ«) => `(Expr.binop BinaryOp.mul_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ / $eββ«) => `(Expr.binop BinaryOp.div_int βͺ$eββ« βͺ$eββ«)\n | `(βͺlet $s:ident := $eβ:expr in $eβ:exprβ«) => `(Expr.save $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eββ« βͺ$eββ«)\n | `(βͺletrec $s:ident := $eβ:expr in $eβ:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.save $name (Expr.recur $name βͺ$eββ«) βͺ$eββ«)\n | `(βͺrec $s:ident $e:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.recur $name βͺ$eβ«)\n | `(βͺβ₯β«) => `(Expr.fail)\n | `(βͺcases| | $s:ident => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« Expr.fail)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« Expr.fail)\n | `(βͺcases| | _ => $e:expr β«) =>\n `(βͺ$eβ«)\n | `(βͺcase $e:expr of $cs:cases endβ«) => do\n `(Expr.save \"_case_\" βͺ$eβ« βͺcases|$csβ«)\n | `(βͺ($e)β«) => `(βͺ$eβ«)\n\n inductive Value : Type where\n | unit : Value\n | const : Constant β Value\n | constr_app : (constr : Name) β (args_rev : List Value) β Value\n | closure : (env : List Object) β (value : Expr) β Value\n deriving Inhabited"
},
{
"name": "cons_value",
"content": "abbrev cons_value (v : Value) (env : Env) : Env := Object.value v :: env\n\n inductive Object : Type where\n | value : Value β Object\n | delayed : (env : List Object) β Expr β Object\n deriving Inhabited"
},
{
"name": "Expr",
"content": "inductive Expr : Type where\n | var : (name : String) β (index : Nat) β Expr\n | unit : Expr\n | const : Constant β Expr\n | constr : Name β Expr\n | app : Expr β Expr β Expr\n | constr_app : Expr β Expr β Expr\n | binop : (oper : BinaryOp) β (argβ argβ : Expr) β Expr\n | lambda : (var_name : String) β (body : Expr) β Expr\n | save : (var_name : String) β (value : Expr) β (body : Expr) β Expr\n | branch : (constr : Name) β (var_names : List Name) β (body : Expr) β (next : Expr) β Expr\n | recur : (var_name : Name) β (body : Expr) β Expr\n | fail : Expr\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "BinaryOp",
"content": "inductive BinaryOp : Type where\n | add_int : BinaryOp\n | sub_int : BinaryOp\n | mul_int : BinaryOp\n | div_int : BinaryOp\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Constant",
"content": "inductive Constant : Type where\n | int : Int β Constant\n | string : String β Constant\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Name",
"content": "abbrev Name : Type := String"
},
{
"name": "Env",
"content": "abbrev Env : Type := List Object"
},
{
"name": "Value.Approx",
"content": "def Value.Approx (v v' : Value) : Prop :=\n β n, v β²α΅₯(n) v'"
},
{
"name": "Expr.Approx",
"content": "def Expr.Approx (eβ eβ : Expr) : Prop :=\n β envβ envβ, envβ β²β envβ β eβ β²β¨envβ, envββ© eβ"
},
{
"name": "Expr.Approx.Param",
"content": "def Expr.Approx.Param (envβ envβ : Env) (eβ eβ : Expr) : Prop :=\n (β vβ, envβ β’ eβ β¦ vβ β β vβ, envβ β’ eβ β¦ vβ β§ vβ β²α΅₯ vβ)"
},
{
"name": "Object.Approx",
"content": "inductive Object.Approx : Object β Object β Prop where\n | value {vβ vβ} : vβ β²α΅₯ vβ β Object.Approx (Object.value vβ) (Object.value vβ)\n | delayed {envβ envβ eβ eβ} :\n eβ β²β¨envβ, envββ© eβ β\n Object.Approx (Object.delayed envβ eβ) (Object.delayed envβ eβ)"
},
{
"name": "Env.Approx",
"content": "def Env.Approx : (envβ envβ : Env) β Prop :=\n List.Forallβ Object.Approx"
},
{
"name": "Eval.Indexed",
"content": "inductive Eval.Indexed : Nat β Env β Expr β Value β Prop where\n | var {n env name idx val} :\n env[idx]? = some (Object.value val) β\n Eval.Indexed n env (Expr.var name idx) val\n | var_rec {n env name idx env' expr val} :\n env[idx]? = some (Object.delayed env' expr) β\n Eval.Indexed n env' expr val β\n Eval.Indexed n env (Expr.var name idx) val\n | unit {n env} :\n Eval.Indexed n env Expr.unit Value.unit\n | const {n env c} :\n Eval.Indexed n env (Expr.const c) (Value.const c)\n | constr {n env name} :\n Eval.Indexed n env (Expr.constr name) (Value.constr_app name [])\n | app {n nβ nβ env env' f body arg val val'} :\n nβ + nβ + 1 β€ n β\n Eval.Indexed nβ env f (Value.closure env' body) β\n Eval.Indexed (nβ + 1) env arg val β\n Eval.Indexed nβ (val β· env') body val' β\n Eval.Indexed n env (Expr.app f arg) val'\n | constr_app {n n' env ctr ctr_name ctr_args_rev arg val} :\n n' < n β\n Eval.Indexed n env ctr (Value.constr_app ctr_name ctr_args_rev) β\n Eval.Indexed n' env arg val β\n Eval.Indexed n env (Expr.constr_app ctr arg) (Value.constr_app ctr_name (val :: ctr_args_rev))\n | binop {n env op argβ argβ valβ valβ} :\n Eval.Indexed n env argβ (Value.const (Constant.int valβ)) β\n Eval.Indexed n env argβ (Value.const (Constant.int valβ)) β\n Eval.Indexed n env (Expr.binop op argβ argβ) (Value.const (Constant.int (eval_binop_int op valβ valβ)))\n | lambda {n env name body} :\n Eval.Indexed n env (Expr.lambda name body) (Value.closure env body)\n | save {n nβ nβ env name value body val val'} :\n nβ + nβ β€ n β\n Eval.Indexed nβ env value val β\n Eval.Indexed nβ (val β· env) body val' β\n Eval.Indexed n env (Expr.save name value body) val'\n | branch_matches {n n' env name args_rev body val} :\n n' < n β\n Eval.Indexed n' (args_rev.map Object.value ++ env) body val β\n Eval.Indexed n (Value.constr_app name args_rev β· env) (Expr.branch name _ body _) val\n | branch_fails {n env name name' args_rev next val} :\n name β name' β\n Eval.Indexed n (Value.constr_app name args_rev β· env) next val β\n Eval.Indexed n (Value.constr_app name args_rev β· env) (Expr.branch name' _ _ next) val\n | recur {n n' env name body val} :\n n' < n β\n Eval.Indexed n' (Object.delayed env (Expr.recur name body) :: env) body val β\n Eval.Indexed n env (Expr.recur name body) val"
},
{
"name": "Eval",
"content": "@[aesop unsafe constructors]\ninductive Eval : Env β Expr β Value β Prop where\n | var {env name idx val} :\n env[idx]? = some (Object.value val) β\n Eval env (Expr.var name idx) val\n | var_rec {env name idx env' expr val} :\n env[idx]? = some (Object.delayed env' expr) β\n Eval env' expr val β\n Eval env (Expr.var name idx) val\n | unit {env} :\n Eval env Expr.unit Value.unit\n | const {env c} :\n Eval env (Expr.const c) (Value.const c)\n | constr {env name} :\n Eval env (Expr.constr name) (Value.constr_app name [])\n | app {env env' f body arg val val'} :\n Eval env f (Value.closure env' body) β\n Eval env arg val β\n Eval (val β· env') body val' β\n Eval env (Expr.app f arg) val'\n | constr_app {env ctr ctr_name ctr_args_rev arg val} :\n Eval env ctr (Value.constr_app ctr_name ctr_args_rev) β\n Eval env arg val β\n Eval env (Expr.constr_app ctr arg) (Value.constr_app ctr_name (val :: ctr_args_rev))\n | binop {env op argβ argβ valβ valβ} :\n Eval env argβ (Value.const (Constant.int valβ)) β\n Eval env argβ (Value.const (Constant.int valβ)) β\n Eval env (Expr.binop op argβ argβ) (Value.const (Constant.int (eval_binop_int op valβ valβ)))\n | lambda {env name body} :\n Eval env (Expr.lambda name body) (Value.closure env body)\n | save {env name value body val val'} :\n Eval env value val β\n Eval (val β· env) body val' β\n Eval env (Expr.save name value body) val'\n | branch_matches {env name args_rev body val} :\n Eval (args_rev.map Object.value ++ env) body val β\n Eval (Value.constr_app name args_rev β· env) (Expr.branch name _ body _) val\n | branch_fails {env name name' args_rev next val} :\n name β name' β\n Eval (Value.constr_app name args_rev β· env) next val β\n Eval (Value.constr_app name args_rev β· env) (Expr.branch name' _ _ next) val\n | recur {env name body val} :\n Eval (Object.delayed env (Expr.recur name body) :: env) body val β\n Eval env (Expr.recur name body) val"
},
{
"name": "Context",
"content": "inductive Context : Type where\n | hole : Context\n | app_left : Context β Expr β Context\n | app_right : Expr β Context β Context\n | constr_app_left : Context β Expr β Context\n | constr_app_right : Expr β Context β Context\n | binop_left : (oper : BinaryOp) β (argβ : Context) β (argβ : Expr) β Context\n | binop_right : (oper : BinaryOp) β (argβ : Expr) β (argβ : Context) β Context\n | lambda : (var_name : String) β (body : Context) β Context\n | save_left : (var_name : String) β (value : Context) β (body : Expr) β Context\n | save_right : (var_name : String) β (value : Expr) β (body : Context) β Context\n | branch_left : (constr : Name) β (var_names : List Name) β (body : Context) β (next : Expr) β Context\n | branch_right : (constr : Name) β (var_names : List Name) β (body : Expr) β (next : Context) β Context\n | recur : (var_name : Name) β (ctx : Context) β Context\n deriving Inhabited, BEq"
},
{
"name": "eval_binop_int",
"content": "def eval_binop_int (op : BinaryOp) (iβ iβ : Int) : Int :=\n match op with\n | BinaryOp.add_int => iβ + iβ\n | BinaryOp.sub_int => iβ - iβ\n | BinaryOp.mul_int => iβ * iβ\n | BinaryOp.div_int => iβ / iβ"
},
{
"name": "infixr:50 \" β· \" => cons_value",
"content": "infixr:50 \" β· \" => cons_value"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Inde",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Indexed n env e v"
},
{
"name": "notation:40 v:40 \" β²α΅₯ \" v':40 => Value.Approx v v'",
"content": "notation:40 v:40 \" β²α΅₯ \" v':40 => Value.Approx v v'"
},
{
"name": "notation:40 e:40 \" β²β¨\" env:40 \", \" env':40 \"β© \" e':40 => Exp",
"content": "notation:40 e:40 \" β²β¨\" env:40 \", \" env':40 \"β© \" e':40 => Expr.Approx.Param env env' e e'"
},
{
"name": "notation:40 v:40 \" β²β \" v':40 => Object.Approx v v'",
"content": "notation:40 v:40 \" β²β \" v':40 => Object.Approx v v'"
},
{
"name": "notation:40 envβ:40 \" β²β \" envβ:40 => Env.Approx envβ envβ",
"content": "notation:40 envβ:40 \" β²β \" envβ:40 => Env.Approx envβ envβ"
},
{
"name": "notation:40 eβ:40 \" β² \" eβ:40 => Expr.Approx eβ eβ",
"content": "notation:40 eβ:40 \" β² \" eβ:40 => Expr.Approx eβ eβ"
},
{
"name": "infixl:100 \" @@ \" => Expr.app",
"content": "infixl:100 \" @@ \" => Expr.app"
}
] | [
{
"name": "List.Forallβ.get",
"module": "Mathlib.Data.List.Forall2"
},
{
"name": "List.Forallβ.length_eq",
"module": "Mathlib.Data.List.Forall2"
},
{
"name": "List.getElem?_eq_some_iff",
"module": "Init.Data.List.Lemmas"
},
{
"name": "List.get_eq_getElem",
"module": "Init.Data.List.Lemmas"
},
{
"name": "forall_true_left",
"module": "Mathlib.Logic.Basic"
},
{
"name": "and_self",
"module": "Init.SimpLemmas"
},
{
"name": "exists_and_left",
"module": "Init.PropLemmas"
},
{
"name": "exists_const",
"module": "Init.PropLemmas"
},
{
"name": "exists_eq_left'",
"module": "Init.PropLemmas"
},
{
"name": "false_and",
"module": "Init.SimpLemmas"
},
{
"name": "false_or",
"module": "Init.SimpLemmas"
},
{
"name": "implies_true",
"module": "Init.SimpLemmas"
},
{
"name": "or_false",
"module": "Init.SimpLemmas"
},
{
"name": "true_and",
"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": "Juvix.Core.Main.Value.Approx.Indexed",
"content": "def Value.Approx.Indexed (n : Nat) (vβ vβ : Value) : Prop :=\n (vβ = Value.unit β§ vβ = Value.unit) β¨\n (β c, vβ = Value.const c β§ vβ = Value.const c) β¨\n (β ctr_name args_rev args_rev',\n vβ = Value.constr_app ctr_name args_rev β§\n vβ = Value.constr_app ctr_name args_rev' β§\n (β k < n, List.Forallβ (Value.Approx.Indexed k) args_rev args_rev')) β¨\n (β envβ bodyβ envβ bodyβ,\n vβ = Value.closure envβ bodyβ β§\n vβ = Value.closure envβ bodyβ β§\n (β nβ nβ, nβ + nβ < n β\n β aβ aβ rβ,\n Value.Approx.Indexed (nβ + nβ) aβ aβ β\n aβ β· envβ β’ bodyβ β¦(nβ) rβ β\n β rβ,\n aβ β· envβ β’ bodyβ β¦ rβ β§\n Value.Approx.Indexed nβ rβ rβ))"
},
{
"name": "Juvix.Core.Main.Expr.Approx.Param.Indexed",
"content": "def Expr.Approx.Param.Indexed (n : Nat) (envβ envβ : Env) (eβ eβ : Expr) : Prop :=\n (β nβ nβ vβ, nβ + nβ β€ n β envβ β’ eβ β¦(nβ) vβ β β vβ, envβ β’ eβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ)"
},
{
"name": "Juvix.Core.Main.Object.Approx.Indexed'",
"content": "inductive Object.Approx.Indexed' (n : Nat) : Object β Object β Prop where\n | value {vβ vβ} :\n vβ β²α΅₯(n) vβ β\n Object.Approx.Indexed' n (Object.value vβ) (Object.value vβ)\n | delayed {envβ envβ eβ eβ} :\n eβ β²(n)β¨envβ, envββ© eβ β\n Object.Approx.Indexed' n (Object.delayed envβ eβ) (Object.delayed envβ eβ)\n | delayed_eq {envβ envβ e} :\n List.Forallβ (Object.Approx.Indexed' n) envβ envβ β\n Object.Approx.Indexed' n (Object.delayed envβ e) (Object.delayed envβ e)"
},
{
"name": "Juvix.Core.Main.Env.Approx.Indexed'",
"content": "def Env.Approx.Indexed' (n : Nat) : (envβ envβ : Env) β Prop :=\n List.Forallβ (Object.Approx.Indexed' n)"
},
{
"name": "Juvix.Core.Main.Expr.Approx.Indexed'",
"content": "def Expr.Approx.Indexed' (n : Nat) (eβ eβ : Expr) : Prop :=\n (β nβ nβ vβ, nβ + nβ β€ n β\n β envβ envβ, envβ β²β'(nβ + nβ) envβ β envβ β’ eβ β¦(nβ) vβ β β vβ, envβ β’ eβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ)"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.Inversion",
"content": "@[aesop safe cases]\ninductive Value.Approx.Indexed.Inversion (n : Nat) : Value β Value β Prop where\n | unit : Value.Approx.Indexed.Inversion n Value.unit Value.unit\n | const {c} : Value.Approx.Indexed.Inversion n (Value.const c) (Value.const c)\n | constr_app {ctr_name args_rev args_rev'} :\n (β k < n, args_rev β²β(k) args_rev') β\n Value.Approx.Indexed.Inversion n (Value.constr_app ctr_name args_rev) (Value.constr_app ctr_name args_rev')\n | closure {envβ bodyβ envβ bodyβ} :\n (β nβ nβ, nβ + nβ < n β\n β aβ aβ vβ,\n aβ β²α΅₯(nβ + nβ) aβ β\n aβ β· envβ β’ bodyβ β¦(nβ) vβ β\n β vβ, aβ β· envβ β’ bodyβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ) β\n Value.Approx.Indexed.Inversion n (Value.closure envβ bodyβ) (Value.closure envβ bodyβ)"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.Preservation",
"content": "def Value.Approx.Indexed.Preservation (k : Nat) : Prop :=\n β m n env env' e v,\n m + n < k β\n env β²β'(m + n) env' β\n env β’ e β¦(n) v β\n β v', env' β’ e β¦ v' β§ v β²α΅₯(m) v'"
}
] | [
{
"name": "Juvix.Core.Main.Env.Approx.Indexed'.get",
"content": "lemma Env.Approx.Indexed'.get {n i : Nat} {env env' oβ}\n (hβ : env β²β'(n) env')\n (hβ : env[i]? = some oβ) :\n β oβ, env'[i]? = some oβ β§ oβ β²β'(n) oβ"
},
{
"name": "Juvix.Core.Main.Env.Approx.Indexed'.value",
"content": "lemma Env.Approx.Indexed'.value {n i : Nat} {env env' v}\n (hβ : env β²β'(n) env')\n (hβ : env[i]? = some (Object.value v)) :\n β v', env'[i]? = some (Object.value v') β§ v β²α΅₯(n) v'"
},
{
"name": "Juvix.Core.Main.Env.Approx.Indexed'.delayed",
"content": "lemma Env.Approx.Indexed'.delayed {n i : Nat} {envβ envβ env e}\n (hβ : envβ β²β'(n) envβ)\n (hβ : envβ[i]? = some (Object.delayed env e)) :\n (β env' e', e β²(n)β¨env, env'β© e' β§ envβ[i]? = some (Object.delayed env' e')) β¨\n β env', env β²β'(n) env' β§ envβ[i]? = some (Object.delayed env' e)"
},
{
"name": "Juvix.Core.Main.Env.Approx.Indexed'.from_value",
"content": "lemma Env.Approx.Indexed'.from_value {n lβ lβ} (h : lβ β²β(n) lβ) :\n List.map Object.value lβ β²β'(n) List.map Object.value lβ"
},
{
"name": "Juvix.Core.Main.Env.Approx.Indexed'.concat",
"content": "lemma Env.Approx.Indexed'.concat {n envβ envβ envβ' envβ'}\n (hβ : envβ β²β'(n) envβ')\n (hβ : envβ β²β'(n) envβ') :\n envβ ++ envβ β²β'(n) envβ' ++ envβ'"
},
{
"name": "Juvix.Core.Main.Env.Approx.Indexed'.cons",
"content": "lemma Env.Approx.Indexed'.cons {n oβ oβ envβ envβ}\n (hβ : oβ β²β'(n) oβ)\n (hβ : envβ β²β'(n) envβ) :\n oβ :: envβ β²β'(n) oβ :: envβ"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.unit",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.unit {n} : Value.unit β²α΅₯(n) Value.unit"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.const",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.const {n c} : Value.const c β²α΅₯(n) Value.const c"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.constr_app",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.constr_app {n ctr_name args_rev args_rev'} :\n (β k < n, args_rev β²β(k) args_rev') β\n Value.constr_app ctr_name args_rev β²α΅₯(n) Value.constr_app ctr_name args_rev'"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.closure",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.closure {n envβ bodyβ envβ bodyβ} :\n (β nβ nβ, nβ + nβ < n β\n β aβ aβ vβ,\n aβ β²α΅₯(nβ + nβ) aβ β\n aβ β· envβ β’ bodyβ β¦(nβ) vβ β\n β vβ, aβ β· envβ β’ bodyβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ) β\n Value.closure envβ bodyβ β²α΅₯(n) Value.closure envβ bodyβ"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.anti_monotone",
"content": "lemma Value.Approx.Indexed.anti_monotone {n n' vβ vβ} (h : vβ β²α΅₯(n) vβ) (h' : n' β€ n) : vβ β²α΅₯(n') vβ"
},
{
"name": "Juvix.Core.Main.Expr.Approx.Param.Indexed.anti_monotone",
"content": "lemma Expr.Approx.Param.Indexed.anti_monotone {n n' envβ envβ eβ eβ}\n (h : eβ β²(n)β¨envβ, envββ© eβ)\n (h' : n' β€ n)\n : eβ β²(n')β¨envβ, envββ© eβ"
},
{
"name": "Juvix.Core.Main.Expr.Approx.Indexed'.anti_monotone",
"content": "lemma Expr.Approx.Indexed'.anti_monotone {n n' eβ eβ}\n (h : eβ β²'(n) eβ)\n (h' : n' β€ n)\n : eβ β²'(n') eβ"
},
{
"name": "Juvix.Core.Main.Env.Approx.Indexed'.anti_monotone",
"content": " lemma Env.Approx.Indexed'.anti_monotone {n n' envβ envβ}\n (h : envβ β²β'(n) envβ)\n (h' : n' β€ n)\n : envβ β²β'(n') envβ"
},
{
"name": "Juvix.Core.Main.Object.Approx.Indexed'.anti_monotone",
"content": " lemma Object.Approx.Indexed'.anti_monotone {n n' oβ oβ} (h : oβ β²β'(n) oβ) (h' : n' β€ n) : oβ β²β'(n') oβ"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.Preservation.anti_monotone",
"content": "lemma Value.Approx.Indexed.Preservation.anti_monotone {k k'} (h : Value.Approx.Indexed.Preservation k) (h' : k' β€ k) : Value.Approx.Indexed.Preservation k'"
}
] | import Juvix.Core.Main.Semantics.Eval
import Juvix.Core.Main.Semantics.Eval.Indexed
import Juvix.Utils
import Mathlib.Tactic.Linarith
import Mathlib.Data.List.Forall2
import Aesop
namespace Juvix.Core.Main
def Value.Approx.Indexed (n : Nat) (vβ vβ : Value) : Prop :=
(vβ = Value.unit β§ vβ = Value.unit) β¨
(β c, vβ = Value.const c β§ vβ = Value.const c) β¨
(β ctr_name args_rev args_rev',
vβ = Value.constr_app ctr_name args_rev β§
vβ = Value.constr_app ctr_name args_rev' β§
(β k < n, List.Forallβ (Value.Approx.Indexed k) args_rev args_rev')) β¨
(β envβ bodyβ envβ bodyβ,
vβ = Value.closure envβ bodyβ β§
vβ = Value.closure envβ bodyβ β§
(β nβ nβ, nβ + nβ < n β
β aβ aβ rβ,
Value.Approx.Indexed (nβ + nβ) aβ aβ β
aβ β· envβ β’ bodyβ β¦(nβ) rβ β
β rβ,
aβ β· envβ β’ bodyβ β¦ rβ β§
Value.Approx.Indexed nβ rβ rβ))
notation:40 v:40 " β²α΅₯(" n:40 ") " v':40 => Value.Approx.Indexed n v v'
notation:40 argsβ:40 " β²β(" n:40 ") " argsβ:40 => List.Forallβ (Value.Approx.Indexed n) argsβ argsβ
def Expr.Approx.Param.Indexed (n : Nat) (envβ envβ : Env) (eβ eβ : Expr) : Prop :=
(β nβ nβ vβ, nβ + nβ β€ n β envβ β’ eβ β¦(nβ) vβ β β vβ, envβ β’ eβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ)
notation:40 e:40 " β²(" n:40 ")β¨" env:40 ", " env':40 "β© " e':40 => Expr.Approx.Param.Indexed n env env' e e'
inductive Object.Approx.Indexed' (n : Nat) : Object β Object β Prop where
| value {vβ vβ} :
vβ β²α΅₯(n) vβ β
Object.Approx.Indexed' n (Object.value vβ) (Object.value vβ)
| delayed {envβ envβ eβ eβ} :
eβ β²(n)β¨envβ, envββ© eβ β
Object.Approx.Indexed' n (Object.delayed envβ eβ) (Object.delayed envβ eβ)
| delayed_eq {envβ envβ e} :
List.Forallβ (Object.Approx.Indexed' n) envβ envβ β
Object.Approx.Indexed' n (Object.delayed envβ e) (Object.delayed envβ e)
def Env.Approx.Indexed' (n : Nat) : (envβ envβ : Env) β Prop :=
List.Forallβ (Object.Approx.Indexed' n)
notation:40 v:40 " β²β'(" n:40 ") " v':40 => Object.Approx.Indexed' n v v'
notation:40 envβ:40 " β²β'(" n:40 ") " envβ:40 => Env.Approx.Indexed' n envβ envβ
def Expr.Approx.Indexed' (n : Nat) (eβ eβ : Expr) : Prop :=
(β nβ nβ vβ, nβ + nβ β€ n β
β envβ envβ, envβ β²β'(nβ + nβ) envβ β envβ β’ eβ β¦(nβ) vβ β β vβ, envβ β’ eβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ)
notation:40 e:40 " β²'(" n:40 ") " e':40 => Expr.Approx.Indexed' n e e'
@[aesop safe cases]
inductive Value.Approx.Indexed.Inversion (n : Nat) : Value β Value β Prop where
| unit : Value.Approx.Indexed.Inversion n Value.unit Value.unit
| const {c} : Value.Approx.Indexed.Inversion n (Value.const c) (Value.const c)
| constr_app {ctr_name args_rev args_rev'} :
(β k < n, args_rev β²β(k) args_rev') β
Value.Approx.Indexed.Inversion n (Value.constr_app ctr_name args_rev) (Value.constr_app ctr_name args_rev')
| closure {envβ bodyβ envβ bodyβ} :
(β nβ nβ, nβ + nβ < n β
β aβ aβ vβ,
aβ β²α΅₯(nβ + nβ) aβ β
aβ β· envβ β’ bodyβ β¦(nβ) vβ β
β vβ, aβ β· envβ β’ bodyβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ) β
Value.Approx.Indexed.Inversion n (Value.closure envβ bodyβ) (Value.closure envβ bodyβ)
end
def Value.Approx.Indexed.Preservation (k : Nat) : Prop :=
β m n env env' e v,
m + n < k β
env β²β'(m + n) env' β
env β’ e β¦(n) v β
β v', env' β’ e β¦ v' β§ v β²α΅₯(m) v' | lemma Value.Approx.Indexed.preserved_step {k} :
(β k' < k, Preservation k') β Preservation k := | := by
intro ihk
intro m n env env' e v hβ hβ hβ
induction hβ generalizing m env'
case var env i v h =>
obtain β¨v', hget, happroxβ© := Env.Approx.Indexed'.value hβ h
exists v'
constructor
Β· apply Eval.var
aesop
Β· apply Value.Approx.Indexed.anti_monotone
Β· assumption
Β· linarith
case var_rec n' envβ name i envβ' eβ' v' hget heval ih =>
have hget_or :
(β envβ' eβ', eβ' β²(m + n')β¨envβ', envβ'β© eβ' β§
env'[i]? = some (Object.delayed envβ' eβ')) β¨
(β envβ', envβ' β²β'(m + n') envβ' β§
env'[i]? = some (Object.delayed envβ' eβ')) := by
apply Env.Approx.Indexed'.delayed hβ; assumption
cases hget_or
case inl hget' =>
obtain β¨envβ', eβ', hβ, hget'β© := hget'
simp [Expr.Approx.Param.Indexed] at hβ
obtain β¨v'', heval', happrox'β© := hβ n' m v' (by linarith) heval
exists v''
constructor
Β· apply Eval.var_rec
Β· exact hget'
Β· assumption
Β· assumption
case inr hget' =>
obtain β¨envβ, happrox, hget'β© := hget'
obtain β¨v'', heval', happrox'β© := ih m envβ (by linarith) happrox
exists v''
constructor
Β· apply Eval.var_rec
Β· exact hget'
Β· assumption
Β· assumption
case unit =>
exists Value.unit
constructor
Β· apply Eval.unit
Β· apply Value.Approx.Indexed.unit
case const c =>
exists Value.const c
constructor
Β· apply Eval.const
Β· apply Value.Approx.Indexed.const
case constr ctr_name =>
exists Value.constr_app ctr_name []
constructor
Β· apply Eval.constr
Β· apply Value.Approx.Indexed.constr_app
intro k hk
simp
case app n nβ nβ env envβ f body arg val val' hn hcl hβ hβ ih_f ih_arg ih_body =>
have : env β²β'(m + nβ + 1 + nβ) env' := by
apply Env.Approx.Indexed'.anti_monotone
Β· assumption
Β· linarith
obtain β¨v_f, heval_f, happrox_fβ© := ih_f (m + nβ + 1) env' (by linarith) this
clear this
have : env β²β'(m + nβ + nβ + 1) env' := by
apply Env.Approx.Indexed'.anti_monotone
Β· assumption
Β· linarith
obtain β¨v_arg, heval_arg, happrox_argβ© := ih_arg (m + nβ) env' (by nlinarith) this
clear this
invert happrox_f
case closure cenv cbody ch =>
have happrox_arg' : val β²α΅₯(nβ + m) v_arg := by
have : m + nβ = nβ + m := by linarith
rw [this] at happrox_arg
exact happrox_arg
obtain β¨v_body, heval_body, happrox_bodyβ© := ch nβ m (by linarith) val v_arg val' happrox_arg' hβ
exists v_body
constructor
Β· apply Eval.app
Β· exact heval_f
Β· exact heval_arg
Β· exact heval_body
Β· assumption
case constr_app nβ nβ envβ eβ cname args arg v' hlt _ hβ hβ hβ =>
obtain β¨vβ, heval_eβ, happrox_eββ© := hβ m env' (by linarith) hβ
have : envβ β²β'(m + nβ) env' := by
apply Env.Approx.Indexed'.anti_monotone
Β· assumption
Β· linarith
obtain β¨vβ, heval_arg, happrox_argβ© := hβ m env' (by linarith) this
invert happrox_eβ
case constr_app args_rev hargs =>
exists (Value.constr_app cname (vβ :: args_rev))
constructor
Β· apply Eval.constr_app
Β· exact heval_eβ
Β· exact heval_arg
Β· apply Value.Approx.Indexed.constr_app
intro k hk
constructor
Β· apply Value.Approx.Indexed.anti_monotone
Β· exact happrox_arg
Β· linarith
Β· apply hargs
linarith
case binop n' envβ op argβ argβ iβ iβ vβ vβ hvβ hvβ =>
obtain β¨vβ', hevalβ, happroxββ© := hvβ m env' (by linarith) hβ
obtain β¨vβ', hevalβ, happroxββ© := hvβ m env' (by linarith) hβ
invert happroxβ
invert happroxβ
exists (Value.const (Constant.int (eval_binop_int op iβ iβ)))
constructor
Β· apply Eval.binop
Β· exact hevalβ
Β· exact hevalβ
Β· apply Value.Approx.Indexed.const
case lambda n' envβ name body =>
exists (Value.closure env' body)
constructor
Β· apply Eval.lambda
Β· apply Value.Approx.Indexed.closure
intro nβ nβ hlt aβ aβ vβ happrox heval
have happrox_env : aβ β· envβ β²β'(nβ + nβ) aβ β· env' := by
constructor
Β· constructor
exact happrox
Β· apply Env.Approx.Indexed'.anti_monotone (n := m + n')
Β· assumption
Β· linarith
apply ihk (nβ + nβ + 1) (by linarith) (m := nβ) (n := nβ)
Β· linarith
Β· have : nβ + nβ = nβ + nβ := by linarith
rw [<- this]
exact happrox_env
Β· exact heval
case save n' nβ nβ envβ name eβ eβ val val' hle haβ haβ ihβ ihβ =>
have : envβ β²β'(m + nβ + nβ) env' := by
apply Env.Approx.Indexed'.anti_monotone
Β· assumption
Β· linarith
obtain β¨vβ, hevalβ, happroxββ© := ihβ (m + nβ) env' (by linarith) this
clear this
have : val β· envβ β²β'(m + nβ) vβ β· env' := by
constructor
Β· apply Object.Approx.Indexed'.value
Β· apply Value.Approx.Indexed.anti_monotone
Β· exact happroxβ
Β· linarith
apply Env.Approx.Indexed'.anti_monotone
Β· assumption
Β· linarith
obtain β¨vβ, hevalβ, happroxββ© := ihβ m (vβ β· env') (by linarith) this
exists vβ
constructor
Β· apply Eval.save
Β· exact hevalβ
Β· exact hevalβ
Β· assumption
case branch_matches e' nβ nβ' envβ name args_rev body val hlt heval_body ih =>
rcases env' with
β¨β© | β¨β¨hdβ©, env'β©
case nil =>
cases hβ
case cons.value =>
cases hβ
case cons hβ hβ =>
cases hβ
case value hβ =>
invert hβ
case constr_app args_rev' happrox =>
let args := List.map Object.value args_rev
let args' := List.map Object.value args_rev'
have : args ++ envβ β²β'(m + nβ') args' ++ env' := by
apply Env.Approx.Indexed'.concat
Β· apply Env.Approx.Indexed'.from_value
apply happrox
linarith
Β· apply Env.Approx.Indexed'.anti_monotone
Β· assumption
Β· linarith
obtain β¨v', heval', happrox'β© := ih m (args' ++ env') (by linarith) this
exists v'
constructor
Β· apply Eval.branch_matches
Β· exact heval'
Β· assumption
case cons.delayed =>
cases hβ
case cons h _ =>
cases h
case branch_fails e' n' envβ name name' args eβ vβ hname heval ih =>
rcases env' with
β¨β© | β¨β¨hdβ©, env'β©
case nil =>
cases hβ
case cons.value =>
cases hβ
case cons hβ hβ =>
cases hβ
case value hβ =>
invert hβ
case constr_app args_rev h =>
have hβ : Value.constr_app name args β· envβ β²β'(m + n') Value.constr_app name args_rev β· env' := by
constructor
Β· apply Object.Approx.Indexed'.value
apply Value.Approx.Indexed.constr_app
intro k hk
apply h
exact hk
Β· apply Env.Approx.Indexed'.anti_monotone
Β· assumption
Β· linarith
obtain β¨v', heval', happrox'β© := ih m (Value.constr_app name args_rev β· env') (by linarith) hβ
exists v'
constructor
Β· apply Eval.branch_fails
Β· exact hname
Β· exact heval'
Β· assumption
case cons.delayed =>
cases hβ
case cons h _ =>
cases h
case recur nβ nβ envβ name body val hn haβ ih =>
let d := Object.delayed envβ (Expr.recur name body)
let d' := Object.delayed env' (Expr.recur name body)
have : d β²β'(m + nβ) d' := by
simp [d, d']
apply Object.Approx.Indexed'.delayed_eq
apply Env.Approx.Indexed'.anti_monotone
Β· assumption
Β· linarith
have : d :: envβ β²β'(m + nβ) d' :: env' := by
apply Env.Approx.Indexed'.cons
Β· assumption
Β· apply Env.Approx.Indexed'.anti_monotone
Β· assumption
Β· linarith
obtain β¨v, heval, happroxβ© := ih m (d' :: env') (by linarith) this
exists v
constructor
Β· apply Eval.recur
exact heval
Β· assumption | 4 | 68 | true | Semantics |
246 | Juvix.Core.Main.Value.Approx.Indexed.refl | @[refl]
lemma Value.Approx.Indexed.refl {n} v : v β²α΅₯(n) v | juvix-lean | Juvix/Core/Main/Semantics/Approx/Indexed.lean | [
"import Juvix.Utils",
"import Juvix.Core.Main.Semantics.Eval.Indexed",
"import Mathlib.Tactic.Linarith",
"import Mathlib.Data.List.Forall2",
"import Juvix.Core.Main.Semantics.Eval",
"import Aesop"
] | [
{
"name": "BEq",
"module": "Init.Prelude"
},
{
"name": "DecidableEq",
"module": "Init.Prelude"
},
{
"name": "Inhabited",
"module": "Init.Prelude"
},
{
"name": "Int",
"module": "Init.Data.Int.Basic"
},
{
"name": "String",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "closure",
"module": "Mathlib.Topology.Defs.Basic"
},
{
"name": "List.Forallβ",
"module": "Batteries.Data.List.Basic"
},
{
"name": "List.Forallβ.cons",
"module": "Batteries.Data.List.Basic"
},
{
"name": "List.Forallβ.nil",
"module": "Batteries.Data.List.Basic"
},
{
"name": "List.cons",
"module": "Init.Prelude"
},
{
"name": "List.nil",
"module": "Init.Prelude"
},
{
"name": "Prod",
"module": "Init.Prelude"
},
{
"name": "reduceCtorEq",
"module": "Lean.Meta.Tactic.Simp.BuiltinSimprocs.Core"
},
{
"name": "List.map",
"module": "Init.Prelude"
}
] | [
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β\" => Eval.Defined env e",
"content": "notation:40 env:40 \" β’ \" e:40 \" β\" => Eval.Defined env e"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Inde",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Indexed n env e v"
},
{
"name": "notation:40 e:40 \" β²(\" n:40 \")β¨\" env:40 \", \" env':40 \"β© \" e'",
"content": "notation:40 e:40 \" β²(\" n:40 \")β¨\" env:40 \", \" env':40 \"β© \" e':40 => Expr.Approx.Param.Indexed n env env' e e'"
},
{
"name": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Inde",
"content": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Indexed n v v'"
},
{
"name": "notation:40 envβ:40 \" β²β'(\" n:40 \") \" envβ:40 => Env.Approx.",
"content": "notation:40 envβ:40 \" β²β'(\" n:40 \") \" envβ:40 => Env.Approx.Indexed' n envβ envβ\n\nsyntax \"case \" expr \" of \" cases \" end\" : expr"
},
{
"name": "notation:40 v:40 \" β²β'(\" n:40 \") \" v':40 => Object.Approx.In",
"content": "notation:40 v:40 \" β²β'(\" n:40 \") \" v':40 => Object.Approx.Indexed' n v v'"
},
{
"name": "notation:40 argsβ:40 \" β²β(\" n:40 \") \" argsβ:40 => List.Foral",
"content": "notation:40 argsβ:40 \" β²β(\" n:40 \") \" argsβ:40 => List.Forallβ (Value.Approx.Indexed n) argsβ argsβ\n\nsyntax:100 expr:100 ppSpace expr:101 : expr\n\nsyntax:50 expr:50 \" + \" expr:51 : expr\n\nsyntax:50 expr:50 \" - \" expr:50 : expr\n\nsyntax:60 expr:60 \" * \" expr:61 : expr\n\nsyntax:60 expr:60 \" / \" expr:60 : expr"
},
{
"name": "notation:40 e:40 \" β²'(\" n:40 \") \" e':40 => Expr.Approx.Index",
"content": "notation:40 e:40 \" β²'(\" n:40 \") \" e':40 => Expr.Approx.Indexed' n e e'"
},
{
"name": "macro \"invert\" h:term : tactic => `(tactic| (cases ($h).inve",
"content": "macro \"invert\" h:term : tactic => `(tactic| (cases ($h).invert <;> try clear $h))\n\nsyntax \"let \" ident \" := \" expr \" in \" expr : expr"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(βͺ$s:ident β― $i:numβ«) => `(Expr.var $(Lean.Syntax.mkStrLit s.getId.toString) $i)\n | `(βͺ$num:numβ«) => `(Expr.const (Constant.int $num))\n | `(βͺ$s:strβ«) => `(Expr.const (Constant.string $s))\n | `(βͺΟ
β«) => `(Expr.unit)\n | `(βͺ$eβ:expr $eβ:exprβ«) => `(Expr.app βͺ$eββ« βͺ$eββ«)\n | `(βͺΞ» $s:ident $e:exprβ«) => `(Expr.lambda $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eβ«)\n | `(βͺΞ» $ss:ident* . $e:exprβ«) => mkLambdas ss e\n | `(βͺ $s:ident β«) => `(Expr.constr $(Lean.Syntax.mkStrLit s.getId.toString))\n | `(βͺ $s:ident $es:expr* β«) => mkConstrApp s es\n | `(βͺ$eβ + $eββ«) => `(Expr.binop BinaryOp.add_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ - $eββ«) => `(Expr.binop BinaryOp.sub_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ * $eββ«) => `(Expr.binop BinaryOp.mul_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ / $eββ«) => `(Expr.binop BinaryOp.div_int βͺ$eββ« βͺ$eββ«)\n | `(βͺlet $s:ident := $eβ:expr in $eβ:exprβ«) => `(Expr.save $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eββ« βͺ$eββ«)\n | `(βͺletrec $s:ident := $eβ:expr in $eβ:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.save $name (Expr.recur $name βͺ$eββ«) βͺ$eββ«)\n | `(βͺrec $s:ident $e:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.recur $name βͺ$eβ«)\n | `(βͺβ₯β«) => `(Expr.fail)\n | `(βͺcases| | $s:ident => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« Expr.fail)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« Expr.fail)\n | `(βͺcases| | _ => $e:expr β«) =>\n `(βͺ$eβ«)\n | `(βͺcase $e:expr of $cs:cases endβ«) => do\n `(Expr.save \"_case_\" βͺ$eβ« βͺcases|$csβ«)\n | `(βͺ($e)β«) => `(βͺ$eβ«)\n\n inductive Value : Type where\n | unit : Value\n | const : Constant β Value\n | constr_app : (constr : Name) β (args_rev : List Value) β Value\n | closure : (env : List Object) β (value : Expr) β Value\n deriving Inhabited"
},
{
"name": "cons_value",
"content": "abbrev cons_value (v : Value) (env : Env) : Env := Object.value v :: env\n\n inductive Object : Type where\n | value : Value β Object\n | delayed : (env : List Object) β Expr β Object\n deriving Inhabited"
},
{
"name": "Expr",
"content": "inductive Expr : Type where\n | var : (name : String) β (index : Nat) β Expr\n | unit : Expr\n | const : Constant β Expr\n | constr : Name β Expr\n | app : Expr β Expr β Expr\n | constr_app : Expr β Expr β Expr\n | binop : (oper : BinaryOp) β (argβ argβ : Expr) β Expr\n | lambda : (var_name : String) β (body : Expr) β Expr\n | save : (var_name : String) β (value : Expr) β (body : Expr) β Expr\n | branch : (constr : Name) β (var_names : List Name) β (body : Expr) β (next : Expr) β Expr\n | recur : (var_name : Name) β (body : Expr) β Expr\n | fail : Expr\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "BinaryOp",
"content": "inductive BinaryOp : Type where\n | add_int : BinaryOp\n | sub_int : BinaryOp\n | mul_int : BinaryOp\n | div_int : BinaryOp\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Constant",
"content": "inductive Constant : Type where\n | int : Int β Constant\n | string : String β Constant\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Name",
"content": "abbrev Name : Type := String"
},
{
"name": "Env",
"content": "abbrev Env : Type := List Object"
},
{
"name": "Value.Approx",
"content": "def Value.Approx (v v' : Value) : Prop :=\n β n, v β²α΅₯(n) v'"
},
{
"name": "Object.Approx",
"content": "inductive Object.Approx : Object β Object β Prop where\n | value {vβ vβ} : vβ β²α΅₯ vβ β Object.Approx (Object.value vβ) (Object.value vβ)\n | delayed {envβ envβ eβ eβ} :\n eβ β²β¨envβ, envββ© eβ β\n Object.Approx (Object.delayed envβ eβ) (Object.delayed envβ eβ)"
},
{
"name": "Env.Approx",
"content": "def Env.Approx : (envβ envβ : Env) β Prop :=\n List.Forallβ Object.Approx"
},
{
"name": "Expr.Approx",
"content": "def Expr.Approx (eβ eβ : Expr) : Prop :=\n β envβ envβ, envβ β²β envβ β eβ β²β¨envβ, envββ© eβ"
},
{
"name": "Expr.Approx.Param",
"content": "def Expr.Approx.Param (envβ envβ : Env) (eβ eβ : Expr) : Prop :=\n (β vβ, envβ β’ eβ β¦ vβ β β vβ, envβ β’ eβ β¦ vβ β§ vβ β²α΅₯ vβ)"
},
{
"name": "Eval.Indexed",
"content": "inductive Eval.Indexed : Nat β Env β Expr β Value β Prop where\n | var {n env name idx val} :\n env[idx]? = some (Object.value val) β\n Eval.Indexed n env (Expr.var name idx) val\n | var_rec {n env name idx env' expr val} :\n env[idx]? = some (Object.delayed env' expr) β\n Eval.Indexed n env' expr val β\n Eval.Indexed n env (Expr.var name idx) val\n | unit {n env} :\n Eval.Indexed n env Expr.unit Value.unit\n | const {n env c} :\n Eval.Indexed n env (Expr.const c) (Value.const c)\n | constr {n env name} :\n Eval.Indexed n env (Expr.constr name) (Value.constr_app name [])\n | app {n nβ nβ env env' f body arg val val'} :\n nβ + nβ + 1 β€ n β\n Eval.Indexed nβ env f (Value.closure env' body) β\n Eval.Indexed (nβ + 1) env arg val β\n Eval.Indexed nβ (val β· env') body val' β\n Eval.Indexed n env (Expr.app f arg) val'\n | constr_app {n n' env ctr ctr_name ctr_args_rev arg val} :\n n' < n β\n Eval.Indexed n env ctr (Value.constr_app ctr_name ctr_args_rev) β\n Eval.Indexed n' env arg val β\n Eval.Indexed n env (Expr.constr_app ctr arg) (Value.constr_app ctr_name (val :: ctr_args_rev))\n | binop {n env op argβ argβ valβ valβ} :\n Eval.Indexed n env argβ (Value.const (Constant.int valβ)) β\n Eval.Indexed n env argβ (Value.const (Constant.int valβ)) β\n Eval.Indexed n env (Expr.binop op argβ argβ) (Value.const (Constant.int (eval_binop_int op valβ valβ)))\n | lambda {n env name body} :\n Eval.Indexed n env (Expr.lambda name body) (Value.closure env body)\n | save {n nβ nβ env name value body val val'} :\n nβ + nβ β€ n β\n Eval.Indexed nβ env value val β\n Eval.Indexed nβ (val β· env) body val' β\n Eval.Indexed n env (Expr.save name value body) val'\n | branch_matches {n n' env name args_rev body val} :\n n' < n β\n Eval.Indexed n' (args_rev.map Object.value ++ env) body val β\n Eval.Indexed n (Value.constr_app name args_rev β· env) (Expr.branch name _ body _) val\n | branch_fails {n env name name' args_rev next val} :\n name β name' β\n Eval.Indexed n (Value.constr_app name args_rev β· env) next val β\n Eval.Indexed n (Value.constr_app name args_rev β· env) (Expr.branch name' _ _ next) val\n | recur {n n' env name body val} :\n n' < n β\n Eval.Indexed n' (Object.delayed env (Expr.recur name body) :: env) body val β\n Eval.Indexed n env (Expr.recur name body) val"
},
{
"name": "Eval",
"content": "@[aesop unsafe constructors]\ninductive Eval : Env β Expr β Value β Prop where\n | var {env name idx val} :\n env[idx]? = some (Object.value val) β\n Eval env (Expr.var name idx) val\n | var_rec {env name idx env' expr val} :\n env[idx]? = some (Object.delayed env' expr) β\n Eval env' expr val β\n Eval env (Expr.var name idx) val\n | unit {env} :\n Eval env Expr.unit Value.unit\n | const {env c} :\n Eval env (Expr.const c) (Value.const c)\n | constr {env name} :\n Eval env (Expr.constr name) (Value.constr_app name [])\n | app {env env' f body arg val val'} :\n Eval env f (Value.closure env' body) β\n Eval env arg val β\n Eval (val β· env') body val' β\n Eval env (Expr.app f arg) val'\n | constr_app {env ctr ctr_name ctr_args_rev arg val} :\n Eval env ctr (Value.constr_app ctr_name ctr_args_rev) β\n Eval env arg val β\n Eval env (Expr.constr_app ctr arg) (Value.constr_app ctr_name (val :: ctr_args_rev))\n | binop {env op argβ argβ valβ valβ} :\n Eval env argβ (Value.const (Constant.int valβ)) β\n Eval env argβ (Value.const (Constant.int valβ)) β\n Eval env (Expr.binop op argβ argβ) (Value.const (Constant.int (eval_binop_int op valβ valβ)))\n | lambda {env name body} :\n Eval env (Expr.lambda name body) (Value.closure env body)\n | save {env name value body val val'} :\n Eval env value val β\n Eval (val β· env) body val' β\n Eval env (Expr.save name value body) val'\n | branch_matches {env name args_rev body val} :\n Eval (args_rev.map Object.value ++ env) body val β\n Eval (Value.constr_app name args_rev β· env) (Expr.branch name _ body _) val\n | branch_fails {env name name' args_rev next val} :\n name β name' β\n Eval (Value.constr_app name args_rev β· env) next val β\n Eval (Value.constr_app name args_rev β· env) (Expr.branch name' _ _ next) val\n | recur {env name body val} :\n Eval (Object.delayed env (Expr.recur name body) :: env) body val β\n Eval env (Expr.recur name body) val"
},
{
"name": "Context",
"content": "inductive Context : Type where\n | hole : Context\n | app_left : Context β Expr β Context\n | app_right : Expr β Context β Context\n | constr_app_left : Context β Expr β Context\n | constr_app_right : Expr β Context β Context\n | binop_left : (oper : BinaryOp) β (argβ : Context) β (argβ : Expr) β Context\n | binop_right : (oper : BinaryOp) β (argβ : Expr) β (argβ : Context) β Context\n | lambda : (var_name : String) β (body : Context) β Context\n | save_left : (var_name : String) β (value : Context) β (body : Expr) β Context\n | save_right : (var_name : String) β (value : Expr) β (body : Context) β Context\n | branch_left : (constr : Name) β (var_names : List Name) β (body : Context) β (next : Expr) β Context\n | branch_right : (constr : Name) β (var_names : List Name) β (body : Expr) β (next : Context) β Context\n | recur : (var_name : Name) β (ctx : Context) β Context\n deriving Inhabited, BEq"
},
{
"name": "eval_binop_int",
"content": "def eval_binop_int (op : BinaryOp) (iβ iβ : Int) : Int :=\n match op with\n | BinaryOp.add_int => iβ + iβ\n | BinaryOp.sub_int => iβ - iβ\n | BinaryOp.mul_int => iβ * iβ\n | BinaryOp.div_int => iβ / iβ"
},
{
"name": "infixr:50 \" β· \" => cons_value",
"content": "infixr:50 \" β· \" => cons_value"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Inde",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Indexed n env e v"
},
{
"name": "notation:40 v:40 \" β²α΅₯ \" v':40 => Value.Approx v v'",
"content": "notation:40 v:40 \" β²α΅₯ \" v':40 => Value.Approx v v'"
},
{
"name": "notation:40 e:40 \" β²β¨\" env:40 \", \" env':40 \"β© \" e':40 => Exp",
"content": "notation:40 e:40 \" β²β¨\" env:40 \", \" env':40 \"β© \" e':40 => Expr.Approx.Param env env' e e'"
},
{
"name": "notation:40 v:40 \" β²β \" v':40 => Object.Approx v v'",
"content": "notation:40 v:40 \" β²β \" v':40 => Object.Approx v v'"
},
{
"name": "notation:40 envβ:40 \" β²β \" envβ:40 => Env.Approx envβ envβ",
"content": "notation:40 envβ:40 \" β²β \" envβ:40 => Env.Approx envβ envβ"
},
{
"name": "notation:40 eβ:40 \" β² \" eβ:40 => Expr.Approx eβ eβ",
"content": "notation:40 eβ:40 \" β² \" eβ:40 => Expr.Approx eβ eβ"
},
{
"name": "infixl:100 \" @@ \" => Expr.app",
"content": "infixl:100 \" @@ \" => Expr.app"
}
] | [
{
"name": "and_self",
"module": "Init.SimpLemmas"
},
{
"name": "exists_and_left",
"module": "Init.PropLemmas"
},
{
"name": "exists_const",
"module": "Init.PropLemmas"
},
{
"name": "exists_eq_left'",
"module": "Init.PropLemmas"
},
{
"name": "false_and",
"module": "Init.SimpLemmas"
},
{
"name": "false_or",
"module": "Init.SimpLemmas"
},
{
"name": "implies_true",
"module": "Init.SimpLemmas"
},
{
"name": "or_false",
"module": "Init.SimpLemmas"
},
{
"name": "true_and",
"module": "Init.SimpLemmas"
},
{
"name": "List.forallβ_same",
"module": "Mathlib.Data.List.Forall2"
},
{
"name": "List.Forallβ.get",
"module": "Mathlib.Data.List.Forall2"
},
{
"name": "List.Forallβ.length_eq",
"module": "Mathlib.Data.List.Forall2"
},
{
"name": "List.getElem?_eq_some_iff",
"module": "Init.Data.List.Lemmas"
},
{
"name": "List.get_eq_getElem",
"module": "Init.Data.List.Lemmas"
},
{
"name": "forall_true_left",
"module": "Mathlib.Logic.Basic"
},
{
"name": "Nat.le_eq",
"module": "Init.Data.Nat.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": "Juvix.Core.Main.Value.Approx.Indexed",
"content": "def Value.Approx.Indexed (n : Nat) (vβ vβ : Value) : Prop :=\n (vβ = Value.unit β§ vβ = Value.unit) β¨\n (β c, vβ = Value.const c β§ vβ = Value.const c) β¨\n (β ctr_name args_rev args_rev',\n vβ = Value.constr_app ctr_name args_rev β§\n vβ = Value.constr_app ctr_name args_rev' β§\n (β k < n, List.Forallβ (Value.Approx.Indexed k) args_rev args_rev')) β¨\n (β envβ bodyβ envβ bodyβ,\n vβ = Value.closure envβ bodyβ β§\n vβ = Value.closure envβ bodyβ β§\n (β nβ nβ, nβ + nβ < n β\n β aβ aβ rβ,\n Value.Approx.Indexed (nβ + nβ) aβ aβ β\n aβ β· envβ β’ bodyβ β¦(nβ) rβ β\n β rβ,\n aβ β· envβ β’ bodyβ β¦ rβ β§\n Value.Approx.Indexed nβ rβ rβ))"
},
{
"name": "Juvix.Core.Main.Expr.Approx.Param.Indexed",
"content": "def Expr.Approx.Param.Indexed (n : Nat) (envβ envβ : Env) (eβ eβ : Expr) : Prop :=\n (β nβ nβ vβ, nβ + nβ β€ n β envβ β’ eβ β¦(nβ) vβ β β vβ, envβ β’ eβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ)"
},
{
"name": "Juvix.Core.Main.Object.Approx.Indexed'",
"content": "inductive Object.Approx.Indexed' (n : Nat) : Object β Object β Prop where\n | value {vβ vβ} :\n vβ β²α΅₯(n) vβ β\n Object.Approx.Indexed' n (Object.value vβ) (Object.value vβ)\n | delayed {envβ envβ eβ eβ} :\n eβ β²(n)β¨envβ, envββ© eβ β\n Object.Approx.Indexed' n (Object.delayed envβ eβ) (Object.delayed envβ eβ)\n | delayed_eq {envβ envβ e} :\n List.Forallβ (Object.Approx.Indexed' n) envβ envβ β\n Object.Approx.Indexed' n (Object.delayed envβ e) (Object.delayed envβ e)"
},
{
"name": "Juvix.Core.Main.Env.Approx.Indexed'",
"content": "def Env.Approx.Indexed' (n : Nat) : (envβ envβ : Env) β Prop :=\n List.Forallβ (Object.Approx.Indexed' n)"
},
{
"name": "Juvix.Core.Main.Expr.Approx.Indexed'",
"content": "def Expr.Approx.Indexed' (n : Nat) (eβ eβ : Expr) : Prop :=\n (β nβ nβ vβ, nβ + nβ β€ n β\n β envβ envβ, envβ β²β'(nβ + nβ) envβ β envβ β’ eβ β¦(nβ) vβ β β vβ, envβ β’ eβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ)"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.Inversion",
"content": "@[aesop safe cases]\ninductive Value.Approx.Indexed.Inversion (n : Nat) : Value β Value β Prop where\n | unit : Value.Approx.Indexed.Inversion n Value.unit Value.unit\n | const {c} : Value.Approx.Indexed.Inversion n (Value.const c) (Value.const c)\n | constr_app {ctr_name args_rev args_rev'} :\n (β k < n, args_rev β²β(k) args_rev') β\n Value.Approx.Indexed.Inversion n (Value.constr_app ctr_name args_rev) (Value.constr_app ctr_name args_rev')\n | closure {envβ bodyβ envβ bodyβ} :\n (β nβ nβ, nβ + nβ < n β\n β aβ aβ vβ,\n aβ β²α΅₯(nβ + nβ) aβ β\n aβ β· envβ β’ bodyβ β¦(nβ) vβ β\n β vβ, aβ β· envβ β’ bodyβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ) β\n Value.Approx.Indexed.Inversion n (Value.closure envβ bodyβ) (Value.closure envβ bodyβ)"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.Preservation",
"content": "def Value.Approx.Indexed.Preservation (k : Nat) : Prop :=\n β m n env env' e v,\n m + n < k β\n env β²β'(m + n) env' β\n env β’ e β¦(n) v β\n β v', env' β’ e β¦ v' β§ v β²α΅₯(m) v'"
}
] | [
{
"name": "Juvix.Core.Main.Env.Approx.Indexed'.get",
"content": "lemma Env.Approx.Indexed'.get {n i : Nat} {env env' oβ}\n (hβ : env β²β'(n) env')\n (hβ : env[i]? = some oβ) :\n β oβ, env'[i]? = some oβ β§ oβ β²β'(n) oβ"
},
{
"name": "Juvix.Core.Main.Env.Approx.Indexed'.value",
"content": "lemma Env.Approx.Indexed'.value {n i : Nat} {env env' v}\n (hβ : env β²β'(n) env')\n (hβ : env[i]? = some (Object.value v)) :\n β v', env'[i]? = some (Object.value v') β§ v β²α΅₯(n) v'"
},
{
"name": "Juvix.Core.Main.Env.Approx.Indexed'.delayed",
"content": "lemma Env.Approx.Indexed'.delayed {n i : Nat} {envβ envβ env e}\n (hβ : envβ β²β'(n) envβ)\n (hβ : envβ[i]? = some (Object.delayed env e)) :\n (β env' e', e β²(n)β¨env, env'β© e' β§ envβ[i]? = some (Object.delayed env' e')) β¨\n β env', env β²β'(n) env' β§ envβ[i]? = some (Object.delayed env' e)"
},
{
"name": "Juvix.Core.Main.Env.Approx.Indexed'.from_value",
"content": "lemma Env.Approx.Indexed'.from_value {n lβ lβ} (h : lβ β²β(n) lβ) :\n List.map Object.value lβ β²β'(n) List.map Object.value lβ"
},
{
"name": "Juvix.Core.Main.Env.Approx.Indexed'.concat",
"content": "lemma Env.Approx.Indexed'.concat {n envβ envβ envβ' envβ'}\n (hβ : envβ β²β'(n) envβ')\n (hβ : envβ β²β'(n) envβ') :\n envβ ++ envβ β²β'(n) envβ' ++ envβ'"
},
{
"name": "Juvix.Core.Main.Env.Approx.Indexed'.cons",
"content": "lemma Env.Approx.Indexed'.cons {n oβ oβ envβ envβ}\n (hβ : oβ β²β'(n) oβ)\n (hβ : envβ β²β'(n) envβ) :\n oβ :: envβ β²β'(n) oβ :: envβ"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.unit",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.unit {n} : Value.unit β²α΅₯(n) Value.unit"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.const",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.const {n c} : Value.const c β²α΅₯(n) Value.const c"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.constr_app",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.constr_app {n ctr_name args_rev args_rev'} :\n (β k < n, args_rev β²β(k) args_rev') β\n Value.constr_app ctr_name args_rev β²α΅₯(n) Value.constr_app ctr_name args_rev'"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.closure",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.closure {n envβ bodyβ envβ bodyβ} :\n (β nβ nβ, nβ + nβ < n β\n β aβ aβ vβ,\n aβ β²α΅₯(nβ + nβ) aβ β\n aβ β· envβ β’ bodyβ β¦(nβ) vβ β\n β vβ, aβ β· envβ β’ bodyβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ) β\n Value.closure envβ bodyβ β²α΅₯(n) Value.closure envβ bodyβ"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.anti_monotone",
"content": "lemma Value.Approx.Indexed.anti_monotone {n n' vβ vβ} (h : vβ β²α΅₯(n) vβ) (h' : n' β€ n) : vβ β²α΅₯(n') vβ"
},
{
"name": "Juvix.Core.Main.Expr.Approx.Param.Indexed.anti_monotone",
"content": "lemma Expr.Approx.Param.Indexed.anti_monotone {n n' envβ envβ eβ eβ}\n (h : eβ β²(n)β¨envβ, envββ© eβ)\n (h' : n' β€ n)\n : eβ β²(n')β¨envβ, envββ© eβ"
},
{
"name": "Juvix.Core.Main.Expr.Approx.Indexed'.anti_monotone",
"content": "lemma Expr.Approx.Indexed'.anti_monotone {n n' eβ eβ}\n (h : eβ β²'(n) eβ)\n (h' : n' β€ n)\n : eβ β²'(n') eβ"
},
{
"name": "Juvix.Core.Main.Env.Approx.Indexed'.anti_monotone",
"content": " lemma Env.Approx.Indexed'.anti_monotone {n n' envβ envβ}\n (h : envβ β²β'(n) envβ)\n (h' : n' β€ n)\n : envβ β²β'(n') envβ"
},
{
"name": "Juvix.Core.Main.Object.Approx.Indexed'.anti_monotone",
"content": " lemma Object.Approx.Indexed'.anti_monotone {n n' oβ oβ} (h : oβ β²β'(n) oβ) (h' : n' β€ n) : oβ β²β'(n') oβ"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.Preservation.anti_monotone",
"content": "lemma Value.Approx.Indexed.Preservation.anti_monotone {k k'} (h : Value.Approx.Indexed.Preservation k) (h' : k' β€ k) : Value.Approx.Indexed.Preservation k'"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.preserved_step",
"content": "lemma Value.Approx.Indexed.preserved_step {k} :\n (β k' < k, Preservation k') β Preservation k"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.preserved'",
"content": "lemma Value.Approx.Indexed.preserved' {k} : Preservation k"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.preserved",
"content": "theorem Value.Approx.Indexed.preserved :\n β m n env env' e v,\n env β²β'(m + n) env' β\n env β’ e β¦(n) v β\n β v', env' β’ e β¦ v' β§ v β²α΅₯(m) v'"
},
{
"name": "Juvix.Core.Main.Env.Approx.Indexed'.refl'",
"content": " lemma Env.Approx.Indexed'.refl' {n env} (h : β v, v β²α΅₯(n) v) : env β²β'(n) env"
},
{
"name": "Juvix.Core.Main.Object.Approx.Indexed'.refl'",
"content": " lemma Object.Approx.Indexed'.refl' {n o} (h : β v, v β²α΅₯(n) v) : o β²β'(n) o"
}
] | import Juvix.Core.Main.Semantics.Eval
import Juvix.Core.Main.Semantics.Eval.Indexed
import Juvix.Utils
import Mathlib.Tactic.Linarith
import Mathlib.Data.List.Forall2
import Aesop
namespace Juvix.Core.Main
def Value.Approx.Indexed (n : Nat) (vβ vβ : Value) : Prop :=
(vβ = Value.unit β§ vβ = Value.unit) β¨
(β c, vβ = Value.const c β§ vβ = Value.const c) β¨
(β ctr_name args_rev args_rev',
vβ = Value.constr_app ctr_name args_rev β§
vβ = Value.constr_app ctr_name args_rev' β§
(β k < n, List.Forallβ (Value.Approx.Indexed k) args_rev args_rev')) β¨
(β envβ bodyβ envβ bodyβ,
vβ = Value.closure envβ bodyβ β§
vβ = Value.closure envβ bodyβ β§
(β nβ nβ, nβ + nβ < n β
β aβ aβ rβ,
Value.Approx.Indexed (nβ + nβ) aβ aβ β
aβ β· envβ β’ bodyβ β¦(nβ) rβ β
β rβ,
aβ β· envβ β’ bodyβ β¦ rβ β§
Value.Approx.Indexed nβ rβ rβ))
notation:40 v:40 " β²α΅₯(" n:40 ") " v':40 => Value.Approx.Indexed n v v'
notation:40 argsβ:40 " β²β(" n:40 ") " argsβ:40 => List.Forallβ (Value.Approx.Indexed n) argsβ argsβ
def Expr.Approx.Param.Indexed (n : Nat) (envβ envβ : Env) (eβ eβ : Expr) : Prop :=
(β nβ nβ vβ, nβ + nβ β€ n β envβ β’ eβ β¦(nβ) vβ β β vβ, envβ β’ eβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ)
notation:40 e:40 " β²(" n:40 ")β¨" env:40 ", " env':40 "β© " e':40 => Expr.Approx.Param.Indexed n env env' e e'
inductive Object.Approx.Indexed' (n : Nat) : Object β Object β Prop where
| value {vβ vβ} :
vβ β²α΅₯(n) vβ β
Object.Approx.Indexed' n (Object.value vβ) (Object.value vβ)
| delayed {envβ envβ eβ eβ} :
eβ β²(n)β¨envβ, envββ© eβ β
Object.Approx.Indexed' n (Object.delayed envβ eβ) (Object.delayed envβ eβ)
| delayed_eq {envβ envβ e} :
List.Forallβ (Object.Approx.Indexed' n) envβ envβ β
Object.Approx.Indexed' n (Object.delayed envβ e) (Object.delayed envβ e)
def Env.Approx.Indexed' (n : Nat) : (envβ envβ : Env) β Prop :=
List.Forallβ (Object.Approx.Indexed' n)
notation:40 v:40 " β²β'(" n:40 ") " v':40 => Object.Approx.Indexed' n v v'
notation:40 envβ:40 " β²β'(" n:40 ") " envβ:40 => Env.Approx.Indexed' n envβ envβ
def Expr.Approx.Indexed' (n : Nat) (eβ eβ : Expr) : Prop :=
(β nβ nβ vβ, nβ + nβ β€ n β
β envβ envβ, envβ β²β'(nβ + nβ) envβ β envβ β’ eβ β¦(nβ) vβ β β vβ, envβ β’ eβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ)
notation:40 e:40 " β²'(" n:40 ") " e':40 => Expr.Approx.Indexed' n e e'
@[aesop safe cases]
inductive Value.Approx.Indexed.Inversion (n : Nat) : Value β Value β Prop where
| unit : Value.Approx.Indexed.Inversion n Value.unit Value.unit
| const {c} : Value.Approx.Indexed.Inversion n (Value.const c) (Value.const c)
| constr_app {ctr_name args_rev args_rev'} :
(β k < n, args_rev β²β(k) args_rev') β
Value.Approx.Indexed.Inversion n (Value.constr_app ctr_name args_rev) (Value.constr_app ctr_name args_rev')
| closure {envβ bodyβ envβ bodyβ} :
(β nβ nβ, nβ + nβ < n β
β aβ aβ vβ,
aβ β²α΅₯(nβ + nβ) aβ β
aβ β· envβ β’ bodyβ β¦(nβ) vβ β
β vβ, aβ β· envβ β’ bodyβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ) β
Value.Approx.Indexed.Inversion n (Value.closure envβ bodyβ) (Value.closure envβ bodyβ)
end
def Value.Approx.Indexed.Preservation (k : Nat) : Prop :=
β m n env env' e v,
m + n < k β
env β²β'(m + n) env' β
env β’ e β¦(n) v β
β v', env' β’ e β¦ v' β§ v β²α΅₯(m) v'
end | @[refl]
lemma Value.Approx.Indexed.refl {n} v : v β²α΅₯(n) v := | := by
revert n
suffices β n, β k β€ n, v β²α΅₯(k) v by
intro k
exact this k k k.le_refl
intro n
induction n generalizing v with
| zero =>
intros k hk
cases v
case unit =>
exact Value.Approx.Indexed.unit
case const c =>
exact Value.Approx.Indexed.const
case constr_app ctr_name args_rev =>
apply Value.Approx.Indexed.constr_app
Β· intros
have : k = 0 := by linarith
subst k
contradiction
case closure env body =>
apply Value.Approx.Indexed.closure
Β· intros
have : k = 0 := by linarith
subst k
contradiction
| succ n ih =>
intros k hk
cases v
case unit =>
exact Value.Approx.Indexed.unit
case const c =>
exact Value.Approx.Indexed.const
case constr_app ctr_name args_rev =>
apply Value.Approx.Indexed.constr_app
Β· intros k' hk'
have : k' β€ n := by linarith
rw [List.forallβ_same]
intros
apply ih
Β· assumption
case closure env body =>
apply Value.Approx.Indexed.closure
Β· intros nβ nβ hn aβ aβ rβ happrox heval
have henv : aβ β· env β²β'(nβ + nβ) aβ β· env := by
simp [Env.Approx.Indexed']
constructor
Β· constructor; exact happrox
Β· intro x _
cases x
case value vβ vβ =>
apply Object.Approx.Indexed'.value
Β· apply ih
Β· linarith
case delayed =>
apply Object.Approx.Indexed'.refl'
intro v
apply ih
linarith
apply Value.Approx.Indexed.preserved (n := nβ) (m := nβ)
Β· have : nβ + nβ = nβ + nβ := by linarith
rw [<- this]
exact henv
Β· assumption | 7 | 80 | true | Semantics |
247 | Juvix.Core.Main.Eval.toIndexed | lemma Eval.toIndexed {env e v} (h : env β’ e β¦ v) : β n, env β’ e β¦(n) v | juvix-lean | Juvix/Core/Main/Semantics/Eval/Indexed.lean | [
"import Mathlib.Tactic.Linarith",
"import Juvix.Core.Main.Semantics.Eval"
] | [
{
"name": "BEq",
"module": "Init.Prelude"
},
{
"name": "DecidableEq",
"module": "Init.Prelude"
},
{
"name": "Inhabited",
"module": "Init.Prelude"
},
{
"name": "Int",
"module": "Init.Data.Int.Basic"
},
{
"name": "String",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "closure",
"module": "Mathlib.Topology.Defs.Basic"
}
] | [
{
"name": "syntax:100 expr:100 ppSpace expr:101 : expr",
"content": "syntax:100 expr:100 ppSpace expr:101 : expr\n\nsyntax:50 expr:50 \" + \" expr:51 : expr\n\nsyntax:50 expr:50 \" - \" expr:50 : expr\n\nsyntax:60 expr:60 \" * \" expr:61 : expr\n\nsyntax:60 expr:60 \" / \" expr:60 : expr\n\nsyntax \"case \" expr \" of \" cases \" end\" : expr"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β\" => Eval.Defined env e",
"content": "notation:40 env:40 \" β’ \" e:40 \" β\" => Eval.Defined env e"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Inde",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Indexed n env e v"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(βͺ$s:ident β― $i:numβ«) => `(Expr.var $(Lean.Syntax.mkStrLit s.getId.toString) $i)\n | `(βͺ$num:numβ«) => `(Expr.const (Constant.int $num))\n | `(βͺ$s:strβ«) => `(Expr.const (Constant.string $s))\n | `(βͺΟ
β«) => `(Expr.unit)\n | `(βͺ$eβ:expr $eβ:exprβ«) => `(Expr.app βͺ$eββ« βͺ$eββ«)\n | `(βͺΞ» $s:ident $e:exprβ«) => `(Expr.lambda $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eβ«)\n | `(βͺΞ» $ss:ident* . $e:exprβ«) => mkLambdas ss e\n | `(βͺ $s:ident β«) => `(Expr.constr $(Lean.Syntax.mkStrLit s.getId.toString))\n | `(βͺ $s:ident $es:expr* β«) => mkConstrApp s es\n | `(βͺ$eβ + $eββ«) => `(Expr.binop BinaryOp.add_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ - $eββ«) => `(Expr.binop BinaryOp.sub_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ * $eββ«) => `(Expr.binop BinaryOp.mul_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ / $eββ«) => `(Expr.binop BinaryOp.div_int βͺ$eββ« βͺ$eββ«)\n | `(βͺlet $s:ident := $eβ:expr in $eβ:exprβ«) => `(Expr.save $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eββ« βͺ$eββ«)\n | `(βͺletrec $s:ident := $eβ:expr in $eβ:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.save $name (Expr.recur $name βͺ$eββ«) βͺ$eββ«)\n | `(βͺrec $s:ident $e:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.recur $name βͺ$eβ«)\n | `(βͺβ₯β«) => `(Expr.fail)\n | `(βͺcases| | $s:ident => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« Expr.fail)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« Expr.fail)\n | `(βͺcases| | _ => $e:expr β«) =>\n `(βͺ$eβ«)\n | `(βͺcase $e:expr of $cs:cases endβ«) => do\n `(Expr.save \"_case_\" βͺ$eβ« βͺcases|$csβ«)\n | `(βͺ($e)β«) => `(βͺ$eβ«)"
},
{
"name": "Eval",
"content": "@[aesop unsafe constructors]\ninductive Eval : Env β Expr β Value β Prop where\n | var {env name idx val} :\n env[idx]? = some (Object.value val) β\n Eval env (Expr.var name idx) val\n | var_rec {env name idx env' expr val} :\n env[idx]? = some (Object.delayed env' expr) β\n Eval env' expr val β\n Eval env (Expr.var name idx) val\n | unit {env} :\n Eval env Expr.unit Value.unit\n | const {env c} :\n Eval env (Expr.const c) (Value.const c)\n | constr {env name} :\n Eval env (Expr.constr name) (Value.constr_app name [])\n | app {env env' f body arg val val'} :\n Eval env f (Value.closure env' body) β\n Eval env arg val β\n Eval (val β· env') body val' β\n Eval env (Expr.app f arg) val'\n | constr_app {env ctr ctr_name ctr_args_rev arg val} :\n Eval env ctr (Value.constr_app ctr_name ctr_args_rev) β\n Eval env arg val β\n Eval env (Expr.constr_app ctr arg) (Value.constr_app ctr_name (val :: ctr_args_rev))\n | binop {env op argβ argβ valβ valβ} :\n Eval env argβ (Value.const (Constant.int valβ)) β\n Eval env argβ (Value.const (Constant.int valβ)) β\n Eval env (Expr.binop op argβ argβ) (Value.const (Constant.int (eval_binop_int op valβ valβ)))\n | lambda {env name body} :\n Eval env (Expr.lambda name body) (Value.closure env body)\n | save {env name value body val val'} :\n Eval env value val β\n Eval (val β· env) body val' β\n Eval env (Expr.save name value body) val'\n | branch_matches {env name args_rev body val} :\n Eval (args_rev.map Object.value ++ env) body val β\n Eval (Value.constr_app name args_rev β· env) (Expr.branch name _ body _) val\n | branch_fails {env name name' args_rev next val} :\n name β name' β\n Eval (Value.constr_app name args_rev β· env) next val β\n Eval (Value.constr_app name args_rev β· env) (Expr.branch name' _ _ next) val\n | recur {env name body val} :\n Eval (Object.delayed env (Expr.recur name body) :: env) body val β\n Eval env (Expr.recur name body) val"
},
{
"name": "BinaryOp",
"content": "inductive BinaryOp : Type where\n | add_int : BinaryOp\n | sub_int : BinaryOp\n | mul_int : BinaryOp\n | div_int : BinaryOp\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "eval_binop_int",
"content": "def eval_binop_int (op : BinaryOp) (iβ iβ : Int) : Int :=\n match op with\n | BinaryOp.add_int => iβ + iβ\n | BinaryOp.sub_int => iβ - iβ\n | BinaryOp.mul_int => iβ * iβ\n | BinaryOp.div_int => iβ / iβ"
},
{
"name": "Expr",
"content": "inductive Expr : Type where\n | var : (name : String) β (index : Nat) β Expr\n | unit : Expr\n | const : Constant β Expr\n | constr : Name β Expr\n | app : Expr β Expr β Expr\n | constr_app : Expr β Expr β Expr\n | binop : (oper : BinaryOp) β (argβ argβ : Expr) β Expr\n | lambda : (var_name : String) β (body : Expr) β Expr\n | save : (var_name : String) β (value : Expr) β (body : Expr) β Expr\n | branch : (constr : Name) β (var_names : List Name) β (body : Expr) β (next : Expr) β Expr\n | recur : (var_name : Name) β (body : Expr) β Expr\n | fail : Expr\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "cons_value",
"content": "abbrev cons_value (v : Value) (env : Env) : Env := Object.value v :: env\n\n inductive Object : Type where\n | value : Value β Object\n | delayed : (env : List Object) β Expr β Object\n deriving Inhabited\n\n inductive Value : Type where\n | unit : Value\n | const : Constant β Value\n | constr_app : (constr : Name) β (args_rev : List Value) β Value\n | closure : (env : List Object) β (value : Expr) β Value\n deriving Inhabited"
},
{
"name": "Constant",
"content": "inductive Constant : Type where\n | int : Int β Constant\n | string : String β Constant\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Name",
"content": "abbrev Name : Type := String"
},
{
"name": "Env",
"content": "abbrev Env : Type := List Object"
},
{
"name": "Context",
"content": "inductive Context : Type where\n | hole : Context\n | app_left : Context β Expr β Context\n | app_right : Expr β Context β Context\n | constr_app_left : Context β Expr β Context\n | constr_app_right : Expr β Context β Context\n | binop_left : (oper : BinaryOp) β (argβ : Context) β (argβ : Expr) β Context\n | binop_right : (oper : BinaryOp) β (argβ : Expr) β (argβ : Context) β Context\n | lambda : (var_name : String) β (body : Context) β Context\n | save_left : (var_name : String) β (value : Context) β (body : Expr) β Context\n | save_right : (var_name : String) β (value : Expr) β (body : Context) β Context\n | branch_left : (constr : Name) β (var_names : List Name) β (body : Context) β (next : Expr) β Context\n | branch_right : (constr : Name) β (var_names : List Name) β (body : Expr) β (next : Context) β Context\n | recur : (var_name : Name) β (ctx : Context) β Context\n deriving Inhabited, BEq"
},
{
"name": "infixr:50 \" β· \" => cons_value",
"content": "infixr:50 \" β· \" => cons_value"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v"
},
{
"name": "infixl:100 \" @@ \" => Expr.app",
"content": "infixl:100 \" @@ \" => Expr.app"
}
] | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "Termination.var",
"content": "lemma Termination.var {env name i v} :\n env[i]? = some (Object.value v) β\n env β’ Expr.var name i β"
},
{
"name": "Termination.var_rec",
"content": "lemma Termination.var_rec {env name i env' e} :\n env[i]? = some (Object.delayed env' e) β\n env' β’ e β β\n env β’ (Expr.var name i) β"
},
{
"name": "Termination.unit",
"content": "lemma Termination.unit {env} :\n env β’ Expr.unit β"
},
{
"name": "Termination.const",
"content": "lemma Termination.const {env c} :\n env β’ Expr.const c β"
},
{
"name": "Termination.constr",
"content": "lemma Termination.constr {env nm} :\n env β’ Expr.constr nm β"
},
{
"name": "Termination.app",
"content": "lemma Termination.app {env eβ eβ v env' body} :\n env β’ eβ β¦ Value.closure env' body β\n env β’ eβ β¦ v β\n v β· env' β’ body β β\n env β’ Expr.app eβ eβ β"
},
{
"name": "Termination.constr_app",
"content": "lemma Termination.constr_app {env eβ eβ eββ eββ} :\n env β’ eβ β¦ Value.constr_app eββ eββ β\n env β’ eβ β β\n env β’ Expr.constr_app eβ eβ β"
},
{
"name": "Termination.binop",
"content": "lemma Termination.binop {env op eβ eβ cβ cβ} :\n env β’ eβ β¦ Value.const (Constant.int cβ) β\n env β’ eβ β¦ Value.const (Constant.int cβ) β\n env β’ Expr.binop op eβ eβ β"
},
{
"name": "Termination.lambda",
"content": "lemma Termination.lambda {env name e} : env β’ Expr.lambda name e β"
},
{
"name": "Termination.save",
"content": "lemma Termination.save {env name eβ eβ v} :\n env β’ eβ β¦ v β\n v β· env β’ eβ β β\n env β’ Expr.save name eβ eβ β"
},
{
"name": "Termination.branch_matches",
"content": "lemma Termination.branch_matches {env name vnames args_rev e e'} :\n args_rev.map Object.value ++ env β’ e β β\n Value.constr_app name args_rev β· env β’ Expr.branch name vnames e e' β"
},
{
"name": "Termination.branch_fails",
"content": "lemma Termination.branch_fails {env name name' vnames args_rev e e'} :\n name β name' β\n Value.constr_app name args_rev β· env β’ e' β β\n Value.constr_app name args_rev β· env β’ Expr.branch name' vnames e e' β"
},
{
"name": "Termination.recur",
"content": "lemma Termination.recur {env name e} :\n Object.delayed env (Expr.recur name e) :: env β’ e β β\n env β’ Expr.recur name e β"
}
] | [
{
"name": "Juvix.Core.Main.Eval.Indexed",
"content": "inductive Eval.Indexed : Nat β Env β Expr β Value β Prop where\n | var {n env name idx val} :\n env[idx]? = some (Object.value val) β\n Eval.Indexed n env (Expr.var name idx) val\n | var_rec {n env name idx env' expr val} :\n env[idx]? = some (Object.delayed env' expr) β\n Eval.Indexed n env' expr val β\n Eval.Indexed n env (Expr.var name idx) val\n | unit {n env} :\n Eval.Indexed n env Expr.unit Value.unit\n | const {n env c} :\n Eval.Indexed n env (Expr.const c) (Value.const c)\n | constr {n env name} :\n Eval.Indexed n env (Expr.constr name) (Value.constr_app name [])\n | app {n nβ nβ env env' f body arg val val'} :\n nβ + nβ + 1 β€ n β\n Eval.Indexed nβ env f (Value.closure env' body) β\n Eval.Indexed (nβ + 1) env arg val β\n Eval.Indexed nβ (val β· env') body val' β\n Eval.Indexed n env (Expr.app f arg) val'\n | constr_app {n n' env ctr ctr_name ctr_args_rev arg val} :\n n' < n β\n Eval.Indexed n env ctr (Value.constr_app ctr_name ctr_args_rev) β\n Eval.Indexed n' env arg val β\n Eval.Indexed n env (Expr.constr_app ctr arg) (Value.constr_app ctr_name (val :: ctr_args_rev))\n | binop {n env op argβ argβ valβ valβ} :\n Eval.Indexed n env argβ (Value.const (Constant.int valβ)) β\n Eval.Indexed n env argβ (Value.const (Constant.int valβ)) β\n Eval.Indexed n env (Expr.binop op argβ argβ) (Value.const (Constant.int (eval_binop_int op valβ valβ)))\n | lambda {n env name body} :\n Eval.Indexed n env (Expr.lambda name body) (Value.closure env body)\n | save {n nβ nβ env name value body val val'} :\n nβ + nβ β€ n β\n Eval.Indexed nβ env value val β\n Eval.Indexed nβ (val β· env) body val' β\n Eval.Indexed n env (Expr.save name value body) val'\n | branch_matches {n n' env name args_rev body val} :\n n' < n β\n Eval.Indexed n' (args_rev.map Object.value ++ env) body val β\n Eval.Indexed n (Value.constr_app name args_rev β· env) (Expr.branch name _ body _) val\n | branch_fails {n env name name' args_rev next val} :\n name β name' β\n Eval.Indexed n (Value.constr_app name args_rev β· env) next val β\n Eval.Indexed n (Value.constr_app name args_rev β· env) (Expr.branch name' _ _ next) val\n | recur {n n' env name body val} :\n n' < n β\n Eval.Indexed n' (Object.delayed env (Expr.recur name body) :: env) body val β\n Eval.Indexed n env (Expr.recur name body) val"
}
] | [
{
"name": "Juvix.Core.Main.Eval.Indexed.monotone",
"content": "lemma Eval.Indexed.monotone {n n' env e v} (h : env β’ e β¦(n) v) (h' : n β€ n') : env β’ e β¦(n') v"
}
] | import Juvix.Core.Main.Semantics.Eval
import Mathlib.Tactic.Linarith
namespace Juvix.Core.Main
inductive Eval.Indexed : Nat β Env β Expr β Value β Prop where
| var {n env name idx val} :
env[idx]? = some (Object.value val) β
Eval.Indexed n env (Expr.var name idx) val
| var_rec {n env name idx env' expr val} :
env[idx]? = some (Object.delayed env' expr) β
Eval.Indexed n env' expr val β
Eval.Indexed n env (Expr.var name idx) val
| unit {n env} :
Eval.Indexed n env Expr.unit Value.unit
| const {n env c} :
Eval.Indexed n env (Expr.const c) (Value.const c)
| constr {n env name} :
Eval.Indexed n env (Expr.constr name) (Value.constr_app name [])
| app {n nβ nβ env env' f body arg val val'} :
nβ + nβ + 1 β€ n β
Eval.Indexed nβ env f (Value.closure env' body) β
Eval.Indexed (nβ + 1) env arg val β
Eval.Indexed nβ (val β· env') body val' β
Eval.Indexed n env (Expr.app f arg) val'
| constr_app {n n' env ctr ctr_name ctr_args_rev arg val} :
n' < n β
Eval.Indexed n env ctr (Value.constr_app ctr_name ctr_args_rev) β
Eval.Indexed n' env arg val β
Eval.Indexed n env (Expr.constr_app ctr arg) (Value.constr_app ctr_name (val :: ctr_args_rev))
| binop {n env op argβ argβ valβ valβ} :
Eval.Indexed n env argβ (Value.const (Constant.int valβ)) β
Eval.Indexed n env argβ (Value.const (Constant.int valβ)) β
Eval.Indexed n env (Expr.binop op argβ argβ) (Value.const (Constant.int (eval_binop_int op valβ valβ)))
| lambda {n env name body} :
Eval.Indexed n env (Expr.lambda name body) (Value.closure env body)
| save {n nβ nβ env name value body val val'} :
nβ + nβ β€ n β
Eval.Indexed nβ env value val β
Eval.Indexed nβ (val β· env) body val' β
Eval.Indexed n env (Expr.save name value body) val'
| branch_matches {n n' env name args_rev body val} :
n' < n β
Eval.Indexed n' (args_rev.map Object.value ++ env) body val β
Eval.Indexed n (Value.constr_app name args_rev β· env) (Expr.branch name _ body _) val
| branch_fails {n env name name' args_rev next val} :
name β name' β
Eval.Indexed n (Value.constr_app name args_rev β· env) next val β
Eval.Indexed n (Value.constr_app name args_rev β· env) (Expr.branch name' _ _ next) val
| recur {n n' env name body val} :
n' < n β
Eval.Indexed n' (Object.delayed env (Expr.recur name body) :: env) body val β
Eval.Indexed n env (Expr.recur name body) val
notation:40 env:40 " β’ " e:40 " β¦(" n ") " v:40 => Eval.Indexed n env e v | lemma Eval.toIndexed {env e v} (h : env β’ e β¦ v) : β n, env β’ e β¦(n) v := | := by
induction h
case var =>
exists 0; apply Eval.Indexed.var; assumption
case var_rec ih =>
obtain β¨n, ihβ© := ih
exists n
apply Eval.Indexed.var_rec <;> assumption
case unit =>
exists 0; apply Eval.Indexed.unit
case const =>
exists 0; apply Eval.Indexed.const
case constr =>
exists 0; apply Eval.Indexed.constr
case app env env' f body arg val val' _ _ _ ih1 ih2 ih3 =>
obtain β¨nβ, ihββ© := ih1
obtain β¨nβ, ihββ© := ih2
obtain β¨nβ, ihββ© := ih3
have ihβ' : env β’ f β¦(nβ + nβ) Value.closure env' body := by
apply Eval.Indexed.monotone ihβ; linarith
have ihβ' : env β’ arg β¦(nβ + nβ + 1) val := by
apply Eval.Indexed.monotone ihβ; linarith
exists (nβ + nβ + nβ + 1)
apply Eval.Indexed.app
Β· rfl
Β· exact ihβ'
Β· exact ihβ'
Β· exact ihβ
case constr_app ihβ ihβ =>
obtain β¨nβ, ihββ© := ihβ
obtain β¨nβ, ihββ© := ihβ
exists (nβ + nβ + 1)
apply Eval.Indexed.constr_app (n' := nβ + nβ)
Β· linarith
Β· apply Eval.Indexed.monotone ihβ; linarith
Β· apply Eval.Indexed.monotone ihβ; linarith
case binop ihβ ihβ =>
obtain β¨nβ, ihββ© := ihβ
obtain β¨nβ, ihββ© := ihβ
exists (nβ + nβ)
apply Eval.Indexed.binop (n := nβ + nβ)
Β· apply Eval.Indexed.monotone ihβ; linarith
Β· apply Eval.Indexed.monotone ihβ; linarith
case lambda =>
exists 0; apply Eval.Indexed.lambda
case save ihβ ihβ =>
obtain β¨nβ, ihββ© := ihβ
obtain β¨nβ, ihββ© := ihβ
exists (nβ + nβ)
apply Eval.Indexed.save (n := nβ + nβ)
Β· rfl
Β· apply Eval.Indexed.monotone ihβ; linarith
Β· apply Eval.Indexed.monotone ihβ; linarith
case branch_matches ih =>
obtain β¨n, ihβ© := ih
exists (n + 1)
apply Eval.Indexed.branch_matches (n' := n)
Β· linarith
Β· assumption
case branch_fails ih =>
obtain β¨n, ihβ© := ih
exists n
apply Eval.Indexed.branch_fails <;> assumption
case recur ih =>
obtain β¨n, ihβ© := ih
exists n.succ
apply Eval.Indexed.recur (n' := n)
Β· linarith
Β· assumption | 3 | 24 | true | Semantics |
248 | Juvix.Core.Main.Termination.recur | lemma Termination.recur {env name e} :
Object.delayed env (Expr.recur name e) :: env β’ e β β
env β’ Expr.recur name e β | juvix-lean | Juvix/Core/Main/Tactics/Termination.lean | [
"import Juvix.Core.Main.Tactics.Base"
] | [
{
"name": "BEq",
"module": "Init.Prelude"
},
{
"name": "DecidableEq",
"module": "Init.Prelude"
},
{
"name": "Inhabited",
"module": "Init.Prelude"
},
{
"name": "Int",
"module": "Init.Data.Int.Basic"
},
{
"name": "String",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "closure",
"module": "Mathlib.Topology.Defs.Basic"
}
] | [
{
"name": "syntax:100 expr:100 ppSpace expr:101 : expr",
"content": "syntax:100 expr:100 ppSpace expr:101 : expr\n\nsyntax:50 expr:50 \" + \" expr:51 : expr\n\nsyntax:50 expr:50 \" - \" expr:50 : expr\n\nsyntax:60 expr:60 \" * \" expr:61 : expr\n\nsyntax:60 expr:60 \" / \" expr:60 : expr"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β\" => Eval.Defined env e",
"content": "notation:40 env:40 \" β’ \" e:40 \" β\" => Eval.Defined env e"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Inde",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Indexed n env e v"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(βͺ$s:ident β― $i:numβ«) => `(Expr.var $(Lean.Syntax.mkStrLit s.getId.toString) $i)\n | `(βͺ$num:numβ«) => `(Expr.const (Constant.int $num))\n | `(βͺ$s:strβ«) => `(Expr.const (Constant.string $s))\n | `(βͺΟ
β«) => `(Expr.unit)\n | `(βͺ$eβ:expr $eβ:exprβ«) => `(Expr.app βͺ$eββ« βͺ$eββ«)\n | `(βͺΞ» $s:ident $e:exprβ«) => `(Expr.lambda $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eβ«)\n | `(βͺΞ» $ss:ident* . $e:exprβ«) => mkLambdas ss e\n | `(βͺ $s:ident β«) => `(Expr.constr $(Lean.Syntax.mkStrLit s.getId.toString))\n | `(βͺ $s:ident $es:expr* β«) => mkConstrApp s es\n | `(βͺ$eβ + $eββ«) => `(Expr.binop BinaryOp.add_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ - $eββ«) => `(Expr.binop BinaryOp.sub_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ * $eββ«) => `(Expr.binop BinaryOp.mul_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ / $eββ«) => `(Expr.binop BinaryOp.div_int βͺ$eββ« βͺ$eββ«)\n | `(βͺlet $s:ident := $eβ:expr in $eβ:exprβ«) => `(Expr.save $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eββ« βͺ$eββ«)\n | `(βͺletrec $s:ident := $eβ:expr in $eβ:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.save $name (Expr.recur $name βͺ$eββ«) βͺ$eββ«)\n | `(βͺrec $s:ident $e:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.recur $name βͺ$eβ«)\n | `(βͺβ₯β«) => `(Expr.fail)\n | `(βͺcases| | $s:ident => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« Expr.fail)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« Expr.fail)\n | `(βͺcases| | _ => $e:expr β«) =>\n `(βͺ$eβ«)\n | `(βͺcase $e:expr of $cs:cases endβ«) => do\n `(Expr.save \"_case_\" βͺ$eβ« βͺcases|$csβ«)\n | `(βͺ($e)β«) => `(βͺ$eβ«)\n\n inductive Object : Type where\n | value : Value β Object\n | delayed : (env : List Object) β Expr β Object\n deriving Inhabited"
},
{
"name": "Eval",
"content": "@[aesop unsafe constructors]\ninductive Eval : Env β Expr β Value β Prop where\n | var {env name idx val} :\n env[idx]? = some (Object.value val) β\n Eval env (Expr.var name idx) val\n | var_rec {env name idx env' expr val} :\n env[idx]? = some (Object.delayed env' expr) β\n Eval env' expr val β\n Eval env (Expr.var name idx) val\n | unit {env} :\n Eval env Expr.unit Value.unit\n | const {env c} :\n Eval env (Expr.const c) (Value.const c)\n | constr {env name} :\n Eval env (Expr.constr name) (Value.constr_app name [])\n | app {env env' f body arg val val'} :\n Eval env f (Value.closure env' body) β\n Eval env arg val β\n Eval (val β· env') body val' β\n Eval env (Expr.app f arg) val'\n | constr_app {env ctr ctr_name ctr_args_rev arg val} :\n Eval env ctr (Value.constr_app ctr_name ctr_args_rev) β\n Eval env arg val β\n Eval env (Expr.constr_app ctr arg) (Value.constr_app ctr_name (val :: ctr_args_rev))\n | binop {env op argβ argβ valβ valβ} :\n Eval env argβ (Value.const (Constant.int valβ)) β\n Eval env argβ (Value.const (Constant.int valβ)) β\n Eval env (Expr.binop op argβ argβ) (Value.const (Constant.int (eval_binop_int op valβ valβ)))\n | lambda {env name body} :\n Eval env (Expr.lambda name body) (Value.closure env body)\n | save {env name value body val val'} :\n Eval env value val β\n Eval (val β· env) body val' β\n Eval env (Expr.save name value body) val'\n | branch_matches {env name args_rev body val} :\n Eval (args_rev.map Object.value ++ env) body val β\n Eval (Value.constr_app name args_rev β· env) (Expr.branch name _ body _) val\n | branch_fails {env name name' args_rev next val} :\n name β name' β\n Eval (Value.constr_app name args_rev β· env) next val β\n Eval (Value.constr_app name args_rev β· env) (Expr.branch name' _ _ next) val\n | recur {env name body val} :\n Eval (Object.delayed env (Expr.recur name body) :: env) body val β\n Eval env (Expr.recur name body) val"
},
{
"name": "eval_binop_int",
"content": "def eval_binop_int (op : BinaryOp) (iβ iβ : Int) : Int :=\n match op with\n | BinaryOp.add_int => iβ + iβ\n | BinaryOp.sub_int => iβ - iβ\n | BinaryOp.mul_int => iβ * iβ\n | BinaryOp.div_int => iβ / iβ"
},
{
"name": "BinaryOp",
"content": "inductive BinaryOp : Type where\n | add_int : BinaryOp\n | sub_int : BinaryOp\n | mul_int : BinaryOp\n | div_int : BinaryOp\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Expr",
"content": "inductive Expr : Type where\n | var : (name : String) β (index : Nat) β Expr\n | unit : Expr\n | const : Constant β Expr\n | constr : Name β Expr\n | app : Expr β Expr β Expr\n | constr_app : Expr β Expr β Expr\n | binop : (oper : BinaryOp) β (argβ argβ : Expr) β Expr\n | lambda : (var_name : String) β (body : Expr) β Expr\n | save : (var_name : String) β (value : Expr) β (body : Expr) β Expr\n | branch : (constr : Name) β (var_names : List Name) β (body : Expr) β (next : Expr) β Expr\n | recur : (var_name : Name) β (body : Expr) β Expr\n | fail : Expr\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "cons_value",
"content": "abbrev cons_value (v : Value) (env : Env) : Env := Object.value v :: env\n\n inductive Value : Type where\n | unit : Value\n | const : Constant β Value\n | constr_app : (constr : Name) β (args_rev : List Value) β Value\n | closure : (env : List Object) β (value : Expr) β Value\n deriving Inhabited"
},
{
"name": "Constant",
"content": "inductive Constant : Type where\n | int : Int β Constant\n | string : String β Constant\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Name",
"content": "abbrev Name : Type := String"
},
{
"name": "Env",
"content": "abbrev Env : Type := List Object"
},
{
"name": "Eval.Defined",
"content": "def Eval.Defined (env : Env) (e : Expr) : Prop :=\n β v, env β’ e β¦ v"
},
{
"name": "infixr:50 \" β· \" => cons_value",
"content": "infixr:50 \" β· \" => cons_value"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β\" => Eval.Defined env e",
"content": "notation:40 env:40 \" β’ \" e:40 \" β\" => Eval.Defined env e"
},
{
"name": "infixl:100 \" @@ \" => Expr.app",
"content": "infixl:100 \" @@ \" => Expr.app"
}
] | [
{
"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]"
}
] | [] | [] | import Juvix.Core.Main.Tactics.Base
namespace Juvix.Core.Main | lemma Termination.recur {env name e} :
Object.delayed env (Expr.recur name e) :: env β’ e β β
env β’ Expr.recur name e β := | := by
unfold Eval.Defined
intro h
obtain β¨w, hβ© := h
exists w
Β· apply Juvix.Core.Main.Eval.recur
exact h | 4 | 19 | false | Semantics |
249 | Juvix.Core.Main.Value.Approx.Indexed.trans | @[trans]
lemma Value.Approx.Indexed.trans {n vβ vβ vβ} : vβ β²α΅₯(n) vβ β vβ β²α΅₯ vβ β vβ β²α΅₯(n) vβ | juvix-lean | Juvix/Core/Main/Semantics/Approx.lean | [
"import Juvix.Core.Main.Semantics.Approx.Indexed",
"import Juvix.Utils"
] | [
{
"name": "BEq",
"module": "Init.Prelude"
},
{
"name": "DecidableEq",
"module": "Init.Prelude"
},
{
"name": "Inhabited",
"module": "Init.Prelude"
},
{
"name": "Int",
"module": "Init.Data.Int.Basic"
},
{
"name": "String",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "closure",
"module": "Mathlib.Topology.Defs.Basic"
},
{
"name": "List.Forallβ",
"module": "Batteries.Data.List.Basic"
},
{
"name": "IsEmpty",
"module": "Mathlib.Logic.IsEmpty"
}
] | [
{
"name": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Inde",
"content": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Indexed n v v'"
},
{
"name": "notation:40 v:40 \" β²α΅₯ \" v':40 => Value.Approx v v'",
"content": "notation:40 v:40 \" β²α΅₯ \" v':40 => Value.Approx v v'"
},
{
"name": "notation:40 eβ:40 \" β² \" eβ:40 => Expr.Approx eβ eβ",
"content": "notation:40 eβ:40 \" β² \" eβ:40 => Expr.Approx eβ eβ"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β\" => Eval.Defined env e",
"content": "notation:40 env:40 \" β’ \" e:40 \" β\" => Eval.Defined env e"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Inde",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Indexed n env e v"
},
{
"name": "notation:40 e:40 \" β²β¨\" env:40 \", \" env':40 \"β© \" e':40 => Exp",
"content": "notation:40 e:40 \" β²β¨\" env:40 \", \" env':40 \"β© \" e':40 => Expr.Approx.Param env env' e e'"
},
{
"name": "notation:40 argsβ:40 \" β²β \" argsβ:40 => List.Forallβ Value.A",
"content": "notation:40 argsβ:40 \" β²β \" argsβ:40 => List.Forallβ Value.Approx argsβ argsβ"
},
{
"name": "macro \"invert\" h:term : tactic => `(tactic| (cases ($h).inve",
"content": "macro \"invert\" h:term : tactic => `(tactic| (cases ($h).invert <;> try clear $h))"
},
{
"name": "notation:40 argsβ:40 \" β²β(\" n:40 \") \" argsβ:40 => List.Foral",
"content": "notation:40 argsβ:40 \" β²β(\" n:40 \") \" argsβ:40 => List.Forallβ (Value.Approx.Indexed n) argsβ argsβ\n\nsyntax \"case \" expr \" of \" cases \" end\" : expr"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(βͺ$s:ident β― $i:numβ«) => `(Expr.var $(Lean.Syntax.mkStrLit s.getId.toString) $i)\n | `(βͺ$num:numβ«) => `(Expr.const (Constant.int $num))\n | `(βͺ$s:strβ«) => `(Expr.const (Constant.string $s))\n | `(βͺΟ
β«) => `(Expr.unit)\n | `(βͺ$eβ:expr $eβ:exprβ«) => `(Expr.app βͺ$eββ« βͺ$eββ«)\n | `(βͺΞ» $s:ident $e:exprβ«) => `(Expr.lambda $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eβ«)\n | `(βͺΞ» $ss:ident* . $e:exprβ«) => mkLambdas ss e\n | `(βͺ $s:ident β«) => `(Expr.constr $(Lean.Syntax.mkStrLit s.getId.toString))\n | `(βͺ $s:ident $es:expr* β«) => mkConstrApp s es\n | `(βͺ$eβ + $eββ«) => `(Expr.binop BinaryOp.add_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ - $eββ«) => `(Expr.binop BinaryOp.sub_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ * $eββ«) => `(Expr.binop BinaryOp.mul_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ / $eββ«) => `(Expr.binop BinaryOp.div_int βͺ$eββ« βͺ$eββ«)\n | `(βͺlet $s:ident := $eβ:expr in $eβ:exprβ«) => `(Expr.save $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eββ« βͺ$eββ«)\n | `(βͺletrec $s:ident := $eβ:expr in $eβ:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.save $name (Expr.recur $name βͺ$eββ«) βͺ$eββ«)\n | `(βͺrec $s:ident $e:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.recur $name βͺ$eβ«)\n | `(βͺβ₯β«) => `(Expr.fail)\n | `(βͺcases| | $s:ident => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« Expr.fail)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« Expr.fail)\n | `(βͺcases| | _ => $e:expr β«) =>\n `(βͺ$eβ«)\n | `(βͺcase $e:expr of $cs:cases endβ«) => do\n `(Expr.save \"_case_\" βͺ$eβ« βͺcases|$csβ«)\n | `(βͺ($e)β«) => `(βͺ$eβ«)"
},
{
"name": "BinaryOp",
"content": "inductive BinaryOp : Type where\n | add_int : BinaryOp\n | sub_int : BinaryOp\n | mul_int : BinaryOp\n | div_int : BinaryOp\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Value.Approx.Indexed",
"content": "def Value.Approx.Indexed (n : Nat) (vβ vβ : Value) : Prop :=\n (vβ = Value.unit β§ vβ = Value.unit) β¨\n (β c, vβ = Value.const c β§ vβ = Value.const c) β¨\n (β ctr_name args_rev args_rev',\n vβ = Value.constr_app ctr_name args_rev β§\n vβ = Value.constr_app ctr_name args_rev' β§\n (β k < n, List.Forallβ (Value.Approx.Indexed k) args_rev args_rev')) β¨\n (β envβ bodyβ envβ bodyβ,\n vβ = Value.closure envβ bodyβ β§\n vβ = Value.closure envβ bodyβ β§\n (β nβ nβ, nβ + nβ < n β\n β aβ aβ rβ,\n Value.Approx.Indexed (nβ + nβ) aβ aβ β\n aβ β· envβ β’ bodyβ β¦(nβ) rβ β\n β rβ,\n aβ β· envβ β’ bodyβ β¦ rβ β§\n Value.Approx.Indexed nβ rβ rβ))\n\n inductive Value : Type where\n | unit : Value\n | const : Constant β Value\n | constr_app : (constr : Name) β (args_rev : List Value) β Value\n | closure : (env : List Object) β (value : Expr) β Value\n deriving Inhabited"
},
{
"name": "cons_value",
"content": "abbrev cons_value (v : Value) (env : Env) : Env := Object.value v :: env\n\n inductive Object : Type where\n | value : Value β Object\n | delayed : (env : List Object) β Expr β Object\n deriving Inhabited"
},
{
"name": "Expr",
"content": "inductive Expr : Type where\n | var : (name : String) β (index : Nat) β Expr\n | unit : Expr\n | const : Constant β Expr\n | constr : Name β Expr\n | app : Expr β Expr β Expr\n | constr_app : Expr β Expr β Expr\n | binop : (oper : BinaryOp) β (argβ argβ : Expr) β Expr\n | lambda : (var_name : String) β (body : Expr) β Expr\n | save : (var_name : String) β (value : Expr) β (body : Expr) β Expr\n | branch : (constr : Name) β (var_names : List Name) β (body : Expr) β (next : Expr) β Expr\n | recur : (var_name : Name) β (body : Expr) β Expr\n | fail : Expr\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Constant",
"content": "inductive Constant : Type where\n | int : Int β Constant\n | string : String β Constant\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Name",
"content": "abbrev Name : Type := String"
},
{
"name": "Env",
"content": "abbrev Env : Type := List Object"
},
{
"name": "Value.Approx.Indexed.Inversion",
"content": "@[aesop safe cases]\ninductive Value.Approx.Indexed.Inversion (n : Nat) : Value β Value β Prop where\n | unit : Value.Approx.Indexed.Inversion n Value.unit Value.unit\n | const {c} : Value.Approx.Indexed.Inversion n (Value.const c) (Value.const c)\n | constr_app {ctr_name args_rev args_rev'} :\n (β k < n, args_rev β²β(k) args_rev') β\n Value.Approx.Indexed.Inversion n (Value.constr_app ctr_name args_rev) (Value.constr_app ctr_name args_rev')\n | closure {envβ bodyβ envβ bodyβ} :\n (β nβ nβ, nβ + nβ < n β\n β aβ aβ vβ,\n aβ β²α΅₯(nβ + nβ) aβ β\n aβ β· envβ β’ bodyβ β¦(nβ) vβ β\n β vβ, aβ β· envβ β’ bodyβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ) β\n Value.Approx.Indexed.Inversion n (Value.closure envβ bodyβ) (Value.closure envβ bodyβ)"
},
{
"name": "infixr:50 \" β· \" => cons_value",
"content": "infixr:50 \" β· \" => cons_value"
},
{
"name": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Inde",
"content": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Indexed n v v'"
},
{
"name": "infixl:100 \" @@ \" => Expr.app",
"content": "infixl:100 \" @@ \" => Expr.app"
}
] | [
{
"name": "IsEmpty.forall_iff",
"module": "Mathlib.Logic.IsEmpty"
},
{
"name": "implies_true",
"module": "Init.SimpLemmas"
},
{
"name": "nonpos_iff_eq_zero",
"module": "Mathlib.Algebra.Order.Monoid.Canonical.Defs"
},
{
"name": "not_lt_zero'",
"module": "Mathlib.Algebra.Order.GroupWithZero.Canonical"
}
] | [
{
"name": "Value.Approx.Indexed.invert",
"content": "@[aesop unsafe destruct]\nlemma Value.Approx.Indexed.invert {n v v'} :\n v β²α΅₯(n) v' β\n Value.Approx.Indexed.Inversion n v v'"
},
{
"name": "Value.Approx.Indexed.constr_app",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.constr_app {n ctr_name args_rev args_rev'} :\n (β k < n, args_rev β²β(k) args_rev') β\n Value.constr_app ctr_name args_rev β²α΅₯(n) Value.constr_app ctr_name args_rev'"
},
{
"name": "Value.Approx.Indexed.unit",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.unit {n} : Value.unit β²α΅₯(n) Value.unit"
},
{
"name": "Value.Approx.Indexed.const",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.const {n c} : Value.const c β²α΅₯(n) Value.const c"
},
{
"name": "Value.Approx.Indexed.closure",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.closure {n envβ bodyβ envβ bodyβ} :\n (β nβ nβ, nβ + nβ < n β\n β aβ aβ vβ,\n aβ β²α΅₯(nβ + nβ) aβ β\n aβ β· envβ β’ bodyβ β¦(nβ) vβ β\n β vβ, aβ β· envβ β’ bodyβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ) β\n Value.closure envβ bodyβ β²α΅₯(n) Value.closure envβ bodyβ"
},
{
"name": "forallβ_trans'",
"content": "theorem forallβ_trans' {Ξ±} {P Q R : Ξ± β Ξ± β Prop} {lβ lβ lβ}\n (h : β x y z, P x y β Q y z β R x z)\n (hβ : List.Forallβ P lβ lβ)\n (hβ : List.Forallβ Q lβ lβ)\n : List.Forallβ R lβ lβ"
}
] | [
{
"name": "Juvix.Core.Main.Value.Approx",
"content": "def Value.Approx (v v' : Value) : Prop :=\n β n, v β²α΅₯(n) v'"
},
{
"name": "Juvix.Core.Main.Value.Approx.Inversion",
"content": "@[aesop safe cases]\ninductive Value.Approx.Inversion : Value -> Value -> Prop where\n | unit : Value.Approx.Inversion Value.unit Value.unit\n | const {c} : Value.Approx.Inversion (Value.const c) (Value.const c)\n | constr_app {ctr_name args_rev args_rev'} :\n args_rev β²β args_rev' β\n Value.Approx.Inversion (Value.constr_app ctr_name args_rev) (Value.constr_app ctr_name args_rev')\n | closure {envβ bodyβ envβ bodyβ} :\n (β aβ aβ, aβ β²α΅₯ aβ β bodyβ β²β¨aβ β· envβ, aβ β· envββ© bodyβ) β\n Value.Approx.Inversion (Value.closure envβ bodyβ) (Value.closure envβ bodyβ)"
}
] | [
{
"name": "Juvix.Core.Main.Value.Approx.invert",
"content": "@[aesop unsafe destruct]\nlemma Value.Approx.invert {v v'} :\n v β²α΅₯ v' β\n Value.Approx.Inversion v v'"
}
] | import Juvix.Core.Main.Semantics.Approx.Indexed
namespace Juvix.Core.Main
def Value.Approx (v v' : Value) : Prop :=
β n, v β²α΅₯(n) v'
notation:40 v:40 " β²α΅₯ " v':40 => Value.Approx v v'
notation:40 argsβ:40 " β²β " argsβ:40 => List.Forallβ Value.Approx argsβ argsβ
notation:40 e:40 " β²β¨" env:40 ", " env':40 "β© " e':40 => Expr.Approx.Param env env' e e'
notation:40 v:40 " β²β " v':40 => Object.Approx v v'
notation:40 envβ:40 " β²β " envβ:40 => Env.Approx envβ envβ
notation:40 eβ:40 " β² " eβ:40 => Expr.Approx eβ eβ
@[aesop safe cases]
inductive Value.Approx.Inversion : Value -> Value -> Prop where
| unit : Value.Approx.Inversion Value.unit Value.unit
| const {c} : Value.Approx.Inversion (Value.const c) (Value.const c)
| constr_app {ctr_name args_rev args_rev'} :
args_rev β²β args_rev' β
Value.Approx.Inversion (Value.constr_app ctr_name args_rev) (Value.constr_app ctr_name args_rev')
| closure {envβ bodyβ envβ bodyβ} :
(β aβ aβ, aβ β²α΅₯ aβ β bodyβ β²β¨aβ β· envβ, aβ β· envββ© bodyβ) β
Value.Approx.Inversion (Value.closure envβ bodyβ) (Value.closure envβ bodyβ) | @[trans]
lemma Value.Approx.Indexed.trans {n vβ vβ vβ} : vβ β²α΅₯(n) vβ β vβ β²α΅₯ vβ β vβ β²α΅₯(n) vβ := | := by
revert n
suffices β n, β k β€ n, vβ β²α΅₯(k) vβ β vβ β²α΅₯ vβ β vβ β²α΅₯(k) vβ by
intro k
exact this k k k.le_refl
intros n
induction n generalizing vβ vβ vβ with
| zero =>
intros k hk hβ hβ
invert hβ
case unit =>
invert hβ
case unit =>
exact Value.Approx.Indexed.unit
case const =>
invert hβ
case const =>
exact Value.Approx.Indexed.const
case constr_app ctr_name args_revβ args_revβ' chβ =>
cases hβ.invert
case constr_app args_revβ chβ =>
apply Value.Approx.Indexed.constr_app;
intros
simp_all only [nonpos_iff_eq_zero, not_lt_zero', IsEmpty.forall_iff, implies_true]
case closure envβ bodyβ envβ' bodyβ' chβ =>
cases hβ.invert
case closure envβ bodyβ chβ =>
apply Value.Approx.Indexed.closure
Β· intro k' hk' v vβ h
have : k = 0 := by linarith
subst k
contradiction
| succ n ih =>
intros k hk hβ hβ
invert hβ
case unit =>
invert hβ
case unit =>
exact Value.Approx.Indexed.unit
case const =>
invert hβ
case const =>
exact Value.Approx.Indexed.const
case constr_app ctr_name args_rev args_rev' chβ =>
invert hβ
case constr_app args_rev'' chβ =>
apply Value.Approx.Indexed.constr_app
Β· intro k' hk'
have hk' : k' β€ n := by linarith
apply Utils.forallβ_trans' (P := fun vβ vβ => vβ β²α΅₯(k') vβ) (Q := fun vβ vβ => vβ β²α΅₯ vβ)
Β· intros vβ vβ vβ hβ hβ
apply ih <;> assumption
Β· apply chβ
simp_all only
Β· apply chβ
case closure envβ bodyβ envβ bodyβ chβ =>
invert hβ
case closure envβ bodyβ chβ =>
apply Value.Approx.Indexed.closure
Β· intro nβ nβ hn aβ aβ vβ happrox hevalβ
have ahβ : β vβ, (aβ β· envβ) β’ bodyβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ := by
apply chβ
Β· assumption
Β· assumption
Β· assumption
obtain β¨vβ, hevalβ, hββ© := ahβ
have ahβ : β vβ, (aβ β· envβ) β’ bodyβ β¦ vβ β§ vβ β²α΅₯ vβ := by
apply chβ
Β· rfl
Β· assumption
obtain β¨vβ, _, hββ© := ahβ
have : nβ β€ n := by linarith
exists vβ
aesop | 3 | 33 | true | Semantics |
250 | Juvix.Core.Main.Value.Approx.Indexed.anti_monotone | lemma Value.Approx.Indexed.anti_monotone {n n' vβ vβ} (h : vβ β²α΅₯(n) vβ) (h' : n' β€ n) : vβ β²α΅₯(n') vβ | juvix-lean | Juvix/Core/Main/Semantics/Approx/Indexed.lean | [
"import Juvix.Utils",
"import Juvix.Core.Main.Semantics.Eval.Indexed",
"import Mathlib.Tactic.Linarith",
"import Mathlib.Data.List.Forall2",
"import Juvix.Core.Main.Semantics.Eval",
"import Aesop"
] | [
{
"name": "BEq",
"module": "Init.Prelude"
},
{
"name": "DecidableEq",
"module": "Init.Prelude"
},
{
"name": "Inhabited",
"module": "Init.Prelude"
},
{
"name": "Int",
"module": "Init.Data.Int.Basic"
},
{
"name": "String",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "closure",
"module": "Mathlib.Topology.Defs.Basic"
},
{
"name": "List.Forallβ",
"module": "Batteries.Data.List.Basic"
},
{
"name": "Prod",
"module": "Init.Prelude"
},
{
"name": "reduceCtorEq",
"module": "Lean.Meta.Tactic.Simp.BuiltinSimprocs.Core"
}
] | [
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β\" => Eval.Defined env e",
"content": "notation:40 env:40 \" β’ \" e:40 \" β\" => Eval.Defined env e"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Inde",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Indexed n env e v"
},
{
"name": "notation:40 argsβ:40 \" β²β(\" n:40 \") \" argsβ:40 => List.Foral",
"content": "notation:40 argsβ:40 \" β²β(\" n:40 \") \" argsβ:40 => List.Forallβ (Value.Approx.Indexed n) argsβ argsβ"
},
{
"name": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Inde",
"content": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Indexed n v v'"
},
{
"name": "macro \"invert\" h:term : tactic => `(tactic| (cases ($h).inve",
"content": "macro \"invert\" h:term : tactic => `(tactic| (cases ($h).invert <;> try clear $h))\n\nsyntax \"case \" expr \" of \" cases \" end\" : expr"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(βͺ$s:ident β― $i:numβ«) => `(Expr.var $(Lean.Syntax.mkStrLit s.getId.toString) $i)\n | `(βͺ$num:numβ«) => `(Expr.const (Constant.int $num))\n | `(βͺ$s:strβ«) => `(Expr.const (Constant.string $s))\n | `(βͺΟ
β«) => `(Expr.unit)\n | `(βͺ$eβ:expr $eβ:exprβ«) => `(Expr.app βͺ$eββ« βͺ$eββ«)\n | `(βͺΞ» $s:ident $e:exprβ«) => `(Expr.lambda $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eβ«)\n | `(βͺΞ» $ss:ident* . $e:exprβ«) => mkLambdas ss e\n | `(βͺ $s:ident β«) => `(Expr.constr $(Lean.Syntax.mkStrLit s.getId.toString))\n | `(βͺ $s:ident $es:expr* β«) => mkConstrApp s es\n | `(βͺ$eβ + $eββ«) => `(Expr.binop BinaryOp.add_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ - $eββ«) => `(Expr.binop BinaryOp.sub_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ * $eββ«) => `(Expr.binop BinaryOp.mul_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ / $eββ«) => `(Expr.binop BinaryOp.div_int βͺ$eββ« βͺ$eββ«)\n | `(βͺlet $s:ident := $eβ:expr in $eβ:exprβ«) => `(Expr.save $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eββ« βͺ$eββ«)\n | `(βͺletrec $s:ident := $eβ:expr in $eβ:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.save $name (Expr.recur $name βͺ$eββ«) βͺ$eββ«)\n | `(βͺrec $s:ident $e:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.recur $name βͺ$eβ«)\n | `(βͺβ₯β«) => `(Expr.fail)\n | `(βͺcases| | $s:ident => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« Expr.fail)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« Expr.fail)\n | `(βͺcases| | _ => $e:expr β«) =>\n `(βͺ$eβ«)\n | `(βͺcase $e:expr of $cs:cases endβ«) => do\n `(Expr.save \"_case_\" βͺ$eβ« βͺcases|$csβ«)\n | `(βͺ($e)β«) => `(βͺ$eβ«)\n\n inductive Value : Type where\n | unit : Value\n | const : Constant β Value\n | constr_app : (constr : Name) β (args_rev : List Value) β Value\n | closure : (env : List Object) β (value : Expr) β Value\n deriving Inhabited"
},
{
"name": "cons_value",
"content": "abbrev cons_value (v : Value) (env : Env) : Env := Object.value v :: env\n\n inductive Object : Type where\n | value : Value β Object\n | delayed : (env : List Object) β Expr β Object\n deriving Inhabited"
},
{
"name": "Expr",
"content": "inductive Expr : Type where\n | var : (name : String) β (index : Nat) β Expr\n | unit : Expr\n | const : Constant β Expr\n | constr : Name β Expr\n | app : Expr β Expr β Expr\n | constr_app : Expr β Expr β Expr\n | binop : (oper : BinaryOp) β (argβ argβ : Expr) β Expr\n | lambda : (var_name : String) β (body : Expr) β Expr\n | save : (var_name : String) β (value : Expr) β (body : Expr) β Expr\n | branch : (constr : Name) β (var_names : List Name) β (body : Expr) β (next : Expr) β Expr\n | recur : (var_name : Name) β (body : Expr) β Expr\n | fail : Expr\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "BinaryOp",
"content": "inductive BinaryOp : Type where\n | add_int : BinaryOp\n | sub_int : BinaryOp\n | mul_int : BinaryOp\n | div_int : BinaryOp\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Constant",
"content": "inductive Constant : Type where\n | int : Int β Constant\n | string : String β Constant\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Name",
"content": "abbrev Name : Type := String"
},
{
"name": "Env",
"content": "abbrev Env : Type := List Object"
},
{
"name": "Value.Approx",
"content": "def Value.Approx (v v' : Value) : Prop :=\n β n, v β²α΅₯(n) v'"
},
{
"name": "infixr:50 \" β· \" => cons_value",
"content": "infixr:50 \" β· \" => cons_value"
},
{
"name": "notation:40 v:40 \" β²α΅₯ \" v':40 => Value.Approx v v'",
"content": "notation:40 v:40 \" β²α΅₯ \" v':40 => Value.Approx v v'"
},
{
"name": "infixl:100 \" @@ \" => Expr.app",
"content": "infixl:100 \" @@ \" => Expr.app"
}
] | [
{
"name": "and_self",
"module": "Init.SimpLemmas"
},
{
"name": "exists_and_left",
"module": "Init.PropLemmas"
},
{
"name": "exists_const",
"module": "Init.PropLemmas"
},
{
"name": "exists_eq_left'",
"module": "Init.PropLemmas"
},
{
"name": "false_and",
"module": "Init.SimpLemmas"
},
{
"name": "false_or",
"module": "Init.SimpLemmas"
},
{
"name": "implies_true",
"module": "Init.SimpLemmas"
},
{
"name": "or_false",
"module": "Init.SimpLemmas"
},
{
"name": "true_and",
"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": "Juvix.Core.Main.Value.Approx.Indexed",
"content": "def Value.Approx.Indexed (n : Nat) (vβ vβ : Value) : Prop :=\n (vβ = Value.unit β§ vβ = Value.unit) β¨\n (β c, vβ = Value.const c β§ vβ = Value.const c) β¨\n (β ctr_name args_rev args_rev',\n vβ = Value.constr_app ctr_name args_rev β§\n vβ = Value.constr_app ctr_name args_rev' β§\n (β k < n, List.Forallβ (Value.Approx.Indexed k) args_rev args_rev')) β¨\n (β envβ bodyβ envβ bodyβ,\n vβ = Value.closure envβ bodyβ β§\n vβ = Value.closure envβ bodyβ β§\n (β nβ nβ, nβ + nβ < n β\n β aβ aβ rβ,\n Value.Approx.Indexed (nβ + nβ) aβ aβ β\n aβ β· envβ β’ bodyβ β¦(nβ) rβ β\n β rβ,\n aβ β· envβ β’ bodyβ β¦ rβ β§\n Value.Approx.Indexed nβ rβ rβ))"
}
] | [
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.unit",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.unit {n} : Value.unit β²α΅₯(n) Value.unit"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.const",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.const {n c} : Value.const c β²α΅₯(n) Value.const c"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.constr_app",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.constr_app {n ctr_name args_rev args_rev'} :\n (β k < n, args_rev β²β(k) args_rev') β\n Value.constr_app ctr_name args_rev β²α΅₯(n) Value.constr_app ctr_name args_rev'"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.closure",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.closure {n envβ bodyβ envβ bodyβ} :\n (β nβ nβ, nβ + nβ < n β\n β aβ aβ vβ,\n aβ β²α΅₯(nβ + nβ) aβ β\n aβ β· envβ β’ bodyβ β¦(nβ) vβ β\n β vβ, aβ β· envβ β’ bodyβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ) β\n Value.closure envβ bodyβ β²α΅₯(n) Value.closure envβ bodyβ"
}
] | import Juvix.Core.Main.Semantics.Eval
import Juvix.Core.Main.Semantics.Eval.Indexed
import Juvix.Utils
import Mathlib.Tactic.Linarith
import Mathlib.Data.List.Forall2
import Aesop
namespace Juvix.Core.Main
def Value.Approx.Indexed (n : Nat) (vβ vβ : Value) : Prop :=
(vβ = Value.unit β§ vβ = Value.unit) β¨
(β c, vβ = Value.const c β§ vβ = Value.const c) β¨
(β ctr_name args_rev args_rev',
vβ = Value.constr_app ctr_name args_rev β§
vβ = Value.constr_app ctr_name args_rev' β§
(β k < n, List.Forallβ (Value.Approx.Indexed k) args_rev args_rev')) β¨
(β envβ bodyβ envβ bodyβ,
vβ = Value.closure envβ bodyβ β§
vβ = Value.closure envβ bodyβ β§
(β nβ nβ, nβ + nβ < n β
β aβ aβ rβ,
Value.Approx.Indexed (nβ + nβ) aβ aβ β
aβ β· envβ β’ bodyβ β¦(nβ) rβ β
β rβ,
aβ β· envβ β’ bodyβ β¦ rβ β§
Value.Approx.Indexed nβ rβ rβ))
notation:40 v:40 " β²α΅₯(" n:40 ") " v':40 => Value.Approx.Indexed n v v'
notation:40 argsβ:40 " β²β(" n:40 ") " argsβ:40 => List.Forallβ (Value.Approx.Indexed n) argsβ argsβ
notation:40 e:40 " β²(" n:40 ")β¨" env:40 ", " env':40 "β© " e':40 => Expr.Approx.Param.Indexed n env env' e e'
notation:40 v:40 " β²β'(" n:40 ") " v':40 => Object.Approx.Indexed' n v v'
notation:40 envβ:40 " β²β'(" n:40 ") " envβ:40 => Env.Approx.Indexed' n envβ envβ
notation:40 e:40 " β²'(" n:40 ") " e':40 => Expr.Approx.Indexed' n e e' | lemma Value.Approx.Indexed.anti_monotone {n n' vβ vβ} (h : vβ β²α΅₯(n) vβ) (h' : n' β€ n) : vβ β²α΅₯(n') vβ := | := by
revert n n'
suffices β n, vβ β²α΅₯(n) vβ β β k β€ n, vβ β²α΅₯(k) vβ by
intro n n' h hn
exact this n h n' hn
intro n
induction n generalizing vβ vβ with
| zero =>
intros h k hk
invert h
case unit =>
exact Value.Approx.Indexed.unit
case const =>
exact Value.Approx.Indexed.const
case constr_app ctr_name args_rev args_rev' hargs =>
apply Value.Approx.Indexed.constr_app
Β· intros
have : k = 0 := by linarith
subst k
contradiction
case closure envβ bodyβ envβ bodyβ h =>
apply Value.Approx.Indexed.closure
Β· intros
have : k = 0 := by linarith
subst k
contradiction
| succ n ih =>
intros h k hk
invert h
case unit =>
exact Value.Approx.Indexed.unit
case const =>
exact Value.Approx.Indexed.const
case constr_app ctr_name args_rev args_rev' hargs =>
apply Value.Approx.Indexed.constr_app
Β· intros k' hk'
have : k' < n + 1 := by linarith
simp_all only
case closure envβ bodyβ envβ bodyβ ch =>
apply Value.Approx.Indexed.closure
Β· intro nβ nβ hn aβ aβ vβ happrox heval
apply ch nβ nβ
Β· linarith
Β· assumption
Β· assumption | 3 | 34 | true | Semantics |
251 | Juvix.Core.Main.Expr.Approx.Context.preserved | lemma Expr.Approx.Context.preserved (eβ eβ : Expr) :
eβ β² eβ β
β (C : Context) envβ envβ vβ,
envβ β²β envβ β envβ β’ C.subst eβ β¦ vβ β
β vβ, envβ β’ C.subst eβ β¦ vβ β§ vβ β²α΅₯ vβ | juvix-lean | Juvix/Core/Main/Semantics/Approx/Soundness.lean | [
"import Juvix.Core.Main.Semantics.Approx.Indexed",
"import Juvix.Core.Main.Semantics.Approx",
"import Juvix.Core.Main.Semantics.Eval.Indexed",
"import Juvix.Core.Main.Semantics.Approx.Contextual",
"import Juvix.Core.Main.Semantics.Eval"
] | [
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "List.Forallβ",
"module": "Batteries.Data.List.Basic"
},
{
"name": "BEq",
"module": "Init.Prelude"
},
{
"name": "DecidableEq",
"module": "Init.Prelude"
},
{
"name": "Inhabited",
"module": "Init.Prelude"
},
{
"name": "Int",
"module": "Init.Data.Int.Basic"
},
{
"name": "String",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "closure",
"module": "Mathlib.Topology.Defs.Basic"
},
{
"name": "List.map",
"module": "Init.Prelude"
}
] | [
{
"name": "notation:40 e:40 \" β²β¨\" env:40 \", \" env':40 \"β© \" e':40 => Exp",
"content": "notation:40 e:40 \" β²β¨\" env:40 \", \" env':40 \"β© \" e':40 => Expr.Approx.Param env env' e e'"
},
{
"name": "notation:40 eβ:40 \" β² \" eβ:40 => Expr.Approx eβ eβ",
"content": "notation:40 eβ:40 \" β² \" eβ:40 => Expr.Approx eβ eβ"
},
{
"name": "notation:40 envβ:40 \" β²β \" envβ:40 => Env.Approx envβ envβ",
"content": "notation:40 envβ:40 \" β²β \" envβ:40 => Env.Approx envβ envβ"
},
{
"name": "notation:40 v:40 \" β²α΅₯ \" v':40 => Value.Approx v v'",
"content": "notation:40 v:40 \" β²α΅₯ \" v':40 => Value.Approx v v'"
},
{
"name": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Inde",
"content": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Indexed n v v'"
},
{
"name": "notation:40 e:40 \" β²'(\" n:40 \") \" e':40 => Expr.Approx.Index",
"content": "notation:40 e:40 \" β²'(\" n:40 \") \" e':40 => Expr.Approx.Indexed' n e e'"
},
{
"name": "notation:40 envβ:40 \" β²β'(\" n:40 \") \" envβ:40 => Env.Approx.",
"content": "notation:40 envβ:40 \" β²β'(\" n:40 \") \" envβ:40 => Env.Approx.Indexed' n envβ envβ"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β\" => Eval.Defined env e",
"content": "notation:40 env:40 \" β’ \" e:40 \" β\" => Eval.Defined env e"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Inde",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Indexed n env e v"
},
{
"name": "notation:40 e:40 \" β²(\" n:40 \")β¨\" env:40 \", \" env':40 \"β© \" e'",
"content": "notation:40 e:40 \" β²(\" n:40 \")β¨\" env:40 \", \" env':40 \"β© \" e':40 => Expr.Approx.Param.Indexed n env env' e e'\n\nsyntax:100 expr:100 ppSpace expr:101 : expr\n\nsyntax:50 expr:50 \" + \" expr:51 : expr\n\nsyntax:50 expr:50 \" - \" expr:50 : expr\n\nsyntax:60 expr:60 \" * \" expr:61 : expr\n\nsyntax:60 expr:60 \" / \" expr:60 : expr"
},
{
"name": "notation:40 argsβ:40 \" β²β \" argsβ:40 => List.Forallβ Value.A",
"content": "notation:40 argsβ:40 \" β²β \" argsβ:40 => List.Forallβ Value.Approx argsβ argsβ"
},
{
"name": "macro \"invert\" h:term : tactic => `(tactic| (cases ($h).inve",
"content": "macro \"invert\" h:term : tactic => `(tactic| (cases ($h).invert <;> try clear $h))\n\nsyntax \"case \" expr \" of \" cases \" end\" : expr"
},
{
"name": "notation:40 v:40 \" β²β \" v':40 => Object.Approx v v'",
"content": "notation:40 v:40 \" β²β \" v':40 => Object.Approx v v'"
},
{
"name": "notation:40 v:40 \" β²β'(\" n:40 \") \" v':40 => Object.Approx.In",
"content": "notation:40 v:40 \" β²β'(\" n:40 \") \" v':40 => Object.Approx.Indexed' n v v'"
},
{
"name": "notation:40 argsβ:40 \" β²β(\" n:40 \") \" argsβ:40 => List.Foral",
"content": "notation:40 argsβ:40 \" β²β(\" n:40 \") \" argsβ:40 => List.Forallβ (Value.Approx.Indexed n) argsβ argsβ\n\nsyntax \"let \" ident \" := \" expr \" in \" expr : expr"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(βͺ$s:ident β― $i:numβ«) => `(Expr.var $(Lean.Syntax.mkStrLit s.getId.toString) $i)\n | `(βͺ$num:numβ«) => `(Expr.const (Constant.int $num))\n | `(βͺ$s:strβ«) => `(Expr.const (Constant.string $s))\n | `(βͺΟ
β«) => `(Expr.unit)\n | `(βͺ$eβ:expr $eβ:exprβ«) => `(Expr.app βͺ$eββ« βͺ$eββ«)\n | `(βͺΞ» $s:ident $e:exprβ«) => `(Expr.lambda $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eβ«)\n | `(βͺΞ» $ss:ident* . $e:exprβ«) => mkLambdas ss e\n | `(βͺ $s:ident β«) => `(Expr.constr $(Lean.Syntax.mkStrLit s.getId.toString))\n | `(βͺ $s:ident $es:expr* β«) => mkConstrApp s es\n | `(βͺ$eβ + $eββ«) => `(Expr.binop BinaryOp.add_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ - $eββ«) => `(Expr.binop BinaryOp.sub_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ * $eββ«) => `(Expr.binop BinaryOp.mul_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ / $eββ«) => `(Expr.binop BinaryOp.div_int βͺ$eββ« βͺ$eββ«)\n | `(βͺlet $s:ident := $eβ:expr in $eβ:exprβ«) => `(Expr.save $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eββ« βͺ$eββ«)\n | `(βͺletrec $s:ident := $eβ:expr in $eβ:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.save $name (Expr.recur $name βͺ$eββ«) βͺ$eββ«)\n | `(βͺrec $s:ident $e:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.recur $name βͺ$eβ«)\n | `(βͺβ₯β«) => `(Expr.fail)\n | `(βͺcases| | $s:ident => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« Expr.fail)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« Expr.fail)\n | `(βͺcases| | _ => $e:expr β«) =>\n `(βͺ$eβ«)\n | `(βͺcase $e:expr of $cs:cases endβ«) => do\n `(Expr.save \"_case_\" βͺ$eβ« βͺcases|$csβ«)\n | `(βͺ($e)β«) => `(βͺ$eβ«)"
},
{
"name": "Expr.Approx",
"content": "def Expr.Approx (eβ eβ : Expr) : Prop :=\n β envβ envβ, envβ β²β envβ β eβ β²β¨envβ, envββ© eβ"
},
{
"name": "Env.Approx",
"content": "def Env.Approx : (envβ envβ : Env) β Prop :=\n List.Forallβ Object.Approx"
},
{
"name": "Object.Approx",
"content": "inductive Object.Approx : Object β Object β Prop where\n | value {vβ vβ} : vβ β²α΅₯ vβ β Object.Approx (Object.value vβ) (Object.value vβ)\n | delayed {envβ envβ eβ eβ} :\n eβ β²β¨envβ, envββ© eβ β\n Object.Approx (Object.delayed envβ eβ) (Object.delayed envβ eβ)\n\n inductive Object : Type where\n | value : Value β Object\n | delayed : (env : List Object) β Expr β Object\n deriving Inhabited"
},
{
"name": "Context.subst",
"content": "@[simp]\ndef Context.subst (C : Context) (e : Expr) : Expr :=\n match C with\n | Context.hole => e\n | Context.app_left C' e' => Expr.app (C'.subst e) e'\n | Context.app_right e' C' => Expr.app e' (C'.subst e)\n | Context.constr_app_left C' e' => Expr.constr_app (C'.subst e) e'\n | Context.constr_app_right e' C' => Expr.constr_app e' (C'.subst e)\n | Context.binop_left oper Cβ eβ => Expr.binop oper (Cβ.subst e) eβ\n | Context.binop_right oper eβ Cβ => Expr.binop oper eβ (Cβ.subst e)\n | Context.lambda s C' => Expr.lambda s (C'.subst e)\n | Context.save_left s C' e' => Expr.save s (C'.subst e) e'\n | Context.save_right s e' C' => Expr.save s e' (C'.subst e)\n | Context.branch_left constr names C' next => Expr.branch constr names (C'.subst e) next\n | Context.branch_right constr names body C' => Expr.branch constr names body (C'.subst e)\n | Context.recur name C' => Expr.recur name (C'.subst e)"
},
{
"name": "Context",
"content": "inductive Context : Type where\n | hole : Context\n | app_left : Context β Expr β Context\n | app_right : Expr β Context β Context\n | constr_app_left : Context β Expr β Context\n | constr_app_right : Expr β Context β Context\n | binop_left : (oper : BinaryOp) β (argβ : Context) β (argβ : Expr) β Context\n | binop_right : (oper : BinaryOp) β (argβ : Expr) β (argβ : Context) β Context\n | lambda : (var_name : String) β (body : Context) β Context\n | save_left : (var_name : String) β (value : Context) β (body : Expr) β Context\n | save_right : (var_name : String) β (value : Expr) β (body : Context) β Context\n | branch_left : (constr : Name) β (var_names : List Name) β (body : Context) β (next : Expr) β Context\n | branch_right : (constr : Name) β (var_names : List Name) β (body : Expr) β (next : Context) β Context\n | recur : (var_name : Name) β (ctx : Context) β Context\n deriving Inhabited, BEq"
},
{
"name": "Expr",
"content": "inductive Expr : Type where\n | var : (name : String) β (index : Nat) β Expr\n | unit : Expr\n | const : Constant β Expr\n | constr : Name β Expr\n | app : Expr β Expr β Expr\n | constr_app : Expr β Expr β Expr\n | binop : (oper : BinaryOp) β (argβ argβ : Expr) β Expr\n | lambda : (var_name : String) β (body : Expr) β Expr\n | save : (var_name : String) β (value : Expr) β (body : Expr) β Expr\n | branch : (constr : Name) β (var_names : List Name) β (body : Expr) β (next : Expr) β Expr\n | recur : (var_name : Name) β (body : Expr) β Expr\n | fail : Expr\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "BinaryOp",
"content": "inductive BinaryOp : Type where\n | add_int : BinaryOp\n | sub_int : BinaryOp\n | mul_int : BinaryOp\n | div_int : BinaryOp\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Constant",
"content": "inductive Constant : Type where\n | int : Int β Constant\n | string : String β Constant\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Name",
"content": "abbrev Name : Type := String"
},
{
"name": "Value.Approx.Inversion",
"content": "@[aesop safe cases]\ninductive Value.Approx.Inversion : Value -> Value -> Prop where\n | unit : Value.Approx.Inversion Value.unit Value.unit\n | const {c} : Value.Approx.Inversion (Value.const c) (Value.const c)\n | constr_app {ctr_name args_rev args_rev'} :\n args_rev β²β args_rev' β\n Value.Approx.Inversion (Value.constr_app ctr_name args_rev) (Value.constr_app ctr_name args_rev')\n | closure {envβ bodyβ envβ bodyβ} :\n (β aβ aβ, aβ β²α΅₯ aβ β bodyβ β²β¨aβ β· envβ, aβ β· envββ© bodyβ) β\n Value.Approx.Inversion (Value.closure envβ bodyβ) (Value.closure envβ bodyβ)"
},
{
"name": "Value.Approx",
"content": "def Value.Approx (v v' : Value) : Prop :=\n β n, v β²α΅₯(n) v'"
},
{
"name": "Eval.Indexed",
"content": "inductive Eval.Indexed : Nat β Env β Expr β Value β Prop where\n | var {n env name idx val} :\n env[idx]? = some (Object.value val) β\n Eval.Indexed n env (Expr.var name idx) val\n | var_rec {n env name idx env' expr val} :\n env[idx]? = some (Object.delayed env' expr) β\n Eval.Indexed n env' expr val β\n Eval.Indexed n env (Expr.var name idx) val\n | unit {n env} :\n Eval.Indexed n env Expr.unit Value.unit\n | const {n env c} :\n Eval.Indexed n env (Expr.const c) (Value.const c)\n | constr {n env name} :\n Eval.Indexed n env (Expr.constr name) (Value.constr_app name [])\n | app {n nβ nβ env env' f body arg val val'} :\n nβ + nβ + 1 β€ n β\n Eval.Indexed nβ env f (Value.closure env' body) β\n Eval.Indexed (nβ + 1) env arg val β\n Eval.Indexed nβ (val β· env') body val' β\n Eval.Indexed n env (Expr.app f arg) val'\n | constr_app {n n' env ctr ctr_name ctr_args_rev arg val} :\n n' < n β\n Eval.Indexed n env ctr (Value.constr_app ctr_name ctr_args_rev) β\n Eval.Indexed n' env arg val β\n Eval.Indexed n env (Expr.constr_app ctr arg) (Value.constr_app ctr_name (val :: ctr_args_rev))\n | binop {n env op argβ argβ valβ valβ} :\n Eval.Indexed n env argβ (Value.const (Constant.int valβ)) β\n Eval.Indexed n env argβ (Value.const (Constant.int valβ)) β\n Eval.Indexed n env (Expr.binop op argβ argβ) (Value.const (Constant.int (eval_binop_int op valβ valβ)))\n | lambda {n env name body} :\n Eval.Indexed n env (Expr.lambda name body) (Value.closure env body)\n | save {n nβ nβ env name value body val val'} :\n nβ + nβ β€ n β\n Eval.Indexed nβ env value val β\n Eval.Indexed nβ (val β· env) body val' β\n Eval.Indexed n env (Expr.save name value body) val'\n | branch_matches {n n' env name args_rev body val} :\n n' < n β\n Eval.Indexed n' (args_rev.map Object.value ++ env) body val β\n Eval.Indexed n (Value.constr_app name args_rev β· env) (Expr.branch name _ body _) val\n | branch_fails {n env name name' args_rev next val} :\n name β name' β\n Eval.Indexed n (Value.constr_app name args_rev β· env) next val β\n Eval.Indexed n (Value.constr_app name args_rev β· env) (Expr.branch name' _ _ next) val\n | recur {n n' env name body val} :\n n' < n β\n Eval.Indexed n' (Object.delayed env (Expr.recur name body) :: env) body val β\n Eval.Indexed n env (Expr.recur name body) val"
},
{
"name": "Eval",
"content": "@[aesop unsafe constructors]\ninductive Eval : Env β Expr β Value β Prop where\n | var {env name idx val} :\n env[idx]? = some (Object.value val) β\n Eval env (Expr.var name idx) val\n | var_rec {env name idx env' expr val} :\n env[idx]? = some (Object.delayed env' expr) β\n Eval env' expr val β\n Eval env (Expr.var name idx) val\n | unit {env} :\n Eval env Expr.unit Value.unit\n | const {env c} :\n Eval env (Expr.const c) (Value.const c)\n | constr {env name} :\n Eval env (Expr.constr name) (Value.constr_app name [])\n | app {env env' f body arg val val'} :\n Eval env f (Value.closure env' body) β\n Eval env arg val β\n Eval (val β· env') body val' β\n Eval env (Expr.app f arg) val'\n | constr_app {env ctr ctr_name ctr_args_rev arg val} :\n Eval env ctr (Value.constr_app ctr_name ctr_args_rev) β\n Eval env arg val β\n Eval env (Expr.constr_app ctr arg) (Value.constr_app ctr_name (val :: ctr_args_rev))\n | binop {env op argβ argβ valβ valβ} :\n Eval env argβ (Value.const (Constant.int valβ)) β\n Eval env argβ (Value.const (Constant.int valβ)) β\n Eval env (Expr.binop op argβ argβ) (Value.const (Constant.int (eval_binop_int op valβ valβ)))\n | lambda {env name body} :\n Eval env (Expr.lambda name body) (Value.closure env body)\n | save {env name value body val val'} :\n Eval env value val β\n Eval (val β· env) body val' β\n Eval env (Expr.save name value body) val'\n | branch_matches {env name args_rev body val} :\n Eval (args_rev.map Object.value ++ env) body val β\n Eval (Value.constr_app name args_rev β· env) (Expr.branch name _ body _) val\n | branch_fails {env name name' args_rev next val} :\n name β name' β\n Eval (Value.constr_app name args_rev β· env) next val β\n Eval (Value.constr_app name args_rev β· env) (Expr.branch name' _ _ next) val\n | recur {env name body val} :\n Eval (Object.delayed env (Expr.recur name body) :: env) body val β\n Eval env (Expr.recur name body) val"
},
{
"name": "Expr.Approx.Param.Indexed",
"content": "def Expr.Approx.Param.Indexed (n : Nat) (envβ envβ : Env) (eβ eβ : Expr) : Prop :=\n (β nβ nβ vβ, nβ + nβ β€ n β envβ β’ eβ β¦(nβ) vβ β β vβ, envβ β’ eβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ)"
},
{
"name": "Env",
"content": "abbrev Env : Type := List Object\n\n inductive Value : Type where\n | unit : Value\n | const : Constant β Value\n | constr_app : (constr : Name) β (args_rev : List Value) β Value\n | closure : (env : List Object) β (value : Expr) β Value\n deriving Inhabited"
},
{
"name": "Expr.Approx.Param",
"content": "def Expr.Approx.Param (envβ envβ : Env) (eβ eβ : Expr) : Prop :=\n (β vβ, envβ β’ eβ β¦ vβ β β vβ, envβ β’ eβ β¦ vβ β§ vβ β²α΅₯ vβ)"
},
{
"name": "Object.Approx.Indexed'",
"content": "inductive Object.Approx.Indexed' (n : Nat) : Object β Object β Prop where\n | value {vβ vβ} :\n vβ β²α΅₯(n) vβ β\n Object.Approx.Indexed' n (Object.value vβ) (Object.value vβ)\n | delayed {envβ envβ eβ eβ} :\n eβ β²(n)β¨envβ, envββ© eβ β\n Object.Approx.Indexed' n (Object.delayed envβ eβ) (Object.delayed envβ eβ)\n | delayed_eq {envβ envβ e} :\n List.Forallβ (Object.Approx.Indexed' n) envβ envβ β\n Object.Approx.Indexed' n (Object.delayed envβ e) (Object.delayed envβ e)"
},
{
"name": "Value.Approx.Indexed.Inversion",
"content": "@[aesop safe cases]\ninductive Value.Approx.Indexed.Inversion (n : Nat) : Value β Value β Prop where\n | unit : Value.Approx.Indexed.Inversion n Value.unit Value.unit\n | const {c} : Value.Approx.Indexed.Inversion n (Value.const c) (Value.const c)\n | constr_app {ctr_name args_rev args_rev'} :\n (β k < n, args_rev β²β(k) args_rev') β\n Value.Approx.Indexed.Inversion n (Value.constr_app ctr_name args_rev) (Value.constr_app ctr_name args_rev')\n | closure {envβ bodyβ envβ bodyβ} :\n (β nβ nβ, nβ + nβ < n β\n β aβ aβ vβ,\n aβ β²α΅₯(nβ + nβ) aβ β\n aβ β· envβ β’ bodyβ β¦(nβ) vβ β\n β vβ, aβ β· envβ β’ bodyβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ) β\n Value.Approx.Indexed.Inversion n (Value.closure envβ bodyβ) (Value.closure envβ bodyβ)"
},
{
"name": "eval_binop_int",
"content": "def eval_binop_int (op : BinaryOp) (iβ iβ : Int) : Int :=\n match op with\n | BinaryOp.add_int => iβ + iβ\n | BinaryOp.sub_int => iβ - iβ\n | BinaryOp.mul_int => iβ * iβ\n | BinaryOp.div_int => iβ / iβ"
},
{
"name": "cons_value",
"content": "abbrev cons_value (v : Value) (env : Env) : Env := Object.value v :: env"
},
{
"name": "Expr.Approx.Indexed'",
"content": "def Expr.Approx.Indexed' (n : Nat) (eβ eβ : Expr) : Prop :=\n (β nβ nβ vβ, nβ + nβ β€ n β\n β envβ envβ, envβ β²β'(nβ + nβ) envβ β envβ β’ eβ β¦(nβ) vβ β β vβ, envβ β’ eβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ)"
},
{
"name": "Value.Approx.Indexed",
"content": "def Value.Approx.Indexed (n : Nat) (vβ vβ : Value) : Prop :=\n (vβ = Value.unit β§ vβ = Value.unit) β¨\n (β c, vβ = Value.const c β§ vβ = Value.const c) β¨\n (β ctr_name args_rev args_rev',\n vβ = Value.constr_app ctr_name args_rev β§\n vβ = Value.constr_app ctr_name args_rev' β§\n (β k < n, List.Forallβ (Value.Approx.Indexed k) args_rev args_rev')) β¨\n (β envβ bodyβ envβ bodyβ,\n vβ = Value.closure envβ bodyβ β§\n vβ = Value.closure envβ bodyβ β§\n (β nβ nβ, nβ + nβ < n β\n β aβ aβ rβ,\n Value.Approx.Indexed (nβ + nβ) aβ aβ β\n aβ β· envβ β’ bodyβ β¦(nβ) rβ β\n β rβ,\n aβ β· envβ β’ bodyβ β¦ rβ β§\n Value.Approx.Indexed nβ rβ rβ))"
},
{
"name": "Env.Approx.Indexed'",
"content": "def Env.Approx.Indexed' (n : Nat) : (envβ envβ : Env) β Prop :=\n List.Forallβ (Object.Approx.Indexed' n)"
},
{
"name": "Value.Approx.Indexed.Preservation",
"content": "def Value.Approx.Indexed.Preservation (k : Nat) : Prop :=\n β m n env env' e v,\n m + n < k β\n env β²β'(m + n) env' β\n env β’ e β¦(n) v β\n β v', env' β’ e β¦ v' β§ v β²α΅₯(m) v'"
},
{
"name": "infixr:50 \" β· \" => cons_value",
"content": "infixr:50 \" β· \" => cons_value"
},
{
"name": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Inde",
"content": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Indexed n v v'"
},
{
"name": "notation:40 e:40 \" β²(\" n:40 \")β¨\" env:40 \", \" env':40 \"β© \" e'",
"content": "notation:40 e:40 \" β²(\" n:40 \")β¨\" env:40 \", \" env':40 \"β© \" e':40 => Expr.Approx.Param.Indexed n env env' e e'"
},
{
"name": "notation:40 v:40 \" β²β'(\" n:40 \") \" v':40 => Object.Approx.In",
"content": "notation:40 v:40 \" β²β'(\" n:40 \") \" v':40 => Object.Approx.Indexed' n v v'"
},
{
"name": "notation:40 envβ:40 \" β²β'(\" n:40 \") \" envβ:40 => Env.Approx.",
"content": "notation:40 envβ:40 \" β²β'(\" n:40 \") \" envβ:40 => Env.Approx.Indexed' n envβ envβ"
},
{
"name": "notation:40 e:40 \" β²'(\" n:40 \") \" e':40 => Expr.Approx.Index",
"content": "notation:40 e:40 \" β²'(\" n:40 \") \" e':40 => Expr.Approx.Indexed' n e e'"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Inde",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Indexed n env e v"
},
{
"name": "notation:40 v:40 \" β²α΅₯ \" v':40 => Value.Approx v v'",
"content": "notation:40 v:40 \" β²α΅₯ \" v':40 => Value.Approx v v'"
},
{
"name": "notation:40 e:40 \" β²β¨\" env:40 \", \" env':40 \"β© \" e':40 => Exp",
"content": "notation:40 e:40 \" β²β¨\" env:40 \", \" env':40 \"β© \" e':40 => Expr.Approx.Param env env' e e'"
},
{
"name": "notation:40 v:40 \" β²β \" v':40 => Object.Approx v v'",
"content": "notation:40 v:40 \" β²β \" v':40 => Object.Approx v v'"
},
{
"name": "notation:40 envβ:40 \" β²β \" envβ:40 => Env.Approx envβ envβ",
"content": "notation:40 envβ:40 \" β²β \" envβ:40 => Env.Approx envβ envβ"
},
{
"name": "notation:40 eβ:40 \" β² \" eβ:40 => Expr.Approx eβ eβ",
"content": "notation:40 eβ:40 \" β² \" eβ:40 => Expr.Approx eβ eβ"
},
{
"name": "infixl:100 \" @@ \" => Expr.app",
"content": "infixl:100 \" @@ \" => Expr.app"
}
] | [
{
"name": "List.forallβ_cons",
"module": "Batteries.Data.List.Basic"
},
{
"name": "List.forallβ_same",
"module": "Mathlib.Data.List.Forall2"
}
] | [
{
"name": "Expr.Approx.toIndexed",
"content": "lemma Expr.Approx.toIndexed {eβ eβ} : eβ β² eβ β β n, eβ β²'(n) eβ"
},
{
"name": "Value.Approx.Indexed.trans",
"content": "@[trans]\nlemma Value.Approx.Indexed.trans {n vβ vβ vβ} : vβ β²α΅₯(n) vβ β vβ β²α΅₯ vβ β vβ β²α΅₯(n) vβ"
},
{
"name": "Value.Approx.invert",
"content": "@[aesop unsafe destruct]\nlemma Value.Approx.invert {v v'} :\n v β²α΅₯ v' β\n Value.Approx.Inversion v v'"
},
{
"name": "Env.Approx.toIndexed",
"content": "lemma Env.Approx.toIndexed {envβ envβ} : envβ β²β envβ β β n, envβ β²β'(n) envβ"
},
{
"name": "Env.Approx.cons",
"content": "lemma Env.Approx.cons {envβ envβ oβ oβ} :\n oβ β²β oβ β envβ β²β envβ β (oβ :: envβ) β²β (oβ :: envβ)"
},
{
"name": "Object.Approx.toIndexed",
"content": "lemma Object.Approx.toIndexed {oβ oβ} : oβ β²β oβ β β n, oβ β²β'(n) oβ"
},
{
"name": "Eval.deterministic",
"content": "theorem Eval.deterministic {env e vβ vβ} (hβ : env β’ e β¦ vβ) (hβ : env β’ e β¦ vβ) : vβ = vβ"
},
{
"name": "Eval.toIndexed",
"content": "lemma Eval.toIndexed {env e v} (h : env β’ e β¦ v) : β n, env β’ e β¦(n) v"
},
{
"name": "Eval.Indexed.monotone",
"content": "lemma Eval.Indexed.monotone {n n' env e v} (h : env β’ e β¦(n) v) (h' : n β€ n') : env β’ e β¦(n') v"
},
{
"name": "Value.Approx.Indexed.preserved",
"content": "theorem Value.Approx.Indexed.preserved :\n β m n env env' e v,\n env β²β'(m + n) env' β\n env β’ e β¦(n) v β\n β v', env' β’ e β¦ v' β§ v β²α΅₯(m) v'"
},
{
"name": "Value.Approx.Indexed.preserved'",
"content": "lemma Value.Approx.Indexed.preserved' {k} : Preservation k"
},
{
"name": "Env.Approx.Indexed'.refl",
"content": "@[refl]\nlemma Env.Approx.Indexed'.refl {n env} : env β²β'(n) env"
},
{
"name": "Value.Approx.Indexed.refl",
"content": "@[refl]\nlemma Value.Approx.Indexed.refl {n} v : v β²α΅₯(n) v"
},
{
"name": "Object.Approx.Indexed'.refl'",
"content": "lemma Object.Approx.Indexed'.refl' {n o} (h : β v, v β²α΅₯(n) v) : o β²β'(n) o"
},
{
"name": "Env.Approx.Indexed'.refl'",
"content": "lemma Env.Approx.Indexed'.refl' {n env} (h : β v, v β²α΅₯(n) v) : env β²β'(n) env"
},
{
"name": "Value.Approx.Indexed.constr_app",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.constr_app {n ctr_name args_rev args_rev'} :\n (β k < n, args_rev β²β(k) args_rev') β\n Value.constr_app ctr_name args_rev β²α΅₯(n) Value.constr_app ctr_name args_rev'"
},
{
"name": "Value.Approx.Indexed.unit",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.unit {n} : Value.unit β²α΅₯(n) Value.unit"
},
{
"name": "Value.Approx.Indexed.const",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.const {n c} : Value.const c β²α΅₯(n) Value.const c"
},
{
"name": "Value.Approx.Indexed.closure",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.closure {n envβ bodyβ envβ bodyβ} :\n (β nβ nβ, nβ + nβ < n β\n β aβ aβ vβ,\n aβ β²α΅₯(nβ + nβ) aβ β\n aβ β· envβ β’ bodyβ β¦(nβ) vβ β\n β vβ, aβ β· envβ β’ bodyβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ) β\n Value.closure envβ bodyβ β²α΅₯(n) Value.closure envβ bodyβ"
},
{
"name": "Object.Approx.Indexed'.refl",
"content": "@[refl]\nlemma Object.Approx.Indexed'.refl {n o} : o β²β'(n) o"
},
{
"name": "Value.Approx.Indexed.preserved_step",
"content": "lemma Value.Approx.Indexed.preserved_step {k} :\n (β k' < k, Preservation k') β Preservation k"
},
{
"name": "Expr.Approx.Param.Indexed.anti_monotone",
"content": "lemma Expr.Approx.Param.Indexed.anti_monotone {n n' envβ envβ eβ eβ}\n (h : eβ β²(n)β¨envβ, envββ© eβ)\n (h' : n' β€ n)\n : eβ β²(n')β¨envβ, envββ© eβ"
},
{
"name": "Expr.Approx.Indexed'.anti_monotone",
"content": "lemma Expr.Approx.Indexed'.anti_monotone {n n' eβ eβ}\n (h : eβ β²'(n) eβ)\n (h' : n' β€ n)\n : eβ β²'(n') eβ"
},
{
"name": "Env.Approx.Indexed'.delayed",
"content": "lemma Env.Approx.Indexed'.delayed {n i : Nat} {envβ envβ env e}\n (hβ : envβ β²β'(n) envβ)\n (hβ : envβ[i]? = some (Object.delayed env e)) :\n (β env' e', e β²(n)β¨env, env'β© e' β§ envβ[i]? = some (Object.delayed env' e')) β¨\n β env', env β²β'(n) env' β§ envβ[i]? = some (Object.delayed env' e)"
},
{
"name": "Env.Approx.Indexed'.value",
"content": "lemma Env.Approx.Indexed'.value {n i : Nat} {env env' v}\n (hβ : env β²β'(n) env')\n (hβ : env[i]? = some (Object.value v)) :\n β v', env'[i]? = some (Object.value v') β§ v β²α΅₯(n) v'"
},
{
"name": "Env.Approx.Indexed'.get",
"content": "lemma Env.Approx.Indexed'.get {n i : Nat} {env env' oβ}\n (hβ : env β²β'(n) env')\n (hβ : env[i]? = some oβ) :\n β oβ, env'[i]? = some oβ β§ oβ β²β'(n) oβ"
},
{
"name": "Value.Approx.Indexed.anti_monotone",
"content": "lemma Value.Approx.Indexed.anti_monotone {n n' vβ vβ} (h : vβ β²α΅₯(n) vβ) (h' : n' β€ n) : vβ β²α΅₯(n') vβ"
},
{
"name": "Value.Approx.Indexed.Preservation.anti_monotone",
"content": "lemma Value.Approx.Indexed.Preservation.anti_monotone {k k'} (h : Value.Approx.Indexed.Preservation k) (h' : k' β€ k) : Value.Approx.Indexed.Preservation k'"
},
{
"name": "Env.Approx.Indexed'.anti_monotone",
"content": "lemma Env.Approx.Indexed'.anti_monotone {n n' envβ envβ}\n (h : envβ β²β'(n) envβ)\n (h' : n' β€ n)\n : envβ β²β'(n') envβ"
},
{
"name": "Object.Approx.Indexed'.anti_monotone",
"content": "lemma Object.Approx.Indexed'.anti_monotone {n n' oβ oβ} (h : oβ β²β'(n) oβ) (h' : n' β€ n) : oβ β²β'(n') oβ"
},
{
"name": "Env.Approx.Indexed'.cons",
"content": "lemma Env.Approx.Indexed'.cons {n oβ oβ envβ envβ}\n (hβ : oβ β²β'(n) oβ)\n (hβ : envβ β²β'(n) envβ) :\n oβ :: envβ β²β'(n) oβ :: envβ"
},
{
"name": "Env.Approx.Indexed'.concat",
"content": "lemma Env.Approx.Indexed'.concat {n envβ envβ envβ' envβ'}\n (hβ : envβ β²β'(n) envβ')\n (hβ : envβ β²β'(n) envβ') :\n envβ ++ envβ β²β'(n) envβ' ++ envβ'"
},
{
"name": "Env.Approx.Indexed'.from_value",
"content": "lemma Env.Approx.Indexed'.from_value {n lβ lβ} (h : lβ β²β(n) lβ) :\n List.map Object.value lβ β²β'(n) List.map Object.value lβ"
},
{
"name": "Value.Approx.preserved",
"content": "theorem Value.Approx.preserved :\n β env env' e v,\n env β²β env' β\n env β’ e β¦ v β\n β v', env' β’ e β¦ v' β§ v β²α΅₯ v'"
},
{
"name": "Value.Approx.constr_app",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.constr_app {ctr_name args_rev args_rev'} :\n args_rev β²β args_rev' β\n Value.constr_app ctr_name args_rev β²α΅₯ Value.constr_app ctr_name args_rev'"
},
{
"name": "Value.Approx.closure",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.closure {envβ bodyβ envβ bodyβ} :\n (β aβ aβ,\n aβ β²α΅₯ aβ β\n bodyβ β²β¨aβ β· envβ, aβ β· envββ© bodyβ) β\n Value.closure envβ bodyβ β²α΅₯ Value.closure envβ bodyβ"
},
{
"name": "Expr.Approx.Param.preserved",
"content": "lemma Expr.Approx.Param.preserved {e e' envβ envβ envβ} :\n e β²β¨envβ, envββ© e' β\n envβ β²β envβ β\n e β²β¨envβ, envββ© e'"
},
{
"name": "Expr.Approx.const",
"content": "lemma Expr.Approx.const {cβ cβ} :\n Expr.const cβ β² Expr.const cβ β\n cβ = cβ"
},
{
"name": "Expr.Approx.preservation",
"content": "lemma Expr.Approx.preservation {eβ eβ} :\n eβ β² eβ β\n β env vβ, env β’ eβ β¦ vβ β β vβ, env β’ eβ β¦ vβ β§ vβ β²α΅₯ vβ"
},
{
"name": "Expr.Approx.to_preservation",
"content": "lemma Expr.Approx.to_preservation {eβ eβ} :\n eβ β² eβ β\n β env vβ, env β’ eβ β¦ vβ β β vβ, env β’ eβ β¦ vβ β§ vβ β²α΅₯ vβ"
},
{
"name": "Expr.Approx.from_preservation",
"content": "lemma Expr.Approx.from_preservation {eβ eβ}\n (h : β env vβ, env β’ eβ β¦ vβ β β vβ, env β’ eβ β¦ vβ β§ vβ β²α΅₯ vβ)\n : eβ β² eβ"
}
] | [
{
"name": "Juvix.Core.Main.Context.Indexed.Preserved",
"content": "def Context.Indexed.Preserved (k : Nat) : Prop :=\n β n m,\n n + m < k β\n β eβ eβ,\n eβ β²'(n + m) eβ β β (C : Context) envβ envβ vβ,\n envβ β²β'(n + m) envβ β\n envβ β’ C.subst eβ β¦(n) vβ β\n β vβ, envβ β’ C.subst eβ β¦ vβ β§ vβ β²α΅₯(m) vβ"
}
] | [
{
"name": "Juvix.Core.Main.Expr.Approx.Context.Indexed.preserved_step",
"content": "lemma Expr.Approx.Context.Indexed.preserved_step (k : Nat) :\n Context.Indexed.Preserved k β Context.Indexed.Preserved (k + 1)"
},
{
"name": "Juvix.Core.Main.Expr.Approx.Context.Indexed.preserved",
"content": "lemma Expr.Approx.Context.Indexed.preserved (k : Nat) :\n Context.Indexed.Preserved k"
}
] | import Juvix.Core.Main.Semantics.Approx
import Juvix.Core.Main.Semantics.Approx.Contextual
namespace Juvix.Core.Main
def Context.Indexed.Preserved (k : Nat) : Prop :=
β n m,
n + m < k β
β eβ eβ,
eβ β²'(n + m) eβ β β (C : Context) envβ envβ vβ,
envβ β²β'(n + m) envβ β
envβ β’ C.subst eβ β¦(n) vβ β
β vβ, envβ β’ C.subst eβ β¦ vβ β§ vβ β²α΅₯(m) vβ | lemma Expr.Approx.Context.preserved (eβ eβ : Expr) :
eβ β² eβ β
β (C : Context) envβ envβ vβ,
envβ β²β envβ β envβ β’ C.subst eβ β¦ vβ β
β vβ, envβ β’ C.subst eβ β¦ vβ β§ vβ β²α΅₯ vβ := | := by
intro happrox C envβ envβ vβ henv heval
obtain β¨n, heval'β© := Eval.toIndexed heval
have happrox' : eβ β²'(n + 0) eβ := by apply Expr.Approx.toIndexed happrox
have henv' : envβ β²β'(n + 0) envβ := by apply Env.Approx.toIndexed henv
obtain β¨vβ, hevalβ, happroxββ© := Expr.Approx.Context.Indexed.preserved (n + 1) n 0 (by linarith) eβ eβ happrox' C envβ envβ vβ henv' heval'
have : β m, vβ β²α΅₯(m) vβ := by
intro m
have happrox_m : eβ β²'(n + m) eβ := by apply Expr.Approx.toIndexed happrox
have henv_m : envβ β²β'(n + m) envβ := by apply Env.Approx.toIndexed henv
obtain β¨vβ', hevalβ', happroxβ'β© := Expr.Approx.Context.Indexed.preserved (n + m + 1) n m (by linarith) eβ eβ happrox_m C envβ envβ vβ henv_m heval'
have : vβ = vβ' := Eval.deterministic hevalβ hevalβ'
rw [this]
assumption
exists vβ | 5 | 84 | false | Semantics |
252 | Juvix.Core.Main.Value.Approx.closure | @[aesop unsafe apply]
lemma Value.Approx.closure {envβ bodyβ envβ bodyβ} :
(β aβ aβ,
aβ β²α΅₯ aβ β
bodyβ β²β¨aβ β· envβ, aβ β· envββ© bodyβ) β
Value.closure envβ bodyβ β²α΅₯ Value.closure envβ bodyβ | juvix-lean | Juvix/Core/Main/Semantics/Approx.lean | [
"import Juvix.Core.Main.Semantics.Approx.Indexed",
"import Juvix.Utils"
] | [
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "List.Forallβ",
"module": "Batteries.Data.List.Basic"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "BEq",
"module": "Init.Prelude"
},
{
"name": "DecidableEq",
"module": "Init.Prelude"
},
{
"name": "Inhabited",
"module": "Init.Prelude"
},
{
"name": "Int",
"module": "Init.Data.Int.Basic"
},
{
"name": "String",
"module": "Init.Prelude"
},
{
"name": "closure",
"module": "Mathlib.Topology.Defs.Basic"
},
{
"name": "IsEmpty",
"module": "Mathlib.Logic.IsEmpty"
},
{
"name": "List.map",
"module": "Init.Prelude"
}
] | [
{
"name": "notation:40 e:40 \" β²β¨\" env:40 \", \" env':40 \"β© \" e':40 => Exp",
"content": "notation:40 e:40 \" β²β¨\" env:40 \", \" env':40 \"β© \" e':40 => Expr.Approx.Param env env' e e'"
},
{
"name": "notation:40 v:40 \" β²α΅₯ \" v':40 => Value.Approx v v'",
"content": "notation:40 v:40 \" β²α΅₯ \" v':40 => Value.Approx v v'"
},
{
"name": "notation:40 eβ:40 \" β² \" eβ:40 => Expr.Approx eβ eβ",
"content": "notation:40 eβ:40 \" β² \" eβ:40 => Expr.Approx eβ eβ"
},
{
"name": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Inde",
"content": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Indexed n v v'"
},
{
"name": "notation:40 e:40 \" β²(\" n:40 \")β¨\" env:40 \", \" env':40 \"β© \" e'",
"content": "notation:40 e:40 \" β²(\" n:40 \")β¨\" env:40 \", \" env':40 \"β© \" e':40 => Expr.Approx.Param.Indexed n env env' e e'"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β\" => Eval.Defined env e",
"content": "notation:40 env:40 \" β’ \" e:40 \" β\" => Eval.Defined env e"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Inde",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Indexed n env e v"
},
{
"name": "notation:40 argsβ:40 \" β²β \" argsβ:40 => List.Forallβ Value.A",
"content": "notation:40 argsβ:40 \" β²β \" argsβ:40 => List.Forallβ Value.Approx argsβ argsβ"
},
{
"name": "macro \"invert\" h:term : tactic => `(tactic| (cases ($h).inve",
"content": "macro \"invert\" h:term : tactic => `(tactic| (cases ($h).invert <;> try clear $h))"
},
{
"name": "notation:40 argsβ:40 \" β²β(\" n:40 \") \" argsβ:40 => List.Foral",
"content": "notation:40 argsβ:40 \" β²β(\" n:40 \") \" argsβ:40 => List.Forallβ (Value.Approx.Indexed n) argsβ argsβ\n\nsyntax \"case \" expr \" of \" cases \" end\" : expr"
},
{
"name": "notation:40 envβ:40 \" β²β'(\" n:40 \") \" envβ:40 => Env.Approx.",
"content": "notation:40 envβ:40 \" β²β'(\" n:40 \") \" envβ:40 => Env.Approx.Indexed' n envβ envβ"
},
{
"name": "notation:40 v:40 \" β²β'(\" n:40 \") \" v':40 => Object.Approx.In",
"content": "notation:40 v:40 \" β²β'(\" n:40 \") \" v':40 => Object.Approx.Indexed' n v v'"
},
{
"name": "notation:40 envβ:40 \" β²β \" envβ:40 => Env.Approx envβ envβ",
"content": "notation:40 envβ:40 \" β²β \" envβ:40 => Env.Approx envβ envβ\n\nsyntax:100 expr:100 ppSpace expr:101 : expr\n\nsyntax:50 expr:50 \" + \" expr:51 : expr\n\nsyntax:50 expr:50 \" - \" expr:50 : expr\n\nsyntax:60 expr:60 \" * \" expr:61 : expr\n\nsyntax:60 expr:60 \" / \" expr:60 : expr"
},
{
"name": "notation:40 e:40 \" β²'(\" n:40 \") \" e':40 => Expr.Approx.Index",
"content": "notation:40 e:40 \" β²'(\" n:40 \") \" e':40 => Expr.Approx.Indexed' n e e'\n\nsyntax \"let \" ident \" := \" expr \" in \" expr : expr"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(βͺ$s:ident β― $i:numβ«) => `(Expr.var $(Lean.Syntax.mkStrLit s.getId.toString) $i)\n | `(βͺ$num:numβ«) => `(Expr.const (Constant.int $num))\n | `(βͺ$s:strβ«) => `(Expr.const (Constant.string $s))\n | `(βͺΟ
β«) => `(Expr.unit)\n | `(βͺ$eβ:expr $eβ:exprβ«) => `(Expr.app βͺ$eββ« βͺ$eββ«)\n | `(βͺΞ» $s:ident $e:exprβ«) => `(Expr.lambda $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eβ«)\n | `(βͺΞ» $ss:ident* . $e:exprβ«) => mkLambdas ss e\n | `(βͺ $s:ident β«) => `(Expr.constr $(Lean.Syntax.mkStrLit s.getId.toString))\n | `(βͺ $s:ident $es:expr* β«) => mkConstrApp s es\n | `(βͺ$eβ + $eββ«) => `(Expr.binop BinaryOp.add_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ - $eββ«) => `(Expr.binop BinaryOp.sub_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ * $eββ«) => `(Expr.binop BinaryOp.mul_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ / $eββ«) => `(Expr.binop BinaryOp.div_int βͺ$eββ« βͺ$eββ«)\n | `(βͺlet $s:ident := $eβ:expr in $eβ:exprβ«) => `(Expr.save $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eββ« βͺ$eββ«)\n | `(βͺletrec $s:ident := $eβ:expr in $eβ:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.save $name (Expr.recur $name βͺ$eββ«) βͺ$eββ«)\n | `(βͺrec $s:ident $e:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.recur $name βͺ$eβ«)\n | `(βͺβ₯β«) => `(Expr.fail)\n | `(βͺcases| | $s:ident => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« Expr.fail)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« Expr.fail)\n | `(βͺcases| | _ => $e:expr β«) =>\n `(βͺ$eβ«)\n | `(βͺcase $e:expr of $cs:cases endβ«) => do\n `(Expr.save \"_case_\" βͺ$eβ« βͺcases|$csβ«)\n | `(βͺ($e)β«) => `(βͺ$eβ«)\n\n inductive Object : Type where\n | value : Value β Object\n | delayed : (env : List Object) β Expr β Object\n deriving Inhabited"
},
{
"name": "Env.Approx.Indexed'",
"content": "def Env.Approx.Indexed' (n : Nat) : (envβ envβ : Env) β Prop :=\n List.Forallβ (Object.Approx.Indexed' n)"
},
{
"name": "Object.Approx.Indexed'",
"content": "inductive Object.Approx.Indexed' (n : Nat) : Object β Object β Prop where\n | value {vβ vβ} :\n vβ β²α΅₯(n) vβ β\n Object.Approx.Indexed' n (Object.value vβ) (Object.value vβ)\n | delayed {envβ envβ eβ eβ} :\n eβ β²(n)β¨envβ, envββ© eβ β\n Object.Approx.Indexed' n (Object.delayed envβ eβ) (Object.delayed envβ eβ)\n | delayed_eq {envβ envβ e} :\n List.Forallβ (Object.Approx.Indexed' n) envβ envβ β\n Object.Approx.Indexed' n (Object.delayed envβ e) (Object.delayed envβ e)"
},
{
"name": "cons_value",
"content": "abbrev cons_value (v : Value) (env : Env) : Env := Object.value v :: env\n\n inductive Value : Type where\n | unit : Value\n | const : Constant β Value\n | constr_app : (constr : Name) β (args_rev : List Value) β Value\n | closure : (env : List Object) β (value : Expr) β Value\n deriving Inhabited"
},
{
"name": "Expr",
"content": "inductive Expr : Type where\n | var : (name : String) β (index : Nat) β Expr\n | unit : Expr\n | const : Constant β Expr\n | constr : Name β Expr\n | app : Expr β Expr β Expr\n | constr_app : Expr β Expr β Expr\n | binop : (oper : BinaryOp) β (argβ argβ : Expr) β Expr\n | lambda : (var_name : String) β (body : Expr) β Expr\n | save : (var_name : String) β (value : Expr) β (body : Expr) β Expr\n | branch : (constr : Name) β (var_names : List Name) β (body : Expr) β (next : Expr) β Expr\n | recur : (var_name : Name) β (body : Expr) β Expr\n | fail : Expr\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "BinaryOp",
"content": "inductive BinaryOp : Type where\n | add_int : BinaryOp\n | sub_int : BinaryOp\n | mul_int : BinaryOp\n | div_int : BinaryOp\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Constant",
"content": "inductive Constant : Type where\n | int : Int β Constant\n | string : String β Constant\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Name",
"content": "abbrev Name : Type := String"
},
{
"name": "Env",
"content": "abbrev Env : Type := List Object"
},
{
"name": "Value.Approx.Indexed",
"content": "def Value.Approx.Indexed (n : Nat) (vβ vβ : Value) : Prop :=\n (vβ = Value.unit β§ vβ = Value.unit) β¨\n (β c, vβ = Value.const c β§ vβ = Value.const c) β¨\n (β ctr_name args_rev args_rev',\n vβ = Value.constr_app ctr_name args_rev β§\n vβ = Value.constr_app ctr_name args_rev' β§\n (β k < n, List.Forallβ (Value.Approx.Indexed k) args_rev args_rev')) β¨\n (β envβ bodyβ envβ bodyβ,\n vβ = Value.closure envβ bodyβ β§\n vβ = Value.closure envβ bodyβ β§\n (β nβ nβ, nβ + nβ < n β\n β aβ aβ rβ,\n Value.Approx.Indexed (nβ + nβ) aβ aβ β\n aβ β· envβ β’ bodyβ β¦(nβ) rβ β\n β rβ,\n aβ β· envβ β’ bodyβ β¦ rβ β§\n Value.Approx.Indexed nβ rβ rβ))"
},
{
"name": "Value.Approx.Indexed.Inversion",
"content": "@[aesop safe cases]\ninductive Value.Approx.Indexed.Inversion (n : Nat) : Value β Value β Prop where\n | unit : Value.Approx.Indexed.Inversion n Value.unit Value.unit\n | const {c} : Value.Approx.Indexed.Inversion n (Value.const c) (Value.const c)\n | constr_app {ctr_name args_rev args_rev'} :\n (β k < n, args_rev β²β(k) args_rev') β\n Value.Approx.Indexed.Inversion n (Value.constr_app ctr_name args_rev) (Value.constr_app ctr_name args_rev')\n | closure {envβ bodyβ envβ bodyβ} :\n (β nβ nβ, nβ + nβ < n β\n β aβ aβ vβ,\n aβ β²α΅₯(nβ + nβ) aβ β\n aβ β· envβ β’ bodyβ β¦(nβ) vβ β\n β vβ, aβ β· envβ β’ bodyβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ) β\n Value.Approx.Indexed.Inversion n (Value.closure envβ bodyβ) (Value.closure envβ bodyβ)"
},
{
"name": "Value.Approx.Indexed.Preservation",
"content": "def Value.Approx.Indexed.Preservation (k : Nat) : Prop :=\n β m n env env' e v,\n m + n < k β\n env β²β'(m + n) env' β\n env β’ e β¦(n) v β\n β v', env' β’ e β¦ v' β§ v β²α΅₯(m) v'"
},
{
"name": "Expr.Approx.Param.Indexed",
"content": "def Expr.Approx.Param.Indexed (n : Nat) (envβ envβ : Env) (eβ eβ : Expr) : Prop :=\n (β nβ nβ vβ, nβ + nβ β€ n β envβ β’ eβ β¦(nβ) vβ β β vβ, envβ β’ eβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ)"
},
{
"name": "Eval.Indexed",
"content": "inductive Eval.Indexed : Nat β Env β Expr β Value β Prop where\n | var {n env name idx val} :\n env[idx]? = some (Object.value val) β\n Eval.Indexed n env (Expr.var name idx) val\n | var_rec {n env name idx env' expr val} :\n env[idx]? = some (Object.delayed env' expr) β\n Eval.Indexed n env' expr val β\n Eval.Indexed n env (Expr.var name idx) val\n | unit {n env} :\n Eval.Indexed n env Expr.unit Value.unit\n | const {n env c} :\n Eval.Indexed n env (Expr.const c) (Value.const c)\n | constr {n env name} :\n Eval.Indexed n env (Expr.constr name) (Value.constr_app name [])\n | app {n nβ nβ env env' f body arg val val'} :\n nβ + nβ + 1 β€ n β\n Eval.Indexed nβ env f (Value.closure env' body) β\n Eval.Indexed (nβ + 1) env arg val β\n Eval.Indexed nβ (val β· env') body val' β\n Eval.Indexed n env (Expr.app f arg) val'\n | constr_app {n n' env ctr ctr_name ctr_args_rev arg val} :\n n' < n β\n Eval.Indexed n env ctr (Value.constr_app ctr_name ctr_args_rev) β\n Eval.Indexed n' env arg val β\n Eval.Indexed n env (Expr.constr_app ctr arg) (Value.constr_app ctr_name (val :: ctr_args_rev))\n | binop {n env op argβ argβ valβ valβ} :\n Eval.Indexed n env argβ (Value.const (Constant.int valβ)) β\n Eval.Indexed n env argβ (Value.const (Constant.int valβ)) β\n Eval.Indexed n env (Expr.binop op argβ argβ) (Value.const (Constant.int (eval_binop_int op valβ valβ)))\n | lambda {n env name body} :\n Eval.Indexed n env (Expr.lambda name body) (Value.closure env body)\n | save {n nβ nβ env name value body val val'} :\n nβ + nβ β€ n β\n Eval.Indexed nβ env value val β\n Eval.Indexed nβ (val β· env) body val' β\n Eval.Indexed n env (Expr.save name value body) val'\n | branch_matches {n n' env name args_rev body val} :\n n' < n β\n Eval.Indexed n' (args_rev.map Object.value ++ env) body val β\n Eval.Indexed n (Value.constr_app name args_rev β· env) (Expr.branch name _ body _) val\n | branch_fails {n env name name' args_rev next val} :\n name β name' β\n Eval.Indexed n (Value.constr_app name args_rev β· env) next val β\n Eval.Indexed n (Value.constr_app name args_rev β· env) (Expr.branch name' _ _ next) val\n | recur {n n' env name body val} :\n n' < n β\n Eval.Indexed n' (Object.delayed env (Expr.recur name body) :: env) body val β\n Eval.Indexed n env (Expr.recur name body) val"
},
{
"name": "Eval",
"content": "@[aesop unsafe constructors]\ninductive Eval : Env β Expr β Value β Prop where\n | var {env name idx val} :\n env[idx]? = some (Object.value val) β\n Eval env (Expr.var name idx) val\n | var_rec {env name idx env' expr val} :\n env[idx]? = some (Object.delayed env' expr) β\n Eval env' expr val β\n Eval env (Expr.var name idx) val\n | unit {env} :\n Eval env Expr.unit Value.unit\n | const {env c} :\n Eval env (Expr.const c) (Value.const c)\n | constr {env name} :\n Eval env (Expr.constr name) (Value.constr_app name [])\n | app {env env' f body arg val val'} :\n Eval env f (Value.closure env' body) β\n Eval env arg val β\n Eval (val β· env') body val' β\n Eval env (Expr.app f arg) val'\n | constr_app {env ctr ctr_name ctr_args_rev arg val} :\n Eval env ctr (Value.constr_app ctr_name ctr_args_rev) β\n Eval env arg val β\n Eval env (Expr.constr_app ctr arg) (Value.constr_app ctr_name (val :: ctr_args_rev))\n | binop {env op argβ argβ valβ valβ} :\n Eval env argβ (Value.const (Constant.int valβ)) β\n Eval env argβ (Value.const (Constant.int valβ)) β\n Eval env (Expr.binop op argβ argβ) (Value.const (Constant.int (eval_binop_int op valβ valβ)))\n | lambda {env name body} :\n Eval env (Expr.lambda name body) (Value.closure env body)\n | save {env name value body val val'} :\n Eval env value val β\n Eval (val β· env) body val' β\n Eval env (Expr.save name value body) val'\n | branch_matches {env name args_rev body val} :\n Eval (args_rev.map Object.value ++ env) body val β\n Eval (Value.constr_app name args_rev β· env) (Expr.branch name _ body _) val\n | branch_fails {env name name' args_rev next val} :\n name β name' β\n Eval (Value.constr_app name args_rev β· env) next val β\n Eval (Value.constr_app name args_rev β· env) (Expr.branch name' _ _ next) val\n | recur {env name body val} :\n Eval (Object.delayed env (Expr.recur name body) :: env) body val β\n Eval env (Expr.recur name body) val"
},
{
"name": "Context",
"content": "inductive Context : Type where\n | hole : Context\n | app_left : Context β Expr β Context\n | app_right : Expr β Context β Context\n | constr_app_left : Context β Expr β Context\n | constr_app_right : Expr β Context β Context\n | binop_left : (oper : BinaryOp) β (argβ : Context) β (argβ : Expr) β Context\n | binop_right : (oper : BinaryOp) β (argβ : Expr) β (argβ : Context) β Context\n | lambda : (var_name : String) β (body : Context) β Context\n | save_left : (var_name : String) β (value : Context) β (body : Expr) β Context\n | save_right : (var_name : String) β (value : Expr) β (body : Context) β Context\n | branch_left : (constr : Name) β (var_names : List Name) β (body : Context) β (next : Expr) β Context\n | branch_right : (constr : Name) β (var_names : List Name) β (body : Expr) β (next : Context) β Context\n | recur : (var_name : Name) β (ctx : Context) β Context\n deriving Inhabited, BEq"
},
{
"name": "eval_binop_int",
"content": "def eval_binop_int (op : BinaryOp) (iβ iβ : Int) : Int :=\n match op with\n | BinaryOp.add_int => iβ + iβ\n | BinaryOp.sub_int => iβ - iβ\n | BinaryOp.mul_int => iβ * iβ\n | BinaryOp.div_int => iβ / iβ"
},
{
"name": "Expr.Approx.Indexed'",
"content": "def Expr.Approx.Indexed' (n : Nat) (eβ eβ : Expr) : Prop :=\n (β nβ nβ vβ, nβ + nβ β€ n β\n β envβ envβ, envβ β²β'(nβ + nβ) envβ β envβ β’ eβ β¦(nβ) vβ β β vβ, envβ β’ eβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ)"
},
{
"name": "infixr:50 \" β· \" => cons_value",
"content": "infixr:50 \" β· \" => cons_value"
},
{
"name": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Inde",
"content": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Indexed n v v'"
},
{
"name": "notation:40 e:40 \" β²(\" n:40 \")β¨\" env:40 \", \" env':40 \"β© \" e'",
"content": "notation:40 e:40 \" β²(\" n:40 \")β¨\" env:40 \", \" env':40 \"β© \" e':40 => Expr.Approx.Param.Indexed n env env' e e'"
},
{
"name": "notation:40 v:40 \" β²β'(\" n:40 \") \" v':40 => Object.Approx.In",
"content": "notation:40 v:40 \" β²β'(\" n:40 \") \" v':40 => Object.Approx.Indexed' n v v'"
},
{
"name": "notation:40 envβ:40 \" β²β'(\" n:40 \") \" envβ:40 => Env.Approx.",
"content": "notation:40 envβ:40 \" β²β'(\" n:40 \") \" envβ:40 => Env.Approx.Indexed' n envβ envβ"
},
{
"name": "notation:40 e:40 \" β²'(\" n:40 \") \" e':40 => Expr.Approx.Index",
"content": "notation:40 e:40 \" β²'(\" n:40 \") \" e':40 => Expr.Approx.Indexed' n e e'"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Inde",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Indexed n env e v"
},
{
"name": "infixl:100 \" @@ \" => Expr.app",
"content": "infixl:100 \" @@ \" => Expr.app"
}
] | [
{
"name": "IsEmpty.forall_iff",
"module": "Mathlib.Logic.IsEmpty"
},
{
"name": "implies_true",
"module": "Init.SimpLemmas"
},
{
"name": "nonpos_iff_eq_zero",
"module": "Mathlib.Algebra.Order.Monoid.Canonical.Defs"
},
{
"name": "not_lt_zero'",
"module": "Mathlib.Algebra.Order.GroupWithZero.Canonical"
}
] | [
{
"name": "Value.Approx.Indexed.invert",
"content": "@[aesop unsafe destruct]\nlemma Value.Approx.Indexed.invert {n v v'} :\n v β²α΅₯(n) v' β\n Value.Approx.Indexed.Inversion n v v'"
},
{
"name": "Value.Approx.Indexed.constr_app",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.constr_app {n ctr_name args_rev args_rev'} :\n (β k < n, args_rev β²β(k) args_rev') β\n Value.constr_app ctr_name args_rev β²α΅₯(n) Value.constr_app ctr_name args_rev'"
},
{
"name": "Value.Approx.Indexed.unit",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.unit {n} : Value.unit β²α΅₯(n) Value.unit"
},
{
"name": "Value.Approx.Indexed.const",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.const {n c} : Value.const c β²α΅₯(n) Value.const c"
},
{
"name": "Value.Approx.Indexed.closure",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.closure {n envβ bodyβ envβ bodyβ} :\n (β nβ nβ, nβ + nβ < n β\n β aβ aβ vβ,\n aβ β²α΅₯(nβ + nβ) aβ β\n aβ β· envβ β’ bodyβ β¦(nβ) vβ β\n β vβ, aβ β· envβ β’ bodyβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ) β\n Value.closure envβ bodyβ β²α΅₯(n) Value.closure envβ bodyβ"
},
{
"name": "forallβ_trans'",
"content": "theorem forallβ_trans' {Ξ±} {P Q R : Ξ± β Ξ± β Prop} {lβ lβ lβ}\n (h : β x y z, P x y β Q y z β R x z)\n (hβ : List.Forallβ P lβ lβ)\n (hβ : List.Forallβ Q lβ lβ)\n : List.Forallβ R lβ lβ"
},
{
"name": "Value.Approx.Indexed.preserved",
"content": "theorem Value.Approx.Indexed.preserved :\n β m n env env' e v,\n env β²β'(m + n) env' β\n env β’ e β¦(n) v β\n β v', env' β’ e β¦ v' β§ v β²α΅₯(m) v'"
},
{
"name": "Value.Approx.Indexed.preserved'",
"content": "lemma Value.Approx.Indexed.preserved' {k} : Preservation k"
},
{
"name": "Env.Approx.Indexed'.refl",
"content": "@[refl]\nlemma Env.Approx.Indexed'.refl {n env} : env β²β'(n) env"
},
{
"name": "Value.Approx.Indexed.refl",
"content": "@[refl]\nlemma Value.Approx.Indexed.refl {n} v : v β²α΅₯(n) v"
},
{
"name": "Object.Approx.Indexed'.refl'",
"content": "lemma Object.Approx.Indexed'.refl' {n o} (h : β v, v β²α΅₯(n) v) : o β²β'(n) o"
},
{
"name": "Env.Approx.Indexed'.refl'",
"content": "lemma Env.Approx.Indexed'.refl' {n env} (h : β v, v β²α΅₯(n) v) : env β²β'(n) env"
},
{
"name": "Object.Approx.Indexed'.refl",
"content": "@[refl]\nlemma Object.Approx.Indexed'.refl {n o} : o β²β'(n) o"
},
{
"name": "Value.Approx.Indexed.preserved_step",
"content": "lemma Value.Approx.Indexed.preserved_step {k} :\n (β k' < k, Preservation k') β Preservation k"
},
{
"name": "Expr.Approx.Param.Indexed.anti_monotone",
"content": "lemma Expr.Approx.Param.Indexed.anti_monotone {n n' envβ envβ eβ eβ}\n (h : eβ β²(n)β¨envβ, envββ© eβ)\n (h' : n' β€ n)\n : eβ β²(n')β¨envβ, envββ© eβ"
},
{
"name": "Expr.Approx.Indexed'.anti_monotone",
"content": "lemma Expr.Approx.Indexed'.anti_monotone {n n' eβ eβ}\n (h : eβ β²'(n) eβ)\n (h' : n' β€ n)\n : eβ β²'(n') eβ"
},
{
"name": "Env.Approx.Indexed'.delayed",
"content": "lemma Env.Approx.Indexed'.delayed {n i : Nat} {envβ envβ env e}\n (hβ : envβ β²β'(n) envβ)\n (hβ : envβ[i]? = some (Object.delayed env e)) :\n (β env' e', e β²(n)β¨env, env'β© e' β§ envβ[i]? = some (Object.delayed env' e')) β¨\n β env', env β²β'(n) env' β§ envβ[i]? = some (Object.delayed env' e)"
},
{
"name": "Env.Approx.Indexed'.value",
"content": "lemma Env.Approx.Indexed'.value {n i : Nat} {env env' v}\n (hβ : env β²β'(n) env')\n (hβ : env[i]? = some (Object.value v)) :\n β v', env'[i]? = some (Object.value v') β§ v β²α΅₯(n) v'"
},
{
"name": "Env.Approx.Indexed'.get",
"content": "lemma Env.Approx.Indexed'.get {n i : Nat} {env env' oβ}\n (hβ : env β²β'(n) env')\n (hβ : env[i]? = some oβ) :\n β oβ, env'[i]? = some oβ β§ oβ β²β'(n) oβ"
},
{
"name": "Value.Approx.Indexed.anti_monotone",
"content": "lemma Value.Approx.Indexed.anti_monotone {n n' vβ vβ} (h : vβ β²α΅₯(n) vβ) (h' : n' β€ n) : vβ β²α΅₯(n') vβ"
},
{
"name": "Value.Approx.Indexed.Preservation.anti_monotone",
"content": "lemma Value.Approx.Indexed.Preservation.anti_monotone {k k'} (h : Value.Approx.Indexed.Preservation k) (h' : k' β€ k) : Value.Approx.Indexed.Preservation k'"
},
{
"name": "Env.Approx.Indexed'.anti_monotone",
"content": "lemma Env.Approx.Indexed'.anti_monotone {n n' envβ envβ}\n (h : envβ β²β'(n) envβ)\n (h' : n' β€ n)\n : envβ β²β'(n') envβ"
},
{
"name": "Object.Approx.Indexed'.anti_monotone",
"content": "lemma Object.Approx.Indexed'.anti_monotone {n n' oβ oβ} (h : oβ β²β'(n) oβ) (h' : n' β€ n) : oβ β²β'(n') oβ"
},
{
"name": "Env.Approx.Indexed'.cons",
"content": "lemma Env.Approx.Indexed'.cons {n oβ oβ envβ envβ}\n (hβ : oβ β²β'(n) oβ)\n (hβ : envβ β²β'(n) envβ) :\n oβ :: envβ β²β'(n) oβ :: envβ"
},
{
"name": "Env.Approx.Indexed'.concat",
"content": "lemma Env.Approx.Indexed'.concat {n envβ envβ envβ' envβ'}\n (hβ : envβ β²β'(n) envβ')\n (hβ : envβ β²β'(n) envβ') :\n envβ ++ envβ β²β'(n) envβ' ++ envβ'"
},
{
"name": "Env.Approx.Indexed'.from_value",
"content": "lemma Env.Approx.Indexed'.from_value {n lβ lβ} (h : lβ β²β(n) lβ) :\n List.map Object.value lβ β²β'(n) List.map Object.value lβ"
}
] | [
{
"name": "Juvix.Core.Main.Value.Approx",
"content": "def Value.Approx (v v' : Value) : Prop :=\n β n, v β²α΅₯(n) v'"
},
{
"name": "Juvix.Core.Main.Expr.Approx.Param",
"content": "def Expr.Approx.Param (envβ envβ : Env) (eβ eβ : Expr) : Prop :=\n (β vβ, envβ β’ eβ β¦ vβ β β vβ, envβ β’ eβ β¦ vβ β§ vβ β²α΅₯ vβ)"
},
{
"name": "Juvix.Core.Main.Object.Approx",
"content": "inductive Object.Approx : Object β Object β Prop where\n | value {vβ vβ} : vβ β²α΅₯ vβ β Object.Approx (Object.value vβ) (Object.value vβ)\n | delayed {envβ envβ eβ eβ} :\n eβ β²β¨envβ, envββ© eβ β\n Object.Approx (Object.delayed envβ eβ) (Object.delayed envβ eβ)"
},
{
"name": "Juvix.Core.Main.Env.Approx",
"content": "def Env.Approx : (envβ envβ : Env) β Prop :=\n List.Forallβ Object.Approx"
},
{
"name": "Juvix.Core.Main.Expr.Approx",
"content": "def Expr.Approx (eβ eβ : Expr) : Prop :=\n β envβ envβ, envβ β²β envβ β eβ β²β¨envβ, envββ© eβ"
},
{
"name": "Juvix.Core.Main.Value.Approx.Inversion",
"content": "@[aesop safe cases]\ninductive Value.Approx.Inversion : Value -> Value -> Prop where\n | unit : Value.Approx.Inversion Value.unit Value.unit\n | const {c} : Value.Approx.Inversion (Value.const c) (Value.const c)\n | constr_app {ctr_name args_rev args_rev'} :\n args_rev β²β args_rev' β\n Value.Approx.Inversion (Value.constr_app ctr_name args_rev) (Value.constr_app ctr_name args_rev')\n | closure {envβ bodyβ envβ bodyβ} :\n (β aβ aβ, aβ β²α΅₯ aβ β bodyβ β²β¨aβ β· envβ, aβ β· envββ© bodyβ) β\n Value.Approx.Inversion (Value.closure envβ bodyβ) (Value.closure envβ bodyβ)"
}
] | [
{
"name": "Juvix.Core.Main.Value.Approx.invert",
"content": "@[aesop unsafe destruct]\nlemma Value.Approx.invert {v v'} :\n v β²α΅₯ v' β\n Value.Approx.Inversion v v'"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.trans",
"content": "@[trans]\nlemma Value.Approx.Indexed.trans {n vβ vβ vβ} : vβ β²α΅₯(n) vβ β vβ β²α΅₯ vβ β vβ β²α΅₯(n) vβ"
}
] | import Juvix.Core.Main.Semantics.Approx.Indexed
namespace Juvix.Core.Main
def Value.Approx (v v' : Value) : Prop :=
β n, v β²α΅₯(n) v'
notation:40 v:40 " β²α΅₯ " v':40 => Value.Approx v v'
notation:40 argsβ:40 " β²β " argsβ:40 => List.Forallβ Value.Approx argsβ argsβ
def Expr.Approx.Param (envβ envβ : Env) (eβ eβ : Expr) : Prop :=
(β vβ, envβ β’ eβ β¦ vβ β β vβ, envβ β’ eβ β¦ vβ β§ vβ β²α΅₯ vβ)
notation:40 e:40 " β²β¨" env:40 ", " env':40 "β© " e':40 => Expr.Approx.Param env env' e e'
inductive Object.Approx : Object β Object β Prop where
| value {vβ vβ} : vβ β²α΅₯ vβ β Object.Approx (Object.value vβ) (Object.value vβ)
| delayed {envβ envβ eβ eβ} :
eβ β²β¨envβ, envββ© eβ β
Object.Approx (Object.delayed envβ eβ) (Object.delayed envβ eβ)
def Env.Approx : (envβ envβ : Env) β Prop :=
List.Forallβ Object.Approx
notation:40 v:40 " β²β " v':40 => Object.Approx v v'
notation:40 envβ:40 " β²β " envβ:40 => Env.Approx envβ envβ
def Expr.Approx (eβ eβ : Expr) : Prop :=
β envβ envβ, envβ β²β envβ β eβ β²β¨envβ, envββ© eβ
notation:40 eβ:40 " β² " eβ:40 => Expr.Approx eβ eβ
@[aesop safe cases]
inductive Value.Approx.Inversion : Value -> Value -> Prop where
| unit : Value.Approx.Inversion Value.unit Value.unit
| const {c} : Value.Approx.Inversion (Value.const c) (Value.const c)
| constr_app {ctr_name args_rev args_rev'} :
args_rev β²β args_rev' β
Value.Approx.Inversion (Value.constr_app ctr_name args_rev) (Value.constr_app ctr_name args_rev')
| closure {envβ bodyβ envβ bodyβ} :
(β aβ aβ, aβ β²α΅₯ aβ β bodyβ β²β¨aβ β· envβ, aβ β· envββ© bodyβ) β
Value.Approx.Inversion (Value.closure envβ bodyβ) (Value.closure envβ bodyβ) | @[aesop unsafe apply]
lemma Value.Approx.closure {envβ bodyβ envβ bodyβ} :
(β aβ aβ,
aβ β²α΅₯ aβ β
bodyβ β²β¨aβ β· envβ, aβ β· envββ© bodyβ) β
Value.closure envβ bodyβ β²α΅₯ Value.closure envβ bodyβ := | := by
intro h n
apply Value.Approx.Indexed.closure
intro nβ nβ hn aβ aβ vβ happrox heval
have hβ : β vβ', aβ β· envβ β’ bodyβ β¦ vβ' β§ vβ β²α΅₯(nβ) vβ' := by
apply Indexed.preserved nβ nβ (aβ β· envβ) (aβ β· envβ) bodyβ vβ
Β· simp [Env.Approx.Indexed']
constructor
Β· constructor
have : nβ + nβ = nβ + nβ := by linarith
rw [this]
exact happrox
Β· intros
rfl
Β· assumption
obtain β¨vβ', heval', happrox'β© := hβ
obtain β¨vβ, hevalβ, happroxββ© := h aβ aβ (by rfl) vβ' heval'
exists vβ
constructor
Β· assumption
Β· apply Value.Approx.Indexed.trans <;> assumption | 4 | 68 | false | Semantics |
253 | Juvix.Core.Main.Object.Approx.Indexed'.anti_monotone | lemma Object.Approx.Indexed'.anti_monotone {n n' oβ oβ} (h : oβ β²β'(n) oβ) (h' : n' β€ n) : oβ β²β'(n') oβ :=
match h with
| @Object.Approx.Indexed'.value n vβ vβ happrox => by
apply Object.Approx.Indexed'.value
Β· apply Value.Approx.Indexed.anti_monotone
Β· assumption
Β· assumption
| @Object.Approx.Indexed'.delayed n envβ envβ eβ eβ happrox => by
apply Object.Approx.Indexed'.delayed
apply Expr.Approx.Param.Indexed.anti_monotone
Β· assumption
Β· assumption
| @Object.Approx.Indexed'.delayed_eq n envβ envβ e happrox =>
Object.Approx.Indexed'.delayed_eq (Env.Approx.Indexed'.anti_monotone happrox h') | juvix-lean | Juvix/Core/Main/Semantics/Approx/Indexed.lean | [
"import Juvix.Utils",
"import Juvix.Core.Main.Semantics.Eval.Indexed",
"import Mathlib.Tactic.Linarith",
"import Mathlib.Data.List.Forall2",
"import Juvix.Core.Main.Semantics.Eval",
"import Aesop"
] | [
{
"name": "BEq",
"module": "Init.Prelude"
},
{
"name": "DecidableEq",
"module": "Init.Prelude"
},
{
"name": "Inhabited",
"module": "Init.Prelude"
},
{
"name": "Int",
"module": "Init.Data.Int.Basic"
},
{
"name": "String",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "closure",
"module": "Mathlib.Topology.Defs.Basic"
},
{
"name": "List.Forallβ",
"module": "Batteries.Data.List.Basic"
},
{
"name": "Prod",
"module": "Init.Prelude"
},
{
"name": "reduceCtorEq",
"module": "Lean.Meta.Tactic.Simp.BuiltinSimprocs.Core"
},
{
"name": "List.Forallβ.cons",
"module": "Batteries.Data.List.Basic"
},
{
"name": "List.Forallβ.nil",
"module": "Batteries.Data.List.Basic"
}
] | [
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β\" => Eval.Defined env e",
"content": "notation:40 env:40 \" β’ \" e:40 \" β\" => Eval.Defined env e"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Inde",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Indexed n env e v"
},
{
"name": "notation:40 e:40 \" β²(\" n:40 \")β¨\" env:40 \", \" env':40 \"β© \" e'",
"content": "notation:40 e:40 \" β²(\" n:40 \")β¨\" env:40 \", \" env':40 \"β© \" e':40 => Expr.Approx.Param.Indexed n env env' e e'"
},
{
"name": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Inde",
"content": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Indexed n v v'"
},
{
"name": "notation:40 argsβ:40 \" β²β(\" n:40 \") \" argsβ:40 => List.Foral",
"content": "notation:40 argsβ:40 \" β²β(\" n:40 \") \" argsβ:40 => List.Forallβ (Value.Approx.Indexed n) argsβ argsβ"
},
{
"name": "macro \"invert\" h:term : tactic => `(tactic| (cases ($h).inve",
"content": "macro \"invert\" h:term : tactic => `(tactic| (cases ($h).invert <;> try clear $h))\n\nsyntax \"case \" expr \" of \" cases \" end\" : expr"
},
{
"name": "notation:40 v:40 \" β²β'(\" n:40 \") \" v':40 => Object.Approx.In",
"content": "notation:40 v:40 \" β²β'(\" n:40 \") \" v':40 => Object.Approx.Indexed' n v v'"
},
{
"name": "notation:40 envβ:40 \" β²β'(\" n:40 \") \" envβ:40 => Env.Approx.",
"content": "notation:40 envβ:40 \" β²β'(\" n:40 \") \" envβ:40 => Env.Approx.Indexed' n envβ envβ"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(βͺ$s:ident β― $i:numβ«) => `(Expr.var $(Lean.Syntax.mkStrLit s.getId.toString) $i)\n | `(βͺ$num:numβ«) => `(Expr.const (Constant.int $num))\n | `(βͺ$s:strβ«) => `(Expr.const (Constant.string $s))\n | `(βͺΟ
β«) => `(Expr.unit)\n | `(βͺ$eβ:expr $eβ:exprβ«) => `(Expr.app βͺ$eββ« βͺ$eββ«)\n | `(βͺΞ» $s:ident $e:exprβ«) => `(Expr.lambda $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eβ«)\n | `(βͺΞ» $ss:ident* . $e:exprβ«) => mkLambdas ss e\n | `(βͺ $s:ident β«) => `(Expr.constr $(Lean.Syntax.mkStrLit s.getId.toString))\n | `(βͺ $s:ident $es:expr* β«) => mkConstrApp s es\n | `(βͺ$eβ + $eββ«) => `(Expr.binop BinaryOp.add_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ - $eββ«) => `(Expr.binop BinaryOp.sub_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ * $eββ«) => `(Expr.binop BinaryOp.mul_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ / $eββ«) => `(Expr.binop BinaryOp.div_int βͺ$eββ« βͺ$eββ«)\n | `(βͺlet $s:ident := $eβ:expr in $eβ:exprβ«) => `(Expr.save $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eββ« βͺ$eββ«)\n | `(βͺletrec $s:ident := $eβ:expr in $eβ:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.save $name (Expr.recur $name βͺ$eββ«) βͺ$eββ«)\n | `(βͺrec $s:ident $e:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.recur $name βͺ$eβ«)\n | `(βͺβ₯β«) => `(Expr.fail)\n | `(βͺcases| | $s:ident => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« Expr.fail)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« Expr.fail)\n | `(βͺcases| | _ => $e:expr β«) =>\n `(βͺ$eβ«)\n | `(βͺcase $e:expr of $cs:cases endβ«) => do\n `(Expr.save \"_case_\" βͺ$eβ« βͺcases|$csβ«)\n | `(βͺ($e)β«) => `(βͺ$eβ«)\n\n inductive Value : Type where\n | unit : Value\n | const : Constant β Value\n | constr_app : (constr : Name) β (args_rev : List Value) β Value\n | closure : (env : List Object) β (value : Expr) β Value\n deriving Inhabited"
},
{
"name": "cons_value",
"content": "abbrev cons_value (v : Value) (env : Env) : Env := Object.value v :: env\n\n inductive Object : Type where\n | value : Value β Object\n | delayed : (env : List Object) β Expr β Object\n deriving Inhabited"
},
{
"name": "Expr",
"content": "inductive Expr : Type where\n | var : (name : String) β (index : Nat) β Expr\n | unit : Expr\n | const : Constant β Expr\n | constr : Name β Expr\n | app : Expr β Expr β Expr\n | constr_app : Expr β Expr β Expr\n | binop : (oper : BinaryOp) β (argβ argβ : Expr) β Expr\n | lambda : (var_name : String) β (body : Expr) β Expr\n | save : (var_name : String) β (value : Expr) β (body : Expr) β Expr\n | branch : (constr : Name) β (var_names : List Name) β (body : Expr) β (next : Expr) β Expr\n | recur : (var_name : Name) β (body : Expr) β Expr\n | fail : Expr\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "BinaryOp",
"content": "inductive BinaryOp : Type where\n | add_int : BinaryOp\n | sub_int : BinaryOp\n | mul_int : BinaryOp\n | div_int : BinaryOp\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Constant",
"content": "inductive Constant : Type where\n | int : Int β Constant\n | string : String β Constant\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Name",
"content": "abbrev Name : Type := String"
},
{
"name": "Env",
"content": "abbrev Env : Type := List Object"
},
{
"name": "Value.Approx",
"content": "def Value.Approx (v v' : Value) : Prop :=\n β n, v β²α΅₯(n) v'"
},
{
"name": "Object.Approx",
"content": "inductive Object.Approx : Object β Object β Prop where\n | value {vβ vβ} : vβ β²α΅₯ vβ β Object.Approx (Object.value vβ) (Object.value vβ)\n | delayed {envβ envβ eβ eβ} :\n eβ β²β¨envβ, envββ© eβ β\n Object.Approx (Object.delayed envβ eβ) (Object.delayed envβ eβ)"
},
{
"name": "Env.Approx",
"content": "def Env.Approx : (envβ envβ : Env) β Prop :=\n List.Forallβ Object.Approx"
},
{
"name": "Expr.Approx",
"content": "def Expr.Approx (eβ eβ : Expr) : Prop :=\n β envβ envβ, envβ β²β envβ β eβ β²β¨envβ, envββ© eβ"
},
{
"name": "Expr.Approx.Param",
"content": "def Expr.Approx.Param (envβ envβ : Env) (eβ eβ : Expr) : Prop :=\n (β vβ, envβ β’ eβ β¦ vβ β β vβ, envβ β’ eβ β¦ vβ β§ vβ β²α΅₯ vβ)"
},
{
"name": "infixr:50 \" β· \" => cons_value",
"content": "infixr:50 \" β· \" => cons_value"
},
{
"name": "notation:40 v:40 \" β²α΅₯ \" v':40 => Value.Approx v v'",
"content": "notation:40 v:40 \" β²α΅₯ \" v':40 => Value.Approx v v'"
},
{
"name": "notation:40 e:40 \" β²β¨\" env:40 \", \" env':40 \"β© \" e':40 => Exp",
"content": "notation:40 e:40 \" β²β¨\" env:40 \", \" env':40 \"β© \" e':40 => Expr.Approx.Param env env' e e'"
},
{
"name": "notation:40 v:40 \" β²β \" v':40 => Object.Approx v v'",
"content": "notation:40 v:40 \" β²β \" v':40 => Object.Approx v v'"
},
{
"name": "notation:40 envβ:40 \" β²β \" envβ:40 => Env.Approx envβ envβ",
"content": "notation:40 envβ:40 \" β²β \" envβ:40 => Env.Approx envβ envβ"
},
{
"name": "notation:40 eβ:40 \" β² \" eβ:40 => Expr.Approx eβ eβ",
"content": "notation:40 eβ:40 \" β² \" eβ:40 => Expr.Approx eβ eβ"
},
{
"name": "infixl:100 \" @@ \" => Expr.app",
"content": "infixl:100 \" @@ \" => Expr.app"
}
] | [
{
"name": "and_self",
"module": "Init.SimpLemmas"
},
{
"name": "exists_and_left",
"module": "Init.PropLemmas"
},
{
"name": "exists_const",
"module": "Init.PropLemmas"
},
{
"name": "exists_eq_left'",
"module": "Init.PropLemmas"
},
{
"name": "false_and",
"module": "Init.SimpLemmas"
},
{
"name": "false_or",
"module": "Init.SimpLemmas"
},
{
"name": "implies_true",
"module": "Init.SimpLemmas"
},
{
"name": "or_false",
"module": "Init.SimpLemmas"
},
{
"name": "true_and",
"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": "Juvix.Core.Main.Value.Approx.Indexed",
"content": "def Value.Approx.Indexed (n : Nat) (vβ vβ : Value) : Prop :=\n (vβ = Value.unit β§ vβ = Value.unit) β¨\n (β c, vβ = Value.const c β§ vβ = Value.const c) β¨\n (β ctr_name args_rev args_rev',\n vβ = Value.constr_app ctr_name args_rev β§\n vβ = Value.constr_app ctr_name args_rev' β§\n (β k < n, List.Forallβ (Value.Approx.Indexed k) args_rev args_rev')) β¨\n (β envβ bodyβ envβ bodyβ,\n vβ = Value.closure envβ bodyβ β§\n vβ = Value.closure envβ bodyβ β§\n (β nβ nβ, nβ + nβ < n β\n β aβ aβ rβ,\n Value.Approx.Indexed (nβ + nβ) aβ aβ β\n aβ β· envβ β’ bodyβ β¦(nβ) rβ β\n β rβ,\n aβ β· envβ β’ bodyβ β¦ rβ β§\n Value.Approx.Indexed nβ rβ rβ))"
},
{
"name": "Juvix.Core.Main.Expr.Approx.Param.Indexed",
"content": "def Expr.Approx.Param.Indexed (n : Nat) (envβ envβ : Env) (eβ eβ : Expr) : Prop :=\n (β nβ nβ vβ, nβ + nβ β€ n β envβ β’ eβ β¦(nβ) vβ β β vβ, envβ β’ eβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ)"
},
{
"name": "Juvix.Core.Main.Object.Approx.Indexed'",
"content": "inductive Object.Approx.Indexed' (n : Nat) : Object β Object β Prop where\n | value {vβ vβ} :\n vβ β²α΅₯(n) vβ β\n Object.Approx.Indexed' n (Object.value vβ) (Object.value vβ)\n | delayed {envβ envβ eβ eβ} :\n eβ β²(n)β¨envβ, envββ© eβ β\n Object.Approx.Indexed' n (Object.delayed envβ eβ) (Object.delayed envβ eβ)\n | delayed_eq {envβ envβ e} :\n List.Forallβ (Object.Approx.Indexed' n) envβ envβ β\n Object.Approx.Indexed' n (Object.delayed envβ e) (Object.delayed envβ e)"
},
{
"name": "Juvix.Core.Main.Env.Approx.Indexed'",
"content": "def Env.Approx.Indexed' (n : Nat) : (envβ envβ : Env) β Prop :=\n List.Forallβ (Object.Approx.Indexed' n)"
}
] | [
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.unit",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.unit {n} : Value.unit β²α΅₯(n) Value.unit"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.const",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.const {n c} : Value.const c β²α΅₯(n) Value.const c"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.constr_app",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.constr_app {n ctr_name args_rev args_rev'} :\n (β k < n, args_rev β²β(k) args_rev') β\n Value.constr_app ctr_name args_rev β²α΅₯(n) Value.constr_app ctr_name args_rev'"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.closure",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.closure {n envβ bodyβ envβ bodyβ} :\n (β nβ nβ, nβ + nβ < n β\n β aβ aβ vβ,\n aβ β²α΅₯(nβ + nβ) aβ β\n aβ β· envβ β’ bodyβ β¦(nβ) vβ β\n β vβ, aβ β· envβ β’ bodyβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ) β\n Value.closure envβ bodyβ β²α΅₯(n) Value.closure envβ bodyβ"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.anti_monotone",
"content": "lemma Value.Approx.Indexed.anti_monotone {n n' vβ vβ} (h : vβ β²α΅₯(n) vβ) (h' : n' β€ n) : vβ β²α΅₯(n') vβ"
},
{
"name": "Juvix.Core.Main.Expr.Approx.Param.Indexed.anti_monotone",
"content": "lemma Expr.Approx.Param.Indexed.anti_monotone {n n' envβ envβ eβ eβ}\n (h : eβ β²(n)β¨envβ, envββ© eβ)\n (h' : n' β€ n)\n : eβ β²(n')β¨envβ, envββ© eβ"
},
{
"name": "Juvix.Core.Main.Env.Approx.Indexed'.anti_monotone",
"content": " lemma Env.Approx.Indexed'.anti_monotone {n n' envβ envβ}\n (h : envβ β²β'(n) envβ)\n (h' : n' β€ n)\n : envβ β²β'(n') envβ"
}
] | import Juvix.Core.Main.Semantics.Eval
import Juvix.Core.Main.Semantics.Eval.Indexed
import Juvix.Utils
import Mathlib.Tactic.Linarith
import Mathlib.Data.List.Forall2
import Aesop
namespace Juvix.Core.Main
def Value.Approx.Indexed (n : Nat) (vβ vβ : Value) : Prop :=
(vβ = Value.unit β§ vβ = Value.unit) β¨
(β c, vβ = Value.const c β§ vβ = Value.const c) β¨
(β ctr_name args_rev args_rev',
vβ = Value.constr_app ctr_name args_rev β§
vβ = Value.constr_app ctr_name args_rev' β§
(β k < n, List.Forallβ (Value.Approx.Indexed k) args_rev args_rev')) β¨
(β envβ bodyβ envβ bodyβ,
vβ = Value.closure envβ bodyβ β§
vβ = Value.closure envβ bodyβ β§
(β nβ nβ, nβ + nβ < n β
β aβ aβ rβ,
Value.Approx.Indexed (nβ + nβ) aβ aβ β
aβ β· envβ β’ bodyβ β¦(nβ) rβ β
β rβ,
aβ β· envβ β’ bodyβ β¦ rβ β§
Value.Approx.Indexed nβ rβ rβ))
notation:40 v:40 " β²α΅₯(" n:40 ") " v':40 => Value.Approx.Indexed n v v'
notation:40 argsβ:40 " β²β(" n:40 ") " argsβ:40 => List.Forallβ (Value.Approx.Indexed n) argsβ argsβ
def Expr.Approx.Param.Indexed (n : Nat) (envβ envβ : Env) (eβ eβ : Expr) : Prop :=
(β nβ nβ vβ, nβ + nβ β€ n β envβ β’ eβ β¦(nβ) vβ β β vβ, envβ β’ eβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ)
notation:40 e:40 " β²(" n:40 ")β¨" env:40 ", " env':40 "β© " e':40 => Expr.Approx.Param.Indexed n env env' e e'
inductive Object.Approx.Indexed' (n : Nat) : Object β Object β Prop where
| value {vβ vβ} :
vβ β²α΅₯(n) vβ β
Object.Approx.Indexed' n (Object.value vβ) (Object.value vβ)
| delayed {envβ envβ eβ eβ} :
eβ β²(n)β¨envβ, envββ© eβ β
Object.Approx.Indexed' n (Object.delayed envβ eβ) (Object.delayed envβ eβ)
| delayed_eq {envβ envβ e} :
List.Forallβ (Object.Approx.Indexed' n) envβ envβ β
Object.Approx.Indexed' n (Object.delayed envβ e) (Object.delayed envβ e)
def Env.Approx.Indexed' (n : Nat) : (envβ envβ : Env) β Prop :=
List.Forallβ (Object.Approx.Indexed' n)
notation:40 v:40 " β²β'(" n:40 ") " v':40 => Object.Approx.Indexed' n v v'
notation:40 envβ:40 " β²β'(" n:40 ") " envβ:40 => Env.Approx.Indexed' n envβ envβ
notation:40 e:40 " β²'(" n:40 ") " e':40 => Expr.Approx.Indexed' n e e' | lemma Object.Approx.Indexed'.anti_monotone {n n' oβ oβ} (h : oβ β²β'(n) oβ) (h' : n' β€ n) : oβ β²β'(n') oβ := | :=
match h with
| @Object.Approx.Indexed'.value n vβ vβ happrox => by
apply Object.Approx.Indexed'.value
Β· apply Value.Approx.Indexed.anti_monotone
Β· assumption
Β· assumption
| @Object.Approx.Indexed'.delayed n envβ envβ eβ eβ happrox => by
apply Object.Approx.Indexed'.delayed
apply Expr.Approx.Param.Indexed.anti_monotone
Β· assumption
Β· assumption
| @Object.Approx.Indexed'.delayed_eq n envβ envβ e happrox =>
Object.Approx.Indexed'.delayed_eq (Env.Approx.Indexed'.anti_monotone happrox h') | 3 | 47 | false | Semantics |
254 | Juvix.Core.Main.Value.Approx.closure_inv | lemma Value.Approx.closure_inv {envβ bodyβ envβ bodyβ}
(h : Value.closure envβ bodyβ β²α΅₯ Value.closure envβ bodyβ) :
β aβ aβ, aβ β²α΅₯ aβ β bodyβ β²β¨aβ β· envβ, aβ β· envββ© bodyβ | juvix-lean | Juvix/Core/Main/Semantics/Approx.lean | [
"import Juvix.Core.Main.Semantics.Approx.Indexed",
"import Juvix.Core.Main.Semantics.Eval.Indexed",
"import Juvix.Utils",
"import Juvix.Core.Main.Semantics.Eval"
] | [
{
"name": "BEq",
"module": "Init.Prelude"
},
{
"name": "DecidableEq",
"module": "Init.Prelude"
},
{
"name": "Inhabited",
"module": "Init.Prelude"
},
{
"name": "Int",
"module": "Init.Data.Int.Basic"
},
{
"name": "String",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "closure",
"module": "Mathlib.Topology.Defs.Basic"
},
{
"name": "List.Forallβ",
"module": "Batteries.Data.List.Basic"
},
{
"name": "IsEmpty",
"module": "Mathlib.Logic.IsEmpty"
},
{
"name": "List.map",
"module": "Init.Prelude"
}
] | [
{
"name": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Inde",
"content": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Indexed n v v'"
},
{
"name": "notation:40 v:40 \" β²α΅₯ \" v':40 => Value.Approx v v'",
"content": "notation:40 v:40 \" β²α΅₯ \" v':40 => Value.Approx v v'"
},
{
"name": "notation:40 eβ:40 \" β² \" eβ:40 => Expr.Approx eβ eβ",
"content": "notation:40 eβ:40 \" β² \" eβ:40 => Expr.Approx eβ eβ"
},
{
"name": "notation:40 e:40 \" β²β¨\" env:40 \", \" env':40 \"β© \" e':40 => Exp",
"content": "notation:40 e:40 \" β²β¨\" env:40 \", \" env':40 \"β© \" e':40 => Expr.Approx.Param env env' e e'"
},
{
"name": "notation:40 e:40 \" β²(\" n:40 \")β¨\" env:40 \", \" env':40 \"β© \" e'",
"content": "notation:40 e:40 \" β²(\" n:40 \")β¨\" env:40 \", \" env':40 \"β© \" e':40 => Expr.Approx.Param.Indexed n env env' e e'"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β\" => Eval.Defined env e",
"content": "notation:40 env:40 \" β’ \" e:40 \" β\" => Eval.Defined env e"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Inde",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Indexed n env e v"
},
{
"name": "notation:40 argsβ:40 \" β²β \" argsβ:40 => List.Forallβ Value.A",
"content": "notation:40 argsβ:40 \" β²β \" argsβ:40 => List.Forallβ Value.Approx argsβ argsβ"
},
{
"name": "macro \"invert\" h:term : tactic => `(tactic| (cases ($h).inve",
"content": "macro \"invert\" h:term : tactic => `(tactic| (cases ($h).invert <;> try clear $h))"
},
{
"name": "notation:40 argsβ:40 \" β²β(\" n:40 \") \" argsβ:40 => List.Foral",
"content": "notation:40 argsβ:40 \" β²β(\" n:40 \") \" argsβ:40 => List.Forallβ (Value.Approx.Indexed n) argsβ argsβ\n\nsyntax \"case \" expr \" of \" cases \" end\" : expr"
},
{
"name": "notation:40 envβ:40 \" β²β'(\" n:40 \") \" envβ:40 => Env.Approx.",
"content": "notation:40 envβ:40 \" β²β'(\" n:40 \") \" envβ:40 => Env.Approx.Indexed' n envβ envβ"
},
{
"name": "notation:40 v:40 \" β²β'(\" n:40 \") \" v':40 => Object.Approx.In",
"content": "notation:40 v:40 \" β²β'(\" n:40 \") \" v':40 => Object.Approx.Indexed' n v v'"
},
{
"name": "notation:40 envβ:40 \" β²β \" envβ:40 => Env.Approx envβ envβ",
"content": "notation:40 envβ:40 \" β²β \" envβ:40 => Env.Approx envβ envβ\n\nsyntax:100 expr:100 ppSpace expr:101 : expr\n\nsyntax:50 expr:50 \" + \" expr:51 : expr\n\nsyntax:50 expr:50 \" - \" expr:50 : expr\n\nsyntax:60 expr:60 \" * \" expr:61 : expr\n\nsyntax:60 expr:60 \" / \" expr:60 : expr"
},
{
"name": "notation:40 e:40 \" β²'(\" n:40 \") \" e':40 => Expr.Approx.Index",
"content": "notation:40 e:40 \" β²'(\" n:40 \") \" e':40 => Expr.Approx.Indexed' n e e'\n\nsyntax \"let \" ident \" := \" expr \" in \" expr : expr"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(βͺ$s:ident β― $i:numβ«) => `(Expr.var $(Lean.Syntax.mkStrLit s.getId.toString) $i)\n | `(βͺ$num:numβ«) => `(Expr.const (Constant.int $num))\n | `(βͺ$s:strβ«) => `(Expr.const (Constant.string $s))\n | `(βͺΟ
β«) => `(Expr.unit)\n | `(βͺ$eβ:expr $eβ:exprβ«) => `(Expr.app βͺ$eββ« βͺ$eββ«)\n | `(βͺΞ» $s:ident $e:exprβ«) => `(Expr.lambda $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eβ«)\n | `(βͺΞ» $ss:ident* . $e:exprβ«) => mkLambdas ss e\n | `(βͺ $s:ident β«) => `(Expr.constr $(Lean.Syntax.mkStrLit s.getId.toString))\n | `(βͺ $s:ident $es:expr* β«) => mkConstrApp s es\n | `(βͺ$eβ + $eββ«) => `(Expr.binop BinaryOp.add_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ - $eββ«) => `(Expr.binop BinaryOp.sub_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ * $eββ«) => `(Expr.binop BinaryOp.mul_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ / $eββ«) => `(Expr.binop BinaryOp.div_int βͺ$eββ« βͺ$eββ«)\n | `(βͺlet $s:ident := $eβ:expr in $eβ:exprβ«) => `(Expr.save $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eββ« βͺ$eββ«)\n | `(βͺletrec $s:ident := $eβ:expr in $eβ:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.save $name (Expr.recur $name βͺ$eββ«) βͺ$eββ«)\n | `(βͺrec $s:ident $e:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.recur $name βͺ$eβ«)\n | `(βͺβ₯β«) => `(Expr.fail)\n | `(βͺcases| | $s:ident => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« Expr.fail)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« Expr.fail)\n | `(βͺcases| | _ => $e:expr β«) =>\n `(βͺ$eβ«)\n | `(βͺcase $e:expr of $cs:cases endβ«) => do\n `(Expr.save \"_case_\" βͺ$eβ« βͺcases|$csβ«)\n | `(βͺ($e)β«) => `(βͺ$eβ«)"
},
{
"name": "BinaryOp",
"content": "inductive BinaryOp : Type where\n | add_int : BinaryOp\n | sub_int : BinaryOp\n | mul_int : BinaryOp\n | div_int : BinaryOp\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "cons_value",
"content": "abbrev cons_value (v : Value) (env : Env) : Env := Object.value v :: env\n\n inductive Object : Type where\n | value : Value β Object\n | delayed : (env : List Object) β Expr β Object\n deriving Inhabited\n\n inductive Value : Type where\n | unit : Value\n | const : Constant β Value\n | constr_app : (constr : Name) β (args_rev : List Value) β Value\n | closure : (env : List Object) β (value : Expr) β Value\n deriving Inhabited"
},
{
"name": "Expr",
"content": "inductive Expr : Type where\n | var : (name : String) β (index : Nat) β Expr\n | unit : Expr\n | const : Constant β Expr\n | constr : Name β Expr\n | app : Expr β Expr β Expr\n | constr_app : Expr β Expr β Expr\n | binop : (oper : BinaryOp) β (argβ argβ : Expr) β Expr\n | lambda : (var_name : String) β (body : Expr) β Expr\n | save : (var_name : String) β (value : Expr) β (body : Expr) β Expr\n | branch : (constr : Name) β (var_names : List Name) β (body : Expr) β (next : Expr) β Expr\n | recur : (var_name : Name) β (body : Expr) β Expr\n | fail : Expr\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Constant",
"content": "inductive Constant : Type where\n | int : Int β Constant\n | string : String β Constant\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Name",
"content": "abbrev Name : Type := String"
},
{
"name": "Env",
"content": "abbrev Env : Type := List Object"
},
{
"name": "Env.Approx.Indexed'",
"content": "def Env.Approx.Indexed' (n : Nat) : (envβ envβ : Env) β Prop :=\n List.Forallβ (Object.Approx.Indexed' n)"
},
{
"name": "Object.Approx.Indexed'",
"content": "inductive Object.Approx.Indexed' (n : Nat) : Object β Object β Prop where\n | value {vβ vβ} :\n vβ β²α΅₯(n) vβ β\n Object.Approx.Indexed' n (Object.value vβ) (Object.value vβ)\n | delayed {envβ envβ eβ eβ} :\n eβ β²(n)β¨envβ, envββ© eβ β\n Object.Approx.Indexed' n (Object.delayed envβ eβ) (Object.delayed envβ eβ)\n | delayed_eq {envβ envβ e} :\n List.Forallβ (Object.Approx.Indexed' n) envβ envβ β\n Object.Approx.Indexed' n (Object.delayed envβ e) (Object.delayed envβ e)"
},
{
"name": "Value.Approx.Indexed",
"content": "def Value.Approx.Indexed (n : Nat) (vβ vβ : Value) : Prop :=\n (vβ = Value.unit β§ vβ = Value.unit) β¨\n (β c, vβ = Value.const c β§ vβ = Value.const c) β¨\n (β ctr_name args_rev args_rev',\n vβ = Value.constr_app ctr_name args_rev β§\n vβ = Value.constr_app ctr_name args_rev' β§\n (β k < n, List.Forallβ (Value.Approx.Indexed k) args_rev args_rev')) β¨\n (β envβ bodyβ envβ bodyβ,\n vβ = Value.closure envβ bodyβ β§\n vβ = Value.closure envβ bodyβ β§\n (β nβ nβ, nβ + nβ < n β\n β aβ aβ rβ,\n Value.Approx.Indexed (nβ + nβ) aβ aβ β\n aβ β· envβ β’ bodyβ β¦(nβ) rβ β\n β rβ,\n aβ β· envβ β’ bodyβ β¦ rβ β§\n Value.Approx.Indexed nβ rβ rβ))"
},
{
"name": "Value.Approx.Indexed.Inversion",
"content": "@[aesop safe cases]\ninductive Value.Approx.Indexed.Inversion (n : Nat) : Value β Value β Prop where\n | unit : Value.Approx.Indexed.Inversion n Value.unit Value.unit\n | const {c} : Value.Approx.Indexed.Inversion n (Value.const c) (Value.const c)\n | constr_app {ctr_name args_rev args_rev'} :\n (β k < n, args_rev β²β(k) args_rev') β\n Value.Approx.Indexed.Inversion n (Value.constr_app ctr_name args_rev) (Value.constr_app ctr_name args_rev')\n | closure {envβ bodyβ envβ bodyβ} :\n (β nβ nβ, nβ + nβ < n β\n β aβ aβ vβ,\n aβ β²α΅₯(nβ + nβ) aβ β\n aβ β· envβ β’ bodyβ β¦(nβ) vβ β\n β vβ, aβ β· envβ β’ bodyβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ) β\n Value.Approx.Indexed.Inversion n (Value.closure envβ bodyβ) (Value.closure envβ bodyβ)"
},
{
"name": "Value.Approx.Indexed.Preservation",
"content": "def Value.Approx.Indexed.Preservation (k : Nat) : Prop :=\n β m n env env' e v,\n m + n < k β\n env β²β'(m + n) env' β\n env β’ e β¦(n) v β\n β v', env' β’ e β¦ v' β§ v β²α΅₯(m) v'"
},
{
"name": "Expr.Approx.Param.Indexed",
"content": "def Expr.Approx.Param.Indexed (n : Nat) (envβ envβ : Env) (eβ eβ : Expr) : Prop :=\n (β nβ nβ vβ, nβ + nβ β€ n β envβ β’ eβ β¦(nβ) vβ β β vβ, envβ β’ eβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ)"
},
{
"name": "Eval.Indexed",
"content": "inductive Eval.Indexed : Nat β Env β Expr β Value β Prop where\n | var {n env name idx val} :\n env[idx]? = some (Object.value val) β\n Eval.Indexed n env (Expr.var name idx) val\n | var_rec {n env name idx env' expr val} :\n env[idx]? = some (Object.delayed env' expr) β\n Eval.Indexed n env' expr val β\n Eval.Indexed n env (Expr.var name idx) val\n | unit {n env} :\n Eval.Indexed n env Expr.unit Value.unit\n | const {n env c} :\n Eval.Indexed n env (Expr.const c) (Value.const c)\n | constr {n env name} :\n Eval.Indexed n env (Expr.constr name) (Value.constr_app name [])\n | app {n nβ nβ env env' f body arg val val'} :\n nβ + nβ + 1 β€ n β\n Eval.Indexed nβ env f (Value.closure env' body) β\n Eval.Indexed (nβ + 1) env arg val β\n Eval.Indexed nβ (val β· env') body val' β\n Eval.Indexed n env (Expr.app f arg) val'\n | constr_app {n n' env ctr ctr_name ctr_args_rev arg val} :\n n' < n β\n Eval.Indexed n env ctr (Value.constr_app ctr_name ctr_args_rev) β\n Eval.Indexed n' env arg val β\n Eval.Indexed n env (Expr.constr_app ctr arg) (Value.constr_app ctr_name (val :: ctr_args_rev))\n | binop {n env op argβ argβ valβ valβ} :\n Eval.Indexed n env argβ (Value.const (Constant.int valβ)) β\n Eval.Indexed n env argβ (Value.const (Constant.int valβ)) β\n Eval.Indexed n env (Expr.binop op argβ argβ) (Value.const (Constant.int (eval_binop_int op valβ valβ)))\n | lambda {n env name body} :\n Eval.Indexed n env (Expr.lambda name body) (Value.closure env body)\n | save {n nβ nβ env name value body val val'} :\n nβ + nβ β€ n β\n Eval.Indexed nβ env value val β\n Eval.Indexed nβ (val β· env) body val' β\n Eval.Indexed n env (Expr.save name value body) val'\n | branch_matches {n n' env name args_rev body val} :\n n' < n β\n Eval.Indexed n' (args_rev.map Object.value ++ env) body val β\n Eval.Indexed n (Value.constr_app name args_rev β· env) (Expr.branch name _ body _) val\n | branch_fails {n env name name' args_rev next val} :\n name β name' β\n Eval.Indexed n (Value.constr_app name args_rev β· env) next val β\n Eval.Indexed n (Value.constr_app name args_rev β· env) (Expr.branch name' _ _ next) val\n | recur {n n' env name body val} :\n n' < n β\n Eval.Indexed n' (Object.delayed env (Expr.recur name body) :: env) body val β\n Eval.Indexed n env (Expr.recur name body) val"
},
{
"name": "Eval",
"content": "@[aesop unsafe constructors]\ninductive Eval : Env β Expr β Value β Prop where\n | var {env name idx val} :\n env[idx]? = some (Object.value val) β\n Eval env (Expr.var name idx) val\n | var_rec {env name idx env' expr val} :\n env[idx]? = some (Object.delayed env' expr) β\n Eval env' expr val β\n Eval env (Expr.var name idx) val\n | unit {env} :\n Eval env Expr.unit Value.unit\n | const {env c} :\n Eval env (Expr.const c) (Value.const c)\n | constr {env name} :\n Eval env (Expr.constr name) (Value.constr_app name [])\n | app {env env' f body arg val val'} :\n Eval env f (Value.closure env' body) β\n Eval env arg val β\n Eval (val β· env') body val' β\n Eval env (Expr.app f arg) val'\n | constr_app {env ctr ctr_name ctr_args_rev arg val} :\n Eval env ctr (Value.constr_app ctr_name ctr_args_rev) β\n Eval env arg val β\n Eval env (Expr.constr_app ctr arg) (Value.constr_app ctr_name (val :: ctr_args_rev))\n | binop {env op argβ argβ valβ valβ} :\n Eval env argβ (Value.const (Constant.int valβ)) β\n Eval env argβ (Value.const (Constant.int valβ)) β\n Eval env (Expr.binop op argβ argβ) (Value.const (Constant.int (eval_binop_int op valβ valβ)))\n | lambda {env name body} :\n Eval env (Expr.lambda name body) (Value.closure env body)\n | save {env name value body val val'} :\n Eval env value val β\n Eval (val β· env) body val' β\n Eval env (Expr.save name value body) val'\n | branch_matches {env name args_rev body val} :\n Eval (args_rev.map Object.value ++ env) body val β\n Eval (Value.constr_app name args_rev β· env) (Expr.branch name _ body _) val\n | branch_fails {env name name' args_rev next val} :\n name β name' β\n Eval (Value.constr_app name args_rev β· env) next val β\n Eval (Value.constr_app name args_rev β· env) (Expr.branch name' _ _ next) val\n | recur {env name body val} :\n Eval (Object.delayed env (Expr.recur name body) :: env) body val β\n Eval env (Expr.recur name body) val"
},
{
"name": "Context",
"content": "inductive Context : Type where\n | hole : Context\n | app_left : Context β Expr β Context\n | app_right : Expr β Context β Context\n | constr_app_left : Context β Expr β Context\n | constr_app_right : Expr β Context β Context\n | binop_left : (oper : BinaryOp) β (argβ : Context) β (argβ : Expr) β Context\n | binop_right : (oper : BinaryOp) β (argβ : Expr) β (argβ : Context) β Context\n | lambda : (var_name : String) β (body : Context) β Context\n | save_left : (var_name : String) β (value : Context) β (body : Expr) β Context\n | save_right : (var_name : String) β (value : Expr) β (body : Context) β Context\n | branch_left : (constr : Name) β (var_names : List Name) β (body : Context) β (next : Expr) β Context\n | branch_right : (constr : Name) β (var_names : List Name) β (body : Expr) β (next : Context) β Context\n | recur : (var_name : Name) β (ctx : Context) β Context\n deriving Inhabited, BEq"
},
{
"name": "eval_binop_int",
"content": "def eval_binop_int (op : BinaryOp) (iβ iβ : Int) : Int :=\n match op with\n | BinaryOp.add_int => iβ + iβ\n | BinaryOp.sub_int => iβ - iβ\n | BinaryOp.mul_int => iβ * iβ\n | BinaryOp.div_int => iβ / iβ"
},
{
"name": "Expr.Approx.Indexed'",
"content": "def Expr.Approx.Indexed' (n : Nat) (eβ eβ : Expr) : Prop :=\n (β nβ nβ vβ, nβ + nβ β€ n β\n β envβ envβ, envβ β²β'(nβ + nβ) envβ β envβ β’ eβ β¦(nβ) vβ β β vβ, envβ β’ eβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ)"
},
{
"name": "infixr:50 \" β· \" => cons_value",
"content": "infixr:50 \" β· \" => cons_value"
},
{
"name": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Inde",
"content": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Indexed n v v'"
},
{
"name": "notation:40 e:40 \" β²(\" n:40 \")β¨\" env:40 \", \" env':40 \"β© \" e'",
"content": "notation:40 e:40 \" β²(\" n:40 \")β¨\" env:40 \", \" env':40 \"β© \" e':40 => Expr.Approx.Param.Indexed n env env' e e'"
},
{
"name": "notation:40 v:40 \" β²β'(\" n:40 \") \" v':40 => Object.Approx.In",
"content": "notation:40 v:40 \" β²β'(\" n:40 \") \" v':40 => Object.Approx.Indexed' n v v'"
},
{
"name": "notation:40 envβ:40 \" β²β'(\" n:40 \") \" envβ:40 => Env.Approx.",
"content": "notation:40 envβ:40 \" β²β'(\" n:40 \") \" envβ:40 => Env.Approx.Indexed' n envβ envβ"
},
{
"name": "notation:40 e:40 \" β²'(\" n:40 \") \" e':40 => Expr.Approx.Index",
"content": "notation:40 e:40 \" β²'(\" n:40 \") \" e':40 => Expr.Approx.Indexed' n e e'"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Inde",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Indexed n env e v"
},
{
"name": "infixl:100 \" @@ \" => Expr.app",
"content": "infixl:100 \" @@ \" => Expr.app"
}
] | [
{
"name": "IsEmpty.forall_iff",
"module": "Mathlib.Logic.IsEmpty"
},
{
"name": "implies_true",
"module": "Init.SimpLemmas"
},
{
"name": "nonpos_iff_eq_zero",
"module": "Mathlib.Algebra.Order.Monoid.Canonical.Defs"
},
{
"name": "not_lt_zero'",
"module": "Mathlib.Algebra.Order.GroupWithZero.Canonical"
}
] | [
{
"name": "Value.Approx.Indexed.invert",
"content": "@[aesop unsafe destruct]\nlemma Value.Approx.Indexed.invert {n v v'} :\n v β²α΅₯(n) v' β\n Value.Approx.Indexed.Inversion n v v'"
},
{
"name": "Value.Approx.Indexed.constr_app",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.constr_app {n ctr_name args_rev args_rev'} :\n (β k < n, args_rev β²β(k) args_rev') β\n Value.constr_app ctr_name args_rev β²α΅₯(n) Value.constr_app ctr_name args_rev'"
},
{
"name": "Value.Approx.Indexed.unit",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.unit {n} : Value.unit β²α΅₯(n) Value.unit"
},
{
"name": "Value.Approx.Indexed.const",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.const {n c} : Value.const c β²α΅₯(n) Value.const c"
},
{
"name": "Value.Approx.Indexed.closure",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.closure {n envβ bodyβ envβ bodyβ} :\n (β nβ nβ, nβ + nβ < n β\n β aβ aβ vβ,\n aβ β²α΅₯(nβ + nβ) aβ β\n aβ β· envβ β’ bodyβ β¦(nβ) vβ β\n β vβ, aβ β· envβ β’ bodyβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ) β\n Value.closure envβ bodyβ β²α΅₯(n) Value.closure envβ bodyβ"
},
{
"name": "forallβ_trans'",
"content": "theorem forallβ_trans' {Ξ±} {P Q R : Ξ± β Ξ± β Prop} {lβ lβ lβ}\n (h : β x y z, P x y β Q y z β R x z)\n (hβ : List.Forallβ P lβ lβ)\n (hβ : List.Forallβ Q lβ lβ)\n : List.Forallβ R lβ lβ"
},
{
"name": "Value.Approx.Indexed.preserved",
"content": "theorem Value.Approx.Indexed.preserved :\n β m n env env' e v,\n env β²β'(m + n) env' β\n env β’ e β¦(n) v β\n β v', env' β’ e β¦ v' β§ v β²α΅₯(m) v'"
},
{
"name": "Value.Approx.Indexed.preserved'",
"content": "lemma Value.Approx.Indexed.preserved' {k} : Preservation k"
},
{
"name": "Env.Approx.Indexed'.refl",
"content": "@[refl]\nlemma Env.Approx.Indexed'.refl {n env} : env β²β'(n) env"
},
{
"name": "Value.Approx.Indexed.refl",
"content": "@[refl]\nlemma Value.Approx.Indexed.refl {n} v : v β²α΅₯(n) v"
},
{
"name": "Object.Approx.Indexed'.refl'",
"content": "lemma Object.Approx.Indexed'.refl' {n o} (h : β v, v β²α΅₯(n) v) : o β²β'(n) o"
},
{
"name": "Env.Approx.Indexed'.refl'",
"content": "lemma Env.Approx.Indexed'.refl' {n env} (h : β v, v β²α΅₯(n) v) : env β²β'(n) env"
},
{
"name": "Object.Approx.Indexed'.refl",
"content": "@[refl]\nlemma Object.Approx.Indexed'.refl {n o} : o β²β'(n) o"
},
{
"name": "Value.Approx.Indexed.preserved_step",
"content": "lemma Value.Approx.Indexed.preserved_step {k} :\n (β k' < k, Preservation k') β Preservation k"
},
{
"name": "Expr.Approx.Param.Indexed.anti_monotone",
"content": "lemma Expr.Approx.Param.Indexed.anti_monotone {n n' envβ envβ eβ eβ}\n (h : eβ β²(n)β¨envβ, envββ© eβ)\n (h' : n' β€ n)\n : eβ β²(n')β¨envβ, envββ© eβ"
},
{
"name": "Expr.Approx.Indexed'.anti_monotone",
"content": "lemma Expr.Approx.Indexed'.anti_monotone {n n' eβ eβ}\n (h : eβ β²'(n) eβ)\n (h' : n' β€ n)\n : eβ β²'(n') eβ"
},
{
"name": "Env.Approx.Indexed'.delayed",
"content": "lemma Env.Approx.Indexed'.delayed {n i : Nat} {envβ envβ env e}\n (hβ : envβ β²β'(n) envβ)\n (hβ : envβ[i]? = some (Object.delayed env e)) :\n (β env' e', e β²(n)β¨env, env'β© e' β§ envβ[i]? = some (Object.delayed env' e')) β¨\n β env', env β²β'(n) env' β§ envβ[i]? = some (Object.delayed env' e)"
},
{
"name": "Env.Approx.Indexed'.value",
"content": "lemma Env.Approx.Indexed'.value {n i : Nat} {env env' v}\n (hβ : env β²β'(n) env')\n (hβ : env[i]? = some (Object.value v)) :\n β v', env'[i]? = some (Object.value v') β§ v β²α΅₯(n) v'"
},
{
"name": "Env.Approx.Indexed'.get",
"content": "lemma Env.Approx.Indexed'.get {n i : Nat} {env env' oβ}\n (hβ : env β²β'(n) env')\n (hβ : env[i]? = some oβ) :\n β oβ, env'[i]? = some oβ β§ oβ β²β'(n) oβ"
},
{
"name": "Value.Approx.Indexed.anti_monotone",
"content": "lemma Value.Approx.Indexed.anti_monotone {n n' vβ vβ} (h : vβ β²α΅₯(n) vβ) (h' : n' β€ n) : vβ β²α΅₯(n') vβ"
},
{
"name": "Value.Approx.Indexed.Preservation.anti_monotone",
"content": "lemma Value.Approx.Indexed.Preservation.anti_monotone {k k'} (h : Value.Approx.Indexed.Preservation k) (h' : k' β€ k) : Value.Approx.Indexed.Preservation k'"
},
{
"name": "Env.Approx.Indexed'.anti_monotone",
"content": "lemma Env.Approx.Indexed'.anti_monotone {n n' envβ envβ}\n (h : envβ β²β'(n) envβ)\n (h' : n' β€ n)\n : envβ β²β'(n') envβ"
},
{
"name": "Object.Approx.Indexed'.anti_monotone",
"content": "lemma Object.Approx.Indexed'.anti_monotone {n n' oβ oβ} (h : oβ β²β'(n) oβ) (h' : n' β€ n) : oβ β²β'(n') oβ"
},
{
"name": "Env.Approx.Indexed'.cons",
"content": "lemma Env.Approx.Indexed'.cons {n oβ oβ envβ envβ}\n (hβ : oβ β²β'(n) oβ)\n (hβ : envβ β²β'(n) envβ) :\n oβ :: envβ β²β'(n) oβ :: envβ"
},
{
"name": "Env.Approx.Indexed'.concat",
"content": "lemma Env.Approx.Indexed'.concat {n envβ envβ envβ' envβ'}\n (hβ : envβ β²β'(n) envβ')\n (hβ : envβ β²β'(n) envβ') :\n envβ ++ envβ β²β'(n) envβ' ++ envβ'"
},
{
"name": "Env.Approx.Indexed'.from_value",
"content": "lemma Env.Approx.Indexed'.from_value {n lβ lβ} (h : lβ β²β(n) lβ) :\n List.map Object.value lβ β²β'(n) List.map Object.value lβ"
},
{
"name": "Eval.deterministic",
"content": "theorem Eval.deterministic {env e vβ vβ} (hβ : env β’ e β¦ vβ) (hβ : env β’ e β¦ vβ) : vβ = vβ"
},
{
"name": "Eval.toIndexed",
"content": "lemma Eval.toIndexed {env e v} (h : env β’ e β¦ v) : β n, env β’ e β¦(n) v"
},
{
"name": "Eval.Indexed.monotone",
"content": "lemma Eval.Indexed.monotone {n n' env e v} (h : env β’ e β¦(n) v) (h' : n β€ n') : env β’ e β¦(n') v"
}
] | [
{
"name": "Juvix.Core.Main.Value.Approx",
"content": "def Value.Approx (v v' : Value) : Prop :=\n β n, v β²α΅₯(n) v'"
},
{
"name": "Juvix.Core.Main.Expr.Approx.Param",
"content": "def Expr.Approx.Param (envβ envβ : Env) (eβ eβ : Expr) : Prop :=\n (β vβ, envβ β’ eβ β¦ vβ β β vβ, envβ β’ eβ β¦ vβ β§ vβ β²α΅₯ vβ)"
},
{
"name": "Juvix.Core.Main.Object.Approx",
"content": "inductive Object.Approx : Object β Object β Prop where\n | value {vβ vβ} : vβ β²α΅₯ vβ β Object.Approx (Object.value vβ) (Object.value vβ)\n | delayed {envβ envβ eβ eβ} :\n eβ β²β¨envβ, envββ© eβ β\n Object.Approx (Object.delayed envβ eβ) (Object.delayed envβ eβ)"
},
{
"name": "Juvix.Core.Main.Env.Approx",
"content": "def Env.Approx : (envβ envβ : Env) β Prop :=\n List.Forallβ Object.Approx"
},
{
"name": "Juvix.Core.Main.Expr.Approx",
"content": "def Expr.Approx (eβ eβ : Expr) : Prop :=\n β envβ envβ, envβ β²β envβ β eβ β²β¨envβ, envββ© eβ"
}
] | [] | import Juvix.Core.Main.Semantics.Approx.Indexed
namespace Juvix.Core.Main
def Value.Approx (v v' : Value) : Prop :=
β n, v β²α΅₯(n) v'
notation:40 v:40 " β²α΅₯ " v':40 => Value.Approx v v'
notation:40 argsβ:40 " β²β " argsβ:40 => List.Forallβ Value.Approx argsβ argsβ
def Expr.Approx.Param (envβ envβ : Env) (eβ eβ : Expr) : Prop :=
(β vβ, envβ β’ eβ β¦ vβ β β vβ, envβ β’ eβ β¦ vβ β§ vβ β²α΅₯ vβ)
notation:40 e:40 " β²β¨" env:40 ", " env':40 "β© " e':40 => Expr.Approx.Param env env' e e'
inductive Object.Approx : Object β Object β Prop where
| value {vβ vβ} : vβ β²α΅₯ vβ β Object.Approx (Object.value vβ) (Object.value vβ)
| delayed {envβ envβ eβ eβ} :
eβ β²β¨envβ, envββ© eβ β
Object.Approx (Object.delayed envβ eβ) (Object.delayed envβ eβ)
def Env.Approx : (envβ envβ : Env) β Prop :=
List.Forallβ Object.Approx
notation:40 v:40 " β²β " v':40 => Object.Approx v v'
notation:40 envβ:40 " β²β " envβ:40 => Env.Approx envβ envβ
def Expr.Approx (eβ eβ : Expr) : Prop :=
β envβ envβ, envβ β²β envβ β eβ β²β¨envβ, envββ© eβ
notation:40 eβ:40 " β² " eβ:40 => Expr.Approx eβ eβ | lemma Value.Approx.closure_inv {envβ bodyβ envβ bodyβ}
(h : Value.closure envβ bodyβ β²α΅₯ Value.closure envβ bodyβ) :
β aβ aβ, aβ β²α΅₯ aβ β bodyβ β²β¨aβ β· envβ, aβ β· envββ© bodyβ := | := by
intro aβ aβ ha vβ h'
suffices β n, β vβ, (aβ β· envβ) β’ bodyβ β¦ vβ β§ vβ β²α΅₯(n) vβ by
obtain β¨vβ, _, _β© := this 0
exists vβ
constructor
Β· assumption
Β· intro n
obtain β¨vβ', _, _β© := this n
have : vβ = vβ' := by
apply Eval.deterministic <;> assumption
subst this
simp_all only
intro nβ
obtain β¨nβ, h''β© := Eval.toIndexed h'
invert (h (nβ + nβ + 1))
case closure ch =>
apply ch (nβ := nβ) (nβ := nβ)
Β· linarith
Β· apply ha
Β· assumption | 5 | 72 | false | Semantics |
255 | Juvix.Core.Main.Value.Approx.preserved | theorem Value.Approx.preserved :
β env env' e v,
env β²β env' β
env β’ e β¦ v β
β v', env' β’ e β¦ v' β§ v β²α΅₯ v' | juvix-lean | Juvix/Core/Main/Semantics/Approx.lean | [
"import Juvix.Core.Main.Semantics.Approx.Indexed",
"import Juvix.Core.Main.Semantics.Eval",
"import Juvix.Core.Main.Semantics.Eval.Indexed"
] | [
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "List.Forallβ",
"module": "Batteries.Data.List.Basic"
},
{
"name": "BEq",
"module": "Init.Prelude"
},
{
"name": "DecidableEq",
"module": "Init.Prelude"
},
{
"name": "Inhabited",
"module": "Init.Prelude"
},
{
"name": "Int",
"module": "Init.Data.Int.Basic"
},
{
"name": "String",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "closure",
"module": "Mathlib.Topology.Defs.Basic"
},
{
"name": "List.Forallβ.cons",
"module": "Batteries.Data.List.Basic"
},
{
"name": "List.map",
"module": "Init.Prelude"
}
] | [
{
"name": "notation:40 e:40 \" β²β¨\" env:40 \", \" env':40 \"β© \" e':40 => Exp",
"content": "notation:40 e:40 \" β²β¨\" env:40 \", \" env':40 \"β© \" e':40 => Expr.Approx.Param env env' e e'"
},
{
"name": "notation:40 v:40 \" β²α΅₯ \" v':40 => Value.Approx v v'",
"content": "notation:40 v:40 \" β²α΅₯ \" v':40 => Value.Approx v v'"
},
{
"name": "notation:40 eβ:40 \" β² \" eβ:40 => Expr.Approx eβ eβ",
"content": "notation:40 eβ:40 \" β² \" eβ:40 => Expr.Approx eβ eβ"
},
{
"name": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Inde",
"content": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Indexed n v v'"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β\" => Eval.Defined env e",
"content": "notation:40 env:40 \" β’ \" e:40 \" β\" => Eval.Defined env e"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Inde",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Indexed n env e v"
},
{
"name": "notation:40 e:40 \" β²(\" n:40 \")β¨\" env:40 \", \" env':40 \"β© \" e'",
"content": "notation:40 e:40 \" β²(\" n:40 \")β¨\" env:40 \", \" env':40 \"β© \" e':40 => Expr.Approx.Param.Indexed n env env' e e'\n\nsyntax:100 expr:100 ppSpace expr:101 : expr\n\nsyntax:50 expr:50 \" + \" expr:51 : expr\n\nsyntax:50 expr:50 \" - \" expr:50 : expr\n\nsyntax:60 expr:60 \" * \" expr:61 : expr\n\nsyntax:60 expr:60 \" / \" expr:60 : expr\n\nsyntax \"case \" expr \" of \" cases \" end\" : expr"
},
{
"name": "notation:40 v:40 \" β²β'(\" n:40 \") \" v':40 => Object.Approx.In",
"content": "notation:40 v:40 \" β²β'(\" n:40 \") \" v':40 => Object.Approx.Indexed' n v v'"
},
{
"name": "notation:40 v:40 \" β²β \" v':40 => Object.Approx v v'",
"content": "notation:40 v:40 \" β²β \" v':40 => Object.Approx v v'"
},
{
"name": "notation:40 envβ:40 \" β²β \" envβ:40 => Env.Approx envβ envβ",
"content": "notation:40 envβ:40 \" β²β \" envβ:40 => Env.Approx envβ envβ"
},
{
"name": "notation:40 envβ:40 \" β²β'(\" n:40 \") \" envβ:40 => Env.Approx.",
"content": "notation:40 envβ:40 \" β²β'(\" n:40 \") \" envβ:40 => Env.Approx.Indexed' n envβ envβ"
},
{
"name": "notation:40 argsβ:40 \" β²β(\" n:40 \") \" argsβ:40 => List.Foral",
"content": "notation:40 argsβ:40 \" β²β(\" n:40 \") \" argsβ:40 => List.Forallβ (Value.Approx.Indexed n) argsβ argsβ"
},
{
"name": "notation:40 e:40 \" β²'(\" n:40 \") \" e':40 => Expr.Approx.Index",
"content": "notation:40 e:40 \" β²'(\" n:40 \") \" e':40 => Expr.Approx.Indexed' n e e'"
},
{
"name": "macro \"invert\" h:term : tactic => `(tactic| (cases ($h).inve",
"content": "macro \"invert\" h:term : tactic => `(tactic| (cases ($h).invert <;> try clear $h))\n\nsyntax \"let \" ident \" := \" expr \" in \" expr : expr"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(βͺ$s:ident β― $i:numβ«) => `(Expr.var $(Lean.Syntax.mkStrLit s.getId.toString) $i)\n | `(βͺ$num:numβ«) => `(Expr.const (Constant.int $num))\n | `(βͺ$s:strβ«) => `(Expr.const (Constant.string $s))\n | `(βͺΟ
β«) => `(Expr.unit)\n | `(βͺ$eβ:expr $eβ:exprβ«) => `(Expr.app βͺ$eββ« βͺ$eββ«)\n | `(βͺΞ» $s:ident $e:exprβ«) => `(Expr.lambda $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eβ«)\n | `(βͺΞ» $ss:ident* . $e:exprβ«) => mkLambdas ss e\n | `(βͺ $s:ident β«) => `(Expr.constr $(Lean.Syntax.mkStrLit s.getId.toString))\n | `(βͺ $s:ident $es:expr* β«) => mkConstrApp s es\n | `(βͺ$eβ + $eββ«) => `(Expr.binop BinaryOp.add_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ - $eββ«) => `(Expr.binop BinaryOp.sub_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ * $eββ«) => `(Expr.binop BinaryOp.mul_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ / $eββ«) => `(Expr.binop BinaryOp.div_int βͺ$eββ« βͺ$eββ«)\n | `(βͺlet $s:ident := $eβ:expr in $eβ:exprβ«) => `(Expr.save $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eββ« βͺ$eββ«)\n | `(βͺletrec $s:ident := $eβ:expr in $eβ:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.save $name (Expr.recur $name βͺ$eββ«) βͺ$eββ«)\n | `(βͺrec $s:ident $e:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.recur $name βͺ$eβ«)\n | `(βͺβ₯β«) => `(Expr.fail)\n | `(βͺcases| | $s:ident => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« Expr.fail)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« Expr.fail)\n | `(βͺcases| | _ => $e:expr β«) =>\n `(βͺ$eβ«)\n | `(βͺcase $e:expr of $cs:cases endβ«) => do\n `(Expr.save \"_case_\" βͺ$eβ« βͺcases|$csβ«)\n | `(βͺ($e)β«) => `(βͺ$eβ«)\n\n inductive Object : Type where\n | value : Value β Object\n | delayed : (env : List Object) β Expr β Object\n deriving Inhabited"
},
{
"name": "Value.Approx.Indexed",
"content": "def Value.Approx.Indexed (n : Nat) (vβ vβ : Value) : Prop :=\n (vβ = Value.unit β§ vβ = Value.unit) β¨\n (β c, vβ = Value.const c β§ vβ = Value.const c) β¨\n (β ctr_name args_rev args_rev',\n vβ = Value.constr_app ctr_name args_rev β§\n vβ = Value.constr_app ctr_name args_rev' β§\n (β k < n, List.Forallβ (Value.Approx.Indexed k) args_rev args_rev')) β¨\n (β envβ bodyβ envβ bodyβ,\n vβ = Value.closure envβ bodyβ β§\n vβ = Value.closure envβ bodyβ β§\n (β nβ nβ, nβ + nβ < n β\n β aβ aβ rβ,\n Value.Approx.Indexed (nβ + nβ) aβ aβ β\n aβ β· envβ β’ bodyβ β¦(nβ) rβ β\n β rβ,\n aβ β· envβ β’ bodyβ β¦ rβ β§\n Value.Approx.Indexed nβ rβ rβ))\n\n inductive Value : Type where\n | unit : Value\n | const : Constant β Value\n | constr_app : (constr : Name) β (args_rev : List Value) β Value\n | closure : (env : List Object) β (value : Expr) β Value\n deriving Inhabited"
},
{
"name": "cons_value",
"content": "abbrev cons_value (v : Value) (env : Env) : Env := Object.value v :: env"
},
{
"name": "Expr",
"content": "inductive Expr : Type where\n | var : (name : String) β (index : Nat) β Expr\n | unit : Expr\n | const : Constant β Expr\n | constr : Name β Expr\n | app : Expr β Expr β Expr\n | constr_app : Expr β Expr β Expr\n | binop : (oper : BinaryOp) β (argβ argβ : Expr) β Expr\n | lambda : (var_name : String) β (body : Expr) β Expr\n | save : (var_name : String) β (value : Expr) β (body : Expr) β Expr\n | branch : (constr : Name) β (var_names : List Name) β (body : Expr) β (next : Expr) β Expr\n | recur : (var_name : Name) β (body : Expr) β Expr\n | fail : Expr\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "BinaryOp",
"content": "inductive BinaryOp : Type where\n | add_int : BinaryOp\n | sub_int : BinaryOp\n | mul_int : BinaryOp\n | div_int : BinaryOp\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Constant",
"content": "inductive Constant : Type where\n | int : Int β Constant\n | string : String β Constant\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Name",
"content": "abbrev Name : Type := String"
},
{
"name": "Env",
"content": "abbrev Env : Type := List Object"
},
{
"name": "Env.Approx.Indexed'",
"content": "def Env.Approx.Indexed' (n : Nat) : (envβ envβ : Env) β Prop :=\n List.Forallβ (Object.Approx.Indexed' n)"
},
{
"name": "Object.Approx.Indexed'",
"content": "inductive Object.Approx.Indexed' (n : Nat) : Object β Object β Prop where\n | value {vβ vβ} :\n vβ β²α΅₯(n) vβ β\n Object.Approx.Indexed' n (Object.value vβ) (Object.value vβ)\n | delayed {envβ envβ eβ eβ} :\n eβ β²(n)β¨envβ, envββ© eβ β\n Object.Approx.Indexed' n (Object.delayed envβ eβ) (Object.delayed envβ eβ)\n | delayed_eq {envβ envβ e} :\n List.Forallβ (Object.Approx.Indexed' n) envβ envβ β\n Object.Approx.Indexed' n (Object.delayed envβ e) (Object.delayed envβ e)"
},
{
"name": "Eval.Indexed",
"content": "inductive Eval.Indexed : Nat β Env β Expr β Value β Prop where\n | var {n env name idx val} :\n env[idx]? = some (Object.value val) β\n Eval.Indexed n env (Expr.var name idx) val\n | var_rec {n env name idx env' expr val} :\n env[idx]? = some (Object.delayed env' expr) β\n Eval.Indexed n env' expr val β\n Eval.Indexed n env (Expr.var name idx) val\n | unit {n env} :\n Eval.Indexed n env Expr.unit Value.unit\n | const {n env c} :\n Eval.Indexed n env (Expr.const c) (Value.const c)\n | constr {n env name} :\n Eval.Indexed n env (Expr.constr name) (Value.constr_app name [])\n | app {n nβ nβ env env' f body arg val val'} :\n nβ + nβ + 1 β€ n β\n Eval.Indexed nβ env f (Value.closure env' body) β\n Eval.Indexed (nβ + 1) env arg val β\n Eval.Indexed nβ (val β· env') body val' β\n Eval.Indexed n env (Expr.app f arg) val'\n | constr_app {n n' env ctr ctr_name ctr_args_rev arg val} :\n n' < n β\n Eval.Indexed n env ctr (Value.constr_app ctr_name ctr_args_rev) β\n Eval.Indexed n' env arg val β\n Eval.Indexed n env (Expr.constr_app ctr arg) (Value.constr_app ctr_name (val :: ctr_args_rev))\n | binop {n env op argβ argβ valβ valβ} :\n Eval.Indexed n env argβ (Value.const (Constant.int valβ)) β\n Eval.Indexed n env argβ (Value.const (Constant.int valβ)) β\n Eval.Indexed n env (Expr.binop op argβ argβ) (Value.const (Constant.int (eval_binop_int op valβ valβ)))\n | lambda {n env name body} :\n Eval.Indexed n env (Expr.lambda name body) (Value.closure env body)\n | save {n nβ nβ env name value body val val'} :\n nβ + nβ β€ n β\n Eval.Indexed nβ env value val β\n Eval.Indexed nβ (val β· env) body val' β\n Eval.Indexed n env (Expr.save name value body) val'\n | branch_matches {n n' env name args_rev body val} :\n n' < n β\n Eval.Indexed n' (args_rev.map Object.value ++ env) body val β\n Eval.Indexed n (Value.constr_app name args_rev β· env) (Expr.branch name _ body _) val\n | branch_fails {n env name name' args_rev next val} :\n name β name' β\n Eval.Indexed n (Value.constr_app name args_rev β· env) next val β\n Eval.Indexed n (Value.constr_app name args_rev β· env) (Expr.branch name' _ _ next) val\n | recur {n n' env name body val} :\n n' < n β\n Eval.Indexed n' (Object.delayed env (Expr.recur name body) :: env) body val β\n Eval.Indexed n env (Expr.recur name body) val"
},
{
"name": "Eval",
"content": "@[aesop unsafe constructors]\ninductive Eval : Env β Expr β Value β Prop where\n | var {env name idx val} :\n env[idx]? = some (Object.value val) β\n Eval env (Expr.var name idx) val\n | var_rec {env name idx env' expr val} :\n env[idx]? = some (Object.delayed env' expr) β\n Eval env' expr val β\n Eval env (Expr.var name idx) val\n | unit {env} :\n Eval env Expr.unit Value.unit\n | const {env c} :\n Eval env (Expr.const c) (Value.const c)\n | constr {env name} :\n Eval env (Expr.constr name) (Value.constr_app name [])\n | app {env env' f body arg val val'} :\n Eval env f (Value.closure env' body) β\n Eval env arg val β\n Eval (val β· env') body val' β\n Eval env (Expr.app f arg) val'\n | constr_app {env ctr ctr_name ctr_args_rev arg val} :\n Eval env ctr (Value.constr_app ctr_name ctr_args_rev) β\n Eval env arg val β\n Eval env (Expr.constr_app ctr arg) (Value.constr_app ctr_name (val :: ctr_args_rev))\n | binop {env op argβ argβ valβ valβ} :\n Eval env argβ (Value.const (Constant.int valβ)) β\n Eval env argβ (Value.const (Constant.int valβ)) β\n Eval env (Expr.binop op argβ argβ) (Value.const (Constant.int (eval_binop_int op valβ valβ)))\n | lambda {env name body} :\n Eval env (Expr.lambda name body) (Value.closure env body)\n | save {env name value body val val'} :\n Eval env value val β\n Eval (val β· env) body val' β\n Eval env (Expr.save name value body) val'\n | branch_matches {env name args_rev body val} :\n Eval (args_rev.map Object.value ++ env) body val β\n Eval (Value.constr_app name args_rev β· env) (Expr.branch name _ body _) val\n | branch_fails {env name name' args_rev next val} :\n name β name' β\n Eval (Value.constr_app name args_rev β· env) next val β\n Eval (Value.constr_app name args_rev β· env) (Expr.branch name' _ _ next) val\n | recur {env name body val} :\n Eval (Object.delayed env (Expr.recur name body) :: env) body val β\n Eval env (Expr.recur name body) val"
},
{
"name": "eval_binop_int",
"content": "def eval_binop_int (op : BinaryOp) (iβ iβ : Int) : Int :=\n match op with\n | BinaryOp.add_int => iβ + iβ\n | BinaryOp.sub_int => iβ - iβ\n | BinaryOp.mul_int => iβ * iβ\n | BinaryOp.div_int => iβ / iβ"
},
{
"name": "Value.Approx.Indexed.Preservation",
"content": "def Value.Approx.Indexed.Preservation (k : Nat) : Prop :=\n β m n env env' e v,\n m + n < k β\n env β²β'(m + n) env' β\n env β’ e β¦(n) v β\n β v', env' β’ e β¦ v' β§ v β²α΅₯(m) v'"
},
{
"name": "Value.Approx.Indexed.Inversion",
"content": "@[aesop safe cases]\ninductive Value.Approx.Indexed.Inversion (n : Nat) : Value β Value β Prop where\n | unit : Value.Approx.Indexed.Inversion n Value.unit Value.unit\n | const {c} : Value.Approx.Indexed.Inversion n (Value.const c) (Value.const c)\n | constr_app {ctr_name args_rev args_rev'} :\n (β k < n, args_rev β²β(k) args_rev') β\n Value.Approx.Indexed.Inversion n (Value.constr_app ctr_name args_rev) (Value.constr_app ctr_name args_rev')\n | closure {envβ bodyβ envβ bodyβ} :\n (β nβ nβ, nβ + nβ < n β\n β aβ aβ vβ,\n aβ β²α΅₯(nβ + nβ) aβ β\n aβ β· envβ β’ bodyβ β¦(nβ) vβ β\n β vβ, aβ β· envβ β’ bodyβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ) β\n Value.Approx.Indexed.Inversion n (Value.closure envβ bodyβ) (Value.closure envβ bodyβ)"
},
{
"name": "Expr.Approx.Param.Indexed",
"content": "def Expr.Approx.Param.Indexed (n : Nat) (envβ envβ : Env) (eβ eβ : Expr) : Prop :=\n (β nβ nβ vβ, nβ + nβ β€ n β envβ β’ eβ β¦(nβ) vβ β β vβ, envβ β’ eβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ)"
},
{
"name": "Context",
"content": "inductive Context : Type where\n | hole : Context\n | app_left : Context β Expr β Context\n | app_right : Expr β Context β Context\n | constr_app_left : Context β Expr β Context\n | constr_app_right : Expr β Context β Context\n | binop_left : (oper : BinaryOp) β (argβ : Context) β (argβ : Expr) β Context\n | binop_right : (oper : BinaryOp) β (argβ : Expr) β (argβ : Context) β Context\n | lambda : (var_name : String) β (body : Context) β Context\n | save_left : (var_name : String) β (value : Context) β (body : Expr) β Context\n | save_right : (var_name : String) β (value : Expr) β (body : Context) β Context\n | branch_left : (constr : Name) β (var_names : List Name) β (body : Context) β (next : Expr) β Context\n | branch_right : (constr : Name) β (var_names : List Name) β (body : Expr) β (next : Context) β Context\n | recur : (var_name : Name) β (ctx : Context) β Context\n deriving Inhabited, BEq"
},
{
"name": "Expr.Approx.Indexed'",
"content": "def Expr.Approx.Indexed' (n : Nat) (eβ eβ : Expr) : Prop :=\n (β nβ nβ vβ, nβ + nβ β€ n β\n β envβ envβ, envβ β²β'(nβ + nβ) envβ β envβ β’ eβ β¦(nβ) vβ β β vβ, envβ β’ eβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ)"
},
{
"name": "infixr:50 \" β· \" => cons_value",
"content": "infixr:50 \" β· \" => cons_value"
},
{
"name": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Inde",
"content": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Indexed n v v'"
},
{
"name": "notation:40 e:40 \" β²(\" n:40 \")β¨\" env:40 \", \" env':40 \"β© \" e'",
"content": "notation:40 e:40 \" β²(\" n:40 \")β¨\" env:40 \", \" env':40 \"β© \" e':40 => Expr.Approx.Param.Indexed n env env' e e'"
},
{
"name": "notation:40 v:40 \" β²β'(\" n:40 \") \" v':40 => Object.Approx.In",
"content": "notation:40 v:40 \" β²β'(\" n:40 \") \" v':40 => Object.Approx.Indexed' n v v'"
},
{
"name": "notation:40 envβ:40 \" β²β'(\" n:40 \") \" envβ:40 => Env.Approx.",
"content": "notation:40 envβ:40 \" β²β'(\" n:40 \") \" envβ:40 => Env.Approx.Indexed' n envβ envβ"
},
{
"name": "notation:40 e:40 \" β²'(\" n:40 \") \" e':40 => Expr.Approx.Index",
"content": "notation:40 e:40 \" β²'(\" n:40 \") \" e':40 => Expr.Approx.Indexed' n e e'"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Inde",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Indexed n env e v"
},
{
"name": "infixl:100 \" @@ \" => Expr.app",
"content": "infixl:100 \" @@ \" => Expr.app"
}
] | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "Eval.Indexed.toEval",
"content": "lemma Eval.Indexed.toEval {n env e v} (h : env β’ e β¦(n) v) : env β’ e β¦ v"
},
{
"name": "Value.Approx.Indexed.preserved",
"content": "theorem Value.Approx.Indexed.preserved :\n β m n env env' e v,\n env β²β'(m + n) env' β\n env β’ e β¦(n) v β\n β v', env' β’ e β¦ v' β§ v β²α΅₯(m) v'"
},
{
"name": "Value.Approx.Indexed.preserved'",
"content": "lemma Value.Approx.Indexed.preserved' {k} : Preservation k"
},
{
"name": "Env.Approx.Indexed'.refl",
"content": "@[refl]\nlemma Env.Approx.Indexed'.refl {n env} : env β²β'(n) env"
},
{
"name": "Value.Approx.Indexed.refl",
"content": "@[refl]\nlemma Value.Approx.Indexed.refl {n} v : v β²α΅₯(n) v"
},
{
"name": "Object.Approx.Indexed'.refl'",
"content": "lemma Object.Approx.Indexed'.refl' {n o} (h : β v, v β²α΅₯(n) v) : o β²β'(n) o"
},
{
"name": "Env.Approx.Indexed'.refl'",
"content": "lemma Env.Approx.Indexed'.refl' {n env} (h : β v, v β²α΅₯(n) v) : env β²β'(n) env"
},
{
"name": "Value.Approx.Indexed.constr_app",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.constr_app {n ctr_name args_rev args_rev'} :\n (β k < n, args_rev β²β(k) args_rev') β\n Value.constr_app ctr_name args_rev β²α΅₯(n) Value.constr_app ctr_name args_rev'"
},
{
"name": "Value.Approx.Indexed.unit",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.unit {n} : Value.unit β²α΅₯(n) Value.unit"
},
{
"name": "Value.Approx.Indexed.const",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.const {n c} : Value.const c β²α΅₯(n) Value.const c"
},
{
"name": "Value.Approx.Indexed.closure",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.closure {n envβ bodyβ envβ bodyβ} :\n (β nβ nβ, nβ + nβ < n β\n β aβ aβ vβ,\n aβ β²α΅₯(nβ + nβ) aβ β\n aβ β· envβ β’ bodyβ β¦(nβ) vβ β\n β vβ, aβ β· envβ β’ bodyβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ) β\n Value.closure envβ bodyβ β²α΅₯(n) Value.closure envβ bodyβ"
},
{
"name": "Object.Approx.Indexed'.refl",
"content": "@[refl]\nlemma Object.Approx.Indexed'.refl {n o} : o β²β'(n) o"
},
{
"name": "Value.Approx.Indexed.preserved_step",
"content": "lemma Value.Approx.Indexed.preserved_step {k} :\n (β k' < k, Preservation k') β Preservation k"
},
{
"name": "Expr.Approx.Param.Indexed.anti_monotone",
"content": "lemma Expr.Approx.Param.Indexed.anti_monotone {n n' envβ envβ eβ eβ}\n (h : eβ β²(n)β¨envβ, envββ© eβ)\n (h' : n' β€ n)\n : eβ β²(n')β¨envβ, envββ© eβ"
},
{
"name": "Expr.Approx.Indexed'.anti_monotone",
"content": "lemma Expr.Approx.Indexed'.anti_monotone {n n' eβ eβ}\n (h : eβ β²'(n) eβ)\n (h' : n' β€ n)\n : eβ β²'(n') eβ"
},
{
"name": "Env.Approx.Indexed'.delayed",
"content": "lemma Env.Approx.Indexed'.delayed {n i : Nat} {envβ envβ env e}\n (hβ : envβ β²β'(n) envβ)\n (hβ : envβ[i]? = some (Object.delayed env e)) :\n (β env' e', e β²(n)β¨env, env'β© e' β§ envβ[i]? = some (Object.delayed env' e')) β¨\n β env', env β²β'(n) env' β§ envβ[i]? = some (Object.delayed env' e)"
},
{
"name": "Env.Approx.Indexed'.value",
"content": "lemma Env.Approx.Indexed'.value {n i : Nat} {env env' v}\n (hβ : env β²β'(n) env')\n (hβ : env[i]? = some (Object.value v)) :\n β v', env'[i]? = some (Object.value v') β§ v β²α΅₯(n) v'"
},
{
"name": "Env.Approx.Indexed'.get",
"content": "lemma Env.Approx.Indexed'.get {n i : Nat} {env env' oβ}\n (hβ : env β²β'(n) env')\n (hβ : env[i]? = some oβ) :\n β oβ, env'[i]? = some oβ β§ oβ β²β'(n) oβ"
},
{
"name": "Value.Approx.Indexed.anti_monotone",
"content": "lemma Value.Approx.Indexed.anti_monotone {n n' vβ vβ} (h : vβ β²α΅₯(n) vβ) (h' : n' β€ n) : vβ β²α΅₯(n') vβ"
},
{
"name": "Value.Approx.Indexed.Preservation.anti_monotone",
"content": "lemma Value.Approx.Indexed.Preservation.anti_monotone {k k'} (h : Value.Approx.Indexed.Preservation k) (h' : k' β€ k) : Value.Approx.Indexed.Preservation k'"
},
{
"name": "Env.Approx.Indexed'.anti_monotone",
"content": "lemma Env.Approx.Indexed'.anti_monotone {n n' envβ envβ}\n (h : envβ β²β'(n) envβ)\n (h' : n' β€ n)\n : envβ β²β'(n') envβ"
},
{
"name": "Object.Approx.Indexed'.anti_monotone",
"content": "lemma Object.Approx.Indexed'.anti_monotone {n n' oβ oβ} (h : oβ β²β'(n) oβ) (h' : n' β€ n) : oβ β²β'(n') oβ"
},
{
"name": "Env.Approx.Indexed'.cons",
"content": "lemma Env.Approx.Indexed'.cons {n oβ oβ envβ envβ}\n (hβ : oβ β²β'(n) oβ)\n (hβ : envβ β²β'(n) envβ) :\n oβ :: envβ β²β'(n) oβ :: envβ"
},
{
"name": "Env.Approx.Indexed'.concat",
"content": "lemma Env.Approx.Indexed'.concat {n envβ envβ envβ' envβ'}\n (hβ : envβ β²β'(n) envβ')\n (hβ : envβ β²β'(n) envβ') :\n envβ ++ envβ β²β'(n) envβ' ++ envβ'"
},
{
"name": "Env.Approx.Indexed'.from_value",
"content": "lemma Env.Approx.Indexed'.from_value {n lβ lβ} (h : lβ β²β(n) lβ) :\n List.map Object.value lβ β²β'(n) List.map Object.value lβ"
},
{
"name": "Eval.deterministic",
"content": "theorem Eval.deterministic {env e vβ vβ} (hβ : env β’ e β¦ vβ) (hβ : env β’ e β¦ vβ) : vβ = vβ"
},
{
"name": "Eval.toIndexed",
"content": "lemma Eval.toIndexed {env e v} (h : env β’ e β¦ v) : β n, env β’ e β¦(n) v"
},
{
"name": "Eval.Indexed.monotone",
"content": "lemma Eval.Indexed.monotone {n n' env e v} (h : env β’ e β¦(n) v) (h' : n β€ n') : env β’ e β¦(n') v"
}
] | [
{
"name": "Juvix.Core.Main.Value.Approx",
"content": "def Value.Approx (v v' : Value) : Prop :=\n β n, v β²α΅₯(n) v'"
},
{
"name": "Juvix.Core.Main.Expr.Approx.Param",
"content": "def Expr.Approx.Param (envβ envβ : Env) (eβ eβ : Expr) : Prop :=\n (β vβ, envβ β’ eβ β¦ vβ β β vβ, envβ β’ eβ β¦ vβ β§ vβ β²α΅₯ vβ)"
},
{
"name": "Juvix.Core.Main.Object.Approx",
"content": "inductive Object.Approx : Object β Object β Prop where\n | value {vβ vβ} : vβ β²α΅₯ vβ β Object.Approx (Object.value vβ) (Object.value vβ)\n | delayed {envβ envβ eβ eβ} :\n eβ β²β¨envβ, envββ© eβ β\n Object.Approx (Object.delayed envβ eβ) (Object.delayed envβ eβ)"
},
{
"name": "Juvix.Core.Main.Env.Approx",
"content": "def Env.Approx : (envβ envβ : Env) β Prop :=\n List.Forallβ Object.Approx"
},
{
"name": "Juvix.Core.Main.Expr.Approx",
"content": "def Expr.Approx (eβ eβ : Expr) : Prop :=\n β envβ envβ, envβ β²β envβ β eβ β²β¨envβ, envββ© eβ"
}
] | [
{
"name": "Juvix.Core.Main.Env.Approx.cons",
"content": "lemma Env.Approx.cons {envβ envβ oβ oβ} :\n oβ β²β oβ β envβ β²β envβ β (oβ :: envβ) β²β (oβ :: envβ)"
},
{
"name": "Juvix.Core.Main.Object.Approx.toIndexed",
"content": "lemma Object.Approx.toIndexed {oβ oβ} : oβ β²β oβ β β n, oβ β²β'(n) oβ"
},
{
"name": "Juvix.Core.Main.Env.Approx.toIndexed",
"content": "lemma Env.Approx.toIndexed {envβ envβ} : envβ β²β envβ β β n, envβ β²β'(n) envβ"
}
] | import Juvix.Core.Main.Semantics.Approx.Indexed
namespace Juvix.Core.Main
def Value.Approx (v v' : Value) : Prop :=
β n, v β²α΅₯(n) v'
notation:40 v:40 " β²α΅₯ " v':40 => Value.Approx v v'
notation:40 argsβ:40 " β²β " argsβ:40 => List.Forallβ Value.Approx argsβ argsβ
def Expr.Approx.Param (envβ envβ : Env) (eβ eβ : Expr) : Prop :=
(β vβ, envβ β’ eβ β¦ vβ β β vβ, envβ β’ eβ β¦ vβ β§ vβ β²α΅₯ vβ)
notation:40 e:40 " β²β¨" env:40 ", " env':40 "β© " e':40 => Expr.Approx.Param env env' e e'
inductive Object.Approx : Object β Object β Prop where
| value {vβ vβ} : vβ β²α΅₯ vβ β Object.Approx (Object.value vβ) (Object.value vβ)
| delayed {envβ envβ eβ eβ} :
eβ β²β¨envβ, envββ© eβ β
Object.Approx (Object.delayed envβ eβ) (Object.delayed envβ eβ)
def Env.Approx : (envβ envβ : Env) β Prop :=
List.Forallβ Object.Approx
notation:40 v:40 " β²β " v':40 => Object.Approx v v'
notation:40 envβ:40 " β²β " envβ:40 => Env.Approx envβ envβ
def Expr.Approx (eβ eβ : Expr) : Prop :=
β envβ envβ, envβ β²β envβ β eβ β²β¨envβ, envββ© eβ
notation:40 eβ:40 " β² " eβ:40 => Expr.Approx eβ eβ | theorem Value.Approx.preserved :
β env env' e v,
env β²β env' β
env β’ e β¦ v β
β v', env' β’ e β¦ v' β§ v β²α΅₯ v' := | := by
intro env env' e v hβ hβ
suffices β n, β v', env' β’ e β¦ v' β§ v β²α΅₯(n) v' by
obtain β¨v', heval', happrox'β© := this 0
exists v'
constructor
Β· assumption
Β· intro n
obtain β¨v'', heval'', happrox''β© := this n
have : v' = v'' := by
apply Eval.deterministic <;> assumption
subst this
exact happrox''
intro m
obtain β¨n, hβ'β© := Eval.toIndexed hβ
have hβ' : env β²β'(m + n) env' := by
apply Env.Approx.toIndexed
assumption
obtain β¨v', heval', happrox'β© := Value.Approx.Indexed.preserved (env := env) (env' := env') m n e v hβ' hβ'
aesop | 4 | 66 | false | Semantics |
256 | Juvix.Core.Main.Env.Approx.Indexed'.delayed | lemma Env.Approx.Indexed'.delayed {n i : Nat} {envβ envβ env e}
(hβ : envβ β²β'(n) envβ)
(hβ : envβ[i]? = some (Object.delayed env e)) :
(β env' e', e β²(n)β¨env, env'β© e' β§ envβ[i]? = some (Object.delayed env' e')) β¨
β env', env β²β'(n) env' β§ envβ[i]? = some (Object.delayed env' e) | juvix-lean | Juvix/Core/Main/Semantics/Approx/Indexed.lean | [
"import Juvix.Utils",
"import Juvix.Core.Main.Semantics.Eval.Indexed",
"import Mathlib.Tactic.Linarith",
"import Mathlib.Data.List.Forall2",
"import Juvix.Core.Main.Semantics.Eval",
"import Aesop"
] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "List.Forallβ",
"module": "Batteries.Data.List.Basic"
}
] | [
{
"name": "notation:40 e:40 \" β²(\" n:40 \")β¨\" env:40 \", \" env':40 \"β© \" e'",
"content": "notation:40 e:40 \" β²(\" n:40 \")β¨\" env:40 \", \" env':40 \"β© \" e':40 => Expr.Approx.Param.Indexed n env env' e e'"
},
{
"name": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Inde",
"content": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Indexed n v v'"
},
{
"name": "notation:40 v:40 \" β²β'(\" n:40 \") \" v':40 => Object.Approx.In",
"content": "notation:40 v:40 \" β²β'(\" n:40 \") \" v':40 => Object.Approx.Indexed' n v v'"
},
{
"name": "notation:40 envβ:40 \" β²β'(\" n:40 \") \" envβ:40 => Env.Approx.",
"content": "notation:40 envβ:40 \" β²β'(\" n:40 \") \" envβ:40 => Env.Approx.Indexed' n envβ envβ\n\nsyntax \"case \" expr \" of \" cases \" end\" : expr"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(βͺ$s:ident β― $i:numβ«) => `(Expr.var $(Lean.Syntax.mkStrLit s.getId.toString) $i)\n | `(βͺ$num:numβ«) => `(Expr.const (Constant.int $num))\n | `(βͺ$s:strβ«) => `(Expr.const (Constant.string $s))\n | `(βͺΟ
β«) => `(Expr.unit)\n | `(βͺ$eβ:expr $eβ:exprβ«) => `(Expr.app βͺ$eββ« βͺ$eββ«)\n | `(βͺΞ» $s:ident $e:exprβ«) => `(Expr.lambda $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eβ«)\n | `(βͺΞ» $ss:ident* . $e:exprβ«) => mkLambdas ss e\n | `(βͺ $s:ident β«) => `(Expr.constr $(Lean.Syntax.mkStrLit s.getId.toString))\n | `(βͺ $s:ident $es:expr* β«) => mkConstrApp s es\n | `(βͺ$eβ + $eββ«) => `(Expr.binop BinaryOp.add_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ - $eββ«) => `(Expr.binop BinaryOp.sub_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ * $eββ«) => `(Expr.binop BinaryOp.mul_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ / $eββ«) => `(Expr.binop BinaryOp.div_int βͺ$eββ« βͺ$eββ«)\n | `(βͺlet $s:ident := $eβ:expr in $eβ:exprβ«) => `(Expr.save $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eββ« βͺ$eββ«)\n | `(βͺletrec $s:ident := $eβ:expr in $eβ:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.save $name (Expr.recur $name βͺ$eββ«) βͺ$eββ«)\n | `(βͺrec $s:ident $e:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.recur $name βͺ$eβ«)\n | `(βͺβ₯β«) => `(Expr.fail)\n | `(βͺcases| | $s:ident => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« Expr.fail)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« Expr.fail)\n | `(βͺcases| | _ => $e:expr β«) =>\n `(βͺ$eβ«)\n | `(βͺcase $e:expr of $cs:cases endβ«) => do\n `(Expr.save \"_case_\" βͺ$eβ« βͺcases|$csβ«)\n | `(βͺ($e)β«) => `(βͺ$eβ«)\n\n inductive Object : Type where\n | value : Value β Object\n | delayed : (env : List Object) β Expr β Object\n deriving Inhabited"
},
{
"name": "Object.Approx",
"content": "inductive Object.Approx : Object β Object β Prop where\n | value {vβ vβ} : vβ β²α΅₯ vβ β Object.Approx (Object.value vβ) (Object.value vβ)\n | delayed {envβ envβ eβ eβ} :\n eβ β²β¨envβ, envββ© eβ β\n Object.Approx (Object.delayed envβ eβ) (Object.delayed envβ eβ)"
},
{
"name": "Env.Approx",
"content": "def Env.Approx : (envβ envβ : Env) β Prop :=\n List.Forallβ Object.Approx"
},
{
"name": "BinaryOp",
"content": "inductive BinaryOp : Type where\n | add_int : BinaryOp\n | sub_int : BinaryOp\n | mul_int : BinaryOp\n | div_int : BinaryOp\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Expr",
"content": "inductive Expr : Type where\n | var : (name : String) β (index : Nat) β Expr\n | unit : Expr\n | const : Constant β Expr\n | constr : Name β Expr\n | app : Expr β Expr β Expr\n | constr_app : Expr β Expr β Expr\n | binop : (oper : BinaryOp) β (argβ argβ : Expr) β Expr\n | lambda : (var_name : String) β (body : Expr) β Expr\n | save : (var_name : String) β (value : Expr) β (body : Expr) β Expr\n | branch : (constr : Name) β (var_names : List Name) β (body : Expr) β (next : Expr) β Expr\n | recur : (var_name : Name) β (body : Expr) β Expr\n | fail : Expr\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Constant",
"content": "inductive Constant : Type where\n | int : Int β Constant\n | string : String β Constant\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "notation:40 v:40 \" β²β \" v':40 => Object.Approx v v'",
"content": "notation:40 v:40 \" β²β \" v':40 => Object.Approx v v'"
},
{
"name": "notation:40 envβ:40 \" β²β \" envβ:40 => Env.Approx envβ envβ",
"content": "notation:40 envβ:40 \" β²β \" envβ:40 => Env.Approx envβ envβ"
},
{
"name": "infixl:100 \" @@ \" => Expr.app",
"content": "infixl:100 \" @@ \" => Expr.app"
}
] | [
{
"name": "List.Forallβ.get",
"module": "Mathlib.Data.List.Forall2"
},
{
"name": "List.Forallβ.length_eq",
"module": "Mathlib.Data.List.Forall2"
},
{
"name": "List.getElem?_eq_some_iff",
"module": "Init.Data.List.Lemmas"
},
{
"name": "List.get_eq_getElem",
"module": "Init.Data.List.Lemmas"
},
{
"name": "forall_true_left",
"module": "Mathlib.Logic.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": "Juvix.Core.Main.Object.Approx.Indexed'",
"content": "inductive Object.Approx.Indexed' (n : Nat) : Object β Object β Prop where\n | value {vβ vβ} :\n vβ β²α΅₯(n) vβ β\n Object.Approx.Indexed' n (Object.value vβ) (Object.value vβ)\n | delayed {envβ envβ eβ eβ} :\n eβ β²(n)β¨envβ, envββ© eβ β\n Object.Approx.Indexed' n (Object.delayed envβ eβ) (Object.delayed envβ eβ)\n | delayed_eq {envβ envβ e} :\n List.Forallβ (Object.Approx.Indexed' n) envβ envβ β\n Object.Approx.Indexed' n (Object.delayed envβ e) (Object.delayed envβ e)"
},
{
"name": "Juvix.Core.Main.Env.Approx.Indexed'",
"content": "def Env.Approx.Indexed' (n : Nat) : (envβ envβ : Env) β Prop :=\n List.Forallβ (Object.Approx.Indexed' n)"
}
] | [
{
"name": "Juvix.Core.Main.Env.Approx.Indexed'.get",
"content": "lemma Env.Approx.Indexed'.get {n i : Nat} {env env' oβ}\n (hβ : env β²β'(n) env')\n (hβ : env[i]? = some oβ) :\n β oβ, env'[i]? = some oβ β§ oβ β²β'(n) oβ"
},
{
"name": "Juvix.Core.Main.Env.Approx.Indexed'.value",
"content": "lemma Env.Approx.Indexed'.value {n i : Nat} {env env' v}\n (hβ : env β²β'(n) env')\n (hβ : env[i]? = some (Object.value v)) :\n β v', env'[i]? = some (Object.value v') β§ v β²α΅₯(n) v'"
}
] | import Juvix.Core.Main.Semantics.Eval
import Juvix.Core.Main.Semantics.Eval.Indexed
import Juvix.Utils
import Mathlib.Tactic.Linarith
import Mathlib.Data.List.Forall2
import Aesop
namespace Juvix.Core.Main
notation:40 v:40 " β²α΅₯(" n:40 ") " v':40 => Value.Approx.Indexed n v v'
notation:40 argsβ:40 " β²β(" n:40 ") " argsβ:40 => List.Forallβ (Value.Approx.Indexed n) argsβ argsβ
notation:40 e:40 " β²(" n:40 ")β¨" env:40 ", " env':40 "β© " e':40 => Expr.Approx.Param.Indexed n env env' e e'
inductive Object.Approx.Indexed' (n : Nat) : Object β Object β Prop where
| value {vβ vβ} :
vβ β²α΅₯(n) vβ β
Object.Approx.Indexed' n (Object.value vβ) (Object.value vβ)
| delayed {envβ envβ eβ eβ} :
eβ β²(n)β¨envβ, envββ© eβ β
Object.Approx.Indexed' n (Object.delayed envβ eβ) (Object.delayed envβ eβ)
| delayed_eq {envβ envβ e} :
List.Forallβ (Object.Approx.Indexed' n) envβ envβ β
Object.Approx.Indexed' n (Object.delayed envβ e) (Object.delayed envβ e)
def Env.Approx.Indexed' (n : Nat) : (envβ envβ : Env) β Prop :=
List.Forallβ (Object.Approx.Indexed' n)
notation:40 v:40 " β²β'(" n:40 ") " v':40 => Object.Approx.Indexed' n v v'
notation:40 envβ:40 " β²β'(" n:40 ") " envβ:40 => Env.Approx.Indexed' n envβ envβ
notation:40 e:40 " β²'(" n:40 ") " e':40 => Expr.Approx.Indexed' n e e' | lemma Env.Approx.Indexed'.delayed {n i : Nat} {envβ envβ env e}
(hβ : envβ β²β'(n) envβ)
(hβ : envβ[i]? = some (Object.delayed env e)) :
(β env' e', e β²(n)β¨env, env'β© e' β§ envβ[i]? = some (Object.delayed env' e')) β¨
β env', env β²β'(n) env' β§ envβ[i]? = some (Object.delayed env' e) := | := by
obtain β¨o, h, happroxβ© := Env.Approx.Indexed'.get hβ hβ
cases hβ : o
case value v =>
rw [hβ] at happrox
contradiction
case delayed env' e' =>
rw [hβ] at happrox
cases happrox
case delayed h =>
left
subst hβ
exists env'
exists e'
case delayed_eq =>
right
subst hβ
exists env' | 3 | 15 | false | Semantics |
257 | Juvix.Core.Main.Value.Approx.Indexed.preserved' | lemma Value.Approx.Indexed.preserved' {k} : Preservation k | juvix-lean | Juvix/Core/Main/Semantics/Approx/Indexed.lean | [
"import Juvix.Utils",
"import Juvix.Core.Main.Semantics.Eval.Indexed",
"import Mathlib.Tactic.Linarith",
"import Mathlib.Data.List.Forall2",
"import Juvix.Core.Main.Semantics.Eval",
"import Aesop"
] | [
{
"name": "BEq",
"module": "Init.Prelude"
},
{
"name": "DecidableEq",
"module": "Init.Prelude"
},
{
"name": "Inhabited",
"module": "Init.Prelude"
},
{
"name": "Int",
"module": "Init.Data.Int.Basic"
},
{
"name": "String",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "closure",
"module": "Mathlib.Topology.Defs.Basic"
},
{
"name": "List.Forallβ",
"module": "Batteries.Data.List.Basic"
},
{
"name": "List.Forallβ.cons",
"module": "Batteries.Data.List.Basic"
},
{
"name": "List.Forallβ.nil",
"module": "Batteries.Data.List.Basic"
},
{
"name": "List.cons",
"module": "Init.Prelude"
},
{
"name": "List.nil",
"module": "Init.Prelude"
},
{
"name": "Prod",
"module": "Init.Prelude"
},
{
"name": "reduceCtorEq",
"module": "Lean.Meta.Tactic.Simp.BuiltinSimprocs.Core"
},
{
"name": "List.map",
"module": "Init.Prelude"
}
] | [
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β\" => Eval.Defined env e",
"content": "notation:40 env:40 \" β’ \" e:40 \" β\" => Eval.Defined env e"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Inde",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Indexed n env e v"
},
{
"name": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Inde",
"content": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Indexed n v v'"
},
{
"name": "notation:40 envβ:40 \" β²β'(\" n:40 \") \" envβ:40 => Env.Approx.",
"content": "notation:40 envβ:40 \" β²β'(\" n:40 \") \" envβ:40 => Env.Approx.Indexed' n envβ envβ"
},
{
"name": "notation:40 e:40 \" β²(\" n:40 \")β¨\" env:40 \", \" env':40 \"β© \" e'",
"content": "notation:40 e:40 \" β²(\" n:40 \")β¨\" env:40 \", \" env':40 \"β© \" e':40 => Expr.Approx.Param.Indexed n env env' e e'\n\nsyntax \"case \" expr \" of \" cases \" end\" : expr"
},
{
"name": "notation:40 v:40 \" β²β'(\" n:40 \") \" v':40 => Object.Approx.In",
"content": "notation:40 v:40 \" β²β'(\" n:40 \") \" v':40 => Object.Approx.Indexed' n v v'"
},
{
"name": "notation:40 argsβ:40 \" β²β(\" n:40 \") \" argsβ:40 => List.Foral",
"content": "notation:40 argsβ:40 \" β²β(\" n:40 \") \" argsβ:40 => List.Forallβ (Value.Approx.Indexed n) argsβ argsβ\n\nsyntax:100 expr:100 ppSpace expr:101 : expr\n\nsyntax:50 expr:50 \" + \" expr:51 : expr\n\nsyntax:50 expr:50 \" - \" expr:50 : expr\n\nsyntax:60 expr:60 \" * \" expr:61 : expr\n\nsyntax:60 expr:60 \" / \" expr:60 : expr"
},
{
"name": "notation:40 e:40 \" β²'(\" n:40 \") \" e':40 => Expr.Approx.Index",
"content": "notation:40 e:40 \" β²'(\" n:40 \") \" e':40 => Expr.Approx.Indexed' n e e'"
},
{
"name": "macro \"invert\" h:term : tactic => `(tactic| (cases ($h).inve",
"content": "macro \"invert\" h:term : tactic => `(tactic| (cases ($h).invert <;> try clear $h))\n\nsyntax \"let \" ident \" := \" expr \" in \" expr : expr"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(βͺ$s:ident β― $i:numβ«) => `(Expr.var $(Lean.Syntax.mkStrLit s.getId.toString) $i)\n | `(βͺ$num:numβ«) => `(Expr.const (Constant.int $num))\n | `(βͺ$s:strβ«) => `(Expr.const (Constant.string $s))\n | `(βͺΟ
β«) => `(Expr.unit)\n | `(βͺ$eβ:expr $eβ:exprβ«) => `(Expr.app βͺ$eββ« βͺ$eββ«)\n | `(βͺΞ» $s:ident $e:exprβ«) => `(Expr.lambda $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eβ«)\n | `(βͺΞ» $ss:ident* . $e:exprβ«) => mkLambdas ss e\n | `(βͺ $s:ident β«) => `(Expr.constr $(Lean.Syntax.mkStrLit s.getId.toString))\n | `(βͺ $s:ident $es:expr* β«) => mkConstrApp s es\n | `(βͺ$eβ + $eββ«) => `(Expr.binop BinaryOp.add_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ - $eββ«) => `(Expr.binop BinaryOp.sub_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ * $eββ«) => `(Expr.binop BinaryOp.mul_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ / $eββ«) => `(Expr.binop BinaryOp.div_int βͺ$eββ« βͺ$eββ«)\n | `(βͺlet $s:ident := $eβ:expr in $eβ:exprβ«) => `(Expr.save $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eββ« βͺ$eββ«)\n | `(βͺletrec $s:ident := $eβ:expr in $eβ:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.save $name (Expr.recur $name βͺ$eββ«) βͺ$eββ«)\n | `(βͺrec $s:ident $e:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.recur $name βͺ$eβ«)\n | `(βͺβ₯β«) => `(Expr.fail)\n | `(βͺcases| | $s:ident => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« Expr.fail)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« Expr.fail)\n | `(βͺcases| | _ => $e:expr β«) =>\n `(βͺ$eβ«)\n | `(βͺcase $e:expr of $cs:cases endβ«) => do\n `(Expr.save \"_case_\" βͺ$eβ« βͺcases|$csβ«)\n | `(βͺ($e)β«) => `(βͺ$eβ«)\n\n inductive Value : Type where\n | unit : Value\n | const : Constant β Value\n | constr_app : (constr : Name) β (args_rev : List Value) β Value\n | closure : (env : List Object) β (value : Expr) β Value\n deriving Inhabited"
},
{
"name": "cons_value",
"content": "abbrev cons_value (v : Value) (env : Env) : Env := Object.value v :: env\n\n inductive Object : Type where\n | value : Value β Object\n | delayed : (env : List Object) β Expr β Object\n deriving Inhabited"
},
{
"name": "Expr",
"content": "inductive Expr : Type where\n | var : (name : String) β (index : Nat) β Expr\n | unit : Expr\n | const : Constant β Expr\n | constr : Name β Expr\n | app : Expr β Expr β Expr\n | constr_app : Expr β Expr β Expr\n | binop : (oper : BinaryOp) β (argβ argβ : Expr) β Expr\n | lambda : (var_name : String) β (body : Expr) β Expr\n | save : (var_name : String) β (value : Expr) β (body : Expr) β Expr\n | branch : (constr : Name) β (var_names : List Name) β (body : Expr) β (next : Expr) β Expr\n | recur : (var_name : Name) β (body : Expr) β Expr\n | fail : Expr\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "BinaryOp",
"content": "inductive BinaryOp : Type where\n | add_int : BinaryOp\n | sub_int : BinaryOp\n | mul_int : BinaryOp\n | div_int : BinaryOp\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Constant",
"content": "inductive Constant : Type where\n | int : Int β Constant\n | string : String β Constant\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Name",
"content": "abbrev Name : Type := String"
},
{
"name": "Env",
"content": "abbrev Env : Type := List Object"
},
{
"name": "Value.Approx",
"content": "def Value.Approx (v v' : Value) : Prop :=\n β n, v β²α΅₯(n) v'"
},
{
"name": "Object.Approx",
"content": "inductive Object.Approx : Object β Object β Prop where\n | value {vβ vβ} : vβ β²α΅₯ vβ β Object.Approx (Object.value vβ) (Object.value vβ)\n | delayed {envβ envβ eβ eβ} :\n eβ β²β¨envβ, envββ© eβ β\n Object.Approx (Object.delayed envβ eβ) (Object.delayed envβ eβ)"
},
{
"name": "Env.Approx",
"content": "def Env.Approx : (envβ envβ : Env) β Prop :=\n List.Forallβ Object.Approx"
},
{
"name": "Expr.Approx",
"content": "def Expr.Approx (eβ eβ : Expr) : Prop :=\n β envβ envβ, envβ β²β envβ β eβ β²β¨envβ, envββ© eβ"
},
{
"name": "Expr.Approx.Param",
"content": "def Expr.Approx.Param (envβ envβ : Env) (eβ eβ : Expr) : Prop :=\n (β vβ, envβ β’ eβ β¦ vβ β β vβ, envβ β’ eβ β¦ vβ β§ vβ β²α΅₯ vβ)"
},
{
"name": "Eval.Indexed",
"content": "inductive Eval.Indexed : Nat β Env β Expr β Value β Prop where\n | var {n env name idx val} :\n env[idx]? = some (Object.value val) β\n Eval.Indexed n env (Expr.var name idx) val\n | var_rec {n env name idx env' expr val} :\n env[idx]? = some (Object.delayed env' expr) β\n Eval.Indexed n env' expr val β\n Eval.Indexed n env (Expr.var name idx) val\n | unit {n env} :\n Eval.Indexed n env Expr.unit Value.unit\n | const {n env c} :\n Eval.Indexed n env (Expr.const c) (Value.const c)\n | constr {n env name} :\n Eval.Indexed n env (Expr.constr name) (Value.constr_app name [])\n | app {n nβ nβ env env' f body arg val val'} :\n nβ + nβ + 1 β€ n β\n Eval.Indexed nβ env f (Value.closure env' body) β\n Eval.Indexed (nβ + 1) env arg val β\n Eval.Indexed nβ (val β· env') body val' β\n Eval.Indexed n env (Expr.app f arg) val'\n | constr_app {n n' env ctr ctr_name ctr_args_rev arg val} :\n n' < n β\n Eval.Indexed n env ctr (Value.constr_app ctr_name ctr_args_rev) β\n Eval.Indexed n' env arg val β\n Eval.Indexed n env (Expr.constr_app ctr arg) (Value.constr_app ctr_name (val :: ctr_args_rev))\n | binop {n env op argβ argβ valβ valβ} :\n Eval.Indexed n env argβ (Value.const (Constant.int valβ)) β\n Eval.Indexed n env argβ (Value.const (Constant.int valβ)) β\n Eval.Indexed n env (Expr.binop op argβ argβ) (Value.const (Constant.int (eval_binop_int op valβ valβ)))\n | lambda {n env name body} :\n Eval.Indexed n env (Expr.lambda name body) (Value.closure env body)\n | save {n nβ nβ env name value body val val'} :\n nβ + nβ β€ n β\n Eval.Indexed nβ env value val β\n Eval.Indexed nβ (val β· env) body val' β\n Eval.Indexed n env (Expr.save name value body) val'\n | branch_matches {n n' env name args_rev body val} :\n n' < n β\n Eval.Indexed n' (args_rev.map Object.value ++ env) body val β\n Eval.Indexed n (Value.constr_app name args_rev β· env) (Expr.branch name _ body _) val\n | branch_fails {n env name name' args_rev next val} :\n name β name' β\n Eval.Indexed n (Value.constr_app name args_rev β· env) next val β\n Eval.Indexed n (Value.constr_app name args_rev β· env) (Expr.branch name' _ _ next) val\n | recur {n n' env name body val} :\n n' < n β\n Eval.Indexed n' (Object.delayed env (Expr.recur name body) :: env) body val β\n Eval.Indexed n env (Expr.recur name body) val"
},
{
"name": "Eval",
"content": "@[aesop unsafe constructors]\ninductive Eval : Env β Expr β Value β Prop where\n | var {env name idx val} :\n env[idx]? = some (Object.value val) β\n Eval env (Expr.var name idx) val\n | var_rec {env name idx env' expr val} :\n env[idx]? = some (Object.delayed env' expr) β\n Eval env' expr val β\n Eval env (Expr.var name idx) val\n | unit {env} :\n Eval env Expr.unit Value.unit\n | const {env c} :\n Eval env (Expr.const c) (Value.const c)\n | constr {env name} :\n Eval env (Expr.constr name) (Value.constr_app name [])\n | app {env env' f body arg val val'} :\n Eval env f (Value.closure env' body) β\n Eval env arg val β\n Eval (val β· env') body val' β\n Eval env (Expr.app f arg) val'\n | constr_app {env ctr ctr_name ctr_args_rev arg val} :\n Eval env ctr (Value.constr_app ctr_name ctr_args_rev) β\n Eval env arg val β\n Eval env (Expr.constr_app ctr arg) (Value.constr_app ctr_name (val :: ctr_args_rev))\n | binop {env op argβ argβ valβ valβ} :\n Eval env argβ (Value.const (Constant.int valβ)) β\n Eval env argβ (Value.const (Constant.int valβ)) β\n Eval env (Expr.binop op argβ argβ) (Value.const (Constant.int (eval_binop_int op valβ valβ)))\n | lambda {env name body} :\n Eval env (Expr.lambda name body) (Value.closure env body)\n | save {env name value body val val'} :\n Eval env value val β\n Eval (val β· env) body val' β\n Eval env (Expr.save name value body) val'\n | branch_matches {env name args_rev body val} :\n Eval (args_rev.map Object.value ++ env) body val β\n Eval (Value.constr_app name args_rev β· env) (Expr.branch name _ body _) val\n | branch_fails {env name name' args_rev next val} :\n name β name' β\n Eval (Value.constr_app name args_rev β· env) next val β\n Eval (Value.constr_app name args_rev β· env) (Expr.branch name' _ _ next) val\n | recur {env name body val} :\n Eval (Object.delayed env (Expr.recur name body) :: env) body val β\n Eval env (Expr.recur name body) val"
},
{
"name": "Context",
"content": "inductive Context : Type where\n | hole : Context\n | app_left : Context β Expr β Context\n | app_right : Expr β Context β Context\n | constr_app_left : Context β Expr β Context\n | constr_app_right : Expr β Context β Context\n | binop_left : (oper : BinaryOp) β (argβ : Context) β (argβ : Expr) β Context\n | binop_right : (oper : BinaryOp) β (argβ : Expr) β (argβ : Context) β Context\n | lambda : (var_name : String) β (body : Context) β Context\n | save_left : (var_name : String) β (value : Context) β (body : Expr) β Context\n | save_right : (var_name : String) β (value : Expr) β (body : Context) β Context\n | branch_left : (constr : Name) β (var_names : List Name) β (body : Context) β (next : Expr) β Context\n | branch_right : (constr : Name) β (var_names : List Name) β (body : Expr) β (next : Context) β Context\n | recur : (var_name : Name) β (ctx : Context) β Context\n deriving Inhabited, BEq"
},
{
"name": "eval_binop_int",
"content": "def eval_binop_int (op : BinaryOp) (iβ iβ : Int) : Int :=\n match op with\n | BinaryOp.add_int => iβ + iβ\n | BinaryOp.sub_int => iβ - iβ\n | BinaryOp.mul_int => iβ * iβ\n | BinaryOp.div_int => iβ / iβ"
},
{
"name": "infixr:50 \" β· \" => cons_value",
"content": "infixr:50 \" β· \" => cons_value"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Inde",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Indexed n env e v"
},
{
"name": "notation:40 v:40 \" β²α΅₯ \" v':40 => Value.Approx v v'",
"content": "notation:40 v:40 \" β²α΅₯ \" v':40 => Value.Approx v v'"
},
{
"name": "notation:40 e:40 \" β²β¨\" env:40 \", \" env':40 \"β© \" e':40 => Exp",
"content": "notation:40 e:40 \" β²β¨\" env:40 \", \" env':40 \"β© \" e':40 => Expr.Approx.Param env env' e e'"
},
{
"name": "notation:40 v:40 \" β²β \" v':40 => Object.Approx v v'",
"content": "notation:40 v:40 \" β²β \" v':40 => Object.Approx v v'"
},
{
"name": "notation:40 envβ:40 \" β²β \" envβ:40 => Env.Approx envβ envβ",
"content": "notation:40 envβ:40 \" β²β \" envβ:40 => Env.Approx envβ envβ"
},
{
"name": "notation:40 eβ:40 \" β² \" eβ:40 => Expr.Approx eβ eβ",
"content": "notation:40 eβ:40 \" β² \" eβ:40 => Expr.Approx eβ eβ"
},
{
"name": "infixl:100 \" @@ \" => Expr.app",
"content": "infixl:100 \" @@ \" => Expr.app"
}
] | [
{
"name": "and_self",
"module": "Init.SimpLemmas"
},
{
"name": "exists_and_left",
"module": "Init.PropLemmas"
},
{
"name": "exists_const",
"module": "Init.PropLemmas"
},
{
"name": "exists_eq_left'",
"module": "Init.PropLemmas"
},
{
"name": "false_and",
"module": "Init.SimpLemmas"
},
{
"name": "false_or",
"module": "Init.SimpLemmas"
},
{
"name": "implies_true",
"module": "Init.SimpLemmas"
},
{
"name": "or_false",
"module": "Init.SimpLemmas"
},
{
"name": "true_and",
"module": "Init.SimpLemmas"
},
{
"name": "List.forallβ_same",
"module": "Mathlib.Data.List.Forall2"
},
{
"name": "List.Forallβ.get",
"module": "Mathlib.Data.List.Forall2"
},
{
"name": "List.Forallβ.length_eq",
"module": "Mathlib.Data.List.Forall2"
},
{
"name": "List.getElem?_eq_some_iff",
"module": "Init.Data.List.Lemmas"
},
{
"name": "List.get_eq_getElem",
"module": "Init.Data.List.Lemmas"
},
{
"name": "forall_true_left",
"module": "Mathlib.Logic.Basic"
},
{
"name": "Nat.le_eq",
"module": "Init.Data.Nat.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": "Juvix.Core.Main.Value.Approx.Indexed",
"content": "def Value.Approx.Indexed (n : Nat) (vβ vβ : Value) : Prop :=\n (vβ = Value.unit β§ vβ = Value.unit) β¨\n (β c, vβ = Value.const c β§ vβ = Value.const c) β¨\n (β ctr_name args_rev args_rev',\n vβ = Value.constr_app ctr_name args_rev β§\n vβ = Value.constr_app ctr_name args_rev' β§\n (β k < n, List.Forallβ (Value.Approx.Indexed k) args_rev args_rev')) β¨\n (β envβ bodyβ envβ bodyβ,\n vβ = Value.closure envβ bodyβ β§\n vβ = Value.closure envβ bodyβ β§\n (β nβ nβ, nβ + nβ < n β\n β aβ aβ rβ,\n Value.Approx.Indexed (nβ + nβ) aβ aβ β\n aβ β· envβ β’ bodyβ β¦(nβ) rβ β\n β rβ,\n aβ β· envβ β’ bodyβ β¦ rβ β§\n Value.Approx.Indexed nβ rβ rβ))"
},
{
"name": "Juvix.Core.Main.Expr.Approx.Param.Indexed",
"content": "def Expr.Approx.Param.Indexed (n : Nat) (envβ envβ : Env) (eβ eβ : Expr) : Prop :=\n (β nβ nβ vβ, nβ + nβ β€ n β envβ β’ eβ β¦(nβ) vβ β β vβ, envβ β’ eβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ)"
},
{
"name": "Juvix.Core.Main.Object.Approx.Indexed'",
"content": "inductive Object.Approx.Indexed' (n : Nat) : Object β Object β Prop where\n | value {vβ vβ} :\n vβ β²α΅₯(n) vβ β\n Object.Approx.Indexed' n (Object.value vβ) (Object.value vβ)\n | delayed {envβ envβ eβ eβ} :\n eβ β²(n)β¨envβ, envββ© eβ β\n Object.Approx.Indexed' n (Object.delayed envβ eβ) (Object.delayed envβ eβ)\n | delayed_eq {envβ envβ e} :\n List.Forallβ (Object.Approx.Indexed' n) envβ envβ β\n Object.Approx.Indexed' n (Object.delayed envβ e) (Object.delayed envβ e)"
},
{
"name": "Juvix.Core.Main.Env.Approx.Indexed'",
"content": "def Env.Approx.Indexed' (n : Nat) : (envβ envβ : Env) β Prop :=\n List.Forallβ (Object.Approx.Indexed' n)"
},
{
"name": "Juvix.Core.Main.Expr.Approx.Indexed'",
"content": "def Expr.Approx.Indexed' (n : Nat) (eβ eβ : Expr) : Prop :=\n (β nβ nβ vβ, nβ + nβ β€ n β\n β envβ envβ, envβ β²β'(nβ + nβ) envβ β envβ β’ eβ β¦(nβ) vβ β β vβ, envβ β’ eβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ)"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.Inversion",
"content": "@[aesop safe cases]\ninductive Value.Approx.Indexed.Inversion (n : Nat) : Value β Value β Prop where\n | unit : Value.Approx.Indexed.Inversion n Value.unit Value.unit\n | const {c} : Value.Approx.Indexed.Inversion n (Value.const c) (Value.const c)\n | constr_app {ctr_name args_rev args_rev'} :\n (β k < n, args_rev β²β(k) args_rev') β\n Value.Approx.Indexed.Inversion n (Value.constr_app ctr_name args_rev) (Value.constr_app ctr_name args_rev')\n | closure {envβ bodyβ envβ bodyβ} :\n (β nβ nβ, nβ + nβ < n β\n β aβ aβ vβ,\n aβ β²α΅₯(nβ + nβ) aβ β\n aβ β· envβ β’ bodyβ β¦(nβ) vβ β\n β vβ, aβ β· envβ β’ bodyβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ) β\n Value.Approx.Indexed.Inversion n (Value.closure envβ bodyβ) (Value.closure envβ bodyβ)"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.Preservation",
"content": "def Value.Approx.Indexed.Preservation (k : Nat) : Prop :=\n β m n env env' e v,\n m + n < k β\n env β²β'(m + n) env' β\n env β’ e β¦(n) v β\n β v', env' β’ e β¦ v' β§ v β²α΅₯(m) v'"
}
] | [
{
"name": "Juvix.Core.Main.Env.Approx.Indexed'.get",
"content": "lemma Env.Approx.Indexed'.get {n i : Nat} {env env' oβ}\n (hβ : env β²β'(n) env')\n (hβ : env[i]? = some oβ) :\n β oβ, env'[i]? = some oβ β§ oβ β²β'(n) oβ"
},
{
"name": "Juvix.Core.Main.Env.Approx.Indexed'.value",
"content": "lemma Env.Approx.Indexed'.value {n i : Nat} {env env' v}\n (hβ : env β²β'(n) env')\n (hβ : env[i]? = some (Object.value v)) :\n β v', env'[i]? = some (Object.value v') β§ v β²α΅₯(n) v'"
},
{
"name": "Juvix.Core.Main.Env.Approx.Indexed'.delayed",
"content": "lemma Env.Approx.Indexed'.delayed {n i : Nat} {envβ envβ env e}\n (hβ : envβ β²β'(n) envβ)\n (hβ : envβ[i]? = some (Object.delayed env e)) :\n (β env' e', e β²(n)β¨env, env'β© e' β§ envβ[i]? = some (Object.delayed env' e')) β¨\n β env', env β²β'(n) env' β§ envβ[i]? = some (Object.delayed env' e)"
},
{
"name": "Juvix.Core.Main.Env.Approx.Indexed'.from_value",
"content": "lemma Env.Approx.Indexed'.from_value {n lβ lβ} (h : lβ β²β(n) lβ) :\n List.map Object.value lβ β²β'(n) List.map Object.value lβ"
},
{
"name": "Juvix.Core.Main.Env.Approx.Indexed'.concat",
"content": "lemma Env.Approx.Indexed'.concat {n envβ envβ envβ' envβ'}\n (hβ : envβ β²β'(n) envβ')\n (hβ : envβ β²β'(n) envβ') :\n envβ ++ envβ β²β'(n) envβ' ++ envβ'"
},
{
"name": "Juvix.Core.Main.Env.Approx.Indexed'.cons",
"content": "lemma Env.Approx.Indexed'.cons {n oβ oβ envβ envβ}\n (hβ : oβ β²β'(n) oβ)\n (hβ : envβ β²β'(n) envβ) :\n oβ :: envβ β²β'(n) oβ :: envβ"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.unit",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.unit {n} : Value.unit β²α΅₯(n) Value.unit"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.const",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.const {n c} : Value.const c β²α΅₯(n) Value.const c"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.constr_app",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.constr_app {n ctr_name args_rev args_rev'} :\n (β k < n, args_rev β²β(k) args_rev') β\n Value.constr_app ctr_name args_rev β²α΅₯(n) Value.constr_app ctr_name args_rev'"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.closure",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.closure {n envβ bodyβ envβ bodyβ} :\n (β nβ nβ, nβ + nβ < n β\n β aβ aβ vβ,\n aβ β²α΅₯(nβ + nβ) aβ β\n aβ β· envβ β’ bodyβ β¦(nβ) vβ β\n β vβ, aβ β· envβ β’ bodyβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ) β\n Value.closure envβ bodyβ β²α΅₯(n) Value.closure envβ bodyβ"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.anti_monotone",
"content": "lemma Value.Approx.Indexed.anti_monotone {n n' vβ vβ} (h : vβ β²α΅₯(n) vβ) (h' : n' β€ n) : vβ β²α΅₯(n') vβ"
},
{
"name": "Juvix.Core.Main.Expr.Approx.Param.Indexed.anti_monotone",
"content": "lemma Expr.Approx.Param.Indexed.anti_monotone {n n' envβ envβ eβ eβ}\n (h : eβ β²(n)β¨envβ, envββ© eβ)\n (h' : n' β€ n)\n : eβ β²(n')β¨envβ, envββ© eβ"
},
{
"name": "Juvix.Core.Main.Expr.Approx.Indexed'.anti_monotone",
"content": "lemma Expr.Approx.Indexed'.anti_monotone {n n' eβ eβ}\n (h : eβ β²'(n) eβ)\n (h' : n' β€ n)\n : eβ β²'(n') eβ"
},
{
"name": "Juvix.Core.Main.Env.Approx.Indexed'.anti_monotone",
"content": " lemma Env.Approx.Indexed'.anti_monotone {n n' envβ envβ}\n (h : envβ β²β'(n) envβ)\n (h' : n' β€ n)\n : envβ β²β'(n') envβ"
},
{
"name": "Juvix.Core.Main.Object.Approx.Indexed'.anti_monotone",
"content": " lemma Object.Approx.Indexed'.anti_monotone {n n' oβ oβ} (h : oβ β²β'(n) oβ) (h' : n' β€ n) : oβ β²β'(n') oβ"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.Preservation.anti_monotone",
"content": "lemma Value.Approx.Indexed.Preservation.anti_monotone {k k'} (h : Value.Approx.Indexed.Preservation k) (h' : k' β€ k) : Value.Approx.Indexed.Preservation k'"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.preserved_step",
"content": "lemma Value.Approx.Indexed.preserved_step {k} :\n (β k' < k, Preservation k') β Preservation k"
}
] | import Juvix.Core.Main.Semantics.Eval
import Juvix.Core.Main.Semantics.Eval.Indexed
import Juvix.Utils
import Mathlib.Tactic.Linarith
import Mathlib.Data.List.Forall2
import Aesop
namespace Juvix.Core.Main
def Value.Approx.Indexed (n : Nat) (vβ vβ : Value) : Prop :=
(vβ = Value.unit β§ vβ = Value.unit) β¨
(β c, vβ = Value.const c β§ vβ = Value.const c) β¨
(β ctr_name args_rev args_rev',
vβ = Value.constr_app ctr_name args_rev β§
vβ = Value.constr_app ctr_name args_rev' β§
(β k < n, List.Forallβ (Value.Approx.Indexed k) args_rev args_rev')) β¨
(β envβ bodyβ envβ bodyβ,
vβ = Value.closure envβ bodyβ β§
vβ = Value.closure envβ bodyβ β§
(β nβ nβ, nβ + nβ < n β
β aβ aβ rβ,
Value.Approx.Indexed (nβ + nβ) aβ aβ β
aβ β· envβ β’ bodyβ β¦(nβ) rβ β
β rβ,
aβ β· envβ β’ bodyβ β¦ rβ β§
Value.Approx.Indexed nβ rβ rβ))
notation:40 v:40 " β²α΅₯(" n:40 ") " v':40 => Value.Approx.Indexed n v v'
notation:40 argsβ:40 " β²β(" n:40 ") " argsβ:40 => List.Forallβ (Value.Approx.Indexed n) argsβ argsβ
def Expr.Approx.Param.Indexed (n : Nat) (envβ envβ : Env) (eβ eβ : Expr) : Prop :=
(β nβ nβ vβ, nβ + nβ β€ n β envβ β’ eβ β¦(nβ) vβ β β vβ, envβ β’ eβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ)
notation:40 e:40 " β²(" n:40 ")β¨" env:40 ", " env':40 "β© " e':40 => Expr.Approx.Param.Indexed n env env' e e'
inductive Object.Approx.Indexed' (n : Nat) : Object β Object β Prop where
| value {vβ vβ} :
vβ β²α΅₯(n) vβ β
Object.Approx.Indexed' n (Object.value vβ) (Object.value vβ)
| delayed {envβ envβ eβ eβ} :
eβ β²(n)β¨envβ, envββ© eβ β
Object.Approx.Indexed' n (Object.delayed envβ eβ) (Object.delayed envβ eβ)
| delayed_eq {envβ envβ e} :
List.Forallβ (Object.Approx.Indexed' n) envβ envβ β
Object.Approx.Indexed' n (Object.delayed envβ e) (Object.delayed envβ e)
def Env.Approx.Indexed' (n : Nat) : (envβ envβ : Env) β Prop :=
List.Forallβ (Object.Approx.Indexed' n)
notation:40 v:40 " β²β'(" n:40 ") " v':40 => Object.Approx.Indexed' n v v'
notation:40 envβ:40 " β²β'(" n:40 ") " envβ:40 => Env.Approx.Indexed' n envβ envβ
def Expr.Approx.Indexed' (n : Nat) (eβ eβ : Expr) : Prop :=
(β nβ nβ vβ, nβ + nβ β€ n β
β envβ envβ, envβ β²β'(nβ + nβ) envβ β envβ β’ eβ β¦(nβ) vβ β β vβ, envβ β’ eβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ)
notation:40 e:40 " β²'(" n:40 ") " e':40 => Expr.Approx.Indexed' n e e'
@[aesop safe cases]
inductive Value.Approx.Indexed.Inversion (n : Nat) : Value β Value β Prop where
| unit : Value.Approx.Indexed.Inversion n Value.unit Value.unit
| const {c} : Value.Approx.Indexed.Inversion n (Value.const c) (Value.const c)
| constr_app {ctr_name args_rev args_rev'} :
(β k < n, args_rev β²β(k) args_rev') β
Value.Approx.Indexed.Inversion n (Value.constr_app ctr_name args_rev) (Value.constr_app ctr_name args_rev')
| closure {envβ bodyβ envβ bodyβ} :
(β nβ nβ, nβ + nβ < n β
β aβ aβ vβ,
aβ β²α΅₯(nβ + nβ) aβ β
aβ β· envβ β’ bodyβ β¦(nβ) vβ β
β vβ, aβ β· envβ β’ bodyβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ) β
Value.Approx.Indexed.Inversion n (Value.closure envβ bodyβ) (Value.closure envβ bodyβ)
end
def Value.Approx.Indexed.Preservation (k : Nat) : Prop :=
β m n env env' e v,
m + n < k β
env β²β'(m + n) env' β
env β’ e β¦(n) v β
β v', env' β’ e β¦ v' β§ v β²α΅₯(m) v' | lemma Value.Approx.Indexed.preserved' {k} : Preservation k := | := by
suffices β k' β€ k, Preservation k' by
aesop
induction k with
| zero =>
intro k' hk'
refine preserved_step ?_
intro k hk
linarith
| succ k ih =>
intro k' hk'
cases hk'
case succ.refl =>
refine preserved_step ?_
intro k' hk'
apply ih
linarith
case succ.step =>
apply ih
simp_all only [Nat.le_eq] | 9 | 80 | false | Semantics |
258 | Juvix.Core.Main.Object.Approx.Indexed'.refl' | lemma Object.Approx.Indexed'.refl' {n o} (h : β v, v β²α΅₯(n) v) : o β²β'(n) o | juvix-lean | Juvix/Core/Main/Semantics/Approx/Indexed.lean | [
"import Juvix.Utils",
"import Juvix.Core.Main.Semantics.Eval.Indexed",
"import Mathlib.Tactic.Linarith",
"import Mathlib.Data.List.Forall2",
"import Juvix.Core.Main.Semantics.Eval",
"import Aesop"
] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "List.Forallβ",
"module": "Batteries.Data.List.Basic"
},
{
"name": "List.Forallβ.cons",
"module": "Batteries.Data.List.Basic"
},
{
"name": "List.Forallβ.nil",
"module": "Batteries.Data.List.Basic"
},
{
"name": "List.cons",
"module": "Init.Prelude"
},
{
"name": "List.nil",
"module": "Init.Prelude"
}
] | [
{
"name": "notation:40 e:40 \" β²(\" n:40 \")β¨\" env:40 \", \" env':40 \"β© \" e'",
"content": "notation:40 e:40 \" β²(\" n:40 \")β¨\" env:40 \", \" env':40 \"β© \" e':40 => Expr.Approx.Param.Indexed n env env' e e'"
},
{
"name": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Inde",
"content": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Indexed n v v'\n\nsyntax \"case \" expr \" of \" cases \" end\" : expr"
},
{
"name": "notation:40 v:40 \" β²β'(\" n:40 \") \" v':40 => Object.Approx.In",
"content": "notation:40 v:40 \" β²β'(\" n:40 \") \" v':40 => Object.Approx.Indexed' n v v'"
},
{
"name": "notation:40 envβ:40 \" β²β'(\" n:40 \") \" envβ:40 => Env.Approx.",
"content": "notation:40 envβ:40 \" β²β'(\" n:40 \") \" envβ:40 => Env.Approx.Indexed' n envβ envβ"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(βͺ$s:ident β― $i:numβ«) => `(Expr.var $(Lean.Syntax.mkStrLit s.getId.toString) $i)\n | `(βͺ$num:numβ«) => `(Expr.const (Constant.int $num))\n | `(βͺ$s:strβ«) => `(Expr.const (Constant.string $s))\n | `(βͺΟ
β«) => `(Expr.unit)\n | `(βͺ$eβ:expr $eβ:exprβ«) => `(Expr.app βͺ$eββ« βͺ$eββ«)\n | `(βͺΞ» $s:ident $e:exprβ«) => `(Expr.lambda $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eβ«)\n | `(βͺΞ» $ss:ident* . $e:exprβ«) => mkLambdas ss e\n | `(βͺ $s:ident β«) => `(Expr.constr $(Lean.Syntax.mkStrLit s.getId.toString))\n | `(βͺ $s:ident $es:expr* β«) => mkConstrApp s es\n | `(βͺ$eβ + $eββ«) => `(Expr.binop BinaryOp.add_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ - $eββ«) => `(Expr.binop BinaryOp.sub_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ * $eββ«) => `(Expr.binop BinaryOp.mul_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ / $eββ«) => `(Expr.binop BinaryOp.div_int βͺ$eββ« βͺ$eββ«)\n | `(βͺlet $s:ident := $eβ:expr in $eβ:exprβ«) => `(Expr.save $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eββ« βͺ$eββ«)\n | `(βͺletrec $s:ident := $eβ:expr in $eβ:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.save $name (Expr.recur $name βͺ$eββ«) βͺ$eββ«)\n | `(βͺrec $s:ident $e:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.recur $name βͺ$eβ«)\n | `(βͺβ₯β«) => `(Expr.fail)\n | `(βͺcases| | $s:ident => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« Expr.fail)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« Expr.fail)\n | `(βͺcases| | _ => $e:expr β«) =>\n `(βͺ$eβ«)\n | `(βͺcase $e:expr of $cs:cases endβ«) => do\n `(Expr.save \"_case_\" βͺ$eβ« βͺcases|$csβ«)\n | `(βͺ($e)β«) => `(βͺ$eβ«)\n\n inductive Object : Type where\n | value : Value β Object\n | delayed : (env : List Object) β Expr β Object\n deriving Inhabited"
},
{
"name": "Object.Approx",
"content": "inductive Object.Approx : Object β Object β Prop where\n | value {vβ vβ} : vβ β²α΅₯ vβ β Object.Approx (Object.value vβ) (Object.value vβ)\n | delayed {envβ envβ eβ eβ} :\n eβ β²β¨envβ, envββ© eβ β\n Object.Approx (Object.delayed envβ eβ) (Object.delayed envβ eβ)"
},
{
"name": "Env.Approx",
"content": "def Env.Approx : (envβ envβ : Env) β Prop :=\n List.Forallβ Object.Approx"
},
{
"name": "BinaryOp",
"content": "inductive BinaryOp : Type where\n | add_int : BinaryOp\n | sub_int : BinaryOp\n | mul_int : BinaryOp\n | div_int : BinaryOp\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Expr",
"content": "inductive Expr : Type where\n | var : (name : String) β (index : Nat) β Expr\n | unit : Expr\n | const : Constant β Expr\n | constr : Name β Expr\n | app : Expr β Expr β Expr\n | constr_app : Expr β Expr β Expr\n | binop : (oper : BinaryOp) β (argβ argβ : Expr) β Expr\n | lambda : (var_name : String) β (body : Expr) β Expr\n | save : (var_name : String) β (value : Expr) β (body : Expr) β Expr\n | branch : (constr : Name) β (var_names : List Name) β (body : Expr) β (next : Expr) β Expr\n | recur : (var_name : Name) β (body : Expr) β Expr\n | fail : Expr\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Constant",
"content": "inductive Constant : Type where\n | int : Int β Constant\n | string : String β Constant\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "notation:40 v:40 \" β²β \" v':40 => Object.Approx v v'",
"content": "notation:40 v:40 \" β²β \" v':40 => Object.Approx v v'"
},
{
"name": "notation:40 envβ:40 \" β²β \" envβ:40 => Env.Approx envβ envβ",
"content": "notation:40 envβ:40 \" β²β \" envβ:40 => Env.Approx envβ envβ"
},
{
"name": "infixl:100 \" @@ \" => Expr.app",
"content": "infixl:100 \" @@ \" => Expr.app"
}
] | [
{
"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": "Juvix.Core.Main.Object.Approx.Indexed'",
"content": "inductive Object.Approx.Indexed' (n : Nat) : Object β Object β Prop where\n | value {vβ vβ} :\n vβ β²α΅₯(n) vβ β\n Object.Approx.Indexed' n (Object.value vβ) (Object.value vβ)\n | delayed {envβ envβ eβ eβ} :\n eβ β²(n)β¨envβ, envββ© eβ β\n Object.Approx.Indexed' n (Object.delayed envβ eβ) (Object.delayed envβ eβ)\n | delayed_eq {envβ envβ e} :\n List.Forallβ (Object.Approx.Indexed' n) envβ envβ β\n Object.Approx.Indexed' n (Object.delayed envβ e) (Object.delayed envβ e)"
},
{
"name": "Juvix.Core.Main.Env.Approx.Indexed'",
"content": "def Env.Approx.Indexed' (n : Nat) : (envβ envβ : Env) β Prop :=\n List.Forallβ (Object.Approx.Indexed' n)"
}
] | [
{
"name": "Juvix.Core.Main.Env.Approx.Indexed'.refl'",
"content": " lemma Env.Approx.Indexed'.refl' {n env} (h : β v, v β²α΅₯(n) v) : env β²β'(n) env"
}
] | import Juvix.Core.Main.Semantics.Eval
import Juvix.Core.Main.Semantics.Eval.Indexed
import Juvix.Utils
import Mathlib.Tactic.Linarith
import Mathlib.Data.List.Forall2
import Aesop
namespace Juvix.Core.Main
notation:40 v:40 " β²α΅₯(" n:40 ") " v':40 => Value.Approx.Indexed n v v'
notation:40 argsβ:40 " β²β(" n:40 ") " argsβ:40 => List.Forallβ (Value.Approx.Indexed n) argsβ argsβ
notation:40 e:40 " β²(" n:40 ")β¨" env:40 ", " env':40 "β© " e':40 => Expr.Approx.Param.Indexed n env env' e e'
inductive Object.Approx.Indexed' (n : Nat) : Object β Object β Prop where
| value {vβ vβ} :
vβ β²α΅₯(n) vβ β
Object.Approx.Indexed' n (Object.value vβ) (Object.value vβ)
| delayed {envβ envβ eβ eβ} :
eβ β²(n)β¨envβ, envββ© eβ β
Object.Approx.Indexed' n (Object.delayed envβ eβ) (Object.delayed envβ eβ)
| delayed_eq {envβ envβ e} :
List.Forallβ (Object.Approx.Indexed' n) envβ envβ β
Object.Approx.Indexed' n (Object.delayed envβ e) (Object.delayed envβ e)
def Env.Approx.Indexed' (n : Nat) : (envβ envβ : Env) β Prop :=
List.Forallβ (Object.Approx.Indexed' n)
notation:40 v:40 " β²β'(" n:40 ") " v':40 => Object.Approx.Indexed' n v v'
notation:40 envβ:40 " β²β'(" n:40 ") " envβ:40 => Env.Approx.Indexed' n envβ envβ
notation:40 e:40 " β²'(" n:40 ") " e':40 => Expr.Approx.Indexed' n e e'
end | lemma Object.Approx.Indexed'.refl' {n o} (h : β v, v β²α΅₯(n) v) : o β²β'(n) o := | := by
cases o
case value v =>
apply Object.Approx.Indexed'.value
apply h
case delayed env e =>
apply Object.Approx.Indexed'.delayed_eq
exact Env.Approx.Indexed'.refl' h | 3 | 14 | false | Semantics |
259 | Juvix.Core.Main.Expr.Equiv.eval_const | lemma Expr.Equiv.eval_const {op aβ aβ iβ iβ iβ} :
aβ β Expr.const (Constant.int iβ) β
aβ β Expr.const (Constant.int iβ) β
iβ = eval_binop_int op iβ iβ β
Expr.binop op aβ aβ β
Expr.const (Constant.int iβ) | juvix-lean | Juvix/Core/Main/Semantics/Equiv.lean | [
"import Juvix.Core.Main.Semantics.Approx"
] | [
{
"name": "BEq",
"module": "Init.Prelude"
},
{
"name": "DecidableEq",
"module": "Init.Prelude"
},
{
"name": "Inhabited",
"module": "Init.Prelude"
},
{
"name": "Int",
"module": "Init.Data.Int.Basic"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "List.Forallβ",
"module": "Batteries.Data.List.Basic"
},
{
"name": "String",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "closure",
"module": "Mathlib.Topology.Defs.Basic"
}
] | [
{
"name": "notation:40 eβ:40 \" β² \" eβ:40 => Expr.Approx eβ eβ",
"content": "notation:40 eβ:40 \" β² \" eβ:40 => Expr.Approx eβ eβ"
},
{
"name": "notation:40 e:40 \" β²β¨\" env:40 \", \" env':40 \"β© \" e':40 => Exp",
"content": "notation:40 e:40 \" β²β¨\" env:40 \", \" env':40 \"β© \" e':40 => Expr.Approx.Param env env' e e'"
},
{
"name": "notation:40 envβ:40 \" β²β \" envβ:40 => Env.Approx envβ envβ",
"content": "notation:40 envβ:40 \" β²β \" envβ:40 => Env.Approx envβ envβ"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β\" => Eval.Defined env e",
"content": "notation:40 env:40 \" β’ \" e:40 \" β\" => Eval.Defined env e"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Inde",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Indexed n env e v"
},
{
"name": "notation:40 v:40 \" β²α΅₯ \" v':40 => Value.Approx v v'",
"content": "notation:40 v:40 \" β²α΅₯ \" v':40 => Value.Approx v v'"
},
{
"name": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Inde",
"content": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Indexed n v v'"
},
{
"name": "notation:40 e:40 \" β²(\" n:40 \")β¨\" env:40 \", \" env':40 \"β© \" e'",
"content": "notation:40 e:40 \" β²(\" n:40 \")β¨\" env:40 \", \" env':40 \"β© \" e':40 => Expr.Approx.Param.Indexed n env env' e e'\n\nsyntax:100 expr:100 ppSpace expr:101 : expr\n\nsyntax:50 expr:50 \" + \" expr:51 : expr\n\nsyntax:50 expr:50 \" - \" expr:50 : expr\n\nsyntax:60 expr:60 \" * \" expr:61 : expr\n\nsyntax:60 expr:60 \" / \" expr:60 : expr\n\nsyntax \"case \" expr \" of \" cases \" end\" : expr"
},
{
"name": "notation:40 v:40 \" β²β'(\" n:40 \") \" v':40 => Object.Approx.In",
"content": "notation:40 v:40 \" β²β'(\" n:40 \") \" v':40 => Object.Approx.Indexed' n v v'"
},
{
"name": "notation:40 v:40 \" β²β \" v':40 => Object.Approx v v'",
"content": "notation:40 v:40 \" β²β \" v':40 => Object.Approx v v'"
},
{
"name": "notation:40 envβ:40 \" β²β'(\" n:40 \") \" envβ:40 => Env.Approx.",
"content": "notation:40 envβ:40 \" β²β'(\" n:40 \") \" envβ:40 => Env.Approx.Indexed' n envβ envβ"
},
{
"name": "macro \"invert\" h:term : tactic => `(tactic| (cases ($h).inve",
"content": "macro \"invert\" h:term : tactic => `(tactic| (cases ($h).invert <;> try clear $h))"
},
{
"name": "notation:40 eβ:40 \" β \" eβ:40 => Expr.Equiv eβ eβ",
"content": "notation:40 eβ:40 \" β \" eβ:40 => Expr.Equiv eβ eβ"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(βͺ$s:ident β― $i:numβ«) => `(Expr.var $(Lean.Syntax.mkStrLit s.getId.toString) $i)\n | `(βͺ$num:numβ«) => `(Expr.const (Constant.int $num))\n | `(βͺ$s:strβ«) => `(Expr.const (Constant.string $s))\n | `(βͺΟ
β«) => `(Expr.unit)\n | `(βͺ$eβ:expr $eβ:exprβ«) => `(Expr.app βͺ$eββ« βͺ$eββ«)\n | `(βͺΞ» $s:ident $e:exprβ«) => `(Expr.lambda $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eβ«)\n | `(βͺΞ» $ss:ident* . $e:exprβ«) => mkLambdas ss e\n | `(βͺ $s:ident β«) => `(Expr.constr $(Lean.Syntax.mkStrLit s.getId.toString))\n | `(βͺ $s:ident $es:expr* β«) => mkConstrApp s es\n | `(βͺ$eβ + $eββ«) => `(Expr.binop BinaryOp.add_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ - $eββ«) => `(Expr.binop BinaryOp.sub_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ * $eββ«) => `(Expr.binop BinaryOp.mul_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ / $eββ«) => `(Expr.binop BinaryOp.div_int βͺ$eββ« βͺ$eββ«)\n | `(βͺlet $s:ident := $eβ:expr in $eβ:exprβ«) => `(Expr.save $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eββ« βͺ$eββ«)\n | `(βͺletrec $s:ident := $eβ:expr in $eβ:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.save $name (Expr.recur $name βͺ$eββ«) βͺ$eββ«)\n | `(βͺrec $s:ident $e:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.recur $name βͺ$eβ«)\n | `(βͺβ₯β«) => `(Expr.fail)\n | `(βͺcases| | $s:ident => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« Expr.fail)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« Expr.fail)\n | `(βͺcases| | _ => $e:expr β«) =>\n `(βͺ$eβ«)\n | `(βͺcase $e:expr of $cs:cases endβ«) => do\n `(Expr.save \"_case_\" βͺ$eβ« βͺcases|$csβ«)\n | `(βͺ($e)β«) => `(βͺ$eβ«)"
},
{
"name": "Expr",
"content": "inductive Expr : Type where\n | var : (name : String) β (index : Nat) β Expr\n | unit : Expr\n | const : Constant β Expr\n | constr : Name β Expr\n | app : Expr β Expr β Expr\n | constr_app : Expr β Expr β Expr\n | binop : (oper : BinaryOp) β (argβ argβ : Expr) β Expr\n | lambda : (var_name : String) β (body : Expr) β Expr\n | save : (var_name : String) β (value : Expr) β (body : Expr) β Expr\n | branch : (constr : Name) β (var_names : List Name) β (body : Expr) β (next : Expr) β Expr\n | recur : (var_name : Name) β (body : Expr) β Expr\n | fail : Expr\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Expr.Approx",
"content": "def Expr.Approx (eβ eβ : Expr) : Prop :=\n β envβ envβ, envβ β²β envβ β eβ β²β¨envβ, envββ© eβ"
},
{
"name": "Constant",
"content": "inductive Constant : Type where\n | int : Int β Constant\n | string : String β Constant\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "eval_binop_int",
"content": "def eval_binop_int (op : BinaryOp) (iβ iβ : Int) : Int :=\n match op with\n | BinaryOp.add_int => iβ + iβ\n | BinaryOp.sub_int => iβ - iβ\n | BinaryOp.mul_int => iβ * iβ\n | BinaryOp.div_int => iβ / iβ"
},
{
"name": "BinaryOp",
"content": "inductive BinaryOp : Type where\n | add_int : BinaryOp\n | sub_int : BinaryOp\n | mul_int : BinaryOp\n | div_int : BinaryOp\n deriving Inhabited, BEq, DecidableEq\n\n inductive Value : Type where\n | unit : Value\n | const : Constant β Value\n | constr_app : (constr : Name) β (args_rev : List Value) β Value\n | closure : (env : List Object) β (value : Expr) β Value\n deriving Inhabited"
},
{
"name": "Value.Approx",
"content": "def Value.Approx (v v' : Value) : Prop :=\n β n, v β²α΅₯(n) v'"
},
{
"name": "Env.Approx",
"content": "def Env.Approx : (envβ envβ : Env) β Prop :=\n List.Forallβ Object.Approx"
},
{
"name": "Object.Approx",
"content": "inductive Object.Approx : Object β Object β Prop where\n | value {vβ vβ} : vβ β²α΅₯ vβ β Object.Approx (Object.value vβ) (Object.value vβ)\n | delayed {envβ envβ eβ eβ} :\n eβ β²β¨envβ, envββ© eβ β\n Object.Approx (Object.delayed envβ eβ) (Object.delayed envβ eβ)\n\n inductive Object : Type where\n | value : Value β Object\n | delayed : (env : List Object) β Expr β Object\n deriving Inhabited"
},
{
"name": "Value.Approx.Indexed",
"content": "def Value.Approx.Indexed (n : Nat) (vβ vβ : Value) : Prop :=\n (vβ = Value.unit β§ vβ = Value.unit) β¨\n (β c, vβ = Value.const c β§ vβ = Value.const c) β¨\n (β ctr_name args_rev args_rev',\n vβ = Value.constr_app ctr_name args_rev β§\n vβ = Value.constr_app ctr_name args_rev' β§\n (β k < n, List.Forallβ (Value.Approx.Indexed k) args_rev args_rev')) β¨\n (β envβ bodyβ envβ bodyβ,\n vβ = Value.closure envβ bodyβ β§\n vβ = Value.closure envβ bodyβ β§\n (β nβ nβ, nβ + nβ < n β\n β aβ aβ rβ,\n Value.Approx.Indexed (nβ + nβ) aβ aβ β\n aβ β· envβ β’ bodyβ β¦(nβ) rβ β\n β rβ,\n aβ β· envβ β’ bodyβ β¦ rβ β§\n Value.Approx.Indexed nβ rβ rβ))"
},
{
"name": "cons_value",
"content": "abbrev cons_value (v : Value) (env : Env) : Env := Object.value v :: env"
},
{
"name": "Name",
"content": "abbrev Name : Type := String"
},
{
"name": "Env",
"content": "abbrev Env : Type := List Object"
},
{
"name": "Env.Approx.Indexed'",
"content": "def Env.Approx.Indexed' (n : Nat) : (envβ envβ : Env) β Prop :=\n List.Forallβ (Object.Approx.Indexed' n)"
},
{
"name": "Object.Approx.Indexed'",
"content": "inductive Object.Approx.Indexed' (n : Nat) : Object β Object β Prop where\n | value {vβ vβ} :\n vβ β²α΅₯(n) vβ β\n Object.Approx.Indexed' n (Object.value vβ) (Object.value vβ)\n | delayed {envβ envβ eβ eβ} :\n eβ β²(n)β¨envβ, envββ© eβ β\n Object.Approx.Indexed' n (Object.delayed envβ eβ) (Object.delayed envβ eβ)\n | delayed_eq {envβ envβ e} :\n List.Forallβ (Object.Approx.Indexed' n) envβ envβ β\n Object.Approx.Indexed' n (Object.delayed envβ e) (Object.delayed envβ e)"
},
{
"name": "Eval.Indexed",
"content": "inductive Eval.Indexed : Nat β Env β Expr β Value β Prop where\n | var {n env name idx val} :\n env[idx]? = some (Object.value val) β\n Eval.Indexed n env (Expr.var name idx) val\n | var_rec {n env name idx env' expr val} :\n env[idx]? = some (Object.delayed env' expr) β\n Eval.Indexed n env' expr val β\n Eval.Indexed n env (Expr.var name idx) val\n | unit {n env} :\n Eval.Indexed n env Expr.unit Value.unit\n | const {n env c} :\n Eval.Indexed n env (Expr.const c) (Value.const c)\n | constr {n env name} :\n Eval.Indexed n env (Expr.constr name) (Value.constr_app name [])\n | app {n nβ nβ env env' f body arg val val'} :\n nβ + nβ + 1 β€ n β\n Eval.Indexed nβ env f (Value.closure env' body) β\n Eval.Indexed (nβ + 1) env arg val β\n Eval.Indexed nβ (val β· env') body val' β\n Eval.Indexed n env (Expr.app f arg) val'\n | constr_app {n n' env ctr ctr_name ctr_args_rev arg val} :\n n' < n β\n Eval.Indexed n env ctr (Value.constr_app ctr_name ctr_args_rev) β\n Eval.Indexed n' env arg val β\n Eval.Indexed n env (Expr.constr_app ctr arg) (Value.constr_app ctr_name (val :: ctr_args_rev))\n | binop {n env op argβ argβ valβ valβ} :\n Eval.Indexed n env argβ (Value.const (Constant.int valβ)) β\n Eval.Indexed n env argβ (Value.const (Constant.int valβ)) β\n Eval.Indexed n env (Expr.binop op argβ argβ) (Value.const (Constant.int (eval_binop_int op valβ valβ)))\n | lambda {n env name body} :\n Eval.Indexed n env (Expr.lambda name body) (Value.closure env body)\n | save {n nβ nβ env name value body val val'} :\n nβ + nβ β€ n β\n Eval.Indexed nβ env value val β\n Eval.Indexed nβ (val β· env) body val' β\n Eval.Indexed n env (Expr.save name value body) val'\n | branch_matches {n n' env name args_rev body val} :\n n' < n β\n Eval.Indexed n' (args_rev.map Object.value ++ env) body val β\n Eval.Indexed n (Value.constr_app name args_rev β· env) (Expr.branch name _ body _) val\n | branch_fails {n env name name' args_rev next val} :\n name β name' β\n Eval.Indexed n (Value.constr_app name args_rev β· env) next val β\n Eval.Indexed n (Value.constr_app name args_rev β· env) (Expr.branch name' _ _ next) val\n | recur {n n' env name body val} :\n n' < n β\n Eval.Indexed n' (Object.delayed env (Expr.recur name body) :: env) body val β\n Eval.Indexed n env (Expr.recur name body) val"
},
{
"name": "Eval",
"content": "@[aesop unsafe constructors]\ninductive Eval : Env β Expr β Value β Prop where\n | var {env name idx val} :\n env[idx]? = some (Object.value val) β\n Eval env (Expr.var name idx) val\n | var_rec {env name idx env' expr val} :\n env[idx]? = some (Object.delayed env' expr) β\n Eval env' expr val β\n Eval env (Expr.var name idx) val\n | unit {env} :\n Eval env Expr.unit Value.unit\n | const {env c} :\n Eval env (Expr.const c) (Value.const c)\n | constr {env name} :\n Eval env (Expr.constr name) (Value.constr_app name [])\n | app {env env' f body arg val val'} :\n Eval env f (Value.closure env' body) β\n Eval env arg val β\n Eval (val β· env') body val' β\n Eval env (Expr.app f arg) val'\n | constr_app {env ctr ctr_name ctr_args_rev arg val} :\n Eval env ctr (Value.constr_app ctr_name ctr_args_rev) β\n Eval env arg val β\n Eval env (Expr.constr_app ctr arg) (Value.constr_app ctr_name (val :: ctr_args_rev))\n | binop {env op argβ argβ valβ valβ} :\n Eval env argβ (Value.const (Constant.int valβ)) β\n Eval env argβ (Value.const (Constant.int valβ)) β\n Eval env (Expr.binop op argβ argβ) (Value.const (Constant.int (eval_binop_int op valβ valβ)))\n | lambda {env name body} :\n Eval env (Expr.lambda name body) (Value.closure env body)\n | save {env name value body val val'} :\n Eval env value val β\n Eval (val β· env) body val' β\n Eval env (Expr.save name value body) val'\n | branch_matches {env name args_rev body val} :\n Eval (args_rev.map Object.value ++ env) body val β\n Eval (Value.constr_app name args_rev β· env) (Expr.branch name _ body _) val\n | branch_fails {env name name' args_rev next val} :\n name β name' β\n Eval (Value.constr_app name args_rev β· env) next val β\n Eval (Value.constr_app name args_rev β· env) (Expr.branch name' _ _ next) val\n | recur {env name body val} :\n Eval (Object.delayed env (Expr.recur name body) :: env) body val β\n Eval env (Expr.recur name body) val"
},
{
"name": "infixr:50 \" β· \" => cons_value",
"content": "infixr:50 \" β· \" => cons_value"
},
{
"name": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Inde",
"content": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Indexed n v v'"
},
{
"name": "notation:40 v:40 \" β²β'(\" n:40 \") \" v':40 => Object.Approx.In",
"content": "notation:40 v:40 \" β²β'(\" n:40 \") \" v':40 => Object.Approx.Indexed' n v v'"
},
{
"name": "notation:40 envβ:40 \" β²β'(\" n:40 \") \" envβ:40 => Env.Approx.",
"content": "notation:40 envβ:40 \" β²β'(\" n:40 \") \" envβ:40 => Env.Approx.Indexed' n envβ envβ"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Inde",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Indexed n env e v"
},
{
"name": "notation:40 v:40 \" β²α΅₯ \" v':40 => Value.Approx v v'",
"content": "notation:40 v:40 \" β²α΅₯ \" v':40 => Value.Approx v v'"
},
{
"name": "notation:40 v:40 \" β²β \" v':40 => Object.Approx v v'",
"content": "notation:40 v:40 \" β²β \" v':40 => Object.Approx v v'"
},
{
"name": "notation:40 envβ:40 \" β²β \" envβ:40 => Env.Approx envβ envβ",
"content": "notation:40 envβ:40 \" β²β \" envβ:40 => Env.Approx envβ envβ"
},
{
"name": "notation:40 eβ:40 \" β² \" eβ:40 => Expr.Approx eβ eβ",
"content": "notation:40 eβ:40 \" β² \" eβ:40 => Expr.Approx eβ eβ"
},
{
"name": "infixl:100 \" @@ \" => Expr.app",
"content": "infixl:100 \" @@ \" => Expr.app"
}
] | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "Expr.Approx.eval_constβ",
"content": "lemma Expr.Approx.eval_constβ {op aβ aβ iβ iβ iβ} :\n aβ β² Expr.const (Constant.int iβ) β\n aβ β² Expr.const (Constant.int iβ) β\n iβ = eval_binop_int op iβ iβ β\n Expr.binop op aβ aβ β²\n Expr.const (Constant.int iβ)"
},
{
"name": "Expr.Approx.const_right",
"content": "lemma Expr.Approx.const_right {c e env v} :\n e β² Expr.const c β\n env β’ e β¦ v β\n v = Value.const c"
},
{
"name": "Expr.Approx.preservation",
"content": "lemma Expr.Approx.preservation {eβ eβ} :\n eβ β² eβ β\n β env vβ, env β’ eβ β¦ vβ β β vβ, env β’ eβ β¦ vβ β§ vβ β²α΅₯ vβ"
},
{
"name": "Expr.Approx.to_preservation",
"content": "lemma Expr.Approx.to_preservation {eβ eβ} :\n eβ β² eβ β\n β env vβ, env β’ eβ β¦ vβ β β vβ, env β’ eβ β¦ vβ β§ vβ β²α΅₯ vβ"
},
{
"name": "Expr.Approx.from_preservation",
"content": "lemma Expr.Approx.from_preservation {eβ eβ}\n (h : β env vβ, env β’ eβ β¦ vβ β β vβ, env β’ eβ β¦ vβ β§ vβ β²α΅₯ vβ)\n : eβ β² eβ"
},
{
"name": "Value.Approx.preserved",
"content": "theorem Value.Approx.preserved :\n β env env' e v,\n env β²β env' β\n env β’ e β¦ v β\n β v', env' β’ e β¦ v' β§ v β²α΅₯ v'"
},
{
"name": "Env.Approx.toIndexed",
"content": "lemma Env.Approx.toIndexed {envβ envβ} : envβ β²β envβ β β n, envβ β²β'(n) envβ"
},
{
"name": "Object.Approx.toIndexed",
"content": "lemma Object.Approx.toIndexed {oβ oβ} : oβ β²β oβ β β n, oβ β²β'(n) oβ"
},
{
"name": "Env.Approx.cons",
"content": "lemma Env.Approx.cons {envβ envβ oβ oβ} :\n oβ β²β oβ β envβ β²β envβ β (oβ :: envβ) β²β (oβ :: envβ)"
},
{
"name": "Expr.Approx.eval_constβ",
"content": "lemma Expr.Approx.eval_constβ {op aβ aβ iβ iβ iβ} :\n Expr.const (Constant.int iβ) β² aβ β\n Expr.const (Constant.int iβ) β² aβ β\n iβ = eval_binop_int op iβ iβ β\n Expr.const (Constant.int iβ) β²\n Expr.binop op aβ aβ"
},
{
"name": "Expr.Approx.const_left",
"content": "lemma Expr.Approx.const_left {c e env} :\n Expr.const c β² e β\n env β’ e β¦ Value.const c"
},
{
"name": "Expr.Approx.const",
"content": "lemma Expr.Approx.const {cβ cβ} :\n Expr.const cβ β² Expr.const cβ β\n cβ = cβ"
}
] | [
{
"name": "Juvix.Core.Main.Expr.Equiv",
"content": "def Expr.Equiv (eβ eβ : Expr) : Prop :=\n eβ β² eβ β§ eβ β² eβ"
}
] | [] | import Juvix.Core.Main.Semantics.Approx
namespace Juvix.Core.Main
notation:40 v:40 " βα΅₯ " v':40 => Value.Equiv v v'
notation:40 argsβ:40 " ββ " argsβ:40 => List.Forallβ Value.Equiv argsβ argsβ
notation:40 v:40 " ββ " v':40 => Object.Equiv v v'
notation:40 envβ:40 " ββ " envβ:40 => Env.Equiv envβ envβ
notation:40 eβ:40 " ββ¨" envβ:40 ", " envβ:40 "β© " eβ:40 => Expr.Equiv.Param envβ envβ eβ eβ
def Expr.Equiv (eβ eβ : Expr) : Prop :=
eβ β² eβ β§ eβ β² eβ
notation:40 eβ:40 " β " eβ:40 => Expr.Equiv eβ eβ | lemma Expr.Equiv.eval_const {op aβ aβ iβ iβ iβ} :
aβ β Expr.const (Constant.int iβ) β
aβ β Expr.const (Constant.int iβ) β
iβ = eval_binop_int op iβ iβ β
Expr.binop op aβ aβ β
Expr.const (Constant.int iβ) := | := by
simp only [Expr.Equiv]
intro hβ hβ hβ
constructor
Β· apply Expr.Approx.eval_constβ (op := op) (iβ := iβ) (iβ := iβ) <;>
simp_all only
Β· apply Expr.Approx.eval_constβ (op := op) (iβ := iβ) (iβ := iβ) <;>
simp_all only | 3 | 40 | false | Semantics |
260 | Juvix.Core.Main.Env.Approx.Indexed'.from_delayed | lemma Env.Approx.Indexed'.from_delayed {n envβ envβ l} (h : envβ β²β'(n) envβ) :
List.map (Object.delayed envβ) l β²β'(n) List.map (Object.delayed envβ) l | juvix-lean | Juvix/Core/Main/Semantics/Approx/Indexed.lean | [
"import Juvix.Utils",
"import Juvix.Core.Main.Semantics.Eval.Indexed",
"import Mathlib.Tactic.Linarith",
"import Mathlib.Data.List.Forall2",
"import Juvix.Core.Main.Semantics.Eval",
"import Aesop"
] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "List.Forallβ",
"module": "Batteries.Data.List.Basic"
},
{
"name": "List.map",
"module": "Init.Prelude"
},
{
"name": "List.Forallβ.cons",
"module": "Batteries.Data.List.Basic"
},
{
"name": "List.Forallβ.nil",
"module": "Batteries.Data.List.Basic"
}
] | [
{
"name": "notation:40 e:40 \" β²(\" n:40 \")β¨\" env:40 \", \" env':40 \"β© \" e'",
"content": "notation:40 e:40 \" β²(\" n:40 \")β¨\" env:40 \", \" env':40 \"β© \" e':40 => Expr.Approx.Param.Indexed n env env' e e'"
},
{
"name": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Inde",
"content": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Indexed n v v'"
},
{
"name": "notation:40 v:40 \" β²β'(\" n:40 \") \" v':40 => Object.Approx.In",
"content": "notation:40 v:40 \" β²β'(\" n:40 \") \" v':40 => Object.Approx.Indexed' n v v'"
},
{
"name": "notation:40 envβ:40 \" β²β'(\" n:40 \") \" envβ:40 => Env.Approx.",
"content": "notation:40 envβ:40 \" β²β'(\" n:40 \") \" envβ:40 => Env.Approx.Indexed' n envβ envβ\n\nsyntax \"case \" expr \" of \" cases \" end\" : expr"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(βͺ$s:ident β― $i:numβ«) => `(Expr.var $(Lean.Syntax.mkStrLit s.getId.toString) $i)\n | `(βͺ$num:numβ«) => `(Expr.const (Constant.int $num))\n | `(βͺ$s:strβ«) => `(Expr.const (Constant.string $s))\n | `(βͺΟ
β«) => `(Expr.unit)\n | `(βͺ$eβ:expr $eβ:exprβ«) => `(Expr.app βͺ$eββ« βͺ$eββ«)\n | `(βͺΞ» $s:ident $e:exprβ«) => `(Expr.lambda $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eβ«)\n | `(βͺΞ» $ss:ident* . $e:exprβ«) => mkLambdas ss e\n | `(βͺ $s:ident β«) => `(Expr.constr $(Lean.Syntax.mkStrLit s.getId.toString))\n | `(βͺ $s:ident $es:expr* β«) => mkConstrApp s es\n | `(βͺ$eβ + $eββ«) => `(Expr.binop BinaryOp.add_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ - $eββ«) => `(Expr.binop BinaryOp.sub_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ * $eββ«) => `(Expr.binop BinaryOp.mul_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ / $eββ«) => `(Expr.binop BinaryOp.div_int βͺ$eββ« βͺ$eββ«)\n | `(βͺlet $s:ident := $eβ:expr in $eβ:exprβ«) => `(Expr.save $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eββ« βͺ$eββ«)\n | `(βͺletrec $s:ident := $eβ:expr in $eβ:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.save $name (Expr.recur $name βͺ$eββ«) βͺ$eββ«)\n | `(βͺrec $s:ident $e:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.recur $name βͺ$eβ«)\n | `(βͺβ₯β«) => `(Expr.fail)\n | `(βͺcases| | $s:ident => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« Expr.fail)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« Expr.fail)\n | `(βͺcases| | _ => $e:expr β«) =>\n `(βͺ$eβ«)\n | `(βͺcase $e:expr of $cs:cases endβ«) => do\n `(Expr.save \"_case_\" βͺ$eβ« βͺcases|$csβ«)\n | `(βͺ($e)β«) => `(βͺ$eβ«)\n\n inductive Object : Type where\n | value : Value β Object\n | delayed : (env : List Object) β Expr β Object\n deriving Inhabited"
},
{
"name": "Object.Approx",
"content": "inductive Object.Approx : Object β Object β Prop where\n | value {vβ vβ} : vβ β²α΅₯ vβ β Object.Approx (Object.value vβ) (Object.value vβ)\n | delayed {envβ envβ eβ eβ} :\n eβ β²β¨envβ, envββ© eβ β\n Object.Approx (Object.delayed envβ eβ) (Object.delayed envβ eβ)"
},
{
"name": "Env.Approx",
"content": "def Env.Approx : (envβ envβ : Env) β Prop :=\n List.Forallβ Object.Approx"
},
{
"name": "BinaryOp",
"content": "inductive BinaryOp : Type where\n | add_int : BinaryOp\n | sub_int : BinaryOp\n | mul_int : BinaryOp\n | div_int : BinaryOp\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Expr",
"content": "inductive Expr : Type where\n | var : (name : String) β (index : Nat) β Expr\n | unit : Expr\n | const : Constant β Expr\n | constr : Name β Expr\n | app : Expr β Expr β Expr\n | constr_app : Expr β Expr β Expr\n | binop : (oper : BinaryOp) β (argβ argβ : Expr) β Expr\n | lambda : (var_name : String) β (body : Expr) β Expr\n | save : (var_name : String) β (value : Expr) β (body : Expr) β Expr\n | branch : (constr : Name) β (var_names : List Name) β (body : Expr) β (next : Expr) β Expr\n | recur : (var_name : Name) β (body : Expr) β Expr\n | fail : Expr\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Constant",
"content": "inductive Constant : Type where\n | int : Int β Constant\n | string : String β Constant\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "notation:40 v:40 \" β²β \" v':40 => Object.Approx v v'",
"content": "notation:40 v:40 \" β²β \" v':40 => Object.Approx v v'"
},
{
"name": "notation:40 envβ:40 \" β²β \" envβ:40 => Env.Approx envβ envβ",
"content": "notation:40 envβ:40 \" β²β \" envβ:40 => Env.Approx envβ envβ"
},
{
"name": "infixl:100 \" @@ \" => Expr.app",
"content": "infixl:100 \" @@ \" => Expr.app"
}
] | [
{
"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": "Juvix.Core.Main.Object.Approx.Indexed'",
"content": "inductive Object.Approx.Indexed' (n : Nat) : Object β Object β Prop where\n | value {vβ vβ} :\n vβ β²α΅₯(n) vβ β\n Object.Approx.Indexed' n (Object.value vβ) (Object.value vβ)\n | delayed {envβ envβ eβ eβ} :\n eβ β²(n)β¨envβ, envββ© eβ β\n Object.Approx.Indexed' n (Object.delayed envβ eβ) (Object.delayed envβ eβ)\n | delayed_eq {envβ envβ e} :\n List.Forallβ (Object.Approx.Indexed' n) envβ envβ β\n Object.Approx.Indexed' n (Object.delayed envβ e) (Object.delayed envβ e)"
},
{
"name": "Juvix.Core.Main.Env.Approx.Indexed'",
"content": "def Env.Approx.Indexed' (n : Nat) : (envβ envβ : Env) β Prop :=\n List.Forallβ (Object.Approx.Indexed' n)"
}
] | [] | import Juvix.Core.Main.Semantics.Eval
import Juvix.Core.Main.Semantics.Eval.Indexed
import Juvix.Utils
import Mathlib.Tactic.Linarith
import Mathlib.Data.List.Forall2
import Aesop
namespace Juvix.Core.Main
notation:40 v:40 " β²α΅₯(" n:40 ") " v':40 => Value.Approx.Indexed n v v'
notation:40 argsβ:40 " β²β(" n:40 ") " argsβ:40 => List.Forallβ (Value.Approx.Indexed n) argsβ argsβ
notation:40 e:40 " β²(" n:40 ")β¨" env:40 ", " env':40 "β© " e':40 => Expr.Approx.Param.Indexed n env env' e e'
inductive Object.Approx.Indexed' (n : Nat) : Object β Object β Prop where
| value {vβ vβ} :
vβ β²α΅₯(n) vβ β
Object.Approx.Indexed' n (Object.value vβ) (Object.value vβ)
| delayed {envβ envβ eβ eβ} :
eβ β²(n)β¨envβ, envββ© eβ β
Object.Approx.Indexed' n (Object.delayed envβ eβ) (Object.delayed envβ eβ)
| delayed_eq {envβ envβ e} :
List.Forallβ (Object.Approx.Indexed' n) envβ envβ β
Object.Approx.Indexed' n (Object.delayed envβ e) (Object.delayed envβ e)
def Env.Approx.Indexed' (n : Nat) : (envβ envβ : Env) β Prop :=
List.Forallβ (Object.Approx.Indexed' n)
notation:40 v:40 " β²β'(" n:40 ") " v':40 => Object.Approx.Indexed' n v v'
notation:40 envβ:40 " β²β'(" n:40 ") " envβ:40 => Env.Approx.Indexed' n envβ envβ
notation:40 e:40 " β²'(" n:40 ") " e':40 => Expr.Approx.Indexed' n e e' | lemma Env.Approx.Indexed'.from_delayed {n envβ envβ l} (h : envβ β²β'(n) envβ) :
List.map (Object.delayed envβ) l β²β'(n) List.map (Object.delayed envβ) l := | := by
induction l
case nil =>
exact List.Forallβ.nil
case cons e l' h' =>
simp
apply List.Forallβ.cons
Β· apply Object.Approx.Indexed'.delayed_eq
assumption
Β· assumption | 3 | 12 | false | Semantics |
261 | Juvix.Core.Main.Termination.binop | lemma Termination.binop {env op eβ eβ cβ cβ} :
env β’ eβ β¦ Value.const (Constant.int cβ) β
env β’ eβ β¦ Value.const (Constant.int cβ) β
env β’ Expr.binop op eβ eβ β | juvix-lean | Juvix/Core/Main/Tactics/Termination.lean | [
"import Juvix.Core.Main.Tactics.Base"
] | [
{
"name": "BEq",
"module": "Init.Prelude"
},
{
"name": "DecidableEq",
"module": "Init.Prelude"
},
{
"name": "Inhabited",
"module": "Init.Prelude"
},
{
"name": "Int",
"module": "Init.Data.Int.Basic"
},
{
"name": "String",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "closure",
"module": "Mathlib.Topology.Defs.Basic"
}
] | [
{
"name": "syntax:100 expr:100 ppSpace expr:101 : expr",
"content": "syntax:100 expr:100 ppSpace expr:101 : expr\n\nsyntax:50 expr:50 \" + \" expr:51 : expr\n\nsyntax:50 expr:50 \" - \" expr:50 : expr\n\nsyntax:60 expr:60 \" * \" expr:61 : expr\n\nsyntax:60 expr:60 \" / \" expr:60 : expr"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β\" => Eval.Defined env e",
"content": "notation:40 env:40 \" β’ \" e:40 \" β\" => Eval.Defined env e"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Inde",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Indexed n env e v"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(βͺ$s:ident β― $i:numβ«) => `(Expr.var $(Lean.Syntax.mkStrLit s.getId.toString) $i)\n | `(βͺ$num:numβ«) => `(Expr.const (Constant.int $num))\n | `(βͺ$s:strβ«) => `(Expr.const (Constant.string $s))\n | `(βͺΟ
β«) => `(Expr.unit)\n | `(βͺ$eβ:expr $eβ:exprβ«) => `(Expr.app βͺ$eββ« βͺ$eββ«)\n | `(βͺΞ» $s:ident $e:exprβ«) => `(Expr.lambda $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eβ«)\n | `(βͺΞ» $ss:ident* . $e:exprβ«) => mkLambdas ss e\n | `(βͺ $s:ident β«) => `(Expr.constr $(Lean.Syntax.mkStrLit s.getId.toString))\n | `(βͺ $s:ident $es:expr* β«) => mkConstrApp s es\n | `(βͺ$eβ + $eββ«) => `(Expr.binop BinaryOp.add_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ - $eββ«) => `(Expr.binop BinaryOp.sub_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ * $eββ«) => `(Expr.binop BinaryOp.mul_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ / $eββ«) => `(Expr.binop BinaryOp.div_int βͺ$eββ« βͺ$eββ«)\n | `(βͺlet $s:ident := $eβ:expr in $eβ:exprβ«) => `(Expr.save $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eββ« βͺ$eββ«)\n | `(βͺletrec $s:ident := $eβ:expr in $eβ:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.save $name (Expr.recur $name βͺ$eββ«) βͺ$eββ«)\n | `(βͺrec $s:ident $e:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.recur $name βͺ$eβ«)\n | `(βͺβ₯β«) => `(Expr.fail)\n | `(βͺcases| | $s:ident => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« Expr.fail)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« Expr.fail)\n | `(βͺcases| | _ => $e:expr β«) =>\n `(βͺ$eβ«)\n | `(βͺcase $e:expr of $cs:cases endβ«) => do\n `(Expr.save \"_case_\" βͺ$eβ« βͺcases|$csβ«)\n | `(βͺ($e)β«) => `(βͺ$eβ«)"
},
{
"name": "Expr",
"content": "inductive Expr : Type where\n | var : (name : String) β (index : Nat) β Expr\n | unit : Expr\n | const : Constant β Expr\n | constr : Name β Expr\n | app : Expr β Expr β Expr\n | constr_app : Expr β Expr β Expr\n | binop : (oper : BinaryOp) β (argβ argβ : Expr) β Expr\n | lambda : (var_name : String) β (body : Expr) β Expr\n | save : (var_name : String) β (value : Expr) β (body : Expr) β Expr\n | branch : (constr : Name) β (var_names : List Name) β (body : Expr) β (next : Expr) β Expr\n | recur : (var_name : Name) β (body : Expr) β Expr\n | fail : Expr\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Constant",
"content": "inductive Constant : Type where\n | int : Int β Constant\n | string : String β Constant\n deriving Inhabited, BEq, DecidableEq\n\n inductive Value : Type where\n | unit : Value\n | const : Constant β Value\n | constr_app : (constr : Name) β (args_rev : List Value) β Value\n | closure : (env : List Object) β (value : Expr) β Value\n deriving Inhabited"
},
{
"name": "Eval",
"content": "@[aesop unsafe constructors]\ninductive Eval : Env β Expr β Value β Prop where\n | var {env name idx val} :\n env[idx]? = some (Object.value val) β\n Eval env (Expr.var name idx) val\n | var_rec {env name idx env' expr val} :\n env[idx]? = some (Object.delayed env' expr) β\n Eval env' expr val β\n Eval env (Expr.var name idx) val\n | unit {env} :\n Eval env Expr.unit Value.unit\n | const {env c} :\n Eval env (Expr.const c) (Value.const c)\n | constr {env name} :\n Eval env (Expr.constr name) (Value.constr_app name [])\n | app {env env' f body arg val val'} :\n Eval env f (Value.closure env' body) β\n Eval env arg val β\n Eval (val β· env') body val' β\n Eval env (Expr.app f arg) val'\n | constr_app {env ctr ctr_name ctr_args_rev arg val} :\n Eval env ctr (Value.constr_app ctr_name ctr_args_rev) β\n Eval env arg val β\n Eval env (Expr.constr_app ctr arg) (Value.constr_app ctr_name (val :: ctr_args_rev))\n | binop {env op argβ argβ valβ valβ} :\n Eval env argβ (Value.const (Constant.int valβ)) β\n Eval env argβ (Value.const (Constant.int valβ)) β\n Eval env (Expr.binop op argβ argβ) (Value.const (Constant.int (eval_binop_int op valβ valβ)))\n | lambda {env name body} :\n Eval env (Expr.lambda name body) (Value.closure env body)\n | save {env name value body val val'} :\n Eval env value val β\n Eval (val β· env) body val' β\n Eval env (Expr.save name value body) val'\n | branch_matches {env name args_rev body val} :\n Eval (args_rev.map Object.value ++ env) body val β\n Eval (Value.constr_app name args_rev β· env) (Expr.branch name _ body _) val\n | branch_fails {env name name' args_rev next val} :\n name β name' β\n Eval (Value.constr_app name args_rev β· env) next val β\n Eval (Value.constr_app name args_rev β· env) (Expr.branch name' _ _ next) val\n | recur {env name body val} :\n Eval (Object.delayed env (Expr.recur name body) :: env) body val β\n Eval env (Expr.recur name body) val"
},
{
"name": "eval_binop_int",
"content": "def eval_binop_int (op : BinaryOp) (iβ iβ : Int) : Int :=\n match op with\n | BinaryOp.add_int => iβ + iβ\n | BinaryOp.sub_int => iβ - iβ\n | BinaryOp.mul_int => iβ * iβ\n | BinaryOp.div_int => iβ / iβ"
},
{
"name": "BinaryOp",
"content": "inductive BinaryOp : Type where\n | add_int : BinaryOp\n | sub_int : BinaryOp\n | mul_int : BinaryOp\n | div_int : BinaryOp\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "cons_value",
"content": "abbrev cons_value (v : Value) (env : Env) : Env := Object.value v :: env\n\n inductive Object : Type where\n | value : Value β Object\n | delayed : (env : List Object) β Expr β Object\n deriving Inhabited"
},
{
"name": "Name",
"content": "abbrev Name : Type := String"
},
{
"name": "Env",
"content": "abbrev Env : Type := List Object"
},
{
"name": "infixr:50 \" β· \" => cons_value",
"content": "infixr:50 \" β· \" => cons_value"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v"
},
{
"name": "infixl:100 \" @@ \" => Expr.app",
"content": "infixl:100 \" @@ \" => Expr.app"
}
] | [
{
"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]"
}
] | [] | [] | import Juvix.Core.Main.Tactics.Base
namespace Juvix.Core.Main | lemma Termination.binop {env op eβ eβ cβ cβ} :
env β’ eβ β¦ Value.const (Constant.int cβ) β
env β’ eβ β¦ Value.const (Constant.int cβ) β
env β’ Expr.binop op eβ eβ β := | := by
intro hβ hβ
constructor
apply Juvix.Core.Main.Eval.binop
Β· assumption
Β· assumption | 4 | 18 | false | Semantics |
262 | Juvix.Core.Main.Object.Approx.trans | @[trans]
lemma Object.Approx.trans {oβ oβ oβ} : oβ β²β oβ β oβ β²β oβ β oβ β²β oβ | juvix-lean | Juvix/Core/Main/Semantics/Approx.lean | [
"import Juvix.Core.Main.Semantics.Approx.Indexed",
"import Juvix.Utils"
] | [
{
"name": "BEq",
"module": "Init.Prelude"
},
{
"name": "DecidableEq",
"module": "Init.Prelude"
},
{
"name": "Inhabited",
"module": "Init.Prelude"
},
{
"name": "Int",
"module": "Init.Data.Int.Basic"
},
{
"name": "String",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "closure",
"module": "Mathlib.Topology.Defs.Basic"
},
{
"name": "List.Forallβ",
"module": "Batteries.Data.List.Basic"
},
{
"name": "IsEmpty",
"module": "Mathlib.Logic.IsEmpty"
}
] | [
{
"name": "notation:40 e:40 \" β²β¨\" env:40 \", \" env':40 \"β© \" e':40 => Exp",
"content": "notation:40 e:40 \" β²β¨\" env:40 \", \" env':40 \"β© \" e':40 => Expr.Approx.Param env env' e e'"
},
{
"name": "notation:40 eβ:40 \" β² \" eβ:40 => Expr.Approx eβ eβ",
"content": "notation:40 eβ:40 \" β² \" eβ:40 => Expr.Approx eβ eβ"
},
{
"name": "notation:40 envβ:40 \" β²β \" envβ:40 => Env.Approx envβ envβ",
"content": "notation:40 envβ:40 \" β²β \" envβ:40 => Env.Approx envβ envβ"
},
{
"name": "notation:40 v:40 \" β²α΅₯ \" v':40 => Value.Approx v v'",
"content": "notation:40 v:40 \" β²α΅₯ \" v':40 => Value.Approx v v'"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β\" => Eval.Defined env e",
"content": "notation:40 env:40 \" β’ \" e:40 \" β\" => Eval.Defined env e"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Inde",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Indexed n env e v"
},
{
"name": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Inde",
"content": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Indexed n v v'"
},
{
"name": "notation:40 argsβ:40 \" β²β \" argsβ:40 => List.Forallβ Value.A",
"content": "notation:40 argsβ:40 \" β²β \" argsβ:40 => List.Forallβ Value.Approx argsβ argsβ"
},
{
"name": "macro \"invert\" h:term : tactic => `(tactic| (cases ($h).inve",
"content": "macro \"invert\" h:term : tactic => `(tactic| (cases ($h).invert <;> try clear $h))"
},
{
"name": "notation:40 argsβ:40 \" β²β(\" n:40 \") \" argsβ:40 => List.Foral",
"content": "notation:40 argsβ:40 \" β²β(\" n:40 \") \" argsβ:40 => List.Forallβ (Value.Approx.Indexed n) argsβ argsβ\n\nsyntax \"case \" expr \" of \" cases \" end\" : expr"
},
{
"name": "notation:40 v:40 \" β²β \" v':40 => Object.Approx v v'",
"content": "notation:40 v:40 \" β²β \" v':40 => Object.Approx v v'"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(βͺ$s:ident β― $i:numβ«) => `(Expr.var $(Lean.Syntax.mkStrLit s.getId.toString) $i)\n | `(βͺ$num:numβ«) => `(Expr.const (Constant.int $num))\n | `(βͺ$s:strβ«) => `(Expr.const (Constant.string $s))\n | `(βͺΟ
β«) => `(Expr.unit)\n | `(βͺ$eβ:expr $eβ:exprβ«) => `(Expr.app βͺ$eββ« βͺ$eββ«)\n | `(βͺΞ» $s:ident $e:exprβ«) => `(Expr.lambda $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eβ«)\n | `(βͺΞ» $ss:ident* . $e:exprβ«) => mkLambdas ss e\n | `(βͺ $s:ident β«) => `(Expr.constr $(Lean.Syntax.mkStrLit s.getId.toString))\n | `(βͺ $s:ident $es:expr* β«) => mkConstrApp s es\n | `(βͺ$eβ + $eββ«) => `(Expr.binop BinaryOp.add_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ - $eββ«) => `(Expr.binop BinaryOp.sub_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ * $eββ«) => `(Expr.binop BinaryOp.mul_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ / $eββ«) => `(Expr.binop BinaryOp.div_int βͺ$eββ« βͺ$eββ«)\n | `(βͺlet $s:ident := $eβ:expr in $eβ:exprβ«) => `(Expr.save $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eββ« βͺ$eββ«)\n | `(βͺletrec $s:ident := $eβ:expr in $eβ:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.save $name (Expr.recur $name βͺ$eββ«) βͺ$eββ«)\n | `(βͺrec $s:ident $e:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.recur $name βͺ$eβ«)\n | `(βͺβ₯β«) => `(Expr.fail)\n | `(βͺcases| | $s:ident => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« Expr.fail)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« Expr.fail)\n | `(βͺcases| | _ => $e:expr β«) =>\n `(βͺ$eβ«)\n | `(βͺcase $e:expr of $cs:cases endβ«) => do\n `(Expr.save \"_case_\" βͺ$eβ« βͺcases|$csβ«)\n | `(βͺ($e)β«) => `(βͺ$eβ«)\n\n inductive Object : Type where\n | value : Value β Object\n | delayed : (env : List Object) β Expr β Object\n deriving Inhabited"
},
{
"name": "Env",
"content": "abbrev Env : Type := List Object\n\n inductive Value : Type where\n | unit : Value\n | const : Constant β Value\n | constr_app : (constr : Name) β (args_rev : List Value) β Value\n | closure : (env : List Object) β (value : Expr) β Value\n deriving Inhabited"
},
{
"name": "Constant",
"content": "inductive Constant : Type where\n | int : Int β Constant\n | string : String β Constant\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Expr",
"content": "inductive Expr : Type where\n | var : (name : String) β (index : Nat) β Expr\n | unit : Expr\n | const : Constant β Expr\n | constr : Name β Expr\n | app : Expr β Expr β Expr\n | constr_app : Expr β Expr β Expr\n | binop : (oper : BinaryOp) β (argβ argβ : Expr) β Expr\n | lambda : (var_name : String) β (body : Expr) β Expr\n | save : (var_name : String) β (value : Expr) β (body : Expr) β Expr\n | branch : (constr : Name) β (var_names : List Name) β (body : Expr) β (next : Expr) β Expr\n | recur : (var_name : Name) β (body : Expr) β Expr\n | fail : Expr\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "BinaryOp",
"content": "inductive BinaryOp : Type where\n | add_int : BinaryOp\n | sub_int : BinaryOp\n | mul_int : BinaryOp\n | div_int : BinaryOp\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Name",
"content": "abbrev Name : Type := String"
},
{
"name": "Value.Approx.Indexed",
"content": "def Value.Approx.Indexed (n : Nat) (vβ vβ : Value) : Prop :=\n (vβ = Value.unit β§ vβ = Value.unit) β¨\n (β c, vβ = Value.const c β§ vβ = Value.const c) β¨\n (β ctr_name args_rev args_rev',\n vβ = Value.constr_app ctr_name args_rev β§\n vβ = Value.constr_app ctr_name args_rev' β§\n (β k < n, List.Forallβ (Value.Approx.Indexed k) args_rev args_rev')) β¨\n (β envβ bodyβ envβ bodyβ,\n vβ = Value.closure envβ bodyβ β§\n vβ = Value.closure envβ bodyβ β§\n (β nβ nβ, nβ + nβ < n β\n β aβ aβ rβ,\n Value.Approx.Indexed (nβ + nβ) aβ aβ β\n aβ β· envβ β’ bodyβ β¦(nβ) rβ β\n β rβ,\n aβ β· envβ β’ bodyβ β¦ rβ β§\n Value.Approx.Indexed nβ rβ rβ))"
},
{
"name": "cons_value",
"content": "abbrev cons_value (v : Value) (env : Env) : Env := Object.value v :: env"
},
{
"name": "Value.Approx.Indexed.Inversion",
"content": "@[aesop safe cases]\ninductive Value.Approx.Indexed.Inversion (n : Nat) : Value β Value β Prop where\n | unit : Value.Approx.Indexed.Inversion n Value.unit Value.unit\n | const {c} : Value.Approx.Indexed.Inversion n (Value.const c) (Value.const c)\n | constr_app {ctr_name args_rev args_rev'} :\n (β k < n, args_rev β²β(k) args_rev') β\n Value.Approx.Indexed.Inversion n (Value.constr_app ctr_name args_rev) (Value.constr_app ctr_name args_rev')\n | closure {envβ bodyβ envβ bodyβ} :\n (β nβ nβ, nβ + nβ < n β\n β aβ aβ vβ,\n aβ β²α΅₯(nβ + nβ) aβ β\n aβ β· envβ β’ bodyβ β¦(nβ) vβ β\n β vβ, aβ β· envβ β’ bodyβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ) β\n Value.Approx.Indexed.Inversion n (Value.closure envβ bodyβ) (Value.closure envβ bodyβ)"
},
{
"name": "infixr:50 \" β· \" => cons_value",
"content": "infixr:50 \" β· \" => cons_value"
},
{
"name": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Inde",
"content": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Indexed n v v'"
},
{
"name": "infixl:100 \" @@ \" => Expr.app",
"content": "infixl:100 \" @@ \" => Expr.app"
}
] | [
{
"name": "IsEmpty.forall_iff",
"module": "Mathlib.Logic.IsEmpty"
},
{
"name": "implies_true",
"module": "Init.SimpLemmas"
},
{
"name": "nonpos_iff_eq_zero",
"module": "Mathlib.Algebra.Order.Monoid.Canonical.Defs"
},
{
"name": "not_lt_zero'",
"module": "Mathlib.Algebra.Order.GroupWithZero.Canonical"
}
] | [
{
"name": "Value.Approx.Indexed.invert",
"content": "@[aesop unsafe destruct]\nlemma Value.Approx.Indexed.invert {n v v'} :\n v β²α΅₯(n) v' β\n Value.Approx.Indexed.Inversion n v v'"
},
{
"name": "Value.Approx.Indexed.constr_app",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.constr_app {n ctr_name args_rev args_rev'} :\n (β k < n, args_rev β²β(k) args_rev') β\n Value.constr_app ctr_name args_rev β²α΅₯(n) Value.constr_app ctr_name args_rev'"
},
{
"name": "Value.Approx.Indexed.unit",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.unit {n} : Value.unit β²α΅₯(n) Value.unit"
},
{
"name": "Value.Approx.Indexed.const",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.const {n c} : Value.const c β²α΅₯(n) Value.const c"
},
{
"name": "Value.Approx.Indexed.closure",
"content": "@[aesop unsafe apply]\nlemma Value.Approx.Indexed.closure {n envβ bodyβ envβ bodyβ} :\n (β nβ nβ, nβ + nβ < n β\n β aβ aβ vβ,\n aβ β²α΅₯(nβ + nβ) aβ β\n aβ β· envβ β’ bodyβ β¦(nβ) vβ β\n β vβ, aβ β· envβ β’ bodyβ β¦ vβ β§ vβ β²α΅₯(nβ) vβ) β\n Value.closure envβ bodyβ β²α΅₯(n) Value.closure envβ bodyβ"
},
{
"name": "forallβ_trans'",
"content": "theorem forallβ_trans' {Ξ±} {P Q R : Ξ± β Ξ± β Prop} {lβ lβ lβ}\n (h : β x y z, P x y β Q y z β R x z)\n (hβ : List.Forallβ P lβ lβ)\n (hβ : List.Forallβ Q lβ lβ)\n : List.Forallβ R lβ lβ"
}
] | [
{
"name": "Juvix.Core.Main.Value.Approx",
"content": "def Value.Approx (v v' : Value) : Prop :=\n β n, v β²α΅₯(n) v'"
},
{
"name": "Juvix.Core.Main.Expr.Approx.Param",
"content": "def Expr.Approx.Param (envβ envβ : Env) (eβ eβ : Expr) : Prop :=\n (β vβ, envβ β’ eβ β¦ vβ β β vβ, envβ β’ eβ β¦ vβ β§ vβ β²α΅₯ vβ)"
},
{
"name": "Juvix.Core.Main.Object.Approx",
"content": "inductive Object.Approx : Object β Object β Prop where\n | value {vβ vβ} : vβ β²α΅₯ vβ β Object.Approx (Object.value vβ) (Object.value vβ)\n | delayed {envβ envβ eβ eβ} :\n eβ β²β¨envβ, envββ© eβ β\n Object.Approx (Object.delayed envβ eβ) (Object.delayed envβ eβ)"
},
{
"name": "Juvix.Core.Main.Expr.Approx",
"content": "def Expr.Approx (eβ eβ : Expr) : Prop :=\n β envβ envβ, envβ β²β envβ β eβ β²β¨envβ, envββ© eβ"
},
{
"name": "Juvix.Core.Main.Value.Approx.Inversion",
"content": "@[aesop safe cases]\ninductive Value.Approx.Inversion : Value -> Value -> Prop where\n | unit : Value.Approx.Inversion Value.unit Value.unit\n | const {c} : Value.Approx.Inversion (Value.const c) (Value.const c)\n | constr_app {ctr_name args_rev args_rev'} :\n args_rev β²β args_rev' β\n Value.Approx.Inversion (Value.constr_app ctr_name args_rev) (Value.constr_app ctr_name args_rev')\n | closure {envβ bodyβ envβ bodyβ} :\n (β aβ aβ, aβ β²α΅₯ aβ β bodyβ β²β¨aβ β· envβ, aβ β· envββ© bodyβ) β\n Value.Approx.Inversion (Value.closure envβ bodyβ) (Value.closure envβ bodyβ)"
}
] | [
{
"name": "Juvix.Core.Main.Value.Approx.invert",
"content": "@[aesop unsafe destruct]\nlemma Value.Approx.invert {v v'} :\n v β²α΅₯ v' β\n Value.Approx.Inversion v v'"
},
{
"name": "Juvix.Core.Main.Value.Approx.Indexed.trans",
"content": "@[trans]\nlemma Value.Approx.Indexed.trans {n vβ vβ vβ} : vβ β²α΅₯(n) vβ β vβ β²α΅₯ vβ β vβ β²α΅₯(n) vβ"
},
{
"name": "Juvix.Core.Main.Value.Approx.trans",
"content": "@[trans]\nlemma Value.Approx.trans {vβ vβ vβ} : vβ β²α΅₯ vβ β vβ β²α΅₯ vβ β vβ β²α΅₯ vβ"
},
{
"name": "Juvix.Core.Main.Expr.Approx.Param.trans",
"content": "lemma Expr.Approx.Param.trans {envβ envβ envβ eβ eβ eβ} :\n eβ β²β¨envβ, envββ© eβ β eβ β²β¨envβ, envββ© eβ β eβ β²β¨envβ, envββ© eβ"
}
] | import Juvix.Core.Main.Semantics.Approx.Indexed
namespace Juvix.Core.Main
def Value.Approx (v v' : Value) : Prop :=
β n, v β²α΅₯(n) v'
notation:40 v:40 " β²α΅₯ " v':40 => Value.Approx v v'
notation:40 argsβ:40 " β²β " argsβ:40 => List.Forallβ Value.Approx argsβ argsβ
def Expr.Approx.Param (envβ envβ : Env) (eβ eβ : Expr) : Prop :=
(β vβ, envβ β’ eβ β¦ vβ β β vβ, envβ β’ eβ β¦ vβ β§ vβ β²α΅₯ vβ)
notation:40 e:40 " β²β¨" env:40 ", " env':40 "β© " e':40 => Expr.Approx.Param env env' e e'
inductive Object.Approx : Object β Object β Prop where
| value {vβ vβ} : vβ β²α΅₯ vβ β Object.Approx (Object.value vβ) (Object.value vβ)
| delayed {envβ envβ eβ eβ} :
eβ β²β¨envβ, envββ© eβ β
Object.Approx (Object.delayed envβ eβ) (Object.delayed envβ eβ)
notation:40 v:40 " β²β " v':40 => Object.Approx v v'
notation:40 envβ:40 " β²β " envβ:40 => Env.Approx envβ envβ
def Expr.Approx (eβ eβ : Expr) : Prop :=
β envβ envβ, envβ β²β envβ β eβ β²β¨envβ, envββ© eβ
notation:40 eβ:40 " β² " eβ:40 => Expr.Approx eβ eβ
@[aesop safe cases]
inductive Value.Approx.Inversion : Value -> Value -> Prop where
| unit : Value.Approx.Inversion Value.unit Value.unit
| const {c} : Value.Approx.Inversion (Value.const c) (Value.const c)
| constr_app {ctr_name args_rev args_rev'} :
args_rev β²β args_rev' β
Value.Approx.Inversion (Value.constr_app ctr_name args_rev) (Value.constr_app ctr_name args_rev')
| closure {envβ bodyβ envβ bodyβ} :
(β aβ aβ, aβ β²α΅₯ aβ β bodyβ β²β¨aβ β· envβ, aβ β· envββ© bodyβ) β
Value.Approx.Inversion (Value.closure envβ bodyβ) (Value.closure envβ bodyβ) | @[trans]
lemma Object.Approx.trans {oβ oβ oβ} : oβ β²β oβ β oβ β²β oβ β oβ β²β oβ := | := by
intros hβ hβ
cases hβ
case value vβ vβ happrox =>
cases hβ
case value vβ happrox' =>
apply Object.Approx.value
trans vβ <;> assumption
case delayed envβ envβ eβ eβ happrox =>
cases hβ
case delayed envβ' eβ' happrox' =>
apply Object.Approx.delayed
exact Expr.Approx.Param.trans happrox happrox' | 6 | 39 | false | Semantics |
263 | Juvix.Core.Main.Env.Approx.cons_value | lemma Env.Approx.cons_value {vβ vβ env} :
vβ β²α΅₯ vβ β vβ β· env β²β vβ β· env | juvix-lean | Juvix/Core/Main/Semantics/Approx.lean | [
"import Juvix.Core.Main.Semantics.Approx.Indexed"
] | [
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "List.Forallβ",
"module": "Batteries.Data.List.Basic"
},
{
"name": "BEq",
"module": "Init.Prelude"
},
{
"name": "DecidableEq",
"module": "Init.Prelude"
},
{
"name": "Inhabited",
"module": "Init.Prelude"
},
{
"name": "Int",
"module": "Init.Data.Int.Basic"
},
{
"name": "String",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "closure",
"module": "Mathlib.Topology.Defs.Basic"
},
{
"name": "List.Forallβ.cons",
"module": "Batteries.Data.List.Basic"
},
{
"name": "List.Forallβ.nil",
"module": "Batteries.Data.List.Basic"
}
] | [
{
"name": "notation:40 e:40 \" β²β¨\" env:40 \", \" env':40 \"β© \" e':40 => Exp",
"content": "notation:40 e:40 \" β²β¨\" env:40 \", \" env':40 \"β© \" e':40 => Expr.Approx.Param env env' e e'"
},
{
"name": "notation:40 v:40 \" β²α΅₯ \" v':40 => Value.Approx v v'",
"content": "notation:40 v:40 \" β²α΅₯ \" v':40 => Value.Approx v v'"
},
{
"name": "notation:40 eβ:40 \" β² \" eβ:40 => Expr.Approx eβ eβ",
"content": "notation:40 eβ:40 \" β² \" eβ:40 => Expr.Approx eβ eβ"
},
{
"name": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Inde",
"content": "notation:40 v:40 \" β²α΅₯(\" n:40 \") \" v':40 => Value.Approx.Indexed n v v'\n\nsyntax \"case \" expr \" of \" cases \" end\" : expr"
},
{
"name": "notation:40 v:40 \" β²β \" v':40 => Object.Approx v v'",
"content": "notation:40 v:40 \" β²β \" v':40 => Object.Approx v v'"
},
{
"name": "notation:40 envβ:40 \" β²β \" envβ:40 => Env.Approx envβ envβ",
"content": "notation:40 envβ:40 \" β²β \" envβ:40 => Env.Approx envβ envβ"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(βͺ$s:ident β― $i:numβ«) => `(Expr.var $(Lean.Syntax.mkStrLit s.getId.toString) $i)\n | `(βͺ$num:numβ«) => `(Expr.const (Constant.int $num))\n | `(βͺ$s:strβ«) => `(Expr.const (Constant.string $s))\n | `(βͺΟ
β«) => `(Expr.unit)\n | `(βͺ$eβ:expr $eβ:exprβ«) => `(Expr.app βͺ$eββ« βͺ$eββ«)\n | `(βͺΞ» $s:ident $e:exprβ«) => `(Expr.lambda $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eβ«)\n | `(βͺΞ» $ss:ident* . $e:exprβ«) => mkLambdas ss e\n | `(βͺ $s:ident β«) => `(Expr.constr $(Lean.Syntax.mkStrLit s.getId.toString))\n | `(βͺ $s:ident $es:expr* β«) => mkConstrApp s es\n | `(βͺ$eβ + $eββ«) => `(Expr.binop BinaryOp.add_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ - $eββ«) => `(Expr.binop BinaryOp.sub_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ * $eββ«) => `(Expr.binop BinaryOp.mul_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ / $eββ«) => `(Expr.binop BinaryOp.div_int βͺ$eββ« βͺ$eββ«)\n | `(βͺlet $s:ident := $eβ:expr in $eβ:exprβ«) => `(Expr.save $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eββ« βͺ$eββ«)\n | `(βͺletrec $s:ident := $eβ:expr in $eβ:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.save $name (Expr.recur $name βͺ$eββ«) βͺ$eββ«)\n | `(βͺrec $s:ident $e:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.recur $name βͺ$eβ«)\n | `(βͺβ₯β«) => `(Expr.fail)\n | `(βͺcases| | $s:ident => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« Expr.fail)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« Expr.fail)\n | `(βͺcases| | _ => $e:expr β«) =>\n `(βͺ$eβ«)\n | `(βͺcase $e:expr of $cs:cases endβ«) => do\n `(Expr.save \"_case_\" βͺ$eβ« βͺcases|$csβ«)\n | `(βͺ($e)β«) => `(βͺ$eβ«)\n\n inductive Object : Type where\n | value : Value β Object\n | delayed : (env : List Object) β Expr β Object\n deriving Inhabited"
},
{
"name": "cons_value",
"content": "abbrev cons_value (v : Value) (env : Env) : Env := Object.value v :: env\n\n inductive Value : Type where\n | unit : Value\n | const : Constant β Value\n | constr_app : (constr : Name) β (args_rev : List Value) β Value\n | closure : (env : List Object) β (value : Expr) β Value\n deriving Inhabited"
},
{
"name": "Expr",
"content": "inductive Expr : Type where\n | var : (name : String) β (index : Nat) β Expr\n | unit : Expr\n | const : Constant β Expr\n | constr : Name β Expr\n | app : Expr β Expr β Expr\n | constr_app : Expr β Expr β Expr\n | binop : (oper : BinaryOp) β (argβ argβ : Expr) β Expr\n | lambda : (var_name : String) β (body : Expr) β Expr\n | save : (var_name : String) β (value : Expr) β (body : Expr) β Expr\n | branch : (constr : Name) β (var_names : List Name) β (body : Expr) β (next : Expr) β Expr\n | recur : (var_name : Name) β (body : Expr) β Expr\n | fail : Expr\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "BinaryOp",
"content": "inductive BinaryOp : Type where\n | add_int : BinaryOp\n | sub_int : BinaryOp\n | mul_int : BinaryOp\n | div_int : BinaryOp\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Constant",
"content": "inductive Constant : Type where\n | int : Int β Constant\n | string : String β Constant\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Name",
"content": "abbrev Name : Type := String"
},
{
"name": "Env",
"content": "abbrev Env : Type := List Object"
},
{
"name": "infixr:50 \" β· \" => cons_value",
"content": "infixr:50 \" β· \" => cons_value"
},
{
"name": "infixl:100 \" @@ \" => Expr.app",
"content": "infixl:100 \" @@ \" => Expr.app"
}
] | [
{
"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": "Juvix.Core.Main.Value.Approx",
"content": "def Value.Approx (v v' : Value) : Prop :=\n β n, v β²α΅₯(n) v'"
},
{
"name": "Juvix.Core.Main.Object.Approx",
"content": "inductive Object.Approx : Object β Object β Prop where\n | value {vβ vβ} : vβ β²α΅₯ vβ β Object.Approx (Object.value vβ) (Object.value vβ)\n | delayed {envβ envβ eβ eβ} :\n eβ β²β¨envβ, envββ© eβ β\n Object.Approx (Object.delayed envβ eβ) (Object.delayed envβ eβ)"
},
{
"name": "Juvix.Core.Main.Env.Approx",
"content": "def Env.Approx : (envβ envβ : Env) β Prop :=\n List.Forallβ Object.Approx"
}
] | [
{
"name": "Juvix.Core.Main.Value.Approx.refl",
"content": "@[refl]\nlemma Value.Approx.refl v : v β²α΅₯ v"
},
{
"name": "Juvix.Core.Main.Object.Approx.refl",
"content": "@[refl]\nlemma Object.Approx.refl {o} : o β²β o"
},
{
"name": "Juvix.Core.Main.Env.Approx.refl",
"content": "@[refl]\nlemma Env.Approx.refl {env} : env β²β env"
},
{
"name": "Juvix.Core.Main.Env.Approx.cons",
"content": "lemma Env.Approx.cons {envβ envβ oβ oβ} :\n oβ β²β oβ β envβ β²β envβ β (oβ :: envβ) β²β (oβ :: envβ)"
}
] | import Juvix.Core.Main.Semantics.Approx.Indexed
namespace Juvix.Core.Main
def Value.Approx (v v' : Value) : Prop :=
β n, v β²α΅₯(n) v'
notation:40 v:40 " β²α΅₯ " v':40 => Value.Approx v v'
notation:40 argsβ:40 " β²β " argsβ:40 => List.Forallβ Value.Approx argsβ argsβ
notation:40 e:40 " β²β¨" env:40 ", " env':40 "β© " e':40 => Expr.Approx.Param env env' e e'
inductive Object.Approx : Object β Object β Prop where
| value {vβ vβ} : vβ β²α΅₯ vβ β Object.Approx (Object.value vβ) (Object.value vβ)
| delayed {envβ envβ eβ eβ} :
eβ β²β¨envβ, envββ© eβ β
Object.Approx (Object.delayed envβ eβ) (Object.delayed envβ eβ)
def Env.Approx : (envβ envβ : Env) β Prop :=
List.Forallβ Object.Approx
notation:40 v:40 " β²β " v':40 => Object.Approx v v'
notation:40 envβ:40 " β²β " envβ:40 => Env.Approx envβ envβ
notation:40 eβ:40 " β² " eβ:40 => Expr.Approx eβ eβ | lemma Env.Approx.cons_value {vβ vβ env} :
vβ β²α΅₯ vβ β vβ β· env β²β vβ β· env := | := by
intro h
apply Env.Approx.cons
Β· apply Object.Approx.value
assumption
Β· apply Env.Approx.refl | 4 | 26 | false | Semantics |
264 | Juvix.Core.Main.Termination.branch_matches | lemma Termination.branch_matches {env name vnames args_rev e e'} :
args_rev.map Object.value ++ env β’ e β β
Value.constr_app name args_rev β· env β’ Expr.branch name vnames e e' β | juvix-lean | Juvix/Core/Main/Tactics/Termination.lean | [
"import Juvix.Core.Main.Tactics.Base"
] | [
{
"name": "BEq",
"module": "Init.Prelude"
},
{
"name": "DecidableEq",
"module": "Init.Prelude"
},
{
"name": "Inhabited",
"module": "Init.Prelude"
},
{
"name": "Int",
"module": "Init.Data.Int.Basic"
},
{
"name": "String",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "closure",
"module": "Mathlib.Topology.Defs.Basic"
}
] | [
{
"name": "syntax:100 expr:100 ppSpace expr:101 : expr",
"content": "syntax:100 expr:100 ppSpace expr:101 : expr\n\nsyntax:50 expr:50 \" + \" expr:51 : expr\n\nsyntax:50 expr:50 \" - \" expr:50 : expr\n\nsyntax:60 expr:60 \" * \" expr:61 : expr\n\nsyntax:60 expr:60 \" / \" expr:60 : expr"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β\" => Eval.Defined env e",
"content": "notation:40 env:40 \" β’ \" e:40 \" β\" => Eval.Defined env e"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Inde",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦(\" n \") \" v:40 => Eval.Indexed n env e v"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(βͺ$s:ident β― $i:numβ«) => `(Expr.var $(Lean.Syntax.mkStrLit s.getId.toString) $i)\n | `(βͺ$num:numβ«) => `(Expr.const (Constant.int $num))\n | `(βͺ$s:strβ«) => `(Expr.const (Constant.string $s))\n | `(βͺΟ
β«) => `(Expr.unit)\n | `(βͺ$eβ:expr $eβ:exprβ«) => `(Expr.app βͺ$eββ« βͺ$eββ«)\n | `(βͺΞ» $s:ident $e:exprβ«) => `(Expr.lambda $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eβ«)\n | `(βͺΞ» $ss:ident* . $e:exprβ«) => mkLambdas ss e\n | `(βͺ $s:ident β«) => `(Expr.constr $(Lean.Syntax.mkStrLit s.getId.toString))\n | `(βͺ $s:ident $es:expr* β«) => mkConstrApp s es\n | `(βͺ$eβ + $eββ«) => `(Expr.binop BinaryOp.add_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ - $eββ«) => `(Expr.binop BinaryOp.sub_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ * $eββ«) => `(Expr.binop BinaryOp.mul_int βͺ$eββ« βͺ$eββ«)\n | `(βͺ$eβ / $eββ«) => `(Expr.binop BinaryOp.div_int βͺ$eββ« βͺ$eββ«)\n | `(βͺlet $s:ident := $eβ:expr in $eβ:exprβ«) => `(Expr.save $(Lean.Syntax.mkStrLit s.getId.toString) βͺ$eββ« βͺ$eββ«)\n | `(βͺletrec $s:ident := $eβ:expr in $eβ:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.save $name (Expr.recur $name βͺ$eββ«) βͺ$eββ«)\n | `(βͺrec $s:ident $e:exprβ«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.recur $name βͺ$eβ«)\n | `(βͺβ₯β«) => `(Expr.fail)\n | `(βͺcases| | $s:ident => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr $cs:cases β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« βͺcases|$csβ«)\n | `(βͺcases| | $s:ident => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n `(Expr.branch $name [] βͺ$eβ« Expr.fail)\n | `(βͺcases| | $s:ident $ss:ident* => $e:expr β«) =>\n let name := Lean.Syntax.mkStrLit s.getId.toString\n let vnames := ss.toList.map fun s => s.getId.toString\n `(Expr.branch $name $(quote vnames) βͺ$eβ« Expr.fail)\n | `(βͺcases| | _ => $e:expr β«) =>\n `(βͺ$eβ«)\n | `(βͺcase $e:expr of $cs:cases endβ«) => do\n `(Expr.save \"_case_\" βͺ$eβ« βͺcases|$csβ«)\n | `(βͺ($e)β«) => `(βͺ$eβ«)"
},
{
"name": "Eval",
"content": "@[aesop unsafe constructors]\ninductive Eval : Env β Expr β Value β Prop where\n | var {env name idx val} :\n env[idx]? = some (Object.value val) β\n Eval env (Expr.var name idx) val\n | var_rec {env name idx env' expr val} :\n env[idx]? = some (Object.delayed env' expr) β\n Eval env' expr val β\n Eval env (Expr.var name idx) val\n | unit {env} :\n Eval env Expr.unit Value.unit\n | const {env c} :\n Eval env (Expr.const c) (Value.const c)\n | constr {env name} :\n Eval env (Expr.constr name) (Value.constr_app name [])\n | app {env env' f body arg val val'} :\n Eval env f (Value.closure env' body) β\n Eval env arg val β\n Eval (val β· env') body val' β\n Eval env (Expr.app f arg) val'\n | constr_app {env ctr ctr_name ctr_args_rev arg val} :\n Eval env ctr (Value.constr_app ctr_name ctr_args_rev) β\n Eval env arg val β\n Eval env (Expr.constr_app ctr arg) (Value.constr_app ctr_name (val :: ctr_args_rev))\n | binop {env op argβ argβ valβ valβ} :\n Eval env argβ (Value.const (Constant.int valβ)) β\n Eval env argβ (Value.const (Constant.int valβ)) β\n Eval env (Expr.binop op argβ argβ) (Value.const (Constant.int (eval_binop_int op valβ valβ)))\n | lambda {env name body} :\n Eval env (Expr.lambda name body) (Value.closure env body)\n | save {env name value body val val'} :\n Eval env value val β\n Eval (val β· env) body val' β\n Eval env (Expr.save name value body) val'\n | branch_matches {env name args_rev body val} :\n Eval (args_rev.map Object.value ++ env) body val β\n Eval (Value.constr_app name args_rev β· env) (Expr.branch name _ body _) val\n | branch_fails {env name name' args_rev next val} :\n name β name' β\n Eval (Value.constr_app name args_rev β· env) next val β\n Eval (Value.constr_app name args_rev β· env) (Expr.branch name' _ _ next) val\n | recur {env name body val} :\n Eval (Object.delayed env (Expr.recur name body) :: env) body val β\n Eval env (Expr.recur name body) val"
},
{
"name": "eval_binop_int",
"content": "def eval_binop_int (op : BinaryOp) (iβ iβ : Int) : Int :=\n match op with\n | BinaryOp.add_int => iβ + iβ\n | BinaryOp.sub_int => iβ - iβ\n | BinaryOp.mul_int => iβ * iβ\n | BinaryOp.div_int => iβ / iβ"
},
{
"name": "BinaryOp",
"content": "inductive BinaryOp : Type where\n | add_int : BinaryOp\n | sub_int : BinaryOp\n | mul_int : BinaryOp\n | div_int : BinaryOp\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Expr",
"content": "inductive Expr : Type where\n | var : (name : String) β (index : Nat) β Expr\n | unit : Expr\n | const : Constant β Expr\n | constr : Name β Expr\n | app : Expr β Expr β Expr\n | constr_app : Expr β Expr β Expr\n | binop : (oper : BinaryOp) β (argβ argβ : Expr) β Expr\n | lambda : (var_name : String) β (body : Expr) β Expr\n | save : (var_name : String) β (value : Expr) β (body : Expr) β Expr\n | branch : (constr : Name) β (var_names : List Name) β (body : Expr) β (next : Expr) β Expr\n | recur : (var_name : Name) β (body : Expr) β Expr\n | fail : Expr\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "cons_value",
"content": "abbrev cons_value (v : Value) (env : Env) : Env := Object.value v :: env\n\n inductive Object : Type where\n | value : Value β Object\n | delayed : (env : List Object) β Expr β Object\n deriving Inhabited\n\n inductive Value : Type where\n | unit : Value\n | const : Constant β Value\n | constr_app : (constr : Name) β (args_rev : List Value) β Value\n | closure : (env : List Object) β (value : Expr) β Value\n deriving Inhabited"
},
{
"name": "Constant",
"content": "inductive Constant : Type where\n | int : Int β Constant\n | string : String β Constant\n deriving Inhabited, BEq, DecidableEq"
},
{
"name": "Name",
"content": "abbrev Name : Type := String"
},
{
"name": "Env",
"content": "abbrev Env : Type := List Object"
},
{
"name": "infixr:50 \" β· \" => cons_value",
"content": "infixr:50 \" β· \" => cons_value"
},
{
"name": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v",
"content": "notation:40 env:40 \" β’ \" e:40 \" β¦ \" v:40 => Eval env e v"
},
{
"name": "infixl:100 \" @@ \" => Expr.app",
"content": "infixl:100 \" @@ \" => Expr.app"
}
] | [
{
"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]"
}
] | [] | [] | import Juvix.Core.Main.Tactics.Base
namespace Juvix.Core.Main | lemma Termination.branch_matches {env name vnames args_rev e e'} :
args_rev.map Object.value ++ env β’ e β β
Value.constr_app name args_rev β· env β’ Expr.branch name vnames e e' β := | := by
intro h
obtain β¨w, hβ© := h
constructor
apply Juvix.Core.Main.Eval.branch_matches
assumption | 4 | 18 | false | Semantics |
265 | eval_bool_completeness | theorem eval_bool_completeness (e: BoolExpr V): BoolStepStar V val e (BoolExpr.Const (eval_bool V val e)) | LeanExprEvaluator | ExprEval/Basic.lean | [
"import ExprEval.Steps",
"import ExprEval.Lemmas",
"import ExprEval.Expr"
] | [
{
"name": "And",
"module": "Init.Prelude"
},
{
"name": "Bool",
"module": "Init.Prelude"
},
{
"name": "Eq",
"module": "Init.Prelude"
},
{
"name": "Not",
"module": "Init.Prelude"
},
{
"name": "Or",
"module": "Init.Prelude"
},
{
"name": "Add",
"module": "Init.Prelude"
},
{
"name": "Int",
"module": "Init.Data.Int.Basic"
},
{
"name": "Mul",
"module": "Init.Prelude"
},
{
"name": "Sub",
"module": "Init.Prelude"
},
{
"name": "BEq",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Repr",
"module": "Init.Data.Repr"
},
{
"name": "Vector",
"module": "Init.Data.Vector.Basic"
},
{
"name": "String",
"module": "Init.Prelude"
},
{
"name": "bool",
"module": "Init.Control.Basic"
},
{
"name": "ite",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Computation",
"module": "Mathlib.Data.Seq.Computation"
},
{
"name": "Max",
"module": "Init.Prelude"
},
{
"name": "Max.max",
"module": "Init.Prelude"
},
{
"name": "Option",
"module": "Init.Prelude"
}
] | [
{
"name": "BoolStepStar",
"content": "def BoolStepStar (V: Type) := StepStar (Step := BoolStep V) V"
},
{
"name": "BoolStep",
"content": "inductive BoolStep: (val: V -> Int) -> (BoolExpr V) -> (BoolExpr V) -> Prop where\n | notIsBoolNot (b: Bool): BoolStep val\n (BoolExpr.Not (BoolExpr.Const b))\n (BoolExpr.Const !b)\n | andLeftTrue (e: BoolExpr V): BoolStep val\n (BoolExpr.And (BoolExpr.Const true) e)\n e\n | orLeftFalse (e: BoolExpr V): BoolStep val\n (BoolExpr.Or (BoolExpr.Const false) e)\n e\n | andLeftShortCircuit e : BoolStep val\n (BoolExpr.And (BoolExpr.Const false) e)\n (BoolExpr.Const false)\n | orLeftShortCircuit e : BoolStep val\n (BoolExpr.Or (BoolExpr.Const true) e)\n (BoolExpr.Const true)\n | lessConstConstTrue nβ nβ : nβ < nβ -> BoolStep val\n (BoolExpr.Less (ArExpr.Const nβ) (ArExpr.Const nβ))\n (BoolExpr.Const true)\n | lessConstConstFalse nβ nβ : nβ >= nβ -> BoolStep val\n (BoolExpr.Less (ArExpr.Const nβ) (ArExpr.Const nβ))\n (BoolExpr.Const false)\n | eqConstConstTrue nβ nβ : nβ = nβ -> BoolStep val\n (BoolExpr.Eq (ArExpr.Const nβ) (ArExpr.Const nβ))\n (BoolExpr.Const true)\n | eqConstConstFalse nβ nβ : nβ != nβ -> BoolStep val\n (BoolExpr.Eq (ArExpr.Const nβ) (ArExpr.Const nβ))\n (BoolExpr.Const false)\n | lessArStepLeft (eβ eβ' eβ: ArExpr V):\n ArStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.Less eβ eβ)\n (BoolExpr.Less eβ' eβ)\n | eqArStepLeft (eβ eβ' eβ: ArExpr V):\n ArStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.Eq eβ eβ)\n (BoolExpr.Eq eβ' eβ)\n | lessArStepRight (eβ eβ eβ': ArExpr V):\n ArStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.Less eβ eβ)\n (BoolExpr.Less eβ eβ')\n | eqArStepRight (eβ eβ eβ': ArExpr V):\n ArStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.Eq eβ eβ)\n (BoolExpr.Eq eβ eβ')\n | orStepLeft (eβ eβ' eβ: BoolExpr V):\n BoolStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.Or eβ eβ)\n (BoolExpr.Or eβ' eβ)\n | andStepLeft (eβ eβ' eβ: BoolExpr V):\n BoolStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.And eβ eβ)\n (BoolExpr.And eβ' eβ)\n | notStep (e e' : BoolExpr V):\n BoolStep val e e' -> BoolStep val\n (BoolExpr.Not e)\n (BoolExpr.Not e')"
},
{
"name": "ArStep",
"content": "inductive ArStep: (val: V -> Int) -> (ArExpr V) -> (ArExpr V) -> Prop where\n | getVarValue (var: V) :\n ArStep\n val\n (ArExpr.Var var)\n (ArExpr.Const (val var))\n | addConstConst(nβ nβ: Int) :\n ArStep\n val\n (ArExpr.Add (ArExpr.Const nβ) (ArExpr.Const nβ))\n (ArExpr.Const (nβ + nβ))\n | subConstConst(nβ nβ: Int) :\n ArStep\n val\n (ArExpr.Sub (ArExpr.Const nβ) (ArExpr.Const nβ))\n (ArExpr.Const (nβ - nβ))\n | mulConstConst(nβ nβ: Int) :\n ArStep\n val\n (ArExpr.Mul (ArExpr.Const nβ) (ArExpr.Const nβ))\n (ArExpr.Const (nβ * nβ))\n | addLeft (eβ eβ' eβ) : ArStep val eβ eβ' -> ArStep val (ArExpr.Add eβ eβ) (ArExpr.Add eβ' eβ)\n\n | subLeft (eβ eβ' eβ) : ArStep val eβ eβ' -> ArStep val (ArExpr.Sub eβ eβ) (ArExpr.Sub eβ' eβ)\n\n | mulLeft (eβ eβ' eβ) : ArStep val eβ eβ' -> ArStep val (ArExpr.Mul eβ eβ) (ArExpr.Mul eβ' eβ)\n\n | addRight (n: Int) (eβ eβ': ArExpr V) : ArStep val eβ eβ' -> ArStep val (ArExpr.Add (ArExpr.Const n) eβ) (ArExpr.Add (ArExpr.Const n) eβ')\n\n | subRight (n: Int) (eβ eβ': ArExpr V) : ArStep val eβ eβ' -> ArStep val (ArExpr.Sub (ArExpr.Const n) eβ) (ArExpr.Sub (ArExpr.Const n) eβ')\n | mulRight (n: Int) (eβ eβ': ArExpr V) : ArStep val eβ eβ' -> ArStep val (ArExpr.Mul (ArExpr.Const n) eβ) (ArExpr.Mul (ArExpr.Const n) eβ')\n\n | ifStep (e e': BoolExpr V) (a b : ArExpr V): BoolStep val e e' ->\n ArStep val (ArExpr.If e a b) (ArExpr.If e' a b)\n | ifCondTrue (a b: ArExpr V) : ArStep val (ArExpr.If (BoolExpr.Const true) a b) a\n | ifCondFalse (a b: ArExpr V) : ArStep val (ArExpr.If (BoolExpr.Const false) a b) b\n\n inductive ArExpr: Type\n | Const: Int -> ArExpr\n | Add: ArExpr -> ArExpr -> ArExpr\n | Sub: ArExpr -> ArExpr -> ArExpr\n | Mul: ArExpr -> ArExpr -> ArExpr\n | Var: V -> ArExpr\n | If : BoolExpr -> ArExpr -> ArExpr -> ArExpr\n\n inductive BoolExpr : Type\n | Const: Bool -> BoolExpr\n | Less: ArExpr -> ArExpr -> BoolExpr\n | Eq: ArExpr -> ArExpr -> BoolExpr\n | Not : BoolExpr -> BoolExpr\n | And : BoolExpr -> BoolExpr -> BoolExpr\n | Or : BoolExpr -> BoolExpr -> BoolExpr"
},
{
"name": "StepStar",
"content": "inductive StepStar {ExprType: Type} {Step: StepKind V ExprType} : (val: V -> Int) -> ExprType -> ExprType -> Prop where\n | refl val e : StepStar val e e\n | trans eβ eβ eβ : Step val eβ eβ -> StepStar val eβ eβ -> StepStar val eβ eβ"
},
{
"name": "BoolStepStar.refl",
"content": "def BoolStepStar.refl {V: Type} (val: V -> Int) := StepStar.refl (Step := BoolStep V) val\n\n def eval (val: V -> Int) (e: ArExpr V) : Int :=\n match e with\n | ArExpr.Const x => x\n | ArExpr.Add lhs rhs => (eval val lhs) + (eval val rhs)\n | ArExpr.Sub lhs rhs => (eval val lhs) - (eval val rhs)\n | ArExpr.Mul lhs rhs => (eval val lhs) * (eval val rhs)\n | ArExpr.Var v => val v\n | ArExpr.If cond then_e else_e => if eval_bool val cond then eval val then_e else eval val else_e\n\n def eval_bool (val: V -> Int) (e: BoolExpr V): Bool :=\n match e with\n | BoolExpr.Const b => b\n | BoolExpr.Less l r => (eval val l) < (eval val r)\n | BoolExpr.Eq l r => (eval val l) == (eval val r)\n | BoolExpr.Not e => not (eval_bool val e)\n | BoolExpr.And l r => if eval_bool val l then eval_bool val r else false\n | BoolExpr.Or l r => if eval_bool val l then true else eval_bool val r"
},
{
"name": "ArStepStar.trans",
"content": "def ArStepStar.trans {V: Type} {val: V -> Int} eβ eβ eβ := StepStar.trans eβ eβ eβ (Step := ArStep V) (val := val)"
},
{
"name": "ArStepStar",
"content": "def ArStepStar (V: Type) := StepStar (Step := ArStep V) V"
},
{
"name": "ArStepStar.refl",
"content": "def ArStepStar.refl {V: Type} (val: V -> Int) := StepStar.refl (Step := ArStep V) val"
},
{
"name": "BoolStepStar.trans",
"content": "def BoolStepStar.trans {V: Type} {val: V -> Int} eβ eβ eβ := StepStar.trans eβ eβ eβ (Step := BoolStep V) (val := val)"
},
{
"name": "StepKind",
"content": "def StepKind (V: Type) (ExprType: Type):= (V -> Int) -> ExprType -> ExprType -> Prop"
}
] | [
{
"name": "Int.not_lt",
"module": "Init.Data.Int.Order"
},
{
"name": "bne_iff_ne",
"module": "Init.SimpLemmas"
},
{
"name": "decide_eq_false",
"module": "Init.Prelude"
},
{
"name": "decide_eq_true",
"module": "Init.Prelude"
},
{
"name": "eq_false_of_ne_true",
"module": "Init.Prelude"
},
{
"name": "ge_iff_le",
"module": "Init.Core"
},
{
"name": "ne_of_beq_false",
"module": "Init.Core"
}
] | [
{
"name": "BoolStepStar.andStepLeft",
"content": "theorem BoolStepStar.andStepLeft (eβ eβ' eβ: BoolExpr V):\n BoolStepStar V val eβ eβ' -> BoolStepStar V val\n (BoolExpr.And eβ eβ)\n (BoolExpr.And eβ' eβ)"
},
{
"name": "chasles_step_star",
"content": "theorem chasles_step_star {ExprKind: Type} {Step: StepKind V ExprKind} {eβ eβ eβ: ExprKind}:\n StepStar (Step := Step) V val eβ eβ ->\n StepStar (Step := Step) V val eβ eβ ->\n StepStar (Step := Step) V val eβ eβ"
},
{
"name": "BoolStepStar.lessArStepStarLeft",
"content": "theorem BoolStepStar.lessArStepStarLeft (eβ eβ' eβ: ArExpr V):\n ArStepStar V val eβ eβ' ->\n BoolStepStar V val\n (BoolExpr.Less eβ eβ)\n (BoolExpr.Less eβ' eβ)"
},
{
"name": "BoolStepStar.notStep",
"content": "theorem BoolStepStar.notStep {V: Type} {val: V -> Int}\n (e e': BoolExpr V):\n BoolStepStar V val e e' -> BoolStepStar V val (BoolExpr.Not e) (BoolExpr.Not e')"
},
{
"name": "BoolStepStar.lessArStepStarRight",
"content": "theorem BoolStepStar.lessArStepStarRight (eβ eβ eβ': ArExpr V):\n ArStepStar V val eβ eβ' ->\n BoolStepStar V val\n (BoolExpr.Less eβ eβ)\n (BoolExpr.Less eβ eβ')"
},
{
"name": "step_to_stepstar",
"content": "theorem step_to_stepstar {ExprKind: Type} {Step: StepKind V ExprKind} {e e': ExprKind}:\n Step val e e' -> StepStar (Step := Step) V val e e'"
},
{
"name": "BoolStepStar.eqArStepStarRight",
"content": "theorem BoolStepStar.eqArStepStarRight (eβ eβ eβ': ArExpr V):\n ArStepStar V val eβ eβ' ->\n BoolStepStar V val\n (BoolExpr.Eq eβ eβ)\n (BoolExpr.Eq eβ eβ')"
},
{
"name": "BoolStepStar.eqArStepStarLeft",
"content": "theorem BoolStepStar.eqArStepStarLeft (eβ eβ' eβ: ArExpr V):\n ArStepStar V val eβ eβ' ->\n BoolStepStar V val\n (BoolExpr.Eq eβ eβ)\n (BoolExpr.Eq eβ' eβ)"
},
{
"name": "BoolStepStar.orStepLeft",
"content": "theorem BoolStepStar.orStepLeft (eβ eβ' eβ: BoolExpr V):\n BoolStepStar V val eβ eβ' -> BoolStepStar V val\n (BoolExpr.Or eβ eβ)\n (BoolExpr.Or eβ' eβ)"
},
{
"name": "arstepstar_add_right",
"content": "theorem arstepstar_add_right (n: Int) (eβ eβ': ArExpr V) :\n ArStepStar V val eβ eβ' ->\n ArStepStar V val\n (ArExpr.Add (ArExpr.Const n) eβ)\n (ArExpr.Add (ArExpr.Const n) eβ')"
},
{
"name": "arstepstar_sub_left",
"content": "theorem arstepstar_sub_left (eβ eβ' eβ: ArExpr V) :\n ArStepStar V val eβ eβ' ->\n ArStepStar V val\n (ArExpr.Sub eβ eβ)\n (ArExpr.Sub eβ' eβ)"
},
{
"name": "arstepstar_add_left",
"content": "theorem arstepstar_add_left (eβ eβ' eβ: ArExpr V) :\n ArStepStar V val eβ eβ' -> ArStepStar V val (ArExpr.Add eβ eβ) (ArExpr.Add eβ' eβ)"
},
{
"name": "arstepstar_sub_right",
"content": "theorem arstepstar_sub_right (n: Int) (eβ eβ': ArExpr V) :\n ArStepStar V val eβ eβ' ->\n ArStepStar V val\n (ArExpr.Sub (ArExpr.Const n) eβ)\n (ArExpr.Sub (ArExpr.Const n) eβ')"
},
{
"name": "ArStepStar.ifStep",
"content": "theorem ArStepStar.ifStep (e e': BoolExpr V) (a b: ArExpr V): BoolStepStar V val e e' ->\n ArStepStar V val (ArExpr.If e a b) (ArExpr.If e' a b)"
},
{
"name": "arstepstar_mul_right",
"content": "theorem arstepstar_mul_right (n: Int) (eβ eβ': ArExpr V) :\n ArStepStar V val eβ eβ' ->\n ArStepStar V val\n (ArExpr.Mul (ArExpr.Const n) eβ)\n (ArExpr.Mul (ArExpr.Const n) eβ')"
},
{
"name": "arstepstar_mul_left",
"content": "theorem arstepstar_mul_left (eβ eβ' eβ: ArExpr V) :\n ArStepStar V val eβ eβ' ->\n ArStepStar V val\n (ArExpr.Mul eβ eβ)\n (ArExpr.Mul eβ' eβ)"
}
] | [] | [
{
"name": "eval_completeness",
"content": " theorem eval_completeness (e: ArExpr V) : ArStepStar V val e (ArExpr.Const (eval V val e))"
}
] | import ExprEval.Steps
import ExprEval.Lemmas
variable (V: Type) | theorem eval_bool_completeness (e: BoolExpr V): BoolStepStar V val e (BoolExpr.Const (eval_bool V val e)) := | := by
cases e with
| Const b =>
simp [eval_bool]
apply BoolStepStar.refl
| Not e =>
simp [eval_bool]
have ihn := eval_bool_completeness e (val := val)
have h := BoolStepStar.notStep e _ ihn
have h1 := BoolStep.notIsBoolNot (eval_bool V val e) (val := val)
have h2 := (step_to_stepstar V h1)
apply chasles_step_star V h h2
| And l r =>
have l_step := eval_bool_completeness l (val := val)
have r_step := eval_bool_completeness r (val := val)
simp [eval_bool]
by_cases h: (eval_bool V val l)
. simp [and]
rw [h]
simp
rw [h] at l_step
have h1 := BoolStep.andLeftTrue r (val := val)
have h2 := StepStar.trans _ _ _ h1 r_step
have h3 := BoolStepStar.andStepLeft _ _ r l_step
exact chasles_step_star V h3 h2
. replace h := eq_false_of_ne_true h
rw [h]
rw [h] at l_step
simp [and]
have h1 := BoolStepStar.andStepLeft _ _ r l_step
have h2 := BoolStep.andLeftShortCircuit r (val := val)
have h3 := step_to_stepstar V h2
exact chasles_step_star V h1 h3
| Or l r =>
have l_step := eval_bool_completeness l (val := val)
have r_step := eval_bool_completeness r (val := val)
simp [eval_bool]
by_cases h: (eval_bool V val l)
. rw [h]
rw [h] at l_step
simp [or]
have h1 := BoolStepStar.orStepLeft _ _ r l_step
have h2 := BoolStep.orLeftShortCircuit r (val := val)
have h3 := step_to_stepstar V h2
exact chasles_step_star V h1 h3
. replace h := eq_false_of_ne_true h
rw [h]
rw [h] at l_step
simp
have h1 := BoolStep.orLeftFalse r (val := val)
have h2 := StepStar.trans _ _ _ h1 r_step
have h3 := BoolStepStar.orStepLeft _ _ r l_step
exact chasles_step_star V h3 h2
| Eq l r =>
simp [eval_bool]
by_cases h: (eval V val l == eval V val r)
. replace h := eq_of_beq h
rw [h]
simp
have h1 := BoolStep.eqConstConstTrue _ _ h (val := val)
have hl := eval_completeness l (val := val)
have hr := eval_completeness r (val := val)
have h2 := BoolStepStar.eqArStepStarLeft l (ArExpr.Const (eval V val l)) r hl
have h3 := BoolStepStar.eqArStepStarRight (ArExpr.Const (eval V val l)) r (ArExpr.Const (eval V val r)) hr
have h4 := chasles_step_star V h2 h3
exact chasles_step_star V h4 (step_to_stepstar V h1)
. replace h := eq_false_of_ne_true h
rw [h]
have h' := ne_of_beq_false h
rw [<- bne_iff_ne] at h'
have h1 := BoolStep.eqConstConstFalse _ _ h' (val := val)
have hl := eval_completeness l (val := val)
have hr := eval_completeness r (val := val)
have h2 := BoolStepStar.eqArStepStarLeft l (ArExpr.Const (eval V val l)) r hl
have h3 := BoolStepStar.eqArStepStarRight (ArExpr.Const (eval V val l)) r (ArExpr.Const (eval V val r)) hr
have h4 := chasles_step_star V h2 h3
exact chasles_step_star V h4 (step_to_stepstar V h1)
| Less l r =>
simp [eval_bool]
by_cases h: (eval V val l < eval V val r)
. rw [decide_eq_true]
have h1 := BoolStep.lessConstConstTrue _ _ h (val := val)
have hr := eval_completeness r (val := val)
have hl := eval_completeness l (val := val)
have hr := eval_completeness r (val := val)
have h2 := BoolStepStar.lessArStepStarLeft l (ArExpr.Const (eval V val l)) r hl
have h3 := BoolStepStar.lessArStepStarRight (ArExpr.Const (eval V val l)) r (ArExpr.Const (eval V val r)) hr
have h4 := chasles_step_star V h2 h3
apply chasles_step_star V h4 (step_to_stepstar V h1)
exact h
. rw [decide_eq_false]
have h' := h
rw [Int.not_lt] at h'
rw [<- ge_iff_le] at h'
have h1 := BoolStep.lessConstConstFalse _ _ h' (val := val)
have hl := eval_completeness l (val := val)
have hr := eval_completeness r (val := val)
have h2 := BoolStepStar.lessArStepStarLeft l (ArExpr.Const (eval V val l)) r hl
have h3 := BoolStepStar.lessArStepStarRight (ArExpr.Const (eval V val l)) r (ArExpr.Const (eval V val r)) hr
have h4 := chasles_step_star V h2 h3
exact chasles_step_star V h4 (step_to_stepstar V h1)
exact h | 4 | 60 | true | Semantics |
266 | eval_completeness | theorem eval_completeness (e: ArExpr V) : ArStepStar V val e (ArExpr.Const (eval V val e)) | LeanExprEvaluator | ExprEval/Basic.lean | [
"import ExprEval.Steps",
"import ExprEval.Lemmas",
"import ExprEval.Expr"
] | [
{
"name": "Add",
"module": "Init.Prelude"
},
{
"name": "Int",
"module": "Init.Data.Int.Basic"
},
{
"name": "Mul",
"module": "Init.Prelude"
},
{
"name": "Sub",
"module": "Init.Prelude"
},
{
"name": "And",
"module": "Init.Prelude"
},
{
"name": "Bool",
"module": "Init.Prelude"
},
{
"name": "Eq",
"module": "Init.Prelude"
},
{
"name": "Not",
"module": "Init.Prelude"
},
{
"name": "Or",
"module": "Init.Prelude"
},
{
"name": "BEq",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Repr",
"module": "Init.Data.Repr"
},
{
"name": "Vector",
"module": "Init.Data.Vector.Basic"
},
{
"name": "String",
"module": "Init.Prelude"
},
{
"name": "bool",
"module": "Init.Control.Basic"
},
{
"name": "ite",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Computation",
"module": "Mathlib.Data.Seq.Computation"
},
{
"name": "Max",
"module": "Init.Prelude"
},
{
"name": "Max.max",
"module": "Init.Prelude"
},
{
"name": "Option",
"module": "Init.Prelude"
}
] | [
{
"name": "ArStep",
"content": "inductive ArStep: (val: V -> Int) -> (ArExpr V) -> (ArExpr V) -> Prop where\n | getVarValue (var: V) :\n ArStep\n val\n (ArExpr.Var var)\n (ArExpr.Const (val var))\n | addConstConst(nβ nβ: Int) :\n ArStep\n val\n (ArExpr.Add (ArExpr.Const nβ) (ArExpr.Const nβ))\n (ArExpr.Const (nβ + nβ))\n | subConstConst(nβ nβ: Int) :\n ArStep\n val\n (ArExpr.Sub (ArExpr.Const nβ) (ArExpr.Const nβ))\n (ArExpr.Const (nβ - nβ))\n | mulConstConst(nβ nβ: Int) :\n ArStep\n val\n (ArExpr.Mul (ArExpr.Const nβ) (ArExpr.Const nβ))\n (ArExpr.Const (nβ * nβ))\n | addLeft (eβ eβ' eβ) : ArStep val eβ eβ' -> ArStep val (ArExpr.Add eβ eβ) (ArExpr.Add eβ' eβ)\n\n | subLeft (eβ eβ' eβ) : ArStep val eβ eβ' -> ArStep val (ArExpr.Sub eβ eβ) (ArExpr.Sub eβ' eβ)\n\n | mulLeft (eβ eβ' eβ) : ArStep val eβ eβ' -> ArStep val (ArExpr.Mul eβ eβ) (ArExpr.Mul eβ' eβ)\n\n | addRight (n: Int) (eβ eβ': ArExpr V) : ArStep val eβ eβ' -> ArStep val (ArExpr.Add (ArExpr.Const n) eβ) (ArExpr.Add (ArExpr.Const n) eβ')\n\n | subRight (n: Int) (eβ eβ': ArExpr V) : ArStep val eβ eβ' -> ArStep val (ArExpr.Sub (ArExpr.Const n) eβ) (ArExpr.Sub (ArExpr.Const n) eβ')\n | mulRight (n: Int) (eβ eβ': ArExpr V) : ArStep val eβ eβ' -> ArStep val (ArExpr.Mul (ArExpr.Const n) eβ) (ArExpr.Mul (ArExpr.Const n) eβ')\n\n | ifStep (e e': BoolExpr V) (a b : ArExpr V): BoolStep val e e' ->\n ArStep val (ArExpr.If e a b) (ArExpr.If e' a b)\n | ifCondTrue (a b: ArExpr V) : ArStep val (ArExpr.If (BoolExpr.Const true) a b) a\n | ifCondFalse (a b: ArExpr V) : ArStep val (ArExpr.If (BoolExpr.Const false) a b) b"
},
{
"name": "ArStepStar.trans",
"content": "def ArStepStar.trans {V: Type} {val: V -> Int} eβ eβ eβ := StepStar.trans eβ eβ eβ (Step := ArStep V) (val := val)"
},
{
"name": "BoolStep",
"content": "inductive BoolStep: (val: V -> Int) -> (BoolExpr V) -> (BoolExpr V) -> Prop where\n | notIsBoolNot (b: Bool): BoolStep val\n (BoolExpr.Not (BoolExpr.Const b))\n (BoolExpr.Const !b)\n | andLeftTrue (e: BoolExpr V): BoolStep val\n (BoolExpr.And (BoolExpr.Const true) e)\n e\n | orLeftFalse (e: BoolExpr V): BoolStep val\n (BoolExpr.Or (BoolExpr.Const false) e)\n e\n | andLeftShortCircuit e : BoolStep val\n (BoolExpr.And (BoolExpr.Const false) e)\n (BoolExpr.Const false)\n | orLeftShortCircuit e : BoolStep val\n (BoolExpr.Or (BoolExpr.Const true) e)\n (BoolExpr.Const true)\n | lessConstConstTrue nβ nβ : nβ < nβ -> BoolStep val\n (BoolExpr.Less (ArExpr.Const nβ) (ArExpr.Const nβ))\n (BoolExpr.Const true)\n | lessConstConstFalse nβ nβ : nβ >= nβ -> BoolStep val\n (BoolExpr.Less (ArExpr.Const nβ) (ArExpr.Const nβ))\n (BoolExpr.Const false)\n | eqConstConstTrue nβ nβ : nβ = nβ -> BoolStep val\n (BoolExpr.Eq (ArExpr.Const nβ) (ArExpr.Const nβ))\n (BoolExpr.Const true)\n | eqConstConstFalse nβ nβ : nβ != nβ -> BoolStep val\n (BoolExpr.Eq (ArExpr.Const nβ) (ArExpr.Const nβ))\n (BoolExpr.Const false)\n | lessArStepLeft (eβ eβ' eβ: ArExpr V):\n ArStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.Less eβ eβ)\n (BoolExpr.Less eβ' eβ)\n | eqArStepLeft (eβ eβ' eβ: ArExpr V):\n ArStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.Eq eβ eβ)\n (BoolExpr.Eq eβ' eβ)\n | lessArStepRight (eβ eβ eβ': ArExpr V):\n ArStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.Less eβ eβ)\n (BoolExpr.Less eβ eβ')\n | eqArStepRight (eβ eβ eβ': ArExpr V):\n ArStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.Eq eβ eβ)\n (BoolExpr.Eq eβ eβ')\n | orStepLeft (eβ eβ' eβ: BoolExpr V):\n BoolStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.Or eβ eβ)\n (BoolExpr.Or eβ' eβ)\n | andStepLeft (eβ eβ' eβ: BoolExpr V):\n BoolStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.And eβ eβ)\n (BoolExpr.And eβ' eβ)\n | notStep (e e' : BoolExpr V):\n BoolStep val e e' -> BoolStep val\n (BoolExpr.Not e)\n (BoolExpr.Not e')\n\n inductive BoolExpr : Type\n | Const: Bool -> BoolExpr\n | Less: ArExpr -> ArExpr -> BoolExpr\n | Eq: ArExpr -> ArExpr -> BoolExpr\n | Not : BoolExpr -> BoolExpr\n | And : BoolExpr -> BoolExpr -> BoolExpr\n | Or : BoolExpr -> BoolExpr -> BoolExpr\n\n inductive ArExpr: Type\n | Const: Int -> ArExpr\n | Add: ArExpr -> ArExpr -> ArExpr\n | Sub: ArExpr -> ArExpr -> ArExpr\n | Mul: ArExpr -> ArExpr -> ArExpr\n | Var: V -> ArExpr\n | If : BoolExpr -> ArExpr -> ArExpr -> ArExpr"
},
{
"name": "StepStar",
"content": "inductive StepStar {ExprType: Type} {Step: StepKind V ExprType} : (val: V -> Int) -> ExprType -> ExprType -> Prop where\n | refl val e : StepStar val e e\n | trans eβ eβ eβ : Step val eβ eβ -> StepStar val eβ eβ -> StepStar val eβ eβ"
},
{
"name": "ArStepStar",
"content": "def ArStepStar (V: Type) := StepStar (Step := ArStep V) V\n\n def eval (val: V -> Int) (e: ArExpr V) : Int :=\n match e with\n | ArExpr.Const x => x\n | ArExpr.Add lhs rhs => (eval val lhs) + (eval val rhs)\n | ArExpr.Sub lhs rhs => (eval val lhs) - (eval val rhs)\n | ArExpr.Mul lhs rhs => (eval val lhs) * (eval val rhs)\n | ArExpr.Var v => val v\n | ArExpr.If cond then_e else_e => if eval_bool val cond then eval val then_e else eval val else_e\n\n def eval_bool (val: V -> Int) (e: BoolExpr V): Bool :=\n match e with\n | BoolExpr.Const b => b\n | BoolExpr.Less l r => (eval val l) < (eval val r)\n | BoolExpr.Eq l r => (eval val l) == (eval val r)\n | BoolExpr.Not e => not (eval_bool val e)\n | BoolExpr.And l r => if eval_bool val l then eval_bool val r else false\n | BoolExpr.Or l r => if eval_bool val l then true else eval_bool val r"
},
{
"name": "ArStepStar.refl",
"content": "def ArStepStar.refl {V: Type} (val: V -> Int) := StepStar.refl (Step := ArStep V) val"
},
{
"name": "BoolStepStar",
"content": "def BoolStepStar (V: Type) := StepStar (Step := BoolStep V) V"
},
{
"name": "BoolStepStar.refl",
"content": "def BoolStepStar.refl {V: Type} (val: V -> Int) := StepStar.refl (Step := BoolStep V) val"
},
{
"name": "StepKind",
"content": "def StepKind (V: Type) (ExprType: Type):= (V -> Int) -> ExprType -> ExprType -> Prop"
},
{
"name": "BoolStepStar.trans",
"content": "def BoolStepStar.trans {V: Type} {val: V -> Int} eβ eβ eβ := StepStar.trans eβ eβ eβ (Step := BoolStep V) (val := val)"
}
] | [
{
"name": "Int.not_lt",
"module": "Init.Data.Int.Order"
},
{
"name": "bne_iff_ne",
"module": "Init.SimpLemmas"
},
{
"name": "decide_eq_false",
"module": "Init.Prelude"
},
{
"name": "decide_eq_true",
"module": "Init.Prelude"
},
{
"name": "eq_false_of_ne_true",
"module": "Init.Prelude"
},
{
"name": "ge_iff_le",
"module": "Init.Core"
},
{
"name": "ne_of_beq_false",
"module": "Init.Core"
}
] | [
{
"name": "arstepstar_add_right",
"content": "theorem arstepstar_add_right (n: Int) (eβ eβ': ArExpr V) :\n ArStepStar V val eβ eβ' ->\n ArStepStar V val\n (ArExpr.Add (ArExpr.Const n) eβ)\n (ArExpr.Add (ArExpr.Const n) eβ')"
},
{
"name": "arstepstar_sub_left",
"content": "theorem arstepstar_sub_left (eβ eβ' eβ: ArExpr V) :\n ArStepStar V val eβ eβ' ->\n ArStepStar V val\n (ArExpr.Sub eβ eβ)\n (ArExpr.Sub eβ' eβ)"
},
{
"name": "chasles_step_star",
"content": "theorem chasles_step_star {ExprKind: Type} {Step: StepKind V ExprKind} {eβ eβ eβ: ExprKind}:\n StepStar (Step := Step) V val eβ eβ ->\n StepStar (Step := Step) V val eβ eβ ->\n StepStar (Step := Step) V val eβ eβ"
},
{
"name": "arstepstar_add_left",
"content": "theorem arstepstar_add_left (eβ eβ' eβ: ArExpr V) :\n ArStepStar V val eβ eβ' -> ArStepStar V val (ArExpr.Add eβ eβ) (ArExpr.Add eβ' eβ)"
},
{
"name": "arstepstar_sub_right",
"content": "theorem arstepstar_sub_right (n: Int) (eβ eβ': ArExpr V) :\n ArStepStar V val eβ eβ' ->\n ArStepStar V val\n (ArExpr.Sub (ArExpr.Const n) eβ)\n (ArExpr.Sub (ArExpr.Const n) eβ')"
},
{
"name": "ArStepStar.ifStep",
"content": "theorem ArStepStar.ifStep (e e': BoolExpr V) (a b: ArExpr V): BoolStepStar V val e e' ->\n ArStepStar V val (ArExpr.If e a b) (ArExpr.If e' a b)"
},
{
"name": "arstepstar_mul_right",
"content": "theorem arstepstar_mul_right (n: Int) (eβ eβ': ArExpr V) :\n ArStepStar V val eβ eβ' ->\n ArStepStar V val\n (ArExpr.Mul (ArExpr.Const n) eβ)\n (ArExpr.Mul (ArExpr.Const n) eβ')"
},
{
"name": "arstepstar_mul_left",
"content": "theorem arstepstar_mul_left (eβ eβ' eβ: ArExpr V) :\n ArStepStar V val eβ eβ' ->\n ArStepStar V val\n (ArExpr.Mul eβ eβ)\n (ArExpr.Mul eβ' eβ)"
},
{
"name": "BoolStepStar.andStepLeft",
"content": "theorem BoolStepStar.andStepLeft (eβ eβ' eβ: BoolExpr V):\n BoolStepStar V val eβ eβ' -> BoolStepStar V val\n (BoolExpr.And eβ eβ)\n (BoolExpr.And eβ' eβ)"
},
{
"name": "BoolStepStar.lessArStepStarLeft",
"content": "theorem BoolStepStar.lessArStepStarLeft (eβ eβ' eβ: ArExpr V):\n ArStepStar V val eβ eβ' ->\n BoolStepStar V val\n (BoolExpr.Less eβ eβ)\n (BoolExpr.Less eβ' eβ)"
},
{
"name": "BoolStepStar.notStep",
"content": "theorem BoolStepStar.notStep {V: Type} {val: V -> Int}\n (e e': BoolExpr V):\n BoolStepStar V val e e' -> BoolStepStar V val (BoolExpr.Not e) (BoolExpr.Not e')"
},
{
"name": "BoolStepStar.lessArStepStarRight",
"content": "theorem BoolStepStar.lessArStepStarRight (eβ eβ eβ': ArExpr V):\n ArStepStar V val eβ eβ' ->\n BoolStepStar V val\n (BoolExpr.Less eβ eβ)\n (BoolExpr.Less eβ eβ')"
},
{
"name": "step_to_stepstar",
"content": "theorem step_to_stepstar {ExprKind: Type} {Step: StepKind V ExprKind} {e e': ExprKind}:\n Step val e e' -> StepStar (Step := Step) V val e e'"
},
{
"name": "BoolStepStar.eqArStepStarRight",
"content": "theorem BoolStepStar.eqArStepStarRight (eβ eβ eβ': ArExpr V):\n ArStepStar V val eβ eβ' ->\n BoolStepStar V val\n (BoolExpr.Eq eβ eβ)\n (BoolExpr.Eq eβ eβ')"
},
{
"name": "BoolStepStar.eqArStepStarLeft",
"content": "theorem BoolStepStar.eqArStepStarLeft (eβ eβ' eβ: ArExpr V):\n ArStepStar V val eβ eβ' ->\n BoolStepStar V val\n (BoolExpr.Eq eβ eβ)\n (BoolExpr.Eq eβ' eβ)"
},
{
"name": "BoolStepStar.orStepLeft",
"content": "theorem BoolStepStar.orStepLeft (eβ eβ' eβ: BoolExpr V):\n BoolStepStar V val eβ eβ' -> BoolStepStar V val\n (BoolExpr.Or eβ eβ)\n (BoolExpr.Or eβ' eβ)"
}
] | [] | [] | import ExprEval.Steps
import ExprEval.Lemmas
variable (V: Type) | theorem eval_completeness (e: ArExpr V) : ArStepStar V val e (ArExpr.Const (eval V val e)) := | := by
cases e with
| Const x =>
simp [eval]
exact ArStepStar.refl _ _
| Add eβ eβ =>
have ih1 := eval_completeness eβ (val := val)
have ih2 := eval_completeness eβ (val := val)
simp [eval]
have a := arstepstar_add_left _ _ eβ ih1
have b := arstepstar_add_right (eval V val eβ) eβ _ ih2
have c := ArStep.addConstConst (val := val) (eval V val eβ) (eval V val eβ)
have d := ArStepStar.trans _ _ _ c (ArStepStar.refl _ (ArExpr.Const (eval V val eβ + eval V val eβ)))
have e := chasles_step_star _ a (chasles_step_star _ b d)
exact e
| Sub eβ eβ =>
have ih1 := eval_completeness eβ (val := val)
have ih2 := eval_completeness eβ (val := val)
simp [eval]
have a := arstepstar_sub_left _ _ eβ ih1
have b := arstepstar_sub_right (eval V val eβ) eβ _ ih2
have c := ArStep.subConstConst (val := val) (eval V val eβ) (eval V val eβ)
have d := ArStepStar.trans _ _ _ c (ArStepStar.refl _ (ArExpr.Const (eval V val eβ - eval V val eβ)))
have e := chasles_step_star _ a (chasles_step_star _ b d)
exact e
| Mul eβ eβ =>
have ih1 := eval_completeness eβ (val := val)
have ih2 := eval_completeness eβ (val := val)
simp [eval]
have a := arstepstar_mul_left _ _ eβ ih1
have b := arstepstar_mul_right (eval V val eβ) eβ _ ih2
have c := ArStep.mulConstConst (val := val) (eval V val eβ) (eval V val eβ)
have d := ArStepStar.trans _ _ _ c (ArStepStar.refl _ (ArExpr.Const (eval V val eβ * eval V val eβ)))
have e := chasles_step_star _ a (chasles_step_star _ b d)
exact e
| Var var =>
simp [eval]
have a := ArStep.getVarValue var (val := val)
have b := ArStepStar.refl val (ArExpr.Const (val var))
exact ArStepStar.trans (val := val) _ _ _ a b
| If cond a b =>
simp [eval]
cases h: (eval_bool V val cond)
. simp
have h1 := ArStep.ifCondFalse a b (val := val)
have h2 := eval_completeness b (val := val)
have h3 := StepStar.trans _ _ _ h1 h2
have h4 := eval_bool_completeness cond (val := val)
rw [h] at h4
have h5 := ArStepStar.ifStep _ _ a b h4
exact chasles_step_star V h5 h3
. simp
have h1 := ArStep.ifCondTrue a b (val := val)
have h2 := eval_completeness a (val := val)
have h3 := StepStar.trans _ _ _ h1 h2
have h4 := eval_bool_completeness cond (val := val)
rw [h] at h4
have h5 := ArStepStar.ifStep _ _ a b h4
exact chasles_step_star V h5 h3 | 4 | 60 | true | Semantics |
267 | boolstep_preserves_eval_bool | theorem boolstep_preserves_eval_bool (e e': BoolExpr V):
BoolStep V val e e' -> eval_bool V val e = eval_bool V val e' | LeanExprEvaluator | ExprEval/Lemmas.lean | [
"import ExprEval.Steps",
"import ExprEval.Expr"
] | [
{
"name": "Add",
"module": "Init.Prelude"
},
{
"name": "Int",
"module": "Init.Data.Int.Basic"
},
{
"name": "Mul",
"module": "Init.Prelude"
},
{
"name": "Sub",
"module": "Init.Prelude"
},
{
"name": "And",
"module": "Init.Prelude"
},
{
"name": "Bool",
"module": "Init.Prelude"
},
{
"name": "Eq",
"module": "Init.Prelude"
},
{
"name": "Not",
"module": "Init.Prelude"
},
{
"name": "Or",
"module": "Init.Prelude"
},
{
"name": "BEq",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Repr",
"module": "Init.Data.Repr"
},
{
"name": "Vector",
"module": "Init.Data.Vector.Basic"
},
{
"name": "String",
"module": "Init.Prelude"
},
{
"name": "bool",
"module": "Init.Control.Basic"
},
{
"name": "ite",
"module": "Init.Prelude"
},
{
"name": "Nat",
"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": "BoolExpr",
"content": "inductive BoolExpr : Type\n | Const: Bool -> BoolExpr\n | Less: ArExpr -> ArExpr -> BoolExpr\n | Eq: ArExpr -> ArExpr -> BoolExpr\n | Not : BoolExpr -> BoolExpr\n | And : BoolExpr -> BoolExpr -> BoolExpr\n | Or : BoolExpr -> BoolExpr -> BoolExpr\n\n inductive ArExpr: Type\n | Const: Int -> ArExpr\n | Add: ArExpr -> ArExpr -> ArExpr\n | Sub: ArExpr -> ArExpr -> ArExpr\n | Mul: ArExpr -> ArExpr -> ArExpr\n | Var: V -> ArExpr\n | If : BoolExpr -> ArExpr -> ArExpr -> ArExpr"
},
{
"name": "BoolStep",
"content": "inductive BoolStep: (val: V -> Int) -> (BoolExpr V) -> (BoolExpr V) -> Prop where\n | notIsBoolNot (b: Bool): BoolStep val\n (BoolExpr.Not (BoolExpr.Const b))\n (BoolExpr.Const !b)\n | andLeftTrue (e: BoolExpr V): BoolStep val\n (BoolExpr.And (BoolExpr.Const true) e)\n e\n | orLeftFalse (e: BoolExpr V): BoolStep val\n (BoolExpr.Or (BoolExpr.Const false) e)\n e\n | andLeftShortCircuit e : BoolStep val\n (BoolExpr.And (BoolExpr.Const false) e)\n (BoolExpr.Const false)\n | orLeftShortCircuit e : BoolStep val\n (BoolExpr.Or (BoolExpr.Const true) e)\n (BoolExpr.Const true)\n | lessConstConstTrue nβ nβ : nβ < nβ -> BoolStep val\n (BoolExpr.Less (ArExpr.Const nβ) (ArExpr.Const nβ))\n (BoolExpr.Const true)\n | lessConstConstFalse nβ nβ : nβ >= nβ -> BoolStep val\n (BoolExpr.Less (ArExpr.Const nβ) (ArExpr.Const nβ))\n (BoolExpr.Const false)\n | eqConstConstTrue nβ nβ : nβ = nβ -> BoolStep val\n (BoolExpr.Eq (ArExpr.Const nβ) (ArExpr.Const nβ))\n (BoolExpr.Const true)\n | eqConstConstFalse nβ nβ : nβ != nβ -> BoolStep val\n (BoolExpr.Eq (ArExpr.Const nβ) (ArExpr.Const nβ))\n (BoolExpr.Const false)\n | lessArStepLeft (eβ eβ' eβ: ArExpr V):\n ArStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.Less eβ eβ)\n (BoolExpr.Less eβ' eβ)\n | eqArStepLeft (eβ eβ' eβ: ArExpr V):\n ArStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.Eq eβ eβ)\n (BoolExpr.Eq eβ' eβ)\n | lessArStepRight (eβ eβ eβ': ArExpr V):\n ArStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.Less eβ eβ)\n (BoolExpr.Less eβ eβ')\n | eqArStepRight (eβ eβ eβ': ArExpr V):\n ArStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.Eq eβ eβ)\n (BoolExpr.Eq eβ eβ')\n | orStepLeft (eβ eβ' eβ: BoolExpr V):\n BoolStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.Or eβ eβ)\n (BoolExpr.Or eβ' eβ)\n | andStepLeft (eβ eβ' eβ: BoolExpr V):\n BoolStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.And eβ eβ)\n (BoolExpr.And eβ' eβ)\n | notStep (e e' : BoolExpr V):\n BoolStep val e e' -> BoolStep val\n (BoolExpr.Not e)\n (BoolExpr.Not e')\n\n def eval (val: V -> Int) (e: ArExpr V) : Int :=\n match e with\n | ArExpr.Const x => x\n | ArExpr.Add lhs rhs => (eval val lhs) + (eval val rhs)\n | ArExpr.Sub lhs rhs => (eval val lhs) - (eval val rhs)\n | ArExpr.Mul lhs rhs => (eval val lhs) * (eval val rhs)\n | ArExpr.Var v => val v\n | ArExpr.If cond then_e else_e => if eval_bool val cond then eval val then_e else eval val else_e\n\n def eval_bool (val: V -> Int) (e: BoolExpr V): Bool :=\n match e with\n | BoolExpr.Const b => b\n | BoolExpr.Less l r => (eval val l) < (eval val r)\n | BoolExpr.Eq l r => (eval val l) == (eval val r)\n | BoolExpr.Not e => not (eval_bool val e)\n | BoolExpr.And l r => if eval_bool val l then eval_bool val r else false\n | BoolExpr.Or l r => if eval_bool val l then true else eval_bool val r"
},
{
"name": "ArStep",
"content": "inductive ArStep: (val: V -> Int) -> (ArExpr V) -> (ArExpr V) -> Prop where\n | getVarValue (var: V) :\n ArStep\n val\n (ArExpr.Var var)\n (ArExpr.Const (val var))\n | addConstConst(nβ nβ: Int) :\n ArStep\n val\n (ArExpr.Add (ArExpr.Const nβ) (ArExpr.Const nβ))\n (ArExpr.Const (nβ + nβ))\n | subConstConst(nβ nβ: Int) :\n ArStep\n val\n (ArExpr.Sub (ArExpr.Const nβ) (ArExpr.Const nβ))\n (ArExpr.Const (nβ - nβ))\n | mulConstConst(nβ nβ: Int) :\n ArStep\n val\n (ArExpr.Mul (ArExpr.Const nβ) (ArExpr.Const nβ))\n (ArExpr.Const (nβ * nβ))\n | addLeft (eβ eβ' eβ) : ArStep val eβ eβ' -> ArStep val (ArExpr.Add eβ eβ) (ArExpr.Add eβ' eβ)\n\n | subLeft (eβ eβ' eβ) : ArStep val eβ eβ' -> ArStep val (ArExpr.Sub eβ eβ) (ArExpr.Sub eβ' eβ)\n\n | mulLeft (eβ eβ' eβ) : ArStep val eβ eβ' -> ArStep val (ArExpr.Mul eβ eβ) (ArExpr.Mul eβ' eβ)\n\n | addRight (n: Int) (eβ eβ': ArExpr V) : ArStep val eβ eβ' -> ArStep val (ArExpr.Add (ArExpr.Const n) eβ) (ArExpr.Add (ArExpr.Const n) eβ')\n\n | subRight (n: Int) (eβ eβ': ArExpr V) : ArStep val eβ eβ' -> ArStep val (ArExpr.Sub (ArExpr.Const n) eβ) (ArExpr.Sub (ArExpr.Const n) eβ')\n | mulRight (n: Int) (eβ eβ': ArExpr V) : ArStep val eβ eβ' -> ArStep val (ArExpr.Mul (ArExpr.Const n) eβ) (ArExpr.Mul (ArExpr.Const n) eβ')\n\n | ifStep (e e': BoolExpr V) (a b : ArExpr V): BoolStep val e e' ->\n ArStep val (ArExpr.If e a b) (ArExpr.If e' a b)\n | ifCondTrue (a b: ArExpr V) : ArStep val (ArExpr.If (BoolExpr.Const true) a b) a\n | ifCondFalse (a b: ArExpr V) : ArStep val (ArExpr.If (BoolExpr.Const false) a b) b"
}
] | [
{
"name": "bne_iff_ne",
"module": "Init.SimpLemmas"
},
{
"name": "Int.mul_eq_mul_right_iff",
"module": "Init.Data.Int.Lemmas"
},
{
"name": "beq_eq_false_iff_ne",
"module": "Init.SimpLemmas"
},
{
"name": "beq_iff_eq",
"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": "arstep_preserve_eval",
"content": " theorem arstep_preserve_eval (e e': ArExpr V): (ArStep V val) e e' -> eval V val e = eval V val e'"
}
] | import ExprEval.Expr
import ExprEval.Steps | theorem boolstep_preserves_eval_bool (e e': BoolExpr V):
BoolStep V val e e' -> eval_bool V val e = eval_bool V val e' := | := by
intro h
cases h with
| notIsBoolNot b => simp [eval_bool]
| andLeftTrue e => simp [eval_bool]
| orLeftFalse e => simp [eval_bool]
| andLeftShortCircuit e => simp [eval_bool]
| orLeftShortCircuit e => simp [eval_bool]
| lessConstConstTrue n1 n2 h =>
simp [eval_bool]
simp [eval]
exact h
| lessConstConstFalse n1 n2 h =>
simp [eval_bool]
simp [eval]
exact h
| eqConstConstTrue n1 n2 h =>
simp [eval_bool]
simp [eval]
exact h
| eqConstConstFalse n1 n2 h =>
simp [eval_bool]
simp [eval]
simp [bne_iff_ne] at h
exact h
| lessArStepLeft eβ eβ' eβ arstep
| eqArStepLeft eβ eβ' eβ arstep =>
simp [eval_bool]
have h' := arstep_preserve_eval eβ eβ' arstep
rw [h']
| lessArStepRight eβ eβ eβ' arstep
| eqArStepRight eβ eβ eβ' arstep =>
simp [eval_bool]
have h' := arstep_preserve_eval eβ eβ' arstep
rw [h']
| orStepLeft eβ eβ' eβ step
| andStepLeft eβ eβ' eβ step =>
have ihn := boolstep_preserves_eval_bool eβ eβ' step
simp [eval_bool]
rw [ihn]
| notStep e e' step =>
simp[eval_bool]
have ihn := boolstep_preserves_eval_bool e e' step
rw [ihn] | 3 | 33 | false | Semantics |
268 | arstep_preserve_eval | theorem arstep_preserve_eval (e e': ArExpr V): (ArStep V val) e e' -> eval V val e = eval V val e' | LeanExprEvaluator | ExprEval/Lemmas.lean | [
"import ExprEval.Steps",
"import ExprEval.Expr"
] | [
{
"name": "Add",
"module": "Init.Prelude"
},
{
"name": "Int",
"module": "Init.Data.Int.Basic"
},
{
"name": "Mul",
"module": "Init.Prelude"
},
{
"name": "Sub",
"module": "Init.Prelude"
},
{
"name": "And",
"module": "Init.Prelude"
},
{
"name": "Bool",
"module": "Init.Prelude"
},
{
"name": "Eq",
"module": "Init.Prelude"
},
{
"name": "Not",
"module": "Init.Prelude"
},
{
"name": "Or",
"module": "Init.Prelude"
},
{
"name": "BEq",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Repr",
"module": "Init.Data.Repr"
},
{
"name": "Vector",
"module": "Init.Data.Vector.Basic"
},
{
"name": "String",
"module": "Init.Prelude"
},
{
"name": "bool",
"module": "Init.Control.Basic"
},
{
"name": "ite",
"module": "Init.Prelude"
},
{
"name": "Nat",
"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": "ArStep",
"content": "inductive ArStep: (val: V -> Int) -> (ArExpr V) -> (ArExpr V) -> Prop where\n | getVarValue (var: V) :\n ArStep\n val\n (ArExpr.Var var)\n (ArExpr.Const (val var))\n | addConstConst(nβ nβ: Int) :\n ArStep\n val\n (ArExpr.Add (ArExpr.Const nβ) (ArExpr.Const nβ))\n (ArExpr.Const (nβ + nβ))\n | subConstConst(nβ nβ: Int) :\n ArStep\n val\n (ArExpr.Sub (ArExpr.Const nβ) (ArExpr.Const nβ))\n (ArExpr.Const (nβ - nβ))\n | mulConstConst(nβ nβ: Int) :\n ArStep\n val\n (ArExpr.Mul (ArExpr.Const nβ) (ArExpr.Const nβ))\n (ArExpr.Const (nβ * nβ))\n | addLeft (eβ eβ' eβ) : ArStep val eβ eβ' -> ArStep val (ArExpr.Add eβ eβ) (ArExpr.Add eβ' eβ)\n\n | subLeft (eβ eβ' eβ) : ArStep val eβ eβ' -> ArStep val (ArExpr.Sub eβ eβ) (ArExpr.Sub eβ' eβ)\n\n | mulLeft (eβ eβ' eβ) : ArStep val eβ eβ' -> ArStep val (ArExpr.Mul eβ eβ) (ArExpr.Mul eβ' eβ)\n\n | addRight (n: Int) (eβ eβ': ArExpr V) : ArStep val eβ eβ' -> ArStep val (ArExpr.Add (ArExpr.Const n) eβ) (ArExpr.Add (ArExpr.Const n) eβ')\n\n | subRight (n: Int) (eβ eβ': ArExpr V) : ArStep val eβ eβ' -> ArStep val (ArExpr.Sub (ArExpr.Const n) eβ) (ArExpr.Sub (ArExpr.Const n) eβ')\n | mulRight (n: Int) (eβ eβ': ArExpr V) : ArStep val eβ eβ' -> ArStep val (ArExpr.Mul (ArExpr.Const n) eβ) (ArExpr.Mul (ArExpr.Const n) eβ')\n\n | ifStep (e e': BoolExpr V) (a b : ArExpr V): BoolStep val e e' ->\n ArStep val (ArExpr.If e a b) (ArExpr.If e' a b)\n | ifCondTrue (a b: ArExpr V) : ArStep val (ArExpr.If (BoolExpr.Const true) a b) a\n | ifCondFalse (a b: ArExpr V) : ArStep val (ArExpr.If (BoolExpr.Const false) a b) b"
},
{
"name": "BoolStep",
"content": "inductive BoolStep: (val: V -> Int) -> (BoolExpr V) -> (BoolExpr V) -> Prop where\n | notIsBoolNot (b: Bool): BoolStep val\n (BoolExpr.Not (BoolExpr.Const b))\n (BoolExpr.Const !b)\n | andLeftTrue (e: BoolExpr V): BoolStep val\n (BoolExpr.And (BoolExpr.Const true) e)\n e\n | orLeftFalse (e: BoolExpr V): BoolStep val\n (BoolExpr.Or (BoolExpr.Const false) e)\n e\n | andLeftShortCircuit e : BoolStep val\n (BoolExpr.And (BoolExpr.Const false) e)\n (BoolExpr.Const false)\n | orLeftShortCircuit e : BoolStep val\n (BoolExpr.Or (BoolExpr.Const true) e)\n (BoolExpr.Const true)\n | lessConstConstTrue nβ nβ : nβ < nβ -> BoolStep val\n (BoolExpr.Less (ArExpr.Const nβ) (ArExpr.Const nβ))\n (BoolExpr.Const true)\n | lessConstConstFalse nβ nβ : nβ >= nβ -> BoolStep val\n (BoolExpr.Less (ArExpr.Const nβ) (ArExpr.Const nβ))\n (BoolExpr.Const false)\n | eqConstConstTrue nβ nβ : nβ = nβ -> BoolStep val\n (BoolExpr.Eq (ArExpr.Const nβ) (ArExpr.Const nβ))\n (BoolExpr.Const true)\n | eqConstConstFalse nβ nβ : nβ != nβ -> BoolStep val\n (BoolExpr.Eq (ArExpr.Const nβ) (ArExpr.Const nβ))\n (BoolExpr.Const false)\n | lessArStepLeft (eβ eβ' eβ: ArExpr V):\n ArStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.Less eβ eβ)\n (BoolExpr.Less eβ' eβ)\n | eqArStepLeft (eβ eβ' eβ: ArExpr V):\n ArStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.Eq eβ eβ)\n (BoolExpr.Eq eβ' eβ)\n | lessArStepRight (eβ eβ eβ': ArExpr V):\n ArStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.Less eβ eβ)\n (BoolExpr.Less eβ eβ')\n | eqArStepRight (eβ eβ eβ': ArExpr V):\n ArStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.Eq eβ eβ)\n (BoolExpr.Eq eβ eβ')\n | orStepLeft (eβ eβ' eβ: BoolExpr V):\n BoolStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.Or eβ eβ)\n (BoolExpr.Or eβ' eβ)\n | andStepLeft (eβ eβ' eβ: BoolExpr V):\n BoolStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.And eβ eβ)\n (BoolExpr.And eβ' eβ)\n | notStep (e e' : BoolExpr V):\n BoolStep val e e' -> BoolStep val\n (BoolExpr.Not e)\n (BoolExpr.Not e')\n\n inductive BoolExpr : Type\n | Const: Bool -> BoolExpr\n | Less: ArExpr -> ArExpr -> BoolExpr\n | Eq: ArExpr -> ArExpr -> BoolExpr\n | Not : BoolExpr -> BoolExpr\n | And : BoolExpr -> BoolExpr -> BoolExpr\n | Or : BoolExpr -> BoolExpr -> BoolExpr\n\n inductive ArExpr: Type\n | Const: Int -> ArExpr\n | Add: ArExpr -> ArExpr -> ArExpr\n | Sub: ArExpr -> ArExpr -> ArExpr\n | Mul: ArExpr -> ArExpr -> ArExpr\n | Var: V -> ArExpr\n | If : BoolExpr -> ArExpr -> ArExpr -> ArExpr\n\n def eval (val: V -> Int) (e: ArExpr V) : Int :=\n match e with\n | ArExpr.Const x => x\n | ArExpr.Add lhs rhs => (eval val lhs) + (eval val rhs)\n | ArExpr.Sub lhs rhs => (eval val lhs) - (eval val rhs)\n | ArExpr.Mul lhs rhs => (eval val lhs) * (eval val rhs)\n | ArExpr.Var v => val v\n | ArExpr.If cond then_e else_e => if eval_bool val cond then eval val then_e else eval val else_e\n\n def eval_bool (val: V -> Int) (e: BoolExpr V): Bool :=\n match e with\n | BoolExpr.Const b => b\n | BoolExpr.Less l r => (eval val l) < (eval val r)\n | BoolExpr.Eq l r => (eval val l) == (eval val r)\n | BoolExpr.Not e => not (eval_bool val e)\n | BoolExpr.And l r => if eval_bool val l then eval_bool val r else false\n | BoolExpr.Or l r => if eval_bool val l then true else eval_bool val r"
}
] | [
{
"name": "Int.mul_eq_mul_right_iff",
"module": "Init.Data.Int.Lemmas"
},
{
"name": "beq_eq_false_iff_ne",
"module": "Init.SimpLemmas"
},
{
"name": "beq_iff_eq",
"module": "Init.Core"
},
{
"name": "bne_iff_ne",
"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]"
}
] | [] | [] | import ExprEval.Expr
import ExprEval.Steps | theorem arstep_preserve_eval (e e': ArExpr V): (ArStep V val) e e' -> eval V val e = eval V val e' := | := by
intro h
cases h with
| addConstConst nβ nβ
| subConstConst nβ nβ
| mulConstConst nβ nβ => simp [eval]
| subLeft eβ eβ' eβ step
| addLeft eβ eβ' eβ step =>
simp [eval]
exact arstep_preserve_eval eβ eβ' step
| mulLeft eβ eβ' eβ step =>
simp [eval]
cases h : (eval V val eβ == 0)
. rw [beq_eq_false_iff_ne] at h
rw [Int.mul_eq_mul_right_iff]
exact arstep_preserve_eval eβ eβ' step
exact h
. rw [beq_iff_eq] at h
rw [h]
simp
| addRight n eβ eβ' step
| subRight n eβ eβ' step
| mulRight n eβ eβ' step =>
-- have ih := arstep_preserve_eval eβ eβ' step
have ihn := arstep_preserve_eval eβ eβ' step
simp [eval, ihn]
| getVarValue var => simp [eval]
| ifCondTrue a b =>
simp [eval]
simp [eval_bool]
| ifCondFalse a b =>
simp [eval]
simp [eval_bool]
| ifStep e e' a b bstep =>
have ihn := boolstep_preserves_eval_bool e e' bstep
cases h: (eval_bool V val e)
. simp [eval]
rw [h]
rw [<- ihn]
simp
intro noth
rw [h] at noth
nomatch noth
. simp [eval]
rw [h]
rw [<- ihn]
simp
intro noth
rw [h] at noth
nomatch noth | 4 | 33 | true | Semantics |
269 | boolstepstar_preserves_eval_bool | theorem boolstepstar_preserves_eval_bool (e e': BoolExpr V):
BoolStepStar V val e e' -> eval_bool V val e = eval_bool V val e' | LeanExprEvaluator | ExprEval/Lemmas.lean | [
"import ExprEval.Steps",
"import ExprEval.Expr"
] | [
{
"name": "Add",
"module": "Init.Prelude"
},
{
"name": "Int",
"module": "Init.Data.Int.Basic"
},
{
"name": "Mul",
"module": "Init.Prelude"
},
{
"name": "Sub",
"module": "Init.Prelude"
},
{
"name": "And",
"module": "Init.Prelude"
},
{
"name": "Bool",
"module": "Init.Prelude"
},
{
"name": "Eq",
"module": "Init.Prelude"
},
{
"name": "Not",
"module": "Init.Prelude"
},
{
"name": "Or",
"module": "Init.Prelude"
},
{
"name": "BEq",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Repr",
"module": "Init.Data.Repr"
},
{
"name": "Vector",
"module": "Init.Data.Vector.Basic"
},
{
"name": "String",
"module": "Init.Prelude"
},
{
"name": "bool",
"module": "Init.Control.Basic"
},
{
"name": "ite",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Computation",
"module": "Mathlib.Data.Seq.Computation"
},
{
"name": "Max",
"module": "Init.Prelude"
},
{
"name": "Max.max",
"module": "Init.Prelude"
},
{
"name": "Option",
"module": "Init.Prelude"
}
] | [
{
"name": "BoolExpr",
"content": "inductive BoolExpr : Type\n | Const: Bool -> BoolExpr\n | Less: ArExpr -> ArExpr -> BoolExpr\n | Eq: ArExpr -> ArExpr -> BoolExpr\n | Not : BoolExpr -> BoolExpr\n | And : BoolExpr -> BoolExpr -> BoolExpr\n | Or : BoolExpr -> BoolExpr -> BoolExpr\n\n inductive ArExpr: Type\n | Const: Int -> ArExpr\n | Add: ArExpr -> ArExpr -> ArExpr\n | Sub: ArExpr -> ArExpr -> ArExpr\n | Mul: ArExpr -> ArExpr -> ArExpr\n | Var: V -> ArExpr\n | If : BoolExpr -> ArExpr -> ArExpr -> ArExpr"
},
{
"name": "BoolStepStar",
"content": "def BoolStepStar (V: Type) := StepStar (Step := BoolStep V) V"
},
{
"name": "BoolStep",
"content": "inductive BoolStep: (val: V -> Int) -> (BoolExpr V) -> (BoolExpr V) -> Prop where\n | notIsBoolNot (b: Bool): BoolStep val\n (BoolExpr.Not (BoolExpr.Const b))\n (BoolExpr.Const !b)\n | andLeftTrue (e: BoolExpr V): BoolStep val\n (BoolExpr.And (BoolExpr.Const true) e)\n e\n | orLeftFalse (e: BoolExpr V): BoolStep val\n (BoolExpr.Or (BoolExpr.Const false) e)\n e\n | andLeftShortCircuit e : BoolStep val\n (BoolExpr.And (BoolExpr.Const false) e)\n (BoolExpr.Const false)\n | orLeftShortCircuit e : BoolStep val\n (BoolExpr.Or (BoolExpr.Const true) e)\n (BoolExpr.Const true)\n | lessConstConstTrue nβ nβ : nβ < nβ -> BoolStep val\n (BoolExpr.Less (ArExpr.Const nβ) (ArExpr.Const nβ))\n (BoolExpr.Const true)\n | lessConstConstFalse nβ nβ : nβ >= nβ -> BoolStep val\n (BoolExpr.Less (ArExpr.Const nβ) (ArExpr.Const nβ))\n (BoolExpr.Const false)\n | eqConstConstTrue nβ nβ : nβ = nβ -> BoolStep val\n (BoolExpr.Eq (ArExpr.Const nβ) (ArExpr.Const nβ))\n (BoolExpr.Const true)\n | eqConstConstFalse nβ nβ : nβ != nβ -> BoolStep val\n (BoolExpr.Eq (ArExpr.Const nβ) (ArExpr.Const nβ))\n (BoolExpr.Const false)\n | lessArStepLeft (eβ eβ' eβ: ArExpr V):\n ArStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.Less eβ eβ)\n (BoolExpr.Less eβ' eβ)\n | eqArStepLeft (eβ eβ' eβ: ArExpr V):\n ArStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.Eq eβ eβ)\n (BoolExpr.Eq eβ' eβ)\n | lessArStepRight (eβ eβ eβ': ArExpr V):\n ArStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.Less eβ eβ)\n (BoolExpr.Less eβ eβ')\n | eqArStepRight (eβ eβ eβ': ArExpr V):\n ArStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.Eq eβ eβ)\n (BoolExpr.Eq eβ eβ')\n | orStepLeft (eβ eβ' eβ: BoolExpr V):\n BoolStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.Or eβ eβ)\n (BoolExpr.Or eβ' eβ)\n | andStepLeft (eβ eβ' eβ: BoolExpr V):\n BoolStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.And eβ eβ)\n (BoolExpr.And eβ' eβ)\n | notStep (e e' : BoolExpr V):\n BoolStep val e e' -> BoolStep val\n (BoolExpr.Not e)\n (BoolExpr.Not e')"
},
{
"name": "ArStep",
"content": "inductive ArStep: (val: V -> Int) -> (ArExpr V) -> (ArExpr V) -> Prop where\n | getVarValue (var: V) :\n ArStep\n val\n (ArExpr.Var var)\n (ArExpr.Const (val var))\n | addConstConst(nβ nβ: Int) :\n ArStep\n val\n (ArExpr.Add (ArExpr.Const nβ) (ArExpr.Const nβ))\n (ArExpr.Const (nβ + nβ))\n | subConstConst(nβ nβ: Int) :\n ArStep\n val\n (ArExpr.Sub (ArExpr.Const nβ) (ArExpr.Const nβ))\n (ArExpr.Const (nβ - nβ))\n | mulConstConst(nβ nβ: Int) :\n ArStep\n val\n (ArExpr.Mul (ArExpr.Const nβ) (ArExpr.Const nβ))\n (ArExpr.Const (nβ * nβ))\n | addLeft (eβ eβ' eβ) : ArStep val eβ eβ' -> ArStep val (ArExpr.Add eβ eβ) (ArExpr.Add eβ' eβ)\n\n | subLeft (eβ eβ' eβ) : ArStep val eβ eβ' -> ArStep val (ArExpr.Sub eβ eβ) (ArExpr.Sub eβ' eβ)\n\n | mulLeft (eβ eβ' eβ) : ArStep val eβ eβ' -> ArStep val (ArExpr.Mul eβ eβ) (ArExpr.Mul eβ' eβ)\n\n | addRight (n: Int) (eβ eβ': ArExpr V) : ArStep val eβ eβ' -> ArStep val (ArExpr.Add (ArExpr.Const n) eβ) (ArExpr.Add (ArExpr.Const n) eβ')\n\n | subRight (n: Int) (eβ eβ': ArExpr V) : ArStep val eβ eβ' -> ArStep val (ArExpr.Sub (ArExpr.Const n) eβ) (ArExpr.Sub (ArExpr.Const n) eβ')\n | mulRight (n: Int) (eβ eβ': ArExpr V) : ArStep val eβ eβ' -> ArStep val (ArExpr.Mul (ArExpr.Const n) eβ) (ArExpr.Mul (ArExpr.Const n) eβ')\n\n | ifStep (e e': BoolExpr V) (a b : ArExpr V): BoolStep val e e' ->\n ArStep val (ArExpr.If e a b) (ArExpr.If e' a b)\n | ifCondTrue (a b: ArExpr V) : ArStep val (ArExpr.If (BoolExpr.Const true) a b) a\n | ifCondFalse (a b: ArExpr V) : ArStep val (ArExpr.If (BoolExpr.Const false) a b) b"
},
{
"name": "StepStar",
"content": "inductive StepStar {ExprType: Type} {Step: StepKind V ExprType} : (val: V -> Int) -> ExprType -> ExprType -> Prop where\n | refl val e : StepStar val e e\n | trans eβ eβ eβ : Step val eβ eβ -> StepStar val eβ eβ -> StepStar val eβ eβ\n\n def eval_bool (val: V -> Int) (e: BoolExpr V): Bool :=\n match e with\n | BoolExpr.Const b => b\n | BoolExpr.Less l r => (eval val l) < (eval val r)\n | BoolExpr.Eq l r => (eval val l) == (eval val r)\n | BoolExpr.Not e => not (eval_bool val e)\n | BoolExpr.And l r => if eval_bool val l then eval_bool val r else false\n | BoolExpr.Or l r => if eval_bool val l then true else eval_bool val r\n\n def eval (val: V -> Int) (e: ArExpr V) : Int :=\n match e with\n | ArExpr.Const x => x\n | ArExpr.Add lhs rhs => (eval val lhs) + (eval val rhs)\n | ArExpr.Sub lhs rhs => (eval val lhs) - (eval val rhs)\n | ArExpr.Mul lhs rhs => (eval val lhs) * (eval val rhs)\n | ArExpr.Var v => val v\n | ArExpr.If cond then_e else_e => if eval_bool val cond then eval val then_e else eval val else_e"
}
] | [
{
"name": "Int.mul_eq_mul_right_iff",
"module": "Init.Data.Int.Lemmas"
},
{
"name": "beq_eq_false_iff_ne",
"module": "Init.SimpLemmas"
},
{
"name": "beq_iff_eq",
"module": "Init.Core"
},
{
"name": "bne_iff_ne",
"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": "arstep_preserve_eval",
"content": " theorem arstep_preserve_eval (e e': ArExpr V): (ArStep V val) e e' -> eval V val e = eval V val e'"
},
{
"name": "boolstep_preserves_eval_bool",
"content": " theorem boolstep_preserves_eval_bool (e e': BoolExpr V):\n BoolStep V val e e' -> eval_bool V val e = eval_bool V val e'"
}
] | import ExprEval.Expr
import ExprEval.Steps | theorem boolstepstar_preserves_eval_bool (e e': BoolExpr V):
BoolStepStar V val e e' -> eval_bool V val e = eval_bool V val e' := | := by
intro h
induction h with
| refl => rfl
| trans _ _ _ h_step _ ihn =>
rw [<- ihn]
exact boolstep_preserves_eval_bool _ _ h_step | 4 | 35 | false | Semantics |
270 | arstepstar_preserves_eval | theorem arstepstar_preserves_eval (e e': ArExpr V) :
ArStepStar V val e e' -> eval V val e = eval V val e' | LeanExprEvaluator | ExprEval/Lemmas.lean | [
"import ExprEval.Steps",
"import ExprEval.Expr"
] | [
{
"name": "And",
"module": "Init.Prelude"
},
{
"name": "Bool",
"module": "Init.Prelude"
},
{
"name": "Eq",
"module": "Init.Prelude"
},
{
"name": "Not",
"module": "Init.Prelude"
},
{
"name": "Or",
"module": "Init.Prelude"
},
{
"name": "Add",
"module": "Init.Prelude"
},
{
"name": "Int",
"module": "Init.Data.Int.Basic"
},
{
"name": "Mul",
"module": "Init.Prelude"
},
{
"name": "Sub",
"module": "Init.Prelude"
},
{
"name": "BEq",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Repr",
"module": "Init.Data.Repr"
},
{
"name": "Vector",
"module": "Init.Data.Vector.Basic"
},
{
"name": "String",
"module": "Init.Prelude"
},
{
"name": "bool",
"module": "Init.Control.Basic"
},
{
"name": "ite",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Computation",
"module": "Mathlib.Data.Seq.Computation"
},
{
"name": "Max",
"module": "Init.Prelude"
},
{
"name": "Max.max",
"module": "Init.Prelude"
},
{
"name": "Option",
"module": "Init.Prelude"
}
] | [
{
"name": "ArExpr",
"content": "inductive ArExpr: Type\n | Const: Int -> ArExpr\n | Add: ArExpr -> ArExpr -> ArExpr\n | Sub: ArExpr -> ArExpr -> ArExpr\n | Mul: ArExpr -> ArExpr -> ArExpr\n | Var: V -> ArExpr\n | If : BoolExpr -> ArExpr -> ArExpr -> ArExpr\n\n inductive BoolExpr : Type\n | Const: Bool -> BoolExpr\n | Less: ArExpr -> ArExpr -> BoolExpr\n | Eq: ArExpr -> ArExpr -> BoolExpr\n | Not : BoolExpr -> BoolExpr\n | And : BoolExpr -> BoolExpr -> BoolExpr\n | Or : BoolExpr -> BoolExpr -> BoolExpr"
},
{
"name": "ArStepStar",
"content": "def ArStepStar (V: Type) := StepStar (Step := ArStep V) V"
},
{
"name": "ArStep",
"content": "inductive ArStep: (val: V -> Int) -> (ArExpr V) -> (ArExpr V) -> Prop where\n | getVarValue (var: V) :\n ArStep\n val\n (ArExpr.Var var)\n (ArExpr.Const (val var))\n | addConstConst(nβ nβ: Int) :\n ArStep\n val\n (ArExpr.Add (ArExpr.Const nβ) (ArExpr.Const nβ))\n (ArExpr.Const (nβ + nβ))\n | subConstConst(nβ nβ: Int) :\n ArStep\n val\n (ArExpr.Sub (ArExpr.Const nβ) (ArExpr.Const nβ))\n (ArExpr.Const (nβ - nβ))\n | mulConstConst(nβ nβ: Int) :\n ArStep\n val\n (ArExpr.Mul (ArExpr.Const nβ) (ArExpr.Const nβ))\n (ArExpr.Const (nβ * nβ))\n | addLeft (eβ eβ' eβ) : ArStep val eβ eβ' -> ArStep val (ArExpr.Add eβ eβ) (ArExpr.Add eβ' eβ)\n\n | subLeft (eβ eβ' eβ) : ArStep val eβ eβ' -> ArStep val (ArExpr.Sub eβ eβ) (ArExpr.Sub eβ' eβ)\n\n | mulLeft (eβ eβ' eβ) : ArStep val eβ eβ' -> ArStep val (ArExpr.Mul eβ eβ) (ArExpr.Mul eβ' eβ)\n\n | addRight (n: Int) (eβ eβ': ArExpr V) : ArStep val eβ eβ' -> ArStep val (ArExpr.Add (ArExpr.Const n) eβ) (ArExpr.Add (ArExpr.Const n) eβ')\n\n | subRight (n: Int) (eβ eβ': ArExpr V) : ArStep val eβ eβ' -> ArStep val (ArExpr.Sub (ArExpr.Const n) eβ) (ArExpr.Sub (ArExpr.Const n) eβ')\n | mulRight (n: Int) (eβ eβ': ArExpr V) : ArStep val eβ eβ' -> ArStep val (ArExpr.Mul (ArExpr.Const n) eβ) (ArExpr.Mul (ArExpr.Const n) eβ')\n\n | ifStep (e e': BoolExpr V) (a b : ArExpr V): BoolStep val e e' ->\n ArStep val (ArExpr.If e a b) (ArExpr.If e' a b)\n | ifCondTrue (a b: ArExpr V) : ArStep val (ArExpr.If (BoolExpr.Const true) a b) a\n | ifCondFalse (a b: ArExpr V) : ArStep val (ArExpr.If (BoolExpr.Const false) a b) b"
},
{
"name": "BoolStep",
"content": "inductive BoolStep: (val: V -> Int) -> (BoolExpr V) -> (BoolExpr V) -> Prop where\n | notIsBoolNot (b: Bool): BoolStep val\n (BoolExpr.Not (BoolExpr.Const b))\n (BoolExpr.Const !b)\n | andLeftTrue (e: BoolExpr V): BoolStep val\n (BoolExpr.And (BoolExpr.Const true) e)\n e\n | orLeftFalse (e: BoolExpr V): BoolStep val\n (BoolExpr.Or (BoolExpr.Const false) e)\n e\n | andLeftShortCircuit e : BoolStep val\n (BoolExpr.And (BoolExpr.Const false) e)\n (BoolExpr.Const false)\n | orLeftShortCircuit e : BoolStep val\n (BoolExpr.Or (BoolExpr.Const true) e)\n (BoolExpr.Const true)\n | lessConstConstTrue nβ nβ : nβ < nβ -> BoolStep val\n (BoolExpr.Less (ArExpr.Const nβ) (ArExpr.Const nβ))\n (BoolExpr.Const true)\n | lessConstConstFalse nβ nβ : nβ >= nβ -> BoolStep val\n (BoolExpr.Less (ArExpr.Const nβ) (ArExpr.Const nβ))\n (BoolExpr.Const false)\n | eqConstConstTrue nβ nβ : nβ = nβ -> BoolStep val\n (BoolExpr.Eq (ArExpr.Const nβ) (ArExpr.Const nβ))\n (BoolExpr.Const true)\n | eqConstConstFalse nβ nβ : nβ != nβ -> BoolStep val\n (BoolExpr.Eq (ArExpr.Const nβ) (ArExpr.Const nβ))\n (BoolExpr.Const false)\n | lessArStepLeft (eβ eβ' eβ: ArExpr V):\n ArStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.Less eβ eβ)\n (BoolExpr.Less eβ' eβ)\n | eqArStepLeft (eβ eβ' eβ: ArExpr V):\n ArStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.Eq eβ eβ)\n (BoolExpr.Eq eβ' eβ)\n | lessArStepRight (eβ eβ eβ': ArExpr V):\n ArStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.Less eβ eβ)\n (BoolExpr.Less eβ eβ')\n | eqArStepRight (eβ eβ eβ': ArExpr V):\n ArStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.Eq eβ eβ)\n (BoolExpr.Eq eβ eβ')\n | orStepLeft (eβ eβ' eβ: BoolExpr V):\n BoolStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.Or eβ eβ)\n (BoolExpr.Or eβ' eβ)\n | andStepLeft (eβ eβ' eβ: BoolExpr V):\n BoolStep val eβ eβ' ->\n BoolStep val\n (BoolExpr.And eβ eβ)\n (BoolExpr.And eβ' eβ)\n | notStep (e e' : BoolExpr V):\n BoolStep val e e' -> BoolStep val\n (BoolExpr.Not e)\n (BoolExpr.Not e')"
},
{
"name": "StepStar",
"content": "inductive StepStar {ExprType: Type} {Step: StepKind V ExprType} : (val: V -> Int) -> ExprType -> ExprType -> Prop where\n | refl val e : StepStar val e e\n | trans eβ eβ eβ : Step val eβ eβ -> StepStar val eβ eβ -> StepStar val eβ eβ\n\n def eval (val: V -> Int) (e: ArExpr V) : Int :=\n match e with\n | ArExpr.Const x => x\n | ArExpr.Add lhs rhs => (eval val lhs) + (eval val rhs)\n | ArExpr.Sub lhs rhs => (eval val lhs) - (eval val rhs)\n | ArExpr.Mul lhs rhs => (eval val lhs) * (eval val rhs)\n | ArExpr.Var v => val v\n | ArExpr.If cond then_e else_e => if eval_bool val cond then eval val then_e else eval val else_e\n\n def eval_bool (val: V -> Int) (e: BoolExpr V): Bool :=\n match e with\n | BoolExpr.Const b => b\n | BoolExpr.Less l r => (eval val l) < (eval val r)\n | BoolExpr.Eq l r => (eval val l) == (eval val r)\n | BoolExpr.Not e => not (eval_bool val e)\n | BoolExpr.And l r => if eval_bool val l then eval_bool val r else false\n | BoolExpr.Or l r => if eval_bool val l then true else eval_bool val r"
}
] | [
{
"name": "bne_iff_ne",
"module": "Init.SimpLemmas"
},
{
"name": "Int.mul_eq_mul_right_iff",
"module": "Init.Data.Int.Lemmas"
},
{
"name": "beq_eq_false_iff_ne",
"module": "Init.SimpLemmas"
},
{
"name": "beq_iff_eq",
"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": "arstep_preserve_eval",
"content": " theorem arstep_preserve_eval (e e': ArExpr V): (ArStep V val) e e' -> eval V val e = eval V val e'"
}
] | import ExprEval.Expr
import ExprEval.Steps | theorem arstepstar_preserves_eval (e e': ArExpr V) :
ArStepStar V val e e' -> eval V val e = eval V val e' := | := by
intro h
induction h with
| refl _ => rfl
| trans _ _ _ h1 _ ih =>
rw [arstep_preserve_eval _ _ h1, ih] | 3 | 35 | false | Semantics |
271 | TM.progress | theorem progress t T
: HasType t T β value t β¨ β t', Step t t' | lean-formal-reasoning-program | Frap/Types.lean | [
"import Frap.SmallStep"
] | [
{
"name": "structure BitVec (w : Nat) where",
"module": ""
},
{
"name": "/-- Construct a `BitVec w` from a number less than `2^w`.",
"module": ""
},
{
"name": "O(1), because we use `Fin` as the internal representation of a bitvector. -/",
"module": ""
},
{
"name": "ofFin ::",
"module": ""
},
{
"name": "/-- Interpret a bitvector as a number less than `2^w`.",
"module": ""
},
{
"name": "O(1), because we use `Fin` as the internal representation of a bitvector. -/",
"module": ""
},
{
"name": "toFin : Fin (hPow 2 w)",
"module": ""
}
] | [
{
"name": "syntax term \"==>\" term : term",
"content": "syntax term \"==>\" term : term\n\nsyntax term \"~~>\" term : term\n\nsyntax term \"~~>*\" term : term\n\nsyntax:30 term \" =[ \" imp \" ]=> \" term : term\n\nsyntax term \"!->\" term \"; \" term : term\n\nsyntax:36 term \"<<->>\" term : term"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(term|$t:term ==> $n:term) => `(Eval $t $n)"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(term|$tβ:term ~~> $tβ:term) => `(Step $tβ $tβ)\n\nexample :\n p\n (p (c 1) (c 3))\n (p (c 2) (c 4))\n ~~>\n p\n (c 4)\n (p (c 2) (c 4)) := by admit /- proof elided -/"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(term|$tβ:term ~~>* $tβ:term) => `(Multi Step $tβ $tβ)"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(term|$p <<->> $q) => `($p ->> $q β§ $q ->> $p)"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(term|{*$p*} $c {*$q*}) => `(valid_hoare_triple $p $c $q)"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(term|$st =[ $c ]=> $st') => `(CEval <{$c}> $st $st')"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(term|$x:term !-> $a:term ; $st) => `(update $st $x $a)\n\nexample : empty =[\n x := 2;\n if (x <= 1) then y := 3 else z := 4 end\n ]=> (z !-> 4; x !-> 2; empty) := by admit /- proof elided -/"
},
{
"name": "Step",
"content": "inductive Step : Tm β Tm β Prop :=\n | st_ifTrue tβ tβ : Step (ite tru tβ tβ) tβ\n | st_ifFalse tβ tβ : Step (ite fls tβ tβ) tβ\n | st_if c c' tβ tβ :\n Step c c' β Step (ite c tβ tβ) (ite c' tβ tβ)\n | st_succ tβ tβ' : Step tβ tβ' β Step (scc tβ) (scc tβ')\n | st_pred0 : Step (prd zro) zro\n | st_predSucc v : NValue v β Step (prd (scc v)) v\n | st_pred tβ tβ' : Step tβ tβ' β Step (prd tβ) (prd tβ')\n | st_iszero0 : Step (iszero zro) tru\n | st_iszeroSucc v : NValue v β Step (iszero (scc v)) fls\n | st_iszero tβ tβ' :\n Step tβ tβ' β Step (iszero tβ) (iszero tβ')"
},
{
"name": "Tm",
"content": "inductive Tm : Type :=\n | tru : Tm\n | fls : Tm\n | ite : Tm β Tm β Tm β Tm\n | zro : Tm\n | scc : Tm β Tm\n | prd : Tm β Tm\n | iszero : Tm β Tm"
},
{
"name": "NValue",
"content": "inductive NValue : Tm β Prop :=\n | nv_0 : NValue zro\n | nv_succ t : NValue t β NValue (scc t)"
},
{
"name": "Ty",
"content": "inductive Ty : Type :=\n | bool : Ty\n | nat : Ty"
},
{
"name": "HasType",
"content": "inductive HasType : Tm β Ty β Prop :=\n | t_true : HasType tru bool\n | t_false : HasType fls bool\n | t_if tβ tβ tβ T :\n HasType tβ bool β HasType tβ T β HasType tβ T\n β HasType (ite tβ tβ tβ) T\n | t_0 : HasType zro nat\n | t_succ tβ : HasType tβ nat β HasType (scc tβ) nat\n | t_pred tβ : HasType tβ nat β HasType (prd tβ) nat\n | t_iszero tβ : HasType tβ nat β HasType (iszero tβ) bool"
},
{
"name": "Tm",
"content": "inductive Tm : Type :=\n | c : Nat β Tm \n | p : Tm β Tm β Tm "
},
{
"name": "BValue",
"content": "inductive BValue : Tm β Prop :=\n | bv_true : BValue tru\n | bv_false : BValue fls"
}
] | [
{
"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": "TM.Tm",
"content": "inductive Tm : Type :=\n | tru : Tm\n | fls : Tm\n | ite : Tm β Tm β Tm β Tm\n | zro : Tm\n | scc : Tm β Tm\n | prd : Tm β Tm\n | iszero : Tm β Tm"
},
{
"name": "TM.BValue",
"content": "inductive BValue : Tm β Prop :=\n | bv_true : BValue tru\n | bv_false : BValue fls"
},
{
"name": "TM.NValue",
"content": "inductive NValue : Tm β Prop :=\n | nv_0 : NValue zro\n | nv_succ t : NValue t β NValue (scc t)"
},
{
"name": "TM.value",
"content": "abbrev value (t : Tm) := BValue t β¨ NValue t"
},
{
"name": "TM.Step",
"content": "inductive Step : Tm β Tm β Prop :=\n | st_ifTrue tβ tβ : Step (ite tru tβ tβ) tβ\n | st_ifFalse tβ tβ : Step (ite fls tβ tβ) tβ\n | st_if c c' tβ tβ :\n Step c c' β Step (ite c tβ tβ) (ite c' tβ tβ)\n | st_succ tβ tβ' : Step tβ tβ' β Step (scc tβ) (scc tβ')\n | st_pred0 : Step (prd zro) zro\n | st_predSucc v : NValue v β Step (prd (scc v)) v\n | st_pred tβ tβ' : Step tβ tβ' β Step (prd tβ) (prd tβ')\n | st_iszero0 : Step (iszero zro) tru\n | st_iszeroSucc v : NValue v β Step (iszero (scc v)) fls\n | st_iszero tβ tβ' :\n Step tβ tβ' β Step (iszero tβ) (iszero tβ')"
},
{
"name": "TM.Ty",
"content": "inductive Ty : Type :=\n | bool : Ty\n | nat : Ty"
},
{
"name": "TM.HasType",
"content": "inductive HasType : Tm β Ty β Prop :=\n | t_true : HasType tru bool\n | t_false : HasType fls bool\n | t_if tβ tβ tβ T :\n HasType tβ bool β HasType tβ T β HasType tβ T\n β HasType (ite tβ tβ tβ) T\n | t_0 : HasType zro nat\n | t_succ tβ : HasType tβ nat β HasType (scc tβ) nat\n | t_pred tβ : HasType tβ nat β HasType (prd tβ) nat\n | t_iszero tβ : HasType tβ nat β HasType (iszero tβ) bool"
}
] | [
{
"name": "TM.bool_canonical",
"content": "theorem bool_canonical t : HasType t bool β value t β BValue t"
},
{
"name": "TM.nat_canonical",
"content": "theorem nat_canonical t : HasType t nat β value t β NValue t"
}
] | import Frap.SmallStep
namespace TM
inductive Tm : Type :=
| tru : Tm
| fls : Tm
| ite : Tm β Tm β Tm β Tm
| zro : Tm
| scc : Tm β Tm
| prd : Tm β Tm
| iszero : Tm β Tm
open Tm
inductive BValue : Tm β Prop :=
| bv_true : BValue tru
| bv_false : BValue fls
inductive NValue : Tm β Prop :=
| nv_0 : NValue zro
| nv_succ t : NValue t β NValue (scc t)
open BValue
open NValue
abbrev value (t : Tm) := BValue t β¨ NValue t
inductive Step : Tm β Tm β Prop :=
| st_ifTrue tβ tβ : Step (ite tru tβ tβ) tβ
| st_ifFalse tβ tβ : Step (ite fls tβ tβ) tβ
| st_if c c' tβ tβ :
Step c c' β Step (ite c tβ tβ) (ite c' tβ tβ)
| st_succ tβ tβ' : Step tβ tβ' β Step (scc tβ) (scc tβ')
| st_pred0 : Step (prd zro) zro
| st_predSucc v : NValue v β Step (prd (scc v)) v
| st_pred tβ tβ' : Step tβ tβ' β Step (prd tβ) (prd tβ')
| st_iszero0 : Step (iszero zro) tru
| st_iszeroSucc v : NValue v β Step (iszero (scc v)) fls
| st_iszero tβ tβ' :
Step tβ tβ' β Step (iszero tβ) (iszero tβ')
open Step
inductive Ty : Type :=
| bool : Ty
| nat : Ty
open Ty
inductive HasType : Tm β Ty β Prop :=
| t_true : HasType tru bool
| t_false : HasType fls bool
| t_if tβ tβ tβ T :
HasType tβ bool β HasType tβ T β HasType tβ T
β HasType (ite tβ tβ tβ) T
| t_0 : HasType zro nat
| t_succ tβ : HasType tβ nat β HasType (scc tβ) nat
| t_pred tβ : HasType tβ nat β HasType (prd tβ) nat
| t_iszero tβ : HasType tβ nat β HasType (iszero tβ) bool
open HasType
example -- `β’ if false then 0 else (succ 0) β nat`
: HasType (ite fls zro (scc zro)) nat := by
apply t_if
. apply t_false
. apply t_0
. apply t_succ
apply t_0
/-
It's important to realize that the typing relation is a _conservative_ (or _static_) approximation: it does not consider what happens when the term is reduced.
In particular, it does not calculate the type of its normal form.
-/
example -- `β’ if false then zero else true β bool`
: Β¬ HasType (ite fls zro tru) bool := by
intro contra
cases contra
rename_i contra _
cases contra
/-
exercise (1-star)
-/
example t : HasType (scc t) nat β HasType t nat := by
intro ht
cases ht
assumption | theorem progress t T
: HasType t T β value t β¨ β t', Step t t' := | := by
intro ht
induction ht with
| t_if tβ tβ tβ T =>
rename_i ihβ ihβ ihβ
right; cases ihβ
. -- tβ is a value
have h : BValue tβ := by
apply bool_canonical <;> assumption
cases h
. exists tβ; apply st_ifTrue
. exists tβ; apply st_ifFalse
. -- tβ can take a step
rename_i h
obtain β¨tβ', hββ© := h
exists ite tβ' tβ tβ
apply st_if; exact hβ
| t_true =>
left;unfold value; left; apply bv_true
| t_false =>
left; unfold value; left; apply bv_false
| t_0 =>
left; unfold value; right; apply nv_0
| t_succ t =>
rename_i ih
cases ih
. -- t is a value
left
have h : NValue t := by
apply nat_canonical <;> assumption
cases h
. unfold value; right; apply nv_succ; apply nv_0
. unfold value; right; apply nv_succ; apply nv_succ; assumption
. -- t can take a step
right
rename_i ih
obtain β¨t', hβ© := ih
exists (scc t')
apply st_succ; exact h
| t_pred t =>
rename_i ih
right; cases ih
. -- t is a value
have h : NValue t := by
apply nat_canonical <;> assumption
cases h
. exists zro; apply st_pred0
. constructor; apply st_predSucc; assumption
. -- t can take a step
rename_i h
obtain β¨t', hβ© := h
exists (prd t')
apply st_pred; exact h
| t_iszero t =>
rename_i ih
right; cases ih
. -- t is a value
have h : NValue t := by
apply nat_canonical <;> assumption
cases h
. exists tru; apply st_iszero0
. exists fls; apply st_iszeroSucc; assumption
. -- t can take a step
rename_i h
obtain β¨t', hβ© := h
exists (iszero t')
apply st_iszero; exact h
/-
### Type preservation
The second critical property of typing is that, when a well-typed term takes a step, the result is a well-typed term (of the same type).
-/
/-
exercise (3-star)
Complete the following informal proof:
_Theorem_: If `β’ t β T` and `t ~~> t'`, then `β’ t' β T`.
_Proof_: By induction on a derivation of `β’ t β T`.
* If the last rule in the derivation is `t_if`, then `t = if tβ then tβ else tβ`, with `β’ tβ β bool`, `β’ tβ β T`, and `β’ tβ β T`.
Inspecting the rules for the small-step reduction relation and remembering that `t` is the form `if ...`, we see that the only ones that could have been used to prove `t ~~> t'` are `st_ifTrue`, `st_ifFalse`, or `st_if`.
* If the last rule was `st_ifTrue`, then `t' = tβ`.
But we know that `β’ tβ β T`, so we are done.
* If the last rule was `st_ifFalse`, then `t' = tβ`.
But we know that `β’ tβ β T`, so we are done.
* If the last rule was `st_if`, then `t' = if tβ' then tβ else tβ`, where `tβ ~~> tβ'`.
We know `β’ tβ β bool`, so by the IH, `β’ tβ' β bool`.
The `t_if` rule then gives us `β’ if if tβ' then tβ else tβ β T`, as required.
/- **FILL IN HERE** -/
-/ | 2 | 16 | true | Semantics |
272 | Imp.fold_constants_com_sound | theorem fold_constants_com_sound : ctrans_sound fold_constants_com | lean-formal-reasoning-program | Frap/Trans.lean | [
"import Frap.Exercises.Equiv",
"import Frap.Equiv"
] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "String",
"module": "Init.Prelude"
},
{
"name": "Bool",
"module": "Init.Prelude"
}
] | [
{
"name": "syntax \"<[\" term \"]>\" : imp",
"content": "syntax \"<[\" term \"]>\" : imp\n\nsyntax \"<{\" imp \"}>\" : term\n\nsyntax \"false\" : imp\n\nsyntax \"false\" : term\n\nsyntax:21 \"if\" imp:20 \"then\" imp:20 \"else\" imp:20 \"end\" : imp\n\nsyntax \"true\" : imp\n\nsyntax \"true\" : term\n\nsyntax \"skip\" : imp\n\nsyntax:21 \"while\" imp:20 \"do\" imp:20 \"end\" : imp"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(term|true) => `(Bool.true)\n | `(term|false) => `(Bool.false)\n | `(term|<{$x}>) => `(imp|$x)\n | `(imp|$n:num) => `(a_num $n)\n | `(imp|$s:str) => `(a_id $s)\n | `(imp|$x + $y) => `(a_plus <{$x}> <{$y}>)\n | `(imp|$x - $y) => `(a_minus <{$x}> <{$y}>)\n | `(imp|$x * $y) => `(a_mult <{$x}> <{$y}>)\n | `(imp|true) => `(b_true)\n | `(imp|false) => `(b_false)\n | `(imp|$x = $y) => `(b_eq <{$x}> <{$y}>)\n | `(imp|$x != $y) => `(b_neq <{$x}> <{$y}>)\n | `(imp|$x <= $y) => `(b_le <{$x}> <{$y}>)\n | `(imp|!$x) => `(b_not <{$x}>)\n | `(imp|$x && $y) => `(b_and <{$x}> <{$y}>)\n | `(imp|$x || $y) => `(b_or <{$x}> <{$y}>)\n | `(imp|($x)) => `(<{$x}>)\n | `(imp|$x:ident) => `(a_id $(Lean.quote (toString x.getId)))\n | `(imp|<[$t:term]>) => pure t"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(imp|skip) => `(c_skip)\n | `(imp|$x:str := $y) => `(c_asgn $x <{$y}>)\n | `(imp|$x:ident := $y) => `(c_asgn $x <{$y}>)\n | `(imp|$c1 ; $c2) => `(c_seq <{$c1}> <{$c2}>)\n | `(imp|if $b then $c1 else $c2 end) => `(c_if <{$b}> <{$c1}> <{$c2}>)\n | `(imp|while $b do $c end) => `(c_while <{$b}> <{$c}>)"
},
{
"name": "cequiv",
"content": "def cequiv (cβ cβ : Com) : Prop :=\n β st st' : State, (st =[<[cβ]>]=> st') β (st =[<[cβ]>]=> st')"
},
{
"name": "State",
"content": "abbrev State := String β Nat"
},
{
"name": "Com",
"content": "inductive Com :=\n | c_skip : Com\n | c_asgn : String β AExp β Com\n | c_seq : Com β Com β Com\n | c_if : BExp β Com β Com β Com\n | c_while : BExp β Com β Com"
},
{
"name": "AExp",
"content": "inductive AExp where\n | a_num : Nat β AExp\n | a_id : String β AExp \n | a_plus : AExp β AExp β AExp\n | a_minus : AExp β AExp β AExp\n | a_mult : AExp β AExp β AExp"
},
{
"name": "AExp",
"content": "inductive AExp where\n | a_num : Nat β AExp\n | a_plus : AExp β AExp β AExp\n | a_minus : AExp β AExp β AExp\n | a_mult : AExp β AExp β AExp"
},
{
"name": "Com",
"content": "inductive Com : Type :=\n | c_skip : Com\n | c_asgn : String β AExp β Com\n | c_seq : Com β Com β Com\n | c_if : BExp β Com β Com β Com\n | c_while : BExp β Com β Com\n | c_par : Com β Com β Com "
},
{
"name": "BExp",
"content": "inductive BExp where\n | b_true : BExp\n | b_false : BExp\n | b_eq : AExp β AExp β BExp\n | b_neq : AExp β AExp β BExp\n | b_le : AExp β AExp β BExp\n | b_not : BExp β BExp\n | b_and : BExp β BExp β BExp\n | b_or : BExp β BExp β BExp"
},
{
"name": "x",
"content": "abbrev x := \"x\""
},
{
"name": "y",
"content": "abbrev y := \"y\""
},
{
"name": "loop",
"content": "def loop : Com :=\n <{ while true do\n skip\n end }>"
},
{
"name": "bequiv",
"content": "def bequiv (bβ bβ : BExp) : Prop :=\n β (st : State), beval st bβ = beval st bβ"
},
{
"name": "beval",
"content": "def beval (st : State) (b : BExp) : Bool :=\n match b with\n | b_true => true\n | b_false => false\n | b_eq aβ aβ => (aeval st aβ) == (aeval st aβ)\n | b_neq aβ aβ => (aeval st aβ) != (aeval st aβ)\n | b_le aβ aβ => (aeval st aβ) <= (aeval st aβ)\n | b_not bβ => not (beval st bβ)\n | b_and bβ bβ => and (beval st bβ) (beval st bβ)\n | b_or bβ bβ => or (beval st bβ) (beval st bβ)\n\nexample : aeval (update empty x 5)\n <{3 + x * 2}>\n \n = 13 := by admit /- proof elided -/"
},
{
"name": "empty",
"content": "def empty : State := fun _ => 0"
},
{
"name": "z",
"content": "abbrev z := \"z\""
},
{
"name": "aeval",
"content": "def aeval (st : State) (a : AExp) : Nat :=\n match a with\n | a_num n => n\n | a_id x => st x\n | a_plus aβ aβ => (aeval st aβ) + (aeval st aβ)\n | a_minus aβ aβ => (aeval st aβ) - (aeval st aβ)\n | a_mult aβ aβ => (aeval st aβ) * (aeval st aβ)"
},
{
"name": "update",
"content": "def update (st : State) (k : String) (v : Nat) : State :=\n fun x => if x == k then v else st x"
},
{
"name": "aequiv",
"content": "def aequiv (aβ aβ : AExp) : Prop :=\n β (st : State), aeval st aβ = aeval st aβ"
},
{
"name": "CEval",
"content": "inductive CEval : Com β State β State β Prop :=\n | e_skip : β st,\n CEval c_skip st st\n | e_asgn : β a n x st,\n aeval st a = n\n β CEval (c_asgn x a) st (update st x n)\n | e_seq : β cβ cβ st st' st'',\n CEval cβ st st' β CEval cβ st' st''\n β CEval (c_seq cβ cβ) st st''\n | e_ifTrue : β b cβ cβ st st',\n beval st b = true β CEval cβ st st'\n β CEval (c_if b cβ cβ) st st'\n | e_ifFalse : β b cβ cβ st st',\n beval st b = false β CEval cβ st st'\n β CEval (c_if b cβ cβ) st st'\n | e_whileFalse : β b c st,\n beval st b = false\n β CEval (c_while b c) st st\n | e_whileTrue : β b c st st' st'',\n beval st b = true\n β CEval c st st'\n β CEval (c_while b c) st' st''\n β CEval (c_while b c) st st''"
}
] | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "if_true",
"content": "theorem if_true b cβ cβ\n : bequiv b <{true}> β cequiv <{if <[b]> then <[cβ]> else <[cβ]> end}> cβ"
},
{
"name": "if_false",
"content": "theorem if_false b cβ cβ\n : bequiv b <{false}> β cequiv <{if <[b]> then <[cβ]> else <[cβ]> end}> cβ"
},
{
"name": "while_false",
"content": "theorem while_false b c : bequiv b <{false}> β\n cequiv <{while <[b]> do <[c]> end}> <{skip}>"
}
] | [
{
"name": "Imp.atrans_sound",
"content": "def atrans_sound (atrans : AExp β AExp) :=\n β (a : AExp), aequiv a (atrans a)"
},
{
"name": "Imp.btrans_sound",
"content": "def btrans_sound (btrans : BExp β BExp) :=\n β (b : BExp), bequiv b (btrans b)"
},
{
"name": "Imp.ctrans_sound",
"content": "def ctrans_sound (ctrans : Com β Com) :=\n β (c : Com), cequiv c (ctrans c)"
},
{
"name": "Imp.fold_constants_aexp",
"content": "def fold_constants_aexp (a : AExp) : AExp :=\n match a with\n | a_num _\n | a_id _\n => a\n | a_plus a1 a2 =>\n match (fold_constants_aexp a1, fold_constants_aexp a2) with\n | (a_num n1, a_num n2) => a_num (n1 + n2)\n | (a1', a2') => a_plus a1' a2'\n | a_minus a1 a2 =>\n match (fold_constants_aexp a1, fold_constants_aexp a2) with\n | (a_num n1, a_num n2) => a_num (n1 - n2)\n | (a1', a2') => a_minus a1' a2'\n | a_mult a1 a2 =>\n match (fold_constants_aexp a1, fold_constants_aexp a2) with\n | (a_num n1, a_num n2) => a_num (n1 * n2)\n | (a1', a2') => a_mult a1' a2'\n\nexample : fold_constants_aexp <{(1 + 2) * x}> = <{3 * x}> := by admit /- proof elided -/"
},
{
"name": "Imp.fold_constants_bexp",
"content": "def fold_constants_bexp (b : BExp) : BExp :=\n match b with\n | b_true\n | b_false\n => b\n | b_eq a1 a2 =>\n match (fold_constants_aexp a1, fold_constants_aexp a2) with\n | (a_num n1, a_num n2) => if n1 == n2 then b_true else b_false\n | (a1', a2') => b_eq a1' a2'\n | b_neq a1 a2 =>\n match (fold_constants_aexp a1, fold_constants_aexp a2) with\n | (a_num n1, a_num n2) => if n1 != n2 then b_true else b_false\n | (a1', a2') => b_neq a1' a2'\n | b_le a1 a2 =>\n match (fold_constants_aexp a1, fold_constants_aexp a2) with\n | (a_num n1, a_num n2) => if n1 <= n2 then b_true else b_false\n | (a1', a2') => b_le a1' a2'\n | b_not b1 =>\n match fold_constants_bexp b1 with\n | b_true => b_false\n | b_false => b_true\n | b1' => b_not b1'\n | b_and b1 b2 =>\n match (fold_constants_bexp b1, fold_constants_bexp b2) with\n | (b_true, b_true) => b_true\n | (b_true, b_false) => b_false\n | (b_false, b_true) => b_false\n | (b_false, b_false) => b_false\n | (b1', b2') => b_and b1' b2'\n | b_or b1 b2 =>\n match (fold_constants_bexp b1, fold_constants_bexp b2) with\n | (b_true, b_true) => b_true\n | (b_true, b_false) => b_true\n | (b_false, b_true) => b_true\n | (b_false, b_false) => b_false\n | (b1', b2') => b_or b1' b2'\n\nexample : fold_constants_bexp <{true && !(false && true)}> = <{true}> := by admit /- proof elided -/"
},
{
"name": "Imp.fold_constants_com",
"content": "def fold_constants_com (c : Com) : Com :=\n match c with\n | c_skip => c\n | c_asgn x a => c_asgn x (fold_constants_aexp a)\n | c_seq c1 c2 => c_seq (fold_constants_com c1) (fold_constants_com c2)\n | c_if b c1 c2 =>\n match fold_constants_bexp b with\n | b_true => fold_constants_com c1\n | b_false => fold_constants_com c2\n | b' => c_if b' (fold_constants_com c1) (fold_constants_com c2)\n | c_while b c1 =>\n match fold_constants_bexp b with\n | b_true => loop\n | b_false => c_skip\n | b' => c_while b' (fold_constants_com c1)\n\nexample : fold_constants_com\n \n <{ x := 4 + 5;\n y := x - 3;\n if (x - y) = (2 + 4) then skip\n else y := 0 end;\n if 0 <= (4 - (2 + 1)) then y := 0\n else skip end;\n while y = 0 do\n x := x + 1\n end }>\n = \n <{ x := 9;\n y := x - 3;\n if (x - y) = 6 then skip\n else y := 0 end;\n y := 0;\n while y = 0 do\n x := x + 1\n end }> := by admit /- proof elided -/"
}
] | [
{
"name": "Imp.while_true",
"content": "theorem while_true b c :\n bequiv b <{true}> β cequiv <{while <[b]> do <[c]> end}> loop"
},
{
"name": "Imp.sym_bequiv",
"content": "theorem sym_bequiv bβ bβ : bequiv bβ bβ β bequiv bβ bβ"
},
{
"name": "Imp.sym_cequiv",
"content": "theorem sym_cequiv cβ cβ : cequiv cβ cβ β cequiv cβ cβ"
},
{
"name": "Imp.trans_cequiv",
"content": "theorem trans_cequiv cβ cβ cβ : cequiv cβ cβ β cequiv cβ cβ β cequiv cβ cβ"
},
{
"name": "Imp.c_asgn_congruence",
"content": "theorem c_asgn_congruence x a a'\n : aequiv a a' β cequiv <{x := <[a]>}> <{x := <[a']>}>"
},
{
"name": "Imp.c_while_congruence",
"content": "theorem c_while_congruence b b' c c'\n : bequiv b b' β cequiv c c'\n β cequiv <{while <[b]> do <[c]> end}> <{while <[b']> do <[c']> end}>"
},
{
"name": "Imp.c_seq_congruence",
"content": "theorem c_seq_congruence cβ cβ' cβ cβ'\n : cequiv cβ cβ' β cequiv cβ cβ' β cequiv (c_seq cβ cβ) (c_seq cβ' cβ')"
},
{
"name": "Imp.c_if_congruence",
"content": "theorem c_if_congruence b b' cβ cβ' cβ cβ'\n : bequiv b b' β cequiv cβ cβ' β cequiv cβ cβ'\n β cequiv (c_if b cβ cβ) (c_if b' cβ' cβ')"
},
{
"name": "Imp.fold_constants_aexp_sound",
"content": "theorem fold_constants_aexp_sound : atrans_sound fold_constants_aexp"
},
{
"name": "Imp.fold_constants_bexp_sound",
"content": "theorem fold_constants_bexp_sound : btrans_sound fold_constants_bexp"
}
] | import Frap.Equiv
import Frap.Exercises.Equiv
namespace Imp
open AExp
open BExp
open Com
open CEval
def atrans_sound (atrans : AExp β AExp) :=
β (a : AExp), aequiv a (atrans a)
def btrans_sound (btrans : BExp β BExp) :=
β (b : BExp), bequiv b (btrans b)
def ctrans_sound (ctrans : Com β Com) :=
β (c : Com), cequiv c (ctrans c)
def fold_constants_aexp (a : AExp) : AExp :=
match a with
| a_num _
| a_id _
=> a
| a_plus a1 a2 =>
match (fold_constants_aexp a1, fold_constants_aexp a2) with
| (a_num n1, a_num n2) => a_num (n1 + n2)
| (a1', a2') => a_plus a1' a2'
| a_minus a1 a2 =>
match (fold_constants_aexp a1, fold_constants_aexp a2) with
| (a_num n1, a_num n2) => a_num (n1 - n2)
| (a1', a2') => a_minus a1' a2'
| a_mult a1 a2 =>
match (fold_constants_aexp a1, fold_constants_aexp a2) with
| (a_num n1, a_num n2) => a_num (n1 * n2)
| (a1', a2') => a_mult a1' a2'
example : fold_constants_aexp <{(1 + 2) * x}> = <{3 * x}> := by admit /- proof elided -/
def fold_constants_bexp (b : BExp) : BExp :=
match b with
| b_true
| b_false
=> b
| b_eq a1 a2 =>
match (fold_constants_aexp a1, fold_constants_aexp a2) with
| (a_num n1, a_num n2) => if n1 == n2 then b_true else b_false
| (a1', a2') => b_eq a1' a2'
| b_neq a1 a2 =>
match (fold_constants_aexp a1, fold_constants_aexp a2) with
| (a_num n1, a_num n2) => if n1 != n2 then b_true else b_false
| (a1', a2') => b_neq a1' a2'
| b_le a1 a2 =>
match (fold_constants_aexp a1, fold_constants_aexp a2) with
| (a_num n1, a_num n2) => if n1 <= n2 then b_true else b_false
| (a1', a2') => b_le a1' a2'
| b_not b1 =>
match fold_constants_bexp b1 with
| b_true => b_false
| b_false => b_true
| b1' => b_not b1'
| b_and b1 b2 =>
match (fold_constants_bexp b1, fold_constants_bexp b2) with
| (b_true, b_true) => b_true
| (b_true, b_false) => b_false
| (b_false, b_true) => b_false
| (b_false, b_false) => b_false
| (b1', b2') => b_and b1' b2'
| b_or b1 b2 =>
match (fold_constants_bexp b1, fold_constants_bexp b2) with
| (b_true, b_true) => b_true
| (b_true, b_false) => b_true
| (b_false, b_true) => b_true
| (b_false, b_false) => b_false
| (b1', b2') => b_or b1' b2'
example : fold_constants_bexp <{true && !(false && true)}> = <{true}> := by admit /- proof elided -/
def fold_constants_com (c : Com) : Com :=
match c with
| c_skip => c
| c_asgn x a => c_asgn x (fold_constants_aexp a)
| c_seq c1 c2 => c_seq (fold_constants_com c1) (fold_constants_com c2)
| c_if b c1 c2 =>
match fold_constants_bexp b with
| b_true => fold_constants_com c1
| b_false => fold_constants_com c2
| b' => c_if b' (fold_constants_com c1) (fold_constants_com c2)
| c_while b c1 =>
match fold_constants_bexp b with
| b_true => loop
| b_false => c_skip
| b' => c_while b' (fold_constants_com c1)
example : fold_constants_com
<{ x := 4 + 5;
y := x - 3;
if (x - y) = (2 + 4) then skip
else y := 0 end;
if 0 <= (4 - (2 + 1)) then y := 0
else skip end;
while y = 0 do
x := x + 1
end }>
=
<{ x := 9;
y := x - 3;
if (x - y) = 6 then skip
else y := 0 end;
y := 0;
while y = 0 do
x := x + 1
end }> := by admit /- proof elided -/ | theorem fold_constants_com_sound : ctrans_sound fold_constants_com := | := by
intro c; induction c with simp [fold_constants_com]
| c_asgn =>
apply c_asgn_congruence
apply fold_constants_aexp_sound
| c_seq =>
apply c_seq_congruence <;> assumption
| c_if b cβ cβ ih1 ih2 =>
split
. apply trans_cequiv _ cβ
. apply if_true
rename_i heq; rw [β heq]
apply fold_constants_bexp_sound
. assumption
. apply trans_cequiv _ cβ
. apply if_false
rename_i heq; rw [β heq]
apply fold_constants_bexp_sound
. assumption
. apply c_if_congruence
. apply fold_constants_bexp_sound
. assumption
. assumption
| c_while b c' ih =>
split
. apply while_true
rename_i heq; rw [β heq]
apply fold_constants_bexp_sound
. apply while_false
rename_i heq; rw [β heq]
apply fold_constants_bexp_sound
. apply c_while_congruence
. apply fold_constants_bexp_sound
. assumption | 5 | 40 | true | Semantics |
273 | CImp.par_loop_any_x | theorem par_loop_any_x n
: β st', Multi CStep (par_loop, empty) (c_skip, st')
β§ st' x = n | lean-formal-reasoning-program | Frap/SmallStepImp.lean | [
"import Frap.SmallStep",
"import Frap.Equiv"
] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "String",
"module": "Init.Prelude"
},
{
"name": "And",
"module": "Init.Prelude"
}
] | [
{
"name": "syntax:21 \"if\" imp:20 \"then\" imp:20 \"else\" imp:20 \"end\" : im",
"content": "syntax:21 \"if\" imp:20 \"then\" imp:20 \"else\" imp:20 \"end\" : imp"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(term|true) => `(Bool.true)\n | `(term|false) => `(Bool.false)\n | `(term|<{$x}>) => `(imp|$x)\n | `(imp|$n:num) => `(a_num $n)\n | `(imp|$s:str) => `(a_id $s)\n | `(imp|$x + $y) => `(a_plus <{$x}> <{$y}>)\n | `(imp|$x - $y) => `(a_minus <{$x}> <{$y}>)\n | `(imp|$x * $y) => `(a_mult <{$x}> <{$y}>)\n | `(imp|true) => `(b_true)\n | `(imp|false) => `(b_false)\n | `(imp|$x = $y) => `(b_eq <{$x}> <{$y}>)\n | `(imp|$x != $y) => `(b_neq <{$x}> <{$y}>)\n | `(imp|$x <= $y) => `(b_le <{$x}> <{$y}>)\n | `(imp|!$x) => `(b_not <{$x}>)\n | `(imp|$x && $y) => `(b_and <{$x}> <{$y}>)\n | `(imp|$x || $y) => `(b_or <{$x}> <{$y}>)\n | `(imp|($x)) => `(<{$x}>)\n | `(imp|$x:ident) => `(a_id $(Lean.quote (toString x.getId)))\n | `(imp|<[$t:term]>) => pure t"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(imp|skip) => `(c_skip)\n | `(imp|$x:str := $y) => `(c_asgn $x <{$y}>)\n | `(imp|$x:ident := $y) => `(c_asgn $x <{$y}>)\n | `(imp|$c1 ; $c2) => `(c_seq <{$c1}> <{$c2}>)\n | `(imp|if $b then $c1 else $c2 end) => `(c_if <{$b}> <{$c1}> <{$c2}>)\n | `(imp|while $b do $c end) => `(c_while <{$b}> <{$c}>)"
},
{
"name": "AExp",
"content": "inductive AExp where\n | a_num : Nat β AExp\n | a_id : String β AExp \n | a_plus : AExp β AExp β AExp\n | a_minus : AExp β AExp β AExp\n | a_mult : AExp β AExp β AExp"
},
{
"name": "AExp",
"content": "inductive AExp where\n | a_num : Nat β AExp\n | a_plus : AExp β AExp β AExp\n | a_minus : AExp β AExp β AExp\n | a_mult : AExp β AExp β AExp"
},
{
"name": "State",
"content": "abbrev State := String β Nat"
},
{
"name": "BExp",
"content": "inductive BExp where\n | b_true : BExp\n | b_false : BExp\n | b_eq : AExp β AExp β BExp\n | b_neq : AExp β AExp β BExp\n | b_le : AExp β AExp β BExp\n | b_not : BExp β BExp\n | b_and : BExp β BExp β BExp\n | b_or : BExp β BExp β BExp"
},
{
"name": "x",
"content": "abbrev x := \"x\""
},
{
"name": "Com",
"content": "inductive Com :=\n | c_skip : Com\n | c_asgn : String β AExp β Com\n | c_seq : Com β Com β Com\n | c_if : BExp β Com β Com β Com\n | c_while : BExp β Com β Com"
},
{
"name": "empty",
"content": "def empty : State := fun _ => 0"
},
{
"name": "Multi",
"content": "inductive Multi {X : Type} (R : relation X) : relation X :=\n | multi_refl x : Multi R x x\n | multi_step x y z : R x y β Multi R y z β Multi R x z"
},
{
"name": "relation",
"content": "def relation (X : Type) := X β X β Prop"
},
{
"name": "update",
"content": "def update (st : State) (k : String) (v : Nat) : State :=\n fun x => if x == k then v else st x"
},
{
"name": "y",
"content": "abbrev y := \"y\""
},
{
"name": "And",
"content": "inductive And : Prop β Prop β Prop where\n | intro : a β b β And a b"
}
] | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "multi_R",
"content": "theorem multi_R (X : Type) (R : relation X) x y : R x y β Multi R x y"
},
{
"name": "multi_trans",
"content": "theorem multi_trans (X : Type) (R : relation X) x y z\n : Multi R x y β Multi R y z β Multi R x z"
}
] | [
{
"name": "AVal",
"content": "inductive AVal : AExp β Prop :=\n | av_num : β n, AVal (a_num n)"
},
{
"name": "AStep",
"content": "inductive AStep (st : State) : AExp β AExp β Prop :=\n | as_id : β v, AStep st (a_id v) (a_num (st v))\n | as_plus1 : β aβ aβ' aβ,\n AStep st aβ aβ'\n β AStep st (a_plus aβ aβ) (a_plus aβ' aβ)\n | as_plus2 : β vβ aβ aβ',\n AVal vβ β AStep st aβ aβ'\n β AStep st (a_plus vβ aβ) (a_plus vβ aβ')\n | as_plus : β (vβ vβ : Nat),\n AStep st (a_plus (a_num vβ) (a_num vβ)) (a_num (vβ + vβ))\n | as_minus1 : β aβ aβ' aβ,\n AStep st aβ aβ'\n β AStep st (a_minus aβ aβ) (a_minus aβ' aβ)\n | as_minus2 : β vβ aβ aβ',\n AVal vβ β AStep st aβ aβ'\n β AStep st (a_minus vβ aβ) (a_minus vβ aβ')\n | as_minus : β (vβ vβ : Nat),\n AStep st (a_minus (a_num vβ) (a_num vβ)) (a_num (vβ - vβ))\n | as_mult1 : β aβ aβ' aβ,\n AStep st aβ aβ'\n β AStep st (a_mult aβ aβ) (a_mult aβ' aβ)\n | as_mult2 : β vβ aβ aβ',\n AVal vβ β AStep st aβ aβ'\n β AStep st (a_mult vβ aβ) (a_mult vβ aβ')\n | as_mult : β (vβ vβ : Nat),\n AStep st (a_mult (a_num vβ) (a_num vβ)) (a_num (vβ * vβ))"
},
{
"name": "BStep",
"content": "inductive BStep (st : State) : BExp β BExp β Prop :=\n | bs_eq1 : β aβ aβ' aβ,\n AStep st aβ aβ'\n β BStep st (b_eq aβ aβ) (b_eq aβ' aβ)\n | bs_eq2 : β vβ aβ aβ',\n AVal vβ β AStep st aβ aβ'\n β BStep st (b_eq vβ aβ) (b_eq vβ aβ')\n | bs_eq : β (vβ vβ : Nat),\n BStep st (b_eq (a_num vβ) (a_num vβ))\n (if vβ == vβ then b_true else b_false)\n | bs_neq1 : β aβ aβ' aβ,\n AStep st aβ aβ'\n β BStep st (b_neq aβ aβ) (b_neq aβ' aβ)\n | bs_neq2 : β vβ aβ aβ',\n AVal vβ β AStep st aβ aβ'\n β BStep st (b_neq vβ aβ) (b_neq vβ aβ')\n | bs_neq : β (vβ vβ : Nat),\n BStep st (b_neq (a_num vβ) (a_num vβ))\n (if vβ != vβ then b_true else b_false)\n | bs_le1 : β aβ aβ' aβ,\n AStep st aβ aβ'\n β BStep st (b_le aβ aβ) (b_le aβ' aβ)\n | bs_le2 : β vβ aβ aβ',\n AVal vβ β AStep st aβ aβ'\n β BStep st (b_le vβ aβ) (b_le vβ aβ')\n | bs_le : β (vβ vβ : Nat),\n BStep st (b_le (a_num vβ) (a_num vβ))\n (if vβ <= vβ then b_true else b_false)\n | bs_notStep : β bβ bβ',\n BStep st bβ bβ'\n β BStep st (b_not bβ) (b_not bβ')\n | bs_notTrue : BStep st (b_not b_true) b_false\n | bs_notFalse : BStep st (b_not b_false) b_true\n | bs_andStep : β bβ bβ' bβ,\n BStep st bβ bβ'\n β BStep st (b_and bβ bβ) (b_and bβ' bβ)\n | bs_andFalse : β bβ,\n BStep st (b_and b_false bβ) b_false\n | bs_andTrueStep : β bβ bβ',\n BStep st bβ bβ'\n β BStep st (b_and b_true bβ) (b_and b_true bβ')\n | bs_andTrueTrue :\n BStep st (b_and b_true b_true) b_true\n | bs_andTrueFalse :\n BStep st (b_and b_true b_false) b_false\n | bs_orStep : β bβ bβ' bβ,\n BStep st bβ bβ'\n β BStep st (b_or bβ bβ) (b_or bβ' bβ)\n | bs_orTrue : β bβ,\n BStep st (b_or b_true bβ) b_true\n | bs_orFalseStep : β bβ bβ',\n BStep st bβ bβ'\n β BStep st (b_or b_false bβ) (b_or b_false bβ')\n | bs_orFalseTrue :\n BStep st (b_or b_false b_true) b_true\n | bs_orFalseFalse :\n BStep st (b_or b_false b_false) b_false"
},
{
"name": "CStep",
"content": "inductive CStep : (Com Γ State) β (Com Γ State) β Prop :=\n | cs_asgnStep : β st v aβ aβ',\n AStep st aβ aβ'\n β CStep (c_asgn v aβ, st) (c_asgn v aβ', st)\n | cs_asgn : β st v (n : Nat),\n CStep (c_asgn v (a_num n), st) (c_skip, x !-> n; st)\n | cs_seqStep : β st cβ cβ' st' cβ,\n CStep (cβ, st) (cβ', st')\n β CStep (c_seq cβ cβ, st) (c_seq cβ' cβ, st')\n | cs_seqFinish : β st cβ,\n CStep (c_seq c_skip cβ, st) (cβ, st)\n | cs_ifStep : β st bβ bβ' cβ cβ,\n BStep st bβ bβ'\n β CStep (c_if bβ cβ cβ, st) (c_if bβ' cβ cβ, st)\n | cs_ifTrue : β st cβ cβ,\n CStep (c_if b_true cβ cβ, st) (cβ, st)\n | cs_ifFalse : β st cβ cβ,\n CStep (c_if b_false cβ cβ, st) (cβ, st)\n | cs_while : β st bβ cβ,\n CStep (c_while bβ cβ, st)\n (c_if bβ (c_seq cβ (c_while bβ cβ)) c_skip, st)"
},
{
"name": "CImp.Com",
"content": "inductive Com : Type :=\n | c_skip : Com\n | c_asgn : String β AExp β Com\n | c_seq : Com β Com β Com\n | c_if : BExp β Com β Com β Com\n | c_while : BExp β Com β Com\n | c_par : Com β Com β Com"
},
{
"name": "CImp.CStep",
"content": "inductive CStep : (Com Γ State) β (Com Γ State) β Prop :=\n \n | cs_asgnStep : β st v aβ aβ',\n AStep st aβ aβ'\n β CStep (c_asgn v aβ, st) (c_asgn v aβ', st)\n | cs_asgn : β st v (n : Nat),\n CStep (c_asgn v (a_num n), st) (c_skip, v !-> n; st)\n | cs_seqStep : β st cβ cβ' st' cβ,\n CStep (cβ, st) (cβ', st')\n β CStep (c_seq cβ cβ, st) (c_seq cβ' cβ, st')\n | cs_seqFinish : β st cβ,\n CStep (c_seq c_skip cβ, st) (cβ, st)\n | cs_ifStep : β st bβ bβ' cβ cβ,\n BStep st bβ bβ'\n β CStep (c_if bβ cβ cβ, st) (c_if bβ' cβ cβ, st)\n | cs_ifTrue : β st cβ cβ,\n CStep (c_if b_true cβ cβ, st) (cβ, st)\n | cs_ifFalse : β st cβ cβ,\n CStep (c_if b_false cβ cβ, st) (cβ, st)\n | cs_while : β st bβ cβ,\n CStep (c_while bβ cβ, st)\n (c_if bβ (c_seq cβ (c_while bβ cβ)) c_skip, st)\n \n | cs_par1 : β st cβ cβ' cβ st',\n CStep (cβ, st) (cβ', st')\n β CStep (c_par cβ cβ, st) (c_par cβ' cβ, st')\n | cs_par2 : β st cβ cβ cβ' st',\n CStep (cβ, st) (cβ', st')\n β CStep (c_par cβ cβ, st) (c_par cβ cβ', st')\n | cs_parDone : β st,\n CStep (c_par c_skip c_skip, st) (c_skip, st)"
},
{
"name": "CImp.par_loop",
"content": "def par_loop : Com :=\n c_par\n (c_asgn y (a_num 1))\n (c_while (b_eq (a_id y) (a_num 0))\n (c_asgn x (a_plus (a_id x) (a_num 1))))\n\n/-\nIn particular, it can terminate with `x` set to `0`.\n-/\n\nexample : β st',\n Multi CStep (par_loop, empty) (c_skip, st')\n β§ st' x = 0 :="
}
] | [
{
"name": "CImp.par_body_n__Sn",
"content": "theorem par_body_n__Sn n st\n : st x = n β§ st y = 0\n β Multi CStep (par_loop, st) (par_loop, x !-> n + 1; st)"
},
{
"name": "CImp.par_body_n",
"content": "theorem par_body_n n st\n : st x = 0 β§ st y = 0\n β β st', Multi CStep (par_loop, st) (par_loop, st')\n β§ st' x = n β§ st' y = 0"
}
] | import Frap.Equiv
import Frap.SmallStep
open Imp
open AExp
open BExp
open Com
open Multi
inductive AVal : AExp β Prop :=
| av_num : β n, AVal (a_num n)
inductive AStep (st : State) : AExp β AExp β Prop :=
| as_id : β v, AStep st (a_id v) (a_num (st v))
| as_plus1 : β aβ aβ' aβ,
AStep st aβ aβ'
β AStep st (a_plus aβ aβ) (a_plus aβ' aβ)
| as_plus2 : β vβ aβ aβ',
AVal vβ β AStep st aβ aβ'
β AStep st (a_plus vβ aβ) (a_plus vβ aβ')
| as_plus : β (vβ vβ : Nat),
AStep st (a_plus (a_num vβ) (a_num vβ)) (a_num (vβ + vβ))
| as_minus1 : β aβ aβ' aβ,
AStep st aβ aβ'
β AStep st (a_minus aβ aβ) (a_minus aβ' aβ)
| as_minus2 : β vβ aβ aβ',
AVal vβ β AStep st aβ aβ'
β AStep st (a_minus vβ aβ) (a_minus vβ aβ')
| as_minus : β (vβ vβ : Nat),
AStep st (a_minus (a_num vβ) (a_num vβ)) (a_num (vβ - vβ))
| as_mult1 : β aβ aβ' aβ,
AStep st aβ aβ'
β AStep st (a_mult aβ aβ) (a_mult aβ' aβ)
| as_mult2 : β vβ aβ aβ',
AVal vβ β AStep st aβ aβ'
β AStep st (a_mult vβ aβ) (a_mult vβ aβ')
| as_mult : β (vβ vβ : Nat),
AStep st (a_mult (a_num vβ) (a_num vβ)) (a_num (vβ * vβ))
open AStep
inductive BStep (st : State) : BExp β BExp β Prop :=
| bs_eq1 : β aβ aβ' aβ,
AStep st aβ aβ'
β BStep st (b_eq aβ aβ) (b_eq aβ' aβ)
| bs_eq2 : β vβ aβ aβ',
AVal vβ β AStep st aβ aβ'
β BStep st (b_eq vβ aβ) (b_eq vβ aβ')
| bs_eq : β (vβ vβ : Nat),
BStep st (b_eq (a_num vβ) (a_num vβ))
(if vβ == vβ then b_true else b_false)
| bs_neq1 : β aβ aβ' aβ,
AStep st aβ aβ'
β BStep st (b_neq aβ aβ) (b_neq aβ' aβ)
| bs_neq2 : β vβ aβ aβ',
AVal vβ β AStep st aβ aβ'
β BStep st (b_neq vβ aβ) (b_neq vβ aβ')
| bs_neq : β (vβ vβ : Nat),
BStep st (b_neq (a_num vβ) (a_num vβ))
(if vβ != vβ then b_true else b_false)
| bs_le1 : β aβ aβ' aβ,
AStep st aβ aβ'
β BStep st (b_le aβ aβ) (b_le aβ' aβ)
| bs_le2 : β vβ aβ aβ',
AVal vβ β AStep st aβ aβ'
β BStep st (b_le vβ aβ) (b_le vβ aβ')
| bs_le : β (vβ vβ : Nat),
BStep st (b_le (a_num vβ) (a_num vβ))
(if vβ <= vβ then b_true else b_false)
| bs_notStep : β bβ bβ',
BStep st bβ bβ'
β BStep st (b_not bβ) (b_not bβ')
| bs_notTrue : BStep st (b_not b_true) b_false
| bs_notFalse : BStep st (b_not b_false) b_true
| bs_andStep : β bβ bβ' bβ,
BStep st bβ bβ'
β BStep st (b_and bβ bβ) (b_and bβ' bβ)
| bs_andFalse : β bβ,
BStep st (b_and b_false bβ) b_false
| bs_andTrueStep : β bβ bβ',
BStep st bβ bβ'
β BStep st (b_and b_true bβ) (b_and b_true bβ')
| bs_andTrueTrue :
BStep st (b_and b_true b_true) b_true
| bs_andTrueFalse :
BStep st (b_and b_true b_false) b_false
| bs_orStep : β bβ bβ' bβ,
BStep st bβ bβ'
β BStep st (b_or bβ bβ) (b_or bβ' bβ)
| bs_orTrue : β bβ,
BStep st (b_or b_true bβ) b_true
| bs_orFalseStep : β bβ bβ',
BStep st bβ bβ'
β BStep st (b_or b_false bβ) (b_or b_false bβ')
| bs_orFalseTrue :
BStep st (b_or b_false b_true) b_true
| bs_orFalseFalse :
BStep st (b_or b_false b_false) b_false
open BStep
inductive CStep : (Com Γ State) β (Com Γ State) β Prop :=
| cs_asgnStep : β st v aβ aβ',
AStep st aβ aβ'
β CStep (c_asgn v aβ, st) (c_asgn v aβ', st)
| cs_asgn : β st v (n : Nat),
CStep (c_asgn v (a_num n), st) (c_skip, x !-> n; st)
| cs_seqStep : β st cβ cβ' st' cβ,
CStep (cβ, st) (cβ', st')
β CStep (c_seq cβ cβ, st) (c_seq cβ' cβ, st')
| cs_seqFinish : β st cβ,
CStep (c_seq c_skip cβ, st) (cβ, st)
| cs_ifStep : β st bβ bβ' cβ cβ,
BStep st bβ bβ'
β CStep (c_if bβ cβ cβ, st) (c_if bβ' cβ cβ, st)
| cs_ifTrue : β st cβ cβ,
CStep (c_if b_true cβ cβ, st) (cβ, st)
| cs_ifFalse : β st cβ cβ,
CStep (c_if b_false cβ cβ, st) (cβ, st)
| cs_while : β st bβ cβ,
CStep (c_while bβ cβ, st)
(c_if bβ (c_seq cβ (c_while bβ cβ)) c_skip, st)
namespace CImp
inductive Com : Type :=
| c_skip : Com
| c_asgn : String β AExp β Com
| c_seq : Com β Com β Com
| c_if : BExp β Com β Com β Com
| c_while : BExp β Com β Com
| c_par : Com β Com β Com
open Com
inductive CStep : (Com Γ State) β (Com Γ State) β Prop :=
| cs_asgnStep : β st v aβ aβ',
AStep st aβ aβ'
β CStep (c_asgn v aβ, st) (c_asgn v aβ', st)
| cs_asgn : β st v (n : Nat),
CStep (c_asgn v (a_num n), st) (c_skip, v !-> n; st)
| cs_seqStep : β st cβ cβ' st' cβ,
CStep (cβ, st) (cβ', st')
β CStep (c_seq cβ cβ, st) (c_seq cβ' cβ, st')
| cs_seqFinish : β st cβ,
CStep (c_seq c_skip cβ, st) (cβ, st)
| cs_ifStep : β st bβ bβ' cβ cβ,
BStep st bβ bβ'
β CStep (c_if bβ cβ cβ, st) (c_if bβ' cβ cβ, st)
| cs_ifTrue : β st cβ cβ,
CStep (c_if b_true cβ cβ, st) (cβ, st)
| cs_ifFalse : β st cβ cβ,
CStep (c_if b_false cβ cβ, st) (cβ, st)
| cs_while : β st bβ cβ,
CStep (c_while bβ cβ, st)
(c_if bβ (c_seq cβ (c_while bβ cβ)) c_skip, st)
| cs_par1 : β st cβ cβ' cβ st',
CStep (cβ, st) (cβ', st')
β CStep (c_par cβ cβ, st) (c_par cβ' cβ, st')
| cs_par2 : β st cβ cβ cβ' st',
CStep (cβ, st) (cβ', st')
β CStep (c_par cβ cβ, st) (c_par cβ cβ', st')
| cs_parDone : β st,
CStep (c_par c_skip c_skip, st) (c_skip, st)
open CStep
def par_loop : Com :=
c_par
(c_asgn y (a_num 1))
(c_while (b_eq (a_id y) (a_num 0))
(c_asgn x (a_plus (a_id x) (a_num 1))))
/-
In particular, it can terminate with `x` set to `0`.
-/
example : β st',
Multi CStep (par_loop, empty) (c_skip, st')
β§ st' x = 0 := | theorem par_loop_any_x n
: β st', Multi CStep (par_loop, empty) (c_skip, st')
β§ st' x = n := | := by
let h := par_body_n n empty
simp [empty] at h
obtain β¨st', β¨h', β¨hx, _β©β©β© := h
exists y !-> 1; st'
constructor
. apply multi_trans
. apply h'
. apply multi_step
. apply cs_par1; apply cs_asgn
. apply multi_step
. apply cs_par2; apply cs_while
. apply multi_step
. apply cs_par2; apply cs_ifStep
apply bs_eq1; apply as_id
. apply multi_step
. apply cs_par2; apply cs_ifStep
apply bs_eq
. simp [update]; apply multi_step
. apply cs_par2; apply cs_ifFalse
. apply multi_R
apply cs_parDone
. simp [update]; assumption | 3 | 27 | true | Semantics |
274 | Imp.fold_constants_bexp_sound | theorem fold_constants_bexp_sound : btrans_sound fold_constants_bexp | lean-formal-reasoning-program | Frap/Trans.lean | [
"import Frap.Exercises.Equiv",
"import Frap.Equiv"
] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "String",
"module": "Init.Prelude"
},
{
"name": "Bool",
"module": "Init.Prelude"
}
] | [
{
"name": "syntax \"<{\" imp \"}>\" : term",
"content": "syntax \"<{\" imp \"}>\" : term\n\nsyntax \"false\" : imp\n\nsyntax \"false\" : term\n\nsyntax:21 \"if\" imp:20 \"then\" imp:20 \"else\" imp:20 \"end\" : imp\n\nsyntax \"true\" : imp\n\nsyntax \"true\" : term"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(term|true) => `(Bool.true)\n | `(term|false) => `(Bool.false)\n | `(term|<{$x}>) => `(imp|$x)\n | `(imp|$n:num) => `(a_num $n)\n | `(imp|$s:str) => `(a_id $s)\n | `(imp|$x + $y) => `(a_plus <{$x}> <{$y}>)\n | `(imp|$x - $y) => `(a_minus <{$x}> <{$y}>)\n | `(imp|$x * $y) => `(a_mult <{$x}> <{$y}>)\n | `(imp|true) => `(b_true)\n | `(imp|false) => `(b_false)\n | `(imp|$x = $y) => `(b_eq <{$x}> <{$y}>)\n | `(imp|$x != $y) => `(b_neq <{$x}> <{$y}>)\n | `(imp|$x <= $y) => `(b_le <{$x}> <{$y}>)\n | `(imp|!$x) => `(b_not <{$x}>)\n | `(imp|$x && $y) => `(b_and <{$x}> <{$y}>)\n | `(imp|$x || $y) => `(b_or <{$x}> <{$y}>)\n | `(imp|($x)) => `(<{$x}>)\n | `(imp|$x:ident) => `(a_id $(Lean.quote (toString x.getId)))\n | `(imp|<[$t:term]>) => pure t"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(imp|skip) => `(c_skip)\n | `(imp|$x:str := $y) => `(c_asgn $x <{$y}>)\n | `(imp|$x:ident := $y) => `(c_asgn $x <{$y}>)\n | `(imp|$c1 ; $c2) => `(c_seq <{$c1}> <{$c2}>)\n | `(imp|if $b then $c1 else $c2 end) => `(c_if <{$b}> <{$c1}> <{$c2}>)\n | `(imp|while $b do $c end) => `(c_while <{$b}> <{$c}>)"
},
{
"name": "AExp",
"content": "inductive AExp where\n | a_num : Nat β AExp\n | a_id : String β AExp \n | a_plus : AExp β AExp β AExp\n | a_minus : AExp β AExp β AExp\n | a_mult : AExp β AExp β AExp"
},
{
"name": "AExp",
"content": "inductive AExp where\n | a_num : Nat β AExp\n | a_plus : AExp β AExp β AExp\n | a_minus : AExp β AExp β AExp\n | a_mult : AExp β AExp β AExp"
},
{
"name": "x",
"content": "abbrev x := \"x\""
},
{
"name": "y",
"content": "abbrev y := \"y\""
},
{
"name": "BExp",
"content": "inductive BExp where\n | b_true : BExp\n | b_false : BExp\n | b_eq : AExp β AExp β BExp\n | b_neq : AExp β AExp β BExp\n | b_le : AExp β AExp β BExp\n | b_not : BExp β BExp\n | b_and : BExp β BExp β BExp\n | b_or : BExp β BExp β BExp"
},
{
"name": "bequiv",
"content": "def bequiv (bβ bβ : BExp) : Prop :=\n β (st : State), beval st bβ = beval st bβ"
},
{
"name": "beval",
"content": "def beval (st : State) (b : BExp) : Bool :=\n match b with\n | b_true => true\n | b_false => false\n | b_eq aβ aβ => (aeval st aβ) == (aeval st aβ)\n | b_neq aβ aβ => (aeval st aβ) != (aeval st aβ)\n | b_le aβ aβ => (aeval st aβ) <= (aeval st aβ)\n | b_not bβ => not (beval st bβ)\n | b_and bβ bβ => and (beval st bβ) (beval st bβ)\n | b_or bβ bβ => or (beval st bβ) (beval st bβ)\n\nexample : aeval (update empty x 5)\n <{3 + x * 2}>\n \n = 13 := by admit /- proof elided -/"
},
{
"name": "empty",
"content": "def empty : State := fun _ => 0"
},
{
"name": "State",
"content": "abbrev State := String β Nat"
},
{
"name": "z",
"content": "abbrev z := \"z\""
},
{
"name": "aeval",
"content": "def aeval (st : State) (a : AExp) : Nat :=\n match a with\n | a_num n => n\n | a_id x => st x\n | a_plus aβ aβ => (aeval st aβ) + (aeval st aβ)\n | a_minus aβ aβ => (aeval st aβ) - (aeval st aβ)\n | a_mult aβ aβ => (aeval st aβ) * (aeval st aβ)"
},
{
"name": "update",
"content": "def update (st : State) (k : String) (v : Nat) : State :=\n fun x => if x == k then v else st x"
},
{
"name": "aequiv",
"content": "def aequiv (aβ aβ : AExp) : Prop :=\n β (st : State), aeval st aβ = aeval st 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": "Imp.atrans_sound",
"content": "def atrans_sound (atrans : AExp β AExp) :=\n β (a : AExp), aequiv a (atrans a)"
},
{
"name": "Imp.btrans_sound",
"content": "def btrans_sound (btrans : BExp β BExp) :=\n β (b : BExp), bequiv b (btrans b)"
},
{
"name": "Imp.fold_constants_aexp",
"content": "def fold_constants_aexp (a : AExp) : AExp :=\n match a with\n | a_num _\n | a_id _\n => a\n | a_plus a1 a2 =>\n match (fold_constants_aexp a1, fold_constants_aexp a2) with\n | (a_num n1, a_num n2) => a_num (n1 + n2)\n | (a1', a2') => a_plus a1' a2'\n | a_minus a1 a2 =>\n match (fold_constants_aexp a1, fold_constants_aexp a2) with\n | (a_num n1, a_num n2) => a_num (n1 - n2)\n | (a1', a2') => a_minus a1' a2'\n | a_mult a1 a2 =>\n match (fold_constants_aexp a1, fold_constants_aexp a2) with\n | (a_num n1, a_num n2) => a_num (n1 * n2)\n | (a1', a2') => a_mult a1' a2'\n\nexample : fold_constants_aexp <{(1 + 2) * x}> = <{3 * x}> := by admit /- proof elided -/"
},
{
"name": "Imp.fold_constants_bexp",
"content": "def fold_constants_bexp (b : BExp) : BExp :=\n match b with\n | b_true\n | b_false\n => b\n | b_eq a1 a2 =>\n match (fold_constants_aexp a1, fold_constants_aexp a2) with\n | (a_num n1, a_num n2) => if n1 == n2 then b_true else b_false\n | (a1', a2') => b_eq a1' a2'\n | b_neq a1 a2 =>\n match (fold_constants_aexp a1, fold_constants_aexp a2) with\n | (a_num n1, a_num n2) => if n1 != n2 then b_true else b_false\n | (a1', a2') => b_neq a1' a2'\n | b_le a1 a2 =>\n match (fold_constants_aexp a1, fold_constants_aexp a2) with\n | (a_num n1, a_num n2) => if n1 <= n2 then b_true else b_false\n | (a1', a2') => b_le a1' a2'\n | b_not b1 =>\n match fold_constants_bexp b1 with\n | b_true => b_false\n | b_false => b_true\n | b1' => b_not b1'\n | b_and b1 b2 =>\n match (fold_constants_bexp b1, fold_constants_bexp b2) with\n | (b_true, b_true) => b_true\n | (b_true, b_false) => b_false\n | (b_false, b_true) => b_false\n | (b_false, b_false) => b_false\n | (b1', b2') => b_and b1' b2'\n | b_or b1 b2 =>\n match (fold_constants_bexp b1, fold_constants_bexp b2) with\n | (b_true, b_true) => b_true\n | (b_true, b_false) => b_true\n | (b_false, b_true) => b_true\n | (b_false, b_false) => b_false\n | (b1', b2') => b_or b1' b2'\n\nexample : fold_constants_bexp <{true && !(false && true)}> = <{true}> := by admit /- proof elided -/"
}
] | [
{
"name": "Imp.fold_constants_aexp_sound",
"content": "theorem fold_constants_aexp_sound : atrans_sound fold_constants_aexp"
}
] | import Frap.Equiv
import Frap.Exercises.Equiv
namespace Imp
open AExp
open BExp
open Com
open CEval
def atrans_sound (atrans : AExp β AExp) :=
β (a : AExp), aequiv a (atrans a)
def btrans_sound (btrans : BExp β BExp) :=
β (b : BExp), bequiv b (btrans b)
def fold_constants_aexp (a : AExp) : AExp :=
match a with
| a_num _
| a_id _
=> a
| a_plus a1 a2 =>
match (fold_constants_aexp a1, fold_constants_aexp a2) with
| (a_num n1, a_num n2) => a_num (n1 + n2)
| (a1', a2') => a_plus a1' a2'
| a_minus a1 a2 =>
match (fold_constants_aexp a1, fold_constants_aexp a2) with
| (a_num n1, a_num n2) => a_num (n1 - n2)
| (a1', a2') => a_minus a1' a2'
| a_mult a1 a2 =>
match (fold_constants_aexp a1, fold_constants_aexp a2) with
| (a_num n1, a_num n2) => a_num (n1 * n2)
| (a1', a2') => a_mult a1' a2'
example : fold_constants_aexp <{(1 + 2) * x}> = <{3 * x}> := by admit /- proof elided -/
def fold_constants_bexp (b : BExp) : BExp :=
match b with
| b_true
| b_false
=> b
| b_eq a1 a2 =>
match (fold_constants_aexp a1, fold_constants_aexp a2) with
| (a_num n1, a_num n2) => if n1 == n2 then b_true else b_false
| (a1', a2') => b_eq a1' a2'
| b_neq a1 a2 =>
match (fold_constants_aexp a1, fold_constants_aexp a2) with
| (a_num n1, a_num n2) => if n1 != n2 then b_true else b_false
| (a1', a2') => b_neq a1' a2'
| b_le a1 a2 =>
match (fold_constants_aexp a1, fold_constants_aexp a2) with
| (a_num n1, a_num n2) => if n1 <= n2 then b_true else b_false
| (a1', a2') => b_le a1' a2'
| b_not b1 =>
match fold_constants_bexp b1 with
| b_true => b_false
| b_false => b_true
| b1' => b_not b1'
| b_and b1 b2 =>
match (fold_constants_bexp b1, fold_constants_bexp b2) with
| (b_true, b_true) => b_true
| (b_true, b_false) => b_false
| (b_false, b_true) => b_false
| (b_false, b_false) => b_false
| (b1', b2') => b_and b1' b2'
| b_or b1 b2 =>
match (fold_constants_bexp b1, fold_constants_bexp b2) with
| (b_true, b_true) => b_true
| (b_true, b_false) => b_true
| (b_false, b_true) => b_true
| (b_false, b_false) => b_false
| (b1', b2') => b_or b1' b2'
example : fold_constants_bexp <{true && !(false && true)}> = <{true}> := by admit /- proof elided -/ | theorem fold_constants_bexp_sound : btrans_sound fold_constants_bexp := | := by
intro b st; induction b with simp [fold_constants_bexp]
| b_eq a1 a2 =>
rw [fold_constants_aexp_sound a1, fold_constants_aexp_sound a2]
split
. rename_i hm
simp at hm
obtain β¨β© := hm
split <;> simp [*]
. rename_i hm
simp at hm
obtain β¨β© := hm
simp [*]
| b_neq a1 a2 =>
rw [fold_constants_aexp_sound a1, fold_constants_aexp_sound a2]
split
. rename_i hm
simp at hm
obtain β¨β© := hm
split <;> simp [*]
. rename_i hm
simp at hm
obtain β¨β© := hm
simp [*]
| b_le a1 a2 =>
rw [fold_constants_aexp_sound a1, fold_constants_aexp_sound a2]
split
. rename_i hm
simp at hm
obtain β¨β© := hm
split <;> simp [*]
. rename_i hm
simp at hm
obtain β¨β© := hm
simp [*]
| b_not =>
split <;> simp [*]
| b_and =>
simp [*]
split <;> (
rename_i hm
simp at hm
obtain β¨β© := hm
simp [*]
)
| b_or =>
simp [*]
split <;> (
rename_i hm
simp at hm
obtain β¨β© := hm
simp [*]
) | 5 | 21 | true | Semantics |
275 | step_normalizing | theorem step_normalizing : normalizing Step | lean-formal-reasoning-program | Frap/SmallStep.lean | [] | [
{
"name": "Nat",
"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": "Tm",
"content": "inductive Tm : Type :=\n | c : Nat β Tm \n | p : Tm β Tm β Tm"
},
{
"name": "SimpleArith1.Step",
"content": "inductive Step : Tm β Tm β Prop :=\n | st_plusConstConst nβ nβ : Step (p (c nβ) (c nβ)) (c (nβ + nβ))\n | st_plus1 tβ tβ' tβ : Step tβ tβ' β Step (p tβ tβ) (p tβ' tβ)\n | st_plus2 nβ tβ tβ' : Step tβ tβ' β Step (p (c nβ) tβ) (p (c nβ) tβ')"
},
{
"name": "relation",
"content": "def relation (X : Type) := X β X β Prop"
},
{
"name": "Value",
"content": "inductive Value : Tm β Prop :=\n | v_const n : Value (c n)"
},
{
"name": "Step",
"content": "inductive Step : Tm β Tm β Prop :=\n | st_plusConstConst nβ nβ : Step (p (c nβ) (c nβ)) (c (nβ + nβ))\n | st_plus1 tβ tβ' tβ : Step tβ tβ' β Step (p tβ tβ) (p tβ' tβ)\n | st_plus2 vβ tβ tβ' : Value vβ β Step tβ tβ' β Step (p vβ tβ) (p vβ tβ')"
},
{
"name": "normal_form",
"content": "def normal_form {X : Type} (R : relation X) (t : X) : Prop := Β¬βt', R t t'"
},
{
"name": "Multi",
"content": "inductive Multi {X : Type} (R : relation X) : relation X :=\n | multi_refl x : Multi R x x\n | multi_step x y z : R x y β Multi R y z β Multi R x z"
},
{
"name": "normalizing",
"content": "def normalizing {X : Type} (R : relation X) :=\n βt, βt', (Multi R) t t' β§ normal_form R t'"
}
] | [
{
"name": "strong_progress",
"content": "theorem strong_progress t : Value t β¨ βt', Step t t'"
},
{
"name": "value_is_nf",
"content": "theorem value_is_nf v : Value v β normal_form Step v"
},
{
"name": "nf_is_value",
"content": "theorem nf_is_value t : normal_form Step t β Value t"
},
{
"name": "nf_same_as_value",
"content": "theorem nf_same_as_value t : normal_form Step t β Value t"
},
{
"name": "multi_R",
"content": "theorem multi_R (X : Type) (R : relation X) x y : R x y β Multi R x y"
},
{
"name": "multi_trans",
"content": "theorem multi_trans (X : Type) (R : relation X) x y z\n : Multi R x y β Multi R y z β Multi R x z"
},
{
"name": "multistep_congr_1",
"content": "theorem multistep_congr_1 tβ tβ' tβ\n : (tβ ~~>* tβ') β (p tβ tβ ~~>* p tβ' tβ)"
},
{
"name": "multistep_congr_2",
"content": "theorem multistep_congr_2 vβ tβ tβ'\n : (tβ ~~>* tβ') β (p vβ tβ ~~>* p vβ tβ')"
}
] | inductive Tm : Type :=
| c : Nat β Tm
| p : Tm β Tm β Tm
open Tm
open Eval
namespace SimpleArith1
inductive Step : Tm β Tm β Prop :=
| st_plusConstConst nβ nβ : Step (p (c nβ) (c nβ)) (c (nβ + nβ))
| st_plus1 tβ tβ' tβ : Step tβ tβ' β Step (p tβ tβ) (p tβ' tβ)
| st_plus2 nβ tβ tβ' : Step tβ tβ' β Step (p (c nβ) tβ) (p (c nβ) tβ')
open Step
end SimpleArith1
def relation (X : Type) := X β X β Prop
namespace SimpleArith2
open SimpleArith1
end SimpleArith2
inductive Value : Tm β Prop :=
| v_const n : Value (c n)
open Value
inductive Step : Tm β Tm β Prop :=
| st_plusConstConst nβ nβ : Step (p (c nβ) (c nβ)) (c (nβ + nβ))
| st_plus1 tβ tβ' tβ : Step tβ tβ' β Step (p tβ tβ) (p tβ' tβ)
| st_plus2 vβ tβ tβ' : Value vβ β Step tβ tβ' β Step (p vβ tβ) (p vβ tβ')
open Step
def normal_form {X : Type} (R : relation X) (t : X) : Prop := Β¬βt', R t t'
inductive Multi {X : Type} (R : relation X) : relation X :=
| multi_refl x : Multi R x x
| multi_step x y z : R x y β Multi R y z β Multi R x z
open Multi
def normalizing {X : Type} (R : relation X) :=
βt, βt', (Multi R) t t' β§ normal_form R t' | theorem step_normalizing : normalizing Step := | := by
unfold normalizing
intro t
induction t with
| c n =>
exists c n
constructor
. apply multi_refl
. rw [nf_same_as_value]; apply v_const
| p tβ tβ ihβ ihβ =>
obtain β¨tβ', β¨hsβ, hnββ©β© := ihβ
obtain β¨tβ', β¨hsβ, hnββ©β© := ihβ
rw [nf_same_as_value] at hnβ
rw [nf_same_as_value] at hnβ
cases hnβ; cases hnβ
rename_i nβ nβ
exists c (nβ + nβ)
constructor
. apply multi_trans
. apply multistep_congr_1
apply hsβ
. apply multi_trans
. apply multistep_congr_2
apply hsβ
. apply multi_R
apply st_plusConstConst
. rw [nf_same_as_value]; apply v_const | 3 | 17 | true | Semantics |
276 | Imp.optimize_0plus_com_sound | theorem optimize_0plus_com_sound : ctrans_sound optimize_0plus_com | lean-formal-reasoning-program | Frap/Exercises/Trans.lean | [
"import Frap.Trans"
] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "String",
"module": "Init.Prelude"
},
{
"name": "Bool",
"module": "Init.Prelude"
}
] | [
{
"name": "syntax \"<{\" imp \"}>\" : term",
"content": "syntax \"<{\" imp \"}>\" : term\n\nsyntax:21 \"while\" imp:20 \"do\" imp:20 \"end\" : imp\n\nsyntax \"<[\" term \"]>\" : imp\n\nsyntax:21 \"if\" imp:20 \"then\" imp:20 \"else\" imp:20 \"end\" : imp\n\nsyntax \"false\" : imp\n\nsyntax \"false\" : term\n\nsyntax \"true\" : imp\n\nsyntax \"true\" : term"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(term|true) => `(Bool.true)\n | `(term|false) => `(Bool.false)\n | `(term|<{$x}>) => `(imp|$x)\n | `(imp|$n:num) => `(a_num $n)\n | `(imp|$s:str) => `(a_id $s)\n | `(imp|$x + $y) => `(a_plus <{$x}> <{$y}>)\n | `(imp|$x - $y) => `(a_minus <{$x}> <{$y}>)\n | `(imp|$x * $y) => `(a_mult <{$x}> <{$y}>)\n | `(imp|true) => `(b_true)\n | `(imp|false) => `(b_false)\n | `(imp|$x = $y) => `(b_eq <{$x}> <{$y}>)\n | `(imp|$x != $y) => `(b_neq <{$x}> <{$y}>)\n | `(imp|$x <= $y) => `(b_le <{$x}> <{$y}>)\n | `(imp|!$x) => `(b_not <{$x}>)\n | `(imp|$x && $y) => `(b_and <{$x}> <{$y}>)\n | `(imp|$x || $y) => `(b_or <{$x}> <{$y}>)\n | `(imp|($x)) => `(<{$x}>)\n | `(imp|$x:ident) => `(a_id $(Lean.quote (toString x.getId)))\n | `(imp|<[$t:term]>) => pure t"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(imp|skip) => `(c_skip)\n | `(imp|$x:str := $y) => `(c_asgn $x <{$y}>)\n | `(imp|$x:ident := $y) => `(c_asgn $x <{$y}>)\n | `(imp|$c1 ; $c2) => `(c_seq <{$c1}> <{$c2}>)\n | `(imp|if $b then $c1 else $c2 end) => `(c_if <{$b}> <{$c1}> <{$c2}>)\n | `(imp|while $b do $c end) => `(c_while <{$b}> <{$c}>)"
},
{
"name": "AExp",
"content": "inductive AExp where\n | a_num : Nat β AExp\n | a_id : String β AExp \n | a_plus : AExp β AExp β AExp\n | a_minus : AExp β AExp β AExp\n | a_mult : AExp β AExp β AExp"
},
{
"name": "AExp",
"content": "inductive AExp where\n | a_num : Nat β AExp\n | a_plus : AExp β AExp β AExp\n | a_minus : AExp β AExp β AExp\n | a_mult : AExp β AExp β AExp"
},
{
"name": "BExp",
"content": "inductive BExp where\n | b_true : BExp\n | b_false : BExp\n | b_eq : AExp β AExp β BExp\n | b_neq : AExp β AExp β BExp\n | b_le : AExp β AExp β BExp\n | b_not : BExp β BExp\n | b_and : BExp β BExp β BExp\n | b_or : BExp β BExp β BExp"
},
{
"name": "Com",
"content": "inductive Com :=\n | c_skip : Com\n | c_asgn : String β AExp β Com\n | c_seq : Com β Com β Com\n | c_if : BExp β Com β Com β Com\n | c_while : BExp β Com β Com"
},
{
"name": "Com",
"content": "inductive Com : Type :=\n | c_skip : Com\n | c_asgn : String β AExp β Com\n | c_seq : Com β Com β Com\n | c_if : BExp β Com β Com β Com\n | c_while : BExp β Com β Com\n | c_par : Com β Com β Com "
},
{
"name": "ctrans_sound",
"content": "def ctrans_sound (ctrans : Com β Com) :=\n β (c : Com), cequiv c (ctrans c)"
},
{
"name": "cequiv",
"content": "def cequiv (cβ cβ : Com) : Prop :=\n β st st' : State, (st =[<[cβ]>]=> st') β (st =[<[cβ]>]=> st')"
},
{
"name": "State",
"content": "abbrev State := String β Nat"
},
{
"name": "btrans_sound",
"content": "def btrans_sound (btrans : BExp β BExp) :=\n β (b : BExp), bequiv b (btrans b)"
},
{
"name": "bequiv",
"content": "def bequiv (bβ bβ : BExp) : Prop :=\n β (st : State), beval st bβ = beval st bβ"
},
{
"name": "beval",
"content": "def beval (st : State) (b : BExp) : Bool :=\n match b with\n | b_true => true\n | b_false => false\n | b_eq aβ aβ => (aeval st aβ) == (aeval st aβ)\n | b_neq aβ aβ => (aeval st aβ) != (aeval st aβ)\n | b_le aβ aβ => (aeval st aβ) <= (aeval st aβ)\n | b_not bβ => not (beval st bβ)\n | b_and bβ bβ => and (beval st bβ) (beval st bβ)\n | b_or bβ bβ => or (beval st bβ) (beval st bβ)\n\nexample : aeval (update empty x 5)\n <{3 + x * 2}>\n \n = 13 := by admit /- proof elided -/"
},
{
"name": "empty",
"content": "def empty : State := fun _ => 0"
},
{
"name": "y",
"content": "abbrev y := \"y\""
},
{
"name": "x",
"content": "abbrev x := \"x\""
},
{
"name": "z",
"content": "abbrev z := \"z\""
},
{
"name": "aeval",
"content": "def aeval (st : State) (a : AExp) : Nat :=\n match a with\n | a_num n => n\n | a_id x => st x\n | a_plus aβ aβ => (aeval st aβ) + (aeval st aβ)\n | a_minus aβ aβ => (aeval st aβ) - (aeval st aβ)\n | a_mult aβ aβ => (aeval st aβ) * (aeval st aβ)"
},
{
"name": "update",
"content": "def update (st : State) (k : String) (v : Nat) : State :=\n fun x => if x == k then v else st x"
},
{
"name": "atrans_sound",
"content": "def atrans_sound (atrans : AExp β AExp) :=\n β (a : AExp), aequiv a (atrans a)"
},
{
"name": "aequiv",
"content": "def aequiv (aβ aβ : AExp) : Prop :=\n β (st : State), aeval st aβ = aeval st aβ"
},
{
"name": "CEval",
"content": "inductive CEval : Com β State β State β Prop :=\n | e_skip : β st,\n CEval c_skip st st\n | e_asgn : β a n x st,\n aeval st a = n\n β CEval (c_asgn x a) st (update st x n)\n | e_seq : β cβ cβ st st' st'',\n CEval cβ st st' β CEval cβ st' st''\n β CEval (c_seq cβ cβ) st st''\n | e_ifTrue : β b cβ cβ st st',\n beval st b = true β CEval cβ st st'\n β CEval (c_if b cβ cβ) st st'\n | e_ifFalse : β b cβ cβ st st',\n beval st b = false β CEval cβ st st'\n β CEval (c_if b cβ cβ) st st'\n | e_whileFalse : β b c st,\n beval st b = false\n β CEval (c_while b c) st st\n | e_whileTrue : β b c st st' st'',\n beval st b = true\n β CEval c st st'\n β CEval (c_while b c) st' st''\n β CEval (c_while b c) st st''"
}
] | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "c_while_congruence",
"content": "theorem c_while_congruence b b' c c'\n : bequiv b b' β cequiv c c'\n β cequiv <{while <[b]> do <[c]> end}> <{while <[b']> do <[c']> end}>"
},
{
"name": "sym_bequiv",
"content": "theorem sym_bequiv bβ bβ : bequiv bβ bβ β bequiv bβ bβ"
},
{
"name": "sym_cequiv",
"content": "theorem sym_cequiv cβ cβ : cequiv cβ cβ β cequiv cβ cβ"
},
{
"name": "c_if_congruence",
"content": "theorem c_if_congruence b b' cβ cβ' cβ cβ'\n : bequiv b b' β cequiv cβ cβ' β cequiv cβ cβ'\n β cequiv (c_if b cβ cβ) (c_if b' cβ' cβ')"
},
{
"name": "c_asgn_congruence",
"content": "theorem c_asgn_congruence x a a'\n : aequiv a a' β cequiv <{x := <[a]>}> <{x := <[a']>}>"
},
{
"name": "c_seq_congruence",
"content": "theorem c_seq_congruence cβ cβ' cβ cβ'\n : cequiv cβ cβ' β cequiv cβ cβ' β cequiv (c_seq cβ cβ) (c_seq cβ' cβ')"
},
{
"name": "refl_cequiv",
"content": "theorem refl_cequiv c : cequiv c c"
}
] | [
{
"name": "Imp.optimize_0plus_aexp",
"content": "def optimize_0plus_aexp (a : AExp) : AExp :=\n match a with\n | a_num _ => a\n | a_id _ => a\n | a_plus (a_num 0) aβ => optimize_0plus_aexp aβ\n | a_plus aβ aβ => a_plus (optimize_0plus_aexp aβ) (optimize_0plus_aexp aβ)\n | a_minus aβ aβ => a_minus (optimize_0plus_aexp aβ) (optimize_0plus_aexp aβ)\n | a_mult aβ aβ => a_mult (optimize_0plus_aexp aβ) (optimize_0plus_aexp aβ)"
},
{
"name": "Imp.optimize_0plus_bexp",
"content": "def optimize_0plus_bexp (b : BExp) : BExp :=\n match b with\n | b_true => b_true\n | b_false => b_false\n | b_eq aβ aβ => b_eq (optimize_0plus_aexp aβ) (optimize_0plus_aexp aβ)\n | b_neq aβ aβ => b_neq (optimize_0plus_aexp aβ) (optimize_0plus_aexp aβ)\n | b_le aβ aβ => b_le (optimize_0plus_aexp aβ) (optimize_0plus_aexp aβ)\n | b_not bβ => b_not (optimize_0plus_bexp bβ)\n | b_and bβ bβ => b_and (optimize_0plus_bexp bβ) (optimize_0plus_bexp bβ)\n | b_or bβ bβ => b_or (optimize_0plus_bexp bβ) (optimize_0plus_bexp bβ)"
},
{
"name": "Imp.optimize_0plus_com",
"content": "def optimize_0plus_com (c : Com) : Com :=\n match c with\n | c_skip => c_skip\n | c_asgn x a => c_asgn x (optimize_0plus_aexp a)\n | c_seq cβ cβ => c_seq (optimize_0plus_com cβ) (optimize_0plus_com cβ)\n | c_if b cβ cβ => c_if (optimize_0plus_bexp b) (optimize_0plus_com cβ) (optimize_0plus_com cβ)\n | c_while b c => c_while (optimize_0plus_bexp b) (optimize_0plus_com c)\n\n \n\nexample :\n optimize_0plus_com <{ while x != 0 do x := 0 + x - 1 end }>\n = <{ while x != 0 do x := x - 1 end }> := by admit /- proof elided -/"
}
] | [
{
"name": "Imp.optimize_0plus_aexp_sound",
"content": "theorem optimize_0plus_aexp_sound : atrans_sound optimize_0plus_aexp"
},
{
"name": "Imp.optimize_0plus_bexp_sound",
"content": "theorem optimize_0plus_bexp_sound : btrans_sound optimize_0plus_bexp"
}
] | import Frap.Trans
namespace Hidden.AExp
open AExp
end Hidden.AExp
namespace Imp
open AExp
open BExp
open Com
open CEval
def optimize_0plus_aexp (a : AExp) : AExp :=
match a with
| a_num _ => a
| a_id _ => a
| a_plus (a_num 0) aβ => optimize_0plus_aexp aβ
| a_plus aβ aβ => a_plus (optimize_0plus_aexp aβ) (optimize_0plus_aexp aβ)
| a_minus aβ aβ => a_minus (optimize_0plus_aexp aβ) (optimize_0plus_aexp aβ)
| a_mult aβ aβ => a_mult (optimize_0plus_aexp aβ) (optimize_0plus_aexp aβ)
def optimize_0plus_bexp (b : BExp) : BExp :=
match b with
| b_true => b_true
| b_false => b_false
| b_eq aβ aβ => b_eq (optimize_0plus_aexp aβ) (optimize_0plus_aexp aβ)
| b_neq aβ aβ => b_neq (optimize_0plus_aexp aβ) (optimize_0plus_aexp aβ)
| b_le aβ aβ => b_le (optimize_0plus_aexp aβ) (optimize_0plus_aexp aβ)
| b_not bβ => b_not (optimize_0plus_bexp bβ)
| b_and bβ bβ => b_and (optimize_0plus_bexp bβ) (optimize_0plus_bexp bβ)
| b_or bβ bβ => b_or (optimize_0plus_bexp bβ) (optimize_0plus_bexp bβ)
def optimize_0plus_com (c : Com) : Com :=
match c with
| c_skip => c_skip
| c_asgn x a => c_asgn x (optimize_0plus_aexp a)
| c_seq cβ cβ => c_seq (optimize_0plus_com cβ) (optimize_0plus_com cβ)
| c_if b cβ cβ => c_if (optimize_0plus_bexp b) (optimize_0plus_com cβ) (optimize_0plus_com cβ)
| c_while b c => c_while (optimize_0plus_bexp b) (optimize_0plus_com c)
example :
optimize_0plus_com <{ while x != 0 do x := 0 + x - 1 end }>
= <{ while x != 0 do x := x - 1 end }> := by admit /- proof elided -/ | theorem optimize_0plus_com_sound : ctrans_sound optimize_0plus_com := | := by
intros c
induction c with simp [*] at *
| c_skip => apply refl_cequiv
| c_asgn => apply c_asgn_congruence; apply optimize_0plus_aexp_sound
| c_seq =>
apply c_seq_congruence
. assumption
. assumption
| c_if =>
apply c_if_congruence
. apply optimize_0plus_bexp_sound
. assumption
. assumption
| c_while =>
apply c_while_congruence
. apply optimize_0plus_bexp_sound
. assumption | 6 | 35 | false | Semantics |
277 | Tree.balance_BST | theorem balance_BST {Ξ± : Type u} c (l : Tree Ξ±) k vk (r : Tree Ξ±)
: ForallTree (fun x _ => x < k) l
-> ForallTree (fun x _ => x > k) r
-> BST l
-> BST r
-> BST (balance c l k vk r) | lean-formal-reasoning-program | Frap/RedBlack.lean | [] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "String",
"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": "Color",
"content": "inductive Color where\n | red\n | black"
},
{
"name": "Tree",
"content": "inductive Tree (Ξ± : Type u) where\n | empty : Tree Ξ±\n | tree (c: Color) (l : Tree Ξ±) (k : Nat) (v : Ξ±) (r : Tree Ξ±) : Tree Ξ±"
},
{
"name": "Tree.ex_tree",
"content": "def ex_tree : Tree String :=\n tree black (tree red empty 2 \"two\" empty) 4 \"four\" (tree red empty 5 \"five\" empty)"
},
{
"name": "Tree.balance",
"content": "def balance {Ξ± : Type u} (c : Color) (l : Tree Ξ±) (k : Nat) (vk : Ξ±) (r : Tree Ξ±) : Tree Ξ± :=\n match c with\n | red => tree red l k vk r\n | black =>\n match (l, k, vk, r) with\n | (tree red (tree red a x vx b) y vy c, z, vz, d)\n | (tree red a x vx (tree red b y vy c), z, vz, d)\n | (a, x, vx, tree red (tree red b y vy c) z vz d)\n | (a, x, vx, tree red b y vy (tree red c z vz d))\n => tree red (tree black a x vx b) y vy (tree black c z vz d)\n | _ => tree black l k vk r"
},
{
"name": "Tree.ForallTree",
"content": "inductive ForallTree {Ξ± : Type u} (p : Nat β Ξ± β Prop) : Tree Ξ± β Prop where\n | empty : ForallTree p empty\n | tree : β c l k v r,\n p k v β ForallTree p l β ForallTree p r\n β ForallTree p (tree c l k v r)"
},
{
"name": "Tree.BST",
"content": "inductive BST {Ξ± : Type u} : Tree Ξ± β Prop where\n | empty : BST empty\n | tree : β c l k v r,\n ForallTree (fun x _ => x < k) l\n β ForallTree (fun x _ => x > k) r\n β BST l\n β BST r\n β BST (tree c l k v r)\n\n \n\nexample : BST ex_tree := by admit /- proof elided -/"
}
] | [
{
"name": "Tree.forallTree_imp",
"content": "theorem forallTree_imp {Ξ± : Type u} (P Q : Nat β Ξ± β Prop) t\n : ForallTree P t β (β k v, P k v β Q k v) β ForallTree Q t"
},
{
"name": "Tree.forallTree_lt",
"content": "theorem forallTree_lt {Ξ± : Type u} (t : Tree Ξ±) k k'\n : ForallTree (fun x _ => x < k) t β k < k'\n β ForallTree (fun x _ => x < k') t"
},
{
"name": "Tree.forallTree_gt",
"content": "theorem forallTree_gt {Ξ± : Type u} (t : Tree Ξ±) k k'\n : ForallTree (fun x _ => x > k) t β k > k'\n β ForallTree (fun x _ => x > k') t"
}
] | inductive Color where
| red
| black
inductive Tree (Ξ± : Type u) where
| empty : Tree Ξ±
| tree (c: Color) (l : Tree Ξ±) (k : Nat) (v : Ξ±) (r : Tree Ξ±) : Tree Ξ±
namespace Tree
open Color
def ex_tree : Tree String :=
tree black (tree red empty 2 "two" empty) 4 "four" (tree red empty 5 "five" empty)
def balance {Ξ± : Type u} (c : Color) (l : Tree Ξ±) (k : Nat) (vk : Ξ±) (r : Tree Ξ±) : Tree Ξ± :=
match c with
| red => tree red l k vk r
| black =>
match (l, k, vk, r) with
| (tree red (tree red a x vx b) y vy c, z, vz, d)
| (tree red a x vx (tree red b y vy c), z, vz, d)
| (a, x, vx, tree red (tree red b y vy c) z vz d)
| (a, x, vx, tree red b y vy (tree red c z vz d))
=> tree red (tree black a x vx b) y vy (tree black c z vz d)
| _ => tree black l k vk r
inductive ForallTree {Ξ± : Type u} (p : Nat β Ξ± β Prop) : Tree Ξ± β Prop where
| empty : ForallTree p empty
| tree : β c l k v r,
p k v β ForallTree p l β ForallTree p r
β ForallTree p (tree c l k v r)
inductive BST {Ξ± : Type u} : Tree Ξ± β Prop where
| empty : BST empty
| tree : β c l k v r,
ForallTree (fun x _ => x < k) l
β ForallTree (fun x _ => x > k) r
β BST l
β BST r
β BST (tree c l k v r)
example : BST ex_tree := by admit /- proof elided -/ | theorem balance_BST {Ξ± : Type u} c (l : Tree Ξ±) k vk (r : Tree Ξ±)
: ForallTree (fun x _ => x < k) l
-> ForallTree (fun x _ => x > k) r
-> BST l
-> BST r
-> BST (balance c l k vk r) := | := by
intro hlk hkr hbl hbr; simp
split
. constructor <;> assumption
. split
. -- we are in the case where `x` is left child of `y`
cases l <;> repeat simp [*] at *
rcases hbl with β¨β© | β¨_, _, _, _, _, hxy, hyc, hbx, hbcβ©
rcases hlk with β¨β© | β¨_, _, _, _, _, hyz, hxz, hzcβ©
rcases hbx with β¨β© | β¨_, _, _, _, _, hax, hxb, hba, hbbβ©
rcases hxy with β¨β© | β¨_, _, _, _, _, hxy, hay, hbyβ©
rcases hxz with β¨β© | β¨_, _, _, _, _, haz, hxz, hbzβ©
/-
Here, we have destructed all the assumptions to the atomic level.
The goal remains to show that the resulting tree is a BST.
We apply the constructor tactic repeatedly.
Most of the resulting subgoals are trivial by assumption.
-/
(repeat' constructor) <;> try assumption
/-
The only interesting subgoal is to show that each node in the right subtree of the original root is greater than the left child of the original root.
This should follow from assumptions, although not trivially.
To facilitate reasoning at this point, we prove lemmas `forallTree_imp`, `forallTree_lt`, and `forallTree_gt` above.
-/
apply forallTree_gt <;> assumption
. -- we are in the case where `y` is right child of `x`
cases l <;> repeat simp [*] at *
rcases hbl with β¨β© | β¨_, _, _, _, _, hax, hxy, hba, hbyβ©
rcases hlk with β¨β© | β¨_, _, _, _, _, hxz, haz, hyzβ©
rcases hby with β¨β© | β¨_, _, _, _, _, hby, hyc, hbb, hbcβ©
rcases hxy with β¨β© | β¨_, _, _, _, _, hxy, hxb, hxcβ©
rcases hyz with β¨β© | β¨_, _, _, _, _, hyz, hbz, hczβ©
(repeat' constructor) <;> try assumption
. apply forallTree_lt
. exact hax
. assumption
. apply forallTree_gt <;> assumption
. -- we are in the case where `y` is left child of `z`
cases r <;> repeat simp [*] at *
rcases hbr with β¨β© | β¨_, _, _, _, _, hyz, hzd, hby, hbdβ©
rcases hkr with β¨β© | β¨_, _, _, _, _, hxz, hxy, hxdβ©
rcases hby with β¨β© | β¨_, _, _, _, _, hby, hyc, hbb, hbcβ©
rcases hxy with β¨β© | β¨_, _, _, _, _, hxy, hxb, hxcβ©
rcases hyz with β¨β© | β¨_, _, _, _, _, hyz, hbz, hczβ©
(repeat' constructor) <;> try assumption
. apply forallTree_lt <;> assumption
. apply forallTree_gt
. exact hzd
. assumption
. -- we are in the case where `z` is right child of `y`
cases r <;> repeat simp [*] at *
rcases hbr with β¨β© | β¨_, _, _, _, _, hby, hyz, hbb, hbzβ©
rcases hkr with β¨β© | β¨_, _, _, _, _, hxy, hxb, hxzβ©
rcases hbz with β¨β© | β¨_, _, _, _, _, hcz, hzd, hbc, hbdβ©
rcases hxz with β¨β© | β¨_, _, _, _, _, hxz, hxc, hxdβ©
rcases hyz with β¨β© | β¨_, _, _, _, _, hyz, hyc, hydβ©
(repeat' constructor) <;> try assumption
apply forallTree_lt <;> assumption
. constructor <;> assumption | 2 | 11 | true | Semantics |
278 | permutation_app_comm | theorem permutation_app_comm (l l' : List Ξ±)
: Permutation (l ++ l') (l' ++ l) | lean-formal-reasoning-program | Frap/Sort.lean | [] | [
{
"name": "List",
"module": "Init.Prelude"
}
] | [
{
"name": "...",
"content": "..."
}
] | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "append_assoc",
"content": "theorem append_assoc (as bs cs : List Ξ±)\n : (as ++ bs) ++ cs = as ++ (bs ++ cs)"
}
] | [
{
"name": "Permutation",
"content": "inductive Permutation {Ξ± : Type} : List Ξ± β List Ξ± β Prop :=\n | perm_nil : Permutation [] []\n | perm_skip x l l'\n : Permutation l l' β Permutation (x::l) (x::l')\n | perm_swap x y l : Permutation (y::x::l) (x::y::l)\n | perm_trans l l' l''\n : Permutation l l' β Permutation l' l''\n β Permutation l l''"
}
] | [
{
"name": "permutation_refl",
"content": "theorem permutation_refl (l : List Ξ±) : Permutation l l"
},
{
"name": "permutation_symm",
"content": "theorem permutation_symm (l l' : List Ξ±)\n : Permutation l l' β Permutation l' l"
},
{
"name": "permutation_app_tail",
"content": "theorem permutation_app_tail (l l' tl : List Ξ±)\n : Permutation l l' β Permutation (l++tl) (l'++tl)"
},
{
"name": "permutation_app_head",
"content": "theorem permutation_app_head (l tl tl' : List Ξ±)\n : Permutation tl tl' β Permutation (l++tl) (l++tl')"
},
{
"name": "permutation_cons_append",
"content": "theorem permutation_cons_append (l : List Ξ±) x\n : Permutation (x :: l) (l ++ [x])"
}
] | inductive Permutation {Ξ± : Type} : List Ξ± β List Ξ± β Prop :=
| perm_nil : Permutation [] []
| perm_skip x l l'
: Permutation l l' β Permutation (x::l) (x::l')
| perm_swap x y l : Permutation (y::x::l) (x::y::l)
| perm_trans l l' l''
: Permutation l l' β Permutation l' l''
β Permutation l l''
open Permutation | theorem permutation_app_comm (l l' : List Ξ±)
: Permutation (l ++ l') (l' ++ l) := | := by
induction l with simp
| nil => apply permutation_refl
| cons a al ih =>
-- a :: (al ++ l')
-- al ++ l' ++ [a]
-- l' ++ al ++ [a]
-- l' ++ (al ++ [a])
-- l' ++ a :: al
apply perm_trans
. apply permutation_cons_append
. apply perm_trans
. apply permutation_app_tail; exact ih
. rw [List.append_assoc]
apply permutation_app_head
apply permutation_symm
apply permutation_cons_append | 2 | 8 | false | Semantics |
279 | Hidden.Nat.add_comm | theorem add_comm (m n : Nat) : m + n = n + m | lean-formal-reasoning-program | Frap/Inductive.lean | [] | [
{
"name": "structure BitVec (w : Nat) where",
"module": ""
},
{
"name": "/-- Construct a `BitVec w` from a number less than `2^w`.",
"module": ""
},
{
"name": "O(1), because we use `Fin` as the internal representation of a bitvector. -/",
"module": ""
},
{
"name": "ofFin ::",
"module": ""
},
{
"name": "/-- Interpret a bitvector as a number less than `2^w`.",
"module": ""
},
{
"name": "O(1), because we use `Fin` as the internal representation of a bitvector. -/",
"module": ""
},
{
"name": "toFin : Fin (hPow 2 w)",
"module": ""
}
] | [
{
"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": "Hidden.Nat",
"content": "inductive Nat where\n | zero : Nat\n | succ : Nat β Nat"
}
] | [
{
"name": "Hidden.Nat.add_zero",
"content": "theorem add_zero (m : Nat) : m + zero = m"
},
{
"name": "Hidden.Nat.add_succ",
"content": "theorem add_succ (m n : Nat) : m + succ n = succ (m + n)"
},
{
"name": "Hidden.Nat.zero_add",
"content": "theorem zero_add (n : Nat) : zero + n = n"
},
{
"name": "Hidden.Nat.succ_add",
"content": "theorem succ_add (m n : Nat) : succ (m + n) = succ m + n"
}
] | section rewriting
variable (Ξ± : Type) (a b c d : Ξ±) -- a, b, c, d are elements of some type
/-
## Rewriting
Recall our equality proof from last time.
-/
example : a = b β c = b β c = d β a = d := by
intro hab hcb hcd
apply Eq.trans
. exact hab
. apply Eq.trans
. apply Eq.symm
exact hcb
. exact hcd
/-
Notice that in each subgoal, we are attempting to use a hypothesis by way of an equality property.
For example, we invoke the transitive property on `a = d` so that we can use the assumption `a = b` and be left with `b = d` to prove.
In effect, we are substituting `b` for `a` in the goal.
This substitution operation can be seen as rewriting some term in the goal with another, via an equality in the hypothesis.
This rewriting operation is so common that Lean provides a `rw` tactic to do so.
It replaces equals for equals, which could be an equality (`=`) or equivalence (`β`).
Be default, it rewrites the left-hand side with the right-hand side.
For right-to-left rewriting, a left arrow needs to be indicated before the hypothesis (`β`, typed with `\<-` shortcut) .
-/
example : a = b β c = b β c = d β a = d := by
intro hab hcb hcd
rw [hab]
rw [β hcd]
rw [hcb]
end rewriting
/-
## reflexivity tactic
One of the most powerful tactics is the _reflexivity_ tactic, written `rfl` in Lean.
It will attempt to conclude that both sides of an equality goal is indeed equal, up to some trivial computation, such as expansion of definitions and function applications.
-/
example : 2 + 5 = 7 := by
rfl
example : Β¬ Even = 3 := by
intro h
sorry
namespace Hidden
inductive Nat where
| zero : Nat
| succ : Nat β Nat
namespace Nat
end Nat
end Hidden
section opendemo
open Nat
end opendemo
namespace Hidden
namespace Nat
end Nat
end Hidden
namespace Hidden
namespace Nat | theorem add_comm (m n : Nat) : m + n = n + m := | := by
induction n with
| zero =>
rw [add_zero]
rw [zero_add]
| succ n' ih =>
rw [add_succ]
rw [ih]
rw [succ_add]
/-
Alternatively, if the supporting fact is only useful within a single theorem, we can embed the proof within, using the
-/
example (m n : Nat) : m + n = n + m := by
induction n with
| zero =>
rw [add_zero]
rw [zero_add]
| succ n' ih =>
rw [add_succ]
rw [ih]
have h (m n : Nat) : succ (m + n) = succ m + n := by
induction n with
| zero =>
rw [add_zero]
rw [add_zero]
| succ n' ih =>
rw [add_succ]
rw [add_succ]
rw [ih]
rw [h] | 1 | 5 | false | Semantics |
280 | Hidden.List.Palindrome.Palindrome_rev | theorem Palindrome_rev {Ξ± : Type} (l : List Ξ±)
: Palindrome l β l = reverse l | lean-formal-reasoning-program | Frap/Exercises/IndProp.lean | [] | [
{
"name": "structure BitVec (w : Nat) where",
"module": ""
},
{
"name": "/-- Construct a `BitVec w` from a number less than `2^w`.",
"module": ""
},
{
"name": "O(1), because we use `Fin` as the internal representation of a bitvector. -/",
"module": ""
},
{
"name": "ofFin ::",
"module": ""
},
{
"name": "/-- Interpret a bitvector as a number less than `2^w`.",
"module": ""
},
{
"name": "O(1), because we use `Fin` as the internal representation of a bitvector. -/",
"module": ""
},
{
"name": "toFin : Fin (hPow 2 w)",
"module": ""
}
] | [
{
"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": "Hidden.List",
"content": "inductive List (Ξ± : Type u) where\n | nil : List Ξ±\n | cons : Ξ± β List Ξ± β List Ξ±"
},
{
"name": "Hidden.List.reverse",
"content": "def reverse {Ξ± : Type u} (as : List Ξ±) : List Ξ± :=\n match as with\n | nil => nil\n | cons a as' => reverse as' ++ cons a nil"
},
{
"name": "Hidden.List.Palindrome",
"content": "inductive Palindrome {Ξ± : Type} : List Ξ± β Prop where\n | nil : Palindrome nil\n | single (x : Ξ±) : Palindrome (cons x nil)\n | sandwich (x : Ξ±) (xs : List Ξ±)\n : Palindrome xs β Palindrome (cons x xs ++ cons x nil)"
}
] | [
{
"name": "Hidden.List.nil_append",
"content": "theorem nil_append (as : List Ξ±) : nil ++ as = as"
},
{
"name": "Hidden.List.cons_append",
"content": "theorem cons_append (a : Ξ±) (as bs : List Ξ±)\n : (cons a as) ++ bs = cons a (as ++ bs)"
},
{
"name": "Hidden.List.append_nil",
"content": "theorem append_nil (as : List Ξ±) : as ++ nil = as"
},
{
"name": "Hidden.List.append_assoc",
"content": "theorem append_assoc (as bs cs : List Ξ±)\n : (as ++ bs) ++ cs = as ++ (bs ++ cs)"
},
{
"name": "Hidden.List.reverse_append",
"content": "theorem reverse_append {Ξ± : Type u} (as bs : List Ξ±)\n : reverse (as ++ bs) = reverse bs ++ reverse as"
}
] | namespace Hidden
inductive List (Ξ± : Type u) where
| nil : List Ξ±
| cons : Ξ± β List Ξ± β List Ξ±
namespace List
def reverse {Ξ± : Type u} (as : List Ξ±) : List Ξ± :=
match as with
| nil => nil
| cons a as' => reverse as' ++ cons a nil
inductive Palindrome {Ξ± : Type} : List Ξ± β Prop where
| nil : Palindrome nil
| single (x : Ξ±) : Palindrome (cons x nil)
| sandwich (x : Ξ±) (xs : List Ξ±)
: Palindrome xs β Palindrome (cons x xs ++ cons x nil)
namespace Palindrome | theorem Palindrome_rev {Ξ± : Type} (l : List Ξ±)
: Palindrome l β l = reverse l := | := by
intro lPal
induction lPal with
| nil => rfl
| single x => rfl
| sandwich x xs xsPal xsRev =>
rw [reverse_append, reverse, reverse, nil_append, reverse, βxsRev]
rw [cons_append, βappend_assoc, cons_append, nil_append, cons_append] | 2 | 8 | false | Semantics |
281 | Imp.Hoare.hoare_while | theorem hoare_while P b c :
{* fun st => P st β§ beval st b *} c {* P *}
β {* P *} c_while b c {* fun st => P st β§ Β¬(beval st b) *} | lean-formal-reasoning-program | Frap/Hoare.lean | [
"import Frap.Trans"
] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "String",
"module": "Init.Prelude"
},
{
"name": "Bool",
"module": "Init.Prelude"
}
] | [
{
"name": "syntax:21 \"if\" imp:20 \"then\" imp:20 \"else\" imp:20 \"end\" : im",
"content": "syntax:21 \"if\" imp:20 \"then\" imp:20 \"else\" imp:20 \"end\" : imp\n\nsyntax \"false\" : imp\n\nsyntax \"false\" : term\n\nsyntax \"true\" : imp\n\nsyntax \"true\" : term\n\nsyntax \"<{\" imp \"}>\" : term\n\nsyntax:21 \"while\" imp:20 \"do\" imp:20 \"end\" : imp\n\nsyntax:30 \"{*\" term \"*}\" term \"{*\" term \"*}\" : term"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(term|true) => `(Bool.true)\n | `(term|false) => `(Bool.false)\n | `(term|<{$x}>) => `(imp|$x)\n | `(imp|$n:num) => `(a_num $n)\n | `(imp|$s:str) => `(a_id $s)\n | `(imp|$x + $y) => `(a_plus <{$x}> <{$y}>)\n | `(imp|$x - $y) => `(a_minus <{$x}> <{$y}>)\n | `(imp|$x * $y) => `(a_mult <{$x}> <{$y}>)\n | `(imp|true) => `(b_true)\n | `(imp|false) => `(b_false)\n | `(imp|$x = $y) => `(b_eq <{$x}> <{$y}>)\n | `(imp|$x != $y) => `(b_neq <{$x}> <{$y}>)\n | `(imp|$x <= $y) => `(b_le <{$x}> <{$y}>)\n | `(imp|!$x) => `(b_not <{$x}>)\n | `(imp|$x && $y) => `(b_and <{$x}> <{$y}>)\n | `(imp|$x || $y) => `(b_or <{$x}> <{$y}>)\n | `(imp|($x)) => `(<{$x}>)\n | `(imp|$x:ident) => `(a_id $(Lean.quote (toString x.getId)))\n | `(imp|<[$t:term]>) => pure t"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(imp|skip) => `(c_skip)\n | `(imp|$x:str := $y) => `(c_asgn $x <{$y}>)\n | `(imp|$x:ident := $y) => `(c_asgn $x <{$y}>)\n | `(imp|$c1 ; $c2) => `(c_seq <{$c1}> <{$c2}>)\n | `(imp|if $b then $c1 else $c2 end) => `(c_if <{$b}> <{$c1}> <{$c2}>)\n | `(imp|while $b do $c end) => `(c_while <{$b}> <{$c}>)"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(term|$p <<->> $q) => `($p ->> $q β§ $q ->> $p)"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(term|{*$p*} $c {*$q*}) => `(valid_hoare_triple $p $c $q)"
},
{
"name": "x",
"content": "abbrev x := \"x\""
},
{
"name": "beval",
"content": "def beval (st : State) (b : BExp) : Bool :=\n match b with\n | b_true => true\n | b_false => false\n | b_eq aβ aβ => (aeval st aβ) == (aeval st aβ)\n | b_neq aβ aβ => (aeval st aβ) != (aeval st aβ)\n | b_le aβ aβ => (aeval st aβ) <= (aeval st aβ)\n | b_not bβ => not (beval st bβ)\n | b_and bβ bβ => and (beval st bβ) (beval st bβ)\n | b_or bβ bβ => or (beval st bβ) (beval st bβ)\n\nexample : aeval (update empty x 5)\n <{3 + x * 2}>\n \n = 13 := by admit /- proof elided -/"
},
{
"name": "empty",
"content": "def empty : State := fun _ => 0"
},
{
"name": "State",
"content": "abbrev State := String β Nat"
},
{
"name": "y",
"content": "abbrev y := \"y\""
},
{
"name": "z",
"content": "abbrev z := \"z\""
},
{
"name": "aeval",
"content": "def aeval (st : State) (a : AExp) : Nat :=\n match a with\n | a_num n => n\n | a_id x => st x\n | a_plus aβ aβ => (aeval st aβ) + (aeval st aβ)\n | a_minus aβ aβ => (aeval st aβ) - (aeval st aβ)\n | a_mult aβ aβ => (aeval st aβ) * (aeval st aβ)"
},
{
"name": "AExp",
"content": "inductive AExp where\n | a_num : Nat β AExp\n | a_id : String β AExp \n | a_plus : AExp β AExp β AExp\n | a_minus : AExp β AExp β AExp\n | a_mult : AExp β AExp β AExp"
},
{
"name": "AExp",
"content": "inductive AExp where\n | a_num : Nat β AExp\n | a_plus : AExp β AExp β AExp\n | a_minus : AExp β AExp β AExp\n | a_mult : AExp β AExp β AExp"
},
{
"name": "update",
"content": "def update (st : State) (k : String) (v : Nat) : State :=\n fun x => if x == k then v else st x"
},
{
"name": "BExp",
"content": "inductive BExp where\n | b_true : BExp\n | b_false : BExp\n | b_eq : AExp β AExp β BExp\n | b_neq : AExp β AExp β BExp\n | b_le : AExp β AExp β BExp\n | b_not : BExp β BExp\n | b_and : BExp β BExp β BExp\n | b_or : BExp β BExp β BExp"
},
{
"name": "Com",
"content": "inductive Com : Type :=\n | c_skip : Com\n | c_asgn : String β AExp β Com\n | c_seq : Com β Com β Com\n | c_if : BExp β Com β Com β Com\n | c_while : BExp β Com β Com\n | c_par : Com β Com β Com"
},
{
"name": "CEval",
"content": "inductive CEval : Com β State β State β Prop :=\n | e_skip : β st,\n CEval c_skip st st\n | e_asgn : β a n x st,\n aeval st a = n\n β CEval (c_asgn x a) st (update st x n)\n | e_seq : β cβ cβ st st' st'',\n CEval cβ st st' β CEval cβ st' st''\n β CEval (c_seq cβ cβ) st st''\n | e_ifTrue : β b cβ cβ st st',\n beval st b = true β CEval cβ st st'\n β CEval (c_if b cβ cβ) st st'\n | e_ifFalse : β b cβ cβ st st',\n beval st b = false β CEval cβ st st'\n β CEval (c_if b cβ cβ) st st'\n | e_whileFalse : β b c st,\n beval st b = false\n β CEval (c_while b c) st st\n | e_whileTrue : β b c st st' st'',\n beval st b = true\n β CEval c st st'\n β CEval (c_while b c) st' st''\n β CEval (c_while b c) st st''\n\nsyntax:30 term \" =[ \" imp \" ]=> \" term : term\nmacro_rules\n | `(term|$st =[ $c ]=> $st') => `(CEval <{$c}> $st $st')"
},
{
"name": "Assertion",
"content": "abbrev Assertion := State β Prop"
},
{
"name": "assert_implies",
"content": "def assert_implies (P Q : Assertion) : Prop :=\n β st, P st β Q st"
},
{
"name": "valid_hoare_triple",
"content": "def valid_hoare_triple (P : Assertion) (c : Com) (Q : Assertion) : Prop :=\n β st st', P st β (st =[<[c]>]=> st') β Q st'"
}
] | [
{
"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]"
}
] | [] | [] | import Frap.Trans
namespace Imp
open AExp
open BExp
open Com
open CEval
namespace Hoare
infix:36 " ->> " => assert_implies | theorem hoare_while P b c :
{* fun st => P st β§ beval st b *} c {* P *}
β {* P *} c_while b c {* fun st => P st β§ Β¬(beval st b) *} := | := by
intro hHoare st st' hPre hEval
-- we proceed by induction on `hEval`
generalize hloop : c_while b c = cmd at *
induction hEval with simp at *
| e_whileFalse =>
constructor
. exact hPre
. simp [*]
| e_whileTrue =>
simp [*] at *
rename_i ih
apply ih
apply hHoare
. constructor
. apply hPre
. assumption
. assumption
/-
We call `P` a _loop invariant_ of `while b do c` if
`{P β§ b} c {P}`
is a valid Hoare triple.
This means that `P` will be true at the end of the loop body whenever the loop body executes.
If `P` contradicts `b`, this holds trivially since the precondition is false.
For instance, `X = 0` is a loop invariant of
`while X = 2 do X := 1 end`
since the program will never enter the loop.
The program
`while Y > 10 do Y := Y - 1; Z := Z + 1 end`
admits an interesting loop invariant:
`X = Y + Z`
Note that this doesn't contradict the loop guard but neither is it a command invariant of
`Y := Y - 1; Z := Z + 1`
since, if `X = 5`, `Y = 0` and `Z = 5`, running the command will set `Y + Z` to 6, because `Y` remains 0.
The loop guard `Y > 10` guarantees that this will not be the case.
We will see many such loop invariants in the following lecture.
-/
example :
-- { x β€ 3 }
{* fun st => st x β€ 3 *}
<{
while x <= 2 do
x := x + 1 | 4 | 15 | true | Semantics |
282 | Tree.bst_insert_of_bst | theorem bst_insert_of_bst {Ξ± : Type u} (k : Nat) (v : Ξ±) (t : Tree Ξ±)
: BST t β BST (insert k v t) | lean-formal-reasoning-program | Frap/ADT.lean | [] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "String",
"module": "Init.Prelude"
}
] | [
{
"name": "...",
"content": "..."
}
] | [
{
"name": "Nat.le_antisymm",
"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": "Tree",
"content": "inductive Tree (Ξ± : Type u) where\n | empty : Tree Ξ±\n | tree (l : Tree Ξ±) (k : Nat) (v : Ξ±) (r : Tree Ξ±) : Tree Ξ±"
},
{
"name": "Tree.ex_tree",
"content": "def ex_tree : Tree String :=\n tree (tree empty 2 \"two\" empty) 4 \"four\" (tree empty 5 \"five\" empty)"
},
{
"name": "Tree.insert",
"content": "def insert {Ξ± : Type u} (x : Nat) (v : Ξ±) (t : Tree Ξ±) : Tree Ξ± :=\n match t with\n | empty => tree empty x v empty\n | tree l k v' r =>\n if x < k then tree (insert x v l) k v' r\n else if x > k then tree l k v' (insert x v r)\n else tree l x v r"
},
{
"name": "Tree.ForallTree",
"content": "inductive ForallTree {Ξ± : Type u} (p : Nat β Ξ± β Prop) : Tree Ξ± β Prop where\n | empty : ForallTree p empty\n | tree : β l k v r,\n p k v β ForallTree p l β ForallTree p r\n β ForallTree p (tree l k v r)"
},
{
"name": "Tree.BST",
"content": "inductive BST {Ξ± : Type u} : Tree Ξ± β Prop where\n | empty : BST empty\n | tree : β l k v r,\n ForallTree (fun x _ => x < k) l\n β ForallTree (fun x _ => x > k) r\n β BST l\n β BST r\n β BST (tree l k v r)\n\nexample : BST ex_tree := by admit /- proof elided -/"
}
] | [
{
"name": "Tree.forall_insert_of_forall",
"content": "theorem forall_insert_of_forall {Ξ± : Type u} (P : Nat β Ξ± β Prop) (t : Tree Ξ±)\n : ForallTree P t β β k v, P k v β ForallTree P (insert k v t)"
}
] | inductive Tree (Ξ± : Type u) where
| empty : Tree Ξ±
| tree (l : Tree Ξ±) (k : Nat) (v : Ξ±) (r : Tree Ξ±) : Tree Ξ±
namespace Tree
def ex_tree : Tree String :=
tree (tree empty 2 "two" empty) 4 "four" (tree empty 5 "five" empty)
def insert {Ξ± : Type u} (x : Nat) (v : Ξ±) (t : Tree Ξ±) : Tree Ξ± :=
match t with
| empty => tree empty x v empty
| tree l k v' r =>
if x < k then tree (insert x v l) k v' r
else if x > k then tree l k v' (insert x v r)
else tree l x v r
inductive ForallTree {Ξ± : Type u} (p : Nat β Ξ± β Prop) : Tree Ξ± β Prop where
| empty : ForallTree p empty
| tree : β l k v r,
p k v β ForallTree p l β ForallTree p r
β ForallTree p (tree l k v r)
inductive BST {Ξ± : Type u} : Tree Ξ± β Prop where
| empty : BST empty
| tree : β l k v r,
ForallTree (fun x _ => x < k) l
β ForallTree (fun x _ => x > k) r
β BST l
β BST r
β BST (tree l k v r)
example : BST ex_tree := by admit /- proof elided -/ | theorem bst_insert_of_bst {Ξ± : Type u} (k : Nat) (v : Ξ±) (t : Tree Ξ±)
: BST t β BST (insert k v t) := | := by
intro hbst
induction hbst with
| empty => constructor <;> constructor
| tree l k' v' r hlt hgt hbstl hbstr =>
unfold insert
split
. constructor
. apply forall_insert_of_forall
. assumption
. assumption
. assumption
. assumption
. assumption
. split
. constructor
. assumption
. apply forall_insert_of_forall
. assumption
. assumption
. assumption
. assumption
. have heq : k = k' := by
simp [*] at *
apply Nat.le_antisymm <;> assumption
constructor
. rw [heq]; assumption
. rw [heq]; assumption
. assumption
. assumption | 4 | 11 | false | Semantics |
283 | Hidden.List.Palindrome.Palindrome_app_rev | theorem Palindrome_app_rev {Ξ± : Type} (l : List Ξ±) : Palindrome (l ++ reverse l) | lean-formal-reasoning-program | Frap/Exercises/IndProp.lean | [] | [
{
"name": "structure BitVec (w : Nat) where",
"module": ""
},
{
"name": "/-- Construct a `BitVec w` from a number less than `2^w`.",
"module": ""
},
{
"name": "O(1), because we use `Fin` as the internal representation of a bitvector. -/",
"module": ""
},
{
"name": "ofFin ::",
"module": ""
},
{
"name": "/-- Interpret a bitvector as a number less than `2^w`.",
"module": ""
},
{
"name": "O(1), because we use `Fin` as the internal representation of a bitvector. -/",
"module": ""
},
{
"name": "toFin : Fin (hPow 2 w)",
"module": ""
}
] | [
{
"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": "Hidden.List",
"content": "inductive List (Ξ± : Type u) where\n | nil : List Ξ±\n | cons : Ξ± β List Ξ± β List Ξ±"
},
{
"name": "Hidden.List.reverse",
"content": "def reverse {Ξ± : Type u} (as : List Ξ±) : List Ξ± :=\n match as with\n | nil => nil\n | cons a as' => reverse as' ++ cons a nil"
},
{
"name": "Hidden.List.Palindrome",
"content": "inductive Palindrome {Ξ± : Type} : List Ξ± β Prop where\n | nil : Palindrome nil\n | single (x : Ξ±) : Palindrome (cons x nil)\n | sandwich (x : Ξ±) (xs : List Ξ±)\n : Palindrome xs β Palindrome (cons x xs ++ cons x nil)"
}
] | [
{
"name": "Hidden.List.nil_append",
"content": "theorem nil_append (as : List Ξ±) : nil ++ as = as"
},
{
"name": "Hidden.List.cons_append",
"content": "theorem cons_append (a : Ξ±) (as bs : List Ξ±)\n : (cons a as) ++ bs = cons a (as ++ bs)"
},
{
"name": "Hidden.List.append_assoc",
"content": "theorem append_assoc (as bs cs : List Ξ±)\n : (as ++ bs) ++ cs = as ++ (bs ++ cs)"
}
] | namespace Hidden
inductive List (Ξ± : Type u) where
| nil : List Ξ±
| cons : Ξ± β List Ξ± β List Ξ±
namespace List
def reverse {Ξ± : Type u} (as : List Ξ±) : List Ξ± :=
match as with
| nil => nil
| cons a as' => reverse as' ++ cons a nil
inductive Palindrome {Ξ± : Type} : List Ξ± β Prop where
| nil : Palindrome nil
| single (x : Ξ±) : Palindrome (cons x nil)
| sandwich (x : Ξ±) (xs : List Ξ±)
: Palindrome xs β Palindrome (cons x xs ++ cons x nil)
namespace Palindrome | theorem Palindrome_app_rev {Ξ± : Type} (l : List Ξ±) : Palindrome (l ++ reverse l) := | := by
induction l with
| nil => rw [nil_append, reverse]; exact nil
| cons x xs ih =>
rw [cons_append, reverse, βappend_assoc, βcons_append]
apply sandwich x
exact ih | 2 | 6 | false | Semantics |
284 | Hidden.Nat.mul_assoc | theorem mul_assoc (m n k : Nat) : m * n * k = m * (n * k) | lean-formal-reasoning-program | Frap/Inductive.lean | [] | [
{
"name": "structure BitVec (w : Nat) where",
"module": ""
},
{
"name": "/-- Construct a `BitVec w` from a number less than `2^w`.",
"module": ""
},
{
"name": "O(1), because we use `Fin` as the internal representation of a bitvector. -/",
"module": ""
},
{
"name": "ofFin ::",
"module": ""
},
{
"name": "/-- Interpret a bitvector as a number less than `2^w`.",
"module": ""
},
{
"name": "O(1), because we use `Fin` as the internal representation of a bitvector. -/",
"module": ""
},
{
"name": "toFin : Fin (hPow 2 w)",
"module": ""
}
] | [
{
"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": "Hidden.Nat",
"content": "inductive Nat where\n | zero : Nat\n | succ : Nat β Nat"
},
{
"name": "Hidden.Nat.add",
"content": "def add (m n : Nat) : Nat :=\n match n with\n | zero => m\n | succ n' => succ (add m n')"
}
] | [
{
"name": "Hidden.Nat.add_succ",
"content": "theorem add_succ (m n : Nat) : m + succ n = succ (m + n)"
},
{
"name": "Hidden.Nat.add_assoc",
"content": "theorem add_assoc (m n k : Nat) : m + n + k = m + (n + k)"
},
{
"name": "Hidden.Nat.mul_succ",
"content": "theorem mul_succ (m n : Nat) : m * succ n = add (m * n) m"
},
{
"name": "Hidden.Nat.add_infix",
"content": "theorem add_infix (m n : Nat) : m.add n = m + n"
}
] | section rewriting
variable (Ξ± : Type) (a b c d : Ξ±) -- a, b, c, d are elements of some type
/-
## Rewriting
Recall our equality proof from last time.
-/
example : a = b β c = b β c = d β a = d := by
intro hab hcb hcd
apply Eq.trans
. exact hab
. apply Eq.trans
. apply Eq.symm
exact hcb
. exact hcd
/-
Notice that in each subgoal, we are attempting to use a hypothesis by way of an equality property.
For example, we invoke the transitive property on `a = d` so that we can use the assumption `a = b` and be left with `b = d` to prove.
In effect, we are substituting `b` for `a` in the goal.
This substitution operation can be seen as rewriting some term in the goal with another, via an equality in the hypothesis.
This rewriting operation is so common that Lean provides a `rw` tactic to do so.
It replaces equals for equals, which could be an equality (`=`) or equivalence (`β`).
Be default, it rewrites the left-hand side with the right-hand side.
For right-to-left rewriting, a left arrow needs to be indicated before the hypothesis (`β`, typed with `\<-` shortcut) .
-/
example : a = b β c = b β c = d β a = d := by
intro hab hcb hcd
rw [hab]
rw [β hcd]
rw [hcb]
end rewriting
/-
## reflexivity tactic
One of the most powerful tactics is the _reflexivity_ tactic, written `rfl` in Lean.
It will attempt to conclude that both sides of an equality goal is indeed equal, up to some trivial computation, such as expansion of definitions and function applications.
-/
example : 2 + 5 = 7 := by
rfl
example : Β¬ Even = 3 := by
intro h
sorry
namespace Hidden
inductive Nat where
| zero : Nat
| succ : Nat β Nat
namespace Nat
def add (m n : Nat) : Nat :=
match n with
| zero => m
| succ n' => succ (add m n')
def mul (m n : Nat) : Nat :=
match n with
| zero => zero
| succ n' => add (mul m n') m
instance : Add Nat where
add := add
instance : Mul Nat where
mul := mul
end Nat
end Hidden
section opendemo
open Nat
end opendemo
namespace Hidden
namespace Nat
end Nat
end Hidden
namespace Hidden
namespace Nat | theorem mul_assoc (m n k : Nat) : m * n * k = m * (n * k) := | := by
induction k with
| zero => rfl
| succ k' ih =>
rw [mul_succ, mul_succ, ih, add_infix, add_infix]
have nat_distrib (m n k : Nat)
: m * n + m * k = m * (n + k) := by
-- distributive property from left
induction k with
| zero => rfl
| succ k' ih =>
rw [mul_succ, add_succ, mul_succ, add_infix, add_infix, β add_assoc, ih]
rw [nat_distrib] | 2 | 6 | false | Semantics |
285 | permutation_cons_app | theorem permutation_cons_app (l lβ lβ : List Ξ±)
: Permutation l (lβ ++ lβ)
β Permutation (a :: l) (lβ ++ a :: lβ) | lean-formal-reasoning-program | Frap/Sort.lean | [] | [
{
"name": "List",
"module": "Init.Prelude"
}
] | [
{
"name": "...",
"content": "..."
}
] | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "append_assoc",
"content": "theorem append_assoc (as bs cs : List Ξ±)\n : (as ++ bs) ++ cs = as ++ (bs ++ cs)"
}
] | [
{
"name": "Permutation",
"content": "inductive Permutation {Ξ± : Type} : List Ξ± β List Ξ± β Prop :=\n | perm_nil : Permutation [] []\n | perm_skip x l l'\n : Permutation l l' β Permutation (x::l) (x::l')\n | perm_swap x y l : Permutation (y::x::l) (x::y::l)\n | perm_trans l l' l''\n : Permutation l l' β Permutation l' l''\n β Permutation l l''"
}
] | [
{
"name": "permutation_refl",
"content": "theorem permutation_refl (l : List Ξ±) : Permutation l l"
},
{
"name": "permutation_symm",
"content": "theorem permutation_symm (l l' : List Ξ±)\n : Permutation l l' β Permutation l' l"
},
{
"name": "permutation_app_head",
"content": "theorem permutation_app_head (l tl tl' : List Ξ±)\n : Permutation tl tl' β Permutation (l++tl) (l++tl')"
},
{
"name": "permutation_cons_append",
"content": "theorem permutation_cons_append (l : List Ξ±) x\n : Permutation (x :: l) (l ++ [x])"
}
] | inductive Permutation {Ξ± : Type} : List Ξ± β List Ξ± β Prop :=
| perm_nil : Permutation [] []
| perm_skip x l l'
: Permutation l l' β Permutation (x::l) (x::l')
| perm_swap x y l : Permutation (y::x::l) (x::y::l)
| perm_trans l l' l''
: Permutation l l' β Permutation l' l''
β Permutation l l''
open Permutation | theorem permutation_cons_app (l lβ lβ : List Ξ±)
: Permutation l (lβ ++ lβ)
β Permutation (a :: l) (lβ ++ a :: lβ) := | := by
intro h
-- a :: l
-- a :: (lβ ++ lβ)
-- lβ ++ lβ ++ [a]
-- lβ ++ (lβ ++ [a])
-- lβ ++ a :: lβ
apply perm_trans
. apply perm_skip; exact h
. apply perm_trans
. apply permutation_cons_append
. rw [List.append_assoc]
apply permutation_app_head
apply permutation_symm
apply permutation_cons_append | 2 | 7 | false | Semantics |
286 | TM.soundness | theorem soundness t t' T
: HasType t T β multistep t t' β Β¬ stuck t' | lean-formal-reasoning-program | Frap/Types.lean | [
"import Frap.SmallStep"
] | [
{
"name": "And",
"module": "Init.Prelude"
}
] | [
{
"name": "syntax term \"==>\" term : term",
"content": "syntax term \"==>\" term : term\n\nsyntax term \"~~>\" term : term\n\nsyntax term \"~~>*\" term : term\n\nsyntax:30 term \" =[ \" imp \" ]=> \" term : term\n\nsyntax term \"!->\" term \"; \" term : term\n\nsyntax:36 term \"<<->>\" term : term"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(term|$t:term ==> $n:term) => `(Eval $t $n)"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(term|$tβ:term ~~> $tβ:term) => `(Step $tβ $tβ)\n\nexample :\n p\n (p (c 1) (c 3))\n (p (c 2) (c 4))\n ~~>\n p\n (c 4)\n (p (c 2) (c 4)) := by admit /- proof elided -/"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(term|$tβ:term ~~>* $tβ:term) => `(Multi Step $tβ $tβ)"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(term|$p <<->> $q) => `($p ->> $q β§ $q ->> $p)"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(term|{*$p*} $c {*$q*}) => `(valid_hoare_triple $p $c $q)"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(term|$st =[ $c ]=> $st') => `(CEval <{$c}> $st $st')"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(term|$x:term !-> $a:term ; $st) => `(update $st $x $a)\n\nexample : empty =[\n x := 2;\n if (x <= 1) then y := 3 else z := 4 end\n ]=> (z !-> 4; x !-> 2; empty) := by admit /- proof elided -/"
},
{
"name": "Tm",
"content": "inductive Tm : Type :=\n | tru : Tm\n | fls : Tm\n | ite : Tm β Tm β Tm β Tm\n | zro : Tm\n | scc : Tm β Tm\n | prd : Tm β Tm\n | iszero : Tm β Tm"
},
{
"name": "Step",
"content": "inductive Step : Tm β Tm β Prop :=\n | st_ifTrue tβ tβ : Step (ite tru tβ tβ) tβ\n | st_ifFalse tβ tβ : Step (ite fls tβ tβ) tβ\n | st_if c c' tβ tβ :\n Step c c' β Step (ite c tβ tβ) (ite c' tβ tβ)\n | st_succ tβ tβ' : Step tβ tβ' β Step (scc tβ) (scc tβ')\n | st_pred0 : Step (prd zro) zro\n | st_predSucc v : NValue v β Step (prd (scc v)) v\n | st_pred tβ tβ' : Step tβ tβ' β Step (prd tβ) (prd tβ')\n | st_iszero0 : Step (iszero zro) tru\n | st_iszeroSucc v : NValue v β Step (iszero (scc v)) fls\n | st_iszero tβ tβ' :\n Step tβ tβ' β Step (iszero tβ) (iszero tβ')"
},
{
"name": "NValue",
"content": "inductive NValue : Tm β Prop :=\n | nv_0 : NValue zro\n | nv_succ t : NValue t β NValue (scc t)"
},
{
"name": "Tm",
"content": "inductive Tm : Type :=\n | c : Nat β Tm \n | p : Tm β Tm β Tm "
},
{
"name": "normal_form",
"content": "def normal_form {X : Type} (R : relation X) (t : X) : Prop := Β¬βt', R t t'"
},
{
"name": "relation",
"content": "def relation (X : Type) := X β X β Prop"
},
{
"name": "BValue",
"content": "inductive BValue : Tm β Prop :=\n | bv_true : BValue tru\n | bv_false : BValue fls"
},
{
"name": "And",
"content": "inductive And : Prop β Prop β Prop where\n | intro : a β b β And a b"
},
{
"name": "Ty",
"content": "inductive Ty : Type :=\n | bool : Ty\n | nat : Ty"
},
{
"name": "HasType",
"content": "inductive HasType : Tm β Ty β Prop :=\n | t_true : HasType tru bool\n | t_false : HasType fls bool\n | t_if tβ tβ tβ T :\n HasType tβ bool β HasType tβ T β HasType tβ T\n β HasType (ite tβ tβ tβ) T\n | t_0 : HasType zro nat\n | t_succ tβ : HasType tβ nat β HasType (scc tβ) nat\n | t_pred tβ : HasType tβ nat β HasType (prd tβ) nat\n | t_iszero tβ : HasType tβ nat β HasType (iszero tβ) bool"
},
{
"name": "Multi",
"content": "inductive Multi {X : Type} (R : relation X) : relation X :=\n | multi_refl x : Multi R x x\n | multi_step x y z : R x y β Multi R y z β Multi R x z"
}
] | [
{
"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": "TM.Tm",
"content": "inductive Tm : Type :=\n | tru : Tm\n | fls : Tm\n | ite : Tm β Tm β Tm β Tm\n | zro : Tm\n | scc : Tm β Tm\n | prd : Tm β Tm\n | iszero : Tm β Tm"
},
{
"name": "TM.BValue",
"content": "inductive BValue : Tm β Prop :=\n | bv_true : BValue tru\n | bv_false : BValue fls"
},
{
"name": "TM.NValue",
"content": "inductive NValue : Tm β Prop :=\n | nv_0 : NValue zro\n | nv_succ t : NValue t β NValue (scc t)"
},
{
"name": "TM.value",
"content": "abbrev value (t : Tm) := BValue t β¨ NValue t"
},
{
"name": "TM.Step",
"content": "inductive Step : Tm β Tm β Prop :=\n | st_ifTrue tβ tβ : Step (ite tru tβ tβ) tβ\n | st_ifFalse tβ tβ : Step (ite fls tβ tβ) tβ\n | st_if c c' tβ tβ :\n Step c c' β Step (ite c tβ tβ) (ite c' tβ tβ)\n | st_succ tβ tβ' : Step tβ tβ' β Step (scc tβ) (scc tβ')\n | st_pred0 : Step (prd zro) zro\n | st_predSucc v : NValue v β Step (prd (scc v)) v\n | st_pred tβ tβ' : Step tβ tβ' β Step (prd tβ) (prd tβ')\n | st_iszero0 : Step (iszero zro) tru\n | st_iszeroSucc v : NValue v β Step (iszero (scc v)) fls\n | st_iszero tβ tβ' :\n Step tβ tβ' β Step (iszero tβ) (iszero tβ')"
},
{
"name": "TM.step_normal_form",
"content": "abbrev step_normal_form := normal_form Step"
},
{
"name": "TM.stuck",
"content": "def stuck (t: Tm) : Prop :=\n step_normal_form t β§ Β¬ value t\n\n/-\nexercise (2-star)\n-/\nexample : β t, stuck t :="
},
{
"name": "TM.Ty",
"content": "inductive Ty : Type :=\n | bool : Ty\n | nat : Ty"
},
{
"name": "TM.HasType",
"content": "inductive HasType : Tm β Ty β Prop :=\n | t_true : HasType tru bool\n | t_false : HasType fls bool\n | t_if tβ tβ tβ T :\n HasType tβ bool β HasType tβ T β HasType tβ T\n β HasType (ite tβ tβ tβ) T\n | t_0 : HasType zro nat\n | t_succ tβ : HasType tβ nat β HasType (scc tβ) nat\n | t_pred tβ : HasType tβ nat β HasType (prd tβ) nat\n | t_iszero tβ : HasType tβ nat β HasType (iszero tβ) bool"
},
{
"name": "TM.multistep",
"content": "abbrev multistep := Multi Step"
}
] | [
{
"name": "TM.bool_canonical",
"content": "theorem bool_canonical t : HasType t bool β value t β BValue t"
},
{
"name": "TM.nat_canonical",
"content": "theorem nat_canonical t : HasType t nat β value t β NValue t"
},
{
"name": "TM.progress",
"content": "theorem progress t T\n : HasType t T β value t β¨ β t', Step t t'"
},
{
"name": "TM.preservation",
"content": "theorem preservation t t' T\n : HasType t T β Step t t' β HasType t' T"
}
] | import Frap.SmallStep
namespace TM
inductive Tm : Type :=
| tru : Tm
| fls : Tm
| ite : Tm β Tm β Tm β Tm
| zro : Tm
| scc : Tm β Tm
| prd : Tm β Tm
| iszero : Tm β Tm
open Tm
inductive BValue : Tm β Prop :=
| bv_true : BValue tru
| bv_false : BValue fls
inductive NValue : Tm β Prop :=
| nv_0 : NValue zro
| nv_succ t : NValue t β NValue (scc t)
open BValue
open NValue
abbrev value (t : Tm) := BValue t β¨ NValue t
inductive Step : Tm β Tm β Prop :=
| st_ifTrue tβ tβ : Step (ite tru tβ tβ) tβ
| st_ifFalse tβ tβ : Step (ite fls tβ tβ) tβ
| st_if c c' tβ tβ :
Step c c' β Step (ite c tβ tβ) (ite c' tβ tβ)
| st_succ tβ tβ' : Step tβ tβ' β Step (scc tβ) (scc tβ')
| st_pred0 : Step (prd zro) zro
| st_predSucc v : NValue v β Step (prd (scc v)) v
| st_pred tβ tβ' : Step tβ tβ' β Step (prd tβ) (prd tβ')
| st_iszero0 : Step (iszero zro) tru
| st_iszeroSucc v : NValue v β Step (iszero (scc v)) fls
| st_iszero tβ tβ' :
Step tβ tβ' β Step (iszero tβ) (iszero tβ')
open Step
abbrev step_normal_form := normal_form Step
def stuck (t: Tm) : Prop :=
step_normal_form t β§ Β¬ value t
/-
exercise (2-star)
-/
example : β t, stuck t :=
inductive Ty : Type :=
| bool : Ty
| nat : Ty
open Ty
inductive HasType : Tm β Ty β Prop :=
| t_true : HasType tru bool
| t_false : HasType fls bool
| t_if tβ tβ tβ T :
HasType tβ bool β HasType tβ T β HasType tβ T
β HasType (ite tβ tβ tβ) T
| t_0 : HasType zro nat
| t_succ tβ : HasType tβ nat β HasType (scc tβ) nat
| t_pred tβ : HasType tβ nat β HasType (prd tβ) nat
| t_iszero tβ : HasType tβ nat β HasType (iszero tβ) bool
open HasType
example -- `β’ if false then 0 else (succ 0) β nat`
: HasType (ite fls zro (scc zro)) nat := by
apply t_if
. apply t_false
. apply t_0
. apply t_succ
apply t_0
/-
It's important to realize that the typing relation is a _conservative_ (or _static_) approximation: it does not consider what happens when the term is reduced.
In particular, it does not calculate the type of its normal form.
-/
example -- `β’ if false then zero else true β bool`
: Β¬ HasType (ite fls zro tru) bool := by
intro contra
cases contra
rename_i contra _
cases contra
/-
exercise (1-star)
-/
example t : HasType (scc t) nat β HasType t nat := by
intro ht
cases ht
assumption
abbrev multistep := Multi Step | theorem soundness t t' T
: HasType t T β multistep t t' β Β¬ stuck t' := | := by
intro hT P
induction P with (intro contra; obtain β¨R, Sβ© := contra)
| multi_refl =>
cases (progress _ _ hT)
. -- value
simp [*] at *
. -- step
simp [step_normal_form, normal_form, *] at *
| multi_step =>
rename_i ih; apply ih
. apply preservation
. apply hT
. assumption
. unfold stuck; constructor <;> assumption | 4 | 26 | false | Semantics |
287 | CImp.par_body_n | theorem par_body_n n st
: st x = 0 β§ st y = 0
β β st', Multi CStep (par_loop, st) (par_loop, st')
β§ st' x = n β§ st' y = 0 | lean-formal-reasoning-program | Frap/SmallStepImp.lean | [
"import Frap.SmallStep",
"import Frap.Equiv"
] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "String",
"module": "Init.Prelude"
},
{
"name": "And",
"module": "Init.Prelude"
}
] | [
{
"name": "syntax:21 \"if\" imp:20 \"then\" imp:20 \"else\" imp:20 \"end\" : im",
"content": "syntax:21 \"if\" imp:20 \"then\" imp:20 \"else\" imp:20 \"end\" : imp"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(term|true) => `(Bool.true)\n | `(term|false) => `(Bool.false)\n | `(term|<{$x}>) => `(imp|$x)\n | `(imp|$n:num) => `(a_num $n)\n | `(imp|$s:str) => `(a_id $s)\n | `(imp|$x + $y) => `(a_plus <{$x}> <{$y}>)\n | `(imp|$x - $y) => `(a_minus <{$x}> <{$y}>)\n | `(imp|$x * $y) => `(a_mult <{$x}> <{$y}>)\n | `(imp|true) => `(b_true)\n | `(imp|false) => `(b_false)\n | `(imp|$x = $y) => `(b_eq <{$x}> <{$y}>)\n | `(imp|$x != $y) => `(b_neq <{$x}> <{$y}>)\n | `(imp|$x <= $y) => `(b_le <{$x}> <{$y}>)\n | `(imp|!$x) => `(b_not <{$x}>)\n | `(imp|$x && $y) => `(b_and <{$x}> <{$y}>)\n | `(imp|$x || $y) => `(b_or <{$x}> <{$y}>)\n | `(imp|($x)) => `(<{$x}>)\n | `(imp|$x:ident) => `(a_id $(Lean.quote (toString x.getId)))\n | `(imp|<[$t:term]>) => pure t"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(imp|skip) => `(c_skip)\n | `(imp|$x:str := $y) => `(c_asgn $x <{$y}>)\n | `(imp|$x:ident := $y) => `(c_asgn $x <{$y}>)\n | `(imp|$c1 ; $c2) => `(c_seq <{$c1}> <{$c2}>)\n | `(imp|if $b then $c1 else $c2 end) => `(c_if <{$b}> <{$c1}> <{$c2}>)\n | `(imp|while $b do $c end) => `(c_while <{$b}> <{$c}>)"
},
{
"name": "AExp",
"content": "inductive AExp where\n | a_num : Nat β AExp\n | a_id : String β AExp \n | a_plus : AExp β AExp β AExp\n | a_minus : AExp β AExp β AExp\n | a_mult : AExp β AExp β AExp"
},
{
"name": "AExp",
"content": "inductive AExp where\n | a_num : Nat β AExp\n | a_plus : AExp β AExp β AExp\n | a_minus : AExp β AExp β AExp\n | a_mult : AExp β AExp β AExp"
},
{
"name": "State",
"content": "abbrev State := String β Nat"
},
{
"name": "BExp",
"content": "inductive BExp where\n | b_true : BExp\n | b_false : BExp\n | b_eq : AExp β AExp β BExp\n | b_neq : AExp β AExp β BExp\n | b_le : AExp β AExp β BExp\n | b_not : BExp β BExp\n | b_and : BExp β BExp β BExp\n | b_or : BExp β BExp β BExp"
},
{
"name": "x",
"content": "abbrev x := \"x\""
},
{
"name": "Com",
"content": "inductive Com :=\n | c_skip : Com\n | c_asgn : String β AExp β Com\n | c_seq : Com β Com β Com\n | c_if : BExp β Com β Com β Com\n | c_while : BExp β Com β Com"
},
{
"name": "empty",
"content": "def empty : State := fun _ => 0"
},
{
"name": "Multi",
"content": "inductive Multi {X : Type} (R : relation X) : relation X :=\n | multi_refl x : Multi R x x\n | multi_step x y z : R x y β Multi R y z β Multi R x z"
},
{
"name": "relation",
"content": "def relation (X : Type) := X β X β Prop"
},
{
"name": "update",
"content": "def update (st : State) (k : String) (v : Nat) : State :=\n fun x => if x == k then v else st x"
},
{
"name": "y",
"content": "abbrev y := \"y\""
},
{
"name": "And",
"content": "inductive And : Prop β Prop β Prop where\n | intro : a β b β And a b"
}
] | [
{
"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": "AVal",
"content": "inductive AVal : AExp β Prop :=\n | av_num : β n, AVal (a_num n)"
},
{
"name": "AStep",
"content": "inductive AStep (st : State) : AExp β AExp β Prop :=\n | as_id : β v, AStep st (a_id v) (a_num (st v))\n | as_plus1 : β aβ aβ' aβ,\n AStep st aβ aβ'\n β AStep st (a_plus aβ aβ) (a_plus aβ' aβ)\n | as_plus2 : β vβ aβ aβ',\n AVal vβ β AStep st aβ aβ'\n β AStep st (a_plus vβ aβ) (a_plus vβ aβ')\n | as_plus : β (vβ vβ : Nat),\n AStep st (a_plus (a_num vβ) (a_num vβ)) (a_num (vβ + vβ))\n | as_minus1 : β aβ aβ' aβ,\n AStep st aβ aβ'\n β AStep st (a_minus aβ aβ) (a_minus aβ' aβ)\n | as_minus2 : β vβ aβ aβ',\n AVal vβ β AStep st aβ aβ'\n β AStep st (a_minus vβ aβ) (a_minus vβ aβ')\n | as_minus : β (vβ vβ : Nat),\n AStep st (a_minus (a_num vβ) (a_num vβ)) (a_num (vβ - vβ))\n | as_mult1 : β aβ aβ' aβ,\n AStep st aβ aβ'\n β AStep st (a_mult aβ aβ) (a_mult aβ' aβ)\n | as_mult2 : β vβ aβ aβ',\n AVal vβ β AStep st aβ aβ'\n β AStep st (a_mult vβ aβ) (a_mult vβ aβ')\n | as_mult : β (vβ vβ : Nat),\n AStep st (a_mult (a_num vβ) (a_num vβ)) (a_num (vβ * vβ))"
},
{
"name": "BStep",
"content": "inductive BStep (st : State) : BExp β BExp β Prop :=\n | bs_eq1 : β aβ aβ' aβ,\n AStep st aβ aβ'\n β BStep st (b_eq aβ aβ) (b_eq aβ' aβ)\n | bs_eq2 : β vβ aβ aβ',\n AVal vβ β AStep st aβ aβ'\n β BStep st (b_eq vβ aβ) (b_eq vβ aβ')\n | bs_eq : β (vβ vβ : Nat),\n BStep st (b_eq (a_num vβ) (a_num vβ))\n (if vβ == vβ then b_true else b_false)\n | bs_neq1 : β aβ aβ' aβ,\n AStep st aβ aβ'\n β BStep st (b_neq aβ aβ) (b_neq aβ' aβ)\n | bs_neq2 : β vβ aβ aβ',\n AVal vβ β AStep st aβ aβ'\n β BStep st (b_neq vβ aβ) (b_neq vβ aβ')\n | bs_neq : β (vβ vβ : Nat),\n BStep st (b_neq (a_num vβ) (a_num vβ))\n (if vβ != vβ then b_true else b_false)\n | bs_le1 : β aβ aβ' aβ,\n AStep st aβ aβ'\n β BStep st (b_le aβ aβ) (b_le aβ' aβ)\n | bs_le2 : β vβ aβ aβ',\n AVal vβ β AStep st aβ aβ'\n β BStep st (b_le vβ aβ) (b_le vβ aβ')\n | bs_le : β (vβ vβ : Nat),\n BStep st (b_le (a_num vβ) (a_num vβ))\n (if vβ <= vβ then b_true else b_false)\n | bs_notStep : β bβ bβ',\n BStep st bβ bβ'\n β BStep st (b_not bβ) (b_not bβ')\n | bs_notTrue : BStep st (b_not b_true) b_false\n | bs_notFalse : BStep st (b_not b_false) b_true\n | bs_andStep : β bβ bβ' bβ,\n BStep st bβ bβ'\n β BStep st (b_and bβ bβ) (b_and bβ' bβ)\n | bs_andFalse : β bβ,\n BStep st (b_and b_false bβ) b_false\n | bs_andTrueStep : β bβ bβ',\n BStep st bβ bβ'\n β BStep st (b_and b_true bβ) (b_and b_true bβ')\n | bs_andTrueTrue :\n BStep st (b_and b_true b_true) b_true\n | bs_andTrueFalse :\n BStep st (b_and b_true b_false) b_false\n | bs_orStep : β bβ bβ' bβ,\n BStep st bβ bβ'\n β BStep st (b_or bβ bβ) (b_or bβ' bβ)\n | bs_orTrue : β bβ,\n BStep st (b_or b_true bβ) b_true\n | bs_orFalseStep : β bβ bβ',\n BStep st bβ bβ'\n β BStep st (b_or b_false bβ) (b_or b_false bβ')\n | bs_orFalseTrue :\n BStep st (b_or b_false b_true) b_true\n | bs_orFalseFalse :\n BStep st (b_or b_false b_false) b_false"
},
{
"name": "CStep",
"content": "inductive CStep : (Com Γ State) β (Com Γ State) β Prop :=\n | cs_asgnStep : β st v aβ aβ',\n AStep st aβ aβ'\n β CStep (c_asgn v aβ, st) (c_asgn v aβ', st)\n | cs_asgn : β st v (n : Nat),\n CStep (c_asgn v (a_num n), st) (c_skip, x !-> n; st)\n | cs_seqStep : β st cβ cβ' st' cβ,\n CStep (cβ, st) (cβ', st')\n β CStep (c_seq cβ cβ, st) (c_seq cβ' cβ, st')\n | cs_seqFinish : β st cβ,\n CStep (c_seq c_skip cβ, st) (cβ, st)\n | cs_ifStep : β st bβ bβ' cβ cβ,\n BStep st bβ bβ'\n β CStep (c_if bβ cβ cβ, st) (c_if bβ' cβ cβ, st)\n | cs_ifTrue : β st cβ cβ,\n CStep (c_if b_true cβ cβ, st) (cβ, st)\n | cs_ifFalse : β st cβ cβ,\n CStep (c_if b_false cβ cβ, st) (cβ, st)\n | cs_while : β st bβ cβ,\n CStep (c_while bβ cβ, st)\n (c_if bβ (c_seq cβ (c_while bβ cβ)) c_skip, st)"
},
{
"name": "CImp.Com",
"content": "inductive Com : Type :=\n | c_skip : Com\n | c_asgn : String β AExp β Com\n | c_seq : Com β Com β Com\n | c_if : BExp β Com β Com β Com\n | c_while : BExp β Com β Com\n | c_par : Com β Com β Com"
},
{
"name": "CImp.CStep",
"content": "inductive CStep : (Com Γ State) β (Com Γ State) β Prop :=\n \n | cs_asgnStep : β st v aβ aβ',\n AStep st aβ aβ'\n β CStep (c_asgn v aβ, st) (c_asgn v aβ', st)\n | cs_asgn : β st v (n : Nat),\n CStep (c_asgn v (a_num n), st) (c_skip, v !-> n; st)\n | cs_seqStep : β st cβ cβ' st' cβ,\n CStep (cβ, st) (cβ', st')\n β CStep (c_seq cβ cβ, st) (c_seq cβ' cβ, st')\n | cs_seqFinish : β st cβ,\n CStep (c_seq c_skip cβ, st) (cβ, st)\n | cs_ifStep : β st bβ bβ' cβ cβ,\n BStep st bβ bβ'\n β CStep (c_if bβ cβ cβ, st) (c_if bβ' cβ cβ, st)\n | cs_ifTrue : β st cβ cβ,\n CStep (c_if b_true cβ cβ, st) (cβ, st)\n | cs_ifFalse : β st cβ cβ,\n CStep (c_if b_false cβ cβ, st) (cβ, st)\n | cs_while : β st bβ cβ,\n CStep (c_while bβ cβ, st)\n (c_if bβ (c_seq cβ (c_while bβ cβ)) c_skip, st)\n \n | cs_par1 : β st cβ cβ' cβ st',\n CStep (cβ, st) (cβ', st')\n β CStep (c_par cβ cβ, st) (c_par cβ' cβ, st')\n | cs_par2 : β st cβ cβ cβ' st',\n CStep (cβ, st) (cβ', st')\n β CStep (c_par cβ cβ, st) (c_par cβ cβ', st')\n | cs_parDone : β st,\n CStep (c_par c_skip c_skip, st) (c_skip, st)"
},
{
"name": "CImp.par_loop",
"content": "def par_loop : Com :=\n c_par\n (c_asgn y (a_num 1))\n (c_while (b_eq (a_id y) (a_num 0))\n (c_asgn x (a_plus (a_id x) (a_num 1))))\n\n/-\nIn particular, it can terminate with `x` set to `0`.\n-/\n\nexample : β st',\n Multi CStep (par_loop, empty) (c_skip, st')\n β§ st' x = 0 :="
}
] | [
{
"name": "CImp.par_body_n__Sn",
"content": "theorem par_body_n__Sn n st\n : st x = n β§ st y = 0\n β Multi CStep (par_loop, st) (par_loop, x !-> n + 1; st)"
}
] | import Frap.Equiv
import Frap.SmallStep
open Imp
open AExp
open BExp
open Com
open Multi
inductive AVal : AExp β Prop :=
| av_num : β n, AVal (a_num n)
inductive AStep (st : State) : AExp β AExp β Prop :=
| as_id : β v, AStep st (a_id v) (a_num (st v))
| as_plus1 : β aβ aβ' aβ,
AStep st aβ aβ'
β AStep st (a_plus aβ aβ) (a_plus aβ' aβ)
| as_plus2 : β vβ aβ aβ',
AVal vβ β AStep st aβ aβ'
β AStep st (a_plus vβ aβ) (a_plus vβ aβ')
| as_plus : β (vβ vβ : Nat),
AStep st (a_plus (a_num vβ) (a_num vβ)) (a_num (vβ + vβ))
| as_minus1 : β aβ aβ' aβ,
AStep st aβ aβ'
β AStep st (a_minus aβ aβ) (a_minus aβ' aβ)
| as_minus2 : β vβ aβ aβ',
AVal vβ β AStep st aβ aβ'
β AStep st (a_minus vβ aβ) (a_minus vβ aβ')
| as_minus : β (vβ vβ : Nat),
AStep st (a_minus (a_num vβ) (a_num vβ)) (a_num (vβ - vβ))
| as_mult1 : β aβ aβ' aβ,
AStep st aβ aβ'
β AStep st (a_mult aβ aβ) (a_mult aβ' aβ)
| as_mult2 : β vβ aβ aβ',
AVal vβ β AStep st aβ aβ'
β AStep st (a_mult vβ aβ) (a_mult vβ aβ')
| as_mult : β (vβ vβ : Nat),
AStep st (a_mult (a_num vβ) (a_num vβ)) (a_num (vβ * vβ))
open AStep
inductive BStep (st : State) : BExp β BExp β Prop :=
| bs_eq1 : β aβ aβ' aβ,
AStep st aβ aβ'
β BStep st (b_eq aβ aβ) (b_eq aβ' aβ)
| bs_eq2 : β vβ aβ aβ',
AVal vβ β AStep st aβ aβ'
β BStep st (b_eq vβ aβ) (b_eq vβ aβ')
| bs_eq : β (vβ vβ : Nat),
BStep st (b_eq (a_num vβ) (a_num vβ))
(if vβ == vβ then b_true else b_false)
| bs_neq1 : β aβ aβ' aβ,
AStep st aβ aβ'
β BStep st (b_neq aβ aβ) (b_neq aβ' aβ)
| bs_neq2 : β vβ aβ aβ',
AVal vβ β AStep st aβ aβ'
β BStep st (b_neq vβ aβ) (b_neq vβ aβ')
| bs_neq : β (vβ vβ : Nat),
BStep st (b_neq (a_num vβ) (a_num vβ))
(if vβ != vβ then b_true else b_false)
| bs_le1 : β aβ aβ' aβ,
AStep st aβ aβ'
β BStep st (b_le aβ aβ) (b_le aβ' aβ)
| bs_le2 : β vβ aβ aβ',
AVal vβ β AStep st aβ aβ'
β BStep st (b_le vβ aβ) (b_le vβ aβ')
| bs_le : β (vβ vβ : Nat),
BStep st (b_le (a_num vβ) (a_num vβ))
(if vβ <= vβ then b_true else b_false)
| bs_notStep : β bβ bβ',
BStep st bβ bβ'
β BStep st (b_not bβ) (b_not bβ')
| bs_notTrue : BStep st (b_not b_true) b_false
| bs_notFalse : BStep st (b_not b_false) b_true
| bs_andStep : β bβ bβ' bβ,
BStep st bβ bβ'
β BStep st (b_and bβ bβ) (b_and bβ' bβ)
| bs_andFalse : β bβ,
BStep st (b_and b_false bβ) b_false
| bs_andTrueStep : β bβ bβ',
BStep st bβ bβ'
β BStep st (b_and b_true bβ) (b_and b_true bβ')
| bs_andTrueTrue :
BStep st (b_and b_true b_true) b_true
| bs_andTrueFalse :
BStep st (b_and b_true b_false) b_false
| bs_orStep : β bβ bβ' bβ,
BStep st bβ bβ'
β BStep st (b_or bβ bβ) (b_or bβ' bβ)
| bs_orTrue : β bβ,
BStep st (b_or b_true bβ) b_true
| bs_orFalseStep : β bβ bβ',
BStep st bβ bβ'
β BStep st (b_or b_false bβ) (b_or b_false bβ')
| bs_orFalseTrue :
BStep st (b_or b_false b_true) b_true
| bs_orFalseFalse :
BStep st (b_or b_false b_false) b_false
open BStep
inductive CStep : (Com Γ State) β (Com Γ State) β Prop :=
| cs_asgnStep : β st v aβ aβ',
AStep st aβ aβ'
β CStep (c_asgn v aβ, st) (c_asgn v aβ', st)
| cs_asgn : β st v (n : Nat),
CStep (c_asgn v (a_num n), st) (c_skip, x !-> n; st)
| cs_seqStep : β st cβ cβ' st' cβ,
CStep (cβ, st) (cβ', st')
β CStep (c_seq cβ cβ, st) (c_seq cβ' cβ, st')
| cs_seqFinish : β st cβ,
CStep (c_seq c_skip cβ, st) (cβ, st)
| cs_ifStep : β st bβ bβ' cβ cβ,
BStep st bβ bβ'
β CStep (c_if bβ cβ cβ, st) (c_if bβ' cβ cβ, st)
| cs_ifTrue : β st cβ cβ,
CStep (c_if b_true cβ cβ, st) (cβ, st)
| cs_ifFalse : β st cβ cβ,
CStep (c_if b_false cβ cβ, st) (cβ, st)
| cs_while : β st bβ cβ,
CStep (c_while bβ cβ, st)
(c_if bβ (c_seq cβ (c_while bβ cβ)) c_skip, st)
namespace CImp
inductive Com : Type :=
| c_skip : Com
| c_asgn : String β AExp β Com
| c_seq : Com β Com β Com
| c_if : BExp β Com β Com β Com
| c_while : BExp β Com β Com
| c_par : Com β Com β Com
open Com
inductive CStep : (Com Γ State) β (Com Γ State) β Prop :=
| cs_asgnStep : β st v aβ aβ',
AStep st aβ aβ'
β CStep (c_asgn v aβ, st) (c_asgn v aβ', st)
| cs_asgn : β st v (n : Nat),
CStep (c_asgn v (a_num n), st) (c_skip, v !-> n; st)
| cs_seqStep : β st cβ cβ' st' cβ,
CStep (cβ, st) (cβ', st')
β CStep (c_seq cβ cβ, st) (c_seq cβ' cβ, st')
| cs_seqFinish : β st cβ,
CStep (c_seq c_skip cβ, st) (cβ, st)
| cs_ifStep : β st bβ bβ' cβ cβ,
BStep st bβ bβ'
β CStep (c_if bβ cβ cβ, st) (c_if bβ' cβ cβ, st)
| cs_ifTrue : β st cβ cβ,
CStep (c_if b_true cβ cβ, st) (cβ, st)
| cs_ifFalse : β st cβ cβ,
CStep (c_if b_false cβ cβ, st) (cβ, st)
| cs_while : β st bβ cβ,
CStep (c_while bβ cβ, st)
(c_if bβ (c_seq cβ (c_while bβ cβ)) c_skip, st)
| cs_par1 : β st cβ cβ' cβ st',
CStep (cβ, st) (cβ', st')
β CStep (c_par cβ cβ, st) (c_par cβ' cβ, st')
| cs_par2 : β st cβ cβ cβ' st',
CStep (cβ, st) (cβ', st')
β CStep (c_par cβ cβ, st) (c_par cβ cβ', st')
| cs_parDone : β st,
CStep (c_par c_skip c_skip, st) (c_skip, st)
open CStep
def par_loop : Com :=
c_par
(c_asgn y (a_num 1))
(c_while (b_eq (a_id y) (a_num 0))
(c_asgn x (a_plus (a_id x) (a_num 1))))
/-
In particular, it can terminate with `x` set to `0`.
-/
example : β st',
Multi CStep (par_loop, empty) (c_skip, st')
β§ st' x = 0 := | theorem par_body_n n st
: st x = 0 β§ st y = 0
β β st', Multi CStep (par_loop, st) (par_loop, st')
β§ st' x = n β§ st' y = 0 := | := by
intro h
obtain β¨hx, hyβ© := h
induction n with
| zero =>
exists st
apply And.intro
. apply multi_refl
. apply And.intro
. apply hx
. apply hy
| succ n' hn' =>
obtain β¨st', β¨h', β¨hx', hy'β©β©β© := hn'
constructor
apply And.intro
. apply multi_trans
. apply h'
. apply par_body_n__Sn
. apply And.intro
. exact hx'
. exact hy'
. apply And.intro
. rfl
. exact hy' | 3 | 24 | false | Semantics |
288 | Imp.Hoare.hoare_if | theorem hoare_if P Q b cβ cβ :
{* fun st => P st β§ beval st b *} cβ {* Q *}
β {* fun st => P st β§ Β¬(beval st b) *} cβ {* Q *}
β {* P *} c_if b cβ cβ {* Q *} | lean-formal-reasoning-program | Frap/Hoare.lean | [
"import Frap.Trans"
] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "String",
"module": "Init.Prelude"
},
{
"name": "Bool",
"module": "Init.Prelude"
}
] | [
{
"name": "syntax:21 \"if\" imp:20 \"then\" imp:20 \"else\" imp:20 \"end\" : im",
"content": "syntax:21 \"if\" imp:20 \"then\" imp:20 \"else\" imp:20 \"end\" : imp\n\nsyntax \"false\" : imp\n\nsyntax \"false\" : term\n\nsyntax \"true\" : imp\n\nsyntax \"true\" : term\n\nsyntax \"<{\" imp \"}>\" : term\n\nsyntax:30 \"{*\" term \"*}\" term \"{*\" term \"*}\" : term\n\nsyntax \"<[\" term \"]>\" : imp"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(term|true) => `(Bool.true)\n | `(term|false) => `(Bool.false)\n | `(term|<{$x}>) => `(imp|$x)\n | `(imp|$n:num) => `(a_num $n)\n | `(imp|$s:str) => `(a_id $s)\n | `(imp|$x + $y) => `(a_plus <{$x}> <{$y}>)\n | `(imp|$x - $y) => `(a_minus <{$x}> <{$y}>)\n | `(imp|$x * $y) => `(a_mult <{$x}> <{$y}>)\n | `(imp|true) => `(b_true)\n | `(imp|false) => `(b_false)\n | `(imp|$x = $y) => `(b_eq <{$x}> <{$y}>)\n | `(imp|$x != $y) => `(b_neq <{$x}> <{$y}>)\n | `(imp|$x <= $y) => `(b_le <{$x}> <{$y}>)\n | `(imp|!$x) => `(b_not <{$x}>)\n | `(imp|$x && $y) => `(b_and <{$x}> <{$y}>)\n | `(imp|$x || $y) => `(b_or <{$x}> <{$y}>)\n | `(imp|($x)) => `(<{$x}>)\n | `(imp|$x:ident) => `(a_id $(Lean.quote (toString x.getId)))\n | `(imp|<[$t:term]>) => pure t"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(imp|skip) => `(c_skip)\n | `(imp|$x:str := $y) => `(c_asgn $x <{$y}>)\n | `(imp|$x:ident := $y) => `(c_asgn $x <{$y}>)\n | `(imp|$c1 ; $c2) => `(c_seq <{$c1}> <{$c2}>)\n | `(imp|if $b then $c1 else $c2 end) => `(c_if <{$b}> <{$c1}> <{$c2}>)\n | `(imp|while $b do $c end) => `(c_while <{$b}> <{$c}>)"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(term|$p <<->> $q) => `($p ->> $q β§ $q ->> $p)"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(term|{*$p*} $c {*$q*}) => `(valid_hoare_triple $p $c $q)"
},
{
"name": "x",
"content": "abbrev x := \"x\""
},
{
"name": "Com",
"content": "inductive Com : Type :=\n | c_skip : Com\n | c_asgn : String β AExp β Com\n | c_seq : Com β Com β Com\n | c_if : BExp β Com β Com β Com\n | c_while : BExp β Com β Com\n | c_par : Com β Com β Com "
},
{
"name": "beval",
"content": "def beval (st : State) (b : BExp) : Bool :=\n match b with\n | b_true => true\n | b_false => false\n | b_eq aβ aβ => (aeval st aβ) == (aeval st aβ)\n | b_neq aβ aβ => (aeval st aβ) != (aeval st aβ)\n | b_le aβ aβ => (aeval st aβ) <= (aeval st aβ)\n | b_not bβ => not (beval st bβ)\n | b_and bβ bβ => and (beval st bβ) (beval st bβ)\n | b_or bβ bβ => or (beval st bβ) (beval st bβ)\n\nexample : aeval (update empty x 5)\n <{3 + x * 2}>\n \n = 13 := by admit /- proof elided -/"
},
{
"name": "empty",
"content": "def empty : State := fun _ => 0"
},
{
"name": "State",
"content": "abbrev State := String β Nat"
},
{
"name": "y",
"content": "abbrev y := \"y\""
},
{
"name": "z",
"content": "abbrev z := \"z\""
},
{
"name": "aeval",
"content": "def aeval (st : State) (a : AExp) : Nat :=\n match a with\n | a_num n => n\n | a_id x => st x\n | a_plus aβ aβ => (aeval st aβ) + (aeval st aβ)\n | a_minus aβ aβ => (aeval st aβ) - (aeval st aβ)\n | a_mult aβ aβ => (aeval st aβ) * (aeval st aβ)"
},
{
"name": "AExp",
"content": "inductive AExp where\n | a_num : Nat β AExp\n | a_id : String β AExp \n | a_plus : AExp β AExp β AExp\n | a_minus : AExp β AExp β AExp\n | a_mult : AExp β AExp β AExp"
},
{
"name": "AExp",
"content": "inductive AExp where\n | a_num : Nat β AExp\n | a_plus : AExp β AExp β AExp\n | a_minus : AExp β AExp β AExp\n | a_mult : AExp β AExp β AExp"
},
{
"name": "update",
"content": "def update (st : State) (k : String) (v : Nat) : State :=\n fun x => if x == k then v else st x"
},
{
"name": "BExp",
"content": "inductive BExp where\n | b_true : BExp\n | b_false : BExp\n | b_eq : AExp β AExp β BExp\n | b_neq : AExp β AExp β BExp\n | b_le : AExp β AExp β BExp\n | b_not : BExp β BExp\n | b_and : BExp β BExp β BExp\n | b_or : BExp β BExp β BExp"
},
{
"name": "Com",
"content": "inductive Com :=\n | c_skip : Com\n | c_asgn : String β AExp β Com\n | c_seq : Com β Com β Com\n | c_if : BExp β Com β Com β Com\n | c_while : BExp β Com β Com"
}
] | [
{
"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": "Imp.Hoare.Assertion",
"content": "abbrev Assertion := State β Prop"
},
{
"name": "Imp.Hoare.assert_implies",
"content": "def assert_implies (P Q : Assertion) : Prop :=\n β st, P st β Q st"
},
{
"name": "Imp.Hoare.valid_hoare_triple",
"content": "def valid_hoare_triple (P : Assertion) (c : Com) (Q : Assertion) : Prop :=\n β st st', P st β (st =[<[c]>]=> st') β Q st'"
}
] | [
{
"name": "Imp.Hoare.hoare_asgn",
"content": "theorem hoare_asgn Q x a :\n {* fun st => Q (st[x β¦ aeval st a]) *} c_asgn x a {* Q *}"
},
{
"name": "Imp.Hoare.hoare_consequence_pre",
"content": "theorem hoare_consequence_pre P P' Q c :\n {* P' *} c {* Q *}\n β P ->> P'\n β {* P *} c {* Q *}"
}
] | import Frap.Trans
namespace Imp
open AExp
open BExp
open Com
open CEval
namespace Hoare
abbrev Assertion := State β Prop
def assert_implies (P Q : Assertion) : Prop :=
β st, P st β Q st
infix:36 " ->> " => assert_implies
def valid_hoare_triple (P : Assertion) (c : Com) (Q : Assertion) : Prop :=
β st st', P st β (st =[<[c]>]=> st') β Q st' | theorem hoare_if P Q b cβ cβ :
{* fun st => P st β§ beval st b *} cβ {* Q *}
β {* fun st => P st β§ Β¬(beval st b) *} cβ {* Q *}
β {* P *} c_if b cβ cβ {* Q *} := | := by
intro hTrue hFalse st st' hPre hEval
cases hEval
. -- e_ifTrue
rename_i hb hcβ
apply hTrue
. constructor
. exact hPre
. exact hb
. exact hcβ
. -- e_ifFalse
rename_i hb hcβ
apply hFalse
. constructor
. exact hPre
. simp [hb]
. exact hcβ
example :
-- { True }
{* fun _ => True *}
<{if x = 0 then y := 2 else y := x + 1 end}>
-- { x β€ y }
{* fun st => st x <= st y *} := by
apply hoare_if
. apply hoare_consequence_pre
. apply hoare_asgn
. intro st _
simp [update] at *
split <;> simp [*]
. apply hoare_consequence_pre
. apply hoare_asgn
. intro st _
simp [update]
split
. simp [*]
. unfold x
omega | 4 | 21 | false | Semantics |
289 | Hidden.List.reverse_append | theorem reverse_append {Ξ± : Type u} (as bs : List Ξ±)
: reverse (as ++ bs) = reverse bs ++ reverse as | lean-formal-reasoning-program | Frap/Exercises/IndProp.lean | [] | [
{
"name": "structure BitVec (w : Nat) where",
"module": ""
},
{
"name": "/-- Construct a `BitVec w` from a number less than `2^w`.",
"module": ""
},
{
"name": "O(1), because we use `Fin` as the internal representation of a bitvector. -/",
"module": ""
},
{
"name": "ofFin ::",
"module": ""
},
{
"name": "/-- Interpret a bitvector as a number less than `2^w`.",
"module": ""
},
{
"name": "O(1), because we use `Fin` as the internal representation of a bitvector. -/",
"module": ""
},
{
"name": "toFin : Fin (hPow 2 w)",
"module": ""
}
] | [
{
"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": "Hidden.List",
"content": "inductive List (Ξ± : Type u) where\n | nil : List Ξ±\n | cons : Ξ± β List Ξ± β List Ξ±"
},
{
"name": "Hidden.List.reverse",
"content": "def reverse {Ξ± : Type u} (as : List Ξ±) : List Ξ± :=\n match as with\n | nil => nil\n | cons a as' => reverse as' ++ cons a nil"
}
] | [
{
"name": "Hidden.List.nil_append",
"content": "theorem nil_append (as : List Ξ±) : nil ++ as = as"
},
{
"name": "Hidden.List.cons_append",
"content": "theorem cons_append (a : Ξ±) (as bs : List Ξ±)\n : (cons a as) ++ bs = cons a (as ++ bs)"
},
{
"name": "Hidden.List.append_nil",
"content": "theorem append_nil (as : List Ξ±) : as ++ nil = as"
},
{
"name": "Hidden.List.append_assoc",
"content": "theorem append_assoc (as bs cs : List Ξ±)\n : (as ++ bs) ++ cs = as ++ (bs ++ cs)"
}
] | namespace Hidden
inductive List (Ξ± : Type u) where
| nil : List Ξ±
| cons : Ξ± β List Ξ± β List Ξ±
namespace List
def reverse {Ξ± : Type u} (as : List Ξ±) : List Ξ± :=
match as with
| nil => nil
| cons a as' => reverse as' ++ cons a nil | theorem reverse_append {Ξ± : Type u} (as bs : List Ξ±)
: reverse (as ++ bs) = reverse bs ++ reverse as := | := by
induction as with
| nil =>
rw [nil_append, reverse, append_nil]
| cons a as' ih =>
rw [cons_append, reverse, reverse, ih, append_assoc] | 2 | 7 | false | Semantics |
290 | and_associative | theorem and_associative (p q r : Prop) : (p β§ q) β§ r β p β§ (q β§ r) | lean-formal-reasoning-program | Frap/Propositional.lean | [] | [
{
"name": "Iff",
"module": "Init.Core"
}
] | [
{
"name": "Iff",
"content": "inductive Iff : Prop β Prop β Prop where\n | intro : (a β b) β (b β a) β Iff a b"
}
] | [
{
"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": "and_commutative",
"content": "theorem and_commutative (p q : Prop) : p β§ q β q β§ p"
}
] | import Mathlib.Computability.NFA
import Mathlib.Data.FinEnum
import Mathlib.Data.Rel
import Mathlib.Data.Vector.Basic
import Blase.AutoStructs.ForLean
open Set
open Mathlib
open SetRel
-- this is better because card is defeq to n
instance (Ξ± : Type) : Inter (Language Ξ±) := β¨Set.interβ©
instance (Ξ± : Type) : Union (Language Ξ±) := β¨Set.unionβ©
/--
The set of `n`-tuples of bit vectors of an arbitrary width.
-/
structure BitVecs (n : Nat) where
w : Nat
bvs : List.Vector (BitVec w) n
def BitVecs.cast (bvs : BitVecs n) (h : n = n') : BitVecs n' :=
{ w := bvs.w, bvs := h βΈ bvs.bvs }
abbrev BitVecs.empty : BitVecs n := β¨0, List.Vector.replicate n .nilβ©
abbrev BitVecs.singleton {w : Nat} (bv : BitVec w) : BitVecs 1 := β¨w, bv ::α΅₯ .nilβ©
abbrev BitVecs.pair {w : Nat} (bv1 bv2 : BitVec w) : BitVecs 2 := β¨w, bv1 ::α΅₯ bv2 ::α΅₯ .nilβ©
/--
The set of `n`-tuples of bit vectors of an arbitrary width, encoded as a list of
bit vectors of width `n`. The width of the encoded bit vectors is the length of
the list.
-/
abbrev BitVecs' (n : Nat) := List (BitVec n)
@[simps]
def dec (bvs' : BitVecs' n) : BitVecs n where
w := bvs'.length
bvs := List.Vector.ofFn fun k => BitVec.ofFn fun i => bvs'[i].getLsbD k
@[simp] | theorem and_associative (p q r : Prop) : (p β§ q) β§ r β p β§ (q β§ r) := | := by
constructor
. intro h
cases h with
| intro hpq hr =>
cases hpq with
| intro hp hq =>
apply And.intro
. exact hp
. apply And.intro
. exact hq
. exact hr
. intro h
cases h with
| intro hp hqr =>
cases hqr with
| intro hq hr =>
apply And.intro
. apply And.intro
. exact hp
. exact hq
. exact hr
/-
## Rewriting proof terms using previously proven results
Often in our proof, we'll need to use the same tactic sequence as in a prior proof.
Like in software development, duplicating the sequence results in duplicate code and can lead to maintenance problems.
We can refer to an earlier propeosition by simply writing the name of the theorem or lemma of interest.
This is similar to breaking down a large program into functions.
First, if we have a previously proven result, we can apply that result directly in the `apply` tactic.
-/
example (p q : Prop) : p β§ q β q β§ p := by
apply and_commutative
/-
We can even refer to asserted but unproven propositions.
-/
example (p q r : Prop) : (p β§ q) β§ r β p β§ (q β§ r) := by
apply and_associative
/-
For nested proof terms, we can use the `rewrite` tactic, along with a list of identities (equivalences) to apply to the proof goal or a hypothesis.
The syntax here is a bit complicated.
We need to pass a configuration stating which occurrence(s) of the proof term we want to rewrite.
An occurrence is a preorder position within the AST of the proof term, with 1 as the root (the entire proof term).
You might need to do some trial-and-error to get the desired occurrence.
Refer to the pop-up contextual guide for more information.
-/
example (p q r : Prop) : (p β§ q) β§ r β (q β§ p) β§ r := by
apply Iff.intro
. intro h
rewrite (config := {occs := .pos [2]}) [and_commutative] at h
assumption
. intro h
rewrite (config := {occs := .pos [2]}) [and_commutative] at h
assumption | 2 | 3 | false | Semantics |
291 | While.WellTyped.some_ty | theorem WellTyped.some_ty {e ty} : e.ty = some ty β WellTyped e ty | lean-hoare | Hoare/While/Types.lean | [
"import Hoare.While.Syntax"
] | [
{
"name": "DecidableEq",
"module": "Init.Prelude"
},
{
"name": "Repr",
"module": "Init.Data.Repr"
},
{
"name": "bool",
"module": "Init.Control.Basic"
},
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "Option.isSome",
"module": "Init.Data.Option.Basic"
}
] | [
{
"name": "syntax num : nexpr",
"content": "syntax num : nexpr\n\nsyntax \"if \" bexpr \" then \" com \" else \" com \" fi\" : com"
},
{
"name": "macro_rules",
"content": "macro_rules\n| `([nexpr| $n:num]) => `(Expr.num $n)\n| `([nexpr| $x:ident]) => `(Expr.var $(Lean.quote x.getId.toString))\n| `([bexpr| true]) => `(Expr.bool Β«trueΒ»)\n| `([bexpr| false]) => `(Expr.bool Β«falseΒ»)\n| `([nexpr| $e1 + $e2]) => `(Expr.add [nexpr| $e1] [nexpr| $e2])\n| `([nexpr| $e1 - $e2]) => `(Expr.sub [nexpr| $e1] [nexpr| $e2])\n| `([nexpr| $e1 * $e2]) => `(Expr.mul [nexpr| $e1] [nexpr| $e2])\n| `([bexpr| $e1:nexpr == $e2]) => `(Expr.eq [nexpr| $e1] [nexpr| $e2])\n| `([bexpr| $e1:nexpr < $e2]) => `(Expr.lt [nexpr| $e1] [nexpr| $e2])\n| `([bexpr| $e1:nexpr > $e2]) => `(Expr.gt [nexpr| $e1] [nexpr| $e2])\n| `([bexpr| $e1:nexpr <= $e2]) => `(Expr.le [nexpr| $e1] [nexpr| $e2])\n| `([bexpr| $e1:nexpr >= $e2]) => `(Expr.ge [nexpr| $e1] [nexpr| $e2])\n| `([bexpr| $e1:bexpr && $e2]) => `(Expr.and [bexpr| $e1] [bexpr| $e2])\n| `([bexpr| $e1:bexpr || $e2]) => `(Expr.or [bexpr| $e1] [bexpr| $e2])\n| `([bexpr| ($e)]) => `([bexpr| $e])\n| `([nexpr| ($e)]) => `([nexpr| $e])\n| `([com| skip]) => `(Com.skip)\n| `([com| let $x:ident := $e]) => `(Com.assign $(Lean.quote x.getId.toString) [nexpr| $e])\n| `([com| $x:ident := $e]) => `(Com.assign $(Lean.quote x.getId.toString) [nexpr| $e])\n| `([com| $c1; $c2]) => `(Com.seq [com| $c1] [com| $c2])\n| `([com| if $e then $c1 else $c2 fi]) => `(Com.cond [bexpr| $e] [com| $c1] [com| $c2])\n| `([com| while $e do $c od]) => `(Com.while [bexpr| $e] [com| $c])"
},
{
"name": "macro_rules",
"content": "macro_rules\n| `([bexpr| $($t:term)]) => `($t)\n| `([nexpr| $($t:term)]) => `($t)\n| `([com| $($t:term)]) => `($t)"
},
{
"name": "Expr.ty",
"content": "def Expr.ty : Expr β Option Ty\n | Expr.num _ => Ty.num\n | Expr.bool _ => Ty.bool\n | Expr.add e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .num else none\n | Expr.sub e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .num else none\n | Expr.mul e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .num else none\n | Expr.eq e1 e2 => if e1.ty = e2.ty β§ e1.ty.isSome then some .bool else none\n | Expr.lt e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .bool else none\n | Expr.gt e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .bool else none\n | Expr.le e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .bool else none\n | Expr.ge e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .bool else none\n | Expr.and e1 e2 => if e1.ty = some .bool β§ e2.ty = some .bool then some .bool else none\n | Expr.or e1 e2 => if e1.ty = some .bool β§ e2.ty = some .bool then some .bool else none\n | Expr.var _ => none "
},
{
"name": "Com",
"content": "inductive Com\n| assign : String β Expr β Com\n| seq : Com β Com β Com\n| cond : Expr β Com β Com β Com\n| while : Expr β Com β Com\n| skip : Com"
},
{
"name": "Expr",
"content": "inductive Expr\n| num : Nat β Expr\n| bool : Bool β Expr\n| var : String β Expr\n| add : Expr β Expr β Expr\n| sub : Expr β Expr β Expr\n| mul : Expr β Expr β Expr\n| eq : Expr β Expr β Expr\n| lt : Expr β Expr β Expr\n| gt : Expr β Expr β Expr\n| le : Expr β Expr β Expr\n| ge : Expr β Expr β Expr\n| and : Expr β Expr β Expr\n| or : Expr β Expr β Expr\nderiving Repr, DecidableEq"
}
] | [
{
"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": "While.Ty",
"content": "inductive Ty\n| num : Ty\n| bool : Ty\nderiving Repr, DecidableEq"
},
{
"name": "While.WellTyped",
"content": "inductive WellTyped : Expr β Ty β Prop\n| num : WellTyped (Expr.num _) Ty.num\n| bool : WellTyped (Expr.bool _) Ty.bool\n| add : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.add e1 e2) Ty.num\n| sub : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.sub e1 e2) Ty.num\n| mul : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.mul e1 e2) Ty.num\n| eq : β e1 e2 t, WellTyped e1 t β WellTyped e2 t β\n WellTyped (Expr.eq e1 e2) Ty.bool\n| lt : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.lt e1 e2) Ty.bool\n| gt : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.gt e1 e2) Ty.bool\n| le : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.le e1 e2) Ty.bool\n| ge : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.ge e1 e2) Ty.bool\n| and : β e1 e2, WellTyped e1 Ty.bool β WellTyped e2 Ty.bool β\n WellTyped (Expr.and e1 e2) Ty.bool\n| or : β e1 e2, WellTyped e1 Ty.bool β WellTyped e2 Ty.bool β\n WellTyped (Expr.or e1 e2) Ty.bool"
},
{
"name": "While.Expr.ty",
"content": "def Expr.ty : Expr β Option Ty\n | Expr.num _ => Ty.num\n | Expr.bool _ => Ty.bool\n | Expr.add e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .num else none\n | Expr.sub e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .num else none\n | Expr.mul e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .num else none\n | Expr.eq e1 e2 => if e1.ty = e2.ty β§ e1.ty.isSome then some .bool else none\n | Expr.lt e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .bool else none\n | Expr.gt e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .bool else none\n | Expr.le e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .bool else none\n | Expr.ge e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .bool else none\n | Expr.and e1 e2 => if e1.ty = some .bool β§ e2.ty = some .bool then some .bool else none\n | Expr.or e1 e2 => if e1.ty = some .bool β§ e2.ty = some .bool then some .bool else none\n | Expr.var _ => none"
}
] | [
{
"name": "While.WellTyped.ty_some",
"content": "theorem WellTyped.ty_some {e ty} : WellTyped e ty β e.ty = some ty"
}
] | import Hoare.While.Syntax
namespace While
inductive Ty
| num : Ty
| bool : Ty
deriving Repr, DecidableEq
inductive WellTyped : Expr β Ty β Prop
| num : WellTyped (Expr.num _) Ty.num
| bool : WellTyped (Expr.bool _) Ty.bool
| add : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β
WellTyped (Expr.add e1 e2) Ty.num
| sub : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β
WellTyped (Expr.sub e1 e2) Ty.num
| mul : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β
WellTyped (Expr.mul e1 e2) Ty.num
| eq : β e1 e2 t, WellTyped e1 t β WellTyped e2 t β
WellTyped (Expr.eq e1 e2) Ty.bool
| lt : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β
WellTyped (Expr.lt e1 e2) Ty.bool
| gt : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β
WellTyped (Expr.gt e1 e2) Ty.bool
| le : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β
WellTyped (Expr.le e1 e2) Ty.bool
| ge : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β
WellTyped (Expr.ge e1 e2) Ty.bool
| and : β e1 e2, WellTyped e1 Ty.bool β WellTyped e2 Ty.bool β
WellTyped (Expr.and e1 e2) Ty.bool
| or : β e1 e2, WellTyped e1 Ty.bool β WellTyped e2 Ty.bool β
WellTyped (Expr.or e1 e2) Ty.bool
def Expr.ty : Expr β Option Ty
| Expr.num _ => Ty.num
| Expr.bool _ => Ty.bool
| Expr.add e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .num else none
| Expr.sub e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .num else none
| Expr.mul e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .num else none
| Expr.eq e1 e2 => if e1.ty = e2.ty β§ e1.ty.isSome then some .bool else none
| Expr.lt e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .bool else none
| Expr.gt e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .bool else none
| Expr.le e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .bool else none
| Expr.ge e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .bool else none
| Expr.and e1 e2 => if e1.ty = some .bool β§ e2.ty = some .bool then some .bool else none
| Expr.or e1 e2 => if e1.ty = some .bool β§ e2.ty = some .bool then some .bool else none
| Expr.var _ => none | theorem WellTyped.some_ty {e ty} : e.ty = some ty β WellTyped e ty := | := by
intro h
induction e generalizing ty <;> simp_all [Expr.ty]
case num _ => rw [β h]; exact WellTyped.num
case bool _ => rw [β h]; exact WellTyped.bool
case add e1 e2 ih_e1 ih_e2 =>
have h' := h.2.symm; subst h'; exact WellTyped.add e1 e2 ih_e1 ih_e2
case sub e1 e2 ih_e1 ih_e2 =>
have h' := h.2.symm; subst h'; exact WellTyped.sub e1 e2 ih_e1 ih_e2
case mul e1 e2 ih_e1 ih_e2 =>
have h' := h.2.symm; subst h'; exact WellTyped.mul e1 e2 ih_e1 ih_e2
case eq e1 e2 ih_e1 ih_e2 =>
have h' := h.2.symm; subst h'
match hty : e1.ty with
| some .num => have hty' := h.1.1.symm; rw [hty] at hty'; exact WellTyped.eq e1 e2 .num (ih_e1 hty') (ih_e2 hty')
| some .bool => have hty' := h.1.1.symm; rw [hty] at hty'; exact WellTyped.eq e1 e2 .bool (ih_e1 hty') (ih_e2 hty')
| none => rw [hty] at h; have hc := h.1.2; simp [Option.isSome] at hc
case lt e1 e2 ih_e1 ih_e2 =>
have h' := h.2.symm; subst h'; exact WellTyped.lt e1 e2 ih_e1 ih_e2
case gt e1 e2 ih_e1 ih_e2 =>
have h' := h.2.symm; subst h'; exact WellTyped.gt e1 e2 ih_e1 ih_e2
case le e1 e2 ih_e1 ih_e2 =>
have h' := h.2.symm; subst h'; exact WellTyped.le e1 e2 ih_e1 ih_e2
case ge e1 e2 ih_e1 ih_e2 =>
have h' := h.2.symm; subst h'; exact WellTyped.ge e1 e2 ih_e1 ih_e2
case and e1 e2 ih_e1 ih_e2 =>
have h' := h.2.symm; subst h'; exact WellTyped.and e1 e2 ih_e1 ih_e2
case or e1 e2 ih_e1 ih_e2 =>
have h' := h.2.symm; subst h'; exact WellTyped.or e1 e2 ih_e1 ih_e2 | 3 | 13 | false | Semantics |
292 | While.WellTyped.ty_some | theorem WellTyped.ty_some {e ty} : WellTyped e ty β e.ty = some ty | lean-hoare | Hoare/While/Types.lean | [
"import Hoare.While.Syntax"
] | [
{
"name": "DecidableEq",
"module": "Init.Prelude"
},
{
"name": "Repr",
"module": "Init.Data.Repr"
},
{
"name": "bool",
"module": "Init.Control.Basic"
},
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "Option.isSome",
"module": "Init.Data.Option.Basic"
}
] | [
{
"name": "syntax num : nexpr",
"content": "syntax num : nexpr\n\nsyntax \"if \" bexpr \" then \" com \" else \" com \" fi\" : com"
},
{
"name": "macro_rules",
"content": "macro_rules\n| `([nexpr| $n:num]) => `(Expr.num $n)\n| `([nexpr| $x:ident]) => `(Expr.var $(Lean.quote x.getId.toString))\n| `([bexpr| true]) => `(Expr.bool Β«trueΒ»)\n| `([bexpr| false]) => `(Expr.bool Β«falseΒ»)\n| `([nexpr| $e1 + $e2]) => `(Expr.add [nexpr| $e1] [nexpr| $e2])\n| `([nexpr| $e1 - $e2]) => `(Expr.sub [nexpr| $e1] [nexpr| $e2])\n| `([nexpr| $e1 * $e2]) => `(Expr.mul [nexpr| $e1] [nexpr| $e2])\n| `([bexpr| $e1:nexpr == $e2]) => `(Expr.eq [nexpr| $e1] [nexpr| $e2])\n| `([bexpr| $e1:nexpr < $e2]) => `(Expr.lt [nexpr| $e1] [nexpr| $e2])\n| `([bexpr| $e1:nexpr > $e2]) => `(Expr.gt [nexpr| $e1] [nexpr| $e2])\n| `([bexpr| $e1:nexpr <= $e2]) => `(Expr.le [nexpr| $e1] [nexpr| $e2])\n| `([bexpr| $e1:nexpr >= $e2]) => `(Expr.ge [nexpr| $e1] [nexpr| $e2])\n| `([bexpr| $e1:bexpr && $e2]) => `(Expr.and [bexpr| $e1] [bexpr| $e2])\n| `([bexpr| $e1:bexpr || $e2]) => `(Expr.or [bexpr| $e1] [bexpr| $e2])\n| `([bexpr| ($e)]) => `([bexpr| $e])\n| `([nexpr| ($e)]) => `([nexpr| $e])\n| `([com| skip]) => `(Com.skip)\n| `([com| let $x:ident := $e]) => `(Com.assign $(Lean.quote x.getId.toString) [nexpr| $e])\n| `([com| $x:ident := $e]) => `(Com.assign $(Lean.quote x.getId.toString) [nexpr| $e])\n| `([com| $c1; $c2]) => `(Com.seq [com| $c1] [com| $c2])\n| `([com| if $e then $c1 else $c2 fi]) => `(Com.cond [bexpr| $e] [com| $c1] [com| $c2])\n| `([com| while $e do $c od]) => `(Com.while [bexpr| $e] [com| $c])"
},
{
"name": "macro_rules",
"content": "macro_rules\n| `([bexpr| $($t:term)]) => `($t)\n| `([nexpr| $($t:term)]) => `($t)\n| `([com| $($t:term)]) => `($t)"
},
{
"name": "Expr.ty",
"content": "def Expr.ty : Expr β Option Ty\n | Expr.num _ => Ty.num\n | Expr.bool _ => Ty.bool\n | Expr.add e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .num else none\n | Expr.sub e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .num else none\n | Expr.mul e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .num else none\n | Expr.eq e1 e2 => if e1.ty = e2.ty β§ e1.ty.isSome then some .bool else none\n | Expr.lt e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .bool else none\n | Expr.gt e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .bool else none\n | Expr.le e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .bool else none\n | Expr.ge e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .bool else none\n | Expr.and e1 e2 => if e1.ty = some .bool β§ e2.ty = some .bool then some .bool else none\n | Expr.or e1 e2 => if e1.ty = some .bool β§ e2.ty = some .bool then some .bool else none\n | Expr.var _ => none "
},
{
"name": "Com",
"content": "inductive Com\n| assign : String β Expr β Com\n| seq : Com β Com β Com\n| cond : Expr β Com β Com β Com\n| while : Expr β Com β Com\n| skip : Com"
},
{
"name": "Expr",
"content": "inductive Expr\n| num : Nat β Expr\n| bool : Bool β Expr\n| var : String β Expr\n| add : Expr β Expr β Expr\n| sub : Expr β Expr β Expr\n| mul : Expr β Expr β Expr\n| eq : Expr β Expr β Expr\n| lt : Expr β Expr β Expr\n| gt : Expr β Expr β Expr\n| le : Expr β Expr β Expr\n| ge : Expr β Expr β Expr\n| and : Expr β Expr β Expr\n| or : Expr β Expr β Expr\nderiving Repr, DecidableEq"
}
] | [
{
"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": "While.Ty",
"content": "inductive Ty\n| num : Ty\n| bool : Ty\nderiving Repr, DecidableEq"
},
{
"name": "While.WellTyped",
"content": "inductive WellTyped : Expr β Ty β Prop\n| num : WellTyped (Expr.num _) Ty.num\n| bool : WellTyped (Expr.bool _) Ty.bool\n| add : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.add e1 e2) Ty.num\n| sub : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.sub e1 e2) Ty.num\n| mul : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.mul e1 e2) Ty.num\n| eq : β e1 e2 t, WellTyped e1 t β WellTyped e2 t β\n WellTyped (Expr.eq e1 e2) Ty.bool\n| lt : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.lt e1 e2) Ty.bool\n| gt : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.gt e1 e2) Ty.bool\n| le : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.le e1 e2) Ty.bool\n| ge : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.ge e1 e2) Ty.bool\n| and : β e1 e2, WellTyped e1 Ty.bool β WellTyped e2 Ty.bool β\n WellTyped (Expr.and e1 e2) Ty.bool\n| or : β e1 e2, WellTyped e1 Ty.bool β WellTyped e2 Ty.bool β\n WellTyped (Expr.or e1 e2) Ty.bool"
},
{
"name": "While.Expr.ty",
"content": "def Expr.ty : Expr β Option Ty\n | Expr.num _ => Ty.num\n | Expr.bool _ => Ty.bool\n | Expr.add e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .num else none\n | Expr.sub e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .num else none\n | Expr.mul e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .num else none\n | Expr.eq e1 e2 => if e1.ty = e2.ty β§ e1.ty.isSome then some .bool else none\n | Expr.lt e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .bool else none\n | Expr.gt e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .bool else none\n | Expr.le e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .bool else none\n | Expr.ge e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .bool else none\n | Expr.and e1 e2 => if e1.ty = some .bool β§ e2.ty = some .bool then some .bool else none\n | Expr.or e1 e2 => if e1.ty = some .bool β§ e2.ty = some .bool then some .bool else none\n | Expr.var _ => none"
}
] | [] | import Hoare.While.Syntax
namespace While
inductive Ty
| num : Ty
| bool : Ty
deriving Repr, DecidableEq
inductive WellTyped : Expr β Ty β Prop
| num : WellTyped (Expr.num _) Ty.num
| bool : WellTyped (Expr.bool _) Ty.bool
| add : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β
WellTyped (Expr.add e1 e2) Ty.num
| sub : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β
WellTyped (Expr.sub e1 e2) Ty.num
| mul : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β
WellTyped (Expr.mul e1 e2) Ty.num
| eq : β e1 e2 t, WellTyped e1 t β WellTyped e2 t β
WellTyped (Expr.eq e1 e2) Ty.bool
| lt : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β
WellTyped (Expr.lt e1 e2) Ty.bool
| gt : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β
WellTyped (Expr.gt e1 e2) Ty.bool
| le : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β
WellTyped (Expr.le e1 e2) Ty.bool
| ge : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β
WellTyped (Expr.ge e1 e2) Ty.bool
| and : β e1 e2, WellTyped e1 Ty.bool β WellTyped e2 Ty.bool β
WellTyped (Expr.and e1 e2) Ty.bool
| or : β e1 e2, WellTyped e1 Ty.bool β WellTyped e2 Ty.bool β
WellTyped (Expr.or e1 e2) Ty.bool
def Expr.ty : Expr β Option Ty
| Expr.num _ => Ty.num
| Expr.bool _ => Ty.bool
| Expr.add e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .num else none
| Expr.sub e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .num else none
| Expr.mul e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .num else none
| Expr.eq e1 e2 => if e1.ty = e2.ty β§ e1.ty.isSome then some .bool else none
| Expr.lt e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .bool else none
| Expr.gt e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .bool else none
| Expr.le e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .bool else none
| Expr.ge e1 e2 => if e1.ty = some .num β§ e2.ty = some .num then some .bool else none
| Expr.and e1 e2 => if e1.ty = some .bool β§ e2.ty = some .bool then some .bool else none
| Expr.or e1 e2 => if e1.ty = some .bool β§ e2.ty = some .bool then some .bool else none
| Expr.var _ => none | theorem WellTyped.ty_some {e ty} : WellTyped e ty β e.ty = some ty := | :=
by
intro h
induction h
case num => rfl
case bool => rfl
case add _ _ h1 h2 => simp [Expr.ty, h1, h2]
case sub _ _ h1 h2 => simp [Expr.ty, h1, h2]
case mul _ _ h1 h2 => simp [Expr.ty, h1, h2]
case eq e1 _ _ h1 h2 => simp [Expr.ty, h1, h2]
case lt _ _ h1 h2 => simp [Expr.ty, h1, h2]
case gt _ _ h1 h2 => simp [Expr.ty, h1, h2]
case le _ _ h1 h2 => simp [Expr.ty, h1, h2]
case ge _ _ h1 h2 => simp [Expr.ty, h1, h2]
case and _ _ h1 h2 => simp [Expr.ty, h1, h2]
case or _ _ h1 h2 => simp [Expr.ty, h1, h2] | 4 | 13 | false | Semantics |
293 | While.WellTyped.not_eq_not_eq_ty | theorem WellTyped.not_eq_not_eq_ty {e1 e2 : Expr} {t1 t2 : Ty} :
WellTyped e1 t1 β WellTyped e2 t2 β t1 β t2 β β t, Β¬ (WellTyped (Expr.eq e1 e2) t) | lean-hoare | Hoare/While/Types.lean | [
"import Hoare.While.Syntax"
] | [
{
"name": "DecidableEq",
"module": "Init.Prelude"
},
{
"name": "Repr",
"module": "Init.Data.Repr"
},
{
"name": "bool",
"module": "Init.Control.Basic"
}
] | [
{
"name": "Expr",
"content": "inductive Expr\n| num : Nat β Expr\n| bool : Bool β Expr\n| var : String β Expr\n| add : Expr β Expr β Expr\n| sub : Expr β Expr β Expr\n| mul : Expr β Expr β Expr\n| eq : Expr β Expr β Expr\n| lt : Expr β Expr β Expr\n| gt : Expr β Expr β Expr\n| le : Expr β Expr β Expr\n| ge : Expr β Expr β Expr\n| and : Expr β Expr β Expr\n| or : Expr β Expr β Expr\nderiving Repr, DecidableEq"
},
{
"name": "WellTyped",
"content": "inductive WellTyped : Expr β Ty β Prop\n| num : WellTyped (Expr.num _) Ty.num\n| bool : WellTyped (Expr.bool _) Ty.bool\n| add : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.add e1 e2) Ty.num\n| sub : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.sub e1 e2) Ty.num\n| mul : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.mul e1 e2) Ty.num\n| eq : β e1 e2 t, WellTyped e1 t β WellTyped e2 t β\n WellTyped (Expr.eq e1 e2) Ty.bool\n| lt : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.lt e1 e2) Ty.bool\n| gt : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.gt e1 e2) Ty.bool\n| le : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.le e1 e2) Ty.bool\n| ge : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.ge e1 e2) Ty.bool\n| and : β e1 e2, WellTyped e1 Ty.bool β WellTyped e2 Ty.bool β\n WellTyped (Expr.and e1 e2) Ty.bool\n| or : β e1 e2, WellTyped e1 Ty.bool β WellTyped e2 Ty.bool β\n WellTyped (Expr.or e1 e2) Ty.bool"
}
] | [
{
"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": "While.Ty",
"content": "inductive Ty\n| num : Ty\n| bool : Ty\nderiving Repr, DecidableEq"
},
{
"name": "While.WellTyped",
"content": "inductive WellTyped : Expr β Ty β Prop\n| num : WellTyped (Expr.num _) Ty.num\n| bool : WellTyped (Expr.bool _) Ty.bool\n| add : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.add e1 e2) Ty.num\n| sub : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.sub e1 e2) Ty.num\n| mul : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.mul e1 e2) Ty.num\n| eq : β e1 e2 t, WellTyped e1 t β WellTyped e2 t β\n WellTyped (Expr.eq e1 e2) Ty.bool\n| lt : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.lt e1 e2) Ty.bool\n| gt : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.gt e1 e2) Ty.bool\n| le : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.le e1 e2) Ty.bool\n| ge : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.ge e1 e2) Ty.bool\n| and : β e1 e2, WellTyped e1 Ty.bool β WellTyped e2 Ty.bool β\n WellTyped (Expr.and e1 e2) Ty.bool\n| or : β e1 e2, WellTyped e1 Ty.bool β WellTyped e2 Ty.bool β\n WellTyped (Expr.or e1 e2) Ty.bool"
}
] | [
{
"name": "While.WellTyped.unique",
"content": "theorem WellTyped.unique : β {e t1 t2}, WellTyped e t1 β WellTyped e t2 β t1 = t2"
}
] | import Hoare.While.Syntax
namespace While
inductive Ty
| num : Ty
| bool : Ty
deriving Repr, DecidableEq | theorem WellTyped.not_eq_not_eq_ty {e1 e2 : Expr} {t1 t2 : Ty} :
WellTyped e1 t1 β WellTyped e2 t2 β t1 β t2 β β t, Β¬ (WellTyped (Expr.eq e1 e2) t) := | := by
intro h1 h2 h3 t h4
cases h4
Β· case eq t h1' h2' =>
have ht1 : t1 = t := WellTyped.unique h1 h1'
have ht2 : t2 = t := WellTyped.unique h2 h2'
rw [ht1, ht2] at h3
contradiction | 2 | 6 | false | Semantics |
294 | While.WellTyped.not_welltyped_not_eq_ty | theorem WellTyped.not_welltyped_not_eq_ty {e1 e2 : Expr} {t : Ty} :
WellTyped e1 t β Β¬ WellTyped e2 t β β t', Β¬ (WellTyped (Expr.eq e1 e2) t') | lean-hoare | Hoare/While/Types.lean | [
"import Hoare.While.Syntax"
] | [
{
"name": "DecidableEq",
"module": "Init.Prelude"
},
{
"name": "Repr",
"module": "Init.Data.Repr"
},
{
"name": "bool",
"module": "Init.Control.Basic"
}
] | [
{
"name": "Expr",
"content": "inductive Expr\n| num : Nat β Expr\n| bool : Bool β Expr\n| var : String β Expr\n| add : Expr β Expr β Expr\n| sub : Expr β Expr β Expr\n| mul : Expr β Expr β Expr\n| eq : Expr β Expr β Expr\n| lt : Expr β Expr β Expr\n| gt : Expr β Expr β Expr\n| le : Expr β Expr β Expr\n| ge : Expr β Expr β Expr\n| and : Expr β Expr β Expr\n| or : Expr β Expr β Expr\nderiving Repr, DecidableEq"
},
{
"name": "WellTyped",
"content": "inductive WellTyped : Expr β Ty β Prop\n| num : WellTyped (Expr.num _) Ty.num\n| bool : WellTyped (Expr.bool _) Ty.bool\n| add : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.add e1 e2) Ty.num\n| sub : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.sub e1 e2) Ty.num\n| mul : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.mul e1 e2) Ty.num\n| eq : β e1 e2 t, WellTyped e1 t β WellTyped e2 t β\n WellTyped (Expr.eq e1 e2) Ty.bool\n| lt : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.lt e1 e2) Ty.bool\n| gt : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.gt e1 e2) Ty.bool\n| le : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.le e1 e2) Ty.bool\n| ge : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.ge e1 e2) Ty.bool\n| and : β e1 e2, WellTyped e1 Ty.bool β WellTyped e2 Ty.bool β\n WellTyped (Expr.and e1 e2) Ty.bool\n| or : β e1 e2, WellTyped e1 Ty.bool β WellTyped e2 Ty.bool β\n WellTyped (Expr.or e1 e2) Ty.bool"
}
] | [
{
"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": "While.Ty",
"content": "inductive Ty\n| num : Ty\n| bool : Ty\nderiving Repr, DecidableEq"
},
{
"name": "While.WellTyped",
"content": "inductive WellTyped : Expr β Ty β Prop\n| num : WellTyped (Expr.num _) Ty.num\n| bool : WellTyped (Expr.bool _) Ty.bool\n| add : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.add e1 e2) Ty.num\n| sub : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.sub e1 e2) Ty.num\n| mul : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.mul e1 e2) Ty.num\n| eq : β e1 e2 t, WellTyped e1 t β WellTyped e2 t β\n WellTyped (Expr.eq e1 e2) Ty.bool\n| lt : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.lt e1 e2) Ty.bool\n| gt : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.gt e1 e2) Ty.bool\n| le : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.le e1 e2) Ty.bool\n| ge : β e1 e2, WellTyped e1 Ty.num β WellTyped e2 Ty.num β\n WellTyped (Expr.ge e1 e2) Ty.bool\n| and : β e1 e2, WellTyped e1 Ty.bool β WellTyped e2 Ty.bool β\n WellTyped (Expr.and e1 e2) Ty.bool\n| or : β e1 e2, WellTyped e1 Ty.bool β WellTyped e2 Ty.bool β\n WellTyped (Expr.or e1 e2) Ty.bool"
}
] | [
{
"name": "While.WellTyped.unique",
"content": "theorem WellTyped.unique : β {e t1 t2}, WellTyped e t1 β WellTyped e t2 β t1 = t2"
}
] | import Hoare.While.Syntax
namespace While
inductive Ty
| num : Ty
| bool : Ty
deriving Repr, DecidableEq | theorem WellTyped.not_welltyped_not_eq_ty {e1 e2 : Expr} {t : Ty} :
WellTyped e1 t β Β¬ WellTyped e2 t β β t', Β¬ (WellTyped (Expr.eq e1 e2) t') := | := by
intro h1 h2 t' h3
cases h3
Β· case eq t' h1' h2' =>
have ht : t = t' := WellTyped.unique h1 h1'
apply h2
rw [ht]
exact h2' | 2 | 6 | false | Semantics |
295 | processOneElem_spec | omit [Fintype S] in
lemma processOneElem_spec {st : worklist.St A S} (s : State) (sa : S) (k : β) :
β a sa', (f sa)[k]? = some (a, sa') β
processOneElem_mot inits final f s sa k st β
processOneElem_mot inits final f s sa (k+1) (processOneElem A S final s st (a, sa')) | lean-mlir | Blase/Blase/AutoStructs/Worklist.lean | [
"import Blase.Blase.AutoStructs.Basic",
"import Blase.Blase.AutoStructs.ForLean",
"import Blase.AutoStructs.Basic"
] | [
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "BEq",
"module": "Init.Prelude"
},
{
"name": "DecidableEq",
"module": "Init.Prelude"
},
{
"name": "FinEnum",
"module": "Mathlib.Data.FinEnum"
},
{
"name": "Hashable",
"module": "Init.Prelude"
},
{
"name": "Repr",
"module": "Init.Data.Repr"
},
{
"name": "Std.HashMap",
"module": "Std.Data.HashMap.Basic"
},
{
"name": "Std.HashSet",
"module": "Std.Data.HashSet.Basic"
},
{
"name": "Array",
"module": "Init.Prelude"
},
{
"name": "List.map",
"module": "Init.Prelude"
},
{
"name": "SetRel",
"module": "Mathlib.Data.Rel"
},
{
"name": "Set",
"module": "Mathlib.Data.Set.Defs"
},
{
"name": "NFA",
"module": "Mathlib.Computability.NFA"
},
{
"name": "Bool",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Finset",
"module": "Mathlib.Data.Finset.Defs"
},
{
"name": "Option",
"module": "Init.Prelude"
},
{
"name": "Prod",
"module": "Init.Prelude"
},
{
"name": "Prod.mk",
"module": "Init.Prelude"
},
{
"name": "Finset.range",
"module": "Mathlib.Data.Finset.Range"
},
{
"name": "Fintype",
"module": "Mathlib.Data.Fintype.Defs"
},
{
"name": "SetRel.inv",
"module": "Mathlib.Data.Rel"
},
{
"name": "LawfulBEq",
"module": "Init.Core"
},
{
"name": "List.next",
"module": "Mathlib.Data.List.Cycle"
},
{
"name": "LawfulHashable",
"module": "Init.Data.LawfulHashable"
},
{
"name": "Inhabited",
"module": "Init.Prelude"
},
{
"name": "List.insert",
"module": "Init.Data.List.Basic"
}
] | [
{
"name": "RawCNFA.statesFinset",
"content": "instance RawCNFA.statesFinset (m : RawCNFA A) : Fintype m.states := (Finset.range m.stateMax).fintypeCoeSort"
},
{
"name": "State",
"content": "abbrev State := Nat"
},
{
"name": "RawCNFA.WF",
"content": "structure RawCNFA.WF (m : RawCNFA A) where\n initials_lt : β {s}, s β m.initials β s β m.states\n finals_lt : β {s}, s β m.finals β s β m.states\n trans_src_lt : β s_a β m.trans, s_a.1 β m.states\n trans_tgt_lt : s' β m.tr s a β s' β m.states"
},
{
"name": "RawCNFA.tr",
"content": "@[inline]\ndef RawCNFA.tr (m : RawCNFA A) s a := m.trans.getD (s, a) β
"
},
{
"name": "RawCNFA.states",
"content": "def RawCNFA.states (m : RawCNFA A) : Finset State := Finset.range m.stateMax"
},
{
"name": "RawCNFA.addFinal",
"content": "def RawCNFA.addFinal (m : RawCNFA A) (s : State) : RawCNFA A :=\n { m with finals := m.finals.insert s }"
},
{
"name": "RawCNFA.newState",
"content": "def RawCNFA.newState (m : RawCNFA A) : State Γ RawCNFA A :=\n let old := m.stateMax\n let m := { m with stateMax := old + 1 }\n (old, m)"
},
{
"name": "RawCNFA.addTrans",
"content": "def RawCNFA.addTrans (m : RawCNFA A) (a : A) (s s' : State) : RawCNFA A :=\n let ns := m.trans.getD (s, a) β
\n let ns := ns.insert s'\n { m with trans := m.trans.insert (s, a) ns }"
}
] | [
{
"name": "Std.HashMap.getElem?_insert",
"module": "Std.Data.HashMap.Lemmas"
},
{
"name": "getElem?_eq_none_iff",
"module": "Init.GetElem"
},
{
"name": "Set.mem_setOf_eq",
"module": "Mathlib.Data.Set.Operations"
},
{
"name": "true_and",
"module": "Init.SimpLemmas"
},
{
"name": "Array.mem_of_getElem?",
"module": "Init.Data.Array.Lemmas"
},
{
"name": "Prod.mk.eta",
"module": "Mathlib.Data.Prod.Basic"
},
{
"name": "Std.HashSet.mem_insert",
"module": "Std.Data.HashSet.Lemmas"
},
{
"name": "beq_iff_eq",
"module": "Init.Core"
},
{
"name": "ge_iff_le",
"module": "Init.Core"
},
{
"name": "not_and",
"module": "Init.SimpLemmas"
},
{
"name": "not_exists",
"module": "Init.PropLemmas"
},
{
"name": "or_true",
"module": "Init.SimpLemmas"
},
{
"name": "true_or",
"module": "Init.SimpLemmas"
}
] | [
{
"name": "Std.HashMap.get?_none_not_mem",
"content": "@[aesop 50% unsafe]\ntheorem Std.HashMap.get?_none_not_mem [BEq K] [LawfulBEq K] [Hashable K] [LawfulHashable K] {m : Std.HashMap K V} {k : K} : m.get? k = none β k β m"
},
{
"name": "Std.HashMap.mem_of_getElem?",
"content": "@[aesop 50% unsafe]\ntheorem Std.HashMap.mem_of_getElem? [BEq K] [LawfulBEq K] [Hashable K] [LawfulHashable K] {m : Std.HashMap K V} {k : K} :\n m[k]? = some v β k β m"
},
{
"name": "Std.HashMap.mem_iff_getElem?",
"content": "theorem Std.HashMap.mem_iff_getElem? [BEq K] [LawfulBEq K] [Hashable K] [LawfulHashable K] [Inhabited V] {m : Std.HashMap K V} {k : K} :\n k β m β β v, m[k]? = some v"
},
{
"name": "addTrans_tr_eq",
"content": "@[grind =, simp]\nlemma addTrans_tr_eq (m : RawCNFA A) [LawfulBEq A] (a : A) (sβ sβ : State) :\n (m.addTrans a sβ sβ).tr sβ a = (m.tr sβ a).insert sβ"
},
{
"name": "@[grind =] -- TODO: should I?",
"content": "@[grind =] -- TODO: should I?\nlemma addTrans_tr (m : RawCNFA A) [LawfulBEq A] {a b : A} {sβ sβ' sβ : State} :\n (m.addTrans a sβ sβ).tr sβ' b = if sβ = sβ' β§ a = b then (m.tr sβ a).insert sβ else m.tr sβ' b"
},
{
"name": "RawCNFA.WF.trans_src_lt''",
"content": "@[grind ., simp, aesop 50% unsafe]\nlemma RawCNFA.WF.trans_src_lt'' [LawfulBEq A] {m : RawCNFA A} (hwf : m.WF) :\n β {s a s'}, s' β m.tr s a β s β m.states"
},
{
"name": "RawCNFA.WF.trans_src_lt'",
"content": "@[grind ., simp, aesop 50% unsafe]\nlemma RawCNFA.WF.trans_src_lt' {m : RawCNFA A} (hwf : m.WF) :\n β {s a}, (s, a) β m.trans β s β m.states"
},
{
"name": "Std.HashMap.getElem?_none_not_mem",
"content": "@[aesop 50% unsafe]\ntheorem Std.HashMap.getElem?_none_not_mem [BEq K] [LawfulBEq K] [Hashable K] [LawfulHashable K] {m : Std.HashMap K V} {k : K} :\n m[k]? = none β k β m"
}
] | [
{
"name": "nfa",
"content": "def nfa : NFA A S where\n start := { sa | sa β inits }\n accept := { sa | final sa }\n step sa a := { sa' | (a, sa') β f sa }"
},
{
"name": "worklist.St",
"content": "structure worklist.St where\n m : RawCNFA A\n map : Std.HashMap S State := β
\n worklist : Array S := β
\n worklist_nodup : worklist.toList.Nodup\n worklist_incl : β sa β worklist, sa β map"
},
{
"name": "worklist.St.addOrCreateState",
"content": "def worklist.St.addOrCreateState (st : worklist.St A S) (final? : Bool) (sa : S) : State Γ worklist.St A S :=\n match heq : st.map[sa]? with\n | some s => (s, st)\n | none =>\n let (s, m) := st.m.newState\n let m := if final? then m.addFinal s else m\n let map := st.map.insert sa s\n let worklist := st.worklist.push sa\n have worklist_nodup : worklist.toList.Nodup := by admit /- proof elided -/"
},
{
"name": "processOneElem",
"content": "def processOneElem (final : S β Bool) (s : State) (st : worklist.St A S) : A Γ S β worklist.St A S :=\n fun (a', sa') =>\n let (s', st') := st.addOrCreateState _ _ (final sa') sa'\n let m := st'.m.addTrans a' s s'\n { st' with m }"
},
{
"name": "worklist.St.visited",
"content": "def worklist.St.visited (st : worklist.St A S) : Set S := { s : S | s β st.map β§ s β st.worklist }"
},
{
"name": "StInv",
"content": "structure StInv (m : RawCNFA A) (map : Std.HashMap S State) where\n wf : m.WF\n map_states : β (sa : S) s, map[sa]? = some s β s β m.states\n map_surj : β s : m.states, β (sa : S), map[sa]? = some s.val\n map_inj : β {s} {sa sa' : S}, map[sa]? = some s β map[sa']? = some s β sa = sa'"
},
{
"name": "worklist.St.rel",
"content": "def worklist.St.rel (st : worklist.St A S) : SetRel State S := {(s, sa) | st.map[sa]? = some s }"
},
{
"name": "worklist.St.D",
"content": "def worklist.St.D (st : worklist.St A S) : Set S := st.visited"
},
{
"name": "worklist.St.sim",
"content": "abbrev worklist.St.sim {st : worklist.St A S} (T : Set (S Γ A Γ S)) :=\n st.m.Simul (nfa inits final f) st.rel st.D T"
},
{
"name": "processOneElem_mot",
"content": "def processOneElem_mot (s : State) (sa : S) (n : β) (st : worklist.St A S) : Prop :=\n st.map[sa]? = some s β§\n sa β st.visited β§\n StInv A S st.m st.map β§\n st.sim inits final f {(sa1, a, sa') | sa1 = sa β§ β k β₯ n, (f sa)[k]? = some (a, sa') }"
},
{
"name": "processOneElem_inv",
"content": "def processOneElem_inv {st : worklist.St A S} (s : State) (sa : S) (k : β) :\n β a sa', (f sa)[k]? = some (a, sa') β\n processOneElem_mot inits final f s sa k st β\n let st' := processOneElem A S final s st (a, sa')\n StInv A S st'.m st'.map :="
}
] | [
{
"name": "addOrCreate_preserves_map",
"content": "omit [Fintype S] [LawfulBEq A] in\nlemma addOrCreate_preserves_map (st : worklist.St A S) (final? : Bool) (sa sa' : S) :\n let (_, st') := st.addOrCreateState _ _ final? sa'\n st.map[sa]? = some s β\n st'.map[sa]? = some s"
},
{
"name": "processOneElem_preserves_map",
"content": "omit [Fintype S] [LawfulBEq A] in\nlemma processOneElem_preserves_map (st : worklist.St A S) (final : S β Bool) (a : A) (sa sa' : S) (s s' : State) :\n let st' := processOneElem _ _ final s st (a, sa')\n st.map[sa]? = some s' β\n st'.map[sa]? = some s'"
},
{
"name": "addOrCreateElem_visited",
"content": "omit [LawfulBEq A] [Fintype S] [DecidableEq S] in\nlemma addOrCreateElem_visited final? (st : worklist.St A S) sa :\n st.addOrCreateState _ _ final? sa |>.2.visited = st.visited"
},
{
"name": "processOneElem_visited",
"content": "omit [LawfulBEq A] [Fintype S] [DecidableEq S] in\nlemma processOneElem_visited (st : worklist.St A S) :\n let st' := processOneElem _ _ final s st (a, sa')\n st'.visited = st.visited"
},
{
"name": "processOneElem_map",
"content": "omit [LawfulBEq A] [Fintype S] in\nlemma processOneElem_map (st : worklist.St A S) (final : S β Bool) (a : A) (sa sa' : S) (s : State) :\n (processOneElem A S final s st (a, sa)).map[sa']? =\n match st.map[sa']? with\n | some s => some s\n | none => if sa = sa' then some st.m.stateMax else none"
},
{
"name": "processOneElem_initials",
"content": "omit [LawfulBEq A] [Fintype S] [DecidableEq S] in\n@[simp]\nlemma processOneElem_initials (st : worklist.St A S) (final : S β Bool) (a : A) (sa : S) (s : State) :\n (processOneElem A S final s st (a, sa)).m.initials = st.m.initials"
},
{
"name": "processOneElem_finals",
"content": "omit [LawfulBEq A] [Fintype S] [DecidableEq S] in\nlemma processOneElem_finals (st : worklist.St A S) (final : S β Bool) (a : A) (sa : S) (s : State) :\n (processOneElem A S final s st (a, sa)).m.finals =\n if sa β st.map β§ final sa then st.m.finals.insert st.m.stateMax else st.m.finals"
},
{
"name": "processOneElem_tr",
"content": "omit [Fintype S] [DecidableEq S] in\nlemma processOneElem_tr (st : worklist.St A S) (final : S β Bool) (a b : A) (sa : S) (s s' : State) :\n if a = b β§ s = s' then\n β ssa, (processOneElem A S final s st (a, sa)).map[sa]? = some ssa β§\n (processOneElem A S final s st (a, sa)).m.tr s' b =\n (st.m.tr s a |>.insert ssa)\n else\n (processOneElem A S final s st (a, sa)).m.tr s' b = st.m.tr s' b"
},
{
"name": "processOneElem_rel",
"content": "omit [LawfulBEq A] [Fintype S] in\nlemma processOneElem_rel {sβ sβ : State} :\n sβ ~[(processOneElem A S final sβ st (a, sa)).rel] sa' β\n (sβ ~[st.rel] sa' β¨ (sβ = st.m.stateMax β§ sa' = sa β§ st.map[sa']? = none))"
},
{
"name": "rel_in_states",
"content": "omit [LawfulBEq A] [Fintype S] [LawfulBEq S] [DecidableEq S] in\nlemma rel_in_states {st : worklist.St A S} (hinv : StInv A S st.m st.map) :\n s ~[st.rel] sa β s β st.m.states"
},
{
"name": "processOneElem_rel_preserve",
"content": "omit [LawfulBEq A] [Fintype S] in\nlemma processOneElem_rel_preserve :\n sβ ~[st.rel] sa' β\n sβ ~[(processOneElem A S final sβ st (a, sa)).rel] sa'"
},
{
"name": "processOneElem_rel_preserve_olds",
"content": "omit [LawfulBEq A] [Fintype S] in\nlemma processOneElem_rel_preserve_olds :\n sβ ~[(processOneElem A S final sβ st (a, sa)).rel] sa' β\n sβ β st.m.states β sβ ~[st.rel] sa'"
}
] | import Blase.AutoStructs.Basic
open SetRel
section nfa
variable {A : Type} [BEq A] [LawfulBEq A] [Hashable A] [DecidableEq A] [FinEnum A]
variable {S : Type} [Fintype S] [BEq S] [LawfulBEq S] [Hashable S] [DecidableEq S]
variable (inits : Array S) (final : S β Bool) (f : S β Array (A Γ S))
def nfa : NFA A S where
start := { sa | sa β inits }
accept := { sa | final sa }
step sa a := { sa' | (a, sa') β f sa }
end nfa
section nfa'
variable {S : Type} [Fintype S] [BEq S] [LawfulBEq S] [Hashable S] [DecidableEq S]
variable (inits : Array S) (final : S β Bool) (f : S β Array (BitVec n Γ S))
end nfa'
section worklist
variable (A : Type) [BEq A] [LawfulBEq A] [Hashable A] [DecidableEq A] [FinEnum A]
variable (S : Type) [Fintype S] [BEq S] [LawfulBEq S] [Hashable S] [DecidableEq S]
structure worklist.St where
m : RawCNFA A
map : Std.HashMap S State := β
worklist : Array S := β
worklist_nodup : worklist.toList.Nodup
worklist_incl : β sa β worklist, sa β map
open List in
def worklist.St.addOrCreateState (st : worklist.St A S) (final? : Bool) (sa : S) : State Γ worklist.St A S :=
match heq : st.map[sa]? with
| some s => (s, st)
| none =>
let (s, m) := st.m.newState
let m := if final? then m.addFinal s else m
let map := st.map.insert sa s
let worklist := st.worklist.push sa
have worklist_nodup : worklist.toList.Nodup := by admit /- proof elided -/
def processOneElem (final : S β Bool) (s : State) (st : worklist.St A S) : A Γ S β worklist.St A S :=
fun (a', sa') =>
let (s', st') := st.addOrCreateState _ _ (final sa') sa'
let m := st'.m.addTrans a' s s'
{ st' with m }
open List in
have hgrow : β sas, st2.map.keys ~ (sas ++ st1.map.keys) β§ st2.worklist.toList = st1.worklist.toList ++ sas := by
rcases a with β¨alβ©
unfold st2
generalize hst1 : st1 = x; clear hst1; revert x
induction al with
| nil => simp
| cons asa al ih =>
simp; simp at ih; intros st
let wl' := processOneElem A S final s st asa
rcases ih wl' with β¨sas', h1', h2'β©; clear ih
rcases processOneElem_grow _ _ st final asa.1 asa.2 s with β¨sas, h1, h2β©
use (sas ++ sas')
constructor
{ simp [wl'] at h1'; apply list_perm_trick; exact h1'; exact h1 }
{ simp [wl', h2] at h2'; aesop }
have hincl : β k, k β st1.map β k β st2.map := by
intros k; rcases hgrow with β¨sas, hkeys, -β©;
have := @(List.perm_subset_iff_right hkeys st1.map.keys).mpr (by aesop) k; aesop
have : st1.meas < st0.meas := by
rcases heq' : sa? with β¨β© | β¨saβ©
{ simp_all }
apply Finset.card_lt_card
simp [Finset.ssubset_iff, Finset.subset_iff]
use sa
simp [sa?] at heq'
constructor
{ constructor
{ apply Array.mem_of_back? at heq'; apply st0.worklist_incl; assumption }
{ apply Array.not_elem_back_pop at heq' <;> simp_all +zetaDelta [Array.pop] } }
constructor
{ right; apply Array.mem_of_back? at heq'; assumption }
rintro sa hh; rcases hh with hnin | hin
{ simp +zetaDelta [hnin] }
right
exact Array.mem_of_mem_pop st0.worklist sa hin
have : st2.meas β€ st1.meas := by
apply Finset.card_le_card
simp +zetaDelta [Finset.subset_iff]
intros sa' h
rcases h with hnin | hin
{ left; simp [st1] at hincl; intros hc; apply hnin; apply hincl; assumption }
by_cases hnew : sa' β st0.map
all_goals try (left; trivial)
right
simp [st1] at hgrow
rcases hgrow with β¨sas, hkeys2, hwl2β©
have hnin : sa'β sas := by
intros hc
have hdisj : st0.map.keys.Disjoint sas := by
have : (sas ++ st0.map.keys).Nodup := by
apply List.Perm.nodup
assumption
apply st2.map.keys_nodup
simp [List.nodup_append_comm, List.disjoint_of_nodup_append, this]
apply hdisj
{ simp_all [Std.HashMap.mem_keys]; apply hnew }
{ apply hc }
rcases hin with β¨hinβ©; simp_all +zetaDelta
have : st2.meas < st0.meas := by omega
go st2
else
st0.m -- never happens
| none => st0.m -- never happens
termination_by st0.meas
def worklist.St.visited (st : worklist.St A S) : Set S := { s : S | s β st.map β§ s β st.worklist }
structure StInv (m : RawCNFA A) (map : Std.HashMap S State) where
wf : m.WF
map_states : β (sa : S) s, map[sa]? = some s β s β m.states
map_surj : β s : m.states, β (sa : S), map[sa]? = some s.val
map_inj : β {s} {sa sa' : S}, map[sa]? = some s β map[sa']? = some s β sa = sa'
end worklist
section worklist_correct
variable {A : Type} [BEq A] [LawfulBEq A] [Hashable A] [DecidableEq A] [FinEnum A]
variable {S : Type} [Fintype S] [BEq S] [LawfulBEq S] [Hashable S] [DecidableEq S]
variable (inits : Array S) (final : S β Bool) (f : S β Array (A Γ S))
def worklist.St.rel (st : worklist.St A S) : SetRel State S := {(s, sa) | st.map[sa]? = some s }
def worklist.St.D (st : worklist.St A S) : Set S := st.visited
abbrev worklist.St.sim {st : worklist.St A S} (T : Set (S Γ A Γ S)) :=
st.m.Simul (nfa inits final f) st.rel st.D T
def processOneElem_mot (s : State) (sa : S) (n : β) (st : worklist.St A S) : Prop :=
st.map[sa]? = some s β§
sa β st.visited β§
StInv A S st.m st.map β§
st.sim inits final f {(sa1, a, sa') | sa1 = sa β§ β k β₯ n, (f sa)[k]? = some (a, sa') }
def processOneElem_inv {st : worklist.St A S} (s : State) (sa : S) (k : β) :
β a sa', (f sa)[k]? = some (a, sa') β
processOneElem_mot inits final f s sa k st β
let st' := processOneElem A S final s st (a, sa')
StInv A S st'.m st'.map := | omit [Fintype S] in
lemma processOneElem_spec {st : worklist.St A S} (s : State) (sa : S) (k : β) :
β a sa', (f sa)[k]? = some (a, sa') β
processOneElem_mot inits final f s sa k st β
processOneElem_mot inits final f s sa (k+1) (processOneElem A S final s st (a, sa')) := | := by
intro a sa' hf β¨hmap, hvisited, inv, hsimβ©
have hmem : β s (sa : S), st.map[sa]? = some s β s β st.m.states := by intros; apply inv.map_states; assumption
have hwf : st.m.WF := by apply inv.wf
have inv' := processOneElem_inv inits final f s sa k a sa' hf β¨hmap, hvisited, inv, hsimβ©
unfold processOneElem_mot
constructor
(rw [processOneElem_preserves_map]; assumption)
constructor
(rw [processOneElem_visited]; exact hvisited)
use inv'; constructor
{ rw [processOneElem_finals]
rintro s' q hR
have hs' : s β st.m.states := by apply hmem <;> assumption
rw [processOneElem_rel] at hR
rcases hR with hR | β¨rfl, rfl, heqβ©
Β· have heq := rel_in_states inv hR
split_ifs with hcond
Β· have hneq : st.m.stateMax β s' := by rintro rfl; simp [RawCNFA.states] at heq
simp [hneq]
apply hsim.accept; assumption
Β· apply hsim.accept; assumption
Β· split_ifs with h
Β· rcases h with β¨_, hfinβ©
simp [nfa, hfin]
Β· simp [nfa]
suffices hnin : q β st.map by
push_neg at h; specialize h hnin; simp_all
rintro hc; apply hwf.finals_lt at hc; simp at hc
exact Std.HashMap.getElem?_none_not_mem heq }
{ rintro sβ hsβ; rw [processOneElem_initials] at hsβ
obtain β¨q, hq, hRβ© := hsim.initialβ hsβ
use q, hq, processOneElem_rel_preserve final hR }
{ intros q hq; obtain β¨s, hs, hRβ© := hsim.initialβ hq
simp only [processOneElem_initials]
use s, hs, (by exact processOneElem_rel_preserve final hR) }
{ rintro sβ sβ b qβ hR htr
have h := processOneElem_tr st final a b sa' s sβ
split_ifs at h with hcond
on_goal 2 => {
rw [h] at htr
apply processOneElem_rel_preserve_olds at hR
specialize hR (RawCNFA.WF.trans_src_lt'' hwf htr)
obtain β¨qβ, hst, hrelβ© := hsim.trans_matchβ hR htr
use qβ; simp only [hst, true_and]
exact processOneElem_rel_preserve final hrel }
rcases hcond with β¨rfl, rflβ©
rcases h with β¨sβ, hmap', htr'β©
rw [htr'] at htr; clear htr'
simp only [Std.HashSet.mem_insert, beq_iff_eq] at htr
rcases htr with rfl | htr
on_goal 2 =>
have hold := RawCNFA.WF.trans_src_lt'' hwf htr
obtain β¨qβ, hst, hrelβ© := hsim.trans_matchβ
(by apply processOneElem_rel_preserve_olds final hR hold) htr
use qβ, hst, processOneElem_rel_preserve final hrel
use sa'; constructor
Β· suffices heq : qβ = sa by
subst heq; apply Array.mem_of_getElem? hf
apply processOneElem_preserves_map at hmap
unfold worklist.St.rel at hR
apply inv'.map_inj hR hmap
Β· exact hmap' }
{ rintro sβ b qβ qβ hR hs hD hnT
simp only [ge_iff_le, Prod.mk.eta, Set.mem_setOf_eq, not_and, not_exists] at hnT
have h := processOneElem_tr st final a b sa' s sβ
split_ifs at h with hcond
on_goal 2 =>
have hR' : sβ ~[st.rel] qβ := by
rw [processOneElem_rel] at hR; rcases hR with hR' | β¨_, _, hnoneβ©; exact hR'
unfold worklist.St.D at hD; rw [processOneElem_visited] at hD
rcases hD with β¨hnin, -β©
apply Std.HashMap.getElem?_none_not_mem at hnone
contradiction
obtain β¨sβ, hs', hRβ© := hsim.trans_matchβ hR' hs
(by simp_all [worklist.St.D, processOneElem_visited])
(by simp; rintro rfl i hi hc
by_cases heq: k = i
Β· subst heq; apply hcond; constructor
Β· simp [hc] at hf; simp [hf]
Β· rw [hR'] at hmap; simp at hmap; exact hmap.symm
Β· apply hnT rfl _ (by omega) hc)
use sβ; simp only [h, hs', true_and]
apply processOneElem_rel_preserve; assumption
rcases hcond with β¨rfl, rflβ©
rcases h with β¨sβ, hmap', htr'β©
obtain rfl : sa = qβ := by
apply processOneElem_preserves_map at hmap
apply inv'.map_inj hmap hR
simp only [htr', Std.HashSet.mem_insert, beq_iff_eq]
by_cases heq : sa' = qβ
Β· subst heq; use sβ; simp only [true_or, true_and]; exact hmap'
Β· have hold := hmem _ _ hmap
apply processOneElem_rel_preserve_olds at hR
obtain β¨sβ, hs', hRβ© := hsim.trans_matchβ (hR hold) hs
(by simp_all [worklist.St.D, processOneElem_visited])
(by simp; rintro i hi hc
have _ : i β k := by rintro rfl; simp_all
apply hnT rfl i (by omega) hc)
use sβ; simp only [hs', or_true, true_and]
apply processOneElem_rel_preserve; assumption } | 5 | 79 | false | Compiler |
296 | formula_language_case_atom | lemma formula_language_case_atom :
let Ο := Formula.atom rel t1 t2
Ο.language = Ξ» (bvs : BitVecs Ο.arity) => Ο.sat (fun k => bvs.bvs.get k) | lean-mlir | Blase/Blase/AutoStructs/Defs.lean | [
"import Blase.SingleWidth.Defs",
"import Blase.Blase.AutoStructs.ForMathlib",
"import Blase.AutoStructs.ForMathlib"
] | [
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.last",
"module": "Init.Data.Fin.Basic"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Fin.castLE",
"module": "Init.Data.Fin.Basic"
},
{
"name": "BitVec",
"module": "Init.Prelude"
},
{
"name": "BitVec.ofNat",
"module": "Init.Prelude"
},
{
"name": "BitVec.zero",
"module": "Init.Data.BitVec.Basic"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "List.Vector",
"module": "Mathlib.Data.Vector.Defs"
},
{
"name": "Set",
"module": "Mathlib.Data.Set.Defs"
},
{
"name": "Fintype",
"module": "Mathlib.Data.Fintype.Defs"
},
{
"name": "Repr",
"module": "Init.Data.Repr"
},
{
"name": "Bool",
"module": "Init.Prelude"
},
{
"name": "BitVec.iunfoldr",
"module": "Init.Data.BitVec.Folds"
},
{
"name": "Vector",
"module": "Init.Data.Vector.Basic"
},
{
"name": "Vector.ofFn",
"module": "Init.Data.Vector.Basic"
},
{
"name": "impl",
"module": "Mathlib.Deprecated.MLList.BestFirst"
},
{
"name": "FinEnum",
"module": "Mathlib.Data.FinEnum"
},
{
"name": "FinEnum.card",
"module": "Mathlib.Data.FinEnum"
},
{
"name": "Fin.isValue",
"module": "Lean.Meta.Tactic.Simp.BuiltinSimprocs.Fin"
},
{
"name": "List.Vector.nil",
"module": "Mathlib.Data.Vector.Defs"
},
{
"name": "Set.Mem",
"module": "Mathlib.Data.Set.Defs"
},
{
"name": "Set.instMembership",
"module": "Mathlib.Data.Set.Defs"
},
{
"name": "List.Vector.get",
"module": "Mathlib.Data.Vector.Defs"
},
{
"name": "Inhabited",
"module": "Init.Prelude"
},
{
"name": "Lean.ToExpr",
"module": "Lean.ToExpr"
}
] | [
{
"name": "syntax \"max\" : MLIR.Pretty.uniform_op",
"content": "syntax \"max\" : MLIR.Pretty.uniform_op"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(mlir_op| $res:mlir_op_operand = const ($x)\n $[: $outer_type]? ) => do\n let outer_type β outer_type.getDM `(mlir_type| _)\n `(mlir_op| $res:mlir_op_operand = \"const\"()\n {val = $x:num : $outer_type} : ($outer_type) -> ($outer_type) )"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(mlir_op| $res:mlir_op_operand = li ($x)\n $[: $outer_type]? ) => do\n let outer_type β outer_type.getDM `(mlir_type| _ )\n `(mlir_op| $res:mlir_op_operand = \"li\"()\n {imm = $x:num : $outer_type } : ($outer_type) -> ($outer_type))"
},
{
"name": "macro_rules",
"content": "macro_rules\n| `(mlir_op| $res:mlir_op_operand = $op1:MLIR.Pretty.RV.opWithImmediate $reg1 , $x : $t) => do\n let some opName := MLIR.EDSL.Pretty.extractOpName op1.raw\n | Macro.throwUnsupported\n `(mlir_op| $res:mlir_op_operand = $opName ($reg1) {imm = $x:num : $t} : ($t) -> ($t) )"
},
{
"name": "macro_rules",
"content": "macro_rules\n| `(mlir_op| $res:mlir_op_operand = $op1:MLIR.Pretty.RV.opWithShamt $reg1 , $x : $t ) => do\n let some opName := MLIR.EDSL.Pretty.extractOpName op1.raw\n | Macro.throwUnsupported\n `(mlir_op| $res:mlir_op_operand = $opName ($reg1) {shamt = $x:num : $t} : ($t) -> ($t) )"
},
{
"name": "Term",
"content": "inductive Term : Type\n| var : Nat β Term\n \n| zero : Term\n \n| negOne : Term\n \n| one : Term\n \n| ofNat (n : Nat) : Term\n \n| and : Term β Term β Term\n \n| or : Term β Term β Term\n \n| xor : Term β Term β Term\n \n| not : Term β Term\n \n| add : Term β Term β Term\n \n| sub : Term β Term β Term\n \n| neg : Term β Term\n\n\n \n| shiftL : Term β Nat β Term\n\n\nderiving Repr, Inhabited, Lean.ToExpr"
},
{
"name": "Term.arity",
"content": "@[simp] def Term.arity : Term β Nat\n| (var n) => n+1\n| zero => 0\n| one => 0\n| negOne => 0\n| ofNat _ => 0\n| Term.and tβ tβ => max (arity tβ) (arity tβ)\n| Term.or tβ tβ => max (arity tβ) (arity tβ)\n| Term.xor tβ tβ => max (arity tβ) (arity tβ)\n| Term.not t => arity t\n| add tβ tβ => max (arity tβ) (arity tβ)\n| sub tβ tβ => max (arity tβ) (arity tβ)\n| neg t => arity t\n\n\n| shiftL t .. => arity t"
},
{
"name": "BitVecs",
"content": "structure BitVecs (n : Nat) where\n w : Nat\n bvs : List.Vector (BitVec w) n"
},
{
"name": "WidthPredicate",
"content": "inductive WidthPredicate\n| eq\n| neq\n| lt\n| le\n| gt\n| ge\nderiving Repr, Inhabited, Lean.ToExpr"
},
{
"name": "BitVecs.transport",
"content": "def BitVecs.transport (f : Fin n β Fin m) (bvs : BitVecs m) : BitVecs n :=\n { w := bvs.w, bvs := bvs.bvs.transport f }"
},
{
"name": "BitVec.transport",
"content": "def BitVec.transport (f : Fin n2 β Fin n1) (bv : BitVec n1) : BitVec n2 :=\n BitVec.ofFn fun i => bv.getLsbD (f i)"
},
{
"name": "BitVec.ofFn",
"content": "def BitVec.ofFn {w : Nat} (f : Fin w β Bool) : BitVec w :=\n BitVec.iunfoldr (fun i _ => ((), f i)) () |>.2"
},
{
"name": "List.Vector.transport",
"content": "def List.Vector.transport (v : Vector Ξ± m) (f : Fin n β Fin m) : Vector Ξ± n :=\n Vector.ofFn fun i => v.get (f i)"
},
{
"name": "BitVecs'.transport",
"content": "def BitVecs'.transport (f : Fin n β Fin m) (bvs' : BitVecs' m): BitVecs' n :=\n bvs'.map fun bv => bv.transport f"
},
{
"name": "Valuation.cons",
"content": "def Valuation.cons {Ξ : Ctxt Ty} {t : Ty} (x : toType t) (V : Ξ.Valuation) :\n (Ξ.cons t).Valuation :="
},
{
"name": "BitVecs.cast",
"content": "def BitVecs.cast (bvs : BitVecs n) (h : n = n') : BitVecs n' :=\n { w := bvs.w, bvs := h βΈ bvs.bvs }"
},
{
"name": "infixr:67 \"::α΅₯\" => Valuation.cons",
"content": "infixr:67 \"::α΅₯\" => Valuation.cons"
}
] | [
{
"name": "Nat.add_comm",
"module": "Init.Data.Nat.Basic"
},
{
"name": "Fin.val_last",
"module": "Init.Data.Fin.Lemmas"
},
{
"name": "Nat.mod_eq_of_lt",
"module": "Init.Data.Nat.Div.Basic"
},
{
"name": "Set.mem_setOf_eq",
"module": "Mathlib.Data.Set.Operations"
},
{
"name": "le_add_iff_nonneg_right",
"module": "Mathlib.Algebra.Order.Monoid.Unbundled.Basic"
},
{
"name": "zero_le",
"module": "Mathlib.Algebra.Order.Monoid.Canonical.Defs"
}
] | [
{
"name": "List.Vector.append_get_ge",
"content": "@[simp]\nlemma List.Vector.append_get_ge {x : List.Vector Ξ± n} {y : List.Vector Ξ± m} {i : Fin (n+m)} (hlt: n β€ i) :\n (x ++ y).get i = y.get ((i.cast (Nat.add_comm n m) |>.subNat n hlt))"
},
{
"name": "List.Vector.append_get_lt",
"content": "@[simp]\nlemma List.Vector.append_get_lt {x : List.Vector Ξ± n} {y : List.Vector Ξ± m} {i : Fin (n+m)} (hlt: i < n) :\n (x ++ y).get i = x.get (i.castLT hlt)"
},
{
"name": "BitVecs.transport_getElem",
"content": "@[simp]\nlemma BitVecs.transport_getElem {bvs : BitVecs m} (f : Fin n β Fin m) (i : Fin n) :\n (bvs.transport f).bvs.get i = bvs.bvs.get (f i)"
}
] | [
{
"name": "liftMaxSucc1",
"content": "def liftMaxSucc1 (n m : Nat) : Fin (n + 1) β Fin (max n m + 2) :=\n fun k => if _ : k = n then Fin.last (max n m) else k.castLE (by admit /- proof elided -/\n )"
},
{
"name": "liftMaxSucc2",
"content": "def liftMaxSucc2 (n m : Nat) : Fin (m + 1) β Fin (max n m + 2) :=\n fun k => if _ : k = m then Fin.last (max n m + 1) else k.castLE (by admit /- proof elided -/\n )"
},
{
"name": "liftLast2",
"content": "def liftLast2 n : Fin 2 β Fin (n + 2)\n| 0 => n\n| 1 => Fin.last (n + 1)"
},
{
"name": "liftExcept2",
"content": "def liftExcept2 n : Fin n β Fin (n + 2) :=\n fun k => Fin.castLE (by admit /- proof elided -/\n ) k"
},
{
"name": "liftMax1",
"content": "def liftMax1 (n m : Nat) : Fin n β Fin (max n m) :=\n fun k => k.castLE (by admit /- proof elided -/\n )"
},
{
"name": "liftMax2",
"content": "def liftMax2 (n m : Nat) : Fin m β Fin (max n m) :=\n fun k => k.castLE (by admit /- proof elided -/\n )"
},
{
"name": "Term.evalFinBV",
"content": "@[simp] def Term.evalFinBV (t : Term) (vars : Fin (arity t) β BitVec w) : BitVec w :=\n match t with\n | .var n => vars (Fin.last n)\n | .zero => BitVec.zero w\n | .one => 1\n | .negOne => -1\n | .ofNat n => BitVec.ofNat _ n\n | .and tβ tβ =>\n let xβ := tβ.evalFinBV (fun i => vars (Fin.castLE (by admit /- proof elided -/\n ) i))\n let xβ := tβ.evalFinBV (fun i => vars (Fin.castLE (by admit /- proof elided -/\n ) i))\n xβ &&& xβ\n | .or tβ tβ =>\n let xβ := tβ.evalFinBV (fun i => vars (Fin.castLE (by admit /- proof elided -/\n ) i))\n let xβ := tβ.evalFinBV (fun i => vars (Fin.castLE (by admit /- proof elided -/\n ) i))\n xβ ||| xβ\n | .xor tβ tβ =>\n let xβ := tβ.evalFinBV (fun i => vars (Fin.castLE (by admit /- proof elided -/\n ) i))\n let xβ := tβ.evalFinBV (fun i => vars (Fin.castLE (by admit /- proof elided -/\n ) i))\n xβ ^^^ xβ\n | .not t => ~~~(t.evalFinBV vars)\n \n | .add tβ tβ =>\n let xβ := tβ.evalFinBV (fun i => vars (Fin.castLE (by admit /- proof elided -/\n ) i))\n let xβ := tβ.evalFinBV (fun i => vars (Fin.castLE (by admit /- proof elided -/\n ) i))\n xβ + xβ\n | .sub tβ tβ =>\n let xβ := tβ.evalFinBV (fun i => vars (Fin.castLE (by admit /- proof elided -/\n ) i))\n let xβ := tβ.evalFinBV (fun i => vars (Fin.castLE (by admit /- proof elided -/\n ) i))\n xβ - xβ\n | .neg t => -(t.evalFinBV vars)\n | .shiftL a n => (a.evalFinBV vars) <<< n"
},
{
"name": "Term.language",
"content": "def Term.language (t : Term) : Set (BitVecs (t.arity + 1)) :=\n { bvs : BitVecs (t.arity + 1) | t.evalFinBV (fun n => bvs.bvs.get n) = bvs.bvs.get t.arity }"
},
{
"name": "RelationOrdering",
"content": "inductive RelationOrdering\n| lt | le | gt | ge\nderiving Repr, Fintype"
},
{
"name": "Relation",
"content": "inductive Relation\n| eq\n| signed (ord : RelationOrdering)\n| unsigned (ord : RelationOrdering)\nderiving Repr"
},
{
"name": "evalRelation",
"content": "def evalRelation (rel : Relation) {w} (bv1 bv2 : BitVec w) : Prop :=\n match rel with\n | .eq => bv1 = bv2\n | .signed .lt => bv1.slt bv2\n | .signed .le => bv1.sle bv2\n | .signed .gt => bv2.slt bv1\n | .signed .ge => bv2.sle bv1\n | .unsigned .lt => bv1.ult bv2\n | .unsigned .le => bv1.ule bv2\n | .unsigned .gt => bv2.ult bv1\n | .unsigned .ge => bv2.ule bv1"
},
{
"name": "Relation.language",
"content": "@[simp]\ndef Relation.language (rel : Relation) : Set (BitVecs 2) :=\n { bvs | evalRelation rel (bvs.bvs.get 0) (bvs.bvs.get 1) }"
},
{
"name": "Binop",
"content": "inductive Binop\n| and | or | impl | equiv\nderiving Repr"
},
{
"name": "evalBinop",
"content": "def evalBinop (op : Binop) (b1 b2 : Prop) : Prop :=\n match op with\n | .and => b1 β§ b2\n | .or => b1 β¨ b2\n | .impl => b1 β b2\n | .equiv => b1 β b2"
},
{
"name": "langBinop",
"content": "def langBinop (op : Binop) (l1 l2 : Set (BitVecs n)) : Set (BitVecs n) :=\n match op with\n | .and => l1 β© l2\n | .or => l1 βͺ l2\n | .impl => l1αΆ βͺ l2\n | .equiv => (l1αΆ βͺ l2) β© (l2αΆ βͺ l1)"
},
{
"name": "Unop",
"content": "inductive Unop\n| neg\nderiving Repr"
},
{
"name": "Formula",
"content": "inductive Formula : Type\n| width : WidthPredicate β Nat β Formula\n| atom : Relation β Term β Term β Formula\n| msbSet : Term β Formula\n| unop : Unop β Formula β Formula\n| binop : Binop β Formula β Formula β Formula\nderiving Repr"
},
{
"name": "Formula.arity",
"content": "@[simp]\ndef Formula.arity : Formula β Nat\n| width _ _ => 0\n| atom _ t1 t2 => max t1.arity t2.arity\n| msbSet t => t.arity\n| unop _ Ο => Ο.arity\n| binop _ Ο1 Ο2 => max Ο1.arity Ο2.arity"
},
{
"name": "WidthPredicate.sat",
"content": "@[simp]\ndef WidthPredicate.sat (wp : WidthPredicate) (w n : Nat) : Bool :=\n match wp with\n | .eq => w = n\n | .neq => w β n\n | .lt => w < n\n | .le => w β€ n\n | .gt => w > n\n | .ge => w β₯ n"
},
{
"name": "Formula.sat",
"content": "@[simp]\ndef Formula.sat {w : Nat} (Ο : Formula) (Ο : Fin Ο.arity β BitVec w) : Prop :=\n match Ο with\n | .width wp n => wp.sat w n\n | .atom rel t1 t2 =>\n let bv1 := t1.evalFinBV (fun n => Ο $ Fin.castLE (by admit /- proof elided -/\n ) n)\n let bv2 := t2.evalFinBV (fun n => Ο $ Fin.castLE (by admit /- proof elided -/\n ) n)\n evalRelation rel bv1 bv2\n | .unop .neg Ο => Β¬ Ο.sat Ο\n | .binop op Ο1 Ο2 =>\n let b1 := Ο1.sat (fun n => Ο $ Fin.castLE (by admit /- proof elided -/\n ) n)\n let b2 := Ο2.sat (fun n => Ο $ Fin.castLE (by admit /- proof elided -/\n ) n)\n evalBinop op b1 b2\n | .msbSet t => (t.evalFinBV Ο).msb"
},
{
"name": "_root_.Set.lift",
"content": "@[simp]\ndef _root_.Set.lift (f : Fin n β Fin m) (bvs : Set (BitVecs n)) : Set (BitVecs m) :=\n BitVecs.transport f β»ΒΉ' bvs"
},
{
"name": "_root_.Set.proj",
"content": "@[simp]\ndef _root_.Set.proj (f : Fin n β Fin m) (bvs : Set (BitVecs m)) : Set (BitVecs n) :=\n BitVecs.transport f '' bvs"
},
{
"name": "Formula.language",
"content": "@[simp]\ndef Formula.language (Ο : Formula) : Set (BitVecs Ο.arity) :=\n match Ο with\n | .width wp n => { bvs | wp.sat bvs.w n }\n | .atom rel t1 t2 =>\n let l1 := t1.language.lift (liftMaxSucc1 (FinEnum.card $ Fin t1.arity) (FinEnum.card $ Fin t2.arity))\n let l2 := t2.language.lift (liftMaxSucc2 (FinEnum.card $ Fin t1.arity) (FinEnum.card $ Fin t2.arity))\n let lrel := rel.language.lift $ liftLast2 (max (FinEnum.card (Fin t1.arity)) (FinEnum.card (Fin t2.arity)))\n let l := lrel β© l1 β© l2\n l.proj (liftExcept2 _)\n | .unop .neg Ο => Ο.languageαΆ\n | .binop op Ο1 Ο2 =>\n let l1 := Ο1.language.lift $ liftMax1 Ο1.arity Ο2.arity\n let l2 := Ο2.language.lift $ liftMax2 Ο1.arity Ο2.arity\n langBinop op l1 l2\n | .msbSet t =>\n let lmsb := langMsb.lift $ fun _ => Fin.last t.arity\n let l' := t.language β© lmsb\n l'.proj fun n => n.castLE (by admit /- proof elided -/\n )"
}
] | [
{
"name": "evalFin_eq",
"content": "lemma evalFin_eq {t : Term} {vars1 : Fin t.arity β BitVec w1} {vars2 : Fin t.arity β BitVec w2} :\n β (heq : w1 = w2),\n (β n, vars1 n = heq βΈ vars2 n) β\n t.evalFinBV vars1 = heq βΈ t.evalFinBV vars2"
},
{
"name": "evalRelation_coe",
"content": "@[simp]\nlemma evalRelation_coe (rel : Relation) (bv1 bv2 : BitVec w1) (heq : w1 = w2) :\n evalRelation rel (heq βΈ bv1) (heq βΈ bv2) = evalRelation rel bv1 bv2"
},
{
"name": "helper1",
"content": "lemma helper1 : (k = 0) β (x ::α΅₯ vs).get k = x"
},
{
"name": "helper2",
"content": "lemma helper2 : (k = 1) β (x ::α΅₯ y ::α΅₯ vs).get k = y"
}
] | import Blase.AutoStructs.ForMathlib
import Blase.SingleWidth.Defs
open Fin.NatCast
def liftMaxSucc1 (n m : Nat) : Fin (n + 1) β Fin (max n m + 2) :=
fun k => if _ : k = n then Fin.last (max n m) else k.castLE (by admit /- proof elided -/
)
def liftMaxSucc2 (n m : Nat) : Fin (m + 1) β Fin (max n m + 2) :=
fun k => if _ : k = m then Fin.last (max n m + 1) else k.castLE (by admit /- proof elided -/
)
def liftLast2 n : Fin 2 β Fin (n + 2)
| 0 => n
| 1 => Fin.last (n + 1)
def liftExcept2 n : Fin n β Fin (n + 2) :=
fun k => Fin.castLE (by admit /- proof elided -/
) k
def liftMax1 (n m : Nat) : Fin n β Fin (max n m) :=
fun k => k.castLE (by admit /- proof elided -/
)
def liftMax2 (n m : Nat) : Fin m β Fin (max n m) :=
fun k => k.castLE (by admit /- proof elided -/
)
@[simp] def Term.evalFinBV (t : Term) (vars : Fin (arity t) β BitVec w) : BitVec w :=
match t with
| .var n => vars (Fin.last n)
| .zero => BitVec.zero w
| .one => 1
| .negOne => -1
| .ofNat n => BitVec.ofNat _ n
| .and tβ tβ =>
let xβ := tβ.evalFinBV (fun i => vars (Fin.castLE (by admit /- proof elided -/
) i))
let xβ := tβ.evalFinBV (fun i => vars (Fin.castLE (by admit /- proof elided -/
) i))
xβ &&& xβ
| .or tβ tβ =>
let xβ := tβ.evalFinBV (fun i => vars (Fin.castLE (by admit /- proof elided -/
) i))
let xβ := tβ.evalFinBV (fun i => vars (Fin.castLE (by admit /- proof elided -/
) i))
xβ ||| xβ
| .xor tβ tβ =>
let xβ := tβ.evalFinBV (fun i => vars (Fin.castLE (by admit /- proof elided -/
) i))
let xβ := tβ.evalFinBV (fun i => vars (Fin.castLE (by admit /- proof elided -/
) i))
xβ ^^^ xβ
| .not t => ~~~(t.evalFinBV vars)
| .add tβ tβ =>
let xβ := tβ.evalFinBV (fun i => vars (Fin.castLE (by admit /- proof elided -/
) i))
let xβ := tβ.evalFinBV (fun i => vars (Fin.castLE (by admit /- proof elided -/
) i))
xβ + xβ
| .sub tβ tβ =>
let xβ := tβ.evalFinBV (fun i => vars (Fin.castLE (by admit /- proof elided -/
) i))
let xβ := tβ.evalFinBV (fun i => vars (Fin.castLE (by admit /- proof elided -/
) i))
xβ - xβ
| .neg t => -(t.evalFinBV vars)
| .shiftL a n => (a.evalFinBV vars) <<< n
def Term.language (t : Term) : Set (BitVecs (t.arity + 1)) :=
{ bvs : BitVecs (t.arity + 1) | t.evalFinBV (fun n => bvs.bvs.get n) = bvs.bvs.get t.arity }
inductive RelationOrdering
| lt | le | gt | ge
deriving Repr, Fintype
inductive Relation
| eq
| signed (ord : RelationOrdering)
| unsigned (ord : RelationOrdering)
deriving Repr
def evalRelation (rel : Relation) {w} (bv1 bv2 : BitVec w) : Prop :=
match rel with
| .eq => bv1 = bv2
| .signed .lt => bv1.slt bv2
| .signed .le => bv1.sle bv2
| .signed .gt => bv2.slt bv1
| .signed .ge => bv2.sle bv1
| .unsigned .lt => bv1.ult bv2
| .unsigned .le => bv1.ule bv2
| .unsigned .gt => bv2.ult bv1
| .unsigned .ge => bv2.ule bv1
@[simp]
def Relation.language (rel : Relation) : Set (BitVecs 2) :=
{ bvs | evalRelation rel (bvs.bvs.get 0) (bvs.bvs.get 1) }
inductive Binop
| and | or | impl | equiv
deriving Repr
def evalBinop (op : Binop) (b1 b2 : Prop) : Prop :=
match op with
| .and => b1 β§ b2
| .or => b1 β¨ b2
| .impl => b1 β b2
| .equiv => b1 β b2
def langBinop (op : Binop) (l1 l2 : Set (BitVecs n)) : Set (BitVecs n) :=
match op with
| .and => l1 β© l2
| .or => l1 βͺ l2
| .impl => l1αΆ βͺ l2
| .equiv => (l1αΆ βͺ l2) β© (l2αΆ βͺ l1)
inductive Unop
| neg
deriving Repr
inductive Formula : Type
| width : WidthPredicate β Nat β Formula
| atom : Relation β Term β Term β Formula
| msbSet : Term β Formula
| unop : Unop β Formula β Formula
| binop : Binop β Formula β Formula β Formula
deriving Repr
@[simp]
def Formula.arity : Formula β Nat
| width _ _ => 0
| atom _ t1 t2 => max t1.arity t2.arity
| msbSet t => t.arity
| unop _ Ο => Ο.arity
| binop _ Ο1 Ο2 => max Ο1.arity Ο2.arity
@[simp]
def WidthPredicate.sat (wp : WidthPredicate) (w n : Nat) : Bool :=
match wp with
| .eq => w = n
| .neq => w β n
| .lt => w < n
| .le => w β€ n
| .gt => w > n
| .ge => w β₯ n
@[simp]
def Formula.sat {w : Nat} (Ο : Formula) (Ο : Fin Ο.arity β BitVec w) : Prop :=
match Ο with
| .width wp n => wp.sat w n
| .atom rel t1 t2 =>
let bv1 := t1.evalFinBV (fun n => Ο $ Fin.castLE (by admit /- proof elided -/
) n)
let bv2 := t2.evalFinBV (fun n => Ο $ Fin.castLE (by admit /- proof elided -/
) n)
evalRelation rel bv1 bv2
| .unop .neg Ο => Β¬ Ο.sat Ο
| .binop op Ο1 Ο2 =>
let b1 := Ο1.sat (fun n => Ο $ Fin.castLE (by admit /- proof elided -/
) n)
let b2 := Ο2.sat (fun n => Ο $ Fin.castLE (by admit /- proof elided -/
) n)
evalBinop op b1 b2
| .msbSet t => (t.evalFinBV Ο).msb
@[simp]
def _root_.Set.lift (f : Fin n β Fin m) (bvs : Set (BitVecs n)) : Set (BitVecs m) :=
BitVecs.transport f β»ΒΉ' bvs
@[simp]
def _root_.Set.proj (f : Fin n β Fin m) (bvs : Set (BitVecs m)) : Set (BitVecs n) :=
BitVecs.transport f '' bvs
@[simp]
def Formula.language (Ο : Formula) : Set (BitVecs Ο.arity) :=
match Ο with
| .width wp n => { bvs | wp.sat bvs.w n }
| .atom rel t1 t2 =>
let l1 := t1.language.lift (liftMaxSucc1 (FinEnum.card $ Fin t1.arity) (FinEnum.card $ Fin t2.arity))
let l2 := t2.language.lift (liftMaxSucc2 (FinEnum.card $ Fin t1.arity) (FinEnum.card $ Fin t2.arity))
let lrel := rel.language.lift $ liftLast2 (max (FinEnum.card (Fin t1.arity)) (FinEnum.card (Fin t2.arity)))
let l := lrel β© l1 β© l2
l.proj (liftExcept2 _)
| .unop .neg Ο => Ο.languageαΆ
| .binop op Ο1 Ο2 =>
let l1 := Ο1.language.lift $ liftMax1 Ο1.arity Ο2.arity
let l2 := Ο2.language.lift $ liftMax2 Ο1.arity Ο2.arity
langBinop op l1 l2
| .msbSet t =>
let lmsb := langMsb.lift $ fun _ => Fin.last t.arity
let l' := t.language β© lmsb
l'.proj fun n => n.castLE (by admit /- proof elided -/
) | lemma formula_language_case_atom :
let Ο := | := Formula.atom rel t1 t2
Ο.language = Ξ» (bvs : BitVecs Ο.arity) => Ο.sat (fun k => bvs.bvs.get k) := by
unfold Formula.language
rintro Ο
let n := Ο.arity
unfold Ο
dsimp (config := { zeta := false })
lift_lets
intros l1 l2 lrel l
ext bvs
constructor
Β· intros h; simp at h
obtain β¨bvsb, h, heqbβ© := h
unfold l at h
simp at h
unfold lrel l1 l2 at h
obtain β¨β¨hrel, h1β©, h2β© := h
have _ : n+1 < bvsb.bvs.length := by simp +zetaDelta
have _ : n < bvsb.bvs.length := by simp +zetaDelta
have hrel : evalRelation rel (bvsb.bvs.get n) (bvsb.bvs.get (Fin.last (n + 1))) := by
simp at hrel
apply hrel
have ht1 : bvsb.bvs.get n = t1.evalFinBV fun n => bvsb.bvs.get n := by
unfold Term.language at h1
simp [liftMaxSucc1] at h1
unfold n; simp +zetaDelta; rw [βh1]
congr; ext1 k
congr; ext; simp; rw [Nat.mod_eq_of_lt]; omega
have ht2 : bvsb.bvs.get (Fin.last (n+1)) = t2.evalFinBV fun n => bvsb.bvs.get n := by
unfold Term.language at h2
simp [liftMaxSucc2] at h2
unfold n; simp +zetaDelta only [Formula.arity]; rw [βh2]
congr; ext1 k
congr; ext; simp; rw [Nat.mod_eq_of_lt]; omega
have hw : bvsb.w = bvs.w := by rw [βheqb]; simp
have heq1 : (t1.evalFinBV fun n => bvsb.bvs.get n) =
hw βΈ t1.evalFinBV fun n => bvs.bvs.get $ n.castLE (by simp) := by
apply evalFin_eq hw; intros k
rcases bvs with β¨w, bvsβ©; rcases hw
injection heqb with _ heqb; rw [βheqb]
simp [List.Vector.transport, liftExcept2]
congr; ext; simp; omega
have heq2 : (t2.evalFinBV fun n => bvsb.bvs.get n) =
hw βΈ t2.evalFinBV fun n => bvs.bvs.get $ n.castLE (by simp) := by
apply evalFin_eq hw; intros k
rcases bvs with β¨w, bvsβ©; rcases hw
injection heqb with _ heqb; rw [βheqb]
simp [List.Vector.transport, liftExcept2]
congr; ext; simp; omega
rw [ht1, ht2, heq1, heq2, evalRelation_coe] at hrel
dsimp only [Set.instMembership, Set.Mem]
simp_all
Β· intros h
simp
let bv1 := t1.evalFinBV fun k => bvs.bvs.get $ k.castLE (by simp)
let bv2 := t2.evalFinBV fun k => bvs.bvs.get $ k.castLE (by simp)
use β¨bvs.w, bvs.bvs ++ bv1 ::α΅₯ bv2 ::α΅₯ List.Vector.nilβ©
rcases bvs with β¨w, bvsβ©
simp
constructor
Β· unfold l; simp; split_ands
Β· unfold lrel; simp only [Fin.isValue, BitVecs.transport_getElem,
liftLast2, Set.mem_setOf_eq, Fin.val_last, le_add_iff_nonneg_right, zero_le,
List.Vector.append_get_ge]
rw [List.Vector.append_get_ge (by dsimp; rw [Nat.mod_eq_of_lt]; omega)]
simp [Set.instMembership, Set.Mem] at h
convert h using 2
Β· apply helper1; ext; simp; rw [Nat.mod_eq_of_lt] <;> omega
Β· apply helper2; ext; simp
Β· unfold l1 Term.language; simp [liftMaxSucc1]
rw [List.Vector.append_get_ge (by dsimp; rw [Nat.mod_eq_of_lt]; omega)]
rw [helper1 (by ext; simp; rw [Nat.mod_eq_of_lt] <;> omega)]
unfold bv1
congr;
Β· unfold l2 Term.language; simp [liftMaxSucc2]
rw [helper2 (by ext; simp)]
unfold bv2
congr
Β· ext1; simp
next i =>
simp [liftExcept2]
rw [List.Vector.append_get_lt i.isLt]
congr 1 | 5 | 73 | false | Compiler |
297 | TermBinop.alt_lang | lemma TermBinop.alt_lang {tβ tβ : Term} (op : TermBinop) :
(op.subst_arity' βΈ (op.subst tβ tβ).language) =
let lop : Set (BitVecs 3) := op.openTerm_arity βΈ op.openTerm.language
let lop' : Set (BitVecs ((tβ.arity β tβ.arity) + 3)) := lop.lift (liftLast3 (max tβ.arity tβ.arity))
let lβ := tβ.language.lift (liftMaxSuccSucc1 tβ.arity tβ.arity)
let lβ := tβ.language.lift (liftMaxSuccSucc2 tβ.arity tβ.arity)
let l := lβ β© lβ β© lop'
l.proj (liftOp _) | lean-mlir | Blase/Blase/AutoStructs/FormulaToAuto.lean | [
"import Blase.SingleWidth.Defs",
"import Blase.AutoStructs.Constructions",
"import Blase.Blase.Fast.BitStream",
"import Mathlib.Data.Nat.Size -- TODO: remove and get rid of shiftLeft_eq_mul_pow use",
"import Blase.Blase.AutoStructs.ForMathlib",
"import Blase.AutoStructs.Defs",
"import Mathlib.Tactic.FinCases",
"import Mathlib.Data.BitVec",
"import Mathlib.Tactic.Ring",
"import Blase.AutoStructs.FiniteStateMachine",
"import Batteries.Data.Fin.Lemmas",
"import Batteries.Data.Fin.Basic"
] | [
{
"name": "Inhabited",
"module": "Init.Prelude"
},
{
"name": "Lean.ToExpr",
"module": "Lean.ToExpr"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Repr",
"module": "Init.Data.Repr"
},
{
"name": "Bool",
"module": "Init.Prelude"
},
{
"name": "Int.xor",
"module": "Mathlib.Data.Int.Bitwise"
},
{
"name": "BitVec",
"module": "Init.Prelude"
},
{
"name": "BitVec.adcb",
"module": "Init.Data.BitVec.Bitblast"
},
{
"name": "Prod",
"module": "Init.Prelude"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "Fin.last",
"module": "Init.Data.Fin.Basic"
},
{
"name": "Fin.mk",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "List.Vector",
"module": "Mathlib.Data.Vector.Defs"
},
{
"name": "BitVec.ofNat",
"module": "Init.Prelude"
},
{
"name": "BitVec.zero",
"module": "Init.Data.BitVec.Basic"
},
{
"name": "Fin.castLE",
"module": "Init.Data.Fin.Basic"
},
{
"name": "Set",
"module": "Mathlib.Data.Set.Defs"
},
{
"name": "Fin.cast",
"module": "Init.Data.Fin.Basic"
},
{
"name": "Fin.castLT",
"module": "Init.Data.Fin.Basic"
},
{
"name": "Fin.subNat",
"module": "Init.Data.Fin.Basic"
},
{
"name": "List.Vector.get",
"module": "Mathlib.Data.Vector.Defs"
},
{
"name": "List.Vector.nil",
"module": "Mathlib.Data.Vector.Defs"
}
] | [
{
"name": "syntax \"xor\" : MLIR.Pretty.uniform_op",
"content": "syntax \"xor\" : MLIR.Pretty.uniform_op\n\nsyntax \"max\" : MLIR.Pretty.uniform_op"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(mlir_op| $res:mlir_op_operand = const ($x)\n $[: $outer_type]? ) => do\n let outer_type β outer_type.getDM `(mlir_type| _)\n `(mlir_op| $res:mlir_op_operand = \"const\"()\n {val = $x:num : $outer_type} : ($outer_type) -> ($outer_type) )"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(mlir_op| $res:mlir_op_operand = li ($x)\n $[: $outer_type]? ) => do\n let outer_type β outer_type.getDM `(mlir_type| _ )\n `(mlir_op| $res:mlir_op_operand = \"li\"()\n {imm = $x:num : $outer_type } : ($outer_type) -> ($outer_type))"
},
{
"name": "macro_rules",
"content": "macro_rules\n| `(mlir_op| $res:mlir_op_operand = $op1:MLIR.Pretty.RV.opWithImmediate $reg1 , $x : $t) => do\n let some opName := MLIR.EDSL.Pretty.extractOpName op1.raw\n | Macro.throwUnsupported\n `(mlir_op| $res:mlir_op_operand = $opName ($reg1) {imm = $x:num : $t} : ($t) -> ($t) )"
},
{
"name": "macro_rules",
"content": "macro_rules\n| `(mlir_op| $res:mlir_op_operand = $op1:MLIR.Pretty.RV.opWithShamt $reg1 , $x : $t ) => do\n let some opName := MLIR.EDSL.Pretty.extractOpName op1.raw\n | Macro.throwUnsupported\n `(mlir_op| $res:mlir_op_operand = $opName ($reg1) {shamt = $x:num : $t} : ($t) -> ($t) )"
},
{
"name": "Term",
"content": "inductive Term : Type\n| var : Nat β Term\n \n| zero : Term\n \n| negOne : Term\n \n| one : Term\n \n| ofNat (n : Nat) : Term\n \n| and : Term β Term β Term\n \n| or : Term β Term β Term\n \n| xor : Term β Term β Term\n \n| not : Term β Term\n \n| add : Term β Term β Term\n \n| sub : Term β Term β Term\n \n| neg : Term β Term\n\n\n \n| shiftL : Term β Nat β Term\n\n\nderiving Repr, Inhabited, Lean.ToExpr"
},
{
"name": "neg",
"content": "def neg (x : BitStream) : BitStream :=\n fun n => (negAux x n).1"
},
{
"name": "negAux",
"content": "def negAux (x : BitStream) : Nat β Bool Γ Bool\n | 0 => (x 0, !(x 0))\n | n+1 =>\n let borrow := (negAux x n).2\n let a := x (n + 1)\n (xor (!a) borrow, !a && borrow)"
},
{
"name": "BitStream",
"content": "def BitStream : Type := Nat β Bool"
},
{
"name": "sub",
"content": "def sub (x y : BitStream) : BitStream :=\n fun n => (subAux x y n).1"
},
{
"name": "subAux",
"content": "def subAux (x y : BitStream) : Nat β Bool Γ Bool\n | 0 => (xor (x 0) (y 0), !(x 0) && y 0)\n | n+1 =>\n let borrow := (subAux x y n).2\n let a := x (n + 1)\n let b := y (n + 1)\n (xor a (xor b borrow), !a && b || ((!(xor a b)) && borrow))"
},
{
"name": "add",
"content": "def add (x y : BitStream) : BitStream :=\n fun n => (addAux x y n).1"
},
{
"name": "addAux",
"content": "def addAux (x y : BitStream) (i : Nat) : Bool Γ Bool :=\n let carryIn : Bool := match i with\n | 0 => false\n | i + 1 => (addAux x y i).2\n Prod.swap (BitVec.adcb (x i) (y i) carryIn)"
},
{
"name": "BitVecs",
"content": "structure BitVecs (n : Nat) where\n w : Nat\n bvs : List.Vector (BitVec w) n"
},
{
"name": "liftMaxSuccSucc2",
"content": "def liftMaxSuccSucc2 (n m : Nat) : Fin (m + 1) β Fin (max n m + 3) :=\n fun k => if _ : k = Fin.last m then max n m + 1 else k.castLE (by admit /- proof elided -/\n )"
},
{
"name": "liftMaxSuccSucc1",
"content": "def liftMaxSuccSucc1 (n m : Nat) : Fin (n + 1) β Fin (max n m + 3) :=\n fun k => if _ : k = Fin.last n then (max n m).cast else k.castLE (by admit /- proof elided -/\n )"
},
{
"name": "liftLast3",
"content": "def liftLast3 n : Fin 3 β Fin (n + 3)\n| 0 => n\n| 1 => n + 1\n| 2 => Fin.last (n + 2)"
},
{
"name": "BitVecs.cast",
"content": "def BitVecs.cast (bvs : BitVecs n) (h : n = n') : BitVecs n' :=\n { w := bvs.w, bvs := h βΈ bvs.bvs }"
},
{
"name": "Valuation.cons",
"content": "def Valuation.cons {Ξ : Ctxt Ty} {t : Ty} (x : toType t) (V : Ξ.Valuation) :\n (Ξ.cons t).Valuation :="
},
{
"name": "Term.language",
"content": "def Term.language (t : Term) : Set (BitVecs (t.arity + 1)) :=\n { bvs : BitVecs (t.arity + 1) | t.evalFinBV (fun n => bvs.bvs.get n) = bvs.bvs.get t.arity }"
},
{
"name": "Formula.arity",
"content": "@[simp]\ndef Formula.arity : Formula β Nat\n| width _ _ => 0\n| atom _ t1 t2 => max t1.arity t2.arity\n| msbSet t => t.arity\n| unop _ Ο => Ο.arity\n| binop _ Ο1 Ο2 => max Ο1.arity Ο2.arity"
},
{
"name": "Term.evalFinBV",
"content": "@[simp] def Term.evalFinBV (t : Term) (vars : Fin (arity t) β BitVec w) : BitVec w :=\n match t with\n | .var n => vars (Fin.last n)\n | .zero => BitVec.zero w\n | .one => 1\n | .negOne => -1\n | .ofNat n => BitVec.ofNat _ n\n | .and tβ tβ =>\n let xβ := tβ.evalFinBV (fun i => vars (Fin.castLE (by admit /- proof elided -/\n ) i))\n let xβ := tβ.evalFinBV (fun i => vars (Fin.castLE (by admit /- proof elided -/\n ) i))\n xβ &&& xβ\n | .or tβ tβ =>\n let xβ := tβ.evalFinBV (fun i => vars (Fin.castLE (by admit /- proof elided -/\n ) i))\n let xβ := tβ.evalFinBV (fun i => vars (Fin.castLE (by admit /- proof elided -/\n ) i))\n xβ ||| xβ\n | .xor tβ tβ =>\n let xβ := tβ.evalFinBV (fun i => vars (Fin.castLE (by admit /- proof elided -/\n ) i))\n let xβ := tβ.evalFinBV (fun i => vars (Fin.castLE (by admit /- proof elided -/\n ) i))\n xβ ^^^ xβ\n | .not t => ~~~(t.evalFinBV vars)\n \n | .add tβ tβ =>\n let xβ := tβ.evalFinBV (fun i => vars (Fin.castLE (by admit /- proof elided -/\n ) i))\n let xβ := tβ.evalFinBV (fun i => vars (Fin.castLE (by admit /- proof elided -/\n ) i))\n xβ + xβ\n | .sub tβ tβ =>\n let xβ := tβ.evalFinBV (fun i => vars (Fin.castLE (by admit /- proof elided -/\n ) i))\n let xβ := tβ.evalFinBV (fun i => vars (Fin.castLE (by admit /- proof elided -/\n ) i))\n xβ - xβ\n | .neg t => -(t.evalFinBV vars)\n | .shiftL a n => (a.evalFinBV vars) <<< n"
},
{
"name": "Term.arity",
"content": "@[simp] def Term.arity : Term β Nat\n| (var n) => n+1\n| zero => 0\n| one => 0\n| negOne => 0\n| ofNat _ => 0\n| Term.and tβ tβ => max (arity tβ) (arity tβ)\n| Term.or tβ tβ => max (arity tβ) (arity tβ)\n| Term.xor tβ tβ => max (arity tβ) (arity tβ)\n| Term.not t => arity t\n| add tβ tβ => max (arity tβ) (arity tβ)\n| sub tβ tβ => max (arity tβ) (arity tβ)\n| neg t => arity t\n\n\n| shiftL t .. => arity t"
},
{
"name": "infixr:67 \"::α΅₯\" => Valuation.cons",
"content": "infixr:67 \"::α΅₯\" => Valuation.cons"
}
] | [
{
"name": "Nat.add_comm",
"module": "Init.Data.Nat.Basic"
},
{
"name": "Fin.add_def",
"module": "Init.Data.Fin.Lemmas"
},
{
"name": "Fin.castLE_castLE",
"module": "Init.Data.Fin.Lemmas"
},
{
"name": "Nat.le_of_eq",
"module": "Init.Data.Nat.Basic"
},
{
"name": "Nat.mod_eq_of_lt",
"module": "Init.Data.Nat.Div.Basic"
}
] | [
{
"name": "List.Vector.append_get_ge",
"content": "@[simp]\nlemma List.Vector.append_get_ge {x : List.Vector Ξ± n} {y : List.Vector Ξ± m} {i : Fin (n+m)} (hlt: n β€ i) :\n (x ++ y).get i = y.get ((i.cast (Nat.add_comm n m) |>.subNat n hlt))"
},
{
"name": "List.Vector.append_get_lt",
"content": "@[simp]\nlemma List.Vector.append_get_lt {x : List.Vector Ξ± n} {y : List.Vector Ξ± m} {i : Fin (n+m)} (hlt: i < n) :\n (x ++ y).get i = x.get (i.castLT hlt)"
},
{
"name": "ext",
"content": "@[ext]\ntheorem ext {x y : BitStream} (h : β i, x i = y i) : x = y"
}
] | [
{
"name": "liftOp",
"content": "def liftOp n : Fin (n + 1) β Fin (n + 3) :=\n fun k =>\n if k = n then Fin.last (n+2) else k.castLE (by admit /- proof elided -/\n )"
},
{
"name": "liftOp_unchanged",
"content": "@[simp]\ndef liftOp_unchanged (k : Fin n) : liftOp n k.castSucc = k.castLE (by simp) :="
},
{
"name": "TermBinop",
"content": "inductive TermBinop where\n| and | or | xor | add | sub"
},
{
"name": "TermBinop.subst",
"content": "def TermBinop.subst (op : TermBinop) (tβ tβ : Term) : Term :=\n match op with\n | .and => .and tβ tβ\n | .or => .or tβ tβ\n | .xor => .xor tβ tβ\n | .add => .add tβ tβ\n | .sub => .sub tβ tβ"
},
{
"name": "TermBinop.openTerm",
"content": "def TermBinop.openTerm (op : TermBinop) : Term := op.subst (.var 0) (.var 1)"
},
{
"name": "TermBinop.openTerm_arity",
"content": "@[simp]\ndef TermBinop.openTerm_arity (op : TermBinop) : op.openTerm.arity + 1 = 3 :="
},
{
"name": "swapLastTwoBlock",
"content": "def swapLastTwoBlock (x : Fin (n + 3)) : Fin (n + 3) :=\n if x = Fin.last (n+2) then n\n else if x = n+1 then Fin.last (n + 2)\n else if x = n then n + 1\n else x"
}
] | [
{
"name": "TermBinop.subst_arity'",
"content": "lemma TermBinop.subst_arity' {op : TermBinop} : (op.subst tβ tβ).arity + 1= tβ.arity β tβ.arity + 1"
},
{
"name": "BitVecs.cast_eq",
"content": "@[simp]\nlemma BitVecs.cast_eq (x : BitVecs n) (h : n = n') : h βΈ x = x.cast h"
}
] | import Batteries.Data.Fin.Basic
import Batteries.Data.Fin.Lemmas
import Blase.SingleWidth.Defs
import Blase.AutoStructs.Constructions
import Blase.AutoStructs.Defs
import Blase.AutoStructs.FiniteStateMachine
import Mathlib.Tactic.Ring
import Mathlib.Data.Nat.Size -- TODO: remove and get rid of shiftLeft_eq_mul_pow use
import Mathlib.Data.BitVec
import Mathlib.Tactic.FinCases
open Fin.NatCast
open Mathlib
section fsm
variable {arity : Type} [FinEnum arity]
open BitStream in
end fsm
section nfas_relations
end nfas_relations
def liftOp n : Fin (n + 1) β Fin (n + 3) :=
fun k =>
if k = n then Fin.last (n+2) else k.castLE (by admit /- proof elided -/
)
@[simp]
def liftOp_unchanged (k : Fin n) : liftOp n k.castSucc = k.castLE (by simp) :=
inductive TermBinop where
| and | or | xor | add | sub
def TermBinop.subst (op : TermBinop) (tβ tβ : Term) : Term :=
match op with
| .and => .and tβ tβ
| .or => .or tβ tβ
| .xor => .xor tβ tβ
| .add => .add tβ tβ
| .sub => .sub tβ tβ
def TermBinop.openTerm (op : TermBinop) : Term := op.subst (.var 0) (.var 1)
@[simp]
def TermBinop.openTerm_arity (op : TermBinop) : op.openTerm.arity + 1 = 3 :=
def swapLastTwoBlock (x : Fin (n + 3)) : Fin (n + 3) :=
if x = Fin.last (n+2) then n
else if x = n+1 then Fin.last (n + 2)
else if x = n then n + 1
else x | lemma TermBinop.alt_lang {tβ tβ : Term} (op : TermBinop) :
(op.subst_arity' βΈ (op.subst tβ tβ).language) =
let lop : Set (BitVecs 3) := | := op.openTerm_arity βΈ op.openTerm.language
let lop' : Set (BitVecs ((tβ.arity β tβ.arity) + 3)) := lop.lift (liftLast3 (max tβ.arity tβ.arity))
let lβ := tβ.language.lift (liftMaxSuccSucc1 tβ.arity tβ.arity)
let lβ := tβ.language.lift (liftMaxSuccSucc2 tβ.arity tβ.arity)
let l := lβ β© lβ β© lop'
l.proj (liftOp _)
:= by
simp [Term.language]
ext bvs
simp
constructor
Β· rintro heq
let bvs' := bvs.bvs ++
(tβ.evalFinBV (Ξ» n β¦ bvs.bvs.get n) ::α΅₯ tβ.evalFinBV (Ξ» n β¦ bvs.bvs.get n) ::α΅₯ List.Vector.nil)
|>.transport swapLastTwoBlock
use β¨_, bvs'β©
simp [bvs']
split_ands
Β· rw [liftMaxSuccSucc1]; simp
conv =>
enter [1, 2, n]
rw [List.Vector.append_get_lt (by rcases n with β¨n, hnβ©; simp_all; rw [Nat.mod_eq_of_lt (by omega)]; omega)]
rfl
rw [List.Vector.append_get_ge]
on_goal 2 => apply Nat.le_of_eq; simp [Fin.add_def]; rw [Nat.mod_eq_of_lt (by omega)]
generalize_proofs hβ hβ hβ hβ
have heq h : Fin.subNat (tβ.arity β tβ.arity + 1) (Fin.cast hβ (β(tβ.arity β tβ.arity) + 1)) h = 0 := by
ext; simp [Fin.add_def]; rw [Nat.mod_eq_of_lt (by omega)]; omega
simp [heq]
congr; ext1 i; congr 1
rcases i with β¨i, hiβ©; simp [Fin.castLT]; ext; simp; repeat rw [Nat.mod_eq_of_lt (by omega)]
Β· rw [liftMaxSuccSucc2]; simp
conv =>
enter [1, 2, n]
rw [List.Vector.append_get_lt (by rcases n with β¨n, hnβ©; simp_all; rw [Nat.mod_eq_of_lt (by omega)]; omega)]
rfl
generalize_proofs hβ hβ hβ hβ
have heq h : Fin.subNat (tβ.arity β tβ.arity + 1) (Fin.last (2 + tβ.arity β tβ.arity)) h = 1 := by
ext; simp; omega
simp [heq]
congr; ext1 i; congr 1
rcases i with β¨i, hiβ©; simp [Fin.castLT]; ext; simp; repeat rw [Nat.mod_eq_of_lt (by omega)]
Β· rw [BitVecs.cast_eq] at *
simp [BitVecs.cast] at *
rw [liftLast3]
simp
rw [List.Vector.append_get_lt (by simp; rw [Nat.mod_eq_of_lt (by omega)]; omega)]
convert heq using 1
have h n : n + 1 < n + 3 := by omega
have h' n m k : n < m β n < (k β m) + 1 := by omega
Β· cases op <;>
Β· simp [openTerm, subst, liftLast3]; congr
Β· rw [List.Vector.append_get_ge]
Β· simp [Fin.subNat, Fin.add_def]; simp [Nat.mod_eq_of_lt, h]; congr! with β¨n, hnβ©; ext; simp; omega
Β· rw [Fin.add_def]; simp; rw [Nat.mod_eq_of_lt (by omega)]
Β· have heq h : (Fin.subNat (tβ.arity β tβ.arity + 1) (Fin.last (2 + tβ.arity β tβ.arity)) h) = 1 := by
simp [Fin.subNat]; omega
simp [heq, List.Vector.get]; congr; ext1 β¨i, hiβ©; simp; simp [Nat.mod_eq_of_lt (h' _ _ tβ.arity hi)]
Β· congr!; simp [Fin.castLT, Fin.last]; omega
Β· ext1
Β· simp
next i =>
simp [liftOp]
split_ifs with h
Β· subst h
simp
rw [List.Vector.append_get_lt]
on_goal 2 =>
simp +arith
repeat (rw [Nat.mod_eq_of_lt (by omega)])
omega
congr; ext; simp +arith
omega
Β· simp [h]
rw [List.Vector.append_get_lt (by rcases i; simp_all [Fin.last]; rw [Nat.mod_eq_of_lt (by omega)]; omega)]
rcases i with β¨i, hiβ©; congr!; simp_all; omega
Β· rintro β¨bvs', β¨β¨β¨heqβ, heqββ©, heqββ©, heqββ©β©
rw [BitVecs.cast_eq] at *
simp [BitVecs.cast] at *
rw [βheqβ]
conv_rhs =>
simp
simp [liftOp]
rfl
simp [liftMaxSuccSucc1, liftMaxSuccSucc2] at heqβ heqβ
rw [liftLast3] at heqβ
convert heqβ using 1
have hβ : (tβ.evalFinBV fun i => bvs'.bvs.get (liftOp (tβ.arity β tβ.arity) (Fin.castLE (by omega) i).castSucc)) =
bvs'.bvs.get (liftLast3 (tβ.arity β tβ.arity) 0) := by
simp only [liftOp_unchanged, Fin.castLE_castLE, liftLast3]; convert heqβ using 1
have hβ : (tβ.evalFinBV fun i => bvs'.bvs.get (liftOp (tβ.arity β tβ.arity) (Fin.castLE (by omega) i).castSucc)) =
bvs'.bvs.get (liftLast3 (tβ.arity β tβ.arity) 1) := by
simp only [liftOp_unchanged, Fin.castLE_castLE, liftLast3]; convert heqβ
rcases op with _ | _ | _ <;>
. simp [subst, openTerm] at *; congr | 4 | 57 | false | Compiler |
298 | Predicate.eval_eq_denote | theorem Predicate.eval_eq_denote (w : Nat) (p : Predicate) (vars : List (BitVec w)) :
(p.eval (vars.map .ofBitVecSext) w = false) β p.denote w vars | lean-mlir | Blase/Blase/Fast/Defs.lean | [
"import Blase.SingleWidth.Defs",
"import Mathlib.Data.Fin.Basic",
"import Mathlib.Data.Bool.Basic",
"import Blase.Fast.BitStream",
"import Blase.Blase.Fast.BitStream"
] | [
{
"name": "Bool",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Int.xor",
"module": "Mathlib.Data.Int.Bitwise"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Nat.testBit",
"module": "Init.Data.Nat.Bitwise.Basic"
},
{
"name": "BitVec",
"module": "Init.Prelude"
},
{
"name": "BitVec.ofNat",
"module": "Init.Prelude"
},
{
"name": "List.map",
"module": "Init.Prelude"
},
{
"name": "BitVec.ult",
"module": "Init.Data.BitVec.Basic"
},
{
"name": "BitVec.carry",
"module": "Init.Data.BitVec.Bitblast"
},
{
"name": "BitVec.sle",
"module": "Init.Data.BitVec.Basic"
},
{
"name": "BitVec.slt",
"module": "Init.Data.BitVec.Basic"
},
{
"name": "BitVec.ule",
"module": "Init.Data.BitVec.Basic"
},
{
"name": "BitVec.adcb",
"module": "Init.Data.BitVec.Bitblast"
},
{
"name": "Prod",
"module": "Init.Prelude"
}
] | [
{
"name": "syntax \"slt\" : MLIR.Pretty.uniform_op",
"content": "syntax \"slt\" : MLIR.Pretty.uniform_op"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(mlir_op| $res:mlir_op_operand = const ($x)\n $[: $outer_type]? ) => do\n let outer_type β outer_type.getDM `(mlir_type| _)\n `(mlir_op| $res:mlir_op_operand = \"const\"()\n {val = $x:num : $outer_type} : ($outer_type) -> ($outer_type) )"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(mlir_op| $res:mlir_op_operand = li ($x)\n $[: $outer_type]? ) => do\n let outer_type β outer_type.getDM `(mlir_type| _ )\n `(mlir_op| $res:mlir_op_operand = \"li\"()\n {imm = $x:num : $outer_type } : ($outer_type) -> ($outer_type))"
},
{
"name": "macro_rules",
"content": "macro_rules\n| `(mlir_op| $res:mlir_op_operand = $op1:MLIR.Pretty.RV.opWithImmediate $reg1 , $x : $t) => do\n let some opName := MLIR.EDSL.Pretty.extractOpName op1.raw\n | Macro.throwUnsupported\n `(mlir_op| $res:mlir_op_operand = $opName ($reg1) {imm = $x:num : $t} : ($t) -> ($t) )"
},
{
"name": "macro_rules",
"content": "macro_rules\n| `(mlir_op| $res:mlir_op_operand = $op1:MLIR.Pretty.RV.opWithShamt $reg1 , $x : $t ) => do\n let some opName := MLIR.EDSL.Pretty.extractOpName op1.raw\n | Macro.throwUnsupported\n `(mlir_op| $res:mlir_op_operand = $opName ($reg1) {shamt = $x:num : $t} : ($t) -> ($t) )"
},
{
"name": "BitStream",
"content": "def BitStream : Type := Nat β Bool"
},
{
"name": "borrow",
"content": "def borrow (x y : BitStream) : BitStream :=\n fun n => (subAux x y n).2"
},
{
"name": "subAux",
"content": "def subAux (x y : BitStream) : Nat β Bool Γ Bool\n | 0 => (xor (x 0) (y 0), !(x 0) && y 0)\n | n+1 =>\n let borrow := (subAux x y n).2\n let a := x (n + 1)\n let b := y (n + 1)\n (xor a (xor b borrow), !a && b || ((!(xor a b)) && borrow))"
},
{
"name": "nxor",
"content": "def nxor (a b : BitStream) : BitStream := fun i => a i == b i"
},
{
"name": "scanAnd",
"content": "def scanAnd (s : BitStream) : BitStream := scanl true Bool.and s"
},
{
"name": "scanl",
"content": "abbrev scanl (init : Bool) (f : Bool β Bool β Bool) (s : BitStream) : BitStream :=\n fun n => match n with\n | 0 => f init (s 0)\n | n+1 => f (scanl init f s n) (s (n + 1))"
},
{
"name": "scanOr",
"content": "def scanOr (s : BitStream) : BitStream := scanl false Bool.or s"
},
{
"name": "falseIffNeq",
"content": "abbrev falseIffNeq (n : Nat) : BitStream := fun i => decide (i == n)"
},
{
"name": "falseIffLt",
"content": "abbrev falseIffLt (n : Nat) : BitStream := fun i => decide (i β₯ n)"
},
{
"name": "falseIffGe",
"content": "abbrev falseIffGe (n : Nat) : BitStream := fun i => decide (i < n)"
},
{
"name": "falseIffEq",
"content": "abbrev falseIffEq (n : Nat) : BitStream := fun i => decide (i != n)"
},
{
"name": "falseIffGt",
"content": "abbrev falseIffGt (n : Nat) : BitStream := fun i => decide (i β€ n)"
},
{
"name": "Term.width",
"content": "def Term.width (t : Term) : WidthExpr :=\n match t with\n\n | .ofNat w _n => w\n | .var _v w => w\n | .add w _a _b => w\n | .zext _a wnew => wnew\n | .setWidth _a wnew => wnew\n | .sext _a wnew => wnew\n | .bor w _a _b => w\n | .band w _a _b => w\n | .bxor w _a _b => w\n | .bnot w _a => w\n | .boolVar _v => WidthExpr.const 1 \n | .boolConst _b => WidthExpr.const 1\n | .shiftl w _a _k => w\n | .bvOfBool _b => WidthExpr.const 1\n | binWidthRel _k wa wb => WidthExpr.const 0\n | binRel _k w _a _b => w\n | or _p1 _p2 => WidthExpr.const 0\n | and _p1 _p2 => WidthExpr.const 0\n | pvar _v => WidthExpr.const 0\n | boolBinRel _k _a _b => WidthExpr.const 0"
},
{
"name": "falseIffLe",
"content": "abbrev falseIffLe (n : Nat) : BitStream := fun i => decide (i > n)"
},
{
"name": "negOne",
"content": "abbrev negOne : BitStream := fun _ => true"
},
{
"name": "shiftLeft",
"content": "def shiftLeft (x : BitStream) (k : Nat) : BitStream :=\n fun i => if i < k then false else x (i - k) "
},
{
"name": "ofNat",
"content": "def ofNat (x : Nat) : BitStream :=\n Nat.testBit x"
},
{
"name": "one",
"content": "abbrev one : BitStream := (Β· == 0)"
},
{
"name": "zero",
"content": "abbrev zero : BitStream := fun _ => false"
},
{
"name": "Predicate",
"content": "inductive Predicate : Type where\n \n| width (wp : WidthPredicate) (n : Nat) : Predicate\n| binary (p : BinaryPredicate) (tβ tβ : Term)\n| land (p q : Predicate) : Predicate\n| lor (p q : Predicate) : Predicate\nderiving Repr, Inhabited, Lean.ToExpr"
},
{
"name": "neg",
"content": "def neg (x : BitStream) : BitStream :=\n fun n => (negAux x n).1"
},
{
"name": "negAux",
"content": "def negAux (x : BitStream) : Nat β Bool Γ Bool\n | 0 => (x 0, !(x 0))\n | n+1 =>\n let borrow := (negAux x n).2\n let a := x (n + 1)\n (xor (!a) borrow, !a && borrow)"
},
{
"name": "map",
"content": "abbrev map (f : Bool β Bool) : BitStream β BitStream :=\n fun x i => f (x i)"
},
{
"name": "ofBitVecSext",
"content": "abbrev ofBitVecSext {w} (x : BitVec w) : BitStream :=\n fun i => if i < w then x.getLsbD i else x.msb"
},
{
"name": "Term.denote",
"content": "def Term.denote (w : Nat) (t : Term) (vars : List (BitVec w)) : BitVec w :=\n match t with\n | ofNat n => BitVec.ofNat w n\n | var n => vars.getD n default\n | zero => 0#w\n | negOne => -1#w\n | one => 1#w\n | and a b => (a.denote w vars) &&& (b.denote w vars)\n | or a b => (a.denote w vars) ||| (b.denote w vars)\n | xor a b => (a.denote w vars) ^^^ (b.denote w vars)\n | not a => ~~~ (a.denote w vars)\n | add a b => (a.denote w vars) + (b.denote w vars)\n | sub a b => (a.denote w vars) - (b.denote w vars)\n | neg a => - (a.denote w vars)\n \n \n | shiftL a n => (a.denote w vars) <<< n"
},
{
"name": "Predicate.denote",
"content": "def Predicate.denote (p : Predicate) (w : Nat) (vars : List (BitVec w)) : Prop :=\n match p with\n | .width .ge k => k β€ w \n | .width .gt k => k < w \n | .width .le k => w β€ k\n | .width .lt k => w < k\n | .width .neq k => w β k\n | .width .eq k => w = k\n | .binary .eq tβ tβ => tβ.denote w vars = tβ.denote w vars\n | .binary .neq tβ tβ => tβ.denote w vars β tβ.denote w vars\n | .binary .sle tβ tβ => ((tβ.denote w vars).sle (tβ.denote w vars)) = true\n | .binary .slt tβ tβ => ((tβ.denote w vars).slt (tβ.denote w vars)) = true\n | .binary .ule tβ tβ => ((tβ.denote w vars).ule (tβ.denote w vars)) = true\n | .binary .ult tβ tβ => (tβ.denote w vars).ult (tβ.denote w vars) = true\n | .land p q => p.denote w vars β§ q.denote w vars\n | .lor p q => p.denote w vars β¨ q.denote w vars"
},
{
"name": "WidthPredicate",
"content": "inductive WidthPredicate\n| eq\n| neq\n| lt\n| le\n| gt\n| ge\nderiving Repr, Inhabited, Lean.ToExpr"
},
{
"name": "toBitVec",
"content": "def toBitVec (w : Nat) (x : BitStream) : BitVec w :=\n match w with\n | 0 => 0#0\n | w+1 => (x.toBitVec w).cons (x w)"
},
{
"name": "Term",
"content": "inductive Term : Type\n| var : Nat β Term\n \n| zero : Term\n \n| negOne : Term\n \n| one : Term\n \n| ofNat (n : Nat) : Term\n \n| and : Term β Term β Term\n \n| or : Term β Term β Term\n \n| xor : Term β Term β Term\n \n| not : Term β Term\n \n| add : Term β Term β Term\n \n| sub : Term β Term β Term\n \n| neg : Term β Term\n\n\n \n| shiftL : Term β Nat β Term\n\n\nderiving Repr, Inhabited, Lean.ToExpr"
},
{
"name": "concat",
"content": "def concat (b : Bool) (x : BitStream) : BitStream\n | 0 => b\n | i+1 => x i"
},
{
"name": "sub",
"content": "def sub (x y : BitStream) : BitStream :=\n fun n => (subAux x y n).1"
},
{
"name": "add",
"content": "def add (x y : BitStream) : BitStream :=\n fun n => (addAux x y n).1"
},
{
"name": "addAux",
"content": "def addAux (x y : BitStream) (i : Nat) : Bool Γ Bool :=\n let carryIn : Bool := match i with\n | 0 => false\n | i + 1 => (addAux x y i).2\n Prod.swap (BitVec.adcb (x i) (y i) carryIn)"
}
] | [
{
"name": "BitVec.lt_def",
"module": "Init.Data.BitVec.Lemmas"
},
{
"name": "BitVec.of_length_zero",
"module": "Init.Data.BitVec.Lemmas"
},
{
"name": "BitVec.ult_eq_not_carry",
"module": "Init.Data.BitVec.Bitblast"
},
{
"name": "BitVec.eq_of_getLsbD_eq",
"module": "Init.Data.BitVec.Bootstrap"
},
{
"name": "Bool.not_eq_false",
"module": "Init.SimpLemmas"
},
{
"name": "BitVec.eq_of_toInt_eq",
"module": "Init.Data.BitVec.Lemmas"
},
{
"name": "Bool.false_eq_true",
"module": "Init.Data.Bool"
},
{
"name": "Bool.not_eq_true",
"module": "Init.SimpLemmas"
},
{
"name": "Bool.not_false",
"module": "Init.SimpLemmas"
},
{
"name": "Bool.not_true",
"module": "Init.SimpLemmas"
},
{
"name": "decide_false",
"module": "Init.Core"
},
{
"name": "decide_true",
"module": "Init.Core"
},
{
"name": "true_and",
"module": "Init.SimpLemmas"
},
{
"name": "BitVec.neg_one_eq_allOnes",
"module": "Init.Data.BitVec.Lemmas"
},
{
"name": "Bool.true_and",
"module": "Init.SimpLemmas"
},
{
"name": "BitVec.msb_eq_getLsbD_last",
"module": "Init.Data.BitVec.Lemmas"
},
{
"name": "BitVec.le_def",
"module": "Init.Data.BitVec.Lemmas"
},
{
"name": "BitVec.slt_eq_ult",
"module": "Init.Data.BitVec.Lemmas"
}
] | [
{
"name": "subAux_eq_BitVec_carry",
"content": "@[simp] theorem subAux_eq_BitVec_carry (a b : BitStream) (w i : Nat) (hi : i < w) :\n (a.subAux b i).2 = !(BitVec.carry (i + 1) (a.toBitVec w) ((~~~b).toBitVec w) true)"
},
{
"name": "scanOr_true_iff",
"content": "theorem scanOr_true_iff (s : BitStream) (n : Nat)\n : s.scanOr n = true β β (i : Nat), (i β€ n) β§ s i = true"
},
{
"name": "scanOr_false_iff",
"content": "theorem scanOr_false_iff (s : BitStream) (n : Nat) : s.scanOr n = false β β (i : Nat), (hi : i β€ n) β s i = false"
},
{
"name": "scanOr_succ",
"content": "@[simp]\ntheorem scanOr_succ (s : BitStream) : scanOr s (n+1) = ((s.scanOr n) || s (n + 1))"
},
{
"name": "scanAnd_true_iff",
"content": "theorem scanAnd_true_iff (s : BitStream) (n : Nat) :\n s.scanAnd n = true β β (i : Nat), (hi : i β€ n) β s i = true"
},
{
"name": "scanAnd_succ",
"content": "@[simp] theorem scanAnd_succ (s : BitStream) : scanAnd s (n+1) = ((s.scanAnd n) && s (n + 1))"
},
{
"name": "scanAnd_false_iff",
"content": "theorem scanAnd_false_iff (s : BitStream) (n : Nat)\n : s.scanAnd n = false β β (i : Nat), (i β€ n) β§ s i = false"
},
{
"name": "and_eq",
"content": "@[simp] theorem and_eq : (x &&& y) i = (x i && y i)"
},
{
"name": "getLsbD_toBitVec",
"content": "@[simp] theorem getLsbD_toBitVec (w : Nat) (x : BitStream) :\n (x.toBitVec w).getLsbD i = ((decide (i < w)) && x i)"
},
{
"name": "xor_eq",
"content": "@[simp] theorem xor_eq : (x ^^^ y) i = (xor (x i) (y i))"
}
] | [
{
"name": "Term.eval",
"content": "def Term.eval (t : Term) (vars : List BitStream) : BitStream :=\n match t with\n | var n => vars.getD n default\n | zero => BitStream.zero\n | one => BitStream.one\n | negOne => BitStream.negOne\n | ofNat n => BitStream.ofNat n\n | and tβ tβ => (tβ.eval vars) &&& (tβ.eval vars)\n | or tβ tβ => (tβ.eval vars) ||| (tβ.eval vars)\n | xor tβ tβ => (tβ.eval vars) ^^^ (tβ.eval vars)\n | not t => ~~~(t.eval vars)\n | add tβ tβ => (Term.eval tβ vars) + (Term.eval tβ vars)\n | sub tβ tβ => (Term.eval tβ vars) - (Term.eval tβ vars)\n | neg t => -(Term.eval t vars)\n\n\n | shiftL t n => BitStream.shiftLeft (Term.eval t vars) n"
},
{
"name": "Predicate.evalEq",
"content": "def Predicate.evalEq (tβ tβ : BitStream) : BitStream := (tβ ^^^ tβ).concat false |>.scanOr"
},
{
"name": "Predicate.evalNeq",
"content": "def Predicate.evalNeq (tβ tβ : BitStream) : BitStream := (tβ.nxor tβ).concat true |>.scanAnd"
},
{
"name": "Predicate.evalLor",
"content": "def Predicate.evalLor (tβ tβ : BitStream) : BitStream := (tβ &&& tβ)"
},
{
"name": "Predicate.evalLand",
"content": "def Predicate.evalLand (tβ tβ : BitStream) : BitStream := (tβ ||| tβ)"
},
{
"name": "Predicate.evalUlt",
"content": "def Predicate.evalUlt (tβ tβ : BitStream) : BitStream := (~~~ (tβ.borrow tβ)).concat true"
},
{
"name": "Predicate.evalMsbEq",
"content": "def Predicate.evalMsbEq (tβ tβ : BitStream) : BitStream :=\n (tβ ^^^ tβ).concat false"
},
{
"name": "Predicate.evalSlt",
"content": "def Predicate.evalSlt (tβ tβ : BitStream) : BitStream :=\n (((Predicate.evalUlt tβ tβ)) ^^^ (Predicate.evalMsbEq tβ tβ))"
},
{
"name": "Predicate.eval",
"content": "def Predicate.eval (p : Predicate) (vars : List BitStream) : BitStream :=\n match p with\n | .width .eq n => BitStream.falseIffEq n\n | .width .neq n => BitStream.falseIffNeq n\n | .width .lt n => BitStream.falseIffLt n\n | .width .le n => BitStream.falseIffLe n\n | .width .gt n => BitStream.falseIffGt n\n | .width .ge n => BitStream.falseIffGe n\n | lor p q => Predicate.evalLor (p.eval vars) (q.eval vars)\n | land p q => Predicate.evalLand (p.eval vars) (q.eval vars)\n | binary .eq tβ tβ => Predicate.evalEq (tβ.eval vars) (tβ.eval vars)\n \n | binary .neq t1 t2 => Predicate.evalNeq (t1.eval vars) (t2.eval vars)\n | binary .ult tβ tβ => Predicate.evalUlt (tβ.eval vars) (tβ.eval vars)\n | binary .ule tβ tβ =>\n Predicate.evalLor\n (Predicate.evalEq (tβ.eval vars) (tβ.eval vars))\n (Predicate.evalUlt (tβ.eval vars) (tβ.eval vars))\n | binary .slt tβ tβ => Predicate.evalSlt (tβ.eval vars) (tβ.eval vars)\n | binary .sle tβ tβ => Predicate.evalLor\n (Predicate.evalEq (tβ.eval vars) (tβ.eval vars))\n (Predicate.evalSlt (tβ.eval vars) (tβ.eval vars))"
}
] | [
{
"name": "Term.eval_eq_denote",
"content": "@[simp] theorem Term.eval_eq_denote (t : Term) (w : Nat) (vars : List (BitVec w)) :\n (t.eval (vars.map BitStream.ofBitVecSext)).toBitVec w = t.denote w vars"
},
{
"name": "Term.eval_eq_denote_apply",
"content": "theorem Term.eval_eq_denote_apply (t : Term) {w : Nat} {vars : List (BitVec w)}\n {i : Nat} (hi : i < w) :\n (t.eval (vars.map BitStream.ofBitVecSext)) i = (t.denote w vars).getLsbD i"
},
{
"name": "Predicate.evalEq_denote_false_iff",
"content": "theorem Predicate.evalEq_denote_false_iff {w : Nat} (a b : Term) (vars : List (BitVec w)) :\n evalEq (a.eval (List.map .ofBitVecSext vars)) (b.eval (List.map .ofBitVecSext vars)) w = false β\n Term.denote w a vars = Term.denote w b vars"
},
{
"name": "Predicate.evalEq_iff_not_evalNeq",
"content": "theorem Predicate.evalEq_iff_not_evalNeq (a b : BitStream) :\n β (w : Nat), evalEq a b w β Β¬ (evalNeq a b w)"
},
{
"name": "Predicate.evalNeq_denote",
"content": "theorem Predicate.evalNeq_denote {w : Nat} (a b : Term) (vars : List (BitVec w)) :\n evalNeq (a.eval (List.map .ofBitVecSext vars)) (b.eval (List.map .ofBitVecSext vars)) w = false β\n Term.denote w a vars β Term.denote w b vars"
},
{
"name": "Predicate.evalEq_denote_true_iff",
"content": "theorem Predicate.evalEq_denote_true_iff {w : Nat} (a b : Term) (vars : List (BitVec w)) :\n evalEq (a.eval (List.map .ofBitVecSext vars)) (b.eval (List.map .ofBitVecSext vars)) w = true β\n Term.denote w a vars β Term.denote w b vars"
},
{
"name": "BitVec.lt_eq_decide_ult",
"content": "private theorem BitVec.lt_eq_decide_ult {x y : BitVec w} : (x < y) = decide (x.ult y)"
},
{
"name": "Predicate.evalUlt_denote_false_iff",
"content": "theorem Predicate.evalUlt_denote_false_iff {w : Nat} (a b : Term) (vars : List (BitVec w)) :\n evalUlt (a.eval (List.map .ofBitVecSext vars)) (b.eval (List.map .ofBitVecSext vars)) w = false β\n (Term.denote w a vars < Term.denote w b vars)"
},
{
"name": "Predicate.evalUlt_denote_true_iff",
"content": "theorem Predicate.evalUlt_denote_true_iff {w : Nat} (a b : Term) (vars : List (BitVec w)) :\n evalUlt (a.eval (List.map .ofBitVecSext vars)) (b.eval (List.map .ofBitVecSext vars)) w = true β\n (Term.denote w b vars) β€ (Term.denote w a vars)"
},
{
"name": "evalMsbEq_denote_false_iff",
"content": "private theorem evalMsbEq_denote_false_iff {w : Nat} (a b : Term) (vars : List (BitVec w)) :\n Predicate.evalMsbEq (a.eval (List.map .ofBitVecSext vars)) (b.eval (List.map .ofBitVecSext vars)) w = false β\n ((Term.denote w a vars).msb = (Term.denote w b vars).msb)"
},
{
"name": "evalMsbEq_denote_true_iff",
"content": "private theorem evalMsbEq_denote_true_iff {w : Nat} (a b : Term) (vars : List (BitVec w)) :\n Predicate.evalMsbEq (a.eval (List.map .ofBitVecSext vars)) (b.eval (List.map .ofBitVecSext vars)) w = true β\n ((Term.denote w a vars).msb β (Term.denote w b vars).msb)"
},
{
"name": "eq_true_iff_of_eq_false_iff",
"content": "theorem eq_true_iff_of_eq_false_iff (b : Bool) (rhs : Prop) (h : (b = false) β rhs) :\n (b = true) β Β¬ rhs"
},
{
"name": "Predicate.evalSlt_denote_false_iff",
"content": "private theorem Predicate.evalSlt_denote_false_iff {w : Nat} (a b : Term) (vars : List (BitVec w)) :\n evalSlt (a.eval (List.map .ofBitVecSext vars)) (b.eval (List.map .ofBitVecSext vars)) w = false β\n (Term.denote w a vars).slt (Term.denote w b vars)"
},
{
"name": "Predicate.evalSlt_denote_true_iff",
"content": "private theorem Predicate.evalSlt_denote_true_iff {w : Nat} (a b : Term) (vars : List (BitVec w)) :\n evalSlt (a.eval (List.map .ofBitVecSext vars)) (b.eval (List.map .ofBitVecSext vars)) w = true β\n Β¬ (Term.denote w a vars).slt (Term.denote w b vars)"
},
{
"name": "BitVec.ForLean.ule_iff_ult_or_eq'",
"content": "private theorem BitVec.ForLean.ule_iff_ult_or_eq' (x y : BitVec w) : (x.ule y) = (decide (x = y β¨ x < y))"
},
{
"name": "BitVec.sle_iff_slt_or_eq",
"content": "private theorem BitVec.sle_iff_slt_or_eq (x y : BitVec w) : x.sle y β (decide (x = y) β¨ x.slt y)"
},
{
"name": "BitVec.ult_notation_eq_decide_ult",
"content": "theorem BitVec.ult_notation_eq_decide_ult (x y : BitVec w) : (x.ult y) = decide (x < y)"
}
] | import Mathlib.Data.Bool.Basic
import Mathlib.Data.Fin.Basic
import Blase.Fast.BitStream
import Blase.SingleWidth.Defs
open Term
open BitStream in
def Term.eval (t : Term) (vars : List BitStream) : BitStream :=
match t with
| var n => vars.getD n default
| zero => BitStream.zero
| one => BitStream.one
| negOne => BitStream.negOne
| ofNat n => BitStream.ofNat n
| and tβ tβ => (tβ.eval vars) &&& (tβ.eval vars)
| or tβ tβ => (tβ.eval vars) ||| (tβ.eval vars)
| xor tβ tβ => (tβ.eval vars) ^^^ (tβ.eval vars)
| not t => ~~~(t.eval vars)
| add tβ tβ => (Term.eval tβ vars) + (Term.eval tβ vars)
| sub tβ tβ => (Term.eval tβ vars) - (Term.eval tβ vars)
| neg t => -(Term.eval t vars)
| shiftL t n => BitStream.shiftLeft (Term.eval t vars) n
def Predicate.evalEq (tβ tβ : BitStream) : BitStream := (tβ ^^^ tβ).concat false |>.scanOr
def Predicate.evalNeq (tβ tβ : BitStream) : BitStream := (tβ.nxor tβ).concat true |>.scanAnd
def Predicate.evalLor (tβ tβ : BitStream) : BitStream := (tβ &&& tβ)
def Predicate.evalLand (tβ tβ : BitStream) : BitStream := (tβ ||| tβ)
def Predicate.evalUlt (tβ tβ : BitStream) : BitStream := (~~~ (tβ.borrow tβ)).concat true
def Predicate.evalMsbEq (tβ tβ : BitStream) : BitStream :=
(tβ ^^^ tβ).concat false
def Predicate.evalSlt (tβ tβ : BitStream) : BitStream :=
(((Predicate.evalUlt tβ tβ)) ^^^ (Predicate.evalMsbEq tβ tβ))
open BitStream in
def Predicate.eval (p : Predicate) (vars : List BitStream) : BitStream :=
match p with
| .width .eq n => BitStream.falseIffEq n
| .width .neq n => BitStream.falseIffNeq n
| .width .lt n => BitStream.falseIffLt n
| .width .le n => BitStream.falseIffLe n
| .width .gt n => BitStream.falseIffGt n
| .width .ge n => BitStream.falseIffGe n
| lor p q => Predicate.evalLor (p.eval vars) (q.eval vars)
| land p q => Predicate.evalLand (p.eval vars) (q.eval vars)
| binary .eq tβ tβ => Predicate.evalEq (tβ.eval vars) (tβ.eval vars)
| binary .neq t1 t2 => Predicate.evalNeq (t1.eval vars) (t2.eval vars)
| binary .ult tβ tβ => Predicate.evalUlt (tβ.eval vars) (tβ.eval vars)
| binary .ule tβ tβ =>
Predicate.evalLor
(Predicate.evalEq (tβ.eval vars) (tβ.eval vars))
(Predicate.evalUlt (tβ.eval vars) (tβ.eval vars))
| binary .slt tβ tβ => Predicate.evalSlt (tβ.eval vars) (tβ.eval vars)
| binary .sle tβ tβ => Predicate.evalLor
(Predicate.evalEq (tβ.eval vars) (tβ.eval vars))
(Predicate.evalSlt (tβ.eval vars) (tβ.eval vars))
section Predicate
end Predicate | theorem Predicate.eval_eq_denote (w : Nat) (p : Predicate) (vars : List (BitVec w)) :
(p.eval (vars.map .ofBitVecSext) w = false) β p.denote w vars := | := by
induction p generalizing vars w
case width wp n => cases wp <;> simp [eval, denote]
case binary p a b =>
cases p with
| eq => simp [eval, denote]; apply evalEq_denote_false_iff
| neq => simp [eval, denote]; apply evalNeq_denote
| ult =>
simp [eval, denote]
rw [BitVec.ult_notation_eq_decide_ult]
by_cases h: Term.denote w a vars < Term.denote w b vars
case pos => simp only [h, decide_true, Bool.not_true]; rw [evalUlt_denote_false_iff]; exact h
case neg => simp only [h, decide_false, Bool.not_false]; rw [evalUlt_denote_true_iff]; simpa using h
| slt =>
simp [eval, denote];
by_cases h : (Term.denote w a vars).slt (Term.denote w b vars)
Β· rw [h]
simp [Predicate.evalSlt_denote_false_iff, h]
Β· simp at h
rw [h]
simp only [Bool.not_false]
by_contra h'
simp only [Bool.not_eq_true] at h'
rw [Predicate.evalSlt_denote_false_iff] at h'
simp only [h, Bool.false_eq_true] at h'
| ule =>
simp [eval, denote];
simp only [evalLor, BitStream.and_eq]
rw [BitVec.ForLean.ule_iff_ult_or_eq' (Term.denote w a vars) (Term.denote w b vars)]
by_cases heq : Term.denote w a vars = Term.denote w b vars
Β· rw [heq]
simp [evalEq_denote_false_iff a b vars |>.mpr heq]
Β· simp [heq]
by_cases hlt : Term.denote w a vars < Term.denote w b vars
Β· simp [hlt]
simp [evalUlt_denote_false_iff a b vars |>.mpr hlt]
Β· simp [hlt]
have := evalEq_denote_false_iff a b vars |>.not |>.mpr heq
simp only [this, true_and]
have := evalUlt_denote_false_iff a b vars |>.not |>.mpr hlt
simp only [this]
| sle =>
simp [eval, denote]
simp only [evalLor, BitStream.and_eq]
have h := BitVec.sle_iff_slt_or_eq (Term.denote w a vars) (Term.denote w b vars) |>.eq
rcases hSle : (Term.denote w a vars).sle (Term.denote w b vars)
Β· simp [hSle] at h β’
obtain β¨hβ, hββ© := h
simp [evalEq_denote_true_iff .. |>.mpr hβ]
rw [evalSlt_denote_true_iff .. |>.mpr]
simp [hβ]
Β· simp [hSle] at h β’
intros hEq
simp [evalEq_denote_true_iff .. |>.mp hEq] at h
apply evalSlt_denote_false_iff .. |>.mpr h
case land p q hp hq => simp [eval, denote, hp, hq, evalLand]
case lor p q hp hq =>
simp [eval, denote]
simp only [evalLor, BitStream.and_eq]
constructor
Β· intros heval
by_cases hp' : p.denote w vars
Β· simp [hp']
Β· by_cases hq' : q.denote w vars
Β· simp [hq']
Β· have := hp .. |>.not |>.mpr hp'
simp [this] at heval
have := hq .. |>.not |>.mpr hq'
simp [this] at heval
Β· intros hdenote
rcases hdenote with hp' | hq'
Β· have := hp .. |>.mpr hp'
simp [this]
Β· have := hq .. |>.mpr hq'
simp [this] | 9 | 96 | false | Compiler |
299 | eq_true_iff_of_eq_false_iff | theorem eq_true_iff_of_eq_false_iff (b : Bool) (rhs : Prop) (h : (b = false) β rhs) :
(b = true) β Β¬ rhs | lean-mlir | Blase/Blase/Fast/Defs.lean | [
"import Blase.SingleWidth.Defs",
"import Mathlib.Data.Fin.Basic",
"import Blase.Fast.BitStream",
"import Mathlib.Data.Bool.Basic"
] | [
{
"name": "Bool",
"module": "Init.Prelude"
}
] | [
{
"name": "Term",
"content": "inductive Term : Type\n| var : Nat β Term\n \n| zero : Term\n \n| negOne : Term\n \n| one : Term\n \n| ofNat (n : Nat) : Term\n \n| and : Term β Term β Term\n \n| or : Term β Term β Term\n \n| xor : Term β Term β Term\n \n| not : Term β Term\n \n| add : Term β Term β Term\n \n| sub : Term β Term β Term\n \n| neg : Term β Term\n\n\n \n| shiftL : Term β Nat β Term\n\n\nderiving Repr, Inhabited, Lean.ToExpr"
}
] | [
{
"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]"
}
] | [] | [] | import Mathlib.Data.Bool.Basic
import Mathlib.Data.Fin.Basic
import Blase.Fast.BitStream
import Blase.SingleWidth.Defs
open Term
open BitStream in
open BitStream in
section Predicate
end Predicate | theorem eq_true_iff_of_eq_false_iff (b : Bool) (rhs : Prop) (h : (b = false) β rhs) :
(b = true) β Β¬ rhs := | := by
constructor
Β· intros h'
apply h.not.mp
simp [h']
Β· intros h'
by_contra hcontra
simp at hcontra
have := h.mp hcontra
exact h' this | 1 | 2 | false | Compiler |
300 | ReflectVerif.BvDecide.KInductionCircuits.FSM.carryWith_congrEnv_envBitstream_set_of_le | theorem FSM.carryWith_congrEnv_envBitstream_set_of_le (fsm : FSM arity)
(s0 : fsm.Ξ± β Bool) (env : arity β BitStream) (n : Nat) (v : arity β Bool)
(k : Nat) (hk : k β€ n) :
fsm.carryWith s0 (envBitstream_set env n v) k =
fsm.carryWith s0 env k | lean-mlir | Blase/Blase/KInduction/KInduction.lean | [
"import Blase.Fast.Defs",
"import Blase.Vars",
"import Blase.Fast.ForLean",
"import Lean.Meta.ForEachExpr",
"import Mathlib.Data.Bool.Basic",
"import Mathlib.Data.Finset.Defs",
"import Blase.Fast.FiniteStateMachine",
"import Blase.SingleWidth.Syntax",
"import Lean.Meta.Tactic.Simp.BuiltinSimprocs.BitVec",
"import Blase.Fast.BitStream",
"import Blase.EnvBitstream",
"import Blase.Blase.Fast.FiniteStateMachine",
"import Mathlib.Data.Finset.Basic",
"import Mathlib.Data.Fin.Basic",
"import Blase.Fast.Decide",
"import Lean",
"import Mathlib.Data.Multiset.FinsetOps"
] | [
{
"name": "Bool",
"module": "Init.Prelude"
},
{
"name": "Nat",
"module": "Init.Prelude"
},
{
"name": "Vector",
"module": "Init.Data.Vector.Basic"
},
{
"name": "Fin",
"module": "Init.Prelude"
},
{
"name": "String",
"module": "Init.Prelude"
},
{
"name": "Unit",
"module": "Init.Prelude"
},
{
"name": "List",
"module": "Init.Prelude"
},
{
"name": "Field",
"module": "Mathlib.Algebra.Field.Defs"
},
{
"name": "DecidableEq",
"module": "Init.Prelude"
},
{
"name": "FinEnum",
"module": "Mathlib.Data.FinEnum"
},
{
"name": "Hashable",
"module": "Init.Prelude"
},
{
"name": "Empty",
"module": "Init.Prelude"
},
{
"name": "Empty.elim",
"module": "Init.Core"
},
{
"name": "Sum",
"module": "Init.Core"
},
{
"name": "Sum.elim",
"module": "Init.Data.Sum.Basic"
},
{
"name": "ZMod",
"module": "Mathlib.Data.ZMod.Defs"
}
] | [
{
"name": "syntax \"llvm.and\" : MLIR.Pretty.uniform_op",
"content": "syntax \"llvm.and\" : MLIR.Pretty.uniform_op\n\nsyntax \"llvm.ashr\" : MLIR.Pretty.exact_op\n\nsyntax \"llvm.add\" : MLIR.Pretty.overflow_op\n\nsyntax \"llvm.return\" : MLIR.Pretty.uniform_op\n\nsyntax \"return\" : MLIR.Pretty.uniform_op"
},
{
"name": "macro_rules",
"content": "macro_rules\n \n | `(mlir_op| $v:mlir_op_operand = mod_arith.constant $x:neg_num : $t) =>\n `(mlir_op| $v:mlir_op_operand = \"mod_arith.constant\" () {value = $x:neg_num} : () -> ($t))\n\n \n | `(mlir_op| $v:mlir_op_operand = mod_arith.constant ${ $x:term } : $t) => do\n let ctor := mkIdent ``MLIR.AST.AttrValue.int\n let x β `($ctor $x [mlir_type| i64])\n `(mlir_op| $v:mlir_op_operand = \"mod_arith.constant\" () {value = $$($x)} : () -> ($t))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(mlir_op| $resName:mlir_op_operand = $name:InstCombine.cmp_op_name $x, $y $[: $t]?) => do\n let some opName := extractOpName name.raw\n | Macro.throwUnsupported\n let t β t.getDM `(mlir_type| _)\n `(mlir_op| $resName:mlir_op_operand = $opName ($x, $y) : ($t, $t) -> (i1) )"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(mlir_op| $resName:mlir_op_operand = $name:InstCombine.int_cast_op $x : $t to $t') => do\n let some opName := extractOpName name.raw\n | Macro.throwUnsupported\n `(mlir_op| $resName:mlir_op_operand = $opName ($x) : ($t) -> $t')"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(mlir_op| $res:mlir_op_operand = llvm.mlir.constant( $x $[: $inner_type]?)\n $[: $outer_type]? ) => do\n \n let outer_type β outer_type.getDM `(mlir_type| _)\n let inner_type := inner_type.getD outer_type\n `(mlir_op| $res:mlir_op_operand = \"llvm.mlir.constant\"()\n {value = $x:neg_num : $inner_type} : () -> ($outer_type) )\n | `(mlir_op| $res:mlir_op_operand = llvm.mlir.constant( ${ $x:term }) $[: $t]?) => do\n let t β t.getDM `(mlir_type| _)\n let x β `(MLIR.AST.AttrValue.int $x [mlir_type| $t])\n `(mlir_op| $res:mlir_op_operand = \"llvm.mlir.constant\"() {value = $$($x) } : () -> ($t) )"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(mlir_op| $res:mlir_op_operand = llvm.mlir.constant (true) $[: $t]?) =>\n `(mlir_op| $res:mlir_op_operand = llvm.mlir.constant (1 : i1) : i1)\n | `(mlir_op| $res:mlir_op_operand = llvm.mlir.constant (false) $[: $t]?) =>\n `(mlir_op| $res:mlir_op_operand = llvm.mlir.constant (0 : i1) : i1)\n | `(mlir_op| $res:mlir_op_operand = llvm.mlir.constant $x $[: $t]?) =>\n `(mlir_op| $res:mlir_op_operand = llvm.mlir.constant($x $[: $t]?) $[: $t]?)\n | `(mlir_op| $res:mlir_op_operand = llvm.mlir.constant ${ $x:term } $[: $t]?) =>\n `(mlir_op| $res:mlir_op_operand = llvm.mlir.constant($$($x) $[: $t]?) $[: $t]?)"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(mlir_op| $res:mlir_op_operand = llvm.icmp $p $x, $y $[: $t]?) => do\n let t β t.getDM `(mlir_type| _)\n match p.getString with\n | \"eq\" => `(mlir_op| $res:mlir_op_operand = \"llvm.icmp.eq\" ($x, $y) : ($t, $t) -> (i1))\n | \"ne\" => `(mlir_op| $res:mlir_op_operand = \"llvm.icmp.ne\" ($x, $y) : ($t, $t) -> (i1))\n | \"slt\" => `(mlir_op| $res:mlir_op_operand = \"llvm.icmp.slt\" ($x, $y) : ($t, $t) -> (i1))\n | \"sle\" => `(mlir_op| $res:mlir_op_operand = \"llvm.icmp.sle\" ($x, $y) : ($t, $t) -> (i1))\n | \"sgt\" => `(mlir_op| $res:mlir_op_operand = \"llvm.icmp.sgt\" ($x, $y) : ($t, $t) -> (i1))\n | \"sge\" => `(mlir_op| $res:mlir_op_operand = \"llvm.icmp.sge\" ($x, $y) : ($t, $t) -> (i1))\n | \"ult\" => `(mlir_op| $res:mlir_op_operand = \"llvm.icmp.ult\" ($x, $y) : ($t, $t) -> (i1))\n | \"ule\" => `(mlir_op| $res:mlir_op_operand = \"llvm.icmp.ule\" ($x, $y) : ($t, $t) -> (i1))\n | \"ugt\" => `(mlir_op| $res:mlir_op_operand = \"llvm.icmp.ugt\" ($x, $y) : ($t, $t) -> (i1))\n | \"uge\" => `(mlir_op| $res:mlir_op_operand = \"llvm.icmp.uge\" ($x, $y) : ($t, $t) -> (i1))\n | _ => Macro.throwErrorAt p s!\"unexpected predicate {p.getString}\""
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(mlir_op| $res:mlir_op_operand = llvm.select $c, $x, $y $[: $t]?) => do\n let t β t.getDM `(mlir_type| _)\n `(mlir_op| $res:mlir_op_operand = \"llvm.select\" ($c, $x, $y) : (i1, $t, $t) -> ($t))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(mlir_op| $v:mlir_op_operand = arith.const $x:neg_num : $t) =>\n `(mlir_op| $v:mlir_op_operand = \"arith.const\" () {value = $x:neg_num } : () -> ($t))\n | `(mlir_op| $v:mlir_op_operand = arith.const ${ $x:term } : $t) => do\n let ctor := mkIdent ``MLIR.AST.AttrValue.int\n let x β `($ctor $x [mlir_type| i64])\n \n \n \n \n `(mlir_op| $v:mlir_op_operand = \"arith.const\" () {value = $$($x) } : () -> ($t))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(mlir_op| $v:mlir_op_operand = poly.const $x:neg_num : $t) =>\n `(mlir_op| $v:mlir_op_operand = \"poly.const\" () {value = $x:neg_num } : () -> ($t))\n | `(mlir_op| $v:mlir_op_operand = poly.const ${ $x:term } : $t) => do\n let ctor := mkIdent ``MLIR.AST.AttrValue.int\n let x β `($ctor $x [mlir_type| i64])\n \n \n \n \n `(mlir_op| $v:mlir_op_operand = \"poly.const\" () {value = $$($x) } : () -> ($t))"
},
{
"name": "macro_rules",
"content": "macro_rules\n | `(mlir_op| $v:mlir_op_operand = poly.monomial $xs,* : ($ts,*) -> $t) =>\n `(mlir_op| $v:mlir_op_operand = \"poly.monomial\" ($xs,*) : ($ts,*) -> $t)"
},
{
"name": "BitStream",
"content": "def BitStream : Type := Nat β Bool"
},
{
"name": "FSM",
"content": "structure FSM (arity : Type) : Type 1 where\n \n ( Ξ± : Type )\n [ i : FinEnum Ξ± ]\n [ h : Hashable Ξ± ]\n [ dec_eq : DecidableEq Ξ± ]\n \n ( initCarry : Ξ± β Bool )\n \n outputCirc : Circuit (Ξ± β arity)\n nextStateCirc : Ξ± β Circuit (Ξ± β arity)"
},
{
"name": "Circuit",
"content": "inductive Circuit (Ξ± : Type u) : Type u\n | tru : Circuit Ξ±\n | fals : Circuit Ξ±\n \n | var : (positive: Bool) β Ξ± β Circuit Ξ±\n | and : Circuit Ξ± β Circuit Ξ± β Circuit Ξ±\n | or : Circuit Ξ± β Circuit Ξ± β Circuit Ξ±\n | xor : Circuit Ξ± β Circuit Ξ± β Circuit Ξ±\nderiving Repr, DecidableEq"
},
{
"name": "Var",
"content": "def Var (Ξ : Context Ty) (ty : Ty) : Type := { v : VarName // Ξ.hasType v ty }"
},
{
"name": "carryWith",
"content": "def carryWith (p : FSM arity) (carryState : p.Ξ± β Bool) (x : arity β BitStream) (n : Nat) : p.Ξ± β Bool := fun a =>\n (p.changeInitCarry carryState).carry x n a"
},
{
"name": "changeInitCarry",
"content": "def changeInitCarry (p : FSM arity) (c : p.Ξ± β Bool) : FSM arity :=\n { p with initCarry := c }"
},
{
"name": "zero",
"content": "def zero : FSM (Fin 0) :=\n { Ξ± := Empty,\n initCarry := Empty.elim,\n nextStateCirc := Empty.elim,\n outputCirc := Circuit.fals\n }"
},
{
"name": "carry",
"content": "def carry (x : arity β BitStream) : β β p.State\n | 0 => p.initCarry\n | n+1 => (p.nextBit (carry x n) (fun i => x i n)).1"
},
{
"name": "State",
"content": "abbrev State : Type := p.Ξ± β Bool"
},
{
"name": "nextBit",
"content": "def nextBit : p.State β (arity β Bool) β p.State Γ Bool :=\n fun carry inputBits =>\n let input := Sum.elim carry inputBits\n let newState : p.State := fun (a : p.Ξ±) => (p.nextStateCirc a).eval input\n let outBit : Bool := (p.outputCirc).eval input\n (newState, outBit)"
},
{
"name": "rhs",
"content": "def rhs := [poly q, n, hq | {\n^bb0(%a : !R):\n return %a : !R\n\n}]"
},
{
"name": "AttrValue",
"content": "inductive AttrValue where\n | symbol: String -> AttrValue \n | str : String -> AttrValue\n | int : Int -> MLIRType Ο -> AttrValue\n | nat: Nat -> AttrValue\n | bool : Bool -> AttrValue\n | float : Float -> MLIRType Ο -> AttrValue\n | type : MLIRType Ο -> AttrValue\n | affine: AffineMap -> AttrValue\n | permutation: List Nat -> AttrValue \n | list: List AttrValue -> AttrValue\n | nestedsymbol: AttrValue -> AttrValue -> AttrValue\n | alias: String -> AttrValue\n | dict: AttrDict -> AttrValue\n | opaque_: (dialect: String) -> (value: String) -> AttrValue\n | opaqueElements: (dialect: String) -> (value: String) -> (type: MLIRType Ο) -> AttrValue\n | unit: AttrValue"
},
{
"name": "R",
"content": "abbrev R := (ZMod q)[X] β§Έ (Ideal.span {f q n})"
},
{
"name": "bb0",
"content": "def bb0 : Region 0 := [mlir_region|\n{\n ^bb0(%arg0: i32):\n %0 = llvm.mlir.constant(8) : i32\n %1 = llvm.mlir.constant(31) : i32\n %2 = llvm.ashr %arg0, %1 : i32\n %3 = llvm.and %2, %0 : i32\n %4 = llvm.add %3, %2 : i32\n llvm.return %4 : i32\n }]"
},
{
"name": "Region",
"content": "structure Region where\n (name: String)\n (args: List <| TypedSSAVal Ο)\n (ops: List Op)"
}
] | [
{
"name": "...",
"module": ""
}
] | [
{
"name": "carryWith_congrEnv",
"content": "theorem carryWith_congrEnv {p : FSM arity}\n {carryState : p.Ξ± β Bool} {x y : arity β BitStream} {n : Nat}\n (h : β a i, i < n β x a i = y a i) :\n p.carryWith carryState x n = p.carryWith carryState y n"
},
{
"name": "carry_congrEnv",
"content": "theorem carry_congrEnv {p : FSM arity}\n {x y : arity β BitStream} {n : Nat} (h : β a i, i < n β x a i = y a i) :\n p.carry x n = p.carry y n"
}
] | [
{
"name": "ReflectVerif.BvDecide.KInductionCircuits",
"content": "structure KInductionCircuits {arity : Type _}\n [DecidableEq arity] [Fintype arity] [Hashable arity] (fsm : FSM arity) (n : Nat) where\n \n cInitCarryAssignCirc : Circuit (Vars fsm.Ξ± arity 0)\n \n cSuccCarryAssignCirc : Circuit (Vars fsm.Ξ± arity (n+2))\n \n cOutAssignCirc : Circuit (Vars fsm.Ξ± arity (n + 2))\n \n cStatesUniqueCirc : Circuit (Vars fsm.Ξ± arity n)"
},
{
"name": "ReflectVerif.BvDecide.KInductionCircuits.envBitstream_set",
"content": "def envBitstream_set (x : arity β BitStream) (n : Nat) (v : arity β Bool) :\n arity β BitStream :=\n fun a j => if j = n then v a else x a j"
}
] | [] | import Mathlib.Data.Bool.Basic
import Mathlib.Data.Fin.Basic
import Mathlib.Data.Finset.Basic
import Mathlib.Data.Finset.Defs
import Mathlib.Data.Multiset.FinsetOps
import Blase.Fast.BitStream
import Blase.Fast.Defs
import Blase.Fast.FiniteStateMachine
import Blase.Fast.Decide
import Blase.SingleWidth.Syntax
import Lean.Meta.ForEachExpr
import Lean.Meta.Tactic.Simp.BuiltinSimprocs.BitVec
import Blase.Fast.ForLean
import Blase.Vars
import Blase.EnvBitstream
import Lean
open Fin.NatCast
namespace ReflectVerif
open Lean Meta Elab Tactic
namespace BvDecide
open Std Sat AIG
structure KInductionCircuits {arity : Type _}
[DecidableEq arity] [Fintype arity] [Hashable arity] (fsm : FSM arity) (n : Nat) where
cInitCarryAssignCirc : Circuit (Vars fsm.Ξ± arity 0)
cSuccCarryAssignCirc : Circuit (Vars fsm.Ξ± arity (n+2))
cOutAssignCirc : Circuit (Vars fsm.Ξ± arity (n + 2))
cStatesUniqueCirc : Circuit (Vars fsm.Ξ± arity n)
namespace KInductionCircuits
variable {arity : Type _}
{fsm : FSM arity}
variable [DecidableEq arity] [Fintype arity] [Hashable arity]
def envBitstream_set (x : arity β BitStream) (n : Nat) (v : arity β Bool) :
arity β BitStream :=
fun a j => if j = n then v a else x a j | theorem FSM.carryWith_congrEnv_envBitstream_set_of_le (fsm : FSM arity)
(s0 : fsm.Ξ± β Bool) (env : arity β BitStream) (n : Nat) (v : arity β Bool)
(k : Nat) (hk : k β€ n) :
fsm.carryWith s0 (envBitstream_set env n v) k =
fsm.carryWith s0 env k := | := by
apply FSM.carryWith_congrEnv
intros a l hl
simp [envBitstream_set]
intros hcontra; omega | 5 | 33 | false | Compiler |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.