Topics Register • News • History • How to • Sequences statistics • Template prototypes

# Rational number

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

A rational number is a real number which can be written as $\displaystyle{ \frac{a}{b} }$ or $\displaystyle{ a/b }$ where $\displaystyle{ a }$ (the numerator) is any integer and $\displaystyle{ b }$ (the denominator) is an integer different from zero. The set of all rational numbers is named $\displaystyle{ \mathbb{Q} }$.

The notation $\displaystyle{ a/b }$ is called fraction. A fraction is irreducible when both numbers are coprime, otherwise it can be reduced to an irreducible form by dividing both the numerator and the denominator by their greatest common divisor. This operation does not change the rational number represented by the fraction.

The following operations are defined:

## Contents

$\displaystyle{ \large \frac{A}{B} + \frac{C}{D} = \frac{AD+BC}{BD} }$

## Subtraction

$\displaystyle{ \large \frac{A}{B} - \frac{C}{D} = \frac{AD-BC}{BD} }$

## Multiplication

$\displaystyle{ \large \frac{A}{B}\frac{C}{D} = \frac{AC}{BD} }$

## Division

Valid only when the second rational number is not zero.

$\displaystyle{ \large \frac{A}{B}/\frac{C}{D} = \frac{AD}{BC} }$

Between two rational numbers there are infinite other rational numbers. This is because between the numbers $\displaystyle{ a }$ and $\displaystyle{ b }$ we have the following $\displaystyle{ n }$ numbers:

$\displaystyle{ \large a + \frac{k(b-a)}{n+1} }$

by varying the number $\displaystyle{ k }$ from 1 to $\displaystyle{ n }$. Then we can make the value $\displaystyle{ n }$ as high as we please.

This means that the set of rational numbers is a dense subset of the real numbers.

From the above reasoning one can think that all real number are rational, but it can be shown that the set of irrational numbers (those real numbers that are not rational) is also dense and there are more irrational numbers than rationals (there are different types of infinites).

## Decimal representation of rational numbers

A rational number can be represented exactly when the denominator of the irreducible fraction is a perfect power of 2 multiplied by a perfect power of 5, i.e. it has the form $\displaystyle{ 2^n \times 5^m }$.

Otherwise the number represented in decimal is periodic where the period is a divisor of the Euler totient function of the denominator. This function can be computed by factoring the denominator. As a special case, when the denominator is a prime number, the period is a divisor of the denominator minus 1.

When we have the number represented in decimal form, to convert it to a fraction depends on whether the decimal expansion is exact or periodic.

In the first case, when the number $\displaystyle{ N }$ in decimal has the form $\displaystyle{ m.n }$ where $\displaystyle{ n }$ has $\displaystyle{ d }$ digits at the right of the decimal point ($\displaystyle{ d=0 }$ for integers), the fraction is:

$\displaystyle{ \large N = \frac{m * 10^d + n}{10^d} }$

In the second case, when the number $\displaystyle{ N }$ in decimal has the form $\displaystyle{ m.npppp\ldots }$ where $\displaystyle{ n }$ has $\displaystyle{ d }$ digits and $\displaystyle{ p }$ has $\displaystyle{ e }$ digits, the fraction is:

$\displaystyle{ \large N = \frac{(m * 10^d + n)(10^e-1)+p}{10^d (10^e-1)} }$