Correspondence between binary quadratic representations and proper ideals of quadratic number fields $\DeclareMathOperator\SL{SL}\DeclareMathOperator\Aut{Aut}$Fix $d < 0$, a fundamental quadratic discriminant and $n$ a positive integer. Suppose $Q$ is a primitive binary quadratic form of discriminant $d$. Let us define the following,

*

*Representations of $n$ by $Q$: $R(Q, n) = \{ (x, y) \in \mathbb{Z}^2 |  Q(x, y) = n\}$

*$\Aut(Q)$ as the subgroup of $\SL_2(\mathbb{Z})$ that fixes $Q$ under the usual action of $\SL_2(\mathbb{Z})$ on binary quadratic forms.

*$R(d, n) = \coprod_QR(Q, n)/\Aut(Q)$ as $Q$ runs through a complete set of representatives for each class of properly equivalent forms. Typically, we may select the reduced forms.

*$I(d, n) = \{I \textrm{ proper ideals of the ring of integers of } K \textrm{ of norm } n \}$ where $K = \mathbb{Q}[\sqrt{(d)}]$ the quadratic numberfield of discriminant $d$.

*The Epstein zeta function for $Q$: $\zeta(s, Q) = \frac{1}{2} \sum_{(x, y) \neq (0, 0)}{(Q(x, y))}^{-s}$ for $\mathfrak{R}(s) > 1$ for $(x, y) \in \mathbb{Z}^2$

*The Dirichlet zeta function for $K$: $\zeta(s, K) = \sum_{I}{Nm(I)}^{-s}$ for $\mathfrak{R}(s) > 1$ as $I$ runs through all the proper integer ideals of $K$.

As a fact I know that when $d < -4$, $\sum_{[Q]}\zeta(s, Q) = \zeta(s, K)$. Also in I read that in general $|R(d, n)| = \sum_{m|n}{\chi_{d}(m)} = |I(d, n)|$ where $\chi_{d}$ is the Kronecker symbol mod $|d|$. All these facts tend to point out that there is a one-one correspondence between $R(d,n)$ and $I(d, n)$.
My question is that whether such a correspondence exists? If so could you explain this correspondence? Does this hold for $d > 0$ also?
 A: As explained below, there is a correspondence between non-zero locally principal ideals  $I$ in the order of disc. $D$ and quadratic forms $Q$ of disc. $D$.    The form $Q$ is naturally defined on  $I$ via $x \in I \mapsto N(x)/N(I).$  So $Q(x) = n$ iff $N(x) =  n  N(I)$ if $N(x I^{-1})  = n,$ so representations of $n$ by $Q$ correspond to ideals in the class
of $I^{-1}$ having norm $n$.
If we sum over all ideal classes, or equivalently over all $Q$, (and divide by the number of automorphisms of $Q$, which is the group of units in the order, to count ideals rather than elements that generate them) we will get the number of ideals of norm  $n$.
============
The discovery of this correspondence must go back  to the 19th century, maybe to Dirichlet or Dedekind?  And Will Jagy's answer gives a very concrete description of it.
One can also give a more conceptual description of it.  Indeed,
it is fairly easy, and classical, to describe the quadratic form attached to an ideal class in conceptual terms; I explain this at the end of my answer.  There is also a conceptual approach to going from quadratic forms to ideal classes, but as far as I know it is more recent, and due to Melanie Wood (a version  of it is mentioned in this answer).
Namely, if $Q(x,y)$ is a quadratic form over $\mathbb Z$ which is primitive, then one can consider $\mathrm{Proj} \mathbb Z[x,y]/Q(x,y)$, which turns out to be finite flat of degree $2$  over $\mathbb Z$, therefore affine, of the form $\mathrm{Spec} A$ for  some quadratic order $A$.  And in fact $A$ is isomorphic to $R[(D +\sqrt{D})/2]$, where $D$ is the discriminant of $Q$ (so $A$ is the quadratic order of discriminant $D$).    (There is no canonical identification of $A$ with this order though; we can compose with the automorphism $\sqrt{D} \mapsto -\sqrt{D}$ to get
another isomorphism.)
Now $\mathrm{Proj}$ comes with a canonical line bundle $\mathcal O(1)$,  and so this is an element of $\mathrm{Pic} A$, which can be thought of as the class group
of non-zero locally principal ideals in $A$.  (The usual class group when $D$ is a  fundamental discriminant.)
Using the isomorphism $A \cong R[(D +\sqrt{D})/2],$ we get an element of the
class group of $R[(D +\sqrt{D})/2],$ or really a pair $I,I^{-1}$ of elements,
because applying the automorphism $\sqrt{D} \mapsto -\sqrt{D}$ switches $I$
and it's inverse.
This gives a map
$$\text{ primitive quadratic forms } Q \text{ of discriminant } D
\longrightarrow \text{ pairs } I, I^{-1} \text{  in the class group of }
R[(D +\sqrt{D})/2].$$
To see it is a bijection, one can give an explicit inverse (as I mentioned above,
this is more classical):
If $I$ is a locally principal ideal in $R[(D +\sqrt{D})/2],$ then the formula
$$x \in I \mapsto N(x)/ N(I) \in \mathbb{Z}$$
defines  a quadratic form $Q$ on the free rank two $\mathbb{Z}$-module  $I$.  (Note that $I^{-1}$ will give the same quadratic form, since formation of norms is invariant under conjugation.)
A: We shall give an explicit correspondence between $R(d,n)$ and $I(d,n)$ based on the explicit correspondence between representatives $Q$ of proper equivalence classes of quadratic forms of discriminant $d$ and representatives $I$ of the narrow ideal class group of $\mathbb{Q}(\sqrt{d})$.
We recall that to each representative quadratic form $Q$, there exists a unique representative ideal $I$ and an oriented basis $(\omega_1,\omega_2)$ of $I$ such that
$$Q(r,s)=N(r\omega_1+\omega_2 s)/N(I).$$
Oriented basis means that $I=\mathbb{Z}\omega_1+\mathbb{Z}\omega_2$ and $\bar\omega_1\omega_2-\omega_1\bar\omega_2=N(I)\sqrt{d}$, where $\sqrt{d}$ is a fixed square-root of $d$ (independent of $I$). Now to each integral representation $Q(x,y)=n$, we associate the ideal $(x\omega_1+y\omega_2)/I$ of norm $n$. The range of this map is clearly $I(d,n)$. Moreover, two integral representations $Q(x,y)=n$ and $Q'(x',y')=n$ give rise to the same ideal if and only if $Q=Q'$ and $(x,y)$ only differs from $(x',y')$ by an automorph of $Q$. That is, our map induces a bijection between $R(d,n)$ and $I(d,n)$.
