
// Make newform 1521.2.a.o in Magma, downloaded from the LMFDB on 01 February 2026.
// To make the character of type GrpDrchElt, type "MakeCharacter_1521_a();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_1521_2_a_o();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose lines below.
// The precision argument determines an initial guess on how many Fourier coefficients to use.
// This guess is increased enough to uniquely determine the newform.
// To make the Hecke irreducible modular symbols subspace (type ModSym)
// containing the newform, type "MakeNewformModSym_1521_2_a_o();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose line below.
// The default sign is -1.  You can change this with the optional parameter "sign".
function ConvertToHeckeField(input: pass_field := false, Kf := [])
    if not pass_field then
        poly := [1, -2, -1, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0], [0, 1, 0], [-2, 0, 1]];
    Rf_basisdens := [1, 1, 1];
    Rf_basisnums := ChangeUniverse([[z : z in elt] : elt in Rf_num], Kf);
    Rfbasis := [Rf_basisnums[i]/Rf_basisdens[i] : i in [1..Degree(Kf)]];
    inp_vec := Vector(Rfbasis)*ChangeRing(Transpose(Matrix([[elt : elt in row] : row in input])),Kf);
    return Eltseq(inp_vec);
end function;


// To make the character of type GrpDrchElt, type "MakeCharacter_1521_a();"
function MakeCharacter_1521_a()
    N := 1521;
    order := 1;
    char_gens := [677, 847];
    v := [1, 1];
    // chi(gens[i]) = zeta^v[i]
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    F := CyclotomicField(order);
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),[F|F.1^e:e in v]);
    return MinimalBaseRingCharacter(chi);
end function;

function MakeCharacter_1521_a_Hecke( : Kf := Kf)
    return MakeCharacter_1521_a();
end function;


