top | item 42035735

(no title)

shawa_a_a | 1 year ago

I would second Prolog as mind-blowing. I've found you're typically confronted with fully engaging with the core of whatever problem you're solving, and only that core. This is probably what can make it so frustrating sometimes as you have no option but to work out the hard stuff nearly immediately; not to mention that unconsidered edge cases, mistakes can cause some pretty opaquely wrong results, or the query not terminating, which can make conventional debugging pretty difficult. The guarantees you get with using the 'pure' core of Prolog do open up some really interesting avenues though, for example Scryer's debugging library is quite neat in affording _semantic_ debugging: https://www.scryer.pl/debug

Just some additional commentary too - I think this post quite misrepresents it with some of the comparisons.

Prolog at its core is SLD Resolution [1] (a form of search) over Horn Clauses [2] (first order logic). Queries posted to the runtime are attempts to find a set of values which will satisfy (cause to be true) the query – whilst SQL is founded on relational algebra which more closely aligned with set theory.

Whilst there's probably some isomorphism between satisfying/refuting a logical predicate, and performing various set operations, I'd say it's a bit of a confusion of ideas to say that SQL is based on 'a subset of Prolog'. The author might be thinking about Datalog [3], which is indeed a syntactic subset of Prolog.

[1]: https://en.wikipedia.org/wiki/SLD_resolution [2]: https://en.wikipedia.org/wiki/Horn_clause [3]: https://en.wikipedia.org/wiki/Datalog

discuss

order

Claudus|1 year ago

I remember learning Prolog, it was tricky to wrap my mind around it, it wasn’t like any other language. The day I finally “got it” I was very happy, until I realized all the other languages I had previously learned, no longer made any sense.

dtjohnnymonkey|1 year ago

I remember taking a PL class in undergrad, learning Prolog as one of a handful of languages. During that section my brain started to want to "bind" variables to things as I was going about my day, it was very weird.

__rito__|1 year ago

What Prolog resources would you recommend for someone to learn it and a blown mind?

tannhaeuser|1 year ago

You can run pure ISO Prolog interactively in your browser on [1]. There's also an extended tutorial for solving toy container logistics problems there ([2]). Though while it doesn't require prior Prolog knowledge, it's not so much a learning resource as it is a teaser and practical guide for using Prolog's built-in combinatorical search for linear planning in the classic STRIPS style (David Warren's WARPLAN being among the earliest Prolog applications apart from NLP).

[1]: https://quantumprolog.sgml.net

[2]: https://quantumprolog.sgml.net/container-planning-demo/part1...

6gvONxR4sf7o|1 year ago

The frustrating thing about prolog is that at first it seems you get to ignore the execution model, but very very quickly you have to learn to think of it in imperative terms anyhow, so you can ensure termination and stuff. Or at least, I never got far enough past that to wrap back around to not coding in it with a background imperative model running in my head.

wodenokoto|1 year ago

Would you recommend prolog over datalog for someone looking for something new that doesn't have to be related to their work in data analytics?

sirwhinesalot|1 year ago

Not the OP but personally I would recommend looking into constraint programming which is related but different to logic programming (Prolog has extensions for Constraint Logic Programming which combines the two).

You mentioned you're looking for something new that doesn't have to be related to data analytics, well constraint programming (and similar) is basically the mirror problem. Instead of data you have the rules of the "game" and the solver's job can be to: find a solution, find the optimal solution, find all solutions, or prove there is no solution.

Things like scheduling problems, resource allocation problems, etc. A real-world example would be finding the most efficient cell placement when developing a microchip, this is basically an advanced rectangle packing puzzle.

Much like prolog you define the rules (constraints) and the solver takes over from there. Part of the fun is figuring out the most effective way to model a real-world problem in this manner.

The closest thing to Prolog in this domain would be ASP, with Clingo/Clasp being the best solver available. But you also have regular constraint programming (look into MiniZinc or Google's OR-Tools), mixed-integer programming which is mainly for hardcore optimization problems (commercial solvers sell for tens of thousands of dollars), satisfiability modulo theories (often used for software verification and mathematical proofs), etc.

The mind-blowing bit is that this sort of problem is NP-complete but these solvers can find solutions to utterly massive problems (millions of variables and constraints) in milliseconds sometimes.

llsf|1 year ago

Same Prolog, and particularly Lambda Prolog literally blew my mind. I could (physically) feel my brain, trying to think differently about the problem to solve. It was an experience. I need to retake that course (was 20 years ago...). I also wonder if/how AI could leverage lambda prolog to prove things.

sirwhinesalot|1 year ago

Also look into ASP for the real mind blowing one. Specially clingo/clasp. Much more powerful than Datalog, can even solve optimization problems without being turing complete.