
    g[%                     T   d Z ddlmZmZmZmZmZmZmZ ddl	m
Z
 ddlmZmZmZ ddlmZmZmZmZmZmZmZ ddgZe eeef          e eeef          e eeef          ee
e eeeef          eeeeiZd e                                D             Zd	 Zd
 Zd Zd Zd Z d Z!dS )a   A module for mapping operators to their corresponding eigenstates
and vice versa

It contains a global dictionary with eigenstate-operator pairings.
If a new state-operator pair is created, this dictionary should be
updated as well.

It also contains functions operators_to_state and state_to_operators
for mapping between the two. These can handle both classes and
instances of operators and states. See the individual function
descriptions for details.

TODO List:
- Update the dictionary with a complete list of state-operator pairs
    )XOpYOpZOpXKetPxOpPxKetPositionKet3D)Operator)	StateBaseBraBaseKet)JxOpJyOpJzOpJ2OpJxKetJyKetJzKetoperators_to_statestate_to_operatorsc                     i | ]\  }}||	S  r   ).0kvs      ]/var/www/html/ai-engine/env/lib/python3.11/site-packages/sympy/physics/quantum/operatorset.py
<dictcomp>r   ,   s    555tq!a555    c                    t          | t          t          f          s$t          | t                    st	          d          t          | t                    r| D ];}t          |t                    s$t          |t                    st	          d          <t          |           }|t          v rS	 d |D             }t          t          |         t          |          fi |}n# t          $ r t          |         }Y nw xY w|S d |D             }t          |          }|t          v rt          t          |         |fi |}nd}|S | t          v rD	  |             }t          t          |          |fi |}n# t          $ r t          |          }Y nw xY w|S t          |           t          v r&t          t          t          |                    | fi |S dS )a.   Returns the eigenstate of the given operator or set of operators

    A global function for mapping operator classes to their associated
    states. It takes either an Operator or a set of operators and
    returns the state associated with these.

    This function can handle both instances of a given operator or
    just the class itself (i.e. both XOp() and XOp)

    There are multiple use cases to consider:

    1) A class or set of classes is passed: First, we try to
    instantiate default instances for these operators. If this fails,
    then the class is simply returned. If we succeed in instantiating
    default instances, then we try to call state._operators_to_state
    on the operator instances. If this fails, the class is returned.
    Otherwise, the instance returned by _operators_to_state is returned.

    2) An instance or set of instances is passed: In this case,
    state._operators_to_state is called on the instances passed. If
    this fails, a state class is returned. If the method returns an
    instance, that instance is returned.

    In both cases, if the operator class or set does not exist in the
    state_mapping dictionary, None is returned.

    Parameters
    ==========

    arg: Operator or set
         The class or instance of the operator or set of operators
         to be mapped to a state

    Examples
    ========

    >>> from sympy.physics.quantum.cartesian import XOp, PxOp
    >>> from sympy.physics.quantum.operatorset import operators_to_state
    >>> from sympy.physics.quantum.operator import Operator
    >>> operators_to_state(XOp)
    |x>
    >>> operators_to_state(XOp())
    |x>
    >>> operators_to_state(PxOp)
    |px>
    >>> operators_to_state(PxOp())
    |px>
    >>> operators_to_state(Operator)
    |psi>
    >>> operators_to_state(Operator())
    |psi>
    z%Argument is not an Operator or a set!zSet is not all Operators!c                 "    g | ]} |            S r   r   )r   ops     r   
<listcomp>z&operators_to_state.<locals>.<listcomp>t   s    333333r   c                 ,    g | ]}t          |          S r   )type)r   os     r   r"   z&operators_to_state.<locals>.<listcomp>{   s    (((q477(((r   N)	
isinstancer
   set
