
    \ht6                         S SK Jr  S SKJr  S SKJr  S SKJr  S SKJ	r	  S SK
Jr  S SKJr  S SKJr  S S	KJrJrJrJrJr  S
S/r " S S
\5      rS rS r " S S\5      rS rS rS rg)    )Expr)Symbol)sympify)Matrix)
prettyForm)Tuple)is_sequence)Dagger)numpy_ndarrayscipy_sparse_matrixto_sympyto_numpyto_scipy_sparseQuantumErrorQExprc                       \ rS rSrSrg)r       N)__name__
__module____qualname____firstlineno____static_attributes__r       S/var/www/auris/envauris/lib/python3.13/site-packages/sympy/physics/quantum/qexpr.pyr   r      s    r   c                 *    [        [        U 5      5      $ )af  Convert 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_sequencer       s    0 +C011r   c                 $   [        U 5      (       dB  [        U [        5      (       a  U $ [        U [        5      (       a  [	        U 5      $ [        U 5      $ [        U [        5      (       a  U $ U  Vs/ s H  n[        U5      PM     nn[        U6 $ s  snf )zL
Helper function for _qsympify_sequence
This function does the actual work.
)	r	   
isinstancer   strr   r   r   r   r   )r   itemresults      r   r   r   8   s     sc6""JS!!#;3< #u
 <??34(.3F?&> @s   .Bc                      \ rS rSrSrSrSrSrS r\	S 5       r
\S 5       r\S	 5       r\	S
 5       rS r\	S 5       r\	S 5       rS rS rS rS rS$S jrS rS rS rS rS rS rS rS rS rS r S r!S r"SS .S! jr#S" r$S#r%g)%r   U   z>A base class for all quantum object like operators and states.)hilbert_spaceF c                     U R                   " U40 UD6n[        U5      S:X  a*  U R                   " [        U R                  5       5      40 UD6n[        R
                  " U /UQ76 nU R                  U5      Ul        U$ )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_argslenr   default_argsr   __new___eval_hilbert_spacer(   )clsargskwargsinsts       r   r.   QExpr.__new__d   sn    : ~~d-f-t9>>>%(8(8(:";FvFD||C'$' 44T:r   c                 F    [         R                  " U /UQ70 UD6nXl        U$ )ad  Create 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.
)r   r.   r(   )r0   r(   r1   old_assumptionsobjs        r   _new_rawargsQExpr._new_rawargs   s'     ll3999)
r   c                     [        U R                  5      S:X  a(  U R                  [        U R	                  5       5      5      $ U R                  $ )zThe 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,   r1   r+   listr-   selfs    r   labelQExpr.label   s;     tyy>Q??4(9(9(;#<==99r   c                     g)NTr   r<   s    r   is_symbolicQExpr.is_symbolic   s    r   c                     [        S5      e)a  If 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!NotImplementedErrorr<   s    r   r-   QExpr.default_args   s     ""HIIr   c                     [         R                  " U 5      nUc  [         R                  " [        U 5      n[	        U[
        5      (       a  U R                  Ul        U$ N)r   _eval_adjointr.   r
   r"   r   r(   )r=   r7   s     r   rI   QExpr._eval_adjoint   sG      &;,,vt,Cc5!! $ 2 2C
r   c                     [        U5      $ )zbProcess the args passed to the __new__ method.

This simply runs args through _qsympify_sequence.
)r    )r0   r1   s     r   r+   QExpr._eval_args   s     "$''r   c                     SSK Jn  U" 5       $ )z:Compute the Hilbert space instance from the args.
        r   )HilbertSpace)sympy.physics.quantum.hilbertrN   )r0   r1   rN   s      r   r/   QExpr._eval_hilbert_space   s     	?~r   c                 ~    / nU H%  nUR                  UR                  " U/UQ76 5        M'     UR                  U5      $ rH   )append_printjoin)r=   r   sepprinterr1   r%   r$   s          r   _print_sequenceQExpr._print_sequence   s:    DMM'..556 xxr   c           	          UR                   " US   /UQ76 nUSS   HB  n[        UR                  U5      6 n[        UR                  UR                   " U/UQ76 5      6 nMD     U$ )Nr      )rS   r   right)r=   r   rU   rV   r1   pformr$   s          r   _print_sequence_prettyQExpr._print_sequence_pretty   sd    s1v--GDC 01EGNN4,G$,G HIE  r   c                     [        UR                  SUR                  5       -  5      6 n[        UR                  SUR                  5       -  5      6 n[        UR	                  U5      S[         R
                  06$ )N binding)r   leftwidthr[   belowPOW)r=   abtopbots        r   _print_subscript_prettyQExpr._print_subscript_pretty   sX    !&&QWWY/0!''#aggi-01399S>B*..BBr   c                 
    X-  $ rH   r   )r=   rf   rg   s      r   _print_superscript_prettyQExpr._print_superscript_pretty   s	    tr   c                 ,    [        UR                  X#S96 $ )N)rb   r[   )r   parens)r=   r\   rb   r[   s       r   _print_parens_prettyQExpr._print_parens_pretty   s    5<<T<?@@r   c                 T    U R                   " U R                  U R                  U/UQ76 $ )zPrints the label of the QExpr

This method prints self.label, using self._label_separator to separate
the elements. This method should not be overridden, instead, override
_print_contents to change printing behavior.
rW   r>   _label_separatorr=   rV   r1   s      r   _print_labelQExpr._print_label   s0     ##JJ--w
9=
 	
r   c                 @    U R                   " U R                  SU/UQ76 $ )N,)rW   r>   rv   s      r   _print_label_reprQExpr._print_label_repr   s(    ##JJW
'+
 	
r   c                 T    U R                   " U R                  U R                  U/UQ76 $ rH   )r]   r>   ru   rv   s      r   _print_label_prettyQExpr._print_label_pretty  s.    **JJ--w
9=
 	
r   c                 T    U R                   " U R                  U R                  U/UQ76 $ rH   rt   rv   s      r   _print_label_latexQExpr._print_label_latex
  s.    ##JJ--w
9=
 	
r   c                 (    U R                   " U/UQ76 $ )a+  Printer for contents of QExpr

Handles the printing of any unique identifying contents of a QExpr to
print as its contents, such as any variables or quantum numbers. The
default is to print the label, which is almost always the args. This
should not include printing of any brackets or parentheses.
)rw   rv   s      r   _print_contentsQExpr._print_contents  s       0400r   c                 (    U R                   " U/UQ76 $ rH   )r~   rv   s      r   _print_contents_prettyQExpr._print_contents_pretty  s    ''7$77r   c                 (    U R                   " U/UQ76 $ rH   )r   rv   s      r   _print_contents_latexQExpr._print_contents_latex  s    &&w666r   c                 (    U R                   " U/UQ76 $ )a  Default printing behavior of QExpr objects

Handles the default printing of a QExpr. To add other things to the
printing of the object, such as an operator name to operators or
brackets to states, the class should override the _print/_pretty/_latex
functions directly and make calls to _print_contents where appropriate.
This allows things like InnerProduct to easily control its printing the
printing of contents.
)r   rv   s      r   	_sympystrQExpr._sympystr#  s     ##G3d33r   c                 h    U R                   R                  nU R                  " U/UQ76 nU< SU< S3$ )N())	__class__r   r{   )r=   rV   r1   	classnamer>   s        r   
_sympyreprQExpr._sympyrepr/  s1    NN++	&&w66$e,,r   c                 ,    U R                   " U/UQ76 nU$ rH   )r   )r=   rV   r1   r\   s       r   _prettyQExpr._pretty4  s    ++G;d;r   c                 (    U R                   " U/UQ76 $ rH   )r   rv   s      r   _latexQExpr._latex8  s    ))'9D99r   c                     [        S5      e)Nz)This object does not have a default basisrD   )r=   optionss     r   _represent_default_basisQExpr._represent_default_basis?  s    !"MNNr   N)basisc                    Uc  U R                   " S0 UD6nO[        U SU40 UD6nUR                  SS5      nU R                  X45      nU$ )a  Represent this object in a given basis.

This method dispatches to the actual methods that perform the
representation. Subclases of QExpr should define various methods to
determine how the object will be represented in various bases. The
format of these methods is::

    def _represent_BasisName(self, basis, **options):

Thus to define how a quantum object is represented in the basis of
the operator Position, you would define::

    def _represent_Position(self, basis, **options):

Usually, basis object will be instances of Operator subclasses, but
there is a chance we will relax this in the future to accommodate other
types of basis sets that are not associated with an operator.

If the ``format`` option is given it can be ("sympy", "numpy",
"scipy.sparse"). This will ensure that any matrices that result from
representing the object are returned in the appropriate matrix format.

Parameters
==========

basis : Operator
    The Operator whose basis functions will be used as the basis for
    representation.
options : dict
    A dictionary of key/value pairs that give options and hints for
    the representation, such as the number of basis functions to
    be used.

_representformatsympyr   )r   dispatch_methodget_format_represent)r=   r   r   r%   r   s        r   r   QExpr._representB  sW    D =22=W=F$T<J'JF Xw/''7r   c                     US:X  a   [        U[        5      (       d  [        U5      $ US:X  a   [        U[        5      (       d  [	        U5      $ US:X  a   [        U[
        5      (       d  [        U5      $ U$ )Nr   numpyzscipy.sparse)r"   r   r   r   r   r   r   )r=   r%   r   s      r   r   QExpr._format_representn  sf    WZ%?%?F##wz&-'H'HF##~%v':;;"6**r   r   )r   r   )&r   r   r   r   __doc__	__slots__is_commutativeru   r.   classmethodr8   propertyr>   rA   r-   rI   r+   r/   rW   r]   rj   rm   rq   rw   r{   r~   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   U   s   H $IN #J  $     J J ( (   C
A
	





187

4-
:O #' *X	r   c                 B    U R                  5       u  p[        U5      nX4$ )z1Split into commutative and non-commutative parts.)args_cncr;   )ec_partnc_parts      r   split_commutative_partsr   z  s     jjlOF&\F?r   c                     / n/ nU R                    H<  n[        U[        5      (       d  UR                  U5        M+  UR                  U5        M>     X4$ )z=Split an expression into Expr and noncommutative QExpr parts.)r1   r"   r   rR   )r   	expr_part
qexpr_partargs       r   split_qexpr_partsr     sN    IJvv#u%%S!c"	 
   r   c                     U< SUR                   R                  < 3n[        X5      (       a  [        X5      nU" U40 UD6nUb  U$ [	        U R                   R                  < SU< SU< 35      e)z)Dispatch a method to the proper handlers._.z cannot handle: )r   r   hasattrgetattrrE   )r=   basenamer   r   method_namefr%   s          r   r   r     sh    %s}}'='=>Kt!!D&3"'"M
		 	 (C	1 r   N)sympy.core.exprr   sympy.core.symbolr   sympy.core.sympifyr   sympy.matrices.denser    sympy.printing.pretty.stringpictr   sympy.core.containersr   sympy.utilities.iterablesr	   sympy.physics.quantum.daggerr
   !sympy.physics.quantum.matrixutilsr   r   r   r   r   __all__	Exceptionr   r    r   r   r   r   r   r   r   r   <module>r      sj      $ & ' 7 ' 1 /  	9 	26:bD bJ		!r   