/
resolution.jl
106 lines (85 loc) · 2.93 KB
/
resolution.jl
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
export ResolutionSet, sresolution, betti, minres
###############################################################################
#
# Basic manipulation
#
###############################################################################
base_ring(r::sresolution) = r.base_ring
base_ring(R::ResolutionSet) = R.base_ring
function parent(r::sresolution{T}) where T <: AbstractAlgebra.RingElem
return ResolutionSet{T}(r.base_ring)
end
elem_type(::Type{ResolutionSet{T}}) where T <: AbstractAlgebra.RingElem = sresolution{T}
elem_type(::ResolutionSet{T}) where T <: AbstractAlgebra.RingElem = sresolution{T}
parent_type(::Type{sresolution{T}}) where T <: AbstractAlgebra.RingElem = ResolutionSet{T}
function checkbounds(r::sresolution, i::Int)
(i < 1 || i > r.len) && throw(BoundsError(I, i))
end
function getindex(r::sresolution, i::Int)
checkbounds(r, i)
R = base_ring(r)
ptr = libSingular.getindex(r.ptr, Cint(i - 1))
if ptr != C_NULL
ptr = libSingular.id_Copy(ptr, R.ptr)
end
return Module(R, ptr)
end
length(r::sresolution) = r.len - 1
function deepcopy_internal(r::sresolution, dict::ObjectIdDict)
R = base_ring(r)
ptr = libSingular.res_Copy(r.ptr, Cint(r.len), R.ptr)
return parent(r)(ptr, r.len)
end
###############################################################################
#
# Betti numbers
#
###############################################################################
function betti(r::sresolution)
libSingular.syBetti(r.ptr, Cint(r.len), r.base_ring.ptr)
end
###############################################################################
#
# Minimal resolution
#
###############################################################################
function minres(r::sresolution{T}) where T <: AbstractAlgebra.RingElem
if r.minimal
return r
end
R = base_ring(r)
ptr = libSingular.syMinimize(r.ptr, Cint(r.len), R.ptr)
return sresolution{T}(R, r.len, ptr, true)
end
###############################################################################
#
# String I/O
#
###############################################################################
function show(io::IO, R::ResolutionSet)
print(io, "Set of Singular Resolutions over ")
show(io, R.base_ring)
end
function show(io::IO, r::sresolution)
println(io, "Singular Resolution:")
if r.len > 0
ptr = libSingular.getindex(r.ptr, Cint(0))
print(io, "R^", libSingular.rank(ptr))
end
for i = 1:r.len - 1
ptr = libSingular.getindex(r.ptr, Cint(i-1))
if ptr == C_NULL
break
end
print(io, " <- R^", libSingular.ngens(ptr))
end
end
###############################################################################
#
# Parent object call overload
#
###############################################################################
function (S::ResolutionSet{T})(ptr::libSingular.resolvente, len::Int) where T <: AbstractAlgebra.RingElem
R = base_ring(S)
return sresolution{T}(R, len, ptr)
end