-
Notifications
You must be signed in to change notification settings - Fork 63
/
fundamental_interface.jl
296 lines (222 loc) · 6.04 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
###############################################################################
#
# 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
###############################################################################
#
# 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 = PuiseuxSeriesField(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 = MatrixAlgebra(QQ, 2)
Matrix algebra 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 = PuiseuxSeriesField(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 = PuiseuxSeriesField(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 = LaurentPolynomialRing(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}
###############################################################################
#
# Unsafe functions
#
###############################################################################
@doc raw"""
zero!(a)
Return the zero of `parent(a)`, possibly modifying the object `a` in the process.
"""
function zero! end
@doc raw"""
add!(a, b, c)
Return `b + c`, possibly modifying the object `a` in the process.
"""
function add! end
@doc raw"""
addeq!(a, b)
Return `a + b`, possibly modifying the object `a` in the process.
"""
function addeq! end
@doc raw"""
sub!(a, b, c)
Return `b - c`, possibly modifying the object `a` in the process.
"""
function sub! end
@doc raw"""
mul!(a, b, c)
Return `b*c`, possibly modifying the object `a` in the process.
"""
function mul! end