
    wgc              	      "   d Z ddlmZ ddlmZ ddlmZmZmZm	Z	 ddl
mZ ddlmZ ddlmZ ddlmZmZ dd	lmZ g d
Zi 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/d0d1d2d3d4Z G d5 d6e      Zd:d8Zd9 Zy7);ai  
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.

    )annotations)Any)MulPowSRational)_keep_coeff)equal_valued)CodePrinter)
precedence
PRECEDENCEsearch)1sincostancotseccscasinacosacotatanatan2asecacscsinhcoshtanhcothcschsechasinhacoshatanhacothasechacscherfcerfierferfinverfcinvbesselibesseljbesselkbessely	bernoullibetaeulerexp	factorialfloorfresnelcfresnelsgammaharmoniclogpolylogsignzetalegendreAbsabsarganglebinomialbincoeffceilingceil
chebyshevu
chebyshevU
chebyshevt
chebyshevTChicoshintCicosint	conjugateconj
DiracDeltadirac	Heaviside	heavisideimimaglaguerre	laguerreLLambertWlambertwlilogintloggammagammalnMaxmaxminmodpsireal
pochhammersinhintsinint)MinMod	polygammareRisingFactorialShiSic            	          e Zd ZU dZdZdZddddZ eej                  fi di d	d	d
Z	de
d<   i f f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d! Zd" Z e Z!e Z"e 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/ Z0d0 Z1d1 Z2d2 Z3d3 Z4d4 Z5d5 Z6d6 Z7d7 Z8d8 Z9d9 Z:d: Z;d; Z<d< Z=e=xZ>Z?d= Z@e@xZAZBd> ZCd? ZDd@ ZE xZFS )AOctaveCodePrinterzL
    A printer to convert expressions to strings of Octave/Matlab code.
    _octaveOctave&|~)andornot   T)	precisionuser_functionscontractinlinezdict[str, Any]_default_settingsc                   t         |   |       t        t        t        t                    | _        | j
                  j                  t        t                     |j                  di       }| j
                  j                  |       y )Nr}   )	super__init__dictzipknown_fcns_src1known_functionsupdateknown_fcns_src2get)selfsettings	userfuncs	__class__s      Z/home/mcse/projects/flask/flask-venv/lib/python3.12/site-packages/sympy/printing/octave.pyr   zOctaveCodePrinter.__init__Y   sb    "#C$IJ##D$9:LL!126	##I.    c                    |dz  S )N    )r   ps     r   _rate_index_positionz&OctaveCodePrinter._rate_index_positiona   s    s
r   c                    d|z  S )Nz%s;r   )r   
codestrings     r   _get_statementz OctaveCodePrinter._get_statemente   s    z!!r   c                $    dj                  |      S )Nz% {}format)r   texts     r   _get_commentzOctaveCodePrinter._get_commenti   s    }}T""r   c                &    dj                  ||      S )Nz{} = {};r   )r   namevalues      r   _declare_number_constz'OctaveCodePrinter._declare_number_constm   s      u--r   c                $    | j                  |      S N)indent_code)r   liness     r   _format_codezOctaveCodePrinter._format_codeq   s    &&r   c                J    |j                   \  }fdt        |      D        S )Nc              3  F   K   | ]  }t              D ]  }||f 
  y wr   )range).0jirowss      r   	<genexpr>z=OctaveCodePrinter._traverse_matrix_indices.<locals>.<genexpr>x   s%     A1U4[AAAAs   !)shaper   )r   matcolsr   s      @r   _traverse_matrix_indicesz*OctaveCodePrinter._traverse_matrix_indicesu   s    YY
