Skip to main content

pynomials

This is a simple Mathematical Module which is extremely user-friendly. The module deals with mathematical Polynomials in one variable, namely "x". Using this module, the algebra of Polynomials can be easily performed in python.
Polynomial(an, ..., a2, a1, a0) -> anx^n + ... + a2x^2 + a1x^1 + a0x^0
A lot of help text is included in the class, and in the error messages, hence making the module easy to use.

Attributes of Polynomial objects

Polynomials have the following attributes:

  • self.degree = highest power of x
  • self.coeffs = (an, ..., a2, a1, a0)
  • self.a0, self.a1, self.a2, ... = a0, a1, a2, ...

Note: degree of Zero Polynomial is None as it is left exclusively undefined in Mathematics

Methods

  • add two Polynomials:

    returns the Polynomial obtained by adding the Polynomials
    can be achieved through p1 + p2

  • subtract two Polynomials:

    returns the Polynomial obtained by subtracting the Polynomials
    can be achieved through p1 - p2

  • multiply two Polynomials:

    returns the Polynomial obtained by multiplying the Polynomials
    can be achieved through p1 * p2

  • divide two Polynomials (/, //, %):

    / : returns the Rational Function obtained by p1 / p2 as a python function
    //: returns the Quotient obtained by p1 // p2 if the result is a Polynomial else None
    % : returns the Remainder obtained by p1 % p2 if the result of p1 // p2 is a Polynomial else None

  • raise Polynomials to integer powers:

    returns the Polynomial obtained by raising a Polynomial to an integer power
    can be obtained through p ** n

  • indexing a Polynomial:

    p[n] -> returns the coefficient of x^n (i.e. coefficient at degree n)

  • accessing Polynomial as a function:

    p1(n) -> returns the value of the Polynomial function at x = n
    p1(p2) -> returns the Polynomial obtained by composition defined as P(Q(x)) where P, Q = p1, p2

  • Polynomial.derivative(p)

    returns the Polynomial obtained by differentiating p

  • Polynomial.integral(p, c=0)

    returns the Polynomial obtained by integrating p at value of integrating constant c

Alternate Polynomial constructors:

  • Polynomial.FromRoots(root1, root2, ..., rootn)

    creates a Polynomial of degree n whose roots are given as arguments, where n is the number of roots

  • Polynomial.FromSequence(seq)

    creates a Polynomial whose components are taken from the given list, tuple or generator
    the elements of the sequence are passed to the Polynomial() constructor in order

And many more... Each function contains help text that can be accessed through help() in python to know more about it. Users are advised to read help() on methods they want to use to ensure required results.

Plotting a Polynomial

Two methods allow you to plot the Polynomial on a graph:

  • Polynomial.plot(p1, limits=(-100, 100)):

    plots single Polynomial

  • Polynomial.plot_polynomials(p1, p2, p3, ..., pn, limits=(-100, 100), show_legend=True):

    plots multiple Polynomials on the same grid
    show_legend is a boolean which displays legend on the plot if True

Note: limits should be a tuple containing the minimum and maximum values for x

Updates (0.0.4)

Added two more methods to class Polynomial:

  • Polynomial.definite_derivative(p, n)

    returns the value of derivaitve of p at x = n

  • Polynomial.definite_integral(p, a, b)

    returns the value of integral of p from lower limit a to upper limit b

Updates (0.0.5)

  • Minor bug fixes
  • Changes in division of Polynomials using // and % operators. Using these operators on Polynomials now strictly returns Polynomials, as they should.

Reach out to me

Feel free to reach out to me if you notice any bugs or if you need any kind of help from me in understanding the usage of the module or the source code. My email: knightt1821@gmail.com

Release files for pynomials 0.0.5

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pynomials 0.0.5
File Size Uploaded
pynomials-0.0.5.tar.gz 7.6 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pynomials 0.0.5
File Interpreter ABI Platform
pynomials-0.0.5-py3-none-any.whl Python 3 none any Details

Total release size: 15.4 kB

Release files / pynomials-0.0.5.tar.gz

Download URL pynomials-0.0.5.tar.gz
Size 7.6 kB
Tags Source
SHA-256 checksum
How to use checksums
9b7a806dad99fd8bf1af90513f25e8b16e7b4711819556c3303f0b429d0b3bbf
BLAKE2b-256 checksum
How to use checksums
692ca2ba6795605ceffdbd08cac6578324f0e04ca6acfe367c4761eb0005c004
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.1

Release files / pynomials-0.0.5-py3-none-any.whl

Download URL pynomials-0.0.5-py3-none-any.whl
Size 7.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ea3dba500fd25b5df9df7597b30306c0ee2ddf8b56bf1702e82ec7e81eb4d9fe
BLAKE2b-256 checksum
How to use checksums
2271b92e5215f1d3df297b5d34f9a711d36806cc601f4b5efb961d280fe82649
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.1

Release history Release notifications | RSS feed

This release

0.0.5 This release

2 release files

0.0.4

2 release files

0.0.3

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page