\documentstyle{amsppt} \magnification=\magstephalf  \hsize=16.4true cm \vsize=23.3true cm
\nologo  \TagsOnRight \NoRunningHeads \parskip=4pt  \NoBlackBoxes
\def\Z{\Bbb Z}  \def\Q{\Bbb Q}  \def\R{\Bbb R}  \def\C{\Bbb C}  \def\z{\zeta} \def\H{\frak H} \def\M{\Cal M} \def\D{\Delta}
\def\G{\Gamma} \def\g{\gamma} \def\l{\lambda} \def\a{\alpha} \def\b{\beta} \def\t{\bold t} \def\abcd{\pmatrix a&b\\c&d\endpmatrix}
\def\d{\partial}   \def\SL{\operatorname{SL}_2(\Z)} \def\inv{^{-1}} \def\imply{\;\Rightarrow\;}  
\def\wJ{\widetilde J} \def\wphi{\widetilde\phi}
\def\mp{\!+\!} \def\mm{\!-\!} \def\bp{\,+\,} \def\bm{\,-\,} \def\O{\text O} \def\h{\frac12}  \def\={\,=\,}
\def\Qd{\Cal Q_d}  \def\sumG{\sum_{Q\in\Qd/\G}} \def\prodG{\prod_{Q\in\Qd/\G}} \def\Sd{\Cal S_d}
\def\Bo{1}
\def\Br{2}
\def\DN{3}
\def\EZ{4}
%\def\Fr{5}
%\def\GKZ{5}
\def\GZ{5}
\def\HM{6}
\def\HZ{7}
\def\Ka{8}
\def\Kb{9}
\def\Ko{10}
\def\Kob{11}
  % \def\Mo{13}
\def\Na{12}
  %  \def\No{9}
\def\Zc{13}
\def\Za{14}
\def\Zb{15}

\topmatter\title Traces of singular moduli \endtitle
\author Don Zagier\endauthor \endtopmatter 
\document

{\bf Introduction.}  ``Singular moduli" is the classical name for the values assumed
by the modular invariant $j(\tau)$ (or by other modular functions) when the argument
is a quadratic irrationality.  These values are algebraic
numbers and have been studied intensively since the time of Kronecker and Weber.
In [\GZ], formulas for their norms, and for the norms of their differences,
were obtained.  Here we obtain instead a result for their traces, and a number
of generalizations.  The results are closely related to a theorem of Borcherds [\Bo]
of which we will give a new proof and a generalization. 

The formula for the traces of the singular values of $j$ can be stated in two equivalent ways. The first one,
formulated in \S1, gives these traces as the Fourier coefficients of a certain modular form of weight 3/2.  The
second one, stated in \S2 and proved in \S\S3--4, gives them as the solutions of a certain pair of recursion
equations. The proof of one of the two recursions is a variant of the classical proof of the Kronecker class
number relations and is quite amusing.  

Borcherds's theorem is recalled in \S5 and the relationship
to our result is explained. In a few words, it is as follows.  There is a sequence of modular forms $f_d(\tau)$
of weight 1/2, one for each order in an imaginary quadratic field, and a sequence of modular forms $g_D(\tau)$ of 
weight 3/2, one for each order in a real quadratic field. Our formula says that the trace of a singular modulus 
of discriminant $-d$ is the coefficient of $q^d$ in the {\it fixed} modular form $-g_1(\tau)\,$; Borcherds's theorem 
implies that it is the coefficient of $q^1$ in the {\it variable} modular form $f_d\,$; and the relationship of 
the two results is that, for any $d$ and $D$, the $D$th Fourier coefficient 
of $f_d$ is the negative of the $d$th Fourier coefficient of $g_D$.  In fact, by a relatively
straightforward application of Hecke operators one can obtain the full statement of Borcherds's 
theorem (which describes the minimal polynomials of singular moduli, not just their traces, in
terms of the $n^2$-th Fourier coefficients of $f_d$ as $n$ varies) from the formula for the
traces. This is done in \S6.  

The third part of the paper describes generalizations in three
different directions: \S7 gives an interpretation of the {\it other} Fourier coefficients as traces
(roughly speaking, the $D$th Fourier coefficient of $f_d$, or the $d$th coefficient of $g_D$, 
describes the relative traces of singular moduli of discriminant $-dD$ from the Hilbert class field of
$\Q(\sqrt{-dD})$ to its real quadratic subfield $\Q(\sqrt D)\,$); in \S8 a generalization to the traces of singular
values of Hauptmodules for certain other groups of genus 0 is described (they are equal to the Fourier coefficients
of Jacobi forms of weight 2 and index $>\!1$); and in \S9 we state a generalization to modular forms of other small
half-integral weights (there are modular forms of weight $k+1/2$ and $3/2-k$
satisfying the same sort of duality relation as the $f_d$ and $g_D$, and their Fourier coefficients
again can be interpreted as traces, but now of singular values of certain {\it non}-holomorphic modular functions).
These results can be seen as analogues of the Shimura correspondence between modular forms of integral and half-integral weight.

We mention that the first results of this paper were found in 1994 and were quoted and applied in  the two papers 
[\Ka] and [\Kb] by Masanobu Kaneko, who used Theorem 1 to obtain a closed formula for the Fourier coefficients 
of $j(\tau)$ in terms of traces of singular moduli.


{\bf \S1. The trace of $j(\alpha)\,$.}
Throughout this paper, $d$ denotes a positive integer congruent to 0 or 3 modulo 4.  We denote by $\Qd$ the set of 
positive definite binary quadratic forms $Q=[a,b,c]=aX^2+bXY+cY^2$ ($a,\,b,\,c\in\Z$) of discriminant $b^2-4ac=-d$, with the usual
action of the modular group $\G=\text{PSL}(2,\Z)$. To each $Q\in\Qd$ we associate its unique root $\a_Q$ in $\H$ (= upper half-plane).
The value of $j(\a_Q)$ depends only on the $\G$-equivalence class of $Q$ and, as is well-known, is an algebraic integer. More precisely,
if $h(-d)$ denotes the class number of $-d$, i.e., the number of $\G$-equivalence classes of {\it primitive} quadratic forms in $\Qd$,
then each of the corresponding $h(-d)$ values of $j(\a_Q)$ is an algebraic integer of exact degree $h(-d)$ and they form a full set of
conjugates, so that the sum of these numbers is the trace.  For instance, we have $h(-3)=h(-4)=h(-7)=h(-8)=1$ and $h(-15)=2$,
and the corresponding $j$-values are
$$ \aligned & j\bigl(\frac{1+i\sqrt3}2\bigr)=0,\qquad j(i)=1728,\qquad j\bigl(\frac{1+i\sqrt7}2\bigr)=-3375,\qquad j(i\sqrt2)=8000,\\
&j\bigl(\frac{1+i\sqrt{15}}2\bigr)=\frac{-191025-85995\sqrt5}2,\qquad j\bigl(\frac{1+i\sqrt{15}}4\bigr)=\frac{-191025+85995\sqrt5}2\,.
\endaligned\tag1$$

We want to give a formula for the traces. Actually, it is convenient to make three small changes.  First, we 
replace the function $j$ by the  normalized Hauptmodul for $\G=\text{PSL}(2,\Z)$,
 $$ J(\tau)=j(\tau)-744=q\inv \bp 196884\,q\bp 21493760\,q^2\bp \cdots 
     \qquad(\tau\in\H,\;q=e^{2\pi i\tau}).\tag2$$
Secondly, we sum over {\it all} forms in $\Qd$, not just the primitive ones. Finally, we weight the number $J(\a_Q)$ by the
factor $1/w_Q$, where $w_Q=|\G_Q|$ (=2 or 3 if $Q$ is $\G$-equivalent to $[a,0,a]$ or $[a,a,a]$, and 1 otherwise). We therefore define
the {\it Hurwitz-Kronecker class numbers} $\,H(d)\,$ and the {\it modular trace function} $\,\t(d)\,$ by
   $$H(d) := \sumG\frac1{w_Q}\,,\qquad \t(d) := \sumG\frac1{w_Q}\,J(\a_Q)
      \qquad(d>0,\quad d\equiv0\text{ or }3\!\!\pmod 4)\,.$$
For instance, from the examples in (1) we see that $H(3)=\frac13$, $H(4)=\frac12$, $H(15)=2$ and
$$ \t(3)=\frac{0-744}3=-248,\quad\t(4)=\frac{1728-744}2=492,\quad \t(15)=-191025-2\cdot744=-192513\,.$$
Further values are given in the following small table. 
$$ \vbox{\tabskip=0pt \offinterlineskip
\halign{\strut \hfil#& \tabskip=1em plus 2em\hfill#&\vrule#&\hfill#&
\hfill#&\hfill#&\hfill#&\hfill#&\hfill#&\hfill#&\hfill#&\hfill#\tabskip=0pt\cr
&$d$&&3&4&7&8&11&12&15&16&19\cr \noalign{\vskip0pt}\multispan{12}\hrulefill\cr
&$H(d)\vphantom{|^{x^2}_2}$&&$1/3$&1/2&1&1&1&4/3&2&3/2&2\cr
    % &$H(d)\vphantom{|^{x^2}_{2_x}}$&&$\frac13$&$\frac12$&1&1&1&$\frac43$&2&$\frac32$&2\cr
&$\t(d)$&&$-248$&492&$-4119$&7256&$-33512$&53008&$-192513$&287244&$-885480$\cr}}  $$
$$ \vbox{\tabskip=0pt \offinterlineskip
\halign{\strut \hfil#& \tabskip=1em plus 2em\hfill#&\vrule#&\hfill#&
\hfill#&\hfill#&\hfill#&\hfill#&\hfill#&\hfill#\tabskip=0pt\cr
&$d$&&20&23&24&27&28&31&32\cr \noalign{\vskip0pt}\multispan{10}\hrulefill\cr
&$H(d)\vphantom{|^{x^2}_2}$&&$2$&3&2&4/3&2&3&2\cr
   % &$H(d)\vphantom{|^{x^2}_{2_x}}$&&$2$&3&2&$\frac43$&2&3&2\cr
&$\t(d)$&&1262512&$-3493982$&4833456&$-12288992$&16576512&$-39493539$&52255768\cr }}  $$ 
\medskip
On the other hand, we define a (meromorphic) modular form of weight 3/2 by the formula
  $$ g(\tau) := \theta_1(\tau)\,\frac{E_4(4\tau)}{\eta(4\tau)^6}\,=q\inv\bm 2\bp 248\,q^3\bm 492\,q^4\bp 4119\,q^7\bm7256\,q^8\bp\cdots\;.\tag3$$
where $\theta_1$, $E_4$ and $\eta$ are the classical modular forms
  $$\theta_1(\tau)=\sum_{n=-\infty}^\infty(-1)^nq^{n^2},\quad 
  E_4(\tau)=1+240\sum_{n=1}^\infty\frac{n^3\,q^n}{1-q^n}\,,\quad
  \eta(\tau)=q^{1/24}\,\prod_{n=1}^\infty\bigl(1-q^n\bigr)$$
of weights 1/2, 4, and 1/2, respectively.  
Comparing the first few coefficients of $g$ with the above table suggests the following ``modular" formula for the traces $\t(d)$ :
\proclaim{Theorem 1} Write the Fourier expansion of $g(\tau)$ as
$ g(\tau)=\sum_{d\ge-1}B(d)\,q^d\,.$ Then
  $$\t(d)=-B(d)\qquad(\forall d>0)\,.\tag4$$ \endproclaim
\noindent The proof of this result will occupy the next three sections.

\bigskip
{\bf \S2. A recursion for the numbers $\,\t(d)\,$.}  
Let $\theta(\tau)$ be the theta series $\sum_{n\in\Z}q^{n^2}$ and
 $U_4$ the operator $\sum c_nq^n\mapsto\sum c_{4n}q^n$. The fact that $g(\tau)$
