11export FixedVariablesSet
22
3- struct FixedVariablesIdeal{V<: AbstractVariable , T<: Number , MT<: AbstractMonomialLike } <: AbstractPolynomialIdeal
4- substitutions:: Union{Nothing, Dict{V, T}}
5- end
6- function Base. convert (:: Type{FixedVariablesIdeal{V, T, MT}} , ideal:: FixedVariablesIdeal{V, T, MT} ) where {V<: AbstractVariable , T<: Number , MT<: AbstractMonomialLike }
3+ struct FixedVariablesIdeal{
4+ V<: AbstractVariable ,
5+ T<: Number ,
6+ MT<: AbstractMonomialLike ,
7+ } <: AbstractPolynomialIdeal
8+ substitutions:: Union{Nothing,Dict{V,T}}
9+ end
10+ function Base. convert (
11+ :: Type{FixedVariablesIdeal{V,T,MT}} ,
12+ ideal:: FixedVariablesIdeal{V,T,MT} ,
13+ ) where {V<: AbstractVariable ,T<: Number ,MT<: AbstractMonomialLike }
714 return ideal
815end
9- function Base. convert (:: Type{FixedVariablesIdeal{V, T, MT}} , ideal:: FixedVariablesIdeal{V, S, MT} ) where {V, S, T, MT}
16+ function Base. convert (
17+ :: Type{FixedVariablesIdeal{V,T,MT}} ,
18+ ideal:: FixedVariablesIdeal{V,S,MT} ,
19+ ) where {V,S,T,MT}
1020 subs = ideal. substitutions
1121 if subs != = nothing
12- subs = convert (Dict{V, T}, subs)
22+ subs = convert (Dict{V,T}, subs)
1323 end
14- return FixedVariablesIdeal {V, T, MT} (subs)
24+ return FixedVariablesIdeal {V,T, MT} (subs)
1525end
1626
17- function MP. variables (ideal:: FixedVariablesIdeal{V} ) where V
27+ function MP. variables (ideal:: FixedVariablesIdeal{V} ) where {V}
1828 if generate_nonzero_constant (ideal)
1929 return V[]
2030 else
21- return sort (collect (keys (ideal. substitutions)), rev= true )
31+ return sort (collect (keys (ideal. substitutions)); rev = true )
2232 end
2333end
2434# In that case, the ideal can generate any polynomial.
@@ -34,15 +44,26 @@ function Base.rem(p::AbstractPolynomialLike, I::FixedVariablesIdeal)
3444 end
3545end
3646
37- struct FixedVariablesSet{V, T, MT} <: AbstractAlgebraicSet
38- ideal:: FixedVariablesIdeal{V, T, MT}
39- end
40- MP. similar_type (:: Type{FixedVariablesSet{V, S, MT}} , T:: Type ) where {V, S, MT} = FixedVariablesSet{V, T, MT}
41- function Base. convert (:: Type{FixedVariablesSet{V, T, MT}} , set:: FixedVariablesSet{V, T, MT} ) where {V, T, MT}
47+ struct FixedVariablesSet{V,T,MT} <: AbstractAlgebraicSet
48+ ideal:: FixedVariablesIdeal{V,T,MT}
49+ end
50+ function MP. similar_type (
51+ :: Type{FixedVariablesSet{V,S,MT}} ,
52+ T:: Type ,
53+ ) where {V,S,MT}
54+ return FixedVariablesSet{V,T,MT}
55+ end
56+ function Base. convert (
57+ :: Type{FixedVariablesSet{V,T,MT}} ,
58+ set:: FixedVariablesSet{V,T,MT} ,
59+ ) where {V,T,MT}
4260 return set
4361end
44- function Base. convert (:: Type{FixedVariablesSet{V, T, MT}} , set:: FixedVariablesSet{V, S, MT} ) where {V, S, T, MT}
45- return FixedVariablesSet (convert (FixedVariablesIdeal{V, T, MT}, set. ideal))
62+ function Base. convert (
63+ :: Type{FixedVariablesSet{V,T,MT}} ,
64+ set:: FixedVariablesSet{V,S,MT} ,
65+ ) where {V,S,T,MT}
66+ return FixedVariablesSet (convert (FixedVariablesIdeal{V,T,MT}, set. ideal))
4667end
4768
4869ideal (set:: FixedVariablesSet , args... ) = set. ideal
@@ -54,14 +75,17 @@ function nequalities(set::FixedVariablesSet)
5475 return length (set. ideal. substitutions)
5576 end
5677end
57- function equalities (set:: FixedVariablesSet{V, T, MT} ) where {V, T, MT}
78+ function equalities (set:: FixedVariablesSet{V,T, MT} ) where {V,T, MT}
5879 if set. ideal. substitutions === nothing
5980 return [constant_term (one (T), MT)]
6081 else
6182 return [key - value for (key, value) in set. ideal. substitutions]
6283 end
6384end
64- function Base. intersect (V:: FixedVariablesSet{V1, T1, MT1} , W:: FixedVariablesSet{V2, T2, MT2} ) where {V1, V2, T1, T2, MT1, MT2}
85+ function Base. intersect (
86+ V:: FixedVariablesSet{V1,T1,MT1} ,
87+ W:: FixedVariablesSet{V2,T2,MT2} ,
88+ ) where {V1,V2,T1,T2,MT1,MT2}
6589 # For `DynamicPolynomials`, they have the same type and for
6690 # `TypedPolynomials`, promoting would give `Monomial`.
6791 VT = V1 == V2 ? V1 : AbstractVariable
@@ -76,14 +100,14 @@ function Base.intersect(V::FixedVariablesSet{V1, T1, MT1}, W::FixedVariablesSet{
76100 end
77101 return a
78102 end
79- sub = Dict {VT, T} ()
103+ sub = Dict {VT,T} ()
80104 merge! (combine, sub, V. ideal. substitutions)
81105 merge! (combine, sub, W. ideal. substitutions)
82106 if has_dup
83107 sub = nothing
84108 end
85109 end
86- ideal = FixedVariablesIdeal {VT, T, promote_type(MT1, MT2)} (sub)
110+ ideal = FixedVariablesIdeal {VT,T, promote_type(MT1, MT2)} (sub)
87111 return FixedVariablesSet (ideal)
88112end
89113function Base. intersect (V:: AlgebraicSet , W:: FixedVariablesSet )
@@ -103,12 +127,12 @@ end
103127# Assumes `isempty(V)`
104128function only_point (V:: FixedVariablesSet )
105129 subs = collect (V. ideal. substitutions)
106- sort! (subs, rev = true , by = sub -> sub[1 ])
130+ sort! (subs; rev = true , by = sub -> sub[1 ])
107131 return [sub[2 ] for sub in subs]
108132end
109133
110- Base. eltype (:: FixedVariablesSet{V, T} ) where {V, T} = Vector{T}
111- function Base. iterate (V:: FixedVariablesSet , state= nothing )
134+ Base. eltype (:: FixedVariablesSet{V,T} ) where {V,T} = Vector{T}
135+ function Base. iterate (V:: FixedVariablesSet , state = nothing )
112136 if state === nothing && ! isempty (V)
113137 return only_point (V), true
114138 else
@@ -117,7 +141,7 @@ function Base.iterate(V::FixedVariablesSet, state=nothing)
117141end
118142Base. length (V:: FixedVariablesSet ) = isempty (V) ? 0 : 1
119143
120- struct FixedVariable{V<: AbstractVariable , T}
144+ struct FixedVariable{V<: AbstractVariable ,T}
121145 variable:: V
122146 value:: T
123147end
130154
131155function Base. intersect (el:: FixedVariable ; kws... )
132156 subs = Dict (el. variable => el. value)
133- return FixedVariablesSet (FixedVariablesIdeal{
134- typeof (el. variable), typeof (el. value), typeof (el. variable)}(subs))
157+ return FixedVariablesSet (
158+ FixedVariablesIdeal{
159+ typeof (el. variable),
160+ typeof (el. value),
161+ typeof (el. variable),
162+ }(
163+ subs,
164+ ),
165+ )
135166end
0 commit comments