Reordering arguments in a translation #
This module defines reorders, which can be specified with to_dual (reorder := ...) or
to_additive (reorder := ...), to deal with definitions and theorems that need to have their
arguments and/or universe parameters 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.
If the declaration is translated to itself or to an existing declaration,
the heuristic in guessReorder tries to predict the argument reorder.
This is done with a syntactic comparison of which variable is moved where.
The universe reordering is always inferred automatically, using guessUnivReorder.
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, it suffices to write@[to_dual self].
Implementation details #
Permutation are stored as their disjoint cycle representation (Permutation).
This allows efficiently permuting an array/list of arguments/universes
(Permutation.permute!/Permutation.permuteList!).
Permute an array of arguments using the given reorder.
Equations
Instances For
Permute a list of either universe levels or universe parameters.
Instances For
Return the minimum size of an array on which the permutation is valid.
Equations
Instances For
ArgReorder represents a permutation of arguments in a translation.
- perm : Permutation
The list of disjoint cycles that represents the permutation.
- argReorders : Array (Nat × ArgReorder)
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
Return true if the reorder doesn't do anything.
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 all permutations are the same.
Print an ArgReorder, 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.ArgReorder.instToString = { toString := fun (x : Mathlib.Tactic.Translate.ArgReorder) => x.toString }
Equations
- Mathlib.Tactic.Translate.ArgReorder.instToMessageData = { toMessageData := fun (x : Mathlib.Tactic.Translate.ArgReorder) => (Lean.MessageData.ofFormat ∘ Std.format) x.toString }
Reorder represents a permutation of arguments and universe levels for translating
a given constant.
- univReorder : Permutation
The reordering of universe levels.
- reorder : ArgReorder
The reordering of arguments.
Instances For
Reordering an expression #
Reorder the arguments of a function type using the given ArgReorder.
Reorder the arguments of a function using the given ArgReorder.
Guessing the reorder given the reordered expression #
Determine the universe level reorder for decl, given the argument reorder.
For each reordering in reorder, we find any corresponding universe reorderings,
which are then combined to get the result.
Equations
- One or more equations did not get rendered due to their size.
Instances For
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 recursively in hypotheses.
Syntax for specifying a reorder #
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
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.