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
Copy file name to clipboardExpand all lines: src/polynomials/ImmutablePolynomial.jl
+11-40Lines changed: 11 additions & 40 deletions
Original file line number
Diff line number
Diff line change
@@ -7,16 +7,19 @@ Construct an immutable (static) polynomial from its coefficients `a`,
7
7
lowest order first, optionally in terms of the given variable `x`
8
8
where `x` can be a character, symbol, or string.
9
9
10
-
If ``p = a_n x^n + \\ldots + a_2 x^2 + a_1 x + a_0``, we construct this through
11
-
`ImmutablePolynomial((a_0, a_1, ..., a_n))`.
10
+
If ``p = a_n x^n + \\ldots + a_2 x^2 + a_1 x + a_0``, we construct
11
+
this through `ImmutablePolynomial((a_0, a_1, ..., a_n))` (assuming
12
+
`a_n ≠ 0`). As well, a vector or number can be used for construction.
12
13
13
14
The usual arithmetic operators are overloaded to work with polynomials
14
15
as well as with combinations of polynomials and scalars. However,
15
16
operations involving two polynomials of different variables causes an
16
17
error, though for `+` and `*` operations, constant polynomials are
17
-
treated as having no variable. (This adds a runtime check, but is useful when working with matrices of polynomials.)
18
+
treated as having no variable.
18
19
19
-
As the coefficient size is a compile-time constant, immutable polynomials can take advantage of faster polynomial evaluation provided by `evalpoly` from Julia 1.4.
20
+
As the coefficient size is a compile-time constant, immutable
21
+
polynomials can take advantage of faster polynomial evaluation
22
+
provided by `evalpoly` from Julia 1.4.
20
23
21
24
# Examples
22
25
@@ -74,12 +77,6 @@ end
74
77
75
78
@register ImmutablePolynomial
76
79
77
-
#Base.promote_rule(::Type{ImmutablePolynomial{T,N}},q::Type{ImmutablePolynomial{S,M}}) where {T,N,S,M} =
78
-
# ImmutablePolynomial{promote_type(T,S)}
79
-
80
-
#Base.promote_rule(::Type{ImmutablePolynomial{T,N}}, ::Type{S}) where {T,N, S<:Number} =
81
-
# ImmutablePolynomial{promote_type(T, S)}
82
-
83
80
functionImmutablePolynomial{T,N}(coeffs::Tuple, var) where {T,N}
84
81
ImmutablePolynomial{T,N}(NTuple{N,T}(c for c in coeffs), var)
85
82
end
@@ -94,21 +91,6 @@ function ImmutablePolynomial(coeffs::NTuple{M,T}, var::SymbolLike=:x) where {M,
94
91
end
95
92
ImmutablePolynomial{T,N}(cs, var)
96
93
end
97
-
functionImmutablePolynomial(coeffs::Vector{T}, var::SymbolLike=:x) where {T}
98
-
N =findlast(!iszero, coeffs)
99
-
if N ==nothing
100
-
returnzero(ImmutablePolynomial{T},var)
101
-
else
102
-
cs =NTuple{N,T}(T(c) for c in coeffs[1:N])
103
-
end
104
-
ImmutablePolynomial{T,N}(cs, var)
105
-
end
106
-
107
-
#ImmutablePolynomial(n::T, var::SymbolLike = :x) where {T <: Number} =
0 commit comments