
    g:'                         d Z dgZddlmZ ddlmZ ddlmZmZ ddl	m
Z
mZmZ ddlmZ ddlmZmZ dd	lmZmZ dd
lmZ ddlmZ ddlmZmZmZ ddlmZmZm Z   ej!        ee z            Z" G d de          Z#dS )zb
This module has all the classes and functions related to waves in optics.

**Contains**

* TWave
TWave    )Basic)Expr)
DerivativeFunction)NumberpiI)S)Symbolsymbols)_sympifysympify)exp)sqrt)atan2cossin)speed_of_lightmetersecondc                   P   e Zd ZdZdej        d ed          fdZed             Z	ed             Z
ed             Zed             Zed	             Zed
             Zed             Zed             Zed             Zd ZeZd Zd Zd Zd Zd Zd Zd Zd Zd Zd Zd ZdS )r   a4  
    This is a simple transverse sine wave travelling in a one-dimensional space.
    Basic properties are required at the time of creation of the object,
    but they can be changed later with respective methods provided.

    Explanation
    ===========

    It is represented as :math:`A \times cos(k*x - \omega \times t + \phi )`,
    where :math:`A` is the amplitude, :math:`\omega` is the angular frequency,
    :math:`k` is the wavenumber (spatial frequency), :math:`x` is a spatial variable
    to represent the position on the dimension on which the wave propagates,
    and :math:`\phi` is the phase angle of the wave.


    Arguments
    =========

    amplitude : Sympifyable
        Amplitude of the wave.
    frequency : Sympifyable
        Frequency of the wave.
    phase : Sympifyable
        Phase angle of the wave.
    time_period : Sympifyable
        Time period of the wave.
    n : Sympifyable
        Refractive index of the medium.

    Raises
    =======

    ValueError : When neither frequency nor time period is provided
        or they are not consistent.
    TypeError : When anything other than TWave objects is added.


    Examples
    ========

    >>> from sympy import symbols
    >>> from sympy.physics.optics import TWave
    >>> A1, phi1, A2, phi2, f = symbols('A1, phi1, A2, phi2, f')
    >>> w1 = TWave(A1, f, phi1)
    >>> w2 = TWave(A2, f, phi2)
    >>> w3 = w1 + w2  # Superposition of two waves
    >>> w3
    TWave(sqrt(A1**2 + 2*A1*A2*cos(phi1 - phi2) + A2**2), f,
        atan2(A1*sin(phi1) + A2*sin(phi2), A1*cos(phi1) + A2*cos(phi2)), 1/f, n)
    >>> w3.amplitude
    sqrt(A1**2 + 2*A1*A2*cos(phi1 - phi2) + A2**2)
    >>> w3.phase
    atan2(A1*sin(phi1) + A2*sin(phi2), A1*cos(phi1) + A2*cos(phi2))
    >>> w3.speed
    299792458*meter/(second*n)
    >>> w3.angular_velocity
    2*pi*f

    Nnc                    |t          |          }t          j        |z  }|Bt          |          }t          j        |z  }|"|t          j        |z  k    rt          d          ||t          d          ||}||}t          |          }t          |          }t	          |          }t          j        | |||||          }|S )Nz/frequency and time_period should be consistent.z*Either frequency or time period is needed.)r   r   One
