o
    g                     @   sH  d dl mZ d dlmZ d dlmZmZmZ d dlm	Z	 d dl
mZmZmZ d dlmZmZmZmZmZmZ d dlmZ d dlmZ d d	lmZmZ d d
lmZ d dlmZm Z  d dl!m"Z"m#Z# d dl$m%Z% d dl&m'Z' d dl(m)Z)m*Z*m+Z+ d dl,m-Z- d dl.m/Z/ d dl0m1Z1 d dl2m3Z3m4Z4m5Z5 d dl6m7Z7m8Z8m9Z9m:Z:m;Z;m<Z<m=Z=m>Z>m?Z?m@Z@mAZAmBZBmCZC d dlmDZD d dlmEZE d dlFmGZGmHZHmIZImJZJmKZK d dlLmMZMmNZN d dlOmPZPmQZQ d dlRmSZSmTZT d dlUmVZVmWZW d dlXmYZY d dlZm[Z[ dd Z\d d! Z]d"d# Z^d$d% Z_d&d' Z`d(d) Zad*d+ Zbd,d- Zcd.d/ Zdd0d1 Zed2d3 Zfd4d5 Zgd6d7 Zhd8d9 Zid:d; Zjd<d= Zkd>d? Zld@dA ZmdBdC ZndDdE ZodFdG ZpdHdI ZqdJdK ZrdLdM ZsdNdO ZtdPdQ ZudRdS ZvdTdU ZwdVdW ZxdXdY ZydZd[ Zzd\d] Z{d^d_ Z|d`da Z}dbdc Z~ddde Zdfdg Zdhdi Zdjdk Zdldm Zdndo Zdpdq Zdrds ZdtS )u    )Add)Expr)FunctionLambdadiff)Mod)Catalan
EulerGammaGoldenRatio)EFloatIIntegerRationalpi)Eq)S)Dummysymbols)	factorial)	conjugatesign)explog)sqrt)	Piecewise)atan2cossin)gamma)Integral)Range)For
Assignment
aug_assign)DeclarationVariablefloat32float64value_constrealbool_WhileFunctionPrototypeFunctionDefinitionintegerReturnElement)UnevaluatedExpr)
Relational)AndOrNot
EquivalentXor)MatrixMatrixSymbol)fcodeFCodePrinter)IndexedBaseIdx)ArraySymbolArrayElement)implemented_function)raisesc            
      C   s   t ddd\} }}t|| }tt| | }t|dddks!J t d\}}}t|| }tt|| }	t|	dd	d
  dksDJ t|	ddid dksRJ d S )Nzp q rT)r*   freesource_formatzexp(p + (q + r))x y zFhuman   zexp(re(x) + re(y + z))rerealpartuser_functionsz"exp(realpart(x) + realpart(y + z)))r   r2   absr   r;   lstrip)
pqrq_rexprxyzy_zexpr2 rZ   X/var/www/visachat/venv/lib/python3.10/site-packages/sympy/printing/tests/test_fortran.pytest_UnevaluatedExpr#   s    r\   c                  C   s0   t d} G dd dt}t|| dksJ d S )NrU   c                   @   s   e Zd Zdd ZdS )ztest_printmethod.<locals>.nintc                 S   s   d| | jd  S )Nznint(%s)r   )_printargs)selfprinterrZ   rZ   r[   _fcode3   s   z%test_printmethod.<locals>.nint._fcodeN)__name__
__module____qualname__ra   rZ   rZ   rZ   r[   nint2   s    re   z      nint(x))r   r   r;   )rU   re   rZ   rZ   r[   test_printmethod/   s   rf   c                     s   t d t ddd} t ddd}tt ddd	d
ksJ tt| ddd	dks*J tt|ddd	dks7J tt fdd d S )NrU   rV   Tr/   rW   )complex_   rC   standardrE   z#merge(0d0, dsign(1d0, x), x == 0d0)zmerge(0, isign(1, y), y == 0)z/merge(cmplx(0d0, 0d0), z/abs(z), abs(z) == 0d0)c                      s   t t S N)r;   r   rZ   rU   rZ   r[   <lambda>?   s    z!test_fcode_sign.<locals>.<lambda>)r   r;   r   rB   NotImplementedError)rV   rW   rZ   rm   r[   test_fcode_sign8   s   rp   c                  C   s(  t d\} }t ddd}t| d dksJ t| |d  dks"J tdt| d	 | ||     | d
 |  dks<J tt| dksFJ tt|dksPJ t| d dksZJ tt| dksdJ ttddksnJ t| d dksxJ t| d ddddksJ t| tdd dksJ d S )Nx,ynTrg      z
      x**3z      x**(y**3)   g      @rI   z,      (3.5d0*sin(x))**(-x + y**x)/(x**2 + y)z      sqrt(x)z      sqrt(dble(n))g      ?
   z      sqrt(10.0d0)g      z      1d0/xg       rV   rC   rD   zy = x**(-2.0d0)   z      x**(3.0d0/7.0d0))r   r;   r   r   r   )rU   rV   rr   rZ   rZ   r[   test_fcode_PowB   s   *rw   c                  C   s   t d} ttdddksJ ttdddksJ ttddd	ks%J ttd
