This commit is contained in:
jverzani
2025-07-23 08:05:43 -04:00
parent 31ce21c8ad
commit c3a94878f3
50 changed files with 3711 additions and 1385 deletions

View File

@@ -18,7 +18,7 @@ import SymPy # imported only: some functions, e.g. degree, need qualification
---
While `SymPy` can be used to represent polynomials, there are also native `Julia` packages available for this and related tasks. These packages include `Polynomials`, `MultivariatePolynomials`, and `AbstractAlgebra`, among many others. (A search on [juliahub.com](juliahub.com) found over $50$ packages matching "polynomial".) We will look at the `Polynomials` package in the following, as it is straightforward to use and provides the features we are looking at for univariate polynomials.
While `SymPy` can be used to represent polynomials, there are also native `Julia` packages available for this and related tasks. These packages include `Polynomials`, `MultivariatePolynomials`, and `AbstractAlgebra`, among many others. (A search on [juliahub.com](https://juliahub.com) found almost $100$ packages matching "polynomial".) We will look at the `Polynomials` package in the following, as it is straightforward to use and provides the features we are looking at for *univariate* polynomials.
## Construction
@@ -76,7 +76,7 @@ Polynomials may be evaluated using function notation, that is:
p(1)
```
This blurs the distinction between a polynomial expression a formal object consisting of an indeterminate, coefficients, and the operations of addition, subtraction, multiplication, and non-negative integer powers and a polynomial function.
This blurs the distinction between a polynomial expression--a formal object consisting of an indeterminate, coefficients, and the operations of addition, subtraction, multiplication, and non-negative integer powers--and a polynomial function.
The polynomial variable, in this case `1x`, can be returned by `variable`:
@@ -86,14 +86,15 @@ The polynomial variable, in this case `1x`, can be returned by `variable`:
x = variable(p)
```
This variable is a `Polynomial` object, so can be manipulated as a polynomial; we can then construct polynomials through expressions like:
This variable is a `Polynomial` object that prints as `x`.
These variables can be manipulated as any polynomial. We can then construct polynomials through expressions like:
```{julia}
r = (x-2)^2 * (x-1) * (x+1)
```
The product is expanded for storage by `Polynomials`, which may not be desirable for some uses. A new variable can be produced by calling `variable()`; so we could have constructed `p` by:
The product is expanded for storage by `Polynomials`, which may not be desirable for some uses. A new variable can also be produced by calling `variable()`; so we could have constructed `p` by:
```{julia}
@@ -125,7 +126,7 @@ The `Polynomials` package has different ways to represent polynomials, and a fac
fromroots(FactoredPolynomial, [2, 2, 1, -1])
```
This form is helpful for some operations, for example polynomial multiplication and positive integer exponentiation, but not others such as addition of polynomials, where such polynomials must first be converted to the standard basis to add and are then converted back into a factored form.
This form is helpful for some operations, for example polynomial multiplication and positive integer exponentiation, but not others such as addition of polynomials, where such polynomials must first be converted to the standard basis to add and are then converted back into a factored form. (A task that may suffer from floating point roundoff.)
---
@@ -181,7 +182,7 @@ A consequence of the fundamental theorem of algebra and the factor theorem is th
:::{.callout-note}
## Note
`SymPy` also has a `roots` function. If both `Polynomials` and `SymPy` are used together, calling `roots` must be qualified, as with `Polynomials.roots(...)`. Similarly, `degree` is provided in both, so it too must be qualified.
`SymPy` also has a `roots` function. If both `Polynomials` and `SymPy` are used together, calling `roots` must be qualified, as with `Polynomials.roots(...)`. Similarly, `degree` is exported in both, so it too must be qualified.
:::