% beta.pl
% simple beta distributions (0 <= x <=1, mean=B)
% only B = 0.1, 0.2, 0.3, ... 0.9, 1 is supported

:- ensure_loaded(ranf).
:- arithmetic_function(beta/1).

beta(B,X) :- beta1(B,X),!.
beta(B,X) :- B1 is 1 - B, beta1(B1,Y),X is 1 - Y.

% the following tricks came from a statistics
% guy who did the algebra and showed me some
% tricks for quickly generating beta vars using
% fractional powers.
beta1(0.50,X) :- X is ranf.
beta1(0.60,X) :- X is ranf^0.67.
beta1(0.67,X) :- X is ranf^0.5.
beta1(0.75,X) :- X is ranf^0.33.
beta1(0.80,X) :- X is ranf^0.25.
beta1(0.9,X)  :- X is ranf^(1/9).
beta1(1,1).