MathGroup Archive 1999

[Date Index] [Thread Index] [Author Index]

Search the Archive

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[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}}
>
<Snip>
 
> 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?

Maybe this will do what you want:

In[1]:=
b = Array[a, {2, 2, 3}]
Out[1]=
{{{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[2]:=
multiIndex = {1, 1, 3}
Out[2]=
{1, 1, 3}
In[3]:=
a[Sequence @@ multiIndex] = 10^6
Out[3]=
1000000
In[4]:=
b
Out[4]=
{{{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