Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions docs/src/ncpolynomial.md
Original file line number Diff line number Diff line change
Expand Up @@ -351,8 +351,7 @@ x
### Evaluation

```@docs
evaluate{T <: NCRingElem}(::NCPolyRingElem{T}, ::T)
evaluate(::NCPolyRingElem, ::Integer)
evaluate(::NCPolyRingElem, ::NCRingElem)
```

We also overload the functional notation so that the polynomial $f$ can be
Expand Down
28 changes: 7 additions & 21 deletions src/AbsSeries.jl
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ function *(a::T, b::AbsPowerSeriesRingElem{T}) where {T <: RingElem}
return z
end

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

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

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

###############################################################################
#
Expand Down Expand Up @@ -563,35 +563,21 @@ end
###############################################################################

@doc raw"""
==(x::AbsPowerSeriesRingElem{T}, y::T) where {T <: RingElem}
==(x::AbsPowerSeriesRingElem{<:RingElem}, y::RingElement)
==(x::RingElement, y::AbsPowerSeriesRingElem{<:RingElem})

Return `true` if $x == y$ arithmetically, otherwise return `false`.
"""
==(x::AbsPowerSeriesRingElem{T}, y::T) where {T <: RingElem} = precision(x) == 0 ||
((length(x) == 0 && iszero(y)) || (length(x) == 1 && coeff(x, 0) == y))

@doc raw"""
==(x::T, y::AbsPowerSeriesRingElem{T}) where {T <: RingElem}

Return `true` if $x == y$ arithmetically, otherwise return `false`.
"""
==(x::T, y::AbsPowerSeriesRingElem{T}) where {T <: RingElem} = y == x

@doc raw"""
==(x::AbsPowerSeriesRingElem, y::Union{Integer, Rational, AbstractFloat})

Return `true` if $x == y$ arithmetically, otherwise return `false`.
"""
==(x::AbsPowerSeriesRingElem, y::Union{Integer, Rational, AbstractFloat}) = precision(x) == 0 ||
==(x::AbsPowerSeriesRingElem, y::JuliaRingElement) = precision(x) == 0 ||
((length(x) == 0 && iszero(base_ring(x)(y))) ||
(length(x) == 1 && coeff(x, 0) == y))

@doc raw"""
==(x::Union{Integer, Rational, AbstractFloat}, y::AbsPowerSeriesRingElem)

Return `true` if $x == y$ arithmetically, otherwise return `false`.
"""
==(x::Union{Integer, Rational, AbstractFloat}, y::AbsPowerSeriesRingElem) = y == x
==(x::JuliaRingElement, y::AbsPowerSeriesRingElem) = y == x

###############################################################################
#
Expand Down Expand Up @@ -654,7 +640,7 @@ end
#
###############################################################################

function divexact(x::AbsPowerSeriesRingElem, y::Union{Integer, Rational, AbstractFloat}; check::Bool=true)
function divexact(x::AbsPowerSeriesRingElem, y::JuliaRingElement; check::Bool=true)
iszero(y) && throw(DivideError())
lenx = length(x)
z = parent(x)()
Expand Down
10 changes: 7 additions & 3 deletions src/AbstractAlgebra.jl
Original file line number Diff line number Diff line change
Expand Up @@ -179,10 +179,14 @@ pretty_eq(x::Number, y::Number) = (x == y)
include("julia/JuliaTypes.jl")

# Unions of AbstactAlgebra abstract types and Julia types
const RingElement = Union{RingElem, Integer, Rational, AbstractFloat}
const NCRingElement = Union{NCRingElem, Integer, Rational, AbstractFloat}
const JuliaRingElement = Union{Integer, Rational, AbstractFloat}
const JuliaFieldElement = Union{Rational, AbstractFloat}
const JuliaExactRingElement = Union{Integer, Rational}

const FieldElement = Union{FieldElem, Rational, AbstractFloat}
const RingElement = Union{RingElem, JuliaRingElement}
const NCRingElement = Union{NCRingElem, JuliaRingElement}

const FieldElement = Union{FieldElem, JuliaFieldElement}

include("ConcreteTypes.jl")

Expand Down
22 changes: 4 additions & 18 deletions src/Fraction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ end

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

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

function -(a::Union{Integer, AbstractFloat}, b::FracElem)
n = a*denominator(b, false) - numerator(b, false)
Expand Down Expand Up @@ -451,11 +451,6 @@ end
#
###############################################################################

