Skip to content

Commit b73b8a7

Browse files
authored
feat: helper ordered ring theorems (#10529)
This PR adds some helper theorems for the upcoming `grind order` solver.
1 parent 94e5b66 commit b73b8a7

File tree

1 file changed

+80
-0
lines changed

1 file changed

+80
-0
lines changed

src/Init/Grind/Ordered/Ring.lean

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,86 @@ theorem ofNat_nonneg (x : Nat) : (OfNat.ofNat x : R) ≥ 0 := by
5353
have := Preorder.lt_of_lt_of_le this ih
5454
exact Preorder.le_of_lt this
5555

56+
attribute [local instance] Semiring.natCast Ring.intCast
57+
58+
theorem le_of_natCast_le_natCast (a b : Nat) : (a : R) ≤ (b : R) → a ≤ b := by
59+
induction a generalizing b <;> cases b <;> simp
60+
next n ih =>
61+
simp [Semiring.natCast_succ, Semiring.natCast_zero]
62+
intro h
63+
have : (n:R) ≤ 0 := by
64+
have := OrderedRing.zero_lt_one (R := R)
65+
replace this := OrderedAdd.add_le_right (M := R) (n:R) (Std.le_of_lt this)
66+
rw [Semiring.add_zero] at this
67+
exact Std.IsPreorder.le_trans _ _ _ this h
68+
replace ih := ih 0
69+
simp [Semiring.natCast_zero] at ih
70+
replace ih := ih this
71+
subst n
72+
clear this
73+
have := OrderedRing.zero_lt_one (R := R)
74+
rw [Semiring.natCast_zero, Semiring.add_comm, Semiring.add_zero] at h
75+
replace this := Std.lt_of_lt_of_le this h
76+
have := Preorder.lt_irrefl (0:R)
77+
contradiction
78+
next ih m =>
79+
simp [Semiring.natCast_succ]
80+
intro h
81+
have := OrderedAdd.add_le_left_iff _ |>.mpr h
82+
exact ih _ this
83+
84+
theorem le_of_intCast_le_intCast (a b : Int) : (a : R) ≤ (b : R) → a ≤ b := by
85+
intro h
86+
replace h := OrderedAdd.sub_nonneg_iff.mpr h
87+
rw [← Ring.intCast_sub] at h
88+
suffices 0 ≤ b - a by omega
89+
revert h
90+
generalize b - a = x
91+
cases x <;> simp [Ring.intCast_natCast, Int.negSucc_eq, Ring.intCast_neg, Ring.intCast_add]
92+
intro h
93+
replace h := OrderedAdd.neg_nonneg_iff.mp h
94+
rw [Ring.intCast_one, ← Semiring.natCast_one, ← Semiring.natCast_add, ← Semiring.natCast_zero] at h
95+
replace h := le_of_natCast_le_natCast _ _ h
96+
omega
97+
98+
theorem lt_of_natCast_lt_natCast (a b : Nat) : (a : R) < (b : R) → a < b := by
99+
induction a generalizing b <;> cases b <;> simp
100+
next =>
101+
simp [Semiring.natCast_zero]
102+
exact Preorder.lt_irrefl (0:R)
103+
next n ih =>
104+
simp [Semiring.natCast_succ, Semiring.natCast_zero]
105+
intro h
106+
have : (n:R) < 0 := by
107+
have := OrderedRing.zero_lt_one (R := R)
108+
replace this := OrderedAdd.add_le_right (M := R) (n:R) (Std.le_of_lt this)
109+
rw [Semiring.add_zero] at this
110+
exact Std.lt_of_le_of_lt this h
111+
replace ih := ih 0
112+
simp [Semiring.natCast_zero] at ih
113+
exact ih this
114+
next ih m =>
115+
simp [Semiring.natCast_succ]
116+
intro h
117+
have := OrderedAdd.add_lt_left_iff _ |>.mpr h
118+
exact ih _ this
119+
120+
theorem lt_of_intCast_lt_intCast (a b : Int) : (a : R) < (b : R) → a < b := by
121+
intro h
122+
replace h := OrderedAdd.sub_pos_iff.mpr h
123+
rw [← Ring.intCast_sub] at h
124+
suffices 0 < b - a by omega
125+
revert h
126+
generalize b - a = x
127+
cases x <;> simp [Ring.intCast_natCast, Int.negSucc_eq, Ring.intCast_neg, Ring.intCast_add]
128+
next => intro h; rw [← Semiring.natCast_zero] at h; exact lt_of_natCast_lt_natCast _ _ h
129+
next =>
130+
intro h
131+
replace h := OrderedAdd.neg_pos_iff.mp h
132+
rw [Ring.intCast_one, ← Semiring.natCast_one, ← Semiring.natCast_add, ← Semiring.natCast_zero] at h
133+
replace h := lt_of_natCast_lt_natCast _ _ h
134+
omega
135+
56136
instance [Ring R] [LE R] [LT R] [LawfulOrderLT R] [IsPreorder R] [OrderedRing R] :
57137
IsCharP R 0 := IsCharP.mk' _ _ <| by
58138
intro x

0 commit comments

Comments
 (0)