lcp@104
|
1 |
%% $Id$
|
lcp@104
|
2 |
\chapter{Substitution Tactics} \label{substitution}
|
lcp@323
|
3 |
\index{tactics!substitution|(}\index{equality|(}
|
lcp@323
|
4 |
|
lcp@104
|
5 |
Replacing equals by equals is a basic form of reasoning. Isabelle supports
|
lcp@104
|
6 |
several kinds of equality reasoning. {\bf Substitution} means to replace
|
lcp@104
|
7 |
free occurrences of~$t$ by~$u$ in a subgoal. This is easily done, given an
|
lcp@104
|
8 |
equality $t=u$, provided the logic possesses the appropriate rule ---
|
lcp@104
|
9 |
unless you want to substitute even in the assumptions. The tactic
|
lcp@323
|
10 |
{\tt hyp_subst_tac} performs substitution in the assumptions, but it
|
lcp@104
|
11 |
works via object-level implication, and therefore must be specially set up
|
lcp@104
|
12 |
for each suitable object-logic.
|
lcp@104
|
13 |
|
lcp@104
|
14 |
Substitution should not be confused with object-level {\bf rewriting}.
|
lcp@104
|
15 |
Given equalities of the form $t=u$, rewriting replaces instances of~$t$ by
|
lcp@104
|
16 |
corresponding instances of~$u$, and continues until it reaches a normal
|
lcp@104
|
17 |
form. Substitution handles `one-off' replacements by particular
|
lcp@104
|
18 |
equalities, while rewriting handles general equalities.
|
lcp@104
|
19 |
Chapter~\ref{simp-chap} discusses Isabelle's rewriting tactics.
|
lcp@104
|
20 |
|
lcp@104
|
21 |
|
lcp@323
|
22 |
\section{Substitution rules}
|
lcp@323
|
23 |
\index{substitution!rules}\index{*subst theorem}
|
lcp@323
|
24 |
Many logics include a substitution rule of the form
|
lcp@104
|
25 |
$$ \List{\Var{a}=\Var{b}; \Var{P}(\Var{a})} \Imp
|
lcp@104
|
26 |
\Var{P}(\Var{b}) \eqno(subst)$$
|
lcp@104
|
27 |
In backward proof, this may seem difficult to use: the conclusion
|
lcp@104
|
28 |
$\Var{P}(\Var{b})$ admits far too many unifiers. But, if the theorem {\tt
|
lcp@104
|
29 |
eqth} asserts $t=u$, then \hbox{\tt eqth RS subst} is the derived rule
|
lcp@104
|
30 |
\[ \Var{P}(t) \Imp \Var{P}(u). \]
|
lcp@104
|
31 |
Provided $u$ is not an unknown, resolution with this rule is
|
lcp@104
|
32 |
well-behaved.\footnote{Unifying $\Var{P}(u)$ with a formula~$Q$
|
lcp@104
|
33 |
expresses~$Q$ in terms of its dependence upon~$u$. There are still $2^k$
|
lcp@104
|
34 |
unifiers, if $Q$ has $k$ occurrences of~$u$, but Isabelle ensures that
|
lcp@104
|
35 |
the first unifier includes all the occurrences.} To replace $u$ by~$t$ in
|
lcp@104
|
36 |
subgoal~$i$, use
|
lcp@104
|
37 |
\begin{ttbox}
|
lcp@104
|
38 |
resolve_tac [eqth RS subst] \(i\) {\it.}
|
lcp@104
|
39 |
\end{ttbox}
|
lcp@104
|
40 |
To replace $t$ by~$u$ in
|
lcp@104
|
41 |
subgoal~$i$, use
|
lcp@104
|
42 |
\begin{ttbox}
|
lcp@104
|
43 |
resolve_tac [eqth RS ssubst] \(i\) {\it,}
|
lcp@104
|
44 |
\end{ttbox}
|
lcp@323
|
45 |
where \tdxbold{ssubst} is the `swapped' substitution rule
|
lcp@104
|
46 |
$$ \List{\Var{a}=\Var{b}; \Var{P}(\Var{b})} \Imp
|
lcp@104
|
47 |
\Var{P}(\Var{a}). \eqno(ssubst)$$
|
lcp@323
|
48 |
If \tdx{sym} denotes the symmetry rule
|
lcp@104
|
49 |
\(\Var{a}=\Var{b}\Imp\Var{b}=\Var{a}\), then {\tt ssubst} is just
|
lcp@104
|
50 |
\hbox{\tt sym RS subst}. Many logics with equality include the rules {\tt
|
lcp@104
|
51 |
subst} and {\tt ssubst}, as well as {\tt refl}, {\tt sym} and {\tt trans}
|
lcp@323
|
52 |
(for the usual equality laws). Examples include {\tt FOL} and {\tt HOL},
|
lcp@323
|
53 |
but not {\tt CTT} (Constructive Type Theory).
|
lcp@104
|
54 |
|
lcp@104
|
55 |
Elim-resolution is well-behaved with assumptions of the form $t=u$.
|
lcp@104
|
56 |
To replace $u$ by~$t$ or $t$ by~$u$ in subgoal~$i$, use
|
lcp@104
|
57 |
\begin{ttbox}
|
lcp@104
|
58 |
eresolve_tac [subst] \(i\) {\it or} eresolve_tac [ssubst] \(i\) {\it.}
|
lcp@104
|
59 |
\end{ttbox}
|
lcp@104
|
60 |
|
lcp@104
|
61 |
|
lcp@104
|
62 |
\section{Substitution in the hypotheses}
|
lcp@323
|
63 |
\index{assumptions!substitution in}
|
lcp@104
|
64 |
Substitution rules, like other rules of natural deduction, do not affect
|
lcp@104
|
65 |
the assumptions. This can be inconvenient. Consider proving the subgoal
|
lcp@104
|
66 |
\[ \List{c=a; c=b} \Imp a=b. \]
|
lcp@323
|
67 |
Calling {\tt eresolve_tac\ts[ssubst]\ts\(i\)} simply discards the
|
lcp@104
|
68 |
assumption~$c=a$, since $c$ does not occur in~$a=b$. Of course, we can
|
lcp@323
|
69 |
work out a solution. First apply {\tt eresolve_tac\ts[subst]\ts\(i\)},
|
lcp@104
|
70 |
replacing~$a$ by~$c$:
|
lcp@104
|
71 |
\[ \List{c=b} \Imp c=b \]
|
lcp@104
|
72 |
Equality reasoning can be difficult, but this trivial proof requires
|
lcp@104
|
73 |
nothing more sophisticated than substitution in the assumptions.
|
lcp@323
|
74 |
Object-logics that include the rule~$(subst)$ provide tactics for this
|
lcp@104
|
75 |
purpose:
|
lcp@104
|
76 |
\begin{ttbox}
|
lcp@323
|
77 |
hyp_subst_tac : int -> tactic
|
lcp@323
|
78 |
bound_hyp_subst_tac : int -> tactic
|
lcp@104
|
79 |
\end{ttbox}
|
lcp@323
|
80 |
\begin{ttdescription}
|
lcp@104
|
81 |
\item[\ttindexbold{hyp_subst_tac} {\it i}]
|
lcp@323
|
82 |
selects an equality assumption of the form $t=u$ or $u=t$, where $t$ is a
|
lcp@323
|
83 |
free variable or parameter. Deleting this assumption, it replaces $t$
|
lcp@323
|
84 |
by~$u$ throughout subgoal~$i$, including the other assumptions.
|
lcp@323
|
85 |
|
lcp@323
|
86 |
\item[\ttindexbold{bound_hyp_subst_tac} {\it i}]
|
lcp@323
|
87 |
is similar but only substitutes for parameters (bound variables).
|
lcp@323
|
88 |
Uses for this are discussed below.
|
lcp@323
|
89 |
\end{ttdescription}
|
lcp@104
|
90 |
The term being replaced must be a free variable or parameter. Substitution
|
lcp@104
|
91 |
for constants is usually unhelpful, since they may appear in other
|
lcp@104
|
92 |
theorems. For instance, the best way to use the assumption $0=1$ is to
|
lcp@104
|
93 |
contradict a theorem that states $0\not=1$, rather than to replace 0 by~1
|
lcp@104
|
94 |
in the subgoal!
|
lcp@104
|
95 |
|
lcp@104
|
96 |
Replacing a free variable causes similar problems if they appear in the
|
lcp@104
|
97 |
premises of a rule being derived --- the substitution affects object-level
|
lcp@104
|
98 |
assumptions, not meta-level assumptions. For instance, replacing~$a$
|
lcp@323
|
99 |
by~$b$ could make the premise~$P(a)$ worthless. To avoid this problem, use
|
lcp@323
|
100 |
{\tt bound_hyp_subst_tac}; alternatively, call \ttindex{cut_facts_tac} to
|
lcp@323
|
101 |
insert the atomic premises as object-level assumptions.
|
lcp@104
|
102 |
|
lcp@104
|
103 |
|
lcp@104
|
104 |
\section{Setting up {\tt hyp_subst_tac}}
|
lcp@104
|
105 |
Many Isabelle object-logics, such as {\tt FOL}, {\tt HOL} and their
|
lcp@104
|
106 |
descendants, come with {\tt hyp_subst_tac} already defined. A few others,
|
lcp@104
|
107 |
such as {\tt CTT}, do not support this tactic because they lack the
|
lcp@104
|
108 |
rule~$(subst)$. When defining a new logic that includes a substitution
|
lcp@104
|
109 |
rule and implication, you must set up {\tt hyp_subst_tac} yourself. It
|
lcp@104
|
110 |
is packaged as the \ML{} functor \ttindex{HypsubstFun}, which takes the
|
lcp@323
|
111 |
argument signature~{\tt HYPSUBST_DATA}:
|
lcp@104
|
112 |
\begin{ttbox}
|
lcp@104
|
113 |
signature HYPSUBST_DATA =
|
lcp@104
|
114 |
sig
|
lcp@104
|
115 |
val subst : thm
|
lcp@104
|
116 |
val sym : thm
|
lcp@104
|
117 |
val rev_cut_eq : thm
|
lcp@104
|
118 |
val imp_intr : thm
|
lcp@104
|
119 |
val rev_mp : thm
|
lcp@104
|
120 |
val dest_eq : term -> term*term
|
lcp@104
|
121 |
end;
|
lcp@104
|
122 |
\end{ttbox}
|
lcp@104
|
123 |
Thus, the functor requires the following items:
|
lcp@323
|
124 |
\begin{ttdescription}
|
lcp@323
|
125 |
\item[\tdxbold{subst}] should be the substitution rule
|
lcp@104
|
126 |
$\List{\Var{a}=\Var{b};\; \Var{P}(\Var{a})} \Imp \Var{P}(\Var{b})$.
|
lcp@104
|
127 |
|
lcp@323
|
128 |
\item[\tdxbold{sym}] should be the symmetry rule
|
lcp@104
|
129 |
$\Var{a}=\Var{b}\Imp\Var{b}=\Var{a}$.
|
lcp@104
|
130 |
|
lcp@323
|
131 |
\item[\tdxbold{rev_cut_eq}] should have the form
|
lcp@104
|
132 |
$\List{\Var{a}=\Var{b};\; \Var{a}=\Var{b}\Imp\Var{R}} \Imp \Var{R}$.
|
lcp@104
|
133 |
|
lcp@323
|
134 |
\item[\tdxbold{imp_intr}] should be the implies introduction
|
lcp@104
|
135 |
rule $(\Var{P}\Imp\Var{Q})\Imp \Var{P}\imp\Var{Q}$.
|
lcp@104
|
136 |
|
lcp@323
|
137 |
\item[\tdxbold{rev_mp}] should be the `reversed' implies elimination
|
lcp@104
|
138 |
rule $\List{\Var{P}; \;\Var{P}\imp\Var{Q}} \Imp \Var{Q}$.
|
lcp@104
|
139 |
|
lcp@104
|
140 |
\item[\ttindexbold{dest_eq}] should return the pair~$(t,u)$ when
|
lcp@104
|
141 |
applied to the \ML{} term that represents~$t=u$. For other terms, it
|
lcp@323
|
142 |
should raise exception~\xdx{Match}.
|
lcp@323
|
143 |
\end{ttdescription}
|
lcp@323
|
144 |
The functor resides in file {\tt Provers/hypsubst.ML} in the Isabelle
|
lcp@104
|
145 |
distribution directory. It is not sensitive to the precise formalization
|
lcp@104
|
146 |
of the object-logic. It is not concerned with the names of the equality
|
lcp@104
|
147 |
and implication symbols, or the types of formula and terms. Coding the
|
lcp@104
|
148 |
function {\tt dest_eq} requires knowledge of Isabelle's representation of
|
lcp@104
|
149 |
terms. For {\tt FOL} it is defined by
|
lcp@104
|
150 |
\begin{ttbox}
|
lcp@286
|
151 |
fun dest_eq (Const("Trueprop",_) $ (Const("op =",_)$t$u)) = (t,u)
|
lcp@104
|
152 |
\end{ttbox}
|
wenzelm@148
|
153 |
Here {\tt Trueprop} is the coercion from type~$o$ to type~$prop$, while
|
lcp@104
|
154 |
\hbox{\tt op =} is the internal name of the infix operator~{\tt=}.
|
lcp@104
|
155 |
Pattern-matching expresses the function concisely, using wildcards~({\tt_})
|
lcp@104
|
156 |
to hide the types.
|
lcp@104
|
157 |
|
lcp@323
|
158 |
Here is how {\tt hyp_subst_tac} works. Given a subgoal of the form
|
lcp@323
|
159 |
\[ \List{P@1; \cdots ; t=u; \cdots ; P@n} \Imp Q, \] it locates a suitable
|
lcp@323
|
160 |
equality assumption and moves it to the last position using elim-resolution
|
lcp@323
|
161 |
on {\tt rev_cut_eq} (possibly re-orienting it using~{\tt sym}):
|
lcp@104
|
162 |
\[ \List{P@1; \cdots ; P@n; t=u} \Imp Q \]
|
lcp@323
|
163 |
Using $n$ calls of {\tt eresolve_tac\ts[rev_mp]}, it creates the subgoal
|
lcp@104
|
164 |
\[ \List{t=u} \Imp P@1\imp \cdots \imp P@n \imp Q \]
|
lcp@323
|
165 |
By {\tt eresolve_tac\ts[ssubst]}, it replaces~$t$ by~$u$ throughout:
|
lcp@104
|
166 |
\[ P'@1\imp \cdots \imp P'@n \imp Q' \]
|
lcp@323
|
167 |
Finally, using $n$ calls of \hbox{\tt resolve_tac\ts[imp_intr]}, it restores
|
lcp@104
|
168 |
$P'@1$, \ldots, $P'@n$ as assumptions:
|
lcp@104
|
169 |
\[ \List{P'@n; \cdots ; P'@1} \Imp Q' \]
|
lcp@104
|
170 |
|
lcp@323
|
171 |
\index{equality|)}\index{tactics!substitution|)}
|