-
Notifications
You must be signed in to change notification settings - Fork 112
/
ExteriorAlgebra.jl
195 lines (155 loc) · 7.31 KB
/
ExteriorAlgebra.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
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
export exterior_algebra # MAIN EXPORT!
# Commented out old impl: exterior_algebra_PBWAlgQuo (allows coeffs in a non-field)
#--------------------------------------------
# Two implementations of exterior algebras:
# (1) delegating everything to Singular -- fast, coeff ring must be a field
# (2) as a quotient of PBW algebra -- slower, coeff ring must be commutative
# ADVICE: avoid impl (2) which deliberately has an awkward name.
# See also:
# * tests in Oscar.jl/test/Experimental/ExteriorAlgebra-test.jl
# * doc tests in Oscar.jl/docs/src/NoncommutativeAlgebra/PBWAlgebras/quotients.md
# -------------------------------------------------------
# Exterior algebra: delegating everything to Singular.
#---------------------- MAIN FUNCTION ----------------------
# exterior_algebra constructor: args are
# - underlying coeff FIELD and
# - number of indets (or list of indet names)
# Returns 2 components: ExtAlg, list of the gens/variables
# DEVELOPER DOC
# This impl is "inefficient": it must create essentially 2 copies of
# the exterior algebra. One copy is so that Oscar knows the structure
# of the ext alg (as a quotient of a PBWAlg); the other copy is a
# Singular implementation (seen as a "black box" by Oscar) which
# actually does the arithmetic (quickly).
#
# To make this work I had to make changes to struct PBWAlgQuo: (see the source)
# (*) previously a PBWAlgQuo had a single datum, namely the (2-sided) ideal
# used to make the quotient -- the base ring could be derived from the ideal
#
# (*) now a PBWAlgQuo has an extra data field "sring" which refers to
# the underlying Singular ring structure which actually performs
# the arithmetic. For exterior algebras "sring" refers to a
# specific Singular ring "exteriorAlgebra"; in other cases "sring"
# refers to the Singular(plural) ring which implements the PBW alg
# (i.e. IGNORING the fact that the elems are in a quotient)
# PBWAlgQuoElem did not need to change. Its "data" field just refers
# to a PBWAlgElem (namely some representative of the class).
# Attach docstring to "abstract" function exterior_algebra, so that
# it is automatically "inherited" by the methods.
@doc raw"""
exterior_algebra(K::Field, numVars::Int)
exterior_algebra(K::Field, listOfVarNames::AbstractVector{<:VarName})
The *first form* returns an exterior algebra with coefficient field `K` and
`numVars` variables: `numVars` must be positive, and the variables are
called `e1, e2, ...`.
The *second form* returns an exterior algebra with coefficient field `K`, and
variables named as specified in `listOfVarNames` (which must be non-empty).
NOTE: Creating an `exterior_algebra` with many variables will create an object
occupying a lot of memory (probably cubic in `numVars`).
# Examples
```jldoctest
julia> ExtAlg, (e1,e2) = exterior_algebra(QQ, 2);
julia> e2*e1
-e1*e2
julia> (e1+e2)^2 # result is automatically reduced!
0
julia> ExtAlg, (x,y) = exterior_algebra(QQ, ["x","y"]);
julia> y*x
-x*y
```
"""
function exterior_algebra end
# ---------------------------------
# -- Method where caller specifies just number of variables
function exterior_algebra(K::Field, numVars::Int)
if numVars < 1
throw(ArgumentError("numVars must be strictly positive, but numVars=$numVars"))
end
return exterior_algebra(K, (k -> "e$k").((1:numVars)))
end
#---------------------------------
# Method where caller specifies name of variables.
function exterior_algebra(K::Field, listOfVarNames::AbstractVector{<:VarName})
numVars = length(listOfVarNames)
if numVars == 0
throw(ArgumentError("no variables/indeterminates given"))
end
# if (!allunique(VarNames))
# throw(ArgumentError("variable names must be distinct"))
# end
R, indets = polynomial_ring(K, listOfVarNames)
SameCoeffRing = singular_coeff_ring(coefficient_ring(R))
M = zero_matrix(R, numVars, numVars)
for i in 1:(numVars - 1)
for j in (i + 1):numVars
M[i, j] = -indets[i] * indets[j]
end
end
PBW, PBW_indets = pbw_algebra(R, M, degrevlex(indets); check=false) # disable check since we know it is OK!
I = two_sided_ideal(PBW, PBW_indets .^ 2)
# Now construct the fast exteriorAlgebra in Singular;
# get var names from PBW in case it had "mangled" them.
P, _ = Singular.polynomial_ring(SameCoeffRing, string.(symbols(PBW)))
SINGULAR_PTR = Singular.libSingular.exteriorAlgebra(Singular.libSingular.rCopy(P.ptr))
ExtAlg_singular = Singular.create_ring_from_singular_ring(SINGULAR_PTR)
# Create Quotient ring with special implementation:
ExtAlg, _ = quo(PBW, I; SpecialImpl=ExtAlg_singular) # 2nd result is a QuoMap, apparently not needed
###### set_attribute!(ExtAlg, :is_exterior_algebra, :true) ### DID NOT WORK (see PBWAlgebraQuo.jl) Anyway, the have_special_impl function suffices.
return ExtAlg, gens(ExtAlg)
end
# COMMENTED OUT "OLD IMPLEMENTATION" (so as not to lose the code)
# #--------------------------------------------
# # Exterior algebra implementation as a quotient of a PBW algebra;
# # **PREFER** exterior_algebra over this SLOW implementation!
# # Returns 2 components: ExtAlg, list of the gens/variables in order (e1,..,en)
# @doc raw"""
# exterior_algebra_PBWAlgQuo(coeffRing::Ring, numVars::Int)
# exterior_algebra_PBWAlgQuo(coeffRing::Ring, listOfVarNames::Vector{String})
# Use `exterior_algebra` in preference to this function when `coeffRing` is a field.
# The first form returns an exterior algebra with given `coeffRing` and `numVars` variables;
# the variables are called `e1, e2, ...`. The value `numVars` must be positive; be aware that
# large values will create an object occupying a lot of memory (probably cubic in `numVars`).
# The second form returns an exterior algebra with given `coeffRing`, and variables named
# as specified in `listOfVarNames` (which must be non-empty).
# # Examples
# ```jldoctest
# julia> ExtAlg, (e1,e2) = exterior_algebra_PBWAlgQuo(QQ, 2);
# julia> e2*e1
# -e1*e2
# julia> is_zero((e1+e2)^2)
# true
# julia> ExtAlg, (x,y) = exterior_algebra_PBWAlgQuo(QQ, ["x","y"]);
# julia> y*x
# -x*y
# ```
# """
# function exterior_algebra_PBWAlgQuo(K::Ring, numVars::Int)
# if (numVars < 1)
# throw(ArgumentError("numVars must be strictly positive: numVars=$numVars"))
# end
# return exterior_algebra_PBWAlgQuo(K, (1:numVars) .|> (k -> "e$k"))
# end
# function exterior_algebra_PBWAlgQuo(K::Ring, listOfVarNames::AbstractVector{<:VarName})
# numVars = length(listOfVarNames)
# if (numVars == 0)
# throw(ArgumentError("no variables/indeterminates given"))
# end
# # if (!allunique(listOfVarNames))
# # throw(ArgumentError("variable names must be distinct"))
# # end
# R, indets = polynomial_ring(K, listOfVarNames)
# M = zero_matrix(R, numVars, numVars)
# for i in 1:numVars-1
# for j in i+1:numVars
# M[i,j] = -indets[i]*indets[j]
# end
# end
# PBW, PBW_indets = pbw_algebra(R, M, degrevlex(indets); check = false) # disable check since we know it is OK!
# I = two_sided_ideal(PBW, PBW_indets.^2)
# ExtAlg,QuoMap = quo(PBW, I)
# return ExtAlg, QuoMap.(PBW_indets)
# end
# # BUGS/DEFICIENCIES (2023-02-13):
# # (1) Computations with elements DO NOT AUTOMATICALLY REDUCE
# # modulo the squares of the generators.
# # (2) Do we want/need a special printing function? (show/display)