procedure EULER(FCT,SUM,EPS,TIM);value EPS,TIM;
integer TIM; real procedure FCT; real SUM, EPS;
comment EULER COMPUTES THE SUM OF FCT (I) FOR I
 FROM ZERO UP TO INFINITY BY MEANS OF A SUITABLY
 REFINED EULER TRANSFORMATION. THE SUMMATION IS
 STOPPED AS SOON AS TIM TIMES IN SUCCESSION THE ABSOLUTE
 VALUE OF THE TERMS OF THE TRANSFORMED SERIES IS
 FOUND TO BE LESS THAN EPS, HENCE ONE SHOULD PROVIDE
 A FUNCTION FCT WITH ONE INTEGER ARGUMENT, AN UPPER
 BOUND EPS, AND AN INTEGER TIM. THE OUTPUT IS THE SUM SUM.
 EULER IS PARTICULARLY EFFICIENT IN THE CASE OF A SLOWLY
 CONVERGENT OR DIVERGENT ALTERNATING SERIES;
 begin integer I,K,N,T;array M(/0:15/);
 real MN, MP, DS;
  I:=N:=T:=0;M(/0/):=FCT(0);SUM:=M(/0/)/2;
  NEXTTERM:I:=I+1;MN:=FCT(1);
    for K:=0step 1until N'DO'
         begin MP:=(MN+M(/K/))/2;M(/K/):=MN;
            MN:=MP'END'MEANS;
    if (ABS(MN)less ABS (M(/N/))and N'LESS'15)then 
         begin DS:=MN/2;N:=N+1;
            M(/N/):=MN'END' ACCEPT
         else DS:=MN;
          SUM:=SUM+DS;
         if ABS(DS)less EPS'THEN'T:=T+1else T:=0;
         if T'LESS'TIM'THEN'goto NEXTTERM
         end EULER;