[Date Index]
[Thread Index]
[Author Index]
Re: Subscripts, Doh!!!
*To*: mathgroup at smc.vnet.net
*Subject*: [mg19202] Re: Subscripts, Doh!!!
*From*: Jason Harris <j.harris at phys.canterbury.ac.nz>
*Date*: Tue, 10 Aug 1999 02:52:55 -0400
*References*: <7o5ier$rme@smc.vnet.net> <7oba5o$3p6@smc.vnet.net> <"199908060358.XAA08108"@smc.vnet.net>
*Sender*: owner-wri-mathgroup at wolfram.com
>(Colin Rose) Wrote:
>
>David Bailey <db at salford-software.com> wrote:
>
>> I have always found the way Mathematica handles subscripts rather neat.
>
>Me too. Mostly. And it's much better under v4 than v3.
[Snipped : Observations about subscripts and improvements in version 4. ]
(I missed these in my earlier post... mainly since these are not the
main reasons I personally use Symbolizations and Notations.
Admittedly though, it appears that the handling by "solve" type
functions looks like it has been improved.)
Just using subscripted symbols has its problems though...
For instance \!\(\(?m\_1\)\), that is ? m sub 1 will yield an error.
As will something like \!\(Clear[m\_1]\), that is Clear[ m sub 1].
etc.
>
>3. Symbolize ?
>_______________
>
>
>Symbolize looks like a pretty amazing piece of work:
>trying to retrofit a new framework on an existing structure.
>That being said, I must say that I don't like Symbolize.
>I shall offer 3 reasons:
Symbolize is not a universal panacea. Its main use where it is
indispensable is when you want rules and definitions involving
subscripted symbols. However, one should still be weary of when to
use it and when not to use it.
>(i) << Utilities`Notation`
[snipped parts (illustrating the creation of subscripted expressions
and symbols that have the same output form)]
>OUCH !
>We now have two sets of "identical" notation in use.
>In the one set, m_2 is a Symbol; in the other set, m_2 is a Subscript
>(not a Symbol). They both look the same on screen. Tres confusing !
This is really just a case of your point number (iii) which I address below.
>
>(ii) More generally, what you see is NOT what you get
> The Symbolize package uses a palette based entry method.
> The reason it uses a palette entry system is because underneath,
> it is adding a much more complicated tag box structure. So while
> it looks like:
>
> Symbolize[x_2]
>
> in fact the full Input story is:
>
> Symbolize[NotationBoxTag[\(x\_2\)]]
>
> This makes reproducing results in textbooks very difficult, or cumbersome.
In v4 you can now see the tag boxes behind the symbolizations and
notations. It is sooooo much easier to visually identify the
structures being modified. Also using Esc-symbolize-Esc and
Esc-notation-Esc makes entering these structures much easier.
(Actually there is a slight glitch in unix & linux versions which
causes these styles not to be shown properly... To do with the
handling of SelectedNotebook[] being different in Windows and
Macintosh systems to that of Linux & Unixes. There is an update for
linux systems at http://resources.wolfram.com/packages/notation/ .)
>
>(iii) Ideally, one would be able to
>
> Symbolize[ Subscript[x, _Integer] ]
>
> and then be able to work with
>
> Table[x_i, {i, 1, 4}]
>
> where each of x_1, x_2, x_3 etc are treated as symbols.
> But none of this works.
Although it is not in the introduction of the documentation, methods
to accomplish this are actually given in the documentation. (Under
complex patterns...)
Here is some code to do what you request. (It looks much better on
screen than below. It takes only 3 lines on screen.)
\!\(\*
RowBox[{
RowBox[{"Symbolize", "[",
TagBox[
SubscriptBox["m",
TagBox[\(i_?unparsedNumericQ\),
NotationPatternTag,
TagStyle->"NotationPatternWrapperStyle"]],
NotationBoxTag,
TagStyle->"NotationTemplateStyle"], "]"}],
"\n", \(m\_\(i_?IntegerQ\) := ToExpression\ @\ MakeBoxes[\ m\_i]\),
"\n", \(unparsedNumericQ\ \ @\ \ boxes___\ := \ \
\[IndentingNewLine]ReleaseHold\ @\ \(Hold[
NumericQ]\ @\ \(Hold[Unevaluated]\ @\
ToExpression[boxes, StandardForm, Hold]\)\)\)}]\)
Or in plain text
Symbolize[
NotationBoxTag[
SubscriptBox["m",
TagBox[RowBox[List["i_", "?", "unparsedNumericQ"]],
NotationPatternTag,
Rule[TagStyle, "NotationPatternWrapperStyle"]]]]]
Subscript[m, i_?IntegerQ] := ToExpression @ MakeBoxes @ Subscript[m, i]
unparsedNumericQ @ boxes___ :=
ReleaseHold @
Hold[NumericQ] @
Hold[Unevaluated] @ ToExpression[boxes, StandardForm, Hold]
The function UnparsedNumericQ carefully tries to determine if a
string is a number without evaluating it.
Here is an illustrative example. (Assuming the Notation package has
been loaded and the above code entered.)
In[3]:=
\!\(Table[m\_i, {i, 1, 3}] === {m\_1, m\_2, m\_3}\)
Out[3]=
True
Yet m subscripted by things other than integers remain
"expressionized" rather than "symbolized".
In[4]:=
\!\(Head[m\_i]\)
Out[4]=
Subscript
While m subscripted by integers is symbolized.
In[5]:=
\!\(Head[m\_4]\)
Out[5]=
Symbol
Of course, this is all possible programmatically so one can easily
define a function to automate this. In summary and to reiterate, just
like any programming structure in Mathematica, Symbolize will not be
applicable in every situation, but when applicable it can lead to
elegant solutions.
Cheers,
Jason Harris
Prev by Date:
**Re: Any Hazards When Installing V3 and V4 in Parallel?**
Next by Date:
**Re: Automatic grouping of animation cells**
Previous by thread:
**Re: Subscripts, Doh!!!**
Next by thread:
**Re: Subscripts, Doh!!!**
| |