ddks0J t| tdd dks=J ttdd|  dksJJ d S )NrU   rs   rv   z      3.0d0/7.0d0   	   z      2iz      -3.0d0/7.0d0z      x + 3.0d0/7.0d0z      (3.0d0/7.0d0)*x)r   r;   r   rm   rZ   rZ   r[   test_fcode_RationalT   s   r{   c                   C   ,   t tddks
J t tddksJ d S )NC   z      67z      -1)r;   r   rZ   rZ   rZ   r[   test_fcode_Integer^      r   c                   C   r|   )Ng      E@z      42.0000000000000d0g@xz      -1.00000000000000d+20)r;   r   rZ   rZ   rZ   r[   test_fcode_Floatc   r   r   c                     s   t d\ tt t dksJ tt fdd tt fdd tt fdd tt fdd dD ]} tt | d	d
ksMJ t  | d	d
ksYJ q>d S )Nrq   z      sin(x)**cos(y)c                         t t ddS NB   rk   r;   r   rZ   rU   rV   rZ   r[   rn   k       z&test_fcode_functions.<locals>.<lambda>c                         t   ddS r   r;   rZ   r   rZ   r[   rn   l       c                      r   NM   r   r   rZ   r   rZ   r[   rn   m   r   c                      r   r   r   rZ   r   rZ   r[   rn   n   r   )Z   ri   i  i  r   z      modulo(x, y))r   r;   r   r   rB   ro   r   r   rZ   r   r[   test_fcode_functionsh   s   r   c                  C   s  t  } td\}}}}}}}tt|t||  t||  dks$J tt|d| | |tdd   dks;J tt|t||  t||  dddksSJ t|t| ddd	ksaJ | j|t| | d
ddksrJ | j|t| dddksJ | j|dddksJ tddd\}}	td}
td}td}t	d|	}t	d|}t|
||f ||  || dddksJ d S )Nzx,x_,x__,y,X,X_,Yz&      exp(x_) + sin(x*y) + cos(X__*Y_)rI   rv   z(      2*X_**(7.0d0/2.0d0)*Y*x + exp(x__)F)name_manglingz#      exp(x_) + sin(x*y) + cos(X*Y)z      x - cos(X)me	assign_toz      me = X*sin(x_) + x__muz      mu = X*sin(x_)adz      ad = x__n,mTrg   ArU   rV   ir   rC   r   rE   zndo i = 1, m
   y(i) = 0
end do
do i = 1, m
   do I_ = 1, n
      y(i) = A(i, I_)*x(I_) + y(i)
   end do
end do)
r<   r   r;   r   r   r   r   doprintr=   r>   )obrU   x_x__rV   XX_Yrr   mr   r   r   rZ   rZ   r[   	test_caset   s0   "$&"

 r   c                  C   s   t d} tdd}d}t| td d| ksJ t| td d| ks)J t| ttd d| ks9J tttdd| ksGJ ttddtdd ksXJ t| ttd d| kshJ t| tttd d| kszJ d S )NrU   ru      z0.8340324452479558d0z      x*%sd0z
      %sd0z
      x*%s)r   r   evalfr;   r   r   )rU   log10_17loglog10_17rZ   rZ   r[   "test_fcode_functions_with_integers   s    " (r   c                  C   s  d} t  }ttdt|  ksJ ttdt|  ksJ ttdt|  ks,J ttdt|  ks9J ttdt|  ksFJ ttdddtd ksUJ ttd	d
