ó
8™xTc           @   sR   d  d l  m Z d  d l Z d  d l Z d d d „  ƒ  YZ d d d „  ƒ  YZ d S(	   iÿÿÿÿ(   t   divisionNt   least_squaresc           B   sG   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s`   | |  _  | |  _ |  j j |  j j } } t j | d | d ƒ |  _ |  j  |  j |  _ d  S(   Ni   (   t   obst   calct   realt   imagt   matht   sqrtt   abs_calct   delta(   t   selfR   R   t   at   b(    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/examples/exp_i_alpha_derivatives.pyt   __init__   s
    		c         C   s   |  j  d S(   s$   Mathematica: f=(obs-Sqrt[a^2+b^2])^2i   (   R	   (   R
   (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/examples/exp_i_alpha_derivatives.pyt   f   s    c         C   s/   |  j  d k r d Sd |  j |  j j |  j  S(   s   Mathematica: D[f,a]i    iþÿÿÿ(   R   R	   R   R   (   R
   (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/examples/exp_i_alpha_derivatives.pyt   da   s     c         C   s/   |  j  d k r d Sd |  j |  j j |  j  S(   s   Mathematica: D[f,b]i    iþÿÿÿ(   R   R	   R   R   (   R
   (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/examples/exp_i_alpha_derivatives.pyt   db   s     c         C   sU   |  j  } | d k r, |  j d k r( d Sd Sd d |  j j d |  j | | | S(   s0   Mathematica: FortranForm[FullSimplify[D[f,a,a]]]i    i   gÃüo%ÔÂ&á(   R   R   R   R   (   R
   t   ac(    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/examples/exp_i_alpha_derivatives.pyt   daa   s    	 c         C   sU   |  j  } | d k r, |  j d k r( d Sd Sd d |  j j d |  j | | | S(   s0   Mathematica: FortranForm[FullSimplify[D[f,b,b]]]i    i   gÃüo%ÔÂ&á(   R   R   R   R   (   R
   R   (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/examples/exp_i_alpha_derivatives.pyt   dbb$   s    	 c         C   sW   |  j  } | d k r, |  j d k r( d Sd Sd |  j j |  j j |  j | | | S(   s0   Mathematica: FortranForm[FullSimplify[D[f,a,b]]]i    gÃüo%ÔÂ&ai   (   R   R   R   R   R   (   R
   R   (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/examples/exp_i_alpha_derivatives.pyt   dab,   s    	 (	   t   __name__t
   __module__R   R   R   R   R   R   R   (    (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/examples/exp_i_alpha_derivatives.pyR      s   						t   exp_i_alpha_sumc           B   s>   e  Z d  „  Z d „  Z d „  Z d „  Z d „  Z d „  Z RS(   c         C   s   | |  _  d  S(   N(   t   alphas(   R
   R   (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/examples/exp_i_alpha_derivatives.pyR   6   s    c         C   s5   d } x( |  j  D] } | t j d | ƒ 7} q W| S(   s   Mathematica: f=Exp[I alpha]i    y              ð?(   R   t   cmatht   exp(   R
   t   resultt   alpha(    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/examples/exp_i_alpha_derivatives.pyR   9   s    c         C   s+   g  |  j  D] } d t j d | ƒ ^ q
 S(   s   Mathematica: D[f,alpha]y              ð?(   R   R   R   (   R
   R   (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/examples/exp_i_alpha_derivatives.pyt   d_alphas@   s    c         C   s(   g  |  j  D] } t j d | ƒ ^ q
 S(   s   Mathematica: D[f,alpha,alpha]y              ð?(   R   R   R   (   R
   R   (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/examples/exp_i_alpha_derivatives.pyt	   d2_alphasD   s    c         C   sH   | j  ƒ  | j ƒ  } } g  |  j ƒ  D] } | | j | | j ^ q& S(   s.   Rule for derivatives of sum of roots of unity.(   R   R   R   R   R   (   R
   t   targetR   R   t   d(    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/examples/exp_i_alpha_derivatives.pyt   d_target_d_alphasH   s    c         C   s#  g  } | j  ƒ  | j ƒ  } } | j ƒ  | j ƒ  | j ƒ  } } } |  j ƒ  } |  j ƒ  }	 x¿ t | |	 ƒ D]® \ }
 } g  } xŒ | D]„ } | |
 j | j | |
 j	 | j	 | |
 j | j	 |
 j	 | j } |
 | k rý | | | j | | j	 7} n  | j
 | ƒ q† W| j
 | ƒ qm W| S(   s2   Product rule applied to da * d.real + db * d.imag.(   R   R   R   R   R   R   R   t   zipR   R   t   append(   R
   R   R   R   R   R   R   R   R    t   d2t   dit   d2it   rowt   djt   sum(    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/examples/exp_i_alpha_derivatives.pyt   d2_target_d_alphasM   s    &F(   R   R   R   R   R   R   R!   R*   (    (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/examples/exp_i_alpha_derivatives.pyR   4   s   					(    (    (   t
   __future__R    R   R   R   R   (    (    (    sT   /public2/ftp/pub/ccp4/6.5/ccp4-6.5/lib/py2/cctbx/examples/exp_i_alpha_derivatives.pyt   <module>   s   /