src/HOL/Library/Efficient_Nat.thy
author kuncar
Fri Dec 09 18:07:04 2011 +0100 (2011-12-09)
changeset 45802 b16f976db515
parent 45793 331ebffe0593
child 46028 9f113cdf3d66
permissions -rw-r--r--
Quotient_Info stores only relation maps
haftmann@23854
     1
(*  Title:      HOL/Library/Efficient_Nat.thy
haftmann@25931
     2
    Author:     Stefan Berghofer, Florian Haftmann, TU Muenchen
haftmann@23854
     3
*)
haftmann@23854
     4
haftmann@25931
     5
header {* Implementation of natural numbers by target-language integers *}
haftmann@23854
     6
haftmann@23854
     7
theory Efficient_Nat
haftmann@31203
     8
imports Code_Integer Main
haftmann@23854
     9
begin
haftmann@23854
    10
haftmann@23854
    11
text {*
haftmann@25931
    12
  When generating code for functions on natural numbers, the
haftmann@25931
    13
  canonical representation using @{term "0::nat"} and
haftmann@37388
    14
  @{term Suc} is unsuitable for computations involving large
haftmann@25931
    15
  numbers.  The efficiency of the generated code can be improved
haftmann@25931
    16
  drastically by implementing natural numbers by target-language
haftmann@25931
    17
  integers.  To do this, just include this theory.
haftmann@23854
    18
*}
haftmann@23854
    19
haftmann@25931
    20
subsection {* Basic arithmetic *}
haftmann@23854
    21
haftmann@23854
    22
text {*
haftmann@23854
    23
  Most standard arithmetic functions on natural numbers are implemented
haftmann@23854
    24
  using their counterparts on the integers:
haftmann@23854
    25
*}
haftmann@23854
    26
haftmann@25931
    27
code_datatype number_nat_inst.number_of_nat
haftmann@24715
    28
haftmann@32069
    29
lemma zero_nat_code [code, code_unfold_post]:
haftmann@25931
    30
  "0 = (Numeral0 :: nat)"
haftmann@25931
    31
  by simp
haftmann@24715
    32
haftmann@32069
    33
lemma one_nat_code [code, code_unfold_post]:
haftmann@25931
    34
  "1 = (Numeral1 :: nat)"
haftmann@25931
    35
  by simp
haftmann@24715
    36
haftmann@25931
    37
lemma Suc_code [code]:
haftmann@25931
    38
  "Suc n = n + 1"
haftmann@25931
    39
  by simp
haftmann@24715
    40
haftmann@25931
    41
lemma plus_nat_code [code]:
haftmann@25931
    42
  "n + m = nat (of_nat n + of_nat m)"
haftmann@25931
    43
  by simp
haftmann@24715
    44
haftmann@25931
    45
lemma minus_nat_code [code]:
haftmann@25931
    46
  "n - m = nat (of_nat n - of_nat m)"
haftmann@25931
    47
  by simp
haftmann@24715
    48
haftmann@25931
    49
lemma times_nat_code [code]:
haftmann@25931
    50
  "n * m = nat (of_nat n * of_nat m)"
haftmann@25931
    51
  unfolding of_nat_mult [symmetric] by simp
haftmann@24715
    52
haftmann@37958
    53
lemma divmod_nat_code [code]:
haftmann@40607
    54
  "divmod_nat n m = map_pair nat nat (pdivmod (of_nat n) (of_nat m))"
haftmann@40607
    55
  by (simp add: map_pair_def split_def pdivmod_def nat_div_distrib nat_mod_distrib divmod_nat_div_mod)
haftmann@24715
    56
haftmann@25931
    57
lemma eq_nat_code [code]:
haftmann@38857
    58
  "HOL.equal n m \<longleftrightarrow> HOL.equal (of_nat n \<Colon> int) (of_nat m)"
haftmann@38857
    59
  by (simp add: equal)
haftmann@28351
    60
haftmann@28351
    61
