File tree Expand file tree Collapse file tree 3 files changed +22
-9
lines changed
src/Lean/Meta/Tactic/Grind/Arith/Cutsat Expand file tree Collapse file tree 3 files changed +22
-9
lines changed Original file line number Diff line number Diff line change @@ -13,6 +13,7 @@ import Lean.Meta.Tactic.Grind.Arith.Cutsat.Util
1313import Lean.Meta.Tactic.Grind.Arith.Cutsat.Var
1414import Lean.Meta.Tactic.Grind.Arith.CommRing.Reify
1515import Lean.Meta.Tactic.Grind.Arith.CommRing.DenoteExpr
16+ import Lean.Meta.Tactic.Grind.Arith.CommRing.SafePoly
1617public section
1718namespace Lean.Meta.Grind.Arith.Cutsat
1819/-!
@@ -22,7 +23,7 @@ CommRing interface for cutsat. We use it to normalize nonlinear polynomials.
2223/-- Returns `true` if `p` contains a nonlinear monomial. -/
2324def _root_.Int.Linear.Poly.isNonlinear (p : Poly) : GoalM Bool := do
2425 let .add _ x p := p | return false
25- if (← getVar x).isAppOf ``HMul.hMul then return true
26+ if (← getVar x).isAppOf ``HMul.hMul || (← getVar x).isAppOf ``HPow.hPow then return true
2627 p.isNonlinear
2728
2829def _root_.Int.Linear.Poly.getGeneration (p : Poly) : GoalM Nat := do
@@ -46,7 +47,7 @@ def _root_.Int.Linear.Poly.normCommRing? (p : Poly) : GoalM (Option (CommRing.Ri
4647 let e ← shareCommon (← canon e)
4748 let gen ← p.getGeneration
4849 let some re ← CommRing.reify? e (gen := gen) | return none
49- let p' := re.toPoly
50+ let some p' ← re.toPolyM? | return none
5051 let e' ← p'.denoteExpr
5152 let e' ← preprocessLight e'
5253 -- Remark: we are reusing the `IntModule` virtual parent.
Original file line number Diff line number Diff line change @@ -386,13 +386,6 @@ private def exprAsPoly (a : Expr) : GoalM Poly := do
386386 else
387387 throwError "internal `grind` error, expression is not relevant to cutsat{indentExpr a}"
388388
389- private def processNewIntEq (a b : Expr) : GoalM Unit := do
390- let p₁ ← exprAsPoly a
391- let p₂ ← exprAsPoly b
392- -- Remark: we don't need to use the comm ring normalizer here because `p` is always linear.
393- let p := p₁.combine (p₂.mul (-1 ))
394- { p, h := .core a b p₁ p₂ : EqCnstr }.assert
395-
396389/-- Asserts a constraint coming from the core. -/
397390private def EqCnstr.assertCore (c : EqCnstr) : GoalM Unit := do
398391 if let some (re, rp, p) ← c.p.normCommRing? then
@@ -401,6 +394,14 @@ private def EqCnstr.assertCore (c : EqCnstr) : GoalM Unit := do
401394 else
402395 c.assert
403396
397+ private def processNewIntEq (a b : Expr) : GoalM Unit := do
398+ let p₁ ← exprAsPoly a
399+ let p₂ ← exprAsPoly b
400+ -- Remark: we don't need to use the comm ring normalizer here because `p` is always linear.
401+ let p := p₁.combine (p₂.mul (-1 ))
402+ let c := { p, h := .core a b p₁ p₂ : EqCnstr }
403+ c.assertCore
404+
404405/--
405406Similar to `natToInt`, but checks first whether the term has already been internalized.
406407-/
Original file line number Diff line number Diff line change 1+ example {n a b : Nat}
2+ (this : (b : Int) ^ (n + 1 ) + ↑(n + 1 ) * ↑b ^ (n + 1 - 1 ) * (↑a - ↑b) ≤
3+ (↑b + (↑a - ↑b)) ^ (n + 1 )) :
4+ (n + 1 ) * a * b ^ n ≤ a ^ (n + 1 ) + n * b * b ^ n := by
5+ grind (splits := 0 )
6+
7+ example {n a b : Nat}
8+ (this : (b : Int) ^ (n + 1 ) + ↑(n + 1 ) * ↑b ^ (n + 1 - 1 ) * (↑a - ↑b) ≤
9+ (↑b + (↑a - ↑b)) ^ (n + 1 )) :
10+ (n + 1 ) * a * b ^ n ≤ a ^ (n + 1 ) + n * b * b ^ n := by
11+ grind
You can’t perform that action at this time.
0 commit comments