import Mathlib import Nominal.Permutations import Nominal.Support /-! # Definitions and Properties for Equivariance We define equivariance for functions, sets, and binary relations. -/ variable (๐”ธ : Type) [Infinite ๐”ธ] [Countable ๐”ธ] [DecidableEq ๐”ธ] /-! ## Definitions Basic definitions for equivariance. -/ section Definition variable {X Y : Type} [PermSet ๐”ธ X] [PermSet ๐”ธ Y] /-- A function is equivariant if it is invariant to applying a permutation before or after the function. -/ def Equivariant (f : X โ†’ Y) : Prop := โˆ€ (x : X) (ฯ€ : FPerm ๐”ธ), f (ฯ€ โ€ข x) = ฯ€ โ€ข f x /-- A set is equivariant if it is closed under permutations. -/ def EquivariantSet (S : Set X) : Prop := โˆ€ (x : X) (ฯ€ : FPerm ๐”ธ), x โˆˆ S โ†’ ฯ€ โ€ข x โˆˆ S /-- A binary relation is equivariant if it is closed under permutations. -/ def EquivariantRelation (R : Rel X Y) : Prop := โˆ€ (x : X) (y : Y) (ฯ€ : FPerm ๐”ธ), R x y โ†’ R (ฯ€ โ€ข x) (ฯ€ โ€ข y) /-- Extended setoid definition that also requires the relation to be equivariant. -/ class EquivariantSetoid (X : Type) [PermSet ๐”ธ X] extends Setoid X where equivariant : EquivariantRelation ๐”ธ r /-- For equivariant sets, we even have "if and only if". -/ lemma equivariant_set_iff {S : Set X} : EquivariantSet ๐”ธ S โ†” โˆ€ (x : X) (ฯ€ : FPerm ๐”ธ), x โˆˆ S โ†” ฯ€ โ€ข x โˆˆ S := by constructor ยท intro h x ฯ€; constructor ยท intro hx; exact h x ฯ€ hx ยท intro hx apply (h (ฯ€ โ€ข x) ฯ€โปยน) at hx simp only [inv_smul_smul] at hx exact hx ยท intro h x ฯ€ hx exact (h x ฯ€).mp hx /-- For equivariant relations, we even have "if and only if". -/ lemma equivariant_relation_iff {R : Rel X Y} : EquivariantRelation ๐”ธ R โ†” โˆ€ (x : X) (y : Y) (ฯ€ : FPerm ๐”ธ), R x y โ†” R (ฯ€ โ€ข x) (ฯ€ โ€ข y) := by constructor ยท intro h x y ฯ€; constructor ยท intro hxy; exact h x y ฯ€ hxy ยท intro hxy apply (h (ฯ€ โ€ข x) (ฯ€ โ€ข y) ฯ€โปยน) at hxy simp only [inv_smul_smul] at hxy exact hxy ยท intro h x y ฯ€ hxy exact (h x y ฯ€).mp hxy end Definition /-! ## Trivial Instances Some trivial instances of equivariant functions, sets, and relations. -/ section Trivial variable {X Y Z : Type} [PermSet ๐”ธ X] [PermSet ๐”ธ Y] [PermSet ๐”ธ Z] /-- The identity function is equivariant. -/ lemma id_equivariant : Equivariant ๐”ธ (id : X โ†’ X) := by simp [Equivariant] /-- The composition of two equivariant functions is equivariant. -/ lemma comp_equivariant {f : Y โ†’ Z} {g : X โ†’ Y} : Equivariant ๐”ธ f โ†’ Equivariant ๐”ธ g โ†’ Equivariant ๐”ธ (f โˆ˜ g) := by intro hf hg x ฯ€ calc f (g (ฯ€ โ€ข x)) = f (ฯ€ โ€ข g x) := by rw [hg] _ = ฯ€ โ€ข (f (g x)) := by rw [hf] /-- The subset relation is equivariant. -/ lemma subset_equivariant : EquivariantRelation ๐”ธ (Set.Subset : Set X โ†’ Set X โ†’ Prop) := by intro S T ฯ€ hST x hx rw [Set.mem_smul_set_iff_inv_smul_mem] at hx rw [Set.mem_smul_set_iff_inv_smul_mem] exact hST hx end Trivial /-! ## Support Propositions relating equivariance to support in (FPerm ๐”ธ)-sets. -/ section Support variable {X Y : Type} [PermSet ๐”ธ X] [PermSet ๐”ธ Y] namespace Equivariant /-- Equivariant functions preserve supports. -/ lemma preserve_support {x : X} {f : X โ†’ Y} {S : Set ๐”ธ} : Equivariant ๐”ธ f โ†’ PermSet.HasSupport ๐”ธ x S โ†’ PermSet.HasSupport ๐”ธ (f x) S := by intro hequi hsupp ฯ€ hฯ€ calc ฯ€ โ€ข f x = f (ฯ€ โ€ข x) := by rw [โ† hequi] _ = f x := by rw [hsupp hฯ€] /-- Equivariant injective functions exactly preserve supports. -/ lemma preserve_support_inj {x : X} {f : X โ†’ Y} {S : Set ๐”ธ} : Equivariant ๐”ธ f โ†’ f.Injective โ†’ (PermSet.HasSupport ๐”ธ x S โ†” PermSet.HasSupport ๐”ธ (f x) S) := by intro hequi hinj; constructor ยท exact preserve_support ๐”ธ hequi ยท intro hsupp ฯ€ hฯ€ by_contra h have : ฯ€ โ€ข f x โ‰  f x := by rw [โ† hequi]; exact fun a => h (hinj a) have : ฯ€ โ€ข f x = f x := hsupp hฯ€ contradiction end Equivariant /-- HasSupport is an equivariant relation. -/ lemma PermSet.support_equivariant : EquivariantRelation ๐”ธ (HasSupport ๐”ธ : X โ†’ Set ๐”ธ โ†’ Prop) := by intro x S ฯ€ hS ฯƒ hฯƒ have hfix : (ฯ€โปยน * ฯƒ * ฯ€) โˆˆ fix ๐”ธ S := by intro a ha calc (ฯ€โปยน * ฯƒ * ฯ€) โ€ข a = ฯ€โปยน โ€ข (ฯƒ โ€ข (ฯ€ โ€ข a)) := rfl _ = ฯ€โปยน โ€ข (ฯ€ โ€ข a) := by rw [hฯƒ (ฯ€ โ€ข a) (Set.smul_mem_smul_set ha)] _ = (ฯ€โปยน * ฯ€) โ€ข a := rfl _ = (1 : FPerm ๐”ธ) โ€ข a := by rw [@Group.inv_mul_cancel] _ = a := rfl calc ฯƒ โ€ข (ฯ€ โ€ข x) = (ฯƒ * ฯ€) โ€ข x := by apply smul_smul _ = (1 * ฯƒ * ฯ€) โ€ข x := rfl _ = (ฯ€ * ฯ€โปยน * ฯƒ * ฯ€) โ€ข x := by rw [@mul_inv_cancel] _ = ฯ€ โ€ข ((ฯ€โปยน * ฯƒ * ฯ€) โ€ข x) := by symm; apply smul_smul _ = ฯ€ โ€ข x := by rw [hS hfix] end Support /-! ## Nominal Sets Properties about equivariance relating to nominal sets. -/ section Nominal variable {X Y : Type} [NominalSet ๐”ธ X] [NominalSet ๐”ธ Y] namespace Equivariant /-- If f is equivariant, then supp (f x) โІ supp x. -/ lemma supp_subset {x : X} {f : X โ†’ Y} : Equivariant ๐”ธ f โ†’ NominalSet.supp ๐”ธ (f x) โІ NominalSet.supp ๐”ธ x := by intro hequi apply NominalSet.support_subset_supp ยท exact preserve_support ๐”ธ hequi (NominalSet.supp_is_support ๐”ธ) ยท exact NominalSet.supp_finite ๐”ธ /-- If f is equivariant and injective, then supp (f x) = supp x. -/ lemma supp_eq_if_inj {x : X} {f : X โ†’ Y} : Equivariant ๐”ธ f โ†’ Function.Injective f โ†’ NominalSet.supp ๐”ธ (f x) = NominalSet.supp ๐”ธ x := by intro hequi hinj simp [NominalSet.supp, preserve_support_inj ๐”ธ hequi hinj] end Equivariant /-- If there is an equivariant surjection from a nominal set into an (FPerm ๐”ธ)-Set, then that set is nominal. -/ def NominalSet.fromEquivariantSurjective {X Y : Type} [NominalSet ๐”ธ X] [PermSet ๐”ธ Y] (f : X โ†’ Y) (hequi : Equivariant ๐”ธ f) (hsurj : Function.Surjective f) : NominalSet ๐”ธ Y where fin_supp := by intro y obtain โŸจx, hxโŸฉ := hsurj y use (NominalSet.supp ๐”ธ x) constructor ยท rw [โ† hx] exact Equivariant.preserve_support ๐”ธ hequi (supp_is_support ๐”ธ) ยท exact supp_finite ๐”ธ /-- supp is an equivariant function. -/ lemma NominalSet.supp_equivariant : Equivariant ๐”ธ (supp ๐”ธ : X โ†’ Set ๐”ธ) := by intro x ฯ€; ext a; constructor ยท apply support_subset_supp ๐”ธ ยท apply PermSet.support_equivariant exact supp_is_support ๐”ธ ยท apply Set.Finite.smul_set exact supp_finite ๐”ธ ยท intro ha S hS have hsupp : PermSet.HasSupport ๐”ธ x (ฯ€โปยน โ€ข S) := by rw [show x = ฯ€โปยน โ€ข ฯ€ โ€ข x by exact eq_inv_smul_iff.mpr rfl] apply PermSet.support_equivariant exact hS.out.left rw [Set.mem_smul_set_iff_inv_smul_mem] at ha suffices ฯ€โปยน โ€ข a โˆˆ ฯ€โปยน โ€ข S by rw [Set.smul_mem_smul_set_iff] at this; assumption suffices supp ๐”ธ x โІ ฯ€โปยน โ€ข S by exact this ha apply support_subset_supp ๐”ธ ยท exact hsupp ยท apply Set.Finite.smul_set exact hS.out.right /-- Freshness is an equivariant relation. -/ lemma NominalSet.fresh_equivariant : EquivariantRelation ๐”ธ (NominalSet.IsFresh : ๐”ธ โ†’ X โ†’ Prop) := by intro x y ฯ€ h rwa [IsFresh, supp_equivariant, Set.smul_mem_smul_set_iff] end Nominal /-! ## Freshness For propositions of the form `ะ˜ a, a R x`, where `R` is an equivariant relation, we do not have to differentiate between "for any fresh a" and "for all fresh a". -/ section Freshness namespace Equivariance variable {X : Type} [NominalSet ๐”ธ X] {R: Rel ๐”ธ X} {x : X} -- We continue with a circular implication chain argument to show these equivalences. private lemma for_fresh_iffโ‚ : EquivariantRelation ๐”ธ R โ†’ (ะ˜ a, R a x) โ†’ (โˆƒ a, a # x โˆง R a x) := by intro hequi h apply Set.Finite.infinite_compl at h simp at h have hinf : ({a | R a x} \ NominalSet.supp ๐”ธ x).Infinite := Set.Infinite.diff h (NominalSet.supp_finite ๐”ธ) obtain โŸจa, haโŸฉ := hinf.nonempty simp only [Set.mem_diff, Set.mem_setOf_eq] at ha use a; exact ha.symm private lemma for_fresh_iffโ‚‚ : EquivariantRelation ๐”ธ R โ†’ (โˆƒ a, a # x โˆง R a x) โ†’ (โˆ€ a, a # x โ†’ R a x) := by intro hequi h obtain โŸจa, โŸจhfresha, haโŸฉโŸฉ := h intro b hfreshb have hmem := hequi a x โธจa, bโธฉ ha rw [PermSet.atom_swap, Equiv.swap_apply_left] at hmem rw [NominalSet.fresh_swap_fix ๐”ธ hfresha hfreshb] at hmem exact hmem private lemma for_fresh_iffโ‚ƒ : EquivariantRelation ๐”ธ R โ†’ (โˆ€ a, a # x โ†’ R a x) โ†’ (ะ˜ a, R a x) := by intro hequi h have hsub : {a : ๐”ธ | R a x}แถœ โІ NominalSet.supp ๐”ธ x := by rw [Set.compl_subset_comm] intro a ha rw [Set.mem_compl_iff] at ha exact h a ha simp only [NominalSet.ForFresh] apply Set.Finite.subset (NominalSet.supp_finite ๐”ธ) hsub /-- The quantifier in `ะ˜ a, a R x` is equivalent to "for any fresh `a`". -/ lemma for_fresh_iff_exists : EquivariantRelation ๐”ธ R โ†’ ((ะ˜ a, R a x) โ†” (โˆƒ a, a # x โˆง R a x)) := by intro hequi; constructor ยท intro h apply for_fresh_iffโ‚ ๐”ธ hequi exact h ยท intro h apply for_fresh_iffโ‚ƒ ๐”ธ hequi apply for_fresh_iffโ‚‚ ๐”ธ hequi exact h /-- The quantifier in `ะ˜ a, a R x` is equivalent to "for all fresh `a`". -/ lemma for_fresh_iff_all : EquivariantRelation ๐”ธ R โ†’ ((ะ˜ a, R a x) โ†” (โˆ€ a, a # x โ†’ R a x)) := by intro hequi; constructor ยท intro h apply for_fresh_iffโ‚‚ ๐”ธ hequi apply for_fresh_iffโ‚ ๐”ธ hequi exact h ยท intro h apply for_fresh_iffโ‚ƒ ๐”ธ hequi exact h end Equivariance end Freshness /-! ## Bundled Functions In the following, we also define a bundled function type for equivariant functions. -/ section BundledFunction /-- A function carrying a proof of its equivariance. -/ structure EquivariantMap (X Y : Type) [PermSet ๐”ธ X] [PermSet ๐”ธ Y] where /-- The underlying function. -/ toFun : X โ†’ Y /-- Proof of equivariance. -/ equivariant : Equivariant ๐”ธ toFun /-- We write `X โ†’โ‚‘ Y` or `X โ†’โ‚‘[๐”ธ] Y` for an equivariant map X โ†’ Y. -/ infixr:25 " โ†’โ‚‘ " => EquivariantMap _ /-- We write `X โ†’โ‚‘ Y` or `X โ†’โ‚‘[๐”ธ] Y` for an equivariant map X โ†’ Y. -/ notation:25 X " โ†’โ‚‘[" A "] " Y => EquivariantMap A X Y variable {X Y Z : Type} [PermSet ๐”ธ X] [PermSet ๐”ธ Y] [PermSet ๐”ธ Z] instance : FunLike (X โ†’โ‚‘[๐”ธ] Y) X Y where coe := EquivariantMap.toFun coe_injective' f g h := by cases f; cases g; congr namespace EquivariantMap /-- The identity function. -/ def id : X โ†’โ‚‘[๐”ธ] X := โŸจ_root_.id, id_equivariant ๐”ธโŸฉ /-- Function composition. -/ def comp (f : Y โ†’โ‚‘[๐”ธ] Z) (g : X โ†’โ‚‘[๐”ธ] Y) : X โ†’โ‚‘[๐”ธ] Z := โŸจf โˆ˜ g, comp_equivariant ๐”ธ f.equivariant g.equivariantโŸฉ @[simp] lemma toFun_eq_coe {f : X โ†’โ‚‘[๐”ธ] Y} : f.toFun = (f : X โ†’ Y) := rfl @[ext] lemma ext {f g : X โ†’โ‚‘[๐”ธ] Y} (h : โˆ€ a, f a = g a) : f = g := DFunLike.ext _ _ h end EquivariantMap end BundledFunction