DRealFns.mesa
Copyright Ó 1989, 1991 by Xerox Corporation. All rights reserved.
Russ Atkinson (RRA) June 22, 1989 9:40:11 pm PDT
DRealFns: CEDAR DEFINITIONS = BEGIN
Exponent and logarithm functions
Exp: PROC [x: DREAL] RETURNS [DREAL];
For an input argument x, returns e^x (e=2.718...).
Ln: PROC [x: DREAL] RETURNS [DREAL];
Computes the natural logarithm (base e) of x.
Log: PROC [base, arg: DREAL] RETURNS [DREAL];
Computes logarithm to the base of arg.
Power: PROC [base, exponent: DREAL] RETURNS [DREAL];
Calculates base to the exponent power by e(exponent*Ln(base)).
Root: PROC [index, arg: DREAL] RETURNS [DREAL];
Calculates the index root of arg by e(Ln(arg)/index).
SqRt: PROC [x: DREAL] RETURNS [DREAL];
Calculates the square root of the input value by Newton's iteration.
Trigonometric functions
Sin: PROC [radians: DREAL] RETURNS [DREAL];
SinDeg: PROC [degrees: DREAL] RETURNS [DREAL];
Cos: PROC [radians: DREAL] RETURNS [DREAL];
CosDeg: PROC [degrees: DREAL] RETURNS [DREAL];
Tan: PROC [radians: DREAL] RETURNS [DREAL];
TanDeg: PROC [degrees: DREAL] RETURNS [DREAL];
ArcTan: PROC [y, x: DREAL] RETURNS [radians: DREAL];
ArcTanDeg: PROC [y, x: DREAL] RETURNS [degrees: DREAL];
Hyperbolic circle functions
SinH: PROC [x: DREAL] RETURNS [DREAL];
Hyperbolic sine
CosH: PROC [x: DREAL] RETURNS [DREAL];
Hyperbolic cosine
TanH: PROC [x: DREAL] RETURNS [DREAL];
Hyperbolic tangent
CotH: PROC [x: DREAL] RETURNS [DREAL];
Hyperbolic cotangent
InvSinH: PROC [x: DREAL] RETURNS [DREAL];
InvCosH: PROC [x: DREAL] RETURNS [DREAL];
...defined for x >= 1.0, returns non-negative result
InvTanH: PROC [x: DREAL] RETURNS [DREAL];
...defined for x IN (-1.0..1.0)
InvCotH: PROC [x: DREAL] RETURNS [DREAL];
...defined for x NOT IN [-1.0..1.0]
Gamma functions
LnGamma: PROC [x: DREAL] RETURNS [DREAL];
.. defined for x>0
Gamma: PROC [x: DREAL] RETURNS [DREAL];
.. defined for x>0; computed by Exp[LnGamma[x]]
Gamma[x+1] = x! for integer x.
Bessel functions
J0: PROC [x: DREAL] RETURNS [DREAL];
Bessel function of first kind of order 0
J1: PROC [x: DREAL] RETURNS [DREAL];
Bessel function of first kind of order 1
Jn: PROC [n: INT, x: DREAL] RETURNS [DREAL];
Bessel function of first kind of order n
Y0: PROC [x: DREAL] RETURNS [DREAL];
Bessel function of second kind of order 0
Y1: PROC [x: DREAL] RETURNS [DREAL];
Bessel function of second kind of order 1
Yn: PROC [n: INT, x: DREAL] RETURNS [DREAL];
Bessel function of second kind of order n
Rational approximation
Rational: TYPE ~ RECORD [numerator: INT, denominator: INT];
RationalFromDReal: PROC [x: DREAL, limit: INT ¬ INT.LAST] RETURNS [Rational];
... computes the best rational approximation to a real using continued fractions.
|numerator| <= limit, 0 < denominator <= limit.
Approximate equality
AlmostZero: PROC [x: DREAL, distance: INTEGER] RETURNS [BOOL];
AlmostZero[x, distance] ==
ABS[x] < 2^distance
AlmostEqual: PROC [y, x: DREAL, distance: INTEGER] RETURNS [BOOL];
AlmostEqual[y, x, distance] ==
NotNaN[x] AND NotNaN[y] AND
ABS[x-y] <= MAX[ABS[x], ABS[y]] * 2^distance
Notes:
When either number is a Nan (not-a-number), then equality is never guaranteed, so FALSE is a conservative answer.
Comparing anything against 0.0 can give surprising results using the above definition, since ABS[x-0] = MAX[ABS[x], ABS[0]], which implies that AlmostEqual[0, x, distance] is only true for distance = 0.
END.
Russ Atkinson (RRA) May 29, 1989 5:05:29 pm PDT
Adapted from RealFns