use of suite.math.sym.Polynomial.Poly in project suite by stupidsing.
the class DivisiblePolynomial method format.
public Node format(Poly<N> poly) {
Express ex = new Express();
OpGroup add = ex.add;
OpGroup mul = ex.mul;
Int_Obj<Node> powerFun = p -> {
Node power = mul.identity();
for (int i = 0; i < p; i++) power = mul.apply(x, power);
return power;
};
Node sum = format_.apply(n0);
for (IntObjPair<N> pair : poly.streamlet().sortByKey(Integer::compare)) {
int p = pair.t0;
Node power = p < 0 ? mul.inverse(powerFun.apply(-p)) : powerFun.apply(p);
sum = add.apply(mul.apply(format_.apply(pair.t1), power), sum);
}
return sum;
}
Aggregations