
// Make newform 275.4.b.c in Magma, downloaded from the LMFDB on 09 May 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_275_b();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_275_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_275_4_b_c();".
// 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_275_4_b_c();".
// 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, 0, -1, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 0, 0, 1], [-1, 0, 2, 0], [0, 2, 0, -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_275_b();"
function MakeCharacter_275_b()
    N := 275;
    order := 2;
    char_gens := [177, 101];
    v := [1, 2];
    // 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_275_b_Hecke();"
function MakeCharacter_275_b_Hecke(Kf)
    N := 275;
    order := 2;
    char_gens := [177, 101];
    char_values := [[-1, 0, 0, 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 := 4;
    raw_aps := [[0, 1, -1, 0], [0, 1, -4, 0], [0, 0, 0, 0], [0, 10, 4, 0], [-11, 0, 0, 0], [0, -40, -20, 0], [0, -62, -12, 0], [-36, 0, 0, 60], [0, 49, -36, 0], [-72, 0, 0, -56], [-17, 0, 0, -28], [0, 27, 8, 0], [268, 0, 0, 4], [0, 30, -16, 0], [0, -136, 120, 0], [0, 246, -56, 0], [-317, 0, 0, -132], [420, 0, 0, -184], [0, 377, 20, 0], [-339, 0, 0, -76], [0, 200, -468, 0], [-158, 0, 0, 656], [0, -234, 120, 0], [921, 0, 0, -328], [0, 1097, -144, 0], [566, 0, 0, 420], [0, 880, 488, 0], [0, 174, -380, 0], [-490, 0, 0, 320], [0, 855, 664, 0], [0, -604, 412, 0], [-222, 0, 0, 796], [0, 905, -408, 0], [1466, 0, 0, 828], [-530, 0, 0, -1708], [-1870, 0, 0, 408], [0, 1409, -616, 0], [0, 2060, -384, 0], [0, 1608, -652, 0], [0, -2058, 144, 0], [2871, 0, 0, 900], [1303, 0, 0, 1216], [2321, 0, 0, 348], [0, 572, 1104, 0], [0, -4322, -464, 0], [-408, 0, 0, 240], [1500, 0, 0, 928], [0, 1973, -1132, 0], [0, 1422, 1844, 0], [-3495, 0, 0, -912], [0, -2304, 1208, 0], [-114, 0, 0, -2424], [1456, 0, 0, -1416], [409, 0, 0, -396], [0, -1226, -1160, 0], [0, -3194, 1724, 0], [-3010, 0, 0, -1168], [3032, 0, 0, -892], [0, 166, -232, 0], [198, 0, 0, -2952], [0, 4964, 136, 0], [0, 3276, 3236, 0], [0, -1588, 52, 0], [-1956, 0, 0, -3192], [0, -3263, 2264, 0], [0, 109, 72, 0], [3607, 0, 0, 2844], [0, 5726, 3444, 0], [0, -632, 3020, 0], [-5106, 0, 0, -932], [0, 2589, -4808, 0], [7808, 0, 0, -2132], [0, 8215, 836, 0], [0, 2726, -1492, 0], [1829, 0, 0, 572], [0, 4585, 1012, 0], [2847, 0, 0, 3440], [0, 9262, -2856, 0], [-2950, 0, 0, 1912], [-2514, 0, 0, -3872], [12100, 0, 0, 1624], [-170, 0, 0, -7688], [2658, 0, 0, -1300], [0, 6755, -2880, 0], [2000, 0, 0, -5672], [0, -10885, -452, 0], [-8315, 0, 0, -5000], [0, -13380, -1624, 0], [6660, 0, 0, 1112], [0, 2243, 3276, 0], [0, -5019, -5852, 0], [-10784, 0, 0, 452], [0, -5641, 7324, 0], [-10472, 0, 0, -1648], [3580, 0, 0, 9520], [0, -8974, 688, 0], [-2487, 0, 0, 2288], [-5859, 0, 0, 7776], [0, -9356, -1788, 0], [-2348, 0, 0, 6732], [0, -7984, -1752, 0], [0, -7910, -2372, 0], [0, 9332, -328, 0], [2472, 0, 0, 4504], [-7180, 0, 0, 5648], [0, -17607, -1224, 0], [0, 484, -6120, 0], [0, -3740, 352, 0], [-11632, 0, 0, 896], [-6994, 0, 0, 6796], [0, 9650, -7056, 0], [0, -4592, -4688, 0], [0, -3246, 11248, 0], [4393, 0, 0, -9844], [8791, 0, 0, -7356], [6375, 0, 0, -7952], [0, -8189, 11940, 0], [0, -6031, -2564, 0], [0, -13183, 3952, 0], [-2338, 0, 0, -7424], [2797, 0, 0, -288], [0, -11006, -7040, 0], [0, 5538, -4436, 0], [0, 21688, 4536, 0], [8993, 0, 0, 10860], [5126, 0, 0, -14332], [-15215, 0, 0, -2256], [15393, 0, 0, -9948], [0, -4029, -2036, 0], [0, -10308, -968, 0], [22750, 0, 0, 2536], [0, 9020, 11664, 0], [3937, 0, 0, -7388], [0, 5666, 17360, 0], [21432, 0, 0, 7484], [-10616, 0, 0, 12828], [0, 24126, -6608, 0], [0, 5656, -5816, 0], [0, -9571, -10080, 0], [-14772, 0, 0, -5124], [23842, 0, 0, 5568], [-8618, 0, 0, 6480], [0, -1887, -17372, 0], [0, -1864, -20724, 0], [-1897, 0, 0, 1752], [37781, 0, 0, -236], [0, -10238, 18896, 0], [0, 13064, 17520, 0], [-19425, 0, 0, -5836], [0, -2352, -6928, 0], [0, -11760, -18180, 0], [11645, 0, 0, -4520], [0, -48940, 88, 0], [0, 25394, 9296, 0], [0, 29652, -4640, 0], [18348, 0, 0, -8488], [-4066, 0, 0, -15712], [8310, 0, 0, -8584], [0, -29524, 2916, 0], [28626, 0, 0, -7624], [0, -2955, -17428, 0], [0, -10102, 17804, 0], [0, -27176, 10968, 0], [-12865, 0, 0, -4452], [0, 12117, 1400, 0], [0, -1815, 17956, 0], [-4304, 0, 0, -19504], [0, -29374, 1484, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_275_b_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_275_4_b_c();".
// 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_275_4_b_c(:prec:=4)
    chi := MakeCharacter_275_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_275_4_b_c();".
// 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_275_4_b_c( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_275_b();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([<2,R![4, 0, 8, 0, 1]>],Snew);
    return Vf;
end function;