We will encode a mini-AST in Prolog using complex data structures. A "node" will consist of either a nb(Functor,LeftExpr,RightExpr), nu(Functor,Expr) or nn(Number). nb(Functor,LeftExpr,RightExpr) -- "node binary", Functor is guaranteed to be a binary arithmetic predicate that can be evaluated with `is`. LeftExpr and RightExpr are recursively defined "nodes". nu(Functor,Expr) -- "node unary", Functor is guaranteed to be a unary arithmetic predicate that can be evaluated with `is`. Expr is a recursively defined "node". nn(Number) -- "node number", Number is guaranteed to be just that. Hence, the following AST + / \ * random / \ \ 2 3 5 would be encoded as nb(+,nb(*,nn(2),nn(3)),nu(random,nn(5))).