Andriy

260 Reputation

13 Badges

10 years, 140 days

MaplePrimes Activity


These are replies submitted by Andriy

@ecterrab

Thank you for your help in deriving of the coefficients of decomposition of wave function through the basis Ket-vectors.

I guess, I have to report some strange behaviour of select-command in one particular case

Physics:-Version()


restart; 
with(Physics); with(Library); Setup(mathematicalnotation = true);
Physics:-Setup(anticommutativeprefix = psi);

phi := (a+b)*Ket(psi, 1, 1, 0);

type(phi, Ket);
type(phi, PhysicsType:-ExtendedKet);
select(type, phi, commutative);                   #  works well
select(type, phi, PhysicsType:-Ket);              #  works well
select(type, phi, PhysicsType:-ExtendedKet); #  I expected to receive here (a+b)*Ket(psi,1,1,0)  but received  Ket(psi,1,1,0).
indets(phi, PhysicsType:-ExtendedKet)           #  works well


false
true





Generally the result is correct

restart; 
with(Physics); with(Library); Setup(mathematicalnotation = true);
Physics:-Setup(anticommutativeprefix = psi);

phi := Ket(psi, 1, 1, 0);
type(phi, Ket);
type(phi, PhysicsType:-ExtendedKet);
select(type, phi, commutative);                  # works strange
select(type, phi, PhysicsType:-Ket);             # works strange
select(type, phi, PhysicsType:-ExtendedKet);  # works strange
indets(phi, PhysicsType:-ExtendedKet)           # works well


true
true





The result seems to be strange.


@ecterrab

Thank you for your help in deriving of the coefficients of decomposition of wave function through the basis Ket-vectors.

I guess, I have to report some strange behaviour of select-command in one particular case

Physics:-Version()


restart; 
with(Physics); with(Library); Setup(mathematicalnotation = true);
Physics:-Setup(anticommutativeprefix = psi);

phi := (a+b)*Ket(psi, 1, 1, 0);

type(phi, Ket);
type(phi, PhysicsType:-ExtendedKet);
select(type, phi, commutative);                   #  works well
select(type, phi, PhysicsType:-Ket);              #  works well
select(type, phi, PhysicsType:-ExtendedKet); #  I expected to receive here (a+b)*Ket(psi,1,1,0)  but received  Ket(psi,1,1,0).
indets(phi, PhysicsType:-ExtendedKet)           #  works well


false
true





Generally the result is correct

restart; 
with(Physics); with(Library); Setup(mathematicalnotation = true);
Physics:-Setup(anticommutativeprefix = psi);

phi := Ket(psi, 1, 1, 0);
type(phi, Ket);
type(phi, PhysicsType:-ExtendedKet);
select(type, phi, commutative);                  # works strange
select(type, phi, PhysicsType:-Ket);             # works strange
select(type, phi, PhysicsType:-ExtendedKet);  # works strange
indets(phi, PhysicsType:-ExtendedKet)           # works well


true
true





The result seems to be strange.


@ecterrab

1) minor bug

Please look at the following code:

restart; 
Physics:-Version();
with(Physics); with(Library); Setup(mathematicalnotation = true, anticommutativeprefix = psi);

for i to 4 do
  ap[i] := Creation(psi, i, notation = explicit);
  am[i] := Annihilation(psi, i, notation = explicit)
end do;

z := a*ap[1].am[1]+ap[1];

cc := proc (EE)
local ee, P, U;
  ee := UnnestProductsInExpression(EE, ':-productsinoutput = P'):
  P := [seq(P[j] = U[j], j = 1 .. nops(P))]:
  ee := subs(P, ee):
  coeffs(ee, map(rhs, P))
end proc:

cc(z);

The result:



instead of



I understand what actually cc(z) does. As a first step procedure UnnestProductsInExpression extracts noncommutative products of argument EE and puts them in P. All next steps are clear. It is a little strange that similar procedure extracting nonoperator part doesn't exist. However, I understand that such situation may have grounds.

This bug doesn't affect my problem. It will reveal itself in exotic cases only.

2) I was surprised to realize that I cann't extract a factor for a wave function:

z := (a+b)/(c+d):
phi := z*Ket(psi, 1, 0, 1):
op(1, phi);

gives only a+b. Could you help me to get the factor (a+b)/(c+d)?


@ecterrab

1) minor bug

