Examples of FromChildToParentIterator


Examples of cc.redberry.core.tensor.iterator.FromChildToParentIterator

    public Tensor transform(Tensor t) {
        return collectNonScalars(t);
    }

    public static Tensor collectNonScalars(Tensor t) {
        FromChildToParentIterator iterator = new FromChildToParentIterator(t);
        Tensor c;
        while ((c = iterator.next()) != null)
            if (c instanceof Sum) {
                //TODO add check whether we need to do this transformation
                SumBuilderSplitingScalars sbss = new SumBuilderSplitingScalars(c.size());
                for (Tensor tt : c)
                    sbss.put(tt);
                iterator.set(sbss.build());
            }
        return iterator.result();
    }
View Full Code Here

Examples of cc.redberry.core.tensor.iterator.FromChildToParentIterator

     * @param tensor        tensor
     * @param traverseGuide specifies parts of expression to apply the transformation
     * @return the result
     */
    public static Tensor collectScalarFactors(Tensor tensor, TraverseGuide traverseGuide) {
        FromChildToParentIterator iterator = new FromChildToParentIterator(tensor, traverseGuide);
        Tensor current;
        while ((current = iterator.next()) != null) {
            if (current instanceof Product)
                iterator.set(collectScalarFactorsInProduct((Product) current));
        }
        return iterator.result();
    }
View Full Code Here

Examples of cc.redberry.core.tensor.iterator.FromChildToParentIterator

        }
        return iterator.result();
    }

    private static Tensor factorSymbolicTerm(Tensor sum, FactorizationEngine factorizationEngine) {
        TreeIterator iterator = new FromChildToParentIterator(sum);
        Tensor c;
        while ((c = iterator.next()) != null)
            if (c instanceof Sum)
                iterator.set(factorOut(c, factorizationEngine));

        iterator = new FromParentToChildIterator(iterator.result());
        while ((c = iterator.next()) != null) {
            if (!(c instanceof Sum))
                continue;
            if (needTogether(c)) {
                c = TogetherTransformation.together(c, true);
                if (c instanceof Product) {
                    TensorBuilder pb = null;
                    for (int i = c.size() - 1; i >= 0; --i) {
                        if (c.get(i) instanceof Sum) {
                            if (pb == null) {
                                pb = c.getBuilder();
                                for (int j = c.size() - 1; j > i; --j)
                                    pb.put(c.get(j));
                            }
                            pb.put(factorizationEngine.factor(c.get(i)));
                        } else if (pb != null)
                            pb.put(c.get(i));
                    }
                    iterator.set(pb == null ? c : pb.build());
                } else iterator.set(c);
            } else
                iterator.set(factorizationEngine.factor(c));
        }
        return iterator.result();
    }
View Full Code Here

Examples of cc.redberry.core.tensor.iterator.FromChildToParentIterator

    static Tensor factorOut(Tensor tensor) {
        return factorOut(tensor, JasFactor.ENGINE);
    }

    static Tensor factorOut(Tensor tensor, FactorizationEngine factorizationEngine) {
        FromChildToParentIterator iterator = new FromChildToParentIterator(tensor);
        Tensor c;
        while ((c = iterator.next()) != null)
            if (c instanceof Sum)
                iterator.set(factorOut1(c, factorizationEngine));
        return iterator.result();
    }
View Full Code Here

Examples of cc.redberry.core.tensor.iterator.FromChildToParentIterator

        this(varsToIndicator(vars));
    }

    @Override
    public Tensor transform(Tensor t) {
        FromChildToParentIterator iterator = new FromChildToParentIterator(t);
        Tensor c;

        while ((c = iterator.next()) != null)
            if (powerExpandApplicable(c, toExpandIndicator))
                iterator.set(Tensors.multiply(powerExpandToArray1(c, toExpandIndicator)));

        return iterator.result();
    }
View Full Code Here

