author | haftmann |
Wed, 24 Feb 2010 14:34:40 +0100 | |
changeset 35372 | ca158c7b1144 |
parent 35312 | 99cd1f96b400 |
child 35387 | 4356263e0bdd |
permissions | -rw-r--r-- |
33197 | 1 |
(* Title: HOL/Nitpick_Examples/Typedef_Nits.thy |
2 |
Author: Jasmin Blanchette, TU Muenchen |
|
35076
cc19e2aef17e
added hotel key card example for Nitpick, and renumber atoms in Nitpick's output for increased readability
blanchet
parents:
34126
diff
changeset
|
3 |
Copyright 2009, 2010 |
33197 | 4 |
|
5 |
Examples featuring Nitpick applied to typedefs. |
|
6 |
*) |
|
7 |
||
8 |
header {* Examples Featuring Nitpick Applied to Typedefs *} |
|
9 |
||
10 |
theory Typedef_Nits |
|
35372 | 11 |
imports Complex_Main |
33197 | 12 |
begin |
13 |
||
35284
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35078
diff
changeset
|
14 |
nitpick_params [card = 1\<midarrow>4, sat_solver = MiniSat_JNI, max_threads = 1, |
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35078
diff
changeset
|
15 |
timeout = 60 s] |
33197 | 16 |
|
17 |
typedef three = "{0\<Colon>nat, 1, 2}" |
|
18 |
by blast |
|
19 |
||
20 |
definition A :: three where "A \<equiv> Abs_three 0" |
|
21 |
definition B :: three where "B \<equiv> Abs_three 1" |
|
22 |
definition C :: three where "C \<equiv> Abs_three 2" |
|
23 |
||
24 |
lemma "x = (y\<Colon>three)" |
|
25 |
nitpick [expect = genuine] |
|
26 |
oops |
|
27 |
||
28 |
typedef 'a one_or_two = "{undefined False\<Colon>'a, undefined True}" |
|
29 |
by auto |
|
30 |
||
31 |
lemma "x = (y\<Colon>unit one_or_two)" |
|
32 |
nitpick [expect = none] |
|
33 |
sorry |
|
34 |
||
35 |
lemma "x = (y\<Colon>bool one_or_two)" |
|
36 |
nitpick [expect = genuine] |
|
37 |
oops |
|
38 |
||
39 |
lemma "undefined False \<longleftrightarrow> undefined True \<Longrightarrow> x = (y\<Colon>bool one_or_two)" |
|
40 |
nitpick [expect = none] |
|
41 |
sorry |
|
42 |
||
43 |
lemma "undefined False \<longleftrightarrow> undefined True \<Longrightarrow> \<exists>x (y\<Colon>bool one_or_two). x \<noteq> y" |
|
44 |
nitpick [card = 1, expect = potential] (* unfortunate *) |
|
45 |
oops |
|
46 |
||
47 |
lemma "\<exists>x (y\<Colon>bool one_or_two). x \<noteq> y" |
|
48 |
nitpick [card = 1, expect = potential] (* unfortunate *) |
|
49 |
nitpick [card = 2, expect = none] |
|
50 |
oops |
|
51 |
||
52 |
typedef 'a bounded = |
|
53 |
"{n\<Colon>nat. finite (UNIV\<Colon>'a \<Rightarrow> bool) \<longrightarrow> n < card (UNIV\<Colon>'a \<Rightarrow> bool)}" |
|
54 |
apply (rule_tac x = 0 in exI) |
|
55 |
apply (case_tac "card UNIV = 0") |
|
56 |
by auto |
|
57 |
||
58 |
lemma "x = (y\<Colon>unit bounded)" |
|
59 |
nitpick [expect = none] |
|
60 |
sorry |
|
61 |
||
62 |
lemma "x = (y\<Colon>bool bounded)" |
|
63 |
nitpick [expect = genuine] |
|
64 |
oops |
|
65 |
||
66 |
lemma "x \<noteq> (y\<Colon>bool bounded) \<Longrightarrow> z = x \<or> z = y" |
|
67 |
nitpick [expect = none] |
|
68 |
sorry |
|
69 |
||
70 |
lemma "x \<noteq> (y\<Colon>(bool \<times> bool) bounded) \<Longrightarrow> z = x \<or> z = y" |
|
34126 | 71 |
nitpick [card = 1\<midarrow>5, expect = genuine] |
33197 | 72 |
oops |
73 |
||
74 |
lemma "True \<equiv> ((\<lambda>x\<Colon>bool. x) = (\<lambda>x. x))" |
|
75 |
nitpick [expect = none] |
|
76 |
by (rule True_def) |
|
77 |
||
78 |
lemma "False \<equiv> \<forall>P. P" |
|
79 |
nitpick [expect = none] |
|
80 |
by (rule False_def) |
|
81 |
||
82 |
lemma "() = Abs_unit True" |
|
83 |
nitpick [expect = none] |
|
84 |
by (rule Unity_def) |
|
85 |
||
86 |
lemma "() = Abs_unit False" |
|
87 |
nitpick [expect = none] |
|
88 |
by simp |
|
89 |
||
90 |
lemma "Rep_unit () = True" |
|
91 |
nitpick [expect = none] |
|
92 |
by (insert Rep_unit) (simp add: unit_def) |
|
93 |
||
94 |
lemma "Rep_unit () = False" |
|
95 |
nitpick [expect = genuine] |
|
96 |
oops |
|
97 |
||
98 |
lemma "Pair a b \<equiv> Abs_Prod (Pair_Rep a b)" |
|
99 |
nitpick [card = 1\<midarrow>2, expect = none] |
|
100 |
by (rule Pair_def) |
|
101 |
||
102 |
lemma "Pair a b \<equiv> Abs_Prod (Pair_Rep b a)" |
|
103 |
nitpick [card = 1\<midarrow>2, expect = none] |
|
104 |
nitpick [dont_box, expect = genuine] |
|
105 |
oops |
|
106 |
||
107 |
lemma "fst (Abs_Prod (Pair_Rep a b)) = a" |
|
108 |
nitpick [card = 2, expect = none] |
|
109 |
by (simp add: Pair_def [THEN symmetric]) |
|
110 |
||
111 |
lemma "fst (Abs_Prod (Pair_Rep a b)) = b" |
|
112 |
nitpick [card = 1\<midarrow>2, expect = none] |
|
113 |
nitpick [dont_box, expect = genuine] |
|
114 |
oops |
|
115 |
||
116 |
lemma "a \<noteq> a' \<Longrightarrow> Pair_Rep a b \<noteq> Pair_Rep a' b" |
|
117 |
nitpick [expect = none] |
|
118 |
apply (rule ccontr) |
|
119 |
apply simp |
|
120 |
apply (drule subst [where P = "\<lambda>r. Abs_Prod r = Abs_Prod (Pair_Rep a b)"]) |
|
121 |
apply (rule refl) |
|
122 |
by (simp add: Pair_def [THEN symmetric]) |
|
123 |
||
124 |
lemma "Abs_Prod (Rep_Prod a) = a" |
|
125 |
nitpick [card = 2, expect = none] |
|
126 |
by (rule Rep_Prod_inverse) |
|
127 |
||
128 |
lemma "Inl \<equiv> \<lambda>a. Abs_Sum (Inl_Rep a)" |
|
129 |
nitpick [card = 1, expect = none] |
|
33979 | 130 |
by (simp only: Inl_def o_def) |
33197 | 131 |
|
132 |
lemma "Inl \<equiv> \<lambda>a. Abs_Sum (Inr_Rep a)" |
|
133 |
nitpick [card = 1, card "'a + 'a" = 2, expect = genuine] |
|
134 |
oops |
|
135 |
||
136 |
lemma "Inl_Rep a \<noteq> Inr_Rep a" |
|
137 |
nitpick [expect = none] |
|
138 |
by (rule Inl_Rep_not_Inr_Rep) |
|
139 |
||
140 |
lemma "Abs_Sum (Rep_Sum a) = a" |
|
35284
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35078
diff
changeset
|
141 |
nitpick [card = 1, expect = none] |
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35078
diff
changeset
|
142 |
nitpick [card = 2, expect = none] |
33197 | 143 |
by (rule Rep_Sum_inverse) |
144 |
||
145 |
lemma "0::nat \<equiv> Abs_Nat Zero_Rep" |
|
35312 | 146 |
nitpick [expect = none] |
33197 | 147 |
by (rule Zero_nat_def_raw) |
148 |
||
149 |
lemma "Suc \<equiv> \<lambda>n. Abs_Nat (Suc_Rep (Rep_Nat n))" |
|
35312 | 150 |
nitpick [expect = none] |
33197 | 151 |
by (rule Suc_def) |
152 |
||
153 |
lemma "Suc \<equiv> \<lambda>n. Abs_Nat (Suc_Rep (Suc_Rep (Rep_Nat n)))" |
|
154 |
nitpick [expect = genuine] |
|
155 |
oops |
|
156 |
||
157 |
lemma "Abs_Nat (Rep_Nat a) = a" |
|
158 |
nitpick [expect = none] |
|
159 |
by (rule Rep_Nat_inverse) |
|
160 |
||
161 |
lemma "0 \<equiv> Abs_Integ (intrel `` {(0, 0)})" |
|
34126 | 162 |
nitpick [card = 1, unary_ints, max_potential = 0, expect = none] |
33197 | 163 |
by (rule Zero_int_def_raw) |
164 |
||
165 |
lemma "Abs_Integ (Rep_Integ a) = a" |
|
34126 | 166 |
nitpick [card = 1, unary_ints, max_potential = 0, expect = none] |
33197 | 167 |
by (rule Rep_Integ_inverse) |
168 |
||
169 |
lemma "Abs_list (Rep_list a) = a" |
|
34126 | 170 |
nitpick [card = 1\<midarrow>2, expect = none] |
33197 | 171 |
by (rule Rep_list_inverse) |
172 |
||
173 |
record point = |
|
174 |
Xcoord :: int |
|
175 |
Ycoord :: int |
|
176 |
||
177 |
lemma "Abs_point_ext_type (Rep_point_ext_type a) = a" |
|
33571 | 178 |
nitpick [expect = none] |
33197 | 179 |
by (rule Rep_point_ext_type_inverse) |
180 |
||
181 |
lemma "Fract a b = of_int a / of_int b" |
|
33737
e441fede163d
fixed "expect" of Nitpick examples to reflect latest changes in Nitpick
blanchet
parents:
33571
diff
changeset
|
182 |
nitpick [card = 1, expect = none] |
33197 | 183 |
by (rule Fract_of_int_quotient) |
184 |
||
185 |
lemma "Abs_Rat (Rep_Rat a) = a" |
|
33737
e441fede163d
fixed "expect" of Nitpick examples to reflect latest changes in Nitpick
blanchet
parents:
33571
diff
changeset
|
186 |
nitpick [card = 1, expect = none] |
33197 | 187 |
by (rule Rep_Rat_inverse) |
188 |
||
189 |
end |