HP Forums
CAS: math expresion -> logical evaluation - Printable Version

+- HP Forums (https://www.hpmuseum.org/forum)
+-- Forum: HP Calculators (and very old HP Computers) (/forum-3.html)
+--- Forum: HP Prime (/forum-5.html)
+--- Thread: CAS: math expresion -> logical evaluation (/thread-6738.html)



CAS: math expresion -> logical evaluation - compsystems - 08-27-2016 02:36 PM

How to evaluate an expression with the (=) operator, so that returns a Boolean value (true/false)?

Example

0 = 0 -> true
10*e^5-10*e^10 = 0 -> false

I think it takes a function of the type.
evaLogic (MathExpre) -> true/false

evaLogic ( (10 * e ^ 5) - (10 * e ^ 10) = 0 ) -> false


RE: CAS: math expresion -> logical evaluation - Didier Lachieze - 08-27-2016 03:04 PM

What about :
Code:
EXPORT EvalLogic(expression)
BEGIN
  LOCAL s;
  s:=REPLACE(STRING(expression),"=","==");
  CAS(s);
END;

EvalLogic('0=0') -> 1
EvalLogic('0=1') -> 0
EvalLogic('10*e^5-10*e^10=0') -> 0

And in CAS mode you can also evaluate expressions with undefined variables :

EvalLogic('2*x = x+x') -> 1

[Edited to support undefined variables]


RE: CAS: math expresion -> logical evaluation - parisse - 08-27-2016 06:29 PM

subst(x^2+x*y+y^2+x*y=x^2+2x*y+y^2,'=','==')


RE: CAS: math expresion -> logical evaluation - Didier Lachieze - 08-28-2016 06:55 AM

(08-27-2016 06:49 PM)compsystems Wrote:  The flags must be changed manually =(, but that's not the idea, the flags should be changed from the program code, it is to automate algorithms as does the hp 48 hp 50, TI89 ...

No need to change the flags if you explicitly simplify the expression :
Code:
#cas
evalLogicv3(expression)
BEGIN
  LOCAL bool_numeric;
  bool_numeric:= subst(simplify(expression),'=','==');
  if(bool_numeric==1) then
    return true;
  else
    return false;
  end;
END;
#end



RE: CAS: math expresion -> logical evaluation - Didier Lachieze - 08-31-2016 06:57 AM

(08-28-2016 06:44 PM)compsystems Wrote:  also must be added EXACT MODE

Do you have an exemple of an expression for which the latest version of evalLogicv3 is different depending on the status of the Exact flag ?