how to input clingo variable

454 Views Asked by At

I have following code, but I want to change the variable of p, how can I do it?

{p(1;2;3;4)}.
:- p(X*2).

It is normal. But the following code does'nt work.

p(1;2;3;4)

{p(X)} :- X = p(X).
:- p(X*2).
1

There are 1 best solutions below

0
On

In ASP truth values do not change over time, either atoms are true or false for a specific answer set, they can not be overwritten. However you are free to introduce auxiliary predicates, for example:

p(1;2;3;4).
{q(X)} :- p(X).
:- q(X*2).
#show q/1.

The last line limits the output to just show the predicate q with arity 1. Output:

Answer: 1

Answer: 2
q(3)
Answer: 3
q(1)
Answer: 4
q(1) q(3)
SATISFIABLE