function ExtendMultiplicatively(weight, aps, character)
    prec := NextPrime(NthPrime(#aps)) - 1; // we will able to figure out a_0 ... a_prec
    primes := PrimesUpTo(prec);
    prime_powers := primes;
    assert #primes eq #aps;
    log_prec := Floor(Log(prec)/Log(2)); // prec < 2^(log_prec+1)
    F := Universe(aps);
    FXY<X, Y> := PolynomialRing(F, 2);
    // 1/(1 - a_p T + p^(weight - 1) * char(p) T^2) = 1 + a_p T + a_{p^2} T^2 + ...
    R<T> := PowerSeriesRing(FXY : Precision := log_prec + 1);
    recursion := Coefficients(1/(1 - X*T + Y*T^2));
    coeffs := [F!0: i in [1..prec]];
    coeffs[1] := 1; //a_1
    for i := 1 to #primes do
        p := primes[i];
        coeffs[p] := aps[i];
        b := p^(weight - 1) * F!character(p);
        r := 2;
        p_power := p * p;
        //deals with powers of p
        while p_power le prec do
            Append(~prime_powers, p_power);
            coeffs[p_power] := Evaluate(recursion[r + 1], [aps[i], b]);
            p_power *:= p;
            r +:= 1;
        end while;    
    end for;
    Sort(~prime_powers);
    for pp in prime_powers do
        for k := 1 to Floor(prec/pp) do
            if GCD(k, pp) eq 1 then
                coeffs[pp*k] := coeffs[pp]*coeffs[k];
            end if;
        end for;
    end for;
    return coeffs;
end function;


function qexpCoeffs()
    // To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
    weight := 2;
    raw_aps := [[-1, 0, -1], [0, 0, 0], [-2, 1, -1], [1, -1, -1], [-2, -1, 1], [0, 0, 0], [1, 1, 2], [1, 2, 1], [3, -2, 2], [3, -5, 3], [-1, 5, -3], [-3, -2, 1], [1, -4, 6], [6, -2, 3], [-6, 1, 1], [-4, 4, -7], [-5, -4, 0], [-1, 6, -1], [4, -6, 5], [-10, 3, 0], [-4, 6, 3], [-4, -1, -8], [-6, 9, -2], [-6, 7, 0], [-5, 1, -7], [-6, 3, -10], [-4, 8, -1], [-1, 3, 2], [-4, -2, 6], [-8, -1, 2], [-4, -9, 1], [7, -5, -1], [8, -4, 0], [1, -11, 6], [3, 3, 0], [5, -12, 2], [-5, 1, -5], [-13, 1, 2], [-10, 2, -14], [0, 16, -8], [-2, -5, 4], [7, -1, -8], [0, -4, -9], [-8, 8, -10], [3, -8, 0], [-11, 6, -11], [2, -5, -5], [9, -3, 3], [2, -8, 3], [8, 8, -7], [8, -3, 2], [-13, -3, 6], [0, 1, -11], [-6, 2, -16], [-11, 13, 5], [-9, 6, -13], [6, -3, -1], [16, -14, 9], [0, 10, -5], [-8, 5, -6], [-12, 20, -14], [-17, 7, -16], [-2, 2, 10], [-1, 15, 3], [-9, -4, 7], [22, -8, 18], [2, 0, 11], [-4, -5, 12], [12, -2, 7], [7, 4, -3], [5, 1, 7], [-17, 10, -18], [7, 11, 6], [10, -16, 5], [-25, 13, -12], [2, -8, 16], [-12, -2, -16], [6, -11, 10], [10, 1, -9], [16, -15, 21], [22, 9, -2], [18, 6, 5], [-11, -6, -10], [-4, 5, 7], [9, -9, 14], [-18, 6, -4], [-10, 6, -11], [16, -17, 8], [-12, -6, -7], [3, -8, -5], [29, -19, 30], [-27, -3, -2], [-23, 11, -31], [-12, -11, 8], [-4, -15, 6], [15, -21, 24], [0, -2, 9], [19, 10, 2], [-24, 8, -5], [-27, 0, -6], [9, 12, 5], [15, -9, 2], [18, -7, 3], [20, -10, 3], [-10, 7, 4], [-27, -8, -3], [10, -9, -21], [-6, 14, 14], [-9, 14, -5], [9, -6, 0], [0, -9, 22], [8, 12, -7], [1, 20, -20], [-4, 6, 3], [-14, 3, 18], [-29, -4, 1], [-9, -17, 5], [-4, 12, -16], [-5, -15, 14], [-25, 7, 1], [-10, 25, -17], [23, -24, 11], [26, -4, -6], [11, -10, 17], [-29, 8, -13], [11, 4, -20], [-2, 31, -5], [6, -9, 13], [-5, -3, -11], [-6, 2, -27], [-12, -10, 2], [-21, 1, 7], [6, 10, -16], [-7, 0, 22], [5, -24, 9], [32, -23, 38], [-32, 8, 1], [23, -19, 24], [9, -15, -9], [28, -16, 6], [23, -17, 3], [9, 6, 21], [-17, 18, -6], [32, -23, 30], [25, -2, 5], [-14, 14, 14], [36, 4, 0], [-22, -8, 1], [-2, 8, 12], [-17, -8, -8], [-21, 33, -11], [34, -12, 13], [30, -21, 14], [-15, 5, -8], [-5, -7, -9], [-34, 12, -21], [14, 2, -7], [13, 9, -4], [26, -9, 6], [11, -12, 12], [1, -20, -8], [-3, 9, 27], [-7, 17, -24], [3, 16, 8], [25, 0, -1], [-38, 13, -33], [-26, 12, -25], [3, 11, -13], [-3, -22, 26], [-31, 23, -24], [-25, 8, -10], [-17, -17, -12], [-22, 21, 6], [31, -6, 2], [-36, 20, -9], [-15, 13, 10], [5, 8, 3], [17, -6, -3], [-23, -10, 19], [22, -6, 0], [0, -15, 4], [1, -28, 10], [17, -4, 20], [17, -11, -19], [-8, -28, 19], [9, -2, 30], [-14, -24, 3], [13, 16, -6], [2, -25, -14], [-39, 12, -2], [-9, 35, -3], [24, 0, 15], [-23, 11, 10], [40, -20, -8], [14, -25, -24], [-26, 17, -28], [16, -29, 11], [-14, -1, 11], [38, -9, -14], [-7, 10, 28], [-13, 38, -28], [-4, -1, 8], [-11, -15, 11], [5, -19, -9], [-2, -14, 1], [-39, 14, -14], [-5, 0, 9], [31, -1, -11], [27, 9, 19], [7, -17, 13], [14, -6, -1], [-24, 31, 1], [-3, -8, -16], [13, -27, 37], [-16, -37, 18], [13, 11, 4], [-25, 2, 3], [35, -22, -10], [13, 11, -4], [25, 17, -14], [-32, 24, -46], [-16, 30, -39], [47, -32, 34], [20, -23, 35], [-42, 10, -32], [41, 9, 7], [44, -22, 23], [17, 1, 18], [23, 3, -9], [-16, 8, 18], [9, -9, -25], [11, 16, -19], [-18, 25, -7], [-15, 4, -33], [-11, 0, -26], [4, -11, 20], [-64, -1, -1], [4, 39, -17], [-1, -8, -5], [-34, 30, -16], [20, -3, -12], [-15, -26, -5], [14, -37, -7], [-16, 21, 13], [22, -22, -5], [-22, 31, -38], [-6, 13, -19], [-45, 20, -26], [34, -12, 19], [18, -45, 22], [-31, 2, -6], [-1, 26, -1], [30, -19, 23], [20, -5, 20], [-6, -31, 12], [-25, -3, 8], [-48, -4, -16], [38, 4, -6], [-9, 5, 27], [21, -12, 19], [-11, 22, -19], [-20, 41, -6], [13, -49, 20], [10, -21, 23], [27, -3, 34], [-28, 34, 2], [29, -23, 0], [-33, 11, -25], [-7, -11, -3], [-17, 50, -35], [13, -13, -13], [29, 10, -2], [34, -11, -19], [28, -33, 28], [-47, 33, -45], [5, -60, 28], [-31, 19, -2], [17, -10, 5], [6, 2, -3], [53, -38, 41], [2, -16, -33], [-7, -20, 0], [-27, 11, -42], [60, -14, 19], [27, -17, 53], [-10, 20, -22], [-20, 57, -25], [-2, -12, -40], [-20, -24, 23], [-33, 17, -26], [-4, -4, -15], [-4, -9, -23], [-4, -46, 21], [-24, -5, -21], [25, 6, 12], [-8, 3, -2], [5, 7, 4], [16, -54, 15], [3, -31, 3], [42, -14, 35], [48, -8, 20], [-16, 21, 31], [46, -5, 20], [30, 40, -18], [-7, 44, -35], [-2, -33, -3], [7, -27, 44], [-15, 8, 12], [-6, 7, 26], [-64, 24, -16], [-18, 19, 32], [-16, 30, 18], [41, -21, 27], [-2, 29, -6], [5, -24, -17], [40, -50, 58], [7, 21, 14], [-13, 36, 19], [51, -10, 31], [37, -18, 43], [2, -43, 7], [17, 21, 21], [16, 16, 8], [-68, 24, -25], [-16, -31, -8], [41, -44, 47], [38, -13, -6], [-55, 10, -26], [2, 13, -21], [47, -15, 27], [-5, 2, 20], [-28, 13, 0], [45, -52, 48], [17, 4, 25], [32, 16, -1], [-20, 37, -51], [31, -22, -26], [-3, 1, 17], [-14, -7, 7], [11, 4, 19], [76, -19, 26], [-11, 18, -2], [-40, -9, 25], [43, -38, 29], [-14, -2, -14], [-24, 9, 20], [-30, 25, -21], [18, -22, -26], [-21, 11, 32], [29, -42, 35], [7, 2, 12], [35, 26, 4], [-5, 21, -2], [12, -14, 24], [-3, 15, 11], [7, 8, -27], [-20, 13, 6], [-46, 23, 30], [-5, -42, 15], [12, 25, -17], [50, -31, 36], [27, 2, -18], [57, -9, 23], [32, -40, 30], [5, 25, 0], [0, -1, -38], [-1, -25, 14], [-37, 49, -56], [1, -2, 23], [-43, 17, -62], [-34, -13, -7], [-3, -5, -47], [-1, 37, -16], [-43, -6, 0], [-16, -16, 18], [18, -65, 43], [7, 41, -16], [-32, -23, 9], [4, 27, -34], [-30, 31, -45], [-4, 36, 8], [-33, 26, -46], [14, -4, -38], [19, -2, 14], [-49, 21, -7], [26, -5, 8], [-26, 17, -48], [35, 8, 38], [-15, 33, 0], [-70, 6, 6], [-6, 4, 36], [-3, -61, 18], [44, 5, 33], [17, 17, 15], [-59, 52, -46], [-10, -2, -26], [34, -1, 19], [31, 3, -2], [1, -11, 42], [30, -26, 9], [-31, 27, -7], [-11, 52, -21], [-23, -14, -43], [-17, -16, 21], [-46, -13, -20], [23, -29, 57], [4, 33, -47], [-10, -23, -26], [-6, 10, 22], [-7, 22, -23], [2, 22, -32], [-67, 31, -21], [-41, -26, -3], [16, 17, -14], [-2, 26, 21], [-9, -12, 21], [30, -64, 49], [70, -6, 17], [15, -9, 15], [-43, 11, -9], [21, -12, 52], [48, -28, -7], [4, 29, -16], [41, -34, 40], [33, -25, -17], [3, 3, 52], [-65, 13, -26], [-41, 40, -14], [78, -12, 28], [53, -32, 27]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1521_a_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1521_2_a_o();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose lines below.
// The precision argument determines an initial guess on how many Fourier coefficients to use.
// This guess is increased enough to uniquely determine the newform.
function MakeNewformModFrm_1521_2_a_o(:prec:=3)
    chi := MakeCharacter_1521_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 2));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 1;
    while true do
        trunc_vec := Vector(Kf, [0] cat [f_vec[i]: i in [1..prec]]);
        B := Basis(S, prec + 1);
        S_basismat := Matrix([AbsEltseq(g): g in B]);
        if Rank(S_basismat) eq Min(NumberOfRows(S_basismat), NumberOfColumns(S_basismat)) then
            S_basismat := ChangeRing(S_basismat,Kf);
            f_lincom := Solution(S_basismat,trunc_vec);
            f := &+[f_lincom[i]*Basis(S)[i] : i in [1..#Basis(S)]];
            return f;
        end if;
        error if prec eq maxprec, "Unable to distinguish newform within newspace";
        prec := Min(Ceiling(1.25 * prec), maxprec);
    end while;
end function;


// To make the Hecke irreducible modular symbols subspace (type ModSym)
// containing the newform, type "MakeNewformModSym_1521_2_a_o();".
// This may take a long time!  To see verbose output, uncomment the SetVerbose line below.
// The default sign is -1.  You can change this with the optional parameter "sign".
function MakeNewformModSym_1521_2_a_o( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1521_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![-1, -1, 2, 1]>,<5,R![-1, 3, 4, 1]>,<7,R![13, -4, -3, 1]>],Snew);
    return Vf;
end function;