⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 family.pl

📁 prolog样例
💻 PL
字号:
female(ann).

female(cathy).

female(lisa).

female(lora).

female(mary).

female(rose).

female(susan).



male(charles).

male(david).

male(fred).

male(george).

male(ian).

male(joe).

male(john).

male(paul).

male(peter).



mother_of(john,ann).

mother_of(mary,ann).

mother_of(cathy,ann).

mother_of(peter,mary).

mother_of(paul,mary).

mother_of(charles,cathy).

mother_of(susan,cathy).

mother_of(george,lora).

mother_of(ian,lora).

mother_of(lisa,rose).



father_of(john,fred).

father_of(mary,fred).

father_of(cathy,fred).

father_of(peter,joe).

father_of(paul,joe).

father_of(charles,david).

father_of(susan,david).

father_of(george,paul).

father_of(ian,paul).

father_of(lisa,charles).



parents(Child,Mother,Father) :- 

   mother_of(Child,Mother),

   father_of(Child,Father).



sisters(X,Y) :- female(X), female(Y),

                X \= Y,

                parents(X,M,F),

                parents(Y,M,F).



is_grandfather(G) :- father_of(X,G),

                     (mother_of(_,X); father_of(_,X)).



ancestor_of(P,A) :- mother_of(P,A).

ancestor_of(P,A) :- father_of(P,A).

ancestor_of(P,A) :- mother_of(P,M), ancestor_of(M,A).

ancestor_of(P,A) :- father_of(P,M), ancestor_of(M,A).



ancestors_of(P,As) :- bagof(A,ancestor_of(P,A),As).



descendants_of(P,Ds) :- bagof(D,ancestor_of(D,P),Ds).



is_grandmother(G) :- mother_of(X,G),

                     (mother_of(_,X); father_of(_,X)).



% inferior implementation of grandparents/0 returning multiple instances ...

% grandparents :- (is_grandmother(G);is_grandfather(G)), write(G), nl, fail.

% grandparents.



grandparents :- setof(G,(is_grandmother(G); is_grandfather(G)),Gs),

                writelist(Gs).



writelist([]).

writelist([H|T]) :- write(H), write(', '), writelist(T).



⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -