Search in sources :

Example 1 with IntObjPair

use of suite.primitive.adt.pair.IntObjPair 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 IntObjPair

use of suite.primitive.adt.pair.IntObjPair in project suite by stupidsing.

the class HtmlUtil method parse.

public HtmlNode parse(String in) {
    List<IntIntPair> pairs = new ArrayList<>();
    int pos0, pos1 = 0;
    while (0 <= (pos0 = in.indexOf("<", pos1)) && 0 <= (pos1 = in.indexOf(">", pos0 + 1))) pairs.add(IntIntPair.of(pos0, ++pos1));
    Fun<String, IntObjPair<String>> getNameFun = tag -> {
        int p0 = 1, p1 = p0 + 1, px = tag.length() - 1;
        char first = tag.charAt(p1);
        char last = tag.charAt(px - 1);
        int d;
        if (first == '!')
            return IntObjPair.of(0, tag);
        else {
            if (first == '/') {
                p1++;
                d = -1;
            } else if (last == '/') {
                px--;
                d = 0;
            } else
                d = 1;
            int ps0 = tag.indexOf(' ');
            int ps1 = 0 <= ps0 ? ps0 : px;
            return IntObjPair.of(d, tag.substring(p1, ps1));
        }
    };
    Deque<HtmlNode> deque = new ArrayDeque<>(List.of(new HtmlNode(null)));
    int prevp = 0;
    for (IntIntPair pair : pairs) {
        HtmlNode htmlNode = deque.element(), htmlNode1;
        int p0 = pair.t0;
        int px = pair.t1;
        htmlNode.children.add(new HtmlNode(in.substring(prevp, p0)));
        String tag = in.substring(p0, px);
        IntObjPair<String> dn = getNameFun.apply(tag);
        int d = dn.t0;
        String name = dn.t1;
        if (d == -1)
            while (!deque.isEmpty() && !String_.equals(getNameFun.apply(deque.pop().tag).t1, name)) ;
        else {
            htmlNode.children.add(htmlNode1 = new HtmlNode(tag));
            if (d == 1)
                deque.push(htmlNode1);
        }
        prevp = px;
    }
    return deque.pop();
}
Also used : List(java.util.List) IntObjPair(suite.primitive.adt.pair.IntObjPair) BiMap(suite.adt.map.BiMap) IntIntPair(suite.primitive.adt.pair.IntIntPair) HashBiMap(suite.adt.map.HashBiMap) ArrayDeque(java.util.ArrayDeque) Deque(java.util.Deque) Fun(suite.util.FunUtil.Fun) ArrayList(java.util.ArrayList) IntObjPair(suite.primitive.adt.pair.IntObjPair) ArrayList(java.util.ArrayList) ArrayDeque(java.util.ArrayDeque) IntIntPair(suite.primitive.adt.pair.IntIntPair)

Example 3 with IntObjPair

use of suite.primitive.adt.pair.IntObjPair 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

IntObjPair (suite.primitive.adt.pair.IntObjPair)3 Fun (suite.util.FunUtil.Fun)3 Predicate (java.util.function.Predicate)2 Pattern (suite.BindArrayUtil.Pattern)2 Opt (suite.adt.Opt)2 Fixie3 (suite.adt.pair.Fixie_.Fixie3)2 OpGroup (suite.math.sym.Express.OpGroup)2 Ring (suite.math.sym.Sym.Ring)2 Int (suite.node.Int)2 Node (suite.node.Node)2 SwitchNode (suite.node.io.SwitchNode)2 Int_Obj (suite.primitive.IntPrimitives.Int_Obj)2 Obj_Int (suite.primitive.IntPrimitives.Obj_Int)2 Iterate (suite.util.FunUtil.Iterate)2 Fun2 (suite.util.FunUtil2.Fun2)2 ArrayDeque (java.util.ArrayDeque)1 ArrayList (java.util.ArrayList)1 Deque (java.util.Deque)1 List (java.util.List)1 BiMap (suite.adt.map.BiMap)1