a) cow(herbivore).
lion(carnivore).
?- cow(herbivore).
true
b) cow(herbivore).
lion(carnivore).
?- cow(carnivore).
false
c) cow(herbivore).
lion(carnivore).
?- cow(vegitarian).
false
d) cow(herbivore).
lion(carnivore).
?- cow(What).
What = herbivore
e) ?- write(welcome).
welcome
f) ?- write(welcome),write(to),write(“PROLOG”),write(world).
welcometo[80,82,79,76,79,71]world
g) ?- write(welcome),nl,write(to),nl,write(“PROLOG”),nl,write(world).
welcome
[80,82,79,76,79,71]
world
h) ?- write(“Welcome to PROLOG world”).
[87,101,108,99,111,109,101,32,116,111,32,80,82,79,76,79,71,32,119,111,114,108,100]
i)assert().
Adds facts and terms to the knowledge database.
j) retract().
Removes facts from the database.
k) listing.
Lists the terms and facts in the database.
l) ?- X = 2, X = 1 + 1.
no
m) ?- X = 5, Z = X + 2.
yes
n) ?- X = Y, Y = Z, A = Y + Z, X = 2.
yes
male(sri).
male(majid).
male(tom).
male(tim).
female(ann).
female(jeni).
female(rosi).
p) ?- male(sri),male(majid).
yes
q) ?- male(sri),male(ann).
no
r) ?- male(jeni),male(ann).
no
s) ?- female(jeni),female(ann).
yes
t) ?- male(sri);male(majid).
yes
u) ?- male(sri);male(ann).
yes
v) ?- male(jeni);male(ann).
no
w) ?- not(male(jeni)).
yes
x) ?- not(male(sri)).
no
y) ?- male(_).
yes
z) ?- not(male(_)).
No
Animal knowledge base:
/*Start of code*/
animal(X) :- reptile(X);bird(X);mammal(X). %All reptiles, mammals and birds are animals
%list of mammals
mammal(tiger).
mammal(bat).
mammal(wolf).
mammal(rabbit).
mammal(gnu).
%list of reptiles
reptile(crocodile).
reptile(tortoise).
reptile(chameleon).
%list of birds
bird(owl).
bird(ostrich).
bird(crow).
bird(seagull).
bird(hawk).
%list of carnivores
carnivore(tiger).
carnivore(wolf).
carnivore(owl).
carnivore(hawk).
carnivore(owl).
carnivore(crocodile).
carnivore(chameleon).
%list of herbivores
herbivore(gnu).
herbivore(rabbit).
herbivore(tortoise).
/*End of code*/
a.All animals
?-animal(X).
X = crocodile ? ;
X = tortoise ? ;
X = chameleon ? ;
X = owl ? ;
X = ostrich ? ;
X = crow ? ;
X = seagull ? ;
X = hawk ? ;
X = tiger ? ;
X = bat ? ;
X = wolf ? ;
X = rabbit ? ;
X = gnu
yes
b. All mammals
?-mammal(X).
X = tiger ? ;
X = bat ? ;
X = wolf ? ;
X = rabbit ? ;
X = gnu
yes
c. All the birds which is only carnivores
?-bird(X),carnivore(X).
X = owl ? ;
X = hawk
yes
d. All the mammals which is only carnivores
?-mammal(X),carnivore(X).
X = tiger ? ;
X = wolf ? ;
no
e. All the mammals which is only herbivores
?-mammal(X),herbivore(X).
X = rabbit ? ;
X = gnu
yes
f. All the reptiles which are only carnivores
?-reptile(X),carnivore(X).
X = crocodile ? ;
X = chameleon
yes
Semantic net:
- Use the following information to construct a semantic net and convert it to a Prolog database, then devise queries to pick out followings
‘Diet related to people’s priorities. Elderly people concerned about their blood-pressure often avoid fats. Athletes, who are concerned with energy and body-building, eat sugar and proteins. For similar reasons, growing children are given these foods. Overweight people who want to lose weight avoid sugar and fats.’
/*START*/
avoid(elderly,fats).
avoid(overweight,sugar).
avoid(overweight,fats).
eat(athletes,sugar).
eat(athletes,proteins).
eat(growing_children,sugar).
eat(growing_children,proteins).
concerned_with(athletes,body-building).
concerned_with(athletes,energy).
concerned_with(growing_children,body-building).
concerned_with(growing_children,energy).
concerned_with(elderly,blood-pressure).
/*END*/
- Who eats protein for body-building
eat(Who,proteins),concerned_with(Who,body-building).
- The reasons why sugar is eaten
Dating database:
/* A DATING AGENCY DATABASE */
/* Facts */
person(bill,male,24).
person(carol,female,15).
person(george,male,17).
person(margaret,female,52).
person(alfred,male,15).
person(jane,female,23).
/* Rules */
male(Male):-person(Male,male,_).
female(Female):-person(Female,female,_).
man(Man):-person(Man,male,Age),Age>17.
boy(Boy):-person(Boy,male,Age),Age<18.
/* END */
- Create a file ‘dating.pl’ and add the code above. Extend the knowledgebase with rules to define a woman and girl and generate answer for the following queries.
/* dating.pl*/
/* Facts */
person(bill,male,24).
person(carol,female,15).
person(george,male,17).
person(margaret,female,52).
person(alfred,male,15).
person(jane,female,23).
/* Rules */
male(Male):-person(Male,male,_).
female(Female):-person(Female,female,_).
woman(Female):-person(Female,female,Age),Age>17.
girl(Female):-person(Female,female,Age),Age<18.
man(Man):-person(Man,male,Age),Age>17.
boy(Boy):-person(Boy,male,Age),Age<18.
/* END */
a)?- person(Male,male,_).
Male = bill ? ;
Male = george ? ;
Male = alfred ? ;
no
b) ?- person(Person,_,15).
Person = carol ? ;
Person = alfred ? ;
no
c) ?- man(bill).
yes
d) ?- girl(Anybody).
Anybody = carol ? ;
no
e) ?- man(george).
no
f) ?- boy(X).
X = george ? ;
X = alfred ? ;
no
2.Design rules using ‘if else’ structure and develop Prolog code for followings;
/* A DATING AGENCY DATABASE –with if-then-else rules */
/* Facts */
person(bill,male,24).
person(carol,female,15).
person(george,male,17).
person(margaret,female,52).
person(alfred,male,15).
person(jane,female,23).
/* Rules */
male(Male):-person(Male,male,_).
female(Female):-person(Female,female,_).
man(Man):-person(Man,male,Age),Age>17.
boy(Boy):-person(Boy,male,Age),Age<18.
/* END */
a) a rule match which matches any male with any female, using the person facts
male(_),female(_) :- female(Female) :- person(Female,female,_), female(Female) :- person(Female,female,_),person(Male,male,_) :- Female,Male.
match(X,Y):-person(X,male,_), person(Y,female,_).
b) a rule match which matches any man with any woman, using the man and woman rules
matchwomanman(X,Y):-man(X),woman(Y).
c) another rule match which matches any man in his 20s with any woman in her twenties, using the person facts
match20s(X,Y):-person(X,male,Mage),Mage<30,Mage>19,person(Y,female,Fage),Fage<30,Fage>19.
- In the same file create test cases for each of the rules developed above. Show the results of running your test cases.
/* A DATING AGENCY DATABASE */
/* Facts */
person(bill,male,24).
person(carol,female,15).
person(george,male,17).
person(margaret,female,52).
person(alfred,male,15).
person(jane,female,23).
person(john,male,33).
person(jack,male,18).
person(dreyfus,male,29).
person(mccarthy,male,20).
person(norvig,male,42).
person(ada,female,26).
person(alison,female,16).
person(kate,female,41).
person(ella,female,22).
person(melinda,female,24).
/* Rules */
male(Male):-person(Male,male,_).
female(Female):-person(Female,female,_).
man(Man):-person(Man,male,Age),Age>17.
woman(Woman):-person(Woman,female,Age),Age>17.
boy(Boy):-person(Boy,male,Age),Age<18.
match20s(X,Y):-person(X,male,Mage),Mage<30,Mage>19,person(Y,female,Fage),Fage<30,Fage>19.
matchwomanman(X,Y):-man(X),woman(Y).
male(_),female(_) :- female(Female) :- person(Female,female,_), female(Female) :- person(Female,female,_),person(Male,male,_) :- Female,Male.
/* END */
?-match20s(X,Y).
X = bill
Y = jane ? ;
X = bill
Y = ada ? ;
X = bill
Y = ella ? ;
X = bill
Y = melinda ? ;
X = dreyfus
Y = jane ? ;
X = dreyfus
Y = ada ? ;
X = dreyfus
Y = ella ? ;
X = dreyfus
Y = melinda ? ;
X = mccarthy
Y = jane ? ;
X = mccarthy
Y = ada ? ;
X = mccarthy
Y = ella ? ;
X = mccarthy
Y = melinda ? ;
no
?-matchmanwoman(X,Y).
X = bill
Y = margaret ? ;
X = bill
Y = jane ? ;
X = bill
Y = ada ? ;
X = bill
Y = kate ? ;
X = bill
Y = ella ? ;
X = bill
Y = melinda ? ;
X = john
Y = margaret ? ;
X = john
Y = jane ? ;
X = john
Y = ada ? ;
X = john
Y = kate ? ;
X = john
Y = ella ? ;
X = john
Y = melinda ? ;
X = jack
Y = margaret ? ;
X = jack
Y = jane ? ;
X = jack
Y = ada ? ;
X = jack
Y = kate ? ;
X = jack
Y = ella ? ;
X = jack
Y = melinda ? ;
X = dreyfus
Y = margaret ? ;
X = dreyfus
Y = jane ? ;
X = dreyfus
Y = ada ? ;
X = dreyfus
Y = kate ? ;
X = dreyfus
Y = ella ? ;
X = dreyfus
Y = melinda ? ;
X = mccarthy
Y = margaret ? ;
X = mccarthy
Y = jane ? ;
X = mccarthy
Y = ada ? ;
X = mccarthy
Y = kate ? ;
X = mccarthy
Y = ella ? ;
X = mccarthy
Y = melinda ? ;
X = norvig
Y = margaret ? ;
X = norvig
Y = jane ? ;
X = norvig
Y = ada ? ;
X = norvig
Y = kate ? ;
X = norvig
Y = ella ? ;
X = norvig
Y = melinda ? ;
(8 ms) no
Expert systems differ from conventional programs in 3 basic ways: their purpose, their design and their user interface. Expert systems are meant to mimic, simulate or automate knowledge-based decision-making. For this reason, the design and architecture of expert systems must be based on formal logic and rely on knowledge database. Expert systems are therefore basically knowledge databases and inference engines. Conventional programs such as http servers, web browsers, word processors and music players are meant primarily to manipulate data: to send it, save it, encrypt it, or display it in various means. While expert systems also manipulate data, that is not their primary purpose. The difference is clearest in the emphasis on knowledge rather than data in expert systems. Whereas conventional programs are marked by limited conditionality, expert systems are highly conditional, as the data they manipulate is in a sense an extension of their code. Expert systems are also apt to use more artificial intelligence techniques, such as formal logic, semantic networks, frames, machine learning, computational semantics, etc., than conventional programs. Expert systems use natural language for interaction with the user than conventional programs, which are usually graphical-based or text-base in terminals.
Expert systems are advantageous because, unlike a human expert, they can accurately handle a large amount of data. Although humans can remember an incredible amount of information, it is quite limited in comparison with how much a computer can handle, especially numerical knowledge and technical knowledge. Human memory is marred with inaccuracy, but data in a computer is exact. Unlike human experts, however, expert systems have limited understanding and mastery of natural language, which is the communication medium used by humans. A limited capacity for natural language also means expert systems have a limited capacity for logic and knowledge acquisition. Expert systems are also limited to specific domains and fields, for example medicine, engineering or economics; they cannot use knowledge from other domains and are infamous for lacking “common sense” logic and knowledge. Expert systems are suited in fields that may be extremely menial or exhausting to humans. Their speed also gives them an advantage where huge numerical variables may be involved.
Expert system shells are programs which feature an inference engine and interactive environment that facilitates the adding of domain knowledge to build a complete expert system. Expert system shells are more comfortable and easier to deal with for non-programmers, and they offer a practical way to make commercial expert system for any domain of knowledge. Expert systems provide a higher level of abstraction by combining frequently used techniques in the development of expert systems. They are used by experts in the field to easily and rapidly build a knowledge base to be used by the inference engine.
Some application areas of expert systems include in medicine, crisis management, monitoring and auto-correcting complex systems such as industrial and mechanical processes, question-and-answering systems such as in customer care, and many others. An early example of an expert system is MYCIN, which was designed to aid human experts in the diagnosis and treatment of bacterial infections. It used its knowledge to probabilistically judge the microbe causing the infection and recommended an appropriate antibiotic. MYCIN is an example of an expert system that was used to aid an expert rather than replace them.
In expert systems, verification and validation refers to the process of ensuring the quality and robustness of an expert system. A poor-quality expert system may make serious errors that may be costly, loss, or even human suffering. The process of verification and validation involves the evaluation and assessment of the system to probe for anomalies, inconsistencies, completeness, correctness and redundancy. The definition of validity and credibility in a system is also addressed.
Knowledge acquisition, as the term suggests, is the process of acquiring knowledge in that formalized way for a particular purpose or in a specific way. Knowledge acquisition is one of the most challenging and interesting subjects in artificial intelligence. The process involves the extraction, structuring, and organization of knowledge from human experts or other sources. Knowledge elicitation is the sub-process of knowledge acquisition that involves the analysis and development of domain-specific knowledge that is the basis of human cognition.
Knowledge representation is the process of structuring and encoding knowledge to facilitate and enable its manipulation and use in cognitive processes. Knowledge representation is an essential part of any system that uses reasoning. Representing knowledge means symbolically approximating external information in a system internally. Different kinds of knowledge require different kind of reasoning, hence there are different models of knowledge representation.
- Create a simple prolog application that repeatedly asks the user for two numbers and returns their sum. If the user wants to exit the program she may type ‘y’ to exit. On exit a ‘See you next time.’ message is displayed.
/*calc.pl –will add single-character integers repeatedly*/
respond(Ans):-write('The answer is '),write(Ans),write('.'),nl.
ask1:-write('Please enter the first number:').
ask2:-write('Please enter the second number:').
quit:-write('See you next time.').
loop:-ask1,
get(A),
(B==y -> quit ;
ask2,
get(C),
(B==y -> quit;
E is B+D,respond(E),loop)).
/*END*/
Works Cited
Hart, Anna. "Knowledge elicitation: issues and methods." Computer-Aided Design (1985): 445-462.
Norvig, Peter. Paradigms of Artificial intelligence Programming:case studies in common lisp. San Francisco, Carlifornia: Morgan Kauffmann Publishers, 1992.
O'keefe, Robert M and Daniel E O'leary. "Expert system verification and Validation: A survey ann tutorial." Artificial Intelligence Review (1993): 3-42.
Russell, Stuart Jonathan and Peter Norvig. Artificial Intelligence: A Modern Approach. New Jersey: Pearson, 2014.