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

What is f[1]? Advanced question

69 views
Skip to first unread message

amannucci

unread,
Jun 25, 2013, 9:06:04 PM6/25/13
to
I have found a Mathematica program with the following construct:
x[1]=0.1
x[2]=0.2
x[3]=0.3

or
Do[x[i]=i/10.,{i,1,3}]

x is not a function. It is not a list. What is it? If I query x thus:
?x

the answer is just what I have written above. Mathematica knows about x[1], x[2], etc. How does Mathematica know about the "elements" of x?

In some other sense, I could have written:
y1 = 0.1
y2 = 0.2
y3 = 0.3

But
?y

obviously gives a different result (just returns y).

Thank you.

Tomas Garza

unread,
Jun 26, 2013, 12:59:16 AM6/26/13
to

It is possibly a previously declared "Array" with the name "x", and the three lines are assigning values to the elements of the array. Check for Array in the Help.
-Tomas

Mannucci, Anthony J (335G)

unread,
Jun 26, 2013, 12:59:36 AM6/26/13
to

I believe I figured this out. x[] is a function that has definitions only at certain values. A function can be defined thus:
x[x_] :=
which matches the rhs to a pattern (x_), or a function can be defined thus:
x[1] = 0.1
which means: if the function argument expression evaluates to 1, then substitute 0.1. However, if the function argument evaluated to something other than 1, there is no substitution made, so that x[2] just evaluates to x[2].

I don't think there is an Array data type in Mathematica.

Thank you!

-Tony


From: Tomas Garza <tgar...@msn.com<mailto:tgar...@msn.com>>
Date: Tuesday, June 25, 2013 6:27 PM
To: Tony Mannucci <Anthony.J...@jpl.nasa.gov<mailto:Anthony.J...@jpl.nasa.gov>>, "math...@smc.vnet.net<mailto:math...@smc.vnet.net>" <math...@smc.vnet.net<mailto:math...@smc.vnet.net>>
Subject: Re: What is f[1]? Advanced question

It is possibly a previously declared "Array" with the name "x", and the three lines are assigning values to the elements of the array. Check for Array in the Help.

-Tomas


Bob Hanlon

unread,
Jun 26, 2013, 1:00:37 AM6/26/13
to

Do[x[i] = i/10., {i, 1, 3}]


x is a user-defined function whose domain is just the integers 1, 2, and
3. Like all functions, its Head is Symbol.


Head /@ {x, Exp, Mean}


{Symbol, Symbol, Symbol}


The function definitions are stored in the DownValues of the symbol


DownValues[x]


{HoldPattern[x[1]] :> 0.1, HoldPattern[x[2]] :> 0.2, HoldPattern[x[3]] :>
0.3}


Like any function, when given an argument outside of its defined domain, it
returns unevaluated.


x[4]


x[4]



Bob Hanlon




On Tue, Jun 25, 2013 at 9:14 PM, amannucci
<Anthony.J...@jpl.nasa.gov>wrote:

Bill Rowe

unread,
Jun 27, 2013, 6:24:23 AM6/27/13
to
On 6/25/13 at 9:14 PM, Anthony.J...@jpl.nasa.gov (amannucci)
wrote:

>I have found a Mathematica program with the following construct:
>x[1]=0.1
>x[2]=0.2
>x[3]=0.3

>or Do[x[i]=i/10.,{i,1,3}]

>x is not a function. It is not a list. What is it?

x is a function that you have defined at specific values.

Notice that

In[1]:= x[1] = 0.1;
x[2] = 0.2;
x[3] = 0.3;

In[4]:= DownValues[x]

Out[4]= {HoldPattern[x(1)]:>0.1,HoldPattern[x(2)]:>0.2,HoldPattern[x(3)]:=
>0.3}

and

In[5]:= f[y_] := y^2

In[6]:= DownValues[f]

Out[6]= {HoldPattern[f(y_)]:>y^2}

That is the values for x are stored exactly like the definition
of an expression is what most think of as a function in Mathematica.


