# Building a ComplexityFunction based on the size of the expression output

I am experimenting with the ComplexityFunction of Simplify and came up with this one:

ComplexityFunction->Function[e,Rasterize[HoldForm[e],"BoundingBox"][[1]]]


It gets the width of the bounding box of the image representation for the expression. The expression which generates an image with less width, is the chosen one. It works, but since it uses Rasterize, it is very slow.

I would like to know if there is a faster way to measure the displayed size the expression output. Any ideas?

• I can't imagine how you could measure an image without generating it first. Perhaps the problem is more like finding another almost equivalent weighting function – Dr. belisarius Dec 7 '14 at 22:50
• There is another way, by measuring the BoundingBox. It works, but is slow too. See mathematica.stackexchange.com/questions/67482/… – Giovanni F. Dec 8 '14 at 1:03
• You mean ComplexityFunction-> Function[e,StringLength[ToString[InputForm[e]]]] cannot meet request? – yode Dec 8 '16 at 6:15
• No, the string representation is not good for some expressions. – Giovanni F. Dec 8 '16 at 20:20