o
    §ƒðjÊ  ã                   @   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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.é    )ÚInteger)ÚS)Ú	conjugate)Úexp)Úsqrt)ÚOperator)ÚHilbertSpaceÚ	FockSpaceÚKetÚBra)ÚKroneckerDelta)ÚBosonOpÚBosonFockKetÚBosonFockBraÚBosonCoherentKetÚBosonCoherentBrac                   @   st   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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   ú�/tmp/claude-1000/-var-www-html-academy/3f42efd1-c2b7-4d08-9b05-30d86bb35479/scratchpad/piper/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_annihilation1   s   zBosonOp.is_annihilationc                 C   s   dS )N)ÚaTr   r   r   r   r   Údefault_args5   ó   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&   9   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_BosonOpE   s   üz BosonOp._eval_commutator_BosonOpc                 K   s   t jS ©N)r   r+   r,   r   r   r   Ú_eval_commutator_FermionOpQ   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_BosonOpT   s   z$BosonOp._eval_anticommutator_BosonOpc                 C   s   t t| jƒ| j ƒS r/   )r   Ústrr   r   r   r   r   r   Ú_eval_adjoint[   s   zBosonOp._eval_adjointc                 G   ó"   | j r
dt| jƒ S dt| jƒ S )Nz{%s}z{{%s}^\dagger}©r   r2   r   ©r   Úprinterr   r   r   r   Ú_print_contents_latex^   ó   zBosonOp._print_contents_latexc                 G   r4   )Nz%sz
Dagger(%s)r5   r6   r   r   r   Ú_print_contentsd   r9   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.stringpictr;   Ú_printr   r   )r   r7   r   r;   Úpformr   r   r   Ú_print_contents_prettyj   s
   zBosonOp._print_contents_prettyN)Ú__name__Ú
__module__Ú__qualname__Ú__doc__Úpropertyr   r   Úclassmethodr    r&   r.   r0   r1   r3   r8   r:   r?   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 r/   ©r
   r&   ©r'   Únr   r   r   r&   ~   ó   zBosonFockKet.__new__c                 C   r   r   ©Úlabelr   r   r   r   rJ   �   r   zBosonFockKet.nc                 C   ó   t S r/   )r   r   r   r   r   Ú
dual_class…   r!   zBosonFockKet.dual_classc                 C   ó   t ƒ S r/   ©r	   ©r'   rM   r   r   r   Ú_eval_hilbert_space‰   ó   z BosonFockKet._eval_hilbert_spacec                 K   s   t | j|jƒS r/   )r   rJ   ©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   rJ   r   ©r   ÚopÚoptionsr   r   r   Ú_apply_from_right_to_BosonOp�   s   z)BosonFockKet._apply_from_right_to_BosonOpN)r@   rA   rB   rC   r&   rD   rJ   rE   rO   rS   rW   r[   r   r   r   r   r   s   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   rG   r/   ©r   r&   rI   r   r   r   r&   ¢   rK   zBosonFockBra.__new__c                 C   r   r   rL   r   r   r   r   rJ   ¥   r   zBosonFockBra.nc                 C   rN   r/   )r   r   r   r   r   rO   ©   r!   zBosonFockBra.dual_classc                 C   rP   r/   rQ   rR   r   r   r   rS   ­   rT   z BosonFockBra._eval_hilbert_spaceN)
r@   rA   rB   rC   r&   rD   rJ   rE   rO   rS   r   r   r   r   r   —   s    


r   c                   @   rF   )r   zœCoherent state ket for a bosonic mode.

    Parameters
    ==========

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

    c                 C   rG   r/   rH   ©r'   Úalphar   r   r   r&   ½   rK   zBosonCoherentKet.__new__c                 C   r   r   rL   r   r   r   r   r^   À   r   zBosonCoherentKet.alphac                 C   rN   r/   )r   r   r   r   r   rO   Ä   r!   zBosonCoherentKet.dual_classc                 C   rP   r/   )r   rR   r   r   r   rS   È   rT   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"   )r^   r   r%   r   Úabsr   rU   r   r   r   Ú#_eval_innerproduct_BosonCoherentBraÌ   s   :z4BosonCoherentKet._eval_innerproduct_BosonCoherentBrac                 K   s   |j r| j|  S d S r/   ©r   r^   rX   r   r   r   r[   Ò   ó   
z-BosonCoherentKet._apply_from_right_to_BosonOpN)r@   rA   rB   rC   r&   rD   r^   rE   rO   rS   r`   r[   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   rG   r/   r\   r]   r   r   r   r&   ä   rK   zBosonCoherentBra.__new__c                 C   r   r   rL   r   r   r   r   r^   ç   r   zBosonCoherentBra.alphac                 C   rN   r/   )r   r   r   r   r   rO   ë   r!   zBosonCoherentBra.dual_classc                 K   s   |j s| j|  S d S r/   ra   rX   r   r   r   Ú_apply_operator_BosonOpï   rb   z(BosonCoherentBra._apply_operator_BosonOpN)
r@   rA   rB   rC   r&   rD   r^   rE   rO   rc   r   r   r   r   r   Ù   s    


r   N)rC   Ú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   Ú(sympy.functions.special.tensor_functionsr   Ú__all__r   r   r   r   r   r   r   r   r   Ú<module>   s    	]$'