Services & Resources / Wolfram Forums
MathGroup Archive
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2005

[Date Index] [Thread Index] [Author Index]

Search the Archive

Re: Imposing a value for LeafCount

  • To: mathgroup at
  • Subject: [mg61211] Re: [mg61187] Imposing a value for LeafCount
  • From: Andrzej Kozlowski <andrzej at>
  • Date: Wed, 12 Oct 2005 04:04:54 -0400 (EDT)
  • References: <>
  • Reply-to: Andrzej Kozlowski <andrzej at>
  • Sender: owner-wri-mathgroup at

On 12 Oct 2005, at 14:42, kalymereau at wrote:

> Dear MathGroup
> I have a complicated expression in which appears a symbol of the form
> f[i] where i is an integer (i.e. f[1], f[2] ... are  found in the full
> expression).
> When I LeafCount the full expression I want that each f[i] is
> considered as a single symbol with LeafCount=1. So I have defined
> LeafCount[f[i_Integer]] ^:= 1
> Then of course LeafCount[f[1]]=1 as I want, but LeafCount[2+f[1]] is 4
> instead of 3 (e.g. LeafCount[2+a]=3). This is because LeafCount[2+f 
> [1]]
> is not of the form LeafCount[f[i_Integer]], so that the above
> definition does not apply.
> How can I force LeafCount to consider that each f[i] has a LeafCount=1
> even in subexpressions ?
> Thanks

I would say the simplest way would be to define your own LeafCount as  

MyLeafCount[expr_] := LeafCount[expr /. f[i_Integer] :> Unique[f]]





Andrzej Kozlowski
Tokyo, Japan

  • Prev by Date: Re: NET/Link with Mono?
  • Next by Date: Re: ListPlot3D Scatter Plot
  • Previous by thread: Imposing a value for LeafCount
  • Next by thread: Solving Diophantine Equations