Skip to content

Commit e1a5cf7

Browse files
committed
Proof assignment-invariance for terms
1 parent 099d5dc commit e1a5cf7

File tree

2 files changed

+125
-10
lines changed

2 files changed

+125
-10
lines changed

InferenceInLean/Models.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -176,7 +176,7 @@ lemma validIn_of_entails_closed {sig : Signature} {X : Variables} [inst : Decida
176176
(∃ (β : Assignment X univ), EntailsInterpret I β F) → ValidIn F I := by
177177
intro hβ β
178178
rcases hβ with ⟨γ, hγ⟩
179-
have heval := Formula.eval_of_closed _ I F hclosed β γ
179+
have heval := Formula.eval_of_closed I F hclosed β γ
180180
rw [EntailsInterpret, heval, ← EntailsInterpret]
181181
exact hγ
182182

InferenceInLean/Semantics.lean

Lines changed: 124 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,10 @@ def Term.eval_without_free {sig : Signature} {X : Variables} [DecidableEq X] (t
210210
Term.freeVars sig X term = ∅ → ∀ (args : List (Term sig X)), term = Term.func f args := sorry
211211
specialize ih h -/
212212

213-
#check Formula.freeVars
214-
#check Set.mem_diff_singleton
215-
#check Term.freeVars
213+
214+
lemma List.reduce_to_empty {α β: Type} {xs : List α} {as : List β}
215+
(hlen : xs.length = as.length) (hzero : as.length = 0 ∨ xs.length = 0) : xs = [] ∧ as = [] := by
216+
simp_all only [List.length_eq_zero, or_self, and_true, List.length_nil]
216217
-- β[x1 ↦ a1, ..., xn ↦ an]
217218
@[simp]
218219
def Assignment.bigModify {X : Variables} {univ : Universes} [DecidableEq X]
@@ -249,8 +250,7 @@ lemma Assignment.bigModify_append {X : Variables} {univ : Universes} [DecidableE
249250
(hlen : xs.length = as.length) (y : X) (b : univ) (hy : y ∉ xs) :
250251
β.bigModify (xs ++ [y]) (as ++ [b]) = (β.bigModify xs as).modify y b := by
251252
induction' n with n ih generalizing β xs as
252-
· have hxsempty : xs = [] := by exact List.length_eq_zero.mp (id (Eq.symm hn))
253-
have hasempty : as = [] := by subst hxsempty; exact List.length_eq_zero.mp (id (Eq.symm hlen))
253+
· obtain ⟨hxsempty, hasempty⟩ := List.reduce_to_empty hlen (by simp_all only [or_self])
254254
subst hxsempty hasempty
255255
simp only [Assignment, List.nil_append, bigModify]
256256
· match xs, as with
@@ -268,8 +268,7 @@ lemma Assignment.bigModify_modify {X : Variables} {univ : Universes} [DecidableE
268268
(hxnotinxs : y ∉ xs) (n : ℕ) (hn : n = xs.length) (hlen : xs.length = as.length) :
269269
(β.bigModify xs as).modify y b = (β.modify y b).bigModify xs as := by
270270
induction' n with n ih generalizing xs as β
271-
· have hxsempty : xs = [] := by exact List.length_eq_zero.mp (id (Eq.symm hn))
272-
have hasempty : as = [] := by subst hxsempty; exact List.length_eq_zero.mp (id (Eq.symm hlen))
271+
· obtain ⟨hxsempty, hasempty⟩ := List.reduce_to_empty hlen (by simp_all only [or_self])
273272
subst hxsempty hasempty
274273
simp_all only [List.nodup_nil, List.not_mem_nil, not_false_eq_true, List.length_nil, Assignment,
275274
bigModify]
@@ -445,6 +444,29 @@ lemma Assignment.bigModify_mem {X : Variables} {univ : Universes} [DecidableEq X
445444
simp only [← heq, h]
446445
exact bigModify_single_index β xs huniq as n hn hnempty hlen i hinbounds
447446

447+
lemma Assignment.bigModify_erase_modify_eq_modify {X : Variables} {univ : Universes} [DecidableEq X]
448+
(β : Assignment X univ) (xs : List X) (n : ℕ) (hn : n = xs.length) (hnempty : xs ≠ [])
449+
(as : List univ) (hlen : xs.length = as.length) (huniq : xs.Nodup) :
450+
∀ (y : X) (b : univ) (i : ℕ) (hiinbounds : i < n) (hiindex : xs[i] = y ∧ as[i] = b),
451+
β.bigModify (xs.eraseIdx i ++ [y]) (as.eraseIdx i ++ [b]) = (β.bigModify xs as).modify y b := by
452+
intro x a i hiinbounds hiindix
453+
wlog hlast : i = n - 1
454+
· sorry
455+
·
456+
subst hlast
457+
simp_all only [ne_eq, Assignment, List.eraseIdx_length_sub_one]
458+
obtain ⟨left, right⟩ := hiindix
459+
subst right left
460+
induction' n with n ih generalizing xs as
461+
· sorry
462+
· match xs, as with
463+
| x :: xs, a :: as =>
464+
simp_all only [reduceCtorEq, not_false_eq_true, List.nodup_cons, List.length_cons, Nat.add_one_sub_one,
465+
bigModify]
466+
obtain ⟨hnonmem, hxuniq⟩ := huniq
467+
sorry
468+
| [], [] => simp_all only [not_true_eq_false]
469+
448470
-- An alternative way to formalize expressions of the form β[x1 ↦ a1, ..., xn ↦ an]
449471
@[simp]
450472
def Assignment.modFn {X : Variables} {univ : Universes} [DecidableEq X]
@@ -498,7 +520,94 @@ lemma Assignment.modFn_eq_id {X : Variables} {univ : Universes} [DecidableEq X]
498520
have hxsnone : xs[i]? = none := by simp_all only [not_lt, getElem?_eq_none]
499521
rw [hasnone, hxsnone, Option.map]
500522

501-
--lemma Assignment.modify_same
523+
lemma Term.arg_subset_of_freeVars {sig : Signature} {X : Variables}
524+
[_inst : DecidableEq X] (args : List (Term sig X)) (f : sig.funs) :
525+
∀ (arg : Term sig X) (_harg : arg ∈ args),
526+
Term.freeVars sig X arg ⊆ Term.freeVars sig X (Term.func f args) := by
527+
intro arg harg
528+
induction' args with arg' args ih
529+
· simp_all only [List.not_mem_nil]
530+
· simp only [List.mem_cons] at harg
531+
rcases harg with harg | harg
532+
· subst harg
533+
simp_all only [Term.freeVars.eq_3, Set.subset_union_left]
534+
· specialize ih harg
535+
rw [Term.freeVars]
536+
exact Set.subset_union_of_subset_right ih (Term.freeVars sig X arg')
537+
538+
lemma Term.eval_of_many_free {univ : Universes} {sig : Signature} {X : Variables}
539+
[inst : DecidableEq X] (I : Interpretation sig univ) (T : Term sig X) (xs : List X)
540+
(as : List univ) (hxuniq : xs.Nodup) (hlen : xs.length = as.length) (n : ℕ) (hn : n = xs.length)
541+
(hfree : T.freeVars ⊆ xs.toFinset) : (∀ (β γ : Assignment X univ),
542+
Term.eval I (β.bigModify xs as) T = Term.eval I (γ.bigModify xs as) T) := by
543+
simp_all only [List.coe_toFinset]
544+
induction' T using Term.induction with y args ih f
545+
· simp_all only [Term.freeVars.eq_1, Set.singleton_subset_iff, Set.mem_setOf_eq, eval]
546+
induction' n with n ih generalizing xs as
547+
· intro β γ
548+
obtain ⟨hxsempty, hasempty⟩ := List.reduce_to_empty hlen (by simp_all only [or_self])
549+
subst hasempty hxsempty
550+
simp_all only [List.length_nil, List.nodup_nil, List.not_mem_nil]
551+
· match xs, as with
552+
| x :: xs, a :: as =>
553+
intro β γ
554+
simp_all only [Assignment, List.nodup_cons, List.length_cons, Nat.add_right_cancel_iff,
555+
List.mem_cons, Assignment.bigModify]
556+
subst hn
557+
obtain ⟨left, right⟩ := hxuniq
558+
cases hfree with
559+
| inl h =>
560+
subst h
561+
simp_all only [not_false_eq_true, Assignment.bigModify_nonmem, Assignment.modify,
562+
↓reduceIte]
563+
| inr h_1 =>
564+
apply ih <;> simp_all only
565+
| [], [] => simp_all only [Assignment, List.nodup_nil, List.length_nil, Nat.add_one_ne_zero]
566+
· simp_all only [Assignment, eval, List.map_subtype, List.unattach_attach]
567+
induction' n with n ih' generalizing xs as
568+
· intro β γ
569+
obtain ⟨hxsempty, hasempty⟩ := List.reduce_to_empty hlen (by simp_all only [or_self])
570+
subst hxsempty hasempty
571+
rw [Assignment.bigModify, Assignment.bigModify] at *
572+
have hempty : Term.freeVars sig X (Term.func f args) = {} := by
573+
simp_all only [List.nodup_nil, List.not_mem_nil, Set.setOf_false, Set.subset_empty_iff,
574+
List.length_nil, Assignment.bigModify]
575+
simp_all only [List.nodup_nil, List.not_mem_nil, Set.setOf_false, subset_refl,
576+
List.length_nil, Set.subset_empty_iff, Assignment.bigModify]
577+
have hargsareequal : List.map (eval I β) args = List.map (eval I γ) args := by
578+
simp_all only [List.map_inj_left]
579+
intro arg harg
580+
have hempty : Term.freeVars sig X arg = ∅ := by
581+
have hsub := Term.arg_subset_of_freeVars args f arg harg
582+
exact Set.subset_eq_empty hsub hempty
583+
specialize ih arg harg hempty β γ
584+
exact ih
585+
rw [hargsareequal]
586+
simp only [List.nil_eq, reduceCtorEq, imp_self, implies_true]
587+
simp only [List.nil_eq, reduceCtorEq, imp_self, implies_true]
588+
· intro β γ
589+
match xs, as with
590+
| x :: xs, a :: as =>
591+
clear ih'
592+
rw [Assignment.bigModify, Assignment.bigModify]
593+
have hargsareequal :
594+
List.map (eval I ((Assignment.modify β x a).bigModify xs as)) args =
595+
List.map (eval I ((Assignment.modify γ x a).bigModify xs as)) args := by
596+
simp_all only [List.nodup_cons, List.length_cons, Nat.add_right_cancel_iff, List.mem_cons,
597+
Assignment.bigModify, List.map_inj_left]
598+
intro arg harg
599+
subst hn
600+
obtain ⟨hxnonmen, hxuniq⟩ := hxuniq
601+
-- Term.arg_subset_of_freeVars
602+
have hsubset : Term.freeVars sig X arg ⊆ {a | a = x ∨ a ∈ xs} := by
603+
have hsub := Term.arg_subset_of_freeVars args f arg harg
604+
exact fun ⦃a⦄ a_1 ↦ hfree (hsub a_1)
605+
specialize ih arg harg hsubset β γ
606+
exact ih
607+
rw [hargsareequal]
608+
| [], [] => simp_all only [List.nodup_nil, List.length_nil, Nat.add_one_ne_zero]
609+
610+
#check Term.freeVars
502611
lemma Formula.eval_of_many_free {univ : Universes} {sig : Signature} {X : Variables}
503612
[inst : DecidableEq X] (I : Interpretation sig univ) (F : Formula sig X) (xs : List X)
504613
(as : List univ) (hxuniq : xs.Nodup) (hlen : xs.length = as.length)
@@ -508,7 +617,13 @@ lemma Formula.eval_of_many_free {univ : Universes} {sig : Signature} {X : Variab
508617
induction' F with a F ih F G ihF ihG F G ihF ihG F G ihF ihG F G ihF ihG y F ih y F ih generalizing β γ xs as
509618
· simp_all only [Formula.freeVars, eval]
510619
· simp_all only [Formula.freeVars, eval]
511-
· sorry
620+
· induction' a with p args
621+
simp_all only [Formula.freeVars, Atom.freeVars, List.coe_toFinset, eval, Atom.eval, eq_iff_iff]
622+
apply Iff.intro
623+
· intro a
624+
sorry
625+
· intro a
626+
sorry
512627
· rw [eval, eval]
513628
specialize ih xs as hxuniq hlen hfree β γ
514629
exact congrArg Not ih

0 commit comments

Comments
 (0)