44 comments

[ 4.5 ms ] story [ 62.9 ms ] thread
[flagged]
is prolog a use-case language or is it as versatile as python?
It's a language that should have just been a library. There's nothing noteworthy about it and it's implementable in any working language. Sometimes quite neatly. Schelog is a famous example.
In university, Learning prolog was my first encounter with the idea that my IQ may not be as high as I thought
There are declarative languages like SQL and XSLT.

And then there are declarative languages like Prolog.

I had more success with the Prolog language track on https://exercism.org/tracks/prolog

It's a mind-bending language and if you want to experience the feeling of learning programming from the beginning again this would be it

I've recently started modeling some of my domains/potential code designs in Prolog. I'm not that advanced. I don't really know Prolog that well. But even just using a couple basic prolog patterns to implement a working spec in the 'prolog way' is *unbelievably* useful for shipping really clean code designs to replace hoary old chestnut code. (prolog -> ruby)
Always felt this would be language that Sherlock Holmes would use...so be sure to wear the hat when learning it
I remember writing a Prolog(ish) interpreter in Common Lisp in an 90's AI course in grad school for Theorem proving (which is essentially what Prolog is doing under the hood). Really foundational to my understanding of how declarative programming works. In an ideal world I would still be programming in Lisp and using Prolog tools.
Prolog really is such a fantastic system, if I can justify its usage then I won't hesitate to do so. Most of the time I'll call a language that I find to be powerful a "power tool", but that doesn't apply here. Prolog is beyond a power tool. A one-off bit of experimental tech built by the greatest minds of a forgotten generation. You'd it find deep in irradiated ruins of a dead city, buried far underground in a bunker easily missed. A supercomputer with the REPL's cursor flickering away in monochrome phosphor. It's sitting there, forgotten. Dutifully waiting for you to jack in.
I remember a project I did in undergrad with Prolog that would fit connecting parts of theoretical widgets together based on constraints about how different pieces could connect and it just worked instantly and it felt like magic because I had absolutely no clue how I would have coded that in Pascal or COBOL at that time. It blew my mind because the program was so simple.
What kind of problems is Prolog helping to solve besides GOFAI, theorem proving and computational linguistics?
We had it in university courses and it seemed useless. DSL for backtracking.
Yes. As an add-on or library, it could be useful, but as a language it's just a forgotten dead end.
And for some cases it's easier to understand if you write the backtracking yourself, and can edit/debug it. That is in case you write readable code professionally, as such algorhythms are not very intuitive for a person who sees it first time.
I really enjoyed learning Prolog in university, but it is a weird language. I think that 98% of tasks I would not want to use Prolog for, but for that remaining 2% of tasks it's extremely well suited for. I have always wished that I could easily call Prolog easily from other languages when it suited the use case, however good luck getting most companies to allow writing some code in Prolog.
I love Prolog, and have seen so many interesting use cases for it.

In the end though, it mostly just feels enough of a separate universe to any other language or ecosystem I'm using for projects that there's a clear threshold for bringing it in.

If there was a really strong prolog implementation with a great community and ecosystem around, in say Python or Go, that would be killer. I know there are some implementations, but the ones I've looked into seem to be either not very full-blown in their Prolog support, or have close to non-existent usage.

I am once again shilling the idea that someone should find a way to glue Prolog and LLMs together for better reasoning agents.

https://news.ycombinator.com/context?id=43948657

Thesis:

1. LLMs are bad at counting the number of r's in strawberry.

2. LLMs are good at writing code that counts letters in a string.

3. LLMs are bad at solving reasoning problems.

4. Prolog is good at solving reasoning problems.

5. ???

6. LLMs are good at writing prolog that solves reasoning problems.

Common replies:

1. The bitter lesson.

2. There are better solvers, ex. Z3.

3. Someone smart must have already tried and ruled it out.

Successful experiments:

1. https://quantumprolog.sgml.net/llm-demo/part1.html

