
    g1%                        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dS )    N)Expr)sympifySpreorder_traversal)
CoordSys3D)Vector	VectorMul	VectorAddCrossDot)
Derivative)Add)Mulc                     t          |           }t                      }|D ]@}t          |t                    r)|                    |           |                                 At          |          S N)r   set
isinstancer   addskip	frozenset)exprgretis       R/var/www/html/ai-engine/env/lib/python3.11/site-packages/sympy/vector/operators.py_get_coord_systemsr      sb    4  A
%%C  a$$ 	GGAJJJFFHHHS>>    c                     t          j        d           }| j        D ]}|t          |          xx         |z  cc<    t	          |                                          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)      sc    ..AY & &	
Q

   A%    

r   c                       e Zd ZdZd Zd ZdS )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                 \    t          |          }t          j        | |          }||_        |S r   r   r   __new___exprclsr   objs      r   r.   zGradient.__new__+   *    t}}l3%%	
r   c                 .    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dS )
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                 \    t          |          }t          j        | |          }||_        |S r   r-   r0   s      r   r.   zDivergence.__new__D   r3   r   c                 .    t          | j        d          S r5   )
divergencer/   r9   s     r   r7   zDivergence.doitJ   s    $*40000r   Nr<   r!   r   r   rB   rB   5   s<           1 1 1 1 1r   rB   c                       e Zd ZdZd Zd ZdS )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                 \    t          |          }t          j        | |          }||_        |S r   r-   r0   s      r   r.   zCurl.__new__]   r3   r   c                 .    t          | j        d          S r5   )curlr/   r9   s     r   r7   z	Curl.doitc   s    DJT****r   Nr<   r!   r   r   rG   rG   N   s<           + + + + +r   rG   Tc                 F   t          |           }t          |          dk    rt          j        S t          |          dk    r`t	          t          |                    }|                                \  }}}|                                \  }}}|                                \  }	}
}| 	                    |          }| 	                    |          }| 	                    |          }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|                                S |S t          | t          t          f          roddlm 	 t	          t          |                    fd| j        D             }n# t$          $ r
 | j        }Y nw xY wt          j        fd|D                       S t          | t(          t*          f          rd | j        D             d         }t)          j        d | j        D                       }t-          t/          |          |                                          |t1          |          z  z   }r|                                S |S t          | t,          t2          t4          f          rt3          |           S t3          |           )	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      expressc                 ,    g | ]} |d           S )T	variablesr!   ).0r   csrN   s     r   
<listcomp>zcurl.<locals>.<listcomp>   s*    JJJ12666JJJr   c              3   :   K   | ]}t          |           V  dS r6   N)rJ   rR   r   r7   s     r   	<genexpr>zcurl.<locals>.<genexpr>   s0      %G%GQd14&8&8&8%G%G%G%G%G%Gr   c                 V    g | ]&}t          |t          t          t          f          $|'S r!   r   r   r   r+   rR   r   s     r   rT   zcurl.<locals>.<listcomp>   .    WWWAjVUH<U.V.VWaWWWr   c              3   ^   K   | ](}t          |t          t          t          f          $|V  )d S r   rZ   r[   s     r   rX   zcurl.<locals>.<genexpr>   :      !g!gjVUZ\dLe>f>f!g!!g!g!g!g!g!gr   r6   )r   lenr   zeronextiterbase_vectorsbase_scalarslame_coefficientsdotr   r7   r   r   r
   sympy.vectorrN   r%   
ValueErrorfromiterr   r	   r   r8   rJ   rG   r+   )vectr7   	coord_sysr   jkxyzh1h2h3vectxvectyvectzoutvecr%   vectorscalarresrS   rN   s    `                  @@r   rJ   rJ   g   s9   < #4((I
9~~{	Y1		i))	((**1a((**1a0022
B:ebj!,,ebj!,,-01257"W> 	>:ebj!,,ebj!,,-01257"W> 	>:ebj!,,ebj!,,-01257"W> 	>  	!;;== dS),-- 	,,,,,,!$y//**JJJJJ	JJJ ! ! !y!%%G%G%G%G$%G%G%GGGGsI.// 
	WWWWWXYZF\!g!gTY!g!g!gggF((&1166886$vTXBYBYBY;YYC "xxzz!JudH566 	::t**s   	0G: :HHc                 H   t          |           }t          |          dk    rt          j        S t          |          dk    r?t	          | t
          t          t          f          rt          |           S t          t          |                    }|                                \  }}}|                                \  }}}|                                \  }	}
}t          |                     |          ||
|          |	|
z  |z  z  }t          |                     |          |||	          |	|
z  |z  z  }t          |                     |          ||	|
          |	|
