math::polynomials(n)
๐ math::polynomials ๐
hiii bestie, welcome to the math::polynomials page, fresh out of the Tcl Math Library. it's giving polynomials, it's giving arithmetic, it's giving "let me do calculus on a list of numbers and look cute while doing it". ๐ฆ no cap, this one is lowkey iconic.
โจ NAME โจ
math::polynomials โ polynomial functions. that's the whole name, that's the whole vibe. ๐
๐ธ 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 ๐
okay so. this package is all about polynomial functions of one variable. the way that it does, like, three things and does them flawlessly:
- 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 ๐
periodt. that's the whole package and she ate. ๐
๐ PROCEDURES ๐
here's every public procedure the package defines, bestie. all of them. no skips, no cuts. โจ
::math::polynomials::polynomial coeffs
gives you back an (encoded) list that defines the polynomial. so a polynomial like
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โ the coefficients of the polynomial (in ascending order). yes, ascending. don't come for me, that's just how she is. ๐
::math::polynomials::polynCmd coeffs
makes you a brand new procedure that evaluates the polynomial. the name of the polynomial is automatically generated for you, so you don't gotta name it yourself. super useful if you need to evaluate the polynomial many times, because the procedure consists of a single [expr] command. efficient queen. ๐
list coeffsโ the coefficients of the polynomial (in ascending order) or the polynomial definition returned by thepolynomialcommand. either one works, we're flexible. ๐ซถ
::math::polynomials::evalPolyn polynomial x
evaluates the polynomial at x. that's it, that's the function. โญ
list polynomialโ the polynomial's definition (as returned by thepolynomialcommand).order)float xโ the coordinate at which to evaluate the polynomial.
::math::polynomials::addPolyn polyn1 polyn2
returns a new polynomial that is the sum of the two others. math but make it cute. โจ
list polyn1โ the first polynomial operandlist polyn2โ the second polynomial operand
::math::polynomials::subPolyn polyn1 polyn2
returns a new polynomial that is the difference of the two others. subtraction nation rise. ๐ฆ
list polyn1โ the first polynomial operandlist polyn2โ the second polynomial operand
::math::polynomials::multPolyn polyn1 polyn2
returns a new polynomial that is the product of the two others. and listen: if one of the arguments is a scalar value, the other polynomial is simply scaled. no drama, just scaling. ๐
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? dropped. gone. not invited. ๐
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. this is the one that catches what divPolyn threw away. ๐
list polyn1โ the first polynomial operandlist polyn2โ the second polynomial operand
::math::polynomials::derivPolyn polyn
differentiates the polynomial and returns the result. calculus girlies, this is your moment. ๐ฅ
list polynโ the polynomial to be differentiated
::math::polynomials::primitivePolyn polyn
integrates the polynomial and returns the result. heads up: the integration constant is set to zero. that's the rule, bestie, don't @ me. ๐
list polynโ the polynomial to be integrated
::math::polynomials::degreePolyn polyn
returns the degree of the polynomial. short, sweet, slay. โญ
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. iykyk. ๐ง
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). all of them. every single one. ๐
list polynโ the polynomial in question
๐ฎ REMARKS ON THE IMPLEMENTATION ๐ฎ
okay nerdy moment, but it's a cute nerdy moment. ๐ซถ the implementation for evaluating the polynomials at some point uses Horn's rule, which guarantees numerical stability and a minimum of arithmetic operations. obsessed with the efficiency ngl.
and so you can 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. (that's descending, bestie โ the latter makes it easier to implement Horner's rule.) ๐
๐ BUGS, IDEAS, FEEDBACK ๐
real talk: this document, and the package it describes, will undoubtedly contain bugs and other problems. it's not a flaw, it's a personality trait, but still โ please report such in the category math :: polynomials of the Tcllib Trackers http://core.tcl.tk/tcllib/reportlist. please also report any ideas for enhancements you may have for either package and/or documentation. we want them all. ๐
when proposing code changes, please provide unified diffs, i.e the output of diff -u. it's giving organized, it's giving helpful.
also 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. that's the move, bestie. ๐ฏ
โญ KEYWORDS โญ
math, polynomial functions
๐ CATEGORY ๐
Mathematics
๐ COPYRIGHT ๐
Copyright (c) 2004 Arjen Markus <arjenmarkus@users.sourceforge.net>
and that's a wrap on math::polynomials(n), bestie!! ๐ฆ this page lives in tcllib, version 1.0.2, and it's the math::polynomials(n) page from the Tcl Math Library. now go forth and do polynomial arithmetic, you main character. ๐
โจ๐ธ
๐ฆ where this page comes from
- fedora 43: tcllib 2.0-3.fc43 ยท TCL
- fedora 44: tcllib 2.0-4.fc44 ยท TCL
- nixos 26.05: tcllib 2.0
- nixpkgs unstable: tcllib 2.0
- 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