a
    ¬<bl  ã                   @   sn   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
d„ZdS )zX
This module implements a method to find
Euler-Lagrange Equations for given Lagrangian.
é    )Úcombinations_with_replacement)Ú
DerivativeÚFunctionÚdiff)ÚEq)ÚS)ÚSymbol©Úsympify)Úiterable© c           
   
      st  t ˆ ƒrtˆ ƒnˆ f‰ ˆ s*t|  t¡ƒ‰ n ˆ D ]}t|tƒs.td| ƒ‚q.t |ƒrZt|ƒn|f}|spˆ d j}ntdd„ |D ƒƒ}tdd„ |D ƒƒs td| ƒ‚ˆ D ]}||jks¤td||f ƒ‚q¤t	‡ fdd	„|  t
¡D ƒdg ƒ}g }ˆ D ]€}t| |ƒ}td
|d
 ƒD ]D}t||ƒD ]2}|tj| t| t|g|¢R Ž g|¢R Ž   }qq
t|dƒ}	t|	tƒrî| |	¡ qî|S )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                 s   s   | ]}t |ƒV  qd S ©Nr	   )Ú.0Úvarr   r   úd/Users/vegardjervell/Documents/master/model/venv/lib/python3.9/site-packages/sympy/calculus/euler.pyÚ	<genexpr>V   ó    z"euler_equations.<locals>.<genexpr>c                 s   s   | ]}t |tƒV  qd S r   )Ú
isinstancer   )r   Úvr   r   r   r   X   r   z!Variables are not symbols, got %sz"Variables %s do not match args: %sc                    s    g | ]}|j ˆ v rt|jƒ‘qS r   )ÚexprÚlenÚ	variables)r   Úd©Úfuncsr   r   Ú
<listcomp>_   s   
ÿz#euler_equations.<locals>.<listcomp>é   )r   ÚtupleZatomsr   r   Ú	TypeErrorÚargsÚallÚ
ValueErrorÚmaxr   r   Úranger   r   ZNegativeOner   Úappend)
ÚLr   ÚvarsÚfÚorderZeqnsÚeqÚiÚpZnew_eqr   r   r   Úeuler_equations   s8    :

ÿ
4

r,   N)r   r   )Ú__doc__Ú	itertoolsr   Zsympy.core.functionr   r   r   Zsympy.core.relationalr   Zsympy.core.singletonr   Zsympy.core.symbolr   Zsympy.core.sympifyr
   Zsympy.utilities.iterablesr   r,   r   r   r   r   Ú<module>   s   