
// Make newform 400.6.c.o in Magma, downloaded from the LMFDB on 19 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_400_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_400_c_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_400_6_c_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_400_6_c_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 := [3600, 0, 121, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0], [0, 61, 0, 1], [0, 181, 0, 1], [121, 0, 2, 0]];
    Rf_basisdens := [1, 60, 60, 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_400_c();"
function MakeCharacter_400_c()
    N := 400;
    order := 2;
    char_gens := [351, 101, 177];
    v := [2, 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_400_c_Hecke();"
function MakeCharacter_400_c_Hecke(Kf)
    N := 400;
    order := 2;
    char_gens := [351, 101, 177];
    char_values := [[1, 0, 0, 0], [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 := 6;
    raw_aps := [[0, 0, 0, 0], [0, -4, -1, 0], [0, 0, 0, 0], [0, -4, -2, 0], [100, 0, 0, 21], [0, -296, -52, 0], [0, -139, 16, 0], [-420, 0, 0, 59], [0, 976, 98, 0], [2340, 0, 0, -148], [2504, 0, 0, 354], [0, -6250, -484, 0], [-2667, 0, 0, 936], [0, -112, -1076, 0], [0, 13036, 0, 0], [0, -23406, 360, 0], [-40888, 0, 0, -416], [-23466, 0, 0, 44], [0, 34404, 323, 0], [-3724, 0, 0, 344], [0, -54411, 72, 0], [-54052, 0, 0, 3062], [0, -13612, 3841, 0], [-35495, 0, 0, -5024], [0, 48426, 3800, 0], [-75534, 0, 0, -7860], [0, -100276, 1240, 0], [0, 57260, 5165, 0], [-70714, 0, 0, 8980], [0, -32127, 11064, 0], [0, -54896, 7738, 0], [-133880, 0, 0, 988], [0, 148469, -4104, 0], [122708, 0, 0, 2939], [-268884, 0, 0, 12964], [-122748, 0, 0, 12134], [0, 122882, -27104, 0], [0, -386276, -5643, 0], [0, -166580, -6512, 0], [0, -174096, -34088, 0], [298028, 0, 0, 21727], [-224134, 0, 0, -20856], [-149864, 0, 0, 14846], [0, 76475, -3216, 0], [0, -188770, -33168, 0], [-212480, 0, 0, 18428], [659420, 0, 0, 22459], [0, 384176, -15660, 0], [0, 796568, 22316, 0], [879396, 0, 0, 26920], [0, -24790, 41936, 0], [-368508, 0, 0, 41148], [-463215, 0, 0, -14888], [453436, 0, 0, -84869], [0, -767530, -15400, 0], [0, 1315224, -24726, 0], [1305376, 0, 0, 42320], [413976, 0, 0, -98910], [0, -209556, 6676, 0], [337334, 0, 0, -89544], [0, 577676, 23997, 0], [0, 4254, -24868, 0], [0, -251700, -87527, 0], [-17268, 0, 0, 140026], [0, 1263198, -104824, 0], [0, -214028, 80680, 0], [2532212, 0, 0, 19145], [0, 341835, -73864, 0], [0, 1551172, -50971, 0], [-230386, 0, 0, -22564], [0, 426594, -133256, 0], [276084, 0, 0, -203418], [0, -4253640, 27020, 0], [0, 2615534, 37224, 0], [2631580, 0, 0, 54225], [0, 240900, -116226, 0], [-2611998, 0, 0, -153168], [0, 2094756, -46528, 0], [3088757, 0, 0, 151616], [-25317, 0, 0, 390592], [3215004, 0, 0, -157473], [-2173268, 0, 0, 268984], [-4301028, 0, 0, -81542], [0, 638459, -184736, 0], [-2772716, 0, 0, 213588], [0, -749996, 340345, 0], [-292377, 0, 0, 237504], [0, 3955233, 282512, 0], [309652, 0, 0, -225080], [0, -1784552, 376444, 0], [0, 8519040, -34268, 0], [-1620336, 0, 0, 444202], [0, -5713696, -196854, 0], [-1389816, 0, 0, -414900], [-4347816, 0, 0, -141572], [0, -141488, -124724, 0], [2776494, 0, 0, 223808], [524845, 0, 0, 107840], [0, -4661844, 164831, 0], [-7154632, 0, 0, 342520], [0, 2135468, -415751, 0], [0, -443152, -246404, 0], [0, -5566248, -455336, 0], [3397855, 0, 0, 339872], [5837488, 0, 0, -587812], [0, 1959467, -133800, 0], [0, 13406660, -154057, 0], [0, -4227951, 616248, 0], [-3995972, 0, 0, -204962], [-8185221, 0, 0, 475136], [0, -8455544, 506536, 0], [0, 4697026, -44144, 0], [0, 1202638, 453376, 0], [-696520, 0, 0, 171756], [5065872, 0, 0, 848362], [7369506, 0, 0, 18312], [0, -1625920, 264332, 0], [0, -1308912, -224580, 0], [0, -1253826, -995780, 0], [9343556, 0, 0, -390343], [-10216044, 0, 0, -623028], [0, 13850374, 9088, 0], [0, 9060680, -382008, 0], [0, 2730188, 400031, 0], [9371700, 0, 0, 931841], [16653224, 0, 0, -59948], [-5239820, 0, 0, 534552], [17202892, 0, 0, 284186], [0, -24254916, -199948, 0], [0, 13885432, 102028, 0], [8002864, 0, 0, -157148], [0, 9570928, 382498, 0], [-2143780, 0, 0, -1280476], [0, 4823736, -197576, 0], [8837893, 0, 0, -709064], [3656659, 0, 0, 486752], [0, 5999676, 537036, 0], [0, -6642408, 557060, 0], [0, 6074522, -420160, 0], [-747450, 0, 0, -779112], [614992, 0, 0, -1190724], [14295122, 0, 0, 839880], [0, 1948856, -322532, 0], [0, 1674852, 690615, 0], [7901216, 0, 0, -483204], [7754992, 0, 0, -633792], [0, -377138, -1356120, 0], [0, 12555853, -583904, 0], [-8787084, 0, 0, 529435], [0, 1631740, 2012092, 0], [0, 762700, 1837896, 0], [7282870, 0, 0, -283400], [0, 27319812, 40447, 0], [0, 34264016, -341876, 0], [0, -13389200, 938812, 0], [15082136, 0, 0, -234956], [-11333248, 0, 0, -229134], [29542418, 0, 0, -598064], [0, -18576949, -67424, 0], [1666080, 0, 0, 384076], [0, 2501624, -2696576, 0], [0, -28357625, -1458224, 0], [0, 40914408, 699528, 0], [8974828, 0, 0, 1799837], [0, 28000417, 222000, 0], [0, -9014204, -2742050, 0], [-3733404, 0, 0, 1081514], [0, -18597132, -2007840, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_400_c_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_400_6_c_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_400_6_c_o(:prec:=4)
    chi := MakeCharacter_400_c();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 6));
    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_400_6_c_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_400_6_c_o( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_400_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,6,sign)));
    Vf := Kernel([<3,R![50625, 0, 514, 0, 1]>],Snew);
    return Vf;
end function;