LeafCount
- To: mathgroup at smc.vnet.net
- Subject: [mg25943] LeafCount
- From: Will Self <wself at msubillings.edu>
- Date: Fri, 10 Nov 2000 02:40:20 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
In the expression Plus[x, Times[y, z]] I would say that there are 3 terminal nodes (leaves), x, y, and z. The built-in function LeafCount, which purports to count the number of terminal nodes in the expression tree, actually counts *all* the nodes. So LeafCount[Plus[x, Times[y, z]]] ---> 5 Am I missing something here, or is it true that LeafCount is wrongly described in the Mathematica Book? Here is mine: myLeafCount[expr_]:= Length[Flatten[Hold[expr] /. x_ :> List /; Head[x] == Symbol]] Does anyone see anything wrong with this? Or have another suggestion? Will Self private email replies appreciated Sent via Deja.com http://www.deja.com/ Before you buy.