开发者

How to write "a implies b or c" in Prolog

How would I write the following in Prolog?

开发者_JAVA技巧
a -> b V c

In English that would be a implies that b or c (or both)


The clause

a => (b ; c)     % ';' means 'or'

is not a Horn clause and hence cannot be represented in (pure) Prolog (see e.g Wikipedia). On the other hand (b ; c) => a is a Horn clause and can obviously be represented by two Prolog rules.


I'm not entirely sure what you want to do with with this implies statement. But I would have thought the following would suffice (bear in mind this is SICStus not swi, but at this low level I think it's all the same).

predicate(a, b).
predicate(a, c).

?- predicate(a, Then).
Then = b ;
Then = c ;
no

?- predicate(x, Then).
no

You could do more complicated checks to make sure a is never an unbound value (to prevent predicate(If, b). being true), but unless you're making a huge application then I'm sure good documentation would suffice.


Logically, "b or c" is the same thing as "b or c (or both)"

You can read about logical operators in Prolog here: http://rigaux.org/language-study/syntax-across-languages-per-language/Prolog.html

Can you explain a bit more please what you're trying to do with 'implies'?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