clpfd - Constraint - SWI- Prolog Queries -
i have exam coming , i'm going through past papers understanding.
i came across following past paper question:
consider following queries , answers. answers coincide swi-prolog infer whereas others erroneous. indicate answers genuine , ones fake (no explanation of answer required).
(i) |?- [a, b, c] ins 0 .. 2, #= b + c. = 0..2 b = 0..2 c = 0..2 (ii) |?- in 0 .. 3, * #= a. = 0..2 (iii) |?- [a, b] ins -1 .. 1, #= b. = 1 b = 1 (iv) |?- [a, b] ins 0 .. 3, #= b + 1. = 1..3 b = 1..2
i'm struggling see how each 1 either true or false. able explain me how figure these out please.
thank you, appreciate help.
the key principle deciding answers admissible , not whether residual program declaratively equivalent original query. if residual constraints admit solution original query not, or other way around, answer fake (or have found mistake in clp(fd) solver). if shown answer not syntactically valid, answer definitely fake.
let's it:
(i)
|?- [a, b, c] ins 0 .. 2, #= b + c.
suggested answer:
a = 0..2 b = 0..2 c = 0..2
wrong! original query constrains variables integers, answer not syntactically valid prolog program.
(ii)
|?- in 0 .. 3, * #= a.
suggested answer:
a = 0..2
wrong! original query constrains
a
integers, according residual program,a = 0..2
valid solution. term..(0, 2)
not integer.(iii)
|?- [a, b] ins -1 .. 1, #= b.
suggested answer:
a = 1 b = 1
wrong! not syntactically valid.
(iv)
|?- [a, b] ins 0 .. 3, #= b + 1.
suggested answer:
a = 1..3 b = 1..2
wrong! not syntactically valid.
note if shown answers syntactically valid and =/2
replaced in/2
in residual goals of (i), (ii) , (iv), these answer still wrong, because can in each case find solutions either not admissible original query or residual goals, not both. leave solving these cases exercise you, example, suppose respective answers are:
a in 0..2, b in 0..2, c in 0..2.
a in 0..2.
a = 1, b = 1.
a in 1..3, b in 1..2.
and find witness each case show residual goals semantically different respective original query.
for example, in case (1), a = b = c = 2
valid solution according residual constraints, original constraints exclude solution, because 2 #= 2 + 2
not hold!
Comments
Post a Comment