# Question:Problems with command alias and diff

## Question:Problems with command alias and diff

Maple

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] is the first private equation, and phi[iC] 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, is not the same as phi[iP], even though iP:=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:= x**2+x**2:
phix:= x   +x:
phix:= x   +x+x:
phix:= x   +x+x:

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

f;

x-phix;

print(iP,iC);

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

TEST1:=diff(x-phix,x);

TEST2:=diff(f,x);

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

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

The result is

-x^2  - x^2  + x
x - x^2  - x^2
1, 3

-x^2 - x^2  + x, x
dPdC[1, 3] - 2 x
-2 x
-2 x
-2 x
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. ﻿