首页 文章
  • 0 votes
     answers
     views

    Prolog中的谓词,如果A小于或等于B,则为真

    我想在prolog中写一个谓词 test(A,B) ,如果A小于或等于B,则为真 . 查询示例(应返回true): test(s(s(0)), s(s(s(0)))). test(s(s(s(0))), s(s(s(0)))). 这是我到目前为止编写的代码: test(0,0). test(0, s(B)) :- nat(B). test(s(A),s(B)) :- test(A,B). 但它...
  • 2 votes
     answers
     views

    Prolog中的后继功能

    在我最近在逻辑编程的大学水平考试中遇到的一个问题中,我被要求编写Prolog谓词 odd/1 ,它确定给定值是否为奇数 . 该实现应该使用已经给定的谓词 s/1 ,它将评估给定元素的后继(即X 1) . 这是为 odd/1 谓词的实现提供的解决方案: odd(s(0)):-!. % 1 is the first odd number odd(s(s(X))):- odd(X). % A numbe...

热门问题