Package cc.redberry.core.indices

Examples of cc.redberry.core.indices.IndicesBuilder


            else if (position < indexlessData.length)
                newIndexless.add(indexlessData[position]);
            else
                newData.add(data[position - indexlessData.length]);
        }
        return new Product(new IndicesBuilder().append(newData).getIndices(), newFactor,
                newIndexless.toArray(new Tensor[newIndexless.size()]),
                newData.toArray(new Tensor[newData.size()]));
    }
View Full Code Here


                        summand = new Product(product.factor, product.indexlessData, new Tensor[0], ProductContent.EMPTY_INSTANCE, IndicesFactory.EMPTY_INDICES);
                else if (dataLength == 1 && product.indexlessData.length == 0 && product.factor == Complex.ONE)
                    summand = scalars[0];
                else {
                    Tensor[] data = new Tensor[dataLength];
                    IndicesBuilder ib = new IndicesBuilder();
                    dataLength = -1;
                    for (Tensor t : scalars)
                        if (t instanceof Product)
                            for (Tensor d : t) {
                                data[++dataLength] = d;
                                ib.append(d);
                            }
                        else {
                            data[++dataLength] = t;
                            ib.append(t);
                        }
                    assert dataLength == data.length - 1;
                    Arrays.sort(data);
                    summand = new Product(product.factor, product.indexlessData, data, null, ib.getIndices());
                }
            } else {
                summand = Complex.ONE;
                factor = tensor;
            }
View Full Code Here

            if (newData == null)
                // we can pass the hash code, since we did not changed the order of
                // indexless data, and its hash cannot been changed by the renaming of dummies
                return new Product(product.indices, product.factor, newIndexless, data, product.contentReference);

            return new Product(new IndicesBuilder().append(newData).getIndices(), product.factor, newIndexless, newData);
        }

        if (tensor instanceof Sum) {
            Sum sum = (Sum) tensor;
            Tensor[] data = sum.data, newData = null;
View Full Code Here

    }

    public Indices getIndices() {
        switch (tensorType) {
            case Product:
                IndicesBuilder builder = new IndicesBuilder();
                for (ParseNode node : content)
                    builder.append(node.getIndices());
                return builder.getIndices();
            case Sum:
                return IndicesFactory.createSorted(content[0].getIndices());
            case Power:
                return IndicesFactory.EMPTY_INDICES;
            case Expression:
View Full Code Here

        if (tensor instanceof Product) {
            int i;
            int count = 0;
            Tensor current;
            IndicesBuilder ib = new IndicesBuilder();
            List<Tensor> newProductElements = new ArrayList<>();
            for (i = tensor.size() - 1; i >= 0; --i) {
                current = tensor.get(i);
                if (current instanceof SimpleTensor && ((SimpleTensor) current).getName() == const_n.getName()) {
                    ib.append(current);
                    ++count;
                } else
                    newProductElements.add(current);
            }
            if (count == 0)
                return tensor;
            if (count % 2 != 0)
                return Complex.ZERO;
            count = count / 2;
            Tensor averaged = average(ib.getIndices().getAllIndices().copy());
            long factor = ArithmeticUtils.pow((long) 2, count) * ArithmeticUtils.factorial(count + 1);
            Complex number = new Complex((long) factor);
            averaged = Expand.expand(averaged);
            newProductElements.add(number);
            newProductElements.add(averaged);
View Full Code Here

            if (indexlessData.isEmpty() && elements.size() == 1)
                return elements.get(0);
        }

        //Calculating product indices
        IndicesBuilder ibs = new IndicesBuilder();
        Indices indices;
        for (Tensor t : elements)
            ibs.append(t);
        try {
            indices = ibs.getIndices();
        } catch (InconsistentIndicesException exception) {
            throw new InconsistentIndicesException(exception.getIndex());
        }

        return new Product(indices, complex,
View Full Code Here

                indices = IndicesFactory.createSorted(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());
            }
        }
View Full Code Here

            newIndexless[i] = tensor;
            return new Product(indices, newFactor, newIndexless, data, contentReference);
        } else {
            Tensor[] newData = data.clone();
            newData[i - indexlessData.length] = tensor;
            return new Product(new IndicesBuilder().append(newData).getIndices(),
                    newFactor, indexlessData, newData);
        }
    }
View Full Code Here

        if (i < indexlessData.length) {
            Tensor[] newIndexless = ArraysUtils.remove(indexlessData, i);
            return new Product(indices, complex, newIndexless, data, contentReference);
        } else {
            Tensor[] newData = ArraysUtils.remove(data, i - indexlessData.length);
            return new Product(new IndicesBuilder().append(newData).getIndices(),
                    complex, indexlessData, newData);
        }
    }
View Full Code Here

            dataPositions[i] -= indexlessData.length;

        Tensor[] newIndexless = ArraysUtils.remove(indexlessData, indexlessPositions);
        Tensor[] newData = ArraysUtils.remove(data, dataPositions);

        return createProduct(new IndicesBuilder().append(newData).getIndices(),
                newFactor, newIndexless, newData);
    }
View Full Code Here

TOP

Related Classes of cc.redberry.core.indices.IndicesBuilder

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.