# Creation Functions

## Ambient Spaces

The functions in this section are used to create spaces of modular forms. Spaces of half-integral weight can also be created (see the next section).

For information on Dirichlet characters, see Section [Dirichlet Characters](../../BasicRings/ResidueClassRings/dirichlet-characters.md#rngint-dirichlet).

### `ModularForms(N): RngIntElt -> ModFrm`

The space $M_2(\Gamma_0(N),{\mathbb{Z}})$ of modular forms on $\Gamma_0(N)$ of weight $2$. See the documentation for `ModularForms(N,k)` below, with $k=2$.

### `ModularForms(N, k): RngIntElt, RngIntElt -> ModFrm`

The space $M_k(\Gamma_0(N),{\mathbb{Z}})$ of weight $k$ modular forms on $\Gamma_0(N)$ over ${\mathbb{Z}}$.

### `ModularForms(eps, k): GrpDrchElt, RngIntElt -> ModFrm`

Given a Dirichlet character *eps* and an integer $k$, this returns a space of modular forms over the integers, of weight $k$, which under base extension becomes equal to the direct sum of the spaces $M_k(\Gamma_1(N),eps1)$ of weight $k$ and nebentypus character *eps1*, where *eps1* runs over all Galois conjugates *eps*.

### `ModularForms(chars, k): [GrpDrchElt], RngIntElt -> ModFrm`

The space of modular forms of weight $k$ over the integers, formed as the direct sum of spaces `ModularForms(eps,k)`, summing over all *eps* in the given sequence *chars* of Dirichlet characters.

### `ModularForms(G, k): GrpPSL2, RngIntElt -> ModFrm`

### `ModularForms(G): GrpPSL2 -> ModFrm`

The space $M_k(G,{\mathbb{Z}})$, where $G$ is a congruence subgroup. The groups $\Gamma_0(N)$ and $\Gamma_1(N)$ are currently supported, and can be created using the commands `Gamma0(N)` and `Gamma1(N)`, respectively. When not specified, $k = 2$.

### `CuspForms(x): Any -> ModFrm`

### `CuspForms(x, y): Any, Any -> ModFrm`

These commands are a shortcut, and return the `CuspidalSubspace` of the corresponding full space of modular forms.

### `Example: Creation Space (ex-902ab1)`

In this example, we illustrate each of the above constructors in turn. First we create $M_2(\Gamma_0(65))$.

```magma
> M := ModularForms(65); M;
Space of modular forms on Gamma_0(65) of weight 2 and dimension 8 over
Integer Ring.
> Dimension(M);
8
> Basis(CuspidalSubspace(M));
[
    q + q^5 + 2*q^6 + q^7 + O(q^8),
    q^2 + 2*q^5 + 3*q^6 + 2*q^7 + O(q^8),
    q^3 + 2*q^5 + 2*q^6 + 2*q^7 + O(q^8),
    q^4 + 2*q^5 + 3*q^6 + 3*q^7 + O(q^8),
    3*q^5 + 5*q^6 + 2*q^7 + O(q^8)
]

```

Next we create $M_4(\Gamma_0(8))$.

```magma
> M := ModularForms(8,4); M;
Space of modular forms on Gamma_0(8) of weight 4 and dimension 5 over
Integer Ring.
> Dimension(M);
5
> Basis(CuspidalSubspace(M));
[
    q - 4*q^3 - 2*q^5 + 24*q^7 + O(q^8)
]

```

Now we create the space $M_3(N,\varepsilon)$, where $\varepsilon$ is a character of level $20$, conductor $5$ and order $4$.

```magma
> G := DirichletGroup(20,CyclotomicField(EulerPhi(20)));
> chars := Elements(G);
> #chars;
8
> [Conductor(eps) : eps in chars];
[ 1, 4, 5, 20, 5, 20, 5, 20 ]
> exists(eps){eps : eps in chars | Conductor(eps) eq 5 and IsOdd(eps)};
true
> Order(eps);
4
> M := ModularForms(eps, 3); M;
Space of modular forms on Gamma_1(20) with character all conjugates of
[$.2], weight 3, and dimension 18 over Integer Ring.
> Dimension(EisensteinSubspace(M));
12
> Dimension(CuspidalSubspace(M));
6

```

Next we create the direct sum of the spaces $M_k(20,\varepsilon)$ as $\varepsilon$ varies over the four mod $20$ characters of order at most $2$, for $k=2$ and $3$.

```magma
> G := DirichletGroup(20, RationalField());   // (Z/20Z)^* --> Q^*
> chars := Elements(G); #chars;
4
> M := ModularForms(chars,2); M;
Space of modular forms on Gamma_1(20) with characters all
conjugates of [1, $.1, $.2, $.1*$.2], weight 2, and dimension 12
over Integer Ring.
> M := ModularForms(chars,3); M;
Space of modular forms on Gamma_1(20) with characters all
conjugates of [1, $.1, $.2, $.1*$.2], weight 3, and dimension 16
over Integer Ring.

```

Now we create the spaces $M_k(\Gamma_1(20))$ for $k=2,3$.

```magma
> ModularForms(Gamma1(20));
Space of modular forms on Gamma_1(20) of weight 2 and dimension 22
over Integer Ring.
> ModularForms(Gamma1(20),3);
Space of modular forms on Gamma_1(20) of weight 3 and dimension 34
over Integer Ring.

```

We can also create the subspace of cuspforms directly:

```magma
> CuspForms(Gamma1(20));
Space of modular forms on Gamma_1(20) of weight 2 and dimension 3
over Integer Ring.
> CuspForms(Gamma1(20),3);
Space of modular forms on Gamma_1(20) of weight 3 and dimension 14
over Integer Ring.

```

### Half-integral Weight Forms

Spaces of modular forms of half-integral weight can also be constructed. For these spaces, `CuspidalSubspace` and `qExpansionBasis` are available, as well as basic functionality such as element arithmetic. More functionality will be added in future releases.

The algorithm for determining the q-expansion basis involves computing those of related integral-weight spaces (of weight either one half smaller or one half larger, and appropriate level and character).

#### `HalfIntegralWeightForms(N, w): RngIntElt, FldRatElt -> ModFrm`

The space of half-integral weight forms on `Gamma0(N)` and weight $w$. Here $N$ should be a multiple of $4$ and $w$ a positive element of ${\mathbb{Z}}+ 1/2$.

#### `HalfIntegralWeightForms(chi, w): GrpDrchElt, FldRatElt -> ModFrm`

The space of half-integral weight forms on `Gamma1(N)` with character `chi` and weight $w$. The modulus of `chi` should be a multiple of $4$, and $w$ a positive element of ${\mathbb{Z}}+ 1/2$.

#### `HalfIntegralWeightForms(G, w): GrpPSL2, FldRatElt -> ModFrm`

The space of half-integral weight forms on the congruence subgroup $G$ and weight $w$. Here $G$ must be contained in `Gamma0(4)`, and $w$ is a positive element of ${\mathbb{Z}}+ 1/2$.

## Base Extension

If $M$ is a space of modular forms created using one of the constructors in Section [Ambient Spaces](#sec-ambient-spaces), then the base ring of $M$ is ${\mathbb{Z}}$. Thus we can base extend $M$ to any ring $R$. The examples below illustrate some simple applications of `BaseExtend`.

### `BaseExtend(M, R): ModFrm, Rng -> ModFrm, Map`

The base extension of the space $M$ of modular forms to the ring $R$ and the induced map from $M$ to `BaseExtend(M,R)`. The only requirement on $R$ is that there is a natural coercion map from the base ring of $M$ to $R$. For example, when `BaseRing(M)` is the integers, any ring $R$ is allowed.

### `BaseExtend(M, phi): ModFrm, Map -> ModFrm, Map`

The base extension of the space $M$ of modular forms to the ring $R$ using the map $\phi \colon$ `BaseRing(M)` $\rightarrow R$, and the induced map from $M$ to `BaseExtend(M,R)`

### `Example: Base Extend (ex-c5a11c)`

We first illustrate an Eisenstein series in $M_{12}(1)$ that is congruent to $1$ modulo $3$.

```magma
> M<q> := EisensteinSubspace(ModularForms(1,12));
> E12 := M.1; E12 + O(q^4);
691 + 65520*q + 134250480*q^2 + 11606736960*q^3 + O(q^4)
> M3<q3> := BaseExtend(M,GF(3));
> Dimension(M3);
1
> M3.1+O(q3^20);
1 + O(q3^20)

```

This congruence can be proved by noting that the coefficient of $q^n$ in the $q$-expansion of $E_{12}/65520$, for any $n\geq 1$, is an eigenvalue of a Hecke operator, hence an integer, and that $65520$ is divisible by $3$. Because $E_{12}$ is defined over ${\mathbb{Z}}$ the command `"E12Q/65520"` would result in an error, so we first base extend to ${\mathbb{Q}}$.

```magma
> MQ, phi := BaseExtend(M,RationalField());
> E12Q := phi(E12);
> E12Q/65520;
691/65520 + q + 2049*q^2 + 177148*q^3 + 4196353*q^4 + 48828126*q^5 +
362976252*q^6 + 1977326744*q^7 + O(q^8)

```

It is possible to base extend to almost any silly commutative ring.

```magma
> M := ModularForms(11,2);
> R := PolynomialRing(GF(17),3);
> MR<q> := BaseExtend(M,R); MR;
Space of modular forms on Gamma_0(11) of weight 2 and dimension 2 over
Polynomial ring of rank 3 over GF(17)
Lexicographical Order
Variables: $.1, $.2, $.3.
> f := MR.1;  f + O(q^5);
1 + 12*q^2 + 12*q^3 + 12*q^4 + O(q^5)
> f*(R.1+3*R.2) + O(q^4);
$.1 + 3*$.2 + (12*$.1 + 2*$.2)*q^2 + (12*$.1 + 2*$.2)*q^3 + O(q^4)

```

## Elements

### `M . i: ModFrm, RngIntElt -> ModFrmElt`

The $i$th basis vector of the space of modular forms $M$.

### `M ! f: ModFrm, . -> ModFrmElt`

The coercion of $f$ into the space of modular forms $M$. Here $f$ can be a modular form, a power series with absolute precision, or something that can be coerced into `RSpace(M)`.

### `ModularForm(E): CrvEll -> ModFrm`

The modular form associated to the elliptic curve $E$ over ${\mathbb{Q}}$. (See Section [Elliptic Curves](abelian-varieties.md#sec-abelian-varieties).)

### `Example: Creation Elements (ex-e76151)`

```magma
> M := ModularForms(Gamma0(11),2);
> M.1;
1 + 12*q^2 + 12*q^3 + 12*q^4 + 12*q^5 + 24*q^6 + 24*q^7 + O(q^8)
> M.2;
q - 2*q^2 - q^3 + 2*q^4 + q^5 + 2*q^6 - 2*q^7 + O(q^8)
> R<q> := PowerSeriesRing(Integers());
> f := M!(1 + q + 10*q^2 + O(q^3));
> f;
1 + q + 10*q^2 + 11*q^3 + 14*q^4 + 13*q^5 + 26*q^6 + 22*q^7 + O(q^8)
> Eltseq(f);
[ 1, 1 ]

```

`Eltseq` gives $f$ as a linear combination of `M.1` and `M.2`. Next we coerce $f$ into $M_2(\Gamma_0(22))$.

```magma
> M22 := ModularForms(Gamma0(22),2);
> g := M22!f; g;
1 + q + 10*q^2 + 11*q^3 + 14*q^4 + 13*q^5 + 26*q^6 + 22*q^7 + O(q^8)
> Eltseq(g);
[ 1, 1, 10, 11, 14 ]

```

The elliptic curve $E$ defines an element of $M_2(\Gamma_0(11))$.

```magma
> E := EllipticCurve([ 0, -1, 1, -10, -20 ]);
> Conductor(E);
11
> f := ModularForm(E);
> f;
q - 2*q^2 - q^3 + 2*q^4 + q^5 + 2*q^6 - 2*q^7 + O(q^8)

```

A new copy of $S_2(\Gamma_0(11))$ was created as the space containing $f$

```magma
> Sf := Parent(f);
> Mf := AmbientSpace(Parent(f));
> Sf; Mf;
Space of modular forms on Gamma_0(11) of weight 2 and dimension 1 over
Integer Ring
Space of modular forms on Gamma_0(11) of weight 2 and dimension 2 over
Integer Ring
> IsIdentical(M, Mf);
false
> M eq Mf;
true
> f in Sf, f in Mf, f in M;
true false false

```

There is a canonical way to coerce $f$ into $M$ using its $q$-expansion.

```magma
> IsCoercible(M, f);
true
q - 2*q^2 - q^3 + 2*q^4 + q^5 + 2*q^6 - 2*q^7 - 2*q^9 - 2*q^10 + q^11 + O(q^12)

```

This coercion is applied automatically for some operations.

```magma
> f + M.1;
1 + q + 10*q^2 + 11*q^3 + 14*q^4 + 13*q^5 + 26*q^6 + 22*q^7 + 36*q^8 + 34*q^9
     + 46*q^10 + q^11 + O(q^12)

```
