2 poly - evaluate a polynomial
15 return Depends on argument types
19 clist List of coefficients
21 x, y, ... Coefficients
23 return Depends on argument types
25 Here an arithmetic type is one for which the required + and *
26 operations are defined, e.g. real or complex numbers or square
27 matrices of the same size. A coefficient is either of arithmetic
28 type or a list of coefficients.
31 If the first argument is not a list, and the necessary operations are
34 poly(a_0, a_1, ..., a_n, x)
38 a_n + (a_n-1 + ... + (a_1 + a_0 * x) * x ...) * x
40 If the coefficients a_0, a_1, ..., a_n and x are elements of a
41 commutative ring, e.g. if the coefficients and x are real or complex
42 numbers, this is the value of the polynomial:
44 a_0 * x^n + a_1 * x^(n-1) + ... + a_(n-1) * x + a_n.
46 For other structures (e.g. if addition is not commutative),
47 the order of operations may be relevant.
51 poly(a, x) returns the value of a.
53 poly(a, b, x) returns the value of b + a * x
55 poly(a, b, c, x) returns the value of c + (b + a * x) * x
58 If the first argument is a list as if defined by:
60 clist = list(a_0, a_1, ..., a_n)
62 and the coefficients a_i and x are are of arithmetic type,
63 poly(clist, x) returns:
65 a_0 + (a_1 + (a_2 + ... + a_n * x) * x)
67 which for a commutative ring, expands to:
69 a_0 + a_1 * x + ... + a_n * x^n.
71 If clist is the empty list, the value returned is the number 0.
73 Note that the order of the coefficients for the list case is the
74 reverse of that for the non-list case.
76 If one or more elements of clist is a list and there are more than
77 one arithmetic arguments x, y, ..., the coefficient corresponding
78 to such an element is the value of poly for that list and the next
79 argument in x, y, ... For example:
81 poly(list(list(a,b,c), list(d,e), f), x, y)
85 (a + b * y + c * y^2) + (d + e * y) * x + f * x^2.
87 Arguments in excess of those required for clist are ignored, e.g.:
89 poly(list(1,2,3), x, y)
91 returns the same as poly(list(1,2,3), x). If the number of
92 arguments is less than greatest depth of lists in clist, the
93 "missing" arguments are deemed to be zero. E.g.:
95 poly(list(list(1,2), list(3,4), 5), x)
99 poly(list(1, 3, 5), x).
101 If in the clist case, one or more of x, y, ... is a list, the
102 arguments to be applied to the polynomial are the successive
103 non-list values in the list or sublists. For example, if the x_i
106 poly(clist, list(x_0, x_1), x_2, list(list(x_3, x_4), x_5))
110 poly(clist, x_0, x_1, x_2, x_3, x_4, x_5).
113 ; print poly(2, 3, 5, 7), poly(list(5, 3, 2), 7), 5 + 3 * 7 + 2 * 7^2
116 ; mat A[2,2] = {1,2,3,4}
117 ; mat I[2,2] = {1,0,0,1}
118 print poly(2 * I, 3 * I, 5 * I, A)
120 mat [2,2] (4 elements, 4 nonzero)
126 ; P = list(list(0,0,1), list(0,2), 3); x = 4; y = 5
127 ; print poly(P,x,y), poly(P, list(x,y)), y^2 + 2 * y * x + 3 * x^2
131 The number of arguments is not to exceed 1024
134 BOOL evalpoly(LIST *clist, LISTELEM *x, VALUE *result);
139 ## Copyright (C) 1999-2006 Landon Curt Noll
141 ## Calc is open software; you can redistribute it and/or modify it under
142 ## the terms of the version 2.1 of the GNU Lesser General Public License
143 ## as published by the Free Software Foundation.
145 ## Calc is distributed in the hope that it will be useful, but WITHOUT
146 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
147 ## or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
148 ## Public License for more details.
150 ## A copy of version 2.1 of the GNU Lesser General Public License is
151 ## distributed with calc under the filename COPYING-LGPL. You should have
152 ## received a copy with calc; if not, write to Free Software Foundation, Inc.
153 ## 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
155 ## @(#) $Revision: 30.1 $
156 ## @(#) $Id: poly,v 30.1 2007/03/16 11:10:42 chongo Exp $
157 ## @(#) $Source: /usr/local/src/cmd/calc/help/RCS/poly,v $
159 ## Under source code control: 1995/12/02 02:40:43
160 ## File existed as early as: 1995
162 ## chongo <was here> /\oo/\ http://www.isthe.com/chongo/
163 ## Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/