failed attempts to intercept copy command when the cursor is in the empty text field...
[LeanCalc.git] / help / cfappr
1 NAME
2     cfappr - approximate a real number using continued fractions
3
4 SYNOPSIS
5     cfappr(x [,eps [,rnd]]) or cfappr(x, n [,rnd])
6
7 TYPES
8     x           real
9     eps         real with abs(eps) < 1, defaults to epsilon()
10     n           real with n >= 1
11     rnd         integer, defaults to config("cfappr")
12
13     return      real
14
15 DESCRIPTION
16     If x is an integer or eps is zero, either form returns x.
17
18     If abs(eps) < 1, cfappr(x, eps) returns the smallest-denominator
19     number in one of the three intervals, [x, x + abs(eps)],
20     [x - abs(eps], x], [x - abs(eps)/2, x + abs(eps)/2].
21
22     If n >= 1 and den(x) > n, cfappr(x, n) returns the nearest above,
23     nearest below, or nearest, approximation to x with denominator less
24     than or equal to n.  If den(x) <= n, cfappr(x,n) returns x.
25
26     In either case when the result v is not x, how v relates to x is
27     determined by bits 0, 1, 2 and 4 of the argument rnd in the same way as
28     these bits are used in the functions round() and appr().  In the
29     following y is either eps or n.
30
31                 rnd     sign of remainder x - v
32
33                 0               sgn(y)
34                 1               -sgn(y
35                 2               sgn(x), "rounding to zero"
36                 3               -sgn(x), "rounding from zero"
37                 4               +, "rounding down"
38                 5               -, "rounding up"
39                 6               sgn(x/y)
40                 7               -sgn(x/y)
41
42     If bit 4 of rnd is set, the other bits are irrelevant for the eps case;
43     thus for 16 <= rnd < 24, cfappr(x, eps, rnd) is the smallest-denominator
44     number differing from x by at most abs(eps)/2.
45
46     If bit 4 of rnd is set and den(x) > 2, the other bits are irrelevant for
47     the bounded denominator case; in the case of two equally near nearest
48     approximations with denominator less than n, cfappr(x, n, rnd)
49     returns the number with smaller denominator.   If den(x) = 2,  bits
50     0, 1 and 2 of rnd are used as described above.
51
52     If -1 < eps < 1, cfappr(x, eps, 0) may be described as the smallest
53     denominator number in the closed interval with end-points x and x - eps.
54     It follows that if abs(a - b) < 1, cfappr(a, a - b, 0) gives the smallest
55     denominator number in the interval with end-points a and b; the same
56     result is returned by cfappr(b, b - a, 0) or cfappr(a, b - a, 1).
57
58     If abs(eps) < 1 and v = cfappr(x, eps, rnd), then
59     cfappr(x, sgn(eps) * den(v), rnd) = v.
60
61     If 1 <= n < den(x), u = cfappr(x, n, 0) and v = cfappr(x, n, 1), then
62     u < x < v, den(u) <= n, den(v) <= n, den(u) + den(v) > n, and
63     v - u = 1/(den(u) * den(v)).
64
65     If x is not zero, the nearest approximation with numerator not
66     exceeding n is 1/cfappr(1/x, n, 16).
67
68 EXAMPLE
69     > c = config("mode", "frac")
70     > x = 43/30; u = cfappr(x, 10, 0); v = cfappr(x, 10, 1);
71     > print u, v, x - u, v - x, v - u, cfappr(x, 10, 16)
72     10/7 13/9 1/210 1/90 1/63 10/7
73
74     > pi = pi(1e-10)
75     > print cfappr(pi, 100, 16), cfappr(pi, .01, 16), cfappr(pi, 1e-6, 16)
76     311/99 22/7 355/113
77
78     > x = 17/12; u = cfappr(x,4,0); v = cfappr(x,4,1);
79     > print u, v, x - u, v - x, cfappr(x,4,16)
80     4/3 3/2 1/12 1/12 3/2
81
82 LIMITS
83     none
84
85 LINK LIBRARY
86     NUMBER *qcfappr(NUMBER *q, NUMBER *epsilon, long R)
87
88 SEE ALSO
89     appr, cfsim
90