ValueErrorr   r   __new__)	cls	amplitude	frequencyphasetime_periodr   
_frequency_time_periodobjs	            V/var/www/html/ai-engine/env/lib/python3.11/site-packages/sympy/physics/optics/waves.pyr   zTWave.__new__Y   s     "";//K{*J  ++I5?L&k 111$%VWWW!4IJJJ"I&KY''	AJJmCIuk1MM
    c                     | j         d         S )a!  
        Returns the amplitude of the wave.

        Examples
        ========

        >>> from sympy import symbols
        >>> from sympy.physics.optics import TWave
        >>> A, phi, f = symbols('A, phi, f')
        >>> w = TWave(A, f, phi)
        >>> w.amplitude
        A
        r   argsselfs    r&   r   zTWave.amplitudev   s     y|r'   c                     | j         d         S )a?  
        Returns the frequency of the wave,
        in cycles per second.

        Examples
        ========

        >>> from sympy import symbols
        >>> from sympy.physics.optics import TWave
        >>> A, phi, f = symbols('A, phi, f')
        >>> w = TWave(A, f, phi)
        >>> w.frequency
        f
           r)   r+   s    r&   r    zTWave.frequency         y|r'   c                     | j         d         S )a5  
        Returns the phase angle of the wave,
        in radians.

        Examples
        ========

        >>> from sympy import symbols
        >>> from sympy.physics.optics import TWave
        >>> A, phi, f = symbols('A, phi, f')
        >>> w = TWave(A, f, phi)
        >>> w.phase
        phi
           r)   r+   s    r&   r!   zTWave.phase   r/   r'   c                     | j         d         S )aI  
        Returns the temporal period of the wave,
        in seconds per cycle.

        Examples
        ========

        >>> from sympy import symbols
        >>> from sympy.physics.optics import TWave
        >>> A, phi, f = symbols('A, phi, f')
        >>> w = TWave(A, f, phi)
        >>> w.time_period
        1/f
           r)   r+   s    r&   r"   zTWave.time_period   r/   r'   c                     | j         d         S )z<
        Returns the refractive index of the medium
           r)   r+   s    r&   r   zTWave.n   s    
 y|r'   c                 0    t           | j        | j        z  z  S )a  
        Returns the wavelength (spatial period) of the wave,
        in meters per cycle.
        It depends on the medium of the wave.

        Examples
        ========

        >>> from sympy import symbols
        >>> from sympy.physics.optics import TWave
        >>> A, phi, f = symbols('A, phi, f')
        >>> w = TWave(A, f, phi)
        >>> w.wavelength
        299792458*meter/(second*f*n)
        )cr    r   r+   s    r&   
wavelengthzTWave.wavelength   s    " $.'((r'   c                      | j         | j        z  S )a  
        Returns the propagation speed of the wave,
        in meters per second.
        It is dependent on the propagation medium.

        Examples
        ========

        >>> from sympy import symbols
        >>> from sympy.physics.optics import TWave
        >>> A, phi, f = symbols('A, phi, f')
        >>> w = TWave(A, f, phi)
        >>> w.speed
        299792458*meter/(second*n)
        )r8   r    r+   s    r&   speedzTWave.speed   s    " t~--r'   c                 &    dt           z  | j        z  S )aS  
        Returns the angular velocity of the wave,
        in radians per second.

        Examples
        ========

        >>> from sympy import symbols
        >>> from sympy.physics.optics import TWave
        >>> A, phi, f = symbols('A, phi, f')
        >>> w = TWave(A, f, phi)
        >>> w.angular_velocity
        2*pi*f
        r1   )r	   r    r+   s    r&   angular_velocityzTWave.angular_velocity   s      tDN""r'   c                 &    dt           z  | j        z  S )a_  
        Returns the wavenumber of the wave,
        in radians per meter.

        Examples
        ========

        >>> from sympy import symbols
        >>> from sympy.physics.optics import TWave
        >>> A, phi, f = symbols('A, phi, f')
        >>> w = TWave(A, f, phi)
        >>> w.wavenumber
        pi*second*f*n/(149896229*meter)
        r1   )r	   r8   r+   s    r&   
wavenumberzTWave.wavenumber   s      tDO##r'   c                 X    ddl m} t          |           j         || j                  z   S )z!String representation of a TWave.r   )sstr)sympy.printingr@   type__name__r*   )r,   r@   s     r&   __str__zTWave.__str__  s2    ''''''Dzz"TT$)__44r'   c                    t          |t                    r| j        |j        k    r| j        |j        k    rt          t	          | j        dz  |j        dz  z   d| j        z  |j        z  t          | j        |j        z
            z  z             | j        t          | j        t          | j                  z  |j        t          |j                  z  z   | j        t          | j                  z  |j        t          |j                  z  z                       S t          d          t          t          |          j        dz             )z
        Addition of two waves will result in their superposition.
        The type of interference will depend on their phase angles.
        r1   zJInterference of waves with different frequencies has not been implemented.z# and TWave objects cannot be added.)
isinstancer   r    r8   r   r   r   r!   r   r   NotImplementedError	TypeErrorrB   rC   r,   others     r&   __add__zTWave.__add__  sR   
 eU## 	Z~00T_HX5X5XT$.!"3eoq6H"H1"&.L116LAAD&*j5;&>B@ B@L@ #@ A A "^"4>#dj//#A$s5;/?/??$@!^C
