private Tensor __newTo(DFromTo fromTo, TensorField currentField,
Tensor currentNode, SubstitutionIterator iterator) {
TensorField from = fromTo.from;
Mapping mapping = IndexMappings.simpleTensorsPort(from, currentField).take();
if (mapping == null)
return currentNode;
Indices[] fromIndices = from.getArgIndices(),
currentIndices = currentField.getArgIndices();
List<Tensor> argFrom = new ArrayList<>(), argTo = new ArrayList<>();
Tensor fArg;
int[] cIndices, fIndices;
int i;
for (i = from.size() - 1; i >= 0; --i) {
if (IndexMappings.positiveMappingExists(currentNode.get(i), from.get(i)))
continue;
fIndices = fromIndices[i].getAllIndices().copy();
cIndices = currentIndices[i].getAllIndices().copy();
assert cIndices.length == fIndices.length;
fArg = ApplyIndexMapping.applyIndexMapping(from.get(i), new Mapping(fIndices, cIndices), new int[0]);
argFrom.add(fArg);
argTo.add(currentNode.get(i));
}
Tensor newTo = fromTo.to;
newTo = new SubstitutionTransformation(
argFrom.toArray(new Tensor[argFrom.size()]),
argTo.toArray(new Tensor[argTo.size()]),
false).transform(newTo);
if (!TensorUtils.isSymbolic(newTo))
newTo = ApplyIndexMapping.applyIndexMapping(newTo, mapping, iterator.getForbidden());
else if (mapping.getSign())
newTo = Tensors.negate(newTo);
return newTo;
}