## 80 Reputation

14 years, 166 days

## I found a work around my own problem...

Instead of a URL I now use a button with an image icon showing the first
image of the animation.

The button action is something like:

use DocumentTools in
pid:=system[launch]("C:\\Program Files\\Internet Explorer\\iexplore.exe file://C:\\Users\...\\Documents\\...l\\Animation.htm ");
end use;
This will lauch iexplorer without exiting the Slideshow mode in
MAPLE and MAPLEPLAYER

## Optimizing the GIF generated by MAPLE...

To generate a GIF you right click on the plot and <export> it in GIF.
It may not be optimized. I used the Gimp software to compress it without
loss of resolution with impressive results.

## Thank you !...

@acer
I was not aware of this startup code options. Sorry.
The first example works best since it can be run again with full MAPLE without changing the graphic size.

## Buttons not working in a MaplePlayer Sli...

Here is an example code of what I want to do for my talk.

It works in a Maple Slideshow but not in a MaplesPlayer Slideshow (F11 function key)

MaplePlayerSlideShowTest.mw

## Using version 5 of the ExpandQop and new...

I did not have time work on this subject since a long time.

Here are some of my latest work.
1) I added a few lines to the ExpandQop version 4 available in the last post it is now at version 5.
2) Created two procedures to work more easily with multiple qubits using the StringTool package they are in the ImplodeExplodeStates.mw file below
3) The new QuantumTeleportation file provides
a) The dentisty matrix of |phi2>
b) Some examples of calculations with partial traces.

Hope this is interresting.

ImplodeExplodeStates.mw

Author:  Louis Lamarche   lamarche.louis@ireq.ca
Institute of Research of Hydro-Quebec (IREQ)
Science des données et calcul haute performance
2018, July 25

File:        QuantumTeleportationDensityMatrix.mw

Purpose:  Teleport a pure quantum state

This versoin was tested in Maple2018.1 and Maple2018.2 using
the ExpandQopV5 procedure and the ImplodeExplodeStates procedures.

