Skip to content

Commit 2627b5e

Browse files
authored
Add Julia(Field|Ring|ExactRing)Element type unions (#2231)
Also merge or remove some docstrings
1 parent 077dbd4 commit 2627b5e

28 files changed

+139
-322
lines changed

docs/src/ncpolynomial.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,8 +351,7 @@ x
351351
### Evaluation
352352

353353
```@docs
354-
evaluate{T <: NCRingElem}(::NCPolyRingElem{T}, ::T)
355-
evaluate(::NCPolyRingElem, ::Integer)
354+
evaluate(::NCPolyRingElem, ::NCRingElem)
356355
```
357356

358357
We also overload the functional notation so that the polynomial $f$ can be

src/AbsSeries.jl

Lines changed: 7 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ function *(a::T, b::AbsPowerSeriesRingElem{T}) where {T <: RingElem}
337337
return z
338338
end
339339

340-
function *(a::Union{Integer, Rational, AbstractFloat}, b::AbsPowerSeriesRingElem)
340+
function *(a::JuliaRingElement, b::AbsPowerSeriesRingElem)
341341
len = length(b)
342342
z = parent(b)()
343343
fit!(z, len)
@@ -351,7 +351,7 @@ end
351351

352352
*(a::AbsPowerSeriesRingElem{T}, b::T) where {T <: RingElem} = b*a
353353

354-
*(a::AbsPowerSeriesRingElem, b::Union{Integer, Rational, AbstractFloat}) = b*a
354+
*(a::AbsPowerSeriesRingElem, b::JuliaRingElement) = b*a
355355

356356
###############################################################################
357357
#
@@ -563,35 +563,21 @@ end
563563
###############################################################################
564564

565565
@doc raw"""
566-
==(x::AbsPowerSeriesRingElem{T}, y::T) where {T <: RingElem}
566+
==(x::AbsPowerSeriesRingElem{<:RingElem}, y::RingElement)
567+
==(x::RingElement, y::AbsPowerSeriesRingElem{<:RingElem})
567568
568569
Return `true` if $x == y$ arithmetically, otherwise return `false`.
569570
"""
570571
==(x::AbsPowerSeriesRingElem{T}, y::T) where {T <: RingElem} = precision(x) == 0 ||
571572
((length(x) == 0 && iszero(y)) || (length(x) == 1 && coeff(x, 0) == y))
572573

573-
@doc raw"""
574-
==(x::T, y::AbsPowerSeriesRingElem{T}) where {T <: RingElem}
575-
576-
Return `true` if $x == y$ arithmetically, otherwise return `false`.
577-
"""
578574
==(x::T, y::AbsPowerSeriesRingElem{T}) where {T <: RingElem} = y == x
579575

580-
@doc raw"""
581-
==(x::AbsPowerSeriesRingElem, y::Union{Integer, Rational, AbstractFloat})
582-
583-
Return `true` if $x == y$ arithmetically, otherwise return `false`.
584-
"""
585-
==(x::AbsPowerSeriesRingElem, y::Union{Integer, Rational, AbstractFloat}) = precision(x) == 0 ||
576+
==(x::AbsPowerSeriesRingElem, y::JuliaRingElement) = precision(x) == 0 ||
586577
((length(x) == 0 && iszero(base_ring(x)(y))) ||
587578
(length(x) == 1 && coeff(x, 0) == y))
588579

589-
@doc raw"""
590-
==(x::Union{Integer, Rational, AbstractFloat}, y::AbsPowerSeriesRingElem)
591-
592-
Return `true` if $x == y$ arithmetically, otherwise return `false`.
593-
"""
594-
==(x::Union{Integer, Rational, AbstractFloat}, y::AbsPowerSeriesRingElem) = y == x
580+
==(x::JuliaRingElement, y::AbsPowerSeriesRingElem) = y == x
595581

596582
###############################################################################
597583
#
@@ -654,7 +640,7 @@ end
654640
#
655641
###############################################################################
656642

657-
function divexact(x::AbsPowerSeriesRingElem, y::Union{Integer, Rational, AbstractFloat}; check::Bool=true)
643+
function divexact(x::AbsPowerSeriesRingElem, y::JuliaRingElement; check::Bool=true)
658644
iszero(y) && throw(DivideError())
659645
lenx = length(x)
660646
z = parent(x)()

src/AbstractAlgebra.jl

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -179,10 +179,14 @@ pretty_eq(x::Number, y::Number) = (x == y)
179179
include("julia/JuliaTypes.jl")
180180

181181
# Unions of AbstactAlgebra abstract types and Julia types
182-
const RingElement = Union{RingElem, Integer, Rational, AbstractFloat}
183-
const NCRingElement = Union{NCRingElem, Integer, Rational, AbstractFloat}
182+
const JuliaRingElement = Union{Integer, Rational, AbstractFloat}
183+
const JuliaFieldElement = Union{Rational, AbstractFloat}
184+
const JuliaExactRingElement = Union{Integer, Rational}
184185

185-
const FieldElement = Union{FieldElem, Rational, AbstractFloat}
186+
const RingElement = Union{RingElem, JuliaRingElement}
187+
const NCRingElement = Union{NCRingElem, JuliaRingElement}
188+
189+
const FieldElement = Union{FieldElem, JuliaFieldElement}
186190

187191
include("ConcreteTypes.jl")
188192

src/Fraction.jl

Lines changed: 4 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -374,7 +374,7 @@ end
374374

375375
-(a::FracElem, b::Rational) = return a - parent(a)(b)
376376

377-
+(a::Union{Integer, Rational, AbstractFloat}, b::FracElem) = b + a
377+
+(a::JuliaRingElement, b::FracElem) = b + a
378378

379379
function -(a::Union{Integer, AbstractFloat}, b::FracElem)
380380
n = a*denominator(b, false) - numerator(b, false)
@@ -451,11 +451,6 @@ end
451451
#
452452
###############################################################################
453453

454-
@doc raw"""
455-
==(x::FracElem, y::Union{Integer, Rational, AbstractFloat})
456-
457-
Return `true` if $x == y$ arithmetically, otherwise return `false`.
458-
"""
459454
function ==(x::FracElem, y::Union{Integer, AbstractFloat})
460455
return (isone(denominator(x, false)) && numerator(x, false) == y) ||
461456
(isone(denominator(x, true)) && numerator(x, true) == y) ||
@@ -469,15 +464,11 @@ function ==(x::FracElem, y::Rational)
469464
denominator(x, false)*numerator(y, false))
470465
end
471466

