@@ -13,6 +13,9 @@ An abstract container for various polynomials.
13
13
"""
14
14
abstract type AbstractPolynomial{T} end
15
15
16
+ # We want ⟒(P{α…,T}) = P{α…}; this default
17
+ # works for most cases
18
+ ⟒ (P:: Type{<:AbstractPolynomial} ) = constructorof (P)
16
19
17
20
"""
18
21
Polynomials.@register(name)
@@ -36,17 +39,18 @@ macro register(name)
36
39
quote
37
40
Base. convert (:: Type{P} , p:: P ) where {P<: $poly } = p
38
41
Base. convert (P:: Type{<:$poly} , p:: $poly{T} ) where {T} = P (coeffs (p), p. var)
39
- Base. promote_rule (:: Type{$poly{T}} , :: Type{$poly{S}} ) where {T,S} =
42
+ Base. promote (p:: P , q:: Q ) where {T, P <: $poly{T} , Q <: $poly{T} } = p,q
43
+ Base. promote_rule (:: Type{<:$poly{T}} , :: Type{<:$poly{S}} ) where {T,S} =
40
44
$ poly{promote_type (T, S)}
41
- Base. promote_rule (:: Type{$poly{T}} , :: Type{S} ) where {T,S<: Number } =
45
+ Base. promote_rule (:: Type{<: $poly{T}} , :: Type{S} ) where {T,S<: Number } =
42
46
$ poly{promote_type (T, S)}
43
47
$ poly (coeffs:: AbstractVector{T} , var:: SymbolLike = :x ) where {T} =
44
48
$ poly {T} (coeffs, Symbol (var))
45
- $ poly {T} (x:: AbstractVector{S} , var = :x ) where {T,S<: Number } =
46
- $ poly (T .(x), var)
47
- $ poly {T} (n:: S , var = :x ) where {T, S<: Number } =
48
- $ poly (T[n], var)
49
- $ poly (n:: Number , var = :x ) = $ poly ([n], var)
49
+ $ poly {T} (x:: AbstractVector{S} , var:: SymbolLike = :x ) where {T,S<: Number } =
50
+ $ poly (T .(x), Symbol ( var) )
51
+ $ poly {T} (n:: S , var:: SymbolLike = :x ) where {T, S<: Number } =
52
+ $ poly (T[n], Symbol ( var) )
53
+ $ poly (n:: Number , var:: SymbolLike = :x ) = $ poly ([n], Symbol ( var) )
50
54
$ poly {T} (var:: SymbolLike = :x ) where {T} = variable ($ poly{T}, Symbol (var))
51
55
$ poly (var:: SymbolLike = :x ) = variable ($ poly, Symbol (var))
52
56
end
@@ -58,19 +62,20 @@ macro register1(name)
58
62
poly = esc (name)
59
63
quote
60
64
Base. convert (:: Type{P} , p:: P ) where {P<: $poly } = p
61
- Base. promote_rule (:: Type{$poly{α,T}} , :: Type{$poly{α,S}} ) where {α,T,S} =
65
+ Base. promote (p:: P , q:: Q ) where {α,T, P <: $poly{α,T} , Q <: $poly{α,T} } = p,q
66
+ Base. promote_rule (:: Type{<:$poly{α,T}} , :: Type{<:$poly{α,S}} ) where {α,T,S} =
62
67
$ poly{α,promote_type (T, S)}
63
- Base. promote_rule (:: Type{$poly{α,T}} , :: Type{S} ) where {α,T,S<: Number } =
68
+ Base. promote_rule (:: Type{<: $poly{α,T}} , :: Type{S} ) where {α,T,S<: Number } =
64
69
$ poly{α,promote_type (T,S)}
65
- function $poly {α,T} (x:: AbstractVector{S} , var:: Polynomials. SymbolLike = :x ) where {α,T,S}
70
+ function $poly {α,T} (x:: AbstractVector{S} , var:: SymbolLike = :x ) where {α,T,S}
66
71
$ poly {α,T} (T .(x), Symbol (var))
67
72
end
68
- $ poly {α} (coeffs:: AbstractVector{T} , var:: Polynomials. SymbolLike= :x ) where {α,T} =
73
+ $ poly {α} (coeffs:: AbstractVector{T} , var:: SymbolLike = :x ) where {α,T} =
69
74
$ poly {α,T} (coeffs, Symbol (var))
70
- $ poly {α,T} (n:: Number , var:: Polynomials. SymbolLike = :x ) where {α,T} = n* one ($ poly{α,T}, Symbol (var))
71
- $ poly {α} (n:: Number , var:: Polynomials. SymbolLike = :x ) where {α} = n* one ($ poly{α}, Symbol (var))
72
- $ poly {α,T} (var:: Polynomials. SymbolLike= :x ) where {α, T} = variable ($ poly{α,T}, Symbol (var))
73
- $ poly {α} (var:: Polynomials. SymbolLike= :x ) where {α} = variable ($ poly{α}, Symbol (var))
75
+ $ poly {α,T} (n:: Number , var:: SymbolLike = :x ) where {α,T} = n* one ($ poly{α,T}, Symbol (var))
76
+ $ poly {α} (n:: Number , var:: SymbolLike = :x ) where {α} = n* one ($ poly{α}, Symbol (var))
77
+ $ poly {α,T} (var:: SymbolLike = :x ) where {α, T} = variable ($ poly{α,T}, Symbol (var))
78
+ $ poly {α} (var:: SymbolLike = :x ) where {α} = variable ($ poly{α}, Symbol (var))
74
79
end
75
80
end
76
81
@@ -80,17 +85,18 @@ macro register2(name)
80
85
poly = esc (name)
81
86
quote
82
87
Base. convert (:: Type{P} , p:: P ) where {P<: $poly } = p
83
- Base. promote_rule (:: Type{$poly{α,β,T}} , :: Type{$poly{α,β,S}} ) where {α,β,T,S} =
88
+ Base. promote (p:: P , q:: Q ) where {α,β,T, P <: $poly{α,β,T} , Q <: $poly{α,β,T} } = p,q
89
+ Base. promote_rule (:: Type{<:$poly{α,β,T}} , :: Type{<:$poly{α,β,S}} ) where {α,β,T,S} =
84
90
$ poly{α,β,promote_type (T, S)}
85
- Base. promote_rule (:: Type{$poly{α,β,T}} , :: Type{S} ) where {α,β,T,S<: Number } =
91
+ Base. promote_rule (:: Type{<: $poly{α,β,T}} , :: Type{S} ) where {α,β,T,S<: Number } =
86
92
$ poly{α,β,promote_type (T, S)}
87
- $ poly {α,β} (coeffs:: AbstractVector{T} , var:: Polynomials. SymbolLike = :x ) where {α,β,T} =
93
+ $ poly {α,β} (coeffs:: AbstractVector{T} , var:: SymbolLike = :x ) where {α,β,T} =
88
94
$ poly {α,β,T} (coeffs, Symbol (var))
89
- $ poly {α,β,T} (x:: AbstractVector{S} , var = :x ) where {α,β,T,S<: Number } = $ poly {α,β,T} (T .(x), var)
90
- $ poly {α,β,T} (n:: Number , var = :x ) where {α,β,T} = n* one ($ poly{α,β,T}, var)
91
- $ poly {α,β} (n:: Number , var = :x ) where {α,β} = n* one ($ poly{α,β}, var)
92
- $ poly {α,β,T} (var= :x ) where {α,β, T} = variable ($ poly{α,β,T}, var)
93
- $ poly {α,β} (var= :x ) where {α,β} = variable ($ poly{α,β}, var)
95
+ $ poly {α,β,T} (x:: AbstractVector{S} , var:: SymbolLike = :x ) where {α,β,T,S<: Number } = $ poly {α,β,T} (T .(x), var)
96
+ $ poly {α,β,T} (n:: Number , var:: SymbolLike = :x ) where {α,β,T} = n* one ($ poly{α,β,T}, Symbol ( var) )
97
+ $ poly {α,β} (n:: Number , va :: SymbolLiker = :x ) where {α,β} = n* one ($ poly{α,β}, Symbol ( var) )
98
+ $ poly {α,β,T} (var:: SymbolLike = :x ) where {α,β, T} = variable ($ poly{α,β,T}, Symbol ( var) )
99
+ $ poly {α,β} (var:: SymbolLike = :x ) where {α,β} = variable ($ poly{α,β}, Symbol ( var) )
94
100
end
95
101
end
96
102
0 commit comments