Live data from Hacker News

Ask HN: What's Prolog like in 2024?

news.ycombinator.com

111–120 of 289 posts

Re: Ask HN: What's Prolog like in 2024?

#111
I think of Prolog as a general purpose logic programming language and Datalog to be logic programming more focused on data analysis. Data analysis is a very large area, so boundary might get blurry at times.

If your data is in a relational database consider Logica - a Datalog family language that compiles to SQL and runs naturally on SQLite, Postgres, DuckDB and Google BigQuery.

Easy to install, easy to play with in CoLab or any other Jupyter notebook.

Works for data analysis (aggregation, filtering etc) that is commonly associated with SQL, as well as recursive logical querries commonly associalted with Logic programming per-se.

Here is what it looks like for a data-analysis-ish query of finding popular baby names over time:

# Count babies per year.

NameCountByYear(name:, year:) += number :- BabyNames(name:, year:, number:);

# For each year pick the most popular.

TopNameByYear(year) ArgMax= name -> NameCountByYear(name:, year:);

# Accumulate most popular name into a table, dropping the year.

PopularName(name: TopNameByYear());

The classic grand-parent rule looks as usual:

Grandparent(a, c) :- Parent(a, b), Parent(b, c);

Here is a recursive program for finidng distances in a directed graph:

D(a, b) Min= 1 :- Edge(a, b);

D(a, b) Min= D(a, x) + D(x, b);

Links to CoLabs:

Grandparent, ancestor: https://colab.research.google.com/drive/1lujnnUOXsF6VrC9__jV...

Distance in graph:

https://colab.research.google.com/drive/1sOCODHqN0ruxZSx_L-V...

Github repo: https://github.com/EvgSkv/logica

Re: Ask HN: What's Prolog like in 2024?

#112
post #69

Earlier quoted context omitted.

Prolog and Datalog example (they are identical in this case) % Facts parent(john, mary). parent(mary, ann). parent(mary, tom). % Rules ancestor(X, Y) :- parent(X, Y). ancestor(X, Z) :- parent(X, Y), ancestor(Y, Z). % Query ?- ancestor(john, X). The Prolog code looks identical to Datalog but the execution model is different. Prolog uses depth-first search and backtracking, which can lead to infinite loops if the rules…

> Prolog uses depth-first search and backtracking, which can lead to infinite loops if the rules are not carefully ordered Is this an issue in practice? Most languages can create programs with infinite loops, but it's easy to spot in code reviews. It's been over a decade since I encountered an infinite loop in production in the backend. Just wondering if the same is true for Prolog.

Here's an infinite loop in Prolog, getting the length of a list:

    length(List_of_animals, Len)
Oops, List_of_animals hasn't been bound to any value, so length/2 will backtrack forever making it a longer and longer list of empty placeholders. Nothing will warn you that the variable wasn't declared because that's also a normal thing to do. Here's another, checking if something is in a list:

    member(cat, List_of_animals)
same problem, if the list isn't grounded to a fixed length list by the time this line executes, backtracking will generate longer and longer lists with `cat` in them and lots of placeholders:

    [cat]
    [_, cat]
    [_, _, cat]
    ...
forever. It's not just that you can accidentally write an infinite for(;;) loop by typoing the exit condition, it's that a lot of things in Prolog can be used in ways which finish deterministically or in ways that act a bit like Python generators yielding endless answers. So it's about the context in which you call them, and the surrounding code. e.g. one reason you're using Prolog is that you want it to generate List_of_animals for you (making up fictional animal names, or something), so you can't look for a missing `List_of_animals = [...]` because there might not be one anywhere.

Re: Ask HN: What's Prolog like in 2024?

#113

Earlier quoted context omitted.

How do you normally use Prolog and Python together? I had looked into embedding logic programming within Python in the past, and found a lack of satisfying options, but maybe I didn't know where to look.

I have two short examples in one of my books that I am currently re-writing. Here is a link directly to the Python+ Prolog interop examples https://leanpub.com/pythonai/read#use-predicate-logic-by-cal...

