MCAIII - Lab Assessement
MCAIII - Lab Assessement
Problem statement 1 – write simple relation and facts and find out answer to queries.
In Prolog we can make some statements by using facts. Facts either consist of a particular item or a
relation between items. Facts have some simple rules of syntax. Facts should always begin with a
lowercase letter and end with a full stop. The facts themselves can consist of any letter or number
combination, as well as the underscore _ character. However, names containing the characters -, +,
*, /, or other mathematical operators should be avoided.
Program:
Clauses
Likes (ram, mango). girl (Seema). red(rose). Likes (bill, Cindy). Owns (john, gold).
Output:
Goal queries
?-likes(ram, What).
What= mango
?-likes(Who, cindy). Who= cindy
?-red(What).
What= rose
?-owns(Who, What).
Who= john
What= gold.
Outcome
Student will understand how to write simple facts using prolog.
Assessment 2
Problem statement 2 – This program is designed to answer questions about relationships within a
given family tree. The program will tell you who the mother, father, sister, brother, aunt, uncle,
grandmother, grandfather, brother-in-law, sister-in-law, mother-in-law, father-in-law, ancestor, and
descendent of someone is. The standard form is predicate (someone, relation).
where the relation will be the mother or father or so on.
male(james1).
male(charles1).
male(charles2).
male(james2).
male(george1).
male(paul).
male(sam).
female(catherine).
female(elizabeth).
female(sophia).
female(claudia).
female(fay).
Outcome
/* rules*/
/* Dad is the father of Child if he is male and is the child's parent */
/* Mom is the mother of Child if she is female and the child's parent*/
mother (Child, Mom): - female (Mom), parent (Child, Mom).
/* Bro is the brother of Sibling if he is male and has the same parents as the sibling*/
brother (Sibling, Bro): - male(Bro), father(Sibling, Father), father(Bro, Father), Bro \= Sibling,
mother(Sibling, Mother), mother(Bro, Mother).
/* Sis is the sister of Sibling if she is female and has the same parents as the sibling*/
/* Auntie is the aunt of Kid if she is female and a sister of the kid's parent or she is female
and married to the kid's uncle. This is the definition of an Aunt.
/* Unclebuck is the uncle of Kid if he is male and a brother of the kid's parent or he is male
and married to the kid's aunt. This is the definition of an Aunt.
/* Grandmother is the grandmother of Grandchild if she is female and the parent of the
grandchild's parent */
/* Grandfather is the grandfather of GrandChild if he is male and the parent of the child's
parent */
/*
BInLaw is the brother in law of SiblingInLaw
You are the brother in law if: you are male and The brother of one's spouse.
The husband of one's sister.The husband of the sister of one's spouse
*/
/*
SInLaw is the sister in law of SiblingInLaw
You are the sister in law if: you are female and The sister of one's spouse.
The wife of one's brother. The wife of the brother of one's spouse.
*/
/*
FInLaw is the father in law of ChildInLaw
You are the father in law if: you are male and your son is married to
ChildInLaw or your daughter is married to ChildInLaw
*/
/* Person is an ancestor of Descendent. You are the ancestor if you are the parent of the
person or you are the parent of the person's parent and so forth
*/
Program Statement 3 - Write predicates one convert centigrade temperature to Fahrenheit, the other
checks if a temperature is below freezing.
Prolog expressions are comprised of the following truth-functional symbols, which have the same
interpretation as in the predicate calculus.
Arithmetic:
c_to_f f is c * 9 / 5 +32
freezing f < = 32
Rules:
c_to_f(C,F) :-
F is C * 9 / 5 + 32.
freezing(F) :-
F =< 32.
Output:
Queries:
?- c_to_f(100,X).
X = 212
Yes
?- freezing(15)
.Yes
?- freezing(45).
No
OUTCOME: Student will understand how to write a program using the rules.
Assessment 4
Program
move(state(middle,onbox,middle,hasnot),
grasp,
state(middle,onbox,middle,has)).
move(state(P,onfloor,P,H),
climb,
state(P,onbox,P,H)).
move(state(P1,onfloor,P1,H),
drag(P1,P2),
state(P2,onfloor,P2,H)).
move(state(P1,onfloor,B,H),
walk(P1,P2),
state(P2,onfloor,B,H)).
canget(state(_,_,_,has)).
canget(State1) :-
move(State1,_,State2),
canget(State2).
Output
| ?- [monkey_banana].
/*compiling*/
true ?
yes
| ?- trace
.
The debugger will first creep -- showing everything (trace)
yes
{trace}
| ?- canget(state(atdoor, onfloor, atwindow, hasnot)).
Call: canget(state(atdoor,onfloor,atwindow,hasnot)) ?
Call: move(state(atdoor,onfloor,atwindow,hasnot),_52,_92) ?
Exit:move(state(atdoor,onfloor,atwindow,hasnot),walk(atdoor,_80),state(_80,onfloor,atwindow,ha
snot)) ?
Call: canget(state(_80,onfloor,atwindow,hasnot)) ?
Call: move(state(_80,onfloor,atwindow,hasnot),_110,_150) ?
Exit:
move(state(atwindow,onfloor,atwindow,hasnot),climb,state(atwindow,onbox,atwindow,hasnot)) ?
Call: canget(state(atwindow,onbox,atwindow,hasnot)) ?
Call: move(state(atwindow,onbox,atwindow,hasnot),_165,_205) ?
Fail: move(state(atwindow,onbox,atwindow,hasnot),_165,_193) ?
Fail: canget(state(atwindow,onbox,atwindow,hasnot)) ?
Redo:
move(state(atwindow,onfloor,atwindow,hasnot),climb,state(atwindow,onbox,atwindow,hasnot)) ?
Exit:
move(state(atwindow,onfloor,atwindow,hasnot),drag(atwindow,_138),state(_138,onfloor,_138,has
not)) ?
Call: canget(state(_138,onfloor,_138,hasnot)) ?
Call: move(state(_138,onfloor,_138,hasnot),_168,_208) ?
Exit: move(state(_138,onfloor,_138,hasnot),climb,state(_138,onbox,_138,hasnot)) ?
Call: canget(state(_138,onbox,_138,hasnot)) ?
Call: move(state(_138,onbox,_138,hasnot),_223,_263) ?
Exit: move(state(middle,onbox,middle,hasnot),grasp,state(middle,onbox,middle,has)) ?
Call: canget(state(middle,onbox,middle,has)) ?
Exit: canget(state(middle,onbox,middle,has)) ?
Exit: canget(state(middle,onbox,middle,hasnot)) ?
Exit: canget(state(middle,onfloor,middle,hasnot)) ?
Exit: canget(state(atwindow,onfloor,atwindow,hasnot)) ?
Exit: canget(state(atdoor,onfloor,atwindow,hasnot)) ?
true ?
Assessment 5
Problem statement 5 – write a food table program. shows the facts, rules, goals and their English
meanings.
Facts
English meanings
food(burger). // burger is a food
food(sandwich). // sandwich is a food
food(pizza). // pizza is a food
lunch(sandwich). // sandwich is a lunch
dinner(pizza). // pizza is a dinner
Rules
meal(X) :- food(X).
Queries / Goals
?- food(pizza).
// Is pizza a food?
?- meal(X), lunch(X).
// Which food is meal and lunch?
?- dinner(sandwich).
// Is sandwich a dinner?
Assessment 6
Problem statement 6 – write student-professor relation table shows the facts, rules, goals and their
English meanings.
Facts
English meanings
studies(charlie, csc135).
// charlie studies csc135
studies(olivia, csc135).
// olivia studies csc135
studies(jack, csc131).
// jack studies csc131
studies(arthur, csc134).
// arthur studies csc134
teaches(kirke, csc135).
// kirke teaches csc135
teaches(collins, csc131).
// collins teaches csc131
teaches(collins, csc171).
// collins teaches csc171
teaches(juniper, csc134).
// juniper teaches csc134
Rules
professor(X, Y) :-
teaches(X, C), studies(Y, C).
Queries / Goals
?- studies(charlie, What).