math::polynomials(n)

๐Ÿ“ฆ
version 2.0 ยท 2 versions
, in fedora 43, fedora 44, nixos 26.05, nixpkgs unstable

๐ŸŽ€ 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 the polynomial command. 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 the polynomial command). 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 operand
  • list 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 operand
  • list 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 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? dropped. gone. not invited. ๐Ÿ’€

  • 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. this is the one that catches what divPolyn threw away. ๐Ÿ™ˆ

  • list polyn1 โ€” the first polynomial operand
  • list 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 examined
  • int 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 (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