SWI-Prolog and Unicode.

Submitted by Greg Buchholz
on February 15, 2007 - 2:17pm

% fun with SWI-Prolog and Unicode.  Try some queries like... 
% Ans ≔ ∫x d x.
% Ans ≔ ∫ 2 + x^3 d x.

:- encoding(utf8).
:- op(699, xfy,).
:- op(600, fx,).
:- op(510, xfx, d).
:- op(200, xf, ²).

A+B ≔ ∫ Y+Z d X :- A ≔ ∫ Y d X, B ≔ ∫ Z d X. 
C*A ≔ ∫ C*Y d X :- free(C,X), A ≔ ∫ Y d X.
C*X ≔ ∫ C d X   :- free(C,X).
X² / 2 ≔ ∫ X d X.
X^N1/N1 ≔ ∫ X^N d X :- free(N,X), N =\= -1, N1 is N + 1. 
(log(A*X+B)/A) ≔ ∫ 1/(A * X + B) d X :- free(A,X),free(B,X).
(exp(A*X+B)/A) ≔ ∫ exp(A*X+B) d X    :- free(A,X), free(B,X).E d X ≔ ∫ E d X.

free(C,X) :- \+ bound(C,X).

bound(X,X).
bound(A+B,X) :- bound(A,X); bound(B,X).
bound(A-B,X) :- bound(A,X); bound(B,X).
bound(A*B,X) :- bound(A,X); bound(B,X).
bound(A/B,X) :- bound(A,X); bound(B,X).
bound(A^B,X) :- bound(A,X); bound(B,X).