|
| 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 |
0 commit comments