prolog

Prolog Query - Trying to understand how this result happens

夙愿已清 提交于 2019-12-24 00:43:46
问题 So I'm trying to figure out some stuff from Prolog, but I'm not sure WHY I'm getting the result that I'm getting. Given this definition: families(_, Smith, lucy, _, jeff, Smith). and this query: ?- families(Ford, nancy, Ford, jeff, Smith, White). Why is this the result?: Ford = lucy, Smith = jeff, White = nancy. Thank you! 回答1: (A note: no need to leave spaces after the opening and before the closing parenthesis. Also, if this is homework, you should say so.) The definition of families/6 ,

How can I verify if a coordinate is in a list

拜拜、爱过 提交于 2019-12-24 00:38:59
问题 I'm generating random coordinates and adding on my list, but first I need verify if that coordinate already exists. I'm trying to use member but when I was debugging I saw that isn't working: My code is basically this: % L is a list and Q is a count that define the number of coordinate % X and Y are the coordinate members % check if the coordniate already exists % if exists, R is 0 and if not, R is 1 createCoordinates(L,Q) :- random(1,10,X), random(1,10,Y), convertNumber(X,Z), checkCoordinate

Make matrix from list

不打扰是莪最后的温柔 提交于 2019-12-24 00:36:59
问题 Good morning. I need your help. I want to make a list of list (matrix with size SQRT(N)*SQRT(N)) from a list with Size N I am tried but It does not work for me :( gen(L,T,Matrix) which T is the size of Matrix You are free to add more param if you want for example gen([1,2,3,4,5,6,7,8,9],3,Matrix) Matrix = [[1,2,3],[4,5,6],[7,8,9]] 回答1: This is actually a fairly straightforward problem. The trick is to remember that append/3 has many instantiation patterns, and can be used not just to glue

Is there a better method than making a new rule to change variable order for maplist?

不羁的心 提交于 2019-12-24 00:25:26
问题 I have written a program that defines a relation between a 'full' data table a set of sets of column headers (features), an aggregate function and the aggregate table. An example query : ?- data(D), fulltable_aggfunction_sets_aggtable(D,mean,[[a,b,c],[d,e,f]],AggTable), print_data(D),print_data(AggTable). [a,b,c,d,e,f,g,class] [1,1,1,1,1,1,1,0] [2,3,4,5,4,2,1,0] [3,1,3,4,6,7,8,1] [1,2,3,6,1,1,2,1] [feature(1,mean,[a,b,c]),feature(2,mean,[d,e,f])] [1,1] [3,3.6666666666666665] [2

SWI-Prolog - Unit testing library plunit - How is forall option used?

若如初见. 提交于 2019-12-24 00:24:23
问题 For my lexer (tokenizer) all of the ASCII 7-bit characters (0x00 to 0x7F) have a specific token. As SWI-Prolog supports Unicode, the character codes go from 0x0000 to 0xFFFF. In my lexer, since there are many characters that will not map to a specific token there is an unknown token (tokUnknown). To ensure that all of the characters with code between 0 and 127 (0x00 to 0x7F) do not have tokUnknown , test cases are needed. The test case needs a simple lexer to convert the character to a token.

How to prevent duplicates in generated sequences by using dif/2?

血红的双手。 提交于 2019-12-24 00:15:55
问题 This question came up while answering another question on StackOverflow on (generalizing a bit) generating all sequences formed out of a finite set of elements with no duplicate occurrences. As Boris rightly indicated in the comments, there are many existing solutions to this problem. However, I am interested in a solution that does not use an accumulator (i.e., a list of already picked elements against which a newly selected element is to be compared) but that uses dif/2 statements instead.

What is never equal to itself?

ぃ、小莉子 提交于 2019-12-23 22:25:18
问题 Is there value in Prolog that is not equal to itself? I write answer to some question about min of tree and this answer also says that if tree is empty min is null. Sounds good idea first but now when I think it sounds like bad idea. It is kinda OK if null <> null , no problem. But in Prolog I see null is just atom so.... ?- null = null. true. ?- null == null. true. ?- dif(null, null). false. How can I make some term in Prolog that always say: ?- dif(Something, Something). true. But if it is

Why cant i get the answer to the zebra puzzle in prolog?

筅森魡賤 提交于 2019-12-23 22:13:43
问题 this is my code currently, I am trying to solve the zebra puzzle. exists(A,(A,_,_,_,_)). exists(A,(_,A,_,_,_)). exists(A,(_,_,A,_,_)). exists(A,(_,_,_,A,_)). exists(A,(_,_,_,_,A)). rightOf(A,B,(B,A,_,_,_)). rightOf(A,B,(_,B,A,_,_)). rightOf(A,B,(_,_,B,A,_)). rightOf(A,B,(_,_,_,B,A)). middleHouse(A,(_,_,A,_,_)). firstHouse(A,(A,_,_,_,_)). nextTo(A,B,(B,A,_,_,_)). nextTo(A,B,(_,B,A,_,_)). nextTo(A,B,(_,_,B,A,_)). nextTo(A,B,(_,_,_,B,A)). nextTo(A,B,(A,B,_,_,_)). nextTo(A,B,(_,A,B,_,_)). nextTo

Prolog - Operation inside findall

旧时模样 提交于 2019-12-23 22:11:21
问题 Using a findall in Prolog how can I perform operations inside the goal without affecting backtracking? The following example explains what I'm trying to achieve: value('M1', 11, 3). value('M2', 11, 3). connection('M1',1, 'A', 'B'). connection('M1',1, 'B', 'C'). connection('M1',2, 'C', 'D'). connection('M1',2, 'D', 'E'). connection('M2',1, 'D', 'F'). run :- bbR('C',[(0,'X',['A'])],_,_). run2 :- bbR2('C',[(0,['A'])],_,_). bbR(Destination,[(Cost,_,[Destination|T])|_],Result,Cost):- reverse(

Measuring execution time ECLiPSe CLP (or Prolog)

醉酒当歌 提交于 2019-12-23 21:28:30
问题 How do I measure the execution time of a method in ECLiPSe CLP? Currently, I have this: measure_traditional(Difficulty,Selection,Choice):- statistics(runtime, _), time(solve_traditional(Difficulty,Selection,Choice,_)), time(solve_traditional(Difficulty,Selection,Choice,_)), time(solve_traditional(Difficulty,Selection,Choice,_)), time(solve_traditional(Difficulty,Selection,Choice,_)), time(solve_traditional(Difficulty,Selection,Choice,_)), time(solve_traditional(Difficulty,Selection,Choice,_))