HoldPattern question
- To: mathgroup at smc.vnet.net
- Subject: [mg70026] HoldPattern question
- From: dimmechan at yahoo.com
- Date: Sat, 30 Sep 2006 05:13:17 -0400 (EDT)
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.