U
    9%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 dddddg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   s
   | j d S Nr   )argsself r   Z/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/sympy/physics/quantum/boson.pyname.   s    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   s    zBosonOp.default_argsc                 O   sb   t |dkrtd| t |dkr2|d tjf}t |dkrR|d t|d f}tj| f| 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s6|jr6tjS nd|kr6|d r6t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|k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 r-   )r   strr   r   r   r   r   r   _eval_adjoint\   s    zBosonOp._eval_adjointc                 C   sn   |t dkr| S t|trdtdd |jD }tdd |jD }| }|D ]}|| }qJt| | S t| |S )Nr!   c                 s   s   | ]}|j r|V  qd S r-   Zis_commutative.0argr   r   r   	<genexpr>e   s      z"BosonOp.__mul__.<locals>.<genexpr>c                 s   s   | ]}|j s|V  qd S r-   r2   r3   r   r   r   r6   f   s      )r   
isinstancer   tupler   )r   r+   Zargs1Zargs2xyr   r   r   __mul___   s    

zBosonOp.__mul__c                 G   s&   | j rdt| j S dt| j S d S )Nz{%s}z{{%s}^\dagger}r   r0   r   r   printerr   r   r   r   _print_contents_latexn   s    zBosonOp._print_contents_latexc                 G   s&   | j rdt| j S dt| j S d S )Nz%sz
Dagger(%s)r<   r=   r   r   r   _print_contentst   s    zBosonOp._print_contentsc                 G   s<   ddl m} |j| jd f| }| jr,|S ||d S d S )Nr   )
prettyFormu   †)Z sympy.printing.pretty.stringpictrA   Z_printr   r   )r   r>   r   rA   Zpformr   r   r   _print_contents_prettyz   s
    zBosonOp._print_contents_prettyN)__name__
__module____qualname____doc__propertyr   r   classmethodr    r%   r,   r.   r/   r1   r;   r?   r@   rB   r   r   r   r   r      s    


c                   @   sL   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   s   t | |S r-   r   r%   r&   nr   r   r   r%      s    zBosonFockKet.__new__c                 C   s
   | j d S r   labelr   r   r   r   rK      s    zBosonFockKet.nc                 C   s   t S r-   )r   r   r   r   r   
dual_class   s    zBosonFockKet.dual_classc                 C   s   t  S r-   r
   r&   rM   r   r   r   _eval_hilbert_space   s    z BosonFockKet._eval_hilbert_spacec                 K   s   t | j|jS r-   )r   rK   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 d S r   )r   r   rK   r   r   opoptionsr   r   r   _apply_from_right_to_BosonOp   s    z)BosonFockKet._apply_from_right_to_BosonOpN)rC   rD   rE   rF   r%   rG   rK   rH   rN   rQ   rS   rW   r   r   r   r   r      s   



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   s   t | |S r-   r   r%   rJ   r   r   r   r%      s    zBosonFockBra.__new__c                 C   s
   | j d S r   rL   r   r   r   r   rK      s    zBosonFockBra.nc                 C   s   t S r-   )r   r   r   r   r   rN      s    zBosonFockBra.dual_classc                 C   s   t  S r-   rO   rP   r   r   r   rQ      s    z BosonFockBra._eval_hilbert_spaceN)
rC   rD   rE   rF   r%   rG   rK   rH   rN   rQ   r   r   r   r   r      s   


c                   @   sL   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   zCoherent state ket for a bosonic mode.

    Parameters
    ==========

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

    c                 C   s   t | |S r-   rI   r&   alphar   r   r   r%      s    zBosonCoherentKet.__new__c                 C   s
   | j d S r   rL   r   r   r   r   rZ      s    zBosonCoherentKet.alphac                 C   s   t S r-   )r   r   r   r   r   rN      s    zBosonCoherentKet.dual_classc                 C   s   t  S r-   )r	   rP   r   r   r   rQ      s    z$BosonCoherentKet._eval_hilbert_spacec                 K   sP   | j |j krtjS tt| j d t|j d  dt|j  | j    d S d S )Nr!   )rZ   r   r$   r   absr   rR   r   r   r   #_eval_innerproduct_BosonCoherentBra   s    z4BosonCoherentKet._eval_innerproduct_BosonCoherentBrac                 K   s   |j r| j|  S d S d S r-   r   rZ   rT   r   r   r   rW      s    
z-BosonCoherentKet._apply_from_right_to_BosonOpN)rC   rD   rE   rF   r%   rG   rZ   rH   rN   rQ   r\   rW   r   r   r   r   r      s   



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   s   t | |S r-   rX   rY   r   r   r   r%      s    zBosonCoherentBra.__new__c                 C   s
   | j d S r   rL   r   r   r   r   rZ      s    zBosonCoherentBra.alphac                 C   s   t S r-   )r   r   r   r   r   rN      s    zBosonCoherentBra.dual_classc                 K   s   |j s| j|  S d S d S r-   r]   rT   r   r   r   _apply_operator_BosonOp   s    
z(BosonCoherentBra._apply_operator_BosonOpN)
rC   rD   rE   rF   r%   rG   rZ   rH   rN   r^   r   r   r   r   r      s   


N)rF   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$'