Please look at the following code:

restart; 
Physics:-Version();
with(Physics); with(Library); Setup(mathematicalnotation = true, anticommutativeprefix = psi);

for i to 4 do
  ap[i] := Creation(psi, i, notation = explicit);
  am[i] := Annihilation(psi, i, notation = explicit)
end do;

z := a*ap[1].am[1]+ap[1];

cc := proc (EE)
local ee, P, U;
  ee := UnnestProductsInExpression(EE, ':-productsinoutput = P'):
  P := [seq(P[j] = U[j], j = 1 .. nops(P))]:
  ee := subs(P, ee):
  coeffs(ee, map(rhs, P))
end proc:

cc(z);

The result:



instead of



I understand what actually cc(z) does. As a first step procedure UnnestProductsInExpression extracts noncommutative products of argument EE and puts them in P. All next steps are clear. It is a little strange that similar procedure extracting nonoperator part doesn't exist. However, I understand that such situation may have grounds.

This bug doesn't affect my problem. It will reveal itself in exotic cases only.

2) I was surprised to realize that I cann't extract a factor for a wave function:

z := (a+b)/(c+d):
phi := z*Ket(psi, 1, 0, 1):
op(1, phi);

gives only a+b. Could you help me to get the factor (a+b)/(c+d)?


@ecterrab 

I guess the correction of the help page would be enough. But what do you think about my 'key issue' (see above)

@ecterrab 

I guess the correction of the help page would be enough. But what do you think about my 'key issue' (see above)

@ecterrab 

I'll try to explain better my expectation from Coefficients-type operator. I have an operator of type

H=...+x[alpha]*ap[i1]. ... .ap[in].am[j1]. ... .am[jn]+...        (1)

where i1x[alpha] are complex numbers (more precisely they are some expressions). I need to have a command (or to have a possibility to program a procedure), let's call it 'coeffs(H)', that works in the following way:

coeffs(H);

result:

x[1], x[2], ... , x[alpha], ... 

I'd like to have a direct generalization of the existed procedure 'coeffs' or to have a possibility to program it myself.  Existed 'coeffs' extracts all coefficients of a multivariate polynomial:

s := 3*v^2*y^2+2*v*y^3:
coeffs(s);

gives

3, 2

My operators 'H' is a result of some transformations of initial operator H0. I make a minor change of parameters of the H0 and it results in drastic changes of operator H. Hence, Generally I don't know the particular structure of that H except that it is of view (1). Of course, I can extract all the coefficients x[alpha] by programming the coeffs() that uses

Coefficients(H, [ap[i1]. ... .ap[in].am[j1]. ... .am[jn]], 1)

but it is not a solution as I must rewrite my procedure coeffs(H) every time when I get a new operator H0.

PS
I have noticed that SortProduct returns the result in form

however generally operators are presented in form

You mentioned about two possible options of SortProduct that produce an output in these two presentations. What is the difference?

Thank you.

@ecterrab 

I'll try to explain better my expectation from Coefficients-type operator. I have an operator of type

H=...+x[alpha]*ap[i1]. ... .ap[in].am[j1]. ... .am[jn]+...        (1)

where i1x[alpha] are complex numbers (more precisely they are some expressions). I need to have a command (or to have a possibility to program a procedure), let's call it 'coeffs(H)', that works in the following way:

coeffs(H);

result:

x[1], x[2], ... , x[alpha], ... 

I'd like to have a direct generalization of the existed procedure 'coeffs' or to have a possibility to program it myself.  Existed 'coeffs' extracts all coefficients of a multivariate polynomial:

s := 3*v^2*y^2+2*v*y^3:
coeffs(s);

gives

3, 2

My operators 'H' is a result of some transformations of initial operator H0. I make a minor change of parameters of the H0 and it results in drastic changes of operator H. Hence, Generally I don't know the particular structure of that H except that it is of view (1). Of course, I can extract all the coefficients x[alpha] by programming the coeffs() that uses

Coefficients(H, [ap[i1]. ... .ap[in].am[j1]. ... .am[jn]], 1)

but it is not a solution as I must rewrite my procedure coeffs(H) every time when I get a new operator H0.

PS
I have noticed that SortProduct returns the result in form

however generally operators are presented in form

You mentioned about two possible options of SortProduct that produce an output in these two presentations. What is the difference?

Thank you.

@ecterrab 

