Download presentation
Presentation is loading. Please wait.
1
Supplemental slides for CSE 327 Prof. Jeff Heflin
Ch. 9 – FOL Inference Supplemental slides for CSE 327 Prof. Jeff Heflin
2
EBNF Grammar for Prolog
<program> <clause> { <clause> } <clause> <fact> | <rule> <fact> <compound> . <compound> <atom> ( <termlist> ) <rule> <head> :- <body> . <head> <compound> <body> <compound> { , <compound> } <termlist> <term> { , <term> } <term> <atom> | <num> | <var> | … Notes: { <a> } means 0, 1 or more <a>’s This grammar is slightly more restrictive than the actual language
3
Backward Chaining function FOL-BC-Ask (KB, goals, ) returns a set of substitutions local answers, a set of substitutions, initially empty if goals is empty then return { } q’ Subst( ,First(goals)) for each sentence r in KB where Standardize-Apart(r) = (p1 … pn q) and ’ Unify(q,q’) succeeds new_goals Prepend([p1,…,pn], Rest(goals)) answers FOL-BC-Ask(KB, new_goals, Compose(’, )) answers return answers Alternative description of Figure 9.6, p. 338
4
Backward Chaining Example
Set of sentences: S1: x1,y1 child(x1,y1) parent(y1,x1) S2: x2,y2 parent(x2,y2) female(x2) mother(x2,y2) S3: child(Lisa,Homer) S4: child(Lisa,Marge) S5: female(Marge) Note: variables have already been standardized apart using subscripts Query: x mother(x,Lisa)
5
Backward Chaining Search Tree
mother(x0,Lisa) match rule S2 ’={x2/x0, y2/Lisa} parent(x0,Lisa), female(x0) match rule S1 ’={y1/x0, x1/Lisa} child(Lisa,x0), female(x0) match S4 ’={x0/Marge} match S3 ’={x0/Homer} female(Homer) female(Marge) matches S5 ’={ x0/Marge} no matches answers={} (FAIL!) answers= { x0/Marge}
6
Forward Chaining function FOL-FC-Ask (KB,) returns a substitution or false local new, the new sentences inferred on each iteration repeat until new is empty new {} for each sentence r in KB do (p1 … pn q ) Standardize-Apart (r) for each such that Subst( , p1 … pn)= Subst( , p1’ … pn’) for some p1’ ,…, pn’ in KB q’ Subst( ,q) if q’ does not unify with some sentence already in KB or new then do add q’ to new Unify(q’, ) if is not fail then return add new to KB return answers From Figure 9.3, p. 332
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.