Question: Problems with command alias and diff

Hey all Maple experts, Kris here!

I could really use some help/clarfication on what is going on with alias, diff, and pointers for vectors.

A short description of what I want to do:
I have 4 equations with 4 variables. The first two equations and variables (1 and 2) are called private, and the last two (3 and 4) are called common. I want to establish an implicit dependence of common on private, namely that the private variables 1 and 2 depend on 3 and 4. Then I want to derivate the private equations with respect to the common variables.

Thus, I create pointers that point to the correct private or common equation or variables with the loop.
for i from 1 to 2 do
iP[i]:=i:
iC[i]:=i+2;
od:

So that for example, a set of four equations named "phi" phi[1..4] where phi[iP[1]] is the first private equation, and phi[iC[1]] is the first common equation. Hopefully so far I have been clear. I create an alias, and continue to derivate these equations. However, I notice that Maple does not recognize the functions in the diff command if the "pointer" notation is used. I will paste the entire code for you all to look at and maybe you can see where things get "weird". Namely if I write phi[1], is not the same as phi[iP[1]], even though iP[1]:=1 (Both are integers). 

p.s. I have used implicitdiff. It is way too slow and memory inefficient for many equations (hundreds to thousands). So that is why I am trying to find a work-around.

restart:
Digits:=15:
with(LinearAlgebra):


for i from 1 to 2 do
iP[i]:=i:
iC[i]:=i+2;
od:


alias(seq(x[iP[i]]=x[iP[i]](seq(x[iC[j]],j=1..2)),i=1..2)):
alias(seq(seq(dPdC[i,iC[k]]=diff(x[iP[i]](seq(x[iC[j]],j=1..2)),x[iC[k]]),k=1..2),i=1..2));


# Define all (PRIVATE + COMMON) phi expressions.
# 1 and 2 are the PRIVATE equations.
# 3 and 4 are the COMMON equations.
phix[1]:= x[3]**2+x[4]**2:
phix[2]:= x[1]   +x[4]:
phix[3]:= x[1]   +x[3]+x[1]:
phix[4]:= x[1]   +x[3]+x[1]:

for i from 1 to 2   do
f[i]:=x[iP[i]]-phix[iP[i]]:
od:


f[1];

x[1]-phix[1];

print(iP[1],iC[1]);

print(x[iP[1]]-phix[iP[1]],x[iC[1]]);

TEST1:=diff(x[1]-phix[1],x[3]);

TEST2:=diff(f[1],x[3]);

TEST3:=diff(f[1],x[iC[1]]);

TEST4:=diff(x[iP[1]]-phix[iP[1]],x[iC[1]]);

The result is 
      
                     -x[3]^2  - x[4]^2  + x[1]
                      x[1] - x[3]^2  - x[4]^2 
                              1, 3
     
                  -x[3]^2 - x[4]^2  + x[1], x[3]
                      dPdC[1, 3] - 2 x[3]
                            -2 x[3]
                            -2 x[3]
                            -2 x[3]
Where dPdC includes the implicit derivatives, which is the answer I want, but then I am forced to write by hand what the elements are. If I put the expression in a loop with the pointers, then I get the other "TEST" answers, and as you can see, the implicit dependence from alias has been ignored.
 

Please Wait...