dAdAAr   c           	         g }g }|D ]n  }t        | j                  |j                  |j                  dz   |j                  dz   g      \  }}}|j                  d|d|d|       |j                  d       p ||fS )N   zfor  = :end)map_printlabellowerupperappend)r   indices
open_linesclose_linesr   varstartstops           r   _get_loop_opening_endingz*OctaveCodePrinter._get_loop_opening_ending{   s    
 	&A"4;;WWaggk177Q;7 9C#udCDu%	& ;&&r   c                <   |j                   rO|j                  rCt        j                  |z  j                  r&d| j                  t        j                   |z        z  S t        |      }|j                         \  }}|dk  rt        | |      }d}nd}g }g }g }| j                  dvr|j                         }	nt        j                  |      }	|	D ]  }
|
j                  r|
j                  r|
j                  j                   r|
j                  j"                  r|
j                  dk7  r3|j%                  t'        |
j(                  |
j                   d             t+        |
j,                  d   j,                        d	k7  r+t/        |
j(                  t              r|j%                  |
       |j%                  t'        |
j(                  |
j                                |
j                   r||
t        j0                  urj|
j2                  d	k7  r$|j%                  t5        |
j2                               |
j6                  d	k7  sn|j%                  t5        |
j6                               |j%                  |
        |xs t        j8                  g}|D cg c]  }| j;                  ||       }}|D cg c]  }| j;                  ||       }}|D ]N  }
|
j(                  |v sd
||j=                  |
j(                           z  ||j=                  |
j(                        <   P d }|s| |||      z   S t+        |      d	k(  r(|d   j                   rdnd}| |||      z   |z   |d   z   S t?        d |D              rdnd}| |||      z   |z   d
 |||      z  z   S c c}w c c}w )Nz%sir   - )oldnoneF)evaluater   z(%s)c                    |d   }t        dt        |             D ]#  }| |dz
     j                  rdnd}||z   ||   z   }% |S )Nr   r   *.*)r   len	is_number)aa_strrr   mulsyms        r   multjoinz.OctaveCodePrinter._print_Mul.<locals>.multjoin   sU    aA1c!f% * !!A# 0 0dJq)* Hr   /./c              3  4   K   | ]  }|j                     y wr   r   )r   bis     r   r   z/OctaveCodePrinter._print_Mul.<locals>.<genexpr>   s     99   ) r   is_imaginaryr   ImaginaryUnit
is_Integerr   r   as_coeff_Mulr	   orderas_ordered_factorsr   	make_argsis_commutativeis_Powr5   is_Rationalis_negativer   r   baser   args
isinstanceInfinityr   r   qOneparenthesizeindexall)r   exprpreccer>   r   b	pow_parenr   itemxr   b_strr   divsyms                   r   
_print_MulzOctaveCodePrinter._print_Mul   s   NNt00%114;;'7'<=== $  "1q5r1%DDD	::_,**,D ==&D  	D##8L8L,,88r>HHSTXXIFG499Q<,,-2z$))S7Q!((.HHSTXXI67!!d!**&<66Q;HHXdff-.66Q;HHXdff-.	" L!%%567""1d+77567""1d+77  	ODyyA~,2U177499;M5N,Naggdii()	O
	 (1e,,,Vq[aDNNSF(1e,,v5a@@9q99StF8Au--#hq%&889 :1 87s   N-Nc                    | j                  |j                        }| j                  |j                        }|j                  }dj	                  |||      S )Nz{} {} {})r   lhsrhsrel_opr   )r   r   lhs_coderhs_codeops        r   _print_Relationalz#OctaveCodePrinter._print_Relational   sD    ;;txx(;;txx([[  2x88r   c                   t        d |j                  D              rdnd}t        |      }t        |j                  d      rd| j                  |j                        z  S |j                  rt        |j                  d      r>|j                  j                  rdnd}d	|z   d| j                  |j                        z  z   S t        |j                  d
      r?|j                  j                  rdnd}d	|z   d| j                  |j                  |      z  z   S | j                  |j                  |      || j                  |j                  |      S )Nc              3  4   K   | ]  }|j                     y wr   r   )r   r   s     r   r   z/OctaveCodePrinter._print_Pow.<locals>.<genexpr>   s     >qq{{>r   ^z.^g      ?zsqrt(%s)g      r   r   1r   %s)
r   r   r   r
   r5   r   r   r   r   r   )r   r   	powsymbolPRECsyms        r   
