rejig

General Limitations
Login

General Limitations

Known limitations of the rejig support for specific families of RPN calculators are in other documents:

Here we cover instead the general observations applicable to each of these, collected to avoid repeating them in each model-specific document.

Raising and Lowering

Support for non-R47 program formats in rejig is implemented by mapping their instructions to the nearest R47 equivalent. It tries for a 1:1 mapping in every instance where the R47 acts as a superset of these lesser machines.

In certain cases where a rough equivalent exists but with a semantic mismatch, we set that 1:1 ideal aside rather than fail the translation outright. Because even the lowliest machine we support — HP-12C — is Turing-complete, we can in principle emulate any R47 instruction provided we have enough RAM and compute time. While we do not go to extremes in rejig, there are several cases where a straightforward 2:1 mapping is possible, and a few more where a higher ratio is worth the cost.

This lowering process must then be accompanied by a “raising” process in the reverse transform path to restore the original code.

The --map option is helpful in understanding where and how this type of thing occurs.

Key-by-Key Numbers

The most common case where rejig ends up producing a transformation ratio greater than 2:1 occurs when raising Voyager programs, since those store numeric inputs as individual key codes. Because the R47 instead stores real-number literals whole, within a single op, rejig collects digits plus an optional decimal radix, a sign, and e-notation to assemble the intended value. It then deconstructs this when lowering programs from the intermediate R47 form to a Voyager program format.

Complex Numbers

Still more complicated is the way rejig raises the primitive 1982-era HP-15C complex number support into the first-class form the R47 expects, and vice versa when lowering. A further nuance here is that rejig is smart enough to error out when that lowering target is an HP-11C, which lacks this feature. Then there’s the DM32 lowering path, where the conversion wholly differs because the HP-32S designers did not adopt the HP-15C dual-stack scheme. For their 30-series Pioneer models, Hewlett-Packard chose a method similar to the one they provided at launch of the HP-41C in their Math Pac add-on module, which in turn allows rejig to use a DM32-like lowering method when that or the Advantage Pac instructions are selected.

Confused? Feel free to ignore these details; leave the complexities — hah, math joke! 🤓 — to rejig.

A related case is the classic HP interpretation of the “to rectangular” and “to polar” conversion ops, which take the real part from X and the imaginary part from Y. Because the R47 has first-class complex number support — thus also rejig — its default is to treat X alone as the complex-valued argument.

For compatibility with programs written under the old rules, the R47 has a second set of complex conversion ops. Because their behavior is gated under the 🟧 PREF `RP_(HP)` pref, rejig presumes that if you use them in a program, you’ve left this pref at its default. In other words, rejig treats the op style as implying the ops’ arity. If you mix the styles — compatibility ops but set the pref to give R47 arity — rejig will fail to guess what you meant.

Argument Mapping

Another common class of cases where ops don’t raise and lower 1:1 is when a historical machine has substantially the same operation as the R47, but it doesn’t take its argument the same way.

Let’s take as our example the R47 WSIZE op — part of its HP-16C superset — which encodes the word size argument as part of the operation itself, indivisible:

WSIZE 18       ; set PDP-1 word size

Contrast that faithful textual representation of the wire coding for this single op with the way the original machine did it:

1
8
f WSIZE

This formatting is meant to demonstrate how the key-by-key number encoding issue combines with the Voyager family’s primitive op encoding, where the shift keys are stored as separate byte codes. There isn’t a literal WSIZE op in its catalog, but instead a request for the f-shifted variant of the 4th key in the 4th row.

(This same code sequence — 42 44 — has a different interpretation on every other Voyager model!1)

Then you have Free42, where a faithful text representation becomes:

18
WSIZE

This is not a mere presentation style choice. The formatting here is meant to convey the fact that the “18” argument gets stored as a single number on the stack, which is then consumed by the WSIZE op that Free42 added atop the HP-42S base, which lacked it.

I give these examples not merely for their own pedagogic value, but also as preface to the following challenge: if we return to the R47 example above, what should be done with the comment at the end of its line when producing a listing for the HP-16C or Free42?