lemma eq_nat_refl [code nbe]:
haftmann@38857
    62
  "HOL.equal (n::nat) n \<longleftrightarrow> True"
haftmann@38857
    63
  by (rule equal_refl)
haftmann@24715
    64
haftmann@25931
    65
lemma less_eq_nat_code [code]:
haftmann@25931
    66
  "n \<le> m \<longleftrightarrow> (of_nat n \<Colon> int) \<le> of_nat m"
haftmann@25931
    67
  by simp
haftmann@23854
    68
haftmann@25931
    69
lemma less_nat_code [code]:
haftmann@25931
    70
  "n < m \<longleftrightarrow> (of_nat n \<Colon> int) < of_nat m"
haftmann@25931
    71
  by simp
haftmann@23854
    72
haftmann@25931
    73
subsection {* Case analysis *}
haftmann@23854
    74
haftmann@23854
    75
text {*
haftmann@25931
    76
  Case analysis on natural numbers is rephrased using a conditional
haftmann@25931
    77
  expression:
haftmann@23854
    78
*}
haftmann@23854
    79
haftmann@31998
    80
lemma [code, code_unfold]:
haftmann@25931
    81
  "nat_case = (\<lambda>f g n. if n = 0 then f else g (n - 1))"
nipkow@39302
    82
  by (auto simp add: fun_eq_iff dest!: gr0_implies_Suc)
haftmann@25615
    83
haftmann@23854
    84
haftmann@23854
    85
subsection {* Preprocessors *}
haftmann@23854
    86
haftmann@23854
    87
text {*
haftmann@23854
    88
  In contrast to @{term "Suc n"}, the term @{term "n + (1::nat)"} is no longer
haftmann@23854
    89
  a constructor term. Therefore, all occurrences of this term in a position
haftmann@23854
    90
  where a pattern is expected (i.e.\ on the left-hand side of a recursion
haftmann@23854
    91
  equation or in the arguments of an inductive relation in an introduction
haftmann@23854
    92
  rule) must be eliminated.
haftmann@23854
    93
  This can be accomplished by applying the following transformation rules:
haftmann@23854
    94
*}
haftmann@23854
    95
haftmann@29937
    96
lemma Suc_if_eq: "(\<And>n. f (Suc n) \<equiv> h n) \<Longrightarrow> f 0 \<equiv> g \<Longrightarrow>
haftmann@29937
    97
  f n \<equiv> if n = 0 then g else h (n - 1)"
haftmann@31954
    98
  by (rule eq_reflection) (cases n, simp_all)
haftmann@29937
    99
haftmann@25931
   100
lemma Suc_clause: "(\<And>n. P n (Suc n)) \<Longrightarrow> n \<noteq> 0 \<Longrightarrow> P (n - 1) n"
haftmann@29932
   101
  by (cases n) simp_all
haftmann@23854
   102
haftmann@23854
   103
text {*
haftmann@23854
   104
  The rules above are built into a preprocessor that is plugged into
haftmann@23854
   105
  the code generator. Since the preprocessor for introduction rules
haftmann@23854
   106
  does not know anything about modes, some of the modes that worked
haftmann@23854
   107
  for the canonical representation of natural numbers may no longer work.
haftmann@23854
   108
*}
haftmann@23854
   109
haftmann@23854
   110
(*<*)
haftmann@27609
   111
