Knights and Knaves in Prolog

Поділитися
Вставка
  • Опубліковано 14 гру 2024

КОМЕНТАРІ • 10

  • @bayesianadventures6246
    @bayesianadventures6246 3 роки тому

    Very nicely done! I've long been a fan of the logician Smullyan (he died in 2017). I've used Bayesian networks to solve these puzzles which also works very nicely since they use an inference engine underneath a GUI.

  • @kalebjuliu7944
    @kalebjuliu7944 4 роки тому +2

    Very nice explanation!

  • @bertrandduguesclin826
    @bertrandduguesclin826 2 роки тому

    If I query A says (A = knave, B = knight) then I get A = knave, dif(B, knight) as an answer. Is there a way to specifiy that the domain of A and B is [knight, knave] ? Should I map these two atoms to integers as it is done for the mapcolor puzzle?

    • @ThePowerOfProlog
      @ThePowerOfProlog  2 роки тому +1

      If you map them to integers, then you can benefit from CLP(ℤ) constraint propagation. Alternatively, you can constrain these variables to their intended domain with (for example) member/2, ideally after all constraints are posted so that inconsistent branches of the search are pruned early.
      Some Prolog systems also provide CLP(Set), so that you can reason about sets of admissible values that are not necessarily integers.

    • @bertrandduguesclin826
      @bertrandduguesclin826 2 роки тому

      @@ThePowerOfProlog Thank you for your answer. swi-prolog does not seem to have clp(set) but yes I can do it with clp(Z). I will see with member/2 but there is no constraint to post since I was refering to the DSL part of your video.

  • @ooloncolluphid9975
    @ooloncolluphid9975 4 роки тому

    Can we also use this to generate the statements, to solve the "Fork in the road" variants? For example we encounter a inhabitants A and B, one of them is a knight and the other a knave, but we don't know which. So we ask a single question X to determine the "knighthoods" of A and B. How would one use clpb to solve this?

    • @ThePowerOfProlog
      @ThePowerOfProlog  4 роки тому +1

      Good question! I think it is conceivable. It's quite hard though. Maybe start with a declarative description of what a "question" could look like, and what sensible answers could be. Then exhaustively generate questions, and find matching answers.

    • @ooloncolluphid9975
      @ooloncolluphid9975 4 роки тому

      @@ThePowerOfProlog yes, I feel it amounts to something like "list all the true statements given some axioms", which could be problematic :)

  • @0xeb-
    @0xeb- 2 роки тому +1

    Thank you.

  • @Schwonko
    @Schwonko 2 місяці тому

    A says: Either ... or. To me this is a xor, not an or. Then you also have the solution A=0, B=1.
    goal: sat((~A # B) =:= A), labeling([A,B]).