You are on page 1of 24

Generality in AI: From Programs to Solvers

By using right data-structures, heuristic search algorithms, and heuristic functions, its possible to write programs for solving problems like: Rubiks Cube 15-puzzle Blocks-World Route Finding, etc. Intelligence, however, is tied to the ability to solve new problems Can we actually write such general programs; i.e., programs capable of solving an innite collection of problems not anticipated by programmmer? Such programs called solvers; well move in that direction now . . .

Hector Gener, Intro to AI, Kings College, 2014

Example: Solver for Linear Equations

Problem = Solver = Solution Problem: The age of John is 3 times the age of Peter. In 10 years, it will be only 2 times. How old are John and Peter? Expressed as: J = 3P ; J + 10 = 2(P + 10) Solver: Gauss-Jordan (Variable Elimination) Solution: P = 10 ; J = 30

Solver is general as deals with any problem expressed as an instance of model Linear Equations Model, however, is easy (polynomial); AI models are not . . .

Hector Gener, Intro to AI, Kings College, 2014

AI Models and Solvers

Problem = Solver = Solution Constraint Satisfaction/SAT: nd values for variables to satisfy constraints E.g., Sudoku, N-Queens, Graph Coloring, Magic Square, . . . Planning: nd action sequence to drive system from initial state to goal state Rubiks Cube, 15-puzzle, Blocks-World, Logistics, . . . Bayesian Networks, General Game Playing, Planning with feedback ... Solvers for these models are general; not tailored to specic domains Models are all intractable, and some extremely powerful Main challenge is computational: how to scale up Methodology is empirical: benchmarks and competitions We will focus mainly on SAT and Planning
Hector Gener, Intro to AI, Kings College, 2014 3

Propositional Logic and SAT

Logic is the study of valid forms of inference More than 2000 years old More recently, led to development of modern computers (Turing) Many other applications in Computer Science and AI representation languages programming languages verication systems inference in intelligent systems

Hector Gener, Intro to AI, Kings College, 2014

Example: Inference in Wumpus World

Stench Breeze PIT

Breeze Breeze Stench PIT Stench Breeze PIT Breeze


The Wumpus World is game used in main AI textbook (Russell and Norvig) Agent must grab gold while avoding little monster and pits Gold, monster, and pits locations, however, unknown Agent has sensors to detect stench, breeze, brightness Stench and breeze sensed next to monster and pit; brightness sensed where there is gold

Where agent should move next? What are the following moves? Why?

Hector Gener, Intro to AI, Kings College, 2014

An example of everyday inference

John, Peter, and Tom order pizzas in a restaurant. The waiter eventually comes back with the pizzas, and asks Who ordered Margarita? and hands the Margarita pizza to John. Then he asks Who ordered Pepperoni? and hands the Pepperoni pizza to Tom. The waiter nally does not ask Who ordered Gorgonzola?; rather he hands the Gorgonzola pizza directly to Peter.

Questions: What is the inference made by the waiter? Is the inference correct? Why? Is it about pizzas or something more general? How can this be done in general? Logic provides an answer to all these questions . . . and more
Hector Gener, Intro to AI, Kings College, 2014 6

A formal system covering three dimensions: Formal Language: denes the formulas Formal Semantics: denes what is a valid inference Proof Theory: denes rules for making valid inferences. Logics come in many forms and shapes, like propositional and predicate logic, modal logics, conditional logics, and so on, according to form of inferences that want to be captured. We will focus on propositional logic.

Hector Gener, Intro to AI, Kings College, 2014

Propositional Logic: The Language

Propositional language dened inductively as set of expressions P such that propositional symbols p, q , r, . . . are in P , if A in P , A is in P if A in P and B in P , then (A op B ) in P for op {, , }

Expressiones in P called formulas Operators in {, , , } called connectives, unary or binary. Often parentheses omitted when no ambiguity created (precedence rules as in arithmetic)

Hector Gener, Intro to AI, Kings College, 2014

Examples of Propositional Formulas

(p q ): read p or q (p q ): read p and q (p q ): read p implies not q (p q ): read its not the case that p and q , .. Logical structure of English sentences encoded by suitable formulas: If John goes to the party, Peter will go as well: p q If Peter goes, then neither Mary nor Anne will go: p (m a) The machine is on but not working: on w Light is red only when machine is on and not working: (red (on w)) ((on w) red) Its not true that both Peter and Tom came: (p t) Only one of them came: (p t) (p t)
Hector Gener, Intro to AI, Kings College, 2014 9

