前向和后向链接的Prolog示例

时间:2017-11-12 03:54:52

标签: prolog

根据当时的规则,任何允许的安全人员 没有任何有效身份证明的任何局外人进入校园 暂停。一些没有任何有效身份证明的局外人在里面找到 校园。所有这些局外人都被允许进入校园 安全人员名叫X先生。

(a) From the above statements, construct a knowledge base.
(b) Implement forward and backward chaining.
(c) Using the forward chaining and backward chaining, prove that
“Mr. X must be suspended”.
(d) Compare the efficiency of forward chaining and backward chain-
ing algorithms with respect to the number of irrelevant clauses
generated.

对于上述问题,我这样做。

securityPerson(mrx).
outsider(P).
securityAllows(mrx,P).
suspended(Z) :- securityPerson(Z),outsider(P),securityAllows(Z,P).

查询:

?- suspended(mrx).
true.
?- suspended(mrxa).
false.
?- trace.
true.
[trace]  ?- suspended(mrx).
Call: (7) suspended(mrx) ? creep
Call: (8) securityPerson(mrx) ? creep
Exit: (8) securityPerson(mrx) ? creep
Call: (8) outsider(_G1937) ? creep
Exit: (8) outsider(_G1937) ? creep
Call: (8) securityAllows(mrx, _G1938) ? creep
Exit: (8) securityAllows(mrx, _G1938) ? creep
Exit: (7) suspended(mrx) ? creep
true.

是否正确?如果没有请帮助

1 个答案:

答案 0 :(得分:0)

不,这似乎不正确。你没有编写“校园内部”。此外,你的规则似乎暗示X先生是一个局外人。你应该组成一些个体,而不是在outsider / 1子句中有一个(n隐式普遍量化的)变量。

相关问题