Search in sources :

Example 1 with OpGroup

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;
}
Also used : Poly(suite.math.sym.Polynomial.Poly) Ring(suite.math.sym.Sym.Ring) Predicate(java.util.function.Predicate) Pattern(suite.BindArrayUtil.Pattern) OpGroup(suite.math.sym.Express.OpGroup) Fun(suite.util.FunUtil.Fun) Node(suite.node.Node) Opt(suite.adt.Opt) Iterate(suite.util.FunUtil.Iterate) Pair(suite.adt.pair.Pair) Int_Obj(suite.primitive.IntPrimitives.Int_Obj) Fun2(suite.util.FunUtil2.Fun2) Obj_Int(suite.primitive.IntPrimitives.Obj_Int) IntObjPair(suite.primitive.adt.pair.IntObjPair) Fixie3(suite.adt.pair.Fixie_.Fixie3) Field(suite.math.sym.Sym.Field) SwitchNode(suite.node.io.SwitchNode) Int(suite.node.Int) OpGroup(suite.math.sym.Express.OpGroup) Node(suite.node.Node) SwitchNode(suite.node.io.SwitchNode)

Example 2 with OpGroup

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_));
}
Also used : Ring(suite.math.sym.Sym.Ring) Pattern(suite.BindArrayUtil.Pattern) OpGroup(suite.math.sym.Express.OpGroup) Fun(suite.util.FunUtil.Fun) Node(suite.node.Node) Opt(suite.adt.Opt) Iterate(suite.util.FunUtil.Iterate) Pair(suite.adt.pair.Pair) Fun2(suite.util.FunUtil2.Fun2) Obj_Int(suite.primitive.IntPrimitives.Obj_Int) Field(suite.math.sym.Sym.Field) SwitchNode(suite.node.io.SwitchNode) Int(suite.node.Int) OpGroup(suite.math.sym.Express.OpGroup) Node(suite.node.Node) SwitchNode(suite.node.io.SwitchNode)

Example 3 with OpGroup

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;
}
Also used : Ring(suite.math.sym.Sym.Ring) Predicate(java.util.function.Predicate) Pattern(suite.BindArrayUtil.Pattern) IntObjStreamlet(suite.primitive.streamlet.IntObjStreamlet) OpGroup(suite.math.sym.Express.OpGroup) IntObjMap(suite.primitive.adt.map.IntObjMap) Fun(suite.util.FunUtil.Fun) Node(suite.node.Node) Opt(suite.adt.Opt) Iterate(suite.util.FunUtil.Iterate) Int_Obj(suite.primitive.IntPrimitives.Int_Obj) Fun2(suite.util.FunUtil2.Fun2) Obj_Int(suite.primitive.IntPrimitives.Obj_Int) IntObjPair(suite.primitive.adt.pair.IntObjPair) Fixie(suite.adt.pair.Fixie) Fixie3(suite.adt.pair.Fixie_.Fixie3) As(suite.streamlet.As) SwitchNode(suite.node.io.SwitchNode) Int(suite.node.Int) OpGroup(suite.math.sym.Express.OpGroup) Node(suite.node.Node) SwitchNode(suite.node.io.SwitchNode)

Aggregations

Pattern (suite.BindArrayUtil.Pattern)3 Opt (suite.adt.Opt)3 OpGroup (suite.math.sym.Express.OpGroup)3 Ring (suite.math.sym.Sym.Ring)3 Int (suite.node.Int)3 Node (suite.node.Node)3 SwitchNode (suite.node.io.SwitchNode)3 Obj_Int (suite.primitive.IntPrimitives.Obj_Int)3 Fun (suite.util.FunUtil.Fun)3 Iterate (suite.util.FunUtil.Iterate)3 Fun2 (suite.util.FunUtil2.Fun2)3 Predicate (java.util.function.Predicate)2 Fixie3 (suite.adt.pair.Fixie_.Fixie3)2 Pair (suite.adt.pair.Pair)2 Field (suite.math.sym.Sym.Field)2 Int_Obj (suite.primitive.IntPrimitives.Int_Obj)2 IntObjPair (suite.primitive.adt.pair.IntObjPair)2 Fixie (suite.adt.pair.Fixie)1 Poly (suite.math.sym.Polynomial.Poly)1 IntObjMap (suite.primitive.adt.map.IntObjMap)1