K iQdZddlmZmZddlmZddlmZddlm Z ddl m Z ddl m Z ddlmZmZmZdd lmZdd lmZmZdd lmZdd lmZdd lmZGdde ZGddeZGddeZGddeZ GddeZ!GddeZ"Gdde"eZ#Gdde"eZ$edZ%edZ&e!dZ'e d Z(ed!Z)ed"Z*y#)$z&Simple Harmonic Oscillator 1-Dimension)IInteger)S)Symbol)sqrt)hbar)Operator)BraKetState)QExpr)XPx)KroneckerDelta) ComplexSpace) matrix_zerosc0eZdZdZedZedZy)SHOOpz_A base class for the SHO Operators. We are limiting the number of arguments to be 1. cbtj|}t|dk(r|Std)NzToo many arguments)r _eval_argslen ValueError)clsargss a/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/physics/quantum/sho1d.pyrzSHOOp._eval_argss.% t9>K12 2c4ttjSNrrInfinityrlabels r_eval_hilbert_spacezSHOOp._eval_hilbert_space!AJJ''rN)__name__ __module__ __qualname____doc__ classmethodrr$rrrrs/ 33((rrcReZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z d Zy ) RaisingOpaThe Raising Operator or a^dagger. When a^dagger acts on a state it raises the state up by one. Taking the adjoint of a^dagger returns 'a', the Lowering Operator. a^dagger can be rewritten in terms of position and momentum. We can represent a^dagger as a matrix, which will be its default basis. Parameters ========== args : tuple The list of numbers or parameters that uniquely specify the operator. Examples ======== Create a Raising Operator and rewrite it in terms of position and momentum, and show that taking its adjoint returns 'a': >>> from sympy.physics.quantum.sho1d import RaisingOp >>> from sympy.physics.quantum import Dagger >>> ad = RaisingOp('a') >>> ad.rewrite('xp').doit() sqrt(2)*(m*omega*X - I*Px)/(2*sqrt(hbar)*sqrt(m*omega)) >>> Dagger(ad) a Taking the commutator of a^dagger with other Operators: >>> from sympy.physics.quantum import Commutator >>> from sympy.physics.quantum.sho1d import RaisingOp, LoweringOp >>> from sympy.physics.quantum.sho1d import NumberOp >>> ad = RaisingOp('a') >>> a = LoweringOp('a') >>> N = NumberOp('N') >>> Commutator(ad, a).doit() -1 >>> Commutator(ad, N).doit() -RaisingOp(a) Apply a^dagger to a state: >>> from sympy.physics.quantum import qapply >>> from sympy.physics.quantum.sho1d import RaisingOp, SHOKet >>> ad = RaisingOp('a') >>> k = SHOKet('k') >>> qapply(ad*k) sqrt(k + 1)*|k + 1> Matrix Representation >>> from sympy.physics.quantum.sho1d import RaisingOp >>> from sympy.physics.quantum.represent import represent >>> ad = RaisingOp('a') >>> represent(ad, basis=N, ndim=4, format='sympy') Matrix([ [0, 0, 0, 0], [1, 0, 0, 0], [0, sqrt(2), 0, 0], [0, 0, sqrt(3), 0]]) ctjttdtzt zt zz tjtztzt t ztzzzSN) rOnerrrmomega NegativeOnerrrselfrkwargss r_eval_rewrite_as_xpzRaisingOp._eval_rewrite_as_xpjsLd71:d?1,U233 MM!OB 5 *, ,rc&t|jSr) LoweringOprr6s r _eval_adjointzRaisingOp._eval_adjointns499%%rc"tjSrrr4r6others r_eval_commutator_LoweringOpz%RaisingOp._eval_commutator_LoweringOpqs }}rc(tj|zSrr>r?s r_eval_commutator_NumberOpz#RaisingOp._eval_commutator_NumberOpts}}T!!rc j|jtjz}t|t |zSr)nrr1rSHOKetr6ketoptionstemps r_apply_operator_SHOKetz RaisingOp._apply_operator_SHOKetws&uuquu}Dz&,&&rc &|jdi|SNr_represent_NumberOpr6rIs r_represent_default_basisz"RaisingOp._represent_default_basis{'t''888rc tdNz*Position representation is not implementedNotImplementedErrorr6basisrIs r_represent_XOpzRaisingOp._represent_XOp~ ""NOOrc |jdd}|jdd}t||fi|}t|dz D]*}t|dz}|dk(r t |}|||dz|f<,|dk(r|j }|SNndimformatsympyr scipy.sparsegetrrangerfloattocsrr6rXrI ndim_infor_matrixivalues rrOzRaisingOp._represent_NumberOpsKK* Xg.i>g>y1}% %AQKE'e $F1q5!8   % ^ #\\^F rcz|j|jdg|}|jjd|dS)Nr())_printr __class__r&)r6printerrarg0s r_print_contentszRaisingOp._print_contentss4w~~diil2T2>>22D99rchddlm}|j|jdg|}||dz}|S)Nr) prettyFormu†) sympy.printing.pretty.stringpictruror)r6rqrrupforms r_print_contents_prettyz RaisingOp._print_contents_prettys6?tyy|3d3z,// rcH|j|jd}d|zS)Nrz %s^{\dagger})ror)r6rqrargs r_print_contents_latexzRaisingOp._print_contents_latexs#nnTYYq\*$$rN)r&r'r(r)r8r<rArCrKrQrYrOrsrxr{r+rrr-r-%sABH,&"'9P ": %rr-c@eZdZdZdZdZdZdZdZdZ dZ d Z y ) r:aThe Lowering Operator or 'a'. When 'a' acts on a state it lowers the state up by one. Taking the adjoint of 'a' returns a^dagger, the Raising Operator. 'a' can be rewritten in terms of position and momentum. We can represent 'a' as a matrix, which will be its default basis. Parameters ========== args : tuple The list of numbers or parameters that uniquely specify the operator. Examples ======== Create a Lowering Operator and rewrite it in terms of position and momentum, and show that taking its adjoint returns a^dagger: >>> from sympy.physics.quantum.sho1d import LoweringOp >>> from sympy.physics.quantum import Dagger >>> a = LoweringOp('a') >>> a.rewrite('xp').doit() sqrt(2)*(m*omega*X + I*Px)/(2*sqrt(hbar)*sqrt(m*omega)) >>> Dagger(a) RaisingOp(a) Taking the commutator of 'a' with other Operators: >>> from sympy.physics.quantum import Commutator >>> from sympy.physics.quantum.sho1d import LoweringOp, RaisingOp >>> from sympy.physics.quantum.sho1d import NumberOp >>> a = LoweringOp('a') >>> ad = RaisingOp('a') >>> N = NumberOp('N') >>> Commutator(a, ad).doit() 1 >>> Commutator(a, N).doit() a Apply 'a' to a state: >>> from sympy.physics.quantum import qapply >>> from sympy.physics.quantum.sho1d import LoweringOp, SHOKet >>> a = LoweringOp('a') >>> k = SHOKet('k') >>> qapply(a*k) sqrt(k)*|k - 1> Taking 'a' of the lowest state will return 0: >>> from sympy.physics.quantum import qapply >>> from sympy.physics.quantum.sho1d import LoweringOp, SHOKet >>> a = LoweringOp('a') >>> k = SHOKet(0) >>> qapply(a*k) 0 Matrix Representation >>> from sympy.physics.quantum.sho1d import LoweringOp >>> from sympy.physics.quantum.represent import represent >>> a = LoweringOp('a') >>> represent(a, basis=N, ndim=4, format='sympy') Matrix([ [0, 1, 0, 0], [0, 0, sqrt(2), 0], [0, 0, 0, sqrt(3)], [0, 0, 0, 0]]) ctjttdtzt zt zz ttzt t ztzzzSr/) rr1rrrr2r3rrrr5s rr8zLoweringOp._eval_rewrite_as_xpsCd71:d?1,U233 bD1U719  rc&t|jSr)r-rr;s rr<zLoweringOp._eval_adjoints$))$$rc"tjSr)rr1r?s r_eval_commutator_RaisingOpz%LoweringOp._eval_commutator_RaisingOps uu rc|Srr+r?s rrCz$LoweringOp._eval_commutator_NumberOps rc |jtdz }|jtjurtjSt |jt |zS)Nr)rErrZerorrFrGs rrKz!LoweringOp._apply_operator_SHOKetsCuuwqz! 55AFF?66M;vd|+ +rc &|jdi|SrMrNrPs rrQz#LoweringOp._represent_default_basisrRrc tdrTrUrWs rrYzLoweringOp._represent_XOp rZrc |jdd}|jdd}t||fi|}t|dz D]*}t|dz}|dk(r t |}||||dzf<,|dk(r|j }|Sr\rbrgs rrOzLoweringOp._represent_NumberOpsKK* Xw/i>g>y1}% $AQKE'e #F1QU7O  $ ^ #\\^F rN) r&r'r(r)r8r<rrCrKrQrYrOr+rrr:r:s2L\%,9P rr:cLeZdZdZdZdZdZdZdZdZ dZ d Z d Z d Z y ) NumberOpabThe Number Operator is simply a^dagger*a It is often useful to write a^dagger*a as simply the Number Operator because the Number Operator commutes with the Hamiltonian. And can be expressed using the Number Operator. Also the Number Operator can be applied to states. We can represent the Number Operator as a matrix, which will be its default basis. Parameters ========== args : tuple The list of numbers or parameters that uniquely specify the operator. Examples ======== Create a Number Operator and rewrite it in terms of the ladder operators, position and momentum operators, and Hamiltonian: >>> from sympy.physics.quantum.sho1d import NumberOp >>> N = NumberOp('N') >>> N.rewrite('a').doit() RaisingOp(a)*a >>> N.rewrite('xp').doit() -1/2 + (m**2*omega**2*X**2 + Px**2)/(2*hbar*m*omega) >>> N.rewrite('H').doit() -1/2 + H/(hbar*omega) Take the Commutator of the Number Operator with other Operators: >>> from sympy.physics.quantum import Commutator >>> from sympy.physics.quantum.sho1d import NumberOp, Hamiltonian >>> from sympy.physics.quantum.sho1d import RaisingOp, LoweringOp >>> N = NumberOp('N') >>> H = Hamiltonian('H') >>> ad = RaisingOp('a') >>> a = LoweringOp('a') >>> Commutator(N,H).doit() 0 >>> Commutator(N,ad).doit() RaisingOp(a) >>> Commutator(N,a).doit() -a Apply the Number Operator to a state: >>> from sympy.physics.quantum import qapply >>> from sympy.physics.quantum.sho1d import NumberOp, SHOKet >>> N = NumberOp('N') >>> k = SHOKet('k') >>> qapply(N*k) k*|k> Matrix Representation >>> from sympy.physics.quantum.sho1d import NumberOp >>> from sympy.physics.quantum.represent import represent >>> N = NumberOp('N') >>> represent(N, basis=N, ndim=4, format='sympy') Matrix([ [0, 0, 0, 0], [0, 1, 0, 0], [0, 0, 2, 0], [0, 0, 0, 3]]) cttzSr)adar5s r_eval_rewrite_as_azNumberOp._eval_rewrite_as_ajs !t rctjtdtztzt zz t dztt ztzdzzztjz Sr/) rr1rr2rr3rrHalfr5s rr8zNumberOp._eval_rewrite_as_xpmsSwqz!|D(./"a% eGAI;3VV$ $rcLtttzz tjz Sr)Hrr3rrr5s r_eval_rewrite_as_HzNumberOp._eval_rewrite_as_Hqs$u*~&&rc |j|zSr)rEr6rHrIs rrKzNumberOp._apply_operator_SHOKettsuuSyrc"tjSrrrr?s r_eval_commutator_Hamiltonianz%NumberOp._eval_commutator_Hamiltonianw vv rc|Srr+r?s rrz#NumberOp._eval_commutator_RaisingOpzs rc(tj|zSrr>r?s rrAz$NumberOp._eval_commutator_LoweringOp}s}}U""rc &|jdi|SrMrNrPs rrQz!NumberOp._represent_default_basisrRrc tdrTrUrWs rrYzNumberOp._represent_XOprZrc |jdd}|jdd}t||fi|}t|D]}|}|dk(r t|}||||f<|dk(r|j }|SNr]r^r_r`ra)rcrrdrerfrgs rrOzNumberOp._represent_NumberOpsKK* Xw/i>g>y! AE'e F1Q3K  ^ #\\^F rN)r&r'r(r)rr8rrKrrrArQrYrOr+rrrr!s<FP$'#9P rrc@eZdZdZdZdZdZdZdZdZ dZ d Z y ) Hamiltoniana.The Hamiltonian Operator. The Hamiltonian is used to solve the time-independent Schrodinger equation. The Hamiltonian can be expressed using the ladder operators, as well as by position and momentum. We can represent the Hamiltonian Operator as a matrix, which will be its default basis. Parameters ========== args : tuple The list of numbers or parameters that uniquely specify the operator. Examples ======== Create a Hamiltonian Operator and rewrite it in terms of the ladder operators, position and momentum, and the Number Operator: >>> from sympy.physics.quantum.sho1d import Hamiltonian >>> H = Hamiltonian('H') >>> H.rewrite('a').doit() hbar*omega*(1/2 + RaisingOp(a)*a) >>> H.rewrite('xp').doit() (m**2*omega**2*X**2 + Px**2)/(2*m) >>> H.rewrite('N').doit() hbar*omega*(1/2 + N) Take the Commutator of the Hamiltonian and the Number Operator: >>> from sympy.physics.quantum import Commutator >>> from sympy.physics.quantum.sho1d import Hamiltonian, NumberOp >>> H = Hamiltonian('H') >>> N = NumberOp('N') >>> Commutator(H,N).doit() 0 Apply the Hamiltonian Operator to a state: >>> from sympy.physics.quantum import qapply >>> from sympy.physics.quantum.sho1d import Hamiltonian, SHOKet >>> H = Hamiltonian('H') >>> k = SHOKet('k') >>> qapply(H*k) hbar*k*omega*|k> + hbar*omega*|k>/2 Matrix Representation >>> from sympy.physics.quantum.sho1d import Hamiltonian >>> from sympy.physics.quantum.represent import represent >>> H = Hamiltonian('H') >>> represent(H, basis=N, ndim=4, format='sympy') Matrix([ [hbar*omega/2, 0, 0, 0], [ 0, 3*hbar*omega/2, 0, 0], [ 0, 0, 5*hbar*omega/2, 0], [ 0, 0, 0, 7*hbar*omega/2]]) cZttzttztj zzSr)rr3rrrrr5s rrzHamiltonian._eval_rewrite_as_asEz2a4!&&=))rctjtdtzz tdztt zt zdzzzSr/)rr1rr2rr3rr5s rr8zHamiltonian._eval_rewrite_as_xps3wqz!|$r1u% A~'=>>rcLttzttjzzSr)rr3Nrrr5s r_eval_rewrite_as_NzHamiltonian._eval_rewrite_as_NsEz1qvv:&&rc ^ttz|jtjzz|zSr)rr3rErrrs rrKz"Hamiltonian._apply_operator_SHOKets"U CEEAFFN+S00rc"tjSrrr?s rrCz%Hamiltonian._eval_commutator_NumberOprrc &|jdi|SrMrNrPs rrQz$Hamiltonian._represent_default_basisrRrc tdrTrUrWs rrYzHamiltonian._represent_XOprZrc "|jdd}|jdd}t||fi|}t|D],}|tjz}|dk(r t |}||||f<.|dk(r|j }ttz|zSr) rcrrdrrrerfrr3rgs rrOzHamiltonian._represent_NumberOpsKK* Xw/i>g>y! AJE'e F1Q3K  ^ #\\^FEz&  rN) r&r'r(r)rr8rrKrCrQrYrOr+rrrrs1?B*?'19P !rrc0eZdZdZedZedZy)SHOStatezState class for SHO statesc4ttjSrr r"s rr$zSHOState._eval_hilbert_spacer%rc |jdS)Nr)rr;s rrEz SHOState.n syy|rN)r&r'r(r)r*r$propertyrEr+rrrrs+$((rrc2eZdZdZedZdZdZdZy)rFa1D eigenket. Inherits from SHOState and Ket. Parameters ========== args : tuple The list of numbers or parameters that uniquely specify the ket This is usually its quantum numbers or its symbol. Examples ======== Ket's know about their associated bra: >>> from sympy.physics.quantum.sho1d import SHOKet >>> k = SHOKet('k') >>> k.dual >> k.dual_class() Take the Inner Product with a bra: >>> from sympy.physics.quantum import InnerProduct >>> from sympy.physics.quantum.sho1d import SHOKet, SHOBra >>> k = SHOKet('k') >>> b = SHOBra('b') >>> InnerProduct(b,k).doit() KroneckerDelta(b, k) Vector representation of a numerical state ket: >>> from sympy.physics.quantum.sho1d import SHOKet, NumberOp >>> from sympy.physics.quantum.represent import represent >>> k = SHOKet(3) >>> N = NumberOp('N') >>> represent(k, basis=N, ndim=4) Matrix([ [0], [0], [0], [1]]) ctSr)SHOBrar;s r dual_classzSHOKet.dual_classC rc Ft|j|j}|Sr)rrE)r6brahintsresults r_eval_innerproduct_SHOBraz SHOKet._eval_innerproduct_SHOBraGs. rc &|jdi|SrMrNrPs rrQzSHOKet._represent_default_basisKrRrc |jdd}|jdd}d|d<t|dfi|}t|jtr|j|k\r t dS|d k(r,d |t |jd f<|j}|S|d k(rd |t |jd f<|Stj||jd f<|St d SNr]r^r_r`lilspmatrixrzN-Dimension too smallrag?rnumpyzNot Numerical State rcr isinstancerErrintrfrr1r6rXrIrhr_vectors rrOzSHOKet._represent_NumberOpNsKK* Xw/# i6g6 dffg &vv"!"9::'),s466{A~& M 7"),s466{A~&M%&EEtvvqy!M34 4rN) r&r'r(r)r*rrrQrOr+rrrFrFs+0d95rrFc,eZdZdZedZdZdZy)raKA time-independent Bra in SHO. Inherits from SHOState and Bra. Parameters ========== args : tuple The list of numbers or parameters that uniquely specify the ket This is usually its quantum numbers or its symbol. Examples ======== Bra's know about their associated ket: >>> from sympy.physics.quantum.sho1d import SHOBra >>> b = SHOBra('b') >>> b.dual |b> >>> b.dual_class() Vector representation of a numerical state bra: >>> from sympy.physics.quantum.sho1d import SHOBra, NumberOp >>> from sympy.physics.quantum.represent import represent >>> b = SHOBra(3) >>> N = NumberOp('N') >>> represent(b, basis=N, ndim=4) Matrix([[0, 0, 0, 1]]) ctSr)rFr;s rrzSHOBra.dual_classrrc &|jdi|SrMrNrPs rrQzSHOBra._represent_default_basisrRrc |jdd}|jdd}d|d<td|fi|}t|jtr|j|k\r t dS|d k(r,d |d t |jf<|j}|S|d k(rd |d t |jf<|Stj|d |jf<|St d Srrrs rrOzSHOBra._represent_NumberOpsKK* Xw/# a6g6 dffg &vv"!"9::'),q#dff+~& M 7"),q#dff+~&M%&EEq$&&y!M34 4rN)r&r'r(r)r*rrQrOr+rrrrbs&"H95rrrrrr3r2N)+r)sympy.core.numbersrrsympy.core.singletonrsympy.core.symbolr(sympy.functions.elementary.miscellaneousrsympy.physics.quantum.constantsrsympy.physics.quantum.operatorr sympy.physics.quantum.stater r r sympy.physics.quantum.qexprr sympy.physics.quantum.cartesianrr(sympy.functions.special.tensor_functionsrsympy.physics.quantum.hilbertr!sympy.physics.quantum.matrixutilsrrr-r:rrrrFrrrrrr3r2r+rrrs,+"$90377-1C6:(H(&~%~%@yyxuuupg!%g!V u O5XsO5d=5Xs=5@s^sO SMw 3Kr