t|t| fht	 dfkslJ ttd	d
t|t| fht	 dfksJ ttd	d
t|t| fht	 dfksJ ttd	d
t|t| fht	 dfksJ ttd	d
t|t| fht	 dfksJ ttdd	dt|tdfht	 dfksJ d S )Nr   z.      parameter (Catalan = %sd0)
      Catalanz4      parameter (EulerGamma = %sd0)
      EulerGammaz"      parameter (E = %sd0)
      Ez6      parameter (GoldenRatio = %sd0)
      GoldenRatioz$      parameter (pi = %sd0)
      pi   )	precisionFrG   z      Catalanz      EulerGammaz      Ez      GoldenRatioz      pi)r   rH   )
r<   r;   r   r   r	   r   r
   r   r]   set)precrP   rZ   rZ   r[   test_fcode_NumberSymbol   sH   







r   c                  C   s   t tdksJ td} t dt dksJ t ddt  dks"J t ddt  |  dks0J t t|  dks:J t ddt  |  d	ksHJ tdd
d} t d|  dksXJ t t|  dksbJ t d|  dkslJ d S )Nz      cmplx(0,1)rU      z      cmplx(0,4)rs   z      cmplx(3,4)z      cmplx(3,4) + xz      cmplx(0,1)*xz      cmplx(3,4) - xT)	imaginaryr   z	      5*xz      x + 3)r;   r   r   rm   rZ   rZ   r[   test_fcode_complex   s   r   c                  C   sN   t d\} }tt| dksJ tt| |dksJ tt| dks%J d S )Nrq   z      sin(x)z      atan2(x, y)z      conjg(x))r   r;   r   r   r   r   rZ   rZ   r[   test_implicit   s   r   c                  C   s   t d} td}tt tt|  W d    n1 sw   Y  ttt| dddks0J tt t||  W d    d S 1 sFw   Y  d S )NrU   gF)strictzHC     Not supported in Fortran:
C     Integral
      Integral(sin(x), x))r   r   rB   ro   r;   r   r    r   )rU   r   rZ   rZ   r[   test_not_fortran   s   

"r   c                  C   s   t d} tt| ddiddksJ t d} tt| ddiddks$J td	}t|| d	d
iddks6J t ddd}tt|ddiddksJJ d S )NrU   r   zsinrL   z      zsin(x)r   mygammaz      mygamma(x)r   greatz      great(x)rr   Trg   r   fctz      fct(n))r   r;   r   r   r   r   )rU   r   rr   rZ   rZ   r[   test_user_functions   s    r   c                  C   s   t d} tdt| d|  }t|| dksJ tdt| dt |  }t|| dtd ks3J td}tdt d	d
d}tdt| | d|   d|   }t||| || ddks`J d S )NrU   r   rI   z	      2*xz(      parameter (pi = %sd0)
      2*pi/xr   r   r   rr   Trg   rt   r   zI      do i = 1, n
         A(i) = (A(i) + 1)*(A(i) + 2)*A(i)
      end do)r   rA   r   r;   r   r   r=   r>   )rU   r   r   r   rZ   rZ   r[   test_inline_function   s   

 r   c                  C   s$   t d} tt| dddksJ d S )NrU   sr   z      s = sin(x))r   r;   r   rm   rZ   rZ   r[   test_assign_to   s   r   c                     sZ   t d\ } t |  d  dddksJ  fddtdD }tt| d	ks+J d S )
Nrq   ru   varr   z      var = x**10 + 10*x**9*y + 45*x**8*y**2 + 120*x**7*y**3 + 210*x**6*
     @ y**4 + 252*x**5*y**5 + 210*x**4*y**6 + 120*x**3*y**7 + 45*x**2*y
     @ **8 + 10*x*y**9 + y**10c                    s   g | ]} | qS rZ   rZ   ).0r   rm   rZ   r[   
<listcomp>  s    z&test_line_wrapping.<locals>.<listcomp>   zR      x**10 + x**9 + x**8 + x**7 + x**6 + x**5 + x**4 + x**3 + x**2 + x
     @ + 1)r   r;   expandranger   )rV   erZ   rm   r[   test_line_wrapping   s   
r   c                  C   s   t d\} }tt| |k || d k dddksJ tt| |k || d k dddks,J tt| |k || d k ddddd	ksAJ tt| |k || d k ddd
ksTJ d S )Nx yrt   rC   rD   zx < y .and. y < x + 1zx < y .or. y < x + 1Fevaluatezx < y .neqv. y < x + 1zx < y .eqv. y < x + 1)r   r;   r4   r5   r8   r7   r   rZ   rZ   r[   test_fcode_precedence
  s   r   c                  C   st  t d\} }}tt| dddksJ tt| |dddks J tt| t|dddks/J ttt| |dddks>J ttt| t|dddksOJ ttt| |d	d
dddks`J tt| |dddksmJ tt| t|dddks|J ttt| |dddksJ ttt| t|dddksJ ttt| |d	d
dddksJ ttt||| dddksJ ttt|| |dddksJ ttt| ||dddksJ ttt||| dddksJ ttt|| |dddksJ ttt| ||dddksJ tt| ||dddksJ tt| |t|dddks.J tt| t||dddks?J ttt| ||dddksPJ ttt| ||d	d
dddkscJ tt| ||dddksrJ tt| |t|dddksJ tt| t||dddksJ ttt| ||dddksJ ttt| ||d	d
ddd ksJ d S )!NrF   rC   rD   z.not. xz	x .and. yzx .and. .not. yzy .and. .not. xz.not. x .and. .not. yFr   z.not. (x .and. y)zx .or. yzx .or. .not. yzy .or. .not. xz.not. x .or. .not. yz.not. (x .or. y)zx .and. (y .or. z)zy .and. (x .or. z)zz .and. (x .or. y)zx .or. y .and. zzy .or. x .and. zzz .or. x .and. yzx .and. y .and. zzx .and. y .and. .not. zzx .and. z .and. .not. yzy .and. z .and. .not. xz.not. (x .and. y .and. z)zx .or. y .or. zzx .or. y .or. .not. zzx .or. z .or. .not. yzy .or. z .or. .not. xz.not. (x .or. y .or. z))r   r;   r6   r4   r5   rU   rV   rW   rZ   rZ   r[   test_fcode_Logical  sh        "






r   c                  C   s(  t d\} }}tt| |dddddksJ tt| t|dddddks'J ttt| |dddddks8J ttt| t|ddddd	ksKJ ttt| |ddddddd
ks^J tt| |dddkskJ tt| t|dddkszJ ttt| |dddksJ ttt| t|dddksJ ttt| |dddddksJ ttt||| dddksJ ttt|| |dddksJ ttt| ||dddksJ ttt||| dddksJ ttt|| |dddksJ ttt| ||dddksJ ttt||| dddksJ ttt|| |dddks.J ttt| ||dddks?J ttt||| dddksPJ ttt|| |dddksaJ ttt| ||dddksrJ ttt||dd| dddksJ ttt|| dd|dddksJ ttt| |dd|dddksJ ttt||| dddddksJ ttt|| |ddddd ksJ ttt| ||ddddd!ksJ ttt||| ddddd"ksJ ttt|| |ddddd#ks
J ttt| ||ddddd$ksJ ttt||dd| ddd%ks0J ttt|| dd|ddd&ksCJ ttt| |dd|ddd'ksVJ ttt||| ddddd(ksiJ ttt|| |ddddd)ks|J ttt| ||ddddd*ksJ ttt||dd| ddd+ksJ ttt|| dd|ddd,ksJ ttt| |dd|ddd-ksJ tt| ||ddddd.ksJ tt| |t|ddddd/ksJ tt| t||ddddd0ksJ ttt| ||ddddd1ksJ d S )2NrF   Fr   rC   rD   z
x .neqv. yzx .neqv. .not. yzy .neqv. .not. xz.not. x .neqv. .not. yz.not. (x .neqv. y)z	x .eqv. yzx .eqv. .not. yzy .eqv. .not. xz.not. x .eqv. .not. yz.not. (x .eqv. y)zx .eqv. y .and. zzy .eqv. x .and. zzz .eqv. x .and. yzx .and. (y .eqv. z)zy .and. (x .eqv. z)zz .and. (x .eqv. y)zx .eqv. y .or. zzy .eqv. x .or. zzz .eqv. x .or. yzx .or. (y .eqv. z)zy .or. (x .eqv. z)zz .or. (x .eqv. y)zx .eqv. (y .neqv. z)zy .eqv. (x .neqv. z)zz .eqv. (x .neqv. y)zx .neqv. (y .eqv. z)zy .neqv. (x .eqv. z)zz .neqv. (x .eqv. y)zx .neqv. y .and. zzy .neqv. x .and. zzz .neqv. x .and. yzx .and. (y .neqv. z)zy .and. (x .neqv. z)zz .and. (x .neqv. y)zx .neqv. y .or. zzy .neqv. x .or. zzz .neqv. x .or. yzx .or. (y .neqv. z)zy .or. (x .neqv. z)zz .or. (x .neqv. y)zx .neqv. y .neqv. zzx .neqv. y .neqv. .not. zzx .neqv. z .neqv. .not. yzy .neqv. z .neqv. .not. x)r   r;   r8   r6   r7   r4   r5   r   rZ   rZ   r[   test_fcode_XlogicalG  s*  



























r   c                  C   s   t d\} }tt| |ddddksJ tt| |ddddks"J tt| |dddd	ks0J tt| |d
dddks>J tt| |ddddksLJ tt| |ddddksZJ d S )Nr   z==rC   rD   zx == yz!=zx /= yz>=zx >= yz<=zx <= y>zx > y<zx < y)r   r;   r3   r   rZ   rZ   r[   test_fcode_Relational  s    r   c                     sd  t d} t| | dk f| d df tt fdd t dd}d	}||ks(J tt| | dk f| d dfd
ddks=J t| |  }t| |  }tdD ]}t|| }t|| }qMd}tt|| dk f|dfdd}||ksqJ tt| | dk f| d | dkft| dfdd}d}||ksJ t| | dk f| d | dkft| | dkf tt	 fdd d S )NrU   rt   rI   Tc                         t  S rl   r   rZ   rT   rZ   r[   rn         z&test_fcode_Piecewise.<locals>.<lambda>ri   r   z      merge(x, x**2, x < 1)r   r   zR      if (x < 1) then
         var = x
      else
         var = x**2
      end ifru   a/        if (x < 0) then
         weird_name = -cos(x)/x + 10*sin(x)/x**2 + 90*cos(x)/x**3 - 720*
     @ sin(x)/x**4 - 5040*cos(x)/x**5 + 30240*sin(x)/x**6 + 151200*cos(x
     @ )/x**7 - 604800*sin(x)/x**8 - 1814400*cos(x)/x**9 + 3628800*sin(x
     @ )/x**10 + 3628800*cos(x)/x**11
      else
         weird_name = -sin(x)/x - 10*cos(x)/x**2 + 90*sin(x)/x**3 + 720*
     @ cos(x)/x**4 - 5040*sin(x)/x**5 - 30240*cos(x)/x**6 + 151200*sin(x
     @ )/x**7 + 604800*cos(x)/x**8 - 1814400*sin(x)/x**9 - 3628800*cos(x
     @ )/x**10 + 3628800*sin(x)/x**11
      end ifr   
weird_namez1      merge(x, merge(x**2, sin(x), x > 1), x < 1)c                      r   rl   r   rZ   r   rZ   r[   rn     r   )
r   r   rB   ro   r;   r   r   r   r   
ValueError)rU   codeexpectedabr   rZ   r   r[   test_fcode_Piecewise  s.    
0,r   c                  C   sr   t  } g d}| |}g d}|D ]
}t|dksJ qt||D ]
\}}||ks,J q"t|t|ks7J d S )N)zbC     This is a long comment on a single line that must be wrapped properly to produce nice outputzf      this = is + a + long + and + nasty + fortran + statement + that * must + be + wrapped + properlyzg      this = is + a + long + and + nasty + fortran + statement +  that * must + be + wrapped + properlyzh      this = is + a + long + and + nasty + fortran + statement +   that * must + be + wrapped + properlyzd      this = is + a + long + and + nasty + fortran + statement + that*must + be + wrapped + properlyzf      this = is + a + long + and + nasty + fortran + statement +   that*must + be + wrapped + properlyzg      this = is + a + long + and + nasty + fortran + statement +    that*must + be + wrapped + properlyzh      this = is + a + long + and + nasty + fortran + statement +     that*must + be + wrapped + properlyze      this = is + a + long + and + nasty + fortran + statement + that**must + be + wrapped + properlyzf      this = is + a + long + and + nasty + fortran + statement +  that**must + be + wrapped + properlyzg      this = is + a + long + and + nasty + fortran + statement +   that**must + be + wrapped + properlyzh      this = is + a + long + and + nasty + fortran + statement +    that**must + be + wrapped + properlyzi      this = is + a + long + and + nasty + fortran + statement +     that**must + be + wrapped + properlyzc      this = is + a + long + and + nasty + fortran + statement(that)/must + be + wrapped + properlyzg      this = is + a + long + and + nasty + fortran +     statement(that)/must + be + wrapped + properly)zBC     This is a long comment on a single line that must be wrappedz%C     properly to produce nice outputzG      this = is + a + long + and + nasty + fortran + statement + that *%     @ must + be + wrapped + properlyzH      this = is + a + long + and + nasty + fortran + statement +  that *r   G      this = is + a + long + and + nasty + fortran + statement +   thatz'     @ * must + be + wrapped + properlyzF      this = is + a + long + and + nasty + fortran + statement + that*r   zH      this = is + a + long + and + nasty + fortran + statement +   that*r   H      this = is + a + long + and + nasty + fortran + statement +    thatz&     @ *must + be + wrapped + properly@      this = is + a + long + and + nasty + fortran + statement +z*     @ that*must + be + wrapped + properlyzG      this = is + a + long + and + nasty + fortran + statement + that**r   zH      this = is + a + long + and + nasty + fortran + statement +  that**r   r   '     @ **must + be + wrapped + properlyr   r   r   z+     @ that**must + be + wrapped + properlyzE      this = is + a + long + and + nasty + fortran + statement(that)/r   zH      this = is + a + long + and + nasty + fortran +     statement(that)z&     @ /must + be + wrapped + properlyH   )r<   _wrap_fortranlenzip)r`   lineswrapped_linesexpected_lineslinewr   rZ   rZ   r[   test_wrap_fortran  s   
 r   c                  C   s,   t  } g d}g d}| ||ksJ d S )N)H      this_variable_is_very_long_because_we_try_to_test_line_break=1.0d0zI      this_variable_is_very_long_because_we_try_to_test_line_break =1.0d0zK      this_variable_is_very_long_because_we_try_to_test_line_break  = 1.0d0zL      this_variable_is_very_long_because_we_try_to_test_line_break   = 1.0d0zM      this_variable_is_very_long_because_we_try_to_test_line_break    = 1.0d0zK      this_variable_is_very_long_because_we_try_to_test_line_break = 10.0d0)r   D      this_variable_is_very_long_because_we_try_to_test_line_break =     @ 1.0d0zE      this_variable_is_very_long_because_we_try_to_test_line_break  =r   zF      this_variable_is_very_long_because_we_try_to_test_line_break   =r   zG      this_variable_is_very_long_because_we_try_to_test_line_break    =r   r   z     @ 10.0d0r<   r   r`   r   r   rZ   rZ   r[   test_wrap_fortran_keep_d0  s   r   c                   C   s   t tdd  d S )Nc                   S   s   t tdddS )Nr   garbage)method)r;   r   rZ   rZ   rZ   r[   rn   6  r   ztest_settings.<locals>.<lambda>)rB   	TypeErrorrZ   rZ   rZ   r[   test_settings5  s   r   c                  C   s0   t d\} }tt| t| dddksJ d S )Nrq   rC   rD   zsin(y) + cos(x))r   r;   r   r   r   rZ   rZ   r[   test_free_form_code_line9  s   $r   c                  C   s@   t d\} }tt| t| d  dd}d}||ksJ d S )Nrq   rv   rC   rD   zsin(y)**7 + 7*sin(y)**6*cos(x) + 21*sin(y)**5*cos(x)**2 + 35*sin(y)**4* &
      cos(x)**3 + 35*sin(y)**3*cos(x)**4 + 21*sin(y)**2*cos(x)**5 + 7* &
      sin(y)*cos(x)**6 + cos(x)**7)r   r;   r   r   r   )rU   rV   resultr   rZ   rZ   r[    test_free_form_continuation_line>  s
    r   c                  C   s0   t ddi} dg}ddg}| ||ksJ d S )NrE   rC   z^! This is a long comment on a single line that must be wrapped properly to produce nice outputzG! This is a long comment on a single line that must be wrapped properlyz! to produce nice outputr   r   rZ   rZ   r[   test_free_form_comment_lineI  s   r   c            	      C   s   t ddd\} }td}td}td}td|}td| }d	}t|||f ||  || d
d}||ddi ksS||ddi ksU||ddi ksW||ddi ksYJ d S d S d S d S )Nr   Trg   r   rU   rV   r   jz_do i = 1, m
   y(i) = 0
end do
do i = 1, m
   do j = 1, n
      y(i) = %(rhs)s
   end do
end dorC   r   rhszy(i) + A(i, j)*x(j)zy(i) + x(j)*A(i, j)zx(j)*A(i, j) + y(i)zA(i, j)*x(j) + y(i))r   r=   r>   r;   )	rr   r   r   rU   rV   r   r   r   r   rZ   rZ   r[   
test_loopsR  s"   

"r   c                  C   sf   t ddtd\} }td}td}t| |} d| jj|jd }t||  ||  dd	}||ks1J d S )
Nzi mT)r/   clsrU   rV   zMdo i_%(icount)i = 1, m_%(mcount)i
   y(i_%(icount)i) = x(i_%(icount)i)
end do)icountmcountrC   r   )r   r   r=   r>   labeldummy_indexr;   )r   r   rU   rV   r   r   rZ   rZ   r[   test_dummy_loopsl  s   
r   c                  C   s   d} t d| fd}t d| fd}t d| d fd}td| d }t|| ||d  ||  ||d  ||   }t|j|jdd	}|d
sIJ d S )Nr   rV   shaperU   Dyrt   r   F)r   contract+Dy(i) = (y(i + 1) - y(i))/(x(i + 1) - x(i)))r=   r>   r   r;   r   lhsendswithlen_yrV   rU   r   r   r   code0rZ   rZ   r[   2test_fcode_Indexed_without_looking_for_contraction{  s   2r  c                     s  d} t d| fd}t d| fd}t d| d fd}td| d }t|| ||d  ||  ||d  ||   }tt|j|j}|dsIJ G d	d
 d
tt	 |
 fdd|tD }t|| ||d  ||  ||d  ||   }tt|j|j}|dsJ d S )Nr   rV   r   rU   r   rt   r   r  c                   @   s   e Zd ZdS )z.test_element_like_objects.<locals>.ElementExprN)rb   rc   rd   rZ   rZ   rZ   r[   ElementExpr  s    r	  c                 3   s"    | ]}| |j |jfV  qd S rl   )nameindices)r   r   r	  rZ   r[   	<genexpr>  s     z,test_element_like_objects.<locals>.<genexpr>)r?   r>   r   r;   r#   r  r   r  r1   r   subsatomsr@   r  rZ   r  r[   test_element_like_objects  s   22r  c                  C   s:   G dd dt } |  }td}|t|ddksJ d S )Nc                   @   s   e Zd Zej ZdS )z1test_derived_classes.<locals>.MyFancyFCodePrinterN)rb   rc   rd   r<   _default_settingscopyrZ   rZ   rZ   r[   MyFancyFCodePrinter  s    r  rU   borkz      bork = sin(x))r<   r   r   r   )r  r`   rU   rZ   rZ   r[   test_derived_classes  s   r  c                  C   s.   d} d}t ddi}|| }||ksJ d S )Nau  subroutine test(a)
