prolog-setof

Prolog understanding setof/3 with ^ markings [duplicate]

微笑、不失礼 提交于 2021-01-29 02:37:09
问题 This question already has answers here : What is the Prolog operator `^` (“caret”)? (4 answers) Closed 10 months ago . Could someone explain to me what this is doing? (\+ setof((P1,C),P^R^Bag,PS) -> ... otherwise ->... I have read the documentation of setof; my understanding is that the thrid argument gets unified with the facts. However, I can't make sense of the code snippet above. The full snippet is: solve_task_bt(go(Target),Agenda,ClosedSet,F,G,NewPos,RR,BackPath) :- Agenda = [Current

How to choose between bagof, setof and findall in Prolog

自闭症网瘾萝莉.ら 提交于 2020-12-08 06:46:33
问题 How does one choose between bagof, setof and findall? Are there any important differences? Which is most commonly used and which is the safest? Thanks for your comments/answers. I checked the SWI-Prolog manual page on findall/3 and found them to be very similar. 回答1: That's a great question! I am not attempting to give an exhaustive answer, but I would like to suggest a few lines of thought that can help you to understand these predicates better: Think about which of these predicates are more

Don't repeat solutions in Prolog

我只是一个虾纸丫 提交于 2020-06-27 07:36:19
问题 Suppose you have a database with the following content: son(a, d). son(b, d). son(a, c). son(b, c). So a and b are sons of d and c. Now you want to know, given a bigger database, who is brother to who. A solution would be: brother(X, Y) :- son(X, P), son(Y, P), X \= Y. The problem with this is that if you ask "brother(X, Y)." and start pressing ";" you'll get redundant results like: X = a, Y = b; X = b, Y = a; X = a, Y = b; X = b, Y = a; I can understand why I get these results but I am

setof/3 inside setof/3 not working, but why?

泪湿孤枕 提交于 2020-03-22 09:00:26
问题 Inspired by Find mutual element in different facts in swi-prolog I wanted to try my hand at "RDBMS operations in Prolog" (actually, this is more or less Datalog) Problem statement Given a database of "actors starring in movies": starsin(a,bob). starsin(c,bob). starsin(a,maria). starsin(b,maria). starsin(c,maria). starsin(a,george). starsin(b,george). starsin(c,george). starsin(d,george). And given set of movies, find those actors that starred in all the movies of said set. I first had an ugly

Using a self-created list in prolog

那年仲夏 提交于 2019-12-24 00:46:49
问题 I'm pretty new to Prolog, Don't be too hard on me. Anyhow, I've got the next problem in Prolog: I've created a small 'database' of actors, defined by: actor(ID, Name). Same goes for movies,cast,Director, Defined by: movie(ID,Name, Director, Category). director(ID,Name). cast(MovieID, ActorID). Now i need to Write a procedure people(Movie, List) that defines the relation between movie name and list of names of all people participated in the movie - director and actors (in any order). So I've

Check if variable is empty or filled

牧云@^-^@ 提交于 2019-12-19 10:36:12
问题 I have the following problem: prolog prog: man(thomas, 2010). man(leon, 2011). man(thomas, 2012). man(Man) :- once(man(Man, _). problem: ?- man(thomas). true ; %i want only on true even if there are more "thomas" *working because of once()* ?- man(X). X = thomas ; %i want all man to be listed *isn't working* goal: ?- man(thomas). true ; ?- man(X). X = thomas ; X = leon ; X = thomas ; I do unterstand why this happens, but still want to get the names of all man. So my solution woud be to look

Prolog (Sicstus) - setof and findall combination issues

£可爱£侵袭症+ 提交于 2019-12-11 04:33:54
问题 Given a set of routes a given station has, such us : route(TubeLine, ListOfStations). route(green, [a,b,c,d,e,f]). route(blue, [g,b,c,h,i,j]). ... I am required to find names of lines that have a specific station in common. The result must be ordered, with non-repeated stations and must return an empty list, if there were no results. So, querying | ?- lines(i, Ls). Should give: Ls = [blue,red,silver] ? ; no I tried doing the following: lines(X, L) :- setof(L1, findall(W, (route(W, Stations)

run function with all possibilities resulted from other function

[亡魂溺海] 提交于 2019-12-10 23:53:35
问题 I have two predicates: foo(Y,X) bar(Y,Z) After running foo, How can I run bar with all possibilities of Y ? example: foo(Y, key) % all possibilities of Y => chat % faq % about % search How can I run bar with these all possibilities ? bar(chat, Z) bar(faq, Z) bar(about, Z) bar(serach, Z) And then store all the results of Z in a list Zs ? 回答1: allZs(X, Zs) :- setof(Y, foo(Y, X), Ys), maplist(bar, Ys, Zs). related SWI-Prolog man pages: Finding all Solutions to a Goal and library apply Note:

What is the Prolog operator ^?

我与影子孤独终老i 提交于 2019-12-10 03:47:00
问题 What is the Prolog operator ^ ? Looking at The Prolog Built-in Directive op gives a list of the built-in operators. I see ** is exponentiation /\ is or but what is ^ ? Each of the three current answers are of value and I learned something: Roy for the book false for the examples I accepted the answer by CapelliC because it made clear that ^/2 has multiple meanings depending on context which instantly cleared up my confusion. 回答1: In Prolog, most symbols can be used 'uninterpreted', at