## 270 Reputation

12 years, 17 days

## Ok...

@Carl Love

Ok, thank you. The last: what means `if` enclosed in slanted single quotes?
Btw

nn:= ()-> if([args]::list(integer), ap(args).am(args), 'procname'(args)):

(without slanted single quotes)
works well too

## Ok...

@Carl Love

Ok, thank you. The last: what means `if` enclosed in slanted single quotes?
Btw

nn:= ()-> if([args]::list(integer), ap(args).am(args), 'procname'(args)):

(without slanted single quotes)
works well too

## Here it is...

.....

nn:= ()-> `if`([args]::list(integer), ap(args).am(args), 'procname'(args)):   # minor correction
#
Setup(op = {am, ap, nn}):

N:= proc(f)
local i,j,sigma;
Sum(Sum(Sum(nn(i,j,sigma), sigma= 1..2), j= 1..3), i= 1..f)
end proc:
#Setup(op = N):

phi := Ket(psi, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1):
f := 2:
N(f).phi;
type(N, Library:-PhysicsType:-ExtendedQuantumOperator);
type(nn, Library:-PhysicsType:-ExtendedQuantumOperator);

output:

false
false

However if

N:= proc(f)
local i,j,sigma;
sum(sum(sum(nn(i,j,sigma), sigma= 1..2), j= 1..3), i= 1..f)
end proc:

Then output is

false

false.

The result is correct. Great! However, the fact that nn and N are not quantum operators disturbs me. Therefore I'll uncomment two strings with Setup(op = {am, ap, nn}): and Setup(op = N): for more reliability.

Could you explain me the string

nn:= ()-> `if`([args]::list(integer), ap(args).am(args), 'procname'(args)):
Of couse I'll try do it myself but I will not reject your help.

## Here it is...

.....

nn:= ()-> `if`([args]::list(integer), ap(args).am(args), 'procname'(args)):   # minor correction
#
Setup(op = {am, ap, nn}):

N:= proc(f)
local i,j,sigma;
Sum(Sum(Sum(nn(i,j,sigma), sigma= 1..2), j= 1..3), i= 1..f)
end proc:
#Setup(op = N):

phi := Ket(psi, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 1):
f := 2:
N(f).phi;
type(N, Library:-PhysicsType:-ExtendedQuantumOperator);
type(nn, Library:-PhysicsType:-ExtendedQuantumOperator);

output:

false
false

However if

N:= proc(f)
local i,j,sigma;
sum(sum(sum(nn(i,j,sigma), sigma= 1..2), j= 1..3), i= 1..f)
end proc:

Then output is

false

false.

The result is correct. Great! However, the fact that nn and N are not quantum operators disturbs me. Therefore I'll uncomment two strings with Setup(op = {am, ap, nn}): and Setup(op = N): for more reliability.

Could you explain me the string

nn:= ()-> `if`([args]::list(integer), ap(args).am(args), 'procname'(args)):
Of couse I'll try do it myself but I will not reject your help.

does't work.

does't work.

## Thank you for detailed answer!...

Hi ecterrab

I still have some questions.
Here is the first one

`restart;`
`with(Physics); Setup(mathematicalnotation = true); Physics:-Setup(anticommutativeprefix = psi); am := proc (i, j, sigma) local k::posint;if [i, j, sigma]::(Not(list(posint))) then return 'procname(args)' end if; k := 6*i-8+2*j+sigma; Annihilation(psi, k, notation = explicit) end proc;ap := proc (i, j, sigma)local k::posint;if [i, j, sigma]::(Not(list(posint))) then return 'procname(args)' end if; k := 6*i-8+2*j+sigma;Creation(psi, k, notation = explicit) end proc; nn := proc (i, j, sigma)if [i, j, sigma]::(Not(list(posint))) then return 'procname(args)' end if; ap(i, j, sigma).am(i, j, sigma) end proc;Setup(op = {am, ap, nn}); N := sum(add(add(nn(i, j, sigma), sigma = 1 .. 2), j = 1 .. 3), i = 1 .. f);`

and you will get a predictible result:

Then execute

`i:=7:N;And the result is an error:`

Error, (in sum) summation variable previously assigned, second argument evaluates to 7 = 1 .. f

Sum behaves very strange. It perceives external 'i' to be an internal index 'i'. Is it intended behaviour?

## Thank you for detailed answer!...

Hi ecterrab

I still have some questions.
Here is the first one

`restart;`
`with(Physics); Setup(mathematicalnotation = true); Physics:-Setup(anticommutativeprefix = psi); am := proc (i, j, sigma) local k::posint;if [i, j, sigma]::(Not(list(posint))) then return 'procname(args)' end if; k := 6*i-8+2*j+sigma; Annihilation(psi, k, notation = explicit) end proc;ap := proc (i, j, sigma)local k::posint;if [i, j, sigma]::(Not(list(posint))) then return 'procname(args)' end if; k := 6*i-8+2*j+sigma;Creation(psi, k, notation = explicit) end proc; nn := proc (i, j, sigma)if [i, j, sigma]::(Not(list(posint))) then return 'procname(args)' end if; ap(i, j, sigma).am(i, j, sigma) end proc;Setup(op = {am, ap, nn}); N := sum(add(add(nn(i, j, sigma), sigma = 1 .. 2), j = 1 .. 3), i = 1 .. f);`

and you will get a predictible result:

Then execute

`i:=7:N;And the result is an error:`

