Prolog implying a negative predicate

后端 未结 4 549
时光说笑
时光说笑 2021-02-02 16:20

How can I write the following rule in PROLOG: if P then not Q

I understand that you can easily write if P then Q the predicates like q(X) :- p(X)

4条回答
  •  自闭症患者
    2021-02-02 16:36

    Have you ever heard about cut in Prolog?

    Anyway I don't know much about Prolog standard, but in SWI-Prolog the symbol \+ means negation. I know it don't have to work in every Prolog's interpreter.

    You can make the predicate negation with Prolog's cut. The predicate is defined like:

    not(Goal) :- call(Goal),!,fail.
    not(Goal). 
    

    It means that Goal can't be proven, not the Goal is false. Maybe this Prolog & Cut link will be useful.

提交回复
热议问题