MathGroup Archive 2002

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

Search the Archive

Re: Why do parentheses spuriously appear when I type in a formula?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg34551] Re: [mg34410] Why do parentheses spuriously appear when I type in a formula?
  • From: "Carl K. Woll" <carlw at u.washington.edu>
  • Date: Mon, 27 May 2002 01:16:55 -0400 (EDT)
  • References: <000001c20345$446cc140$03f5b4d0@HolyCow>
  • Sender: owner-wri-mathgroup at wolfram.com

DrBob,

Let me rephrase my comment.

Why do you compare

(the b subscript of T) raised to the a power

 the b subscript of (T raised to the a power)

Neither of these expressions correspond to the way input is given in
Mathematica.

Carl Woll
Physics Dept
U of Washington

----- Original Message -----
From: "DrBob" <majort at cox-internet.com>
To: mathgroup at smc.vnet.net
Hartmut'" <Hartmut.Wolf at t-systems.com>
Subject: [mg34551] RE: [mg34410] Why do parentheses spuriously appear when I type in a
formula?


> No, "T with (b subscript raised to the a power)" is a third thing
> entirely.
>
> We can "talk about parentheses as related to Mathematica" in any context
> where they do (or don't) occur, so change the choices if you want, but
> don't say it's necessary.
>
> Bobby
>
> -----Original Message-----
> From: Carl K. Woll [mailto:carlw at u.washington.edu]
To: mathgroup at smc.vnet.net
> Sent: Friday, May 24, 2002 11:31 AM
> Subject: [mg34551] Re: [mg34410] Why do parentheses spuriously appear when I type
> in a formula?
>
> DrBob and Hartmut,
>
> Since I started this thread, let me add a few words of comment.
>
> DrBob compares
>
> (the b subscript of T) raised to the a power
>
> the b subscript of (T raised to the a power)
>
> and states that parentheses are needed in one of the two to be able to
> distinguish between them. However, the syntax of Mathematica for
> subscripts
> is the same as the syntax for superscripts (or power), so this
> comparison
> has no relevance to Mathematica. That is, subscripting is given by
> Subscript[T,b] not Subscript[b,T]. In words, you should compare
>
> (T with b subscript) raised to the a power
>
> T with (b subscript raised to the a power)
>
> if you want to talk about parentheses as related to Mathematica. Now,
> the
> question is if parentheses are needed to visually distinguish between
> these
> two cases, and the answer is no! There is a clear visual difference
> between
> the two. Just compare
>
> Superscript[Subscript[T,b],a]
>
> Subscript[T,Superscript[b,a]]
>
> after deleting the parentheses that show up in the first case. Since
> there
> is a clear visual difference between the two, the added parentheses are
> really just optional, and I would prefer the option without parentheses.
>
> Moreover, the designers of Mathematica apparently agreed that the
> parentheses were really optional. Consider the case with Superscript and
> Subscript switched.
>
> Subscript[Superscript[T,b],a]
> Superscript[T,Subscript[b,a]]
>
> Again the visual difference between the two is clear, but notice that in
> this case Mathematica does NOT add any parentheses. So the designers of
> Mathematica decided that in one case they would add parentheses and not
> in
> the other. This choice is obviously influenced by the fact that
> superscripts
> are usually interpreted as power.
>
> At any rate, when I asked my original question, I was looking for a way
> to
> make Mathematica NOT add these parentheses. Since the parentheses are
> added
> during the input phase (even with no kernel present) adding rules to
> MakeExpression will not solve the problem. It is possible that modifying
> one
> of the text resources might change this behaviour, but I couldn't figure
> out
> which file to modify. For example, the file MathMLPatterns seems to be
> relevant. However, there may be no way for a user to change this
> behavior.
>
> On another note, there is another example where Mathematica adds
> parentheses, and most people would consider these parentheses to be
> almost
> mandatory. This example occurs when you take the subscript or
> superscript of
> a quotient. So, it is important that Mathematica be able to add
> parentheses
> when necessary for visual reasons. Still, as Hartmut points out, there
> is
> never any ambiguity in what is meant when one uses one dimensional
> input,
> since everything has a precedence. The expression without parentheses
> may
> not be what you want, but that doesn't mean the expression is ambiguous.
> The
> only time there is any ambiguity is when this one dimensional input is
> converted to two dimensional (visual) form.
>
> Also, Hartmut asks whether I could use Ctrl^% to get my input, and the
> answer is no. I was trying to come up with a way to input tensors, and
> for
> tensors the order of indices is important. Using Ctrl^% loses the
> information about which index comes first.
>
> Carl Woll
> Physics Dept
> U of Washington
>
> "DrBob" <majort at cox-internet.com> wrote in message
> news:ackolu$8f8$1 at smc.vnet.net...
> > >>the b subscript of T raised to the a power
> >
> > I read that wrong before.  Sorry.
> >
> > If you mean (the b subscript of T) raised to the a power, the
> keystrokes
> > are T Ctrl-_ b Ctrl-space Ctrl-^ a, and there are no parentheses.
> >
> > If you mean the b subscript of (T raised to the a power), the
> keystrokes
> > are T Ctrl-^ a Ctrl-space Ctrl-_ b, and there MUST be parentheses in
> > order to distinguish between that and the other answer.  If you care.
> > If you don't, then use the other method and avoid the parentheses.
> >
> > I see no other reasonable way to read it, and I see no reliable way to
> > visually distinguish between the two forms without parentheses in one
> of
> > them.
> >
> > >>You can also check the input which does work: first the subscript,
> > then the subscript; the ctrl-space escape *is* needed!
> >
> > That's obviously a typo... so I still haven't seen the answer you DO
> > want.
> >
> > Bobby
> >
> > -----Original Message-----
> > From: Wolf, Hartmut [mailto:Hartmut.Wolf at t-systems.com]
To: mathgroup at smc.vnet.net
> > Subject: [mg34551] RE:  Why do parentheses spuriously
> > appear when I type in a formula?
> >
> >
> > > -----Original Message-----
> > > From: DrBob [mailto:majort at cox-internet.com]
To: mathgroup at smc.vnet.net
> > > Sent: Thursday, May 23, 2002 5:01 PM
> > > Subject: [mg34551] RE:  Why do parentheses spuriously
> > > appear when I type in a formula?
> > >
> > >
> > > >>My exact key strokes are T Ctrl-^ a Ctrl-space Ctrl-_ b.
> > >
> > > Omit "Ctrl-space" and you get what you want.
> >
> > [Hartmut Wolf] No, Bobby, this gives something different: mark the
> box,
> > Menu
> > Format > Show Expression to see
> >
> > Cell[BoxData[
> >     SuperscriptBox["T",
> >       SubscriptBox["a", "b"]]], "Input"]
> >
> > which was *not* wanted, see also Out[2] of my first reply. You can
> also
> > check the input which does work: first the subscript, then the
> > subscript;
> > the ctrl-space escape *is* needed!
> >
> > Quite obviously there is a bug at forming the input stream (or rather
> > it's
> > display in StandardForm). Comparing Out[13] with Out[3] (of my first
> > reply)
> > shows what: instead of invisible brackets \(...\) visible ones (...)
> are
> > interspersed at box formation around T\^a at the very moment when
> ctr-_
> > is
> > pressed.
> >
> > I tried adding a semantic rule to the parser (expression formation)
> >
> > In[3]:=
> > MakeExpression[SubscriptBox[RowBox[{"(", SuperscriptBox[T_, a_],
> ")"}],
> > b_],
> >
> >     StandardForm] :=
> >   MakeExpression[SubscriptBox[SuperscriptBox[T, a], b], StandardForm]
> >
> > but it doesn't trigger (or shouldn't?, or couldn't because this is no
> > issue
> > of expression formation? already too late? I'd like to know!)
> >
> > Trying InputForm...
> >
> > In[6]:= \!\(\((T\^a)\)\_b // InputForm\)
> > Out[6]//InputForm= Subscript[T^a, b]
> >
> > In[7]:= \!\(\(T\^a\)\_b // InputForm\)
> > Out[7]//InputForm= Subscript[T^a, b]
> >
> > ...shows that both forms, with and without explicit parentheses,
> convert
> > to
> > the same InputForm (i.e. same expression). However doing it in reverse
> >
> > In[8]:= Subscript[T^a,b]//StandardForm
> > Out[8]//StandardForm= \!\(\((T\^a)\)\_b\)
> >
> > brings up again the unwanted parentheses. Perhaps for calculation just
> > don't
> > bother with them, but if you finally want to show something printable
> > for
> > publication, the spurious parentheses are disturbing and more than
> ugly!
> >
> > --
> > Hartmut
> >
> >
> > >
> > > Bobby Treat
> > >
> > > -----Original Message-----
> > > From: Wolf, Hartmut [mailto:Hartmut.Wolf at t-systems.com]
To: mathgroup at smc.vnet.net
> > > Sent: Wednesday, May 22, 2002 1:46 AM
> > > Subject: [mg34551]  Why do parentheses spuriously appear
> > > when I type in a formula?
> > >
> > > > -----Original Message-----
> > > > From: Carl K. Woll [mailto:carlw at u.washington.edu]
To: mathgroup at smc.vnet.net
> > > > Sent: Saturday, May 18, 2002 9:52 AM
> > > > Subject: [mg34551]  Why do parentheses spuriously
> > > appear when
> > >
> > > > I type in a
> > > > formula?
> > > >
> > > >
> > > > Hi all,
> > > >
> > > > For some strange reason, I want to type into Mathematica an
> > > > expression that
> > > > should look like T^a_b, that is, the b subscript of T raised
> > > > to the a power.
> > > > My exact key strokes are T Ctrl-^ a Ctrl-space Ctrl-_ b.
> > > > However, when I
> > > > enter this expression into mathematica, it adds (spuriously
> > > > in my mind) some
> > > > parentheses, so that I get (T^a)_b. I would like to know what
> > > > causes these
> > > > parentheses to be added, and if there is anything I can do to
> > > > prevent them
> > > > from appearing. What I have to do now is go back into the
> > > > expression and
> > > > edit out the parentheses.
> > > >
> > > > Carl Woll
> > > > Physics Dept
> > > > U of Washington
> > > >
> > > >
> > > >
> > >
> > > Dear Carl,
> > >
> > > of course as to the why, I could at most speculate. I
> > > wouldn't do that,
> > > instead just add an observation:
> > >
> > > If we input  "T Ctrl-^ a Ctrl-space Ctrl-_ b" as you described, we
> get
> > >
> > > Cell[BoxData[
> > >     SubscriptBox[
> > >       RowBox[{"(",
> > >         SuperscriptBox["T", "a"], ")"}], "b"]], "Input"]
> > >
> > > What you desired however is this:
> > >
> > > Cell[BoxData[
> > >     SubscriptBox[
> > >       SuperscriptBox["T", "a"], "b"]], "Input"]
> > >
> > > If I try one-dimensional input, to reach that I must add a bracket
> \(
> > > ... \)
> > >
> > > In[13]:= \(\(T\^a\)\_b\)
> > > Out[13]= SubscriptBox[SuperscriptBox[T,a],b]
> > >
> > > otherwise I'd get something different and unwanted
> > >
> > > In[2]:= \(T\^a\_b\)
> > > Out[2]= SuperscriptBox[T,SubscriptBox[a,b]]
> > >
> > > Parenthesis as from your undesired behaviour are reproduced with
> > >
> > > In[3]:= \((T\^a)\_b\)
> > > Out[3]= SubscriptBox[RowBox[{(,SuperscriptBox[T,a],)}],b]
> > >
> > > (without the backslashes!) In contrast the complementary T can be
> > > reached by
> > > "T ctrl-_ a ctrl-blank ctrl-^ b"
> > >
> > > Cell[BoxData[
> > >     SuperscriptBox[
> > >       SubscriptBox["T", "a"], "b"]], "Input"]
> > >
> > > or simply as
> > >
> > > In[5]:= \(T\_a\^b\)
> > > Out[5]= SuperscriptBox[SubscriptBox[T,a],b]
> > >
> > > Related forms are produced as they should:
> > >
> > > In[23]:= \(T\_\(a\^b\)\)
> > > Out[23]= SubscriptBox[T,SuperscriptBox[a,b]]
> > >
> > > In[25]:= \(T\^\(a\_b\)\)
> > > Out[25]= SuperscriptBox[T,SubscriptBox[a,b]]
> > >
> > >
> > > If you want to input fluently, perhaps it helps to first enter the
> > > subscription:
> > > "T ctl-_ b arrowleft arrowleft ctrl-^ a end"
> > >
> > > Perhaps you can use the form
> > >
> > > In[29]:= \(T\^a\%b\)//DisplayForm
> > > Out[29]//DisplayForm=
> > >  \!\(\* TagBox[\(T\_b\%a\), DisplayForm]\)
> > >
> > > which inputs straight foreword as "T ctrl-^ a ctrl-% b"
> > >
> > > Cell[BoxData[
> > >     SubsuperscriptBox["T", "b", "a"]], "Input"]
> > >
> > > --
> > > Hartmut
> > >
> > >
> > >
> > >
> >
> >
> >
>
>
>
>




  • Prev by Date: RE: Why do parentheses spuriously appear when I type in a formula?
  • Next by Date: Re: Define a function
  • Previous by thread: RE: Why do parentheses spuriously appear when I type in a formula?
  • Next by thread: Re: Why do parentheses spuriously appear when I type in a formula?