src/HOL/Library/Predicate_Compile_Alternative_Defs.thy
author wenzelm
Sat, 07 Apr 2012 16:41:59 +0200
changeset 47389 e8552cba702d
parent 47108 2a1953f0d20d
child 47840 732ea1f08e3f
permissions -rw-r--r--
explicit checks stable_finished_theory/stable_command allow parallel asynchronous command transactions; tuned;
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
35953
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
     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: 35953
diff changeset
     2
imports Main
35953
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
     3
begin
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
     4
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
     5
section {* Common constants *}
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
     6
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
     7
declare HOL.if_bool_eq_disj[code_pred_inline]
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
     8
36253
6e969ce3dfcc added further inlining of boolean constants to the predicate compiler
bulwahn
parents: 36246
diff changeset
     9
declare bool_diff_def[code_pred_inline]
46905
6b1c0a80a57a prefer abs_def over def_raw;
wenzelm
parents: 46884
diff changeset
    10
declare inf_bool_def[abs_def, code_pred_inline]
6b1c0a80a57a prefer abs_def over def_raw;
wenzelm
parents: 46884
diff changeset
    11
declare less_bool_def[abs_def, code_pred_inline]
6b1c0a80a57a prefer abs_def over def_raw;
wenzelm
parents: 46884
diff changeset
    12
declare le_bool_def[abs_def, code_pred_inline]
36253
6e969ce3dfcc added further inlining of boolean constants to the predicate compiler
bulwahn
parents: 36246
diff changeset
    13
6e969ce3dfcc added further inlining of boolean constants to the predicate compiler
bulwahn
parents: 36246
diff 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: 45461
diff 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: 36246
diff changeset
    16
39650
2a35950ec495 handling equivalences smarter in the predicate compiler
bulwahn
parents: 39302
diff changeset
    17
lemma [code_pred_inline]: 
2a35950ec495 handling equivalences smarter in the predicate compiler
bulwahn
parents: 39302
diff changeset
    18
  "((A::bool) ~= (B::bool)) = ((A & ~ B) | (B & ~ A))"
2a35950ec495 handling equivalences smarter in the predicate compiler
bulwahn
parents: 39302
diff changeset
    19
by fast
2a35950ec495 handling equivalences smarter in the predicate compiler
bulwahn
parents: 39302
diff changeset
    20
35953
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
    21
setup {* Predicate_Compile_Data.ignore_consts [@{const_name Let}] *}
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
    22
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
    23
section {* Pairs *}
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
    24
37591
d3daea901123 merged constants "split" and "prod_case"
haftmann
parents: 36253
diff changeset
    25
setup {* Predicate_Compile_Data.ignore_consts [@{const_name fst}, @{const_name snd}, @{const_name prod_case}] *}
35953
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
    26
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
    27
section {* Bounded quantifiers *}
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
    28
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
    29
declare Ball_def[code_pred_inline]
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
    30
declare Bex_def[code_pred_inline]
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
    31
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
    32
section {* Set operations *}
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
    33
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
    34
declare eq_reflection[OF empty_def, code_pred_inline]
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
    35
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
    36
declare subset_iff[code_pred_inline]
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
    37
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
    38
declare Int_def[code_pred_inline]
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
    39
declare eq_reflection[OF Un_def, code_pred_inline]
44928
7ef6505bde7f renamed Complete_Lattices lemmas, removed legacy names
hoelzl
parents: 44890
diff changeset
    40
declare eq_reflection[OF UNION_eq, code_pred_inline]
35953
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
    41
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
    42
lemma Diff[code_pred_inline]:
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
    43
  "(A - B) = (%x. A x \<and> \<not> B x)"
46884
154dc6ec0041 tuned proofs
noschinl
parents: 45970
diff changeset
    44
  by (simp add: fun_eq_iff)
35953
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
    45
36253
6e969ce3dfcc added further inlining of boolean constants to the predicate compiler
bulwahn
parents: 36246
diff changeset
    46
lemma subset_eq[code_pred_inline]:
6e969ce3dfcc added further inlining of boolean constants to the predicate compiler
bulwahn
parents: 36246
diff changeset
    47
  "(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: 45461
diff changeset
    48
  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: 36246
diff changeset
    49
35953
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
    50
