Zulip Chat Archive

Stream: mathlib4

Topic: IsTrans


Yury G. Kudryashov (Jan 12 2023 at 06:49):

Should we migrate from IsTrans to Trans?

Yury G. Kudryashov (Jan 12 2023 at 06:50):

E.g., by using

abbreviation IsTrans α r := Trans r r r

Yury G. Kudryashov (Jan 12 2023 at 08:18):

Trans is used, e.g., by calc and tactic trans

Yury G. Kudryashov (Jan 12 2023 at 08:26):

With this definition Lean fails to extend IsTrans α r saying that it's not a class.

Yury G. Kudryashov (Jan 12 2023 at 08:26):

@Gabriel Ebner What should I do?

Yury G. Kudryashov (Jan 12 2023 at 08:27):

Make it class IsTrans α r extends Trans r r r and add a loop instance [IsTrans α r] : Trans r r r?

Yury G. Kudryashov (Jan 12 2023 at 08:27):

Or something else?

Yury G. Kudryashov (Jan 12 2023 at 20:33):

@Mario Carneiro @Gabriel Ebner :up:

Gabriel Ebner (Jan 13 2023 at 00:19):

I think there's class abbrev IsTrans α r := Trans r r r.

Yury G. Kudryashov (Jan 13 2023 at 03:44):

It seems that Trans is not in Prop.

Yury G. Kudryashov (Jan 13 2023 at 03:46):

So, I see 2 options.

  • Add an instance [IsTrans α r] : Trans r r r and a linter that bans other Trans r r r instances.
  • Add both instances [IsTrans α r] : Trans r r r and [Trans r r r] : IsTrans α r and hope that Lean 4 is good with instance loops.

Gabriel Ebner (Jan 13 2023 at 04:13):

Lean 4 is good with this kind of instance loop.

Yury G. Kudryashov (Jan 13 2023 at 04:13):

Related issue: since calc doesn't unfold Trans instances, an Equiv defined using calc uses Trans.trans, not Equiv.trans.

Gabriel Ebner (Jan 13 2023 at 04:15):

Ah, I don't think much thought has gone into non-Prop Trans instances.

Yury G. Kudryashov (Jan 13 2023 at 04:15):

While the results are defeq, simp doesn't work on the result.

Yury G. Kudryashov (Jan 13 2023 at 04:16):

Of course, we can drop Equiv.trans and use Trans.trans instead.

Yury G. Kudryashov (Jan 13 2023 at 04:16):

But this way we can't use dot notation.

Yury G. Kudryashov (Jan 13 2023 at 04:18):

One more question: can we unexport Trans.trans? In many cases, our _root_.trans is more useful.

Yury G. Kudryashov (Jan 13 2023 at 05:06):

I understand that Trans.trans is more general but in many cases it's not useful outside of calc. E.g., we can't write apply Trans.trans h and expect Lean to figure out the type of the second argument.

Yury G. Kudryashov (Jan 13 2023 at 05:18):

I added instances IsTrans α r → Trans r r r and Trans r r r → IsTrans α r, and now I have to add _root_ here and there.

Yury G. Kudryashov (Jan 13 2023 at 05:29):

These collisions are new because without these instances, one of two trans did not apply.

Yury G. Kudryashov (Jan 13 2023 at 09:30):

BTW, am I right that Lean 4 calc can't handle https://leanprover-community.github.io/mathlib4_docs/Mathlib/Algebra/Hom/Equiv/Basic.html#MulEquiv.trans?

Yury G. Kudryashov (Jan 13 2023 at 09:36):

The only class-based solution that I can think of is

class Trans (α β : Sort _) (γ : outParam (Sort _)) where
  trans : α  β  γ

with instances like

instance [Preorder α] {a b c : α} : Trans (a  b) (b  c) (a  c) :=
  le_trans

instance [Mul M] [Mul N] [Mul P] : Trans (M ≃* N) (N ≃* P) (M ≃* P) :=
  MulEquiv.trans

Yury G. Kudryashov (Jan 15 2023 at 21:07):

@Gabriel Ebner @Mario Carneiro Who is the right person to talk about calc support for MulEquiv etc?

Mario Carneiro (Jan 15 2023 at 21:08):

It's a core PR, but I don't think it has any special prerequisites

Mario Carneiro (Jan 15 2023 at 21:09):

but you should be aware that @Adrien Champion 's PR might affect how calc works because it needs the ability to add a refl step at the beginning

Mario Carneiro (Jan 15 2023 at 21:10):

(I wouldn't mind if we found another way to do it though)

Mario Carneiro (Jan 15 2023 at 21:11):

the issue is that the new syntax has an (optional) extra LHS term at the beginning which we have to fit into the inequality chain

Yury G. Kudryashov (Jan 15 2023 at 21:11):

I wanted to discuss what should be done before trying to do something.

Yury G. Kudryashov (Jan 15 2023 at 21:12):

Where can I read about the new syntax?

Mario Carneiro (Jan 15 2023 at 21:12):

Also, that more general instance will have problems with the Trans Eq R R and Trans R Eq R instances

Mario Carneiro (Jan 15 2023 at 21:13):

https://leanprover.zulipchat.com/#narrow/stream/270676-lean4/topic/.60calc.60.20indentation

Yury G. Kudryashov (Jan 15 2023 at 21:16):

We can have general instances Trans (a = b) (R b c) (R a b) and Trans (R a b) (b = c) (R a c). For MulEquivs etc, we can't have M = N → N ≃* P → M ≃* P anyway because the first equality says nothing about [Mul M] and [Mul N].


Last updated: Dec 20 2023 at 11:08 UTC