integer :: a, i, j

do
do 
do j = 1, 5
if (a>b) then
if(b>0) then
a = 3
donot_indent_me = 2
do_not_indent_me_either = 2
ifIam_indented_something_went_wrong = 2
if_I_am_indented_something_went_wrong = 2
end should not be unindented here
end if
endif
end do
end do
enddo
end subroutine

subroutine test2(a)
integer :: a
do
a = a + 1
end do 
end subroutine
a  subroutine test(a)
integer :: a, i, j

do
   do 
      do j = 1, 5
         if (a>b) then
            if(b>0) then
               a = 3
               donot_indent_me = 2
               do_not_indent_me_either = 2
               ifIam_indented_something_went_wrong = 2
               if_I_am_indented_something_went_wrong = 2
               end should not be unindented here
            end if
         endif
      end do
   end do
enddo
end subroutine

subroutine test2(a)
integer :: a
do
   a = a + 1
end do 
end subroutine
rE   rC   )r<   indent_code)	codelinesr   rP   r   rZ   rZ   r[   test_indent  s   
r  c            	      C   s,  t d\} }}t| | td|  |dkf|dft|g}tddd}t||dks,J td|d	  | dkf|d	 dft|d
  |d  }t|dddksQJ tddd}tddd}tt|d
 dt|d	 g|d
 |d	  |d dgd|d  |d
  t|d d dgg}t||dksJ d S )Nzx,y,zrI   r   Tr   rs   rt   z      A(1, 1) = x*y
      if (y > 0) then
         A(2, 1) = x + 2
      else
         A(2, 1) = y
      end if
      A(3, 1) = sin(z))rI   r   )rt   r   r   r   ri   r   z?      merge(2*A(3, 1), A(3, 1), x > 0) + sin(A(2, 1)) + A(1, 1)rQ   r   M)rs   r   )r   r   r   z      M(1, 1) = sin(q(2, 1))
      M(2, 1) = q(2, 1) + q(3, 1)
      M(3, 1) = 2*q(5, 1)/q(2, 1)
      M(1, 2) = 0
      M(2, 2) = q(4, 1)
      M(3, 2) = sqrt(q(1, 1)) + 4
      M(1, 3) = cos(q(3, 1))
      M(2, 3) = 5
      M(3, 3) = 0)r   r9   r   r   r:   r;   r   r   )	rU   rV   rW   matr   rT   rQ   r  r   rZ   rZ   r[   test_Matrix_printing  s&   ,6	
$r  c                  C   sD   t d\} }t| tdddt|| | g}t|}|dks J d S )Nr   r   ru   rI   z2      do x = 0, 9, 2
         y = x*y
      end do)r   r"   r!   r#   r;   )rU   rV   fsolrZ   rZ   r[   test_fcode_For  s    r  c            
      C   s   dd } t ddd}t|}t|}| |d t d\}}t|tdthd	}t|}| |d
 t|td}t|}	| |	d | td | td | tdttid | tdttid d S )Nc                 [   s"   t | fddd||ksJ d S )Nri   rC   rj   r   )rT   refkwargsrZ   rZ   r[   check  s   "z%test_fcode_Declaration.<locals>.checkr   Trg   zinteger*4 :: ir   *   )valueattrszreal*4, parameter :: x = 42typezlogical :: yzreal*4zreal*8)type_aliases)	r   r&   deducedr%   r'   r)   r+   r(   r*   )
