Package cc.redberry.core.utils

Examples of cc.redberry.core.utils.IntArrayList


        return namespace.get(nextInt(namespace.size()));
    }

    private NameDescriptor nextNameDescriptor(StructureOfIndices typeStructure) {
        //search
        IntArrayList positions = new IntArrayList();
        for (int i = namespace.size() - 1; i >= 0; --i)
            if (namespace.get(i).getStructureOfIndices().equals(typeStructure))
                positions.add(i);
        if (!positions.isEmpty())
            return namespace.get(positions.get(random.nextInt(positions.size())));

        if (!generateNewDescriptors)
            throw new IllegalArgumentException("No descriptor for such structure.");

        //create new nameDescriptor
View Full Code Here


        Indices factorIndices = new IndicesBuilder().append(factors).getIndices();
        TIntHashSet dummies = new TIntHashSet(IndicesUtils.getIntersections(
                factorIndices.getUpper().toArray(), factorIndices.getLower().toArray()));
        SimpleIndices currentFactorIndices;
        IntArrayList from = new IntArrayList(), to = new IntArrayList();
        ArrayList<Tensor> kroneckers = new ArrayList<>();
        int j, index, newIndex;
        IndexGeneratorImpl generator = new IndexGeneratorImpl(TensorUtils.getAllIndicesNamesT(tensor).toArray());
        for (int i = 0; i < factors.length; ++i) {
            from.clear();
            to.clear();
            currentFactorIndices = IndicesFactory.createSimple(null, factors[i].getIndices());

            for (j = currentFactorIndices.size() - 1; j >= 0; --j) {
                index = currentFactorIndices.get(j);
                if (freeIndices.contains(getNameWithType(index))) {
                    newIndex = setRawState(getRawStateInt(index), generator.generate(getType(index)));
                    from.add(index);
                    to.add(newIndex);
                    kroneckers.add(Tensors.createKronecker(index, inverseIndexState(newIndex)));
                } else if (IndicesUtils.getState(index) && dummies.contains(getNameWithType(index))) {
                    newIndex = setRawState(getRawStateInt(index), generator.generate(getType(index)));
                    from.add(index);
                    to.add(newIndex);
                    kroneckers.add(Tensors.createKronecker(index, inverseIndexState(newIndex)));
                }
            }

            factors[i] = applyDirectMapping(factors[i],
                    new StateSensitiveMapping(from.toArray(), to.toArray()));
        }

        //temp check
//            factorIndices = new IndicesBuilder().append(factors).getIndices();
//            assert factorIndices.size() == factorIndices.getFree().size();
View Full Code Here

     * @param degree     largest integer moved by the generators plus one or bigger
     * @return orbit of specified point
     */
    public static IntArrayList getOrbitList(Collection<Permutation> generators, int point, int degree) {
        //orbit as list
        IntArrayList orbitList = new IntArrayList();
        orbitList.add(point);
        if (generators.isEmpty())
            return orbitList;//throw new IllegalArgumentException("Empty generators.");
        //seen points
        BitArray seen = new BitArray(degree);
        seen.set(point);
        int imageOfPoint;
        //main loop over all points in orbit
        for (int orbitIndex = 0; orbitIndex < orbitList.size(); ++orbitIndex) {
            //loop over all generators of a group
            for (Permutation generator : generators) {
                //image of point under permutation
                imageOfPoint = generator.newIndexOf(orbitList.get(orbitIndex));
                //testing whether current permutation maps orbit point into orbit or not
                if (!seen.get(imageOfPoint)) {
                    //adding new point to orbit
                    orbitList.add(imageOfPoint);
                    //filling Schreier vector
                    seen.set(imageOfPoint);
                }
            }
        }
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, factorizationEngine);
            if (remainder instanceof Sum) {
                SumBuilder sb = new SumBuilder(remainder.size());
                for (Tensor tt : remainder)
                    sb.put(factorSymbolicTerms(tt, factorizationEngine));
View Full Code Here

        ArrayList<int[]> orbits = new ArrayList<>();
        Arrays.fill(positionsInOrbit, -1);
        int seenCount = 0, orbitsIndex = 0;
        while (seenCount < positionsInOrbit.length) {
            //orbit as list
            IntArrayList orbitList = new IntArrayList();
            int point = -1;
            //first not seen point
            for (int i = 0; i < positionsInOrbit.length; ++i)
                if (positionsInOrbit[i] == -1) {
                    point = i;
                    break;
                }
            assert point != -1;
            orbitList.add(point);
            ++seenCount;
            positionsInOrbit[point] = orbitsIndex;
            int imageOfPoint;
            //main loop over all points in orbit
            for (int orbitIndex = 0; orbitIndex < orbitList.size(); ++orbitIndex) {
                //loop over all generators of a group
                for (Permutation generator : generators) {
                    //image of point under permutation
                    imageOfPoint = generator.newIndexOf(orbitList.get(orbitIndex));
                    //testing whether current permutation maps orbit point into orbit or not
                    if (positionsInOrbit[imageOfPoint] == -1) {
                        ++seenCount;
                        positionsInOrbit[imageOfPoint] = orbitsIndex;
                        //adding new point to orbit
                        orbitList.add(imageOfPoint);
                    }
                }
            }
            orbits.add(orbitList.toArray());
            ++orbitsIndex;
        }
        return orbits.toArray(new int[orbits.size()][]);
    }
View Full Code Here

        return Tensors.sum(parts[0], parts[1]);
    }

    private static Tensor[] reIm(Tensor sum) {
        IntArrayList im = new IntArrayList(sum.size());
        for (int i = sum.size() - 1; i >= 0; --i) {
            if (sum.get(i) instanceof Complex && !((Complex) sum.get(i)).getImaginary().isZero())
                im.add(i);
            else if (sum.get(i) instanceof Product && !((Product) sum.get(i)).getFactor().getImaginary().isZero())
                im.add(i);
        }
        Tensor[] parts = new Tensor[2];
        int[] positions = im.toArray();
        parts[0] = ((Sum) sum).select(positions);
        parts[1] = ((Sum) sum).remove(positions);
        return parts;
    }
