} else {
for (j = 0; j < cIndices.length; ++j) {
cIndices[j] = IndicesUtils.getNameWithType(cIndices[j]);
fIndices[j] = IndicesUtils.getNameWithType(fIndices[j]);
}
IndexMappingImpl im = new IndexMappingImpl(new int[0], fIndices, cIndices);
fArg = ApplyIndexMappingTransformation.INSTANCE.perform(fArg, im);
}
if (!IndexMappings.mappingExists(fromArgs[i], fArg, allowDiffStates))
throw new InconsistentSubstitutionException(from, to, current);
transformations.add(Substitutions.createSubstitution(fArg, currentArgs[i], allowDiffStates));
}
Tensor newTo = to.clone();
if (!allowDiffStates || !IndexMappingUtils.containsDiffStates(buffer))
newTo = ApplyIndexMappingTransformation.INSTANCE.perform(newTo, new IndexMappingImpl(iterator.usedIndices(), buffer));
else
newTo = ApplyIndexMappingUtils.applyIndexMappingWithDiffStates(newTo, buffer, iterator.usedIndices());
if (!transformations.isEmpty()) {
for (Transformation transformation : transformations)
newTo = transformation.transform(newTo);
int[] indices = newTo.getIndices().getFreeIndices().getAllIndices().copy();
for (i = 0; i < indices.length; ++i)
indices[i] = IndicesUtils.getNameWithType(indices[i]);
newTo = ApplyIndexMappingTransformation.INSTANCE.perform(newTo, new IndexMappingImpl(iterator.usedIndices(), indices, indices));
}
iterator.set(newTo);
}
Tensor result = tensorWrapper.getInnerTensor();
result.setParent(parent);