Separating rational coefficients from $a + b\sqrt{2}$ From Gallian’s Contemporary Abstract Algebra, Exercise 6.26:
Let
$$
  G= \lbrace a + b\sqrt{2} \mid \text{$a$, $b$ rational} \rbrace
$$
and
$$
  H =
  \left\lbrace
    \begin{bmatrix} 
      a & 2b \\ 
      b & a 
    \end{bmatrix}
    \,\middle|\,
    \text{$a, b$ rational}
  \right\rbrace.
$$
The task is to show “that $G$ and $H$ are isomorphic under addition”. Here my question is not about the calculations that show that the isomorphism is operation preserving (these I believe are routine), but the form of the mapping itself.
I think the easy way is a mapping from $H$ to $G$, because if you have separate components $a$ and $b$, you can easily form the sum $a + b \sqrt{2}$. But what about the mapping from $G$ to $H$?
Instead, I am concerned with how to pull out rational coefficients from the sum of $a + b\sqrt{2}$. Isn’t that a bit weird? Is something like that possible, if the sum is represented in some number format, either floating point, or a string of digits? How does one do it? Perhaps I am missing some rational/irrational background.
 A: The isomorphism you want is a simple assignment. We'll take the function $f: G \to H$ to be defined by
$$f(a + b\sqrt{2}) = \begin{pmatrix}
a & 2b\\ 
b & a
\end{pmatrix}$$
which, you can compare to the block of Python code
import numpy as np
def f(a, b):
    return np.array([[a, 2b], [b, a]))

that does the same assignment. Don't worry that there isn't a $\sqrt{2}$ in that code - we can regard $G$ has the structure that interprets a coordinate $(a, b)$ as the sum $a + b\sqrt{2}$. (It's actually the structure $\mathbb{Q} [\sqrt{2}]$.)
One can show that this function is one-to-one and onto (exercise), and the additions are preserved and it's easily shown.
Functions in mathematics need not be "computed," but rather it's just a rule that assigns elements of one set to another. Heck, we even have functions like $\pi (x),$ the number of primes less than or equal to $x$, or, if you've seen earlier in Gallian's text, $\phi(n)$, the Euler totient function, that counts the number of natural numbers relatively prime to $n$, up to $n$ itself.
But the point of the exercise is to show the two structures behave the same. I would not get bogged down by the word "function."
A: The important part here is that the two numbers $1$ and $\sqrt{2}$ are linearly independent over $ℚ$.
That is, whenever we have
$$
  a ⋅ 1 + b ⋅ \sqrt{2} = c ⋅ 1 + d ⋅ \sqrt{2}
$$
for some rational numbers $a, b, c, d$, then automatically
$$
  a = c \quad\text{and}\quad  b = d \,.
$$
For every element $x$ of the set $\{ a + b \sqrt{2} \mid a, b ∈ ℚ \}$ we have therefore unique (!) rational numbers $a$ and $b$ with $x = a + b \sqrt{2}$.
This uniqueness allows us to implicitly extract the coefficients $a$ and $b$ from $x$.