Error, (in sum) summation variable previously assigned, second argument evaluates to 7 = 1 .. f

Sum behaves very strange. It perceives external 'i' to be an internal index 'i'. Is it intended behaviour?

## Now tested...

I have decided that it is a typo as I can't understand this construction:

N:= (i,j,sigma,f)-> sum(sum(sum(nn(i,j,sigma), sigma= 1..2), j= 1..3), i= 1..f):

Ok. I try the following:

restart:
with(Physics):
Setup(mathematicalnotation= true):
Setup(anticommutativeprefix= Psi):

am:= (i,j,sigma)-> Annihilation(Psi, 6*(i-1)+2*(j-1)+sigma, notation= explicit):
ap:= (i,j,sigma)-> Creation(Psi, 6*(i-1)+2*(j-1)+sigma, notation= explicit):
nn:= ap.am:

N:= (i,j,sigma,f)-> sum(sum(sum(nn(i,j,sigma), sigma= 1..2), j= 1..3), i= 1..f):  # ???

psi := Ket(Psi, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0):
f := 2:
N(i,j,sigma,f).psi;

and it gives an error. What values of i, j, sigma actually I have to pass to function N in order to calculate action of N on psi?

## Now tested...

I have decided that it is a typo as I can't understand this construction:

N:= (i,j,sigma,f)-> sum(sum(sum(nn(i,j,sigma), sigma= 1..2), j= 1..3), i= 1..f):

Ok. I try the following:

restart:
with(Physics):
Setup(mathematicalnotation= true):
Setup(anticommutativeprefix= Psi):

am:= (i,j,sigma)-> Annihilation(Psi, 6*(i-1)+2*(j-1)+sigma, notation= explicit):
ap:= (i,j,sigma)-> Creation(Psi, 6*(i-1)+2*(j-1)+sigma, notation= explicit):
nn:= ap.am:

N:= (i,j,sigma,f)-> sum(sum(sum(nn(i,j,sigma), sigma= 1..2), j= 1..3), i= 1..f):  # ???

psi := Ket(Psi, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0):
f := 2:
N(i,j,sigma,f).psi;

and it gives an error. What values of i, j, sigma actually I have to pass to function N in order to calculate action of N on psi?

## the problem persist...

The command

N:= Sum(Sum(Sum('nn'(i, j, sigma), sigma= 1..2), j= 1 ..3), i= 1 ..f);

defines operator N but I don't know how to use it in particular calculations:

....

psi := Ket(Psi, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0):
f:=2;
N.psi;

Output:

Error, (in Creation) invalid input: too many and/or wrong type of arguments passed to Creation; first unused argument is 6*i-8+2*j+sigma

However if

N := f -> Sum(Sum(Sum('nn'(i, j, sigma), sigma = 1 .. 2), j = 1 .. 3), i = 1 .. f);

then

psi := Ket(Psi, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0):
f:=2;
N(f).psi;

gives

without error but no calculations are made.

## the problem persist...

The command

N:= Sum(Sum(Sum('nn'(i, j, sigma), sigma= 1..2), j= 1 ..3), i= 1 ..f);

defines operator N but I don't know how to use it in particular calculations:

....

psi := Ket(Psi, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0):
f:=2;
N.psi;

Output:

Error, (in Creation) invalid input: too many and/or wrong type of arguments passed to Creation; first unused argument is 6*i-8+2*j+sigma

However if

N := f -> Sum(Sum(Sum('nn'(i, j, sigma), sigma = 1 .. 2), j = 1 .. 3), i = 1 .. f);

then

psi := Ket(Psi, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0):
f:=2;
N(f).psi;

gives

without error but no calculations are made.

## I wonder why it doesn't work...

nn:= ap.am: is a nice feature!

restart:
with(Physics):
Setup(mathematicalnotation= true):
Setup(anticommutativeprefix= Psi):

am:= (i,j,sigma)-> Annihilation(Psi, 6*(i-1)+2*(j-1)+sigma, notation= explicit):
ap:= (i,j,sigma)-> Creation(Psi, 6*(i-1)+2*(j-1)+sigma, notation= explicit):
nn:= ap.am:

N:= f -> sum(sum(sum(nn(i,j,sigma), sigma= 1..2), j= 1..3), i= 1..f):

psi := Ket(Psi, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0):
f := 2:
N(f).psi;

Output:
Error, (in Creation) invalid input: too many and/or wrong type of arguments passed to Creation; first unused argument is 6*i-8+2*j+sigma

A special thanks for grammar correction!

## I wonder why it doesn't work...

nn:= ap.am: is a nice feature!

restart:
with(Physics):
Setup(mathematicalnotation= true):
Setup(anticommutativeprefix= Psi):

am:= (i,j,sigma)-> Annihilation(Psi, 6*(i-1)+2*(j-1)+sigma, notation= explicit):
ap:= (i,j,sigma)-> Creation(Psi, 6*(i-1)+2*(j-1)+sigma, notation= explicit):
nn:= ap.am:

N:= f -> sum(sum(sum(nn(i,j,sigma), sigma= 1..2), j= 1..3), i= 1..f):

psi := Ket(Psi, 1, 0, 1, 1, 0, 0, 0, 1, 1, 0, 0, 0):
f := 2:
N(f).psi;

Output:
Error, (in Creation) invalid input: too many and/or wrong type of arguments passed to Creation; first unused argument is 6*i-8+2*j+sigma

A special thanks for grammar correction!