_print_PowzOctaveCodePrinter._print_Pow   s   >DII>>CD	$#&DII 666DHHd+!YY00cdSy:DII0F#FFFDHHb)!YY00cdSy4$*;*;DIIt*L#LLL,,TYY=y,,TXXt<> 	>r   c                    t        |      }| j                  |j                  |      d| j                  |j                  |      S )Nr  )r   r   r   r5   r   r   r	  s      r   _print_MatPowzOctaveCodePrinter._print_MatPow   s>    $++DIIt<++DHHd;= 	=r   c                    t        |      }| j                  |j                  |      d| j                  |j                  |      S )Nz \ )r   r   matrixvectorr  s      r   _print_MatrixSolvez$OctaveCodePrinter._print_MatrixSolve   s@    $!..t{{DA!..t{{DAC 	Cr   c                     y)Npir   r   r   s     r   	_print_PizOctaveCodePrinter._print_Pi       r   c                     y)N1ir   r  s     r   _print_ImaginaryUnitz&OctaveCodePrinter._print_ImaginaryUnit   r  r   c                     y)Nzexp(1)r   r  s     r   _print_Exp1zOctaveCodePrinter._print_Exp1   s    r   c                     y)Nz(1+sqrt(5))/2r   r  s     r   _print_GoldenRatioz$OctaveCodePrinter._print_GoldenRatio  s     r   c                X   ddl m} ddlm} ddlm} |j                  }|j                  }| j                  d   swt        |j                  |      rag }g }|j                  D ].  \  }	}
|j                   |||	             |j                  |
       0  |t        ||       }| j                  |      S | j                  d   r4|j                  |      s|j                  |      r| j                  ||      S | j                  |      }| j                  |      }| j!                  |d|      S )Nr   )