Note: Multi qubits states and operators are represented
by sums of tensor products of non commutative bras
and kets.

 > restart; with(Physics): with(StringTools): Physics:-Version(); interface(imaginaryunit=i): Setup(mathematicalnotation=true);
 (1)
 > Setup(unitaryoperators={I,U,X,Y,Z,H,HI,CNOT,CnotI,rho}); Setup(noncommutativeprefix={q,beta,psi,ket});
 (2)
 > Setup(bracketrules= { %Bracket(%Bra(q0), %Ket(q0))=1,                       %Bracket(%Bra(q1), %Ket(q1))=1,                       %Bracket(%Bra(q1), %Ket(q0))=0,                       %Bracket(%Bra(q0), %Ket(q1))=0                     });
 (3)
 > ################################################################################ # Load the procedure and set the required global variables # read "ExpandQopV5.m": optp:=op(0,Ket(q0)*Ket(q1)): optpx:= op(0,(Ket(q0)+Ket(q1))^2): read "ImplodeExplodeStates.m": # ################################################################################
 > IS:=proc(state) ImplodeState(state) end proc: # Usefull ImplodeState name contraction ES:=proc(state) ExplodeState(state) end proc: # Usefull ExplodeState name contraction # Define the Ket and the Bra DS:=proc(name)     Ket(name):=ES(Ket(name)); Bra(name):=Dagger(Ket(name));     return 'Ket(name)'=Ket(name), 'Bra(name)'=Bra(name);     end proc: # Undefine a multiqubit state UD:=proc(name)     Ket(name):='Ket(name)';   Bra(name):='Bra(name)';     return;     end proc:
 > # This is usefull to represent a 2 qubits system DefineStates:=proc()     DS(q00); DS(q01); DS(q10); DS(q11);     return;     end proc: UndefineStates:=proc()     UD(q00); UD(q01); UD(q10); UD(q11);     return;     end proc:
 > # # ... Lines of first post deleted #
 > UndefineStates(); # To prevent interference with the ImplodeState procedure
 > # # Display the operator x in matrix form # OPtoMatrix:=proc(x,values)     # values = true:  compute the symbolic values     # values = false: return the marix element names     local j,k,l,m,n,o,ik,bk,ret,iket,ibra,bra,ket;          ik[0]:=Ket(q0); bk[0]:=Bra(q0);     ik[1]:=Ket(q1); bk[1]:=Bra(q1);     ret:=Matrix(8,8);     for j from 0 to 1 do         for k from 0 to 1 do             for l from 0 to 1 do                 ibra:=j*4+k*2+l+1;                 bra:=bk[l]*bk[k]*bk[j]; # Ordre inversé                 for m from 0 to 1 do                     for n from 0 to 1 do                         for o from 0 to 1 do                             iket:=m*4+n*2+o+1;                             ket:=ik[m]*ik[n]*ik[o];                             if values                             then ret[ibra,iket]:=bra.x.ket;                             else ret[ibra,iket]:=ImplodeState(bra).'rho'.ImplodeState(ket);                             fi;                         end do;                     end do;                 end do;             end do;         end do;     end do;     return ret;     end proc:
 > print("I would never try to compute this by hand"); rho:=ExpandQop(Ket(psi[2])*Dagger(Ket(psi[2]))): # this operator has 8x8=64 terms 'rho[m]'=OPtoMatrix(rho,false); 'rho[m]'=OPtoMatrix(rho,true);
 (4)
 > rho__Alice=Tr__Bob('rho');
 (5)
 > SomBob:=proc(k)    local ret,j,ik;    ik[0]:=Ket(q0);    ik[1]:=Ket(q1);    ret:=0;    for j from 0 to 1 do        ret:=ret+Dagger(k*ik[j]).rho.(k*ik[j]);    end do;    return ret;    end proc:
 > "Matrix elements of", rho__Alice; '(Bra(q0)*Bra(q0)).rho__Alice.(Ket(q0)*Ket(q0))'='Dagger(Ket(q0)*Ket(q0)*Ket(q1)).rho.(Ket(q0)*Ket(q0)*Ket(q1))'                                                 +'Dagger(Ket(q0)*Ket(q0)*Ket(q0)).rho.(Ket(q0)*Ket(q0)*Ket(q0))'; '(Bra(q0)*Bra(q0)).rho__Alice.(Ket(q0)*Ket(q0))'=SomBob(Ket(q0)*Ket(q0)); '(Bra(q1)*Bra(q0)).rho__Alice.(Ket(q0)*Ket(q1))'=SomBob(Ket(q0)*Ket(q1)); '(Bra(q0)*Bra(q1)).rho__Alice.(Ket(q1)*Ket(q0))'=SomBob(Ket(q1)*Ket(q0)); '(Bra(q1)*Bra(q1)).rho__Alice.(Ket(q1)*Ket(q1))'=SomBob(Ket(q1)*Ket(q1));
 (6)
 > rhoAlice:=proc(rho)    local ret,j,k,l,ik,elem,ket,bra,ketbra;    ik[0]:=Ket(q0);    ik[1]:=Ket(q1);    ret:=0;    for j from 0 to 1 do        for k from 0 to 1 do           elem:=0;           ket:=ik[j]*ik[k];           bra:=Dagger(ket);           ketbra:=ket*bra;                   for l from 0 to 1 do               # Sum over Bobs single qubit               elem:=elem+Dagger(ket*ik[l]).rho.(ket*ik[l]);           end do;           ret:=ret+elem*ketbra;        end do;    end do;    return ret;    end proc:
 > rho__Alice:=simplify(rhoAlice(rho));
 (7)
 > rhoBob:=proc(rho)    local ret,j,k,l,ik,elem,ket,bra,ketbra;    ik[0]:=Ket(q0);    ik[1]:=Ket(q1);    ret:=0;    for j from 0 to 1 do        elem:=0;        ketbra:=ik[j]*Dagger(ik[j]);        # Sum over Alice two qubits        for k from 0 to 1 do           for l from 0 to 1 do               ket:=ik[k]*ik[l];               bra:=Dagger(ket);               elem:=elem+Dagger(ket*ik[j]).rho.(ket*ik[j]);           end do;                  end do;        ret:=ret+elem*ketbra;    end do;    return ret;    end proc:
 > rho__Bob:=simplify(rhoBob(rho));
 (8)
 > M__0:=Ket(q0)*Bra(q0); M__1:=Ket(q1)*Bra(q1);
 (9)
 > p__0=Tr('M__0'.Dagger('M__0').'rho__Bob'); p__0=Tr(M__0.Dagger(M__0).rho__Bob); Tr(M__0.Dagger(M__0).rho__Bob)='Bra(q0).M__0.Dagger(M__0).rho__Bob.Ket(q0)'; Tr(M__0.Dagger(M__0).rho__Bob)=Bra(q0).M__0.Dagger(M__0).rho__Bob.Ket(q0); p__0:=rhs(%); abs(a)^2+abs(b)^2=1; 'p__0'=1/2; 'M__0.rho__Bob.Dagger(M__0)'=M__0.rho__Bob.Dagger(M__0); print("State of Bob's qubit after he measures 0"); 'rho[0]'=rhs(%)/p__0;
 (10)
 > p__1=Tr(M__1.Dagger(M__1).rho__Bob); Tr(M__1.Dagger(M__1).rho__Bob)='Bra(q1).M__1.Dagger(M__1).rho__Bob.Ket(q1)'; Tr(M__1.Dagger(M__1).rho__Bob)=Bra(q1).M__1.Dagger(M__1).rho__Bob.Ket(q1); p__1:=rhs(%); abs(a)^2+abs(b)^2=1; 'p__1'=1/2; 'M__1.rho__Bob.Dagger(M__1)'=M__1.rho__Bob.Dagger(M__1); print("State of Bos's qubit after he measures 1"); 'rho[1]'=rhs(%)/p__1;
 (11)
 > rho2:=(I/2*I/2*rho__Bob);
 (12)
 > 'rhoBob(I/2*I/2*rho__Bob)-rho__Bob'=simplify(rhoBob(rho2)-rho__Bob);
 (13)
 > rho3:=rho__Alice*I/2:
 > 'rhoAlice(rho__Alice*I/2)-rho__Alice'=simplify(rhoAlice(rho3)-rho__Alice);
 (14)
 > # A more general solution to compute the partual trace Tr__partial:=proc(mask,rho)     local n,j,ik,bk,me,ret,rho__sub, mask__sub;     ik[0]:=Ket(q0); bk[0]:=Bra(q0);     ik[1]:=Ket(q1); bk[1]:=Bra(q1);     n:=nops(mask);     ret:=0;     if n > 1 then mask__sub:=[seq(mask[j],j=2..n)]; fi;          for j from 0 to 1 do         if n > 1 then             rho__sub:=bk[j].rho.ik[j];             me:=Tr__partial(mask__sub,rho__sub);         else             me:=bk[j].rho.ik[j];         fi;         if op(1,mask)=0 then             # me:=ExpandQop(ik[j]*bk[j]*me);             me:=(ik[j]*bk[j]*me);         fi;         ret:=ret+me;     end do;     return ret;     end proc:
 > AliceBits:=[1,1,0]; BobBits  :=[0,0,1];
 (15)
 > simplify(Tr__partial(AliceBits,rho)); 'Tr__partial(AliceBits,rho)-rho__Bob'=%-rho__Bob;
 (16)
 > simplify(ExpandQop(Tr__partial(BobBits,rho))); 'Tr__partial(BobBits,rho)-rho__Alice'=%-rho__Alice;
 (17)
 > AllBits:=[1,1,1]; 'Tr(rho)'='Tr__partial(AllBits,rho)'; 'Tr(rho)'=ExpandQop(Tr__partial(AllBits,rho));
 (18)
 > NoBits:=[0,0,0]; 'rho[diagonal]'=Tr__partial(NoBits,rho);
 (19)
 > 'rho[diagonal]'=simplify(ExpandQop(Tr__partial(NoBits,rho)));
 (20)
 >

