o
    jg                     @   s   d Z ddlmZ ddlmZ ddlmZ ddlmZ ddl	m
Z
 ddlmZ ddlmZ dd	lmZmZmZmZmZ dd
lmZ g dZG dd deZG dd deZG dd deZG dd deZG dd deZdS )zBosonic quantum operators.    )Mul)Integer)S)	conjugate)exp)sqrt)Operator)HilbertSpace	FockSpaceKetBraIdentityOperator)KroneckerDelta)BosonOpBosonFockKetBosonFockBraBosonCoherentKetBosonCoherentBrac                   @   s|   e Zd ZdZedd Zedd Zedd Zdd	 Z	d
d Z
dd Zdd Zdd Zdd Zdd Zdd Zdd ZdS )r   a  A bosonic operator that satisfies [a, Dagger(a)] == 1.

    Parameters
    ==========

    name : str
        A string that labels the bosonic mode.

    annihilation : bool
        A bool that indicates if the bosonic operator is an annihilation (True,
        default value) or creation operator (False)

    Examples
    ========

    >>> from sympy.physics.quantum import Dagger, Commutator
    >>> from sympy.physics.quantum.boson import BosonOp
    >>> a = BosonOp("a")
    >>> Commutator(a, Dagger(a)).doit()
    1
    c                 C   
   | j d S Nr   )argsself r   S/var/www/html/zoom/venv/lib/python3.10/site-packages/sympy/physics/quantum/boson.pyname.      
zBosonOp.namec                 C   s   t | jd S N   )boolr   r   r   r   r   is_annihilation2   s   zBosonOp.is_annihilationc                 C   s   dS )N)aTr   r   r   r   r   default_args6      zBosonOp.default_argsc                 O   sd   t |dvrtd| t |dkr|d tjf}t |dkr)|d t|d f}tj| g|R  S )N)r      z"1 or 2 parameters expected, got %sr   r   r$   )len
ValueErrorr   Oner   r   __new__)clsr   hintsr   r   r   r(   :   s   zBosonOp.__new__c                 K   s<   | j |j kr| js|jrtjS d S d|v r|d rtjS d S )Nindependent)r   r    r   NegativeOneZeror   otherr*   r   r   r   _eval_commutator_BosonOpF   s   z BosonOp._eval_commutator_BosonOpc                 K   s   t jS N)r   r-   r.   r   r   r   _eval_commutator_FermionOpR   s   z"BosonOp._eval_commutator_FermionOpc                 K   s    d|v r|d rd|  | S d S )Nr+   r$   r   r.   r   r   r   _eval_anticommutator_BosonOpU   s   z$BosonOp._eval_anticommutator_BosonOpc                 C   s   t t| j| j S r1   )r   strr   r    r   r   r   r   _eval_adjoint\   s   zBosonOp._eval_adjointc                 C   sn   |t dkr| S t|tr2tdd |jD }tdd |jD }| }|D ]}|| }q%t| | S t| |S )Nr$   c                 s   s    | ]}|j r|V  qd S r1   is_commutative.0argr   r   r   	<genexpr>e       z"BosonOp.__mul__.<locals>.<genexpr>c                 s   s    | ]}|j s|V  qd S r1   r6   r8   r   r   r   r;   f   r<   )r   
isinstancer   tupler   )r   r/   args1args2xyr   r   r   __mul___   s   


zBosonOp.__mul__c                 G   "   | j r
dt| j S dt| j S )Nz{%s}z{{%s}^\dagger}r    r4   r   r   printerr   r   r   r   _print_contents_latexn      zBosonOp._print_contents_latexc                 G   rD   )Nz%sz
Dagger(%s)rE   rF   r   r   r   _print_contentst   rI   zBosonOp._print_contentsc                 G   s:   ddl m} |j| jd g|R  }| jr|S ||d S )Nr   )
prettyFormu   †) sympy.printing.pretty.stringpictrK   _printr   r    )r   rG   r   rK   pformr   r   r   _print_contents_prettyz   s
   zBosonOp._print_contents_prettyN)__name__
__module____qualname____doc__propertyr   r    classmethodr"   r(   r0   r2   r3   r5   rC   rH   rJ   rO   r   r   r   r   r      s"    


