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";
|
9458
|
11 |
by(case_tac xs, simp, simp);
|
8745
|
12 |
|
|
13 |
text{*\noindent
|
|
14 |
Note the use of ``\ttindexboldpos{,}{$Isar}'' to string together a
|
|
15 |
sequence of methods. Assuming that the simplification rule
|
9541
|
16 |
@{term"(rev xs = []) = (xs = [])"}
|
8745
|
17 |
is present as well,
|
|
18 |
*}
|
|
19 |
|
|
20 |
lemma "xs \\<noteq> [] \\<Longrightarrow> hd(rev xs) # tl(rev xs) = rev xs";
|
|
21 |
(*<*)
|
9458
|
22 |
by(simp);
|
8745
|
23 |
(*>*)
|
|
24 |
text{*\noindent
|
8771
|
25 |
is proved by plain simplification:
|
9792
|
26 |
the conditional equation @{thm[source]hd_Cons_tl} above
|
|
27 |
can simplify @{term"hd(rev xs) # tl(rev xs)"} to @{term"rev xs"}
|
|
28 |
because the corresponding precondition @{term"rev xs ~= []"}
|
|
29 |
simplifies to @{term"xs ~= []"}, which is exactly the local
|
8745
|
30 |
assumption of the subgoal.
|
|
31 |
*}
|
|
32 |
(*<*)
|
|
33 |
end
|
|
34 |
(*>*)
|