## New documentation for the ExpandQop proc...

I did have any time to work on that subject until this last weekend.

Here is and update version 5 of the procedure documentation.
1) I have many typos corrected
2) The text is in Maple document block mode

 (1)

-----------------------------------
File: ExpandQopV5-doc.mw
-----------------------------------

------------------------------------------------------------------------------------------------
NOTICE
Author: Louis Lamarche
Institute of Research of Hydro-Quebec (IREQ)
Science des données et calcul haute performance
2018, August 1

Function name: ExpandQop (x)
Purpose: Compute the tensor product of two quantum
operators in Dirac notations
Argument:
x: a quantum operator defined with non-commutative products
of Bras and Kets

Description: This procedure is a hand-crafted parser for expanding
polynomials of non-commutative Kets  and Bras

Version: 5

Note 1: Permission to use this software is granted if you
Note 2: Permission to copy this software is granted if you
leave this notice intact. Thank you.
--------------------------------------------------------------------------------------------------

Theory:

Let  be a Hilbert space of dimension k spanned by its associated orthonormal Ket vectors set  {,... } satisfying the relation  describing a single particle, qubit or system. The projector operator on an arbitrary state of that system is defined as , where  2 {}. Suppose we now consider a system with two similar particles, qubits or systems. The projector on an arbitrary state of the second system becomes , where  2 {}. The states of the combines systems are described using a tensor product. A simple state of the resulting Hilbert space named  is by consequence defined by the equality . An important convention to adopt is how to represent the bra vector of this Ket. The usual convention is to use , so that the scalar, interior or dot product ()  of the bra with the Ket is given by  . The procedure to compute this dot product requires a mental operation of counting and associating the left-hand side components before the dot ()  with their right-hand side counterparts. This  is useful for Hilbert spaces of small dimensions but may become tedious on a large Hilbert space. The convention proposed here (and already used by some researcher) is at the opposite . The dot product then becomes. . The rules are simple, the dot operator consumes the Kets from left to right and the Bras from right to left. Any tensor product operator 5 applied to a complex number returns that complex number.