Physics:-Version();



Please look at the code:

restart; with(Physics): with(Library): Setup(mathematicalnotation = true): 
Setup(anticommutativeprefix = psi):

for i to 4 do
  ap[i] := Creation(psi, i, notation = explicit):
  am[i] := Annihilation(psi, i, notation = explicit)
end do:

z := 3*ap[1].am[1]+R*ap[1].am[1]+K/(C+D)*ap[2].am[2];

Coefficients(z, ap[1]);
Coefficients(z, [ap[1].am[1]], 1)


Result:





Great.

Now look at another code:

restart; with(Physics): with(Library): Setup(mathematicalnotation = true): 
Setup(anticommutativeprefix = psi):

for i to 4 do
  ap[i] := Creation(psi, i, notation = explicit):
  am[i] := Annihilation(psi, i, notation = explicit)
end do:

ApAm1 := [seq(ap[j], j = 1 .. 4), seq(am[j], j = 1 .. 4)]:

z := D1*ap[1].am[2].ap[4].am[3]+A*am[2].ap[2].am[1].ap[1]+B*ap[1].am[1].ap[2].am[2]+
B*ap[3].am[3].ap[4].am[4]+ap[1].(D2*am[2].ap[4].am[3])+3*ap[1].am[1]+
R*ap[1].am[1]+ap[2].am[2]+K[1]*(1/(C+5*D))*ap[3].am[4]+L[5]*(1/(C+5*D))*ap[3].am[4];

z := SortProducts(z, ApAm1, useanticommutator):
z := collect(z, `.`):
z := simplify(z, size);

Coefficients(z, ap[1],0):
Coefficients(z, [ap[1].am[1]], 1); # gives an error







Error, (in Physics:-Coefficients) unable to compute the coefficients of `a-`[psi[1]] in the not commutative product Physics:-`.`(`a+`[psi[2]], Physics:-`.`(`a-`[psi[1]], `a-`[psi[2]]))

@ecterrab 

Physics:-Version();



Please look at the code:

restart; with(Physics): with(Library): Setup(mathematicalnotation = true): 
Setup(anticommutativeprefix = psi):

for i to 4 do
  ap[i] := Creation(psi, i, notation = explicit):
  am[i] := Annihilation(psi, i, notation = explicit)
end do:

z := 3*ap[1].am[1]+R*ap[1].am[1]+K/(C+D)*ap[2].am[2];

Coefficients(z, ap[1]);
Coefficients(z, [ap[1].am[1]], 1)


Result:





Great.

Now look at another code:

restart; with(Physics): with(Library): Setup(mathematicalnotation = true): 
Setup(anticommutativeprefix = psi):

for i to 4 do
  ap[i] := Creation(psi, i, notation = explicit):
  am[i] := Annihilation(psi, i, notation = explicit)
end do:

ApAm1 := [seq(ap[j], j = 1 .. 4), seq(am[j], j = 1 .. 4)]:

z := D1*ap[1].am[2].ap[4].am[3]+A*am[2].ap[2].am[1].ap[1]+B*ap[1].am[1].ap[2].am[2]+
B*ap[3].am[3].ap[4].am[4]+ap[1].(D2*am[2].ap[4].am[3])+3*ap[1].am[1]+
R*ap[1].am[1]+ap[2].am[2]+K[1]*(1/(C+5*D))*ap[3].am[4]+L[5]*(1/(C+5*D))*ap[3].am[4];

z := SortProducts(z, ApAm1, useanticommutator):
z := collect(z, `.`):
z := simplify(z, size);

Coefficients(z, ap[1],0):
Coefficients(z, [ap[1].am[1]], 1); # gives an error







Error, (in Physics:-Coefficients) unable to compute the coefficients of `a-`[psi[1]] in the not commutative product Physics:-`.`(`a+`[psi[2]], Physics:-`.`(`a-`[psi[1]], `a-`[psi[2]]))

@ecterrab

collect(z,`.`) works perfect. All is clear except one moment.

Regarding your answer to my message "The coefficients of operator expression". I am afraid you didn't understand what I mean. Of course, it is very useful to have a function Coefficient that extracts coefficients  in noncommutative products expressed using Physics:-`.` in addition to products expressed using Physics:-`*`. But my question concerns a bit different point. I need to extract a coefficient (it may be an expression) that is a real or complex value indeed.

