# 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. ﻿
{"ft_lang_label":"__label__en","ft_lang_prob":0.86875534,"math_prob":0.99073356,"size":2597,"snap":"2021-04-2021-17","text_gpt3_token_len":882,"char_repetition_ratio":0.11531045,"word_repetition_ratio":0.041463416,"special_character_ratio":0.35309973,"punctuation_ratio":0.16196136,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.9997414,"pos_list":[0,1,2],"im_url_duplicate_count":[null,null,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2021-01-23T20:44:20Z\",\"WARC-Record-ID\":\"<urn:uuid:6f54c76c-84aa-44e1-a2e6-c856a0b1980f>\",\"Content-Length\":\"114020\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:410beaab-95f4-4ca8-b5a0-983849aba9a2>\",\"WARC-Concurrent-To\":\"<urn:uuid:c1fb0312-83eb-440f-88df-12f2f3ab4222>\",\"WARC-IP-Address\":\"199.71.183.11\",\"WARC-Target-URI\":\"https://mapleprimes.com/questions/223206-Problems-With-Command-Alias-And-Diff\",\"WARC-Payload-Digest\":\"sha1:KZRFBLZRRAZUHRHHQ7UEKQITCW6YRHXY\",\"WARC-Block-Digest\":\"sha1:LJIH3LWU5EKFD4EQQNPCJJOLP3JLSEOZ\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2021/CC-MAIN-2021-04/CC-MAIN-2021-04_segments_1610703538431.77_warc_CC-MAIN-20210123191721-20210123221721-00747.warc.gz\"}"}