Incidentally, MAPLE does this automatically if we specify that the Bras and Kets names begin with dedicated prefixes declared as non-commutative, with for instance the statement:

The Physics,* description says:

When computing with quantum-state vectors in Dirac notation, the Physics * operator also represents the tensor product of Bras and Kets , such as in   (a quantum operator) or  (a Ket  of the tensor product of spaces).

Also the Physics,.  description says:

Scalar product between Bras, Kets, and quantum operators, and simplification of contracted indices in spacetime tensors
...
In the following situations, the scalar product can be performed:
...
A bracket rule , for example, for  or , where  represents a generic quantum operator, has been previously set by Setup , and so determines the result.

In the present application all quantum operators will be described in terms of Dirac notations. We will not use:

 • argument 2..n of the Ket and Bra vectors procedures representing quantum numbers and defining implicitly orthonormal basis.

 • The implicit definition of the relation between quantum operators and their orthonormal basis

Now noting that , a__n = being just a name in the left-hand side, while on the right-hand side we have a Ket with an implicit quantum number property.

 (2)

We can see that,

'Ket(a__1*a__2)' = Ket(a__1)*Ket(a__2);
'Bra(a__1*a__2)' = 'Dagger(Ket(a__1)*Ket(a__2))';
'Bra(a__1*a__2)' = Dagger(Ket(a__1)*Ket(a__2));
'Bracket(Bra(a__1*a__2),Ket(a__1*a__2))'='Dagger(Ket(a__1)*Ket(a__2)).(Ket(a__1)*Ket(a__2))';
'Bracket(Bra(a__1*a__2),Ket(a__1*a__2))'=Dagger(Ket(a__1)*Ket(a__2)).(Ket(a__1)*Ket(a__2));

 (3)

Let A be an operator on the tensor product of 1..n of such Hilbert spaces (describing for instance n similar particles or qubits). A is operating in Hilbert space  (n times)  naming an arbitrary orthonormal Ket vector of the  particle with the index n,  where cn, 2 {}. We now consider a possible instance of A.

Let  be a second Hilbert space of dimension l spanned by its associated orthonormal Ket vectors set {,... } satisfying the relation . Let B be an operator on the tensor product of 1..m of such Hilbert spaces (describing for instance m similar particles or qubits).  B is operating in Hilbert space  (m times)  naming an arbitrary orthonormal Ket vector of the  particle with the index m,  where cm, 2 {}. We now consider a possible instance of B.

The tensor product C of these two operators acts on Hilbert space   = . The resulting Hilbert space size is consequently equal to . The expression of the product using the convention given above is,

\___________________________  ___________________________/

## Trying disjointed spaces for the Quantum...

