§
    PŠtj^<  ã                   óÎ   — d dl m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 d dlmZ d d	lmZ d d
lmZ dd„Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zd„ Zddœd„Z dS )é    )Ú
CoordSys3D)ÚDel)Ú
BaseScalar)ÚVectorÚ
BaseVector)ÚgradientÚcurlÚ
divergence)Údiff)ÚS)Ú	integrate)Úsympify)ÚDyadicNFc           	      óˆ  — | dt           j        fv r| S t          |t          ¦  «        st	          d¦  «        ‚t          | t           ¦  «        �r|�t          d¦  «        ‚|rrd„ |                      t          t          ¦  «        D ¦   «         |hz
  }i }|D ]*}| 	                    | 
                    |¦  «        ¦  «         Œ+|                      |¦  «        } t           j        }|                      ¦   «         }|D ]X}	|	|k    rE|                     |	¦  «        ||	                              |	¦  «        z  }
|t          |
|¦  «        z  }ŒM|||	         z  }ŒY|S t          | t           ¦  «        r¨|€|}t          |t          ¦  «        st	          d¦  «        ‚t           j        }|}| j                             ¦   «         D ]V\  }}|t'          |||¬¦  «        t'          |j        d         ||¬¦  «        t'          |j        d         ||¬¦  «        z  z  z  }ŒW|S |�t          d¦  «        ‚|r£t+          ¦   «         }t-          | ¦  «        } |                      t          ¦  «        D ]'}	|	j        |k    r|                     |	j        ¦  «         Œ(i }|D ]*}| 	                    | 
                    |¦  «        ¦  «         Œ+|                      |¦  «        S | S )	aK  
    Global function for 'express' functionality.

    Re-expresses a Vector, Dyadic or scalar(sympyfiable) in the given
    coordinate system.

    If 'variables' is True, then the coordinate variables (base scalars)
    of other coordinate systems present in the vector/scalar field or
    dyadic are also substituted in terms of the base scalars of the
    given system.

    Parameters
    ==========

    expr : Vector/Dyadic/scalar(sympyfiable)
        The expression to re-express in CoordSys3D 'system'

    system: CoordSys3D
        The coordinate system the expr is to be expressed in

    system2: CoordSys3D
        The other coordinate system required for re-expression
        (only for a Dyadic Expr)

    variables : boolean
        Specifies whether to substitute the coordinate variables present
        in expr, in terms of those of parameter system

    Examples
    ========

    >>> from sympy.vector import CoordSys3D
    >>> from sympy import Symbol, cos, sin
    >>> N = CoordSys3D('N')
    >>> q = Symbol('q')
    >>> B = N.orient_new_axis('B', q, N.k)
    >>> from sympy.vector import express
    >>> express(B.i, N)
    (cos(q))*N.i + (sin(q))*N.j
    >>> express(N.x, B, variables=True)
    B.x*cos(q) - B.y*sin(q)
    >>> d = N.i.outer(N.i)
    >>> express(d, B, N) == (cos(q))*(B.i|N.i) + (-sin(q))*(B.j|N.i)
    True

    r   z>system should be a CoordSys3D                         instanceNzJsystem2 should not be provided for                                 Vectorsc                 ó   — h | ]	}|j         ’Œ
S © )Úsystem)Ú.0Úxs     úT/var/www/html/CA-Chatbot/venv/lib/python3.11/site-packages/sympy/vector/functions.pyú	<setcomp>zexpress.<locals>.<setcomp>L   s   € ÐPÐPÐP¨˜1œ8ÐPÐPÐPó    zCsystem2 should be a CoordSys3D                             instance©Ú	variablesé   )r   ÚzeroÚ
isinstancer   Ú	TypeErrorÚ
ValueErrorÚatomsr   r   ÚupdateÚ
scalar_mapÚsubsÚseparateÚrotation_matrixÚ	to_matrixÚmatrix_to_vectorr   Ú
componentsÚitemsÚexpressÚargsÚsetr   r   Úadd)Úexprr   Úsystem2r   Úsystem_listÚ	subs_dictÚfÚoutvecÚpartsr   ÚtempÚoutdyadÚvarÚkÚvÚ
system_sets                   r   r*   r*      s  € ð` �•6”;ÐÐÐØˆå�f�jÑ)Ô)ð #Ýð "ñ #ô #ð 	#õ �$�ÑÔñ 7ØÐÝð )ñ *ô *ð *ð ð 	(ð QÐP¨T¯ZªZ½
ÅJÑ-OÔ-OÐPÑPÔPÐTZÐS[Ñ[ˆKØˆIØ ð 7ð 7�Ø× Ò  §¢¨fÑ!5Ô!5Ñ6Ô6Ð6Ð6Ø—9’9˜YÑ'Ô'ˆDå”ˆØ—’‘”ˆØð 	#ð 	#ˆAØ�FŠ{ˆ{Ø×-Ò-¨aÑ0Ô0°5¸´8×3EÒ3EÀaÑ3HÔ3HÑH�ØÕ*¨4°Ñ8Ô8Ñ8��à˜% œ(Ñ"��Øˆå	�D�&Ñ	!Ô	!ð Øˆ?ØˆGÝ˜'¥:Ñ.Ô.ð 	'Ýð &ñ 'ô 'ð 'å”+ˆØˆØ”O×)Ò)Ñ+Ô+ð 	Fð 	F‰DˆAˆqØ�  6°SÐ9Ñ9Ô9Ý  ¤¨¤¨F¸cÐBÑBÔBÝ  ¤¨¤¨G¸sÐCÑCÔCñDñEñ FˆGˆGð ˆð ÐÝð )ñ *ô *ð *àð 	(å™œˆJÝ˜4‘=”=ˆDà—Z’Z¥
Ñ+Ô+ð -ð -�Ø”8˜vÒ%Ð%Ø—N’N 1¤8Ñ,Ô,Ð,øØˆIØð 7ð 7�Ø× Ò  §¢¨fÑ!5Ô!5Ñ6Ô6Ð6Ð6Ø—9’9˜YÑ'Ô'Ð'Øˆr   c                 ó¢  — ddl m}  || ¦  «        }t          |¦  «        dk    rÿt          t	          |¦  «        ¦  «        }t          | |d¬¦  «        } |                     ¦   «         \  }}}|                     ¦   «         \  }}}	t          j	        ||¦  «        t          | |¦  «        z  }
|
t          j	        ||¦  «        t          | |¦  «        z  z  }
|
t          j	        ||¦  «        t          | |	¦  «        z  z  }
|
dk    r!t          | t          ¦  «        rt          j        }
|
S t          | t          ¦  «        rt          j        S t          j        S )aé  
    Returns the directional derivative of a scalar or vector field computed
    along a given vector in coordinate system which parameters are expressed.

    Parameters
    ==========

    field : Vector or Scalar
        The scalar or vector field to compute the directional derivative of

    direction_vector : Vector
        The vector to calculated directional derivative along them.


    Examples
    ========

    >>> from sympy.vector import CoordSys3D, directional_derivative
    >>> R = CoordSys3D('R')
    >>> f1 = R.x*R.y*R.z
    >>> v1 = 3*R.i + 4*R.j + R.k
    >>> directional_derivative(f1, v1)
    R.x*R.y + 4*R.x*R.z + 3*R.y*R.z
    >>> f2 = 5*R.x**2*R.z
    >>> directional_derivative(f2, v1)
    5*R.x**2 + 30*R.x*R.z

    r   )Ú_get_coord_systemsTr   )Úsympy.vector.operatorsr<   ÚlenÚnextÚiterr*   Úbase_vectorsÚbase_scalarsr   Údotr   r   r   r   ÚZero)ÚfieldÚdirection_vectorr<   Ú	coord_sysÚiÚjr8   r   ÚyÚzÚouts              r   Údirectional_derivativerM   ~   s7  € ð: :Ð9Ð9Ð9Ð9Ð9Ø"Ð" 5Ñ)Ô)€IÝ
ˆ9�~„~˜ÒÐå�˜i™œÑ)Ô)ˆ	Ý˜˜y°DÐ9Ñ9Ô9ˆØ×(Ò(Ñ*Ô*‰ˆˆ1ˆaØ×(Ò(Ñ*Ô*‰ˆˆ1ˆaÝŒjÐ)¨1Ñ-Ô-µ°U¸A±´Ñ>ˆØ�vŒzÐ*¨AÑ.Ô.µ°e¸Q±´Ñ?Ñ?ˆØ�vŒzÐ*¨AÑ.Ô.µ°e¸Q±´Ñ?Ñ?ˆØ�!Š8ˆ8�
 5­&Ñ1Ô1ˆ8Ý”+ˆCØˆ
Ý	�E�6Ñ	"Ô	"ð ÝŒ{ÐåŒvˆr   c                 ó"  — t          ¦   «         }| j        rKt          t          | ¦  «        ¦  «        t	          t	          | ¦  «        ¦  «        z
                       ¦   «         S |                      || ¦  «        ¦  «                             ¦   «         S )a!  
    Return the laplacian of the given field computed in terms of
    the base scalars of the given coordinate system.

    Parameters
    ==========

    expr : SymPy Expr or Vector
        expr denotes a scalar or vector field.

    Examples
    ========

    >>> from sympy.vector import CoordSys3D, laplacian
    >>> R = CoordSys3D('R')
    >>> f = R.x**2*R.y**5*R.z
    >>> laplacian(f)
    20*R.x**2*R.y**3*R.z + 2*R.y**5*R.z
    >>> f = R.x**2*R.i + R.y**3*R.j + R.z**4*R.k
    >>> laplacian(f)
    2*R.i + 6*R.y*R.j + 12*R.z**2*R.k

    )r   Ú	is_Vectorr   r
   r	   ÚdoitrC   )r.   Údelops     r   Ú	laplacianrR   ¯   ss   € õ2 ‰EŒE€EØ„~ð FÝ� DÑ)Ô)Ñ*Ô*­Tµ$°t±*´*Ñ-=Ô-=Ñ=×CÒCÑEÔEÐEØ�9Š9�U�U˜4‘[”[Ñ!Ô!×&Ò&Ñ(Ô(Ð(r   c                 óÌ   — t          | t          ¦  «        st          d¦  «        ‚| t          j        k    rdS t	          | ¦  «                             ¦   «         t          j        k    S )aŸ  
    Checks if a field is conservative.

    Parameters
    ==========

    field : Vector
        The field to check for conservative property

    Examples
    ========

    >>> from sympy.vector import CoordSys3D
    >>> from sympy.vector import is_conservative
    >>> R = CoordSys3D('R')
    >>> is_conservative(R.y*R.z*R.i + R.x*R.z*R.j + R.x*R.y*R.k)
    True
    >>> is_conservative(R.z*R.j)
    False

    úfield should be a VectorT)r   r   r   r   r	   Úsimplify©rE   s    r   Úis_conservativerW   Î   sV   € õ4 �e�VÑ$Ô$ð 4ÝÐ2Ñ3Ô3Ð3Ø•”ÒÐØˆtÝ�‰;Œ;×ÒÑ!Ô!¥V¤[Ò0Ð0r   c                 óÈ   — t          | t          ¦  «        st          d¦  «        ‚| t          j        k    rdS t	          | ¦  «                             ¦   «         t          j        u S )a—  
    Checks if a field is solenoidal.

    Parameters
    ==========

    field : Vector
        The field to check for solenoidal property

    Examples
    ========

    >>> from sympy.vector import CoordSys3D
    >>> from sympy.vector import is_solenoidal
    >>> R = CoordSys3D('R')
    >>> is_solenoidal(R.y*R.z*R.i + R.x*R.z*R.j + R.x*R.y*R.k)
    True
    >>> is_solenoidal(R.y * R.j)
    False

    rT   T)r   r   r   r   r
   rU   r   rD   rV   s    r   Úis_solenoidalrY   ï   sX   € õ4 �e�VÑ$Ô$ð 4ÝÐ2Ñ3Ô3Ð3Ø•”ÒÐØˆtÝ�eÑÔ×%Ò%Ñ'Ô'­1¬6Ð1Ð1r   c                 óh  — t          | ¦  «        st          d¦  «        ‚| t          j        k    rt          j        S t          |t          ¦  «        st          d¦  «        ‚t          | |d¬¦  «        } | 
                    ¦   «         }|                     ¦   «         }t          |                      |d         ¦  «        |d         ¦  «        }t          |dd…         ¦  «        D ]R\  }}t          |||dz            ¦  «        }|                      |¦  «        |z
  }|t          |||dz            ¦  «        z  }ŒS|S )aÃ  
    Returns the scalar potential function of a field in a given
    coordinate system (without the added integration constant).

    Parameters
    ==========

    field : Vector
        The vector field whose scalar potential function is to be
        calculated

    coord_sys : CoordSys3D
        The coordinate system to do the calculation in

    Examples
    ========

    >>> from sympy.vector import CoordSys3D
    >>> from sympy.vector import scalar_potential, gradient
    >>> R = CoordSys3D('R')
    >>> scalar_potential(R.k, R) == R.z
    True
    >>> scalar_field = 2*R.x**2*R.y*R.z
    >>> grad_field = gradient(scalar_field)
    >>> scalar_potential(grad_field, R)
    2*R.x**2*R.y*R.z

    zField is not conservativeúcoord_sys must be a CoordSys3DTr   r   r   N)rW   r   r   r   r   rD   r   r   r   r*   rA   rB   r   rC   Ú	enumerater   )rE   rG   Ú
dimensionsÚscalarsÚtemp_functionrH   ÚdimÚpartial_diffs           r   Úscalar_potentialrb     s'  € õ> ˜5Ñ!Ô!ð 6ÝÐ4Ñ5Ô5Ð5Ø•”ÒÐÝŒvˆõ �i¥Ñ,Ô,ð :ÝÐ8Ñ9Ô9Ð9Ý�E˜9°Ð5Ñ5Ô5€EØ×'Ò'Ñ)Ô)€JØ×$Ò$Ñ&Ô&€Gå˜eŸiši¨
°1¬Ñ6Ô6¸À¼
ÑCÔC€MÝ˜J q r rœNÑ+Ô+ð Að A‰ˆˆ3Ý˜M¨7°1°q±5¬>Ñ:Ô:ˆØ—y’y ‘~”~¨Ñ4ˆØ� <°¸¸Q¹´Ñ@Ô@Ñ@ˆˆØÐr   c                 óˆ  — t          |t          ¦  «        st          d¦  «        ‚t          | t          ¦  «        rt	          | |¦  «        }n| }|j        }t          |                     |¦  «        |d¬¦  «        }t          |                     |¦  «        |d¬¦  «        }i }i }	|                     ¦   «         }
t          | 
                    ¦   «         ¦  «        D ]A\  }}|                     |¦  «        ||
|         <   |                     |¦  «        |	|
|         <   ŒB|                     |	¦  «        |                     |¦  «        z
  S )a)  
    Returns the scalar potential difference between two points in a
    certain coordinate system, wrt a given field.

    If a scalar field is provided, its values at the two points are
    considered. If a conservative vector field is provided, the values
    of its scalar potential function at the two points are used.

    Returns (potential at point2) - (potential at point1)

    The position vectors of the two Points are calculated wrt the
    origin of the coordinate system provided.

    Parameters
    ==========

    field : Vector/Expr
        The field to calculate wrt

    coord_sys : CoordSys3D
        The coordinate system to do the calculations in

    point1 : Point
        The initial Point in given coordinate system

    position2 : Point
        The second Point in the given coordinate system

    Examples
    ========

    >>> from sympy.vector import CoordSys3D
    >>> from sympy.vector import scalar_potential_difference
    >>> R = CoordSys3D('R')
    >>> P = R.origin.locate_new('P', R.x*R.i + R.y*R.j + R.z*R.k)
    >>> vectfield = 4*R.x*R.y*R.i + 2*R.x**2*R.j
    >>> scalar_potential_difference(vectfield, R, R.origin, P)
    2*R.x**2*R.y
    >>> Q = R.origin.locate_new('O', 3*R.i + R.j + 2*R.k)
    >>> scalar_potential_difference(vectfield, R, P, Q)
    -2*R.x**2*R.y + 18

    r[   Tr   )r   r   r   r   rb   Úoriginr*   Úposition_wrtrB   r\   rA   rC   r#   )rE   rG   Úpoint1Úpoint2Ú	scalar_fnrd   Ú	position1Ú	position2Ú
subs_dict1Ú
subs_dict2r^   rH   r   s                r   Úscalar_potential_differencerm   C  sH  € õZ �i¥Ñ,Ô,ð :ÝÐ8Ñ9Ô9Ð9Ý�%�Ñ Ô ð å$ U¨IÑ6Ô6ˆ	ˆ	ð ˆ	àÔ€FÝ˜×+Ò+¨FÑ3Ô3°YØ"&ð(ñ (ô (€Iå˜×+Ò+¨FÑ3Ô3°YØ"&ð(ñ (ô (€Ið €JØ€JØ×$Ò$Ñ&Ô&€GÝ˜)×0Ò0Ñ2Ô2Ñ3Ô3ð 2ð 2‰ˆˆ1Ø!"§¢ yÑ!1Ô!1ˆ
�7˜1”:ÑØ!"§¢ yÑ!1Ô!1ˆ
�7˜1”:ÑÐØ�>Š>˜*Ñ%Ô%¨	¯ª°zÑ(BÔ(BÑBÐBr   c                 óŒ   — t           j        }|                     ¦   «         }t          | ¦  «        D ]\  }}||||         z  z  }Œ|S )aà  
    Converts a vector in matrix form to a Vector instance.

    It is assumed that the elements of the Matrix represent the
    measure numbers of the components of the vector along basis
    vectors of 'system'.

    Parameters
    ==========

    matrix : SymPy Matrix, Dimensions: (3, 1)
        The matrix to be converted to a vector

    system : CoordSys3D
        The coordinate system the vector is to be defined in

    Examples
    ========

    >>> from sympy import ImmutableMatrix as Matrix
    >>> m = Matrix([1, 2, 3])
    >>> from sympy.vector import CoordSys3D, matrix_to_vector
    >>> C = CoordSys3D('C')
    >>> v = matrix_to_vector(m, C)
    >>> v
    C.i + 2*C.j + 3*C.k
    >>> v.to_matrix(C) == m
    True

    )r   r   rA   r\   )Úmatrixr   r3   ÚvectsrH   r   s         r   r'   r'   ˆ  sQ   € õ@ Œ[€FØ×ÒÑ!Ô!€EÝ˜&Ñ!Ô!ð ð ‰ˆˆ1Ø�!�e˜A”h‘,ÑˆˆØ€Mr   c                 ó  — | j         |j         k    r2t          dt          | ¦  «        z   dz   t          |¦  «        z   ¦  «        ‚g }|}|j        �#|                     |¦  «         |j        }|j        ­#|                     |¦  «         t          |¦  «        }g }| }||vr |                     |¦  «         |j        }||v° t          |¦  «        }|                     ||                     |¦  «        dd…         ¦  «         ||fS )z¿
    Calculates the 'path' of objects starting from 'from_object'
    to 'to_object', along with the index of the first common
    ancestor in the tree.

    Returns (index, list) tuple.
    z!No connecting path found between z and Néÿÿÿÿ)	Ú_rootr   ÚstrÚ_parentÚappendr,   r>   ÚextendÚindex)Úfrom_objectÚ	to_objectÚ
other_pathÚobjÚ
object_setÚ	from_pathrx   s          r   Ú_pathr   ¯  s1  € ð Ô˜IœOÒ+Ð+ÝÐ<Ý˜[Ñ)Ô)ñ*Ø,3ñ4Ý69¸)±n´nñEñ Fô Fð 	Fð €JØ
€CØ
Œ+Ð
!Ø×Ò˜#ÑÔÐØŒkˆð Œ+Ð
!ð ×Ò�cÑÔÐÝ�Z‘”€JØ€IØ
€CØ
�ZÐ
Ð
Ø×Ò˜ÑÔÐØŒkˆð �ZÐ
Ð
õ �	‰NŒN€EØ×Ò�Z 
× 0Ò 0°Ñ 5Ô 5Ð 9°rÐ 9Ô:Ñ;Ô;Ð;Ø�)ÐÐr   )Úorthonormalc                 ó’  — t          d„ |D ¦   «         ¦  «        st          d¦  «        ‚g }t          |¦  «        D ]~\  }}t          |¦  «        D ]&}|||                              ||         ¦  «        z  }Œ'|                     t          j        ¦  «        rt          d¦  «        ‚| 	                    |¦  «         Œ| rd„ |D ¦   «         }|S )aO  
    Takes a sequence of independent vectors and orthogonalizes them
    using the Gram - Schmidt process. Returns a list of
    orthogonal or orthonormal vectors.

    Parameters
    ==========

    vlist : sequence of independent vectors to be made orthogonal.

    orthonormal : Optional parameter
                  Set to True if the vectors returned should be
                  orthonormal.
                  Default: False

    Examples
    ========

    >>> from sympy.vector.coordsysrect import CoordSys3D
    >>> from sympy.vector.functions import orthogonalize
    >>> C = CoordSys3D('C')
    >>> i, j, k = C.base_vectors()
    >>> v1 = i + 2*j
    >>> v2 = 2*i + 3*j
    >>> orthogonalize(v1, v2)
    [C.i + 2*C.j, 2/5*C.i + (-1/5)*C.j]

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Gram-Schmidt_process

    c              3   ó@   K  — | ]}t          |t          ¦  «        V — Œd S )N)r   r   ©r   Úvecs     r   ú	<genexpr>z orthogonalize.<locals>.<genexpr>ð  s,   è è € Ð8Ð8¨3�z˜#�vÑ&Ô&Ð8Ð8Ð8Ð8Ð8Ð8r   z#Each element must be of Type Vectorz#Vector set not linearly independentc                 ó6   — g | ]}|                      ¦   «         ‘ŒS r   )Ú	normalizerƒ   s     r   ú
<listcomp>z!orthogonalize.<locals>.<listcomp>ÿ  s    € Ð>Ð>Ð>¨3�s—}’}‘”Ð>Ð>Ð>r   )
Úallr   r\   ÚrangeÚ
projectionÚequalsr   r   r   rv   )r€   ÚvlistÚortho_vlistrH   ÚtermrI   s         r   Úorthogonalizer�   Í  sê   € õF Ð8Ð8°%Ð8Ñ8Ô8Ñ8Ô8ð ?ÝÐ=Ñ>Ô>Ð>à€KÝ˜UÑ#Ô#ð !ð !‰ˆˆ4Ý�q‘”ð 	8ð 	8ˆAØ�K ”N×-Ò-¨e°A¬hÑ7Ô7Ñ7ˆDˆDð �;Š;•v”{Ñ#Ô#ð 	DÝÐBÑCÔCÐCØ×Ò˜4Ñ Ô Ð Ð àð ?Ø>Ð>°+Ð>Ñ>Ô>ˆàÐr   )NF)!Úsympy.vector.coordsysrectr   Úsympy.vector.deloperatorr   Úsympy.vector.scalarr   Úsympy.vector.vectorr   r   r=   r   r	   r
   Úsympy.core.functionr   Úsympy.core.singletonr   Úsympy.integrals.integralsr   Ú
sympy.corer   Úsympy.vector.dyadicr   r*   rM   rR   rW   rY   rb   rm   r'   r   r�   r   r   r   ú<module>rš      s�  ðØ 0Ð 0Ð 0Ð 0Ð 0Ð 0Ø (Ð (Ð (Ð (Ð (Ð (Ø *Ð *Ð *Ð *Ð *Ð *Ø 2Ð 2Ð 2Ð 2Ð 2Ð 2Ð 2Ð 2Ø =Ð =Ð =Ð =Ð =Ð =Ð =Ð =Ð =Ð =Ø $Ð $Ð $Ð $Ð $Ð $Ø "Ð "Ð "Ð "Ð "Ð "Ø /Ð /Ð /Ð /Ð /Ð /Ø Ð Ð Ð Ð Ð Ø &Ð &Ð &Ð &Ð &Ð &ðnð nð nð nðb.ð .ð .ðb)ð )ð )ð>1ð 1ð 1ðB2ð 2ð 2ðB0ð 0ð 0ðfBCð BCð BCðJ$ð $ð $ðNð ð ð< ',ð 4ð 4ð 4ð 4ð 4ð 4ð 4r   