Skip to content
This repository was archived by the owner on Jul 24, 2024. It is now read-only.

Commit 4ec60c3

Browse files
committed
feat(algebra/pointwise): pointwise addition and multiplication of sets
1 parent 410ae5d commit 4ec60c3

File tree

1 file changed

+167
-0
lines changed

1 file changed

+167
-0
lines changed

src/algebra/pointwise.lean

Lines changed: 167 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,167 @@
1+
import data.set.lattice
2+
import algebra.group
3+
import group_theory.subgroup
4+
5+
namespace set
6+
open function
7+
8+
variables {α : Type*} {β : Type*} (f : α → β)
9+
10+
@[to_additive set.pointwise_zero]
11+
def pointwise_one [has_one α] : has_one (set α) := ⟨{1}⟩
12+
13+
local attribute [instance] pointwise_one
14+
15+
@[simp, to_additive set.mem_pointwise_zero]
16+
lemma mem_pointwise_one [has_one α] (a : α) :
17+
a ∈ (1 : set α) ↔ a = 1 :=
18+
mem_singleton_iff
19+
20+
@[to_additive set.pointwise_add]
21+
def pointwise_mul [has_mul α] : has_mul (set α) :=
22+
⟨λ s t, {a | ∃ x ∈ s, ∃ y ∈ t, a = x * y}⟩
23+
24+
local attribute [instance] pointwise_one pointwise_mul
25+
26+
@[to_additive set.mem_pointwise_add]
27+
lemma mem_pointwise_mul [has_mul α] {s t : set α} {a : α} :
28+
a ∈ s * t ↔ ∃ x ∈ s, ∃ y ∈ t, a = x * y := iff.rfl
29+
30+
def pointwise_mul_semigroup [semigroup α] : semigroup (set α) :=
31+
{ mul_assoc := λ s t u,
32+
begin
33+
ext a, split,
34+
{ rintros ⟨_, ⟨x, _, y, _, rfl⟩, z, _, rfl⟩,
35+
exact ⟨_, ‹_›, _, ⟨_, ‹_›, _, ‹_›, rfl⟩, mul_assoc _ _ _⟩ },
36+
{ rintros ⟨x, _, _, ⟨y, _, z, _, rfl⟩, rfl⟩,
37+
exact ⟨_, ⟨_, ‹_›, _, ‹_›, rfl⟩, _, ‹_›, (mul_assoc _ _ _).symm⟩ }
38+
end,
39+
..pointwise_mul }
40+
41+
def pointwise_add_add_semigroup [add_semigroup α] : add_semigroup (set α) :=
42+
{ add_assoc := λ s t u,
43+
begin
44+
ext a, split,
45+
{ rintros ⟨_, ⟨x, _, y, _, rfl⟩, z, _, rfl⟩,
46+
exact ⟨_, ‹_›, _, ⟨_, ‹_›, _, ‹_›, rfl⟩, add_assoc _ _ _⟩ },
47+
{ rintros ⟨x, _, _, ⟨y, _, z, _, rfl⟩, rfl⟩,
48+
exact ⟨_, ⟨_, ‹_›, _, ‹_›, rfl⟩, _, ‹_›, (add_assoc _ _ _).symm⟩ }
49+
end,
50+
..pointwise_add }
51+
52+
attribute [to_additive set.pointwise_add_add_semigroup._proof_1] pointwise_mul_semigroup._proof_1
53+
attribute [to_additive set.pointwise_add_add_semigroup] pointwise_mul_semigroup
54+
55+
def pointwise_mul_monoid [monoid α] : monoid (set α) :=
56+
{ one_mul := λ s, set.ext $ λ a,
57+
by {rintros ⟨_, _, _, _, rfl⟩, simp * at *},
58+
λ h, ⟨1, mem_singleton 1, a, h, (one_mul a).symm⟩⟩,
59+
mul_one := λ s, set.ext $ λ a,
60+
by {rintros ⟨_, _, _, _, rfl⟩, simp * at *},
61+
λ h, ⟨a, h, 1, mem_singleton 1, (mul_one a).symm⟩⟩,
62+
..pointwise_mul_semigroup,
63+
..pointwise_one }
64+
65+
def pointwise_add_add_monoid [add_monoid α] : add_monoid (set α) :=
66+
{ zero_add := λ s, set.ext $ λ a,
67+
by {rintros ⟨_, _, _, _, rfl⟩, simp * at *},
68+
λ h, ⟨0, mem_singleton 0, a, h, (zero_add a).symm⟩⟩,
69+
add_zero := λ s, set.ext $ λ a,
70+
by {rintros ⟨_, _, _, _, rfl⟩, simp * at *},
71+
λ h, ⟨a, h, 0, mem_singleton 0, (add_zero a).symm⟩⟩,
72+
..pointwise_add_add_semigroup,
73+
..pointwise_zero }
74+
75+
attribute [to_additive set.pointwise_add_add_monoid._proof_1] pointwise_mul_monoid._proof_1
76+
attribute [to_additive set.pointwise_add_add_monoid._proof_2] pointwise_mul_monoid._proof_2
77+
attribute [to_additive set.pointwise_add_add_monoid._proof_3] pointwise_mul_monoid._proof_3
78+
attribute [to_additive set.pointwise_add_add_monoid] pointwise_mul_monoid
79+
80+
local attribute [instance] pointwise_mul_monoid
81+
82+
@[to_additive set.singleton.is_add_hom]
83+
def singleton.is_mul_hom [has_mul α] : is_mul_hom (singleton : α → set α) :=
84+
{ map_mul := λ x y, set.ext $ λ a, by simp [mem_singleton_iff, mem_pointwise_mul] }
85+
86+
@[to_additive set.singleton.is_add_monoid_hom]
87+
def singleton.is_monoid_hom [monoid α] : is_monoid_hom (singleton : α → set α) :=
88+
{ map_one := rfl, ..singleton.is_mul_hom }
89+
90+
@[to_additive set.pointwise_neg]
91+
def pointwise_inv [has_inv α] : has_inv (set α) :=
92+
⟨λ s, {a | a⁻¹ ∈ s}⟩
93+
94+
@[simp] lemma pointwise_mul_empty [has_mul α] (s : set α) :
95+
s * ∅ = ∅ :=
96+
set.ext $ λ a, ⟨by {rintros ⟨_, _, _, _, rfl⟩, tauto}, false.elim⟩
97+
98+
@[simp] lemma empty_pointwise_mul [has_mul α] (s : set α) :
99+
∅ * s = ∅ :=
100+
set.ext $ λ a, ⟨by {rintros ⟨_, _, _, _, rfl⟩, tauto}, false.elim⟩
101+
102+
lemma pointwise_mul_union [has_mul α] (s t u : set α) :
103+
s * (t ∪ u) = (s * t) ∪ (s * u) :=
104+
begin
105+
ext a, split,
106+
{ rintros ⟨_, _, _, H, rfl⟩,
107+
cases H; [left, right]; exact ⟨_, ‹_›, _, ‹_›, rfl⟩ },
108+
{ intro H,
109+
cases H with H H;
110+
{ rcases H with ⟨_, _, _, _, rfl⟩,
111+
refine ⟨_, ‹_›, _, _, rfl⟩,
112+
erw mem_union,
113+
simp * } }
114+
end
115+
116+
lemma union_pointwise_mul [has_mul α] (s t u : set α) :
117+
(s ∪ t) * u = (s * u) ∪ (t * u) :=
118+
begin
119+
ext a, split,
120+
{ rintros ⟨_, H, _, _, rfl⟩,
121+
cases H; [left, right]; exact ⟨_, ‹_›, _, ‹_›, rfl⟩ },
122+
{ intro H,
123+
cases H with H H;
124+
{ rcases H with ⟨_, _, _, _, rfl⟩;
125+
refine ⟨_, _, _, ‹_›, rfl⟩;
126+
erw mem_union;
127+
simp * } }
128+
end
129+
130+
def pointwise_mul_semiring [monoid α] : semiring (set α) :=
131+
{ add := (⊔),
132+
zero := ∅,
133+
add_assoc := set.union_assoc,
134+
zero_add := set.empty_union,
135+
add_zero := set.union_empty,
136+
add_comm := set.union_comm,
137+
zero_mul := empty_pointwise_mul,
138+
mul_zero := pointwise_mul_empty,
139+
left_distrib := pointwise_mul_union,
140+
right_distrib := union_pointwise_mul,
141+
..pointwise_mul_monoid }
142+
143+
def pointwise_mul_comm_semiring [comm_monoid α] : comm_semiring (set α) :=
144+
{ mul_comm := λ s t, set.ext $ λ a,
145+
by split; { rintros ⟨_, _, _, _, rfl⟩, rw mul_comm, exact ⟨_, ‹_›, _, ‹_›, rfl⟩ },
146+
..pointwise_mul_semiring }
147+
148+
local attribute [instance] pointwise_mul_semiring
149+
150+
variables [monoid α] [monoid β] [is_monoid_hom f]
151+
152+
instance : is_semiring_hom (image f) :=
153+
{ map_zero := image_empty _,
154+
map_one := by erw [image_singleton, is_monoid_hom.map_one f]; refl,
155+
map_add := image_union _,
156+
map_mul := λ s t, set.ext $ λ a,
157+
begin
158+
split,
159+
{ rintros ⟨_, ⟨_, _, _, _, rfl⟩, rfl⟩,
160+
refine ⟨_, ⟨_, ‹_›, rfl⟩, _, ⟨_, ‹_›, rfl⟩, _⟩,
161+
apply is_monoid_hom.map_mul f },
162+
{ rintros ⟨_, ⟨_, _, rfl⟩, _, ⟨_, _, rfl⟩, rfl⟩,
163+
refine ⟨_, ⟨_, ‹_›, _, ‹_›, rfl⟩, _⟩,
164+
apply is_monoid_hom.map_mul f }
165+
end }
166+
167+
end set

0 commit comments

Comments
 (0)