Ask HN: What are some interesting examples of Prolog?
51–60 of 64 posts
Re: Ask HN: What are some interesting examples of Prolog?
#52Here's an example for a problem that's moderately difficult to do recursively, hard to do iteratively, and trivial in Prolog: Given that you have the following coins, 1¢ (i.e. 1 cent or $0.01), 5¢, 10¢, 25¢, 50¢, how many different ways are there to give change for a dollar? For example, one way would be to give 2x50c, another would be to give 100x1c. How many are there total? In most languages this is not super easy…
:- use_module(library(clpfd)).
main :-
100 #= H*50 + Q*25 + D*10 + N*5 + P*1.
That's it.Re: Ask HN: What are some interesting examples of Prolog?
#53eval(E1+E2,I):- eval(E1,I1),eval(E2,I2), I is I1+I2.
eval(E1E2,I):- eval(E1,I1),eval(E2,I2), I is I1I2.
:- eval(12+34,R),writeln(R),R=14.
:- halt.
Very simple Operational Semantics.
this mean
syntax
e ::= i | e+e | e * e
evaluation rule
-------------- (E-Int)
i1-->i1
e1-->i1 e2-->i2
i is i1+i2
------------------- (E-Plus)
e1+e2 --> i
e1-->i1 e2-->i2
i is i1i2
------------------- (E-Times)
e1*e2 --> i
Re: Ask HN: What are some interesting examples of Prolog?
#54You could look at "PRESS: PRolog Equation Solving System", "a system for solving symbolic, transcendental, non-differential equations." Journal of Symbolic Computation Volume 7, Issue 1, January 1989, Pages 71-84 "Solving symbolic equations with PRESS" https://www.sciencedirect.com/science/article/pii/S074771718... Source: https://github.com/maths/PRESS - - - - BTW, Does anyone know where I can find the source for MI…
Re: Ask HN: What are some interesting examples of Prolog?
#55What’s the best way to get started with Prolog on macOS? Implementations, editors, etc?
Re: Ask HN: What are some interesting examples of Prolog?
#56Not exactly a big codebase, but it was a revelation for me how natural typecheckers can feel in Prolog: I basically rewrote typing rules with some tweaks: [1] Also, tests were surprisingly enjoyable in Prolog: [2]. [1] https://github.com/EarlGray/language-incubator/blob/29755c32... [2] https://github.com/EarlGray/language-incubator/blob/29755c32...
Not a criticism of the code here by any stretch, I always find it impressive when people manage to understand languages that are totally foreign to me, that being said however Prolog has always struck me as uniquely unreadable. Even back in university when we looked briefly at different styles of programming, the code always ended up looking something like lines 107-132 in your example, which to someone jumping in is…
I agree that this piece of code was written in a more academic mindset, with large dose of TAPL-specific jargon and abbreviations which can easily throw anybody off if not known beforehand. I do not have good examples of industrial-grade Prolog code bases, if that's what was asked.
Re: Ask HN: What are some interesting examples of Prolog?
#57You could look at "PRESS: PRolog Equation Solving System", "a system for solving symbolic, transcendental, non-differential equations." Journal of Symbolic Computation Volume 7, Issue 1, January 1989, Pages 71-84 "Solving symbolic equations with PRESS" https://www.sciencedirect.com/science/article/pii/S074771718... Source: https://github.com/maths/PRESS - - - - BTW, Does anyone know where I can find the source for MI…
The author has a linkedin account in Sweden, I would message them directly.
Re: Ask HN: What are some interesting examples of Prolog?
#58One of the most interesting applications of Prolog I have seen in the recent past is the formalization of dose-escalation trial designs that occur in clinical oncology. In particular, David C. Norris has implemented a Prolog formulation of the cumulative cohort design (CCD) as part of his precautionary package: https://github.com/dcnorris/precautionary/blob/main/exec/pro... This Prolog program can be used to exhausti…
Wow this is the best thing since the Actually Portable Executable source code. https://justine.lol/thun.png How did the author generate those letters?
Re: Ask HN: What are some interesting examples of Prolog?
#59Here's an example for a problem that's moderately difficult to do recursively, hard to do iteratively, and trivial in Prolog: Given that you have the following coins, 1¢ (i.e. 1 cent or $0.01), 5¢, 10¢, 25¢, 50¢, how many different ways are there to give change for a dollar? For example, one way would be to give 2x50c, another would be to give 100x1c. How many are there total? In most languages this is not super easy…
from ortools.sat.python.cp_model import *
m = CpModel()
a, b, c, d, e = [m.NewIntVar(0, 100, '') for _ in range(5)]
m.Add(a*50 + b*25 + c*10 + d*5 + e*1 == 100)
s = CpSolver()
s.Solve(m)
print([s.Value(x) for x in [a, b, c, d, e]])Re: Ask HN: What are some interesting examples of Prolog?
#60Not exactly a big codebase, but it was a revelation for me how natural typecheckers can feel in Prolog: I basically rewrote typing rules with some tweaks: [1] Also, tests were surprisingly enjoyable in Prolog: [2]. [1] https://github.com/EarlGray/language-incubator/blob/29755c32... [2] https://github.com/EarlGray/language-incubator/blob/29755c32...
I have rewritten all TAPL code in Prolog. It was very interesting.
https://github.com/mitsuchi/copl-in-prolog/
This is another textbook "Concept of Programming Language" implementations.