* numbers
*/
public static OrderedPair toSameType(Expression a, Expression b) {
if (a instanceof NaturalNumber) {
if (b instanceof NaturalNumber) {
return new OrderedPair(a, b);
} else if (b instanceof IntegerNumber) {
return new OrderedPair(((NaturalNumber) a).toInteger(), b);
} else if (b instanceof RationalNumber) {
return new OrderedPair(((NaturalNumber) a).toRational(), b);
} else if (b instanceof RealNumber) {
return new OrderedPair(((NaturalNumber) a).toReal(), b);
}
} else if (a instanceof IntegerNumber) {
if (b instanceof NaturalNumber) {
return new OrderedPair(a, ((NaturalNumber) b).toInteger());
} else if (b instanceof IntegerNumber) {
return new OrderedPair(a, b);
} else if (b instanceof RationalNumber) {
return new OrderedPair(((IntegerNumber) a).toRational(), b);
} else if (b instanceof RealNumber) {
return new OrderedPair(((IntegerNumber) a).toReal(), b);
}
} else if (a instanceof RationalNumber) {
if (b instanceof NaturalNumber) {
return new OrderedPair(a, ((NaturalNumber) b).toRational());
} else if (b instanceof IntegerNumber) {
return new OrderedPair(a, ((IntegerNumber) b).toRational());
} else if (b instanceof RationalNumber) {
return new OrderedPair(a, b);
} else if (b instanceof RealNumber) {
return new OrderedPair(((RationalNumber) a).toReal(), b);
}
} else if (a instanceof RealNumber) {
if (b instanceof NaturalNumber) {
return new OrderedPair(a, ((NaturalNumber) b).toReal());
} else if (b instanceof IntegerNumber) {
return new OrderedPair(a, ((IntegerNumber) b).toReal());
} else if (b instanceof RationalNumber) {
return new OrderedPair(a, ((NaturalNumber) b).toReal());
} else if (b instanceof RealNumber) {
return new OrderedPair(a, b);
}
}
return new OrderedPair(a, b);
}