MathGroup Archive 2011

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

Search the Archive

Re: Basic questions on _Plus and recursion

  • To: mathgroup at smc.vnet.net
  • Subject: [mg120887] Re: Basic questions on _Plus and recursion
  • From: Heike Gramberg <heike.gramberg at gmail.com>
  • Date: Sun, 14 Aug 2011 08:14:57 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <201108131049.GAA25524@smc.vnet.net>

For the second part of your question you could do something like

f[a___, b_ /; Scalar[b] == 1, c___] := b f[a, c]

example:

Scalar[a] = 1;
Scalar[c] = 1;
f[a, b, c]

output:

a c f[b]

Heike

On 13 Aug 2011, at 12:49, Ethan Dyer wrote:

> Hi. I'm sure these are common issues, but I haven't found them. Here 
are the two, unrelated questions. Thank you for the help.
>
> 1) I want to use _Plus for a function with arbitrary arguments. ie I 
want: f[a+b]=f[a]+f[b], f[a+b,c+d] to go to 
f[a,c]+f[a,d]+f[b,c]+f[b,d], ... Is there a standard way to do this?
>
> 2)Here I want to pull out scalars from a function. Something like 
this:
>
> f[x__] :=(Times@@Select[{x},Scalar[#]==1&]) 
(f@@Select[{x},Scalar[#]!=1&])
>
> Where i have defined a function Scalar to =1 for some symbols.
>
> for instance say I had defined Scalar[a]=1 then f[a,b,c]= a 
f[b,c].
>
> The above does not work, as it gives infinite recursion. Is there a 
way to do this properly?
>
> Thank you again. Sorry if these are too common.
>
> Ethan
>





  • Prev by Date: Re: Getting the Date and Time From a Time Server
  • Next by Date: Re: Getting the Date and Time From a Time Server
  • Previous by thread: Re: Basic questions on _Plus and recursion
  • Next by thread: Re: Basic questions on _Plus and recursion