Structure of Propositional Formulas: Syntactic Trees

Its useful to visualize the structure of a formula as a tree whose leaves are the symbols in the formula, and whose internal nodes represent the connectives: The tree associated with symbol p has just pas only node The tree associated with A has root node connected to root of tree for A The tree associated with (A op B ) has root node op connected to roots of trees for A and B Syntactic tree for formula (p (q r)) is: p
Hector Gener, Intro to AI, Kings College, 2014

q r

Propositional Logic: Semantics and Validity

Semantics determines when inference of formula B from A1, . . . , An is valid B is then said to follow from A1, . . . , An or to be deducible If inference is valid, written as A1, . . . , An |= B ; if not, as A1, . . . , An |= B Formulas Ai called premises and formula B conclusion E.g., is inference from (p (q r)) and (q r) to p r valid? i.e., is it (p (q r)), (q r) |= p r or (p (q r)), (q r) |= p r As we see next, semantics determines validity of inference in terms of the truth of tentative conclusion B in the truth valuations that satisfy all the premises A1 , . . . , A n

Hector Gener, Intro to AI, Kings College, 2014


Truth Valuations and Satisfaction

A truth valuation v over language P is an assignment of truth values (true, false) to the symbols in P A truth valuation over the symbols in P determines a truth valuation V over all formulas in P by virtue of truth tables associated with the connectives For example, if v such that v (p) = v (q ) = true, then V (p q ) = V (p q ) = true Formally, given truth valuation v over symbols, V (A) is true i A A A A A is is is is is symbol p and v (p) is true B and V (B ) is false (B C ) and V (B ) or V (C ) is true (B C ) and both V (B ) and V (C ) are true (B C ) and its not the case that V (B ) is true and V (C ) is false

Hector Gener, Intro to AI, Kings College, 2014


Determine truth value V (A) of formula A = (p q ) (r q ) given valuation v such that v (p) = v (q ) = v (r) = true Find truth valuation v that makes the formula true, i.e., V (A) = true Its common to write true as 1 and false as 0 Also, a valuation is said to satisfy a formula if it makes it true A formula is satisable if there is a valuation that satises it

Hector Gener, Intro to AI, Kings College, 2014


Semantics: Denitions and Wrap up

Inference of formula B from A1, . . . , An is valid, written A1, . . . , An |= B , i all the valuations that satisfy all premises A1, . . . , An, satisfy conclusion B Examples: p q |= p p q, q |= p p q, q r |= p r p q |= q p p q |= q p Brute force procedure for testing validity: check truth of premises and conclusion in each of the 2n possible valuations, where n is the number of symbols involved in these formulas In the worst case, one cannot do better, but on average yes . . .

Hector Gener, Intro to AI, Kings College, 2014


Semantics: Tautologies, Contradictions, Logical Equivalence

A formula A is a tautology if |= A A is a contradiction if it is not satisable, which means if |= A A and B are logically equivalent if satised by the same valuations Some properties: A |= B i |= (A B ) A |= B i (A B ) is a contradiction A and B logically equivalent i |= ((A B ) (B A)) Some examples; A and B logically equivalent abbreviated as A B : A A is a tautology A A is a contradiction p and p logically equivalent (double negation) (p q ) and (p q ) logically equivalent (distribution) (p q ) and (p q ) logically equivalent (distribution) (p q ) and (p q ) logically equivalent (material implication)

Hector Gener, Intro to AI, Kings College, 2014


Propositional Logic: Proof Theory

Semantics characterizes valid inference, but provides no rules for constructing valid inferences Proof theory provides rules for capturing all and only valid inferences A proof theory P denes derivations in terms of axioms and rules of inference A derivation is a nite sequence of formulas, in which each formula is an axiom in P , a premise, or follows from earlier formulas in the sequence by a rule of inference in P B is derivable from A1, . . . , An in P , written A1, . . . , An derivation for B in P with premises A1, . . . , An A proof theory P is sound if A

B if there is a

B implies A |= B

A proof theory P is complete if A |= B implies A

Hector Gener, Intro to AI, Kings College, 2014


Many Types of Proof Theories