issubclassNotImplementedError	frozenset
op_mapping
_get_stater$   )		operatorsoptionssopsop_instancesrettmpclassesop_instances	            r   r   r   /   s   l y8S/22 KjH6U6U K!"IJJJ)S!! ( 	G 	GAq(++ G H--G)*EFFF	""*&33s333 C#l2C2COOwOO& & & & o& J((C(((CnnG*$$ G!4cEEWEEJ
"",'ikk I!6OOwOO& , , , +, J)__
**ji99PPPPP4s$   -2C   C:9C:#E/ /F	F	c           	      0   t          | t                    s$t          | t                    st          d          | t          v r]t          |           }	 t          |t          t          |                    fi |}n# t          t          f$ r t          |          }Y nmw xY wt          |           t          v r5t          | t          t          t          |                              fi |}nt          | t                    rV|                                 t          v r;t          | t          t          |                                                              }nt          | t                    r|                                 t          v rt          |           }	 t          |t          t          |                                                              }n8# t          t          f$ r" t          |                                          }Y nw xY wd}t          |          S )a`   Returns the operator or set of operators corresponding to the
    given eigenstate

    A global function for mapping state classes to their associated
    operators or sets of operators. It takes either a state class
    or instance.

    This function can handle both instances of a given state or just
    the class itself (i.e. both XKet() and XKet)

    There are multiple use cases to consider:

    1) A state class is passed: In this case, we first try
    instantiating a default instance of the class. If this succeeds,
    then we try to call state._state_to_operators on that instance.
    If the creation of the default instance or if the calling of
    _state_to_operators fails, then either an operator class or set of
    operator classes is returned. Otherwise, the appropriate
    operator instances are returned.

    2) A state instance is returned: Here, state._state_to_operators
    is called for the instance. If this fails, then a class or set of
    operator classes is returned. Otherwise, the instances are returned.

    In either case, if the state's class does not exist in
    state_mapping, None is returned.

    Parameters
    ==========

    arg: StateBase class or instance (or subclasses)
         The class or instance of the state to be mapped to an
         operator or set of operators

    Examples
    ========

    >>> from sympy.physics.quantum.cartesian import XKet, PxKet, XBra, PxBra
    >>> from sympy.physics.quantum.operatorset import state_to_operators
    >>> from sympy.physics.quantum.state import Ket, Bra
    >>> state_to_operators(XKet)
    X
    >>> state_to_operators(XKet())
    X
    >>> state_to_operators(PxKet)
    Px
    >>> state_to_operators(PxKet())
    Px
    >>> state_to_operators(PxBra)
    Px
    >>> state_to_operators(XBra)
    X
    >>> state_to_operators(Ket)
    O
    >>> state_to_operators(Bra)
    O
    zArgument is not a state!N)r&   r   r(   r)   state_mapping_make_default_get_ops	_make_set	TypeErrorr$   r   
dual_class)stater.   
state_instr2   s       r   r   r      s   v ui(( >Jui,H,H >!"<==="5))
	':$]5%9::G G>EG GCC#Y/ 	' 	' 	'&CCC	'	e	%	%u tE{{!;<<I I@GI I	E7	#	# (8(8(:(:m(K(Ku u/?/?/A/A!BCCE E	E7	#	# (8(8(:(:m(K(K"5))
	4:$]53C3C3E3E%FGGI ICC#Y/ 	4 	4 	4 0 0 2 23CCC	4 S>>s$   &A; ;BB:G 0HHc                 B    	  |             }n# t           $ r | }Y nw xY w|S N)r;   )exprr2   s     r   r8   r8      s?    dff    Js   
 c                 d    	  | j         |fi |}n# t          $ r t          |           }Y nw xY w|S r@   )_operators_to_stater)   r8   )state_classr0   r.   r2   s       r   r,   r,      sV    )-k-c==W== ) ) )K(() Js    --c                 <   	  | j         |fi |}n[# t          $ rN t          |t          t          t
          f          rt	          d |D                       }nt          |          }Y nw xY wt          |t                    rt          |          dk    r|d         S |S )Nc              3   4   K   | ]}t          |          V  d S r@   )r8   )r   xs     r   	<genexpr>z_get_ops.<locals>.<genexpr>	  s*      ==Qa((======r      r   )_state_to_operatorsr)   r&   r'   tupler*   r8   len)r>   
op_classesr.   r2   s       r   r9   r9     s    ,,j,ZCC7CC , , ,j3y"9:: 	,==*=====CC
++C	, #s CA1vJs    AA)(A)c                 h    t          | t          t          t          f          rt	          |           S | S r@   )r&   rK   listr*   r'   )r0   s    r   r:   r:     s+    #tY/00 3xx
r   N)"__doc__sympy.physics.quantum.cartesianr   r   r   r   r   r   r	   sympy.physics.quantum.operatorr
   sympy.physics.quantum.stater   r   r   sympy.physics.quantum.spinr   r   r   r   r   r   r   __all__r*   r7   itemsr+   r   r   r8   r,   r9   r:   r   r   r   <module>rW      s    < < < < < < < < < < < < < < < < < < 3 3 3 3 3 3 ? ? ? ? ? ? ? ? ? ?/ / / / / / / / / / / / / / / / / /  D$<00D$<00D$<00xCc?!;!; 65}2244555
a a aHU U Up	 	 	    "    r   