There is **leaf_count()** type function which is standard and buildin in other CAS systems (Mathematica and Maple). It is very useful. It is used to measure the size of a mathematical expression in a standard way.

This will make it easier for example, to compare the size of the anti-derivative from a call to integrate from different CAS systems.

There are couple of ad-hoc attempts on the net now to do this in sagemath, but they do not work for all expressions, (give errors in some cases) and do not produce good measure of the size of the expression.

leaf_count() is described in https://reference.wolfram.com/language/ref/LeafCount.html

and

https://www.maplesoft.com/support/help/Maple/view.aspx?path=MmaTranslator/Mma/LeafCount

*LeafCount counts the number of subexpressions in expr that correspond to "leaves" on the expression tree.*

So basically, if it possible to obtain the expression tree of any sagemath mathematical expression, leaf_count() should just return the number of leaf nodes of that tree.

Currently, the way I obtain leaf_count() for a sagemath expression, is by calling Maple and passing it the expression (as a string), then use Maple's `LeafCount`

function there (after converting the expression back to Maple, using parse function).

I use Maple not Mathematica for this, since the syntax of the sagemath expressions are much closer to Maple's.

But I prefer to do this all in sagemath. Much simpler. But the current implementation I saw does not work well for everything, and gives different result of the measure of the expression.

see as an example https://stackoverflow.com/questions/25202346/how-to-obtain-leaf-count-expression-size-in-sage

I am sure some sagemath internals expert here could write such a function and add it to sagemath as a standard buildin function. May be for 9.4 version?

Thank you --Nasser