User:Paolo Liberatore~enwiki/Fresh variant

In logic programming, a fresh variant of a clause is a rewriting of the clause using new variables. The use of fresh variants is necessary to avoid the variables of a rule to be incorrectly bound to the values of variables that are used somewhere else in the program.

As an example, the rule  tells that   is true for any value of its argument that makes   true. However, when applying such a rule, the variable  may be already used somewhere else in the program, this interfering with the correct application of this clause. This happens, for example, when evaluating the goal  against the following logic program:

C(a):-A(d) A(X):-B(X) B(d)

In the first step,  is unified with , generating the substitution  , and replacing   in place of the goal. If using  instead of a fresh variant to it, this rule would be equivalent to , whose head does not unify with   and whose body cannot be proved. On the other hand,  should be provable, as   is in the program.

Using a fresh variant, this problem does not occur: the goal   unifies with the head of this fresh variant under the substitution  , and the goal is proved.

Category:Logic programming