'how to input clingo variable

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).


Solution 1:[1]

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

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 DuDa