Results from trying to use "get" inside a Maxima function
Subject: Results from trying to use "get" inside a Maxima function
From: Bruce Linnell
Date: Wed, 09 Mar 2011 10:19:49 -0500
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!