I tried today to implement a quantum teleportation using the hilbertspaces option of the
Physics package for Maple 2017 issued in March 2018. I was unable to implement a
2 qubit operator. It appears to be issues in commutator rules and inner product definition.

 > restart;
 >
 > Physics:-Version();
 (1)
 > Setup(hilbertspaces = {A, B}); Setup(noncommutativeprefix={psi,v,q});
 (2)
 > # Setup(hideketlabel=true);
 > Setup(mathematicalnotation=true); print("Inner or scalar products."); print("The gereral product (*) operator is needed to make it work"); 'Bra(A,1)*Ket(A,1)'=Bra(A,1)*Ket(A,1); print("The inner product (.) operator is not defined");  'Bra(A,1).Ket(A,1)'=Bra(A,1).Ket(A,1), "NOT OK"; 'Bra(A,1)*Ket(A,0)'=Bra(A,1)*Ket(A,0); 'Bra(A,0)*Ket(A,1)'=Bra(A,0)*Ket(A,1); 'Bra(A,1)*Ket(A,1)'=Bra(A,1)*Ket(A,1); 'Bra(B,1)*Ket(B,1)'=Bra(B,1)*Ket(B,1); 'Bra(B,1)*Ket(B,0)'=Bra(B,1)*Ket(B,0); 'Bra(B,0)*Ket(B,1)'=Bra(B,0)*Ket(B,1); 'Bra(B,1)*Ket(B,1)'=Bra(B,1)*Ket(B,1); print("Outer products defined using the (*) general product"); Ket(A,0)*Bra(A,0); Ket(A,1)*Bra(A,0); Ket(A,0)*Bra(A,1); Ket(A,1)*Bra(A,1); Ket(B,0)*Bra(B,0); Ket(B,1)*Bra(B,0); Ket(B,0)*Bra(B,1); Ket(B,1)*Bra(B,1); print("Needed working for mutiple qubit systems, OK"); 'Ket(A,1)*Ket(B,1)-Ket(B,1)*Ket(A,1)'=Ket(A,1)*Ket(B,1)-Ket(B,1)*Ket(A,1); 'Ket(A,1)*Ket(B,1)-Ket(B,1)*Ket(A,1)'<>0, "OK IMHO"; 'Ket(A,0)*Ket(B,1)-Ket(B,1)*Ket(A,0)'=Ket(A,0)*Ket(B,1)-Ket(B,1)*Ket(A,0), "NOT OK IMHO";
 (3)
 >

## New version of the ExpandQop procedure ...

This new version will handle
OP8 := sqrt(2)*(Ket(q0)-Ket(q1))*(Bra(q0)-Bra(q1))*(1/(1+sqrt(2)))

= sqrt(2)*(Ket(q0)*Bra(q0)-Ket(q1)*Bra(q0)-Ket(q0)*Bra(q1)+Ket(q1)*Bra(q1))*(1/(1+sqrt(2)))

## Correction to the Y operator...

NOTE: this as not impact on the example but

Y:=i*Ket(q1)*Bra(q0)-i*Ket(q0)*Bra(q1);    # = sigma[2] = sigma[y]

and not

Y:=-i*Ket(q1)*Bra(q0)+i*Ket(q0)*Bra(q1);

## Update version for the Maple2018 Physics...

I have include here an upgrade of the ExpandQop procedure compatible with theMaple2018
Physics Library. It  is essentially a parser of non commutativre products of Bras and Kets
defined in the Physics package.

Quantum qubit circuits diagrams states where the qubits are viewed from top to bottom are
represented by tensor products of noncommutative  Ket(q0) and Ket(q1)  aligned from left to right.

Global operators on a set of qubits are represented by tensor product of operators. For instance
H * I * Cnot  is a four qubit operator and applies the Hadamard operator on the firts qubit, and
Identity to the second and a Cnot operation on the last two.

I will try to see if this can be made compatible with the work done by the
Physics of Information Lab of the University of Waterloo . It would be great if we could mix
qubits and harmonic oscillators.

The first file contains the procedure ExpandQop.mw
The second contains a test workshhep for the procedure ExpandQopTests.mw
The third contains an upgrade version of the quantum teleportation example. QuantumTeleportation.mw

## First try of the disjointed spaces optio...

I am having difficulties applying the option to get what is needed probably due
to a lack of understading of this disjointed spaces option.

