PRODUCTS
Products Overview
Mathematica
Mathematica Student Edition
Mathematica Home Edition
Wolfram
CDF Player
(free download)
Computable Document Format (CDF)
web
Mathematica
grid
Mathematica
Wolfram
Workbench
Wolfram
SystemModeler
Wolfram
Finance Platform
Mathematica
Add-Ons
Wolfram|Alpha Products
SOLUTIONS
Solutions Overview
Engineering
Aerospace Engineering & Defense
Chemical Engineering
Control Systems
Electrical Engineering
Image Processing
Industrial Engineering
Materials Science
Mechanical Engineering
Operations Research
Optics
Petroleum Engineering
Biotechnology & Medicine
Bioinformatics
Medical Imaging
Finance, Statistics & Business Analysis
Actuarial Sciences
Data Analysis & Mining
Econometrics
Economics
Financial Engineering & Mathematics
Financial Risk Management
Statistics
Software Engineering & Content Delivery
Authoring & Publishing
Interface Development
Software Engineering
Web Development
Science
Astronomy
Biological Sciences
Chemistry
Environmental Sciences
Geosciences
Social & Behavioral Sciences
Design, Arts & Entertainment
Game Design, Special Effects & Generative Art
Education
STEM Education Initiative
Higher Education
Community & Technical College Education
Primary & Secondary Education
Students
Technology
Computable Document Format (CDF)
High-Performance & Parallel Computing (HPC)
See Also: Technology Guide
PURCHASE
Online Store
Other Ways to Buy
Volume & Site Licensing
Contact Sales
Software
Service
Upgrades
Training
Books
Merchandise
SUPPORT
Support Overview
Mathematica
Documentation
Knowledge Base
Learning Center
Technical Services
Community & Forums
Training
Does My Site Have a License?
Wolfram User Portal
COMPANY
About Wolfram Research
News
Events
Wolfram Blog
Partnerships
Employment Opportunities
History of
Mathematica
Stephen Wolfram's Home Page
Contact Us
OUR SITES
All Sites
Wolfram|Alpha
Demonstrations Project
MathWorld
Integrator
Wolfram Functions Site
Mathematica Journal
Wolfram Media
Wolfram
Tones
Wolfram Science
Stephen Wolfram
THIS IS DOCUMENTATION FOR AN OBSOLETE PRODUCT.
SEE THE
DOCUMENTATION CENTER
FOR THE LATEST INFORMATION.
DOCUMENTATION CENTER SEARCH
New to
Mathematica
?
Find your learning path
»
Mathematica
>
Core Language
>
Expressions
>
Expression Structure
>
LeafCount
>
BUILT-IN MATHEMATICA SYMBOL
Expressions as Trees
Memory Management
Tutorials »
|
ByteCount
Length
Depth
AtomQ
Hash
See Also »
|
Expression Structure
Memory Measurement & Optimization
More About »
LeafCount
LeafCount
[
expr
]
gives the total number of indivisible subexpressions in
expr
.
MORE INFORMATION
LeafCount
gives a measure of the total "size" of an expression.
LeafCount
counts the number of subexpressions in
expr
that correspond to "leaves" on the expression tree.
LeafCount
is based on
FullForm
representation of expressions.
Numbers with heads
Rational
and
Complex
are treated as composite objects, just as in
FullForm
.
EXAMPLES
CLOSE ALL
Basic Examples
(1)
Find the number of "leaves" in an expression tree:
Find the number of "leaves" in an expression tree:
In[1]:=
Out[1]=
In[2]:=
Out[2]=
Applications
(3)
Find leafcount measures of the sizes of successive integrals:
Make
Simplify
pick expressions with minimum
LeafCount
:
Find leafcounts in combinator expressions
Properties & Relations
(1)
LeafCount
includes the head and all elements inside it:
Possible Issues
(5)
LeafCount
is based on the
FullForm
of expressions:
LeafCount
counts elements in rational and complex numbers just as in
FullForm
:
Integers of any size are still treated as single expression leaves:
LeafCount
treats
SparseArray
objects as single expression leaves:
Unlike
TreeForm
,
LeafCount
takes into consideration the structure of expression heads:
This shows the expression tree whose leaves are counted by
LeafCount
:
SEE ALSO
ByteCount
Length
Depth
AtomQ
Hash
TUTORIALS
Expressions as Trees
Memory Management
MORE ABOUT
Expression Structure
Memory Measurement & Optimization
RELATED LINKS
NKS|Online
(
A New Kind of Science
)
New in 1