U
    	-e                     @   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sBtt d\}}}t|| }tt|| }	t|	dd	d
  dkstt|	ddid dkst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;   AssertionErrorlstrip)
pqrZq_rexprxyzZy_zZexpr2 rV   b/var/www/html/Darija-Ai-Train/env/lib/python3.8/site-packages/sympy/printing/tests/test_fortran.pytest_UnevaluatedExpr#   s    rX   c                  C   s0   t d} G dd dt}t|| dks,td S )NrS   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printerrV   rV   rW   _fcode3   s    z%test_printmethod.<locals>.nint._fcodeN)__name__
__module____qualname__r]   rV   rV   rV   rW   nint2   s   ra   z      nint(x))r   r   r;   rM   )rS   ra   rV   rV   rW   test_printmethod/   s    rb   c                     s   t d t ddd} t ddd}tt ddd	d
ks:ttt| ddd	dksTttt|ddd	dksnttt fdd d S )NrS   rT   Tr/   rU   )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   rV   rS   rV   rW   <lambda>?       z!test_fcode_sign.<locals>.<lambda>)r   r;   r   rM   rB   NotImplementedError)rT   rU   rV   ri   rW   test_fcode_sign8   s    rm   c                  C   s,  t d\} }t ddd}t| d dks,tt| |d  dksDttdt| d	 | ||     | d
 |  dksxttt| dksttt|dkstt| d dksttt| dkstttddkstt| d dkstt| d ddddkstt| tdd dks(td S )Nx,ynTrc      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       rT   rC   rD   zy = x**(-2.0d0)   z      x**(3.0d0/7.0d0))r   r;   rM   r   r   r   )rS   rT   ro   rV   rV   rW   test_fcode_PowB   s    *rt   c                  C   s   t d} ttdddkstttdddks4tttddd	ksJtttd
ddks`tt| tdd dksztttdd|  dkstd S )NrS   rp   rs   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   ri   rV   rV   rW   test_fcode_RationalT   s    rx   c                   C   s,   t tddkstt tddks(td S )NC   z      67z      -1)r;   r   rM   rV   rV   rV   rW   test_fcode_Integer^   s    r{   c                   C   s,   t tddkstt tddks(td S )Ng      E@z      42.0000000000000d0g@xz      -1.00000000000000d+20)r;   r   rM   rV   rV   rV   rW   test_fcode_Floatc   s    r|   c                     s   t d\ tt t dks(ttt fdd tt fdd tt fdd tt fdd dD ]6} tt | d	d
kstt  | d	d
ks|tq|d S )Nrn   z      sin(x)**cos(y)c                      s   t t ddS NB   rg   r;   r   rV   rS   rT   rV   rW   rj   k   rk   z&test_fcode_functions.<locals>.<lambda>c                      s   t   ddS r}   r;   rV   r   rV   rW   rj   l   rk   c                      s   t t ddS NM   r   r   rV   r   rV   rW   rj   m   rk   c                      s   t   ddS r   r   rV   r   rV   rW   rj   n   rk   )Z   re   i  i  r   z      modulo(x, y))r   r;   r   r   rM   rB   rl   r   r   rV   r   rW   test_fcode_functionsh   s    r   c                  C   s  t  } td\}}}}}}}tt|t||  t||  dksHttt|d| | |tdd   dksvttt|t||  t||  dddkstt|t| ddd	kst| j|t| | d
ddkst| j|t| dddkst| j|dddksttddd\}}	t	d}
t	d}t	d}t
d|	}t
d|}t|
||f ||  || dddkstd S )Nzx,x_,x__,y,X,X_,Yz&      exp(x_) + sin(x*y) + cos(X__*Y_)rI   rs   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,mTrc   ArS   rT   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   rM   r   doprintr=   r>   )obrS   Zx_Zx__rT   XZX_Yro   mr   r   r   rV   rV   rW   	test_caset   s0    "$&" 

 r   c                  C   s   t d} tdd}d}t| td d| ks6tt| td d| ksRtt| ttd d| ksrttttdd| kstttddtdd kstt| ttd d| kstt| tttd d| kstd S )NrS   rr      z0.8340324452479558d0z      x*%sd0z
      %sd0z
      x*%s)r   r   evalfr;   rM   r   r   )rS   Zlog10_17Zloglog10_17rV   rV   rW   "test_fcode_functions_with_integers   s     " r   c                  C   s  d} t  }ttdt|  ks$tttdt|  ks>tttdt|  ksXtttdt|  ksrtttdt|  kstttdddtd kstttd	d
t|	t| fht
 dfkstttd	d
t|	t| fht
 dfkstttd	d
t|	t| fht
 dfks8tttd	d
t|	t| fht
 dfkshtttd	d
t|	t| fht
 dfkstttdd	dt|	tdfht
 dfkst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   rM   r	   r   r
   r   rY   set)precrO   rV   rV   rW   test_fcode_NumberSymbol   s\     
 
 
   
    r   c                  C   s   t tdksttd} t dt dks,tt ddt  dksDtt ddt  |  dks`tt t|  dksttt ddt  |  d	ksttdd
