MathGroup Archive 2001

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

Search the Archive

Re: Bug: Collect with Simplify destroys Hold

  • To: mathgroup at smc.vnet.net
  • Subject: [mg30673] Re: [mg30671] Bug: Collect with Simplify destroys Hold
  • From: Andrzej Kozlowski <andrzej at tuins.ac.jp>
  • Date: Sat, 8 Sep 2001 02:22:13 -0400 (EDT)
  • Sender: owner-wri-mathgroup at wolfram.com

The workaround is to use the Notation package. Here is what happens if 
you turn all subscripted J's into symbols:

In[1]:=
<<Utilities`Notation`

In[2]:=
\!\(\*
   RowBox[{"Symbolize", "[",
     TagBox[\(J\__\),
       NotationBoxTag,
       TagStyle->"NotationTemplateStyle"], "]"}]\)

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

In[4]:=
\!\(\(test\  = \ Hold[J\_y]\ x;\)\)

In[6]:=
Collect[test, x, Simplify]//Trace

Out[6]=
\!\(\*
   RowBox[{"{",
     RowBox[{
       RowBox[{"{",
         RowBox[{
           TagBox["test",
             HoldForm], ",",
           TagBox[\(x\ Hold[J\_y]\),
             HoldForm]}], "}"}], ",",
       TagBox[\(Collect[x\ Hold[J\_y], x, Simplify]\),
         HoldForm], ",",
       RowBox[{"{",
         RowBox[{
           TagBox[\(Simplify[Hold[J\_y]]\),
             HoldForm], ",",
           TagBox[\(Hold[J\_y]\),
             HoldForm]}], "}"}], ",",
       TagBox[\(x\ Hold[J\_y]\),
         HoldForm]}], "}"}]\)

On Tuesday, September 4, 2001, at 09:32  AM, Alan Mason wrote:

> 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]]]]\)
>
>
>

Andrzej Kozlowski
Toyama International University
JAPAN
http://platon.c.u-tokyo.ac.jp/andrzej/


  • Prev by Date: Good news from the Math Forum@Drexel
  • Next by Date: FindMinimum and least square minimization
  • Previous by thread: Bug: Collect with Simplify destroys Hold
  • Next by thread: Repeated Messages Fixed