Skip to content

Proof simplifications & additional lemmas #21

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Lampe/Lampe/Hoare/Builtins.lean
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,13 @@ theorem pureBuiltin_intro {A : Type} {a : A} {sgn desc args} :
constructor
cases em (desc a args).fst
. apply Builtin.genericPureOmni.ok
. simp_all only [mapToValHeapCondition, SLP.true_star, exists_const]
. simp_all only [mapToVHCond, SLP.true_star, exists_const]
apply SLP.ent_star_top
simp_all only [SLP.true_star, exists_const]
. tauto
. apply Builtin.genericPureOmni.err
. tauto
. simp_all [mapToValHeapCondition]
. simp_all [mapToVHCond]

lemma pureBuiltin_intro_consequence
{A : Type} {a : A} {sgn desc args} {Q : Tp.denote p outTp → Prop}
Expand Down Expand Up @@ -438,7 +438,7 @@ theorem writeRef_intro :
apply And.intro
. rename_i st₁ st₂ _ _
have _ : r ∈ st₁.vals := by rw [hs]; tauto
simp_all [State.membership_in_val]
simp_all [State.mem_iff_mem_val]
simp only [Finmap.insert_eq_singleton_union, ←Finmap.union_assoc, Finmap.union_singleton, SLP.star_assoc]
rename_i st₁ st₂ _ _
exists (⟨Finmap.singleton r ⟨tp, v'⟩, st₁.lambdas⟩), ?_
Expand Down
5 changes: 2 additions & 3 deletions Lampe/Lampe/Hoare/SepTotal.lean
Original file line number Diff line number Diff line change
Expand Up @@ -319,9 +319,8 @@ theorem lam_intro :
exists ⟨∅, Finmap.singleton r lambda⟩, st
refine ⟨?_, ?_, ?_, ?_⟩
. simp only [LawfulHeap.disjoint]
refine ⟨?_, ?_⟩
. apply Finmap.disjoint_empty
. apply Finmap.singleton_disjoint_of_not_mem (by tauto)
refine ⟨?_, by simp_all⟩
apply Finmap.disjoint_empty
. simp only [State.union_parts, State.mk.injEq]
refine ⟨by simp_all, ?_⟩
have hd : Finmap.Disjoint st.lambdas (Finmap.singleton r lambda) := by
Expand Down
55 changes: 13 additions & 42 deletions Lampe/Lampe/Semantics.lean
Original file line number Diff line number Diff line change
Expand Up @@ -168,37 +168,25 @@ theorem Omni.frame {p Γ tp} {st₁ st₂ : State p} {e : Expr (Tp.denote p) tp}
rename Builtin => b
intros
constructor
simp only [State.union_closures, State.union_vals]
rename_i _ st₁ _ _ _ _ hd
simp only [State.union_parts, LawfulHeap.disjoint] at *
rw [mapToVHCond_iff_fun_match]
have hf := b.frame hq (st₂ := st₂)
unfold mapToValHeapCondition at *
simp_all only [LawfulHeap.disjoint, true_implies]
simp_all only [true_implies]
convert hf
funext
rename Option _ → Prop => Q'
casesm Option (ValHeap _ × _) <;> try rfl
simp_all only [SLP.star, eq_iff_iff]
apply Iff.intro
all_goals (
apply Iff.intro <;> (
intros hin
obtain ⟨s₁, ⟨s₂, ⟨hin₁, hin₂, hin₃, hin₄⟩⟩⟩ := hin
obtain ⟨s₁, ⟨s₂, ⟨hin₁, _, _, _⟩⟩⟩ := hin
)
. exists s₁, s₂
simp only [LawfulHeap.disjoint] at *
refine ⟨by tauto, ?_, ?_, by tauto⟩
. simp only [State.union_parts] at hin₂
injection hin₂
refine ⟨by tauto, by simp_all, ?_, by tauto⟩
. have hc : s₁.lambdas = st₁.lambdas := by
obtain ⟨_, hd₂⟩ := hin₁
rw [State.union_parts] at hin₂
injection hin₂ with _ hu
rw [State.mk.injEq] at hin₄
obtain ⟨_, hin₀⟩ := hin₄
rw [←hin₀] at hu
obtain ⟨_, hd₁⟩ := hd
rw [←hin₀] at hd₁
rw [Finmap.union_cancel hd₁ hd₂] at hu
tauto
apply Finmap.union_cancel hd₂ ?_ |>.mp <;> simp_all
rw [←hc]
tauto
. exists ⟨s₁, st₁.lambdas⟩, ⟨s₂, st₂.lambdas⟩
Expand All @@ -223,7 +211,6 @@ theorem Omni.frame {p Γ tp} {st₁ st₂ : State p} {e : Expr (Tp.denote p) tp}
tauto
| lam =>
intros h
simp only [LawfulHeap.disjoint, State.union_parts_left] at *
obtain ⟨_, hd⟩ := h
constructor
intros
Expand All @@ -232,29 +219,13 @@ theorem Omni.frame {p Γ tp} {st₁ st₂ : State p} {e : Expr (Tp.denote p) tp}
rename ValHeap _ => vh
rename Ref => r
generalize hL : (⟨_, _, _⟩ : Lambda _) = lambda
have hi : r ∉ lmbs ∧ r ∉ st₂.lambdas := by aesop
have hd₁ : Finmap.Disjoint lmbs (Finmap.singleton r lambda) := by
apply Finmap.Disjoint.symm
apply Finmap.singleton_disjoint_iff_not_mem.mpr
tauto
have hd₂ : Finmap.Disjoint (Finmap.singleton r lambda) st₂.lambdas := by
apply Finmap.singleton_disjoint_iff_not_mem.mpr
tauto
have hd : Finmap.Disjoint lmbs (Finmap.singleton r lambda) := by
simp_all [Finmap.Disjoint.symm, Finmap.singleton_disjoint_iff_not_mem]
exists ⟨vh, lmbs ∪ Finmap.singleton r lambda⟩, st₂
refine ⟨?_, ?_, ?_, by tauto⟩
. simp only [LawfulHeap.disjoint]
refine ⟨by tauto, ?_⟩
simp only [Finmap.disjoint_union_left]
tauto
. simp only [State.union_parts_left, State.mk.injEq]
refine ⟨by tauto, ?_⟩
simp only [Finmap.insert_eq_singleton_union]
simp only [Finmap.union_comm_of_disjoint hd₁, Finmap.union_assoc]
. simp [Finmap.union_comm_of_disjoint, Finmap.insert_eq_singleton_union]
rename (∀ref ∉ lmbs, _) => hQ
rw [hL] at hQ
simp only [Finmap.insert_eq_singleton_union] at hQ
rw [Finmap.union_comm_of_disjoint hd₁]
tauto
. simp_all [LawfulHeap.disjoint, Finmap.disjoint_union_left]
. simp_all [State.union_parts_left, Finmap.insert_eq_singleton_union, Finmap.union_comm_of_disjoint hd, Finmap.union_assoc]
. simp only
simp_all [Finmap.insert_eq_singleton_union, Finmap.union_comm_of_disjoint hd]

end Lampe
60 changes: 27 additions & 33 deletions Lampe/Lampe/SeparationLogic/State.lean
Original file line number Diff line number Diff line change
Expand Up @@ -14,37 +14,37 @@ instance : Membership Ref (State p) where
mem := fun a e => e ∈ a.vals

@[simp]
lemma State.membership_in_val {a : State p} : e ∈ a ↔ e ∈ a.vals := by rfl
theorem State.mem_iff_mem_val {a : State p} : e ∈ a ↔ e ∈ a.vals := by rfl

instance : Coe (State p) (ValHeap p) where
coe := fun s => s.vals

/-- Maps a post-condition on `State`s to a post-condition on `ValHeap`s by keeping the lambdas fixed -/
@[reducible]
def mapToValHeapCondition
(lambdas : Lambdas p)
(Q : Option (State p × T) → Prop) : Option (ValHeap p × T) → Prop :=
fun vv => Q (vv.map (fun (vals, t) => ⟨⟨vals, lambdas⟩, t⟩))
def mapToVHCond (lambdas : Lambdas p) (Q : Option (State p × T) → Prop) : Option (ValHeap p × T) → Prop :=
fun vhv => Q (vhv.map (fun (vals, t) => ⟨⟨vals, lambdas⟩, t⟩))

/-- Maps a post-condition on `ValHeap`s to a post-condition on `State`s -/
@[reducible]
def mapToStateCondition
(Q : Option (ValHeap p × T) → Prop) : Option (State p × T) → Prop :=
fun stv => Q (stv.map (fun (st, t) => ⟨st.vals, t⟩))
@[simp]
theorem mapToVHCond_some_iff {Q : Option (State p × T) → Prop} :
((mapToVHCond lmbds Q) (some ⟨vh, v⟩)) ↔ (Q (some ⟨⟨vh, lmbds⟩, v⟩)) := by tauto

@[simp]
theorem mapToVHCond_none_iff {Q : Option (State p × T) → Prop} :
((mapToVHCond lmbds Q) none) ↔ (Q none) := by tauto

theorem mapToVHCond_iff_fun_match {Q : Option (State p × T) → Prop} :
(mapToVHCond lmbds Q) =
(fun vhv => match vhv with
| none => Q none
| some (vh, v) => Q (some ⟨⟨vh, lmbds⟩, v⟩)) := by
unfold mapToVHCond
simp only
funext vhv
casesm Option (ValHeap _ × _) <;> rfl

def State.insertVal (self : State p) (r : Ref) (v : AnyValue p) : State p :=
⟨self.vals.insert r v, self.lambdas⟩

lemma State.eq_constructor {st₁ : State p} :
(st₁ = st₂) ↔ (State.mk st₁.vals st₁.lambdas = State.mk st₂.vals st₂.lambdas) := by
rfl

@[simp]
lemma State.eq_closures :
(State.mk v c = State.mk v' c') → (c = c') := by
intro h
injection h

instance : LawfulHeap (State p) where
union := fun a b => ⟨a.vals ∪ b.vals, a.lambdas ∪ b.lambdas⟩
disjoint := fun a b => a.vals.Disjoint b.vals ∧ a.lambdas.Disjoint b.lambdas
Expand All @@ -55,18 +55,12 @@ instance : LawfulHeap (State p) where
thm_union_assoc := by
intros
simp only [Union.union, State.mk.injEq]
apply And.intro
. apply Finmap.union_assoc
. apply Finmap.union_assoc
apply And.intro <;> apply Finmap.union_assoc
thm_disjoint_symm_iff := by tauto
thm_union_comm_of_disjoint := by
intros
simp only [Union.union, State.mk.injEq]
apply And.intro
. apply Finmap.union_comm_of_disjoint
tauto
. apply Finmap.union_comm_of_disjoint
tauto
apply And.intro <;> { apply Finmap.union_comm_of_disjoint; tauto }
thm_disjoint_empty := by tauto
thm_disjoint_union_left := by
intros x y z
Expand All @@ -91,26 +85,26 @@ def State.lmbSingleton (r : Ref) (v : Lambda (Tp.denote p)) : SLP (State p) :=
notation:max "[" "λ" l " ↦ " r "]" => State.lmbSingleton l r

@[simp]
lemma State.union_parts_left :
theorem State.union_parts_left :
(State.mk v c ∪ st₂ = State.mk (v ∪ st₂.vals) (c ∪ st₂.lambdas)) := by
rfl

@[simp]
lemma State.union_parts_right :
theorem State.union_parts_right :
(st₂ ∪ State.mk v c = State.mk (st₂.vals ∪ v) (st₂.lambdas ∪ c)) := by
rfl

@[simp]
lemma State.union_parts :
theorem State.union_parts :
st₁ ∪ st₂ = State.mk (st₁.vals ∪ st₂.vals) (st₁.lambdas ∪ st₂.lambdas) := by
rfl

@[simp]
lemma State.union_vals {st₁ st₂ : State p} :
theorem State.union_vals {st₁ st₂ : State p} :
(st₁ ∪ st₂).vals = (st₁.vals ∪ st₂.vals) := by rfl

@[simp]
lemma State.union_closures {st₁ st₂ : State p} :
theorem State.union_closures {st₁ st₂ : State p} :
(st₁ ∪ st₂).lambdas = (st₁.lambdas ∪ st₂.lambdas) := by rfl

end Lampe
Loading