I am a beginner prologue and I want to create a brother relationship.
The relation should be symmetrical, as if the brother (alin, alex) is true, the brother (alex, alin) should also be.
It must also be transitive, as if the brother (alin, alex) and brother (alex, claudiu) were true, brother (alin, claudiu) .
Combining with properties, if the brother (alex, alin) and brother (alex, claudiu) are true, the brother (alin, claudiu) should also be true.
Here is my code:
r_brother(alin, alex).
r_brother(alin, ciprian).
r_brother(alex, claudiu).
s_brother(X, Y) :- r_brother(X, Y).
s_brother(X, Y) :- r_brother(Y, X).
brother(L1, L2) :-
t_brother(L1, L2, []).
t_brother(L1, L2, _) :-
s_brother(L1, L2).
t_brother(L1, L2, IntermediateNodes) :-
s_brother(L1, L3),
\+ member(L3, IntermediateNodes),
t_brother(L3, L2, [L3 | IntermediateNodes]).
r_brother - basic ratio
s_brother - ( )
t_brother - , ,
, :
?- brother(X, alin).
:
X = alex ;
X = ciprian ;
X = alin ;
X = alin ;
X = alin ;
X = alin ;
X = alex ;
X = alex ;
X = alex ;
X = alex ;
X = ciprian ;
X = ciprian ;
X = claudiu ;
X = claudiu ;
false.
, , , , .
alin , .