X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=doc%2Frpntutorial.txt;h=97a5fc8d3955999f8bb570c5f7114bd797e23b02;hb=d9822df7ed5e8122cf3a62e4e99678e94007f504;hp=75f39cd5043aa32c0ebbd73e5675696912d680ad;hpb=2dbf17c3d0f7145817e7a27afa42e4f9ddc22e4c;p=pkg-rrdtool.git diff --git a/doc/rpntutorial.txt b/doc/rpntutorial.txt index 75f39cd..97a5fc8 100644 --- a/doc/rpntutorial.txt +++ b/doc/rpntutorial.txt @@ -19,8 +19,8 @@ RReeaaddiinngg CCoommppaarriissoonn OOppeerraattoorrss For example, think about "2,1,GT". This RPN expression could be read as "is two greater than one?" The answer to that question is "true". - So the three values should be replaced with "1". Thus the RPN expres- - sion 2,1,GT evaluates to 1. + So the three values should be replaced with "1". Thus the RPN + expression 2,1,GT evaluates to 1. Now consider "2,1,LE". This RPN expression could be read as "is two less than or equal to one?". The natural response is "no" and thus @@ -33,8 +33,8 @@ RReeaaddiinngg tthhee IIFF OOppeerraattoorr So the IF operator acts on only one value on the stack: the third value to the left of the IF value. The second value to the left of the IF corresponds to the true ("Y") branch. And the first value to the left - of the IF corresponds to the false ("Z") branch. Read the RPN expres- - sion "X,Y,Z,IF" from left to right like so: "if X then Y else Z". + of the IF corresponds to the false ("Z") branch. Read the RPN + expression "X,Y,Z,IF" from left to right like so: "if X then Y else Z". For example, consider "1,10,100,IF". It looks bizarre to me. But when I read "if 1 then 10 else 100" it's crystal clear: 1 is true so the @@ -49,12 +49,12 @@ RReeaaddiinngg tthhee IIFF OOppeerraattoorr operators. SSoommee EExxaammpplleess - While compound expressions can look overly complex, they can be consid- - ered elegantly simple. To quickly comprehend RPN expressions, you must - know the the algorithm for evaluating RPN expressions: iterate searches - from the left to the right looking for an operator. When it's found, - apply that operator by popping the operator and some number of values - (and by definition, not operators) off the stack. + While compound expressions can look overly complex, they can be + considered elegantly simple. To quickly comprehend RPN expressions, + you must know the algorithm for evaluating RPN expressions: iterate + searches from the left to the right looking for an operator. When it's + found, apply that operator by popping the operator and some number of + values (and by definition, not operators) off the stack. For example, the stack "1,2,3,+,+" gets "2,3,+" evaluated (as "2+3") during the first iteration and is replaced by 5. This results in the @@ -65,8 +65,8 @@ SSoommee EExxaammpplleess 2) 1,5,+ eval is 1,5,+ = 6 result is 6 3) 6 - Let's use that notation to conveniently solve some complex RPN expres- - sions with multiple logic operators: + Let's use that notation to conveniently solve some complex RPN + expressions with multiple logic operators: 1) 20,10,GT,10,20,IF eval is 20,10,GT = 1 result is 1,10,20,IF @@ -77,13 +77,13 @@ SSoommee EExxaammpplleess read pop "if 1 then 10 else 20" so push 10. Only 10 is left so 10 is the answer. - Let's read a complex RPN expression that also has the traditional mul- - tiplication operator: + Let's read a complex RPN expression that also has the traditional + multiplication operator: 1) 128,8,*,7000,GT,7000,128,8,*,IF eval 128,8,* result is 1024 - 2) 1024,7000,GT,7000,128,8,*,IF eval 1024,7000,GT result is 0 - 3) 0,128,8,*,IF eval 128,8,* result is 1024 - 4) 0,7000,1024,IF result is 1024 + 2) 1024 ,7000,GT,7000,128,8,*,IF eval 1024,7000,GT result is 0 + 3) 0, 7000,128,8,*,IF eval 128,8,* result is 1024 + 4) 0, 7000,1024, IF result is 1024 Now let's go back to the first example of multiple logic operators, but replace the value 20 with the variable "input": @@ -96,7 +96,7 @@ SSoommee EExxaammpplleess 2) A,10,input,IF eval is A,10,input,IF read "if A then 10 else input". Now replace A with it's verbose - description againg and--voila!--you have a easily readable description + description again and--voila!--you have an easily readable description of the expression: if input > 10 then 10 else input @@ -126,8 +126,8 @@ SSoommee EExxaammpplleess EExxeerrcciisseess Exercise 1: - Compute "3,2,*,1,+ and "3,2,1,+,*" by hand. Rewrite them in tradi- - tional notation. Explain why they have different answers. + Compute "3,2,*,1,+ and "3,2,1,+,*" by hand. Rewrite them in + traditional notation. Explain why they have different answers. Answer 1: @@ -152,7 +152,7 @@ EExxeerrcciisseess Answer 2: if (input <= 56000/8 ) { input*8 } else { 56000 } - input,56000,8,DIV,LT,input,8,*,56000,IF + input,56000,8,DIV,LE,input,8,*,56000,IF Exercise 3: @@ -187,4 +187,4 @@ AAUUTTHHOORR -1.3rc4 2008-03-15 RPNTUTORIAL(1) +1.4.8 2013-05-23 RPNTUTORIAL(1)