# Integration on an ordered domain

**URL:** <https://discourse.julialang.org/t/integration-on-an-ordered-domain/118180>\
**Category:** Numerics\
**Tags:** question, package, integral, integrate\
**Created:** [August 14, 2024, 1:03pm UTC](https://discourse.julialang.org/t/integration-on-an-ordered-domain/118180 "2024-08-14T13:03:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![IlliaFaraji](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/illiafaraji/32/211327_2.png) [@IlliaFaraji](https://discourse.julialang.org/u/IlliaFaraji)\
**Post date:** [August 14, 2024, 1:03pm UTC](https://discourse.julialang.org/t/integration-on-an-ordered-domain/118180/1 "2024-08-14T13:03:14Z")

</div>

I want to carry out an integral of this form

\int\_{0}^{\infty} \int\_{0}^{t\_{n}} \ldots \int\_{0}^{t\_2} \ f(s\_1, \ldots, s\_n)\, \mathrm{d}s\_1 \ldots \mathrm{d}s\_n ,

for n \approx 10. The domain of integration here is S=\{t\in \mathbb{R}^n: 0 \leq t\_1 \leq \ldots \leq t\_n\} . I don’t know if there is already a name for this region, so let’s call it an ordered domain on \mathbb{R}^n.

looking at [Integrals.jl](https://docs.sciml.ai/Integrals/stable/), one of the FAQs is “How can I integrate on arbitrary geometries?” to which the answer

> You can’t, since Integrals.jl currently supports integration on hypercubes because that is what lower-level packages implement.

So my question is, are there any packages or methods that allow me to (fairly) efficiently (and hopefully fairly easily) compute my integral?

Of course, I could define a function g(t) = f(t) on S and zero elsewhere, and then integrate g on \{t \in \mathbb{R}^n: t\_i \> 0\}, but this would be very inefficient as a lot of time would be lost sampling points where the function is zero. So I am looking for a better solution.

---

<div class="post-metadata">

**Author:** ![juliohm](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/juliohm/32/215266_2.png) [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Post date:** [August 14, 2024, 1:22pm UTC](https://discourse.julialang.org/t/integration-on-an-ordered-domain/118180/2 "2024-08-14T13:22:49Z")

</div>

MeshIntegrals.jl is a good start, specially if your domains are physical domains.

---

<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:** [August 14, 2024, 2:10pm UTC](https://discourse.julialang.org/t/integration-on-an-ordered-domain/118180/3 "2024-08-14T14:10:57Z")

</div>

> [@IlliaFaraji](#):
>
> So my question is, are there any packages or methods that allow me to (fairly) efficiently (and hopefully fairly easily) compute my integral?

The standard technique if the bounds depend on one another is to use a change of variables. This is the usual, easy way to use hypercube-integration packages with a differently shaped domain. For example, see: [How to Compute the integration of the following formula by HCubature](https://discourse.julialang.org/t/how-to-compute-the-integration-of-the-following-formula-by-hcubature/32269)

> [@IlliaFaraji](#):
>
> The domain of integration here is S=\{t\in \mathbb{R}^n: 0 \leq t\_1 \leq \ldots \leq t\_n\}

If I understand you correctly, this is:

\int\_0^\infty dt\_n \int\_0^{t\_n} dt\_{n-1} \int\_0^{t\_{n-1}} dt\_{n-2} \cdots \int\_0^{t\_2} dt\_1 \,f(t\_1, \ldots, t\_n) 

which can be transformed to a hypercube via the change of variables t\_k = s\_k t\_{k+1} = t\_n \prod\_{j=k}^{n-1} s\_j for s\_{k} \in [0,1]:

\int\_0^\infty dt\_n \int\_0^{1} ds\_{n-1} \int\_0^{1} ds\_{n-2} \cdots \int\_0^{1} ds\_1\, f\left(t\_n \prod\_{j=1}^{n-1} s\_j, t\_n \prod\_{j=2}^{n-1} s\_j, \ldots, t\_n\right) t\_n^{n-1} \prod\_{j=1}^{n-1} s\_j^{j-1} 

(Or add a finite upper bound on t\_n if desired. If you want a semi-infinite t\_n domain like this you may need an [additional change of variables](https://github.com/stevengj/cubature?tab=readme-ov-file#infinite-intervals).)

---

<div class="post-metadata">

**Author:** ![IlliaFaraji](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/illiafaraji/32/211327_2.png) [@IlliaFaraji](https://discourse.julialang.org/u/IlliaFaraji)\
**Post date:** [August 14, 2024, 2:55pm UTC](https://discourse.julialang.org/t/integration-on-an-ordered-domain/118180/4 "2024-08-14T14:55:00Z")

</div>

Thanks for your answer. And yes, my limits on the integral were wrong.
