You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If `q` is non-constant, such as `variable(Polynomial, :y)`, then there would be an error due to the mismatched symbols. (The mathematical result would need a multivariate polynomial, not a univariate polynomial, as this package provides.)
585
585
586
-
The same conversion is done for polynomial multiplication: constant polynomials are treated as numbers; non-constant polynomials must have their symbols match.
586
+
The same conversion is done for polynomial multiplication: constant polynomials are treated as numbers; non-constant polynomials must have their symbols match.
587
587
588
588
There is an oddity -- though the following two computations look the same, they are technically different:
Both are constant polynomials over `Int`, but the first has the indeterminate `:y`, the second `:x`.
598
+
Both are constant polynomials over `Int`, but the first has the indeterminate `:y`, the second `:x`.
599
599
600
600
This technical difference causes no issues with polynomial addition or multiplication, as there constant polynomials are treated as numbers, but can be an issue when constant polynomials are used as array elements.
polynomial evaluation, here either with a scalar or a matrix:
710
+
711
+
```jldoctest non_number
712
+
julia> p(2)
713
+
2×2 Matrix{Int64}:
714
+
7 0
715
+
24 7
716
+
717
+
julia> p(b)
718
+
2×2 Matrix{Int64}:
719
+
3 0
720
+
18 3
721
+
```
722
+
723
+
But if the type `T` lacks support of some generic functions, such as `zero(T)` and `one(T)`, then there may be issues. For example, when `T <: AbstractMatrix` the output of `p-p` is an error, as the implementation assumes `zero(T)` is defined. For static arrays, this isn't an issue, as there is support for `zero(T)`. Other polynomial types, such as `SparsePolynomial` have less support, as some specialized methods assume more of the generic interface be implemented.
724
+
725
+
Similarly, using polynomials for `T` is a possibility:
But much doesn't. For example, implicit promotion can fail. For example, the scalar multiplication `p * b` will fail, as the methods assume this is the fallback polynomial multiplication and not the intended scalar multiplication.
755
+
756
+
672
757
## Rational functions
673
758
674
759
The package provides support for rational functions -- fractions of polynomials (for most types). The construction of the basic type mirrors the construction of rational numbers.
A polynomial type holds an indeterminate `X`; coefficients of type `T`, stored in some container type; and an implicit basis, such as the standard basis.
9
13
10
14
# Properties
11
15
- `coeffs` - The coefficients of the polynomial
16
+
17
+
# The type `T`
18
+
19
+
`T` need not be `T <: Number`, at the moment it is not restricted
20
+
21
+
Some `T`s will not be successful
22
+
23
+
* scalar mult: `c::Number * p::Polynomial` should be defined
24
+
* scalar mult: `c::T * p:Polynomial{T}` An ambiguity when `T <: AbstractPolynomial`
25
+
* scalar mult: `p:Polynomial{T} * c::T` need not commute
26
+
27
+
* scalar add/sub: `p::Polynomial{T} + q::Polynomial{T}` should be defined
28
+
* scalar sub: `p::Polynomial{T} - p::Polynomial{T}` generally needs `zeros(T,1)` defined for `zero(Polynomial{T})`
29
+
30
+
* poly mult: `p::Polynomial{T} * q::Polynomial{T}` Needs "`T * T`" defined (e.g. `Base.promote_op(*, Vector{Int}, Vector{Int}))` needs to be something.)
31
+
* poly powers: `p::Polynomial{T}^2` needs "`T^2`" defined
32
+
33
+
* implicit promotion: `p::Polynomial{T} + c::Number` needs `convert(T, c)` defined
This will implement simple self-conversions like `convert(::Type{MyPoly}, p::MyPoly) = p` and creates two promote rules. The first allows promotion between two types (e.g. `promote(Polynomial, ChebyshevT)`) and the second allows promotion between parametrized types (e.g. `promote(Polynomial{T}, Polynomial{S})`).
70
+
This will implement simple self-conversions like `convert(::Type{MyPoly}, p::MyPoly) = p` and creates two promote rules. The first allows promotion between two types (e.g. `promote(Polynomial, ChebyshevT)`) and the second allows promotion between parametrized types (e.g. `promote(Polynomial{T}, Polynomial{S})`).
38
71
39
72
For constructors, it implements the shortcut for `MyPoly(...) = MyPoly{T}(...)`, singleton constructor `MyPoly(x::Number, ...)`, conversion constructor `MyPoly{T}(n::S, ...)`, and `variable` alternative `MyPoly(var=:x)`.
40
73
"""
@@ -44,15 +77,15 @@ macro register(name)
44
77
Base.convert(::Type{P}, p::P) where {P<:$poly} = p
45
78
function Base.convert(P::Type{<:$poly}, p::$poly{T,X}) where {T,X}
0 commit comments