↑ to Frrr103 Menu  ↑ to Main Menu

Frrraction 104 — Advanced functions


APRX - A powerful decimal-to-stack converter

tutorial icon
Frrraction Procedure

The really powerful thing you can do with a decimal number is to get rid of it: Use the yellow APRX function. APRX is short for 'Approximate', and what it does is generate in F2 an efficient stacked version of the decimal number in F1intD. (By "efficient" we mean a stack with small numerator and denominator whose decimal accurately matches the given decimal.)

Decimal-to-Stack conversion is a surprisingly subtle task. For example, the standard conversion of the famous number e, accurate to 8 digits, is 2 + 7,182,818/10,000,000. To 4 digits it is easily approximated by 2 + 718/1,000. But 2 + 719/1,001 which looks almost the same, is way more accurate (7 digits—off by only 1 in the 8th digit). You don't figure out stuff like that by a quick calculation in your head.

information icon 00 copies Fdec to F1intD:

Internally, APRX generates five different efficient decimal-to-stack conversions then selects the best of the five and presents it to you in Fraction F2. This can sometimes be very handy.  To get Fig. APRX1, we made F1intD be the decimal fraction 12.543 and ytapped APRX.
APRX result screenshot
Figure APRX1
Summary of all five methods is shown.
The five APRX methods are numbered from 0 to 4 and named "0—std exact", "1—repeat pattern", "2—end-9, ob1", "3—try all, exact", and "4—try all, ob1" where "ob1" is short for "off by 1". For each given target fraction APRX temporarily covers frrrNotes to list the methods in order from best to worst performance on that specific fraction, using a numeric "Eval Code". The most significant digit of the eval code shows how many digits are in the denominator (2 for the try-all-exact method, and 4 for the standard method). That digit-count is followed by the actual denominator (000000035 or 35 for Method 3, and 000001000 or 1000 for Method 0).

As you can see, the result (given in Fraction F2) was excellent. The standard mixed form — listed fourth in the ranking — is 12+543/1000, whose denominator is much larger than that of the 12+19/35 that Frrraction's APRX Method 3 found.
Five more APRX Examples
F1intDF2int+F2num/F2den=F2dec
12.512+
1
/
2
=12.5
12.5412+
7
/
13
=12.538462
12.54312+
19
/
35
=12.542857
12.543212+
44
/
81
=12.54321
12.5432112+
44
/
81
=12.54321
In each of the five examples, notice how F2dec correctly rounds off to exactly match all specified digits of F1intD. The standard conversion used by most fraction apps seldom comes close to the efficiency of APRX. The worst case in this series would be 12.54321 = 12 + 54,321/100,000 — six denominator digits for standard vs. two for APRX.

This Math is Fun icon and link to adding fractions links to a page that explains the standard conversion, APRX's "Method 0 std exact". Calling it "9 Recurring", Math is Fun also includes a Special Note explaining part of the APRX "Method 1 repeat pattern".

 ↑ to Frrr104 Menu

CF - Composite Functions

background iconbackground

CF stands for "Composite Functions", a term meant to distinguish them from Frrraction's basic built-ins. The CF facility provides a way for users to automate their fraction calculations by writing programs—sequences of Frrraction keycodes—that can be performed whenever they yTap the CF key. It also provides a way to essentially enlarge the number of useable keys beyond the sixteen permitted by the limited space on iPhone screens.

To use CFs, you Edit a Note to include one or more "CF Brackets", which are matched pairs of braces enclosing sequences that define the functions. There are three kinds of Composite Function: Egyptian Fractions, Continued Fractions, and Program Functions. Within a Note, their brackets look like this:

CFBracketentries
Egyptian Fraction
{ a0; a1, a2, ... an }
integer denominators
Continued Fraction
[ a0; a1, a2, ... an ]
integer quotients
Program Function
{{ blah this that etc }}
action keywords

Classic Fractions—Egyptian Fractions and Continued Fractions—are similar to each other in style, and simpler to use than Program Functions, so we discuss them in the next section. Following that, we go into the details of Program Functions.

CF - Classic Fractions

There are two kinds of classic fractions: Continued Fractions and Egyptian Fractions. Continued Fractions are cool for a number of uses, including the secret codes my Grandson Galen and I are doing. Egyptian Fractions built the pyramids 4000 years ago. They're still good for divvying things among people, but aren't useful for much else any more.

