Moved old website to README.
[frac.git] / cf.h
blob7226ff7b7e7715758dbef9ac6782d964f1fa5dfa
1 // Requires gmp.h
2 //
3 // Opaque interface to continued fractions object.
5 #ifndef __CF_H__
6 #define __CF_H__
8 struct cf_s;
9 typedef struct cf_s *cf_t;
11 cf_t cf_new(void *(*func)(cf_t), void *data);
12 static inline cf_t cf_new_const(void *(*func)(cf_t)) {
13 return cf_new(func, NULL);
15 void cf_free(cf_t cf);
17 void cf_set_sign(cf_t cf, int sign);
18 int cf_sign(cf_t cf);
19 int cf_flip_sign(cf_t cf);
20 void cf_get(mpz_t z, cf_t cf);
21 void cf_put(cf_t cf, mpz_t z);
22 void cf_put_int(cf_t cf, int n);
24 int cf_wait(cf_t cf);
26 void *cf_data(cf_t cf);
28 void cf_signal(cf_t cf); // For tee.
29 void cf_wait_special(cf_t cf);
31 // From cf_tee.c:
33 void cf_tee(cf_t *out_array, cf_t in);
35 // From cf_mobius.c:
37 // Compute convergents of a simple continued fraction x.
38 // Outputs p then q on channel, where p/q is the last convergent computed.
39 cf_t cf_new_cf_convergent(cf_t x);
40 // Compute decimal representation of a simple continued fraction x.
41 // Outputs integer part first, then digits one at a time.
42 cf_t cf_new_cf_to_decimal(cf_t x);
44 // Compute convergents of (a x + b)/(c x + d)
45 // where x is a regular continued fraction.
46 cf_t cf_new_mobius_convergent(cf_t x, mpz_t a, mpz_t b, mpz_t c, mpz_t d);
47 cf_t cf_new_mobius_to_decimal(cf_t x, mpz_t a, mpz_t b, mpz_t c, mpz_t d);
48 cf_t cf_new_mobius_to_cf(cf_t x, mpz_t z[4]);
50 // Compute convergents of (a x + b)/(c x + d)
51 // where x is a nonregular continued fraction.
52 cf_t cf_new_nonregular_mobius_convergent(cf_t x, mpz_t a, mpz_t b, mpz_t c, mpz_t d);
53 // Input: Mobius transformation and nonregular continued fraction.
54 // Output: Regular continued fraction. Assumes input fraction is well-behaved.
55 cf_t cf_new_nonregular_to_cf(cf_t x, mpz_t a, mpz_t b, mpz_t c, mpz_t d);
56 // Does both of the above at once. Seems slow.
57 cf_t cf_new_nonregular_mobius_to_decimal(cf_t x, mpz_t a[4]);
59 cf_t cf_new_const_nonregular(void *(*fun)(cf_t));
60 cf_t cf_new_one_arg_nonregular(void *(*fun)(cf_t), mpz_t z);
62 // Well-known continued fraction expansions.
63 // cf_famous.c:
64 // e:
65 cf_t cf_new_sqrt2();
66 cf_t cf_new_sqrt5();
67 cf_t cf_new_e();
68 cf_t cf_new_pi();
69 cf_t cf_new_tan1();
70 cf_t cf_new_epow(mpz_t pow);
71 cf_t cf_new_tanh(mpz_t z);
73 // This won't work because my code cannot handle negative denominators,
74 // and also assumes the sequence of convergents alternatively overshoot
75 // and undershoots the target. The tan expansion leads to a sequence of
76 // strictly increasing convergents (for positive input).
77 cf_t cf_new_tan(mpz_t z);
79 // Gosper's method for computing bihomographic functions of continued fractions.
80 cf_t cf_new_bihom(cf_t x, cf_t y, mpz_t a[8]);
81 cf_t cf_new_add(cf_t x, cf_t y);
82 cf_t cf_new_sub(cf_t x, cf_t y);
83 cf_t cf_new_mul(cf_t x, cf_t y);
84 cf_t cf_new_div(cf_t x, cf_t y);
86 void mpz8_init(mpz_t z[8]);
87 void mpz8_clear(mpz_t z[8]);
88 void mpz8_set_int(mpz_t z[8],
89 int a, int b, int c, int d,
90 int e, int f, int g, int h);
91 void mpz8_set_add(mpz_t z[8]);
92 void mpz8_set_sub(mpz_t z[8]);
93 void mpz8_set_mul(mpz_t z[8]);
94 void mpz8_set_div(mpz_t z[8]);
96 // From taylor.c:
97 cf_t cf_new_sin1();
98 cf_t cf_new_cos1();
100 // From newton.c:
101 // Use Newton's method to find solutions of:
103 // a0 xy + a1 x + a2 y + a3
104 // y = ------------------------
105 // a4 xy - a0 x + a5 y - a2
106 cf_t cf_new_newton(cf_t x, mpz_t a[6], mpz_t lower);
107 cf_t cf_new_sqrt(cf_t x);
108 cf_t cf_new_sqrt_int(int a, int b);
109 cf_t cf_new_sqrt_pq(mpz_t zp, mpz_t zq);
111 #endif // __CF_H__