Immediate algebraic expressions in RPL+ Message #1 Posted by Oliver Unter Ecker on 18 Nov 2011, 7:49 p.m.
In RPN/RPL, you work from the "inside out" or from the "bottom up". In algebraic notation, you take a "top down" approach.
Whether you write Algebraic: total(squared(divs(x)))
orRPL+: x divs squared total (RPL: x DIVIS SQ SIGMALIST)
comes arguably down to preference.
Algebraic has in its favor, that it matches natural language: English: "Sum of squares of the divisors of a number."
RPN has in its favor, that it matches recipestyle stepbystep processing: English: "Compute divisors for x. Square them. Sum them up."
Let's suggest, that no one is better or worse than the other.
When it comes to algebraic expressions involving operators, RPL doesn't look so good, though, I'd say.
Can you comprehend
1 3 a * 4 b * + 5 c * +
or
1 3 a * 4 b * 5 c * + +
at a glance?
How about the algebraic equivalent of
3*a+4*b+5*c
?
The situation becomes worse when expressions are consumed by a function or construct that takes multiple arguments.
Consider
1 b 4 + x  FOR i ...
You can't glance where start and end value computations begin and end, without backtracking.
Consider these variations of using a comparison operator:
IF x SQ y == THEN
x SQ y == IF THEN
x SQ y IF == THEN
x SQ IF y == THEN
It's not hard to argue that, in these cases, the RP notation comes at the expense of readability.
Now. RPL calcs support algebraic expressions via a data type.
You could write
IF 'SQ(x)==y' EVAL THEN ...
to increase readability.
What if you could type
IF SQ(x)==y THEN ...
?
I'm working on supporting "immediate algebraic expressions" in RPL+, which permit just that.
You may write
expr
instead of
'expr' EVAL
This pulls all of algebraic notation into RPL, and (gasp!) merges them.
An example:
1: 1 size(arr)n FOR i
2: arr[in/2] divs squared total =x
3: IF SQ(x)==y THEN BREAK END
4: NEXT
This is not a particularly instructive example, but here're some notes:
Line 1: The algebraic expression size(arr)n segments what comes before FOR into two blocks, and makes the calculation more readable
Line 2: pure RPL+ with an algebraic in the arrayaccess operator (=x is equivalent to 'x' STO)
You could write this line also entirely in algebraic notation:
x=total(squared(divs(arr[in/2])))
Line 3: Algebraic makes the comparison more readable
As with every other RPL+ feature, you may use it, or not.
Am I instigating a forbidden love here, that should better remain unconsummated? Your opinions are welcome.