setup {*
haftmann@27609
   112
let
haftmann@23854
   113
haftmann@31954
   114
fun remove_suc thy thms =
haftmann@23854
   115
  let
wenzelm@43324
   116
    val vname = singleton (Name.variant_list (map fst
wenzelm@43324
   117
      (fold (Term.add_var_names o Thm.full_prop_of) thms []))) "n";
haftmann@23854
   118
    val cv = cterm_of thy (Var ((vname, 0), HOLogic.natT));
haftmann@23854
   119
    fun lhs_of th = snd (Thm.dest_comb
haftmann@31954
   120
      (fst (Thm.dest_comb (cprop_of th))));
haftmann@31954
   121
    fun rhs_of th = snd (Thm.dest_comb (cprop_of th));
haftmann@23854
   122
    fun find_vars ct = (case term_of ct of
haftmann@29932
   123
        (Const (@{const_name Suc}, _) $ Var _) => [(cv, snd (Thm.dest_comb ct))]
haftmann@23854
   124
      | _ $ _ =>
haftmann@23854
   125
        let val (ct1, ct2) = Thm.dest_comb ct
haftmann@23854
   126
        in 
haftmann@23854
   127
          map (apfst (fn ct => Thm.capply ct ct2)) (find_vars ct1) @
haftmann@23854
   128
          map (apfst (Thm.capply ct1)) (find_vars ct2)
haftmann@23854
   129
        end
haftmann@23854
   130
      | _ => []);
haftmann@23854
   131
    val eqs = maps
haftmann@23854
   132
      (fn th => map (pair th) (find_vars (lhs_of th))) thms;
haftmann@23854
   133
    fun mk_thms (th, (ct, cv')) =
haftmann@23854
   134
      let
haftmann@23854
   135
        val th' =
haftmann@23854
   136
          Thm.implies_elim
haftmann@23854
   137
           (Conv.fconv_rule (Thm.beta_conversion true)
haftmann@23854
   138
             (Drule.instantiate'
haftmann@23854
   139
               [SOME (ctyp_of_term ct)] [SOME (Thm.cabs cv ct),
haftmann@23854
   140
                 SOME (Thm.cabs cv' (rhs_of th)), NONE, SOME cv']
haftmann@31954
   141
               @{thm Suc_if_eq})) (Thm.forall_intr cv' th)
haftmann@23854
   142
      in
haftmann@23854
   143
        case map_filter (fn th'' =>
haftmann@23854
   144
            SOME (th'', singleton
wenzelm@36603
   145
              (Variable.trade (K (fn [th'''] => [th''' RS th']))
wenzelm@36603
   146
                (Variable.global_thm_context th'')) th'')
haftmann@23854
   147
          handle THM _ => NONE) thms of
haftmann@23854
   148
            [] => NONE
haftmann@23854
   149
          | thps =>
haftmann@23854
   150
              let val (ths1, ths2) = split_list thps
haftmann@23854
   151
              in SOME (subtract Thm.eq_thm (th :: ths1) thms @ ths2) end
haftmann@23854
   152
      end
haftmann@29937
   153
  in get_first mk_thms eqs end;
haftmann@29937
   154
haftmann@34893
   155
fun eqn_suc_base_preproc thy thms =
haftmann@29937
   156
  let
haftmann@31954
   157
    val dest = fst o Logic.dest_equals o prop_of;
haftmann@29937
   158
    val contains_suc = exists_Const (fn (c, _) => c = @{const_name Suc});
haftmann@29937
   159
  in
haftmann@29937
   160
    if forall (can dest) thms andalso exists (contains_suc o dest) thms
haftmann@32348
   161
      then thms |> perhaps_loop (remove_suc thy) |> (Option.map o map) Drule.zero_var_indexes
haftmann@29937
   162
       else NONE
haftmann@23854
   163
  end;
haftmann@23854
   164
haftmann@34893
   165
val eqn_suc_preproc = Code_Preproc.simple_functrans eqn_suc_base_preproc;
haftmann@23854
   166
haftmann@27609
   167
in
haftmann@27609
   168
haftmann@34893
   169
  Code_Preproc.add_functrans ("eqn_Suc", eqn_suc_preproc)
haftmann@27609
   170
haftmann@27609
   171
end;
haftmann@23854
   172
*}
haftmann@23854
   173
(*>*)
haftmann@23854
   174
haftmann@27609
   175
haftmann@25931
   176
subsection {* Target language setup *}
haftmann@25931
   177
haftmann@25931
   178
text {*
haftmann@25967
   179
  For ML, we map @{typ nat} to target language integers, where we
haftmann@34899
   180
  ensure that values are always non-negative.
haftmann@25931
   181
*}
haftmann@25931
   182
haftmann@25931
   183
code_type nat
haftmann@27496
   184
  (SML "IntInf.int")
haftmann@25931
   185
  (OCaml "Big'_int.big'_int")
haftmann@37958
   186
  (Eval "int")
haftmann@25931
   187
haftmann@25931
   188
text {*
bulwahn@45185
   189
  For Haskell and Scala we define our own @{typ nat} type.  The reason
haftmann@34899
   190
  is that we have to distinguish type class instances for @{typ nat}
haftmann@34899
   191
  and @{typ int}.
haftmann@25967
   192
*}
haftmann@25967
   193
haftmann@38774
   194
code_include Haskell "Nat"
haftmann@38774
   195
{*newtype Nat = Nat Integer deriving (Eq, Show, Read);
haftmann@25967
   196
haftmann@25967
   197
instance Num Nat where {
haftmann@25967
   198
  fromInteger k = Nat (if k >= 0 then k else 0);
haftmann@25967
   199
  Nat n + Nat m = Nat (n + m);
haftmann@25967
   200
  Nat n - Nat m = fromInteger (n - m);
haftmann@25967
   201
  Nat n * Nat m = Nat (n * m);
haftmann@25967
   202
  abs n = n;
haftmann@25967
   203
  signum _ = 1;
haftmann@25967
   204
  negate n = error "negate Nat";
haftmann@25967
   205
};
haftmann@25967
   206
haftmann@25967
   207
instance Ord Nat where {
haftmann@25967
   208
  Nat n <= Nat m = n <= m;
haftmann@25967
   209
  Nat n < Nat m = n < m;
haftmann@25967
   210
};
haftmann@25967
   211
haftmann@25967
   212
instance Real Nat where {
haftmann@25967
   213
  toRational (Nat n) = toRational n;
haftmann@25967
   214
};
haftmann@25967
   215
haftmann@25967
   216
instance Enum Nat where {
haftmann@25967
   217
  toEnum k = fromInteger (toEnum k);
haftmann@25967
   218
  fromEnum (Nat n) = fromEnum n;
haftmann@25967
   219
};
haftmann@25967
   220
haftmann@25967
   221
instance Integral Nat where {
haftmann@25967
   222
  toInteger (Nat n) = n;
haftmann@25967
   223
  divMod n m = quotRem n m;
haftmann@37958
   224
  quotRem (Nat n) (Nat m)
haftmann@37958
   225
    | (m == 0) = (0, Nat n)
haftmann@37958
   226
    | otherwise = (Nat k, Nat l) where (k, l) = quotRem n m;
haftmann@25967
   227
};
haftmann@25967
   228
*}
haftmann@25967
   229
haftmann@25967
   230
code_reserved Haskell Nat
haftmann@25967
   231
haftmann@38774
   232
code_include Scala "Nat"
haftmann@38968
   233
{*object Nat {
haftmann@34899
   234
haftmann@34899
   235
  def apply(numeral: BigInt): Nat = new Nat(numeral max 0)
haftmann@34899
   236
  def apply(numeral: Int): Nat = Nat(BigInt(numeral))
haftmann@34899
   237
  def apply(numeral: String): Nat = Nat(BigInt(numeral))
haftmann@34899
   238
haftmann@34899
   239
}
haftmann@34899
   240
haftmann@34899
   241
class Nat private(private val value: BigInt) {
haftmann@34899
   242
haftmann@34899
   243
  override def hashCode(): Int = this.value.hashCode()
haftmann@34899
   244
haftmann@34899
   245
  override def equals(that: Any): Boolean = that match {
haftmann@34899
   246
    case that: Nat => this equals that
haftmann@34899
   247
    case _ => false
haftmann@34899
   248
  }
haftmann@34899
   249
haftmann@34899
   250
  override def toString(): String = this.value.toString
haftmann@34899
   251
haftmann@34899
   252
  def equals(that: Nat): Boolean = this.value == that.value
haftmann@34899
   253
haftmann@34899
   254
  def as_BigInt: BigInt = this.value
haftmann@39781
   255
  def as_Int: Int = if (this.value >= scala.Int.MinValue && this.value <= scala.Int.MaxValue)
haftmann@34944
   256
      this.value.intValue
haftmann@37969
   257
    else error("Int value out of range: " + this.value.toString)
haftmann@34899
   258
haftmann@34899
   259
  def +(that: Nat): Nat = new Nat(this.value + that.value)
haftmann@37223
   260
  def -(that: Nat): Nat = Nat(this.value - that.value)
haftmann@34899
   261
  def *(that: Nat): Nat = new Nat(this.value * that.value)
haftmann@34899
   262
haftmann@34899
   263
  def /%(that: Nat): (Nat, Nat) = if (that.value == 0) (new Nat(0), this)
haftmann@34899
   264
    else {
haftmann@34899
   265
      val (k, l) = this.value /% that.value
haftmann@34899
   266
      (new Nat(k), new Nat(l))
haftmann@34899
   267
    }
haftmann@34899
   268
haftmann@34899
   269
  def <=(that: Nat): Boolean = this.value <= that.value
haftmann@34899
   270
haftmann@34899
   271
  def <(that: Nat): Boolean = this.value < that.value
haftmann@34899
   272
haftmann@34899
   273
}
haftmann@34899
   274
*}
haftmann@34899
   275
haftmann@34899
   276
code_reserved Scala Nat
haftmann@34899
   277
haftmann@25967
   278
code_type nat
haftmann@29793
   279
  (Haskell "Nat.Nat")
haftmann@38968
   280
  (Scala "Nat")
haftmann@25967
   281
haftmann@38857
   282
code_instance nat :: equal
haftmann@25967
   283
  (Haskell -)
haftmann@25967
   284
haftmann@25967
   285
text {*
haftmann@25931
   286
  Natural numerals.
haftmann@25931
   287
*}
haftmann@25931
   288
haftmann@32069
   289
lemma [code_unfold_post]:
haftmann@25931
   290
  "nat (number_of i) = number_nat_inst.number_of_nat i"
haftmann@25931
   291
  -- {* this interacts as desired with @{thm nat_number_of_def} *}
haftmann@25931
   292
  by (simp add: number_nat_inst.number_of_nat)
haftmann@25931
   293
haftmann@25931
   294
setup {*
haftmann@25931
   295
  fold (Numeral.add_code @{const_name number_nat_inst.number_of_nat}
haftmann@37958
   296
    false Code_Printer.literal_positive_numeral) ["SML", "OCaml", "Haskell", "Scala"]
haftmann@25931
   297
*}
haftmann@25931
   298
haftmann@25931
   299
text {*
haftmann@25931
   300
  Since natural numbers are implemented
haftmann@25967
   301
  using integers in ML, the coercion function @{const "of_nat"} of type
haftmann@25931
   302
  @{typ "nat \<Rightarrow> int"} is simply implemented by the identity function.
haftmann@37388
   303
  For the @{const nat} function for converting an integer to a natural
haftmann@25931
   304
  number, we give a specific implementation using an ML function that
haftmann@25931
   305
  returns its input value, provided that it is non-negative, and otherwise
haftmann@25931
   306
  returns @{text "0"}.
haftmann@25931
   307
*}
haftmann@25931
   308
haftmann@32073
   309
definition int :: "nat \<Rightarrow> int" where
haftmann@28562
   310
  [code del]: "int = of_nat"
haftmann@25931
   311
haftmann@28562
   312
lemma int_code' [code]:
haftmann@25931
   313
  "int (number_of l) = (if neg (number_of l \<Colon> int) then 0 else number_of l)"
haftmann@25931
   314
  unfolding int_nat_number_of [folded int_def] ..
haftmann@25931
   315
haftmann@28562
   316
lemma nat_code' [code]:
haftmann@25931
   317
  "nat (number_of l) = (if neg (number_of l \<Colon> int) then 0 else number_of l)"
huffman@28969
   318
  unfolding nat_number_of_def number_of_is_id neg_def by simp
haftmann@25931
   319
haftmann@32069
   320
lemma of_nat_int [code_unfold_post]:
haftmann@25931
   321
  "of_nat = int" by (simp add: int_def)
haftmann@25931
   322
haftmann@32073
   323
lemma of_nat_aux_int [code_unfold]:
haftmann@32073
   324
  "of_nat_aux (\<lambda>i. i + 1) k 0 = int k"
haftmann@32073
   325
  by (simp add: int_def Nat.of_nat_code)
haftmann@32073
   326
haftmann@25931
   327
code_const int
haftmann@25931
   328
  (SML "_")
haftmann@25931
   329
  (OCaml "_")
haftmann@25931
   330
haftmann@25967
   331
code_const nat
haftmann@43653
   332
  (SML "IntInf.max/ (0,/ _)")
haftmann@25967
   333
  (OCaml "Big'_int.max'_big'_int/ Big'_int.zero'_big'_int")
haftmann@37958
   334
  (Eval "Integer.max/ _/ 0")
haftmann@25967
   335
haftmann@35689
   336
text {* For Haskell and Scala, things are slightly different again. *}
haftmann@25967
   337
haftmann@25967
   338
code_const int and nat
haftmann@25967
   339
  (Haskell "toInteger" and "fromInteger")
haftmann@38968
   340
  (Scala "!_.as'_BigInt" and "Nat")
haftmann@25931
   341
haftmann@37958
   342
text {* Conversion from and to code numerals. *}
haftmann@25931
   343
haftmann@31205
   344
code_const Code_Numeral.of_nat
haftmann@25967
   345
  (SML "IntInf.toInt")
haftmann@31377
   346
  (OCaml "_")
haftmann@37958
   347
  (Haskell "!(fromInteger/ ./ toInteger)")
haftmann@38968
   348
  (Scala "!Natural(_.as'_BigInt)")
haftmann@37958
   349
  (Eval "_")
haftmann@25967
   350
haftmann@31205
   351
code_const Code_Numeral.nat_of
haftmann@25931
   352
  (SML "IntInf.fromInt")
haftmann@31377
   353
  (OCaml "_")
haftmann@37958
   354
  (Haskell "!(fromInteger/ ./ toInteger)")
haftmann@38968
   355
  (Scala "!Nat(_.as'_BigInt)")
haftmann@37958
   356
  (Eval "_")
haftmann@25931
   357
haftmann@25931
   358
text {* Using target language arithmetic operations whenever appropriate *}
haftmann@25931
   359
haftmann@25931
   360
code_const "op + \<Colon> nat \<Rightarrow> nat \<Rightarrow> nat"
haftmann@25931
   361
  (SML "IntInf.+ ((_), (_))")
haftmann@25931
   362
  (OCaml "Big'_int.add'_big'_int")
haftmann@25931
   363
  (Haskell infixl 6 "+")
haftmann@34899
   364
  (Scala infixl 7 "+")
haftmann@37958
   365
  (Eval infixl 8 "+")
haftmann@34899
   366
haftmann@34899
   367
code_const "op - \<Colon> nat \<Rightarrow> nat \<Rightarrow> nat"
haftmann@34899
   368
  (Haskell infixl 6 "-")
haftmann@34899
   369
  (Scala infixl 7 "-")
haftmann@25931
   370
haftmann@25931
   371
code_const "op * \<Colon> nat \<Rightarrow> nat \<Rightarrow> nat"
haftmann@25931
   372
  (SML "IntInf.* ((_), (_))")
haftmann@25931
   373
  (OCaml "Big'_int.mult'_big'_int")
haftmann@25931
   374
  (Haskell infixl 7 "*")
haftmann@34899
   375
  (Scala infixl 8 "*")
haftmann@37958
   376
  (Eval infixl 9 "*")
haftmann@25931
   377
haftmann@37958
   378
code_const divmod_nat
haftmann@26009
   379
  (SML "IntInf.divMod/ ((_),/ (_))")
haftmann@26009
   380
  (OCaml "Big'_int.quomod'_big'_int")
haftmann@26009
   381
  (Haskell "divMod")
haftmann@34899
   382
  (Scala infixl 8 "/%")
haftmann@37958
   383
  (Eval "Integer.div'_mod")
haftmann@25931
   384
haftmann@38857
   385
code_const "HOL.equal \<Colon> nat \<Rightarrow> nat \<Rightarrow> bool"
haftmann@25931
   386
  (SML "!((_ : IntInf.int) = _)")
haftmann@25931
   387
  (OCaml "Big'_int.eq'_big'_int")
haftmann@39272
   388
  (Haskell infix 4 "==")
haftmann@34899
   389
  (Scala infixl 5 "==")
haftmann@37958
   390
  (Eval infixl 6 "=")
haftmann@25931
   391
haftmann@25931
   392
code_const "op \<le> \<Colon> nat \<Rightarrow> nat \<Rightarrow> bool"
haftmann@25931
   393
  (SML "IntInf.<= ((_), (_))")
haftmann@25931
   394
  (OCaml "Big'_int.le'_big'_int")
haftmann@25931
   395
  (Haskell infix 4 "<=")
haftmann@34899
   396
  (Scala infixl 4 "<=")
haftmann@37958
   397
  (Eval infixl 6 "<=")
haftmann@25931
   398
haftmann@25931
   399
code_const "op < \<Colon> nat \<Rightarrow> nat \<Rightarrow> bool"
haftmann@25931
   400
  (SML "IntInf.< ((_), (_))")
haftmann@25931
   401
  (OCaml "Big'_int.lt'_big'_int")
haftmann@25931
   402
  (Haskell infix 4 "<")
haftmann@34899
   403
  (Scala infixl 4 "<")
haftmann@37958
   404
  (Eval infixl 6 "<")
haftmann@25931
   405
haftmann@25931
   406
haftmann@28228
   407
text {* Evaluation *}
haftmann@28228
   408
haftmann@28562
   409
lemma [code, code del]:
haftmann@32657
   410
  "(Code_Evaluation.term_of \<Colon> nat \<Rightarrow> term) = Code_Evaluation.term_of" ..
haftmann@28228
   411
haftmann@32657
   412
code_const "Code_Evaluation.term_of \<Colon> nat \<Rightarrow> term"
haftmann@28228
   413
  (SML "HOLogic.mk'_number/ HOLogic.natT")
haftmann@28228
   414
bulwahn@45793
   415
text {* Evaluation with @{text "Quickcheck_Narrowing"} does not work, as
bulwahn@45793
   416
  @{text "code_module"} is very aggressive leading to bad Haskell code.
bulwahn@45793
   417
  Therefore, we simply deactivate the narrowing-based quickcheck from here on.
bulwahn@45793
   418
*}
bulwahn@45793
   419
bulwahn@45793
   420
declare [[quickcheck_narrowing_active = false]] 
haftmann@28228
   421
haftmann@25931
   422
text {* Module names *}
haftmann@23854
   423
haftmann@23854
   424
code_modulename SML
haftmann@33364
   425
  Efficient_Nat Arith
haftmann@23854
   426
haftmann@23854
   427
code_modulename OCaml
haftmann@33364
   428
  Efficient_Nat Arith
haftmann@23854
   429
haftmann@23854
   430
code_modulename Haskell
haftmann@33364
   431
  Efficient_Nat Arith
haftmann@23854
   432
wenzelm@36176
   433
hide_const int
haftmann@23854
   434
haftmann@23854
   435
end