### Modular Fractions

We only need 7 numbers for modulus (or clock) arithmetic mod 7 including working with fractions. Explore how to divide numbers and write fractions in modulus arithemtic.

Decipher a simple code based on the rule C=7P+17 (mod 26) where C is the code for the letter P from the alphabet. Rearrange the formula and use the inverse to decipher automatically.

### Double Time

Crack this code which depends on taking pairs of letters and using two simultaneous relations and modulus arithmetic to encode the message.

# Inverting Rational Functions

##### Stage: 5 Challenge Level:

One of our most prolific solvers, Patrick from Woodbridge School, sent in his thoughts on this problem

To invert a function, $f(x)$, the following procedure is used: say
$$f(x) = \frac{2x+9}{ x+2}$$
then the graph is
$$y = \frac{2x+9}{x+2}$$
It is inverted by replacing $x$ with $y$, and $y$ with $x$:
$$x = \frac{2y + 9}{y + 2}$$
and rearranging gives
$$y = \frac{9-2x}{x-2}$$
Thus
$$g(x) = \frac{9-2x}{x-2}$$
However, for values $x = \pm 2$, we have a denominator $0$ in one of the fractions, so these must be excluded from the domain of the functions.

For
$$y= \frac{x-7}{2x+1}$$
To invert this put
$$x = \frac{y-7}{2y+1}$$
Rearrange:
$$2xy + x - y = -7\,\quad y(2x-1) = -7-x\, \quad y = -\frac{x+7}{2x-1}$$
Thus, the inverse of $h$ is
$$k(x) = -\frac{x+7}{2x-1}$$

The procedure used by Patrick can be used to invert more general rational functions as follows
$$f(x)= \frac{ax+b}{cx+d}\quad\mbox{has inverse}\quad g(x)=\frac{b-dx}{cx-a}$$
To check this properly, consider
$$f(g(x))=\frac{a\left(\frac{b-dx}{cx-a}\right)+b}{c\left(\frac{b-dx}{cx-a}\right)+d}$$
This reduces to
$$f(g(x)) = \frac{a(b-dx)+b(cx-a)}{c(b-dx)+d(cx-a)}=\frac{(bc-ad)x}{bc-ad}$$
Which cancels to $x$, provided that $bc-ad \neq 0$. The same holds for $g(f(x))$.

On Ask NRICH, some discussion took place concerning the generalisation to rational functions involving quadratics.

Some progress can be made, in that if
$$y = f(x) = \frac{P(x)}{Q(x)}$$
then you might try to construct the inverse using the idea that $x\leftrightarrow y$, corresponding to reflecting the graph in the line $x=y$ so that
$$x = \frac{P(y)}{Q(y)}$$
Rearranging gives
$$Q(y)x = P(y)$$
This is a polynomial equation in $y$ of degree equal to the maximum of the degree of $P$ and $Q$.
However, a unique solution will only typically follow if $P(y)$ and $Q(y)$ are linear, and in general no algebraic solution will exist. Moreover, for the inverse to be unique, the function $f(x)$ must be one-to-one, which will not be the case for anything but linear rational functions.