amannucci

unread,
Jun 27, 2013, 6:25:04 AM6/27/13
to
Thanks. This is very helpful. I remain puzzled by this:

u // FullForm
FullForm[Symbol["u"]]
FullForm[Unevaluated[Symbol["u"]]
Head[u]

FullForm[{1, 2, 3}]
Head[{1, 2, 3}]

In other words, Head and FullForm seem consist for the list, and inconsistent for the variable u. u's full form is just, literally "u", not Symbol["u"]. But the list's FullForm starts with "List". Head of Symbol["u"] is not Symbol, but "u". What gives?


David Bailey

unread,
Jun 28, 2013, 3:48:00 AM6/28/13
to
I don't think there is too much mystery here - FullForm would simply be
too clumsy if it expanded symbols into Symbol constructs. As it is,
FullForm is incredibly useful.

I wish there was also a variant that did not evaluate its argument. True
one can write:

expression //Hold//FullForm

but the expression gets contaminated with Hold.

David Bailey
http://www.dbaileyconsultancy.co.uk


Louis Talman

unread,
Jun 28, 2013, 3:49:41 AM6/28/13
to
On Tue, 25 Jun 2013 19:14:08 -0600, amannucci
<Anthony.J...@jpl.nasa.gov> wrote:

> I have found a Mathematica program with the following construct:
> x[1]=0.1
> x[2]=0.2
> x[3]=0.3
> or
> Do[x[i]=i/10.,{i,1,3}]
> x is not a function. It is not a list. What is it? If I query x thus:
> ?x

x most certainly *is* a function. Its a function whose domain contains
just the three numbers 1, 2, and 3.

And it is *not* an array. Mathematica has lists, which it uses as arrays
on occasion. An array, y, is indexed with double brackets: a[[1]],
a[[2]], etc.

--Louis A. Talman
Department of Mathematical and Computer Sciences
Metropolitan State University of Denver

<http://rowdy.msudenver.edu/~talmanl>
.

John Doty

unread,
Jun 28, 2013, 3:48:20 AM6/28/13
to
On Thursday, June 27, 2013 4:25:04 AM UTC-6, amannucci wrote:
> Thanks. This is very helpful. I remain puzzled by this:
>
>
>
> u // FullForm
>
> FullForm[Symbol["u"]]
>
> FullForm[Unevaluated[Symbol["u"]]
>
> Head[u]
>
>
>
> FullForm[{1, 2, 3}]
>
> Head[{1, 2, 3}]
>
>
>
> In other words, Head and FullForm seem consist for the list, and inconsistent for the variable u. u's full form is just, literally "u", not Symbol["u"]. But the list's FullForm starts with "List". Head of Symbol["u"] is not Symbol, but "u". What gives?

If FullForm did what you expected, its output would be infinite, because every expression in Mathematica has a head. Remember that the head of an expression is itself an (arbitrary!) expression. So, FullForm "bottoms out" when further expansion would expose an elementary head like Symbol or Integer.

Tomas Garza

unread,
Jun 29, 2013, 4:48:04 AM6/29/13
to

In[2]:= Array[x, 3]

Out[2]= {x[1], x[2], x[3]}

x is an array and is indexed with single brackets (cf. the Help browser).
-Tomas

> From: tal...@gmail.com
> Subject: Re: What is f[1]? Advanced question

Helen Read

unread,
Jul 1, 2013, 5:45:09 AM7/1/13
to
x is not an array. It is a symbol which in this case has not been
defined. It does not refer to the list.

If you were to name the array, like this:

b= Array[x, 3]

The list is named b, and you can extract the entries with double brackets.

b[[2]]

Perhaps your confusion arises from the fact that b[[2]] and x[2] are
equal. Here is another example that will perhaps clarify.

c = Array[x, 5, -8]

c[[1]] (* first entry of c. Not the same as x[1] *)

c[[2]] (* second entry of c. Not the same as x[2] *)
0 new messages