author | smolkas |
Wed, 28 Nov 2012 12:25:43 +0100 | |
changeset 50272 | 316d94b4ffe2 |
parent 49834 | b27bbb021df1 |
child 51706 | 0a4b4735d8bd |
permissions | -rw-r--r-- |
33197 | 1 |
(* Title: HOL/Nitpick_Examples/Typedef_Nits.thy |
2 |
Author: Jasmin Blanchette, TU Muenchen |
|
45035 | 3 |
Copyright 2009-2011 |
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 |
||
42959 | 14 |
nitpick_params [verbose, card = 1\<emdash>4, sat_solver = MiniSat_JNI, max_threads = 1, |
42208
02513eb26eb7
raised timeouts further, for SML/NJ -- because of variations in machines/compilers, fixed timeouts can merely prevent non-termination, not enforce particular performance characteristics.
krauss
parents:
42187
diff
changeset
|
15 |
timeout = 240] |
33197 | 16 |
|
45694
4a8743618257
prefer typedef without extra definition and alternative name;
wenzelm
parents:
45035
diff
changeset
|
17 |
definition "three = {0\<Colon>nat, 1, 2}" |
49834 | 18 |
typedef three = three |
45694
4a8743618257
prefer typedef without extra definition and alternative name;
wenzelm
parents:
45035
diff
changeset
|
19 |
unfolding three_def by blast |
33197 | 20 |
|
21 |
definition A :: three where "A \<equiv> Abs_three 0" |
|
22 |
definition B :: three where "B \<equiv> Abs_three 1" |
|
23 |
definition C :: three where "C \<equiv> Abs_three 2" |
|
24 |
||
25 |
lemma "x = (y\<Colon>three)" |
|
26 |
nitpick [expect = genuine] |
|
27 |
oops |
|
28 |
||
45694
4a8743618257
prefer typedef without extra definition and alternative name;
wenzelm
parents:
45035
diff
changeset
|
29 |
definition "one_or_two = {undefined False\<Colon>'a, undefined True}" |
4a8743618257
prefer typedef without extra definition and alternative name;
wenzelm
parents:
45035
diff
changeset
|
30 |
|
49834 | 31 |
typedef 'a one_or_two = "one_or_two :: 'a set" |
45694
4a8743618257
prefer typedef without extra definition and alternative name;
wenzelm
parents:
45035
diff
changeset
|
32 |
unfolding one_or_two_def by auto |
33197 | 33 |
|
34 |
lemma "x = (y\<Colon>unit one_or_two)" |
|
35 |
nitpick [expect = none] |
|
36 |
sorry |
|
37 |
||
38 |
lemma "x = (y\<Colon>bool one_or_two)" |
|
39 |
nitpick [expect = genuine] |
|
40 |
oops |
|
41 |
||
42 |
lemma "undefined False \<longleftrightarrow> undefined True \<Longrightarrow> x = (y\<Colon>bool one_or_two)" |
|
43 |
nitpick [expect = none] |
|
44 |
sorry |
|
45 |
||
46 |
lemma "undefined False \<longleftrightarrow> undefined True \<Longrightarrow> \<exists>x (y\<Colon>bool one_or_two). x \<noteq> y" |
|
47 |
nitpick [card = 1, expect = potential] (* unfortunate *) |
|
48 |
oops |
|
49 |
||
50 |
lemma "\<exists>x (y\<Colon>bool one_or_two). x \<noteq> y" |
|
51 |
nitpick [card = 1, expect = potential] (* unfortunate *) |
|
52 |
nitpick [card = 2, expect = none] |
|
53 |
oops |
|
54 |
||
45970
b6d0cff57d96
adjusted to set/pred distinction by means of type constructor `set`
haftmann
parents:
45694
diff
changeset
|
55 |
definition "bounded = {n\<Colon>nat. finite (UNIV \<Colon> 'a set) \<longrightarrow> n < card (UNIV \<Colon> 'a set)}" |
b6d0cff57d96
adjusted to set/pred distinction by means of type constructor `set`
haftmann
parents:
45694
diff
changeset
|
56 |
|
49834 | 57 |
typedef 'a bounded = "bounded(TYPE('a))" |
45694
4a8743618257
prefer typedef without extra definition and alternative name;
wenzelm
parents:
45035
diff
changeset
|
58 |
unfolding bounded_def |
33197 | 59 |
apply (rule_tac x = 0 in exI) |
60 |
apply (case_tac "card UNIV = 0") |
|
61 |
by auto |
|
62 |
||
63 |
lemma "x = (y\<Colon>unit bounded)" |
|
64 |
nitpick [expect = none] |
|
65 |
sorry |
|
66 |
||
67 |
lemma "x = (y\<Colon>bool bounded)" |
|
68 |
nitpick [expect = genuine] |
|
69 |
oops |
|
70 |
||
71 |
lemma "x \<noteq> (y\<Colon>bool bounded) \<Longrightarrow> z = x \<or> z = y" |
|
39362
ee65900bfced
adapt examples to latest Nitpick changes + speed them up a little bit
blanchet
parents:
38542
diff
changeset
|
72 |
nitpick [expect = potential] (* unfortunate *) |
33197 | 73 |
sorry |
74 |
||
75 |
lemma "x \<noteq> (y\<Colon>(bool \<times> bool) bounded) \<Longrightarrow> z = x \<or> z = y" |
|
42959 | 76 |
nitpick [card = 1\<emdash>5, expect = genuine] |
33197 | 77 |
oops |
78 |
||
79 |
lemma "True \<equiv> ((\<lambda>x\<Colon>bool. x) = (\<lambda>x. x))" |
|
80 |
nitpick [expect = none] |
|
81 |
by (rule True_def) |
|
82 |
||
83 |
lemma "False \<equiv> \<forall>P. P" |
|
84 |
nitpick [expect = none] |
|
85 |
by (rule False_def) |
|
86 |
||
87 |
lemma "() = Abs_unit True" |
|
88 |
nitpick [expect = none] |
|
89 |
by (rule Unity_def) |
|
90 |
||
91 |
lemma "() = Abs_unit False" |
|
92 |
nitpick [expect = none] |
|
93 |
by simp |
|
94 |
||
95 |
lemma "Rep_unit () = True" |
|
96 |
nitpick [expect = none] |
|
40590 | 97 |
by (insert Rep_unit) simp |
33197 | 98 |
|
99 |
lemma "Rep_unit () = False" |
|
100 |
nitpick [expect = genuine] |
|
101 |
oops |
|
102 |
||
37400
cf5e06d5ecaf
adjust Nitpick example to follow latest wave of renamings
blanchet
parents:
37255
diff
changeset
|
103 |
lemma "Pair a b = Abs_prod (Pair_Rep a b)" |
42959 | 104 |
nitpick [card = 1\<emdash>2, expect = none] |
33197 | 105 |
by (rule Pair_def) |
106 |
||
37400
cf5e06d5ecaf
adjust Nitpick example to follow latest wave of renamings
blanchet
parents:
37255
diff
changeset
|
107 |
lemma "Pair a b = Abs_prod (Pair_Rep b a)" |
42959 | 108 |
nitpick [card = 1\<emdash>2, expect = none] |
33197 | 109 |
nitpick [dont_box, expect = genuine] |
110 |
oops |
|
111 |
||
37400
cf5e06d5ecaf
adjust Nitpick example to follow latest wave of renamings
blanchet
parents:
37255
diff
changeset
|
112 |
lemma "fst (Abs_prod (Pair_Rep a b)) = a" |
33197 | 113 |
nitpick [card = 2, expect = none] |
37400
cf5e06d5ecaf
adjust Nitpick example to follow latest wave of renamings
blanchet
parents:
37255
diff
changeset
|
114 |
by (simp add: Pair_def [THEN sym]) |
33197 | 115 |
|
37400
cf5e06d5ecaf
adjust Nitpick example to follow latest wave of renamings
blanchet
parents:
37255
diff
changeset
|
116 |
lemma "fst (Abs_prod (Pair_Rep a b)) = b" |
42959 | 117 |
nitpick [card = 1\<emdash>2, expect = none] |
33197 | 118 |
nitpick [dont_box, expect = genuine] |
119 |
oops |
|
120 |
||
121 |
lemma "a \<noteq> a' \<Longrightarrow> Pair_Rep a b \<noteq> Pair_Rep a' b" |
|
122 |
nitpick [expect = none] |
|
123 |
apply (rule ccontr) |
|
124 |
apply simp |
|
37400
cf5e06d5ecaf
adjust Nitpick example to follow latest wave of renamings
blanchet
parents:
37255
diff
changeset
|
125 |
apply (drule subst [where P = "\<lambda>r. Abs_prod r = Abs_prod (Pair_Rep a b)"]) |
33197 | 126 |
apply (rule refl) |
37400
cf5e06d5ecaf
adjust Nitpick example to follow latest wave of renamings
blanchet
parents:
37255
diff
changeset
|
127 |
by (simp add: Pair_def [THEN sym]) |
33197 | 128 |
|
37400
cf5e06d5ecaf
adjust Nitpick example to follow latest wave of renamings
blanchet
parents:
37255
diff
changeset
|
129 |
lemma "Abs_prod (Rep_prod a) = a" |
33197 | 130 |
nitpick [card = 2, expect = none] |
37400
cf5e06d5ecaf
adjust Nitpick example to follow latest wave of renamings
blanchet
parents:
37255
diff
changeset
|
131 |
by (rule Rep_prod_inverse) |
33197 | 132 |
|
37400
cf5e06d5ecaf
adjust Nitpick example to follow latest wave of renamings
blanchet
parents:
37255
diff
changeset
|
133 |
lemma "Inl \<equiv> \<lambda>a. Abs_sum (Inl_Rep a)" |
33197 | 134 |
nitpick [card = 1, expect = none] |
37400
cf5e06d5ecaf
adjust Nitpick example to follow latest wave of renamings
blanchet
parents:
37255
diff
changeset
|
135 |
by (simp add: Inl_def o_def) |
33197 | 136 |
|
37400
cf5e06d5ecaf
adjust Nitpick example to follow latest wave of renamings
blanchet
parents:
37255
diff
changeset
|
137 |
lemma "Inl \<equiv> \<lambda>a. Abs_sum (Inr_Rep a)" |
33197 | 138 |
nitpick [card = 1, card "'a + 'a" = 2, expect = genuine] |
139 |
oops |
|
140 |
||
141 |
lemma "Inl_Rep a \<noteq> Inr_Rep a" |
|
142 |
nitpick [expect = none] |
|
143 |
by (rule Inl_Rep_not_Inr_Rep) |
|
144 |
||
37400
cf5e06d5ecaf
adjust Nitpick example to follow latest wave of renamings
blanchet
parents:
37255
diff
changeset
|
145 |
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
|
146 |
nitpick [card = 1, expect = none] |
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
blanchet
parents:
35078
diff
changeset
|
147 |
nitpick [card = 2, expect = none] |
37400
cf5e06d5ecaf
adjust Nitpick example to follow latest wave of renamings
blanchet
parents:
37255
diff
changeset
|
148 |
by (rule Rep_sum_inverse) |
33197 | 149 |
|
150 |
lemma "0::nat \<equiv> Abs_Nat Zero_Rep" |
|
35312 | 151 |
nitpick [expect = none] |
46905 | 152 |
by (rule Zero_nat_def [abs_def]) |
33197 | 153 |
|
37400
cf5e06d5ecaf
adjust Nitpick example to follow latest wave of renamings
blanchet
parents:
37255
diff
changeset
|
154 |
lemma "Suc n = Abs_Nat (Suc_Rep (Rep_Nat n))" |
35312 | 155 |
nitpick [expect = none] |
46547
d1dcb91a512e
use qualified constant names instead of suffixes (from Florian Haftmann)
huffman
parents:
46082
diff
changeset
|
156 |
by (rule Nat.Suc_def) |
33197 | 157 |
|
37400
cf5e06d5ecaf
adjust Nitpick example to follow latest wave of renamings
blanchet
parents:
37255
diff
changeset
|
158 |
lemma "Suc n = Abs_Nat (Suc_Rep (Suc_Rep (Rep_Nat n)))" |
33197 | 159 |
nitpick [expect = genuine] |
160 |
oops |
|
161 |
||
162 |
lemma "Abs_Nat (Rep_Nat a) = a" |
|
163 |
nitpick [expect = none] |
|
164 |
by (rule Rep_Nat_inverse) |
|
165 |
||
166 |
lemma "Abs_list (Rep_list a) = a" |
|
42959 | 167 |
nitpick [card = 1\<emdash>2, expect = none] |
33197 | 168 |
by (rule Rep_list_inverse) |
169 |
||
170 |
record point = |
|
171 |
Xcoord :: int |
|
172 |
Ycoord :: int |
|
173 |
||
38542
c9599ce8cbfc
adjusted to restored naming convention of logical record types
haftmann
parents:
37481
diff
changeset
|
174 |
lemma "Abs_point_ext (Rep_point_ext a) = a" |
33571 | 175 |
nitpick [expect = none] |
38542
c9599ce8cbfc
adjusted to restored naming convention of logical record types
haftmann
parents:
37481
diff
changeset
|
176 |
by (fact Rep_point_ext_inverse) |
33197 | 177 |
|
178 |
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
|
179 |
nitpick [card = 1, expect = none] |
33197 | 180 |
by (rule Fract_of_int_quotient) |
181 |
||
47908 | 182 |
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
|
183 |
nitpick [card = 1, expect = none] |
47908 | 184 |
by (rule Rep_rat_inverse) |
33197 | 185 |
|
186 |
end |