Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
1996
*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 1996

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

Search the Archive

Re: Difficulties in patterns matching

  • To: mathgroup at smc.vnet.net
  • Subject: [mg3749] Re: Difficulties in patterns matching
  • From: Juergen.Schmidt at math.uni.giessen.de (Juergen Schmidt)
  • Date: Sun, 14 Apr 1996 03:02:23 -0400
  • Organization: Institut fuer Mathematische Physik
  • Sender: owner-wri-mathgroup at wolfram.com

In article <4jvrv2$nt1 at dragonfly.wolfram.com>, nader at math.chalmers.se says...

>        Hi,
>
>        I spent some time to get a grip on the following patterns
>matching problem but to no avail. 
>
>        Consider the following expression.
>
>test = (2*Sum[(gamma*x[i])/(sigma^2*(1 - (gamma*x[i])/sigma)), {i, 1, n}])/
>    gamma^3 + (-1 + gamma^(-1))*
>    Sum[(2*gamma*x[i]^3)/(sigma^4*(1 - (gamma*x[i])/sigma)^3) + 
>      (2*x[i]^2)/(sigma^3*(1 - (gamma*x[i])/sigma)^2), {i, 1, n}] - 
>   (2*Sum[(gamma*x[i]^2)/(sigma^3*(1 - (gamma*x[i])/sigma)^2) + 
>        x[i]/(sigma^2*(1 - (gamma*x[i])/sigma)), {i, 1, n}])/gamma^2
>
>        I would like to apply the following transformation rules to
>the above expression.
>
>1) Sum[x[i]/(1-gamma x[i]/sigma),{i,1,n}]-> n f1[gamma,sigma]
>
>2) Sum[x[i]^2/(1-gamma x[i]/sigma)^2,{i,1,n}]-> n f2[gamma,sigma]
>
>3) And generally for different m's:
>
>Sum[x[i]^m/(1-gamma x[i]/sigma)^m,{i,1,n}]-> n fm[gamma,sigma]
>
>
>        There are lots of such expressions and the main problem is
>that I can't define a general transformation rule which can handle for
>example rule no 1 for all different coefficients of x[i] in the numerator of
>expressions and also for different coefficients of (1-gamma
>x[i]/sigma) in the denominator of expressions. This means that the
>first sum in "test" should be transformed to
>
>                n gamma f1[gamma,sigma] /sigma^2
>
>These rules should also handle sums like
>
>        Sum[x[i]+y[i],{i,n}]=Sum[x[i],{i,n}]+Sum[y[i],{i,n}].
>
>
>        Thanks in advance for any advice you can give.
>
>        Regards, Nader Tajvidi


Hello,

try this:

rel = 
{Literal at Sum[c_*f_, {i_, n__}]       :> c*Sum[f, {i, n}] /; FreeQ[c, i],

 Literal at Sum[a_ + b_, range_List]    :> Sum[a, range] + Sum[b, range],

 Literal at Sum[c1_.*x[i_]^m_. * (c2_.*(1-gamma x[i_]/sigma))^n_.,  {i_, 1, N_}] :> 
   c1/c2* N ToExpression["f"<>ToString[m]][gamma, sigma] /; 
                                    (FreeQ[{c1, c2}, i]) && (m + n === 0)
};

test//.rel

The real problem is caused by such pattern:

   MatchQ[ a/b,     a^n_. * b^(-n_.)]
   True

   MatchQ[ a^2/b^2, a^n_. * b^(-n_.)]
   False

This can be circumvented by using
  
   MatchQ[ a^2/b^2, a^n_. * b^m_. /; n + m === 0]
   True


Juergen


--------------------------------------------------------
 Dipl.-Phys. Juergen Schmidt
  Mathematisches Institut (Math. Physik)
   der Justus-Liebig-Universitaet Giessen
    Arndtstr. 2
     D-35392 Giessen
      Tel. +49 641702-2542 (-2535 Secr./-2548 Fax)
       http://www.uni-giessen.de/www-Mathematische-Physik/  
      ---------------------------------------------------------


==== [MESSAGE SEPARATOR] ====


  • Prev by Date: Please help me : Communication between mathematica and other Windows programs.
  • Next by Date: Re: Mathematica: should I move to Windows from X?
  • Previous by thread: Difficulties in patterns matching
  • Next by thread: mathlink.h and math2.1