ó
    Š*£h}c  ã            	      ó$  • S r SSKJr  SSKJr  SSKJrJrJrJ	r	  SSK
Jr  SSKJr  SSKJr  SSKJrJr  SS	KJr  / S
Qr0 SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS _S!S"_S#S$_S%S&_S'S(_S)S*_S+S,_S-S.S/S0S1S2S3S4.Er " S5 S6\5      rS:S8 jrS9 rg7);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            	      óÊ  ^ • \ rS rSr% SrSrSrSSSS.r\" \	R                  40 S	0 S
S
S.D6r
S\S'   0 4U 4S jjrS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS rS  rS! rS" r S# r!\!r"\!r#\!r$S$ r%S% r&S& r'S' r(S( r)S) r*S* r+S+ r,S, r-S- r.S. r/S/ r0S0 r1S1 r2S2 r3S3 r4S4 r5S5 r6S6 r7S7 r8S8 r9S9 r:S: r;S; r<S< r=\==r>r?S= r@\@=rArBS> rCS? rDS@ rESArFU =rG$ )BÚOctaveCodePrinteréA   zD
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U ]  U5        [        [        [        [        5      5      U l        U R
                  R                  [        [        5      5        UR                  S0 5      nU R
                  R                  U5        g )Nr~   )	ÚsuperÚ__init__ÚdictÚzipÚknown_fcns_src1Úknown_functionsÚupdateÚknown_fcns_src2Úget)ÚselfÚsettingsÚ	userfuncsÚ	__class__s      €ÚR/home/mande/repo/quber/.venv/lib/python3.13/site-packages/sympy/printing/octave.pyr„   ÚOctaveCodePrinter.__init__Y   sb   ø€ Ü‰Ñ˜Ô"Ü#¤C¬¼Ó$IÓJˆÔØ×Ñ×#Ñ#¤D¬Ó$9Ô:Ø—L‘LÐ!1°2Ó6ˆ	Ø×Ñ×#Ñ# IÕ.ó    c                ó   • US-  $ )Né   © )rŒ   Úps     r�   Ú_rate_index_positionÚ&OctaveCodePrinter._rate_index_positiona   s   € Ø�‰sˆ
r’   c                ó   • SU-  $ )Nz%s;r•   )rŒ   Ú
codestrings     r�   Ú_get_statementÚ OctaveCodePrinter._get_statemente   s   € Ø�zÑ!Ð!r’   c                ó$   • SR                  U5      $ )Nz% {}©Úformat)rŒ   Útexts     r�   Ú_get_commentÚOctaveCodePrinter._get_commenti   s   € Ø�}‰}˜TÓ"Ð"r’   c                ó$   • SR                  X5      $ )Nz{} = {};rž   )rŒ   ÚnameÚvalues      r�   Ú_declare_number_constÚ'OctaveCodePrinter._declare_number_constm   s   € Ø× Ñ  Ó-Ð-r’   c                ó$   • U R                  U5      $ ©N)Úindent_code)rŒ   Úliness     r�   Ú_format_codeÚOctaveCodePrinter._format_codeq   s   € Ø×Ñ Ó&Ð&r’   c                óL   ^• UR                   u  mnU4S j[        U5       5       $ )Nc              3  óP   >#   • U  H  n[        T5        H  o"U4v •  M
     M     g 7fr©   )Úrange)Ú.0ÚjÚiÚrowss      €r�   Ú	<genexpr>Ú=OctaveCodePrinter._traverse_matrix_indices.<locals>.<genexpr>x   s   øé € ÐA¢˜1´U¸4·[°�A•±[‘¢ùs   ƒ#&)Úshaper°   )rŒ   ÚmatÚcolsr´   s      @r�   Ú_traverse_matrix_indicesÚ*OctaveCodePrinter._traverse_matrix_indicesu   s   ø€ à—Y‘Y‰
ˆˆdÜA¤ d¤ÓAÐAr’   c           	     óþ   • / n/ nU Hq  n[        U R                  UR                  UR                  S-   UR                  S-   /5      u  pVnUR                  SU< SU< SU< 35        UR                  S5        Ms     X#4$ )Né   zfor ú = Ú:Úend)ÚmapÚ_printÚlabelÚlowerÚupperÚappend)rŒ   ÚindicesÚ
open_linesÚclose_linesr³   ÚvarÚstartÚstops           r�   Ú_get_loop_opening_endingÚ*OctaveCodePrinter._get_loop_opening_ending{   sw   € Øˆ
ØˆÛˆAä" 4§;¡;Ø—W‘W˜aŸg™g¨™k¨1¯7©7°Q©;Ð7ó 9ÑˆC˜à×Ò³#³uºdÐCÔDØ×Ñ˜uÖ%ñ ð Ð&Ð&r’   c           	     óÖ  • UR                   (       aY  UR                  (       aH  [        R                  U-  R                  (       a&  SU R                  [        R                  * U-  5      -  $ [        U5      nUR                  5       u  p4US:  a  [        U* U5      nSnOSn/ n/ n/ nU R                  S;  a  UR                  5       n	O[        R                  " U5      n	U	 GHË  n
U
R                  (       Ga  U
R                  (       Ga   U
R                  R                   (       aå  U
R                  R"                  (       aÊ  U
R                  S:w  a1  UR%                  ['        U
R(                  U
R                  * SS95        MŸ  [+        U
R,                  S   R,                  5      S	:w  a0  [/        U
R(                  [        5      (       a  UR%                  U
5        UR%                  ['        U
R(                  U
R                  * 5      5        GM(  U
R                   (       a�  U
[        R0                  Lan  U
R2                  S	:w  a$  UR%                  [5        U
R2                  5      5        U
R6                  S	:w  a'  UR%                  [5        U
R6                  5      5        GM·  GMº  UR%                  U
5        GMÎ     U=(       d    [        R8                  /nU Vs/ s H  o°R;                  X²5      PM     nnU Vs/ s H  o°R;                  X²5      PM     nnU HP  n
U
R(                  U;   d  M  S
X×R=                  U
R(                  5         -  X×R=                  U
R(                  5      '   MR     S nU(       d
  X^" Xl5      -   $ [+        U5      S	:X  a+  US   R                   (       a  SOSnX^" Xl5      -   U-   US   -   $ [?        S U 5       5      (       a  SOSnX^" Xl5      -   U-   S
U" X}5      -  -   $ s  snf s  snf )Nz%sir   Ú-Ú )ÚoldÚnoneéÿÿÿÿF)Úevaluater½   z(%s)c                óŽ   • US   n[        S[        U 5      5       H&  nXS-
     R                  (       a  SOSnX$-   X   -   nM(     U$ )Nr   r½   Ú*ú.*)r°   ÚlenÚ	is_number)ÚaÚa_strÚrr³   Úmulsyms        r�   ÚmultjoinÚ.OctaveCodePrinter._print_Mul.<locals>.multjoin¿   sJ   € à�a‘ˆAÜ˜1œc !›fÖ%�Ø ! A¡#¡× 0× 0™°d�Ø‘J ¡Ñ)’ñ &ð ˆHr’   Ú/ú./c              3  ó8   #   • U  H  oR                   v •  M     g 7fr©   ©rÚ   )r±   Úbis     r�   rµ   Ú/OctaveCodePrinter._print_Mul.<locals>.<genexpr>Í   s   é € Ð9²q°§¦²qùó   ‚) 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_MulÚOctaveCodePrinter._print_Mul‡   s  € à�N�N˜t×0×0Ü—‘ Ñ%×1×1Ø˜4Ÿ;™;¬¯©Ð'7¸Ñ'<Ó=Ñ=Ð=ô ˜$Óˆà× Ñ Ó"‰ˆØˆq‹5Ü ˜r 1Ó%ˆDØ‰DàˆDàˆØˆàˆ	à�:‰:˜_Ó,Ø×*Ñ*Ó,‰Dô —=’= Ó&ˆDô ˆDØ×#×#Ð#¨¯¯¨¸¿¹×8L×8LØŸ™×,×,Ø—8‘8˜r“>Ø—H‘HœS §¡¨T¯X©X¨IÀÑFÖGä˜4Ÿ9™9 Q™<×,Ñ,Ó-°Ó2´zÀ$Ç)Á)ÌS×7QÑ7QØ!×(Ñ(¨Ô.Ø—H‘HœS §¡¨T¯X©X¨IÓ6×7Ø×!×! d´!·*±*Ò&<Ø—6‘6˜Q“;Ø—H‘HœX d§f¡fÓ-Ô.Ø—6‘6˜Q“;Ø—H‘HœX d§f¡fÓ-×.ò ð —‘˜—ñ ð" �L”!—%‘%�ˆá56Ó7²Q°×"Ñ" 1Ö+±QˆÐ7Ù56Ó7²Q°×"Ñ" 1Ö+±QˆÐ7ó ˆDØ�y‰y˜A�~Ø,2°U¿7¹7À4Ç9Á9Ó;MÑ5NÑ,N�—g‘g˜dŸi™iÓ(Ó)ñ ò
	ö Ø˜( 1Ó,Ñ,Ð,Ü�‹V�q‹[Ø˜a™DŸNŸN‘S°ˆFØ˜( 1Ó,Ñ,¨vÑ5¸¸a¹Ñ@Ð@äÑ9±qÓ9×9Ñ9‘S¸tˆFØ˜8 AÓ-Ñ-ØñØ#¡h¨qÓ&8Ñ8ñ9ð :ùò1 8ùÚ7s   ËO!Ë-O&c                óª   • U R                  UR                  5      nU R                  UR                  5      nUR                  nSR	                  X$U5      $ )Nz{} {} {})rÂ   ÚlhsÚrhsÚrel_oprŸ   )rŒ   rü   Úlhs_codeÚrhs_codeÚops        r�   Ú_print_RelationalÚ#OctaveCodePrinter._print_RelationalÑ   sB   € Ø—;‘;˜tŸx™xÓ(ˆØ—;‘;˜tŸx™xÓ(ˆØ�[‰[ˆØ× Ñ  ¨xÓ8Ð8r’   c                óî  • [        S UR                   5       5      (       a  SOSn[        U5      n[        UR                  S5      (       a  SU R                  UR                  5      -  $ UR                  (       a½  [        UR                  S5      (       aC  UR                  R                  (       a  SOSnS	U-   SU R                  UR                  5      -  -   $ [        UR                  S
5      (       aD  UR                  R                  (       a  SOSnS	U-   SU R                  UR                  U5      -  -   $ U R                  UR                  U5      < U< U R                  UR                  U5      < 3$ )Nc              3  ó8   #   • U  H  oR                   v •  M     g 7fr©   rä   )r±   r  s     r�   rµ   Ú/OctaveCodePrinter._print_Pow.<locals>.<genexpr>Ø   s   é € Ð>²I¨qŸ{ž{²Iù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_PowÚOctaveCodePrinter._print_Pow×   s  € ÜÑ>°D·I²IÓ>×>Ñ>‘CÀDˆ	ä˜$Óˆä˜Ÿ™ #×&Ñ&Ø §¡¨D¯I©IÓ 6Ñ6Ð6à××Ü˜DŸH™H d×+Ñ+Ø!ŸY™Y×0×0‘c°d�Ø˜S‘y :°·±¸D¿I¹IÓ0FÑ#FÑFÐFÜ˜DŸH™H b×)Ñ)Ø!ŸY™Y×0×0‘c°d�Ø˜S‘y 4¨$×*;Ñ*;¸D¿I¹IÀtÓ*LÑ#LÑLÐLà×,Ñ,¨T¯Y©Y¸Õ=ºyØ×,Ñ,¨T¯X©X°tÕ<ð>ð 	>r’   c                ó’   • [        U5      nU R                  UR                  U5      < SU R                  UR                  U5      < 3$ )Nr  )r   rù   ró   r5   ©rŒ   rü   r  s      r�   Ú_print_MatPowÚOctaveCodePrinter._print_MatPowë   s>   € Ü˜$ÓˆØ×+Ñ+¨D¯I©I°tÖ<Ø×+Ñ+¨D¯H©H°dÕ;ð=ð 	=r’   c                ó’   • [        U5      nU R                  UR                  U5      < SU R                  UR                  U5      < 3$ )Nz \ )r   rù   ÚmatrixÚvectorr  s      r�   Ú_print_MatrixSolveÚ$OctaveCodePrinter._print_MatrixSolveð   s@   € Ü˜$ÓˆØ!×.Ñ.¨t¯{©{¸DÖAØ!×.Ñ.¨t¯{©{¸DÕAðCð 	Cr’   c                ó   • g)NÚpir•   ©rŒ   rü   s     r�   Ú	_print_PiÚOctaveCodePrinter._print_Piõ   ó   € Ør’   c                ó   • g)NÚ1ir•   r'  s     r�   Ú_print_ImaginaryUnitÚ&OctaveCodePrinter._print_ImaginaryUnitù   r*  r’   c                ó   • g)Nzexp(1)r•   r'  s     r�   Ú_print_Exp1ÚOctaveCodePrinter._print_Exp1ý   s   € Ør’   c                ó   • g)Nz(1+sqrt(5))/2r•   r'  s     r�   Ú_print_GoldenRatioÚ$OctaveCodePrinter._print_GoldenRatio  s   € ð r’   c                óŠ  • SSK Jn  SSKJn  SSKJn  UR                  nUR                  nU R                  S   (       d{  [        UR                  U5      (       a`  / n/ nUR                   H-  u  pšUR                  U" XY5      5        UR                  U
5        M/     U" [        Xx5      6 nU R                  U5      $ U R                  S   (       a=  UR                  U5      (       d  UR                  U5      (       a  U R                  Xe5      $ U R                  U5      nU R                  U5      nU R!                  U< SU< 35      $ )Nr   )Ú
Assignment)Ú	Piecewise)ÚIndexedBaser€   r   r¾   )Úsympy.codegen.astr6  Ú$sympy.functions.elementary.piecewiser7  Úsympy.tensor.indexedr8  r	  r
  Ú	_settingsrõ   rô   rÆ   r†   rÂ   ÚhasÚ_doprint_loopsr›   )rŒ   rü   r6  r7  r8  r	  r
  ÚexpressionsÚ
conditionsrÿ   rþ   Útempr  r  s                 r�   Ú_print_AssignmentÚ#OctaveCodePrinter._print_Assignment  s  € Ý0ÝBÝ4à�h‰hˆØ�h‰hˆà�~‰~˜h×'¬J°t·x±xÀ×,KÑ,Kð ˆKØˆJØŸ(œ(‘�Ø×"Ñ"¡:¨cÓ#5Ô6Ø×!Ñ! !Ö$ñ #ñ œc +Ó:Ð;ˆDØ—;‘;˜tÓ$Ð$Ø�>‰>˜*×%¨3¯7©7°;×+?Ñ+?Ø—‘˜×$Ñ$ð ×&Ñ& sÓ0Ð0à—{‘{ 3Ó'ˆHØ—{‘{ 3Ó'ˆHØ×&Ñ&³HºhÐ'GÓHÐHr’   c                ó   • g)NÚinfr•   r'  s     r�   Ú_print_InfinityÚ!OctaveCodePrinter._print_Infinity$  ó   € Ør’   c                ó   • g)Nz-infr•   r'  s     r�   Ú_print_NegativeInfinityÚ)OctaveCodePrinter._print_NegativeInfinity(  ó   € Ør’   c                ó   • g)NÚNaNr•   r'  s     r�   Ú
_print_NaNÚOctaveCodePrinter._print_NaN,  rH  r’   c                óF   ^ • SSR                  U 4S jU 5       5      -   S-   $ )NÚ{ú, c              3  óF   >#   • U  H  nTR                  U5      v •  M     g 7fr©   ©rÂ   )r±   rÛ   rŒ   s     €r�   rµ   Ú0OctaveCodePrinter._print_list.<locals>.<genexpr>1  s   øé € Ð<²t°!˜tŸ{™{¨1Ÿ~˜~²tùó   ƒ!Ú})Újoinr'  s   ` r�   Ú_print_listÚOctaveCodePrinter._print_list0  s"   ø€ Ø�T—Y‘YÔ<±tÓ<Ó<Ñ<¸sÑBÐBr’   c                ó   • g)NÚtruer•   r'  s     r�   Ú_print_BooleanTrueÚ$OctaveCodePrinter._print_BooleanTrue7  rL  r’   c                ó   • g)NÚfalser•   r'  s     r�   Ú_print_BooleanFalseÚ%OctaveCodePrinter._print_BooleanFalse;  s   € Ør’   c                ó4   • [        U5      R                  5       $ r©   )ÚstrrÄ   r'  s     r�   Ú_print_boolÚOctaveCodePrinter._print_bool?  s   € Ü�4‹y�‰Ó Ð r’   c                ó~  ^ ^• TR                   TR                  4S:X  a  g[        R                  TR                  ;   a  STR                   < STR                  < S3$ TR                   TR                  4S:X  a  T R                  TS   5      $ SSR                  UU 4S	 j[        TR                   5       5       5      -  $ )
N)r   r   z[]zzeros(rS  Ú))r½   r½   z[%s]z; c           	   3  óž   >#   • U  H=  nS R                  TUSS24    Vs/ s H  nTR                  U5      PM     sn5      v •  M?     gs  snf 7f)Ú N)rY  rÂ   )r±   rÝ   rÛ   ÚArŒ   s      €€r�   rµ   Ú6OctaveCodePrinter._print_MatrixBase.<locals>.<genexpr>P  sI   øé € ð ":Ú+8 að #&§(¡(ÀAÀaÊÀdÂGÓ+LÂG¸q¨D¯K©K¸®NÁGÑ+L×"MÐ"MÚ+8ùò ,Mùs   ƒAŸA
ºA)r´   r¹   r   ÚZeror·   rÂ   rY  r°   )rŒ   rl  s   ``r�   Ú_print_MatrixBaseÚ#OctaveCodePrinter._print_MatrixBaseG  s“   ù€ à�F‰F�A—F‘FÐ˜vÓ%ØÜ�V‰V�q—w‘wÔØ&'§f¤f¨a¯f¬fÐ5Ð5Ø�f‰f�a—f‘fÐ Ó'à—;‘;˜q ™wÓ'Ð'Ø˜Ÿ	™	õ ":Ü+0°·±¬=ó":ó :ñ :ð 	:r’   c                ó°  • SSK Jn  UR                  5       nU" U Vs/ s H
  oDS   S-   PM     sn/5      nU" U Vs/ s H
  oDS   S-   PM     sn/5      nU" U Vs/ s H  oDS   PM	     sn/5      nSU R                  U5      < SU R                  U5      < SU R                  U5      < SUR                  < SUR
                  < S3$ s  snf s  snf s  snf )Nr   )ÚMatrixr½   é   zsparse(rS  ri  )Úsympy.matricesrr  Úcol_listrÂ   r´   r¹   )rŒ   rl  rr  ÚLÚkÚIÚJÚAIJs           r�   Ú_print_SparseRepMatrixÚ(OctaveCodePrinter._print_SparseRepMatrixT  s¶   € Ý)Ø�J‰J‹Lˆá¡qÓ)¢q !�q‘T˜A”X¡qÑ)Ð*Ó+ˆÙ¡qÓ)¢q !�q‘T˜A”X¡qÑ)Ð*Ó+ˆÙ¡QÓ'¢Q ˜”t¡QÑ'Ð(Ó)‰Ø/3¯{©{¸1®~¸t¿{¹{È1¾~Ø,0¯K©K¸Ö,<¸a¿f¼fÀaÇfÄfðNð 	Nùò *ùÚ)ùÚ's   �C	¼CÁCc                ó’   • U R                  UR                  [        S   SS9SUR                  S-   < SUR                  S-   < S3-   $ )NÚAtomT)ÚstrictÚ(r½   rS  ri  )rù   Úparentr   r³   r²   r'  s     r�   Ú_print_MatrixElementÚ&OctaveCodePrinter._print_MatrixElement_  sB   € Ø× Ñ  §¡¬j¸Ñ.@ÈÐ ÑNØ ŸF™F QœJ¨¯©°¬
Ð3ñ4ð 	4r’   c                ó  ^ • U 4S jnT R                  UR                  5      S-   U" UR                  UR                  R                  S   5      -   S-   U" UR                  UR                  R                  S   5      -   S-   $ )Nc                ó  >• U S   S-   nU S   nU S   nTR                  U5      nX1:X  a  SOTR                  U5      nUS:X  a  US:X  a  X1:X  a  gX#:X  a  U$ US-   U-   $ SR                  UTR                  U5      U45      $ )Nr   r½   rs  rÀ   r¿   )rÂ   rY  )r  ÚlimÚlÚhÚstepÚlstrÚhstrrŒ   s          €r�   ÚstrsliceÚ6OctaveCodePrinter._print_MatrixSlice.<locals>.strslicee  s�   ø€ Ø�!‘�q‘ˆAØ�!‘ˆAØ�Q‘4ˆDØ—;‘;˜q“>ˆDØ›H‘5¨$¯+©+°a«.ˆDØ�q‹yØ˜“6˜a›hØØ“6Ø�Kà #™:¨Ñ,Ð,à—x‘x  t§{¡{°4Ó'8¸$Ð ?Ó@Ð@r’   r€  r   rS  r½   ri  )rÂ   r�  Úrowslicer·   Úcolslice)rŒ   rü   rŒ  s   `  r�   Ú_print_MatrixSliceÚ$OctaveCodePrinter._print_MatrixSliced  s|   ø€ õ	Að —‘˜DŸK™KÓ(¨3Ñ.Ù˜Ÿ™¨¯©×(9Ñ(9¸!Ñ(<Ó=ñ>Ø@DñEá˜Ÿ™¨¯©×(9Ñ(9¸!Ñ(<Ó=ñ>à@CñDð 	Er’   c                óØ   • UR                    Vs/ s H  o R                  U5      PM     nnU R                  UR                  R                  5      < SSR	                  U5      < S3$ s  snf )Nr€  rS  ri  )rÇ   rÂ   ró   rÃ   rY  )rŒ   rü   r³   Úindss       r�   Ú_print_IndexedÚ OctaveCodePrinter._print_Indexedy  sI   € Ø)-¯ªÓ7ª A—‘˜Q–©ˆÐ7ØŸ;™; t§y¡y§¡Ö7¸¿¹À4¾ÐIÐIùò 8s   �A'c                ó^   ^ ^• [         S   mS[        UU 4S jUR                   5       5      -  $ )Nr   zdouble(%s == %s)c              3  óH   >#   • U  H  nTR                  UT5      v •  M     g 7fr©   )rù   )r±   r  rý   rŒ   s     €€r�   rµ   Ú:OctaveCodePrinter._print_KroneckerDelta.<locals>.<genexpr>€  s(   øé € ð *>Ú3<¨að +/×*;Ñ*;¸A¸t×*DÐ*DÚ3<ùs   ƒ")r   Útuplerô   )rŒ   rü   rý   s   ` @r�   Ú_print_KroneckerDeltaÚ'OctaveCodePrinter._print_KroneckerDelta~  s2   ù€ Ü˜%Ñ ˆØ!¤Eõ *>Ø37·9²9ó*>ó %>ñ >ð 	>r’   c                ó–   • SR                  UR                   Vs/ s H  nU R                  U[        U5      5      PM      sn5      $ s  snf )NrØ   )rY  rô   rù   r   )rŒ   rü   rC   s      r�   Ú_print_HadamardProductÚ(OctaveCodePrinter._print_HadamardProductƒ  sI   € Ø�y‰yØ%)§Y¢Yó0Ú%.˜cð ×+Ñ+¨C´¸DÓ1AÖBÙ%.ñ0ó 1ð 	1ùò 0s   š%Ac                ó¦   • [        U5      nSR                  U R                  UR                  U5      U R                  UR                  U5      /5      $ )Nz.**)r   rY  rù   ró   r5   r  s      r�   Ú_print_HadamardPowerÚ&OctaveCodePrinter._print_HadamardPower‡  sJ   € Ü˜$ÓˆØ�z‰zØ×Ñ˜dŸi™i¨Ó.Ø×Ñ˜dŸh™h¨Ó-ðó ð 	r’   c                ó¤   ^ • UR                   n[        U5      S:X  a  US   US   :X  a  US   /nSR                  U 4S jU 5       5      nSU-   S-   $ )Nrs  r   r½   rS  c              3  óF   >#   • U  H  nTR                  U5      v •  M     g 7fr©   rU  )r±   ÚnrŒ   s     €r�   rµ   Ú4OctaveCodePrinter._print_Identity.<locals>.<genexpr>’  s   øé € Ð4ªe¨�d—k‘k !—n�nªeùrW  zeye(ri  )r·   rÙ   rY  )rŒ   rü   r·   Úss   `   r�   Ú_print_IdentityÚ!OctaveCodePrinter._print_IdentityŽ  sT   ø€ Ø—
‘
ˆÜˆu‹:˜‹?˜u Q™x¨5°©8Ó3Ø˜1‘X�JˆEØ�I‰IÔ4©eÓ4Ó4ˆØ˜‰z˜CÑÐr’   c                ó–   • SR                  U R                  UR                  S   5      U R                  UR                  S   5      5      $ )Nz (gammainc({1}, {0}).*gamma({0}))r   r½   ©rŸ   rÂ   rô   r'  s     r�   Ú_print_lowergammaÚ#OctaveCodePrinter._print_lowergamma•  s>   € à1×8Ñ8Ø�K‰K˜Ÿ	™	 !™Ó% t§{¡{°4·9±9¸Q±<Ó'@óBð 	Br’   c                ó–   • SR                  U R                  UR                  S   5      U R                  UR                  S   5      5      $ )Nz)(gammainc({1}, {0}, 'upper').*gamma({0}))r   r½   rª  r'  s     r�   Ú_print_uppergammaÚ#OctaveCodePrinter._print_uppergamma›  s>   € Ø:×AÑAØ�K‰K˜Ÿ	™	 !™Ó% t§{¡{°4·9±9¸Q±<Ó'@óBð 	Br’   c                óf   • SU R                  UR                  S   [        R                  -  5      -  $ )Nzsinc(%s)r   )rÂ   rô   r   ÚPir'  s     r�   Ú_print_sincÚOctaveCodePrinter._print_sinc   s'   € à˜DŸK™K¨¯	©	°!©´Q·T±TÑ(9Ó:Ñ:Ð:r’   c                ó|   • SU R                  UR                  5      < SU R                  UR                  5      < S3$ )Núbesselh(z, 1, ri  ©rÂ   rì   Úargumentr'  s     r�   Ú_print_hankel1Ú OctaveCodePrinter._print_hankel1¥  ó.   � Ø'+§{¡{°4·:±:Ö'>Ø'+§{¡{°4·=±=Ö'AðCð 	Cr’   c                ó|   • SU R                  UR                  5      < SU R                  UR                  5      < S3$ )Nrµ  z, 2, ri  r¶  r'  s     r�   Ú_print_hankel2Ú OctaveCodePrinter._print_hankel2ª  rº  r’   c                óÎ   • SSK JnJn  UR                  nU" [        R
                  SU-  -  5      U" UR                  [        R                  -   U5      -  nU R                  U5      $ )Nr   )Úsqrtr/   rs  )	Úsympy.functionsr¿  r/   r·  r   r±  rì   ÚHalfrÂ   )rŒ   rü   r¿  r/   r  Úexpr2s         r�   Ú	_print_jnÚOctaveCodePrinter._print_jn°  óL   € ß1Ø�M‰MˆÙ”Q—T‘T˜1˜Q™3‘ZÓ ¡¨¯©´a·f±fÑ)<¸aÓ!@Ñ@ˆØ�{‰{˜5Ó!Ð!r’   c                óÎ   • SSK JnJn  UR                  nU" [        R
                  SU-  -  5      U" UR                  [        R                  -   U5      -  nU R                  U5      $ )Nr   )r¿  r1   rs  )	rÀ  r¿  r1   r·  r   r±  rì   rÁ  rÂ   )rŒ   rü   r¿  r1   r  rÂ  s         r�   Ú	_print_ynÚOctaveCodePrinter._print_yn·  rÅ  r’   c                óD   • SU R                  UR                  S   5      -  $ )Nzairy(0, %s)r   ©rÂ   rô   r'  s     r�   Ú_print_airyaiÚOctaveCodePrinter._print_airyai¾  ó   € Ø˜tŸ{™{¨4¯9©9°Q©<Ó8Ñ8Ð8r’   c                óD   • SU R                  UR                  S   5      -  $ )Nzairy(1, %s)r   rÊ  r'  s     r�   Ú_print_airyaiprimeÚ$OctaveCodePrinter._print_airyaiprimeÂ  rÍ  r’   c                óD   • SU R                  UR                  S   5      -  $ )Nzairy(2, %s)r   rÊ  r'  s     r�   Ú_print_airybiÚOctaveCodePrinter._print_airybiÆ  rÍ  r’   c                óD   • SU R                  UR                  S   5      -  $ )Nzairy(3, %s)r   rÊ  r'  s     r�   Ú_print_airybiprimeÚ$OctaveCodePrinter._print_airybiprimeÊ  rÍ  r’   c                ót   • UR                   u  p#US:w  a  U R                  U5      $ SU R                  U5      -  $ )Nr½   z
expint(%s))rô   Ú_print_not_supportedrÂ   )rŒ   rü   Úmur  s       r�   Ú_print_expintÚOctaveCodePrinter._print_expintÎ  s8   € Ø—	‘	‰ˆØ�‹7Ø×,Ñ,¨TÓ2Ð2Ø˜dŸk™k¨!›nÑ,Ð,r’   c                ó&  • [        UR                  5      S::  d   eSR                  U R                  UR                  R
                     SR                  [        UR                  5       Vs/ s H  o R                  U5      PM     sn5      S9$ s  snf )Nrs  z{name}({args})rS  )r¤   rô   )	rÙ   rô   rŸ   rˆ   r�   Ú__name__rY  ÚreversedrÂ   )rŒ   rü   r  s      r�   Ú_one_or_two_reversed_argsÚ+OctaveCodePrinter._one_or_two_reversed_argsÕ  sw   € Ü�4—9‘9‹~ Ó"Ð"Ð"Ø×&Ñ&Ø×%Ñ% d§n¡n×&=Ñ&=Ñ>Ø—‘´H¸T¿Y¹YÔ4GÓHÒ4G¨qŸK™K¨žNÑ4GÑHÓIð 'ð 
ð 	
ùâHs   Á+Bc                óð   • SR                  U R                  UR                  R                     U R	                  UR
                  S   5      U R	                  UR                  " UR
                  SS  6 5      S9$ )Nz{name}({arg1}, {arg2})r   r½   )r¤   Úarg1Úarg2)rŸ   rˆ   r�   rÝ  rÂ   rô   Úfuncr'  s     r�   Ú_nested_binary_math_funcÚ*OctaveCodePrinter._nested_binary_math_funcà  se   € Ø'×.Ñ.Ø×%Ñ% d§n¡n×&=Ñ&=Ñ>Ø—‘˜TŸY™Y q™\Ó*Ø—‘˜TŸYšY¨¯	©	°!°"¨Ð6Ó7ð /ð ð 	r’   c           
     óà  • UR                   S   R                  S:w  a  [        S5      e/ nU R                  S   (       a§  UR                   S S  VVs/ s H5  u  p4SR	                  U R                  U5      U R                  U5      5      PM7     nnnSU R                  UR                   S   R                  5      -  nSR                  U5      U-   S[        U5      -  -   nS	U-   S-   $ [        UR                   5       HÚ  u  nu  p4US
:X  a$  UR                  SU R                  U5      -  5        OWU[        UR                   5      S-
  :X  a  US:X  a  UR                  S5        O#UR                  SU R                  U5      -  5        U R                  U5      n	UR                  U	5        U[        UR                   5      S-
  :X  d  MÉ  UR                  S5        MÜ     SR                  U5      $ s  snnf )NrÔ   Tz¼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€   z({0}).*({1}) + (~({0})).*(r  z ...
ri  r€  r   zif (%s)r½   Úelsezelseif (%s)rÀ   Ú
)rô   ÚcondÚ
ValueErrorr<  rŸ   rÂ   rü   rY  rÙ   Ú	enumeraterÆ   )
rŒ   rü   r«   rÿ   rþ   ÚecpairsÚelastÚpwr³   Úcode0s
             r�   Ú_print_PiecewiseÚ"OctaveCodePrinter._print_Piecewiseê  sª  € Ø�9‰9�R‰=×Ñ Ó%ô ð /ó 0ð 0ð
 ˆØ�>‰>˜(×#ð $(§9¡9¨S¨b¡>ô3â#1™4˜1ð 4×:Ñ:ØŸ™ A›¨¯©°A«ö8á#1ð ñ 3ð ˜4Ÿ;™; t§y¡y°¡}×'9Ñ'9Ó:Ñ:ˆEØ—‘˜wÓ'¨%Ñ/°#´c¸'³lÑ2BÑBˆBð ˜‘8˜c‘>Ð!ä& t§y¡yÖ1‘	�‘6�AØ˜“6Ø—L‘L ¨T¯[©[¸«^Ñ!;Õ<Øœ#˜dŸi™i›.¨1Ñ,Ó,°°d³Ø—L‘L Õ(à—L‘L °·±¸Q³Ñ!?Ô@ØŸ™ A›�Ø—‘˜UÔ#Øœ˜DŸI™I›¨Ñ*Õ*Ø—L‘L Ö'ñ 2ð —9‘9˜UÓ#Ð#ùó)3s   Á<G*c                ó˜   • [        UR                  5      S:X  a!  SU R                  UR                  S   5      -  $ U R                  U5      $ )Nr½   zzeta(%s)r   )rÙ   rô   rÂ   rØ  r'  s     r�   Ú_print_zetaÚOctaveCodePrinter._print_zeta  sA   € Üˆt�y‰y‹>˜QÓØ §¡¨D¯I©I°a©LÓ 9Ñ9Ð9ð ×,Ñ,¨TÓ2Ð2r’   c           	     ól  ^• [        U[        5      (       a1  U R                  UR                  S5      5      nSR	                  U5      $ SnSnSnU Vs/ s H  ofR                  S5      PM     nnU V^s/ s H!  m[        [        U4S jU 5       5      5      PM#     nnU V^s/ s H!  m[        [        U4S jU 5       5      5      PM#     nn/ n	S	n
[        U5       HF  u  nmTS
;   a  U	R                  T5        M  X¨U   -  n
U	R                  X:-  < T< 35        X§U   -  n
MH     U	$ s  snf s  snf s  snf )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  ó<   >#   • U  H  n[        UT5      v •  M     g 7fr©   r   ©r±   rm   Úlines     €r�   rµ   Ú0OctaveCodePrinter.indent_code.<locals>.<genexpr>&  ó   øé € ÐBº	°"œV B¨×-Ð-º	ùó   ƒc              3  ó<   >#   • U  H  n[        UT5      v •  M     g 7fr©   r   rú  s     €r�   rµ   rü  (  rý  rþ  r   )rÑ   ré  )
rõ   re  rª   Ú
splitlinesrY  ÚlstripÚintÚanyrì  rÆ   )rŒ   ÚcodeÚ
code_linesÚtabÚ	inc_regexÚ	dec_regexrû  ÚincreaseÚdecreaseÚprettyÚlevelr¤  s         `     r�   rª   ÚOctaveCodePrinter.indent_code  s@  ø€ ô �dœC× Ñ Ø×)Ñ)¨$¯/©/¸$Ó*?Ó@ˆJØ—7‘7˜:Ó&Ð&àˆØIˆ	Ø3ˆ	ñ 15Ó6²¨—‘˜UÖ#±ˆÐ6ñ "&ô(Ú!%˜ô œÔB¹	ÓBÓBÖCÙ!%ð 	ð (ñ "&ô(Ú!%˜ô œÔB¹	ÓBÓBÖCÙ!%ð 	ð (ð ˆØˆÜ  –‰GˆAˆtØ�zÓ!Ø—‘˜dÔ#ÙØ˜a‘[Ñ ˆEØ�M‰M C£IªtÐ4Ô5Ø˜a‘[Ñ ŠEñ 'ð ˆùò! 7ùò(ùò(s   ÁD'Á3(D,Â"(D1)rˆ   )HrÝ  Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__ÚprintmethodÚlanguageÚ
_operatorsr…   r   r�   Ú__annotations__r„   r—   r›   r¡   r¦   r¬   rº   rÍ   r  r  r  r  r#  r(  r-  r0  r3  rB  rF  rJ  rO  rZ  Ú_print_tupleÚ_print_TupleÚ_print_Listr^  rb  rf  ro  r{  r‚  r�  r”  rš  r�  r   r§  r«  r®  r²  r¸  r¼  rÃ  rÇ  rË  rÏ  rÒ  rÕ  rÚ  rß  Ú_print_DiracDeltaÚ_print_LambertWrå  Ú
_print_MaxÚ
_print_Minrñ  rô  rª   Ú__static_attributes__Ú__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Ð6€J�ò"$òJ3÷ð r’   rr   Nc                ó6   • [        U5      R                  X5      $ )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"  7  s   € ôP ˜XÓ&×.Ñ.¨tÓ?Ð?r’   c                ó.   • [        [        U 40 UD65        g)z„Prints 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€ô8s˜ô sôlH@óV)r’   