z  |z  z  }||z   |z   }r|                                S |S t	          | t"          t$          f          r%t#          j        fd| j        D                       S t	          | t*          t,          f          rd | j        D             d         }t+          j        d | j        D                       }t/          |t1          |                    |t3          |          z  z   }r|                                S |S t	          | t
          t          t          f          rt          |           S t          |           )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   :   K   | ]}t          |           V  dS rV   )rE   rW   s     r   rX   zdivergence.<locals>.<genexpr>   s0      LLQ
14 8 8 8LLLLLLr   c                 V    g | ]&}t          |t          t          t          f          $|'S r!   rZ   r[   s     r   rT   zdivergence.<locals>.<listcomp>   r\   r   c              3   ^   K   | ](}t          |t          t          t          f          $|V  )d S r   rZ   r[   s     r   rX   zdivergence.<locals>.<genexpr>   r^   r   r6   )r   r_   r   Zeror   r   rG   r+   rB   ra   rb   rc   rd   re   _diff_conditionalrf   r7   r   r
   ri   r%   r   r	   r   r8   rE   )rj   r7   rk   r   rl   rm   rn   ro   rp   rq   rr   rs   vxvyvzrz   rx   ry   s    `                r   rE   rE      sx   < #4((I
9~~v	Y1		dUD(344 	$d###i))	((**1a((**1a0022
Btxx{{Ar266R"txx{{Ar266R"txx{{Ar266R"2gl 	88::
dS),-- 	#<LLLL$)LLLLLLsI.// 
	#WWWWWXYZF\!g!gTY!g!g!gggFfhv..//&FQU9V9V9V2VVC "xxzz!JudH566 	#d###T"""r   c                 ^    t                     }t          |          dk    rt          j        S t          |          dk    rt	          t          |                    }|                                \  }}}|                                \  }}}|                                \  }	}
}t           |	          |z  }t           |
          |z  }t           |          |z  }|r#||z  ||z  z   ||z  z   
                                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   4   K   | ]}t          |          V  d S r   r8   r[   s     r   rX   zgradient.<locals>.<genexpr>$  s(      %M%Mahqkk%M%M%M%M%M%Mr   c              3   B   K   | ]}|z  t          |          z  V  d S r   r   )rR   r   scalar_fields     r   rX   zgradient.<locals>.<genexpr>'  s3      %P%PlQ&6!&D%P%P%P%P%P%Pr   )r   r_   r   r`   ra   rb   re   rc   rd   r   r7   r   r   r
   ri   r%   r   r	   r)   r+   )r   r7   rk   rq   rr   rs   r   rl   rm   rn   ro   rp   r   r   r   ss   `               r   r8   r8      s   : #<00I
9~~{	Y1		i))	0022
B((**1a((**1aa((2-a((2-a((2- 	5FR!VOb1f,22444AvQa''lS)$455 	N%%M%M<;L%M%M%MMMMlS)$455 	Q,\::A%%P%P%P%Pa%P%P%PPPP%%%r   c                       e Zd ZdZd Zd ZdS )	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                 \    t          |          }t          j        | |          }||_        |S r   r-   r0   s      r   r.   zLaplacian.__new__:  r3   r   c                 .    ddl m}  || j                  S )Nr   )	laplacian)sympy.vector.functionsr   r/   )r:   r;   r   s      r   r7   zLaplacian.doit@  s&    444444y$$$r   Nr<   r!   r   r   r   r   +  s<           % % % % %r   r   c                     ddl m}  || |j        d          }||z  |z  }|rt          ||          n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   TrP   )r   rN   systemr   r   r   )r   base_scalarcoeff_1coeff_2rN   new_exprargs          r   r   r   E  sZ     /.....wt[/4@@@H
G
h
&C+.::c;'''AF: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      s                   5 5 5 5 5 5 5 5 5 5 0 0 0 0 0 0 H H H H H H H H H H H H H H * * * * * *                / / / / /t / / /21 1 1 1 1 1 1 12+ + + + +4 + + +2H H H HV@# @# @# @#F3& 3& 3& 3&l% % % % % % % %4
; 
; 
; 
; 
;r   