简体   繁体   English

通过通用规则在 Prolog 中创建含义,其中 A 暗示 B,B 暗示 A

[英]Creating implications in Prolog, where A implies B and B implies A, through generic rules

No smoke without fire, no fire without smoke.无火无烟,无烟无火。

Identify the conclusion and condition from above statement with a Prolog program.用 Prolog 程序识别上述语句的结论和条件。 In the answer, the conclusion must be that if there is fire, there is smoke and if there is smoke, there must be fire.在答案中,结论必须是,如果有火,就有烟,如果有烟,就一定有火。

How do I do this?我该怎么做呢?

Please explain the answer.请解释答案。

Both are possible because one could argue that there cant be smoke without fire and there cant be fire without smoke.两者都是可能的,因为有人可能会争辩说,没有火就不可能有烟,没有烟就不可能有火。

But given the sentence without prior knowledge about fire and smoke you can only conclude that there can only be smoke if there is a fire .但是在没有关于火和烟的先验知识的情况下,您只能得出结论,只有在有火的情况下才会有烟 So smoke is the condition because " if you see smoke (condition)" you "know there is a fire (conclusion)".所以烟雾是条件,因为“如果你看到烟雾(条件)”你“知道有火(结论)”。 But given only the sentence if you know there is fire you cant be sure there is smoke.但是,如果您知道有火,则仅给出这句话,您不能确定有烟。

I'm assuming this question is about how to create sensible rules which imply facts are true based on other facts known about certain atoms.我假设这个问题是关于如何根据有关某些原子的其他已知事实来创建暗示事实是真实的合理规则。 If location 'a' is smoking, there must be fire at location 'a', therefore 'a' has fire.如果位置“a”在冒烟,则位置“a”一定有火,因此“a”有火。

smoke(a).
smoke(b).
fire(c).

fire(X) :- smoke(X).
smoke(X) :- fire(X).

?- fire(a).
true

?- fire(b).
true

?- fire(c).
true

?- smoke(c).
true

In case you want to specifically check whether something is on fire or smoking:如果您想专门检查某物是否着火或冒烟:

isFire(X) :- fire(X);smoke(X).
isSmoke(X) :- smoke(X);fire(X).

Example:例子:

?- isFire(asbestos), smoke(asbestos).
false <- the first statement is never true so the second never gets called

The ; ; symbol means OR, so if either fire or smoke is true for a given fact, it will return true.符号表示或,所以如果火或烟对于给定的事实为真,它将返回真。

I assume you want to write predicate rule for: If there is smoke there is fine.我假设您想为以下内容编写谓词规则:如果有烟就很好。

Answer: smell(smoke, if) ^ reaction(fire)答案:气味(烟雾,如果)^ 反应(火)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM