Explicit computation of the effect of the Atkin-Lehner operator/Fricke involution's effect on $q$-expansion As a part of the research with which I am involved, I would like to understand how to compute the effect of the Atkin-Lehner operator/Fricke involution $W_2 = \begin{pmatrix} 0 & 1 \\ -2 & 0 \end{pmatrix}$ on the $q$-expansion modular forms with $\Gamma_0(2)$ level structure. I know of the Magma function $\operatorname{AtkinLehnerOperator}(f,q)$, but I would like to understand how this works at a theoretical level, both to get at theoretical results and to extend this function to work on modular forms over rings that are not the rationals, (specifically the integers and the 3-adic integers).
If anyone has any sources on or explanations as to how to compute how q-expansions are transformed under the Atkin-Lehner/Fricke involution, it would be greatly appreciated!
 A: In short, there is no simple formula for the $q$-expansion of the transform of a modular form under an Atkin-Lehner operator $W_Q$, in terms of the $q$-expansion of the original modular form.
The action of $W_Q$ on modular symbols is simply $\{\alpha,\beta\} \mapsto \{W_Q \alpha, W_Q \beta\}$. This is easy to implement, and gives the matrix of $W_Q$ in the basis of homology given by (linear combinations of) Manin symbols. If you are interested in the action on a given newform, you just restrict this matrix to the corresponding Hecke module. Otherwise, you compute a linear combination of such transforms.
This works well for $\Gamma_0(N)$ (trivial character), but not in general, because $W_Q$ doesn't preserve the character.
There is an implementation in Magma, as you have mentioned, with the restriction to cusp forms with trivial character and integral weight $\geq 2$. In Pari/GP there is a completely general implementation, for modular forms of arbitrary weight (including weight 1 and half-integral weight), level and character. In the difficult cases, this relies on a theorem of Borisov and Gunnells, which asserts that a cusp form of weight $>2$ on $\Gamma_1(N)$ can be expressed as a linear combination of pairwise products of Eisenstein series, plus an Eisenstein series. The idea being that the action of $W_Q$ on Eisenstein series is very easy to write down. It should be said, however, that finding such a linear combination of pairwise products, if done exactly, turns out to be very costly. For this reason, the Pari/GP algorithm is numerical; but it works well in practice. Some more details are given in the course Modular forms in Pari/GP by Belabas and Cohen.
There are also theoretical results. In your case the character is trivial, so that newforms are eigenvectors for Atkin-Lehner operators. If the newform $f$ satisfies $a_q(f) \neq 0$ for a prime $q$ dividing the level, then there is a formula for the local eigenvalue at $q$, see for example Atkin, Li, Twists of newforms and pseudo-eigenvalues of $W$-operators, Inv. Math. (1978) 48: 221-244. General theoretical formulas are difficult to get. They seem to be more conveniently stated and proved using the adelic language and the Whittaker model of the newform. The resulting formulas involve $\mathrm{GL}_2$ Gauss sums. For trivial character, there is a completely explicit formula in Nelson, Pitale, Saha, Bounds for Rankin-Selberg integrals and quantum unique ergodicity for powerful levels, J. Amer. Math. Soc. (2014), 27: 147-191, see p. 177. I should say here that $\begin{pmatrix} 0 & 1 \\ -2 & 0 \end{pmatrix} = \begin{pmatrix} 0 & 1 \\ -1 & 0 \end{pmatrix} \begin{pmatrix} 2 & 0 \\ 0 & 1 \end{pmatrix}$, so that the problem is reduced to the action of $\sigma = \begin{pmatrix} 0 & 1 \\ -1 & 0 \end{pmatrix}$. I guess that in your case, the formula will be simpler.
