Package cc.redberry.core.indices

Examples of cc.redberry.core.indices.IndicesBuilder


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


            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

            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

            TIntHashSet freeIndices = new TIntHashSet(IndicesUtils.getIndicesNames(tensor.getIndices().getFree()));

            //now we need to uncontract dummies and free

            Indices factorIndices = new IndicesBuilder().append(factors).getIndices();
            TIntHashSet dummies = new TIntHashSet(IndicesUtils.getIntersections(
                    factorIndices.getUpper().copy(), factorIndices.getLower().copy()));
            SimpleIndices currentFactorIndices;
            IntArrayList from = new IntArrayList(), to = new IntArrayList();
            ArrayList<Tensor> kroneckers = new ArrayList<>();
View Full Code Here

            Arrays.sort(factors);
            int hash = 17;
            for (SimpleTensor f : factors)
                hash = hash * 17 + f.hashCode();
            this.hashCode = hash;
            this.forbidden = IndicesUtils.getIndicesNames(new IndicesBuilder().append(factors).getIndices());
        }
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

        if (tensor instanceof Product) {
            int i;
            int count = 0;
            Tensor current, old;
            IndicesBuilder ib = new IndicesBuilder();
            List<Tensor> newProductElements = new ArrayList<>();
            for (i = tensor.size() - 1; i >= 0; --i) {
                current = tensor.get(i);
                if (isN(current)) {
                    ib.append(current);
                    ++count;
                } else {
                    if (TensorUtils.isScalar(current)) {
                        FromChildToParentIterator iterator = new FromChildToParentIterator(current);
                        Tensor temp;
                        boolean flag = false;
                        while ((temp = iterator.next()) != null) {
                            if (isN(temp)) {
                                flag = true;
                                break;
                            }
                        }
                        if (!flag) {
                            newProductElements.add(current);
                            continue;
                        }
                        if (!(current instanceof Power) || !TensorUtils.isInteger(current.get(1)) || ((Complex) current.get(1)).intValue() != 2)
                            throw new IllegalArgumentException();

                        Tensor[] bases = {current.get(0), current.get(0)};
                        bases[1] = ApplyIndexMapping.renameDummy(bases[1], TensorUtils.getAllIndicesNamesT(tensor).toArray());
                        flag = false;
                        for (Tensor base : bases) {
                            for (Tensor t : base) {
                                if (isN(t)) {
                                    ib.append(t);
                                    ++count;
                                    flag = true;
                                } else
                                    newProductElements.add(t);
                            }
                        }
                        if (!flag)
                            throw new IllegalArgumentException("Expand first");
                    } else
                        newProductElements.add(current);
                }
            }
            if (count == 0)
                return tensor;
            if (count % 2 != 0)
                return Complex.ZERO;
//            System.out.println(count);
            count = count / 2;
            Tensor result = average(ib.getIndices().getAllIndices().copy());
            long factor = ArithmeticUtils.pow((long) 2, count) * ArithmeticUtils.factorial(count + 1);//may be BigInteger?
            Complex number = new Complex((long) factor).reciprocal();
            result = ExpandTransformation.expand(result);
            newProductElements.add(number);
            newProductElements.add(result);
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

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.