Zulip Chat Archive

Stream: mathlib4

Topic: !4#2773 type mismatch


Jeremy Tan (Mar 10 2023 at 07:59):

!4#2773 I can't understand why refine' mul_dvd_mul _ ih in Lean 4 generates a type mismatch error but mathlib 3 refine mul_dvd_mul _ ih doesn't

Eric Wieser (Mar 10 2023 at 09:01):

Looks like a change in a lemma statement

Eric Wieser (Mar 10 2023 at 09:02):

The error is

has type
  ?m.2582 * (p ^ (k + 1))  ?m.2583 * (a ^ p ^ k - b ^ p ^ k) : Prop
but is expected to have type
  (p * p ^ (k + 1))  ...

Eric Wieser (Mar 10 2023 at 09:02):

Note the arrows are in different places

Eric Wieser (Mar 10 2023 at 09:02):

You should open the lean3 and work out where they are supposed to be

Eric Wieser (Mar 10 2023 at 09:02):

And track down where the proof diverges

Jeremy Tan (Mar 10 2023 at 09:39):

using the lean web editor I find that

  • in mathlib3, after the last pow_succ in rw [pow_succ' p k, pow_mul, pow_mul, ← geom_sum₂_mul, pow_succ] the coercion distributes and the term ↑p * ↑p ^ k.succ appears
  • but in mathlib4 at the same place the coercion doesn't distribute and ↑(p * p ^ (k + 1)) remains

Jeremy Tan (Mar 10 2023 at 09:41):

I need a way to distribute the coercion

Jeremy Tan (Mar 10 2023 at 10:33):

but as I have only barely scratched the surface of mathlib I don't know how to look for suitable rewriting theorems

Floris van Doorn (Mar 10 2023 at 10:48):

The norm_cast tactic is useful when having do move coercions around.

Jeremy Tan (Mar 10 2023 at 11:21):

Nat.mul_cast worked, but now I'm getting a whnf heartbeat error

Jeremy Tan (Mar 10 2023 at 11:22):

I pushed a partial fix. Now in the proof at

rw [ mem_span_singleton,  eq_zero_iff_mem, RingHom.map_geom_sum₂, RingHom.map_pow,
    RingHom.map_pow, h, geom_sum₂_self, hp, zero_mul]

when Lean tries to rewrite using h it reaches the max number of heartbeats

Jeremy Tan (Mar 10 2023 at 11:24):

just before rw [... h] the goal state is

 (Finset.sum (Finset.range p) fun i => ((mk (span {p})) a ^ p ^ k) ^ i * ((mk (span {p})) b ^ p ^ k) ^ (p - 1 - i)) =

and I have h: ↑(mk (span {↑p})) a = ↑(mk (span {↑p})) b

Jeremy Tan (Mar 10 2023 at 11:30):

the comment at !4#2757 should solve it though:

For instance, in a statement of an equality a = b... The solution in that case was to provide a type ascription to a to avoid the metavariables.

how would that be done in this case?

Jeremy Tan (Mar 11 2023 at 00:51):

@Jireh Loreaux how do I apply a type ascription here to solve the heartbeat problem without setting max heartbeats?

Jireh Loreaux (Mar 11 2023 at 01:27):

The issue I described there may not be the same thing occurring here.

Jireh Loreaux (Mar 11 2023 at 01:28):

In fact I doubt it is.

Jeremy Tan (Mar 11 2023 at 01:29):

should I just apply the max heartbeat adjustment suggested on the PR or is there a better way out?

Jireh Loreaux (Mar 11 2023 at 01:32):

There are generally other workarounds when dealing with lean4#2074. You can grep mathlib for 2074 to find some.

Jireh Loreaux (Mar 11 2023 at 01:35):

If you want to see if it is caused by 2074, you can do set_option synthInstance.etaExperiment true before the declaration. If that doesn't fix it then it's probably not 2074.

Jeremy Tan (Mar 11 2023 at 01:36):

like this?

set_option synthInstance.etaExperiment true
theorem ...

Jeremy Tan (Mar 11 2023 at 01:37):

but it doesn't seem to change anything

Jireh Loreaux (Mar 11 2023 at 01:39):

Okay, in that case I would move on to something else for now and come back to it. I don't have time to actually pull it up right now.

Jeremy Tan (Mar 11 2023 at 01:46):

I've adopted the heartbeat fix for now

Jireh Loreaux (Mar 11 2023 at 02:02):

Please add a porting note so it doesn't get merged that way.

Jeremy Tan (Mar 11 2023 at 02:05):

@Jireh Loreaux Note added. Now what?

Jireh Loreaux (Mar 11 2023 at 02:06):

If there are no other things to be done for the PR, just wait. If there are, keep fixing other things.

Jeremy Tan (Mar 11 2023 at 13:37):

@Johan Commelin I don't get what the two instances are

Johan Commelin (Mar 11 2023 at 13:40):

Did you search for "2074"?

Jeremy Tan (Mar 11 2023 at 13:40):

hold on

Johan Commelin (Mar 11 2023 at 13:40):

You will find things like

-- Porting note: TODO: workaround for lean4#2074
attribute [-instance] Ring.toNonAssocRing

Jeremy Tan (Mar 11 2023 at 13:43):

what does that line do?

Johan Commelin (Mar 11 2023 at 13:44):

It disables that instance, so that typeclass resolution can't use it.

Jeremy Tan (Mar 11 2023 at 13:45):

adding the two lines

attribute [-instance] Semiring.toNonAssocSemiring
attribute [-instance] NonAssocRing.toNonAssocSemiring

together (and only together) work, but then I get another error where I introduced Nat.cast_mul

  • adding just one of the two lines still leads to heartbeat error

Johan Commelin (Mar 11 2023 at 13:46):

What kind of error?

Jeremy Tan (Mar 11 2023 at 13:47):

rewrite just fails; ↑(p * p ^ (k + 1)) is there where Nat.cast_mul expects ↑(m * n) = ↑m * ↑n

Jeremy Tan (Mar 11 2023 at 13:47):

in the code with the heartbeat expansion this rewrite went through, allowing mul_dvd_mul on the next line to work

Johan Commelin (Mar 11 2023 at 13:48):

Can you try

erw [Nat.cast_mul]

on a line on its own? (So remove it from the current rw)

Jeremy Tan (Mar 11 2023 at 13:48):

still fails

Johan Commelin (Mar 11 2023 at 13:48):

Crazy

Johan Commelin (Mar 11 2023 at 13:49):

I'll load it up in VScode

Jeremy Tan (Mar 11 2023 at 13:49):

(the code with the disabled instances has been pushed in place of the heartbeat expansion, by the way)

Johan Commelin (Mar 11 2023 at 13:51):

ok, I'll pull again

Jeremy Tan (Mar 11 2023 at 13:53):

Watching bors stage, compile and commit the approved PRs is almost hypnotic

Johan Commelin (Mar 11 2023 at 14:13):

The problem seems to be the rw [h] on the last line. But I don't understand why.

Jeremy Tan (Mar 11 2023 at 14:15):

I had a discussion with Jireh earlier in this narrow and he asked me to perform the eta-experiment. We determined that this was probably not a 2074 issue

Jeremy Tan (Mar 11 2023 at 14:15):

If you want to see if it is caused by 2074, you can do set_option synthInstance.etaExperiment true before the declaration. If that doesn't fix it then it's probably not 2074.

Jeremy Tan (Mar 11 2023 at 14:17):

Which was why I simply opted for the heartbeat expansion suggested by Lukas

Johan Commelin (Mar 11 2023 at 14:22):

I pushed a fix and golf

Jeremy Tan (Mar 11 2023 at 14:23):

hmm... this may contain a lot for me to learn

Johan Commelin (Mar 11 2023 at 14:23):

Yeah, I think that besides 2074, there might be some orthogonal issue with quotients. But I don't understand the details.

Jireh Loreaux (Mar 11 2023 at 14:41):

I've ported a few quotient files and they have been a royal pain.


Last updated: Dec 20 2023 at 11:08 UTC