1
0
mirror of https://github.com/PDP-10/its.git synced 2026-02-06 16:44:44 +00:00

Get macsyma primer working.

Resolves #1011.
This commit is contained in:
Eric Swenson
2018-07-15 20:34:43 -07:00
parent a08865ce75
commit 82674a7555
9 changed files with 2129 additions and 301 deletions

259
src/ellen/check.52 Normal file
View File

@@ -0,0 +1,259 @@
;;; -*- Mode: Lisp; Package: Macsyma -*-
;;; Checking functions for PRIMER FASL
;;; (c) Copyright 1982 Masssachusetts Institute of Technology
(macsyma-module check)
(load-macsyma-macros mrgmac)
(DECLARE (SPECIAL CLABEL DLABEL $% $LABELS $LINENUM EXAMPLE1
PRAC-EXAMPLE1 PRAC-EXAMPLE2 RADCANEXAMPLE)
(*EXPR MEVAL STRIPDOLLAR DISPLA MGRIND MAKSTRING MACSYMA RETRIEVE))
(DEFUN FUNCHKP (A B)
(DO X (MREAD) (MREAD) NIL
(COND ((OR (EQ '$EXIT X) (EQ '$QUIT X)) (PRIMER-EXIT))
((EQ '$NO X)
(TERPRI) (PRINC '|O.K., we'll use this one.|)
(RETURN (MACSYMA '((MDEFINE) (($F) $X)
((MPLUS) ((MTIMES) 2 ((MEXPT) $X 2))
((MTIMES) 2 $X) 4)))))
((NOT (EQ (CAAR X) (CAR A)))
(TERPRI) (PRINC '|Not a function definition, use := .|) NIL)
((NOT (EQ (CAAADR X) (CAAR B)))
(TERPRI) (PRINC '|Please use |)
(PRINC (FULLSTRIP1 (CAAR B)))
(PRINC '| as the function name.|) NIL)
((NOT (EQ (CADADR X) (CADR B)))
(TERPRI) (PRINC '|Please use |)
(PRINC (FULLSTRIP1 (CADR B)))
(PRINC '| for the variable.|) NIL)
(($FREEOF (CADR B) (CADDR X))
(TERPRI) (PRINC '|Please use |)
(PRINC (FULLSTRIP1 (CADR B)))
(PRINC '| in the function itself.|) NIL)
(T (RETURN (MPRINEVAL))))
(TERPRI) (PRINC '|Try again.|)))
(DEFUN ASSIGNCHKP (X)
(COND ((OR (EQ '$EXIT X) (EQ '$QUIT X)) (PRIMER-EXIT))
((EQ '$NO X)
(TERPRI) (PRINC '|O.K., I'll do it for you.|)
(MACSYMA '((MSETQ) $A 3)) 'NOLABEL)
((NOT (EQ 'MSETQ (CAAR X)))
(TERPRI) (PRINC '|Not an assignment.|) NIL)
((NOT (EQ '$A (CADR X)))
(TERPRI) (PRINC '|Please use A.|) NIL)
((NOT (MNUMP (CADDR X)))
(COND ((NOT (EQ 'MMINUS (CAR (CAADDR X))))
(TERPRI) (PRINC '|Please assign a number value.|) NIL)
(T T)))
(T T)))
(DEFUN CHKEXONEP (X)
(COND ((OR (EQ '$EXIT X) (EQ '$QUIT X)) (PRIMER-EXIT))
((EQ '$NO X)
(TERPRI) (PRINC '|O.K., I'll do it for you.|)
(MACSYMA EXAMPLE1) 'NOLABEL)
((ATOM X)
(TERPRI) (PRINC '|Oops, you typed the ; too soon.|) NIL)
((EQ 'MPLUS (CAAR X))
(TERPRI) (PRINC '|The X+1 should be in parentheses.|) NIL)
((EQ 'MTIMES (CAAR X))
(TERPRI) (PRINC '|Use ^ or two asterisks for exponentiation.|) NIL)
((NOT (MNUMP (CADDR X)))
(TERPRI) (PRINC '|Use a small positive number for the exponent, please.|) NIL)
((AND (MNUMP (CADDR X)) (GREATERP (CADDR X) 6))
(TERPRI) (PRINC '|MACSYMA will only expand up to the value|)
(TERPRI) (PRINC '|of MAXPOSEX or MAXNEGEX. Their initial|)
(TERPRI) (PRINC '|value is 6.|) NIL)
((NOT (PALIKE EXAMPLE1 X)) NIL)
(T T)))
(DEFUN POLYCHK (A)
((LAMBDA (VAR)
(COND ((OR (EQ '$EXIT A) (EQ '$QUIT A)) (PRIMER-EXIT))
((EQ '$NO A)
(TERPRI) (PRINC '|O.K., we'll use this one.|)
(DISPLA (POWER PRAC-EXAMPLE1 2))
(MACSYMA (POWER PRAC-EXAMPLE1 2)) 'NOLABEL)
((ATOM A)
(TERPRI) (PRINC '|That polynomial won't be very interesting.|)
(TERPRI) (PRINC '|Let's use |)
(DISPLA (POWER PRAC-EXAMPLE1 2))
(MACSYMA (POWER PRAC-EXAMPLE1 2)) 'NOLABEL)
((MEMQ (CAAR A) '(MPLUS MTIMES))
(TERPRI) (PRINC '|Ok, to make that a bit more interesting,|)
(TERPRI) (PRINC '|let's square it.|)
(MACSYMA (POWER A 2)) 'NOLABEL)
((EQ (CAAR A) 'MEXPT)
(COND ((ATOM (CADR A))
(TERPRI) (PRINC '|That polynomial won't be very interesting.|)
(TERPRI) (PRINC '|Let's use |)
(DISPLA (POWER PRAC-EXAMPLE1 2))
(MACSYMA (POWER PRAC-EXAMPLE1 2)) 'NOLABEL)
((FREE (CADR A) VAR)
(FREE (CADDR A) VAR))
(T (AND (FIXP (CADDR A))
(GREATERP (CADDR A) 0.)
(POLYP (CADR A))))))
((EQ (CAAR A) 'MDEFINE)
(TERPRI) (PRINC '|It isn't necessary to define it as a function.|) NIL)
((NOT (MEMQ (CAAR A)'(MPLUS MTIMES MEXPT)))
(TERPRI) (PRINC '|Oops.|) NIL)
(T T))) '$X))
(DEFUN VALUEP (X)
(COND ((OR (EQ '$EXIT X) (EQ '$QUIT X)) (PRIMER-EXIT))
((EQ '$NO X)
(TERPRI) (PRINC '|O.K., I'll do it for you.|)
(MACSYMA '(($F) 3)) 'NOLABEL)
((NOT (EQ (CAAR X) '$F))
(TERPRI) (PRINC '|Oops, wrong function name.|) NIL)
((NOT (OR (MMMINUSP (CADR X)) (MNUMP (CADR X))))
(TERPRI) (PRINC '|Please use a number for the value.|) NIL)
(T T)))
(DEFUN SUBEXAMPLE1 (X)
(COND ((OR (EQ '$EXIT X) (EQ '$QUIT X)) (PRIMER-EXIT))
((EQ '$NO X)
(TERPRI) (PRINC '|O.K. I'll do it for you.|)
(MACSYMA '(($SUBSTITUTE) 1 ((MPLUS) ((MEXPT) ((%SIN) $X) 2)
((MEXPT) ((%COS) $X) 2)) $%))
'NOLABEL)
((ATOM X)
(TERPRI) (PRINC '|Oops, you typed the ; too soon.|) NIL)
((OR (EQUAL '(($SUBSTITUTE) 1 ((MPLUS) ((MEXPT) ((%SIN) $X) 2)
((MEXPT) ((%COS) $X) 2)) $%)
X)
(EQUAL '(($SUBSTITUTE) ((MPLUS) 1 ((MMINUS)
((MEXPT) ((%SIN) $X) 2)))
((MEXPT) ((%COS) $X) 2) $%) X)
(EQUAL '(($SUBSTITUTE) ((MPLUS) 1 ((MMINUS)
((MEXPT) ((%COS) $X) 2)))
((MEXPT) ((%SIN) $X) 2) $%) X)))
((NOT (EQ '$SUBSTITUTE (CAAR X)))
(TERPRI) (PRINC '|That should be SUBST.|) NIL)
(T (SUBCHK X))))
(DEFUN SUBEXAMPLE2 (X)
(COND ((OR (EQ '$EXIT X) (EQ '$QUIT X)) (PRIMER-EXIT))
((EQ '$NO X)
(TERPRI) (PRINC '|O.K. I'll do it for you.|)
(MACSYMA '(($RATSUBST) 1 ((MPLUS) ((MEXPT) ((%SIN) $X) 2)
((MEXPT) ((%COS) $X) 2)) $%))
'NOLABEL)
((ATOM X)
(TERPRI) (PRINC '|Oops, you typed the ; too soon.|) NIL)
((OR (EQUAL '(($RATSUBST) 1 ((MPLUS) ((MEXPT) ((%SIN) $X) 2)
((MEXPT) ((%COS) $X) 2)) $%)
X)
(EQUAL '(($RATSUBST) ((MPLUS) 1 ((MMINUS)
((MEXPT) ((%SIN) $X) 2)))
((MEXPT) ((%COS) $X) 2) $%) X)
(EQUAL '(($RATSUBST) ((MPLUS) 1 ((MMINUS)
((MEXPT) ((%COS) $X) 2)))
((MEXPT) ((%SIN) $X) 2) $%) X)))
((NOT (EQ '$RATSUBST (CAAR X)))
(TERPRI) (PRINC '|That should be RATSUBST.|) NIL)
(T (SUBCHK X))))
(DEFUN SUBCHK (X)
(COND ((EQUAL 1 (CADR X))
(COND ((NOT (EQUAL '((MPLUS) ((MEXPT) ((%SIN) $X) 2)
((MEXPT) ((%COS) $X) 2))
(CADDR X)))
(TERPRI) (PRINC '|The thing you are substituting for |)
(TERPRI) (PRINC '|should be SIN(X)^2+COS(X)^2 for this method.|) NIL)
(T T)))
((EQUAL '((MPLUS) 1 ((MMINUS) ((MEXPT) ((%SIN) $X) 2))) (CADR X))
(COND ((NOT (EQUAL '((MEXPT) ((%COS) $X) 2) (CADDR X)))
(TERPRI) (PRINC '|The thing you are substituting for |)
(TERPRI) (PRINC '|should be COS(X)^2 for this method.|) NIL)
(T T)))
((EQUAL '((MPLUS) 1 ((MMINUS) ((MEXPT) ((%COS) $X) 2))) (CADR X))
(COND ((NOT (EQUAL '((MEXPT) ((%SIN) $X) 2) (CADDR X)))
(TERPRI) (PRINC '|The thing you are substituting for |)
(TERPRI) (PRINC '|should be SIN(X)^2 for this method.|) NIL)
(T T)))
((NOT (MEMBER (CADR X)
'(1 ((MPLUS) 1 ((MMINUS) ((MEXPT) ((%COS) $X) 2)))
((MPLUS) 1 ((MMINUS) ((MEXPT) ((%SIN) $X) 2))) )))
(TERPRI) (PRINC '|Use 1, 1-SIN(X)^2, or 1-COS(X)^2 as something|)
(TERPRI) (PRINC '|to substitute in.|) NIL)
((NOT (EQ (CADDDR X) DLABEL))
(TERPRI) (PRINC '|Use % or check your D-line number.|) NIL)
(T NIL)))
(DEFUN CHKRADCAN (X)
(COND ((OR (EQ '$EXIT X) (EQ '$QUIT X)) (PRIMER-EXIT))
((EQ '$NO X)
(TERPRI) (PRINC '|O.K.,I'll do it for you.|)
(MACSYMA RADCANEXAMPLE) 'NOLABEL)
((ATOM X)
(TERPRI) (PRINC '|Oops, you typed the ; too soon.|) NIL)
((NOT (ISITIN '%LOG X))
(TERPRI) (PRINC '|The word LOG is used just like that.|) NIL)
((NOT (PALIKE RADCANEXAMPLE X)) NIL)
(T T)))
(DEFUN PE2CHK (X)
(COND ((OR (EQ '$EXIT X) (EQ '$QUIT X)) (PRIMER-EXIT))
((EQ '$NO X)
(TERPRI) (PRINC '|O.K.,I'll do it for you.|)
(MACSYMA PRAC-EXAMPLE2) 'NOLABEL)
((ATOM X)
(TERPRI) (PRINC '|Oops, you typed the ; too soon.|) NIL)
((PALIKE '((MEXPT) ((MPLUS) ((MEXPT) $X 2) 3) ((MMINUS) 1))
X))
((NOT (PALIKE PRAC-EXAMPLE2 X)) NIL)
(T T)))
(DEFUN DOITYOURSELF (X)
(COND ((OR (EQ '$EXIT X) (EQ '$QUIT X)) (PRIMER-EXIT))
((EQ '$NO X)
(TERPRI) (PRINC '|O.K., never mind.|) 'NOLABEL)
((NULL X)
(TERPRI) (PRINC '|Oops, that wasn't much of an expression.|)
(TERPRI) (PRINC CLABEL) NIL)
(T T)))
(DEFUN SYNCHK (FUN PAT)
(DO ((X (MREAD) (MREAD))) (NIL)
(COND ((OR (EQ '$EXIT X) (EQ '$QUIT X)) (PRIMER-EXIT))
((EQ '$NO X)
(TERPRI) (PRINC '|O.K., I'll show you.|)
(DISPLA PAT)
(RETURN (MACSYMA PAT)) 'NOLABEL)
((SYNCHK2 FUN PAT X) (RETURN (MPRINEVAL)))
(T (TERPRI) (PRINC '|Try again.|)))))
(DEFUN SYNCHK2 (FUN PAT X)
(COND ((ATOM X)
(COND ((EQ (GETOP (CAR FUN)) X)
(TERPRI) (PRINC '|Oops, that was just |)
(MGRIND (GETOP (CAR FUN)) NIL)
(PRINC '|, try|)
(PRINC (FULLSTRIP1 PAT)) NIL)
((NUMBERP X)
(TERPRI) (PRINC '|Oops, that was just a number, what about |)
(MGRIND (GETOP (CAR FUN)) NIL)
(PRINC '|/?|) NIL)
(T (TERPRI) (PRINC '|Oops, you typed the ; too soon.|))) NIL)
((NOT (PALIKE PAT X)) NIL)
(T T)))
(DEFUN PARTCHK (CMD PAT)
(DO ((X (MREAD) (MREAD))) (NIL)
(COND ((ATOM X)
(TERPRI) (PRINC '|Aw, come on, this is easy.|) NIL)
((NOT (EQ CMD (CAAR X)))
(COND ((MEMQ (CAR (PLIST (CAAR X))) '(SUBR LSUBR EXPR FEXPR))
(TERPRI) (PRINC '|Please use the |)
(PRINC (FULLSTRIP1 CMD))
(PRINC '| command.|))
(T (TERPRI) (PRINC '|Check your spelling.|))) NIL)
((EQ '$END (MEVAL X))
(TERPRI) (PRINC '|Whoops, that "PART" is off the end of the expression.|) NIL)
((PALIKE PAT (MPRINEVAL)) (RETURN T)))
(TERPRI) (PRINC '|Try again.|) (TERPRI)))

View File

@@ -1,297 +0,0 @@
;;;-*-lisp-*-
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;To run this primer interpreted, the following files must be LOADFILED into ;;
;;MACSYMA: MRG;MACROS FASL, ELLEN;CHECK >, ELLEN;SCRIPT >, and this file. ;;
;;I do not recommend doing that, however. -Ellen ;;
;;(C) Copyright 1979, Massachusetts Institute of Technology ;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(DECLARE (SPECIAL CLABEL DLABEL NSP TB LP RP SCRIPTINDEX LISPREADTABLE
$% $LABELS $LINENUM $INCHAR $OUTCHAR
LINEL GCT $SHOWTIME $LASTTIME)
(UNSPECIAL *)
(*EXPR MEVAL STRIPDOLLAR DISPLA MGRIND MAKSTRING ADD2LNC RETRIEVE)
(*FEXPR $LOADFILE) (FASLOAD MACROS FASL DSK MRG))
(DECLARE (EVAL (READ)))
(SETSYNTAX '/# 'MACRO 'TYI)
(SETSYNTAX '/" 'MACRO 'READTEXT)
(DEFUN READTEXT ()
(LAMBIND ((READTABLE (GET 'PRIMER 'ARRAY)))
(DO ((S (READ) (READ)) (NL)) ((EQ '/" S) `(TEXT ',(NREVERSE NL)))
(SETQ NL (CONS S NL))
(IF (EQ '/@ S)
(LAMBIND ((READTABLE LISPREADTABLE)) (SETQ NL (CONS (READ) NL)))))))
(SETSYNTAX #~ 'MACRO 'NOFILL)
(DEFUN NOFILL ()
(DO ((C (TYI) (TYI)) (CL))
((= #~ C) `(PRINC ',(MAKNAM (NREVERSE CL))))
(SETQ CL (CONS C CL))))
(*ARRAY 'PRIMER 'READTABLE T)
(LAMBIND ((READTABLE (GET 'PRIMER 'ARRAY)))
(DO I ## (1+ I) (> I #@) (SETSYNTAX I 1 I))
(DO I #a (1+ I) (> I #z) (SETSYNTAX I 1 I))
(SETSYNTAX #` 'SINGLE #`)
(SETSYNTAX #@ 'SINGLE #@)
(SETSYNTAX #" 'SINGLE #"))
(DECLARE (COUTPUT (READ)))
(DEFUN IF MACRO (X)
(COND ((NULL (CDDDR X)) `(COND (,(CADR X) ,(CADDR X))))
(T `(COND (,(CADR X) ,(CADDR X)) (T . ,(CDDDR X))))))
(SETQ LISPREADTABLE READTABLE
SCRIPTINDEX '(($INTRO (SCRIPT INTRO DSK ELLEN)(CHECK FASL DSK ELLEN))
($CONSOLEPRIMER (SCRIPT INTRO DSK ELLEN)
(CHECK FASL DSK ELLEN))
($HELP (SCRIPT INTRO DSK ELLEN)(CHECK FASL DSK ELLEN))
($SYNTAX (SCRIPT INTRO DSK ELLEN)(CHECK FASL DSK ELLEN))
($SIMPLIFICATION (SCRIPT INTRO DSK ELLEN)
(CHECK FASL DSK ELLEN))
($SCRATCHPAD (SCRIPT INTRO DSK ELLEN)
(CHECK FASL DSK ELLEN))
($ASSIGNMENT (SCRIPT AUX DSK ELLEN)
(CHECK FASL DSK ELLEN))
($FILING (SCRIPT AUX DSK ELLEN)
(CHECK FASL DSK ELLEN))
($STRINGCOMMANDS (SCRIPT AUX DSK ELLEN)
(CHECK FASL DSK ELLEN))
($MATRICES (SCRIPT MATRIX DSK ELLEN)
(CHECK FASL DSK ELLEN))
($SHARE (SHARE SCRIPT DSK ELLEN))
($ABSIMP (SHARE SCRIPT DSK ELLEN))
($ROMBER (SHARE SCRIPT DSK ELLEN))
($FFT (SHARE SCRIPT DSK ELLEN))
($DESOLN (SHARE SCRIPT DSK ELLEN))
($UNITS (SHARE SCRIPT DSK ELLEN))
($ARRAY (SHARE SCRIPT DSK ELLEN))
($DIMEN (SHARE SCRIPT DSK ELLEN))
($DUMP (SHARE SCRIPT DSK ELLEN))
($FACT (SHARE SCRIPT DSK ELLEN))
($INTPOL (SHARE SCRIPT DSK ELLEN))
($MATCH (MATCH SCRIPT DSK MRG))))
(DEFUN $PRIMER FEXPR (X)
(SETQ X (COND (X (CAR X))
((SEENP (STATUS UNAME) '$CONSOLEPRIMER) '$HELP)
(T '$CONSOLEPRIMER)))
(*CATCH 'PQUIT (SCRIPT X T))
'$DONE)
(DEFUN SEENP (USER SC)
(PROGB (IN)
(SETQ IN (OPEN '(USER PROFIL DSK ALJABR) 'IN))
(DO ((U (READ IN 'EOF) (READ IN 'EOF))) ((EQ U 'EOF) (CLOSE IN) NIL)
(COND ((EQ USER (CAR U)) (CLOSE IN) (RETURN (MEMQ SC (CDR U))))))))
(DEFUN SEEN (USER SC)
(PROGB (IN OUT)
(SETQ IN (OPEN '(USER PROFIL DSK ALJABR) 'IN)
OUT (OPEN '(USER PROFIL DSK ALJABR) 'OUT))
(DO ((U (READ IN NIL) (READ IN NIL)) (SUCCESS))
((NULL U) (IFN SUCCESS (PRINT (LIST USER SC) OUT)))
(IFN (EQ USER (CAR U)) T (SETQ SUCCESS T) (RPLACD U (CONS SC (CDR U))))
(PRINT U OUT))
(CLOSE IN) (CLOSE OUT)))
(DEFUN SCRIPT (SC TOP)
(SETQ SC (GETSCRIPT SC TOP))
(*CATCH 'EXIT (DO () ((NULL SC)) (TERPRI) (EVAL (CAR SC))
(SETQ SC (CDR SC)))))
(DEFUN GETSCRIPT (SC TOP)
(PROGB (*)
(COND ((GET SC 'SCRIPT))
((AND (SETQ * (CDR (ASSQ SC SCRIPTINDEX)))
(DO ((L * (CDR L))) ((NULL L) T)
(APPLY '$LOADFILE (CAR L)))
(GET SC 'SCRIPT)))
(T (TERPRI) (PRINC '|No such script.|) (COND (TOP (ERR)))))))
(DEFUN TEXT (L)
(TERPRI) (TYO TB)
(DO ((X) (W) (WD 8)) ((NULL L)) (DECLARE (FIXNUM W WD))
(IF (NOT (EQ '/@ (CAR L))) (SETQ X (CAR L) W (FLATC X))
(SETQ L (CDR L) X (STRGRIND (EVAL (CAR L))) W (LENGTH X)))
(COND ((>= (+ 3 W WD) LINEL) (TERPRI) (SETQ WD 0)))
(IF (ATOM X) (PRINC X) (MAPC 'TYO X)) (TYO NSP)
(SETQ L (CDR L) WD (+ 1 W WD))))
(DEFUN EXIT () (*THROW 'EXIT NIL))
(DEFUN PQUIT () (*THROW 'PQUIT NIL))
(DEFUN YESORNO ()
(TERPRI)
(DO ANS (RETRIEVE NIL NIL) (RETRIEVE NIL NIL) NIL
(COND ((MEMQ ANS '($YES $YEP $YEAH $Y $YUP $SURE $OK $T)) (RETURN T))
((MEMQ ANS '($NO $N $NOPE $NIL)) (RETURN NIL))
(T (PRINC '|Was that a YES or a NO?|)
(TERPRI)))))
(DEFUN MREAD ()
(SETQ CLABEL (MAKLABEL $INCHAR $LINENUM)) (ADD2LNC CLABEL $LABELS)
(TERPRI) (PRLABEL CLABEL) (SET CLABEL (RETRIEVE NIL NIL)))
(DEFUN MPRINEVAL ()
(PROGB (TIME)
(SETQ TIME (RUNTIME) GCT (STATUS GCTIME) $% (MEVAL (EVAL CLABEL)))
(SETQ DLABEL (MAKLABEL $OUTCHAR $LINENUM)) (ADD2LNC DLABEL $LABELS)
(DISPLA `((MLABLE) ,DLABEL ,(SET DLABEL $%)))
(SETQ $LASTTIME (LIST '(MLIST SIMP)
(COMPUTIME (RUNTIME) TIME)
(COMPUTIME (STATUS GCTIME) GCT)))
(COND ($SHOWTIME (IF (NOT (ZEROP (CHARPOS T))) (TERPRI))
(PRINC '|time=|) (PRINC (CADR $LASTTIME)) (PRINC '| msec.|)
(TERPRI)))
(SETQ $LINENUM (1+ $LINENUM))
$%))
(DEFUN MACSYMA (FORM)
(SETQ CLABEL (MAKLABEL $INCHAR $LINENUM)) (ADD2LNC CLABEL $LABELS)
(TERPRI) (PRLABEL CLABEL) (MAPC 'PRINC (MAKSTRING FORM)) (TYO #;)
(SET CLABEL FORM) (MPRINEVAL))
(DEFUN MAKLABEL (C N) (IMPLODE (NCONC (EXPLODEN C) (EXPLODEN N))))
(DEFUN PRLABEL (L) (PRINC '|(|) (PRINC (STRIPDOLLAR L)) (PRINC '|) |))
(DEFUN CLINE (X)
(TERPRI)
(TYO TB)
(MGRIND X T)) ;MGRIND take OUTPUT file as 2nd arg -- RWK
(DEFUN CENTER (X) (DISPLA (LIST '(MLABLE) NIL X)))
(DEFUN DEFSCRIPT FEXPR (F) (PUT (CAR F) (CDR F) 'SCRIPT) (CAR F))
(DEFUN MACSYM ()
(DO ((X)) ((NOT (ATOM X)) (CAR X))
(MREAD) (SETQ X (ERRSET (MPRINEVAL)))))
(DEFUN INCHK (PAT)
(DO ((X (MREAD) (MREAD))) (NIL)
(COND ((OR (EQ '$EXIT X)(EQ '$QUIT X))
(EXIT))
((EQ '$NO X)
(TERPRI) (PRINC '|O.K., I'll do it for you.|)
(RETURN (MACSYMA PAT)))
((PALIKE PAT X) (RETURN (MPRINEVAL)))
(T (TERPRI) (PRINC '|Try again.|) (TERPRI)))))
(DEFUN OUTCHK (PAT)
(DO X (MACSYM) (MACSYM) (PALIKE PAT X)
(TERPRI) (PRINC '|Try again.|) (TERPRI)))
(DEFUN INCHKP (P)
(DO ((X (MREAD) (MREAD))(Y)) (NIL)
(IF (SETQ Y (FUNCALL P X)) (RETURN (COND ((NOT (EQ Y 'NOLABEL))
(MPRINEVAL))))
(TERPRI) (PRINC '|Try again.|))))
(DEFUN OUTCHK2 (PRED)
(DO X (MACSYM)(MACSYM)
(COND ((OR (EQ '$EXIT X) (EQ '$QUIT X)) (EXIT))
((EQ '$NO X))
((FUNCALL PRED X)))
(TERPRI) (PRINC '|Try again.|) (TERPRI)))
(DEFUN PALIKE (PAT X)
(COND ((EQ PAT X))
((EQ 'DLABEL PAT) (PALIKE DLABEL X))
((ATOM PAT) (AND (ATOM X) (EQUAL (MEVAL PAT) (MEVAL X))))
((ATOM X) NIL)
((EQ (CAAR PAT) (CAAR X))
(SETQ PAT (CDR PAT) X (CDR X))
(DO () ((NOT (PALIKE (CAR PAT) (CAR X))))
(COND ((NULL PAT) (IF (NULL X) (RETURN T)))
((NULL X) (RETURN NIL))
(T (SETQ PAT (CDR PAT) X (CDR X))))))))
(DEFUN DECODE (X L)
(COND ((NOT (EQ (TYPEP X) 'FIXNUM)) (NOR-ERR))
((OR (NOT (> X 0)) (> X (LENGTH L))) (NOR-ERR))
((SETQ X (NTHCDR (1- X) L)) (CAR X))
(T (NOR-ERR))))
(DEFUN SPELLCHECK (X L)
(COND ((NOT (ISITIN X L)) (SPELL-ERR))
(T X)))
(DEFUN MENU (OPTS)
(DO ((L OPTS (CDR L)) (I 1 (1+ I))) ((NULL L))
(PRINC I) (PRINC '| - |) (PRINC (FULLSTRIP1 (CAR L)))
(COND ((GET (CAR L) 'KIND) (TYO NSP) (PRINC (GET (CAR L) 'KIND))))
(TERPRI)))
(DEFUN SPELL-ERR () (PRINC '|No such script. Try again.|) (TERPRI))
(DEFUN OPT-ERR () (PRINC '|Illegal command to OPTIONS|) (TERPRI))
(DEFUN NOR-ERR () (PRINC '|Number out of range|) (TERPRI))
(DEFUN SELECT (L) (IF (EQ '$EXIT (SETQ L (SELECT1 L))) (PQUIT) (SCRIPT L NIL)))
(DEFUN SELECT1 (L)
(DO ((ANS)) (NIL)
(MENU L)
(SETQ ANS (RETRIEVE NIL NIL))
(COND ((FIXP ANS) (IF (SETQ ANS (DECODE ANS L)) (RETURN ANS)))
((ATOM ANS) (IF (SETQ ANS (SPELLCHECK ANS L))(RETURN ANS))))))
(DEFUN CMDCHKP (CMD)
(DO ((X (MREAD) (MREAD))) (NIL)
(COND ((OR (EQ '$EXIT X)(EQ '$QUIT X))
(EXIT))
((EQ '$NO X)
(TERPRI) (PRINC '|O.K., I'll do it for you.|)
(RETURN (MACSYMA CMD)))
((CMDCHKP2 CMD X)(RETURN (MPRINEVAL)))
(T (TERPRI) (PRINC '|Try again.|)))))
(DEFUN CMDCHKP2 (C D)
(COND ((ATOM D)
(TERPRI) (PRINC '|Oops, you typed the ; too soon.|) NIL)
((NOT (EQ (CAAR C)(CAAR D)))
(CMDCHKP3 (CAAR D)(CAAR C)) NIL)
((EQ '$% (CADR D)))
((NOT (EQUAL (CADR C)(CADR D)))
(TERPRI) (PRINC '|Use |)
(PRINC (FULLSTRIP1 (CADR C))) NIL)
((NOT (PALIKE C D)) NIL)
(T T)))
(DEFUN CMDCHKP3 (E C)
(COND ((MEMQ (CAR (PLIST E)) '(SUBR LSUBR EXPR FEXPR))
(TERPRI)(PRINC '|Please use the |)
(PRINC (FULLSTRIP1 C))
(PRINC '| command.|))
(T (TERPRI) (PRINC '|Check your spelling.|))))
(DEFUN INOUTCHK (CMD PAT)
(DO ((X (MREAD) (MREAD))) (NIL)
(COND ((ATOM X)
(TERPRI) (PRINC '|Aw, come on, this is easy.|) NIL)
((NOT (EQ CMD (CAAR X)))
(COND ((MEMQ (CAR (PLIST (CAAR X))) '(SUBR LSUBR EXPR FEXPR))
(TERPRI)(PRINC '|Please use the |)
(PRINC (FULLSTRIP1 CMD))
(PRINC '| command.|))
(T (TERPRI) (PRINC '|Check your spelling.|))) NIL)
((PALIKE PAT (MPRINEVAL))(RETURN T)))
(TERPRI) (PRINC '|Try again.|)(TERPRI)))
(DEFUN ISITIN (A L)
(COND ((ATOM L) (EQ A L))
(T (DO () ((NULL L) NIL)
(COND ((ISITIN A (CAR L)) (RETURN T))
(T (SETQ L (CDR L))))))))

481
src/ellen/primer.239 Normal file
View File

@@ -0,0 +1,481 @@
;; -*- Mode: Lisp; Package: Macsyma; -*-
;; (c) Copyright 1976, 1984 Massachusetts Institute of Technology
;; All Rights Reserved.
;; Enhancements (c) Copyright 1984 Symbolics Inc.
;; All Rights Reserved.
;; The data and information in the Enhancements are proprietary to, and
;; a valuable trade secret of, SYMBOLICS, INC., a Delaware corporation.
;; They are given in confidence by SYMBOLICS, pursuant to the license
;; agreement between Symbolics and their recipient, and may not be used,
;; reproduced, or copied, or distributed to any other party, in whole or
;; in part, without the prior written consent of SYMBOLICS except as
;; permitted by the license agreement.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;To run this primer interpreted, the following files must be LOADFILED into ;;
;;MACSYMA: ELLEN;CHECK >, ELLEN;SCRIPT >, and this file. ;;
;;I do not recommend doing that, however. -Ellen ;;
;;(C) Copyright 1983, Massachusetts Institute of Technology ;;
;; Enhancements (c) 1983, Symbolics, Inc. All Rights Reserved.
;; The data and information in the Enhancements is proprietary
;; to, and a valuable trade secret of, SYMBOLICS, INC., a
;; Delaware corporation. It is given in confidence by
;; SYMBOLICS, and may not be used as the basis of manufacture,
;; or be reproduced or copied, or distributed to any other
;; party, in whole or in part, without the prior written
;; consent of SYMBOLICS.
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
(macsyma-module primer)
(load-macsyma-macros mrgmac)
(DECLARE (SPECIAL CLABEL DLABEL $% $LABELS $LINENUM $INCHAR $OUTCHAR
LINEL GCT $SHOWTIME $LASTTIME $LOADPRINT $DYNAMALLOC)
(UNSPECIAL *)
(special readtable)
(*EXPR MEVAL STRIPDOLLAR DISPLA MGRIND MAKSTRING ADD2LNC RETRIEVE)
)
;; The primer works by interpreting script files at runtime, and a special
;; syntax is used for parsing them. Part of it is kept in the primer
;; readtable, and some is done via readmacro characters. The macro characters
;; will clobber the global Macsyma syntax, so don't expect to debug anything
;; with the primer loaded. We wouldn't lose so badly if macro characters were
;; per-readtable.
(DEFVAR LISP-READTABLE READTABLE)
(DEFVAR PRIMER-READTABLE #-Franz (*ARRAY NIL 'READTABLE T)
#+Franz (makereadtable nil))
#+Franz
(defvar vaxima-scr-dir (concat vaxima-main-dir "//ellen//"))
;; Text in a DEFSCRIPT form is parsed using the Lisp READ function, and is
;; enclosed in double quotes. An @ inside the string allows an evaluation of a
;; Lisp form at run time. Character translation is turned off and words are
;; read as symbols. A string of text is read as a list of symbols.
;; This is done to permit run-time justification of text to the
;; appropriate console width.
#-Franz
(SETSYNTAX #/" 'MACRO 'READTEXT)
(DEFUN READTEXT ()
(LET ((READTABLE PRIMER-READTABLE))
#+Franz (sstatus uctolc nil)
(DO ((S (READ) (READ)) (NL))
((EQ '/" S)
#+Franz (sstatus uctolc t)
`(TEXT ',(NREVERSE NL)))
(PUSH S NL)
(IF (EQ '/@ S)
(LET ((READTABLE LISP-READTABLE))
#+Franz (sstatus uctolc t)
(PUSH (READ) NL)
#+Franz (sstatus uctolc nil))))))
;; Why is ` a single character object?
#-Franz
(LET ((READTABLE PRIMER-READTABLE))
(DO I #/# (1+ I) (> I #/@) (SETSYNTAX I 1 I))
(DO I #/a (1+ I) (> I #/z) (SETSYNTAX I 1 I))
(SETSYNTAX #/` 'SINGLE #/`)
(SETSYNTAX #/@ 'SINGLE #/@)
(SETSYNTAX #/" 'SINGLE #/"))
#+Franz
(LET ((READTABLE PRIMER-READTABLE))
(DO I #/# (1+ I) (> I #/@) (SETSYNTAX I 'vcharacter))
(setsyntax #/` 'vsingle-character-symbol)
(setsyntax #/@ 'vsingle-character-symbol)
(setsyntax #/" 'vsingle-character-symbol))
;; This is for pieces of text which aren't supposed to be justified, i.e.
;; no-fill mode. Text bracketed with ~'s rather than "'s gets printed
;; directly. Newlines are printed between entries in a script.
#-Franz
(SETSYNTAX #/~ 'MACRO 'NOFILL)
(DEFUN NOFILL ()
(DO ((C (TYI) (TYI)) (CL))
((= #/~ C) `(PRINC ',(MAKNAM (NREVERSE CL))))
(SETQ CL (CONS C CL))))
;; This associates a given script with the file it is found in
;; and other files it needs to run. On bigger systems, just load
;; the scripts in when the primer file is loaded.
#-Franz
(DEFVAR SCRIPTINDEX '(($INTRO (SCRIPT INTRO DSK MACSYM)(CHECK FASL DSK MACSYM))
($CONSOLEPRIMER (SCRIPT BEGIN DSK MACSYM)
(CHECK FASL DSK MACSYM))
($HELP (SCRIPT INTRO DSK MACSYM)(CHECK FASL DSK MACSYM))
($SYNTAX (SCRIPT INTRO DSK MACSYM)(CHECK FASL DSK MACSYM))
($SIMPLIFICATION (SCRIPT INTRO DSK MACSYM)
(CHECK FASL DSK MACSYM))
($SCRATCHPAD (SCRIPT INTRO DSK MACSYM)
(CHECK FASL DSK MACSYM))
($ASSIGNMENT (SCRIPT AUX DSK MACSYM)
(CHECK FASL DSK MACSYM))
($FILING (SCRIPT AUX DSK MACSYM)
(CHECK FASL DSK MACSYM))
($STRINGCOMMANDS (SCRIPT AUX DSK MACSYM)
(CHECK FASL DSK MACSYM))
($MATRICES (SCRIPT MATRIX DSK MACSYM)
(CHECK FASL DSK MACSYM))
($SHARE (SHARE SCRIPT DSK MACSYM))
($ABSIMP (SHARE SCRIPT DSK MACSYM))
($ROMBER (SHARE SCRIPT DSK MACSYM))
($FFT (SHARE SCRIPT DSK MACSYM))
($DESOLN (SHARE SCRIPT DSK MACSYM))
($UNITS (SHARE SCRIPT DSK MACSYM))
($ARRAY (SHARE SCRIPT DSK MACSYM))
($DIMEN (SHARE SCRIPT DSK MACSYM))
($DUMP (SHARE SCRIPT DSK MACSYM))
($FACT (SHARE SCRIPT DSK MACSYM))
($INTPOL (SHARE SCRIPT DSK MACSYM))
))
#+Franz
(defvar scriptindex '(($intro intro)
($franzprimer begin)
($help intro)
($syntax intro)
($simplification intro)
($scratchpad intro)
($assignment aux)
($filing aux)
($stringcommands aux)
($matrices matrix)))
;; The top-level function. If this is the first time a user has run a script,
;; he/she is given the "console primer" and the fact that the console primer
;; has been seen is kept in a file. When the primer is run later by the same
;; user, the "help" script is run instead. Alternately, a script can be
;; specified by giving this function an argument.
#-Franz
(DEFMSPEC $PRIMER (X) (SETQ X (CDR X))
(LET (($LOADPRINT T) ($DYNAMALLOC T))
(SETQ X (COND (X (CAR X))
((SEENP (STATUS UNAME) '$CONSOLEPRIMER) '$HELP)
(T '$CONSOLEPRIMER)))
(*CATCH 'PQUIT (SCRIPT X T))
'$DONE))
#+Franz
(defmspec $primer (x)
(let ((quotsyn (getsyntax '/"))
(tildsyn (getsyntax '/~))
($loadprint t))
(setq x (cdr x)) ; remove (mlist)
(unwind-protect
(progn (setsyntax #/" 'macro 'readtext)
(setsyntax #/~ 'macro 'nofill)
(setq x (cond (x (car x))
((seenp (sys-user-id) '$franzprimer) '$help)
(t '$franzprimer)))
(*catch 'pquit (script x t))
'$done)
(progn (setsyntax #/" quotsyn)
(setsyntax #/~ tildsyn)))))
;; These manipulate the user profile data base.
#+Franz
(defun seenp (user sc)
(let ((in (concat vaxima-main-dir "//aljabr//user.pro")) res u)
(if (not (probef in))
(merror "user.pro file does not exist. please send a bug
note."))
(if
(null (setq res (errset
(progn
(setq in (infile in))
(setq u (read in nil))
(close in)
(do ((v u (cdr v)))
((null v) nil)
(cond ((eq user (caar v))
(return (memq sc (cdar v))))))))))
(merror "error while processing user.pro file.
Please send a bug note."))
(car res)))
#+Franz
(defun seen (user sc)
(let (in out u
(profilefile (concat vaxima-main-dir "//aljabr//user.pro")))
(if (not (probef profilefile))
(merror "user.pro file does not exist. please send a bug note."))
(if
(null (errset
(progn
(setq in (infile profilefile))
(setq u (read in nil))
(close in)
(do ((v u (cdr v)))
((null v)
(setq u (cons (list user sc) u)))
(if (eq user (caar v))
(return (rplacd (car v) (cons sc (cdar v))))))
(setq out (outfile profilefile))
(print u out)
(close out))))
(merror "error while processing user.pro file.
Please send a bug note."))))
#-Franz
(DEFUN SEENP (USER SC)
(LET ((IN '((DSK MACSYM) USER PROFIL)) RES)
(IF (NOT (PROBEF IN))
(MERROR "USER PROFIL file does not exist. Please send a bug
note."))
(IF
(NULL (SETQ RES (ERRSET
(PROG2
(SETQ IN (OPEN IN 'IN))
(DO ((U (READ IN 'EOF) (READ IN 'EOF)))
((EQ U 'EOF) (CLOSE IN) NIL)
(COND ((EQ USER (CAR U))
(CLOSE IN) (RETURN (MEMQ SC (CDR U))))))))))
(MERROR "Error while processing USER PROFIL file.
Please send a bug note."))
(CAR RES)))
#-Franz
(DEFUN SEEN (USER SC)
(LET (IN OUT)
(IF (NOT (PROBEF '(USER PROFIL DSK MACSYM)))
(MERROR "USER PROFIL file does not exist. Please send a bug note."))
(IF
(NULL (ERRSET
(PROGN
(SETQ IN (OPEN '(USER PROFIL DSK MACSYM) 'IN)
OUT (OPEN '(USER PROFIL DSK MACSYM) 'OUT))
(DO ((U (READ IN NIL) (READ IN NIL)) (SUCCESS))
((NULL U) (IFN SUCCESS (PRINT (LIST USER SC) OUT)))
(IFN (EQ USER (CAR U)) T (SETQ SUCCESS T)
(RPLACD U (CONS SC (CDR U))))
(PRINT U OUT))
(CLOSE IN) (CLOSE OUT))))
(MERROR "Error while processing USER PROFIL file.
Please send a bug note."))))
;; The script interpreter. The first argument to this function is the
;; symbol naming the script.
(DEFUN SCRIPT (SC TOP)
(SETQ SC (GETSCRIPT SC TOP))
(*CATCH 'EXIT (DO () ((NULL SC)) (TERPRI) (EVAL (CAR SC))
(SETQ SC (CDR SC)))))
(DEFUN GETSCRIPT (SC TOP)
(LET (*)
(COND ((GET SC 'SCRIPT))
((AND (SETQ * (CDR (ASSQ SC SCRIPTINDEX)))
(DO ((L * (CDR L))) ((NULL L) T)
#-Franz ($LOAD (NAMESTRING (CAR L)))
#+Franz ($load (concat vaxima-scr-dir (car l))))
(GET SC 'SCRIPT)))
(T (IF TOP
(MERROR "No such script.")
(MTELL "~%No such script."))
))))
(DEFUN TEXT (L)
#-Franz(TERPRI)
(TYO #\TAB)
(DO ((X) (W) (WD 8)) ((NULL L)) (DECLARE (FIXNUM W WD))
(IF (NOT (EQ '/@ (CAR L))) (SETQ X (CAR L) W (FLATC X))
(SETQ L (CDR L) X (STRGRIND (EVAL (CAR L))) W (LENGTH X)))
(COND ((>= (+ 3 W WD) LINEL) (TERPRI) (SETQ WD 0)))
(IF (ATOM X) (PRINC X) (MAPC 'TYO X)) (TYO #\SP)
(SETQ L (CDR L) WD (+ 1 W WD))))
(DEFUN PRIMER-EXIT () (*THROW 'EXIT NIL))
(DEFUN PQUIT () (*THROW 'PQUIT NIL))
(DEFUN YESORNO ()
(TERPRI)
(DO ANS (RETRIEVE NIL NIL) (RETRIEVE NIL NIL) NIL
(COND ((MEMQ ANS '($YES $YEP $YEAH $Y $YUP $SURE $OK $T)) (RETURN T))
((MEMQ ANS '($NO $N $NOPE $NIL)) (RETURN NIL))
(T (PRINC '|Was that a YES or a NO?|)
(TERPRI)))))
(DEFUN MREAD ()
(SETQ CLABEL (MAKLABEL $INCHAR $LINENUM)) (ADD2LNC CLABEL $LABELS)
(TERPRI) (PRLABEL CLABEL) (SET CLABEL (RETRIEVE NIL NIL)))
(DEFUN MPRINEVAL ()
(LET (TIME)
(SETQ TIME (RUNTIME) GCT (SYS-GCTIME) $% (MEVAL (EVAL CLABEL)))
(SETQ DLABEL (MAKLABEL $OUTCHAR $LINENUM)) (ADD2LNC DLABEL $LABELS)
(DISPLA `((MLABLE) ,DLABEL ,(SET DLABEL $%)))
(SETQ $LASTTIME (LIST '(MLIST SIMP)
(COMPUTIME (RUNTIME) TIME)
(COMPUTIME (SYS-GCTIME) GCT)))
(COND ($SHOWTIME (IF (NOT (ZEROP (CHARPOS T))) (TERPRI))
(PRINC '|time=|) (PRINC (CADR $LASTTIME)) (PRINC '| msec.|)
(TERPRI)))
(SETQ $LINENUM (1+ $LINENUM))
$%))
(DEFUN MACSYMA (FORM)
(SETQ CLABEL (MAKLABEL $INCHAR $LINENUM)) (ADD2LNC CLABEL $LABELS)
(TERPRI) (PRLABEL CLABEL) (MAPC 'PRINC (MAKSTRING FORM)) (TYO #/;)
(SET CLABEL FORM)
#+Franz (terpri)
(MPRINEVAL))
(DEFUN MAKLABEL (C N) #-LISPM (IMPLODE (NCONC (EXPLODEN C) (EXPLODEN N)))
#+LISPM (STRING-APPEND C N))
(DEFUN PRLABEL (L) (PRINC '|(|) (PRINC (STRIPDOLLAR L)) (PRINC '|) |))
;; This function is used in scripts. It will have to be changed before this
;; function is moved to Multics since it is a system function there.
(DEFUN PCLINE (X)
(TERPRI)
(TYO #\TAB)
(MGRIND X T)) ;MGRIND take OUTPUT file as 2nd arg -- RWK
(DEFUN CENTER (X) (DISPLA (LIST '(MLABLE) NIL X)))
;; A script is a list of forms which are kept on the property list of a symbol
;; naming the script. The forms are evaluated sequentially and thus dispatch
;; on the functions defined in this file.
(DEFUN DEFSCRIPT FEXPR (F) (PUT (CAR F) (CDR F) 'SCRIPT) (CAR F))
(DEFUN MACSYM ()
(DO ((X)) ((NOT (ATOM X)) (CAR X))
(MREAD) (SETQ X (ERRSET (MPRINEVAL)))))
(DEFUN INCHK (PAT)
(DO ((X (MREAD) (MREAD))) (NIL)
(COND ((OR (EQ '$EXIT X)(EQ '$QUIT X))
(PRIMER-EXIT))
((EQ '$NO X)
(TERPRI) (PRINC '|O.K., I'll do it for you.|)
(RETURN (MACSYMA PAT)))
((PALIKE PAT X) (RETURN (MPRINEVAL)))
(T (TERPRI) (PRINC '|Try again.|) (TERPRI)))))
(DEFUN OUTCHK (PAT)
(DO X (MACSYM) (MACSYM) (PALIKE PAT X)
(TERPRI) (PRINC '|Try again.|) (TERPRI)))
(DEFUN INCHKP (P)
(DO ((X (MREAD) (MREAD))(Y)) (NIL)
(IF (SETQ Y (FUNCALL P X)) (RETURN (COND ((NOT (EQ Y 'NOLABEL))
(MPRINEVAL))))
(TERPRI) (PRINC '|Try again.|))))
(DEFUN OUTCHK2 (PRED)
(DO X (MACSYM)(MACSYM)
(COND ((OR (EQ '$EXIT X) (EQ '$QUIT X)) (PRIMER-EXIT))
((EQ '$NO X))
((FUNCALL PRED X)))
(TERPRI) (PRINC '|Try again.|) (TERPRI)))
(DEFUN PALIKE (PAT X)
(COND ((EQ PAT X))
((EQ 'DLABEL PAT) (PALIKE DLABEL X))
((ATOM PAT) (AND (ATOM X) (EQUAL (MEVAL PAT) (MEVAL X))))
((ATOM X) NIL)
((EQ (CAAR PAT) (CAAR X))
(SETQ PAT (CDR PAT) X (CDR X))
(DO () ((NOT (PALIKE (CAR PAT) (CAR X))))
(COND ((NULL PAT) (IF (NULL X) (RETURN T)))
((NULL X) (RETURN NIL))
(T (SETQ PAT (CDR PAT) X (CDR X))))))))
(DEFUN DECODE (X L)
(COND ((NOT (EQ (TYPEP X) 'FIXNUM)) (NOR-ERR))
((OR (NOT (> X 0)) (> X (LENGTH L))) (NOR-ERR))
((SETQ X (NTHCDR (1- X) L)) (CAR X))
(T (NOR-ERR))))
(DEFUN SPELLCHECK (X L)
(COND ((NOT (ISITIN X L)) (SPELL-ERR))
(T X)))
(DEFUN MENU (OPTS)
(DO ((L OPTS (CDR L)) (I 1 (1+ I))) ((NULL L))
(PRINC I) (PRINC '| - |) (PRINC (FULLSTRIP1 (CAR L)))
(COND ((GET (CAR L) 'KIND) (TYO #\SP) (PRINC (GET (CAR L) 'KIND))))
(TERPRI)))
(DEFUN SPELL-ERR () (PRINC '|No such script. Try again.|) (TERPRI))
(DEFUN OPT-ERR () (PRINC '|Illegal command to OPTIONS|) (TERPRI))
(DEFUN NOR-ERR () (PRINC '|Number out of range|) (TERPRI))
(DEFUN PRIMER-SELECT (L)
(IF (EQ '$EXIT (SETQ L (SELECT1 L))) (PQUIT) (SCRIPT L NIL)))
(DEFUN SELECT1 (L)
(DO ((ANS)) (NIL)
(MENU L)
(SETQ ANS (RETRIEVE NIL NIL))
(COND ((FIXP ANS) (IF (SETQ ANS (DECODE ANS L)) (RETURN ANS)))
((ATOM ANS) (IF (SETQ ANS (SPELLCHECK ANS L))(RETURN ANS))))))
(DEFUN CMDCHKP (CMD)
(DO ((X (MREAD) (MREAD))) (NIL)
(COND ((OR (EQ '$EXIT X)(EQ '$QUIT X))
(PRIMER-EXIT))
((EQ '$NO X)
(TERPRI) (PRINC '|O.K., I'll do it for you.|)
(RETURN (MACSYMA CMD)))
((CMDCHKP2 CMD X)(RETURN (MPRINEVAL)))
(T (TERPRI) (PRINC '|Try again.|)))))
(DEFUN CMDCHKP2 (C D)
(COND ((ATOM D)
(TERPRI) (PRINC '|Oops, you typed the ; too soon.|) NIL)
((NOT (EQ (CAAR C)(CAAR D)))
(CMDCHKP3 (CAAR D)(CAAR C)) NIL)
((EQ '$% (CADR D)))
((NOT (EQUAL (CADR C)(CADR D)))
(TERPRI) (PRINC '|Use |)
(PRINC (FULLSTRIP1 (CADR C))) NIL)
((NOT (PALIKE C D)) NIL)
(T T)))
(DEFUN CMDCHKP3 (E C)
(COND ((MEMQ (CAR (PLIST E)) '(SUBR LSUBR EXPR FEXPR))
(TERPRI)(PRINC '|Please use the |)
(PRINC (FULLSTRIP1 C))
(PRINC '| command.|))
(T (TERPRI) (PRINC '|Check your spelling.|))))
(DEFUN INOUTCHK (CMD PAT)
(DO ((X (MREAD) (MREAD))) (NIL)
(COND ((ATOM X)
(TERPRI) (PRINC '|Aw, come on, this is easy.|) NIL)
((NOT (EQ CMD (CAAR X)))
(COND ((MEMQ (CAR (PLIST (CAAR X))) '(SUBR LSUBR EXPR FEXPR))
(TERPRI)(PRINC '|Please use the |)
(PRINC (FULLSTRIP1 CMD))
(PRINC '| command.|))
(T (TERPRI) (PRINC '|Check your spelling.|))) NIL)
((PALIKE PAT (MPRINEVAL))(RETURN T)))
(TERPRI) (PRINC '|Try again.|)(TERPRI)))
(DEFUN ISITIN (A L)
(COND ((ATOM L) (EQ A L))
(T (DO () ((NULL L) NIL)
(COND ((ISITIN A (CAR L)) (RETURN T))
(T (SETQ L (CDR L))))))))

562
src/ellen/script.intro Normal file
View File

@@ -0,0 +1,562 @@
;;; -*- Mode:LISP; Package:MACSYMA -*-
; ** (c) Copyright 1981 Massachusetts Institute of Technology **
(SETQ $LOADPRINT NIL)
;This shouldn't be needed any more --kmp
;(COND ((STATUS FEATURE MACLISP) (LOAD '((LISP)DEFMAX))))
(DEFUN IF MACRO (X)
(COND ((NULL (CDDDR X)) `(COND (,(CADR X) ,(CADDR X))))
(T `(COND (,(CADR X) ,(CADDR X)) (T . ,(CDDDR X))))))
(DEFSCRIPT $CONSOLEPRIMER
"Welcome to the MACSYMA Primer. This section of the Primer
is called the CONSOLEPRIMER because it is intended to be
used by people who have not had previous experience
interacting with a computer console."
(COND ((AND $PAGEPAUSE CURSORPOS)(SCRIPT 'CRTCONSOLE NIL)))
(SLEEP 2)
"You will notice that your console looks much like a typewriter, except
for having a few special keys. The two most important special
keys are the 'altmode' and the 'control' key. The 'altmode'
may be labeled 'alt', 'esc', '(sel)', or 'escape'. The 'control'
key may be labeled 'CTRL' or 'CNTL'. The altmode is used to
enter the MACSYMA editor. Do not attempt to use the editor while
you are in the Primer since it may tend to confuse you. A future
script will deal with editing. The control key is used in
the same fashion as the shift key on the typwriter, i.e. you hold
it down and type the character whose 'control' value you wish.
For example, to type control-Z, you would hold down the control
key and type a Z. Don't do that now, as control-Z is the control
character that will return you to top level when you are ready
to log out."
(SLEEP 2)
"The Primer will explain some of the aspects of MACSYMA to you and allow
you to try out various examples. Your responses to
the Primer must end with a semi-colon (;). That is the one
thing which the Primer cannot correct you on, since it will not
even see your response until you have typed the semi-colon. Thus
if nothing seems to be happening, check that you have typed the
semi-colon."
"In the Primer you should answer all questions the system asks. There
are three kinds of questions:"
"1. Questions you can answer with a yes or a no. You type the word
YES or the word NO followed immediately by a semi-colon (;) to
answer these. Case does not matter, upper or lower will do.
Try it here: Type YES; or NO;"
(IF (YESORNO) (TERPRI))
"2. Questions which require you to select a script or an option. The system
will print out a list, for example:"
(MENU '($SIMPLIFICATION $SCRATCHPAD $ASSIGNMENT))
"This list is called the 'menu', the list of scripts available.
You select a script to see by typing the number of your choice
followed by a semi-colon (;), to answer these. E.g."
"3;"
"Now you try it."
(MENU '($SIMPLIFICATION $SCRATCHPAD $ASSIGNMENT))
(NUMCHK 3)
"3. Requests to type in commands to MACSYMA. The system will make a
request, such as 'Type in a polynomial in X,' and then give you
a dummy MACSYMA command line number. You then type the command,
followed by a semi-colon. This is to give you a chance to practice
what you are learning. If you type the command correctly, the
system will pass what you type to MACSYMA, and MACSYMA will
evaluate it and return a response. If you make a mistake the
system will attempt to tell you what you did wrong, and will
offer you a chance to try again. Here, try typing X+2;"
(INCHK '((MPLUS) $X 2))
"The response, as you see, is just the expression itself, since
no simplification or operation was necessary or specified."
"Do you know how to type 'control-characters'?"
(IF (NOT (YESORNO)) (SCRIPT 'CTRLCHAR NIL))
"Control-G is the QUIT command for MACSYMA."
"The other control characters you should know about for MACSYMA are:"
"Control-L: this reprints the command line you are typing. On a display
console it will also clear the screen. It is particularly useful
if you have used rubout (delete) a lot and want to verify that you
have everything right."
"Control-^: this will put you into LISP, the language MACSYMA is written in.
You will not usually want to use it, but should know about it so
you can avoid typing it. If you do type it by mistake, control-G
will get you back to a MACSYMA command line."
"Control-A: this enters a MACSYMA break. This suspends the current
computation, and allows you to 'poke around' in your MACSYMA,
perhaps to open a file for output, or to see what the value of
some variable is. To get out of the 'break' and resume the
computation, type 'exit;'"
"Control-]: this prints out the time used by the computation so far.
You can type it at any point during a computation. Try it now to
see how much CPU time this PRIMER session has used:"
(SLEEP 8)
"Now you are ready to move along to the Introductory Script of the Primer."
(COND ((EQ 'WSMR (STATUS UNAME))(SCRIPT '$INTRO NIL))
(T (SEEN (STATUS UNAME) '$CONSOLEPRIMER)))
(SCRIPT '$INTRO NIL))
(DEFSCRIPT $INTRO
"Welcome to the MACSYMA Primer. This is the script called INTRO."
"Please terminate responses to all questions with a semi-colon (;).
You may delete any characters you have typed by using
the delete or rub-out key on your console. The deleted
character will be erased if you are using a display terminal.
If you are using a printing terminal, it will be
typed back so you know what has been deleted."
"If you do not understand how to type an expression, or have tried
several times and wish to give up, you may type NO; and the
PRIMER will show you the correct way to do it."
"In this PRIMER session, after an optional introduction to
MACSYMA syntax, a few of the specialized MACSYMA commands
will be introduced. After that we will discuss some of the
facilities of MACSYMA which allow you to manipulate algebraic
expressions within the computer in much the same way you
do on paper."
"MACSYMA is a system for symbolic algebraic manipulation.
It uses a syntax resembling ALGOL 60."
"Do you need help with MACSYMA syntax?"
(IF (YESORNO) (SCRIPT '$SYNTAX NIL))
"MACSYMA contains a large set of commands for manipulating
algebraic expressions. Among these are commands to
factor, expand, differentiate, integrate, substitute and
simplify. Lets try an example:"
"Type in"
(DISPLA EXAMPLE1)
(INCHKP 'CHKEXONEP)
"Now you may want this expression multiplied out. The EXPAND command
will do this for you. It takes one argument, the expression
to be EXPANDed. You may refer to an expression you have typed
in already by using its D-line label. Type:"
(PCLINE `(($EXPAND) ,DLABEL))
(CMDCHKP `(($EXPAND) ,DLABEL))
"On the other hand, factored form is smaller, and the FACTOR command
in MACSYMA will factor expressions for you. There is a short
hand for the D-line label of the last expression
you typed, the character %. Type"
(PCLINE '(($FACTOR) $%))
(CMDCHKP `(($FACTOR) ,DLABEL))
"The MACSYMA commands to integrate and differentiate (INTEGRATE and
DIFF) both take a second argument -- the variable to integrate
or differentiate with respect to. The second argument is
separated from the first by a comma. For example,"
(PCLINE `(($INTEGRATE) ,DLABEL $X))
"If you would type in the expression for"
(DISPLA EXAMPLE2)
"Then we can try integrating and differentiating it."
(INCHK EXAMPLE2)
"Now use the INTEGRATE command to integrate the last expression"
(setq $LOADPRINT T)
(INCHK `(($INTEGRATE) ,DLABEL $X))
"Now use the DIFF command to differentiate your last result."
(INCHK `(($DIFF) ,DLABEL $X))
"You may note that the answer MACSYMA just computed is not the same as
the original expression before it was integrated and
differentiated. The terms are not expanded, nor is the sum
put over a common denominator. The RATSIMP (RATional
SIMPlification) command will do this for you."
(CMDCHKP `(($RATSIMP) ,DLABEL))
"Would you like to learn in more detail about MACSYMA's simplification
commands?"
(IF (YESORNO) (SCRIPT '$SIMPLIFICATION NIL))
"MACSYMA has facilities to handle various series expansions, for
example, Taylor Series. The TAYLOR command takes four
arguments, an expression, a variable, the point around which
to expand the expression, and the power through which to
generate the terms. To generate a TAYLOR series of the
square root of 1+X, around the point 0, to the 5th power,
type:"
"TAYLOR (SQRT(1+X),X,0,5)"
(INCHK '(($TAYLOR) ((%SQRT) ((MPLUS) 1 $X)) $X 0 5))
"You can manipulate these expressions just like any others.
For instance, you can multiply the previous expression by
itself. Type:"
"%*%"
(INCHK `((MTIMES) ,DLABEL ,DLABEL))
"The TAYLOR command converts an expression internally
to MACSYMA's Canonical Rational Expression (CRE) form by
expanding it and combining all terms over a common denominator.
This simplifies the operation of the command.
Expressions that are in CRE form always have the symbol /R/
following the line label. The RATSIMP command also converts
expressions internally into CRE form, but converts them back
to the usual general form at the end.
Type in:"
(DISPLA '((MEXPT) ((MPLUS) $X 3) 20))
(INCHK '((MEXPT) ((MPLUS) $X 3) 20))
"RATSIMP takes one argument, the expression to be converted.
Use RATSIMP on the expression you just typed in."
(CMDCHKP `(($RATSIMP) ,DLABEL))
"This form is obviously bulkier than our original expression,
but the expanded CRE form is useful in many problems."
"Now, differentiate this expression with respect to X"
(INCHK `(($DIFF) ,DLABEL $X))
"If you use FACTOR on this expression, you will see that indeed it
is the appropriate derivative."
(CMDCHKP `(($FACTOR) ,DLABEL))
"MACSYMA has a facility to solve equations using the SOLVE command, which
usually takes two arguments, the first an expression, and the second
the variable to be solved for. The second argument may be
omitted if the expression contains only one variable.
Use SOLVE on the following expression:"
(DISPLA '((MPLUS) ((MEXPT) $X 6) ((MMINUS) 1)))
(INCHK '(($SOLVE) ((MPLUS) ((MEXPT) $X 6) ((MMINUS) 1))))
"What would you like to go over now?"
(PRIMER-SELECT '($SIMPLIFICATION $SCRATCHPAD $ASSIGNMENT $SYNTAX $EXIT)) )
(DEFSCRIPT $SIMPLIFICATION
"This is the SIMPLIFICATION script."
"MACSYMA has several functions to help simplify expressions. Each
one of them has special properties which make it useful in
certain situations."
"For dealing with ratios of polynomials, there are two
functions which are of use. These are RATSIMP and
RATEXPAND. RATSIMP rationally simplifies an expression
and all of its subexpressions and returns a quotient of
two polynomials. RATEXPAND is similar
to EXPAND but the result is a sum of terms each of the form A
over B with all terms over the least common denominator."
"Type in a polynomial in X."
(INCHKP 'POLYCHK)
"Now use the RATSIMP command on it."
(CMDCHKP `(($RATSIMP) ,DLABEL))
"Sometimes before using RATSIMP on a complicated expression, it is useful
to cancel common factors and combine terms a bit, to allow RATSIMP
to work more efficiently."
"To illustrate this let's make MACSYMA print out the time it uses, by
setting SHOWTIME to TRUE."
(MACSYMA '((MSETQ) $SHOWTIME $TRUE))
"Now type in this expression:"
(DISPLA SIMPEXAMPLE1)
(INCHK SIMPEXAMPLE1)(SETQ D DLABEL)
"And now use RATSIMP on it."
(CMDCHKP `(($RATSIMP) ,DLABEL))
"That works, but for larger expressions it might take quite a long time, or
might run out of space. XTHRU is a command that will do some
preliminary simplification like cancelling common factors and
combining terms. Like RATSIMP, it takes one argument, the
expression to be operated on.
So referring back to the original expression
by its D-label, @D use XTHRU to simplify it."
(GC)
(CMDCHKP `(($XTHRU) ,D))
"Now use RATSIMP on it."
(CMDCHKP `(($RATSIMP) ,DLABEL))
"As you can see, the total time for the XTHRU and RATSIMP are considerably
less than that for just the RATSIMP of the original expression."
"Now, we will turn off the TIME printout again, by setting TIME to FALSE."
(MACSYMA '((MSETQ) $SHOWTIME $FALSE))
"Along with FACTOR, EXPAND, RATSIMP, and RATEXPAND,
MACSYMA also has a simplifier to handle expressions
involving logs, exponentials, and radicals. This
simplifier is called RADCAN, which is short for radical
canonical. RADCAN can take a long time to simplify
some expressions, so it should be used with this in mind."
"Would you like to try RADCAN on an expression?"
(IF (YESORNO) (SCRIPT 'TRYRADCAN NIL))
"Would you like to learn more about simplifying and manipulating
expressions?"
(IF (YESORNO) (SCRIPT '$SCRATCHPAD NIL))
"What would you like to go over now?"
(PRIMER-SELECT '($INTRO $SCRATCHPAD $ASSIGNMENT $SYNTAX $EXIT)) )
(DEFSCRIPT $SCRATCHPAD
"This is the SCRATCHPAD script."
"In some cases the user
will want to have access to a finer level of control over
his expressions. MACSYMA has commands which allow the
user to play with his expressions in the machine in much
the same way he would with paper and pencil."
"One important command of this type in MACSYMA is the SUBST
command. This command can be used to replace all
occurrences of a subexpression with some other expression
in an intermediate result. This is useful, for
example, in expressions involving trigonometric
functions, where the MACSYMA simplifiers are not willing,
for reasons of efficiency, to try all possible trigonometric
identities."
"SUBST(A,B,C) means substitute A for B in C. The
resulting expression will be mathematically equivalent to the
original expression if A is mathematically equivalent to B."
(SLEEP 2)
"Here is a simple example of the use of SUBST. The
numerator of this expression is equal to 1 for all X,
but the MACSYMA simplifiers will not simplify it directly."
(MACSYMA SUBST-EXAMPLE1)
"There are three ways to use SUBST on this example:"
"One could substitute 1 for SIN(X)^2+COS(X)^2"
"One could substitute 1-SIN(X)^2 for COS(X)^2"
"Or one could substitute 1-COS(X)^2 for SIN(X)^2"
"The first way is more direct, but in more complex
examples where the sin squared plus cos squared is deeply
entwined with other elements of the expression the second
or third way would be necessary. Pick the way you like
best and simplify the expression by using SUBST."
(INCHKP 'SUBEXAMPLE1)
"SUBST however, can only substitute for expressions
that constitute an extractable part of the larger expression they
are contained in. In the case where the thing that you
want to substitute for is embedded in the expression,
then a more powerful tool is needed. RATSUBST is a
command that can be helpful in these cases. Here is an
example of the same simplification as before but with it
embedded so that the COS(X)^2 is not easily extractable from
the expression."
(MACSYMA SUBST-EXAMPLE2)
"Now use RATSUBST to simplify the above."
(INCHKP 'SUBEXAMPLE2)
"In working with algebraic expressions by hand, one will
often take part of a larger expression and work with that for
a time. In MACSYMA that can by done by using the PART
command. The PART command takes two or more arguments.
The first is the expression and the rest are specifications
as to which part is to be taken. Each of the specifications
is an integer that tells which one of the top level operators
arguments to take. Consider this example:"
(MACSYMA EXAMPLE3)
"This is a quotient of sums and thus the quotient is the top
level operator. Its first argument is its numerator, and its
second argument is the denominator. Thus:"
(PCLINE `(($PART) ,DLABEL 1))
"would return the numerator. If PART had been given a third
argument it would pick one of the terms of the numerator. Now
use the PART command to get the R from the above expression."
(SETQ $PARTSWITCH T)
(PARTCHK '$PART '$R)
(SETQ $PARTSWITCH NIL)
"What would you like to go over now?"
(PRIMER-SELECT '($INTRO $SIMPLIFICATION $ASSIGNMENT $SYNTAX $EXIT)) )
(DEFSCRIPT $SYNTAX
"This is the SYNTAX script."
"Input to MACSYMA is done with a syntax somewhat like that of
Fortran or Algol. All input lines are terminated
with a semi-colon (;). Input lines
are labeled consecutively starting with (C1), and then
(C2) (C3) etc. MACSYMA results are labeled from
(D1) on. Thus (D1) is the result of the computations
performed by MACSYMA on the user's input string (C1)."
"These line numbers may be used to refer to expressions."
(SLEEP 2)
"The display MACSYMA prints out is two dimensional, like a textbook.
You must be careful not to let this confuse you. If you want
to type in the mathematical expression 2X, which of course is
'2 times X', you must type '2*X' even though MACSYMA will
print back"
(DISPLA '((MTIMES) 2 $X))
"Try typing in 2X or some other expression times X:"
(SYNCHK '(MTIMES) '((MTIMES) 2 $X))
"* is the multiplication operator. The other operators MACSYMA
uses are:"
~! for Factorial,~
~^ or ** for Exponentiation,~
~* for Multiplication,~
~. for non-commutative multiplication~
~/ for Division, ~
~+ for Addition, and~
~- for Subtraction.~
(SLEEP 2)
"These operators are applied following the traditional rules for
operator precedence.
Do you know what is meant by operator precedence?"
(IF (NOT (YESORNO)) (SCRIPT 'PRECEDENCE NIL))
"Variables in MACSYMA (and names of functions and arrays) consist of
a string of numbers and letters including the character %. Other
characters may be included by preceding them with a backslash
(\). Variable names are not limited in length, but must not
begin with a number."
"Constants are either numbers or one of the special constants, pi, e
(the base of natural logarithms), or i (the square root of minus
one) which are written %PI, %E, and %I to distinguish them from
the variables pi, e, and i."
(SLEEP 2)
"An operator may appear before its argument(s), between its arguments
or after its argument. Operators that appear before their
arguments are usually functions (such as SIN and COS) or
MACSYMA commands (such as INTEGRATE or RATSIMP). The arguments
to these operators are enclosed in parentheses, for example"
(PCLINE '((%SIN) 3.141))
"or"
(PCLINE '(($INTEGRATE) $% $X))
"Would you like to practice typing in some expressions?"
(IF (YESORNO) (SCRIPT 'PRACTICE NIL))
"That's all for syntax.")
(DEFSCRIPT PRACTICE
"Let's start with a simple linear expression: type in the expression for"
(DISPLA PRAC-EXAMPLE1)
(INCHK PRAC-EXAMPLE1)
"Okay, now try one where you need to use some parentheses to get the proper
operator precedence"
(DISPLA PRAC-EXAMPLE2)
(INCHK PRAC-EXAMPLE2)
"Now try a ratio."
(DISPLA PRAC-EXAMPLE3)
(INCHK PRAC-EXAMPLE3)
"Okay, try another type of exponentiation"
(DISPLA PRAC-EXAMPLE4)
(INCHK PRAC-EXAMPLE4)
"Here's a polynomial"
(DISPLA PRAC-EXAMPLE5)
(INCHK PRAC-EXAMPLE5)
"Now try a slightly more complicated ratio:"
(DISPLA PRAC-EXAMPLE6)
(INCHK PRAC-EXAMPLE6)
"Would you like to continue with the Introductory Section of
the primer?"
(IF (NOT (YESORNO)) (SCRIPT '$HELP2 NIL)))
(DEFSCRIPT $HELP2
"What would you like to go over? "
(PRIMER-SELECT '($CONSOLEPRIMER $INTRO $SIMPLIFICATION $SCRATCHPAD $SYNTAX $ASSIGNMENT $EXIT)) )
(DEFSCRIPT PRECEDENCE
"MACSYMA uses the conventional mathematical operator precedence."
"Would you like to see some examples of how MACSYMA represents
operator precedence?"
(IF (YESORNO) (SCRIPT 'PRECEDENCE1 NIL)))
(DEFSCRIPT PRECEDENCE1
"Uparrow, ^, for exponentiation, has higher precedence that * for
multiplication, so:"
(MACSYMA '((MTIMES) ((MEXPT) $A 2) $B))
"Asterisk, *, for multiplication has higher precedence than + for
addition, so:"
(MACSYMA '((MPLUS) $A ((MTIMES) $B $C)))
"Parentheses may be used to change the order of application of
operators,"
(MACSYMA '((MTIMES) ((MPLUS) $A $B) $C))
"If you need further examples, consult page 8 of the MACSYMA Manual."
(SLEEP 7))
(DEFSCRIPT TRYRADCAN
"Type in this expression:"
(DISPLA RADCANEXAMPLE)
(INCHKP 'CHKRADCAN)
"Now use RADCAN on it."
(CMDCHKP `(($RADCAN) ,DLABEL)))
(DEFSCRIPT $HELP
"Hello. Please terminate your responses with a ;.
What would you like to go over? (Select the number of the script you
would like to see.)
INTRO is a general introduction
for people who have never used MACSYMA or this PRIMER before."
(PRIMER-SELECT '($CONSOLEPRIMER $INTRO $SIMPLIFICATION $SCRATCHPAD $SYNTAX $ASSIGNMENT $EXIT)) )
(DEFSCRIPT CRTCONSOLE
"Since you have a display (CRT) console, there is one special
thing you must know before we proceed: When the printout
reaches the bottom of your screen, the system will print
**MORE**, --More Display?--, or --Pause--, and the output
will pause, leaving you as much time as you like to read
what has been printed. When you are ready to continue, you
hit the space bar once. The system will print --Continued--
and output will resume." )
(DEFSCRIPT CTRLCHAR
(SSTATUS TTYINT 7 'NIL)
"To type a control-character you use the key on your console labeled
'CTRL' or 'Control' in the same fashion as you would use the
'shift' key, that is you hold down the key labeled 'CTRL' and
strike the key you want to make a control-character. The
control-character which you will probably find the most useful
in MACSYMA, is control-G.
This is MACSYMA's 'QUIT' character, that is the character which
will cause MACSYMA to stop what it is doing and accept more input
from you. It is sort of the 'panic button', and will stop infinite
loops. So you can find it and practice
typing it, it is temporarily disabled as a 'QUIT' character."
"Try typing it now:"
(QUITCHK)
(SSTATUS TTYINT 7 'MQUIT))
(SETQ EXAMPLE1 '((MEXPT) ((MPLUS) $X 1) 3))
(SETQ EXAMPLE2 '((MQUOTIENT) $A
((MPLUS) ((MEXPT) $X 3) ((MTIMES) 2 ((MEXPT) $X 2)) $X)))
(SETQ EXAMPLE3 '((MQUOTIENT) ((MPLUS) $A $B $C) ((MPLUS) $Q $R $S)))
(SETQ EXAMPLE4 '(($FACTOR)
((MPLUS) ((MEXPT) $X 3)
((MTIMES) ((MEXPT) $X 2)
((MEXPT) $Y 2))
((MMINUS) ((MTIMES) $X ((MEXPT) $Z 2)))
((MMINUS) ((MTIMES) ((MEXPT) $Y 2)
((MEXPT) $Z 2))))))
(SETQ SUBST-EXAMPLE1 '((MQUOTIENT)
((MPLUS) ((MEXPT) ((%SIN) $X) 2)
((MEXPT) ((%COS) $X) 2))
((MPLUS) ((MEXPT) $X 2) 39)))
(SETQ SUBST-EXAMPLE2 '((MPLUS)
((MTIMES) ((MEXPT) ((%COS) $X) 3) ((%SIN) $X))
((MTIMES) ((%COS) $X) ((MEXPT) ((%SIN) $X) 3))))
(SETQ PRAC-EXAMPLE1 '((MPLUS)((MTIMES) 3 $X) 1))
(SETQ PRAC-EXAMPLE2 '((MEXPT)((MPLUS) $X 2) 3))
(SETQ PRAC-EXAMPLE3 '((MQUOTIENT) 1 ((%SIN) $X)))
(SETQ PRAC-EXAMPLE4 '((MEXPT) $%E ((MTIMES) 2 $%PI $I)))
(SETQ PRAC-EXAMPLE5 '((MPLUS)((MEXPT) $X 2)((MTIMES) 2 $X) 1))
(SETQ PRAC-EXAMPLE6 '((MQUOTIENT) 1 ((MPLUS) ((MEXPT) $X 2) 3)))
(SETQ SIMPEXAMPLE1 '((MPLUS)((MQUOTIENT) 1 ((MEXPT) ((MPLUS) $Y $X) 3))
((MQUOTIENT) ((MPLUS) ((MEXPT) ((MPLUS) $X 2) 8)
((MMINUS) ((MTIMES) 2 $Y)))
((MEXPT) ((MPLUS) $Y $X) 8))))
(SETQ RADCANEXAMPLE '((MQUOTIENT)((MEXPT)((MPLUS)
((%LOG)((MPLUS)((MEXPT) $X 2) $X))
((MMINUS) ((%LOG) $X)))
$B)
((MEXPT)((%LOG)((MPLUS) $X 1))((MQUOTIENT) $B 2))))
(DEFUN NUMCHK (NUM)
(TERPRI)
(DO ANS (RETRIEVE NIL NIL) (RETRIEVE NIL NIL) NIL
(COND ((EQ '$NO ANS)
(TERPRI) (PRINC '|Well, all right, I'll show you.|)
(TERPRI)(PRIN1 NUM)(PRINC '|;|)(RETURN (TERPRI)))
((NOT (EQ (TYPEP ANS) 'FIXNUM))
(TERPRI)(PRINC '|That isn't a number.|)
(TERPRI)(PRINC '|Try again.|)(TERPRI))
((AND (> ANS 0)(NOT (> ANS NUM)))(RETURN (TERPRI)))
(T (TERPRI) (PRINC '|That number isn't in the list. Try again.|)
(TERPRI)))))
(DEFUN QUITCHK ()
(TERPRI)
(DO ((X (TYI)(TYI))) (NIL)
(COND ((OR (= X 103) (= X 71))
(TERPRI)
(PRINC '|That was just a G, try again.|)
(TERPRI)
(PRINC '|Hold down the control key.|)(TERPRI))
((= X 7)
(TERPRI)
(PRINC '|That's it, very good.|)
(TERPRI)
(PRINC '|Now we'll make it a quit character again, so|)
(TERPRI)
(PRINC '|only type it if you want to quit out of the PRIMER.|)
(RETURN (TERPRI)))
(T (TERPRI)
(PRINC '|Nope, not quite. Try again, hold down the control key|)
(TERPRI)
(PRINC '|and hit the G.|)(TERPRI)))))

90
src/macsym/script.aux Executable file
View File

@@ -0,0 +1,90 @@
;;; -*- Mode:LISP; Package:MACSYMA -*-
; ** (c) Copyright 1981 Massachusetts Institute of Technology **
(DEFSCRIPT $ASSIGNMENT
"In MACSYMA variables are assigned values by use of a :, for
example, if you want to set a equal to 3, you would type"
"a:3;"
"and MACSYMA would respond"
(DISPLA '3)
"Assign a numerical value to A"
(INCHKP 'ASSIGNCHKP)
"The values assigned to variables may be complex, "
(MACSYMA '((MSETQ) $C ((MTIMES) ((%COS SIMP) $X) ((%SIN SIMP) $X))))
"The difference between expressions and functions is sometimes
difficult to understand in MACSYMA. For example, you can type
to MACSYMA"
"f(x)=x^2"
"or you could type"
"f(x):=x^2"
"MACSYMA will accept either form, but will treat them differently.
The first, which looks familiar to mathematicians as a function,
is to MACSYMA only an equation. If you ask MACSYMA to
evaluate f(2), MACSYMA will type back F(2). The second, with
the colon equals is the proper MACSYMA function definition for
the function X squared."
"Type in a simple function for f(x)."
(FUNCHKP '(MDEFINE) '(($F) $X))
"Now ask MACSYMA to tell you the value of this function for some
value of X:"
(INCHKP 'VALUEP)
"We defined C above as SIN(X) times COS(X). Now, let's define a
function that uses C. Type in g(x):=C^2."
(INCHK '((MDEFINE) (($G) $X) ((MEXPT) $C 2)))
"Notice that MACSYMA has not inserted the value of C in this function
definition."
"To get MACSYMA to evaluate G(X) and use the value it knows for C,
type"
"ev(g(x));"
(INCHK '(($EV)(($G) $X)))
"Now let's remove the value we assigned to C. To do this type"
"kill(c);"
(INCHK '(($KILL) $C))
"Now ask MACSYMA to evaluate G(X) again."
(INCHK '(($EV)(($G) $X)))
"You assigned a value to A above, ask MACSYMA to evaluate the function
F for the value of A. Type F(A)."
(INCHK '(($F) $A))
"When you have assigned values to a lot of variables, and defined
a number of functions, it is important to be able to tell
what you have assigned. MACSYMA maintains lists of these
things for you. Type VALUES; to see a list of the variables
to which you have assigned values."
(INCHK '$VALUES)
"Typing FUNCTIONS; will list the functions which you have defined."
(INCHK '$FUNCTIONS)
"To print out the complete function definition of one of your functions
use the command DISPFUN, which takes the name of the function to be
printed out as an argument. Use DISPFUN to display the definition
of your function F."
(CMDCHKP '(($DISPFUN) $F))
"INFOLISTS is a list of the lists of information MACSYMA maintains.
Type INFOLISTS; to see the names of all these lists."
(INCHK '$INFOLISTS)
"Typing EV(INFOLISTS); will give you a list of the things in each
of the lists."
(INCHK '(($EV) $INFOLISTS))
"Checking INFOLISTS periodically during a session can help you keep
track of the information you have in your MACSYMA. It is also
useful for determining what information you had stored in a
file when you reload the file (see the FILING section of the
Primer)."
"What would you like to go over now?"
(PRIMER-SELECT '($INTRO $SIMPLIFICATION $SCRATCHPAD $SYNTAX $EXIT)) )
(DEFSCRIPT $FILING
"This script is not ready yet. Try it again in a few weeks.")
(DEFSCRIPT $STRINGCOMMANDS
"This script temporarily does not exist."
)

263
src/macsym/script.begin Executable file
View File

@@ -0,0 +1,263 @@
;; (c) Copyright 1983 Massachusetts Institute of Technology
;;
;; Enhancements (c) 1983, Symbolics, Inc. All Rights Reserved.
;; The data and information in the Enhancements is proprietary
;; to, and a valuable trade secret of, SYMBOLICS, INC., a
;; Delaware corporation. It is given in confidence by
;; SYMBOLICS, and may not be used as the basis of manufacture,
;; or be reproduced or copied, or distributed to any other
;; party, in whole or in part, without the prior written
;; consent of SYMBOLICS.
;;
(SETQ $LOADPRINT NIL)
;This shouldn't be needed any more --kmp
;(COND ((STATUS FEATURE MACLISP) (LOAD '((LISP)DEFMAX))))
(DEFSCRIPT $CONSOLEPRIMER
"Welcome to the MACSYMA Primer. This section of the Primer
is called the CONSOLEPRIMER because it is intended to be
used by people who have not had previous experience
interacting with a computer console."
(COND ((AND $PAGEPAUSE CURSORPOS)(SCRIPT 'CRTCONSOLE NIL)))
(SLEEP 2)
"You will notice that your console looks much like a typewriter, except
for having a few special keys. The two most important special
keys are the 'altmode' and the 'control' key. The 'altmode'
may be labeled 'alt', 'esc', '(sel)', or 'escape'. The 'control'
key may be labeled 'CTRL' or 'CNTL'. The altmode is used to
enter the MACSYMA editor. Do not attempt to use the editor while
you are in the Primer since it may tend to confuse you. A future
script will deal with editing. The control key is used in
the same fashion as the shift key on the typwriter, i.e. you hold
it down and type the character whose 'control' value you wish.
For example, to type control-Z, you would hold down the control
key and type a Z. Don't do that now, as control-Z is the control
character that will return you to top level when you are ready
to log out."
(SLEEP 2)
"The Primer will explain some of the aspects of MACSYMA to you and allow
you to try out various examples. Your responses to
the Primer must end with a semi-colon (;). That is the one
thing which the Primer cannot correct you on, since it will not
even see your response until you have typed the semi-colon. Thus
if nothing seems to be happening, check that you have typed the
semi-colon."
"In the Primer you should answer all questions the system asks. There
are three kinds of questions:"
"1. Questions you can answer with a yes or a no. You type the word
YES or the word NO followed immediately by a semi-colon (;) to
answer these. Case does not matter, upper or lower will do.
Try it here: Type YES; or NO;"
(AND (YESORNO) (TERPRI))
"2. Questions which require you to select a script or an option. The system
will print out a list, for example:"
(MENU '($SIMPLIFICATION $SCRATCHPAD $ASSIGNMENT))
"This list is called the 'menu', the list of scripts available.
You select a script to see by typing the number of your choice
followed by a semi-colon (;), to answer these. E.g."
"3;"
"Now you try it."
(MENU '($SIMPLIFICATION $SCRATCHPAD $ASSIGNMENT))
(NUMCHK 3)
"3. Requests to type in commands to MACSYMA. The system will make a
request, such as 'Type in a polynomial in X,' and then give you
a dummy MACSYMA command line number. You then type the command,
followed by a semi-colon. This is to give you a chance to practice
what you are learning. If you type the command correctly, the
system will pass what you type to MACSYMA, and MACSYMA will
evaluate it and return a response. If you make a mistake the
system will attempt to tell you what you did wrong, and will
offer you a chance to try again. Here, try typing X+2;"
(INCHK '((MPLUS) $X 2))
"The response, as you see, is just the expression itself, since
no simplification or operation was necessary or specified."
"Do you know how to type 'control-characters'?"
(AND (NOT (YESORNO)) (SCRIPT 'CTRLCHAR NIL))
"Control-G is the QUIT command for MACSYMA."
"The other control characters you should know about for MACSYMA are:"
"Control-L: this reprints the command line you are typing. On a display
console it will also clear the screen. It is particularly useful
if you have used rubout (delete) a lot and want to verify that you
have everything right."
"Control-^: this will put you into LISP, the language MACSYMA is written in.
You will not usually want to use it, but should know about it so
you can avoid typing it. If you do type it by mistake, control-G
will get you back to a MACSYMA command line."
"Control-A: this enters a MACSYMA break. This suspends the current
computation, and allows you to 'poke around' in your MACSYMA,
perhaps to open a file for output, or to see what the value of
some variable is. To get out of the 'break' and resume the
computation, type 'exit;'"
"Control-]: this prints out the time used by the computation so far.
You can type it at any point during a computation. Try it now to
see how much CPU time this PRIMER session has used:"
(SLEEP 8)
"Now you are ready to move along to the Introductory Script of the Primer."
(COND ((EQ 'WSMR (STATUS UNAME))(SCRIPT '$INTRO NIL))
(T (SEEN (STATUS UNAME) '$CONSOLEPRIMER)))
(SCRIPT '$INTRO NIL))
(DEFSCRIPT $FRANZPRIMER
"Welcome to the MACSYMA Primer. This section of the Primer
is called the FRANZPRIMER because it is intended to be
used by people who have not had previous experience
interacting with a Franz Lisp version of MACSYMA, or
maybe even with a computer console."
(COND ((AND $PAGEPAUSE CURSORPOS)(SCRIPT 'CRTCONSOLE NIL)))
"You will notice that your console looks much like a typewriter, except
for having a few special keys. The two most important special
keys are the 'altmode' and the 'control' key. The 'altmode'
may be labeled 'alt', 'esc', '(sel)', or 'escape'. The 'control'
key may be labeled 'CTRL' or 'CNTL'. The altmode is used to
enter the MACSYMA editor. Do not attempt to use the editor while
you are in the Primer since it may tend to confuse you. A future
script will deal with editing. The control key is used in
the same fashion as the shift key on the typwriter, i.e. you hold
it down and type the character whose 'control' value you wish.
For example, to type control-Z, you would hold down the control
key and type a Z. Don't do that now, as control-Z is the control
character that will return you to top level if you wish to interrupt
your MACSYMA briefly."
"The Primer will explain some of the aspects of MACSYMA to you and allow
you to try out various examples. Your responses to
the Primer must end with a semi-colon (;) followed by a carriage return
(newline). That is the one
thing which the Primer cannot correct you on, since it will not
even see your response until you have typed the semi-colon and the
carriage return. Thus
if nothing seems to be happening, check that you have typed
semi-colon carriage return."
"In the Primer you should answer all questions the system asks. There
are three kinds of questions:"
"1. Questions you can answer with a yes or a no. You type the word
YES or the word NO followed immediately by a semi-colon (;) and a
carriage return to
answer these. By convention in the primer we use upper case to
make what you wish to type stand out from the rest of the text.
However, in your answers you should use lower case.
Try it here: Type YES; or NO;"
(AND (YESORNO) (TERPRI))
"2. Questions which require you to select a script or an option. The system
will print out a list, for example:"
(MENU '($SIMPLIFICATION $SCRATCHPAD $ASSIGNMENT))
"This list is called the 'menu', the list of scripts available.
You select a script to see by typing the number of your choice
followed by a semi-colon (;) and a carriage return, to answer
these. E.g."
"3;"
"Now you try it."
(MENU '($SIMPLIFICATION $SCRATCHPAD $ASSIGNMENT))
(NUMCHK 3)
"3. Requests to type in commands to MACSYMA. The system will make a
request, such as 'Type in a polynomial in X,' and then give you
a dummy MACSYMA command line number. You then type the command,
followed by a semi-colon. This is to give you a chance to practice
what you are learning. If you type the command correctly, the
system will pass what you type to MACSYMA, and MACSYMA will
evaluate it and return a response. If you make a mistake the
system will attempt to tell you what you did wrong, and will
offer you a chance to try again. Here, try typing X+2; followed
by a carriage return."
(INCHK '((MPLUS) $X 2))
"The response, as you see, is just the expression itself, since
no simplification or operation was necessary or specified."
"Do you know how to type 'control-characters'?"
(AND (NOT (YESORNO)) (SCRIPT 'FRANZCTRLCHAR NIL))
"Control-C is the QUIT command for MACSYMA.
It places you in a break loop from which you may return to MACSYMA,
enter Lisp, enter a MACSYMA break for debugging, or return to
the shell, killing MACSYMA."
"The other control characters you should know about for MACSYMA are:"
"Control-L: this reprints the command line you are typing.
It is particularly useful
if you have used (delete) a lot and want to verify that you
have everything right."
"Control-D: this will put you into LISP, the language MACSYMA is written in.
You will not usually want to use it, but should know about it so
you can avoid typing it. If you do type it by mistake, a second
control-D
will get you back to a MACSYMA command line."
"Control-H (backspace): this deletes (erases) the last character you
typed. It may be used repeatedly."
(SLEEP 8)
"Now you are ready to move along to the Introductory Script of the Primer."
(COND ((EQ 'WSMR (STATUS UNAME))(SCRIPT '$INTRO NIL))
(T (SEEN (sys-user-id) '$franzprimer)))
(SCRIPT '$INTRO NIL))
(DEFSCRIPT CRTCONSOLE
"Since you have a display (CRT) console, there is one special
thing you must know before we proceed: When the printout
reaches the bottom of your screen, the system will print
**MORE**, --More Display?--, or --Pause--, and the output
will pause, leaving you as much time as you like to read
what has been printed. When you are ready to continue, you
hit the space bar once. The system will print --Continued--
and output will resume." )
(DEFSCRIPT CTRLCHAR
(SSTATUS TTYINT 7 'NIL)
"To type a control-character you use the key on your console labeled
'CTRL' or 'Control' in the same fashion as you would use the
'shift' key, that is you hold down the key labeled 'CTRL' and
strike the key you want to make a control-character. The
control-character which you will probably find the most useful
in MACSYMA, is control-G.
This is MACSYMA's 'QUIT' character, that is the character which
will cause MACSYMA to stop what it is doing and accept more input
from you. It is sort of the 'panic button', and will stop infinite
loops. So you can find it and practice
typing it, it is temporarily disabled as a 'QUIT' character."
"Try typing it now:"
(QUITCHK)
(SSTATUS TTYINT 7 'MQUIT))
(DEFSCRIPT FRANZCTRLCHAR
"To type a control-character you use the key on your console labeled
'CTRL' or 'Control' in the same fashion as you would use the
'shift' key, that is you hold down the key labeled 'CTRL' and
strike the key you want to make a control-character. The
control-character which you will probably find the most useful
in MACSYMA, is control-C.
This is MACSYMA's 'QUIT' character, that is the character which
will cause MACSYMA to stop what it is doing and accept more input
from you. It is sort of the 'panic button', and will stop infinite
loops."
)
(DEFUN NUMCHK (NUM)
(TERPRI)
(DO ANS (RETRIEVE NIL NIL) (RETRIEVE NIL NIL) NIL
(COND ((EQ '$NO ANS)
(TERPRI) (PRINC '|Well, all right, I'll show you.|)
(TERPRI)(PRIN1 NUM)(PRINC '|;|)(RETURN (TERPRI)))
((NOT (EQ (TYPEP ANS) 'FIXNUM))
(TERPRI)(PRINC '|That isn't a number.|)
(TERPRI)(PRINC '|Try again.|)(TERPRI))
((AND (> ANS 0)(NOT (> ANS NUM)))(RETURN (TERPRI)))
(T (TERPRI) (PRINC '|That number isn't in the list. Try again.|)
(TERPRI)))))
(DEFUN QUITCHK ()
(TERPRI)
(DO ((X (TYI)(TYI))) (NIL)
(COND ((OR (= X 103) (= X 71))
(TERPRI)
(PRINC '|That was just a G, try again.|)
(TERPRI)
(PRINC '|Hold down the control key.|)(TERPRI))
((= X 7)
(TERPRI)
(PRINC '|That's it, very good.|)
(TERPRI)
(PRINC '|Now we'll make it a quit character again, so|)
(TERPRI)
(PRINC '|only type it if you want to quit out of the PRIMER.|)
(RETURN (TERPRI)))
(T (TERPRI)
(PRINC '|Nope, not quite. Try again, hold down the control key|)
(TERPRI)
(PRINC '|and hit the G.|)(TERPRI)))))

468
src/macsym/script.intro Executable file
View File

@@ -0,0 +1,468 @@
;;; -*- Mode:LISP; Package:MACSYMA -*-
; ** (c) Copyright 1976, 1983 Massachusetts Institute of Technology **
;; Enhancements (c) 1983, Symbolics, Inc. All Rights Reserved.
;; The data and information in the Enhancements is proprietary
;; to, and a valuable trade secret of, SYMBOLICS, INC., a
;; Delaware corporation. It is given in confidence by
;; SYMBOLICS, and may not be used as the basis of manufacture,
;; or be reproduced or copied, or distributed to any other
;; party, in whole or in part, without the prior written
;; consent of SYMBOLICS.
(SETQ $LOADPRINT NIL)
;This shouldn't be needed any more --kmp
;(COND ((STATUS FEATURE MACLISP) (LOAD '((LISP)DEFMAX))))
(DEFSCRIPT $INTRO
"Welcome to the MACSYMA Primer. This is the script called INTRO."
"Please terminate responses to all questions with a semi-colon (;).
You may delete any characters you have typed by using
the delete or rub-out key on your console (control-H or backspace
for VAX systems). The deleted
character will be erased if you are using a display terminal.
If you are using a printing terminal, it will be
typed back so you know what has been deleted."
"If you do not understand how to type an expression, or have tried
several times and wish to give up, you may type NO; and the
PRIMER will show you the correct way to do it."
"In this PRIMER session, after an optional introduction to
MACSYMA syntax, a few of the specialized MACSYMA commands
will be introduced. After that we will discuss some of the
facilities of MACSYMA which allow you to manipulate algebraic
expressions within the computer in much the same way you
do on paper."
"MACSYMA is a system for symbolic algebraic manipulation.
It uses a syntax resembling ALGOL 60."
"Do you need help with MACSYMA syntax?"
(AND (YESORNO) (SCRIPT '$SYNTAX NIL))
"MACSYMA contains a large set of commands for manipulating
algebraic expressions. Among these are commands to
factor, expand, differentiate, integrate, substitute and
simplify. Lets try an example:"
"Type in"
(DISPLA EXAMPLE1)
(INCHKP 'CHKEXONEP)
"Now you may want this expression multiplied out. The EXPAND command
will do this for you. It takes one argument, the expression
to be EXPANDed. You may refer to an expression you have typed
in already by using its D-line label. Type:"
(PCLINE (LIST '($EXPAND) DLABEL))
(CMDCHKP (LIST '($EXPAND) DLABEL))
"On the other hand, factored form is smaller, and the FACTOR command
in MACSYMA will factor expressions for you. There is a short
hand for the D-line label of the last expression
you typed, the character %. Type"
(PCLINE '(($FACTOR) $%))
(CMDCHKP (LIST '($FACTOR) DLABEL))
"The MACSYMA commands to integrate and differentiate (INTEGRATE and
DIFF) both take a second argument -- the variable to integrate
or differentiate with respect to. The second argument is
separated from the first by a comma. For example,"
(PCLINE (LIST '($INTEGRATE) DLABEL '$X))
"If you would type in the expression for"
(DISPLA EXAMPLE2)
"Then we can try integrating and differentiating it."
(INCHK EXAMPLE2)
"Now use the INTEGRATE command to integrate the last expression"
(setq $LOADPRINT T)
(INCHK (LIST '($INTEGRATE) DLABEL '$X))
"Now use the DIFF command to differentiate your last result."
(INCHK (LIST '($DIFF) DLABEL '$X))
"You may note that the answer MACSYMA just computed is not the same as
the original expression before it was integrated and
differentiated. The terms are not expanded, nor is the sum
put over a common denominator. The RATSIMP (RATional
SIMPlification) command will do this for you."
(CMDCHKP (LIST '($RATSIMP) DLABEL))
"Would you like to learn in more detail about MACSYMA's simplification
commands?"
(AND (YESORNO) (SCRIPT '$SIMPLIFICATION NIL))
"MACSYMA has facilities to handle various series expansions, for
example, Taylor Series. The TAYLOR command takes four
arguments, an expression, a variable, the point around which
to expand the expression, and the power through which to
generate the terms. To generate a TAYLOR series of the
square root of 1+X, around the point 0, to the 5th power,
type:"
"TAYLOR (SQRT(1+X),X,0,5)"
(INCHK '(($TAYLOR) ((%SQRT) ((MPLUS) 1 $X)) $X 0 5))
"You can manipulate these expressions just like any others.
For instance, you can multiply the previous expression by
itself. Type:"
"%*%"
(INCHK (LIST '(MTIMES) DLABEL DLABEL))
"The TAYLOR command converts an expression internally
to MACSYMA's Canonical Rational Expression (CRE) form by
expanding it and combining all terms over a common denominator.
This simplifies the operation of the command.
Expressions that are in CRE form always have the symbol /R/
following the line label. The RATSIMP command also converts
expressions internally into CRE form, but converts them back
to the usual general form at the end.
Type in:"
(DISPLA '((MEXPT) ((MPLUS) $X 3) 20))
(INCHK '((MEXPT) ((MPLUS) $X 3) 20))
"RATSIMP takes one argument, the expression to be converted.
Use RATSIMP on the expression you just typed in."
(CMDCHKP (LIST '($RATSIMP) DLABEL))
"This form is obviously bulkier than our original expression,
but the expanded CRE form is useful in many problems."
"Now, differentiate this expression with respect to X"
(INCHK (LIST '($DIFF) DLABEL '$X))
"If you use FACTOR on this expression, you will see that indeed it
is the appropriate derivative."
(CMDCHKP (LIST '($FACTOR) DLABEL))
"MACSYMA has a facility to solve equations using the SOLVE command, which
usually takes two arguments, the first an expression, and the second
the variable to be solved for. The second argument may be
omitted if the expression contains only one variable.
Use SOLVE on the following expression:"
(DISPLA '((MPLUS) ((MEXPT) $X 6) ((MMINUS) 1)))
(INCHK '(($SOLVE) ((MPLUS) ((MEXPT) $X 6) ((MMINUS) 1))))
"What would you like to go over now?"
(PRIMER-SELECT '($SIMPLIFICATION $SCRATCHPAD $ASSIGNMENT $SYNTAX $EXIT)) )
(DEFSCRIPT $SIMPLIFICATION
"This is the SIMPLIFICATION script."
"MACSYMA has several functions to help simplify expressions. Each
one of them has special properties which make it useful in
certain situations."
"For dealing with ratios of polynomials, there are two
functions which are of use. These are RATSIMP and
RATEXPAND. RATSIMP rationally simplifies an expression
and all of its subexpressions and returns a quotient of
two polynomials. RATEXPAND is similar
to EXPAND but the result is a sum of terms each of the form A
over B with all terms over the least common denominator."
"Type in a polynomial in X."
(INCHKP 'POLYCHK)
"Now use the RATSIMP command on it."
(CMDCHKP (LIST '($RATSIMP) DLABEL))
"Sometimes before using RATSIMP on a complicated expression, it is useful
to cancel common factors and combine terms a bit, to allow RATSIMP
to work more efficiently."
"To illustrate this let's make MACSYMA print out the time it uses, by
setting SHOWTIME to TRUE."
(MACSYMA '((MSETQ) $SHOWTIME $TRUE))
"Now type in this expression:"
(DISPLA SIMPEXAMPLE1)
(INCHK SIMPEXAMPLE1)(SETQ D DLABEL)
"And now use RATSIMP on it."
(CMDCHKP (LIST '($RATSIMP) DLABEL))
"That works, but for larger expressions it might take quite a long time, or
might run out of space. XTHRU is a command that will do some
preliminary simplification like cancelling common factors and
combining terms. Like RATSIMP, it takes one argument, the
expression to be operated on.
So referring back to the original expression
by its D-label, @D use XTHRU to simplify it."
(GC)
(CMDCHKP (LIST '($XTHRU) D))
"Now use RATSIMP on it."
(CMDCHKP (LIST '($RATSIMP) DLABEL))
"As you can see, the total time for the XTHRU and RATSIMP are considerably
less than that for just the RATSIMP of the original expression."
"Now, we will turn off the TIME printout again, by setting TIME to FALSE."
(MACSYMA '((MSETQ) $SHOWTIME $FALSE))
"Along with FACTOR, EXPAND, RATSIMP, and RATEXPAND,
MACSYMA also has a simplifier to handle expressions
involving logs, exponentials, and radicals. This
simplifier is called RADCAN, which is short for radical
canonical. RADCAN can take a long time to simplify
some expressions, so it should be used with this in mind."
"Would you like to try RADCAN on an expression?"
(AND (YESORNO) (SCRIPT 'TRYRADCAN NIL))
"Would you like to learn more about simplifying and manipulating
expressions?"
(AND (YESORNO) (SCRIPT '$SCRATCHPAD NIL))
"What would you like to go over now?"
(PRIMER-SELECT '($INTRO $SCRATCHPAD $ASSIGNMENT $SYNTAX $EXIT)) )
(DEFSCRIPT $SCRATCHPAD
"This is the SCRATCHPAD script."
"In some cases the user
will want to have access to a finer level of control over
his expressions. MACSYMA has commands which allow the
user to play with his expressions in the machine in much
the same way he would with paper and pencil."
"One important command of this type in MACSYMA is the SUBST
command. This command can be used to replace all
occurrences of a subexpression with some other expression
in an intermediate result. This is useful, for
example, in expressions involving trigonometric
functions, where the MACSYMA simplifiers are not willing,
for reasons of efficiency, to try all possible trigonometric
identities."
"SUBST(A,B,C) means substitute A for B in C. The
resulting expression will be mathematically equivalent to the
original expression if A is mathematically equivalent to B."
(SLEEP 2)
"Here is a simple example of the use of SUBST. The
numerator of this expression is equal to 1 for all X,
but the MACSYMA simplifiers will not simplify it directly."
(MACSYMA SUBST-EXAMPLE1)
"There are three ways to use SUBST on this example:"
"One could substitute 1 for SIN(X)^2+COS(X)^2"
"One could substitute 1-SIN(X)^2 for COS(X)^2"
"Or one could substitute 1-COS(X)^2 for SIN(X)^2"
"The first way is more direct, but in more complex
examples where the sin squared plus cos squared is deeply
entwined with other elements of the expression the second
or third way would be necessary. Pick the way you like
best and simplify the expression by using SUBST."
(INCHKP 'SUBEXAMPLE1)
"SUBST however, can only substitute for expressions
that constitute an extractable part of the larger expression they
are contained in. In the case where the thing that you
want to substitute for is embedded in the expression,
then a more powerful tool is needed. RATSUBST is a
command that can be helpful in these cases. Here is an
example of the same simplification as before but with it
embedded so that the COS(X)^2 is not easily extractable from
the expression."
(MACSYMA SUBST-EXAMPLE2)
"Now use RATSUBST to simplify the above."
(INCHKP 'SUBEXAMPLE2)
"In working with algebraic expressions by hand, one will
often take part of a larger expression and work with that for
a time. In MACSYMA that can by done by using the PART
command. The PART command takes two or more arguments.
The first is the expression and the rest are specifications
as to which part is to be taken. Each of the specifications
is an integer that tells which one of the top level operators
arguments to take. Consider this example:"
(MACSYMA EXAMPLE3)
"This is a quotient of sums and thus the quotient is the top
level operator. Its first argument is its numerator, and its
second argument is the denominator. Thus:"
(PCLINE (LIST '($PART) DLABEL 1))
"would return the numerator. If PART had been given a third
argument it would pick one of the terms of the numerator. Now
use the PART command to get the R from the above expression."
(SETQ $PARTSWITCH T)
(PARTCHK '$PART '$R)
(SETQ $PARTSWITCH NIL)
"What would you like to go over now?"
(PRIMER-SELECT '($INTRO $SIMPLIFICATION $ASSIGNMENT $SYNTAX $EXIT)) )
(DEFSCRIPT $SYNTAX
"This is the SYNTAX script."
"Input to MACSYMA is done with a syntax somewhat like that of
Fortran or Algol. All input lines are terminated
with a semi-colon (;). Input lines
are labeled consecutively starting with (C1), and then
(C2) (C3) etc. MACSYMA results are labeled from
(D1) on. Thus (D1) is the result of the computations
performed by MACSYMA on the user's input string (C1)."
"These line numbers may be used to refer to expressions."
(SLEEP 2)
"The display MACSYMA prints out is two dimensional, like a textbook.
You must be careful not to let this confuse you. If you want
to type in the mathematical expression 2X, which of course is
'2 times X', you must type '2*X' even though MACSYMA will
print back"
(DISPLA '((MTIMES) 2 $X))
"Try typing in 2X or some other expression times X:"
(SYNCHK '(MTIMES) '((MTIMES) 2 $X))
"* is the multiplication operator. The other operators MACSYMA
uses are:"
~! for Factorial,~
~^ or ** for Exponentiation,~
~* for Multiplication,~
~. for non-commutative multiplication~
~/ for Division, ~
~+ for Addition, and~
~- for Subtraction.~
(SLEEP 2)
"These operators are applied following the traditional rules for
operator precedence.
Do you know what is meant by operator precedence?"
(AND (NOT (YESORNO)) (SCRIPT 'PRECEDENCE NIL))
"Variables in MACSYMA (and names of functions and arrays) consist of
a string of numbers and letters including the character %. Other
characters may be included by preceding them with a backslash
(\). Variable names are not limited in length, but must not
begin with a number."
"Constants are either numbers or one of the special constants, pi, e
(the base of natural logarithms), or i (the square root of minus
one) which are written %PI, %E, and %I to distinguish them from
the variables pi, e, and i."
(SLEEP 2)
"An operator may appear before its argument(s), between its arguments
or after its argument. Operators that appear before their
arguments are usually functions (such as SIN and COS) or
MACSYMA commands (such as INTEGRATE or RATSIMP). The arguments
to these operators are enclosed in parentheses, for example"
(PCLINE '((%SIN) 3.141))
"or"
(PCLINE '(($INTEGRATE) $% $X))
"Would you like to practice typing in some expressions?"
(AND (YESORNO) (SCRIPT 'PRACTICE NIL))
"That's all for syntax.")
(DEFSCRIPT PRACTICE
"Let's start with a simple linear expression: type in the expression for"
(DISPLA PRAC-EXAMPLE1)
(INCHK PRAC-EXAMPLE1)
"Okay, now try one where you need to use some parentheses to get the proper
operator precedence"
(DISPLA PRAC-EXAMPLE2)
(INCHK PRAC-EXAMPLE2)
"Now try a ratio."
(DISPLA PRAC-EXAMPLE3)
(INCHK PRAC-EXAMPLE3)
"Okay, try another type of exponentiation"
(DISPLA PRAC-EXAMPLE4)
(INCHK PRAC-EXAMPLE4)
"Here's a polynomial"
(DISPLA PRAC-EXAMPLE5)
(INCHK PRAC-EXAMPLE5)
"Now try a slightly more complicated ratio:"
(DISPLA PRAC-EXAMPLE6)
(INCHK PRAC-EXAMPLE6)
"Would you like to continue with the Introductory Section of
the primer?"
(AND (NOT (YESORNO)) (SCRIPT '$HELP2 NIL)))
(DEFSCRIPT $HELP2
"What would you like to go over? "
#-Franz
(PRIMER-SELECT
'($CONSOLEPRIMER $INTRO $SIMPLIFICATION $SCRATCHPAD $SYNTAX $ASSIGNMENT $EXIT))
#+Franz
(PRIMER-SELECT
'($FRANZPRIMER $INTRO $SIMPLIFICATION $SCRATCHPAD $SYNTAX $ASSIGNMENT $EXIT)))
(DEFSCRIPT PRECEDENCE
"MACSYMA uses the conventional mathematical operator precedence."
"Would you like to see some examples of how MACSYMA represents
operator precedence?"
(AND (YESORNO) (SCRIPT 'PRECEDENCE1 NIL)))
(DEFSCRIPT PRECEDENCE1
"Uparrow, ^, for exponentiation, has higher precedence that * for
multiplication, so:"
(MACSYMA '((MTIMES) ((MEXPT) $A 2) $B))
"Asterisk, *, for multiplication has higher precedence than + for
addition, so:"
(MACSYMA '((MPLUS) $A ((MTIMES) $B $C)))
"Parentheses may be used to change the order of application of
operators,"
(MACSYMA '((MTIMES) ((MPLUS) $A $B) $C))
"If you need further examples, consult the MACSYMA Manual.
(Page 11 in Version 9, Page 2-4 in Version 10.)"
(SLEEP 7))
(DEFSCRIPT TRYRADCAN
"Type in this expression:"
(DISPLA RADCANEXAMPLE)
(INCHKP 'CHKRADCAN)
"Now use RADCAN on it."
(CMDCHKP (LIST '($RADCAN) DLABEL)))
(DEFSCRIPT $HELP
"Hello. Please terminate your responses with a ;.
What would you like to go over? (Select the number of the script you
would like to see.)
INTRO is a general introduction
for people who have never used MACSYMA or this PRIMER before."
#-Franz
(PRIMER-SELECT
'($CONSOLEPRIMER $INTRO $SIMPLIFICATION $SCRATCHPAD $SYNTAX $ASSIGNMENT $EXIT))
#+Franz
(PRIMER-SELECT
'($FRANZPRIMER $INTRO $SIMPLIFICATION $SCRATCHPAD $SYNTAX $ASSIGNMENT $EXIT)) )
(SETQ EXAMPLE1 '((MEXPT) ((MPLUS) $X 1) 3))
(SETQ EXAMPLE2 '((MQUOTIENT) $A
((MPLUS) ((MEXPT) $X 3) ((MTIMES) 2 ((MEXPT) $X 2)) $X)))
(SETQ EXAMPLE3 '((MQUOTIENT) ((MPLUS) $A $B $C) ((MPLUS) $Q $R $S)))
(SETQ EXAMPLE4 '(($FACTOR)
((MPLUS) ((MEXPT) $X 3)
((MTIMES) ((MEXPT) $X 2)
((MEXPT) $Y 2))
((MMINUS) ((MTIMES) $X ((MEXPT) $Z 2)))
((MMINUS) ((MTIMES) ((MEXPT) $Y 2)
((MEXPT) $Z 2))))))
(SETQ SUBST-EXAMPLE1 '((MQUOTIENT)
((MPLUS) ((MEXPT) ((%SIN) $X) 2)
((MEXPT) ((%COS) $X) 2))
((MPLUS) ((MEXPT) $X 2) 39)))
(SETQ SUBST-EXAMPLE2 '((MPLUS)
((MTIMES) ((MEXPT) ((%COS) $X) 3) ((%SIN) $X))
((MTIMES) ((%COS) $X) ((MEXPT) ((%SIN) $X) 3))))
(SETQ PRAC-EXAMPLE1 '((MPLUS)((MTIMES) 3 $X) 1))
(SETQ PRAC-EXAMPLE2 '((MEXPT)((MPLUS) $X 2) 3))
(SETQ PRAC-EXAMPLE3 '((MQUOTIENT) 1 ((%SIN) $X)))
(SETQ PRAC-EXAMPLE4 '((MEXPT) $%E ((MTIMES) 2 $%PI $%I)))
(SETQ PRAC-EXAMPLE5 '((MPLUS)((MEXPT) $X 2)((MTIMES) 2 $X) 1))
(SETQ PRAC-EXAMPLE6 '((MQUOTIENT) 1 ((MPLUS) ((MEXPT) $X 2) 3)))
(SETQ SIMPEXAMPLE1 '((MPLUS)((MQUOTIENT) 1 ((MEXPT) ((MPLUS) $Y $X) 3))
((MQUOTIENT) ((MPLUS) ((MEXPT) ((MPLUS) $X 2) 8)
((MMINUS) ((MTIMES) 2 $Y)))
((MEXPT) ((MPLUS) $Y $X) 8))))
(SETQ RADCANEXAMPLE '((MQUOTIENT)((MEXPT)((MPLUS)
((%LOG)((MPLUS)((MEXPT) $X 2) $X))
((MMINUS) ((%LOG) $X)))
$B)
((MEXPT)((%LOG)((MPLUS) $X 1))((MQUOTIENT) $B 2))))
(DEFUN NUMCHK (NUM)
(TERPRI)
(DO ANS (RETRIEVE NIL NIL) (RETRIEVE NIL NIL) NIL
(COND ((EQ '$NO ANS)
(TERPRI) (PRINC '|Well, all right, I'll show you.|)
(TERPRI)(PRIN1 NUM)(PRINC '|;|)(RETURN (TERPRI)))
((NOT (EQ (TYPEP ANS) 'FIXNUM))
(TERPRI)(PRINC '|That isn't a number.|)
(TERPRI)(PRINC '|Try again.|)(TERPRI))
((AND (> ANS 0)(NOT (> ANS NUM)))(RETURN (TERPRI)))
(T (TERPRI) (PRINC '|That number isn't in the list. Try again.|)
(TERPRI)))))
(DEFUN QUITCHK ()
(TERPRI)
(DO ((X (TYI)(TYI))) (NIL)
(COND ((OR (= X 103) (= X 71))
(TERPRI)
(PRINC '|That was just a G, try again.|)
(TERPRI)
(PRINC '|Hold down the control key.|)(TERPRI))
((= X 7)
(TERPRI)
(PRINC '|That's it, very good.|)
(TERPRI)
(PRINC '|Now we'll make it a quit character again, so|)
(TERPRI)
(PRINC '|only type it if you want to quit out of the PRIMER.|)
(RETURN (TERPRI)))
(T (TERPRI)
(PRINC '|Nope, not quite. Try again, hold down the control key|)
(TERPRI)
(PRINC '|and hit the G.|)(TERPRI)))))