d} t d|  dkstt t|  dkstt d|  dkstd S )Nz      cmplx(0,1)rS      z      cmplx(0,4)rp   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   rM   r   ri   rV   rV   rW   test_fcode_complex   s    r   c                  C   sN   t d\} }tt| dks ttt| |dks6ttt| dksJtd S )Nrn   z      sin(x)z      atan2(x, y)z      conjg(x))r   r;   r   rM   r   r   r   rV   rV   rW   test_implicit   s    r   c                  C   sX   t d} td}tt| }|dks(tttt| dks@tt|| dksTtd S )NrS   gz:C     Not supported in Fortran:
C     gamma
      gamma(x)zHC     Not supported in Fortran:
C     Integral
      Integral(sin(x), x)z2C     Not supported in Fortran:
C     g
      g(x))r   r   r;   r   rM   r    r   )rS   r   Zgamma_frV   rV   rW   test_not_fortran   s    r   c                  C   s   t d} tt| ddiddks$tt d} tt| ddiddksHttd	}t|| d	d
iddksltt ddd}tt|ddiddkstd S )NrS   r   ZzsinrK   z      zsin(x)r   Zmygammaz      mygamma(x)r   Zgreatz      great(x)ro   Trc   r   Zfctz      fct(n))r   r;   r   rM   r   r   r   )rS   r   ro   rV   rV   rW   test_user_functions   s$      r   c                  C   s   t d} tdt| d|  }t|| dks0ttdt| dt |  }t|| dtd ksfttd}tdt d	d
d}tdt| | d|   d|   }t||| || ddkstd S )NrS   r   rI   z	      2*xz(      parameter (pi = %sd0)
      2*pi/xr   r   r   ro   Trc   rq   r   zI      do i = 1, n
         A(i) = (A(i) + 1)*(A(i) + 2)*A(i)
      end do)	r   rA   r   r;   rM   r   r   r=   r>   )rS   r   r   r   rV   rV   rW   test_inline_function   s    

 r   c                  C   s$   t d} tt| dddks td S )NrS   sr   z      s = sin(x))r   r;   r   rM   ri   rV   rV   rW   test_assign_to   s    r   c                     sZ   t d\ } t |  d  dddks,t fddtdD }tt| d	ksVtd S )
Nrn   rr   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 rV   rV   ).0r   ri   rV   rW   
<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;   expandrM   ranger   )rT   erV   ri   rW   test_line_wrapping   s    
r   c                  C   s   t d\} }tt| |k || d k dddks2ttt| |k || d k dddksXttt| |k || d k ddddd	ksttt| |k || d k ddd
kstd S )Nx yrq   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   rM   r5   r8   r7   r   rV   rV   rW   test_fcode_precedence	  s    r   c                  C   s  t d\} }}tt| dddks&ttt| |dddks@ttt| t|dddks^tttt| |dddks|tttt| t|dddkstttt| |d	d
dddksttt| |dddksttt| t|dddkstttt| |dddkstttt| t|dddks<tttt| |d	d
dddks`tttt||| dddkstttt|| |dddkstttt| ||dddkstttt||| dddkstttt|| |dddks
tttt| ||dddks,ttt| ||dddksJttt| |t|dddkslttt| t||dddkstttt| ||dddkstttt| ||d	d
dddksttt| ||dddksttt| |t|dddksttt| t||dddks8tttt| ||dddksZtttt| ||d	d
ddd kst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   rM   r4   r5   rS   rT   rU   rV   rV   rW   test_fcode_Logical  sh     

""""""






r   c                  C   s8  t d\} }}tt| |dddddks,ttt| t|dddddksNtttt| |dddddksptttt| t|ddddd	kstttt| |ddddddd
ksttt| |dddksttt| t|dddkstttt| |dddkstttt| t|dddks8tttt| |dddddks\tttt||| dddks~tttt|| |dddkstttt| ||dddkstttt||| dddkstttt|| |dddkstttt| ||dddks(tttt||| dddksJtttt|| |dddksltttt| ||dddkstttt||| dddkstttt|| |dddkstttt| ||dddkstttt||dd| dddkstttt|| dd|dddks@tttt| |dd|dddksftttt||| dddddkstttt|| |ddddd kstttt| ||ddddd!kstttt||| ddddd"kstttt|| |ddddd#ks$tttt| ||ddddd$ksJtttt||dd| ddd%ksptttt|| dd|ddd&kstttt| |dd|ddd'kstttt||| ddddd(kstttt|| |ddddd)kstttt| ||ddddd*ks.tttt||dd| ddd+ksTtttt|| dd|ddd,ksztttt| |dd|ddd-ksttt| ||ddddd.ksttt| |t|ddddd/ksttt| t||ddddd0kstttt| ||ddddd1ks4t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   rM   r6   r7   r4   r5   r   rV   rV   rW   test_fcode_XlogicalF  s*   



































r   c                  C   s   t d\} }tt| |ddddks(ttt| |ddddksDttt| |dddd	ks`ttt| |d
dddks|ttt| |ddddksttt| |ddddkst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   rM   r   rV   rV   rW   test_fcode_Relational  s    r   c                     sf  t d} t| | dk f| d df tt fdd t dd}d	}||ksPttt| | dk f| d dfd
ddksztt| |  }t| |  }tdD ]}t	|| }t	|| }qd}tt|| dk f|dfdd}||ksttt| | dk f| d | dkft| dfdd}d}||ks$tt| | dk f| d | dkft| | dkf tt
 fdd d S )NrS   rq   rI   Tc                      s   t  S rh   r   rV   rR   rV   rW   rj     rk   z&test_fcode_Piecewise.<locals>.<lambda>re   r   z      merge(x, x**2, x < 1)r   r   zR      if (x < 1) then
         var = x
      else
         var = x**2
      end ifrr   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                      s   t  S rh   r   rV   r   rV   rW   rj     rk   )r   r   rB   rl   r;   rM   r   r   r   r   
ValueError)rS   codeexpectedabr   rV   r   rW   test_fcode_Piecewise  s.     
0,r   c                  C   s   t  } ddddddddd	d
dddddg}| |}dddddddddddddddddddddddddd d!dd"d#g}|D ]}t|d$ksvtqvt||D ]\}}||kstqt|t|kstd S )%NzbC     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 + properlyzBC     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 *z%     @ must + be + wrapped + properlyzH      this = is + a + long + and + nasty + fortran + statement +  that *zG      this = is + a + long + and + nasty + fortran + statement +   thatz'     @ * must + be + wrapped + properlyzF      this = is + a + long + and + nasty + fortran + statement + that*zH      this = is + a + long + and + nasty + fortran + statement +   that*zH      this = is + a + long + and + nasty + fortran + statement +    thatz&     @ *must + be + wrapped + properlyz@      this = is + a + long + and + nasty + fortran + statement +z*     @ that*must + be + wrapped + properlyzG      this = is + a + long + and + nasty + fortran + statement + that**zH      this = is + a + long + and + nasty + fortran + statement +  that**z'     @ **must + be + wrapped + properlyz+     @ that**must + be + wrapped + properlyzE      this = is + a + long + and + nasty + fortran + statement(that)/zH      this = is + a + long + and + nasty + fortran +     statement(that)z&     @ /must + be + wrapped + properlyH   )r<   _wrap_fortranlenrM   zip)r\   lineswrapped_linesZexpected_lineslinewr   rV   rV   rW   test_wrap_fortran  sl    
 r   c                  C   sF   t  } ddddddg}dddd	dd
dddddg}| ||ksBtd S )NzH      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.0d0zD      this_variable_is_very_long_because_we_try_to_test_line_break =z     @ 1.0d0zE      this_variable_is_very_long_because_we_try_to_test_line_break  =zF      this_variable_is_very_long_because_we_try_to_test_line_break   =zG      this_variable_is_very_long_because_we_try_to_test_line_break    =z     @ 10.0d0r<   r   rM   r\   r   r   rV   rV   rW   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   rV   rV   rV   rW   rj   5  rk   ztest_settings.<locals>.<lambda>)rB   	TypeErrorrV   rV   rV   rW   test_settings4  s    r   c                  C   s0   t d\} }tt| t| dddks,td S )Nrn   rC   rD   zsin(y) + cos(x))r   r;   r   r   rM   r   rV   rV   rW   test_free_form_code_line8  s    r   c                  C   s@   t d\} }tt| t| d  dd}d}||ks<td S )Nrn   rs   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   rM   )rS   rT   resultr   rV   rV   rW    test_free_form_continuation_line=  s
     r   c                  C   s0   t ddi} dg}ddg}| ||ks,t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   rV   rV   rW   test_free_form_comment_lineH  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s||ddi ks||ddi ks||ddi kstd S )Nr   Trc   r   rS   rT   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   )	ro   r   r   rS   rT   r   r   r   r   rV   rV   rW   
test_loopsQ  s     

"r   c                  C   sf   t ddtd\} }td}td}t| |} d| jj|jd }t||  ||  dd	}||ksbtd S )
Nzi mT)r/   clsrS   rT   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;   rM   )r   r   rS   rT   r   r   rV   rV   rW   test_dummy_loopsk  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
std S )Nr   rT   shaperS   Dyrq   r   F)r   Zcontract+Dy(i) = (y(i + 1) - y(i))/(x(i + 1) - x(i)))r=   r>   r   r;   r   lhsendswithrM   Zlen_yrT   rS   r   r   r   Zcode0rV   rV   rW   2test_fcode_Indexed_without_looking_for_contractionz  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stG d	d
 d
t	t
 | fdd|tD }t|| ||d  ||  ||d  ||   }tt|j|j}|dstd S )Nr   rT   r   rS   r   rq   r   r   c                   @   s   e Zd ZdS )z.test_element_like_objects.<locals>.ElementExprN)r^   r_   r`   rV   rV   rV   rW   ElementExpr  s   r   c                 3   s    | ]}| |j |jfV  qd S rh   )nameindices)r   r   r   rV   rW   	<genexpr>  s     z,test_element_like_objects.<locals>.<genexpr>)r?   r>   r   r;   r#   r   r   r   rM   r1   r   subsZatomsr@   r   rV   r   rW   test_element_like_objects  s    22r   c                  C   s:   G dd dt } |  }td}|t|ddks6t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copyrV   rV   rV   rW   MyFancyFCodePrinter  s   r   rS   Zborkz      bork = sin(x))r<   r   r   r   rM   )r   r\   rS   rV   rV   rW   test_derived_classes  s    r   c                  C   s.   d} d}t ddi}|| }||ks*t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_coderM   )Z	codelinesr   rO   r   rV   rV   rW   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sXttd|d	  | dkf|d	 dft|d
  |d  }t|dddkst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s*td S )Nzx,y,zrI   r   Tr   rp   rq   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   )rq   r   r   r   re   r   z?      merge(2*A(3, 1), A(3, 1), x > 0) + sin(A(2, 1)) + A(1, 1)rP   r   M)rp   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;   rM   r   r   )	rS   rT   rU   matr   rR   rP   r   r   rV   rV   rW   test_Matrix_printing  s&    ,	6
$r   c                  C   sD   t d\} }t| tdddt|| | g}t|}|dks@td S )Nr   r   rr   rI   z2      do x = 0, 9, 2
         y = x*y
      end do)r   r"   r!   r#   r;   rM   )rS   rT   fZsolrV   rV   rW   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td S )Nre   rC   rf   )r;   rM   )rR   refkwargsrV   rV   rW   check  s    z%test_fcode_Declaration.<locals>.checkr   Trc   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dcl1rS   rT   Zvar2Zdcl2bZvar3Zdcl3rV   rV   rW   test_fcode_Declaration  s     





r   c                  C   sx   t ddd} t ddd}t ddd}t| d dks8ttd| d  dksPt|d || | }t|d	ksttd S )
Nr   rq   rp   BCr   z      A(1, 1)z      3*A(1, 1)z      (A - B)(1, 1))r:   r;   rM   r   )r   r   r   FrV   rV   rW   test_MatrixElement_printing&  s    r   c                  C   s(   t d} tt| dddddks$td S )NrS   +rq   rC   rD   z	x = x + 1)r   r;   r$   rM   ri   rV   rV   rW   test_aug_assign3  s    r  c                  C   s8   t d} ttt| dkt| ddgdddks4td S )NrS   rq   -rC   rD   z)do while (abs(x) > 1)
   x = x - 1
end do)r   r;   r,   rL   r$   rM   ri   rV   rV   rW   
test_While8  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 )	NrS   ro   Trc   r   powerc                      s   t  S rh   r   rV   fp1rV   rW   rj   I  rk   z.test_FunctionPrototype_print.<locals>.<lambda>)r   r&   r*   r/   r-   rB   rl   )rS   ro   vxvnrV   r  rW   test_FunctionPrototype_printA  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 )	NrS   ro   Trc   r   r  c                      s   t  S rh   r   rV   Zfd1rV   rW   rj   U  rk   z/test_FunctionDefinition_print.<locals>.<lambda>)	r   r&   r*   r/   r#   r0   r.   rB   rl   )rS   ro   r  r  bodyrV   r
  rW   test_FunctionDefinition_printL  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   rX   rb   rm   rt   rx   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	  r  rV   rV   rV   rW   <module>   s    <	

	1c
+<		?#
	