Documentation

Init.Grind.Attr

def Lean.Grind.genPattern {α : Sort u} (_h : Prop) (x _val : α) :
α

Gadget for representing generalization steps h : x = val in patterns This gadget is used to represent patterns in theorems that have been generalized to reduce the number of casts introduced during E-matching based instantiation.

For example, consider the theorem

Option.pbind_some {α1 : Type u_1} {a : α1} {α2 : Type u_2}
    {f : (a_1 : α1) → some a = some a_1 → Option α2}
    : (some a).pbind f = f a rfl

Now, suppose we have a goal containing the term c.pbind g and the equivalence class {c, some b}. The E-matching module generates the instance

(some b).pbind (cast ⋯ g)

The cast is necessary because g's type contains c instead of some b. This cast` problematic because we don't have a systematic way of pushing casts over functions to its arguments. Moreover, heterogeneous equality is not effective because the following theorem is not provable in DTT:

theorem hcongr (h₁ : f ≍ g) (h₂ : a ≍ b)  : f a ≍ g b := ...

The standard solution is to generalize the theorem above and write it as

theorem Option.pbind_some'
        {α1 : Type u_1} {a : α1} {α2 : Type u_2}
        {x : Option α1}
        {f : (a_1 : α1) → x = some a_1 → Option α2}
        (h : x = some a)
        : x.pbind f = f a h := by
  subst h
  apply Option.pbind_some

Internally, we use this gadget to mark the E-matching pattern as

(genPattern h x (some a)).pbind f

This pattern is matched in the same way we match (some a).pbind f, but it saves the proof for the actual term to the some-application in f, and the actual term in x.

In the example above, c.pbind g also matches the pattern (genPattern h x (some a)).pbind f, and stores c in x, b in a, and the proof that c = some b in h.

Equations
Instances For
    def Lean.Grind.genHEqPattern {α β : Sort u} (_h : Prop) (x : α) (_val : β) :
    α

    Similar to genPattern but for the heterogeneous case

    Equations
    Instances For

      Reset all grind attributes. This command is intended for testing purposes only and should not be used in applications.

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

          The = modifier instructs grind to check that the conclusion of the theorem is an equality, and then uses the left-hand side of the equality as a pattern. This may fail if not all of the arguments appear in the left-hand side.

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

            The =_ modifier instructs grind to check that the conclusion of the theorem is an equality, and then uses the right-hand side of the equality as a pattern. This may fail if not all of the arguments appear in the right-hand side.

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

              The _=_ modifier acts like a macro which expands to = and =_. It adds two patterns, allowing the equality theorem to trigger in either direction.

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

                The ←= modifier is unlike the other grind modifiers, and it used specifically for backwards reasoning on equality. When a theorem's conclusion is an equality proposition and it is annotated with @[grind ←=], grind will instantiate it whenever the corresponding disequality is assumed—this is a consequence of the fact that grind performs all proofs by contradiction. Ordinarily, the grind attribute does not consider the = symbol when generating patterns.

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

                  The modifier instructs grind to select a multi-pattern from the conclusion of theorem. In other words, grind will use the theorem for backwards reasoning. This may fail if not all of the arguments to the theorem appear in the conclusion.

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

                    The modifier instructs grind to select a multi-pattern from the hypotheses of the theorem. In other words, grind will use the theorem for forwards reasoning. To generate a pattern, it traverses the hypotheses of the theorem from left to right. Each time it encounters a minimal indexable subexpression which covers an argument which was not previously covered, it adds that subexpression as a pattern, until all arguments have been covered.

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

                      The modifier instructs grind to select a multi-pattern by traversing the conclusion, and then all the hypotheses from right to left. Each time it encounters a minimal indexable subexpression which covers an argument which was not previously covered, it adds that subexpression as a pattern, until all arguments have been covered.

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

                        The modifier instructs grind to select a multi-pattern by traversing all the hypotheses from left to right, followed by the conclusion. Each time it encounters a minimal indexable subexpression which covers an argument which was not previously covered, it adds that subexpression as a pattern, until all arguments have been covered.

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

                          The usr modifier indicates that this theorem was applied using a user-defined instantiation pattern. Such patterns are declared with the grind_pattern command, which lets you specify how grind should match and use particular theorems.

                          Example:

                          • grind [usr myThm] means grind is using myThm, but with the the custom pattern you defined with grind_pattern.
                          Equations
                          Instances For

                            The cases modifier marks inductively-defined predicates as suitable for case splitting.

                            Equations
                            Instances For

                              The cases eager modifier marks inductively-defined predicates as suitable for case splitting, and instructs grind to perform it eagerly while preprocessing hypotheses.

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

                                The intro modifier instructs grind to use the constructors (introduction rules) of an inductive predicate as E-matching theorems.Example:

                                inductive Even : Nat → Prop where
                                | zero : Even 0
                                | add2 : Even x → Even (x + 2)
                                
                                attribute [grind intro] Even
                                example (h : Even x) : Even (x + 6) := by grind
                                example : Even 0 := by grind
                                

                                Here attribute [grind intro] Even acts like a macro that expands to attribute [grind] Even.zero and attribute [grind] Even.add2. This is especially convenient for inductive predicates with many constructors.

                                Equations
                                Instances For

                                  The ext modifier marks extensionality theorems for use by grind. For example, the standard library marks funext with this attribute.

                                  Whenever grind encounters a disequality a ≠ b, it attempts to apply any available extensionality theorems whose matches the type of a and b.

                                  Equations
                                  Instances For

                                    symbol <prio> sets the priority of a constant for grind’s pattern-selection procedure. grind prefers patterns that contain higher-priority symbols. Example:

                                    opaque p : NatNat → Prop
                                    opaque q : NatNat → Prop
                                    opaque r : NatNat → Prop
                                    
                                    attribute [grind symbol low] p
                                    attribute [grind symbol high] q
                                    
                                    axiom bar {x y} : p x y → q x x → r x y → r y x
                                    attribute [grind →] bar
                                    

                                    Here p is low priority, q is high priority, and r is default. grind first tries to find a multi-pattern covering x and y using only high-priority symbols while scanning hypotheses left to right. This fails because q x x does not cover y. It then allows both high and default symbols and succeeds with the multi-pattern q x x, r x y. The term p x y is ignored due to p’s low priority. Symbols with priority 0 are never used in patterns.

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