| author | wenzelm | 
| Thu, 26 Oct 2023 22:20:22 +0200 | |
| changeset 78852 | 2700e4b484f7 | 
| parent 69690 | 1fb204399d8d | 
| child 81706 | 7beb0cf38292 | 
| permissions | -rw-r--r-- | 
| 41905 | 1  | 
(* Author: Lukas Bulwahn, TU Muenchen *)  | 
2  | 
||
| 60758 | 3  | 
section \<open>Counterexample generator performing narrowing-based testing\<close>  | 
| 41905 | 4  | 
|
| 
41930
 
1e008cc4883a
renaming lazysmallcheck ML file to Quickcheck_Narrowing
 
bulwahn 
parents: 
41929 
diff
changeset
 | 
5  | 
theory Quickcheck_Narrowing  | 
| 
56047
 
1f283d0a4966
make it possible to load Quickcheck exhaustive & narrowing in parallel
 
blanchet 
parents: 
55676 
diff
changeset
 | 
6  | 
imports Quickcheck_Random  | 
| 
46950
 
d0181abdbdac
declare command keywords via theory header, including strict checking outside Pure;
 
wenzelm 
parents: 
46758 
diff
changeset
 | 
7  | 
keywords "find_unused_assms" :: diag  | 
| 41905 | 8  | 
begin  | 
9  | 
||
| 60758 | 10  | 
subsection \<open>Counterexample generator\<close>  | 
| 41905 | 11  | 
|
| 60758 | 12  | 
subsubsection \<open>Code generation setup\<close>  | 
| 
43308
 
fd6cc1378fec
compilation of Haskell in its own target for Quickcheck; passing options by arguments in Narrowing_Generators
 
bulwahn 
parents: 
43237 
diff
changeset
 | 
13  | 
|
| 60758 | 14  | 
setup \<open>Code_Target.add_derived_target ("Haskell_Quickcheck", [(Code_Haskell.target, I)])\<close>
 | 
| 
43308
 
fd6cc1378fec
compilation of Haskell in its own target for Quickcheck; passing options by arguments in Narrowing_Generators
 
bulwahn 
parents: 
43237 
diff
changeset
 | 
15  | 
|
| 
52435
 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 
haftmann 
parents: 
51143 
diff
changeset
 | 
16  | 
code_printing  | 
| 60758 | 17  | 
code_module Typerep \<rightharpoonup> (Haskell_Quickcheck) \<open>  | 
| 69690 | 18  | 
module Typerep(Typerep(..)) where  | 
19  | 
||
| 55676 | 20  | 
data Typerep = Typerep String [Typerep]  | 
| 69528 | 21  | 
\<close> for type_constructor typerep constant Typerep.Typerep  | 
| 55676 | 22  | 
| type_constructor typerep \<rightharpoonup> (Haskell_Quickcheck) "Typerep.Typerep"  | 
23  | 
| constant Typerep.Typerep \<rightharpoonup> (Haskell_Quickcheck) "Typerep.Typerep"  | 
|
| 
51143
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
24  | 
|
| 
43308
 
fd6cc1378fec
compilation of Haskell in its own target for Quickcheck; passing options by arguments in Narrowing_Generators
 
bulwahn 
parents: 
43237 
diff
changeset
 | 
25  | 
code_reserved Haskell_Quickcheck Typerep  | 
| 
41909
 
383bbdad1650
replacing strings in generated Code resolves the changing names of Typerep in lazysmallcheck prototype
 
bulwahn 
parents: 
41908 
diff
changeset
 | 
26  | 
|
| 
58400
 
d0d3c30806b4
always annotate potentially polymorphic Haskell numerals
 
haftmann 
parents: 
58350 
diff
changeset
 | 
27  | 
code_printing  | 
| 69528 | 28  | 
type_constructor integer \<rightharpoonup> (Haskell_Quickcheck) "Prelude.Int"  | 
29  | 
| constant "0::integer" \<rightharpoonup>  | 
|
| 
58400
 
d0d3c30806b4
always annotate potentially polymorphic Haskell numerals
 
haftmann 
parents: 
58350 
diff
changeset
 | 
30  | 
(Haskell_Quickcheck) "!(0/ ::/ Prelude.Int)"  | 
| 
 
d0d3c30806b4
always annotate potentially polymorphic Haskell numerals
 
haftmann 
parents: 
58350 
diff
changeset
 | 
31  | 
|
| 60758 | 32  | 
setup \<open>  | 
| 
58400
 
d0d3c30806b4
always annotate potentially polymorphic Haskell numerals
 
haftmann 
parents: 
58350 
diff
changeset
 | 
33  | 
let  | 
| 
 
d0d3c30806b4
always annotate potentially polymorphic Haskell numerals
 
haftmann 
parents: 
58350 
diff
changeset
 | 
34  | 
val target = "Haskell_Quickcheck";  | 
| 
 
d0d3c30806b4
always annotate potentially polymorphic Haskell numerals
 
haftmann 
parents: 
58350 
diff
changeset
 | 
35  | 
fun print _ = Code_Haskell.print_numeral "Prelude.Int";  | 
| 
 
d0d3c30806b4
always annotate potentially polymorphic Haskell numerals
 
haftmann 
parents: 
58350 
diff
changeset
 | 
36  | 
in  | 
| 69593 | 37  | 
Numeral.add_code \<^const_name>\<open>Code_Numeral.Pos\<close> I print target  | 
38  | 
#> Numeral.add_code \<^const_name>\<open>Code_Numeral.Neg\<close> (~) print target  | 
|
| 
58400
 
