Documentation

Lean.Meta.Tactic.Grind.Canon

A canonicalizer module for the grind tactic. The canonicalizer defined in Meta/Canonicalizer.lean is not suitable for the grind tactic. It was designed for tactics such as omega, where the goal is to detect when two structurally different atoms are definitionally equal.

The grind tactic, on the other hand, uses congruence closure. Moreover, types, type formers, proofs, and instances are considered supporting elements and are not factored into congruence detection.

This module minimizes the number of isDefEq checks by comparing two terms a and b only if they instances, types, or type formers and are the i-th arguments of two different f-applications. This approach is sufficient for the congruence closure procedure used by the grind tactic.

To further optimize isDefEq checks, instances are compared using TransparencyMode.instances, which reduces the number of constants that need to be unfolded. If diagnostics are enabled, instances are compared using the default transparency mode too for sanity checking, and discrepancies are reported. Types and type formers are always checked using default transparency.

Remark: The canonicalizer minimizes issues with non-canonical instances and structurally different but definitionally equal types, but it does not solve all problems. For example, consider a situation where we have (a : BitVec n) and (b : BitVec m), along with instances inst1 n : Add (BitVec n) and inst2 m : Add (BitVec m) where inst1 and inst2 are structurally different. Now consider the terms a + a and b + b. After canonicalization, the two additions will still use structurally different (and definitionally different) instances: inst1 n and inst2 m. Furthermore, grind will not be able to infer that HEq (a + a) (b + b) even if we add the assumptions n = m and HEq a b.

Helper function for canonicalizing e occurring as the ith argument of an f-application. isInst is true if e is an type class instance.

Recall that we use TransparencyMode.instances for checking whether two instances are definitionally equal or not. Thus, if diagnostics are enabled, we also check them using TransparencyMode.default. If the result is different we report to the user.

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

    See comments at ShouldCanonResult.

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