Unit 5 Ai
Unit 5 Ai
What is LISP?
• LISP (LISt Processing) is one of the oldest programming languages, invented by John
McCarthy in 1958, mainly for Artificial Intelligence (AI) research.
• It emphasizes symbolic computation—the manipulation of symbols rather than
numbers.
Key Features:
Syntax Overview:
Examples:
(+ 2 3) ; 5
(- 7 4) ; 3
(* 3 4) ; 12
(/ 8 2) ; 4
Function: read
Syntax:
(setq x (read))
Example:
Output in LISP
To define variables that are accessible only within a specific block or function.
Syntax:
Example:
(defun add-two-numbers ()
(print "Enter first number: ")
(setq a (read))
(print "Enter second number: ")
(setq b (read))
(let ((sum (+ a b)))
(format t "Sum is: ~d~%" sum)))
Call it using:
(add-two-numbers)
Interaction in LISP
In LISP, interaction refers to the real-time communication between the user and the
program using:
Recursion in LISP
Recursion is a process where a function calls itself to solve a smaller part of a problem.
(factorial 5) → 120
(fibonacci 6) → 8
LISP interpreters can optimize tail-recursive functions (where recursive call is the last
step).
Example:
Concept Description
Interaction Enables dynamic user-program communication using input/output
REPL Interactive environment for live LISP programming
Recursion A function calling itself to solve subproblems
Tail Recursion Optimized recursion with no stack overhead
Importance Essential for AI tasks like list processing, decision trees, etc.
A Property List (or plist) in LISP is a list that stores pairs of property names and values.
Each even indexed elementis a property name (keyword), and the next is its value.
Syntax:
(setq animal '(:name "Dog": sound "Bark": legs 4))
Here, :name: sound, and: legs are property keys, and "Dog", "Bark", and 4 are their
corresponding values.
Accessing Properties
Arrays in LISP
An array is a fixed-size indexed data structure used for efficient data access. LISP
supports 1D, 2D, and multi-dimensional arrays.
Creating Arrays
(make-array size)
Example (1D array):
(setq a (make-array 5))
This creates an array with 5 elements, all initially NIL.
Example:
(setf (aref a 0) 10)
(setf (aref a 1) 20)
Multi-dimensional Arrays
(setq matrix (make-array '(3 3))) ; 3x3 matrix
Disadvantages of Arrays:
Disadvantage Description
Fixed size Cannot resize after creation
Less flexible Compared to lists
Initialization needed Need to assign values or use initial-element
Common AI Languages:
1. Propositional Logic
a. Deals with simple, true/false statements
b. Example: A ∧ B → C
2. First-Order Logic (FOL)
a. Adds quantifiers and predicates
b. Example: ∀x (Human(x) → Mortal(x))
3. Second-Order Logic
a. Allows quantification over predicates/functions
b. More expressive, less decidable
What is WERS?
Key Properties:
Example:
Application in AI:
Limitation:
2. Abductive Reasoning: Reasoning from an effect or observation to the most likely cause.
Example:
Application in AI:
Limitation:
3. Default Reasoning: Making assumptions that are generally true unless proven
otherwise.
Example:
Application in AI:
Limitation:
Example:
Techniques:
• Bayesian Networks
• Markov Models
• Fuzzy logic systems
Application in AI:
Limitation:
Example:
Application in AI:
Limitation:
• Heuristics may be inaccurate or misleading.
Reason Explanation
Real-world problems are uncertain We rarely have complete information
Deals with noise and ambiguity Useful in NLP, vision, decision-making
Enables learning from experience Machine learning relies on induction
Supports flexible decision-making AI systems need to revise beliefs