Skip to content

Commit 320576e

Browse files
committed
Update Lean toolchain to v4.29.0.
1 parent 535adf0 commit 320576e

26 files changed

Lines changed: 156 additions & 203 deletions

Smt/Reconstruct.lean

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ def solve (query : String) (timeout : Option Nat) (prove : Bool := true) (option
321321
where each entry is the Lean reconstruction of either a declared sort (paired with a
322322
`Fin n` standing for its finite domain) or a declared function/constant (paired with the
323323
value cvc5 assigned to it).
324-
* `unsat hp mvs usedHints` — the query is unsatisfiable.
324+
* `unsat hp mvs uc` — the query is unsatisfiable.
325325
- `hp` is the reconstructed proof term, or `none` when proof reconstruction was disabled
326326
(i.e. the call was made with `prove := false`). See `solveAndReconstructProof` for the
327327
shape of its type.
@@ -332,13 +332,13 @@ def solve (query : String) (timeout : Option Nat) (prove : Bool := true) (option
332332
the caller to discharge. These should be **rare in practice and worth flagging** when
333333
they appear: a non-empty `mvs` means part of the cvc5 proof was trusted rather than
334334
checked.
335-
- `usedHints` is the unsat core returned by cvc5, with each assertion reconstructed as a
335+
- `uc` is the unsat core returned by cvc5, with each assertion reconstructed as a
336336
Lean `Expr`.
337337
* `unknown reason` — cvc5 returned `unknown`; `reason` is the stringified
338338
`cvc5.UnknownExplanation`. -/
339339
inductive SolveReconstructResult where
340340
| sat (model : Array (Expr × Expr))
341-
| unsat (hp : Option Expr) (mvs : List MVarId) (usedHints : Array Expr)
341+
| unsat (hp : Option Expr) (mvs : List MVarId) (uc : Array Expr)
342342
| unknown (reason : String)
343343

344344
open Qq in
@@ -393,7 +393,7 @@ open Qq in
393393
degenerates to `True → ¬ andN as`; with a single assertion the conclusion is `¬ a₁`; with no
394394
assertions at all it is `¬ True`. -/
395395
def solveAndReconstructProof (query : String)
396-
(timeout : Option Nat) (prove : Bool := true)
396+
(timeout : Option Nat := none) (prove : Bool := true)
397397
(options : List (String × String) := defaultSolverOptions ++ (if prove then [("produce-proofs", "true")] else []))
398398
(userNames : Std.HashMap String Expr := {}) (native : Bool := false) : MetaM SolveReconstructResult :=
399399
profileitM Exception "smt" {} do
@@ -438,7 +438,7 @@ open Lean.Elab Tactic in
438438
@[tactic reconstruct] def evalReconstruct : Tactic := fun stx =>
439439
withMainContext do
440440
let some query := stx[1].isStrLit? | throwError "expected string"
441-
let r ← solveAndReconstructProof query none true (defaultSolverOptions) (← getUserNames)
441+
let r ← solveAndReconstructProof query (userNames := ← getUserNames)
442442
match r with
443443
| .unknown reason =>
444444
throwError m!"solver returned unknown: {reason}"
@@ -455,7 +455,6 @@ open Lean.Elab Tactic in
455455
for (v, t) in model do
456456
md := md ++ m!"\n {v} = {t}"
457457
logInfo md
458-
459458
where
460459
getUserNames : MetaM (Std.HashMap String Expr) := do
461460
let lCtx ← getLCtx

Smt/Reconstruct/Builtin.lean

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -266,17 +266,13 @@ where
266266
decide (p : Q(Prop)) (hp : Q(Decidable $p)) : MetaM Q($p) := do
267267
return .app q(@of_decide_eq_true $p $hp) q(Eq.refl true)
268268
nativeDecide (p : Q(Prop)) (hp : Q(Decidable $p)) : MetaM Q($p) := do
269-
let auxDeclName ← mkNativeAuxDecl `_nativePolynorm q(Bool) q(decide $p)
270-
let b : Q(Bool) := .const auxDeclName []
271-
return .app q(@of_decide_eq_true $p $hp) (.app q(Lean.ofReduceBool $b true) q(Eq.refl true))
272-
mkNativeAuxDecl (baseName : Name) (type value : Expr) : MetaM Name := do
273-
let auxName ← Lean.mkAuxDeclName baseName
274-
let decl := Declaration.defnDecl {
275-
name := auxName, levelParams := [], type, value
276-
hints := .abbrev
277-
safety := .safe
278-
}
279-
addAndCompile decl
280-
pure auxName
269+
match ← Meta.nativeEqTrue `Smt.eval q(decide $p) with
270+
| .notTrue =>
271+
throwError m!"[smt_eval] evaluated that the proposition
272+
{indentExpr q(decide $p)}\n\
273+
is false"
274+
| .success hdp =>
275+
-- get instance from `d`
276+
return .app q(@of_decide_eq_true $p $hp) hdp
281277

282278
end Smt.Reconstruct.Builtin

Smt/Reconstruct/Builtin/Tactic.lean

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -64,18 +64,14 @@ def nativeAbsorb (mv : MVarId) (zero op : Expr) : MetaM Unit := do
6464
where
6565
nativeDecide (p : Q(Prop)) : MetaM Q($p) := do
6666
let hp : Q(Decidable $p) ← Meta.synthInstance q(Decidable $p)
67-
let auxDeclName ← mkNativeAuxDecl `_nativePolynorm q(Bool) q(decide $p)
68-
let b : Q(Bool) := .const auxDeclName []
69-
return .app q(@of_decide_eq_true $p $hp) (.app q(Lean.ofReduceBool $b true) q(Eq.refl true))
70-
mkNativeAuxDecl (baseName : Name) (type value : Expr) : MetaM Name := do
71-
let auxName ← Lean.mkAuxDeclName baseName
72-
let decl := Declaration.defnDecl {
73-
name := auxName, levelParams := [], type, value
74-
hints := .abbrev
75-
safety := .safe
76-
}
77-
addAndCompile decl
78-
pure auxName
67+
match ← Meta.nativeEqTrue `Smt.absorb q(decide $p) with
68+
| .notTrue =>
69+
throwError m!"[poly_norm] evaluated that the proposition
70+
{indentExpr q(decide $p)}\n\
71+
is false"
72+
| .success hdp =>
73+
-- get instance from `d`
74+
return .app q(@of_decide_eq_true $p $hp) hdp
7975

8076
namespace Tactic
8177

Smt/Reconstruct/Int/Polynorm.lean

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -366,18 +366,14 @@ where
366366
logInfo m!"poly := {PolyNorm.Polynomial.toExpr p.toPolynomial ppCtx}"
367367
nativeDecide (p : Q(Prop)) : MetaM Q($p) := do
368368
let hp : Q(Decidable $p) ← Meta.synthInstance q(Decidable $p)
369-
let auxDeclName ← mkNativeAuxDecl `_nativePolynorm q(Bool) q(decide $p)
370-
let b : Q(Bool) := .const auxDeclName []
371-
return .app q(@of_decide_eq_true $p $hp) (.app q(Lean.ofReduceBool $b true) q(Eq.refl true))
372-
mkNativeAuxDecl (baseName : Name) (type value : Expr) : MetaM Name := do
373-
let auxName ← Lean.mkAuxDeclName baseName
374-
let decl := Declaration.defnDecl {
375-
name := auxName, levelParams := [], type, value
376-
hints := .abbrev
377-
safety := .safe
378-
}
379-
addAndCompile decl
380-
pure auxName
369+
match ← Meta.nativeEqTrue `Smt.polynorm q(decide $p) with
370+
| .notTrue =>
371+
throwError m!"[poly_norm] evaluated that the proposition
372+
{indentExpr q(decide $p)}\n\
373+
is false"
374+
| .success hdp =>
375+
-- get instance from `d`
376+
return .app q(@of_decide_eq_true $p $hp) hdp
381377

382378
namespace Tactic
383379

Smt/Reconstruct/Rat/Core.lean

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,6 @@ namespace Rat
1111

1212
variable (x y a b c q : Rat)
1313

14-
protected def abs (x : Rat) := if x < 0 then -x else x
15-
1614
instance : NatPow Rat where
1715
pow := Rat.pow
1816

@@ -58,14 +56,6 @@ theorem mk'_zero (d) (h : d ≠ 0) (w) : mk' 0 d h w = 0 := by
5856
congr
5957
apply Nat.coprime_zero_left d |>.mp w
6058

61-
theorem eq_iff_mul_eq_mul {p q : Rat} : p = q ↔ p.num * q.den = q.num * p.den := by
62-
conv =>
63-
lhs
64-
rw [← num_divInt_den p, ← num_divInt_den q]
65-
apply Rat.divInt_eq_divInt_iff <;>
66-
· rw [← Int.natCast_zero, Ne, Int.ofNat_inj]
67-
apply den_nz
68-
6959
protected theorem lt_iff_blt {x y : Rat} : x < y ↔ x.blt y := by
7060
simp only [LT.lt]
7161

@@ -103,11 +93,6 @@ protected theorem mul_eq_zero_iff : a * b = 0 ↔ a = 0 ∨ b = 0 := by
10393
protected theorem mul_ne_zero_iff : a * b ≠ 0 ↔ a ≠ 0 ∧ b ≠ 0 := by
10494
simp only [not_congr (Rat.mul_eq_zero_iff a b), not_or, ne_eq]
10595

106-
@[simp]
107-
theorem neg_neg : - -q = q := by
108-
rewrite [← Rat.mkRat_self q, Rat.neg_mkRat, Rat.neg_mkRat]
109-
simp
110-
11196
theorem num_ne_zero : q.num ≠ 0 ↔ q ≠ 0 := not_congr num_eq_zero
11297

11398
theorem nonneg_iff_sub_nonpos : 0 ≤ q ↔ -q ≤ 0 := by
@@ -158,14 +143,8 @@ theorem num_neg : q.num < 0 ↔ q < 0 := by
158143
theorem num_neg_eq_neg_num (q : Rat) : (-q).num = -q.num :=
159144
rfl
160145

161-
@[simp]
162-
protected theorem sub_self : x - x = 0 :=
163-
numDenCasesOn' x fun nx dx h_dx => by
164-
rw [Rat.divInt_sub_divInt _ _ (Int.natCast_ne_zero.mpr h_dx) (Int.natCast_ne_zero.mpr h_dx)]
165-
simp
166-
167146
protected theorem add_neg_self : x + -x = 0 :=
168-
Rat.sub_eq_add_neg x x ▸ Rat.sub_self x
147+
Rat.sub_eq_add_neg x x ▸ Rat.sub_self
169148

170149
protected theorem eq_neg_of_add_eq_zero_left : x + y = 0 → x = - y :=
171150
numDenCasesOn'' x fun nx dx h_dx h_dx_red =>
@@ -205,7 +184,7 @@ protected theorem divInt_le_divInt
205184

206185
theorem cast_lt1 {a b : Int} : Rat.ofInt a < Rat.ofInt b -> a < b := by
207186
intro h
208-
simp [Rat.instLT, Rat.ofInt] at h
187+
simp [Rat.lt_iff_blt, Rat.ofInt] at h
209188
simp [Rat.blt] at h
210189
cases h with
211190
| inl h =>
@@ -220,7 +199,7 @@ theorem cast_lt1 {a b : Int} : Rat.ofInt a < Rat.ofInt b -> a < b := by
220199

221200
theorem cast_lt2 {a b : Int} : a < b → Rat.ofInt a < Rat.ofInt b := by
222201
intro h
223-
simp only [instLT, ofInt, mk_den_one]
202+
simp only [Rat.lt_iff_blt, ofInt, mk_den_one]
224203
simp [Rat.blt]
225204
cases Classical.em (a = 0) with
226205
| inl ha => simp [ha]; rw [ha] at h; exact h
@@ -236,7 +215,7 @@ theorem cast_lt' {a b : Int} : a < b ↔ Rat.ofInt a < Rat.ofInt b :=
236215

237216
theorem cast_le1 {a b : Int} : Rat.ofInt a ≤ Rat.ofInt b -> a ≤ b := by
238217
intro h
239-
simp only [instLE, ofInt, mk_den_one] at h
218+
simp only [Rat.le_iff_blt, ofInt, mk_den_one] at h
240219
simp [Rat.blt] at h
241220
cases Classical.em (b = 0) with
242221
| inl hb =>
@@ -260,7 +239,7 @@ theorem cast_le1 {a b : Int} : Rat.ofInt a ≤ Rat.ofInt b -> a ≤ b := by
260239

261240
theorem cast_le2 {a b : Int} : a ≤ b → Rat.ofInt a ≤ Rat.ofInt b := by
262241
intro h
263-
simp [Rat.instLE, Rat.ofInt]
242+
simp [Rat.le_iff_blt, Rat.ofInt]
264243
simp [Rat.blt]
265244
cases Classical.em (b = 0) with
266245
| inl hb =>
@@ -303,13 +282,6 @@ theorem le_floor {z : Int} : ∀ {r : Rat}, z ≤ Rat.floor r ↔ (z : Rat) ≤
303282
rw [Rat.intCast_eq_divInt, Rat.divInt_le_divInt Int.zero_lt_one h', Int.mul_one]
304283
exact Int.le_ediv_iff_mul_le h'
305284

306-
@[simp]
307-
protected theorem neg_zero : -(0:Rat) = 0 := rfl
308-
309-
protected theorem neg_add (a b : Rat) : -(a + b) = -a + -b := by
310-
rw [←Rat.sub_eq_add_neg, ←Rat.neg_neg b, ←Rat.sub_eq_add_neg, Rat.neg_sub]
311-
simp [Rat.sub_eq_add_neg, Rat.add_comm, Rat.neg_neg]
312-
313285
theorem neg_eq_neg_one_mul (a : Rat) : -a = -1 * a :=
314286
numDenCasesOn a fun n d h h1 => by
315287
simp [Rat.neg_mkRat, Rat.mul_def, Rat.normalize_eq_mkRat]

0 commit comments

Comments
 (0)