Skip to content

Commit d3b4f0c

Browse files
committed
chore: bump quote4 (#5975)
1 parent 41fc6fc commit d3b4f0c

File tree

12 files changed

+335
-355
lines changed

12 files changed

+335
-355
lines changed

Mathlib/NumberTheory/LucasLehmer.lean

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -596,8 +596,7 @@ theorem isNat_not_lucasLehmerTest : {p np : ℕ} →
596596
@[norm_num LucasLehmer.LucasLehmerTest (_ : ℕ)]
597597
def evalLucasLehmerTest : NormNumExt where eval {u α} e := do
598598
let .app _ (p : Q(ℕ)) ← Meta.whnfR e | failure
599-
let sℕ : Q(AddMonoidWithOne ℕ) := q(instAddMonoidWithOneNat)
600-
let ⟨ep, hp⟩ ← deriveNat p
599+
let ⟨ep, hp⟩ ← deriveNat p _
601600
let np := ep.natLit!
602601
unless 1 < np do
603602
failure

Mathlib/Tactic/ModCases.lean

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,13 +60,15 @@ and `b ≤ n`. Returns the list of subgoals `?gi : a ≡ i [ZMOD n] → p`.
6060
partial def proveOnModCases (n : Q(ℕ)) (a : Q(ℤ)) (b : Q(ℕ)) (p : Q(Sort u)) :
6161
MetaM (Q(OnModCases $n $a $b $p) × List MVarId) := do
6262
if n.natLit! ≤ b.natLit! then
63-
pure ((q(onModCases_stop $p $n $a) : Expr), [])
63+
haveI' : $b =Q $n := ⟨⟩
64+
pure (q(onModCases_stop $p $n $a), [])
6465
else
6566
let ty := q($a ≡ OfNat.ofNat $b [ZMOD OfNat.ofNat $n] → $p)
66-
let g : QQ ty ← mkFreshExprMVar ty
67-
let ((pr : Q(OnModCases $n $a (Nat.add $b 1) $p)), acc) ←
68-
proveOnModCases n a (mkRawNatLit (b.natLit! + 1)) p
69-
pure ((q(onModCases_succ $b $g $pr) : Expr), g.mvarId! :: acc)
67+
let g ← mkFreshExprMVarQ ty
68+
have b1 : Q(ℕ) := mkRawNatLit (b.natLit! + 1)
69+
haveI' : $b1 =Q ($b).succ := ⟨⟩
70+
let (pr, acc) ← proveOnModCases n a b1 p
71+
pure (q(onModCases_succ $b $g $pr), g.mvarId! :: acc)
7072

7173
/--
7274
* The tactic `mod_cases h : e % 3` will perform a case disjunction on `e : ℤ` and yield subgoals

Mathlib/Tactic/NormNum/Basic.lean

Lines changed: 182 additions & 178 deletions
Large diffs are not rendered by default.

Mathlib/Tactic/NormNum/BigOperators.lean

Lines changed: 75 additions & 88 deletions
Original file line numberDiff line numberDiff line change
@@ -105,51 +105,44 @@ lemma List.range_succ_eq_map' {n nn n' : ℕ} (pn : NormNum.IsNat n nn) (pn' : n
105105
List.range n = 0 :: List.map Nat.succ (List.range n') := by
106106
rw [pn.out, Nat.cast_id, pn', List.range_succ_eq_map]
107107

108+
set_option linter.unusedVariables false in
108109
/-- Either show the expression `s : Q(List α)` is Nil, or remove one element from it.
109110
110111
Fails if we cannot determine which of the alternatives apply to the expression.
111112
-/
112-
partial def List.proveNilOrCons {α : Q(Type u)} :
113-
(s : Q(List $α)) → MetaM (List.ProveNilOrConsResult s) :=
114-
fun s =>
113+
partial def List.proveNilOrCons {α : Q(Type u)} (s : Q(List $α)) :
114+
MetaM (List.ProveNilOrConsResult s) :=
115115
s.withApp fun e a =>
116116
match (e, e.constName, a) with
117-
| (_, `EmptyCollection.EmptyCollection, _) => pure (.nil (q(rfl) : Q((∅ : List $α) = [])))
118-
| (_, `List.nil, _) => pure (.nil (q(rfl) : Q(([] : List $α) = [])))
119-
| (_, `List.cons, #[_, a, s']) => pure (.cons a s' (q(rfl) : Q($s = $s)))
120-
| (_, `List.range, #[(n : Q(ℕ))]) => do
121-
let instAMO_nat : Q(AddMonoidWithOne ℕ) := q(AddCommMonoidWithOne.toAddMonoidWithOne)
122-
let ⟨nn, pn⟩ ← NormNum.deriveNat n
117+
| (_, ``EmptyCollection.emptyCollection, _) => haveI : $s =Q {} := ⟨⟩; pure (.nil q(.refl []))
118+
| (_, ``List.nil, _) => haveI : $s =Q [] := ⟨⟩; pure (.nil q(rfl))
119+
| (_, ``List.cons, #[_, (a : Q($α)), (s' : Q(List $α))]) =>
120+
haveI : $s =Q $a :: $s' := ⟨⟩; pure (.cons a s' q(rfl))
121+
| (_, ``List.range, #[(n : Q(ℕ))]) =>
122+
have s : Q(List ℕ) := s; .uncheckedCast _ _ <$> show MetaM (ProveNilOrConsResult s) from do
123+
let ⟨nn, pn⟩ ← NormNum.deriveNat n _
124+
haveI' : $s =Q .range $n := ⟨⟩
123125
let nnL := nn.natLit!
124126
if nnL = 0 then
125-
let pn : Q(@NormNum.IsNat _ _ $n 0) := pn
126-
return .nil (q(List.range_zero' $pn) : Q(List.range $n = []))
127+
haveI' : $nn =Q 0 := ⟨⟩
128+
return .nil q(List.range_zero' $pn)
127129
else
128130
have n' : Q(ℕ) := mkRawNatLit (nnL - 1)
129-
let pn' : Q($nn = Nat.succ $n') := (q(Eq.refl $nn) : Expr)
130-
return (List.ProveNilOrConsResult.cons
131-
q(0)
132-
q(List.map Nat.succ (List.range $n'))
133-
q(List.range_succ_eq_map' $pn $pn')).uncheckedCast (q(List.range ($n)) : Q(List ℕ)) s
134-
| (_, `List.finRange, #[(n : Q(ℕ))]) => do
135-
match ← Nat.unifyZeroOrSucc n with -- We want definitional equality on `n`.
136-
| .zero _pf => do
137-
pure (.nil (q(List.finRange_zero) : Q(List.finRange 0 = [])))
138-
| .succ n' _pf => pure <| ((List.ProveNilOrConsResult.cons
139-
q(0 : Fin (Nat.succ $n'))
140-
(q(List.map Fin.succ (List.finRange $n')))
141-
(q(List.finRange_succ_eq_map $n'))).uncheckedCast
142-
(q(List.finRange (Nat.succ $n')) : Q(List (Fin (Nat.succ $n'))))
143-
s)
144-
| (.const `List.map [v, _], _, #[β, _, f, xxs]) => do
145-
have β : Q(Type v) := β
146-
have f : Q($β → $α) := f
147-
have xxs : Q(List $β) := xxs
148-
match ← List.proveNilOrCons xxs with
149-
| .nil pf => pure <| (.nil
150-
(q($pf ▸ List.map_nil) : Q(List.map $f $xxs = [])))
151-
| .cons x xs pf => pure <| (.cons q($f $x) q(List.map $f $xs)
152-
(q($pf ▸ List.map_cons $f $x $xs) : Q(List.map $f $xxs = $f $x :: List.map $f $xs)))
131+
have : $nn =Q .succ $n' := ⟨⟩
132+
return .cons _ _ q(List.range_succ_eq_map' $pn (.refl $nn))
133+
| (_, ``List.finRange, #[(n : Q(ℕ))]) =>
134+
have s : Q(List (Fin $n)) := s
135+
.uncheckedCast _ _ <$> show MetaM (ProveNilOrConsResult s) from do
136+
haveI' : $s =Q .finRange $n := ⟨⟩
137+
return match ← Nat.unifyZeroOrSucc n with -- We want definitional equality on `n`.
138+
| .zero _pf => .nil q(List.finRange_zero)
139+
| .succ n' _pf => .cons _ _ q(List.finRange_succ_eq_map $n')
140+
| (.const ``List.map [v, _], _, #[(β : Q(Type v)), _, (f : Q($β → $α)), (xxs : Q(List $β))]) => do
141+
haveI' : $s =Q ($xxs).map $f := ⟨⟩
142+
return match ← List.proveNilOrCons xxs with
143+
| .nil pf => .nil q(($pf ▸ List.map_nil : List.map _ _ = _))
144+
| .cons x xs pf => .cons q($f $x) q(($xs).map $f)
145+
q(($pf ▸ List.map_cons $f $x $xs : List.map _ _ = _))
153146
| (_, fn, args) =>
154147
throwError "List.proveNilOrCons: unsupported List expression {s} ({fn}, {args})"
155148

@@ -194,33 +187,31 @@ lemma Multiset.range_succ' {n nn n' : ℕ} (pn : NormNum.IsNat n nn) (pn' : nn =
194187
195188
Fails if we cannot determine which of the alternatives apply to the expression.
196189
-/
197-
partial def Multiset.proveZeroOrCons {α : Q(Type u)} :
198-
(s : Q(Multiset $α)) → MetaM (Multiset.ProveZeroOrConsResult s) :=
199-
fun s =>
200-
match Expr.getAppFnArgs s with
201-
| (`EmptyCollection.EmptyCollection, _) => pure (.zero (q(rfl) : Q((∅ : Multiset $α) = 0)))
202-
| (`Zero.zero, _) => pure (.zero (q(rfl) : Q((0 : Multiset $α) = 0)))
203-
| (`Multiset.cons, #[_, a, s']) => pure (.cons a s' (q(rfl) : Q($s = $s)))
204-
| (`Multiset.ofList, #[_, (val : Q(List $α))]) => do
205-
match ← List.proveNilOrCons val with
206-
| .nil pf => pure <| .zero (q($pf ▸ Multiset.coe_nil) : Q(($val : Multiset $α) = 0))
207-
| .cons a s' pf => do
208-
return (.cons a q($s')
209-
(q($pf ▸ Multiset.cons_coe $a $s') : Q(↑$val = Multiset.cons $a $s')))
210-
| (`Multiset.range, #[(n : Q(ℕ))]) => do
211-
let instAMO_nat : Q(AddMonoidWithOne ℕ) := q(AddCommMonoidWithOne.toAddMonoidWithOne)
212-
let ⟨nn, pn⟩ ← NormNum.deriveNat n
190+
partial def Multiset.proveZeroOrCons {α : Q(Type u)} (s : Q(Multiset $α)) :
191+
MetaM (Multiset.ProveZeroOrConsResult s) :=
192+
match s.getAppFnArgs with
193+
| (``EmptyCollection.emptyCollection, _) => haveI : $s =Q {} := ⟨⟩; pure (.zero q(rfl))
194+
| (``Zero.zero, _) => haveI : $s =Q 0 := ⟨⟩; pure (.zero q(rfl))
195+
| (``Multiset.cons, #[_, (a : Q($α)), (s' : Q(Multiset $α))]) =>
196+
haveI : $s =Q .cons $a $s' := ⟨⟩
197+
pure (.cons a s' q(rfl))
198+
| (``Multiset.ofList, #[_, (val : Q(List $α))]) => do
199+
haveI : $s =Q .ofList $val := ⟨⟩
200+
return match ← List.proveNilOrCons val with
201+
| .nil pf => .zero q($pf ▸ Multiset.coe_nil : Multiset.ofList _ = _)
202+
| .cons a s' pf => .cons a q($s') q($pf ▸ Multiset.cons_coe $a $s' : Multiset.ofList _ = _)
203+
| (``Multiset.range, #[(n : Q(ℕ))]) => do
204+
have s : Q(Multiset ℕ) := s; .uncheckedCast _ _ <$> show MetaM (ProveZeroOrConsResult s) from do
205+
let ⟨nn, pn⟩ ← NormNum.deriveNat n _
206+
haveI' : $s =Q .range $n := ⟨⟩
213207
let nnL := nn.natLit!
214208
if nnL = 0 then
215-
let pn : Q(@NormNum.IsNat _ _ $n 0) := pn
216-
return .zero (q(Multiset.range_zero' $pn) : Q(Multiset.range $n = 0))
209+
haveI' : $nn =Q 0 := ⟨⟩
210+
return .zero q(Multiset.range_zero' $pn)
217211
else
218212
have n' : Q(ℕ) := mkRawNatLit (nnL - 1)
219-
let pn' : Q($nn = Nat.succ $n') := (q(Eq.refl $nn) : Expr)
220-
return (Multiset.ProveZeroOrConsResult.cons
221-
n'
222-
q(Multiset.range $n')
223-
q(Multiset.range_succ' $pn $pn')).uncheckedCast (q(Multiset.range ($n)) : Q(Multiset ℕ)) s
213+
haveI' : $nn =Q ($n').succ := ⟨⟩
214+
return .cons _ _ q(Multiset.range_succ' $pn rfl)
224215
| (fn, args) =>
225216
throwError "Multiset.proveZeroOrCons: unsupported multiset expression {s} ({fn}, {args})"
226217

@@ -270,13 +261,14 @@ lemma Finset.univ_eq_elems {α : Type _} [Fintype α] (elems : Finset α)
270261
271262
Fails if we cannot determine which of the alternatives apply to the expression.
272263
-/
273-
partial def Finset.proveEmptyOrCons {α : Q(Type u)} :
274-
(s : Q(Finset $α)) → MetaM (Finset.ProveEmptyOrConsResult s) :=
275-
fun s =>
276-
match Expr.getAppFnArgs s with
277-
| (`EmptyCollection.emptyCollection, _) => pure (.empty (q(rfl) : Q($s = $s)))
278-
| (`Finset.cons, #[_, a, s', h]) => pure (.cons a s' h (q(rfl) : Q($s = $s)))
279-
| (`Finset.mk, #[_, (val : Q(Multiset $α)), (nd : Q(Multiset.Nodup $val))]) => do
264+
partial def Finset.proveEmptyOrCons {α : Q(Type u)} (s : Q(Finset $α)) :
265+
MetaM (ProveEmptyOrConsResult s) :=
266+
match s.getAppFnArgs with
267+
| (``EmptyCollection.emptyCollection, _) => haveI : $s =Q {} := ⟨⟩; pure (.empty q(rfl))
268+
| (``Finset.cons, #[_, (a : Q($α)), (s' : Q(Finset $α)), (h : Q(¬ $a ∈ $s'))]) =>
269+
haveI : $s =Q .cons $a $s' $h := ⟨⟩
270+
pure (.cons a s' h q(.refl $s))
271+
| (``Finset.mk, #[_, (val : Q(Multiset $α)), (nd : Q(Multiset.Nodup $val))]) => do
280272
match ← Multiset.proveZeroOrCons val with
281273
| .zero pf => pure <| .empty (q($pf ▸ Finset.mk_zero) : Q(Finset.mk $val $nd = ∅))
282274
| .cons a s' pf => do
@@ -285,29 +277,24 @@ partial def Finset.proveEmptyOrCons {α : Q(Type u)} :
285277
let h' : Q($a ∉ $s') := q((Multiset.nodup_cons.mp $h).1)
286278
return (.cons a q(Finset.mk $s' $nd') h'
287279
(q($pf ▸ Finset.mk_cons $h) : Q(Finset.mk $val $nd = Finset.cons $a ⟨$s', $nd'⟩ $h')))
288-
| (`Finset.range, #[(n : Q(ℕ))]) => do
289-
let instAMO_nat : Q(AddMonoidWithOne ℕ) := q(AddCommMonoidWithOne.toAddMonoidWithOne)
290-
let ⟨nn, pn⟩ ← NormNum.deriveNat n
280+
| (``Finset.range, #[(n : Q(ℕ))]) =>
281+
have s : Q(Finset ℕ) := s; .uncheckedCast _ _ <$> show MetaM (ProveEmptyOrConsResult s) from do
282+
let ⟨nn, pn⟩ ← NormNum.deriveNat n _
283+
haveI' : $s =Q .range $n := ⟨⟩
291284
let nnL := nn.natLit!
292285
if nnL = 0 then
293-
let pn : Q(@NormNum.IsNat _ _ $n 0) := pn
294-
return .empty (q(Finset.range_zero' $pn) : Q(Finset.range $n = {}))
286+
haveI : $nn =Q 0 := ⟨⟩
287+
return .empty q(Finset.range_zero' $pn)
295288
else
296289
have n' : Q(ℕ) := mkRawNatLit (nnL - 1)
297-
let pn' : Q($nn = Nat.succ $n') := (q(Eq.refl $nn) : Expr)
298-
return (Finset.ProveEmptyOrConsResult.cons
299-
n'
300-
(q(Finset.range $n'))
301-
(q(@Finset.not_mem_range_self $n'))
302-
(q(Finset.range_succ' $pn $pn'))).uncheckedCast
303-
(q(Finset.range $n) : Q(Finset ℕ))
304-
s
305-
| (`Finset.univ, #[_, instFT]) => do
306-
match Expr.getAppFnArgs (← whnfI instFT) with
307-
| (`Fintype.mk, #[_, (elems : Q(Finset $α)), (complete : Q(∀ x : $α, x ∈ $elems))]) => do
308-
have _instFT : Q(Fintype $α) := instFT
290+
haveI' : $nn =Q ($n').succ := ⟨⟩
291+
return .cons n' _ _ q(Finset.range_succ' $pn (.refl $nn))
292+
| (``Finset.univ, #[_, (instFT : Q(Fintype $α))]) => do
293+
haveI' : $s =Q .univ := ⟨⟩
294+
match (← whnfI instFT).getAppFnArgs with
295+
| (``Fintype.mk, #[_, (elems : Q(Finset $α)), (complete : Q(∀ x : $α, x ∈ $elems))]) => do
309296
let res ← Finset.proveEmptyOrCons elems
310-
pure <| res.eq_trans (q(Finset.univ_eq_elems $elems $complete) : Q(Finset.univ = $elems))
297+
pure <| res.eq_trans q(Finset.univ_eq_elems $elems $complete)
311298
| e =>
312299
throwError "Finset.proveEmptyOrCons: could not determine elements of Fintype instance {e}"
313300
| (fn, args) =>
@@ -374,7 +361,7 @@ partial def evalFinsetProd : NormNumExt where eval {u β} e := do
374361
have α : Q(Type v) := α
375362
have s : Q(Finset $α) := s
376363
have f : Q($α → $β) := f
377-
let instCS ← synthInstanceQ (q(CommSemiring $β) : Q(Type u)) <|>
364+
let instCS : Q(CommSemiring $β) ← synthInstanceQ q(CommSemiring $β) <|>
378365
throwError "not a commutative semiring: {β}"
379366
let instS : Q(Semiring $β) := q(CommSemiring.toSemiring)
380367
-- Have to construct this expression manually, `q(1)` doesn't parse correctly:
@@ -384,7 +371,7 @@ partial def evalFinsetProd : NormNumExt where eval {u β} e := do
384371

385372
evalFinsetBigop q(Finset.prod) f res_empty (fun {a s' h} res_fa res_prod_s' ↦ do
386373
let fa : Q($β) := Expr.app f a
387-
let res : Result _ ← evalMul.core q($fa * Finset.prod $s' $f) q((· * ·)) _ _ instS res_fa
374+
let res ← evalMul.core q($fa * Finset.prod $s' $f) q(HMul.hMul) _ _ instS res_fa
388375
res_prod_s'
389376
let eq : Q(Finset.prod (Finset.cons $a $s' $h) $f = $fa * Finset.prod $s' $f) :=
390377
q(Finset.prod_cons $h)
@@ -403,15 +390,15 @@ partial def evalFinsetSum : NormNumExt where eval {u β} e := do
403390
have α : Q(Type v) := α
404391
have s : Q(Finset $α) := s
405392
have f : Q($α → $β) := f
406-
let instCS ← synthInstanceQ (q(CommSemiring $β) : Q(Type u)) <|>
393+
let instCS : Q(CommSemiring $β) ← synthInstanceQ q(CommSemiring $β) <|>
407394
throwError "not a commutative semiring: {β}"
408-
let n : Q(ℕ) := q(0)
395+
let n : Q(ℕ) := mkRawNatLit 0
409396
let pf : Q(IsNat (Finset.sum ∅ $f) $n) := q(@Finset.sum_empty $β $α $instCS $f)
410397
let res_empty := Result.isNat _ n pf
411398

412399
evalFinsetBigop q(Finset.sum) f res_empty (fun {a s' h} res_fa res_sum_s' ↦ do
413400
let fa : Q($β) := Expr.app f a
414-
let res : Result _ ← evalAdd.core q($fa + Finset.sum $s' $f) q((· + ·)) _ _ res_fa res_sum_s'
401+
let res ← evalAdd.core q($fa + Finset.sum $s' $f) q(HAdd.hAdd) _ _ res_fa res_sum_s'
415402
let eq : Q(Finset.sum (Finset.cons $a $s' $h) $f = $fa + Finset.sum $s' $f) :=
416403
q(Finset.sum_cons $h)
417404
pure <| res.eq_trans eq)

Mathlib/Tactic/NormNum/GCD.lean

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,10 @@ def proveNatGCD (ex ey : Q(ℕ)) : (ed : Q(ℕ)) × Q(Nat.gcd $ex $ey = $ed) :=
9898
| x, y =>
9999
let (d, a, b) := Nat.xgcdAux x 1 0 y 0 1
100100
if d = x then
101-
have pq : Q(Nat.mod $ey $ex = 0) := (q(@Eq.refl Nat 0) : Expr)
101+
have pq : Q(Nat.mod $ey $ex = 0) := (q(Eq.refl (nat_lit 0)) : Expr)
102102
⟨ex, q(nat_gcd_helper_dvd_left $ex $ey $pq)⟩
103103
else if d = y then
104-
have pq : Q(Nat.mod $ex $ey = 0) := (q(@Eq.refl Nat 0) : Expr)
104+
have pq : Q(Nat.mod $ex $ey = 0) := (q(Eq.refl (nat_lit 0)) : Expr)
105105
⟨ey, q(nat_gcd_helper_dvd_right $ex $ey $pq)⟩
106106
else
107107
have ea' : Q(ℕ) := mkRawNatLit a.natAbs
@@ -115,8 +115,8 @@ def proveNatGCD (ex ey : Q(ℕ)) : (ed : Q(ℕ)) × Q(Nat.gcd $ex $ey = $ed) :=
115115
⟨mkRawNatLit 1, q(nat_gcd_helper_1' $ex $ey $ea' $eb' $pt)⟩
116116
else
117117
have ed : Q(ℕ) := mkRawNatLit d
118-
have pu : Q(Nat.mod $ex $ed = 0) := (q(@Eq.refl Nat 0) : Expr)
119-
have pv : Q(Nat.mod $ey $ed = 0) := (q(@Eq.refl Nat 0) : Expr)
118+
have pu : Q(Nat.mod $ex $ed = 0) := (q(Eq.refl (nat_lit 0)) : Expr)
119+
have pv : Q(Nat.mod $ey $ed = 0) := (q(Eq.refl (nat_lit 0)) : Expr)
120120
if a ≥ 0 then
121121
have pt : Q($ex * $ea' = $ey * $eb' + $ed) := (q(Eq.refl ($ex * $ea')) : Expr)
122122
⟨ed, q(nat_gcd_helper_2 $ed $ex $ey $ea' $eb' $pu $pv $pt)⟩
@@ -127,12 +127,13 @@ def proveNatGCD (ex ey : Q(ℕ)) : (ed : Q(ℕ)) × Q(Nat.gcd $ex $ey = $ed) :=
127127
@[norm_num Nat.gcd _ _]
128128
def evalNatGCD : NormNumExt where eval {u α} e := do
129129
let .app (.app _ (x : Q(ℕ))) (y : Q(ℕ)) ← Meta.whnfR e | failure
130+
haveI' : u =QL 0 := ⟨⟩; haveI' : $α =Q ℕ := ⟨⟩
131+
haveI' : $e =Q Nat.gcd $x $y := ⟨⟩
130132
let sℕ : Q(AddMonoidWithOne ℕ) := q(instAddMonoidWithOneNat)
131133
let ⟨ex, p⟩ ← deriveNat x sℕ
132134
let ⟨ey, q⟩ ← deriveNat y sℕ
133135
let ⟨ed, pf⟩ := proveNatGCD ex ey
134-
let pf' : Q(IsNat (Nat.gcd $x $y) $ed) := q(isNat_gcd $p $q $pf)
135-
return .isNat sℕ ed pf'
136+
return .isNat sℕ ed q(isNat_gcd $p $q $pf)
136137

137138
/-- Given natural number literals `ex` and `ey`, return their LCM as a natural number literal
138139
and an equality proof. Panics if `ex` or `ey` aren't natural number literals. -/
@@ -155,12 +156,13 @@ def proveNatLCM (ex ey : Q(ℕ)) : (ed : Q(ℕ)) × Q(Nat.lcm $ex $ey = $ed) :=
155156
@[norm_num Nat.lcm _ _]
156157
def evalNatLCM : NormNumExt where eval {u α} e := do
157158
let .app (.app _ (x : Q(ℕ))) (y : Q(ℕ)) ← Meta.whnfR e | failure
159+
haveI' : u =QL 0 := ⟨⟩; haveI' : $α =Q ℕ := ⟨⟩
160+
haveI' : $e =Q Nat.lcm $x $y := ⟨⟩
158161
let sℕ : Q(AddMonoidWithOne ℕ) := q(instAddMonoidWithOneNat)
159162
let ⟨ex, p⟩ ← deriveNat x sℕ
160163
let ⟨ey, q⟩ ← deriveNat y sℕ
161164
let ⟨ed, pf⟩ := proveNatLCM ex ey
162-
let pf' : Q(IsNat (Nat.lcm $x $y) $ed) := q(isNat_lcm $p $q $pf)
163-
return .isNat sℕ ed pf'
165+
return .isNat sℕ ed q(isNat_lcm $p $q $pf)
164166

165167
/-- Given two integers, return their GCD and an equality proof.
166168
Panics if `ex` or `ey` aren't integer literals. -/
@@ -174,14 +176,12 @@ def proveIntGCD (ex ey : Q(ℤ)) : (ed : Q(ℕ)) × Q(Int.gcd $ex $ey = $ed) :=
174176
@[norm_num Int.gcd _ _]
175177
def evalIntGCD : NormNumExt where eval {u α} e := do
176178
let .app (.app _ (x : Q(ℤ))) (y : Q(ℤ)) ← Meta.whnfR e | failure
177-
let sℕ : Q(AddMonoidWithOne ℕ) := q(instAddMonoidWithOneNat)
178-
let sℤ : Q(Ring ℤ) := q(Int.instRingInt)
179-
let ⟨ex, p⟩ ← deriveInt x
180-
let ⟨ey, q⟩ ← deriveInt y
179+
let ⟨ex, p⟩ ← deriveInt x _
180+
let ⟨ey, q⟩ ← deriveInt y _
181+
haveI' : u =QL 0 := ⟨⟩; haveI' : $α =Q ℕ := ⟨⟩
182+
haveI' : $e =Q Int.gcd $x $y := ⟨⟩
181183
let ⟨ed, pf⟩ := proveIntGCD ex ey
182-
have pf : Q(Int.gcd $ex $ey = $ed) := pf
183-
have pf' : Q(IsNat (Int.gcd $x $y) $ed) := q(isInt_gcd $p $q $pf)
184-
return .isNat sℕ ed pf'
184+
return .isNat _ ed q(isInt_gcd $p $q $pf)
185185

186186
/-- Given two integers, return their LCM and an equality proof.
187187
Panics if `ex` or `ey` aren't integer literals. -/
@@ -195,14 +195,12 @@ def proveIntLCM (ex ey : Q(ℤ)) : (ed : Q(ℕ)) × Q(Int.lcm $ex $ey = $ed) :=
195195
@[norm_num Int.lcm _ _]
196196
def evalIntLCM : NormNumExt where eval {u α} e := do
197197
let .app (.app _ (x : Q(ℤ))) (y : Q(ℤ)) ← Meta.whnfR e | failure
198-
let sℕ : Q(AddMonoidWithOne ℕ) := q(instAddMonoidWithOneNat)
199-
let sℤ : Q(Ring ℤ) := q(Int.instRingInt)
200-
let ⟨ex, p⟩ ← deriveInt x
201-
let ⟨ey, q⟩ ← deriveInt y
198+
let ⟨ex, p⟩ ← deriveInt x _
199+
let ⟨ey, q⟩ ← deriveInt y _
200+
haveI' : u =QL 0 := ⟨⟩; haveI' : $α =Q ℕ := ⟨⟩
201+
haveI' : $e =Q Int.lcm $x $y := ⟨⟩
202202
let ⟨ed, pf⟩ := proveIntLCM ex ey
203-
have pf : Q(Int.lcm $ex $ey = $ed) := pf
204-
have pf' : Q(IsNat (Int.lcm $x $y) $ed) := q(isInt_lcm $p $q $pf)
205-
return .isNat sℕ ed pf'
203+
return .isNat _ ed q(isInt_lcm $p $q $pf)
206204

207205
end NormNum
208206

Mathlib/Tactic/NormNum/IsCoprime.lean

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,8 @@ def proveIntIsCoprime (ex ey : Q(ℤ)) : Q(IsCoprime $ex $ey) ⊕ Q(¬ IsCoprime
4848
@[norm_num IsCoprime (_ : ℤ) (_ : ℤ)]
4949
def evalIntIsCoprime : NormNumExt where eval {u α} e := do
5050
let .app (.app _ (x : Q(ℤ))) (y : Q(ℤ)) ← Meta.whnfR e | failure
51-
let sℤ : Q(Ring ℤ) := q(Int.instRingInt)
52-
let ⟨ex, p⟩ ← deriveInt x
53-
let ⟨ey, q⟩ ← deriveInt y
51+
let ⟨ex, p⟩ ← deriveInt x _
52+
let ⟨ey, q⟩ ← deriveInt y _
5453
match proveIntIsCoprime ex ey with
5554
| .inl pf =>
5655
have pf' : Q(IsCoprime $x $y) := q(isInt_isCoprime $p $q $pf)

0 commit comments

Comments
 (0)