d0d3c30806b4
always annotate potentially polymorphic Haskell numerals
 
haftmann 
parents: 
58350 
diff
changeset
 | 
39  | 
end  | 
| 60758 | 40  | 
\<close>  | 
| 
58400
 
d0d3c30806b4
always annotate potentially polymorphic Haskell numerals
 
haftmann 
parents: 
58350 
diff
changeset
 | 
41  | 
|
| 
42021
 
52551c0a3374
extending code_int type more; adding narrowing instance for type int; added test case for int instance
 
bulwahn 
parents: 
41965 
diff
changeset
 | 
42  | 
|
| 60758 | 43  | 
subsubsection \<open>Narrowing's deep representation of types and terms\<close>  | 
| 41905 | 44  | 
|
| 
58350
 
919149921e46
added 'extraction' plugins -- this might help 'HOL-Proofs'
 
blanchet 
parents: 
58334 
diff
changeset
 | 
45  | 
datatype (plugins only: code extraction) narrowing_type =  | 
| 58152 | 46  | 
Narrowing_sum_of_products "narrowing_type list list"  | 
47  | 
||
| 
58350
 
919149921e46
added 'extraction' plugins -- this might help 'HOL-Proofs'
 
blanchet 
parents: 
58334 
diff
changeset
 | 
48  | 
datatype (plugins only: code extraction) narrowing_term =  | 
| 58152 | 49  | 
Narrowing_variable "integer list" narrowing_type  | 
50  | 
| Narrowing_constructor integer "narrowing_term list"  | 
|
51  | 
||
| 
58350
 
919149921e46
added 'extraction' plugins -- this might help 'HOL-Proofs'
 
blanchet 
parents: 
58334 
diff
changeset
 | 
