Mathematica Asked by apkg on February 5, 2021
I have
Integrate[
Boole[Abs[xa] < 1] Boole[Abs[xa - xb] < 1] Boole[
Abs[-L + xb] < 1] Boole[Abs[xa - xc] < 1] Boole[
Abs[-L + xc] < 1], {xa, L - 2, 1}, {xb, L - 1, 2}, {xc, L - 1, 2},
Assumptions -> {2 < L < 3}] // AbsoluteTiming
and get
{0.554812, -(1/3) (-3 + L)^3}
I am in fact doing this many thousands of times, by generating these Boolean expressions from the adjacency matrices of some random graphs. Thus, it needs to be as fast as possible.
Is there a reason it takes 1/2 a second to complete?
If I run without the assumptions, it is much faster.
L = 2.5; AbsoluteTiming[
Integrate[
Boole[Abs[xa] < 1] Boole[Abs[xa - xb] < 1] Boole[
Abs[-L + xb] < 1] Boole[Abs[xa - xc] < 1] Boole[
Abs[-L + xc] < 1], {xa, L - 2, 1}, {xb, L - 1, 2}, {xc, L - 1,
2}]]
{0.031514, 0.0416667}
Perhaps there is a way to convert the Boole’s into a set of intervals, over which one then repeatedly integrates unity.
If you you only need a numerical result for given L
try
int[L_?NumericQ] :=NIntegrate[
Boole[Abs[xa] < 1] Boole[Abs[xa - xb] < 1] Boole[
Abs[-L + xb] < 1] Boole[Abs[xa - xc] < 1] Boole[
Abs[-L + xc] < 1], {xa, L - 2, 1}, {xb, L - 1, 2}, {xc, L - 1,2} ]
int[2.5] // AbsoluteTiming
(*{0.0222419, 0.0416667}*)
Answered by Ulrich Neumann on February 5, 2021
reg = ImplicitRegion[{Abs[xa] < 1, Abs[xa - xb] < 1, Abs[-L + xb] < 1,
Abs[xa - xc] < 1, Abs[-L + xc] < 1, L - 2 <= xa <= 1,
L - 1 <= xb <= 2, L - 1 <= xc <= 2}, {xa, xb, xc}];
Assuming[2 < L < 3, Integrate[1, Element[{xa, xb, xc}, reg]]] //
Simplify // AbsoluteTiming
(*{0.142462, -(1/3) (-3 + L)^3}*)
Answered by cvgmt on February 5, 2021
J = ImplicitRegion[
Abs[xa] < 1 && Abs[xa - xb] < 1 && Abs[-L + xb] < 1 &&
Abs[xa - xc] < 1 && Abs[-L + xc] < 1 &&
L - 2 <= xa <= 1 && L - 1 <= xb <= 2 && L - 1 <= xc <= 2, {xa, xb, xc}];
Assuming[2 < L < 3, RegionMeasure[J]]
(* 1/3 (27 - 27 L + 9 L^2 - L^3) *)
is very quick.
Answered by Roman on February 5, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP