o
    GZh                     @   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))reZrealpartZuser_functionsz"exp(realpart(x) + realpart(y + z)))r   r2   absr   r;   lstrip)
pqrZq_rexprxyzZy_zZexpr2 rU   P/var/www/auris/lib/python3.10/site-packages/sympy/printing/tests/test_fortran.pytest_UnevaluatedExpr#   s    rW   c                  C   s0   t d} G dd dt}t|| dksJ d S )NrR   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printerrU   rU   rV   _fcode3   s   z%test_printmethod.<locals>.nint._fcodeN)__name__
__module____qualname__r\   rU   rU   rU   rV   nint2   s    r`   z      nint(x))r   r   r;   )rR   r`   rU   rU   rV   test_printmethod/   s   ra   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 )NrR   rS   Tr/   rT   )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   rU   rR   rU   rV   <lambda>?   s    z!test_fcode_sign.<locals>.<lambda>)r   r;   r   rB   NotImplementedError)rS   rT   rU   rh   rV   test_fcode_sign8   s   rk   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nTrb      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       rS   rC   rD   zy = x**(-2.0d0)   z      x**(3.0d0/7.0d0))r   r;   r   r   r   )rR   rS   rm   rU   rU   rV   test_fcode_PowB   s   *rr   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 )NrR   rn   rq   z      3.0d0/7.0d0   	   z      2iz      -3.0d0/7.0d0z      x + 3.0d0/7.0d0z      (3.0d0/7.0d0)*x)r   r;   r   rh   rU   rU   rV   test_fcode_RationalT   s   rv   c                   C   ,   t tddks
J t tddksJ d S )NC   z      67z      -1)r;   r   rU   rU   rU   rV   test_fcode_Integer^      rz   c                   C   rw   )Ng      E@z      42.0000000000000d0g@xz      -1.00000000000000d+20)r;   r   rU   rU   rU   rV   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 )Nrl   z      sin(x)**cos(y)c                         t t ddS NB   rf   r;   r   rU   rR   rS   rU   rV   ri   k       z&test_fcode_functions.<locals>.<lambda>c                         t   ddS r~   r;   rU   r   rU   rV   ri   l       c                      r}   NM   r   r   rU   r   rU   rV   ri   m   r   c                      r   r   r   rU   r   rU   rV   ri   n   r   )Z   rd   i  i  r   z      modulo(x, y))r   r;   r   r   rB   rj   r   r   rU   r   rV   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   rq   z(      2*X_**(7.0d0/2.0d0)*Y*x + exp(x__)F)Z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,mTrb   ArR   rS   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>   )obrR   Zx_Zx__rS   XZX_Yrm   mr   r   r   rU   rU   rV   	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 )NrR   rp      z0.8340324452479558d0z      x*%sd0z
      %sd0z
      x*%s)r   r   evalfr;   r   r   )rR   Zlog10_17Zloglog10_17rU   rU   rV   "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   rX   set)precrN   rU   rU   rV   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)rR      z      cmplx(0,4)rn   z      cmplx(3,4)z      cmplx(3,4) + xz      cmplx(0,1)*xz      cmplx(3,4) - xT)Z	imaginaryr   z	      5*xz      x + 3)r;   r   r   rh   rU   rU   rV   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 )Nrl   z      sin(x)z      atan2(x, y)z      conjg(x))r   r;   r   r   r   r   rU   rU   rV   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 )NrR   gF)strictzHC     Not supported in Fortran:
C     Integral
      Integral(sin(x), x))r   r   rB   rj   r;   r   r    r   )rR   r   rU   rU   rV   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 )NrR   r   ZzsinrK   z      zsin(x)r   Zmygammaz      mygamma(x)r   Zgreatz      great(x)rm   Trb   r   Zfctz      fct(n))r   r;   r   r   r   r   )rR   r   rm   rU   rU   rV   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 )NrR   r   rI   z	      2*xz(      parameter (pi = %sd0)
      2*pi/xr   r   r   rm   Trb   ro   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>   )rR   r   r   r   rU   rU   rV   test_inline_function   s   

 r   c                  C   s$   t d} tt| dddksJ d S )NrR   sr   z      s = sin(x))r   r;   r   rh   rU   rU   rV   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 )
Nrl   rp   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 rU   rU   ).0r   rh   rU   rV   
<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   )rS   erU   rh   rV   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 yro   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   rU   rU   rV   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   rR   rS   rT   rU   rU   rV   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   rU   rU   rV   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   rU   rU   rV   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 )NrR   ro   rI   Tc                         t  S rg   r   rU   rQ   rU   rV   ri         z&test_fcode_Piecewise.<locals>.<lambda>rd   r   z      merge(x, x**2, x < 1)r   r   zR      if (x < 1) then
         var = x
      else
         var = x**2
      end ifrp   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   Z
weird_namez1      merge(x, merge(x**2, sin(x), x > 1), x < 1)c                      r   rg   r   rU   r   rU   rV   ri     r   )
r   r   rB   rj   r;   r   r   r   r   
ValueError)rR   codeexpectedabr   rU   r   rV   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_linesZexpected_lineslinewr   rU   rU   rV   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   rU   rU   rV   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   rU   rU   rU   rV   ri   6  r   ztest_settings.<locals>.<lambda>)rB   	TypeErrorrU   rU   rU   rV   test_settings5  s   r   c                  C   s0   t d\} }tt| t| dddksJ d S )Nrl   rC   rD   zsin(y) + cos(x))r   r;   r   r   r   rU   rU   rV   test_free_form_code_line9  s   $r   c                  C   s@   t d\} }tt| t| d  dd}d}||ksJ d S )Nrl   rq   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   )rR   rS   resultr   rU   rU   rV    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   rU   rU   rV   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   Trb   r   rR   rS   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;   )	rm   r   r   rR   rS   r   r   r   r   rU   rU   rV   
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/   clsrR   rS   zMdo i_%(icount)i = 1, m_%(mcount)i
   y(i_%(icount)i) = x(i_%(icount)i)
end do)ZicountZmcountrC   r   )r   r   r=   r>   labelZdummy_indexr;   )r   r   rR   rS   r   r   rU   rU   rV   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   rS   shaperR   Dyro   r   F)r   Zcontract+Dy(i) = (y(i + 1) - y(i))/(x(i + 1) - x(i)))r=   r>   r   r;   r   lhsendswithZlen_yrS   rR   r   r   r   Zcode0rU   rU   rV   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   rS   r   rR   r   ro   r   r   c                   @   s   e Zd ZdS )z.test_element_like_objects.<locals>.ElementExprN)r]   r^   r_   rU   rU   rU   rV   ElementExpr  s    r   c                 3   s"    | ]}| |j |jfV  qd S rg   )nameindices)r   r   r   rU   rV   	<genexpr>  s     z,test_element_like_objects.<locals>.<genexpr>)r?   r>   r   r;   r#   r   r   r   r1   r   subsZatomsr@   r   rU   r   rV   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)r]   r^   r_   r<   Z_default_settingscopyrU   rU   rU   rV   MyFancyFCodePrinter  s    r   rR   Zborkz      bork = sin(x))r<   r   r   r   )r   r[   rR   rU   rU   rV   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<   Zindent_code)Z	codelinesr   rN   r   rU   rU   rV   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   rn   ro   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   )ro   r   r   r   rd   r   z?      merge(2*A(3, 1), A(3, 1), x > 0) + sin(A(2, 1)) + A(1, 1)rO   r   M)rn   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   )	rR   rS   rT   matr   rQ   rO   r   r   rU   rU   rV   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   rp   rI   z2      do x = 0, 9, 2
         y = x*y
      end do)r   r"   r!   r#   r;   )rR   rS   fZsolrU   rU   rV   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 )Nrd   rC   re   r   )rQ   refkwargsrU   rU   rV   check  s   "z%test_fcode_Declaration.<locals>.checkr   Trb   zinteger*4 :: ir   *   )valueattrszreal*4, parameter :: x = 42typezlogical :: yzreal*4zreal*8)Ztype_aliases)	r   r&   Zdeducedr%   r'   r)   r+   r(   r*   )
r  r   Zvar1Zdcl1rR   rS   Zvar2Zdcl2bZvar3Zdcl3rU   rU   rV   test_fcode_Declaration  s    





r
  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   ro   rn   BCr   z      A(1, 1)z      3*A(1, 1)z      (A - B)(1, 1))r:   r;   r   )r   r  r  FrU   rU   rV   test_MatrixElement_printing'  s   r  c                  C   s(   t d} tt| dddddksJ d S )NrR   +ro   rC   rD   z	x = x + 1)r   r;   r$   rh   rU   rU   rV   test_aug_assign4  s    r  c                  C   s8   t d} ttt| dkt| ddgdddksJ d S )NrR   ro   -rC   rD   z)do while (abs(x) > 1)
   x = x - 1
end do)r   r;   r,   rL   r$   rh   rU   rU   rV   
test_While9  s   "r  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 )	NrR   rm   Trb   r  powerc                      r   rg   r   rU   fp1rU   rV   ri   J  r   z.test_FunctionPrototype_print.<locals>.<lambda>)r   r&   r*   r/   r-   rB   rj   )rR   rm   vxvnrU   r  rV   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 )	NrR   rm   Trb   r  r  c                      r   rg   r   rU   Zfd1rU   rV   ri   V  r   z/test_FunctionDefinition_print.<locals>.<lambda>)	r   r&   r*   r/   r#   r0   r.   rB   rj   )rR   rm   r  r  bodyrU   r  rV   test_FunctionDefinition_printM  s   r  N)Zsympy.core.addr   Zsympy.core.exprr   Zsympy.core.functionr   r   r   Zsympy.core.modr   Z
sympy.corer   r	   r
   Zsympy.core.numbersr   r   r   r   r   r   Zsympy.core.relationalr   Zsympy.core.singletonr   Zsympy.core.symbolr   r   Z(sympy.functions.combinatorial.factorialsr   Z$sympy.functions.elementary.complexesr   r   Z&sympy.functions.elementary.exponentialr   r   Z(sympy.functions.elementary.miscellaneousr   Z$sympy.functions.elementary.piecewiser   Z(sympy.functions.elementary.trigonometricr   r   r   Z'sympy.functions.special.gamma_functionsr   Zsympy.integrals.integralsr    Zsympy.sets.fancysetsr!   Zsympy.codegenr"   r#   r$   Zsympy.codegen.astr%   r&   r'   r(   r)   r*   r+   r,   r-   r.   r/   r0   r1   r2   r3   Zsympy.logic.boolalgr4   r5   r6   r7   r8   Zsympy.matricesr9   r:   Zsympy.printing.fortranr;   r<   Zsympy.tensorr=   r>   Zsympy.tensor.array.expressionsr?   r@   Zsympy.utilities.lambdifyrA   Zsympy.testing.pytestrB   rW   ra   rk   rr   rv   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  r  rU   rU   rU   rV   <module>   s     <	


1c
+<		?#
	