math::polynomials(3tcl)
π math::polynomials π
okay bestie, welcome to math::polynomials, a page straight out of the Tcl Math Library. it's giving 3tcl manual section energy, and honestly? polynomials have never been this cute. π
β¨ SYNOPSIS β¨
package require Tcl ?8.5?
package require math::polynomials ?1.0.2?
::math::polynomials::polynomial coeffs
::math::polynomials::polynCmd coeffs
::math::polynomials::evalPolyn polynomial x
::math::polynomials::addPolyn polyn1 polyn2
::math::polynomials::subPolyn polyn1 polyn2
::math::polynomials::multPolyn polyn1 polyn2
::math::polynomials::divPolyn polyn1 polyn2
::math::polynomials::remainderPolyn polyn1 polyn2
::math::polynomials::derivPolyn polyn
::math::polynomials::primitivePolyn polyn
::math::polynomials::degreePolyn polyn
::math::polynomials::coeffPolyn polyn index
::math::polynomials::allCoeffsPolyn polyn
πΈ DESCRIPTION πΈ
so this package is all about polynomial functions of one variable, and fr fr it does the most:
- the basic arithmetic operations are extended to polynomials β¨
- computing the derivatives and primitives of these functions
- evaluation through a general procedure or via specific procedures) π
π«Ά PROCEDURES π«Ά
the package defines the following public procedures, and yes we're going through every single one:
::math::polynomials::polynomial coeffsβ returns an (encoded) list that defines the polynomial. so like, a polynomial
f(x) = a + b.x + c.x**2 + d.x**3
can be defined via:
set f [::math::polynomials::polynomial [list $a $b $c $d]
list coeffsβ coefficients of the polynomial (in ascending order)
::math::polynomials::polynCmd coeffsβ makes you a brand new procedure that evaluates the polynomial. the name of the polynomial gets generated automatically, no cap. super useful if you gotta evaluate the polynomial so many times, because the procedure is literally just a single[expr]command. iconic.list coeffsβ coefficients of the polynomial (in ascending order), or the polynomial definition that thepolynomialcommand handed back
::math::polynomials::evalPolyn polynomial xβ evaluates the polynomial at x.list polynomialβ the polynomial's definition (as returned by thepolynomialcommand). order) π (yes the stray "order)" is in the original, we don't gatekeep)float xβ the coordinate at which to evaluate the polynomial
::math::polynomials::addPolyn polyn1 polyn2β returns a new polynomial that's the sum of the two others. math but make it β¨freshβ¨.list polyn1β the first polynomial operandlist polyn2β the second polynomial operand
::math::polynomials::subPolyn polyn1 polyn2β returns a new polynomial that's the difference of the two others.list polyn1β the first polynomial operandlist polyn2β the second polynomial operand
::math::polynomials::multPolyn polyn1 polyn2β returns a new polynomial that's the product of the two others. and if one of the arguments is a scalar value, the other polynomial just gets scaled. easy.list polyn1β the first polynomial operand or a scalarlist polyn2β the second polynomial operand or a scalar
::math::polynomials::divPolyn polyn1 polyn2β divides the first polynomial by the second polynomial and returns the result. the remainder is dropped, bye bestie πlist polyn1β the first polynomial operandlist polyn2β the second polynomial operand
::math::polynomials::remainderPolyn polyn1 polyn2β divides the first polynomial by the second polynomial and returns the remainder. (yes this is the one that keeps the leftovers.)list polyn1β the first polynomial operandlist polyn2β the second polynomial operand
::math::polynomials::derivPolyn polynβ differentiates the polynomial and returns the result. calculus slay. π₯list polynβ the polynomial to be differentiated
::math::polynomials::primitivePolyn polynβ integrates the polynomial and returns the result. the integration constant is set to zero, periodt.list polynβ the polynomial to be integrated
::math::polynomials::degreePolyn polynβ returns the degree of the polynomial.list polynβ the polynomial to be examined
::math::polynomials::coeffPolyn polyn indexβ returns the coefficient of the term of the index'th degree of the polynomial.list polynβ the polynomial to be examinedint indexβ the degree of the term
::math::polynomials::allCoeffsPolyn polynβ returns the coefficients of the polynomial (in ascending order).list polynβ the polynomial in question
π REMARKS ON THE IMPLEMENTATION π
so the implementation for evaluating the polynomials at some point uses Horn's rule, which guarantees numerical stability and a minimum of arithmetic operations. she's efficient AND stable, we love a multitasker. π
and to recognise that a polynomial definition is indeed a correct definition, it consists of a list of two elements: the keyword "POLYNOMIAL" and the list of coefficients in descending order. the latter makes it easier to implement Horner's rule. iykyk. π¦
π BUGS, IDEAS, FEEDBACK π
ngl this document, and the package it describes, will undoubtedly contain bugs and other problems. please report such in the category math :: polynomials of the Tcllib Trackers at http://core.tcl.tk/tcllib/reportlist. and please also report any ideas for enhancements you may have for either the package and/or the documentation, we wanna hear it bestie.
when proposing code changes, please provide unified diffs, i.e the output of diff -u.
note further that attachments are strongly preferred over inlined patches. attachments can be made by going to the Edit form of the ticket immediately after its creation, and then using the left-most button in the secondary navigation bar. okay? okay. π
β KEYWORDS β
math, polynomial functions
π CATEGORY π
Mathematics
π COPYRIGHT π
Copyright (c) 2004 Arjen Markus <arjenmarkus@users.sourceforge.net>
and that's the whole page, no skips no crumbs. this little love letter came to you from tcllib, version 1.0.2, and it lives at math::polynomials(3tcl). go forth and evaluate some polynomials, you absolute main character. πβ¨π¦
π¦ where this page comes from
- debian trixie: tcllib 2.0+dfsg-4 Β· Tcl
- ubuntu questing: tcllib 2.0+dfsg-4
- ubuntu resolute: tcllib 2.0+dfsg-5 Β· Tcl
- ubuntu stonking: tcllib 2.0+dfsg-6 Β· Tcl
- Copyright (c) 2004 Arjen Markus <arjenmarkus@users\&.sourceforge\&.net>
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms