doc-src/TutorialI/Misc/case_splits.thy
author wenzelm
Tue, 01 Aug 2000 13:43:22 +0200
changeset 9490 c2606af9922c
parent 9458 c613cd06d5cf
child 9541 d17c0b34d5c8
permissions -rw-r--r--
tuned msg;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
8745
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
     1
(*<*)
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
     2
theory case_splits = Main:;
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
     3
(*>*)
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
     4
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
     5
text{*
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
     6
Goals containing \isaindex{if}-expressions are usually proved by case
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
     7
distinction on the condition of the \isa{if}. For example the goal
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
     8
*}
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
     9
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    10
lemma "\\<forall>xs. if xs = [] then rev xs = [] else rev xs \\<noteq> []";
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    11
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    12
txt{*\noindent
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    13
can be split into
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    14
\begin{isabellepar}%
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    15
~1.~{\isasymforall}xs.~(xs~=~[]~{\isasymlongrightarrow}~rev~xs~=~[])~{\isasymand}~(xs~{\isasymnoteq}~[]~{\isasymlongrightarrow}~rev~xs~{\isasymnoteq}~[])%
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    16
\end{isabellepar}%
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    17
by a degenerate form of simplification
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    18
*}
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    19
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    20
apply(simp only: split: split_if);
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    21
(*<*)oops;(*>*)
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    22
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    23
text{*\noindent
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    24
where no simplification rules are included (\isa{only:} is followed by the
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    25
empty list of theorems) but the rule \isaindexbold{split_if} for
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    26
splitting \isa{if}s is added (via the modifier \isa{split:}). Because
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    27
case-splitting on \isa{if}s is almost always the right proof strategy, the
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    28
simplifier performs it automatically. Try \isacommand{apply}\isa{(simp)}
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    29
on the initial goal above.
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    30
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    31
This splitting idea generalizes from \isa{if} to \isaindex{case}:
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    32
*}
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    33
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    34
lemma "(case xs of [] \\<Rightarrow> zs | y#ys \\<Rightarrow> y#(ys@zs)) = xs@zs";
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    35
txt{*\noindent
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    36
becomes
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    37
\begin{isabellepar}%
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    38
~1.~(xs~=~[]~{\isasymlongrightarrow}~zs~=~xs~@~zs)~{\isasymand}\isanewline
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    39
~~~~({\isasymforall}a~list.~xs~=~a~\#~list~{\isasymlongrightarrow}~a~\#~list~@~zs~=~xs~@~zs)%
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    40
\end{isabellepar}%
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    41
by typing
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    42
*}
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    43
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    44
apply(simp only: split: list.split);
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    45
(*<*)oops;(*>*)
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    46
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    47
text{*\noindent
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    48
In contrast to \isa{if}-expressions, the simplifier does not split
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    49
\isa{case}-expressions by default because this can lead to nontermination
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    50
in case of recursive datatypes. Again, if the \isa{only:} modifier is
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8745
diff changeset
    51
dropped, the above goal is solved,
8745
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    52
*}
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    53
(*<*)
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    54
lemma "(case xs of [] \\<Rightarrow> zs | y#ys \\<Rightarrow> y#(ys@zs)) = xs@zs";
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    55
(*>*)
9458
c613cd06d5cf apply. -> by
nipkow
parents: 8771
diff changeset
    56
by(simp split: list.split);
8745
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    57
8771
026f37a86ea7 *** empty log message ***
nipkow
parents: 8745
diff changeset
    58
text{*\noindent%
026f37a86ea7 *** empty log message ***
nipkow
parents: 8745
diff changeset
    59
which \isacommand{apply}\isa{(simp)} alone will not do.
026f37a86ea7 *** empty log message ***
nipkow
parents: 8745
diff changeset
    60
8745
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    61
In general, every datatype $t$ comes with a theorem
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    62
\isa{$t$.split} which can be declared to be a \bfindex{split rule} either
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    63
locally as above, or by giving it the \isa{split} attribute globally:
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    64
*}
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    65
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    66
theorems [split] = list.split;
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    67
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    68
text{*\noindent
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    69
The \isa{split} attribute can be removed with the \isa{del} modifier,
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    70
either locally
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    71
*}
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    72
(*<*)
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    73
lemma "dummy=dummy";
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    74
(*>*)
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    75
apply(simp split del: split_if);
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    76
(*<*)
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    77
oops;
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    78
(*>*)
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    79
text{*\noindent
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    80
or globally:
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    81
*}
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    82
theorems [split del] = list.split;
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    83
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    84
(*<*)
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    85
end
13b32661dde4 I wonder which files i forgot.
nipkow
parents:
diff changeset
    86
(*>*)