두 개의 이진 트리가 서로 동형인지를 결정하는 프롤로그 조건자를 작성하는 임무가 있습니다. 술어는 모든 이진 트리에 동형 그래프를 모두 제공 할 수 있어야합니다.Binary Tree Isomorphism
여기는 내가 지금까지 가지고있는 것입니다, 중복을 제외하고 작동합니다.
% Clause: btree_iso
%
% Specification:
% --------------
% Satisfied when the two binary-tree parameters are isomorphic. Two binary
% trees are isomorphic if one can be derived from the other by changing the
% order of the branches. Either of the parameters may be instantiated with a
% variable when btree_iso is used in a top-level goal.
%
% Description:
% ------------
% Base case for the binary tree iso morphism predicate.
% Both sides are leaves.
btree_iso(leaf, leaf).
% Description:
% ------------
% TODO
btree_iso(node(BTL1, X, BTR1), node(BTL2, X, BTR2)) :- btree_iso(BTL1, BTL2),
btree_iso(BTR1, BTR2).
% Description:
% ------------
% TODO
btree_iso(node(BTL1, X, BTR1), node(BTL2, X, BTR2)) :- btree_iso(BTL1, BTR2),
btree_iso(BTR1, BTL2).
예상 출력 :
? - btree_iso(node(node(leaf,3,leaf),3,node(leaf,5,leaf)),BT).
BT = node(node(leaf, 3, leaf), 3, node(leaf, 5, leaf)) ;
BT = node(node(leaf, 5, leaf), 3, node(leaf, 3, leaf)).
내 출력 분명히
?- btree_iso(node(node(leaf,3,leaf),3,node(leaf,5,leaf)),BT).
BT = node(node(leaf, 3, leaf), 3, node(leaf, 5, leaf)) ;
BT = node(node(leaf, 3, leaf), 3, node(leaf, 5, leaf)) ;
BT = node(node(leaf, 3, leaf), 3, node(leaf, 5, leaf)) ;
BT = node(node(leaf, 3, leaf), 3, node(leaf, 5, leaf)) ;
BT = node(node(leaf, 5, leaf), 3, node(leaf, 3, leaf)) ;
BT = node(node(leaf, 5, leaf), 3, node(leaf, 3, leaf)) ;
BT = node(node(leaf, 5, leaf), 3, node(leaf, 3, leaf)) ;
BT = node(node(leaf, 5, leaf), 3, node(leaf, 3, leaf)).
이 모든 반복은, 내가 컷을 배치 할 적절한 위치를 찾을 수 없습니다 따라서 술어는 중복을 리턴하지 않습니다. 또한 하나의 잎과 하나의 다른 노드가있는 노드에 대해 두 개의 다른 술어를 작성하려고했지만 도움이되지 않았습니다.
중복을 어떻게 막을 수 있습니까?
TA를 요청하는 이유는 무엇입니까? 솔직히, 너 자신을 위해 이걸 알아 내려고 노력하면 수업 시간에 더 잘 할거야. – vy32