src/HOL/Nitpick_Examples/Manual_Nits.thy
changeset 35349 f9801fdeb789
parent 35312 99cd1f96b400
child 35665 ff2bf50505ab
equal deleted inserted replaced
35348:c6331256b087 35349:f9801fdeb789
    11 imports Main Coinductive_List Quotient_Product RealDef
    11 imports Main Coinductive_List Quotient_Product RealDef
    12 begin
    12 begin
    13 
    13 
    14 chapter {* 3. First Steps *}
    14 chapter {* 3. First Steps *}
    15 
    15 
    16 nitpick_params [sat_solver = MiniSat_JNI, max_threads = 1]
    16 nitpick_params [sat_solver = MiniSat_JNI, max_threads = 1, timeout = 15 s]
    17 
    17 
    18 subsection {* 3.1. Propositional Logic *}
    18 subsection {* 3.1. Propositional Logic *}
    19 
    19 
    20 lemma "P \<longleftrightarrow> Q"
    20 lemma "P \<longleftrightarrow> Q"
    21 nitpick
    21 nitpick
    68 lemma "\<forall>n. Suc n \<noteq> n \<Longrightarrow> P"
    68 lemma "\<forall>n. Suc n \<noteq> n \<Longrightarrow> P"
    69 nitpick [card nat = 100, check_potential]
    69 nitpick [card nat = 100, check_potential]
    70 oops
    70 oops
    71 
    71 
    72 lemma "P Suc"
    72 lemma "P Suc"
    73 nitpick [card = 1-6]
    73 nitpick
    74 oops
    74 oops
    75 
    75 
    76 lemma "P (op +\<Colon>nat\<Rightarrow>nat\<Rightarrow>nat)"
    76 lemma "P (op +\<Colon>nat\<Rightarrow>nat\<Rightarrow>nat)"
    77 nitpick [card nat = 1]
    77 nitpick [card nat = 1]
    78 nitpick [card nat = 2]
    78 nitpick [card nat = 2]
   147 "even' (0\<Colon>nat)" |
   147 "even' (0\<Colon>nat)" |
   148 "even' 2" |
   148 "even' 2" |
   149 "\<lbrakk>even' m; even' n\<rbrakk> \<Longrightarrow> even' (m + n)"
   149 "\<lbrakk>even' m; even' n\<rbrakk> \<Longrightarrow> even' (m + n)"
   150 
   150 
   151 lemma "\<exists>n \<in> {0, 2, 4, 6, 8}. \<not> even' n"
   151 lemma "\<exists>n \<in> {0, 2, 4, 6, 8}. \<not> even' n"
   152 nitpick [card nat = 10, unary_ints, verbose, show_consts] (* FIXME: should be genuine *)
   152 nitpick [card nat = 10, unary_ints, verbose, show_consts]
   153 oops
   153 oops
   154 
   154 
   155 lemma "even' (n - 2) \<Longrightarrow> even' n"
   155 lemma "even' (n - 2) \<Longrightarrow> even' n"
   156 nitpick [card nat = 10, show_consts]
   156 nitpick [card nat = 10, show_consts]
   157 oops
   157 oops
   208 "subst\<^isub>1 \<sigma> (App t u) = App (subst\<^isub>1 \<sigma> t) (subst\<^isub>1 \<sigma> u)"
   208 "subst\<^isub>1 \<sigma> (App t u) = App (subst\<^isub>1 \<sigma> t) (subst\<^isub>1 \<sigma> u)"
   209 
   209 
   210 lemma "\<not> loose t 0 \<Longrightarrow> subst\<^isub>1 \<sigma> t = t"
   210 lemma "\<not> loose t 0 \<Longrightarrow> subst\<^isub>1 \<sigma> t = t"
   211 nitpick [verbose]
   211 nitpick [verbose]
   212 nitpick [eval = "subst\<^isub>1 \<sigma> t"]
   212 nitpick [eval = "subst\<^isub>1 \<sigma> t"]
   213 nitpick [dont_box]
   213 (* nitpick [dont_box] *)
   214 oops
   214 oops
   215 
   215 
   216 primrec subst\<^isub>2 where
   216 primrec subst\<^isub>2 where
   217 "subst\<^isub>2 \<sigma> (Var j) = \<sigma> j" |
   217 "subst\<^isub>2 \<sigma> (Var j) = \<sigma> j" |
   218 "subst\<^isub>2 \<sigma> (Lam t) =
   218 "subst\<^isub>2 \<sigma> (Lam t) =
   219  Lam (subst\<^isub>2 (\<lambda>n. case n of 0 \<Rightarrow> Var 0 | Suc m \<Rightarrow> lift (\<sigma> m) 0) t)" |
   219  Lam (subst\<^isub>2 (\<lambda>n. case n of 0 \<Rightarrow> Var 0 | Suc m \<Rightarrow> lift (\<sigma> m) 0) t)" |
   220 "subst\<^isub>2 \<sigma> (App t u) = App (subst\<^isub>2 \<sigma> t) (subst\<^isub>2 \<sigma> u)"
   220 "subst\<^isub>2 \<sigma> (App t u) = App (subst\<^isub>2 \<sigma> t) (subst\<^isub>2 \<sigma> u)"
   221 
   221 
   222 lemma "\<not> loose t 0 \<Longrightarrow> subst\<^isub>2 \<sigma> t = t"
   222 lemma "\<not> loose t 0 \<Longrightarrow> subst\<^isub>2 \<sigma> t = t"
   223 nitpick
   223 nitpick [card = 1\<midarrow>6]
   224 sorry
   224 sorry
   225 
   225 
   226 subsection {* 3.11. Scope Monotonicity *}
   226 subsection {* 3.11. Scope Monotonicity *}
   227 
   227 
   228 lemma "length xs = length ys \<Longrightarrow> rev (zip xs ys) = zip xs (rev ys)"
   228 lemma "length xs = length ys \<Longrightarrow> rev (zip xs ys) = zip xs (rev ys)"
   241 "(4\<Colon>nat) \<in> reach" |
   241 "(4\<Colon>nat) \<in> reach" |
   242 "n \<in> reach \<Longrightarrow> n < 4 \<Longrightarrow> 3 * n + 1 \<in> reach" |
   242 "n \<in> reach \<Longrightarrow> n < 4 \<Longrightarrow> 3 * n + 1 \<in> reach" |
   243 "n \<in> reach \<Longrightarrow> n + 2 \<in> reach"
   243 "n \<in> reach \<Longrightarrow> n + 2 \<in> reach"
   244 
   244 
   245 lemma "n \<in> reach \<Longrightarrow> 2 dvd n"
   245 lemma "n \<in> reach \<Longrightarrow> 2 dvd n"
   246 nitpick
   246 nitpick [unary_ints]
   247 apply (induct set: reach)
   247 apply (induct set: reach)
   248   apply auto
   248   apply auto
   249  nitpick
   249  nitpick
   250  apply (thin_tac "n \<in> reach")
   250  apply (thin_tac "n \<in> reach")
   251  nitpick
   251  nitpick
   252 oops
   252 oops
   253 
   253 
   254 lemma "n \<in> reach \<Longrightarrow> 2 dvd n \<and> n \<noteq> 0"
   254 lemma "n \<in> reach \<Longrightarrow> 2 dvd n \<and> n \<noteq> 0"
   255 nitpick
   255 nitpick [unary_ints]
   256 apply (induct set: reach)
   256 apply (induct set: reach)
   257   apply auto
   257   apply auto
   258  nitpick
   258  nitpick
   259  apply (thin_tac "n \<in> reach")
   259  apply (thin_tac "n \<in> reach")
   260  nitpick
   260  nitpick
   287 lemma "labels (swap t a b) =
   287 lemma "labels (swap t a b) =
   288        (if a \<in> labels t then
   288        (if a \<in> labels t then
   289           if b \<in> labels t then labels t else (labels t - {a}) \<union> {b}
   289           if b \<in> labels t then labels t else (labels t - {a}) \<union> {b}
   290         else
   290         else
   291           if b \<in> labels t then (labels t - {b}) \<union> {a} else labels t)"
   291           if b \<in> labels t then (labels t - {b}) \<union> {a} else labels t)"
   292 nitpick
   292 (* nitpick *)
   293 proof (induct t)
   293 proof (induct t)
   294   case Leaf thus ?case by simp
   294   case Leaf thus ?case by simp
   295 next
   295 next
   296   case (Branch t u) thus ?case
   296   case (Branch t u) thus ?case
   297   nitpick [non_std "'a bin_tree", show_consts]
   297   nitpick [non_std, show_all]
   298   by auto
   298   by auto
   299 qed
   299 qed
   300 
   300 
   301 section {* 4. Case Studies *}
   301 section {* 4. Case Studies *}
   302 
   302