Check if two functions are equal - CAS not reliable in HTML/Javascript?

s_o shared this question 6 years ago
Needs Answer

Hey,

I would like to check if function the user enters is equal to one that already exists. For example there is a function f(x)=x^2+4x+7 and the user enters "(x+2)^2+3", this will be defined as ans(x) and then I would like to see if these functions are the same, this is what I do:


  1. ggbApplet.evalCommand("ans(x)="+input_txt);
  2. cas_answer = ggbApplet.evalCommandCAS("simplify(f(x)-ans(x))");
  3. if(cas_answer=="0") correct();
  4. else not_correct();

While this works great in desktop/Java application, in the HTML/JavaScript the answer of the CAS sometimes is "?", also when it works it's really slow and sometimes the browser hangs. Am I using the CAS wrong? Is there another way (without CAS) to check if the functions are equal?

Best regards,

Stefan

Best Answer
photo

you can compare two functions f and g by the command f==g. The result is a Boolean value with values true or false. You can use this result in your javasript (or in GeoGebrascript). See a and b in the file added.


chris

Comments (2)

photo
2

you can compare two functions f and g by the command f==g. The result is a Boolean value with values true or false. You can use this result in your javasript (or in GeoGebrascript). See a and b in the file added.


chris

photo
2

Hey Chris,

thanks for your help! That works great! I was sure it wouldn't work if the functions have different notation and did not even try it at first, but it even works if one uses decimal fractions and the other normal ones!

Best regards

Stefan

© 2022 International GeoGebra Institute