;ò
…Rã?c           @   sD   d  Z  d k Z d f  d „  ƒ  YZ d „  Z d „  Z d d „ Z d S(   s`  This module provides automatic differentiation for functions with
any number of variables. Instances of the class DerivVar represent the
values of a function and its partial derivatives with respect to a
list of variables. All common mathematical operations and functions
are available for these numbers.  There is no restriction on the type
of the numbers fed into the code; it works for real and complex
numbers as well as for any Python type that implements the necessary
operations.

This module is as far as possible compatible with the n-th order
derivatives module Derivatives. If only first-order derivatives
are required, this module is faster than the general one.

Example:

  >>>print sin(DerivVar(2))

  produces the output

  >>>(0.909297426826, [-0.416146836547])

The first number is the value of sin(2); the number in the following
list is the value of the derivative of sin(x) at x=2, i.e. cos(2).

When there is more than one variable, DerivVar must be called with
an integer second argument that specifies the number of the variable.

Example:

  >>>x = DerivVar(7., 0)
  >>>y = DerivVar(42., 1)
  >>>z = DerivVar(pi, 2)
  >>>print (sqrt(pow(x,2)+pow(y,2)+pow(z,2)))

  produces the output

  >>>(42.6950770511, [0.163953328662, 0.98371997197, 0.0735820818365])

The numbers in the list are the partial derivatives with respect
to x, y, and z, respectively.

Note: It doesn't make sense to use DerivVar with different values
for the same variable index in one calculation, but there is
no check for this. I.e.

  >>>print DerivVar(3, 0)+DerivVar(5, 0)

  produces

  >>>(8, [2])

but this result is meaningless.
Ns   DerivVarc           B   sU  t  Z d  Z d d d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d	 „  Z	 d
 „  Z
 d „  Z d „  Z d „  Z e Z d „  Z d „  Z d „  Z e Z d „  Z d „  Z e d „ Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z  d „  Z! d „  Z" d  „  Z# d! „  Z$ d" „  Z% d# „  Z& d$ „  Z' RS(%   så  Variable with derivatives

    Constructor: DerivVar(|value|, |index| = 0)

    Arguments:

    |value| -- the numerical value of the variable

    |index| -- the variable index (an integer), which serves to
               distinguish between variables and as an index for
               the derivative lists. Each explicitly created
               instance of DerivVar must have a unique index.

    Indexing with an integer yields the derivatives of the corresponding
    order.
    i    i   c         C   s~   | d j o t d ‚ n | |  _ | d j o g  |  _ n> t | ƒ t g  ƒ j o | |  _ n | d g d g |  _ d  S(   Ni   s   Only first-order derivativesi    (   s   orders
   ValueErrors   values   selfs   derivs   types   index(   s   selfs   values   indexs   order(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   __init__V   s    	c         C   sJ   | d j  p
 | d j o t d ‚ n | d j o |  i Sn |  i Sd  S(   Ni    i   s   Index out of range(   s   items
   ValueErrors   selfs   values   deriv(   s   selfs   item(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   __getitem__a   s
    c         C   s   |  i |  i f Sd  S(   N(   s   selfs   values   deriv(   s   self(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   __repr__i   s    c         C   s   t  |  i |  i f ƒ Sd  S(   N(   s   strs   selfs   values   deriv(   s   self(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   __str__l   s    c         C   s2   t  | ƒ o |  | f Sn |  t | g  ƒ f Sd  S(   N(   s
   isDerivVars   others   selfs   DerivVar(   s   selfs   other(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys
   __coerce__o   s    c         C   s   t  |  i | i ƒ Sd  S(   N(   s   cmps   selfs   values   other(   s   selfs   other(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   __cmp__u   s    c         C   s$   t  |  i t d „  |  i ƒ ƒ Sd  S(   Nc         C   s   |  S(   N(   s   a(   s   a(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   <lambda>y   s    (   s   DerivVars   selfs   values   maps   deriv(   s   self(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   __neg__x   s    c         C   s   |  Sd  S(   N(   s   self(   s   self(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   __pos__{   s    c         C   s9   t  |  i ƒ } t | t |  i | d „ |  i ƒ ƒ Sd  S(   Nc         C   s   | |  S(   N(   s   ds   a(   s   as   d(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   <lambda>€   s    (   s   abss   selfs   values   absvalues   DerivVars   maps   deriv(   s   selfs   absvalue(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   __abs__~   s    c         C   s   |  i d j Sd  S(   Ni    (   s   selfs   value(   s   self(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   __nonzero__‚   s    c         C   s0   t  |  i | i t d „  |  i | i ƒ ƒ Sd  S(   Nc         C   s   |  | S(   N(   s   as   b(   s   as   b(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   <lambda>‡   s    (   s   DerivVars   selfs   values   others	   _mapderivs   deriv(   s   selfs   other(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   __add__…   s    c         C   s0   t  |  i | i t d „  |  i | i ƒ ƒ Sd  S(   Nc         C   s   |  | S(   N(   s   as   b(   s   as   b(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   <lambda>Œ   s    (   s   DerivVars   selfs   values   others	   _mapderivs   deriv(   s   selfs   other(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   __sub__Š   s    c         C   s0   t  | i |  i t d „  | i |  i ƒ ƒ Sd  S(   Nc         C   s   |  | S(   N(   s   as   b(   s   as   b(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   <lambda>�   s    (   s   DerivVars   others   values   selfs	   _mapderivs   deriv(   s   selfs   other(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   __rsub__Ž   s    c         C   sT   t  |  i | i t d „  t | i d „ |  i ƒ t |  i d „ | i ƒ ƒ ƒ Sd  S(   Nc         C   s   |  | S(   N(   s   as   b(   s   as   b(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   <lambda>”   s    c         C   s   | |  S(   N(   s   fs   x(   s   xs   f(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   <lambda>•   s    (   s   DerivVars   selfs   values   others	   _mapderivs   maps   deriv(   s   selfs   other(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   __mul__’   s    	c         C   s{   | i o t d ‚ n d | i } t |  i | t d „  t | d „ |  i ƒ t |  i | | d „ | i ƒ ƒ ƒ Sd  S(   Ns   DerivVar divisionf1.0c         C   s   |  | S(   N(   s   as   b(   s   as   b(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   <lambda>ž   s    c         C   s   | |  S(   N(   s   fs   x(   s   xs   f(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   <lambda>Ÿ   s    (	   s   others   values   ZeroDivisionErrors   invs   DerivVars   selfs	   _mapderivs   maps   deriv(   s   selfs   others   inv(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   __div__™   s    	c         C   s   | |  Sd  S(   N(   s   others   self(   s   selfs   other(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   __rdiv__¢   s    c         C   sÛ   | t j	 o t d ‚ n t |  i | i d ƒ } | |  i } t	 | | i d „ |  i
 ƒ } t | ƒ o t | i
 ƒ d j oH t	 | t i |  i ƒ d „ | i
 ƒ } t | t d „  | | ƒ ƒ Sn t | | ƒ Sd  S(   Ns'   DerivVar does not support ternary pow()i   c         C   s   | |  S(   N(   s   fs   x(   s   xs   f(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   <lambda>ª   s    i    c         C   s   |  | S(   N(   s   as   b(   s   as   b(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   <lambda>®   s    (   s   zs   Nones	   TypeErrors   pows   selfs   values   others   val1s   vals   maps   derivs   deriv1s
   isDerivVars   lens   Numerics   logs   deriv2s   DerivVars	   _mapderiv(   s   selfs   others   zs   vals   deriv2s   deriv1s   val1(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   __pow__¥   s    # c         C   s   t  | |  ƒ Sd  S(   N(   s   pows   others   self(   s   selfs   other(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   __rpow__²   s    c         C   s5   t  i |  i ƒ } t | t | d „ |  i ƒ ƒ Sd  S(   Nc         C   s   | |  S(   N(   s   fs   x(   s   xs   f(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   <lambda>·   s    (   s   Numerics   exps   selfs   values   vs   DerivVars   maps   deriv(   s   selfs   v(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   expµ   s    c         C   sB   t  i |  i ƒ } d |  i } t | t | d „ |  i ƒ ƒ Sd  S(   Nf1.0c         C   s   | |  S(   N(   s   fs   x(   s   xs   f(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   <lambda>¼   s    (	   s   Numerics   logs   selfs   values   vs   ds   DerivVars   maps   deriv(   s   selfs   ds   v(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   log¹   s    c         C   sO   t  i |  i ƒ } d |  i t  i d ƒ } t | t | d „ |  i	 ƒ ƒ Sd  S(   Nf1.0i
   c         C   s   | |  S(   N(   s   fs   x(   s   xs   f(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   <lambda>Á   s    (
   s   Numerics   log10s   selfs   values   vs   logs   ds   DerivVars   maps   deriv(   s   selfs   ds   v(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   log10¾   s    c         C   s?   t  i |  i ƒ } d | } t | t | d „ |  i ƒ ƒ Sd  S(   Nf0.5c         C   s   | |  S(   N(   s   fs   x(   s   xs   f(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   <lambda>Æ   s    (	   s   Numerics   sqrts   selfs   values   vs   ds   DerivVars   maps   deriv(   s   selfs   ds   v(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   sqrtÃ   s    
c         C   s:   |  i d j o t d ‚ n t t i |  i ƒ d ƒ Sd  S(   Ni    s"   can't differentiate sign() at zero(   s   selfs   values
   ValueErrors   DerivVars   Numerics   sign(   s   self(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   signÈ   s    c         C   sG   t  i |  i ƒ } t  i |  i ƒ } t | t | d „ |  i	 ƒ ƒ Sd  S(   Nc         C   s   | |  S(   N(   s   fs   x(   s   xs   f(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   <lambda>Ð   s    (
   s   Numerics   sins   selfs   values   vs   coss   ds   DerivVars   maps   deriv(   s   selfs   ds   v(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   sinÍ   s    c         C   sH   t  i |  i ƒ } t  i |  i ƒ } t | t | d „ |  i	 ƒ ƒ Sd  S(   Nc         C   s   | |  S(   N(   s   fs   x(   s   xs   f(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   <lambda>Õ   s    (
   s   Numerics   coss   selfs   values   vs   sins   ds   DerivVars   maps   deriv(   s   selfs   ds   v(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   cosÒ   s    c         C   sH   t  i |  i ƒ } d t | d ƒ } t | t | d „ |  i	 ƒ ƒ Sd  S(   Nf1.0i   c         C   s   | |  S(   N(   s   fs   x(   s   xs   f(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   <lambda>Ú   s    (
   s   Numerics   tans   selfs   values   vs   pows   ds   DerivVars   maps   deriv(   s   selfs   ds   v(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   tan×   s    c         C   sG   t  i |  i ƒ } t  i |  i ƒ } t | t | d „ |  i	 ƒ ƒ Sd  S(   Nc         C   s   | |  S(   N(   s   fs   x(   s   xs   f(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   <lambda>ß   s    (
   s   Numerics   sinhs   selfs   values   vs   coshs   ds   DerivVars   maps   deriv(   s   selfs   ds   v(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   sinhÜ   s    c         C   sG   t  i |  i ƒ } t  i |  i ƒ } t | t | d „ |  i	 ƒ ƒ Sd  S(   Nc         C   s   | |  S(   N(   s   fs   x(   s   xs   f(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   <lambda>ä   s    (
   s   Numerics   coshs   selfs   values   vs   sinhs   ds   DerivVars   maps   deriv(   s   selfs   ds   v(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   coshá   s    c         C   sT   t  i |  i ƒ } d t t  i |  i ƒ d ƒ } t | t	 | d „ |  i
 ƒ ƒ Sd  S(   Nf1.0i   c         C   s   | |  S(   N(   s   fs   x(   s   xs   f(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   <lambda>é   s    (   s   Numerics   tanhs   selfs   values   vs   pows   coshs   ds   DerivVars   maps   deriv(   s   selfs   ds   v(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   tanhæ   s    c         C   sX   t  i |  i ƒ } d t  i d t |  i d ƒ ƒ } t | t	 | d „ |  i
 ƒ ƒ Sd  S(   Nf1.0i   c         C   s   | |  S(   N(   s   fs   x(   s   xs   f(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   <lambda>î   s    (   s   Numerics   arcsins   selfs   values   vs   sqrts   pows   ds   DerivVars   maps   deriv(   s   selfs   ds   v(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   arcsinë   s    #c         C   sX   t  i |  i ƒ } d t  i d t |  i d ƒ ƒ } t | t	 | d „ |  i
 ƒ ƒ Sd  S(   Nf-1.0f1.0i   c         C   s   | |  S(   N(   s   fs   x(   s   xs   f(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   <lambda>ó   s    (   s   Numerics   arccoss   selfs   values   vs   sqrts   pows   ds   DerivVars   maps   deriv(   s   selfs   ds   v(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   arccosð   s    #c         C   sO   t  i |  i ƒ } d d t |  i d ƒ } t | t | d „ |  i	 ƒ ƒ Sd  S(   Nf1.0i   c         C   s   | |  S(   N(   s   fs   x(   s   xs   f(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   <lambda>ø   s    (
   s   Numerics   arctans   selfs   values   vs   pows   ds   DerivVars   maps   deriv(   s   selfs   ds   v(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   arctanõ   s    c         C   sŽ   |  i |  i | i | i } |  i | } | i | } t t i |  i | i ƒ t	 d „  t
 | d „ |  i ƒ t
 | d „ | i ƒ ƒ ƒ Sd  S(   Nc         C   s   |  | S(   N(   s   as   b(   s   as   b(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   <lambda>ÿ   s    c         C   s   | |  S(   N(   s   fs   x(   s   xs   f(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   <lambda>   s    (   s   selfs   values   others   dens   ss   os   DerivVars   Numerics   arctan2s	   _mapderivs   maps   deriv(   s   selfs   others   os   ss   den(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   arctan2ú   s    	c         C   sX   d k  l } l } | |  i ƒ } | | |  i ƒ } t | t | d „ |  i	 ƒ ƒ Sd  S(   N(   s   gammas   psic         C   s   | |  S(   N(   s   fs   x(   s   xs   f(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   <lambda>  s    (
   s   transcendentals   gammas   psis   selfs   values   vs   ds   DerivVars   maps   deriv(   s   selfs   psis   ds   vs   gamma(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   gamma  s    ((   s   __name__s
   __module__s   __doc__s   __init__s   __getitem__s   __repr__s   __str__s
   __coerce__s   __cmp__s   __neg__s   __pos__s   __abs__s   __nonzero__s   __add__s   __radd__s   __sub__s   __rsub__s   __mul__s   __rmul__s   __div__s   __rdiv__s   Nones   __pow__s   __rpow__s   exps   logs   log10s   sqrts   signs   sins   coss   tans   sinhs   coshs   tanhs   arcsins   arccoss   arctans   arctan2s   gamma(    (    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   DerivVarC   sJ    																																	c         C   s!   t  |  d ƒ o t  |  d ƒ Sd S(   s&   Returns 1 if |x| is a DerivVar object.s   values   derivN(   s   hasattrs   x(   s   x(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys
   isDerivVar  s     c         C   se   t  t | ƒ t | ƒ ƒ } | | t | ƒ d g } | | t | ƒ d g } t |  | | ƒ Sd  S(   Ni    (   s   maxs   lens   as   bs   nvarss   maps   func(   s   funcs   as   bs   nvars(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys	   _mapderiv  s    i    c         C   s   d k  l } t |  ƒ o t | ƒ o
 t | ƒ o | |  | | ƒ Sn4 | t |  | ƒ t | | d ƒ t | | d ƒ ƒ Sd S(   sù   Returns a vector whose components are DerivVar objects.

    Arguments:

    |x|, |y|, |z| -- vector components (numbers)

    |index| -- the DerivVar index for the x component. The y and z
               components receive consecutive indices.
    (   s   Vectori   i   N(   s   Scientific.Geometry.Vectors   Vectors
   isDerivVars   xs   ys   zs   DerivVars   index(   s   xs   ys   zs   indexs   Vector(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   DerivVector  s    
 '(   s   __doc__s   Numerics   DerivVars
   isDerivVars	   _mapderivs   DerivVector(   s	   _mapderivs
   isDerivVars   DerivVars   DerivVectors   Numeric(    (    sP   /mit/python/lib/python2.3/site-packages/Scientific/Functions/FirstDerivatives.pys   ?;   s
   	È			