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?
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".
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!
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.
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?
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!
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.
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.
(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).
@@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.
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
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?
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".
@@ThePowerOfProlog Thanks for the explanation, quite simple really.
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?
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!
Is CLP a library for prolog? How I can install it?
Just go to 6:00 ...
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.
You are almost there! The challenge is to state explicitly everything you know about the task. Thank you for your interest!
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?
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!
@@ThePowerOfProlog Ah I see now. Thanks!
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.
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.
@@ThePowerOfProlog Scryer unlike SICStus is free?
@@alamagordoingordo3047 Yes, Scryer is free.
@@ThePowerOfProlog Install Scryer is so difficult, i'm not a docker fan...
I really like your videos, but sometimes I have to listen at 0.75 speed to understand it all.. :)
Thank you a lot, this is one of the nicest compliments I have heard about these videos, at least regarding the information content!
Why not "is" instead of #=
(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).
@@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.
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
swipl behaves ok however....weird