Post Reply 
newRPL: Alpha demo 0.9 released [UPDATED 2017-10-25]
08-29-2017, 03:18 PM
Post: #72
RE: newRPL: Alpha demo 0.9 released [UPDATED 2017-08-24]
(08-29-2017 04:25 AM)The Shadow Wrote:  Something weird is going on with EVAL. And after a lot of experimentation after getting very strange answers, I think I've figured out what.

If I type in '2/3', then press EVAL, I get something that *looks* exactly like '2/3', but if I do OBJ-> on it, rather than:

2
3
2
/

I get:

2
INV(3)
2
*

I would have expected the latter to look like:

'2*INV(3)', not '2/3'. So my FXND algorithm is getting very confused.

It's not weird at all once you understand some basic concepts of expressions in newRPL:

  1. Expressions remain as entered by the user until operated upon.
  2. Operations in expressions produce new expressions always in canonical form (more on this below).


Canonical form enforces a few internal rules that make manipulating an expression a lot simpler:
  • Negative numbers don't exist. They are replaced with unary minus operator on a positive number.
  • Subtractions don't exist. They are replaced with additions of negative terms.
  • Divisions don't exist. They are replaced with multiplication of INVerted factors.
  • Addition trees are flattened: The + operator can take multiple arguments.
  • Multiplication trees are flattened: The * operator can take multiple arguments.

And a few other rules that I can't recall.
So when you type: '2+3+1'
you generate an object with a tree structure (+ (+ 2 3) 1) because for the parser + is a binary operator, but for the (future) CAS to operate properly, it flattens the tree to (+ 2 3 1), which makes it simpler to simplify terms, search for expressions, cancel out terms, etc.
Your fraction '2/3' is converted after EVAL to '2*INV(3)' per the rules above. What you get from OBJ-> is one level expansion of the main operator. Perhaps OBJ-> should convert to canonical form always before expanding, so you get consistent results every time.

Other than that, everything works as designed.
Find all posts by this user
Quote this message in a reply
Post Reply 


Messages In This Thread
RE: newRPL: Alpha demo 0.9 released [UPDATED 2017-08-24] - Claudio L. - 08-29-2017 03:18 PM



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