diff options
| author | Hannes Schulze <haschu0103@outlook.de> | 2025-12-03 21:06:17 +0100 |
|---|---|---|
| committer | Hannes Schulze <haschu0103@outlook.de> | 2025-12-03 21:06:17 +0100 |
| commit | d7660ed1688a486b48f1c968e742ff85490e497f (patch) | |
| tree | 8915eebe06742e63dd1e8f2a85f7a0626c17bce9 | |
| parent | 71a6a3d5b6f4b428b463bc4a0766c91d8c1d5768 (diff) | |
clean up nominal algebra terms
| -rw-r--r-- | Algebra/Term.lean | 107 |
1 files changed, 61 insertions, 46 deletions
diff --git a/Algebra/Term.lean b/Algebra/Term.lean index 665999f..b4d18f9 100644 --- a/Algebra/Term.lean +++ b/Algebra/Term.lean @@ -55,21 +55,35 @@ inductive Term.HasDepth : Term ๐ธ sig X โ โ โ Prop def TermAtDepth (sig : Signature) (X : Type) [NominalSet ๐ธ X] (n : โ) := { t : Term ๐ธ sig X // t.HasDepth ๐ธ n } +def TermAtDepth.var (x : X) : TermAtDepth ๐ธ sig X 0 := โจ.var x, by constructorโฉ + +def TermAtDepth.pure {n : โ} (f : sig.pure) (args : sig.pureArgs f โ TermAtDepth ๐ธ sig X n) : + TermAtDepth ๐ธ sig X (n + sig.pureDepth f) := + โจ.pure f (Subtype.val โ args), by constructor; intro arg; exact (args arg).propโฉ + +def TermAtDepth.free {n : โ} (a : ๐ธ) (f : sig.free) (args : sig.freeArgs f โ TermAtDepth ๐ธ sig X n) : + TermAtDepth ๐ธ sig X (n + sig.freeDepth f) := + โจ.free a f (Subtype.val โ args), by constructor; intro arg; exact (args arg).propโฉ + +def TermAtDepth.bound {n : โ} (a : ๐ธ) (f : sig.bound) (args : sig.boundArgs f โ TermAtDepth ๐ธ sig X n) : + TermAtDepth ๐ธ sig X (n + sig.boundDepth f) := + โจ.bound a f (Subtype.val โ args), by constructor; intro arg; exact (args arg).propโฉ + def Substitution (sig : Signature) (X : Type) [NominalSet ๐ธ X] (Y : Type) [NominalSet ๐ธ Y] (l : โ) := X โ TermAtDepth ๐ธ sig Y l -private def Substitution.apply' {l : โ} (ฯ : Substitution ๐ธ sig X Y l) : Term ๐ธ sig X โ Term ๐ธ sig Y +def Substitution.apply {l : โ} (ฯ : Substitution ๐ธ sig X Y l) : Term ๐ธ sig X โ Term ๐ธ sig Y | .var x => (ฯ x).val - | .pure f args => .pure f (fun x => ฯ.apply' (args x)) - | .free a f args => .free a f (fun x => ฯ.apply' (args x)) - | .bound a f args => .bound a f (fun x => ฯ.apply' (args x)) + | .pure f args => .pure f (fun x => ฯ.apply (args x)) + | .free a f args => .free a f (fun x => ฯ.apply (args x)) + | .bound a f args => .bound a f (fun x => ฯ.apply (args x)) -def Substitution.apply {n l : โ} (ฯ : Substitution ๐ธ sig X Y l) (t : TermAtDepth ๐ธ sig X n) : +def Substitution.applyUniform {n l : โ} (ฯ : Substitution ๐ธ sig X Y l) (t : TermAtDepth ๐ธ sig X n) : TermAtDepth ๐ธ sig Y (n + l) := - โจฯ.apply' ๐ธ t.val, by - suffices โ t n, t.HasDepth ๐ธ n โ (ฯ.apply' ๐ธ t).HasDepth ๐ธ (n + l) by + โจฯ.apply ๐ธ t.val, by + suffices โ t n, t.HasDepth ๐ธ n โ (ฯ.apply ๐ธ t).HasDepth ๐ธ (n + l) by exact this t.val n t.prop - intro t; fun_induction apply' + intro t; fun_induction apply ยท intro n h; cases h rw [Nat.zero_add] exact (ฯ _).prop @@ -79,21 +93,36 @@ def Substitution.apply {n l : โ} (ฯ : Substitution ๐ธ sig X Y l) (t : TermA constructor; intro arg apply ih1; exact h argโฉ -private def rename' (ฯ : FPerm ๐ธ) : Term ๐ธ sig X โ Term ๐ธ sig X +@[simp] lemma Substitution.apply_var {l : โ} {x : X} {ฯ : Substitution ๐ธ sig X Y l} : + ฯ.apply ๐ธ (.var x) = (ฯ x).val := rfl + +@[simp] lemma Substitution.apply_pure + {f : sig.pure} {args : sig.pureArgs f โ Term ๐ธ sig X} {l : โ} {ฯ : Substitution ๐ธ sig X Y l} : + ฯ.apply ๐ธ (.pure f args) = .pure f (apply ๐ธ ฯ โ args) := rfl + +@[simp] lemma Substitution.apply_free + {a : ๐ธ} {f : sig.free} {args : sig.freeArgs f โ Term ๐ธ sig X} {l : โ} {ฯ : Substitution ๐ธ sig X Y l} : + ฯ.apply ๐ธ (.free a f args) = .free a f (apply ๐ธ ฯ โ args) := rfl + +@[simp] lemma Substitution.apply_bound + {a : ๐ธ} {f : sig.bound} {l : โ} {args : sig.boundArgs f โ Term ๐ธ sig X} {ฯ : Substitution ๐ธ sig X Y l} : + ฯ.apply ๐ธ (.bound a f args) = .bound a f (apply ๐ธ ฯ โ args) := rfl + +private def rename (ฯ : FPerm ๐ธ) : Term ๐ธ sig X โ Term ๐ธ sig X | .var x => .var (ฯ โข x) - | .pure f args => .pure f (fun x => rename' ฯ (args x)) - | .free a f args => .free (ฯ โข a) f (fun x => rename' ฯ (args x)) - | .bound a f args => .bound (ฯ โข a) f (fun x => rename' ฯ (args x)) + | .pure f args => .pure f (fun x => rename ฯ (args x)) + | .free a f args => .free (ฯ โข a) f (fun x => rename ฯ (args x)) + | .bound a f args => .bound (ฯ โข a) f (fun x => rename ฯ (args x)) -private lemma one_rename (t : Term ๐ธ sig X) : rename' ๐ธ 1 t = t := by - induction' t <;> all_goals simp [rename', *] +private lemma one_rename (t : Term ๐ธ sig X) : rename ๐ธ 1 t = t := by + induction' t <;> all_goals simp [rename, *] private lemma mul_rename (ฯ ฯ : FPerm ๐ธ) (t : Term ๐ธ sig X) : - rename' ๐ธ (ฯ * ฯ) t = rename' ๐ธ ฯ (rename' ๐ธ ฯ t) := by - induction' t <;> all_goals simp [rename', mul_smul, *] + rename ๐ธ (ฯ * ฯ) t = rename ๐ธ ฯ (rename ๐ธ ฯ t) := by + induction' t <;> all_goals simp [rename, mul_smul, *] instance : PermSet ๐ธ (Term ๐ธ sig X) where - smul := rename' ๐ธ + smul := rename ๐ธ one_smul := one_rename ๐ธ mul_smul := mul_rename ๐ธ @@ -159,21 +188,10 @@ private lemma atoms_support (t : Term ๐ธ sig X) : PermSet.HasSupport ๐ธ t (a apply PermSet.fix_antitone_mem ๐ธ hฯ apply Set.subset_sUnion_of_mem use x - ยท intro hฯ - simp only [PermSet.fix', smul_free, Term.free.injEq, heq_eq_eq, true_and, Set.mem_setOf_eq] - constructor - ยท apply PermSet.fix_antitone_mem ๐ธ hฯ - apply Set.subset_union_left - rfl - ยท ext x - rw [Function.comp_apply] - apply ih1 - apply PermSet.fix_antitone_mem ๐ธ hฯ - apply Set.subset_union_of_subset_right - apply Set.subset_sUnion_of_mem - use x - ยท intro hฯ - simp only [PermSet.fix', smul_bound, Term.bound.injEq, heq_eq_eq, true_and, Set.mem_setOf_eq] + all_goals + intro hฯ + simp only [PermSet.fix', smul_free, smul_bound, Term.free.injEq, Term.bound.injEq, heq_eq_eq, + true_and, Set.mem_setOf_eq] constructor ยท apply PermSet.fix_antitone_mem ๐ธ hฯ apply Set.subset_union_left @@ -191,21 +209,18 @@ instance : NominalSet ๐ธ (Term ๐ธ sig X) where use atoms ๐ธ t exact โจatoms_support ๐ธ t, atoms_finite ๐ธ tโฉ -private def rename {n : โ} (ฯ : FPerm ๐ธ) (t : TermAtDepth ๐ธ sig X n) : TermAtDepth ๐ธ sig X n := - โจฯ โข t.val, by - suffices โ t n, t.HasDepth ๐ธ n โ (rename' ๐ธ ฯ t).HasDepth ๐ธ n by - exact this t.val n t.prop - intro t; fun_induction rename' - ยท intro n h; cases h; constructor - all_goals - intro n h; cases h - expose_names - constructor; intro arg - apply ih1; exact h argโฉ - -instance Term.instHasDepthEquivariant {n : โ} : Set.Equivariant ๐ธ {t : Term ๐ธ sig X | HasDepth ๐ธ t n} := by +instance Term.instHasDepthEquivariant {n : โ} : + Set.Equivariant ๐ธ {t : Term ๐ธ sig X | HasDepth ๐ธ t n} := by constructor; intro t ฯ ht - exact (rename ๐ธ ฯ โจt, htโฉ).prop + suffices โ t n, t.HasDepth ๐ธ n โ (rename ๐ธ ฯ t).HasDepth ๐ธ n by + exact this t n ht + intro t; fun_induction rename + ยท intro n h; cases h; constructor + all_goals + intro n h; cases h + expose_names + constructor; intro arg + apply ih1; exact h arg instance {n : โ} : NominalSet ๐ธ (TermAtDepth ๐ธ sig X n) := (Subtype.instNominalSetElem ๐ธ : NominalSet ๐ธ {t : Term ๐ธ sig X | Term.HasDepth ๐ธ t n}) |
