crowlogic / arb4j

arb4j is a Java API for the arbitrary precision ball arithmetic library found at http://arblib.org
Other
1 stars 0 forks source link

implement rational numbers and functions #417

Closed crowlogic closed 3 months ago

crowlogic commented 4 months ago

You're absolutely right! I apologize for my oversight. The issue lies in the fact that the argument 'x' is of type RealPolynomial, not a general expression. When dividing polynomials, the result is not always a polynomial but a rational function.

In your example:

var p = new RealPolynomial().set(1);
var q = new RealPolynomial(2).identity().shiftLeft(1);
var poverq = p.div(q, 128, new RealPolynomial());

The div method of RealPolynomial performs polynomial division, which returns the quotient and stores the remainder in the provided RealPolynomial object (poverq in this case).

In the output:

jshell> poverq
poverq ==> ∅
jshell> poverq.remainder
$34 ==> 1

The poverq polynomial is empty (∅) because the quotient of the division is not a polynomial. The remainder is 1, as the division of 1 by x^2 leaves a remainder of 1.

To handle this situation correctly, you need to modify the HypergeometricPolynomial class to work with rational functions instead of just polynomials. This involves updating the argument type to accept a more general expression that can represent both polynomials and rational functions.

One possible approach is to use a separate class for rational functions that can handle the division of polynomials and represent the result as a fraction of polynomials. Then, you can update the HypergeometricPolynomial class to work with these rational functions.

Alternatively, you can modify the evaluation logic in the HypergeometricPolynomial class to handle the division of polynomials explicitly and represent the result as a combination of the quotient and remainder.

I apologize for not considering this aspect earlier. Thank you for pointing out the issue and providing a clear example that demonstrates the problem.

crowlogic commented 4 months ago

ok. the idea is to add a RationalFunction type and add a method to RealPolynomial called asRationalFunction() which will return the rational function described by the remainder as the divisor

crowlogic commented 3 months ago

\documentclass{article} \usepackage{amsmath}

\begin{document}

\section*{Extended Polynomial Data Type Operations}

Define two functions ( f(x) ) and ( g(x) ) as follows: [ f(x) = \frac{a(x)}{b(x)} + r(x) ] [ g(x) = \frac{c(x)}{d(x)} + s(x) ]

where ( a(x), b(x), c(x), ) and ( d(x) ) are polynomials with ( b(x) \neq 0 ) and ( d(x) \neq 0 ), and ( r(x) ) and ( s(x) ) are the remainders.

The operations for the extended polynomial data type, which includes both a quotient and a remainder, are defined as follows:

\textbf{Addition:} [ f(x) + g(x) = \frac{a(x)d(x) + c(x)b(x)}{b(x)d(x)} + (r(x) + s(x)) ]

\textbf{Subtraction:} [ f(x) - g(x) = \frac{a(x)d(x) - c(x)b(x)}{b(x)d(x)} + (r(x) - s(x)) ]

\textbf{Multiplication:} [ f(x) \times g(x) = \frac{a(x)c(x)}{b(x)d(x)} + \frac{a(x)s(x)}{b(x)} + \frac{r(x)c(x)}{d(x)} + r(x)s(x) ]

\textbf{Division:} [ f(x) \div g(x) = \left( \frac{a(x)}{b(x)} + r(x) \right) \times \left( \frac{d(x)}{c(x)} \right) ]

Expanding and simplifying the division: [ f(x) \div g(x) = \left( \frac{a(x)}{b(x)} + r(x) \right) \times \frac{d(x)}{c(x)} ] [ f(x) \div g(x) = \frac{a(x)d(x)}{b(x)c(x)} + \frac{r(x)d(x)}{c(x)} ]

These operations ensure that the extended polynomial data type adheres to the axioms of a field, with special handling for the quotient and remainder.

\end{document}

crowlogic commented 3 months ago

the flint types are insufficient, i need ratios of real polynomials