Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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.

share|improve this question
1  
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 1

up vote 2 down vote accepted

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.

share|improve this answer
    
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

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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