summaryrefslogtreecommitdiff
path: root/Nominal/Instances.lean
blob: b637b32c95a8031f642b6f78a90ad957691f7bbf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
import Mathlib
import Nominal.Support
import Nominal.Equivariance

/-!
# Instances

This file contains common instances of (FPerm 𝔸)-sets and nominal sets.
-/

variable (𝔸 : Type) [Infinite 𝔸] [Countable 𝔸] [DecidableEq 𝔸]

/-!
## Atoms

The set 𝔸 of atoms itself is a nominal set, where supp a = {a}.
-/
section Atoms

private lemma NominalSet.supp_atom' {a : 𝔸} : PermSet.HasSupport 𝔸 a {a} := by
  simp [PermSet.HasSupport, PermSet.fix, PermSet.fix']

instance : NominalSet 𝔸 𝔸 where
  fin_supp := by
    intro a; use {a}
    exact ⟨NominalSet.supp_atom' 𝔸, Set.finite_singleton a⟩

@[simp] lemma NominalSet.supp_atom {a : 𝔸} : supp 𝔸 a = {a} := by
  ext b; constructor
  · apply support_subset_supp 𝔸
    · exact NominalSet.supp_atom' 𝔸
    · exact Set.finite_singleton a
  · suffices a ∈ supp 𝔸 a by simp; intro h; rwa [h]
    intro S ⟨hsuppS, hfinS⟩
    by_contra ha
    -- Show that we can find a fresh c with (a c) ∈ fix S
    obtain ⟨c, hc⟩ := Infinite.exists_notMem_finset ({a} ∪ hfinS.toFinset)
    simp at hc
    have hfix : ⸨a, c⸩ ∈ PermSet.fix 𝔸 S := by
      intro d hd
      apply Equiv.Perm.supp_notin
      simp [FPerm.swap, Equiv.Perm.supp_swap, Ne.symm hc.left]
      exact ⟨ne_of_mem_of_not_mem hd ha, ne_of_mem_of_not_mem hd hc.right⟩
    have h₁ : ⸨a, c⸩ • a = c := by simp [show ⸨a,c⸩ • a = (Equiv.swap a c) a from rfl]
    have h₂ : ⸨a, c⸩ • a = a := by apply hsuppS; assumption
    rw [h₁] at h₂
    exact hc.left h₂

@[simp] lemma NominalSet.fresh_atom {a b : 𝔸} : a # b ↔ a ≠ b := by
  simp [IsFresh]

end Atoms

/-!
## Discrete Nominal Sets

Every set can be made into a discrete nominal set, where supp x = ∅.
-/
section Discrete

def NominalSet.discrete (X : Type) : DiscreteNominalSet 𝔸 X where
  smul π x := x
  one_smul := by intro; rfl
  mul_smul := by intro _ _ _; rfl
  is_discrete := by intro _ _; rfl
  fin_supp := by
    intro x; use {}
    constructor
    · intro π hπ; simp [PermSet.fix']; rfl
    · exact Set.finite_empty

@[simp] lemma NominalSet.supp_discrete {X : Type} [DiscreteNominalSet 𝔸 X] {x : X} : supp 𝔸 x = ∅ := by
  rw [← Set.subset_empty_iff]
  apply Set.sInter_subset_of_mem
  constructor
  · intro π hπ; simp [PermSet.fix', DiscreteNominalSet.is_discrete]
  · exact Set.finite_empty

@[simp] lemma NominalSet.fresh_discrete {X : Type} [DiscreteNominalSet 𝔸 X] {a : 𝔸} {x : X} : a # x := by
  simp [IsFresh]

/-- We consider Unit a discrete nominal set. -/
instance : DiscreteNominalSet 𝔸 Unit := NominalSet.discrete 𝔸 Unit

/-- We consider Bool a discrete nominal set. -/
instance : DiscreteNominalSet 𝔸 Bool := NominalSet.discrete 𝔸 Bool

end Discrete

/-!
## Products

Pairs of two nominal sets also form a nominal set, where supp (x, y) = supp x ∪ supp y.
-/
section Products

instance {X Y : Type} [PermSet 𝔸 X] [PermSet 𝔸 Y] : PermSet 𝔸 (X × Y) where

variable {X Y : Type} [NominalSet 𝔸 X] [NominalSet 𝔸 Y]

private lemma NominalSet.supp_product' {x : X} {y : Y} : PermSet.HasSupport 𝔸 (x, y) (supp 𝔸 x ∪ supp 𝔸 y) := by
  intro π hπ
  obtain ⟨hπ₁, hπ₂⟩ := PermSet.fix_union 𝔸 hπ
  exact Prod.mk_inj.mpr ⟨supp_is_support 𝔸 hπ₁, supp_is_support 𝔸 hπ₂⟩

instance : NominalSet 𝔸 (X × Y) where
  fin_supp := by
    intro ⟨x, y⟩; use NominalSet.supp 𝔸 x ∪ NominalSet.supp 𝔸 y
    exact ⟨NominalSet.supp_product' 𝔸, Set.Finite.union (NominalSet.supp_finite 𝔸) (NominalSet.supp_finite 𝔸)⟩

@[simp] lemma NominalSet.supp_product {x : X} {y : Y} : supp 𝔸 (x, y) = supp 𝔸 x ∪ supp 𝔸 y := by
  ext b; constructor
  · apply support_subset_supp
    · exact supp_product' 𝔸
    · exact Set.Finite.union (supp_finite 𝔸) (supp_finite 𝔸)
  · intro hb; cases hb with
    | inl hx =>
        intro S hS
        suffices PermSet.HasSupport 𝔸 x S by apply hx; exact ⟨this, hS.out.right⟩
        intro π hπ
        suffices π ∈ PermSet.fix' 𝔸 (x, y) by simp [PermSet.fix'] at this; exact this.left
        exact (hS.out.left hπ).out
    | inr hy =>
        intro S hS
        suffices PermSet.HasSupport 𝔸 y S by apply hy; exact ⟨this, hS.out.right⟩
        intro π hπ
        suffices π ∈ PermSet.fix' 𝔸 (x, y) by simp [PermSet.fix'] at this; exact this.right
        exact (hS.out.left hπ).out

@[simp] lemma NominalSet.fresh_product {a : 𝔸} {x : X} {y : Y} : a # (x, y) ↔ a # x ∧ a # y := by
  simp [IsFresh]

lemma NominalSet.supp_product_comm {x : X} {y : Y} : supp 𝔸 (x, y) = supp 𝔸 (y, x) := by
  simp; apply Set.union_comm

lemma Prod.fst_equivariant : Equivariant 𝔸 (Prod.fst : X × Y → X) := by
  simp [Equivariant]

lemma Prod.snd_equivariant : Equivariant 𝔸 (Prod.snd : X × Y → Y) := by
  simp [Equivariant]

end Products

/-!
## Coproducts

Sums of two nominal sets also form a nominal set, where supp (inl x) = supp x and supp (inr y) = supp y.
-/
section Coproducts

instance {X Y : Type} [PermSet 𝔸 X] [PermSet 𝔸 Y] : PermSet 𝔸 (X ⊕ Y) where

variable {X Y : Type} [NominalSet 𝔸 X] [NominalSet 𝔸 Y]

private lemma NominalSet.supp_coproduct₁' {x : X} : PermSet.HasSupport 𝔸 (.inl x : X ⊕ Y) (supp 𝔸 x) := by
  intro π hπ
  simp [PermSet.fix']
  exact supp_is_support 𝔸 hπ

private lemma NominalSet.supp_coproduct₂' {y : Y} : PermSet.HasSupport 𝔸 (.inr y : X ⊕ Y) (supp 𝔸 y) := by
  intro π hπ
  simp [PermSet.fix']
  exact supp_is_support 𝔸 hπ

instance : NominalSet 𝔸 (X ⊕ Y) where
  fin_supp := by
    intro xy
    cases xy with
    | inl x => use NominalSet.supp 𝔸 x; exact ⟨NominalSet.supp_coproduct₁' 𝔸, NominalSet.supp_finite 𝔸⟩
    | inr y => use NominalSet.supp 𝔸 y; exact ⟨NominalSet.supp_coproduct₂' 𝔸, NominalSet.supp_finite 𝔸⟩

@[simp] lemma NominalSet.supp_coproduct₁ {x : X} : supp 𝔸 (.inl x : X ⊕ Y) = supp 𝔸 x := by
  ext b; constructor
  · apply support_subset_supp
    · exact supp_coproduct₁' 𝔸
    · exact supp_finite 𝔸
  · intro hb S hS
    suffices PermSet.HasSupport 𝔸 x S by apply hb; exact ⟨this, hS.out.right⟩
    intro π hπ
    suffices π ∈ PermSet.fix' 𝔸 (.inl x : X ⊕ Y) by simp [PermSet.fix'] at this; exact this
    exact (hS.out.left hπ).out

@[simp] lemma NominalSet.supp_coproduct₂ {y : Y} : supp 𝔸 (.inr y : X ⊕ Y) = supp 𝔸 y := by
  ext b; constructor
  · apply support_subset_supp
    · exact supp_coproduct₂' 𝔸
    · exact supp_finite 𝔸
  · intro hb S hS
    suffices PermSet.HasSupport 𝔸 y S by apply hb; exact ⟨this, hS.out.right⟩
    intro π hπ
    suffices π ∈ PermSet.fix' 𝔸 (.inr y : X ⊕ Y) by simp [PermSet.fix'] at this; exact this
    exact (hS.out.left hπ).out

@[simp] lemma NominalSet.fresh_coproduct₁ {a : 𝔸} {x : X} : a # (.inl x : X ⊕ Y) ↔ a # x := by
  simp [IsFresh]

@[simp] lemma NominalSet.fresh_coproduct₂ {a : 𝔸} {y : Y} : a # (.inr y : X ⊕ Y) ↔ a # y := by
  simp [IsFresh]

lemma Sum.inl_equivariant : Equivariant 𝔸 (Sum.inl : X → X ⊕ Y) := by
  simp [Equivariant]

lemma Sum.inr_equivariant : Equivariant 𝔸 (Sum.inr : Y → X ⊕ Y) := by
  simp [Equivariant]

end Coproducts