Skip to content

Commit 30c92ef

Browse files
authored
Merge pull request #246 from adamslc/print_tree_fix
Make print_tree show coefficients for Add and Mul
2 parents e8ef3d4 + 51bd30f commit 30c92ef

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

src/types.jl

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,17 @@ struct TreePrint
902902
x
903903
end
904904
AbstractTrees.children(x::Term) = arguments(x)
905-
AbstractTrees.children(x::Union{Add, Mul}) = map(y->TreePrint(x isa Add ? (:*) : (:^), y), collect(pairs(x.dict)))
905+
function AbstractTrees.children(x::Union{Add, Mul})
906+
children = Any[x.coeff]
907+
for (key, coeff) in pairs(x.dict)
908+
if coeff == 1
909+
push!(children, key)
910+
else
911+
push!(children, TreePrint(x isa Add ? (:*) : (:^), (key, coeff)))
912+
end
913+
end
914+
return children
915+
end
906916
AbstractTrees.children(x::Union{Pow}) = [x.base, x.exp]
907917
AbstractTrees.children(x::TreePrint) = [x.x[1], x.x[2]]
908918

0 commit comments

Comments
 (0)