SkillAgentSearch skills...

Rpn

RPN command-line calculator

Install / Use

/learn @ConceptJunkie/Rpn

README

rpn

rpnChilada is a command-line Reverse-Polish Notation calculator.

rpnChilada supports arithmetic with arbitrary precision, powers and roots, logarithms, algebraic functions (including polynomials arithmetic and solving), trigonometric functions, complex numbers, computer science related functions (bitwise math, base conversion), number theory functions, astronomical functions, prime number calculations and lookup, can operate with single operands or lists of operands and supports a wide variety of flexible unit conversions comparable to the GNU units program.

Updates

Update - November 24, 2021

Python 3.10 really broke RPN, but the fixes were simple.

8.5.6 includes several small fixes to deal with incompatibilities introduced with Python 3.10, the most significant of which is that pyreadline, the moribund library that provides readline functionality for Python on Windows was replaced with the built-in readline. If I recall correctly, the readline library didn't support Windows in the hazy past, which is why I started using pyreadline.

Update - September 27, 2021

RPN isn't dead, although I figured it was time for a new release since with the library updates, 8.4.0 didn't work any more.

rpn 8.5.4 is released: Big Clean-Up and Documentation Release!

Much more thorough argument validation has been implemented on all operators. In addition, all non-constant operator function names now end with 'Operator', which means I can be sure they are not being called recursively, or being called by other operator functions, so that the argument expansion and validation isn't being done more than once.

I have continued my focus on completing the online help, which is now more than 95% complete. This also resulted in a number of operators being eliminated (see below), and a bevy of bug fixes. Almost every operator now has a help example.

The help for units is now complete. Every unit has help text.

About 70 new operators have been added.


The current release is 8.5.6.

See "rpn help settings" for more information.

Installing from PyPI

In theory, you just need to do "pip install rpnChilada".

Windows users will want to use Christophe Gohlke's Windows installers for gmpy2 and pyephem at https://www.lfd.uci.edu/~gohlke/pythonlibs/.

For Python 3.10, an installer for gmpy2 can be found here: https://github.com/aleaxit/gmpy/releases/download/gmpy2-2.1.0rc1/gmpy2-2.1.0rc1-cp310-cp310-win_amd64.whl

Installing for Termux

Before installing from PyPI or from source for use on Termux, the following packages need to be installed:

"pkg install rust binutils libandroid-spawn build-essential"

and for Python:

https://github.com/termux/termux-packages/issues/10065

"pip install cmake ninja"

for reasons I can't explain, it takes a really long time to build the required Python packages. A really long time.

Installing RPN on Debian-based Linux:

I don't think this is correct yet.

#sudo apt install python3-dev python3-pip libgmp-dev libmpfr-dev libmpc-dev python3-setuptools python3-gmpy2 #pip3 install rpnChilada

Running RPN using the source:

rpn is written in Python 3, and requires several libraries for the hard math stuff.

Please see requirements.txt for a list of required Python packages.

Windows users will want to use Christophe Gohlke's Windows installers for gmpy2 and pyephem at https://www.lfd.uci.edu/~gohlke/pythonlibs/.

Using rpnChilada

rpnChilada is very easy to use. It's just like any RPN calculator: Operands go first, then the operators, just like your Dad's old HP calculator.

If you are using the package installed with pip, there are commands in the scripts directories called "rpn" and "rpnChilada" to launch rpnChilada. If you are running from the source, then rpn is an alias for python /<path-to-rpn>/rpn.py. In interactive mode, you leave off the rpn.

Unit tests can be run with the testRPN command (when installed from the wheel) or by running testRPN.py from the rpn/ directory.

For instance:

rpn 2 2 +

will calculate 2 + 2.

rpnChilada supports more than 1000 operators. (rpn _dump_operators will list them all.)

The entire operator list is also included at the bottom of this document.

Built-in Help

rpn has pretty extensive built-in help, although the help files are not complete. However, all operators have at least a brief description, and most are obvious enough to use easily.

Start with rpn help for an overview. To dive right in, see rpn help examples. In interactive mode, typing help will launch help mode. Then, topics will print out a list of help topics and exit will return to rpn.

Data Files

The data files are stored in the same location as rpn.py in a subdirectory called rpndata/.

If you really want to generate prime numbers, see my "primes" project: https://github.com/ConceptJunkie/primes I've calculated the first 15 billion prime numbers and will someday update the rpn lookup tables.

The project https://github.com/ConceptJunkie/rpnChiladaData provides the compiled prime number data files. If you installed rpnChilada with pip, then this data will be automatically installed.

rpn also provides a simple interface for accessing The On-Line Encyclopedia of Integer Sequences (http://oeis.org), see rpn help special and rpn help oeis.

rpnChilada used to provide a Windows installer, but I haven't been able to do that since version 6.4.0. I hope to bring that back some day.

Feedback, Comments, Bug Reports:

Any feedback is welcome at rickg@his.com. This was originally an exercise to learn Python, but slowly blossomed into something really useful and fun, so I wanted to share it. rpn also exposes just a few of the features of the amazing mpmath library (by Fredrik Johansson, http://mpmath.org/) which is where almost all the hard math stuff is actually done.

Rick Gutleber rickg@his.com

p.s. rpn is licensed under the GNU GPL version 3.0. See (see (http://www.gnu.org/licenses/gpl.html) for more information).

Release Notes

8.5.4

Big Clean-Up and Documentation Release!

Much more thorough argument validation has been implemented on all operators. In addition, all non-constant operator function names now end with 'Operator', which means I can be sure they are not being called recursively, or being called by other operator functions, so that the argument expansion and validation isn't being done more than once.

I have continued my focus on completing the online help, which is now more than 95% complete. This also resulted in a number of operators being eliminated (see below), and a bevy of bug fixes. Almost every operator now has a help example.

The help for units is now complete. Every unit has help text.

About 70 new operators have been added, including:

The 'number_from_file' and 'get_decimal_digits' operators have been added.

Time zone handling has been improved. 'to_time_zone', 'set_time_zone' and 'to_local_time' have been added.

'lat_long_to_nac' was removed (after I fixed it), since the developers of the Natural Area Code claim a copyright on the system itself, and do not allow outside implementations. I guess they don't want people adopting their system. <shrug>

I removed the 'cyclotomic' operator, since I don't understand it enough to explain what it does or why it's useful. I'm just exposing an mpmath function. Some day I'll probably go through an expose all those mpmath functions that I haven't already.

I removed 'planck_angular_frequency' since there is some confusion as to how it should be defined. Plus, it isn't very interesting. (see https://chemphys.ca/pbunker/PlanckWiki.pdf)

I removed the 'planck_pressure' operator since it was identical to the 'planck_energy_density' operator.

I removed 'iso_date' and 'iso_day' which both duplicated 'to_iso'. Also, 'make_iso_time' was essentially a duplicate function as well, so it's been removed.

I renamed the following operators to be more consistent: 'get_utc' --> 'to_utc' 'get_local_time' --> 'to_local_time' 'num' --> 'ranged_sum' 'nprod' --> 'ranged_product' 'power_tower2' --> 'power_tower_right' 'is_friendly' --> 'is_sociable_list' 'limitn' --> 'decreasing_limit'

Removed a couple of unit types for which I could not find sufficient documentation. In particular the Talk page on Wikipedia claims that a couple of the wine bottle sizes they had previously reported could not be verified.

Removed the 'filter_lists' operator because it isn't needed. 'filter' works fine on a list of lists.

I got rid of the 'repeat' operator because I literally couldn't think of a use for it.

I eliminated 'eval_list2' and 'eval_list3' because I couldn't figure out how to contrive a meaningful example, and therefore don't think they would be useful.

The 'recurrence' operator was removed, because it was a duplicate of the 'sequence' operator.

And, of course, the usual bug fixes.

8.4.0

Revamped the prime number operators, and filled in a couple of missing ones.

A number of operator names have changed for more consistency. The old names have been added as aliases.

Added the 'bitwise_xnor', 'from_french_republican', 'to_french_republican', 'to_french_republcan_name' operators.

A fix was made to support using rpn on OS X.

A number of bugs were fixed, and I did extensive touch-ups based on pylint.

8.3.0

Added the 'solve_frobenius' operator and renamed 'denomination_combinations' to 'count_frobenius'.

Added the 'sequence' and 'tau' operators.

The astronomy operators now don't care which order the arguments are in, except for 'angular_separation', which expects the first two arguments to be astronomical bodies.

The aliquot operators now detect if an amicable number chain has been found and terminate.

Help has been filled in for all constants and most of the units.

Added 'does_list_repeat', 'sequence' and 'tau' operator.

Added the 'esterling' unit.

'hyperop' now has several hard-coded results fo

View on GitHub
GitHub Stars23
CategoryDevelopment
Updated1mo ago
Forks3

Languages

Python

Security Score

95/100

Audited on Feb 18, 2026

No findings