Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions docs/src/mpolynomial.md
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,10 @@ The following functionality is also provided for all multivariate polynomials.
is_univariate(::MPolyRing{T}) where T <: RingElement
```

```@docs
var_indices(p::MPolyRingElem{T}) where T <: RingElement
```

```@docs
vars(p::MPolyRingElem{T}) where T <: RingElement
```
Expand Down
20 changes: 14 additions & 6 deletions src/MPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,19 +89,27 @@ Return the number of variables in `R`.
"""
number_of_generators(R::MPolyRing) = number_of_variables(R)

@doc raw"""
var_indices(p::MPolyRingElem{T}) where {T <: RingElement}

Return the indices of the variables actually occurring in $p$.
"""
function var_indices(p::MPolyRingElem{T}) where {T <: RingElement}
isused = zeros(Int, nvars(parent(p)))
for v in exponent_vectors(p)
isused .|= v # accumulate by OR-ing the exponent vectors
end
return findall(!iszero, isused)
end

@doc raw"""
vars(p::MPolyRingElem{T}) where {T <: RingElement}

Return the variables actually occurring in $p$.
"""
function vars(p::MPolyRingElem{T}) where {T <: RingElement}
R = parent(p)
n = nvars(R)
isused = zeros(Int, n)
for v in exponent_vectors(p)
isused .|= v # accumulate by OR-ing the exponent vectors
end
return [R[i] for i in 1:n if isused[i] != 0]
return [gen(R, i) for i in var_indices(p)]
end

@doc raw"""
Expand Down
1 change: 1 addition & 0 deletions src/exports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -598,6 +598,7 @@ export use_karamul
export valuation
export var
export var_index
export var_indices
export vars
export vector_space
export vector_space_dim
Expand Down
18 changes: 11 additions & 7 deletions src/generic/MPoly.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,17 @@ function gen(a::MPolyRing{T}, i::Int) where {T <: RingElement}
return a([one(base_ring(a))], exps)
end

function vars(p::MPoly{T}) where {T <: RingElement}
vars_in_p = Vector{MPoly{T}}(undef, 0)
n = nvars(p.parent)
function var_indices(p::MPoly)
vars_in_p = Int[]
n = nvars(parent(p))
exps = p.exps
gen_list = gens(p.parent)
for j = 1:n
for i = 1:length(p)
if exps[j, i] > 0
if p.parent.ord == :degrevlex
push!(vars_in_p, gen_list[j])
push!(vars_in_p, j)
else
push!(vars_in_p, gen_list[n - j + 1])
push!(vars_in_p, n - j + 1)
end
break
end
Expand All @@ -97,7 +96,12 @@ function vars(p::MPoly{T}) where {T <: RingElement}
if p.parent.ord != :degrevlex
vars_in_p = reverse(vars_in_p)
end
return(vars_in_p)
return vars_in_p
end

function vars(p::MPoly{T}) where {T <: RingElement}
R = parent(p)
return MPoly{T}[gen(R, i) for i in var_indices(p)]
end

@doc raw"""
Expand Down
1 change: 1 addition & 0 deletions src/generic/imports.jl
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ import ..AbstractAlgebra: use_karamul
import ..AbstractAlgebra: valuation
import ..AbstractAlgebra: var
import ..AbstractAlgebra: var_index
import ..AbstractAlgebra: var_indices
import ..AbstractAlgebra: vars
import ..AbstractAlgebra: vector_space_dim
import ..AbstractAlgebra: zero!
Loading