Post Reply 
Understanding How a Program Is Treating Parentheses
01-11-2018, 09:13 PM
Post: #1
Understanding How a Program Is Treating Parentheses
Hi there,

I'm trying to make a simple program to return an expression for the curvature of a single variable function in X. My intention would be to execute this in the home view and plot the result.

LOCAL DEX=CAS.diff(EX,'X'), DDEX=CAS.diff(EX,'X',2);
  RETURN (ABS(DDEX))/((1+(DEX)^(2))^(3/2));

For a lot of functions this works just fine, but if I try it on the exponential function, I get some unexpected behavior.

[Image: GkQIyUD.png]

When textbook display is enabled, the result seems exactly as expected, but once I copy it back to input, the (e^X)^2 term becomes e^(X)^2.

[Image: lPkcpSD.png]

If I disable textbook display, we see that the function is actually returning e^(X)^2, which, strictly speaking, represents e^(X^2) instead of the desired e^(2X). If I evaluate the copied expression, you can even see that the extra parentheses are inserted afterwards to reflect this parsing:

[Image: H3VzxVA.png]

I'm pretty sure the problem lies in the way my program is evaluating the return expression, but I'm unaware of how it should be written to ensure parentheses are always included before squaring the derivative.

Any insight would be much appreciated!

Find all posts by this user
Quote this message in a reply
Post Reply 

Messages In This Thread
Understanding How a Program Is Treating Parentheses - kvloxx - 01-11-2018 09:13 PM

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