src/HOL/Library/Code_Index.thy
author haftmann
Tue, 29 Jan 2008 10:19:56 +0100
changeset 26009 b6a64fe38634
parent 25967 dd602eb20f3f
child 26086 3c243098b64a
permissions -rw-r--r--
treating division by zero properly
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24999
haftmann
parents:
diff changeset
     1
(*  ID:         $Id$
haftmann
parents:
diff changeset
     2
    Author:     Florian Haftmann, TU Muenchen
haftmann
parents:
diff changeset
     3
*)
haftmann
parents:
diff changeset
     4
haftmann
parents:
diff changeset
     5
header {* Type of indices *}
haftmann
parents:
diff changeset
     6
haftmann
parents:
diff changeset
     7
theory Code_Index
25691
8f8d83af100a switched from PreList to ATP_Linkup
haftmann
parents: 25502
diff changeset
     8
imports ATP_Linkup
24999
haftmann
parents:
diff changeset
     9
begin
haftmann
parents:
diff changeset
    10
haftmann
parents:
diff changeset
    11
text {*
25767
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    12
  Indices are isomorphic to HOL @{typ nat} but
24999
haftmann
parents:
diff changeset
    13
  mapped to target-language builtin integers
haftmann
parents:
diff changeset
    14
*}
haftmann
parents:
diff changeset
    15
haftmann
parents:
diff changeset
    16
subsection {* Datatype of indices *}
haftmann
parents:
diff changeset
    17
25767
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    18
datatype index = index_of_nat nat
24999
haftmann
parents:
diff changeset
    19
25967
dd602eb20f3f fixed and tuned
haftmann
parents: 25945
diff changeset
    20
lemma [code func]:
dd602eb20f3f fixed and tuned
haftmann
parents: 25945
diff changeset
    21
  "index_size k = 0"
dd602eb20f3f fixed and tuned
haftmann
parents: 25945
diff changeset
    22
  by (cases k) simp
dd602eb20f3f fixed and tuned
haftmann
parents: 25945
diff changeset
    23
24999
haftmann
parents:
diff changeset
    24
lemmas [code func del] = index.recs index.cases
haftmann
parents:
diff changeset
    25
25767
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    26
primrec
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    27
  nat_of_index :: "index \<Rightarrow> nat"
24999
haftmann
parents:
diff changeset
    28
where
25767
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    29
  "nat_of_index (index_of_nat k) = k"
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    30
lemmas [code func del] = nat_of_index.simps
24999
haftmann
parents:
diff changeset
    31
haftmann
parents:
diff changeset
    32
lemma index_id [simp]:
25767
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    33
  "index_of_nat (nat_of_index n) = n"
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    34
  by (cases n) simp_all
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    35
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    36
lemma nat_of_index_inject [simp]:
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    37
  "nat_of_index n = nat_of_index m \<longleftrightarrow> n = m"
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    38
  by (cases n) auto
24999
haftmann
parents:
diff changeset
    39
haftmann
parents:
diff changeset
    40
lemma index:
25767
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    41
  "(\<And>n\<Colon>index. PROP P n) \<equiv> (\<And>n\<Colon>nat. PROP P (index_of_nat n))"
24999
haftmann
parents:
diff changeset
    42
proof
25767
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    43
  fix n :: nat
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    44
  assume "\<And>n\<Colon>index. PROP P n"
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    45
  then show "PROP P (index_of_nat n)" .
24999
haftmann
parents:
diff changeset
    46
next
25767
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    47
  fix n :: index
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    48
  assume "\<And>n\<Colon>nat. PROP P (index_of_nat n)"
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    49
  then have "PROP P (index_of_nat (nat_of_index n))" .
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    50
  then show "PROP P n" by simp
24999
haftmann
parents:
diff changeset
    51
qed
haftmann
parents:
diff changeset
    52
25767
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    53
lemma [code func]: "size (n\<Colon>index) = 0"
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    54
  by (cases n) simp_all
24999
haftmann
parents:
diff changeset
    55
haftmann
parents:
diff changeset
    56
25767
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    57
subsection {* Indices as datatype of ints *}
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    58
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    59
instantiation index :: number
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    60
begin
24999
haftmann
parents:
diff changeset
    61
25767
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    62
definition
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    63
  "number_of = index_of_nat o nat"
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    64
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    65
instance ..
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    66
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    67
end
24999
haftmann
parents:
diff changeset
    68
haftmann
parents:
diff changeset
    69
code_datatype "number_of \<Colon> int \<Rightarrow> index"
haftmann
parents:
diff changeset
    70
