The Museum of HP Calculators

HP Forum Archive 20

 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))) ``` or```RPL+: 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 recipe-style step-by-step 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[i-n/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 array-access operator (=x is equivalent to 'x' STO) You could write this line also entirely in algebraic notation: ```x=total(squared(divs(arr[i-n/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.

 Re: Immediate algebraic expressions in RPL+Message #2 Posted by David Hayden on 18 Nov 2011, 8:34 p.m.,in response to message #1 by Oliver Unter Ecker Hi Oliver, I'd say do it. To me, RPN is good for keying in the solution to problems, but when it comes to *reading* expressions, I'd much rather see algebraic since that's how they always appear in books. To me, the ability to read a program is just as important as the ability to have the program produce the correct answer. After all, if you can't understand the code, then bugs are highly likely. So I think algebraic expressions in the programming language are a good thing. Dave

 Re: Immediate algebraic expressions in RPL+Message #3 Posted by Oliver Unter Ecker on 19 Nov 2011, 4:12 a.m.,in response to message #2 by David Hayden David, thanks for the encouragement!

 Re: Immediate algebraic expressions in RPL+Message #6 Posted by Crawl on 19 Nov 2011, 12:10 a.m.,in response to message #1 by Oliver Unter Ecker Quote: You may write ```expr ``` instead of ```'expr' EVAL ``` The only thing I would suggest is that if you take this route, you may want to have an "unEVAL" command, so, for example, if you had UNEVAL expr it would work just like expr alone does now. The reason is that sometimes you do NOT want an expression to be evaluated (eg., evaluating it might be time consuming); you just want to push it onto the stack. It would be good to retain that ability (in contrast, the TI89 does not have that ability; it tries to evaluate every entered expression) But switching the default to automatically evaluate expressions seems fine to me.
 Re: Immediate algebraic expressions in RPL+Message #9 Posted by Oliver Unter Ecker on 19 Nov 2011, 4:29 a.m.,in response to message #6 by Crawl I don't really know the TI-89, but I suspect this would allow the calc to be used very similarly. (Again, except for CONTROL structures, which could be addressed, too.) With one interesting side-effect: Consider```a=4; 3+4; b=3+a; ``` in C-like languages. The middle statement is valid. It's just "dead", inconsequential code. In this merged world, "unconsumed" expression results, such as this one, are pushed onto a FIFO stack. And they're pulled from it when you specify a function or operator without arguments. So, these are the two mods you need to transform an algebraic environment into a RPL environment. Not that weird sounding, perhaps.