472-
@doc raw"""
473-
==(x::Union{Integer, Rational, AbstractFloat}, y::FracElem)
474-
475-
Return `true` if $x == y$ arithmetically, otherwise return `false`.
476-
"""
477-
==(x::Union{Integer, Rational, AbstractFloat}, y::FracElem) = y == x
467+
==(x::JuliaRingElement, y::FracElem) = y == x
478468

479469
@doc raw"""
480-
==(x::FracElem{T}, y::T) where {T <: RingElem}
470+
==(x::FracElem{<:RingElem}, y::RingElement)
471+
==(x::RingElement, y::FracElem{<:RingElem})
481472
482473
Return `true` if $x == y$ arithmetically, otherwise return `false`.
483474
"""
@@ -487,11 +478,6 @@ function ==(x::FracElem{T}, y::T) where {T <: RingElem}
487478
(numerator(x, false) == denominator(x, false)*y)
488479
end
489480

490-
@doc raw"""
491-
==(x::T, y::FracElem{T}) where {T <: RingElem}
492-
493-
Return `true` if $x == y$ arithmetically, otherwise return `false`.
494-
"""
495481
==(x::T, y::FracElem{T}) where {T <: RingElem} = y == x
496482

497483
###############################################################################

src/MatRing.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ end
208208
#
209209
###############################################################################
210210

211-
function ==(x::MatRingElem, y::Union{Integer, Rational, AbstractFloat})
211+
function ==(x::MatRingElem, y::JuliaRingElement)
212212
n = degree(x)
213213
for i = 1:n
214214
if x[i, i] != y
@@ -225,7 +225,7 @@ function ==(x::MatRingElem, y::Union{Integer, Rational, AbstractFloat})
225225
return true
226226
end
227227

228-
==(x::Union{Integer, Rational, AbstractFloat}, y::MatRingElem) = y == x
228+
==(x::JuliaRingElement, y::MatRingElem) = y == x
229229

230230
function ==(x::MatRingElem{T}, y::T) where T <: NCRingElem
231231
n = degree(x)