haftmann
parents:
diff changeset
    71
haftmann
parents:
diff changeset
    72
subsection {* Basic arithmetic *}
haftmann
parents:
diff changeset
    73
25767
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    74
instantiation index :: "{minus, ordered_semidom, Divides.div, linorder}"
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    75
begin
24999
haftmann
parents:
diff changeset
    76
25767
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    77
definition [simp, code func del]:
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    78
  "(0\<Colon>index) = index_of_nat 0"
24999
haftmann
parents:
diff changeset
    79
haftmann
parents:
diff changeset
    80
lemma zero_index_code [code inline, code func]:
haftmann
parents:
diff changeset
    81
  "(0\<Colon>index) = Numeral0"
25767
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    82
  by (simp add: number_of_index_def Pls_def)
25967
dd602eb20f3f fixed and tuned
haftmann
parents: 25945
diff changeset
    83
lemma [code post]: "Numeral0 = (0\<Colon>index)"
dd602eb20f3f fixed and tuned
haftmann
parents: 25945
diff changeset
    84
  using zero_index_code ..
25767
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    85
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    86
definition [simp, code func del]:
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    87
  "(1\<Colon>index) = index_of_nat 1"
24999
haftmann
parents:
diff changeset
    88
haftmann
parents:
diff changeset
    89
lemma one_index_code [code inline, code func]:
haftmann
parents:
diff changeset
    90
  "(1\<Colon>index) = Numeral1"
25767
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    91
  by (simp add: number_of_index_def Pls_def Bit_def)
25967
dd602eb20f3f fixed and tuned
haftmann
parents: 25945
diff changeset
    92
lemma [code post]: "Numeral1 = (1\<Colon>index)"
dd602eb20f3f fixed and tuned
haftmann
parents: 25945
diff changeset
    93
  using one_index_code ..
25767
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    94
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    95
definition [simp, code func del]:
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    96
  "n + m = index_of_nat (nat_of_index n + nat_of_index m)"
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    97
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    98
lemma plus_index_code [code func]:
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
    99
  "index_of_nat n + index_of_nat m = index_of_nat (n + m)"
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
   100
  by simp
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
   101
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
   102
definition [simp, code func del]:
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
   103
  "n - m = index_of_nat (nat_of_index n - nat_of_index m)"
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
   104
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
   105
definition [simp, code func del]:
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
   106
  "n * m = index_of_nat (nat_of_index n * nat_of_index m)"
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
   107
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
   108
lemma times_index_code [code func]:
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
   109
  "index_of_nat n * index_of_nat m = index_of_nat (n * m)"
24999
haftmann
parents:
diff changeset
   110
  by simp
haftmann
parents:
diff changeset
   111
25767
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
   112
definition [simp, code func del]:
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
   113
  "n div m = index_of_nat (nat_of_index n div nat_of_index m)"
24999
haftmann
parents:
diff changeset
   114
25767
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
   115
definition [simp, code func del]:
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
   116
  "n mod m = index_of_nat (nat_of_index n mod nat_of_index m)"
24999
haftmann
parents:
diff changeset
   117
25767
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
   118
lemma div_index_code [code func]:
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
   119
  "index_of_nat n div index_of_nat m = index_of_nat (n div m)"
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
   120
  by simp
25335
182a001a7ea4 duv, mod, int conversion
haftmann
parents: 24999
diff changeset
   121
25767
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
   122
lemma mod_index_code [code func]:
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
   123
  "index_of_nat n mod index_of_nat m = index_of_nat (n mod m)"
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
   124
  by simp
24999
haftmann
parents:
diff changeset
   125
25767
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
   126
definition [simp, code func del]:
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
   127
  "n \<le> m \<longleftrightarrow> nat_of_index n \<le> nat_of_index m"
24999
haftmann
parents:
diff changeset
   128
25767
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
   129
definition [simp, code func del]:
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
   130
  "n < m \<longleftrightarrow> nat_of_index n < nat_of_index m"
24999
haftmann
parents:
diff changeset
   131
25767
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
   132
lemma less_eq_index_code [code func]:
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
   133
  "index_of_nat n \<le> index_of_nat m \<longleftrightarrow> n \<le> m"
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
   134
  by simp
24999
haftmann
parents:
diff changeset
   135
25767
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
   136
lemma less_index_code [code func]:
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
   137
  "index_of_nat n < index_of_nat m \<longleftrightarrow> n < m"
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
   138
  by simp
24999
haftmann
parents:
diff changeset
   139
25767
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
   140
instance by default (auto simp add: left_distrib index)
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
   141
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
   142
