Prolog predicates

好久不见. 提交于 2020-01-05 15:28:10

问题


I am currently learning about predicate logic in Prolog. I am having trouble answering a question on the topic and would like to know the steps one one take to solve such a question using Prolog predicates. I have a scenario which must be represented in Prolog predicates using only two different predicate names.

  1. A and B are married
  2. B likes C
  3. C and D are married
  4. D likes E
  5. F likes B
  6. E likes B
  7. E and G are married
  8. A likes G

回答1:


Just write down what it says.

are_married(a,b).

likes(b,c).

And so on. We've used two names of predicates so far.

In Prolog, atoms are denoted by identifiers starting with a lower case letter. Identifiers starting with an upper case letter or an underscore _ denote logical variables.



来源:https://stackoverflow.com/questions/16502892/prolog-predicates

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!