src/Matrix.jl

Lines changed: 16 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ end
919919
#
920920
###############################################################################
921921

922-
function *(x::Union{Integer, Rational, AbstractFloat}, y::MatrixElem{T}) where T <: NCRingElement
922+
function *(x::JuliaRingElement, y::MatrixElem{T}) where T <: NCRingElement
923923
z = similar(y)
924924
for i = 1:nrows(y)
925925
for j = 1:ncols(y)
@@ -939,7 +939,7 @@ function *(x::T, y::MatrixElem{T}) where {T <: NCRingElem}
939939
return z
940940
end
941941

942-
function *(x::MatrixElem{T}, y::Union{Integer, Rational, AbstractFloat}) where T <: NCRingElement
942+
function *(x::MatrixElem{T}, y::JuliaRingElement) where T <: NCRingElement
943943
z = similar(x)
944944
for i = 1:nrows(x)
945945
for j = 1:ncols(x)
@@ -959,12 +959,7 @@ function *(x::MatrixElem{T}, y::T) where {T <: NCRingElem}
959959
return z
960960
end
961961

962-
@doc raw"""
963-
+(x::Union{Integer, Rational, AbstractFloat}, y::MatrixElem)
964-
965-
Return $S(x) + y$ where $S$ is the parent of $y$.
966-
"""
967-
function +(x::Union{Integer, Rational, AbstractFloat}, y::MatrixElem{T}) where T <: NCRingElement
962+
function +(x::JuliaRingElement, y::MatrixElem{T}) where T <: NCRingElement
968963
z = similar(y)
969964
R = base_ring(y)
970965
for i = 1:nrows(y)
@@ -979,15 +974,10 @@ function +(x::Union{Integer, Rational, AbstractFloat}, y::MatrixElem{T}) where T
979974
return z
980975
end
981976

982-
@doc raw"""
983-
+(x::MatrixElem{T}, y::Union{Integer, Rational, AbstractFloat}) where T <: NCRingElement
984-
985-
Return $x + S(y)$ where $S$ is the parent of $x$.
986-
"""
987-
+(x::MatrixElem{T}, y::Union{Integer, Rational, AbstractFloat}) where T <: NCRingElement = y + x
977+
+(x::MatrixElem{T}, y::JuliaRingElement) where T <: NCRingElement = y + x
988978

989979
@doc raw"""
990-
+(x::T, y::MatrixElem{T}) where {T <: NCRingElem}
980+
+(x::NCRingElement, y::MatrixElem{<:NCRingElement})
991981
992982
Return $S(x) + y$ where $S$ is the parent of $y$.
993983
"""
@@ -1006,18 +996,13 @@ function +(x::T, y::MatrixElem{T}) where {T <: NCRingElem}
1006996
end
1007997

1008998
@doc raw"""
1009-
+(x::MatrixElem{T}, y::T) where {T <: RingElem}
999+
+(x::MatrixElem{<:NCRingElement}, y::NCRingElement)
10101000
1011-
Return $x + S(y)$ where $S$ is the parent of $x$.
1001+
Return $x + S(y)$, where $S$ is the parent of $a$.
10121002
"""
10131003
+(x::MatrixElem{T}, y::T) where {T <: NCRingElem} = y + x
10141004

1015-
@doc raw"""
1016-
-(x::Union{Integer, Rational, AbstractFloat}, y::MatrixElem{T}) where T <: NCRingElement
1017-
1018-
Return $S(x) - y$ where $S$ is the parent of $y$.
1019-
"""
1020-
function -(x::Union{Integer, Rational, AbstractFloat}, y::MatrixElem{T}) where T <: NCRingElement
1005+
function -(x::JuliaRingElement, y::MatrixElem{T}) where T <: NCRingElement
10211006
z = similar(y)
10221007
R = base_ring(y)
10231008
for i = 1:nrows(y)
@@ -1032,12 +1017,7 @@ function -(x::Union{Integer, Rational, AbstractFloat}, y::MatrixElem{T}) where T
10321017
return z
10331018
end
10341019

