1
votes

I have a some predicates inside the recursion verif(X1,Y1,F). The first predicate is gen(X1,Y1,X2,Y2) which receives X1 and Y1 and generates the numbers X2 and Y2. The other predicates are the ones that I want to verify. If one of this predicates returns F=1 the loop should be restarted with verif(X2,Y2,F), but I dont know how to do this. If all the predicates return F=0 the recursion ends. Here is the example:

 verif(X1,Y1,0).

 verif(X1,Y1,F):-
                  gen(X1,Y1,X2,Y2),
                  pred1(X2,Y2,A,B,F),
                  pred2(X2,Y2,C,D,F),
                  pred3(X2,Y2,E,G,F),
                  verif(X2,Y2,F).

The problem is when the 3 predicates return diferent values for F it will fail. One way would be to use the predicate repeat until none of the predicates fails, but this way the predicate gen(X1, Y1, X2, Y2) would always generate the same X2 and Y2 because it would allways receive the same X1 and Y1.

1
So as soon as one of the pred1, pred2 or pred3 sees F = 1 then you want to backtrack or fail and have gen retrieve a new X2 and Y2? And does F only get a value of 0 or 1?lurker

1 Answers

0
votes

I think you can use different variables, and then test the values

verif(X1,Y1,F):-
   gen(X1,Y1,X2,Y2),
   pred1(X2,Y2,A,B,F1),
   pred2(X2,Y2,C,D,F2),
   pred3(X2,Y2,E,G,F3),
   (( F1 == 0, F2 == 0, F3 == 0 ) -> true ; verif(X2,Y2,F)).

or simpler

verif(X1,Y1,F):-
   gen(X1,Y1,X2,Y2),
   pred1(X2,Y2,A,B,F1),
   pred2(X2,Y2,C,D,F2),
   pred3(X2,Y2,E,G,F3),
   (F1 + F3 + F3 =:= 0 -> true ; verif(X2,Y2,F)).