最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

PROLOG predicate returns false and negation does as well (using not) - Stack Overflow

programmeradmin2浏览0评论

I have the following rules set up.

pokemonOfType(charmander, fire).
pokemonOfType(staryu, water).

typeWins(water, fire). % this should not affect the outcome,
                       % but who knows

pokemonWins(Winner, Loser) :-
    pokemonOfType(Winner, TypeWinner), 
    pokemonOfType(Loser, TypeLoser),
    typeWins(TypeWinner, TypeLoser).

If I run ?-pokemonWins(charmander, staryu). I get the following output (false). If I run ?-not(pokemonWins(charmander, staryu)). I also get false!

What is going on?

I have the following rules set up.

pokemonOfType(charmander, fire).
pokemonOfType(staryu, water).

typeWins(water, fire). % this should not affect the outcome,
                       % but who knows

pokemonWins(Winner, Loser) :-
    pokemonOfType(Winner, TypeWinner), 
    pokemonOfType(Loser, TypeLoser),
    typeWins(TypeWinner, TypeLoser).

If I run ?-pokemonWins(charmander, staryu). I get the following output (false). If I run ?-not(pokemonWins(charmander, staryu)). I also get false!

What is going on?

Share Improve this question edited Nov 18, 2024 at 20:36 TessellatingHeckler 29.1k4 gold badges54 silver badges93 bronze badges asked Nov 18, 2024 at 17:28 ChuweeChuwee 11 bronze badge 2
  • not(pokemonWins(charmander, staryu)). succeeds, i.e. shows true, in swi-prolog 9.2.8. – brebs Commented Nov 18, 2024 at 18:09
  • Try using the built-in negation. Instead of not(pokemonWins...) write: \+ pokemonWins(...) – TA_intern Commented Nov 19, 2024 at 7:22
Add a comment  | 

1 Answer 1

Reset to default 0
?- pokemonWins(charmander, staryu)
false

?- not(pokemonWins(charmander, staryu))
true

should work. So, it's likely something else.

But, in Prolog, not is implemented as "negation as failure". not(X) succeeds if X fails, and fails if X succeeds. not doesn't mean "logical not" in the classical sense.

And it's considered deprecated due to such confusion and should not be used in a new code according to the SWI prolog. https://www.swi-prolog./pldoc/man?predicate=not/1

发布评论

评论列表(0)

  1. 暂无评论