% File LOG.ALG	(c)		05/21/81	The Soft Warehouse %


FUNCTION LOGEXPD (EX1, LOGEXPD),
  EVAL (EX1),
ENDFUN $

FUNCTION LOG (EX1, % Optional: % EX2),
  WHEN EMPTY(EX2), LOG (EX1, LOGBAS) EXIT,
  WHEN ZERO(EX1),  ?(LIST('LOG, EX1, EX2))  EXIT,
  WHEN EX2 EQ 1, ?(LIST('LOG, EX1, EX2))  EXIT,
  WHEN PBRCH AND EX1 EQ 1, 0 EXIT,
  WHEN PBRCH AND EX1=EX2, 1 EXIT,
  WHEN PBRCH AND ZERO (MOD(EX1,EX2)),
    1 + LOG (QUOTIENT(EX1,EX2), EX2)  EXIT,
  WHEN NOT(EX2 EQ LOGBAS) AND POSMULT(LOGEXPD,2),
    LOG(EX1,LOGBAS) / LOG(EX2,LOGBAS)  EXIT,
  WHEN ATOM(EX1), LIST('LOG, EX1, EX2)  EXIT,
  WHEN APPLY(GET('LOG,FIRST(EX1)), ADJOIN(EX2,ARGEX(EX1)))  EXIT,
  LIST('LOG, EX1, EX2),
ENDFUN $

PROPERTY PRTMATH, LOG, FUNCTION (LEX1,
  % Local: % EX1),
  EX1 : POP(LEX1),
  LEX1: FIRST(LEX1),
  WHEN LEX1 EQ #E,
    PRTLIST ('LN, EX1) EXIT,
  WHEN LEX1 = LOGBAS,
    PRTLIST ('LOG, EX1) EXIT,
ENDFUN $

FUNCTION LN (EX1),
  LOG(EX1, #E),
ENDFUN $

PROPERTY LOG, *, FUNCTION (EX1, EX2, EX3),
  WHEN POSMULT(LOGEXPD,5),  LOG(EX2,EX1) + LOG(EX3,EX1)  EXIT,
ENDFUN $

PROPERTY LOG, ^, FUNCTION (EX1, EX2, EX3),
  WHEN POSMULT(LOGEXPD,3), EX3*LOG(EX2,EX1)  EXIT,
  WHEN PBRCH AND EX1=EX2, EX3*LOG(EX2,EX1)  EXIT,
ENDFUN $

PROPERTY *, LOG, FUNCTION (EX1, EX2, EX3),
  WHEN NEGMULT(LOGEXPD,2) AND POWER(EX1)
      AND LOGARITHM(SECOND(EX1)) AND THIRD(EX1) EQ -1 
      AND THIRD(SECOND(EX1))=EX3,
    LOG (EX2, SECOND(SECOND(EX1)))  EXIT,
  WHEN NEGMULT(LOGEXPD,3),  LOG (EX2^EX1, EX3)  EXIT,
ENDFUN $

FUNCTION LOGARITHM (EX1),
  FIRST(EX1) EQ 'LOG,
ENDFUN $

PROPERTY +, LOG, FUNCTION (EX1, EX2, EX3),
  WHEN LOGARITHM(EX1),
    WHEN NEGMULT(LOGEXPD,5),
      WHEN THIRD(EX1)=EX3,
        LOG (SECOND(EX1)*EX2, EX3)  EXIT EXIT EXIT,
ENDFUN $

PROPERTY EXPON, LOG, FUNCTION (EX1, EX2, EX3),
  WHEN EX1 = EX3,  EX2  EXIT,
ENDFUN $

RDS() $

