-
Notifications
You must be signed in to change notification settings - Fork 449
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: offset constraints support for the
grind
tactic (#6603)
This PR implements support for offset constraints in the `grind` tactic. Several features are still missing, such as constraint propagation and support for offset equalities, but `grind` can already solve examples like the following: ```lean example (a b c : Nat) : a ≤ b → b + 2 ≤ c → a + 1 ≤ c := by grind example (a b c : Nat) : a ≤ b → b ≤ c → a ≤ c := by grind example (a b c : Nat) : a + 1 ≤ b → b + 1 ≤ c → a + 2 ≤ c := by grind example (a b c : Nat) : a + 1 ≤ b → b + 1 ≤ c → a + 1 ≤ c := by grind example (a b c : Nat) : a + 1 ≤ b → b ≤ c + 2 → a ≤ c + 1 := by grind example (a b c : Nat) : a + 2 ≤ b → b ≤ c + 2 → a ≤ c := by grind ``` --------- Co-authored-by: Kim Morrison <scott.morrison@gmail.com>
- Loading branch information
1 parent
0da3624
commit c7939cf
Showing
19 changed files
with
859 additions
and
212 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
/- | ||
Copyright (c) 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Leonardo de Moura | ||
-/ | ||
prelude | ||
import Lean.Meta.Tactic.Grind.Arith.Util | ||
import Lean.Meta.Tactic.Grind.Arith.Types | ||
import Lean.Meta.Tactic.Grind.Arith.Offset | ||
import Lean.Meta.Tactic.Grind.Arith.Main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
/- | ||
Copyright (c) 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Leonardo de Moura | ||
-/ | ||
prelude | ||
import Lean.Meta.Tactic.Grind.Arith.Offset | ||
|
||
namespace Lean.Meta.Grind.Arith | ||
|
||
namespace Offset | ||
|
||
def internalizeTerm (_e : Expr) (_a : Expr) (_k : Nat) : GoalM Unit := do | ||
-- TODO | ||
return () | ||
|
||
def internalizeCnstr (e : Expr) : GoalM Unit := do | ||
let some c := isNatOffsetCnstr? e | return () | ||
let c := { c with | ||
a := (← mkNode c.a) | ||
b := (← mkNode c.b) | ||
} | ||
trace[grind.offset.internalize] "{e} ↦ {c}" | ||
modify' fun s => { s with | ||
cnstrs := s.cnstrs.insert { expr := e } c | ||
} | ||
|
||
end Offset | ||
|
||
def internalize (e : Expr) : GoalM Unit := do | ||
Offset.internalizeCnstr e | ||
|
||
end Lean.Meta.Grind.Arith |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
/- | ||
Copyright (c) 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Leonardo de Moura | ||
-/ | ||
prelude | ||
import Lean.Meta.Tactic.Grind.Arith.Offset | ||
|
||
namespace Lean.Meta.Grind.Arith | ||
|
||
def checkInvariants : GoalM Unit := | ||
Offset.checkInvariants | ||
|
||
end Lean.Meta.Grind.Arith |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/- | ||
Copyright (c) 2025 Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
Released under Apache 2.0 license as described in the file LICENSE. | ||
Authors: Leonardo de Moura | ||
-/ | ||
prelude | ||
import Lean.Meta.Tactic.Grind.PropagatorAttr | ||
import Lean.Meta.Tactic.Grind.Arith.Offset | ||
|
||
namespace Lean.Meta.Grind.Arith | ||
|
||
namespace Offset | ||
def isCnstr? (e : Expr) : GoalM (Option (Cnstr NodeId)) := | ||
return (← get).arith.offset.cnstrs.find? { expr := e } | ||
|
||
def assertTrue (c : Cnstr NodeId) (p : Expr) : GoalM Unit := do | ||
addEdge c.a c.b c.k (← mkOfEqTrue p) | ||
|
||
def assertFalse (c : Cnstr NodeId) (p : Expr) : GoalM Unit := do | ||
let p := mkOfNegEqFalse (← get').nodes c p | ||
let c := c.neg | ||
addEdge c.a c.b c.k p | ||
|
||
end Offset | ||
|
||
builtin_grind_propagator propagateLE ↓LE.le := fun e => do | ||
if (← isEqTrue e) then | ||
if let some c ← Offset.isCnstr? e then | ||
Offset.assertTrue c (← mkEqTrueProof e) | ||
if (← isEqFalse e) then | ||
if let some c ← Offset.isCnstr? e then | ||
Offset.assertFalse c (← mkEqFalseProof e) | ||
|
||
end Lean.Meta.Grind.Arith |
Oops, something went wrong.