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

% Subtract, Divide, Multiply: Prolog Lab

This document contains 5 logic programming lab exercises in Prolog: 1) Defines predicates for arithmetic operators and tests addition of integers and reals 2) Defines predicates for synonyms and antonyms of symbols and tests finding an antonym 3) Defines a predicate to determine if a number is odd or even and tests a number 4) Defines a predicate to determine if a number is positive or negative and tests a number 5) Defines predicates for students, GPA, honors status, and probation and finds honor students not on probation
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
47 views

% Subtract, Divide, Multiply: Prolog Lab

This document contains 5 logic programming lab exercises in Prolog: 1) Defines predicates for arithmetic operators and tests addition of integers and reals 2) Defines predicates for synonyms and antonyms of symbols and tests finding an antonym 3) Defines a predicate to determine if a number is odd or even and tests a number 4) Defines a predicate to determine if a number is positive or negative and tests a number 5) Defines predicates for students, GPA, honors status, and probation and finds honor students not on probation
Copyright
© Attribution Non-Commercial (BY-NC)
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

[] PROLOG

LAB

LAB #4

OPERATORS ( ADD, SUBTRACT, DIVIDE, MULTIPLY)


Dictionary (synonym(), antonym(.) )
Even Odd
Positive and Negative

%Lab4_1:
PREDICATES
addi(integer,integer)
% subtract, divide, multiply
addr(real,real)
%subti
CLAUSES
addi(A,B) if C =A+B, write(" The sum is ",C), nl.
addr(A,B) if C =A+B, write(" The sum is ",C), nl.
% subti(A,B) .
GOAL
addr(4.3, 5.5).

%Lab4_2:
PREDICATES
synonym(symbol, symbol)
antonym(symbol, symbol)
CLAUSES
synonym(brave, daring).
synonym(honest, truthful).
synonym(brave, powerful).
antonym(brave, cowardly).
antonym(honest, dishonest).
GOAL
antonym(brave, A), write( The antonym for brave is , A), nl.

%Lab4_3:
PREDICATES
OddEven(integer)
CLAUSES
OddEven(X):- X mod 2= 0 , write(" It is Even"), nl.
OddEven(X):- write("It is Odd "), nl.
GOAL
OddEven(-5).
%OddEven(19).
-------------------------------------------------------------------------------------------------------------------------Dr Mohammed Fadhl
1

[] PROLOG

LAB

%Lab4_4:
PREDICATES
positive(integer)
CLAUSES
positive(X):- X >=0 , write(" It is positive"), nl.
positive(_):- write("It is negative "), nl.
GOAL
positive(-5).
%positive(5).

%Lab4_5: Using not


DOMAINS
name = symbol
gpa = real
PREDICATES
honor_student(name)
student(name, gpa)
probation(name)
CLAUSES
student("omer ali", 3.5).
student("salem", 2.0).
student("mohammed", 3.7).
probation("omer ali").
probation("salem").
honor_student(Name):- student(Name, GPA),
GPA >= 3.5,
not(probation(Name)).
GOAL
honor_student(X).
-------------------------------------------------------------------------------------------------------------------------Dr Mohammed Fadhl
2

You might also like