Skip to content

Commit 484c8ec

Browse files
committed
Prove assignment-invariance for atoms
1 parent e1a5cf7 commit 484c8ec

File tree

2 files changed

+65
-67
lines changed

2 files changed

+65
-67
lines changed

InferenceInLean/Semantics.lean

Lines changed: 48 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -520,21 +520,6 @@ lemma Assignment.modFn_eq_id {X : Variables} {univ : Universes} [DecidableEq X]
520520
have hxsnone : xs[i]? = none := by simp_all only [not_lt, getElem?_eq_none]
521521
rw [hasnone, hxsnone, Option.map]
522522

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-
538523
lemma Term.eval_of_many_free {univ : Universes} {sig : Signature} {X : Variables}
539524
[inst : DecidableEq X] (I : Interpretation sig univ) (T : Term sig X) (xs : List X)
540525
(as : List univ) (hxuniq : xs.Nodup) (hlen : xs.length = as.length) (n : ℕ) (hn : n = xs.length)
@@ -544,8 +529,7 @@ lemma Term.eval_of_many_free {univ : Universes} {sig : Signature} {X : Variables
544529
induction' T using Term.induction with y args ih f
545530
· simp_all only [Term.freeVars.eq_1, Set.singleton_subset_iff, Set.mem_setOf_eq, eval]
546531
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])
532+
· obtain ⟨hxsempty, hasempty⟩ := List.reduce_to_empty hlen (by simp_all only [or_self])
549533
subst hasempty hxsempty
550534
simp_all only [List.length_nil, List.nodup_nil, List.not_mem_nil]
551535
· match xs, as with
@@ -563,49 +547,50 @@ lemma Term.eval_of_many_free {univ : Universes} {sig : Signature} {X : Variables
563547
| inr h_1 =>
564548
apply ih <;> simp_all only
565549
| [], [] => 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]
550+
· intro β γ
551+
subst hn
552+
simp_all only [Assignment, eval, List.map_subtype, List.unattach_attach]
553+
have hargsareequal : List.map (eval I (β.bigModify xs as)) args =
554+
List.map (eval I (γ.bigModify xs as)) args := by
555+
simp_all only [List.map_inj_left]
556+
intro arg harg
557+
have hsubset : Term.freeVars sig X arg ⊆ {a | a ∈ xs} := by
558+
have hsub := Term.arg_subset_of_freeVars args f arg harg
559+
exact fun ⦃a⦄ a_1 ↦ hfree (hsub a_1)
560+
specialize ih arg harg hsubset β γ
561+
exact ih
562+
rw [hargsareequal]
563+
564+
lemma Atom.eval_of_many_free {univ : Universes} {sig : Signature} {X : Variables}
565+
[inst : DecidableEq X] (I : Interpretation sig univ) (A : Atom sig X) (xs : List X)
566+
(as : List univ) (hxuniq : xs.Nodup) (hlen : xs.length = as.length) (n : ℕ)
567+
(_hn : n = xs.length) (hfree : A.freeVars ⊆ xs.toFinset) : (∀ (β γ : Assignment X univ),
568+
Atom.eval I (β.bigModify xs as) A = Atom.eval I (γ.bigModify xs as) A) := by
569+
induction' A with P args
570+
intro β γ
571+
simp_all only [Atom.freeVars, List.coe_toFinset, eval, eq_iff_iff]
572+
have hargsareequal : List.map (Term.eval I (β.bigModify xs as)) args =
573+
List.map (Term.eval I (γ.bigModify xs as)) args := by
574+
simp_all only [List.map_inj_left]
575+
intro arg harg
576+
have hsubset : Term.freeVars sig X arg ⊆ ↑xs.toFinset := by
577+
simp_all only [List.coe_toFinset]
578+
have hsub : Term.freeVars sig X arg ⊆ (Atom.pred P args).freeVars := by
579+
induction' args with arg' args ih
580+
· simp_all only [Atom.freeVars, Set.empty_subset, List.not_mem_nil]
581+
· simp_all only [Atom.freeVars, Set.union_subset_iff, List.mem_cons, forall_const]
582+
obtain ⟨left, right⟩ := hfree
583+
cases harg with
584+
| inl h =>
585+
subst h
586+
simp_all only [Set.subset_union_left]
587+
| inr h_1 =>
588+
simp_all only [forall_const]
589+
exact Set.subset_union_of_subset_right ih (Term.freeVars sig X arg')
590+
exact fun ⦃a⦄ a_1 ↦ hfree (hsub a_1)
591+
have heval := Term.eval_of_many_free I arg xs as hxuniq hlen xs.length rfl hsubset β γ
592+
exact heval
593+
rw [hargsareequal]
609594

610595
#check Term.freeVars
611596
lemma Formula.eval_of_many_free {univ : Universes} {sig : Signature} {X : Variables}
@@ -618,12 +603,9 @@ lemma Formula.eval_of_many_free {univ : Universes} {sig : Signature} {X : Variab
618603
· simp_all only [Formula.freeVars, eval]
619604
· simp_all only [Formula.freeVars, eval]
620605
· 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
606+
have hatom := Atom.eval_of_many_free I (Atom.pred p args) xs as hxuniq hlen xs.length rfl
607+
(by simp_all only [Formula.freeVars, Atom.freeVars, List.coe_toFinset]) β γ
608+
simp_all only [Formula.freeVars, Atom.freeVars, List.coe_toFinset, Atom.eval, eq_iff_iff, eval]
627609
· rw [eval, eval]
628610
specialize ih xs as hxuniq hlen hfree β γ
629611
exact congrArg Not ih

InferenceInLean/Syntax.lean

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,8 @@ inductive Atom where
6666

6767
@[simp]
6868
def Atom.freeVars {sig : Signature} {X : Variables} : Atom sig X -> Set X
69-
| .pred _ args => args.foldl (fun acc t => acc ∪ Term.freeVars sig X t) ∅
69+
| .pred _ [] => ∅
70+
| .pred P (a :: args) => a.freeVars ∪ (Atom.pred P args).freeVars
7071

7172
inductive Literal where
7273
| pos (a : Atom sig X)
@@ -316,3 +317,18 @@ Maybe continue with?
316317
3.3 LEMMA If a is an idempotent substitution and z is an arbitrary substitution, then a is
317318
more general than z iff za = z.
318319
-/
320+
321+
lemma Term.arg_subset_of_freeVars {sig : Signature} {X : Variables}
322+
[_inst : DecidableEq X] (args : List (Term sig X)) (f : sig.funs) :
323+
∀ (arg : Term sig X) (_harg : arg ∈ args),
324+
Term.freeVars sig X arg ⊆ Term.freeVars sig X (Term.func f args) := by
325+
intro arg harg
326+
induction' args with arg' args ih
327+
· simp_all only [List.not_mem_nil]
328+
· simp only [List.mem_cons] at harg
329+
rcases harg with harg | harg
330+
· subst harg
331+
simp_all only [Term.freeVars.eq_3, Set.subset_union_left]
332+
· specialize ih harg
333+
rw [Term.freeVars]
334+
exact Set.subset_union_of_subset_right ih (Term.freeVars sig X arg')

0 commit comments

Comments
 (0)