 file SERIES%.DIF                             GAE - Feb. 1982
Make a file called SERIES.DIF as follows:
(1)  Start with this file (SERIES%.DIF).
(2)  Insert in it (at the spot marked INSERT HERE) the two
          functions FUNCTION QUERY and FUNCTION SIGN.  They
          can be found at the beginning of file LIM.DIF or
          file INT.DIF.
(3)  Finally, delete this comment up to the line.
-----------------------------------------------------------


% File  SERIES.DIF     Infinite series.  %

% rewritten, Feb. 1982 - GAE  
    DIF.ALG is required.
    LOG, TRGNEG, ATRG  may be useful with this file.  %



         %  INSERT HERE %


 
FUNCTION FCTR1(EX1,
  % Local: % PWREXPD, NUMNUM, DENDEN, DENNUM, NUMDEN, BASEXP, EXPBAS),
  PWREXPD: 6,
  DENNUM: NUMNUM: DENDEN: -30,
  EXPBAS: BASEXP: 30,
  NUMDEN: 0,
  EVAL (EX1),
ENDFUN $

FUNCTION LINCF(EX1, INDET),
  WHEN FREE(EX1:(EVSUB(EX1,INDET,INDET+1)-EX1),INDET), EX1  EXIT,
ENDFUN $

FUNCTION SIGSB2(EX1,EX2,
  % Local: % EX3, EX4),
  EX3: COS(EX1), EX4: SIN(EX1),
  #E^(EX3*EX2)*COS(EX4*EX2),
ENDFUN $

FUNCTION SIGF(EX1,EX2,EX3,
  % Local: % EX4, INDET2, INDET3),
  INDET2: 'INDET2, INDET3: 'INDET3,
  WHEN EX3 > 0,
    EX4: SIGF(INDET3,EX2,0),
    LOOP
      WHEN EX3 EQ EX2,  EXIT,
      EX4: DIF(EX4,INDET3),
      EX3: EX3+1,
    ENDLOOP,
    EVSUB(EX4,INDET3,EX1)  EXIT,
  % EX3 EQ 0 %
  EX4: 2*#PI/EX2,
  WHEN MOD(EX2,2) EQ 0,
    (#E^EX1+#E^-EX1+
        2*SIGMA(SIGSB2(INDET2*EX4,EX1),INDET2,1,(EX2-2)/2))/EX2  EXIT,
  (#E^EX1+2*SIGMA(SIGSB2(INDET2*EX4,EX1),INDET2,1,(EX2-1)/2))/EX2,
ENDFUN $

FUNCTION SIGFM(EX1,EX2,EX3,
  % Local: % EX4, INDET2, INDET3),
  INDET2: 'INDET2, INDET3: 'INDET3,
  WHEN EX3 > 0,
    EX4: -SIGFM(INDET3,EX2,0),
    LOOP
      WHEN EX3 EQ EX2,  EXIT,
      EX4: DIF(EX4,INDET3),
      EX3: EX3+1,
    ENDLOOP,
    EVSUB(EX4,INDET3,EX1)  EXIT,
  % EX3 EQ 0 %
  EX4: #PI/EX2,
  WHEN MOD(EX2,2) EQ 0,
    SIGMA(SIGSB2((2*INDET2+1)*EX4,EX1),INDET2,0,(EX2-2)/2)/(EX2/2)  EXIT,
  (#E^-EX1+2*SIGMA(SIGSB2((2*INDET2+1)*EX4,EX1),INDET2,0,(EX3-3)/2))/EX2,
ENDFUN $

FUNCTION SIGSB3(EX1,EX2,EX6,
  % Local: % EX3,EX4,EX5),
  EX3: COS(EX2),
  EX4: SIN(EX2),
  EX5: COS(EX1*EX2),
  EX1: 2*(COS((EX1-1)*EX2)-EX3*EX5)/EX4,
  -EX5*LOG(1-2*EX3*EX6+EX6^2,#E)+EX1*ATAN((EX6-EX3)/EX4)+EX1*(#PI/2-EX2),
ENDFUN $

FUNCTION SIGMA2(EX1, EX2,
  % Local: % EX3, EX4, EX5, EX6),
  EX4: DEN(EX1), EX5: NUM(EX1), EX6: EX2^(1/EX4),
  EX3: (2/EX4)*#PI,
  EX1: -LOG(1-EX6,#E),
  BLOCK
    WHEN EX5 EQ 0,  EXIT,
    EX1: EX1+(-EX4/EX5)*EX6^EX5,
  ENDBLOCK,
  WHEN MOD(EX4,2) EQ 0,
    EX1: EX1-(-1)^EX5*LOG(1+EX6,#E),
    EX2: (EX4-2)/2,
    LOOP
      WHEN EX2 EQ 0,  EXIT,
      EX1: EX1+SIGSB3(EX5,EX2*EX3,EX6),
      EX2: EX2-1,
    ENDLOOP,
    EX1  EXIT,
  EX2: (EX4-1)/2,
  LOOP
    WHEN EX2 EQ 0,  EXIT,
    EX1: EX1+SIGSB3(EX5,EX2*EX3,EX6),
    EX2: EX2-1,
  ENDLOOP,
  EX1,
ENDFUN $

FUNCTION SIGMA2M(EX1,EX2,
  % Local: % EX3,EX4,EX5,EX6),
  EX4: DEN(EX1), EX5: NUM(EX1), EX6: EX2^(1/EX4),
  EX3: #PI/EX4,
  EX1: 0,
  BLOCK
    WHEN EX5 EQ 0,  EXIT,
    EX1: (EX4/EX5)*EX6^EX5,
  ENDBLOCK,
  WHEN MOD(EX4,2) EQ 0,
    EX2: EX4-1,
    LOOP
      WHEN EX2 EQ -1,  EXIT,
      EX1: EX1-SIGSB3(EX5,EX2*EX3,EX6),
      EX2: EX2-2,
    ENDLOOP,
    WHEN EX5 EQ 0, -EX1  EXIT,
    EX1  EXIT,
  EX1: EX1+(-1)^EX5*LOG(1+EX6,#E),
  EX2: EX4-2,
  LOOP
    WHEN EX2 EQ -1, EXIT,
    EX1: EX1-SIGSB3(EX5,EX2*EX3,EX6),
    EX2: EX2-2,
  ENDLOOP,
  WHEN EX5 EQ 0, -EX1  EXIT,
  EX1,
ENDFUN $

FUNCTION SIGMA1(EX7,EX6,EX1,
  % Local: % INDET3,INDET4,EX8,EX9),
  % Fluid: EX2,EX3,EX5,INDET %
  INDET3: 'INDET3, INDET4: 'INDET4,
  WHEN POSITIVE(EX6),
    WHEN EX5 EQ 1 AND EX7 EQ 1,
      WHEN EX3 EQ PINF, PINF  EXIT,
      EX8: EXPD(PROD(INDET-INDET3,INDET3,0,EX6-1)),
      EX9: (INDET+1)*EX8,
      EX9: EVSUB(EX9,INDET,EX3)-EVSUB(EX9,INDET,EX2-1),
      EXPD(EX9)/(1+EX6)+SIGMA(INDET^EX6-EX8,INDET,EX2,EX3)  EXIT,
    EX8: SIGMA1(INDET4,0,EX1),  
    WHEN FREE(EX8, 'SIGMA),
      WHEN MEMBER(EX8, '(PINF MINF CINF ?) ),  EX8  EXIT,
      LOOP
        EX6: EX6-1,
        WHEN EX6<0,  EXIT,
        EX8: INDET4*DIF(EX8,INDET4),
      ENDLOOP,
      INDET4: EX7,
      EXPD(EX8)  EXIT,
    LIST('SIGMA,EX5*INDET^EX6*EX7^INDET,INDET,EX2,EX3)  EXIT,
  % EX6=0 %
  WHEN FREE(EX5,INDET),
    WHEN EX3 EQ PINF,
      WHEN SIGN(1-EX1) EQ 1,
        WHEN SIGN(1+EX1) EQ 1,
          EX5*EX7^EX2/(1-EX7)  EXIT,
        '?  EXIT,
      PINF  EXIT,
    WHEN EX7=1, EX5*(EX3-EX2+1)  EXIT,
    EX5*(EX7^EX2-EX7^(EX3+1))/(1-EX7)  EXIT,
  WHEN NUMBER(EX6:LINCF(1/EX5,INDET)) AND EX3=PINF,
    WHEN (EX8:SIGN(1+EX1)) EQ -1, '?  EXIT,
    WHEN EX8 EQ 0 AND NOT EX7=EX1, '?  EXIT,
    WHEN SIGN(1-EX1) EQ 1,
      EX8: EXPD(1/EX5-EX6*INDET),
      EX10: EX8/EX6,
      EX4: QUOTIENT(NUM(EX10),DEN(EX10)),
      EX2: EX2+EX4,
      EX8: EX8-EX4*EX6,
      EX10: EX8/EX6,
      WHEN MOD(DEN(EX10),2) EQ 0,
        WHEN SIGN(EX1) EQ -1,
          (-SIGMA2M(EX10,-EX7)+
              SIGMAX((-EX7)^(INDET+EX10)*(-1)^INDET/(INDET+EX10),INDET,EX2,0))
              *(-EX7)^-EX10*EX7^-EX4/EX6  EXIT,
        (SIGMA2(EX10,EX7)+SIGMAX(EX7^(INDET+EX10)/(INDET+EX10),INDET,EX2,0))
              *EX7^-(EX10+EX4)/EX6  EXIT,
      (SIGMA2(EX10,EX7)+SIGMAX(EX7^(INDET+EX10)/(INDET+EX10),INDET,EX2,0))
            *EX7^-(EX10+EX4)/EX6  EXIT,
    WHEN SIGN(EX6) EQ 1, PINF  EXIT,
    MINF  EXIT,
  WHEN FIRST(EX9:1/EX5) EQ '! AND EX3=PINF,
    EX9:SECOND(EX9),
    WHEN POSITIVE(EX6:LINCF(EX9,INDET)) AND INTEGER(EX8:EXPD(EX9-INDET*EX6)),
      EX4: QUOTIENT(EX8,EX6),
      EX8: MOD(EX8,EX6),
      EX2: EX2+EX4,
      WHEN MOD(EX6,2) EQ 0,
        WHEN SIGN(EX1) EQ 1,
          EX7^(-EX8/EX6-EX4)*SIGF(EX7^(1/EX6),EX6,EX8)
            -SIGMAX(EX5*EX7^INDET,INDET,-EX4,EX2-EX4-1)  EXIT,
        (-EX7)^(-EX8/EX6-EX4)*(SIGFM((-EX7)^(1/EX6),EX6,EX8)
            -SIGMAX(EX5*EX7^INDET,INDET,-EX4,EX2-EX4-1))  EXIT,
      EX7^(-EX8/EX6-EX4)*SIGF(EX7^(1/EX6),EX6,EX8)
            -SIGMAX(EX5*EX7^INDET,INDET,-EX4,EX2-EX4-1)  EXIT,
    LIST('SIGMA,EX5*EX7^INDET,INDET,EX2,EX3)  EXIT,
  LIST('SIGMA,EX5*EX7^INDET,INDET,EX2,EX3),
ENDFUN $

FUNCTION SIGMAX(EX1, INDET, EX2, EX3),
  WHEN EX2 > EX3+1, -SIGMA(EX1,INDET,EX3+1,EX2-1)  EXIT,
  SIGMA(EX1,INDET,EX2,EX3),
ENDFUN $

FUNCTION SIGMA (EX1, INDET, EX2, EX3,
  % Local: %  EX4, EX5, EX6, EX7, EX8, EX9, EX10,
      DENNUM, LEX1, SIGN),
  DENNUM: 30,
  WHEN EX2 = MINF,
    WHEN EX3 = PINF,
      SIGMA(EX1,INDET,0,PINF)+SIGMA(EVSUB(EX1,INDET,-INDET),INDET,1,PINF)  EXIT,
    SIGMA(EVSUB(EX1,INDET,-INDET),INDET,-EX3,PINF)  EXIT,
  WHEN INTEGER(EX2) AND INTEGER(EX3),
    EX4: 0,
    LOOP
      WHEN EX2 > EX3, EX4 EXIT,
      EX4: EX4 + EVSUB(EX1,INDET,EX2),
      EX2: EX2 + 1,
    ENDLOOP EXIT,
  EX1: EXPD(NUM(EX1))/DEN(EX1),
  WHEN APPLY(GET('SIGMA,FIRST(EX1)), ARGEX(EX1))  EXIT,
  EX4: FCTR1(EX1),
  BLOCK
    WHEN PRODUCT(EX4), LEX1: REST(EX4)  EXIT,
    LEX1: LIST(EX4),
  ENDBLOCK,
  EX6: 0, EX4: EX5: EX7: 1,
  LOOP
    WHEN ATOM(LEX1), EXIT,
    EX8: POP(LEX1),
    BLOCK
      WHEN FREE(EX8, INDET), EX4: EX4*EX8  EXIT,
      WHEN EX8=INDET, EX6:EX6+1  EXIT,
      WHEN POWER(EX8),
        EX9: SECOND(EX8), EX10: THIRD(EX8),
        WHEN EX9=INDET AND POSITIVE(EX10),
          EX6: EX6+EX10  EXIT,
        WHEN FREE(EX10: EX10/INDET, INDET) AND FREE(EX9,INDET),
          EX7: EX7*EX9^EX10  EXIT,
        EX5: EX5*EX8  EXIT,
      EX5: EX5*EX8,
    ENDBLOCK,
  ENDLOOP,
  EX4*SIGMA1(EX7,EX6,EX7),
ENDFUN $

PROPERTY SIGMA, +, FUNCTION (EX1, EX4),
  % fluid: INDET, EX2, EX3 %
  WHEN ZERO (EVSUB(EX1,INDET,INDET+1) + EX4),
    EVSUB(EX1,INDET,EX2)+EVSUB(EX4,INDET,EX3)  EXIT,
  WHEN ZERO (EVSUB(EX4,INDET,INDET+1) + EX1),
    EVSUB(EX4,INDET,EX2)+EVSUB(EX1,INDET,EX3)  EXIT,
  SIGMA(EX1,INDET,EX2,EX3) + SIGMA(EX4,INDET,EX2,EX3)
ENDFUN $

FUNCTION PROD (EX1, INDET, EX2, EX3,
  % Local: %  EX4, LOGEXPD),
  WHEN INTEGER(EX2) AND INTEGER(EX3),
    EX4: 1,
    LOOP
      WHEN EX2 > EX3, EX4 EXIT,
      EX4: EX4 * EVSUB(EX1,INDET,EX2),
      EX2: EX2 + 1,
    ENDLOOP  EXIT,
  WHEN EX1=INDET, EX3!/(EX2-1)!  EXIT,
  WHEN FREE(EX1,INDET), EX1^(EX3-EX2+1)  EXIT,
  WHEN APPLY(GET('PROD,FIRST(EX1)), ARGEX(EX1))  EXIT,
  LIST ('PROD, EX1, INDET, EX2, EX3),
ENDFUN $


PROPERTY PROD, +, FUNCTION (EX1, EX4),
  % fluid: EX2, EX3, INDET %
  WHEN EX1=INDET AND FREE(EX4,INDET),
    (EX3+EX4)!/(EX2+EX4-1)!  EXIT,
  WHEN EX4=INDET AND FREE(EX1,INDET),
    (EX3+EX1)!/(EX2+EX1-1)!  EXIT,
ENDFUN $

PROPERTY PROD, *, FUNCTION (EX1, EX4),
  % fluid: EX2,EX3, INDET %
  WHEN EXPD(EVSUB(EX1,INDET,INDET+1)*EX4) EQ 1,
    EVSUB(EX1,INDET,EX2)*EVSUB(EX4,INDET,EX3)  EXIT,
  WHEN EXPD(EVSUB(EX4,INDET,INDET+1)*EX1) EQ 1,
    EVSUB(EX4,INDET,EX2)*EVSUB(EX1,INDET,EX3)  EXIT,
  PROD(EX1,INDET,EX2,EX3) * PROD(EX4,INDET,EX2,EX3),
ENDFUN $

PROPERTY PROD, ^, FUNCTION (EX1, EX4)
  % fluid: EX2, EX3, INDET %
  WHEN FREE(EX4,INDET),
    PROD(EX1,INDET,EX2,EX3)^EX4  EXIT,
  WHEN FREE(EX1,INDET),
    EX1^SIGMA(EX4,INDET,EX2,EX3)  EXIT,
ENDFUN $

RDS() $
