# Variable calculations should be done in this file.
# It is read and interpreted by wims for all valid calls to the module.

!if $style=simple and $type!=series and $type!=finite
 type=
!endif

!default series1=1
!default finite1=1
!default finite2=10
!default type=series
!default num_precision=12
!default style=simple
wims_rawmath_variables=n

pari_precision=$num_precision
maxima_precision=$num_precision

!if $formula!=$empty and $noshow!=yes and $cmd!=resume and $cmd!=help
 compute=yes
 formula=!trim $formula
 formula=!lower $formula
 formula=!rawmath $formula
 
 !if $type=series
  series1=!rawmath $series1
  result=!exec maxima abstr:sum($formula,n,$series1,inf);\
	bfloat(abstr);
 !endif
 
 !if $type=seralt or $type=serpos
  mode=!char 4 to -1 of $type
  series1=!rawmath $series1
  result=!exec pari print("sum")\
	print(sum$mode(n=$series1,$formula))
 !endif

 !if $type=finite
  !default finite1=1
  !default finite2=10
  finite1=!rawmath $finite1
  finite2=!rawmath $finite2
  test=!eval $finite2-$finite1
  !if . isin $finite1$finite2 and NaN notin $test
   error_test=realbound
   !exit
  !endif
  !if NaN notin $test
   !if abs($test)>20
    add_term=+0.0
   !endif
   result=!exec pari print(abstr=sum(n=$finite1,$finite2,$formula $add_term))\
	print(abstr+0.0)
  !else
   result=!exec maxima abstr:sum($formula,n,$finite1,$finite2);\
	bfloat(abstr);
  !endif
 !endif
 
 !if $type=prime
  !default prime1=1
  !default prime2=100
  prime1=!rawmath $prime1
  prime2=!rawmath $prime2
  result=!exec pari somme=0;forprime(n=$prime1,$prime2,somme=somme+$formula);print(somme)
 !endif

 !if $type=div
  div=!trim $div
  div=!rawmath $div
  !if $div=$empty
   error_test=nodivnum
   !exit
  !endif
  result=!exec pari print(sumdiv($div,n,$formula))
 !endif

 !if $type=poly and 1=0
  poly=!lowercase $poly
  poly=!rawmath $poly
  !if x notvarof $poly
   error_test=nopoly
   !exit
  !endif
  result=!exec mupad abstr:=sum($formula,n=RootOf($poly,x));\
	print(float(abstr));
 !endif

 res_abstr=!line 1 of $result
 res_abstr=!texmath $res_abstr
 !if a isin $res_abstr or e isin $res_abstr or i isin $res_abstr\
     or o isin $res_abstr or u isin $res_abstr or y isin $res_abstr\
     or A isin $res_abstr or E isin $res_abstr or I isin $res_abstr\
     or O isin $res_abstr or U isin $res_abstr or Y isin $res_abstr\
     or / isin $res_abstr
  res_num=!line 2 of $result
  test=!eval $res_num
  !if NaN isin $test
   res_num=
  !endif
 !endif
 !if sum isin $res_abstr or abstr isin $res_abstr
  res_abstr=
 !endif
 !if $res_abstr!=$empty and $res_num!=$empty
  res_link==
 !endif
 !if $res_abstr$res_num=$empty
  error_test=fail
 !else
  wims_module_log=$type: $formula
 !endif
!endif

