Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #4398 > unrolled thread

Treat subscripted variables as symbols

Started byCamille <camille.segarra@gmail.com>
First post2011-08-14 12:22 +0000
Last post2011-08-19 10:33 +0000
Articles 5 — 4 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  Treat subscripted variables as symbols Camille <camille.segarra@gmail.com> - 2011-08-14 12:22 +0000
    Re: Treat subscripted variables as symbols Simon <simonjtyler@gmail.com> - 2011-08-15 00:23 +0000
    Re: Treat subscripted variables as symbols "Alexey Popkov" <lehin.p@gmail.com> - 2011-08-17 09:53 +0000
    Re: Treat subscripted variables as symbols Ralph Dratman <ralph.dratman@gmail.com> - 2011-08-18 07:29 +0000
    Re: Treat subscripted variables as symbols "Alexey Popkov" <lehin.p@gmail.com> - 2011-08-19 10:33 +0000

#4398 — Treat subscripted variables as symbols

FromCamille <camille.segarra@gmail.com>
Date2011-08-14 12:22 +0000
SubjectTreat subscripted variables as symbols
Message-ID<j28emt$3fa$1@smc.vnet.net>
Dear all,

I try in mathematica to define a function using subscripted variables and subscripted parameters. It seems however that mathematica is not able to treat these subscripted variables as symbols. Indeed, when I use non subscripted variables and parameters it "works".

