Package cc.redberry.core.tensor

Examples of cc.redberry.core.tensor.Product


                wrapper.dump();
            }
            wrapper.write();
            return newSum;
        } else if (tensor instanceof Product) {
            Product p = new Product();
            TensorIterator iterator = tensor.iterator();
            Tensor current;
            Tensor temp = null;
            int[] lower = ind.getLower().copy();
            int[] upper = ind.getUpper().copy();
            int[] total = new int[length * 2];
            while (iterator.hasNext()) {
                current = iterator.next();
                if (!indicator.is(current)) {
                    p.add(current.clone());
                    continue;
                }
                if (temp == null) {
                    System.arraycopy(upper, 0, total, 0, length);
                    for (int i = length; i < length * 2; ++i)
                        total[i] = indexGenerator.generate(
                                IndicesUtils.getType(lower[i - length]));
                    temp = current;
                    continue;
                } else {
                    p.add(transform(temp, indexGenerator, IndicesFactory.createSimple(total.clone())));
                    for (int i = 0; i < length; ++i)
                        total[i] = 0x80000000 ^ total[i + length];
                    for (int i = length; i < length * 2; ++i)
                        total[i] = indexGenerator.generate(
                                IndicesUtils.getType(total[i]));
                    temp = current;
                }
            }
            if (temp != null) {
                System.arraycopy(lower, 0, total, length, length);
                p.add(transform(temp, indexGenerator, IndicesFactory.createSimple(total)));
            }
            return p;
        } else
            return tensor.clone();
    }
View Full Code Here


        //TODO discover case, when factoredNumber == 0
        if (factoredNumber.isOne())
            return term;
        if (termIsOne)
            return factoredNumber;
        return new Product(factoredNumber, term);
    }
View Full Code Here

        if (f2 instanceof Fraction) {
            Fraction f2_ = (Fraction) f2;
            Struct s = calcStruct(f1.getDenominator(), f2_.getDenominator());
            return new Fraction(
                    new Sum(
                    s.firstMultiplicand == null ? f1.getNumerator() : new Product(f1.getNumerator(), s.firstMultiplicand),
                    s.secondMultiplicand == null ? f2_.getNumerator() : new Product(f2_.getNumerator(), s.secondMultiplicand)),
                    s.denominator);
        }
        Tensor f = new Product(f1.getDenominator().clone(), f2);
        return new Fraction(new Sum(f1.getNumerator(), f), f1.getDenominator());
    }
View Full Code Here

                    commonDetected = true;
                    break;
                }
            }
            if (commonDetected)
                return new Struct(null, t1.equivalent().clone(), new Product(t1, t2));
            else
                return new Struct(t2.clone(), t1.clone(), new Product(t1, t2));
        }
        if (!(t1 instanceof Product) && t2 instanceof Product)
            return calcStruct(t2, t1).inverse();
        if (t1 instanceof Product && t2 instanceof Product) {
            Product _t1 = (Product) t1;
            Product _t2 = (Product) t2;
            _t1.sort();
            _t2.sort();
            TensorIterator iterator1 = _t1.iterator(), iterator2 = _t2.iterator();
            Tensor current1 = iterator1.next(), current2 = iterator2.next();
            int hash1 = current1.hashCode(), hash2 = current2.hashCode(), oldSize = 0;
            boolean process = false;

            List<Tensor> common = new ArrayList<>();
            List<Tensor> equalsHash1 = new ArrayList<>();

            while (true) {
                if (hash1 < hash2) {
                    if (!iterator1.hasNext())
                        break;
                    current1 = iterator1.next();

                } else if (hash2 < hash1) {
                    if (!iterator2.hasNext())
                        break;
                    current2 = iterator2.next();
                    hash2 = current2.hashCode();
                    process = process && hash2 == equalsHash1.get(0).hashCode();
                    if (process) {
                        for (int i = equalsHash1.size() - 1; i >= oldSize; --i)
                            if (TTest.testParity(equalsHash1.get(i), current2)) {
                                iterator2.remove();
//                                current2 = iterator2.next();

                                common.add(equalsHash1.remove(i));
                                break;
                            }
                        oldSize = equalsHash1.size();
                    }
                } else if (TTest.testParity(current1, current2)) {
                    common.add(current1);
                    iterator1.remove();
                    iterator2.remove();
                    if (!iterator1.hasNext() || !iterator2.hasNext())
                        break;
                    current1 = iterator1.next();
                    current2 = iterator2.next();
                } else {
                    process = true;
                    equalsHash1.add(current1);
                    iterator1.remove();
                    if (!iterator1.hasNext())
                        continue;
                    current1 = iterator1.next();
                }
                hash1 = current1.hashCode();
                hash2 = current2.hashCode();
            }
            _t1.add(equalsHash1);
            Product denom = new Product();
            denom.add(_t1.clone());
            denom.add(_t2.clone());
            denom.add(common);
            return new Struct(
                    _t2.isEmpty() ? null : _t2.equivalent(),
                    _t1.isEmpty() ? null : _t1.equivalent(),
                    denom.equivalent());
        } else if (TTest.testParity(t1, t2))
            return new Struct(null, null, t1);
        else
            return new Struct(t2.clone(), t1.clone(), new Product(t1, t2));
    }
