3
$\begingroup$

Consider the following function:

test[x_, u_, v_] = 
 Piecewise[{{CosIntegral[ (-3 + u + v) x], u + v > 3}, 
            {CosIntegral[ (-3 + u + v) x], u + v < 3}, 
            {5, u + v == 3}}];

If I run:

 Assuming[u + v == 3, Simplify[test[x, u, v]]]

Then I get the error "Simplify Expression CosIntegral[(-3+u+v)x] simplified to -Infinity". However, it should not be evaluating either of the first cases. This can be checked by running:

 Simplify[u + v > 3 || u + v < 3, u + v == 3] 

which evaluates to false (as it should). Hence, Mathematica shouldn't be evaluating the first two cases in the piecewise function, as it "knows" this isn't true (when you ask it to simplify the condition). However, despite Mathematica knowing this, it seems to not be using it, as running:

  Assuming[u + v == 3, Refine[test[x, u, v]]]

returns CosIntegral[(-3+u+x)x] for u+v>3 || u+v<3 and 5 for True. So u+v>3 || u+v<3 is not getting evaluated to false here.

In this case, ignoring the error message is not too difficult. However, in my actual function, there are multiple CosIntegrals in the spurious cases, and this causes Mathematica to hang as it tries to evaluate them. However, there is no need to do that, since they only go to Infinities when u+v==3 which is a separate case.

How can I tell Mathematica to simplify the first conditions to false and so not evaluate the function value?

Thanks for the help.

Update: The second proposal (in the first answer) below fails on:

test[x_, u_, v_] = 
 Piecewise[{{CosIntegral[ (-3 + u + v) x]+1, u + v > 3}, 
            {CosIntegral[ (-3 + u + v) x]-1, u + v < 3}, 
            {5, u + v == 3}}];

and so, while helpful, isn't a general solution. (The first one, to ignore the error message, while helpful doesn't actually prevent Mathematica from evaluating the irrelevant cases.)

$\endgroup$

1 Answer 1

1
$\begingroup$

Starting with a fresh kernel

$Version

(* "13.2.0 for Mac OS X x86 (64-bit) (November 18, 2022)" *)

Clear["Global`*"]

test[x_, u_, v_] = Piecewise[{
   {CosIntegral[(-3 + u + v) x], u + v > 3},
   {CosIntegral[(-3 + u + v) x], u + v < 3},
   {5, u + v == 3}}]

enter image description here

Whether defined with Set or SetDelayed, I only see the error/warning message for the first evaluation, subsequent evaluations do not produce a message.

Assuming[u + v == 3, Simplify[test[x, u, v]]]

(* Simplify::infd: Expression CosIntegral[(-3+u+v) x] simplified to -∞. 

5 *)

Assuming[u + v == 3, Simplify[test[x, u, v]]]

(* 5 *)

A slight change in the definition (including Simplify) does not produce the message

test2[x_, u_, v_] = Piecewise[{
    {CosIntegral[(-3 + u + v) x], u + v > 3},
    {CosIntegral[(-3 + u + v) x], u + v < 3},
    {5, u + v == 3}}] // Simplify

enter image description here

Assuming[u + v == 3, Simplify[test2[x, u, v]]]

(* 5 *)
$\endgroup$
1
  • $\begingroup$ I still get the error on the first try, which is a problem as in my actual (longer) function with multiple CosIntegrals Mathematica actually hangs and never evaluates. With the second one, the reason I have u + v > 3 and u + v < 3 broken out separately is because the other terms are different, and so this approach doesn't work so far as I can tell. (E.g., put CosIntegral[(-3+u+v)x] + 1 for u+v > 3 and CosIntegral[(-3+u+v)x] -1 for u+v < 3.) $\endgroup$ Jan 19, 2023 at 18:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.