src/HOL/Library/Efficient_Nat.thy
author haftmann
Thu Aug 09 15:52:45 2007 +0200 (2007-08-09)
changeset 24195 7d1a16c77f7c
parent 23854 688a8a7bcd4e
child 24222 a8a28c15c5cc
permissions -rw-r--r--
tuned
haftmann@23854
     1
(*  Title:      HOL/Library/Efficient_Nat.thy
haftmann@23854
     2
    ID:         $Id$
haftmann@23854
     3
    Author:     Stefan Berghofer, TU Muenchen
haftmann@23854
     4
*)
haftmann@23854
     5
haftmann@23854
     6
header {* Implementation of natural numbers by integers *}
haftmann@23854
     7
haftmann@23854
     8
theory Efficient_Nat
haftmann@23854
     9
imports Main Pretty_Int
haftmann@23854
    10
begin
haftmann@23854
    11
haftmann@23854
    12
text {*
haftmann@23854
    13
When generating code for functions on natural numbers, the canonical
haftmann@23854
    14
representation using @{term "0::nat"} and @{term "Suc"} is unsuitable for
haftmann@23854
    15
computations involving large numbers. The efficiency of the generated
haftmann@23854
    16
code can be improved drastically by implementing natural numbers by
haftmann@23854
    17
integers. To do this, just include this theory.
haftmann@23854
    18
*}
haftmann@23854
    19
haftmann@23854
    20
subsection {* Logical rewrites *}
haftmann@23854
    21
haftmann@23854
    22
text {*
haftmann@23854
    23
  An int-to-nat conversion
haftmann@23854
    24
  restricted to non-negative ints (in contrast to @{const nat}).
haftmann@23854
    25
  Note that this restriction has no logical relevance and
haftmann@23854
    26
  is just a kind of proof hint -- nothing prevents you from 
haftmann@23854
    27
  writing nonsense like @{term "nat_of_int (-4)"}
haftmann@23854
    28
*}
haftmann@23854
    29
haftmann@23854
    30
definition
haftmann@23854
    31
  nat_of_int :: "int \<Rightarrow> nat" where
haftmann@23854
    32
  "k \<ge> 0 \<Longrightarrow> nat_of_int k = nat k"
haftmann@23854
    33
haftmann@23854
    34
definition
haftmann@23854
    35
  int' :: "nat \<Rightarrow> int" where
haftmann@23854
    36
  "int' n = of_nat n"
haftmann@23854
    37
haftmann@23854
    38
lemma int'_Suc [simp]: "int' (Suc n) = 1 + int' n"
haftmann@23854
    39
unfolding int'_def by simp
haftmann@23854
    40
haftmann@23854
    41
lemma int'_add: "int' (m + n) = int' m + int' n"
haftmann@23854
    42
unfolding int'_def by (rule of_nat_add)
haftmann@23854
    43
haftmann@23854
    44
lemma int'_mult: "int' (m * n) = int' m * int' n"
haftmann@23854
    45
unfolding int'_def by (rule of_nat_mult)
haftmann@23854
    46
haftmann@23854
    47
lemma nat_of_int_of_number_of:
haftmann@23854
    48
  fixes k
haftmann@23854
    49
  assumes "k \<ge> 0"
haftmann@23854
    50
  shows "number_of k = nat_of_int (number_of k)"
haftmann@23854
    51
  unfolding nat_of_int_def [OF assms] nat_number_of_def number_of_is_id ..
haftmann@23854
    52
haftmann@23854
    53
lemma nat_of_int_of_number_of_aux:
haftmann@23854
    54
  fixes k
haftmann@23854
    55
  assumes "Numeral.Pls \<le> k \<equiv> True"
haftmann@23854
    56
  shows "k \<ge> 0"
haftmann@23854
    57
  using assms unfolding Pls_def by simp
haftmann@23854
    58
haftmann@23854
    59
lemma nat_of_int_int:
haftmann@23854
    60
  "nat_of_int (int' n) = n"
