mathlib icon indicating copy to clipboard operation
mathlib copied to clipboard

Tactic to transfer theorems / definitions using an equivalence.

Open urkud opened this issue 5 years ago • 9 comments

It would be nice to have a tactic that can transfer definitions and / or theorems through equivalences. E.g., all theorems in the upper half of data/equiv/algebra should be by equiv_transfer e.

In its simplest form it should assume that there is no structure on the target type, and transfer everything from the source type. I.e., it should analyze the requested type, and substitute e, e.symm, e.apply_symm_apply and e.symm_apply_apply as needed.

A more advanced version should be able to work with a target type that already has some structure but this structure agrees with that on the source type (e.g., e (a * b) = e a * e b), and the lemmas that prove these equalities either have predictable names, or are given as arguments to the tactic.

With the second type of tactic, it would be easy to define new types that are mathematically equivalent to old ones but provide better performance (more precisely, to prove theorems about these types).

urkud avatar Jan 08 '20 15:01 urkud

Related: #408

jcommelin avatar Jan 08 '20 15:01 jcommelin

Also related: @CohenCyril spent a couple of intense weeks on the problem (his repo). It is not an easy problem and we'll have to be patient.

cipher1024 avatar Jan 08 '20 17:01 cipher1024

Since I didn't see this mentioned either here or at #408, there's the transfer tactic that Johannes wrote a long time ago. Here's an example in mathlib where it transfers theorems between and znum (an isomorphic copy of ).

gebner avatar Jan 08 '20 21:01 gebner

It was mentioned in the conversation earlier. I think the consensus was that this machinery is too ad hoc and not very extendible. I don't personally have experience with it but that's what I got from the conversation. @CohenCyril on the other hand is formalizing a theory of parametricity to base transport on which promises to be more principled and more solid.

cipher1024 avatar Jan 08 '20 21:01 cipher1024

Note that the transfer that @gebner mentions is indeed quite ad hoc: https://github.com/leanprover-community/mathlib/blob/master/src/data/num/lemmas.lean#L955 There is also: https://github.com/leanprover-community/mathlib/blob/master/src/tactic/transfer.lean I have no experience with this tactic.

jcommelin avatar Jan 09 '20 06:01 jcommelin

@johoelzl Could you please explain what does src/tactic/transfer do?

urkud avatar Jan 09 '20 15:01 urkud

I've done a bunch of work towards this, so far appearing in #2246 (an equiv_rw tactic) and #2251 (a transport tactic).

kim-em avatar Mar 28 '20 23:03 kim-em

Can it do all the transfers in data/equiv/transfer_instance? Does it produce the same definitional equalities?

urkud avatar Mar 29 '20 04:03 urkud

Oh, I didn't even realise that file existed. Yes, I will certainly aspire to automate everything there away. (And hopefully synthesize lots of missing lemmas about these transferred instances.)

kim-em avatar Mar 30 '20 05:03 kim-em