diff options
| -rw-r--r-- | Algebra.lean | 1 | ||||
| -rw-r--r-- | Algebra/Term.lean | 117 | ||||
| -rw-r--r-- | lakefile.toml | 6 |
3 files changed, 123 insertions, 1 deletions
diff --git a/Algebra.lean b/Algebra.lean new file mode 100644 index 0000000..73c5f4e --- /dev/null +++ b/Algebra.lean @@ -0,0 +1 @@ +import Algebra.Term diff --git a/Algebra/Term.lean b/Algebra/Term.lean new file mode 100644 index 0000000..20fd009 --- /dev/null +++ b/Algebra/Term.lean @@ -0,0 +1,117 @@ +import Mathlib +import Nominal + +namespace Algebra + +variable (πΈ : Type) [Infinite πΈ] [Countable πΈ] [DecidableEq πΈ] + +/-- A graded signature. -/ +structure Signature where + pure : Type + free : Type + bound : Type + /-- Type representing the arguments required for an operation. -/ + args : pure β free β bound β Type + args_fintype : β f, Fintype (args f) := by intro; infer_instance + /-- Depth of an operation. -/ + depth : pure β free β bound β β + +def Signature.pureArgs (sig : Signature) (f : sig.pure) : Type := sig.args (.inl f) +def Signature.freeArgs (sig : Signature) (f : sig.free) : Type := sig.args (.inr (.inl f)) +def Signature.boundArgs (sig : Signature) (f : sig.bound) : Type := sig.args (.inr (.inr f)) + +def Signature.pureArgs_fintype (sig : Signature) (f : sig.pure) : Fintype (sig.pureArgs f) := sig.args_fintype (.inl f) +def Signature.freeArgs_fintype (sig : Signature) (f : sig.free) : Fintype (sig.freeArgs f) := sig.args_fintype (.inr (.inl f)) +def Signature.boundArgs_fintype (sig : Signature) (f : sig.bound) : Fintype (sig.boundArgs f) := sig.args_fintype (.inr (.inr f)) + +def Signature.arity (sig : Signature) (f : sig.pure β sig.free β sig.bound) : β := (sig.args_fintype f).card +def Signature.pureArity (sig : Signature) (f : sig.pure) : β := sig.arity (.inl f) +def Signature.freeArity (sig : Signature) (f : sig.free) : β := sig.arity (.inr (.inl f)) +def Signature.boundArity (sig : Signature) (f : sig.bound) : β := sig.arity (.inr (.inr f)) + +def Signature.pureDepth (sig : Signature) (f : sig.pure) : β := sig.depth (.inl f) +def Signature.freeDepth (sig : Signature) (f : sig.free) : β := sig.depth (.inr (.inl f)) +def Signature.boundDepth (sig : Signature) (f : sig.bound) : β := sig.depth (.inr (.inr f)) + +variable {sig : Signature} +variable {X : Type} [NominalSet πΈ X] +variable {Y : Type} [NominalSet πΈ Y] + +inductive Term (sig : Signature) (X : Type) [NominalSet πΈ X] + | var (x : X) : Term sig X + | pure (f : sig.pure) (args : sig.pureArgs f β Term sig X) : Term sig X + | free (a : πΈ) (f : sig.free) (args : sig.freeArgs f β Term sig X) : Term sig X + | bound (a : πΈ) (f : sig.bound) (args : sig.boundArgs f β Term sig X) : Term sig X + +inductive Term.HasDepth : Term πΈ sig X β β β Prop + | var (x : X) : HasDepth (.var x) 0 + | pure (f : sig.pure) (args : sig.pureArgs f β Term πΈ sig X) (k : β) : + (β arg : sig.pureArgs f, HasDepth (args arg) k) β HasDepth (.pure f args) (k + sig.pureDepth f) + | free (a : πΈ) (f : sig.free) (args : sig.freeArgs f β Term πΈ sig X) (k : β) : + (β arg : sig.freeArgs f, HasDepth (args arg) k) β HasDepth (.free a f args) (k + sig.freeDepth f) + | bound (a : πΈ) (f : sig.bound) (args : sig.boundArgs f β Term πΈ sig X) (k : β) : + (β arg : sig.boundArgs f, HasDepth (args arg) k) β HasDepth (.bound a f args) (k + sig.boundDepth f) + +def TermAtDepth (sig : Signature) (X : Type) [NominalSet πΈ X] (n : β) := + { t : Term πΈ sig X // t.HasDepth πΈ n } + +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 + | .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)) + +def Substitution.apply {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 + exact this t.val n t.prop + intro t; fun_induction apply' + Β· intro n h; cases h + rw [Nat.zero_add] + exact (Ο _).prop + all_goals + intro n h; cases h; expose_names + rw [Nat.add_right_comm] + constructor; intro arg + apply ih1; exact h argβ© + +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)) + +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, *] + +instance : PermSet πΈ (Term πΈ sig X) where + smul := rename' πΈ + one_smul := one_rename πΈ + mul_smul := mul_rename πΈ + +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 {n : β} : PermSet πΈ (TermAtDepth πΈ sig X n) where + smul := rename πΈ + one_smul t := by apply Subtype.eq; exact one_rename πΈ t.val + mul_smul Ο Ο t := by apply Subtype.eq; exact mul_rename πΈ Ο Ο t.val + +end Algebra diff --git a/lakefile.toml b/lakefile.toml index e851548..21e9fc9 100644 --- a/lakefile.toml +++ b/lakefile.toml @@ -11,4 +11,8 @@ rev = "v4.25.0" name = "Nominal" [[lean_lib]] -name = "Graded"
\ No newline at end of file +name = "Graded" + +[[lean_lib]] +name = "Algebra" +needs = ["Nominal", "Graded"]
\ No newline at end of file |
