math::polynomials(3tcl)

πŸ“¦
version 2.0 Β· 2 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

πŸ’– 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 the polynomial command handed back
  • ::math::polynomials::evalPolyn polynomial x β€” evaluates the polynomial at x.
    • list polynomial β€” the polynomial's definition (as returned by the polynomial command). 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 operand
    • list 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 operand
    • list 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 scalar
    • list 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 operand
    • list 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 operand
    • list 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 examined
    • int 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 (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