9 begin |
9 begin |
10 |
10 |
11 subsection {* booleans *} |
11 subsection {* booleans *} |
12 |
12 |
13 definition |
13 definition |
14 xor :: "bool \<Rightarrow> bool \<Rightarrow> bool" |
14 xor :: "bool \<Rightarrow> bool \<Rightarrow> bool" where |
15 "xor p q = ((p | q) & \<not> (p & q))" |
15 "xor p q = ((p | q) & \<not> (p & q))" |
16 |
16 |
17 subsection {* natural numbers *} |
17 subsection {* natural numbers *} |
18 |
18 |
19 definition |
19 definition |
20 n :: nat |
20 n :: nat where |
21 "n = 42" |
21 "n = 42" |
22 |
22 |
23 subsection {* pairs *} |
23 subsection {* pairs *} |
24 |
24 |
25 definition |
25 definition |
26 swap :: "'a * 'b \<Rightarrow> 'b * 'a" |
26 swap :: "'a * 'b \<Rightarrow> 'b * 'a" where |
27 "swap p = (let (x, y) = p in (y, x))" |
27 "swap p = (let (x, y) = p in (y, x))" |
28 appl :: "('a \<Rightarrow> 'b) * 'a \<Rightarrow> 'b" |
28 |
|
29 definition |
|
30 appl :: "('a \<Rightarrow> 'b) * 'a \<Rightarrow> 'b" where |
29 "appl p = (let (f, x) = p in f x)" |
31 "appl p = (let (f, x) = p in f x)" |
30 snd_three :: "'a * 'b * 'c => 'b" |
32 |
|
33 definition |
|
34 snd_three :: "'a * 'b * 'c => 'b" where |
31 "snd_three a = id (\<lambda>(a, b, c). b) a" |
35 "snd_three a = id (\<lambda>(a, b, c). b) a" |
32 |
36 |
33 lemma [code]: |
37 lemma [code]: |
34 "swap (x, y) = (y, x)" |
38 "swap (x, y) = (y, x)" |
35 unfolding swap_def Let_def by auto |
39 unfolding swap_def Let_def by auto |
57 subsection {* options *} |
61 subsection {* options *} |
58 |
62 |
59 subsection {* lists *} |
63 subsection {* lists *} |
60 |
64 |
61 definition |
65 definition |
62 ps :: "nat list" |
66 ps :: "nat list" where |
63 "ps = [2, 3, 5, 7, 11]" |
67 "ps = [2, 3, 5, 7, 11]" |
64 qs :: "nat list" |
68 |
|
69 definition |
|
70 qs :: "nat list" where |
65 "qs == rev ps" |
71 "qs == rev ps" |
66 |
72 |
67 subsection {* mutual datatypes *} |
73 subsection {* mutual datatypes *} |
68 |
74 |
69 datatype mut1 = Tip | Top mut2 |
75 datatype mut1 = Tip | Top mut2 |