prolog

GNU Prolog - Recursion problem (easy?)

Ok, so i have this edu_less(hs,college). edu_less(college,masters). edu_less(masters,phd). I need to write a function to tell if something is than the other. The predicate is edu_le. So if i put edu_le(hs,phd). it should return yes. I came up with this. edu_le(A,B) :- A = B. edu_le(A,B) :- edu_less(A,B). edu_le(A,B) :- edu_less(A,...

Prolog loops and conditional statements?

Is there anything in Prolog that works like a for loop and if then condition? ...

Prolog, find minimum in a list.

Hi, in short: How to find min value in a list? (thanks for the advise kaarel) long story: I have created a weighted graph in amzi prolog and given 2 nodes, I am able to retrieve a list of paths. However, I need to find the minimum value in this path but am unable to traverse the list to do this. May I please seek your advise on how t...

Prolog, counting from an interval; (SWI-PROLOG)

Hello, I have a small question. I need to make a predicate that counts from a natural number to some other natural number. I have to implement a check too, that the second interval is bigger than the first one. However I got stuck during my way. Here is my code (SWI-PROLOG) count(O, _, O). count(A, B, C) :- count(A, B, D), C is D+1, C ...

Traverse undirected graph in prolog

Hi everyone, In short: I am trying to traverse an undirected graph in prolog, but don't know how to, any advise would be greatly appreciated. Background: Trying to model rail system, with stations as nodes and their links as edges with weight 1. I had no problem doing it in a directed manner, but cant do it in an undirected graph. ...

lists inside a list

i am writing a predicate in prolog to delete an atom in a list, but i stuck on how to check if the atom is whether a list inside a list. any suggestions. ...

Recursion Append list

Heres a snippet: translate("a", "4"). translate("m", "/\\/\\"). tol33t([], []). tol33t([Upper|UpperTail], [Lower|LowerTail]) :- translate([Upper], [Lower]), tol33t(UpperTail, LowerTail). Basically what i want to do is look up in the table for a letter and then get that letter and add it to the new list. What i have works if ...

Matching Multiple Lists

Hi there, I can write a predicate that is satisfied when two lists are equal e.g. equal([2,3],[2,3]) would be true and equal([2,3],[4,5]). would be false. However, what if I want to have a list and try and match it with any list in a list of lists e.g. match([2,3],[[5,6],[4,6,2],[2,3]]). would be true because of the last list in the li...

Stack overflow in Prolog

I am trying to write Prolog code to determine whether the bound variable X is in the scope of the bound variable Y in a list. Lists may be nested and X is in the scope of Y if X and Y are members of the same list or if X is a member of a list that is a member of a list that is a member of a list...(nested indefinitely) that is in the sam...

Prolog - call a rule with fact

TL;DR: Need help calling a rule with a fact I´ve started out with prolog, coming from C and got stuff working... until they evidently got broken. I´m writing a small car-paint program for myself as I´m learning this new language Im trying to call a rule with a fact (is this possible?), what I want to do is use one fact "cars" and anothe...

Pattern matching list of lists

Hi. I have a problem where I have a list like this: [[el1, el2, el3], [el4, el5, el6], [[el7, el8, el9], [el10, el11, el12], ..... , [elxx, elyy, elzz]], [el, el, el]...]] I want to pattern match the inner list of lists, the [el7, el8, el9], [el10, el11, el12], ..... , [elxx, elyy, elzz] How can this be done? As of now I pattern...

Prolog GNU - Having a difficult time with this, lists and recursion

So , i still don't completely understand how lists and recursion work in prolog, could be why i am having trouble with this, but i don't even know how to begin this problem. There is a list of friends. f(a,b). f(a,c). f(a,d). f(b,c). f(b,e). f(b,f). f(c,e). f(c,g). f(g,e). etc.. I have to find if someone is a friend through someone e...

GNU Prolog - Build up a list in a loop

I need to build a new list with a "loop". Basically i can't use recursion explicitly, so i am using append to go through lists of list. I can get the element. Problem is i need to check this element and if something is true it returns another element i need to put back into the list. It does check correctly and it changes correctly. Pr...

Prolog - return value from base case

Ok, here's the deal: I've got two piles of shirts I want to take a random shirt from each pile and put them in a new pile Then get the new pile out And here is the code: mix([],[],_). mix(P1,P2, Pile):- takeshirt(P1,1,Taken1,Rem1), takeshirt(P2,1,Taken2,Rem2), #Take one append(Pile,Taken1,New), append(New,Taken2,New...

Using prolog to output into bash shell

Hi. I am trying to call a prolog program and receive output into my bash script. Currently I am using the extremely crude version of using halt(0) or halt(1) and then examining the exit code in bash, using 0 as true and 1 as false to the question my prolog program answers. Is there a better way to handle output? I am using gnu prolog. I...

Help In Learning Prolog

Hello Guys Please forgive me if this is the wrong place for asking this question. Kindly point me to the right place. Thanks. I am learning prolog and need help finding a good book that can help me understand it so that i can do all my assigments. At the moment i have LEARN PROLOG NOW from Blackburn but it seems i still miss some thing...

Prolog query to find largest element in database?

If I have defined all the digits in a prolog database, such as dig(0),dig(1)...dig(9), what query can I use for prolog to return the largest digit, so 9? I tried something like dig(N),dig(M),N>M, but that just returns the first possibility, not the largest number. ...

Logically Handling Lists

I have a large number of facts within my program, listing developers and designers in a company, as well as previous projects, like so.. % project(Project Name,Year) project(efnet, 2007). % designer(Project Name, Name, Role) designer(efnet, jane_cole, lead). % developer(Project Name, Name, Role) developer(efnet, alex_tobbs, architect). ...

Prolog - get the first list from a list of lists

I've got a list consisting of smaller lists inside of it, each list consisting of 2 items: [[a,1],[b,2],[c,3]] I'm using a function called take(1,L,R) to take the first item from list L and return the item R. The code for the take function is here: take(0,X,X). take(N,[H|T],[H|R]):- N>0, M is N-1, take(M,T,R). At t...