prolog

Prolog wildcard for completing a string

只谈情不闲聊 提交于 2020-01-19 17:13:12
问题 I am currently stuck on a prolog problem. So far I have: film(Title) :- movie(Title,_,_). (Where ' movie(T,_,_,) ' is a reference to my database) namesearch(Title, Firstword) :- film(Title), contains_term(Firstword, Title). It is hard to explain what I need help on, but basically is there a wildcard I can use to search for all films starting with a specific word, for example, if I were to search for all films beginning with the word "The". Is there a wildcard which would allow me to input as

Complexity of ISO Prolog predicates

笑着哭i 提交于 2020-01-18 04:44:13
问题 Are there any guarantees for upper bounds on the time complexity of the standard Prolog predicates? For example: is it certain that sort(+List, ?SortedList) runs in O(nlog(n)) time (n being the length of List ) in any standard compliant Prolog system? 回答1: tl;dr: No and no. Let's start with sort/2 which ideally would need n ld( n ) comparisons. Fine, but how long does one comparison take? Let's try this out: tails(Es0, [Es0|Ess]) :- Es0 = [_|Es], tails(Es, Ess). tails([],[[]]). call_time(G,T)

What is the meaning of predicate “simple/1” in Prolog (SWI-Prolog)

橙三吉。 提交于 2020-01-17 08:31:20
问题 I run into problem while reading a book. I see a program use predicate "simple" ( I guess simple/1 ). I don't know what is the meaning of this predicate, I can't find it with ?-help(simple) in the console. But when I tried with some queries in console, it worked something like: 5 ?- simple(p(x)). false. 6 ?- simple(mia). true. 7 ?- simple(Mia). true. 8 ?- simple(f(Mia)). false. I guess it is some sort of predicate to determine if the argument was Terms(or Variables) or Complex Terms. 回答1: The

What is the meaning of predicate “simple/1” in Prolog (SWI-Prolog)

狂风中的少年 提交于 2020-01-17 08:31:16
问题 I run into problem while reading a book. I see a program use predicate "simple" ( I guess simple/1 ). I don't know what is the meaning of this predicate, I can't find it with ?-help(simple) in the console. But when I tried with some queries in console, it worked something like: 5 ?- simple(p(x)). false. 6 ?- simple(mia). true. 7 ?- simple(Mia). true. 8 ?- simple(f(Mia)). false. I guess it is some sort of predicate to determine if the argument was Terms(or Variables) or Complex Terms. 回答1: The

Getting number of common items between lists in Prolog

北城余情 提交于 2020-01-17 03:07:45
问题 I want to modify the code on Creating a list from user input with swi-prolog : diagnose(Disease):- retractall(symptom(_)), getSymptoms(List), forall(member(X,List),assertz(symptom(X))), disease(Disease). getSymptoms([Symptom|List]):- writeln('Enter Symptom:'), read(Symptom), dif(Symptom,stop), getSymptoms(List). getSymptoms([]). disease(flu):- symptom(fever), symptom(chills), symptom(nausea). disease(cold):- symptom(cough), symptom(runny_nose), symptom(sore_throat). disease(hungover):-

Swi-Prolog的安装

最后都变了- 提交于 2020-01-16 14:15:08
转载自:https://mp.weixin.qq.com/s/cVhuibaXiCuUBTc-dX1Weg macOS的安装 Port安装 开启浏览器输入链接 https://www.macports.org/install.php 下载当前使用的版本如下所示: 运行MacPorts-xxxxxxx.pkg安装包成功后 安装稳定版 $ sudo port install swi-prolog Password: Portfile changed since last build; discarding previous state. —> Computing dependencies for swi-prolog The following dependencies will be installed: … … … —> Some of the ports you installed have notes: gawk has the following notes: readline support has been removed from gawk. If you need to run gawk interactively, install rlwrap: sudo port install rlwrap and run gawk using rlwrap: rlwrap

How to give values to items in a list in prolog

故事扮演 提交于 2020-01-16 14:09:50
问题 So i made a list using atom_chars(X,Y). Which split the string 'abc' into [a,b,c] . I now want to assign numbers to the elements in the list. Such as a is 4, b is 2, c is 7. How would i go about doing this? 回答1: In Prolog, the symbols a , b , and c are considered atoms . You can't "assign" values to them. You could, however, associate numbers with them using, for example, - as a convenient notation for a term. You could form a list: [a-2, b-4, c-3] Let's say you bind this to the variable

Converting list to terms in Prolog

浪子不回头ぞ 提交于 2020-01-16 09:13:39
问题 I have to implement the predicate cons(List, Term) that will take a list [Head|Tail] and convert it to terms, represented as next(Head, Tail) . How do I do this? I don't even know where to start. Here is the example of a successful query given in the question: cons([a,b,c],X). /*query returns X=next(a,next(b,next(c,null))).*/ 回答1: Doing most anything with lists will require that you consider two cases: the empty list and a list with a head and a sublist. Usually your base case is handling the

Prolog - return second to last list element

孤街醉人 提交于 2020-01-16 06:14:28
问题 puzzling over a problem of trying to return the second to last element in a list written in Prolog. This language is interesting to use but I'm having trouble getting my head wrapped around it. Here is what I have: secondLast([X], X). secondLast(X, [Y], X) :- secondLast(Y, K). secondLast(X, [Y|Z], K) :- secondLast(Y, Z, K). secondLast([X|Z], Ans) :- secondLast(X, Z, Ans). so calling secondLast([a, b, c, d], X). X should equal c . Any ideas? Thanks! 回答1: Can be just: secondLast(L, X) :- append

Recognize sentence structure in Prolog

廉价感情. 提交于 2020-01-16 01:12:09
问题 I have a situation where I'm reading in three different types of sentences. They will be of one of the following forms: _ is a _ A _ is a _ Is _ a _? I need to be able to recognize which type of sentence was entered and then add to or query my knowledge base. For example, the user may input: Fido is a dog. I would then add that fact to my knowledge base. The user could then enter: Is Fido a dog? And the program would answer yes. So far my only idea of recognizing the facts is splitting the