source: CGBLisp/latex-doc/parse.tex@ 1

Last change on this file since 1 was 1, checked in by Marek Rychlik, 15 years ago

First import of a version circa 1997.

File size: 7.6 KB
Line 
1\begin{lisp:documentation}{parse}{FUNCTION}{{\sf \&optional} stream }
2Parser of infis expressions with integer/rational coefficients
3The parser will recognize two kinds of polynomial expressions:
4$-$ polynomials in fully expanded forms with coefficients
5 written in front of symbolic expressions; constants can be
6optionally enclosed in (); for example, the infix form
7X\symbol{94}2$-$Y\symbol{94}2+($-$4/3)*U\symbol{94}2*W\symbol{94}3$-$5 parses to
8 (+ ($-$ (EXPT X 2) (EXPT Y 2)) (* ($-$ (/ 4 3)) (EXPT U 2) (EXPT W
93)) ($-$ 5))
10$-$ lists of polynomials; for example
11 [X$-$Y, X\symbol{94}2+3*Z]
12 parses to
13 (:[ ($-$ X Y) (+ (EXPT X 2) (* 3 Z)))
14 where the first symbol [ marks a list of polynomials.
15$-$other infix expressions, for example
16 [(X$-$Y)*(X+Y)/Z,(X+1)\symbol{94}2]
17parses to:
18 (:[ (/ (* ($-$ X Y) (+ X Y)) Z) (EXPT (+ X 1) 2))
19Currently this function is implemented using M. Kantrowitz's INFIX
20package.
21\end{lisp:documentation}
22
23\begin{lisp:documentation}{alist$-$form}{FUNCTION}{plist vars }
24Translates an expression PLIST, which should be a list of polynomials
25in variables VARS, to an alist representation of a polynomial.
26It returns the alist. See also PARSE$-$TO$-$ALIST.
27\end{lisp:documentation}
28
29\begin{lisp:documentation}{alist$-$form$-$1}{FUNCTION}{p vars {\sf \&aux} (ht (make$-$hash$-$table :test \#'equal :size 16)) stack }
30{\ } % NO DOCUMENTATION FOR ALIST-FORM-1
31\end{lisp:documentation}
32
33\begin{lisp:documentation}{powers}{FUNCTION}{monom vars {\sf \&aux} (tab (pairlis vars (make$-$list (length vars) :initial$-$element 0))) }
34{\ } % NO DOCUMENTATION FOR POWERS
35\end{lisp:documentation}
36
37\begin{lisp:documentation}{parse$-$to$-$alist}{FUNCTION}{vars {\sf \&optional} stream }
38Parse an expression already in prefix form to an association list
39form according to the internal CGBlisp polynomial syntax: a
40polynomial is an alist of pairs (MONOM . COEFFICIENT). For example:
41 (WITH$-$INPUT$-$FROM$-$STRING (S
42"X\symbol{94}2$-$Y\symbol{94}2+($-$4/3)*U\symbol{94}2*W\symbol{94}3$-$5") (PARSE$-$TO$-$ALIST '(X Y U W) S))
43evaluates to
44(((0 0 2 3) . $-$4/3) ((0 2 0 0) . $-$1) ((2 0 0 0) . 1) ((0 0 0 0) .
45$-$5))
46\end{lisp:documentation}
47
48\begin{lisp:documentation}{parse$-$string$-$to$-$alist}{FUNCTION}{str vars }
49Parse string STR and return a polynomial as a sorted association
50list of pairs (MONOM . COEFFICIENT). For example:
51(parse$-$string$-$to$-$alist
52"[x\symbol{94}2$-$y\symbol{94}2+($-$4/3)*u\symbol{94}2*w\symbol{94}3$-$5,y]" '(x y u w)) ([ (((0 0 2 3) . $-$4/3) ((0 2 0 0) . $-$1) ((2 0 0 0) . 1)
53 ((0 0 0 0) . $-$5))
54 (((0 1 0 0) . 1)))
55The functions PARSE$-$TO$-$SORTED$-$ALIST and
56PARSE$-$STRING$-$TO$-$SORTED$-$ALIST sort terms by the predicate
57defined in the ORDER package.
58\end{lisp:documentation}
59
60\begin{lisp:documentation}{parse$-$to$-$sorted$-$alist}{FUNCTION}{vars {\sf \&optional} (order \#'lex$>$) (stream t) }
61Parses streasm STREAM and returns a polynomial represented as
62a sorted alist. For example:
63(WITH$-$INPUT$-$FROM$-$STRING (S
64"X\symbol{94}2$-$Y\symbol{94}2+($-$4/3)*U\symbol{94}2*W\symbol{94}3$-$5") (PARSE$-$TO$-$SORTED$-$ALIST '(X Y U W) S))
65returns
66(((2 0 0 0) . 1) ((0 2 0 0) . $-$1) ((0 0 2 3) . $-$4/3) ((0 0 0 0) .
67$-$5)) and
68(WITH$-$INPUT$-$FROM$-$STRING (S
69"X\symbol{94}2$-$Y\symbol{94}2+($-$4/3)*U\symbol{94}2*W\symbol{94}3$-$5") (PARSE$-$TO$-$SORTED$-$ALIST '(X Y U W) T \#'GRLEX$>$) S)
70returns
71(((0 0 2 3) . $-$4/3) ((2 0 0 0) . 1) ((0 2 0 0) . $-$1) ((0 0 0 0) .
72$-$5))
73\end{lisp:documentation}
74
75\begin{lisp:documentation}{parse$-$string$-$to$-$sorted$-$alist}{FUNCTION}{str vars {\sf \&optional} (order \#'lex$>$) }
76Parse a string to a sorted alist form, the internal representation
77of polynomials used by our system.
78\end{lisp:documentation}
79
80\begin{lisp:documentation}{sort$-$poly$-$1}{FUNCTION}{p order }
81Sort the terms of a single polynomial P using an admissible monomial
82order ORDER. Returns the sorted polynomial. Destructively modifies P.
83\end{lisp:documentation}
84
85\begin{lisp:documentation}{sort$-$poly}{FUNCTION}{poly$-$or$-$poly$-$list {\sf \&optional} (order \#'lex$>$) }
86Sort POLY$-$OR$-$POLY$-$LIST, which could be either a single
87polynomial or a list of polynomials in internal alist representation,
88using admissible monomial order ORDER. Each polynomial is sorted
89using SORT$-$POLY$-$1.
90\end{lisp:documentation}
91
92\begin{lisp:documentation}{poly$-$eval$-$1}{FUNCTION}{expr vars order ring {\sf \&aux} (n (length vars)) }
93Evaluate an expression EXPR as polynomial
94by substituting operators + $-$ * expt with
95corresponding polynomial operators
96and variables VARS with monomials (1 0 ... 0), (0 1 ... 0) etc.
97We use special versions of binary
98operators \$poly+, \$poly$-$, \$minus$-$poly, \$poly* and
99\$poly$-$expt which work like the corresponding functions in the
100POLY package, but accept scalars as arguments as well.
101\end{lisp:documentation}
102
103\begin{lisp:documentation}{poly$-$eval}{FUNCTION}{expr vars {\sf \&optional} (order \#'lex$>$) (ring *coefficient$-$ring*) }
104Evaluate an expression EXPR, which should be a polynomial
105expression or a list of polynomial expressions (a list of expressions
106marked by prepending keyword :[ to it) given in lisp prefix notation,
107in variables VARS, which should be a list of symbols. The result of
108the evaluation is a polynomial or a list of polynomials (marked by
109prepending symbol '[) in the internal alist form. This evaluator is
110used by the PARSE package to convert input from strings directly to
111internal form.
112\end{lisp:documentation}
113
114\begin{lisp:documentation}{monom$-$basis}{FUNCTION}{n {\sf \&aux} (basis (copy$-$tree (make$-$list n :initial$-$element (list 'quote (list (cons (make$-$list n :initial$-$element 0) 1)))))) }
115Generate a list of monomials ((1 0 ... 0) (0 1 0 ... 0) ... (0 0 ...
1161) which correspond to linear monomials X1, X2, ... XN.
117\end{lisp:documentation}
118
119\begin{lisp:documentation}{convert$-$number}{FUNCTION}{number$-$or$-$poly n }
120Returns NUMBER$-$OR$-$POLY, if it is a polynomial. If it is a number,
121it converts it to the constant monomial in N variables. If the result
122is a number then convert it to a polynomial in N variables.
123\end{lisp:documentation}
124
125\begin{lisp:documentation}{\$poly+}{FUNCTION}{p q n order ring }
126Add two polynomials P and Q, where each polynomial is either a
127numeric constant or a polynomial in internal representation. If the
128result is a number then convert it to a polynomial in N variables.
129\end{lisp:documentation}
130
131\begin{lisp:documentation}{\$poly$-$}{FUNCTION}{p q n order ring }
132Subtract two polynomials P and Q, where each polynomial is either a
133numeric constant or a polynomial in internal representation. If the
134result is a number then convert it to a polynomial in N variables.
135\end{lisp:documentation}
136
137\begin{lisp:documentation}{\$minus$-$poly}{FUNCTION}{p n ring }
138Negation of P is a polynomial is either a numeric constant or a
139polynomial in internal representation. If the result is a number then
140convert it to a polynomial in N variables.
141\end{lisp:documentation}
142
143\begin{lisp:documentation}{\$poly*}{FUNCTION}{p q n order ring }
144Multiply two polynomials P and Q, where each polynomial is either a
145numeric constant or a polynomial in internal representation. If the
146result is a number then convert it to a polynomial in N variables.
147\end{lisp:documentation}
148
149\begin{lisp:documentation}{\$poly/}{FUNCTION}{p q ring }
150Divide a polynomials P which is either a numeric constant or a
151polynomial in internal representation, by a number Q.
152\end{lisp:documentation}
153
154\begin{lisp:documentation}{\$poly$-$expt}{FUNCTION}{p l n order ring }
155Raise polynomial P, which is a polynomial in internal
156representation or a numeric constant, to power L. If P is a number,
157convert the result to a polynomial in N variables.
158\end{lisp:documentation}
159
Note: See TracBrowser for help on using the repository browser.