An example Continued Fraction is:
5 + 1 / (4 + 1/ (3 + 1/ 2 )).
In normal notation, this continued fraction would be written something like this:

     1
5 + ——————————————
          1
     4 + —————————
               1
          3 + ————
               2
Continued Fraction Example 1

"Doing the arithmetic" reduces it to the ordinary stacked fraction: 157/30.

Here's an example Egyptian Fraction:
5 + 1/4 + 1/3 + 1/2.
Doing its arithmetic reduces it to the ordinary stacked fraction: 73/12.

Classic Fractions are awkward to type, so Frrraction abbreviates them with a widely used shorthand bracket notation: Square brackets formed with the square braces [ and ] enclose Continued Fractions, and curly brackets formed with the curly braces { and } enclose Egyptian Fractions — look closely, those Egyptian curly braces are not the normal smooth parentheses.

The integer part of the fraction immediately follows the opening brace, and is followed by a semicolon.

If there is no integer part then the first entry within the bracket is 0 followed by a semicolon, viz. [0;a,b].

If the fraction has the mixed form a+0/1 i.e. there is nothing but an integer part then the bracket is simply [a;]. Don't omit the semicolon, though—without it, CF doesn't even recognize <[a] as a continued fraction command.

After the semicolon, the quotients (fraction parts) follow in order, each followed by a comma — although the final comma before the closing brace is usually omitted. For example, the continued fractions [5;4,3,2] and [5;4,3,2,] have integer part 5 and fraction parts 4, 3, and 2 and they equal 157/30.

YTapping Frrraction's CF key performs any of several tasks, depending upon what brackets you've put into frrrNotes.

You don't really need the CF function in order to work with classic fractions, of course. You can use normal Frrraction arithmetic or just do the work by hand. Of course, you could wear itchy old hair shirts instead of soft cotton, too.

For example, to convert [5;4,3,2] into an ordinary stacked fraction, the following steps (working from back to front) would do it:

  1. put 2 into F1
  2. put ONE into F2 then Divide
  3. put 3 into F2int (requires Frrraction showing Mixed Fractions)
  4. put ONE into F1 then Divide
  5. put 4 into F1int
  6. put ONE into F2 then Divide
  7. put 5 into F2int.

and there you have it: [5;4,3,2] is 5+7/30, or 157/30. (Frrraction's M|P function will convert the mixed fraction 5+7/30 into the pure fraction 157/30 if you don't want to do that chore by hand.)

Here's a procedure to go the other way — convert 157/30 into a continued fraction (writing the bracket down by hand as you go, I suppose):

  1. put 0+157/30 into F1
  2. Use M|P to convert it to 5+7/30
Now you know that the bracket begins with [5; ].
  1. Clear the 5 in F1int to 0
  2. put ONE into F2 and Divide.
This leaves 4+2/7 in F2.
  1. The bracket continues as [5;4, ].
  2. Clear the 4 in F2int to 0
  3. put ONE into F1 and Divide.
This puts 3+1/2 into F1.
  1. Put the 3 into the bracket as [5;4,3, ]
  2. Clear the 3 in F1int to 0
  3. put ONE into F2 and Divide.
This puts 2+0/1 into F2.
  1. Put the 2 into the bracket as [5;4,3,2, ]
  2. Clear the 2 from F2int
This leaves the result as 0+0/1 or just zero, which says we're done. Delete the final comma in the bracket and the answer is complete: 157/30 = [5;4,3,2].


 ↑ to Frrr104 Menu

CF — Program Functions

At the start of the previous section, introducing Composite Functions, we described a typical Program Function as

{{ blah this blah that etc }}

This double-curly-bracket is one of four kinds of bracket that can co-exist in a frrNote: The other three are: [...] square brackets for Continued Fractions, {...} for Egyptian Fractions, and |...| for File operations—mentioned at this point only for completeness, file brackets superficially resemble Composite Functions but are really quite different, as described in the frrrFile section of this guide.

