 file SOLVE4%.EQN                         GAE - Feb. 1982
Make a file called SOLVE4.EQN as follows:
(1)  Start with the existing file SOLVE.EQN.
(2)  Delete the entire FUNCTION SOLEXP (about 50 lines).
(3)  Insert in its place the entire file SOLVE4%.EQN below
          this line:
-------------------------------------------------------------

FUNCTION SOLEXP (EX1,
  % Local: % EX2,EX3,EX4,EX5,EX6,EX7,EX8,EX9,EX10,LEX1,LEX2,LEX3,LEX4),
  EX1: NUM (FCTR(EX1)),
  BLOCK WHEN SUM(EX1), EX1: NUM(EXPD(EX1))  EXIT,
  ENDBLOCK,
  WHEN ZERO(EX1), LIST(INDET "==" ARB(#ARB)) EXIT,
  WHEN FREE(EX1, INDET), FALSE EXIT,
  BLOCK WHEN PRODUCT(EX1), LEX1: REST(EX1) EXIT,
    LEX1: LIST(EX1)
  ENDBLOCK,
  LOOP
    EX1: NUM(EXPD(POP(LEX1))),
    BLOCK
      WHEN SUM(EX1),
        LEX3:REST(EX1), EX6:EX7:EX8:EX9:EX10:0, EX2:FALSE,
        LOOP
          EX3: POP(LEX3),
          BLOCK WHEN FREE(EX3,INDET), EX6: EX6+EX3 EXIT,
            EX4: EX5: 1,
            BLOCK WHEN PRODUCT(EX3), LEX4: REST(EX3) EXIT,
              LEX4: LIST(EX3)
            ENDBLOCK,
            LOOP
              EX3: POP(LEX4),
              BLOCK WHEN FREE(EX3, INDET), EX4: EX4*EX3 EXIT,
                EX5: EX5*EX3
              ENDBLOCK,
              WHEN ATOM(LEX4), EXIT
            ENDLOOP,
            WHEN EMPTY(EX2), EX7: EX4, EX2: EX5  EXIT,
            WHEN EX5 = EX2, EX7: EX7+EX4 EXIT,
            WHEN EX5 = EX2^2, EX8: EX8+EX4 EXIT,
            WHEN EX5 = EX2^3, EX9: EX9+EX4 EXIT,
            WHEN EX5 = EX2^4, EX10: EX10+EX4 EXIT,
            WHEN NOT ZERO(EX9), EX2:0 EXIT,
            WHEN NOT ZERO(EX10), EX2:0 EXIT,
            WHEN EX5^2 = EX2,
              EX10:EX8, EX8:EX7, EX7:EX4, EX2:EX5 EXIT,
            WHEN NOT ZERO(EX8), EX2:0 EXIT,
            WHEN EX5^3=EX2,
              EX9:EX7, EX7:EX4, EX2:EX5 EXIT,
            WHEN EX5^4=EX2,
              EX10:EX7, EX7:EX4, EX2:EX5 EXIT,
            WHEN EX5^3=EX2^2,
              EX9: EX7, EX8: EX4, EX7: 0, EX2: EX2/EX5 EXIT,
            WHEN EX5^2=EX2^2,
              EX9: EX4, EX8: EX7, EX7: 0, EX2: EX5/EX2 EXIT,
            EX2:0
          ENDBLOCK,
          WHEN ZERO(EX2), EX1: LIST (EX1 "==" 0) EXIT,
          WHEN ATOM (LEX3),
            WHEN NOT ZERO(EX10),
              EX1:BIQUAD1(EX6,EX7,EX8,EX9,EX10)  EXIT,
            WHEN NOT ZERO(EX9),
              EX1:CUBIC1(EX6,EX7,EX8,EX9)  EXIT,
            WHEN NOT ZERO(EX8),
              EX1:QUADRAT1(EX6,EX7,EX8)  EXIT,
            EX1:LINEAR1(EX6,EX7)  EXIT,
        ENDLOOP EXIT,
      WHEN NOT FREE(EX1,INDET),
        EX2: EX1,
        EX1: SOLF(0) EXIT,
      EX1: FALSE,
    ENDBLOCK,
    LEX2: UNION(EX1, LEX2),
    WHEN ATOM (LEX1), LEX2 EXIT,
  ENDLOOP,
ENDFUN $

FUNCTION LINEAR1(EX6,EX7),
  % fluid : EX2 %
  SOLF(-EX6/EX7),
ENDFUN $

FUNCTION QUADRAT1(EX6,EX7,EX8),
  % fluid : EX2 %
  EX6: QUADRAT(EX6,EX7,EX8),
  UNION (SOLF(POP(EX6)),SOLF(POP(EX6))),
ENDFUN $

FUNCTION SQRT(EX1,
  %local % PBRCH),
  PBRCH: TRUE,
  EX1^(1/2),
ENDFUN $

FUNCTION QUADRAT(EX6,EX7,EX8),
  WHEN E6=0, ADJOIN(0,LINEAR(EX7,EX8))  EXIT,
  EX6:SQRT(EX7^2-4*EX8*EX6),
  LIST((-EX7+EX6)/(2*EX8), (-EX7-EX6)/(2*EX8)),
ENDFUN $

FUNCTION CUBIC1(EX6,EX7,EX8,EX9),
  %fluid : EX2 %
  EX6: CUBIC(EX6,EX7,EX8,EX9),
  UNION(SOLF(POP(EX6)),
  UNION(SOLF(POP(EX6)),
        SOLF(POP(EX6)))),
ENDFUN $

#OMEGA: -1/2 + #I*3^(1/2)/2 $
#OMSQ:  -1/2 - #I*3^(1/2)/2 $

FUNCTION CUBRT(EX1,
  % local : % PBRCH),
  PBRCH: TRUE,
  EX1^(1/3),
ENDFUN $

FUNCTION CUBIC(EX6,EX7,EX8,EX9)
  WHEN EX6=0, ADJOIN(0,QUADRAT(EX7,EX8,EX9))  EXIT,
  EX8: EX8/EX9, EX7: EX7/EX9, EX6: EX6/EX9,
  EX6: QUADRAT((EX8^2-3*EX7)^3, 2*EX8^3-9*EX8*EX7+27*EX6,1),
  EX9: CUBRT(POP(EX6)),
  BLOCK
    WHEN EX9=0, EX7: CUBRT(POP(EX6))  EXIT,
    EX7: (EX8*EX8-3*EX7)/EX9,
  ENDBLOCK,
  LIST((-EX8+EX9+EX7)/3,
       (-EX8+#OMSQ*EX9+#OMEGA*EX7)/3,
       (-EX8+#OMEGA*EX9+#OMSQ*EX7)/3),
ENDFUN $

FUNCTION BIQUAD1(EX6,EX7,EX8,EX9,EX10),
  %fluid : EX2 %
  EX6: BIQUAD(EX6,EX7,EX8,EX9,EX10),
  UNION(UNION(SOLF(POP(EX6)),
              SOLF(POP(EX6))),
        UNION(SOLF(POP(EX6)),
              SOLF(POP(EX6)))),
ENDFUN $

FUNCTION BIQUAD(EX6,EX7,EX8,EX9,EX10,
  % local : % EX1),
  WHEN EX6=0, ADJOIN(0,CUBIC(EX7,EX8,EX9,EX10))  EXIT,
  EX9: EX9/EX10, EX8: EX8/EX10, EX7: EX7/EX10, EX6: EX6/EX10,
  EX1: CUBIC(-(EX9^3-4*EX9*EX8+8*EX7)^2,
           3*EX9^4-16*EX9*EX9*EX8+16*EX9*EX7+16*EX8*EX8-64*EX6,
           -3*EX9*EX9+8*EX8,
           1),
  EX10:SQRT(POP(EX1)),
  EX6:SQRT(POP(EX1)),
  BLOCK
    WHEN EX10*EX6=0, EX8:SQRT(POP(EX1))  EXIT,
    EX8:(-EX9^3+4*EX9*EX8-8*EX7)/(EX6*EX10),
  ENDBLOCK,
  LIST((-EX9+EX10+EX6+EX8)/4,
       (-EX9+EX10-EX6-EX8)/4,
       (-EX9-EX10+EX6-EX8)/4,
       (-EX9-EX10-EX6+EX8)/4),
ENDFUN $

