Artificial Intelligence CIS 342 The College of Saint Rose David Goldschmidt, Ph.D.
Von Neumann Architecture
Imperative Languages Based directly on the von Neumann architecture – Variables have memory locations – Program flow of control is: sequential condition-based repeatable (e.g. loops) based on functions based on objects
Imperative Languages Based directly on the von Neumann architecture – Efficiency is the primary concern – Management of variables and data structures is a constant concern – Causes program complexity and therefore bugs
Logic Programming – Prolog Based on formal logic – Prolog is a goal-driven logic programming language – Prolog is a declarative language No flow of control....? – Apply known rules to facts to infer answers to queries Think of Prolog as an inference engine
Propositions A proposition is a logical statement that may or may not be true male('George'). female('Mary'). smart('Mary'). tall('George'). smart('George').
Propositions A proposition describes objects and their relationships – e.g. Mary is a parent of George – e.g. George is a child of Mary parent('Mary', 'George'). child('George', 'Mary').
Propositions A proposition is stated in one of two ways: – Fact : proposition assumed to be true – Query : truth of proposition is to be determined Facts are often organized into a knowledge base – Knowledge bases are utilized to answer queries – New knowledge is inferred via an inference engine
Symbolic Logic We utilize Symbolic logic to: – Express propositions – Express relationships between propositions – Describe how new propositions can be inferred from other propositions Particular form of symbolic logic used for logic programming is called first-order predicate calculus – Forms the basis for logic programming languages
Logical Operators NameSymbolExampleMeaning negation a not a conjunction a b a and b disjunction a b a or b equivalence a b a is equivalent to b implication a b a b a implies b b implies a
Quantifiers X.(woman(X) human(X)) Y.(mother('Mary', Y) male(Y)) Z.(smarter(Z, 'Dr.G')) NameExampleMeaning universal X.P For all X, P is true existential X.P There exists a value of X such that P is true e.g.
Simplifying the Predicate Calculus To simplify a Prolog implementation, standardize propositions using the following clausal form : B 1 B 2 … B n A 1 A 2 … A m The A terms represent the antecedent The B terms represent the consequent If all A s are true, then at least one B is true All propositions can be expressed using this clausal form
Simplifying the Predicate Calculus Simplify further using a Horn clause – Headless Horn clause : has no consequent parent('Mary', 'George'). child('George', 'Mary'). state facts
Simplifying the Predicate Calculus Simplify further using a Horn clause – Headed Horn clause : has a single proposition as consequent mother(X, Y) parent(X, Y) female(X) mother(X, Y) :- parent(X, Y), female(X). state inference rules
Additional Prolog Syntax In Prolog, the, operator denotes conjunction ( AND ) The ; operator denotes disjunction ( OR ) mother(X,Y) :- parent(X,Y), female(X). sibling(X,Y) :- brother(X,Y); sister(X,Y).
Additional Prolog Syntax Operators in Prolog – Equality is denoted using == operator – Inequality is denoted using \= operator same(X,Y) :- X == Y. mother(X,Y) :- parent(X,Y), female(X), X \= Y.
Additional Prolog Syntax Parentheses can be used to group logic together X is a sibling of Y if – X is a brother of Y or X is a sister of Y and – X is not the same entity as Y sibling(X,Y) :- (brother(X,Y); sister(X,Y)), X \= Y.
Prolog Family Tree Example Given only male(), female(), and parent(), write Prolog inference rules for the following: – mother() – father() – grandparent() – uncle() – aunt() – brother() – sister() assume that parent(X,Y) is read “ X is a parent of Y ” – cousin() – descendant()
Using SWI-Prolog SWI-Prolog is a free Prolog environment: Interactive Prolog interface
Handling Multiple Subgoals Prolog implementations use depth-first search ( dfs ) approach to finding a goal consisting of multiple subgoals – Backtracking as necessary.... Another approach is to use a breadth-first search ( bfs ), but dfs is usually preferred – to consume fewer resources—i.e. memory female(X), parent(X, 'Bob').
Atoms and Variables Atoms consist of symbols – Start with a lowercase letter Variables also consist of symbols – Start with an uppercase letter – An anonymous variable is the underscore character ( _ ) Use single quotes to create an atom that starts with a capital letter b dave next_solution X Y List1 P2 'Dave' 'Apple' 'Next'
Numbers and Arithmetic Numbers in Prolog include integers and reals – Prolog is not typically used for numeric computation – Predefined operators: – Prolog supports arithmetic evaluation via the is operator = + - * / mod X is X = order matters! distance(X,Y) :- speed_mph(X,Speed), time_minutes(X,Time), Y is Speed * Time / 60.
Using Arithmetic Expressions speed_mph(ford,100). speed_mph(chevy,105). speed_mph(dodge,95). speed_mph(volvo,80). time_minutes(ford,20). time_minutes(chevy,21). time_minutes(dodge,24). time_minutes(volvo,24). distance(X,Y) :- speed_mph(X,Speed), time_minutes(X,Time), Y is Speed * Time / 60. distance(ford,D)D = 2000distance(volvo,D)D = 1920
List Processing in Prolog Prolog supports list structures by using square brackets and commas: Prolog also supports list dismantling : [apple, prune, orange, grape] [ Head_of_List | Rest_of_List ] “dismantles” a list