-
Notifications
You must be signed in to change notification settings - Fork 63
/
fundamental_interface.jl
482 lines (365 loc) · 9.96 KB
/
fundamental_interface.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
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
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
###############################################################################
#
# basic_interface.jl : basic interface for AbstractAlgebra
#
###############################################################################
# TODO: Move more generic functions to this file.
###############################################################################
#
# Parents, elements and data type methods
#
###############################################################################
@doc raw"""
parent(a)
Return parent object of given element $a$.
# Examples
```jldoctest; setup = :(using AbstractAlgebra)
julia> G = SymmetricGroup(5); g = Perm([3,4,5,2,1])
(1,3,5)(2,4)
julia> parent(g) == G
true
julia> S, x = laurent_series_ring(ZZ, 3, "x")
(Laurent series ring in x over integers, x + O(x^4))
julia> parent(x) == S
true
```
"""
function parent end
# TODO: Give example
@doc raw"""
elem_type(parent)
elem_type(parent_type)
Given a parent object (or its type), return the type of its elements.
# Examples
```jldoctest; setup = :(using AbstractAlgebra)
julia> S, x = power_series_ring(QQ, 2, "x")
(Univariate power series ring over rationals, x + O(x^3))
julia> elem_type(S) == typeof(x)
true
```
"""
elem_type(x) = elem_type(typeof(x))
elem_type(T::DataType) = throw(MethodError(elem_type, (T,)))
@doc raw"""
parent_type(element)
parent_type(element_type)
Given an element (or its type), return the type of its parent object.
# Examples
```jldoctest; setup = :(using AbstractAlgebra)
julia> R, x = polynomial_ring(ZZ, "x")
(Univariate polynomial ring in x over integers, x)
julia> S = matrix_space(R, 2, 2)
Matrix space of 2 rows and 2 columns
over univariate polynomial ring in x over integers
julia> a = rand(S, 0:1, 0:1);
julia> parent_type(a) == typeof(S)
true
```
"""
parent_type(x) = parent_type(typeof(x))
parent_type(T::DataType) = throw(MethodError(parent_type, (T,)))
@doc raw"""
base_ring(a)
Return base ring $R$ of given element or parent $a$.
# Examples
```jldoctest; setup = :(using AbstractAlgebra)
julia> S, x = polynomial_ring(QQ, "x")
(Univariate polynomial ring in x over rationals, x)
julia> base_ring(S) == QQ
true
julia> R = GF(7)
Finite field F_7
julia> base_ring(R)
Union{}
```
"""
function base_ring end
base_ring(x::ModuleElem) = base_ring(parent(x))
base_ring(x::NCRingElement) = base_ring(parent(x))
@doc raw"""
base_ring_type(a)
Return the type of the base ring of the given element, element type, parent or parent type $a$.
# Examples
```jldoctest; setup = :(using AbstractAlgebra)
julia> R, x = polynomial_ring(ZZ, "x")
(Univariate polynomial ring in x over integers, x)
julia> base_ring_type(R) == typeof(base_ring(R))
true
julia> base_ring_type(zero(R)) == typeof(base_ring(zero(R)))
true
julia> base_ring_type(typeof(R)) == typeof(base_ring(R))
true
julia> base_ring_type(typeof(zero(R))) == typeof(base_ring(zero(R)))
true
```
"""
base_ring_type(x) = base_ring_type(typeof(x))
base_ring_type(x::Type{<:NCRingElement}) = base_ring_type(parent_type(x))
base_ring_type(x::Type{<:ModuleElem}) = base_ring_type(parent_type(x))
base_ring_type(x::Type{<:Ideal}) = base_ring_type(parent_type(x))
base_ring_type(T::DataType) = throw(MethodError(base_ring_type, (T,)))
# generic coefficient_ring method
coefficient_ring(x::NCRingElement) = coefficient_ring(parent(x))
###############################################################################
#
# Special elements
#
###############################################################################
@doc raw"""
one(a)
Return the multiplicative identity in the algebraic structure of $a$, which can
be either an element or parent.
# Examples
```jldoctest; setup = :(using AbstractAlgebra)
julia> S = matrix_space(ZZ, 2, 2)
Matrix space of 2 rows and 2 columns
over integers
julia> one(S)
[1 0]
[0 1]
julia> R, x = puiseux_series_field(QQ, 4, "x")
(Puiseux series field in x over rationals, x + O(x^5))
julia> one(x)
1 + O(x^4)
julia> G = GF(5)
Finite field F_5
julia> one(G)
1
```
"""
function one end
@doc raw"""
zero(a)
Return the additive identity in the algebraic structure of $a$, which can be
either an element or parent.
# Examples
```jldoctest; setup = :(using AbstractAlgebra)
julia> S = matrix_ring(QQ, 2)
Matrix ring of degree 2
over rationals
julia> zero(S)
[0//1 0//1]
[0//1 0//1]
julia> R, x = polynomial_ring(ZZ, "x")
(Univariate polynomial ring in x over integers, x)
julia> zero(x^3 + 2)
0
```
"""
function zero end
###############################################################################
#
# Basic manipulation
#
###############################################################################
@doc raw"""
isone(a)
Return true if $a$ is the multiplicative identity, else return false.
# Examples
```jldoctest; setup = :(using AbstractAlgebra)
julia> S = matrix_space(ZZ, 2, 2); T = matrix_space(ZZ, 2, 3); U = matrix_space(ZZ, 3, 2);
julia> isone(S([1 0; 0 1]))
true
julia> isone(T([1 0 0; 0 1 0]))
false
julia> isone(U([1 0; 0 1; 0 0]))
false
julia> T, x = puiseux_series_field(QQ, 10, "x")
(Puiseux series field in x over rationals, x + O(x^11))
julia> isone(x), isone(T(1))
(false, true)
```
"""
function isone end
@doc raw"""
iszero(a)
Return true if $a$ is the additative identity, else return false.
# Examples
```jldoctest; setup = :(using AbstractAlgebra)
julia> T, x = puiseux_series_field(QQ, 10, "x")
(Puiseux series field in x over rationals, x + O(x^11))
julia> a = T(0)
O(x^10)
julia> iszero(a)
true
```
"""
function iszero end
###############################################################################
#
# More generic functions
#
###############################################################################
# @doc raw"""
# gen(a)
# Return element generating parent $a$.
# # Examples
# ```jldoctest; setup = :(using AbstractAlgebra)
# julia> S, x = laurent_polynomial_ring(QQ, "x")
# (Univariate Laurent Polynomial Ring in x over Rationals, x)
# julia> gen(S)
# x
# ```
# """
function gen end
# @doc raw"""
# gens(a)
# Return elements generating parent $a$ in an array.
# # Examples
# ```jldoctest; setup = :(using AbstractAlgebra)
# ```
# """
function gens end
###############################################################################
#
# Variable names
#
###############################################################################
"""
const VarName = Union{Symbol, AbstractString, Char}
Types allowed when giving variable names.
"""
const VarName = Union{Symbol, AbstractString, Char}
###############################################################################
#
# Unsafe functions
#
###############################################################################
@doc raw"""
zero!(a)
Return the zero of `parent(a)`, possibly modifying the object `a` in the process.
"""
function zero!(a)
return zero(parent(a))
end
@doc raw"""
add!(a, b, c)
Return `b + c`, possibly modifying the object `a` in the process.
"""
function add!(a, b, c)
return b + c
end
@doc raw"""
add!(a, b)
Return `a + b`, possibly modifying the object `a` in the process.
This is a shorthand for `add!(a, a, b)`.
"""
add!(a, b) = add!(a, a, b)
@doc raw"""
sub!(a, b, c)
Return `b - c`, possibly modifying the object `a` in the process.
"""
function sub!(a, b, c)
return b - c
end
@doc raw"""
sub!(a, b)
Return `a - b`, possibly modifying the object `a` in the process.
This is a shorthand for `sub!(a, a, b)`.
"""
sub!(a, b) = sub!(a, a, b)
@doc raw"""
neg!(a, b)
Return `-b`, possibly modifying the object `a` in the process.
"""
function neg!(a, b)
return -b
end
@doc raw"""
neg!(a)
Return `-a`, possibly modifying the object `a` in the process.
This is a shorthand for `neg!(a, a)`.
"""
neg!(a) = neg!(a, a)
@doc raw"""
mul!(a, b, c)
Return `b * c`, possibly modifying the object `a` in the process.
"""
function mul!(a, b, c)
return b * c
end
@doc raw"""
mul!(a, b)
Return `a * b`, possibly modifying the object `a` in the process.
This is a shorthand for `mul!(a, a, b)`.
"""
mul!(a, b) = mul!(a, a, b)
@doc raw"""
div!(a, b, c)
Return `div(b, c)`, possibly modifying the object `a` in the process.
"""
function div!(a, b, c)
return div(b, c)
end
@doc raw"""
div!(a, b)
Return `div(a, b)`, possibly modifying the object `a` in the process.
This is a shorthand for `div!(a, a, b)`.
"""
div!(a, b) = div!(a, a, b)
@doc raw"""
rem!(a, b, c)
Return `rem(b, c)`, possibly modifying the object `a` in the process.
"""
function rem!(a, b, c)
return rem(b, c)
end
@doc raw"""
rem!(a, b)
Return `rem(a, b)`, possibly modifying the object `a` in the process.
This is a shorthand for `rem!(a, a, b)`.
"""
rem!(a, b) = rem!(a, a, b)
@doc raw"""
mod!(a, b, c)
Return `mod(b, c)`, possibly modifying the object `a` in the process.
"""
function mod!(a, b, c)
return mod(b, c)
end
@doc raw"""
mod!(a, b)
Return `mod(a, b)`, possibly modifying the object `a` in the process.
This is a shorthand for `mod!(a, a, b)`.
"""
mod!(a, b) = mod!(a, a, b)
@doc raw"""
inv!(a, b)
Return `inv(b)`, possibly modifying the object `a` in the process.
"""
function inv!(a, b)
return inv(b)
end
@doc raw"""
inv!(a)
Return `inv(a)`, possibly modifying the object `a` in the process.
This is a shorthand for `inv!(a, a)`.
"""
inv!(a) = inv!(a, a)
@doc raw"""
gcd!(a, b, c)
Return `gcd(b, c)`, possibly modifying the object `a` in the process.
"""
function gcd!(a, b, c)
return gcd(b, c)
end
@doc raw"""
canonical_injection(D, i)
Return the i-th canonical injection into the direct sum or product objects `D`.
"""
function canonical_injection end
@doc raw"""
canonical_projection(D, i)
Return the i-th canonical projection into the direct sum or product objects `D`.
"""
function canonical_projection end
@doc raw"""
_number_of_direct_product_factors(D)
Return the number of factors/ summands in the direct product/ sum object `D`
"""
function _number_of_direct_product_factors end
@doc raw"""
hom(D, C, data)
Return the homomorphism from the domain `D` into the codomain `C` defined by the data.
"""
function hom end