1

I am using SWI-Prolog with the clpr library for solving constraints over real numbers. I do this by calling SWI-Prolog from the command line and parsing the output by another program.

For example, to solve something like {F = 1.8 * C + 32}, {C = 25}. I generate the following command:

swipl \
  -g "use_module(library(clpr))" \
  -g "{F = 1.8 * C + 32}, {C = 25}, write(\"F -> \"), write(F), write(\"\\n\")" \
  -g halt

And the output from SWI-Prolog is:

F -> 77.0

This works great if the result is a plain number but not if the result is again a constraint (or a more complex solution in general). For example, for {X > 3}, {Y < 5}, {X + Y = 10}. I get the solution {Y < 5.0, X = 10.0 - Y} in the SWI-Prolog environment but I did not found a way to write this to the command line output. Is there a way to do this?

Michael
  • 4,722
  • 6
  • 37
  • 58
  • Sure you do not want to use [tag:clpq] in stead? clpr is riddled with numerical problems everywhere... – false Sep 18 '17 at 17:18

1 Answers1

2

You can use dump/3 predicate, for example:

{X > 3}, {Y < 5}, {X + Y = 10}, dump([X,Y], [x,y], L), write(L).

produces:

 [y=10.0-x,x>5.0]
code_x386
  • 778
  • 3
  • 5