Documentation

Mathlib.Tactic.Translate.Reorder

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 #

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.

  • perm : List { l : List Nat // 2 l.length }

    The list of disjoint cycles that represents the permutation.

  • argReorders : Array (Nat × Reorder)

    The recursive reorders for reordering arguments of arguments. For the purpose of checking equality between reorders, this should be sorted.

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

      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 they act on expressions in the same way.

              @[irreducible]

              Print a Reorder, representing the arguments by their index.

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

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