
    \h^<                         S SK Jr  S SKJr  S SKJr  S SKJrJr  S SK	J
r
JrJr  S SKJr  S SKJr  S SKJr  S S	KJr  S S
KJr  SS jrS rS rS rS rS rS rS rS rSS.S jr g)    )
CoordSys3D)Del)
BaseScalar)Vector
BaseVector)gradientcurl
divergence)diff)S)	integrate)sympify)DyadicNFc           
      N   U S[         R                  4;   a  U $ [        U[        5      (       d  [	        S5      e[        U [         5      (       a  Ub  [        S5      eU(       at  U R                  [        [        5       Vs1 s H  oDR                  iM     snU1-
  n0 nU H#  nUR                  UR                  U5      5        M%     U R                  U5      n [         R                  nU R                  5       n	U	 HD  nXA:w  a5  UR                  U5      X   R                  U5      -  n
U[!        X5      -  nM=  XU   -  nMF     U$ [        U ["        5      (       a  Uc  Un[        U[        5      (       d  [	        S5      e["        R                  nUnU R$                  R'                  5        HB  u  pU[)        XUS9[)        UR*                  S   XS9[)        UR*                  S   X,S9-  -  -  nMD     U$ Ub  [        S5      eU(       a  [-        5       n[/        U 5      n U R                  [        5       H0  nUR                  U:w  d  M  UR1                  UR                  5        M2     0 nU H#  nUR                  UR                  U5      5        M%     U R                  U5      $ U $ s  snf )a  
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                         instancezJsystem2 should not be provided for                                 VectorszCsystem2 should be a CoordSys3D                             instance	variables   )r   zero
isinstancer   	TypeError
ValueErroratomsr   r   systemupdate
scalar_mapsubsseparaterotation_matrix	to_matrixmatrix_to_vectorr   
componentsitemsexpressargssetr   add)exprr   system2r   xsystem_list	subs_dictfoutvecpartstempoutdyadvarkv
system_sets                   N/var/www/auris/envauris/lib/python3.13/site-packages/sympy/vector/functions.pyr#   r#      sw   ` 6;;fj)) " # 	# $ ) * *  .2ZZ
J-OP-O88-OPTZS[[KI   f!56 !99Y'DA{--a0583E3Ea3HH*488("  	D&	!	!?G':.. & ' '++OO))+DAS9 FB GCDE FG ,
   ) * *J4=DZZ
+88v%NN188, , I  f!56  99Y''_ Qs   ?J"c                 `   SSK Jn  U" U 5      n[        U5      S:  a  [        [	        U5      5      n[        XSS9n UR                  5       u  pEnUR                  5       u  pxn	[        R                  " X5      [        X5      -  n
U
[        R                  " X5      [        X5      -  -  n
U
[        R                  " X5      [        X	5      -  -  n
U
S:X  a%  [        U [        5      (       a  [        R                  n
U
$ [        U [        5      (       a  [        R                  $ [        R                  $ )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.operatorsr7   lennextiterr#   base_vectorsbase_scalarsr   dotr   r   r   r   Zero)fielddirection_vectorr7   	coord_sysijr2   r)   yzouts              r5   directional_derivativerH   ~   s    : :"5)I
9~i)	D9((*a((*ajj)-U>vzz*.e??vzz*.e??!8
5&11++C
	E6	"	"{{vv    c                     [        5       nU R                  (       a7  [        [        U 5      5      [	        [	        U 5      5      -
  R                  5       $ UR                  U" U 5      5      R                  5       $ )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	   doitr>   )r'   delops     r5   	laplacianrN      sU    2 EE~~D)*T$t*-==CCEE99U4[!&&((rI   c                     [        U [        5      (       d  [        S5      eU [        R                  :X  a  g[	        U 5      R                  5       [        R                  :H  $ )ac  
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r@   s    r5   is_conservativerS      sH    4 eV$$233;!V[[00rI   c                     [        U [        5      (       d  [        S5      eU [        R                  :X  a  g[	        U 5      R                  5       [        R                  L $ )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

rP   T)r   r   r   r   r
   rQ   r   r?   rR   s    r5   is_solenoidalrU      sI    4 eV$$233e%%'16611rI   c                    [        U 5      (       d  [        S5      eU [        R                  :X  a  [        R
                  $ [        U[        5      (       d  [        S5      e[        XSS9n UR                  5       nUR                  5       n[        U R                  US   5      US   5      n[        USS 5       H>  u  pV[        XCUS-      5      nU R                  U5      U-
  nU[        XsUS-      5      -  nM@     U$ )ao  
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)rS   r   r   r   r   r?   r   r   r   r#   r<   r=   r   r>   	enumerater   )r@   rB   
dimensionsscalarstemp_functionrC   dimpartial_diffs           r5   scalar_potentialr^     s    > 5!!455vv i,,899E5E'')J$$&Geii
16
CMJqrN+M1q5>:yy~4<Q@@ , rI   c                    [        U[        5      (       d  [        S5      e[        U [        5      (       a  [	        X5      nOU nUR
                  n[        UR                  U5      USS9n[        UR                  U5      USS9n0 n0 n	UR                  5       n
[        UR                  5       5       H1  u  pUR                  U5      XU   '   UR                  U5      XU   '   M3     UR                  U	5      UR                  U5      -
  $ )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

rW   Tr   )r   r   r   r   r^   originr#   position_wrtr=   rX   r<   r>   r   )r@   rB   point1point2	scalar_fnr`   	position1	position2
subs_dict1
subs_dict2rZ   rC   r)   s                r5   scalar_potential_differenceri   C  s    Z i,,899%  $U6	 	F++F3Y"&(I++F3Y"&(I JJ$$&G)0023!"y!1
1:!"y!1
1: 4 >>*%	z(BBBrI   c                     [         R                  nUR                  5       n[        U 5       H  u  pEX%X4   -  -  nM     U$ )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   r<   rX   )matrixr   r-   vectsrC   r)   s         r5   r    r      s@    @ [[F!E&!eh, "MrI   c                    U R                   UR                   :w  a&  [        S[        U 5      -   S-   [        U5      -   5      e/ nUnUR                  b,  UR	                  U5        UR                  nUR                  b  M,  UR	                  U5        [        U5      n/ nU nX4;  a$  UR	                  U5        UR                  nX4;  a  M$  [        U5      nUR                  X"R                  U5      SS2   5        Xe4$ )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%   r9   extendindex)from_object	to_object
other_pathobj
object_set	from_pathrt   s          r5   _pathr{     s    IOO+<[)*,3469)nE F 	F J
C
++
!#kk ++
! cZJI
C

kk 
 	NEZ 0 0 5 9r 9:;rI   )orthonormalc                    [        S U 5       5      (       d  [        S5      e/ n[        U5       Ho  u  p4[        U5       H  nXBU   R	                  X   5      -  nM     UR                  [        R                  5      (       a  [        S5      eUR                  U5        Mq     U (       a  U Vs/ s H  ofR                  5       PM     nnU$ s  snf )a  
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   B   #    U  H  n[        U[        5      v   M     g 7f)N)r   r   ).0vecs     r5   	<genexpr> orthogonalize.<locals>.<genexpr>  s     8%3z#v&&%s   z#Each element must be of Type Vectorz#Vector set not linearly independent)allr   rX   range
projectionequalsr   r   r   rr   	normalize)r|   vlistortho_vlistrC   termrD   r   s          r5   orthogonalizer     s    F 8%888=>>KU#qAN--eh77D 
 ;;v{{##BCC4  $ 2=>+3}}+> ?s   .C)NF)!sympy.vector.coordsysrectr   sympy.vector.deloperatorr   sympy.vector.scalarr   sympy.vector.vectorr   r   r8   r   r	   r
   sympy.core.functionr   sympy.core.singletonr   sympy.integrals.integralsr   
sympy.corer   sympy.vector.dyadicr   r#   rH   rN   rS   rU   r^   ri   r    r{   r    rI   r5   <module>r      sg    0 ( * 2 = = $ " /  &nb.b)>1B2B0fBCJ$N< ', 4rI   