Zulip Chat Archive

Stream: mathlib4

Topic: !4#2046 to_additive trouble


Eric Wieser (Feb 07 2023 at 15:34):

to_additive doesn't seem to like the use of the equation compiler in !4#2046 (a forward-port). Is this a problem we already know about?

Eric Wieser (Feb 07 2023 at 15:34):

The error there is on these lines, and is

./././Mathlib/Algebra/GroupPower/Order.lean:168:2: error: application type mismatch
  motive 0 x
argument has type
  1  0
but function has type
  0  0  Prop

Eric Wieser (Feb 07 2023 at 15:39):

Replacing 1 in the match with Nat.succ 0 seems to fix it

Eric Wieser (Feb 07 2023 at 15:42):

mwe:

import Mathlib.Algebra.Group.Basic

-- fails
@[to_additive]
def mul_foo {α} [Monoid α] (a : α) :   α
| 0 => 1
| 1 => 1
| (n + 2) => a

-- ok
@[to_additive]
def mul_bar {α} [Monoid α] (a : α) :   α
| 0 => 1
| (Nat.succ 0) => 1
| (n + 2) => a

Floris van Doorn (Feb 07 2023 at 17:10):

This one is indeed new.

The problem is that the elaborated term contains motive 1, where 1 is a pure natural number literal, not within a ofNat application (which the elaborator inserts in all other cases we've encountered so far).
This means we do not know what type this literal is supposed to be in.
I'll try to add the rule that a variable applied to a literal should never be changed. Hopefully that will not break other cases.

Eric Wieser (Feb 07 2023 at 17:42):

Could this be an elaboration bug?

Floris van Doorn (Feb 07 2023 at 20:05):

I expect this is intended behavior. But the fix is easy !4#2153 and seems to have no bad side-effects


Last updated: Dec 20 2023 at 11:08 UTC