178 |
178 |
179 end; |
179 end; |
180 *} |
180 *} |
181 |
181 |
182 |
182 |
|
183 subsection {* Specialized @{term "op - \<Colon> index \<Rightarrow> index \<Rightarrow> index"}, |
|
184 @{term "op div \<Colon> index \<Rightarrow> index \<Rightarrow> index"} and @{term "op mod \<Colon> index \<Rightarrow> index \<Rightarrow> index"} |
|
185 operations *} |
|
186 |
|
187 definition |
|
188 minus_index_aux :: "index \<Rightarrow> index \<Rightarrow> index" |
|
189 where |
|
190 [code func del]: "minus_index_aux = op -" |
|
191 |
|
192 lemma [code func]: "op - = minus_index_aux" |
|
193 using minus_index_aux_def .. |
|
194 |
|
195 definition |
|
196 div_mod_index :: "index \<Rightarrow> index \<Rightarrow> index \<times> index" |
|
197 where |
|
198 [code func del]: "div_mod_index n m = (n div m, n mod m)" |
|
199 |
|
200 lemma [code func]: |
|
201 "div_mod_index n m = (if m = 0 then (0, n) else (n div m, n mod m))" |
|
202 unfolding div_mod_index_def by auto |
|
203 |
|
204 lemma [code func]: |
|
205 "n div m = fst (div_mod_index n m)" |
|
206 unfolding div_mod_index_def by simp |
|
207 |
|
208 lemma [code func]: |
|
209 "n mod m = snd (div_mod_index n m)" |
|
210 unfolding div_mod_index_def by simp |
|
211 |
|
212 |
183 subsection {* Code serialization *} |
213 subsection {* Code serialization *} |
184 |
214 |
185 text {* Implementation of indices by bounded integers *} |
215 text {* Implementation of indices by bounded integers *} |
186 |
216 |
187 code_type index |
217 code_type index |
203 code_const "op + \<Colon> index \<Rightarrow> index \<Rightarrow> index" |
233 code_const "op + \<Colon> index \<Rightarrow> index \<Rightarrow> index" |
204 (SML "Int.+/ ((_),/ (_))") |
234 (SML "Int.+/ ((_),/ (_))") |
205 (OCaml "Pervasives.( + )") |
235 (OCaml "Pervasives.( + )") |
206 (Haskell infixl 6 "+") |
236 (Haskell infixl 6 "+") |
207 |
237 |
208 code_const "op - \<Colon> index \<Rightarrow> index \<Rightarrow> index" |
238 code_const "minus_index_aux \<Colon> index \<Rightarrow> index \<Rightarrow> index" |
209 (SML "Int.max/ (_/ -/ _,/ 0 : int)") |
239 (SML "Int.max/ (_/ -/ _,/ 0 : int)") |
210 (OCaml "Pervasives.max/ (_/ -/ _)/ (0 : int) ") |
240 (OCaml "Pervasives.max/ (_/ -/ _)/ (0 : int) ") |
211 (Haskell "max/ (_/ -/ _)/ (0 :: Int)") |
241 (Haskell "max/ (_/ -/ _)/ (0 :: Int)") |
212 |
242 |
213 code_const "op * \<Colon> index \<Rightarrow> index \<Rightarrow> index" |
243 code_const "op * \<Colon> index \<Rightarrow> index \<Rightarrow> index" |
214 (SML "Int.*/ ((_),/ (_))") |
244 (SML "Int.*/ ((_),/ (_))") |
215 (OCaml "Pervasives.( * )") |
245 (OCaml "Pervasives.( * )") |
216 (Haskell infixl 7 "*") |
246 (Haskell infixl 7 "*") |
217 |
247 |
218 code_const "op div \<Colon> index \<Rightarrow> index \<Rightarrow> index" |
248 code_const div_mod_index |
219 (SML "Int.div/ ((_),/ (_))") |
249 (SML "(fn n => fn m =>/ (n div m, n mod m))") |
220 (OCaml "Pervasives.( / )") |
250 (OCaml "(fun n -> fun m ->/ (n '/ m, n mod m))") |
221 (Haskell "div") |
251 (Haskell "divMod") |
222 |
|
223 code_const "op mod \<Colon> index \<Rightarrow> index \<Rightarrow> index" |
|
224 (SML "Int.mod/ ((_),/ (_))") |
|
225 (OCaml "Pervasives.( mod )") |
|
226 (Haskell "mod") |
|
227 |
252 |
228 code_const "op = \<Colon> index \<Rightarrow> index \<Rightarrow> bool" |
253 code_const "op = \<Colon> index \<Rightarrow> index \<Rightarrow> bool" |
229 (SML "!((_ : Int.int) = _)") |
254 (SML "!((_ : Int.int) = _)") |
230 (OCaml "!((_ : int) = _)") |
255 (OCaml "!((_ : int) = _)") |
231 (Haskell infixl 4 "==") |
256 (Haskell infixl 4 "==") |