Found a bug in trace; should be fixed with next changes
Work around sympy cache by keeping index of tensors