src/HOL/Nitpick_Examples/Manual_Nits.thy
changeset 34982 7b8c366e34a2
parent 34126 8a2c5d7aff51
child 35076 cc19e2aef17e
equal deleted inserted replaced
34981:475aef44d5fb 34982:7b8c366e34a2
   217 
   217 
   218 lemma "\<exists>g. \<forall>x\<Colon>'b. g (f x) = x \<Longrightarrow> \<forall>y\<Colon>'a. \<exists>x. y = f x"
   218 lemma "\<exists>g. \<forall>x\<Colon>'b. g (f x) = x \<Longrightarrow> \<forall>y\<Colon>'a. \<exists>x. y = f x"
   219 nitpick [mono]
   219 nitpick [mono]
   220 nitpick
   220 nitpick
   221 oops
   221 oops
       
   222 
       
   223 subsection {* 3.12. Inductive Properties *}
       
   224 
       
   225 inductive_set reach where
       
   226 "(4\<Colon>nat) \<in> reach" |
       
   227 "n \<in> reach \<Longrightarrow> n < 4 \<Longrightarrow> 3 * n + 1 \<in> reach" |
       
   228 "n \<in> reach \<Longrightarrow> n + 2 \<in> reach"
       
   229 
       
   230 lemma "n \<in> reach \<Longrightarrow> 2 dvd n"
       
   231 nitpick
       
   232 apply (induct set: reach)
       
   233   apply auto
       
   234  nitpick
       
   235  apply (thin_tac "n \<in> reach")
       
   236  nitpick
       
   237 oops
       
   238 
       
   239 lemma "n \<in> reach \<Longrightarrow> 2 dvd n \<and> n \<noteq> 0"
       
   240 nitpick
       
   241 apply (induct set: reach)
       
   242   apply auto
       
   243  nitpick
       
   244  apply (thin_tac "n \<in> reach")
       
   245  nitpick
       
   246 oops
       
   247 
       
   248 lemma "n \<in> reach \<Longrightarrow> 2 dvd n \<and> n \<ge> 4"
       
   249 by (induct set: reach) arith+
       
   250 
       
   251 datatype 'a bin_tree = Leaf 'a | Branch "'a bin_tree" "'a bin_tree"
       
   252 
       
   253 primrec labels where
       
   254 "labels (Leaf a) = {a}" |
       
   255 "labels (Branch t u) = labels t \<union> labels u"
       
   256 
       
   257 primrec swap where
       
   258 "swap (Leaf c) a b =
       
   259  (if c = a then Leaf b else if c = b then Leaf a else Leaf c)" |
       
   260 "swap (Branch t u) a b = Branch (swap t a b) (swap u a b)"
       
   261 
       
   262 lemma "\<lbrakk>a \<in> labels t; b \<in> labels t; a \<noteq> b\<rbrakk> \<Longrightarrow> labels (swap t a b) = labels t"
       
   263 nitpick
       
   264 proof (induct t)
       
   265   case Leaf thus ?case by simp
       
   266 next
       
   267   case (Branch t u) thus ?case
       
   268   nitpick
       
   269   nitpick [non_std "'a bin_tree", show_consts]
       
   270 oops
       
   271 
       
   272 lemma "labels (swap t a b) =
       
   273        (if a \<in> labels t then
       
   274           if b \<in> labels t then labels t else (labels t - {a}) \<union> {b}
       
   275         else
       
   276           if b \<in> labels t then (labels t - {b}) \<union> {a} else labels t)"
       
   277 nitpick
       
   278 proof (induct t)
       
   279   case Leaf thus ?case by simp
       
   280 next
       
   281   case (Branch t u) thus ?case
       
   282   nitpick [non_std "'a bin_tree", show_consts]
       
   283   by auto
       
   284 qed
   222 
   285 
   223 section {* 4. Case Studies *}
   286 section {* 4. Case Studies *}
   224 
   287 
   225 nitpick_params [max_potential = 0, max_threads = 2]
   288 nitpick_params [max_potential = 0, max_threads = 2]
   226 
   289 
   298 nitpick
   361 nitpick
   299 sorry
   362 sorry
   300 
   363 
   301 subsection {* 4.2. AA Trees *}
   364 subsection {* 4.2. AA Trees *}
   302 
   365 
   303 datatype 'a tree = \<Lambda> | N "'a\<Colon>linorder" nat "'a tree" "'a tree"
   366 datatype 'a aa_tree = \<Lambda> | N "'a\<Colon>linorder" nat "'a aa_tree" "'a aa_tree"
   304 
   367 
   305 primrec data where
   368 primrec data where
   306 "data \<Lambda> = undefined" |
   369 "data \<Lambda> = undefined" |
   307 "data (N x _ _ _) = x"
   370 "data (N x _ _ _) = x"
   308 
   371