1 // cl_LF internals, transcendental functions
6 #include "cln/integer.h"
7 #include "cln/lfloat.h"
11 // Subroutine for evaluating
12 // sum(0 <= n < N, a(n)/b(n) * (p(0)...p(n))/(q(0)...q(n)))
13 // where all the entries are small integers (ideally polynomials in n).
14 // This is fast because it groups factors together before multiplying.
16 // Vectors p[0..N-1], q[0..N-1], a[0..N-1], b[0..N-1], N.
17 // Some of the vectors (a,b,p,q) can be a NULL pointer, all of its entries
18 // are then understood to be 1.
19 // If given, a vector qs[0..N-1] which the evaluation routine may use to
20 // split off q[n] into q[n]*2^qs[n]. qs may be NULL, in that case no shift
21 // optimizations will be used. (They are worth it only if a significant
22 // amount of multiplication work can be saved by shifts.)
23 // Result will be a cl_LF with len digits.
25 struct cl_rational_series {
26 // To be set explicitly.
33 extern const cl_LF eval_rational_series (uintL N, const cl_rational_series& args, uintC len);
35 // In each the special cases below, none of (a,b,p,q) can be NULL. But qs can
36 // still be given or NULL.
38 struct cl_pqab_series {
45 extern const cl_LF eval_rational_series (uintL N, const cl_pqab_series& args, uintC len);
47 struct cl_pqb_series {
53 extern const cl_LF eval_rational_series (uintL N, const cl_pqb_series& args, uintC len);
55 struct cl_pqa_series {
61 extern const cl_LF eval_rational_series (uintL N, const cl_pqa_series& args, uintC len);
68 extern const cl_LF eval_rational_series (uintL N, const cl_pq_series& args, uintC len);
70 struct cl_pab_series {
75 extern const cl_LF eval_rational_series (uintL N, const cl_pab_series& args, uintC len);
81 extern const cl_LF eval_rational_series (uintL N, const cl_pb_series& args, uintC len);
87 extern const cl_LF eval_rational_series (uintL N, const cl_pa_series& args, uintC len);
92 extern const cl_LF eval_rational_series (uintL N, const cl_p_series& args, uintC len);
94 struct cl_qab_series {
100 extern const cl_LF eval_rational_series (uintL N, const cl_qab_series& args, uintC len);
102 struct cl_qb_series {
107 extern const cl_LF eval_rational_series (uintL N, const cl_qb_series& args, uintC len);
109 struct cl_qa_series {
114 extern const cl_LF eval_rational_series (uintL N, const cl_qa_series& args, uintC len);
120 extern const cl_LF eval_rational_series (uintL N, const cl_q_series& args, uintC len);
122 struct cl_ab_series {
126 extern const cl_LF eval_rational_series (uintL N, const cl_ab_series& args, uintC len);
131 extern const cl_LF eval_rational_series (uintL N, const cl_b_series& args, uintC len);
136 extern const cl_LF eval_rational_series (uintL N, const cl_a_series& args, uintC len);
140 extern const cl_LF eval_rational_series (uintL N, const cl__series& args, uintC len);
143 // In this alternate implementation the series is not represented as a couple
144 // of arrays, but as a method returning each tuple (p(n),q(n),a(n),b(n))
145 // in turn. This is preferrable if the a(n) are big, in order to avoid too
146 // much memory usage at the same time.
147 // Some of the factors (a,b) may be omitted. They are then understood to be 1.
148 // The next function is called N times and is expected to return
149 // (p(n),q(n),a(n),b(n)) for n=0..N-1 in that order.
151 struct cl_pqab_series_term {
157 struct cl_pqab_series_stream {
158 cl_pqab_series_term (*nextfn)(cl_pqab_series_stream&);
159 cl_pqab_series_term next () { return nextfn(*this); }
161 cl_pqab_series_stream (cl_pqab_series_term (*n)(cl_pqab_series_stream&)) : nextfn (n) {}
163 extern const cl_LF eval_rational_series (uintL N, cl_pqab_series_stream& args, uintC len);
165 struct cl_pqb_series_term {
170 struct cl_pqb_series_stream {
171 cl_pqb_series_term (*nextfn)(cl_pqb_series_stream&);
172 cl_pqb_series_term next () { return nextfn(*this); }
174 cl_pqb_series_stream (cl_pqb_series_term (*n)(cl_pqb_series_stream&)) : nextfn (n) {}
176 extern const cl_LF eval_rational_series (uintL N, cl_pqb_series_stream& args, uintC len);
178 struct cl_pqa_series_term {
183 struct cl_pqa_series_stream {
184 cl_pqa_series_term (*nextfn)(cl_pqa_series_stream&);
185 cl_pqa_series_term next () { return nextfn(*this); }
187 cl_pqa_series_stream (cl_pqa_series_term (*n)(cl_pqa_series_stream&)) : nextfn (n) {}
189 extern const cl_LF eval_rational_series (uintL N, cl_pqa_series_stream& args, uintC len);
191 struct cl_pq_series_term {
195 struct cl_pq_series_stream {
196 cl_pq_series_term (*nextfn)(cl_pq_series_stream&);
197 cl_pq_series_term next () { return nextfn(*this); }
199 cl_pq_series_stream (cl_pq_series_term (*n)(cl_pq_series_stream&)) : nextfn (n) {}
201 extern const cl_LF eval_rational_series (uintL N, cl_pq_series_stream& args, uintC len);
206 // Evaluates S = sum(N1 <= n < N2, (p(N1)...p(n))/(q(N1)...q(n)))
207 // and U = sum(N1 <= n < N2,
208 // (c(N1)/d(N1)+...+c(n)/d(n))*(p(N1)...p(n))/(q(N1)...q(n)))
210 // P = p(N1)...p(N2-1),
211 // Q = q(N1)...q(N2-1),
213 // C/D = c(N1)/d(N1)+...+c(N2-1)/d(N2-1),
215 // all integers. On entry N1 < N2.
216 struct cl_pqcd_series_term {
222 struct cl_pqcd_series_result {
230 extern void eval_pqcd_series_aux (uintL N, cl_pqcd_series_term* args, cl_pqcd_series_result& Z, cl_boolean rightmost = cl_true);
231 // Ditto, but returns U/S.
232 extern const cl_LF eval_pqcd_series (uintL N, cl_pqcd_series_term* args, uintC len);
234 // [Special case c(n)=1.]
236 // Evaluates S = sum(N1 <= n < N2, (p(N1)...p(n))/(q(N1)...q(n)))
237 // and U = sum(N1 <= n < N2, (1/d(N1)+...+1/d(n))*(p(N1)...p(n))/(q(N1)...q(n)))
239 // P = p(N1)...p(N2-1),
240 // Q = q(N1)...q(N2-1),
242 // C/D = 1/d(N1)+...+1/d(N2-1),
244 // all integers. On entry N1 < N2.
245 struct cl_pqd_series_term {
250 struct cl_pqd_series_result {
258 extern void eval_pqd_series_aux (uintL N, cl_pqd_series_term* args, cl_pqd_series_result& Z, cl_boolean rightmost = cl_true);
259 // Ditto, but returns U/S.
260 extern const cl_LF eval_pqd_series (uintL N, cl_pqd_series_term* args, uintC len);
264 #endif /* _CL_LF_TRAN_H */