Sie sind auf Seite 1von 29

First order logic

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

A sentence is a formula with no unquantied variables.

More inference rules for FOL

Universal specialization: Replace variable with individual, so from x : p(x) we can get p(A)

Unication: essentially pattern matching and variable substitution

Formulas involving cats and sh

1. xy : cat(x) sh(y) will-eat(x, y)

2. x : calico(x) cat(x)

3. x : tuna(x) sh(x)

4. tuna(Charlie)

5. calico(Pudge)

Prove that Pudge will eat Charlie!

(more examples of writing FOL sentences)

Extending the logic code


A modest extension of the propositional logic theorem prover can handle variables, predicate functions and universal quantication. examples of predicates (facts, or assertions) (<- (metabolized-by cimetadine cyp3a4)) (<- (inhibited-by loratidine cyp3a4)) Meaning, Cimetadine is metabolized by the enzyme CYP3A4 and Loratidine is inhibited by the enzyme CYP3A4. example of a rule with variables (assumed to be universally quantied) (<- (interacts ?x ?y ?z) (and (metabolized-by ?x ?z) (inhibited-by ?z ?y))) Meaning, Drug x interacts with drug y by enzyme z if x is metabolized by z and z is inhibited by y

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.

The match function


The match function takes two patterns and a set of bindings, and attempts to match them, possibly returning some additional bindings: (defun match (x y &optional binds) (cond ((eql x y) (values binds t)) ((assoc x binds) (match (binding x binds) y binds)) ((assoc y binds) (match x (binding y binds) binds)) ((var? x) (values (cons (cons x y) binds) t)) ((var? y) (values (cons (cons y x) binds) t)) (t (when (and (consp x) (consp y)) (multiple-value-bind (b2 yes) (match (first x) (first y) binds) (and yes (match (rest x) (rest y) b2)))))))

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 match function in action


Successful matches with bindings: > (match (p a b c a) (p ?x ?y c ?x)) ((?Y . B) (?X . A)) T > (match (p ?x b ?y a) (p ?y b c a)) ((?Y . C) (?X . ?Y)) T A match failure > (match (a b c) (a a a)) NIL NIL Not all successful matches generate bindings: > (match (p ?x) (p ?x)) NIL T

Extension of the <- operator

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))))

Additional functions used by prove


The prove-and function requires success on all the clauses and returns all the bindings (or nil): (defun prove-and (clauses binds) (if (null clauses) (list binds) (mapcan #(lambda (b) (prove (first clauses) b)) (prove-and (rest clauses) binds)))) The prove-or function returns the bindings for any that succeed: (defun prove-or (clauses binds) (mapcan #(lambda (c) (prove c binds)) clauses)) The prove-not function is really simple. As in the propositional case, proving A means that there is no proof for A. It does not mean that A is denitely false. (defun prove-not (clause binds) (unless (prove clause binds) (list binds)))

The query interface

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))))

The cat and sh example again


The rules and facts about cats and sh, in computer readable form: (<(<(<(<(<(<(<(will-eat ?x ?y) (and (cat ?x) (fish ?y))) (cat ?x) (calico ?x)) (fish ?x) (tuna ?x)) (tuna charlie)) (tuna herb)) (human ira)) (calico pudge))

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.

What is the signicance of these things for biomedicine?

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?

More unsound inference

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.

What is the signicance of these things for biomedicine?

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)

The same is true of existential quantiers: xy : glass(x) color(x, y) yx : glass(x) color(x, y)

Quantier order, continued

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)

Quantier movement, continued

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.

Eliminate implication symbols (replace with equivalents)

Reduce scope of negations to single atomic formulas.

Standardize variables.

Clauses, continued

Eliminate existential quantiers (use Skolem functions).

Convert to prenex form.

Put the matrix part in conjunctive normal form.

Eliminate universal quantiers.

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)

Das könnte Ihnen auch gefallen