|
[Date Index]
[Thread Index]
[Author Index]
RE: Sum expansion
- To: mathgroup at smc.vnet.net
- Subject: [mg32668] RE: [mg32630] Sum expansion
- From: "Wolf, Hartmut" <Hartmut.Wolf at t-systems.com>
- Date: Mon, 4 Feb 2002 03:23:36 -0500 (EST)
- Sender: owner-wri-mathgroup at wolfram.com
> -----Original Message-----
> From: Cyril Fischer [mailto:fischerc at itam.cas.cz]
To: mathgroup at smc.vnet.net
> Sent: Friday, February 01, 2002 8:03 AM
> To: mathgroup at smc.vnet.net
> Subject: [mg32668] [mg32630] Sum expansion
>
>
>
> I would like to arrange exression
> A Sum [ B_i ,{i,1,s}]
> into expression
> Sum [ A B_i, {i,1,s} ]
>
> Following transformation code gives unwanted answer:
> A*Sum[Subscript[B, i], {i, 1, s}] /.
> a_*Sum[b_, {i, 1, s}] -> Sum[a*b, {i, 1, s}]
> Result is
> A s Bi
>
> I understand, why it behawes this way, but I dont know the
> correct way.
>
> Thanks for your hints,
> Cyril
>
>
Cyril,
use RuleDelayed
In[9]:= A*Sum[Subscript[B, i], {i, 1, s}] /.
a_*Sum[b_, {i, 1, s}] :> Sum[a*b, {i, 1, s}]
Out[9]=
Sum[A*Subscript[B, i], {i, 1, s}]
otherwise the rhs of Rule can be evaluated (prematurely for you).
[This would not have happend, if a dependence on i had been preserved:
In[10]:= A*Sum[Subscript[B, i], {i, 1, s}] /.
a_*Sum[Subscript[b_, i], {i, 1, s}] ->
Sum[a*Subscript[b, i], {i, 1, s}]
Out[10]=
Sum[A*Subscript[B, i], {i, 1, s}]
...]
This is enough in this case. Otherwise, prevent evaluation of the lhs with
Unevaluated, of the pattern with HoldPattern (and use RuleDelayed of course)
--
Hartmut
Prev by Date:
RE: Simplify
Next by Date:
Re: About programming Mathematica [Newbie question]
Previous by thread:
Re: Sum expansion
Next by thread:
Re: dropping higher order terms
|