9 numeric g =
a, s = 1, t = 0, g1 = p, s1 = 0, t1 = 1;
16 o[i++] = g - iquo(g,g1)*g1;
17 o[i++] = s - iquo(g,g1)*s1;
18 o[i++] = t - iquo(g,g1)*t1;
39 numeric q = iquo(
a, b);
40 numeric amb = mod(
a, b);
44 numeric xqx = x1 - q * x0;
55 for (
int i = 0; i < n.size(); i++) prod *= n[i];
58 for (
int i = 0; i < n.size(); i++) {
59 numeric p = iquo(prod, n[i]);
60 sm +=
a[i] *
mulInv(p, n[i]) * p;
67 numeric prod = 1, res = 0, resQ = 1, i, temp, steps = 0, resQprev = 0;
68 for(
int i=0; i<aa.size(); i++) {
72 if(resQ == resQprev)
return resQ;
76 throw Error(
"RationalReconstruct unstable!");
81 ex
Thiele(
const exvector & keys,
const exvector & values,
const ex &
d) {
84 for(
int i=0; i<n; i++) coeffs[i] = 0;
85 for(
int i=0; i<n; i++) {
86 auto temp = values[i];
87 for(
int j=0; j<i; j++) {
88 if(temp.is_equal(coeffs[j])) {
92 temp = (keys[i] - keys[j])/(temp - coeffs[j]);
96 throw Error(
"Thiele unstable!");
98 ex result = coeffs[n];
99 for(
int i=n-1; i>=0; i--) result = coeffs[i] + (
d - keys[i])/result;
100 result = normal(result);
105 ex
Newton(
const exvector & keys,
const exvector & values,
const ex &
d,
const ex factor) {
108 for(
int i=0; i<n; i++) coeffs[i] = 0;
109 for(
int i=0; i<n; i++) {
110 auto temp = values[i] * factor.subs(
d==keys[i]);
113 for(
int j=0; j<i; j++) {
114 if(temp.is_equal(coeffs[j])) {
118 temp = (temp - coeffs[j])/(keys[i] - keys[j]);
124 throw Error(
"Newton unstable!");
126 ex result = coeffs[n];
127 for(
int i=n-1; i>=0; i--) result = coeffs[i] + (
d - keys[i]) * result;
128 result = normal(result/factor);
class used to wrap error message
numeric RationalReconstruct(numeric a, numeric p)
ex Thiele(const exvector &keys, const exvector &values, const ex &d)
numeric ChineseRemainder(std::vector< numeric > a, std::vector< numeric > n)
numeric mulInv(numeric a, numeric b)
ex Newton(const exvector &keys, const exvector &values, const ex &d, const ex factor=1)