prolog

What does +,+ mode in Prolog mean?

吃可爱长大的小学妹 提交于 2019-12-18 07:02:11
问题 So am being told a specific predicate has to work in +,+ mode. What does that mean in Prolog? 回答1: When one wants to give information on a predicate in prolog, those conventions are often used : arity : predicate/3 means predicate takes 3 arguments. parameters : predicate(+Element, +List, -Result) means that Element and List should not be free variables and that Result should be a free variable for the predicate to work properly. ? is used when it can be both, @ is mentionned on the above

What does +,+ mode in Prolog mean?

你说的曾经没有我的故事 提交于 2019-12-18 07:01:09
问题 So am being told a specific predicate has to work in +,+ mode. What does that mean in Prolog? 回答1: When one wants to give information on a predicate in prolog, those conventions are often used : arity : predicate/3 means predicate takes 3 arguments. parameters : predicate(+Element, +List, -Result) means that Element and List should not be free variables and that Result should be a free variable for the predicate to work properly. ? is used when it can be both, @ is mentionned on the above

Prolog and ancestor relationship

落花浮王杯 提交于 2019-12-18 06:58:20
问题 I have to write a small prolog program which checks if a given person is a ancestor of a second one. These are the facts and rules: mother(tim, anna). mother(anna, fanny). mother(daniel, fanny). mother(celine, gertrude). father(tim, bernd). father(anna, ephraim). father(daniel, ephraim). father(celine, daniel). parent(X,Y) :- mother(X,Y). parent(X,Y) :- father(X,Y). The test if a person is an ancestor of another person is easy: ancestor(X, Y) :- parent(X, Y). ancestor(X, Y) :- parent(X, Z),

Prolog manual or custom labeling

亡梦爱人 提交于 2019-12-18 06:55:13
问题 I am currently writing a solver for a floor planning problem in Prolog and have some issues with the labeling part. The current problem is my constraints are posted but when I launch the labeling, it takes forever to find a solution. I would like to bring in some heuristics. My question is, how do I manually label my variables ? I am afraid that after defining a clpfd variable like this : X in Xinf..Xsup and constraining it, If I do something like : fd_sup(X, Xmax), X = Xmax, ... in my custom

Prolog anonymous variable

こ雲淡風輕ζ 提交于 2019-12-18 05:43:51
问题 Here is what I have understood about Prolog variables. A single underscore stands for anonymous variable, which is like a new variable each time it occurs. A variable name starting with underscore like _W is not an anonymous variable. Or, the variable names generated inside Prolog, like _G189, is not considered anonymous: ?- append([1,2],X,Y). X = _G189 Y = [1, 2|_G189] Could you please help me understand? By the way, I got the above example from some tutorials, but when I run it in SWI

Prolog anonymous variable

送分小仙女□ 提交于 2019-12-18 05:43:27
问题 Here is what I have understood about Prolog variables. A single underscore stands for anonymous variable, which is like a new variable each time it occurs. A variable name starting with underscore like _W is not an anonymous variable. Or, the variable names generated inside Prolog, like _G189, is not considered anonymous: ?- append([1,2],X,Y). X = _G189 Y = [1, 2|_G189] Could you please help me understand? By the way, I got the above example from some tutorials, but when I run it in SWI

Count the number of occurrences of a number in a list

不羁岁月 提交于 2019-12-18 04:42:35
问题 I'm writing a program in prolog that count the number of occurrences of a number in a list count([],X,0). count([X|T],X,Y):- count(T,X,Z), Y is 1+Z. count([_|T],X,Z):- count(T,X,Z). and this is the output ?- count([2,23,3,45,23,44,-20],X,Y). X = 2, Y = 1 ; X = 23, Y = 2 ; X = 23, Y = 1 ; X = 3, Y = 1 ; X = 45, Y = 1 ; X = 23, Y = 1 ; X = 44, Y = 1 ; X = -20, Y = 1 ; false. it's count the same number several times Any help is appreciated 回答1: Instead of the dummy variable _ just use another

Purity of Prolog predicates that use impure primitives

家住魔仙堡 提交于 2019-12-18 03:38:29
问题 I know that var/1 , nonvar/1 and !/0 are impure primitives, but does their use make every program that uses them impure? I wrote the following predicate plus/3 that behaves as if it were pure or at least that is what I claim. The predicate is demonstrative, not designed to be efficient. % nat(X) is true if X is a natural number nat(0). nat(X):- nonvar(X), !, X > 0. nat(X):- nat(X1), X is X1 + 1. % plus(A, B, C) is true if A,B and C are natural numbers and A+B=C plus(A, B, C):- nat(A), (nonvar

How to use SWI-Prolog ./2 function?

牧云@^-^@ 提交于 2019-12-17 23:36:10
问题 Need example using SWI-Prolog ./2. The signature is .(+Int,[]) Also if there is a name for this operator it would be nice to know. Searching for '.' is senseless. The closest to a name is from SWI documentation section F.3 Arithmetic Functions List of one character: character code What I tried ?- X is .(97,[]). results in ERROR: Type error: `dict' expected, found `97' (an integer) ERROR: In: ERROR: [11] throw(error(type_error(dict,97),_5812)) ERROR: [8] '<meta-call>'(user:(...,...)) <foreign>

Tennis match scheduling

妖精的绣舞 提交于 2019-12-17 21:47:53
问题 There are a limited number of players and a limited number of tennis courts. At each round, there can be at most as many matches as there are courts. Nobody plays 2 rounds without a break. Everyone plays a match against everyone else. Produce the schedule that takes as few rounds as possible. (Because of the rule that there must a break between rounds for everyone, there can be a round without matches.) The output for 5 players and 2 courts could be: | 1 2 3 4 5 -|------------------- 2| 1 - 3