end
24999
haftmann
parents:
diff changeset
   143
25928
042e877d9841 tuned code setup
haftmann
parents: 25918
diff changeset
   144
lemma index_of_nat_code [code]:
25918
haftmann
parents: 25767
diff changeset
   145
  "index_of_nat = of_nat"
haftmann
parents: 25767
diff changeset
   146
proof
haftmann
parents: 25767
diff changeset
   147
  fix n :: nat
haftmann
parents: 25767
diff changeset
   148
  have "of_nat n = index_of_nat n"
haftmann
parents: 25767
diff changeset
   149
    by (induct n) simp_all
haftmann
parents: 25767
diff changeset
   150
  then show "index_of_nat n = of_nat n"
haftmann
parents: 25767
diff changeset
   151
    by (rule sym)
haftmann
parents: 25767
diff changeset
   152
qed
haftmann
parents: 25767
diff changeset
   153
25928
042e877d9841 tuned code setup
haftmann
parents: 25918
diff changeset
   154
lemma index_not_eq_zero: "i \<noteq> index_of_nat 0 \<longleftrightarrow> i \<ge> 1"
042e877d9841 tuned code setup
haftmann
parents: 25918
diff changeset
   155
  by (cases i) auto
042e877d9841 tuned code setup
haftmann
parents: 25918
diff changeset
   156
042e877d9841 tuned code setup
haftmann
parents: 25918
diff changeset
   157
definition
042e877d9841 tuned code setup
haftmann
parents: 25918
diff changeset
   158
  nat_of_index_aux :: "index \<Rightarrow> nat \<Rightarrow> nat"
042e877d9841 tuned code setup
haftmann
parents: 25918
diff changeset
   159
where
042e877d9841 tuned code setup
haftmann
parents: 25918
diff changeset
   160
  "nat_of_index_aux i n = nat_of_index i + n"
042e877d9841 tuned code setup
haftmann
parents: 25918
diff changeset
   161
042e877d9841 tuned code setup
haftmann
parents: 25918
diff changeset
   162
lemma nat_of_index_aux_code [code]:
042e877d9841 tuned code setup
haftmann
parents: 25918
diff changeset
   163
  "nat_of_index_aux i n = (if i = 0 then n else nat_of_index_aux (i - 1) (Suc n))"
042e877d9841 tuned code setup
haftmann
parents: 25918
diff changeset
   164
  by (auto simp add: nat_of_index_aux_def index_not_eq_zero)
042e877d9841 tuned code setup
haftmann
parents: 25918
diff changeset
   165
042e877d9841 tuned code setup
haftmann
parents: 25918
diff changeset
   166
lemma nat_of_index_code [code]:
042e877d9841 tuned code setup
haftmann
parents: 25918
diff changeset
   167
  "nat_of_index i = nat_of_index_aux i 0"
042e877d9841 tuned code setup
haftmann
parents: 25918
diff changeset
   168
  by (simp add: nat_of_index_aux_def)
25918
haftmann
parents: 25767
diff changeset
   169
24999
haftmann
parents:
diff changeset
   170
haftmann
parents:
diff changeset
   171
subsection {* ML interface *}
haftmann
parents:
diff changeset
   172
haftmann
parents:
diff changeset
   173
ML {*
haftmann
parents:
diff changeset
   174
structure Index =
haftmann
parents:
diff changeset
   175
struct
haftmann
parents:
diff changeset
   176
25928
042e877d9841 tuned code setup
haftmann
parents: 25918
diff changeset
   177
fun mk k = HOLogic.mk_number @{typ index} k;
24999
haftmann
parents:
diff changeset
   178
haftmann
parents:
diff changeset
   179
end;
haftmann
parents:
diff changeset
   180
*}
haftmann
parents:
diff changeset
   181
haftmann
parents:
diff changeset
   182
26009
b6a64fe38634 treating division by zero properly
haftmann
parents: 25967
diff changeset
   183
subsection {* Specialized @{term "op - \<Colon> index \<Rightarrow> index \<Rightarrow> index"},
b6a64fe38634 treating division by zero properly
haftmann
parents: 25967
diff changeset
   184
  @{term "op div \<Colon> index \<Rightarrow> index \<Rightarrow> index"} and @{term "op mod \<Colon> index \<Rightarrow> index \<Rightarrow> index"}
b6a64fe38634 treating division by zero properly
haftmann
parents: 25967
diff changeset
   185
  operations *}
b6a64fe38634 treating division by zero properly
haftmann
parents: 25967
diff changeset
   186
b6a64fe38634 treating division by zero properly
haftmann
parents: 25967
diff changeset
   187