is a modular form of weight 3/2 having non-zero Fourier coefficients only for $q^d$ with $d\equiv0$ or 3
modulo 4 (the so-called ``Kohnen plus-condition"; see \S5) implies that the function $(g\theta)|U_4$ is a
holomorphic modular form of weight 2 on the full modular group $\text{PSL}(2,\Z)$ and hence vanishes
identically.  Similarly, the image $[g,\theta]|U_4$ of the ``Cohen bracket" $[g,\theta](\tau)=g'(\tau)\theta(\tau)-3g(\tau)\theta'(\tau)$ under $U_4$  is a
holomorphic modular form of weight 4 on $\text{PSL}(2,\Z)$ and hence is a multiple of $E_4(\tau)$.
Writing these two facts out in terms of Fourier coefficients gives the two identities
$$ \sum_{r\in\Z}B(4n-r^2)=0\,,\qquad  \sum_{r>0}r^2\,B(4n-r^2)=240\sigma_3(n)\qquad(\forall n\ge0)\,,$$
where $\sigma_3(0)=1/240$ and $\sigma_3(n)$ for $n\ge1$ is the sum of the cubes of the positive divisors of $n$.  
These formulas can be rewritten
$$ B(4n-1)=240\sigma_3(n)-\!\!\sum_{2\le r\le\sqrt{4n+1}}r^2\,B(4n-r^2)\,,\qquad
B(4n)=-2\!\!\!\sum_{1\le r\le\sqrt{4n+1}}\,B(4n-r^2),$$
and in this form obviously determine all the $B(d)$ by recursion: $B(-1)=240\sigma_3(0)=1$,
$B(0)=-2B(-1)=-2$, $B(3)=240\sigma_3(1)-4B(0)=248$, $B(4)=-2B(3)-2B(0)=-492$, etc.  Thus to prove (4)
it suffices to prove the corresponding identities for $\t(d)$; i.e., Theorem 1 follows from:
\proclaim{Theorem 2} For all integers $n\ge1$ we have the identities
$$\sum_{|r|<2\sqrt n}\,\t(4n-r^2)\quad=\quad\cases -4&\text{\rm if $n$ is a square,}\\
   \phantom x2&\text{\rm if $4n+1$ is a square,}\\ \phantom x0&\text{\rm otherwise}\endcases\tag 5$$ and
$$ \sum_{1\le r<2\sqrt n}\,r^2\,\t(4n-r^2)\quad=\quad-240\sigma_3(n)+\cases \;-8n&\text{\rm if $n$ is a square,}\\
   4n+1&\text{\rm if $4n+1$ is a square,}\\ \phantom{xx}0&\text{\rm otherwise.}\endcases \tag6$$\endproclaim
The proofs of equations (5) and (6) are given in the next two sections and are rather pretty. In particular,
the proof of (5) is a refinement of the classical proof of Kronecker's class number relation
   $$\sum_{|r|<2\sqrt n}H(4n-r^2)=\sum_{d|n}\max\{d,\,n/d\}\; 
     +\cases 1/6&\text{if $n$ is a square,}\\ \phantom10&\text{otherwise.}\endcases\tag7$$

\smallskip
{\bf \S3. Proof of the first recursion for $\t(d)$.} In this section we prove equations (5) and~(7).
Let $\Phi_n(X,Y)\in\Z[X,Y]$ denote the well-known $n$th modular polynomial, defined by the property
$$ \Phi_n\bigl(X,\,j(\tau)\bigr)=\prod_{M\in\G\backslash\M_n}\bigl(X-j(M\circ\tau)\bigr)\qquad(\tau\in\H), \tag8$$
where $\M_n$ denotes the set of $2\times2$ integral matrices of determinant $n$, with $M$ and $-M$ being
identified, and $\circ$ denotes the usual action of $PGL^+(2,\R)$ on $\H$.  We exclude for the moment
the case when $n$ is a square.  Then observing that the function
$\Phi_n(j(\tau),j(\tau))$ vanishes exactly at the points $\tau\in\H$ which are fixed by
some $M\in\M_n$, and that these are just the points $\a_Q$ with $Q$ a positive definite quadratic form whose
discriminant has the form $r^2-4n$ for some integer $r$ ($=\text{tr}(M)$) satisfying $|r|<2\sqrt n$, 
we get the classical identity
$$ \Phi_n(X,X) = \text{const.}\times\prod_{|r|<2\sqrt n}\Cal H_{4n-r^2}(X)\,,\tag9$$  where
the constant factor (which is always $\pm1$ and is easily determined) does not matter to us and 
the function $\Cal H_d(X)$ is defined by
$$ \Cal H_d(X)=\prodG\!\bigl(X-j(\alpha_Q)\bigr)^{1/w_Q} 
 \qquad(d>0,\quad d\equiv0\text{ or }3\!\pmod 4)\,.\tag10$$
This function is $X^{1/3}$ times a polynomial in $X$ if $d/3$ is a square, $(X-1728)^{1/2}$ times a
polynomial in $X$ if $d$ is a square, and a polynomial in $X$ otherwise.  Clearly we have the $q$-expansion
$$\Cal H_d\bigl(j(\tau)\bigr)=  \prodG\!\bigl(q\inv-J(\alpha_Q)+\O(q)\bigr)^{1/w_Q}   =q^{-H(d)}\,\bigl(1-\t(d)\,q+\O(q^2)\bigr)\,.\tag11 $$
On the other hand, taking as representatives for $\G\backslash\M_n$ the matrices 
$\bigl(\smallmatrix a&b\\0&d\endsmallmatrix\bigr)$ with $ad=n$, $1\le b\le d$, we get
$$ \align\Phi_n\bigl(j(\tau),j(\tau)\bigr)
&=\prod_{ad=n}\prod_{b=1}^d\biggl(j\bigl(\tau\bigr)-j\bigl(\frac{a\tau+b}d\bigr)\biggr)\\
&=\prod_{ad=n}\prod_{b=1}^d\biggl(q\inv-e^{-2\pi ib/d}\,q^{-a/d} + \O\bigl(q^{>0}\bigr)\biggr)\\
&=\prod_{ad=n}\bigl(q^{-d} - q^{-a}\bigr)\bigl(1 + \O\bigl(q^{>1}\bigr)\bigr) \\
&=\prod_{ad=n}\pm q^{-\max\{a,d\}}\,\bigl(1\bm \varepsilon_a\,q\bp\O(q^2)\bigr)\,,  \endalign$$
where $\varepsilon_a$ is 1 if $|a-d|=1$ (which can happen only if $4n+1$ is a perfect square) and 0 otherwise. 
Comparing this with (9) and (11), we get both equations (5) and (7) for non-square $n$.

 If $n$ is a square, then $\Phi_n(X,Y)$ is divisible by $\Phi_1(X,Y)=X-Y$ and we must replace (9) by
$$\biggl.\frac{\Phi_n(X,Y)}{\Phi_1(X,Y)}\biggr|_{Y=X} 
= \text{const.}\times\prod_{|r|<2\sqrt n}\Cal H_{4n-r^2}(X)\,/\,\prod_{|r|<2}\Cal H_{4-r^2}(X)\,.$$
When we substitute $X=j(\tau)$, the left-hand side is $\pm q^A\bigl(1+\O(q^2)\bigr)$ by essentially the same 
calculation as before, but omitting the factor corresponding to $a=d=\sqrt n$, $b=0$. (Note that now $4n+1$ is 
not a square.)  Hence $\sum_{|r|<2\sqrt n}\t(4n-r^2)=\sum_{|r|<2}\t(4-r^2)=-4$.

\smallskip
{\bf \S4. Proof of the second recursion for $\t(d)$.}  The method used to prove (5) was essentially geometric: we
identified two different functions up to a constant by observing that they had the same divisors, and
then obtained the desired identity by computing the expansions of both expressions at infinity.  This
does not generalize directly to the higher weight identity (6), but does if we think of the logarithmic
derivatives of the previous functions as modular forms of weight 2 and replace these by modular forms
of higher weight. (One could state this geometrically by working on the Kuga variety over $\H/\G$,
or with appropriate local coefficient systems over $\H/\G$, but we will not do this.)  More
precisely, for each positive integer $d\equiv0$ or 3 (mod 4) we define
$$ \Lambda_d(\tau)=\frac d{d\tau}\log\Cal H_d(j(\tau))=\sumG\frac1{w_Q}\,\frac{j'(\tau)}{j(\tau)-j(\a_Q)}\,.$$
This is a meromorphic modular form of weight 2, holomorphic at infinity and with a simple pole of residue 
$1/|\G_\a|$ at each point $\a\in\H$ satisfying a quadratic equation over $\Z$ of discriminant $-d$, and 
is uniquely characterized by these properties since there are no holomorphic modular forms of weight 2 on $\G$.  
The analogue of the logarithmic derivative of equation (9) is then the following:
\proclaim{Proposition} Let $n$ be a positive integer which is not a square, $\tau\in\H$. Then
$$ \frac{E_4(\tau)E_6(\tau)}{\D(\tau)} \sum_{M\in\G\backslash\M_n}\frac{(E_4|M)(\tau)}{j(\tau)-j(M\tau)}
\,=\,\frac1{4\pi i}\sum_{|r|<2\sqrt n}(r^2-n)\,\Lambda_{4n-r^2}(\tau)\,,\tag12$$  
where $M\tau:=\dfrac{a\tau+b}{c\tau+d}$ and $(E_4|M)(\tau):=n^3(c\tau+d)^{-4}E_4(M\tau)$ for 
$M=\bigl(\smallmatrix a&b\\c&d\endsmallmatrix\bigr)\in\M_n$. \endproclaim
\demo{Proof} Both sides of the equality are meromorphic modular forms of weight 2, holomorphic at infinity,
and with only simple poles, so it suffices to compare the residues.  Let $\a\in\H$ be a fixed point of
the action of $M =\bigl(\smallmatrix a&b\\c&d\endsmallmatrix\bigr)\in\M_n$, where we can suppose that
$c>0$.  The number $\l=c\a+d$ is a quadratic algebraic integer of trace $r=\text{tr}(M)$ and norm $n$, and
$$\text{Res}_{\tau=\a}\biggl( \frac{E_4(\tau)E_6(\tau)}{\D(\tau)}\,
\frac{(E_4|M)(\tau)}{j(\tau)-j(M\tau)}\biggr) =\frac{E_4(\a)E_6(\a)}{\D(\a)}
\frac{n^3\l^{-4}E_4(\a)}{(1-n\l^{-2})j'(\a)}=\frac1{2\pi i}\frac{-\bar\l^3}{\l-\bar\l}\,.$$
(We leave to the reader the modifications necessary if $\a$ is a root of $E_4$ or $E_6$, i.e.~a point
with a non-trivial stabilizer in $\G$.)  By combining the matrices $M$ and 
$nM\inv=\bigl(\smallmatrix \phantom.d&-b\\-c&\phantom.a\endsmallmatrix\bigr)$, which have the same fixed points but
conjugate values of $\l$, we can replace the expression $-\bar\l^3/(\l-\bar\l)$ by $\h(\l^3-\bar\l^3)/(\l-\bar\l)=\h(r^2-n)$.
The proposition follows.  \enddemo

The rest of the proof is similar to the calculation in the last section.  Denote by $S_n(\tau)$ the expression
on the left-hand side of (12) and write its expansion at infinity as $C_0+C_1q+\cdots$. From (12) and the expansion 
$$  -\frac1{2\pi i}\Lambda_d(\tau) =\sumG\frac1{w_Q}\,\frac{q\inv+\O(q)}{q\inv-J(\a_Q)+\O(q)}= H(d)+\t(d)\,q+\O(q^2)\,,$$
we obtain
$$C_0=\h\sum_{|r|<2\sqrt n}(n-r^2)H(4n-r^2),\qquad C_1=\h\sum_{|r|<2\sqrt n}(n-r^2)\t(4n-r^2)\,.$$
On the other hand, again taking as a set of representatives for $\Gamma\backslash\M_n$ the matrices 
$\bigl(\smallmatrix a&b\\0&d\endsmallmatrix\bigr)$ with $0\le b<d$ and $ad=n$,
we find that $S_n(\tau)=\sum_{ad=n}a^3S_{a,d}(\tau)$ where
$$S_{a,d}(\tau)=\frac{E_4(\tau)E_6(\tau)}{\D(\tau)}\cdot\frac1d\sum_{0\le b<d}
\frac{E_4\bigl((a\tau+b)/d\bigr)}{j\bigl(\tau\bigr)-j\bigl((a\tau+b)/d\bigr)}\,.$$
If $a<d$, then we can calculate the $q$-expansion of $S_{a,d}(\tau)$ as
$$\align S_{a,d}(\tau)&=  \bigl(q\inv-240+\O(q)\bigr)\cdot\frac1d\sum_{\z^d=1}
\frac{1+240\,\z q^{a/d}+240\sigma_3(2)\,\z^2q^{2a/d}+\cdots}{q\inv-\z\inv q^{-a/d}+\O(q^{a/d})}\\
&=\sum\Sb l,\,m\ge0\\l\equiv m\!\pmod d\endSb 240\sigma_3(l)\,q^{m+a(l-m)/d}\,\bigl(1-240q+\O(q^2)\bigr)\\
&= 1\,+\,\bigl(240\,\delta_{a,1}\,\sigma_3(n)+\delta_{a,d-1}\bigr)\,q\,+\,\O(q^2),\endalign $$
since the only pairs $(l,m)$ which contribute to the powers $q^0$ and $q^1$ are (0,0), (1,1),
($d$,0) (if $a=1$) and (0,$d$) (if $a=d-1$). Similarly, for $a>d$ we find
$$\align S_{a,d}(\tau) &=\sum\Sb l\ge0,\,m\ge1\\l+m\equiv0\pmod d\endSb 240\sigma_3(l)\,q^{-m+a(l-m)/d}
  \,(1-240q+\O(q^2)\bigr)\,\\ &= \,-\delta_{a,d+1}\,q\,+\,\O(q^2)\,,\endalign $$
since this time only the pair $(l,m)=(0,d)$ contributes.  Summing over all divisors $a$ of $d$,
we find that the first two Fourier coefficients of $S_n(\tau)$ are given by 
$$ C_0=\sum\Sb 0<a<\sqrt n\\ a|n\endSb a^3\,,\qquad 
  C_1=240\sigma_3(n)-\cases3n+1&\text{if $4n+1=\square$,}\\\phantom{xx}0&\text{otherwise,}\endcases $$
where the last term comes from the two factorizations of $n$ as $ad$ with $a-d=\pm1$. Comparing the
formula for $C_1$ with the one given above, we obtain equation (6) (or more precisely, the difference
between 2 times equation (6) and $n$ times equation (5), but we have already proved (5)) for non-square $n$.
The proof when $n$ is a square is similar, except that we must also compute the Fourier expansion of
$S_{a,d}(\tau)$ in the case when $a=d$; we leave this calculation to the reader.  By comparing
the two expressions obtained for $C_0$ we also get the (well-known) identity 
  $$\sum_{|r|<2\sqrt n}(n-r^2)H(4n-r^2)=\sum_{d|n}\min(d,\,n/d)^3\; 
     -\cases n/2&\text{if $n$ is a square,}\\ \phantom10&\text{otherwise,}\endcases$$
which together with (7) recursively determines the Hurwitz-Kronecker class numbers $H(n)$.

\smallskip
{\bf \S5. Relation to Borcherds's theorem.}  
By equation (11), the Hurwitz-Kronecker class number $H(d)$ and the modified-trace-of-$j$ function $\t(d)$
can be interpreted as the first two Fourier coefficients of the logarithmic derivative of $\Cal H_d(j(\tau))$,
where $\Cal H_d(X)$ is the (nearly) polynomial function (10). Borcherds's theorem describes the
full Fourier expansion of  the logarithmic derivative of $\Cal H_d(j(\tau))$ in terms of certain Fourier
coefficients of a meromorphic modular form $f_d(\tau)$ of weight 1/2. In this section we state his result
and show how to deduce from it the formula for $\t(d)$ given in Theorem 1.  In \S6 we show how, conversely,
Borcherds's formula follows from Theorem~1 and some simple considerations about Hecke operators in integral
and half-integral weight, and in the following section we show how similar ideas can 
be used to identify the remaining Fourier coefficients of $f_d(\tau)$ in terms of traces of singular moduli.

To define the functions $f_d(\tau)$, we need some basic facts from the theory of modular forms of
half-integral weight.  For any integer $k$, denote by $M_{k+1/2}(\G_0(4))$ the space of functions which are
holomorphic in $\H$ and at the cusps and which transform under the action of $\G_0(4)$ like $\theta(\tau)^{2k+1}$,
where $\theta(\tau)$ is the Jacobi theta-function $\sum_nq^{n^2}$ already used in \S2. The ``Kohnen plus-space" 
is the subspace consisting of functions whose Fourier expansion at infinity has the form $\sum c(n)q^n$ where
$c(n)$ is non-zero only for integers $n$ satisfying $(-1)^kn\equiv0$ or 1 modulo 4.  We will denote this
space simply by $M_{k+1/2}$, and consider its elements to be modular forms ``of level one," because of
Kohnen's basic result that $M_{k+1/2}$ is isomorphic as a Hecke module to the space $M_{2k}=M_{2k}(\G)$ 
of holomorphic modular forms of weight $2k$ on the full modular group.  (The definition of the action
of the Hecke algebra on $M_{k+1/2}$ will be recalled in the next section.) 

From the isomorphism $M_{k+1/2}\approx M_{2k}$, or directly, we see that the space $M_{k+1/2}$
is one-dimensional (spanned by $\theta$ itself) for $k=0$ and is zero for $k=1$ or $k<0$.
To get non-trivial spaces in these low half-integral weights, we have to allow modular forms with poles.  Let 
$M_{k+1/2}^!(\G_0(4))$ be defined like $M_{k+1/2}(\G_0(4))$ but with the condition ``holomorphic at the
cusps" relaxed to ``meromorphic at the cusps" (Borcherds [\Bo] calls such forms ``nearly holomorphic") 
 and define a ``plus-subspace" $M_{k+1/2}^!$ of it by the
same condition on the Fourier coefficients as before (where now $c(n)$ may be non-zero for a finite number
of negative values of $n$).  Equivalently, a function $f(\tau)$ belongs to $M_{k+1/2}^!$ if and only if
$f(\tau)\D(4\tau)^n$ belongs to $M_{k+12n+1/2}$ for some integer $n>0$. The space $M^!_{k+1/2}$ is infinite-dimensional 
for every $k$. In particular, for every integer $d\ge0$ with $d\equiv0,\,3\pmod4$ there
is a unique modular form $f_d\in M_{1/2}^!$ having a Fourier development of the form
$$f_d(\tau)=q^{-d}+\sum_{D>0}A(D,d)\,q^D\,,\tag13$$
and the functions $f_0$, $f_3$, $f_4$, $f_7$, \dots form a basis of $M_{1/2}^!$. The existence and uniqueness of the
forms $f_d$ (=Lemma 14.2 of [\Bo]) are easy to see.  Indeed, the uniqueness is clear since
the difference of any two functions satisfying the definition of $f_d$ would be an element of $M_{1/2}$
with constant term 0 and hence would vanish.  For the existence, we first construct $f_0$ and $f_3$ ``by hand" 
($f_0(\tau)$ is just $\theta(\tau)$ itself, and a non-trivial linear combination of $f_3$ and $f_0$ can be 
obtained e.g.~as $[\theta(\tau),\,E_{10}(4\tau)]/\D(4\tau)$, where $E_{10}(\tau)=E_4(\tau)E_6(\tau)$
is the Eisenstein series of weight 10 on $\G$ and $[\theta(\tau),\,E_{10}(4\tau)]
=\theta(\tau)E_{10}'(4\tau)-5\theta'(\tau)E_{10}(4\tau)$ the Cohen bracket of $\theta(\tau)$ and 
$E_{10}(4\tau)$). Then for each $d\ge4$ we obtain $f_d(\tau)$ by multiplying $f_{d-4}(\tau)$ by
$j(4\tau)$ to get a ``plus"-form of weight 1/2 with leading coefficient $q^{-d}$ and then subtracting off
multiples of $f_{d'}$  to successively kill the coefficients of $q^{-d'}$ for $0\le d'<d$. The process is
effective and we find, for instance, that the Fourier expansions of the first few  $f_d$ begin as follows:
$$\align f_0 &= 1 \bp 2q \bp 2q^4 \bp 2q^9 \bp 2q^{16} \bp \O(q^{25}), \\
f_3 &= q^{-3} - 248q + 26752q^4 - 85995q^5 + 1707264q^8 - 4096248q^9 + \O(q^{12}), \\
f_4 &= q^{-4} + 492q + 143376q^4 + 565760q^5 + 18473000q^8 + 51180012q^9 + \O(q^{12}), \\
f_7 &= q^{-7} - 4119q + 8288256q^4 - 52756480q^5 +5734772736q^8+ \O(q^9), \\
f_8 &= q^{-8} + 7256q + 26124256q^4 + 190356480q^5 +29071392966q^8+ \O(q^9), \\
f_{11}&= q^{-11} - 33512q +561346944q^4-5874905295q^5 +2225561184000q^8+ \O(q^9)\,.  \endalign $$


\proclaim{Theorem 3 (Borcherds {\rm [Bo, p.~204]})} Let $d>0$, $d\equiv0$ or $3\!\pmod 4$. Then
$$\Cal H_d\bigl(j(\tau)\bigr)=q^{-H(d)}\,\prod_{n=1}^\infty\bigl(1-q^n\bigr)^{A(n^2\!,d)}\,.\tag 14$$  \endproclaim
\noindent{\bf Example.} From equation (14) for $d=3$ and the above expansion of $f_3$ we find
 $$ j(\tau)^{1/3} \=q^{-1/3}\,(1-q)^{-248}\,(1-q^2)^{26752}\,(1-q^3)^{-4096248}\,\cdots\;.$$

Comparing equation (14) with (11), we obtain :
\proclaim{Corollary} $\t(d)=A(1,d)$ for all $d>0$.\endproclaim
This corollary and Theorem 1 give two apparently different ways to calculate $\t(d)$: Theorem 1 gives all of the
$\t(d)$ as the Fourier coefficients of a single modular form $g(\tau)$ of weight 3/2, while the Corollary gives each
$\t(d)$ as a coefficient of a different modular form $f_d$ of weight 1/2.  To see how the two formulas are related, 
we define a second sequence of modular forms, analogous to the $f_d$ but now in weight 3/2 rather than 1/2, namely 
for each positive integer $D$ congruent to 0 or 1 modulo 4 we define $g_D(\tau)$ as the unique form in $M_{3/2}^!$ 
having a Fourier expansion of the form
 $$g_D(\tau)=q^{-D}+\sum_{d\ge0}B(D,d)\,q^d\,.\tag15$$
For $D=1$ this is just the function $g(\tau)$ defined in (3), so $B(1,d)$ is the same as the coefficient which was
denoted $B(d)$ in \S2.   We can construct $g_4$ either by applying the weight 3/2
Hecke operator $T(2)$ to $g_1$ (cf.~\S6) or in the same way as $f_3$ was constructed from $f_0$ ($[g_1(\tau),E_{10}(\tau)]
/\Delta(4\tau)\,$ is a linear combination of $g_1(\tau)$, $g_4(\tau)$, and $g_1(\tau)j(4\tau)\,$),
  %  We can then construct $g_4$ from $g_1$ the same way that $f_3$ was constructed from $f_0$, 
and then get the forms $g_D(\tau)$ for $D>4$ inductively by multiplying $g_{D-4}(\tau)$ by $j(4\tau)$ and
subtracting a suitable linear combination of $g_{D'}(\tau)$ with $D'<D$; and the uniqueness of the $g_D$ follows 
from the fact that $M_{3/2}=\{0\}$. Here are the beginnings of the Fourier developments of the first few $g_D$:
$$\align g_1 &= q\inv-2+248q^3-492q^4+4119q^7-7256q^8+33512q^{11}-53008q^{12}+\O(q^{15}), \\
g_4 &= q^{-4} - 2 - 26752q^3 - 143376q^4 - 8288256q^7 - 26124256q^8 + \O(q^{11}), \\
g_5 &= q^{-5} +0+ 85995q^3 - 565760q^4 + 52756480q^7 - 190356480q^8 + \O(q^{11}), \\
g_8 &= q^{-8}+0 - 1707264q^3 - 18473000q^4 - 5734772736 q^7 - 29071392966q^8+\O(q^{11}), \\
g_9 &= q^{-9} - 2 + 4096248q^3 - 51180012q^4 +22505066244q^7 -125891591256q^8 + \O(q^{11})\,.\endalign $$
Comparing these expansions with those of the $f_d$ given above, we notice that the coefficients occurring
are the same up to sign. The next theorem, which by virtue of the above corollary reduces to (4) for $D=1$, says that this is true in general.
\proclaim{Theorem 4} $A(D,d)=-B(D,d)$ for all $D$ and $d$.\endproclaim
\demo{Proof}  Consider the function 
$$F(\tau_1,\,\tau_2)=\frac{f_0(\tau_1)g_4(\tau_2)+f_3(\tau_1)\,g_1(\tau_2)}{j(4\tau_2)-j(4\tau_1)}
   \qquad(\tau_1,\,\tau_2\in\H)\,.$$
It is meromorphic, with a simple pole whenever $4\tau_1$ and $4\tau_2$ are $\G$-equivalent.
If $\Im(\tau_1)$ and $\Im(\tau_2)$ are big enough (to be precise, bigger than 1/4), then this is the case
if and only if $4\tau_1$ and $4\tau_2$ differ by an integer.  On the other hand, we can easily check that
   $$f_0\bigl(\tau+\frac n4\bigr)\,g_4(\tau)+f_3\bigl(\tau+\frac n4\bigr)\,g_1(\tau)
     =-\frac{1+i^n}{2\pi i}\,j'(4\tau)\qquad(n=0,\,1,\,2,\,3),$$
so the residue of $F$ (with respect to $\tau_1$, keeping $\tau_2$ fixed) at $\tau_1=\tau_2+n/4$ ($n\in\Z$)
equals $(1+i^n)/8\pi i$.  This is the same as the residue of the elementary function 
$F_0(\tau_1,\tau_2)=(q_1^4+q_1q_2^3)/(q_1^4-q_2^4)$, where $q_j=e^{2\pi i\tau_j}$,
so $F-F_0$ is a holomorphic function of $(q_1,q_2)$ in a neighbourhood of $(0,0)\in\C^2$, i.e.
  $$ F(\tau_1,\,\tau_2)=\frac{q_1^4+q_1q_2^3}{q_1^4-q_2^4}\,+\sum_{D>0,\,d\ge0}C(D,d)\,q_1^D\,q_2^d$$
in this neighbourhood for some coefficients $C(D,d)$.  Here we can write $D>0$ rather than $D\ge0$ in the summation
because both $F$ and $F_0$ obviously vanish on the $q_2$-axis; moreover, it is clear that $C(D,d)$ is 0
unless $D$ and $d$ satisfy the usual congruences $D\equiv 0,\,1\!\pmod4$, $d\equiv 0,\,3\!\pmod4$.
Expanding $F_0$ in a geometric series in
the region $|q_2|<|q_1|$, we find that the Taylor expansion of $F$ with respect to $\tau_2$ is given by
  $$  F(\tau_1,\,\tau_2)= \sum\Sb d\ge0\\d\equiv 0,\,3\!\pmod4\endSb \biggl(q_1^{-d}+
  \sum\Sb D>0\\D\equiv 0,\,1\!\pmod4\endSb C(D,d)\,q_1^D\biggr)\,q_2^d\qquad(\tau_1\in\H,\;\Im(\tau_2)\to\infty).$$
Since $F$ is a (plus-)modular form of weight 1/2 with respect to $\tau_1$, the expression in parentheses also
is one, so it equals $f_d(\tau_1)$. Hence $C(D,d)=A(D,d)$.  Similarly, from the expansion
$$  F(\tau_1,\,\tau_2)= \sum\Sb D>0\\D\equiv 0,\,1\!\pmod4\endSb \biggl(-q_2^{-D}+
 \sum\Sb d\ge0\\d\equiv 0,\,3\!\pmod4\endSb C(D,d)\,q_2^d\biggr)\,q_1^D\qquad(\tau_2\in\H,\;\Im(\tau_1)\to\infty)$$
and the fact that $F$ is a (plus-)modular form of weight 3/2 with respect to $\tau_2$ we deduce that $C(D,d)=-B(D,d)$.
This completes the proof.\enddemo
Notice that the Fourier expansions of $F$ just given also yield formulas for all $f_d(\tau)$ ($d\ge0$) as linear
combinations of $f_0(\tau)$ and $f_3(\tau)$ with coefficients in $\Q[j(4\tau)]$, namely
$$ f_d(\tau)=\sum_{n=0}^{[d/4]}\text{Coeff}_{q^d}\biggl(\frac{g_4(\tau)}{j(4\tau)^{n+1}}\!\biggr)\,j(4\tau)^nf_0(\tau)
\;+\sum_{n=0}^{[(d-3)/4]}\text{Coeff}_{q^d}\biggl(\frac{g_1(\tau)}{j(4\tau)^{n+1}}\!\biggr)\,j(4\tau)^nf_3(\tau)\,,$$
and similarly for all $g_D(\tau)$ ($D>0$) as linear combinations over $\Q[j(4\tau)]$ of $g_1(\tau)$ and $g_4(\tau)$.

{\bf Remark.} As Masanobu Kaneko has pointed out to me, there is an easier proof of Theorem~4. It
is easily checked that the constant term of the $q$-expansion of $fg$ vanishes for any $f\in M_{1/2}^!$ and $g\in M_{3/2}^!$
(because $fg|U_4$ is a modular form of weight 2 on $SL_2(\Z)$ with a pole only at infinity, and every such form is the 
derivative of a polynomial in $j$).  Applying this to $f=f_d$, $g=g_D$ immediately gives the assertion.  We have retained the
original proof because of the supplementary information it gives about the functions $f_d$ and $g_D$.

\smallskip
{\bf \S6. Hecke operators.}  Theorems 1 and 4 together clearly imply the corollary to Borcherds's theorem,
since one has $\t(d)=-B(1,d)=A(1,d)$.  In fact, they imply the full theorem in a more or less straightforward
way, as we now explain.

To obtain the full minimal polynomial $\Cal H_d(X)$ of the algebraic number $j(\alpha_Q)$, we need not just its
trace but also the traces of all of its powers (or at least of all of its powers up to the class number).
Instead of working with the traces of $j$ (or of $J$), we work with the functions $J_m$, defined for every
integer $m\ge0$ as the unique holomorphic function on $\H/\G$ with a Fourier expansion beginning $\,q^{-m}+\O(q)\,$.
For $m=0$ this is the constant function 1 and for $m=1$ it is the function $J(\tau)$ defined in (2), 
while the next three values have Fourier developments starting
  $$\align J_2(\tau)\,&=\,q^{-2} + 42987520\,q + 40491909396\,q^2 + 8504046600192\,q^3 + \cdots\,,\\
 J_3(\tau)\,&=\, q^{-3} + 2592899910\,q + 12756069900288\,q^2 + 9529320689550144\,q^3 + \cdots\,,\\
 J_4(\tau)\,&=\, q^{-4} +80983425024\,q +1605963589611520\,q^2 +3497254878743101440\,q^3 + \cdots\,.\endalign $$
The uniqueness of these functions is obvious (the difference of any two functions satisfying the definition of $J_m$
would be a holomorphic cusp form of weight 0 and hence 0) and the existence also, since $J_m$ can clearly be
obtained as a monic polynomial of degree $m$ in $j(\tau)$, e.g.
$$\align J_2(\tau)\,&=\,j(\tau)^2-1488\,j(\tau)+159768\,,\\
 J_3(\tau)\,&=\,j(\tau)^3-2232\,j(\tau)^2+1069956\,j(\tau)-36866976\,,\\
 J_4(\tau)\,&=\,j(\tau)^4-2976\,j(\tau)^3+2533680\,j(\tau)^2-561444608\,j(\tau)+8507424792\,.\endalign $$

The minimal polynomials of all $j(\alpha_Q)$ are then determined if we know the numbers
  $$ \t_m(d) := \sumG\frac1{w_Q}\,J_m(\a_Q)  \tag16$$
for all $d$ and all $m\ge1$ (or even just for $0\le m\le H(d)$). To get them, 
we must generalize Theorems 1 and 4 to include Hecke operators.  For any integer $m\ge1$ 
let $A_m(D,d)$ and $B_m(D,d)$ denote the coefficient of $q^D$ in $f_d|_\h T(m)$ and the 
coefficient of $q^d$ in $g_D|_{\frac32}T(m)$, respectively, where $\,|_\h T(m)$ and
 $\,|_{\frac32}T(m)$ denote the action of the $m$th Hecke
operator $T(m)$ (sometimes denoted $T(m^2)$ or $T^+(m^2)$) on the space $M_k^!\,$, $k=1/2$ or 3/2.
The formulas for this action (at least for holomorphic modular forms, but nothing changes
if we allow the pole at infinity) are given in many places, e.g. [\Ko], Prop.~2 or, in the equivalent
language of Jacobi forms, [\EZ], Th.~4.5.  In particular, for $m=p$ prime we have
 $$A_p(D,d) =  p\,A(p^2D,\,d)\bp\bigl(\frac Dp\bigr)\,A(D,\,d)\bp A(p^{-2}D,\,d) \tag 17$$  
and
 $$B_p(D,d) = B(D,p^2d)\bp\bigl(\frac{-d}p\bigr)\,B(D,\,d)\bp p\,B(D,\,p^{-2}d) \tag 18$$ 
(with the convention that $A(p^{-2}D,d)=0$ unless $p^{-2}D$ is an integer congruent to
0 or 1 modulo~4, and similarly for $B(D,p^{-2}d)\,$), while for $D=1$ and $m$ arbitrary we have
 $$A_m(1,d)=\sum_{n|m} n\,A(n^2,\,d)\,.\tag 19$$
\proclaim{Theorem 5} With the above notations, we have
\smallskip $\;($i$)$ $\quad\Cal H_d\bigl(j(\tau)\bigr)=q^{-H(d)}\,\exp\bigl(-\sum\limits_{m=1}^\infty \t_m(d)\,\dfrac{q^m}m\bigr)\quad$ 
for all $\;d\,$;
\smallskip $\,($ii$)$ $\quad\t_m(d)=-B_m(1,d)\quad $ for all $\;m\,$ and $\,d\,$;
\smallskip $($iii$)$ $\;\, A_m(D,d)=-B_m(D,d)\quad $ for all $\;m$, $\,D\,$ and $\,d\,$.
\endproclaim 
\noindent Note that parts (ii) and (iii) of this theorem are the generalizations of Theorems 1 and 4 to $m\ge1$, while Theorem 3 
is obtained by combining (i), (ii), the case $D=1$ of (iii), and equation (19).
\demo{Proof} (i) This identity follows directly from the definitions (10) and (16) of $\Cal H_d(\tau)$ and $\t_m(d)$ together
with the identity
$$ j(\tau)-j(z) \;=\; q\inv\,\exp\biggl(-\sum_{m=1}^\infty J_m(z)\,\frac{q^m}m\biggr)
\quad\qquad\bigl(q=e^{2\pi i\tau},\;\,\Im(\tau)\gg0)\,,\tag20$$
an identity which has been discovered independently by a number of authors   %   (see e.g.~[\Bo], p.~?? or [\No], p.??)
 and which can be proved easily
by noting that the logarithmic derivative with respect to $\tau$ of either side is, for fixed $\tau$ with sufficiently large
imaginary part, a $\G$-invariant meromorphic function of $z$ whose only pole in the standard fundamental domain is a simple one
of residue~1 at $z=\tau$ and which vanishes at infinity.

(ii) We first observe that the function $J_m$ is the composite of $J$ with the $m$th Hecke operator $T(m)$ acting in
degree~0, i.e., $J_m(\tau)$ is the sum of $J(M(\tau))$ with $M$ ranging over $\G\backslash\M_n$.  (This is obvious, since $J_1|_0T(m)$
is a modular function with a pole $q^{-m}+\O(q)$ at infinity and no other poles.)  It follows that $\t_m(d)$ is
the sum of the values of $J_1(\a)$ summed over all $\a\in\Sd|T(m)$, where $\Sd\subset\H/\G$ is the set of $\a_Q$,
$Q\in\Qd/\G$ (counted with multiplicity $1/q_Q$).   But $\Sd|T(m)$ is a combination of sets $\Cal S_{dm^2/n^2}$ with $n$ ranging
over the divisors of $m$. For example, $\Sd|T(p)$ for $p$ prime is equal to $\Cal S_{dp^2}+\bigl(\dfrac{-d}p\bigr)\Sd
+p\Cal S_{d/p^2}$.  (The proof of this is an exercise, carried out, e.g., on pages 290--292 of [\Zb].)  Assertion (ii) for
$m=p$ then follows from Theorem~1 and equation (18).  The general case can be proved similarly, or one can use the 
multiplicative properties of Hecke operators (which are the same in integral and half-integral weight) and induction
on the number of prime factors of $m$.

(iii) Again we need only consider the case when $m=p$ is prime.  Formula (17) for the Fourier coefficients of $f_d|_{\frac12}T(p)$
is true for all $D$, negative as well as positive, so from the defining property $A(D,d)=\delta_{D,-d}$ ($D<0$) of $f_d$ we
deduce that $A_p(D,d)=p\delta_{D,-d/p^2}+\bigl(\dfrac{-d}p\bigr)\delta_{D,-d}+\delta_{D,-dp^2}$ for $D<0$, i.e., the
principal part of  $f_d|_{\frac12}T(p)$ at infinity is $pq^{-d/p^2}+\bigl(\dfrac{-d}p\bigr)q^{-d}+q^{-dp^2}$ (with the first
term to be omitted unless $-d/p^2$ is a discriminant).  It follows that $f_d|_{\frac12}T(p)$ equals
$pf_{d/p^2}+\bigl(\dfrac{-d}p\bigr)f_d+f_{dp^2}$ and hence that its $D$th Fourier coefficient $A_p(D,d)$ is equal to
$\,pA(D,d/p^2)+\bigl(\dfrac{-d}p\bigr)A(D,d)+A(D,dp^2)$.  Comparing with (18), we find that (iii) follows from Theorem~4. One
could also give a dual proof by using (18) to show that $g_D|_{\frac32}T(p)=pg_{Dp^2}+\bigl(\dfrac Dp\bigr)g_D+g_{D/p^2}$,
and there is yet a third proof along the lines of the proof given for the special case Theorem~4 by looking at the singular part at
infinity of the images of the two-variable modular form $F(\tau_1,\tau_2)$ under the actions of $T(p)$ on $\tau_1$ (in weight $1/2$)
and $\tau_2$ (in weight $3/2$). 
\enddemo
This completes the proof of Theorem~5 and of Borcherds's product formula (14) from our more elementary formula~(4).
In the remaining sections of the paper we describe without detailed proofs generalizations of these results in
various different directions.

\bigskip
{\bf \S7. First generalization: other discriminants.}  The theorems we have discussed so far give an interpretation 
of the numbers $A_m(D,d)=-B_m(D,d)$ as traces when $D$ is equal to 1 or, more generally, whenever $D$ is a perfect square.  
Is there  a similar interpretation for the other values?

The answer is yes, but now we have to take ``twisted" traces in which the conjugates of $j(\alpha_Q)$ are
multiplied by a genus character before summing.  We recall the definition of these characters.  Let
$D$ and $-d$ be a positive and a negative discriminant, respectively. For ease of exposition we suppose them to
be fundamental and coprime. (Comments on other situations are given in Remark~3 below.)
Then the genus character $\chi=\chi_{D,-d}$ assigns to any quadratic form $Q$ of discriminant $-dD$ a value $\pm1$
defined by $\chi(Q)=\bigl(\frac Dp\bigr)=\bigl(\frac{-d}p\bigr)$ where $p$ is any prime represented by $Q$ 
and not dividing $Dd$. (This is independent of the choice of $p$.) 
\proclaim{Theorem 6} Let $D>1$ and $-d<0$ be coprime fundamental discriminants, and $\chi=\chi_{D,-d}$ 
the associated genus character. Then
$$  A(D,d) \= \frac1{\sqrt D}\sum_{Q\in\Cal Q_{dD}/\G} \chi(Q)\,j(\a_Q)\,. \tag21$$ \endproclaim
\noindent{\bf Example.} Take $D=5$, $d=3$, the first non-trivial case. There are two $\G$-equivalence classes of
quadratic forms of discriminant $-15$, represented by the forms
$Q_1=[1,1,4]$ and $Q_2=[2,1,2]$ with $\chi(Q_1)~=~1$, $\chi(Q_2)=-1$. The corresponding values of $j(\a_Q)$ are
given in~(1). We see that the right-hand side of (21) is $\bigl(j(\a_{Q_1})-j(\a_{Q_2})\bigr)/\sqrt5=-85995$, in agreement with
the value $A(5,3)=-B(5,3)=-85995$ given in~\S5.

\noindent{\bf Remarks. 1.} In formula (21) we could omit the usual factor $w_Q\inv$ because it is always 1 for $D$ 
and $d$ as in the theorem, and similarly we could write $j(\a_Q)$ rather than $J(\a_Q)$ because summing with
the non-trivial character $\chi$ kills the additive constant by which $j$ and $J$ differ.

\noindent{\bf 2.} The right-hand side of (21) is {\it a priori} a rational integer.  Indeed, the sum of $j(\a_Q)$
as $Q$ ranges over the forms with $\chi(Q)=+1$ is, by class field theory, the trace of the algebraic integer
$j(\a_Q)$ from the Hilbert class field of $\Q(\sqrt{-dD})$ to its real quadratic subfield $\Q(\sqrt D)$. If
we write this number as $\l=\h(a+b\sqrt D)$ with $a$ and $b$ in $\Z$, then the sum over {\it all}
$j(\a_Q)$ is equal to $\,\text{Tr}_{\Q(\sqrt D)/\Q}(\l)=a$ and therefore the weighted sum $\sum \chi(Q)j(\a_Q)$
is equal to $-a+2\l=b\sqrt D$. 

\noindent{\bf 3.}  If $D$ and $d$ are not coprime, then the statement of the theorem is unaltered but $\chi(Q)$ must be
defined as 0 for imprimitive forms $Q$ which are divisible by some prime dividing both $D$ and $d$.
Thus for instance the values $A(8,4)=18473000$ and $A(5,15)=-292658282496$ are obtained as
$(j(\a_{[1,0,8]})-j(\a_{[3,2,3]}))/\sqrt8$ and 
$(j(\a_{[1,1,19]})-j(\a_{[3,3,7]}))/\sqrt5$, respectively. The cases when $D$ and $d$ are
not assumed to be fundamental can be given by a suitable modification of (21) (the reader can find the
right formulas easily by a little numerical experimentation) or can be obtained from the case of
fundamental discriminants by suitable applications of Hecke operators. 

We can also give a generalization of the Borcherds product expansion~(14), but with a difference.  For
$D$ and $d$ as in the theorem we define a rational function $\Cal H_{D,d}(X)$ by
$$ \Cal H_{D,d}(X)=\prod_{Q\in\Cal Q_{Dd}/\G}\!\bigl(X-j(\alpha_Q)\bigr)^{\chi(Q)} \,.\tag22$$
For the same reasons as in Remark 2, this belongs to $\Q(\sqrt D)(X)$ and is mapped by the non-trivial 
element of $\,\text{Gal}(\Q(\sqrt D)/\Q)\,$ to its inverse.  It follows that the power series expansion
of $\,\log\Cal H_{D,d}(j(\tau))$, which begins with 1, has a logarithm belonging to $\sqrt D\,\Q[[q]].$
\proclaim{Theorem 7} Let $D$, $d$ and $\Cal H_{D,d}(X)$ be as above.  Then
$$ \Cal H_{D,d}\bigl(j(\tau)\bigr) \=\prod_{n=1}^\infty P_D(q^n)^{A(n^2D,d)} \tag 23$$
where 
$$ P_D(t)\;:=\;\exp\biggl(-\sqrt D\;\sum_{r=1}^\infty\,\bigl(\frac Dr\bigr)\,\frac{t^r}r\biggr)\quad\in\,\Q(\sqrt D)[[t]]\,.\tag 24$$
The function $P_d(t)$ is a rational function of $t$ with coefficients in $\Q(\sqrt D)$.
\endproclaim
\noindent{\bf Examples.}
For $D=1$ we clearly have $P_1(t)=1-t$, so that (24) reduces to (14) in this case.  The next values of $P_D$ are
$$P_5(t)=\dfrac{1-\phi\,t+t^2}{1-\phi't+t^2}\,,\qquad P_8(t)=\dfrac{1-\sqrt2\,t+t^2}{1+\sqrt2\,t+t^2}\,,
\qquad P_{12}(t)=\dfrac{1-\sqrt3\,t+t^2}{1+\sqrt3\,t+t^2}\,,$$
where $\phi=(1+\sqrt5)/2$ is the golden ratio and $\phi'=(1-\sqrt5)/2$ its Galois conjugate.
A typical example of the theorem ($D=8$, $d=3$) is the expansion 
$$\frac{j(\tau)-2417472-1707264\sqrt2}{j(\tau)-2417472+1707264\sqrt2}
  \=\prod_{n=1}^\infty\biggl(\frac{1-\sqrt2 q^n+q^{2n}}{1+\sqrt2\,q^n+q^{2n}}\biggr)^{A(8n^2\!,\,3)}$$
of the ratio of $j(\tau)-j(\sqrt{-6})$ and $j(\tau)-j(\sqrt{-3/2})$, whereas Borcherds's product
expansion (14) would give the Fourier expansion of the product of the same two expressions in the form
$$ j(\tau)^2-4834944\,j(\tau)+14670139392 \=q^2\,\prod_{n=1}^\infty\bigl(1-q^n\bigr)^{A(n^2\!,\,24)}\,,$$

% We now say something about the proofs of these two theorems.
Theorem~7 follows from Theorem~6 in the same way as explained in \S6 for the special case $D=1$.  If we 
denote by $\t(D,d)$ the sum occurring in the right-hand side of (21) (``twisted trace") and by $\t_m(D,d)$ the corresponding sum with $j$ replaced by $J_m$, then we can use Hecke operators in integral and half-integral
weight to show that (21) generalizes to  
$$ \t_m(D,d))\=A_m(D,d)\,\sqrt D\qquad\qquad\text{for all $m$, $D$ and $d$}\,.\tag25$$
From equations (20) and (25) we find 
$$ \Cal H_{D,d}\bigl(j(\tau)\bigr)\=\exp\biggl(-\sum_{m=1}^\infty\t_m(D,d)\,\frac{q^m}m\biggr) 
 \=\exp\biggl(-\sqrt D\,\sum_{m=1}^\infty A_m(D,d)\,\frac{q^m}m\biggr) \,,$$
and combining this with the formula
 $$A_m(D,d)=\sum_{n|m} n\,\bigl(\frac D{m/n}\bigr)\,A(n^2D,\,d)\,,$$
which is the generalization of (19) to fundamental discriminants $D>1$, gives (23). 
For the final statement of Theorem 7 we use the Gauss sum identity 
$\,\sqrt D\,\bigl(\dfrac Dr\bigr)=\sum\limits_{0<n<D}\bigl(\dfrac Dn\bigr)\,e^{2\pi inr/D}\,$ to get
$$ P_D(t)\=\prod_{0<n<D}\bigl(1\,-\,\z_D^n\,t\bigr)^{(\frac Dn)}
 \= \frac{\text N_{\Q(\z_D)/\Q(\sqrt D)}\bigl(1-\z_Dt\bigr)^2}{\text N_{\Q(\z_D)/\Q}\bigl(1-\z_Dt\bigr)}
\qquad\quad\bigl(\,\z_D=\exp^{2\pi i/D}\,\bigr)\,.\tag 26$$

{\bf Digression on  Hilbert modular surfaces, the Doi-Naganuma lifting, and twisted Borcherds products.}
To prove Theorem 6, two approaches are possible (although to be honest I  have not actually carried out either one in detail).
One way would be to generalize the proof which Borcherds gave in [\Bo] for the case $D=1$.  This proof is based 
on the circle method and uses explicit calculations of the Fourier developments of Poincar\'e series, so that it
is a kind of multiplicative analogue of the method which was introduced in [\Zc] to construct the Doi-Naganuma lifting
from elliptic to Hilbert modular forms and applied in [\Kob] for the usual Shimura lifting from modular forms of
half-integral to modular forms of integral weight.  But in keeping with the spirit of the rest of this paper,
one would like to give a more elementary proof, and also to see the ``twisted traces" $\t(D,d)$ 
for a fixed $D$ and variable $d$ appear naturally as the Fourier coefficients of a single modular form $g_D$ 
rather than a collection of modular forms $\{f_d\}$. The method used to prove Theorem~1 in this paper was to 
reduce it to the set of recursions given in Theorem~2 and then prove these by a geometric method. Specifically, 
to prove Theorem~2 we used the polynomial $\Phi_n(X,Y)$, which is the function on
$\Bbb P^1\times\Bbb P^1 \cong \H/\G\times\H/\G=:X_1$ whose zero-divisor is the graph of the 
Hecke correspondence $T_n\subset X_1$. The recursions (5) and (6) are then connected with the geometric
fact that the intersection of $T_n$ with the diagonal $T_1=\H/\G\subset X_1$ is the union over $|r|<2\sqrt n$
of the CM-cycles $\Cal S_{4n-r^2}\subset\H/\G$. We would like to see what replaces this when $D>1$.

The obvious replacement for the surface $X_1$ when one is dealing with a non-square positive discriminant $D$, 
say the discriminant of a real quadratic field $K$, is the Hilbert modular surface $X_D=\H\times\H/SL(2,\Cal O_K)$,
and the usual replacement for the graph of the Hecke correspondence in $X_1$ is the curve (also denoted $T_n$)
in $X_D$ which was studied in [\HZ]. The result $T_n\cap T_1=\bigcup \Cal S_{4n-r^2}$ on $X_1$ then generalizes nicely to a
similar formula on $X_D$ (essentially $T_n\cap T_1=\bigcup \Cal S_{(4n-r^2)/D}$, at least for $D$ prime, which we now
assume).  The problem is that $T_n$ is not in general the zero-set of any function on $X_D$, because its homology class 
on the surface $X_D$ is not in general trivial.  Indeed, the main result of [\HZ]
says that this homology class as $n$ varies is the $n$th coefficient of a modular form (with coefficients
in $H_2(X_D)$) of level $D$ and Nebentypus $\bigl(\dfrac\cdot D\bigr)$ and that this modular form describes
(i.e., is the kernel function for) the Naganuma map [\Na] from $M_2\bigl(\G_0(D),\bigl(\dfrac\cdot D\bigr)\bigr)$
to $M_2\bigl(SL(2,\Cal O_K)\bigr)$.  This map is injective and the dimension of 
$M_2\bigl(\G_0(D),\bigl(\dfrac\cdot D\bigr)\bigr)$ grows linearly with $D$, so it becomes increasingly
difficult to find linear combinations of the curves $T_n$ which are are homologically trivial.

However, as well as the Naganuma lifting from $M_k\bigl(\G_0(D),\bigl(\dfrac\cdot D\bigr)\bigr)$
to $M_k(SL(2,\Cal O_K)$, there is also the lifting constructed earlier by Doi and Naganuma [\DN]
from $M_k\bigl(SL(2,\Z)\bigr)$ to $M_k(SL(2,\Cal O_K)$, and in [\Za, pp\. 63--65] it was shown that it, too, could
be described geometrically in terms of intersections numbers with certain divisors $\widetilde T_n$ on $X_D$.
But since there are no cusp forms of weight~2 on $SL(2,\Z)$, this means that all of the divisors $\widetilde T_n$ are
homologically trivial and hence (since $X_D$ is known to be simply connected) principal, so that they can be obtained 
as the divisors of certain Hilbert modular functions $\Psi^{(D)}_n$. It is these functions which are the analogues 
of the functions $\Phi_n(j(\tau_1),j(\tau_2))$ in the case $D=1$. The definition of the curves $\widetilde T_n$, which we
will not repeat here, is well suited to our twisted traces $\t(D,d)$ and twisted Heegner
cycles $\Cal S_{D,d}=\sum \chi(Q)[\a_Q]$, because $\widetilde T_n$ is defined as the difference of two components of $T_{nD^2}$
which are distinguished by the value of the Legendre symbol $(\cdot/D)$. Using this one finds easily that 
$\widetilde T_n\cap T_1=\bigcup_r\Cal S_{D,4n-r^2}$ and hence that the restriction of $\Psi^{(D)}_n$ to $T_1$ is 
$\prod_r\Cal H_{D,4n-r^2}(j)$, where we have identified $T_1\approx\H/\G$ with the $j$-line, and it is this which
replaces the classical identity (9).

\def\v{\varepsilon} \def\Tr{\text{Tr}}
We now have an amusing calculation.  Write $J_m(\tau)=q^{-m}+\sum_{n>0}c_m(n)q^n$.  The coefficients $c_m(n)$ are given by
$c_m(n)=\sum_{d|(m,n)}md\inv c(mn/d^2)$, where $c(n)=c_1(n)$ is the coefficient of $q^n$ in $J(\tau)$.
It follows that $c_m(n)=mn\inv c_n(m)$ and that the function $S_m(\tau):=q^{-m}-\sum_{n>0}c_n(m)q^n$ is a multiple of $J'_m(\tau)$
and hence is the (obviously unique) modular form in $M^!_2(\G)$ with a Fourier expansion of the form $q^{-m}+\O(q)$.  Now consider the
function $(g_D\theta)|U_4$, where $D$ as usual is positive and congruent to 0 or 1 modulo 4.  From  $g_D=q^{-D}-2\v(D)+\O(q)$ 
($\v(D)=1$ or 0 according as $D$ is or is not a square) we find $(g_D\theta)|U_4=\sum_f q^{(f^2-D)/4}+\O(q)$, where the summation
runs over all integers $f$ with $f^2<D$, $f\equiv D\!\pmod2$. Also, $(g_D\theta)|U_4$ is a modular form of weight 2 on $\G$ and
is nearly holomorphic. Hence by our previous remark $(g_D\theta)|U_4=\sum_f S_{(D-f^2)/4}$, and comparing the coefficients of
$q^n$ on both sides we obtain the identity
% $$ \sum_{r^2<4n}A(D,\,4n-r^2)\=\sum\Sb f^2<D\\f\equiv D\pmod2\endSb c_n\bigl(\frac{D-f^2}4\bigr)\,+\,2\v(4n+D)\,.$$
$$ \sum_{r^2<4n}A(D,\,4n-r^2)\=\sum_{f^2<D,\;f\equiv D\pmod2} c_n\bigl(\frac{D-f^2}4\bigr)\,+\,2\v(4n+D)\,.$$
Combining this with the above identity $\Psi_n^{(D)}(\tau,\tau)=\prod_{r^2<4n}\Cal H_{D,4n-r^2}(j(\tau))$ and 
equation (23), we deduce after a short calculation that
  % $$ \Psi^{(D)}_n(\tau,\tau)\=\prod\Sb\nu\in\frak d\inv\\ \nu\gg0\endSb P_d\bigl(q^{\Tr(\nu)}\bigr)^{c_n(D\nu\nu')}
  % \,\prod\Sb\nu\in\frak d\inv\\ D\nu\nu'=-n\\ \Tr(\nu)>0\endSb P_d\bigl(q^{\Tr(\nu)}\bigr)\,,$$
$$ \Psi^{(D)}_n(\tau,\tau)\=\prod_{\nu\in\frak d\inv,\;\Tr(\nu)>0} P_D\bigl(q^{\Tr(\nu)}\bigr)^{c_n(D\nu\nu')}\,,$$
where the product is over all all elements $\nu$ in the inverse different $\frak d\inv=D^{-1/2}\Cal O_K$ with $\Tr(\nu)$
positive and $D\nu\nu'$ either positive or else equal to $-n$.  This strongly suggests the identity
  % $$ \Psi^{(D)}_n(\tau_1,\tau_2)\=\prod\Sb\nu\in\frak d\inv\\ \nu\gg0\endSb P_d\bigl(q^{\Tr(\nu)}\bigr)^{c_n(D\nu\nu')}
  % \,\prod\Sb\nu\in\frak d\inv\\ D\nu\nu'=-n\\ \Tr(\nu)>0\endSb P_d\bigl(q^{\Tr(\nu)}\bigr)\,,$$
$$\Psi^{(D)}_n(\tau_1,\tau_2)\=\prod_{\nu\in\frak d\inv/\{\pm1\}}P_D\bigl(e^{2\pi i(\nu\tau_1+\nu'\tau_2)}\bigr)^{c_n(D\nu\nu')}\tag27$$
(in a suitable neighborhood of infinity), which is a kind of twisted Borcherds product expansion for the Hilbert modular function 
$\Psi^{(D)}_n$.  This identity is similar
(apart from the twisting) to an identity proved by Bruinier [\Br] for the usual curves $T_n$, and could doubtless be proved the same way,
although I have not gone through the details. Indeed, the calculation should be much easier here because in Bruinier's case only
certain linear combinations of the $T_n$ were homologically trivial and therefore representable as the divisor of a Hilbert modular
function, and (correspondingly) the Poincar\'e series of weight 2, which here are trivial because $\G$ has genus 0, were more complicated
because of the the presence of holomorphic cusp forms (on $\G_0(D)$ and Nebentypus) of weight 2.  

If we take the logarithm of (27) and substitute the definition (24) of the power series $P_D(t)$, then we find that the
coefficient of $e^{2\pi i(\nu\tau_1+\nu'\tau_2)}$ in $\,\log\bigl(\Psi^{(D)}_n(\tau_1,\tau_2)\bigr)\,$ is equal to
$\sum\limits_r r\inv\bigl(\dfrac Dr\bigr)\,c_n\bigl(\dfrac{D\nu\nu'}{r^2}\bigr)$. This formula is identical (with $a_n=c_n$ and $k=0$)
to the formula for the $\nu$th Fourier coefficient of the classical Doi-Naganuma lifting of a holomorphic modular form
$f=\sum a_nq^n\in M_k(\G)$ (cf.~[\Zc]).  We can thus interpret the logarithm of $\Psi^{(D)}_n$ as the Doi-Naganuma lifting of the
nearly holomorphic modular form $J_n\in M_0^!(\G)$, and (28) as saying that such a multiplicative version of the Doi-Naganuma
lifting exists.  Again, this is the analogue of the corresponding (but harder) result proved by Bruinier for the case of the Naganuma
lifting.

An interesting problem would be to show that the Hilbert modular function $\Psi^{(D)}_n$ is defined over $\Q$ or $K$ and to compute
its values at CM points, as was done in [\GZ] for the case $D=1$.  In analogy with the results of [\GZ], we would expect these values
to factor completely into small primes in a way which can be described explicitly.
   % (``special points" in the sense of [\EZ])

\bigskip
{\bf \S8. Second generalization: other groups.}  
 Another evident way to generalize Theorem~1 is to replace the function $j(\tau)$ by a modular function of higher
level, and in particular by the Hauptmodul associated to other groups of genus 0.
We discuss examples of this in this section.  We will consider only the case when the genus 0 group is the group
$\G_0^*(N)$ (the extension of $\G_0(N)$ by the group of all Atkin-Lehner involutions $W_p$, $\,p|N$).  We will look
in detail at the first five values $N=2$, 3, 4, 5 and 6 (although there are many further values of $N$ for which
$\G_0^*(N)$ has genus 0). The corresponding Hauptmodules (with apologies for the mixed German/English spelling!) are 
$$\align j_2^*(z)&\=\biggl(\frac{\eta(z)}{\eta(2z)}\biggr)^{24}\!+\,24\,+\,2^{12}\biggl(\frac{\eta(2z)}{\eta(z)}\biggr)^{24}\\
   &\=q\inv + 4372\,q + 96256\,q^2 + 1240002\,q^3 + 10698752\,q^4 + 74428120\,q^5 + 431529984\,q^6 + \cdots\,,\\
j_3^*(z)&\=\biggl(\frac{\eta(z)}{\eta(3z)}\biggr)^{12}\!+\,12+3^6\,\biggl(\frac{\eta(3z)}{\eta(z)}\biggr)^{12}\\
   &\=q\inv + 783\,q + 8672\,q^2 + 65367\,q^3 + 371520\,q^4 + 1741655\,q^5 + 7161696\,q^6 + \cdots\,,\\
j_4^*(z)&\=\biggl(\frac{\eta(z)}{\eta(4z)}\biggr)^8+\,8\,+\,4^4\biggl(\frac{\eta(4z)}{\eta(z)}\biggr)^8\\
   &\=q\inv + 276\,q + 2048\,q^2 + 11202\,q^3 + 49152\,q^4 + 184024\,q^5 + 614400\,q^6 +\cdots\,, \endalign$$
$$\align j_5^*(z)&\=\biggl(\frac{\eta(z)}{\eta(5z)}\biggr)^6+\,6\,+\,5^3\biggl(\frac{\eta(5z)}{\eta(z)}\biggr)^6 \\
  &\= q\inv + 134\,q + 760\,q^2 + 3345\,q^3 + 12256\,q^4 + 39350\,q^5 + 114096\,q^6  +\cdots\,,\\
j_6^*(z)&\=\biggl(\frac{\eta(z)\eta(2z)}{\eta(3z)\eta(6z)}\biggr)^4\!+4+3^4\biggl(\frac{\eta(3z)\eta(6z)}{\eta(z)\eta(2z)}\biggr)^4
    \=\biggl(\frac{\eta(z)\eta(3z)}{\eta(2z)\eta(6z)}\biggr)^6\!+6+2^6\biggl(\frac{\eta(2z)\eta(6z)}{\eta(z)\eta(3z)}\biggr)^6\\
  &\ = q\inv + 79\,q + 352\,q^2 + 1431\,q^3 + 4160\,q^4 + 13015\,q^5 + 31968\,q^6 +\cdots\,.\\
\endalign $$
Each of these functions takes on algebraic integer values at CM points in the upper half-plane, and we want to give a 
formula for their traces.  

For $N>1$ one must consider Heegner points rather than arbitrary CM points. The easiest way to describe these is
to say that they are the images of the roots $\a_Q\in\H$ of quadratic forms $Q(X,Y)=aX^2+bXY+cY^2$ with $a\equiv0\!\pmod N$
and $(a,b,c,N)=1$.  (The last condition is automatic if we assume that the $-d$ is not divisible as a discriminant by the
square of any prime dividing $N$, an assumption we make from now on.) This requires in particular that the discriminant $-d$
of $Q$ is congruent to a square modulo $4N$. The class of $\a_Q$ modulo $\G_0(N)$ has a second invariant, apart from its class 
in $\Qd/\G$, namely the value of $b\!\pmod{2N}$.  If we fix this class, i.e., choose an integer $\beta\!\pmod{2N}$ with
$\beta^2\equiv-d\!\pmod{4N}$ and consider only forms $Q=[a,b,c]$ with $a\equiv0\!\pmod N$ and $b\equiv\beta\!\pmod{2N}$, then
the number of $\G_0(N)$-equivalence classes of such $Q$, counted as usual with multiplicity $1/w_Q$, is $H(d)$, and the
natural map from the quotient $\Cal Q_{d,N,\beta}/\G_0(N)$ (with the obvious notation) to $\Qd/\G$ is a bijection.  We could
then define a trace $t^{(N,\b)}(d)$ as the sum of the values of $j_N^*(\a_Q)$ with $Q$ running over a set of representatives
for $\Cal Q_{d,N,\beta}/\G_0(N)$.  In our case, however, we are looking at the smaller quotient of $\H$ by $\G_0(N)^*$,
and here the value of $t^{(N,\b)}(d)$ is independent of $\b$. (This is why we chose to restrict to this case.) We can therefore define 
$$ \t^{(N)}(d)\;=\;\sum_Q\frac1{w_Q}\,j_N^*\bigl(\a_Q\bigr)\,,$$
where the sum runs over $\G_0^*(N)$-representatives of forms $Q=[a,b,c]$ satisfying $N|a$.
  % or, more simply, over a set of representatives of $\Qd/\G$ which are chosen to satisfy the condition $N|a$.  
Here are some numerical examples with $N=2$ and $N=3$:
$$ \t^{(2)}(4) = \frac12\,j_2^*\bigl(\frac{1+i}2\bigr)=-52\,,\quad
\t^{(2)}(7) = j_2^*\bigl(\frac{1+\sqrt{-7}}4\bigr)=-23\,,\quad \t^{(2)}(8) = j_2^*\bigl(\frac{\sqrt{-2}}2\bigr)=152\,,$$
and
$$ \t^{(3)}(3) = \frac13\,j_3^*\bigl(\frac{-3+\sqrt{-3}}6\bigr)=-14\,,\quad % \t^{(3)}(8) = j_3^*\bigl(\frac{1+\sqrt{-2}}3\bigr)=-34\,,\quad 
\t^{(3)}(11) = j_3^*\bigl(\frac{1+\sqrt{-11}}6\bigr)=22\,.$$


In analogy with Theorem 1, we want to express these traces as the coefficients of some modular forms of weight 3/2. In fact,
 the results will be more easily formulated in the language of Jacobi forms rather than modular forms of half-integral
weight. (If we were looking at Hauptmodules for groups $\G_0(N)$ rather than $\G_0^*(N)$, then we would actually have to
work with Jacobi forms, since the trace would then depend on both the discriminant $-d$ and on a choice of square-root $\b$ of
$-d\pmod{4N}$, as explained above. In our case it would be possible to work just with modular forms, but using Jacobi forms makes things
simpler.) We begin by recalling some basic definitions and facts from the theory of Jacobi forms, referring to [\EZ] for a more detailed exposition.

For any integers $k$ and $N>0$, the space $J_{k,N}$ of Jacobi forms of weight $k$ and index $N$ (on the full modular group)
is defined as the set of holomorphic functions $\phi(\tau,z)$ on $\H\times\C$ which are in a suitable sense both modular
(with respect to the action $(\tau,z)\mapsto((a\tau+b)/(c\tau+d),z/(c\tau+d))$ of $\G$ on $\H\times\C$) and elliptic
(with respect to the translations of $z$ by elements of the lattice $\,\Z\tau+\Z$), and which satisfy a suitable
condition of holomorphy at infinity.  The transformation equations imply that $\phi$ has a Fourier development of the form
$$\phi(\tau,z)\=\sum_{n,r\in\Z} c(n,r)\,q^n\z^r\qquad\qquad\bigl(q=e^{2\pi i\tau}\,,\;\z=e^{2\pi iz}\bigr)$$
in which the coefficient $c(n,r)$ depends only on the quantity $4Nn-r^2$ and on $r\pmod{2N}$. The holomorphy condition at
infinity is that $c(n,r)$ vanishes unless $4Nn-r^2\ge0$.  If we relax the condition to merely requiring that $c(n,r)=0$ if $n<0$,
we obtain the space of {\it weak Jacobi forms}, denoted $\wJ_{k,N}$ in [\EZ], and if we drop it entirely we obtain
the space of nearly holomorphic Jacobi forms, which we will denote $J^!_{k,N}$.  The structure of the ring $\wJ_{*,*}$ of
all weak Jacobi forms was determined in [\EZ], Theorem 9.3 and 9.4: its even weight subring is the free polynomial algebra
over $M_*=M_*(\G)=\C[E_4(\tau),E_6(\tau)]$ on two generators $a=\wphi_{-2,1}(\tau,z)\in\wJ_{-2,1}$ and
$b=\wphi_{0,1}(\tau,z)\in\wJ_{0,1}$, while the full ring is an extension of this by a further element
$c\in\wJ_{-1,2}$ with $432c^2=ab^3-3E_4a^3b+2E_6a^4$. It follows from this description that the rings $J^!_{\text{ev},*}$
and $J^!_{*,*}$ are given by a similar formula, but with $M_*(\G)$ replaced by $M_*^!(\G)=\C[E_4,E_6,\D\inv]/(E_4^3-E_6^2=1728\D)$.
The Fourier expansions of $a$~and~$b$ begin
$$ \align a\=&(\z-2+\z\inv)\,+\,(-2\z^2+8\z-12+8\z\inv-2\z^{-2})\,q\\
 &\;+\,(\z^3-12\z^2+39\z-56+\dots)\,q^2+\,(8\z^3-56\z^2+152\z-208+\dots)\,q^3\,+\,\cdots\\
b\=&(\z+10+\z\inv)\,+\,(10\z^2-64\z+108-64\z+10\z^2)\,q\,\\
 &\;+\,(\z^3+108\z^2-513\z+808-\dots)\,q^2\,+\,(-64\z^3+808\z^2-2752\z+4016-\dots)\,q^3\,+\,\cdots\,,\endalign$$
where the ``\dots" means that the coefficients of negative powers of $\z$ have been omitted (the transformation equation of
Jacobi forms imply that $c(n,-r)=(-1)^kc(n,r)$ for a Jacobi form of weight $k$).  The above-mentioned periodicity property of
the Fourier coefficients is clearly visible in these expansions.

If $N=1$, then the periodicity property of the Fourier coefficients mentioned above implies that $c(n,r)=C(4n-r^2)$ for
some function $d\mapsto C(d)$, and also that $k$ is even.  There is then an isomorphism between $J_{k,1}$ and $M_{k-1/2}$,
and between $J_{k,1}^!$ and $M_{k-1/2}^!$, sending $\sum c(n,r)q^n\z^r$ to $\sum C(d)q^d$.  For example, the two forms $g_1$ 
and $g_5$ in $M_{3/2}$ correspond to the Jacobi forms
$$\align\phi(\tau,z)&\=E_4\,a\=(\z-2+\z\inv)+(-2\z^2+248\z-492+\dots)\,q+\cdots\;, \\
  \phi_5(\tau,z)&\=\bigl(\frac56\,\frac{E_4^4}\D-816\,E_4\bigr)\,a\,+\,\frac16\,\frac{E_4^2E_6}\D\,b\\ &
\=(\z+\z\inv)\,q\inv\,+\,0\,q^0 + (\z^3+ 85995\z - 565760+\dots)\,q + \cdots\;.\endalign$$
in $\wJ_{2,1}$ and $J^!_{2,1}\,$, respectively.  
Generalizing the function $\phi=\phi^{(1)}$ there are Jacobi forms $\phi^{(N)}\in\wJ_{2,N}$ ($2\le N\le6$) uniquely characterized
by the requirement that they have Fourier coefficients $c(n,r)=B^{(N)}(4nN-r^2)$ which depend only on the discriminant $r^2-4Nn$
(except in the case when $N=4$ and $r\equiv0\!\pmod4$, in which case $c(n,r)=(-1)^{r/4}\,B^{(4)}(16n-r^2)$), with 
$B^{(N)}(-1)=1$, $B^{(N)}(0)=-2$.  (In particular, the Fourier development of $\phi^{(N)}$ begins $(\z-2+\z\inv)+\O(q)$.)
The representations of the forms $\phi^{(N)}$ in terms of the generators $a=\wphi_{-2,1}$, $b=\wphi_{0,1}$ of $\wJ_{*,*}$ are as follows:
$$ \align  \phi^{(2)}&\= \frac1{12}\,a\,\bigl(E_4b-E_6a\bigr)\,, \\
 \phi^{(3)}&\= \frac1{12^2}\,a\,\bigl(E_4b^2-2E_6ab+E_4^2a^2\bigr)\,, \\
 \phi^{(4)}&\= \frac1{12^3}\,a\,\bigl(E_4b^3-3E_6ab^2+3E_4^2a^2b-E_4E_6a^3\bigr)\,, \\
 \phi^{(5)}&\= \frac1{12^4}\,a\,\bigl(E_4b^4-4E_6ab^3+6E_4^2a^2b^2-4E_4E_6a^3b+(4E_6^2-3E_4^3)a^4\bigr)\,, \\
 \phi^{(6)}&\= \frac1{12^5}\,a\,\bigl(E_4b^5-5E_6ab^4+10E_4^2a^2b^3-10E_4E_6a^3b^2+(8E_6^2-3E_4^3)a^4b-E_4^2E_6a^5\bigr)\,, \endalign$$
so that each $\phi^{(N)}(\tau,z)$ has the form $\sum_{\nu=1}^Nf_{N,\nu}(\tau)\wphi_{-2,1}(\tau,z)^\nu\wphi_{0,1}(\tau,z)^{N-\nu}$
where $f_{N,\nu}(\tau)$ is a holomorphic modular form of weight $2\nu+2$ on $SL(2,\Z)$ with constant term
 $\frac{(-1)^{\nu-1}}{12^{N-1}}\,\bigl({N-1\atop\nu-1}\bigr)$.
Using these expansions one can compute the Fourier coefficients $B^{(N)}(d)$.  Here is a table for $0<d<30$.
$$ \vbox{\tabskip=0pt \offinterlineskip
\halign{\strut \hfil#&\tabskip=.6em plus .4em\hfill#&\vrule#&\hfill#&
\hfill#&\hfill#&\hfill#&\hfill#&\hfill#&\hfill#&\hfill#&\hfill#&\hfill#&\hfill#&\hfill#&\hfill#&\hfill#\tabskip=0pt\cr
&$d\quad$&&3&4&7&8&11&12&15&16&19&20&23&24&27&28\cr \noalign{\vskip0pt}\multispan{17}\hrulefill\cr
&$B^{(2)}(d)\vphantom{x^{x^2}}$&& &52&23&$-152$& &496&1&$-1036$& &2256&94&$-4400$& &8192\cr
&$B^{(3)}(d)$&&14& & &34&$-22$&$-52$&138& & &116&$-115$&$-348$&482& \cr
&$B^{(4)}(d)$&& & &23& & &0&1&$-52$& & &94& & &0\cr
&$B^{(5)}(d)$&& &8& & &12& &38&6&$-20$&$-12$& &44& &\cr
&$B^{(6)}(d)$&& & & &10& &28&10& & &$-12$&13&$-44$& &\cr}}  $$
(The empty entries correspond to $-d$ which are not congruent to squares modulo $4N$.)
Comparing these numbers with the examples of traces $\t^{(N)}(d)$ given at the beginning of the section, we
are led to the following result, which can be proved in a way analogous to the proof of Theorem 1.
\proclaim{Theorem 8} $\;\t^{(N)}(d)=-B^{(N)}(d)$ for all $d$ and $N$. \endproclaim




\bigskip
{\bf \S9. Third generalization: other weights.}  
The results discussed so far concerned the modular forms $j(\tau)$ and $J_m(\tau)$ of weight 0,
the modular forms $f_d$ of weight 1/2, and the modular forms $g_D$ of weight 3/2.  It is natural
to wonder whether there are similar results for other weights.  

In fact our story so far involved not only the weights 0, 1/2, and 3/2, but also the weight 2,
although in an invisible form: the existence of the Hauptmodul, a special modular form of weight~0,
depended on the fact that the modular curve being studied had genus~0 and hence that the space of 
modular forms of the complementary weight 2 contained no cusp forms.  We will find analogous results
for all other pairs of half-integral weights $(k+\frac12,\,\frac32-k)$ for which there are no non-zero cusp forms
of weight $2k$ on $SL(2,\Z)$, i.e., for $k=2$, 3, 4, 5,  and 7.

We look first at the case $k=2$.  For each nonpositive discriminant $-d$ there is a unique form 
$u_d\in\M_{5/2}^!$ such that $u_d=q^{-d}+\O(q)$ at infinity, and for each positive discriminant $D$ 
there is a unique form $v_D\in\M_{-1/2}^!$ such that $v_D=q^{-D}+\O(1)$ at infinity. The Fourier 
expansions of the first few of these functions begin
$$\align u_0 &= 1 - 10q - 70q^4 - 48q^5 - 120q^8 - 250q^9 - 240q^{12} - 240q^{13} + \O(q^{16})\,, \\
  u_3 &= q^{-3} + 64q - 32384q^4 + 131565q^5 - 4257024q^8 + 11535936q^9 + \O(q^{12})\,, \\
  u_4 &= q^{-4} - 108q - 131976q^4 - 656800q^5 - 34867000q^8 - 109046412q^9 + \O(q^{12})\,, \\
  u_7 &= q^{-7} + 513q - 4451328q^4 + 35655680q^5- 6275241984q^8 + \O(q^9)\,,\\
  u_8 &= q^{-8} - 808q - 12327152q^4 - 112985280q^5 - 27914678946q^8 + \O(q^9)\,,\\ & \\
 v_1 &=q\inv+10-64q^3+108q^4-513q^7+808q^8-2752q^{11}+4016q^{12}+\O(q^{15})\,, \\
  v_4 &= q^{-4} + 70 + 32384q^3 + 131976q^4 + 4451328q^7 + 12327152q^8 + \O(q^{11})\,,\\
  v_5 &= q^{-5} + 48 - 131565q^3 + 656800q^4 - 35655680q^7 + 112985280q^8 + \O(q^{11})\,, \\
  v_8 &= q^{-8} + 120 + 4257024q^3 + 34867000q^4 + 6275241984q^7 + \O(q^8)\,, \\
  v_9 &= q^{-9} + 250 - 11535936q^3 + 109046412q^4- 27774693612q^7  + \O(q^8)\,. \endalign $$
These values suggest the following result, whose proof is entirely analogous to that of Theorem 4.
\proclaim{Theorem 9}  For all $D$ and $d$ the coefficient of $q^D$ in $u_d$ is the negative of 
the coefficient of $q^d$ in~$v_D\,$.\endproclaim
The corresponding result holds also for the other cases $k=3$, 4, 5, and 7. We will come back to this at the end of the section,
but first we want to know whether there is any analogue of Theorem~1 for the new coefficients, and specifically
whether the coefficients of the form $v_1$ (and then later of the other forms $v_D$ and $u_d$, in analogy with the
generalization of Theorem 1 given in~\S7) can be interpreted as traces of some modular function.

The answer is yes, but we have to work with {\it non-holomorphic modular functions}.  This is in a sense quite
natural.  The values $k=2$, 3, 4, 5, 7 for which $S_{k+1/2}=\{0\}$ are, by virtue of the Shimura-Kohnen 
correspondence, precisely those for which  $S_{2k}(\G)=\{0\}$, as already mentioned, so their special behaviour
has to do with the pair of integral weights $2k$ and $2-2k$, rather than 2 and~0 as in the case we studied originally.
In particular, for these values of $k$ there is a unique nearly holomorphic modular form $F_k\in\M_{2-2k}^!(\G)$
having a Fourier development starting $q^{-1}+\O(1)$.  We would like to take the sum of the values of this function
at all points of $\Qd/\G$, but of course this makes no sense since $F_k$ is not $\G$-invariant.  However, there
is a well-known {\it non-holomorphic differentiation operator} which increases the weight of a modular form by 2
(at the cost of making it mildly non-holomorphic), and by applying this the right number of times to the function $F_k$ 
we get a $\G$-invariant function which we then can evaluate on $\Qd/\G$.  For $k=2$ the function $F_k$ is given by 
$$  F_2(\tau)\=\frac{E_4(\tau)E_6(\tau)}{\D(\tau)}\=q\inv - 240 - 141444\,q - 8529280\,q^2 - 238758390\,q^3  - \cdots$$
and its non-holomorphic derivative is the function
$$ K(\tau)\= -\biggl(\frac1{2\pi i}\,\frac{\d}{\d\tau}+\frac1{2\pi\Im(\tau)}\biggr)F_2(\tau)        
  \=\frac{E_2^*(\tau)E_4(\tau)E_6(\tau)+3E_4(\tau)^3+2E_6(\tau)^2}{6\D(\tau)}\,,$$
where $E_4$ and $E_6$ are the usual Eisenstein series of weights 4 and 6 on $\SL$ and 
$$E_2^*(\tau)=1-24\,\sum_{n=1}^\infty\frac{n\,q^n}{1-q^n}-\frac3{\pi\Im(\tau)}
\=1-\frac3{\pi\Im(\tau)}-24\,q-72\,q^2-96\,q^3- 168\,q^4 -\cdots$$
the non-holomorphic Eisenstein series of weight 2 on $\G$.

It is well-known that, although $E_2^*(z)$ is not holomorphic, it has the same arithmetic property as a holomorphic modular
form with rational Fourier coefficients, namely that its quotient by a meromorphic modular form of weight 2 
has algebraic values (belonging to the usual class field) at CM points in the upper half-plane.  It follows
that $K(\tau)$ is algebraic at all CM points.  Here are a few sample values.
$$ \align & K\bigl(\frac{1+\sqrt{-3}}2\bigr)=-576,\quad K\bigl(i\bigr)=864,\quad
K\bigl(\frac{1+\sqrt{-7}}2\bigr)=-3591,\quad K\bigl(\sqrt{-2}\bigr)=6464,\\
&K\bigl(\frac{1+\sqrt{-15}}2\bigr)=\frac{-176625-78939\sqrt5}2\,,\quad
K\bigl(\frac{1+\sqrt{-15}}4\bigr)=\frac{-176625+78939\sqrt5}2\,.\endalign$$
Note that in all of these examples, the values of $K(\a_Q)$ are algebraic integers, but this
is not always the case. For instance, the values of $K(\a_Q)$ for the three
inequivalent quadratic forms of discriminant $-31$ are the roots of the polynomial
$$ X^3 + 37235619\,X^2 - \frac{61346290410}{31}\,X + 1143159756791823$$
in which the coefficients of $X^2$ and $X^0$ (trace and norm) are integral and even divisible
by 31, but the coefficient of $X$ has a denominator 31.  This is because the values of $E_4(z)/\D(z)^{1/3}=\root3\of{j(z)}$ and $E_6(z)/\D(z)^{1/2}=\sqrt{j(z)-1728}$ for $z\in\Qd$ are algebraic integers, but $E_2^*(z)/\D(z)^{1/6}$ in general has a 
denominator $\sqrt{-d}$. For instance, the values of $E_2^*(z)/\D(z)^{1/6}$ for $z\in\Cal Q_{31}\,$ (with an appropriate 
choice of $\D(z)^{1/6}$) are equal to $3\a/\sqrt{-31}$ with $\a$ a root of $\a^3-26\a^2+85\a-141=0$.

Comparing the values of $K(\tau)$ just given with the coefficients of the function $v_1$ given above, we are led to formulate
the following theorem, which is analogous to Theorem~1 and can be proved in a similar way:
\proclaim{Theorem 10} For all positive integers $d$ congruent to $0$ or $3\!\pmod4$ we have
$$   \sumG\frac1{w_Q}\,K(\a_Q)\=d\,\b(d)\,,\tag 28$$
where $\b(d)$ denotes the coefficient of $q^d$ in the function $v_1\in M_{-1/2}^!\,$.\endproclaim


All of the extensions of Theorem 1 which we discussed in the previous sections carry over to the new situation. For instance,
we can consider the image $K_m=K\circ T(m)$ of $K$ under the $m$th Hecke operators $(m\ge1$), which has the form $p_m(j(\tau))K(\tau)+j(\tau)(j(\tau)-1728)p_m'(j(\tau))$ for a certain monic polynomial $p_m(j)$ of degree $m-1$
($p_1=1$, $p_2=j-504$, $p_3=j^2-1248j+180252$, \dots), determined by the requirement that
$p_m(j(\tau))F_2(\tau)=q^{-m}+\O(1)$. Then (28) generalizes to
$$ \sumG \frac1{w_Q}\,K_m(\a_Q)\=d\,\b_m(d)\,,\tag 29$$
where $\b_m(d)$ is the coefficient of $q^d$ in the image of $v_1$ under $T(m)$, given for $m=p$ prime by
$$\b_p(d)\=   p^3\,\b(p^2d)\,+\,p\,\bigl(\frac{-d}p\bigr)\,\b(d)+\b(p^{-2}d)\,.$$
As numerical examples of (29), for $m=2$ we find the values
$$ \align \frac1{3\cdot3}\,K_2\bigl(\frac{1+\sqrt{-3}}2\bigr)&\=32256\=8\b(12)-2\b(3)\,,\\
 \frac1{2\cdot4}\,K_2\bigl(i\bigr)&\=132192\=8\b(16)\,,\\
\frac17\,K_2\bigl(\frac{1+\sqrt{-7}}2\bigr)&\=4450302\=8\b(28)+2\b(7)\,,\\
\frac1{12}\biggl(K_2(\sqrt{-3})+\frac13\,K_2\bigl(\frac{1+\sqrt{-3}}2\bigr)\biggr)
&\= 450927936\=8\b(48) +\b(3)\,.\endalign$$
The results of \S7 also carry over in the obvious way. For instance, the number $-78939$ occurring
as the coefficient of $\sqrt5$ in the formula for $K((1+\sqrt{-15})/2)$ given above is 3/5 times the
coefficient $-131565$ of $q^3$ in $v_5$ (or of $-q^5$ in $u_3$).  One can also give a generalization
to higher levels along the lines of the formulas in \S8, for all levels having no cusp forms of weight 4.    

We now turn to the higher values $3$, 4, 5, 6 and 7 of $k$. The situation here turns out to be similar, but with
a difference according as $k$ is even or odd. The forms $F_k\in M^!_{2-2k}$ for these $k$ are $E_4^2/\D$, 
$E_6/\D$, $E_4/\D$ and $1/\D$, respectively. The associated non-holomorphic modular forms of weight 0 are 
$\Phi_k\=(-1)^{k-1}\,\d_{-2}\circ\d_{-4}\cdots\d_{2-2k}\bigl(F_k\bigr)\,,$ where $\d_h$ is the   
operator  $\dfrac1{2\pi i}\dfrac{\d}{\d\tau}-\dfrac h{4\pi\Im(\tau)}$ which maps modular forms of weight $h$ to modular
 forms of weight $h+2$. The value of $\Phi_2=K$ was given above. The others are
 $$ \align \Phi_3(\tau)&=\frac{3E_2^{*2}E_4^2+12E_2^*E_4E_6+13E_4^3+8E_6^2}{36\D}\;,\\ 
\Phi_4(\tau)&=\frac{5 E_2^{*3}E_6+15E_2^{*2}E_4^2+27E_2^*E_4E_6+16E_4^3+9E_6^2}{72\D}\;,\\ \Phi_5(\tau)&=\frac{35E_2^{*4}E_4+70E_2^{*3}E_6+120E_2^{*2}E_4^2+130E_2^*E_4E_6+51E_4^3+26E_6^2}{432\D}\;,\\ 
\Phi_7(\tau)&=\frac{385E_2^{*6}+525E_2^{*4}E_4+280E_2^{*3}E_6+315E_2^{*2}E_4^2+168E_2^*E_4E_6+39E_4^3+16E_6^2}{1728\D}\;.\endalign$$
In particular, each $\Phi_k$ belongs to $\Q(J)[K]$, e.g. $\Phi_3=\dfrac{(6K-5J-264)^2}{12(J-984)}+2K-\dfrac{13}{12}J-38\,$.

On the half-integral side we define $\g_k(\tau)$ to be the unique modular form in $M^!_{-k+3/2}$ with a Fourier expansion
beginning $q\inv+\O(1)$ if $k$ is even (i.e., $k=2$ or 4), and the unique modular form in $M^!_{k+1/2}$ with a Fourier expansion
beginning $q\inv+\O(q)$ if $k$ is odd (i.e., $k=3$, 5 or 7). If
$$ \align\a &\= q\inv-2+8q^3-12q^4+39q^7-56q^8+152q^{11}-208q^{12}+\cdots\,,\\
   \b&\=q\inv+10-64q^3+108q^4-513q^7+808q^8-2752q^{11}+\cdots\endalign$$
denote the forms in $M^!_{-5/2}$ and $M^!_{-1/2}$ corresponding under the isomorphism $M_{k-1/2}^!\approx J_{k,1}^!$
to the two generators $a=\wphi_{-2,1}(\tau,z)\in\wJ_{-2,1}$ 
and $b=\wphi_{0,1}(\tau,z)\in\wJ_{0,1}$ of the ring of weak Jacobi forms, then the $\g_k$ are given by 
$\g_2\;(\,=v_1)\,=\b$ and $\g_4\,=\,\a$  for $k$ even and by 
$$ \align \g_3&\=\frac{5E_6\,\a+E_4\,\b}6\;\=q\inv-384\,q^3+1248\,q^4-19473\,q^7+40768\,q^8-272512\,q^{11}+\cdots\,,\\
\g_5&\=\frac{5\,E_4^2\,\a+E_6\,\b}6\;\,\=q\inv+312\,q^3-1632\,q^4+57351\,q^7-144704\,q^8+1503272\,q^{11}+\cdots\,,\\
\g_7&\=\frac{5\,E_4E_6\a+E_4^2\b}6\=q\inv-144\,q^3+1248\,q^4-109473\,q^7+340288\,q^8-5768752\,q^{11}+\cdots\endalign$$
for $k$ odd. The generalization of Theorem 10 to higher weights is then: 
\proclaim{Theorem 11} Let $k\in\{2,\,3,\,4,\,5,\,7\}$ and $d>0$ an integer congruent to $0$ or $3$ modulo $4$. Then
$$ \sumG\frac1{w_Q}\,\Phi_k(\a_Q)\quad=\quad\cases -(-d)^{k/2}\cdot\text{coefficient of $q^d$ in $\g_k$ } & \text{if $k$ is even,}\\
-(-d)^{(1-k)/2}\cdot\text{coefficient of $q^d$ in $\g_k$ } & \text{if $k$ is odd.}\endcases $$ \endproclaim
The reader can use the formula for $\Phi_3$ as a rational function of $J$ and $K$ and the  values of $J(\a_Q)$ 
and $K(\a_Q)$ given earlier to check this theorem for $k=3$ and the first few values of $d$.\

The most surprising aspect of the theorem is the dependence on the parity of $k$, with the traces of $\Phi_k(\a_Q)$ 
being divisible by a power of $d$ (as in (28)) for even $k$ and having a power of $d$ as denominator for odd $k$.  This dichotomy
of course arises because of the definition of the Kohnen ``plus space", which forces us to look at half-integral weights
congruent to 3/2 modulo 2 (since we want coefficients indexed by integers congruent to 0 or 3 modulo 4) and therefore to
choose $\g_k$ of weight $\frac32-k$ or $\frac12+k$ according whether $k$ is even or odd.

Again, there are results of the same type also for forms of higher level, so long as the  weight and level are such
that the corresponding space of Jacobi forms, or of modular forms of integral weight, contains no cusp forms. In fact, there are 
also results, though not as clean, when cusp forms are present. For instance, for level 1 and $k=6$, 8 or 10 (so that
$\,\dim S_{2k}(\G)=1$), there is no form in $M_{2-2k}^!$ with a Fourier development beginning $q\inv+\O(1)$, and similarly no form 
$q\inv+\O(1)$ in $M_{-k+3/2}^!\,$, but there is a form in $M_{2-2k}^!$ with Fourier expansion
beginning $q^{-2}+Cq\inv+\O(1)$ and a form in $M_{-k+3/2}^!\,$  with Fourier expansion
beginning $q^{-4}+C'q\inv+\O(1)$, and the traces of the values at CM points of the $(k-1)$st nonholomorphic
derivative of the former are expressible in terms of the Fourier coefficients of the latter.  Presumably (although I have not computed any
examples) the twisted trace of the values at CM points of discriminant $-Dd$ will also be given as a multiple of the $d$th 
coefficient of a half-integral weight form with Fourier expansion starting $q^{-4D}+Aq^{-D}+\O(1)$, for all $d$ and $D$.  If this 
picture is correct, then these correspondences would constitute a kind of Shimura lifting, compatible with Hecke operators, between 
nearly holomorphic modular forms of half-integral and integral weights. I leave this as an open problem. A possible method of proof
would be to use renormalized integrals against a meromorphic theta-function kernel, as explained in the appendix of [\HM]. 


  
\Refs 
 
\ref\key\Bo \by  Borcherds, R. \paper Automorphic forms on $\O_{s+2,2}(\R)$ and infinite products
\jour Invent. math.\vol 120 \pages 161--213 \yr 1995 \endref

\ref\key\Br \by  Bruinier, J.H. \paper Borcherds products and Chern classes of Hirzebruch-Zagier divisors
 \jour Invent. math. \pages to appear\endref

\ref\key\DN \by Doi, K. and Naganuma, H. \paper On the functional equation of certain Dirichlet series
\jour Invent. math. \vol 9 \yr 1969 \pages 1--14 \endref 


\ref\key\EZ  \by Eichler, M. and Zagier, D. \book The Theory of Jacobi Forms 
 \publ  Progress in Math. {\bf 55}, Birkh\"auser-Verlag \publaddr Boston--Basel--Stuttgart\yr 1985 \endref

% \ref\key\Fr \by Franke, H.-G.\paper Kurven in Hilbertschen Modulfl\"achen und Humbertsche Fl\"achen im Siegel-Raum 
% \jour Thesis, Bonn\yr 1977 \endref

\ref\key\GZ \by  Gross, B. and Zagier, D.\paper On singular moduli 
\jour J. reine angewandte Mathematik \vol 355 \pages 191--220\yr 1985 \endref

% \ref\key\GKZ \by  Gross, B., Kohnen, W. and Zagier, D.\paper Heegner points and derivatives of L-series. II 
% \jour Math. Annalen \vol 278 \pages 497--562\yr 1987 \endref

\ref\key \HM \by Harvey, J. and Moore, G. \paper Algebras, BPS states, and strings
\jour Nuclear Phys. B \vol 463 \yr 1996 \pages 315--368 \endref
    % \hep-th/9510183

\ref\key \HZ \by  Hirzebruch, F. and Zagier, D.\paper Intersection numbers of curves on Hilbert modular surfaces
and modular forms of Nebentypus \jour Invent. math.\vol 36 \yr 1976 \pages 57--113\endref

\ref\key\Ka \by  Kaneko, M. \paper The Fourier coefficients and the singular moduli of the elliptic modular function $j(\tau)$
\jour Mem. Fac. Eng. Design, Kyoto Inst. Tech. \vol 19 \pages 1--5 \yr 1996 \endref
  
\ref\key\Kb \by Kaneko, M. \paper Traces of singular moduli and the Fourier coefficients of the elliptic modular function $j(\tau)$
\jour CRM Proceedings and Lecture Notes \vol 19 \pages 173--176\yr 1999 \endref

\ref\key\Ko \by \,Kohnen, W.\paper Modular forms of half-integral weight on $\Gamma_0(4)$ \jour Math. Ann.\vol 248\pages 249--266 \yr 1980 \endref

\ref\key\Kob \by \,Kohnen, W.\paper Fourier coefficients of modular forms of half-integral weight
\jour Math. Ann.\vol 271\pages 237--268 \yr 1985 \endref

\ref\key\Na \by\,Naganuma, H. \paper On the coincidence of two Dirichlet series associated with cusp forms of
Hecke's ``Neben"-type and Hilbert modular forms over a real quadratic field 
\jour J. Math. Soc. Japan\vol 25 \yr 1973 \pages 547--555 \endref

%\ref\key\No \by  Norton, S. \paper [formula for action of $T_n$ on $j$] \yr 19?? \endref

\ref\key\Zc \by \,Zagier, D.\paper Modular forms associated to real quadratic fields \jour Invent. Math.
\yr 1975 \pages 1--46 \vol 30 \endref

\ref\key\Za \by \,Zagier, D.\paper Modular forms whose Fourier coefficients involve zeta-functions of quadratic fields
\inbook  Modular Forms of One Variable VI, (eds: Serre, J-P., Zagier, D.), Lecture Notes Math. {\bf 627}
\publ Springer \publaddr Berlin--Heidelberg--New York \pages 105--169 \yr 1977 \endref

\ref\key\Zb \by \,Zagier, D.\paper Eisenstein series and the Riemann zeta function \pages 275--301
\inbook Automorphic Forms, Representation Theory and Arithmetic \publ Springer-Verlag \publaddr Berlin--Heidelberg--New York\yr 1981 \endref


\end
