I did come across terminusdb: https://github.com/terminusdb/terminusdb which looks interesting.
Any other codebases people would recommend that are worth a read?
https://github.com/dcnorris/precautionary/blob/main/exec/pro...
This Prolog program can be used to exhaustively enumerate all possible arising cases, and also to complete partially given trials. In addition to the specific usage mode of telling the clinician what action to perform next after a sequence of events has occurred, it is also possible to ask interesting questions about the trial design as a whole, such as whether specific cases can arise at all, or whether a specific instance was performed according to the protocol. In this sense, the formulation truly serves as an executable specification of trial designs that are otherwise stated only comparatively informally in the medical literature, and may even be subject to divergent interpretations. The formulation uses Scryer Prolog and the latest Prolog language constructs (such as if_/3 and CLP(ℤ) constraints) to achieve a short and very general description. Such declarative specifications may help considerably to improve safety and efficiency of clinical trials, by making all steps and outcomes amenable to analysis and comparison.
Theorem provers and reasoning engines are also often implemented in Prolog. A recent example is solidarity by Jos De Roo:
https://github.com/josd/solidarity
Prolog is also frequently used for prototyping interpreters. For example, Adrián Arroyo Calle is working on a MIPS simulator written in Prolog:
https://github.com/aarroyoc/mipsie
Simon Forman has implemented a Prolog interpreter of Joy in which, remarkably, the declarative description also serves as a type inferencer and type checker:
https://git.sr.ht/~sforman/Thun/tree/master/item/source/thun...
Porting this code to Scryer Prolog could be an interesting project if it appeals to you. There is already an issue for it and pertaining discussion:
toilet is a slightly more modern reimplementation with some added features (like color): http://caca.zoy.org/wiki/toilet
Echoing what triska said, CLP(ℤ) and friends are some of the most under-appreciated aspects of prolog implementations.
I'm amazed that programmers still don't have access to CLP when trying to do scheduling and planning solutions.
As an example in practice, what if you want to know about a transaction in which a number of entities transitively had holdings in one of the beneficiaries of the transaction at that particular time. The date window is not known, and the date windows are important in the ownership chain as well as the transactions that are being undertaken.
With CLP(FD) you can ask for a window of time, and the solution will zoom in on an appropriate time window which exists for the entire chain and match the time of the transaction.
Now try to do this query in SQL. It's almost impossibly hard.
I can't wait until I have the time to implement constraint variables for TerminusDB, but at the minute we are still working on more prosaic features.
Aside from that there are very interesting program correctness and optimisation systems which are based on prolog (usually a datalog). For instance Soufflé: https://souffle-lang.github.io
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.
Is anyone aware of any higher level abstractions for logic based languages that is actually used in industry? From what I’ve seen in the various banks and fintech groups I’ve worked with, prolog itself was very rarely if ever used ‘in anger’, but I have heard of it being used for automation so I’m very curious what that looks like.
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.I used to be a specialist in a product called Tivoli Enterprise Console. Which was a late 90s/2000s era event correlation system that used an ancient prolog dialect as its rules engine.
I had an awesome boss who let me do whatever, a limited set of tools, and a partner in crime who complemented my style. So we ended up implementing an Oracle database interface in Perl and a client application that allowed others to add facts to the database. Periodically, we’d load the facts into the prolog system and could make queries to tell us what apps were impacted, did we care about them, who was responsible, etc.
The end system was able to identify app owners, system administrators and other information on any of about 20k servers and lots of network gear. We were able to take a flow of about 300k daily events and cook it down to about 40-50 actionable alerts and a few hundred automated actions.
The whole thing took about 3 months to build and another 4-6 to tweak. We got promoted and moved on, but the system hummed along for about 4-5 years until IBM started killing the underlying product. I think the place pivoted that functionality to ServiceNow.
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.
I'm using picat, a better Prolog dialect, and generate the facts automatically from C to generate the field layouts via picat automatically.
https://github.com/LibreDWG/libredwg/blob/master/examples/AC...
optimization problems as in compilers are extremely natural in Prolog.
I 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.
The send_display_vehicle_id(Id) in the end actually does a lot, it queries redis for previously announced display type devices, then looks up the capabilities (bit depth, resolution) of each device and formats accordingly then sends the display request for each. Also send_android_notification sends the request to some Java code that initiates a push message to my phone and watch.
None of this is rocket science in terms of Prolog message(MQTTPathAsList, MessageBody) is my general predicate for handling an incoming MQTT message once I've subscribed to it and it's convenient to deal with a MQTT topic path as a list.
message(['Smarthome','Notify', 'vehicle','motion'],_):- log('brain saw vehicle motion'), get_short_timestamp(S), atomic_list_concat([S, ' Vehicle Motion'], NotificationMessage), send_android_notification('Smarthome', NotificationMessage), request_image('alibi4').
request_image(Camera) :- publish(['Smarthome', 'Video', Camera, 'brain', 'request']).
message(['Smarthome','Video', _ ,'brain','response'],Image):- store_image(Image, 'brain'), analyze_image(Image, 'brain').
analyze_image(Image, Id) :- publish(['Smarthome', 'Sighthound', 'analyze', Id], Image).
message(['Smarthome','Vehicle', 'Sighthound'],VehicleJson):- vehicle_id(VehicleJson, Id), get_short_timestamp(S), atomic_list_concat([S, ' brain saw vehicle: ', Id], NotificationMessage), send_android_notification('vehicle', NotificationMessage), send_display_vehicle_id(Id), atom_concat(Id, VehicleJson, Description), atom_concat('brain saw vehicle: ', Description, Message), log(Message).
I have one other Prolog project that is part of a tool. It explains the relationship between potentially related people. It is used in financial surveillance.
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?
https://github.com/hsk/bulletpl/blob/master/bulletpl/1943_ro...
It is a movement of the rolling fire of CAPCOM shooting game 1943.
Original Bullet ML DSL is XML base, however this version base Edinburgh Prolog format.
Cheers Hans
https://github.com/rug-compling/Alpino
Even in the age of neural parsers, it's still one of the most competitive parsers for Dutch.
As part of a knowledge systems course we built a small game in (mostly) Prolog
Some interesting applications of Prolog specifically include using predicates to filter messages by certain criteria (e.g. if it was sent by the bot's account or not), being able to hot-reload by invoking the make/0 predicate, and homoiconicity to (in theory) easily evaluate random code supplied by a user.
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 to do unless you're very comfy with recursion.
In Prolog the solution is basically (pseudocode):
100 = a*50 + b*25 + c*10 + d*5 + e*1
and Prolog will just figure out all possible combinations for you.The challenge with Prolog as far as I understand is making things fast.
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]]) :- use_module(library(clpfd)).
main :-
100 #= H*50 + Q*25 + D*10 + N*5 + P*1.
That's it.[0] https://github.com/hbrouwer/dfs-tools [1] https://www.sciencedirect.com/science/article/pii/S089054012...
prolog looks like a third way, not C and not Lisp.
eval(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
It's a pretty wild concept, and there are tons of cool examples of what Prolog can do. Some examples are:
- A solver for Suduko puzzles: https://rosettacode.org/wiki/Sudoku#Prolog
- A simple game where you guess a person's age: https://rosettacode.org/wiki/Guess_the_number#Prolog
- A family tree program: https://rosettacode.org/wiki/Family_tree#Prolog