definition
b6a64fe38634 treating division by zero properly
haftmann
parents: 25967
diff changeset
   188
  minus_index_aux :: "index \<Rightarrow> index \<Rightarrow> index"
b6a64fe38634 treating division by zero properly
haftmann
parents: 25967
diff changeset
   189
where
b6a64fe38634 treating division by zero properly
haftmann
parents: 25967
diff changeset
   190
  [code func del]: "minus_index_aux = op -"
b6a64fe38634 treating division by zero properly
haftmann
parents: 25967
diff changeset
   191
b6a64fe38634 treating division by zero properly
haftmann
parents: 25967
diff changeset
   192
lemma [code func]: "op - = minus_index_aux"
b6a64fe38634 treating division by zero properly
haftmann
parents: 25967
diff changeset
   193
  using minus_index_aux_def ..
b6a64fe38634 treating division by zero properly
haftmann
parents: 25967
diff changeset
   194
b6a64fe38634 treating division by zero properly
haftmann
parents: 25967
diff changeset
   195
definition
b6a64fe38634 treating division by zero properly
haftmann
parents: 25967
diff changeset
   196
  div_mod_index ::  "index \<Rightarrow> index \<Rightarrow> index \<times> index"
b6a64fe38634 treating division by zero properly
haftmann
parents: 25967
diff changeset
   197
where
b6a64fe38634 treating division by zero properly
haftmann
parents: 25967
diff changeset
   198
  [code func del]: "div_mod_index n m = (n div m, n mod m)"
b6a64fe38634 treating division by zero properly
haftmann
parents: 25967
diff changeset
   199
b6a64fe38634 treating division by zero properly
haftmann
parents: 25967
diff changeset
   200
lemma [code func]:
b6a64fe38634 treating division by zero properly
haftmann
parents: 25967
diff changeset
   201
  "div_mod_index n m = (if m = 0 then (0, n) else (n div m, n mod m))"
b6a64fe38634 treating division by zero properly
haftmann
parents: 25967
diff changeset
   202
  unfolding div_mod_index_def by auto
b6a64fe38634 treating division by zero properly
haftmann
parents: 25967
diff changeset
   203
b6a64fe38634 treating division by zero properly
haftmann
parents: 25967
diff changeset
   204
lemma [code func]:
b6a64fe38634 treating division by zero properly
haftmann
parents: 25967
diff changeset
   205
  "n div m = fst (div_mod_index n m)"
b6a64fe38634 treating division by zero properly
haftmann
parents: 25967
diff changeset
   206
  unfolding div_mod_index_def by simp
b6a64fe38634 treating division by zero properly
haftmann
parents: 25967
diff changeset
   207
b6a64fe38634 treating division by zero properly
haftmann
parents: 25967
diff changeset
   208
lemma [code func]:
b6a64fe38634 treating division by zero properly
haftmann
parents: 25967
diff changeset
   209
  "n mod m = snd (div_mod_index n m)"
b6a64fe38634 treating division by zero properly
haftmann
parents: 25967
diff changeset
   210
  unfolding div_mod_index_def by simp
b6a64fe38634 treating division by zero properly
haftmann
parents: 25967
diff changeset
   211
b6a64fe38634 treating division by zero properly
haftmann
parents: 25967
diff changeset
   212
24999
haftmann
parents:
diff changeset
   213
subsection {* Code serialization *}
haftmann
parents:
diff changeset
   214
25767
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
   215
text {* Implementation of indices by bounded integers *}
852bce03412a index now a copy of nat rather than int
haftmann
parents: 25691
diff changeset
   216
24999
haftmann
parents:
diff changeset
   217
code_type index
haftmann
parents:
diff changeset
   218
  (SML "int")
haftmann
parents:
diff changeset
   219
  (OCaml "int")
25967
dd602eb20f3f fixed and tuned
haftmann
parents: 25945
diff changeset
   220
  (Haskell "Int")
24999
haftmann
parents:
diff changeset
   221
haftmann
parents:
diff changeset
   222
code_instance index :: eq
haftmann
parents:
diff changeset
   223
  (Haskell -)
haftmann
parents:
diff changeset
   224
haftmann
parents:
diff changeset
   225
setup {*
25928
042e877d9841 tuned code setup
haftmann
parents: 25918
diff changeset
   226
  fold (Numeral.add_code @{const_name number_index_inst.number_of_index}
042e877d9841 tuned code setup
haftmann
parents: 25918
diff changeset
   227
    false false) ["SML", "OCaml", "Haskell"]
24999
haftmann
parents:
diff changeset
   228
*}
haftmann
parents:
diff changeset
   229
