Skip to content

Commit c7ac99b

Browse files
committed
Bump Lean version to v4.24.0.
1 parent d6c048b commit c7ac99b

30 files changed

Lines changed: 160 additions & 575 deletions

Smt/Dsl/Sexp.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def generalIdent : Parser :=
2121
fn := fun c s =>
2222
let startPos := s.pos
2323
let s := takeWhile1Fn (fun c => !("(){}[].".contains c) ∧ !c.isWhitespace) "expected generalized identifier" c s
24-
mkNodeToken `generalIdent startPos c s }
24+
mkNodeToken `generalIdent startPos true c s }
2525

2626
def Lean.TSyntax.getGeneralId : TSyntax `generalIdent → String
2727
| ⟨.node _ `generalIdent args⟩ => args[0]!.getAtomVal

Smt/Preprocess/BoolAsProp.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ theorem Bool.eq_eq_true (x y : Bool) : (x = y : Bool) = ((x : Prop) = (y : Prop)
1313
simp only [decide_eq_true_eq, _root_.eq_iff_iff, coe_iff_coe]
1414

1515
theorem Bool.eq_self (x : Bool): (x = x) = (True : Prop) := by
16-
simp only [eq_self]
16+
simp only
1717

1818
theorem Prop.eq_true (x : Prop) : (x = True : Prop) = (x : Prop) := by
1919
simp only [eq_iff_iff, iff_true]

Smt/Preprocess/Embedding.lean

Lines changed: 12 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,11 @@
11
import Lean
2-
import Smt
3-
import Smt.Real
4-
import Lean.Meta.Tactic.Congr
52

3+
import Smt.Preprocess.Basic
64
import Smt.Preprocess.BoolAsProp
75
import Smt.Preprocess.NatAsInt
86
import Smt.Preprocess.RatAsReal
97

10-
namespace Smt.Preprocess.SmtTranslate
8+
namespace Smt.Preprocess
119

1210
open Lean Meta
1311

@@ -334,7 +332,7 @@ def addNonNegToHypotheses (mv : MVarId) (sortedNatDomainVars : Array Expr) : Met
334332
`Int.toNat_of_nonneg` normalization, generalize away Bool/Rat/Nat locals,
335333
then re-introduce hypotheses and clear the original variables.
336334
-/
337-
def smt_translate (mv' : MVarId) : MetaM MVarId := withTraceNode `smt.reconstruct.smt_translate traceSmtTranslate do
335+
def smtTranslateCore (mv' : MVarId) : MetaM MVarId := withTraceNode `smt.reconstruct.smtTranslate traceSmtTranslate do
338336
trace[debug] m!"initial goal: {mv'}"
339337

340338
let mut mv := mv'
@@ -397,7 +395,7 @@ def smt_translate (mv' : MVarId) : MetaM MVarId := withTraceNode `smt.reconstruc
397395
-- For each `x : Rat`, assert a witness equation `x = a / b` with `a b : Int`
398396
for ratVar in sortedRatVars do
399397
let varName ← ratVar.fvarId!.getUserName
400-
let divProof ← mkAppOptM ``Rat.cast_eq_div_int #[ratVar]
398+
let divProof ← mkAppOptM `Rat.cast_eq_div_int #[ratVar]
401399
let divType ← inferType divProof
402400
mv ← mv.assert (varName.appendAfter "_rat") divType divProof
403401
let (fVarId, mv') ← mv.intro (varName.appendAfter "_rat")
@@ -669,7 +667,7 @@ def smt_translate (mv' : MVarId) : MetaM MVarId := withTraceNode `smt.reconstruc
669667
let ns := [
670668
``Bool.and_eq_true, ``Bool.or_eq_true, ``Bool.not_eq_true2, ``Bool.iff_eq_true, ``Bool.xor_eq_true, ``Bool.eq_eq_true, ``Bool.eq_self, ``Bool.true_eq_false, ``Bool.false_eq_true, ``Prop.eq_true, ``Prop.eq_false,
671669

672-
``Int.natCast_add, ``Int.natCast_sub2, ``Int.natCast_mul, ``Int.natCast_ediv, ``Int.natCast_emod, ``Int.ofNat_eq, ``Int.ofNat_le2, ``Int.ofNat_lt2, ``Int.ofNat_ge, ``Int.ofNat_gt, ``Int.ofNat_ne, ``Nat.cast_zero, ``Nat.cast_one, ``Nat.cast_ofNat, ``Int.natSub.eq_1, ``Int.toNat_of_nonneg, ``Int.ofNat_eq_coe,
670+
``Int.natCast_add, ``Int.natCast_sub2, ``Int.natCast_mul, ``Int.natCast_ediv, ``Int.natCast_emod, ``Int.ofNat_eq, ``Int.ofNat_le2, ``Int.ofNat_lt2, ``Int.ofNat_ge, ``Int.ofNat_gt, ``Int.ofNat_ne, ``Int.natSub.eq_1, ``Int.toNat_of_nonneg, ``Int.ofNat_eq_coe, ``Int.cast_ofNat_Int,
673671

674672
``Rat.cast_add, ``Rat.cast_sub, ``Rat.cast_mul, ``Rat.cast_div, ``Rat.cast_neg, ``Rat.cast_inv, ``Rat.cast_eq, ``Rat.cast_le, ``Rat.cast_lt, ``Rat.cast_ge, ``Rat.cast_gt, ``Rat.cast_ne, ``Rat.cast_zero, ``Rat.cast_one, ``Rat.cast_ofNat,
675673
]
@@ -729,7 +727,7 @@ def smt_translate (mv' : MVarId) : MetaM MVarId := withTraceNode `smt.reconstruc
729727

730728
for ratVar in sortedRatVars do
731729
let varName ← ratVar.fvarId!.getUserName
732-
let castExpr ← mkAppOptM ``Rat.cast #[mkConst ``Real, none, ratVar]
730+
let castExpr ← mkAppOptM `Rat.cast #[mkConst `Real, none, ratVar]
733731
(_, mv) ← mv.generalize #[{ expr := castExpr, xName? := varName }]
734732

735733
for natVar in sortedNatVars do
@@ -751,14 +749,10 @@ def smt_translate (mv' : MVarId) : MetaM MVarId := withTraceNode `smt.reconstruc
751749

752750
return mv
753751

754-
namespace Tactic
752+
def smtTranslate (mv : MVarId) : MetaM Result := do
753+
let mv ← smtTranslateCore mv
754+
trace[smt.preprocess] m!"final translated goal: {mv}"
755+
let hs ← mv.withContext (return (← getPropHyps).map Expr.fvar)
756+
return { map := {}, hs, mv }
755757

756-
syntax (name := smt_translate) "smt_translate" : tactic
757-
758-
open Lean.Elab Tactic in
759-
@[tactic smt_translate] def evalSmtTranslate : Tactic := fun _ => withMainContext do
760-
let mv ← Tactic.getMainGoal
761-
let mv ← SmtTranslate.smt_translate mv
762-
replaceMainGoal [mv]
763-
764-
end Tactic
758+
end Smt.Preprocess

Smt/Preprocess/NatAsInt.lean

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import Mathlib.Data.Nat.Cast.Order.Basic
2-
31
theorem Nat.forall_as_int (P : Nat → Prop) : (∀ x : Nat, P x) ↔ (∀ x : Int, x ≥ 0 → P x.toNat) := by
42
constructor
53
· intro h x x_nonneg
@@ -17,15 +15,15 @@ theorem Nat.exists_as_int (P : Nat → Prop) : (∃ x : Nat, P x) ↔ (∃ x : I
1715
constructor
1816
· intro h
1917
obtain ⟨x, hx⟩ := h
20-
use x
18+
exists x
2119
exact if_false_right.mp fun a => hx
2220
· intro h
2321
obtain ⟨x, hx⟩ := h
2422
let x_nat : Nat := x.toNat
2523
have h_nat : x = x_nat := by
2624
refine Int.eq_natCast_toNat.mpr ?_
2725
exact hx.1
28-
use x_nat
26+
exists x_nat
2927
unfold x_nat
3028
have : x ≥ 0 := hx.1
3129
exact hx.2 this
@@ -35,10 +33,10 @@ def Int.natSub (x y : Int) :=
3533

3634
theorem Int.natCast_sub2 (x y : Nat) : (x - y : Nat) = Int.natSub x y := by
3735
rw [Int.natSub]
38-
split_ifs with h
36+
split <;> rename_i h
3937
· rw [Int.natCast_sub]
4038
exact Int.ofNat_le.mp h
41-
· rw [Nat.sub_eq_zero_of_le (Nat.le_of_succ_le (Int.ofNat_lt.mp (not_le.mp h))), Int.natCast_zero]
39+
· rw [Nat.sub_eq_zero_of_le (Nat.le_of_succ_le (Int.ofNat_lt.mp (Int.not_le.mp h))), Int.natCast_zero]
4240

4341
theorem Int.ofNat_eq (x y : Nat) : (x = y) = ((x : Int) = (y : Int)) := by
4442
simp only [Int.ofNat_inj]
@@ -56,8 +54,8 @@ theorem Int.ofNat_gt (x y : Nat) : (x > y) = ((x : Int) > (y : Int)) := by
5654
simp only [gt_iff_lt, Int.ofNat_lt]
5755

5856
theorem Int.ofNat_ne (x y : Nat) : x ≠ y ↔ ((x : Int) ≠ (y : Int)) := by
59-
rw [← not_iff_not]
60-
rw [not_not, not_not]
57+
rw [← Decidable.not_iff_not]
58+
rw [Decidable.not_not, Decidable.not_not]
6159
rw [Int.ofNat_inj]
6260

6361
theorem doubleCast (p : Nat → Prop) (w : Nat) : p w = p (w : Int).toNat := by

Smt/Preprocess/RatAsReal.lean

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
11
import Mathlib.Data.Real.Basic
2-
import Batteries.Data.Rat.Basic
3-
import Batteries.Classes.RatCast
4-
import Mathlib.Data.Rat.Cast.CharZero
52
import Mathlib.Data.Rat.Cast.Order
63

74
open Real

Smt/Reconstruct.lean

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -262,27 +262,29 @@ def defaultSolverOptions : List (String × String) := [
262262
open cvc5 in
263263
def solve (query : String) (timeout : Option Nat) (options : List (String × String)) : MetaM (Except cvc5.Error cvc5Result) :=
264264
profileitM Exception "smt" {} do
265-
withTraceNode `smt.solve traceSolve do Solver.run (← TermManager.new) do
265+
withTraceNode `smt.solve traceSolve do cvc5.run do
266+
let tm ← TermManager.new
267+
let slv ← Solver.new tm
266268
if let .some timeout := timeout then
267269
-- NOTE: `tlimit` wouldn't have any effect here, since we're not running in
268270
-- the binary, and because we only have a single `checkSat`, we can use
269271
-- `tlimit-per` instead to achieve the same effect.
270-
Solver.setOption "tlimit-per" (toString (1000*timeout))
272+
slv.setOption "tlimit-per" (toString (1000*timeout))
271273
for (opt, val) in options do
272-
Solver.setOption opt val
273-
let (uss, ufs) ← Solver.parseCommands query
274-
let res ← Solver.checkSat
274+
slv.setOption opt val
275+
let (uss, ufs) ← slv.parseCommands query
276+
let res ← slv.checkSat
275277
trace[smt.solve] m!"result: {res}"
276278
if res.isSat then
277-
let iss ← uss.mapM fun us => return (us, ← Solver.getModelDomainElements us)
278-
let ifs ← ufs.mapM fun uf => return (uf, ← Solver.getValue uf)
279+
let iss ← uss.mapM fun us => return (us, ← slv.getModelDomainElements us)
280+
let ifs ← ufs.mapM fun uf => return (uf, ← slv.getValue uf)
279281
trace[smt.solve] "model:\n{iss}\n{ifs}"
280282
return .sat { iss, ifs }
281283
else if res.isUnsat then
282-
let ps ← Solver.getProof
283-
let uc ← Solver.getUnsatCore
284+
let ps ← slv.getProof
285+
let uc ← slv.getUnsatCore
284286
if h : 0 < ps.size then
285-
trace[smt.solve] "proof:\n{← Solver.proofToString ps[0]}"
287+
trace[smt.solve] "proof:\n{← slv.proofToString ps[0]}"
286288
trace[smt.solve] "unsat-core:\n{uc}"
287289
return .unsat ps[0] uc
288290
else if res.isUnknown then

Smt/Reconstruct/Prop.lean

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -242,17 +242,13 @@ def reclausify (c : Array cvc5.Term) (l : cvc5.Term) : Array cvc5.Term :=
242242
def clausify (c l : cvc5.Term) : Array cvc5.Term :=
243243
reclausify (nary .OR c) l
244244

245+
private def isNotOf (t₁ t₂ : cvc5.Term) : Bool :=
246+
t₁.getKind == .NOT && t₁[0]! == t₂
247+
245248
def getResolutionResult (c₁ c₂ : Array cvc5.Term) (pol l : cvc5.Term) : Array cvc5.Term := Id.run do
246-
let l₁ := if pol.getBooleanValue! then l else l.not!
247-
let l₂ := if pol.getBooleanValue! then l.not! else l
248-
let mut ls := #[]
249-
for li in c₁ do
250-
if li != l₁ then
251-
ls := ls.push li
252-
for li in c₂ do
253-
if li != l₂ then
254-
ls := ls.push li
255-
return ls
249+
let l₁ := if pol.getBooleanValue! then (· == l) else (isNotOf · l)
250+
let l₂ := if pol.getBooleanValue! then (isNotOf · l) else (· == l)
251+
return c₁.eraseP l₁ ++ c₂.eraseP l₂
256252

257253
def reconstructResolution (c₁ c₂ : Array cvc5.Term) (pol l : cvc5.Term) (hps hqs : Expr) : ReconstructM Expr := do
258254
let f t ps := do
@@ -262,7 +258,9 @@ def reconstructResolution (c₁ c₂ : Array cvc5.Term) (pol l : cvc5.Term) (hps
262258
let qs : Q(List Prop) ← c₂.foldrM f q([])
263259
let hps : Q(orN $ps) ← pure hps
264260
let hqs : Q(orN $qs) ← pure hqs
265-
let (i?, j?) := if pol.getBooleanValue! then (c₁.finIdxOf? l, c₂.finIdxOf? l.not!) else (c₁.finIdxOf? l.not!, c₂.finIdxOf? l)
261+
let (i?, j?) := if pol.getBooleanValue!
262+
then (c₁.finIdxOf? l, c₂.findFinIdx? (isNotOf · l))
263+
else (c₁.findFinIdx? (isNotOf · l), c₂.finIdxOf? l)
266264
if let (some ⟨i, _⟩, some ⟨j, _⟩) := (i?, j?) then
267265
let hi : Q($i < «$ps».length) := .app q(@of_decide_eq_true ($i < «$ps».length) _) q(Eq.refl true)
268266
let hj : Q($j < «$qs».length) := .app q(@of_decide_eq_true ($j < «$qs».length) _) q(Eq.refl true)

Smt/Reconstruct/Rat.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ open Lean Qq
2525
| .DIV_BY_ZERO => return q(fun (x : Rat) => x / 0)
2626
| _ => return none
2727
| .CONST_RATIONAL =>
28-
let c : Std.Internal.Rat := t.getRationalValue!
28+
let c : Rat := t.getRationalValue!
2929
let num : Q(Rat) := mkRatLit c.num.natAbs
3030
if c.den == 1 then
3131
if c.num ≥ 0 then
@@ -342,7 +342,7 @@ where
342342
return ha
343343

344344
def reconstructArithPolyNormRel (pf : cvc5.Proof) : ReconstructM (Option Expr) := do
345-
let lcx : Std.Internal.Rat := pf.getChildren[0]!.getResult[0]![0]!.getRationalValue!
345+
let lcx : Rat := pf.getChildren[0]!.getResult[0]![0]!.getRationalValue!
346346
let cx : Q(Rat) ← reconstructTerm pf.getChildren[0]!.getResult[0]![0]!
347347
let cy : Q(Rat) ← reconstructTerm pf.getChildren[0]!.getResult[1]![0]!
348348
let x₁ : Q(Rat) ← reconstructTerm pf.getResult[0]![0]!

0 commit comments

Comments
 (0)