The unify_equations
tactic #
This module defines unify_equations
, a first-order unification tactic that
unifies one or more equations in the context. It implements the Qnify algorithm
from McBride, Inverting Inductively Defined Relations in LEGO.
The tactic takes as input some equations which it simplifies one after the
other. Each equation is simplified by applying one of several possible
unification steps. Each such step may output other (simpler) equations which are
unified recursively until no unification step applies any more. See
tactic.interactive.unify_equations
for an example and an explanation of the
different steps.
unify_equations eq₁ ... eqₙ
performs a form of first-order unification on the
hypotheses eqᵢ
. The eqᵢ
must be homogeneous or heterogeneous equations.
Unification means that the equations are simplified using various facts about
constructors. For instance, consider this goal:
After unify_equations h₁ h₂
, we get
In the example, unify_equations
uses the fact that every constructor is
injective to conclude n = m
from h₁
. Then it replaces every m
with n
and
moves on to h₂
. The types of f
and g
are now equal, so the heterogeneous
equation turns into a homogeneous one and g
is replaced by f
. Note that the
equations are processed from left to right, so unify_equations h₂ h₁
would not
simplify as much.
In general, unify_equations
uses the following steps on each equation until
none of them applies any more:
- Constructor injectivity: if
nat.succ n = nat.succ m
thenn = m
. - Substitution: if
x = e
for some hypothesisx
, thenx
is replaced bye
everywhere. - No-confusion:
nat.succ n = nat.zero
is a contradiction. If we have such an equation, the goal is solved immediately. - Cycle elimination:
n = nat.succ n
is a contradiction. - Redundancy: if
t = u
butt
andu
are already definitionally equal, then this equation is removed. - Downgrading of heterogeneous equations: if
t == u
butt
andu
have the same type (up to definitional equality), then the equation is replaced byt = u
.