25918
haftmann
parents: 25767
diff changeset
   230
code_reserved SML Int int
haftmann
parents: 25767
diff changeset
   231
code_reserved OCaml Pervasives int
24999
haftmann
parents:
diff changeset
   232
haftmann
parents:
diff changeset
   233
code_const "op + \<Colon> index \<Rightarrow> index \<Rightarrow> index"
25928
042e877d9841 tuned code setup
haftmann
parents: 25918
diff changeset
   234
  (SML "Int.+/ ((_),/ (_))")
25967
dd602eb20f3f fixed and tuned
haftmann
parents: 25945
diff changeset
   235
  (OCaml "Pervasives.( + )")
24999
haftmann
parents:
diff changeset
   236
  (Haskell infixl 6 "+")
haftmann
parents:
diff changeset
   237
26009
b6a64fe38634 treating division by zero properly
haftmann
parents: 25967
diff changeset
   238
code_const "minus_index_aux \<Colon> index \<Rightarrow> index \<Rightarrow> index"
25918
haftmann
parents: 25767
diff changeset
   239
  (SML "Int.max/ (_/ -/ _,/ 0 : int)")
haftmann
parents: 25767
diff changeset
   240
  (OCaml "Pervasives.max/ (_/ -/ _)/ (0 : int) ")
haftmann
parents: 25767
diff changeset
   241
  (Haskell "max/ (_/ -/ _)/ (0 :: Int)")
24999
haftmann
parents:
diff changeset
   242
haftmann
parents:
diff changeset
   243
code_const "op * \<Colon> index \<Rightarrow> index \<Rightarrow> index"
25928
042e877d9841 tuned code setup
haftmann
parents: 25918
diff changeset
   244
  (SML "Int.*/ ((_),/ (_))")
25967
dd602eb20f3f fixed and tuned
haftmann
parents: 25945
diff changeset
   245
  (OCaml "Pervasives.( * )")
24999
haftmann
parents:
diff changeset
   246
  (Haskell infixl 7 "*")
haftmann
parents:
diff changeset
   247
26009
b6a64fe38634 treating division by zero properly
haftmann
parents: 25967
diff changeset
   248
code_const div_mod_index
b6a64fe38634 treating division by zero properly
haftmann
parents: 25967
diff changeset
   249
  (SML "(fn n => fn m =>/ (n div m, n mod m))")
b6a64fe38634 treating division by zero properly
haftmann
parents: 25967
diff changeset
   250
  (OCaml "(fun n -> fun m ->/ (n '/ m, n mod m))")
b6a64fe38634 treating division by zero properly
haftmann
parents: 25967
diff changeset
   251
  (Haskell "divMod")
25928
042e877d9841 tuned code setup
haftmann
parents: 25918
diff changeset
   252
24999
haftmann
parents:
diff changeset
   253
code_const "op = \<Colon> index \<Rightarrow> index \<Rightarrow> bool"
haftmann
parents:
diff changeset
   254
  (SML "!((_ : Int.int) = _)")
25967
dd602eb20f3f fixed and tuned
haftmann
parents: 25945
diff changeset
   255
  (OCaml "!((_ : int) = _)")
24999
haftmann
parents:
diff changeset
   256
  (Haskell infixl 4 "==")
haftmann
parents:
diff changeset
   257
haftmann
parents:
diff changeset
   258
code_const "op \<le> \<Colon> index \<Rightarrow> index \<Rightarrow> bool"
25928
042e877d9841 tuned code setup
haftmann
parents: 25918
diff changeset
   259
  (SML "Int.<=/ ((_),/ (_))")
25967
dd602eb20f3f fixed and tuned
haftmann
parents: 25945
diff changeset
   260
  (OCaml "!((_ : int) <= _)")
24999
haftmann
parents:
diff changeset
   261
  (Haskell infix 4 "<=")
haftmann
parents:
diff changeset
   262
haftmann
parents:
diff changeset
   263
code_const "op < \<Colon> index \<Rightarrow> index \<Rightarrow> bool"
25928
042e877d9841 tuned code setup
haftmann
parents: 25918
diff changeset
   264
  (SML "Int.</ ((_),/ (_))")
25967
dd602eb20f3f fixed and tuned
haftmann
parents: 25945
diff changeset
   265
  (OCaml "!((_ : int) < _)")
24999
haftmann
parents:
diff changeset
   266
  (Haskell infix 4 "<")
haftmann
parents:
diff changeset
   267
haftmann
parents:
diff changeset
   268
end