56'7(41+8 3412)%'()#%+#,+01#.1'2* "#$%&'()#%*+#,+-#.)/+01#.1'22)%. 3412)%'()#%+#,+01#.1'2* !
:$(;)%4 -4<4;+2'77)%.* =4%41';;>+(412)%'()%.+71#.1'2*?+@4/$114%(+71#.1'2* -4,(+(412)%'()%.+71#.1'2*?+A//47('B;4+71#.1'2* "#$%&'()#%*+#,+-#.)/+01#.1'22)%. 3412)%'()#%+#,+01#.1'2* 9
D#4*+(6)*+01#.1'2+3412)%'(4E wine(riesling, chicken). wine(riesling, veal). wine(kerner, veal). diff(riesling, kerner). diff(kerner, riesling). interchangeable(X, Y) :- wine(X, Z), wine(Y, Z), diff(X, Y). "#$%&'()#%*+#,+-#.)/+01#.1'22)%. 3412)%'()#%+#,+01#.1'2* C
D#+(64*4+(G#+3412)%'(4E edge(a, b). edge(b, c). edge(d, e). path(X, Y) :- edge(X, Y). path(X, Y) :- edge(X, Z), path(Z, Y). arc(a, b). arc(b, c). arc(d, e). connected(X, Y) :- arc(X, Y). connected(X, Y) :- connected(X, Z), arc(Z, Y). "#$%&'()#%*+#,+-#.)/+01#.1'22)%. 3412)%'()#%+#,+01#.1'2* F
A%&+(6)*+#%4E edge(a, b). edge(b, c). edge(d, e). edge(c, a). path(X, Y) :- edge(X, Y). path(X, Y) :- edge(X, Z), path(Z, Y). "#$%&'()#%*+#,+-#.)/+01#.1'22)%. 3412)%'()#%+#,+01#.1'2* H
J6'(+AB#$(+(6)*+#%4E edge(a, b). edge(b, c). edge(d, e). edge(c, a). dpath(X, Y, _) :- edge(X, Y). dpath(X, Y, Depth) :- Depth > 0, edge(X, Z), Depth1 is Depth – 1, dpath(Z, Y, Depth1). path(X, Y) :- dpath(X, Y, 10). "#$%&'()#%*+#,+-#.)/+01#.1'22)%. 3412)%'()#%+#,+01#.1'2* I
A+D),,)/$;(+#%4+LLL jump(1). jump(N) :- N > 1, N mod 2 =:= 1, N1 is 3*N + 1, jump(N1). jump(N) :- N > 1, N mod 2 =:= 0, N1 is N // 2, jump(N1). "#$%&'()#%*+#,+-#.)/+01#.1'22)%. 3412)%'()#%+#,+01#.1'2* K
3412)%'()#%+M'>+D474%&+#%+(64+N$41> app([], X, X). app([X|Y], Z, [X|U]) :- app(Y, Z, U). 364+O$41> app([a,b], Y, Z) (412)%'(4*L 364+O$41> app(X, Y, [c,d]) (412)%'(4*L 364+O$41> app(X, [e,f], Z) *+%#(+(412)%'(4L P#G+/'%+G4+71#<4+(6'(+/41(')%+71#.1'2*+'%&+O$41)4*+(412)%'(4E "#$%&'()#%*+#,+-#.)/+01#.1'22)%. 3412)%'()#%+#,+01#.1'2* 8
=4%41';+<*L+0@:-:=+3412)%'()#% app([], X, X). app([X|Y], Z, [X|U]) :- app(Y, Z, U). app3(X, Y, Z, U) :- app(X, Y, V), app(V, Z, U). N$41> app3([a], [b], [c], U) 6'*+'%+)%,)%)(4+R-DS&41)<'()#%L P#G4<41T+0@:-:=+(412)%'(4*L "#$%&'()#%*+#,+-#.)/+01#.1'22)%. 3412)%'()#%+#,+01#.1'2* Q
M$;()*4(* 2$;()*4(+VG1)((4%+ !"# V " ! T+LLLT+ " $ WW ? ! $%#1&414&+*4O$4%/4+ " ! T+LLLT+ " $ ! ! +V#%+,)%)(4+2$;()*4(*+#,+%'($1';+%$2B41*W ? ! ! ' % + ! ! + & +),,+ % +X+V & +Y+ !"# V " WW+ + + ,#1+*#24+ " + + " & +'%&+ ' +*$/6+(6'(+ # ! + + " ' L+ ! +Z+ " J4+G1)(4+ ()* V % T+ & W+? ! + " +'%&+ $+, V % T+ & W+? ! + ' L [#(4?+ ! ! +)*+)114,;4\)<4+'%&+'%()*>224(1)/ "#$%&'()#%*+#,+-#.)/+01#.1'22)%. 3412)%'()#%+#,+01#.1'2* !U
M$;()*4(+:1&41)%. (1'%*)()<4+/;#*$14+#,+'+14;'()#%+ - +#%+'+*4(+ " ? ! *2';;4*(+(1'%*)()<4+14;'()#%+#%+ " +(6'(+/#%(')%*+ - 2$;()*4(+#1&41)%.+V ! ! . W+? ! +(1'%*)()<4+/;#*$14+#,+ ! ! 364#142+ILF 364+2$;()*4(+#1&41)%.+ ! ! . +)*+G4;;S,#$%&4&L "#$%&'()#%*+#,+-#.)/+01#.1'22)%. 3412)%'()#%+#,+01#.1'2* !!
3G#+P4;7,$;+:B*41<'()#%* -422'+IL9 A%+)%,)%)(4T+,)%)(4;>+B1'%/6)%.+(144+6'*+'%+)%,)%)(4+B1'%/6L [#(4+ILC A%+)114,;4\)<4T+'%()*>224(1)/+14;'()#%+)*+G4;;S,#$%&4&+),,+)(*+(1'%*)()<4+/;#*$14+)*+ G4;;S,#$%&4&L 36$*+,)%)(4%4**+#,+'%+R-DS(144+V64%/4T+(412)%'()#%W+/'%+B4+71#<4&+B>+,)%&)%.+'+ *$)('B;4+2$;()*4(+'**).%24%(+,#1+O$41)4*L "#$%&'()#%*+#,+-#.)/+01#.1'22)%. 3412)%'()#%+#,+01#.1'2* !9
-4<4;+M'77)%.* ;4<4;+2'77)%.+,#1+71#.1'2+ / +? ! +,$%/()#%+]+]+?+ 01 / + ! + $ ;4<4;+#,+.1#$%&+'(#2+ 2 +? ! +] 2 ] /;'$*4 34 +14/$114%(+GL1L(L+]+] ? ! ,#1+4<41>+.1#$%&+)%*('%/4+ 2 +^+ 1 +#,+ 4 +'%&+4<41>+ 1 + + " 1 ? + ] 2 ]+_+] 1 ] 71#.1'2+ / +14/$114%(+? ! ,#1+*#24+;4<4;+2'77)%.+]+]T + 4'/6+ 4 + + " / +)*+14/$114%(+GL1L(L+]+] "#$%&'()#%*+#,+-#.)/+01#.1'22)%. 3412)%'()#%+#,+01#.1'2* !C
`\'27;4+VaW + "#"$#% V 5 T+b 5 ] 6 cW+^ + "#"$#% V 5 T+b 6 ] 7 cW+^+ "#"$#% V 5 T+ 7 W J)(6+]+ "#"$#% V 8 T+ 9 W+]+? ! +d;)*(*)e4f+#,+ 9 T+(64+/;'$*4*+'14+14/$114%(L + &'$&#( Vb 5 ] 6 cT+ 7 W+^+ "#"$#% V 5 T+ 7 WT+ &'$&#( V 6 T+ 7 W + &'$&#( Vb+cT+ 5 W+^ D4,)%4+]+ &'$&#( V 8 T+ 9 W+]+? ! + )*&(&*+# V 8 W+g+ )*&(&*+# V 9 WL 36)*+*6#G*+(6'(+(64+4%()14+71#.1'2+)*+14/$114%(L a%/)&4%(';;>T+(64+71#.1'2+';G'>*+(412)%'(4*+,#1+.1#$%&+O$41)4*L "#$%&'()#%*+#,+-#.)/+01#.1'22)%. 3412)%'()#%+#,+01#.1'2* !F
`\'27;4+VaaW + ,-- Vb+cT+ 5 T+ 5 W+^ + ,-- Vb 5 ] 6 cT+ 7 T+b 5 ] : cW+^+ ,-- V 6 T+ 7 T+ : W + %#. Vb+cT+b+cW+^ + %#. Vb 5 ] 6 cT+ 7 W+^+ %#. V 6 T+ : WT+ ,-- V : T+b 5 cT+ 7 W 36)*+71#.1'2+)*+%#(+14/$114%(L a%/)&4%(';;>T+)(+*+%#(+';G'>*+(412)%'(4+,#1+.1#$%&+O$41)4*L %#. Vb " T+ ! cT+ 4 W+ " + %#. Vb ! cT+ : ! WT+ ,-- V : ! T+b " cT+ 4 W + + " + %#. Vb 3 cT+ : 9 WT+ ,-- V : 9 T+b ! cT+ : ! WT+ ,-- V : ! T+b " cT+ 4 W " + %#. Vb 3 cT+ : 9 WT+ ,-- V 6 C T+b ! cT+ : C WT+ ,-- V : ! T+b " cT+ 4 W + + " +LLL "#$%&'()#%*+#,+-#.)/+01#.1'22)%. 3412)%'()#%+#,+01#.1'2* !H
h#$%&4&+N$41)4* '(#2+ 2 +B#$%&4&+GL1L(L+]+] ? ! +,#1+*#24+ ; + + +G4+6'<4+] " % 2 i]+ + & ; +,#1+';;+ 2 i+ + " #<(:$* V 2 W ;4<4;+] 2 ]+#,+B#$%&4&+'(#2+ 2 +? ! + ."5 j] 2 i]+]+ 2 i+ + " #<(:$* V 2 Wk O$41>+B#$%&4&+GL1L(L+]+]+? ! +';;+)(*+'(#2*+'14+B#$%&4&+G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$ W]+X+U+),+ A + +b ' m ] m c + )*&( Vb+cW+^ + )*&( Vb 5 ] 6 cW+^+ )*&( V 6 W D4,)%)%.+] )*&( V 9 W]+? ! +] 9 ] *6#G*+(6'(+(6)*+71#.1'2+)*+14/$114%(T 64%/4+';G'>*+(412)%'()%.+,#1+B#$%&4&+O$41)4*L "#$%&'()#%*+#,+-#.)/+01#.1'22)%. 3412)%'()#%+#,+01#.1'2* !Q
! a27#1('%/4+#,+56#)/4+#,+-4<4;+M'77)%. ,-- Vb+cT+ 5 T+ 5 W+^ + ,-- Vb 5 ] 6 cT+ 7 T+b 5 ] : cW+^+ ,-- V 6 T+ 7 T+ : W + 364*4+/;'$*4*+'14+14/$114%( GL1L(L+] ,-- V 5 T+ 6 T+ 7 W] ! +? ! +] 5 ] + '%&+';*# GL1L(L++] ,-- V 5 T+ 6 T+ 7 W] 9 +? ! +] 7 ]L a%+4'/6+/'*4+G4+#B(')%+&),,414%(+B#$%&4&+O$41)4*L `L.LT+ ,-- Vb " T+ ! cT+>T+ 7 W+)*+B#$%&4&+GL1L(L+]+] ! +B$(+%#(+GL1L(L+]+] 9 + ,-- V 5 T+>T+b 4 T+ * cW+)*+B#$%&4&+GL1L(L+]+] 9 +B$(+%#(+GL1L(L+]+] ! h#(6+(64*4+O$41)4*+'14+B#$%&4&+GL1L(L + +] ,-- V 5 T+ 6 T+ 7 W] C +? ! + .=$ V] 5 ]T+] 7 ]W "#$%&'()#%*+#,+-#.)/+01#.1'22)%. 3412)%'()#%+#,+01#.1'2* 9U
-)2)('()#%*?+=4%41';+R-D+<*L+01#;#.+VaW edge(a, b). edge(b, c). edge(d, e). path(X, Y) :- edge(X, Y). path(X, Y) :- edge(X, Z), path(Z, Y). arc(a, b). arc(b, c). arc(d, e). connected(X, Y) :- arc(X, Y). connected(X, Y) :- connected(X, Z), arc(Z, Y). [4)(641+71#.1'2+)*+14/$114%(L P#G4<41T+';;+-DS&41)<'()#%*+,#1+(64+,)1*(+71#.1'2+'14+,)%)(4L "#$%&'()#%*+#,+-#.)/+01#.1'22)%. 3412)%'()#%+#,+01#.1'2* 9!
-)2)('()#%*?+=4%41';+R-D+<*L+01#;#.+VaaW + ,-- Vb+cT+ 5 T+ 5 W+^ + ,-- Vb 5 ] 6 cT+ 7 T+b 5 ] : cW+^+ ,-- V 6 T+ 7 T+ : W ,--/ V 5 T+ 6 T+ 7 T+ : W+^+ ,-- V 5 T+ 6 T+ B WT+ ,-- V B T+ 7 T+ : W + + ] ,-- V 5 T+ 6 T+ 7 W] ? ! + .=$ V] 5 ]T+] 7 ]W ] ,--/ V 5 T+ 6 T+ 7 T+ : W] ? ! +] 5 ]+g+] : ]+g+! + *6#G*+(6'(+(64+71#.1'2+)*+14/$114%(L h$(+ ,--/ Vb " cT+b ! cT+b 4 cT+ : W+)*+%#(+B#$%&4&+GL1L(L+]+]+'%&+)%&44&+6'*+'%+)%,)%)(4+&41)<'()#%L P#G4<41T+';;+-DS&41)<'()#%*+#,+ / + ! +j ,--/ Vb " cT+b ! cT+b 4 cT+ : Wk+'14+,)%)(4L "#$%&'()#%*+#,+-#.)/+01#.1'22)%. 3412)%'()#%+#,+01#.1'2* 99
Recommend
More recommend