Question: Problem with Graph

I'm trying to add the output of my function FunctionToTree,which gets all elements from an expression, to a graph using the Graph function but I'm getting erros even when I add it as a list.

with(GraphTheory):
with(SpecialGraphs):
FunctionToTree:=proc(expr)
local elem;
local Tree:=NULL;
local exprType := convert(whattype(expr),string);
local newExpr:=convert(expr,string);
if (nops(expr) <> 1) or (nops(op(1,expr)) <> 1) then
for elem in op(expr) do :
if(type(elem,atomic)) then:
Tree := Tree, {elem};
else:
Tree := Tree, {whattype(elem),elem};
end if:
Tree := Tree, FunctionToTree(elem);
end do:
end if:
end proc:


l:=FunctionToTree(3*z+cos(x+2*y));

 Graph({l});

Error, (in GraphTheory:-Graph) invalid argument: {{`*`, 2*y}, {`*`, 3*z}, {function, cos(x+2*y)}}

Please Wait...