       Re: Partial evaluation

• To: mathgroup at smc.vnet.net
• Subject: [mg21155] Re: [mg21094] Partial evaluation
• From: "Tomas Garza" <tgarza at mail.internet.com.mx>
• Date: Fri, 17 Dec 1999 01:22:22 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

```Kevin Jaffe [kj0 at mailcity.com] wrote:

> I'm sure this is a FAQ, but I haven't found the answer.
>
> First we define:
>
>     In:= A = {{0, 0}, {0, 0}}
>
>     Out= {{0, 0}, {0, 0}}
>
>
> Then the following assignment works:
>
>     In:= Part[A, 1, 1] = 1
>
>     Out= 1
>
>     In:= A
>
>     Out= {{1, 0}, {0, 0}}
>
> But this one doesn't:
>
>     In:= Part@@{A, 1, 1} = 2
>
>     Set::write: Tag Apply in Part @@ {{{1, 0}, {0, 0}}, 1, 1} is
> Protected.
>
>     Out= 2
>
>     In:= A
>
>     Out= {{1, 0}, {0, 0}}
>
<Snip>

> What I need is to partially evaluate the
> left-hand side of In, 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?

Maybe this will do what you want:

In:=
b = Array[a, {2, 2, 3}]
Out=
{{{a[1, 1, 1], a[1, 1, 2], a[1, 1, 3]}, {a[1, 2, 1], a[1, 2, 2],
a[1, 2, 3]}}, {{a[2, 1, 1], a[2, 1, 2], a[2, 1, 3]}, {a[2, 2, 1],
a[2, 2, 2], a[2, 2, 3]}}}
In:=
multiIndex = {1, 1, 3}
Out=
{1, 1, 3}
In:=
a[Sequence @@ multiIndex] = 10^6
Out=
1000000
In:=
b
Out=
{{{a[1, 1, 1], a[1, 1, 2], 1000000}, {a[1, 2, 1], a[1, 2, 2],
a[1, 2, 3]}}, {{a[2, 1, 1], a[2, 1, 2], a[2, 1, 3]}, {a[2, 2, 1],
a[2, 2, 2], a[2, 2, 3]}}}

Tomas Garza
Mexico City

```

• Prev by Date: Re: 2 coupled diff. eqns
• Next by Date: Re: Checking the form of an option
• Previous by thread: Re: Partial evaluation
• Next by thread: Re: Partial evaluation