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