Post Reply 
Negate an equation:
02-09-2017, 08:47 PM (This post was last modified: 02-09-2017 08:53 PM by Han.)
Post: #8
RE: Negate an equation:
Be careful when evaluating a symbolic object (represented as a string) within a program whether it be through CAS() or EXPR().


export localwarning()
local x:=1;
L0:={ "x^2+y^2=r^2" };

There is no bug, but you should check whether the answer is what you wanted. If not, you'll need to create your own myEXP() and myCAS() functions when dealing with indirection and undefined variables. The expressions stored as strings in L0 will be evaluated, and therefore inherit whatever values are present as local variables inside the calling function. Since x was used here in our calling program (set to 1), then any expression parsed via EXPR() and CAS() will be evaluate x to 1 -- including the instance where the string is parsed into a symbolic expression. The short solution is to not use x or y or c in your calling program. However, a generalized approach would stead call CAS() or EXPR() without ANY local variables defined, except for possibly the variable used to pass the string (which you hope and cross your fingers does not exist inside the string itself).


begin myCAS(casString)
  return(CAS(EVAL(casString)); // cross your fingers that casString is itself not a sequence of characters in the variable casString

No local variables (other than 'casString') are used in the myCAS() calling program so your chances of having your string/expression modified by pre-existing local variables is next to none. The EVAL() is needed because CAS commands treat their arguments as being literal.

Graph 3D | QPI | SolveSys
Find all posts by this user
Quote this message in a reply
Post Reply 

Messages In This Thread
Negate an equation: - DrD - 02-08-2017, 05:40 PM
RE: Negate an equation: - compsystems - 02-08-2017, 05:48 PM
RE: Negate an equation: - DrD - 02-09-2017, 12:00 PM
RE: Negate an equation: - Didier Lachieze - 02-09-2017, 12:16 PM
RE: Negate an equation: - DrD - 02-09-2017, 05:06 PM
RE: Negate an equation: - Didier Lachieze - 02-09-2017, 07:55 PM
RE: Negate an equation: - DrD - 02-09-2017, 08:10 PM
RE: Negate an equation: - Han - 02-09-2017 08:47 PM

User(s) browsing this thread: 1 Guest(s)