Artificial Intelligence Assignment 1



1.     The Structure of Prolog Programs.
All programs written in Prolog contain at least 4 parts:
         DOMAINS
         PREDICATES
         CLAUSES
         GOALS

Ø  What is DOMAIN?
·         The section of code where we define the legal values for any type that is not defined as a standard type. This may include aliasing of types (renaming).
·         Domain declarations can also be used to define structures that are not defined by the standard domains.

Ø  What are PREDICATES?
·         The PREDICATES section is where we define predicates to be used in the CLAUSES section and define the domains for their arguments.
·         Symbolic name of a relation
·         We found it best to think of predicate declarations as function prototypes.
·         Ex: age(string, integer)

Ø  What are CLAUSES
·         Clauses are the heart of the program.
·         A clause is an instance of a predicate, followed by a period.
·         Clauses are of two types:
·         Facts
·         Rules
Clause Facts:
o   Facts in the CLAUSE section are relations that are known to be true by the programmer.
o   Self-standing basis for inference
o   A property of an object or a relation between objects.
o   Ex: red(car)


Clause Rules:
o   Used to infer other facts
o   Property or relation known given the fact that some other set of relations are known.
o   Ex: Jane can eat food if it is a vegetable on the doctor’s list.
o   Can_eat(jane, X):- food(X), vegetable(X), doc_list(X).

Ø  What are GOALS:
·         Part of program where queries are made.
·         Can be singular or compound.
·         Each part of a compound goal is known as a subgoal.
·         To satisfy a compound goal (or query) each subgoal must itself be satisfied by the system.

Ø  Simple program:
domains
disease,indication = symbol
predicates
symptom(disease, indication)
clauses
symptom(chicken_pox, high_fever).
symptom(chicken_pox, chills).
symptom(flu, chills).
symptom(cold, mild_body_ache).
symptom(flu, severe_body_ache).
symptom(cold, runny_nose).
symptom(flu, runny_nose).
symptom(flu, moderate_cough).
       Goal: symptom(cold, runny_nose)
     True






2.     Given three relations child(X,Y):X is a child of Y, male(X):X is male, female(X):X is female.
Write a program to find relations like brother(X,Y) , father(X,Y), mother(X,Y), grandfather(X,Y), grandmother(X,Y), uncle(X,Y), sister(X,Y), ancestor(X,Y) between different members of a family.


            Gita                             Raman


            Ashok Rajesh
 



                        Payal               Bhaumik
 

                                               
                                                            Arjun

predicates
            female(symbol)
            male(symbol)
            child(symbol,symbol)
            mother(symbol,symbol)
            father(symbol,symbol)
            grandmother(symbol,symbol)
            grandfather(symbol,symbol)
            sister(symbol,symbol)
            brother(symbol,symbol)
            uncle(symbol,symbol)
            ancestor(symbol,symbol)
clauses
            female(gita).
            female(payal).
            male(raman).
            male(ashok).
            male(rajesh).
            male(bhaumik).
            male(arjun).
            child(ashok,gita).
            child(rajesh,gita).
            child(ashok,raman).
            child(rajesh,raman).
            child(payal,rajesh).
            child(bhaumik,rajesh).
            child(arjun,bhaumik).
            mother(X,Y):-
                        female(X),
                        child(Y,X).
            father(X,Y):-
                        male(X),
                        child(Y,X).                 
            grandmother(X,Y):-
                        female(X),
                        child(Z,X),
                        child(Y,Z).
            grandfather(X,Y):-
                        male(X),
                        child(Z,X),
                        child(Y,Z).
            sister(X,Y):-
                        X<>Y,
                        female(X),
                        child(X,Z),
                        child(Y,Z).
            brother(X,Y):-
                        X<>Y,
                        male(X),
                        child(X,Z),
                        child(Y,Z).                             
           
            uncle(X,Y):-
                        male(X),
                        father(P,Y),
                        father(Z,P),
                        P<>X,
                        father(Z,X).
            ancestor(X,Y) :-
                        child(Y,X).
            ancestor(X,Y) :-
                        child(Y,P),
                        ancestor(X,P).





3.     Write a program to prepare a calculator that perform different operations like add, mul, sub, div, etc. (implementation of switch statement using cut).

predicates
        nondeterm action(integer,integer,integer)
        go
       
clauses
        go:-
                    write("Enter Operand 1:  "),
                    readreal(A),
                    write("Enter Operand 2:  "),
                    readreal(B),
                    write("1. Addition"),nl,
                    write("2. Subtraction"),nl,
                    write("3. Multiplication"),nl,
                    write("4. Division"),nl,
                    write("Select the operation by entering number:   "),
                    readreal(S),
                    action(A,B,S).
        action(A,B,1) :-
                    !,
                    nl,
                    R=A+B,
                    write("Addition of given numbers is:  ",R),nl.
        action(A,B,2) :-
                    !,
                    nl,
                    R=A-B,
                    write("Subtraction of given numbers is:  ",R),nl.
       
        action(A,B,3) :-
                    !,
                    nl,
                    R=A*B,
                    write("Multiplication of given numbers is:  ",R),nl.
       
        action(A,B,4) :-
                    !,
                    nl,
                    A>B,
                    R=A/B,
                    write("Division of given numbers is:  ",R),nl.
       
        action(A,B,_) :-
                    !,
                    nl,
                    write("Unknown Input"),nl.
        


Read more...
Related Posts Plugin for WordPress, Blogger...

Engineering material

GTU IDP/ UDP PROJECT

GTU IDP/ UDP PROJECT

Patel free software download

  © Blogger templates The Professional Template by Ourblogtemplates.com 2008

Back to TOP