Skip to content

Commit 17e199e

Browse files
kim-emclaude
andcommitted
Merge lean-pr-testing-13305 into nightly-testing: adapt to new do elaborator (lean4#13305)
Brings in the do-elaborator adaptations for 14 Mathlib files (Ring, NormNum, FieldSimp, Whitespace linter, etc.) and repoints batteries/Qq/aesop/plausible to their nightly-testing branches (which carry the corresponding fixes). Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
2 parents dd06748 + 29c1d73 commit 17e199e

16 files changed

Lines changed: 198 additions & 193 deletions

File tree

Mathlib/Data/Fin/Tuple/Reflection.lean

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -175,10 +175,10 @@ open Lean Meta Qq
175175
that shows it is equal to `∏ i, f i`. -/
176176
meta def mkProdEqQ {u : Level} {α : Q(Type u)}
177177
(inst : Q(CommMonoid $α)) (n : ℕ) (f : Q(Fin $n → $α)) :
178-
MetaM <| (val : Q($α)) × Q(∏ i, $f i = $val) := do
178+
MetaM <| (val : Q($α)) × Q(∏ i, $f i = $val) :=
179179
match n with
180-
| 0 => return ⟨q((1 : $α)), q(Fin.prod_univ_zero $f)⟩
181-
| m + 1 =>
180+
| 0 => do return ⟨q((1 : $α)), q(Fin.prod_univ_zero $f)⟩
181+
| m + 1 => do
182182
let nezero : Q(NeZero ($m + 1)) := q(⟨Nat.succ_ne_zero _⟩)
183183
let val ← makeRHS (m + 1) f nezero (m + 1)
184184
let _ : $val =Q FinVec.prod $f := ⟨⟩
@@ -198,10 +198,10 @@ where
198198
that shows it is equal to `∑ i, f i`. -/
199199
meta def mkSumEqQ {u : Level} {α : Q(Type u)}
200200
(inst : Q(AddCommMonoid $α)) (n : ℕ) (f : Q(Fin $n → $α)) :
201-
MetaM <| (val : Q($α)) × Q(∑ i, $f i = $val) := do
201+
MetaM <| (val : Q($α)) × Q(∑ i, $f i = $val) :=
202202
match n with
203203
| 0 => return ⟨q((0 : $α)), q(Fin.sum_univ_zero $f)⟩
204-
| m + 1 =>
204+
| m + 1 => do
205205
let nezero : Q(NeZero ($m + 1)) := q(⟨Nat.succ_ne_zero _⟩)
206206
let val ← makeRHS (m + 1) f nezero (m + 1)
207207
let _ : $val =Q FinVec.sum $f := ⟨⟩
@@ -228,7 +228,7 @@ open Qq Lean FinVec
228228
simproc_decl prod_univ_ofNat (∏ _ : Fin _, _) := .ofQ fun u _ e => do
229229
match u, e with
230230
| .succ _, ~q(@Finset.prod (Fin $n) _ $inst (@Finset.univ _ $instF) $f) => do
231-
match (generalizing := false) n.nat? with
231+
match n.nat? with
232232
| none =>
233233
return .continue
234234
| some nVal =>

Mathlib/Tactic/Algebra/Basic.lean

Lines changed: 40 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -165,24 +165,24 @@ namespace RingCompute
165165

166166
/-- Evaluate the sum of two normalized expressions in `R` using `ring`. -/
167167
def add (cR : Common.Cache sR) {a b : Q($A)} (za : BaseType sAlg a) (zb : BaseType sAlg b) :
168-
MetaM (Common.Result (BaseType sAlg) q($a + $b) × Option Q(IsNat ($a + $b) 0)) := do
169-
let ⟨r, vr⟩ := za
170-
let ⟨s, vs⟩ := zb
171-
let ⟨t, vt, pt⟩ ← Common.evalAdd (Ring.ringCompute cR) rcℕ vr vs
172-
match vt with
173-
| .zero =>
174-
have : $t =Q 0 := ⟨⟩
175-
return ⟨⟨_, .mk _ vt, q(add_algebraMap $pt)⟩, some q(add_algebraMap_isNat_zero $pt)⟩
176-
| vt =>
177-
return ⟨⟨_, .mk _ vt, q(add_algebraMap $pt)⟩, none⟩
168+
MetaM (Common.Result (BaseType sAlg) q($a + $b) × Option Q(IsNat ($a + $b) 0)) :=
169+
match za, zb with
170+
| .mk r vr, .mk s vs => do
171+
let ⟨t, vt, pt⟩ ← Common.evalAdd (Ring.ringCompute cR) rcℕ vr vs
172+
match (dependent := true) vt with
173+
| .zero =>
174+
have : $t =Q 0 := ⟨⟩
175+
return ⟨⟨_, .mk _ vt, q(add_algebraMap $pt)⟩, some q(add_algebraMap_isNat_zero $pt)⟩
176+
| vt =>
177+
return ⟨⟨_, .mk _ vt, q(add_algebraMap $pt)⟩, none⟩
178178

179179
/-- Evaluate the product of two normalized expressions in `R` using `ring`. -/
180180
def mul (cR : Common.Cache sR) {a b : Q($A)} (za : BaseType sAlg a) (zb : BaseType sAlg b) :
181-
MetaM (Common.Result (BaseType sAlg) q($a * $b)) := do
182-
let ⟨r, vr⟩ := za
183-
let ⟨s, vs⟩ := zb
184-
let ⟨t, vt, pt⟩ ← Common.evalMul (Ring.ringCompute cR) rcℕ vr vs
185-
return ⟨_, .mk _ vt, q(by simp [← $pt, map_mul])⟩
181+
MetaM (Common.Result (BaseType sAlg) q($a * $b)) :=
182+
match za, zb with
183+
| .mk r vr, .mk s vs => do
184+
let ⟨t, vt, pt⟩ ← Common.evalMul (Ring.ringCompute cR) rcℕ vr vs
185+
return ⟨_, .mk _ vt, q(by simp [← $pt, map_mul])⟩
186186

187187
/-- Take an expression `r'` in a ring `R'` such that `R` is an `R'`-algebra and cast `r'` to `R`
188188
using `algebraMap R' R`, so that the scalar multiplication action on `A` is preserved. -/
@@ -195,7 +195,7 @@ def cast (cR : Algebra.Cache sR) (u' : Level) (R' : Q(Type u'))
195195
let ⟨r, pf_smul⟩ ← evalSMulCast q($sAlg) q($_smul) r'
196196
let ⟨_r'', vr, pr⟩ ←
197197
Common.eval rcℕ (Ring.ringCompute cR.toCache) cR.toCache q($r)
198-
match vr with
198+
match (dependent := true) vr with
199199
| .zero .. =>
200200
assumeInstancesCommute
201201
return ⟨_, .zero, q(cast_zero_smul_eq_zero_mul $pr $pf_smul)⟩
@@ -206,37 +206,40 @@ def cast (cR : Algebra.Cache sR) (u' : Level) (R' : Q(Type u'))
206206

207207
/-- Evaluate the product of two normalized expressions in `R` using `ring`. -/
208208
def neg (cR : Algebra.Cache sR) {a : Q($A)} (_rA : Q(CommRing $A)) (za : BaseType sAlg a) :
209-
MetaM (Common.Result (BaseType sAlg) q(-$a)) := do
210-
let ⟨r, vr⟩ := za
211-
match cR.rα with
212-
| some rR =>
213-
let ⟨_, vt, pt⟩ ← Common.evalNeg (Ring.ringCompute cR.toCache) q($rR) vr
214-
assumeInstancesCommute
215-
return ⟨_, .mk _ vt, q(neg_algebraMap $pt)⟩
216-
| none => failure
209+
MetaM (Common.Result (BaseType sAlg) q(-$a)) :=
210+
match za with
211+
| .mk r vr => do
212+
match cR.rα with
213+
| some rR =>
214+
let ⟨_, vt, pt⟩ ← Common.evalNeg (Ring.ringCompute cR.toCache) q($rR) vr
215+
assumeInstancesCommute
216+
return ⟨_, .mk _ vt, q(neg_algebraMap $pt)⟩
217+
| none => failure
217218

218219
/-- Raise a normalized expression in `R` to the power of a normalized natural number expression
219220
using `ring`. -/
220221
def pow (cR : Common.Cache sR) {a : Q($A)} {b : Q(ℕ)} (za : BaseType sAlg a)
221222
(vb : Common.ExProdNat q($b)) :
222-
OptionT MetaM (Common.Result (BaseType sAlg) q($a ^ $b)) := do
223-
let ⟨r, vr⟩ := za
224-
let ⟨_, vs, ps⟩ ← Common.evalPow₁ (Ring.ringCompute cR) rcℕ vr vb
225-
return ⟨_, ⟨_, vs⟩, q(pow_algebraMap $ps)⟩
223+
OptionT MetaM (Common.Result (BaseType sAlg) q($a ^ $b)) :=
224+
match za with
225+
| .mk r vr => do
226+
let ⟨_, vs, ps⟩ ← Common.evalPow₁ (Ring.ringCompute cR) rcℕ vr vb
227+
return ⟨_, ⟨_, vs⟩, q(pow_algebraMap $ps)⟩
226228

227229
/-- Evaluate the inverse of two normalized expressions in `R` using `ring`. -/
228230
/- We include the CharZero argument to match the type signature of the ringCompute entry. -/
229231
@[nolint unusedArguments]
230232
def inv (cR : Algebra.Cache sR) {a : Q($A)} (_ : Option Q(CharZero $A)) (fA : Q(Semifield $A))
231-
(za : BaseType sAlg a) : AtomM (Option (Common.Result (BaseType sAlg) q($a⁻¹))) := do
232-
match cR.dsα with
233-
| some fR =>
234-
let ⟨r, vr⟩ := za
235-
let ⟨_, vs, ps⟩ ← Common.ExSum.evalInv (Ring.ringCompute cR.toCache) rcℕ q($fR) cR.czα vr
236-
assumeInstancesCommute
237-
return some ⟨_, ⟨_, vs⟩, q(inv_algebraMap $ps)⟩
238-
| none =>
239-
return none
233+
(za : BaseType sAlg a) : AtomM (Option (Common.Result (BaseType sAlg) q($a⁻¹))) :=
234+
match za with
235+
| .mk r vr => do
236+
match cR.dsα with
237+
| some fR =>
238+
let ⟨_, vs, ps⟩ ← Common.ExSum.evalInv (Ring.ringCompute cR.toCache) rcℕ q($fR) cR.czα vr
239+
assumeInstancesCommute
240+
return some ⟨_, ⟨_, vs⟩, q(inv_algebraMap $ps)⟩
241+
| none =>
242+
return none
240243

241244
/-- Evaluate constants in `A` using `norm_num`. -/
242245
def derive (cR : Algebra.Cache sR) (cA : Algebra.Cache sA) (x : Q($A)) :

Mathlib/Tactic/FieldSimp.lean

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def onExponent (l : qNF M) (f : ℤ → ℤ) : qNF M :=
6262

6363
/-- Build a transparent expression for the product of powers represented by `l : qNF M`. -/
6464
def evalPrettyMonomial (iM : Q(GroupWithZero $M)) (r : ℤ) (x : Q($M)) :
65-
MetaM (Σ e : Q($M), Q(zpow' $x $r = $e)) := do
65+
MetaM (Σ e : Q($M), Q(zpow' $x $r = $e)) :=
6666
match r with
6767
| 0 => /- If an exponent is zero then we must not have been able to prove that x is nonzero. -/
6868
return ⟨q($x / $x), q(zpow'_zero_eq_div ..)⟩
@@ -111,10 +111,10 @@ def removeZeros
111111
of) the negative powers. -/
112112
def split (iM : Q(CommGroupWithZero $M)) (l : qNF M) :
113113
MetaM (Σ l_n l_d : qNF M, Q(NF.eval $(l.toNF)
114-
= NF.eval $(l_n.toNF) / NF.eval $(l_d.toNF))) := do
114+
= NF.eval $(l_n.toNF) / NF.eval $(l_d.toNF))) :=
115115
match l with
116116
| [] => return ⟨[], [], q(Eq.symm (div_one (1:$M)))⟩
117-
| ((r, x), i) :: t =>
117+
| ((r, x), i) :: t => do
118118
let ⟨t_n, t_d, pf⟩ ← split iM t
119119
if r > 0 then
120120
return ⟨((r, x), i) :: t_n, t_d, (q(NF.cons_eq_div_of_eq_div $r $x $pf):)⟩
@@ -125,13 +125,13 @@ def split (iM : Q(CommGroupWithZero $M)) (l : qNF M) :
125125
return ⟨t_n, ((r', x), i) :: t_d, (q(NF.cons_eq_div_of_eq_div' $r' $x $pf):)⟩
126126

127127
private def evalPrettyAux (iM : Q(CommGroupWithZero $M)) (l : qNF M) :
128-
MetaM (Σ e : Q($M), Q(NF.eval $(l.toNF) = $e)) := do
128+
MetaM (Σ e : Q($M), Q(NF.eval $(l.toNF) = $e)) :=
129129
match l with
130130
| [] => return ⟨q(1), q(rfl)⟩
131-
| [((r, x), _)] =>
131+
| [((r, x), _)] => do
132132
let ⟨e, pf⟩ ← evalPrettyMonomial q(inferInstance) r x
133133
return ⟨e, q(by rw [NF.eval_cons]; exact Eq.trans (one_mul _) $pf)⟩
134-
| ((r, x), k) :: t =>
134+
| ((r, x), k) :: t => do
135135
let ⟨e, pf_e⟩ ← evalPrettyMonomial q(inferInstance) r x
136136
let ⟨t', pf⟩ ← evalPrettyAux iM t
137137
have pf'' : Q(NF.eval $(qNF.toNF (((r, x), k) :: t)) = (NF.eval $(qNF.toNF t)) * zpow' $x $r) :=
@@ -144,7 +144,7 @@ def evalPretty (iM : Q(CommGroupWithZero $M)) (l : qNF M) :
144144
let ⟨l_n, l_d, pf⟩ ← split iM l
145145
let ⟨num, pf_n⟩ ← evalPrettyAux q(inferInstance) l_n
146146
let ⟨den, pf_d⟩ ← evalPrettyAux q(inferInstance) l_d
147-
match l_d with
147+
match (dependent := true) l_d with
148148
| [] => return ⟨num, q(eq_div_of_eq_one_of_subst $pf $pf_n)⟩
149149
| _ =>
150150
let pf_n : Q(NF.eval $(l_n.toNF) = $num) := pf_n
@@ -281,14 +281,14 @@ def mkDenomConditionProofSucc {iM : Q(CommGroupWithZero $M)}
281281
(disch : ∀ {u : Level} (type : Q(Sort u)), MetaM Q($type))
282282
{cond : DenomCondition (M := M) q(inferInstance)}
283283
{L : qNF M} (hL : cond.proof L) (e : Q($M)) (r : ℤ) (i : ℕ) :
284-
MetaM (Q($e ≠ 0) × cond.proof (((r, e), i) :: L)) := do
284+
MetaM (Q($e ≠ 0) × cond.proof (((r, e), i) :: L)) :=
285285
match cond with
286286
| .none => return (← disch q($e ≠ 0), Unit.unit)
287-
| .nonzero =>
287+
| .nonzero => do
288288
let pf ← disch q($e ≠ 0)
289289
let pf₀ : Q(NF.eval $(qNF.toNF L) ≠ 0) := hL
290290
return (pf, q(NF.cons_ne_zero $r $pf $pf₀))
291-
| .positive _ _ _ _ =>
291+
| .positive _ _ _ _ => do
292292
let pf ← disch q(0 < $e)
293293
let pf₀ : Q(0 < NF.eval $(qNF.toNF L)) := hL
294294
let pf' := q(NF.cons_pos $r (x := $e) $pf $pf₀)
@@ -301,14 +301,14 @@ def mkDenomConditionProofSucc' {iM : Q(CommGroupWithZero $M)}
301301
(disch : ∀ {u : Level} (type : Q(Sort u)), MetaM Q($type))
302302
{cond : DenomCondition (M := M) q(inferInstance)}
303303
{L : qNF M} (hL : cond.proof L) (e : Q($M)) (r : ℤ) (i : ℕ) :
304-
MetaM (cond.proof (((r, e), i) :: L)) := do
304+
MetaM (cond.proof (((r, e), i) :: L)) :=
305305
match cond with
306306
| .none => return Unit.unit
307-
| .nonzero =>
307+
| .nonzero => do
308308
let pf ← disch q($e ≠ 0)
309309
let pf₀ : Q(NF.eval $(qNF.toNF L) ≠ 0) := hL
310310
return q(NF.cons_ne_zero $r $pf $pf₀)
311-
| .positive _ _ _ _ =>
311+
| .positive _ _ _ _ => do
312312
let pf ← disch q(0 < $e)
313313
let pf₀ : Q(0 < NF.eval $(qNF.toNF L)) := hL
314314
return q(NF.cons_pos $r (x := $e) $pf $pf₀)

Mathlib/Tactic/FieldSimp/Lemmas.lean

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -398,7 +398,7 @@ def Sign.expr : Sign M → Q($M) → Q($M)
398398
the product with `c` of (± `y`) (here taking the specified sign) is ± `c * y`. -/
399399
def Sign.mulRight (iM : Q(CommGroupWithZero $M)) (c y : Q($M)) (g : Sign M) :
400400
MetaM Q($(g.expr q($c * $y)) = $c * $(g.expr y)) := do
401-
match g with
401+
match (dependent := true) g with
402402
| .plus => pure q(rfl)
403403
| .minus _ =>
404404
assumeInstancesCommute
@@ -409,7 +409,7 @@ the product of (± `y₁`) and (± `y₂`) (here taking the specified signs) is
409409
proof and the computed sign. -/
410410
def Sign.mul (iM : Q(CommGroupWithZero $M)) (y₁ y₂ : Q($M)) (g₁ g₂ : Sign M) :
411411
MetaM (Σ (G : Sign M), Q($(g₁.expr y₁) * $(g₂.expr y₂) = $(G.expr q($y₁ * $y₂)))) := do
412-
match g₁, g₂ with
412+
match (dependent := true) g₁, g₂ with
413413
| .plus, .plus => pure ⟨.plus, q(rfl)⟩
414414
| .plus, .minus i =>
415415
assumeInstancesCommute
@@ -425,7 +425,7 @@ def Sign.mul (iM : Q(CommGroupWithZero $M)) (y₁ y₂ : Q($M)) (g₁ g₂ : Sig
425425
the inverse of (± `y`) (here taking the specified sign) is ± `y⁻¹`. -/
426426
def Sign.inv (iM : Q(CommGroupWithZero $M)) (y : Q($M)) (g : Sign M) :
427427
MetaM (Q($(g.expr y)⁻¹ = $(g.expr q($y⁻¹)))) := do
428-
match g with
428+
match (dependent := true) g with
429429
| .plus => pure q(rfl)
430430
| .minus _ =>
431431
assumeInstancesCommute
@@ -436,7 +436,7 @@ the quotient of (± `y₁`) and (± `y₂`) (here taking the specified signs) is
436436
proof and the computed sign. -/
437437
def Sign.div (iM : Q(CommGroupWithZero $M)) (y₁ y₂ : Q($M)) (g₁ g₂ : Sign M) :
438438
MetaM (Σ (G : Sign M), Q($(g₁.expr y₁) / $(g₂.expr y₂) = $(G.expr q($y₁ / $y₂)))) := do
439-
match g₁, g₂ with
439+
match (dependent := true) g₁, g₂ with
440440
| .plus, .plus => pure ⟨.plus, q(rfl)⟩
441441
| .plus, .minus i =>
442442
assumeInstancesCommute
@@ -452,7 +452,7 @@ def Sign.div (iM : Q(CommGroupWithZero $M)) (y₁ y₂ : Q($M)) (g₁ g₂ : Sig
452452
the negation of (± `y`) (here taking the specified sign) is ∓ `y`. -/
453453
def Sign.neg (iM : Q(Field $M)) (y : Q($M)) (g : Sign M) :
454454
MetaM (Σ (G : Sign M), Q(-$(g.expr y) = $(G.expr y))) := do
455-
match g with
455+
match (dependent := true) g with
456456
| .plus => pure ⟨.minus iM, q(rfl)⟩
457457
| .minus _ =>
458458
assumeInstancesCommute
@@ -463,7 +463,7 @@ the exponentiation to power `s : ℕ` of (± `y`) (here taking the specified sig
463463
return this proof and the computed sign. -/
464464
def Sign.pow (iM : Q(CommGroupWithZero $M)) (y : Q($M)) (g : Sign M) (s : ℕ) :
465465
MetaM (Σ (G : Sign M), Q($(g.expr y) ^ $s = $(G.expr q($y ^ $s)))) := do
466-
match g with
466+
match (dependent := true) g with
467467
| .plus => pure ⟨.plus, q(rfl)⟩
468468
| .minus i =>
469469
assumeInstancesCommute
@@ -479,7 +479,7 @@ the exponentiation to power `s : ℤ` of (± `y`) (here taking the specified sig
479479
return this proof and the computed sign. -/
480480
def Sign.zpow (iM : Q(CommGroupWithZero $M)) (y : Q($M)) (g : Sign M) (s : ℤ) :
481481
MetaM (Σ (G : Sign M), Q($(g.expr y) ^ $s = $(G.expr q($y ^ $s)))) := do
482-
match g with
482+
match (dependent := true) g with
483483
| .plus => pure ⟨.plus, q(rfl)⟩
484484
| .minus i =>
485485
assumeInstancesCommute

Mathlib/Tactic/Linter/Whitespace.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -335,7 +335,7 @@ def whitespaceLinter : Linter where run := withSetOptionIn fun stx ↦ do
335335

336336
let fmt : Option Format := ←
337337
try
338-
liftCoreM <| PrettyPrinter.ppCategory `command stx
338+
liftCoreM <| some <$> PrettyPrinter.ppCategory `command stx
339339
catch _ =>
340340
Linter.logLintIf linter.style.whitespace.verbose (stx.getHead?.getD stx)
341341
m!"The `whitespace` linter had some parsing issues: \

Mathlib/Tactic/NormNum/Core.lean

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ and returning the truth or falsity of `p' : Prop` from an equivalence `p ↔ p'`
150150
def deriveBoolOfIff (p p' : Q(Prop)) (hp : Q($p ↔ $p')) :
151151
MetaM ((b : Bool) × BoolResult p' b) := do
152152
let ⟨b, pb⟩ ← deriveBool p
153-
match b with
153+
match (dependent := true) b with
154154
| true => returntrue, q(Iff.mp $hp $pb)⟩
155155
| false => returnfalse, q((Iff.not $hp).mp $pb)⟩
156156

0 commit comments

Comments
 (0)