Solution (source code)

= Solution

Represent $a+b\sqrt5$ by the pair $(a,b)$ in the <quadratic field> $\mathbb Q(\sqrt5)$. Its multiplication rule is
$$
\boxed{(a+b\sqrt5)(c+d\sqrt5)=(ac+5bd)+(ad+bc)\sqrt5.}
$$
The constructor copies both rational components, so later reduction through another pointer cannot change the constructed value:

``
PROCEDURE mkIrr(r,i: rational): irrational;
VAR z: irrational;
BEGIN
  NEW(z);
  z.rat := mkRat(r.num,r.den);
  z.irr := mkRat(i.num,i.den);
  RETURN z
END mkIrr;

PROCEDURE addIrr(x,y: irrational): irrational;
BEGIN
  RETURN mkIrr(addRat(x.rat,y.rat),addRat(x.irr,y.irr))
END addIrr;

PROCEDURE mulIrr(x,y: irrational): irrational;
VAR r,i: rational;
BEGIN
  r := addRat(mulRat(x.rat,y.rat),
              mulRat(mkRat(5,1),mulRat(x.irr,y.irr)));
  i := addRat(mulRat(x.rat,y.irr),mulRat(x.irr,y.rat));
  RETURN mkIrr(r,i)
END mulIrr;
``

The representation includes rational values when the second coefficient is zero; the supplied type name does not require every stored value to be irrational.