Package cc.redberry.core.tensor

Examples of cc.redberry.core.tensor.TensorSortedContent


    /*
     * If first and second fractions' denominators are products, find fracion with
     * common denominator.
     */
    private Fraction getSumWithProductDenominator(Fraction first, Fraction second) {
        TensorSortedContent firstContent = ((Product) first.getDenominator()).getContent();
        TensorSortedContent secondContent = ((Product) second.getDenominator()).getContent();
        Tensor firstMultiplyed = first.getNumerator();
        Tensor secondMultiplyed = second.getNumerator();

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


    /*
     * If first fraction's denominator is product but second isn't, find
     * fraction with common denominator.
     */
    private Fraction getSumWithProductAndSimpleDenominator(Fraction first, Fraction second) {
        TensorSortedContent firstFracContent = ((Product) first.getDenominator()).getContent();
        Product denom = new Product();
        boolean is = false;

        for (int i = 0; i < firstFracContent.size(); i++)
            if (!is) {
                if (!(firstFracContent.get(i).hashCode() == second.getDenominator().hashCode())) {
                    denom.add(firstFracContent.get(i));
                    continue;
                }
                if (!TTest.testParity(firstFracContent.get(i), second.getDenominator()))
                    denom.add(firstFracContent.get(i));
                else
                    is = true;

            } else
                denom.add(firstFracContent.get(i));
        Tensor denominator = is ? first.getDenominator() : new Product(denom.clone(), second.getDenominator());
        Tensor summand1 = is ? first.getNumerator() : new Product(first.getNumerator(), second.getDenominator());
        Tensor summand2 = new Product(second.getNumerator().clone(), denom);
        return new Fraction(new Sum(summand1, summand2), denominator);
    }
View Full Code Here

TOP

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

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.