Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Variable names in Mathematica

340 views
Skip to first unread message

amannuc1

unread,
Sep 18, 2008, 6:14:14 AM9/18/08
to
Dear Community,

I can't seem to get an answer to this simple question: are greek letters
allowed as variable names in Mathematica? I have tried this with limited
success (v 5.2). It seems that some greek letters are reserved, for example
alpha. I am not sure about that. Any insight is appreciated. Thanks!

-Tony

Jens-Peer Kuska

unread,
Sep 18, 2008, 7:26:46 AM9/18/08
to
Hi,

foo[\[Alpha]_, \[ScriptA]_] := \[Alpha]*\[ScriptA]

and

foo[2, 3]

gives
6

and
foo[2, \[Beta]]

gives

2 \[Beta]

Regards
Jens

Peter Breitfeld

unread,
Sep 18, 2008, 7:31:41 AM9/18/08
to
amannuc1 schrieb:

for variable names you can use all latin, greek, script and gothic
letters. Exceptions are the "one letter" functions or constants:
C, D, E, I, K, N, O and $, which are protected.

K isn't protected, but lives in the System` context and is used
internally e.g. as summation variable. It will not be cleared with
Clear["Global`*].

Gruss Peter
--
==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==-==
Peter Breitfeld, Bad Saulgau, Germany -- http://www.pBreitfeld.de

magma

unread,
Sep 19, 2008, 5:14:59 AM9/19/08
to
On Sep 18, 1:31 pm, Peter Breitfeld <ph...@t-online.de> wrote:
> amannuc1 schrieb:
>
> > Dear Community,
>
> > I can't seem to get an answer to this simple question: are greek letter=
s
> > allowed as variable names in Mathematica? I have tried this with limite=
d
> > success (v 5.2). It seems that some greek letters are reserved, for exa=

mple
> > alpha. I am not sure about that. Any insight is appreciated. Thanks!
>
> > -Tony
>
> for variable names you can use all latin, greek, script and gothic
> letters. Exceptions are the "one letter" functions or constants:
> C, D, E, I, K, N, O and $, which are protected.
>
> K isn't protected, but lives in the System` context and is used
> internally e.g. as summation variable. It will not be cleared with
> Clear["Global`*].
>
> Gruss Peter
> --
> ==-==-==-==-==-==-==-==-==-==-==
=-==-==-==-==-==-==-==-==-==-==-=

==
> Peter Breitfeld, Bad Saulgau, Germany --http://www.pBreitfeld.de

.....and of course greek Pi is protected too.

Murray Eisenberg

unread,
Sep 19, 2008, 5:16:47 AM9/19/08
to
NO, they are NOT reserved. Example (converted to InputForm, which I'd
never use when actually entering Greek letters

\[Alpha]=2;
\[Alpha]+10
12

Perhaps you're confusing some Greek letters with similarly-shaped
symbols, such as the Element symbol or the Sum symbol.

amannuc1 wrote:
> Dear Community,
>
> I can't seem to get an answer to this simple question: are greek letters
> allowed as variable names in Mathematica? I have tried this with limited
> success (v 5.2). It seems that some greek letters are reserved, for example


> alpha. I am not sure about that. Any insight is appreciated. Thanks!
>
> -Tony
>

--
Murray Eisenberg mur...@math.umass.edu
Mathematics & Statistics Dept.
Lederle Graduate Research Tower phone 413 549-1020 (H)
University of Massachusetts 413 545-2859 (W)
710 North Pleasant Street fax 413 545-1801
Amherst, MA 01003-9305

amannuc1

unread,
Sep 20, 2008, 4:58:37 AM9/20/08
to
On Sep 19, 2:16 am, Murray Eisenberg <mur...@math.umass.edu> wrote:
> NO, they are NOT reserved. Example (converted to InputForm, which I'd
> never use when actually entering Greek letters
>
> \[Alpha]=2;
> \[Alpha]+10
> 12
>
> Perhaps you're confusing some Greek letters with similarly-shaped
> symbols, such as the Element symbol or the Sum symbol.
>
> amannuc1 wrote:
> > Dear Community,
>
> > I can't seem to get an answer to this simple question: are greek letter=
s
> > allowed as variable names in Mathematica? I have tried this with limite=
d
> > success (v 5.2). It seems that some greek letters are reserved, for exa=

mple
> > alpha. I am not sure about that. Any insight is appreciated. Thanks!
>
> > -Tony
>
> --
> Murray Eisenberg mur...@math.umas=

s.edu
> Mathematics & Statistics Dept.
> Lederle Graduate Research Tower phone 413 549-1020 (H)
> University of Massachusetts 413 545-2859 (=

W)
> 710 North Pleasant Street fax 413 545-1801
> Amherst, MA 01003-9305

OK. Thanks. I can't seem to reproduce the problem. I will keep
learning.

-Tony

amannuc1

unread,
Sep 20, 2008, 5:01:15 AM9/20/08
to
On Sep 18, 4:26 am, Jens-Peer Kuska <ku...@informatik.uni-leipzig.de>
wrote:

> Hi,
>
> foo[\[Alpha]_, \[ScriptA]_] := \[Alpha]*\[ScriptA]
>
> and
>
> foo[2, 3]
>
> gives
> 6
>
> and
> foo[2, \[Beta]]
>
> gives
>
> 2 \[Beta]
>
> Regards
> Jens
>
> amannuc1 wrote:
> > Dear Community,
>
> > I can't seem to get an answer to this simple question: are greek letter=
s
> > allowed as variable names in Mathematica? I have tried this with limite=
d
> > success (v 5.2). It seems that some greek letters are reserved, for exa=

mple
> > alpha. I am not sure about that. Any insight is appreciated. Thanks!
>
> > -Tony

That's great. Thank you.

Is there an issue doing this with subscripts? For example, suppose my
variable is
\!\(x\_y\)

Can I put that inside a function as you have done? I am having
problems with this.

-Tony

Szabolcs Horvát

unread,
Sep 20, 2008, 4:55:59 AM9/20/08
to
Murray Eisenberg wrote:
> NO, they are NOT reserved. Example (converted to InputForm, which I'd
> never use when actually entering Greek letters
>
> \[Alpha]=2;
> \[Alpha]+10
> 12
>
> Perhaps you're confusing some Greek letters with similarly-shaped
> symbols, such as the Element symbol or the Sum symbol.
>

Maybe confusing \[Alpha] with \[Proportional]? Use ESC a ESC to type alpha.

Jens-Peer Kuska

unread,
Sep 21, 2008, 11:47:45 PM9/21/08
to
Hi,

yes Subscript[x,y] is not a symbol. You can use
the Notation package to Symbolize[] it.

Regards
Jens

Bill Rowe

unread,
Sep 21, 2008, 11:47:55 PM9/21/08
to
On 9/20/08 at 5:00 AM, Anthony.J...@jpl.nasa.gov (amannuc1)
wrote:

>Is there an issue doing this with subscripts? For example, suppose
>my variable is \!\(x\_y\)

>Can I put that inside a function as you have done? I am having
>problems with this.

With a default setup, Mathematica does not work well with
subscripted variables. A naive implementation will not work as
expected in many cases.

The head of a normal Mathematica variable is Symbol. The head of
a subscripted variable is Subscript. This difference will lead
to behavior different than what you might expect in some cases.

This can be remedied by using Symbolize in the Notation package.
But from my perspective, the advantages of subscripted variables
are out weighed by the extra effort spent making subscripted
variables work well with Mathematica's various functions.

Jean-Marc Gulliet

unread,
Sep 21, 2008, 11:49:42 PM9/21/08
to
amannuc1 wrote:

Subscripted names are not symbols and sometimes Mathematica has
difficulties handling them as variables.

If you want to use subscripted variables, you should use the Symbolize
command from the Notation package [1, 2].

Regards,
- Jean-Marc

[1] /Notation, Symbolize and InfixNotation/
http://reference.wolfram.com/mathematica/Notation/tutorial/NotationSymbolizeAndInfixNotation.html

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

0 new messages