use of suite.math.sym.Express.OpGroup 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;
}
use of suite.math.sym.Express.OpGroup in project suite by stupidsing.
the class Fractional method format.
public Node format(Fract<I> fract) {
OpGroup add = ex.add;
OpGroup mul = ex.mul;
Fun2<I, I, Node> f = (n, d) -> {
Node i0 = format_.apply(n);
Node i1 = format_.apply(d);
return mul.apply(i0, mul.inverse(i1));
};
I n_ = fract.t0;
I d_ = fract.t1;
I nn = neg_.apply(n_);
if (0 <= sgn_.apply(n_))
return f.apply(n_, d_);
else
return add.inverse(f.apply(nn, d_));
}
use of suite.math.sym.Express.OpGroup in project suite by stupidsing.
the class Polynomial 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