I've been playing with prolog lists using peano axioms instead of numbers. So for example calculating 0, succ(0), succ(succ(0)) etc. It works much better in prolog than hacky arithmetic. Inc(N, succ(N)) can be used in both directions.. :)
Nice! Then here is a challenge: Implement nat_nat_sum/3, relating two natural numbers in this representation to their sum, in such a way that the predicate terminates for as many modes as possible. For instance, can you implement a version that terminates if at least two of the arguments are ground? How about only one of the arguments?
@@derekfrost8991 For example, with your current definition, does the following query terminate? ?- nat_nat_sum(s(s(0)), Y, Z), false. If so, that's one example where the predicate terminates universally, which is nice. What about the following query, where the first argument is not known, but the second argument is known: ?- nat_nat_sum(X, s(s(0)), Z), false. Does it terminate? If not, is there a way to change the definition so that this query terminates too?
Yes! I have made these definitions available in the Scryer Prolog repository, please have a look: github.com/mthom/scryer-prolog/tree/master/tools I hope they work for you, enjoy!
God, I hate this. My Professor is incredibly bad at explaining this already (in my opinion) complicated topic (not lists but Prolog in general). And on top of all that, we can't even use RUclips to have proper explanations because he insists on his notation and his way of doing things in Prolog, and his ways seem vastly different than what I've seen in videos. Its so god damn frustrating. He is the main reason I have Prolog with a passion.
Thank you for these videos! You have a great presentation style.
Thank you for your kind words, it is really encouraging to hear this! Enjoy!
This was so helpful! Thanks
You can see parallels between Lisp's car and cdr. Interesting... I heard there was cross pollination between them.
I've been playing with prolog lists using peano axioms instead of numbers. So for example calculating 0, succ(0), succ(succ(0)) etc. It works much better in prolog than hacky arithmetic. Inc(N, succ(N)) can be used in both directions.. :)
Nice! Then here is a challenge: Implement nat_nat_sum/3, relating two natural numbers in this representation to their sum, in such a way that the predicate terminates for as many modes as possible. For instance, can you implement a version that terminates if at least two of the arguments are ground? How about only one of the arguments?
@@ThePowerOfProlog I know how to do add/3. I don't understand what the difference is.. :)
@@ThePowerOfProlog add(0,_,0). add(s(n),m,p) :- add(n,m,p). I think.. :)
@@derekfrost8991 For example, with your current definition, does the following query terminate?
?- nat_nat_sum(s(s(0)), Y, Z), false.
If so, that's one example where the predicate terminates universally, which is nice. What about the following query, where the first argument is not known, but the second argument is known:
?- nat_nat_sum(X, s(s(0)), Z), false.
Does it terminate? If not, is there a way to change the definition so that this query terminates too?
@@ThePowerOfProlog I know it terminates with 2 args in any direction, but with only one it seems impossible.. :)
Thank for these vidios , do you know algorithms Eval / Apply ?
hello , are you using any kind of program that represents the list on the right that i see?
Yes! I have made these definitions available in the Scryer Prolog repository, please have a look: github.com/mthom/scryer-prolog/tree/master/tools
I hope they work for you, enjoy!
I want to ask you that can we use Prolog in any language.. it is possible??
God, I hate this. My Professor is incredibly bad at explaining this already (in my opinion) complicated topic (not lists but Prolog in general). And on top of all that, we can't even use RUclips to have proper explanations because he insists on his notation and his way of doing things in Prolog, and his ways seem vastly different than what I've seen in videos. Its so god damn frustrating. He is the main reason I have Prolog with a passion.