Package cc.redberry.core.indices

Examples of cc.redberry.core.indices.IndicesBuilder


            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 class ParseTokenDerivative extends ParseToken {
    Indices indices;

    public ParseTokenDerivative(TokenType tokenType, ParseToken... content) {
        super(tokenType, content);
        IndicesBuilder ib = new IndicesBuilder();
        ib.append(content[0].getIndices().getFree());
        for (int i = content.length - 1; i >= 1; --i)
            ib.append(content[i].getIndices().getInverted().getFree());
        indices = ib.getIndices();
    }
View Full Code Here

    public Tensor toTensor() {
        SimpleTensor[] vars = new SimpleTensor[content.length - 1];
        Tensor temp = content[0].toTensor();

        TIntHashSet allowedDummies = TensorUtils.getAllIndicesNamesT(temp);
        IndicesBuilder free = new IndicesBuilder().append(temp.getIndices());
        for (int i = 1; i < content.length; ++i) {
            temp = content[i].toTensor();
            free.append(temp.getIndices().getInverted());
            allowedDummies.addAll(IndicesUtils.getIndicesNames(temp.getIndices()));
            if (!(temp instanceof SimpleTensor) && !(temp instanceof TensorField))
                throw new IllegalArgumentException("Derivative with respect to non simple argument: " + temp);
            vars[i - 1] = (SimpleTensor) temp;
        }
        allowedDummies.removeAll(IndicesUtils.getIndicesNames(free.getIndices().getFree()));
        Tensor result = new DifferentiateTransformation(
                vars, new Transformation[]{ExpandAndEliminateTransformation.EXPAND_AND_ELIMINATE}
        ).transform(content[0].toTensor());
        result = ApplyIndexMapping.optimizeDummies(result);
        TIntHashSet generated = TensorUtils.getAllDummyIndicesT(result);
View Full Code Here

                forbidden.forbidden.addAll(getAllIndicesNamesT(newTo));
            } else {
                TIntHashSet allowed = new TIntHashSet();
                for (int index : indexlessBijection)
                    allowed.addAll(TensorUtils.getAllDummyIndicesT(content.indexless[index]));
                IndicesBuilder ib = new IndicesBuilder();
                for (int index : dataBijection) {
                    allowed.addAll(TensorUtils.getAllDummyIndicesT(currentData[index]));
                    ib.append(currentData[index]);
                }
                allowed.addAll(ib.getIndices().getNamesOfDummies());
                allowed.removeAll(IndicesUtils.getIndicesNames(mapping.getToData()));
                newTo = applyIndexMappingAndRenameAllDummies(to, mapping, allowed.toArray());
            }
        }
        return new SubsResult(newTo, remainder);
View Full Code Here

                return new Sum(s.indices, sumData, s.hashCode());
            }
        }

        //Calculating product indices
        IndicesBuilder ibs = new IndicesBuilder();
        for (Tensor m : elements)
            ibs.append(m);
        return new Product(ibs.getIndices(), factor,
                indexLess.toArray(new Tensor[indexLess.size()]),
                elements.toArray(new Tensor[elements.size()]));
    }
View Full Code Here

                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));
            indices = builder.getIndices();
        }

        //Processing indexless data
        Tensor[] indexless;
        if (indexlessContainer.count == 0)
View Full Code Here

            // mapping, since it is done automatically

            //putting scalar component
            powers.put(
                    new Product(
                            new IndicesBuilder().append(component.elements).getIndices(),
                            Complex.ONE,
                            new Tensor[0], //all tensors have indices with nonzero length
                            component.elements.toArray(new Tensor[component.elements.size()])));
        }
    }
View Full Code Here

                    sumData[i] = Tensors.negate(sumData[i]);
                return new Sum(s.indices, sumData, s.hashCode());
            }
        }

        return new Product(new IndicesBuilder().append(data).getIndices(),
                factor,
                indexLess.toArray(new Tensor[indexLess.size()]),
                data.toArray(new Tensor[data.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

     * @return {@link Indices} of the corresponding mathematical expression
     */
    public Indices getIndices() {
        switch (tokenType) {
            case Product:
                IndicesBuilder builder = new IndicesBuilder();
                for (ParseToken node : content)
                    builder.append(node.getIndices());
                return builder.getIndices();
            case Sum:
                return IndicesFactory.create(content[0].getIndices());
            case Power:
                return IndicesFactory.EMPTY_INDICES;
        }
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.