o
    8Van                     @   s  d Z ddlmZmZ ddlmZ ddlmZ ddlZddl	m
Z
mZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZmZ ddlmZmZmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z' ddl(m)Z)m*Z*m+Z+m,Z,m-Z- dd	l.m/Z/ dd
l0m1Z1 ddl2m3Z3 ddl4m5Z5 ddl6m7Z7m8Z8 ddl9m:Z: ddl4m;Z;m<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$Z=G d%d& d&e5Z>dS )'aq  
Fortran code printer

The FCodePrinter converts single sympy expressions into single Fortran
expressions, using the functions defined in the Fortran 77 standard where
possible. Some useful pointers to Fortran can be found on wikipedia:

https://en.wikipedia.org/wiki/Fortran

Most of the code below is based on the "Professional Programmer's Guide to
Fortran77" by Clive G. Page:

http://www.star.le.ac.uk/~cgp/prof77.html

Fortran is a case-insensitive language. This might cause trouble because
SymPy is case sensitive. So, fcode adds underscores to variable names when
it is necessary to make them different for Fortran.
    )DictAny)defaultdict)chainN)
AssignmentDeclarationPointervalue_constfloat32float64float80	complex64
complex128int8int16int32int64intcrealintegerbool_complex_)allocatableisigndsigncmplxmerge
literal_dp	elementalpure	intent_in
intent_outintent_inout)SAddNFloatSymbol)Function)Eq)Range)CodePrinter)
precedence
PRECEDENCE)printer_context)fcodeprint_fcodeZsinZcosZtanZasinZacosZatanZatan2ZsinhZcoshZtanhlogexpZerfAbsabs	conjugateZconjgZMaxmaxZMinminc                       s  e Zd ZdZdZdZeeee	e
eiZedede	dededed	ed
edededediZeddiiZdddi ddddddd
ZddddddZdd iZd fd!d"	Zed#d$ Z fd%d&Zd'd( Zd)d* Zd+d, Z d-d. Z!d/d0 Z"d1d2 Z#d3d4 Z$d5d6 Z%d7d8 Z&d9d: Z'd;d< Z(d=d> Z)d?d@ Z*dAdB Z+dCdD Z,dEdF Z-dGdH Z.dIdJ Z/dKdL Z0dMdN Z1dOdP Z2dQdR Z3dSdT Z4dUdV Z5dWdX Z6dYdZ Z7d[d\ Z8d]d^ Z9d_d` Z:dadb Z;dcdd Z<dedf Z=dgdh Z>didj Z?dkdl Z@dmdn ZAdodp ZBdqdr ZCdsdt ZDdudv ZEdwdx ZFdydz ZGd{d| ZHd}d~ ZIdd ZJdd ZKdd ZLdd ZMdd ZNdd ZOdd ZPdd ZQdd ZRdd ZSdd ZTdd ZUdd ZV  ZWS )FCodePrinterzAA printer to convert sympy expressions to strings of Fortran codeZ_fcodeZFortranzinteger(c_int)zreal*4zreal*8zreal*10z	complex*8z
complex*16z	integer*1z	integer*2z	integer*4z	integer*8Zlogicaliso_c_bindingZc_intNauto   TFfixedM   )
ZorderZ	full_prec	precisionuser_functionsZhumanZallow_unknown_functionssource_formatZcontractstandardname_manglingz.and.z.or.z.neqv.z.eqv.z.not. )andorxorZ
equivalentnotz!=z/=c                    s   |si }i | _ g | _tt| j |di  | _tt| j |di  | _t 	| tt
| _
|di }| j
| h d}| jd |vrWtd| jd  tt| _d S )Ntype_aliasestype_mappingsr?   >     B   r=   Z   _     rA   zUnknown Fortran standard: %s)mangled_symbols	used_namedictr   rG   itemspoprH   super__init__known_functionsgetupdate	_settings
ValueErrorr   setmodule_uses)selfZsettingsZ	userfuncsZ	standards	__class__ 8/usr/lib/python3/dist-packages/sympy/printing/fortran.pyrT   z   s(   
zFCodePrinter.__init__c                 C   sF   | j d dkrddddS | j d dkrddd	dS td
| j d  )Nr@   r<   z      z     @ zC     )codecontcommentfree z! zUnknown source format: %s)rX   rY   r\   r_   r_   r`   _lead   s
   zFCodePrinter._leadc                    s   | j d dkrA|| jvr;|j}| | jv r!|d7 }| | jv s| j|  ||jkr4|| j|< nt|| j|< || j}t 	|}|S )NrB   T_)
rX   rN   namelowerrO   appendr'   ZxreplacerS   _print_Symbol)r\   exprri   r]   r_   r`   rl      s   

