File: creal.mli

package info (click to toggle)
ocamlcreal 0.7-6
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, buster, jessie, jessie-kfreebsd, sid, squeeze, stretch, wheezy
  • size: 384 kB
  • ctags: 751
  • sloc: ml: 2,699; ansic: 1,067; makefile: 15
file content (140 lines) | stat: -rw-r--r-- 3,343 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
(*
 * Exact real arithmetic (Constructive reals).
 * Copyright (C) 2000 Jean-Christophe FILLIATRE
 * 
 * This software is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Library General Public
 * License version 2, as published by the Free Software Foundation.
 * 
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * 
 * See the GNU Library General Public License version 2 for more details
 * (enclosed in the file LGPL).
 *)

(*i $Id: creal.mli,v 1.22 2005/10/26 09:25:06 filliatr Exp $ i*)

(*s {\bf Constructive reals} are implemented by the following abstract
    datatype [t]. If [x] is a constructive real, then the function call
    [approx x n] returns an approximation of [x] up to $4^{-n}$, as
    an arbitrary precision integer $x_n$ such that $|4^n\cdot x - x_n| < 1$. *)

open Gmp

type t

val approx : t -> int -> Z.t

val msd : t -> int

(*s Basic operations. *)

val add : t -> t -> t
val neg : t -> t
val sub : t -> t -> t

val abs : t -> t

val mul : t -> t -> t
val inv : t -> t
val div : t -> t -> t

val pow_int : t -> int -> t
val root : int -> t -> t

val sqrt : t -> t

(*s Transcendental functions. [log ~base:x y] is $\log_x(y)$. *)

val ln : t -> t
val log : base:t -> t -> t

val exp : t -> t
val pow : t -> t -> t

(*s Trigonometric functions. *)

val sin : t -> t
val cos : t -> t
val tan : t -> t

val arcsin : t -> t
val arccos : t -> t
val arctan : t -> t

(*s [arctan_reciproqual n] is $\arctan(1/n)$, but is more efficient than
    using [arctan]. *)

val arctan_reciproqual : int -> t

(*s Hyperbolic functions. *)

val sinh : t -> t
val cosh : t -> t
val tanh : t -> t

val arcsinh : t -> t
val arccosh : t -> t
val arctanh : t -> t

(*s Some constants. *)

val zero : t
val one : t
val two : t

val pi : t
val half_pi : t

val e : t

(*s Comparisons. [cmp] is absolute comparison: it may not terminate and only
    returns [-1] or [+1]. [rel_cmp] is relative comparison, up to $4^{-k}$,
    and it returns [-1], [0] or [+1]. *)

val cmp : t -> t -> int
val rel_cmp : int -> t -> t -> int

val min : t -> t -> t
val max : t -> t -> t

(*s Coercions. [to_q] and [to_float] expect a precision. [to_float x
    n] returns the best floating point representation of the rational
    $\ap{x}{n} / 4^n$. [of_string] expects a base as second argument. *)

val of_int : int -> t
val of_z : Z.t -> t
val of_q : Q.t -> t
val of_float : float -> t
val of_string : ?radix:int -> string -> t

val to_float : t -> int -> float
val to_q : t -> int -> Q.t

(*s Coercion to type [string]. Given a decimal precision [p],
    [to_string x p] returns a decimal approximation [d] of [x] with
    either [p] digits such that $|d - x| < 10^{-p}$, or [p+1] digits
    such that $|d - x| < 10^{-p-1}$.

    [to_beautiful_string] returns the same decimal number but with
    digits packed 5 by 5. *)

val to_string : t -> int -> string
val to_beautiful_string : t -> int -> string

(*s Format pretty-printer. *)

val print : Format.formatter -> t -> unit
val set_print_precision : int -> unit

(*s Infix notations. *)

module Infixes : sig
  val ( +! ) : t -> t -> t
  val ( -! ) : t -> t -> t
  val ( *! ) : t -> t -> t
  val ( /! ) : t -> t -> t
end