arrays/lists with multi-idices



Hi again,

Sorry, but I haven't still understood how to use
arrays with list indeces.

What I need to do is simply a procedure deCasteljau(...,n,deg)
that works with b[a_1,a_2,...,a_n] 
or b[[a_1,a_2,...,a_n]], 0<=a_i<=deg,
where n is passed as a parameter, i.e.
multi-indeces whose arity is given by a parameter.

The algorithm we are trying to implement 
is the multivariate "de Casteljau algorithm"
for Bezier hypersurfaces.


I get the following error messages:

If I do:
(%i22) foo (x) := block (local (b), array (b, 5), arrayapply(b,[1,2,3]) : 
x, listarray (b));
(%i23) foo(10);
"

I then get:
"
Improper value assignment:
arrayapply(b, [1, 2, 3])
#0: foo(x=10)
 -- an error.  To debug this try debugmode(true);
"

If I do
"
(%i26) foo (x) := block (local (b), array (b, 5), b[[1,3,4]] : x, 
listarray (b));
(%o26) foo(x) := block(local(b), array(b, 5), b	         : x, 
listarray(b))
					       [1, 3, 4]
(%i27) foo(10);
"
I get:
Array b has dimensions [5], but was called with [[1,3,4]]
#0: foo(x=10)
 -- an error.  To debug this try debugmode(true);
"

  Fabrizio




On Mon, 18 Jun 2007, Robert Dodier wrote:

> On 6/18/07, Fabrizio Caruso <caruso at dm.unipi.it> wrote:
> 
> > Sorry but I don't know hot to force arrays to be local.
> > There must be something I am missing.
> >
> > For instance:
> > foo(x):= block([b],b:make_array('hashed,3),b[1]:x);
> >
> > will change b[1] after its execution.
> >
> > Moreover I would like to use things like
> > b[5,2,3,4] where the number of arguments is a parameter.
> 
> Fabrizio, (1) local(a) within a block saves and restores the
> properties (including some varieties of arrays) of a when the
> block is entered and exited. (2) For Maxima arrays
> implemented as Lisp hashtables, the number of indices is
> immaterial; a hash key can be a list of indices (or anything).
> For Maxima arrays implemented as Lisp arrays,
> arraymake and arrayapply might be useful.
> 
> e.g.
> 
> foo (x) := block (local (b), array (b, 5), b[1] : x, listarray (b));
> foo (3);
>   => [#####, 3, #####, #####, #####, #####]
> listarray (b);
>  => (error message, b is not an array)
> 
> bar (a, [L]) := arrayapply (a, L);
> bar (x, i, j);
>   => x[i, j]
> bar (x, i, j, k);
>   => x[i, j, k]
> 
> I'm sorry that this is confusing; various ideas about arrays,
> not entirely consistent, accumulated over the decades.
> I think now is a good time to reconsider and maybe
> clean up some of that stuff.
> 
> Maybe if you say more about what you're trying to accomplish
> we can give some advice.
> 
> FWIW
> Robert
>