lemma set_equality[code_pred_inline]:
45970
b6d0cff57d96 adjusted to set/pred distinction by means of type constructor `set`
haftmann
parents: 45461
diff changeset
    51
  "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: 45461
diff changeset
    52
  by (auto simp add: fun_eq_iff)
b6d0cff57d96 adjusted to set/pred distinction by means of type constructor `set`
haftmann
parents: 45461
diff changeset
    53
35953
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
    54
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
    55
section {* Setup for Numerals *}
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
    56
47108
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46905
diff changeset
    57
setup {* Predicate_Compile_Data.ignore_consts [@{const_name numeral}, @{const_name neg_numeral}] *}
2a1953f0d20d merged fork with new numeral representation (see NEWS)
huffman
parents: 46905
diff changeset
    58
setup {* Predicate_Compile_Data.keep_functions [@{const_name numeral}, @{const_name neg_numeral}] *}
35953
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
    59
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
    60
setup {* Predicate_Compile_Data.ignore_consts [@{const_name div}, @{const_name mod}, @{const_name times}] *}
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
    61
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: 35953
diff changeset
    62
section {* Arithmetic operations *}
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: 35953
diff changeset
    63
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: 35953
diff changeset
    64
subsection {* Arithmetic on naturals and integers *}
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: 35953
diff changeset
    65
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: 35953
diff changeset
    66
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: 35953
diff 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: 35953
diff changeset
    68
  "plus_eq_nat x y z = (x + y = z)"
35953
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
    69
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: 35953
diff changeset
    70
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: 35953
diff 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: 35953
diff changeset
    72
  "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: 35953
diff 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: 35953
diff changeset
    74
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: 35953
diff 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: 35953
diff changeset
    76
  "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: 35953
diff 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: 35953
diff changeset
    78
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: 35953
diff changeset
    79
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: 35953
diff changeset
    80
  "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: 35953
diff changeset
    81
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: 35953
diff changeset
    82
definition subtract
35953
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
    83
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: 44928
diff changeset
    84
  [code_unfold]: "subtract x y = y - x"
35953
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
    85
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: 35953
diff changeset
    86
