Documentation

Mathlib.Tactic.Translate.Reorder

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 #

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!).

@[reducible, inline]

A permutation, represented using cycle notation.

Equations
Instances For

    Permute an array of arguments using the given reorder.

    Equations
    Instances For

      Permute a list of either universe levels or universe parameters.

      Equations
      Instances For

        Return the inverse permutation.

        Equations
        Instances For

          Return the minimum size of an array on which the permutation is valid.

          Equations
          Instances For

            Two permutations are considered equal if they permute in the same way.

            Equations
            Instances For

              ArgReorder represents a permutation of arguments in a translation.

              • 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

                Return true if the reorder doesn't do anything.

                Equations
                Instances For

                  Permute an array of arguments using the given reorder.

                  Equations
                  Instances For
                    @[irreducible]

                    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.

                        @[irreducible]

                        Print an ArgReorder, representing the arguments by their index.

                        Equations
                        • One or more equations did not get rendered due to their size.
                        Instances For

                          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

                            Return the reorder that reverses the action of the given reorder.

                            Equations
                            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 arguments x and y that appear in the hypothesis H.

                                      If the translated declaration already exists (i.e. when using existing or self), the reorder argument is automatically inferred using the function guessReorder.

                                      Equations
                                      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.

                                        • fvars is only used to add hover information to stx
                                        • head is only used for the error message.
                                        Equations
                                        • One or more equations did not get rendered due to their size.
                                        Instances For
                                          partial def Mathlib.Tactic.Translate.elabReorder (stx : Lean.TSyntax `translateReorder) (argNames : Array Lean.Name) (args : Array Lean.Expr) (head : Lean.MessageData) :

                                          Elaborate the argument of a (reorder := ...) option.