Prolog

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 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

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy