
    wg1%                         d dl Z d dlmZ d dlmZmZ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lmZ d dlmZ d	 Zd
 Z G d de      Z G d de      Z G d de      ZddZddZddZ G d de      Zd Zy)    N)Expr)sympifySpreorder_traversal)
CoordSys3D)Vector	VectorMul	VectorAddCrossDot)
Derivative)Add)Mulc                     t        |       }t               }|D ]4  }t        |t              s|j	                  |       |j                          6 t        |      S N)r   set
isinstancer   addskip	frozenset)exprgretis       [/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/sympy/vector/operators.py_get_coord_systemsr      sL    4 A
%C a$GGAJFFH S>    c                     t        j                  d       }| j                  D ]  }|t        |      xx   |z  cc<    t	        |j                               S )Nc                  "    t         j                  S r   )r   One r   r   <lambda>z._split_mul_args_wrt_coordsys.<locals>.<lambda>   s
     r   )collectionsdefaultdictargsr   listvalues)r   dr   s      r   _split_mul_args_wrt_coordsysr)      sL    .AYY &	
Q
 A% &
r   c                       e Zd ZdZd Zd Zy)Gradientz
    Represents unevaluated Gradient.

    Examples
    ========

    >>> from sympy.vector import CoordSys3D, Gradient
    >>> R = CoordSys3D('R')
    >>> s = R.x*R.y*R.z
    >>> Gradient(s)
    Gradient(R.x*R.y*R.z)

    c                 V    t        |      }t        j                  | |      }||_        |S r   r   r   __new___exprclsr   objs      r   r.   zGradient.__new__+   '    t}ll3%	
r   c                 0    t        | j                  d      S NTdoit)gradientr/   selfhintss     r   r7   zGradient.doit1   s    

..r   N__name__
__module____qualname____doc__r.   r7   r!   r   r   r+   r+      s    /r   r+   c                       e Zd ZdZd Zd Zy)
Divergencea  
    Represents unevaluated Divergence.

    Examples
    ========

    >>> from sympy.vector import CoordSys3D, Divergence
    >>> R = CoordSys3D('R')
    >>> v = R.y*R.z*R.i + R.x*R.z*R.j + R.x*R.y*R.k
    >>> Divergence(v)
    Divergence(R.y*R.z*R.i + R.x*R.z*R.j + R.x*R.y*R.k)

    c                 V    t        |      }t        j                  | |      }||_        |S r   r-   r0   s      r   r.   zDivergence.__new__D   r3   r   c                 0    t        | j                  d      S r5   )
divergencer/   r9   s     r   r7   zDivergence.doitJ   s    $**400r   Nr<   r!   r   r   rB   rB   5   s    1r   rB   c                       e Zd ZdZd Zd Zy)Curla  
    Represents unevaluated Curl.

    Examples
    ========

    >>> from sympy.vector import CoordSys3D, Curl
    >>> R = CoordSys3D('R')
    >>> v = R.y*R.z*R.i + R.x*R.z*R.j + R.x*R.y*R.k
    >>> Curl(v)
    Curl(R.y*R.z*R.i + R.x*R.z*R.j + R.x*R.y*R.k)

    c                 V    t        |      }t        j                  | |      }||_        |S r   r-   r0   s      r   r.   zCurl.__new__]   r3   r   c                 0    t        | j                  d      S r5   )curlr/   r9   s     r   r7   z	Curl.doitc   s    DJJT**r   Nr<   r!   r   r   rG   rG   N   s    +r   rG   c           	         t        |       }t        |      dk(  rt        j                  S t        |      dk(  r(t	        t        |            }|j                         \  }}}|j                         \  }}}|j                         \  }	}
}| j                  |      }| j                  |      }| j                  |      }t        j                  }|t        ||z  |      t        ||
z  |      z
  |z  |
|z  z  z  }|t        ||	z  |      t        ||z  |      z
  |z  |	|z  z  z  }|t        ||
z  |      t        ||	z  |      z
  |z  |
|	z  z  z  }r|j                         S |S t        | t        t        f      r[ddlm} 	 t	        t        |            }| j"                  D cg c]  } |||d       }}t        j&                  fd|D              S t        | t(        t*        f      r| j"                  D cg c]   }t        |t        t,        t.        f      s|" c}d   }t)        j&                  d | j"                  D              }t-        t1        |      |      j                         |t3        |      z  z   }r|j                         S |S t        | t,        t4        t.        f      rt5        |       S t5        |       c c}w # t$        $ r | j"                  }Y )w xY wc c}w )	ao  
    Returns the curl of a vector field computed wrt the base scalars
    of the given coordinate system.

    Parameters
    ==========

    vect : Vector
        The vector operand

    doit : bool
        If True, the result is returned after calling .doit() on
        each component. Else, the returned expression contains
        Derivative instances

    Examples
    ========

    >>> from sympy.vector import CoordSys3D, curl
    >>> R = CoordSys3D('R')
    >>> v1 = R.y*R.z*R.i + R.x*R.z*R.j + R.x*R.y*R.k
    >>> curl(v1)
    0
    >>> v2 = R.x*R.y*R.z*R.i
    >>> curl(v2)
    R.x*R.y*R.j + (-R.x*R.z)*R.k

    r      expressT	variablesc              3   8   K   | ]  }t        |         ywr6   N)rJ   .0r   r7   s     r   	<genexpr>zcurl.<locals>.<genexpr>   s     %GQd14&8&8%G   c              3   X   K   | ]"  }t        |t        t        t        f      r| $ y wr   r   r   r   r+   rT   r   s     r   rU   zcurl.<locals>.<genexpr>   "     !gjVUZ\dLe>f!!g    **r6   )r   lenr   zeronextiterbase_vectorsbase_scalarslame_coefficientsdotr   r7   r   r   r
   sympy.vectorrN   r%   
ValueErrorfromiterr   r	   r   r+   r8   rJ   rG   )vectr7   	coord_sysr   jkxyzh1h2h3vectxvectyvectzoutvecrN   csr%   vectorscalarress    `                    r   rJ   rJ   g   s   < #4(I
9~{{	Y1	i)	((*1a((*1a002
B:ebj!,ebj!,-01257"W> 	>:ebj!,ebj!,-01257"W> 	>:ebj!,ebj!,-01257"W> 	> ;;= dS),-,!$y/*@D		J126JJ %%%G$%GGGsI./!%WAjVUH<U.VaWXYZF\\!gTYY!ggF(&16686$vTXBY;YYCxxz!JudH56:t* K !yy! Xs0   ?"K !K3K 7 K"K"K KKc           	         t        |       }t        |      dk(  rt        j                  S t        |      dk(  rt	        | t
        t        t        f      rt        |       S t        t        |            }|j                         \  }}}|j                         \  }}}|j                         \  }	}
}t        | j                  |      ||
|      |	|
z  |z  z  }t        | j                  |      |||	      |	|
z  |z  z  }t        | j                  |      ||	|
      |	|
z  |z  z  }||z   |z   }r|j!                         S |S t	        | t"        t$        f      r(t#        j&                  fd| j(                  D              S t	        | t*        t,        f      r| j(                  D cg c]   }t	        |t.        t
        t        f      s|" c}d   }t+        j&                  d | j(                  D              }t1        |t3        |            |t5        |      z  z   }r|j!                         S |S t	        | t
        t        t        f      rt        |       S t        |       c c}w )a  
    Returns the divergence of a vector field computed wrt the base
    scalars of the given coordinate system.

    Parameters
    ==========

    vector : Vector
        The vector operand

    doit : bool
        If True, the result is returned after calling .doit() on
        each component. Else, the returned expression contains
        Derivative instances

    Examples
    ========

    >>> from sympy.vector import CoordSys3D, divergence
    >>> R = CoordSys3D('R')
    >>> v1 = R.x*R.y*R.z * (R.i+R.j+R.k)

    >>> divergence(v1)
    R.x*R.y + R.x*R.z + R.y*R.z
    >>> v2 = 2*R.y*R.z*R.j
    >>> divergence(v2)
    2*R.z

    r   rL   c              3   8   K   | ]  }t        |         ywrR   )rE   rS   s     r   rU   zdivergence.<locals>.<genexpr>   s     LQ
14 8 8LrV   c              3   X   K   | ]"  }t        |t        t        t        f      r| $ y wr   rX   rY   s     r   rU   zdivergence.<locals>.<genexpr>   rZ   r[   r6   )r   r\   r   Zeror   r   rG   r+   rB   r^   r_   r`   ra   rb   _diff_conditionalrc   r7   r   r
   rf   r%   r   r	   r   r   r8   rE   )rg   r7   rh   r   ri   rj   rk   rl   rm   rn   ro   rp   vxvyvzrx   rv   rw   s    `                r   rE   rE      s   < #4(I
9~vv	Y1	dUD(34d##i)	((*1a((*1a002
Btxx{Ar26R"txx{Ar26R"txx{Ar26R"2gl88:
dS),-<<L$))LLLsI./!%WAjVUH<U.VaWXYZF\\!gTYY!ggFfhv./&FQU9V2VVCxxz!JudH56d##T"" Xs     IIc                     t               }t        |      dk(  rt        j                  S t        |      dk(  rt	        t        |            }|j                         \  }}}|j                         \  }}}|j                         \  }	}
}t         |	      |z  }t         |
      |z  }t         |      |z  }|r||z  ||z  z   ||z  z   j                         S ||z  ||z  z   ||z  z   S t         t        t        f      r&t        j                  d  j                  D              S t         t         t"        f      r)t%               }t        j                   fd|D              S t'               S )a  
    Returns the vector gradient of a scalar field computed wrt the
    base scalars of the given coordinate system.

    Parameters
    ==========

    scalar_field : SymPy Expr
        The scalar field to compute the gradient of

    doit : bool
        If True, the result is returned after calling .doit() on
        each component. Else, the returned expression contains
        Derivative instances

    Examples
    ========

    >>> from sympy.vector import CoordSys3D, gradient
    >>> R = CoordSys3D('R')
    >>> s1 = R.x*R.y*R.z
    >>> gradient(s1)
    R.y*R.z*R.i + R.x*R.z*R.j + R.x*R.y*R.k
    >>> s2 = 5*R.x**2*R.z
    >>> gradient(s2)
    10*R.x*R.z*R.i + 5*R.x**2*R.k

    r   rL   c              3   2   K   | ]  }t        |        y wr   r8   rY   s     r   rU   zgradient.<locals>.<genexpr>$  s     %Mahqk%Ms   c              3   @   K   | ]  }|z  t        |      z    y wr   r   )rT   r   scalar_fields     r   rU   zgradient.<locals>.<genexpr>'  s     %PlQ&6!&D%Ps   )r   r\   r   r]   r^   r_   rb   r`   ra   r   r7   r   r   r
   rf   r%   r   r	   r)   r+   )r   r7   rh   rn   ro   rp   r   ri   rj   rk   rl   rm   r~   r   r   ss   `               r   r8   r8      sW   : #<0I
9~{{	Y1	i)	002
B((*1a((*1aa(2-a(2-a(2-FR!VOb1f,2244AvQa''lS)$45%%%M<;L;L%MMMlS)$45,\:A%%%Pa%PPP%%r   c                       e Zd ZdZd Zd Zy)	Laplacianz
    Represents unevaluated Laplacian.

    Examples
    ========

    >>> from sympy.vector import CoordSys3D, Laplacian
    >>> R = CoordSys3D('R')
    >>> v = 3*R.x**3*R.y**2*R.z**3
    >>> Laplacian(v)
    Laplacian(3*R.x**3*R.y**2*R.z**3)

    c                 V    t        |      }t        j                  | |      }||_        |S r   r-   r0   s      r   r.   zLaplacian.__new__:  r3   r   c                 2    ddl m}  || j                        S )Nr   )	laplacian)sympy.vector.functionsr   r/   )r:   r;   r   s      r   r7   zLaplacian.doit@  s    4$$r   Nr<   r!   r   r   r   r   +  s    %r   r   c                     ddl m}  || |j                  d      }||z  |z  }|rt        ||      S t        j
                  S )z
    First re-expresses expr in the system that base_scalar belongs to.
    If base_scalar appears in the re-expressed form, differentiates
    it wrt base_scalar.
    Else, returns 0
    r   rM   TrO   )r   rN   systemr   r   r|   )r   base_scalarcoeff_1coeff_2rN   new_exprargs          r   r}   r}   E  sB     /t[//4@H
G
h
&C+.:c;':AFF:r   )T)r#   sympy.core.exprr   
sympy.corer   r   r   sympy.vector.coordsysrectr   sympy.vector.vectorr   r	   r
   r   r   sympy.core.functionr   sympy.core.addr   sympy.core.mulr   r   r)   r+   rB   rG   rJ   rE   r8   r   r}   r!   r   r   <module>r      sv       5 5 0 H H *  /t /21 12+4 +2HV@#F3&l% %4
;r   