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 writeAlgebraic: 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 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!