Namely, assume we have a quantum operator

H:=sum_{\alpha}(A[alpha]*ap[i1].ap[i2]. ... .ap[in].am[j1].am[j2]. ... .am[jm])

where ap/am are creation/annihilation operators and A[alpha] is an expression that gives a complex value after evaluation. I need to extract all that A[alpha] from the operator H. I suppose that Coefficients doesn't allow to do it.

A quotation from the ?Physics[`*`]:

In order to make zero recognition possible in the not commutative case, basic simplifications, unnesting, and sorting of arguments of these products are automatically performed. ... The form automatically returned is "*" itself, built as follows:
1. The sequence of operands of "*" is split into two sequences: s1 and s2, containing the commutative and not commutative (anticommutative and noncommutative) operands, respectively.
2. The elements of s1 are sorted by using machine ordering (table(symmetric)), resulting in sorted_s1.
3. Each subsequence of anticommutative elements of s2 is sorted using machine ordering (table(antisymmetric)), resulting in sorted_s2.
4. Both sorted_s1 and sorted_s2 are normalized by using normal.
A result is built and returned as the normalized form of sorted_s1 times sorted_s2.

I need to extract that commutative part, namely I need that "sorted_s1". I understand that my case is Physics[`.`] not Physics[`*`] but commutative factor exists in noncommutative products expressed using Physics[`.`] too.

@ecterrab

collect(z,`.`) works perfect. All is clear except one moment.

Regarding your answer to my message "The coefficients of operator expression". I am afraid you didn't understand what I mean. Of course, it is very useful to have a function Coefficient that extracts coefficients  in noncommutative products expressed using Physics:-`.` in addition to products expressed using Physics:-`*`. But my question concerns a bit different point. I need to extract a coefficient (it may be an expression) that is a real or complex value indeed.

Namely, assume we have a quantum operator

H:=sum_{\alpha}(A[alpha]*ap[i1].ap[i2]. ... .ap[in].am[j1].am[j2]. ... .am[jm])

where ap/am are creation/annihilation operators and A[alpha] is an expression that gives a complex value after evaluation. I need to extract all that A[alpha] from the operator H. I suppose that Coefficients doesn't allow to do it.

A quotation from the ?Physics[`*`]:

In order to make zero recognition possible in the not commutative case, basic simplifications, unnesting, and sorting of arguments of these products are automatically performed. ... The form automatically returned is "*" itself, built as follows:
1. The sequence of operands of "*" is split into two sequences: s1 and s2, containing the commutative and not commutative (anticommutative and noncommutative) operands, respectively.
2. The elements of s1 are sorted by using machine ordering (table(symmetric)), resulting in sorted_s1.
3. Each subsequence of anticommutative elements of s2 is sorted using machine ordering (table(antisymmetric)), resulting in sorted_s2.
4. Both sorted_s1 and sorted_s2 are normalized by using normal.
A result is built and returned as the normalized form of sorted_s1 times sorted_s2.

I need to extract that commutative part, namely I need that "sorted_s1". I understand that my case is Physics[`.`] not Physics[`*`] but commutative factor exists in noncommutative products expressed using Physics[`.`] too.

@ecterrab

As I mentioned above I need to collect terms with the same operator part: that is

x1*ap[3].am[4]+x2*ap[3].am[4] -> (x1+x2)*ap[3].am[4]

In the previous message I showed that simplify(z,size) doesn't solve the problem.

Besides that I need to get the coefficients near the operator part:
A*ap[i1].ap[i2]. ... .ap[in].am[j1].am[j2]. ... .am[jm] -> A

Unfortunately, I didn't manage to find a way of using Physics:-Coefficients for this purpose. I tried numerous variations of the following:
......

z:=x1*ap[1].am[1]+x2*ap[2].am[2]:
ApAm1 := [seq(ap[j], j = 1 .. 2), seq(am[j], j = 1 .. 2)];
Coefficients(z, ApAm1, all);

......
but unsuccessfully.

More precisely, I need to compose a system of equations A[alpha]=0 where A[alpha] are coefficients in front of operator parts:
z:=sum_{\alpha}(A[alpha]*ap[i1].ap[i2]. ... .ap[in].am[j1].am[j2]. ... .am[jm]).

I tried the following:

restart; 
with(Physics); with(Library); Setup(mathematicalnotation = true);
Physics:-Setup(anticommutativeprefix = psi);

