U
    9%e                     @   s   d dl mZmZ 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 d dl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 G dd deZdd ZdS )    )Basicdiff)S)default_sort_key)Matrix)Integral	integrate)GeometryEntity)simplify)topological_sort)
CoordSys3DVectorParametricRegionparametric_region_listImplicitRegion)_get_coord_systemsc                       sD   e Zd ZdZ fddZedd Zedd Zedd	 Z	  Z
S )
ParametricIntegrala3  
    Represents integral of a scalar or vector field
    over a Parametric Region

    Examples
    ========

    >>> from sympy import cos, sin, pi
    >>> from sympy.vector import CoordSys3D, ParametricRegion, ParametricIntegral
    >>> from sympy.abc import r, t, theta, phi

    >>> C = CoordSys3D('C')
    >>> curve = ParametricRegion((3*t - 2, t + 1), (t, 1, 2))
    >>> ParametricIntegral(C.x, curve)
    5*sqrt(10)/2
    >>> length = ParametricIntegral(1, curve)
    >>> length
    sqrt(10)
    >>> semisphere = ParametricRegion((2*sin(phi)*cos(theta), 2*sin(phi)*sin(theta), 2*cos(phi)),                            (theta, 0, 2*pi), (phi, 0, pi/2))
    >>> ParametricIntegral(C.z, semisphere)
    8*pi

    >>> ParametricIntegral(C.j + C.k, ParametricRegion((r*cos(theta), r*sin(theta)), r, theta))
    0

    c                    s|  t |}t|dkrtd}nt|dkr0tntt|} jdkrLtjS |	 }|
 }|}tj}tt jD ]}	|||	  j|	  7 }qtt|dkrtt jD ]}	|||	  j|	 }q jdkrD jd }
t||
} j|
 d  j|
 d  }}t|tr t||}nt| | }t||
||f}n jdkr|  j j\}}t||}t||}t||}t|tr||}n||  }t|} j| d  j| d  }} j| d  j| d  }}t||||f|||f}nP|  j j}t j| }t|| } fdd|D }t|f| }t|tsh|S t | | S d S )Nr   C      c                    s*   g | ]"}| j | d   j | d fqS )r   r   )limits).0varparametricregion U/var/www/html/Darija-Ai-API/env/lib/python3.8/site-packages/sympy/vector/integrals.py
<listcomp>k   s     z.ParametricIntegral.__new__.<locals>.<listcomp>) r   lenr   
ValueErrornextiter
dimensionsr   ZZerobase_vectorsbase_scalarsr   zerorangeZ
definitionsubs
parametersr   r   
isinstancer
   dotZ	magnituder   _bounds_casecrossr   ZjacobianZdetr   super__new__)clsfieldr   Z	coord_setZ	coord_sysr#   r$   ZparametricfieldriZ	parameterZr_difflowerupperZ	integrandresultuvZr_uZr_vZnormal_vectorZlower_uZupper_uZlower_vZupper_v	variablesZcoeffl	__class__r   r   r.   +   sZ    





zParametricIntegral.__new__c                    sz   t | }g }|D ]H| d  | d     | fdd|D  q|sf|S t||ftdS d S )Nr   r   c                 3   s6   | ].}|kr  |hs& |hr|fV  qd S )N)
issuperset)r   qZlower_ppZupper_pr   r   	<genexpr>   s
      z2ParametricIntegral._bounds_case.<locals>.<genexpr>)key)listkeysZatomsextendr   r   )r/   r(   r   VEr   r>   r   r+   s   s    zParametricIntegral._bounds_casec                 C   s
   | j d S )Nr   argsselfr   r   r   r0      s    zParametricIntegral.fieldc                 C   s
   | j d S )Nr   rG   rI   r   r   r   r      s    z#ParametricIntegral.parametricregion)__name__
__module____qualname____doc__r.   classmethodr+   propertyr0   r   __classcell__r   r   r:   r   r      s   H

r   c                 G   s   t |dkrt|d tr(t| |d S t|d trPt|d d }t| |S t|d trt|d }d}|D ]}|t| |7 }qr|S t| f| S )a  
    Compute the integral of a vector/scalar field
    over a a region or a set of parameters.

    Examples
    ========
    >>> from sympy.vector import CoordSys3D, ParametricRegion, vector_integrate
    >>> from sympy.abc import x, y, t
    >>> C = CoordSys3D('C')

    >>> region = ParametricRegion((t, t**2), (t, 1, 5))
    >>> vector_integrate(C.x*C.i, region)
    12

    Integrals over some objects of geometry module can also be calculated.

    >>> from sympy.geometry import Point, Circle, Triangle
    >>> c = Circle(Point(0, 2), 5)
    >>> vector_integrate(C.x**2 + C.y**2, c)
    290*pi
    >>> triangle = Triangle(Point(-2, 3), Point(2, 3), Point(0, 5))
    >>> vector_integrate(3*C.x**2*C.y*C.i + C.j, triangle)
    -8

    Integrals over some simple implicit regions can be computed. But in most cases,
    it takes too long to compute over them. This is due to the expressions of parametric
    representation becoming large.

    >>> from sympy.vector import ImplicitRegion
    >>> c2 = ImplicitRegion((x, y), (x - 2)**2 + (y - 1)**2 - 9)
    >>> vector_integrate(1, c2)
    6*pi

    Integral of fields with respect to base scalars:

    >>> vector_integrate(12*C.y**3, (C.y, 1, 3))
    240
    >>> vector_integrate(C.x**2*C.z, C.x)
    C.x**3*C.z/3
    >>> vector_integrate(C.x*C.i - C.y*C.k, C.x)
    (Integral(C.x, C.x))*C.i + (Integral(-C.y, C.x))*C.k
    >>> _.doit()
    C.x**2/2*C.i + (-C.x*C.y)*C.k

    r   r   )	r   r)   r   r   r   r   vector_integrater	   r   )r0   regionZregions_listr5   regr   r   r   rR      s    .
rR   N)Z
sympy.corer   r   Zsympy.core.singletonr   Zsympy.core.sortingr   Zsympy.matricesr   Zsympy.integralsr   r   Zsympy.geometry.entityr	   Zsympy.simplify.simplifyr
   Zsympy.utilities.iterablesr   Zsympy.vectorr   r   r   r   r   Zsympy.vector.operatorsr   r   rR   r   r   r   r   <module>   s    