[Date Index]
[Thread Index]
[Author Index]
Re: Superscript on plus expression
*To*: mathgroup at smc.vnet.net
*Subject*: [mg128826] Re: Superscript on plus expression
*From*: awnl <awnl at gmx-topmail.de>
*Date*: Thu, 29 Nov 2012 06:03:46 -0500 (EST)
*Delivered-to*: l-mathgroup@mail-archive0.wolfram.com
*Delivered-to*: l-mathgroup@wolfram.com
*Delivered-to*: mathgroup-newout@smc.vnet.net
*Delivered-to*: mathgroup-newsend@smc.vnet.net
*References*: <20121117084935.868E56AF3@smc.vnet.net> <19898081.6403.1353229345311.JavaMail.root@m06> <000301cdc668$e3ec8740$abc595c0$@comcast.net> <k91u8h$5l1$1@smc.vnet.net>
Hi,
> 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_]] :=
Interpretation[Subsuperscript[
Row[{
Style["(", ShowStringCharacters -> False],
arg,
Style[")", ShowStringCharacters -> False]
}],
Style["", ShowStringCharacters -> False],
k
], 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,
though...
cheers albert
Prev by Date:
**Re: Numerical expression**
Next by Date:
**Integral that should converge, but Mathematica says it does not**
Previous by thread:
**Re: Superscript on plus expression**
Next by thread:
**Re: Plotting a series of Roots**
| |