Skip to content

Commit 0e34c39

Browse files
committed
PolyhedralGeometry: more operators on fans and complexes
1 parent 9627744 commit 0e34c39

File tree

4 files changed

+136
-1
lines changed

4 files changed

+136
-1
lines changed

src/PolyhedralGeometry/PolyhedralComplex/standard_constructions.jl

+66-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@doc raw"""
22
common_refinement(PC1::PolyhedralComplex{T},PC2::PolyhedralComplex{T}) where T<:scalar_types
33
4-
Return the common refinement of two polyhedral complexes.
4+
Return the common refinement of two polyhedral complexes.
55
66
# Examples
77
```jldoctest
@@ -75,3 +75,68 @@ function k_skeleton(PC::PolyhedralComplex{T}, k::Int) where {T<:scalar_types}
7575
)
7676
return PolyhedralComplex{T}(ksk, coefficient_field(PC))
7777
end
78+
79+
80+
###############################################################################
81+
## Scalar product
82+
###############################################################################
83+
84+
function *(c::QQFieldElem, Sigma::PolyhedralComplex)
85+
# if scalar is zero, return polyhedral complex consisting only of the origin
86+
if iszero(c)
87+
return polyhedral_complex(convex_hull(zero_matrix(QQ,1,ambient_dim(Sigma))))
88+
end
89+
90+
# if scalar is non-zero, multiple all vertices and rays by said scalar
91+
SigmaVertsAndRays = vertices_and_rays(Sigma)
92+
SigmaRayIndices = findall(vr -> vr isa RayVector, SigmaVertsAndRays)
93+
SigmaLineality = lineality_space(Sigma)
94+
SigmaIncidence = maximal_polyhedra(IncidenceMatrix,Sigma)
95+
return polyhedral_complex(SigmaIncidence, multiply_by_nonzero_scalar.(SigmaVertsAndRays,c), SigmaRayIndices, SigmaLineality)
96+
end
97+
*(c::Union{ZZRingElem,Rational,Int}, Sigma::PolyhedralComplex) = QQ(c)*Sigma
98+
*(Sigma::PolyhedralComplex, c::Union{QQFieldElem,ZZRingElem,Rational,Int}) = c*Sigma
99+
100+
101+
###############################################################################
102+
## Negation
103+
###############################################################################
104+
105+
function -(Sigma::PolyhedralComplex)
106+
SigmaVertsAndRays = vertices_and_rays(Sigma)
107+
SigmaRayIndices = findall(vr -> vr isa RayVector, SigmaVertsAndRays)
108+
SigmaLineality = lineality_space(Sigma)
109+
SigmaIncidence = maximal_polyhedra(IncidenceMatrix,Sigma)
110+
return polyhedral_complex(SigmaIncidence, -SigmaVertsAndRays, SigmaRayIndices, SigmaLineality)
111+
end
112+
113+
###############################################################################
114+
## Translation
115+
###############################################################################
116+
117+
function translate_by_vector(u::PointVector{QQFieldElem}, v::Vector{QQFieldElem})
118+
return u .+ v
119+
end
120+
function translate_by_vector(u::RayVector{QQFieldElem}, ::Vector{QQFieldElem})
121+
return u
122+
end
123+
function +(v::Vector{QQFieldElem}, Sigma::PolyhedralComplex)
124+
@req length(v)==ambient_dim(Sigma) "ambient dimension mismatch"
125+
SigmaVertsAndRays = vertices_and_rays(Sigma)
126+
SigmaRayIndices = findall(vr -> vr isa RayVector, SigmaVertsAndRays)
127+
SigmaLineality = lineality_space(Sigma)
128+
SigmaIncidence = maximal_polyhedra(IncidenceMatrix,Sigma)
129+
return polyhedral_complex(SigmaIncidence, translate_by_vector.(SigmaVertsAndRays,Ref(v)), SigmaRayIndices, SigmaLineality)
130+
end
131+
+(v::Vector{ZZRingElem}, Sigma::PolyhedralComplex) = QQ.(v)+Sigma
132+
+(v::Vector{Rational}, Sigma::PolyhedralComplex) = QQ.(v)+Sigma
133+
+(v::Vector{Int}, Sigma::PolyhedralComplex) = QQ.(v)+Sigma
134+
135+
+(Sigma::PolyhedralComplex, v::Vector{QQFieldElem}) = v+Sigma
136+
+(Sigma::PolyhedralComplex, v::Vector{ZZRingElem}) = QQ.(v)+Sigma
137+
+(Sigma::PolyhedralComplex, v::Vector{Rational}) = QQ.(v)+Sigma
138+
+(Sigma::PolyhedralComplex, v::Vector{Int}) = QQ.(v)+Sigma
139+
140+
# Vector addition for polyhedral fans
141+
+(Sigma::PolyhedralFan, v::Vector) = polyhedral_complex(Sigma)+v
142+
+(v::Vector, Sigma::PolyhedralFan) = v+polyhedral_complex(Sigma)

src/PolyhedralGeometry/PolyhedralFan/standard_constructions.jl

+37
Original file line numberDiff line numberDiff line change
@@ -406,3 +406,40 @@ function arrangement_polynomial(
406406
F = parent(first(A))
407407
return arrangement_polynomial(ring, matrix(F, A); hyperplanes)
408408
end
409+
410+
###############################################################################
411+
## Scalar multiplication
412+
###############################################################################
413+
414+
function multiply_by_nonzero_scalar(u::PointVector{QQFieldElem}, c::QQFieldElem)
415+
return u .* c
416+
end
417+
function multiply_by_nonzero_scalar(u::RayVector{QQFieldElem}, c::QQFieldElem)
418+
return (c<0 ? -u : u)
419+
end
420+
421+
function *(c::QQFieldElem, Sigma::PolyhedralFan)
422+
# if scalar is zero, return polyhedral complex consisting only of the origin
423+
if iszero(c)
424+
return polyhedral_complex(convex_hull(zero_matrix(QQ,1,ambient_dim(Sigma))))
425+
end
426+
427+
# if scalar is non-zero, multiple all vertices and rays by said scalar
428+
SigmaRays = first(rays_modulo_lineality(Sigma))
429+
SigmaLineality = lineality_space(Sigma)
430+
SigmaIncidence = maximal_cones(IncidenceMatrix,Sigma)
431+
return polyhedral_fan(SigmaIncidence, multiply_by_nonzero_scalar.(SigmaRays,c), SigmaLineality)
432+
end
433+
*(c::Union{ZZRingElem,Rational,Int}, Sigma::PolyhedralFan) = QQ(c)*Sigma
434+
*(Sigma::PolyhedralFan,c::Union{QQFieldElem,ZZRingElem,Rational,Int}) = c*Sigma
435+
436+
###############################################################################
437+
## Negation
438+
###############################################################################
439+
440+
function -(Sigma::PolyhedralFan)
441+
SigmaRays = first(rays_modulo_lineality(Sigma))
442+
SigmaLineality = lineality_space(Sigma)
443+
SigmaIncidence = maximal_cones(IncidenceMatrix,Sigma)
444+
return polyhedral_fan(SigmaIncidence, -SigmaRays, SigmaLineality)
445+
end

test/PolyhedralGeometry/polyhedral_complex.jl

+24
Original file line numberDiff line numberDiff line change
@@ -142,4 +142,28 @@
142142
@test n_maximal_polyhedra(vrep) == n_maximal_polyhedra(hrep)
143143
end
144144
end
145+
146+
@testset "Operators" begin
147+
PC = normal_fan(cube(2))
148+
PCshifted = PC + [1, 1]
149+
@test dim(PCshifted) == dim(PC)
150+
@test ambient_dim(PCshifted) == ambient_dim(PC)
151+
@test lineality_dim(PCshifted) == lineality_dim(PC)
152+
@test issetequal(rays(PCshifted), rays(PC))
153+
@test n_maximal_polyhedra(PCshifted) == n_maximal_cones(PC)
154+
155+
PCscaled = PCshifted*2
156+
@test dim(PCscaled) == dim(PCshifted)
157+
@test ambient_dim(PCscaled) == ambient_dim(PCshifted)
158+
@test lineality_dim(PCscaled) == lineality_dim(PCshifted)
159+
@test issetequal(rays(PCscaled), rays(PCshifted))
160+
@test n_maximal_polyhedra(PCscaled) == n_maximal_polyhedra(PCshifted)
161+
162+
PCnegated = -PCshifted
163+
@test dim(PCnegated) == dim(PCshifted)
164+
@test ambient_dim(PCnegated) == ambient_dim(PCshifted)
165+
@test lineality_dim(PCnegated) == lineality_dim(PCshifted)
166+
@test issetequal(rays(PCnegated), rays(PCshifted))
167+
@test n_maximal_polyhedra(PCnegated) == n_maximal_polyhedra(PCshifted)
168+
end
145169
end

test/PolyhedralGeometry/polyhedral_fan.jl

+9
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,15 @@ end
218218
sff1 = star_subdivision(ff, w1)
219219
@test number_of_maximal_cones(sff0) == 2
220220
@test number_of_maximal_cones(sff1) == 3
221+
222+
f = normal_fan(cube(2))
223+
fMinus = -f
224+
@test n_rays(fMinus) == n_rays(f)
225+
@test n_maximal_cones(fMinus) == n_maximal_cones(f)
226+
227+
fMinus = -1*f
228+
@test n_rays(fMinus) == n_rays(f)
229+
@test n_maximal_cones(fMinus) == n_maximal_cones(f)
221230
end
222231

223232
@testset "Defining polynomial of hyperplane arrangement from matrix" begin

0 commit comments

Comments
 (0)