The actual blah-this-and-that Program-Function keywords include most of the normal button-tapping business of Frrraction. Including one or more of the keywords within a CF function Bracket {{...}} (separated by whitespace) has this effect: When you exit the frrrNoteEditor and later "perform the function" by yTapping the CF key, the bracket is scanned from left to right, top to bottom; as keywords are encountered, Frrraction does exactly what it would do if you had tapped the named keys.
CF Program Function keyword descriptions
Keywordsaction
F1num F1den F1int
F2num F2den F2int
make the named fraction cell become active
F1
F2
make the named fraction—specifically, the cellmate of the present cell—become active
clr
clear the active fraction cell to zero
bDel
backspace-delete digits from the active fraction cell
1 2 3 4 5 6 7 8 9
0
like tapping the named digit key,
even if preceded by Y RCL or Y STO
00
doubleTap 0 (decimal fraction to F1int retasked as F1dec)
add sub mul div
these act like tapping the math op keys
You can use + – * / if you prefer.
Unfortunately, Apple omitted ÷ from the iThing keyboard, so / must serve for div.
Y
this acts like tapping the yellow key, and must precede each yellow function
M|P MIX PURE XCH APRX
DUP MAX pMAX nMAX ONE GCD
these represent the yellowFunctions shared by the digit keys.
CHS STO RCL
these represent the yellowFunctions shared by the math-op keys
@
A CF program loop is an @-group: A group of brackets each with a prefix-@, and the last one with a single inside-@. THE inside-@ can be placed anywhere in the last member of an @-group of cf-brackets (putting it near the bracket's closing double-brace makes it nicely visible when you are developing the program). An @-group behaves this way: When the cf bracket with the inside-@ finishes running, the cf facility searches the entire frrrNote from the top to the position of the inside-@ and replaces all instances of the pattern @{{ by @<{{. What this does is to re-enables all members of the @-group, permitting the run-cycle to start over again with the top member of the group the next time CF is tapped—without the user being required to use EDIT to manually re-enable the group members. The @-command has no effect on cf brackets other than those whose opening is currently tagged by @{{, viz. un-enabled cf brackets the user has designated for inclusion in the cyclic @-group.
CF
FILE
these are INTENTIONALLY OMITTED from the CF-function lexicon

I tend to type the keywords in mixed upper/lowercase as shown in the table, for readability, but CF ignores case so you can use all lowercase or all uppercase or mix it up however you like.

CF generally depends upon space-characters to isolate the keywords so it can recognize them individually but it makes one exception, for yellowKey: An easier way to provide the Y key for yellowFunctions is like this:

yAPRX etc.

Example: {{ F2 Y ONE F1 Y RCL 5 + Y STO 5 }}

or better: {{ f2 yONE f1 yRCL 5 + ySTO 5 }}

If you edit either of these into the current frrrNote, then tap Return-to-Frrr to exit the editor and tap the CF key, fraction F1 and register R5 will both end up containing a number 1 larger than the original contents of register R5.

Key idea


tutorialicon Try it.
Use the editor to change the above example to give it two enablers, so it looks like this:

<<{{ f2 yONE f1 yRCL 5 + ySTO 5 }}

The function (assuming it's the enabled CF closest to the top of frrrNote) can then be executed twice before becoming dormant. You can confirm the operation: Put - 21/33 into fraction F1 then do Y STO 5 to put it into register R5 as a test value; run CF twice; then activate fraction F2 and tap the key-sequence Y RCL 5. At that point, F2 will also contain the same value as F1: 15/11.
 
If you'd like to execute it repeatedly, without having to use EDIT to add more enablers whenever it runs out of them, use the @-loop facility like this:
 
@<{{ f2 yONE f1 yRCL 5 + ySTO 5 @ }}

Now the bracket will run every time you tap CF.

If you'd like automatic one-time initialization to be done by the first CF-tap, with subsequent CF-taps running the @-loop, you can add something like this before the @-loop in the frrrNote:

<{{ yPURE f2num clr 2 1 yCHS f2den clr 3 3 ySTO 5 yONE }}

Now the first time you run CF the initialization will run; that uses up its single <enabler so, the next time you run CF it will be the @-loop that runs, using up that bracket's single <enabler. When the cf system encounters the bracket's inside-@ it will restore the depleted <enabler, setting things up so the next run of CF will re-run the @-loop again. This will repeat as often as you tap CF.

Key idea


You can have any number of CF functions in a frrrNote, some dormant, some enabled, some in @-loop-groups. At any given moment some members of @-loop-group may have <enablers, others not—although the unenabled ones will be re-enabled the next time the inside-@ command within the last cf bracket of the @-group is executed.

Each time you run CF, Frrraction scans the frrrNote from top towards bottom, and performs the first enabled CF function it finds—it doesn't matter whether it happens to be an @<{{ bracket or just a normal <{{ bracket. Each time CF finishes running a function bracket, it strips off one of that function's enablers. When its last enabler is gone, the function falls dormant and the next enabled function will be executed next time you yTap CF.

The frrrNoteEditor's Up- navigation key and Down- navigation key navigator buttons try to position the insertion cursor at the enabler-positions of the various CF functions—that's what the squigglies at the bottom of the keys are meant to remind you—so enablers can be easily replenished.
 ↑ to Frrr104 Menu

hp( — a major CF extension

Some CF Program functions aren't available on Frrraction's keyboard due to lack of space. One of the best of the missing functions is hp(. 'hp' stands for ''high precision'. What it provides is a 64-bit integer-and-floatingPoint decimal programmable calculator for those times when Frrraction's 32-bit integers need some help. It uses RPN (Reverse Polish Notation), automatically accessing a five-deep XYZTU number-stack as needed.

A typical reason to appreciate hp( arises when you compute a high accuracy square root of a fraction. To confirm the result you'd like to multiply the result by itself—doing something like Y DUP ×. But if the numerator or denominator of the putative result exceeds 46,340 (the integer square root of pMAX) the multiplication will cause overflow. Here's where hp( can come to the rescue, because multiplication of two 32-bit numbers cannot overflow in 64-bit arithmetic.

Among its other resources, hp( gives separate access to each of Frrraction's integer cells, individually and in combination, allowing manipulation beyond conventional fraction paradigms. An easy example: Want to give F2's stack a non-unit gcd, to exercise the yellow GCD key? Use hp( to multiply each of F2num and F2den by the desired common divisor. If F2=2+4/5 you can convert it that way into 2+12/15. As with many other hp( operations there's no other way to do it. Putting 0+3/3 into F1 and multiplying does not have the intended effect.

Another example where separate access to Fcells is useful is the following cf bracket for computing the factorial of a small integer:

@<{{
get f2int 1 + put f2int
put/: N :/ f2flt )
*
hp( put/: N ! :/
@ }}
 

If you initialize F1=1+0/1 and F2=0+0/1, then yTap CF five times, you get the following screen showing 5! = 120:

Frrraction screenshot
CF Example Screenshot

Another @-loop example, to help clarify order of execution of CF brackets when multiple CF program-brackets are in the same frrrNote:

123 @-Loop Demo

<{{ F1num clr 1 2 3 hp( 0 sto 1
) }}

@{{ hp( rcl 1 1 + dupx sto 1
put f2num put/- second -/
f1num ) }}

@<{{ hp( rcl 1 1 + dupx sto 1
put f1num put/- first -/ f2num
) @ }}

>|41|

tutorialicon Try it.
Put the above program into frrrNote (either type it in, or use iPhone's Copy/Paste to get it from the web into a fresh frrrNote) and Return-to-Frrr.

Look at the program to determine what you think will happen when you run it. While YellowKey is in its temporary Green-T state (due to Return-to-Frrr), tap CF to see.

F1num contains 123, and the first of the three program brackets no longer has a <enabler. Clearly, that's the bracket that ran.

Which program bracket will run the next time you run CF? Test your analysis by running CF again (YellowKeyStatus is still Green-T, so just tap CF to do it).

F2num now contains 'first'. Q: Which function-bracket put that there? A: The third, with its 'put/- first -/ f2num' command.

Q: Why did the third bracket run before the second? A: For the same reason the first bracket didn't run again: They had no <enabler and the third one did.

Q: The third bracket only had one <enabler; why does it now still have an <enabler? A:It doesn't still have an <enabler; it has a new <enabler—and so does the second bracket—put there by the inside-@ command which executed when the third bracket ran.

What will happen if we tap CF again? Did you figure it out? Then try it.

We didn't tap Y first and F1num is the active Fcell, so you might expect F1num to now contain 7 or 1237. But it now contains 'second'. Only the second bracket with its 'put/- second -/ f1num' command could have done that. Q: Why did CF run instead of the digit 7 being put into F1num? A: Because the YellowState was Green-T, not White-W, and CF is one of the three special yellowFunctions that don't need Y to be tapped when Green-T is up.

Q: Why did the second bracket run instead of the first? A: Because the first had no <enabler whereas the second's <enabler had been replenished as part of an @-loop. Note that the first racket still has no <enabler and, since it ran, the second function-bracket again has no <enabler. So the third bracket is next-in-line to run.

From now on, as the members of the @-loop, the second and third brackets take turns running whenever you tap CF.

Q: Have you figured out the source of the increasing numbers that alternate with the words 'first' and 'second' in the Fnums? I'll leave it for you to answer.

background icon Background Topic: RPN

"Reverse Polish Notation" is all about the order you name numbers and operations when writing arithmetic. The name sounds sophisticated and scary to some people at first, but in practice it's very nice to use. What most people normally use would sound scary too, if schools told you what it's called before telling you how to do it: "In-Fix Notation". See what I mean? There are three notations:

  • Pre-Fix Notation, e.g. – 7 4 or maybe Subtract(7,4)
  • In-Fix Notation (the standard), e.g. 7 – 4
  • Post-Fix Notation (reverse Polish), e.g. 7 4 –
All three of the example expressions define the same result: Subtracting 4 from 7 gives 3.

The great thing about RPN is how it eliminates calculation ambiguities that plague the other two notations, such as: What is the result of 7 – 4 * 2 using infix calculation? Is it –1 or is it 6?

In-fix processors resort to two artifices to resolve such ambiguities: the hard-to-remember notion of "operator binding precedence" in which *mul has higher precedence than –subtract. In the example, *mul is bound to the 4 more tightly than –subtract is bound to the 4, so 7 – 4 * 2 would be 7 – 8. This notion is augmented with user-provided parentheses to override the natural precedence (or overcome the ok-which-is-it confusion) when necessary. Sometimes the whole expression must be rearranged to contrive the result you want. Thus, presented with 7 – 4 * 3 the in-fix processor multiply 3 by 4, and that result would be subtracted from 7 to get –5. To get the other result you would need to override the natural operator precedence by using parentheses, viz. (7 – 4) * 3 would do 7 – 4 first, to get 3; then do 3 * 3 to get 9.

Does that In-Fix approach stll sound simple? I don't think so. We do it just because it's what we first got taught in school.

RPN handles the problem this way: It treats data (7,4,2) and operators (–,*) as a simple stream; data items get "pushed onto the stack" one by one as they're received (like dishes onto a steaming stack in a cafeteria); when the next operator comes along in the stream, it "pulls" the data it needs off the top of the stack, however many data items it needs (the common +,–,*, and / operators each needs two, CHS change-sign needs one, and so forth); combines the data as the operator's nature requires; and pushes the result onto the stack—to be treated as data by future operations when they come along in the stream.

So. To get In-Fix's 7 – (4 * 3) = –5 result, RPN could use
7 4 3 * –

The Stack
during 7 4 3 * –
X 0  7  4  3 12 -5 
Y007470
Z000700
T000000
U000000

To get (7 – 4) * 3 = 9, RPN could do
7 4 – 3 *
The Stack
during 7 4 – 3 *
X 0  7  4  3  3  9 
Y007030
Z000000
T000000
U000000

Note that RPN needs no parentheses or hard-to-interpret precedence rules. It's a simple first-come first-served cafeteria.

information icon Info Topic: hp(

hp( operates in frrrNotes within the standard {{...}} CF bracket in the format hp(...). That is, it has its own sub-bracket: The opening brace, an ordinary left parenthesis, is built right into the hp( keyword with no intervening space. The closing brace is an ordinary right parenthesis. Within that bracket, the keywords, all private to hp(, are presented in Reverse-Polish notation—which means that numeric operands are listed first, followed by the operations that need them.

For example, to subtract 3 from 22 you could edit the following into frrrNote:

<{{ hp( 22 3 − ) }}

Or, to subtract 3 from the denominator of fraction F1—a kind of thing that might be more useful while being awkward to do in Frrraction itself:

<{{ hp( get F1den 3 − put F1den ) }}

The sequence of stacks the first of these would produce is:
The Stack in Action
init after getafter 3after −after put
X0223190
Y002200
Z00000
T00000
U00000

Assuming that the fraction cell F1den started out containing 22, the second CF bracket would produce the same sequence of stacks as the first.

Operation of the stack is automatic. The only times you need to think about it are when you want to get it to show you some intermediate results that would normally evaporate in the normal course of a computation. For such cases, here's how it works: Called a FILO stack (First-In, Last-Out) the stack owns private operations called "push" and "pull". When an operation produces a result, that value gets pushed onto the stack; a chain reaction pushes the older stack entries down by one position: discards the current contents of T (there being no place for it to go), Z moves down into T, Y moves down into Z, and the new value loads into the newly vacated X-position at the top. When an operation needs an operand value, it pulls it from the top of stack: this retrieves the X-value, lets the old Y float up to replace it, the old Z floats up to replace the old Y, the old T value floats up as the new Z and (what doesn't work with plates in the cafeteria) also leaves the old T in place as a copy. The DUPx and XCHxy operations give a modicum of control over the stack contents, and the hp( operation whose keyword is '=' prints the current contents of the stack in the frrrNote.

hp( Control
Binary
Operations
action
+ − * / ^
Integer operations
(Y op X → X) e.g.Y−X→X
X and Y get pulled off the stack,
integer parts extracted if decimal
(before doing the arithmetic),
64-bit integer result pushed onto stack,
becomes new X
%
(Y mod X → X) X and Y pulled off the stack,
keep remainder after Y÷X,
push remainder as new X
00+ 00− 00* 00/ 00^
Decimal operations ('00' prefix intended to remind of Frrraction's doubletap 0 gesture)
(Y op X → X) e.g.Y−X→X
X and Y get pulled off the stack,
converted to decimal if not already,
decimal result pushed on to become new X
xchXY
X and Y pulled off the stack,
pushed back in reverse order
Unary
Operations
chs
pull X,
reverse algebraic sign,
push back as new X
dupX
duplicate X,
push so Y becomes copy of X
Data
(Operands)
literal
integer
up to 19 digits wide,
e.g. -3141592653589793238
get Fcell
retrieves 32-bit value from a Frrraction F1 or F2 cell,e,g, get F1num,
pushes 64-bit version onto stack as new X
put Fcell
pulls 64-bit X from stack,
attempts to deliver it to 32-bit Frrraction cell,
e.g.put F2den.
May cause hidden overflow in Frrraction
00put F1intD
pulls 64-bit X from stack,
converts it to decimal if not already,
delivers rounded-to-32-bit version to F1int,
F1int a.k.a. F1intD is the only Frrraction cell that can hold a decimal value.
sto i
pulls 64-bit X from stack,
stores it in hpRegister i
i between 0 and 9
rcl i
recalls 64-bit value from hpRegister i,
pushes it onto the stack
i between 0 and 9
=
When the hp( scanner encounters the equal sign it halts processing of the bracket and displays the current contents of the stack
=>
Display snapshot of the stack then continue processing
Annotation
show/-...-/
hp( delivers some information into the frrrNote; you can have it intersperse a few words of yours by putting
show/- a few words -/
inside the hp( ... ) bracket.
show Fcell
Frrraction cell contents can be displayed in the frrrNote as well, using
show <fcell>
where <fcell> is any of F1num, F1den, etc.
put /:...:/ Fcell
Labels can be put into Frrraction cells, using
put/: label :/ <fcell>
where <fcell> is any of F1num, F1den, etc.
This ability should be used sparingly.
Footnotes
The Fcell operands for GET and PUT are:
F1num, F1den, F1int, F2num, F2den, and F2int.
There should be nothing but whitespace between GET or PUT and its Fcell operand.
Any number of /- ... -/ annotations can be distributed through an hp( bracket. Don't forget to match each /- with a terminating -/.
The contents of the ten 64-bit hpRegisters are preserved throughout the Frrraction session, across separate runs of CF.
As with the {{...}}-keywords, the hp(...)-keywords are insensitive to upper/lower case.


 ↑ to Frrr104 Menu

CF - other extensions

The CF Bracket facility exposes a slowly growing collection of specialized frrrApplets. Those in support of "Modular Square Roots" have their own section later in this chapter of the Frrraction Guide. Others are listed here.

CF Applets
keywordaction
isPrime
Classifies an integer as prime or composite.
Setup: m in active cell Fcell
Action: Fflt announces
    "Fcell is (or is not) prime"
x^n
Raises x to the integer power n
Setup: F=n+x/1 where F is the active fraction
Action: F becomes r+x/1 where
           r is the 32-bit nth power of x.
           The 64-bit r is shown in frrrNote.
x^nModp
Computes the nth power of x (mod p)
Setup: activeF=n+x/p. n,x,p all >0; p prime.
Action: F becomes r+x/p where
           r is the nth power of x (mod p).
z^nModp
Raises the modular complex number z=x+v·y to the power n modulo prime p. w=v^2 is the QNR square of the imaginary carrier v.
Setup: F1=n+x/p, F2=w+y/p.
Action: The fractions become F1=n+A/p, F2=w+B/p
           where z^n = A+B·v (mod p).
iAdd
iMul
Adds or multiplies the "mate"( of the active Fcell) in the inactive fraction to the active Fcell.
Setup: x in active Fcell,
           y in "the mate of the active Fcell"
           e.g. x in F2den, y in F1den
Action: 32-bit result y <op> x → x.
           64-bit result is shown in frrrNote,
           e.g. x=pMAX in active F2den, y=7 in F1den,
           <{{ iAdd }} in frrrNote;
           -2,147,483,642 → F2den,
            2,147,483,654 is shown in frrrNote.
           Confused? see Frrraction's huge numbers.
n!Modm
mn!
mn! and n!Modm are synonyms.
They compute n factorial (mod m)
Setup: activeF = 0+n/m
Action: activeF = n!(mod m) + n/m
Note: If you use pMAX for m, the result is the normal n! for 0 ≤ n ≤ 12. For n=13 and beyond, n! would cause 32-bit overflow (while n!Modm does not, of course).
           2nd line of Action
key
summary
Setup:
Action:
           more

 ↑ to Frrr104 Menu

CF — Secret Code Ring

This is some really fun stuff! (in my humble opinion). If you can find a way to interpret the numbers in a Continued Fraction as letters of the alphabet, then the Continued Fraction becomes a message. And if you convert that Continued Fraction into an ordinary stacked fraction, then the message is quite nicely disguised--especially to people who think numbers are just numbers!

Galen and I have been working with one way to interpret numbers as letters. We call it the simple alphaNum code: Replace A by 1, B by 2, ... , and Z by 26. For better communication we extended the simple alphaNum code to include a number for a blank space, a period, and a question mark. We use 32 for space, 46 for . and 63 for ?.

That's all there is to it. Now [0;23,15,23,46] or 1/(23 + 1/(15 + 1/(23 + 1/46))) or 15931/367472 all contain the coded message "WOW." Cool, eh?

After you catch on, you can begin to let Frrraction do the heavy numeric lifting for you: Put the CF command <[0;23,15,23,46] into frrrNotes (not forgetting the command arrow '<') and CF will put 15931/367472 into the active fraction. Notice that CF removes the Command Arrow to let you know it finished the job. Or go the other way: Put 15931/367472 into the active fraction and an empty square bracket [] into frrrNotes and let CF fill the empty bracket for you, creating the loaded bracket [0;23,15,23,46].

There are two things to avoid:

A typical long message: 16057/16558 28/451 69865/75672 2932/41465 362/1829 1663/1894. The first way I divided it into codewords, two of the codewords ended with A. In each case I just moved the A to the beginning of the next codeword. Those two five-letter codewords didn't cause overflow to occur so there was no other problem.

When you get tired of counting letters of the alphabet to get from messages to numbers, here is Frrraction to the rescue.

The CF Command that converts simpleAlpha to a normal Continued Fraction is: <[@ followed by the alphabetic letters of a codeword and the closing square bracket ]. Use NOTE to put that into frrrNotes, then employ the CF function. Bingo. frrrNotes then contain the bracket form of the continued fraction.

For example, if you put <[@SHOW] into frrrNotes, then the CF function will replace it by [@SHOW] <[0;19,8,15,23,]. So frrrNotes would then contain a new CF Command, ready for the CF function to put the numeric continued fraction, which encodes the alphaNum SHOW message, into the active Fraction.

Frrraction can also go the other way: it can decode a stacked fraction which happens to be the alphaNum-encoded form of a text message: The CF Command in frrrNotes is just [@] and Frrraction's CF function fills the empty bracket with the decoded form of the active fraction.

For example, if the active fraction contains 2791/53375 and [@] is in frrrNotes then the CF function will replace [@] by [@SHOW]. If the active fraction was just a number, not an alphaNum-encoded message, what you would most likely get from CF is [@~~~~] because the tilde character ~ is what the CF function uses when it doesn't recognize a number as an alphaNum-encoded character.

The next step in Frrraction's Secret Message Codec facility is to use the much more powerful ASCII code instead of the overly simple alphaNum code. The only difference in operation is that the alphaASCII flag is the tilde character ~ rather than alphaNum's @ character. Thus, <[~Wow 012!] converts to [0;87,111,119,32,48,49,50,33,]. The stacked form of that particular numeric continued fraction happens to be so huge it generates an Overflow in Frrraction. The three-to-five character codeword limit applies to ASCII as well as to alphaNum. Breaking it up into two four-letter codewords we get [0;87,111,119,32] = 422831/36790106 and [0;48,49,50,33] = 80932/3886387.

ASCII is Page 1 of UTF8 and Unicode, the world's most important standard communication codes, so well worth being a little familiar with. For reference, here is a convenient list of ASCII codes. Good news is: You do not need to actually know ASCII in order to use it in Frrraction.

Decoding an ASCII-encoded stacked fraction is just as easy: Put an empty ASCII-flagged bracket [~] into frrrNotes and the active fraction will be decoded into the empty bracket. For example, if Fraction F2 were active and contained 80932/3886387, the empty bracket would be replaced by F2 = [0;48,49,50,33][~012!] — the numeric continued fraction followed by its ASCII-decoded form.

A final note: The two alpha encodings are mostly incompatible with each other — they share only the space, period, and question mark. I assume that, once you get to the ASCII [~ forms, you won't feel a need to turn back to the simple alphaNum [@ forms.


 ↑ to Frrr104 Menu

CF Example: Best Approximations

background iconbackground

Sometimes you have a fraction whose numbers are too large for the purpose at hand. Frrraction's APRX function provides an easy-to-use solution that you already know about. The CF continued fraction provides a fascinating alternative.

Example: Suppose you want a simpler fraction than 1,010/7,009 but with the same 7-digit decimal value. Putting 1,010/7,009 into Fraction F1 and doing doubleclick-00 puts the decimal form 0.1441004 into F1int. APRX then finds the simpler stack 712/4,941 which has the decimal form 0.14410038, which rounds to exactly match the seven digits of F1int.

Another way to get that result--and the whole point of this CF Example section of the guide--is to use CF continued fractions to find the most efficient fraction that represents any number in the range from 0.14410035 to 0.144100449, i.e. any number that rounds up or truncates down to the given seven digits. Here's how:

tutorialicon Try it. Really.
Step 1: Put 0.14410035 —the smallest number that rounds up to match 0.1441004—into F1intD and put an empty Continued Fraction bracket [] into frrrNotes, then use the CF function. This replaces the empty CF bracket by F1 = [0;6,1,15,1,1,3,1,3,3,1,...].

Step 2: Put 0.144100449 —the largest number that rounds down or truncates to match 0.1441004—into F1intD, put another empty bracket [] into frrrNotes, and apply CF again. This replaces the empty bracket by [0;6,1,15,1,1,3,1,6,2,1,...].

Step 3: Make a new bracket by copying the previous two as far as they agree, producing [0;6,1,15,1,1,3,1,]. At the next entry, the two brackets disagree: the smaller has a 3, the larger has a 6. Complete your copy by using 1 plus the smaller, viz. 4, so it reads [0;6,1,15,1,1,3,1,4]. Convert that bracket into a command bracket by putting a left-angle-bracket in front of it, to obtain: <[0;6,1,15,1,1,3,1,4].

Step 4: Exit the frrrNotes editor, tap any F2-cell, and use the CF function. It will convert your command bracket into the stack 712/4,941. Exactly the same as APRX got (APRX took less work on your part, but a lot more on the computer's part!).

Fig. APRX2 summarizes the example. The frrrNotes have been edited to include all three steps in one screen. Using NOTE, I simply typed the lines "Best Approximation Example" and "1010/7009 = 0.1441004" after doubleclick-00 gave me the decimal value. The lines "F1 = ... = 0.144..." were produced from empty brackets by the CF-command in Step 1 and Step 2. The line "Lesser+1..." shows what's left of the CF-command-bracket <[0;6,1,15,1,1,3,1,4] after Step 3 collapsed it into F2.

Screenshot: CF best approximation results
Figure APRX2
A CF best-approximation example.
tutorialicon Try it. Really.
For a second example, suppose you would be satisfied with a 4-digit approximation 0.1441 for that same fraction used above. Then the above steps become:
  Step 1: 0.14405 → [0;0;6,1,16,...]
  Step 2: 0.1441499 → [0;0;6,1,14,...]
  Step 3: <[0;6,1,15]
  Step 4: → 16/111.
As a check on the result of Step 4, put 0.1441 into F1intD; APRX then yields 16/111 in F2. It always works.
tutorialicon Try more:
In the above examples we chose intervals to contain precisely all decimals that match (after rounding) a given decimal to a given number of digits.
The examples directly generalize to finding the most efficient stack for a number required only to lie within a specified interval—any interval you want.

This starter reference on best approximations explains in more detail.

 ↑ to Frrr104 Menu

CF - Square Root support

Frrraction offers a constellation of CF functions that address square roots in various forms: