B
    [                 @   sR   d Z ddlmZ ddlmZmZmZmZmZm	Z	m
Z
 ddlmZ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)FunctionsympifydiffEqSSymbol
Derivative)iterablerange c       	   
      sn  t  rt n f  s*t| t n$x" D ]}t|ts0td| q0W t |r^t|n|f}|st d j}ntdd |D }tdd |D std| x& D ]}||jkstd||f qW t	 fdd| t
D }g }x| D ]t}t| |}xVtd	|d	 D ]D}x<t||D ].}|tj| t| t|f| f|   }q W qW |t| qW |S )
ae  
    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 would have 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
        couldn't 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 Symbol, Function
    >>> from sympy.calculus.euler import euler_equations
    >>> 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] http://en.wikipedia.org/wiki/Euler%E2%80%93Lagrange_equation

    zFunction expected, got: %sr   c             s   s   | ]}t |V  qd S )N)r   ).0varr   r   3lib/python3.7/site-packages/sympy/calculus/euler.py	<genexpr>S   s    z"euler_equations.<locals>.<genexpr>c             s   s   | ]}t |tV  qd S )N)
isinstancer   )r   vr   r   r   r   U   s    z!Variables are not symbols, got %sz!Variables %s don't match args: %sc             3   s"   | ]}|j  krt|jV  qd S )N)exprlenZ	variables)r   d)funcsr   r   r   \   s       )r
   tupleZatomsr   r   	TypeErrorargsall
ValueErrormaxr	   r   r   r   r   ZNegativeOneappendr   )	Lr   varsforderZeqnseqipr   )r   r   euler_equations
   s0    ;





4r&   N)r   r   )__doc__	itertoolsr   Zsympyr   r   r   r   r   r   r	   Zsympy.core.compatibilityr
   r   r&   r   r   r   r   <module>   s   $