Re: Partial evaluation

• To: mathgroup at smc.vnet.net
• Subject: [mg21144] Re: Partial evaluation
• From: "Allan Hayes" <hay at haystack.demon.co.uk>
• Date: Fri, 17 Dec 1999 01:21:45 -0500 (EST)
• References: <8320dg\$glm@smc.vnet.net>
• Sender: owner-wri-mathgroup at wolfram.com

```Kevin,

The part assignments

A[[i1, i2 ... in]] = expr

and

A[[i1, i2 ... in]] := expr

work if and only if
- A is a symbol that has been assigned a value with Set, for example

A = data

(not with A:= data)
- and data has a part with index  (i1,i2 ... in).

A is not evaluated in this process.

Allan
---------------------
Allan Hayes
Mathematica Training and Consulting
Leicester UK
www.haystack.demon.co.uk
hay at haystack.demon.co.uk
Voice: +44 (0)116 271 4198
Fax: +44 (0)870 164 0565

"Kevin Jaffe" <kj0 at mailcity.com> wrote in message
news:8320dg\$glm at smc.vnet.net...
> I'm sure this is a FAQ, but I haven't found the answer.
>
> First we define:
>
>     In[1]:= A = {{0, 0}, {0, 0}}
>
>     Out[1]= {{0, 0}, {0, 0}}
>
>
> Then the following assignment works:
>
>     In[2]:= Part[A, 1, 1] = 1
>
>     Out[2]= 1
>
>     In[3]:= A
>
>     Out[3]= {{1, 0}, {0, 0}}
>
> But this one doesn't:
>
>     In[4]:= Part@@{A, 1, 1} = 2
>
>     Set::write: Tag Apply in Part @@ {{{1, 0}, {0, 0}}, 1, 1} is
Protected.
>
>     Out[4]= 2
>
>     In[5]:= A
>
>     Out[5]= {{1, 0}, {0, 0}}
>
> And this is even worse, of course:
>
>     In[6]:= Evaluate[Part@@{A, 1, 1}] = 2
>
>     Set::setraw: Cannot assign to raw object 1.
>
>     Out[6]= 2
>
>     In[7]:= A
>
>     Out[7]= {{1, 0}, {0, 0}}
>
> I understand the reasons for the error messages, but I don't know how
> to get around the problem.  What I need is to partially evaluate the
> left-hand side of In[4], but I don't know how to do this.
>
> The reason I want to do things like "Part@@{A, 1, 1} = 2" is that I'm
> trying to write a module that must modify entries in an n_1 x n_2 x
> ... x n_k array A of arbitrary dimension k.  I can compute the desired
> multi-index v = {i_1, i_2,..., i_k} for the array without knowing the
> array's dimension, but I can't figure a way to assign to the
> location A[[i_1, i_2, ..., i_k]].
>
> Is there any way to do what I'm trying to do?
>
> Thanks!
>
> KJ
>
>
>
> LYCOShop is now open. On your mark, get set, SHOP!!!
> http://shop.lycos.com/
> .
>

```

• Prev by Date: Re: newtons method, notation
• Next by Date: Re: fortran dynamic link library
• Previous by thread: Re: Partial evaluation
• Next by thread: Re: Partial evaluation