zFCodePrinter._print_Symbolc                 C   s
   | d S )N   r_   )r\   pr_   r_   r`   _rate_index_position      
z!FCodePrinter._rate_index_positionc                 C   s   |S Nr_   )r\   Z
codestringr_   r_   r`   _get_statement      zFCodePrinter._get_statementc                 C   s
   d |S )Nz! {})format)r\   textr_   r_   r`   _get_comment   rq   zFCodePrinter._get_commentc                 C   s   d || |S )Nzparameter ({} = {}))ru   _print)r\   ri   valuer_   r_   r`   _declare_number_const      z"FCodePrinter._declare_number_constc                 C   s(   | j |t|| jd f t|S )Nr>   )Z_number_symbolsaddr&   ZevalfrX   strr\   rm   r_   r_   r`   _print_NumberSymbol   s    z FCodePrinter._print_NumberSymbolc                 C   s   |  | |S rr   )_wrap_fortranindent_code)r\   linesr_   r_   r`   _format_code   s   zFCodePrinter._format_codec                    s    |j \ } fddt|D S )Nc                 3   s&    | ]}t  D ]}||fV  qqd S rr   )range).0jiZrowsr_   r`   	<genexpr>   s   $ z8FCodePrinter._traverse_matrix_indices.<locals>.<genexpr>)shaper   )r\   ZmatZcolsr_   r   r`   _traverse_matrix_indices   s   
z%FCodePrinter._traverse_matrix_indicesc                 C   s^   g }g }|D ]$}t | j|j|jd |jd g\}}}|d|||f  |d q||fS )N   zdo %s = %s, %send do)maprx   labelrj   upperrk   )r\   indicesZ
open_linesZclose_linesr   varstartstopr_   r_   r`   _get_loop_opening_ending   s   
z%FCodePrinter._get_loop_opening_endingc                 C   s   ddl m} |j\}|jrtdtd|t|d}n1|js |jr9tt	t
dt
d||| t||t
d}ntt
dtt
d|t|t
d}| |S )Nr   )r3   r   )Zsympyr3   args
is_integerr   r   r)   Z
is_complexZis_infiniter   r   r   rx   )r\   rm   r3   argZnew_exprr_   r_   r`   _print_sign   s   2$
zFCodePrinter._print_signc           
      C   s4  |j d jdkrtdg }|tr]t|j D ]:\}\}}|dkr-|d| |  n|t|j d kr@|dkr@|d n
|d| |  || | q|d	 d
	|S | j
d dkrd}| |j d j}t|j d d }|r| \}}| |}| |}	|j|||	d}|sz|S td)NTzAll 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if (%s) thenr   elsezelse if (%s) thenend if
rA   rL   zmerge({T}, {F}, {COND}))TFZCONDzmUsing Piecewise as an expression using inline operators is not supported in standards earlier than Fortran95.)r   condrY   Zhasr   	enumeraterk   rx   lenjoinrX   rm   listrR   ru   NotImplementedError)
r\   rm   r   r   ecpatternra   Ztermsr   r_   r_   r`   _print_Piecewise   s2   




zFCodePrinter._print_Piecewisec                 C   s,   d | j|jtd dd|jd |jd S )Nz
{}({}, {})ZAtomT)strictr   )ru   parenthesizeparentr-   r   r   r~   r_   r_   r`   _print_MatrixElement  s
   z!FCodePrinter._print_MatrixElementc           
      C   s  g }g }g }|j D ]}|jr|jr|| q	|jr#|jr#|| q	|| q	|r~|rjt|}t| }| |}|drHd}	|dd  }nd}	t||k rTd| }d| t| | t	j
 t|  |	|f S d| t| | t	j
 t|  f S t| |S )N-r   +z(%s)zcmplx(%s,%s) %s %szcmplx(%s,%s))r   	is_numberZis_realrk   is_imaginaryr,   r$   rx   
