Skip to content

Commit 3578ec5

Browse files
committed
ordered rings
1 parent 12b8498 commit 3578ec5

File tree

11 files changed

+221
-115
lines changed

11 files changed

+221
-115
lines changed

src/Init/Grind.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ import Init.Grind.Offset
1616
import Init.Grind.PP
1717
import Init.Grind.CommRing
1818
import Init.Grind.Module
19+
import Init.Grind.Ordered
1920
import Init.Grind.Ext

src/Init/Grind/CommRing.lean

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,4 +14,3 @@ import Init.Grind.CommRing.Fin
1414
import Init.Grind.CommRing.BitVec
1515
import Init.Grind.CommRing.Poly
1616
import Init.Grind.CommRing.Field
17-
import Init.Grind.CommRing.Ordered

src/Init/Grind/CommRing/Basic.lean

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,12 @@ theorem ofNat_mul (a b : Nat) : OfNat.ofNat (α := α) (a * b) = OfNat.ofNat a *
104104
theorem natCast_mul (a b : Nat) : ((a * b : Nat) : α) = ((a : α) * (b : α)) := by
105105
rw [← ofNat_eq_natCast, ofNat_mul, ofNat_eq_natCast, ofNat_eq_natCast]
106106

107+
theorem pow_one (a : α) : a ^ 1 = a := by
108+
rw [pow_succ, pow_zero, one_mul]
109+
110+
theorem pow_two (a : α) : a ^ 2 = a * a := by
111+
rw [pow_succ, pow_one]
112+
107113
theorem pow_add (a : α) (k₁ k₂ : Nat) : a ^ (k₁ + k₂) = a^k₁ * a^k₂ := by
108114
induction k₂
109115
next => simp [pow_zero, mul_one]

src/Init/Grind/CommRing/Ordered.lean

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/Init/Grind/Module.lean

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,3 @@ module
77

88
prelude
99
import Init.Grind.Module.Basic
10-
import Init.Grind.Module.Int

src/Init/Grind/Module/Basic.lean

Lines changed: 0 additions & 85 deletions
Original file line numberDiff line numberDiff line change
@@ -103,91 +103,6 @@ theorem hmul_neg (n : Int) (a : M) : n * (-a) = - (n * a) := by
103103

104104
end IntModule
105105

