Live data from Hacker News

Learn Prolog Now (2006)

lpn.swi-prolog.org

211–220 of 251 posts

Re: Learn Prolog Now (2006)

#211
post #180

Earlier quoted context omitted.

> " as the proof proceeds, the cardinality of the set of possible answers [1] decreases " In the sense that it cuts off part of the search tree where answers cannot be found? member(X, [1,2,3,4]), X > 5, slow_computation(X, 0.001). will never do the slow_computation - but if it did, it would come up with the same result. How is that the polar opposite of brute force, rather than an optimization of brute-force? If a l…

I don't understand (the point of) your example. In all branches of the search `X > 5` will never be `true` so yeah `slow_computation` will not be reached. How does that relate to your point of it being "brute force" >> but if it did, it would come up with the same result Meaning either changing the condition or the order of the clauses. How do you expect Prolog to proceed to `slow_computation` when you have declared…

The point is to compare a) evaluate all three lines (member, >5, slow_computation) then fail because the >5 test failed; against b) evaluate (member, >5) then fail. And to ask whether that's the mechanism YeGoblynQueyne is referring to. If so, is it valid to describe b as "the polar opposite" of a? They don't feel like opposites, merely an implementation detail performance hack. We can imagine some completely different strategy such as "I know from some other Constraint Logic propagation that slow_computation has no solutions so I don't even need to go as far as the X>5 test" which is "clever" not "brute".

> "How do you expect Prolog to proceed to `slow_computation` when you have declared a statement (X > 5) that is always false before it"

I know it doesn't, but there's no reason why it can't. In a C-like language it's common to do short-circuit Boolean logic evaluation like:

    A && B && C
and if the first AND fails, the second is not tested. But if the language/implementation doesn't have that short-circuit optimisation, both tests are run, the outcome doesn't change. The short-circuit eval isn't the opposite of the full eval. And yes this is nitpicking the term "polar opposite of" but that's the relevant bit about whether something is clever or brute - if you go into every door, that's brute. If you try every door and some are locked, that's still brute. If you see some doors have snow up to them and you skip the ones with no footprints, that's completely different.

Re: Learn Prolog Now (2006)

#212

Earlier quoted context omitted.

It's not really false I think. It's 'no', which is an answer to a question "Do I know this to be true?" I think there should be a room for three values there: true, unprovable, false. Where false things are also unprovable. I wonder if Prolog has false, defined as "yes" of the opposite.

> It's not really false I think. It's 'no', which is an answer to a question "Do I know this to be true?" I don't think so, because in this case both x and not-x could be "no", but I think in Prolog, if x is "no", not-x is "yes", even if neither is known to be true. It's not a three-valued logic that doesn't adhere to the law of the excluded middle.

If x is "no" (I do not know this to be true) then not-x is "yes" (I do know this to be true). So negation still works as usual.

"Yes" is not "true" but rather "provably true". And "no" is not "false" but rather "not provably true".

