This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: F1: spechach1,ibmpc,320). F2: spechach2,mac,iGOO}. F3: spec£mach3,ibmpc,640). F4: runs(ibmpc,spreadsheet,500). F5: runs(ibmpc,basic,128). F6: runs(ibmpc,pascal,256). F?: runs(mac,basic,200). F8: runs(mac,smalltalk,1000). F9: access(sue,machi). F10: access€jerry,mach3). F11: accessCsam,machi). F12: access(sam,mach2) . F13: written_in(spreadsheet,pascal). R1: can_use{P,SH) :* access(P,M),
can_run(H,SH). R2: can_run(M,SW) :— spec(H,HW,Memi), ' runs(HW,Sw,Mem2),
Hem1>=hem2. RB: can_run{M,SW) : written_in(SlJ,L),can_runG'I,L). “Hemmer... .. If we run the corresponding program with the goal
?—can_use(X, spreadsheet) . we wiil obtain the following output: ﬂ sue = jerry = jerrv
= 53.112 NNNN Notice that jerry is derived twice, indicating that the program is doing
some unnecessary work. Let's see why this happened. The object jerry
will satisfy canwuse once because jerry has access to machS, which can
run a spreadsheet directly. But the goal can also be derived from the
second rule for caLrun since Pascal can run on means as well and the
spreadsheet is written in Pascal. The cat is considered to be a subgoal that is universally satisﬁed but
that cannot be backed up over. it then stands as a oneway gate for the
subgoai generation process, which, once passed, cannot be backed through. In the previous example, the first rule for oaLrun could be rewritten
with the cut as follows: oan..run(MACH,Si‘i) :w specCMACI—I,HW,MEMl).
runs{HW,SW,MEM2), MEMl >= THEEME,
! . The Cut is signiﬁed by an exclamation point {! }. After the first three subgoals are satisfied, the cut is then satisfied as
well, cornpleting the derivation of can_run. After the entire derivation is
completed, the cut then prevents the backing up process from trying other
alternatives for canmrun. Thus unnecessary checking is avoided, since it
is irrelevant how many ways a computer caLrun a software product. Now the goal
?»—can,_use(X, spreadsheet). wiil ﬁnd only one derivation for each of the three people. and the deriu
vation process is displayed in Figure 11.9. The derivation process, when
backing up to a cut, will automatically produce a failure for all subgoals FIGURE l 1.9 Derivation of a goal in Prolog using cut
amm_______i________l___aH___________HymwMM____~_____H+_________ngwm_____ gdfu'mttx'm'mgpvﬂpilmthlmquhgnplplfhégopoﬁpigngmfu{chimmmMJQCN.bmmumtomqmcndam.ammwnsmmw—a ?—written_in{spreadsheef,L),can_run(machl,L). ?—can_use(X,spreadsheet}.
?—access(K,M),can_run{M,spreadsheet).
?—canirun(machl,spreadsheet].
?—spec(machl,HW,Ml),runs(HW,spreadsheet,M2),Ml>=M2,l.
?—runs(ibmpc,spreadsheet,M2),520>=M2,l. ?—320>:500,!. ?—runs(ibmpc,spreadsheet,m2),520>=M2,i.
?—spec(machl,HW,Ml),runs(HW,spreadsheet,M2},Ml>=M2,E.
?~can_run(machl,spreadsheet)u
?*written_in(spreadsheet,L),canwrun[machl,L).
?—can.run(machl,pasoal}.
?—spec(machl.Hw,Ml},runs(HW,pascal,M2},Ml>:M2,i.
?mruns{ibmpo,pascal,M2},320>=M2,l. ?—320>2256,!. ?—! Skip backup because of cut ﬁ 5. completed
?—written_in(spreadsheet,L),canmrunﬁmachle)
?«can_run(machl,spreadsheet).
?—access{X,M),can_run(M,spreadsheet}.
?—can“run(mach3,spreadsheet).
?—spec(mach3,HW,Ml),runs(HW,spreadsheet,M2),Ml>=M2,E.
?—runs(ibmpc,spreadsheet,M2),640>=M2,E. ?~G4U>=500,!_ ?w! Skip backup because of cut — 3. completed
?«access(X,M),canmrun{M,spreadsheet).
?—can_run(machl,spreadsheet).
?—spec{machl,Hw,Ml),runs[HW,spreadsheet,M2),Ml>=M2,!.
?—runs{ibmpc.spreaésheet,M2),320>=M2,E. ?—320>=500,I. ?—runs{ibmpo,spreadsheet,M2j,320>=M2,i.
?—spec(machl,HW,Ml),runs(HW,spreadSheei,M2),Ml>=M2,i.
?~canurun(machl,spreadsheet).
?—written_in(spreadsheet,L),canHrun{machl,L)_
?—can_run{machl,pa50al}.
?—spec(machl,HW,Ml),runs{HW,pascal,M2),Ml>:M2,l.
?eruns(ibmpc,pascal,M2),320>=M2,E.
?—320>=256,1. ?—1 Skip backup because of out — 5. completed ?—can,run(machl,spreadsheet).
?—access{X,M),can_run(M,spreadsheet). ?—can_run(mach2,spreadsheet).
?—spec(mach2,HW,Ml),runs(HW,spreadsheet,M2),Ml>:M2,i. ?~runs(mao,spreadsheet,M2),1000>=M2,!.
?~spec(mach2,HW,Ml},runs(HW,spreadsheet,M2),Ml>=M2,i.
?—can_run(mach2,spreadsheet).
?—written_in(spreadsheet,L),can_run(mach2,L).
?—can_run(mach2,pascal}.
?~spec(mach2,Hw,Ml},runs(Hw,pascal,M2},Ml>=M2,1.
?—runs(mac.pascal,M2),M1>=M2,!_
?—spec(mach2,HW,Ml},runs(HW,pascal,M2},Ml>=M2.!.
?«can_run{mach2{pasca1}.
?wwritten_in(pascal,L),can_run(mach2,L). ?~can_run{mach2,pasca2}.
?«writtenmin(spreadsheet,L),can_run(mach2,L). ?—can_run{mach2,spreadsheet}.
?—access(X,M},can_run(M,spreadsheet).
?—can_use(X,spreadsheet}. Rl/SW:=Spreadsheet.
F9/M:=machl,X:=sue
R2
Fl/HW:=ibmpc,Ml::520 F4/M222500 Fails Fails Fails R3 Flﬁ/L:=pascal R2
Fl/HW::ibmpc,Ml:=52O
F6/M2:=256
satisfied
satisfied X=sue
Fails Fails FlO/X:=jerry,M:=mach3
R2
FS/Ml::640,HW=ibmpc
F4/M2:=500 satisfied satisfied X=jerry
Fll/X::sam,M:=machl
R2
F1/HW:=ibmpc,Ml::320 Fé/M2::500 Fails Fails Fails R3 FlS/L::pascal R2
Fl/HW22ibmpc,Ml:=320
F6/M2:=256 satisfied saiisfied X=sam
Fails Fails
Flz/X:=sam,M:=mach2
R2 .
F2/HW:zmac,Mlz=lOGO
Fails Fails R5 FlS/L:=pasca1 82
F2/HW:=mac,Ml:=lOOO
Fails Fails RS Fails Faiis Fails Fails Fails Fails ...
View
Full Document
 Spring '11
 Soliman

Click to edit the document details