Mathematica 9 is now available
Services & Resources / Wolfram Forums
-----
 /
MathGroup Archive
2007
*January
*February
*March
*April
*May
*June
*July
*August
*September
*October
*Archive Index
*Ask about this page
*Print this page
*Give us feedback
*Sign up for the Wolfram Insider

MathGroup Archive 2007

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

Search the Archive

Re: Replacement according to the pattern

  • To: mathgroup at smc.vnet.net
  • Subject: [mg77559] Re: Replacement according to the pattern
  • From: Szabolcs <szhorvat at gmail.com>
  • Date: Wed, 13 Jun 2007 07:22:25 -0400 (EDT)
  • Organization: University of Bergen
  • References: <f4lair$avv$1@smc.vnet.net>

tomuf at seznam.cz wrote:
> Hello,
> I wanted to parse a big expression and according to some rules
> integrate it term by term. For example, I wanted to replace symbol
> 
> HPL[{1, 1, 0}, u]
> 
> where HPL(list,variable) is function from package, with (note that
> this simplified example has no mathematical sense)
> 
> HPL[{1, 1, 0}, u] - D[HPL[{1, 1, 0}, u], u]
> 
> i.e. that function minus its derivative with respect to 'u'. I have
> loaded package which allows me to differentiate HPL. This works fine.
> But when I try to generalize this to handle all lists like {1,1,0} at
> the same time so that I don't have to type the rule for all
> combinations, the replacement doesn't work well. When I type:
> 
> in = HPL[{1, 1, 0}, u]
> in /. HPL[{1, 1, 0}, u] -> HPL[{1, 1, 0}, u] - D[HPL[{1, 1, 0}, u], u]
> in /. HPL[a_, u] -> HPL[a, u] - D[HPL[a, u], u]
> 
> the third line produces different result than the second line (the
> difference is in the term involving derivative). Does anyone know what
> could be wrong? Thanks in advance
> 
> Best regards,
> Tomas Prochazka

I can only speculate because I do not know what definitions are 
associated with HPL[], but the problem may be that evaluating 
D[HPL[a,u],u] without 'a' having a value like {1,1,0} gives an error.

Try
in /. HPL[a_, u] :> HPL[a, u] - D[HPL[a, u], u]

If it still doesn't work, try

in /. HoldPattern[HPL[a_, u]] :> HPL[a, u] - D[HPL[a, u], u]

Szabolcs


  • Prev by Date: Integral that Mathematica 5.1 can do and Mathematica 6 cannot do
  • Next by Date: Re: Normally Distributed Random Matrix
  • Previous by thread: Re: Replacement according to the pattern
  • Next by thread: Re: Replacement according to the pattern