equal
deleted
inserted
replaced
1 (*<*) |
1 (*<*) |
2 theory "cases" = Main:; |
2 theory "cases" = Main:; |
3 (*>*) |
3 (*>*) |
|
4 |
|
5 subsection{*Structural induction and case distinction*} |
|
6 |
|
7 text{* |
|
8 \indexbold{structural induction} |
|
9 \indexbold{induction!structural} |
|
10 \indexbold{case distinction} |
|
11 Almost all the basic laws about a datatype are applied automatically during |
|
12 simplification. Only induction is invoked by hand via \isaindex{induct_tac}, |
|
13 which works for any datatype. In some cases, induction is overkill and a case |
|
14 distinction over all constructors of the datatype suffices. This is performed |
|
15 by \isaindexbold{case_tac}. A trivial example: |
|
16 *} |
4 |
17 |
5 lemma "(case xs of [] \\<Rightarrow> [] | y#ys \\<Rightarrow> xs) = xs"; |
18 lemma "(case xs of [] \\<Rightarrow> [] | y#ys \\<Rightarrow> xs) = xs"; |
6 apply(case_tac xs); |
19 apply(case_tac xs); |
7 |
20 |
8 txt{*\noindent |
21 txt{*\noindent |
12 ~2.~{\isasymAnd}a~list.~xs=a\#list~{\isasymLongrightarrow}~(case~xs~of~[]~{\isasymRightarrow}~[]~|~y\#ys~{\isasymRightarrow}~xs)~=~xs% |
25 ~2.~{\isasymAnd}a~list.~xs=a\#list~{\isasymLongrightarrow}~(case~xs~of~[]~{\isasymRightarrow}~[]~|~y\#ys~{\isasymRightarrow}~xs)~=~xs% |
13 \end{isabellepar}% |
26 \end{isabellepar}% |
14 which is solved automatically: |
27 which is solved automatically: |
15 *} |
28 *} |
16 |
29 |
17 by(auto); |
30 by(auto) |
18 (**) |
31 |
|
32 text{* |
|
33 Note that we do not need to give a lemma a name if we do not intend to refer |
|
34 to it explicitly in the future. |
|
35 *} |
|
36 |
19 (*<*) |
37 (*<*) |
20 end |
38 end |
21 (*>*) |
39 (*>*) |