
    \h                    R   S SK Jr  S SKJr  S SKJr  S SKJrJrJ	r	J
r
JrJr  S SKJr  S SKJrJr  S SKJr  S SKJr  S S	K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5      r! " S S\"5      r# " S S\$5      r%S r& " S S\5      r'SS jr(S r)S S jr*S r+S!S jr,S S jr-S r.g)"    )annotations)Anywraps)AddMulPowSsympifyFloat)Basic)ExprUnevaluatedExpr)Lambda)_keep_coeff)default_sort_key)Symbol)re)
StrPrinter)
precedence
PRECEDENCEc                  $    \ rS rSrSrS rS rSrg)requires   z9Decorator for registering requirements on print methods. c                    Xl         g N_req)selfkwargss     R/var/www/auris/envauris/lib/python3.13/site-packages/sympy/printing/codeprinter.py__init__requires.__init__   s    	    c                6   ^ ^ UU 4S jn[        T5      " U5      $ )Nc                   > TR                   R                  5        H  u  p4[        X5      R                  U5        M!     T" U /UQ70 UD6$ r   )r   itemsgetattrupdate)self_argsr    kvmethodr   s        r!   _method_wrapper*requires.__call__.<locals>._method_wrapper   sB    		)!((+ *%1$1&11r$   r   )r   r.   r/   s   `` r!   __call__requires.__call__   s    	2 V}_--r$   r   N)__name__
__module____qualname____firstlineno____doc__r"   r1   __static_attributes__ r$   r!   r   r      s    D.r$   r   c                      \ rS rSrSrSrg)AssignmentError   z9
Raised if an assignment variable for a loop is missing.
r9   Nr3   r4   r5   r6   r7   r8   r9   r$   r!   r;   r;           	r$   r;   c                      \ rS rSrSrSrg)PrintMethodNotImplementedError%   z8
Raised if a _print_* method is missing in the Printer.
r9   Nr=   r9   r$   r!   r@   r@   %   r>   r$   r@   c                    [        U [        5      (       a  SSKJn  U" S U  5       6 $ [        U [        5      (       a  [	        S U  5       5      $ U $ )Nr   )Listc              3  8   #    U  H  n[        U5      v   M     g 7fr   _convert_python_lists.0es     r!   	<genexpr>(_convert_python_lists.<locals>.<genexpr>.   s     <1+A..   c              3  8   #    U  H  n[        U5      v   M     g 7fr   rE   rG   s     r!   rJ   rK   0   s     ;s!*1--srL   )
isinstancelistsympy.codegen.abstract_nodesrC   tuple)argrC   s     r!   rF   rF   +   sF    #t5<<==	C		;s;;;
r$   c            	      :  ^  \ rS rSr% SrSSSS.rSSS	S
SS	S	SS.rS\S'   0 SS/ 4_SS/ 4_SS/ 4_SS/ 4_SS/ 4_SS/ 4_SS/ 4_SS/ 4_SS/ 4_SS / 4_S!S / 4_S"S / 4_S#S$/ 4_S%S&/ 4_S'S&/ 4_S(S$/ 4_S)SS*/4_0 S+S,/ 4_S-S$/ 4_S.S$S*/4_S/S0/ 4_S1S$S*/4_S2S$S*/4_S3S$/ 4_S4S,/ 4_S5S*/ 4_S6S*/ 4_S7S*/ 4_S8S9/ 4_S:S9/ 4_S;S</ 4_S=S</ 4_S>S?/ 4_S@S?S$/4_ESAS*/ 40ErSnU 4SB jjr	SC r
SnSD jrSnSE jrSF rSG rSH rSI rSJ rSK rSL rSM rSN rSO rSP rSQ rSR rSS rST rSU rSV rSW rU 4SX jrSY r SZ r!\!r"S[ r#Sr$S\ r%S] r&S^ r'S_ r(S` r)Sa r*Sb r+Sc r,Sd r-Se r.Sf r/Sg r0Sh r1Si r2Sj r3Sk r4Sl r5\5r6\5r7\5r8\5r9\5r:\5r;\5r<\5r=\5r>\5r?\5r@\5rA\5rB\5rC\5rD\5rE\5rF\5rG\5rH\5rI\5rJ\5rKSmrLU =rM$ )oCodePrinter5   z.
The base class for code-printing subclasses.
z&&z||!)andornotNautoF_T)order	full_precerror_on_reservedreserved_word_suffixhumaninlineallow_unknown_functionsstrictzdict[str, Any]_default_settingscottancscsinseccosacotatanacscasinasecacoscothexpcschsechacothlogacschasechcatalangamma	fibonaccisqrtlucasbetasinc	PiecewiseModfloor	factorial
factorial2subfactorial
uppergammaRisingFactorialFallingFactorialbinomialfracMaxMin	Heavisideerf2erferfcLiliEidirichlet_etazeta
riemann_xiSingularityFunctionc                   > [         TU ]  US9  U R                  R                  SS5      S :X  a,  U R                  R                  SS5      S:H  U R                  S'   [	        U S5      (       d  [        5       U l        g g )N)settingsrc   Tr`   reserved_words)superr"   	_settingsgethasattrsetr   )r   r   	__class__s     r!   r"   CodePrinter.__init__t   sm    (+>>h-5'+~~'9'9'4'HD'PDNN8$t-.."%%D /r$   c                0    UR                  [        S 5      $ )Nc                    [        U [        5      (       a   U R                  S   R                  (       a  U $ [	        U 5      $ )Nr   )rN   r   r+   is_realr   )rR   s    r!   <lambda>5CodePrinter._handle_UnevaluatedExpr.<locals>.<lambda>}   s<    :4" 4"&)hhqk&9&9 -0 -G?A#w-Gr$   )replacer   r   exprs     r!   _handle_UnevaluatedExpr#CodePrinter._handle_UnevaluatedExpr|   s    ||B !G H 	Hr$   c                @  ^ ^^^^ SSK Jm  SSKJmJm  UUUUU 4S jm[        U5      nT" X5      nT R                  U5      n[        5       T l        [        5       T l	        T R                  U5      R                  5       nT R                  S   (       Ga  / nT R                  (       a  UR                  T R                  SR                  T R                   5      5      5        [#        T R                  [$        S9 H6  nUR                  T R                  ['        U5      R(                  5      5        M8     [#        T R                  [$        S9 H%  u  pVUR                  T R+                  XV5      5        M'     XC-   nT R-                  U5      nSR/                  U5      nO`T R-                  U5      nT R                   VV	s1 s H  u  pUT R                  U	5      4iM     n
nn	U
T R                  SR/                  U5      4n[        5       T l        [        5       T l	        U$ s  sn	nf )	aL  
Print the expression as code.

Parameters
----------
expr : Expression
    The expression to be printed.

assign_to : Symbol, string, MatrixSymbol, list of strings or Symbols (optional)
    If provided, the printed code will set the expression to a variable or multiple variables
    with the name or names given in ``assign_to``.
r   MatrixSymbol)	CodeBlock
Assignmentc           
     r  > Uc  [        U 5      $ [        U[        [        45      (       an  [	        U 5      [	        U5      :w  a-  [        SR                  [	        U 5      [	        U5      5      5      eT" [        X5       VVs/ s H  u  p#T" X#5      PM     snn6 $ [        U[        5      (       a1  U R                  (       a  T" U/U R                  Q76 nOX[        U5      nOL[        U[        5      (       d7  [        SR                  [        T5      R                  [        U5      5      5      eT" X5      $ s  snnf )Nz;Failed to assign an expression of length {} to {} variablesz%{} cannot assign to object of type {})r   rN   rO   rQ   len
ValueErrorformatzipstr	is_Matrixshaper   r   	TypeErrortyper3   )	r   	assign_tolhsrhsr   r   r   _handle_assign_tor   s	       r!   r   .CodePrinter.doprint.<locals>._handle_assign_to   s    t}$)dE]33t9I.$%b%i%ijmnrjsux  zC  vD  &E  F  F sSWOc"dOc83#4S#>Oc"dee)S))>> ,Y D DI &y 1I	511 G N NT
++T)_!> ? ?i.. #es    D3
r`   zNot supported in {}:key
)"sympy.matrices.expressions.matexprr   sympy.codegen.astr   r   rF   r   r   _not_supported_number_symbols_print
splitlinesr   append_get_commentr   languagesortedr   r   r3   _declare_number_const_format_codejoin)r   r   r   lines
frontlinesnamevalueresultr,   r-   num_symsr   r   r   r   s   `          @@@@r!   doprintCodePrinter.doprint   s    	D;	/ 	/" %T* 1 ++D1 "e"uD!,,. >>'""J""!!$"3"3.55dmmD#F G"4#6#6C@D%%d&7&7T
8K8K&LM A%d&:&:D!!$"<"<T"IJ  E&E%%e,EYYu%F%%e,E8<8L8LM8LDKKN+8LHM 3 3TYYu5EFF!e"u	 Ns   :Hc           	        U R                   R                  SS5      (       a   SSKJn  U R	                  X5      nU" U5      nO/ nS U40nU R                  U5      u  pgS U;   a!  [        R                  " U [        US    6 5      nO[        R                  " U S5      nU R                  U5      n	/ n
X:w  aN  U
R                  U5        Ub  U R                  U	< SU< 35      nU
R                  U5        U
R                  U5        U GHS  n[        U[        5      (       d  M  U R                  X5      nU R                  U5      u  pX[    GH  nX;   aO  X^    Vs/ s H  n[!        UR#                  5       5      PM     snX^    Vs/ s H  nS /PM     sn:X  d  [%        S5      eUc  ['        S5      eUR)                  U5      (       a  [+        S5      eU
R                  U5        U
R                  U5        U	< S[        R                  " XU-   5      < 3nU
R                  U R                  U5      5        U
R                  U5        U
R                  U5        GM     GMV     S	R-                  U
5      $ s  snf s  snf )
NcontractTr   )get_contraction_structure = z0FIXME: no support for contractions in factor yetz"need assignment variable for loopszZFIXME: lhs present in rhs,                                this is undefined in CodePrinterr   )r   r   sympy.tensorr   _get_expression_indices_get_loop_opening_endingr   r   r   r   extend_get_statementr   rN   rQ   _sort_optimizedrO   keysNotImplementedErrorr;   hasr   r   )r   r   r   r   indicesdummiesopenloop	closelooptextlhs_printedr   d
openloop_dcloseloop_dtermfs                   r!   _doprint_loopsCodePrinter._doprint_loops   sN    >>j$//>224CG/5GGdWoG";;GD 7?%%dC,?@D %%dA.D kk),LL"$**T+JKLLLL# A!U##..q7*.*G*G+'
 $JD0WAaffh0W07>1>1?
 2NP P %,"1 D#F F88I..", .B #C C X.Z0,79K9K d"2:4  5T%8%8%>?[1Y/E ' T yyG 1X>s   #I+?I0
c                    SSK Jn  U" U5      u  pEU" U5      u  peU(       a	  U(       d  UnXF:w  a  [        SU-  5      eU R                  XB5      $ )Nr   )get_indicesz2lhs indices must match non-dummy rhs indices in %s)r   r   r   r   )r   r   r   r   rindsjunklindss          r!   r   #CodePrinter._get_expression_indices  s[    ,!$'!), E> )+/0 1 1 ##E55r$   c                *  ^	 SSK Jn  U(       d  / $ 0 m	U H  nST	U'   M
     UR                  U5      nU H>  n[        UR                  5       H"  u  px T	U==   U R                  U5      -  ss'   M$     M@     [        UU	4S jS9$ ! [         a     ME  f = f)Nr   )Indexedc                   > TU    $ r   r9   )xscore_tables    r!   r   -CodePrinter._sort_optimized.<locals>.<lambda>5  s	    [^r$   r   )sympy.tensor.indexedr   atoms	enumerater   _rate_index_positionKeyErrorr   )
r   r   r   r   iarraysarrpindr   s
            @r!   r   CodePrinter._sort_optimized   s    0I AKN  G$C#CKK0$(A(A!(DD$ 1  g#;<<   s   B
BBc                    [        S5      e)zfunction to calculate score based on position among indices

This method is used to sort loops in an optimized order, see
CodePrinter._sort_optimized()
=This function must be implemented by subclass of CodePrinter.r   )r   r  s     r!   r   CodePrinter._rate_index_position7  s     " #= > 	>r$   c                    [        S5      e)z1Formats a codestring with the proper line ending.r
  r  )r   
codestrings     r!   r   CodePrinter._get_statement@      ! #= > 	>r$   c                    [        S5      e)z#Formats a text string as a comment.r
  r  )r   r   s     r!   r   CodePrinter._get_commentE  r  r$   c                    [        S5      e)z3Declare a numeric constant at the top of a functionr
  r  )r   r   r   s      r!   r   !CodePrinter._declare_number_constJ  r  r$   c                    [        S5      e)zvTake in a list of lines of code, and format them accordingly.

This may include indenting, wrapping long lines, etc...r
  r  )r   r   s     r!   r   CodePrinter._format_codeO  s     " #= > 	>r$   c                    [        S5      e)zGReturns a tuple (open_lines, close_lines) containing lists
of codelinesr
  r  )r   r   s     r!   r   $CodePrinter._get_loop_opening_endingV  s     " #= > 	>r$   c                    UR                   R                  S5      (       a  SUR                   -   $ SUR                   UR                  4-  $ )NDummy_r[   z%s_%d)r   
startswithdummy_indexr   s     r!   _print_DummyCodePrinter._print_Dummy\  s?    99))?"dii)9)9:::r$   c                8    U R                  UR                  5      $ r   )r   labelr   s     r!   
_print_IdxCodePrinter._print_Idxb  s    {{4::&&r$   c                    SR                  UR                   Vs/ s H  o R                  U5      PM     sn5      $ s  snf )Nr   )r   r+   r   )r   r   r  s      r!   _print_CodeBlockCodePrinter._print_CodeBlocke  s-    yy$))<)Q++a.)<==<s   ;c                    [        U5      $ r   )r   r   strings     r!   _print_StringCodePrinter._print_Stringh  s    6{r$   c                     SUR                   -  $ )Nz"%s")r   r   rR   s     r!   _print_QuotedStringCodePrinter._print_QuotedStringk  s      r$   c                6    U R                  [        U5      5      $ r   )r   r   r'  s     r!   _print_CommentCodePrinter._print_Commentn  s      V--r$   c                h   SSK Jn  SSKJn  SSKJn  SSKJn  UR                  nUR                  n[        UR                  U5      (       a`  / n/ n	UR                   H-  u  pUR                  U" Xj5      5        U	R                  U5        M/     U" [        X5      6 nU R                  U5      $ [        Xd5      (       a`  / nU R                  U5       H8  u  pU" XnU4   X~U4   5      nU R                  U5      nUR                  U5        M:     SR!                  U5      $ U R"                  R%                  SS5      (       a=  UR'                  U5      (       d  UR'                  U5      (       a  U R)                  Xv5      $ U R                  U5      nU R                  U5      nU R+                  U< S	U< 35      $ )
Nr   )r   )r   r   )IndexedBaser   r   Fr   )r   r   $sympy.functions.elementary.piecewiser   r   r   r   r3  r   r   rN   r+   r   r   r   _traverse_matrix_indicesr   r   r   r   r   r   )r   r   r   r   r   r3  r   r   expressions
conditionsrI   ctempr   r  jcode0lhs_coderhs_codes                      r!   _print_AssignmentCodePrinter._print_Assignmentq  ss   0BC4hhhhdhh	** KJ(("":c#56!!!$ # c+:;D;;t$$** E77<!#d)SAY7D)U# = 99U##^^
E228L8L$$ &&s00{{3'H{{3'H&&Hh'GHHr$   c                   ^  T R                  UR                  5      nT R                  UR                  5      nT R                  SR                  " U 4S jX!R
                  U4 5       6 5      $ )Nz{} {} {}c              3  F   >#    U  H  nTR                  U5      v   M     g 7fr   r   rH   rR   r   s     r!   rJ   9CodePrinter._print_AugmentedAssignment.<locals>.<genexpr>  s     H*G3dkk#*G   !)r   r   r   r   r   op)r   r   r<  r=  s   `   r!   _print_AugmentedAssignment&CodePrinter._print_AugmentedAssignment  s[    ;;txx(;;txx("":#4#4H8WWh*GH$J K 	Kr$   c                r   ^  UR                   < SSR                  U 4S jUR                   5       5      < S3$ )N(, c              3  F   >#    U  H  nTR                  U5      v   M     g 7fr   rB  rC  s     r!   rJ   2CodePrinter._print_FunctionCall.<locals>.<genexpr>  s     F3ECt{{3''3ErE  ))r   r   function_argsr   s   ` r!   _print_FunctionCallCodePrinter._print_FunctionCall  s.    IIIIF43E3EFGI 	Ir$   c                8    U R                  UR                  5      $ r   )r   symbolr   s     r!   _print_VariableCodePrinter._print_Variable  s    {{4;;''r$   c                   > [         TU ]  U5      nX R                  ;   aA  U R                  S   (       a  Sn[	        UR                  U5      5      eX R                  S   -   $ U$ )Nr^   zVThis expression includes the symbol "{}" which is a reserved keyword in this language.r_   )r   _print_Symbolr   r   r   r   )r   r   r   msgr   s       r!   rW  CodePrinter._print_Symbol  s^    w$T*&&&~~12< D!122..)?@@@Kr$   c                d    XR                   ;   =(       d    [        U SR                  U5      S5      $ )z}Check if function ``name`` is either a known function or has its own
printing method. Used to check if rewriting is possible.z	_print_{}F)known_functionsr(   r   )r   r   s     r!   
_can_printCodePrinter._can_print  s.     +++]wt[=O=OPT=UW\/]]r$   c           	     6  ^  UR                   R                  T R                  ;   a  T R                  UR                   R                     n[        U[        5      (       a$  U< ST R                  UR                  S5      < S3$ U H  u  p4U" UR                  6 (       d  M    O   Wb1   U" UR                   Vs/ s H  nT R                  US5      PM     sn6 $ O[        US5      (       aG  [        UR                  [        5      (       a(  T R                  UR                  " UR                  6 5      $ UR                   R                  T R                  ;   a{  T R                  UR                   R                     u  pgT R                  U5      (       a@  [        U 4S jU 5       5      (       a&  ST R                  UR!                  U5      5      -   S-   $ UR"                  (       aq  T R$                  R'                  SS5      (       aP  T R                  UR                   5      < SSR)                  [+        T R                  UR                  5      5      < S3$ T R-                  U5      $ s  snf ! [         a'    U< ST R                  UR                  S5      < S3s $ f = f)	NrJ  rK  rN  r   _imp_c              3  F   >#    U  H  nTR                  U5      v   M     g 7fr   )r\  )rH   r   r   s     r!   rJ   .CodePrinter._print_Function.<locals>.<genexpr>  s     0Y[1C1C[rE  rb   F)funcr3   r[  rN   r   	stringifyr+   parenthesizer   r   r_  r   r   _rewriteable_functionsr\  allrewriteis_Functionr   r   r   map_print_not_supported)r   r   	cond_funccondrb  itemtarget_frequired_fss   `       r!   _print_FunctionCodePrinter._print_Function  s   99!5!55,,TYY-?-?@I)S))#,dnnTYY.MNN"+JDTYY'' #, #R#TYY%WYTd&7&7a&@Y%WXX $
 T7##
4::v(F(F;;tzz499566YY4#>#>>$($?$?		@R@R$S!Hx((S0Y[0Y-Y-YT[[h)?@@3FF 2 23Le T T#{{4995tyyT[[RVR[R[A\7]^^,,T22 &X$ R+/		41PQQRs$   'I' 7I"I' "I' '.JJc                6   UR                   tp#UR                    H6  nUR                  (       a  M  [        SU R                  R                  -  5      e   SUR
                  R                  -  n[        XS 5      nUc^  U R                  R                  SS5      (       a,  [        S[        U 5       S[        U5       3SU 3-   S-   5      eU R                  U5      $ [        U5      nUR                    Vs/ s H  oU   PM	     n	nU" UR                   U	5      $ s  snf )	NzL%s._print_Derivative(...) only supports functions with symbols as arguments.z_print_Derivative_%src   FUnsupported by : z
Printer has no method: V
Set the printer option 'strict' to False in order to generate partially printed code.)r+   	is_Symbolr   r   r3   rb  r(   r   r   r@   r   rj  dict)
r   r   objwrt_order_pairsfunc_arg	meth_namepmethordersrR   
seq_orderss
             r!   _print_DerivativeCodePrinter._print_Derivative  s    $		H%%% !o!%!8!8"9 : : ! +SXX->->>	.=~~!!(E224%d4j\DJ<@/	{;<mn 
 ,,T22o&-0XX6XcSkX
6SXXz** 7s   3Dc           	     J   U R                   R                  SS5      (       a6  U R                  [        UR	                  U R                   S   5      5      5      $ U R
                  R                  U[        UR	                  U R                   S   5      5      45        [        U5      $ )Nra   F	precision)r   r   r   r   evalfr   addr   r   s     r!   _print_NumberSymbolCodePrinter._print_NumberSymbol  s    >>h..;;uTZZ{0K%LMNN   $$ddjj!<=>&@ At9r$   c                $    U R                  U5      $ r   r  r   s     r!   _print_CatalanCodePrinter._print_Catalan      ''--r$   c                $    U R                  U5      $ r   r  r   s     r!   _print_EulerGammaCodePrinter._print_EulerGamma  r  r$   c                $    U R                  U5      $ r   r  r   s     r!   _print_GoldenRatioCodePrinter._print_GoldenRatio  r  r$   c                $    U R                  U5      $ r   r  r   s     r!   _print_TribonacciConstant%CodePrinter._print_TribonacciConstant  r  r$   c                $    U R                  U5      $ r   r  r   s     r!   _print_Exp1CodePrinter._print_Exp1  r  r$   c                $    U R                  U5      $ r   r  r   s     r!   	_print_PiCodePrinter._print_Pi  r  r$   c                   ^ ^ [        U5      mST R                  S   -  R                  UU 4S j[        UR                  [
        S9 5       5      $ )N %s rW   c              3  H   >#    U  H  nTR                  UT5      v   M     g 7fr   rd  rH   aPRECr   s     r!   rJ   )CodePrinter._print_And.<locals>.<genexpr>  s)      6B@A 7;6G6G46P6P@   "r   r   
_operatorsr   r   r+   r   r   r   r  s   ` @r!   
_print_AndCodePrinter._print_And  sK    $//55 6B		/?@6B B 	Br$   c                   ^ ^ [        U5      mST R                  S   -  R                  UU 4S j[        UR                  [
        S9 5       5      $ )Nr  rX   c              3  H   >#    U  H  nTR                  UT5      v   M     g 7fr   r  r  s     r!   rJ   (CodePrinter._print_Or.<locals>.<genexpr>  s)      5B@A 6:5F5Fq$5O5O@r  r   r  r  s   ` @r!   	_print_OrCodePrinter._print_Or  sK    $..44 5B		/?@5B B 	Br$   c                   ^ ^ T R                   R                  S5      c  T R                  UR                  5       5      $ [	        U5      mST R                   S   -  R                  UU 4S jUR                   5       5      $ )Nxorr  c              3  H   >#    U  H  nTR                  UT5      v   M     g 7fr   r  r  s     r!   rJ   )CodePrinter._print_Xor.<locals>.<genexpr>  s(      6$"A 7;6G6G46P6P"r  r  r   r   to_nnfr   r   r+   r  s   ` @r!   
_print_XorCodePrinter._print_Xor  si    ??u%-;;t{{}--$//55 6$6$ $ 	$r$   c                   ^ ^ T R                   R                  S5      c  T R                  UR                  5       5      $ [	        U5      mST R                   S   -  R                  UU 4S jUR                   5       5      $ )N
equivalentr  c              3  H   >#    U  H  nTR                  UT5      v   M     g 7fr   r  r  s     r!   rJ   0CodePrinter._print_Equivalent.<locals>.<genexpr>  s*      =$"A >B=N=NqRV=W=W"r  r  r  s   ` @r!   _print_EquivalentCodePrinter._print_Equivalent  si    ??|,4;;t{{}--$66<< =$=$ $ 	$r$   c                v    [        U5      nU R                  S   U R                  UR                  S   U5      -   $ )NrY   r   )r   r  rd  r+   r  s      r!   
_print_NotCodePrinter._print_Not  s5    $u%(9(9$))A,(MMMr$   c                @    U R                  UR                  5       5      $ r   )r   r  r   s     r!   _print_BooleanFunction"CodePrinter._print_BooleanFunction  s    {{4;;=))r$   c                :    SU R                   " UR                  6 -  $ )Nz	isnan(%s)r   r+   r,  s     r!   _print_isnanCodePrinter._print_isnan       T[[#((333r$   c                :    SU R                   " UR                  6 -  $ )Nz	isinf(%s)r  r,  s     r!   _print_isinfCodePrinter._print_isinf#  r  r$   c           	     :   [        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H9  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                  U
5        GM<     U=(       d    [$        R&                  /n[        U5      S:X  a1  US:X  a+  U R)                  US   S	[*        S
   [*        S   -   -  5      /nO U Vs/ s H  oR)                  X5      PM     nnU Vs/ s H  oR)                  X5      PM     nnU HP  n
U
R                  U;   d  M  SXR-                  U
R                  5         -  XR-                  U
R                  5      '   MR     U(       d  USR/                  U5      -   $ [        U5      S:X  a  USR/                  U5      -   S-   US   -   $ USR/                  U5      -   SSR/                  U5      -  -   $ s  snf s  snf )Nr   - )oldnoneF)evaluate   g      ?r	   r   z(%s)*/z/(%s))r   as_coeff_Mulr   r\   as_ordered_factorsr   	make_argsis_commutativeis_Powrr   is_Rationalis_negativer   r	   baser   r+   rN   r
   Onerd  r   indexr   )r   r   precr8  rI   signr  b	pow_parenr+   rm  a_strr   b_strs                 r!   
_print_MulCodePrinter._print_Mul&  sw   $  "q5r1%DDD	::_,**,D ==&D D"""t{{{txx7K7KPTPXPXPdPd88r>HHSTXXIFG499Q<,,-2z$))S7Q7Q!((.HHSTXXI67  L!%%q6Q;43;
 &&qtS*U2CJuDU2U-VWXE9:;A&&q/E;567Q""1+Q7 DyyA~,2U77499;M5N,Nggdii()  #((5/))Vq[#((5/)C/%(::#((5/)Gchhuo,EEE <7s   L1Lc                
   U R                   R                  SS5      (       a&  [        S[        U 5       S[        U5       3S-   5      e U R                  R                  U5        U R                  U5      $ ! [         a     Nf = f)Nrc   Frs  rt  ru  )r   r   r@   r   r   r  r   emptyPrinterr   s     r!   rj   CodePrinter._print_not_supported`  s    >>h..0!$t*RT
|<ij 	##D)   &&  		s   	A5 5
BB)r   r   r   r   )Nr3   r4   r5   r6   r7   r  rd   __annotations__re  r"   r   r   r   r   r   r  r   r   r   r   r   r  r!  r$  r)  r-  r0  r>  rG  rP  rT  rW  r\  rp  _print_Exprr  _print_Heavisider  r  r  r  r  r  r  r  r  r  r  r  r  r  r  r  rj  _print_Basic_print_ComplexInfinity_print_ExprCondPair_print_GeometryEntity_print_Infinity_print_Integral_print_Interval_print_AccumulationBounds_print_Limit_print_MatrixBase_print_DeferredVector
_print_NaN_print_NegativeInfinity_print_Order_print_RootOf_print_RootsOf_print_RootSum_print_Uniform_print_Unit_print_Wild_print_WildFunction_print_Relationalr8   __classcell__)r   s   @r!   rT   rT   5   s   
 J " ##(	)~ 	$E2;$E2;$ E2;$ VRL	$
 VRL$ VRL$ UBK$ UBK$ UBK$ eR[$ eR[$ eR[$ }$ &"$ fb\$  WbM!$" U[M*#$$ GR=%$& '2'$( 7[M2)$* \2.+$, +7-$. ;- 8/$0 "1$2 WbM3$4 K$5$6 K$7$8 +r*9$: UBK;$< UBK=$> 4*?$@ 4*A$B fb\C$D 6G9-E$F "K#4G$L(HAFM ^6=.>>
>
>
>>;'>!.#IJKI
(
^
38 "K+* ......B
B
$$N*448Ft' (L1.0*O*O*O 4'L,0%J2'L(M)N)N)N&K&K.,r$   rT   Nc                \    SSK Jn  XBR                  5          " U5      R                  X5      $ )a  Converts an expr to a string of c code

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 is helpful in case of
    line-wrapping, or for expressions that generate multi-line statements.
standard : str, optional
    String specifying the standard. If your compiler supports a more modern
    standard you may set this to 'c99' to allow the printer to use more math
    functions. [default='c89'].
precision : integer, optional
    The precision for numbers such as pi [default=17].
user_functions : dict, optional
    A dictionary where the keys are string representations of either
    ``FunctionClass`` or ``UndefinedFunction`` instances and the values
    are their desired C string representations. Alternatively, the
    dictionary value can be a list of tuples i.e. [(argument_test,
    cfunction_string)] or [(argument_test, cfunction_formater)]. See below
    for examples.
dereference : iterable, optional
    An iterable of symbols that should be dereferenced in the printed code
    expression. These would be values passed by address to the function.
    For example, if ``dereference=[a]``, the resulting code would print
    ``(*a)`` instead of ``a``.
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].

Examples
========

>>> from sympy import ccode, symbols, Rational, sin, ceiling, Abs, Function
>>> x, tau = symbols("x, tau")
>>> expr = (2*tau)**Rational(7, 2)
>>> ccode(expr)
'8*M_SQRT2*pow(tau, 7.0/2.0)'
>>> ccode(expr, math_macros={})
'8*sqrt(2)*pow(tau, 7.0/2.0)'
>>> ccode(sin(x), assign_to="s")
's = sin(x);'
>>> from sympy.codegen.ast import real, float80
>>> ccode(expr, type_aliases={real: float80})
'8*M_SQRT2l*powl(tau, 7.0L/2.0L)'

Simple 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)].

>>> custom_functions = {
...   "ceiling": "CEIL",
...   "Abs": [(lambda x: not x.is_integer, "fabs"),
...           (lambda x: x.is_integer, "ABS")],
...   "func": "f"
... }
>>> func = Function('func')
>>> ccode(func(Abs(x) + ceiling(x)), standard='C89', user_functions=custom_functions)
'f(fabs(x) + CEIL(x))'

or if the C-function takes a subset of the original arguments:

>>> ccode(2**x + 3**x, standard='C99', user_functions={'Pow': [
...   (lambda b, e: b == 2, lambda b, e: 'exp2(%s)' % e),
...   (lambda b, e: b != 2, 'pow')]})
'exp2(x) + pow(3, x)'

``Piecewise`` expressions are converted into conditionals. If an
``assign_to`` variable is provided an if statement is created, otherwise
the ternary operator is used. 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
>>> expr = Piecewise((x + 1, x > 0), (x, True))
>>> print(ccode(expr, tau, standard='C89'))
if (x > 0) {
tau = x + 1;
}
else {
tau = 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]))
>>> ccode(e.rhs, assign_to=e.lhs, contract=False, standard='C89')
'Dy[i] = (y[i + 1] - y[i])/(t[i + 1] - t[i]);'

Matrices are also supported, but a ``MatrixSymbol`` of the same dimensions
must be provided to ``assign_to``. Note that any expression that can be
generated normally can also exist inside a Matrix:

>>> from sympy import Matrix, MatrixSymbol
>>> mat = Matrix([x**2, Piecewise((x + 1, x > 0), (x, True)), sin(x)])
>>> A = MatrixSymbol('A', 3, 1)
>>> print(ccode(mat, A, standard='C89'))
A[0] = pow(x, 2);
if (x > 0) {
   A[1] = x + 1;
}
else {
   A[1] = x;
}
A[2] = sin(x);
r   )c_code_printers)sympy.printing.cr  lowerr   )r   r   standardr   r  s        r!   ccoder    s(    D 1>>+,X6>>tOOr$   c                .    [        [        U 40 UD65        g)z0Prints C representation of the given expression.N)printr  r   r   s     r!   print_ccoder    s    	%
!
!"r$   c                <    SSK Jn  U" U5      R                  X5      $ )a  Converts an expr to a string of fortran code

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 is helpful in case of
    line-wrapping, or for expressions that generate multi-line statements.
precision : integer, optional
    DEPRECATED. Use type_mappings instead. The precision for numbers such
    as pi [default=17].
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].
source_format : optional
    The source format can be either 'fixed' or 'free'. [default='fixed']
standard : integer, optional
    The Fortran standard to be followed. This is specified as an integer.
    Acceptable standards are 66, 77, 90, 95, 2003, and 2008. Default is 77.
    Note that currently the only distinction internally is between
    standards before 95, and those 95 and after. This may change later as
    more features are added.
name_mangling : bool, optional
    If True, then the variables that would become identical in
    case-insensitive Fortran are mangled by appending different number
    of ``_`` at the end. If False, SymPy Will not interfere with naming of
    variables. [default=True]

Examples
========

>>> from sympy import fcode, symbols, Rational, sin, ceiling, floor
>>> x, tau = symbols("x, tau")
>>> fcode((2*tau)**Rational(7, 2))
'      8*sqrt(2.0d0)*tau**(7.0d0/2.0d0)'
>>> fcode(sin(x), assign_to="s")
'      s = 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)].

>>> custom_functions = {
...   "ceiling": "CEIL",
...   "floor": [(lambda x: not x.is_integer, "FLOOR1"),
...             (lambda x: x.is_integer, "FLOOR2")]
... }
>>> fcode(floor(x) + ceiling(x), user_functions=custom_functions)
'      CEIL(x) + FLOOR1(x)'

``Piecewise`` expressions are converted into conditionals. If an
``assign_to`` variable is provided an if statement is created, otherwise
the ternary operator is used. 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
>>> expr = Piecewise((x + 1, x > 0), (x, True))
>>> print(fcode(expr, tau))
      if (x > 0) then
         tau = x + 1
      else
         tau = x
      end if

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]))
>>> fcode(e.rhs, assign_to=e.lhs, contract=False)
'      Dy(i) = (y(i + 1) - y(i))/(t(i + 1) - t(i))'

Matrices are also supported, but a ``MatrixSymbol`` of the same dimensions
must be provided to ``assign_to``. Note that any expression that can be
generated normally can also exist inside a Matrix:

>>> from sympy import Matrix, MatrixSymbol
>>> mat = Matrix([x**2, Piecewise((x + 1, x > 0), (x, True)), sin(x)])
>>> A = MatrixSymbol('A', 3, 1)
>>> print(fcode(mat, A))
      A(1, 1) = x**2
         if (x > 0) then
      A(2, 1) = x + 1
         else
      A(2, 1) = x
         end if
      A(3, 1) = sin(x)
r   )FCodePrinter)sympy.printing.fortranr  r   )r   r   r   r  s       r!   fcoder    s    h 4!))$::r$   c                .    [        [        U 40 UD65        g)zqPrints the Fortran representation of the given expression.

See fcode for the meaning of the optional arguments.
N)r
  r  r  s     r!   print_fcoder    s    
 
%
!
!"r$   c                \    SSK Jn  XBR                  5          " U5      R                  X5      $ )z#C++ equivalent of :func:`~.ccode`. r   )cxx_code_printers)sympy.printing.cxxr  r  r   )r   r   r  r   r  s        r!   cxxcoder    s%    4^^-.x8@@QQr$   c                    SSK Jn  U" U5      nUR                  U 5      n [        U [        5      (       a4  UR
                  R                  5        H  u  pVU R                  XV5      n M     UR                  X5      $ )a  Converts an expr to a string of Rust code

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 is helpful in case of
    line-wrapping, or for expressions that generate multi-line statements.
precision : integer, optional
    The precision for numbers such as pi [default=15].
user_functions : dict, optional
    A dictionary where the keys are string representations of either
    ``FunctionClass`` or ``UndefinedFunction`` instances and the values
    are their desired C string representations. Alternatively, the
    dictionary value can be a list of tuples i.e. [(argument_test,
    cfunction_string)].  See below for examples.
dereference : iterable, optional
    An iterable of symbols that should be dereferenced in the printed code
    expression. These would be values passed by address to the function.
    For example, if ``dereference=[a]``, the resulting code would print
    ``(*a)`` instead of ``a``.
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].

Examples
========

>>> from sympy import rust_code, symbols, Rational, sin, ceiling, Abs, Function
>>> x, tau = symbols("x, tau")
>>> rust_code((2*tau)**Rational(7, 2))
'8.0*1.4142135623731*tau.powf(7_f64/2.0)'
>>> rust_code(sin(x), assign_to="s")
's = x.sin();'

Simple 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)].

>>> custom_functions = {
...   "ceiling": "CEIL",
...   "Abs": [(lambda x: not x.is_integer, "fabs", 4),
...           (lambda x: x.is_integer, "ABS", 4)],
...   "func": "f"
... }
>>> func = Function('func')
>>> rust_code(func(Abs(x) + ceiling(x)), user_functions=custom_functions)
'(fabs(x) + x.ceil()).f()'

``Piecewise`` expressions are converted into conditionals. If an
``assign_to`` variable is provided an if statement is created, otherwise
the ternary operator is used. 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
>>> expr = Piecewise((x + 1, x > 0), (x, True))
>>> print(rust_code(expr, tau))
tau = if (x > 0.0) {
    x + 1
} else {
    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]))
>>> rust_code(e.rhs, assign_to=e.lhs, contract=False)
'Dy[i] = (y[i + 1] - y[i])/(t[i + 1] - t[i]);'

Matrices are also supported, but a ``MatrixSymbol`` of the same dimensions
must be provided to ``assign_to``. Note that any expression that can be
generated normally can also exist inside a Matrix:

>>> from sympy import Matrix, MatrixSymbol
>>> mat = Matrix([x**2, Piecewise((x + 1, x > 0), (x, True)), sin(x)])
>>> A = MatrixSymbol('A', 3, 1)
>>> print(rust_code(mat, A))
A = [x.powi(2), if (x > 0.0) {
    x + 1
} else {
    x
}, x.sin()];
r   )RustCodePrinter)	sympy.printing.rustr  _rewrite_known_functionsrN   r   function_overridesvaluesr   r   )r   r   r   r  printersrc_funcdst_funcs          r!   	rust_coder     si    X 4h'G++D1D$")"<"<"C"C"EH<<3D #F??4++r$   c                .    [        [        U 40 UD65        g)z3Prints Rust representation of the given expression.N)r
  r   r  s     r!   print_rust_coder"    s    	)D
%H
%&r$   )Nc99r   )Nzc++11)/
__future__r   typingr   	functoolsr   
sympy.corer   r   r	   r
   r   r   sympy.core.basicr   sympy.core.exprr   r   sympy.core.functionr   sympy.core.mulr   sympy.core.sortingr   sympy.core.symbolr   $sympy.functions.elementary.complexesr   sympy.printing.strr   sympy.printing.precedencer   r   r   	Exceptionr;   r   r@   rF   rT   r  r  r  r  r  r   r"  r9   r$   r!   <module>r2     s    "   7 7 " 1 & & / $ 3 ) <
. 
.	i 		%8 	N	-* N	-jCPJ#u;p#Rr,j'r$   