Zulip Chat Archive
Stream: general
Topic: rewriter oddity
Chris B (Jul 02 2020 at 05:46):
I ran into this while showing someone the natural numbers game; am I wrong in thinking one (or all) of these should succeed? Both the rewrites fail, and so does library_search
. The version of pow_zero
in core works, as does the one in NNG. I'm on mathlib cd29ede, lean 3.16.5c
example (a b : nat) : a * (b ^ 0) = a := by library_search
example (a b : nat) : a * (b ^ 0) = (a * 1) := by library_search
example (a b : nat) : a * (b ^ 0) = a :=
begin
intros,
rw pow_zero,
sorry
end
example (a b : nat) : a * (b ^ 0) = a :=
begin
intros,
rw pow_zero b,
sorry
end
Shing Tak Lam (Jul 02 2020 at 05:54):
wrt. the rewrites, I think you need nat.pow_zero
, not pow_zero
.
Bryan Gin-ge Chen (Jul 02 2020 at 06:10):
Here's the first error message if you have set_option pp.notation false
and set_option pp.implicit true
:
rewrite tactic failed, did not find instance of the pattern in the target expression
@pow nat nat (@monoid.has_pow nat nat.monoid) b 0
state:
a b : nat
⊢ @eq nat (@has_mul.mul nat nat.has_mul a (@pow nat nat nat.has_pow b 0)) a
So Lean is having trouble unifying @pow nat nat (@monoid.has_pow nat nat.monoid) b 0
(required by src#pow_zero, in algebra.group_power
) with @pow nat nat nat.has_pow b 0
, whereas src#nat.pow_zero (in core) works.
Chris B (Jul 02 2020 at 06:32):
Thank you both. The type of pow_zero
says it's generic over instances of monoid
and #print instances monoid
shows that there's a nat.monoid
in the environment. I don't really know anything about how lean handles typeclass instances internally, but am I wrong to think that src#pow_zero should succeed here?
Mario Carneiro (Jul 02 2020 at 06:55):
it should not succeed
Mario Carneiro (Jul 02 2020 at 06:55):
the problem is that there are two power functions, monoid.pow
and nat.pow
, and they look the same
Mario Carneiro (Jul 02 2020 at 06:56):
if you use power on nats you get nat.pow
, otherwise you get monoid.pow
Mario Carneiro (Jul 02 2020 at 06:56):
and only the nat.pow_*
theorems work on nat.pow
unless you first rewrite with nat.pow_eq_pow
Kevin Buzzard (Jul 02 2020 at 06:59):
This is something which could be fixed but which would just be painful to fix, right?
Chris B (Jul 02 2020 at 07:13):
Wow, what a bummer. Is that kind of overloading common in mathlib?
Chris B (Jul 02 2020 at 07:13):
Thanks for the explanation though.
Johan Commelin (Jul 02 2020 at 07:18):
Chris B said:
Wow, what a bummer. Is that kind of overloading common in mathlib?
No, this issue with nat.pow
is sort of unique. At some point we'll have the courage to fix it.
Kevin Buzzard (Jul 02 2020 at 07:22):
When the number of people reporting it every month on Zulip becomes too much to bear :-)
Kevin Buzzard (Jul 02 2020 at 07:22):
Is nat.pow still in core?
Mario Carneiro (Jul 02 2020 at 07:24):
The issue with nat.pow
is also similar to coe : nat -> int
vs coe : nat -> A
Mario Carneiro (Jul 02 2020 at 07:24):
It is in core. Did we determine that it had a GMP implementation in C++?
Johan Commelin (Jul 02 2020 at 07:25):
Yes, I think it does
Mario Carneiro (Jul 02 2020 at 07:27):
it doesn't
Mario Carneiro (Jul 02 2020 at 07:28):
but gcd does? crazy
Kevin Buzzard (Jul 02 2020 at 07:28):
The coe issue burnt @Ashvni Narayanan only yesterday, with maps from nat to int to with_top int
Johan Commelin (Jul 02 2020 at 07:28):
Mario Carneiro said:
it doesn't
Then we should give it one, right?
Mario Carneiro (Jul 02 2020 at 07:29):
looks pretty easy
Johan Commelin (Jul 02 2020 at 07:29):
If you speak GMP
Ashvni Narayanan (Jul 02 2020 at 12:05):
Kevin Buzzard said:
The coe issue burnt Ashvni Narayanan only yesterday, with maps from nat to int to with_top int
Yeah, I was trying to show
lemma val_int_power (a : K) (nz : a ≠ 0) : ∀ n : ℤ, v(a^n) = (n : with_top ℤ)*v(a) :=
for a discrete valuation field K. Finally used this
lemma with_top.sub_add_eq_zero (n : ℕ) : ((-n : ℤ) : with_top ℤ) + (n : with_top ℤ) = 0 :=
so it worked out okay.
Last updated: Dec 20 2023 at 11:08 UTC