8745
|
1 |
(*<*)
|
|
2 |
theory case_splits = Main:;
|
|
3 |
(*>*)
|
|
4 |
|
|
5 |
text{*
|
9792
|
6 |
Goals containing @{text"if"}-expressions are usually proved by case
|
|
7 |
distinction on the condition of the @{text"if"}. For example the goal
|
8745
|
8 |
*}
|
|
9 |
|
|
10 |
lemma "\\<forall>xs. if xs = [] then rev xs = [] else rev xs \\<noteq> []";
|
|
11 |
|
|
12 |
txt{*\noindent
|
|
13 |
can be split into
|
9723
|
14 |
\begin{isabelle}
|
9792
|
15 |
~1.~{\isasymforall}xs.~(xs~=~[]~{\isasymlongrightarrow}~rev~xs~=~[])~{\isasymand}~(xs~{\isasymnoteq}~[]~{\isasymlongrightarrow}~rev~xs~{\isasymnoteq}~[])
|
9723
|
16 |
\end{isabelle}
|
8745
|
17 |
by a degenerate form of simplification
|
|
18 |
*}
|
|
19 |
|
|
20 |
apply(simp only: split: split_if);
|
|
21 |
(*<*)oops;(*>*)
|
|
22 |
|
|
23 |
text{*\noindent
|
9792
|
24 |
where no simplification rules are included (@{text"only:"} is followed by the
|
8745
|
25 |
empty list of theorems) but the rule \isaindexbold{split_if} for
|
9792
|
26 |
splitting @{text"if"}s is added (via the modifier @{text"split:"}). Because
|
|
27 |
case-splitting on @{text"if"}s is almost always the right proof strategy, the
|
|
28 |
simplifier performs it automatically. Try \isacommand{apply}@{text"(simp)"}
|
8745
|
29 |
on the initial goal above.
|
|
30 |
|
9792
|
31 |
This splitting idea generalizes from @{text"if"} to \isaindex{case}:
|
8745
|
32 |
*}
|
|
33 |
|
|
34 |
lemma "(case xs of [] \\<Rightarrow> zs | y#ys \\<Rightarrow> y#(ys@zs)) = xs@zs";
|
|
35 |
txt{*\noindent
|
|
36 |
becomes
|
9723
|
37 |
\begin{isabelle}
|
8745
|
38 |
~1.~(xs~=~[]~{\isasymlongrightarrow}~zs~=~xs~@~zs)~{\isasymand}\isanewline
|
9792
|
39 |
~~~~({\isasymforall}a~list.~xs~=~a~\#~list~{\isasymlongrightarrow}~a~\#~list~@~zs~=~xs~@~zs)
|
9723
|
40 |
\end{isabelle}
|
8745
|
41 |
by typing
|
|
42 |
*}
|
|
43 |
|
|
44 |
apply(simp only: split: list.split);
|
|
45 |
(*<*)oops;(*>*)
|
|
46 |
|
|
47 |
text{*\noindent
|
9792
|
48 |
In contrast to @{text"if"}-expressions, the simplifier does not split
|
|
49 |
@{text"case"}-expressions by default because this can lead to nontermination
|
|
50 |
in case of recursive datatypes. Again, if the @{text"only:"} modifier is
|
8771
|
51 |
dropped, the above goal is solved,
|
8745
|
52 |
*}
|
|
53 |
(*<*)
|
|
54 |
lemma "(case xs of [] \\<Rightarrow> zs | y#ys \\<Rightarrow> y#(ys@zs)) = xs@zs";
|
|
55 |
(*>*)
|
9458
|
56 |
by(simp split: list.split);
|
8745
|
57 |
|
8771
|
58 |
text{*\noindent%
|
9792
|
59 |
which \isacommand{apply}@{text"(simp)"} alone will not do.
|
8771
|
60 |
|
8745
|
61 |
In general, every datatype $t$ comes with a theorem
|
9792
|
62 |
$t$@{text".split"} which can be declared to be a \bfindex{split rule} either
|
|
63 |
locally as above, or by giving it the @{text"split"} attribute globally:
|
8745
|
64 |
*}
|
|
65 |
|
9541
|
66 |
lemmas [split] = list.split;
|
8745
|
67 |
|
|
68 |
text{*\noindent
|
9792
|
69 |
The @{text"split"} attribute can be removed with the @{text"del"} modifier,
|
8745
|
70 |
either locally
|
|
71 |
*}
|
|
72 |
(*<*)
|
|
73 |
lemma "dummy=dummy";
|
|
74 |
(*>*)
|
|
75 |
apply(simp split del: split_if);
|
|
76 |
(*<*)
|
|
77 |
oops;
|
|
78 |
(*>*)
|
|
79 |
text{*\noindent
|
|
80 |
or globally:
|
|
81 |
*}
|
9541
|
82 |
lemmas [split del] = list.split;
|
8745
|
83 |
|
9721
|
84 |
text{*
|
|
85 |
The above split rules intentionally only affect the conclusion of a
|
9792
|
86 |
subgoal. If you want to split an @{text"if"} or @{text"case"}-expression in
|
|
87 |
the assumptions, you have to apply @{thm[source]split_if_asm} or
|
|
88 |
$t$@{text".split_asm"}:
|
9721
|
89 |
*}
|
|
90 |
|
|
91 |
lemma "if xs = [] then ys ~= [] else ys = [] ==> xs @ ys ~= []"
|
|
92 |
apply(simp only: split: split_if_asm);
|
|
93 |
|
|
94 |
txt{*\noindent
|
|
95 |
In contrast to splitting the conclusion, this actually creates two
|
9792
|
96 |
separate subgoals (which are solved by @{text"simp_all"}):
|
9721
|
97 |
\begin{isabelle}
|
|
98 |
\ \isadigit{1}{\isachardot}\ {\isasymlbrakk}\mbox{xs}\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}{\isacharsemicolon}\ \mbox{ys}\ {\isasymnoteq}\ {\isacharbrackleft}{\isacharbrackright}{\isasymrbrakk}\ {\isasymLongrightarrow}\ {\isacharbrackleft}{\isacharbrackright}\ {\isacharat}\ \mbox{ys}\ {\isasymnoteq}\ {\isacharbrackleft}{\isacharbrackright}\isanewline
|
|
99 |
\ \isadigit{2}{\isachardot}\ {\isasymlbrakk}\mbox{xs}\ {\isasymnoteq}\ {\isacharbrackleft}{\isacharbrackright}{\isacharsemicolon}\ \mbox{ys}\ {\isacharequal}\ {\isacharbrackleft}{\isacharbrackright}{\isasymrbrakk}\ {\isasymLongrightarrow}\ \mbox{xs}\ {\isacharat}\ {\isacharbrackleft}{\isacharbrackright}\ {\isasymnoteq}\ {\isacharbrackleft}{\isacharbrackright}
|
|
100 |
\end{isabelle}
|
|
101 |
If you need to split both in the assumptions and the conclusion,
|
9792
|
102 |
use $t$@{text".splits"} which subsumes $t$@{text".split"} and
|
|
103 |
$t$@{text".split_asm"}. Analogously, there is @{thm[source]if_splits}.
|
9721
|
104 |
*}
|
|
105 |
|
8745
|
106 |
(*<*)
|
9721
|
107 |
by(simp_all)
|
8745
|
108 |
end
|
|
109 |
(*>*)
|