prolog

Is the Prova implemented with a Prolog compiler or Prolog interpreter?

五迷三道 提交于 2020-01-06 03:50:51
问题 I am looking at the Java-written Prolog system, Prova. https://prova.ws/ But it is not clear about its implementation, a Prolog compiler or Prolog interpreter? I read the manual, but did not found an answer. 回答1: There are some rumors that Prova is based on Mandarax. The newest version seem to be heading in the same direction as SWI-Prolog 7, i.e. it supports dicts and a dot notation. See also here: http://prova.ws/confluence/display/REWRITEDEV/Prova+maps+for+defining+slotted+terms The

prolog function to infer new facts from data

断了今生、忘了曾经 提交于 2020-01-06 02:50:07
问题 I have a dataset containing "facts" recognizable to prolog, i.e.: 'be'('mr jiang', 'representative of china'). 'support'('the establishment of the sar', 'mr jiang'). 'be more than'('# distinguished guests', 'the principal representatives'). 'end with'('the playing of the british national anthem', 'hong kong'). 'follow at'('the stroke of midnight', 'this'). 'take part in'('the ceremony', 'both countries'). 'start at about'('# pm', 'the ceremony'). 'end about'('# am', 'the ceremony'). I want

Prolog Looping Redo's

限于喜欢 提交于 2020-01-06 01:33:07
问题 I am trying to write a small program in Prolog(gnu) that will take user input and give true or false to the question "Is this a valid sentence in this grammar?" I have had a lot of trouble finding solid documentation on Prolog, and if anyone has a reliable source that would be appreciated. From what I have found, this code for the most part should work. When I try to trace the execution, I get strange results that I do not understand. The test case I am working with now is when the user

Arithmetic expression in swi-prolog

天涯浪子 提交于 2020-01-05 21:13:52
问题 I have the following prolog program: set_1(2). p(X) :- set_1(X+1). I'm using SWI-Prolog version 5.10.4 for i386 to run the query p(1) on this program. The answer is 'false'. I expect the answer to be 'true', because set_1(X+1) should be grounded as set_1(2) and resolved with the first fact. Why the answer is false and how can I get 'true' ? 回答1: If you want X+1 to unify with 2 in your example, you'll need to code this using is/2 . By itself X+1 is a valid Prolog term, but even when X is

Solving Caliban problems with prolog

我的未来我决定 提交于 2020-01-05 18:57:26
问题 I'm working on solving a logic puzzle using prolog for school. Here's the clues: Brown, Clark, Jones and Smith are 4 substantial citizens who serve their community as achitect, banker, doctor and lawyer, though not necessarily respectively. Brown, who is more conservative than Jones but more liberal than Smith, is a better golfer than the men who are younger than he is and has a larger income than the men who are older than Clark. The banker, who earns more than the architect, is neither the

How to handle a path in Prolog graph traversal

▼魔方 西西 提交于 2020-01-05 17:58:55
问题 I have written in Prolog: edge(x, y). edge(y, t). edge(t, z). edge(y, z). edge(x, z). edge(z, x). path(Start, End, Path) :- path3(Start, End, [Start], Path). path3(End, End, RPath, Path) :- reverse(RPath, Path). path3(A,B,Path,[B|Path]) :- edge(A,B), !. path3(A, B, Done, Path) :- edge(A, Next), \+ memberchk(Next, Done), path3(Next, B, [Next|Done], Path). Its taking care of cyclic graphs as well, I am getting an irregular output when I try to traverse same node from same node. eg: path(x,x,P).

Prolog predicates

好久不见. 提交于 2020-01-05 15:28:10
问题 I am currently learning about predicate logic in Prolog. I am having trouble answering a question on the topic and would like to know the steps one one take to solve such a question using Prolog predicates. I have a scenario which must be represented in Prolog predicates using only two different predicate names. A and B are married B likes C C and D are married D likes E F likes B E likes B E and G are married A likes G 回答1: Just write down what it says. are_married(a,b). likes(b,c). And so

Get unique results with Prolog

独自空忆成欢 提交于 2020-01-05 10:28:14
问题 I have this Prolog code that returns: [[vincent,vincent],[vincent,marcellus],[marcellus,vincent],[marcellus,marcellus],[pumpkin,pumpkin],[honey_bunny,honey_bunny]] . :- initialization main. loves(vincent, mia). loves(marcellus, mia). loves(pumpkin, honey_bunny). loves(honey_bunny, pumpkin). jealous(X, Y) :- loves(X, Z), loves(Y, Z). main :- findall([X, Y], jealous(X, Y), L), write(L), halt. How to get the only results when X != Y? I tried the following code to get the same results as before.

How to calculate a sum of sequence of numbers in Prolog

依然范特西╮ 提交于 2020-01-05 10:24:10
问题 The task is to calculate a sum of natural numbers from 0 to M. I wrote the following code using SWI-Prolog: my_sum(From, To, _) :- From > To, !. my_sum(From, To, S) :- From = 0, Next is 1, S is 1, my_sum(Next, To, S). my_sum(From, To, S) :- From > 0, Next is From + 1, S is S + Next, my_sum(Next, To, S). But when I try to calculate: my_sum(0,10,S), writeln(S). I got False instead of correct number. What is going wrong with this example? 回答1: this is surely false for Next \= 0: S is S + Next .

Prolog check if the list is like 1,2,3,4,2,1

一世执手 提交于 2020-01-05 08:46:05
问题 I need to create a program to check if a list increases then decreases, just like in the example below: [1,2,3,4,5,6,4,3,2,1] and it must be at least a one step increase or decrease. Basically: there must be a single ascending sequence followed by a single descending sequence. the step in each transition must be at least one (no identical numbers side by side). the step can be more than one. I thought about finding the biggest number in the list and then splitting the list into two lists,