Documentation

CslibFrontier.Tactic.FinIndex

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 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 definitions f and g and rewrites with the fact h. The list is a simp only list: definitions, local let variables, lemmas such as (hf : ∀ i, (f i).val = i.val + 7), and Prod.mk.injEq for index pairs all go there.
  • If omega fails and an if remains, every if in the goal and the context is split and omega runs on each case. This is a second attempt; its cost doubles with each if. The split simplifies a branch that compares two numerals, such as 7 = 0; a case left as ¬False is 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.