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