admin管理员组

文章数量:1432595

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

本文标签: PROLOG predicate returns false and negation does as well (using not)Stack Overflow