HP Forums

Full Version: CAS Equations Internal Representation For Python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I wanted full symbolic equations to be transported from stack to python code so that it can calculate & work with those; however, I found that symbolic expressions have to be modified before being used by python math() library

For instance this code retrieves CAS symbolic equations from a user list & display what it contains internally

Code:
EXPORT strpy()
BEGIN
PRINT;
strPY(a);
RETURN TERMINAL(1);
END;

#PYTHON strPY(a)
import sys
print(sys.argv[0])

Check CAS settings
Observations for python compatibility & manipulations:
~ CAS changes equations to some approximation? See screenshot
~ If you have alphabets in list [] CAS returns a list encapsulated in {}; if only numbers in list CAS returns []
~ { & } are to be replaced by [ & ] for python list conversions
~ remove extra space after ever ,
~ math operator like LN, SIN, ATAN... are to be made lower case
~ raised to power ^ to be replaced with **
~ there is no LN() in python math() replace it with log()
~ HP's alog10, log10 are converted to e^ & LN notations. Weird, though python has log10
~ sqrt sign √ will certainly be a challenge for python to understand, don't use it
~ Last example very important the minus sign. Hp provides a separate - sign for prefixing negative numerals perhaps it will not play well with python in the result?
Reference URL's