1035-
@doc raw"""
1036-
-(x::MatrixElem{T}, y::Union{Integer, Rational, AbstractFloat}) where T <: NCRingElement
1037-
1038-
Return $x - S(y)$, where $S$ is the parent of $x$.
1039-
"""
1040-
function -(x::MatrixElem{T}, y::Union{Integer, Rational, AbstractFloat}) where T <: NCRingElement
1020+
function -(x::MatrixElem{T}, y::JuliaRingElement) where T <: NCRingElement
10411021
z = similar(x)
10421022
R = base_ring(x)
10431023
for i = 1:nrows(x)
@@ -1053,7 +1033,7 @@ function -(x::MatrixElem{T}, y::Union{Integer, Rational, AbstractFloat}) where T
10531033
end
10541034

10551035
@doc raw"""
1056-
-(x::T, y::MatrixElem{T}) where {T <: NCRingElem}
1036+
-(x::NCRingElement, y::MatrixElem{<:NCRingElement})
10571037
10581038
Return $S(x) - y$ where $S$ is the parent of $y$.
10591039
"""
@@ -1073,7 +1053,7 @@ function -(x::T, y::MatrixElem{T}) where {T <: NCRingElem}
10731053
end
10741054

10751055
@doc raw"""
1076-
-(x::MatrixElem{T}, y::T) where {T <: NCRingElem}
1056+
-(x::MatrixElem{<:NCRingElem}, y::NCRingElement)
10771057
10781058
Return $x - S(y)$, where $S$ is the parent of $a$.
10791059
"""
@@ -1338,13 +1318,7 @@ end
13381318
#
13391319
###############################################################################
13401320

1341-
@doc raw"""
1342-
==(x::MatrixElem{T}, y::Union{Integer, Rational, AbstractFloat}) where T <: NCRingElement
1343-
1344-
Return `true` if $x == S(y)$ arithmetically, where $S$ is the parent of $x$,
1345-
otherwise return `false`.
1346-
"""
1347-
function ==(x::MatrixElem{T}, y::Union{Integer, Rational, AbstractFloat}) where T <: NCRingElement
1321+
function ==(x::MatrixElem{T}, y::JuliaRingElement) where T <: NCRingElement
13481322
for i = 1:min(nrows(x), ncols(x))
13491323
if x[i, i] != y
13501324
return false
@@ -1360,16 +1334,10 @@ function ==(x::MatrixElem{T}, y::Union{Integer, Rational, AbstractFloat}) where
13601334
return true
13611335
end
13621336

1363-
@doc raw"""
1364-
==(x::Union{Integer, Rational, AbstractFloat}, y::MatrixElem{T}) where T <: NCRingElement
1365-
1366-
Return `true` if $S(x) == y$ arithmetically, where $S$ is the parent of $y$,
1367-
otherwise return `false`.
1368-
"""
1369-
==(x::Union{Integer, Rational, AbstractFloat}, y::MatrixElem{T}) where T <: NCRingElement = y == x
1337+
==(x::JuliaRingElement, y::MatrixElem{T}) where T <: NCRingElement = y == x
13701338

13711339
@doc raw"""
1372-
==(x::MatrixElem{T}, y::T) where {T <: NCRingElem}
1340+
==(x::MatrixElem{<:NCRingElement}, y::NCRingElement)
13731341
13741342
Return `true` if $x == S(y)$ arithmetically, where $S$ is the parent of $x$,
13751343
otherwise return `false`.
@@ -1391,7 +1359,7 @@ function ==(x::MatrixElem{T}, y::T) where {T <: NCRingElem}
13911359
end
13921360

13931361
@doc raw"""
1394-
==(x::T, y::MatrixElem{T}) where {T <: NCRingElem}
1362+
==(x::NCRingElement, y::MatrixElem{<:NCRingElement})
13951363
13961364
Return `true` if $S(x) == y$ arithmetically, where $S$ is the parent of $y$,
13971365
otherwise return `false`.
@@ -1404,7 +1372,7 @@ otherwise return `false`.
14041372
#
14051373
###############################################################################
14061374

1407-
function divexact(x::MatrixElem{T}, y::Union{Integer, Rational, AbstractFloat}; check::Bool=true) where T <: NCRingElement
1375+
function divexact(x::MatrixElem{T}, y::JuliaRingElement; check::Bool=true) where T <: NCRingElement
14081376
z = similar(x)
14091377
for i = 1:nrows(x)
14101378
for j = 1:ncols(x)

0 commit comments

Comments
 (0)