So this is just unification .. (thanks mbratch and checkmate for explanation)
This is how I solve my initial problem and thus makes my code more readable using self-imposed math functions:
:- op(900, xfy, <-). R <- log2(Y) :- R is log(Y)/log(2), !. % the two predicates below solves the problem with using mathematical operators % together with self defined functions note that they should always be last % R <- X :- compound(X), X =..[OP, X2, X3], R2 <- X2, R3 <- X3, Expr =..[OP, R2, R3], R is Expr, !. R <- X :- R is X, !.
then I can write:
?- X <- log2(8). X = 3.0.
and, in addition, the last two predicates allow you to write compounds such as:
?- X <- 17*log2(8) - 2. X = 49.0.
Please note that you are not allowed to mess with is / 2, and therefore I kind of cancel it, using my own <- operator instead
EDIT: added the syntactic sugar suggested by the mat, and added two predicates that fix problems when using the newly defined log2 in combination with other mathematical operators
source share