Skip to content

Commit e66c5a9

Browse files
committed
chore (Data.Nat.Cast.Order): split into Basic and Ring (#14371)
We split `Data.Nat.Cast.Order` into `Data.Nat.Cast.Order.Basic` which only uses unbundled ordered algebra classes and `Data.Nat.Cast.Order.Ring` which uses bundled ordered algebra classes. This avoids importing bundled ordered algebra until later downstream. Co-authored-by: Matthew Robert Ballard <100034030+mattrobball@users.noreply.github.com>
1 parent 83e2503 commit e66c5a9

File tree

16 files changed

+130
-82
lines changed

16 files changed

+130
-82
lines changed

Mathlib.lean

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2181,7 +2181,8 @@ import Mathlib.Data.Nat.Cast.Commute
21812181
import Mathlib.Data.Nat.Cast.Defs
21822182
import Mathlib.Data.Nat.Cast.Field
21832183
import Mathlib.Data.Nat.Cast.NeZero
2184-
import Mathlib.Data.Nat.Cast.Order
2184+
import Mathlib.Data.Nat.Cast.Order.Basic
2185+
import Mathlib.Data.Nat.Cast.Order.Ring
21852186
import Mathlib.Data.Nat.Cast.Prod
21862187
import Mathlib.Data.Nat.Cast.SetInterval
21872188
import Mathlib.Data.Nat.Cast.Synonym

Mathlib/Algebra/Order/Group/Nat.lean

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ instance instOrderedSub : OrderedSub ℕ := by
4747

4848
/-! ### Miscellaneous lemmas -/
4949

50-
theorem _root_.NeZero.one_le {n : ℕ} [NeZero n] : 1 ≤ n := one_le_iff_ne_zero.mpr (NeZero.ne n)
51-
5250
variable {α : Type*} {n : ℕ} {f : α → ℕ}
5351

5452
/-- See also `pow_left_strictMonoOn`. -/

Mathlib/Algebra/Order/Invertible.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ Authors: Yury G. Kudryashov
55
-/
66
import Mathlib.Algebra.Order.Ring.Defs
77
import Mathlib.Algebra.Ring.Invertible
8-
import Mathlib.Data.Nat.Cast.Order
8+
import Mathlib.Data.Nat.Cast.Order.Ring
99

1010
#align_import algebra.order.invertible from "leanprover-community/mathlib"@"ee0c179cd3c8a45aa5bffbf1b41d8dbede452865"
1111

Mathlib/Algebra/Order/Nonneg/Ring.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Authors: Floris van Doorn
66
import Mathlib.Algebra.Order.Monoid.Unbundled.Pow
77
import Mathlib.Algebra.Order.Ring.Defs
88
import Mathlib.Algebra.Order.Ring.InjSurj
9-
import Mathlib.Data.Nat.Cast.Order
9+
import Mathlib.Data.Nat.Cast.Order.Ring
1010
import Mathlib.Order.CompleteLatticeIntervals
1111
import Mathlib.Order.LatticeIntervals
1212

Mathlib/Algebra/Order/Ring/Abs.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Authors: Jeremy Avigad, Leonardo de Moura, Mario Carneiro
66
import Mathlib.Algebra.Order.Ring.Basic
77
import Mathlib.Algebra.Order.Ring.Int
88
import Mathlib.Algebra.Ring.Divisibility.Basic
9-
import Mathlib.Data.Nat.Cast.Order
9+
import Mathlib.Data.Nat.Cast.Order.Ring
1010

1111
#align_import algebra.order.ring.abs from "leanprover-community/mathlib"@"10b4e499f43088dd3bb7b5796184ad5216648ab1"
1212
#align_import data.nat.parity from "leanprover-community/mathlib"@"48fb5b5280e7c81672afc9524185ae994553ebf4"

Mathlib/Algebra/Order/Ring/Cast.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Mario Carneiro
55
-/
66
import Mathlib.Algebra.Order.Ring.Int
7-
import Mathlib.Data.Nat.Cast.Order
7+
import Mathlib.Data.Nat.Cast.Order.Ring
88

99
#align_import data.int.cast.lemmas from "leanprover-community/mathlib"@"acebd8d49928f6ed8920e502a6c90674e75bd441"
1010

Mathlib/Algebra/Order/Ring/Pow.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Yury Kudryashov
55
-/
66
import Mathlib.Data.Nat.Cast.Commute
7-
import Mathlib.Data.Nat.Cast.Order
7+
import Mathlib.Data.Nat.Cast.Order.Ring
88

99
/-! # Bernoulli's inequality -/
1010

Mathlib/Data/Nat/Cast/Field.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
44
Authors: Mario Carneiro, Yaël Dillies, Patrick Stevens
55
-/
66
import Mathlib.Algebra.Order.Field.Basic
7-
import Mathlib.Data.Nat.Cast.Order
7+
import Mathlib.Data.Nat.Cast.Order.Basic
88
import Mathlib.Tactic.Common
99

1010
#align_import data.nat.cast.field from "leanprover-community/mathlib"@"acee671f47b8e7972a1eb6f4eed74b4b3abce829"

Mathlib/Data/Nat/Cast/NeZero.lean

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@ import Mathlib.Algebra.NeZero
1010
# Lemmas about nonzero elements of an `AddMonoidWithOne`
1111
-/
1212

13+
open Nat
14+
1315
namespace NeZero
1416

17+
theorem one_le {n : ℕ} [NeZero n] : 1 ≤ n := by have := NeZero.ne n; omega
18+
1519
lemma natCast_ne (n : ℕ) (R) [AddMonoidWithOne R] [h : NeZero (n : R)] : (n : R) ≠ 0 := h.out
1620
#align ne_zero.nat_cast_ne NeZero.natCast_ne
1721

Mathlib/Data/Nat/Cast/Order.lean renamed to Mathlib/Data/Nat/Cast/Order/Basic.lean

Lines changed: 6 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,10 @@ Authors: Mario Carneiro
55
-/
66
import Mathlib.Data.Nat.Cast.Basic
77
import Mathlib.Algebra.CharZero.Defs
8-
import Mathlib.Algebra.Order.Group.Abs
8+
import Mathlib.Algebra.Order.Monoid.Unbundled.Basic
99
import Mathlib.Data.Nat.Cast.NeZero
10-
import Mathlib.Algebra.Order.Ring.Nat
10+
import Mathlib.Algebra.Order.ZeroLEOne
11+
import Mathlib.Order.Hom.Basic
1112

1213
#align_import data.nat.cast.basic from "leanprover-community/mathlib"@"acebd8d49928f6ed8920e502a6c90674e75bd441"
1314

@@ -16,6 +17,8 @@ import Mathlib.Algebra.Order.Ring.Nat
1617
1718
-/
1819

20+
assert_not_exists OrderedCommMonoid
21+
1922
variable {α β : Type*}
2023

2124
namespace Nat
@@ -45,34 +48,11 @@ theorem _root_.GCongr.natCast_le_natCast {a b : ℕ} (h : a ≤ b) : (a : α)
4548
theorem cast_nonneg' (n : ℕ) : 0 ≤ (n : α) :=
4649
@Nat.cast_zero α _ ▸ mono_cast (Nat.zero_le n)
4750

48-
/-- Specialisation of `Nat.cast_nonneg'`, which seems to be easier for Lean to use. -/
49-
@[simp]
50-
theorem cast_nonneg {α} [OrderedSemiring α] (n : ℕ) : 0 ≤ (n : α) :=
51-
cast_nonneg' n
52-
#align nat.cast_nonneg Nat.cast_nonneg
53-
5451
/-- See also `Nat.ofNat_nonneg`, specialised for an `OrderedSemiring`. -/
5552
-- See note [no_index around OfNat.ofNat]
5653
@[simp low]
5754
theorem ofNat_nonneg' (n : ℕ) [n.AtLeastTwo] : 0 ≤ (no_index (OfNat.ofNat n : α)) := cast_nonneg' n
5855

59-
/-- Specialisation of `Nat.ofNat_nonneg'`, which seems to be easier for Lean to use. -/
60-
-- See note [no_index around OfNat.ofNat]
61-
@[simp]
62-
theorem ofNat_nonneg {α} [OrderedSemiring α] (n : ℕ) [n.AtLeastTwo] :
63-
0 ≤ (no_index (OfNat.ofNat n : α)) :=
64-
ofNat_nonneg' n
65-
66-
@[simp, norm_cast]
67-
theorem cast_min {α} [LinearOrderedSemiring α] {a b : ℕ} : ((min a b : ℕ) : α) = min (a : α) b :=
68-
(@mono_cast α _).map_min
69-
#align nat.cast_min Nat.cast_min
70-
71-
@[simp, norm_cast]
72-
theorem cast_max {α} [LinearOrderedSemiring α] {a b : ℕ} : ((max a b : ℕ) : α) = max (a : α) b :=
73-
(@mono_cast α _).map_max
74-
#align nat.cast_max Nat.cast_max
75-
7656
section Nontrivial
7757

7858
variable [NeZero (1 : α)]
@@ -87,24 +67,6 @@ theorem cast_add_one_pos (n : ℕ) : 0 < (n : α) + 1 := by
8767
@[simp low]
8868
theorem cast_pos' {n : ℕ} : (0 : α) < n ↔ 0 < n := by cases n <;> simp [cast_add_one_pos]
8969

90-
/-- Specialisation of `Nat.cast_pos'`, which seems to be easier for Lean to use. -/
91-
@[simp]
92-
theorem cast_pos {α} [OrderedSemiring α] [Nontrivial α] {n : ℕ} : (0 : α) < n ↔ 0 < n := cast_pos'
93-
#align nat.cast_pos Nat.cast_pos
94-
95-
/-- See also `Nat.ofNat_pos`, specialised for an `OrderedSemiring`. -/
96-
-- See note [no_index around OfNat.ofNat]
97-
@[simp low]
98-
theorem ofNat_pos' {n : ℕ} [n.AtLeastTwo] : 0 < (no_index (OfNat.ofNat n : α)) :=
99-
cast_pos'.mpr (NeZero.pos n)
100-
101-
/-- Specialisation of `Nat.ofNat_pos'`, which seems to be easier for Lean to use. -/
102-
-- See note [no_index around OfNat.ofNat]
103-
@[simp]
104-
theorem ofNat_pos {α} [OrderedSemiring α] [Nontrivial α] {n : ℕ} [n.AtLeastTwo] :
105-
0 < (no_index (OfNat.ofNat n : α)) :=
106-
ofNat_pos'
107-
10870
end Nontrivial
10971

11072
variable [CharZero α] {m n : ℕ}
@@ -140,7 +102,7 @@ theorem one_le_cast : 1 ≤ (n : α) ↔ 1 ≤ n := by rw [← cast_one, cast_le
140102

141103
@[simp, norm_cast]
142104
theorem cast_lt_one : (n : α) < 1 ↔ n = 0 := by
143-
rw [← cast_one, cast_lt, Nat.lt_succ_iff, ← bot_eq_zero, le_bot_iff]
105+
rw [← cast_one, cast_lt, Nat.lt_succ_iff, le_zero]
144106
#align nat.cast_lt_one Nat.cast_lt_one
145107

146108
@[simp, norm_cast]
@@ -149,7 +111,6 @@ theorem cast_le_one : (n : α) ≤ 1 ↔ n ≤ 1 := by rw [← cast_one, cast_le
149111

150112
variable [m.AtLeastTwo] [n.AtLeastTwo]
151113

152-
153114
-- TODO: These lemmas need to be `@[simp]` for confluence in the presence of `cast_lt`, `cast_le`,
154115
-- and `Nat.cast_ofNat`, but their LHSs match literally every inequality, so they're too expensive.
155116
-- If lean4#2867 is fixed in a performant way, these can be made `@[simp]`.
@@ -210,29 +171,6 @@ theorem not_ofNat_lt_one : ¬(no_index (OfNat.ofNat n : α)) < 1 :=
210171

211172
end OrderedSemiring
212173

213-
/-- A version of `Nat.cast_sub` that works for `ℝ≥0` and `ℚ≥0`. Note that this proof doesn't work
214-
for `ℕ∞` and `ℝ≥0∞`, so we use type-specific lemmas for these types. -/
215-
@[simp, norm_cast]
216-
theorem cast_tsub [CanonicallyOrderedCommSemiring α] [Sub α] [OrderedSub α]
217-
[ContravariantClass α α (· + ·) (· ≤ ·)] (m n : ℕ) : ↑(m - n) = (m - n : α) := by
218-
rcases le_total m n with h | h
219-
· rw [Nat.sub_eq_zero_of_le h, cast_zero, tsub_eq_zero_of_le]
220-
exact mono_cast h
221-
· rcases le_iff_exists_add'.mp h with ⟨m, rfl⟩
222-
rw [add_tsub_cancel_right, cast_add, add_tsub_cancel_right]
223-
#align nat.cast_tsub Nat.cast_tsub
224-
225-
@[simp, norm_cast]
226-
theorem abs_cast [LinearOrderedRing α] (a : ℕ) : |(a : α)| = a :=
227-
abs_of_nonneg (cast_nonneg a)
228-
#align nat.abs_cast Nat.abs_cast
229-
230-
-- See note [no_index around OfNat.ofNat]
231-
@[simp]
232-
theorem abs_ofNat [LinearOrderedRing α] (n : ℕ) [n.AtLeastTwo] :
233-
|(no_index (OfNat.ofNat n : α))| = OfNat.ofNat n :=
234-
abs_cast n
235-
236174
end Nat
237175

238176
instance [AddMonoidWithOne α] [CharZero α] : Nontrivial α where exists_pair_ne :=

0 commit comments

Comments
 (0)