0

I want to check if two expressions are equal to each other.

For example 3a+5b === 5b+3a should return 'true'.

I'm trying to use a function:

CloudDeploy[
    APIFunction[
        {
            "x" ->Restricted["SemanticExpression", All, Automatic,"equalityTestingContext`"], 
            "y" ->Restricted["SemanticExpression", All, Automatic,"equalityTestingContext`"]
        },
        TrueQ[Simplify[#x == #y]] &
        ],
    Permissions -> "Public"
]

This is returning true for given example but fails for checking for example 5aewq+3(b^3) === 3(b^3)+5aqwe, returning 'No result — at least one parameter could not be interpreted'.

What should be changed in above code to allow comparison of more complex expressions? Maybe 'Restricted' interpreter?

  • Interesting, so my test cases are bad, right? Every string with length > 3 will be treated as a variable name? – Paweł Jabłoński Sep 04 '15 at 14:02
  • It's how my code behaves. When I insert the '*' between letters, everything is fine. I'll try to do this outside wolfram before sending the requests. Thank you for help! – Paweł Jabłoński Sep 04 '15 at 14:13

1 Answers1

1

It seems that the interpreter construes 5a as 5*a but aqwe as a 4-letter variable name and not the same as aewq.

I guess that it (the interpreter) follows the practice, common to many programming languages, of regarding an alphanumeric string beginning with a letter as the name of an entity of some sort but parses a string beginning with a digit as a multiplication with the sign omitted.

So 5a is interpreted as 5*a, and 123.45a is interpreted as 123.45*a, but strings such as a, ab, abc, a1, a2c are all interpreted as entity names. All of this, in particular the interpretation of 2a as 2*a is consistent with the way that Mathematica / The Wolfram Language interprets input.

High Performance Mark
  • 77,191
  • 7
  • 105
  • 161