src/HOL/Nitpick_Examples/Manual_Nits.thy
changeset 38184 6a221fffbc8a
parent 37477 e482320bcbfe
child 38242 f26d590dce0f
equal deleted inserted replaced
38183:e3bb14be0931 38184:6a221fffbc8a
   156 lemma "\<exists>n. even n \<and> even (Suc n)"
   156 lemma "\<exists>n. even n \<and> even (Suc n)"
   157 nitpick [card nat = 50, unary_ints, verbose, expect = potential]
   157 nitpick [card nat = 50, unary_ints, verbose, expect = potential]
   158 oops
   158 oops
   159 
   159 
   160 lemma "\<exists>n \<le> 49. even n \<and> even (Suc n)"
   160 lemma "\<exists>n \<le> 49. even n \<and> even (Suc n)"
   161 nitpick [card nat = 50, unary_ints, verbose, expect = genuine]
   161 nitpick [card nat = 50, unary_ints, expect = genuine]
   162 oops
   162 oops
   163 
   163 
   164 inductive even' where
   164 inductive even' where
   165 "even' (0\<Colon>nat)" |
   165 "even' (0\<Colon>nat)" |
   166 "even' 2" |
   166 "even' 2" |
   190 oops
   190 oops
   191 
   191 
   192 subsection {* 3.9. Coinductive Datatypes *}
   192 subsection {* 3.9. Coinductive Datatypes *}
   193 
   193 
   194 (* Lazy lists are defined in Andreas Lochbihler's "Coinductive" AFP entry. Since
   194 (* Lazy lists are defined in Andreas Lochbihler's "Coinductive" AFP entry. Since
   195 we cannot rely on its presence, we expediently provide our own axiomatization.
   195    we cannot rely on its presence, we expediently provide our own
   196 The examples also work unchanged with Lochbihler's "Coinductive_List" theory. *)
   196    axiomatization. The examples also work unchanged with Lochbihler's
       
   197    "Coinductive_List" theory. *)
   197 
   198 
   198 typedef 'a llist = "UNIV\<Colon>('a list + (nat \<Rightarrow> 'a)) set" by auto
   199 typedef 'a llist = "UNIV\<Colon>('a list + (nat \<Rightarrow> 'a)) set" by auto
   199 
   200 
   200 definition LNil where
   201 definition LNil where
   201 "LNil = Abs_llist (Inl [])"
   202 "LNil = Abs_llist (Inl [])"
   223 nitpick [verbose, expect = genuine]
   224 nitpick [verbose, expect = genuine]
   224 oops
   225 oops
   225 
   226 
   226 lemma "\<lbrakk>xs = LCons a xs; ys = LCons a ys\<rbrakk> \<Longrightarrow> xs = ys"
   227 lemma "\<lbrakk>xs = LCons a xs; ys = LCons a ys\<rbrakk> \<Longrightarrow> xs = ys"
   227 nitpick [bisim_depth = -1, show_datatypes, expect = quasi_genuine]
   228 nitpick [bisim_depth = -1, show_datatypes, expect = quasi_genuine]
   228 nitpick [expect = none]
   229 nitpick [card = 1\<midarrow>5, expect = none]
   229 sorry
   230 sorry
   230 
   231 
   231 subsection {* 3.10. Boxing *}
   232 subsection {* 3.10. Boxing *}
   232 
   233 
   233 datatype tm = Var nat | Lam tm | App tm tm
   234 datatype tm = Var nat | Lam tm | App tm tm
   266 
   267 
   267 subsection {* 3.11. Scope Monotonicity *}
   268 subsection {* 3.11. Scope Monotonicity *}
   268 
   269 
   269 lemma "length xs = length ys \<Longrightarrow> rev (zip xs ys) = zip xs (rev ys)"
   270 lemma "length xs = length ys \<Longrightarrow> rev (zip xs ys) = zip xs (rev ys)"
   270 nitpick [verbose, expect = genuine]
   271 nitpick [verbose, expect = genuine]
   271 nitpick [card = 8, verbose, expect = genuine]
       
   272 oops
   272 oops
   273 
   273 
   274 lemma "\<exists>g. \<forall>x\<Colon>'b. g (f x) = x \<Longrightarrow> \<forall>y\<Colon>'a. \<exists>x. y = f x"
   274 lemma "\<exists>g. \<forall>x\<Colon>'b. g (f x) = x \<Longrightarrow> \<forall>y\<Colon>'a. \<exists>x. y = f x"
   275 nitpick [mono, expect = none]
   275 nitpick [mono, expect = none]
   276 nitpick [expect = genuine]
   276 nitpick [expect = genuine]
   282 "(4\<Colon>nat) \<in> reach" |
   282 "(4\<Colon>nat) \<in> reach" |
   283 "n \<in> reach \<Longrightarrow> n < 4 \<Longrightarrow> 3 * n + 1 \<in> reach" |
   283 "n \<in> reach \<Longrightarrow> n < 4 \<Longrightarrow> 3 * n + 1 \<in> reach" |
   284 "n \<in> reach \<Longrightarrow> n + 2 \<in> reach"
   284 "n \<in> reach \<Longrightarrow> n + 2 \<in> reach"
   285 
   285 
   286 lemma "n \<in> reach \<Longrightarrow> 2 dvd n"
   286 lemma "n \<in> reach \<Longrightarrow> 2 dvd n"
   287 nitpick [card = 1\<midarrow>5, bits = 1\<midarrow>5, expect = none]
   287 (* nitpick *)
   288 apply (induct set: reach)
   288 apply (induct set: reach)
   289   apply auto
   289   apply auto
   290  nitpick [card = 1\<midarrow>5, bits = 1\<midarrow>5, expect = none]
   290  nitpick [card = 1\<midarrow>4, bits = 1\<midarrow>4, expect = none]
   291  apply (thin_tac "n \<in> reach")
   291  apply (thin_tac "n \<in> reach")
   292  nitpick [expect = genuine]
   292  nitpick [expect = genuine]
   293 oops
   293 oops
   294 
   294 
   295 lemma "n \<in> reach \<Longrightarrow> 2 dvd n \<and> n \<noteq> 0"
   295 lemma "n \<in> reach \<Longrightarrow> 2 dvd n \<and> n \<noteq> 0"
   296 nitpick [card = 1\<midarrow>5, bits = 1\<midarrow>5, expect = none]
   296 (* nitpick *)
   297 apply (induct set: reach)
   297 apply (induct set: reach)
   298   apply auto
   298   apply auto
   299  nitpick [card = 1\<midarrow>5, bits = 1\<midarrow>5, expect = none]
   299  nitpick [card = 1\<midarrow>4, bits = 1\<midarrow>4, expect = none]
   300  apply (thin_tac "n \<in> reach")
   300  apply (thin_tac "n \<in> reach")
   301  nitpick [expect = genuine]
   301  nitpick [expect = genuine]
   302 oops
   302 oops
   303 
   303 
   304 lemma "n \<in> reach \<Longrightarrow> 2 dvd n \<and> n \<ge> 4"
   304 lemma "n \<in> reach \<Longrightarrow> 2 dvd n \<and> n \<ge> 4"
   333 (* nitpick *)
   333 (* nitpick *)
   334 proof (induct t)
   334 proof (induct t)
   335   case Leaf thus ?case by simp
   335   case Leaf thus ?case by simp
   336 next
   336 next
   337   case (Branch t u) thus ?case
   337   case (Branch t u) thus ?case
   338   nitpick [non_std, card = 1\<midarrow>5, expect = none]
   338   nitpick [non_std, card = 1\<midarrow>4, expect = none]
   339   by auto
   339   by auto
   340 qed
   340 qed
   341 
   341 
   342 section {* 4. Case Studies *}
   342 section {* 4. Case Studies *}
   343 
   343