6
$\begingroup$

I am trying to check if a function remains unevaluated.

For example

$$\int \ln ^5(3 x) \sec (3 x) \, dx$$

remains unevaluated in Mathematica, instead $$\int \sec (3 x) \, dx$$ doesn't.

What I tried is

func = Log[3 x]^5*Sec[3 x];
IntFunc = With[{function = func}, HoldForm[Integrate[function, x]]];
SameQ[IntFunc,ReleaseHold[IntFunc]]

which returns False. I also tried

Equal[IntFunc,ReleaseHold[IntFunc]]

which remains unevaluated. I am pretty sure that this has to do with Hold $(*)$ but I don't understand how to fix this. Is there a way to test if a function remains unevaluatd? In other words, get True if it's unevaluated and False if it's evaluated?


$(*)$ Because when I try:

SameQ[Integrate[func, x], ReleaseHold[IntFunc]]

it returns True.

$\endgroup$
3
  • $\begingroup$ ValueQ should do the trick. $\endgroup$
    – JEM_Mosig
    Feb 15, 2018 at 5:49
  • $\begingroup$ @JEM_Mosig how? $\endgroup$
    – DMH16
    Feb 15, 2018 at 6:03
  • 2
    $\begingroup$ From the documentation: ValueQ[expr] gives True if a value has been defined for expr, and gives False otherwise. ValueQ gives False only if expr would not change if it were to be entered as Wolfram Language input. $\endgroup$
    – JEM_Mosig
    Feb 15, 2018 at 8:21

2 Answers 2

10
$\begingroup$

check if a function remains unevaluated.

Why not just check the head?

func = Log[3 x]^5*Sec[3 x];
result = Integrate[func, x]

Mathematica graphics

If[Head[result] === Integrate,
 Print["Opps"],
 Print["it worked"]
 ]

Update for comment

Use this to check if result contains Integrate anywhere

func = 20* Log[3 x]^5*Sec[3 x];
result = Integrate[func, x]

Mathematica graphics

If[FreeQ[result, Integrate, Infinity],
 Print["it worked"],
 Print["Opps"]
 ]
$\endgroup$
3
  • $\begingroup$ Wow, I did not think of this! Thanks! ' $\endgroup$
    – DMH16
    Feb 15, 2018 at 4:15
  • $\begingroup$ Hey, I just noticed that this does not work if a constant is added in front of the function (ex: func = 20*Log[3 x]^5*Sec[3 x];). This because the head now is Times. How would you fix this? $\endgroup$
    – DMH16
    Feb 15, 2018 at 6:03
  • $\begingroup$ @DMH16 I added check $\endgroup$
    – Nasser
    Feb 15, 2018 at 6:38
2
$\begingroup$

ValueQ should do exactly what you want. From the documentation: ValueQ[expr] gives True if a value has been defined for expr, and gives False otherwise. ValueQ gives False only if expr would not change if it were to be entered as Wolfram Language input.

So

ValueQ[Integrate[Log[3 x]^5*Sec[3 x], x]]
(* False *)

and

ValueQ[Integrate[Sec[3 x], x]]
(* True *)
$\endgroup$

Your Answer

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

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