the goodman group
university of cambridge  


The Silicon Graphics Teaching Laboratory
has been replaced by the
Chemi cal Information Laboratory
and this information is for historical interest only

Root Rational Fraction Program (RRF)

A calculator program for working with numbers that are square roots of rational fractions

This program was written by Anthony Stone and Charles Wood, and is intended primarily for the calculation of Wigner 3j, 6j and 9j symbols, which occur in the theory of angular momentum, and for performing elementary arithmetic with them. Further details of the program may be found in Comp. Phys. Comm. 21 (1980) 195. The source code is available as a compressed tarfile (about 25 kbytes). As well as providing a stand-alone calculator program, it provides a library of Fortran subroutines that manipulate numbers which can be represented as square roots of rational fractions.

It reads input a line at a time and treats it as commands for a calculator working in Reverse Polish Notation. It is convenient for interactive use, but it can be used non-interactively by supplying a file of commands as standard input. Such a file should finish with the `Q' or `QUIT' command; if it does not the program will crash rather inelegantly when it reaches the end of the input. After each line of input has been processed, the top item on the stack is displayed, unless the last command already displayed it. The commands available are:

integer - read the integer (which must be non-negative) and put it on the stack. To get a negative number on the stack, you need to read in a positive number and use CHS to change the sign.

PP rrf - read the rest of the line as a root-rational-fraction in power-of-prime form, and put it on the stack.

+ - Add: replace the top two elements on the stack by their sum.

- - Subtract (top-of-stack from the one below). To change the sign of the top-of-stack, use CHS.

* - Multiply

/ - Divide (top-of-stack into the one below)

POWER n - raise to power n (n = integer or integer/2).

SQRT - = POWER 1/2. Note that it is an error to take the square root of a number which already contains half-odd-integer powers.

CHS - change sign

SWOP,SWAP - exchange top two items of stack

STO n - Store top-of-stack in memory n (1 =< n =< 10). The item is not removed from the stack.

RCL n - Recall from memory n to top-of-stack.

V - Verify top of stack.

LIST - List the entire stack using the current default verification mode. Top of stack is shown first.

VP - Verify top-of-stack in power-of-prime notation

VI - Verify top-of-stack as (a/b)*sqrt(c/d), where a, b, c and d are integers (standard default).

VF - Verify top-of-stack as a floating-point number.

VMP - Change default verification mode to power-of-prime.

VMI - Change default verification mode to (a/b)*sqrt(c/d). This is the usual default.

VMF - Change default verification mode to floating-point.

0J, 3J, 6J, 9J - Calculate a Wigner 3j, 6j or 9j symbol and put it on the stack. 0J calculates a 3j symbol for which all m values are zero. The full input for these commands takes the form:

  • 0J j1 j2 j3
  • 3J j1 j2 j3 m1 m2 m3
  • 6J j1 j2 j3 l1 l2 l3
  • 9J a b c d e f g h i
- where each argument is integer or integer/2 (integers only for 0J) and all arguments must appear on the same line separated by one or more spaces.

POP - Delete the top member from the stack.

PUSH - Push the stack down, copying the top member. PUSHing an empty stack inserts zero.

CLR,CLEAR - Clear the stack.

CLF - Clear the factorial table.

PROMPT `string' - Set prompt string. The string is output when the program is ready for the next line of commands. The default string is `..'. A null string may be set.

ECHO+ - Reflect each input line before obeying any commands.

ECHO- - Do not reflect input lines (default).

( - Ignore rest of line.

? - Give a summary of the available commands.

QUIT, Q - Quit.

This file was last revised by Anthony Stone ( on 14 May 1996.

© Goodman Group, 2005-2021; privacy; last updated April 16, 2021

department of chemistry University of Cambridge