Automaton.Bag terms = (Automaton.Bag) automaton.get(args.get(1));
// Must use abs() here, otherwise can end up with negative gcd.
// This is problematic for inequalities as it necessitate
// changing their sign.
BigRational gcd = constant.value.abs();
if(gcd.equals(BigRational.ZERO)) {
// Basically, if there is no coefficient, then ignore it.
gcd = null;
}
// Now, iterate through each term examining its coefficient and
// determining the GreatestCommonDivisor of the whole lot.
for(int i=0;i!=terms.size();++i) {
int child = terms.get(i);
Automaton.Term mul = (Automaton.Term) automaton.get(child);
Automaton.List ls = (Automaton.List) automaton.get(mul.contents);
Automaton.Real coefficient = (Automaton.Real) automaton.get(ls.get(0));
BigRational val = coefficient.value;
if(gcd == null) {
// Must use abs() here, otherwise can end up with negative gcd.
// This is problematic for inequalities as it necessitate
// changing their sign.
gcd = val.abs();
} else {
// Note, gcd of two numbers (either of which may be negative) is
// always positive.
gcd = gcd.gcd(val);
}