22071
|
1 |
(* Title: HOL/Library/ExecutableRat.thy
|
|
2 |
ID: $Id$
|
|
3 |
Author: Florian Haftmann, TU Muenchen
|
|
4 |
*)
|
|
5 |
|
|
6 |
header {* Simple example for executable rational numbers *}
|
|
7 |
|
|
8 |
theory Codegenerator_Rat
|
22803
|
9 |
imports ExecutableRat EfficientNat
|
22071
|
10 |
begin
|
|
11 |
|
|
12 |
definition
|
|
13 |
foo :: "rat \<Rightarrow> rat \<Rightarrow> rat \<Rightarrow> rat" where
|
|
14 |
"foo r s t = (t + s) / t"
|
|
15 |
|
|
16 |
definition
|
|
17 |
bar :: "rat \<Rightarrow> rat \<Rightarrow> rat \<Rightarrow> bool" where
|
|
18 |
"bar r s t \<longleftrightarrow> (r - s) \<le> t \<or> (s - t) \<le> r"
|
|
19 |
|
|
20 |
definition
|
|
21 |
"R1 = Fract 3 7"
|
|
22 |
|
|
23 |
definition
|
|
24 |
"R2 = Fract (-7) 5"
|
|
25 |
|
|
26 |
definition
|
|
27 |
"R3 = Fract 11 (-9)"
|
|
28 |
|
|
29 |
definition
|
|
30 |
"foobar = (foo R1 1 R3, bar R2 0 R3, foo R1 R3 R2)"
|
|
31 |
|
22845
|
32 |
code_gen foobar in SML in OCaml file - in Haskell file -
|
22071
|
33 |
ML {* ROOT.Codegenerator_Rat.foobar *}
|
|
34 |
|
|
35 |
code_module Foo
|
|
36 |
contains foobar
|
|
37 |
ML {* Foo.foobar *}
|
|
38 |
|
|
39 |
end
|