introduction to Genifer -- Deduction
-
Upload
yan-yin -
Category
Technology
-
view
330 -
download
3
Transcript of introduction to Genifer -- Deduction
![Page 1: introduction to Genifer -- Deduction](https://reader033.fdocuments.in/reader033/viewer/2022051318/5a66e1137f8b9a91298b460b/html5/thumbnails/1.jpg)
1
Introduction to Genifer– deduction
source code: deduction.lisp
![Page 2: introduction to Genifer -- Deduction](https://reader033.fdocuments.in/reader033/viewer/2022051318/5a66e1137f8b9a91298b460b/html5/thumbnails/2.jpg)
2
w h a t i sf i r s t - o r d e r l o g i c ?
![Page 3: introduction to Genifer -- Deduction](https://reader033.fdocuments.in/reader033/viewer/2022051318/5a66e1137f8b9a91298b460b/html5/thumbnails/3.jpg)
3
“ J o h n l o v e s M a r y .”
l o v e s ( j o h n , m a r y )
t h i s i s a p r o p o s i t i o na l s o c a l l e d a f o r m u l a , o r s e n t e n c e
![Page 4: introduction to Genifer -- Deduction](https://reader033.fdocuments.in/reader033/viewer/2022051318/5a66e1137f8b9a91298b460b/html5/thumbnails/4.jpg)
4
“ J o h n l o v e s M a r y .”
l o v e s ( j o h n , m a r y )
t h i s i s ap r e d i c a t e t h e s e a r e
a r g u m e n t s
![Page 5: introduction to Genifer -- Deduction](https://reader033.fdocuments.in/reader033/viewer/2022051318/5a66e1137f8b9a91298b460b/html5/thumbnails/5.jpg)
5
“ X l o v e s Y .”
l o v e s ( X , Y )
a r g u m e n t s c a n b ev a r i a b l e s
In my Lisp code variables are denoted by ?1, ?2, … etc
![Page 6: introduction to Genifer -- Deduction](https://reader033.fdocuments.in/reader033/viewer/2022051318/5a66e1137f8b9a91298b460b/html5/thumbnails/6.jpg)
6
First order logic has the following connectives and operators:/\ (AND)\/ (OR)┐ (NOT)→ (IMPLY)↔ (EQUIVALENCE)
For example A → B is equivalent to (┐A \/ B) and its truth table is:A B A→BT T TT F FF T TF F T
( I assume you still remember this stuff... )
![Page 7: introduction to Genifer -- Deduction](https://reader033.fdocuments.in/reader033/viewer/2022051318/5a66e1137f8b9a91298b460b/html5/thumbnails/7.jpg)
7
Horn form
If a bunch of formulae can be written as:A ← B /\ C /\ D /\ …B ← E /\ F /\ G /\ ...
and if A is the goal we want to solve:A
then we can cross out A and replace it withA, B, C, D, …
as the new sub-goals and repeat the process:B, C, D, ..., E, F, G, …
This makes solving the goals very efficient (similar to production systems in the old days).
Formulae written in this form is called the Horn formand is the basis of the language Prolog.
Genifer's logic is also based on Horn.
![Page 8: introduction to Genifer -- Deduction](https://reader033.fdocuments.in/reader033/viewer/2022051318/5a66e1137f8b9a91298b460b/html5/thumbnails/8.jpg)
8
* Optional:
Some first-order formulae cannot be expressed in Horn form.If we want to prove theorems in full first-order logic, we need touse a more general algorithm such as resolution.
The general procedure is:
1. convert all the formulae into CNF (conjunctive normal form)2. eliminate all existential quantifiers ∃ by a process called
Skolemization (see next slide)3. repeatedly apply the resolution rule to formulae in the KB,
until nothing more changes
If we restrict resolution to Horn formulae we get SLD-resolutionwhich is very fast and is the search procedure in Prolog.
I think Horn is expressive enough for making a first AGI prototype.
![Page 9: introduction to Genifer -- Deduction](https://reader033.fdocuments.in/reader033/viewer/2022051318/5a66e1137f8b9a91298b460b/html5/thumbnails/9.jpg)
9
First order logic has 2 quantifiers:
Universal: ∀X liar(X)≡ for all X, X is a liar ≡ “Everyone is a liar”.
Existential: ∃X brother(john, X)≡ exists X such that X is John's brother
The existential quantifier can be eliminated by Skolemization:∃X brother(john, X) “Exists X such that X is John's bro”≡ brother(john, f(john))
where f() is called a Skolem function. Its purpose is to map X to X's brother.
With existential quantifiers eliminated, we can assume all variables are implicitly universally quantified, and omit the ∀'s.
![Page 10: introduction to Genifer -- Deduction](https://reader033.fdocuments.in/reader033/viewer/2022051318/5a66e1137f8b9a91298b460b/html5/thumbnails/10.jpg)
10
When we have a goal to prove...
goal G
KB
knowledge base
We try to fetch facts and rulesfrom the KB to satisfy the goal.
eg: bachelor(john) ?
(defined in memory.lisp)
![Page 11: introduction to Genifer -- Deduction](https://reader033.fdocuments.in/reader033/viewer/2022051318/5a66e1137f8b9a91298b460b/html5/thumbnails/11.jpg)
11
Deduction can start from the goal to the facts. This is known as backward chaining.
goal
each goal has a bunch of rulesthat may apply to itrule1 rule2 rule3
each rule can be a conjunction(/\) of arguments;
arguments are just other goals
A B
G
. . . .
rules and goals alternative down theproof tree
rules
goals
rules
goals
The red link indicates a conjunction (“AND”) that requires all its arguments; The black links represent “OR” (ie, the goal G can be solved by applying either rule1, rule2, rule3, ... etc.
![Page 12: introduction to Genifer -- Deduction](https://reader033.fdocuments.in/reader033/viewer/2022051318/5a66e1137f8b9a91298b460b/html5/thumbnails/12.jpg)
12
rule1 rule2 rule3
A B
G
. . . .
1
5 3 2
4 6
. . . .1 2 3
The simplest search is depth-first search but it may not be flexible enough. I think best-first search may be better, which uses a priority queue to rank the nodes.
Each element in the priority queuepoints to a tree node.
priorityqueue
![Page 13: introduction to Genifer -- Deduction](https://reader033.fdocuments.in/reader033/viewer/2022051318/5a66e1137f8b9a91298b460b/html5/thumbnails/13.jpg)
13
rule1 rule2 rule3
A B
G
. . . .
fact1 rule1fact2 fact3
A goal / sub-goal can be satisfied by either facts or rules.
example of a fact:bachelor(john)
example of a rule:bachelor(?1) ← male(?1) /\ single(?1)
this is a variable A B
![Page 14: introduction to Genifer -- Deduction](https://reader033.fdocuments.in/reader033/viewer/2022051318/5a66e1137f8b9a91298b460b/html5/thumbnails/14.jpg)
14
rule
Q R
P
. . . .
fact fact
bachelor(?1)
bachelor(john)
To satisfy a goal, some variable substitutions occur.
We need to make these 2 termsidentical; this is done by analgorithm known as unification.
The result of unification isa set of substitutions,for example: {?1/john, ...}
![Page 15: introduction to Genifer -- Deduction](https://reader033.fdocuments.in/reader033/viewer/2022051318/5a66e1137f8b9a91298b460b/html5/thumbnails/15.jpg)
15
rule
P
fact fact
bachelor(?1)
bachelor(john) bachelor(pete)
. . . .
A successful matching results in a new set of substitutions. Over time, a goal node can acquire multiple sets of substitutions.
{?1/john}{?1/pete}{?1/paul} … etc
these are 3substitution
sets
stored in the node
Managing these set of substitutions can be a great source of complexity,as the next few slides illustrate...
![Page 16: introduction to Genifer -- Deduction](https://reader033.fdocuments.in/reader033/viewer/2022051318/5a66e1137f8b9a91298b460b/html5/thumbnails/16.jpg)
16
Each substitution set is associated with a truth value (TV).
{?1/john}
{?1/pete}
{?1/paul}
… etc
TV1
TV2
TV3
...
![Page 17: introduction to Genifer -- Deduction](https://reader033.fdocuments.in/reader033/viewer/2022051318/5a66e1137f8b9a91298b460b/html5/thumbnails/17.jpg)
17
rule
Q R
P
fact fact
{?1/john}{?1/pete}{?1/paul} … etc
{?1/mary}{?1/paul}{?1/john} … etc
male(john),male(pete),male(paul), … etc
single(mary),single(paul),single(john), … etc
male(?1) single(?1)
bachelor(?1) ← male(?1) /\ single(?1)
facts from KBthat matchesthe sub-goals
These 2 blocks ofsubstitution-setsmust be mergedto give the resultto the parent node.
When handling substitution setsof a conjunction /\ ...
![Page 18: introduction to Genifer -- Deduction](https://reader033.fdocuments.in/reader033/viewer/2022051318/5a66e1137f8b9a91298b460b/html5/thumbnails/18.jpg)
18
rule
Q R
{?1/john}{?1/pete}{?1/paul} … etc
{?1/mary}{?1/paul}{?1/john} … etc
Each set on the left block has to bematched with each set of the right block.
for example: {?1 / john} {?1 / mary} fail {?1 / john} {?1 / john} match
Because the variable ?1can only take on one valueon each instance.
![Page 19: introduction to Genifer -- Deduction](https://reader033.fdocuments.in/reader033/viewer/2022051318/5a66e1137f8b9a91298b460b/html5/thumbnails/19.jpg)
19
{?1/john}{?1/pete}{?1/paul} … etc
{?1/mary}{?1/paul}{?1/john} … etc
The merging of substitution-sets is handled in the function propagate. Instead of trying all possible combinations between 2 blocks, we try to do the matching when a new substitution-set arrives. When we get a new set, say {?1 / john}, we try to merge it with each set in the other existing blocks:
{?1 / mary }{?1 / sam } {?1 / paul } {?1 / john } .... etc
A B
{?1/sam}
new resultfrom unification
![Page 20: introduction to Genifer -- Deduction](https://reader033.fdocuments.in/reader033/viewer/2022051318/5a66e1137f8b9a91298b460b/html5/thumbnails/20.jpg)
20
{?1/john}{?1/pete}{?1/paul} … etc
{?1/mary}{?1/paul}{?1/john} … etc
rule
Q R
Substitution-sets propagate upwardsalong the proof tree.
....
....
....
parent's block ofsubstitution sets
This part of the Lispcode may still needdeveloping.
![Page 21: introduction to Genifer -- Deduction](https://reader033.fdocuments.in/reader033/viewer/2022051318/5a66e1137f8b9a91298b460b/html5/thumbnails/21.jpg)
21
The Lisp code contains these functions:
backward-chain main function,manages the priority queue
process-subgoalprocess-fact builds up the proof tree during searchprocess-rule
retract deletes a dead proof tree node
propagate propagates TVs up the proof tree
TO-DO:* some comments are excessive