
// Make newform 450.3.i.b in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_450_i();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_450_i_Hecke();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_450_3_i_b();".
// 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_450_3_i_b();".
// 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 := [4, 0, -2, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]];
    Rf_basisdens := [1, 1, 2, 2];
    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_450_i();"
function MakeCharacter_450_i()
    N := 450;
    order := 6;
    char_gens := [101, 127];
    v := [1, 6];
    // 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_450_i_Hecke();"
function MakeCharacter_450_i_Hecke(Kf)
    N := 450;
    order := 6;
    char_gens := [101, 127];
    char_values := [[1, 0, -1, 0], [1, 0, 0, 0]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := true, Kf := Kf); // the value of chi on the gens as elements in the Hecke field
    F := Universe(values);// the Hecke field
    chi := DirichletCharacterFromValuesOnUnitGenerators(DirichletGroup(N,F),values);
    return chi;
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 := 3;
    raw_aps := [[0, 1, 0, -1], [1, -2, -2, 1], [0, 0, 0, 0], [0, 3, -1, 3], [6, 3, -3, -3], [5, 6, -5, -12], [6, 0, -12, 6], [-10, 12, 0, -6], [-3, -3, -3, 0], [6, -6, -3, 6], [19, 9, -19, -18], [-32, 12, 0, -6], [-21, -18, -21, 0], [0, -9, 23, -9], [-18, 21, 9, -21], [30, 0, -60, 30], [21, 39, 21, 0], [0, 18, 31, 18], [53, -9, -53, 18], [30, 0, -60, -24], [52, 36, 0, -18], [0, -15, 7, -15], [126, -15, -63, 15], [30, 0, -60, 66], [0, 42, -7, 42], [-6, -108, 3, 108], [-37, 27, 37, -54], [-60, 0, 120, 48], [-16, 108, 0, -54], [-9, -132, -9, 0], [34, -36, 0, 18], [69, -81, 69, 0], [-222, -30, 111, 30], [-11, -39, 11, 78], [3, -78, 3, 0], [0, 45, 175, 45], [-109, -36, 109, 72], [58, 156, 0, -78], [99, -87, 99, 0], [-18, -60, 9, 60], [96, 0, -192, -84], [140, -84, 0, 42], [-6, -9, 3, 9], [125, -90, -125, 180], [24, 0, -48, -84], [80, -60, 0, 30], [103, 21, -103, -42], [0, -45, 203, -45], [-54, -87, 27, 87], [-143, -108, 143, 216], [48, 0, -96, 48], [-9, 51, -9, 0], [0, 24, -143, 24], [-48, 0, 96, 96], [27, -24, 27, 0], [-462, 45, 231, -45], [-30, 0, 60, 6], [-34, 252, 0, -126], [0, 0, -49, 0], [-210, -114, 105, 114], [-145, -81, 145, 162], [87, 96, 87, 0], [-110, -36, 0, 18], [-93, 63, -93, 0], [0, 12, -397, 12], [330, -126, -165, 126], [0, 93, -245, 93], [335, 12, -335, -24], [-207, -159, -207, 0], [0, -84, -107, -84], [210, -102, -105, 102], [-36, 0, 72, -252], [0, -45, 77, -45], [113, -138, -113, 276], [-328, 132, 0, -66], [183, 297, 183, 0], [-78, -72, 39, 72], [124, 108, 0, -54], [195, -54, 195, 0], [385, 24, -385, -48], [-153, 195, -153, 0], [0, 6, -269, 6], [-276, 0, 552, 156], [-344, 108, 0, -54], [0, -171, 139, -171], [-162, 489, 81, -489], [54, 0, -108, 450], [0, -126, 401, -126], [-138, -78, 69, 78], [-283, -93, 283, 186], [-60, 0, 120, 516], [558, 123, -279, -123], [190, 132, 0, -66], [345, -249, 345, 0], [-35, -243, 35, 486], [342, 0, -684, 216], [195, 378, 195, 0], [-168, 0, 336, -60], [-488, -324, 0, 162], [-274, -192, 0, 96], [0, 207, 41, 207], [-318, 0, 636, -102], [333, 21, 333, 0], [-6, -180, 3, 180], [7, 33, -7, -66], [88, 36, 0, -18], [582, 45, -291, -45], [78, 0, -156, 150], [-483, -33, -483, 0], [0, 18, 751, 18], [-745, 183, 745, -366], [-56, 468, 0, -234], [21, 162, 21, 0], [0, 9, 175, 9], [-58, -84, 0, 42], [-318, -24, 159, 24], [593, -81, -593, 162], [36, 0, -72, -252], [375, -84, 375, 0], [-42, 279, 21, -279], [-395, 252, 395, -504], [0, -174, 137, -174], [-66, -288, 33, 288], [180, 0, -360, -576], [0, -135, -707, -135], [366, 0, -732, -102], [0, 336, 349, 336], [-180, 0, 360, 144], [0, -81, -643, -81], [-55, 270, 55, -540], [272, -540, 0, 270], [-297, -375, -297, 0], [241, 429, -241, -858], [-866, -144, 0, 72], [-369, 222, -369, 0], [157, -204, -157, 408], [234, 0, -468, -90], [359, -189, -359, 378], [-63, 858, -63, 0], [-6, 0, 12, 174], [74, 540, 0, -270], [174, 774, -87, -774], [-1579, 15, 1579, -30], [-444, 0, 888, 132], [980, 84, 0, -42], [-54, 771, 27, -771], [0, 162, 77, 162], [-990, -42, 495, 42], [-245, -291, 245, 582], [528, 0, -1056, 276], [317, 282, -317, -564], [510, 0, -1020, -462], [838, -444, 0, 222], [-87, 513, -87, 0], [0, -345, 335, -345], [198, -777, -99, 777], [38, -1044, 0, 522], [558, -102, -279, 102], [-896, -348, 0, 174], [165, -456, 165, 0], [450, 273, -225, -273], [342, 0, -684, 90], [629, 243, -629, -486], [90, 0, -180, 576], [15, -1092, 15, 0], [-30, -567, 15, 567], [650, -180, 0, 90], [0, -396, 275, -396]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_450_i_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_450_3_i_b();".
// 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_450_3_i_b(:prec:=4)
    chi := MakeCharacter_450_i();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 3));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(997) - 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_450_3_i_b();".
// 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_450_3_i_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_450_i();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<7,R![2809, -106, 57, 2, 1]>],Snew);
    return Vf;
end function;