Package cc.redberry.core.tensor

Examples of cc.redberry.core.tensor.Product$MatricesPrinter


     * 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


            if (!(resultIsProduct || fIsProduct))
                if (TTest.testParity(resultFracD, fD))
                    resultFrac = new Fraction(new Sum(resultFracN, fN), resultFracD);
                else {
                    Tensor summond1 = new Product(resultFracN, fD);
                    Tensor summond2 = new Product(fN, resultFracD.clone());

                    Tensor newNumerator = new Sum(summond1, summond2);
                    Tensor newDenumerator = new Product(resultFracD.clone(), fD);

                    resultFrac = new Fraction(newNumerator, newDenumerator);
                }
            else if (resultIsProduct ^ fIsProduct)
                if (resultIsProduct)
                    resultFrac = getSumWithProductAndSimpleDenominator(resultFrac, f);
                else
                    resultFrac = getSumWithProductAndSimpleDenominator(f, resultFrac);
            else
                if (((Product) resultFracD).size() >= ((Product) fD).size())
                    resultFrac = getSumWithProductDenominator(resultFrac, f);
                else
                    resultFrac = getSumWithProductDenominator(f, resultFrac);


        }

        if (!listTensor.isEmpty()) {
            Tensor simpleSum = new Sum(listTensor);
            Tensor summand1 = new Product(simpleSum, resultFrac.getDenominator().clone());
            Tensor summand2 = resultFrac.getNumerator();
            Tensor result = new Fraction(new Sum(summand1, summand2), resultFrac.getDenominator());
            return result;
        }
        return resultFrac;
View Full Code Here

        return uncontracted;
    }

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

    public boolean isEmpty() {
        return collected.isEmpty();
    }

    public Tensor getResult() {
        Product result = new Product();
        for (Pair p : collected)
            result.add(p.get());
        return result.equivalent();
    }
View Full Code Here

            assert buffer.isEmpty();
            sign = buffer.getSignum();
        }
        if (buffer == null)
            return false;
        factors.add(sign == false ? split.factoredOut : new Product(TensorNumber.createMINUSONE(), split.factoredOut));
        return true;

    }
View Full Code Here

        if (except.is(tensor))
            return tensor;
        TensorIterator productIterator = tensor.iterator();
        ArrayList<Product> products = new ArrayList<>();
        ArrayList<Product> newProducts;
        products.add(new Product());
        Tensor t = null;
        int oldSize, i;
        Sum sum;
        boolean sumsExists = false;
        while (productIterator.hasNext()) {
View Full Code Here

    protected Tensor pairProduct(Tensor f, Tensor t) {
        Tensor[] arr = new Tensor[]{f.equivalent(), t.equivalent()};
        for (int i = 0; i < 2; ++i)
            if (arr[i] instanceof TensorNumber && ((TensorNumber) arr[i]).isOne())
                return arr[1 - i];
        return new Product(arr[0], arr[1]);
    }
View Full Code Here

        if (integrals.isEmpty())
            return tensor;

        //only integrals
        if (((Product) tensor).isEmpty())
            return new Product(integrals);

        //remember integration vars for each integral
        final List<Map<Integer, SimpleTensor>> vars = new ArrayList<>();
        for (final Integral i : integrals) {
            final Map<Integer, SimpleTensor> map = new HashMap<>();
            for (final SimpleTensor s : i.vars())
                map.put(s.getName(), s);
            vars.add(map);
        }

        //main routine
        iterator = tensor.iterator();
        Collection<SimpleTensor> tempVars;
        while (iterator.hasNext()) {
            current = iterator.next();
            //vars in current
            tempVars = TensorUtils.getDiffSimpleTensorContent(current);

            out_for:
            for (int i = 0; i < integrals.size(); ++i) {
                final Map<Integer, SimpleTensor> map = vars.get(i);

                for (SimpleTensor st : tempVars)
                    if (map.containsKey(st.getName()))
                        continue out_for;

                //current can be placed under current integral
                final Integral integral = integrals.get(i);
                integrals.set(i, new Integral(new Product(current, integral.target()), integral.vars()));
                iterator.remove();
            }
        }

        Product result = new Product();
        result.add(tensor);
        result.add(integrals);
        return result.equivalent();
    }
View Full Code Here

            }
            if (res.isEmpty())
                return null;
            return res.equivalent();
        } else if (target instanceof Product) {
            Product product = (Product) target;
            Tensor derivative;
            List<Tensor> resultProducts = new ArrayList<>();
            for (int i = 0; i < product.size(); ++i) {
                derivative = getDerivative(product.getElements().get(i), var);
                if (derivative == null)
                    continue;
                Product clone = (Product) product.clone();
                clone.getElements().remove(i);
                if (!isOne(derivative))
                    clone.add(derivative);
                resultProducts.add(clone.equivalent());
            }
            if (resultProducts.isEmpty())
                return null;
            if (resultProducts.size() == 1)
                return resultProducts.get(0);
            return new Sum(resultProducts);
        } else if (target.getClass() == SimpleTensor.class) {
            if (((SimpleTensor) target).getName() == var.getName())
                return TensorNumber.createONE();
            return null;
        } else if (target.getClass() == TensorField.class) {
            TensorField field = (TensorField) target;
            Tensor[] args = field.getArgs();
            for (int i = 0; i < args.length; ++i)
                if (getDerivative(args[i], var) != null)
                    return Derivative.createFromInversed(target, new SimpleTensor[]{var});
            return null;
        } else if (target instanceof AbstractScalarFunction) {
            AbstractScalarFunction func = (AbstractScalarFunction) target;
            Tensor der = getDerivative(func.getInnerTensor(), var);
            if (der == null)
                return null;
            if (isOne(der))
                return func.derivative();
            return new Product(func.derivative(), der);
        }
        return null;
    }
View Full Code Here

            if (buffer.getSignum())
                if (Derivative.onVarsIndicator.is(iterator)) {
                    derivativeVarChangedSignum ^= true;
                    iterator.set(Transformations.contractMetrics(newTo));
                } else
                    iterator.set(new Product(TensorNumber.createMINUSONE(), newTo));
            else if (Derivative.onVarsIndicator.is(iterator))
                iterator.set(Transformations.contractMetrics(newTo));
            else
                iterator.set(newTo);
        }
View Full Code Here

TOP

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

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.