Ask HN: What are some interesting examples of Prolog?
11–20 of 64 posts
Re: Ask HN: What are some interesting examples of Prolog?
#12 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 MIXTUS partial evaluation system?
Re: Ask HN: What are some interesting examples of Prolog?
#13There exists a formulation of the Japanese Constitution in Prolog, which can then be called with a proposition to determine its constitutionality.
Re: Ask HN: What are some interesting examples of Prolog?
#14One 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…
Re: Ask HN: What are some interesting examples of Prolog?
#15Not 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...
Re: Ask HN: What are some interesting examples of Prolog?
#16One 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?
#17Not 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…
type(Ctx, case(T0, {z, Tz}, {s(V), Ts}), Ty) :- !,
isvar(V),
type(Ctx, T0, nat),
type(Ctx, Tz, Ty),
CtxS = [{V, nat} | Ctx], type(CtxS, Ts, Ty).
type(Ctx, case(T0, {inl(Vl), Tl}, {inr(Vr), Tr}), Ty) :- !,
isvar(Vl), isvar(Vr),
type(Ctx, T0, uni(Ty1, Ty2)),
Ctx1 = [{Vl, Ty1} | Ctx], type(Ctx1, Tl, Ty),
Ctx2 = [{Vr, Ty2} | Ctx], type(Ctx2, Tr, Ty).
It is clear that the two clauses are mutually exclusive if the second argument is known, because they differ in various terms already in the head. For instance, {z, Tz} is clearly different from {inl(Vl), Tl}. A Prolog system with deep indexing, which is also used by Mercury, can detect this, and in such a system, we can therefore remove the two occurrences of !/0 in the code, yielding a more general and shorter version: type(Ctx, case(T0, {z, Tz}, {s(V), Ts}), Ty) :-
isvar(V),
type(Ctx, T0, nat),
type(Ctx, Tz, Ty),
CtxS = [{V, nat} | Ctx], type(CtxS, Ts, Ty).
type(Ctx, case(T0, {inl(Vl), Tl}, {inr(Vr), Tr}), Ty) :-
isvar(Vl), isvar(Vr),
type(Ctx, T0, uni(Ty1, Ty2)),
Ctx1 = [{Vl, Ty1} | Ctx], type(Ctx1, Tl, Ty),
Ctx2 = [{Vr, Ty2} | Ctx], type(Ctx2, Tr, Ty).
The isvar/1 tests can be removed if we use a better representation of our data. For instance, if we use the wrapper v/1 to denote variables in the data, we can replace these clauses by: type(Ctx, case(T0, {z, Tz}, {s(v(V)), Ts}), Ty) :-
type(Ctx, T0, nat),
type(Ctx, Tz, Ty),
CtxS = [{V, nat} | Ctx], type(CtxS, Ts, Ty).
type(Ctx, case(T0, {inl(v(Vl)), Tl}, {inr(v(Vr)), Tr}), Ty) :-
type(Ctx, T0, uni(Ty1, Ty2)),
Ctx1 = [{Vl, Ty1} | Ctx], type(Ctx1, Tl, Ty),
Ctx2 = [{Vr, Ty2} | Ctx], type(Ctx2, Tr, Ty).
Finally, the variables CtxS, Ctx1 and Ctx2 are only used once each, so we can simply write: type(Ctx, case(T0, {z, Tz}, {s(v(V)), Ts}), Ty) :-
type(Ctx, T0, nat),
type(Ctx, Tz, Ty),
type([{V, nat} | Ctx], Ts, Ty).
type(Ctx, case(T0, {inl(v(Vl)), Tl}, {inr(v(Vr)), Tr}), Ty) :-
type(Ctx, T0, uni(Ty1, Ty2)),
type([{Vl, Ty1} | Ctx], Tl, Ty),
type([{Vr, Ty2} | Ctx], Tr, Ty).
With the necessary provisions in place, it may be possible to shorten it further, by generating such code automatically from more declarative descriptions, using a mechanism called term expansion which is available in most Prolog systems. It is analogous to what other languages such as Rust call macros.Re: Ask HN: What are some interesting examples of Prolog?
#18One 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?
toilet is a slightly more modern reimplementation with some added features (like color): http://caca.zoy.org/wiki/toilet
Re: Ask HN: What are some interesting examples of Prolog?
#19Re: Ask HN: What are some interesting examples of Prolog?
#20I don't distribute the home automation code however it's pretty specific to my house. The MQTT library provides some building block examples.
You can also see some other comments I've made on HN which describe some other details.