Skip to content

Commit 1f0294c

Browse files
committed
PolyhedralGeometry: simplified operations with PolyhedralFan and PolyhedralComplex
1 parent 9da4d3c commit 1f0294c

File tree

2 files changed

+20
-34
lines changed

2 files changed

+20
-34
lines changed

src/PolyhedralGeometry/PolyhedralComplex/standard_constructions.jl

+12-17
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ end
8181
## Scalar product
8282
###############################################################################
8383

84-
function *(c::QQFieldElem, Sigma::PolyhedralComplex)
84+
function *(c::scalar_types_extended, Sigma::PolyhedralComplex)
8585
# if scalar is zero, return polyhedral complex consisting only of the origin
8686
if iszero(c)
8787
return polyhedral_complex(convex_hull(zero_matrix(QQ,1,ambient_dim(Sigma))))
@@ -92,10 +92,9 @@ function *(c::QQFieldElem, Sigma::PolyhedralComplex)
9292
SigmaRayIndices = findall(vr -> vr isa RayVector, SigmaVertsAndRays)
9393
SigmaLineality = lineality_space(Sigma)
9494
SigmaIncidence = maximal_polyhedra(IncidenceMatrix,Sigma)
95-
return polyhedral_complex(SigmaIncidence, multiply_by_nonzero_scalar.(SigmaVertsAndRays,c), SigmaRayIndices, SigmaLineality)
95+
return polyhedral_complex(coefficient_field(Sigma), SigmaIncidence, SigmaVertsAndRays .*c, SigmaRayIndices, SigmaLineality)
9696
end
97-
*(c::RationalUnion, Sigma::PolyhedralComplex) = QQ(c)*Sigma
98-
*(Sigma::PolyhedralComplex, c::RationalUnion) = c*Sigma
97+
*(Sigma::PolyhedralComplex, c::scalar_types_extended) = c*Sigma
9998

10099

101100
###############################################################################
@@ -114,27 +113,23 @@ end
114113
## Translation
115114
###############################################################################
116115

117-
function translate_by_vector(u::PointVector{QQFieldElem}, v::Vector{QQFieldElem})
118-
return u .+ v
116+
# requires separate function because to ensure that translation does not change ray vectors
117+
function translate_by_vector(u::PointVector{<:scalar_types_extended}, v::Vector{<:scalar_types_extended})
118+
return u + v
119119
end
120-
function translate_by_vector(u::RayVector{QQFieldElem}, ::Vector{QQFieldElem})
120+
function translate_by_vector(u::RayVector{<:scalar_types_extended}, ::Vector{<:scalar_types_extended})
121121
return u
122122
end
123-
function +(v::Vector{QQFieldElem}, Sigma::PolyhedralComplex)
123+
function +(v::Vector{<:scalar_types_extended}, Sigma::PolyhedralComplex)
124124
@req length(v)==ambient_dim(Sigma) "ambient dimension mismatch"
125125
SigmaVertsAndRays = vertices_and_rays(Sigma)
126126
SigmaRayIndices = findall(vr -> vr isa RayVector, SigmaVertsAndRays)
127127
SigmaLineality = lineality_space(Sigma)
128128
SigmaIncidence = maximal_polyhedra(IncidenceMatrix,Sigma)
129-
return polyhedral_complex(SigmaIncidence, translate_by_vector.(SigmaVertsAndRays,Ref(v)), SigmaRayIndices, SigmaLineality)
129+
return polyhedral_complex(coefficient_field(Sigma), SigmaIncidence, translate_by_vector.(SigmaVertsAndRays,Ref(v)), SigmaRayIndices, SigmaLineality)
130130
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{<:RationalUnion}) = QQ.(v)+Sigma
131+
+(Sigma::PolyhedralComplex, v::Vector{<:scalar_types_extended}) = v+Sigma
137132

138133
# Vector addition for polyhedral fans
139-
+(Sigma::PolyhedralFan, v::Vector) = polyhedral_complex(Sigma)+v
140-
+(v::Vector, Sigma::PolyhedralFan) = v+polyhedral_complex(Sigma)
134+
+(Sigma::PolyhedralFan, v::Vector{<:scalar_types_extended}) = polyhedral_complex(Sigma)+v
135+
+(v::Vector{<:scalar_types_extended}, Sigma::PolyhedralFan) = v+polyhedral_complex(Sigma)

src/PolyhedralGeometry/PolyhedralFan/standard_constructions.jl

+8-17
Original file line numberDiff line numberDiff line change
@@ -411,35 +411,26 @@ end
411411
## Scalar multiplication
412412
###############################################################################
413413

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
414+
function *(c::scalar_types_extended, Sigma::PolyhedralFan)
415+
# if scalar is zero, return polyhedral fan consisting only of the origin
423416
if iszero(c)
424-
return polyhedral_complex(convex_hull(zero_matrix(QQ,1,ambient_dim(Sigma))))
417+
return polyhedral_fan(positive_hull(zero_matrix(coefficient_field(Sigma),1,ambient_dim(Sigma))))
425418
end
426419

427-
# if scalar is non-zero, multiple all vertices and rays by said scalar
420+
# if scalar is non-zero, multiple all rays by said scalar
428421
SigmaRays = first(rays_modulo_lineality(Sigma))
429422
SigmaLineality = lineality_space(Sigma)
430423
SigmaIncidence = maximal_cones(IncidenceMatrix,Sigma)
431-
return polyhedral_fan(SigmaIncidence, multiply_by_nonzero_scalar.(SigmaRays,c), SigmaLineality)
424+
return polyhedral_fan(coefficient_field(Sigma), SigmaIncidence, SigmaRays .* c, SigmaLineality)
432425
end
433-
*(c::RationalUnion, Sigma::PolyhedralFan) = QQ(c)*Sigma
434-
*(Sigma::PolyhedralFan,c::RationalUnion) = c*Sigma
426+
*(Sigma::PolyhedralFan,c::scalar_types_extended) = c*Sigma
435427

436428
###############################################################################
437429
## Negation
438430
###############################################################################
439431

440432
function -(Sigma::PolyhedralFan)
441-
SigmaRays = first(rays_modulo_lineality(Sigma))
442-
SigmaLineality = lineality_space(Sigma)
433+
SigmaRays, SigmaLineality = first(rays_modulo_lineality(Sigma))
443434
SigmaIncidence = maximal_cones(IncidenceMatrix,Sigma)
444-
return polyhedral_fan(SigmaIncidence, -SigmaRays, SigmaLineality)
435+
return polyhedral_fan(coefficient_field(Sigma), SigmaIncidence, -SigmaRays, SigmaLineality)
445436
end

0 commit comments

Comments
 (0)