1
$\begingroup$

FreeQ and MemberQ keep telling me that the expression is incomplete when I want to check if \[PlusMinus] is present in an expression. Any ideas for a work around? Thanks

$\endgroup$
  • 2
    $\begingroup$ Post an example $\endgroup$ – Marius Ladegård Meyer Oct 19 '17 at 11:10
  • $\begingroup$ Could you give an example expression with [PlusMinus]. $\endgroup$ – Sumit Oct 19 '17 at 11:10
  • $\begingroup$ FreeQ[expression, _PlusMinus] or FreeQ[expression, a_ ± b_]? $\endgroup$ – kglr Oct 19 '17 at 11:19
  • $\begingroup$ Yes kglr, that's it. I was missing underscore before term. Many thanks. $\endgroup$ – Rupert Gillyweed Oct 19 '17 at 11:24
1
$\begingroup$
expressions = {±2, ±2 + xyz,  x y z, x PlusMinus[a, b], 3 ± 5}

{±2, xyz + ±2, x y z, x (a ± b), 3 ± 5}

FreeQ[#, PlusMinus] & /@ expressions

{False, False, True, False, False}

FreeQ[#, _PlusMinus] & /@ expressions

{False, False, True, False, False}

FreeQ[#, PlusMinus[__]] & /@ expressions

{False, False, True, False, False}

FreeQ[#, ___ ± ___] & /@ expressions

{False, False, True, False, False}

FreeQ[#, _ ± _] & /@ expressions

{True, True, True, False, False}

$\endgroup$
1
$\begingroup$

For any question like "Detecting ... in an expression", the first thing you should do is look at the FullForm of a simple example. In your case, something like:

FullForm[a ± b]

PlusMinus[a,b]

would show you that you need to look for the head PlusMinus, and not the character $\pm$.

$\endgroup$
0
$\begingroup$
FreeQ[\[PlusMinus]2, _PlusMinus]
$\endgroup$
  • $\begingroup$ What about clarifying the question? $\endgroup$ – Kuba Oct 19 '17 at 11:56

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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