I need to check if the expression is a correct equation with only 1 variable x and without functions, that are not build into Mathematica. For example


is correct equation. And expressions

Sin[x*a]==0, Sin[[x]==0, f[x]==0, Exp[x]=9 

are not correct equations.

  • 1
    $\begingroup$ Are you testing these as strings or as expressions? Because one of them sticks out immediately being syntactically incorrect, so Mathematica won't have a problem checking whether it is a well-formed equation or not. $\endgroup$ Dec 1, 2013 at 19:26
  • $\begingroup$ I'm testing these as strings. When expression is incorrect I will get message. The best variant for me is to get messages in other cases. $\endgroup$
    – user10893
    Dec 1, 2013 at 19:37

1 Answer 1


How about this?

admissibleEqPat = 
  eq_Equal /; 
     Context /@ 
       Cases[eq, _Symbol, Infinity, 
        Heads -> True], x]] === {"System`"};

MatchQ[x^2 + 3 x == 4 x^2/(x + 2), admissibleEqPat]
(* True *)

MatchQ[Sin[x] == 0, admissibleEqPat]
(* True *)

MatchQ[Sin[a x] == 0, admissibleEqPat]
(* False *)

MatchQ[f[x] == 0, admissibleEqPat]
(* False *)

I'm assuming that by built-in functions, you mean the standard built-in ones that are in the System` context.

  • $\begingroup$ The problem is I need to add all functions, which are possible in my equations to admissibleSymbols. for example MatchQ[Sin[x] == 0, admissibleEqPat] (* False *) $\endgroup$
    – user10893
    Dec 1, 2013 at 19:53
  • $\begingroup$ @user10893 Check the update. $\endgroup$
    – Michael E2
    Dec 1, 2013 at 20:02

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.