prolog[1] - Logic Programming Systems CPS 170 Ron...

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: Logic Programming Systems CPS 170 Ron Parr Automa8ng Reasoning •  Want a sound and complete procedure •  Need to represent informa8on in our database in a canonical form •  Need to understand the factors that influence the efficiency of our reasoning system 1 Proofs by Resolu8on •  Convert to canonical form •  Assert nega8on of the proof target •  Resolve un8l “nil” is obtained •  Problem: In general, we can’t bound the number of steps of resolu8on needed. (In some cases, we can make assump8ons about a restricted number of objects in the universe, but then we go from semi ­decidable to exponen8al, s8ll unpleasant.) Speeding Up Resolu8on •  There are many heuris8cs for speeding up resolu8on – we can view it as a special kind of search •  Can also consider special cases •  AI has a colorful history of special case logics and special case reasoning engines for handling these logics 2 Implementa8on Issues •  Any reasoning system must be able to iden8fy relevant sentences in its KB rapidly •  Maintain mul8ple indices: –  –  –  –  A list of posi8ve literals for each predicate symbol A list of nega8ve literals for each predicate symbol A list of sentences with this predicate as conclusion A list of sentences with this predicate as premise •  More sophis8cated, tree ­based indexing schemes are possible Unifica8on •  We need to avoid circular unifica8ons •  Consider Unify(P(x,f(x)),P(y,y))=??? •  What happens: –  Bind x to y –  Bind f(x) to y –  This implies x is bound f(x) –  This is circular •  Checking called an “occurs check” •  O(n2) to check this (many systems don’t) 3 Prolog •  Prolog is a grand effort to make logic a prac8cal programming method •  Prolog is a declara've language –  State the things that are true –  Ask the system to prove things –  All computa8ons are essen8ally proofs •  Prolog makes many restric8ons on KB •  My bias: Prolog is a fascina8ng way to think about logic and programming, but is of waning importance in AI Prolog Proper8es •  KB is sequences of sentences (all implicitly conjoined) •  All sentences must be horn •  Can use constants, variables, or func8ons •  Queries can include conjunc8ons or disjunc8ons •  Cannot assert nega8ons –  Closed world assump8on –  Everything not implied by the KB is assumed false 4 Prolog Proper8es •  All syntac8cally dis8nct terms refer to dis8nct objects –  Two variables can be = –  Two objects cannot be = •  Built in predicates for arithme8c •  Build in list handling as part of the unifica8on process Prolog Implementa8on •  Inferences are done with backward chaining •  Is this complete? •  What is the computa8onal complexity? •  Conjuncts are tried in leb to right order (as entered in the KB) •  Tries implica8ons in order they are entered •  No occurs check (in most Prologs) 5 Prolog UI •  Load a database using consult •  Consult(user) loads database from the command line ctrl ­d to terminal •  Consult(file) loads database from a file. •  Some prologs use [file]. Prolog Syntax •  Variables are upper case •  Constants are lower case •  Implica8on : ­ •  Universal quan8fica8on is implicit •  Sentences are terminated with a . •  Specify RHS first: Mortal(X): ­Man(X) •  Conjunc8on with ,: Mortal(X): ­Man(X),Living(X). 6 Prolog Syntax •  Lists [Head|Tail] –  Head is bound to first element of list –  Tail is bound to remainder of list –  Append •  Numbers –  Numbers are assigned with “is” –  Checked with =, =<, => Prolog Bindings •  Use = to check if two bindings are same •  Use \== to check if they are different •  Hit enter at the end of query to stop search •  Use ; to get mul8ple answers 7 Weird/Interes8ng Stuff About Prolog •  Purely declara8ve (or purely func8onal) framework for programming leaves linle room for “side effects” such as graphics, file output, etc. •  but… Prolog has lots of back doors that let you step outside of the purely declara8ve framework •  Prolog is Turing Complete •  Prolog programmers must be con8nually aware of the opera8on of the theorem proving engine •  You can easily write prolog programs that go into infinite loops, and it will not be obvious why this is happening un8l you have fully internalized the way the theorem prover works Prolog Redux •  Despite its coolness and poten8al power, prolog is not widely used today –  Horn restric8ons are awkward in prac8ce –  Knowledge representa8on is hard in general –  Programming paradigm is alien to many and awkward for things other than logic queries •  Prolog concepts live on in a restricted form in the database query language datalog: –  Subset of prolog –  Sound and complete –  Efficient implementa8ons exist •  Datalog is used primarily for database research, but datalog concepts have influenced mainstream database implementa8ons 8 ...
View Full Document

Ask a homework question - tutors are online