
~9\c        0   @  s  d  Z  d d l m Z m Z d d l m Z d d l m Z m Z m	 Z	 m
 Z
 d d l m Z m Z d d l m Z d d l m Z d d l m Z m Z d d	 l m Z d
 d d d d d d d d d d d d d d d d d d d d d d  d! d" d# d$ d% d& d' d( d) d* d+ d, d- d. d/ d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 g0 Z i d: d; 6d< d= 6d> d? 6d@ dA 6dB dC 6dD dE 6dF dG 6dH dI 6dJ dK 6dL dM 6dN dO 6dP dQ 6dR dS 6dT dU 6dV dW 6dX dY 6dZ d[ 6d\ d] 6d^ d_ 6d` da 6db dc 6dd de 6Z df e f dg     YZ e dh  Z di   Z dj S(k   si  
Octave (and Matlab) code printer

The `OctaveCodePrinter` converts SymPy expressions into Octave expressions.
It uses a subset of the Octave language for Matlab compatibility.

A complete code generator, which uses `octave_code` extensively, can be found
in `sympy.utilities.codegen`.  The `codegen` module can be used to generate
complete source code files.

i(   t   print_functiont   division(   t
   Assignment(   t   Mult   Powt   St   Rational(   t   string_typest   range(   t   _keep_coeff(   t   CodePrinter(   t
   precedencet
   PRECEDENCE(   t   searcht   sint   cost   tant   cott   sect   csct   asint   acost   acott   atant   atan2t   asect   acsct   sinht   cosht   tanht   cotht   cscht   secht   asinht   acosht   atanht   acotht   asecht   acscht   erfct   erfit   erft   erfinvt   erfcinvt   besselit   besseljt   besselkt   besselyt	   bernoullit   betat   eulert   expt	   factorialt   floort   fresnelct   fresnelst   gammat   harmonict   logt   polylogt   signt   zetat   abst   Abst   anglet   argt   ceilt   ceilingt
   chebyshevUt
   chebyshevut
   chebyshevTt
   chebyshevtt   coshintt   Chit   cosintt   Cit   conjt	   conjugatet   diract
   DiracDeltat	   heavisidet	   Heavisidet   imagt   imt	   laguerreLt   laguerret   lambertwt   LambertWt   logintt   lit   gammalnt   loggammat   maxt   Maxt   mint   Mint   psit	   polygammat   realt   ret
   pochhammert   RisingFactorialt   sinhintt   Shit   sinintt   Sit   OctaveCodePrinterc           B  sf  e  Z d  Z d Z d Z i d d 6d d 6d d 6Z i dC d	 6d
 d 6d d 6i  d 6e d 6e d 6e d 6e d 6Z	 i  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 d%   Z d&   Z e Z e Z d'   Z  d(   Z! d)   Z" d*   Z# d+   Z$ e# Z% Z& Z' Z( Z) e$ Z* Z+ d,   Z, d-   Z- d.   Z. d/   Z/ d0   Z0 d1   Z1 d2   Z2 d3   Z3 d4   Z4 d5   Z5 d6   Z6 d7   Z7 d8   Z8 d9   Z9 d:   Z: d;   Z; d<   Z< d=   Z= d>   Z> e> Z? Z@ d?   ZA eA ZB ZC d@   ZD dA   ZE dB   ZF RS(D   sL   
    A printer to convert expressions to strings of Octave/Matlab code.
    t   _octavet   Octavet   &t   andt   |t   ort   ~t   nott   ordert   autot	   full_preci   t	   precisiont   user_functionst   humant   allow_unknown_functionst   contractt   inlinec         C  sj   t  t |   j |  t t t t   |  _ |  j j t t   | j	 d i   } |  j j |  d  S(   NRw   (
   t   superRj   t   __init__t   dictt   zipt   known_fcns_src1t   known_functionst   updatet   known_fcns_src2t   get(   t   selft   settingst	   userfuncs(    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyR}   Z   s
    c         C  s   | d S(   Ni   (    (   R   t   p(    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _rate_index_positionb   s    c         C  s   d | S(   Ns   %s;(    (   R   t
   codestring(    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _get_statementf   s    c         C  s   d j  |  S(   Ns   % {0}(   t   format(   R   t   text(    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _get_commentj   s    c         C  s   d j  | |  S(   Ns
   {0} = {1};(   R   (   R   t   namet   value(    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _declare_number_constn   s    c         C  s   |  j  |  S(   N(   t   indent_code(   R   t   lines(    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _format_coder   s    c           s)   | j  \   }   f d   t |  D S(   Nc         3  s.   |  ]$ } t     D] } | | f Vq q d  S(   N(   R   (   t   .0t   jt   i(   t   rows(    s4   lib/python2.7/site-packages/sympy/printing/octave.pys	   <genexpr>y   s    (   t   shapeR   (   R   t   matt   cols(    (   R   s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _traverse_matrix_indicesv   s    c         C  s   g  } g  } xj | D]b } t  |  j | j | j d | j d g  \ } } } | j d | | | f  | j d  q W| | f S(   Ni   s   for %s = %s:%st   end(   t   mapt   _printt   labelt   lowert   uppert   append(   R   t   indicest
   open_linest   close_linesR   t   vart   startt   stop(    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _get_loop_opening_ending|   s    	,c         C  sr  | j  r; | j r; t j | j r; d |  j t j |  St |  } | j   \ } } | d k  r~ t | |  } d } n d } g  } g  } g  } |  j	 d k r | j
   }	 n t j |  }	 xC|	 D];}
 |
 j r|
 j r|
 j j r|
 j j r|
 j d k r/| j t |
 j |
 j d t  qt |
 j d j  d	 k rmt |
 j t  rm| j |
  n  | j t |
 j |
 j   q |
 j r|
 t j k	 r|
 j d	 k r| j t |
 j   n  |
 j d	 k r| j t |
 j   qq | j |
  q W| pt j g } g  | D] } |  j | |  ^ q"} g  | D] } |  j | |  ^ qG} xJ | D]B }
 |
 j | k rld
 | | j |
 j  | | j |
 j  <qlqlWd   } | s| | | |  St |  d	 k r| d j  rd n d } | | | |  | | d St  g  | D] } | j  ^ q$ rBd n d } | | | |  | d
 | | |  Sd  S(   Ns   %sii    t   -t    t   oldt   noneit   evaluatei   s   (%s)c         S  s]   | d } xL t  d t |    D]5 } |  | d j r= d n d } | | | | } q  W| S(   Ni    i   t   *s   .*(   R   t   lent	   is_number(   t   at   a_strt   rR   t   mulsym(    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   multjoin   s
    
t   /s   ./(   R   R   (!   R   t   is_imaginaryR   t   ImaginaryUnitt
   is_IntegerR   R   t   as_coeff_MulR	   Rs   t   as_ordered_factorsR   t	   make_argst   is_commutativet   is_PowR3   t   is_Rationalt   is_negativeR   R   t   baset   FalseR   t   argst
   isinstancet   InfinityR   R   t   qt   Onet   parenthesizet   indext   all(   R   t   exprt   prect   ct   eR<   R   t   bt	   pow_parenR   t   itemt   xR   t   b_strR   t   divsymt   bi(    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt
   _print_Mul   sV    	&. %%1	.c         C  s/  t  g  | j D] } | j ^ q  r+ d n d } t |  } | j t j k rc d |  j | j  S| j	 r | j t j k r | j j r d n d } d | d |  j | j  S| j t j
 k r | j j r d n d } d | d |  j | j |  Sn  d |  j | j |  | |  j | j |  f S(	   Nt   ^s   .^s   sqrt(%s)R   s   ./t   1s   %ss   %s%s%s(   R   R   R   R   R3   R   t   HalfR   R   R   R   R   (   R   R   R   t	   powsymbolt   PRECt   sym(    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt
   _print_Pow   s    1	"c         C  s8   t  |  } d |  j | j |  |  j | j |  f S(   Ns   %s^%s(   R   R   R   R3   (   R   R   R   (    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _print_MatPow   s    c         C  s   d S(   Nt   pi(    (   R   R   (    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt	   _print_Pi   s    c         C  s   d S(   Nt   1i(    (   R   R   (    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _print_ImaginaryUnit   s    c         C  s   d S(   Ns   exp(1)(    (   R   R   (    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _print_Exp1   s    c         C  s   d S(   Ns   (1+sqrt(5))/2(    (   R   R   (    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _print_GoldenRatio   s    c         C  s1  d d l  m } d d l m } | j } | j } |  j d r t | j |  r g  } g  } x: | j D]/ \ } }	 | j	 t
 | |   | j	 |	  qh W| t | |    }
 |  j |
  S|  j d r | j |  s | j |  r |  j | |  S|  j |  } |  j |  } |  j d | | f  Sd  S(   Ni(   t	   Piecewise(   t   IndexedBaseR{   Rz   s   %s = %s(   t$   sympy.functions.elementary.piecewiseR   t   sympy.tensor.indexedR   t   lhst   rhst	   _settingsR   R   R   R   R   R   t   hast   _doprint_loopsR   (   R   R   R   R   R   R   t   expressionst
   conditionsR   R   t   tempt   lhs_codet   rhs_code(    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _print_Assignment   s$    		 c         C  s   d S(   Nt   inf(    (   R   R   (    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _print_Infinity  s    c         C  s   d S(   Ns   -inf(    (   R   R   (    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _print_NegativeInfinity  s    c         C  s   d S(   Nt   NaN(    (   R   R   (    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt
   _print_NaN#  s    c           s%   d d j    f d   | D  d S(   Nt   {s   , c         3  s   |  ] }   j  |  Vq d  S(   N(   R   (   R   R   (   R   (    s4   lib/python2.7/site-packages/sympy/printing/octave.pys	   <genexpr>(  s    t   }(   t   join(   R   R   (    (   R   s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _print_list'  s    c         C  s   d S(   Nt   true(    (   R   R   (    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _print_BooleanTrue-  s    c         C  s   d S(   Nt   false(    (   R   R   (    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _print_BooleanFalse1  s    c         C  s   t  |  j   S(   N(   t   strR   (   R   R   (    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _print_bool5  s    c           s     j    j f d k r d S  j  d k s:   j d k rN d   j    j f S  j    j f d	 k rw  j   d
  Sd d j    f d   t   j   D  S(   Ni    s   []s   zeros(%s, %s)i   s   [%s]s   ; c         3  sJ   |  ]@ } d  j  g    | d d  f D] }  j |  ^ q&  Vq d S(   t    N(   R   R   (   R   R   R   (   t   AR   (    s4   lib/python2.7/site-packages/sympy/printing/octave.pys	   <genexpr>F  s   (   i    i    (   i   i   (   i    i    (   R   R   R   R   R   (   R   R  (    (   R  R   s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _print_MatrixBase=  s    c         C  s   d d l  m } | j   } | g  | D] } | d d ^ q& g  } | g  | D] } | d d ^ qP g  } | g  | D] } | d ^ qz g  } d |  j |  |  j |  |  j |  | j | j f S(   Ni(   t   Matrixi    i   i   s   sparse(%s, %s, %s, %s, %s)(   t   sympy.matricesR  t   col_listR   R   R   (   R   R  R  t   Lt   kt   It   Jt   AIJ(    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _print_SparseMatrixJ  s    **&c         C  s9   |  j  | j t d d t d | j d | j d f S(   Nt   Atomt   stricts   (%s, %s)i   (   R   t   parentR   t   TrueR   R   (   R   R   (    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _print_MatrixElementc  s    c           s_     f d   }   j  | j  d | | j | j j d  d | | j | j j d  d S(   Nc           s   |  d d } |  d } |  d }   j  |  } | | k rC d n   j  |  } | d k r | d k rz | | k rz d S| | k r | S| d | Sn d j |   j  |  | f  Sd  S(   Ni    i   i   R   t   :(   R   R   (   R   t   limt   lt   ht   stept   lstrt   hstr(   R   (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   strslicei  s    

!t   (i    s   , i   t   )(   R   R  t   rowsliceR   t   colslice(   R   R   R  (    (   R   s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _print_MatrixSliceh  s    c         C  sK   g  | j  D] } |  j |  ^ q
 } d |  j | j j  d j |  f S(   Ns   %s(%s)s   , (   R   R   R   R   R   (   R   R   R   t   inds(    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _print_Indexed}  s    %c         C  s   |  j  | j  S(   N(   R   R   (   R   R   (    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt
   _print_Idx  s    c           s.   t  d   d t    f d   | j D  S(   NR   s   double(%s == %s)c         3  s!   |  ] }  j  |    Vq d  S(   N(   R   (   R   R   (   R   R   (    s4   lib/python2.7/site-packages/sympy/printing/octave.pys	   <genexpr>  s   (   R   t   tupleR   (   R   R   (    (   R   R   s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _print_KroneckerDelta  s    
c           sj   | j  } t |  d k r? | d | d k r? | d g } n  d j   f d   | D  } d | d S(   Ni   i    i   s   , c         3  s   |  ] }   j  |  Vq d  S(   N(   R   (   R   t   n(   R   (    s4   lib/python2.7/site-packages/sympy/printing/octave.pys	   <genexpr>  s    s   eye(R  (   R   R   R   (   R   R   R   t   s(    (   R   s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _print_Identity  s
    	&c         C  s0   d j  |  j | j d  |  j | j d   S(   Ns    (gammainc({1}, {0}).*gamma({0}))i    i   (   R   R   R   (   R   R   (    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _print_lowergamma  s    c         C  s0   d j  |  j | j d  |  j | j d   S(   Ns)   (gammainc({1}, {0}, 'upper').*gamma({0}))i    i   (   R   R   R   (   R   R   (    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _print_uppergamma  s    c         C  s   d |  j  | j d t j  S(   Ns   sinc(%s)i    (   R   R   R   t   Pi(   R   R   (    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _print_sinc  s    c         C  s&   d |  j  | j  |  j  | j  f S(   Ns   besselh(%s, 1, %s)(   R   Rs   t   argument(   R   R   (    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _print_hankel1  s    c         C  s&   d |  j  | j  |  j  | j  f S(   Ns   besselh(%s, 2, %s)(   R   Rs   R/  (   R   R   (    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _print_hankel2  s    c         C  sZ   d d l  m } m } | j } | t j d |  | | j t j |  } |  j |  S(   Ni(   t   sqrtR-   i   (	   t   sympy.functionsR2  R-   R/  R   R-  Rs   R   R   (   R   R   R2  R-   R   t   expr2(    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt	   _print_jn  s    	.c         C  sZ   d d l  m } m } | j } | t j d |  | | j t j |  } |  j |  S(   Ni(   R2  R/   i   (	   R3  R2  R/   R/  R   R-  Rs   R   R   (   R   R   R2  R/   R   R4  (    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt	   _print_yn  s    	.c         C  s   d |  j  | j d  S(   Ns   airy(0, %s)i    (   R   R   (   R   R   (    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _print_airyai  s    c         C  s   d |  j  | j d  S(   Ns   airy(1, %s)i    (   R   R   (   R   R   (    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _print_airyaiprime  s    c         C  s   d |  j  | j d  S(   Ns   airy(2, %s)i    (   R   R   (   R   R   (    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _print_airybi  s    c         C  s   d |  j  | j d  S(   Ns   airy(3, %s)i    (   R   R   (   R   R   (    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _print_airybiprime  s    c         C  s9   | j  \ } } | d k r( |  j |  Sd |  j |  S(   Ni   s
   expint(%s)(   R   t   _print_not_supportedR   (   R   R   t   muR   (    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _print_expint  s    c      	   C  sl   t  | j  d k s t  d j d |  j | j j d d j g  t | j  D] } |  j	 |  ^ qM   S(   Ni   s   {name}({args})R   R   s   , (
   R   R   t   AssertionErrorR   R   t	   __class__t   __name__R   t   reversedR   (   R   R   R   (    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _one_or_two_reversed_args  s    	c      
   C  sR   d j  d |  j | j j d |  j | j d  d |  j | j | j d     S(   Ns   {name}({arg1}, {arg2})R   t   arg1i    t   arg2i   (   R   R   R?  R@  R   R   t   func(   R   R   (    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _nested_binary_math_func  s    	c   
      C  s  | j  d j t k r% t d   n  g  } |  j d r g  | j  d  D]0 \ } } d j |  j |  |  j |   ^ qF } d |  j | j  d j  } d j |  | d t	 |  } d | d Sx t
 | j   D] \ } \ } } | d	 k r| j d
 |  j |   nO | t	 | j   d k rF| t k rF| j d  n | j d |  j |   |  j |  }	 | j |	  | t	 | j   d k r | j d  q q Wd j |  Sd  S(   Nis   All Piecewise expressions must contain an (expr, True) statement to be used as a default condition. Without one, the generated expression may not evaluate to anything under some condition.R{   s   ({0}).*({1}) + (~({0})).*(s   %ss    ...
R  R  i    s   if (%s)i   t   elses   elseif (%s)R   s   
(   R   t   condR  t
   ValueErrorR   R   R   R   R   R   t	   enumerateR   (
   R   R   R   R   R   t   ecpairst   elastt   pwR   t   code0(    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _print_Piecewise  s(    A!"%c         C  s>   t  | j  d k r- d |  j | j d  S|  j |  Sd  S(   Ni   s   zeta(%s)i    (   R   R   R   R;  (   R   R   (    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   _print_zeta  s    c      	   C  sy  t  | t  r4 |  j | j t   } d j |  Sd } d } d } g  | D] } | j d	  ^ qM } g  | D]4 } t t g  | D] } t	 | |  ^ q   ^ qo } g  | D]4 } t t g  | D] } t	 | |  ^ q   ^ q }	 g  }
 d
 } x| t
 |  D]n \ } } | d k s'| d k r:|
 j |  qn  | |	 | 8} |
 j d | | | f  | | | 7} qW|
 S(   s0   Accepts a string of code or a list of code linesR   s     s
   ^function s   ^if s   ^elseif s   ^else$s   ^for s   ^end$s    	i    s   
s   %s%s(   s
   ^function s   ^if s   ^elseif s   ^else$s   ^for (   s   ^end$s   ^elseif s   ^else$(   R   R   R   t
   splitlinesR  R   t   lstript   intt   anyR   RJ  R   (   R   t   codet
   code_linest   tabt	   inc_regext	   dec_regext   lineRc   t   increaset   decreaset   prettyt   levelR(  (    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyR     s*    ">>N(G   R@  t
   __module__t   __doc__t   printmethodt   languaget
   _operatorst   NoneR  R   t   _default_settingsR}   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   R   t   _print_tuplet   _print_TupleR   R  R  R  R  t   _print_Matrixt   _print_DenseMatrixt   _print_MutableDenseMatrixt   _print_ImmutableMatrixt   _print_ImmutableDenseMatrixt   _print_MutableSparseMatrixt   _print_ImmutableSparseMatrixR  R"  R$  R%  R'  R*  R+  R,  R.  R0  R1  R5  R6  R7  R8  R9  R:  R=  RB  t   _print_DiracDeltat   _print_LambertWRF  t
   _print_Maxt
   _print_MinRO  RP  R   (    (    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyRj   >   s   

								K																
																			
	
	%	c         K  s   t  |  j |  |  S(   s  Converts `expr` to a string of Octave (or Matlab) code.

    The string uses a subset of the Octave language for Matlab compatibility.

    Parameters
    ==========

    expr : Expr
        A sympy expression to be converted.
    assign_to : optional
        When given, the argument is used as the name of the variable to which
        the expression is assigned.  Can be a string, ``Symbol``,
        ``MatrixSymbol``, or ``Indexed`` type.  This can be helpful for
        expressions that generate multi-line statements.
    precision : integer, optional
        The precision for numbers such as pi  [default=16].
    user_functions : dict, optional
        A dictionary where keys are ``FunctionClass`` instances and values are
        their string representations.  Alternatively, the dictionary value can
        be a list of tuples i.e. [(argument_test, cfunction_string)].  See
        below for examples.
    human : bool, optional
        If True, the result is a single string that may contain some constant
        declarations for the number symbols.  If False, the same information is
        returned in a tuple of (symbols_to_declare, not_supported_functions,
        code_text).  [default=True].
    contract: bool, optional
        If True, ``Indexed`` instances are assumed to obey tensor contraction
        rules and the corresponding nested loops over indices are generated.
        Setting contract=False will not generate loops, instead the user is
        responsible to provide values for the indices in the code.
        [default=True].
    inline: bool, optional
        If True, we try to create single-statement code instead of multiple
        statements.  [default=True].

    Examples
    ========

    >>> from sympy import octave_code, symbols, sin, pi
    >>> x = symbols('x')
    >>> octave_code(sin(x).series(x).removeO())
    'x.^5/120 - x.^3/6 + x'

    >>> from sympy import Rational, ceiling, Abs
    >>> x, y, tau = symbols("x, y, tau")
    >>> octave_code((2*tau)**Rational(7, 2))
    '8*sqrt(2)*tau.^(7/2)'

    Note that element-wise (Hadamard) operations are used by default between
    symbols.  This is because its very common in Octave to write "vectorized"
    code.  It is harmless if the values are scalars.

    >>> octave_code(sin(pi*x*y), assign_to="s")
    's = sin(pi*x.*y);'

    If you need a matrix product "*" or matrix power "^", you can specify the
    symbol as a ``MatrixSymbol``.

    >>> from sympy import Symbol, MatrixSymbol
    >>> n = Symbol('n', integer=True, positive=True)
    >>> A = MatrixSymbol('A', n, n)
    >>> octave_code(3*pi*A**3)
    '(3*pi)*A^3'

    This class uses several rules to decide which symbol to use a product.
    Pure numbers use "*", Symbols use ".*" and MatrixSymbols use "*".
    A HadamardProduct can be used to specify componentwise multiplication ".*"
    of two MatrixSymbols.  There is currently there is no easy way to specify
    scalar symbols, so sometimes the code might have some minor cosmetic
    issues.  For example, suppose x and y are scalars and A is a Matrix, then
    while a human programmer might write "(x^2*y)*A^3", we generate:

    >>> octave_code(x**2*y*A**3)
    '(x.^2.*y)*A^3'

    Matrices are supported using Octave inline notation.  When using
    ``assign_to`` with matrices, the name can be specified either as a string
    or as a ``MatrixSymbol``.  The dimensions must align in the latter case.

    >>> from sympy import Matrix, MatrixSymbol
    >>> mat = Matrix([[x**2, sin(x), ceiling(x)]])
    >>> octave_code(mat, assign_to='A')
    'A = [x.^2 sin(x) ceil(x)];'

    ``Piecewise`` expressions are implemented with logical masking by default.
    Alternatively, you can pass "inline=False" to use if-else conditionals.
    Note that if the ``Piecewise`` lacks a default term, represented by
    ``(expr, True)`` then an error will be thrown.  This is to prevent
    generating an expression that may not evaluate to anything.

    >>> from sympy import Piecewise
    >>> pw = Piecewise((x + 1, x > 0), (x, True))
    >>> octave_code(pw, assign_to=tau)
    'tau = ((x > 0).*(x + 1) + (~(x > 0)).*(x));'

    Note that any expression that can be generated normally can also exist
    inside a Matrix:

    >>> mat = Matrix([[x**2, pw, sin(x)]])
    >>> octave_code(mat, assign_to='A')
    'A = [x.^2 ((x > 0).*(x + 1) + (~(x > 0)).*(x)) sin(x)];'

    Custom printing can be defined for certain types by passing a dictionary of
    "type" : "function" to the ``user_functions`` kwarg.  Alternatively, the
    dictionary value can be a list of tuples i.e., [(argument_test,
    cfunction_string)].  This can be used to call a custom Octave function.

    >>> from sympy import Function
    >>> f = Function('f')
    >>> g = Function('g')
    >>> custom_functions = {
    ...   "f": "existing_octave_fcn",
    ...   "g": [(lambda x: x.is_Matrix, "my_mat_fcn"),
    ...         (lambda x: not x.is_Matrix, "my_fcn")]
    ... }
    >>> mat = Matrix([[1, x]])
    >>> octave_code(f(x) + g(x) + g(mat), user_functions=custom_functions)
    'existing_octave_fcn(x) + my_fcn(x) + my_mat_fcn([1 x])'

    Support for loops is provided through ``Indexed`` types. With
    ``contract=True`` these expressions will be turned into loops, whereas
    ``contract=False`` will just print the assignment expression that should be
    looped over:

    >>> from sympy import Eq, IndexedBase, Idx, ccode
    >>> len_y = 5
    >>> y = IndexedBase('y', shape=(len_y,))
    >>> t = IndexedBase('t', shape=(len_y,))
    >>> Dy = IndexedBase('Dy', shape=(len_y-1,))
    >>> i = Idx('i', len_y-1)
    >>> e = Eq(Dy[i], (y[i+1]-y[i])/(t[i+1]-t[i]))
    >>> octave_code(e.rhs, assign_to=e.lhs, contract=False)
    'Dy(i) = (y(i + 1) - y(i))./(t(i + 1) - t(i));'
    (   Rj   t   doprint(   R   t	   assign_toR   (    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   octave_code6  s    c         K  s   t  t |  |   d S(   s   Prints the Octave (or Matlab) representation of the given expression.

    See `octave_code` for the meaning of the optional arguments.
    N(   t   printRu  (   R   R   (    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   print_octave_code  s    N(   R`  t
   __future__R    R   t   sympy.codegen.astR   t
   sympy.coreR   R   R   R   t   sympy.core.compatibilityR   R   t   sympy.core.mulR	   t   sympy.printing.codeprinterR
   t   sympy.printing.precedenceR   R   Rc   R   R   R   Rj   Rd  Ru  Rw  (    (    (    s4   lib/python2.7/site-packages/sympy/printing/octave.pyt   <module>   sX   "
 