startswithr#   ImaginaryUnitr+   
_print_Add)
r\   rm   Z	pure_realZpure_imaginaryZmixedr   PRECZtermtsignr_   r_   r`   r     s<   


zFCodePrinter._print_Addc                    sN   | j d   fdd|jD }|j| }t|ts| |S t| |j| S )Nr>   c                    s   g | ]}t | qS r_   )r%   )r   aZprecr_   r`   
<listcomp>0      z0FCodePrinter._print_Function.<locals>.<listcomp>)rX   r   func
isinstancer(   rx   r+   _print_Function)r\   rm   r   Z	eval_exprr_   r   r`   r   -  s   



zFCodePrinter._print_Functionc                 C   s<   | j d dv rd}t||j\}}d| || |S )NrA   )rJ   r=   z]Python % operator and SymPy's Mod() function are not supported by Fortran 66 or 77 standards.z      modulo({}, {}))rX   r   r   ru   rx   )r\   rm   msgxyr_   r_   r`   
_print_Mod7  s
   
zFCodePrinter._print_Modc                 C      dS )Nz
cmplx(0,1)r_   r~   r_   r_   r`   _print_ImaginaryUnitD  s   z!FCodePrinter._print_ImaginaryUnitc                 C      t |S rr   r}   r~   r_   r_   r`   
_print_intH     zFCodePrinter._print_intc                 C   s.   |j r|jrd| tj |  S t| |S )Nzcmplx(0,%s))r   r   rx   r#   r   r+   
_print_Mulr~   r_   r_   r`   r   K  s
   zFCodePrinter._print_Mulc                 C   s   t |}|jdkrd| td| |j|f S |jdkr>|jjr6|jjr.d| |j S d| |j S d| |j S t	| |S )Nr   z%s/%sr   g      ?zsqrt(%s.0d0)zsqrt(dble(%s))zsqrt(%s))
r,   r2   rx   r   r   baser   Z	is_Numberr+   
_print_Pow)r\   rm   r   r_   r_   r`   r   T  s   

zFCodePrinter._print_Powc                 C   s"   t |jt |j}}d||f S )Nz%d.0d0/%d.0d0)intro   q)r\   rm   ro   r   r_   r_   r`   _print_Rationalg  s   zFCodePrinter._print_Rationalc                 C   sF   t | |}|d}|dkrd|d | ||d d  f S d| S )Nr   r   z%sd%sr   z%sd0)r+   _print_Floatfind)r\   rm   Zprintedr   r_   r_   r`   r   k  s
   
 zFCodePrinter._print_Floatc                 C   sD   |  |j}|  |j}|j}|| jvr|n| j| }d|||S )Nz{} {} {})rx   lhsrhsZrel_op_relationalsru   )r\   rm   lhs_coderhs_codeopr_   r_   r`   _print_Relationalr  s
   zFCodePrinter._print_Relationalc                    s0    fdd|j D }d |jjd|f S )Nc                       g | ]}  |qS r_   rx   )r   r   rf   r_   r`   r   z  r   z/FCodePrinter._print_Indexed.<locals>.<listcomp>%s(%s), )r   rx   r   r   r   )r\   rm   Zindsr_   rf   r`   _print_Indexedy  s   zFCodePrinter._print_Indexedc                 C   s   |  |jS rr   )rx   r   r~   r_   r_   r`   
_print_Idx}  s   zFCodePrinter._print_Idxc                    s>     |j}  |j} djt fdd||j|g S )Nz{0} = {0} {1} {2}c                    
     | S rr   r   r   rf   r_   r`   <lambda>     
 z9FCodePrinter._print_AugmentedAssignment.<locals>.<lambda>)rx   r   r   rs   ru   r   Zbinop)r\   rm   r   r   r_   rf   r`   _print_AugmentedAssignment  s   
z'FCodePrinter._print_AugmentedAssignmentc                 C   s^   |  |j}|jd kr|d|  |j 7 }|jd kr$|d|  |j 7 }d|jjd|f S )Nr   z, mask=r   rh   )rx   Zarraydimmaskr^   __name__rstrip)r\   Zsmparamsr_   r_   r`   _print_sum_  s   

zFCodePrinter._print_sum_c                 C   s
   |  |S rr   )r   )r\   Zprodr_   r_   r`   _print_product_  rq   zFCodePrinter._print_product_c                    s\   dg}|j dkr|d d}nd}d| d jdd|jrdndi|j fd	d
|dS )N
concurrentr   stepre   , {step}z*do {concurrent}{counter} = {first}, {last}z
{body}
end do
zconcurrent c                    r   rr   r   r   rf   r_   r`   r     r   z(FCodePrinter._print_Do.<locals>.<lambda>)applyZexcluder_   )r   rk   ru   r   kwargs)r\   ZdoZexclr   r_   rf   r`   	_print_Do  s   


zFCodePrinter._print_Doc                    s:   |j dkrdnd}d| d jd	i |j fdddS )
Nr   re   r   z$({expr}, {counter} = {first}, {last})c                    r   rr   r   r   rf   r_   r`   r     r   z3FCodePrinter._print_ImpliedDoLoop.<locals>.<lambda>r   r_   )r   ru   r   )r\   Zidlr   r_   rf   r`   _print_ImpliedDoLoop  s   z!FCodePrinter._print_ImpliedDoLoopc                 C   sP   |  |j}t|jtr|jj\}}}ntd|  |j}dj|||||dS )Nz*Only iterable currently supported is Rangez3do {target} = {start}, {stop}, {step}
{body}
end do)targetr   r   r   body)	rx   r   r   iterabler*   r   r   r   ru   )r\   rm   r   r   r   r   r   r_   r_   r`   
_print_For  s   zFCodePrinter._print_Forc                 C   sP   | j ||}| j||j}| j|}|r&|D ]\}}| j| | q|S rr   )rG   rV   rH   ri   type_modulesr[   r|   )r\   Ztype_Ztype_strr[   kvr_   r_   r`   _print_Type  s   zFCodePrinter._print_Typec                    ,   dj  |jdt fdd|jdS )Nz{symbol}({idxs})r   c                    r   rr   r   r   rf   r_   r`   r     r   z-FCodePrinter._print_Element.<locals>.<lambda>)symbolZidxs)ru   rx   r   r   r   r   )r\   elemr_   rf   r`   _print_Element     
zFCodePrinter._print_Elementc                 C   r   rr   r   )r\   extr_   r_   r`   _print_Extent  r   zFCodePrinter._print_Extentc              
      sN  |j j}d}fddtttfD }|ddkr!d}n|ddkr4dg d	|d  }ntd
  t	t
rCtd jd dkrdj jtjv rXdnd|riddt fdd| nd|tjv rrdnd jd}|d kr|d | 7 }|S tjv s|rtddt fddjjg}|S )NZ	dimensionc                    s   g | ]}| j v qS r_   )attrs)r   intent)r   r_   r`   r     r   z3FCodePrinter._print_Declaration.<locals>.<listcomp>Tr   re   r   z, intent(%s))inoutZinoutz!Multiple intents specified for %sz1Pointers are not available by default in Fortran.rA   rK   z"{t}{vc}{dim}{intent}{alloc} :: {s}z, parameterz, dimension(%s)r   c                    r   rr   r   r   rf   r_   r`   r     r   z1FCodePrinter._print_Declaration.<locals>.<lambda>z, allocatable)r   Zvcr   r  Zallocsz = %sz0F77 init./parameter statem. req. multiple lines. c                    r   rr   r   r   rf   r_   r`   r     r   )variablery   attr_paramsr    r!   r"   countindexrY   r   r   r   rX   ru   rx   typer	   r  r   r   r   r   )r\   rm   valr   Zintentsr  resultr_   )r\   r   r`   _print_Declaration  s6   


