+
    i%                         R t ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RI	H
t
 ^ RIHt ^ RIHtHt ^ RIHt ^ R	IHt ^ R
IHt ^ RIHt ^ RIHtHt ^ RIHtHtHtHt ^ RI H!t! R.t"R t#R t$R t%R t&R# )z}Logic for applying operators to states.

Todo:
* Sometimes the final result needs to be expanded, we should do this by hand.
)Sum)Add)
NumberKind)Mul)Pow)S)sympify_sympify)AntiCommutator)
Commutator)Dagger)InnerProduct)OuterProductOperator)StateKetBaseBraBaseWavefunction)TensorProductqapplyc                0    V P                  \        R 4      # )zETransform the inner products in an expression by calling ``.doit()``.c                  0    \        V !  P                  4       # N)r   doitargss   *|/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/sympy/physics/quantum/qapply.py<lambda>ip_doit_func.<locals>.<lambda>#   s    t1D1I1I1K    )replacer   es   &r   ip_doit_funcr#   !   s    99\#KLLr   c                0    V P                  \        R 4      # )z;Transform the sums in an expression by calling ``.doit()``.c                  0    \        V !  P                  4       # r   )r   r   r   s   *r   r   sum_doit_func.<locals>.<lambda>(   s    T
(9r   )r    r   r!   s   &r   sum_doit_funcr'   &   s    99S9::r   c           
        ^ RI Hp VP                  RR4      pVP                  RR4      pVP                  RR4      p\        V 4      p V P                  \
        8X  d   V'       d   \        V 4      # T # V P                  RRR7      p \        V \        4      '       d   V # \        V \        4      '       d9   ^ pV P                   F  pV\        V3/ VB ,          pK  	  VP                  4       # \        W4      '       d3   V P                   UU	u. uF  w  pp	\        V3/ VB V	3NK  	  p
pp	V! V
!  # \        V \        4      '       d.   \        V P                   Uu. uF  p\        V3/ VB NK  	  up!  # \        V \        4      '       dE   \        \        V P                  3/ VB .V P                   O5!  pV'       d   \#        V4      pV# TpV# \        V \$        4      '       d(   \        V P&                  3/ VB V P(                  ,          # \        V \*        4      '       d   V P-                  4       w  r\+        V!  p\+        V!  pV'       g   TpM=\        V\*        4      '       d   V\/        V3/ VB ,          pMV\        V3/ VB ,          pW`8X  d'   V'       d   \1        \/        \1        V 4      3/ VB 4      pV'       d   \        V4      MTpV'       d   \#        V4      pV# TpV# V # u up	pi u upi )a]  Apply operators to states in a quantum expression.

Parameters
==========

e : Expr
    The expression containing operators and states. This expression tree
    will be walked to find operators acting on states symbolically.
options : dict
    A dict of key/value pairs that determine how the operator actions
    are carried out.

    The following options are valid:

    * ``dagger``: try to apply Dagger operators to the left
      (default: False).
    * ``ip_doit``: call ``.doit()`` in inner products when they are
      encountered (default: True).
    * ``sum_doit``: call ``.doit()`` on sums when they are encountered
      (default: False). This is helpful for collapsing sums over Kronecker
      delta's that are created when calling ``qapply``.

Returns
=======

e : Expr
    The original expression, but with the operators applied to states.