@doc raw"""
==(x::FracElem, y::Union{Integer, Rational, AbstractFloat})

Return `true` if $x == y$ arithmetically, otherwise return `false`.
"""
function ==(x::FracElem, y::Union{Integer, AbstractFloat})
return (isone(denominator(x, false)) && numerator(x, false) == y) ||
(isone(denominator(x, true)) && numerator(x, true) == y) ||
Expand All @@ -469,15 +464,11 @@ function ==(x::FracElem, y::Rational)
denominator(x, false)*numerator(y, false))
end

@doc raw"""
==(x::Union{Integer, Rational, AbstractFloat}, y::FracElem)

Return `true` if $x == y$ arithmetically, otherwise return `false`.
"""
==(x::Union{Integer, Rational, AbstractFloat}, y::FracElem) = y == x
==(x::JuliaRingElement, y::FracElem) = y == x

@doc raw"""
==(x::FracElem{T}, y::T) where {T <: RingElem}
==(x::FracElem{<:RingElem}, y::RingElement)
==(x::RingElement, y::FracElem{<:RingElem})

Return `true` if $x == y$ arithmetically, otherwise return `false`.
"""
Expand All @@ -487,11 +478,6 @@ function ==(x::FracElem{T}, y::T) where {T <: RingElem}
(numerator(x, false) == denominator(x, false)*y)
end

@doc raw"""
==(x::T, y::FracElem{T}) where {T <: RingElem}

Return `true` if $x == y$ arithmetically, otherwise return `false`.
"""
==(x::T, y::FracElem{T}) where {T <: RingElem} = y == x

###############################################################################
Expand Down
4 changes: 2 additions & 2 deletions src/MatRing.jl
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ end
#
###############################################################################

function ==(x::MatRingElem, y::Union{Integer, Rational, AbstractFloat})
function ==(x::MatRingElem, y::JuliaRingElement)
n = degree(x)
for i = 1:n
if x[i, i] != y
Expand All @@ -225,7 +225,7 @@ function ==(x::MatRingElem, y::Union{Integer, Rational, AbstractFloat})
return true
end

==(x::Union{Integer, Rational, AbstractFloat}, y::MatRingElem) = y == x
==(x::JuliaRingElement, y::MatRingElem) = y == x

function ==(x::MatRingElem{T}, y::T) where T <: NCRingElem
n = degree(x)
Expand Down
64 changes: 16 additions & 48 deletions src/Matrix.jl
Original file line number Diff line number Diff line change
Expand Up @@ -919,7 +919,7 @@ end
#
###############################################################################

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

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

@doc raw"""
+(x::Union{Integer, Rational, AbstractFloat}, y::MatrixElem)

Return $S(x) + y$ where $S$ is the parent of $y$.
"""
function +(x::Union{Integer, Rational, AbstractFloat}, y::MatrixElem{T}) where T <: NCRingElement
function +(x::JuliaRingElement, y::MatrixElem{T}) where T <: NCRingElement
z = similar(y)
R = base_ring(y)
for i = 1:nrows(y)
Expand All @@ -979,15 +974,10 @@ function +(x::Union{Integer, Rational, AbstractFloat}, y::MatrixElem{T}) where T
return z
end

@doc raw"""
+(x::MatrixElem{T}, y::Union{Integer, Rational, AbstractFloat}) where T <: NCRingElement

Return $x + S(y)$ where $S$ is the parent of $x$.
"""
+(x::MatrixElem{T}, y::Union{Integer, Rational, AbstractFloat}) where T <: NCRingElement = y + x
+(x::MatrixElem{T}, y::JuliaRingElement) where T <: NCRingElement = y + x

@doc raw"""
+(x::T, y::MatrixElem{T}) where {T <: NCRingElem}
+(x::NCRingElement, y::MatrixElem{<:NCRingElement})

Return $S(x) + y$ where $S$ is the parent of $y$.
"""
Expand All @@ -1006,18 +996,13 @@ function +(x::T, y::MatrixElem{T}) where {T <: NCRingElem}
end

@doc raw"""
+(x::MatrixElem{T}, y::T) where {T <: RingElem}
+(x::MatrixElem{<:NCRingElement}, y::NCRingElement)

Return $x + S(y)$ where $S$ is the parent of $x$.
Return $x + S(y)$, where $S$ is the parent of $a$.
"""
+(x::MatrixElem{T}, y::T) where {T <: NCRingElem} = y + x

