
    wg                         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e      Zd Zy)    )Basicdiff)S)default_sort_key)Matrix)Integral	integrate)GeometryEntity)simplify)topological_sort)
CoordSys3DVectorParametricRegionparametric_region_listImplicitRegion)_get_coord_systemsc                   R     e Zd ZdZ fdZed        Zed        Zed        Z	 x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                 L   t        |      }t        |      dk(  rt        d      }n(t        |      dkD  rt        t	        t        |            }|j                  dk(  rt        j                  S |j                         }|j                         }|}t        j                  }t        t        |j                              D ]  }	|||	   |j                  |	   z  z  } t        |      dk7  rEt        t        |j                              D ]$  }	|j                  ||	   |j                  |	         }& |j                  dk(  r|j                   d   }
t#        ||
      }|j$                  |
   d   |j$                  |
   d   }}t'        |t              rt)        |j+                  |            }nt)        |j-                         |z        }t/        ||
||f      }n|j                  dk(  r| j1                  |j                   |j$                        \  }}t#        ||      }t#        ||      }t)        |j3                  |            }t'        |t              r|j+                  |      }n||j-                         z  }t)        |      }|j$                  |   d   |j$                  |   d   }}|j$                  |   d   |j$                  |   d   }}t/        ||||f|||f      }n| j1                  |j                   |j$                        }t5        |j                        j7                  |      j9                         }t)        ||z        }|D cg c]'  }||j$                  |   d   |j$                  |   d   f) }}t/        |g| }t'        |t:              s|S t<        | }  | ||      S c c}w )Nr   C      ) r   lenr   
ValueErrornextiter
dimensionsr   Zerobase_vectorsbase_scalarsr   zerorange
definitionsubs
parametersr   limits
isinstancer   dot	magnituder	   _bounds_casecrossr   jacobiandetr   super__new__)clsfieldparametricregion	coord_set	coord_sysr   r    parametricfieldri	parameterr_difflowerupper	integrandresultuvr_ur_vnormal_vectorlower_uupper_ulower_vupper_v	variablescoeffvarl	__class__s                                [/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/sympy/vector/integrals.pyr/   zParametricIntegral.__new__+   s   &u-	y>Q"3I^aT)_-I&&!+66M --/ --/KKs+6678 	@Aa!1!<!<Q!???A	@ y>Q3/::;< h"1"6"6|AHXHcHcdeHf"gh &&!+(33A6I!Y'F+229=a@BRBYBYZcBdefBg5E/62$VZZ%@A	$V%5%5%7%GH	y9eU*CDF((A-##$4$?$?AQAXAXYDAqq!*Cq!*C$SYYs^4M/62+//>	+M,C,C,EE	 +I/66q9!<>N>U>UVW>XYZ>[WG/66q9!<>N>U>UVW>XYZ>[WGy1gw*?!WgAVWF (()9)D)DFVF]F]^I+667@@KOOQE !67Idmn]`#'..s3A68H8O8OPS8TUV8WXnAny-1-F&(+M7?3/?@@ os   ,N!c                    t        |j                               }g }|D ]N  |   d   |   d   j                         j                         |j                  fd|D               P |s|S t	        ||ft
              S )Nr   r   c              3   z   K   | ]2  }|k7  s	j                  |h      sj                  |h      r|f 4 y w)N)
issuperset).0qlower_ppupper_ps     rL   	<genexpr>z2ParametricIntegral._bounds_case.<locals>.<genexpr>   sC      K!q&((!-1C1CQC1H V Ks   
;-;)key)listkeysatomsextendr   r   )r0   r%   r&   VErR   rS   rT   s        @@@rL   r*   zParametricIntegral._bounds_cases   s      	KAQilGQilGmmoGmmoGHH KQ K K	K #QF0@AA    c                      | j                   d   S )Nr   argsselfs    rL   r1   zParametricIntegral.field       yy|r]   c                      | j                   d   S )Nr   r_   ra   s    rL   r2   z#ParametricIntegral.parametricregion   rc   r]   )__name__
__module____qualname____doc__r/   classmethodr*   propertyr1   r2   __classcell__)rK   s   @rL   r   r      sN    8FAP B B&    r]   r   c                 P   t        |      dk(  rt        |d   t              rt        | |d         S t        |d   t              rt        |d         d   }t        | |      S t        |d   t              r(t        |d         }d}|D ]  }|t        | |      z  } |S t        | g| 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	   )r1   regionregions_listr=   regs        rL   rm   rm      s    \ 6{afQi!12%eVAY77fQi0+F1I6q9F#E622fQi01&)<LF# 7*5#667MU$V$$r]   N)
sympy.corer   r   sympy.core.singletonr   sympy.core.sortingr   sympy.matricesr   sympy.integralsr   r	   sympy.geometry.entityr
   sympy.simplify.simplifyr   sympy.utilities.iterablesr   sympy.vectorr   r   r   r   r   sympy.vector.operatorsr   r   rm    r]   rL   <module>r|      s@    " " / ! / 0 , 6@ @ 5 D>%r]   