MathGroup Archive 2008

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

Search the Archive

Re: Subscript Bug?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg90131] Re: Subscript Bug?
  • From: Jean-Marc Gulliet <jeanmarc.gulliet at gmail.com>
  • Date: Mon, 30 Jun 2008 04:52:44 -0400 (EDT)
  • Organization: The Open University, Milton Keynes, UK
  • References: <g47l28$t66$1@smc.vnet.net>

Aaron Fude wrote:

> I have this code in a cell:
> 
> Subscript[H, 1] = 110; Subscript[H, 2] = 90;
> H = Subscript[H, 1] + Subscript[H, 2];
> Tanh[Subscript[H, 1]]
> 
> The first time I execute the cell, I get
> 
> Tanh[Subscript[200, 1]]
> 
> which of course is nonsense.
> 
> A second execution, yields the correct answer:
> 
> Tanh[110]
> 
> Is this a feature that I don't understand or a bug?

*NO BUG HERE*. The "feature" you are looking for is indeed the standard 
evaluation process of an expression by Mathematica (the main loop) and 
you must keep in mind that _subscripted names are not symbols_.

That is they are *not* atomic.

Thus any elements, or their values, within the head *Subscript* can (and 
will) change if any replacement rules may be applied.

To correctly deal with subscripted names as if they were symbols, you 
must use the *Symbolize* command from the *Notation* package [1, 2, 3].

The first time you execute the cell, H is equal to 200 and is replaced 
in the Tanh expression.

Then second time you execute the cell, H_1 becomes 200_1 and the 
expression 200_1 gets the values 100.

You can follow the whole process below.

In[1]:= Subscript[H,1]=110;Subscript[H,2]=90;
H=Subscript[H,1]+Subscript[H,2];
Tanh[Subscript[H,1]]//Trace

Out[3]= {{{H,200},Subscript[200, 1]},Tanh[Subscript[200, 1]]}

In[4]:= ?Global`*
Global`H
H0

In[5]:= Tanh[Subscript[H,1]]//Trace

Out[5]= {{{H,200},Subscript[200, 1]},Tanh[Subscript[200, 1]]}

In[6]:= Subscript[H,1]=110;Subscript[H,2]=90;
Subscript[200,1]===Subscript[H,1]

Out[7]= True

In[8]:= Tanh[Subscript[H,1]]//Trace

Out[8]= {{{H,200},Subscript[200, 1],110},Tanh[110]}

In[9]:= <<Notation`
Symbolize[Subscript[H, _]]
Subscript[H,1]=110;Subscript[H,2]=90;
H=Subscript[H,1]+Subscript[H,2];
Tanh[Subscript[H,1]]

Out[13]= Tanh[110]

Regards,
-- Jean-Marc

(* Easy cut and past without the outputs. *)

Subscript[H, 1] = 110; Subscript[H, 2] = 90;
H = Subscript[H, 1] + Subscript[H, 2];
Trace[Tanh[Subscript[H, 1]]]

Information["Global`*", LongForm -> False]

Trace[Tanh[Subscript[H, 1]]]

Subscript[H, 1] = 110; Subscript[H, 2] = 90;
Subscript[200, 1] === Subscript[H, 1]

Trace[Tanh[Subscript[H, 1]]]

<< "Notation`"
Symbolize[ParsedBoxWrapper[\(H \_ _\)]]
Subscript[H, 1] = 110; Subscript[H, 2] = 90;
H = Subscript[H, 1] + Subscript[H, 2];
Tanh[Subscript[H, 1]]

[1] http://reference.wolfram.com/mathematica/Notation/tutorial/\
NotationSymbolizeAndInfixNotation.html

[2] Notation/guide/NotationPackage

[3] http://reference.wolfram.com/mathematica/Notation/ref/Symbolize.html


  • Prev by Date: Re: Subscript Bug?
  • Next by Date: Re: Re: Re: Re: Happy Birthday Mathematica!
  • Previous by thread: Re: Subscript Bug?
  • Next by thread: Re: Subscript Bug?