Rationals are now Numbers: The SWI Prolog doc needs an update

I have just noticed that the following succeeds:

?- X is 3r7, rational(X), number(X), atomic(X), \+atom(X), format("~q",[X]).

The documentation for number/1 still says

As rational numbers are not atomic in the current implementation and we do not want to break the rule that number/1 implies atomic/1, number/1 fails on rational numbers. This will change if rational numbers become atomic.

Well, the rational numbers are atomic now.

Btw, is there a way to “inspect” the “integer” that is currently in an X. To decide whether it is a machine integer or an integer from GMP. A bit in the spirit of float_parts/4. I can’t directly think of a use for that, but having an inspection trap to the bilge is always good.

1 Like

Thanks. Fixed.

No. Floats have “parts” by their very nature of being defined as mantissa*base^exp. Rationals are D/N, but integer is (AFAIK) a basic numeric concept. SWI-Prolog deliberately does not provide insight in how things are internally represented. GMP may be replaced, notably if commercial users who require unbounded arithmetic by do not want the GMP LGPL license initiate this.

At this moment, any integer that does not fit into a 64 bit signed int is a GMP mpz type and all rationals (not being an integer) are GMP mpq type.

2 Likes