@Override public String toString() { return getIndices().toString(); }
private Split(Tensor[] factors, Tensor summand) { this.factors = factors; this.summands.add(summand); Arrays.sort(factors); this.hashCode = Arrays.hashCode(factors); this.forbidden = IndicesUtils.getIndicesNames(new IndicesBuilder().append(factors).getIndices()); }
@Override protected Tensor select1(int[] positions) { int add = factor == Complex.ONE ? 0 : 1; Complex newFactor = Complex.ONE; List<Tensor> newIndexless = new ArrayList<>(), newData = new ArrayList<>(); for (int position : positions) { position -= add; if (position == -1) newFactor = factor; 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()])); }
@Override protected Tensor remove1(int[] positions) { Complex newFactor = factor; if (factor != Complex.ONE) { if (positions[0] == 0) { newFactor = Complex.ONE; positions = Arrays.copyOfRange(positions, 1, positions.length); } for (int i = positions.length - 1; i >= 0; --i) --positions[i]; } int dataFrom = Arrays.binarySearch(positions, indexlessData.length - 1); if (dataFrom < 0) dataFrom = ~dataFrom - 1; final int[] indexlessPositions = Arrays.copyOfRange(positions, 0, dataFrom + 1); final int[] dataPositions = Arrays.copyOfRange(positions, dataFrom + 1, positions.length); for (int i = 0; i < dataPositions.length; ++i) 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); }
public Indices getIndices() { IndicesBuilder indices = new IndicesBuilder(); for (int i = 0; i < length; i++) indices.append(pc.get(gPositions.get(i))); return indices.getIndices(); }
return new Product(new IndicesBuilder().append(data).getIndices(), factor, indexLess.toArray(new Tensor[indexLess.size()]),
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()]));
/** * Returns {@link Indices} of the corresponding mathematical expression. * * @return {@link Indices} of the corresponding mathematical expression */ public Indices getIndices() { switch (tokenType) { case Product: case Trace: 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; } throw new ParserException("Unknown tensor type: " + tokenType); }
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(); }
for (i = dataContainer.list.size() - 1; i >= 0; --i) builder.append(dataContainer.list.get(i)); indices = builder.getIndices();
new IndicesBuilder().append(component.elements).getIndices(), Complex.ONE, new Tensor[0], //all tensors have indices with nonzero length
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();
} else { Tensor[] newData = ArraysUtils.remove(data, i - indexlessData.length); return new Product(new IndicesBuilder().append(newData).getIndices(), complex, indexlessData, newData);
Indices factorIndices = new IndicesBuilder().append(factors).getIndices(); TIntHashSet dummies = new TIntHashSet(IndicesUtils.getIntersections( factorIndices.getUpper().toArray(), factorIndices.getLower().toArray()));
summand = new Product(product.factor, product.indexlessData, data, null, ib.getIndices());
@Override 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); generated.removeAll(allowedDummies); result = ApplyIndexMapping.renameDummy(result, generated.toArray(), allowedDummies.toArray()); return result; } }
Tensor[] newData = data.clone(); newData[i - indexlessData.length] = tensor; return new Product(new IndicesBuilder().append(newData).getIndices(), newFactor, indexlessData, newData);
return new Product(new IndicesBuilder().append(newData).getIndices(), product.factor, newIndexless, newData);
return new Product(new IndicesBuilder().append(newData).getIndices(), product.factor, newIndexless, newData);
ib.append(currentData[index]); allowed.addAll(ib.getIndices().getNamesOfDummies()); allowed.removeAll(IndicesUtils.getIndicesNames(mapping.getToData())); newTo = applyIndexMappingAndRenameAllDummies(to, mapping, allowed.toArray());