# check if the expression is a equation

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

Sin[x]==0


is correct equation. And expressions

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


are not correct equations.

-
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. –  István Zachar Dec 1 '13 at 19:26
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. –  user10893 Dec 1 '13 at 19:37

## 1 Answer

How about this?

admissibleEqPat =
eq_Equal /;
DeleteDuplicates[
Context /@
DeleteCases[
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.

-
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 *) –  user10893 Dec 1 '13 at 19:53
@user10893 Check the update. –  Michael E2 Dec 1 '13 at 20:02