identifying which predicate failed

31 views
Skip to first unread message

Dan

unread,
Aug 2, 2018, 1:58:42 AM8/2/18
to SWI-Prolog
Hello, 

In checking the properties of a structure I have property identification tests, each comprising a number of predicates. The structure exhibits a property when all predicates succeed, and  not, if at least one in the series of predicates fails. 

This looks something like this:

property_test(p1) :-
  test1(S, X, Y),
  test2(S, Y, Z),
  test3(S, Z, _M).


Typically, this involves a lot of backtracking, before success or failure can be determined.

If there is failure I want to know which predicates failed the property test. 

I tried an -> structure wrapped around a single test predicate, but I think this wont work because tests fail and backtrack and can then succeed. An if structure would abort the next trials. 

nop.

property_test(p1) :-
  (test1(S, X, Y)-> nop; message(1)), 
  (test2(S, Y, Z),-> nop; message(2)),
 (test3(S, Z, _M) -> nop; message(3)).



Any suggestion are most welcome, 

thank you,

Dan

Paul Singleton

unread,
Aug 2, 2018, 7:20:26 AM8/2/18
to SWI-Prolog
You cannot prove a negative - if a goal fails it is because no proof was found - there is no particular reason why.

But suppose you could capture all the explored paths of your unsuccessful search: which ones are significant to you? You need to formalise this.

Then you need a Prolog-in-Prolog interpreter which logs failed branches of the proof.

Perhaps start by playing with spypoints and leashing?

Paul Singleton

Paulo Moura

unread,
Aug 2, 2018, 8:05:21 AM8/2/18
to Dan, SWI-Prolog
Hi Dan,

Something along the lines of the assertion/1 predicate may help:

http://www.swi-prolog.org/pldoc/doc_for?object=assertion/1

Cheers,
Paulo
> --
> You received this message because you are subscribed to the Google Groups "SWI-Prolog" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to swi-prolog+...@googlegroups.com.
> Visit this group at https://groups.google.com/group/swi-prolog.
> For more options, visit https://groups.google.com/d/optout.

Barb Knox

unread,
Aug 2, 2018, 4:57:00 PM8/2/18
to SWI-Prolog, Dan
How about:

property_test(p1) :-
   (  nb_setval(failed, test1),
      test1(S, _X, Y),
      %
      nb_setval(failed, test2),
      test2(S, Y, Z),
      %
      nb_setval(failed, test3),
      test3(S, Z, _M)
   )
-> true % All test predicates succeed.
;  nb_getval(failed, Test),
   message(p1, Test),
   fail.
   

thank you,

HTH.

Dan

-- 
---------------------------
|  BBB                b    \    Barbara at LivingHistory stop co stop uk
|  B  B   aa     rrr  b     |
|  BBB   a  a   r     bbb   |   ,008015L080180,022036,029037
|  B  B  a  a   r     b  b  |   ,047045,L014114L4.
|  BBB    aa a  r     bbb   |
-----------------------------

Dan

unread,
Aug 2, 2018, 4:59:56 PM8/2/18
to SWI-Prolog
Hi Barb, 

This code looks beautiful!

thank you,

Dan
Reply all
Reply to author
Forward
0 new messages