
// Make newform 675.4.b.m in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_675_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_675_b_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_675_4_b_m();".
// 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_675_4_b_m();".
// 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 := [18, -42, 49, -6, 0, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0], [1544, 0, -9, 21, 49, 3], [1056, -2338, 147, -9, -21, -49], [1872, 0, -81, 189, 107, 27], [5280, -11690, 1737, -45, -105, -245], [-1143, 2505, -523, -60, 27, 63]];
    Rf_basisdens := [1, 334, 1002, 334, 1002, 167];
    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_675_b();"
function MakeCharacter_675_b()
    N := 675;
    order := 2;
    char_gens := [326, 352];
    v := [2, 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;

// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_675_b_Hecke();"
function MakeCharacter_675_b_Hecke(Kf)
    N := 675;
    order := 2;
    char_gens := [326, 352];
    char_values := [[1, 0, 0, 0, 0, 0], [-1, 0, 0, 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 := 4;
    raw_aps := [[0, 0, 2, 0, -1, 0], [0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0], [0, 0, 2, 0, 1, -3], [3, -9, 0, 5, 0, 0], [0, 0, 5, 0, -6, -2], [0, 0, 51, 0, -3, 5], [28, -33, 0, 1, 0, 0], [0, 0, -85, 0, -25, -5], [47, -1, 0, 25, 0, 0], [-39, 19, 0, 17, 0, 0], [0, 0, 138, 0, -55, 25], [-188, -26, 0, -10, 0, 0], [0, 0, -281, 0, 17, 29], [0, 0, -9, 0, -123, 5], [0, 0, 136, 0, -38, 30], [104, 68, 0, 0, 0, 0], [-26, -43, 0, 31, 0, 0], [0, 0, -40, 0, 121, -3], [-64, 182, 0, 30, 0, 0], [0, 0, -306, 0, -59, -3], [-343, -38, 0, -54, 0, 0], [0, 0, -102, 0, -24, 60], [360, 0, 0, 60, 0, 0], [0, 0, -202, 0, -113, -1], [-1081, 53, 0, -25, 0, 0], [0, 0, 126, 0, -365, -145], [0, 0, -70, 0, 320, -80], [-748, -290, 0, 130, 0, 0], [0, 0, -147, 0, -279, -155], [0, 0, 1190, 0, 226, -38], [-339, 267, 0, -255, 0, 0], [0, 0, 1462, 0, 184, -40], [-602, 75, 0, 165, 0, 0], [-253, -451, 0, -65, 0, 0], [1231, -478, 0, -14, 0, 0], [0, 0, 597, 0, 125, 145], [0, 0, -305, 0, 578, -14], [0, 0, -1952, 0, -464, -100], [0, 0, -670, 0, -670, -110], [-2536, -202, 0, 30, 0, 0], [288, 409, 0, -53, 0, 0], [482, 14, 0, 150, 0, 0], [0, 0, -1106, 0, 623, -89], [0, 0, -1388, 0, -176, -340], [491, -698, 0, -274, 0, 0], [1762, 449, 0, 167, 0, 0], [0, 0, 176, 0, 264, -192], [0, 0, 1356, 0, -198, 190], [468, 662, 0, 226, 0, 0], [0, 0, 2558, 0, -814, 10], [-3702, 876, 0, -80, 0, 0], [-643, 1092, 0, -484, 0, 0], [1371, 507, 0, -75, 0, 0], [0, 0, 2667, 0, -711, 165], [0, 0, 3804, 0, -1032, -40], [-243, 1179, 0, -275, 0, 0], [3224, -567, 0, -481, 0, 0], [0, 0, -342, 0, -1516, 188], [-5606, 238, 0, -230, 0, 0], [0, 0, 1096, 0, 188, 276], [0, 0, -5350, 0, 200, 160], [0, 0, 4957, 0, 567, 179], [2756, 152, 0, 860, 0, 0], [0, 0, -2960, 0, 137, 529], [0, 0, -856, 0, 68, 500], [4814, 177, 0, 871, 0, 0], [0, 0, 960, 0, 929, 273], [0, 0, -2852, 0, 1246, 490], [2118, 2123, 0, -831, 0, 0], [0, 0, -1945, 0, -55, 445], [884, -1642, 0, 1010, 0, 0], [0, 0, -390, 0, -295, -955], [0, 0, -3409, 0, 1674, 718], [-2536, 2359, 0, -103, 0, 0], [0, 0, -733, 0, 929, -395], [3899, -2107, 0, -445, 0, 0], [0, 0, 3503, 0, 1711, -293], [-11248, 674, 0, 290, 0, 0], [-2191, -266, 0, -278, 0, 0], [-8449, 497, 0, 415, 0, 0], [7336, -1987, 0, -641, 0, 0], [664, -3002, 0, -230, 0, 0], [0, 0, 3426, 0, -872, -264], [5792, 256, 0, 1688, 0, 0], [0, 0, -500, 0, -2360, -1000], [410, -1810, 0, -1650, 0, 0], [0, 0, -900, 0, -634, 702], [1142, -1126, 0, 1490, 0, 0], [0, 0, -3246, 0, -1721, -1037], [0, 0, 1472, 0, 2384, 1100], [7192, -1466, 0, -50, 0, 0], [0, 0, 2920, 0, 1203, 1311], [-780, 2310, 0, 490, 0, 0], [-108, -364, 0, -252, 0, 0], [0, 0, -10285, 0, 2075, 855], [1231, 3547, 0, -55, 0, 0], [-2836, -3742, 0, 30, 0, 0], [0, 0, 2741, 0, 1074, 418], [-8146, -201, 0, -443, 0, 0], [0, 0, 3177, 0, 446, -498], [0, 0, -4768, 0, -2056, -860], [0, 0, -6554, 0, 3022, -850], [7700, 1280, 0, 740, 0, 0], [12254, -1581, 0, 597, 0, 0], [0, 0, 12048, 0, -1537, -2009], [0, 0, -10022, 0, 616, 440], [0, 0, -6379, 0, -283, -435], [-13894, 1172, 0, 400, 0, 0], [1, -2239, 0, 83, 0, 0], [0, 0, -11242, 0, 3121, -203], [0, 0, -13339, 0, 888, -1124], [0, 0, 6185, 0, -3175, -995], [722, -2627, 0, 1219, 0, 0], [-2008, -1335, 0, -1705, 0, 0], [13142, 74, 0, -1210, 0, 0], [0, 0, -6305, 0, 689, 1653], [0, 0, 15264, 0, 1458, 950], [0, 0, -1428, 0, 3264, -400], [-8152, -784, 0, -1560, 0, 0], [10086, -827, 0, 1599, 0, 0], [0, 0, -2526, 0, 1879, -137], [0, 0, -19872, 0, -384, 1620], [0, 0, -6588, 0, 3654, 90], [6638, 678, 0, 674, 0, 0], [18013, -539, 0, -505, 0, 0], [-18392, 2355, 0, 505, 0, 0], [12186, 2052, 0, 2280, 0, 0], [0, 0, 19372, 0, -84, 492], [0, 0, -10390, 0, -7152, -984], [23884, -2376, 0, 712, 0, 0], [0, 0, 2005, 0, 1555, 1755], [6931, -3922, 0, -746, 0, 0], [0, 0, -5323, 0, 1588, -2264], [-23858, 424, 0, -200, 0, 0], [-18519, 3212, 0, -1564, 0, 0], [0, 0, 17138, 0, -6124, -920], [0, 0, -19803, 0, -448, 1944], [0, 0, -9868, 0, 1724, 3500], [-3752, 736, 0, -840, 0, 0], [-11554, -3186, 0, 1162, 0, 0], [20554, -5822, 0, -1190, 0, 0], [0, 0, -3120, 0, 6667, 479], [0, 0, 17686, 0, -1478, -4130], [6288, 1991, 0, -1907, 0, 0], [-4870, -2830, 0, 70, 0, 0], [0, 0, -9275, 0, 4244, 1368], [0, 0, 6338, 0, -244, -1920], [25022, 199, 0, 1577, 0, 0], [0, 0, -20635, 0, -1705, -345], [0, 0, -3943, 0, 3562, -186], [17038, 1636, 0, 3660, 0, 0], [0, 0, 16496, 0, -3603, 2049], [0, 0, 20751, 0, -3723, -1455], [0, 0, -3927, 0, 2792, 3224], [1160, 7280, 0, 400, 0, 0], [16973, 9295, 0, -3235, 0, 0], [19328, -6874, 0, -170, 0, 0], [0, 0, -9778, 0, -10895, -1815], [-5135, -2075, 0, 4415, 0, 0], [0, 0, -8242, 0, 1646, 610], [0, 0, 9167, 0, 10169, 3065], [0, 0, 1018, 0, -3453, 519], [-21197, 841, 0, -1745, 0, 0], [0, 0, 1647, 0, -561, -1705], [0, 0, -6189, 0, -4473, 1875], [-14871, 3646, 0, -4802, 0, 0], [0, 0, 13405, 0, -9111, 613]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_675_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_675_4_b_m();".
// 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_675_4_b_m(:prec:=6)
    chi := MakeCharacter_675_b();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 4));
    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_675_4_b_m();".
// 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_675_4_b_m( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_675_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![900, 0, 364, 0, 41, 0, 1]>,<7,R![68856804, 0, 698409, 0, 1606, 0, 1]>,<11,R![-31260, -2888, 5, 1]>],Snew);
    return Vf;
end function;