1 | \begin{lisp:documentation}{parse}{FUNCTION}{{\sf \&optional} stream }
|
---|
2 | Parser of infis expressions with integer/rational coefficients
|
---|
3 | The 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
|
---|
6 | optionally enclosed in (); for example, the infix form
|
---|
7 | X\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
|
---|
9 | 3)) ($-$ 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]
|
---|
17 | parses to:
|
---|
18 | (:[ (/ (* ($-$ X Y) (+ X Y)) Z) (EXPT (+ X 1) 2))
|
---|
19 | Currently this function is implemented using M. Kantrowitz's INFIX
|
---|
20 | package.
|
---|
21 | \end{lisp:documentation}
|
---|
22 |
|
---|
23 | \begin{lisp:documentation}{alist$-$form}{FUNCTION}{plist vars }
|
---|
24 | Translates an expression PLIST, which should be a list of polynomials
|
---|
25 | in variables VARS, to an alist representation of a polynomial.
|
---|
26 | It 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 }
|
---|
38 | Parse an expression already in prefix form to an association list
|
---|
39 | form according to the internal CGBlisp polynomial syntax: a
|
---|
40 | polynomial 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))
|
---|
43 | evaluates 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 }
|
---|
49 | Parse string STR and return a polynomial as a sorted association
|
---|
50 | list 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)))
|
---|
55 | The functions PARSE$-$TO$-$SORTED$-$ALIST and
|
---|
56 | PARSE$-$STRING$-$TO$-$SORTED$-$ALIST sort terms by the predicate
|
---|
57 | defined 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) }
|
---|
61 | Parses streasm STREAM and returns a polynomial represented as
|
---|
62 | a 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))
|
---|
65 | returns
|
---|
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)
|
---|
70 | returns
|
---|
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$>$) }
|
---|
76 | Parse a string to a sorted alist form, the internal representation
|
---|
77 | of polynomials used by our system.
|
---|
78 | \end{lisp:documentation}
|
---|
79 |
|
---|
80 | \begin{lisp:documentation}{sort$-$poly$-$1}{FUNCTION}{p order }
|
---|
81 | Sort the terms of a single polynomial P using an admissible monomial
|
---|
82 | order 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$>$) }
|
---|
86 | Sort POLY$-$OR$-$POLY$-$LIST, which could be either a single
|
---|
87 | polynomial or a list of polynomials in internal alist representation,
|
---|
88 | using admissible monomial order ORDER. Each polynomial is sorted
|
---|
89 | using 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)) }
|
---|
93 | Evaluate an expression EXPR as polynomial
|
---|
94 | by substituting operators + $-$ * expt with
|
---|
95 | corresponding polynomial operators
|
---|
96 | and variables VARS with monomials (1 0 ... 0), (0 1 ... 0) etc.
|
---|
97 | We use special versions of binary
|
---|
98 | operators \$poly+, \$poly$-$, \$minus$-$poly, \$poly* and
|
---|
99 | \$poly$-$expt which work like the corresponding functions in the
|
---|
100 | POLY 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*) }
|
---|
104 | Evaluate an expression EXPR, which should be a polynomial
|
---|
105 | expression or a list of polynomial expressions (a list of expressions
|
---|
106 | marked by prepending keyword :[ to it) given in lisp prefix notation,
|
---|
107 | in variables VARS, which should be a list of symbols. The result of
|
---|
108 | the evaluation is a polynomial or a list of polynomials (marked by
|
---|
109 | prepending symbol '[) in the internal alist form. This evaluator is
|
---|
110 | used by the PARSE package to convert input from strings directly to
|
---|
111 | internal 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)))))) }
|
---|
115 | Generate a list of monomials ((1 0 ... 0) (0 1 0 ... 0) ... (0 0 ...
|
---|
116 | 1) which correspond to linear monomials X1, X2, ... XN.
|
---|
117 | \end{lisp:documentation}
|
---|
118 |
|
---|
119 | \begin{lisp:documentation}{convert$-$number}{FUNCTION}{number$-$or$-$poly n }
|
---|
120 | Returns NUMBER$-$OR$-$POLY, if it is a polynomial. If it is a number,
|
---|
121 | it converts it to the constant monomial in N variables. If the result
|
---|
122 | is 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 }
|
---|
126 | Add two polynomials P and Q, where each polynomial is either a
|
---|
127 | numeric constant or a polynomial in internal representation. If the
|
---|
128 | result 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 }
|
---|
132 | Subtract two polynomials P and Q, where each polynomial is either a
|
---|
133 | numeric constant or a polynomial in internal representation. If the
|
---|
134 | result 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 }
|
---|
138 | Negation of P is a polynomial is either a numeric constant or a
|
---|
139 | polynomial in internal representation. If the result is a number then
|
---|
140 | convert it to a polynomial in N variables.
|
---|
141 | \end{lisp:documentation}
|
---|
142 |
|
---|
143 | \begin{lisp:documentation}{\$poly*}{FUNCTION}{p q n order ring }
|
---|
144 | Multiply two polynomials P and Q, where each polynomial is either a
|
---|
145 | numeric constant or a polynomial in internal representation. If the
|
---|
146 | result 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 }
|
---|
150 | Divide a polynomials P which is either a numeric constant or a
|
---|
151 | polynomial in internal representation, by a number Q.
|
---|
152 | \end{lisp:documentation}
|
---|
153 |
|
---|
154 | \begin{lisp:documentation}{\$poly$-$expt}{FUNCTION}{p l n order ring }
|
---|
155 | Raise polynomial P, which is a polynomial in internal
|
---|
156 | representation or a numeric constant, to power L. If P is a number,
|
---|
157 | convert the result to a polynomial in N variables.
|
---|
158 | \end{lisp:documentation}
|
---|
159 |
|
---|