Examples of FromChildToParentIterator


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

        assertType(type);
        return inverseOrderOfMatrices1(t, type);
    }

    private static Tensor inverseOrderOfMatrices1(Tensor t, IndexType type) {
        FromChildToParentIterator iterator = new FromChildToParentIterator(t);
        Tensor c;
        while ((c = iterator.next()) != null)
            if (c instanceof Product)
                iterator.set(inverseOrderInProduct((Product) c, type));
        return iterator.result();
    }
View Full Code Here

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

        leviCivitaSimplifications = getLeviCivitaSubstitutions();
    }

    @Override
    public Tensor transform(Tensor t) {
        FromChildToParentIterator iterator = new FromChildToParentIterator(t);
        Tensor c;
        while ((c = iterator.next()) != null) {
            if (c instanceof SimpleTensor
                    && ((SimpleTensor) c).getName() == leviCivita
                    && c.getIndices().size() != c.getIndices().getFree().size()) {
                iterator.set(Complex.ZERO);
            }
            if (c instanceof Product)
                iterator.set(simplifyProduct(c));
        }
        return iterator.result();
    }
View Full Code Here

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

    @Override
    public Tensor transform(Tensor tensor) {
        //todo may be check for contains gammas
        tensor = ExpandAndEliminateTransformation.expandAndEliminate(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;
                //fast check
                boolean needTrace = false;
                for (Tensor t : current)
                    if (isGammaOrGamma5(t)) {
                        needTrace = true;
                        break;
                    }
                if (!needTrace)
                    continue;

                //selecting unitary matrices from product
                //extracting trace combinations from product
                Product product = (Product) current;
                //positions of matrices
                IntArrayList positionsOfMatrices = new IntArrayList();
                int sizeOfIndexless = product.sizeOfIndexlessPart();
                ProductContent pc = product.getContent();
                PrimitiveSubgraph[] partition
                        = PrimitiveSubgraphPartition.calculatePartition(pc, matrixType);

                //calculated traces
                ProductBuilder traces = new ProductBuilder();

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

                    int numberOfGammas = 0, numberOfGamma5s = 0;

                    Tensor gamma;
                    //actual positions in current
                    int[] positions = subgraph.getPartition();
                    assert positions.length > 1;

                    for (int i = positions.length - 1; i >= 0; --i) {
                        positions[i] = positions[i] + sizeOfIndexless;
                        gamma = product.get(positions[i]);
                        if (gamma instanceof SimpleTensor) {
                            if (((SimpleTensor) gamma).getName() == gammaName)
                                ++numberOfGammas;
                            else if (((SimpleTensor) gamma).getName() == gamma5Name)
                                ++numberOfGamma5s;
                            else
                                //not a gamma matrix
                                continue traces;
                        } else {
                            //not a gamma matrix
                            continue traces;
                        }
                    }

                    //early terminations
                    if (numberOfGammas % 2 == 1
                            || (numberOfGammas == 2 && numberOfGamma5s % 2 == 1)) {
                        iterator.set(Complex.ZERO);
                        continue out;
                    }
                    if (numberOfGammas == 0 && numberOfGamma5s % 2 == 1) {
                        iterator.set(Complex.ZERO);
                        continue out;
                    }

                    positionsOfMatrices.addAll(positions);
                    if (numberOfGamma5s == 0)
                        traces.put(traceWithout5(product.select(positions), numberOfGammas));
                    else {
                        //early check
                        if (numberOfGammas == 0) {
                            //numberOfGamma5s % 2 == 0
                            traces.put(Complex.FOUR);
                            continue traces;
                        }


                        //eliminating excess products of gamma5s
                        if (numberOfGamma5s > 1) {
                            //take into account odd number of swaps
                            boolean sign = false;
                            //product of gammas as ordered array (will be filled without excess gamma5s)
                            final SimpleTensor[] orderedProduct = new SimpleTensor[numberOfGammas + (numberOfGamma5s % 2 == 0 ? 0 : 1)];
                            int counter = -1;

                            //index of tensor in product content, which is contracted with current gamma5
                            int positionOfPreviousGamma = -2;

                            SimpleTensor currentGamma;
                            for (int positionOfGamma = 0; positionOfGamma < positions.length; ++positionOfGamma) {
                                currentGamma = (SimpleTensor) product.get(positions[positionOfGamma]);
                                if (currentGamma.getName() == gamma5Name) {
                                    //adding one gamma5 if they are odd number
                                    if (positionOfPreviousGamma == -2) {
                                        if (numberOfGamma5s % 2 == 1) {
                                            orderedProduct[++counter] = currentGamma;
                                            positionOfPreviousGamma = -1;
                                        } else {
                                            positionOfPreviousGamma = positionOfGamma;
                                        }
                                        continue;
                                    }
                                    if (positionOfPreviousGamma == -1)
                                        positionOfPreviousGamma = positionOfGamma;
                                    else {
                                        //odd number of swaps
                                        if ((positionOfGamma - positionOfPreviousGamma) % 2 == 0)
                                            sign ^= true;
                                        positionOfPreviousGamma = -1;
                                    }
                                } else
                                    orderedProduct[++counter] = currentGamma;
                            }

                            //fixing new indices contractions
                            int u = 0, l = 0;
                            for (int i = 0; ; ++i) {
                                if (i == orderedProduct.length - 1) {
                                    orderedProduct[i] = setMatrixIndices(orderedProduct[i], u, 0);
                                    break;
                                }
                                orderedProduct[i] = setMatrixIndices(orderedProduct[i], u, ++l);
                                u = l;
                            }

                            Tensor withoutExcessGamma5s = multiply(orderedProduct);

                            if (numberOfGamma5s % 2 == 0)
                                withoutExcessGamma5s = traceWithout5(withoutExcessGamma5s, numberOfGammas);
                            else {
                                withoutExcessGamma5s = traceWith5(withoutExcessGamma5s, numberOfGammas);
                                withoutExcessGamma5s = simplifyLeviCivita.transform(withoutExcessGamma5s);
                            }

                            if (sign)
                                withoutExcessGamma5s = negate(withoutExcessGamma5s);
                            traces.put(withoutExcessGamma5s);
                        } else
                            traces.put(traceWith5(product.select(positions), numberOfGammas));
                    }
                }
                if (positionsOfMatrices.isEmpty())
                    continue out;

                //final simplifications
                traces.put(product.remove(positionsOfMatrices.toArray()));
                current = traces.build();
                current = ExpandAndEliminateTransformation.expandAndEliminate(current);
                current = deltaTrace.transform(current);
                if (simplifyLeviCivita != null)
                    current = simplifyLeviCivita.transform(current);
                iterator.set(current);
            }
        }
        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,
                                                             OutputPort<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

        //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

        assertType(type);
        return inverseOrderOfMatrices1(t, type);
    }

    private static Tensor inverseOrderOfMatrices1(Tensor t, IndexType type) {
        FromChildToParentIterator iterator = new FromChildToParentIterator(t);
        Tensor c;
        while ((c = iterator.next()) != null)
            if (c instanceof Product)
                iterator.set(inverseOrderInProduct((Product) c, type));
        return iterator.result();
    }
View Full Code Here

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

     *
     * @param t tensor
     * @return the numerical value of tensor
     */
    public static Tensor toNumeric(Tensor t) {
        FromChildToParentIterator iterator = new FromChildToParentIterator(t);
        Tensor c;
        while ((c = iterator.next()) != null)
            if (c instanceof Complex)
                iterator.set(((Complex) c).getNumericValue());

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

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

    }

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

        TreeIterator iterator = new FromParentToChildIterator(sum);
        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(factorSum1(c.get(i), factorizationEngine));
                        } else if (pb != null)
                            pb.put(c.get(i));
                    }
                    iterator.set(pb == null ? c : pb.build());
                } else iterator.set(c);
            } else
                iterator.set(factorSum1(c, factorizationEngine));
        }
        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.