Skip to main content
added 308 characters in body
Source Link
Goofy
  • 3.7k
  • 11
  • 17

Doing the math....

With[{x = Pi/50},
  With[{uvint = (* substitute y == u+v, z == u-v *)
     Hold[2 Sin[y]  Sin[z]  test[x, y, z], {y, 0, Pi/2}, {z, 0, 
           Pi/2}] /. {v_, a_, b_} :> a < v < b /. {y -> u + v, 
         z -> u - v} // Apply@List // 
      ReplaceAll[HeavisideTheta -> UnitStep] //
             Echo[#, HoldForm[uvint]] &},
   With[{interval = (* Reduce figures out the new domains *)
      Reduce[Rest[uvint], {u, v}] /. 
        Or | And -> 
         List /. {Verbatim[Inequality][a_?NumericQ, _, v_, _, 
          b_?NumericQ] :> 
         Flatten@{v, 
           NumericalSort@
            Select[{a, b, x/2, Pi/2 - x/2}, a <= # <= b &]},
        Verbatim[Inequality][a_, _, v_, _, b_] :> {v, a, b}
        } //
             Echo[#, HoldForm[interval]] &
     },
    NIntegrate[First[uvint], ##, 
        Exclusions -> { (* help with the singularities *)
          (*2u==Pi/16,2u==Pi-Pi/16,*)2 
 v == x, 
       2 v == x, 2 v == -x}, 
        MaxRecursion -> 20, MinRecursion -> 1, 
        AccuracyGoal -> 20, WorkingPrecision -> 20] & @@@ interval // 
     Total
    ]]] // AbsoluteTiming

This takes around 7-8 seconds or little more. So stillenter image description here

Still not fast, but convergent and no warnings or errors.

Doing the math....

With[{x = Pi/50},
  With[{uvint = 
     Hold[2 Sin[y]  Sin[z]  test[x, y, z], {y, 0, Pi/2}, {z, 0, 
           Pi/2}] /. {v_, a_, b_} :> a < v < b /. {y -> u + v, 
         z -> u - v} // Apply@List // 
      ReplaceAll[HeavisideTheta -> UnitStep]},
   With[{interval = 
      Reduce[Rest[uvint], {u, v}] /. 
        Or | And -> 
         List /. {Verbatim[Inequality][a_?NumericQ, _, v_, _, 
          b_?NumericQ] :> 
         Flatten@{v, 
           NumericalSort@
            Select[{a, b, x/2, Pi/2 - x/2}, a <= # <= b &]},
        Verbatim[Inequality][a_, _, v_, _, b_] :> {v, a, b}
        }
     },
    NIntegrate[First[uvint], ##, 
        Exclusions -> {(*2u==Pi/16,2u==Pi-Pi/16,*)2 v == x, 
           2 v == -x}, MaxRecursion -> 20, MinRecursion -> 1, 
        AccuracyGoal -> 20, WorkingPrecision -> 20] & @@@ interval // 
     Total
    ]]] // AbsoluteTiming

This takes around 7-8 seconds or little more. So still not fast, but convergent.

Doing the math....

With[{x = Pi/50},
  With[{uvint = (* substitute y == u+v, z == u-v *)
     Hold[2 Sin[y]  Sin[z]  test[x, y, z], {y, 0, Pi/2}, {z, 0, 
           Pi/2}] /. {v_, a_, b_} :> a < v < b /. {y -> u + v, 
         z -> u - v} // Apply@List // 
      ReplaceAll[HeavisideTheta -> UnitStep] //
             Echo[#, HoldForm[uvint]] &},
   With[{interval = (* Reduce figures out the new domains *)
      Reduce[Rest[uvint], {u, v}] /. 
        Or | And -> 
         List /. {Verbatim[Inequality][a_?NumericQ, _, v_, _, 
          b_?NumericQ] :> 
         Flatten@{v, 
           NumericalSort@
            Select[{a, b, x/2, Pi/2 - x/2}, a <= # <= b &]},
        Verbatim[Inequality][a_, _, v_, _, b_] :> {v, a, b}
        } //
             Echo[#, HoldForm[interval]] &
     },
    NIntegrate[First[uvint], ##, 
        Exclusions -> { (* help with the singularities *)
          (*2u==Pi/16,2u==Pi-Pi/16,*) 
          2 v == x, 2 v == -x}, 
        MaxRecursion -> 20, MinRecursion -> 1, 
        AccuracyGoal -> 20, WorkingPrecision -> 20] & @@@ interval // 
     Total
    ]]] // AbsoluteTiming

enter image description here

Still not fast, but convergent and no warnings or errors.

Source Link
Goofy
  • 3.7k
  • 11
  • 17

Doing the math....

With[{x = Pi/50},
  With[{uvint = 
     Hold[2 Sin[y]  Sin[z]  test[x, y, z], {y, 0, Pi/2}, {z, 0, 
           Pi/2}] /. {v_, a_, b_} :> a < v < b /. {y -> u + v, 
         z -> u - v} // Apply@List // 
      ReplaceAll[HeavisideTheta -> UnitStep]},
   With[{interval = 
      Reduce[Rest[uvint], {u, v}] /. 
        Or | And -> 
         List /. {Verbatim[Inequality][a_?NumericQ, _, v_, _, 
          b_?NumericQ] :> 
         Flatten@{v, 
           NumericalSort@
            Select[{a, b, x/2, Pi/2 - x/2}, a <= # <= b &]},
        Verbatim[Inequality][a_, _, v_, _, b_] :> {v, a, b}
        }
     },
    NIntegrate[First[uvint], ##, 
        Exclusions -> {(*2u==Pi/16,2u==Pi-Pi/16,*)2 v == x, 
          2 v == -x}, MaxRecursion -> 20, MinRecursion -> 1, 
        AccuracyGoal -> 20, WorkingPrecision -> 20] & @@@ interval // 
     Total
    ]]] // AbsoluteTiming

This takes around 7-8 seconds or little more. So still not fast, but convergent.