Skip to content

Commit 677e803

Browse files
committed
refactor: remove CnstrKind.eq
1 parent 49a2cc2 commit 677e803

File tree

5 files changed

+17
-31
lines changed

5 files changed

+17
-31
lines changed

src/Lean/Meta/Tactic/Grind/Order/Assert.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ If it can, adds a new entry to propagation list.
118118
-/
119119
def checkEqTrue (u v : NodeId) (k : Weight) (c : Cnstr NodeId) (e : Expr) : OrderM Bool := do
120120
if (← alreadyInternalized e <&&> isEqTrue e) then return true
121-
let some k' := c.getWeight? | return false
121+
let k' := c.getWeight
122122
trace[grind.debug.order.check_eq_true] "{← getExpr u}, {← getExpr v}, {k}, {k'}, {← c.pp}"
123123
if k ≤ k' then
124124
pushToPropagate <| .eqTrue c e u v k k'
@@ -133,7 +133,7 @@ If it can, adds a new entry to propagation list.
133133
-/
134134
def checkEqFalse (u v : NodeId) (k : Weight) (c : Cnstr NodeId) (e : Expr) : OrderM Bool := do
135135
if (← alreadyInternalized e <&&> isEqFalse e) then return true
136-
let some k' := c.getWeight? | return false
136+
let k' := c.getWeight
137137
trace[grind.debug.order.check_eq_false] "{← getExpr u}, {← getExpr v}, {k}, {k'} {← c.pp}"
138138
if (k + k').isNeg then
139139
pushToPropagate <| .eqFalse c e u v k k'

src/Lean/Meta/Tactic/Grind/Order/Internalize.lean

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,6 @@ def mkExpectedHint (s : Struct) (e : Expr) (kind : CnstrKind) (lhs rhs : Expr) (
6969
let rel := match kind with
7070
| .le => s.leFn
7171
| .lt => s.ltFn?.get!
72-
| .eq => mkApp (mkConst ``Eq [mkLevelSucc s.u]) s.type
7372
let e' := mkApp2 rel lhs rhs
7473
let prop := mkApp2 propEq e e'
7574
let h' := mkExpectedPropHint h prop
@@ -88,7 +87,6 @@ def mkCnstrNorm0 (s : Struct) (ringInst : Expr) (kind : CnstrKind) (lhs rhs : Ex
8887
match kind with
8988
| .le => mkLeNorm0 s ringInst lhs rhs
9089
| .lt => mkLtNorm0 s ringInst lhs rhs
91-
| .eq => mkEqNorm0 s ringInst lhs rhs
9290

9391
/--
9492
Returns `rel lhs (rhs + 0)`
@@ -98,7 +96,6 @@ def mkDenote0 [MonadLiftT MetaM m] [MonadError m] [Monad m] [MonadCanon m] [Mona
9896
let rel := match kind with
9997
| .le => s.leFn
10098
| .lt => s.ltFn?.get!
101-
| .eq => mkApp (mkConst ``Eq [mkLevelSucc s.u]) s.type
10299
let rhs' := mkApp2 (← getAddFn) rhs (mkApp (← getIntCastFn) (mkIntLit 0))
103100
return mkApp2 rel lhs rhs'
104101

@@ -118,7 +115,6 @@ def mkCommRingCnstr? (e : Expr) (s : Struct) (kind : CnstrKind) (lhs rhs : Expr)
118115
let h ← match kind with
119116
| .le => mkLeIffProof s.leInst s.ltInst?.get! s.isPreorderInst s.orderedRingInst?.get! lhs rhs lhs' rhs'
120117
| .lt => mkLtIffProof s.leInst s.ltInst?.get! s.lawfulOrderLTInst?.get! s.isPreorderInst s.orderedRingInst?.get! lhs rhs lhs' rhs'
121-
| .eq => mkEqIffProof lhs rhs lhs' rhs'
122118
let (e', h') := mkExpectedHint s e kind u (← rhs'.denoteExpr) h
123119
return some {
124120
kind, u, v, k, e := e', h? := some h'
@@ -141,7 +137,6 @@ def mkNonCommRingCnstr? (e : Expr) (s : Struct) (kind : CnstrKind) (lhs rhs : Ex
141137
let h ← match kind with
142138
| .le => mkNonCommLeIffProof s.leInst s.ltInst?.get! s.isPreorderInst s.orderedRingInst?.get! lhs rhs lhs' rhs'
143139
| .lt => mkNonCommLtIffProof s.leInst s.ltInst?.get! s.lawfulOrderLTInst?.get! s.isPreorderInst s.orderedRingInst?.get! lhs rhs lhs' rhs'
144-
| .eq => mkNonCommEqIffProof lhs rhs lhs' rhs'
145140
let (e', h') := mkExpectedHint s e kind u (← rhs'.denoteExpr) h
146141
return some {
147142
kind, u, v, k, e := e', h? := some h'
@@ -192,15 +187,15 @@ def internalizeCnstr (e : Expr) (kind : CnstrKind) (lhs rhs : Expr) : OrderM Uni
192187
let u ← mkNode c.u
193188
let v ← mkNode c.v
194189
let c := { c with u, v }
195-
if let some k' := c.getWeight? then
196-
if let some k ← getDist? u v then
197-
if k ≤ k' then
198-
propagateEqTrue c e u v k k'
199-
return ()
200-
if let some k ← getDist? v u then
201-
if (k + k').isNeg then
202-
propagateEqFalse c e v u k k'
203-
return ()
190+
let k' := c.getWeight
191+
if let some k ← getDist? u v then
192+
if k ≤ k' then
193+
propagateEqTrue c e u v k k'
194+
return ()
195+
if let some k ← getDist? v u then
196+
if (k + k').isNeg then
197+
propagateEqFalse c e v u k k'
198+
return ()
204199
setStructId e
205200
modifyStruct fun s => { s with
206201
cnstrs := s.cnstrs.insert { expr := e } c
@@ -224,12 +219,6 @@ def adaptNat (e : Expr) : GoalM Expr := do
224219
let eNew := mkIntLT lhs' rhs'
225220
let h := mkApp6 (mkConst ``Nat.ToInt.lt_eq) lhs rhs lhs' rhs' h₁ h₂
226221
pure (eNew, h)
227-
| Eq _ lhs rhs =>
228-
let (lhs', h₁) ← natToInt lhs
229-
let (rhs', h₂) ← natToInt rhs
230-
let eNew := mkIntEq lhs' rhs'
231-
let h := mkApp6 (mkConst ``Nat.ToInt.eq_eq) lhs rhs lhs' rhs' h₁ h₂
232-
pure (eNew, h)
233222
| _ => return e
234223
modify' fun s => { s with
235224
cnstrsMap := s.cnstrsMap.insert { expr := e } (eNew, h)
@@ -259,7 +248,6 @@ public def internalize (e : Expr) (parent? : Option Expr) : GoalM Unit := do
259248
match_expr e with
260249
| LE.le _ _ lhs rhs => internalizeCnstr e .le lhs rhs
261250
| LT.lt _ _ lhs rhs => if (← hasLt) then internalizeCnstr e .lt lhs rhs
262-
| Eq _ lhs rhs => internalizeCnstr e .eq lhs rhs
263251
| _ =>
264252
-- **Note**: We currently do not internalize offset terms nested in other terms.
265253
return ()

src/Lean/Meta/Tactic/Grind/Order/Types.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ Solver for preorders, partial orders, linear orders, and support for offsets.
1717
abbrev NodeId := Nat
1818

1919
inductive CnstrKind where
20-
| le | lt | eq
20+
| le | lt
2121
deriving Inhabited
2222

2323
/--

src/Lean/Meta/Tactic/Grind/Order/Util.lean

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ def Cnstr.pp (c : Cnstr NodeId) : OrderM MessageData := do
1616
let op := match c.kind with
1717
| .le => "≤"
1818
| .lt => "<"
19-
| .eq => "="
2019
if c.k != 0 then
2120
return m!"{Arith.quoteIfArithTerm u} {op} {Arith.quoteIfArithTerm v} + {c.k}"
2221
else
@@ -76,10 +75,9 @@ def ToPropagate.pp (todo : ToPropagate) : OrderM MessageData := do
7675
| .eqFalse _ e u v k k' => return m!"eqFalse: {e}, {← getExpr u}, {← getExpr v}, {k}, {k'}"
7776
| .eq u v => return m!"eq: {← getExpr u}, {← getExpr v}"
7877

79-
def Cnstr.getWeight? (c : Cnstr α) : Option Weight :=
78+
def Cnstr.getWeight (c : Cnstr α) : Weight :=
8079
match c.kind with
81-
| .le => some { k := c.k }
82-
| .lt => some { k := c.k, strict := true }
83-
| .eq => none
80+
| .le => { k := c.k }
81+
| .lt => { k := c.k, strict := true }
8482

8583
end Lean.Meta.Grind.Order

tests/lean/run/grind_order_3.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,10 +49,10 @@ example [LE α] [Std.IsLinearPreorder α]
4949
(a b c d e : α) : a ≥ b → d = c → c = b → d ≥ e → a ≥ e := by
5050
grind -linarith (splits := 0)
5151

52-
example [LE α] [LT α] [Std.LawfulOrderLT α] [Std.IsLinearPreorder α] [CommRing α] [OrderedRing α]
52+
example [LE α] [LT α] [Std.LawfulOrderLT α] [Std.IsPreorder α] [CommRing α] [OrderedRing α]
5353
(a b c d e : α) : a ≥ b → d = c → c = b → d ≥ e → a ≥ e := by
5454
grind -linarith (splits := 0)
5555

56-
example [LE α] [LT α] [Std.LawfulOrderLT α] [Std.IsLinearPreorder α] [CommRing α] [OrderedRing α]
56+
example [LE α] [LT α] [Std.LawfulOrderLT α] [Std.IsPreorder α] [CommRing α] [OrderedRing α]
5757
(a b c d e : α) : a + 2 ≥ b → d = c → c = b → d + 1 ≥ e → a + 3 ≥ e := by
5858
grind -linarith (splits := 0)

0 commit comments

Comments
 (0)