haftmann@23854
    61
  using nat_of_int_def int'_def by simp
haftmann@23854
    62
haftmann@23854
    63
lemma eq_nat_of_int: "int' n = x \<Longrightarrow> n = nat_of_int x"
haftmann@23854
    64
by (erule subst, simp only: nat_of_int_int)
haftmann@23854
    65
haftmann@23854
    66
text {*
haftmann@23854
    67
  Case analysis on natural numbers is rephrased using a conditional
haftmann@23854
    68
  expression:
haftmann@23854
    69
*}
haftmann@23854
    70
haftmann@23854
    71
lemma [code unfold, code inline del]:
haftmann@23854
    72
  "nat_case \<equiv> (\<lambda>f g n. if n = 0 then f else g (n - 1))"
haftmann@23854
    73
proof -
haftmann@23854
    74
  have rewrite: "\<And>f g n. nat_case f g n = (if n = 0 then f else g (n - 1))"
haftmann@23854
    75
  proof -
haftmann@23854
    76
    fix f g n
haftmann@23854
    77
    show "nat_case f g n = (if n = 0 then f else g (n - 1))"
haftmann@23854
    78
      by (cases n) simp_all
haftmann@23854
    79
  qed
haftmann@23854
    80
  show "nat_case \<equiv> (\<lambda>f g n. if n = 0 then f else g (n - 1))"
haftmann@23854
    81
    by (rule eq_reflection ext rewrite)+ 
haftmann@23854
    82
qed
haftmann@23854
    83
haftmann@23854
    84
lemma [code inline]:
haftmann@23854
    85
  "nat_case = (\<lambda>f g n. if n = 0 then f else g (nat_of_int (int' n - 1)))"
haftmann@23854
    86
proof (rule ext)+
haftmann@23854
    87
  fix f g n
haftmann@23854
    88
  show "nat_case f g n = (if n = 0 then f else g (nat_of_int (int' n - 1)))"
haftmann@23854
    89
  by (cases n) (simp_all add: nat_of_int_int)
haftmann@23854
    90
qed
haftmann@23854
    91
haftmann@23854
    92
text {*
haftmann@23854
    93
  Most standard arithmetic functions on natural numbers are implemented
haftmann@23854
    94
  using their counterparts on the integers:
haftmann@23854
    95
*}
haftmann@23854
    96
haftmann@23854
    97
lemma [code func]: "0 = nat_of_int 0"
haftmann@23854
    98
  by (simp add: nat_of_int_def)
haftmann@23854
    99
lemma [code func, code inline]:  "1 = nat_of_int 1"
haftmann@23854
   100
  by (simp add: nat_of_int_def)
haftmann@23854
   101
lemma [code func]: "Suc n = nat_of_int (int' n + 1)"
haftmann@23854
   102
  by (simp add: eq_nat_of_int)
haftmann@23854
   103