for i to 4 do
ap[i] := Creation(psi, i, notation = explicit);
am[i] := Annihilation(psi, i, notation = explicit)
end do;

system_creation := proc (z)::list;
local i, x, syst;
syst := {}:
for i to nops(z) do
x := op(1, op(i, z)):
syst := syst union{`if`(type(x, Or(symbol, numeric, `+`)), x, 1) = 0} :
end do;
syst
end proc:

z := D1*ap[1].am[2].ap[4].am[3]+A*ap[2].am[2].ap[1].am[1]+B*ap[1].am[1].ap[2].am[2]+B*ap[3].am[3].ap[4].am[4]+ap[1].(D2*am[2].ap[4].am[3])+3*ap[1].am[1]+R*ap[1].am[1]+ap[2].am[2]+(K[1]+L)*ap[3]/(C+5*D).am[4];

z2 := system_creation(z)

but the result is




instead of



I understand why it is so, but I can't get the correct result. It seems that Physics Package lack the tool for getting the coefficients of the operator expression. Besides that it whould be great if you introduce Physics:-Library:-Collect (the tool that collects terms with the same operator part).

@ecterrab

As I mentioned above I need to collect terms with the same operator part: that is

x1*ap[3].am[4]+x2*ap[3].am[4] -> (x1+x2)*ap[3].am[4]

In the previous message I showed that simplify(z,size) doesn't solve the problem.

Besides that I need to get the coefficients near the operator part:
A*ap[i1].ap[i2]. ... .ap[in].am[j1].am[j2]. ... .am[jm] -> A

Unfortunately, I didn't manage to find a way of using Physics:-Coefficients for this purpose. I tried numerous variations of the following:
......

z:=x1*ap[1].am[1]+x2*ap[2].am[2]:
ApAm1 := [seq(ap[j], j = 1 .. 2), seq(am[j], j = 1 .. 2)];
Coefficients(z, ApAm1, all);

......
but unsuccessfully.

More precisely, I need to compose a system of equations A[alpha]=0 where A[alpha] are coefficients in front of operator parts:
z:=sum_{\alpha}(A[alpha]*ap[i1].ap[i2]. ... .ap[in].am[j1].am[j2]. ... .am[jm]).

I tried the following:

restart; 
with(Physics); with(Library); Setup(mathematicalnotation = true);
Physics:-Setup(anticommutativeprefix = psi);

for i to 4 do
ap[i] := Creation(psi, i, notation = explicit);
am[i] := Annihilation(psi, i, notation = explicit)
end do;

system_creation := proc (z)::list;
local i, x, syst;
syst := {}:
for i to nops(z) do
x := op(1, op(i, z)):
syst := syst union{`if`(type(x, Or(symbol, numeric, `+`)), x, 1) = 0} :
end do;
syst
end proc:

z := D1*ap[1].am[2].ap[4].am[3]+A*ap[2].am[2].ap[1].am[1]+B*ap[1].am[1].ap[2].am[2]+B*ap[3].am[3].ap[4].am[4]+ap[1].(D2*am[2].ap[4].am[3])+3*ap[1].am[1]+R*ap[1].am[1]+ap[2].am[2]+(K[1]+L)*ap[3]/(C+5*D).am[4];

z2 := system_creation(z)

but the result is




instead of



I understand why it is so, but I can't get the correct result. It seems that Physics Package lack the tool for getting the coefficients of the operator expression. Besides that it whould be great if you introduce Physics:-Library:-Collect (the tool that collects terms with the same operator part).

Unfortunately, simplify/size doesn't always allow to factor out common factors.

restart; with(Physics); with(Library); Setup(mathematicalnotation = true); 
Physics:-Setup(anticommutativeprefix = psi);
Physics:-Version();

for i to 2 do
ap[i] := Creation(psi, i, notation = explicit);
am[i] := Annihilation(psi, i, notation = explicit)
end do;

type(ap, Library:-PhysicsType:-ExtendedQuantumOperator);
3*ap[1].am[1]+ap[1].am[1];
simplify(%, size);


Result:




The result is ok.

But!

z2 := 3*ap[1].am[1]+R*ap[1].am[1]+K/(C+D)*ap[2]).am[2]; 
z2 := simplify(z2, size)


Result:



That is wrong. The correct result is

4 5 6 7 8 9 10 Page 6 of 10