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

Commit 2d395a9

Browse files
kim-embryangingechenChrisHughes24
committed
refactor(algebra/pi_instance): delete pi_instance file, and move instances to group/ring etc appropriately (#3513)
Co-authored-by: Bryan Gin-ge Chen <bryangingechen@gmail.com> Co-authored-by: Chris Hughes <chrishughes24@gmail.com>
1 parent ed33a99 commit 2d395a9

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+524
-530
lines changed

src/algebra/add_torsor.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Authors: Joseph Myers, Yury Kudryashov.
55
-/
66
import algebra.group.prod
77
import algebra.group.type_tags
8-
import algebra.pi_instances
8+
import algebra.group.pi
99
import data.equiv.basic
1010

1111
/-!

src/algebra/big_operators/pi.lean

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
/-
2+
Copyright (c) 2018 Simon Hudon. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Simon Hudon, Patrick Massot
5+
-/
6+
import algebra.ring.pi
7+
import algebra.big_operators
8+
import data.fintype.basic
9+
import algebra.group.prod
10+
/-!
11+
# Big operators for Pi Types
12+
13+
This file contains theorems relevant to big operators in binary and arbitrary product
14+
of monoids and groups
15+
-/
16+
17+
open_locale big_operators
18+
19+
namespace pi
20+
21+
@[to_additive]
22+
lemma list_prod_apply {α : Type*} {β : α → Type*} [∀a, monoid (β a)] (a : α) :
23+
∀ (l : list (Πa, β a)), l.prod a = (l.map (λf:Πa, β a, f a)).prod
24+
| [] := rfl
25+
| (f :: l) := by simp [mul_apply f l.prod a, list_prod_apply l]
26+
27+
@[to_additive]
28+
lemma multiset_prod_apply {α : Type*} {β : α → Type*} [∀a, comm_monoid (β a)] (a : α)
29+
(s : multiset (Πa, β a)) : s.prod a = (s.map (λf:Πa, β a, f a)).prod :=
30+
quotient.induction_on s $ assume l, begin simp [list_prod_apply a l] end
31+
32+
end pi
33+
34+
@[simp, to_additive]
35+
lemma finset.prod_apply {α : Type*} {β : α → Type*} {γ} [∀a, comm_monoid (β a)] (a : α)
36+
(s : finset γ) (g : γ → Πa, β a) : (∏ c in s, g c) a = ∏ c in s, g c a :=
37+
show (s.val.map g).prod a = (s.val.map (λc, g c a)).prod,
38+
by rw [pi.multiset_prod_apply, multiset.map_map]
39+
40+
@[to_additive prod_mk_sum]
41+
lemma prod_mk_prod {α β γ : Type*} [comm_monoid α] [comm_monoid β] (s : finset γ)
42+
(f : γ → α) (g : γ → β) : (∏ x in s, f x, ∏ x in s, g x) = ∏ x in s, (f x, g x) :=
43+
by haveI := classical.dec_eq γ; exact
44+
finset.induction_on s rfl (by simp [prod.ext_iff] {contextual := tt})
45+
46+
section single
47+
variables {I : Type*} [decidable_eq I] {Z : I → Type*}
48+
variables [Π i, add_comm_monoid (Z i)]
49+
50+
-- As we only defined `single` into `add_monoid`, we only prove the `finset.sum` version here.
51+
lemma finset.univ_sum_single [fintype I] (f : Π i, Z i) :
52+
∑ i, pi.single i (f i) = f :=
53+
begin
54+
ext a,
55+
rw [finset.sum_apply, finset.sum_eq_single a],
56+
{ simp, },
57+
{ intros b _ h, simp [h.symm], },
58+
{ intro h, exfalso, simpa using h, },
59+
end
60+
61+
@[ext]
62+
lemma add_monoid_hom.functions_ext [fintype I] (G : Type*)
63+
[add_comm_monoid G] (g h : (Π i, Z i) →+ G)
64+
(w : ∀ (i : I) (x : Z i), g (pi.single i x) = h (pi.single i x)) : g = h :=
65+
begin
66+
ext k,
67+
rw [←finset.univ_sum_single k, add_monoid_hom.map_sum, add_monoid_hom.map_sum],
68+
apply finset.sum_congr rfl,
69+
intros,
70+
apply w,
71+
end
72+
73+
end single
74+
75+
section ring_hom
76+
open pi
77+
variables {I : Type*} [decidable_eq I] {f : I → Type*}
78+
variables [Π i, semiring (f i)]
79+
80+
-- we need `apply`+`convert` because Lean fails to unify different `add_monoid` instances
81+
-- on `Π i, f i`
82+
@[ext]
83+
lemma ring_hom.functions_ext [fintype I] (G : Type*) [semiring G] (g h : (Π i, f i) →+* G)
84+
(w : ∀ (i : I) (x : f i), g (single i x) = h (single i x)) : g = h :=
85+
begin
86+
apply ring_hom.coe_add_monoid_hom_injective,
87+
convert add_monoid_hom.functions_ext _ _ _ _; assumption
88+
end
89+
90+
end ring_hom
91+
92+
namespace prod
93+
94+
variables {α β γ : Type*} [comm_monoid α] [comm_monoid β] {s : finset γ} {f : γ → α × β}
95+
96+
@[to_additive]
97+
lemma fst_prod : (∏ c in s, f c).1 = ∏ c in s, (f c).1 :=
98+
(monoid_hom.fst α β).map_prod f s
99+
100+
@[to_additive]
101+
lemma snd_prod : (∏ c in s, f c).2 = ∏ c in s, (f c).2 :=
102+
(monoid_hom.snd α β).map_prod f s
103+
104+
end prod

src/algebra/category/CommRing/limits.lean

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Scott Morrison
55
-/
66
import algebra.category.CommRing.basic
7+
import ring_theory.subring
8+
import algebra.ring.pi
79

810
/-!
911
# The category of commutative rings has all limits

src/algebra/category/Group/biproducts.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Authors: Scott Morrison
66
import algebra.category.Group.basic
77
import algebra.category.Group.preadditive
88
import category_theory.limits.shapes.biproducts
9-
import algebra.pi_instances
9+
import algebra.group.pi
1010

1111
/-!
1212
# The category of abelian groups has finite biproducts

src/algebra/category/Group/limits.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Authors: Scott Morrison
66
import algebra.category.Group.basic
77
import category_theory.limits.types
88
import category_theory.limits.preserves
9-
import algebra.pi_instances
9+
import algebra.group.pi
1010

1111
/-!
1212
# The category of abelian groups has all limits

src/algebra/char_p.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Author: Kenny Lau, Joey van Langen, Casper Putz
77
import data.fintype.basic
88
import data.nat.choose
99
import data.int.modeq
10-
import algebra.module
10+
import algebra.module.basic
1111
import algebra.iterate_hom
1212

1313
/-!

src/algebra/default.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
import algebra.group
2-
import algebra.module
2+
import algebra.module.basic

src/algebra/field.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Copyright (c) 2014 Robert Lewis. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Robert Lewis, Leonardo de Moura, Johannes Hölzl, Mario Carneiro
55
-/
6-
import algebra.ring
6+
import algebra.ring.basic
77
import algebra.group_with_zero
88
open set
99

src/algebra/group/pi.lean

Lines changed: 155 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,155 @@
1+
/-
2+
Copyright (c) 2018 Simon Hudon. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Simon Hudon, Patrick Massot
5+
-/
6+
import algebra.ordered_group tactic.pi_instances
7+
/-!
8+
# Pi instances for groups and monoids
9+
10+
This file defines instances for group, monoid, semigroup and related structures on Pi Types
11+
-/
12+
13+
universes u v w
14+
variable {I : Type u} -- The indexing type
15+
variable {f : I → Type v} -- The family of types already equipped with instances
16+
variables (x y : Π i, f i) (i : I)
17+
18+
namespace pi
19+
20+
@[to_additive] instance has_one [∀ i, has_one $ f i] : has_one (Π i : I, f i) := ⟨λ _, 1
21+
@[simp, to_additive] lemma one_apply [∀ i, has_one $ f i] : (1 : Π i, f i) i = 1 := rfl
22+
23+
@[to_additive]
24+
instance has_mul [∀ i, has_mul $ f i] : has_mul (Π i : I, f i) := ⟨λ f g i, f i * g i⟩
25+
@[simp, to_additive] lemma mul_apply [∀ i, has_mul $ f i] : (x * y) i = x i * y i := rfl
26+
27+
@[to_additive] instance has_inv [∀ i, has_inv $ f i] : has_inv (Π i : I, f i) := ⟨λ f i, (f i)⁻¹⟩
28+
@[simp, to_additive] lemma inv_apply [∀ i, has_inv $ f i] : x⁻¹ i = (x i)⁻¹ := rfl
29+
30+
@[to_additive add_semigroup]
31+
instance semigroup [∀ i, semigroup $ f i] : semigroup (Π i : I, f i) :=
32+
by refine_struct { mul := (*), .. }; tactic.pi_instance_derive_field
33+
34+
@[to_additive add_comm_semigroup]
35+
instance comm_semigroup [∀ i, comm_semigroup $ f i] : comm_semigroup (Π i : I, f i) :=
36+
by refine_struct { mul := (*), .. }; tactic.pi_instance_derive_field
37+
38+
@[to_additive add_monoid]
39+
instance monoid [∀ i, monoid $ f i] : monoid (Π i : I, f i) :=
40+
by refine_struct { one := (1 : Π i, f i), mul := (*), .. }; tactic.pi_instance_derive_field
41+
42+
@[to_additive add_comm_monoid]
43+
instance comm_monoid [∀ i, comm_monoid $ f i] : comm_monoid (Π i : I, f i) :=
44+
by refine_struct { one := (1 : Π i, f i), mul := (*), .. }; tactic.pi_instance_derive_field
45+
46+
@[to_additive add_group]
47+
instance group [∀ i, group $ f i] : group (Π i : I, f i) :=
48+
by refine_struct { one := (1 : Π i, f i), mul := (*), inv := has_inv.inv, .. };
49+
tactic.pi_instance_derive_field
50+
51+
@[simp] lemma sub_apply [∀ i, add_group $ f i] : (x - y) i = x i - y i := rfl
52+
53+
@[to_additive add_comm_group]
54+
instance comm_group [∀ i, comm_group $ f i] : comm_group (Π i : I, f i) :=
55+
by refine_struct { one := (1 : Π i, f i), mul := (*), inv := has_inv.inv, .. };
56+
tactic.pi_instance_derive_field
57+
58+
@[to_additive add_left_cancel_semigroup]
59+
instance left_cancel_semigroup [∀ i, left_cancel_semigroup $ f i] :
60+
left_cancel_semigroup (Π i : I, f i) :=
61+
by refine_struct { mul := (*) }; tactic.pi_instance_derive_field
62+
63+
@[to_additive add_right_cancel_semigroup]
64+
instance right_cancel_semigroup [∀ i, right_cancel_semigroup $ f i] :
65+
right_cancel_semigroup (Π i : I, f i) :=
66+
by refine_struct { mul := (*) }; tactic.pi_instance_derive_field
67+
68+
@[to_additive ordered_cancel_add_comm_monoid]
69+
instance ordered_cancel_comm_monoid [∀ i, ordered_cancel_comm_monoid $ f i] :
70+
ordered_cancel_comm_monoid (Π i : I, f i) :=
71+
by refine_struct { mul := (*), one := (1 : Π i, f i), le := (≤), lt := (<), .. pi.partial_order };
72+
tactic.pi_instance_derive_field
73+
74+
@[to_additive ordered_add_comm_group]
75+
instance ordered_comm_group [∀ i, ordered_comm_group $ f i] :
76+
ordered_comm_group (Π i : I, f i) :=
77+
{ mul_le_mul_left := λ x y hxy c i, mul_le_mul_left' (hxy i) _,
78+
..pi.comm_group,
79+
..pi.partial_order }
80+
81+
variables [decidable_eq I]
82+
variables [Π i, has_zero (f i)]
83+
84+
/-- The function supported at `i`, with value `x` there. -/
85+
def single (i : I) (x : f i) : Π i, f i :=
86+
λ i', if h : i' = i then (by { subst h, exact x }) else 0
87+
88+
@[simp]
89+
lemma single_eq_same (i : I) (x : f i) : single i x i = x :=
90+
begin
91+
dsimp [single],
92+
split_ifs,
93+
{ refl, },
94+
{ exfalso, exact h rfl, }
95+
end
96+
97+
@[simp]
98+
lemma single_eq_of_ne {i i' : I} (h : i' ≠ i) (x : f i) : single i x i' = 0 :=
99+
begin
100+
dsimp [single],
101+
split_ifs with h',
102+
{ exfalso, exact h h', },
103+
{ refl, }
104+
end
105+
106+
end pi
107+
108+
section monoid_hom
109+
110+
variables (f) [Π i, monoid (f i)]
111+
112+
/-- Evaluation of functions into an indexed collection of monoids at a point is a monoid
113+
homomorphism. -/
114+
@[to_additive "Evaluation of functions into an indexed collection of additive monoids at a point
115+
is an additive monoid homomorphism."]
116+
def monoid_hom.apply (i : I) : (Π i, f i) →* f i :=
117+
{ to_fun := λ g, g i,
118+
map_one' := rfl,
119+
map_mul' := λ x y, rfl, }
120+
121+
@[simp, to_additive]
122+
lemma monoid_hom.apply_apply (i : I) (g : Π i, f i) :
123+
(monoid_hom.apply f i) g = g i := rfl
124+
125+
end monoid_hom
126+
127+
section add_monoid_single
128+
variables [decidable_eq I] (f) [Π i, add_monoid (f i)]
129+
open pi
130+
131+
/-- The additive monoid homomorphism including a single additive monoid
132+
into a dependent family of additive monoids, as functions supported at a point. -/
133+
def add_monoid_hom.single (i : I) : f i →+ Π i, f i :=
134+
{ to_fun := λ x, single i x,
135+
map_zero' :=
136+
begin
137+
ext i', by_cases h : i' = i,
138+
{ subst h, simp only [single_eq_same], refl, },
139+
{ simp only [h, single_eq_of_ne, ne.def, not_false_iff], refl, },
140+
end,
141+
map_add' := λ x y,
142+
begin
143+
ext i', by_cases h : i' = i,
144+
-- FIXME in the next two `simp only`s,
145+
-- it would be really nice to not have to provide the arguments to `add_apply`.
146+
{ subst h, simp only [single_eq_same, add_apply (single i' x) (single i' y) i'], },
147+
{ simp only [h, add_zero, single_eq_of_ne,
148+
add_apply (single i x) (single i y) i', ne.def, not_false_iff], },
149+
end, }
150+
151+
@[simp]
152+
lemma add_monoid_hom.single_apply {i : I} (x : f i) :
153+
(add_monoid_hom.single f i) x = single i x := rfl
154+
155+
end add_monoid_single

src/algebra/group/with_one.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Copyright (c) 2018 Mario Carneiro. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Mario Carneiro, Johan Commelin
55
-/
6-
import algebra.ring
6+
import algebra.ring.basic
77

88
universes u v
99
variable {α : Type u}

src/algebra/midpoint.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Copyright (c) 2020 Yury Kudryashov. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Author: Yury Kudryashov
55
-/
6-
import algebra.module
6+
import algebra.module.basic
77
import algebra.invertible
88

99
/-!
File renamed without changes.

src/algebra/module/default.lean

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
/-
2+
Copyright (c) 2020 Chris Hughes. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Chris Hughes
5+
-/
6+
import algebra.module.basic
7+
8+
/-!
9+
# Default file for module
10+
This file imports `algebra.module.basic`
11+
-/

0 commit comments

Comments
 (0)