equal
deleted
inserted
replaced
1 (* Title: HOL/Proofs/Extraction/Util.thy |
1 (* Title: HOL/Proofs/Extraction/Util.thy |
2 Author: Stefan Berghofer, TU Muenchen |
2 Author: Stefan Berghofer, TU Muenchen |
3 *) |
3 *) |
4 |
4 |
5 section {* Auxiliary lemmas used in program extraction examples *} |
5 section \<open>Auxiliary lemmas used in program extraction examples\<close> |
6 |
6 |
7 theory Util |
7 theory Util |
8 imports "~~/src/HOL/Library/Old_Datatype" |
8 imports "~~/src/HOL/Library/Old_Datatype" |
9 begin |
9 begin |
10 |
10 |
11 text {* |
11 text \<open> |
12 Decidability of equality on natural numbers. |
12 Decidability of equality on natural numbers. |
13 *} |
13 \<close> |
14 |
14 |
15 lemma nat_eq_dec: "\<And>n::nat. m = n \<or> m \<noteq> n" |
15 lemma nat_eq_dec: "\<And>n::nat. m = n \<or> m \<noteq> n" |
16 apply (induct m) |
16 apply (induct m) |
17 apply (case_tac n) |
17 apply (case_tac n) |
18 apply (case_tac [3] n) |
18 apply (case_tac [3] n) |
19 apply (simp only: nat.simps, iprover?)+ |
19 apply (simp only: nat.simps, iprover?)+ |
20 done |
20 done |
21 |
21 |
22 text {* |
22 text \<open> |
23 Well-founded induction on natural numbers, derived using the standard |
23 Well-founded induction on natural numbers, derived using the standard |
24 structural induction rule. |
24 structural induction rule. |
25 *} |
25 \<close> |
26 |
26 |
27 lemma nat_wf_ind: |
27 lemma nat_wf_ind: |
28 assumes R: "\<And>x::nat. (\<And>y. y < x \<Longrightarrow> P y) \<Longrightarrow> P x" |
28 assumes R: "\<And>x::nat. (\<And>y. y < x \<Longrightarrow> P y) \<Longrightarrow> P x" |
29 shows "P z" |
29 shows "P z" |
30 proof (rule R) |
30 proof (rule R) |
46 thus ?case by (rule Suc) |
46 thus ?case by (rule Suc) |
47 qed |
47 qed |
48 qed |
48 qed |
49 qed |
49 qed |
50 |
50 |
51 text {* |
51 text \<open> |
52 Bounded search for a natural number satisfying a decidable predicate. |
52 Bounded search for a natural number satisfying a decidable predicate. |
53 *} |
53 \<close> |
54 |
54 |
55 lemma search: |
55 lemma search: |
56 assumes dec: "\<And>x::nat. P x \<or> \<not> P x" |
56 assumes dec: "\<And>x::nat. P x \<or> \<not> P x" |
57 shows "(\<exists>x<y. P x) \<or> \<not> (\<exists>x<y. P x)" |
57 shows "(\<exists>x<y. P x) \<or> \<not> (\<exists>x<y. P x)" |
58 proof (induct y) |
58 proof (induct y) |