@doc raw"""
-(x::Union{Integer, Rational, AbstractFloat}, y::MatrixElem{T}) where T <: NCRingElement

Return $S(x) - y$ where $S$ is the parent of $y$.
"""
function -(x::Union{Integer, Rational, AbstractFloat}, y::MatrixElem{T}) where T <: NCRingElement
function -(x::JuliaRingElement, y::MatrixElem{T}) where T <: NCRingElement
z = similar(y)
R = base_ring(y)
for i = 1:nrows(y)
Expand All @@ -1032,12 +1017,7 @@ function -(x::Union{Integer, Rational, AbstractFloat}, y::MatrixElem{T}) where T
return z
end

@doc raw"""
-(x::MatrixElem{T}, y::Union{Integer, Rational, AbstractFloat}) where T <: NCRingElement

Return $x - S(y)$, where $S$ is the parent of $x$.
"""
function -(x::MatrixElem{T}, y::Union{Integer, Rational, AbstractFloat}) where T <: NCRingElement
function -(x::MatrixElem{T}, y::JuliaRingElement) where T <: NCRingElement
z = similar(x)
R = base_ring(x)
for i = 1:nrows(x)
Expand All @@ -1053,7 +1033,7 @@ function -(x::MatrixElem{T}, y::Union{Integer, Rational, AbstractFloat}) where T
end

@doc raw"""
-(x::T, y::MatrixElem{T}) where {T <: NCRingElem}
-(x::NCRingElement, y::MatrixElem{<:NCRingElement})

Return $S(x) - y$ where $S$ is the parent of $y$.
"""
Expand All @@ -1073,7 +1053,7 @@ function -(x::T, y::MatrixElem{T}) where {T <: NCRingElem}
end

@doc raw"""
-(x::MatrixElem{T}, y::T) where {T <: NCRingElem}
-(x::MatrixElem{<:NCRingElem}, y::NCRingElement)

Return $x - S(y)$, where $S$ is the parent of $a$.
"""
Expand Down Expand Up @@ -1338,13 +1318,7 @@ end
#
###############################################################################

@doc raw"""
==(x::MatrixElem{T}, y::Union{Integer, Rational, AbstractFloat}) where T <: NCRingElement

Return `true` if $x == S(y)$ arithmetically, where $S$ is the parent of $x$,
otherwise return `false`.
"""
function ==(x::MatrixElem{T}, y::Union{Integer, Rational, AbstractFloat}) where T <: NCRingElement
function ==(x::MatrixElem{T}, y::JuliaRingElement) where T <: NCRingElement
for i = 1:min(nrows(x), ncols(x))
if x[i, i] != y
return false
Expand All @@ -1360,16 +1334,10 @@ function ==(x::MatrixElem{T}, y::Union{Integer, Rational, AbstractFloat}) where
return true
end

@doc raw"""
==(x::Union{Integer, Rational, AbstractFloat}, y::MatrixElem{T}) where T <: NCRingElement

Return `true` if $S(x) == y$ arithmetically, where $S$ is the parent of $y$,
otherwise return `false`.
"""
==(x::Union{Integer, Rational, AbstractFloat}, y::MatrixElem{T}) where T <: NCRingElement = y == x
==(x::JuliaRingElement, y::MatrixElem{T}) where T <: NCRingElement = y == x

@doc raw"""
==(x::MatrixElem{T}, y::T) where {T <: NCRingElem}
==(x::MatrixElem{<:NCRingElement}, y::NCRingElement)

Return `true` if $x == S(y)$ arithmetically, where $S$ is the parent of $x$,
otherwise return `false`.
Expand All @@ -1391,7 +1359,7 @@ function ==(x::MatrixElem{T}, y::T) where {T <: NCRingElem}
end

@doc raw"""
==(x::T, y::MatrixElem{T}) where {T <: NCRingElem}
==(x::NCRingElement, y::MatrixElem{<:NCRingElement})

Return `true` if $S(x) == y$ arithmetically, where $S$ is the parent of $y$,
otherwise return `false`.
Expand All @@ -1404,7 +1372,7 @@ otherwise return `false`.
#
###############################################################################

function divexact(x::MatrixElem{T}, y::Union{Integer, Rational, AbstractFloat}; check::Bool=true) where T <: NCRingElement
function divexact(x::MatrixElem{T}, y::JuliaRingElement; check::Bool=true) where T <: NCRingElement
z = similar(x)
for i = 1:nrows(x)
for j = 1:ncols(x)
Expand Down
Loading
Loading