Notes: Artificial Intelligence (Msc/Mca)
Notes: Artificial Intelligence (Msc/Mca)
ARTIFICIAL INTELLIGENCE
UNIT-1
Introduction of Artificial Intelligence : What is AI ? The Importance of AI. AI and related
fields. Introduction to Natural Language Processing .
UNIT-2
Knowledge : General Concepts, Definition and Importance of Knowledge, Knowledge
based system, representation of Knowledge, Knowledge Organization , Knowledge
Manipulation , Acquisition of Knowledge.
UNIT-3
LISP AND AI PROGRAMMING LANGUAGES : Introduction to LISP : Syntax and Numeric
Functions, Basic List Manipulation Functions in LISP , Functions, Predicates, and
Conditionals, Input, Output, and Local Variables, Iteration and Recursion, Property List
and arrays, PROGLOG and Other AI Programming Languages.
UNIT-4
FORMALIZED SYMBOLIC LOGICS : Introduction , Syntax and Semantics for Propositional
Logic , Syntax and Semantics for FOPL , Properties of Wffs , Conversion to Clausal Form,
Inference Rules , The Resolution Principle , Representations Using Rules.
UNIT-5
Introduction to Expert System , Characteristics features of Expert System, Applications
of Expert System. Importance of Expert System.
BOOKS :
1. Clockskin, W.F. and Mellish, C.S. : Programming in prolog, Narosa publ. House.
2. Charniak, E. : Introduction of Artificial Intellegence, Narosa publ. House.
3. Winston,P.H. : LISP, NArosa publ. House.
4. Milner : Common LISP : A tutorial , Prentice Hall Inc. 1988.
5. Marcellus : Expert Systems Programming in TURBO PROLOG, P.H.I. 1989.
6. Elaime R. : Artificial Intelligence, 1983.
7. Hunt, E.B. : Artificial intelligence, Academic Press 1975
8. Lloyd,J. : Foundation of Logic Programming, Springer-Verlag 1982.
9. clark, K.L. : Micro Prolog , Prentice Hall india.1987.
UNIT-1
Artificial Intelligence is one of the newest fields of intellectual research, but its
foundations began thousands of years ago. In studying Artificial Intelligence, it is useful
to have an understanding of the background of a number of other subjects, primarily
philosophy, linguistics, psychology, and biology.
- Artificial intelligence is the study of systems that act in a way that to any observer
would appear to be intelligent.
- Artificial Intelligence involves using methods based on the intelligent behavior of
humans and other animals to solve complex problems.
- Artificial Intelligence is the study of human intelligence and actions replicated
artificially, such that the resultant bears to its design can think and act like humans
rationality (doing the right thing).
- The art of creating machines that performs functions that require intelligence when
performed by humans.
- Artificial Intelligence is a branch of Science which deals with helping machines finds
solutions to complex problems in a more human-like fashion.
- This generally involves borrowing characteristics from human intelligence, and
applying them as algorithms in a computer friendly way.
- GPS - General Problem Solver.
AI means Artificial Intelligence which is a branch of computer science concern with the
study and creation of computer systems that exhibit some form of intelligence as:
AI may be one of the most important developments of this century. Many countries have
focus on importance of AI and make a plane to development for research work in AI and
for this they have passed budget like-
Japanese were first announced fifth generation computer in October 1981 with budget
of about one billion dollars and produce systems that can converse a natural language,
understand speech and visual scenes, learn and refine their knowledge, make decisions
and exhibit other human traits.
Following Japanese other countries plan to some form of AI program. British initiated a
plan called Alvey Project with respectable project.
The European Common Market countries have jointly initiated a plan called ESPRIT
program.
Other countries also initiated for AI research and development plans as French, Canada,
Soviet Union, Italy, Austria, Irish Republic and Singapore.
The United State push forward in AI research. First in 1983 there was formation of
consortium known as Microelectronics and computer technology corporation (MCC)
headquartered in Austin, Texas. It develop advanced technologies that apply AI
techniques like VLSI. Second development of DARPA ( Defense Advanced Research
Projects Agency) has increase AI research, including development support in three
significant programs:
Early 1936: Alan Turing, sometimes regarded as the father of AI. He had demonstrated
a simple computer processor (also called Turing machine) that manipulated symbols as
well as numbers.
1956-57: Logic Theorist, First automatic theorem proving program by Newell, Shaw and
Simon. List Processing language also developed.
1961-65: A.L. Samuel developed a program which learned to play checkers at a master
level.
AI is generally associated with Computer Science, but it has many important links with
other fields such as Math, Psychology, Cognition, Biology and Philosophy, among many
others. Our ability to combine knowledge from all these fields will ultimately benefit our
progress in the quest of creating an intelligent artificial being.
• Logical AI
What a program knows about the world in general the facts of the specific
situation in which it must act, and its goals are all represented by sentences of
some mathematical logical language. The program decides what to do by
inferring that certain actions are appropriate for achieving its goals.
• Search
AI programs often examine large numbers of possibilities, e.g. moves in a chess
game or inferences by a theorem proving program.
• Pattern Recognition
When a program makes observations of some kind, it is often programmed to
compare what it sees with a pattern. For example, a vision program may try to
match a pattern of eyes and a nose in a scene in order to find a face.
Author: Mr. Lokesh Rathore (MCA/MTech)
WhatsApp&Call: 9425034034, website: www.LRsir.net, Email: [email protected]
P a g e |4
Notes: Artificial Intelligence(MSc/MCA)
• Representation
Facts about the world have to be represented in some way.
• Inference
Like when we hear of a bird, we can infer that it can fly, but this conclusion can
be reversed when we hear that it is a penguin.
• Planning
Planning programs start with general facts, they generate a strategy for
achieving the goal.
• Epistemology
This is a study of the kinds of knowledge that are required for solving problems
in the world.
• Ontology
Ontology is the study of the kinds of things that exist. In AI, the programs and
sentences deal with various kinds of objects, and we study what these kinds are
and what their basic properties are.
• Heuristics
A heuristic is a way of trying to discover something or an idea imbedded in a
program. Heuristic functions are used in some approaches to search to measure
how far a node in a search tree seems to be from a goal. Heuristic predicates that
compare two nodes in a search tree to see if one is better than the other, i.e.
constitutes an advance toward the goal, may be more useful.
• Genetic Programming
Genetic programming is a technique for getting programs to solve a task by
mating random Lisp programs and selecting fittest in millions of generations.
Application of AI:
• Game Playing
You can buy machines that can play master level of game like chess. There is
some AI in them, that play well against people.
• Speech Recognition
it is possible to instruct some computers using speech, in place of keyboard and
mouse which is more convenient.
• Understanding Natural Language A collection of techniques used to enable
computers to “understand” human language.
• Expert Systems
One of the first expert systems was MYCIN in 1974, which diagnosed bacterial
infections of the blood and suggested treatments. It did better than medical
students
Author: Mr. Lokesh Rathore (MCA/MTech)
WhatsApp&Call: 9425034034, website: www.LRsir.net, Email: [email protected]
P a g e |5
Notes: Artificial Intelligence(MSc/MCA)
- NLP is the branch of computer science focused on developing systems that allow
computers to communicate with people using everyday language. It is also called
Computational Linguistics.
- NLP is a sub field of AI which deals with the methods of communicating with a
computer in once on natural language. It includes understanding and generation
as well as other task such as multi lingual translation.
- Natural languages are used by humans for communication. They are distinctly
different from formal languages, such as C++, Java, and PROLOG because they are
not ambiguous.
- A system that can work with one human language cannot necessarily deal with
any other human language.
Advantages of NLP:
NLP minimizes many hardships a person’s faces while communicating with the
computer.
1) One need not be a computer literate to communicate with it.
2) One can dispose of special query languages like SQL, which presently humans
use to access information from databases.
Meaning of Linguistics:
In a natural language, sentence is the basic language element that made up of
words and has a subject and a predicate. Sentences are classified by structure and
predicate like- simple, compound and complex sentences. Sentences are used to assert,
query and describe. Sentences are declarative, imperative, interrogative or exclamatory.
conjunctions(or) and interjections(oh!). Phrases are the part of words but acts as a
single unit within a sentence. All these form the building blocks for syntactic structures.
P: SNP VP
NPART N
VPV NP
Nboy|popsicle|frog
Vate|kissed|flew
ART the|a
Ex: The boy ate a popsicle. This sentence can be generated using the following sequence
of production rules:
SNP VP
ART N VP
the N VP
the boy VP
the boy V VP
the boy ate NP
the boy ate ART N
the boy ate a N
the boy ate a popsicle.
It should be clear that a grammar does not guarantee the generation of meaningful
sentences, only that they are structurally correct. For example, a grammatically correct,
but meaningless sentence like “The popsicle flew a frog” can be generated with this
grammar.
Structural Representations:
It is convenient to represent sentences as a tree or graph to help to expose the structure
of the constituent parts. For example, the sentence “ The boy ate a popsicle” can be
represented as –
The left sub tree is a noun phrase and the right sub tree a verb phrase. The leaf or
terminal nodes contain the terminal symbol from Vt.
A tree structure such as the above represents a large number of English
sentences. It also represents a large class of ill formed strings that are non sentences
like “ The popsicle flew a frog”. This satisfied the above structure, but has no meaning.
UNIT-2
- Knowledge : General Concepts
- Definition and Importance of Knowledge
- Knowledge based system
- Representation of Knowledge
- Knowledge Organization
- Knowledge Manipulation
- Acquisition of Knowledge.
In order to solve the complex problems encountered in AI, one generally needs a large
amount of knowledge, and suitable mechanisms for representing and manipulating all
that knowledge. Knowledge can take many forms. Some simple examples are:
- John has an umbrella.
- It is raining.
- An umbrella stops you getting wet when it’s raining.
- An umbrella will only stop you getting wet if it is used properly.
- Umbrellas are not so useful when it is very windy.
So, we need to study, how should an AI agent store and manipulate knowledge like this?
Knowledge Based System can become effective as problem solvers only when specific
knowledge was brought to bear on the problems.
• Sources of Knowledge:
1) Documented (books, journals, procedures, films, databases)
2) Undocumented (people’s knowledge and expertise, people’s minds,
other senses)
• Types Knowledge:
• Categories of Knowledge:
1) Declarative- (descriptive, facts, shallow knowledge)
2) Procedural- (way things work, tells how to make inferences)
3) Semantic- (symbols)
4) Episodic- (autobiographical, experimental)
5) Meta-knowledge- (Knowledge about the knowledge )
Importance of knowledge:
AI has given new meaning and importance to knowledge. Now a day’s system can
reason and draw conclusion only by embedding knowledge with AI .
Imagine being able to purchase an untiring, reliable advisor that gives high level
professional advise in a specialized area’s such as:
- Manufacturing technique
- Sound financial strategies
- Ways to improve one’s health
- Top marketing sectors and strategies
- And many others important matters.
Author: Mr. Lokesh Rathore (MCA/MTech)
WhatsApp&Call: 9425034034, website: www.LRsir.net, Email: [email protected]
P a g e | 12
Notes: Artificial Intelligence(MSc/MCA)
-------------------------------------------
Knowledge-Based System?(KBS)
o Knowledge Base systems are often called expert systems because the problems
in their application domain are usually solved by human experts.
o For example medical diagnosis is usually performed by a doctor.
o KBS is Heuristic rather than algorithmic
o Knowledge is separated from how it is used:
Knowledge-base: The knowledge base contains the domain knowledge useful for
problem solving.
In a rule-based expert system, the knowledge is represented as a set of rules. Each rule
specifies a relation, recommendation, directive, strategy or heuristic and has the:
_________________________
For Example: we can use mathematical logic as the representation formalism. Consider
the English sentences below.
Spot is a dog
This fact can also be represented in logic as follows:-
Dog(Spot)
Approach to Knowledge Representation:
There are multiple techniques for knowledge representation. Some of them are-
Rules
Semantic Networks
Frames
Propositional and Predicate Logic
Rules Based:
Semantic Networks:
It is based on-
• Graphical depictions
• Nodes and links
• Hierarchical relationships between concepts
• Reflects inheritance
In semantic networks knowledge is represented as a collection of concepts, represented
by nodes (shown as boxes in the diagram), connected together by relationships,
represented by arcs (shown as arrows in the diagram). certain arcs - particularly isa
arcs - allow inheritance of properties.
Frames:
The idea of frame hierarchies is very similar to the idea of class hierarchies found in
object-orientated programming.
o a name.
o slots: these are the properties of the entity that has the name, and they
have values. A particular value may be:
a default value
- In the higher levels of the frame hierarchy, typical knowledge about the class is
stored.
- The value in a slot may be a range or a condition.
- In the lower levels, the value in a slot may be a specific value, to overwrite the
value which would otherwise be inherited from a higher frame.
- An instance of an object is joined to its class by an 'instance_of' relationship.
- A class is joined to its superclass by a 'subclass_of' relationship.
- Frames may contain both procedural and declarative knowledge.
Knowledge Organization:
Knowledge manipulation:
Knowledge Acquisition:
Knowledge Engineer(KR)
It requires that the knowledge engineer mediate between the expert and
the knowledge base. The knowledge engineer elicits knowledge from the expert, refines
it in conjunction with the expert and represents the knowledge in the knowledge base
using a suitable knowledge structure.
Manual:
Semi Automatic: Use a computerised system to support and help experts and
knowledge engineers.
Automatic: Minimise the need for a knowledge engineer or expert.
UNIT-5
Expert system is one of the areas of artificial intelligence. An expert system also
known as knowledge based system is a computer program that contains the knowledge
and analytical skills of one or more human experts in a specific problem domain.
Expert system is a computer program that simulates the judgment and behavior
of a human that has expert knowledge and experience in a particular field. It contains a
knowledge base containing accumulated experience and a set of rules.
The goal of the design of the expert system is to capture the knowledge of a
human expert relative to some specific domain and code this in a computer in such a
way that the knowledge of the expert is available to a less experienced user.
Expert system provides high quality experience, domain specific knowledge;
apply heuristics, forward or backward reasoning, uncertainty and explanation
capability. Rule based expert system contains knowledge base, Inference engine,
knowledge acquisition, explanation facility and user interface. For knowledge
representation techniques, forward and backward chaining rules are used.
Expert systems are designed to emulate an expert in a specialized knowledge
domain such as medicine or any other area of knowledge where there is a shortage of
expert knowledge. The knowledge base elicited from the expert by a trained knowledge
engineer using various methods can include methodical interviews and the repertory
grid technique. Often the expert knowledge area is "fuzzy" in nature and contains a
great deal of procedural knowledge, so the knowledge engineer must be an expert in the
process of knowledge elicitation.
Knowledge Base:
It is a warehouse of the domain specific knowledge captured from the human
expert via the knowledge acquisition module. To represent the knowledge production
rules, frames, logic, semantic net etc. is used.
Inference Engine:
Inference Engine is a brain of expert system. It uses the control structure (rule
interpreter) and provides methodology for reasoning. The major task of inference
engine is to trace its way through a forest of rules to arrive at a conclusion. Here two
approaches are used i.e. forward chaining and backward chaining.
Knowledge Acquisition:
Knowledge acquisition is the accumulation, transfer and transformation of
problem-solving expertise from experts and/or documented knowledge sources to a
computer program for constructing or expanding the knowledge base. For knowledge
acquisition, techniques used are protocol analysis, interviews, and observation.
Explanation Facility:
It is a subsystem that explains the system's actions. Here user would like to ask
the basic questions why and how and serves as a tutor in sharing the system’s
knowledge with the user.
User interface:
It provides facilities such as menus, graphical interface etc. to make the dialog
user friendly. Responsibility of user interface is to convert the rules from its internal
representation (which user may not understand) to the user understandable form.
To build the expert system is known as Knowledge Engineering. The expert and
knowledge engineer should anticipate user’s need while designing an expert system.
The value of expert systems was well established by early 1980s. A number of
successful applications had been completed by then and they proved to be cost
effective. A example which illustrates this point well is the diagnostic system
developed by the Campbell Soup Company.
Campbell Soup uses large cookers to cook soups and other canned products at
eight plants located throughout the company. For the maintenance of cooker fault,
only a single human expert was to diagnosis. He had to flying all site when
necessary. Since this individual will retire after some year then company decided
computer based expert system to diagnosis cooker fault problem.
After some month, Texas Instruments, developed an Expert System used to
provide training to new maintenance personal.
Thus computer expert system never retire, so its very great importance in many
areas.
UNIT-3
LISP AND AI PROGRAMMING LANGUAGES :
- Introduction to LISP :
- Syntax and Numeric Functions
- Basic List Manipulation Functions in LISP
- Functions, Predicates, and Conditionals
- Input, Output, and Local Variables
- Iteration and Recursion
Author: Mr. Lokesh Rathore (MCA/MTech)
WhatsApp&Call: 9425034034, website: www.LRsir.net, Email: [email protected]
P a g e | 24
Notes: Artificial Intelligence(MSc/MCA)
Different Flavors of LISP: Several dialects of LISP are FRANZLISP, INTERLISP, MACLISP,
QLISP, SCHEME and COMMON LISP.
Running the LISP program: LISP program run on an interpreter or as compiled code.
The interpreter examines source programs in a repeated loop (read-evaluate-print).
This loop reads LISP program code, evaluate it, and print the value returned by the
program. LISP interpreter read code using -> prompt.
Ex:
-> (+ 5 6 7)
19
-> Input here next lisp instruction.
Atom, list and string are the valid object in LISP, also called “ Symbolic Expressions or S-
expressions”.
“a b c d e fgh #$%@!”
Invalid: this is not string, “welcome to LISP
When any one is given at prompt then LISP interpreter return as it is form.
-> 12
12
-> t
T
-> nil
Nil
Function call: In LISP a number of functions are available to perform any operation.
Every operation is called function and applying content (atom, list, string) called
argument. Everything written in list form and function-name written as prefix.
Syntax for function call : (function-name arg1 arg2 -----)
When a function is called, the arguments are first evaluated from left to right and
function is executed using the evaluated argument values.
--------------------------------
Syntax and Numeric function : (+,-,*,/) Arithmetic function operate only passing
numeric arguments (integer or real value).
Op means (+ or – or * or /)
-> (- 4 1) gives 3
4) / (Divide): Divide two given arguments.
-> (/) It has zero argument so gives error
-> (/ 9 3) gives 3
Prevent evaluation of List or atom : We precede atom or list with ' (single quotation
mark).
Ex:
-> 'man
Man
-> '(+ 3 5)
(+ 3 5) Not evaluate due to preceding (')
->(+ 3 5)
8 Evaluated due to absent of preceding (') mark.
Declaring Variable (setq): Used to hold data ( atom/ list) for further use and return
last bound data. Unbound variable gives error.
It need two argument-First must be variable name and second may be any atom or list
with or without (') preceding mark. Second Data have (') assign to variable without
evaluate.
Ex1:
-> (setq x 10)
10
->x
10
Single value evaluated and assign to variable x.
Ex2:
-> (setq x (+3 8)
11
->x
11
First (+3 8) evaluated and result assign to variable x.
Ex3:
-> (setq x '(+3 8))
(+ 3 8)
->x
(+ 3 8)
Here (+3 8) does not evaluated due to preceding (') and assign completely to variable x.
This function need only one argument in list form and as the result returns top
element of given list.
Example-
-> (car '(a b c))
Output: a
a is the top of list (a b c)
2) Cdr:
This function need only one argument in list form and as the result returns a list
except first top element of list.
Example-
-> (cdr '(a b c))
Output: (b c)
Element a removes from list (a b c)
3) Cons:
This function need only two arguments, an element (atom or list) and a list, as
the result returns a list with the element inserted at the beginning of list.
Example-
-> (cons 'a '(b c))
Output: (a b c)
Element a add at top of list (b c)
4) List:
This function is used to create a list for given a number of elements as
arguments. It returns a list.
Example-
-> (list 'a '(b c) 'd)
Output: (a (b c) d)
Create a list contain a,(b c) and d.
5) Append:
Merges two or more lists into a single list.
Example-
-> (append '(a) '(b c))
Output: (a b c)
All argument must be list.
6) Last:
Returns a list containing the last element.
Example-
-> (last '(a b c d))
Output: (d)
7) Member: (searching function)
Returns remainder of second argument list starting with element matching first
argument.
Example-
-> (member 'b '(a b c d))
Output: (b c d)
8) Reverse:
Author: Mr. Lokesh Rathore (MCA/MTech)
WhatsApp&Call: 9425034034, website: www.LRsir.net, Email: [email protected]
P a g e | 28
Notes: Artificial Intelligence(MSc/MCA)
Defining Functions:
It is possible to user define functions in LISP. i.e. user can define own function
according to his requirement. In LISP this task is performed using predefine defun
function.
Syntax:
->(defun udfn(p1 p2 ….pn ) body )
Here-
defun= function maker
ufn= user define function name
p= list of parameter which receive values
body= single line of logic in list form.
Ex1: function for average of three numbers.
-> (defun averagethree(n1 n2 n3) (/ (+ n1 n2 n3) 3) )
Output:AVERAGETHREE
Author: Mr. Lokesh Rathore (MCA/MTech)
WhatsApp&Call: 9425034034, website: www.LRsir.net, Email: [email protected]
P a g e | 29
Notes: Artificial Intelligence(MSc/MCA)
Predicate functions:
Predicates are function that test their arguments for some specific condition and
return true (t) or false (nil). (Except for the predicate-member)
The most common predicates are:
1) atom: It needs one argument, if argument is an atom then returns t(true)
otherwise nil(false).
Ex:
-> (atom 'a) output: t
-> (atom '(a)) output: nil
2) listp: It needs one argument, if argument is a list then returns t(true) otherwise
nil(false).
Ex:
-> (listp '(a)) output: t
-> (list 'a) output: nil
3) numberp: It needs one argument, if argument is a number then returns t(true)
otherwise nil(false).
Ex:
-> (numberp 123) output: t
-> (numberp 12ab)) output: nil
4) evenp: It needs one argument, if argument is a even number then returns t(true)
otherwise nil(false).
Ex:
-> (evenp 8) output: t
-> (evenp 9) output: nil
5) oddp: It needs one argument, if argument is a odd number then returns t(true)
otherwise nil(false).
Ex:
-> (oddp 9) output: t
-> (oddp 8) output: nil
6) null: It needs one argument, if argument is a nil or empty list () then returns
t(true) otherwise nil(false).
Ex:
-> (null nil) output: t
-> (null ()) output: t
-> (null (8)) output: nil
7) zerop: It needs one argument, if argument is a zero value then returns t(true)
otherwise nil(false).
Author: Mr. Lokesh Rathore (MCA/MTech)
WhatsApp&Call: 9425034034, website: www.LRsir.net, Email: [email protected]
P a g e | 30
Notes: Artificial Intelligence(MSc/MCA)
Ex:
-> (zerop 0) output: t
-> (zerop 8) output: nil
8) equal: It needs two arguments, if both arguments have same value then returns
t(true) otherwise nil(false).
Ex:
-> (equal 'a (car '(a b)) output: t
-> (equal 'a (cdr '(a b)) output: nil
9) greaterp (>): It needs one or more arguments. If it has only one argument then
returns t(true). If more than one arguments are used than it returns t(true) if the
arguments, from left to right, are successively larger, otherwise nil(false) is
returned.
Ex:
-> (greaterp 2 ) output: t
-> (greaterp 2 4 8) output: t
-> (greaterp 2 4 4) output: nil
10)lessp (<):It needs one or more arguments. If it has only one argument then
returns t(true). If more than one arguments are used than it returns t(true) if the
arguments, from left to right, are successively smaller, otherwise nil(false) is
returned.
Ex:
-> (lessp 2 ) output: t
-> (lessp 8 4 2) output: t
-> (lessp 8 4 4) output: nil
11)>= : It has similar leaning of greaterp, except they return t(true) if successive
elements are also equal.
Ex:
-> (>= 2 ) output: t
-> (>= 2 4 8) output: t
-> (>= 2 4 4) output: t
12)<= : It has similar leaning of lessp, except they return t(true) if successive
elements are also equal.
-> (<= 2 ) output: t
-> (<= 8 4 2) output: t
-> (<= 8 4 4) output: t
Syntax :
(cond (<test1> <action1>) (<test1> <action1>)………(<testk> <actionk>))
Features of cond:
- Cond function can test one or more conditions.
- If <test1> evaluates t(true) then <action1> portion is evaluated, its value is
returned and the remaining condition parts are skipped.
- If <test1> evaluates to nil, control passes to the second part without evaluating
<action1> and the procedure is repeated.
Author: Mr. Lokesh Rathore (MCA/MTech)
WhatsApp&Call: 9425034034, website: www.LRsir.net, Email: [email protected]
P a g e | 31
Notes: Artificial Intelligence(MSc/MCA)
->(setq x (read))
8 (enter)
8 (output, 8 has assigned to x)
-> x (enter)
8 (value of x)
Prinl function: Same as print except that new line and a space are not provided as well
as does not return its argument to another function.
For example:
-> ((prinl '(hello)) (print '(hello)))
(hello)(hello)
->
Princ function: it is same as prinl except that It does not print unwanted quotation
marks like “” with argument. It return argument after print.
-> (princ “hello”)
Hello “HELLO”
->
terpri function: it takes no argument. It introduces a new-line wherever it appears and
then returns nil.
For example: to compute the area of a circle
-> (defun circle-area ()
(terpri)
(princ “enter the radius”)
(setq rad (read))
(princ “The area of the circle is: ”)
(princ (* 3.1416 rad rad))
(terpri))
CIRCLE-AREA
-> (circle-area)
Enter the radius 4
The area of the circle is: 50.2656
In this program princ function print multiple items on the same line, so we use terpri to
introduce a new-line sequence.
format function: Using this function we can print output with variables value and
newline characters, i.e. we can set format according to our needs.
Syntax: (format <destination> <string> arg1, arg2, …)
Here-
Destination=place of output. monitor(t) or some other external file.
String= Desired output that Intermixed with format directives.
Arg1,arg2,..= Arguments that will print in place of directive appear in the string.
Local variable will be preference over global variable. Local variable can be created as-
Ex:
(a b c)
->(setq x '(d e f)
(d e f)
Here x and y are global variable for any function body’s x and y.
Local-var
Here (x) and setq y are local whereas y within (cons) is global.
-> (local-var 6)
(6 a b c)
-> x
Author: Mr. Lokesh Rathore (MCA/MTech)
WhatsApp&Call: 9425034034, website: www.LRsir.net, Email: [email protected]
P a g e | 34
Notes: Artificial Intelligence(MSc/MCA)
(d e f)
->y
(a b c)
It’s clear that parameter and variable of any function are called local variable.
Creating local variable using let: Using let function we can create more than one
variables and used in any expression.
Values are assigned to associated variables. Local variables can be used in expression
and it return evaluated value of expression.
Ex:
-> (let ((x 2)(y 4)) (+ x y))
6
->(let ((x ‘a) (y ‘b) (z ‘c)) (cons x (cons y (list z))))
(A B C)
Creating local variable using prog function: The prog function is similar to let
function but it may be any number of s-expressions.
Syntax- (prog ( (var1 val1) (var2 val2)…) <s-expressions1> <s-expressions2>……)
Not-equal
Iteration and recursion: Iteration is one form of loop whereas recursion is a special
kind of user function.
Iteration: When a set of statements are executed more than one times using a loop until
a given condition satisfied called iteration. Every times statements do not relocated.
Syntax: using do function we can create an iteration.
(do (<var1 val1> <var-update1>)
(<var2 val2> <var-update2>)
.
.
(<test> <return-value>)
(<s-expression>)
)
Here:
- <val> are initial values that bounds to <var> variables parallel first time then
<test> is evaluated.
- If<test> gives nil value then all <var> are parallel updated with <var-update>
value. This process continued until test get non-nil(true).
- If <test> get non-nil any time then iteration process stops and it return <return-
value>.
- <s-expression> is optional. If present, executed with each iteration
Ex: factorial function
->(defun factorial(n)
( do
(i n (- i 1))
(f n (* f (- i 1))
((equal 1 i) f)
)
)
Factorial
-> (factorial 4)
24
Initially value 4 assign to i and f, since i is not 1 so test give nil and second times i update
by 3(- i 1) and f updated by 12(* f (- i 1). After some iteration i updated by 1 then test
give non-nil and iteration will terminate with f value.
Property lists:
The most useful unique features of LISP as an AI language is the ability to assign
properties to atoms. There are following property list functions used to assign, retrieve,
replace and remove properties to an atom.
1) putprop
2) remprop
3) get
4) setf
1) putprop: It is used to assign a value with properties to an atom and returns assigned
value.
Syntax: (putprop atom value property)
Ex:
->(putprop 'car 2013 'year)
2013
->(putprop 'car 'red 'color)
red
2) remprop: It is used to remove any property from atom and return value.
Syntax: (remprop atom property)
Ex:
-> (remprop 'car 'year)
2013
3) get: It is used to retrieve value of property for given atom.
Syntax: (get atom property)
Ex:
-> (get 'car 'color)
Red
4) setf: It is used to reset property of any atom by new value.
syntax: (setf (get atom property) new-value)
Ex:
-> (setf (get 'car 'color) 'blue)
blue
Array:
Collection of items that stores continuously called array. To create and access array we
use following three function.
1) make-array: It is used to create a new blank array of given size in memory.
Syntax:
(setf arr-name (make-array '(size)))
Ex:
->(setf myarray(make-array '(5)))
Output: #A(nil,nil,nil,nil,nil)
Miscellaneous functions:
1) mapcar function: We can add each element of given list by a number using
mapcar function.
->(mapcar '1+ '(5 10 15 20 25))
Output: (6 11 16 21 26)
2) lambda function: using this function we can use one function body more than
one times for single function call.
Ex: find cube of each number of given list.
-> (defun cube-list(lst)
(mapcar #'(lambda(x) (* x x x)) lst) )
Output: cube-list
-> (cube-list (1 2 3 4))
Output:( 1 8 27 64)
When a function is called by another function, it should be preceded by #'
indicate following item is a function.
Internal storage: Lists are made through the use of linked cell structures in memory.
For example: (a (b c (d)) e f) can be represented as-
History:
PROLOG(PROgramming in LOGic) was invented by “Alain Colmerauer” and his
associates at the university of Marseilles during the early 1970s.
Resolution process of PROLOG:
It uses the syntax of predicate logic to perform symbolic, logical computations.
Programming in PROLOG is accomplished by creating a database of facts and rules
about objects, their properties, and their relationships to other objects. Queries can then
be posed about the objects and valid conclusions will be determined and returned by
the program. Responses to user queries are determined through a form of inferencing
control known as resolution.
Facts representation in PROLOG:
Facts are declared with predicates and constants written in lowercase letters.
The arguments of predicates are enclosed in parentheses and separated with
commas(,).
Ex: some facts about family relationship can be written in PROLOG as-
1) sister(sue, bill) - sue is sister of bill.
2) parent(ann, sam) - ann is parent of sam.
3) parent(joe,ann) - joe is parent of ann.
4) male(joe) - joe is a male.
5) female(ann) - ann is a female.
Here sister, parent, male and female are predicate, whereas sue, bill, ann and sam are
arguments.
Rules in PROLOG:
Rules are composed of a condition or “if” part and a conclusion or “then” part
separated by a symbol (:-). Rules are used to represent general relations which hold
when all of the conditions in the if part are satisfied. Rules may contain
variables(uppercase).
Ex: PROLOG rules for grand father, we write
Grandfather(X,Z):- parent(X,Y), parent(Y,Z), male(X)
This rule has following meaning-
For all X, Y and Z,
X is the grand father of Z
If X is the parent of Y, and Y is the parent of Z and X is the male.
Query in PROLOG:
When a database of facts and rules such as that above have given, then we make
queries by typing after (?) symbol such as-
?- parent(X, sam) -who is parent of sam
X=ann -Answer
?- male(joe)
Yes
?- grandfather(X,Y)
X=hoe, Y=sam
?- female(joe)
no
PROLOG searches database for submitted query. If a proper match found between
predicates of query and database then returns response with proper result or failure
occurs.
Lists in PROLOG: Each item must be separated by commas(,) and enclosed in square
brackets[ ].
Ex: [tom, sue,joe,mary,bill] is the list of student in PROLOG.
A list may be empty or non empty. A non empty list has head and tail. Tom is the head
and remaining sublist [sue,joe,mary,bill] is tail.
UNIT-4
FORMALIZED SYMBOLIC LOGICS: Introduction
Syntax and Semantics for Propositional Logic
Syntax and Semantics for FOPL
Properties of Wffs
Conversion to Clausal Form
Inference Rules
The Resolution Principle
Representations Using Rules.
----------------------------------------------------------------------------------------------------------------
Introduction:
FOPL (First Order Predicate Logic) is one of the oldest and most important scheme for
knowledge representation in logical reasoning and mathematical form. Application of
logic as a practical means of representing and manipulating knowledge in a computer
was not demonstrated until the early 1960s. But today, FOPL or predicate calculus has
one of the most important roles in AI for representing knowledge.
FOPL is important for AI professionals because-
1) Logic offers the formal approach to reasoning.
2) Structure of FOPL permits the accurate representation of natural language
reasonably well.
3) To understand AI articles, knowledge of FOPL required because it is commonly
used to design AI programs.
In FOPL English like statements are translated into symbolic structures consists using
predicates, functions, variable, constant, quantifiers and logical connectives . They form
a structure using syntax for FOPL. Once structures of facts or other type of knowledge is
created, inference rules are applied on it for new “deduced” structures.
Ex: “ All employees of the AI-software company are programmers” can be written in
FOPL as –
(∀x)(AI-SOFTWARE-CO-EMPLOYEE(x)→PROGRAMMER(x))
∀x is read as “for all x”.
AI-SOFTWARE-CO-EMPLOYEE(lokesh)
PROGRAMMER(LOKESH)
Thus we conclude that in this way we can translate knowledge in the form of English
sentences can be translated into FOPL statements.
About PL:
Syntax:
The syntax of PL is recursively as follows. T and F are formulas. If P and Q are formulas,
the following are formulas:
(~P)
(P & Q)
(P ⋁ Q)
(P→Q)
(P↔Q)
All formulas are generated from a finite number of the above operations.
P&~Q⋁R→S↔U⋁W
We write ((((P&(~Q))⋁R)→S)↔(U⋁W))
Semantics/Meaning
Semantics/Meaning of PL:
Meaning of formula is just truth values (true or false) i.e. assignment of truth value to
formulas. An interpretation of formulas is assignment of truth value to each
propositional symbol. The semantic rules of PL are represented as
Properties of statements:
statements:
Idempotency P⋁P=P
P&P=P
Associativity (P⋁Q)⋁R=P⋁(Q⋁R)
(P&Q)&R=P&(Q&R)
Commutativity P⋁Q=Q ⋁ P
P & Q=Q & P
P↔Q = Q ↔ P
Distributivity P&(Q⋁R)= (P&Q)⋁(P&R)
P⋁ (Q&R)= (P⋁Q) & (P⋁R)
De Morgan’s laws ~(P⋁Q)=~P & ~Q
~(P & Q)= ~P⋁~Q
Conditional elimination P→Q = ~P ⋁ Q
Bi-conditional elimination P↔Q=(P→Q)&(Q→P)
Determine equivalence of two sentences: It is done by truth table. For example, we can
show using truth table that (P→Q)=(~P⋁Q) and (P↔Q)=(P→Q)&(Q→P) are
constructed equivalence or not.
Syntax and
and Semantics for FOPL:
FOPL was developed by logicians to extend the expressiveness of PL. It is generalization
of PL that permits reasoning about world objects as relational entities as well classes or
subclasses of objects. This generalization comes from the introduction of predicates in
place of propositions, use of functions and use of variables together with variable
quantifiers.
Syntax of FOPL:
The symbols and rules of combination permitted in FOPL are defined as follows.
Constants.
Constants. Fixed value terms belong to a given domain D and denoted by numbers(23),
words(lokesh) and small letters near the beginning of alphabet(a,b,c).
Variables.
Variables. terms that can assume different value over a given domain D and denoted by
words or small letters near the end of alphabets(x,y,z).
Terminology of FOPL: Constants, variable and function are referred to as terms, and
predicates are referred to as atomic formulas or atom. Atom or its negation referred as
literal. () and {} are the used for punctuations.
Given-
E1: All employees earning $1400 or more per year pay taxes.
E2': ∃y (E(y)→S(y))
E1 read as- “for all x if x is employee and income of x is greater than or equal to 1400
then x pays taxes”
E3 read as-“for all x and for all y, if x is employee and y is president then income of x
should not greater than or equal to income of y.”
The expression E1’,E2’ and E3’ are known as well-formed formulas or wffs(woofs).
Semantics of FOPL:
When an assignment of values is given to each term and to each predicate symbol in a
wff, we say an interpretation is given to the wff. Literals are always true or false value
under an interpretation. The value of any given wff can be determined by referring to a
truth table, similar to PL.
The predicate P(x) in ∀x P(x), is true only if it is true for every value of x in the domain.
The predicate P(x) in ∃x P(x), is true only if it is true for at least one value of x in the
domain.
All properties of PL(propositional logic) are exists as well as some more additional
properties are included due to ∀(for all) and ∃(for some). Some important laws of PL:
Step3: Rename variables if necessary so that all remaining quantifiers have different
variable assignments.
Step5: Move all universal quantifiers to the left of the expression and put the
expression on the right into CNF.
Step6: Eliminate all universal quantifiers and conjunctions since they are retained
implicitly.
The resulting expressions are clauses and the set of such expressions is said to be in
clausal form.
∃x ∀y(( ∀z P(f(x)
f(x),y,z)→(∃u
f(x) Q(x,u) & ∃v R(y,v) ) ) into clausal form.
Step1: ∃x ∀y(( ~(∀z) P(f(x),y,z) ⋁ (∃u Q(x,u) & (∃v) R(y,v)) ) Eliminate →
Step5: ∀y((~P(f(a),y,g(y))
∀y(( ⋁ Q(a,h(y))) & ( ~P(f(a),y,g(y)) ⋁ R(y,i(y)) )) move
universal quantifier to left.
~P(f(a),y,g(y)) ⋁ R(y,i(y))