Comparing Fin indices by value #
Registers, tape indices, vertices and layout slots are Fin values built from numbers:
⟨6 * q + r, _⟩, Fin.castAdd m i, a definition that returns one of these. That two of them are
equal, distinct or ordered is a linear fact about the numbers. fin_index proves it: it turns each
comparison of Fin values into the comparison of the numbers, moves Fin.val through
constructors and casts, and calls omega.
omega alone already compares Fin variables (it reads i = j, i ≠ j, i < j and i ≤ j in
Fin n, and knows i.val < n), so a goal with only variables and numerals needs no more than
omega. It does not look inside Fin.val ⟨e, h⟩, Fin.val (Fin.castAdd m i) or
Fin.val (f i) for a definition f: each is an unknown number to it. Mathlib's fin_omega
rewrites comparisons and Fin arithmetic to values but leaves the same terms opaque. fin_index
is the step in between: the simp set fin_index_simps of Fin lemmas for the constructors and
casts, and the definitions to unfold given at the call, as in
fin_index [stageLeft, stageRight].
The rewriting is simp only … at *, so facts in context are used in whatever form they have:
h : f i = f j, hne : i ≠ j and h : ¬ i < j all become facts about values. simp skips a
hypothesis that the goal or another hypothesis depends on, and the dependency can be invisible:
the proof in an index ⟨e, by omega⟩ built after h may mention h. fin_index rewrites a
copy of each such hypothesis. A goal Function.Injective f is introduced first.
When a definition branches on an if with numeric branches, omega cannot use it; fin_index
then splits every if in the goal and the context and calls omega on each case. This second
attempt runs only after omega has failed, and its cost doubles with each if in the goal and
the context.
fin_index is a finishing tactic: it closes the goal or fails and leaves it as it was. It is not
a way to rewrite a goal to values and continue.
The list holds what exposes the numbers: the definitions that build the indices, facts about
their values, local let variables. It is checked like a simp only list: an entry that the
rewriting never used at a call is reported under linter.unusedSimpArgs. A goal that needs
set-membership or logic lemmas before it is a comparison of indices is a simp only [⋯]; omega
goal; keep it that way.
Main definitions #
fin_index: prove an equality, disequality or order fact betweenFinvalues from the numbers.fin_index_simps: the simp set thatfin_indexrewrites with, declared inCslibFrontier.Tactic.FinIndex.Initand filled here. It holds value lemmas of core and MathlibFinconstructors and casts whose value is linear and unbranched (its docstring has the rule); a lemma that branches and the definitions of one development go in the list of the call.
fin_index proves a fact about Fin values from the underlying numbers: a = b, a ≠ b,
a < b, a ≤ b, a conjunction of these, Function.Injective f, or False from such a
hypothesis.
It introduces the hypotheses of the goal, rewrites every comparison of Fin values in the goal
and the context to a comparison of numbers, reduces Fin.append on Fin.castAdd and
Fin.natAdd, moves Fin.val through ⟨_, _⟩, Fin.castAdd, Fin.natAdd, Fin.addNat,
Fin.castSucc, Fin.castPred, Fin.succ, Fin.pred, Fin.last, Fin.cast, Fin.castLE,
Fin.rev, the numerals 0 and 1, and if (the simp set fin_index_simps), and calls
omega.
fin_index [f, g, h]also unfolds the definitionsfandgand rewrites with the facth. The list is asimp onlylist: definitions, localletvariables, lemmas such as(hf : ∀ i, (f i).val = i.val + 7), andProd.mk.injEqfor index pairs all go there.- If
omegafails and anifremains, everyifin the goal and the context is split andomegaruns on each case. This is a second attempt; its cost doubles with eachif. The split simplifies a branch that compares two numerals, such as7 = 0; a case left as¬Falseis closed too.
fin_index closes the goal or fails; it never leaves a rewritten goal behind. On failure the
error of omega ends with a note showing the rewritten goal: a term in its where list such as
↑(f i) names a definition missing from the list. An entry that is never used is reported under
linter.unusedSimpArgs. Without constructors, casts or definitions, use omega.