Third sensible value in this framework (which I think Prolog doesn't have) would be "false" meaning "it's provably false" ("the opposite of it is provably true").

To be frank I think Prolog in newer implementations completely abandoned this nuance and just call states "true" and "false" instead of "yes" and "no".

Re: Learn Prolog Now (2006)

#213

Earlier quoted context omitted.

Contrary to what everyone else is saying, I think you're completely correct. Using it for AI or "reasoning" is a hopeless dead end, even if people wish otherwise. However I've found that Prolog is an excellent language for expressing certain types of problems in a very concise way, like parsers, compilers, and assemblers (and many more). The whole concept of using a predicate in different modes is actually very usefu…

The reason why you can write parsers with Prolog is because you can cast the problem of determining whether a string belongs to a language or not as a proof, and, in Prolog, express it as a set of Definite Clauses, particularly with the syntactic sugar of Definite Clause Grammars that give you an executable grammar that acts as both acceptor and generator and is equivalent to a left-corner parser. Now, with that in m…

Clearly people write parsers in C and C++ and Pascal and OCAML, etc. What does it mean to come in with "the reason you can write parsers with Prolog..."? I'm not claiming that reason is incorrect, I'm handwaving it away as irrelevant and academic. Like saying that Lisp map() is better than Python map() because Lisp map is based on formal Lambda Calculus and Python map is an inferior imitation for blub programmers. When a programmer maps a function over a list and gets a result, it's a distinction without a difference. When a programmer writes a getchar() peek() and goto state machine parser with no formalism, it works, what difference does the formalism behind the implementation practically make?

Yes maybe the Prolog way means concise code is easier for a human to tell whether the code is a correct expression of the intent, but an LLM won't look at it like that. Whatever the formalism brings, it isn't enough that every parser task is done in Prolog in the last 50 years. Therefore it isn't any particular interest or benefit, except academic.

> both acceptor and generator

Also academically interesting but practically useless due to the combinatorial explosion of "all possible valid grammars" after the utterly basic "aaaaabbbbbbbbbbbb" examples.

> "how you and the OP reconcile the ability to carry out a formal proof with the inability to do reasoning. How is it not reasoning, if you're doing a proof? If a proof is not reasoning, then what is?"

If drawing a painting is art, is it art if a computer pulls up a picture of a painting and shows it on screen? No. If a human coded the proof into a computer, the human is reasoning, the computer isn't. If the computer comes up with the proof, the computer is reasoning. Otherwise you're in a situation where dominos falling over is "doing reasoning" because it can be expressed formally as a chain of connected events where the last one only falls if the whole chain is built properly, and that's absurdum.

Re: Learn Prolog Now (2006)

#214
post #27

Earlier quoted context omitted.

There are a bunch of libraries that will do this - here's one example of a python one: https://github.com/yuce/pyswip - and a ruby one: https://github.com/preston/ruby-prolog

I did try ruby-prolog. The deeper issue is that its just not prolog. Writing in actual prolog affords a lot of clarity and concision which would be quite noisy in ruby-prolog. To me, the difference was stark enough it wasn't worth any convenience already being in ruby was worth.

Porolog might be more to your liking.

https://www.rubydoc.info/gems/porolog#porolog-wiki

Re: Learn Prolog Now (2006)

#215
I only read the first 88 pages of Prolog Programming in Depth but I found it to be the best introductory book for programming in Prolog because it presents down to earth examples of coding like e.g. reading a file, storing data. Most other books are mainly or only focused on the pure logic stuff of Prolog but when you program you need more.

Another way of getting stuff done would be to use another programming language with its standard library (with regex, networking, json, ...) and embed or call Prolog code for the pure logic stuff.

Re: Learn Prolog Now (2006)

#216
post #210

Earlier quoted context omitted.

Clocksin is the standard Prolog textbook used in universities. I studied from the 5th edition.

Nice. Do you use Prolog much today? If so, when do you reach for it?

No, just coming back to it for the intellectual curiosity, nothing more.

Re: Learn Prolog Now (2006)

#217

Earlier quoted context omitted.

The reason why you can write parsers with Prolog is because you can cast the problem of determining whether a string belongs to a language or not as a proof, and, in Prolog, express it as a set of Definite Clauses, particularly with the syntactic sugar of Definite Clause Grammars that give you an executable grammar that acts as both acceptor and generator and is equivalent to a left-corner parser. Now, with that in m…

Clearly people write parsers in C and C++ and Pascal and OCAML, etc. What does it mean to come in with "the reason you can write parsers with Prolog..."? I'm not claiming that reason is incorrect, I'm handwaving it away as irrelevant and academic. Like saying that Lisp map() is better than Python map() because Lisp map is based on formal Lambda Calculus and Python map is an inferior imitation for blub programmers. Wh…

With Prolog, the proof is carried out by the computer, not a human. A human writes up a theory and a theorem and the computer proves the theorem with respect to the theory. So I ask again, how is carrying out a proof not reasoning?

>> I'm not claiming that reason is incorrect, I'm handwaving it away as irrelevant and academic.

That's not a great way to have a discussion.

Re: Learn Prolog Now (2006)

#218

Earlier quoted context omitted.

Everything you've written here is an invalid over-reduction, I presume because you aren't terribly well versed with Prolog. Your simplification is not only outright erroneous in a few places, but essentially excludes every single facet of Prolog that makes it a turing complete logic language. What you are essentially presenting Prolog as would be like presenting C as a language where all you can do is perform operati…

The original suggestion was that LLMs should emit Prolog code to test their ideas. My reply was that there is nothing magic in Prolog which would help them over any other language, but there is something in other languages which would help them over Prolog - namely more training data. My example was to illustrate that, not to say Prolog literally is Python. Of course it's simplified to the point of being inaccurate,…

[deleted]

Re: Learn Prolog Now (2006)

#219

Earlier quoted context omitted.

you don’t solve it by brute forcing possible solutions until one sticks

Yeah, read it in another comment. Why do you think doing calculations in your head is brute-forcing? Many people can do it flawlessly, without even knowing of these "tricks". They just know. Is that brute-force?

[flagged]

Re: Learn Prolog Now (2006)

#220

Earlier quoted context omitted.

The reason why you can write parsers with Prolog is because you can cast the problem of determining whether a string belongs to a language or not as a proof, and, in Prolog, express it as a set of Definite Clauses, particularly with the syntactic sugar of Definite Clause Grammars that give you an executable grammar that acts as both acceptor and generator and is equivalent to a left-corner parser. Now, with that in m…

Clearly people write parsers in C and C++ and Pascal and OCAML, etc. What does it mean to come in with "the reason you can write parsers with Prolog..."? I'm not claiming that reason is incorrect, I'm handwaving it away as irrelevant and academic. Like saying that Lisp map() is better than Python map() because Lisp map is based on formal Lambda Calculus and Python map is an inferior imitation for blub programmers. Wh…

> If a human coded the proof into a computer, the human is reasoning, the computer isn't. ... If the computer comes up with the proof, the computer is reasoning.

That is exactly what "formal logic programming" is all about. The machine is coming up with the proof for your query based on the facts/rules given by you. Therefore it is a form of reasoning.

Reasoning (cognitive thinking) is expressed as Arguments (verbal/written premises-to-conclusions) a subset of which are called Proofs (step-by-step valid arguments). Using Formalization techniques we have just pushed some of those proof derivations to a machine.

I pointed this out in my other comment here https://news.ycombinator.com/item?id=45911177 with some relevant links/papers/books.

See also Logical Formalizations of Commonsense Reasoning: A Survey (from the Journal of Artificial Intelligence Research) - https://jair.org/index.php/jair/article/view/11076

Post reply on HN