1 // cl_LF internals, transcendental functions
6 #include "cl_integer.h"
10 // Subroutine for evaluating
11 // sum(0 <= n < N, a(n)/b(n) * (p(0)...p(n))/(q(0)...q(n)))
12 // where all the entries are small integers (ideally polynomials in n).
13 // This is fast because it groups factors together before multiplying.
15 // Vectors p[0..N-1], q[0..N-1], a[0..N-1], b[0..N-1], N.
16 // Some of the vectors (a,b,p,q) can be a NULL pointer, all of its entries
17 // are then understood to be 1.
18 // If given, a vector qs[0..N-1] which the evaluation routine may use to
19 // split off q[n] into q[n]*2^qs[n]. qs may be NULL, in that case no shift
20 // optimizations will be used. (They are worth it only if a significant
21 // amount of multiplication work can be saved by shifts.)
22 // Result will be a cl_LF with len digits.
24 struct cl_rational_series {
25 // To be set explicitly.
32 extern const cl_LF eval_rational_series (uintL N, const cl_rational_series& args, uintC len);
34 // In each the special cases below, none of (a,b,p,q) can be NULL. But qs can
35 // still be given or NULL.
37 struct cl_pqab_series {
44 extern const cl_LF eval_rational_series (uintL N, const cl_pqab_series& args, uintC len);
46 struct cl_pqb_series {
52 extern const cl_LF eval_rational_series (uintL N, const cl_pqb_series& args, uintC len);
54 struct cl_pqa_series {
60 extern const cl_LF eval_rational_series (uintL N, const cl_pqa_series& args, uintC len);
67 extern const cl_LF eval_rational_series (uintL N, const cl_pq_series& args, uintC len);
69 struct cl_pab_series {
74 extern const cl_LF eval_rational_series (uintL N, const cl_pab_series& args, uintC len);
80 extern const cl_LF eval_rational_series (uintL N, const cl_pb_series& args, uintC len);
86 extern const cl_LF eval_rational_series (uintL N, const cl_pa_series& args, uintC len);
91 extern const cl_LF eval_rational_series (uintL N, const cl_p_series& args, uintC len);
93 struct cl_qab_series {
99 extern const cl_LF eval_rational_series (uintL N, const cl_qab_series& args, uintC len);
101 struct cl_qb_series {
106 extern const cl_LF eval_rational_series (uintL N, const cl_qb_series& args, uintC len);
108 struct cl_qa_series {
113 extern const cl_LF eval_rational_series (uintL N, const cl_qa_series& args, uintC len);
119 extern const cl_LF eval_rational_series (uintL N, const cl_q_series& args, uintC len);
121 struct cl_ab_series {
125 extern const cl_LF eval_rational_series (uintL N, const cl_ab_series& args, uintC len);
130 extern const cl_LF eval_rational_series (uintL N, const cl_b_series& args, uintC len);
135 extern const cl_LF eval_rational_series (uintL N, const cl_a_series& args, uintC len);
139 extern const cl_LF eval_rational_series (uintL N, const cl__series& args, uintC len);
142 // In this alternate implementation the series is not represented as a couple
143 // of arrays, but as a method returning each tuple (p(n),q(n),a(n),b(n))
144 // in turn. This is preferrable if the a(n) are big, in order to avoid too
145 // much memory usage at the same time.
146 // Some of the factors (a,b) may be omitted. They are then understood to be 1.
147 // The next function is called N times and is expected to return
148 // (p(n),q(n),a(n),b(n)) for n=0..N-1 in that order.
150 struct cl_pqab_series_term {
156 struct cl_pqab_series_stream {
157 cl_pqab_series_term (*nextfn)(cl_pqab_series_stream&);
158 cl_pqab_series_term next () { return nextfn(*this); }
160 cl_pqab_series_stream (cl_pqab_series_term (*n)(cl_pqab_series_stream&)) : nextfn (n) {}
162 extern const cl_LF eval_rational_series (uintL N, cl_pqab_series_stream& args, uintC len);
164 struct cl_pqb_series_term {
169 struct cl_pqb_series_stream {
170 cl_pqb_series_term (*nextfn)(cl_pqb_series_stream&);
171 cl_pqb_series_term next () { return nextfn(*this); }
173 cl_pqb_series_stream (cl_pqb_series_term (*n)(cl_pqb_series_stream&)) : nextfn (n) {}
175 extern const cl_LF eval_rational_series (uintL N, cl_pqb_series_stream& args, uintC len);
177 struct cl_pqa_series_term {
182 struct cl_pqa_series_stream {
183 cl_pqa_series_term (*nextfn)(cl_pqa_series_stream&);
184 cl_pqa_series_term next () { return nextfn(*this); }
186 cl_pqa_series_stream (cl_pqa_series_term (*n)(cl_pqa_series_stream&)) : nextfn (n) {}
188 extern const cl_LF eval_rational_series (uintL N, cl_pqa_series_stream& args, uintC len);
190 struct cl_pq_series_term {
194 struct cl_pq_series_stream {
195 cl_pq_series_term (*nextfn)(cl_pq_series_stream&);
196 cl_pq_series_term next () { return nextfn(*this); }
198 cl_pq_series_stream (cl_pq_series_term (*n)(cl_pq_series_stream&)) : nextfn (n) {}
200 extern const cl_LF eval_rational_series (uintL N, cl_pq_series_stream& args, uintC len);
205 // Evaluates S = sum(N1 <= n < N2, (p(N1)...p(n))/(q(N1)...q(n)))
206 // and U = sum(N1 <= n < N2,
207 // (c(N1)/d(N1)+...+c(n)/d(n))*(p(N1)...p(n))/(q(N1)...q(n)))
209 // P = p(N1)...p(N2-1),
210 // Q = q(N1)...q(N2-1),
212 // C/D = c(N1)/d(N1)+...+c(N2-1)/d(N2-1),
214 // all integers. On entry N1 < N2.
215 struct cl_pqcd_series_term {
221 struct cl_pqcd_series_result {
229 extern void eval_pqcd_series_aux (uintL N, cl_pqcd_series_term* args, cl_pqcd_series_result& Z, cl_boolean rightmost = cl_true);
230 // Ditto, but returns U/S.
231 extern const cl_LF eval_pqcd_series (uintL N, cl_pqcd_series_term* args, uintC len);
233 // [Special case c(n)=1.]
235 // Evaluates S = sum(N1 <= n < N2, (p(N1)...p(n))/(q(N1)...q(n)))
236 // and U = sum(N1 <= n < N2, (1/d(N1)+...+1/d(n))*(p(N1)...p(n))/(q(N1)...q(n)))
238 // P = p(N1)...p(N2-1),
239 // Q = q(N1)...q(N2-1),
241 // C/D = 1/d(N1)+...+1/d(N2-1),
243 // all integers. On entry N1 < N2.
244 struct cl_pqd_series_term {
249 struct cl_pqd_series_result {
257 extern void eval_pqd_series_aux (uintL N, cl_pqd_series_term* args, cl_pqd_series_result& Z, cl_boolean rightmost = cl_true);
258 // Ditto, but returns U/S.
259 extern const cl_LF eval_pqd_series (uintL N, cl_pqd_series_term* args, uintC len);
262 #endif /* _CL_LF_TRAN_H */