Transport multiplicative to additive

This file defines an attribute to_additive that can be used to automatically transport theorems and definitions (but not inductive types and structures) from multiplicative theory to additive theory.

To use this attribute, just write

@[to_additive]
theorem mul_comm' {α} [comm_semigroup α] (x y : α) : x * y = y * x := comm_semigroup.mul_comm

This code will generate a theorem named add_comm'. It is also possible to manually specify the name of the new declaration, and provide a documentation string.

The transport tries to do the right thing in most cases using several heuristics described below. However, in some cases it fails, and requires manual intervention.

Implementation notes

Handling of hidden definitions

Before transporting the “main” declaration src, to_additive first scans its type and value for names starting with src, and transports them. This includes auxiliary definitions like src._match_1, src._proof_1.

After transporting the “main” declaration, to_additive transports its equational lemmas.

Structure fields and constructors

If src is a structure, then to_additive automatically adds structure fields to its mapping, and similarly for constructors of inductive types.

For new structures this means that to_additive automatically handles coercions, and for old structures it does the same, if ancestry information is present in @[ancestor] attributes.

Name generation

As a safety check, in the first two cases to_additive double checks that the new name differs from the original one.

Missing features