Axiomatic Systems: based on a few axiom schemas and one or two rules of inference (e.g., modus ponens with the form if H A B and H A, then H B ). Derivations often long and not natural. Natural Deduction: based on no axioms and a several rules of inference. Natural derivations can be constructed by hand, but dicult to control automatically. Resolution based on no axioms and a single (resolution) rule of inference that works on clauses only (disjunction of possibly negated atoms, also called literals).

Hector Gener, Intro to AI, Kings College, 2014


Resolution: Clauses
Resolution works over formulas of a special type called clauses A clause is a set literals where a literal is a prop. symbol p or its negation p The clause with no literals is called the empty clause, 2, which is unsatisable E.g., p q r is a clause, p is a clause; p q and p are not clauses Any set of formulas can be converted into a logically equivalent set of clauses E.g., p (q r) is logically equivalent to {p q, p r}

Hector Gener, Intro to AI, Kings College, 2014


Resolution Rule
The resolution rule takes two clauses such that one contains a literal p and the other contains the complementary literal p, and produces a third clause; more precisely: if p C and p C , then C C , where C and C are (potentially empty) clauses This is resolution on the literal p that produces the resolvent C C As another example, the resolution of two clauses q r p and t r on the literal r produces the resolvent q p t; while the resolution of clauses p and p yields 2 Resolution is refutation complete, meaning that a set of clauses is unsatisable i empty clause 2 derivable by repeated applications of the resolution rule Thus, A1, . . . , An |= B i empty clause derivable from resolution from clauses encoding A1, . . . , An and B . Why?
Hector Gener, Intro to AI, Kings College, 2014 19

Example: Formalizing arguments in propositional logic

Model the following argument in propositional logic and prove the conclusion both semantically and using resolution.

John killed Louis or Peter did it. If it was John, then Mary must have seen the killing and she must be shocked. Thus, if Mary is not shocked, Peter must have done it.

Hector Gener, Intro to AI, Kings College, 2014


SAT Solvers
SAT is the problem of determining whether a set of clauses is satisable, and if so, determining a satisfying valuation. Many problems can be mapped into SAT such as Planning, Scheduling, CSPs, Verication problems etc. SAT is an intractable problem (exponential in the worst case unless P=NP) yet very large SAT problems can be solved in practice Best SAT (DPLL) algorithms not based on either pure case analysis (model theory) or resolution (proof theory), but a combination of both Currently very large SAT problems can be solved in this way SAT engines used for formally verifying designs in industry

Hector Gener, Intro to AI, Kings College, 2014


DPLL Procedure for SAT

DPLL is sound and complete proof procedure for SAT DPLL uses resolution but in restricted form called unit resolution in which one parent clause is unit clause Unit resolution is very ecient (linear) but not complete (Example: q p, q p, q p, q p) When Unit Resolution gets stuck, DPLL picks undetermined variable, and splits the problem in two: one where the variable must be true; the other where it must be false DPLL(clauses) Unit-resolution(clauses) if Empty Clause in Clauses, Return False else if all Variables are determined in Clauses, Return True else pick Non-determined Variable VAR, and Return DPLL(clauses + VAR) OR DPLL(clauses + NEG VAR)
Hector Gener, Intro to AI, Kings College, 2014 22

Constraint Satisfaction Problems (CSPs)

CSPs provide generalization of SAT In CSPs, the (main) task is to nd an assignment to a set of variables that satises a set of constraints However, variables do not need to be boolean (true, false), and constraints do not have to be clauses. Other nite domains and constraints accommodated. Examples: Sudoku, N-Queens, Magic Square, Graph Coloring, ... All these problems can be mapped into SAT, although often convenient to use methods that are similar to DPLL in richer CSP context Indeed, it is not easy to express some constraints as clauses (e.g., that sum of rows, columns, and main diagonals must be equal in Magic-Square, etc).

Hector Gener, Intro to AI, Kings College, 2014


Exercises: Propositional Logic and SAT

Scenario: Peter or Tom may show up at work. If both are in, the light is green. If one of them is in, the light is yellow. If none is in, the light is red. Model the scenario in propositional logic and show that: If the light is red, Peter is not in If the light is yellow and Peter is not in, then Tom is in. Show this: Semantically, by showing that conclusion is true in valuations that satisfy the premises Proof-theoretically by resolution, by reducing premises and negation of conclusion to clauses, and deriving 2 Computationally, by executing DPLL over such clauses Do the same with the pizza problem above: state the premises, conclusion, etc.

Hector Gener, Intro to AI, Kings College, 2014