Package cc.redberry.core.utils

Examples of cc.redberry.core.utils.IntArrayList


                //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);
View Full Code Here


        Tensor c;
        while ((c = iterator.next()) != null) {
            if (!(c instanceof Sum))
                continue;
            Tensor remainder = c, temp;
            IntArrayList symbolicPositions = new IntArrayList();
            for (int i = c.size() - 1; i >= 0; --i) {
                temp = c.get(i);
                if (isSymbolic(temp)) {
                    symbolicPositions.add(i);
                    if (remainder instanceof Sum)
                        remainder = ((Sum) remainder).remove(i);
                    else remainder = Complex.ZERO;
                }
            }
            Tensor symbolicPart = ((Sum) c).select(symbolicPositions.toArray());
            symbolicPart = factorSymbolicTerm(symbolicPart);
            if (remainder instanceof Sum) {
                SumBuilder sb = new SumBuilder(remainder.size());
                for (Tensor tt : remainder)
                    sb.put(factorSymbolicTerms(tt));
View Full Code Here

        /*
         * S1:
         * (a+b)*c + a*d + b*d -> (a+b)*c + (a+b)*d
         */
        int i, j = temp.size();
        IntArrayList nonProductOfSumsPositions = new IntArrayList();
        for (i = 0; i < j; ++i)
            if (!isProductOfSums(temp.get(i)))
                nonProductOfSumsPositions.add(i);
//        if (nonProductOfSumsPositions.size() == tensor.size())
//            //when tensor = a*d + b*d + ... (no sums in products)
//            return JasFactor.factor(tensor);

        /*
         * S2:
         * finding product of sums in tensor with minimal number of multipliers
         * we call this term pivot
         */
        final Term[] terms;
        Int pivotPosition = new Int();
        if (nonProductOfSumsPositions.isEmpty() || nonProductOfSumsPositions.size() == temp.size()) {
            //if nonProductOfSumsPositions.isEmpty(), then tensor already of form (a+b)*c + (a+b)*d
            //or if no any sum in terms, then tensor has form a*c + b*c
            terms = sum2SplitArray((Sum) temp, pivotPosition);
        } else {//if no, we need to rebuild tensor
            SumBuilder sb = new SumBuilder();
            for (i = nonProductOfSumsPositions.size() - 1; i >= 0; --i) {
                assert temp instanceof Sum;
                sb.put(temp.get(nonProductOfSumsPositions.get(i)));
                temp = ((Sum) temp).remove(nonProductOfSumsPositions.get(i));
            }
            Tensor withoutSumsTerm = factor(sb.build());
            if (isProductOfSums(withoutSumsTerm)) {
                temp = Tensors.sum(temp, withoutSumsTerm);
                if (!(temp instanceof Sum))
View Full Code Here

        return links;
    }

    private PrimitiveSubgraph processGraph(int pivot) {

        IntArrayList positions = new IntArrayList();
        positions.add(pivot);

        IntArrayList stack = new IntArrayList();
        stack.push(pivot);
        used.set(pivot);

        long[] contractions;
        Indices indices;

        int currentPivot, index, toTensorIndex;
        while (!stack.isEmpty()) {

            currentPivot = stack.pop();

            indices = pc.get(currentPivot).getIndices();
            contractions = fcs.contractions[currentPivot];
            for (int i = contractions.length - 1; i >= 0; --i) {
                index = indices.get(i);
                if (getType(index) != type.getType())
                    continue;

                toTensorIndex = getToTensorIndex(contractions[i]);
                if (toTensorIndex == -1 || used.get(toTensorIndex))
                    continue;
                used.set(toTensorIndex);
                positions.add(toTensorIndex);
                stack.push(toTensorIndex);
            }
        }
        return new PrimitiveSubgraph(GraphType.Graph, positions.toArray());
    }
View Full Code Here

        System.arraycopy(to, 0, allForbidden, 0, to.length);
        System.arraycopy(forbidden, 0, allForbidden, to.length, forbidden.length);
        for (i = allForbidden.length - 1; i >= 0; --i)
            allForbidden[i] = IndicesUtils.getNameWithType(allForbidden[i]);

        IntArrayList fromL = new IntArrayList(from.length), toL = new IntArrayList(to.length);
        fromL.addAll(from);
        toL.addAll(to);

        Arrays.sort(allForbidden);
        int[] forbiddenGeneratorIndices = new int[allForbidden.length + dummyIndices.size()];
        System.arraycopy(allForbidden, 0, forbiddenGeneratorIndices, 0, allForbidden.length);
        i = allForbidden.length - 1;
        for (Integer index : dummyIndices)
            forbiddenGeneratorIndices[++i] = index;

        IndexGenerator generator = new IndexGenerator(forbiddenGeneratorIndices);//also sorts allForbidden array
        for (Integer index : dummyIndices)
            if (Arrays.binarySearch(allForbidden, index) >= 0 && Arrays.binarySearch(from, index) < 0) {
                fromL.add(index);
                toL.add(generator.generate(IndicesUtils.getType(index)));
            }

        int[] _from = fromL.toArray(), _to = toL.toArray();
        ArraysUtils.quickSort(_from, _to);

        return applyIndexMapping(tensor, new IndexMapper(_from, _to));
    }
View Full Code Here

        Tensor c;
        while ((c = iterator.next()) != null) {
            if (!(c instanceof Sum))
                continue;
            Tensor remainder = c, temp;
            IntArrayList symbolicPositions = new IntArrayList();
            for (int i = c.size() - 1; i >= 0; --i) {
                temp = c.get(i);
                if (isSymbolic(temp)) {
                    symbolicPositions.add(i);
                    if (remainder instanceof Sum)
                        remainder = ((Sum) remainder).remove(i);
                    else remainder = Complex.ZERO;
                }
            }
            Tensor symbolicPart = ((Sum) c).select(symbolicPositions.toArray());
            symbolicPart = factorSymbolicTerm(symbolicPart);
            if (remainder instanceof Sum) {
                SumBuilder sb = new SumBuilder(remainder.size());
                for (Tensor tt : remainder)
                    sb.put(factorSymbolicTerms(tt));
View Full Code Here

        /*
         * S1:
         * (a+b)*c + a*d + b*d -> (a+b)*c + (a+b)*d
         */
        int i, j = temp.size();
        IntArrayList nonProductOfSumsPositions = new IntArrayList();
        for (i = 0; i < j; ++i)
            if (!isProductOfSums(temp.get(i)))
                nonProductOfSumsPositions.add(i);
//        if (nonProductOfSumsPositions.size() == tensor.size())
//            //when tensor = a*d + b*d + ... (no sums in products)
//            return JasFactor.factor(tensor);

        /*
         * S2:
         * finding product of sums in tensor with minimal number of multipliers
         * we call this term pivot
         */
        final Term[] terms;
        Int pivotPosition = new Int();
        if (nonProductOfSumsPositions.isEmpty() || nonProductOfSumsPositions.size() == temp.size()) {
            //if nonProductOfSumsPositions.isEmpty(), then tensor already of form (a+b)*c + (a+b)*d
            //or if no any sum in terms, then tensor has form a*c + b*c
            terms = sum2SplitArray((Sum) temp, pivotPosition);
        } else {//if no, we need to rebuild tensor
            SumBuilder sb = new SumBuilder();
            for (i = nonProductOfSumsPositions.size() - 1; i >= 0; --i) {
                assert temp instanceof Sum;
                sb.put(temp.get(nonProductOfSumsPositions.get(i)));
                temp = ((Sum) temp).remove(nonProductOfSumsPositions.get(i));
            }
            Tensor withoutSumsTerm = factor(sb.build());
            if (isProductOfSums(withoutSumsTerm)) {
                temp = Tensors.sum(temp, withoutSumsTerm);
                if (!(temp instanceof Sum))
View Full Code Here

        return create(dataInv, symmetries);
    }

    @Override
    public SimpleIndices getFree() {
        IntArrayList dataList = new IntArrayList();
        boolean y;
        for (int i = 0; i < data.length; i++) {
            y = true;
            for (int j = 0; j < data.length; j++)
                if (i != j && (data[i] ^ data[j]) == 0x80000000) {
                    y = false;
                    break;
                }
            if (y)
                dataList.add(data[i]);
        }
        //FAIL!
        return UnsafeIndicesFactory.createIsolatedUnsafeWithoutSort(null, dataList.toArray());
    }
View Full Code Here

        return new UpperLowerIndices(upper, lower);
    }

    @Override
    public Indices getFree() {
        IntArrayList list = new IntArrayList();
        int u, l;
        int iLower = firstLower, iUpper = 0;
        for (; iUpper < firstLower && iLower < data.length; ++iLower, ++iUpper) {
            u = data[iUpper] & 0x7FFFFFFF; //taking name with type
            l = data[iLower];
            if (u < l) {
                list.add(data[iUpper]);
                --iLower;
            } else if (l < u) {
                list.add(l);
                --iUpper;
            }
        }
        list.add(data, iUpper, firstLower - iUpper);
        list.add(data, iLower, data.length - iLower);
        return IndicesFactory.createSorted(list.toArray());
    }
View Full Code Here

            forbidden[++i] = f;
        System.arraycopy(upperLower, 0, forbidden, dummyIndices.size(), upperLower.length);


        IndexGenerator generator = new IndexGenerator(forbidden);
        IntArrayList from = new IntArrayList(), to = new IntArrayList();
        int fromIndex;
        for (i = upperLower.length - 1; i >= 0; --i) {
            fromIndex = upperLower[i];
            if (dummyIndices.contains(fromIndex)) {
                from.add(fromIndex);
                to.add(generator.generate(IndicesUtils.getType(fromIndex)));
            }
        }

        int[] _from = from.toArray(), _to = to.toArray();
        ArraysUtils.quickSort(_from, _to);

        IITransformer transformer = createTransformer(node, indicator);
        if (transformer != null)
            transformer.apply(new IndexMapper(_from, _to), new IGWrapper(generator), upper, lower);
View Full Code Here

TOP

Related Classes of cc.redberry.core.utils.IntArrayList

Copyright © 2018 www.massapicom. 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.