Let me apologize ahead of time since I am not at all well versed in the theory of modular forms.
I have seen some nice examples where modular forms are used to study certain interesting numbers. For example, one might like to study the sequence $(h_n)_{n \in \mathbb{Z}}$ where $h_n$ is the class number of $\mathbb{Q}(\sqrt{n})$. Now, if $q = e^{2\pi i z}$, we could consider $F(z) = \sum_{n \in \mathbb{Z}} h_n q^n$ (I'm not even sure whether or not this converges), which is most likely not the Fourier expansion of some modular form. On the other hand, for $r \in \mathbb{Z}$ with $r \geq 2$, define \begin{align*} H(r,N) = \begin{cases} 0 & \text{ if } N \not\equiv 0,1 \mod4 \\ \zeta(1 -2r) & \text{ if } N = 0 \\ L(1-r, \chi_D)\sum_{d \mid n} \mu(d)\chi_D(d)d^{r-1}\sigma_{2r-1}(n/d) & \text{ if } (-1)^rN = Dn^2 \end{cases} \end{align*} where $D$ is the fundamental discriminant of a quadratic field, and $\sigma_k(m) = \sum_{d \mid m} d^k$. Then by the class number formula, certain values of $r$ and $N$ relate $H(r,N)$ to the class number $h_D$. We also have for $r \geq 2$ that $F_r(z) = \sum_{N = 0}^{\infty} H(r,N)q^N \in M_{r + 1/2}(\Gamma_0(4), 1)$ (see for example the papers of Cohen and Ono) . So now one has a powerful weapon to study class numbers of quadratic fields.
I have a few questions.
- How did anyone think of defining $H(r,N)$ like this? Were these modular forms just discovered by chance? That is, were people studying certain modular forms and then just noticed there is some connection with class numbers? One may look at the proof of Theorem 3.1 in Cohen's paper where he proves $F_r(z) \in M_{r + 1/2}(\Gamma_0(4), 1)$ by showing it is the linear combination of some other modular forms, but this is not very enlightening to me.
- If one has an interesting sequence of numbers, is there a way to construct a modular form from this sequence? Or do you have to get lucky in some sense?
It's a very natural question! If you know about Eisenstein series, you might spot that the third choice of $H(r,N)$ as very similar to the Eisenstein series of weight $2r$ and character $\chi_D$. If you don't, then I would certainly looking them up, they are very classical examples of modular forms. In this case, the modular form you write down is related to an Eisenstein series by the Shimura correspondence, which was one of the original motivations for studying half-integer weight modular forms. See for example Theorem 1 here for a similar statement about cusp forms. I'm sure no one wrote down $F_r (z)$ without knowing what they were looking for!
This is also a good question. In general, you have to be lucky - or there has to be a good reason for it. In some cases, you want the coefficients $a_n$ to be multiplicative in the sense that $a_{mn} = a_m a_n$ for $(m,n)=1$. An example of this is the Ramanujan $\Delta$-function, whose coefficients are related to the partition function. However, if you start with a general sequence of numbers $a_n$, it's most likely not going to be the coefficients of a modular form.