---
title: "$q$-Expansions"
canonical: "https://docs.magma-maths.org/v2.30-1/ModularArithmeticGeometry/ModularForms/q-expansions.html"
source: "https://docs.magma-maths.org/v2.30-1/ModularArithmeticGeometry/ModularForms/q-expansions.md"
part: "Modular Arithmetic Geometry"
chapter: "Modular Forms"
breadcrumbs:
  - {"title": "Magma Handbook", "source": "https://docs.magma-maths.org/v2.30-1/index.md"}
  - {"title": "Modular Arithmetic Geometry", "source": "https://docs.magma-maths.org/v2.30-1/ModularArithmeticGeometry/index-modular-arithmetic-geometry.md"}
  - {"title": "Modular Forms", "source": "https://docs.magma-maths.org/v2.30-1/ModularArithmeticGeometry/ModularForms/index-modular-forms.md"}
prev: {"title": "Bases", "source": "https://docs.magma-maths.org/v2.30-1/ModularArithmeticGeometry/ModularForms/Bases.md"}
next: {"title": "Arithmetic", "source": "https://docs.magma-maths.org/v2.30-1/ModularArithmeticGeometry/ModularForms/arithmetic.md"}
intrinsics:
  - {"name": "qExpansion", "signature": "qExpansion(f): ModFrmElt -> RngSerPowElt"}
  - {"name": "qExpansion", "signature": "qExpansion(f, prec): ModFrmElt, RngIntElt -> RngSerPowElt"}
  - {"name": "PowerSeries", "signature": "PowerSeries(f): ModFrmElt -> RngSerPowElt"}
  - {"name": "PowerSeries", "signature": "PowerSeries(f, prec): ModFrmElt, RngIntElt -> RngSerPowElt"}
  - {"name": "Coefficient", "signature": "Coefficient(f, n): ModFrmElt, RngIntElt -> RngElt"}
  - {"name": "Precision", "signature": "Precision(M): ModFrm -> RngIntElt"}
  - {"name": "SetPrecision", "signature": "SetPrecision(M, prec): ModFrm, RngIntElt"}
examples:
  - "ex-70e625"
  - "ex-9d6bda"
---

<a id="sec-q-expansions"></a>
<a id="id1"></a>
# $q$-Expansions

The following intrinsics give the $q$-expansion of a modular form (about the cusp $\infty$).

Note that q-expansions are printed by default only to precision $O(q^12)$. This may be adjusted using `SetPrecision` (see below), which should be used to control *printing only*; to control the amount of precision computed *internally*, instead use `qExpansion` or `qExpansionBasis` and specify the desired precision.

<a id="function-qexpansion-modfrmelt"></a>
## `qExpansion(f): ModFrmElt -> RngSerPowElt`

<a id="function-qexpansion-modfrmelt-rngintelt"></a>
## `qExpansion(f, prec): ModFrmElt, RngIntElt -> RngSerPowElt`

<a id="function-powerseries-modfrmelt"></a>
## `PowerSeries(f): ModFrmElt -> RngSerPowElt`

<a id="function-powerseries-modfrmelt-rngintelt"></a>
## `PowerSeries(f, prec): ModFrmElt, RngIntElt -> RngSerPowElt`

```magma
GaloisOrbitRep: BoolElt                    Default: false
```

The $q$-expansion (at the cusp $\infty$) of the modular form (or half-integral weight form) $f$ to absolute precision `prec`. This is an element of the power series ring over the base ring of the parent of $f$.

If `GaloisOrbitRep` is set to `true`, then returns its Galois orbit representative, with a different variable name to mark the conjugate form.

<a id="function-coefficient-modfrmelt-rngintelt"></a>
## `Coefficient(f, n): ModFrmElt, RngIntElt -> RngElt`

The $n$th coefficient of the $q$-expansion of the modular form $f$.

<a id="function-precision-modfrm"></a>
## `Precision(M): ModFrm -> RngIntElt`

<a id="procedure-setprecision-modfrm-rngintelt"></a>
## `SetPrecision(M, prec): ModFrm, RngIntElt`

When an element of the space $M$ is printed, the q-expansion is displayed to this precision. The default value is $12$.

**Important note:** This controls **only printing.** It does not control the precision used during calculations. For instance, the precision to which $q$-expansions are computed is controlled by the second argument in `qExpansion` and `qExpansionBasis`.

<a id="example-ex-70e625"></a>
## `Example: Computing q-Expansions in Several Ways (ex-70e625)`

In this example, we compute the $q$-expansion of a modular form $f\in M_3(\Gamma_1(11))$ in several ways.

```magma
> M := ModularForms(Gamma1(11),3); M;
Space of modular forms on Gamma_1(11) of weight 3 and dimension 15
over Integer Ring.
> f := M.1;
> f;
1 + O(q^8)
> qExpansion(f);
1 + O(q^8)
> Coefficient(f,16);  // f is a modular form, so has infinite precision
-5457936
> qExpansion(f,17);
1 + 763774*q^15 - 5457936*q^16 + O(q^17)
> PowerSeries(f,20);   // same as qExpansion(f,20)
1 + 763774*q^15 - 5457936*q^16 + 14709156*q^17 - 12391258*q^18 -
    21614340*q^19 + O(q^20)
```

The “big-oh” notation is supported via addition of a modular form and a power series.

```magma
> M<q> := Parent(f);
> Parent(q);
Power series ring in q over Integer Ring
> f + O(q^17);
1 + 763774*q^15 - 5457936*q^16 + O(q^17)
> 5*q - O(q^17) + f;
1 + 5*q + 763774*q^15 - 5457936*q^16 + O(q^17)
> 5*q + f;
1 + 5*q + O(q^8)
```

Default printing precision can be set using the command `SetPrecision`.

```magma
> SetPrecision(M,16);
> f;
1 + 763774*q^15 + O(q^16)
```

<a id="example-ex-9d6bda"></a>
## `Example: Weierstrass Points on Modular Curves (ex-9d6bda)`

The `PrecisionBound` intrinsic is related to Weierstrass points on modular curves. Let $N$ be a positive integer such that $S = S_2(\Gamma_0(N))$ has dimension at least $2$. Then the point $\infty$ is a Weierstrass point on $X_0(N)$ if and only if `PrecisionBound(S : Exact := true)-1 ne Dimension(S)`.

```magma
> function InftyIsWP(N)
>    S := CuspidalSubspace(ModularForms(Gamma0(N),2));
>    assert Dimension(S) ge 2;
>    return (PrecisionBound(S : Exact := true)-1) ne Dimension(S);
> end function;
> [<N,InftyIsWP(N)> : N in [97..100]];
[ <97, false>, <98, true>, <99, false>, <100, true> ]
```

It is an open problem to give a simple characterization of the integers $N$ such that $\infty$ is a Weierstrass point on $X_0(N)$, though Atkin and others have made significant progress on this problem (see, e.g., 1967 Annals paper [[Atk67](https://docs.magma-maths.org/v2.30-1/references.md#cite-atkin-weierstrass)]). I verified that if $N<3223$ is square free, then $\infty$ is not a Weierstrass point on $X_0(N)$, which suggests a nice conjecture.
