# Quote notation

Quote notation is a numeral system for representing rational numbers which was designed to be attractive for use in computer architecture. The notation stems from a notation form for p-adic numbers. In a typical computer architecture, the representation and manipulation of rational numbers is a complex topic. In quote notation, arithmetic operations take particularly simple, consistent forms, and can produce exact answers with no roundoff error.

Quote notation’s arithmetic algorithms work with a typical right-to-left direction, in which the addition, subtraction, and multiplication algorithms have the same complexity for natural numbers, and division is easier than a typical division algorithm.

The notation was invented by Eric Hehner of the University of Toronto and Nigel Horspool, then at McGill University, and published in the SIAM Journal on Computing, v.8, n.2, May 1979, pp. 124–134. The construction of this system follows the approach of Kurt Hensel's p-adic numbers.

## Representation

### Introduction

In the decimal system a rational number is written either with a final number of digits, like 123.45, or as such a final number of digits followed by a repeating sequence, like

1/3 = 0.333... and 8/7 = 1.142857 142857 ...

In the quote notation the rational numbers with final decimal representation are written in the same way. Rational numbers with repeating sequences however are written differently, with a leading repeating sequence, indicated by a closing quote, like

3' = ...333,
123' = ...123123123,
123'45.6 = ...12312300 + 45.6 or
12.3'456 = ...123123/10 + 0.0456

In the case of coinciding quote and decimal point an exclamation mark is written:

123!456 = ...123123 + 0.456

The interpretation of the leading repeating sequence is an extension of the sum of the geometric series:

${\displaystyle 1+10^{k}+10^{2k}+10^{3k}+...={\tfrac {1}{1-10^{k}}}}$.

For instance:

${\displaystyle 1+10+100+100+...={\tfrac {1}{1-10}}=-{\tfrac {1}{9}}}$

and

${\displaystyle 1+1000+1000^{2}+1000^{3}+...={\tfrac {1}{1-1000}}=-{\tfrac {1}{999}}}$.

With this convention numbers in quote notation are interpreted as:

3' = ...333 = 3(...+100+10+1) = –3/9 = –1/3
123' =...123123123 = 123(...1000000+1000+1) = –123/999
123'45.6 = 45.6 + 123'00 = 45.6 + 100 × 123' = 45.6 – 12300/999

abc...z' = – abc...z/999...9,

with the same number of 9's in the denominator as there are digits in the repeating part of the sequence.

A rational number is represented in quote notation as a sequence of digits with a quote mark and radix point. For example, 12'3.4 is in quote notation.

The radix point may come before the quote mark, as in 12.3'4, or at the same place, as in 12!3. When the radix point and the quote coincide, an exclamation point (!) is used.

The radix point has its usual function; moving it left divides by the base; moving it right multiplies by the base. When the radix point is at the right end, the multiplicative factor is 1, and the point can be omitted. Scientific notation may be used as an alternative to the radix point.

One can think of the quote mark as saying that the digits to its left are repeated indefinitely to the left. For example, we can think of 12'34 as the infinite sequence ...1212121234 . If this repeated sequence is all 0s, both the zeros and the quote mark can be omitted.

### Natural numbers

The natural numbers are generally written in the way one usually expects to see them, but they can also be written using an explicit quote, an explicit radix point, or redundant zeros on either end. For example, the integer two can be written as 2 or 2. or 0'2 or 0'2. or even 000'02.000, and the integer zero can be written as 0 or 0' or 0. or 0!. In the last example, the exclamation point represents the quote and radix point at the same position.

### Negative integers

Negative integers begin with the digit one less than the base. For example, in decimal, minus three is written as 9'7.

9'7 = 7 – 90/9 = –3

As

9' = – 9/9 = –1,

it is easily understood that for instance:

–189 = –1 × 189 = 9' × 189 = 1701 + 17010 + 170100 + ... = ...999811 = 9'811 = 811 – 1000

or alternatively, as:

9'000 = –1000,
–189 = 811 – 1000 = 811 + 9'000

Numbers beginning with any other repeating sequence are not integers. For example:

6'7 = 7 – 60/9 = 1/3

and

7'6 = 6 – 70/9 = – 16/9

## Interpreting quote notation

### Conversion algorithm

To convert quote notation into standard notation, the following algorithm can be used.