106-
/-- A preorder is a reflexive, transitive relation `≤` with `a < b` defined in the obvious way. -/
107-
class Preorder (α : Type u) extends LE α, LT α where
108-
le_refl : ∀ a : α, a ≤ a
109-
le_trans : ∀ {a b c : α}, a ≤ b → b ≤ c → a ≤ c
110-
lt := fun a b => a ≤ b ∧ ¬b ≤ a
111-
lt_iff_le_not_le : ∀ {a b : α}, a < b ↔ a ≤ b ∧ ¬b ≤ a := by intros; rfl
112-
113-
namespace Preorder
114-
115-
variable {α : Type u} [Preorder α]
116-
117-
theorem le_of_lt {a b : α} (h : a < b) : a ≤ b := (lt_iff_le_not_le.mp h).1
118-
119-
theorem lt_of_lt_of_le {a b c : α} (h₁ : a < b) (h₂ : b ≤ c) : a < c := by
120-
simp [lt_iff_le_not_le] at h₁ ⊢
121-
exact ⟨le_trans h₁.1 h₂, fun h => h₁.2 (le_trans h₂ h)⟩
122-
123-
theorem lt_of_le_of_lt {a b c : α} (h₁ : a ≤ b) (h₂ : b < c) : a < c := by
124-
simp [lt_iff_le_not_le] at h₂ ⊢
125-
exact ⟨le_trans h₁ h₂.1, fun h => h₂.2 (le_trans h h₁)⟩
126-
127-
theorem lt_trans {a b c : α} (h₁ : a < b) (h₂ : b < c) : a < c :=
128-
lt_of_lt_of_le h₁ (le_of_lt h₂)
129-
130-
theorem lt_irrefl {a : α} (h : a < a) : False := by
131-
simp [lt_iff_le_not_le] at h
132-
133-
end Preorder
134-
135-
class IntModule.IsOrdered (M : Type u) [Preorder M] [IntModule M] where
136-
neg_le_iff : ∀ a b : M, -a ≤ b ↔ -b ≤ a
137-
add_le_left : ∀ {a b : M}, a ≤ b → (c : M) → a + c ≤ b + c
138-
hmul_pos : ∀ (k : Int) {a : M}, 0 < a → (0 < k ↔ 0 < k * a)
139-
hmul_nonneg : ∀ {k : Int} {a : M}, 0 ≤ k → 0 ≤ a → 0 ≤ k * a
140-
141-
namespace IntModule.IsOrdered
142-
143-
variable {M : Type u} [Preorder M] [IntModule M] [IntModule.IsOrdered M]
144-
145-
theorem le_neg_iff {a b : M} : a ≤ -b ↔ b ≤ -a := by
146-
conv => lhs; rw [← neg_neg a]
147-
rw [neg_le_iff, neg_neg]
148-
149-
theorem neg_lt_iff {a b : M} : -a < b ↔ -b < a := by
150-
simp [Preorder.lt_iff_le_not_le]
151-
rw [neg_le_iff, le_neg_iff]
152-
153-
theorem lt_neg_iff {a b : M} : a < -b ↔ b < -a := by
154-
conv => lhs; rw [← neg_neg a]
155-
rw [neg_lt_iff, neg_neg]
156-
157-
theorem neg_nonneg_iff {a : M} : 0 ≤ -a ↔ a ≤ 0 := by
158-
rw [le_neg_iff, neg_zero]
159-
160-
theorem neg_pos_iff {a : M} : 0 < -a ↔ a < 0 := by
161-
rw [lt_neg_iff, neg_zero]
162-
163-
theorem add_lt_left {a b : M} (h : a < b) (c : M) : a + c < b + c := by
164-
simp [Preorder.lt_iff_le_not_le] at h ⊢
165-
constructor
166-
· exact add_le_left h.1 _
167-
· intro w
168-
apply h.2
169-
replace w := add_le_left w (-c)
170-
rw [add_assoc, add_assoc, add_neg_cancel, add_zero, add_zero] at w
171-
exact w
172-
173-
theorem add_le_right (a : M) {b c : M} (h : b ≤ c) : a + b ≤ a + c := by
174-
rw [add_comm a b, add_comm a c]
175-
exact add_le_left h a
176-
177-
theorem add_lt_right (a : M) {b c : M} (h : b < c) : a + b < a + c := by
178-
rw [add_comm a b, add_comm a c]
179-
exact add_lt_left h a
180-
181-
theorem hmul_neg (k : Int) {a : M} (h : a < 0) : 0 < k ↔ k * a < 0 := by
182-
simpa [IntModule.hmul_neg, neg_pos_iff] using hmul_pos k (neg_pos_iff.mpr h)
183-
184-
theorem hmul_nonpos {k : Int} {a : M} (hk : 0 ≤ k) (ha : a ≤ 0) : k * a ≤ 0 := by
185-
simpa [IntModule.hmul_neg, neg_nonneg_iff] using hmul_nonneg hk (neg_nonneg_iff.mpr ha)
186-
187-
188-
189-
end IntModule.IsOrdered
190-
191106
/--
192107
Special case of Mathlib's `NoZeroSMulDivisors Nat α`.
193108
-/

src/Init/Grind/Ordered.lean

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
/-
2+
Copyright (c) 2025 Lean FRO, LLC. or its affiliates. All Rights Reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Kim Morrison
5+
-/
6+
module
7+
8+
prelude
9+
import Init.Grind.Ordered.PartialOrder
10+
import Init.Grind.Ordered.Module
11+
import Init.Grind.Ordered.Ring
12+
import Init.Grind.Ordered.Int
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ Authors: Kim Morrison
66
module
77

