| author | traytel | 
| Wed, 17 Feb 2016 16:26:50 +0100 | |
| changeset 62333 | e4e09a6e3922 | 
| parent 61585 | a9599d3d7610 | 
| child 62597 | b3f2b8c906a6 | 
| permissions | -rw-r--r-- | 
| 35953 | 1 | theory Predicate_Compile_Alternative_Defs | 
| 36053 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 2 | imports Main | 
| 35953 | 3 | begin | 
| 4 | ||
| 60500 | 5 | section \<open>Common constants\<close> | 
| 35953 | 6 | |
| 7 | declare HOL.if_bool_eq_disj[code_pred_inline] | |
| 8 | ||
| 36253 
6e969ce3dfcc
added further inlining of boolean constants to the predicate compiler
 bulwahn parents: 
36246diff
changeset | 9 | declare bool_diff_def[code_pred_inline] | 
| 46905 | 10 | declare inf_bool_def[abs_def, code_pred_inline] | 
| 11 | declare less_bool_def[abs_def, code_pred_inline] | |
| 12 | declare le_bool_def[abs_def, code_pred_inline] | |
| 36253 
6e969ce3dfcc
added further inlining of boolean constants to the predicate compiler
 bulwahn parents: 
36246diff
changeset | 13 | |
| 
6e969ce3dfcc
added further inlining of boolean constants to the predicate compiler
 bulwahn parents: 
36246diff
changeset | 14 | lemma min_bool_eq [code_pred_inline]: "(min :: bool => bool => bool) == (op &)" | 
| 45970 
b6d0cff57d96
adjusted to set/pred distinction by means of type constructor `set`
 haftmann parents: 
45461diff
changeset | 15 | by (rule eq_reflection) (auto simp add: fun_eq_iff min_def) | 
| 36253 
6e969ce3dfcc
added further inlining of boolean constants to the predicate compiler
 bulwahn parents: 
36246diff
changeset | 16 | |
| 39650 
2a35950ec495
handling equivalences smarter in the predicate compiler
 bulwahn parents: 
39302diff
changeset | 17 | lemma [code_pred_inline]: | 
| 
2a35950ec495
handling equivalences smarter in the predicate compiler
 bulwahn parents: 
39302diff
changeset | 18 | "((A::bool) ~= (B::bool)) = ((A & ~ B) | (B & ~ A))" | 
| 
2a35950ec495
handling equivalences smarter in the predicate compiler
 bulwahn parents: 
39302diff
changeset | 19 | by fast | 
| 
2a35950ec495
handling equivalences smarter in the predicate compiler
 bulwahn parents: 
39302diff
changeset | 20 | |
| 60500 | 21 | setup \<open>Predicate_Compile_Data.ignore_consts [@{const_name Let}]\<close>
 | 
| 35953 | 22 | |
| 60500 | 23 | section \<open>Pairs\<close> | 
| 35953 | 24 | |
| 61424 
c3658c18b7bc
prod_case as canonical name for product type eliminator
 haftmann parents: 
61180diff
changeset | 25 | setup \<open>Predicate_Compile_Data.ignore_consts [@{const_name fst}, @{const_name snd}, @{const_name case_prod}]\<close>
 | 
| 35953 | 26 | |
| 60500 | 27 | section \<open>Filters\<close> | 
| 60045 
cd2b6debac18
predicate compiler: ignore Abs_filter and Rep_filter
 hoelzl parents: 
56679diff
changeset | 28 | |
| 
cd2b6debac18
predicate compiler: ignore Abs_filter and Rep_filter
 hoelzl parents: 