There are people working on integration deep learning with symbolic AI (but I don't know more)
I've been thinking a lot about this, and I want to build the following experiment, in case anyone is interested:

The experiment is about putting an LLM to play plman[0] with and without prolog help.

plman is a pacman like game for learning prolog, it was written by profesor Francisco J. Gallego from Alicante University to teach logic subject in computer science.

Basically you write solution in prolog for a map, and plman executes it step by step so you can see visually the pacman (plman) moving around the maze eating and avoiding ghost and other traps.

There is an interesting dynamic about finding keys for doors and timing based traps.

There are different levels of complexity, and you can also write easily your maps, since they are just ascii characters in a text file.

I though this was the perfect project to visually explain my coworkers the limit of LLM "reasoning" and what is symbolic reasoning.

So far I hooked ChatGPT API to try to solve scenarios, and it fails even with substancial amount of retries. That's what I was expecting.

The next thing would be to write a mcp tool so that the LLM can navigate the problem by using the tool, but here is where I need guidance.

I'm not sure about the best dynamic to prove the usefulness of prolog in a way that goes beyond what context retrieval or db query could do.

I'm not sure if the LLM should write the prolog solution. I want to avoid to build something trivial like the LLM asking for the steps, already solved, so my intuition is telling me that I need some sort of virtual joystick mcp to hide prolog from the LLM, so the LLM could have access to the current state of the screen, and questions like what would be my position if I move up ? What's the position of the ghost in next move ? where is the door relative to my current position ?

I don't have academic background to design this experiment properly. Would be great if anyone is interested to work together on this, or give me some advice.

Prior work pending on my reading list:

- LoRP: LLM-based Logical Reasoning via Prolog [1]

- A Pipeline of Neural-Symbolic Integration to Enhance Spatial Reasoning in Large Language Models [2]

- [0] https://github.com/Matematicas1UA/plman/blob/master/README.m...

- [1] https://www.sciencedirect.com/science/article/abs/pii/S09507...

- [2] https://arxiv.org/html/2411.18564v1

This is my own recent attempt at this:

https://news.ycombinator.com/item?id=45937480

The core idea of DeepClause is to use a custom Prolog-based DSL together with a metainterpreter implemented in Prolog that can keep track of execution state and implicitly manage conversational memory for an LLM. The DSL itself comes with special predicates that are interpreted by an LLM. "Vague" parts of the reasoning chain can thus be handed off to a (reasonably) advanced LLM.

Would love to collect some feedback and interesting ideas for possible applications.

The background image says "testing version" - is there a production version?
There seems to an interesting difference between Prolog and conventional (predicate) logic.

In Prolog, anything that can't be inferred from the knowledge base is false. If nothing about "playsAirGuitar(mia)" is implied by the knowledge base, it's false. All the facts are assumed to be given; therefore, if something isn't given, it must be false.

Predicate logic is the opposite: If I can't infer anything about "playsAirGuitar(mia)" from my axioms, it might be true or false. It's truth value is unknown. It's true in some model of the axioms, and false in others. The statement is independent of the axioms.

Deductive logic assumes an open universe, Prolog a closed universe.

Prolog is easily one of my favorite languages, and as many others in this thread, I first encountered it during university. I ended up teaching it for a couple of years (along with Haskell) and ever since, I've gone on an involuntary prolog bender of sorts once or twice a year. I almost always use it for Advent of code as well.
Learn it now? I learned back in the 80s... and have since forgotten
Hah. Found this book back at my dad's this past winter: https://imgur.com/a/CyG1E2P

Had never heard of it before, and this is first I'm hearing of it since.

Also had other cool old shit, like CIB copies of Borland Turbo Pascal 6.0, old Maxis games, Windows 3.1

Declarative languages are fantastic to reason about code.

But the true power is unlocked once the underlying libraries are implemented in a way that surpassesthe performance that a human can achieve.

Since implementation details are hidden, caches and parallelism can be added without the programmer noticing anything else than a performance increase.

This is why SQL has received a boost the last decade with massively parallel implementations such as BigQuery, Trino and to some extent DuckDB. And what about adding a CUDA backend?

But all this comes at a cost and needs to be planned so it is only used when needed.

I studied prolog back in 2014. It was used in AI course. I found it very confusing: trying to code A*, N-Queens, or anything in it was just too much. Python, in contrast, was a god-send. I failed the subject twice in my MSc (luckily passing the MSc was based on the total average), but did a similar course in UC Berkeley, with python: aced it, loved it, and learned a lot.

Never again :D