0% found this document useful (0 votes)
11 views

Prolog

The document contains three sections. The first section defines facts about locations of people in cities and states in India. The second defines family relationships like parent, sibling, and uses facts to infer relationships like mother, father, aunt, uncle. The third section defines a predicate to convert Celsius to Fahrenheit and check if a temperature is below freezing.

Uploaded by

Kavya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
11 views

Prolog

The document contains three sections. The first section defines facts about locations of people in cities and states in India. The second defines family relationships like parent, sibling, and uses facts to infer relationships like mother, father, aunt, uncle. The third section defines a predicate to convert Celsius to Fahrenheit and check if a temperature is below freezing.

Uploaded by

Kavya
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 5

% Facts

location(madhurai, tamilnadu).

location(coimbatore, tamilnadu).

location(mangalore, karnataka).

stays(raghul,madhurai).

stays(raja, coimbatore).

stays(anu, mangalore).

% Rules

person_state(Person, State) :-

stays(Person, City),

location(City, State).

% Queries

list_person_state_city :-

location(City, State),

stays(Person, City),

write('Person: '), write(Person), write(', '),

write('State: '), write(State), write(', '),

write('City: '), write(City),nl,

fail.

person_state_query(Person) :-

person_state(Person, State),

write(Person), write(' stays in '), write(State).

?- list_person_state_city.

Person: raghul, State: tamilnadu, City: madhurai


Person: raja, State: tamilnadu, City: coimbatore

Person: anu, State: karnataka, City: mangalore

false.

?- person_state_query(keerthana).

false.

2.

% Facts

parent(john, amy).

parent(john, sara).

parent(john, tom).

parent(kate, amy).

parent(kate, sara).

parent(kate, tom).

parent(peter, john).

parent(lisa, john).

parent(mary, kate).

parent(mary, luke).

parent(mark, sara).

parent(mark, tom).

% Rules

mother(Mother, Child) :-

parent(Mother, Child),

female(Mother).

father(Father, Child) :-

parent(Father, Child),

male(Father).

sibling(X, Y) :-
parent(Parent, X),

parent(Parent, Y),

X \= Y.

grandparent(Grandparent, Grandchild) :-

parent(Grandparent, Parent),

parent(Parent, Grandchild).

uncle(Uncle, NieceNephew) :-

sibling(Uncle, Parent),

parent(Parent, NieceNephew),

male(Uncle).

aunt(Aunt, NieceNephew) :-

sibling(Aunt, Parent),

parent(Parent, NieceNephew),

female(Aunt).

sister(Sister, Sibling) :-

sibling(Sister, Sibling),

female(Sister).

brother(Brother, Sibling) :-

sibling(Brother, Sibling),

male(Brother).

% Facts

parent(john, amy).

parent(john, sara).

parent(john, tom).

parent(kate, amy).
parent(kate, sara).

parent(kate, tom).

parent(peter, john).

parent(lisa, john).

parent(mary, kate).

parent(mary, luke).

parent(mark, sara).

parent(mark, tom).

% Gender facts

male(john).

male(peter).

male(mark).

male(tom).

female(kate).

female(amy).

female(sara).

female(lisa).

female(mary).

3.

% Predicate to convert centigrade to Fahrenheit

celsius_to_fahrenheit(Celsius, Fahrenheit) :-

Fahrenheit is (Celsius * 9/5) + 32.

% Predicate to check if temperature is below freezing

below_freezing(Temperature) :-

Temperature < 0.

celsius_to_fahrenheit(20, Fahrenheit).
Fahrenheit = 68.

You might also like