K i.dZddlmZddlmZddlmZddlmZddl m Z ddl m Z ddl m Z mZmZmZdd lmZdd lmZmZdd lmZdd lmZmZdd lmZddlmZddlm Z m!Z!ddl"m#Z#ddl$m%Z%ddl&m'Z'm(Z(ddl)m*Z*ddl+m,Z,ddl-m.Z.m/Z/m0Z0ddl1m2Z2m3Z3m4Z4ddl5m6Z6ddl7m8Z8ddl9m:Z:m;Z;ddlm?Z?ddl@mAZAgdZBdZCGdd ZDGd!d"eDe/ZEGd#d$eDe/ZFGd%d&eDe.ZGGd'd(eDe.ZHGd)d*eDe.ZIGd+d,eDe.ZJGd-d.e0ZKGd/d0eZLeGd1ZMeHd1ZNeId1ZOeJd1ZPeEd1ZQeFd1ZRGd2d3e4ZSGd4d5eSe3ZTGd6d7eSe2ZUGd8d9eSe3ZVGd:d;eSe2ZWGd<d=eSe3ZXGd>d?eSe2ZYd@ZZGdAdBeSZ[GdCdDe[e3Z\GdEdFe[e2Z]GdGdHe[e3Z^GdIdJe[e2Z_GdKdLe[e3Z`GdMdNe[e2ZadUdPZbdQZcdVdRZddSZedTZfyO)Wz$Quantum mechanical angular momentum.)Sum)Add)Tuple)Expr) int_valued)Mul)IIntegerRationalpi)S)Dummysymbols)sympify)binomial factorial)exp)sqrt)cossin)simplify)zeros) prettyForm stringPict pretty_symbol)QExpr)HermitianOperatorOperatorUnitaryOperator)BraKetState)KroneckerDelta)hbar) ComplexSpaceDirectSumHilbertSpace) TensorProduct)CG)qapply)m_valuesJplusJminusJxJyJzJ2RotationWignerDJxKetJxBraJyKetJyBraJzKetJzBraJzOpJ2Op JxKetCoupled JxBraCoupled JyKetCoupled JyBraCoupled JzKetCoupled JzBraCoupledcoupleuncouplect|}d|zdz}|jr|dkDstd|z|tt d|zdzDcgc]}||z  c}fScc}w)Nrz$qzz/* tAJJ &% %8'ahh''rZc >|jjSrR)_represent_default_basistracer`rxs rN _eval_tracezSpinOpBase._eval_traces ,,.4466rZN)__name__ __module__ __qualname____doc__ classmethodrXpropertyrarhrorrr~rrrrrrrrrrrZrNrPrPNsq(((12 5 '444444 %( 7rZrPcBeZdZdZdZdZdZdZdZdZ dZ d Z d Z y ) JplusOpzThe J+ operator.+r0c@dtzt|jzSNrE)r%r:rar`others rN_eval_commutator_JminusOpz!JplusOp._eval_commutator_JminusOpsvd499o%%rZc B|j}|j}|jr!|jr||k\rtjSt t ||tjzz||tjzzz zt||tjzzSrR rKr is_Numberr Zeror%rOner8r`rrxrKrs rNrzJplusOp._apply_operator_JzKetsr EE EE ;;1;;Avvv DAIAI677aQUU8KKKrZc v|j}|j}|j}|j}|jr!|jr||k\rt j Stt||t jzz||t jzzz zt||t jz||zSrR rKrjncouplingrr rr%rrr@r`rrxrKrrrs rNrz$JplusOp._apply_operator_JzKetCoupleds EE EE VV<< ;;1;;Avvv DAIAI677 QAEE SUW_8```rZctt||tjzz||tjzzz z}|t ||dzz}|t ||z}|Srr%rr rr$r`rKrjpmprzs rNrvzJplusOp.matrix_elementYd1a!%%i=2rAEEz?:;;.BF++.B'' rZc &|jdi|SNrR_represent_JzOprs rNrz JplusOp._represent_default_basis#t##4G44rZc (|j|fi|SrRr~r`rwrxs rNrzJplusOp._represent_JzOp#t##E5W55rZcJt|dtt|dzzSr\rr rr`r^kwargss rN_eval_rewrite_as_xyzzJplusOp._eval_rewrite_as_xyz!DG}qd1g..rZN) rrrrrerwrrrrvrrrrrZrNrrs4 F E&La 56/rZrc<eZdZdZdZdZdZdZdZdZ dZ d Z y ) JminusOpzThe J- operator.-r0c D|j}|j}|jr"|jr|| krtjSt t ||tjzz||tjz zz zt||tjz zSrRrrs rNrzJminusOp._apply_operator_JzKetst EE EE ;;1;;QBwvv DAIAI677aQUU8KKKrZc x|j}|j}|j}|j}|jr"|jr|| krt j Stt||t jzz||t jz zz zt||t jz ||zSrRrrs rNrz%JminusOp._apply_operator_JzKetCoupleds EE EE VV<< ;;1;;QBwvv DAIAI677 QAEE SUW_8```rZctt||tjzz||tjz zz z}|t ||dz z}|t ||z}|Srrrs rNrvzJminusOp.matrix_elementrrZc &|jdi|Srrrs rNrz!JminusOp._represent_default_basisrrZc (|j|fi|SrRrrs rNrzJminusOp._represent_JzOprrZcJt|dtt|dzz Sr\rrs rNrzJminusOp._eval_rewrite_as_xyzrrZN) rrrrrerwrrrvrrrrrZrNrrs/ F ELa 56/rZrcBeZdZdZdZdZdZdZdZdZ dZ d Z d Z y ) rzThe Jx operator.xr.cHttzt|jzSrR)r r%r:rars rN_eval_commutator_JyOpzJxOp._eval_commutator_JyOp vd499o%%rZcJt tzt|jzSrRr r%rrars rN_eval_commutator_JzOpzJxOp._eval_commutator_JzOp r$wtDII&&rZc t|jj|fi|}t|jj|fi|}||zt dz Sr)rrarrr r`rrxrjms rNrzJxOp._apply_operator_JzKetsU 5WTYY  5 5c EW E 6Xdii 6 6s Fg FR##rZc t|jj|fi|}t|jj|fi|}||zt dz Sr)rrarrr rs rNrz!JxOp._apply_operator_JzKetCoupledsU >> from sympy import pi >>> from sympy.physics.quantum.spin import Rotation >>> Rotation(pi, 0, pi/2) R(pi,0,pi/2) With symbolic Euler angles and calculating the inverse rotation operator: >>> from sympy import symbols >>> a, b, c = symbols('a b c') >>> Rotation(a, b, c) R(a,b,c) >>> Rotation(a, b, c).inverse() R(-c,-b,-a) See Also ======== WignerD: Symbolic Wigner-D function D: Wigner-D function d: Wigner small-d function References ========== .. [1] Varshalovich, D A, Quantum Theory of Angular Momentum. 1988. chtj|}t|dk7rtd|z|S)Nz 3 Euler angles required, got: %r)r _eval_argsrrH)rVr^s rNr2zRotation._eval_argss3% t9>?$FG G rZc4ttjSrRrSrUs rNrXzRotation._eval_hilbert_spacerYrZc |jdSr\rWr_s rNalphazRotation.alphazz!}rZc |jdSrr5r_s rNbetaz Rotation.betar7rZc |jdSrr5r_s rNgammazRotation.gammar7rZcy)NRrrfs rN_print_operator_namezRotation._print_operator_namesrZcF|jr tdStdS)Nuℛ zR ) _use_unicoderrfs rN_print_operator_name_prettyz$Rotation._print_operator_name_prettys"   :; ;d# #rZcy)Nz \mathcal{R}rrfs rN_print_operator_name_latexz#Rotation._print_operator_name_latexsrZc^t|j |j |j SrR)r2r;r9r6r_s rN _eval_inversezRotation._eval_inverse s# diiZ$**==rZc"t||||||S)agWigner D-function. Returns an instance of the WignerD class corresponding to the Wigner-D function specified by the parameters. Parameters =========== j : Number Total angular momentum m : Number Eigenvalue of angular momentum along axis after rotation mp : Number Eigenvalue of angular momentum along rotated axis alpha : Number, Symbol First Euler angle of rotation beta : Number, Symbol Second Euler angle of rotation gamma : Number, Symbol Third Euler angle of rotation Examples ======== Return the Wigner-D matrix element for a defined rotation, both numerical and symbolic: >>> from sympy.physics.quantum.spin import Rotation >>> from sympy import pi, symbols >>> alpha, beta, gamma = symbols('alpha beta gamma') >>> Rotation.D(1, 1, 0,pi, pi/2,-pi) WignerD(1, 1, 0, pi, pi/2, -pi) See Also ======== WignerD: Symbolic Wigner-D function r3)rVrKrrr6r9r;s rNDz Rotation.D sRq!Re44rZc"t|||d|dS)aWigner small-d function. Returns an instance of the WignerD class corresponding to the Wigner-D function specified by the parameters with the alpha and gamma angles given as 0. Parameters =========== j : Number Total angular momentum m : Number Eigenvalue of angular momentum along axis after rotation mp : Number Eigenvalue of angular momentum along rotated axis beta : Number, Symbol Second Euler angle of rotation Examples ======== Return the Wigner-D matrix element for a defined rotation, both numerical and symbolic: >>> from sympy.physics.quantum.spin import Rotation >>> from sympy import pi, symbols >>> beta = symbols('beta') >>> Rotation.d(1, 1, 0, pi/2) WignerD(1, 1, 0, 0, pi/2, 0) See Also ======== WignerD: Symbolic Wigner-D function rrG)rVrKrrr9s rNdz Rotation.d7sLq!RD!,,rZc|jj||||j|j|j}|t ||z}|SrR)rrHr6r9r;r$rs rNrvzRotation.matrix_element_sG!! 2tzz499djj  .B'' rZc rt|jdtj}t|jd}t |\}}t ||}t |D]K}t |D];} |j|||||| } |r| j||| f<5| ||| f<=M|S)NrKdoit) rrtr rur+rrIrvrM) r`rwrxrKevaluaterLryrzr{r|r}s rNr~zRotation._represent_basefs GKKQVV, -7;;v./qk etT"t &A4[ &((E!HaqB#%779F1a4L#%F1a4L  & & rZc &|jdi|Srrrs rNrz!Rotation._represent_default_basisurrZc (|j|fi|SrRrrs rNrzRotation._represent_JzOpxrrZT)dummyc |j}|j}|j}|j}|j} |j rfg} t |} | d} | D]G} tj|| | |||}|j}| j|||| zIt| S|r td} n td} ttj|| | |||||| z| | |fSNrFr)r6r9r;rKr is_numberr+r2rHrMrrrrr)r`rrrQrxrmrngrKrrrLszrrr s rN_apply_operator_uncoupledz"Rotation._apply_operator_uncoupled{s JJ II JJ EE EE ;;AA;DaB )JJq!RAq1FFH5B<( )7N4[T]xzz!QAq!4U1b\ABA;O OrZc 2|jt|fi|SrR)rXr4rs rNrzRotation._apply_operator_JxKet-t--eSDGDDrZc 2|jt|fi|SrR)rXr6rs rNrzRotation._apply_operator_JyKetrZrZc 2|jt|fi|SrR)rXr8rs rNrzRotation._apply_operator_JzKetrZrZc ,|j}|j}|j}|j}|j} |j } |j } |jrhg} t|} | d}|D]I}tj|| ||||}|j}| j||||| | zKt| S|r td}n td}t!tj|| |||||||| | z|| |fSrS)r6r9r;rKrrrrTr+r2rHrMrrrrr)r`rrrQrxrmrnrUrKrrrrrLrVrrWr s rN_apply_operator_coupledz Rotation._apply_operator_coupleds JJ II JJ EE EE VV<< ;;AA;DaB 7JJq!RAq1FFH5BH556 77N4[T]xzz!QAq!4U2r86%%')A2qk3 3rZc 2|jt|fi|SrR)r^r<rs rNrz%Rotation._apply_operator_JxKetCoupled+t++L#IIIrZc 2|jt|fi|SrR)r^r>rs rNrz%Rotation._apply_operator_JyKetCoupledr`rZc 2|jt|fi|SrR)r^r@rs rNrz%Rotation._apply_operator_JzKetCoupledr`rZN)rrrrrr2rXrr6r9r;r>rArCrErHrJrvr~rrrXrrrr^rrrrrZrNr2r2s1f (($ >(5(5T%-%-N 56>BP,EEE<@32JJJrZr2ceZdZdZdZdZedZedZedZ edZ edZ ed Z d Z d Zd Zd Zy)r3aWigner-D function The Wigner D-function gives the matrix elements of the rotation operator in the jm-representation. For the Euler angles `\alpha`, `\beta`, `\gamma`, the D-function is defined such that: .. math :: = \delta_{jj'} D(j, m, m', \alpha, \beta, \gamma) Where the rotation operator is as defined by the Rotation class [1]_. The Wigner D-function defined in this way gives: .. math :: D(j, m, m', \alpha, \beta, \gamma) = e^{-i m \alpha} d(j, m, m', \beta) e^{-i m' \gamma} Where d is the Wigner small-d function, which is given by Rotation.d. The Wigner small-d function gives the component of the Wigner D-function that is determined by the second Euler angle. That is the Wigner D-function is: .. math :: D(j, m, m', \alpha, \beta, \gamma) = e^{-i m \alpha} d(j, m, m', \beta) e^{-i m' \gamma} Where d is the small-d function. The Wigner D-function is given by Rotation.D. Note that to evaluate the D-function, the j, m and mp parameters must be integer or half integer numbers. Parameters ========== j : Number Total angular momentum m : Number Eigenvalue of angular momentum along axis after rotation mp : Number Eigenvalue of angular momentum along rotated axis alpha : Number, Symbol First Euler angle of rotation beta : Number, Symbol Second Euler angle of rotation gamma : Number, Symbol Third Euler angle of rotation Examples ======== Evaluate the Wigner-D matrix elements of a simple rotation: >>> from sympy.physics.quantum.spin import Rotation >>> from sympy import pi >>> rot = Rotation.D(1, 1, 0, pi, pi/2, 0) >>> rot WignerD(1, 1, 0, pi, pi/2, 0) >>> rot.doit() sqrt(2)/2 Evaluate the Wigner-d matrix elements of a simple rotation >>> rot = Rotation.d(1, 1, 0, pi/2) >>> rot WignerD(1, 1, 0, 0, pi/2, 0) >>> rot.doit() -sqrt(2)/2 See Also ======== Rotation: Rotation operator References ========== .. [1] Varshalovich, D A, Quantum Theory of Angular Momentum. 1988. Tct|dk(std|zt|}|jdd}|r$t j |g|j St j |g|S)Nz6 parameters expected, got %srNF)rrHrrtr__new__ _eval_wignerd)rVr^hintsrNs rNrfzWignerD.__new__sk4yA~(?@AC  ciiS399;->(?@AC ::?tzzQ>>$)),D3S=)A>>$**-Dtzz#/Dtzz'..*CDEDtzz#/Dtzz'..*DEFD3S=)A4;;=)  %  %  &rZc 6d|d<t|ji|S)NTrN)r3r^)r`rhs rNrMz WignerD.doit\s  j +U++rZc |j}|j}|j}|j}|j}|j }|dk(r|dk(r|dk(r t ||S|jstd|zd}|tdz k(rtd|zdzD]W}|||zkDs|||z kDs|||z kr|tj|zt||z|zt||z ||z|z zz }Y|tj||z zd|zz tt||zt||z zt||zt||z zz zz}nt!|\} } | D]} |t"j%||| tdz j't)| |zt*t-| |zzzzt"j%|| | tdz j'zz }|t*d|z|z |z zzdd|zzz}t/|}|t1t* |z|zt1t* |z|zzz}|S)Nrz1j parameter must be numerical to evaluate, got %srErF)rKrrr6r9r;r$rTrHr rIr NegativeOnerrrr+r2rJrMrr rrr) r`rKrrr6r9r;rWkrLrympps rNrgzWignerD._eval_wignerd`sj FF FF WW yy  A:$!) !!R( ({{CaGI I  2a4<1Q37^ Yq2v:QUa"q&jamma'R(;;HQVQQRUUWZ= 0, got: %sz*m must be integer or half-integer, got: %sz1Allowed values for m are -j <= m <= j, got j, m: z, z8Both j and m must be integer or half-integer, got j, m: )rrTrJrHabsr#rf)rVrKrs rNrfzSpinState.__new__s AJ AJ ;;sc!A#h @1DFF1u !:Q!>?? ;;sc!A#h @1DFF ;;1;;1vz ^_ab!cdd1q5zQU" efhi!jkk}}S!Q''rZc |jdSr\r5r_s rNrKz SpinState.jr7rZc |jdSrr5r_s rNrz SpinState.mr7rZc*td|dzdzS)NrErrF)r&rUs rNrXzSpinState._eval_hilbert_spacesAeAhJN++rZc 4|j}|j}t|jdd}t|jdd}t|jdd}t |\}}t |d} t |D]\} } |jrBtj|j| |j|||j| | df<Ttj|j| |j|||| | df<| S)Nr6rr9r;rF) rKrrrtr+r enumeraterTr2rHrM) r`rxrKrr6r9r;rLryrzr{mvals rNr~zSpinState._represent_bases FF FF GQ/0w{{61-. GQ/0qk etQ ' FGAt{{'zzFFD$&&%u >>Bdfq!t  (zz$&&$*.&&%u Fq!t  F rZct|tr|jttfi|S|jtt fi|SrR)rr!_rewrite_basisr.r5r4r`r^rxs rN_eval_rewrite_as_JxzSpinState._eval_rewrite_as_Jx@ dC &4&&r5@@DQqJ#>4>>$ ',../115a99=aC" a+d+ZZ2tvv772e8b1"a[119Rs Gc ft|j|j}|j|jur0||j d|j|j z z}|S|t|j|jt|j |j zz}|SrR)r$rK dual_classr_represent_JxOprr`brarhrzs rN_eval_innerproduct_JxBraz"SpinState._eval_innerproduct_JxBra . >> 4>> 1 d**40? ?F  n-dffcee<= =F rZc ft|j|j}|j|jur0||j d|j|j z z}|S|t|j|jt|j |j zz}|SrR)r$rKrr_represent_JyOprrs rN_eval_innerproduct_JyBraz"SpinState._eval_innerproduct_JyBrarrZc ft|j|j}|j|jur0||j d|j|j z z}|S|t|j|jt|j |j zz}|SrR)r$rKrrrrrs rN_eval_innerproduct_JzBraz"SpinState._eval_innerproduct_JzBrarrZc (||zjSrR)rM)r`rrhs rNrzSpinState._eval_trace&sD  rZN)rrrr_label_separatorrfrrKrrrXr~rrrrrrrrrrZrNrrsz1((,,$9 9 9 *2X !rZrcHeZdZdZedZedZdZdZdZ dZ y) r4zEigenket of Jx. See JzKet for the usage of spin eigenstates. See Also ======== JzKet: Usage of spin states ctSrRr5r_s rNrzJxKet.dual_classB rZctSrRr<r_s rN coupled_classzJxKet.coupled_classFrZc &|jdi|Sr)rrs rNrzJxKet._represent_default_basisJrrZc &|jdi|SNrrrs rNrzJxKet._represent_JxOpM#t##.g..rZc L|jddttddzi|SNr6r1rErr~r r rs rNrzJxKet._represent_JyOpPs(#t##G"Xa^*;GwGGrZc 8|jddtdz i|SNr9rErr~r rs rNrzJxKet._represent_JzOpSs!#t##9A999rZN rrrrrrrrrrrrrZrNr4r46sD 5/H:rZr4c0eZdZdZedZedZy)r5zEigenbra of Jx. See JzKet for the usage of spin eigenstates. See Also ======== JzKet: Usage of spin states ctSrRr4r_s rNrzJxBra.dual_classcrrZctSrRr=r_s rNrzJxBra.coupled_classgrrZNrrrrrrrrrZrNr5r5W/ rZr5cHeZdZdZedZedZdZdZdZ dZ y) r6zEigenket of Jy. See JzKet for the usage of spin eigenstates. See Also ======== JzKet: Usage of spin states ctSrRr7r_s rNrzJyKet.dual_classxrrZctSrRr>r_s rNrzJyKet.coupled_class|rrZc &|jdi|Sr)rrs rNrzJyKet._represent_default_basisrrZc 8|jddtdz i|SNr;rErrrs rNrzJyKet._represent_JxOps!#t##:"Q$:'::rZc &|jdi|Srrrs rNrzJyKet._represent_JyOprrZc n|jdttddzt dz tdz d|SNr1rE)r6r9r;rrrs rNrzJyKet._represent_JzOps8#t##_"Xa^*;2#a%rRSt_W^__rZNrrrZrNr6r6lsD 5;/`rZr6c0eZdZdZedZedZy)r7zEigenbra of Jy. See JzKet for the usage of spin eigenstates. See Also ======== JzKet: Usage of spin states ctSrRr6r_s rNrzJyBra.dual_classrrZctSrRr?r_s rNrzJyBra.coupled_classrrZNrrrZrNr7r7rrZr7cHeZdZdZedZedZdZdZdZ dZ y) r8aN Eigenket of Jz. Spin state which is an eigenstate of the Jz operator. Uncoupled states, that is states representing the interaction of multiple separate spin states, are defined as a tensor product of states. Parameters ========== j : Number, Symbol Total spin angular momentum m : Number, Symbol Eigenvalue of the Jz spin operator Examples ======== *Normal States:* Defining simple spin states, both numerical and symbolic: >>> from sympy.physics.quantum.spin import JzKet, JxKet >>> from sympy import symbols >>> JzKet(1, 0) |1,0> >>> j, m = symbols('j m') >>> JzKet(j, m) |j,m> Rewriting the JzKet in terms of eigenkets of the Jx operator: Note: that the resulting eigenstates are JxKet's >>> JzKet(1,1).rewrite("Jx") |1,-1>/2 - sqrt(2)*|1,0>/2 + |1,1>/2 Get the vector representation of a state in terms of the basis elements of the Jx operator: >>> from sympy.physics.quantum.represent import represent >>> from sympy.physics.quantum.spin import Jx, Jz >>> represent(JzKet(1,-1), basis=Jx) Matrix([ [ 1/2], [sqrt(2)/2], [ 1/2]]) Apply innerproducts between states: >>> from sympy.physics.quantum.innerproduct import InnerProduct >>> from sympy.physics.quantum.spin import JxBra >>> i = InnerProduct(JxBra(1,1), JzKet(1,1)) >>> i <1,1|1,1> >>> i.doit() 1/2 *Uncoupled States:* Define an uncoupled state as a TensorProduct between two Jz eigenkets: >>> from sympy.physics.quantum.tensorproduct import TensorProduct >>> j1,m1,j2,m2 = symbols('j1 m1 j2 m2') >>> TensorProduct(JzKet(1,0), JzKet(1,1)) |1,0>x|1,1> >>> TensorProduct(JzKet(j1,m1), JzKet(j2,m2)) |j1,m1>x|j2,m2> A TensorProduct can be rewritten, in which case the eigenstates that make up the tensor product is rewritten to the new basis: >>> TensorProduct(JzKet(1,1),JxKet(1,1)).rewrite('Jz') |1,1>x|1,-1>/2 + sqrt(2)*|1,1>x|1,0>/2 + |1,1>x|1,1>/2 The represent method for TensorProduct's gives the vector representation of the state. Note that the state in the product basis is the equivalent of the tensor product of the vector representation of the component eigenstates: >>> represent(TensorProduct(JzKet(1,0),JzKet(1,1))) Matrix([ [0], [0], [0], [1], [0], [0], [0], [0], [0]]) >>> represent(TensorProduct(JzKet(1,1),JxKet(1,1)), basis=Jz) Matrix([ [ 1/2], [sqrt(2)/2], [ 1/2], [ 0], [ 0], [ 0], [ 0], [ 0], [ 0]]) See Also ======== JzKetCoupled: Coupled eigenstates sympy.physics.quantum.tensorproduct.TensorProduct: Used to specify uncoupled states uncouple: Uncouples states given coupling parameters couple: Couples uncoupled states ctSrRr9r_s rNrzJzKet.dual_classrrZctSrRr@r_s rNrzJzKet.coupled_classrrZc &|jdi|Srrrs rNrzJzKet._represent_default_basisrrZc L|jddttddzi|SNr9r1rErrrs rNrzJzKet._represent_JxOps(#t##FHQN):FgFFrZc l|jdttddztdz tdz d|Srrrs rNrzJzKet._represent_JyOps6#t##^"Xa^*;"Q$bQRd^V]^^rZc &|jdi|Srrrs rNrzJzKet._represent_JzOp"rrZNrrrZrNr8r8sGl\5G_/rZr8c0eZdZdZedZedZy)r9zEigenbra of Jz. See the JzKet for the usage of spin eigenstates. See Also ======== JzKet: Usage of spin states ctSrRr8r_s rNrzJzBra.dual_class2rrZctSrRrAr_s rNrzJzBra.coupled_class6rrZNrrrZrNr9r9&rrZr9ct|Dcgc]}|dzg }}g}g}|D][\}}}|j||j||dz ||dz ft||dz ||dz z} | || ddz <]||fScc}w)NrFr)rIrsorted) jcouplinglengthrn_list coupled_jn coupled_nn1n2j_newn_sorts rN_build_coupledr?s %f /1Aw /F /JI"' B% 6"q&>6"q&>:<rAvQ78 &vay1} ' j  0s BceZdZdZdZdZdZdZedZ edZ edZ ed Z e d Zd Zd Zd ZdZy)rz/Base class for coupled angular momentum states.ct||t|dk(rng}tdtD]6}|jd|t t|Dcgc]}| c}f8|jdt|fn.t|dk(r|d}nt dt|dzzt tttfs"t djjzt |tttfs"t d|jjztd|Ds t d tdz t|k(s%td tdz t|fztd |Ds td t|}t|}tDcgc] }t|c}t|D cgc].\}} }tt|t| t|0c}} }}td Drtdztd|Dr tdtfd|Dr tdtd|Dr tdt!|t\} } t} t#| D]\}\}} | t%|dz } | t%| dz }| |}t| j&r|t|j&rgt|j&rR| |z|krtd|dz| ||fzt)| |z |kDrtd|dz| ||fzt+| |zr || t%|| zdz <t|dkDr|dd|k7r tdt-j.||||Scc}wcc}wcc}} }w)NrrErFz5CoupledSpinState only takes 3 or 4 arguments, got: %sr1z'jn must be Tuple, list or tuple, got %sz.jcoupling must be Tuple, list or tuple, got %sc3RK|]}t|tttf!ywrR)rlisttupler.0terms rN z+CoupledSpinState.__new__..dsPd:dT5%$89Ps%'z6All elements of jcoupling must be list, tuple or Tuplez(jcoupling must have length of %d, got %dc38K|]}t|dk(yw)r1Nr)rrs rNrz+CoupledSpinState.__new__..js213q6Q;2z,All elements of jcoupling must have length 3c3^K|]%}|jsd|ztd|zk7'ywrENrTrJ)rjis rNrz+CoupledSpinState.__new__..ss'>Rqts1R4y >s--z;All elements of jn must be integer or half-integer, got: %sc3`K|]&\}}}|t|k7xs|t|k7(ywrR)rJ)rrrrqs rNrz+CoupledSpinState.__new__..us.K+2r1rSW}-c"g -Ks,.z%Indices in jcoupling must be integersc3~K|]4\}}}|dkxs%|dkxs|tkDxs|tkD6yw)rFNr)rrrrqrs rNrz+CoupledSpinState.__new__..wsA]KRQrAv?a?2B<?2B<?]s:=z?Indices must be between 1 and the number of coupled spin spacesc3fK|])\}}}|jsd|ztd|zk7+ywr r )rrqr s rNrz+CoupledSpinState.__new__..ys-MZaB qts1R4y Ms11zGAll coupled j values in coupling scheme must be integer or half-integerzQAll couplings must have j1+j2 >= j3, in coupling number %d got j1,j2,j3: %d,%d,%dzSAll couplings must have |j1+j2| <= j3, in coupling number %d got j1,j2,j3: %d,%d,%drz>Last j value coupled together must be the final j of the state)rrrIrr TypeErrorrrrrrrallrHranyrrminrTrrr#rf)rVrKrrrrrMr rrrrjvalsj1j2j3s ` rNrfzCoupledSpinState.__new__Ns!Q y>Q I1c"g& L  1aeAh.Gr!u.G)H"IK L   q#b'1o / ^q !! ISWZ[dWehiWijl l"tUE23ELL1123 3)dE5%9:L%//889: :PiPPHJ J2w{c)n,G!"gk3y>:;< <2 22KL L AJ AJ B/bgbk/ 1?HJJ/;B#7 $gbk+JL  >2> >Z]__` ` KK KDE E ]S\] ]^_ _ M9M Mfg g .y#b' B :R$Y/ )KAxBs2w{#Bs2w{#BABr{$$)>)>72;CXCX7R<$&GJKa%QSUWY[I\&]^^rBw<"$$&GJKa%QSUWY[I\&]^^b2g&&(E#b2g," # ) y>A )B-"2a"7]^ ^}}S!QI66q/H20Js O O$+3O) c  |j|j|j|jg}t|jdD]*\}}|j d||j|fz,t |jdd|jddD]P\}\}}|j ddjdt||zDd|j|Rdj|S) NrFrzj%d=%srzj(rsc32K|]}t|ywrRrjrrMs rNrz0CoupledSpinState._print_label..9AQ9z)=) rtrKrrrrziprrjoinr) r`rgr^rWrMr rrrs rN _print_labelzCoupledSpinState._print_labels')?@twwa0 EAr LL7>>"%%    4dnnSb6IJ LBR LL9R997>>";M  xxrZc|j|jg}t|jdD]Z\}}d|z}t |}t |dz}t |j |j|}|j|\t|jdd|jddD]t\}\} } djdt| | zD} t d| zdz}t |j |j|}|j|v|j||j|g|S) NrFrj%d=rrsc3>K|]}td|zdyw)r$rNrrs rNrz7CoupledSpinState._print_label_pretty..sO!uqy1"5OrK)rKrrrrrrxrtrr rrr!r_print_sequence_prettyr) r`rgr^rWrMr symbitemrrrrs rN_print_label_prettyz$CoupledSpinState._print_label_prettys3 twwa0 EAr19D &DdSj)Dtzz'..*<=>D LL      4dnnSb6IJ LBROvb2gOOAcAgm,Dtzz'..*<=>D LL    +t** 4((' 48  rZc 2|j|jg||j|jg|g}t|jdD],\}}|j d||j|g|fz.t |jdd|jddD]T\}\}}djdt||zD} |j d| d|j|g|V|jj|S) NrFrz j_{%d}=%srrsc32K|]}t|ywrRrrs rNrz6CoupledSpinState._print_label_latex..rrzj_{z}=) rtrKrrrrr rrr!rr) r`rgr^rWrMr rrrrs rN_print_label_latexz#CoupledSpinState._print_label_latexs  GNN466 )D ) GNN466 )D ) twwa0 HEAr LL>7>>"+Dt+D'EE G H 4dnnSb6IJ HLBR9R99A LL>7>>"+Dt+DE G H$$))%00rZc |jdSrr5r_s rNrzCoupledSpinState.jnr7rZc |jdSrmr5r_s rNrzCoupledSpinState.couplingr7rZcft|jdt|jddS)Nr1rErFrrWrr_s rNrzCoupledSpinState.coupled_jn)djjmSA-?@CCrZcft|jdt|jddS)Nr1rErr2r_s rNrzCoupledSpinState.coupled_nr3rZct|d}|jr9ttt d|zdzddDcgc] }t |c}St d|zdzScc}w)NrErFr)rrTr'rIrJr&)rVrWrKrs rNrXz$CoupledSpinState._eval_hilbert_spacesd qN ;;(U3qQRsUVwrs rNrz$CoupledSpinState._eval_rewrite_as_Jyr=rZct|tr|jttfi|S|jtt fi|SrR)rr!rr0rAr@rs rNrz$CoupledSpinState._eval_rewrite_as_Jzr=rZN)rrrrrfr"r+r.rrrrrrrXr;rrrrrZrNrrKs9@7D  " 1DDDD ) )"@ @ @rZrcHeZdZdZedZedZdZdZdZ dZ y) r<zCoupled eigenket of Jx. See JzKetCoupled for the usage of coupled spin eigenstates. See Also ======== JzKetCoupled: Usage of coupled spin states ctSrRrr_s rNrzJxKetCoupled.dual_classrrZctSrRrr_s rNr8zJxKetCoupled.uncoupled_classrrZc &|jdi|Srrrs rNrz%JxKetCoupled._represent_default_basis rrZc &|jdi|Srr;rs rNrzJxKetCoupled._represent_JxOp+t++6g66rZc L|jddttddzi|Srr;r r rs rNrzJxKetCoupled._represent_JyOps(+t++O"Xa^2COwOOrZc 8|jddtdz i|Srr;r rs rNrzJxKetCoupled._represent_JzOps!+t++AAAAArZN rrrrrrr8rrrrrrZrNr<r<sE 57PBrZr<c0eZdZdZedZedZy)r=zCoupled eigenbra of Jx. See JzKetCoupled for the usage of coupled spin eigenstates. See Also ======== JzKetCoupled: Usage of coupled spin states ctSrRrr_s rNrzJxBraCoupled.dual_class$rrZctSrRrr_s rNr8zJxBraCoupled.uncoupled_class(rrZNrrrrrrr8rrZrNr=r=/ rZr=cHeZdZdZedZedZdZdZdZ dZ y) r>zCoupled eigenket of Jy. See JzKetCoupled for the usage of coupled spin eigenstates. See Also ======== JzKetCoupled: Usage of coupled spin states ctSrRrr_s rNrzJyKetCoupled.dual_class9rrZctSrRrr_s rNr8zJyKetCoupled.uncoupled_class=rrZc &|jdi|Srrrs rNrz%JyKetCoupled._represent_default_basisArrZc 8|jddtdz i|SrrJrs rNrzJyKetCoupled._represent_JxOpDs!+t++B"Q$B'BBrZc &|jdi|SrrErs rNrzJyKetCoupled._represent_JyOpGrFrZc n|jdttddzt dz tdz d|SrrHrs rNrzJyKetCoupled._represent_JzOpJs:+t++g"Xa^2C2#a%WYZ[W[g_fggrZNrKrrZrNr>r>-sE 5C7hrZr>c0eZdZdZedZedZy)r?zCoupled eigenbra of Jy. See JzKetCoupled for the usage of coupled spin eigenstates. See Also ======== JzKetCoupled: Usage of coupled spin states ctSrRrr_s rNrzJyBraCoupled.dual_classZrrZctSrRrr_s rNr8zJyBraCoupled.uncoupled_class^rrZNrOrrZrNr?r?NrPrZr?cHeZdZdZedZedZdZdZdZ dZ y) r@aCoupled eigenket of Jz Spin state that is an eigenket of Jz which represents the coupling of separate spin spaces. The arguments for creating instances of JzKetCoupled are ``j``, ``m``, ``jn`` and an optional ``jcoupling`` argument. The ``j`` and ``m`` options are the total angular momentum quantum numbers, as used for normal states (e.g. JzKet). The other required parameter in ``jn``, which is a tuple defining the `j_n` angular momentum quantum numbers of the product spaces. So for example, if a state represented the coupling of the product basis state `\left|j_1,m_1\right\rangle\times\left|j_2,m_2\right\rangle`, the ``jn`` for this state would be ``(j1,j2)``. The final option is ``jcoupling``, which is used to define how the spaces specified by ``jn`` are coupled, which includes both the order these spaces are coupled together and the quantum numbers that arise from these couplings. The ``jcoupling`` parameter itself is a list of lists, such that each of the sublists defines a single coupling between the spin spaces. If there are N coupled angular momentum spaces, that is ``jn`` has N elements, then there must be N-1 sublists. Each of these sublists making up the ``jcoupling`` parameter have length 3. The first two elements are the indices of the product spaces that are considered to be coupled together. For example, if we want to couple `j_1` and `j_4`, the indices would be 1 and 4. If a state has already been coupled, it is referenced by the smallest index that is coupled, so if `j_2` and `j_4` has already been coupled to some `j_{24}`, then this value can be coupled by referencing it with index 2. The final element of the sublist is the quantum number of the coupled state. So putting everything together, into a valid sublist for ``jcoupling``, if `j_1` and `j_2` are coupled to an angular momentum space with quantum number `j_{12}` with the value ``j12``, the sublist would be ``(1,2,j12)``, N-1 of these sublists are used in the list for ``jcoupling``. Note the ``jcoupling`` parameter is optional, if it is not specified, the default coupling is taken. This default value is to coupled the spaces in order and take the quantum number of the coupling to be the maximum value. For example, if the spin spaces are `j_1`, `j_2`, `j_3`, `j_4`, then the default coupling couples `j_1` and `j_2` to `j_{12}=j_1+j_2`, then, `j_{12}` and `j_3` are coupled to `j_{123}=j_{12}+j_3`, and finally `j_{123}` and `j_4` to `j=j_{123}+j_4`. The jcoupling value that would correspond to this is: ``((1,2,j1+j2),(1,3,j1+j2+j3))`` Parameters ========== args : tuple The arguments that must be passed are ``j``, ``m``, ``jn``, and ``jcoupling``. The ``j`` value is the total angular momentum. The ``m`` value is the eigenvalue of the Jz spin operator. The ``jn`` list are the j values of argular momentum spaces coupled together. The ``jcoupling`` parameter is an optional parameter defining how the spaces are coupled together. See the above description for how these coupling parameters are defined. Examples ======== Defining simple spin states, both numerical and symbolic: >>> from sympy.physics.quantum.spin import JzKetCoupled >>> from sympy import symbols >>> JzKetCoupled(1, 0, (1, 1)) |1,0,j1=1,j2=1> >>> j, m, j1, j2 = symbols('j m j1 j2') >>> JzKetCoupled(j, m, (j1, j2)) |j,m,j1=j1,j2=j2> Defining coupled spin states for more than 2 coupled spaces with various coupling parameters: >>> JzKetCoupled(2, 1, (1, 1, 1)) |2,1,j1=1,j2=1,j3=1,j(1,2)=2> >>> JzKetCoupled(2, 1, (1, 1, 1), ((1,2,2),(1,3,2)) ) |2,1,j1=1,j2=1,j3=1,j(1,2)=2> >>> JzKetCoupled(2, 1, (1, 1, 1), ((2,3,1),(1,2,2)) ) |2,1,j1=1,j2=1,j3=1,j(2,3)=1> Rewriting the JzKetCoupled in terms of eigenkets of the Jx operator: Note: that the resulting eigenstates are JxKetCoupled >>> JzKetCoupled(1,1,(1,1)).rewrite("Jx") |1,-1,j1=1,j2=1>/2 - sqrt(2)*|1,0,j1=1,j2=1>/2 + |1,1,j1=1,j2=1>/2 The rewrite method can be used to convert a coupled state to an uncoupled state. This is done by passing coupled=False to the rewrite function: >>> JzKetCoupled(1, 0, (1, 1)).rewrite('Jz', coupled=False) -sqrt(2)*|1,-1>x|1,1>/2 + sqrt(2)*|1,1>x|1,-1>/2 Get the vector representation of a state in terms of the basis elements of the Jx operator: >>> from sympy.physics.quantum.represent import represent >>> from sympy.physics.quantum.spin import Jx >>> from sympy import S >>> represent(JzKetCoupled(1,-1,(S(1)/2,S(1)/2)), basis=Jx) Matrix([ [ 0], [ 1/2], [sqrt(2)/2], [ 1/2]]) See Also ======== JzKet: Normal spin eigenstates uncouple: Uncoupling of coupling spin states couple: Coupling of uncoupled spin states ctSrRrr_s rNrzJzKetCoupled.dual_classrrZctSrRrr_s rNr8zJzKetCoupled.uncoupled_classrrZc &|jdi|Srrrs rNrz%JzKetCoupled._represent_default_basisrrZc L|jddttddzi|SrrHrs rNrzJzKetCoupled._represent_JxOps(+t++NHQN1BNgNNrZc l|jdttddztdz tdz d|SrrHrs rNrzJzKetCoupled._represent_JyOps8+t++f"Xa^2C"Q$VXYZVZf^effrZc &|jdi|SrrErs rNrzJzKetCoupled._represent_JzOprFrZNrKrrZrNr@r@csGrh5Og7rZr@c0eZdZdZedZedZy)rAzCoupled eigenbra of Jz. See the JzKetCoupled for the usage of coupled spin eigenstates. See Also ======== JzKetCoupled: Usage of coupled spin states ctSrRrr_s rNrzJzBraCoupled.dual_classrrZctSrRrr_s rNr8zJzBraCoupled.uncoupled_classrrZNrOrrZrNrArArPrZrANc|jt}|D]dtdjDs tfdjDs t d|j t |}f|S)a Couple a tensor product of spin states This function can be used to couple an uncoupled tensor product of spin states. All of the eigenstates to be coupled must be of the same class. It will return a linear combination of eigenstates that are subclasses of CoupledSpinState determined by Clebsch-Gordan angular momentum coupling coefficients. Parameters ========== expr : Expr An expression involving TensorProducts of spin states to be coupled. Each state must be a subclass of SpinState and they all must be the same class. jcoupling_list : list or tuple Elements of this list are sub-lists of length 2 specifying the order of the coupling of the spin spaces. The length of this must be N-1, where N is the number of states in the tensor product to be coupled. The elements of this sublist are the same as the first two elements of each sublist in the ``jcoupling`` parameter defined for JzKetCoupled. If this parameter is not specified, the default value is taken, which couples the first and second product basis spaces, then couples this new coupled space to the third product space, etc Examples ======== Couple a tensor product of numerical states for two spaces: >>> from sympy.physics.quantum.spin import JzKet, couple >>> from sympy.physics.quantum.tensorproduct import TensorProduct >>> couple(TensorProduct(JzKet(1,0), JzKet(1,1))) -sqrt(2)*|1,1,j1=1,j2=1>/2 + sqrt(2)*|2,1,j1=1,j2=1>/2 Numerical coupling of three spaces using the default coupling method, i.e. first and second spaces couple, then this couples to the third space: >>> couple(TensorProduct(JzKet(1,1), JzKet(1,1), JzKet(1,0))) sqrt(6)*|2,2,j1=1,j2=1,j3=1,j(1,2)=2>/3 + sqrt(3)*|3,2,j1=1,j2=1,j3=1,j(1,2)=2>/3 Perform this same coupling, but we define the coupling to first couple the first and third spaces: >>> couple(TensorProduct(JzKet(1,1), JzKet(1,1), JzKet(1,0)), ((1,3),(1,2)) ) sqrt(2)*|2,2,j1=1,j2=1,j3=1,j(1,3)=1>/2 - sqrt(6)*|2,2,j1=1,j2=1,j3=1,j(1,3)=2>/6 + sqrt(3)*|3,2,j1=1,j2=1,j3=1,j(1,3)=2>/3 Couple a tensor product of symbolic states: >>> from sympy import symbols >>> j1,m1,j2,m2 = symbols('j1 m1 j2 m2') >>> couple(TensorProduct(JzKet(j1,m1), JzKet(j2,m2))) Sum(CG(j1, m1, j2, m2, j, m1 + m2)*|j,m1 + m2,j1=j1,j2=j2>, (j, m1 + m2, j1 + j2)) c3<K|]}t|tywrR)rrrrs rNrzcouple..CsEE:eY/Esc3hK|])}|jjdju+yw)rN)rr^)rrrs rNrzcouple..Fs(Pu5??bggaj&:&::Ps/2z!All states must be the same basis)atomsr(rr^rr_couple)exprjcoupling_listrmrs @rNrBrBstt =!A:ERWWEE PPP?@ @yyWR89: KrZc  |j}|dj}|2g}tdt|D]}|j d|dzft|t|dz k(s%t dt|dz t|fzt d|Ds tdtd|Dr tdt d|DrLdgt|z}|D]8\}}||dz d k(s ||dz d k(r td d |t||dz <:|Dcgc]}|j} }|Dcgc]}|j} }g} tt|D cgc]} | dzg } } |D]Z}|\}}t| |dz }t| |dz }| j ||ft||z| t||dz <\t d |Dr| Dcgc]0}t|d|dzDcgc]}| |dz | |dz z c}2}}}g}t|d dzD]}t| }t!||zdz |}t|D]}t#|||}td t%||Dr.g}t| }g}t%| |D]\\}}}|t|dz }|t|dz }||z|z }||t||zdz <t|Dcgc] }| |dz  c}} t|Dcgc] }| |dz  c}}!| |!z}"|j || ||!||"f|j t|t||ftd |Dr td|Dr4td|DrHt'|D#cgc]}#t)|#j+c}#}$|"| |}|j |$|zt|Sg}g}g}%t| }| D]&\}}|t|dz }|t|dz }t||zt|k(r t-d}n3ddj/||zDcgc]}d|z c}z}&t-|&}||t||zdz <t|Dcgc] }| |dz  c}} t|Dcgc] }| |dz  c}}!| |!z}"|j || ||!||"f|j t|t||f|%j ||"||zf)t'|D#cgc] }#t)|# c}#}$|"| |}t1|$|zg|%Scc}wcc}wcc} wcc}wcc}}wcc}wcc}wcc}#wcc}wcc}wcc}wcc}#w)NrrFz(jcoupling_list must be length %d, got %dc38K|]}t|dk(ywr r)rrs rNrz_couple..ZsBxH "Br z"Each coupling must define 2 spacesc3,K|] \}}||k(ywrRrrrrs rNrz_couple..\s 1B28 1z'Spin spaces cannot couple to themselvesc3zK|]3\}}t|jxrt|j5ywrR)rrTrps rNrz_couple..^s0 Xvr272; :WR[%:%: : Xs9;rz8Spaces coupling j_n's are referenced by smallest n valuec3xK|]2}|jjxr|jj4ywrR)rKrTrrgs rNrz_couple..ws, Gu577   2!2!2 2 Gs8:c3,K|] \}}||kDywrRr)rrJrs rNrz_couple..sBAq1uBrqc3DK|]}t|d|dkDyw)rqroNrrs rNrz_couple..s!C$s47|d1g-Cs c3>K|]}|d|dz|dkywrrEroNrrs rNrz_couple..s&HttAwa(472Hr'c3PK|]}t|d|dz |dkD ywrxrvrs rNrz_couple..s+MDs47T!W,-Q7Ms$&rKz%s)r^rrIrrrrrHrryrKrrrrrr_confignum_to_difflistr rr)rMrr!r)'rrlstates coupled_evectrj_testrrrrmn coupling_listrMr j_couplingj1_nj2_nrdiff_maxrzdifftot config_num diff_listcg_terms coupled_jr coupling_diffrrrrm1m2m3rcoeff sum_termsj3_names' rNrjrjLs* WWF1I++-Mq#f+& 0A  ! !Aq1u: / 0 ~ #f+/ 1BVq#n*=>?@ @ B>B B=>> 1. 11BCC X XXS[$ )FBb1f~#vb1f~'; !\]]&(F3r2;? # ) & &e%'' &B &% &e%'' &B &M %c&k 2 41Aw 4F 4$8 BF26N#F26N#tTl,$*4$;$7B a!8 G GG:GI-5HQK!!=%'qRAYAE2')II(2,*+$ +DM"A4!8a<.C#Cj + 2:tQG BY)ABB H  36}i3P C/LT4-"CIM3B"CIM3Bb=0B8:Is4$;/!35D9qAE9;BD9qAE9;BbBOOb"b"b"%=?$$s4y#d)R&@B CC(CCHxHHMHMMXFTD  0FH%b"b)< eEk*? + $ +JF|  H ' 0JD$CIM+BCIM+B4$;3v;.S\4$;(Ga(G HHW%02Is4$;'!+ -D1qAE13BD1qAE13BbB OOb"b"b"5 7   s4y#d)R8 :   b"b2g. / 0h7dD 79b"b)45;+++i ' & 5'I2 :9G )H21 8sT/VV 5 V;VV*V V'V#V(  V- V2 V7 V<Vc x|jt}|D]}|j|t|||}!|S)a Uncouple a coupled spin state Gives the uncoupled representation of a coupled spin state. Arguments must be either a spin state that is a subclass of CoupledSpinState or a spin state that is a subclass of SpinState and an array giving the j values of the spaces that are to be coupled Parameters ========== expr : Expr The expression containing states that are to be coupled. If the states are a subclass of SpinState, the ``jn`` and ``jcoupling`` parameters must be defined. If the states are a subclass of CoupledSpinState, ``jn`` and ``jcoupling`` will be taken from the state. jn : list or tuple The list of the j-values that are coupled. If state is a CoupledSpinState, this parameter is ignored. This must be defined if state is not a subclass of CoupledSpinState. The syntax of this parameter is the same as the ``jn`` parameter of JzKetCoupled. jcoupling_list : list or tuple The list defining how the j-values are coupled together. If state is a CoupledSpinState, this parameter is ignored. This must be defined if state is not a subclass of CoupledSpinState. The syntax of this parameter is the same as the ``jcoupling`` parameter of JzKetCoupled. Examples ======== Uncouple a numerical state using a CoupledSpinState state: >>> from sympy.physics.quantum.spin import JzKetCoupled, uncouple >>> from sympy import S >>> uncouple(JzKetCoupled(1, 0, (S(1)/2, S(1)/2))) sqrt(2)*|1/2,-1/2>x|1/2,1/2>/2 + sqrt(2)*|1/2,1/2>x|1/2,-1/2>/2 Perform the same calculation using a SpinState state: >>> from sympy.physics.quantum.spin import JzKet >>> uncouple(JzKet(1, 0), (S(1)/2, S(1)/2)) sqrt(2)*|1/2,-1/2>x|1/2,1/2>/2 + sqrt(2)*|1/2,1/2>x|1/2,-1/2>/2 Uncouple a numerical state of three coupled spaces using a CoupledSpinState state: >>> uncouple(JzKetCoupled(1, 1, (1, 1, 1), ((1,3,1),(1,2,1)) )) |1,-1>x|1,1>x|1,1>/2 - |1,0>x|1,0>x|1,1>/2 + |1,1>x|1,0>x|1,0>/2 - |1,1>x|1,1>x|1,-1>/2 Perform the same calculation using a SpinState state: >>> uncouple(JzKet(1, 1), (1, 1, 1), ((1,3,1),(1,2,1)) ) |1,-1>x|1,1>x|1,1>/2 - |1,0>x|1,0>x|1,1>/2 + |1,1>x|1,0>x|1,0>/2 - |1,1>x|1,1>x|1,-1>/2 Uncouple a symbolic state using a CoupledSpinState state: >>> from sympy import symbols >>> j,m,j1,j2 = symbols('j m j1 j2') >>> uncouple(JzKetCoupled(j, m, (j1, j2))) Sum(CG(j1, m1, j2, m2, j, m)*|j1,m1>x|j2,m2>, (m1, -j1, j1), (m2, -j2, j2)) Perform the same calculation using a SpinState state >>> uncouple(JzKet(j, m), (j1, j2)) Sum(CG(j1, m1, j2, m2, j, m)*|j1,m1>x|j2,m2>, (m1, -j1, j1), (m2, -j2, j2)) )rirr _uncouple)rkrrlrmrs rNrCrCsBH 9AFyy %^ DEF KrZcF t|tr6|j}|j}|j}|j }n t|t r| tdt|ttfs td|Vg}tdt|D]<}|jdd|ztt|dzDcgc]}|| c}f>t|ttfs tdt|t|dz k(s tdt|t|\}}|j }n td|j"}|j$}g} t|} t'||D]H\} \} } | | ddz }| | ddz }| j| | ||| f| | t)| | zdz <J|j*rq|j*rd|Dcgc]}d|z }}t||z }t|}t-||zdz |}g}t|D]}t/|||}t1d t'||Dr.g}| D]p}|\}}}}} t|Dcgc]}||dz ||dz z c}}t|Dcgc]}||dz ||dz z c}}||z}|j||||| |frt3|Dcgc]}t5|j7c}} t9t'||D!cgc]\}}!||||!z c}!}}|j| |zt|Sd t|dzz}"t;|"}#| dd D cgc]a\}}}}} |t|Dcgc] }|#|dz  c}|t|Dcgc] }|#|dz  c}| t||zDcgc] }|#|dz  c}fc}} }}}}}|j| d fD cgc]D\}}}}} |t|Dcgc] }|#|dz  c}|t|Dcgc] }|#|dz  c}||fFc}} }}}}t3|D$cgc] }$t5|$ c}$}%t'||#Dcgc] \}}|| |f }&}}t9t'||#Dcgc]\}}|||c}}}t=|%|zg|&Scc}wcc}wcc}wcc}wcc}wcc}!}wcc}wcc}wcc}wcc}} }}}}wcc}wcc}wcc}} }}}}wcc}$wcc}}wcc}}w) Nz'Must specify j-values for coupled statezjn must be list or tuplerFz!jcoupling must be a list or tuplez?Must specify 2 fewer coupling terms than the number of j valueszstate must be a spin staterrEc3,K|] \}}||kDywrRr)rrJr{s rNrz_uncouple..9s>TQ1q5>rqzm1:%dr)rrrrrr8rrHrrrrIrrrrrrKrr rrTrr{rrr)rMr(rr)'rrrlrrrrMrKrrj_listrrrrrrrrrrrzrrrrrrrrrrrrJm_strrycg_termcg_coeffrs' rNrrs]%)* XXOO %% %%' E9 % :FG G"tUm,67 7  !N1c"g& F%%AsE!a%L$AqRU$ABCF F.4-8?@ @>"c"gk1^_ _ .~s2w G :455 A AM "XFJ 2& HR BqEAI  BqEAI r2r2r24#%s27|a & {{q{{"$&QQqS&&Bx!| Gtax!|T** 'J.z4CI>SH%=>>H) <)1&dBB4IaRAY1q5)99IK4IaRAY1q5)99IK"W"b"b"b!9;  < CBINN,CEE!/22y/ACtq!5AE?CFE MM%+ & ' F|3r7Q;'cppsqsbtwwH^dTVXZ\^T:uQU|:;T:uQU|:;TD[AuQU|ABDww @Mb@Q?RUU%;T4Rs4$@aU1q5\$@As4$@aU1q5\$@Aa!U VX>'W>?-0U^=TQq1"aj= =#b%. J$!Q%1+ JL8E>.I..}%B2'JIDC;:Aw%A$@U?= Js S- S 6S S S S 5S4 S% S4&S*5S4S/"S4;TS> T,T"; TT8TT %S4> Tcg}t|D]Y}|}||z dz }t||zdz |}||k\r"||z}|dz}t||zdz |}||k\r"|j||z [|Sr)rIrr)rrlist_lenrr prev_diff rem_spots rem_configss rNr{r{XsI 8_ + qL1$ ti/!3T: K' + %J AID"4)#3a#7>KK' T)* + rZrR)NN)grsympy.concrete.summationsrsympy.core.addrsympy.core.containersrsympy.core.exprrsympy.core.numbersrsympy.core.mulrr r r r sympy.core.singletonr sympy.core.symbolrrsympy.core.sympifyr(sympy.functions.combinatorial.factorialsrr&sympy.functions.elementary.exponentialr(sympy.functions.elementary.miscellaneousr(sympy.functions.elementary.trigonometricrrsympy.simplify.simplifyrsympy.matricesr sympy.printing.pretty.stringpictrr&sympy.printing.pretty.pretty_symbologyrsympy.physics.quantum.qexprrsympy.physics.quantum.operatorrrr sympy.physics.quantum.stater!r"r#(sympy.functions.special.tensor_functionsr$sympy.physics.quantum.constantsr%sympy.physics.quantum.hilbertr&r'#sympy.physics.quantum.tensorproductr(sympy.physics.quantum.cgr)sympy.physics.quantum.qapplyr*__all__r+rPrrrrr:r;r2r3r.r/r0r1r,r-rr4r5r6r7r8r9rrr<r=r>r?r@rArBrjrCrr{rrZrNrs=*)' )99".&J69?, C@-==77C0M='/ :6\7\7~)/j()/X&/z8&/R 8:( 8F <:(