Zulip Chat Archive
Stream: mathlib4
Topic: calc for group isos
Kevin Buzzard (May 17 2023 at 20:09):
I was rubbish at calc
in Lean 3 for years and right now I feel the same about Lean 4 calc
. Should this work?
import Mathlib.GroupTheory.QuotientGroup
example (A B C : Type) [Group A] [Group B] [Group C] (hAB : A ≃* B) (hBC : B ≃* C) : A ≃* C := by calc
A ≃* B := hAB
_ ≃* C := hBC
because right now I get two errors:
scratch3.lean:6:2
invalid 'calc' step, left-hand-side is
Type ?u.1742 : Type (?u.1742 + 1)
previous right-hand-side is
MulOneClass.toMul : Mul B
scratch3.lean:4:98
application type mismatch
MulEquiv ?m.1744
argument
?m.1744
has type
Mul B : Type
but is expected to have type
Type ?u.1742 : Type (?u.1742 + 1)
Eric Wieser (May 17 2023 at 22:07):
This probably needs a Trans
instance
Eric Wieser (May 17 2023 at 22:07):
Kevin Buzzard (May 17 2023 at 22:14):
How do I insert [Mul A]
into the Trans
machinery?
Eric Wieser (May 17 2023 at 22:20):
I think it's getting confused, and the answer is you don't? Just insert MulEquiv into it
Eric Wieser (May 17 2023 at 22:20):
Eric Wieser (May 17 2023 at 22:21):
Uh oh, this looks impossible
Eric Wieser (May 17 2023 at 22:25):
Trans (@MulEquiv A B) (@MulEquiv B C) (@MulEquiv A C)
maybe?
Kevin Buzzard (May 17 2023 at 22:32):
import Mathlib.GroupTheory.QuotientGroup
instance : Trans (@MulEquiv A B) (@MulEquiv B C) (@MulEquiv A C) where
trans := MulEquiv.trans
example (A B C : Type) [Group A] [Group B] [Group C] (hAB : A ≃* B) (hBC : B ≃* C) : A ≃* C := by calc
A ≃* B := hAB
_ ≃* C := hBC
/-
scratch4.lean:8:2
invalid 'calc' step, left-hand-side is
Type ?u.2425 : Type (?u.2425 + 1)
previous right-hand-side is
MulOneClass.toMul : Mul B
scratch4.lean:6:98
application type mismatch
MulEquiv ?m.2427
argument
?m.2427
has type
Mul B : Type
but is expected to have type
Type ?u.2425 : Type (?u.2425 + 1)
-/
It looks like a parsing error to me?
Eric Wieser (May 17 2023 at 22:37):
Can you turn on pp.explicit?
Eric Wieser (May 17 2023 at 22:38):
I think though this an indication that it's doomed after all
Kevin Buzzard (May 17 2023 at 22:39):
Well I only wanted it for that other thread and it looks like you've found a better solution anyway ;-)
invalid 'calc' step, left-hand-side is
Type ?u.2425 : Type (?u.2425 + 1)
previous right-hand-side is
@MulOneClass.toMul B (@Monoid.toMulOneClass B (@DivInvMonoid.toMonoid B (@Group.toDivInvMonoid B inst✝¹))) : Mul B
This is on _ ≃* C
Kevin Buzzard (May 17 2023 at 22:39):
I think it's parsing A ≃* B
as (A) (≃) (* B)
maybe?
Eric Wieser (May 17 2023 at 22:40):
I don't think that's it
Kevin Buzzard (May 17 2023 at 22:40):
It can't be because that doesn't even typecheck
Eric Wieser (May 17 2023 at 22:40):
I think it needs A and B to be the last arguments of the relation
Eric Wieser (May 17 2023 at 22:40):
But they're not, the Mul A and Mul B arguments are
Eric Wieser (May 17 2023 at 22:41):
This worked in lean 3, though possibly only the community version
Eric Wieser (May 17 2023 at 22:45):
Basically any typeclass that expects something of the form α → Sort*
as an argument becomes useless when you have side conditions like "α is a group" or "equality on α is decidable"
Eric Wieser (May 17 2023 at 22:47):
(another example is not being able to use the monad typeclasses for computable finsets)
Kevin Buzzard (May 17 2023 at 22:48):
Yeah, one error goes away if I add instance : ∀ (G : Type _), Mul G := sorry
, but this is probably not a good instance for mathlib...
Eric Wieser (May 17 2023 at 22:48):
Working with category theory isos should also solve the problem, as there the typeclass is bundled
Eric Wieser (May 17 2023 at 22:49):
But I think it would be better to fix calc...
Kevin Buzzard (May 17 2023 at 22:49):
I'll open an issue but I guess it's low-priority?
Eric Wieser (May 17 2023 at 22:50):
It might be worth checking if mathlib ever uses calc in this way, and that I'm not hallucinating that it used to work in lean 3
Kevin Buzzard (May 17 2023 at 22:52):
Huh,
type mismatch at application
mul_equiv.trans
term
A
has type
Type : Type 1
but is expected to have type
has_mul ?m_1 : Type ?
Eric Wieser (May 17 2023 at 22:54):
Lol, guess I imagined it
Kevin Buzzard (May 17 2023 at 22:54):
Works fine with regular equivs in lean 3 (and this is used)
Kevin Buzzard (May 17 2023 at 22:55):
I don't know how to search for a calc block with mul_equiv in (or indeed any equiv other than unadorned equiv)
Kevin Buzzard (May 17 2023 at 22:55):
calc.*≃
in regex mode is good enough to find examples though (with calc on the same line as the first iso) (and none are adorned)
Eric Wieser (May 17 2023 at 22:58):
Kevin Buzzard said:
Works fine with regular equivs in lean 3 (and this is used)
This works in lean 4 too
Kevin Buzzard (May 17 2023 at 23:08):
lean4#2217 . Thanks for the help.
Last updated: Dec 20 2023 at 11:08 UTC