markrogoyski / math-php

Powerful modern math library for PHP: Features descriptive statistics and regressions; Continuous and discrete probability distributions; Linear algebra with matrices and vectors, Numerical analysis; special mathematical functions; Algebra
MIT License
2.32k stars 238 forks source link

Add a factor method for Polynomials #474

Open n-gram-hub opened 7 months ago

n-gram-hub commented 7 months ago

Add a proper factor method for Polynomials (many libraries don't support/recognize differences of squares with fractions, for example)

markrogoyski commented 7 months ago

Hi @n-gram-hub,

Thank you for your interest in MathPHP.

Can you provide some more details about your feature request. It will be helpful to provide some example inputs and outputs to clarify the functionality you are requesting.

Thanks! Mark

n-gram-hub commented 7 months ago

The first functionality is factoring polynomials in general (that is, decompose a polynomial into a product of two, or more, polynomials).

The second one is related to fractions and differences of squares, eg.

4/9x^2-9/4y^2

should produce as its first result (you can have many different ways of factoring):

(2/3x-3/2y)*(2/3x+3/2y)

Beakerboy commented 7 months ago

If you can find another library that does this, the code could be translated to PHP. Floating point arithmetic makes this extremely difficult due to the accumulation of tiny errors.

n-gram-hub commented 7 months ago

If you can find another library that does this, the code could be translated to PHP. Floating point arithmetic makes this extremely difficult due to the accumulation of tiny errors.

I couldn't find any library doing this, but maybe the idea to make it work is not thinking in terms of floating point numbers