K it6ddlmZddlmZddlmZddlmZddlm Z ddl m Z ddl m Z ddlmZdd lmZmZmZmZmZd d gZGd d eZd ZdZGdd eZdZdZdZy))Expr)Symbol)sympify)Matrix) prettyForm)Tuple) is_sequence)Dagger) numpy_ndarrayscipy_sparse_matrixto_sympyto_numpyto_scipy_sparse QuantumErrorQExprc eZdZy)rN)__name__ __module__ __qualname__a/mnt/ssd/data/python-lab/Trading/venv/lib/python3.12/site-packages/sympy/physics/quantum/qexpr.pyrrsrc*tt|S)aConvert elements of a sequence to standard form. This is like sympify, but it performs special logic for arguments passed to QExpr. The following conversions are done: * (list, tuple, Tuple) => _qsympify_sequence each element and convert sequence to a Tuple. * basestring => Symbol * Matrix => Matrix * other => sympify Strings are passed to Symbol, not sympify to make sure that variables like 'pi' are kept as Symbols, not the SymPy built-in number subclasses. Examples ======== >>> from sympy.physics.quantum.qexpr import _qsympify_sequence >>> _qsympify_sequence((1,2,[3,4,[1,]])) (1, 2, (3, 4, (1,))) )tuple__qsympify_sequence_helper)seqs r_qsympify_sequencers0 +C0 11rct|s8t|tr|St|tr t |St |St|t r|S|Dcgc] }t|}}t|Scc}w)z^ Helper function for _qsympify_sequence This function does the actual work. ) r isinstancerstrrrrrr)ritemresults rrr8su s  c6 "J S !#; 3< #u @sA6ceZdZdZdZdZdZdZedZ e dZ e dZ ed Z d Zed Zed Zd ZdZdZdZd"dZdZdZdZdZdZdZdZdZdZdZdZ dZ!ddd Z"d!Z#y)#rz>A base class for all quantum object like operators and states.) hilbert_spaceFc|j|fi|}t|dk(r*|jt|jfi|}t j |g|}|j ||_|S)a:Construct a new quantum object. Parameters ========== args : tuple The list of numbers or parameters that uniquely specify the quantum object. For a state, this will be its symbol or its set of quantum numbers. Examples ======== >>> from sympy.physics.quantum.qexpr import QExpr >>> q = QExpr(0) >>> q 0 >>> q.label (0,) >>> q.hilbert_space H >>> q.args (0,) >>> q.is_commutative False r) _eval_argslenr default_argsr__new___eval_hilbert_spacer$)clsargskwargsinsts rr*z QExpr.__new__dsr:s~~d-f- t9>!3>>%(8(8(:";FvFD||C'$' 44T: rcFtj|g|i|}||_|S)aCreate new instance of this class with hilbert_space and args. This is used to bypass the more complex logic in the ``__new__`` method in cases where you already have the exact ``hilbert_space`` and ``args``. This should be used when you are positive these arguments are valid, in their final, proper form and want to optimize the creation of the object. )rr*r$)r,r$r-old_assumptionsobjs r _new_rawargszQExpr._new_rawargss)ll3999) rct|jdk(r(|jt|j S|jS)aThe label is the unique set of identifiers for the object. Usually, this will include all of the information about the state *except* the time (in the case of time-dependent objects). This must be a tuple, rather than a Tuple. r)r(r-r'listr)selfs rlabelz QExpr.labels; tyy>Q ??4(9(9(;#<= =99 rcy)NTrr6s r is_symboliczQExpr.is_symbolicsrctd)a6If no arguments are specified, then this will return a default set of arguments to be run through the constructor. NOTE: Any classes that override this MUST return a tuple of arguments. Should be overridden by subclasses to specify the default arguments for kets and operators z$No default arguments for this class!NotImplementedErrorr6s rr)zQExpr.default_argss""HIIrctj|}|tjt|}t |t r|j |_|SN)r _eval_adjointr*r rrr$)r7r2s rr@zQExpr._eval_adjointsD  & ;,,vt,C c5 ! $ 2 2C  rct|S)zrProcess the args passed to the __new__ method. This simply runs args through _qsympify_sequence. )r)r,r-s rr'zQExpr._eval_argss "$''rcddlm}|S)z:Compute the Hilbert space instance from the args. r) HilbertSpace)sympy.physics.quantum.hilbertrC)r,r-rCs rr+zQExpr._eval_hilbert_spaces ?~rczg}|D]$}|j|j|g|&|j|Sr?)append_printjoin)r7rsepprinterr-r"r!s r_print_sequencezQExpr._print_sequencesA 7D MM.'..55 6 7xxrc |j|dg|}|ddD]A}t|j|}t|j|j|g|}C|S)Nr)rGrright)r7rrIrJr-pformr!s r_print_sequence_prettyzQExpr._print_sequence_prettysos1v--G JD C 01E NGNN4,G$,G HIE J rct|jd|jz}t|jd|jz}t|j |dtj iS)N binding)rleftwidthrNbelowPOW)r7abtopbots r_print_subscript_prettyzQExpr._print_subscript_prettysX!&&QWWY/0!''#aggi-01399S>B*..BBrc ||zSr?r)r7rXrYs r_print_superscript_prettyzQExpr._print_superscript_prettys !t rc4t|j||S)N)rTrN)rparens)r7rOrTrNs r_print_parens_prettyzQExpr._print_parens_prettys5<rsj $&'7'1/    9 26:bDbJ  ! r