+
    io                       R t ^ RIHt ^ RIHt ^ RIHt ^ RIHt ^ RI	t	^ RI
HtHtHtHtHtHtHtHtHtHtHtHtHtHtHtHtHtHtHtHtHt ^ RI H!t!H"t"H#t#H$t$H%t%H&t&H't'H(t(H)t)H*t*H+t+ ^ RI,H-t-H.t.H/t/H0t0H1t1 ^ R	I2H3t3 ^ R
I4H5t5 ^ RI6H7t7 ^ RI8H9t9 ^ RI:H;t; ^ RI<H=t=H>t> ^ RI?H@t@ ^ RI:HAtAHBtB / RRbRRbRRbRRbRRbRRbRRbRRbRRbRRbRRbRRbRRbRRbR R!bR"R#bR$R%btC ! R& R'];4      tDR# )(ar  
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:

https://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.
)annotations)Any)defaultdict)chainN)
AssignmentDeclarationPointervalue_constfloat32float64float80	complex64
complex128int8int16int32int64intcrealintegerbool_complex_nonestderrstdout)allocatableisigndsigncmplxmerge
literal_dp	elementalpure	intent_in
intent_outintent_inout)SAddNFloatSymbol)Function)equal_valued)Eq)Range)CodePrinter)
precedence
PRECEDENCE)printer_context)fcodeprint_fcodesincostanasinacosatanatan2sinhcoshtanhlogexperfAbsabs	conjugateconjgMaxmaxMinminc                  `  a  ] tR t^Ft$ RtRtRt]]]	]
]]/t]R]R]
R]R]R]R	]R
]R]R]R]R/t]RR//t]! ]P4                  3/ R^R/ RRRRR^MRR/B tR]R&   RRRRRR R!R"R#R$/tR%R&/tRdV 3R' llt]R( 4       t V 3R) lt!R* t"R+ t#R, t$R- t%R. t&R/ t'R0 t(R1 t)R2 t*R3 t+R4 t,R5 t-R6 t.R7 t/R8 t0R9 t1R: t2R; t3R< t4R= t5R> t6R? t7R@ t8RA t9RB t:RC t;RD t<RE t=RF t>RG t?RH t@RI tARJ tBRK tCRL tDRM tERN tFRO tGRP tHRQ tIRR tJRS tKRT tLRU tMRV tNRW tORX tPRY tQRZ tRR[ tSR\ tTR] tUR^ tVR_ tWR` tXRa tYRb tZRct[V ;t\# )eFCodePrinterzAA printer to convert SymPy expressions to strings of Fortran code_fcodeFortranzinteger(c_int)zreal*4zreal*8zreal*10z	complex*8z
complex*16z	integer*1z	integer*2z	integer*4z	integer*8logicaliso_c_bindingc_int	precisionuser_functionssource_formatfixedcontractTstandardname_manglingzdict[str, Any]_default_settingsandz.and.orz.or.xorz.neqv.
equivalentz.eqv.notz.not. z!=z/=c           	     	  < V'       g   / p/ V n         . V n        \        \        V P                  P                  4       VP                  R / 4      P                  4       4      4      V n        \        \        V P                  P                  4       VP                  R/ 4      P                  4       4      4      V n        \        SV `%  V4       \        \        4      V n
        VP                  R/ 4      pV P                  P                  V4       0 RmpV P                  R,          V9  d$   \        RV P                  R,          ,          4      h\        \         4      V n        R# )type_aliasestype_mappingsrR   rV   zUnknown Fortran standard: %sN>   B   M   Z   _       )mangled_symbols	used_namedictr   r_   itemspopr`   super__init__known_functionsgetupdate	_settings
ValueErrorr   setmodule_uses)selfsettings	userfuncs	standards	__class__s   &&  v/Users/tonyclaw/.openclaw/workspace/skills/math-calculator/venv/lib/python3.14/site-packages/sympy/printing/fortran.pyrm   FCodePrinter.__init__x   s   H! t'8'8'>'>'@'/||NB'G'M'M'O"Q R!%(:(:(@(@(B(0_b(I(O(O(Q#S T"#O4LL!126	##I.0	>>*%Y6;dnn'?) ) * *&s+    c                	    V P                   R ,          R8X  d	   RRRRRR/# V P                   R ,          R8X  d	   RR	RRRR
/# \        RV P                   R ,          ,          4      h)rS   rT   codez      contz     @ commentzC     free z! zUnknown source format: %s)rq   rr   )ru   s   &rz   _leadFCodePrinter._lead   sd    >>/*g5HfiHMM^^O,6B)TBB84>>/;ZZ[[r|   c                	  < V P                   R ,          R8X  d   WP                  9  d   VP                  pVP                  4       V P                  9   d   VR,          pK*  V P                  P                  VP                  4       4       W!P                  8X  d   WP                  V&   M\        V4      V P                  V&   VP                  V P                  4      p\        SV `%  V4      pV# )rW   T_)
rq   rg   namelowerrh   appendr*   xreplacerl   _print_Symbol)ru   exprr   ry   s   && rz   r   FCodePrinter._print_Symbol   s    >>/*d2///yyjjldnn4CKD%%djjl399$15((.17D((.==!5!56Dw$T*r|   c                	    V) ^,          # )    )ru   ps   &&rz   _rate_index_position!FCodePrinter._rate_index_position   s    r!tr|   c                	    V# Nr   )ru   
codestrings   &&rz   _get_statementFCodePrinter._get_statement   s    r|   c                	$    R P                  V4      # )z! {})format)ru   texts   &&rz   _get_commentFCodePrinter._get_comment   s    }}T""r|   c                	B    R P                  WP                  V4      4      # )zparameter ({} = {}))r   _print)ru   r   values   &&&rz   _declare_number_const"FCodePrinter._declare_number_const   s    $++D++e2DEEr|   c           	     	    V P                   P                  V\        VP                  V P                  R ,          4      4      34       \        V4      # rQ   )_number_symbolsaddr)   evalfrq   strru   r   s   &&rz   _print_NumberSymbol FCodePrinter._print_NumberSymbol   s>     	  $djj9T.U(V!WX4yr|   c                	B    V P                  V P                  V4      4      # r   )_wrap_fortranindent_code)ru   liness   &&rz   _format_codeFCodePrinter._format_code   s    !!$"2"25"9::r|   c                	L   a VP                   w  opV3R  l\        V4       4       # )c              3  N   <"   T F  p\        S4       F  q"V3x  K
  	  K  	  R # 5ir   )range).0jirowss   &  rz   	<genexpr>8FCodePrinter._traverse_matrix_indices.<locals>.<genexpr>   s     A1U4[A[s   "%)shaper   )ru   matcolsr   s   && @rz   _traverse_matrix_indices%FCodePrinter._traverse_matrix_indices   s    YY
dAdAAr|   c           	     	   . p. pV Fy  p\        V P                  VP                  VP                  ^,           VP                  ^,           .4      w  rVpVP                  RV: RV: RV: 24       VP                  R4       K{  	  W#3# )   do z = , end do)mapr   labelr   upperr   )ru   indices
open_linesclose_linesr   varstartstops   &&      rz   _get_loop_opening_ending%FCodePrinter._get_loop_opening_ending   sw    
A"4;;WWaggk177Q;7 9C#udCDx(  &&r|   c           
     	   ^ RI Hp VP                  w  pVP                  '       d#   \	        ^ \        ^V4      \        V^ 4      4      pMVP                  '       g   VP                  '       dP   \	        \        \        ^ 4      \        ^ 4      4      W2! V4      ,          \        V! V4      \        ^ 4      4      4      pM<\	        \        ^ 4      \        \        ^4      V4      \        V\        ^ 4      4      4      pV P                  V4      # )    )rB   )$sympy.functions.elementary.complexesrB   args
is_integerr   r   r-   
is_complexis_infiniter   r    r   r   )ru   r   rB   argnew_exprs   &&   rz   _print_signFCodePrinter._print_sign   s    <yy>>>Qar#qz:HnnnU:a=*Q-@#c#h,PRSVWZS[]ghi]jPklHZ]E*Q-,Er#zZ[}G]^H{{8$$r|   c                	   VP                   R,          P                  R8w  d   \        R4      h. pVP                  \        4      '       d   \        VP                   4       F  w  pw  rEV^ 8X  d)   VP                  RV P                  V4      ,          4       MaV\        VP                   4      ^,
          8X  d   VR8X  d   VP                  R4       M'VP                  RV P                  V4      ,          4       VP                  V P                  V4      4       K  	  VP                  R4       RP                  V4      # V P                  R,          ^_8  d   R	pV P                  VP                   R,          P                  4      p\        VP                   R
R 4      pV'       dJ   VP                  4       w  rEV P                  V4      pV P                  V4      p	VP                  WV	R7      pKQ  V# \        R4      h)r   TzAll Piecewise expressions must contain an (expr, True) statement to be used as a default condition. Without one, the generated expression may not evaluate to anything under some condition.zif (%s) thenelsezelse if (%s) thenend if
rV   zmerge({T}, {F}, {COND})N)TFCONDzmUsing Piecewise as an expression using inline operators is not supported in standards earlier than Fortran95.)r   condrr   hasr   	enumerater   r   lenjoinrq   r   listrk   r   NotImplementedError)
ru   r   r   r   ecpatternr~   termsr   s
   &&        rz   _print_PiecewiseFCodePrinter._print_Piecewise   s   99R=%  / 0 0
 88J&tyy1	6A6LL$++a.!@A#dii.1,,dLL(LL!4t{{1~!EFT[[^, 2 LL"99U##^^J'2- 0G;;tyy}112D3B(Eyy{{{1~{{1~~~4~@K & 'J K Kr|   c                	    R P                  V P                  VP                  \        R,          RR7      VP                  ^,           VP
                  ^,           4      # )z
{}({}, {})AtomT)strict)r   parenthesizeparentr1   r   r   r   s   &&rz   _print_MatrixElement!FCodePrinter._print_MatrixElement   sN    ""4#4#4T[[6"4 $5 $126&&1*dffqjJ 	Jr|   c           
     	   . p. p. pVP                    F  pVP                  '       d&   VP                  '       d   VP                  V4       K:  VP                  '       d&   VP                  '       d   VP                  V4       Kq  VP                  V4       K  	  V'       Ed   V'       d   \        V4      p\        V!  pV P                  V4      pVP                  R 4      '       d   R p	VR,          pMRp	\        V4      V8  d
   RV,          pRV P                  \        V!  4      : RV P                  \        P                  ) \        V!  ,          4      : RV	: RV: 2# RV P                  \        V!  4      : RV P                  \        P                  ) \        V!  ,          4      : R2# \        P                  ! W4      # )	-r   NN+z(%s)zcmplx(,z)  ))r   	is_numberis_realr   is_imaginaryr0   r'   r   
startswithr&   ImaginaryUnitr/   
_print_Add)
ru   r   	pure_realpure_imaginarymixedr   PRECtermtsigns
   &&        rz   r  FCodePrinter._print_Add  sa    	99C}}}  %3#3#3#3%%c*S!  >!$'E{KK%<<$$D"ADd#d*
A KKY0KK 0n1E EF!  & KKY0KK 0n1E EF 
 ))$55r|   c                	0   V P                   R ,          pVP                   Uu. uF  p\        W24      NK  	  ppVP                  ! V!  p\	        V\
        4      '       g   V P                  V4      # \        P                  ! WP                  ! V!  4      # u upi r   )	rq   r   r(   func
isinstancer+   r   r/   _print_Function)ru   r   precar   	eval_exprs   &&    rz   r  FCodePrinter._print_Function+  su    {+$(II.Iq!
I.IIt$	)X..;;y))..tYY5EFF /s   Bc                	    V P                   R ,          R9   d   Rp\        V4      hVP                  w  r4RP                  V P	                  V4      V P	                  V4      4      # )rV   z]Python % operator and SymPy's Mod() function are not supported by Fortran 66 or 77 standards.z      modulo({}, {}))ra   rb   )rq   r   r   r   r   )ru   r   msgxys   &&   rz   
_print_ModFCodePrinter._print_Mod5  sU    
 >>*%1>C%c**99DA)00QQPPr|   c                	    R # )z
cmplx(0,1)r   r   s   &&rz   _print_ImaginaryUnit!FCodePrinter._print_ImaginaryUnitB  s    r|   c                	    \        V4      # r   r   r   s   &&rz   
_print_intFCodePrinter._print_intF  s    4yr|   c                	    VP                   '       dA   VP                  '       d/   R V P                  \        P                  ) V,          4      ,          # \
        P                  ! W4      # )zcmplx(0,%s))r   r   r   r&   r  r/   
_print_Mulr   s   &&rz   r"  FCodePrinter._print_MulI  sN    >>>d/// Q__,T12  ))$55r|   c                	f   \        V4      p\        VP                  R4      '       d<   V P                  \	        ^4      4      : RV P                  VP                  V4      : 2# \        VP                  R4      '       d   VP                  P                  '       da   VP                  P                  '       d#   RV P                  VP                  4      ,          # RV P                  VP                  4      ,          # RV P                  VP                  4      ,          # \        P                  ! W4      # )r   /g      ?zsqrt(%s.0d0)zsqrt(dble(%s))zsqrt(%s)r   )r0   r,   r@   r   r    r   baser   	is_Numberr/   
_print_Pow)ru   r   r  s   && rz   r(  FCodePrinter._print_PowR  s    $"%%JqM*!!$))T2  $((C((yy###99&&&)DKK		,BBB+dkk$)).DDD!DKK		$:::))$55r|   c                	h    \        VP                  4      \        VP                  4      r2R W#3,          # )z%d.0d0/%d.0d0)intr   q)ru   r   r   r,  s   &&  rz   _print_RationalFCodePrinter._print_Rationale  s&    466{CK1!''r|   c                	    \         P                  ! W4      pVP                  R 4      pVR8  d   VRV : RW#^,           R : 2# RV,          # )r   Ndz%sd0r   )r/   _print_Floatfind)ru   r   printedr   s   &&  rz   r1  FCodePrinter._print_Floati  sK    **46LLr6%bqk7q56?;;r|   c                	    V P                  VP                  4      pV P                  VP                  4      pVP                  pW@P                  9  d   TMV P                  V,          pR P                  W$V4      # )z{} {} {})r   lhsrhsrel_op_relationalsr   )ru   r   lhs_coderhs_codeops   &&   rz   _print_RelationalFCodePrinter._print_Relationalp  s_    ;;txx(;;txx([[...RD4E4Eb4I  x88r|   c                	    VP                    Uu. uF  q P                  V4      NK  	  ppV P                  VP                  P                  4      : R RP	                  V4      : R2# u upi )(r   r   )r   r   r&  r   r   )ru   r   r   indss   &&  rz   _print_IndexedFCodePrinter._print_Indexedw  sI    )-7AQ7;;tyy74II 8s   A&c           	     	    V P                  VP                  4      pV P                  VP                  4      pV P                  R P	                  V P                  V4      V P                  VP
                  4      V P                  V4      4      4      # )z{0} = {0} {1} {2})r   r6  r7  r   r   binop)ru   r   r:  r;  s   &&  rz   _print_AugmentedAssignment'FCodePrinter._print_AugmentedAssignment{  sp    ;;txx(;;txx(""#6#=#=KK!4;;tzz#:DKK<Q$S T 	Tr|   c                	z   V P                  VP                  4      pVP                  R 8w  d*   VRV P                  VP                  4      ,           ,          pVP                  R 8w  d*   VRV P                  VP                  4      ,           ,          pVP                  P
                  P                  R4      : RV: R2# )Nr   z, mask=r   r@  r   )r   arraydimmaskry   __name__rstrip)ru   smparamss   && rz   _print_sum_FCodePrinter._print_sum_  s    RXX&66T>dT[[000F77d?i$++bgg"666F<<0077<fEEr|   c                	$    V P                  V4      # r   )rP  )ru   prods   &&rz   _print_product_FCodePrinter._print_product_  s    %%r|   c           	     	   a  R .pVP                   ^8X  d   VP                  R4       RpMRpRV,           R,           P                  ! R	R VP                  '       d   RMR/VP	                  V 3R lVR7      B # )

concurrentstepr   , {step}z*do {concurrent}{counter} = {first}, {last}z
{body}
end do
zconcurrent c                &   < SP                  V 4      # r   r   r   ru   s   &rz   <lambda>(FCodePrinter._print_Do.<locals>.<lambda>  s    $++c*:r|   )applyexcluder   )rX  r   r   rW  kwargs)ru   doexclrX  s   f&  rz   	_print_DoFCodePrinter._print_Do  s    ~77a<KKDD 9= ?  &	 

 )+}2
 ii:DiI
 	
r|   c                	   a  VP                   ^8X  d   RMRpRV,           R,           P                  ! R/ VP                  V 3R lR7      B # )r   r   rY  z$({expr}, {counter} = {first}, {last}r   c                &   < SP                  V 4      # r   r[  r\  s   &rz   r]  3FCodePrinter._print_ImpliedDoLoop.<locals>.<lambda>  s    4;;s+;r|   r_  r   )rX  r   ra  )ru   idlrX  s   f& rz   _print_ImpliedDoLoop!FCodePrinter._print_ImpliedDoLoop  sE    XX]r
6t;C?GG 
jj;j<
 	
r|   c                	.   V P                  VP                  4      p\        VP                  \        4      '       d   VP                  P
                  w  r4pM\        R 4      hV P                  VP                  4      pRP                  W#V^,
          WVR7      # )z*Only iterable currently supported is Rangez3do {target} = {start}, {stop}, {step}
{body}
end do)targetr   r   rX  body)	r   rn  r  iterabler.   r   r   ro  r   )ru   r   rn  r   r   rX  ro  s   &&     rz   
_print_ForFCodePrinter._print_For  s{    T[[)dmmU++ $ 2 2E%&RSS{{499% &$(! ! .	.r|   c                	&   V P                   P                  W4      pV P                  P                  WP                  4      pV P                  P                  V4      pV'       d.   V F'  w  rEV P
                  V,          P                  V4       K)  	  V# r   )r_   ro   r`   r   type_modulesrt   r   )ru   type_type_strrt   kvs   &&    rz   _print_TypeFCodePrinter._print_Type  su    !!%%e3%%))%<''++E2#  #''* $r|   c                	   a  R P                  S P                  VP                  4      RP                  V 3R lVP                   4       4      R7      # ){symbol}({idxs})r   c              3  F   <"   T F  pSP                  V4      x  K  	  R # 5ir   r[  r   r   ru   s   & rz   r   .FCodePrinter._print_Element.<locals>.<genexpr>       EDKK,,   !symbolidxs)r   r   r  r   r   ru   elems   f&rz   _print_ElementFCodePrinter._print_Element  sA    !((;;t{{+EEF ) 
 	
r|   c                	    \        V4      # r   r  )ru   exts   &&rz   _print_ExtentFCodePrinter._print_Extent  s    3xr|   c           
     	8  a  VP                   pVP                  pVP                  R 4      p\        \        \
        3 Uu. uF  qUVP                  9   NK  	  ppVP                  R4      ^ 8X  d   RpMJVP                  R4      ^8X  d#   R. ROVP                  R4      ,          ,          pM\        RS ,          4      h\        V\        4      '       d   \        R4      hS P                  R,          ^Z8  d   RP                  S P                  VP                   4      \"        VP                  9   d   RMRV'       d#   R	R
P%                  V 3R lV 4       4      ,          MRT\&        VP                  9   d   RMRS P                  VP(                  4      R7      pVR8w  d    VRS P                  V4      ,          ,          pV# \"        VP                  9   g	   V'       d   \        R4      hRP%                  V 3R lVP                   VP(                  3 4       4      pV# u upi )	dimensionTr   z, intent(%s)z!Multiple intents specified for %sz1Pointers are not available by default in Fortran.rV   z"{t}{vc}{dim}{intent}{alloc} :: {s}z, parameterz, dimension(%s)r   c              3  F   <"   T F  pSP                  V4      x  K  	  R # 5ir   r[  r~  s   & rz   r   2FCodePrinter._print_Declaration.<locals>.<genexpr>  s     2Ss4;;s3C3Csr  z, allocatable)r	  vcrJ  intentallocsNz = %sz0F77 init./parameter statem. req. multiple lines.r   c              3  F   <"   T F  pSP                  V4      x  K  	  R # 5ir   r[  r~  s   & rz   r   r    s     R;QCt{{3//;Qr  )inoutinout)variabler   attr_paramsr#   r$   r%   attrscountindexrr   r  r   r   rq   r   r   typer	   r   r   r  )ru   r   r   valrJ  r  intentsresults   f&      rz   _print_DeclarationFCodePrinter._print_Declaration  s   mmiiook*6?\5Z[5Z6SYY&5Z[==!#F]]4 A%#&<W]]4=P&QQF@4GHHc7##%&YZZ>>*%+9@@++chh'$/399$<="X[%		2Ss2S(TTac)4		)Aor++cjj) A F d{'DKK$444 	 cii'3)*\]]XXRCHHcjj;QRSF5 \s   Hc                	D    R V P                  \        ^ 4      4      ,          # )z(huge(%s) + 1))r   r    r   s   &&rz   _print_InfinityFCodePrinter._print_Infinity  s    $++jm"<<<r|   c                	P   a  R P                   ! R/ VP                  V 3R lR7      B # )z$do while ({condition})
{body}
end doc                &   < SP                  V 4      # r   r[  r\  s   &rz   r]  +FCodePrinter._print_While.<locals>.<lambda>  s    dkk#.r|   ri  r   r   ra  r   s   f&rz   _print_WhileFCodePrinter._print_While  s1    7>> 1. BM B0 1 	1r|   c                	    R # )z.true.r   r   s   &&rz   _print_BooleanTrueFCodePrinter._print_BooleanTrue  s    r|   c                	    R # )z.false.r   r   s   &&rz   _print_BooleanFalse FCodePrinter._print_BooleanFalse  s    r|   c                	   . pV F  pVP                  R 4      '       dA   VP                  V P                  R,          VR,          P                  4       ,           4       KZ  VP                  V P                  R,          V,           4       K  	  V# )!r   r   r~   )r  r   r   lstrip)ru   r   r  lines   &&  rz   _pad_leading_columns!FCodePrinter._pad_leading_columns  sf    Ds##djj3d2hoo6GGHdjj0478	 
 r|   c                  aa	 \        R\        P                  ,           \        P                  ,           4      o\        R4      o	VV	3R lp. pV P                  R,          R8X  d   RpMRpV EF  pVP                  V P                  R,          4      '       d   \        V4      ^H8  d   VP                  R	^^H4      pVR8X  d   ^HpVR
V pWVR
 P                  4       pVP                  V4       V'       dn   VP                  R	^ ^B4      pVR8X  g   \        V4      ^B8  d   ^BpVR
V pWVR
 P                  4       pVP                  V P                  R,          : V: 24       Ku  K  VP                  V4       EK  VP                  V P                  R,          4      '       d   V! V^H4      pVR
V P                  4       pWVR
 P                  4       pV'       d	   Wt,          pVP                  V4       V'       di   V! V^A4      pVR
V P                  4       pWVR
 P                  4       pV'       d	   Wt,          pVP                  V P                  R,          : V: 24       Kp  EK  VP                  V4       EK	  	  V# )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                   <a  \        S 4      V8:  d   \        S 4      # TpV VV3R  lpV! V4      '       g   V^,          pV^ 8X  g   K   V# V# )c                l  < SV ,          S9   ;'       d    SV ^,
          ,          S9  ;'       g    SV ,          S9  ;'       d    SV ^,
          ,          S9   ;'       gW    SV ,          S9   ;'       d    SV ^,
          ,          S9  ;'       g(    SV ,          S9  ;'       d    SV ^,
          ,          S9   # )r   r   )posr  my_alnummy_whites   &rz   r]  DFCodePrinter._wrap_fortran.<locals>.split_pos_code.<locals>.<lambda>	  s    ch&HH4a=+H J Jc(*HHtC!G}/HJ Jch&HH4a=+HJ J c(*HHtC!G}/HJr|   )r   )r  endposr  splitr  r  s   f&  rz   split_pos_code2FCodePrinter._wrap_fortran.<locals>.split_pos_code  sK    4yF"4y CJE
 Cjjq!8!MJr|   rS   r   z &r   r   r   Nr~   r   r   )rs   stringdigitsascii_lettersrq   r  r   r   rfindr  r   rM  )
ru   r   r  r  trailingr  r  hunkr  r  s
   &&      @@rz   r   FCodePrinter._wrap_fortran  s    v-0D0DDEw<	 >>/*f4HHDtzz)455t9r>**S!R0Cby :D:,,.DMM$'"jja4"9D	B"$C#DSz#Dz002

90Et&LM  MM$'F!344$T2.DSz((*Dz((*$Dd#(r2C:,,.D:,,.D(MMDJJv,>"EF  d#G H r|   c                \   \        V\        4      '       d2   V P                  VP                  R4      4      pRP	                  V4      # V P
                  R,          R8H  pV Uu. uF  qDP                  R4      NK  	  ppR	pR
pV Uu. uF+  p\        \        \        VP                  V4      4      4      NK-  	  ppV Uu. uF+  p\        \        \        VP                  V4      4      4      NK-  	  ppV Uu. uF-  p\        \        \        VP                  RR.4      4      4      NK/  	  p	p^ p
^ p^p. p\        V4       F  w  rVR9   d   VP                  V4       K  WV,          ,          p
V'       d   RW,          V,           ,          pMRV
,          V,          pV: V: 2pV'       g   V P                  V.4      ^ ,          pVP                  V4       W,          '       d   ^V,          pM^ pWV,          ,          p
K  	  V'       g   V P                  V4      # V# u upi u upi u upi u upi )z0Accepts a string of code or a list of code linesTr   rS   r   z 	&z&
r   )r   zif(zif zdo
r   program	interface)r   enddor   endifr   zend programzend interface)r   r   )r  r   r   
splitlinesr   rq   r  r+  anyr   r  endswithr   r   r  r   )ru   r~   
code_linesr   r  inc_keyworddec_keywordincreasedecreasecontinuationlevelcont_paddingtabwidthnew_coder   paddings   &&              rz   r   FCodePrinter.indent_code?  s   dC  ))$//$*?@J77:&&~~o.&8046U#6Sd "&(!% S+>?@!% 	 ( "&(!% S+>?@!% 	 ( &*,%)T ST]]S%L!ABC%) 	 ,  GAz!%a[ Eu~<=e)H,$d+D00$8;OOD! z a[ E+ '. %%h//S 7
((,s   "H1H<1H$33H)c                	  a  VP                   '       dP   R P                  RP                  V 3R lVP                   4       4      S P	                  VP                   4      R7      # VP                  w  pRS P	                  V4      ,          # )zgo to ({labels}), {expr}r   c              3  F   <"   T F  pSP                  V4      x  K  	  R # 5ir   r[  r~  s   & rz   r   +FCodePrinter._print_GoTo.<locals>.<genexpr>t  s     !Jks$++c"2"2kr  )labelsr   zgo to %s)r   r   r   r  r   )ru   gotolbls   f& rz   _print_GoToFCodePrinter._print_GoToq  sk    999-44yy!Jdkk!JK[[+ 5  
 ;;DCC 000r|   c                	P   a  R P                   ! R/ VP                  V 3R lR7      B # )z"program {name}
{body}
end program
c                &   < SP                  V 4      # r   r[  r\  s   &rz   r]  -FCodePrinter._print_Program.<locals>.<lambda>  s    S1Ar|   ri  r   r  )ru   progs   f&rz   _print_ProgramFCodePrinter._print_Program{  s7     &	 D ;;%A;B	D 	Dr|   c                	P   a  R P                   ! R/ VP                  V 3R lR7      B # )zAmodule {name}
{declarations}

contains

{definitions}
end module
c                &   < SP                  V 4      # r   r[  r\  s   &rz   r]  ,FCodePrinter._print_Module.<locals>.<lambda>  s    C0@r|   ri  r   r  )ru   mods   f&rz   _print_ModuleFCodePrinter._print_Module  s7    
 & C ::$@:AC 	Cr|   c                	t   VP                   R 8X  d=   V P                  R,          R8  d%   V P                  R,          P                  R4       R# VP                   R8X  d=   V P                  R,          R8  d%   V P                  R,          P                  R4       R# VP                   R 8X  d   R	# VP                   # )
r   rV   re   rO   zstdint=>input_unit
input_unitr   zstdint=>error_unit
error_unit*)r   rq   rt   r   )ru   strms   &&rz   _print_StreamFCodePrinter._print_Stream  s    99 T^^J%?4%G_-112FGYY("t~~j'AT'I_-112FGyyH$yy r|   c                	<  a  VP                   \        8X  d   R pRpMLRR\        R\        R/P	                  VP
                  R4      /,          pS P                  VP                   4      pVP                  VRP                  V 3R lVP                   4       4      R7      # )	zprint {fmt}, {iolist}r  z3write(%(out)s, fmt="{fmt}", advance="no"), {iolist}r  06r   c              3  F   <"   T F  pSP                  V4      x  K  	  R # 5ir   r[  r~  s   & rz   r   ,FCodePrinter._print_Print.<locals>.<genexpr>  s     7#T[[r  )fmtiolist)
format_stringr   r   r   ro   filer   r   r   
print_args)ru   pstemplater   s   f&  rz   _print_PrintFCodePrinter._print_Print  s    t#.HCLVS155bggsCP H ++b../C3tyy7709 : 	:r|   c                	    VP                   w  pR P                  V P                  P                  RR4      V P	                  V4      R7      # )z{result_name} = {arg}result_namesympy_result)r
  r   )r   r   _contextro   r   )ru   rsr   s   && rz   _print_ReturnFCodePrinter._print_Return  sE    ww&--))-HC  . 
 	
r|   c                	b    VP                   w  pV'       d   R V P                  V4      ,          # R# )z	return %sreturn)r   r   )ru   frsr   s   && rz   _print_FortranReturn!FCodePrinter._print_FortranReturn  s'    xxS!111r|   c                	  a  VP                  R 4      pVf   RpMV'       d   RV^ ,          ,          MRpS P                  P                  RR4      pRP                  TS P	                  VP
                  4      RP                  VP                   Uu. uF  pS P	                  VP                  4      NK   	  up4      V'       d
   RV,          MRVR	P                  V 3R
 lVP                   4       4      R7      # u upi )bind_CNr   z bind(C, name="%s")z bind(C)r
  z<{entity}{name}({arg_names}){result}{bind}
{arg_declarations}r   z result(%s)r   c              3  X   <"   T F  pSP                  \        V4      4      x  K!  	  R # 5ir   )r   r   r~  s   & rz   r   %FCodePrinter._head.<locals>.<genexpr>  s$     '_Q^#K4D(E(EQ^s   '*)entityr   	arg_namesr  bindarg_declarations)	r  rq   ro   r   r   r   r   
parametersr  )ru   r  fpra  bind_C_paramsr  r
  r   s   f&&,    rz   _headFCodePrinter._head  s    x0 D?L(=+;;R\Dnn((=!
&RWW%iiBMM RMSSZZ!8M RS4?MK/R!YY'_QSQ^Q^'_`  

	
 !Ss   $C6c                	    R P                  V P                  VP                  4      4      pRP                  V P                  W!4      R7      # ){} function z4interface
{function_head}
end function
end interface)function_head)r   r   return_typer   )ru   r  r  s   && rz   _print_FunctionPrototype%FCodePrinter._print_FunctionPrototype  s@    &&t{{2>>'BC &tzz&5&
6	7r|   c           	     	   \         VP                  9   d   R pM\        VP                  9   d   RpMRpRP                  V P	                  VP
                  4      4      p\        WP                  R7      ;_uu_ 4        RP                  VV P                  W14      V P	                  VP                  4      R7      uuRRR4       #   + '       g   i     R# ; i)z
elemental zpure r   r#  )r
  z,{prefix}{function_head}
{body}
end function
)prefixr$  ro  N)
r!   r  r"   r   r   r%  r2   r   r   ro  )ru   fdr)  r  s   &&  rz   _print_FunctionDefinition&FCodePrinter._print_FunctionDefinition  s     !FRXXFF&&t{{2>>'BCTww77! f"jj4[[)   8777s   ;<CC	c                	z    R P                  V P                  RV4      V P                  VP                  4      R7      # )z({subroutine_head}
{body}
end subroutine
zsubroutine )subroutine_headro  )r   r   r   ro  )ru   subs   &&rz   _print_SubroutineFCodePrinter._print_Subroutine  s;     & JJ}c:SXX&  
		
r|   c                	   a  R P                  S P                  VP                  4      RP                  V 3R lVP                   4       4      R7      # )zcall {name}({args})r   c              3  F   <"   T F  pSP                  V4      x  K  	  R # 5ir   r[  r~  s   & rz   r   5FCodePrinter._print_SubroutineCall.<locals>.<genexpr>  s     N8MDKK,,8Mr  )r   r   )r   r   r   r   subroutine_args)ru   scalls   f&rz   _print_SubroutineCall"FCodePrinter._print_SubroutineCall  sC    $++UZZ(N8M8MNO , 
 	
r|   c                	   a  R \         ;QJ d'    . V 3R lVP                   4       F  NK  	  5,          # ! V 3R lVP                   4       4      ,          # )z%s => %sc              3  F   <"   T F  pSP                  V4      x  K  	  R # 5ir   r[  r~  s   & rz   r   1FCodePrinter._print_use_rename.<locals>.<genexpr>  s     "Hx4;;s#3#3xr  )tupler   )ru   rnms   f&rz   _print_use_renameFCodePrinter._print_use_rename  s5    EE"Hsxx"HEIIE"Hsxx"HIIIr|   c           
     	   R V P                  VP                  4      ,          pVP                  R8w  dH   TRRP                  VP                   Uu. uF  q0P                  V4      NK  	  up4      ,           ,          pVP                  R8w  dH   TRRP                  VP                   Uu. uF  q@P                  V4      NK  	  up4      ,           ,          pV# u upi u upi )zuse %sNr   z, only: )r   	namespacerenamer   only)ru   user  r=  nlys   &&   rz   
_print_useFCodePrinter._print_use  s    DKK66::dTYYCJJ'OJSC(8J'OPPPF88tj499#((-S(3kk#.>(-S#TTTF (P-Ss   C'Cc                	    R # )exitr   ru   r   s   &&rz   _print_BreakTokenFCodePrinter._print_BreakToken  s    r|   c                	    R # )cycler   rJ  s   &&rz   _print_ContinueToken!FCodePrinter._print_ContinueToken   s    r|   c                	   a  S P                   R ,          R8  d   RMRpVRP                  V 3R lVP                   4       4      ,          # )rV   re   z[%s]z(/%s/)r   c              3  F   <"   T F  pSP                  V4      x  K  	  R # 5ir   r[  r~  s   & rz   r   7FCodePrinter._print_ArrayConstructor.<locals>.<genexpr>  s     "K{4;;s#3#3{r  )rq   r   elements)ru   acfmtstrs   f& rz   _print_ArrayConstructor$FCodePrinter._print_ArrayConstructor  s8    >>*5=8		"Kr{{"KLLLr|   c                	   a  R P                  S P                  VP                  4      RP                  V 3R lVP                   4       4      R7      # )r|  r   c              3  F   <"   T F  pSP                  V4      x  K  	  R # 5ir   r[  r~  s   & rz   r   3FCodePrinter._print_ArrayElement.<locals>.<genexpr>
  r  r  r  )r   r   r   r   r   r  s   f&rz   _print_ArrayElement FCodePrinter._print_ArrayElement  sA    !((;;tyy)EEF ) 
 	
r|   )rn   rg   rt   r_   r`   rh   r   )]rL  
__module____qualname____firstlineno____doc__printmethodlanguager   r   r   r   r   r   r_   r   r
   r   r   r   r   r   r   r`   rt  ri   r/   rX   __annotations__
_operatorsr9  rm   propertyr   r   r   r   r   r   r   r   r   r   r   r   r   r  r  r  r  r  r"  r(  r-  r1  r=  rB  rF  rP  rT  rd  rk  rq  ry  r  r  r  r  r  r  r  r  r   r   r  r  r  r  r  r  r  r   r&  r+  r0  r7  r>  rF  rK  rO  rW  r\  __static_attributes____classcell__)ry   s   @rz   rK   rK   F   sF   KKH 	g*L 	;Lk{{{yM 	(L )-[-J-J )R"DBO )~  	wfxgxJ 	dL,( \ \"#F;B	'	%(KTJ%6NGQ66&( 9JTF&
"

.
B=1EN0d1DC!
:

&7(

JM
 
r|   rK   )Era  
__future__r   typingr   collectionsr   	itertoolsr   r  sympy.codegen.astr   r   r   r	   r
   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   sympy.codegen.fnodesr   r   r   r   r   r    r!   r"   r#   r$   r%   
sympy.corer&   r'   r(   r)   r*   sympy.core.functionr+   sympy.core.numbersr,   sympy.core.relationalr-   
sympy.setsr.   sympy.printing.codeprinterr/   sympy.printing.precedencer0   r1   sympy.printing.printerr2   r3   r4   rn   rK   r   r|   rz   <module>rw     sL  & #  #       
    0 / ( + $  2 < 2 :	5	5 
5 F	
 F F W F F F 
5 
5 
5 
5   
5!" 
5#*E
; E
r|   