-
Notifications
You must be signed in to change notification settings - Fork 447
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: model construction for offset constraints
This PR implements model construction for offset constraints in the `grind` tactic.
- Loading branch information
1 parent
d6f0c32
commit 1cae330
Showing
3 changed files
with
56 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/- | ||
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.Basic | ||
import Lean.Meta.Tactic.Grind.Types | ||
|
||
namespace Lean.Meta.Grind.Arith.Offset | ||
/-- Construct a model that statisfies all offset constraints -/ | ||
def mkModel (goal : Goal) : MetaM (Array (Expr × Nat)) := do | ||
let s := goal.arith.offset | ||
let nodes := s.nodes | ||
let mut pre : Array (Option Int) := mkArray nodes.size none | ||
for u in [:nodes.size] do | ||
let val? := s.sources[u]!.foldl (init := @none Int) fun val? v k => Id.run do | ||
let some va := pre[v]! | return val? | ||
let val' := va - k | ||
let some val := val? | return val' | ||
if val' > val then return val' else val? | ||
let val? := s.targets[u]!.foldl (init := val?) fun val? v k => Id.run do | ||
let some va := pre[v]! | return val? | ||
let val' := va + k | ||
let some val := val? | return val' | ||
if val' < val then return val' else val? | ||
let val := val?.getD 0 | ||
pre := pre.set! u (some val) | ||
let min := pre.foldl (init := 0) fun min val? => Id.run do | ||
let some val := val? | return min | ||
if val < min then val else min | ||
let mut r := {} | ||
for u in [:nodes.size] do | ||
let some val := pre[u]! | unreachable! | ||
let val := (val - min).toNat | ||
r := r.push (nodes[u]!, val) | ||
return r | ||
|
||
end Lean.Meta.Grind.Arith.Offset |
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