"
 zFCodePrinter._print_Declarationc                 C   s   d|  td S )Nz(huge(%s) + 1)r   )rx   r   r~   r_   r_   r`   _print_Infinity  r{   zFCodePrinter._print_Infinityc                        dj di |j fdddS )Nz$do while ({condition})
{body}
end doc                    r   rr   r   r   rf   r_   r`   r     r   z+FCodePrinter._print_While.<locals>.<lambda>r   r_   ru   r   r~   r_   rf   r`   _print_While  s   

zFCodePrinter._print_Whilec                 C   r   )Nz.true.r_   r~   r_   r_   r`   _print_BooleanTrue  rt   zFCodePrinter._print_BooleanTruec                 C   r   )Nz.false.r_   r~   r_   r_   r`   _print_BooleanFalse  rt   z FCodePrinter._print_BooleanFalsec                 C   sR   g }|D ]"}| dr|| jd |dd     q|| jd |  q|S )N!rc   r   ra   )r   rk   rg   lstrip)r\   r   r  liner_   r_   r`   _pad_leading_columns  s   
"z!FCodePrinter._pad_leading_columnsc                    s  t dtj tj  t d fdd}g }| jd dkr!d}nd}|D ]}|| jd	 rt|d
kr|ddd
}|dkrBd
}|d| }||d 	 }|
| |r|ddd}|dksht|dk rjd}|d| }||d 	 }|
d| jd	 |f  |sWq%|
| q%|| jd r||d
}|d|  }||d 	 }|r||7 }|
| |r||d}|d|  }||d 	 }|r||7 }|
d| jd |f  |sq%|
| q%|S )zWrap long Fortran lines

           Argument:
             lines  --  a list of lines (without \n character)

           A comment line is split at white space. Code lines are split with a more
           complex rule to give nice results.
        z_+-.z 	()c                    sP   t  |kr
t  S |} fdd}||s&|d8 }|dkr"|S ||r|S )Nc                    sp    |  v r | d  vp7 |  vo | d  v p7 |  v o) | d  vp7 |  vo7 | d  v S )Nr   r_   )pos)r  my_alnummy_whiter_   r`   r     s   zDFCodePrinter._wrap_fortran.<locals>.split_pos_code.<locals>.<lambda>r   r   )r   )r  endposr  splitr  r  )r  r`   split_pos_code  s   z2FCodePrinter._wrap_fortran.<locals>.split_pos_coder@   rd   z &re   rc   H   r     r   Nr   rJ   %s%sra   A   rb   )rZ   stringdigitsZascii_lettersrX   r   rg   r   rfindr  rk   r   )r\   r   r   r  Ztrailingr  r  Zhunkr_   r  r`   r     sX   




