Prolog/推理引擎
外貌
< Prolog
本文需要專家關注!
預設情況下,Prolog 進行自頂向下邏輯推理。
示例
clever(joe).
handsome(joe).
hasgirlfriend(X):-
clever(X),handsome(X).
我們以“hasgirlfriend(X).”執行,以獲取有女朋友的人員。
雙向推理
clever(joe).
handsome(joe).
rule([handsome(joe),clever(joe)],(hasgirlfriend(joe))).
run:- call(rule(X,Y)),findall(A,(member(A,X),call(A)),L),
length(X,Rulelength),
length(L,Rulelength),
assert(Y),print(Y).
我們以“run.”執行。
我們不必直接詢問誰有女朋友,它向我們提供所有可以推斷出的結果。雙向推理的好處是提高了速度。