| author | blanchet | 
| Tue, 22 Jun 2010 13:17:59 +0200 | |
| changeset 37497 | 71fdbffe3275 | 
| parent 37477 | e482320bcbfe | 
| child 38184 | 6a221fffbc8a | 
| permissions | -rw-r--r-- | 
| 33197 | 1 | (* Title: HOL/Nitpick_Examples/Manual_Nits.thy | 
| 2 | Author: Jasmin Blanchette, TU Muenchen | |
| 35076 
cc19e2aef17e
added hotel key card example for Nitpick, and renumber atoms in Nitpick's output for increased readability
 blanchet parents: 
34982diff
changeset | 3 | Copyright 2009, 2010 | 
| 33197 | 4 | |
| 5 | Examples from the Nitpick manual. | |
| 6 | *) | |
| 7 | ||
| 8 | header {* Examples from the Nitpick Manual *}
 | |
| 9 | ||
| 37477 
e482320bcbfe
adjusted Nitpick examples to latest changes + make them slightly faster
 blanchet parents: 
36268diff
changeset | 10 | (* The "expect" arguments to Nitpick in this theory and the other example | 
| 
e482320bcbfe
adjusted Nitpick examples to latest changes + make them slightly faster
 blanchet parents: 
36268diff
changeset | 11 | theories are there so that the example can also serve as a regression test | 
| 
e482320bcbfe
adjusted Nitpick examples to latest changes + make them slightly faster
 blanchet parents: 
36268diff
changeset | 12 | suite. *) | 
| 
e482320bcbfe
adjusted Nitpick examples to latest changes + make them slightly faster
 blanchet parents: 
36268diff
changeset | 13 | |
| 33197 | 14 | theory Manual_Nits | 
| 35665 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 blanchet parents: 
35312diff
changeset | 15 | imports Main Quotient_Product RealDef | 
| 33197 | 16 | begin | 
| 17 | ||
| 18 | chapter {* 3. First Steps *}
 | |
| 19 | ||
| 37477 
e482320bcbfe
adjusted Nitpick examples to latest changes + make them slightly faster
 blanchet parents: 
36268diff
changeset | 20 | nitpick_params [sat_solver = MiniSat_JNI, max_threads = 1, timeout = 60 s] | 
| 33197 | 21 | |
| 22 | subsection {* 3.1. Propositional Logic *}
 | |
| 23 | ||
| 24 | lemma "P \<longleftrightarrow> Q" | |
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 25 | nitpick [expect = genuine] | 
| 33197 | 26 | apply auto | 
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 27 | nitpick [expect = genuine] 1 | 
| 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 28 | nitpick [expect = genuine] 2 | 
| 33197 | 29 | oops | 
| 30 | ||
| 31 | subsection {* 3.2. Type Variables *}
 | |
| 32 | ||
| 33 | lemma "P x \<Longrightarrow> P (THE y. P y)" | |
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 34 | nitpick [verbose, expect = genuine] | 
| 33197 | 35 | oops | 
| 36 | ||
| 37 | subsection {* 3.3. Constants *}
 | |