Thanks for the link. I have played with PySwip (https://github.com/yuce/pyswip), and the MQI looks like a more maintainable approach to integrating SWI-Prolog with Python (https://github.com/SWI-Prolog/packages-mqi).

The biggest source of friction I noticed when playing with PySwip was that because Prolog code was represented as strings, you avoided generating it on the fly. It would be nice to have an embedded DSL for Prolog in Python. (I am thinking something like SymPy or the Pony ORM—https://github.com/ponyorm/pony.)

Re: Ask HN: What's Prolog like in 2024?

#114
post #103

Earlier quoted context omitted.

There are some benchmarks here of SWI Prolog's benchmark suite on diffrent Prolog systems by Jan Wielemaker the SWI Prolog author: https://swi-prolog.discourse.group/t/porting-the-swi-prolog-... He finds Scryer performs worse, which he does comment on, he also explains some tradeoffs and historic choices in SWI's design which affects its performance. I think I have seen the author of Scryer saying that's not surprisi…

So SWI appears to be more performant, it has an open license, so as per the GGP's claim regarding Scryer in the post above, it must not be ISO-compliant?

[deleted]

Re: Ask HN: What's Prolog like in 2024?

#115
Not exactly a prolog, but Verse, a logical (and functional, or functional logic) programming language developed at Epic Games by Simon Peyton Jones of Haskell fame and Tim Sweeney. You can already use it to build mods for fortnite or something like that not really sure. But there's no open source compiler available yet.

Re: Ask HN: What's Prolog like in 2024?

#116
What is it like? 50 years of historic cruft. Questionable whether there are more trip hazards than usefulness for ordinary coding. A fractured community which feels like there are more Prolog systems than Prolog code. Learning Prolog is less "how do I do things in Prolog" and more "how do I contort my things to avoid tripping over Prolog?".

A few dedicated clever people and idealists and dreamers talking about ontologies and building things I don't understand, e.g. the link in https://news.ycombinator.com/item?id=40994780 that could either be genuinely "Prolog is suitable for things no other language is" or "Fusion is 10 years away" or "Perpetual motion is here and so is cold fusion!", I can't tell. But I suspect from the lack of visible activity out in the wider world, closer to the latter than the former. Or perhaps the people able to make use of its strengths are few and far between.

There's a saying about driving to a town which has been hollowed out and is now a road through some empty store fronts and car parks: "there's no there there". The soul of a place is missing, it's no longer a destination, just some buildings on some land. Prolog has the opposite of that, a main road straight past it, few buildings or people, but there is a there there - an attractor, spark of something interesting and fun. Buried in years of cruft. Might be a Siren's call though, a trap - but if it is it appears less dangerous than the LISP one.

Re: Ask HN: What's Prolog like in 2024?

#117

Earlier quoted context omitted.

The problem w/ OWL is that everybody wants to work with first-order logic + math, but Gödel proved it isn't decidable. For instance if I wanted to express financial regulations or business rules inside a bank or other business I'd need to use math: for instance to express the conditions for reserve requirements or approving a loan. OWL is best thought of as a set of templates for generating first-order logic rules th…

> Gödel proved it isn't decidable. He did no such thing. He proved undecidable problems exist in any system powerful enough to be useful. That doesn’t make those systems useless, though.

The trouble is the creators of OWL wanted to have performance and reliability bounds. That is, they want to make systems that act like more like a conventional database server than an SMT solver.

I think they could have made a more expressive standard and something like that might have had more appeal to people but been less consistent in terms of performance.

Re: Ask HN: What's Prolog like in 2024?

#118
post #25

Not sure about Prolog itself but Datalog really needs to overtake SQL, it's just so much better. Related areas like constraint programming are still very relevant.

Could you explain more or point out some interesting references? I'm currently trying to understand how Datalog compares to SQL and, potentially GraphDBs

Mangle is a language that includes "textbook datalog" as a subset https://github.com/google/mangle ; like any real-world datalog language, it extends datalog with various facilities to make it practical.

It was discussed on HN https://news.ycombinator.com/item?id=33756800 and is implemented in go. There is the beginnings of a Rust implementation meanwhile.

If you are looking for datalog in the textbooks, here are some references: https://github.com/google/mangle/blob/main/docs/bibliography...

A graph DBs short intro to datalog: just like the edges of a graph could be represented as a simple table (src, target), you could consider a database tuple or a datalog or prolog fact foo(x1, ..., xN) as a "generalized edge." The nice thing about datalog is then that as one is able to express a connections in an elegant way as "foo(...X...), bar(...X...)" (a conjunction, X being a "node"), whereas in the SQL world one has to deal with a clumsy JOIN statement to express the same thing.

Re: Ask HN: What's Prolog like in 2024?

#119

The "magic" of Prolog is built upon two interesting concepts : Unification ( https://en.wikipedia.org/wiki/Unification_(computer_science)... ) and Backtracking ( https://en.wikipedia.org/wiki/Backtracking ). Often bad teachers only present the declarative aspect of the language. By virtue of being declarative, it allows to express inverse problems in a dangerously simple fashion, but doesn't provide any clue for a so…

> The continuous equivalent in a sort of unification is Rao-Blackwellisation (done automagically by deep-learning from its training experience) which allows to pick the right associations efficiently kind of the same way that a "most general unification algorithm" allows to pick the right variable to unify the terms.

I don't know how to reconcile this statement about deep learning with my understanding of Rao-Blackwell. Can you explain:

- what is the value being estimated?

- what is the sufficient statistic?

- what is the crude estimator? what is the improved estimator?

Roughly, I think sufficient statistics don't really do anything useful in deep learning. If they did, they would give a recipe for embarassingly parallel training that would be assured to reach exactly the same value a fully sequential training. And from an information geometry perspective, because sufficient statistics are geodesics, the exploratory (hand-waving) and slow nature of SGD could be skipped.

Re: Ask HN: What's Prolog like in 2024?

#120
post #103

Earlier quoted context omitted.

So SWI appears to be more performant, it has an open license, so as per the GGP's claim regarding Scryer in the post above, it must not be ISO-compliant?

That's right; comedian Emo Phillips had a bit about it: "Once I saw this guy on a bridge about to jump. I said, "Don't do it!" He said, "Nobody understand me." I said, "What's so special about you?" He said, "I'm a computer guy." I said, "Me too! Desktop, tablet, console, smartphone?" He said "Desktop, mostly", I said "Me, too! Mac, Linux or Windows?" He said, "Any, I'm a programmer." I said, "Me, too! which style? O…

I can't help.

> "Once I saw this guy on a bridge about to jump. I said, "Don't do it!" He said, "Nobody understand me." I said, "What's so special about you?"

He said: "I don't want to jump".

Post reply on HN