Search code examples
variable-assignmentlinear-algebrasymbolic-mathmaple

substituting numerical values in symbolic Maple Vector


I downloaded a Maple proc which returns a Vector (say, v) of expressions and where each individual expression is in terms of other Vectors (p, a) with symbolic entries. For example:

> v := myProc();
> v[1];
p[2] + a[1]
> v[2];
p[5] + a[3] + sqrt(a[1])
...

I'd like to be able to evaluate the expressions in Vector 'v' after it is generated by assigning numerical values to Vectors 'p' and 'a' however if I define Vector 'a' and 'p' as follows:

a := Vector(3,1):  
p := Vector(5,2):

I get results in which one Vector's values are reassigned but the other Vector's values are not:

> v[1]; 
p[2] + 1
> v[2];
p[5] + 1 + sqrt(1)

Any insight as to the nature of this issue would be appreciated. I've been going through the Maple files corresponding to this proc to attempt to assign values to 'p' and 'a' before Vector 'v' returns the expressions, but this has been relatively unsuccessful, as I am relatively new to Maple and the numerous subprocs in the main proc seem to ultimately require symbolic Vectors to successfully return Vector 'v'.


Solution

  • The p[i] in the entries in the first Vector returned by xearm are so-called escaped locals. As such they have a different address from entries of your global p Vector, which is why they fail to evaluate as you expected.

    You can get around this like as follows. Replace,

    v:=f[1];
    

    by,

    v:=f[1];
    v:=convert(v,`global`);
    

    The a[i] and b[i] in the first result returned by xearm appear to be indexed into the global names a and b, and don't have the same issue as do the p[i].

    Using the properly working example from my earlier answer, here is a problematic version which exhibits similar behavior.

    restart:
    
    myProc:=proc()
           local w, p;
           w:=Vector(2);
           w[1]:=p[2] + a[1];
           w[2]:=p[5] + a[3] + sqrt(a[1]);
           return w;
        end proc:
    
    v:=myProc():
    
    v[1];
                                 p[2] + a[1]
    
    v[2];
                                             (1/2)
                           p[5] + a[3] + a[1]     
    
    a:=Vector(3,1):
    p:=Vector(5,2):
    
    v[1];
                                  p[2] + 1
    
    v[2];
                                  p[5] + 2
    
    v:=convert(v,`global`):
    
    v;
                                     [3]
                                     [ ]
                                     [4]