r"  r   var1dcl1rU   rV   var2dcl2bvar3dcl3rZ   rZ   r[   test_fcode_Declaration  s    





r0  c                  C   sx   t ddd} t ddd}t ddd}t| d dksJ td| d  dks(J |d || | }t|d	ks:J d S )
Nr   rt   rs   BCr  z      A(1, 1)z      3*A(1, 1)z      (A - B)(1, 1))r:   r;   r  )r   r1  r2  FrZ   rZ   r[   test_MatrixElement_printing'  s   r4  c                  C   s(   t d} tt| dddddksJ d S )NrU   +rt   rC   rD   z	x = x + 1)r   r;   r$   rm   rZ   rZ   r[   test_aug_assign4  s    r6  c                  C   s8   t d} ttt| dkt| ddgdddksJ d S )NrU   rt   -rC   rD   z)do while (abs(x) > 1)
   x = x - 1
end do)r   r;   r,   rN   r$   rm   rZ   rZ   r[   
test_While9  s   "r8  c                     sR   t d} t ddd}t| td}t|td}ttd||g tt fdd d S )	NrU   rr   Trg   r&  powerc                      r   rl   r   rZ   fp1rZ   r[   rn   J  r   z.test_FunctionPrototype_print.<locals>.<lambda>)r   r&   r*   r/   r-   rB   ro   )rU   rr   vxvnrZ   r:  r[   test_FunctionPrototype_printB  s   r>  c                     sj   t d} t ddd}t| td}t|td}t| | | t| g}ttd||g| tt fdd d S )	NrU   rr   Trg   r&  r9  c                      r   rl   r   rZ   fd1rZ   r[   rn   V  r   z/test_FunctionDefinition_print.<locals>.<lambda>)	r   r&   r*   r/   r#   r0   r.   rB   ro   )rU   rr   r<  r=  bodyrZ   r?  r[   test_FunctionDefinition_printM  s   rB  N)sympy.core.addr   sympy.core.exprr   sympy.core.functionr   r   r   sympy.core.modr   
sympy.corer   r	   r
   sympy.core.numbersr   r   r   r   r   r   sympy.core.relationalr   sympy.core.singletonr   sympy.core.symbolr   r   (sympy.functions.combinatorial.factorialsr   $sympy.functions.elementary.complexesr   r   &sympy.functions.elementary.exponentialr   r   (sympy.functions.elementary.miscellaneousr   $sympy.functions.elementary.piecewiser   (sympy.functions.elementary.trigonometricr   r   r   'sympy.functions.special.gamma_functionsr   sympy.integrals.integralsr    sympy.sets.fancysetsr!   sympy.codegenr"   r#   r$   sympy.codegen.astr%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   sympy.logic.boolalgr4   r5   r6   r7   r8   sympy.matricesr9   r:   sympy.printing.fortranr;   r<   sympy.tensorr=   r>   sympy.tensor.array.expressionsr?   r@   sympy.utilities.lambdifyrA   sympy.testing.pytestrB   r\   rf   rp   rw   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  r0  r4  r6  r8  r>  rB  rZ   rZ   rZ   r[   <module>   s     <	


1c
+<		?#
	