52  | 
datatype (plugins only: code extraction) (dead 'a) narrowing_cons =  | 
| 58152 | 53  | 
Narrowing_cons narrowing_type "(narrowing_term list \<Rightarrow> 'a) list"  | 
| 41905 | 54  | 
|
| 
46758
 
4106258260b3
choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
 
bulwahn 
parents: 
46589 
diff
changeset
 | 
55  | 
primrec map_cons :: "('a => 'b) => 'a narrowing_cons => 'b narrowing_cons"
 | 
| 43356 | 56  | 
where  | 
| 67091 | 57  | 
"map_cons f (Narrowing_cons ty cs) = Narrowing_cons ty (map (\<lambda>c. f \<circ> c) cs)"  | 
| 43356 | 58  | 
|
| 69593 | 59  | 
subsubsection \<open>From narrowing's deep representation of terms to \<^theory>\<open>HOL.Code_Evaluation\<close>'s terms\<close>  | 
| 
42980
 
859fe9cc0838
improving code_int setup in Quickcheck_Narrowing; adding partial_term_of class in Quickcheck_Narrowing
 
bulwahn 
parents: 
42024 
diff
changeset
 | 
60  | 
|
| 
 
859fe9cc0838
improving code_int setup in Quickcheck_Narrowing; adding partial_term_of class in Quickcheck_Narrowing
 
bulwahn 
parents: 
42024 
diff
changeset
 | 
61  | 
class partial_term_of = typerep +  | 
| 
43047
 
26774ccb1c74
automatic derivation of partial_term_of functions; renaming type and term to longer names narrowing_type and narrowing_term; hiding constant C; adding overlord option
 
bulwahn 
parents: 
42980 
diff
changeset
 | 
62  | 
fixes partial_term_of :: "'a itself => narrowing_term => Code_Evaluation.term"  | 
| 
 
26774ccb1c74
automatic derivation of partial_term_of functions; renaming type and term to longer names narrowing_type and narrowing_term; hiding constant C; adding overlord option
 
bulwahn 
parents: 
42980 
diff
changeset
 | 
63  | 
|
| 
 
26774ccb1c74
automatic derivation of partial_term_of functions; renaming type and term to longer names narrowing_type and narrowing_term; hiding constant C; adding overlord option
 
bulwahn 
parents: 
42980 
diff
changeset
 | 
64  | 
lemma partial_term_of_anything: "partial_term_of x nt \<equiv> t"  | 
| 
 
26774ccb1c74
automatic derivation of partial_term_of functions; renaming type and term to longer names narrowing_type and narrowing_term; hiding constant C; adding overlord option
 
bulwahn 
parents: 
42980 
diff
changeset
 | 
65  | 
by (rule eq_reflection) (cases "partial_term_of x nt", cases t, simp)  | 
| 43356 | 66  | 
|
| 60758 | 67  | 
subsubsection \<open>Auxilary functions for Narrowing\<close>  | 
| 41905 | 68  | 
|
| 
51143
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
69  | 
consts nth :: "'a list => integer => 'a"  | 
| 41905 | 70  | 
|
| 
52435
 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 
haftmann 
parents: 
51143 
diff
changeset
 | 
71  | 
code_printing constant nth \<rightharpoonup> (Haskell_Quickcheck) infixl 9 "!!"  | 
| 41905 | 72  | 
|
| 
41908
 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
 
bulwahn 
parents: 
41905 
diff
changeset
 | 
73  | 
consts error :: "char list => 'a"  | 
| 41905 | 74  | 
|
| 
52435
 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 
haftmann 
parents: 
51143 
diff
changeset
 | 
75  | 
code_printing constant error \<rightharpoonup> (Haskell_Quickcheck) "error"  | 
| 41905 | 76  | 
|
| 
51143
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
77  | 
consts toEnum :: "integer => char"  | 
| 
41908
 
3bd9a21366d2
changing invocation of ghc from interactive mode to compilation increases the performance of lazysmallcheck by a factor of twenty; changing Integer type to Int reduces by another 50 percent
 
bulwahn 
parents: 
41905 
diff
changeset
 | 
78  | 
|
| 
52435
 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 
haftmann 
parents: 
51143 
diff
changeset
 | 
79  | 
code_printing constant toEnum \<rightharpoonup> (Haskell_Quickcheck) "Prelude.toEnum"  | 
| 41905 | 80  | 
|
| 43316 | 81  | 
consts marker :: "char"  | 
| 41905 | 82  | 
|
| 
52435
 
6646bb548c6b
migration from code_(const|type|class|instance) to code_printing and from code_module to code_identifier
 
haftmann 
parents: 
51143 
diff
changeset
 | 
83  | 
code_printing constant marker \<rightharpoonup> (Haskell_Quickcheck) "''\\0'"  | 
| 43316 | 84  | 
|
| 60758 | 85  | 
subsubsection \<open>Narrowing's basic operations\<close>  | 
| 41905 | 86  | 
|
| 
51143
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
87  | 
type_synonym 'a narrowing = "integer => 'a narrowing_cons"  | 
| 41905 | 88  | 
|
| 
41961
 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 
bulwahn 
parents: 
41943 
diff
changeset
 | 
89  | 
definition cons :: "'a => 'a narrowing"  | 
| 41905 | 90  | 
where  | 
| 58152 | 91  | 
"cons a d = (Narrowing_cons (Narrowing_sum_of_products [[]]) [(\<lambda>_. a)])"  | 
| 41905 | 92  | 
|
| 
43047
 
26774ccb1c74
automatic derivation of partial_term_of functions; renaming type and term to longer names narrowing_type and narrowing_term; hiding constant C; adding overlord option
 
bulwahn 
parents: 
42980 
diff
changeset
 | 
93  | 
fun conv :: "(narrowing_term list => 'a) list => narrowing_term => 'a"  | 
| 41905 | 94  | 
where  | 
| 
46758
 
4106258260b3
choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
 
bulwahn 
parents: 
46589 
diff
changeset
 | 
95  | 
"conv cs (Narrowing_variable p _) = error (marker # map toEnum p)"  | 
| 
 
4106258260b3
choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
 
bulwahn 
parents: 
46589 
diff
changeset
 | 
96  | 
| "conv cs (Narrowing_constructor i xs) = (nth cs i) xs"  | 
| 41905 | 97  | 
|
| 
46758
 
4106258260b3
choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
 
bulwahn 
parents: 
46589 
diff
changeset
 | 
98  | 
fun non_empty :: "narrowing_type => bool"  | 
| 41905 | 99  | 
where  | 
| 
46758
 
4106258260b3
choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
 
bulwahn 
parents: 
46589 
diff
changeset
 | 
100  | 
"non_empty (Narrowing_sum_of_products ps) = (\<not> (List.null ps))"  | 
| 41905 | 101  | 
|
| 
41961
 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 
bulwahn 
parents: 
41943 
diff
changeset
 | 
102  | 
definition "apply" :: "('a => 'b) narrowing => 'a narrowing => 'b narrowing"
 | 
| 41905 | 103  | 
where  | 
| 65482 | 104  | 
"apply f a d = (if d > 0 then  | 
| 65480 | 105  | 
(case f d of Narrowing_cons (Narrowing_sum_of_products ps) cfs \<Rightarrow>  | 
106  | 
case a (d - 1) of Narrowing_cons ta cas \<Rightarrow>  | 
|
| 41905 | 107  | 
let  | 
| 65482 | 108  | 
shallow = non_empty ta;  | 
| 65480 | 109  | 
cs = [(\<lambda>(x # xs) \<Rightarrow> cf xs (conv cas x)). shallow, cf \<leftarrow> cfs]  | 
| 65482 | 110  | 
in Narrowing_cons (Narrowing_sum_of_products [ta # p. shallow, p \<leftarrow> ps]) cs)  | 
111  | 
else Narrowing_cons (Narrowing_sum_of_products []) [])"  | 
|
| 41905 | 112  | 
|
| 
41961
 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 
bulwahn 
parents: 
41943 
diff
changeset
 | 
113  | 
definition sum :: "'a narrowing => 'a narrowing => 'a narrowing"  | 
| 41905 | 114  | 
where  | 
115  | 
"sum a b d =  | 
|
| 67091 | 116  | 
(case a d of Narrowing_cons (Narrowing_sum_of_products ssa) ca \<Rightarrow>  | 
117  | 
case b d of Narrowing_cons (Narrowing_sum_of_products ssb) cb \<Rightarrow>  | 
|
| 
46758
 
4106258260b3
choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
 
bulwahn 
parents: 
46589 
diff
changeset
 | 
118  | 
Narrowing_cons (Narrowing_sum_of_products (ssa @ ssb)) (ca @ cb))"  | 
| 41905 | 119  | 
|
| 
41912
 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
 
bulwahn 
parents: 
41910 
diff
changeset
 | 
120  | 
lemma [fundef_cong]:  | 
| 
 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
 
bulwahn 
parents: 
41910 
diff
changeset
 | 
121  | 
assumes "a d = a' d" "b d = b' d" "d = d'"  | 
| 
 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
 
bulwahn 
parents: 
41910 
diff
changeset
 | 
122  | 
shows "sum a b d = sum a' b' d'"  | 
| 
46758
 
4106258260b3
choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
 
bulwahn 
parents: 
46589 
diff
changeset
 | 
123  | 
using assms unfolding sum_def by (auto split: narrowing_cons.split narrowing_type.split)  | 
| 
41912
 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
 
bulwahn 
parents: 
41910 
diff
changeset
 | 
124  | 
|
| 
 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
 
bulwahn 
parents: 
41910 
diff
changeset
 | 
125  | 
lemma [fundef_cong]:  | 
| 
51143
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
126  | 
assumes "f d = f' d" "(\<And>d'. 0 \<le> d' \<and> d' < d \<Longrightarrow> a d' = a' d')"  | 
| 
41912
 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
 
bulwahn 
parents: 
41910 
diff
changeset
 | 
127  | 
assumes "d = d'"  | 
| 
 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
 
bulwahn 
parents: 
41910 
diff
changeset
 | 
128  | 
shows "apply f a d = apply f' a' d'"  | 
| 
 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
 
bulwahn 
parents: 
41910 
diff
changeset
 | 
129  | 
proof -  | 
| 
51143
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
130  | 
note assms  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
131  | 
moreover have "0 < d' \<Longrightarrow> 0 \<le> d' - 1"  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
132  | 
by (simp add: less_integer_def less_eq_integer_def)  | 
| 
41912
 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
 
bulwahn 
parents: 
41910 
diff
changeset
 | 
133  | 
ultimately show ?thesis  | 
| 
51143
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
134  | 
by (auto simp add: apply_def Let_def  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
135  | 
split: narrowing_cons.split narrowing_type.split)  | 
| 
41912
 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
 
bulwahn 
parents: 
41910 
diff
changeset
 | 
136  | 
qed  | 
| 
 
1848775589e5
adding termination proofs to series functions in LSC; commenting out momentarily unused term refinement functions in LSC
 
bulwahn 
parents: 
41910 
diff
changeset
 | 
137  | 
|
| 60758 | 138  | 
subsubsection \<open>Narrowing generator type class\<close>  | 
| 41905 | 139  | 
|
| 
41961
 
fdd37cfcd4a3
renaming series and serial to narrowing in Quickcheck_Narrowing
 
bulwahn 
parents: 
41943 
diff
changeset
 | 
140  | 
class narrowing =  | 
| 
51143
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
141  | 
fixes narrowing :: "integer => 'a narrowing_cons"  | 
| 41905 | 142  | 
|
| 
58350
 
919149921e46
added 'extraction' plugins -- this might help 'HOL-Proofs'
 
blanchet 
parents: 
58334 
diff
changeset
 | 
143  | 
datatype (plugins only: code extraction) property =  | 
| 58334 | 144  | 
Universal narrowing_type "(narrowing_term => property)" "narrowing_term => Code_Evaluation.term"  | 
145  | 
| Existential narrowing_type "(narrowing_term => property)" "narrowing_term => Code_Evaluation.term"  | 
|
146  | 
| Property bool  | 
|
| 
43237
 
8f5c3c6c2909
adding compilation that allows existentials in Quickcheck_Narrowing
 
bulwahn 
parents: 
43047 
diff
changeset
 | 
147  | 
|
| 
 
8f5c3c6c2909
adding compilation that allows existentials in Quickcheck_Narrowing
 
bulwahn 
parents: 
43047 
diff
changeset
 | 
148  | 
(* FIXME: hard-wired maximal depth of 100 here *)  | 
| 
43315
 
893de45ac28d
removing unneccessary manual instantiations and dead definitions; hiding more constants and facts
 
bulwahn 
parents: 
43314 
diff
changeset
 | 
149  | 
definition exists :: "('a :: {narrowing, partial_term_of} => property) => property"
 | 
| 
43237
 
8f5c3c6c2909
adding compilation that allows existentials in Quickcheck_Narrowing
 
bulwahn 
parents: 
43047 
diff
changeset
 | 
150  | 
where  | 
| 67091 | 151  | 
  "exists f = (case narrowing (100 :: integer) of Narrowing_cons ty cs \<Rightarrow> Existential ty (\<lambda> t. f (conv cs t)) (partial_term_of (TYPE('a))))"
 | 
| 
43237
 
8f5c3c6c2909
adding compilation that allows existentials in Quickcheck_Narrowing
 
bulwahn 
parents: 
43047 
diff
changeset
 | 
152  | 
|
| 
43315
 
893de45ac28d
removing unneccessary manual instantiations and dead definitions; hiding more constants and facts
 
bulwahn 
parents: 
43314 
diff
changeset
 | 
153  | 
definition "all" :: "('a :: {narrowing, partial_term_of} => property) => property"
 | 
| 
43237
 
8f5c3c6c2909
adding compilation that allows existentials in Quickcheck_Narrowing
 
bulwahn 
parents: 
43047 
diff
changeset
 | 
154  | 
where  | 
| 67091 | 155  | 
  "all f = (case narrowing (100 :: integer) of Narrowing_cons ty cs \<Rightarrow> Universal ty (\<lambda>t. f (conv cs t)) (partial_term_of (TYPE('a))))"
 | 
| 
43237
 
8f5c3c6c2909
adding compilation that allows existentials in Quickcheck_Narrowing
 
bulwahn 
parents: 
43047 
diff
changeset
 | 
156  | 
|
| 61799 | 157  | 
subsubsection \<open>class \<open>is_testable\<close>\<close>  | 
| 41905 | 158  | 
|
| 61799 | 159  | 
text \<open>The class \<open>is_testable\<close> ensures that all necessary type instances are generated.\<close>  | 
| 41905 | 160  | 
|
161  | 
class is_testable  | 
|
162  | 
||
163  | 
instance bool :: is_testable ..  | 
|
164  | 
||
| 
43047
 
26774ccb1c74
automatic derivation of partial_term_of functions; renaming type and term to longer names narrowing_type and narrowing_term; hiding constant C; adding overlord option
 
bulwahn 
parents: 
42980 
diff
changeset
 | 
165  | 
instance "fun" :: ("{term_of, narrowing, partial_term_of}", is_testable) is_testable ..
 | 
| 41905 | 166  | 
|
167  | 
definition ensure_testable :: "'a :: is_testable => 'a :: is_testable"  | 
|
168  | 
where  | 
|
169  | 
"ensure_testable f = f"  | 
|
170  | 
||
| 
41910
 
709c04e7b703
adding serial instance of finite_4 in lazysmallcheck; changing code equations for implies
 
bulwahn 
parents: 
41909 
diff
changeset
 | 
171  | 
|
| 60758 | 172  | 
subsubsection \<open>Defining a simple datatype to represent functions in an incomplete and redundant way\<close>  | 
| 
42022
 
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
 
bulwahn 
parents: 
42021 
diff
changeset
 | 
173  | 
|
| 
58350
 
919149921e46
added 'extraction' plugins -- this might help 'HOL-Proofs'
 
blanchet 
parents: 
58334 
diff
changeset
 | 
174  | 
datatype (plugins only: code quickcheck_narrowing extraction) (dead 'a, dead 'b) ffun =  | 
| 58334 | 175  | 
Constant 'b  | 
176  | 
| Update 'a 'b "('a, 'b) ffun"
 | 
|
| 
42022
 
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
 
bulwahn 
parents: 
42021 
diff
changeset
 | 
177  | 
|
| 
 
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
 
bulwahn 
parents: 
42021 
diff
changeset
 | 
178  | 
primrec eval_ffun :: "('a, 'b) ffun => 'a => 'b"
 | 
| 
 
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
 
bulwahn 
parents: 
42021 
diff
changeset
 | 
179  | 
where  | 
| 
 
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
 
bulwahn 
parents: 
42021 
diff
changeset
 | 
180  | 
"eval_ffun (Constant c) x = c"  | 
| 
 
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
 
bulwahn 
parents: 
42021 
diff
changeset
 | 
181  | 
| "eval_ffun (Update x' y f) x = (if x = x' then y else eval_ffun f x)"  | 
| 
 
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
 
bulwahn 
parents: 
42021 
diff
changeset
 | 
182  | 
|
| 
 
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
 
bulwahn 
parents: 
42021 
diff
changeset
 | 
183  | 
hide_type (open) ffun  | 
| 
 
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
 
bulwahn 
parents: 
42021 
diff
changeset
 | 
184  | 
hide_const (open) Constant Update eval_ffun  | 
| 
 
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
 
bulwahn 
parents: 
42021 
diff
changeset
 | 
185  | 
|
| 
58350
 
919149921e46
added 'extraction' plugins -- this might help 'HOL-Proofs'
 
blanchet 
parents: 
58334 
diff
changeset
 | 
186  | 
datatype (plugins only: code quickcheck_narrowing extraction) (dead 'b) cfun = Constant 'b  | 
| 
42024
 
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
 
bulwahn 
parents: 
42022 
diff
changeset
 | 
187  | 
|
| 
 
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
 
bulwahn 
parents: 
42022 
diff
changeset
 | 
188  | 
primrec eval_cfun :: "'b cfun => 'a => 'b"  | 
| 
 
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
 
bulwahn 
parents: 
42022 
diff
changeset
 | 
189  | 
where  | 
| 
 
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
 
bulwahn 
parents: 
42022 
diff
changeset
 | 
190  | 
"eval_cfun (Constant c) y = c"  | 
| 
 
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
 
bulwahn 
parents: 
42022 
diff
changeset
 | 
191  | 
|
| 
 
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
 
bulwahn 
parents: 
42022 
diff
changeset
 | 
192  | 
hide_type (open) cfun  | 
| 
45734
 
1024dd30da42
hide quickcheck constants Abs_cfun and Rep_cfun, to avoid clash with HOLCF
 
huffman 
parents: 
45001 
diff
changeset
 | 
193  | 
hide_const (open) Constant eval_cfun Abs_cfun Rep_cfun  | 
| 
42024
 
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
 
bulwahn 
parents: 
42022 
diff
changeset
 | 
194  | 
|
| 60758 | 195  | 
subsubsection \<open>Setting up the counterexample generator\<close>  | 
| 
43237
 
8f5c3c6c2909
adding compilation that allows existentials in Quickcheck_Narrowing
 
bulwahn 
parents: 
43047 
diff
changeset
 | 
196  | 
|
| 69605 | 197  | 
external_file \<open>~~/src/HOL/Tools/Quickcheck/Narrowing_Engine.hs\<close>  | 
198  | 
external_file \<open>~~/src/HOL/Tools/Quickcheck/PNF_Narrowing_Engine.hs\<close>  | 
|
199  | 
ML_file \<open>Tools/Quickcheck/narrowing_generators.ML\<close>  | 
|
| 
42024
 
51df23535105
handling a quite restricted set of functions in Quickcheck_Narrowing by an easy transformation
 
bulwahn 
parents: 
42022 
diff
changeset
 | 
200  | 
|
| 
45001
 
5c8d7d6db682
ensuring that some constants are generated in the source code by adding calls in ensure_testable
 
bulwahn 
parents: 
43887 
diff
changeset
 | 
201  | 
definition narrowing_dummy_partial_term_of :: "('a :: partial_term_of) itself => narrowing_term => term"
 | 
| 
 
5c8d7d6db682
ensuring that some constants are generated in the source code by adding calls in ensure_testable
 
bulwahn 
parents: 
43887 
diff
changeset
 | 
202  | 
where  | 
| 
 
5c8d7d6db682
ensuring that some constants are generated in the source code by adding calls in ensure_testable
 
bulwahn 
parents: 
43887 
diff
changeset
 | 
203  | 
"narrowing_dummy_partial_term_of = partial_term_of"  | 
| 
 
5c8d7d6db682
ensuring that some constants are generated in the source code by adding calls in ensure_testable
 
bulwahn 
parents: 
43887 
diff
changeset
 | 
204  | 
|
| 
51143
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
205  | 
definition narrowing_dummy_narrowing :: "integer => ('a :: narrowing) narrowing_cons"
 | 
| 
45001
 
5c8d7d6db682
ensuring that some constants are generated in the source code by adding calls in ensure_testable
 
bulwahn 
parents: 
43887 
diff
changeset
 | 
206  | 
where  | 
| 
 
5c8d7d6db682
ensuring that some constants are generated in the source code by adding calls in ensure_testable
 
bulwahn 
parents: 
43887 
diff
changeset
 | 
207  | 
"narrowing_dummy_narrowing = narrowing"  | 
| 
 
5c8d7d6db682
ensuring that some constants are generated in the source code by adding calls in ensure_testable
 
bulwahn 
parents: 
43887 
diff
changeset
 | 
208  | 
|
| 
 
5c8d7d6db682
ensuring that some constants are generated in the source code by adding calls in ensure_testable
 
bulwahn 
parents: 
43887 
diff
changeset
 | 
209  | 
lemma [code]:  | 
| 
 
5c8d7d6db682
ensuring that some constants are generated in the source code by adding calls in ensure_testable
 
bulwahn 
parents: 
43887 
diff
changeset
 | 
210  | 
"ensure_testable f =  | 
| 
 
5c8d7d6db682
ensuring that some constants are generated in the source code by adding calls in ensure_testable
 
bulwahn 
parents: 
43887 
diff
changeset
 | 
211  | 
(let  | 
| 
51143
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
212  | 
x = narrowing_dummy_narrowing :: integer => bool narrowing_cons;  | 
| 
45001
 
5c8d7d6db682
ensuring that some constants are generated in the source code by adding calls in ensure_testable
 
bulwahn 
parents: 
43887 
diff
changeset
 | 
213  | 
y = narrowing_dummy_partial_term_of :: bool itself => narrowing_term => term;  | 
| 
 
5c8d7d6db682
ensuring that some constants are generated in the source code by adding calls in ensure_testable
 
bulwahn 
parents: 
43887 
diff
changeset
 | 
214  | 
z = (conv :: _ => _ => unit) in f)"  | 
| 
 
5c8d7d6db682
ensuring that some constants are generated in the source code by adding calls in ensure_testable
 
bulwahn 
parents: 
43887 
diff
changeset
 | 
215  | 
unfolding Let_def ensure_testable_def ..  | 
| 
 
5c8d7d6db682
ensuring that some constants are generated in the source code by adding calls in ensure_testable
 
bulwahn 
parents: 
43887 
diff
changeset
 | 
216  | 
|
| 60758 | 217  | 
subsection \<open>Narrowing for sets\<close>  | 
| 46308 | 218  | 
|
219  | 
instantiation set :: (narrowing) narrowing  | 
|
220  | 
begin  | 
|
221  | 
||
222  | 
definition "narrowing_set = Quickcheck_Narrowing.apply (Quickcheck_Narrowing.cons set) narrowing"  | 
|
223  | 
||
224  | 
instance ..  | 
|
225  | 
||
226  | 
end  | 
|
| 
45001
 
5c8d7d6db682
ensuring that some constants are generated in the source code by adding calls in ensure_testable
 
bulwahn 
parents: 
43887 
diff
changeset
 | 
227  | 
|
| 60758 | 228  | 
subsection \<open>Narrowing for integers\<close>  | 
| 43356 | 229  | 
|
230  | 
||
| 
51143
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
231  | 
definition drawn_from :: "'a list \<Rightarrow> 'a narrowing_cons"  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
232  | 
where  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
233  | 
"drawn_from xs =  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
234  | 
Narrowing_cons (Narrowing_sum_of_products (map (\<lambda>_. []) xs)) (map (\<lambda>x _. x) xs)"  | 
| 43356 | 235  | 
|
| 
51143
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
236  | 
function around_zero :: "int \<Rightarrow> int list"  | 
| 43356 | 237  | 
where  | 
238  | 
"around_zero i = (if i < 0 then [] else (if i = 0 then [0] else around_zero (i - 1) @ [i, -i]))"  | 
|
| 
51143
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
239  | 
by pat_completeness auto  | 
| 43356 | 240  | 
termination by (relation "measure nat") auto  | 
241  | 
||
| 
51143
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
242  | 
declare around_zero.simps [simp del]  | 
| 43356 | 243  | 
|
244  | 
lemma length_around_zero:  | 
|
245  | 
assumes "i >= 0"  | 
|
246  | 
shows "length (around_zero i) = 2 * nat i + 1"  | 
|
| 
51143
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
247  | 
proof (induct rule: int_ge_induct [OF assms])  | 
| 43356 | 248  | 
case 1  | 
249  | 
from 1 show ?case by (simp add: around_zero.simps)  | 
|
250  | 
next  | 
|
251  | 
case (2 i)  | 
|
252  | 
from 2 show ?case  | 
|
| 
51143
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
253  | 
by (simp add: around_zero.simps [of "i + 1"])  | 
| 43356 | 254  | 
qed  | 
255  | 
||
256  | 
instantiation int :: narrowing  | 
|
257  | 
begin  | 
|
258  | 
||
259  | 
definition  | 
|
| 
51143
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
260  | 
"narrowing_int d = (let (u :: _ \<Rightarrow> _ \<Rightarrow> unit) = conv; i = int_of_integer d  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
261  | 
in drawn_from (around_zero i))"  | 
| 43356 | 262  | 
|
263  | 
instance ..  | 
|
264  | 
||
265  | 
end  | 
|
266  | 
||
| 66148 | 267  | 
declare [[code drop: "partial_term_of :: int itself \<Rightarrow> _"]]  | 
| 43356 | 268  | 
|
269  | 
lemma [code]:  | 
|
| 
51143
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
270  | 
"partial_term_of (ty :: int itself) (Narrowing_variable p t) \<equiv>  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
271  | 
Code_Evaluation.Free (STR ''_'') (Typerep.Typerep (STR ''Int.int'') [])"  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
272  | 
"partial_term_of (ty :: int itself) (Narrowing_constructor i []) \<equiv>  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
273  | 
(if i mod 2 = 0  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
274  | 
then Code_Evaluation.term_of (- (int_of_integer i) div 2)  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
275  | 
else Code_Evaluation.term_of ((int_of_integer i + 1) div 2))"  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
276  | 
by (rule partial_term_of_anything)+  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
277  | 
|
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
278  | 
instantiation integer :: narrowing  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
279  | 
begin  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
280  | 
|
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
281  | 
definition  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
282  | 
"narrowing_integer d = (let (u :: _ \<Rightarrow> _ \<Rightarrow> unit) = conv; i = int_of_integer d  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
283  | 
in drawn_from (map integer_of_int (around_zero i)))"  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
284  | 
|
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
285  | 
instance ..  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
286  | 
|
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
287  | 
end  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
288  | 
|
| 66148 | 289  | 
declare [[code drop: "partial_term_of :: integer itself \<Rightarrow> _"]]  | 
| 
51143
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
290  | 
|
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
291  | 
lemma [code]:  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
292  | 
"partial_term_of (ty :: integer itself) (Narrowing_variable p t) \<equiv>  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
293  | 
Code_Evaluation.Free (STR ''_'') (Typerep.Typerep (STR ''Code_Numeral.integer'') [])"  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
294  | 
"partial_term_of (ty :: integer itself) (Narrowing_constructor i []) \<equiv>  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
295  | 
(if i mod 2 = 0  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
296  | 
then Code_Evaluation.term_of (- i div 2)  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
297  | 
else Code_Evaluation.term_of ((i + 1) div 2))"  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
298  | 
by (rule partial_term_of_anything)+  | 
| 43356 | 299  | 
|
| 
56401
 
3b2db6132bfd
add missing adaptation for narrowing to work with variables of type integer => integer
 
Andreas Lochbihler 
parents: 
56047 
diff
changeset
 | 
300  | 
code_printing constant "Code_Evaluation.term_of :: integer \<Rightarrow> term" \<rightharpoonup> (Haskell_Quickcheck)  | 
| 
 
3b2db6132bfd
add missing adaptation for narrowing to work with variables of type integer => integer
 
Andreas Lochbihler 
parents: 
56047 
diff
changeset
 | 
301  | 
  "(let { t = Typerep.Typerep \"Code'_Numeral.integer\" [];
 | 
| 
 
3b2db6132bfd
add missing adaptation for narrowing to work with variables of type integer => integer
 
Andreas Lochbihler 
parents: 
56047 
diff
changeset
 | 
302  | 
mkFunT s t = Typerep.Typerep \"fun\" [s, t];  | 
| 
 
3b2db6132bfd
add missing adaptation for narrowing to work with variables of type integer => integer
 
Andreas Lochbihler 
parents: 
56047 
diff
changeset
 | 
303  | 
numT = Typerep.Typerep \"Num.num\" [];  | 
| 
 
3b2db6132bfd
add missing adaptation for narrowing to work with variables of type integer => integer
 
Andreas Lochbihler 
parents: 
56047 
diff
changeset
 | 
304  | 
mkBit 0 = Generated'_Code.Const \"Num.num.Bit0\" (mkFunT numT numT);  | 
| 
 
3b2db6132bfd
add missing adaptation for narrowing to work with variables of type integer => integer
 
Andreas Lochbihler 
parents: 
56047 
diff
changeset
 | 
305  | 
mkBit 1 = Generated'_Code.Const \"Num.num.Bit1\" (mkFunT numT numT);  | 
| 
 
3b2db6132bfd
add missing adaptation for narrowing to work with variables of type integer => integer
 
Andreas Lochbihler 
parents: 
56047 
diff
changeset
 | 
306  | 
mkNumeral 1 = Generated'_Code.Const \"Num.num.One\" numT;  | 
| 
 
3b2db6132bfd
add missing adaptation for narrowing to work with variables of type integer => integer
 
Andreas Lochbihler 
parents: 
56047 
diff
changeset
 | 
307  | 
     mkNumeral i = let { q = i `Prelude.div` 2; r = i `Prelude.mod` 2 }
 | 
| 
 
3b2db6132bfd
add missing adaptation for narrowing to work with variables of type integer => integer
 
Andreas Lochbihler 
parents: 
56047 
diff
changeset
 | 
308  | 
in Generated'_Code.App (mkBit r) (mkNumeral q);  | 
| 
 
3b2db6132bfd
add missing adaptation for narrowing to work with variables of type integer => integer
 
Andreas Lochbihler 
parents: 
56047 
diff
changeset
 | 
309  | 
mkNumber 0 = Generated'_Code.Const \"Groups.zero'_class.zero\" t;  | 
| 
 
3b2db6132bfd
add missing adaptation for narrowing to work with variables of type integer => integer
 
Andreas Lochbihler 
parents: 
56047 
diff
changeset
 | 
310  | 
mkNumber 1 = Generated'_Code.Const \"Groups.one'_class.one\" t;  | 
| 
 
3b2db6132bfd
add missing adaptation for narrowing to work with variables of type integer => integer
 
Andreas Lochbihler 
parents: 
56047 
diff
changeset
 | 
311  | 
mkNumber i = if i > 0 then  | 
| 
 
3b2db6132bfd
add missing adaptation for narrowing to work with variables of type integer => integer
 
Andreas Lochbihler 
parents: 
56047 
diff
changeset
 | 
312  | 
Generated'_Code.App  | 
| 
 
3b2db6132bfd
add missing adaptation for narrowing to work with variables of type integer => integer
 
Andreas Lochbihler 
parents: 
56047 
diff
changeset
 | 
313  | 
(Generated'_Code.Const \"Num.numeral'_class.numeral\"  | 
| 
 
3b2db6132bfd
add missing adaptation for narrowing to work with variables of type integer => integer
 
Andreas Lochbihler 
parents: 
56047 
diff
changeset
 | 
314  | 
(mkFunT numT t))  | 
| 
 
3b2db6132bfd
add missing adaptation for narrowing to work with variables of type integer => integer
 
Andreas Lochbihler 
parents: 
56047 
diff
changeset
 | 
315  | 
(mkNumeral i)  | 
| 
 
3b2db6132bfd
add missing adaptation for narrowing to work with variables of type integer => integer
 
Andreas Lochbihler 
parents: 
56047 
diff
changeset
 | 
316  | 
else  | 
| 
 
3b2db6132bfd
add missing adaptation for narrowing to work with variables of type integer => integer
 
Andreas Lochbihler 
parents: 
56047 
diff
changeset
 | 
317  | 
Generated'_Code.App  | 
| 
 
3b2db6132bfd
add missing adaptation for narrowing to work with variables of type integer => integer
 
Andreas Lochbihler 
parents: 
56047 
diff
changeset
 | 
318  | 
(Generated'_Code.Const \"Groups.uminus'_class.uminus\" (mkFunT t t))  | 
| 
 
3b2db6132bfd
add missing adaptation for narrowing to work with variables of type integer => integer
 
Andreas Lochbihler 
parents: 
56047 
diff
changeset
 | 
319  | 
(mkNumber (- i)); } in mkNumber)"  | 
| 43356 | 320  | 
|
| 61799 | 321  | 
subsection \<open>The \<open>find_unused_assms\<close> command\<close>  | 
| 46589 | 322  | 
|
| 69605 | 323  | 
ML_file \<open>Tools/Quickcheck/find_unused_assms.ML\<close>  | 
| 46589 | 324  | 
|
| 60758 | 325  | 
subsection \<open>Closing up\<close>  | 
| 46589 | 326  | 
|
| 
51143
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
327  | 
hide_type narrowing_type narrowing_term narrowing_cons property  | 
| 
 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 
haftmann 
parents: 
50046 
diff
changeset
 | 
328  | 
hide_const map_cons nth error toEnum marker empty Narrowing_cons conv non_empty ensure_testable all exists drawn_from around_zero  | 
| 
46758
 
4106258260b3
choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
 
bulwahn 
parents: 
46589 
diff
changeset
 | 
329  | 
hide_const (open) Narrowing_variable Narrowing_constructor "apply" sum cons  | 
| 
 
4106258260b3
choosing longer constant names in Quickcheck_Narrowing to reduce the chances of name clashes in Quickcheck-Narrowing
 
bulwahn 
parents: 
46589 
diff
changeset
 | 
330  | 
hide_fact empty_def cons_def conv.simps non_empty.simps apply_def sum_def ensure_testable_def all_def exists_def  | 
| 
42022
 
101ce92333f4
adding a simple datatype for representing functions in Quickcheck_Narrowing
 
bulwahn 
parents: 
42021 
diff
changeset
 | 
331  | 
|
| 
45001
 
5c8d7d6db682
ensuring that some constants are generated in the source code by adding calls in ensure_testable
 
bulwahn 
parents: 
43887 
diff
changeset
 | 
332  | 
end  |