Hello! I want to make function with the following properties:
RAv(expr1+expr2) = RAv(expr1) + RAv(expr2)
RAv(expr1*expr2) = RAv(expr1) * RAv(expr2) + RCr(expr1, expr2)
where RCr is some another function. I have tried
RAv(expr):=
if atom(expr)=true then
'RAv(expr)
elseif part(expr,0) = "+" then
RAv(part(expr,1)) + RAv(part(expr,2))
elseif part(expr,0) = "*" then
RAv(part(expr,1)) * RAv(part(expr,2)) + RCr(part(expr,1), part(expr,2))
else 'RAv(expr)$
but it fails with RAv(x*y*z) or RAv(x+y+z). Well, I know what is wrong, but I have no idea how to make the right variant, that will give
RAv(x+y+z) = RAv(x) + RAv(y) + RAv(z)
RAv(x*y*z) = RAv(x) * RAv(y) * RAv(z) + RAv(x)*RCr(y, z) + RCr(x, y*z) (or with another order of variables, doesn't matter)