You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
to_additive unable to translate toOneHomClass #660
is removed, the to_additive tactic seems to be looking for AddMonoidHomClass.toOneHomClass, when it should look for AddMonoidHomClass.toZeroHomClass. It has no trouble translating OneHomClass to ZeroHomClass, but has trouble with toOneHomClass.
-- [todo] run to_additive on the constructors of n:
-- aux (fun n => (env.constructorsOf n).mmap $ ...
MWE to reproduce error
-- First, all the additive versions
class ZeroA (A : Type _) where
zero : ℕ
zero_add : zero + zero = zero
class ZeroB (A : Type _) extends ZeroA A where
zero_sub : zero - zero = 0
class ZeroC (A : Type _) extends ZeroA A where
zero_refl : zero = zero
class ZeroD (A : Type _) extends ZeroB A, ZeroC A
-- Now all the multiplicative versions
@[to_additive]
class OneA (A : Type _) where
one : ℕ
one_mul : one * one = one
@[to_additive]
class OneB (A : Type _) extends OneA A where
one_sub : one - one = 0
@[to_additive]
class OneC (A : Type _) extends OneA A where
one_refl : one = one
@[to_additive]
class OneD (A : Type _) extends OneB A, OneC A
-- check `to_additive` deals properly with all extensions.
@[to_additive]
lemma one_mul_test_one {A : Type _} [x : OneD A] : true := by
have := x.toOneA
have := x.toOneC
have := x.toOneB
trivial
That todo is not quite the right one. It is for translating constructors, like AddMonoidHomClass.mk. However, this is not actually necessary: the implementation will do fine without these translations.
@digama0: Am I correct that the environment does not contain information about which structures a given structure extends? What is the best way forward? The @[ancestor] hack from Lean 3? Make a Core PR that records this information?
When I removed the ancestor attribute from mathport, my understanding was that this information either already exists or would be stored by lean to avoid the need for duplicating the information. (That said I haven't looked at it in detail and a core PR may be needed.)
Activity
joneugster commentedon Nov 20, 2022
I'll look into that tonight :)
joneugster commentedon Nov 20, 2022
Looks like
to_additivealways has problems if a class extends 2+ other classes. The relevant TODO is this here:mathlib4/Mathlib/Tactic/ToAdditive.lean
Lines 590 to 600 in 085e7ab
MWE to reproduce error
Error:
(kernel) unknown constant 'Test.ZeroD.toOneC'(Because it fails to translate
OneD.toOneCtoZeroD.toZeroC)Unfortunately I don't know how to fix this just now, maybe somebody else does.
fpvandoorn commentedon Nov 23, 2022
That todo is not quite the right one. It is for translating constructors, like
AddMonoidHomClass.mk. However, this is not actually necessary: the implementation will do fine without these translations.@digama0: Am I correct that the environment does not contain information about which structures a given structure
extends? What is the best way forward? The@[ancestor]hack from Lean 3? Make a Core PR that records this information?digama0 commentedon Nov 23, 2022
When I removed the
ancestorattribute from mathport, my understanding was that this information either already exists or would be stored by lean to avoid the need for duplicating the information. (That said I haven't looked at it in detail and a core PR may be needed.)fpvandoorn commentedon Nov 24, 2022
I created a RFC for a core PR at leanprover/lean4#1881
feat: better name guessing for to_additive (#779)
feat: better name guessing for to_additive (#779)
feat: better name guessing for to_additive (#779)
eric-wieser commentedon Apr 3, 2023
This has come up again in #3171; it would be great to revisit it.
fix(to_additive): automatically translate all instances generated by …