Examples of FromChildToParentIterator


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

        this.simplifications = new UnitarySimplifyTransformation(dimension, tokenTransformer);
    }

    @Override
    public Tensor transform(Tensor t) {
        FromChildToParentIterator iterator = new FromChildToParentIterator(t);
        Tensor c;
        while ((c = iterator.next()) != null) {
            if (c instanceof SimpleTensor) {
                // Tr[T_a] = 0
                if (((SimpleTensor) c).getName() == unitaryMatrix && c.getIndices().getOfType(matrixType).getFree().size() == 0)
                    iterator.set(Complex.ZERO);
            } else if (c instanceof Product) {
                //selecting unitary matrices from product
                //extracting trace combinations from product
                Product product = (Product) c;
                int sizeOfIndexless = product.sizeOfIndexlessPart();
                ProductContent productContent = product.getContent();
                PrimitiveSubgraph[] subgraphs
                        = PrimitiveSubgraphPartition.calculatePartition(productContent, matrixType);

                //no unitary matrices in product
                if (subgraphs.length == 0)
                    continue;

                //positions of unitary matrices
                IntArrayList positionsOfMatrices = new IntArrayList();
                //calculated traces
                ProductBuilder calculatedTraces = new ProductBuilder();

                out:
                for (PrimitiveSubgraph subgraph : subgraphs) {
                    //not a trace
                    if (subgraph.getGraphType() != GraphType.Cycle)
                        continue;

                    //positions of unitary matrices
                    int[] partition = subgraph.getPartition();
                    for (int i = partition.length - 1; i >= 0; --i) {
                        partition[i] = sizeOfIndexless + partition[i];
                        //contains not only unitary matrices
                        if (!isUnitaryMatrix(product.get(partition[i]), unitaryMatrix))
                            continue out;
                    }

                    //calculate trace
                    calculatedTraces.put(traceOfProduct(product.select(partition)));
                    positionsOfMatrices.addAll(partition);
                }
                //compiling the result
                c = product.remove(positionsOfMatrices.toArray());
                c = multiply(c, calculatedTraces.build());
                iterator.set(simplifications.transform(c));
            }
        }
        return simplifications.transform(iterator.result());
    }
View Full Code Here

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

                if (isN(current)) {
                    ib.append(current);
                    ++count;
                } else {
                    if (TensorUtils.isScalar(current)) {
                        FromChildToParentIterator iterator = new FromChildToParentIterator(current);
                        Tensor temp;
                        boolean flag = false;
                        while ((temp = iterator.next()) != null) {
                            if (isN(temp)) {
                                flag = true;
                                break;
                            }
                        }
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 doFactor specifies whether to cancel factors in the result
     * @return result
     */
    //todo make two separate methods
    public static Tensor together(Tensor t, boolean doFactor) {
        FromChildToParentIterator iterator = new FromChildToParentIterator(t);
        Tensor c;
        while ((c = iterator.next()) != null) {
            if (c instanceof Sum)
                iterator.set(togetherSum(c, doFactor));
            if (c instanceof Product)
                iterator.set(collectScalarFactorsInProduct((Product) c));
        }
        return iterator.result();
    }
View Full Code Here

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

        if (tensor.getClass() == SimpleTensor.class) {
            Tensor temp = rule.differentiateSimpleTensor((SimpleTensor) tensor);
            return applyTransformations(temp, transformations);
        }
        if (tensor.getClass() == TensorField.class) {
            FromChildToParentIterator iterator = new FromChildToParentIterator(tensor);
            Tensor c;
            while ((c = iterator.next()) != null)
                if (c.getClass() == SimpleTensor.class)
                    if (((SimpleTensor) c).getName() == rule.var.getName())
                        throw new UnsupportedOperationException();
            return Complex.ZERO;
        }
View Full Code Here

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

        }
        return iterator.result();
    }

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

        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(JasFactor.factor(c.get(i)));
                        } else if (pb != null)
                            pb.put(c.get(i));
                    }
                    iterator.set(pb == null ? c : pb.build());
                }
            } else
                iterator.set(JasFactor.factor(c));
        }
        return iterator.result();
    }
View Full Code Here

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

//        return iterator.result();
    }


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

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

    public SymbolsGenerator(String name, Tensor... forbiddenTensors) {
        checkName(name);
        this.name = name;

        Set<String> set = new HashSet<>();
        FromChildToParentIterator iterator;
        for (Tensor f : forbiddenTensors) {
            iterator = new FromChildToParentIterator(f);
            Tensor c;
            while ((c = iterator.next()) != null)
                if (TensorUtils.isSymbol(c))
                    set.add(c.toString());
        }
        this.usedNames = new String[set.size()];
        int i = -1;
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
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.