The Math Forum

Search All of the Math Forum:

Views expressed in these public forums are not endorsed by NCTM or The Math Forum.

Math Forum » Discussions » Inactive » comp.soft-sys.math.mathematica

Topic: Subscript on plus expression
Replies: 16   Last Post: Dec 3, 2012 3:18 AM

Advanced Search

Back to Topic List Back to Topic List Jump to Tree View Jump to Tree View   Messages: [ Previous | Next ]
Albert Retey

Posts: 688
Registered: 7/15/08
Re: Superscript on plus expression
Posted: Dec 3, 2012 3:18 AM
  Click to see the message monospaced in plain text Plain Text   Click to reply to this topic Reply


> Mathematica fails to parenthesize the a+b in
> Superscript[Plus[a,b],k] so the output looks identical to
> Plus[a,Superscript[b,k]]

it's probably interesting to note that this specific behavior seems to
vary between version versions 5 and 7 will show the parentheses for
Superscript[Plus[a,b],k], while 6 and 8 don't. Considering that I'm not
convinced these changes and the behavior in version 8 were made on
purpose (no changes are mentioned for version 8 in the documentation,
too). Probably what you see really is a bug...

> Previous suggestions that worked to fix a similar problem for the
> Subscript case, i.e.,
> Format[Subscript[arg_Plus, k_]] := Subscript[ "(" <> StringJoin @@
> Riffle[ToString /@ (List @@ arg), " + "] <> ")", k]
> and
> MakeBoxes[Subscript[(head : (Plus | Times))[args__], k_], form :
> (StandardForm | TraditionalForm)] := InterpretationBox[#1, #2] & @@
> {SubscriptBox[ RowBox[{"(", ToBoxes[head[args], form], ")"}],
> ToBoxes[k, form]], Subscript[head[args], k]}
> don't carry over analogously to the Superscript case!
> Format[Superscript[arg_Plus, k_]] := Superscript[ "(" <> StringJoin
> @@ Riffle[ToString /@ (List @@ arg), " + "] <> ")", k]
> and
> MakeBoxes[Superscript[(head : (Plus | Times))[args__], k_], form :
> (StandardForm | TraditionalForm)] := InterpretationBox[#1, #2] & @@
> {SuperscriptBox[ RowBox[{"(", ToBoxes[head[args], form], ")"}],
> ToBoxes[k, form]], Superscript[head[args], k]}
> don't work!

Roland has already mentioned that this is most probably due to the early
interpretation of Superscript as Power. I guess they use some kind of
shortcut for that case which circumvents the user accessable functions
for performance reasons...

> How can I get Mathematica to parenthesize the sum in
> Superscript[Plus[a,b],k] ?

Here is another workaround which maps Superscript to Subsuperscript and
then uses the above trick to format the Subsuperscript which does work
as expected:

Superscript[arg_Plus, k_] := Subsuperscript[arg, "", k]

ormat[Subsuperscript[arg_Plus, "", k_]] :=
Style["(", ShowStringCharacters -> False],
Style[")", ShowStringCharacters -> False]
Style["", ShowStringCharacters -> False],
], Subsuperscript[arg, "", k]]

you could use anything that doesn't show instead of the empty string,
e.g. a Spacer[0]. The Interpretation and ShowStringCharacters options
are there so you can copy and paste and use % for the generated output
as usual. With that workaround you would of course need to make all
definitions you planed to make for Superscript now for Subsuperscript
with an empty string as second argument instead. If you are only needing
this to produce nicely formatted output that shouldn't be a problem,

cheers albert

Point your RSS reader here for a feed of the latest messages in this topic.

[Privacy Policy] [Terms of Use]

© The Math Forum at NCTM 1994-2017. All Rights Reserved.