ó
~9­\c           @   ss   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(	   sX   
This module implements a method to find
Euler-Lagrange Equations for given Lagrangian.
iÿÿÿÿ(   t   combinations_with_replacement(   t   Functiont   sympifyt   difft   Eqt   St   Symbolt
   Derivative(   t   iterablet   rangec   	   
      så  t  ˆ  ƒ r t ˆ  ƒ n ˆ  f ‰  ˆ  s? t |  j t ƒ ƒ ‰  n3 x0 ˆ  D]( } t | t ƒ sF t d | ƒ ‚ qF qF Wt  | ƒ rŠ t | ƒ n | f } | s© ˆ  d j } n t d „  | Dƒ ƒ } t d „  | Dƒ ƒ sè t d | ƒ ‚ n  x6 ˆ  D]. } | | j k sï t d | | f ƒ ‚ qï qï Wt	 ‡  f d †  |  j t
 ƒ Dƒ ƒ } g  } x’ ˆ  D]Š } t |  | ƒ } x_ t d | d ƒ D]J } xA t | | ƒ D]0 } | t j | t |  t | | Œ | Œ } q’Wq|W| j t | ƒ ƒ qSW| S(	   sf  
    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] https://en.wikipedia.org/wiki/Euler%E2%80%93Lagrange_equation

    s   Function expected, got: %si    c         s   s   |  ] } t  | ƒ Vq d  S(   N(   R   (   t   .0t   var(    (    s3   lib/python2.7/site-packages/sympy/calculus/euler.pys	   <genexpr>S   s    c         s   s   |  ] } t  | t ƒ Vq d  S(   N(   t
   isinstanceR   (   R
   t   v(    (    s3   lib/python2.7/site-packages/sympy/calculus/euler.pys	   <genexpr>U   s    s!   Variables are not symbols, got %ss!   Variables %s don't match args: %sc         3   s-   |  ]# } | j  ˆ  k r t | j ƒ Vq d  S(   N(   t   exprt   lent	   variables(   R
   t   d(   t   funcs(    s3   lib/python2.7/site-packages/sympy/calculus/euler.pys	   <genexpr>\   s    i   (   R   t   tuplet   atomsR   R   t	   TypeErrort   argst   allt
   ValueErrort   maxR   R   R	   R    R   t   NegativeOnet   appendR   (	   t   LR   t   varst   ft   ordert   eqnst   eqt   it   p(    (   R   s3   lib/python2.7/site-packages/sympy/calculus/euler.pyt   euler_equations
   s0    ;!!%2N(    (    (   t   __doc__t	   itertoolsR    t   sympyR   R   R   R   R   R   R   t   sympy.core.compatibilityR   R	   R$   (    (    (    s3   lib/python2.7/site-packages/sympy/calculus/euler.pyt   <module>   s   4