
    wgl                     l    d 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
 ddlmZ ddlmZ ddlmZ dd	Zy
)zX
This module implements a method to find
Euler-Lagrange Equations for given Lagrangian.
    )combinations_with_replacement)
DerivativeFunctiondiff)Eq)S)Symbolsympify)iterablec                    t        |      rt        |      n|f}|st        | j                  t                    }n%|D ]   }t	        |t              rt        d|z         t        |      rt        |      n|f}|s|d   j                  }nt        d |D              }t        d |D              st        d|z        |D ]"  }||j                  k(  rt        d|d|       t        | j                  t              D cg c]%  }|j                  |v rt        |j                        ' c}dgz         }g }|D ]  }t        | |      }t        d|dz         D ]A  }t!        ||      D ]0  }	|t"        j$                  |z  t        | t        |g|	 g|	 z  z   }2 C t'        |d      }
t	        |
t&              s|j)                  |
        |S c c}w )	a5  
    Find the Euler-Lagrange equations [1]_ for a given Lagrangian.

    Parameters
    ==========

    L : Expr
        The Lagrangian that should be a function of the functions listed
        in the second argument and their derivatives.

        For example, in the case of two functions $f(x,y)$, $g(x,y)$ and
        two independent variables $x$, $y$ the Lagrangian has the form:

            .. math:: L\left(f(x,y),g(x,y),\frac{\partial f(x,y)}{\partial x},
                      \frac{\partial f(x,y)}{\partial y},
                      \frac{\partial g(x,y)}{\partial x},
                      \frac{\partial g(x,y)}{\partial y},x,y\right)

        In many cases it is not necessary to provide anything, except the
        Lagrangian, it will be auto-detected (and an error raised if this
        cannot be done).

    funcs : Function or an iterable of Functions
        The functions that the Lagrangian depends on. The Euler equations
        are differential equations for each of these functions.

    vars : Symbol or an iterable of Symbols
        The Symbols that are the independent variables of the functions.

    Returns
    =======

    eqns : list of Eq
        The list of differential equations, one for each function.

    Examples
    ========

    >>> from sympy import euler_equations, Symbol, Function
    >>> x = Function('x')
    >>> t = Symbol('t')
    >>> L = (x(t).diff(t))**2/2 - x(t)**2/2
    >>> euler_equations(L, x(t), t)
    [Eq(-x(t) - Derivative(x(t), (t, 2)), 0)]
    >>> u = Function('u')
    >>> x = Symbol('x')
    >>> L = (u(t, x).diff(t))**2/2 - (u(t, x).diff(x))**2/2
    >>> euler_equations(L, u(t, x), [t, x])
    [Eq(-Derivative(u(t, x), (t, 2)) + Derivative(u(t, x), (x, 2)), 0)]

    References
    ==========

    .. [1] https://en.wikipedia.org/wiki/Euler%E2%80%93Lagrange_equation

    zFunction expected, got: %sr   c              3   2   K   | ]  }t        |        y wNr
   ).0vars     Y/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/sympy/calculus/euler.py	<genexpr>z"euler_equations.<locals>.<genexpr>V   s     2cWS\2s   c              3   <   K   | ]  }t        |t                y wr   )
isinstancer	   )r   vs     r   r   z"euler_equations.<locals>.<genexpr>X   s     3z!V$3s   z!Variables are not symbols, got %sz
Variables z do not match args:    )r   tupleatomsr   r   	TypeErrorargsall
ValueErrormaxr   exprlen	variablesr   ranger   r   NegativeOner   append)Lfuncsvarsfdordereqnseqipnew_eqs              r   euler_equationsr0      s   t %UOE%L%Eaggh'( 	BAa* <q @AA	B #4.5;tgDQx}}2T223d33;dBCC Oqvv~T1MNNO 177:+> ,a66U? Q[[! ,/0c2 3E D  !QZq%!)$ 	DA24; D!--*44;A;+C+CCCD	D Bfb!KK  K,s    *GN) r1   )__doc__	itertoolsr   sympy.core.functionr   r   r   sympy.core.relationalr   sympy.core.singletonr   sympy.core.symbolr	   sympy.core.sympifyr   sympy.utilities.iterablesr   r0   r1       r   <module>r;      s*    4 < < $ " $ & .^r:   