if (tensor instanceof Product) {
int i;
int count = 0;
Tensor current;
IndicesBuilder ib = new IndicesBuilder();
List<Tensor> newProductElements = new ArrayList<>();
for (i = tensor.size() - 1; i >= 0; --i) {
current = tensor.get(i);
if (current instanceof SimpleTensor && ((SimpleTensor) current).getName() == const_n.getName()) {
ib.append(current);
++count;
} else
newProductElements.add(current);
}
if (count == 0)
return tensor;
if (count % 2 != 0)
return Complex.ZERO;
count = count / 2;
Tensor averaged = average(ib.getIndices().getAllIndices().copy());
long factor = ArithmeticUtils.pow((long) 2, count) * ArithmeticUtils.factorial(count + 1);
Complex number = new Complex((long) factor);
averaged = Expand.expand(averaged);
newProductElements.add(number);
newProductElements.add(averaged);