equal
deleted
inserted
replaced
1 (*<*)theory AB = Main:(*>*) |
1 (*<*)theory AB = Main:(*>*) |
2 |
2 |
3 section{*Case Study: A Context Free Grammar*} |
3 section{*Case Study: A Context Free Grammar*} |
4 |
4 |
5 text{*\label{sec:CFG} |
5 text{*\label{sec:CFG} |
|
6 \index{grammars!defining inductively|(}% |
6 Grammars are nothing but shorthands for inductive definitions of nonterminals |
7 Grammars are nothing but shorthands for inductive definitions of nonterminals |
7 which represent sets of strings. For example, the production |
8 which represent sets of strings. For example, the production |
8 $A \to B c$ is short for |
9 $A \to B c$ is short for |
9 \[ w \in B \Longrightarrow wc \in A \] |
10 \[ w \in B \Longrightarrow wc \in A \] |
10 This section demonstrates this idea with an example |
11 This section demonstrates this idea with an example |
134 apply(induct w); |
135 apply(induct w); |
135 apply(simp); |
136 apply(simp); |
136 by(force simp add:zabs_def take_Cons split:nat.split if_splits); |
137 by(force simp add:zabs_def take_Cons split:nat.split if_splits); |
137 |
138 |
138 text{* |
139 text{* |
139 Finally we come to the above mentioned lemma about cutting in half a word with two |
140 Finally we come to the above-mentioned lemma about cutting in half a word with two more elements of one sort than of the other sort: |
140 more elements of one sort than of the other sort: |
|
141 *} |
141 *} |
142 |
142 |
143 lemma part1: |
143 lemma part1: |
144 "size[x\<in>w. P x] = size[x\<in>w. \<not>P x]+2 \<Longrightarrow> |
144 "size[x\<in>w. P x] = size[x\<in>w. \<not>P x]+2 \<Longrightarrow> |
145 \<exists>i\<le>size w. size[x\<in>take i w. P x] = size[x\<in>take i w. \<not>P x]+1"; |
145 \<exists>i\<le>size w. size[x\<in>take i w. P x] = size[x\<in>take i w. \<not>P x]+1"; |
210 rule to use. For details see \S\ref{sec:complete-ind} below. |
210 rule to use. For details see \S\ref{sec:complete-ind} below. |
211 In this case the result is that we may assume the lemma already |
211 In this case the result is that we may assume the lemma already |
212 holds for all words shorter than @{term w}. |
212 holds for all words shorter than @{term w}. |
213 |
213 |
214 The proof continues with a case distinction on @{term w}, |
214 The proof continues with a case distinction on @{term w}, |
215 i.e.\ if @{term w} is empty or not. |
215 on whether @{term w} is empty or not. |
216 *} |
216 *} |
217 |
217 |
218 apply(case_tac w); |
218 apply(case_tac w); |
219 apply(simp_all); |
219 apply(simp_all); |
220 (*<*)apply(rename_tac x v)(*>*) |
220 (*<*)apply(rename_tac x v)(*>*) |
283 apply(force simp add:min_less_iff_disj) |
283 apply(force simp add:min_less_iff_disj) |
284 by(force simp add:min_less_iff_disj split add: nat_diff_split) |
284 by(force simp add:min_less_iff_disj split add: nat_diff_split) |
285 |
285 |
286 text{* |
286 text{* |
287 We conclude this section with a comparison of our proof with |
287 We conclude this section with a comparison of our proof with |
288 Hopcroft and Ullman's \cite[p.\ts81]{HopcroftUllman}. For a start, the textbook |
288 Hopcroft\index{Hopcroft, J. E.} and Ullman's\index{Ullman, J. D.} |
|
289 \cite[p.\ts81]{HopcroftUllman}. |
|
290 For a start, the textbook |
289 grammar, for no good reason, excludes the empty word, thus complicating |
291 grammar, for no good reason, excludes the empty word, thus complicating |
290 matters just a little bit: they have 8 instead of our 7 productions. |
292 matters just a little bit: they have 8 instead of our 7 productions. |
291 |
293 |
292 More importantly, the proof itself is different: rather than |
294 More importantly, the proof itself is different: rather than |
293 separating the two directions, they perform one induction on the |
295 separating the two directions, they perform one induction on the |
300 proof for part (1); this part is left to the reader''. But this is |
302 proof for part (1); this part is left to the reader''. But this is |
301 precisely the part that requires the intermediate value theorem and |
303 precisely the part that requires the intermediate value theorem and |
302 thus is not at all similar to the other cases (which are automatic in |
304 thus is not at all similar to the other cases (which are automatic in |
303 Isabelle). The authors are at least cavalier about this point and may |
305 Isabelle). The authors are at least cavalier about this point and may |
304 even have overlooked the slight difficulty lurking in the omitted |
306 even have overlooked the slight difficulty lurking in the omitted |
305 cases. This is not atypical for pen-and-paper proofs, once analysed in |
307 cases. Such errors are found in many pen-and-paper proofs when they |
306 detail. *} |
308 are scrutinized formally.% |
|
309 \index{grammars!defining inductively|)} |
|
310 *} |
307 |
311 |
308 (*<*)end(*>*) |
312 (*<*)end(*>*) |