MathGroup Archive 2004

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

Search the Archive

Re: How to explain functions' linearity to Mathematica 5 ?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg51082] Re: [mg51076] How to explain functions' linearity to Mathematica 5 ?
  • From: "David Park" <djmp at earthlink.net>
  • Date: Mon, 4 Oct 2004 06:17:41 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

In the Tensorial package at my web site we use a routine called
LinearBreakout. I copy the routine out here so you can use it independently.

LinearBreakout::usage = "LinearBreakout[f1, \
f2,...][v1, v2,...][expr] will break out the linear \
terms of any expressions within expr that have heads \
matching the patterns fi over variables matching the \
patterns vj. Example:\n f[a x + b \
y]//LinearBreakout[f][x,y] \[Rule] a f[x] + b f[y]";


LinearBreakout[f__][vars__][expr_] :=
  expr //. {(g : Alternatives @@ {f})[p1___, a_ + b__, p2___] :>
        g[p1, a, p2] + g[p1, Plus[b], p2], (g : Alternatives @@ {f})[p1___,
          a_ b : Alternatives @@ {vars}, p2___] :> a g[p1, b, p2]}

N0[i, j, a r + b s] // LinearBreakout[N0][r, s]
a N0[i, j, r] + b N0[i, j, s]

N0[1, 2, \[ImaginaryI] N0[4, 1, r] + 97 N0[4, 3, 5 N0[2, 1, r]]];
% // LinearBreakout[N0][N0[__], r, s]
\[ImaginaryI] N0[1, 2, N0[4, 1, r]] + 485 N0[1, 2, N0[4, 3, N0[2, 1, r]]]

The last is different than you typed below but I think it is correct.

As used above, LinearBreakout would also breakout on the first and second
arguments of N0 if they contained r and s expressions. If you want to
breakout on only one slot you might want to rewrite the expressions using
subvalues for the first two slots.
N0[i,j][a r + b s].

N0[i, j][a r + b s] // LinearBreakout[N0[_, _]][r, s]
a N0[i, j][r] + b N0[i, j][s]

David Park
djmp at earthlink.net
http://home.earthlink.net/~djmp/




From: Stepan Yakovenko [mailto:stiv at novi.ru]
To: mathgroup at smc.vnet.net

Hello !

It would be great if someone will help me to find out a solution for a
small problem.
I have got an abstract function N0[i,j,r], where i and j are integers
and r is some formulae.
N0 has a feature: N0[i,j,r+s]=N0[i,j,r]+N0[i,j,s] and N0[i,j, a s]=a
N0[i,j,s]. I have got
a long expression like this: N0[1,2,
I*N0[4,1,r]+97*N0[4,3,5*N0[2,1,r]]]. I want it to get expanded
like this I*N0[1,2,N0[4,1,r]+5*97*N0[1,2,N0[4,3,N0[2,1,r]]]] with
Mathematica 5. How can I do it ?

Thanx in advance.






  • Prev by Date: Re: Re: Thichness of Plot does not change Solved
  • Next by Date: Re: Trouble with NDSolve Function
  • Previous by thread: Re: How to explain functions' linearity to Mathematica 5 ?
  • Next by thread: Derivatives of user-defined control-flow functions