New library : purescript-sparse-polynomials

purescript-sparse-polynomials

A library to do various computations with sparse polynomials like

  • usual computations using univariate polynomials,
  • multivariate polynomials, or
  • numeric roots of real univariate polynomials

Documentation on Pursuit

https://pursuit.purescript.org/packages/purescript-sparse-polynomials

3 Likes

Is the a difference (besides normalization) between <> serves the same purpose as +?

I would find (+) to be more intuitive

That’s an interesting question and I think the answer have to belong in the philosophical realm rather than the technical one.
To defend myself, I propose the following analogy: when you build a vector X from its components x1 and x2, do you think you’re adding them ? I personnally think I’m glueing them because in order to add them, they should already have the shape (x1, 0) and (0, x2), meaning they’re already glued to something!
Furthermore, the hole in the <> operator reminds that nothing particular happens during the glueing process, which is not the case during the + operation (filtering of null coefficients, for instance).
I guess it’s a matter of point of view.

I see your point.

The multivariante modelling is really elegant.

1 Like

Thank you very much. I’m rather proud of it myself, especially since I’ve realized that I’ve solved the matrix modelling (my next goal) in the process.

Indeed, as there is a 1-to-1 correspondance between any matrix (say 2X3) and a polynomial in (x,y) (in this case : a00+a01y+a02y²+a10x+a11xy+a12xy²), I already have my matrix coefficients basis (a00^0^0, a01^0^1, a02^0^2, a10^1^0, a11^1^1 and a12^1^2) and setters!

In fact, this solves the tensor modelling too when considering more than x and y !!

That is quite clever. I wish you the best for your matrix library!

1 Like

Thanks ! I’m working on it! And to elaborate on your initial question, <> will also serve as a replacement/resetter operator in case of common exponents.
Thanks for your PR :pray:, it is now tested and merged.

I did not think of using <> as a replacement operator. Good point

Strangely, the 1-to-1 correspondance doesn’t provide a 1-to-1 correspondance between the bivariate polynomial product and the matrix product. It is still possible to use the first for the second but it is rather unusual. I had not implemented it like that in my matrix package but I will try to describe it as it is rather fun:
Let’s say we try to find the product of
2 1
3 5
and
4
6
by a polynomial method. Then define p(x,t)=2+t+3x+5xt and q(t,y)=4t+6 [note that powers of t are increasing for p, and decreasing for q]. Then from the product p(x,t)q(t,y)=14t+12+4t^2+42xt+18x+20xt^2 keep only those terms where t has exponent one-less-than-the-common-dimension-of-the-two-matrices (so 2-1=1) => 14t+42xt, then set t=1. Thus, as the result is 14+42x, the product is the matrix
14
42

Thanks, it is now on package-sets.

1 Like