88
prelude
9-
import Init.Grind.Module.Basic
9+
import Init.Grind.Ordered.Ring
1010
import Init.Grind.CommRing.Int
1111
import Init.Omega
1212

@@ -27,4 +27,9 @@ instance : IntModule.IsOrdered Int where
2727
hmul_pos k a ha := ⟨fun hk => Int.mul_pos hk ha, fun h => Int.pos_of_mul_pos_left h ha⟩
2828
hmul_nonneg hk ha := Int.mul_nonneg hk ha
2929

30+
instance : Ring.IsOrdered Int where
31+
zero_lt_one := by omega
32+
mul_lt_mul_of_pos_left := Int.mul_lt_mul_of_pos_left
33+
mul_lt_mul_of_pos_right := Int.mul_lt_mul_of_pos_right
34+
3035
end Lean.Grind

src/Init/Grind/Ordered/Module.lean

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
/-
2+
Copyright (c) 2025 Lean FRO, LLC. or its affiliates. All Rights Reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Kim Morrison
5+
-/
6+
module
7+
8+
prelude
9+
import Init.Data.Int.Order
10+
import Init.Grind.Module.Basic
11+
import Init.Grind.Ordered.PartialOrder
12+
13+
namespace Lean.Grind
14+
15+
class IntModule.IsOrdered (M : Type u) [Preorder M] [IntModule M] where
16+
neg_le_iff : ∀ a b : M, -a ≤ b ↔ -b ≤ a
17+
add_le_left : ∀ {a b : M}, a ≤ b → (c : M) → a + c ≤ b + c
18+
hmul_pos : ∀ (k : Int) {a : M}, 0 < a → (0 < k ↔ 0 < k * a)
19+
hmul_nonneg : ∀ {k : Int} {a : M}, 0 ≤ k → 0 ≤ a → 0 ≤ k * a
20+
21+
namespace IntModule.IsOrdered
22+
23+
variable {M : Type u} [Preorder M] [IntModule M] [IntModule.IsOrdered M]
24+
25+
theorem le_neg_iff {a b : M} : a ≤ -b ↔ b ≤ -a := by
26+
conv => lhs; rw [← neg_neg a]
27+
rw [neg_le_iff, neg_neg]
28+
29+
theorem neg_lt_iff {a b : M} : -a < b ↔ -b < a := by
30+
simp [Preorder.lt_iff_le_not_le]
31+
rw [neg_le_iff, le_neg_iff]
32+
33+
theorem lt_neg_iff {a b : M} : a < -b ↔ b < -a := by
34+
conv => lhs; rw [← neg_neg a]
35+
rw [neg_lt_iff, neg_neg]
36+
37+
theorem neg_nonneg_iff {a : M} : 0 ≤ -a ↔ a ≤ 0 := by
38+
rw [le_neg_iff, neg_zero]
39+
40+
theorem neg_pos_iff {a : M} : 0 < -a ↔ a < 0 := by
41+
rw [lt_neg_iff, neg_zero]
42+
43+
theorem add_lt_left {a b : M} (h : a < b) (c : M) : a + c < b + c := by
44+
simp [Preorder.lt_iff_le_not_le] at h ⊢
45+
constructor
46+
· exact add_le_left h.1 _
47+
· intro w
48+
apply h.2
49+
replace w := add_le_left w (-c)
50+
rw [add_assoc, add_assoc, add_neg_cancel, add_zero, add_zero] at w
51+
exact w
52+
53+
theorem add_le_right (a : M) {b c : M} (h : b ≤ c) : a + b ≤ a + c := by
54+
rw [add_comm a b, add_comm a c]
55+
exact add_le_left h a
56+
57+
theorem add_lt_right (a : M) {b c : M} (h : b < c) : a + b < a + c := by
58+
rw [add_comm a b, add_comm a c]
59+
exact add_lt_left h a
60+
61+
theorem hmul_neg (k : Int) {a : M} (h : a < 0) : 0 < k ↔ k * a < 0 := by
62+
simpa [IntModule.hmul_neg, neg_pos_iff] using hmul_pos k (neg_pos_iff.mpr h)
63+
64+
theorem hmul_nonpos {k : Int} {a : M} (hk : 0 ≤ k) (ha : a ≤ 0) : k * a ≤ 0 := by
65+
simpa [IntModule.hmul_neg, neg_nonneg_iff] using hmul_nonneg hk (neg_nonneg_iff.mpr ha)
66+
67+
end IntModule.IsOrdered
68+
69+
end Lean.Grind
Lines changed: 61 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/-
2+
Copyright (c) 2025 Lean FRO, LLC. or its affiliates. All Rights Reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Authors: Kim Morrison
5+
-/
6+
module
7+
8+
prelude
9+
import Init.Data.Int.Order
10+
11+
namespace Lean.Grind
12+
13+
/-- A preorder is a reflexive, transitive relation `≤` with `a < b` defined in the obvious way. -/
14+
class Preorder (α : Type u) extends LE α, LT α where
15+
le_refl : ∀ a : α, a ≤ a
16+
le_trans : ∀ {a b c : α}, a ≤ b → b ≤ c → a ≤ c
17+
lt := fun a b => a ≤ b ∧ ¬b ≤ a
18+
lt_iff_le_not_le : ∀ {a b : α}, a < b ↔ a ≤ b ∧ ¬b ≤ a := by intros; rfl
19+
20+
namespace Preorder
21+
22+
variable {α : Type u} [Preorder α]
23+
24+
theorem le_of_lt {a b : α} (h : a < b) : a ≤ b := (lt_iff_le_not_le.mp h).1
25+
26+
theorem lt_of_lt_of_le {a b c : α} (h₁ : a < b) (h₂ : b ≤ c) : a < c := by
27+
simp [lt_iff_le_not_le] at h₁ ⊢
28+
exact ⟨le_trans h₁.1 h₂, fun h => h₁.2 (le_trans h₂ h)⟩
29+
30+
theorem lt_of_le_of_lt {a b c : α} (h₁ : a ≤ b) (h₂ : b < c) : a < c := by
31+
simp [lt_iff_le_not_le] at h₂ ⊢
32+
exact ⟨le_trans h₁ h₂.1, fun h => h₂.2 (le_trans h h₁)⟩
33+
34+
theorem lt_trans {a b c : α} (h₁ : a < b) (h₂ : b < c) : a < c :=
35+
lt_of_lt_of_le h₁ (le_of_lt h₂)
36+
37+
theorem lt_irrefl {a : α} (h : a < a) : False := by
38+
simp [lt_iff_le_not_le] at h
39+
40+
end Preorder
41+
42+
class PartialOrder (α : Type u) extends Preorder α where
43+
le_antisymm : ∀ {a b : α}, a ≤ b → b ≤ a → a = b
44+
45+
namespace PartialOrder
46+
47+
variable {α : Type u} [PartialOrder α]
48+
49+
theorem le_iff_lt_or_eq {a b : α} : a ≤ b ↔ a < b ∨ a = b := by
50+
constructor
51+
· intro h
52+
rw [Preorder.lt_iff_le_not_le, Classical.or_iff_not_imp_right]
53+
exact fun w => ⟨h, fun w' => w (le_antisymm h w')⟩
54+
· intro h
55+
cases h with
56+
| inl h => exact Preorder.le_of_lt h
57+
| inr h => subst h; exact Preorder.le_refl a
58+
59+
end PartialOrder
60+
61+
end Lean.Grind

0 commit comments

Comments
 (0)