Sunday, November 22, 2009

My Prolog Notes

Just putting my prolog notes up, hope they might help somebody:

father(f,c);-parentof(f,c),male(f).


-only predicate matching is done in prolog


grandfather(g,c):-parentof(f,c),
parentof(g,f),male(g)

ancestor(a,c):- parentof(a,c),
ancestor(x,c),ancestor(a,x)

-in prolog we represent the relationship france has_capital paris == has_captial

(france,paris).

works_at(nadeem,punjab_university).
cost_of(pill,900).
bright(ahmed).
enjoys(haroon,riding).
likes(yasmin,ice_cream).
tall(ali).
hits(ali,timmy) ^ with(cricket_bat).
travels_by(waleed,plane) ^ to(mecca).
lives_at(farid,16 sawan road) ^ in(isb).


-in prolog there are facts which are represented as predicates. Now there are two

main ways to represent facts in prolog
-Clausal Form consequence < antcentdents
-Horn Clauses(When prepositions are used for resolutions) two types:
1) Atomic Preposition
2) Empty Left Side
-Prepositions can be stated in two modes:
-one in which truth of the statements is known (facts)
-second the truth is yet to be known (Queries)
-Rules are like stored queries that represent more complex relaionships between

predicates which are based on simple relationships. The head of the rule is only

true when the goals in the body of the rule succeeds.
Read it like this:
Head:- head is true if this is true

-You are eligible for scholarship if you score A grade or your father is a

pensioner.
scholarship(X) :- grade_A(X). scholarship(X) :- father_pen(X).


- and or is like this in prolog

We combine both disjunctions and conjunctions together.
Consider: A woman is happy if she is healthy, wealthy or wise
happy(Person):- healthy(Person),woman(Person).
happy(Person):-wealthy(Person),woman(Person).
happy(Person):-wise(Person),woman(Person).

No comments:

Post a Comment