Module rational

This module provides rational constants. The module is responsible for the reduction rules that perform partial evaluation. The result can be also an integer. In case that some extra arguments is not rational, the rules delegate to the polynom and fraction methods since a rational can be easily also viewed as a polynom or fraction.

Examples:
?- X is 2/3*(3/2).
X = 1
?- X is 1/2*(Y+2).
X is 1+1/2*Y

The reduction rules are just predicates inside the rational module with a Python first argument for the method receiver. We provide reduction rules for basic arithmetic. The only special function supported so far is the sqrt/1 constructor. Other special functions are currently not supported. Error handling is rudimentary.

The following rational constant predicates are provided:

-(P, Q):
The predicate succeeds in Q with the P negated.
+(P, Q, R):
The predicate succeeds in R with the sum of P and Q.
-(P, Q, R):
The predicate succeeds in R with P subtracted by Q.
*(P, Q, R):
The predicate succeeds in R with the product of P and Q.
/(P, Q, R):
The predicate succeeds in R with P divided by Q.
^(P, Q, R):
The predicate succeeds in R with P raised by Q.
sqrt(P, Q):
The predicate succeeds in Q with the square root of P.

Comments