This PR replaces the `grind` canonicalizer with a new type-directed normalizer (`Sym.canon`) that goes inside binders and applies targeted reductions in type positions, eliminating the O(n^2) `isDefEq`-based approach. The old canonicalizer maintained a map from `(function, argument_position)` to previously seen arguments, iterating the list and calling `isDefEq` for each new argument. This produced performance problems in some goal. For example, for a goal containing `n` numeric literals, it would produce O(n^2) `isDefEq` comparisons. The new canonicalizer normalizes types directly: - **Instances**: re-synthesized via `synthInstance` with the type normalized first, so `OfNat (Fin (2+1)) 0` and `OfNat (Fin 3) 0` produce the same instance. - **Types**: normalized with targeted reductions — eta, projection, match/ite/cond, and Nat arithmetic (`n.succ + 1` → `n + 2`, `2 + 1` → `3`). - **Values**: traversed but not reduced, preserving lambdas for grind's beta module. The canonicalizer enters binders (the old one did not), using separate caches for type-level and value-level contexts. Propositions are not normalized to avoid interfering with grind's proposition handling. Move `SynthInstance` from `Grind` to `Sym` since the canonicalizer now lives in `Sym` and needs instance synthesis. The `Grind` namespace re-exports the key functions. Add `no_index` annotations to `val_addNat` and `val_castAdd` patterns in `Fin/Lemmas.lean` — arithmetic in type positions is now normalized, so patterns must not rely on the un-normalized form for e-matching indexing. --------- Co-authored-by: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
57 lines
2.7 KiB
Text
57 lines
2.7 KiB
Text
import Lean.Util.Reprove
|
|
|
|
namespace Array
|
|
|
|
reprove pmap_empty pmap_push attach_empty attachWith_empty by grind
|
|
reprove map_pmap pmap_map attach_push attachWith_push pmap_eq_map_attach pmap_eq_attachWith by grind
|
|
reprove attach_map_val attach_map_subtype_val attachWith_map_val attachWith_map_subtype_val by grind
|
|
reprove pmap_attach pmap_attachWith by grind
|
|
-- Removed attachWith_map
|
|
reprove attach_map map_attachWith map_attachWith_eq_pmap map_attach_eq_pmap by grind
|
|
reprove pmap_pmap pmap_append pmap_append' attach_append attachWith_append by grind
|
|
reprove pmap_reverse reverse_pmap attachWith_reverse reverse_attachWith attach_reverse reverse_attach by grind
|
|
reprove back?_pmap back?_attachWith back?_attach by grind
|
|
|
|
end Array
|
|
|
|
namespace Vector
|
|
|
|
reprove pmap_empty pmap_push attach_empty attachWith_empty by grind
|
|
reprove map_pmap pmap_map attach_push attachWith_push pmap_eq_map_attach pmap_eq_attachWith by grind
|
|
reprove attach_map_val attach_map_subtype_val attachWith_map_val attachWith_map_subtype_val by grind
|
|
reprove pmap_attach pmap_attachWith by grind
|
|
-- Removed attachWith_map
|
|
reprove attach_map map_attachWith map_attachWith_eq_pmap map_attach_eq_pmap by grind
|
|
reprove pmap_pmap pmap_append pmap_append' attach_append attachWith_append by grind
|
|
reprove pmap_reverse reverse_pmap attachWith_reverse reverse_attachWith attach_reverse reverse_attach by grind
|
|
reprove back?_pmap back?_attachWith back?_attach by grind
|
|
|
|
end Vector
|
|
|
|
namespace List
|
|
|
|
-- `grind` is less capable on List by default, because the theorems are set up to use induction and `cons`,
|
|
-- rathering than extensionality via indices. Here we just use extensionality.
|
|
attribute [local grind ←=] List.ext_getElem
|
|
|
|
reprove pmap_nil pmap_cons attach_nil attachWith_nil by grind
|
|
reprove map_pmap pmap_map attach_cons attachWith_cons pmap_eq_map_attach pmap_eq_attachWith by grind
|
|
reprove attach_map_val attach_map_subtype_val attachWith_map_val attachWith_map_subtype_val by grind
|
|
reprove pmap_attach pmap_attachWith by grind
|
|
-- Removed attachWith_map
|
|
reprove attach_map map_attachWith map_attachWith_eq_pmap map_attach_eq_pmap by grind
|
|
reprove pmap_pmap pmap_append pmap_append' attach_append attachWith_append by grind
|
|
reprove pmap_reverse reverse_pmap attachWith_reverse reverse_attachWith attach_reverse reverse_attach by grind
|
|
reprove getLast?_pmap getLast?_attachWith getLast?_attach by grind
|
|
|
|
end List
|
|
|
|
namespace Option
|
|
|
|
reprove pmap_none pmap_some attach_none attachWith_none by grind
|
|
reprove map_pmap pmap_map attach_some attachWith_some by grind
|
|
reprove attach_map_subtype_val attachWith_map_val attachWith_map_subtype_val by grind [cases Option]
|
|
reprove attach_map attachWith_map map_attachWith by grind [cases Option]
|
|
reprove map_attachWith_eq_pmap map_attach_eq_pmap by grind [cases Option]
|
|
|
|
end Option
|