Let x and y be sequences of digits, as in ${\displaystyle x'y}$.
Let z be the digit 1 followed by a sequence of zeros of the same length as y.
Let a be the largest valued digit (one less than the base). In decimal, we have a = 9.
Let w be a sequence of as of the same length as x.

Then the number represented by ${\displaystyle x'y}$ is given by ${\displaystyle y-xz/w}$.

As an example, we will take 12'345 and convert it to a standard notation.

x = 12
y = 345
z = 1000
a = 9
w = 99

Then our standard notation follows,

${\displaystyle 345-{\dfrac {12\times 1000}{99}}={\dfrac {7385}{33}}}$

### Length of representation

Quote notation has the disadvantage that representations can be much larger than simple p-adic recording of denominator or numerator. Euler's theorem

${\displaystyle p^{\varphi (d)}\equiv 1{\pmod {d}}}$

guarantees that the periodicity in the p-adic representation of a fraction with denominator d has length ${\displaystyle \operatorname {ord} _{d}(p)\leq \varphi (d)\leq d-1}$. But there do exist numbers d (all of them primes, s. table) with ${\displaystyle \operatorname {ord} _{d}(p)=d-1}$ meaning that the length of a repeating group can be d − 1 which is exponential in the p-adic length ${\displaystyle \operatorname {len} _{p}(d)}$ of d.

${\displaystyle \textstyle d}$ 3 5 7 9 11 13 15 17 19 21 23 25 27 29 31 33 35 37 802787
${\displaystyle \textstyle \varphi (d)}$ 2 4 6 6 10 12 8 16 18 12 22 20 18 28 30 20 24 36 802786
${\displaystyle \scriptstyle \operatorname {len} _{2}(d)}$ 2 3 3 4 4 4 4 5 5 5 5 5 5 5 5 6 6 6 20
${\displaystyle \textstyle \operatorname {ord} _{d}(2)}$ 2 4 3 6 10 12 4 8 18 6 11 20 18 28 5 10 12 36 802786
${\displaystyle \scriptstyle \operatorname {len} _{3}(d)}$ 2 2 3 3 3 3 3 3 4 4 4 4 13
${\displaystyle \textstyle \operatorname {ord} _{d}(3)}$ 4 6 5 3 16 18 11 20 28 30 12 18 401393
${\displaystyle \scriptstyle \operatorname {len} _{5}(d)}$ 1 2 2 2 2 2 2 2 2 3 3 3 3 3 9
${\displaystyle \textstyle \operatorname {ord} _{d}(5)}$ 2 6 6 5 4 16 9 6 22 18 14 3 10 36 802786
${\displaystyle \scriptstyle \operatorname {len} _{7}(d)}$ 1 1 2 2 2 2 2 2 2 2 2 2 2 2 2 7
${\displaystyle \textstyle \operatorname {ord} _{d}(7)}$ 2 4 3 10 12 4 16 3 22 4 9 7 15 10 9 401393
${\displaystyle \scriptstyle \operatorname {len} _{11}(d)}$ 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 6
${\displaystyle \textstyle \operatorname {ord} _{d}(11)}$ 2 2 3 6 12 2 16 3 6 22 5 18 28 30 3 6 401393
${\displaystyle \scriptstyle \operatorname {len} _{13}(d)}$ 1 1 1 1 1 2 2 2 2 2 2 2 2 2 2 2 2 6
${\displaystyle \textstyle \operatorname {ord} _{d}(13)}$ 2 4 2 3 10 4 4 18 2 11 20 9 14 30 10 4 36 802786

As the table shows those primes are quite frequent.

While storing the integer 802787 in binary requires 20 bits, the storing of the rational number 1/802787 in quote notation requires at least 802786 bits (or at least 401393 p-adic digits), which differs by a factor of 40140 (s. rightmost column of the table).[1]

In the example 12'345 of the previous section we have p = 10 and d = 33, thus ${\displaystyle \operatorname {ord} _{33}(10)=2,}$ which is exceptionally small.

### Sign determination

If the leading digit is less than the first digit after the quote, the number is positive. For example, 123'45 is positive because 1 is less than 4. If the leading digit is more than the first digit after the quote, the number is negative. For example, 54'3 is negative because 5 is more than 3 .

If the quote comes at the end, just append a zero after the radix point. For example, 592' = 592!0, which is negative because 5 is more than 0. And 59.2' = 59.2'0 which is also negative.

If the leading digit equals the first digit after the quote, then either the number is 0!0 = 0, or the representation can be shortened by rolling the repetition to the right. For example, 23'25 = 32'5 which is positive because 3 is less than 5.

In binary, if it starts with 1 it is negative, and if it starts with 0 it is nonnegative, assuming the repetition has been rolled to the right as far as possible.

## Arithmetic

In our usual sign-and-magnitude notation, to add the two integers 25 and −37, one first compares signs, and determines that the addition will be performed by subtracting the magnitudes. Then one compares the magnitudes to determine which will be subtracted from which, and to determine the sign of the result. In our usual fraction notation, to add 2/3 + 4/5 requires finding a common denominator, multiplying each numerator by the new factors in this common denominator, then adding the numerators, then dividing the numerator and denominator by any factors they have in common.

In quote notation, to add, just add. There are no sign or magnitude comparisons, and no common denominators. Addition is the same as for natural numbers. Here are some examples.

  9'7 minus three              9'4 minus six
—————                        —————
0'3 makes plus three       9'8 6 makes minus fourteen

  6'7 one-third
+ 7'6 add minus one and seven-ninths
—————
4'3 makes minus one and four-ninths


### Subtraction

In our usual sign-and-magnitude notation, subtraction involves sign comparison and magnitude comparison, and may require adding or subtracting the magnitudes, just like addition. In our usual fraction notation, subtraction requires finding a common denominator, multiplying, subtracting, and reducing to lowest terms, just like addition.

In quote notation, to subtract, just subtract. There are no sign or magnitude comparisons, and no common denominators. When a minuend digit is less than the corresponding subtrahend digit, do not borrow from the minuend digit to its left; instead, carry (add one) to the subtrahend digit to its left. Here are some examples.

  9'7 minus three              9'4 minus six
- 0'6 subtract plus six     -  9'2 subtract minus eight
—————                        —————
9'1 makes minus nine         0'2 makes plus two

  6'7 one-third
- 7'6 subtract minus one and seven-ninths
—————
8'9 1 makes plus two and one-ninth


### Multiplication

Multiplication is the same as for natural numbers. To recognize the repetition in the answer, it helps to add the partial results pairwise. Here are some examples.

6'7 x 0'3 = 0'1 one-third times three makes one

6'7 x 7'6 one-third times minus one and seven-ninths:
multiply 6'7 by 6:        0'2 answer digit 2
multiply 6'7 by 7:      6'9
multiply 6'7 by 7:    6'9
multiply 6'7 by 7:  6'9
0'2 repetition of original
makes 592' minus sixteen twenty-sevenths


To someone who is unfamiliar with quote notation, 592' is unfamiliar, and translation to −16/27 is helpful. To someone who normally uses quote notation, −16/27 is a formula with a negation and a division operation; performing those operations yields the answer 592' .

### Division

The commonly used division algorithm produces digits from left-to-right, which is opposite to addition, subtraction, and multiplication. This makes further arithmetic difficult. For example, how do we add 1.234234234234... + 5.67676767... ? Usually we use a finite number of digits and accept an approximate answer with roundoff error. The commonly used division algorithm also produces duplicate representations; for example, 0.499999... and 0.5 represent the same number. In decimal, there is a kind of guess for each digit, which is seen to be right or wrong as the calculation progresses.

In quote notation, division produces digits from right-to-left, the same as all other arithmetic algorithms; therefore further arithmetic is easy. Quote arithmetic is exact, with no error. Each rational number has a unique representation (if the repetition is expressed as simply as possible, and we have no meaningless 0s at the right end after a radix point). Each digit is determined by a "division table", which is the inverse of part of the multiplication table; there is no "guessing". Here is an example.

9'84 / 0'27 minus sixteen divided by twenty-seven
since 0'27 ends in 7 and 9'84 ends in 4, ask:

                          9'8 4 What times 7 ends in 4? It's 2
multiply 0'27 by 2:       0'5 4
subtract:       —————
9'3   What times 7 ends in 3? It's 9.
multiply 0'27 by 9:   0'2 4 3
subtract:   ———————
9'7 5   What times 7 ends in 5? It's 5.
multiply 0'27 by 5: 0'1 3 5
subtract: ———————
9'8 4 repetition of original
makes 592' minus sixteen twenty-sevenths


Division works when the divisor and the base have no factors in common except 1. In the previous example, 27 has factors 1, 3, and 27. The base is 10, which has factors 1, 2, 5, and 10. So division worked. When there are factors in common, they must be removed. For example, to divide 4 by 15, first multiply both 4 and 15 by 2:

4/15 = 8/30


Any 0s at the end of the divisor just tell where the radix point goes in the result. So now divide 8 by 3.

                      0'8 What times 3 ends in 8? It's 6.
multiply 0'3 by 6:  0'1 8
subtract:   ————
9' What times 3 ends in 9? It's 3.
multiply 0'3 by 3:  0'9
subtract: ————
9' repetition of earlier difference
makes 3'6 two and two-thirds
Now move the decimal point one place left, to get
3!6 four-fifteenths


Removing common factors is annoying, and it is unnecessary if the base is a prime number. Computers use base 2, which is a prime number, so division always works. And the division tables are trivial. The only questions are: what times 1 ends in 0? and: what times 1 ends in 1. Thus the rightmost bits in the differences are the bits in the answer. For example, one divided by three, which is 1/11, proceeds as follows.

             0'1 rightmost bit is 1
subtract 0'1 1
—————
1'  rightmost bit is 1
subtract 0'1 1
—————
1'0   rightmost bit is 0
subtract   0'
————
1'   repetition of earlier difference
makes 01'1 one-third


### Negation

To negate, complement each digit, and then add 1. For example, in decimal, to negate 12'345, complement and get 87'654, and then add 1 to get 87'655. In binary, flip the bits, then add 1 (same as 2's complement). For example, to negate 01'1, which is one-third, flip the bits to get 10'0, then add 1 to get 10'1, and roll right to shorten it to 01' which is minus one-third.

## References

• Hehner, E.C.R.; Horspool, R.N.S. (May 1979), A new representation of the rational numbers for fast easy arithmetic (PDF), SIAM J. Comput. 8 no.2 pp.124-134
Specific
1. ^ Despite all advantages of exact and «fast» arithmetic of rational numbers this disadvantage makes quote notation unsuited for a software package of arbitrary precision.