Prolog Language
파생 나무
수색…
감추다
증명 트리 (검색 트리 또는 파생 트리)는 프롤로그 프로그램의 실행을 표시하는 트리입니다. 이 트리는 Prolog에있는 시간순 역 추적 프로세스를 시각화하는 데 도움이됩니다. 트리의 루트는 초기 쿼리를 나타내고 선택 지점이 발생할 때 분기가 만들어집니다. 그러므로 트리의 모든 노드는 목표를 나타냅니다. true / false가 목표 (들)로 필요하고 Prolog에서 검색이 왼쪽 에서 오른쪽으로 먼저 수행 될 때 분기 만 leafs가됩니다.
다음 예제를 고려하십시오.
% Facts
father_child(paul,chris). % Paul is the father of Chris and Ellen
father_child(paul,ellen).
mother_child(ellen,angie). % Ellen is the mother of Angie and Peter
mother_child(ellen,peter).
% Rules
grandfather_grandchild(X,Y) :-
father_child(X,Z),
father_child(Z,Y).
grandfather_grandchild(X,Y) :-
father_child(X,Z),
mother_child(Z,Y).
우리가 지금 질의 할 때 :
?- grandfather_grandchild(paul,peter).
다음 증명 트리는 깊이 우선 검색 프로세스를 시각화합니다.
?- grandfather_grandchild(paul,peter).
/ \
/ \
?- father_child(paul,Z1),father_child(Z1,peter). ?- father_child(paul,Z2),mother_child(Z2,peter).
/ \ / \
{Z1=chris} {Z1=ellen} {Z2=chris} {Z2=ellen}
/ \ / \
?- father_child(chris,peter). ?- father_child(ellen,peter). ?- mother_child(chris,peter). ?- mother_child(ellen,peter).
| | | / \
fail fail fail fail(*) success
'angie'가 'peter'와 일치하지 않는 mother_child(ellen,angie)
에서 (*) 실패
Modified text is an extract of the original Stack Overflow Documentation
아래 라이선스 CC BY-SA 3.0
와 제휴하지 않음 Stack Overflow