lemma [code]: "m + n = nat (int' m + int' n)"
haftmann@23854
   104
  by (simp add: int'_def nat_eq_iff2)
haftmann@23854
   105
lemma [code func, code inline]: "m + n = nat_of_int (int' m + int' n)"
haftmann@23854
   106
  by (simp add: eq_nat_of_int int'_add)
haftmann@23854
   107
lemma [code, code inline]: "m - n = nat (int' m - int' n)"
haftmann@23854
   108
  by (simp add: int'_def nat_eq_iff2 of_nat_diff)
haftmann@23854
   109
lemma [code]: "m * n = nat (int' m * int' n)"
haftmann@23854
   110
  unfolding int'_def
haftmann@23854
   111
  by (simp add: of_nat_mult [symmetric] del: of_nat_mult)
haftmann@23854
   112
lemma [code func, code inline]: "m * n = nat_of_int (int' m * int' n)"
haftmann@23854
   113
  by (simp add: eq_nat_of_int int'_mult)
haftmann@23854
   114
lemma [code]: "m div n = nat (int' m div int' n)"
haftmann@23854
   115
  unfolding int'_def zdiv_int [symmetric] by simp
haftmann@23854
   116
lemma [code func]: "m div n = fst (Divides.divmod m n)"
haftmann@23854
   117
  unfolding divmod_def by simp
haftmann@23854
   118
lemma [code]: "m mod n = nat (int' m mod int' n)"
haftmann@23854
   119
  unfolding int'_def zmod_int [symmetric] by simp
haftmann@23854
   120
lemma [code func]: "m mod n = snd (Divides.divmod m n)"
haftmann@23854
   121
  unfolding divmod_def by simp
haftmann@23854
   122
lemma [code, code inline]: "(m < n) \<longleftrightarrow> (int' m < int' n)"
haftmann@23854
   123
  unfolding int'_def by simp
haftmann@23854
   124
lemma [code func, code inline]: "(m \<le> n) \<longleftrightarrow> (int' m \<le> int' n)"
haftmann@23854
   125
  unfolding int'_def by simp
haftmann@23854
   126
lemma [code func, code inline]: "m = n \<longleftrightarrow> int' m = int' n"
haftmann@23854
   127
  unfolding int'_def by simp
haftmann@23854
   128
lemma [code func]: "nat k = (if k < 0 then 0 else nat_of_int k)"
haftmann@23854
   129
proof (cases "k < 0")
haftmann@23854
   130
  case True then show ?thesis by simp
haftmann@23854
   131
next
haftmann@23854
   132
  case False then show ?thesis by (simp add: nat_of_int_def)
haftmann@23854
   133
qed
haftmann@23854
   134
lemma [code func]:
haftmann@23854
   135
  "int_aux n i = (if int' n = 0 then i else int_aux (nat_of_int (int' n - 1)) (i + 1))"
haftmann@23854
   136
proof -
haftmann@23854
   137
  have "0 < n \<Longrightarrow> int' n = 1 + int' (nat_of_int (int' n - 1))"
haftmann@23854
   138
  proof -
haftmann@23854
   139
    assume prem: "n > 0"
haftmann@23854
   140
    then have "int' n - 1 \<ge> 0" unfolding int'_def by auto
haftmann@23854
   141
    then have "nat_of_int (int' n - 1) = nat (int' n - 1)" by (simp add: nat_of_int_def)
haftmann@23854
   142
    with prem show "int' n = 1 + int' (nat_of_int (int' n - 1))" unfolding int'_def by simp
haftmann@23854
   143
  qed
haftmann@23854
   144
  then show ?thesis unfolding int_aux_def int'_def by auto
haftmann@23854
   145
qed
haftmann@23854
   146
haftmann@23854
   147
lemma div_nat_code [code func]:
haftmann@23854
   148
  "m div k = nat_of_int (fst (divAlg (int' m, int' k)))"
haftmann@23854
   149
  unfolding div_def [symmetric] int'_def zdiv_int [symmetric]
haftmann@23854
   150
  unfolding int'_def [symmetric] nat_of_int_int ..
haftmann@23854
   151
haftmann@23854
   152
lemma mod_nat_code [code func]:
haftmann@23854
   153
  "m mod k = nat_of_int (snd (divAlg (int' m, int' k)))"
haftmann@23854
   154
  unfolding mod_def [symmetric] int'_def zmod_int [symmetric]
haftmann@23854
   155
  unfolding int'_def [symmetric] nat_of_int_int ..
haftmann@23854
   156
haftmann@23854
   157
haftmann@23854
   158
subsection {* Code generator setup for basic functions *}
haftmann@23854
   159
haftmann@23854
   160
text {*
haftmann@23854
   161
  @{typ nat} is no longer a datatype but embedded into the integers.
haftmann@23854
   162
*}
haftmann@23854
   163
haftmann@23854
   164
code_datatype nat_of_int
haftmann@23854
   165
haftmann@23854
   166
code_type nat
haftmann@23854
   167
  (SML "IntInf.int")
haftmann@23854
   168
  (OCaml "Big'_int.big'_int")
haftmann@23854
   169
  (Haskell "Integer")
haftmann@23854
   170
haftmann@23854
   171
types_code
haftmann@23854
   172
  nat ("int")
haftmann@23854
   173
attach (term_of) {*
haftmann@23854
   174
val term_of_nat = HOLogic.mk_number HOLogic.natT o IntInf.fromInt;
haftmann@23854
   175
*}
haftmann@23854
   176
attach (test) {*
haftmann@23854
   177
fun gen_nat i = random_range 0 i;
haftmann@23854
   178
*}
haftmann@23854
   179
haftmann@23854
   180
consts_code
haftmann@23854
   181
  "0 \<Colon> nat" ("0")
haftmann@23854
   182
  Suc ("(_ + 1)")
haftmann@23854
   183
haftmann@23854
   184
text {*
haftmann@23854
   185
  Since natural numbers are implemented
haftmann@23854
   186
  using integers, the coercion function @{const "int"} of type
haftmann@23854
   187
  @{typ "nat \<Rightarrow> int"} is simply implemented by the identity function,
haftmann@23854
   188
  likewise @{const nat_of_int} of type @{typ "int \<Rightarrow> nat"}.
haftmann@23854
   189
  For the @{const "nat"} function for converting an integer to a natural
haftmann@23854
   190
  number, we give a specific implementation using an ML function that
haftmann@23854
   191
  returns its input value, provided that it is non-negative, and otherwise
haftmann@23854
   192
  returns @{text "0"}.
haftmann@23854
   193
*}
haftmann@23854
   194
haftmann@23854
   195
consts_code
haftmann@23854
   196
  int' ("(_)")
haftmann@23854
   197
  nat ("\<module>nat")
haftmann@23854
   198
attach {*
haftmann@23854
   199
fun nat i = if i < 0 then 0 else i;
haftmann@23854
   200
*}
haftmann@23854
   201
haftmann@23854
   202
code_const int'
haftmann@23854
   203
  (SML "_")
haftmann@23854
   204
  (OCaml "_")
haftmann@23854
   205
  (Haskell "_")
haftmann@23854
   206
haftmann@23854
   207
code_const nat_of_int
haftmann@23854
   208
  (SML "_")
haftmann@23854
   209
  (OCaml "_")
haftmann@23854
   210
  (Haskell "_")
haftmann@23854
   211
haftmann@23854
   212
haftmann@23854
   213
subsection {* Preprocessors *}
haftmann@23854
   214
haftmann@23854
   215
text {*
haftmann@23854
   216
  Natural numerals should be expressed using @{const nat_of_int}.
haftmann@23854
   217
*}
haftmann@23854
   218
haftmann@23854
   219
lemmas [code inline del] = nat_number_of_def
haftmann@23854
   220
haftmann@23854
   221
ML {*
haftmann@23854
   222
fun nat_of_int_of_number_of thy cts =
haftmann@23854
   223
  let
haftmann@23854
   224
    val simplify_less = Simplifier.rewrite 
haftmann@23854
   225
      (HOL_basic_ss addsimps (@{thms less_numeral_code} @ @{thms less_eq_numeral_code}));
haftmann@23854
   226
    fun mk_rew (t, ty) =
haftmann@23854
   227
      if ty = HOLogic.natT andalso IntInf.<= (0, HOLogic.dest_numeral t) then
haftmann@23854
   228
        Thm.capply @{cterm "(op \<le>) Numeral.Pls"} (Thm.cterm_of thy t)
haftmann@23854
   229
        |> simplify_less
haftmann@23854
   230
        |> (fn thm => @{thm nat_of_int_of_number_of_aux} OF [thm])
haftmann@23854
   231
        |> (fn thm => @{thm nat_of_int_of_number_of} OF [thm])
haftmann@23854
   232
        |> (fn thm => @{thm eq_reflection} OF [thm])
haftmann@23854
   233
        |> SOME
haftmann@23854
   234
      else NONE
haftmann@23854
   235
  in
haftmann@23854
   236
    fold (HOLogic.add_numerals o Thm.term_of) cts []
haftmann@23854
   237
    |> map_filter mk_rew
haftmann@23854
   238
  end;
haftmann@23854
   239
*}
haftmann@23854
   240
haftmann@23854
   241
setup {*
haftmann@23854
   242
  CodegenData.add_inline_proc ("nat_of_int_of_number_of", nat_of_int_of_number_of)
haftmann@23854
   243
*}
haftmann@23854
   244
haftmann@23854
   245
text {*
haftmann@23854
   246
  In contrast to @{term "Suc n"}, the term @{term "n + (1::nat)"} is no longer
haftmann@23854
   247
  a constructor term. Therefore, all occurrences of this term in a position
haftmann@23854
   248
  where a pattern is expected (i.e.\ on the left-hand side of a recursion
haftmann@23854
   249
  equation or in the arguments of an inductive relation in an introduction
haftmann@23854
   250
  rule) must be eliminated.
haftmann@23854
   251
  This can be accomplished by applying the following transformation rules:
haftmann@23854
   252
*}
haftmann@23854
   253
haftmann@23854
   254
theorem Suc_if_eq: "(\<And>n. f (Suc n) = h n) \<Longrightarrow> f 0 = g \<Longrightarrow>
haftmann@23854
   255
  f n = (if n = 0 then g else h (n - 1))"
haftmann@23854
   256
  by (case_tac n) simp_all
haftmann@23854
   257
haftmann@23854
   258
theorem Suc_clause: "(\<And>n. P n (Suc n)) \<Longrightarrow> n \<noteq> 0 \<Longrightarrow> P (n - 1) n"
haftmann@23854
   259
  by (case_tac n) simp_all
haftmann@23854
   260
haftmann@23854
   261
text {*
haftmann@23854
   262
  The rules above are built into a preprocessor that is plugged into
haftmann@23854
   263
  the code generator. Since the preprocessor for introduction rules
haftmann@23854
   264
  does not know anything about modes, some of the modes that worked
haftmann@23854
   265
  for the canonical representation of natural numbers may no longer work.
haftmann@23854
   266
*}
haftmann@23854
   267
haftmann@23854
   268
(*<*)
haftmann@23854
   269
haftmann@23854
   270
ML {*
haftmann@23854
   271
local
haftmann@23854
   272
  val Suc_if_eq = thm "Suc_if_eq";
haftmann@23854
   273
  val Suc_clause = thm "Suc_clause";
haftmann@23854
   274
  fun contains_suc t = member (op =) (term_consts t) "Suc";
haftmann@23854
   275
in
haftmann@23854
   276
haftmann@23854
   277
fun remove_suc thy thms =
haftmann@23854
   278
  let
haftmann@23854
   279
    val Suc_if_eq' = Thm.transfer thy Suc_if_eq;
haftmann@23854
   280
    val vname = Name.variant (map fst
haftmann@23854
   281
      (fold (Term.add_varnames o Thm.full_prop_of) thms [])) "x";
haftmann@23854
   282
    val cv = cterm_of thy (Var ((vname, 0), HOLogic.natT));
haftmann@23854
   283
    fun lhs_of th = snd (Thm.dest_comb
haftmann@23854
   284
      (fst (Thm.dest_comb (snd (Thm.dest_comb (cprop_of th))))));
haftmann@23854
   285
    fun rhs_of th = snd (Thm.dest_comb (snd (Thm.dest_comb (cprop_of th))));
haftmann@23854
   286
    fun find_vars ct = (case term_of ct of
haftmann@23854
   287
        (Const ("Suc", _) $ Var _) => [(cv, snd (Thm.dest_comb ct))]
haftmann@23854
   288
      | _ $ _ =>
haftmann@23854
   289
        let val (ct1, ct2) = Thm.dest_comb ct
haftmann@23854
   290
        in 
haftmann@23854
   291
          map (apfst (fn ct => Thm.capply ct ct2)) (find_vars ct1) @
haftmann@23854
   292
          map (apfst (Thm.capply ct1)) (find_vars ct2)
haftmann@23854
   293
        end
haftmann@23854
   294
      | _ => []);
haftmann@23854
   295
    val eqs = maps
haftmann@23854
   296
      (fn th => map (pair th) (find_vars (lhs_of th))) thms;
haftmann@23854
   297
    fun mk_thms (th, (ct, cv')) =
haftmann@23854
   298
      let
haftmann@23854
   299
        val th' =
haftmann@23854
   300
          Thm.implies_elim
haftmann@23854
   301
           (Conv.fconv_rule (Thm.beta_conversion true)
haftmann@23854
   302
             (Drule.instantiate'
haftmann@23854
   303
               [SOME (ctyp_of_term ct)] [SOME (Thm.cabs cv ct),
haftmann@23854
   304
                 SOME (Thm.cabs cv' (rhs_of th)), NONE, SOME cv']
haftmann@23854
   305
               Suc_if_eq')) (Thm.forall_intr cv' th)
haftmann@23854
   306
      in
haftmann@23854
   307
        case map_filter (fn th'' =>
haftmann@23854
   308
            SOME (th'', singleton
haftmann@23854
   309
              (Variable.trade (K (fn [th'''] => [th''' RS th'])) (Variable.thm_context th'')) th'')
haftmann@23854
   310
          handle THM _ => NONE) thms of
haftmann@23854
   311
            [] => NONE
haftmann@23854
   312
          | thps =>
haftmann@23854
   313
              let val (ths1, ths2) = split_list thps
haftmann@23854
   314
              in SOME (subtract Thm.eq_thm (th :: ths1) thms @ ths2) end
haftmann@23854
   315
      end
haftmann@23854
   316
  in
haftmann@23854
   317
    case get_first mk_thms eqs of
haftmann@23854
   318
      NONE => thms
haftmann@23854
   319
    | SOME x => remove_suc thy x
haftmann@23854
   320
  end;
haftmann@23854
   321
haftmann@23854
   322
fun eqn_suc_preproc thy ths =
haftmann@23854
   323
  let
haftmann@23854
   324
    val dest = fst o HOLogic.dest_eq o HOLogic.dest_Trueprop o prop_of
haftmann@23854
   325
  in
haftmann@23854
   326
    if forall (can dest) ths andalso
haftmann@23854
   327
      exists (contains_suc o dest) ths
haftmann@23854
   328
    then remove_suc thy ths else ths
haftmann@23854
   329
  end;
haftmann@23854
   330
haftmann@23854
   331
fun remove_suc_clause thy thms =
haftmann@23854
   332
  let
haftmann@23854
   333
    val Suc_clause' = Thm.transfer thy Suc_clause;
haftmann@23854
   334
    val vname = Name.variant (map fst
haftmann@23854
   335
      (fold (Term.add_varnames o Thm.full_prop_of) thms [])) "x";
haftmann@23854
   336
    fun find_var (t as Const ("Suc", _) $ (v as Var _)) = SOME (t, v)
haftmann@23854
   337
      | find_var (t $ u) = (case find_var t of NONE => find_var u | x => x)
haftmann@23854
   338
      | find_var _ = NONE;
haftmann@23854
   339
    fun find_thm th =
haftmann@23854
   340
      let val th' = Conv.fconv_rule ObjectLogic.atomize th
haftmann@23854
   341
      in Option.map (pair (th, th')) (find_var (prop_of th')) end
haftmann@23854
   342
  in
haftmann@23854
   343
    case get_first find_thm thms of
haftmann@23854
   344
      NONE => thms
haftmann@23854
   345
    | SOME ((th, th'), (Sucv, v)) =>
haftmann@23854
   346
        let
haftmann@23854
   347
          val cert = cterm_of (Thm.theory_of_thm th);
haftmann@23854
   348
          val th'' = ObjectLogic.rulify (Thm.implies_elim
haftmann@23854
   349
            (Conv.fconv_rule (Thm.beta_conversion true)
haftmann@23854
   350
              (Drule.instantiate' []
haftmann@23854
   351
                [SOME (cert (lambda v (Abs ("x", HOLogic.natT,
haftmann@23854
   352
                   abstract_over (Sucv,
haftmann@23854
   353
                     HOLogic.dest_Trueprop (prop_of th')))))),
haftmann@23854
   354
                 SOME (cert v)] Suc_clause'))
haftmann@23854
   355
            (Thm.forall_intr (cert v) th'))
haftmann@23854
   356
        in
haftmann@23854
   357
          remove_suc_clause thy (map (fn th''' =>
haftmann@23854
   358
            if (op = o pairself prop_of) (th''', th) then th'' else th''') thms)
haftmann@23854
   359
        end
haftmann@23854
   360
  end;
haftmann@23854
   361
haftmann@23854
   362
fun clause_suc_preproc thy ths =
haftmann@23854
   363
  let
haftmann@23854
   364
    val dest = fst o HOLogic.dest_mem o HOLogic.dest_Trueprop
haftmann@23854
   365
  in
haftmann@23854
   366
    if forall (can (dest o concl_of)) ths andalso
haftmann@23854
   367
      exists (fn th => member (op =) (foldr add_term_consts
haftmann@23854
   368
        [] (map_filter (try dest) (concl_of th :: prems_of th))) "Suc") ths
haftmann@23854
   369
    then remove_suc_clause thy ths else ths
haftmann@23854
   370
  end;
haftmann@23854
   371
haftmann@23854
   372
end; (*local*)
haftmann@23854
   373
haftmann@23854
   374
fun lift_obj_eq f thy =
haftmann@23854
   375
  map (fn thm => thm RS @{thm meta_eq_to_obj_eq})
haftmann@23854
   376
  #> f thy
haftmann@23854
   377
  #> map (fn thm => thm RS @{thm eq_reflection})
haftmann@23854
   378
  #> map (Conv.fconv_rule Drule.beta_eta_conversion)
haftmann@23854
   379
*}
haftmann@23854
   380
haftmann@23854
   381
setup {*
haftmann@23854
   382
  Codegen.add_preprocessor eqn_suc_preproc
haftmann@23854
   383
  #> Codegen.add_preprocessor clause_suc_preproc
haftmann@23854
   384
  #> CodegenData.add_preproc ("eqn_Suc", lift_obj_eq eqn_suc_preproc)
haftmann@23854
   385
  #> CodegenData.add_preproc ("clause_Suc", lift_obj_eq clause_suc_preproc)
haftmann@23854
   386
*}
haftmann@23854
   387
(*>*)
haftmann@23854
   388
haftmann@23854
   389
haftmann@23854
   390
subsection {* Module names *}
haftmann@23854
   391
haftmann@23854
   392
code_modulename SML
haftmann@23854
   393
  Nat Integer
haftmann@23854
   394
  Divides Integer
haftmann@23854
   395
  Efficient_Nat Integer
haftmann@23854
   396
haftmann@23854
   397
code_modulename OCaml
haftmann@23854
   398
  Nat Integer
haftmann@23854
   399
  Divides Integer
haftmann@23854
   400
  Efficient_Nat Integer
haftmann@23854
   401
haftmann@23854
   402
code_modulename Haskell
haftmann@23854
   403
  Nat Integer
haftmann@24195
   404
  Divides Integer
haftmann@23854
   405
  Efficient_Nat Integer
haftmann@23854
   406
haftmann@23854
   407
hide const nat_of_int int'
haftmann@23854
   408
haftmann@23854
   409
end