Package cc.redberry.core.tensor

Examples of cc.redberry.core.tensor.TensorIterator


    public Tensor transform(Tensor tensor) {
        if (!(tensor instanceof Fraction))
            return tensor;
       
        Fraction fraction = (Fraction) tensor; 
        TensorIterator iterator = fraction.iterator();
        Tensor current;
        while (iterator.hasNext()) {
            current = iterator.next();
           
            if (current instanceof Fraction) {
                Fraction temp = (Fraction) current;
                if (Fraction.onDenominatorIndicator.is(iterator))
                    return new Fraction(new Product(fraction.getNumerator(), temp.getDenominator()), temp.getNumerator());
                else
                    return new Fraction(temp.getNumerator(), new Product(fraction.getDenominator(), temp.getDenominator()));
            }
            if (current instanceof Product) {
                List<Tensor> multiplicands = new ArrayList<>();
                TensorIterator it = current.iterator();
                Tensor current1;
                while (it.hasNext()) {
                    current1 = it.next();
                    if (current1 instanceof Fraction) {
                        Fraction currentFraction = (Fraction) current1;
                        multiplicands.add(currentFraction.getDenominator());
                        it.set(currentFraction.getNumerator());
                    }
                }
                if (multiplicands.isEmpty())
                    return tensor;
                Product newNumerator = new Product();
View Full Code Here


        }
    }

    private Split split(Tensor tensor) {
        if (tensor instanceof Product) {
            TensorIterator it = tensor.iterator();
            Tensor current;
            List<Tensor> factored = new ArrayList<>();
            while (it.hasNext()) {
                current = it.next();
                if (currentPattern.factorOut(current)) {
                    factored.add(current);
                    it.remove();
                }
            }
            if (factored.isEmpty())
                factored.add(TensorNumber.createONE());
            if (((Product) tensor).isEmpty())
View Full Code Here

public abstract class AbstractRemoveElements implements Transformation {
    @Override
    public Tensor transform(Tensor tensor) {
        if (tensor.getClass() != getMultiClass())
            return tensor;
        TensorIterator it = tensor.iterator();
        while (it.hasNext())
            if (remove(it.next()))
                it.remove();
        return tensor.equivalent();
    }
View Full Code Here

            return new SplitNumber(TensorNumber.createONE(), tensor);
        if (tensor instanceof TensorNumber)
            return new SplitNumber(TensorNumber.createONE(), tensor);
        if (tensor instanceof Product) {
            TensorNumber number = TensorNumber.createONE();
            TensorIterator iterator = tensor.iterator();
            Tensor current;
            while (iterator.hasNext()) {
                current = iterator.next();
                if (current instanceof TensorNumber) {
                    number.multiply((TensorNumber) current);
                    iterator.remove();
                }
            }
            return new SplitNumber(number, tensor.equivalent());
        }
        throw new UnsupportedOperationException();
View Full Code Here

    @Override
    public Tensor transform(Tensor tensor) {
        if (tensor.getClass() != getMultiClass())
            return tensor;
        MultiTensor multiTensor = (MultiTensor) tensor;
        TensorIterator it = multiTensor.iterator();
        Tensor current;
        TensorNumber number = null;
        while (it.hasNext()) {
            current = it.next();
            if (current instanceof TensorNumber)
                if (number == null)
                    number = (TensorNumber) current;
                else {
                    multiOperation(number, (TensorNumber) current);
                    it.remove();
                }
        }
//        if (number != null)
//            multiTensor.addFirst(number);
        if (number == null)
View Full Code Here

    @Override
    public Tensor transform(Tensor tensor) {
        if (TTest.testIsSymbol(tensor))
            return ExpandAndCollectTransformation.EXPAND_AND_COLLECT_SCALARS.transform(tensor);
        if (tensor instanceof Product) {
            TensorIterator it = tensor.iterator();
            Tensor c;
            List<Tensor> syms = new ArrayList<>();
            while (it.hasNext())
                if (TTest.testIsSymbol((c = it.next()))) {
                    syms.add(c);
                    it.remove();
                }
            if (syms.isEmpty())
                return tensor;
            if (syms.size() == 1) {
                ((Product) tensor).addFirst(syms.get(0));
View Full Code Here

TOP

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

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.