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