You might be interested in Issue #5234
<https://github.com/JuliaLang/julia/issues/5234>, where I tried to
catalogue issues arising from nonfinite floating-point computations in the
ordinary complex plane (without closure on the Riemann sphere).

Being able to switch between complex and extended complex (closed at
ComplexInf) would be interesting. I vaguely recall discussing complex
infinity with Mike Innes at some point, but I don't recall if we got
anywhere.

One solution is to wrap ordinary complex numbers in a new type representing
finite extended complex numbers, and create yet another new type
representing complex infinity. Define each function over the exted For each
function, and redefine each function you want to use by either wrapping a
finite answer in the new type, or otherwise checking if the answer is
infinite and returning another new type instead which represents complex
infinity.

####

abstract ExtendedComplex{T<:Real}

immutable ComplexInf{T<:Real} <: ExtendedComplex{T} end

immutable FiniteExtendedComplex{T<:Real} <: ExtendedComplex{T}
    z :: Complex{T}
end

function ExtendedComplex{T<:Real}(r::T, i::T)
    if isfinite(r) && isfinite(i))
        return ExtendedComplex(Complex(r, i))
    else
        return ComplexInf{T}()
    end
end

import Base./

function /{T}(z:: ComplexInf{T}, w:: FiniteExtendedComplex{T})
    return z
end

function /{T}(z:: FiniteExtendedComplex{T}, w:: ComplexInf{T})
    return zero(z)
end

function /{T}(z:: FiniteExtendedComplex{T}, w:: FiniteExtendedComplex{T})
    a = z.z/w.z
    return isfinite(a) ? ExtendedComplex(a) : ComplexInf{T}
end

####

With these definitions you can compute as follows:

julia> FiniteExtendedComplex(2.0, 0.5)/FiniteExtendedComplex(0.5, 2.0)
FiniteExtendedComplex{Float64}(0.47058823529411764 - 0.8823529411764706im)

julia> FiniteExtendedComplex(2.0, 0.3)/FiniteExtendedComplex(0.0, 0.0)
ComplexInf{Float64}()

julia> ComplexInf{Float64}()/FiniteExtendedComplex(0.0, 0.0)
ComplexInf{Float64}()

julia> ComplexInf{Float64}()/ComplexInf{Float64}() #Don't know how to do ∞/∞
ERROR: `/` has no method matching /(::ComplexInf{Float64},
::ComplexInf{Float64})


Thanks,

Jiahao Chen
Staff Research Scientist
MIT Computer Science and Artificial Intelligence Laboratory

On Sat, Jan 10, 2015 at 8:55 AM, Ed Scheinerman <
edward.scheiner...@gmail.com> wrote:

> Is there a way to have a single complex infinity? This may come at the
> cost of computational efficiency I suppose, but I can think of situations
> where all of the following give the same result:
>
> julia> (1+1im)/0
> Inf + Inf*im
>
> julia> 1im/0
> NaN + Inf*im
>
> julia> 1/0 + im
> Inf + 1.0im
>
> It would be nice (sometimes) if these were all the same ComplexInf, say.
> Perhaps there's an "extended complex numbers" module for this sort of work?
>

Reply via email to