|
View:
New views
5 Messages
—
Rating Filter:
Alert me
|
|
|
Forall in SWI PrologDear All, I am running into a problem with forall predicate of SWI-Prolog. I have the following predicate that tries to match all subjectMatch(....) with rSub(...). This makes sure all different combinations of subjectMatch(...) facts with different RID and RValue values are matched. However, forall returns True when the Condition section of forall predicate is not matched. That means if there is no fact matching the condition of forall (that is subjectMatch(P,R,N,RID,RValue)) forall returns True as a default value. subjectS(P,R,N) :- forall(subjectMatch(P,R,N,RID,RValue), rSub(RID,RValue)). Is there a way to get around this? I mean if the condition of forall is not matched at all, how can I get a false? Any suggestions are welcome. Thanks in advance. -- Fatih Turkmen _______________________________________________ SWI-Prolog mailing list SWI-Prolog@... https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog |
|
|
Re: Forall in SWI PrologOn 2009/07/04, at 17:48, Fatih TURKMEN wrote: > > Dear All, > > I am running into a problem with forall predicate of SWI-Prolog. I > have the following predicate that tries to match all > subjectMatch(....) with rSub(...). This makes sure all different > combinations of subjectMatch(...) facts with different RID and > RValue values are matched. However, forall returns True when the > Condition section of forall predicate is not matched. That means if > there is no fact matching the condition of forall (that is > subjectMatch(P,R,N,RID,RValue)) forall returns True as a default > value. > > subjectS(P,R,N) :- forall(subjectMatch(P,R,N,RID,RValue), > rSub(RID,RValue)). > > Is there a way to get around this? I mean if the condition of forall > is not matched at all, how can I get a false? subjectS(P, R, N) :- \+ \+ subjectMatch(P, R, N, _, _), forall(subjectMatch(P, R, N, RID, RValue), rSub(RID, RValue)). Cheers, Paulo ----------------------------------------------------------------- Paulo Jorge Lopes de Moura, PhD Assistant Professor Dep. of Computer Science, University of Beira Interior 6201-001 Covilhã, Portugal Office 3.18 Ext. 3276 Phone: +351 275319891 Fax: +351 275319899 Email: <mailto:pmoura@...> Home page: <http://www.di.ubi.pt/~pmoura> Research: <http://logtalk.org/> Blog: <http://blog.logtalk.org/> ----------------------------------------------------------------- _______________________________________________ SWI-Prolog mailing list SWI-Prolog@... https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog |
|
|
|
|
|
Re: Forall in SWI PrologOn 2009/07/04, at 21:05, Fatih TURKMEN wrote: > Thank you very much for your prompt response. I didn't understand > the reason behind True in the case of Condition mismatch of Forall. > Is there an explanation that I can foresee or just an implementation > issue? I am not aware if Sics says anything about this. The meta_predicate forall/2 behaves as defined by the following clause: forall(Generate, Test) :- \+ (Generate, \+ Test). Cheers, Paulo ----------------------------------------------------------------- Paulo Jorge Lopes de Moura, PhD Assistant Professor Dep. of Computer Science, University of Beira Interior 6201-001 Covilhã, Portugal Office 3.18 Ext. 3276 Phone: +351 275319891 Fax: +351 275319899 Email: <mailto:pmoura@...> Home page: <http://www.di.ubi.pt/~pmoura> Research: <http://logtalk.org/> Blog: <http://blog.logtalk.org/> ----------------------------------------------------------------- _______________________________________________ SWI-Prolog mailing list SWI-Prolog@... https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog |
|
|
Re: Forall in SWI PrologOn Jul 5, 2009, at 4:48 AM, Fatih TURKMEN wrote: > > Dear All, > > I am running into a problem with forall predicate of SWI-Prolog. I > have the following predicate that tries to match all > subjectMatch(....) with rSub(...). This makes sure all different > combinations of subjectMatch(...) facts with different RID and > RValue values are matched. However, forall returns True when the > Condition section of forall predicate is not matched. forall(Generator, Test) is true if and only if there is no provable instance of Generator for which Test does not have a provable instance It is an approximation to ∀ x g(x) ⟶ t(x) By its semantics, it *MUST* be true when Generator has no provable instances. This isn't in any sense a "default" value; there is nothing optional or unmotivated about it, the logical formula (forall x) G(x) -> T(x) just *is* true when G(x) is always false. > That means if there is no fact matching the condition of forall > (that is subjectMatch(P,R,N,RID,RValue)) forall returns True as a > default value. > > subjectS(P,R,N) :- forall(subjectMatch(P,R,N,RID,RValue), > rSub(RID,RValue)). The layout here is confusing, to put it mildly. > > > Is there a way to get around this? I mean if the condition of forall > is not matched at all, how can I get a false? The very first thing is to be very clear about what you MEAN. What would a predicate that otherwise behaved like forall/2 but failed when the Generator had no solutions *MEAN*? What do you in fact want subjectS to *MEAN*? It would be extremely easy to make a predicate that *behaved* the way you apparently want; I am having real trouble understanding what it is supposed to mean or why it would be thought useful. CouldYouPerhapsStartByTellingUsWhatThePredicates subjectS/3, subjectMatch/5, and rSub/2 *mean*? I'mStressingTheWord *Mean* becauseThatIsWhatPrologProgramming isSupposedToBeAbout: meaning comes first, behaviour comes second. AndIfYouDon'tLikeTextWrittenInThisStyle, whyDoYouWriteYourPredicateNamesThatWay? _______________________________________________ SWI-Prolog mailing list SWI-Prolog@... https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog |
| Free embeddable forum powered by Nabble | Forum Help |