You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Manual/Grind/EMatching.lean
+1-14Lines changed: 1 addition & 14 deletions
Original file line number
Diff line number
Diff line change
@@ -295,6 +295,7 @@ grindFunCC
295
295
grindFwd
296
296
grindGen
297
297
grindHom
298
+
grindHomFallback
298
299
grindHomPred
299
300
grindInj
300
301
grindIntro
@@ -638,20 +639,6 @@ The {tactic}`grind` tactic can work with a source algebra that doesn't have a gr
638
639
{ref "grind-hom"}[Homomorphism rules] describe the injection from source to target, and how the injection commutes with other operations (like addition or multiplication in the case of bitvectors).
639
640
Homomorphism predicates present additional facts that {tactic}`grind` can use about the injection (like that a bitvector of length $`n` corresponds to a natural number less than $`2^n`).
Copy file name to clipboardExpand all lines: Manual/Grind/Hom.lean
+181Lines changed: 181 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -170,14 +170,20 @@ To use the feature at all, the mapping should be injective with respect to equal
170
170
That is, given {lean}`x` and {lean}`y` of type {lean}`T`, it should be the case that {lean}`x = y` is logically equivalent to {lean}`x.toU = y.toU`.
171
171
Adding the {attr}`grind hom` attribute to a suitable injectivity theoremactivatesthemappingfeature.
172
172
173
+
:::paragraph
173
174
To be useful, the mapping should translate operations of interest on {lean}`T` into operations in {lean}`U` that are supported by {tactic}`grind`'s solvers.
174
175
The {attr}`grind hom` attribute can be added to the following kinds of theorems:
176
+
175
177
* To translate {lean}`f` into {lean}`g`, it should be the case that {lean}`(f x y).toU = g x.toU y.toU`.
176
178
* Ordering relations can be translated by showing that {lean}`x ≤ y ↔ x.toU ≤ y.toU` and {lean}`x < y ↔ x.toU < y.toU`.
177
179
* Numeric literals can be translated by providing a theoremthattranslatesthemintoafunctioninto {lean}`U`.
178
180
This is done by adding the {attr}`grind hom` attribute to a theoremoftheform {lean}`(OfNat.ofNat n : T).toU = h n`.
179
181
* Conditionals can be translated by providing a theoremthatshowsthat {lean}`(if p then x else y).toU = if p then x.toU else y.toU`.
180
182
183
+
As a last resort, fallback rules can be provided that are applied after other rules have failed to rewrite a term.
184
+
These are typically used for rules that would otherwise overlap others.
185
+
:::
186
+
181
187
Additional facts about the range of the mapping can be provided by tagging lemmas with {attr}`grind hom_pred`.
182
188
This is typically used to restrict the range, such as by asserting that the target of {name}`Fin.val` is less than the {name}`Fin`'s bound.
183
189
These lemmas are instantiated when the constants that they mention are used in terms that are not themselves rewritten by {attr}`grind hom` rules.
@@ -189,6 +195,30 @@ Because the mapping is injective, _disequality_ of terms in the new type implies
189
195
Because they run only very early in the process, homomorphism lemmas are applied without a discharger.
190
196
This means that they do not permit conditional rewrites that require further proving (though rewrites can still be made conditional on an instance-implicit hypothesis, and propositional hypotheses are permitted when they are fully determined by the left-hand side).
191
197
198
+
Homomorphism rules are declared using three attributes: {attr}`grind hom`, {attr}`grind hom fallback`, and {attr}`grind hom_pred`.
199
+
These attributes respectively register homomorphism rules, fallback rules to be tried when the other {attr}`grind hom` rules don't apply, and facts about the range of the mapping.
0 commit comments