Reordering arguments in a translation #
This module defines reorders, which are used by to_dual (reorder := ...) and
to_additive (reorder := ...) to deal with definitions and theorems that need to have their
arguments reordered.
A reordering is specified using disjoint cycle notation. For example, 1 2 3, 4 5 will
move the 1st argument to the 2nd, move the 2nd to the 3rd, and the 3rd to the 1st, and it will
swap the 4th and 5th arguments.
Instead of using numbers to refer to argument, you can also refer to them by name. For example
a b will swap the arguments named a and b. This is implemented in elabArgStx.
To specify reordering arguments of arguments, the syntax is recursive. For example,
4 (1 2) will reorder the first two arguments of the fourth argument.
Examples #
to_dualneeds to swap the arguments of some definitions to translate them, such asa ≤ b↦b ≤ aanda ⇨ b↦b \ a. In these cases, we reorder the 3rd and 4th arguments, which can be specified using@[to_dual (reorder := 3 4)].to_additiveneeds to swap the arguments when translatinga ^ n↦n • a.Some theorems are dual to themselves only after reordering some arguments. For example,
le_total : ∀ a b : α, a ≤ b ∨ b ≤ ais dual to itself after swappingaandb. Thanks to the heuristic inguessReorder, this reordering can often be found automatically, so it suffices to write@[to_dual self].
TODO #
We need better support for reordering of universes for to_dual in category theory,
for example to dualize CategoryTheory.Comma to itself.
Reorder represents a permutation of arguments in a translation.
The list of disjoint cycles that represents the permutation.
The recursive reorders for reordering arguments of arguments. For the purpose of checking equality between reorders, this should be sorted.
Instances For
Equations
Instances For
Permute a list of either universe levels or universe parameters. The current heuristic is to swap the first two universes if the first argument is permuted.
Equations
Instances For
Permute an array of arguments using the given reorder.
Equations
Instances For
Return the reorder that reverses the action of the given reorder.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Return the minimum size of an array on which the given reorder is valid.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Two Reorders are considered equal if they act on expressions in the same way.
Equations
Print a Reorder, representing the arguments by their index.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Equations
- Mathlib.Tactic.Translate.instToStringReorder = { toString := fun (x : Mathlib.Tactic.Translate.Reorder) => x.toString }
Equations
- Mathlib.Tactic.Translate.instToMessageDataReorder = { toMessageData := fun (x : Mathlib.Tactic.Translate.Reorder) => (Lean.MessageData.ofFormat ∘ Std.format) x.toString }
Reordering an expression #
Reorder the arguments of a function type using the given Reorder.
Reorder the arguments of a function using the given Reorder.
Guessing the reorder given the reordered expression #
Try to determine the value of the (reorder := ...) option that would be needed to translate
type e₁ to type e₂. If there is no good guess, default to [].
The heuristic that we use is to compare the conclusions of e₁ and e₂,
and to observe which variables are swapped.
We also apply this heuristic recurisvely in hypotheses.
Syntax for specifying a reorder #
Equations
- One or more equations did not get rendered due to their size.
Instances For
The syntax category for the reorder syntax.
Equations
Instances For
Equations
- One or more equations did not get rendered due to their size.
Instances For
(reorder := ...) reorders the arguments/hypotheses in the generated declaration.
This is used in to_dual to swap the arguments in ≤, < and ⟶,
and it is used in to_additive to translate from a ^ n to n • a.
It uses disjoint cycle notation for the permutation. For reordering arguments of an argument a,
it uses the notation a (...) where ... can be any reorder.
For example:
(reorder := α β, 5 6)swaps the argumentsαandβwith each other and the fifth and the sixth argument.(reorder := 3 4 5)will move the fifth argument before the third argument.(reorder := H (x y))will swap the argumentsxandythat appear in the hypothesisH.
If the translated declaration already exists (i.e. when using existing or self), the reorder
argument is automatically inferred using the function guessReorder.
Equations
- Mathlib.Tactic.Translate.reorder = Lean.ParserDescr.node `Mathlib.Tactic.Translate.reorder 1022 (Mathlib.Tactic.Translate.reorderPart.sepBy "," (Lean.ParserDescr.symbol ", "))
Instances For
Elaborate syntax that refers to an argument of a declaration or hypothesis.
This is either a 1-indexed number, or a name from argNames.
fvarsis only used to add hover information tostxheadis only used for the error message.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Elaborate the argument of a (reorder := ...) option.