Showing posts with label AI. Show all posts
Showing posts with label AI. Show all posts

Structure of Programs in Turbo Prolog


        Programs consist of procedures.
        Procedures consist of clauses.
        Each clause is a fact or a rule.
        Programs are executed by posing queries.

Facts:

  • Properties of objects, or relationships between objects;
  • "Dr Turing lectures in course 9020", is written in Prolog as: lectures (turing, 9020).

HERE:  lectures (Turing, 9020). is also called a predicate

Converting English to  Prolog  facts & rules:
 John is the father of Susan.    à father (john,susan).
 John is the husband of Martha. à  husband (john,martha).
 John eats pizza.  à eats(john, pizza).

Prolog Features in AI

Significant Language Features:
Prolog is a rich collection of data structures in the language and human reasoning, and a powerful notation for encoding end-user applications. It has its logical and declarative aspects, interpretive nature, compactness, and inherent modularity.
  • Intelligent Systems - programs which perform useful tasks by utilizing artificaial intelligence techniques.
  • Expert Systems - intelligent systems which reproduce decision-making at the level of a human expert.
  • Natural Language Systems - which can analyse and respond to statements made in ordinary language as opposed to approved keywords or menu selections.
  • Relational Database Systems
Language Features:
The main characteristics/notions of the Visual Prolog programming language are:
  • based on logical programming with Horn clauses
  • fully object oriented
  • object predicate values (delegates)
  • strongly typed
  • algebraic data types
  • pattern matching and unification
  • controlled non-determinism
  • fully integrated fact databases
  • supports parametric polymorphism
  • automatic memory management
  • supports direct linkage with C/C++
supports direct calling of Win32 API functions

Introducation PROLOG.in AI


Prolog (programming in logic) is one of the most widely used programming languages in artificial intelligence research. As opposed to imperative languages such as C or Java (which also happens to be object-oriented) it is a declarative programming language. That means, when implementing the solution to a problem, instead of specifying how to achieve a certain goal in a certain situation, we specify what the situation (rules and facts) and the goal (query) are and let the Prolog interpreter derive the solution for us. Prolog is very useful in some problem areas, such as artificial intelligence, natural language processing, databases,

Prolog is a ‘declarative’ language........
        Clauses are statements about what is true about a problem, instead of instructions how to accomplish the solution.
        The Prolog system uses the clauses to work out how to accomplish the solution by searching through the space of possible solutions.

        Not all problems have pure declarative specifications. Sometimes extra logical statements are needed. 

Example of AI program

I given below program use basic terms of AI used.That's term are study in structure of AI for click below Back sign. That's term used in the program.In this program used to identify relatton other perionship with other person.That relation defined in the program.And program used it.

Example:
Given relation for member of family.That is given as prediction of user.That is useful for identify user interface for it.

Given three relations child(X,Y):X is a child of Y, male(X):X is male,female(X):X is female.Give 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 and  Raman
  • Ashok and Rajesh
  • Payal   and  Bhaumik

The below example consist of  the relation member of the family.That's the above person relation need to be defines.There is also need to define some basic requirement assumption that's used.The program are given below: 


 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),  


The structure of AI


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) 

write a prolog to find m^n value

Program program have calculate m tends to n power.In the program we need to take input.predicates from user is m and n.The type of value takes as integer,not foat supports.There is some allready solution takes as 
  • if m=0 and n=any then m^n=0.
  • If m=any and n=1 then m^n=1.
That's answer is correct from all situation.The other calculation based on the below logic:
  • decrease multiplication of m to n and decrease value of n.
  • Then need to multiplication m with original value of n.
  • That's process until n get 0.
  • The program is given below:

Here we used below type of predication and clauses:
predication:power(int,int,int) and clauses go and power(m,n,ans).here ans is used for the result.We 
need to display result using ans.

               go
               power(integer,integer,integer)
clauses
               go:-
                              write("Enter the value of m:"),
                              readint(M),
                              write("Enter the value of n:"),
                              readint(N),
                              power(M,N,A),
                              write("M power N is:",A,"\n").
                         
               power(M,0,A):-
                              A=1.
               power(0,N,A):-
                              A=0.
               power(M,N,A):-
                              B=N-1,
                              power(M,B,S),
                              A=M*S.

AI:Prolog write a prolog pro to find factorial of given number.

We need to calculate factorials of any number given by user.There are some allready result have o factorials have result 1 and 1 factorials also result 0.The two predication are used in the proggram as go and fact(int,int).

We need to get input value that is identifies factorials value need.The basic formulas that is find the factorials are given belows:
  • Takes input from user.
  • decrease value of number.
  • The decrease value store other variable.
  • Then multiplication original value to the decrease value.
  • That's process until, we not get 1.
The answer is sore using other variable that multiplication process get result.The below program have some predication and clauses are given belows:
The predication are go and fact(int,int).And clauses that is go,fact(0,1),fact(1,A),fact(N,A).


predicates
               go
               fact(integer,integer)
clauses
               go:-
                              write("Enter the no.:"),
                              readint(N),
                              fact(N,A),
                              write("Factorial:",A,"\n").
               fact(0,A):-
                              A=1.
               fact(1,A):-
                              A=1.
               fact(N,A):-
                              B=N-1,
                              fact(B,S),
                              A=N*S.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       .