Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2005
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*November
*December
*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 smc.vnet.net
  • Subject: [mg61211] Re: [mg61187] Imposing a value for LeafCount
  • From: Andrzej Kozlowski <andrzej at yhc.att.ne.jp>
  • Date: Wed, 12 Oct 2005 04:04:54 -0400 (EDT)
  • References: <200510120542.BAA09227@smc.vnet.net>
  • Reply-to: Andrzej Kozlowski <andrzej at akikoz.net>
  • Sender: owner-wri-mathgroup at wolfram.com

On 12 Oct 2005, at 14:42, kalymereau at yahoo.fr 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  
follows:



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

Now

In[2]:=
MyLeafCount[2+f[1]]

Out[2]=
3

etc.




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