8749
|
1 |
\begin{isabelle}%
|
|
2 |
%
|
|
3 |
\begin{isamarkuptext}%
|
|
4 |
Goals containing \isaindex{if}-expressions are usually proved by case
|
|
5 |
distinction on the condition of the \isa{if}. For example the goal%
|
|
6 |
\end{isamarkuptext}%
|
9673
|
7 |
\isacommand{lemma}\ {\isachardoublequote}{\isasymforall}xs{\isachardot}\ if\ xs\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}\ then\ rev\ xs\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}\ else\ rev\ xs\ {\isasymnoteq}\ {\isacharbrackleft}{\isacharbrackright}{\isachardoublequote}%
|
8749
|
8 |
\begin{isamarkuptxt}%
|
|
9 |
\noindent
|
|
10 |
can be split into
|
|
11 |
\begin{isabellepar}%
|
|
12 |
~1.~{\isasymforall}xs.~(xs~=~[]~{\isasymlongrightarrow}~rev~xs~=~[])~{\isasymand}~(xs~{\isasymnoteq}~[]~{\isasymlongrightarrow}~rev~xs~{\isasymnoteq}~[])%
|
|
13 |
\end{isabellepar}%
|
|
14 |
by a degenerate form of simplification%
|
|
15 |
\end{isamarkuptxt}%
|
9673
|
16 |
\isacommand{apply}{\isacharparenleft}simp\ only{\isacharcolon}\ split{\isacharcolon}\ split{\isacharunderscore}if{\isacharparenright}%
|
8749
|
17 |
\begin{isamarkuptext}%
|
|
18 |
\noindent
|
|
19 |
where no simplification rules are included (\isa{only:} is followed by the
|
|
20 |
empty list of theorems) but the rule \isaindexbold{split_if} for
|
|
21 |
splitting \isa{if}s is added (via the modifier \isa{split:}). Because
|
|
22 |
case-splitting on \isa{if}s is almost always the right proof strategy, the
|
|
23 |
simplifier performs it automatically. Try \isacommand{apply}\isa{(simp)}
|
|
24 |
on the initial goal above.
|
|
25 |
|
|
26 |
This splitting idea generalizes from \isa{if} to \isaindex{case}:%
|
|
27 |
\end{isamarkuptext}%
|
9673
|
28 |
\isacommand{lemma}\ {\isachardoublequote}{\isacharparenleft}case\ xs\ of\ {\isacharbrackleft}{\isacharbrackright}\ {\isasymRightarrow}\ zs\ {\isacharbar}\ y{\isacharhash}ys\ {\isasymRightarrow}\ y{\isacharhash}{\isacharparenleft}ys{\isacharat}zs{\isacharparenright}{\isacharparenright}\ {\isacharequal}\ xs{\isacharat}zs{\isachardoublequote}%
|
8749
|
29 |
\begin{isamarkuptxt}%
|
|
30 |
\noindent
|
|
31 |
becomes
|
|
32 |
\begin{isabellepar}%
|
|
33 |
~1.~(xs~=~[]~{\isasymlongrightarrow}~zs~=~xs~@~zs)~{\isasymand}\isanewline
|
|
34 |
~~~~({\isasymforall}a~list.~xs~=~a~\#~list~{\isasymlongrightarrow}~a~\#~list~@~zs~=~xs~@~zs)%
|
|
35 |
\end{isabellepar}%
|
|
36 |
by typing%
|
|
37 |
\end{isamarkuptxt}%
|
9673
|
38 |
\isacommand{apply}{\isacharparenleft}simp\ only{\isacharcolon}\ split{\isacharcolon}\ list{\isachardot}split{\isacharparenright}%
|
8749
|
39 |
\begin{isamarkuptext}%
|
|
40 |
\noindent
|
|
41 |
In contrast to \isa{if}-expressions, the simplifier does not split
|
|
42 |
\isa{case}-expressions by default because this can lead to nontermination
|
|
43 |
in case of recursive datatypes. Again, if the \isa{only:} modifier is
|
8771
|
44 |
dropped, the above goal is solved,%
|
8749
|
45 |
\end{isamarkuptext}%
|
9673
|
46 |
\isacommand{by}{\isacharparenleft}simp\ split{\isacharcolon}\ list{\isachardot}split{\isacharparenright}%
|
8749
|
47 |
\begin{isamarkuptext}%
|
8771
|
48 |
\noindent%
|
|
49 |
which \isacommand{apply}\isa{(simp)} alone will not do.
|
|
50 |
|
8749
|
51 |
In general, every datatype $t$ comes with a theorem
|
|
52 |
\isa{$t$.split} which can be declared to be a \bfindex{split rule} either
|
|
53 |
locally as above, or by giving it the \isa{split} attribute globally:%
|
|
54 |
\end{isamarkuptext}%
|
9673
|
55 |
\isacommand{lemmas}\ {\isacharbrackleft}split{\isacharbrackright}\ {\isacharequal}\ list{\isachardot}split%
|
8749
|
56 |
\begin{isamarkuptext}%
|
|
57 |
\noindent
|
|
58 |
The \isa{split} attribute can be removed with the \isa{del} modifier,
|
|
59 |
either locally%
|
|
60 |
\end{isamarkuptext}%
|
9673
|
61 |
\isacommand{apply}{\isacharparenleft}simp\ split\ del{\isacharcolon}\ split{\isacharunderscore}if{\isacharparenright}%
|
8749
|
62 |
\begin{isamarkuptext}%
|
|
63 |
\noindent
|
|
64 |
or globally:%
|
|
65 |
\end{isamarkuptext}%
|
9673
|
66 |
\isacommand{lemmas}\ {\isacharbrackleft}split\ del{\isacharbrackright}\ {\isacharequal}\ list{\isachardot}split\isanewline
|
8749
|
67 |
\end{isabelle}%
|
9145
|
68 |
%%% Local Variables:
|
|
69 |
%%% mode: latex
|
|
70 |
%%% TeX-master: "root"
|
|
71 |
%%% End:
|