8745
|
1 |
(*<*)
|
|
2 |
theory cond_rewr = Main:;
|
|
3 |
(*>*)
|
|
4 |
|
|
5 |
text{*
|
|
6 |
So far all examples of rewrite rules were equations. The simplifier also
|
|
7 |
accepts \emph{conditional} equations, for example
|
|
8 |
*}
|
|
9 |
|
|
10 |
lemma hd_Cons_tl[simp]: "xs \\<noteq> [] \\<Longrightarrow> hd xs # tl xs = xs";
|
|
11 |
apply(case_tac xs, simp, simp).;
|
|
12 |
|
|
13 |
text{*\noindent
|
|
14 |
Note the use of ``\ttindexboldpos{,}{$Isar}'' to string together a
|
|
15 |
sequence of methods. Assuming that the simplification rule
|
|
16 |
*}(*<*)term(*>*) "(rev xs = []) = (xs = [])";
|
|
17 |
text{*\noindent
|
|
18 |
is present as well,
|
|
19 |
*}
|
|
20 |
|
|
21 |
lemma "xs \\<noteq> [] \\<Longrightarrow> hd(rev xs) # tl(rev xs) = rev xs";
|
|
22 |
(*<*)
|
|
23 |
apply(simp).
|
|
24 |
(*>*)
|
|
25 |
text{*\noindent
|
8771
|
26 |
is proved by plain simplification:
|
8745
|
27 |
the conditional equation \isa{hd_Cons_tl} above
|
|
28 |
can simplify \isa{hd(rev~xs)~\#~tl(rev~xs)} to \isa{rev xs}
|
|
29 |
because the corresponding precondition \isa{rev xs \isasymnoteq\ []}
|
|
30 |
simplifies to \isa{xs \isasymnoteq\ []}, which is exactly the local
|
|
31 |
assumption of the subgoal.
|
|
32 |
*}
|
|
33 |
(*<*)
|
|
34 |
end
|
|
35 |
(*>*)
|