Search code examples
prologclpq

Simple Constraint Logic Programming sample CLP(Q) gives error in Prolog


I've started to learn Prolog and I follow the RIPTutorial PDF. At the Constraint Logic Programming CLP(Q) section, it says:

Constraint Logic Programming CLP(Q) implements reasoning over rational numbers

Example:

?- { 5/6 = X/2 + 1/3 }.
X = 1.

When I've tried this line on SWI-Prolog on Windows, it gave:

ERROR: Unknown procedure: {}/1 (DWIM could not correct goal)

The same line on commandline SWI-Prolog-7.2.0 on macOS gives:

ERROR: toplevel: Undefined procedure: {}/1 (DWIM could not correct goal)

How to get the expected output of X = 1. ?


Solution

  • Using SWI-Prolog.

    As noted in the comments you need to load the code for CLP(Q) first.

    ?- use_module(library(clpq)).
    true
    

    Then enter the query as in the example.

    ?- {5/6 = X/2 + 1/3}.
    X = 1.