prolog

Prolog permutation predicate using insertion of elements

大憨熊 提交于 2020-01-25 21:46:09
问题 I am trying to write a predicate permutation/2 so that it is true if and only if both arguments are list, one a permutation of the other. To do this, I've written the two helper predicates delete/3 and insert/3 . The first is true if and only if the third argument is the second argument, both lists, with the first instance of the element in the first argument removed. The second is true if and only if the third argument equals the second argument with the first argument (element) inserted.

Does SLD tree exist if the query is invalid in Prolog?

自闭症网瘾萝莉.ら 提交于 2020-01-25 10:14:02
问题 Considering the following Prolog program : reverse_bits([1], [0]). reverse_bits([0], [1]). reverse_bits([H|T], [0|R]) :- H==1, reverse_bits(T, R). reverse_bits([H|T], [1|R]) :- H==0, reverse_bits(T, R). What's the SLD tree for the question above ? reverse_bits(Input, [1, 0, 0]).? It's not valid so does it even exist a SLD tree ? 回答1: Here is a minimal example using the sldnfdraw package. First, generate a program and query using the syntax specified in the library documentation: % estamos.pl

Anytime strongly connected components via Prolog

回眸只為那壹抹淺笑 提交于 2020-01-25 09:18:04
问题 Markus Triska has reported an algorithm to determine strongly connected components (SCC). Is there a solution which determines the SCC without making use of attributed variable and that can work anytime. So that some vertices can have infinitely many edges? I am asking because I am wondering whether B-Prologs anytime tabling which they call eager can be replicated. B-Prolog determines clusters which is their name for SCC. But it has also a tabling mode where it returns tabled results eagerly.

Out Of Global Stack Error in Prolog

时光怂恿深爱的人放手 提交于 2020-01-25 04:22:07
问题 I am trying to run the following program in Prolog. mama_mia1(A,M,LI,HI,LO,HO,AA) :- p1(A,M,LI,HI,LO,HO,PROGS), reverse(PROGS,PROG), atom_chars(AA,PROG), !. p1(_,_,LO,LO,LO,_,[]). p1(_,_,HO,HO,_,HO,[]). p1(_,_,LO,HO,LO,HO,[]). p1(_,_,X,LO,LO,HO,[]) :- X>LO,X<HO. p1(_,_,X,HO,LO,HO,[]) :- X>LO,X<HO. p1(_,_,LO,Y,LO,HO,[]) :- Y>LO,Y<HO. p1(_,_,HO,Y,LO,HO,[]) :- Y>LO,Y<HO. p1(_,_,X,Y,LO,HO,[]) :- X>LO,X<HO,Y>LO,Y<HO. p1(A,M,X,Y,LO,HO,PROG) :- ( (X1 is X+A, H1 is HO+1, X1<H1, Y1 is Y+A, Y1<H1 ) ->

Out Of Global Stack Error in Prolog

徘徊边缘 提交于 2020-01-25 04:21:05
问题 I am trying to run the following program in Prolog. mama_mia1(A,M,LI,HI,LO,HO,AA) :- p1(A,M,LI,HI,LO,HO,PROGS), reverse(PROGS,PROG), atom_chars(AA,PROG), !. p1(_,_,LO,LO,LO,_,[]). p1(_,_,HO,HO,_,HO,[]). p1(_,_,LO,HO,LO,HO,[]). p1(_,_,X,LO,LO,HO,[]) :- X>LO,X<HO. p1(_,_,X,HO,LO,HO,[]) :- X>LO,X<HO. p1(_,_,LO,Y,LO,HO,[]) :- Y>LO,Y<HO. p1(_,_,HO,Y,LO,HO,[]) :- Y>LO,Y<HO. p1(_,_,X,Y,LO,HO,[]) :- X>LO,X<HO,Y>LO,Y<HO. p1(A,M,X,Y,LO,HO,PROG) :- ( (X1 is X+A, H1 is HO+1, X1<H1, Y1 is Y+A, Y1<H1 ) ->

Is there a way to use module/2 in ECLiPSe Prolog?

浪尽此生 提交于 2020-01-25 03:39:06
问题 In SWI-Prolog, I am using code such as at the beginning of a module text file: :- module(foo, [bar/2]). :- use_module(library(jack)). I don't want to change my code . How can I neverthelss use ECLiPSe Prolog (*). Is there some library that defines a module/2 directive in ECLiPSe Prolog? Best Regards (*) http://eclipseclp.org/ 回答1: The following code defines a macro that maps module/2 into module/3 directives: :- export macro((:-)/1, translate_directive/2, [top_only]). translate_directive( (:-

Can't understand Prolog line of code

强颜欢笑 提交于 2020-01-24 21:40:29
问题 I am studying for a logic test and I saw an example of Perfect number problem There is many solutions to this however there is one that I am unsure how they have done it. divisors(Number, D, L1, L2) :- X is Number / D, ( D < X -> D1 is D + 1, divsors(Number, D1, L1, L2) ; L1 = L2). divisors(Number, D, L1, L2) :- 0 is Number mod D, D1 is D + 1, X is Number / D, ( D =< X -> divisors(Number, D1, [X, D |L1], L2) ; L1 = L2). 来源: https://stackoverflow.com/questions/47744880/cant-understand-prolog

Forcing variable to reassign (Prolog)

你说的曾经没有我的故事 提交于 2020-01-24 12:54:26
问题 The homework is to take in two variables, a number between 0 and 10,000 and a number of how many circular primes there are between 1 and that number. I am having trouble passing the variable back up through the recursion (backtracing is what it is called, I think.) I get the right number and I am pretty sure I have the concept down, the problem I am having is that it throws an error when I try to reassign a variable (?!) Here is the code: circPrimeCompare(Below, NumCirc):- RealNum is 0,

Querying a data knowledge in prolog

陌路散爱 提交于 2020-01-24 07:53:09
问题 Let's say i have some data in this form: plot('Jurrassic Park",'action') plot('Jurrassic Park",'drama') plot('Jurrassic Park",'adventure') plot('pulp fiction",'retro') plot('pulp fiction",'crime') .... where in plot(X,Y) X is a movie and Y is this movies genre. What i would like to do is query this database and get all the movies that have 3 equal genres. For example if there is another movie that is action,drama,adventure i would like it to be paired with Jurassic park.What i have done so

Querying a data knowledge in prolog

我们两清 提交于 2020-01-24 07:53:05
问题 Let's say i have some data in this form: plot('Jurrassic Park",'action') plot('Jurrassic Park",'drama') plot('Jurrassic Park",'adventure') plot('pulp fiction",'retro') plot('pulp fiction",'crime') .... where in plot(X,Y) X is a movie and Y is this movies genre. What i would like to do is query this database and get all the movies that have 3 equal genres. For example if there is another movie that is action,drama,adventure i would like it to be paired with Jurassic park.What i have done so