# How to do multi-dimension integration with BigFloat?

**URL:** https://discourse.julialang.org/t/how-to-do-multi-dimension-integration-with-bigfloat/113485
**Category:** New to Julia
**Created:** [April 25, 2024, 7:39am UTC](https://discourse.julialang.org/t/how-to-do-multi-dimension-integration-with-bigfloat/113485 "2024-04-25T07:39:04Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![baizhan](https://avatars.discourse-cdn.com/v4/letter/b/ecae2f/32.png) [@baizhan](https://discourse.julialang.org/u/baizhan)
#### Post date: [April 25, 2024, 7:39am UTC](https://discourse.julialang.org/t/how-to-do-multi-dimension-integration-with-bigfloat/113485/1 "2024-04-25T07:39:04Z")

</div>

Hello, I want to calculate a multiple dimension integration,  
and I have to use high precision float.

I have tried `HCubature`, which is a pure-julia implementation of integration.  
But when I use `BigFloat` as input, it will report an error:

`ERROR: LoadError: setindex!() with non-isbitstype eltype is not supported by StaticArrays. Consider using SizedArray.`

What does that mean?  
Is there any other packages that I can use?

---

<div class="post-metadata">

### Author: ![kimikage](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kimikage/32/14534_2.png) [@kimikage](https://discourse.julialang.org/u/kimikage)
#### Post date: [April 27, 2024, 3:37pm UTC](https://discourse.julialang.org/t/how-to-do-multi-dimension-integration-with-bigfloat/113485/2 "2024-04-27T15:37:54Z")

</div>

It is recommended that you show a script that reproduces the problem.  
It appears to work with `BigFloat` for simple cases.

```julia
julia> using HCubature

julia> f(x, y) = x^2 + 5y^2
f (generic function with 1 method)

julia> f(v) = f(v...)
f (generic function with 2 methods)

julia> a0, b0 = big"0.0", big"1.0"
(0.0, 1.0)

julia> a1, b1 = big"0.0", big"2.0"
(0.0, 2.0)

julia> hcubature(f, (a0, a1), (b0, b1))
(14.0, 0.0)

```

Also, do you need arbitrary precision?  
If you just need more precision than `Float64`, `Float128` from Quadmath.jl might be useful.

---

<div class="post-metadata">

### Author: ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)
#### Post date: [April 27, 2024, 3:59pm UTC](https://discourse.julialang.org/t/how-to-do-multi-dimension-integration-with-bigfloat/113485/3 "2024-04-27T15:59:29Z")

</div>

> [@kimikage](#):
>
> It appears to work with `BigFloat` for simple cases.

Although HCubature.jl does indeed support arbitrary precision (its [multidimensional quadrature rule](https://github.com/JuliaMath/HCubature.jl/blob/6ef76ab829007b7b2895a55af9d280fbfdf10ba3/src/genz-malik.jl#L75-L104) is carefully written to use the precision of the endpoints), it corresponds to a low-order quadrature rule that will be very slow (require a lot of subdivisions) to reach high accuracies.

If you are using `BigFloat` or similar types to obtain high accuracy (\gg 16 digits), then you really want to use a high-order quadrature rule (computed in `BigFloat` precision too). The QuadGK.jl package supports this, as discussed in [this tutorial example](https://juliamath.github.io/QuadGK.jl/stable/quadgk-examples/#Arbitrary-precision-integrals) and [this post](https://discourse.julialang.org/t/insanely-higher-order-derivatives/104455/17), for example. You can use nested `quadgk` calls to do multidimensional integration, and there is a package [IteratedIntegration.jl](https://github.com/lxvm/IteratedIntegration.jl) wrapping QuadGK that does this more efficiently.

However, if you want high accuracy arbitrary precision integration, you should also have an integrand that is very smooth (or for which any singularities are [built into the quadrature rule](https://juliamath.github.io/QuadGK.jl/stable/weighted-gauss/)). In that case, you might not want an adaptive routine at all, but simply use a tensor product of 1d quadrature rules (computed with QuadGK to arbitrary precision), e.g. see the example in [this post](https://discourse.julialang.org/t/gauss-quadrature-in-3d-with-change-of-variables/113486/2).
