swi-prolog

Prolog wildcards

Hi guys, I was wondering, how would I use the underscore twice but check that both instances of that underscore unify? What I basically need is something that returns true if two elements of the same value in one mapping exist... I.E member((,),[(a,a),(b,a),(c,a)]). If I use a variable does that make them unified? I.E ...

Prolog routing routine

Hi, I am trying to write a routing function but I cannot seem to get the result needed. This is the code so far. Predecessor finds the node that is linked to N and returns it as P. traceroute(_,L) :- member((A,A),L). traceroute(N,L) :- predecessor(N,P), append(N,L,L1), traceroute(P,L1). When I run my traceroute(placeA, Y). it retur...

prolog program for determining whether any two pairs in a list have the same sum

How can I write a relation in prolog that determines if there are any two pairs in a list with the same sum. The relation should fail if there exist no pairs whose sums are equal. The relation should also fail if the list contains less than four elements. list([1 2 3]) fails since it only has 3 elements list([2 3 4 1]) succeeds since...

Prolog syntax - using function results

Hi, I am trying to perform a sum operation on every result of : combination(0,_,[]). combination(K,L,[X|Xs]) :- K > 0, el(X,L,R), K1 is K-1, combination(K1,R,Xs). el(X,[X|L],L). el(X,[_|L],R) :- el(X,L,R). For example, the user will enter is_sum_equal_10 ([1,2,3,4,5,6,7]) and the result will be true if the sum of any of the permut...

Reversing Part of a List in Prolog

My goal for this Prolog function is as follows: Given two lists, x and y, return true if y can be formed from x by reversing a contiguous part of list x. For example, if the input is x = [1, 3, 2, 4], y = [1, 2, 3, 4], the result should be "true" because we can reverse the second and third elements of x to get y. I really have no ide...

a relation in prolog to shift elements left rotationally

I need a relation in prolog to shift list left rotationally by one element such that ?shift([1,2,3],L) should produce L=[2,3,1]. could you help me? ...

prolog backtracing using mysql

my problem i have a system build in php.in one part of the system i need to make the system can suggest the list of qualfied candidate which the candidate information are from mysql ,,this rule make ussing prolog backtracking technic...? ...

Becoming operational in Prolog ASAP

Hi all, May be this sort of question has been asked many times( as I see the list when I move the cursor to this messagebox), But my company has a project running in Prolog and I want to clarify few things about how to go about learning it. I know Prolog is different. It should not be learnt just like any other language. Having said t...

how to display blackshashes in SWI-Prolog

Hi, I am trying to display a network share path in my Prolog output code. The path is like : \\fileserver\path\to\file.txt (ex1) or \\\\fileserver\\path\\to\\file.txt (ex2) but If I try displaying it using format : pri(Z):- format('Printing Zx : \"~w\"',[Z]). the slashes get truncated to \fileserverpathtofile.txt...

jpl:communicating prolog from java

I'm implementing a software by jpl provided by swi-prolog for calling prolog from java. I'm using Eclipse as IDE. I don't know how to start this example very useful for my purposes that I found on line with other prolog files. Here the java code: package prolog; import java.awt.Container; import java.awt.FlowLayout; import java.awt.ev...

Scheduling of tasks to a single resource using Prolog

I searched through here as best I could and though I found some relevant questions, I don't think they covered the question at hand: Assume a single resource and a known list of requests to schedule a task. Each request includes a start_after, start_by, expected_duration, and action. The goal is to schedule the tasks for execution as s...

Translate Prolog Words

Hello hello :D :D I'm working on this this wonderful Prolog project and I'm stuck at this situation where I need to translate certain words into other words (e.g "i" into "you". "my into "your") This is what I've done and I'm pretty sure it's kidna iffy. I enter the sentence and when It goes to convert it only changes the one word th...

Prolog random and findall buit-ins

Ok! last Prolog question for a loong time!! I'm trying to pick a response that is picked at random but all I can seem to do is pick the first one out of my tables of responses (see code) I'm sure it's done with Prologs "findall" and "random" but how? pick_response(Sent, R) :- response(Sent, R), !. pick_response(_,R) :- punt(...

Extending a Prolog goal through recursion?

I've implemented (finally) a few goals that will schedule a series of tasks according to a startBy startAfter and duration. The schedule goal however, accepts only the prescribed number of tasks. I'd like to extend the functionality of the schedule goal to accept a single list and iterate through that list while scheduling. unfortunatel...

Returning a value after a recursion in Prolog

Hello, I decided to study some logic programming and I stumbled across a problem. It is programmed in SWI Prolog. test(A, B, N):- nonvar(B), B = final, true. test(A, B, N):- N > 2, test(A, final, N). test(A, B, N):- N1 is N + 1, test(N1, B, N1). It is just a sample with no real use except it is driving me crazy. The problem ...

Two stars in a Prolog list

Hi, what are the two stars in a list? [53, 5, 1, 53, 97, 115, 53, 50, 52, 121, 55, 56, 55, 97, 4, 1, 98, **] I tried searching but no success. Thanks, Jan ...

Vector addition in prolog

I'm writing a predicate to add two vectors. This is what I came up with: add( [], [], 0 ). add( [A], 0, A ). add( [A], [B], C ) :- C is A + B. add( A, B, C ) :- add( B, A, C ). add( [H1|T1], [H2|T2], WYNIK ) :- X is H1 + H2, add( T1, T2, Y ), append( [X], Y, WYNIK ). First four lines work just fine, but I can't get the last one to wor...

Prolog - SWI specifically - where is pl located?

Hello guys, I'm trying to set up an environment with interprolog and SWI prolog, interprolog needs the location of swi's "pl" but i cant find it. All i can find is swipl or plrc and neither work with interprolog. If i type pl into the terminal(this should run swi-prolog) it says bash: pl :command not found but if i type in swipl o...

Unexpected output of a Prolog script

leftHand(empty). rightHand(empty). inHands :- write("Left hand:"), nl, leftHand(X), tab(2), write(X), nl, nl, write("Right hand:"), rightHand(Y), tab(2), write(Y), nl. I expect inHands. to return something like this: Left hand: empty Right hand: empty However, this is what I saw:...

Random items in Prolog

I know I can do X is random(10). to get a random number from 0 to 10, but is there a similar command to get a random matching item? ...