Results from trying to use "get" inside a Maxima function
Subject: Results from trying to use "get" inside a Maxima function
From: Stavros Macrakis
Date: Sun, 13 Mar 2011 08:18:04 +0200
Instead of
Test1(T):=block([temp,val,rank],temp:[T[val],T[rank]])$
tensor[val]:matrix([1,2],[2,1]);
tensor[rank]:'Trank2LL;
Test1(tensor);
I would recommend:
Test1(T):=block([temp],temp:[T['val],T['rank]])$
tensor['val]:matrix([1,2],[2,1]);
tensor['rank]:'Trank2LL;
Test1(tensor);
So that if val or rank are used as variables, there will be no conflict.
-s
On Wed, Mar 9, 2011 at 17:19, Bruce Linnell <brlinnell at verizon.net> wrote:
> I thought I'd pass along the results of everybody's suggestions, in case
> anything like this is ever needed or comes up again.
>
> My original goal was to attach a "quality" to a variable that has a value,
> so that when the variable was passed to a function, the function could take
> the appropriate steps based on the quality. In particular, I'm trying to
> add to the CTensor package functionality, which requires knowing whether a
> tensor has upper and/or lower indices. My goal is to be able to manipulate
> vectors, matrices, and arrays containing equations in order to multiply
> tensors, take the covariant derivative of them, raise/lower indices, etc.
>
> I would like to again thank everybody who replied to my original email,
> comments from *every* email I received were needed to be able to put all
> of the following together.
>
> Bruce
>
>
> Tests were done with XMaxima 5.23.2 in Windows XP. The format is as
> follows :
>
> Method
> -----------
> Definition of the test function, to see if I can access both the value of
> the passed variable and its quality at the same time
> Command-line statements used to set things up and call the test
> function
> Results
>
>
> get,put (quality passed attached to var)
> ----------------------------------------
> Test1(T):=block([temp],temp:[T,get(T,'Trank)])$
> tensor:matrix([1,2],[2,1]);
> put('tensor,'Trank2LL,'Trank);
> Test1(tensor);
> Does not work : I tried all combinations of 'T and T in the function, and
> 'tensor and tensor in the function call.
>
>
> declare/feature (quality passed attached to var)
> ------------------------------------------------
> Test1(T):=block([temp],temp:[T,featurep('T,Trank2LL)])$
> declare([Trank1U,Trank1L,Trank2UU,Trank2LL,Trank2UL,Trank2LU],feature);
> tensor:matrix([1,2],[2,1]);
> declare(tensor,Trank2LL);
> Test1(tensor);
> Does not work : I tried all combinations of 'T and T in featurep.
>
>
> get,put (quality passed attached to var)
> ----------------------------------------
> Test1(T):=block([temp],temp:[ev(T),get(T,'Trank)])$
> tensor:matrix([1,2],[2,1]);
> put('tensor,'Trank2LL,'Trank);
> Test1('tensor);
> This works, but you have to pass the variable as 'var in ALL function calls
>
>
> declare/feature (quality passed attached to var)
> ------------------------------------------------
> Test1(T):=block([temp],temp:[ev(T),featurep(T,Trank2LL)])$
> declare([Trank1U,Trank1L,Trank2UU,Trank2LL,Trank2UL,Trank2LU],feature);
> tensor:matrix([1,2],[2,1]);
> declare(tensor,Trank2LL);
> Test1('tensor);
> This works, but you have to pass the variable as 'var in ALL function calls
>
>
> quality passed explicitly
> -------------------------
> Test1(T,rank):=block([temp],temp:[T,rank])$
> put('tensor,'Trank2LL,'Trank);
> tensor:matrix([1,2],[2,1]);
> Test1(tensor,get('tensor,'Trank));
> This works, but you have to include the get() in ALL function calls
> This almost always hangs after returning the result - I'm not sure why
> (just FYI, no reply needed)
>
>
> Create a structure with value+quality
> -------------------------------------
> Test1(T):=block([temp],temp:[T at val,T at rank])$
> defstruct(Tensor(val,rank));
> tensor:new(Tensor);
> tensor at val:matrix([1,2],[2,1]);
> tensor at rank:'Trank2LL;
> Test1(tensor);
> This works!
>
>
> Hashed array containing value+quality
> -------------------------------------
> Test1(T):=block([temp,val,rank],temp:[T[val],T[rank]])$
> tensor[val]:matrix([1,2],[2,1]);
> tensor[rank]:'Trank2LL;
> Test1(tensor);
> This works!
>
>
> _______________________________________________
> Maxima mailing list
> Maxima at math.utexas.edu
> http://www.math.utexas.edu/mailman/listinfo/maxima
>
>