zFCodePrinter._wrap_fortranc                    sD  t |tr| |d}d|S | jd dk}dd |D }dd fd	d|D } fd
d|D }dd |D }d}d}d}	g }
t|D ]O\}}|dksU|dkr[|
| qI||| 8 }|rld||	 |  }nd| |	 }d||f }|s| |gd }|
| || rd|	 }nd}||| 7 }qI|s| 	|
S |
S )z0Accepts a string of code or a list of code linesTre   r@   rd   c                 S   s   g | ]}| d qS )z 	)r  r   r  r_   r_   r`   r   L  r   z,FCodePrinter.indent_code.<locals>.<listcomp>)zdo zif(zif zdo
r   ZprogramZ	interface)r   Zenddor   Zendifr   zend programzend interfacec                        g | ]}t tt|j qS r_   r   anyr   r   r(  )inc_keywordr_   r`   r   Q      c                    r)  r_   r*  r(  )dec_keywordr_   r`   r   S  r-  c                 S   s$   g | ]}t tt|jd dgqS )&z&
)r   r+  r   endswithr(  r_   r_   r`   r   U  s    r      r   r  r#     )
r   r}   r   
splitlinesr   rX   r   rk   r  r   )r\   ra   Z
code_linesrd   ZincreaseZdecreaseZcontinuationlevelZcont_paddingZtabwidthZnew_coder   r  Zpaddingr_   )r.  r,  r`   r   E  sN   







zFCodePrinter.indent_codec                    sH   |j rdjdt fdd|j |j dS |j\}d | S )Nzgo to ({labels}), {expr}r   c                    r   rr   r   r   rf   r_   r`   r   z  r   z*FCodePrinter._print_GoTo.<locals>.<lambda>)labelsrm   zgo to %s)rm   ru   r   r   r5  rx   )r\   ZgotoZlblr_   rf   r`   _print_GoTow  s   
zFCodePrinter._print_GoToc                    r  )Nz"program {name}
{body}
end program
c                    r   rr   r   r   rf   r_   r`   r     r   z-FCodePrinter._print_Program.<locals>.<lambda>r   r_   r  )r\   progr_   rf   r`   _print_Program  s
   zFCodePrinter._print_Programc                    r  )NzAmodule {name}
{declarations}

contains

{definitions}
end module
c                    r   rr   r   r   rf   r_   r`   r     r   z,FCodePrinter._print_Module.<locals>.<lambda>r   r_   r  )r\   modr_   rf   r`   _print_Module  s
   zFCodePrinter._print_Modulec                 C   sl   |j dkr| jd dkr| jd d dS |j dkr,| jd dkr,| jd d d	S |j dkr3d
S |j S )NstdoutrA   rM   r9   zstdint=>input_unitZ
input_unitstderrzstdint=>error_unitZ
error_unit*)ri   rX   r[   r|   )r\   Zstrmr_   r_   r`   _print_Stream  s   
zFCodePrinter._print_Streamc                    s@   |j d kr |j }nd}dj|dt fdd|jdS )Nr=  zprint {fmt}, {iolist}r   c                    r   rr   r   r   rf   r_   r`   r     r   z+FCodePrinter._print_Print.<locals>.<lambda>)fmtZiolist)format_stringrx   ru   r   r   Z
print_args)r\   Zpsr?  r_   rf   r`   _print_Print  s   

zFCodePrinter._print_Printc                 C   s&   |j \}dj| jdd| |dS )Nz{result_name} = {arg}result_nameZsympy_result)rB  r   )r   ru   Z_contextrV   rx   )r\   Zrsr   r_   r_   r`   _print_Return  s
   zFCodePrinter._print_Returnc                 C   s   |j \}|rd| | S dS )Nz	return %sreturn)r   rx   )r\   Zfrsr   r_   r_   r`   _print_FortranReturn  s   z!FCodePrinter._print_FortranReturnc                    s   | d}|d u rd}n
|rd|d  nd} jdd }dj| |jd fd	d
|jD |r7d| nd|dt fdd|jdS )NZbind_Cre   z bind(C, name="%s")r   z bind(C)rB  z<{entity}{name}({arg_names}){result}{bind}
{arg_declarations}r   c                    s   g | ]}  |jqS r_   )rx   r   )r   r   rf   r_   r`   r     s    z&FCodePrinter._head.<locals>.<listcomp>z result(%s)r   c                    s     t| S rr   )rx   r   r   rf   r_   r`   r     s    z$FCodePrinter._head.<locals>.<lambda>)entityri   Z	arg_namesr  bindZarg_declarations)	r	  rX   rV   ru   rx   ri   r   Z
parametersr   )r\   rF  fpr   Zbind_C_paramsrG  rB  r_   rf   r`   _head  s   

zFCodePrinter._headc                 C   s&   d | |j}dj | ||dS )N{} function z4interface
{function_head}
end function
end interface)function_head)ru   rx   return_typerI  )r\   rH  rF  r_   r_   r`   _print_FunctionPrototype  s   z%FCodePrinter._print_FunctionPrototypec                 C   s   t |jv rd}n
t|jv rd}nd}d| |j}t| |jd dj|| ||| |j	dW  d    S 1 s=w   Y  d S )Nz
elemental zpure re   rJ  )rB  z,{prefix}{function_head}
{body}
end function
)prefixrK  r   )
r   r  r   ru   rx   rL  r.   ri   rI  r   )r\   fdrN  rF  r_   r_   r`   _print_FunctionDefinition  s   



$z&FCodePrinter._print_FunctionDefinitionc                 C   s   dj | d|| |jdS )Nz({subroutine_head}
{body}
end subroutine
zsubroutine )Zsubroutine_headr   )ru   rI  rx   r   )r\   subr_   r_   r`   _print_Subroutine  s
   