For example:
In: Function[##,Subscript[A, 2] Subscript[x, 1] ] & @@ {Subscript[A, 2]}

Out:Function::flpar: Parameter specification Subscript[A, 2] in Subscript[A, 2]\[Function]Subscript[A, 2] Subscript[x, 1] should be a symbol or a list of symbols. 

But if I do:
In: Function[##,A x] & @@ {A}
Out: a\[Function]a x
(It is "working")

Any Idea?

Thanks in advance,

Camille


>>

[toc] | [next] | [standalone]


#4412

FromSimon <simonjtyler@gmail.com>
Date2011-08-15 00:23 +0000
Message-ID<j29ot4$7ci$1@smc.vnet.net>
In reply to#4398
Hi Camille,

The easiest way to make subscripted variables into symbols is to use Symbolize from the Notation package.

Needs["Notation`"];
Symbolize[ParsedBoxWrapper[SubscriptBox["_", "_"]]]

See http://stackoverflow.com/q/5481216/421225 for more details.

[toc] | [prev] | [next] | [standalone]


#4443

From"Alexey Popkov" <lehin.p@gmail.com>
Date2011-08-17 09:53 +0000
Message-ID<j2g327$1ch$1@smc.vnet.net>
In reply to#4398
You may try to use the SubscriptSymbols command from Andrew Moylan's 
package:

http://sites.google.com/site/andrewjmoylan/mathematica
http://sites.google.com/site/andrewjmoylan/Moylan.zip

Description from the web-page: "This package makes Mathematica treat all the 
subscripts in your notebook as symbols. I used it for a long time because 
it's standard in physics to treat symbols like r, r0, and rcore as unique 
variables.

If you set SubscriptSymbols = True, every expression with head SubscriptBox 
will be transparently converted into a symbol; and that symbol will display 
as the corresponding SubscriptBoxes on output. You won't normally need to 
know about the underlying proxy symbol, but you can use Information[] to 
find out its name."


"Camille" <camille.segarra@gmail.com> wrote: 
news:j28emt$3fa$1@smc.vnet.net...
> Dear all,
>
> I try in mathematica to define a function using subscripted variables and 
> subscripted parameters. It seems however that mathematica is not able to 
> treat these subscripted variables as symbols. Indeed, when I use non 
> subscripted variables and parameters it "works".
>
> For example:
> In: Function[##,Subscript[A, 2] Subscript[x, 1] ] & @@ {Subscript[A, 2]}
>
> Out:Function::flpar: Parameter specification Subscript[A, 2] in 
> Subscript[A, 2]\[Function]Subscript[A, 2] Subscript[x, 1] should be a 
> symbol or a list of symbols.
>
> But if I do:
> In: Function[##,A x] & @@ {A}
> Out: a\[Function]a x
> (It is "working")
>
> Any Idea?
>
> Thanks in advance,
>
> Camille
>
>
>>>
> 

[toc] | [prev] | [next] | [standalone]


#4461

FromRalph Dratman <ralph.dratman@gmail.com>
Date2011-08-18 07:29 +0000
Message-ID<j2if0f$bmc$1@smc.vnet.net>
In reply to#4398
I've started using lists of strings instead of symbols in place of what some
programming languages refer to as an "enumerated type." I find it difficult
to keep track of Mathematica's rules of evaluating or not evaluating. I
guess this arises because Mathematica's language does many different kinds
of things with symbols, and tries to be transparent for each type of task.
The result, in terms of references and values and so forth, seems convoluted
to me.

That is not a complaint; I'm having a lot of fun with Mathematica. But when
I want to think like a programmer, I prefer to narrow my view for
utilitarian purposes. That's why I am using strings -- in effect, building
my own symbol tables.

That's wasteful, I'm sure, but so far I can't figure out the right way to do
it. Has anyone constructed a compiler in Mathematica? If so, that code might
tell the tale.

Ralph


On Wed, Aug 17, 2011 at 5:52 AM, Alexey Popkov <lehin.p@gmail.com> wrote:

> You may try to use the SubscriptSymbols command from Andrew Moylan's
> package:
>
> http://sites.google.com/site/andrewjmoylan/mathematica
> http://sites.google.com/site/andrewjmoylan/Moylan.zip
>
> Description from the web-page: "This package makes Mathematica treat all
> the
> subscripts in your notebook as symbols. I used it for a long time because
> it's standard in physics to treat symbols like r, r0, and rcore as unique
> variables.
>
> If you set SubscriptSymbols = True, every expression with head SubscriptBox
> will be transparently converted into a symbol; and that symbol will display
> as the corresponding SubscriptBoxes on output. You won't normally need to
> know about the underlying proxy symbol, but you can use Information[] to
> find out its name."
>
>
> "Camille" <camille.segarra@gmail.com> wrote:
> news:j28emt$3fa$1@smc.vnet.net...
> > Dear all,
> >
> > I try in mathematica to define a function using subscripted variables and
> > subscripted parameters. It seems however that mathematica is not able to
> > treat these subscripted variables as symbols. Indeed, when I use non
> > subscripted variables and parameters it "works".
> >
> > For example:
> > In: Function[##,Subscript[A, 2] Subscript[x, 1] ] & @@ {Subscript[A, 2]}
> >
> > Out:Function::flpar: Parameter specification Subscript[A, 2] in
> > Subscript[A, 2]\[Function]Subscript[A, 2] Subscript[x, 1] should be a
> > symbol or a list of symbols.
> >
> > But if I do:
> > In: Function[##,A x] & @@ {A}
> > Out: a\[Function]a x
> > (It is "working")
> >
> > Any Idea?
> >
> > Thanks in advance,
> >
> > Camille
> >
> >
> >>>
> >
>
>

[toc] | [prev] | [next] | [standalone]


#4472

From"Alexey Popkov" <lehin.p@gmail.com>
Date2011-08-19 10:33 +0000
Message-ID<j2le56$nca$1@smc.vnet.net>
In reply to#4398
----- Original Message ----- 
From: "Ralph Dratman" <ralph.dratman@gmail.com>
To: "Alexey Popkov" <lehin.p@gmail.com>
Cc: <mathgroup@smc.vnet.net>
Sent: Wednesday, August 17, 2011 7:37 PM
Subject: Re: Treat subscripted variables as symbols


> I've started using lists of strings instead of symbols in place of what 
> some
> programming languages refer to as an "enumerated type." I find it 
> difficult
> to keep track of Mathematica's rules of evaluating or not evaluating. I
> guess this arises because Mathematica's language does many different kinds
> of things with symbols, and tries to be transparent for each type of task.
> The result, in terms of references and values and so forth, seems 
> convoluted
> to me.
>
> That is not a complaint; I'm having a lot of fun with Mathematica. But 
> when
> I want to think like a programmer, I prefer to narrow my view for
> utilitarian purposes. That's why I am using strings -- in effect, building
> my own symbol tables.
>
> That's wasteful, I'm sure, but so far I can't figure out the right way to 
> do
> it. Has anyone constructed a compiler in Mathematica? If so, that code 
> might
> tell the tale.
>
> Ralph

You can convert a string containing correct symbol name to a symbol by using 
the Symbol command or by using ToExpression. Note three-argument form of 
ToExpression:
ToExpression["symbolName",InputForm,yourFunction]
This form allows you to pass your symbol to arbitrary function with Hold* 
attribute without evaluating your symbol.

You can find description of the standard evaluation sequence on the top of 
the following Documentation page:
http://reference.wolfram.com/mathematica/tutorial/Evaluation.html
I strongly reccommend to become familiar with the standard evaluation 
sequence bacause it explains many "strange" aspects of expression evaluation 
in Mathematica. Some experiments with the Trace command my help with 
understanding it significantly. You could also try to use WReach's traceView 
utilities:
http://stackoverflow.com/questions/5459735/the-clearest-way-to-represent-mathematicas-evaluation-sequence 

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web