Prolog Integer Arithmetic

Поділитися
Вставка
  • Опубліковано 7 січ 2025

КОМЕНТАРІ •

  • @simonsaville9962
    @simonsaville9962 5 років тому +3

    Yet another great video exposition of Prolog. Thank You! However, I am confused concerning the use of "disequality" over "inequality". If I'm honest, I don't really understand the distinction. Help?

    • @ThePowerOfProlog
      @ThePowerOfProlog  5 років тому +3

      Thank you so much for your kind words! "Disequality" denotes the negation of equality, whereas the relations "less/greater than" and "less/greater than or equal to" are called "inequalities".

    • @simonsaville9962
      @simonsaville9962 5 років тому +1

      @@ThePowerOfProlog Thanks for the explanation, quite simple really.

  • @RenanNespolo
    @RenanNespolo 9 місяців тому

    man, I would like to learn plot the tree like in minute 1:14, did you have a vídeo of configuration of make trees?

    • @ThePowerOfProlog
      @ThePowerOfProlog  9 місяців тому

      Thank you a lot for your interest! Please see the following descriptions in the "tools" directory of Scryer Prolog: github.com/mthom/scryer-prolog/tree/master/tools
      I hope this helps!

  • @brianchuquiruna6959
    @brianchuquiruna6959 3 роки тому +2

    Is CLP a library for prolog? How I can install it?

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

      Just go to 6:00 ...

  • @marceloslacerda
    @marceloslacerda 5 років тому +1

    Expressing the example presented I get an unexpected answer:
    ?- (Chicken * 2) + (Cow * 4) #= 74, Chicken + Cow #= 30.
    Chicken+Cow#=30,
    Chicken+2*Cow#=37.
    While it is correct, it's weird that prolog decided to evaluate to another expression rather than saying the values of the free terms.

    • @ThePowerOfProlog
      @ThePowerOfProlog  5 років тому +2

      You are almost there! The challenge is to state explicitly everything you know about the task. Thank you for your interest!

    • @marceloslacerda
      @marceloslacerda 5 років тому

      When I constrain the expression to Chicken #> 0 and Cow #> 0 I get the correct results, but I don't understand, in this problem shouldn't there be only one answer even without the new constraints?

    • @ThePowerOfProlog
      @ThePowerOfProlog  5 років тому

      Try to use the Prolog system to see whether that is indeed the case, i.e., if there are no solutions where these additional constraints are not satisfied, but the others are satisfied!

    • @marceloslacerda
      @marceloslacerda 5 років тому +1

      @@ThePowerOfProlog Ah I see now. Thanks!

  • @alamagordoingordo3047
    @alamagordoingordo3047 3 роки тому +1

    Why to me don't work? with n_factorial(N,F). the result is F = 1. N = 0 ? an then if i press ; yes and stop, no other solutions. P.S. I use GNU prolog.

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

      You can debug the program decelaratively by removing goals, making the program more general. For example, the following goal alone already fails in GNU Prolog: F #= A*B. Therefore, every specialization (i.e., additional constraints) fails too. I recommend to try it for example with Scryer or SICStus Prolog, which are also conforming to the ISO standard and support multiplication more generally.

    • @alamagordoingordo3047
      @alamagordoingordo3047 3 роки тому +2

      @@ThePowerOfProlog Scryer unlike SICStus is free?

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

      @@alamagordoingordo3047 Yes, Scryer is free.

    • @alamagordoingordo3047
      @alamagordoingordo3047 3 роки тому +1

      @@ThePowerOfProlog Install Scryer is so difficult, i'm not a docker fan...

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

    I really like your videos, but sometimes I have to listen at 0.75 speed to understand it all.. :)

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

      Thank you a lot, this is one of the nicest compliments I have heard about these videos, at least regarding the information content!

  • @panjak323
    @panjak323 3 місяці тому

    Why not "is" instead of #=

    • @ThePowerOfProlog
      @ThePowerOfProlog  3 місяці тому

      (is)/2 works only if the right-hand side is ground. For example, we get:
      ?- X is Y + 3.
      error(instantiation_error,(is)/2).
      Whereas (#=)/2 can be used in all situations, and is therefore a lot more general and easier to use. For example:
      ?- #X #= #Y + 3.
      clpz:(#Y+3#=#X).

    • @panjak323
      @panjak323 3 місяці тому

      @@ThePowerOfProlog yeah right, but isn't there also other syntax for numeric evaluation equality?
      Never seen #= in university course, as they forbidden usage of any modules anyways.

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

    I have defined the following predicate:
    n_factorial(0, 1).
    n_factorial(N,F) :-
    N #> 0,
    F #= N*F1,
    N1 #= N - 1,
    n_factorial(N1, F1).
    Yet for some reason when I try to query all possible solutions in gprolog I get the first solution: 0! = 1, then if i press ";" It just says "no" and it returns me to the ?- prompt, any idea why?
    | ?- ['fact'].
    compiling /home/obsrwr/work/fact.pl for byte code...
    /home/obsrwr/work/fact.pl compiled, 7 lines read - 837 bytes written, 6 ms
    yes
    | ?- n_factorial(N,F).
    F = 1
    N = 0 ? ;
    no