Bug: Collect with Simplify destroys Hold

• To: mathgroup at smc.vnet.net
• Subject: [mg30671] Bug: Collect with Simplify destroys Hold
• From: "Alan Mason" <amason2 at austin.rr.com>
• Date: Mon, 3 Sep 2001 20:32:48 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

There is a serious bug in Mathematica 4.1 that affects the new extension
Collect[expr, patt, h] to Collect[expr, patt].  It is supposed to collect
patt in expr and then apply h to each collected part.  Unfortunately, if
expr involves terms of the form Hold[expr2], the hold is destroyed (i.e.,
expr2 is evaluated, which is an absolute no-no, and then Hold is rather
absurdly applied to the result).  This is shown in the following short
notebook.

When working with differential operators that have been defined in terms of
other operators (e.g., in terms of the standard partial differential
operators D_x, D_y, D_z), it is essential to keep them unevaluated until the
proper moment.  In the notebook,  J_y is the y component of the quantum
mechanical angular momentum operator, expressed in terms of derivatives with
respect to the Euler angles.  The bug means that Collect[expr, patt,
Simplify] cannot be used to collect and simplify expressions involving these
operators, which is too bad as it would be extremely useful.

Does anyone know of a workaround? Since the error occurs with arbitrary
heads h, the obvious idea (replacing Simplify by some head h, then replacing
h-> Simplify) does not work.

In[1]:=
\!\(\(\(J\_y\  = \ \(-\[ImaginaryI]\)\ \[HBar]\ Cos[\[Gamma]]\ Hold[
D\_\[Beta]] - \[ImaginaryI]\ \[HBar]\ Csc[\[Beta]]\ Hold[
D\_\[Alpha]]\ Sin[\[Gamma]] + \[ImaginaryI]\ \[HBar]\
Cot[\[Beta]]\ \
Hold[D\_\[Gamma]]\ Sin[\[Gamma]]\)\(\[IndentingNewLine]\)
\)\[IndentingNewLine]
test\  = \ Hold[J\_y]\ x\)

Out[1]=
\!\(\(-\[ImaginaryI]\)\ \[HBar]\ Cos[\[Gamma]]\ Hold[
D\_\[Beta]] - \[ImaginaryI]\ \[HBar]\ Csc[\[Beta]]\ Hold[
D\_\[Alpha]]\ Sin[\[Gamma]] + \[ImaginaryI]\ \[HBar]\ Cot[\[Beta]]\
\
Hold[D\_\[Gamma]]\ Sin[\[Gamma]]\)

Out[2]=
\!\(x\ Hold[J\_y]\)

In[3]:=
Collect[test, x, Simplify]

Out[3]=
\!\(x\ Hold[\(-\[ImaginaryI]\)\ \[HBar]\ Cos[\[Gamma]]\ Hold[
D\_\[Beta]] - \[ImaginaryI]\ \[HBar]\ Csc[\[Beta]]\ Hold[
D\_\[Alpha]]\ Sin[\[Gamma]] + \[ImaginaryI]\ \[HBar]\ \
Cot[\[Beta]]\ Hold[D\_\[Gamma]]\ Sin[\[Gamma]]]\)

In[4]:=
Collect[test, x, h]

Out[4]=
\!\(x\ h[Hold[\(-\[ImaginaryI]\)\ \[HBar]\ Cos[\[Gamma]]\ Hold[
D\_\[Beta]] - \[ImaginaryI]\ \[HBar]\ Csc[\[Beta]]\ Hold[
D\_\[Alpha]]\ Sin[\[Gamma]] + \[ImaginaryI]\ \[HBar]\ Cot[\
\[Beta]]\ Hold[D\_\[Gamma]]\ Sin[\[Gamma]]]]\)

• Prev by Date: Sticky Previews? Mathematica Export, Illustrator, and Textures
• Next by Date: Re: Curl
• Previous by thread: Re: Sticky Previews? Mathematica Export, Illustrator, and Textures
• Next by thread: Re: Bug: Collect with Simplify destroys Hold