Repository navigation
Open
Labels
bugSomething isn't working
Description
Bug description
CubatureJLh does not uphold the same guarantees around singularities as the underlying solver.
Integrating
MRE
using Integrals
using Cubature
f(x, u) = log.(x[1]) ./ sqrt.(x[1])
ff(x) = f(x, 0)
hcubature(ff, 0, 1)
# returns:
# (-3.999999997790874, 3.99790148863247e-8)
problem = IntegralProblem(f, (0, 1))
solve(problem, CubatureJLh())
# returns:
# retcode: Success
# u: -InfExpected result
Integrals.jl should not compromise guarantees given by the solver (i.e. should not evaluate the function at the endpoints)
Environment (please complete the following information):
- Output of
using Pkg; Pkg.status()
[fb37089c] Arblib v1.6.1
[8a292aeb] Cuba v2.3.0
[667455a9] Cubature v1.5.1
[442a2c76] FastGaussQuadrature v1.1.0
[de52edbc] Integrals v4.7.1
[ea1e2de9] MCIntegration v0.4.2- Output of
using Pkg; Pkg.status(; mode = PKGMODE_MANIFEST)
[47edcb42] ADTypes v1.18.0
[7d9f7c33] Accessors v0.1.42
[79e6a3ab] Adapt v4.4.0
[66dad0bd] AliasTables v1.1.3
[fb37089c] Arblib v1.6.1
[ec485272] ArnoldiMethod v0.4.0
[4fba245c] ArrayInterface v7.22.0
[861a8166] Combinatorics v1.0.3
[38540f10] CommonSolve v0.2.4
[34da2185] Compat v4.18.1
[a33af91c] CompositionsBase v0.1.2
[2569d6c7] ConcreteStructs v0.2.3
[187b0558] ConstructionBase v1.6.0
[8a292aeb] Cuba v2.3.0
[667455a9] Cubature v1.5.1
[9a962f9c] DataAPI v1.16.0
⌅ [864edb3b] DataStructures v0.18.22
[8bb1440f] DelimitedFiles v1.9.1
[31c24e10] Distributions v0.25.122
[ffbed154] DocStringExtensions v0.9.5
[4e289a0a] EnumX v1.0.5
[e2ba6199] ExprTools v0.1.10
[55351af7] ExproniconLite v0.10.14
[442a2c76] FastGaussQuadrature v1.1.0
[1a297f60] FillArrays v1.14.0
[069b7b12] FunctionWrappers v1.1.3
[77dc65aa] FunctionWrappersWrappers v0.1.3
[46192b85] GPUArraysCore v0.2.0
[86223c79] Graphs v1.13.1
[19dc6840] HCubature v1.7.0
[076d061b] HashArrayMappedTries v0.2.0
[34004b35] HypergeometricFunctions v0.3.28
[d25df0c9] Inflate v0.1.5
[18e54dd8] IntegerMathUtils v0.1.3
[de52edbc] Integrals v4.7.1
[3587e190] InverseFunctions v0.1.17
[92d709cd] IrrationalConstants v0.2.6
[82899510] IteratorInterfaceExtensions v1.0.0
[692b3bcd] JLLWrappers v1.7.1
[ae98c720] Jieko v0.2.1
[73f95e8e] LatticeRules v0.0.1
[2ab3a3ac] LogExpFunctions v0.3.29
[e6f89c97] LoggingExtras v1.2.0
[ea1e2de9] MCIntegration v0.4.2
[da04e1cc] MPI v0.20.23
[3da0fdf6] MPIPreferences v0.1.11
[1914dd2f] MacroTools v0.5.16
[e1d29d7a] Missings v1.2.0
[4886b29c] MonteCarloIntegration v0.2.0
[2e0e35c7] Moshi v0.3.7
[bac558e1] OrderedCollections v1.8.1
[90014a1f] PDMats v0.11.36
[eebad327] PkgVersion v0.3.3
[d236fae5] PreallocationTools v0.4.34
[aea7be01] PrecompileTools v1.3.3
[21216c6a] Preferences v1.5.0
[27ebfcd6] Primes v0.5.7
[92933f4c] ProgressMeter v1.11.0
[43287f4e] PtrArrays v1.3.0
[1fd47b50] QuadGK v2.11.2
[8a4e6c94] QuasiMonteCarlo v0.3.3
[3cdcf5f2] RecipesBase v1.3.4
[731186ca] RecursiveArrayTools v3.39.0
[189a3867] Reexport v1.2.2
[ae029012] Requires v1.3.1
[79098fc4] Rmath v0.9.0
[7e49a35a] RuntimeGeneratedFunctions v0.5.16
[0bca4576] SciMLBase v2.124.0
[a6db7da4] SciMLLogging v1.4.0
[c0aeaf25] SciMLOperators v1.10.0
[431bcebd] SciMLPublic v1.0.0
[53ae85a6] SciMLStructures v1.7.0
[7e506255] ScopedValues v1.5.0
[699a6c99] SimpleTraits v0.9.5
[ed01d8cd] Sobol v1.5.0
[a2af1166] SortingAlgorithms v1.2.2
[276daf66] SpecialFunctions v2.6.1
[90137ffa] StaticArrays v1.9.15
[1e83bf80] StaticArraysCore v1.4.4
[10745b16] Statistics v1.11.1
[82ae8749] StatsAPI v1.7.1
[2913bbd2] StatsBase v0.34.7
[4c63d2b9] StatsFuns v1.5.2
[2efcf032] SymbolicIndexingInterface v0.3.46
[3bed1096] Cuba_jll v4.2.2+1
[7bc98958] Cubature_jll v1.0.5+0
[e134572f] FLINT_jll v301.300.102+0
[e33a78d0] Hwloc_jll v2.12.2+0
[94ce4f54] Libiconv_jll v1.18.0+0
[7cb0a576] MPICH_jll v4.3.2+0
[f1f71cc9] MPItrampoline_jll v5.5.4+0
[9237b28f] MicrosoftMPI_jll v10.1.4+3
[656ef2d0] OpenBLAS32_jll v0.3.29+0
[fe0851c0] OpenMPI_jll v5.0.8+0
[efe28fd5] OpenSpecFun_jll v0.5.6+0
[f50d1b31] Rmath_jll v0.5.1+0
⌅ [02c8fc9c] XML2_jll v2.13.9+0
[a65dc6b1] Xorg_libpciaccess_jll v0.18.1+0
[0dad84c5] ArgTools v1.1.2
[56f22d72] Artifacts v1.11.0
[2a0f44e3] Base64 v1.11.0
[ade2ca70] Dates v1.11.0
[8ba89e20] Distributed v1.11.0
[f43a241f] Downloads v1.6.0
[7b1f6079] FileWatching v1.11.0
[b77e0a4c] InteractiveUtils v1.11.0
[ac6e5ff7] JuliaSyntaxHighlighting v1.12.0
[4af54fe1] LazyArtifacts v1.11.0
[b27032c2] LibCURL v0.6.4
[76f85450] LibGit2 v1.11.0
[8f399da3] Libdl v1.11.0
[37e2e46d] LinearAlgebra v1.12.0
[56ddb016] Logging v1.11.0
[d6f4376e] Markdown v1.11.0
[a63ad114] Mmap v1.11.0
[ca575930] NetworkOptions v1.3.0
[44cfe95a] Pkg v1.12.0
[de0858da] Printf v1.11.0
[9a3f8284] Random v1.11.0
[ea8e919c] SHA v0.7.0
[9e88b42a] Serialization v1.11.0
[1a1011a3] SharedArrays v1.11.0
[6462fe0b] Sockets v1.11.0
[2f01184e] SparseArrays v1.12.0
[f489334b] StyledStrings v1.11.0
[4607b0f0] SuiteSparse
[fa267f1f] TOML v1.0.3
[a4e569a6] Tar v1.10.0
[8dfed614] Test v1.11.0
[cf7118a7] UUIDs v1.11.0
[4ec0a83e] Unicode v1.11.0
[e66e0078] CompilerSupportLibraries_jll v1.3.0+1
[781609d7] GMP_jll v6.3.0+2
[deac9b47] LibCURL_jll v8.11.1+1
[e37daf67] LibGit2_jll v1.9.0+0
[29816b5a] LibSSH2_jll v1.11.3+1
[3a97d323] MPFR_jll v4.2.2+0
[14a3606d] MozillaCACerts_jll v2025.5.20
[4536629a] OpenBLAS_jll v0.3.29+0
[05823500] OpenLibm_jll v0.8.7+0
[458c3c95] OpenSSL_jll v3.5.1+0
[bea87d4a] SuiteSparse_jll v7.8.3+2
[83775a58] Zlib_jll v1.3.1+2
[8e850b90] libblastrampoline_jll v5.15.0+0
[8e850ede] nghttp2_jll v1.64.0+1
[3f19e933] p7zip_jll v17.5.0+2- Output of
versioninfo()
Julia Version 1.12.1
Commit ba1e628ee4 (2025-10-17 13:02 UTC)
Build Info:
Note: This is an unofficial build, please report bugs to the project
responsible for this build and not to the Julia project unless you can
reproduce the issue using official builds available at https://julialang.org
Platform Info:
OS: Linux (x86_64-pc-linux-gnu)
CPU: 12 × Intel(R) Xeon(R) E-2176M CPU @ 2.70GHz
WORD_SIZE: 64
LLVM: libLLVM-18.1.7 (ORCJIT, skylake)
GC: Built with stock GC
Threads: 1 default, 1 interactive, 1 GC (on 12 virtual cores)Metadata
Metadata
Assignees
Labels
bugSomething isn't working
Activity
lxvm commentedon Dec 2, 2026
Hi, I just looked into this and have an explanation, but not a fix. First, it helps to understand what$\log(x)/\sqrt{x}$ . $x=0$ ,
hcubatureis doing when integratinghcubatureis intended to integrate smooth functions, i.e. functions that have a well-behaved, however since your function has a singularity athcubaturehas to adaptively refine towards that point. Now, the reason there is a difference between the original solver and Integrals.jl wrapper is because Integrals.jl performs a change of variables that maps the integration interval from [0, 1] to [-1, 1]. This changes the result because there are more floating point numbers closer to 0 than -1. Here is a demonstration of this factBecause the spacing between adjacent floats at 0.0 is hundreds of orders of magnitude smaller than at -1.0,
hcubatureis able to adaptively refine much closer towards 0 than -1 before roundoff errors for the quadrature points cause the integrand to be evaluated at one of the endpoints. This meanshcubaturereaches its default requested accuracy (reltol=1e-8) before roundoffs happen. If you throw this integral at hcubature on a shifted interval, it will also fail like Integrals does. For example:The fact that the details of floating point arithmetic change your answer here means that this is an ill-conditioned problem created by the$\log(x)/\sqrt{x}$ singularity at $x=0$ . You really should be specifying the error tolerance for this problem.
To figure out a reasonable error tolerance, you can try the
QuadGKJLalgorithm because QuadGK.jl checks for endpoint roundoff error and will exit the calculation as soon as it does (implemented here). Otherwise, the algorithm forQuadGKJLis nearly identical to that ofCubatureJLh. If I try this with the default tolerancesthe residual/absolute error is about
5e-8, which is a relative error of about1.3e-8and exceeds the default tolerance of1e-8by just a tiny amount. Now, I can setreltol=2e-8(larger than1.3e-8) and solve withCubatureJLhwhich is slightly less accurate than the original
hcubaturecall but identical toQuadGKJL.To answer your question about making CubatureJLh handle singularities like the underlying solver, the answer is that the underlying solver doesn't handle singularities well in the first place. You just got lucky that your singularity was at the origin so that roundoff errors are much smaller and that the (default) requested error tolerance was large enough to converge before roundoff error became a problem. Arguably, there should be no default error tolerances, and the user should specify the accuracy they want, especially in the case of singularities. There are many strategies for handling singular integrals and the QuadGK manual offers a few practical ones.