OO;$s5;/?/??@A A	   * +1 2 2 2 DKK03XXYYYr'   c                     t          |          }t          |t                    r"t          | j        |z  g| j        dd         R  S t          t          |          j        dz             )zT
        Multiplying a wave by a scalar rescales the amplitude of the wave.
        r.   Nz( and TWave objects cannot be multiplied.)	r   rF   r   r   r   r*   rH   rB   rC   rI   s     r&   __mul__zTWave.__mul__,  sf     eV$$ 	_->	!"">>>>DKK03]]^^^r'   c                 2    |                      d|z            S NrK   rI   s     r&   __sub__zTWave.__sub__6  s    ||BuH%%%r'   c                 ,    |                      d          S rO   rM   r+   s    r&   __neg__zTWave.__neg__9  s    ||Br'   c                 ,    |                      |          S NrQ   rI   s     r&   __radd__zTWave.__radd__<      ||E"""r'   c                 ,    |                      |          S rW   rT   rI   s     r&   __rmul__zTWave.__rmul__?  rY   r'   c                 .    |                       |          S rW   )rX   rI   s     r&   __rsub__zTWave.__rsub__B  s    &&&r'   c                     | j         t          | j        t          d          z  | j        t          d          z  z
  | j        z   t          dz  z   d          z  S )Nxtr1   F)evaluate)r   r   r>   r   r<   r!   r	   r,   r*   kwargss      r&   _eval_rewrite_as_sinzTWave._eval_rewrite_as_sinE  sf    ~c$/&++"=#F3KK/#026*#=?A!t#DNSU U U U 	Ur'   c                     | j         t          | j        t          d          z  | j        t          d          z  z
  | j        z             z  S Nr_   r`   )r   r   r>   r   r<   r!   rb   s      r&   _eval_rewrite_as_coszTWave._eval_rewrite_as_cosI  sL    ~c$/&++"=#F3KK/#026*#= > > > 	>r'   c                     t          d          \  }}}}t          d          }t           |||          |d          ||z  t           |||          |d          z  z   S )Nzmu, epsilon, x, tEr1   )r   r   r   )r,   r*   rc   muepsilonr_   r`   ri   s           r&   _eval_rewrite_as_pdezTWave._eval_rewrite_as_pdeM  sd    #$788GQSMM!!Aq''1a((2g:j1a!Q6O6O+OOOr'   c           	          | j         t          t          | j        t	          d          z  | j        t	          d          z  z
  | j        z   z            z  S rf   )r   r   r
   r>   r   r<   r!   rb   s      r&   _eval_rewrite_as_expzTWave._eval_rewrite_as_expR  sS    ~c!T_VC[[%@#F3KK/&026*&= #> ? ? ? 	?r'   )rC   
__module____qualname____doc__r   Zeror   r   propertyr   r    r!   r"   r   r8   r:   r<   r>   rD   __repr__rK   rM   rR   rU   rX   r[   r]   rd   rg   rl   rn    r'   r&   r   r      s       : :~ &fSkk   :   X    X"   X"   X"   X ) ) X)& . . X.$ # # X#" $ $ X$"5 5 5
 HZ Z Z,_ _ _& & &     # # ## # #' ' 'U U U> > >P P P
? ? ? ? ?r'   N)$rq   __all__sympy.core.basicr   sympy.core.exprr   sympy.core.functionr   r   sympy.core.numbersr   r	   r
   sympy.core.singletonr   sympy.core.symbolr   r   sympy.core.sympifyr   r   &sympy.functions.elementary.exponentialr   (sympy.functions.elementary.miscellaneousr   (sympy.functions.elementary.trigonometricr   r   r   sympy.physics.unitsr   r   r   
convert_tor7   r   ru   r'   r&   <module>r      sj    ) " " " " " "             4 4 4 4 4 4 4 4 . . . . . . . . . . " " " " " " / / / / / / / / 0 0 0 0 0 0 0 0 6 6 6 6 6 6 9 9 9 9 9 9 F F F F F F F F F F = = = = = = = = = = NeFl++y? y? y? y? y?D y? y? y? y? y?r'   