Package cc.redberry.core.number

Examples of cc.redberry.core.number.Complex


        if (t instanceof Power) {
            if (!isSymbolic(t.get(0)))
                return false;
            if (!(t.get(1) instanceof Complex))
                return false;
            Complex e = (Complex) t.get(1);
            if (!e.isReal() || e.isNumeric())
                return false;
            return true;
        }
        for (Tensor tt : t)
            if (!isSymbolic(tt))
View Full Code Here


        if (tensors.length == 0)
            return Complex.ONE;
        else if (tensors.length == 1)
            return tensors[0];

        Complex factor = Complex.ONE;

        IndexlessWrapper indexlessContainer = new IndexlessWrapper();
        DataWrapper dataContainer = new DataWrapper();
        Product p;
        for (Tensor current : tensors) {
            if (current instanceof Complex)
                factor = factor.multiply((Complex) current);
            else if (current instanceof Product) {
                p = (Product) current;
                indexlessContainer.add(p.indexlessData);
                dataContainer.add(p.data, p.contentReference.getReferent(), p.indices);
                factor = factor.multiply(p.factor);
            } else if (current.getIndices().size() == 0)
                indexlessContainer.add(current);
            else
                dataContainer.add(current);
            if (factor.isNaN())
                return factor;
        }

        if (NumberUtils.isZeroOrIndeterminate(factor))
            return factor;

        if (factor.isNumeric()) {
            List<Tensor> newTensors = new ArrayList<>();
            factor = Complex.ONE;
            for (Tensor current : tensors) {
                current = toNumeric(current);
                if (current instanceof Complex)
                    factor = factor.multiply((Complex) current);
                else newTensors.add(current);
            }
            if (newTensors.isEmpty())
                return factor;
            indexlessContainer = new IndexlessWrapper();
            dataContainer = new DataWrapper();
            for (Tensor current : newTensors) {
                if (current instanceof Product) {
                    p = (Product) current;
                    indexlessContainer.add(p.indexlessData);
                    dataContainer.add(p.data, p.contentReference.getReferent(), p.indices);
                    factor = factor.multiply(p.factor);
                } else if (current.getIndices().size() == 0)
                    indexlessContainer.add(current);
                else
                    dataContainer.add(current);
            }
        }


        //Processing data with indices
        int i;
        ProductContent content;
        Indices indices;
        Tensor[] data = dataContainer.list.toArray(new Tensor[dataContainer.list.size()]);
        if (dataContainer.count == 1) {
            content = dataContainer.content;
            indices = dataContainer.indices;
            if (indices == null) {
                assert dataContainer.list.size() == 1;
                indices = IndicesFactory.create(dataContainer.list.get(0).getIndices());
            }
        } else {
            content = null;
            Arrays.sort(data);
            IndicesBuilder builder = new IndicesBuilder();
            for (i = dataContainer.list.size() - 1; i >= 0; --i)
                builder.append(dataContainer.list.get(i));
            try {
                indices = builder.getIndices();
            } catch (InconsistentIndicesException exception) {
                throw new InconsistentIndicesException(exception.getIndex());
            }
        }

        //Processing indexless data
        Tensor[] indexless;
        if (indexlessContainer.count == 0)
            indexless = new Tensor[0];
        else if (indexlessContainer.count == 1)
            indexless = indexlessContainer.list.toArray(new Tensor[indexlessContainer.list.size()]);
        else {
            PowersContainer powersContainer = new PowersContainer(indexlessContainer.list.size());
            List<Tensor> indexlessArray = new ArrayList<>();
            Tensor tensor;
            for (i = indexlessContainer.list.size() - 1; i >= 0; --i) {
                tensor = indexlessContainer.list.get(i);
                if (TensorUtils.isSymbolic(tensor)) {
                    powersContainer.put(tensor);
                } else
                    indexlessArray.add(tensor);
            }

            for (Tensor t : powersContainer) {
                assert !(t instanceof Product);

                if (t instanceof Complex) {
                    factor = factor.multiply((Complex) t);
                    if (isZeroOrIndeterminate(factor))
                        return factor;
                } else
                    indexlessArray.add(t);
            }

            if (powersContainer.isSign())
                factor = factor.negate();

            indexless = indexlessArray.toArray(new Tensor[indexlessArray.size()]);
            Arrays.sort(indexless);
        }

        //Constructing result
        if (data.length == 0 && indexless.length == 0)
            return factor;
        if (factor.isOne()) {
            if (data.length == 1 && indexless.length == 0)
                return data[0];
            if (data.length == 0 && indexless.length == 1)
                return indexless[0];
        }
        if (factor.isMinusOne()) {
            Sum s = null;
            if (indexless.length == 1 && data.length == 0 && indexless[0] instanceof Sum)
                //case (-1)*(a+b) -> -a-b
                s = ((Sum) indexless[0]);
            if (indexless.length == 0 && data.length == 1 && data[0] instanceof Sum)
View Full Code Here

        return ((Complex) tensor).isNatural();
    }

    public static boolean isRealPositiveNumber(Tensor tensor) {
        if (tensor instanceof Complex) {
            Complex complex = (Complex) tensor;
            return complex.isReal() && complex.getReal().signum() > 0;
        }
        return false;
    }
