Replies: 4 comments 3 replies
-
You can define natural numbers using classic successor function: nat(0).
nat(succ(X)) :- nat(X). And then you can start building on that notion, for example you can define odd and even numbers: nat_even(0).
nat_even(succ(succ(X))) :- nat_even(X).
nat_odd(succ(X)) :- nat_even(X). Of course you then need to accept that |
Beta Was this translation helpful? Give feedback.
-
Thank you for the suggestions. My newest "lyric code" is not so naked Prolog: I'm using
With At the end of the day, it was a mistaken, out of topic experiment/attempt (not using clpz struggling with not using Nevertheless, I think, I like experimenting with Prolog; though, at a "simple/basic" level. Thank you. |
Beta Was this translation helpful? Give feedback.
-
PS: As a bonus or by-product, then, thinking/writing about the relational filtering, I also "discovered" my own version of a (wannabe) relational addition, but I edited/removed it from my comment (or the whole comment) then:
The "addition" example. Again, don't try it at home...
And today, accidentally, via reading something about Prolog on Softpanorama, I've found: "Pure, Declarative, and Constructive Arithmetic Relations (Declarative Pearl)" |
Beta Was this translation helpful? Give feedback.
-
Consider the following failure-slice: add(N1,N2,Sum) :- length(N1s,N1), length(N2_1s,N2), false, If this does not terminate, then also your original program does not terminate (universally). |
Beta Was this translation helpful? Give feedback.
-
I was inspired by Markus @triska
As I'm a Prolog beginner, and not only Prolog beginner, I would say, the realm of programming itself is something I'm only starting to explore...
So, often I have crazy ideas in my head, like: how to do the numeric filtering, but without clpz library. With naked Prolog, so to speak, how can I make a truly relational filtering program, working in "two-way" mode (like with clpz), at least to some extent... The relational mode means without standard built-in operators:
is/2
and friends. Without standard modulo, minus and comparison operator. Is it possible?The code works only with the basic numbers 0..9 and 10 (why not). I'm not a math person, but, I think, the code might be extended (not by me) to work with arbitrary natural numbers, except, represented like this: 5 = [5], 112 = [1,1,2] as the user-input format; if I want to use only the "naked" Prolog, and I wanted. Yes, in a small 0..9 domain, I could define directly what is even or odd number: without my lists of ones... And indeed, direct defining is the magic. Prolog asks us to define...
Of course, I love clpz library. Beside the declarative arithmetic, many problems, nightmares using classical computer science methods, are suddenly only few declarative lines of code, with the clpz. I love every library and design decision that makes Scryer a more declarative, relational/bidirectional and easy to use Prolog system.
Too, I like the notion (Marc Denecker/recently with David S. Warren) that Prolog is basically a language of (inductive) definitions. Inductive definitions allows bottom-up reasoning, in a good way. Like: Dear category theory, Prolog has a cool constructive math build in, by definition, by the constructive
:-
. Like: Bottom-up thinking in Prolog considered beneficial, especially for beginners: in this view, for instance, recursion is not a concept to think with, it's only a concrete mechanism used to evaluate inductive definitions top-down. But we can think iteratively: building (with our predicates, independently of problem decomposition) a set (a relation is a set, a set of tuples with the desired property) in a bottom-up way. Like: Programming and proving that your program is correct at the same time. Unfortunately, I'm afraid, my filtering example is not a good example of that methodology.Brutally inefficient, quick and dirty and useless, call it a kindergarten programming, it is (sometimes I want to touch some CS and programming basics with my own hands, the most simple things); it's only my crazy thought experiment after all, or my MacGuffin. But I hope, it's fully "definitional", even somewhat inductive, in a lyric sense... Or, maybe not.
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions