% File:  SIGMA.ALG  (c)		08/26/80	The Soft Warehouse %


FUNCTION LINCF (EX1, INDET),
  WHEN FREE (EX1:(EX1-EVSUB(EX1,INDET,0))/INDET, INDET), EX1  EXIT,
ENDFUN$


FUNCTION SIGMA (EX1, INDET, EX2, EX3,
  % Local: %  EX4, NUMNUM, DENDEN, DENNUM, NUMDEN, PWREXPD, LOGEXPD),
  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,
  NUMNUM: DENDEN: 30,
  DENNUM: -30,
  NUMDEN: 0,
  PWREXPD: LOGEXPD: 6,
  WHEN FREE (EX4:ANTIDF(EX1), ANTIDF),
    WHEN INTEGER(#LIM), LIM(EX4,INDET,EX3+1) - LIM(EX4,INDET,EX2) EXIT,
    EVSUB(EX4,INDET,EX3+1) - EVSUB(EX4,INDET,EX2)  EXIT,
  WHEN APPLY(GET('SIGMA,FIRST(EX1)), ARGEX(EX1))  EXIT,
  LIST('SIGMA, EX1,INDET,EX2,EX3),
ENDFUN $

FUNCTION ANTIDF (EX1),
  WHEN EX1 = INDET, EX1*(-1+EX1)/2 EXIT,
  WHEN FREE(EX1,INDET), INDET*EX1 EXIT,
  SIMPU(ANTIDF,EX1)
ENDFUN $

PROPERTY ANTIDF, +, FUNCTION (EX1, EX2),
  WHEN ZERO (EVSUB(EX1,INDET,INDET+1) + EX2), -EX1  EXIT,
  WHEN ZERO (EVSUB(EX2,INDET,INDET+1) + EX1), -EX2  EXIT,
  ANTIDF(EX1) + ANTIDF(EX2),
ENDFUN $

PROPERTY ANTIDF, *, FUNCTION (EX1, EX2),
  WHEN FREE(EX1,INDET), EX1*ANTIDF(EX2)  EXIT,
  WHEN FREE(EX2,INDET), EX2*ANTIDF(EX1)  EXIT,
ENDFUN $

PROPERTY ANTIDF, ^, FUNCTION (EX1, EX2, EX3),
  WHEN EX1 = INDET AND POSITIVE(EX2),
    (EX3:PROD(INDET-'##,'##,0,EX2-1)) * (INDET-EX2)/(1+EX2)
      + ANTIDF(EX1^EX2-EX3)  EXIT,
  WHEN FREE(EX1,INDET) AND (EX3: LINCF(EX2,INDET)),
    EX1^EX2/(EX1^EX3 - 1)  EXIT,
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 FREE (EX4:ANTIDV(EX1), ANTIDV),
    WHEN INTEGER(#LIM), LIM(EX4,INDET,EX3+1) / LIM(EX4,INDET,EX2)  EXIT,
    EVSUB(EX4,INDET,EX3+1) / EVSUB(EX4,INDET,EX2)  EXIT,
  WHEN APPLY(GET('PROD,FIRST(EX1)), ARGEX(EX1))  EXIT,
  LIST ('PROD, EX1, INDET, EX2, EX3),
ENDFUN $

%**************  Optional ANTIDV (PROD) Package  ****************%

FUNCTION ANTIDV (EX1),
  WHEN EX1=INDET, (EX1-1)!  EXIT,
  WHEN FREE(EX1,INDET), EX1^INDET  EXIT,
  SIMPU (ANTIDV, EX1)
ENDFUN $

PROPERTY ANTIDV, +, FUNCTION (EX1, EX2),
  WHEN EX1=INDET AND FREE(EX2,INDET), (EX1-1+EX2)!  EXIT,
  WHEN EX2=INDET AND FREE(EX1,INDET), (EX2-1+EX1)!  EXIT,
ENDFUN $

PROPERTY ANTIDV, *, FUNCTION (EX1, EX2),
  WHEN EXPD(EVSUB(EX1,INDET,INDET+1)*EX2) EQ 1, 1/EX1  EXIT,
  WHEN EXPD(EVSUB(EX2,INDET,INDET+1)*EX1) EQ 1, 1/EX2  EXIT,
  ANTIDV(EX1) * ANTIDV(EX2),
ENDFUN $

PROPERTY ANTIDV, ^, FUNCTION (EX1, EX2, INDET2),
  WHEN FREE(EX2,INDET), ANTIDV(EX1)^EX2  EXIT,
  INDET2: 'INDET2,
  WHEN FREE(EX1,INDET),
    EX1^SIGMA(EVSUB(EX2,INDET,INDET2-1),INDET2,1,INDET)  EXIT,
ENDFUN $

RDS () $