zFCodePrinter._print_Subroutinec                    r   )Nzcall {name}({args})r   c                    r   rr   r   r   rf   r_   r`   r     r   z4FCodePrinter._print_SubroutineCall.<locals>.<lambda>)ri   r   )ru   rx   ri   r   r   Zsubroutine_args)r\   Zscallr_   rf   r`   _print_SubroutineCall  r   z"FCodePrinter._print_SubroutineCallc                    s   dt t fdd|j S )Nz%s => %sc                    r   rr   r   r   rf   r_   r`   r     r   z0FCodePrinter._print_use_rename.<locals>.<lambda>)tupler   r   )r\   rnmr_   rf   r`   _print_use_rename  s   zFCodePrinter._print_use_renamec                    sl   d  |j }|jd kr|dd fdd|jD  7 }|jd kr4|dd fdd|jD  7 }|S )Nzuse %sr   c                    r   r_   r   )r   rU  rf   r_   r`   r     r   z+FCodePrinter._print_use.<locals>.<listcomp>z, only: c                    r   r_   r   )r   Znlyrf   r_   r`   r     r   )rx   	namespacerenamer   Zonly)r\   Zuser  r_   rf   r`   
_print_use  s   
"
"zFCodePrinter._print_usec                 C   r   )Nexitr_   r\   rh   r_   r_   r`   _print_BreakToken  rt   zFCodePrinter._print_BreakTokenc                 C   r   )Ncycler_   r[  r_   r_   r`   _print_ContinueToken  rt   z!FCodePrinter._print_ContinueTokenc                    s4    j d dkr	dnd}|dt fdd|j S )NrA   rM   z[%s]z(/%s/)r   c                    r   rr   r   r   rf   r_   r`   r     r   z6FCodePrinter._print_ArrayConstructor.<locals>.<lambda>)rX   r   r   elements)r\   ZacZfmtstrr_   rf   r`   _print_ArrayConstructor  s   z$FCodePrinter._print_ArrayConstructorrr   )Xr   
__module____qualname____doc__Zprintmethodlanguager   r   r   r   r   r   rG   r   r
   r   r   r   r   r   r   rH   r   Z_default_settingsZ
_operatorsr   rT   propertyrg   rl   rp   rs   rw   rz   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r  r  r   r   r6  r8  r:  r>  rA  rC  rE  rI  rM  rP  rR  rS  rV  rY  r\  r^  r`  __classcell__r_   r_   r]   r`   r8   D   s    	
*'
		!	G2
		
r8   )?rc  typingr   r   collectionsr   	itertoolsr   r%  Zsympy.codegen.astr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   Zsympy.codegen.fnodesr   r   r   r   r   r   r   r   r    r!   r"   Z
sympy.corer#   r$   r%   r&   r'   Zsympy.core.functionr(   Zsympy.core.relationalr)   Z
sympy.setsr*   Zsympy.printing.codeprinterr+   Zsympy.printing.precedencer,   r-   Zsympy.printing.printerr.   r/   r0   rU   r8   r_   r_   r_   r`   <module>   sf    P4	
