|
View:
New views
4 Messages
—
Rating Filter:
Alert me
|
|
|
There must be an easier way!I am using prolog again after a twenty year hiatus and I feel like I am working way too hard.
My problem seems simple. In it's most general form I want to test the truth of falsehood the following: For all X in S foo(X). What I am doing is using findall to get a list of all X for which foo(X) is true. Then I get the size of the set S and I assert that the sizes are the same: forallXinS() :- findall(X,foo(X),B), length(B,N), s(P), length(P,N). This works, but it seems that there must be a better way. Similarly to test : For no X in S foo(X). I use findall and check if it returns an empty set. fornoX() :- findall(X,foo(X),[]). Again this seems like a hack. What is the best way to make these tests? -EdK Ed Keith e_d_k@... Blog: edkeith.blogspot.com _______________________________________________ SWI-Prolog mailing list SWI-Prolog@... https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog |
|
|
Re: There must be an easier way!On 2009/11/01, at 14:56, Ed Keith wrote: > I am using prolog again after a twenty year hiatus and I feel like I > am working way too hard. > > My problem seems simple. In it's most general form I want to test > the truth of falsehood the following: > > For all X in S foo(X). > > What I am doing is using findall to get a list of all X for which > foo(X) is true. Then I get the size of the set S and I assert that > the sizes are the same: > > forallXinS() :- findall(X,foo(X),B), > length(B,N), > s(P), > length(P,N). > > This works, but it seems that there must be a better way. > > Similarly to test : > > For no X in S foo(X). > > I use findall and check if it returns an empty set. > > fornoX() :- findall(X,foo(X),[]). > > Again this seems like a hack. > > What is the best way to make these tests? Take a look at the forall/2 built-in predicate. 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: There must be an easier way!Ed Keith <e_d_k@...> writes:
> For all X in S foo(X). In other words, there is no X in S such that NOT foo(X): \+ ( x_in_s(X, S), \+ foo(X) ) or: forall(x_in_s(X, S), foo(X)) > For no X in S foo(X). \+ ( x_in_s(X, S), foo(X) ) _______________________________________________ SWI-Prolog mailing list SWI-Prolog@... https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog |
|
|
Thanks: Re: There must be an easier way!I'd like to thank everyone who helped me.
I wish a list like this had been available in 1985 when I was first trying to learn prolog. It would have made it a LOT easier! Thanks a lot, -EdK Ed Keith e_d_k@... Blog: edkeith.blogspot.com --- On Sun, 11/1/09, Markus Triska <markus.triska@...> wrote: > From: Markus Triska <markus.triska@...> > Subject: Re: [SWIPL] There must be an easier way! > To: "Ed Keith" <e_d_k@...> > Cc: swi-prolog@... > Date: Sunday, November 1, 2009, 10:26 AM > Ed Keith <e_d_k@...> > writes: > > > For all X in S foo(X). > > In other words, there is no X in S such that NOT foo(X): > > \+ ( x_in_s(X, S), \+ foo(X) ) > > or: > > forall(x_in_s(X, S), foo(X)) > > > > For no X in S foo(X). > > \+ ( x_in_s(X, S), foo(X) ) > _______________________________________________ > SWI-Prolog mailing list > SWI-Prolog@... > https://mailbox.iai.uni-bonn.de/mailman/listinfo.cgi/swi-prolog > _______________________________________________ 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 |