algebra.group.with_one.defs
⟷
Mathlib.Algebra.Group.WithOne.Defs
The following section lists changes to this file in mathlib3 and mathlib4 that occured after the initial port. Most recent changes are shown first. Hovering over a commit will show all commits associated with the same mathlib3 commit.
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(last sync)
option.map₂
(#18081)
Relevant parts are forward-ported as leanprover-community/mathlib4#1439
Co-authored-by: Eric Wieser <wieser.eric@gmail.com> Co-authored-by: Yaël Dillies <yael.dillies@gmail.com>
@@ -19,6 +19,12 @@ this provides an example of an adjunction is proved in `algebra.category.Mon.adj
Another result says that adjoining to a group an element `zero` gives a `group_with_zero`. For more
information about these structures (which are not that standard in informal mathematics, see
`algebra.group_with_zero.basic`)
+
+## Implementation notes
+
+At various points in this file, `id $` is used in at the start of a proof field in a structure. This
+ensures that the generated `_proof_1` lemmas are stated in terms of the algebraic operations and
+not `option.map`, as the latter does not typecheck once `with_zero`/`with_one` is irreducible.
-/
universes u v w
@@ -49,7 +55,7 @@ instance [has_mul α] : has_mul (with_one α) := ⟨option.lift_or_get (*)⟩
@[to_additive] instance [has_inv α] : has_inv (with_one α) := ⟨λ a, option.map has_inv.inv a⟩
@[to_additive] instance [has_involutive_inv α] : has_involutive_inv (with_one α) :=
-{ inv_inv := λ a, (option.map_map _ _ _).trans $ by simp_rw [inv_comp_inv, option.map_id, id],
+{ inv_inv := id $ λ a, (option.map_map _ _ _).trans $ by simp_rw [inv_comp_inv, option.map_id, id],
..with_one.has_inv }
@[to_additive] instance [has_inv α] : inv_one_class (with_one α) :=
@@ -112,15 +118,12 @@ protected lemma cases_on {P : with_one α → Prop} :
∀ (x : with_one α), P 1 → (∀ a : α, P a) → P x :=
option.cases_on
--- the `show` statements in the proofs are important, because otherwise the generated lemmas
--- `with_one.mul_one_class._proof_{1,2}` have an ill-typed statement after `with_one` is made
--- irreducible.
@[to_additive]
instance [has_mul α] : mul_one_class (with_one α) :=
{ mul := (*),
one := (1),
- one_mul := show ∀ x : with_one α, 1 * x = x, from (option.lift_or_get_is_left_id _).1,
- mul_one := show ∀ x : with_one α, x * 1 = x, from (option.lift_or_get_is_right_id _).1 }
+ one_mul := id $ (option.lift_or_get_is_left_id _).1,
+ mul_one := id $ (option.lift_or_get_is_right_id _).1 }
@[to_additive]
instance [semigroup α] : monoid (with_one α) :=
@@ -153,49 +156,28 @@ instance [one : has_one α] : has_one (with_zero α) :=
@[simp, norm_cast] lemma coe_one [has_one α] : ((1 : α) : with_zero α) = 1 := rfl
instance [has_mul α] : mul_zero_class (with_zero α) :=
-{ mul := λ o₁ o₂, o₁.bind (λ a, option.map (λ b, a * b) o₂),
- zero_mul := λ a, rfl,
- mul_zero := λ a, by cases a; refl,
+{ mul := option.map₂ (*),
+ zero_mul := id $ option.map₂_none_left (*),
+ mul_zero := id $ option.map₂_none_right (*),
..with_zero.has_zero }
@[simp, norm_cast] lemma coe_mul {α : Type u} [has_mul α]
{a b : α} : ((a * b : α) : with_zero α) = a * b := rfl
-@[simp] lemma zero_mul {α : Type u} [has_mul α]
- (a : with_zero α) : 0 * a = 0 := rfl
-
-@[simp] lemma mul_zero {α : Type u} [has_mul α]
- (a : with_zero α) : a * 0 = 0 := by cases a; refl
-
instance [has_mul α] : no_zero_divisors (with_zero α) :=
-⟨by { rintro (a|a) (b|b) h, exacts [or.inl rfl, or.inl rfl, or.inr rfl, option.no_confusion h] }⟩
+⟨λ a b, id $ option.map₂_eq_none_iff.1⟩
instance [semigroup α] : semigroup_with_zero (with_zero α) :=
-{ mul_assoc := λ a b c, match a, b, c with
- | none, _, _ := rfl
- | some a, none, _ := rfl
- | some a, some b, none := rfl
- | some a, some b, some c := congr_arg some (mul_assoc _ _ _)
- end,
+{ mul_assoc := id $ λ _ _ _, option.map₂_assoc mul_assoc,
..with_zero.mul_zero_class }
instance [comm_semigroup α] : comm_semigroup (with_zero α) :=
-{ mul_comm := λ a b, match a, b with
- | none, _ := (mul_zero _).symm
- | some a, none := rfl
- | some a, some b := congr_arg some (mul_comm _ _)
- end,
+{ mul_comm := id $ λ _ _, option.map₂_comm mul_comm,
..with_zero.semigroup_with_zero }
instance [mul_one_class α] : mul_zero_one_class (with_zero α) :=
-{ one_mul := λ a, match a with
- | none := rfl
- | some a := congr_arg some $ one_mul _
- end,
- mul_one := λ a, match a with
- | none := rfl
- | some a := congr_arg some $ mul_one _
- end,
+{ one_mul := id $ option.map₂_left_identity one_mul,
+ mul_one := id $ option.map₂_right_identity mul_one,
..with_zero.mul_zero_class,
..with_zero.has_one }
@@ -234,7 +216,7 @@ instance [has_inv α] : has_inv (with_zero α) := ⟨λ a, option.map has_inv.in
@[simp] lemma inv_zero [has_inv α] : (0 : with_zero α)⁻¹ = 0 := rfl
instance [has_involutive_inv α] : has_involutive_inv (with_zero α) :=
-{ inv_inv := λ a, (option.map_map _ _ _).trans $ by simp_rw [inv_comp_inv, option.map_id, id],
+{ inv_inv := id $ λ a, (option.map_map _ _ _).trans $ by simp_rw [inv_comp_inv, option.map_id, id],
..with_zero.has_inv }
instance [inv_one_class α] : inv_one_class (with_zero α) :=
@@ -242,8 +224,7 @@ instance [inv_one_class α] : inv_one_class (with_zero α) :=
..with_zero.has_one,
..with_zero.has_inv }
-instance [has_div α] : has_div (with_zero α) :=
-⟨λ o₁ o₂, o₁.bind (λ a, option.map (λ b, a / b) o₂)⟩
+instance [has_div α] : has_div (with_zero α) := ⟨option.map₂ (/)⟩
@[norm_cast] lemma coe_div [has_div α] (a b : α) : ↑(a / b : α) = (a / b : with_zero α) := rfl
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(no changes)
(first ported)
mathlib commit https://github.com/leanprover-community/mathlib/commit/65a1391a0106c9204fe45bc73a039f056558cb83
@@ -286,7 +286,7 @@ instance [Monoid α] : MonoidWithZero (WithZero α) :=
npow_succ := fun n x =>
match x with
| none => rfl
- | some x => congr_arg some <| pow_succ _ _ }
+ | some x => congr_arg some <| pow_succ' _ _ }
instance [CommMonoid α] : CommMonoidWithZero (WithZero α) :=
{ WithZero.monoidWithZero, WithZero.commSemigroup with }
mathlib commit https://github.com/leanprover-community/mathlib/commit/65a1391a0106c9204fe45bc73a039f056558cb83
@@ -189,8 +189,8 @@ instance [Mul α] : MulOneClass (WithOne α)
where
mul := (· * ·)
one := 1
- one_mul := id <| (Option.liftOrGet_isLeftId _).1
- mul_one := id <| (Option.liftOrGet_isRightId _).1
+ one_mul := id <| (Option.liftOrGet_isId _).1
+ mul_one := id <| (Option.liftOrGet_isId _).1
@[to_additive]
instance [Semigroup α] : Monoid (WithOne α) :=
mathlib commit https://github.com/leanprover-community/mathlib/commit/ce64cd319bb6b3e82f31c2d38e79080d377be451
@@ -3,8 +3,8 @@ Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Johan Commelin
-/
-import Mathbin.Order.WithBot
-import Mathbin.Algebra.Ring.Defs
+import Order.WithBot
+import Algebra.Ring.Defs
#align_import algebra.group.with_one.defs from "leanprover-community/mathlib"@"995b47e555f1b6297c7cf16855f1023e355219fb"
mathlib commit https://github.com/leanprover-community/mathlib/commit/32a7e535287f9c73f2e4d2aef306a39190f0b504
@@ -346,7 +346,7 @@ theorem coe_zpow [DivInvMonoid α] {a : α} (n : ℤ) : ↑(a ^ n : α) = (↑a
instance [DivInvMonoid α] : DivInvMonoid (WithZero α) :=
{ WithZero.hasDiv, WithZero.hasInv,
WithZero.monoidWithZero with
- div_eq_mul_inv := fun a b =>
+ div_eq_hMul_inv := fun a b =>
match a, b with
| none, _ => rfl
| some a, none => rfl
@@ -377,7 +377,7 @@ instance [DivisionMonoid α] : DivisionMonoid (WithZero α) :=
| none, some b => rfl
| some a, none => rfl
| some a, some b => congr_arg some <| mul_inv_rev _ _
- inv_eq_of_mul := fun a b =>
+ inv_eq_of_hMul := fun a b =>
match a, b with
| none, none => fun _ => rfl
| none, some b => by contradiction
mathlib commit https://github.com/leanprover-community/mathlib/commit/8ea5598db6caeddde6cb734aa179cc2408dbd345
@@ -2,15 +2,12 @@
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Johan Commelin
-
-! This file was ported from Lean 3 source module algebra.group.with_one.defs
-! leanprover-community/mathlib commit 995b47e555f1b6297c7cf16855f1023e355219fb
-! Please do not edit these lines, except to modify the commit id
-! if you have ported upstream changes.
-/
import Mathbin.Order.WithBot
import Mathbin.Algebra.Ring.Defs
+#align_import algebra.group.with_one.defs from "leanprover-community/mathlib"@"995b47e555f1b6297c7cf16855f1023e355219fb"
+
/-!
# Adjoining a zero/one to semigroups and related algebraic structures
mathlib commit https://github.com/leanprover-community/mathlib/commit/9fb8964792b4237dac6200193a0d533f1b3f7423
@@ -242,10 +242,12 @@ instance [Mul α] : MulZeroClass (WithZero α) :=
zero_mul := id <| Option.map₂_none_left (· * ·)
mul_zero := id <| Option.map₂_none_right (· * ·) }
+#print WithZero.coe_mul /-
@[simp, norm_cast]
theorem coe_mul {α : Type u} [Mul α] {a b : α} : ((a * b : α) : WithZero α) = a * b :=
rfl
#align with_zero.coe_mul WithZero.coe_mul
+-/
instance [Mul α] : NoZeroDivisors (WithZero α) :=
⟨fun a b => id <| Option.map₂_eq_none_iff.1⟩
mathlib commit https://github.com/leanprover-community/mathlib/commit/cca40788df1b8755d5baf17ab2f27dacc2e17acb
@@ -134,12 +134,11 @@ theorem coe_unone {x : WithOne α} (hx : x ≠ 1) : ↑(unone hx) = x :=
#align with_zero.coe_unzero WithZero.coe_unzero
-/
-/- warning: with_one.some_eq_coe clashes with [anonymous] -> [anonymous]
-Case conversion may be inaccurate. Consider using '#align with_one.some_eq_coe [anonymous]ₓ'. -/
@[to_additive]
-theorem [anonymous] {a : α} : (some a : WithOne α) = ↑a :=
+theorem some_eq_coe {a : α} : (some a : WithOne α) = ↑a :=
rfl
-#align with_one.some_eq_coe [anonymous]
+#align with_one.some_eq_coe WithOne.some_eq_coe
+#align with_zero.some_eq_coe WithZero.some_eq_coe
#print WithOne.coe_ne_one /-
@[simp, to_additive]
mathlib commit https://github.com/leanprover-community/mathlib/commit/917c3c072e487b3cccdbfeff17e75b40e45f66cb
@@ -135,11 +135,6 @@ theorem coe_unone {x : WithOne α} (hx : x ≠ 1) : ↑(unone hx) = x :=
-/
/- warning: with_one.some_eq_coe clashes with [anonymous] -> [anonymous]
-warning: with_one.some_eq_coe -> [anonymous] is a dubious translation:
-lean 3 declaration is
- forall {α : Type.{u}} {a : α}, Eq.{succ u} (Option.{u} α) (Option.some.{u} α a) ((fun (a : Type.{u}) (b : Type.{u}) [self : HasLiftT.{succ u, succ u} a b] => self.0) α (Option.{u} α) (HasLiftT.mk.{succ u, succ u} α (Option.{u} α) (CoeTCₓ.coe.{succ u, succ u} α (Option.{u} α) (coeOption.{u} α))) a)
-but is expected to have type
- forall {α : Type.{u}} {a : Type.{v}}, (Nat -> α -> a) -> Nat -> (List.{u} α) -> (List.{v} a)
Case conversion may be inaccurate. Consider using '#align with_one.some_eq_coe [anonymous]ₓ'. -/
@[to_additive]
theorem [anonymous] {a : α} : (some a : WithOne α) = ↑a :=
@@ -248,12 +243,6 @@ instance [Mul α] : MulZeroClass (WithZero α) :=
zero_mul := id <| Option.map₂_none_left (· * ·)
mul_zero := id <| Option.map₂_none_right (· * ·) }
-/- warning: with_zero.coe_mul -> WithZero.coe_mul is a dubious translation:
-lean 3 declaration is
- forall {α : Type.{u1}} [_inst_1 : Mul.{u1} α] {a : α} {b : α}, Eq.{succ u1} (WithZero.{u1} α) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) α (WithZero.{u1} α) (HasLiftT.mk.{succ u1, succ u1} α (WithZero.{u1} α) (CoeTCₓ.coe.{succ u1, succ u1} α (WithZero.{u1} α) (WithZero.hasCoeT.{u1} α))) (HMul.hMul.{u1, u1, u1} α α α (instHMul.{u1} α _inst_1) a b)) (HMul.hMul.{u1, u1, u1} (WithZero.{u1} α) (WithZero.{u1} α) (WithZero.{u1} α) (instHMul.{u1} (WithZero.{u1} α) (MulZeroClass.toHasMul.{u1} (WithZero.{u1} α) (WithZero.mulZeroClass.{u1} α _inst_1))) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) α (WithZero.{u1} α) (HasLiftT.mk.{succ u1, succ u1} α (WithZero.{u1} α) (CoeTCₓ.coe.{succ u1, succ u1} α (WithZero.{u1} α) (WithZero.hasCoeT.{u1} α))) a) ((fun (a : Type.{u1}) (b : Type.{u1}) [self : HasLiftT.{succ u1, succ u1} a b] => self.0) α (WithZero.{u1} α) (HasLiftT.mk.{succ u1, succ u1} α (WithZero.{u1} α) (CoeTCₓ.coe.{succ u1, succ u1} α (WithZero.{u1} α) (WithZero.hasCoeT.{u1} α))) b))
-but is expected to have type
- forall {α : Type.{u1}} [_inst_1 : Mul.{u1} α] {a : α} {b : α}, Eq.{succ u1} (WithZero.{u1} α) (WithZero.coe.{u1} α (HMul.hMul.{u1, u1, u1} α α α (instHMul.{u1} α _inst_1) a b)) (HMul.hMul.{u1, u1, u1} (WithZero.{u1} α) (WithZero.{u1} α) (WithZero.{u1} α) (instHMul.{u1} (WithZero.{u1} α) (MulZeroClass.toMul.{u1} (WithZero.{u1} α) (WithZero.mulZeroClass.{u1} α _inst_1))) (WithZero.coe.{u1} α a) (WithZero.coe.{u1} α b))
-Case conversion may be inaccurate. Consider using '#align with_zero.coe_mul WithZero.coe_mulₓ'. -/
@[simp, norm_cast]
theorem coe_mul {α : Type u} [Mul α] {a b : α} : ((a * b : α) : WithZero α) = a * b :=
rfl
mathlib commit https://github.com/leanprover-community/mathlib/commit/917c3c072e487b3cccdbfeff17e75b40e45f66cb
@@ -410,10 +410,7 @@ instance : GroupWithZero (WithZero α) :=
{ WithZero.monoidWithZero, WithZero.divInvMonoid,
WithZero.nontrivial with
inv_zero := inv_zero
- mul_inv_cancel := fun a ha => by
- lift a to α using ha
- norm_cast
- apply mul_right_inv }
+ mul_inv_cancel := fun a ha => by lift a to α using ha; norm_cast; apply mul_right_inv }
end Group
@@ -440,8 +437,7 @@ instance [Semiring α] : Semiring (WithZero α) :=
exact congr_arg some (left_distrib _ _ _)
right_distrib := fun a b c => by
cases' c with c
- · change (a + b) * 0 = a * 0 + b * 0
- simp
+ · change (a + b) * 0 = a * 0 + b * 0; simp
cases' a with a <;> cases' b with b <;> try rfl
exact congr_arg some (right_distrib _ _ _) }
mathlib commit https://github.com/leanprover-community/mathlib/commit/bd9851ca476957ea4549eb19b40e7b5ade9428cc
@@ -15,11 +15,12 @@ import Mathlib.Tactic.Common
This file contains different results about adjoining an element to an algebraic structure which then
behaves like a zero or a one. An example is adjoining a one to a semigroup to obtain a monoid. That
-this provides an example of an adjunction is proved in `Algebra.Category.MonCat.Adjunctions`.
+this provides an example of an adjunction is proved in
+`Mathlib.Algebra.Category.MonCat.Adjunctions`.
Another result says that adjoining to a group an element `zero` gives a `GroupWithZero`. For more
information about these structures (which are not that standard in informal mathematics, see
-`Algebra.GroupWithZero.Basic`)
+`Mathlib.Algebra.GroupWithZero.Basic`)
## Porting notes
WithZero
material depending on GroupWithZero
(#12351)
Everything under Algebra.Group
should be additivisable. Therefore I move the GroupWithZero
instances for WithZero
from Algebra.Group.WithOne.Defs
and the whole of Algebra.Group.WithOne.Units
to a new file Algebra.GroupWithZero.WithZero
. I credit Mario for https://github.com/leanprover-community/mathlib/commit/ad92a9ba47f417916aab365d13db653fa8991a84 and Johan for https://github.com/leanprover-community/mathlib/pull/762.
Use the opportunity to slightly clean up the code:
:=
by where
in instance declarationscoe
lemmassection ... end
@@ -3,10 +3,8 @@ Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Johan Commelin
-/
-import Mathlib.Algebra.GroupWithZero.Defs
-import Mathlib.Data.Nat.Cast.Defs
+import Mathlib.Algebra.Group.Defs
import Mathlib.Data.Option.Defs
-import Mathlib.Data.Option.NAry
import Mathlib.Logic.Nontrivial.Basic
import Mathlib.Tactic.Common
@@ -35,6 +33,13 @@ longer typecheck. In Lean 4, both types are plain `def`s, so we don't need these
`WithOne.coe_mul` and `WithZero.coe_mul` have inconsistent use of implicit parameters
-/
+-- Check that we haven't needed to import all the basic lemmas about groups,
+-- by asserting a random sample don't exist here:
+assert_not_exists inv_involutive
+assert_not_exists div_right_inj
+assert_not_exists pow_ite
+
+assert_not_exists MonoidWithZero
universe u v w
@@ -223,176 +228,3 @@ theorem coe_inv [Inv α] (a : α) : ((a⁻¹ : α) : WithOne α) = (a : WithOne
#align with_zero.coe_neg WithZero.coe_neg
end WithOne
-
-namespace WithZero
-
-instance one [one : One α] : One (WithZero α) :=
- { one with }
-
-@[simp, norm_cast]
-theorem coe_one [One α] : ((1 : α) : WithZero α) = 1 :=
- rfl
-#align with_zero.coe_one WithZero.coe_one
-
-instance mulZeroClass [Mul α] : MulZeroClass (WithZero α) :=
- { WithZero.zero with
- mul := Option.map₂ (· * ·),
- zero_mul := Option.map₂_none_left (· * ·),
- mul_zero := Option.map₂_none_right (· * ·) }
-
-@[simp, norm_cast]
-theorem coe_mul {α : Type u} [Mul α] {a b : α} : ((a * b : α) : WithZero α) = a * b :=
- rfl
-#align with_zero.coe_mul WithZero.coe_mul
-
-instance noZeroDivisors [Mul α] : NoZeroDivisors (WithZero α) :=
- ⟨Option.map₂_eq_none_iff.1⟩
-
-instance semigroupWithZero [Semigroup α] : SemigroupWithZero (WithZero α) :=
- { WithZero.mulZeroClass with
- mul_assoc := fun _ _ _ => Option.map₂_assoc mul_assoc }
-
-instance commSemigroup [CommSemigroup α] : CommSemigroup (WithZero α) :=
- { WithZero.semigroupWithZero with
- mul_comm := fun _ _ => Option.map₂_comm mul_comm }
-
-instance mulZeroOneClass [MulOneClass α] : MulZeroOneClass (WithZero α) :=
- { WithZero.mulZeroClass, WithZero.one with
- one_mul := Option.map₂_left_identity one_mul,
- mul_one := Option.map₂_right_identity mul_one }
-
-instance pow [One α] [Pow α ℕ] : Pow (WithZero α) ℕ :=
- ⟨fun x n =>
- match x, n with
- | none, 0 => 1
- | none, _ + 1 => 0
- | some x, n => ↑(x ^ n)⟩
-
-@[simp, norm_cast]
-theorem coe_pow [One α] [Pow α ℕ] {a : α} (n : ℕ) :
- ↑(a ^ n : α) = ((a : WithZero α) ^ n : WithZero α) :=
- rfl
-#align with_zero.coe_pow WithZero.coe_pow
-
-instance monoidWithZero [Monoid α] : MonoidWithZero (WithZero α) :=
- { WithZero.mulZeroOneClass, WithZero.semigroupWithZero with
- npow := fun n x => x ^ n,
- npow_zero := fun x =>
- match x with
- | none => rfl
- | some x => congr_arg some <| pow_zero x,
- npow_succ := fun n x =>
- match x with
- | none => by
- change 0 ^ (n + 1) = 0 ^ n * 0
- simp only [mul_zero]; rfl
- | some x => congr_arg some <| pow_succ x n }
-
-instance commMonoidWithZero [CommMonoid α] : CommMonoidWithZero (WithZero α) :=
- { WithZero.monoidWithZero, WithZero.commSemigroup with }
-
-/-- Given an inverse operation on `α` there is an inverse operation
- on `WithZero α` sending `0` to `0`. -/
-instance inv [Inv α] : Inv (WithZero α) :=
- ⟨fun a => Option.map Inv.inv a⟩
-
-@[simp, norm_cast]
-theorem coe_inv [Inv α] (a : α) : ((a⁻¹ : α) : WithZero α) = (↑a)⁻¹ :=
- rfl
-#align with_zero.coe_inv WithZero.coe_inv
-
-@[simp]
-theorem inv_zero [Inv α] : (0 : WithZero α)⁻¹ = 0 :=
- rfl
-#align with_zero.inv_zero WithZero.inv_zero
-
-instance invOneClass [InvOneClass α] : InvOneClass (WithZero α) :=
- { WithZero.one, WithZero.inv with inv_one := show ((1⁻¹ : α) : WithZero α) = 1 by simp }
-
-instance div [Div α] : Div (WithZero α) :=
- ⟨Option.map₂ (· / ·)⟩
-
-@[norm_cast]
-theorem coe_div [Div α] (a b : α) : ↑(a / b : α) = (a / b : WithZero α) :=
- rfl
-#align with_zero.coe_div WithZero.coe_div
-
-instance [One α] [Pow α ℤ] : Pow (WithZero α) ℤ :=
- ⟨fun x n =>
- match x, n with
- | none, Int.ofNat 0 => 1
- | none, Int.ofNat (Nat.succ _) => 0
- | none, Int.negSucc _ => 0
- | some x, n => ↑(x ^ n)⟩
-
-@[simp, norm_cast]
-theorem coe_zpow [DivInvMonoid α] {a : α} (n : ℤ) : ↑(a ^ n) = (↑a : WithZero α) ^ n :=
- rfl
-#align with_zero.coe_zpow WithZero.coe_zpow
-
-instance divInvMonoid [DivInvMonoid α] : DivInvMonoid (WithZero α) :=
- { WithZero.div, WithZero.inv, WithZero.monoidWithZero with
- div_eq_mul_inv := fun a b =>
- match a, b with
- | none, _ => rfl
- | some _, none => rfl
- | some a, some b => congr_arg some (div_eq_mul_inv a b),
- zpow := fun n x => x ^ n,
- zpow_zero' := fun x =>
- match x with
- | none => rfl
- | some x => congr_arg some <| zpow_zero x,
- zpow_succ' := fun n x =>
- match x with
- | none => by
- change 0 ^ _ = 0 ^ _ * 0
- simp only [mul_zero]
- rfl
- | some x => congr_arg some <| DivInvMonoid.zpow_succ' n x,
- zpow_neg' := fun n x =>
- match x with
- | none => rfl
- | some x => congr_arg some <| DivInvMonoid.zpow_neg' n x }
-
-instance divInvOneMonoid [DivInvOneMonoid α] : DivInvOneMonoid (WithZero α) :=
- { WithZero.divInvMonoid, WithZero.invOneClass with }
-
-section Group
-
-variable [Group α]
-
-/-- if `G` is a group then `WithZero G` is a group with zero. -/
-instance groupWithZero : GroupWithZero (WithZero α) :=
- { WithZero.monoidWithZero, WithZero.divInvMonoid, WithZero.nontrivial with
- inv_zero := inv_zero,
- mul_inv_cancel := fun a ha ↦ by
- lift a to α using ha
- norm_cast
- apply mul_right_inv }
-
-end Group
-
-instance commGroupWithZero [CommGroup α] : CommGroupWithZero (WithZero α) :=
- { WithZero.groupWithZero, WithZero.commMonoidWithZero with }
-
-instance addMonoidWithOne [AddMonoidWithOne α] : AddMonoidWithOne (WithZero α) :=
- { WithZero.addMonoid, WithZero.one with
- natCast := fun n => if n = 0 then 0 else (n.cast : α),
- natCast_zero := rfl,
- natCast_succ := fun n => by
- cases n with
- | zero => show (((1 : ℕ) : α) : WithZero α) = 0 + 1; · rw [Nat.cast_one, coe_one, zero_add]
- | succ n =>
- show (((n + 2 : ℕ) : α) : WithZero α) = ((n + 1 : ℕ) : α) + 1
- rw [Nat.cast_succ, coe_add, coe_one]
- }
-
-end WithZero
-
--- Check that we haven't needed to import all the basic lemmas about groups,
--- by asserting a random sample don't exist here:
-assert_not_exists inv_involutive
-assert_not_exists div_right_inj
-assert_not_exists pow_ite
-
-assert_not_exists Ring
A mix of various changes; generated with a script and manually tweaked.
@@ -26,7 +26,7 @@ information about these structures (which are not that standard in informal math
## Porting notes
In Lean 3, we use `id` here and there to get correct types of proofs. This is required because
-`WithOne` and `WithZero` are marked as `Irreducible` at the end of
+`WithOne` and `WithZero` are marked as `irreducible` at the end of
`Mathlib.Algebra.Group.WithOne.Defs`, so proofs that use `Option α` instead of `WithOne α` no
longer typecheck. In Lean 4, both types are plain `def`s, so we don't need these `id`s.
LinearOrderedCommGroupWithZero
(#11716)
Reconstitute the file Algebra.Order.Monoid.WithZero
from three files:
Algebra.Order.Monoid.WithZero.Defs
Algebra.Order.Monoid.WithZero.Basic
Algebra.Order.WithZero
Avoid importing it in many files. Most uses were just to get le_zero_iff
to work on Nat
.
Before
After
@@ -29,6 +29,10 @@ In Lean 3, we use `id` here and there to get correct types of proofs. This is re
`WithOne` and `WithZero` are marked as `Irreducible` at the end of
`Mathlib.Algebra.Group.WithOne.Defs`, so proofs that use `Option α` instead of `WithOne α` no
longer typecheck. In Lean 4, both types are plain `def`s, so we don't need these `id`s.
+
+## TODO
+
+`WithOne.coe_mul` and `WithZero.coe_mul` have inconsistent use of implicit parameters
-/
We change the following field in the definition of an additive commutative monoid:
nsmul_succ : ∀ (n : ℕ) (x : G),
- AddMonoid.nsmul (n + 1) x = x + AddMonoid.nsmul n x
+ AddMonoid.nsmul (n + 1) x = AddMonoid.nsmul n x + x
where the latter is more natural
We adjust the definitions of ^
in monoids, groups, etc.
Originally there was a warning comment about why this natural order was preferred
use
x * npowRec n x
and notnpowRec n x * x
in the definition to make sure that definitional unfolding ofnpowRec
is blocked, to avoid deep recursion issues.
but it seems to no longer apply.
Remarks on the PR :
pow_succ
and pow_succ'
have switched their meanings.Ideal.IsPrime.mul_mem_pow
which is defined in [Mathlib/RingTheory/DedekindDomain/Ideal.lean]. Changing the order of operation forced me to add the symmetric lemma Ideal.IsPrime.mem_pow_mul
.@@ -279,7 +279,9 @@ instance monoidWithZero [Monoid α] : MonoidWithZero (WithZero α) :=
| some x => congr_arg some <| pow_zero x,
npow_succ := fun n x =>
match x with
- | none => rfl
+ | none => by
+ change 0 ^ (n + 1) = 0 ^ n * 0
+ simp only [mul_zero]; rfl
| some x => congr_arg some <| pow_succ x n }
instance commMonoidWithZero [CommMonoid α] : CommMonoidWithZero (WithZero α) :=
@@ -338,7 +340,10 @@ instance divInvMonoid [DivInvMonoid α] : DivInvMonoid (WithZero α) :=
| some x => congr_arg some <| zpow_zero x,
zpow_succ' := fun n x =>
match x with
- | none => rfl
+ | none => by
+ change 0 ^ _ = 0 ^ _ * 0
+ simp only [mul_zero]
+ rfl
| some x => congr_arg some <| DivInvMonoid.zpow_succ' n x,
zpow_neg' := fun n x =>
match x with
Homogenises porting notes via capitalisation and addition of whitespace.
It makes the following changes:
@@ -92,7 +92,7 @@ instance inhabited : Inhabited (WithOne α) :=
instance nontrivial [Nonempty α] : Nontrivial (WithOne α) :=
Option.nontrivial
--- porting note: this new declaration is here to make `((a : α): WithOne α)` have type `WithOne α`;
+-- Porting note: this new declaration is here to make `((a : α): WithOne α)` have type `WithOne α`;
-- otherwise the coercion kicks in and it becomes `Option.some a : WithOne α` which
-- becomes `Option.some a : Option α`.
/-- The canonical map from `α` into `WithOne α` -/
@@ -113,7 +113,7 @@ def recOneCoe {C : WithOne α → Sort*} (h₁ : C 1) (h₂ : ∀ a : α, C a) :
#align with_one.rec_one_coe WithOne.recOneCoe
#align with_zero.rec_zero_coe WithZero.recZeroCoe
--- porting note: in Lean 3 the to-additivised declaration
+-- Porting note: in Lean 3 the to-additivised declaration
-- would automatically get this; right now in Lean 4...I don't
-- know if it does or not, and I don't know how to check, so
-- I'll add it manually just to be sure.
@@ -139,7 +139,7 @@ lemma coe_unone : ∀ {x : WithOne α} (hx : x ≠ 1), unone hx = x
#align with_one.coe_unone WithOne.coe_unone
#align with_zero.coe_unzero WithZero.coe_unzero
--- porting note: in Lean 4 the `some_eq_coe` lemmas present in the lean 3 version
+-- Porting note: in Lean 4 the `some_eq_coe` lemmas present in the lean 3 version
-- of this file are syntactic tautologies
#noalign with_one.some_eq_coe
#noalign with_zero.some_eq_coe
@@ -180,7 +180,7 @@ protected theorem cases_on {P : WithOne α → Prop} : ∀ x : WithOne α, P 1
#align with_one.cases_on WithOne.cases_on
#align with_zero.cases_on WithZero.cases_on
--- port note: I don't know if `elab_as_elim` is being added to the additivised declaration.
+-- Porting note: I don't know if `elab_as_elim` is being added to the additivised declaration.
attribute [elab_as_elim] WithZero.cases_on
@[to_additive]
WithOne
doesn't import rings (#10275)
Reorder the WithOne
material.
Algebra.Group.WithOne.Defs
was hiding a Ring
import! I credit Johan and Mario for https://github.com/leanprover-community/mathlib/pull/2707.WithBot
is not needed to define WithOne.unone
. It's simpler to redefine it by hand. In the future, we might want to have an Option
version (but not sure how much that's worth, since it would basically be Option.get
again).@@ -3,8 +3,12 @@ Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Johan Commelin
-/
-import Mathlib.Algebra.Ring.Defs
-import Mathlib.Order.WithBot
+import Mathlib.Algebra.GroupWithZero.Defs
+import Mathlib.Data.Nat.Cast.Defs
+import Mathlib.Data.Option.Defs
+import Mathlib.Data.Option.NAry
+import Mathlib.Logic.Nontrivial.Basic
+import Mathlib.Tactic.Common
#align_import algebra.group.with_one.defs from "leanprover-community/mathlib"@"995b47e555f1b6297c7cf16855f1023e355219fb"
@@ -119,8 +123,7 @@ attribute [elab_as_elim] WithZero.recZeroCoe
/-- Deconstruct an `x : WithOne α` to the underlying value in `α`, given a proof that `x ≠ 1`. -/
@[to_additive unzero
"Deconstruct an `x : WithZero α` to the underlying value in `α`, given a proof that `x ≠ 0`."]
-def unone {x : WithOne α} (hx : x ≠ 1) : α :=
- WithBot.unbot x hx
+def unone : ∀ {x : WithOne α}, x ≠ 1 → α | (x : α), _ => x
#align with_one.unone WithOne.unone
#align with_zero.unzero WithZero.unzero
@@ -131,8 +134,8 @@ theorem unone_coe {x : α} (hx : (x : WithOne α) ≠ 1) : unone hx = x :=
#align with_zero.unzero_coe WithZero.unzero_coe
@[to_additive (attr := simp) coe_unzero]
-theorem coe_unone {x : WithOne α} (hx : x ≠ 1) : ↑(unone hx) = x :=
- WithBot.coe_unbot x hx
+lemma coe_unone : ∀ {x : WithOne α} (hx : x ≠ 1), unone hx = x
+ | (x : α), _ => rfl
#align with_one.coe_unone WithOne.coe_unone
#align with_zero.coe_unzero WithZero.coe_unzero
@@ -375,30 +378,6 @@ instance addMonoidWithOne [AddMonoidWithOne α] : AddMonoidWithOne (WithZero α)
rw [Nat.cast_succ, coe_add, coe_one]
}
-instance instLeftDistribClass [Mul α] [Add α] [LeftDistribClass α] :
- LeftDistribClass (WithZero α) where
- left_distrib a b c := by
- cases' a with a; · rfl
- cases' b with b <;> cases' c with c <;> try rfl
- exact congr_arg some (left_distrib _ _ _)
-
-instance instRightDistribClass [Mul α] [Add α] [RightDistribClass α] :
- RightDistribClass (WithZero α) where
- right_distrib a b c := by
- cases' c with c
- · change (a + b) * 0 = a * 0 + b * 0
- simp
- cases' a with a <;> cases' b with b <;> try rfl
- exact congr_arg some (right_distrib _ _ _)
-
-instance instDistrib [Distrib α] : Distrib (WithZero α) where
- left_distrib := left_distrib
- right_distrib := right_distrib
-
-instance semiring [Semiring α] : Semiring (WithZero α) :=
- { WithZero.addMonoidWithOne, WithZero.addCommMonoid, WithZero.mulZeroClass,
- WithZero.monoidWithZero, WithZero.instDistrib with }
-
end WithZero
-- Check that we haven't needed to import all the basic lemmas about groups,
@@ -406,3 +385,5 @@ end WithZero
assert_not_exists inv_involutive
assert_not_exists div_right_inj
assert_not_exists pow_ite
+
+assert_not_exists Ring
Co-authored-by: Scott Morrison <scott.morrison@gmail.com> Co-authored-by: Eric Wieser <wieser.eric@gmail.com> Co-authored-by: Joachim Breitner <mail@joachim-breitner.de>
@@ -184,8 +184,8 @@ attribute [elab_as_elim] WithZero.cases_on
instance mulOneClass [Mul α] : MulOneClass (WithOne α) where
mul := (· * ·)
one := 1
- one_mul := (Option.liftOrGet_isLeftId _).1
- mul_one := (Option.liftOrGet_isRightId _).1
+ one_mul := (Option.liftOrGet_isId _).left_id
+ mul_one := (Option.liftOrGet_isId _).right_id
@[to_additive (attr := simp, norm_cast)]
lemma coe_mul [Mul α] (a b : α) : (↑(a * b) : WithOne α) = a * b := rfl
We are not that far from the point that Algebra/Group/Defs
depends on nothing significant besides simps
and to_additive
.
This removes from Mathlib.Algebra.Group.Defs
the dependencies on
Mathlib.Tactic.Basic
(which is a grab-bag of random stuff)Mathlib.Init.Algebra.Classes
(which is ancient and half-baked)Mathlib.Logic.Function.Basic
(not particularly important, but it is barely used in this file)The goal is to avoid all unnecessary imports to set up the definitions of basic algebraic structures.
We also separate out Mathlib.Tactic.TypeStar
and Mathlib.Tactic.Lemma
as prerequisites to Mathlib.Tactic.Basic
, but which can be imported separately when the rest of Mathlib.Tactic.Basic
is not needed.
Co-authored-by: Scott Morrison <scott.morrison@gmail.com> Co-authored-by: Yaël Dillies <yael.dillies@gmail.com>
@@ -3,8 +3,8 @@ Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Johan Commelin
-/
-import Mathlib.Order.WithBot
import Mathlib.Algebra.Ring.Defs
+import Mathlib.Order.WithBot
#align_import algebra.group.with_one.defs from "leanprover-community/mathlib"@"995b47e555f1b6297c7cf16855f1023e355219fb"
@@ -187,20 +187,28 @@ instance mulOneClass [Mul α] : MulOneClass (WithOne α) where
one_mul := (Option.liftOrGet_isLeftId _).1
mul_one := (Option.liftOrGet_isRightId _).1
-@[to_additive]
-instance monoid [Semigroup α] : Monoid (WithOne α) :=
- { WithOne.mulOneClass with mul_assoc := (Option.liftOrGet_isAssociative _).1 }
-
-@[to_additive]
-instance commMonoid [CommSemigroup α] : CommMonoid (WithOne α) :=
- { WithOne.monoid with mul_comm := (Option.liftOrGet_isCommutative _).1 }
-
@[to_additive (attr := simp, norm_cast)]
-theorem coe_mul [Mul α] (a b : α) : ((a * b : α) : WithOne α) = a * b :=
- rfl
+lemma coe_mul [Mul α] (a b : α) : (↑(a * b) : WithOne α) = a * b := rfl
#align with_one.coe_mul WithOne.coe_mul
#align with_zero.coe_add WithZero.coe_add
+@[to_additive]
+instance monoid [Semigroup α] : Monoid (WithOne α) where
+ __ := mulOneClass
+ mul_assoc a b c := match a, b, c with
+ | 1, b, c => by simp
+ | (a : α), 1, c => by simp
+ | (a : α), (b : α), 1 => by simp
+ | (a : α), (b : α), (c : α) => by simp_rw [← coe_mul, mul_assoc]
+
+@[to_additive]
+instance commMonoid [CommSemigroup α] : CommMonoid (WithOne α) where
+ mul_comm := fun a b => match a, b with
+ | (a : α), (b : α) => congr_arg some (mul_comm a b)
+ | (_ : α), 1 => rfl
+ | 1, (_ : α) => rfl
+ | 1, 1 => rfl
+
@[to_additive (attr := simp, norm_cast)]
theorem coe_inv [Inv α] (a : α) : ((a⁻¹ : α) : WithOne α) = (a : WithOne α)⁻¹ :=
rfl
@@ -392,3 +400,9 @@ instance semiring [Semiring α] : Semiring (WithZero α) :=
WithZero.monoidWithZero, WithZero.instDistrib with }
end WithZero
+
+-- Check that we haven't needed to import all the basic lemmas about groups,
+-- by asserting a random sample don't exist here:
+assert_not_exists inv_involutive
+assert_not_exists div_right_inj
+assert_not_exists pow_ite
@@ -309,7 +309,7 @@ instance [One α] [Pow α ℤ] : Pow (WithZero α) ℤ :=
| some x, n => ↑(x ^ n)⟩
@[simp, norm_cast]
-theorem coe_zpow [DivInvMonoid α] {a : α} (n : ℤ) : ↑(a ^ n : α) = ((↑a : WithZero α) ^ n) :=
+theorem coe_zpow [DivInvMonoid α] {a : α} (n : ℤ) : ↑(a ^ n) = (↑a : WithZero α) ^ n :=
rfl
#align with_zero.coe_zpow WithZero.coe_zpow
@@ -367,18 +367,28 @@ instance addMonoidWithOne [AddMonoidWithOne α] : AddMonoidWithOne (WithZero α)
rw [Nat.cast_succ, coe_add, coe_one]
}
+instance instLeftDistribClass [Mul α] [Add α] [LeftDistribClass α] :
+ LeftDistribClass (WithZero α) where
+ left_distrib a b c := by
+ cases' a with a; · rfl
+ cases' b with b <;> cases' c with c <;> try rfl
+ exact congr_arg some (left_distrib _ _ _)
+
+instance instRightDistribClass [Mul α] [Add α] [RightDistribClass α] :
+ RightDistribClass (WithZero α) where
+ right_distrib a b c := by
+ cases' c with c
+ · change (a + b) * 0 = a * 0 + b * 0
+ simp
+ cases' a with a <;> cases' b with b <;> try rfl
+ exact congr_arg some (right_distrib _ _ _)
+
+instance instDistrib [Distrib α] : Distrib (WithZero α) where
+ left_distrib := left_distrib
+ right_distrib := right_distrib
+
instance semiring [Semiring α] : Semiring (WithZero α) :=
{ WithZero.addMonoidWithOne, WithZero.addCommMonoid, WithZero.mulZeroClass,
- WithZero.monoidWithZero with
- left_distrib := fun a b c => by
- cases' a with a; · rfl
- cases' b with b <;> cases' c with c <;> try rfl
- exact congr_arg some (left_distrib _ _ _),
- right_distrib := fun a b c => by
- cases' c with c
- · change (a + b) * 0 = a * 0 + b * 0
- simp
- cases' a with a <;> cases' b with b <;> try rfl
- exact congr_arg some (right_distrib _ _ _) }
+ WithZero.monoidWithZero, WithZero.instDistrib with }
end WithZero
And fix some names in comments where this revealed issues
@@ -22,9 +22,9 @@ information about these structures (which are not that standard in informal math
## Porting notes
In Lean 3, we use `id` here and there to get correct types of proofs. This is required because
-`WithOne` and `WithZero` are marked as `Irreducible` at the end of `algebra.group.with_one.defs`,
-so proofs that use `Option α` instead of `WithOne α` no longer typecheck. In Lean 4, both types are
-plain `def`s, so we don't need these `id`s.
+`WithOne` and `WithZero` are marked as `Irreducible` at the end of
+`Mathlib.Algebra.Group.WithOne.Defs`, so proofs that use `Option α` instead of `WithOne α` no
+longer typecheck. In Lean 4, both types are plain `def`s, so we don't need these `id`s.
-/
In the basic algebraic hierarchy, the Defs
files should ideally only depend on earlier Defs
files, importing as little theory as possible.
This PR makes some rearrangements so Ring.Defs
can depend on Group.Defs
rather than requiring Group.Basic
.
Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
@@ -76,12 +76,6 @@ instance inv [Inv α] : Inv (WithOne α) :=
#align with_one.has_inv WithOne.inv
#align with_zero.has_neg WithZero.neg
-@[to_additive]
-instance involutiveInv [InvolutiveInv α] : InvolutiveInv (WithOne α) :=
- { WithOne.inv with
- inv_inv := fun a =>
- (Option.map_map _ _ _).trans <| by simp_rw [inv_comp_inv, Option.map_id, id] }
-
@[to_additive]
instance invOneClass [Inv α] : InvOneClass (WithOne α) :=
{ WithOne.one, WithOne.inv with inv_one := rfl }
@@ -295,11 +289,6 @@ theorem inv_zero [Inv α] : (0 : WithZero α)⁻¹ = 0 :=
rfl
#align with_zero.inv_zero WithZero.inv_zero
-instance involutiveInv [InvolutiveInv α] : InvolutiveInv (WithZero α) :=
- { WithZero.inv with
- inv_inv := fun a =>
- (Option.map_map _ _ _).trans <| by simp_rw [inv_comp_inv, Option.map_id, id] }
-
instance invOneClass [InvOneClass α] : InvOneClass (WithZero α) :=
{ WithZero.one, WithZero.inv with inv_one := show ((1⁻¹ : α) : WithZero α) = 1 by simp }
@@ -348,25 +337,6 @@ instance divInvMonoid [DivInvMonoid α] : DivInvMonoid (WithZero α) :=
instance divInvOneMonoid [DivInvOneMonoid α] : DivInvOneMonoid (WithZero α) :=
{ WithZero.divInvMonoid, WithZero.invOneClass with }
-instance divisionMonoid [DivisionMonoid α] : DivisionMonoid (WithZero α) :=
- { WithZero.divInvMonoid, WithZero.involutiveInv with
- mul_inv_rev := fun a b =>
- match a, b with
- | none, none => rfl
- | none, some b => rfl
- | some a, none => rfl
- | some a, some b => congr_arg some <| mul_inv_rev _ _,
- inv_eq_of_mul := fun a b ↦
- match a, b with
- | none, none => fun _ ↦ rfl
- | none, some b => fun _ ↦ by contradiction
- | some a, none => fun _ ↦ by contradiction
- | some a, some b => fun h ↦
- congr_arg some <| inv_eq_of_mul_eq_one_right <| Option.some_injective _ h }
-
-instance divisionCommMonoid [DivisionCommMonoid α] : DivisionCommMonoid (WithZero α) :=
- { WithZero.divisionMonoid, WithZero.commSemigroup with }
-
section Group
variable [Group α]
Type _
and Sort _
(#6499)
We remove all possible occurences of Type _
and Sort _
in favor of Type*
and Sort*
.
This has nice performance benefits.
@@ -109,7 +109,7 @@ instance coeTC : CoeTC α (WithOne α) :=
/-- Recursor for `WithOne` using the preferred forms `1` and `↑a`. -/
@[to_additive (attr := elab_as_elim)
"Recursor for `WithZero` using the preferred forms `0` and `↑a`."]
-def recOneCoe {C : WithOne α → Sort _} (h₁ : C 1) (h₂ : ∀ a : α, C a) : ∀ n : WithOne α, C n
+def recOneCoe {C : WithOne α → Sort*} (h₁ : C 1) (h₂ : ∀ a : α, C a) : ∀ n : WithOne α, C n
| Option.none => h₁
| Option.some x => h₂ x
#align with_one.rec_one_coe WithOne.recOneCoe
@@ -2,15 +2,12 @@
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Johan Commelin
-
-! This file was ported from Lean 3 source module algebra.group.with_one.defs
-! leanprover-community/mathlib commit 995b47e555f1b6297c7cf16855f1023e355219fb
-! Please do not edit these lines, except to modify the commit id
-! if you have ported upstream changes.
-/
import Mathlib.Order.WithBot
import Mathlib.Algebra.Ring.Defs
+#align_import algebra.group.with_one.defs from "leanprover-community/mathlib"@"995b47e555f1b6297c7cf16855f1023e355219fb"
+
/-!
# Adjoining a zero/one to semigroups and related algebraic structures
@@ -125,9 +125,9 @@ def recOneCoe {C : WithOne α → Sort _} (h₁ : C 1) (h₂ : ∀ a : α, C a)
attribute [elab_as_elim] WithZero.recZeroCoe
-/-- Deconstruct a `x : WithOne α` to the underlying value in `α`, given a proof that `x ≠ 1`. -/
+/-- Deconstruct an `x : WithOne α` to the underlying value in `α`, given a proof that `x ≠ 1`. -/
@[to_additive unzero
- "Deconstruct a `x : WithZero α` to the underlying value in `α`, given a proof that `x ≠ 0`."]
+ "Deconstruct an `x : WithZero α` to the underlying value in `α`, given a proof that `x ≠ 0`."]
def unone {x : WithOne α} (hx : x ≠ 1) : α :=
WithBot.unbot x hx
#align with_one.unone WithOne.unone
fix-comments.py
on all files.@@ -25,8 +25,8 @@ information about these structures (which are not that standard in informal math
## Porting notes
In Lean 3, we use `id` here and there to get correct types of proofs. This is required because
-`with_one` and `with_zero` are marked as `irreducible` at the end of `algebra.group.with_one.defs`,
-so proofs that use `option α` instead of `with_one α` no longer typecheck. In Lean 4, both types are
+`WithOne` and `WithZero` are marked as `Irreducible` at the end of `algebra.group.with_one.defs`,
+so proofs that use `Option α` instead of `WithOne α` no longer typecheck. In Lean 4, both types are
plain `def`s, so we don't need these `id`s.
-/
This makes a mathlib4 version of mathlib3's tactic.basic
, now called Mathlib.Tactic.Common
, which imports all tactics which do not have significant theory requirements, and then is imported all across the base of the hierarchy.
This ensures that all common tactics are available nearly everywhere in the library, rather than having to be imported one-by-one as you need them.
Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
@@ -10,7 +10,6 @@ Authors: Mario Carneiro, Johan Commelin
-/
import Mathlib.Order.WithBot
import Mathlib.Algebra.Ring.Defs
-import Mathlib.Tactic.Lift
/-!
# Adjoining a zero/one to semigroups and related algebraic structures
Update some SHAs of files that changed in mathlib3.
These 17 files need mainly only updated SHA as they've been only touched by backports or already have been forward-ported.
The relevant changes are:
Co-authored-by: Eric Wieser <wieser.eric@gmail.com>
@@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Johan Commelin
! This file was ported from Lean 3 source module algebra.group.with_one.defs
-! leanprover-community/mathlib commit e574b1a4e891376b0ef974b926da39e05da12a06
+! leanprover-community/mathlib commit 995b47e555f1b6297c7cf16855f1023e355219fb
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
@@ -98,7 +98,7 @@ instance inhabited : Inhabited (WithOne α) :=
instance nontrivial [Nonempty α] : Nontrivial (WithOne α) :=
Option.nontrivial
--- porting note: this new declaration is here to make `((a : α): WithOne α)` have type `WithOne α` ;
+-- porting note: this new declaration is here to make `((a : α): WithOne α)` have type `WithOne α`;
-- otherwise the coercion kicks in and it becomes `Option.some a : WithOne α` which
-- becomes `Option.some a : Option α`.
/-- The canonical map from `α` into `WithOne α` -/
@@ -190,11 +190,6 @@ protected theorem cases_on {P : WithOne α → Prop} : ∀ x : WithOne α, P 1
-- port note: I don't know if `elab_as_elim` is being added to the additivised declaration.
attribute [elab_as_elim] WithZero.cases_on
--- porting note: in Lean 3 there was the following comment:
--- the `show` statements in the proofs are important, because otherwise the generated lemmas
--- `WithOne.mulOneClass._proof_{1,2}` have an ill-typed statement after `WithOne` is made
--- irreducible. Maybe one day when mathlib is ported to Lean 4 we can experiment
--- to see if these `show` comments can be removed.
@[to_additive]
instance mulOneClass [Mul α] : MulOneClass (WithOne α) where
mul := (· * ·)
@@ -290,7 +285,7 @@ instance commMonoidWithZero [CommMonoid α] : CommMonoidWithZero (WithZero α) :
{ WithZero.monoidWithZero, WithZero.commSemigroup with }
/-- Given an inverse operation on `α` there is an inverse operation
- on `WithZero α` sending `0` to `0`-/
+ on `WithZero α` sending `0` to `0`. -/
instance inv [Inv α] : Inv (WithZero α) :=
⟨fun a => Option.map Inv.inv a⟩
Option.map₂
(#1439)
This is a forward-port of leanprover-community/mathlib#18081
@@ -22,6 +22,13 @@ this provides an example of an adjunction is proved in `Algebra.Category.MonCat.
Another result says that adjoining to a group an element `zero` gives a `GroupWithZero`. For more
information about these structures (which are not that standard in informal mathematics, see
`Algebra.GroupWithZero.Basic`)
+
+## Porting notes
+
+In Lean 3, we use `id` here and there to get correct types of proofs. This is required because
+`with_one` and `with_zero` are marked as `irreducible` at the end of `algebra.group.with_one.defs`,
+so proofs that use `option α` instead of `with_one α` no longer typecheck. In Lean 4, both types are
+plain `def`s, so we don't need these `id`s.
-/
@@ -192,8 +199,8 @@ attribute [elab_as_elim] WithZero.cases_on
instance mulOneClass [Mul α] : MulOneClass (WithOne α) where
mul := (· * ·)
one := 1
- one_mul := show ∀ x : WithOne α, 1 * x = x from (Option.liftOrGet_isLeftId _).1
- mul_one := show ∀ x : WithOne α, x * 1 = x from (Option.liftOrGet_isRightId _).1
+ one_mul := (Option.liftOrGet_isLeftId _).1
+ mul_one := (Option.liftOrGet_isRightId _).1
@[to_additive]
instance monoid [Semigroup α] : Monoid (WithOne α) :=
@@ -229,59 +236,30 @@ theorem coe_one [One α] : ((1 : α) : WithZero α) = 1 :=
instance mulZeroClass [Mul α] : MulZeroClass (WithZero α) :=
{ WithZero.zero with
- mul := fun o₁ o₂ => o₁.bind fun a => Option.map (fun b => a * b) o₂,
- zero_mul := fun a => rfl,
- mul_zero := fun a => by cases a <;> rfl }
+ mul := Option.map₂ (· * ·),
+ zero_mul := Option.map₂_none_left (· * ·),
+ mul_zero := Option.map₂_none_right (· * ·) }
@[simp, norm_cast]
theorem coe_mul {α : Type u} [Mul α] {a b : α} : ((a * b : α) : WithZero α) = a * b :=
rfl
#align with_zero.coe_mul WithZero.coe_mul
--- porting note: this used to be `@[simp]` in Lean 3 but in Lean 4 `simp` can already
--- prove it because we've just proved we're in MulZeroClass.
-theorem zero_mul {α : Type u} [Mul α] (a : WithZero α) : 0 * a = 0 :=
- rfl
--- Porting note: This lemma and the next one
--- don't actually appear to exist in mathlib 3?
--- #align with_zero.zero_mul WithZero.zero_mul
-
--- porting note: in Lean 3 this was `@[simp]` but in Lean 4 `simp` can already prove it.
-theorem mul_zero {α : Type u} [Mul α] (a : WithZero α) : a * 0 = 0 := by cases a <;> rfl
--- #align with_zero.mul_zero WithZero.mul_zero
-
instance noZeroDivisors [Mul α] : NoZeroDivisors (WithZero α) :=
- ⟨by
- rintro (a | a) (b | b) h
- exacts[Or.inl rfl, Or.inl rfl, Or.inr rfl, Option.noConfusion h]⟩
+ ⟨Option.map₂_eq_none_iff.1⟩
instance semigroupWithZero [Semigroup α] : SemigroupWithZero (WithZero α) :=
{ WithZero.mulZeroClass with
- mul_assoc := fun a b c =>
- match a, b, c with
- | none, _, _ => rfl
- | some _, none, _ => rfl
- | some _, some _, none => rfl
- | some a, some b, some c => congr_arg some (mul_assoc a b c) }
+ mul_assoc := fun _ _ _ => Option.map₂_assoc mul_assoc }
instance commSemigroup [CommSemigroup α] : CommSemigroup (WithZero α) :=
{ WithZero.semigroupWithZero with
- mul_comm := fun a b =>
- match a, b with
- | none, _ => (mul_zero _).symm
- | some _, none => rfl
- | some a, some b => congr_arg some (mul_comm a b) }
+ mul_comm := fun _ _ => Option.map₂_comm mul_comm }
instance mulZeroOneClass [MulOneClass α] : MulZeroOneClass (WithZero α) :=
{ WithZero.mulZeroClass, WithZero.one with
- one_mul := fun a =>
- match a with
- | none => rfl
- | some a => congr_arg some <| one_mul a,
- mul_one := fun a =>
- match a with
- | none => rfl
- | some a => congr_arg some <| mul_one a }
+ one_mul := Option.map₂_left_identity one_mul,
+ mul_one := Option.map₂_right_identity mul_one }
instance pow [One α] [Pow α ℕ] : Pow (WithZero α) ℕ :=
⟨fun x n =>
@@ -335,7 +313,7 @@ instance invOneClass [InvOneClass α] : InvOneClass (WithZero α) :=
{ WithZero.one, WithZero.inv with inv_one := show ((1⁻¹ : α) : WithZero α) = 1 by simp }
instance div [Div α] : Div (WithZero α) :=
- ⟨fun o₁ o₂ => o₁.bind fun a => Option.map (fun b => a / b) o₂⟩
+ ⟨Option.map₂ (· / ·)⟩
@[norm_cast]
theorem coe_div [Div α] (a b : α) : ↑(a / b : α) = (a / b : WithZero α) :=
@@ -59,16 +59,19 @@ instance monad : Monad WithOne :=
instance one : One (WithOne α) :=
⟨none⟩
#align with_one.has_one WithOne.one
+#align with_zero.has_zero WithZero.zero
@[to_additive]
instance mul [Mul α] : Mul (WithOne α) :=
⟨Option.liftOrGet (· * ·)⟩
#align with_one.has_mul WithOne.mul
+#align with_zero.has_add WithZero.add
@[to_additive]
instance inv [Inv α] : Inv (WithOne α) :=
⟨fun a => Option.map Inv.inv a⟩
#align with_one.has_inv WithOne.inv
+#align with_zero.has_neg WithZero.neg
@[to_additive]
instance involutiveInv [InvolutiveInv α] : InvolutiveInv (WithOne α) :=
@@ -239,11 +239,13 @@ theorem coe_mul {α : Type u} [Mul α] {a b : α} : ((a * b : α) : WithZero α)
-- prove it because we've just proved we're in MulZeroClass.
theorem zero_mul {α : Type u} [Mul α] (a : WithZero α) : 0 * a = 0 :=
rfl
-#align with_zero.zero_mul WithZero.zero_mul
+-- Porting note: This lemma and the next one
+-- don't actually appear to exist in mathlib 3?
+-- #align with_zero.zero_mul WithZero.zero_mul
-- porting note: in Lean 3 this was `@[simp]` but in Lean 4 `simp` can already prove it.
theorem mul_zero {α : Type u} [Mul α] (a : WithZero α) : a * 0 = 0 := by cases a <;> rfl
-#align with_zero.mul_zero WithZero.mul_zero
+-- #align with_zero.mul_zero WithZero.mul_zero
instance noZeroDivisors [Mul α] : NoZeroDivisors (WithZero α) :=
⟨by
to_additive
is @[to_additive (attrs := simp, ext, simps)]
simp
and simps
attributes to the to_additive
-dictionary.simp
-attributes). In particular it's possible that norm_cast
might generate some auxiliary declarations.to_additive
and simps
from the Simps
file to the toAdditive
file for uniformity.@[reassoc]
Co-authored-by: Johan Commelin <johan@commelin.net> Co-authored-by: Scott Morrison <scott.morrison@gmail.com>
@@ -92,7 +92,7 @@ instance nontrivial [Nonempty α] : Nontrivial (WithOne α) :=
-- otherwise the coercion kicks in and it becomes `Option.some a : WithOne α` which
-- becomes `Option.some a : Option α`.
/-- The canonical map from `α` into `WithOne α` -/
-@[coe, to_additive "The canonical map from `α` into `WithZero α`"]
+@[to_additive (attr := coe) "The canonical map from `α` into `WithZero α`"]
def coe : α → WithOne α :=
Option.some
@@ -101,7 +101,8 @@ instance coeTC : CoeTC α (WithOne α) :=
⟨coe⟩
/-- Recursor for `WithOne` using the preferred forms `1` and `↑a`. -/
-@[elab_as_elim, to_additive "Recursor for `WithZero` using the preferred forms `0` and `↑a`."]
+@[to_additive (attr := elab_as_elim)
+ "Recursor for `WithZero` using the preferred forms `0` and `↑a`."]
def recOneCoe {C : WithOne α → Sort _} (h₁ : C 1) (h₂ : ∀ a : α, C a) : ∀ n : WithOne α, C n
| Option.none => h₁
| Option.some x => h₂ x
@@ -123,13 +124,13 @@ def unone {x : WithOne α} (hx : x ≠ 1) : α :=
#align with_one.unone WithOne.unone
#align with_zero.unzero WithZero.unzero
-@[simp, to_additive unzero_coe]
+@[to_additive (attr := simp) unzero_coe]
theorem unone_coe {x : α} (hx : (x : WithOne α) ≠ 1) : unone hx = x :=
rfl
#align with_one.unone_coe WithOne.unone_coe
#align with_zero.unzero_coe WithZero.unzero_coe
-@[simp, to_additive coe_unzero]
+@[to_additive (attr := simp) coe_unzero]
theorem coe_unone {x : WithOne α} (hx : x ≠ 1) : ↑(unone hx) = x :=
WithBot.coe_unbot x hx
#align with_one.coe_unone WithOne.coe_unone
@@ -140,13 +141,13 @@ theorem coe_unone {x : WithOne α} (hx : x ≠ 1) : ↑(unone hx) = x :=
#noalign with_one.some_eq_coe
#noalign with_zero.some_eq_coe
-@[simp, to_additive]
+@[to_additive (attr := simp)]
theorem coe_ne_one {a : α} : (a : WithOne α) ≠ (1 : WithOne α) :=
Option.some_ne_none a
#align with_one.coe_ne_one WithOne.coe_ne_one
#align with_zero.coe_ne_zero WithZero.coe_ne_zero
-@[simp, to_additive]
+@[to_additive (attr := simp)]
theorem one_ne_coe {a : α} : (1 : WithOne α) ≠ a :=
coe_ne_one.symm
#align with_one.one_ne_coe WithOne.one_ne_coe
@@ -164,17 +165,13 @@ instance canLift : CanLift (WithOne α) α (↑) fun a => a ≠ 1 where
#align with_one.can_lift WithOne.canLift
#align with_zero.can_lift WithZero.canLift
-@[simp, norm_cast, to_additive]
+@[to_additive (attr := simp, norm_cast)]
theorem coe_inj {a b : α} : (a : WithOne α) = b ↔ a = b :=
Option.some_inj
#align with_one.coe_inj WithOne.coe_inj
#align with_zero.coe_inj WithZero.coe_inj
--- port note: at the time of writing it seems that `@[norm_cast, to_additive]` doesn't
--- put the norm_cast tag on the to_additivised declaration.
-attribute [norm_cast] WithZero.coe_inj
-
-@[elab_as_elim, to_additive]
+@[to_additive (attr := elab_as_elim)]
protected theorem cases_on {P : WithOne α → Prop} : ∀ x : WithOne α, P 1 → (∀ a : α, P a) → P x :=
Option.casesOn
#align with_one.cases_on WithOne.cases_on
@@ -203,26 +200,18 @@ instance monoid [Semigroup α] : Monoid (WithOne α) :=
instance commMonoid [CommSemigroup α] : CommMonoid (WithOne α) :=
{ WithOne.monoid with mul_comm := (Option.liftOrGet_isCommutative _).1 }
-@[simp, norm_cast, to_additive]
+@[to_additive (attr := simp, norm_cast)]
theorem coe_mul [Mul α] (a b : α) : ((a * b : α) : WithOne α) = a * b :=
rfl
#align with_one.coe_mul WithOne.coe_mul
#align with_zero.coe_add WithZero.coe_add
--- porting note: in Mathlib3 `[norm_cast, to_additive]` would put the `norm_cast` attribute
--- on the additivised declaration. At the time of writing this isn't true in Mathlib4
-attribute [norm_cast] WithZero.coe_add
-
-@[simp, norm_cast, to_additive]
+@[to_additive (attr := simp, norm_cast)]
theorem coe_inv [Inv α] (a : α) : ((a⁻¹ : α) : WithOne α) = (a : WithOne α)⁻¹ :=
rfl
#align with_one.coe_inv WithOne.coe_inv
#align with_zero.coe_neg WithZero.coe_neg
--- porting note: in Mathlib3 `[norm_cast, to_additive]` would put the `norm_cast` attribute
--- on the additivised declaration. At the time of writing this isn't true in Mathlib4
-attribute [norm_cast] WithZero.coe_neg
-
end WithOne
namespace WithZero
@@ -10,6 +10,7 @@ Authors: Mario Carneiro, Johan Commelin
-/
import Mathlib.Order.WithBot
import Mathlib.Algebra.Ring.Defs
+import Mathlib.Tactic.Lift
/-!
# Adjoining a zero/one to semigroups and related algebraic structures
@@ -157,10 +158,11 @@ theorem ne_one_iff_exists {x : WithOne α} : x ≠ 1 ↔ ∃ a : α, ↑a = x :=
#align with_one.ne_one_iff_exists WithOne.ne_one_iff_exists
#align with_zero.ne_zero_iff_exists WithZero.ne_zero_iff_exists
--- porting note : waiting for `lift` tactic
---@[to_additive]
---instance canLift : CanLift (WithOne α) α coe fun a => a ≠ 1 where prf a := ne_one_iff_exists.1
---#align with_one.can_lift WithOne.canLift
+@[to_additive]
+instance canLift : CanLift (WithOne α) α (↑) fun a => a ≠ 1 where
+ prf _ := ne_one_iff_exists.1
+#align with_one.can_lift WithOne.canLift
+#align with_zero.can_lift WithZero.canLift
@[simp, norm_cast, to_additive]
theorem coe_inj {a b : α} : (a : WithOne α) = b ↔ a = b :=
@@ -406,19 +408,14 @@ section Group
variable [Group α]
--- porting note: the lean 3 proof of this used the `lift` tactic, which was not
--- present in mathlib4 at the time of porting; we instead do a case split.
/-- if `G` is a group then `WithZero G` is a group with zero. -/
instance groupWithZero : GroupWithZero (WithZero α) :=
{ WithZero.monoidWithZero, WithZero.divInvMonoid, WithZero.nontrivial with
inv_zero := inv_zero,
- mul_inv_cancel := fun a _ ↦
- match a with
- | Option.none => by contradiction
- | (x : α) => by
+ mul_inv_cancel := fun a ha ↦ by
+ lift a to α using ha
norm_cast
- apply mul_right_inv
- }
+ apply mul_right_inv }
end Group
Fix a lot of wrong casing mostly in the docstrings but also sometimes in def/theorem names. E.g. fin 2 --> Fin 2
, add_monoid_hom --> AddMonoidHom
Remove \n
from to_additive
docstrings that were inserted by mathport.
Move files and directories with Gcd
and Smul
to GCD
and SMul
@@ -18,7 +18,7 @@ This file contains different results about adjoining an element to an algebraic
behaves like a zero or a one. An example is adjoining a one to a semigroup to obtain a monoid. That
this provides an example of an adjunction is proved in `Algebra.Category.MonCat.Adjunctions`.
-Another result says that adjoining to a group an element `zero` gives a `group_with_zero`. For more
+Another result says that adjoining to a group an element `zero` gives a `GroupWithZero`. For more
information about these structures (which are not that standard in informal mathematics, see
`Algebra.GroupWithZero.Basic`)
-/
@@ -99,8 +99,8 @@ def coe : α → WithOne α :=
instance coeTC : CoeTC α (WithOne α) :=
⟨coe⟩
-/-- Recursor for `with_one` using the preferred forms `1` and `↑a`. -/
-@[elab_as_elim, to_additive "Recursor for `with_zero` using the preferred forms `0` and `↑a`."]
+/-- Recursor for `WithOne` using the preferred forms `1` and `↑a`. -/
+@[elab_as_elim, to_additive "Recursor for `WithZero` using the preferred forms `0` and `↑a`."]
def recOneCoe {C : WithOne α → Sort _} (h₁ : C 1) (h₂ : ∀ a : α, C a) : ∀ n : WithOne α, C n
| Option.none => h₁
| Option.some x => h₂ x
@@ -114,9 +114,9 @@ def recOneCoe {C : WithOne α → Sort _} (h₁ : C 1) (h₂ : ∀ a : α, C a)
attribute [elab_as_elim] WithZero.recZeroCoe
-/-- Deconstruct a `x : with_one α` to the underlying value in `α`, given a proof that `x ≠ 1`. -/
+/-- Deconstruct a `x : WithOne α` to the underlying value in `α`, given a proof that `x ≠ 1`. -/
@[to_additive unzero
- "Deconstruct a `x : with_zero α` to the underlying value in `α`, given a proof that `x ≠ 0`."]
+ "Deconstruct a `x : WithZero α` to the underlying value in `α`, given a proof that `x ≠ 0`."]
def unone {x : WithOne α} (hx : x ≠ 1) : α :=
WithBot.unbot x hx
#align with_one.unone WithOne.unone
@@ -183,7 +183,7 @@ attribute [elab_as_elim] WithZero.cases_on
-- porting note: in Lean 3 there was the following comment:
-- the `show` statements in the proofs are important, because otherwise the generated lemmas
--- `with_one.mul_one_class._proof_{1,2}` have an ill-typed statement after `with_one` is made
+-- `WithOne.mulOneClass._proof_{1,2}` have an ill-typed statement after `WithOne` is made
-- irreducible. Maybe one day when mathlib is ported to Lean 4 we can experiment
-- to see if these `show` comments can be removed.
@[to_additive]
@@ -316,7 +316,7 @@ instance commMonoidWithZero [CommMonoid α] : CommMonoidWithZero (WithZero α) :
{ WithZero.monoidWithZero, WithZero.commSemigroup with }
/-- Given an inverse operation on `α` there is an inverse operation
- on `with_zero α` sending `0` to `0`-/
+ on `WithZero α` sending `0` to `0`-/
instance inv [Inv α] : Inv (WithZero α) :=
⟨fun a => Option.map Inv.inv a⟩
@@ -408,7 +408,7 @@ variable [Group α]
-- porting note: the lean 3 proof of this used the `lift` tactic, which was not
-- present in mathlib4 at the time of porting; we instead do a case split.
-/-- if `G` is a group then `with_zero G` is a group with zero. -/
+/-- if `G` is a group then `WithZero G` is a group with zero. -/
instance groupWithZero : GroupWithZero (WithZero α) :=
{ WithZero.monoidWithZero, WithZero.divInvMonoid, WithZero.nontrivial with
inv_zero := inv_zero,
The script used to do this is included. The yaml file was obtained from https://raw.githubusercontent.com/wiki/leanprover-community/mathlib/mathlib4-port-status.md
@@ -2,6 +2,11 @@
Copyright (c) 2018 Mario Carneiro. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Mario Carneiro, Johan Commelin
+
+! This file was ported from Lean 3 source module algebra.group.with_one.defs
+! leanprover-community/mathlib commit e574b1a4e891376b0ef974b926da39e05da12a06
+! Please do not edit these lines, except to modify the commit id
+! if you have ported upstream changes.
-/
import Mathlib.Order.WithBot
import Mathlib.Algebra.Ring.Defs
All dependencies are ported!