Skip to content

Make RealNumbers parametric in its element type - #188

Open
dlfivefifty wants to merge 1 commit into
masterfrom
realnumbers-eltype
Open

dlfivefifty wants to merge 1 commit into
masterfrom
realnumbers-eltype

Conversation

@dlfivefifty

Copy link
Copy Markdown
Member

ℝ is a Domain{Float64} and had no similardomain method, so it couldn't be converted to another element type. Products like UnitDisk{Float32}() × ℝ threw a MethodError:

MethodError: no method matching similardomain(::DomainSets.RealNumbers, ::Type{ForwardDiff.Dual{...}})

This came up when differentiating a basis on UnitDisk{T}() × ℝ with ForwardDiff, which evaluates at T = Dual.

This PR follows the existing FullSpace{T} pattern:

  • RealNumbers{T<:Real} <: Domain{T}. RealNumbers() and ℝ default to Float64, so their behaviour is unchanged.
  • similardomain(::RealNumbers, ::Type{T}) where T<:Real = RealNumbers{T}().
  • Equality and hashing ignore T, so ℝ == RealNumbers{Float32}(). This matches FullSpace.

One visible change: ℝ now prints as RealNumbers{Float64}() instead of RealNumbers(). Code that dispatches on ::RealNumbers is unaffected, since RealNumbers now names the UnionAll.

I bumped the version to 0.8.4. The full test suite passes.

🤖 Generated with Claude Code

ℝ is a Domain{Float64} with no similardomain method, so it could not be
converted to another element type. This made e.g. UnitDisk{Float32}() × ℝ
or UnitDisk{Dual}() × ℝ (used with ForwardDiff) throw a MethodError.

RealNumbers{T<:Real} now subtypes Domain{T}, with RealNumbers() and ℝ
defaulting to Float64, as with FullSpace. Equality and hashing ignore T.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@codecov

codecov Bot commented Nov 4, 2026 •

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 94.06%. Comparing base (ad941e6) to head (2208156).

Additional details and impacted files
@@            Coverage Diff             @@
##           master     #188      +/-   ##
==========================================
+ Coverage   94.04%   94.06%   +0.01%     
==========================================
  Files          28       28              
  Lines        1865     1869       +4     
==========================================
+ Hits         1754     1758       +4     
  Misses        111      111              

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@dlfivefifty

Copy link
Copy Markdown
Member Author

Actually not sure what the difference between RealNumbers and FullSpace is.

I've changed my code to use FullSpace

@daanhb

daanhb commented Nov 13, 2026

Copy link
Copy Markdown
Member

One important difference is that FullSpace does not guard against conversion, but the sets of integers and numbers do. That leads to something possibly unexpected:

julia> d1 = FullSpace{Int}()
{x} (full space)

julia> 2.1 ∈ d1
true

julia> d2 = Integers()
Integers()

julia> 2.1 ∈ d2
false

So you may want to use the PR after all?

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants