Unit 3 AI
Unit 3 AI
1. Propositional Logic
o Example:
Examples:
Examples:
Summary
FOPL: Adds the ability to talk about objects, their properties, relationships, and functions.
The syntax of FOPL defines the allowed symbols and how to combine them to form valid statements.
Here's a breakdown of its key components:
1. Constants
2. Predicates
o Example:
3. Functions
o Example:
Sqrt(4) (the square root of 4), LeftLegOf(x) (the left leg of x).
4. Variables
o Example:
5. Connectives
6. Quantifiers
Summary
Predicates (properties/relationships),
Quantifiers (universal/existential).
1. Atomic Sentences
Definition: The simplest facts or relationships expressed with predicates and terms.
Examples:
1. Brother(KingJohn, RichardTheLionheart)
Meaning: "The length of Richard's left leg is greater than the length of King John's
left leg."
2. Complex Sentences
Logical Connectives:
o S1 ⇒ S2 (IMPLIES): If the first statement is true, the second must also be true.
Example: King(KingJohn) ⇒ Rich(KingJohn) means "If King John is a king, then King
John is rich."
Definition:
Easy Examples:
1. ∀x (Student(x) ⇒ Studies(x))
2. ∀x (Dog(x) ⇒ HasTail(x))
Definition:
o Used to say that at least one object exists that satisfies a condition.
Easy Examples:
1. ∃x (Student(x) ∧ PlaysFootball(x))
2. ∃x (Cat(x) ∧ Black(x))
Summary
1. Universal Quantifiers (∀): Statements that apply to all objects.
2. Existential Quantifiers (∃): Statements about the existence of at least one object.
Key Idea
Universal (∀) and Existential (∃) quantifiers are connected through negation.
A statement with a universal quantifier can often be rewritten as a negated existential quantifier,
and vice versa.
Easy Example:
Statement 1:
o Meaning: For every person (x), that person does NOT like garlic.
Statement 2:
o Meaning: It is NOT true that there is at least one person who likes garlic.
Connection
Logical equivalence:
o Universal quantifiers can be replaced with negated existential quantifiers, and vice versa.
Summary
1. ∀x ¬... ("For all, not...") is equivalent to ¬∃... ("It is not true that there exists...").
2. Example:
o "Nobody likes chocolate" can be written as:
∀x ¬Likes(x, Chocolate) OR
Conversion to FOPL (First-Order Predicate Logic) – Simplified Explanation with Easy Examples
1. Bill is a student
FOPL: Student(Bill)
o Meaning: For every student x, there is at least one student y whom x loves.
o Meaning: Bill takes at least one of these courses: Analysis or Geometry (or both).
o Meaning: For every student x, there is at least one course y that x takes.
o Meaning: If a student x takes Analysis, then they must also take Geometry.
PROLOG
Features of Prolog
1. What is Prolog?
2. Declarative Nature
o Prolog is declarative, meaning you describe what the program should accomplish, not
how to do it.
o This is very different from traditional languages like Java, C++, or Python, which are
imperative (focus on step-by-step instructions).
o A Prolog program is like a database of facts (e.g., Student(Bill) or Parent(Mary, John)), but
more powerful.
o Example of a rule:
Grandparent(X, Z) :- Parent(X, Y), Parent(Y, Z).
4. Sophisticated Search
o A Prolog interpreter can search through facts and rules to answer queries.
o Example Query:
If you ask Grandparent(Mary, John)?, Prolog will search its database and rules to
determine if the statement is true.
o Knowledge representation.
o Problem-solving.
Facts:
Parent(Mary, John).
Parent(John, Anna).
Rule:
Query:
Grandparent(Mary, Anna)?
Prolog Program
A Prolog program is a text file (usually with the .pl extension) that contains the facts and rules for
the program.
It is like a database where facts are stored and rules are applied to derive new information.
2. The Query Mode in Prolog
This asks Prolog to check whether the given statement is true or false, based on the facts and rules
defined in the program.
Example:
prolog
Copy code
?- parent(mary, john).
Prolog will check if Mary is the parent of John by searching through the facts defined in the
program.
To load and run a Prolog program, you need to use a Prolog compiler.
o Example: family.pl
o Example:
?- [family].
4. Once loaded, you can ask queries about the facts and rules in your program.
Facts:
parent(mary, john).
parent(john, anna).
parent(anna, bob).
Rule:
Query:
?- grandparent(mary, bob).
Explanation: Prolog will use the facts and rule to check if Mary is the grandparent of Bob.
1. Simple Facts
Example:
prolog
Copy code
sunny.
rainy.
No arguments are needed because they are just simple, standalone facts.
o These facts include arguments that describe specific entities or relationships between
them.
Example:
prolog
Copy code
likes(john, mary).
father(ram, luv).
These facts provide more detailed information by including arguments (e.g., john, mary, ram, luv).
Queries in Prolog are used to check if something is true based on the facts and rules defined
in the program.
Example 1:
eats(fred, oranges).
Example 2:
eats(tony, apple).
Example 3:
eats(john, apple).
When you ask a query, Prolog checks if the query matches any facts in the database.
Example Query:
?- eats(fred, oranges).
Prolog will check if the fact eats(fred, oranges) exists in the program.
Example 2:
?- eats(john, apple).
If there is a fact eats(john, apple) in the program, Prolog will return Yes.
Summary:
Facts in Prolog represent information about the world, either simple or with arguments.
Queries ask Prolog to check if a statement is true based on the facts in the program.
Prolog uses matching to check if the query matches any facts in the database, responding with
Yes or No.
Variables in Prolog are distinguished from atoms because they start with a capital letter or an
underscore (_).
They are placeholders that can represent any value during queries or pattern matching.
Examples:
?- eats(fred, What).
What = oranges.
Here, What is a variable that Prolog replaces with oranges because the fact eats(fred, oranges)
exists in the program.
?- eats(Who, oranges).
Who = fred.
2. Unification in Prolog
Unification is the process by which Prolog matches a query with facts or rules in the database.
During unification:
o Variables are replaced with values that make the query true.
Facts:
?- book(_, _, author2).
Explanation:
o This query checks if there is any book with author2 without specifying the book ID or
title.
Result:
Explanation:
Result:
o X = title1;
o X = title2.
?- book(X, _, _).
Explanation:
o X retrieves all book IDs, while _ ignores the title and author.
Result:
o X = 1;
o X = 2;
o X = 3;
o X = 4.
Summary:
Variables in Prolog are placeholders (e.g., What, Who, X) used to match facts dynamically.
Unification is how Prolog matches queries with facts or rules in the database.
Prolog can provide multiple solutions by unifying variables with all possible matches.
Rules in Prolog
Rules are statements in Prolog that define relationships or logic between facts.
o Right-hand side: The condition (what must be true for the conclusion to hold).
Syntax:
conclusion :- condition.
2. Example Rule: All Men Are Mortal
Facts:
human(socrate).
Rule:
mortal(X) :- human(X).
?- mortal(socrate).
Response:
o Yes.
?- mortal(X).
Response:
o X = socrate.
1. Facts in Database:
human(socrate).
2. Rule:
mortal(X) :- human(X).
o Query:?-mortal(socrate).
Response: Yes.
o Query?-mortal(X).
Response: X = socrate.
Summary:
The condition (right-hand side) must be true for the conclusion (left-hand side) to hold.
Unification
What is Unification?
Unification is like finding a match between two logical expressions by replacing variables with
actual values or objects.
It helps Prolog or logic systems make connections between facts and rules to draw
conclusions.
If an object has a property and all objects with that property also have another property,
then the object must have the second property.
Easy Example:
1. Rule:
o In logic:
∀x (Student(x) → Studies(x)).
2. Fact:
o “Sam is a student.”
o In logic:
Student(Sam).
3. Question:
o In logic:
?- Studies(Sam).
4. Unification Process:
Studies(Sam).
1. Rule:
o In logic:
∀x (Rains(x) → Wet(x)).
2. Fact:
o In logic:
Rains(Delhi).
3. Conclusion:
o Result:
Wet(Delhi).
We are using the UNIFY algorithm to match a query with statements in the knowledge base.
o In logic: Knows(Ravna, x)
(Here, x is a variable that can represent anyone Ravna knows.)
1. Knows(Ravna, Sita)
2. Knows(y, Ram)
3. Knows(y, Mother(y))
4. Knows(x, Radha)
Steps of Unification
The UNIFY algorithm compares the query Knows(Ravna, x) with each fact from the knowledge base
and tries to find substitutions that make them match.
o Result:
x = Sita
o Result:
x = Ram, y = Ravna
o Result:
y = Ravna, x = Mother(Ravna)
o No unification is possible.
o Result:
FAIL
Summary Table
Diagram Representation
1. Query: Knows(Ravna, x)
2. Matching Facts:
Knows(Ravna, Sita) → x = Sita
Key Takeaways
3. Variables (x, y) are placeholders that get replaced with actual values during unification.
If P is a variable:
o Example:
P = x, Q = 5 → Substitute x = 5.
If the predicate names (like Knows, Loves, etc.) in P and Q are different, unification fails.
o Example:
Start with no substitutions (SUBST = NIL). This will store all the changes made during the
unification process.
o If FAIL occurs for any argument pair, stop and return FAIL.
o Otherwise, update P and Q with the substitution. Add the substitution to SUBST.
After all arguments are unified, return SUBST, which contains all the substitutions needed to
make P and Q identical.
Easy Example
Input:
Unify Knows(John, x) and Knows(y, Mary).
Step-by-Step Execution:
1. Predicate Check:
y = John
x = Mary
Key Points
Skolemization Explained
What is Skolemization?
In first-order logic, existential quantifiers (∃) represent the existence of something, making
them difficult to work with during inference.
Skolemization removes these quantifiers while retaining the logical meaning of the expression.
Steps in Skolemization
o Example:
o Example:
∀x ∃y P(x, y) becomes ∀x P(x, f(x)), where f(x) is a Skolem function.
Examples
Input: ∃x Rich(x)
Input: ∀x ∃y P(x, y)
2. Now, for ∃y, replace y with a Skolem function g(v, x) (because y is preceded by universal
quantifiers ∀v and ∀x).
Result: ∀v ∀x P(f(a), v, x, g(v, x)) ⇒ Q(v, a, g(v, x))
Skolem Function: Used when existential quantifiers are preceded by universal quantifiers.
Skolemization makes logical formulas easier to use in inference while preserving their
meaning.
What It Is: Works from given facts to arrive at a conclusion step by step.
How It Works:
2. Check which rule's condition matches these facts in the rule base.
3. If a rule matches, execute its action, which may add new facts to the working memory.
4. Repeat the process until the desired conclusion is reached or no more rules apply.
Key Features:
Example:
o Rule 2: If the ground is wet, then plants grow. (Wet ground → Plants grow)
o Fact: It is raining.
o Process:
o Example: You know the weather conditions (e.g., raining, sunny) and want to deduce
possible outcomes (e.g., plants growing, traffic delays).
o Example: In troubleshooting, you might start with facts about a malfunctioning device
and gradually deduce the issue by applying rules.
See forward and backward chaining illustration diagram and diff of
forward and backward chaining from ppt
Backward Chaining/Reasoning
3. Repeat this process until all sub-goals are verified or no further rules can be applied.
4. The system appears focused and logical because it directly targets the solution.
Example:
3. Checks for sore throat: "Does the patient have a sore throat?"
o Example: In medical diagnosis, the system may ask for lab test results to proceed
further.
Applications:
When to Use:
How it Works:
Starts with the goal and works backward to find the facts that support it.
Example:
Checks conditions (like fever, sore throat) to confirm or deny the conclusion.
Forward Chaining (Bottom-up approach):
When to Use:
You don’t know the final solution or goal from the start.
How it Works:
Example:
Given symptoms like fever, cough, and sore throat, the system concludes, "The patient may
have the flu."
Key Differences:
When to
Clear goal known upfront Goal is unknown or broad
Use
Resolution in Logic
Introduced by Robinson (1965): A method for deriving conclusions in logic, particularly useful
in automated theorem proving.
Principle:
o Given two clauses, A and B, if there is a complementary literal (e.g., one is P and the
other is ¬P) between them, remove the literals and combine the rest of the clauses to
create a resolvent.
Steps of Resolution:
o Resolve them by finding complementary literals and combining the rest of the literals
(with appropriate substitutions).
2. Apply Resolution:
o Now, apply resolution to the set of clauses with the negation of the goal.
o Find complementary literals and create resolvents by combining clauses until a
contradiction is found or the goal is confirmed.
Conclusion:
Knowledge Representation
Knowledge Based Systems
Definition and Importance of Knowledge
Knowledge is the body of facts and principles accumulated by humankind,
and it plays a crucial role in intelligence.
Intelligence requires access to knowledge, and in both biological
organisms and computers, knowledge is stored in various forms.
o In biological organisms, it’s stored in neurons.
o In computers, it’s stored as symbolic structures like magnetic spots
and voltage states.
Knowledge Vs Data
Data refers to raw facts (e.g., a patient's medical record).
Knowledge is the learned information (e.g., a physician’s medical training
and experience).
Example:
Data: Patient’s history, vital signs, drug responses.
Knowledge: What the physician learned during education and practice.
Knowledge is derived from data and information.
Types of Knowledge
1. Procedural Knowledge: Knowledge of how to perform tasks (e.g., steps to
solve an algebraic equation).
2. Declarative Knowledge: Passive knowledge expressed as facts (e.g.,
personal data in a database).
3. Heuristic Knowledge: Knowledge used to solve complex problems, often
through judgment or rule of thumb.
Knowledge-Based Agents
A knowledge-based agent combines general knowledge with percepts to
infer hidden aspects of the current state and decide on actions.
Process:
1. It TELLs the knowledge base what it perceives.
2. It ASKs the knowledge base what action to perform.
3. It performs the chosen action.
Representation of Knowledge
1. Propositional Logic
2. First-Order Predicate Logic (FOPL)
3. Frames & Associative Networks
4. Scripts
5. Case Grammar Theory
6. Production Rules
7. Inference System
8. Forward & Backward Deduction
Each of these methods offers ways to represent knowledge, ensuring that
systems can store, manipulate, and infer from information effectively.
See its all diags in ppt
Ontology Engineering
What is Ontology Engineering?
Ontology engineering refers to the process of developing ontologies for a
specific domain. This involves:
Defining terms in the domain and relationships between them.
Defining concepts (classes) in the domain.
Organizing concepts in a subclass-superclass hierarchy.
Defining attributes and properties (slots) for each class, including
constraints on their values.
Defining individuals and filling in their property values.
Example Continued
1. Subclass Relations:
o A category can be a subcategory of another category, establishing a
taxonomic hierarchy:
Basketballs ⊂ Balls (All basketballs are a type of ball).
2. Properties of Category Members:
o All members of a category have certain properties. For example:
If x ∈ Basketballs, then Spherical(x) (All basketballs are
spherical).
3. Recognition of Category Members by Properties:
o A category's members can be identified by specific properties. For
example:
If x ∈ Balls, and Orange(x) ∧ Round(x) ∧ Diameter(x) = 9.5,
then x ∈ Basketballs (A ball with these properties is a
basketball).
4. Category Properties:
o A category itself can also have properties. For instance:
Dogs ∈ Domesticated Species (Dogs are members of the
category of domesticated species).
Further Example
Categories Classify Objects: Categories are used to classify objects based
on common properties or definitions. For example:
o ∀x ∈ Tomatoes ⇒ Red(x) ∧ Round(x) (All tomatoes are red and
round).
Representing Categories:
o Predicates: Tomato(x) means x is a tomato.
o Sets: We can also represent categories using sets. For instance,
Tomatoes as a set of tomatoes (reification).
Measurements
In both scientific and commonsense knowledge, objects can have
measurable properties such as height, mass, cost, etc. The values assigned to
these properties are referred to as measures.
Conversion Between Units:
Measurements often involve converting between different units. For
example, length can be expressed in inches or centimeters:
Length(L1) = Inches(1.5) = Centimeters(3.81) (Converting 1.5 inches to
3.81 centimeters).
The conversion between units can be expressed as:
Centimeters(2.54 × d) = Inches(d) (For example, 1 inch = 2.54 centimeters).
Example of Measures:
Diameter(Basketball12) = Inches(9.5) (The diameter of Basketball12 is 9.5
inches).
ListPrice(Basketball12) = $(19) (The price of Basketball12 is $19).
d ∈ Days ⇒ Duration(d) = Hours(24) (If d is a day, its duration is 24 hours).
These measurements and conversions help describe objects and their
properties in a standardized and logical manner.
Mental Events and Mental Objects
Overview
Events are actions or occurrences that can be described using formal logic or
event calculus. In this context, mental events and mental objects can be
understood as events and objects occurring within the mind.
Events
In event calculus, fluents and events are reified. A fluent refers to a state or
fact that can change over time. For example, At(Shankar, Berkeley) refers to
the fact that Shankar is in Berkeley, but this alone doesn’t tell us whether it is
true or not. To assert its truth at a given time t, we use the predicate T, as in
T(At(Shankar, Berkeley), t).
Events are instances of event categories, and can be described using
predicates. For example:
The event E1 of Shankar flying from San Francisco to Washington, D.C. can
be described as:
o E1 ∈ Flyings ∧ Flyer(E1, Shankar) ∧ Origin(E1, SF) ∧ Destination(E1,
DC)
This formalization captures the details of the event (the flyer, the origin, and
destination) and places it within the broader category of "flying events."
Mental Events
Mental events are cognitive activities or processes that occur within an
individual's mind. These events can include:
Thinking
Remembering
Perceiving
Imagining
Experiencing emotions
Making decisions
Problem-solving
Mental events are subjective experiences, and they encompass both
conscious and unconscious states. For example, thinking about an upcoming
event or feeling anxious about a situation would both be mental events, as
they are processes that occur in the mind.
Mental Objects
Mental objects are the content or objects of thought within the mind. These
are the things, ideas, or concepts that we think about during mental events.
They can be:
Concrete: Representations of sensory experiences, like the mental image
of an apple or a dog.
Abstract: Ideas or concepts like justice, love, or mathematical equations.
In philosophy, the study of mental objects focuses on how the mind
represents or perceives the external world. For example, the mind might
represent the concept of "freedom" or "equality" as a mental object, even
though these are abstract concepts without physical form.
Key Differences:
Mental Events: The activities or processes (e.g., thinking, imagining) that
occur within the mind.
Mental Objects: The specific concepts, ideas, or representations that are
the focus of mental events.
Both mental events and objects are fundamental in understanding cognition
and consciousness, as they form the basis for how we perceive and process
the world around us.
Simple Overview of Belief Representation
In AI, beliefs are important for making decisions and planning, especially
when agents need to consider themselves and others.
Conclusion
In simple terms, beliefs in AI are treated as things that agents can think about,
and we use rules to make them reason logically. This allows agents to make
decisions based on what they know or believe.
Reasoning Systems for Categories (Simplified)
What is Reasoning?
Reasoning is the logical process of drawing conclusions or making
predictions based on existing knowledge.
It enables AI systems to think rationally, similar to humans.
Types of Reasoning
1. Deductive Reasoning:
o Derives a specific conclusion from general facts.
o Example:
Premise 1: All humans eat veggies.
Premise 2: Suresh is a human.
Conclusion: Suresh eats veggies.
2. Inductive Reasoning:
o Makes generalizations based on specific observations.
o Example:
Premise: All pigeons we saw are white.
Conclusion: All pigeons are white.
3. Abductive Reasoning:
o Finds the most likely explanation for an observation.
o Example:
Premise: The cricket ground is wet.
Conclusion: It might have rained.
4. Common Sense Reasoning:
o Relies on everyday experiences to make assumptions.
o Example:
If I put my hand in fire, it will burn.
5. Monotonic Reasoning:
o Once a conclusion is drawn, it cannot be invalidated by new facts.
o Example:
The Earth revolves around the Sun.
6. Non-monotonic Reasoning:
o Conclusions can change with new information.
o Example:
Birds can fly → Pitty is a bird → Pitty can fly.
Add info: Pitty is a penguin → Pitty cannot fly.
Organizing and Reasoning with Categories
1. Semantic Networks:
o Definition: Graphical systems to organize and reason with
categories.
o Benefits:
Visualize relationships.
Infer properties efficiently.
2. Description Logics:
o Definition: A formal language for defining categories and their
relationships.
o Tasks:
Subsumption: Check if one category is a subset of another.
Classification: Check if an object belongs to a category.
Consistency: Ensure definitions don’t conflict.
Examples
Basic Example
Default: "Articles about AI are interesting."
Facts:
o If an article is about AI, it is interesting.
Conclusion: Articles about AI are interesting.
Adding Exceptions
Fact: Some AI articles are boring.
Rule: If an article is boring, it is not interesting.
Result: We cannot assume all AI articles are interesting anymore.
Overriding Rules
Specific rules override general rules.
Example:
o General Rule: "Articles about AI are interesting."
o Specific Rule: "Articles about formal logic are boring."
o Result: Formal logic articles are not interesting, even if they are
about AI.
Key Points to Remember
1. Default Logic: Assume truth unless contradicted.
2. Non-Monotonic Reasoning: New information can change old conclusions.
3. Conflicts: Specific rules always win over general ones.
4. Purpose: Simplifies reasoning when information is incomplete.