MathGroup Archive 2006

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

Search the Archive

Re: HoldPattern question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg70064] Re: [mg70026] HoldPattern question
  • From: Andrzej Kozlowski <akoz at mimuw.edu.pl>
  • Date: Sun, 1 Oct 2006 04:11:02 -0400 (EDT)
  • References: <200609300913.FAA13219@smc.vnet.net>

On 30 Sep 2006, at 18:13, dimmechan at yahoo.com wrote:

> Hello to all.
>
> I copied from the Help Browser.
>
> HoldPattern[expr] is equivalent to expr for pattern matching,
> but maintains expr in an unevaluated form.
> (...)
> Example: expr /. HoldPattern[Integrate[y_, x_]] -> rhs transforms
> any subexpression of the form Integrate[y_, x_] in expr. Without
> the HoldPattern, the Integrate[y_, x_] in the rule would immediately
> be evaluated to give x_ y_, and the replacement would not work."
>
> So based on this notes the folowing rule seems normal and well
> justified.
>
> Hold[Integrate[a, x]] + Log[x] /. {HoldPattern[Integrate[y_, x_]] - 
> > f,
> Log[x] -> Exp[x]}
> E^x + Hold[f]
>
> However why the following rule (that is without HoldPattern) gives the
> same output?
>
> Hold[Integrate[a, x]] + Log[x] /. {Integrate[y_, x_] -> f, Log[x] ->
> Exp[x]}
> E^x + Hold[f]
>
> Using Trace I notice that even without HoldPattern surrounded
> Integrate[y_,x_] the latter is not evaluated to x_y_.
>
> Trace[Hold[Integrate[a, x]] + Log[x] /. {Integrate[y_, x_] -> f, Log 
> [x]
> -> Exp[x]}]
> {{{HoldForm[Integrate[y_, x_] -> f], HoldForm[Integrate[y_, x_] ->  
> f]},
>  {{HoldForm[E^x], HoldForm[E^x]},  HoldForm[Log[x] -> E^x],
> HoldForm[Log[x] -> E^x]},
> HoldForm[{Integrate[y_, x_] -> f, Log[x] -> E^x}]},
> HoldForm[Hold[Integrate[a, x]] + Log[x] /. {Integrate[y_, x_] -> f,
> Log[x] -> E^x}], HoldForm[Hold[f] + E^x], HoldForm[E^x + Hold[f]]}
>
> Based on the Help Browser it is very curious that this worked.
> Otherwise something I am missing.
>
> I really appreciate some guidance.
>
> Thanks.
>

It seems that  Integrate[expr1,expr2] is always returned unevaluated  
if the Head of expr2 is Pattern. Thus:


Integrate[a, Pattern[b]]


Integrate[a, Pattern[b]]


Integrate[a,Pattern[b,c]]


Integrate[a, b:c]

Hence, of course, Integrate[y_,x_], which has full form Integrate 
[Pattern[x, Blank[]], Pattern[y, Blank[]]] is returned unevaluated  
and there is no need to surround it with HoldPattern.

By the way, definite integrals are also returned unevaluated if the  
variable of integration of any limit is a pattern, e.g.

Integrate[x, {x, a_, b_}]

or

Integrate[x_, {x, a, b}]

and so on.

If you still want to know "why" this is so, you have to, I think,  
address you question to someone from  WRI. I have, of course, my own  
ideas, but they are mere speculation.

Andrzej Kozlowski


  • Prev by Date: Re: Input, output troubles me ...
  • Next by Date: Re: RE: Re: Re: distance function
  • Previous by thread: Re: distance function
  • Next by thread: Re: HoldPattern question