setup {*
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: 35953
diff changeset
    87
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: 35953
diff changeset
    88
  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: 35953
diff changeset
    89
  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: 35953
diff changeset
    90
  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: 35953
diff changeset
    91
  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: 35953
diff changeset
    92
  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: 35953
diff changeset
    93
  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: 35953
diff changeset
    94
  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: 35953
diff changeset
    95
  val ooi = Fun (Output, Fun (Output, Fun (Input, Bool)))
40054
cd7b1fa20bce adapting alternative_defs, predicate_compile_quickcheck, examples and code_prolog
bulwahn
parents: 39650
diff changeset
    96
  val plus_nat = Core_Data.functional_compilation @{const_name plus} iio
cd7b1fa20bce adapting alternative_defs, predicate_compile_quickcheck, examples and code_prolog
bulwahn
parents: 39650
diff changeset
    97
  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: 35953
diff changeset
    98
  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: 35953
diff changeset
    99
    let
45461
130c90bb80b4 using more conventional names for monad plus operations
bulwahn
parents: 45231
diff changeset
   100
      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: 35953
diff changeset
   101
    in
44241
7943b69f0188 modernized signature of Term.absfree/absdummy;
wenzelm
parents: 41075
diff changeset
   102
      absdummy @{typ nat} (absdummy @{typ nat}
7943b69f0188 modernized signature of Term.absfree/absdummy;
wenzelm
parents: 41075
diff changeset
   103
        (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: 35953
diff changeset
   104
          (@{term "op > :: nat => nat => bool"} $ Bound 1 $ Bound 0) $
45461
130c90bb80b4 using more conventional names for monad plus operations
bulwahn
parents: 45231
diff changeset
   105
          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: 35953
diff changeset
   106
          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: 35953
diff changeset
   107
          (@{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: 35953
diff changeset
   108
    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: 35953
diff changeset
   109
  fun enumerate_addups_nat compfuns (_ : typ) =
44241
7943b69f0188 modernized signature of Term.absfree/absdummy;
wenzelm
parents: 41075
diff changeset
   110
    absdummy @{typ nat} (Predicate_Compile_Aux.mk_iterate_upto compfuns @{typ "nat * nat"}
7943b69f0188 modernized signature of Term.absfree/absdummy;
wenzelm
parents: 41075
diff changeset
   111
    (absdummy @{typ code_numeral} (@{term "Pair :: nat => nat => nat * 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: 35953
diff changeset
   112
      (@{term "Code_Numeral.nat_of"} $ 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: 35953
diff changeset
   113
      (@{term "op - :: nat => nat => nat"} $ Bound 1 $ (@{term "Code_Numeral.nat_of"} $ 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: 35953
diff changeset
   114
      @{term "0 :: code_numeral"}, @{term "Code_Numeral.of_nat"} $ 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: 35953
diff changeset
   115
  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: 35953
diff changeset
   116
    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: 35953
diff changeset
   117
      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: 45231
diff changeset
   118
      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: 35953
diff changeset
   119
    in
44241
7943b69f0188 modernized signature of Term.absfree/absdummy;
wenzelm
parents: 41075
diff changeset
   120
      absdummy @{typ nat} (absdummy @{typ nat}
7943b69f0188 modernized signature of Term.absfree/absdummy;
wenzelm
parents: 41075
diff changeset
   121
        (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: 35953
diff changeset
   122
          (@{term "op = :: nat => nat => bool"} $ Bound 0 $ @{term "0::nat"}) $
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: 35953
diff changeset
   123
          (Predicate_Compile_Aux.mk_iterate_upto compfuns @{typ nat} (@{term "Code_Numeral.nat_of"},
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: 35953
diff changeset
   124
            @{term "0::code_numeral"}, @{term "Code_Numeral.of_nat"} $ 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: 35953
diff changeset
   125
            (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: 35953
diff changeset
   126
    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: 35953
diff changeset
   127
in
40054
cd7b1fa20bce adapting alternative_defs, predicate_compile_quickcheck, examples and code_prolog
bulwahn
parents: 39650
diff changeset
   128
  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: 35953
diff changeset
   129
    [(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: 35953
diff changeset
   130
     (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: 35953
diff 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: 35953
diff changeset
   132
       (@{term "plus :: nat => nat => nat"}, @{term "plus_eq_nat"})
40054
cd7b1fa20bce adapting alternative_defs, predicate_compile_quickcheck, examples and code_prolog
bulwahn
parents: 39650
diff changeset
   133
  #> 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: 35953
diff changeset
   134
       [(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: 35953
diff changeset
   135
  #> 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: 35953
diff changeset
   136
      (@{term "minus :: nat => nat => nat"}, @{term "minus_eq_nat"})
40054
cd7b1fa20bce adapting alternative_defs, predicate_compile_quickcheck, examples and code_prolog
bulwahn
parents: 39650
diff changeset
   137
  #> 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: 35953
diff changeset
   138
    [(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: 35953
diff changeset
   139
     (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: 35953
diff changeset
   140
  #> 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: 35953
diff changeset
   141
       (@{term "plus :: int => int => int"}, @{term "plus_eq_int"})
40054
cd7b1fa20bce adapting alternative_defs, predicate_compile_quickcheck, examples and code_prolog
bulwahn
parents: 39650
diff changeset
   142
  #> 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: 35953
diff changeset
   143
    [(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: 35953
diff changeset
   144
     (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: 35953
diff changeset
   145
  #> 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: 35953
diff changeset
   146
      (@{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: 35953
diff changeset
   147
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: 35953
diff changeset
   148
*}
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: 35953
diff changeset
   149
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: 35953
diff changeset
   150
subsection {* Inductive definitions for ordering on naturals *}
35953
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   151
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   152
inductive less_nat
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   153
where
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   154
  "less_nat 0 (Suc y)"
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   155
| "less_nat x y ==> less_nat (Suc x) (Suc y)"
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   156
36246
43fecedff8cf added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
bulwahn
parents: 36053
diff changeset
   157
lemma less_nat[code_pred_inline]:
35953
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   158
  "x < y = less_nat x y"
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   159
apply (rule iffI)
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   160
apply (induct x arbitrary: y)
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   161
apply (case_tac y) apply (auto intro: less_nat.intros)
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   162
apply (case_tac y)
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   163
apply (auto intro: less_nat.intros)
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   164
apply (induct rule: less_nat.induct)
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   165
apply auto
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   166
done
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   167
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   168
inductive less_eq_nat
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   169
where
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   170
  "less_eq_nat 0 y"
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   171
| "less_eq_nat x y ==> less_eq_nat (Suc x) (Suc y)"
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   172
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   173
lemma [code_pred_inline]:
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   174
"x <= y = less_eq_nat x y"
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   175
apply (rule iffI)
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   176
apply (induct x arbitrary: y)
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   177
apply (auto intro: less_eq_nat.intros)
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   178
apply (case_tac y) apply (auto intro: less_eq_nat.intros)
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   179
apply (induct rule: less_eq_nat.induct)
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   180
apply auto done
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   181
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   182
section {* Alternative list definitions *}
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   183
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: 35953
diff changeset
   184
subsection {* Alternative rules for length *}
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: 35953
diff changeset
   185
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: 35953
diff changeset
   186
definition size_list :: "'a list => nat"
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: 35953
diff changeset
   187
where "size_list = size"
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: 35953
diff changeset
   188
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: 35953
diff changeset
   189
lemma size_list_simps:
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: 35953
diff changeset
   190
  "size_list [] = 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: 35953
diff changeset
   191
  "size_list (x # xs) = Suc (size_list xs)"
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: 35953
diff changeset
   192
by (auto simp add: size_list_def)
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: 35953
diff changeset
   193
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: 35953
diff changeset
   194
declare size_list_simps[code_pred_def]
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: 35953
diff changeset
   195
declare size_list_def[symmetric, code_pred_inline]
35953
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   196
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   197
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   198
subsection {* Alternative rules for list_all2 *}
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   199
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   200
lemma list_all2_NilI [code_pred_intro]: "list_all2 P [] []"
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   201
by auto
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   202
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   203
lemma list_all2_ConsI [code_pred_intro]: "list_all2 P xs ys ==> P x y ==> list_all2 P (x#xs) (y#ys)"
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   204
by auto
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   205
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   206
code_pred [skip_proof] list_all2
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   207
proof -
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   208
  case list_all2
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   209
  from this show thesis
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   210
    apply -
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   211
    apply (case_tac xb)
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   212
    apply (case_tac xc)
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   213
    apply auto
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   214
    apply (case_tac xc)
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   215
    apply auto
44890
22f665a2e91c new fastforce replacing fastsimp - less confusing name
nipkow
parents: 44241
diff changeset
   216
    apply fastforce
35953
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   217
    done
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   218
qed
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   219
40548
54eb5fd36e5e ignoring the constant STR in the predicate compiler
bulwahn
parents: 40054
diff changeset
   220
section {* Setup for String.literal *}
54eb5fd36e5e ignoring the constant STR in the predicate compiler
bulwahn
parents: 40054
diff changeset
   221
54eb5fd36e5e ignoring the constant STR in the predicate compiler
bulwahn
parents: 40054
diff changeset
   222
setup {* Predicate_Compile_Data.ignore_consts [@{const_name "STR"}] *}
54eb5fd36e5e ignoring the constant STR in the predicate compiler
bulwahn
parents: 40054
diff changeset
   223
36246
43fecedff8cf added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
bulwahn
parents: 36053
diff changeset
   224
section {* Simplification rules for optimisation *}
43fecedff8cf added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
bulwahn
parents: 36053
diff changeset
   225
43fecedff8cf added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
bulwahn
parents: 36053
diff changeset
   226
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: 36053
diff changeset
   227
by auto
43fecedff8cf added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
bulwahn
parents: 36053
diff changeset
   228
43fecedff8cf added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
bulwahn
parents: 36053
diff changeset
   229
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: 36053
diff changeset
   230
by auto
43fecedff8cf added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
bulwahn
parents: 36053
diff changeset
   231
43fecedff8cf added peephole optimisations to the predicate compiler; added structure Predicate_Compile_Simps for peephole optimisations
bulwahn
parents: 36053
diff changeset
   232
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: 36053
diff changeset
   233
unfolding less_nat[symmetric] by auto
35953
0460ff79bb52 moved further predicate compile files to HOL-Library
bulwahn
parents:
diff changeset
   234
46884
154dc6ec0041 tuned proofs
noschinl
parents: 45970
diff changeset
   235
end