| 38 | ||
| 39 | lemma "P x \<Longrightarrow> P (THE y. P y)" | |
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 40 | nitpick [show_consts, expect = genuine] | 
| 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 41 | nitpick [full_descrs, show_consts, expect = genuine] | 
| 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 42 | nitpick [dont_specialize, full_descrs, show_consts, expect = genuine] | 
| 33197 | 43 | oops | 
| 44 | ||
| 45 | lemma "\<exists>!x. P x \<Longrightarrow> P (THE y. P y)" | |
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 46 | nitpick [expect = none] | 
| 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 47 | nitpick [card 'a = 1\<midarrow>50, expect = none] | 
| 33197 | 48 | (* sledgehammer *) | 
| 49 | apply (metis the_equality) | |
| 50 | done | |
| 51 | ||
| 52 | subsection {* 3.4. Skolemization *}
 | |
| 53 | ||
| 54 | lemma "\<exists>g. \<forall>x. g (f x) = x \<Longrightarrow> \<forall>y. \<exists>x. y = f x" | |
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 55 | nitpick [expect = genuine] | 
| 33197 | 56 | oops | 
| 57 | ||
| 58 | lemma "\<exists>x. \<forall>f. f x = x" | |
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 59 | nitpick [expect = genuine] | 
| 33197 | 60 | oops | 
| 61 | ||
| 62 | lemma "refl r \<Longrightarrow> sym r" | |
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 63 | nitpick [expect = genuine] | 
| 33197 | 64 | oops | 
| 65 | ||
| 34126 | 66 | subsection {* 3.5. Natural Numbers and Integers *}
 | 
| 33197 | 67 | |
| 68 | lemma "\<lbrakk>i \<le> j; n \<le> (m\<Colon>int)\<rbrakk> \<Longrightarrow> i * n + j * m \<le> i * m + j * n" | |
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 69 | nitpick [expect = genuine] | 
| 33197 | 70 | oops | 
| 71 | ||
| 72 | lemma "\<forall>n. Suc n \<noteq> n \<Longrightarrow> P" | |
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 73 | nitpick [card nat = 100, check_potential, expect = genuine] | 
| 33197 | 74 | oops | 
| 75 | ||
| 76 | lemma "P Suc" | |
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 77 | nitpick [expect = none] | 
| 33197 | 78 | oops | 
| 79 | ||
| 80 | lemma "P (op +\<Colon>nat\<Rightarrow>nat\<Rightarrow>nat)" | |
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 81 | nitpick [card nat = 1, expect = genuine] | 
| 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 82 | nitpick [card nat = 2, expect = none] | 
| 33197 | 83 | oops | 
| 84 | ||
| 85 | subsection {* 3.6. Inductive Datatypes *}
 | |
| 86 | ||
| 87 | lemma "hd (xs @ [y, y]) = hd xs" | |
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 88 | nitpick [expect = genuine] | 
| 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 89 | nitpick [show_consts, show_datatypes, expect = genuine] | 
| 33197 | 90 | oops | 
| 91 | ||
| 92 | lemma "\<lbrakk>length xs = 1; length ys = 1\<rbrakk> \<Longrightarrow> xs = ys" | |
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 93 | nitpick [show_datatypes, expect = genuine] | 
| 33197 | 94 | oops | 
| 95 | ||
| 96 | subsection {* 3.7. Typedefs, Records, Rationals, and Reals *}
 | |
| 97 | ||
| 98 | typedef three = "{0\<Colon>nat, 1, 2}"
 | |
| 99 | by blast | |
| 100 | ||
| 101 | definition A :: three where "A \<equiv> Abs_three 0" | |
| 102 | definition B :: three where "B \<equiv> Abs_three 1" | |
| 103 | definition C :: three where "C \<equiv> Abs_three 2" | |
| 104 | ||
| 105 | lemma "\<lbrakk>P A; P B\<rbrakk> \<Longrightarrow> P x" | |
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 106 | nitpick [show_datatypes, expect = genuine] | 
| 33197 | 107 | oops | 
| 108 | ||
| 35284 
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
 blanchet parents: 
35185diff
changeset | 109 | fun my_int_rel where | 
| 
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
 blanchet parents: 
35185diff
changeset | 110 | "my_int_rel (x, y) (u, v) = (x + v = u + y)" | 
| 
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
 blanchet parents: 
35185diff
changeset | 111 | |
| 
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
 blanchet parents: 
35185diff
changeset | 112 | quotient_type my_int = "nat \<times> nat" / my_int_rel | 
| 
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
 blanchet parents: 
35185diff
changeset | 113 | by (auto simp add: equivp_def expand_fun_eq) | 
| 
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
 blanchet parents: 
35185diff
changeset | 114 | |
| 
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
 blanchet parents: 
35185diff
changeset | 115 | definition add_raw where | 
| 
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
 blanchet parents: 
35185diff
changeset | 116 | "add_raw \<equiv> \<lambda>(x, y) (u, v). (x + (u\<Colon>nat), y + (v\<Colon>nat))" | 
| 
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
 blanchet parents: 
35185diff
changeset | 117 | |
| 
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
 blanchet parents: 
35185diff
changeset | 118 | quotient_definition "add\<Colon>my_int \<Rightarrow> my_int \<Rightarrow> my_int" is add_raw | 
| 
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
 blanchet parents: 
35185diff
changeset | 119 | |
| 
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
 blanchet parents: 
35185diff
changeset | 120 | lemma "add x y = add x x" | 
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 121 | nitpick [show_datatypes, expect = genuine] | 
| 35284 
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
 blanchet parents: 
35185diff
changeset | 122 | oops | 
| 
9edc2bd6d2bd
enabled Nitpick's support for quotient types + shortened the Nitpick tests a bit
 blanchet parents: 
35185diff
changeset | 123 | |
| 35711 
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
 blanchet parents: 
35710diff
changeset | 124 | ML {*
 | 
| 35712 
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
 blanchet parents: 
35711diff
changeset | 125 | (* Proof.context -> string -> (typ -> term list) -> typ -> term -> term *) | 
| 
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
 blanchet parents: 
35711diff
changeset | 126 | fun my_int_postproc _ _ _ T (Const _ $ (Const _ $ t1 $ t2)) = | 
| 
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
 blanchet parents: 
35711diff
changeset | 127 | HOLogic.mk_number T (snd (HOLogic.dest_number t1) | 
| 
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
 blanchet parents: 
35711diff
changeset | 128 | - snd (HOLogic.dest_number t2)) | 
| 
77aa29bf14ee
added a mechanism to Nitpick to support custom rendering of terms, and used it for multisets
 blanchet parents: 
35711diff
changeset | 129 | | my_int_postproc _ _ _ _ t = t | 
| 35711 
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
 blanchet parents: 
35710diff
changeset | 130 | *} | 
| 
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
 blanchet parents: 
35710diff
changeset | 131 | |
| 
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
 blanchet parents: 
35710diff
changeset | 132 | setup {* Nitpick.register_term_postprocessor @{typ my_int} my_int_postproc *}
 | 
| 
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
 blanchet parents: 
35710diff
changeset | 133 | |
| 
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
 blanchet parents: 
35710diff
changeset | 134 | lemma "add x y = add x x" | 
| 
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
 blanchet parents: 
35710diff
changeset | 135 | nitpick [show_datatypes] | 
| 
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
 blanchet parents: 
35710diff
changeset | 136 | oops | 
| 
548d3f16404b
added term postprocessor to Nitpick, to provide custom syntax for typedefs
 blanchet parents: 
35710diff
changeset | 137 | |
| 33197 | 138 | record point = | 
| 139 | Xcoord :: int | |
| 140 | Ycoord :: int | |
| 141 | ||
| 142 | lemma "Xcoord (p\<Colon>point) = Xcoord (q\<Colon>point)" | |
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 143 | nitpick [show_datatypes, expect = genuine] | 
| 33197 | 144 | oops | 
| 145 | ||
| 146 | lemma "4 * x + 3 * (y\<Colon>real) \<noteq> 1 / 2" | |
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 147 | nitpick [show_datatypes, expect = genuine] | 
| 33197 | 148 | oops | 
| 149 | ||
| 150 | subsection {* 3.8. Inductive and Coinductive Predicates *}
 | |
| 151 | ||
| 152 | inductive even where | |
| 153 | "even 0" | | |
| 154 | "even n \<Longrightarrow> even (Suc (Suc n))" | |
| 155 | ||
| 156 | lemma "\<exists>n. even n \<and> even (Suc n)" | |
| 35710 | 157 | nitpick [card nat = 50, unary_ints, verbose, expect = potential] | 
| 33197 | 158 | oops | 
| 159 | ||
| 35710 | 160 | lemma "\<exists>n \<le> 49. even n \<and> even (Suc n)" | 
| 161 | nitpick [card nat = 50, unary_ints, verbose, expect = genuine] | |
| 33197 | 162 | oops | 
| 163 | ||
| 164 | inductive even' where | |
| 165 | "even' (0\<Colon>nat)" | | |
| 166 | "even' 2" | | |
| 167 | "\<lbrakk>even' m; even' n\<rbrakk> \<Longrightarrow> even' (m + n)" | |
| 168 | ||
| 169 | lemma "\<exists>n \<in> {0, 2, 4, 6, 8}. \<not> even' n"
 | |
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 170 | nitpick [card nat = 10, unary_ints, verbose, show_consts, expect = genuine] | 
| 33197 | 171 | oops | 
| 172 | ||
| 173 | lemma "even' (n - 2) \<Longrightarrow> even' n" | |
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 174 | nitpick [card nat = 10, show_consts, expect = genuine] | 
| 33197 | 175 | oops | 
| 176 | ||
| 177 | coinductive nats where | |
| 178 | "nats (x\<Colon>nat) \<Longrightarrow> nats x" | |
| 179 | ||
| 180 | lemma "nats = {0, 1, 2, 3, 4}"
 | |
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 181 | nitpick [card nat = 10, show_consts, expect = genuine] | 
| 33197 | 182 | oops | 
| 183 | ||
| 184 | inductive odd where | |
| 185 | "odd 1" | | |
| 186 | "\<lbrakk>odd m; even n\<rbrakk> \<Longrightarrow> odd (m + n)" | |
| 187 | ||
| 188 | lemma "odd n \<Longrightarrow> odd (n - 2)" | |
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 189 | nitpick [card nat = 10, show_consts, expect = genuine] | 
| 33197 | 190 | oops | 
| 191 | ||
| 192 | subsection {* 3.9. Coinductive Datatypes *}
 | |
| 193 | ||
| 35665 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 blanchet parents: 
35312diff
changeset | 194 | (* Lazy lists are defined in Andreas Lochbihler's "Coinductive" AFP entry. Since | 
| 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 blanchet parents: 
35312diff
changeset | 195 | we cannot rely on its presence, we expediently provide our own axiomatization. | 
| 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 blanchet parents: 
35312diff
changeset | 196 | The examples also work unchanged with Lochbihler's "Coinductive_List" theory. *) | 
| 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 blanchet parents: 
35312diff
changeset | 197 | |
| 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 blanchet parents: 
35312diff
changeset | 198 | typedef 'a llist = "UNIV\<Colon>('a list + (nat \<Rightarrow> 'a)) set" by auto
 | 
| 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 blanchet parents: 
35312diff
changeset | 199 | |
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 200 | definition LNil where | 
| 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 201 | "LNil = Abs_llist (Inl [])" | 
| 35665 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 blanchet parents: 
35312diff
changeset | 202 | definition LCons where | 
| 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 blanchet parents: 
35312diff
changeset | 203 | "LCons y ys = Abs_llist (case Rep_llist ys of | 
| 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 blanchet parents: 
35312diff
changeset | 204 | Inl ys' \<Rightarrow> Inl (y # ys') | 
| 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 blanchet parents: 
35312diff
changeset | 205 | | Inr f \<Rightarrow> Inr (\<lambda>n. case n of 0 \<Rightarrow> y | Suc m \<Rightarrow> f m))" | 
| 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 blanchet parents: 
35312diff
changeset | 206 | |
| 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 blanchet parents: 
35312diff
changeset | 207 | axiomatization iterates :: "('a \<Rightarrow> 'a) \<Rightarrow> 'a \<Rightarrow> 'a llist"
 | 
| 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 blanchet parents: 
35312diff
changeset | 208 | |
| 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 blanchet parents: 
35312diff
changeset | 209 | lemma iterates_def [nitpick_simp]: | 
| 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 blanchet parents: 
35312diff
changeset | 210 | "iterates f a = LCons a (iterates f (f a))" | 
| 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 blanchet parents: 
35312diff
changeset | 211 | sorry | 
| 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 blanchet parents: 
35312diff
changeset | 212 | |
| 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 blanchet parents: 
35312diff
changeset | 213 | setup {*
 | 
| 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 blanchet parents: 
35312diff
changeset | 214 | Nitpick.register_codatatype @{typ "'a llist"} ""
 | 
| 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 blanchet parents: 
35312diff
changeset | 215 |     (map dest_Const [@{term LNil}, @{term LCons}])
 | 
| 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 blanchet parents: 
35312diff
changeset | 216 | *} | 
| 
ff2bf50505ab
added "finitize" option to Nitpick + remove dependency on "Coinductive_List"
 blanchet parents: 
35312diff
changeset | 217 | |
| 33197 | 218 | lemma "xs \<noteq> LCons a xs" | 
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 219 | nitpick [expect = genuine] | 
| 33197 | 220 | oops | 
| 221 | ||
| 222 | lemma "\<lbrakk>xs = LCons a xs; ys = iterates (\<lambda>b. a) b\<rbrakk> \<Longrightarrow> xs = ys" | |
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 223 | nitpick [verbose, expect = genuine] | 
| 33197 | 224 | oops | 
| 225 | ||
| 226 | lemma "\<lbrakk>xs = LCons a xs; ys = LCons a ys\<rbrakk> \<Longrightarrow> xs = ys" | |
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 227 | nitpick [bisim_depth = -1, show_datatypes, expect = quasi_genuine] | 
| 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 228 | nitpick [expect = none] | 
| 33197 | 229 | sorry | 
| 230 | ||
| 231 | subsection {* 3.10. Boxing *}
 | |
| 232 | ||
| 233 | datatype tm = Var nat | Lam tm | App tm tm | |
| 234 | ||
| 235 | primrec lift where | |
| 236 | "lift (Var j) k = Var (if j < k then j else j + 1)" | | |
| 237 | "lift (Lam t) k = Lam (lift t (k + 1))" | | |
| 238 | "lift (App t u) k = App (lift t k) (lift u k)" | |
| 239 | ||
| 240 | primrec loose where | |
| 241 | "loose (Var j) k = (j \<ge> k)" | | |
| 242 | "loose (Lam t) k = loose t (Suc k)" | | |
| 243 | "loose (App t u) k = (loose t k \<or> loose u k)" | |
| 244 | ||
| 245 | primrec subst\<^isub>1 where | |
| 246 | "subst\<^isub>1 \<sigma> (Var j) = \<sigma> j" | | |
| 247 | "subst\<^isub>1 \<sigma> (Lam t) = | |
| 248 | Lam (subst\<^isub>1 (\<lambda>n. case n of 0 \<Rightarrow> Var 0 | Suc m \<Rightarrow> lift (\<sigma> m) 1) t)" | | |
| 249 | "subst\<^isub>1 \<sigma> (App t u) = App (subst\<^isub>1 \<sigma> t) (subst\<^isub>1 \<sigma> u)" | |
| 250 | ||
| 251 | lemma "\<not> loose t 0 \<Longrightarrow> subst\<^isub>1 \<sigma> t = t" | |
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 252 | nitpick [verbose, expect = genuine] | 
| 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 253 | nitpick [eval = "subst\<^isub>1 \<sigma> t", expect = genuine] | 
| 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 254 | (* nitpick [dont_box, expect = unknown] *) | 
| 33197 | 255 | oops | 
| 256 | ||
| 257 | primrec subst\<^isub>2 where | |
| 258 | "subst\<^isub>2 \<sigma> (Var j) = \<sigma> j" | | |
| 259 | "subst\<^isub>2 \<sigma> (Lam t) = | |
| 260 | Lam (subst\<^isub>2 (\<lambda>n. case n of 0 \<Rightarrow> Var 0 | Suc m \<Rightarrow> lift (\<sigma> m) 0) t)" | | |
| 261 | "subst\<^isub>2 \<sigma> (App t u) = App (subst\<^isub>2 \<sigma> t) (subst\<^isub>2 \<sigma> u)" | |
| 262 | ||
| 263 | lemma "\<not> loose t 0 \<Longrightarrow> subst\<^isub>2 \<sigma> t = t" | |
| 35710 | 264 | nitpick [card = 1\<midarrow>5, expect = none] | 
| 33197 | 265 | sorry | 
| 266 | ||
| 267 | subsection {* 3.11. Scope Monotonicity *}
 | |
| 268 | ||
| 269 | lemma "length xs = length ys \<Longrightarrow> rev (zip xs ys) = zip xs (rev ys)" | |
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 270 | nitpick [verbose, expect = genuine] | 
| 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 271 | nitpick [card = 8, verbose, expect = genuine] | 
| 33197 | 272 | oops | 
| 273 | ||
| 274 | lemma "\<exists>g. \<forall>x\<Colon>'b. g (f x) = x \<Longrightarrow> \<forall>y\<Colon>'a. \<exists>x. y = f x" | |
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 275 | nitpick [mono, expect = none] | 
| 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 276 | nitpick [expect = genuine] | 
| 33197 | 277 | oops | 
| 278 | ||
| 34982 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 279 | subsection {* 3.12. Inductive Properties *}
 | 
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 280 | |
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 281 | inductive_set reach where | 
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 282 | "(4\<Colon>nat) \<in> reach" | | 
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 283 | "n \<in> reach \<Longrightarrow> n < 4 \<Longrightarrow> 3 * n + 1 \<in> reach" | | 
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 284 | "n \<in> reach \<Longrightarrow> n + 2 \<in> reach" | 
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 285 | |
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 286 | lemma "n \<in> reach \<Longrightarrow> 2 dvd n" | 
| 35718 | 287 | nitpick [card = 1\<midarrow>5, bits = 1\<midarrow>5, expect = none] | 
| 34982 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 288 | apply (induct set: reach) | 
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 289 | apply auto | 
| 35718 | 290 | nitpick [card = 1\<midarrow>5, bits = 1\<midarrow>5, expect = none] | 
| 34982 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 291 | apply (thin_tac "n \<in> reach") | 
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 292 | nitpick [expect = genuine] | 
| 34982 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 293 | oops | 
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 294 | |
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 295 | lemma "n \<in> reach \<Longrightarrow> 2 dvd n \<and> n \<noteq> 0" | 
| 35718 | 296 | nitpick [card = 1\<midarrow>5, bits = 1\<midarrow>5, expect = none] | 
| 34982 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 297 | apply (induct set: reach) | 
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 298 | apply auto | 
| 35718 | 299 | nitpick [card = 1\<midarrow>5, bits = 1\<midarrow>5, expect = none] | 
| 34982 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 300 | apply (thin_tac "n \<in> reach") | 
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 301 | nitpick [expect = genuine] | 
| 34982 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 302 | oops | 
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 303 | |
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 304 | lemma "n \<in> reach \<Longrightarrow> 2 dvd n \<and> n \<ge> 4" | 
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 305 | by (induct set: reach) arith+ | 
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 306 | |
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 307 | datatype 'a bin_tree = Leaf 'a | Branch "'a bin_tree" "'a bin_tree" | 
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 308 | |
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 309 | primrec labels where | 
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 310 | "labels (Leaf a) = {a}" |
 | 
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 311 | "labels (Branch t u) = labels t \<union> labels u" | 
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 312 | |
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 313 | primrec swap where | 
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 314 | "swap (Leaf c) a b = | 
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 315 | (if c = a then Leaf b else if c = b then Leaf a else Leaf c)" | | 
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 316 | "swap (Branch t u) a b = Branch (swap t a b) (swap u a b)" | 
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 317 | |
| 35180 
c57dba973391
more work on Nitpick's support for nonstandard models + fix in model reconstruction
 blanchet parents: 
35078diff
changeset | 318 | lemma "{a, b} \<subseteq> labels t \<Longrightarrow> labels (swap t a b) = labels t"
 | 
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 319 | (* nitpick *) | 
| 34982 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 320 | proof (induct t) | 
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 321 | case Leaf thus ?case by simp | 
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 322 | next | 
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 323 | case (Branch t u) thus ?case | 
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 324 | (* nitpick *) | 
| 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 325 | nitpick [non_std, show_all, expect = genuine] | 
| 34982 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 326 | oops | 
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 327 | |
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 328 | lemma "labels (swap t a b) = | 
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 329 | (if a \<in> labels t then | 
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 330 |           if b \<in> labels t then labels t else (labels t - {a}) \<union> {b}
 | 
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 331 | else | 
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 332 |           if b \<in> labels t then (labels t - {b}) \<union> {a} else labels t)"
 | 
| 35309 
997aa3a3e4bb
catch IO errors in Nitpick's "kodkodi" invocation + shorten execution time of "Manual_Nits" example
 blanchet parents: 
35284diff
changeset | 333 | (* nitpick *) | 
| 34982 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 334 | proof (induct t) | 
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 335 | case Leaf thus ?case by simp | 
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 336 | next | 
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 337 | case (Branch t u) thus ?case | 
| 35710 | 338 | nitpick [non_std, card = 1\<midarrow>5, expect = none] | 
| 34982 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 339 | by auto | 
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 340 | qed | 
| 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 341 | |
| 33197 | 342 | section {* 4. Case Studies *}
 | 
| 343 | ||
| 36268 | 344 | nitpick_params [max_potential = 0] | 
| 33197 | 345 | |
| 346 | subsection {* 4.1. A Context-Free Grammar *}
 | |
| 347 | ||
| 348 | datatype alphabet = a | b | |
| 349 | ||
| 350 | inductive_set S\<^isub>1 and A\<^isub>1 and B\<^isub>1 where | |
| 351 | "[] \<in> S\<^isub>1" | |
| 352 | | "w \<in> A\<^isub>1 \<Longrightarrow> b # w \<in> S\<^isub>1" | |
| 353 | | "w \<in> B\<^isub>1 \<Longrightarrow> a # w \<in> S\<^isub>1" | |
| 354 | | "w \<in> S\<^isub>1 \<Longrightarrow> a # w \<in> A\<^isub>1" | |
| 355 | | "w \<in> S\<^isub>1 \<Longrightarrow> b # w \<in> S\<^isub>1" | |
| 356 | | "\<lbrakk>v \<in> B\<^isub>1; v \<in> B\<^isub>1\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^isub>1" | |
| 357 | ||
| 358 | theorem S\<^isub>1_sound: | |
| 359 | "w \<in> S\<^isub>1 \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]" | |
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 360 | nitpick [expect = genuine] | 
| 33197 | 361 | oops | 
| 362 | ||
| 363 | inductive_set S\<^isub>2 and A\<^isub>2 and B\<^isub>2 where | |
| 364 | "[] \<in> S\<^isub>2" | |
| 365 | | "w \<in> A\<^isub>2 \<Longrightarrow> b # w \<in> S\<^isub>2" | |
| 366 | | "w \<in> B\<^isub>2 \<Longrightarrow> a # w \<in> S\<^isub>2" | |
| 367 | | "w \<in> S\<^isub>2 \<Longrightarrow> a # w \<in> A\<^isub>2" | |
| 368 | | "w \<in> S\<^isub>2 \<Longrightarrow> b # w \<in> B\<^isub>2" | |
| 369 | | "\<lbrakk>v \<in> B\<^isub>2; v \<in> B\<^isub>2\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^isub>2" | |
| 370 | ||
| 371 | theorem S\<^isub>2_sound: | |
| 372 | "w \<in> S\<^isub>2 \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]" | |
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 373 | nitpick [expect = genuine] | 
| 33197 | 374 | oops | 
| 375 | ||
| 376 | inductive_set S\<^isub>3 and A\<^isub>3 and B\<^isub>3 where | |
| 377 | "[] \<in> S\<^isub>3" | |
| 378 | | "w \<in> A\<^isub>3 \<Longrightarrow> b # w \<in> S\<^isub>3" | |
| 379 | | "w \<in> B\<^isub>3 \<Longrightarrow> a # w \<in> S\<^isub>3" | |
| 380 | | "w \<in> S\<^isub>3 \<Longrightarrow> a # w \<in> A\<^isub>3" | |
| 381 | | "w \<in> S\<^isub>3 \<Longrightarrow> b # w \<in> B\<^isub>3" | |
| 382 | | "\<lbrakk>v \<in> B\<^isub>3; w \<in> B\<^isub>3\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^isub>3" | |
| 383 | ||
| 384 | theorem S\<^isub>3_sound: | |
| 385 | "w \<in> S\<^isub>3 \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]" | |
| 37477 
e482320bcbfe
adjusted Nitpick examples to latest changes + make them slightly faster
 blanchet parents: 
36268diff
changeset | 386 | nitpick [card = 1\<midarrow>5, expect = none] | 
| 33197 | 387 | sorry | 
| 388 | ||
| 389 | theorem S\<^isub>3_complete: | |
| 390 | "length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b] \<longrightarrow> w \<in> S\<^isub>3" | |
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 391 | nitpick [expect = genuine] | 
| 33197 | 392 | oops | 
| 393 | ||
| 394 | inductive_set S\<^isub>4 and A\<^isub>4 and B\<^isub>4 where | |
| 395 | "[] \<in> S\<^isub>4" | |
| 396 | | "w \<in> A\<^isub>4 \<Longrightarrow> b # w \<in> S\<^isub>4" | |
| 397 | | "w \<in> B\<^isub>4 \<Longrightarrow> a # w \<in> S\<^isub>4" | |
| 398 | | "w \<in> S\<^isub>4 \<Longrightarrow> a # w \<in> A\<^isub>4" | |
| 399 | | "\<lbrakk>v \<in> A\<^isub>4; w \<in> A\<^isub>4\<rbrakk> \<Longrightarrow> b # v @ w \<in> A\<^isub>4" | |
| 400 | | "w \<in> S\<^isub>4 \<Longrightarrow> b # w \<in> B\<^isub>4" | |
| 401 | | "\<lbrakk>v \<in> B\<^isub>4; w \<in> B\<^isub>4\<rbrakk> \<Longrightarrow> a # v @ w \<in> B\<^isub>4" | |
| 402 | ||
| 403 | theorem S\<^isub>4_sound: | |
| 404 | "w \<in> S\<^isub>4 \<longrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]" | |
| 37477 
e482320bcbfe
adjusted Nitpick examples to latest changes + make them slightly faster
 blanchet parents: 
36268diff
changeset | 405 | nitpick [card = 1\<midarrow>5, expect = none] | 
| 33197 | 406 | sorry | 
| 407 | ||
| 408 | theorem S\<^isub>4_complete: | |
| 409 | "length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b] \<longrightarrow> w \<in> S\<^isub>4" | |
| 37477 
e482320bcbfe
adjusted Nitpick examples to latest changes + make them slightly faster
 blanchet parents: 
36268diff
changeset | 410 | nitpick [card = 1\<midarrow>5, expect = none] | 
| 33197 | 411 | sorry | 
| 412 | ||
| 413 | theorem S\<^isub>4_A\<^isub>4_B\<^isub>4_sound_and_complete: | |
| 414 | "w \<in> S\<^isub>4 \<longleftrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b]" | |
| 415 | "w \<in> A\<^isub>4 \<longleftrightarrow> length [x \<leftarrow> w. x = a] = length [x \<leftarrow> w. x = b] + 1" | |
| 416 | "w \<in> B\<^isub>4 \<longleftrightarrow> length [x \<leftarrow> w. x = b] = length [x \<leftarrow> w. x = a] + 1" | |
| 37477 
e482320bcbfe
adjusted Nitpick examples to latest changes + make them slightly faster
 blanchet parents: 
36268diff
changeset | 417 | nitpick [card = 1\<midarrow>5, expect = none] | 
| 33197 | 418 | sorry | 
| 419 | ||
| 420 | subsection {* 4.2. AA Trees *}
 | |
| 421 | ||
| 34982 
7b8c366e34a2
added support for nonstandard models to Nitpick (based on an idea by Koen Claessen) and did other fixes to Nitpick
 blanchet parents: 
34126diff
changeset | 422 | datatype 'a aa_tree = \<Lambda> | N "'a\<Colon>linorder" nat "'a aa_tree" "'a aa_tree" | 
| 33197 | 423 | |
| 424 | primrec data where | |
| 425 | "data \<Lambda> = undefined" | | |
| 426 | "data (N x _ _ _) = x" | |
| 427 | ||
| 428 | primrec dataset where | |
| 429 | "dataset \<Lambda> = {}" |
 | |
| 430 | "dataset (N x _ t u) = {x} \<union> dataset t \<union> dataset u"
 | |
| 431 | ||
| 432 | primrec level where | |
| 433 | "level \<Lambda> = 0" | | |
| 434 | "level (N _ k _ _) = k" | |
| 435 | ||
| 436 | primrec left where | |
| 437 | "left \<Lambda> = \<Lambda>" | | |
| 438 | "left (N _ _ t\<^isub>1 _) = t\<^isub>1" | |
| 439 | ||
| 440 | primrec right where | |
| 441 | "right \<Lambda> = \<Lambda>" | | |
| 442 | "right (N _ _ _ t\<^isub>2) = t\<^isub>2" | |
| 443 | ||
| 444 | fun wf where | |
| 445 | "wf \<Lambda> = True" | | |
| 446 | "wf (N _ k t u) = | |
| 447 | (if t = \<Lambda> then | |
| 448 | k = 1 \<and> (u = \<Lambda> \<or> (level u = 1 \<and> left u = \<Lambda> \<and> right u = \<Lambda>)) | |
| 449 | else | |
| 450 | wf t \<and> wf u \<and> u \<noteq> \<Lambda> \<and> level t < k \<and> level u \<le> k \<and> level (right u) < k)" | |
| 451 | ||
| 452 | fun skew where | |
| 453 | "skew \<Lambda> = \<Lambda>" | | |
| 454 | "skew (N x k t u) = | |
| 455 | (if t \<noteq> \<Lambda> \<and> k = level t then | |
| 456 | N (data t) k (left t) (N x k (right t) u) | |
| 457 | else | |
| 458 | N x k t u)" | |
| 459 | ||
| 460 | fun split where | |
| 461 | "split \<Lambda> = \<Lambda>" | | |
| 462 | "split (N x k t u) = | |
| 463 | (if u \<noteq> \<Lambda> \<and> k = level (right u) then | |
| 464 | N (data u) (Suc k) (N x k t (left u)) (right u) | |
| 465 | else | |
| 466 | N x k t u)" | |
| 467 | ||
| 468 | theorem dataset_skew_split: | |
| 469 | "dataset (skew t) = dataset t" | |
| 470 | "dataset (split t) = dataset t" | |
| 35747 
c910fe606829
make tests less demanding, to prevent sporadic failures
 blanchet parents: 
35718diff
changeset | 471 | nitpick [card = 1\<midarrow>5, expect = none] | 
| 33197 | 472 | sorry | 
| 473 | ||
| 474 | theorem wf_skew_split: | |
| 475 | "wf t \<Longrightarrow> skew t = t" | |
| 476 | "wf t \<Longrightarrow> split t = t" | |
| 35747 
c910fe606829
make tests less demanding, to prevent sporadic failures
 blanchet parents: 
35718diff
changeset | 477 | nitpick [card = 1\<midarrow>5, expect = none] | 
| 33197 | 478 | sorry | 
| 479 | ||
| 480 | primrec insort\<^isub>1 where | |
| 481 | "insort\<^isub>1 \<Lambda> x = N x 1 \<Lambda> \<Lambda>" | | |
| 482 | "insort\<^isub>1 (N y k t u) x = | |
| 483 | (* (split \<circ> skew) *) (N y k (if x < y then insort\<^isub>1 t x else t) | |
| 484 | (if x > y then insort\<^isub>1 u x else u))" | |
| 485 | ||
| 486 | theorem wf_insort\<^isub>1: "wf t \<Longrightarrow> wf (insort\<^isub>1 t x)" | |
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 487 | nitpick [expect = genuine] | 
| 33197 | 488 | oops | 
| 489 | ||
| 490 | theorem wf_insort\<^isub>1_nat: "wf t \<Longrightarrow> wf (insort\<^isub>1 t (x\<Colon>nat))" | |
| 35671 
ed2c3830d881
improved Nitpick's precision for "card" and "setsum" + fix incorrect outcome code w.r.t. "bisim_depth = -1"
 blanchet parents: 
35665diff
changeset | 491 | nitpick [eval = "insort\<^isub>1 t x", expect = genuine] | 
| 33197 | 492 | oops | 
| 493 | ||
| 494 | primrec insort\<^isub>2 where | |
| 495 | "insort\<^isub>2 \<Lambda> x = N x 1 \<Lambda> \<Lambda>" | | |
| 496 | "insort\<^isub>2 (N y k t u) x = | |
| 497 | (split \<circ> skew) (N y k (if x < y then insort\<^isub>2 t x else t) | |
| 498 | (if x > y then insort\<^isub>2 u x else u))" | |
| 499 | ||
| 500 | theorem wf_insort\<^isub>2: "wf t \<Longrightarrow> wf (insort\<^isub>2 t x)" | |
| 35747 
c910fe606829
make tests less demanding, to prevent sporadic failures
 blanchet parents: 
35718diff
changeset | 501 | nitpick [card = 1\<midarrow>5, expect = none] | 
| 33197 | 502 | sorry | 
| 503 | ||
| 504 | theorem dataset_insort\<^isub>2: "dataset (insort\<^isub>2 t x) = {x} \<union> dataset t"
 | |
| 35747 
c910fe606829
make tests less demanding, to prevent sporadic failures
 blanchet parents: 
35718diff
changeset | 505 | nitpick [card = 1\<midarrow>5, expect = none] | 
| 33197 | 506 | sorry | 
| 507 | ||
| 508 | end |