Skip to content

Commit 47062a7

Browse files
committed
chore: Split Data.{Nat,Int}{.Order}.Basic in group vs ring instances (#11924)
Scatter the content of `Data.Nat.Basic` across: * `Data.Nat.Defs` for the lemmas having no dependencies * `Algebra.Group.Nat` for the monoid instances and the few miscellaneous lemmas needing them. * `Algebra.Ring.Nat` for the semiring instance and the few miscellaneous lemmas following it. Similarly, scatter * `Data.Int.Basic` across `Data.Int.Defs`, `Algebra.Group.Int`, `Algebra.Ring.Int` * `Data.Nat.Order.Basic` across `Data.Nat.Defs`, `Algebra.Order.Group.Nat`, `Algebra.Order.Ring.Nat` * `Data.Int.Order.Basic` across `Data.Int.Defs`, `Algebra.Order.Group.Int`, `Algebra.Order.Ring.Int` Also move a few lemmas from `Data.Nat.Order.Lemmas` to `Data.Nat.Defs`. Before ![pre_11924](https://github.com/leanprover-community/mathlib4/assets/14090593/be8a6259-9d2d-434d-b4a5-f5667feb9e1d) After ![post_11924](https://github.com/leanprover-community/mathlib4/assets/14090593/3944f37f-8cfd-4254-830b-d0dbcd23b50a)
1 parent 98715c2 commit 47062a7

File tree

97 files changed

+819
-653
lines changed

Some content is hidden

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

97 files changed

+819
-653
lines changed

Counterexamples/ZeroDivisorsInAddMonoidAlgebras.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def List.dropUntil {α} [DecidableEq α] : List α → List α → List α
134134
open Lean Elab in
135135
/-- `guard_decl na mod` makes sure that the declaration with name `na` is in the module `mod`.
136136
```lean
137-
guard_decl Nat.nontrivial Mathlib.Data.Nat.Basic -- does nothing
137+
guard_decl Nat.nontrivial Mathlib.Algebra.Ring.Nat -- does nothing
138138
139139
guard_decl Nat.nontrivial Not.In.Here
140140
-- the module Not.In.Here is not imported!

Mathlib.lean

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,9 @@ import Mathlib.Algebra.Group.Hom.CompTypeclasses
195195
import Mathlib.Algebra.Group.Hom.Defs
196196
import Mathlib.Algebra.Group.Hom.Instances
197197
import Mathlib.Algebra.Group.InjSurj
198+
import Mathlib.Algebra.Group.Int
198199
import Mathlib.Algebra.Group.MinimalAxioms
200+
import Mathlib.Algebra.Group.Nat
199201
import Mathlib.Algebra.Group.NatPowAssoc
200202
import Mathlib.Algebra.Group.Opposite
201203
import Mathlib.Algebra.Group.OrderSynonym
@@ -431,8 +433,10 @@ import Mathlib.Algebra.Order.Group.Defs
431433
import Mathlib.Algebra.Order.Group.DenselyOrdered
432434
import Mathlib.Algebra.Order.Group.InjSurj
433435
import Mathlib.Algebra.Order.Group.Instances
436+
import Mathlib.Algebra.Order.Group.Int
434437
import Mathlib.Algebra.Order.Group.Lattice
435438
import Mathlib.Algebra.Order.Group.MinMax
439+
import Mathlib.Algebra.Order.Group.Nat
436440
import Mathlib.Algebra.Order.Group.OrderIso
437441
import Mathlib.Algebra.Order.Group.PosPart
438442
import Mathlib.Algebra.Order.Group.Prod
@@ -479,7 +483,9 @@ import Mathlib.Algebra.Order.Ring.CharZero
479483
import Mathlib.Algebra.Order.Ring.Cone
480484
import Mathlib.Algebra.Order.Ring.Defs
481485
import Mathlib.Algebra.Order.Ring.InjSurj
486+
import Mathlib.Algebra.Order.Ring.Int
482487
import Mathlib.Algebra.Order.Ring.Lemmas
488+
import Mathlib.Algebra.Order.Ring.Nat
483489
import Mathlib.Algebra.Order.Ring.Pow
484490
import Mathlib.Algebra.Order.Ring.Star
485491
import Mathlib.Algebra.Order.Ring.WithTop
@@ -559,7 +565,9 @@ import Mathlib.Algebra.Ring.Hom.Basic
559565
import Mathlib.Algebra.Ring.Hom.Defs
560566
import Mathlib.Algebra.Ring.Idempotents
561567
import Mathlib.Algebra.Ring.InjSurj
568+
import Mathlib.Algebra.Ring.Int
562569
import Mathlib.Algebra.Ring.MinimalAxioms
570+
import Mathlib.Algebra.Ring.Nat
563571
import Mathlib.Algebra.Ring.Opposite
564572
import Mathlib.Algebra.Ring.OrderSynonym
565573
import Mathlib.Algebra.Ring.Pi
@@ -1806,7 +1814,6 @@ import Mathlib.Data.HashMap
18061814
import Mathlib.Data.Holor
18071815
import Mathlib.Data.Int.AbsoluteValue
18081816
import Mathlib.Data.Int.Associated
1809-
import Mathlib.Data.Int.Basic
18101817
import Mathlib.Data.Int.Bitwise
18111818
import Mathlib.Data.Int.CardIntervalMod
18121819
import Mathlib.Data.Int.Cast.Basic
@@ -1827,7 +1834,6 @@ import Mathlib.Data.Int.Lemmas
18271834
import Mathlib.Data.Int.Log
18281835
import Mathlib.Data.Int.ModEq
18291836
import Mathlib.Data.Int.NatPrime
1830-
import Mathlib.Data.Int.Order.Basic
18311837
import Mathlib.Data.Int.Order.Lemmas
18321838
import Mathlib.Data.Int.Order.Units
18331839
import Mathlib.Data.Int.Parity
@@ -1931,7 +1937,6 @@ import Mathlib.Data.Multiset.Sym
19311937
import Mathlib.Data.NNRat.BigOperators
19321938
import Mathlib.Data.NNRat.Defs
19331939
import Mathlib.Data.NNRat.Lemmas
1934-
import Mathlib.Data.Nat.Basic
19351940
import Mathlib.Data.Nat.Bits
19361941
import Mathlib.Data.Nat.Bitwise
19371942
import Mathlib.Data.Nat.Cast.Basic
@@ -1981,7 +1986,6 @@ import Mathlib.Data.Nat.MaxPowDiv
19811986
import Mathlib.Data.Nat.ModEq
19821987
import Mathlib.Data.Nat.Multiplicity
19831988
import Mathlib.Data.Nat.Nth
1984-
import Mathlib.Data.Nat.Order.Basic
19851989
import Mathlib.Data.Nat.Order.Lemmas
19861990
import Mathlib.Data.Nat.PSub
19871991
import Mathlib.Data.Nat.Pairing

Mathlib/Algebra/BigOperators/List/Basic.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Johannes Hölzl, Floris van Doorn, Sébastien Gouëzel, Alex J. Best
55
-/
66
import Mathlib.Algebra.Ring.Commute
7-
import Mathlib.Data.Int.Basic
7+
import Mathlib.Algebra.Ring.Int
8+
import Mathlib.Algebra.Ring.Nat
89
import Mathlib.Data.List.Dedup
910
import Mathlib.Data.List.ProdSigma
1011
import Mathlib.Data.List.Join
1112
import Mathlib.Data.List.Perm
1213
import Mathlib.Data.List.Range
1314
import Mathlib.Data.List.Rotate
14-
import Mathlib.Data.Nat.Basic
1515

1616
#align_import data.list.big_operators.basic from "leanprover-community/mathlib"@"6c5f73fd6f6cc83122788a80a27cdd54663609f4"
1717

Mathlib/Algebra/EuclideanDomain/Instances.lean

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,10 @@ Authors: Louis Carlin, Mario Carneiro
55
-/
66
import Mathlib.Algebra.EuclideanDomain.Defs
77
import Mathlib.Algebra.Field.Defs
8+
import Mathlib.Algebra.Group.Nat
89
import Mathlib.Algebra.GroupWithZero.Units.Basic
9-
import Mathlib.Data.Int.Order.Basic
10+
import Mathlib.Algebra.Order.Group.Int
11+
import Mathlib.Algebra.Ring.Int
1012

1113
#align_import algebra.euclidean_domain.instances from "leanprover-community/mathlib"@"e1bccd6e40ae78370f01659715d3c948716e3b7e"
1214

Mathlib/Data/Int/Basic.lean renamed to Mathlib/Algebra/Group/Int.lean

Lines changed: 21 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -4,34 +4,36 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Jeremy Avigad
55
-/
66
import Mathlib.Algebra.Group.TypeTags
7-
import Mathlib.Algebra.Ring.Defs
8-
import Mathlib.Data.Int.Cast.Basic
97
import Mathlib.Order.Monotone.Basic
108

119
#align_import data.int.basic from "leanprover-community/mathlib"@"00d163e35035c3577c1c79fa53b68de17781ffc1"
1210

1311
/-!
14-
# Basic algebraic instances on the integers
12+
# The integers form a group
1513
16-
This file contains instances on `ℤ`. The stronger one is `Int.linearOrderedCommRing`.
14+
This file contains the additive group and multiplicative monoid instances on the integers.
15+
16+
See note [foundational algebra order theory].
1717
-/
1818

19+
assert_not_exists Ring
20+
1921
open Nat
2022

2123
namespace Int
2224

23-
instance instCommRingInt : CommRing ℤ where
24-
zero_mul := Int.zero_mul
25-
mul_zero := Int.mul_zero
25+
/-! ### Instances -/
26+
27+
instance instCommMonoidInt : CommMonoid ℤ where
2628
mul_comm := Int.mul_comm
27-
left_distrib := Int.mul_add
28-
right_distrib := Int.add_mul
2929
mul_one := Int.mul_one
3030
one_mul := Int.one_mul
3131
npow n x := x ^ n
3232
npow_zero _ := rfl
33-
npow_succ n x := rfl
33+
npow_succ _ _ := rfl
3434
mul_assoc := Int.mul_assoc
35+
36+
instance instAddCommGroup : AddCommGroup ℤ where
3537
add_comm := Int.add_comm
3638
add_assoc := Int.add_assoc
3739
add_zero := Int.add_zero
@@ -48,54 +50,27 @@ instance instCommRingInt : CommRing ℤ where
4850
simp only [ofNat_eq_coe, ofNat_succ, Int.add_mul, Int.add_comm, Int.one_mul]
4951
zsmul_neg' m n := by simp only [negSucc_coe, ofNat_succ, Int.neg_mul]
5052
sub_eq_add_neg _ _ := Int.sub_eq_add_neg
51-
natCast := (·)
52-
natCast_zero := rfl
53-
natCast_succ _ := rfl
54-
intCast := (·)
55-
intCast_ofNat _ := rfl
56-
intCast_negSucc _ := rfl
57-
58-
@[simp, norm_cast] lemma cast_id {n : ℤ} : Int.cast n = n := rfl
59-
60-
@[simp, norm_cast]
61-
theorem cast_mul {α : Type*} [NonAssocRing α] : ∀ m n, ((m * n : ℤ) : α) = m * n := fun m => by
62-
obtain ⟨m, rfl | rfl⟩ := Int.eq_nat_or_neg m
63-
· induction m with
64-
| zero => simp
65-
| succ m ih => simp_all [add_mul]
66-
· induction m with
67-
| zero => simp
68-
| succ m ih => simp_all [add_mul]
69-
#align int.cast_mul Int.cast_mulₓ -- dubious translation, type involves HasLiftT
70-
71-
lemma cast_Nat_cast {n : ℕ} {R : Type*} [AddGroupWithOne R] :
72-
(Int.cast (Nat.cast n) : R) = Nat.cast n :=
73-
Int.cast_natCast _
7453

75-
@[simp, norm_cast] lemma cast_pow {R : Type*} [Ring R] (n : ℤ) (m : ℕ) :
76-
↑(n ^ m) = (n ^ m : R) := by
77-
induction' m with m ih <;> simp [_root_.pow_succ, *]
78-
#align int.cast_pow Int.cast_pow
79-
80-
/-! ### Extra instances to short-circuit type class resolution
54+
/-!
55+
### Extra instances to short-circuit type class resolution
8156
8257
These also prevent non-computable instances like `Int.normedCommRing` being used to construct
8358
these instances non-computably.
8459
-/
60+
8561
instance : AddCommMonoid ℤ := by infer_instance
8662
instance : AddMonoid ℤ := by infer_instance
8763
instance : Monoid ℤ := by infer_instance
88-
instance : CommMonoid ℤ := by infer_instance
8964
instance : CommSemigroup ℤ := by infer_instance
9065
instance : Semigroup ℤ := by infer_instance
91-
instance : AddCommGroup ℤ := by infer_instance
9266
instance : AddGroup ℤ := by infer_instance
67+
instance : AddCommGroup ℤ := by infer_instance
9368
instance : AddCommSemigroup ℤ := by infer_instance
9469
instance : AddSemigroup ℤ := by infer_instance
95-
instance : CommSemiring ℤ := by infer_instance
96-
instance : Semiring ℤ := by infer_instance
97-
instance instRingInt : Ring ℤ := by infer_instance
98-
instance : Distrib ℤ := by infer_instance
70+
71+
/-! ### Miscellaneous lemmas -/
72+
73+
@[simp, norm_cast] lemma cast_id {n : ℤ} : Int.cast n = n := rfl
9974

10075
lemma natAbs_pow (n : ℤ) (k : ℕ) : Int.natAbs (n ^ k) = Int.natAbs n ^ k := by
10176
induction' k with k ih
@@ -131,3 +106,4 @@ lemma zsmul_int_one (n : ℤ) : n • (1 : ℤ) = n := mul_one _
131106
#align zsmul_int_one zsmul_int_one
132107

133108
assert_not_exists Set.range
109+
assert_not_exists Ring

Mathlib/Algebra/Group/Nat.lean

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
/-
2+
Copyright (c) 2014 Floris van Doorn (c) 2016 Microsoft Corporation. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Floris van Doorn, Leonardo de Moura, Jeremy Avigad, Mario Carneiro
5+
-/
6+
import Mathlib.Algebra.Group.TypeTags
7+
8+
#align_import data.nat.basic from "leanprover-community/mathlib"@"bd835ef554f37ef9b804f0903089211f89cb370b"
9+
10+
/-!
11+
# The natural numbers form a monoid
12+
13+
This file contains the additive and multiplicative monoid instances on the natural numbers.
14+
15+
See note [foundational algebra order theory].
16+
-/
17+
18+
assert_not_exists Ring
19+
20+
open Multiplicative
21+
22+
namespace Nat
23+
24+
/-! ### Instances -/
25+
26+
instance addCommMonoid : AddCommMonoid ℕ where
27+
add := Nat.add
28+
add_assoc := Nat.add_assoc
29+
zero := Nat.zero
30+
zero_add := Nat.zero_add
31+
add_zero := Nat.add_zero
32+
add_comm := Nat.add_comm
33+
nsmul m n := m * n
34+
nsmul_zero := Nat.zero_mul
35+
nsmul_succ := succ_mul
36+
37+
instance commMonoid : CommMonoid ℕ where
38+
mul := Nat.mul
39+
mul_assoc := Nat.mul_assoc
40+
one := Nat.succ Nat.zero
41+
one_mul := Nat.one_mul
42+
mul_one := Nat.mul_one
43+
mul_comm := Nat.mul_comm
44+
npow m n := n ^ m
45+
npow_zero := Nat.pow_zero
46+
npow_succ _ _ := rfl
47+
48+
/-!
49+
### Extra instances to short-circuit type class resolution
50+
51+
These also prevent non-computable instances being used to construct these instances non-computably.
52+
-/
53+
54+
instance addMonoid : AddMonoid ℕ := by infer_instance
55+
instance monoid : Monoid ℕ := by infer_instance
56+
instance commSemigroup : CommSemigroup ℕ := by infer_instance
57+
instance semigroup : Semigroup ℕ := by infer_instance
58+
instance addCommSemigroup : AddCommSemigroup ℕ := by infer_instance
59+
instance addSemigroup : AddSemigroup ℕ := by infer_instance
60+
61+
/-! ### Miscellaneous lemmas -/
62+
63+
protected lemma nsmul_eq_mul (m n : ℕ) : m • n = m * n := rfl
64+
#align nat.nsmul_eq_mul Nat.nsmul_eq_mul
65+
66+
section Multiplicative
67+
68+
lemma toAdd_pow (a : Multiplicative ℕ) (b : ℕ) : toAdd (a ^ b) = toAdd a * b := mul_comm _ _
69+
#align nat.to_add_pow Nat.toAdd_pow
70+
71+
@[simp] lemma ofAdd_mul (a b : ℕ) : ofAdd (a * b) = ofAdd a ^ b := (toAdd_pow _ _).symm
72+
#align nat.of_add_mul Nat.ofAdd_mul
73+
74+
end Multiplicative
75+
end Nat

Mathlib/Algebra/Group/NatPowAssoc.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Authors: Scott Carnahan
55
-/
66
import Mathlib.Algebra.GroupPower.Basic
77
import Mathlib.GroupTheory.GroupAction.Prod
8-
import Mathlib.Data.Int.Basic
8+
import Mathlib.Algebra.Ring.Int
99
import Mathlib.Data.Nat.Cast.Basic
1010

1111
/-!

Mathlib/Algebra/GroupPower/IterateHom.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@ Copyright (c) 2020 Yury Kudryashov. All rights reserved.
33
Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Yury Kudryashov
55
-/
6+
import Mathlib.Algebra.Group.Int
7+
import Mathlib.Algebra.Group.Nat
68
import Mathlib.Algebra.Ring.Hom.Defs
7-
import Mathlib.Data.Int.Basic
8-
import Mathlib.Data.Nat.Basic
99
import Mathlib.GroupTheory.GroupAction.Opposite
1010

1111
#align_import algebra.hom.iterate from "leanprover-community/mathlib"@"792a2a264169d64986541c6f8f7e3bbb6acb6295"

Mathlib/Algebra/GroupWithZero/Power.lean

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,9 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Johan Commelin
55
-/
66
import Mathlib.Algebra.GroupWithZero.Commute
7-
import Mathlib.Data.Int.Order.Basic
7+
import Mathlib.Algebra.Order.Ring.CharZero
8+
import Mathlib.Algebra.Order.Ring.Int
9+
import Mathlib.Algebra.Order.Ring.Nat
810

911
#align_import algebra.group_with_zero.power from "leanprover-community/mathlib"@"46a64b5b4268c594af770c44d9e502afc6a515cb"
1012

Mathlib/Algebra/Module/Basic.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Authors: Nathaniel Thomas, Jeremy Avigad, Johannes Hölzl, Mario Carneiro
55
-/
66
import Mathlib.Algebra.Function.Indicator
77
import Mathlib.Algebra.SMulWithZero
8-
import Mathlib.Data.Int.Basic
8+
import Mathlib.Algebra.Ring.Int
99
import Mathlib.Data.NNRat.Defs
1010
import Mathlib.GroupTheory.GroupAction.Group
1111
import Mathlib.GroupTheory.GroupAction.Pi

0 commit comments

Comments
 (0)