o
    Ïe©  ã                   @   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   úKD:\Projects\ConvertPro\env\Lib\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   Z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 r0   )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 r0   ©Zis_commutative©Ú.0Úargr   r   r   Ú	<genexpr>e   ó   € z"BosonOp.__mul__.<locals>.<genexpr>c                 s   s   � | ]}|j s|V  qd S r0   r5   r6   r   r   r   r9   f   r:   )r   Ú
isinstancer   Útupler   )r   r.   Zargs1Z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    r3   r   ©r   Úprinterr   r   r   r   Ú_print_contents_latexn   ó   zBosonOp._print_contents_latexc                 G   r@   )Nz%sz
Dagger(%s)rA   rB   r   r   r   Ú_print_contentst   rE   zBosonOp._print_contentsc                 G   s:   ddl m} |j| jd g|¢R Ž }| jr|S ||dƒ S )Nr   )Ú
prettyFormu   â€ )Z sympy.printing.pretty.stringpictrG   Z_printr   r    )r   rC   r   rG   Zpformr   r   r   Ú_print_contents_prettyz   s
   zBosonOp._print_contents_prettyN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úpropertyr   r    Úclassmethodr"   r(   r/   r1   r2   r4   r?   rD   rF   rH   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 r0   ©r   r(   ©r)   Únr   r   r   r(   Ž   ó   zBosonFockKet.__new__c                 C   r   r   ©Úlabelr   r   r   r   rS   ‘   r   zBosonFockKet.nc                 C   ó   t S r0   )r   r   r   r   r   Ú
dual_class•   r#   zBosonFockKet.dual_classc                 C   ó   t ƒ S r0   ©r
   ©r)   rV   r   r   r   Ú_eval_hilbert_space™   ó   z BosonFockKet._eval_hilbert_spacec                 K   s   t | j|jƒS r0   )r   rS   ©r   Z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   rS   r   ©r   ÚopÚoptionsr   r   r   Ú_apply_from_right_to_BosonOp    s   z)BosonFockKet._apply_from_right_to_BosonOpN)rI   rJ   rK   rL   r(   rM   rS   rN   rX   r\   r_   rc   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   rP   r0   ©r   r(   rR   r   r   r   r(   ²   rT   zBosonFockBra.__new__c                 C   r   r   rU   r   r   r   r   rS   µ   r   zBosonFockBra.nc                 C   rW   r0   )r   r   r   r   r   rX   ¹   r#   zBosonFockBra.dual_classc                 C   rY   r0   rZ   r[   r   r   r   r\   ½   r]   z BosonFockBra._eval_hilbert_spaceN)
rI   rJ   rK   rL   r(   rM   rS   rN   rX   r\   r   r   r   r   r   §   s    


r   c                   @   rO   )r   zœCoherent state ket for a bosonic mode.

    Parameters
    ==========

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

    c                 C   rP   r0   rQ   ©r)   Úalphar   r   r   r(   Í   rT   zBosonCoherentKet.__new__c                 C   r   r   rU   r   r   r   r   rf   Ð   r   zBosonCoherentKet.alphac                 C   rW   r0   )r   r   r   r   r   rX   Ô   r#   zBosonCoherentKet.dual_classc                 C   rY   r0   )r	   r[   r   r   r   r\   Ø   r]   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$   )rf   r   r'   r   Úabsr   r^   r   r   r   Ú#_eval_innerproduct_BosonCoherentBraÜ   s   :z4BosonCoherentKet._eval_innerproduct_BosonCoherentBrac                 K   s   |j r| j|  S d S r0   ©r    rf   r`   r   r   r   rc   â   ó   
z-BosonCoherentKet._apply_from_right_to_BosonOpN)rI   rJ   rK   rL   r(   rM   rf   rN   rX   r\   rh   rc   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   zœCoherent state bra for a bosonic mode.

    Parameters
    ==========

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

    c                 C   rP   r0   rd   re   r   r   r   r(   ô   rT   zBosonCoherentBra.__new__c                 C   r   r   rU   r   r   r   r   rf   ÷   r   zBosonCoherentBra.alphac                 C   rW   r0   )r   r   r   r   r   rX   û   r#   zBosonCoherentBra.dual_classc                 K   s   |j s| j|  S d S r0   ri   r`   r   r   r   Ú_apply_operator_BosonOpÿ   rj   z(BosonCoherentBra._apply_operator_BosonOpN)
rI   rJ   rK   rL   r(   rM   rf   rN   rX   rk   r   r   r   r   r   é   s    


r   N)rL   Zsympy.core.mulr   Zsympy.core.numbersr   Zsympy.core.singletonr   Z$sympy.functions.elementary.complexesr   Z&sympy.functions.elementary.exponentialr   Z(sympy.functions.elementary.miscellaneousr   Zsympy.physics.quantumr   r	   r
   r   r   r   Z(sympy.functions.special.tensor_functionsr   Ú__all__r   r   r   r   r   r   r   r   r   Ú<module>   s     	l$'