@@ -95,14 +95,10 @@ TODO: rename to `FreeAddCommGroup` and introduce a multiplicative version
9595-/
9696def FreeAbelianGroup : Type u :=
9797 Additive <| Abelianization <| FreeGroup α
98+ deriving Inhabited, AddCommGroup
9899
99- instance FreeAbelianGroup.addCommGroup : AddCommGroup (FreeAbelianGroup α) :=
100- fast_instance% @Additive.addCommGroup _ <| Abelianization.commGroup _
101-
102- instance : Inhabited (FreeAbelianGroup α) :=
103- ⟨0 ⟩
104-
105- instance [IsEmpty α] : Unique (FreeAbelianGroup α) := by unfold FreeAbelianGroup; infer_instance
100+ instance [IsEmpty α] : Unique (FreeAbelianGroup α) :=
101+ inferInstanceAs <| Unique (delta% FreeAbelianGroup α)
106102
107103variable {α}
108104
@@ -408,18 +404,15 @@ theorem of_mul_of (x y : α) : of x * of y = of (x * y) := by
408404theorem of_mul (x y : α) : of (x * y) = of x * of y :=
409405 Eq.symm <| of_mul_of x y
410406
411- instance distrib : Distrib (FreeAbelianGroup α) :=
412- { FreeAbelianGroup.mul α, FreeAbelianGroup.addCommGroup α with
413- left_distrib := fun _ _ _ ↦ (lift _).map_add _ _
414- right_distrib x y z := by simp [mul_def, ← Pi.add_def] }
407+ instance distrib : Distrib (FreeAbelianGroup α) where
408+ left_distrib := fun _ _ _ ↦ (lift _).map_add _ _
409+ right_distrib x y z := by simp [mul_def, ← Pi.add_def]
415410
416- instance nonUnitalNonAssocRing : NonUnitalNonAssocRing (FreeAbelianGroup α) :=
417- { FreeAbelianGroup.distrib,
418- FreeAbelianGroup.addCommGroup _ with
419- zero_mul := fun a ↦ by
420- have h : 0 * a + 0 * a = 0 * a := by simp [← add_mul]
421- simpa using h
422- mul_zero := fun _ ↦ rfl }
411+ instance nonUnitalNonAssocRing : NonUnitalNonAssocRing (FreeAbelianGroup α) where
412+ zero_mul a := by
413+ have h : 0 * a + 0 * a = 0 * a := by simp [← add_mul]
414+ simpa using h
415+ mul_zero _ := rfl
423416
424417end Mul
425418
@@ -437,46 +430,43 @@ theorem of_one : (of 1 : FreeAbelianGroup α) = 1 :=
437430
438431end One
439432
440- instance nonUnitalRing [Semigroup α] : NonUnitalRing (FreeAbelianGroup α) :=
441- { FreeAbelianGroup.nonUnitalNonAssocRing with
442- mul_assoc x y z := by
443- induction z using FreeAbelianGroup.induction_on with
444- | zero => simp only [mul_zero]
445- | of L3 =>
446- induction y using FreeAbelianGroup.induction_on with
447- | zero => simp only [mul_zero, zero_mul]
448- | of L2 =>
449- induction x using FreeAbelianGroup.induction_on with
450- | zero => simp only [zero_mul]
451- | of L1 => rw [of_mul_of, of_mul_of, of_mul_of, of_mul_of, mul_assoc]
452- | neg L1 ih => rw [neg_mul, neg_mul, neg_mul, ih]
453- | add x₁ x₂ ih₁ ih₂ => rw [add_mul, add_mul, add_mul, ih₁, ih₂]
454- | neg L2 ih => rw [neg_mul, mul_neg, mul_neg, neg_mul, ih]
455- | add y₁ y₂ ih₁ ih₂ => rw [add_mul, mul_add, mul_add, add_mul, ih₁, ih₂]
456- | neg L3 ih => rw [mul_neg, mul_neg, mul_neg, ih]
457- | add z₁ z₂ ih₁ ih₂ => rw [mul_add, mul_add, mul_add, ih₁, ih₂] }
433+ instance nonUnitalRing [Semigroup α] : NonUnitalRing (FreeAbelianGroup α) where
434+ mul_assoc x y z := by
435+ induction z using FreeAbelianGroup.induction_on with
436+ | zero => simp only [mul_zero]
437+ | of L3 =>
438+ induction y using FreeAbelianGroup.induction_on with
439+ | zero => simp only [mul_zero, zero_mul]
440+ | of L2 =>
441+ induction x using FreeAbelianGroup.induction_on with
442+ | zero => simp only [zero_mul]
443+ | of L1 => rw [of_mul_of, of_mul_of, of_mul_of, of_mul_of, mul_assoc]
444+ | neg L1 ih => rw [neg_mul, neg_mul, neg_mul, ih]
445+ | add x₁ x₂ ih₁ ih₂ => rw [add_mul, add_mul, add_mul, ih₁, ih₂]
446+ | neg L2 ih => rw [neg_mul, mul_neg, mul_neg, neg_mul, ih]
447+ | add y₁ y₂ ih₁ ih₂ => rw [add_mul, mul_add, mul_add, add_mul, ih₁, ih₂]
448+ | neg L3 ih => rw [mul_neg, mul_neg, mul_neg, ih]
449+ | add z₁ z₂ ih₁ ih₂ => rw [mul_add, mul_add, mul_add, ih₁, ih₂]
458450
459451section Monoid
460452
461453variable {R : Type *} [Monoid α] [Ring R]
462454
463- instance ring : Ring (FreeAbelianGroup α) :=
464- { FreeAbelianGroup.nonUnitalRing _,
465- FreeAbelianGroup.one _ with
466- mul_one x := by
467- rw [mul_def, one_def, lift_apply_of]
468- induction x using FreeAbelianGroup.induction_on with
469- | zero => rfl
470- | of L => rw [lift_apply_of, mul_one]
471- | neg L ih => rw [map_neg, ih]
472- | add x1 x2 ih1 ih2 => rw [map_add, ih1, ih2]
473- one_mul x := by
474- simp_rw [mul_def, one_def, lift_apply_of]
475- induction x using FreeAbelianGroup.induction_on with
476- | zero => rfl
477- | of L => rw [lift_apply_of, one_mul]
478- | neg L ih => rw [map_neg, ih]
479- | add x1 x2 ih1 ih2 => rw [map_add, ih1, ih2] }
455+ instance ring : Ring (FreeAbelianGroup α) where
456+ mul_one x := by
457+ rw [mul_def, one_def, lift_apply_of]
458+ induction x using FreeAbelianGroup.induction_on with
459+ | zero => rfl
460+ | of L => rw [lift_apply_of, mul_one]
461+ | neg L ih => rw [map_neg, ih]
462+ | add x1 x2 ih1 ih2 => rw [map_add, ih1, ih2]
463+ one_mul x := by
464+ simp_rw [mul_def, one_def, lift_apply_of]
465+ induction x using FreeAbelianGroup.induction_on with
466+ | zero => rfl
467+ | of L => rw [lift_apply_of, one_mul]
468+ | neg L ih => rw [map_neg, ih]
469+ | add x1 x2 ih1 ih2 => rw [map_add, ih1, ih2]
480470
481471variable {α}
482472
@@ -534,29 +524,22 @@ theorem liftMonoid_symm_coe (f : FreeAbelianGroup α →+* R) :
534524
535525end Monoid
536526
537- instance [CommMonoid α] : CommRing (FreeAbelianGroup α) :=
538- { FreeAbelianGroup.ring α with
539- mul_comm x y := by
540- induction x using FreeAbelianGroup.induction_on with
541- | zero => exact zero_mul y
542- | of s =>
543- induction y using FreeAbelianGroup.induction_on with
544- | zero => exact (zero_mul _).symm
545- | of t =>
546- dsimp only [(· * ·), Mul.mul]
547- iterate 4 rw [lift_apply_of]
548- congr 1
549- exact mul_comm _ _
550- | neg t ih => rw [mul_neg, ih, neg_mul_eq_neg_mul]
551- | add y1 y2 ih1 ih2 => rw [mul_add, add_mul, ih1, ih2]
552- | neg s ih => rw [neg_mul, ih, neg_mul_eq_mul_neg]
553- | add x1 x2 ih1 ih2 => rw [add_mul, mul_add, ih1, ih2] }
554-
555- instance pemptyUnique : Unique (FreeAbelianGroup PEmpty) where
556- default := 0
557- uniq x := FreeAbelianGroup.induction_on x rfl (PEmpty.elim ·) (PEmpty.elim ·) (by
558- rintro - - rfl rfl
559- rfl)
527+ instance [CommMonoid α] : CommRing (FreeAbelianGroup α) where
528+ mul_comm x y := by
529+ induction x using FreeAbelianGroup.induction_on with
530+ | zero => exact zero_mul y
531+ | of s =>
532+ induction y using FreeAbelianGroup.induction_on with
533+ | zero => exact (zero_mul _).symm
534+ | of t =>
535+ dsimp only [(· * ·), Mul.mul]
536+ iterate 4 rw [lift_apply_of]
537+ congr 1
538+ exact mul_comm _ _
539+ | neg t ih => rw [mul_neg, ih, neg_mul_eq_neg_mul]
540+ | add y1 y2 ih1 ih2 => rw [mul_add, add_mul, ih1, ih2]
541+ | neg s ih => rw [neg_mul, ih, neg_mul_eq_mul_neg]
542+ | add x1 x2 ih1 ih2 => rw [add_mul, mul_add, ih1, ih2]
560543
561544/-- The free abelian group on a type with one term is isomorphic to `ℤ`. -/
562545def uniqueEquiv (T : Type *) [Unique T] : FreeAbelianGroup T ≃+ ℤ where
0 commit comments