Go on, think about it. Does it follow the WSIZE, resulting in this Free42 form?

18
WSIZE          ; set PDP-1 word size

Or, does it somehow get hoisted to the “18” line? But if so, does that mean it lands on the “1” digit line in HP-16C form?

The actual answer is that earlier versions of rejig dropped it in translation. 🤦‍♂️ As of 0.42.0, rejig is now smart enough to preserve it in this and other cases where 1:1 translation is not possible. Now end-of-line comments end up on the last line in the translation.

Squaring

You might be surprised to learn that a 1:N translation can occur in handling the 𝑥² op. Why? Because it is missing on the HP-12C; that’s why. These primitive machines have a `sqrt(x)` op but no inverse.

A dedicated squaring function did eventually appear in the HP 12c Platinum, in the 2003 inaugural model, but how did those poor financial wonks cope from 1981 until then?

One workaround is to push 2 and then use its closest replacement, the `y^x` op, which is exactly what rejig does for the HP-12C. Alas, it must choose a different — and arguably more idiomatic — solution for the HP-16C, which lacks that op as well: ENTER then ×.

Regardless, we must suppress these workarounds when the singular 𝑥² op occurs in do-if-true context, lest we perpetrate this:

X=0?        ; oopsie! ❌
  ENTER     ; duplicate X register, conditionally?!
×           ; multiply to emulate 𝑥²

¡No es bueno!

The other complication occurs when reversing the HP-16C variant transform into the idealized R47 form. We certainly do have a squaring op in the R47 — two, in fact — but we must not ignore the R47’s eRPN default mode, which changes how ENTER works in a way that matters here. Our unwillingness to guess whether you’ve left that default mode alone or changed it — or inject conditional code into the output to test it — leaves us with an uncomfortable choice: our HP-16C accommodation for a lack of a dedicated `x^2` op is considered one-way, while the HP-12C one is losslessly reversible.

Both 2:1 op expansions have another flaw: they push a T off the top of the stack where a more capable machine would avoid the loss. Our current stance accepts this cost as superior to the alternative: stubbornly refusing to translate the instruction while the solution is straightforward enough that I, your humble software benefactor, can manage it.

🤷‍♂️ Tradeoffs are the soul of engineering.

Pause

On input, legacy argless PSE ops are translated to the R47’s PAUSE op, which takes a count of 100 ms “ticks” to pause. For non-R47 outputs, the compact form expands:

This works up to ~10 seconds due to the 0-99 limit on the PAUSE arg.

For the same reasons laid out above, we made rejig smart enough to avoid it in do-if-true context:

TEST?
  PSE    ; extra pause when TEST is true
PSE      ; regular pause in all cases

If we performed PSE consolidation here, we’d end up with a single PAUSE 20 call, not the two separate PAUSE 10 calls the programmer intended.

Storage Arithmetic

Although the HP-41C family supported the STO arithmetic ops from the start, RCL arithmetic wasn’t added until the HP-42S. We paper over this lack in rejig by expanding ops like “RCL÷ R01” into two separate ops, “RCL R01” then divide.

We then had the idea to spread this capability through the lesser machine targets. This includes special cases like the HP-12C, which has native STO arithmetic for R0-R4; rejig expands that to the other registers, then adds RCL arithmetic to craft a cherry-on-top dessert course for you.

Whether through foresight or luck, HP defined the RPN argument order such that commutativity does not come into play for RCL, allowing an easy 2:1 expansion. No such luck with STO, where STO+ and STO× are 3:1 expansions, and STO- and STO÷ require 4:1 expansions.

Scope

Despite the many examples above, the overall incidence of this type of thing is rare! Do not expect rejig to provide even a fraction of the R47’s advanced feature set to 1980s era RPN calculator designs. We justify it in tightly constrained cases where the round-tripping is straightforward and the loss of the “missing” feature would be painful enough to justify the inline rework.

Legacy Semantics

While the R47 is a spiritual successor to the HP-42S, it does a great many things differently, with the broad intent of doing them better. Strict compatibility with its forty-family forebears is not one of the C47/R47 project’s goals.

