I am trying to build this program but having a really hard time. So I started off writing this program, I have a long program that almost works but is long and messy. Can anyone give me hints or be able to show me how to write this program in prolog? So for the base case, I figured out that it should be
sum(num(X), num(Y), Z):- Z is X + Y.
prod(num(X), num(Y), Z):- Z is X * Y.
I don't know how to distinguish whether the node is a product node or a sum node when traversing the tree. I do understand that num(X) is the leaf, while prod(X, Y) and sum(X, Y) are nodes.