Ë
    7^(h}c  ã            	      ó"  — 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<e<xZ=Z>d<„ Z?e?xZ@ZAd=„ ZBd>„ ZCd?„ ZDˆ xZES )@Ú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      €úS/var/www/skyplay_api_hub/venv/lib/python3.12/site-packages/sympy/printing/octave.pyrƒ   zOctaveCodePrinter.__init__Y   sb   ø€ Ü‰Ñ˜Ô"Ü#¤C¬¼Ó$IÓJˆÔØ×Ñ×#Ñ#¤D¬Ó$9Ô:Ø—L‘LÐ!1°2Ó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%   øè ø€ ÒA˜1´U¸4³[ÒA°��A”ÐA�ÑAùs   ƒ!)Úshaper©   )r‹   ÚmatÚcolsr­   s      @r�   Ú_traverse_matrix_indicesz*OctaveCodePrinter._traverse_matrix_indicesu   s   ø€ à—Y‘Y‰
ˆˆ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§;¡;Ø—W‘W˜aŸg™g¨™k¨1¯7©7°Q©;Ð7ó 9ÑˆC�˜à×Ò²#²u¹dÐ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ÚnoneéÿÿÿÿF)Ú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Ü˜1œc !›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  € à�NŠN˜t×0Ò0Ü—‘ Ñ%×1Ò1Ø˜4Ÿ;™;¬¯©Ð'7¸Ñ'<Ó=Ñ=Ð=ô ˜$Óˆà× Ñ Ó"‰ˆˆ1Øˆ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Ø!×(Ñ(¨Ô.Ø—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°�×"Ñ" 1 dÕ+Ð7ˆÐ7Ø56Ö7°�×"Ñ" 1 dÕ+Ð7ˆÐ7ð ò 	OˆDØ�y‰y˜AŠ~Ø,2°U¸1¿7¹7À4Ç9Á9Ó;MÑ5NÑ,N��a—g‘g˜dŸi™iÓ(Ò)ð	Oò
	ñ Ø™( 1 eÓ,Ñ,Ð,Ü�‹V�qŠ[Ø˜a™DŸNšN‘S°ˆFØ™( 1 eÓ,Ñ,¨vÑ5¸¸a¹Ñ@Ð@äÑ9°qÔ9Ô9‘S¸tˆFØ™8 A uÓ-Ñ-ØñØ#¡h¨q°%Ó&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   € Ø—;‘;˜tŸx™xÓ(ˆØ—;‘;˜tŸx™xÓ(ˆØ�[‰[ˆØ× Ñ  ¨2¨xÓ8Ð8r�   c                ó¢  — t        d„ |j                  D «       «      rdnd}t        |«      }t        |j                  d«      rd| j                  |j                  «      z  S |j                  r©t        |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   è ø€ Ò>¨q˜qŸ{�{Ñ>ù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  € ÜÑ>°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                óŽ   — t        |«      }| j                  |j                  |«      ›d| j                  |j                  |«      ›�S )Nr  )r   rí   rç   r5   ©r‹   rð   r	  s      r�   Ú_print_MatPowzOctaveCodePrinter._print_MatPowë   s>   € Ü˜$ÓˆØ×+Ñ+¨D¯I©I°tÕ<Ø×+Ñ+¨D¯H©H°dÔ;ð=ð 	=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à�h‰hˆØ�h‰hˆà�~‰~˜hÒ'¬J°t·x±xÀÔ,Kð ˆKØˆJØŸ(™(ò %‘��AØ×"Ñ"¡:¨c°1Ó#5Ô6Ø×!Ñ! !Õ$ð%ñ œc +¨zÓ:Ð;ˆDØ—;‘;˜tÓ$Ð$Ø�>‰>˜*Ò%¨3¯7©7°;Ô+?Ø—‘˜Ô$ð ×&Ñ& s¨CÓ0Ð0à—{‘{ 3Ó'ˆHØ—{‘{ 3Ó'ˆHØ×&Ñ&²H¹hÐ'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"   ø€ Ø�T—Y‘YÓ<°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   € Ü�4‹y�‰Ó Ð 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@   øè ø€ ò ":Ø&'ð #&§(¡(ÀAÀaÊÀdÁGÖ+L¸q¨D¯K©K¸­NÒ+L×"Mñ ":ùÒ+Lùs   ƒAžA
¶A)r­   r±   r   ÚZeror¯   r¹   r>  r©   )r‹   rM  s   ``r�   Ú_print_MatrixBasez#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                óš  — 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°   € Ý)Ø�J‰J‹Lˆá qÖ) !�Q�q‘T˜A“XÒ)Ð*Ó+ˆÙ qÖ) !�Q�q‘T˜A“XÒ)Ð*Ó+ˆÙ QÖ' �q˜“tÒ'Ð(Ó)‰Ø/3¯{©{¸1­~¸t¿{¹{È1½~Ø,0¯K©K¸Õ,<¸a¿f»fÀaÇfÃfð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Ø ŸF™F Q›J¨¯©°«
Ð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Ø�Q‘4ˆDØ—;‘;˜q“>ˆDØ šH‘5¨$¯+©+°a«.ˆDØ�qŠyØ˜’6˜a 3šhØØ˜’6Ø�Kà #™:¨Ñ,Ð,à—x‘x  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ð —‘˜DŸK™KÓ(¨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   € Ø)-¯©Ö7 A�—‘˜Q•Ð7ˆÐ7ØŸ;™; t§y¡y§¡Õ7¸¿¹À4½ÐIÐIùò 8s   �A#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&   øè ø€ ò *>Ø./ð +/×*;Ñ*;¸A¸t×*Dñ *>ùs   ƒ)r   Útuplerè   )r‹   rð   rñ   s   ` @r�   Ú_print_KroneckerDeltaz'OctaveCodePrinter._print_KroneckerDelta~  s2   ù€ Ü˜%Ñ ˆØ!¤Eô *>Ø37·9±9ô*>ó %>ñ >ð 	>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   € Ø�y‰yØ%)§Y¡Yö0Ø!ð ×+Ñ+¨C´¸DÓ1AÕ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   € Ü˜$ÓˆØ�z‰zØ×Ñ˜dŸi™i¨Ó.Ø×Ñ˜dŸh™h¨Ó-ðó ð 	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¨�d—k‘k !—nÑ4ùr<  zeye(rJ  )r¯   rÏ   r>  )r‹   rð   r¯   Úss   `   r�   Ú_print_Identityz!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                ó–   — 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Ø�K‰K˜Ÿ	™	 !™Ó% t§{¡{°4·9±9¸Q±<Ó'@ó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Ø�K‰K˜Ÿ	™	 !™Ó% t§{¡{°4·9±9¸Q±<Ó'@ó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'   € à˜DŸK™K¨¯	©	°!©´Q·T±TÑ(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Ø�M‰MˆÙ”Q—T‘T˜1˜Q™3‘ZÓ ¡¨¯©´a·f±fÑ)<¸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Ÿ{™{¨4¯9©9°Q©<Ó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Ø˜dŸk™k¨!›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   € Ü�4—9‘9‹~ Ò"Ð"Ð"Ø×&Ñ&Ø×%Ñ% d§n¡n×&=Ñ&=Ñ>Ø—‘´H¸T¿Y¹YÓ4GÖH¨q˜DŸK™K¨�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   € Ø'×.Ñ.Ø×%Ñ% d§n¡n×&=Ñ&=Ñ>Ø—‘˜TŸY™Y q™\Ó*Ø—‘˜Y˜TŸY™Y¨¯	©	°!°"¨Ð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Ê   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 ...
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°  € Ø�9‰9�R‰=×Ñ Ò%ô ð /ó 0ð 0ð
 ˆØ�>‰>˜(Ò#ð $(§9¡9¨S¨b >÷3á˜1˜að 4×:Ñ:ØŸ™ A›¨¯©°A«õ8ð 3ˆGñ 3ð ˜4Ÿ;™; t§y¡y°¡}×'9Ñ'9Ó:Ñ:ˆEØ—‘˜wÓ'¨%Ñ/°#´c¸'³lÑ2BÑBˆBð ˜‘8˜c‘>Ð!ä& t§y¡yÓ1ò 
(‘	�‘6�A�qØ˜’6Ø—L‘L ¨T¯[©[¸«^Ñ!;Õ<Øœ#˜dŸi™i›.¨1Ñ,Ò,°°d²Ø—L‘L Õ(à—L‘L °·±¸Q³Ñ!?Ô@ØŸ™ A›�Ø—‘˜UÔ#Øœ˜DŸI™I›¨Ñ*Ó*Ø—L‘L Õ'ð
(ð —9‘9˜UÓ#Ð#ùó)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   € Üˆt�y‰y‹>˜QÒØ §¡¨D¯I©I°a©LÓ 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°"œV B¨×-Ñ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Úlevelrz  s         `     r�   r¤   zOctaveCodePrinter.indent_code  sC  ø€ ô �dœCÔ Ø×)Ñ)¨$¯/©/¸$Ó*?Ó@ˆJØ—7‘7˜:Ó&Ð&àˆØIˆ	Ø3ˆ	ð 15Ö6¨�—‘˜UÕ#Ð6ˆÐ6ð "&÷(Øô œÓB¸	ÔBÓBÕCð (ˆð (ð "&÷(Øô œÓB¸	ÔBÓBÕCð (ˆð (ð ˆØˆÜ  “ò 	!‰GˆAˆtØ�zÑ!Ø—‘˜dÔ#ØØ�X˜a‘[Ñ ˆEØ�M‰M C¨¢I©tÐ4Ô5Ø�X˜a‘[Ñ ‰Eð	!ð ˆùò! 7ùò(ùò(s   ÁDÁ,$DÂ$D)Fr¥  Ú
__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  rs  ru  rw  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Ð6€J�ò"$ò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â  7  s   € ôP ˜XÓ&×.Ñ.¨t°YÓ?Ð?r�   c                ó.   — t        t        | fi |¤Ž«       y)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�   