Beruflich Dokumente
Kultur Dokumente
First order logic (FOL) introduces the idea of variables, functions and quantiers. Primitives can be: constant symbols (individuals) function symbols predicate symbols Variables can represent unnamed individuals. Quantiers allow iteration over individuals. There are two basic quantiers, the Universal (for all) and the Existential (there exists): for all there exists
Universal specialization: Replace variable with individual, so from x : p(x) we can get p(A)
2. x : calico(x) cat(x)
3. x : tuna(x) sh(x)
4. tuna(Charlie)
5. calico(Pudge)
Queries
Example use of with-answer macro (from Graham chapter 15): > (with-answer (interacts cimetadine loratidine ?x) (format t "Cimetadine interacts with loratidine by enzyme ~A~%" ?x)) CIMETADINE INTERACTS WITH LORATIDINE BY ENZYME CYP3A4 >
Matching with variables To handle expressions with variables, we need a pattern matcher, that will use unication and specialization. (p ?x ?y c ?x) (p a b c a) matches when ?x = a and ?y = b, and (p ?x b ?y a) (p ?y b c a) matches when ?x = ?y = c. So we need a function called match.
Auxiliary functions for match Here are the other two functions match uses: (defun var? (x) (and (symbolp x) (eql (char (symbol-name x) 0) #\?))) (defun binding (x binds) (let ((b (assoc x binds))) (if b (or (binding (rest b) binds) (rest b)))))
The <- operator needs to handle predicate expressions, not just symbols, in the consequent part. It will use the rst part of the expression as the lookup key. (defmacro <- (con &optional ant) "adds ant to the hash table entry for con, even if nil" (length (push (cons (rest ,con) ,ant) (gethash (first ,con) *rules*))))
Extension of prove-simple
Instead of just a lookup, prove-simple has to use match. If a match is found, the result is the list of bindings that made the match, otherwise as before a call to prove is needed. (defun prove-simple (pred args binds) (mapcan #(lambda (r) (multiple-value-bind (b2 yes) (match args (first r) binds) (when yes (if (rest r) (prove (rest r) b2) (list b2))))) (mapcar #change-vars (gethash pred *rules*))))
Extension of prove
As before, prove handles logical combinations with recursive calls, but here they are elaborated in separate functions, prove-and, etc., and the bindings must be passed through. (defun prove (expr &optional binds) (case (first expr) (and (prove-and (reverse (rest expr)) binds)) (or (prove-or (rest expr) binds)) (not (prove-not (first (rest expr)) binds)) (t (prove-simple (first expr) (rest expr) binds))))
The with-answer macro iterates over all the successful bindings, executing any code you want it to. (defmacro with-answer (query &body body) (let ((binds (gensym))) (dolist (,binds (prove ,query)) (let ,(mapcar #(lambda (v) (,v (binding ,v ,binds))) (vars-in query)) ,@body))))
A query could be to ask what Pudge will eat. This should give two answers, Herb and Charlie. > (with-answer (will-eat pudge ?x) (format t "Pudge will eat ~A.~%" ?x)) Pudge will eat HERB. Pudge will eat CHARLIE. NIL
Completeness
Propositional logic is complete: if a set of formulas S entails another formula R, then a proof of R exists.
Further, propositional logic is decidable: a procedure exist that can determine for any formula whether or not it is provable from a given set of formulas.
The procedure may be costly - for propositional logic the problem is NP-Complete.
Unsound inference
From P and P Q we can infer Q. What about the other way around? From Q and P Q can we infer P ? This is known as abduction, or abductive reasoning. Where in biology, medicine or public health might this apply?
From P and P Q we can infer Q. What about inferring the P Q relation when we observe both P and Q? This is known as induction, or sometimes in a more general form, machine learning. Where in biology, medicine or public health might this apply?
Completeness of FOL
FOL is complete: if a set of sentences S entails another sentence R, then a proof of R exists.
For a given set of axioms, a procedure exists that can nd a proof if it exists. However, no automated procedure (reasoner) can exist that is guaranteed to terminate if the proof does not exist, so FOL is undecidable.
Arithmetic is worse. Any system as complex as arithmetic is guaranteed to have a proposition that is entailed by the system (i.e., true) but for which a proof cannot exist.
Some quotes
The grand aim of science is to cover the greatest number of experimental facts by logical deduction from the smallest number of hypotheses or axioms. - Albert Einstein
There is something fascinating about science. One gets such wholesale returns of conjecture out of such a triing investment of fact. - Mark Twain, Life on the Mississippi, 1874
Using Resolution
With suitable control strategies, resolution is refutation complete, i.e., if a sentence is provable, a proof can be generated. Using resolution requires that we transform all the formulas (sentences) into a collection of disjunctions, called clauses. This can be done with any set of sentences in FOL. However, we will need some additional equivalence laws.
Quantier order
Changing order of universal quantiers does not change the meaning of a sentence: xy : likes(x, y) buys-present(x, y) yx : likes(x, y) buys-present(x, y)
Changing order of a universal with an existential does change the meaning: xy : likes(x, y) yx : likes(x, y)
and similarly within rules: xy : glass(x) box(y) inside(x, y) yx : glass(x) box(y) inside(x, y)
Quantier movement
You can generally move quantiers to the left of a formula: x : rock(x) y : as-heavy-as(x, y) xy : rock(x) as-heavy-as(x, y) x : glass(x) y : box(y) inside(x, y) xy : glass(x) box(y) inside(x, y)
But you can not move quantiers past a negation: x : rock(x) y : heavier-than(y, x) xy : rock(x) heavier-than(y, x)
The solution - move the negations to the atoms, changing any quantiers they pass: x : rock(x) y : heavier-than(y, x) x : rock(x) y : heavier-than(y, x) xy : rock(x) heavier-than(y, x)
Clauses
A clause is a formula with a nite set of literals joined by disjunction (or). P Q R S W To get a set of formulas into Conjunctive normal form we convert each of them to clauses joined by and operators.
Standardize variables.
Clauses, continued
Eliminate conjunctions.
Rename variables.
Horn clauses As in propositional logic, in FOL a Horn clause is a clause in which there is at most one positive term. gram-pos(y) round(y) chains(y) streptococcus(y) It corresponds to an implication formula in which there is a conjunction on the left side and a single term on the right side. gram-pos(y) round(y) chains(y) streptococcus(y)