Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #6786 > unrolled thread

Problem with Patterns and Integrate

Started byJack McInerney <ejmcinerney@gmail.com>
First post2011-11-28 10:55 +0000
Last post2011-11-29 12:06 +0000
Articles 3 — 3 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Problem with Patterns and Integrate Jack McInerney <ejmcinerney@gmail.com> - 2011-11-28 10:55 +0000
    Re: Problem with Patterns and Integrate A Retey <awnl@gmx-topmail.de> - 2011-11-29 12:04 +0000
    Re: Problem with Patterns and Integrate Armand Tamzarian <mike.honeychurch@gmail.com> - 2011-11-29 12:06 +0000

#6786 — Problem with Patterns and Integrate

FromJack McInerney <ejmcinerney@gmail.com>
Date2011-11-28 10:55 +0000
SubjectProblem with Patterns and Integrate
Message-ID<javpbs$jbk$1@smc.vnet.net>
There is something about using patterns that I don't understand, and
am hoping someone can shed some light.  Here is an example of my
problem.  Say I have a function f[x] and I take the derivative of it.
I can then integrate it and get f[x] back:


In[167]:= expr = D[ f[x], x ]
Out[167]= f=E2=80=B2[x]

In[168]:= Integrate[expr, x]
Out[168]= f[x]

If I use a ReplaceAll and a pattern to do the integration, the
Integrate function treats f'[x] as a constant and returns the wrong
answer:

In[169]:= expr /. func_ ->  Integrate[func,x]
Out[169]= x f=E2=80=B2[x]

Any thoughts as to what I am doing wrong?

Jack

[toc] | [next] | [standalone]


#6798

FromA Retey <awnl@gmx-topmail.de>
Date2011-11-29 12:04 +0000
Message-ID<jb2hnv$59o$1@smc.vnet.net>
In reply to#6786
Am 28.11.2011 11:55, schrieb Jack McInerney:
> There is something about using patterns that I don't understand, and
> am hoping someone can shed some light.  Here is an example of my
> problem.  Say I have a function f[x] and I take the derivative of it.
> I can then integrate it and get f[x] back:
>
>
> In[167]:= expr = D[ f[x], x ]
> Out[167]= f=E2=80=B2[x]
>
> In[168]:= Integrate[expr, x]
> Out[168]= f[x]
>
> If I use a ReplaceAll and a pattern to do the integration, the
> Integrate function treats f'[x] as a constant and returns the wrong
> answer:
>
> In[169]:= expr /. func_ ->   Integrate[func,x]
> Out[169]= x f=E2=80=B2[x]
>
> Any thoughts as to what I am doing wrong?

that's a good example for why there is RuleDelayed (:>) and not only 
Rule (->)

expr /. func_ :> Integrate[func, x]

does what you expect. With Rule the Integration is done before the match 
is inserted, that is you are actually doing the replacement

func_ -> func x

hth,

albert

[toc] | [prev] | [next] | [standalone]


#6802

FromArmand Tamzarian <mike.honeychurch@gmail.com>
Date2011-11-29 12:06 +0000
Message-ID<jb2hrq$5cp$1@smc.vnet.net>
In reply to#6786
On Nov 28, 9:55 pm, Jack McInerney <ejmciner...@gmail.com> wrote:
> There is something about using patterns that I don't understand, and
> am hoping someone can shed some light.  Here is an example of my
> problem.  Say I have a function f[x] and I take the derivative of it.
> I can then integrate it and get f[x] back:
>
> In[167]:= expr = D[ f[x], x ]
> Out[167]= f=E2=80=B2[x]
>
> In[168]:= Integrate[expr, x]
> Out[168]= f[x]
>
> If I use a ReplaceAll and a pattern to do the integration, the
> Integrate function treats f'[x] as a constant and returns the wrong
> answer:
>
> In[169]:= expr /. func_ ->  Integrate[func,x]
> Out[169]= x f=E2=80=B2[x]
>
> Any thoughts as to what I am doing wrong?
>
> Jack

Jack you need to use RuleDelayed for this operation

expr /. func_ :>  Integrate[func,x]

Mike

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web