Examples
========

    >>> from sympy.physics.quantum import qapply, Ket, Bra
    >>> b = Bra('b')
    >>> k = Ket('k')
    >>> A = k * b
    >>> A
    |k><b|
    >>> qapply(A * b.dual / (b * b.dual))
    |k>
    >>> qapply(k.dual * A / (k.dual * k))
    <b|
)DensitydaggerFsum_doitip_doitT)
commutatortensorproduct)sympy.physics.quantum.densityr)   getr	   kindr   r#   expand
isinstancer   r   r   r   r   r   functionlimitsr'   r   baseexpr   args_cnc
qapply_Mulr   )r"   optionsr)   r*   r+   r,   resultargstateprobnew_argstc_partnc_partc_mulnc_muls   &,              r   r   r   +   s   V 6[[5)F{{:u-Hkk)T*GA 	vv")|A0q0 	
D5A !W 
As		66CfS,G,,F }} 
A		ff&$:% E-W-t4$ 	 &!! 
A}	%	%QVVDVva373VDEE 
As		VAJJ2'2>QXX>*2v& 9? 
As		aff((!%%// 
As		**,VgF$$:f888F6&4G44F;6Jvay<G<=F)0f%f*2v& 9?
 M& Es   K&K,c           
      z   \        V P                  4      p\        P                  pR p\	        V4      ^8:  g   \        V \        4      '       g   V # VP                  4       pVP                  4       p\        V\        4      '       g   \        V4      P                  '       g2   \        V\        4      '       g   \        V4      P                  '       d   V # \        V\        4      '       d\   VP                  P                  '       d@   VP                  VP                  VP                  ^,
          ,          4       VP                  p\        V\         4      '       d(   VP                  VP"                  4       VP$                  p\        V\         4      '       d   VP$                  pVP"                  p\        V\&        \(        34      '       d   VP+                  4       p\        V\,        4      '       di   \/        V P0                  ! W'P                  ^ ,          V.,           !  V P0                  ! W'P                  ^,          V.,           !  ,           3/ VB V,          # \/        V P0                  ! V!  V,          V,          3/ VB V,          # \        V\2        4      '       Ed   \4        ;QJ d&    R VP                   4       F  '       d   K   RM	  RM! R VP                   4       4      '       Ed3   \        V\2        4      '       Ed   \4        ;QJ d&    R VP                   4       F  '       d   K   RM	  RM! R VP                   4       4      '       d   \	        VP                  4      \	        VP                  4      8X  d   \3        \7        \	        VP                  4      4       Uu. uF8  p\/        VP                  V,          VP                  V,          ,          3/ VB NK:  	  up!  P9                  RR7      p\;        V P0                  ! V!  3/ VB V,          V,          # \        V\<        4      '       Ed!   \        V\<        4      '       d   \?        VP@                  4      PC                  \?        VP@                  4      4      '       d   \E        R4      hVPF                  VPF                  ,           p	\=        \/        VPH                  VPH                  ,          3/ VB .V	O5!  p\;        V P0                  ! V!  V,          3/ VB # \=        \/        WePH                  ,          3/ VB .VPF                  O5!  p\;        V P0                  ! V!  V,          3/ VB # \        V\<        4      '       dT   \=        \/        VPH                  V,          3/ VB .VPF                  O5!  p\;        V P0                  ! V!  V,          3/ VB # \K        VRR 4      p
V
e    V
! V3/ VB pMR pVf   \K        VRR 4      pVe    V! V3/ VB pVf8   \        V\N        4      '       d"   \        V\P        4      '       d   \S        We4      p\        V\T        \V        \X        34      '       d   \[        V4      # VfB   \	        V4      ^ 8X  d   V # \;        V P0                  ! W&.,           !  3/ VB V,          V,          # \        V\R        4      '       d)   V\;        V P0                  ! V!  3/ VB ,          V,          # \/        V P0                  ! V!  V,          3/ VB V,          # u upi   \L         d    R p ELFi ; i  \L         d    R p EL;i ; i)	Nc              3   |   "   T F2  p\        V\        \        \        \        34      ;'       g    V^8H  x  K4  	  R# 5i   Nr3   r   r   r   r   .0r<   s   & r   	<genexpr>qapply_Mul.<locals>.<genexpr>   s7     -{rzknjxPSUX>Y.Z.f.f^aef^f.frz   +<<FTc              3   |   "   T F2  p\        V\        \        \        \        34      ;'       g    V^8H  x  K4  	  R# 5irG   rI   rJ   s   & r   rL   rM      s:       3Awps:cHeUXZ]C^3_3k3kcfjkck3kwrN   )r.   z4Duplicated dummy indices in separate sums in qapply._apply_operator_apply_from_right_to).listr   r   Onelenr3   r   popr   r   is_commutativer   r7   
is_Integerappendr6   r   ketbrar   r
   r   r   r   funcr   allranger2   r9   r   set	variablesintersection
ValueErrorr5   r4   getattrNotImplementedErrorr   r   r   intcomplexfloatr	   )r"   r:   r   extrar;   rhslhscommnr5   _apply_apply_rights   &,          r   r9   r9      s   <DEEEF 4yA~Z3//
((*C
((*C sL))gcl.I.I.IC..73<3N3N3N #s 2 2 2CHHsww{+,hh #|$$CGGgg#|$$gg #
N344xxzdC  1s 3351s 3356  	  !&&$-,S0<G<UBB #}%%##-{rurzrz-{###-{rurzrz-{*{*{sM**ss  3Awzww  3Asss  3Awzww  3A  0A  0AMS]*UZ[^_b_g_g[hUi jUiPQCHHQK(?!K7!KUi jkrr  BFr  G!&&$-373F:5@@ #sc33==!..s3==/ABB !WXXZZ#**,FS\\ 9EWEOOFaffdmF2>g>>LL 0<G<JszzJFaffdmF2>g>>#sVCLL,88F3::F!&&$-.:':: S+T2F	C+7+F ~s$:DA#%c5W5 ~c7##
3(@(@!#+F &3/00	t9>Haffte|5AA#EeKK	FL	)	)j:'::5@@affdmF*6g6u<<k !k0 # 	F	 ' s*   &>\	\ 5	\) \&%\&)\:9\:N)'__doc__sympy.concreter   sympy.core.addr   sympy.core.kindr   sympy.core.mulr   sympy.core.powerr   sympy.core.singletonr   sympy.core.sympifyr   r	   $sympy.physics.quantum.anticommutatorr
    sympy.physics.quantum.commutatorr   sympy.physics.quantum.daggerr   "sympy.physics.quantum.innerproductr   sympy.physics.quantum.operatorr   r   sympy.physics.quantum.stater   r   r   r   #sympy.physics.quantum.tensorproductr   __all__r#   r'   r   r9    r   r   <module>r      s]      &    " 0 ? 7 / ; A M M = M
;
tne=r   