
// Make newform 3525.2.a.u in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_3525_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_3525_2_a_u();".
// 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_3525_2_a_u();".
// 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 := [2, 4, -4, -2, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [-3, -1, 1, 0], [2, -3, -2, 1]];
    Rf_basisdens := [1, 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_3525_a();"
function MakeCharacter_3525_a()
    N := 3525;
    order := 1;
    char_gens := [2351, 1552, 2026];
    v := [1, 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_3525_a_Hecke(Kf)
    return MakeCharacter_3525_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+1)]];
    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, 1, 0, 0], [1, 0, 0, 0], [0, 0, 0, 0], [-1, 1, 0, -1], [3, -1, 1, 0], [1, 1, 0, 0], [-1, 1, 0, -2], [-1, 0, -2, -1], [-1, -1, 2, -1], [5, 0, 0, 0], [1, 0, 3, 1], [1, 1, 1, 2], [4, 1, -1, 0], [6, -4, 2, 2], [-1, 0, 0, 0], [0, -3, 1, 1], [1, 2, 0, -1], [-5, 4, 2, 2], [-3, 2, -3, -1], [1, 4, -4, 1], [-1, -2, -1, -5], [1, 5, -1, -2], [8, -4, -2, 0], [-1, -2, 1, -5], [6, -4, 0, -2], [1, 0, -1, -3], [-2, 0, -1, 3], [-6, 4, -2, -2], [-5, -2, -1, -3], [-1, 1, -3, 0], [-6, 2, -4, 2], [11, -2, 1, 1], [6, -2, 0, 4], [-2, 0, -7, -2], [8, 0, 4, 8], [11, -2, 2, 1], [12, 0, 2, 2], [-2, -2, 2, 0], [-2, 2, 3, 5], [-3, -3, -2, 4], [6, 0, -4, 0], [-15, 2, -5, 1], [5, 2, -1, -5], [1, -2, 1, -3], [-1, 5, 4, -2], [9, 2, 4, 7], [13, 2, 3, 3], [-13, 0, 1, 3], [3, 3, -8, 1], [15, -10, 3, 3], [2, -10, 2, 0], [11, -2, 1, 1], [-9, 4, -4, -4], [6, -8, -3, 2], [1, 9, -1, 2], [-5, -6, -1, 5], [-4, -2, -4, -4], [-4, -4, 2, -8], [-7, -5, -1, -6], [3, 2, -6, 0], [6, -2, -4, -2], [2, 2, -4, 8], [-2, -4, 5, 1], [11, 3, 1, 2], [4, 9, -3, 5], [-14, 0, -8, -6], [-16, 2, -10, 0], [9, -13, -1, 2], [2, -2, -2, 6], [-7, -4, -1, -9], [21, -12, 5, 7], [-6, -2, -4, -8], [-8, -10, 4, 0], [7, -6, 7, -5], [11, -3, 7, 0], [9, -12, 7, -1], [-13, 18, 0, -6], [14, -14, 4, 4], [24, -16, 6, 8], [3, -2, 1, -1], [-10, -4, 0, 2], [4, 2, 10, -2], [-3, 0, -2, -3], [17, 5, 0, 8], [13, -13, -3, 2], [10, -2, -3, -9], [1, -12, 0, -4], [-20, 0, -4, 4], [-2, -2, 2, 4], [-13, 12, -1, 3], [-15, 1, -4, -5], [0, 0, 9, 4], [-2, -6, -7, 3], [9, 2, 4, 11], [-14, 8, 1, 6], [5, -3, 4, -1], [1, 4, 4, 0], [10, -4, 2, -6], [7, -1, 4, -3], [0, -11, -1, -4], [4, -2, 8, -10], [0, 0, 2, -8], [2, 4, -4, 4], [-2, 0, 0, 4], [1, -3, -9, 2], [-28, 13, -9, -11], [4, 0, -2, 10], [9, 5, 3, 10], [14, -2, 4, -4], [-14, 1, 5, 2], [26, -8, 2, 6], [21, 7, -3, 8], [1, -8, -1, -1], [-24, 4, -4, 0], [13, 2, 7, -9], [-16, 16, -4, -4], [11, 3, 2, 7], [-6, 4, -8, -8], [1, -1, 0, -6], [3, 0, 3, -13], [-20, -3, -3, -6], [7, -1, 2, 4], [0, -2, 14, -6], [-18, 12, 6, 6], [23, -8, 8, 7], [-12, 11, 11, 2], [-10, 2, -4, 10], [7, 2, 6, 5], [-12, 22, -2, -6], [7, -5, -1, 4], [18, -6, 8, -4], [-18, 14, -11, -5], [5, -4, 2, 5], [-23, 8, 5, 3], [18, -2, 10, 0], [-8, -10, 10, 0], [25, 2, 1, 1], [32, -14, 8, 12], [-13, -7, 9, 0], [18, 8, 2, 14], [10, -6, 0, -2], [14, -19, -3, 6], [2, -10, -8, -6], [-11, 4, 7, -7], [-22, 18, 2, -8], [18, 2, 0, 2], [-14, 10, -10, 2], [-1, -1, -5, 6], [1, 2, 10, -1], [-16, 14, -12, -6], [-19, 19, -6, -6], [9, 12, -8, -4], [-34, -6, 1, -5], [-8, -12, -6, 2], [8, -14, 1, 3], [-13, 16, 1, -9], [-9, 6, -14, 1], [24, 0, 0, 12], [-43, 4, 1, -5], [26, 4, 8, 14], [-21, 18, 1, -5], [28, -18, -2, 6], [0, 4, 10, 6], [-30, 2, -14, -2], [5, -1, 16, -2], [6, -4, 1, -3], [30, -4, 10, 6], [11, -15, 4, 2], [0, 0, 12, 6], [3, -3, 9, -12], [5, 14, -8, -1], [-3, -6, -8, -6], [10, -2, -4, -8], [-23, 3, 8, -2], [8, -8, -19, 0], [-11, -16, -2, 2], [-22, 4, 4, 10], [-14, -2, -2, 0], [-18, 16, -12, -6], [-24, 12, -8, -6], [-6, 0, -2, -10], [4, 18, -4, 12], [-1, 21, -1, 6], [-24, -3, -15, 9], [22, -6, 15, 1], [3, 10, -1, 3], [-30, 0, -10, 4], [-3, 1, 6, 13], [-27, 16, -12, 0], [20, 2, 8, 14], [-19, -3, -1, 2], [29, -9, 10, 3], [16, 4, 3, 0], [2, -8, -12, 2], [23, -16, -3, 11], [15, 12, 3, 1], [27, -8, 9, -1], [-27, 5, 2, 4], [-5, -19, -4, 6], [-35, 10, 7, 1], [23, 6, -1, 3], [51, -11, 13, 12], [-6, -17, 5, 1], [-36, 11, 1, -8], [-17, 4, 10, 7], [-5, 26, -13, 3], [18, 14, -3, 0], [10, -2, 10, 10], [-8, 26, -4, 2], [3, -16, 7, -9], [9, 3, -9, 2], [7, 8, -1, 11], [-44, 8, -14, -6], [-14, 16, 5, 1], [-25, 20, 6, 3], [34, -16, 6, 4], [-21, -12, 1, -3], [32, -5, 7, 2], [2, 4, -12, 8], [-11, -7, 11, 6], [-2, -12, -4, 0], [2, -18, -12, 6], [6, 6, -4, -2], [-20, -2, -2, 12], [14, -4, -6, 0], [-20, 18, 10, 2], [5, 3, 19, 2], [-1, -1, 3, 14], [18, 14, 6, 16], [-14, -16, -4, -18], [-30, -11, 9, -5], [-33, 17, -1, 0], [-13, 3, -5, -18], [-7, 2, 21, -3], [-5, 4, -9, -5], [38, -4, -8, 0], [0, -20, 10, 6], [15, 17, -4, 2], [-32, 8, 7, 12], [-10, 22, -7, 0], [8, 8, -9, -5], [29, -7, 7, 18], [-11, 14, 9, -7], [18, 6, 2, -6], [19, -32, -1, 13], [11, 14, 5, -7], [6, 14, 13, -13], [-19, -5, 1, 0], [-21, 13, -11, -6], [-31, -16, 9, -1], [-24, -7, -9, -3], [11, -4, 13, 1], [8, 6, -2, -4], [8, -4, 0, -6], [3, 9, 3, 0], [14, -32, 5, 6], [-31, 8, -23, -1], [49, 4, 3, -1], [-30, -2, -6, -2], [16, -18, 22, -2], [-1, -1, -6, 7], [18, 12, 3, -13], [7, -10, 18, -8], [-5, 9, 3, 4], [-1, 1, 7, 12], [15, 7, -1, -2], [-29, -8, -11, 11], [17, -14, 12, -2], [27, -4, 1, 17], [25, -11, 1, -12], [38, -15, 9, 22], [29, 13, -2, -7], [28, -10, -14, 0], [-3, 16, 13, 17], [10, -7, -11, -1], [-29, -10, 13, -3], [-15, 12, 1, -19], [-23, 10, -16, 6], [11, 14, -13, 9], [37, -24, 10, 21], [10, 6, 2, 26], [15, 10, -12, 9], [16, -16, 0, 0], [-6, 22, -12, 6], [-8, -2, -21, 1], [31, -29, 11, 14], [2, -15, -7, 11], [-10, 12, -4, 6], [28, 10, 11, 2], [-5, 14, -9, -7], [-50, 2, -14, -6], [47, -2, 13, 9], [-9, -5, -1, -2], [20, -8, -9, 0], [22, 4, -10, 0], [40, 5, 13, -10], [9, -23, 1, 16], [-38, 8, -14, -18], [7, -7, 17, 10], [-11, -4, -3, -1], [-21, -3, 4, 10], [23, -33, -1, 6], [1, -13, -7, -16], [14, 0, 20, 0], [30, 2, 12, -2], [15, -13, 4, 16], [-3, 4, -5, 9], [-24, 13, -1, -8], [0, 34, -3, -2], [-14, 0, 2, 18], [-23, -8, -1, 17], [-2, -18, -14, -4], [-51, 6, -14, -16], [-11, -2, 1, -11], [-20, 8, 3, -13], [-9, 18, -6, 16], [-24, -12, -4, -2], [-33, 3, -17, 2], [-11, -11, 6, -20], [-25, 12, -19, 9], [3, 9, 15, 14], [-5, -5, -14, -8], [66, -16, 0, 4], [-39, -19, 6, -15], [46, 0, 14, 20], [-29, 22, -7, 1], [-12, -12, 12, -16], [18, -6, -6, 0], [52, -2, 4, 6], [-31, 0, 5, -5], [-6, 11, 17, 12], [-42, 17, -15, -5], [11, 4, 6, -1], [-30, 32, 6, -8], [52, -8, -4, -4], [56, 12, -7, 9], [0, -2, 2, 26], [8, 11, 7, 11], [5, -14, -10, 0], [31, -10, -11, -13], [19, 7, 13, 4], [33, -31, -9, 4], [19, 6, -5, 11], [-61, 17, -17, -10], [-50, 12, -20, 0], [33, -4, 14, -7], [-11, 18, -5, -1], [20, 6, -2, -10], [-11, -30, 6, -5], [-27, 11, -8, -18], [-12, 0, -10, -8], [23, 15, 5, -2], [-2, -12, -2, -2], [23, 0, 31, 5], [24, 2, 0, 6], [-22, -16, -6, -2], [-17, -12, 5, -17], [-30, 8, -9, 6], [-55, 21, 1, -2], [29, 5, 20, 7], [-12, 21, -31, 1], [9, -18, -14, 16], [6, 10, 14, 16], [-26, -12, -16, 14], [-11, -6, -3, -15], [-15, 12, -13, 3], [-33, -1, -1, 4], [7, 3, -16, -7], [-47, 12, -3, -5], [11, 11, 1, 4], [-15, 7, -9, 22], [-34, 4, -14, 2], [44, -14, -4, 6], [4, -10, -7, -14], [6, 5, 5, 3], [-60, 30, -16, -14], [17, -4, 10, 5], [-2, -14, 12, -4], [-10, 2, 22, 2], [27, 5, 23, 6], [-13, 28, -7, -1], [2, 19, -7, -7], [17, -6, 5, 25], [-1, 17, 0, -14], [24, -12, -10, 14], [49, -13, 8, 1], [-14, 6, -11, 4], [16, -5, 3, -1], [2, 24, 9, 13], [-6, 26, -8, -20], [-7, -14, 1, 27], [-46, 13, -13, 3], [1, -15, 9, 10], [3, -9, -2, -5], [-20, -6, -31, 6], [-4, 20, 12, -4], [-27, 40, -2, -19], [9, -22, 15, -11], [-11, 20, 9, -7], [20, 3, 11, -18], [-76, 8, -8, -4], [-31, 5, 6, -4], [36, -34, -4, 4], [20, -13, 35, -9], [13, 0, -3, 9], [23, -1, -19, -2], [-34, 16, -8, -20], [-14, 16, -10, -20], [59, -4, 1, 3], [45, -5, 5, 2], [19, 17, -6, 6], [16, -23, -21, -19], [16, -36, 12, 4], [-75, 14, -9, -13], [-40, 30, 2, -16], [-58, 4, -8, -12], [10, -2, -15, 0], [-10, 32, -10, 4], [19, -3, 29, -10], [-4, -16, -2, -14], [-12, -38, 16, -2], [62, 14, -2, 0], [3, 27, 4, -11], [-9, 24, -3, -17], [-12, 29, -9, 5], [-47, 9, 5, 6], [37, -8, -11, 3], [-42, -14, -6, -2], [12, -12, -11, 0], [59, 11, 5, 22]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_3525_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_3525_2_a_u();".
// 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_3525_2_a_u(:prec:=4)
    chi := MakeCharacter_3525_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_3525_2_a_u();".
// 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_3525_2_a_u( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_3525_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<2,R![1, -6, -4, 2, 1]>,<7,R![5, 16, -14, 0, 1]>,<11,R![-12, 8, 12, -8, 1]>],Snew);
    return Vf;
end function;