View Full Code Here

        //preprocessing conflicting indices
        target = ApplyIndexMappingTransformation.INSTANCE.perform(target, preprocess);

        //adding metrics
        if (!metrics.isEmpty()) {
            Product p = new Product();
            p.add(target);
            p.add(metrics);
            target = p;
        }
        IndexMappingImpl im = new IndexMappingImpl(usedIndices, from, to);
        return ApplyIndexMappingTransformation.INSTANCE.perform(target, im);
    }
View Full Code Here

            }
        }
        if (denominators.isEmpty())
            return tensor;
        //TODO run with RemmoveOneFromProduct transformation
        return new Fraction(tensor, denominators.size() == 1 ? denominators.get(0) : new Product(denominators));

    }
View Full Code Here

        //preprocessing conflicting indices
        target = ApplyIndexMappingTransformation.INSTANCE.perform(target, preprocess);

        //adding metrics
        if (!metrics.isEmpty()) {
            Product p = new Product();
            p.add(target);
            p.add(metrics);
            target = p;
        }
        IndexMappingImpl im = new IndexMappingImpl(usedIndices, indexMappingBuffer);
        return ApplyIndexMappingTransformation.INSTANCE.perform(target, im);
    }
View Full Code Here

                break;
            }
        }
        if (fraction == null)
            return tensor;
        Tensor numer = new Product(tensor.equivalent(), fraction.getDenominator());
        Tensor denom = fraction.getDenominator();
        return new Fraction(numer, denom);
    }
View Full Code Here

        return kroneckers;
    }

    @Override
    public Tensor transform(Tensor tensor) {
        Product result = new Product();
        result.add(renameIndicesAndBuidKroneckers(tensor));
        result.add(kroneckers);
        return result.equivalent();
    }
View Full Code Here

        List<Tensor> firstProduct = new ArrayList<>();
        List<Tensor> secondProduct = new ArrayList<>();
        firstProduct.add(secondMultiplyed);
        secondProduct.add(firstMultiplyed);

        Product denominator = new Product();

        int j = 0;
        boolean firstIsFinish = false;
        for (int i = 0; i < secondContent.size(); i++) {
            if (firstIsFinish) {
                secondProduct.add(secondContent.get(i));
                denominator.add(secondContent.get(i));
                continue;
            }
            if (secondContent.get(i).hashCode() < firstContent.get(j).hashCode()) {
                secondProduct.add(secondContent.get(i));
                denominator.add(secondContent.get(i));
                continue;
            } else if (secondContent.get(i).hashCode() > firstContent.get(j).hashCode()) {
                firstProduct.add(firstContent.get(j));
                denominator.add(firstContent.get(j));
                j++;
                if (j == firstContent.size())
                    firstIsFinish = true;
                i--;
                continue;
            } else if (secondContent.get(i).hashCode() == firstContent.get(j).hashCode())
                while (secondContent.get(i).hashCode() == firstContent.get(j).hashCode() && j < firstContent.size())
                    if (TTest.testParity(secondContent.get(i), firstContent.get(j))) {
                        denominator.add(firstContent.get(j));
                        j++;
                        if (j == firstContent.size())
                            firstIsFinish = true;
                        break;
                    }
        }
        if (!firstIsFinish)
            for (int i = j; i < firstContent.size(); i++) {
                firstProduct.add(firstContent.get(j));
                denominator.add(firstContent.get(j));
            }

        Tensor summond1 = new Product(firstProduct);
        Tensor summond2 = new Product(secondProduct);
        return new Fraction(new Sum(summond1, summond2), denominator);
    }
View Full Code Here

TOP

Related Classes of cc.redberry.core.tensor.Product

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.