4 ms·
When I tried out Prolog, I was struck by the inelegance of is/2. There has to be something like it, because no one knows how to write an interpreter for a
by thisrod 10y ago
When I tried out Prolog, I was struck by the inelegance of is/2. There has to be something like it, because no one knows how to write an interpreter for
arcsin(X,Y) :- sin(Y,X).
However, MetaPost can do that for linear expressions. You can say (in Prolog syntax)
midpoint(X,Y,Z) :- Z == (X+Y)/2.
two(X) :- midpoint(0,X,1).
And the MetaPost interpreter will find the solution two(2).
Does anyone know of Prolog extensions that can solve linear algebra problems like that?
- colanderman 10y agoSWI-Prolog has CLP extensions to do exactly that: http://www.swi-prolog.org/pldoc/man?section=clp http://www.swi-prolog.org/pldoc/man?section=clp ?- use_module(library(clpq)). midpoint(X, Y, Z) :- {Z =:= (X+Y)/2}. two(X) :- midpoint(0, X, 1). does what you want.
- thisrod 10y agoThank you. It's a relief to know that I don't need to invent it.