forked from oscar-system/Oscar.jl
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconstructors.jl
More file actions
289 lines (225 loc) · 8.12 KB
/
constructors.jl
File metadata and controls
289 lines (225 loc) · 8.12 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
######################
# Julia type for ToricVarieties
######################
pm_object(v::NormalToricVarietyType) = v.polymakeNTV
coefficient_field(::NormalToricVarietyType) = QQ
######################
# Constructors
######################
@doc raw"""
affine_normal_toric_variety(C::Cone)
Construct the affine normal toric variety $U_{C}$ corresponding to a polyhedral
cone `C`.
# Examples
Set `C` to be the positive orthant in two dimensions.
```jldoctest
julia> C = positive_hull([1 0; 0 1])
Polyhedral cone in ambient dimension 2
julia> antv = affine_normal_toric_variety(C)
Normal toric variety
```
"""
function affine_normal_toric_variety(C::Cone)
fan = polyhedral_fan(C)
pmntv = Polymake.fulton.NormalToricVariety(Oscar.pm_object(fan))
variety = AffineNormalToricVariety(pmntv)
set_attribute!(variety, :cone, C)
set_attribute!(variety, :fan, fan)
return variety
end
@doc raw"""
normal_toric_variety(C::Cone)
Construct the (affine) normal toric variety $X_{\Sigma}$ corresponding to a
polyhedral fan $\Sigma = C$ consisting only of the cone `C`.
# Examples
Set `C` to be the positive orthant in two dimensions.
```jldoctest
julia> C = positive_hull([1 0; 0 1])
Polyhedral cone in ambient dimension 2
julia> ntv = normal_toric_variety(C)
Normal toric variety
```
"""
function normal_toric_variety(C::Cone)
fan = polyhedral_fan(C)
pmntv = Polymake.fulton.NormalToricVariety(Oscar.pm_object(fan))
variety = NormalToricVariety(pmntv)
set_attribute!(variety, :cone, C)
set_attribute!(variety, :fan, fan)
return variety
end
@doc raw"""
normal_toric_variety(max_cones::IncidenceMatrix, rays::AbstractCollection[RayVector]; non_redundant::Bool = false)
Construct a normal toric variety $X$ by providing the rays and maximal cones
as vector of vectors. By default, this method allows redundancies in the input, e.g. duplicate rays and non-maximal cones. If the user
is certain that no redundancy exists in the entered information, one can
pass `non_redundant = true` as third argument. This will bypass these consistency
checks. In addition, this will ensure that the order of the rays is not
altered by the constructor.
# Examples
```jldoctest
julia> ray_generators = [[1,0], [0, 1], [-1, 5], [0, -1]]
4-element Vector{Vector{Int64}}:
[1, 0]
[0, 1]
[-1, 5]
[0, -1]
julia> max_cones = incidence_matrix([[1, 2], [2, 3], [3, 4], [4, 1]])
4×4 IncidenceMatrix
[1, 2]
[2, 3]
[3, 4]
[1, 4]
julia> normal_toric_variety(max_cones, ray_generators)
Normal toric variety
julia> normal_toric_variety(max_cones, ray_generators; non_redundant = true)
Normal toric variety
```
"""
normal_toric_variety(max_cones::Vector{Vector{Int64}}, rays::AbstractCollection[RayVector]; non_redundant::Bool = false) = normal_toric_variety(IncidenceMatrix(max_cones), rays; non_redundant)
function normal_toric_variety(max_cones::IncidenceMatrix, rays::AbstractCollection[RayVector]; non_redundant::Bool = false)
fan = polyhedral_fan(max_cones, rays; non_redundant)
return normal_toric_variety(fan)
end
@doc raw"""
normal_toric_variety(PF::PolyhedralFan)
Construct the normal toric variety $X_{PF}$ corresponding to a polyhedral fan `PF`.
# Examples
Take `PF` to be the normal fan of the square.
```jldoctest
julia> square = cube(2)
Polytope in ambient dimension 2
julia> nf = normal_fan(square)
Polyhedral fan in ambient dimension 2
julia> ntv = normal_toric_variety(nf)
Normal toric variety
```
"""
function normal_toric_variety(PF::PolyhedralFan)
fan = Oscar.pm_object(PF)
pmntv = Polymake.fulton.NormalToricVariety(fan)
return NormalToricVariety(pmntv)
end
@doc raw"""
normal_toric_variety(P::Polyhedron)
Construct the normal toric variety $X_{\Sigma_P}$ corresponding to the normal
fan $\Sigma_P$ of the given polyhedron `P`.
Note that this only coincides with the projective variety associated to `P`
from the affine relations of the lattice points in `P`, if `P` is very ample.
# Examples
Set `P` to be a square.
```jldoctest
julia> square = cube(2)
Polytope in ambient dimension 2
julia> ntv = normal_toric_variety(square)
Normal toric variety
```
"""
function normal_toric_variety(P::Polyhedron)
variety = normal_toric_variety(normal_fan(P))
set_attribute!(variety, :polyhedron, P)
return variety
end
@doc raw"""
affine_normal_toric_variety(v::NormalToricVariety)
For internal design, we make a strict distinction between
normal toric varieties and affine toric varieties.
Given an affine, normal toric variety `v`,
this method turns it into an affine toric variety.
# Examples
```jldoctest
julia> v = normal_toric_variety(positive_hull([1 0; 0 1]))
Normal toric variety
julia> affineVariety = affine_normal_toric_variety(v)
Normal toric variety
```
"""
function affine_normal_toric_variety(v::NormalToricVariety)
is_affine(v) || error("Cannot construct affine toric variety from non-affine input")
return AffineNormalToricVariety(pm_object(v))
end
######################
# Equality
######################
@doc raw"""
(==)(X::NormalToricVariety, Y::NormalToricVariety) -> Bool
Checks equality of the polyhedral fans as sets of cones.
# Examples
```jldoctest
julia> H = hirzebruch_surface(NormalToricVariety, 0)
Normal toric variety
julia> P1 = projective_space(NormalToricVariety, 1)
Normal toric variety
julia> H == P1 * P1
true
```
"""
function Base.:(==)(X::NormalToricVariety, Y::NormalToricVariety)
X === Y && return true
ambient_dim(X) == ambient_dim(Y) || return false
n_rays(X) == n_rays(Y) || return false
# p is a permutation such that the i-th ray of X is the p(i)-th ray of Y
p = inv(perm(sortperm(rays(X)))) * perm(sortperm(rays(Y)))
for i in 1:n_rays(X)
rays(X)[i] == rays(Y)[p(i)] || return false
end
@inline rows(Z) = [
row(maximal_cones(IncidenceMatrix, Z), i) for i in 1:n_maximal_cones(Z)
]
return Set(map(r -> Set(p.(r)), rows(X))) == Set(rows(Y))
end
@doc raw"""
_id(X::NormalToricVariety)
-> Tuple{Vector{Vector{QQFieldElem}}, Vector{Vector{Int64}}}
Given a toric variety `X`, returns a pair `Oscar._id(X)` with the
following property: two toric varieties `X` and `Y` have equal
polyhedral fans, taken as sets of cones, if and only if
`Oscar._id(X) == Oscar._id(Y)`.
# Examples
```jldoctest
julia> H = hirzebruch_surface(NormalToricVariety, 0)
Normal toric variety
julia> P1 = projective_space(NormalToricVariety, 1)
Normal toric variety
julia> Oscar._id(H) == Oscar._id(P1 * P1)
true
```
"""
function _id(X::NormalToricVariety)
p = inv(perm(sortperm(rays(X))))
sorted_rays = Vector.(permuted(collect(rays(X)), p))
@inline rows(Z) = [
row(maximal_cones(IncidenceMatrix, Z), i) for i in 1:n_maximal_cones(Z)
]
sorted_maximal_cones = sort(map(r -> sort(Vector(p.(r))), rows(X)))
return (sorted_rays, sorted_maximal_cones)
end
function Base.hash(X::NormalToricVariety, h::UInt)
return hash(_id(X), h)
end
######################
# Display
######################
function Base.show(io::IO, v::NormalToricVarietyType)
# initiate properties string
properties_string = ["Normal"]
affine = push_attribute_if_exists!(properties_string, v, :is_affine, "affine")
simplicial_cb!(a, b) = push_attribute_if_exists!(a, b, :is_orbifold, "simplicial")
push_attribute_if_exists!(properties_string, v, :is_smooth, "smooth"; callback=simplicial_cb!)
projective = nothing
if isnothing(affine) || !affine
complete_cb!(a, b) = push_attribute_if_exists!(a, b, :is_complete, "complete")
projective = push_attribute_if_exists!(properties_string, v, :is_projective, "projective"; callback=complete_cb!)
end
q_gor_cb!(a, b) = push_attribute_if_exists!(a, b, :is_q_gorenstein, "q-gorenstein")
gorenstein = push_attribute_if_exists!(properties_string, v, :is_gorenstein, "gorenstein"; callback=q_gor_cb!)
push_attribute_if_exists!(properties_string, v, :is_fano, "fano")
if has_attribute(v, :dim)
push!(properties_string, string(dim(v))*"-dimensional")
end
properties_string = [join(properties_string, ", ")]
push!(properties_string, "toric variety")
push_attribute_if_exists!(properties_string, v, :has_torusfactor, "with torusfactor", "without torusfactor")
join(io, properties_string, " ")
end
Base.show(io::IO, ::MIME"text/plain", v::NormalToricVarietyType) = Base.show(pretty(io), v)