r   c                   @   L   e Zd ZdZdd Zedd Zedd Zedd	 Z	d
d Z
dd ZdS )r   zvFock state ket for a bosonic mode.

    Parameters
    ==========

    n : Number
        The Fock state number.

    c                 C      t | |S r1   r   r(   r)   nr   r   r   r(         zBosonFockKet.__new__c                 C   r   r   labelr   r   r   r   rZ      r   zBosonFockKet.nc                 C      t S r1   )r   r   r   r   r   
dual_class   r#   zBosonFockKet.dual_classc                 C      t  S r1   r
   r)   r]   r   r   r   _eval_hilbert_space      z BosonFockKet._eval_hilbert_spacec                 K   s   t | j|jS r1   )r   rZ   r   brar*   r   r   r   _eval_innerproduct_BosonFockBra   s   z,BosonFockKet._eval_innerproduct_BosonFockBrac                 K   s:   |j rt| jt| jd  S t| jd t| jd  S r   )r    r   rZ   r   r   opoptionsr   r   r   _apply_from_right_to_BosonOp   s   z)BosonFockKet._apply_from_right_to_BosonOpN)rP   rQ   rR   rS   r(   rT   rZ   rU   r_   rc   rg   rk   r   r   r   r   r      s    



r   c                   @   s<   e Zd ZdZdd Zedd Zedd Zedd	 Z	d
S )r   zvFock state bra for a bosonic mode.

    Parameters
    ==========

    n : Number
        The Fock state number.

    c                 C   rW   r1   r   r(   rY   r   r   r   r(      r[   zBosonFockBra.__new__c                 C   r   r   r\   r   r   r   r   rZ      r   zBosonFockBra.nc                 C   r^   r1   )r   r   r   r   r   r_      r#   zBosonFockBra.dual_classc                 C   r`   r1   ra   rb   r   r   r   rc      rd   z BosonFockBra._eval_hilbert_spaceN)
rP   rQ   rR   rS   r(   rT   rZ   rU   r_   rc   r   r   r   r   r      s    


r   c                   @   rV   )r   zCoherent state ket for a bosonic mode.

    Parameters
    ==========

    alpha : Number, Symbol
        The complex amplitude of the coherent state.

    c                 C   rW   r1   rX   r)   alphar   r   r   r(      r[   zBosonCoherentKet.__new__c                 C   r   r   r\   r   r   r   r   rn      r   zBosonCoherentKet.alphac                 C   r^   r1   )r   r   r   r   r   r_      r#   zBosonCoherentKet.dual_classc                 C   r`   r1   )r	   rb   r   r   r   rc      rd   z$BosonCoherentKet._eval_hilbert_spacec                 K   sL   | j |j kr	tjS tt| j d t|j d  dt|j  | j    d S )Nr$   )rn   r   r'   r   absr   re   r   r   r   #_eval_innerproduct_BosonCoherentBra   s   :z4BosonCoherentKet._eval_innerproduct_BosonCoherentBrac                 K   s   |j r| j|  S d S r1   r    rn   rh   r   r   r   rk         
z-BosonCoherentKet._apply_from_right_to_BosonOpN)rP   rQ   rR   rS   r(   rT   rn   rU   r_   rc   rp   rk   r   r   r   r   r      s    



r   c                   @   s8   e Zd ZdZdd Zedd Zedd Zdd	 Z	d
S )r   zCoherent state bra for a bosonic mode.

    Parameters
    ==========

    alpha : Number, Symbol
        The complex amplitude of the coherent state.

    c                 C   rW   r1   rl   rm   r   r   r   r(      r[   zBosonCoherentBra.__new__c                 C   r   r   r\   r   r   r   r   rn      r   zBosonCoherentBra.alphac                 C   r^   r1   )r   r   r   r   r   r_      r#   zBosonCoherentBra.dual_classc                 K   s   |j s| j|  S d S r1   rq   rh   r   r   r   _apply_operator_BosonOp   rr   z(BosonCoherentBra._apply_operator_BosonOpN)
rP   rQ   rR   rS   r(   rT   rn   rU   r_   rs   r   r   r   r   r      s    


r   N)rS   sympy.core.mulr   sympy.core.numbersr   sympy.core.singletonr   $sympy.functions.elementary.complexesr   &sympy.functions.elementary.exponentialr   (sympy.functions.elementary.miscellaneousr   sympy.physics.quantumr   r	   r
   r   r   r   (sympy.functions.special.tensor_functionsr   __all__r   r   r   r   r   r   r   r   r   <module>   s     	l$'