current = iterator.next();
if (current instanceof Fraction) {
Fraction temp = (Fraction) current;
if (Fraction.onDenominatorIndicator.is(iterator))
return new Fraction(new Product(fraction.getNumerator(), temp.getDenominator()), temp.getNumerator());
else
return new Fraction(temp.getNumerator(), new Product(fraction.getDenominator(), temp.getDenominator()));
}
if (current instanceof Product) {
List<Tensor> multiplicands = new ArrayList<>();
TensorIterator it = current.iterator();
Tensor current1;
while (it.hasNext()) {
current1 = it.next();
if (current1 instanceof Fraction) {
Fraction currentFraction = (Fraction) current1;
multiplicands.add(currentFraction.getDenominator());
it.set(currentFraction.getNumerator());
}
}
if (multiplicands.isEmpty())
return tensor;
Product newNumerator = new Product();
if (Fraction.onDenominatorIndicator.is(iterator)) {
newNumerator.add(fraction.getNumerator());
newNumerator.add(multiplicands);
return new Fraction(newNumerator, fraction.getDenominator());
} else {
newNumerator.add(fraction.getDenominator());
newNumerator.add(multiplicands);
return new Fraction(fraction.getNumerator(), newNumerator);
}
}
}
return tensor;