56679diff
changeset | 29 | (*TODO: shouldn't this be done by typedef? *) | 
| 60500 | 30 | setup \<open>Predicate_Compile_Data.ignore_consts [@{const_name Abs_filter}, @{const_name Rep_filter}]\<close>
 | 
| 60045 
cd2b6debac18
predicate compiler: ignore Abs_filter and Rep_filter
 hoelzl parents: 
56679diff
changeset | 31 | |
| 60500 | 32 | section \<open>Bounded quantifiers\<close> | 
| 35953 | 33 | |
| 34 | declare Ball_def[code_pred_inline] | |
| 35 | declare Bex_def[code_pred_inline] | |
| 36 | ||
| 60500 | 37 | section \<open>Operations on Predicates\<close> | 
| 35953 | 38 | |
| 39 | lemma Diff[code_pred_inline]: | |
| 40 | "(A - B) = (%x. A x \<and> \<not> B x)" | |
| 46884 | 41 | by (simp add: fun_eq_iff) | 
| 35953 | 42 | |
| 36253 
6e969ce3dfcc
added further inlining of boolean constants to the predicate compiler
 bulwahn parents: 
36246diff
changeset | 43 | lemma subset_eq[code_pred_inline]: | 
| 
6e969ce3dfcc
added further inlining of boolean constants to the predicate compiler
 bulwahn parents: 
36246diff
changeset | 44 | "(P :: 'a => bool) < (Q :: 'a => bool) == ((\<exists>x. Q x \<and> (\<not> P x)) \<and> (\<forall> x. P x --> Q x))" | 
| 45970 
b6d0cff57d96
adjusted to set/pred distinction by means of type constructor `set`
 haftmann parents: 
45461diff
changeset | 45 | by (rule eq_reflection) (auto simp add: less_fun_def le_fun_def) | 
| 36253 
6e969ce3dfcc
added further inlining of boolean constants to the predicate compiler
 bulwahn parents: 
36246diff
changeset | 46 | |
| 35953 | 47 | lemma set_equality[code_pred_inline]: | 
| 45970 
b6d0cff57d96
adjusted to set/pred distinction by means of type constructor `set`
 haftmann parents: 
45461diff
changeset | 48 | "A = B \<longleftrightarrow> (\<forall>x. A x \<longrightarrow> B x) \<and> (\<forall>x. B x \<longrightarrow> A x)" | 
| 
b6d0cff57d96
adjusted to set/pred distinction by means of type constructor `set`
 haftmann parents: 
45461diff
changeset | 49 | by (auto simp add: fun_eq_iff) | 
| 
b6d0cff57d96
adjusted to set/pred distinction by means of type constructor `set`
 haftmann parents: 
45461diff
changeset | 50 | |
| 60500 | 51 | section \<open>Setup for Numerals\<close> | 
| 35953 | 52 | |
| 60500 | 53 | setup \<open>Predicate_Compile_Data.ignore_consts [@{const_name numeral}]\<close>
 | 
| 54 | setup \<open>Predicate_Compile_Data.keep_functions [@{const_name numeral}]\<close>
 | |
| 35953 | 55 | |
| 60500 | 56 | setup \<open>Predicate_Compile_Data.ignore_consts [@{const_name divide}, @{const_name mod}, @{const_name times}]\<close>
 | 
| 35953 | 57 | |
| 60500 | 58 | section \<open>Arithmetic operations\<close> | 
| 36053 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 59 | |
| 60500 | 60 | subsection \<open>Arithmetic on naturals and integers\<close> | 
| 36053 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 61 | |
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 62 | definition plus_eq_nat :: "nat => nat => nat => bool" | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 63 | where | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 64 | "plus_eq_nat x y z = (x + y = z)" | 
| 35953 | 65 | |
| 36053 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 66 | definition minus_eq_nat :: "nat => nat => nat => bool" | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 67 | where | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 68 | "minus_eq_nat x y z = (x - y = z)" | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 69 | |
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 70 | definition plus_eq_int :: "int => int => int => bool" | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 71 | where | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 72 | "plus_eq_int x y z = (x + y = z)" | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 73 | |
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 74 | definition minus_eq_int :: "int => int => int => bool" | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 75 | where | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 76 | "minus_eq_int x y z = (x - y = z)" | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 77 | |
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 78 | definition subtract | 
| 35953 | 79 | where | 
| 45231 
d85a2fdc586c
replacing code_inline by code_unfold, removing obsolete code_unfold, code_inline del now that the ancient code generator is removed
 bulwahn parents: 
44928diff
changeset | 80 | [code_unfold]: "subtract x y = y - x" | 
| 35953 | 81 | |
| 60500 | 82 | setup \<open> | 
| 36053 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 83 | let | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 84 | val Fun = Predicate_Compile_Aux.Fun | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 85 | val Input = Predicate_Compile_Aux.Input | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 86 | val Output = Predicate_Compile_Aux.Output | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 87 | val Bool = Predicate_Compile_Aux.Bool | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 88 | val iio = Fun (Input, Fun (Input, Fun (Output, Bool))) | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 89 | val ioi = Fun (Input, Fun (Output, Fun (Input, Bool))) | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 90 | val oii = Fun (Output, Fun (Input, Fun (Input, Bool))) | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 91 | val ooi = Fun (Output, Fun (Output, Fun (Input, Bool))) | 
| 40054 
cd7b1fa20bce
adapting alternative_defs, predicate_compile_quickcheck, examples and code_prolog
 bulwahn parents: 
39650diff
changeset | 92 |   val plus_nat = Core_Data.functional_compilation @{const_name plus} iio
 | 
| 
cd7b1fa20bce
adapting alternative_defs, predicate_compile_quickcheck, examples and code_prolog
 bulwahn parents: 
39650diff
changeset | 93 |   val minus_nat = Core_Data.functional_compilation @{const_name "minus"} iio
 | 
| 36053 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 94 | fun subtract_nat compfuns (_ : typ) = | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 95 | let | 
| 45461 
130c90bb80b4
using more conventional names for monad plus operations
 bulwahn parents: 
45231diff
changeset | 96 |       val T = Predicate_Compile_Aux.mk_monadT compfuns @{typ nat}
 | 
| 36053 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 97 | in | 
| 44241 | 98 |       absdummy @{typ nat} (absdummy @{typ nat}
 | 
| 99 |         (Const (@{const_name "If"}, @{typ bool} --> T --> T --> T) $
 | |
| 36053 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 100 |           (@{term "op > :: nat => nat => bool"} $ Bound 1 $ Bound 0) $
 | 
| 45461 
130c90bb80b4
using more conventional names for monad plus operations
 bulwahn parents: 
45231diff
changeset | 101 |           Predicate_Compile_Aux.mk_empty compfuns @{typ nat} $
 | 
| 36053 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 102 | Predicate_Compile_Aux.mk_single compfuns | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 103 |           (@{term "op - :: nat => nat => nat"} $ Bound 0 $ Bound 1)))
 | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 104 | end | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 105 | fun enumerate_addups_nat compfuns (_ : typ) = | 
| 44241 | 106 |     absdummy @{typ nat} (Predicate_Compile_Aux.mk_iterate_upto compfuns @{typ "nat * nat"}
 | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
48640diff
changeset | 107 |     (absdummy @{typ natural} (@{term "Pair :: nat => nat => nat * nat"} $
 | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
48640diff
changeset | 108 |       (@{term "nat_of_natural"} $ Bound 0) $
 | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
48640diff
changeset | 109 |       (@{term "op - :: nat => nat => nat"} $ Bound 1 $ (@{term "nat_of_natural"} $ Bound 0))),
 | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
48640diff
changeset | 110 |       @{term "0 :: natural"}, @{term "natural_of_nat"} $ Bound 0))
 | 
| 36053 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 111 | fun enumerate_nats compfuns (_ : typ) = | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 112 | let | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 113 |       val (single_const, _) = strip_comb (Predicate_Compile_Aux.mk_single compfuns @{term "0 :: nat"})
 | 
| 45461 
130c90bb80b4
using more conventional names for monad plus operations
 bulwahn parents: 
45231diff
changeset | 114 |       val T = Predicate_Compile_Aux.mk_monadT compfuns @{typ nat}
 | 
| 36053 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 115 | in | 
| 44241 | 116 |       absdummy @{typ nat} (absdummy @{typ nat}
 | 
| 117 |         (Const (@{const_name If}, @{typ bool} --> T --> T --> T) $
 | |
| 36053 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 118 |           (@{term "op = :: nat => nat => bool"} $ Bound 0 $ @{term "0::nat"}) $
 | 
| 51143 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
48640diff
changeset | 119 |           (Predicate_Compile_Aux.mk_iterate_upto compfuns @{typ nat} (@{term "nat_of_natural"},
 | 
| 
0a2371e7ced3
two target language numeral types: integer and natural, as replacement for code_numeral;
 haftmann parents: 
48640diff
changeset | 120 |             @{term "0::natural"}, @{term "natural_of_nat"} $ Bound 1)) $
 | 
| 36053 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 121 |             (single_const $ (@{term "op + :: nat => nat => nat"} $ Bound 1 $ Bound 0))))
 | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 122 | end | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 123 | in | 
| 40054 
cd7b1fa20bce
adapting alternative_defs, predicate_compile_quickcheck, examples and code_prolog
 bulwahn parents: 
39650diff
changeset | 124 |   Core_Data.force_modes_and_compilations @{const_name plus_eq_nat}
 | 
| 36053 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 125 | [(iio, (plus_nat, false)), (oii, (subtract_nat, false)), (ioi, (subtract_nat, false)), | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 126 | (ooi, (enumerate_addups_nat, false))] | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 127 | #> Predicate_Compile_Fun.add_function_predicate_translation | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 128 |        (@{term "plus :: nat => nat => nat"}, @{term "plus_eq_nat"})
 | 
| 40054 
cd7b1fa20bce
adapting alternative_defs, predicate_compile_quickcheck, examples and code_prolog
 bulwahn parents: 
39650diff
changeset | 129 |   #> Core_Data.force_modes_and_compilations @{const_name minus_eq_nat}
 | 
| 36053 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 130 | [(iio, (minus_nat, false)), (oii, (enumerate_nats, false))] | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 131 | #> Predicate_Compile_Fun.add_function_predicate_translation | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 132 |       (@{term "minus :: nat => nat => nat"}, @{term "minus_eq_nat"})
 | 
| 40054 
cd7b1fa20bce
adapting alternative_defs, predicate_compile_quickcheck, examples and code_prolog
 bulwahn parents: 
39650diff
changeset | 133 |   #> Core_Data.force_modes_and_functions @{const_name plus_eq_int}
 | 
| 36053 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 134 |     [(iio, (@{const_name plus}, false)), (ioi, (@{const_name subtract}, false)),
 | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 135 |      (oii, (@{const_name subtract}, false))]
 | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 136 | #> Predicate_Compile_Fun.add_function_predicate_translation | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 137 |        (@{term "plus :: int => int => int"}, @{term "plus_eq_int"})
 | 
| 40054 
cd7b1fa20bce
adapting alternative_defs, predicate_compile_quickcheck, examples and code_prolog
 bulwahn parents: 
39650diff
changeset | 138 |   #> Core_Data.force_modes_and_functions @{const_name minus_eq_int}
 | 
| 36053 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 139 |     [(iio, (@{const_name minus}, false)), (oii, (@{const_name plus}, false)),
 | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 140 |      (ioi, (@{const_name minus}, false))]
 | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 141 | #> Predicate_Compile_Fun.add_function_predicate_translation | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 142 |       (@{term "minus :: int => int => int"}, @{term "minus_eq_int"})
 | 
| 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 143 | end | 
| 60500 | 144 | \<close> | 
| 36053 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 145 | |
| 60500 | 146 | subsection \<open>Inductive definitions for ordering on naturals\<close> | 
| 35953 | 147 | |
| 148 | inductive less_nat | |
| 149 | where | |
| 150 | "less_nat 0 (Suc y)" | |
| 151 | | "less_nat x y ==> less_nat (Suc x) (Suc y)" | |
| 152 | ||
| 36246 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 bulwahn parents: 
36053diff
changeset | 153 | lemma less_nat[code_pred_inline]: | 
| 35953 | 154 | "x < y = less_nat x y" | 
| 155 | apply (rule iffI) | |
| 156 | apply (induct x arbitrary: y) | |
| 157 | apply (case_tac y) apply (auto intro: less_nat.intros) | |
| 158 | apply (case_tac y) | |
| 159 | apply (auto intro: less_nat.intros) | |
| 160 | apply (induct rule: less_nat.induct) | |
| 161 | apply auto | |
| 162 | done | |
| 163 | ||
| 164 | inductive less_eq_nat | |
| 165 | where | |
| 166 | "less_eq_nat 0 y" | |
| 167 | | "less_eq_nat x y ==> less_eq_nat (Suc x) (Suc y)" | |
| 168 | ||
| 169 | lemma [code_pred_inline]: | |
| 170 | "x <= y = less_eq_nat x y" | |
| 171 | apply (rule iffI) | |
| 172 | apply (induct x arbitrary: y) | |
| 173 | apply (auto intro: less_eq_nat.intros) | |
| 174 | apply (case_tac y) apply (auto intro: less_eq_nat.intros) | |
| 175 | apply (induct rule: less_eq_nat.induct) | |
| 176 | apply auto done | |
| 177 | ||
| 60500 | 178 | section \<open>Alternative list definitions\<close> | 
| 35953 | 179 | |
| 61585 | 180 | subsection \<open>Alternative rules for \<open>length\<close>\<close> | 
| 36053 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 181 | |
| 56679 | 182 | definition size_list' :: "'a list => nat" | 
| 183 | where "size_list' = size" | |
| 36053 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 184 | |
| 56679 | 185 | lemma size_list'_simps: | 
| 186 | "size_list' [] = 0" | |
| 187 | "size_list' (x # xs) = Suc (size_list' xs)" | |
| 188 | by (auto simp add: size_list'_def) | |
| 36053 
29e242e9e9a3
adding setup for handling arithmetic of natural numbers and integers precisely and more efficiently in the predicate compiler; changed alternative size_list definition for predicate compiler
 bulwahn parents: 
35953diff
changeset | 189 | |
| 56679 | 190 | declare size_list'_simps[code_pred_def] | 
| 191 | declare size_list'_def[symmetric, code_pred_inline] | |
| 35953 | 192 | |
| 193 | ||
| 61585 | 194 | subsection \<open>Alternative rules for \<open>list_all2\<close>\<close> | 
| 35953 | 195 | |
| 196 | lemma list_all2_NilI [code_pred_intro]: "list_all2 P [] []" | |
| 197 | by auto | |
| 198 | ||
| 199 | lemma list_all2_ConsI [code_pred_intro]: "list_all2 P xs ys ==> P x y ==> list_all2 P (x#xs) (y#ys)" | |
| 200 | by auto | |
| 201 | ||
| 202 | code_pred [skip_proof] list_all2 | |
| 203 | proof - | |
| 204 | case list_all2 | |
| 205 | from this show thesis | |
| 206 | apply - | |
| 207 | apply (case_tac xb) | |
| 208 | apply (case_tac xc) | |
| 209 | apply auto | |
| 210 | apply (case_tac xc) | |
| 211 | apply auto | |
| 212 | done | |
| 213 | qed | |
| 214 | ||
| 61140 
78ece168f5b5
reactivate examples with predicate compiler and quickcheck
 Andreas Lochbihler parents: 
61125diff
changeset | 215 | subsection \<open>Alternative rules for membership in lists\<close> | 
| 
78ece168f5b5
reactivate examples with predicate compiler and quickcheck
 Andreas Lochbihler parents: 
61125diff
changeset | 216 | |
| 
78ece168f5b5
reactivate examples with predicate compiler and quickcheck
 Andreas Lochbihler parents: 
61125diff
changeset | 217 | declare in_set_member[code_pred_inline] | 
| 
78ece168f5b5
reactivate examples with predicate compiler and quickcheck
 Andreas Lochbihler parents: 
61125diff
changeset | 218 | |
| 
78ece168f5b5
reactivate examples with predicate compiler and quickcheck
 Andreas Lochbihler parents: 
61125diff
changeset | 219 | lemma member_intros [code_pred_intro]: | 
| 
78ece168f5b5
reactivate examples with predicate compiler and quickcheck
 Andreas Lochbihler parents: 
61125diff
changeset | 220 | "List.member (x#xs) x" | 
| 
78ece168f5b5
reactivate examples with predicate compiler and quickcheck
 Andreas Lochbihler parents: 
61125diff
changeset | 221 | "List.member xs x \<Longrightarrow> List.member (y#xs) x" | 
| 
78ece168f5b5
reactivate examples with predicate compiler and quickcheck
 Andreas Lochbihler parents: 
61125diff
changeset | 222 | by(simp_all add: List.member_def) | 
| 
78ece168f5b5
reactivate examples with predicate compiler and quickcheck
 Andreas Lochbihler parents: 
61125diff
changeset | 223 | |
| 
78ece168f5b5
reactivate examples with predicate compiler and quickcheck
 Andreas Lochbihler parents: 
61125diff
changeset | 224 | code_pred List.member | 
| 
78ece168f5b5
reactivate examples with predicate compiler and quickcheck
 Andreas Lochbihler parents: 
61125diff
changeset | 225 | by(auto simp add: List.member_def elim: list.set_cases) | 
| 
78ece168f5b5
reactivate examples with predicate compiler and quickcheck
 Andreas Lochbihler parents: 
61125diff
changeset | 226 | |
| 61180 | 227 | code_identifier constant member_i_i | 
| 228 | \<rightharpoonup> (SML) "List.member_i_i" | |
| 229 | and (OCaml) "List.member_i_i" | |
| 230 | and (Haskell) "List.member_i_i" | |
| 231 | and (Scala) "List.member_i_i" | |
| 232 | ||
| 233 | code_identifier constant member_i_o | |
| 234 | \<rightharpoonup> (SML) "List.member_i_o" | |
| 235 | and (OCaml) "List.member_i_o" | |
| 236 | and (Haskell) "List.member_i_o" | |
| 237 | and (Scala) "List.member_i_o" | |
| 238 | ||
| 60500 | 239 | section \<open>Setup for String.literal\<close> | 
| 40548 
54eb5fd36e5e
ignoring the constant STR in the predicate compiler
 bulwahn parents: 
40054diff
changeset | 240 | |
| 60500 | 241 | setup \<open>Predicate_Compile_Data.ignore_consts [@{const_name "STR"}]\<close>
 | 
| 40548 
54eb5fd36e5e
ignoring the constant STR in the predicate compiler
 bulwahn parents: 
40054diff
changeset | 242 | |
| 60500 | 243 | section \<open>Simplification rules for optimisation\<close> | 
| 36246 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 bulwahn parents: 
36053diff
changeset | 244 | |
| 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 bulwahn parents: 
36053diff
changeset | 245 | lemma [code_pred_simp]: "\<not> False == True" | 
| 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 bulwahn parents: 
36053diff
changeset | 246 | by auto | 
| 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 bulwahn parents: 
36053diff
changeset | 247 | |
| 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 bulwahn parents: 
36053diff
changeset | 248 | lemma [code_pred_simp]: "\<not> True == False" | 
| 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 bulwahn parents: 
36053diff
changeset | 249 | by auto | 
| 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 bulwahn parents: 
36053diff
changeset | 250 | |
| 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 bulwahn parents: 
36053diff
changeset | 251 | lemma less_nat_k_0 [code_pred_simp]: "less_nat k 0 == False" | 
| 
43fecedff8cf
added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
 bulwahn parents: 
36053diff
changeset | 252 | unfolding less_nat[symmetric] by auto | 
| 35953 | 253 | |
| 46884 | 254 | end |