News for hackers. Stuff that matters.
Re:Why did Prolog lose steam? (2010) by eslaught on Wednesday April 19, 2023 @12:36AM (#35624279)
If you're trying to solve boolean satisfiability, you want a SAT solver, not Prolog.

If you're trying to solve more general problems, you probably want an SMT solver or other more specific solver (e.g., ILP), not Prolog.

If you're trying to verify software, you want a theorem prover, not Prolog.

If you want database-ish stuff you want Datalog (or something like it), not Prolog.

Prolog falls into the uncanny valley of being too general of a DSL for the sorts of optimizations that more narrow solvers enjoy, while being too narrow of a DSL for most general-purpose programming. I think because it was an early DSL, people got caught up in the idea of it being more "high-level" than other languages [1], but the DSL nature of it wasn't fully appreciated at the time.

[1]: For fun, take a read through https://en.wikipedia.org/wiki/Fifth-generation_programming_l... , which was a whole thing in the 1980s.

Re:Why did Prolog lose steam? (2010) by jjtheblunt on Wednesday April 19, 2023 @12:48AM (#35624345)
above is a fantastic lucid comment (not kidding)
Re:Why did Prolog lose steam? (2010) by usgroup on Wednesday April 19, 2023 @01:25AM (#35624554)
I don’t think those are the problems since all sorts of solvers ship with prolog and it’s still a better way to write down a problem.

I think it’s biggest headwind is that you have to be significantly more intelligent than the average developer to think in Prolog.

Prolog requires you to think about code as the implication of constraints — you just have to keep a lot more in your head. Prolog also requires you to understand the execution model before you can do much of anything.

Re:Why did Prolog lose steam? (2010) by nerdponx on Wednesday April 19, 2023 @01:50AM (#35624690)
What about Prolog as an embedded constraint-solving engine inside an application written in some other host language?
Re:Why did Prolog lose steam? (2010) by usgroup on Wednesday April 19, 2023 @02:12AM (#35624814)
I think embedding Prolog is a common use case for it, but I think “constraint solver” is the wrong metaphor.

Use Prolog to “reason about X”, is closer to the gist.

Re:Why did Prolog lose steam? (2010) by discarded1023 on Wednesday April 19, 2023 @02:42AM (#35625010)
> Prolog also requires you to understand the execution model before you can do much of anything.

This is true of most (all?) languages. Prolog's control flow is ultimately not too different from the usual stack-based semantics people are used to from imperative languages like C (if you're not too ambitious with the backtracking; if you are, best of luck!). The tricky part is perhaps understanding the dataflow that arises from unification. That can be arbitrarily complex but it seems people tend to go no further than difference structures, which are easy to comprehend in terms of pointers. (Yes yes I know, but logic variables are essentially just single-assignment pointers.)

The thing I find deeply weird about the logic programming literature is that if you want to reason about your program you're told to use things like Hoare logic [1] or intended interpretations [2] and not fundamental logical concepts like implementations implying specifications (ala Lamport and many others who grappled with refinement).

[1] see Krzysztof Apt's papers

[2] see e.g. https://people.eng.unimelb.edu.au/lee/papers/dd.html

Re:Why did Prolog lose steam? (2010) by usgroup on Wednesday April 19, 2023 @03:46AM (#35625480)
> This is true of most (all?) languages.

Well no, I’d go as far as to say that your average JS/Python dev will know very little about how their code is executed — and doesn’t need to know necessarily. SQL on the other hand is a different story . Noobs don’t know , but pros know and consider the execution graph of a query.

You don’t really have a choice in Prolog —- gotta know what the interpreter is doing from the beginning otherwise you can’t debug.

Re:Why did Prolog lose steam? (2010) by felixyz on Wednesday April 19, 2023 @05:06AM (#35626001)
It't just that everyone has the execution model of imperative languages so internalized, we mostly don't think about it. Same with OO semantics, not to mention various JS pitfalls - they are second nature to enough people that they count as nature-given, but one false move and they come back to bite you.
Re:Why did Prolog lose steam? (2010) by convolvatron on Wednesday April 19, 2023 @12:01PM (#35629834)
It’s worth pointing out that the semantics of prodcedural programs tend to be pairwise, while coaxing the prolog solver to terminate is a more global, transitive problem
Re:Why did Prolog lose steam? (2010) by discarded1023 on Wednesday April 19, 2023 @06:15AM (#35626398)
I don't disagree with your stance but one of the most beautiful things to come from this line of work was Ehud Shapiro's declarative debugging [1]. I'd recommend taking a look at his PhD thesis if you're at all interested in what logic programming can do (that nothing else can [2]). You can also see it as a philosophical exercise: he shows how we might understand Popper's falsification criterion and use it to do science.

[1] Tech report: https://cpsc.yale.edu/sites/default/files/files/tr237.pdf

[2] There have been attempts to build declarative debuggers for other languages but for one reason or another (complexity, space use, incomplete coverage of the language, ...) they don't appear to get used very widely. Shapiro's setup is beautifully simple for what it does.

Here "declarative" means that you have a model in mind ("model" in the sense of logic, i.e., you expect your predicates to hold of particular arguments) and the tool helps you explore the divergence between what you wrote and what you intended. Thinking this way means you can completely ignore the details of SLD-NF resolution (the details of the Prolog implementation)... I mean, it's unlikely to be perfect in practice for any number of reasons, but I find it very disappointing that we don't dream like this any more.

Re:Why did Prolog lose steam? (2010) by usgroup on Wednesday April 19, 2023 @12:19PM (#35630044)
Thank you — this is a nice find.
Re:Why did Prolog lose steam? (2010) by chriswarbo on Wednesday April 19, 2023 @01:40PM (#35631024)
I disagree. A JS/Python developer will have no problem understanding the following example, which makes absolutely no sense without some (operational) semantic model of the code:

  x = x + 1
Re:Why did Prolog lose steam? (2010) by rurban on Wednesday April 19, 2023 @04:08AM (#35625640)
> I think it’s biggest headwind is that you have to be significantly more intelligent than the average developer to think in Prolog.

This is arguably wrong. Thinking in Prolog is much easier than knowing how to solve a problem beforehand. In Prolog you just state the facts and known rules, but you have no clear idea what would be the best way to solve it. Prolog solves it for you then, if possible. No intelligence needed. A "dumb" friend of mine on the 80ies only used Prolog for his work and was very happy with it. Lisp, Pascal or C was too hard for him.

The problem with Prolog is mostly that you'll through too hard problems at it, mostly with exponential complexity. Tiny changes have huge influences then, it either works or not. Also the tabling and SAT/SMT integration sucks.

Re:Why did Prolog lose steam? (2010) by hnfong on Wednesday April 19, 2023 @09:44AM (#35628050)
The problem with your claims is that once you start “debugging”, it gets complicated quickly.

You’ll have to gain an intuition of how the language actually tries so solve the problem under the hood.

sometimes the problem you encounter doesn’t match the capabilities of the language, and then you’ll have to state the problem in a roundabout way to coax the language to do what you intended.

It’s probably great for the small number of toy problems that it was designed to solve, but in my limited experience prolog doesn’t do well on real world problems that have all sorts of edge cases and dirty inputs.

Re:Why did Prolog lose steam? (2010) by forgetfulness on Wednesday April 19, 2023 @11:51AM (#35629705)
You see this often in the data side of things, we delegate very laborious or very complicated tasks to powerful the powerful engines behind Postgres, BigQuery, Spark, and the like, and while they provide you with a high level interface that make common tasks very convenient, mastery can take years as you have to study the architecture and implementation behind them.

It's a huge investment on your end to do that, and people do it readily because the return is being able to process datasets of sizes and complexity that you otherwise wouldn't be able to.

People haven't found it to be a good investment in their time to commit themselves to Prolog's engine.

Re:Why did Prolog lose steam? (2010) by logicmoo on Thursday April 20, 2023 @03:17AM (#35637248)
It wouldn't be surprising if I was your "dumb" friend you are speaking of.

Consider this: Someone who can skillfully create valuable software in Prolog is likely to be highly knowledgeable and capable of programming professionally in other languages like C, Lisp, C#, C++, Scala, Java, Pascal, Python, Assembly, etc.

As a proficient programmer of these languages, I'm often asked to transform my Prolog software into languages like Python, Java, and C#. Even though I have more expertise in those languages compared to Prolog, I still say, "it would be too hard for me to attempt!" Not only would using those other languages for such software be an inefficient use of my time, but if the AI tasks executed in Prolog weren't so intricate, people unfamiliar with Prolog might already be capable of handling them without needing my help.

The dynamic changes and flow control that the software undergoes at runtime would likely be a massive amount of work to implement in those languages. On the few occasions when I or others have actually transformed our software, we often end up writing a Prolog interpreter or compiler in the target language, which then runs our code.

Re:Why did Prolog lose steam? (2010) by logicmoo on Thursday April 20, 2023 @05:28AM (#35637900)
> Thinking in Prolog is much easier than knowing how to solve a problem

> beforehand. In Prolog you just state the facts and known rules,

> but you have no clear idea what would be the best way to solve it.

>

While Prolog streamlines certain aspects of problem-solving due to its declarative nature, it still necessitates a clear understanding of the desired solution and the proper organization of facts and rules. Although Prolog's approach abstracts some implementation details, a well-planned strategy remains essential.

>

> No intelligence needed.

>

Prolog might make some tasks seem simpler, but intelligence and a deep comprehension of logic programming are still needed to efficiently create and maintain solutions.

>

> A "dumb" friend of mine on the 80ies only used Prolog for his

> work and was very happy with it. Lisp, Pascal or C

> was too hard for him.

>

I may be the "dumb" friend you referred to?

Consider this: someone skilled in producing valuable software using Prolog is likely knowledgeable and proficient enough to program professionally in various other languages, such as C, Lisp, C#, C++, Scala, Java, Pascal, Python, Assembly, and more.

As an experienced programmer with a strong background in multiple languages, I often receive requests to translate my Prolog software into languages like Python, Java, or C#. However, I usually decline and claim that "it would be too hard"

Had these tasks not been so daunting, others would have already implemented solutions to them in different languages, and there would be no need for people to continually request my assistance!

>

> The problem with Prolog is mostly that you'll

> throw too hard problems at it, mostly

> with exponential complexity.

>

Prolog isn't inherently prone to exponential complexity problems. The complexity depends on the problem being solved and how the facts and rules are structured. It's crucial to understand the problem domain and optimize the Prolog code accordingly

The complexity of a problem and fluid nature of flow control shifts during software runtime often make it unfeasible to implement the software in alternative languages. So consequently, in the rare instances when I or others have attempted this, we have either developed or found a Prolog interpreter in the target language and executed the original code.

>

> Tiny changes have huge influences

> then, it either works or not.

>

While it is true that small changes can sometimes have significant impacts on the behavior of a Prolog program, this is not unique to Prolog. Any programming language can experience similar issues if the underlying logic is not well-designed or properly tested. It is the developer's responsibility to understand the problem domain and design the logic appropriately to avoid unintended consequences.

>

> Also the tabling and SAT/SMT integration sucks.

>

Tabling is a technique used in Prolog to store intermediate results of a computation to avoid redundant sub-computations, thus improving the efficiency of certain types of queries. While it may have some limitations, it is generally considered a valuable feature of Prolog that can enhance performance for specific types of problems.

Prolog's integration with SAT (Boolean Satisfiability) and SMT (Satisfiability Modulo Theories) solvers is not inherently flawed. Prolog can be used effectively in combination with these solvers to tackle complex problems in various domains. Integrating Prolog with these solvers might require a good understanding of the solver's functionality and the problem domain, but the same can be said for integrating any other programming language with these solvers. It's important to leverage the latest Prolog tools and libraries to optimize these aspects of your program.

Re:Why did Prolog lose steam? (2010) by JimmyRuska on Wednesday April 19, 2023 @12:42PM (#35630311)
Prolog solvers don't necessarily optimize like gurobi, cplex or OR-tools would. Yes they can give you a solution that satisfies the constraints, and you can query for more possible answers, but it doesn't really optimize for the objective function in the same way.
Re:Why did Prolog lose steam? (2010) by logicmoo on Thursday April 20, 2023 @02:44AM (#35637102)
> I think it’s biggest headwind is that you have to be significantly more intelligent than the average developer to think in Prolog.

This is very true!

Re:Why did Prolog lose steam? (2010) by User23 on Wednesday April 19, 2023 @01:35AM (#35624609)
The Norvig AI book really makes its nature as a DSL clear.
Re:Why did Prolog lose steam? (2010) by otabdeveloper4 on Wednesday April 19, 2023 @01:53AM (#35624697)
Solvers are integrated into Prolog nowadays, like the other commenter said.

The real problem is that Prolog doesn't play nice with relational databases. (Too bad the people behind the short-lived NoSQL fad didn't know about Prolog, though.)

Re:Why did Prolog lose steam? (2010) by baq on Wednesday April 19, 2023 @11:54AM (#35629747)
Smuggle a Prolog in YAML somewhere, call it YAMLogic or anything else really which can’t be directly traced to it and watch the kids be amazed at what you can make computers do.

Only about 33% serious here, but… still a bit serious.

Re:Why did Prolog lose steam? (2010) by maweki on Wednesday April 19, 2023 @02:47AM (#35625051)
Prolog being tied to this very specific execution model of SLD resolution is somewhat root to the problems you have described. The promise of declerative programming in general, and logic and constraint programming specifically is, that programs are easier to reason about because the execution model is abstracted away and there's a relatively simple and mathematically pure definition of the model(s) of a program.

But again and again one uses extralogical constructs in Prolog programming.

Case in point: basically all your mentioned alternatives (Datalog, SMT, I'd add ASP) have implementations that use the Prolog syntax or something close to it with very similar semantics. But not being tied to that specific execution model can give you (better) answers or more complete answers, termination guarantees, or other things we might need.

Re:Why did Prolog lose steam? (2010) by usgroup on Wednesday April 19, 2023 @03:58AM (#35625572)
I don’t think is true because ASP is not more popular than Prolog but it is essential (or at least much moreso) declarative.

I think Prologs big strength amongst others is the meta interpreter and higher order functions which I think are essentially tied to SLD.

Re:Why did Prolog lose steam? (2010) by discarded1023 on Wednesday April 19, 2023 @06:28AM (#35626460)
Higher order functions! -- in Prolog! oh my.

Prolog has predicates, not functions. (It has uninterpreted function symbols -- aka functors in this context.) It's based on first-order logic, i.e., it has nothing higher order in it, if you want to take it (formally) seriously. But of course there is `call/1` and so forth, which are just hacks... err, "non declarative".

There are some interesting higher-order logic programming languages, e.g. Mercury. I like the approach taken by HiLog [1] as it struck me as (semantically) honest and simple. I don't know if it's usable.

[1] https://en.wikipedia.org/wiki/HiLog

Re:Why did Prolog lose steam? (2010) by usgroup on Wednesday April 19, 2023 @12:17PM (#35630030)
* Higher order predicates. Prolog has them.
Re:Why did Prolog lose steam? (2010) by YeGoblynQueenne on Wednesday April 19, 2023 @12:41PM (#35630308)
Prolog is not first-order. That's how it's described but it lacks the fundamental distinction between predicate and function symbols that makes First-Order Logic, first-order.

To clarify. A FOL language begins with an "alphabet" (sometimes called a "signature") of predicate symbols, function symbols (including constants), variables, the five logical connectives (¬, ∧, ∨, →, and ↔) and punctuation (left and right parens, comma, dot, colon). The sets of predicate, function and variable symbols are disjoint.

Function symbols are used to define terms, inductively, as follows. A variable is a term; a constant is a term; if f is a function symbol and t_1, ..., t_n are terms, then f(t_1, ..., t_n) is a term.

Terms are used to define formulae as follows: If P is a predicate symbol and t_1, ..., t_n are terms, then P(t_1, ..., t_n) is an atomic formula, or atom. If φ is a formula, then ¬φ is a formula. If φ, ψ are formulae, then φ ∧ ψ, φ ∨ ψ, φ → ψ, and φ ↔ ψ are formulae.

Literals and clauses are defined as follows: if A is an atom, then A is a positive literal and ¬A is a negative literal. A clause is a disjunction of literals. A clause with a single positive literal is definite. A definite clause with no function symbols other than constants is datalog.

Now, if you squint a bit at all of the above and then at a Prolog program you will see a serious violation of the rules of FOL syntax. Observe:

This is Prolog:

  p(x, y):- q(r(x),z), r(p(x,z)).
See? r/1 and p/2 are used both as the symbols of terms and as the symbols of atomic formulae. That is a violation of FOL syntax. What's more, it's a violation of the "first-order" nature of FOL, where functions are "at a lower order" than predicates. That is, in FOL, terms map to entities in the domain of discourse, whereas formulae map to relations over entities in the domain of discourse.

But Prolog doesn't care. Prolog doesn't care if an object is a predicate, or a function, if it's a mapping, or a relation. For Prolog there's no distinction, and because there's no distinction it can treat everything as an argument to everything else: an atomic formula can be "passed" to an atomic formula, and taken apart, and put back together again. For example, you can do this sort of thing:

  ?- T_ =.. [p,X,Y,Z], T =.. [r,T_].
  T_ = p(X, Y, Z),
  T = r(p(X, Y, Z)).
That is no first-order functionality! In fact, in Prolog you can write this sort of thing:

  prove(L):- true.
  prove(L,Ls):- prove(L), prove(Ls).
  prove(L):- L \= (_,_), clause(L,Bs), prove(Bs).
And that is a Prolog interpreter written in Prolog. A program that evaluates programs? Toto, I don't think we're in FOL anymore.
Re:Why did Prolog lose steam? (2010) by discarded1023 on Thursday April 20, 2023 @07:16AM (#35638431)
I don't disagree with what you say here, but ... I'm coming at it from a formal semantics point of view. (I find Prolog and indeed "logic programming" in a larger sense to be all promise and little delivery on this front.) Perhaps you can check if your `prove` example is expressible in HiLog ... if so, it's more-or-less first order (in a semantically clean way). I believe the hard working XSB have an implementation.
Re:Why did Prolog lose steam? (2010) by YeGoblynQueenne on Thursday April 20, 2023 @02:19PM (#35644016)
I don't know that Prolog, or logic programming, makes any promises about formal semantics. I have to say I don't think of Prolog or logic programming in that context. Except for the more general point that Prolog programs are theories, and when a query is executied, that's a theorem being proven.

Btw, I'm not at all complaining about Prolog's higher-order. That may be a "hidden" feature, but it's a really, really useful one. FOL is actually very restrictive in many ways. As far as I understand it, the distinction between first and higher-order logics was not made by Peirce and Frege, who tended to fudge the orders a lot, just like Prolog.

In any case, for me, logic programming begins and ends with Robinson's paper on Resolution. That was not about formal semantics, and only about a sound and complete inference rule. And that (soundness and completeness) is all I really need to know. The rest (including definite clauses, SLD-Resolution and Prolog) is all implementation details.

Re:Why did Prolog lose steam? (2010) by felixyz on Wednesday April 19, 2023 @04:58AM (#35625961)
As I mentioned in another comment, SLG resolution (implemented in XSB Prolog and more recently in SWI-Prolog) does alter the execution model in a way that makes it easier to avoid extralogical constructs. And the wide availability of deeply integrated CLP modules for eg SWI-Prolog also makes it easier to keep programs purely logical.
Re:Why did Prolog lose steam? (2010) by maweki on Wednesday April 19, 2023 @10:11AM (#35628397)
You are correct. Though in my institution we do not get around to teaching that in that one semester of elective LP.
Re:Why did Prolog lose steam? (2010) by YeGoblynQueenne on Wednesday April 19, 2023 @12:22PM (#35630089)
>> Case in point: basically all your mentioned alternatives (Datalog, SMT, I'd add ASP) have implementations that use the Prolog syntax or something close to it with very similar semantics. But not being tied to that specific execution model can give you (better) answers or more complete answers, termination guarantees, or other things we might need.

To clarify, datalog is a restriction of Prolog excluding functions of more than 0 arguments (i.e. constants). For example, P(x,y) :- Q(f(x), g(y)) is Prolog but not datalog. There's also a restriction in the sharing of variables between head and body literals that ensures termination. The point of datalog is that because of its function-free structure it's decidable. You could simply ground a datalog program and get its entire Herbrand model.

SMT, I don't know much about. It's got nothing to do with Prolog, as far as I know. It's not a programming language, but a framework for boolean constraint solving. I don't know why it (or SAT) is compared to Prolog which has nothing to do with boolean satisfiability problems.

ASP also has nothing much to do with Prolog. It's a strictly first-order language (Prolog is higher-order) that is based on the idea of stable model semantics. Very briefly, a stable model is often the set of queries to which Prolog will answer "true" (or "yes" depending on the interpreter). ASP programs share some syntax with Prolog, but are not definite programs. For one thing, ASP allows classical negation, alongside Prolog's Negation-As-Failure. ASP is said to be well-suited to optimisation problems but to me it's more interesting as a formal treatment of reasoning under uncertainty in a strictly logic framework.

Note that datalog is incomplete (obviously, since it doesn't have functions) and ASP solvers are NP-complete. They are also special-purpose languages, so for example nobody is going to write a web server in ASP anytime soon. By comparison, the SWI-Prolog website runs on a web server written in Prolog (https://eu.swi-prolog.org/dogfood.html).

Re:Why did Prolog lose steam? (2010) by chriswarbo on Wednesday April 19, 2023 @01:01PM (#35630560)
> SMT, I don't know much about. It's got nothing to do with Prolog, as far as I know. It's not a programming language, but a framework for boolean constraint solving. I don't know why it (or SAT) is compared to Prolog which has nothing to do with boolean satisfiability problems.

SMT and SAT are certainly less expressive than Prolog (or more abstract systems, like LambdaProlog, Isabelle/HOL, etc.), so they cannot express the same structures/abstractions. However, given any "concrete" query/program, we can collapse all of its structure, in-line/unroll all of its higher-order parts, etc. to get a SAT formula (modulo the halting problem).

The resulting term is usually exponentially-larger than the original; but SAT solvers have become fast enough to handle such giant problems. (SMT solvers are usually wrappers around a SAT solver too)

Re:Why did Prolog lose steam? (2010) by YeGoblynQueenne on Wednesday April 19, 2023 @01:21PM (#35630781)
I think what you're saying is that you can take a Prolog program and ground it all down to the propositional order so you can then evaluate it with a SAT solver. For example, you can take a Prolog clause like this one:

  p(X,Y):- q(X,Z), r(Z,Y)
And ground it in all possible ways with constants in the domain of discourse:

  p(a,b):- q(a,c), r(c,b)
  p(1,3):- q(1,2), r(2,3)
  ... 
And so on, at which point you essentially have propositional formulae, like:

  p1 :- q1, r1
  p2 :- q2, r2
  ... 
etc.

That's what ASP does (except it's not Prolog). But one problem with that is that it doesn't work in a language with functions, because then you get infinite groundings. So for example, ASP doesn't have lists (because you get infinite lists). Prolog does, and you can't just ground any old Prolog program, just like that.

Then again, the motivation behind Prolog's unification is exactly that you don't need to ground the entire Herbrand base of a Prolog program to evaluate it. You can unify variables, until you finally have only ground terms when the proof is complete, but no sooner than that. And of course, you can get a proof before you have only ground terms. So it's really not like SAT solving in my mind (given the very little I understand about SAT solving).

If I understand correctly, the Davis-Putnam algorithm used in SAT solving is based on Resolution in the propositional order, and Prolog is SLD-Resolution, that is a restriction of Resolution to definite clauses which are first-order (though Prolog is not first-order but higher-order as I say in another comment). So that's some common structure, there, but still, they're very different things.

Re:Why did Prolog lose steam? (2010) by maweki on Wednesday April 19, 2023 @02:41PM (#35631759)
> To clarify, ...

sure, that's all true and most of that is part of my day-to-day research. But the post I replied to mentioned very specific problems where Prolog could be suitable at first glance but other models of computation / problem statement are usually preferred.

But most of those do have implementations that use Prolog-like syntax.

Re:Why did Prolog lose steam? (2010) by weinzierl on Wednesday April 19, 2023 @03:52AM (#35625526)
That's a very apt description of where Prolog stands. The niche I see it fit in is as a teaching tool for first-order-logic in computer science (not necessarily math). At least that's how I learned it and I'm glad I did.
Re:Why did Prolog lose steam? (2010) by YeGoblynQueenne on Wednesday April 19, 2023 @12:04PM (#35629868)
Prolog is not a DSL.

Or I guess you can see it as a DSL where the "Domain" is the entire set of programs computable by a Universal Turing Machine. It's a DSL for writing programs that manipulate programs that manipulate programs.

But, not really. It's just not a DSL.