View Full Code Here

            if (permutation[start] == start) {
                ++counter;
                seen.set(start);
                continue;
            }
            IntArrayList cycle = new IntArrayList();
            while (!seen.get(start)) {
                seen.set(start);
                ++counter;
                cycle.add(start);
                start = permutation[start];
            }
            cycles.add(cycle.toArray());
        }
        return cycles.toArray(new int[cycles.size()][]);
    }
View Full Code Here

         * S1:
         * (a+b)*c + a*d + b*d -> (a+b)*c + (a+b)*d
         */
        Tensor temp = tensor;
        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 = factorSymbolicTerms(sb.build(), factorizationEngine);
            if (isProductOfSums(withoutSumsTerm)) {
                temp = Tensors.sum(temp, withoutSumsTerm);
                if (!(temp instanceof Sum))
View Full Code Here

                    closed = true;
                    return null;
                }

                int[] bijectionNew = bijection.clone();
                IntArrayList addedBijectionsNew = addedBijections.clone();

                int j, fromTensorIndex, targetTensorIndex;
                long fromContraction, targetContraction;
                PermutationInfo currentInfo = firstInfo;
                do
                    for (j = 0; j < currentInfo.fromContractions.length; ++j) {
                        //Vse tut cherez jopu mi napisali, no vrode pravil'no
                        fromContraction = currentInfo.fromContractions[j];
                        targetContraction = currentInfo.targetContractions[currentInfo.permutation[j]];

                        assert getFromIndexId(fromContraction) == getFromIndexId(targetContraction);

                        fromTensorIndex = getToTensorIndex(fromContraction);
                        targetTensorIndex = getToTensorIndex(targetContraction);

                        if (getToIndexId(fromContraction) != getToIndexId(targetContraction)) {
                            if (!currentInfo.nextAndResetRightChain()) {
                                closed = true;
                                return null;
                            }
                            continue MAIN;
                        }

//                        assert fromTensorIndex != -1;

                        if (targetTensorIndex == -1) { //Not contracted index of target (but from is contracted with some tensor)
                            if (!currentInfo.nextAndResetRightChain()) {
                                closed = true;
                                return null;
                            }
                            continue MAIN;
                        }

                        if (!weakMatch(fromData[fromTensorIndex], targetData[targetTensorIndex])) {
                            if (!currentInfo.nextAndResetRightChain()) {
                                closed = true;
                                return null;
                            }
                            continue MAIN;
                        }

                        if (bijectionNew[fromTensorIndex] == -1) {
                            //Try addAll new bijection
                            if (alreadyContains(bijectionNew, targetTensorIndex)) {
                                if (!currentInfo.nextAndResetRightChain()) {
                                    closed = true;
                                    return null;
                                }
                                continue MAIN;
                            }
                            bijectionNew[fromTensorIndex] = targetTensorIndex;
                            addedBijectionsNew.add(fromTensorIndex);
                        } else if (bijectionNew[fromTensorIndex] != targetTensorIndex) { //Testing weather new bijection is consistent with already exists
                            if (!currentInfo.nextAndResetRightChain()) {
                                closed = true;
                                return null;
                            }
                            continue MAIN;
                        }
                    }
                while ((currentInfo = currentInfo.next) != null);

                innerPort = new InnerPort(bijectionNew, addedBijectionsNew.toArray());
            } while (true);
        }
View Full Code Here

            if (permutation[start] == start) {
                ++counter;
                seen.set(start);
                continue;
            }
            IntArrayList cycle = new IntArrayList();
            while (!seen.get(start)) {
                seen.set(start);
                ++counter;
                cycle.add(start);
                start = permutation[start];
            }
            cycles.add(cycle.toArray());
        }
        return cycles.toArray(new int[cycles.size()][]);
    }
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.