View Full Code Here

        //todo here we assuming, that all indices belongs to pseudo-Euclidean spaces
        if (size % 2 == 0)
            rhs = negate(rhs);
        sub[0] = expression(lhs, rhs);
        int index = eps1Indices.get(0);
        sub[1] = expression(createKronecker(index, inverseIndexState(index)), new Complex(size));
        cachedSubstitutions.put(eps.getName(), sub);
        return sub;
    }
View Full Code Here

//    }

    @Override
    Tensor newTo_(Tensor currentNode, SubstitutionIterator iterator) {
        Product product = (Product) currentNode;
        Complex factor = product.getFactor();
        PContent content = new PContent(product.getIndexless(), product.getDataSubProduct());

        //TODO getForbidden only if necessary!!!!!!!!!!!!!!!!!
        ForbiddenContainer forbidden = new ForbiddenContainer();
        SubsResult subsResult = atomicSubstitute(content, forbidden, iterator);
        if (subsResult == null)
            return currentNode;

        List<Tensor> newTos = new ArrayList<>();
        while (true) {
            if (subsResult == null)
                break;
            factor = factor.divide(fromFactor);
            newTos.add(subsResult.newTo);
            content = subsResult.remainder;
            subsResult = atomicSubstitute(content, forbidden, iterator);
        }
        Tensor[] result = new Tensor[newTos.size() + content.indexless.length + 2];
View Full Code Here

            builder.put(temp);
        }
        temp = builder.build();
        if (temp instanceof Sum) {
            //retrieving factor
            Complex factor = null, tempF;
            for (int i = temp.size() - 1; i >= 0; --i) {
                if (temp.get(i) instanceof Product) {
                    tempF = ((Product) temp.get(i)).getFactor();
                    assert tempF.isInteger();
                    tempF = tempF.abs();
                } else
                    tempF = Complex.ONE;
                if (factor == null)
                    factor = tempF;
                assert factor.equals(tempF);
            }

            if (!factor.isOne())
                temp = FastTensors.multiplySumElementsOnFactor((Sum) temp, factor.reciprocal());
            return multiply(new Complex(new Rational(1, temp.size())), temp);
        }
        return temp;
    }
View Full Code Here

                        new Mapping(indices, symmetry.permute(indices), symmetry.isAntiSymmetry())));
                ++length;
            }
            t = sb.build();
            if (t instanceof Sum)
                return FastTensors.multiplySumElementsOnFactor((Sum) t, new Complex(new Rational(1L, length)));
            return Tensors.multiply(new Complex(new Rational(1L, length)), t);
        }
    }
View Full Code Here

                if (summand != null)
                    sumBuilder.put(summand);
            }
        }
        if (multiplyOnSymmetryFactor)
            return Tensors.multiply(new Complex(new Rational(1, generatedPermutations.size())), sumBuilder.build());
        else
            return sumBuilder.build();
    }
View Full Code Here

        SplitStruct base = splitFraction(t.get(0), doFactor), temp;
        @SuppressWarnings("unchecked") List<Tensor> numeratorTerms[] = new List[t.size()];
        numeratorTerms[0] = new ArrayList<>();
        numeratorTerms[0].add(base.numerator);
        Tensor s, power;
        Complex exponent, _exponent;
        int i, j;
        for (i = 1; i < t.size(); ++i) {
            s = t.get(i);
            temp = splitFraction(s, doFactor);
View Full Code Here

        Tensor toTensor() {
            BigInteger exponent = this.exponent;
            if (minExponent != null && minExponent.value != null) {
                exponent = exponent.subtract(minExponent.value);
                if (diffSigns && minExponent.value.testBit(0))
                    return Tensors.negate(Tensors.pow(tensor, new Complex(exponent)));
            }
            return Tensors.pow(tensor, new Complex(exponent));
        }
View Full Code Here

TOP

Related Classes of cc.redberry.core.number.Complex

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.