Assignment)	Piecewise)IndexedBaser   r~   r   )sympy.codegen.astr   $sympy.functions.elementary.piecewiser!  sympy.tensor.indexedr"  r   r   	_settingsr   r   r   r   r   has_doprint_loopsr   )r   r   r   r!  r"  r   r   expressions
conditionsr   r   tempr   r   s                 r   _print_Assignmentz#OctaveCodePrinter._print_Assignment  s   0B4hhhh~~h'Jtxx,K KJ(( %A"":c1#56!!!$% c+z:;D;;t$$>>*%377;+?$ &&sC00{{3'H{{3'H&&Hh'GHHr   c                     y)Ninfr   r  s     r   _print_Infinityz!OctaveCodePrinter._print_Infinity$      r   c                     y)Nz-infr   r  s     r   _print_NegativeInfinityz)OctaveCodePrinter._print_NegativeInfinity(      r   c                     y)NNaNr   r  s     r   
_print_NaNzOctaveCodePrinter._print_NaN,  r0  r   c                D     ddj                   fd|D              z   dz   S )N{, c              3  @   K   | ]  }j                  |        y wr   r   )r   r   r   s     r   r   z0OctaveCodePrinter._print_list.<locals>.<genexpr>1  s     <!t{{1~<   })joinr  s   ` r   _print_listzOctaveCodePrinter._print_list0  s"    TYY<t<<<sBBr   c                     y)Ntruer   r  s     r   _print_BooleanTruez$OctaveCodePrinter._print_BooleanTrue7  r3  r   c                     y)Nfalser   r  s     r   _print_BooleanFalsez%OctaveCodePrinter._print_BooleanFalse;  s    r   c                4    t        |      j                         S r   )strr   r  s     r   _print_boolzOctaveCodePrinter._print_bool?  s    4y  r   c                p    j                   j                  fdk(  ryt        j                  j                  v rdj                   dj                  dS j                   j                  fdk(  r j                  d         S ddj                   fd	t        j                         D              z  S )
N)r   r   z[]zzeros(r9  ))r   r   z[%s]z; c           	   3     K   | ]9  }d j                  |ddf   D cg c]  }j                  |       c}       ; yc c}w w) N)r>  r   )r   r   r   Ar   s      r   r   z6OctaveCodePrinter._print_MatrixBase.<locals>.<genexpr>P  s@      ":&' #&((AadG+LqDKKN+L"M ":+Ls   AA
A)r   r   r   Zeror   r   r>  r   )r   rM  s   ``r   _print_MatrixBasez#OctaveCodePrinter._print_MatrixBaseG  s    FFAFFv%VVqww&'ffaff55ffaff';;qw''		 ":+0=": : : 	:r   c                   ddl m} |j                         } ||D cg c]
  }|d   dz    c}g      } ||D cg c]
  }|d   dz    c}g      } ||D cg c]  }|d   	 c}g      }d| j                  |      d| j                  |      d| j                  |      d|j                  d|j
                  dS c c}w c c}w c c}w )Nr   )Matrixr      zsparse(r9  rJ  )sympy.matricesrQ  col_listr   r   r   )r   rM  rQ  LkIJAIJs           r   _print_SparseRepMatrixz(OctaveCodePrinter._print_SparseRepMatrixT  s    )JJLq)!QqTAX)*+q)!QqTAX)*+Q'qt'()/3{{1~t{{1~,0KK,<affaffN 	N *)'s   B>CCc                    | j                  |j                  t        d   d      d|j                  dz   d|j                  dz   dz   S )NAtomT)strict(r   r9  rJ  )r   parentr   r   r   r  s     r   _print_MatrixElementz&OctaveCodePrinter._print_MatrixElement_  sB      j.@ N FFQJ
34 	4r   c                     fd} j                  |j                        dz    ||j                  |j                  j                  d         z   dz    ||j                  |j                  j                  d         z   dz   S )Nc                    | d   dz   }| d   }| d   }j                  |      }||k(  rdnj                  |      }|dk(  r|dk(  r||k(  ry||k(  r|S |dz   |z   S dj                  |j                  |      |f      S )Nr   r   rR  r   r   )r   r>  )r   limlhsteplstrhstrr   s          r   strslicez6OctaveCodePrinter._print_MatrixSlice.<locals>.strslicee  s    !qA!AQ4D;;q>DH5$++a.Dqy6a3h6K#:,,xxt{{4'8$ ?@@r   r^  r   r9  r   rJ  )r   r_  rowslicer   colslice)r   r   ri  s   `  r   _print_MatrixSlicez$OctaveCodePrinter._print_MatrixSliced  s|    	A DKK(3.(9(9!(<=>@DE(9(9!(<=>@CD 	Er   c                    |j                   D cg c]  }| j                  |       }}| j                  |j                  j                        ddj	                  |      dS c c}w )Nr^  r9  rJ  )r   r   r   r   r>  )r   r   r   indss       r   _print_Indexedz OctaveCodePrinter._print_Indexedy  sJ    )-7AQ77;;tyy74II 8s   A#c                8    | j                  |j                        S r   )r   r   r  s     r   
_print_IdxzOctaveCodePrinter._print_Idx~  s    {{4::&&r   c                \     t         d   dt         fd|j                  D              z  S )Nr   zdouble(%s == %s)c              3  B   K   | ]  }j                  |        y wr   )r   )r   r   r   r   s     r   r   z:OctaveCodePrinter._print_KroneckerDelta.<locals>.<genexpr>  s&      *>./ +/*;*;At*D *>s   )r   tupler   )r   r   r   s   ` @r   _print_KroneckerDeltaz'OctaveCodePrinter._print_KroneckerDelta  s2    % !E *>3799*> %> > 	>r   c                    dj                  |j                  D cg c]  }| j                  |t        |             c}      S c c}w )Nr   )r>  r   r   r   )r   r   rC   s      r   _print_HadamardProductz(OctaveCodePrinter._print_HadamardProduct  sD    yy%)YY0! ++CD1AB 0 1 	1 0s   "Ac                    t        |      }dj                  | j                  |j                  |      | j                  |j                  |      g      S )Nz.**)r   r>  r   r   r5   r  s      r   _print_HadamardPowerz&OctaveCodePrinter._print_HadamardPower  sJ    $zzdii.dhh-  	r   c                     |j                   }t        |      dk(  r|d   |d   k(  r|d   g}dj                   fd|D              }d|z   dz   S )NrR  r   r   r9  c              3  @   K   | ]  }j                  |        y wr   r;  )r   nr   s     r   r   z4OctaveCodePrinter._print_Identity.<locals>.<genexpr>  s     4dkk!n4r<  zeye(rJ  )r   r   r>  )r   r   r   ss   `   r   _print_Identityz!OctaveCodePrinter._print_Identity  sT    

u:?uQx5831XJEII4e44zCr   c                    dj                  | j                  |j                  d         | j                  |j                  d               S )Nz (gammainc({1}, {0}).*gamma({0}))r   r   r   r   r   r  s     r   _print_lowergammaz#OctaveCodePrinter._print_lowergamma  s>    188KK		!%t{{499Q<'@B 	Br   c                    dj                  | j                  |j                  d         | j                  |j                  d               S )Nz)(gammainc({1}, {0}, 'upper').*gamma({0}))r   r   r  r  s     r   _print_uppergammaz#OctaveCodePrinter._print_uppergamma  s>    :AAKK		!%t{{499Q<'@B 	Br   c                f    d| j                  |j                  d   t        j                  z        z  S )Nzsinc(%s)r   )r   r   r   Pir  s     r   _print_sinczOctaveCodePrinter._print_sinc  s'    DKK		!QTT(9:::r   c                x    d| j                  |j                        d| j                  |j                        dS )Nbesselh(z, 1, rJ  r   r   argumentr  s     r   _print_hankel1z OctaveCodePrinter._print_hankel1  .    '+{{4::'>'+{{4=='AC 	Cr   c                x    d| j                  |j                        d| j                  |j                        dS )Nr  z, 2, rJ  r  r  s     r   _print_hankel2z OctaveCodePrinter._print_hankel2  r  r   c                    ddl m}m} |j                  } |t        j
                  d|z  z         ||j                  t        j                  z   |      z  }| j                  |      S )Nr   )sqrtr/   rR  )	sympy.functionsr  r/   r  r   r  r   Halfr   )r   r   r  r/   r   expr2s         r   	_print_jnzOctaveCodePrinter._print_jn  L    1MMQTT1Q3Z aff)<a!@@{{5!!r   c                    ddl m}m} |j                  } |t        j
                  d|z  z         ||j                  t        j                  z   |      z  }| j                  |      S )Nr   )r  r1   rR  )	r  r  r1   r  r   r  r   r  r   )r   r   r  r1   r   r  s         r   	_print_ynzOctaveCodePrinter._print_yn  r  r   c                D    d| j                  |j                  d         z  S )Nzairy(0, %s)r   r   r   r  s     r   _print_airyaizOctaveCodePrinter._print_airyai      t{{499Q<888r   c                D    d| j                  |j                  d         z  S )Nzairy(1, %s)r   r  r  s     r   _print_airyaiprimez$OctaveCodePrinter._print_airyaiprime  r  r   c                D    d| j                  |j                  d         z  S )Nzairy(2, %s)r   r  r  s     r   _print_airybizOctaveCodePrinter._print_airybi  r  r   c                D    d| j                  |j                  d         z  S )Nzairy(3, %s)r   r  r  s     r   _print_airybiprimez$OctaveCodePrinter._print_airybiprime  r  r   c                t    |j                   \  }}|dk7  r| j                  |      S d| j                  |      z  S )Nr   z
expint(%s))r   _print_not_supportedr   )r   r   mur   s       r   _print_expintzOctaveCodePrinter._print_expint  s:    		A7,,T22dkk!n,,r   c                &   t        |j                        dk  sJ dj                  | j                  |j                  j
                     dj                  t        |j                        D cg c]  }| j                  |       c}            S c c}w )NrR  z{name}({args})r9  )r   r   )	r   r   r   r   r   __name__r>  reversedr   )r   r   r   s      r   _one_or_two_reversed_argsz+OctaveCodePrinter._one_or_two_reversed_args  ss    499~"""&&%%dnn&=&=>HTYY4GHqDKKNHI ' 
 	
Hs   *Bc                    dj                  | j                  |j                  j                     | j	                  |j
                  d         | j	                   |j                  |j
                  dd               S )Nz{name}({arg1}, {arg2})r   r   )r   arg1arg2)r   r   r   r  r   r   funcr  s     r   _nested_binary_math_funcz*OctaveCodePrinter._nested_binary_math_func  sg    '..%%dnn&=&=>TYYq\*YTYY		!"67 /  	r   c           
        |j                   d   j                  dk7  rt        d      g }| j                  d   r|j                   d d D cg c]5  \  }}dj	                  | j                  |      | j                  |            7 }}}d| j                  |j                   d   j                        z  }dj                  |      |z   dt        |      z  z   }d	|z   dz   S t        |j                         D ]  \  }\  }}|d
k(  r$|j                  d| j                  |      z         nU|t        |j                         dz
  k(  r|dk(  r|j                  d       n#|j                  d| j                  |      z         | j                  |      }	|j                  |	       |t        |j                         dz
  k(  s|j                  d        dj                  |      S c c}}w )Nr   TzAll 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   z({0}).*({1}) + (~({0})).*(r  z ...
rJ  r^  r   zif (%s)r   elsezelseif (%s)r   
)r   cond
ValueErrorr&  r   r   r   r>  r   	enumerater   )
r   r   r   r   r   ecpairselastpwr   code0s
             r   _print_Piecewisez"OctaveCodePrinter._print_Piecewise  s   99R=%  / 0 0
 >>(# $(99Sb>31a 4::AA8 3G 3 4;;tyy}'9'9::Ew'%/#c'l2BBB 8c>!&tyy1 
(	6Aq6LLT[[^!;<#dii.1,,dLL(LLQ!?@AU#DII**LL'
( 99U##)3s   :Gc                    t        |j                        dk(  r!d| j                  |j                  d         z  S | j                  |      S )Nr   zzeta(%s)r   )r   r   r   r  r  s     r   _print_zetazOctaveCodePrinter._print_zeta  sA    tyy>QDIIaL 999 ,,T22r   c           	     F   t        |t              r1| j                  |j                  d            }dj	                  |      S d}d}d}|D cg c]  }|j                  d       }}|D cg c]  t        t        fd|D                    ! }}|D cg c]  t        t        fd|D                    ! }}g }	d	}
t        |      D ]C  \  }d
v r|	j                         |
||   z  }
|	j                  ||
z         |
||   z  }
E |	S c c}w c c}w c c}w )z0Accepts a string of code or a list of code linesTr   z  )z
^function z^if ^elseif ^else$z^for )z^end$r  r  z 	c              3  6   K   | ]  }t        |        y wr   r   r   rm   lines     r   r   z0OctaveCodePrinter.indent_code.<locals>.<genexpr>*       B"VB-B   c              3  6   K   | ]  }t        |        y wr   r   r  s     r   r   z0OctaveCodePrinter.indent_code.<locals>.<genexpr>,  r  r  r   )r   r  )
r   rG  r   
splitlinesr>  lstripintanyr  r   )r   code
code_linestab	inc_regex	dec_regexr  increasedecreaseprettylevelr|  s         `     r   r   zOctaveCodePrinter.indent_code  sC    dC ))$//$*?@J77:&&I	3	 156U#66 "&( B	BBC ( ( "&( B	BBC ( (   	!GAtz!d#Xa[ EMMCIt45Xa[ E	! ! 7((s   D,$D$D)Gr  
__module____qualname____doc__printmethodlanguage
_operatorsr   r   r   __annotations__r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r  r,  r/  r2  r6  r?  _print_tuple_print_Tuple_print_ListrB  rE  rH  rO  rZ  r`  rl  ro  rq  ru  rw  ry  r~  r  r  r  r  r  r  r  r  r  r  r  r  r  _print_DiracDelta_print_LambertWr  
_print_Max
_print_Minr  r  r   __classcell__)r   s   @r   rr   rr   A   s    KH J )-[-J-J )	O )~  !# /"#.'B	'H:T9>(=
C
I:CLLK!
:N4
E*J
'>
1 BB
;
C
C""9999-
 +DC 76J"$J3r   rr   Nc                8    t        |      j                  | |      S )a  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
    >>> 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
    >>> 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));'
    )rr   doprint)r   	assign_tor   s      r   octave_coder  ;  s    P X&..tY??r   c                .    t        t        | fi |       y)zPrints the Octave (or Matlab) representation of the given expression.

    See `octave_code` for the meaning of the optional arguments.
    N)printr  )r   r   s     r   print_octave_coder    s    
 
+d
'h
'(r   r   )r  
__future__r   typingr   
sympy.corer   r   r   r   sympy.core.mulr	   sympy.core.numbersr
   sympy.printing.codeprinterr   sympy.printing.precedencer   r   rm   r   r   r   rr   r  r  r   r   r   <module>r     s5  
 #  , , & + 2 < :	5	7 
 v	
 , , 
9 	(  '  	&  
 	(  	!" 
5#$ 
#
18w wtH@V)r   