home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ARM Club 3
/
TheARMClub_PDCD3.iso
/
hensa
/
maths
/
b116_1
/
jacal
/
English
< prev
next >
Wrap
Text File
|
1993-12-21
|
17KB
|
508 lines
;;; JACAL: Symbolic Mathematics System. -*-scheme-*-
;;; Copyright (C) 1989, 1990, 1991, 1992, 1993 Aubrey Jaffer.
;;; See the file `COPYING' for terms applying to this program.
(define tran:translations
'((Last-expression-lost . "; Last expression lost.")
(bad-arglist . "bad arglist ")
(Column-of-non-matrix?:-- . "Column of non-matrix?: ")
(Coordinate-out-of-range:-- . "Coordinate out of range: ")
(funny-length-vectors . "funny length vectors ")
(unequal-length-vectors . "unequal length vectors ")
(Did-not-verify: . "Did not verify:")
(ERROR . "ERROR")
(Expt-of-equation?:-- . "Expt of equation?: ")
(Inexact-number-to-eval:- . "Inexact number to eval: ")
(Non-rational-radicand:-- . "Non-rational radicand: ")
(Not-a-Number . "Not a Number")
(Not-a-matrix:-- . "Not a matrix: ")
(Row-of-non-matrix?:-- . "Row of non-matrix?: ")
(application . "application ")
(argument . " argument ")
(arguments . " arguments ")
(bad-info-entry . "bad info entry")
(bunch . "bunch")
(can-not-be-read . "can not be read")
(can-not-be-set . "can not be set")
(cannot-be-coerced-to-expl:-- . "cannot be coerced to expl:")
(cannot-be-coerced-to-expr:-- . "cannot be coerced to expr: ")
(cannot-be-coerced-to-implicit:-- . "cannot be coerced to implicit: ")
(cannot-be-coerced-to-poly-eqn:-- . "cannot be coerced to poly eqn: ")
(cannot-extract-denominator- . "cannot extract denominator ")
(cannot-extract-numerator- . "cannot extract numerator ")
(cannot-read-null-grammar . "cannot read null grammar")
(cannot-suchthat-a-vector . "cannot suchthat a vector")
(cc-of . "cc of ")
(column-vector . "column vector")
(could-not-clear-denominator-of:- . "could not clear denominator of: ")
(delimiter-expected--ignoring-rest . "delimiter expected-ignoring rest")
(determinant-of-non-square-matrix . "determinant of non-square matrix")
(differential- . "differential ")
(does-not-appear-in- . " does not appear in ")
(does-not-divide- . " does not divide ")
(does-not-udivide- . " does not udivide ")
(dotproduct-of-unequal-size-matrices:-- . "dotproduct of unequal size matrices: ")
(elim-bunch?- . "elim bunch?")
(eliminating-from-more-than-one-expression?- . "eliminating from more than one expression?")
(eliminating: . "eliminating:")
(elimination-type-not-handled . "elimination type not handled")
(equation . "equation")
(expected-boolean . "expected boolean")
(expected-boolean-or-number . "expected boolean or number")
(expected-simple-symbol . "expected simple symbol")
(expression-missing . "expression missing")
(extra-delimiter . "extra delimiter")
(extra-separator . "extra separator")
(false . "false")
(flag . "flag")
(for-help. . " for help.")
(free-var-to-var:elim . "free var to var:elim")
(from: . " from:")
(function-of- . " function of ")
(grammar . "grammar")
(implicit-expression . "implicit expression")
(is-not-defined . "is not defined")
(matrix . "matrix")
(matrix-product-of-unequal-size-matrices:-- . "matrix product of unequal size matrices: ")
(mismatched-delimiter . "mismatched delimiter")
(more . "--more--")
(no-example-for . "no example for ")
(no-value-to-set . "no value to set")
(no-variables? . "no variables?")
(non-integer-power?-- . "non-integer power? ")
(normalize-symbol?- . "normalize symbol? ")
(normalizing: . "normalizing:")
(not-a-bunch? . "not a bunch?")
(not-a-function? . "not a function?")
(not-a-polynomial-equation . "not a polynomial equation")
(not-a-polynomial? . "not a polynomial?")
(not-a-simple-variable:- . "not a simple variable: ")
(not-an-integer- . "not an integer ")
(not-an-operator . "not an operator")
(not-canonical . "not canonical ")
(not-enough-equations . "not enough equations")
(not-known . "not known")
(not-s-expression . " not s-expression")
(number . "number")
(of- . " of ")
(off . "off")
(on . "on")
(or- . " or ")
(partial-with-respect-to? . "partial with respect to?")
(polynomial . "polynomial")
(q-to-quit-space-for-more:- . " q to quit, space for more: ")
(radical . "radical")
(rational-expression . "rational expression")
(redefined-from- . " redefined from ")
(redefined-to- . " redefined to ")
(row-vector . "row vector")
(to- . " to ")
(to-return-to- . " to return to ")
(trouble-with . "trouble with ")
(true . "true")
(type . "type ")
(type- . ", type ")
(unknown . "unknown")
(value-expected-equation-found:-- . "value expected, equation found: ")
(variable . "variable ")
(wna . ": Wrong number of args ")
(wta . ": Wrong type ")
(yielding: . "yielding:")))
;;;; Here are the templates for 2 dimensional output
(define tps:2d
'(
(TEMPLATE:DEFAULT 140 #d0140 "(" #d1010 #(REST ", " #d2010) ")")
(TEMPLATE:BUNCH 140 "[" #d0010 #(REST ", " BREAK #d1010) "]")
(TEMPLATE:MATRIX 140 (#\[) #d0010 #(REST " " #d1010) (#\]))
(TEMPLATE:PARENTHESIS 200 "(" #d1010 ")")
(- 100 #d1100 " - " BREAK #d2101 #(REST " - " BREAK #d3101))
(NEGATE 100 "- " #d1100)
(+ 100 #d1100 #(REST " + " BREAK #d2101))
(* 120 #d1120 #(REST " " #d2121))
(/ 120 #d1120 "/" #d2121)
(OVER 120 ((-1 #d1040)
(0 #\-)
(1 #d2040)))
(^ 140 #d1141 ((-1 #d2100)))
(= 80 #d1080 " = " BREAK #d2080 #(REST " = " BREAK #d3080))
(DIFFERENTIAL 170 #d1170 "'")
(PARTIAL 130 " " ((-1 "%")
(0 #\-)
(1 "%" #d2140)) " " #d1140)
(SUCHTHAT 40 "{" #d1190 " | " #d2040 "}")
(DEFINE 200 #d1120 ": " ((0 #d2010)))
(RAPPLY 200 #d1200 ((1 #d2030 #(REST "," #d3010))))
(ABS 200 (#\|) #d1010 (#\|))
(BOX 200 ((-1 #\")
(0 (#\") #d1010 (#\"))
(1 #\")))
(FACTORIAL 160 #d1160 "!")
(INTEGRATE 120 ((-3 #(OPTIONAL #d4090))
(-2 "/ ")
(-1 "! ")
(0 "! ")
(1 "! ")
(2 "/ ")
(3 #(OPTIONAL #d3090)))
#d1090 "d" #d2120)
(LIMIT 90 ((0 "limit ")
(1 #d2090 "->" #d3090))
#d1090)
(SUM 90 ((-3 #(OPTIONAL #d4090))
(-2 "====")
(-1 "\\ ")
(0 " > ")
(1 "/ ")
(2 "====")
(3 #(OPTIONAL #d2090 #(OPTIONAL" = " #d3090))))
#d1090)
(PROD 90 ((-3 " " #(OPTIONAL #d4090))
(-2 "/===/")
(-1 " ! ! ")
(0 " ! ! ")
(1 " ! ! ")
(2 #(OPTIONAL #d2090 #(OPTIONAL" = " #d3090))))
#d1090)
(AT 90 #d1090
((-2 "!")
(-1 "!")
(0 "!")
(1 "!")
(2 "!"))
((2 #d2010 #(REST ", " #d3010))))
(HELP 100 "help;")
(QED 100 "qed;")
(% 200 "%")
(NCMULT 110 #d1109 " . " #d2109)
(^^ 210 #d1211 "^^" #d2210)
))
(define tps:c
'(
(TEMPLATE:DEFAULT 140 #d0140 "(" #d1010 #(REST ", " #d2010) ")")
(TEMPLATE:BUNCH 140 "{" #d0010 #(REST ", " #d1010) "}")
(TEMPLATE:PARENTHESIS 200 "(" #d1010 ")")
(= 80 #d1080 " == " BREAK #d2080 #(REST "==" BREAK #d3080))
(- 100 #d1100 " - " BREAK #d2101 #(REST " - " BREAK #d3101))
(+ 100 #d1100 #(REST " + " BREAK #d2101))
(* 120 #d1120 #(REST " * " #d2121))
(NEGATE 90 "- " #d1090)
(/ 120 #d1120 "/" #d2121)
(OVER 120 #d1120 "/" #d2121)
(^ 140 "pow(" #d1141 ", " #d2100 ")")
(RAPPLY 200 #d1200 "[" #d2030 #(REST "," #d3010) "]")
(BOX 200 ((-1 #\")
(0 (#\") #d1010 (#\"))
(1 #\")))
(DEFINE 200 #d1120 " = " #d2010)
(SET 20 "set " #d1120 " " #d2010)
(SHOW 20 "show " #d1120)
))
(define tps:std
'(
(TEMPLATE:DEFAULT 140 #d0140 "(" #d1010 #(REST ", " #d2010) ")")
(TEMPLATE:BUNCH 140 "[" #d0010 #(REST ", " BREAK #d1010) "]")
(TEMPLATE:PARENTHESIS 200 "(" #d1010 ")")
(= 80 #d1080 " = " BREAK #d2080 #(REST " = " BREAK #d3080))
(- 100 #d1100 " - " BREAK #d2101 #(REST " - " BREAK #d3101))
(+ 100 #d1100 #(REST " + " BREAK #d2101))
(* 120 #d1120 #(REST " * " #d2121))
(NEGATE 90 "- " #d1090)
(/ 120 #d1120 "/" #d2121)
(OVER 120 #d1120 "/" #d2121)
(^ 140 #d1141 "^" #d2140)
(DIFFERENTIAL 170 #d1170 "'")
(SUCHTHAT 40 "{" #d1190 " | " #d2040 "}")
(RAPPLY 200 #d1200 "[" #d2030 #(REST "," #d3010) "]")
(BOX 200 ((-1 #\")
(0 (#\") #d1010 (#\"))
(1 #\")))
(DEFINE 200 #d1120 ": " #d2010)
(SET 20 "set " #d1120 " " #d2010)
(SHOW 20 "show " #d1120)
(FACTORIAL 160 #d1160 "!")
(HELP 100 "help;")
(QED 100 "qed;")
(% 200 "%")
(NCMULT 110 #d1109 " . " #d2109)
(^^ 210 #d1211 "^^" #d2210)
))
(define tps:tex
'(
(TEMPLATE:TOP 0 "$" #d1000 "$")
(TEMPLATE:DEFAULT 140 #d0140 "\\left(" #d1010
#(REST ", " #d2010) "\\right)")
(TEMPLATE:BUNCH 140 "\\left[" #d0010 #(REST ", " BREAK #d1010) "\\right]")
;;; (TEMPLATE:MATRIX 140 "\\left({\matrix{" #d0010 #(REST "&" #d1010)
;;; (#\\)(#\c)(#\r) "}}\\right)")
(TEMPLATE:PARENTHESIS 200 "\\left(" #d1010 "\\right)")
(= 80 #d1080 " = " BREAK #d2080 #(REST " = " BREAK #d3080))
(- 100 #d1100 " - " BREAK #d2101 #(REST " - " BREAK #d3101))
(+ 100 #d1100 #(REST " + " BREAK #d2101))
(* 120 #d1120 #(REST "\\," #d2121))
(NEGATE 90 "- " #d1100)
(/ 120 #d1120 "/{" BREAK #d2121 "}")
(OVER 120 "{" #d1040 "}\\over{" BREAK #d2041 "}")
(^ 140 #d1141 "^{" #d2100 "}")
(DIFFERENTIAL 170 "{" #d1170 "}'")
(SUCHTHAT 40 "\\left\\{ " #d1190 " | " BREAK #d2040 "\\right\\}")
(RAPPLY 200 #d1200 "\\left[" #d2030 #(REST "," BREAK #d3010) "\\right]")
(ABS 200 "\\left|" #d1010 "\\right|")
;;; (BOX 200 ((-1 #\")
;;; (0 (#\") #d1010 (#\"))
;;; (1 #\")))
(DEFINE 200 #d1120 ": " #d2010)
(SET 20 "set " #d1120 " " #d2010)
(SHOW 20 "show " #d1120)
(FACTORIAL 160 #d1160 "!")
(HELP 100 "help;")
(QED 100 "qed;")
(% 200 "%")
))
;;;;The parse tables.
(set! *lex-defs* '())
(set! *syn-defs* '())
;(set! *lex-defs* (make-hash-table 51))
;(set! *syn-defs* (make-hash-table 37))
;;;Syntax definitions for STANDARD GRAMMAR
(lex:def-class 70 '(#\^) #f)
(lex:def-class 49 '(#\*) #f)
(lex:def-class 50 '(#\/) #f)
(lex:def-class 51 '(#\+ #\-) #f)
(lex:def-class 20 '(#\|) #f)
(lex:def-class 30 '(#\< #\> #\= #\: #\~) #f)
(lex:def-class 40 '(#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9)
(lambda (l) (string->number (list->string l))))
(lex:def-class 41
'(#\A #\B #\C #\D #\E #\F #\G #\H #\I #\J #\K #\L #\M
#\N #\O #\P #\Q #\R #\S #\T #\U #\V #\W #\X #\Y #\Z
#\a #\b #\c #\d #\e #\f #\g #\h #\i #\j #\k #\l #\m
#\n #\o #\p #\q #\r #\s #\t #\u #\v #\w #\x #\y #\z
#\@ #\% #\? #\_)
#f)
(lex:def-class (lambda (chr) (or (eqv? #\" chr) (eof-object? chr)))
'(#\")
(lambda (l)
(lex:read-char) (string->symbol (list->string (cdr l)))))
;;; Ignore leading whitespace. ^Z (26) needs to be ignored in order
;;; to avoid problem at end of MSDOS files.
(define lex:whitespaces
(case (software-type)
((MSDOS) (list (integer->char 26)))
(else '())))
(do ((i (+ -1 (min 256 char-code-limit)) (+ -1 i))) ((negative? i))
(if (char-whitespace? (integer->char i))
(set! lex:whitespaces (cons (integer->char i) lex:whitespaces))))
(for-each (lambda (x) (lex:def-class 0 (list x) #f)) lex:whitespaces)
;;; Delimiters and Separators
(cgol:separator #\, 10)
(cgol:delim #\; 0)
(cgol:delim (integer->char 0) 0) ;EOF
;(cgol:postfix #\$ (lambda (x) (write x)) 0)
;;;prefix operators
(cgol:prefix '+ #f 100)
(cgol:prefix '- 'negate 100)
(cgol:prefix "+/-" 'u+/- 100)
(cgol:prefix "-/+" 'u-/+ 100)
(cgol:prefix '(NOT ~) 'impl:not 70)
(cgol:prefix ":" 'SetTemplate! 20)
;;;postfix operators
(cgol:postfix #\! 'factorial 160)
(cgol:postfix #\' 'Differential 170)
;;;infix operators
;(cgol:infix 'X 'crossproduct 111 110)
(cgol:infix #\. 'ncmult 110 109)
(cgol:infix '(^ **) '^ 140 139)
(cgol:infix '^^ '^^ 210 210)
(cgol:infix '(":=" ":") 'define 180 20)
(cgol:infix '= '= 80 80)
(cgol:infix '(~= <>) 'make-not-equal 80 80)
(cgol:infix 'mod 'mod 70 70)
;(cgol:infix "" '* 120 120) ;null operator
;;;nary operators
(cgol:nary '* '* 120)
(cgol:nary '+ '+ 100)
(cgol:nary '- '- 100)
(cgol:nary "+/-" 'b+/- 100)
(cgol:nary "-/+" 'b-/+ 100)
(cgol:nary '/ '/ 120)
(cgol:nary '(AND #\&) '& 60)
(cgol:nary 'OR 'or 50)
;;;special operators
(cgol:inmatchfix #\( #f #\) 200)
(cgol:inmatchfix #\[ 'rapply #\] 200)
;;;matchfix operators
(cgol:matchfix #\( #f #\))
(cgol:matchfix #\[ vector #\])
(cgol:matchfix #\{ 'or #\})
(cgol:matchfix #\\ 'lambda #\;)
(cgol:infix "|" 'suchthat 190 40)
(cgol:prefix 'load 'load 50)
(cgol:nofix '% '%)
(cgol:nofix 'help 'help)
(cgol:nofix '(QED bye exit) 'qed)
(cgol:commentfix
'/* (lambda ()
(define echoing (not (eq? (get-grammar 'null) *echo-grammar*)))
(do ((c (lex:read-char) (lex:read-char)))
((or (eof-object? c)
(and (char=? #\* c)
(char=? #\/ (lex:peek-char))))
(lex:read-char))
(if echoing (display c)))))
;;;rest operator reads expressions up to next delimiter.
(cgol:rest 'set 'set 10)
(cgol:rest 'show 'show 10)
(defgrammar 'standard
(make-grammar
'standard ;name
(lambda (grm) ;reader
(set! *lex-rules* (grammar-lex-tab grm))
(set! *syn-rules* (grammar-read-tab grm))
(cgol:top-parse #\, #\;))
*lex-defs* ;lex-tab
*syn-defs* ;read-tab
inprint ;writer
tps:std)) ;write-tab
(defgrammar 'disp2d
(make-grammar
'disp2d ;name
(lambda (grm) ;reader
(set! *lex-rules* (grammar-lex-tab grm))
(set! *syn-rules* (grammar-read-tab grm))
(cgol:top-parse #\, #\;))
*lex-defs* ;lex-tab
*syn-defs* ;read-tab
inprint ;writer
tps:2d)) ;write-tab
(set! *input-grammar* (get-grammar 'standard))
(set! *output-grammar* (get-grammar 'disp2d))
(set! *lex-defs* '())
(set! *syn-defs* '())
;(set! *lex-defs* (make-hash-table 51))
;(set! *syn-defs* (make-hash-table 37))
;;;Syntax definitions for TEX GRAMMAR
(lex:def-class 40 '(#\0 #\1 #\2 #\3 #\4 #\5 #\6 #\7 #\8 #\9)
(lambda (l) (string->number (list->string l))))
(lex:def-class 41
'(#\A #\B #\C #\D #\E #\F #\G #\H #\I #\J #\K #\L #\M
#\N #\O #\P #\Q #\R #\S #\T #\U #\V #\W #\X #\Y #\Z
#\a #\b #\c #\d #\e #\f #\g #\h #\i #\j #\k #\l #\m
#\n #\o #\p #\q #\r #\s #\t #\u #\v #\w #\x #\y #\z)
#f)
(let ((seen1 #f))
(lex:def-class
(lambda (chr)
(cond (seen1 (not (char-alphabetic? chr)))
((not (char-alphabetic? chr))
(set! seen1 chr) #t)
(else (set! seen1 #t) #f)))
'(#\\)
(lambda (l)
(cond ((char? seen1) (lex:read-char)
(set! l (list #\\ seen1))))
(set! seen1 #f)
(list->string l))))
;;; Ignore leading whitespace.
(for-each (lambda (x) (lex:def-class 0 (list x) #f)) lex:whitespaces)
;;; Ignore included text. Better to do using CGOL:COMMENTFIX.
;(lex:def-class (lambda (chr) (or (eqv? #\$ chr) (eof-object? chr)))
; '(#\$)
; (lambda (l) (lex:read-char) (lex)))
(cgol:commentfix
#\$ (lambda ()
(define echoing (not (eq? (get-grammar 'null) *echo-grammar*)))
(do ((c (lex:read-char) (lex:read-char)))
((or (eof-object? c)
(char=? #\$ c)))
(if echoing (display c)))))
(cgol:separator #\, 10)
(cgol:delim #\; 0)
(cgol:delim (integer->char 0) 0) ;EOF
(cgol:prefix #\+ #f 100)
(cgol:prefix #\- 'negate 100)
(cgol:postfix #\! 'factorial 160)
(cgol:postfix #\' 'Differential 170)
(cgol:infix #\: 'define 180 20)
(cgol:infix #\= '= 80 80)
(cgol:nary '(#\* "\\,") '* 120)
(cgol:nary #\+ '+ 100)
(cgol:nary #\- '- 100)
(cgol:nary #\/ '/ 120)
(cgol:nary "\\over" '/ 120)
(cgol:nary #\& vector 50)
(cgol:nary "\\cr" vector 49)
(cgol:commentfix '("\\left" "\\right"
"\\big" "\\bigm" "\\bigl" "\\bigr"
"\\bigg" "\\biggm" "\\biggl" "\\biggr"
"\\Big" "\\Bigm" "\\Bigl" "\\Bigr"
"\\Bigg" "\\Biggm" "\\Biggl" "\\Biggr")
#f)
(cgol:commentfix
#\% (lambda ()
(define echoing (not (eq? (get-grammar 'null) *echo-grammar*)))
(do ((c (lex:read-char) (lex:read-char)))
((or (eof-object? c)
(char=? #\newline c)))
(if echoing (display c)))))
(cgol:inmatchfix #\( #f #\) 200)
(cgol:matchfix #\( #f #\))
(cgol:matchfix #\{ #f #\})
(cgol:matchfix "\\lbrace" #f "\\rbrace")
(cgol:inmatchfix #\[ 'rapply #\] 200)
(cgol:inmatchfix "\\lbrack" 'rapply "\\rbrack" 200)
(cgol:matchfix #\[ vector #\])
(cgol:infix '(#\| "\\vert") 'suchthat 190 40)
(cgol:infix #\^ '^ 140 139)
(cgol:prefix "\\sqrt" (lambda (arg) `(^ ,arg (/ 1 2))) 100)
(cgol:prefix2 "\\frac" '/ 100)
;(cgol:delim "\\of" 10)
;(cgol:prefix "\\root" (lambda (arg) `(^ ,arg (/ 1 2))) 100)
(cgol:prefix 'load 'load 50)
(cgol:nofix '% '%)
(cgol:nofix 'help 'help)
(cgol:nofix '(QED bye exit) 'qed)
(cgol:rest 'set 'set 10)
(cgol:rest 'show 'show 10)
(defgrammar 'tex
(make-grammar
'tex ;name
(lambda (grm) ;reader
(set! *lex-rules* (grammar-lex-tab grm))
(set! *syn-rules* (grammar-read-tab grm))
(cgol:top-parse #\, #\;))
*lex-defs* ;lex-tab
*syn-defs* ;read-tab
inprint ;writer
tps:tex)) ;write-tab