←back to thread

Use Prolog to improve LLM's reasoning

(shchegrikovich.substack.com)
232 points shchegrikovich | 1 comments | | HN request time: 0s | source
Show context
z5h ◴[] No.41873798[source]
i've come to appreciate, over the past 2 years of heavy Prolog use, that all coding should be (eventually) be done in Prolog.

It's one of few languages that is simultaneously a standalone logical formalism, and a standalone representation of computation. (With caveats and exceptions, I know). So a Prolog program can stand in as a document of all facts, rules and relations that a person/organization understands/declares to be true. Even if AI writes code for us, we should expect to have it presented and manipulated as a logical formalism.

Now if someone cares to argue that some other language/compiler is better at generating more performant code on certain architectures, then that person can declare their arguments in a logical formalism (Prolog) and we can use Prolog to translate between language representations, compile, optimize, etc.

replies(7): >>41874164 #>>41874229 #>>41874594 #>>41874985 #>>41875196 #>>41875236 #>>41876524 #
xelxebar ◴[] No.41875236[source]
> over the past 2 years of heavy Prolog use

Oh, cool. Mind if I pick your brain a bit?

Recently, there was an HN post[0] of a paper that makes a case against pure logic languages in favor of "functional logic" ones, which they exhibit with Curry[1]. The setup argument is that Prolog's specs backtracking, which strongly downlimits it from full SLD resolution, causing fatally sharp edges in real world usage.

Being fairly naive to the paradigm, my interpretation is that writing real Prolog programs involves carefully thinking about and controlling the resolution algorithm, which feels very different than straight knowledge declaration. I believe cut/0 is the go-to example. Is that your experience with Prolog in practice?

The real meat of the paper, however, is in its case that functional logic languages fully embed Prolog with almost 1-to-1 expressivity, while also providing more refined tools for externalizing knowledge about the intended search space of solutions.

Thoughts? How are you using Prolog, logic, or constraint programming? What languages and tooling in this arena do you reach for? What is some of your most hard-earned knowledge? Any lesser-known, but golden, websites, books, or materials you'd like to share?

Cheers!

[0]:https://news.ycombinator.com/item?id=41816545

[1]:https://www.curry-language.org/

replies(2): >>41875855 #>>41875988 #
1. z5h ◴[] No.41875988[source]
> What is some of your most hard-earned knowledge?

1. If you find yourself straying too often from coding in relations, and instead coding in instructive steps, you're going to end up with problems.

2. Use DCGs to create a DSL for any high level operations performed on data structures. The bi-directionality of Prolog's clauses means you can use this DSL to generate an audit trail of "commands executed" when Prolog solves a problem for you, but you can also use the audit trail and modify it to execute those commands on other data.