1 // eval_rational_series().
7 #include "cl_LF_tran.h"
12 #include "cln/lfloat.h"
13 #include "cln/integer.h"
14 #include "cln/abort.h"
20 // Evaluates S = sum(N1 <= n < N2, a(n)/b(n) * (p(N1)...p(n))/(q(N1)...q(n)))
21 // and returns P = p(N1)...p(N2-1), Q = q(N1)...q(N2-1), B = B(N1)...B(N2-1)
22 // and T = B*Q*S (all integers). On entry N1 < N2.
23 // P will not be computed if a NULL pointer is passed.
25 static void eval_pb_series_aux (uintL N1, uintL N2,
26 const cl_pb_series& args,
27 cl_I* P, cl_I* B, cl_I* T)
33 if (P) { *P = args.pv[N1]; }
38 var cl_I p01 = args.pv[N1] * args.pv[N1+1];
40 *B = args.bv[N1] * args.bv[N1+1];
41 *T = args.bv[N1+1] * args.pv[N1]
46 var cl_I p01 = args.pv[N1] * args.pv[N1+1];
47 var cl_I p012 = p01 * args.pv[N1+2];
49 var cl_I b12 = args.bv[N1+1] * args.bv[N1+2];
50 *B = args.bv[N1] * b12;
51 *T = b12 * args.pv[N1]
52 + args.bv[N1] * (args.bv[N1+2] * p01
53 + args.bv[N1+1] * p012);
57 var cl_I p01 = args.pv[N1] * args.pv[N1+1];
58 var cl_I p012 = p01 * args.pv[N1+2];
59 var cl_I p0123 = p012 * args.pv[N1+3];
60 if (P) { *P = p0123; }
61 var cl_I b01 = args.bv[N1] * args.bv[N1+1];
62 var cl_I b23 = args.bv[N1+2] * args.bv[N1+3];
64 *T = b23 * (args.bv[N1+1] * args.pv[N1]
66 + b01 * (args.bv[N1+3] * p012
67 + args.bv[N1+2] * p0123);
71 var uintL Nm = (N1+N2)/2; // midpoint
74 eval_pb_series_aux(N1,Nm,args,&LP,&LB,<);
75 // Compute right part.
77 eval_pb_series_aux(Nm,N2,args,(P?&RP:(cl_I*)0),&RB,&RT);
78 // Put together partial results.
79 if (P) { *P = LP*RP; }
81 // S = LS + LP * RS, so T = RB*LT + LB*LP*RT.
82 *T = RB*LT + LB*LP*RT;
88 const cl_LF eval_rational_series (uintL N, const cl_pb_series& args, uintC len)
91 return cl_I_to_LF(0,len);
93 eval_pb_series_aux(0,N,args,NULL,&B,&T);
94 return cl_I_to_LF(T,len) / cl_I_to_LF(B,len);
96 // Bit complexity (if p(n), q(n), a(n), b(n) have length O(log(n))):