Examples of cc.redberry.core.tensor.iterator.FromChildToParentIterator

     * @param tensor     tensors
     * @param setOfNames int set of simple tensors names
     * @return true if tensor contains at least one of simple tensor with name that contains in the set
     */
    public static boolean containsSimpleTensors(Tensor tensor, TIntSet setOfNames) {
        FromChildToParentIterator iterator = new FromChildToParentIterator(tensor);
        Tensor current;
        boolean contains = false;
        while ((current = iterator.next()) != null)
            if (current instanceof SimpleTensor && setOfNames.contains(((SimpleTensor) current).getName())) {
                contains = true;
                break;
            }
        return contains;
View Full Code Here

Examples of cc.redberry.core.tensor.iterator.FromChildToParentIterator

     * @see LocalSymbolsProvider
     */
    public static Expression[] generateReplacementsOfScalars(Tensor tensor,
                                                             OutputPortUnsafe<SimpleTensor> generatedCoefficients) {
        THashSet<Tensor> scalars = new THashSet<>();
        FromChildToParentIterator iterator = new FromChildToParentIterator(tensor);
        Tensor c;
        while ((c = iterator.next()) != null)
            if (c instanceof Product)
                scalars.addAll(Arrays.asList(((Product) c).getContent().getScalars()));

        Expression[] replacements = new Expression[scalars.size()];
        int i = -1;
View Full Code Here

Examples of cc.redberry.core.tensor.iterator.FromChildToParentIterator

    private ComplexConjugateTransformation() {
    }

    @Override
    public Tensor transform(Tensor t) {
        FromChildToParentIterator iterator = new FromChildToParentIterator(t);
        Tensor c;
        while ((c = iterator.next()) != null)
            if (c instanceof Complex)
                iterator.set(((Complex) c).conjugate());
        return iterator.result();
    }
View Full Code Here

Examples of cc.redberry.core.tensor.iterator.FromChildToParentIterator

        //processing equations
        int i;
        for (i = 0; i < equations.length; ++i) {
            Expression eq = equations[i];
            //iterating over the whole equation
            FromChildToParentIterator iterator = new FromChildToParentIterator(eq);
            Tensor t;
            while ((t = iterator.next()) != null) {
                if (!(t instanceof Product) || t.getIndices().size() == 0)
                    continue;
                //scalars content
                Tensor[] scalars = ((Product) t).getContent().getScalars();
                for (Tensor scalar : scalars) {
View Full Code Here

Examples of cc.redberry.core.tensor.iterator.FromChildToParentIterator

    @Override
    public Tensor transform(Tensor tensor) {
        //todo check for contains gammas
        tensor = ExpandTransformation.expand(tensor, EliminateMetricsTransformation.ELIMINATE_METRICS);
        tensor = EliminateMetricsTransformation.eliminate(tensor);
        FromChildToParentIterator iterator = new FromChildToParentIterator(tensor);
        Tensor current;
        out:
        while ((current = iterator.next()) != null) {
            if (isGammaOrGamma5(current)
                    && current.getIndices().getFree().size(matrixType) == 0) {
                iterator.set(Complex.ZERO);
            } else if (current instanceof Product) {
                if (current.getIndices().getFree().size(matrixType) != 0)
                    continue;
                Product product = (Product) current;
                ProductContent pc = product.getContent();
                int sizeOfIndexless = product.sizeOfIndexlessPart();
                PrimitiveSubgraph[] partition
                        = PrimitiveSubgraphPartition.calculatePartition(pc, matrixType);

                for (PrimitiveSubgraph subgraph : partition) {
                    if (subgraph.getGraphType() != GraphType.Cycle)
                        continue;

                    int[] positions = subgraph.getPartition();
                    //actual positions in current
                    for (int i = positions.length - 1; i >= 0; --i)
                        positions[i] = positions[i] + sizeOfIndexless;

                    int[] gg = calculateGammasInProduct(product.select(positions));
                    if (gg[0] + gg[1] != positions.length)
                        continue;

                    assert positions.length != 0;

                    if (positions.length == 1) {
                        iterator.set(Complex.ZERO);
                        continue out;
                    }

                    int gammasCount = gg[0];
                    int gamma5Count = gg[1];

                    if (gammasCount == 0) {
                        if (gamma5Count % 2 == 0) {
                            iterator.set(multiply(product.remove(positions), Complex.FOUR));
                            continue out;
                        } else {
                            iterator.set(Complex.ZERO);
                            continue out;
                        }
                    }

                    if (gamma5Count == 0 && gammasCount % 2 == 1) {
                        iterator.set(Complex.ZERO);
                        continue out;
                    }

                    if (gamma5Count % 2 == 1 && gammasCount % 2 == 1) {
                        iterator.set(Complex.ZERO);
                        continue out;
                    }

                    if (gamma5Count == 0)
                        current = traceWithout5(current, gammasCount);
                    else
                        current = trace5((Product) current, gammasCount, gamma5Count);

                }
                //todo d_i^i = 4
                iterator.set(current);
            }
        }
        return iterator.result();
    }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.