The example you gave works fine but I did not obtained the good result
when trying to define a tensor product of two operator operating
on multiple qubits.

LL

 > restart;
 >
 > Physics:-Version();
 (1)
 > Setup(quantumoperators={A,B,C,E,F,G});
 (2)
 > Setup(hilbertspaces = {a__1, a__2, a__3, a__4, a__5, b__1, b__2, b__3, q__0, q__1})
 (3)
 > Setup(mathematicalnotation=true);
 (4)
 >
 (5)
 >
 (6)
 >
 (7)
 >
 (8)
 >
 (9)
 > kets3 := Ket(q__1)*Ket(q__0)*Ket(q__1)*Ket(q__0)*Ket(q__1); kets4 := Ket(q__0)*Ket(q__0)*Ket(q__1)*Ket(q__1)*Ket(q__1); E:=kets3*Dagger(kets3); F:=kets4*Dagger(kets4); G := E*F;
 (10)

 > #################################################################################### # Load the procedure and set the required global variables # Using version 3 read "ExpandQop.m": optp:=op(0,Ket(q0)*Ket(q1)): optpx:= op(0,(Ket(q0)+Ket(q1))^2): # ####################################################################################
 > print("Using ExpandQop on G gives the same result."); print("This is related to the presence of indexes in the names."); ExpandQop(G);
 (11)
 > print("Defining the operators in a other way works better"); kets3 := Ket(q,1)*Ket(q,0)*Ket(q,1)*Ket(q,0)*Ket(q,1); kets4 := Ket(q,0)*Ket(q,0)*Ket(q,1)*Ket(q,1)*Ket(q,1); E:=kets3*Dagger(kets3); F:=kets4*Dagger(kets4); G := E*F; print("But the expandQop is needed for the solution"); 'ExpandQop(G)'=ExpandQop(G);
 (12)
 > print("Now trying something else"); kets3 := Ket(q,1,0,1,0,1); kets4 := Ket(q,0,0,1,1,1); E:=kets3*Dagger(kets3); F:=kets4*Dagger(kets4); G:=E*F;
 (13)
 > print("This is what is needed"); Setup(noncommutativeprefix={q}); kets3 := Ket(q1)*Ket(q0)*Ket(q1)*Ket(q0)*Ket(q1); kets4 := Ket(q0)*Ket(q0)*Ket(q1)*Ket(q1)*Ket(q1); E:=kets3*Dagger(kets3); F:=kets4*Dagger(kets4); Gok := E*F; Gok:=ExpandQop(Gok);
 (14)
 >

## Tensor product of quantum states...

@ecterrab
It is necessary to use the
Setup(noncommutativeprefix={a,b,c});

Physics("*")  operator now glues the bras and the kets in a non commutative way
that for instance Ket(a2)*Ket(a1) <> Ket(a1)*Ket(a1) . It appear that Maple will not reorder
the elements of these expressions. I used indexes the bras and kets but these are justs
names in the worksheet.

Implicitely  the non commutative  kets separated by the * operator belongs to different Hilbert
spaces. Each element of the product representing a different particule, qubit, position, momentum,
etc. state

I suggest that the ExpandQop solves the problem of computing the tensor product of
two operators defined with properly ordered non commutative kets and bras.

Now I will try to do it with the new Physics package.

Louis Lamarche
IREQ

The purpose of my post was to share my work and I thank you for your reply.

Point 1 - I  agree, this is my error. The Hilbert space size in m x n. I will correct that.

Point 2- The product of kets of one single Hilbert space do not form a tensor product.
a) The Physics ("*")  definition plus the
Setup(noncommutativeprefix={a,b,c}) rule
enables to form new states in the tensor product of the Hilbert spaces.
b)  Operators apprears when we have Bras and Kets back to back.

Point 3- I will very interrested in using and tresting this new library update. For the moment the
Setup(hilberspaces=...) is nor defined in my version.

Thank you again.

LL

## Sorry I found the solution...

Not using quantum numbers for the state vectors solve the issue.

## Difficulty to use the tensor product of ...

It appears the the sent program was not included in the post.

This computer the tensor product an arbitrairy Vet vector with
the Bell State B00. The simplified expression is wrong.

 1 2 Page 1 of 2
﻿