An excellent example of this is how they improved on Hewlett-Packard’s weak alpha string handling scheme. As of mid-2026, the R47 now has a “42” menu with legacy ops to mimic the old way, but these were added to allow rejig to raise these programs to the R47 IR form losslessly. This is no sotto voce admission that the old ways were better; the old singular alpha register sucked, and it took the R47’s improvements to demonstrate it.

Matrices

The natural scope of matrix handling in rejig is programmable ops like M.DIM and M.FIND. Even then, it is restricted by the semantic equivalence rules set out above. I am aware of no RPN calculator that offers a matrix literal syntax — that’s one of the advantages RPL brought — which rules out interactive operations like inputting the matrix or displaying it once input.

The consequence to rejig is that it is blind to many details of matrix handling; all it sees are ops and opaque referents. Type-checking is necessarily a runtime matter, not something rejig can validate.

Add to this the fact that the major exemplars of this feature set within the rejig scope — HP-15C, HP-42S, R47 — each treat matrices quite differently, and you see that rejig cannot always translate programs involving them.

Lossy Mappings

There are several cases where rejig chooses to make semantically lossy instruction mappings. The usual justification is that the R47 way of doing things isn’t precisely the same as how the HP did it back in the day, but there’s enough of a semantic hook to tie the two together. Since the alternative is to fail the translation outright, we choose to proceed with the best-effort conversion but issue a warning, then leave it to the user to attend to the nuances of the change.

It is important to realize that because rejig raises all inputs to R47 form before lowering it for output, it cannot always copy ops straight across. In the worst cases, rejig is forced to fail outright rather than follow HP’s pioneering path, laid down back in the eighties. With no automated option, rejig screams and dies, leaving it to you to address these manually; sorry about that.

A fine example of this is the Voyager family’s single-instruction looping op tangle:

Future versions of rejig may become smarter about all this, but I’m making no promises.

Variable and Register Ranges

The --validate option lets the user name an RPN machine type, one aspect of which is validating that the input program’s storage references are within that machine’s range. For instance, --validate hp11c rejects references to registers A-E even though the keys are present because the hardware rejects sequences like “STO A”. These rules may be applied implicitly by giving rejig a file named with an extension that implies a --validate rule set.

When the user asks for this validated input to be lowered to a machine lacking the same range of storage references, rejig can and will map these references into the available range. For instance, if you have a program containing…

STO "MyVar"

…rejig will raise it without complaint as long as HP-42S or better input validation rules are in effect. If you then ask it to lower that to a machine without alpha-named global variables, rejig will do its best to invent an in-range name for it, by avoiding names it has already seen. To take our HP-11C example again, this is likely to become a “STO R.0” instruction.

This means input like “LBL F” may succeed or fail depending on the combination of input and output rules in effect. If you tell rejig that it is HP-15C input, it will refuse the conversion because it knows that is not true, but if you tell it that it is R47 input and you want it lowered to HP-15C form, that reference to global label F gets remapped to one the target does support.

Local Registers

Voyager and thirty-series machines entirely lack local registers, giving us a hard choice when converting an input using them to one of these targets: stop the conversion and give the user nothing to work with, or proceed and give them something to massage into a better condition by promoting these locals to global registers.

We choose the latter, and the way it works is that rejig elides LocR ops from the output for such targets, and then on later encountering the associated R47 R.𝑥𝑦 local registers, rejig runs them through the same variable name remapper it uses for other cases. It makes no effort to avoid collisions with other subroutines in the same program; doing so would require tracing the call graph, which is well outside the current implementation scope of rejig.

This risk leads us to emit a warning when this occurs, cluing the user into the fact that they will likely need to fix things up, using our best-effort translation as a starting point.

(You may now wish to return to the rejig home page.)

License

This work is © 2026 by Warren Young and is licensed under CC BY-NC-SA 4.0


  1. ^ The HP-11C and 15C do share one of those interpretations, FRAC. On the HP-10C, it’s literally the opposite interpretation: INT, with FRAC shoved one step right as 44 45. On the HP-12C, it has no meaning at all.