
// Make newform 76.3.g.b in Magma, downloaded from the LMFDB on 13 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_76_g();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_76_g_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_76_3_g_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_76_3_g_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 := [100, 0, -10, 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, 10, 10];
    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_76_g();"
function MakeCharacter_76_g()
    N := 76;
    order := 6;
    char_gens := [39, 21];
    v := [3, 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_76_g_Hecke();"
function MakeCharacter_76_g_Hecke(Kf)
    N := 76;
    order := 6;
    char_gens := [39, 21];
    char_values := [[-1, 0, 0, 0], [0, 0, -1, 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]];
    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 := [[2, 0, 0, 0], [-1, 1, -1, 0], [-2, -1, 2, 2], [4, 0, -8, 1], [-1, 0, 2, -5], [0, 0, -6, 0], [-16, -2, 16, 4], [6, 3, 9, -5], [4, -9, -2, 9], [0, 1, -2, 1], [-10, 0, 20, 7], [-24, 10, 0, -5], [13, -4, -13, 8], [-12, -10, -12, 0], [0, 7, 0, -7], [0, 4, 62, 4], [-13, -1, -13, 0], [0, -1, -22, -1], [-34, 21, 17, -21], [34, 14, 34, 0], [-13, 4, 13, -8], [-60, -8, -60, 0], [-19, 0, 38, -19], [0, -22, -8, -22], [-117, 2, 117, -4], [0, 27, -14, 27], [78, 0, -156, 10], [72, 0, -144, 18], [-16, 12, 16, -24], [-49, -8, 0, 4], [-68, 26, 34, -26], [47, -17, 47, 0], [0, 8, 155, 8], [146, 45, -73, -45], [56, 3, -56, -6], [-10, 0, 20, 7], [-80, -4, 80, 8], [5, 0, -10, 63], [-240, -28, 120, 28], [162, 12, -162, -24], [135, 0, -270, -9], [0, -27, 68, -27], [-120, 0, 240, 8], [112, 2, -112, -4], [-72, -30, 0, 15], [44, -46, -22, 46], [46, -68, 46, 0], [-30, -27, -30, 0], [-19, 0, 38, 19], [-208, 16, 0, -8], [55, -20, -55, 40], [48, 0, -96, -64], [0, 10, 121, 10], [-14, 55, 7, -55], [0, 56, 3, 56], [-32, -45, -32, 0], [-20, 32, 20, -64], [-84, 65, -84, 0], [142, 94, 0, -47], [0, -44, -217, -44], [79, 89, 79, 0], [46, -62, 0, 31], [-23, -41, -23, 0], [18, 0, -36, -119], [0, 100, 25, 100], [0, -48, -266, -48], [47, 0, -94, 7], [113, -70, -113, 140], [259, -35, 259, 0], [-332, 64, 0, -32], [-41, 20, 0, -10], [-38, 47, -38, 0], [-396, 13, 198, -13], [280, 8, 0, -4], [-178, 0, 356, 60], [168, -103, 168, 0], [0, 4, -400, 4], [184, -63, -184, 126], [-221, -40, 221, 80], [0, -6, 253, -6], [116, 0, -232, 200], [432, -69, -432, 138], [-324, -170, 162, 170], [0, 12, 308, 12], [-162, 3, -162, 0], [378, 35, -189, -35], [-513, -72, 0, 36], [-161, 176, 0, -88], [-306, -96, 306, 192], [-86, 0, 172, 26], [45, 0, -90, -79], [32, 16, -16, -16], [46, 0, -92, 21], [-184, 50, -184, 0], [-7, -187, -7, 0], [-268, -7, 134, 7], [0, -4, 120, -4], [-327, -60, 0, 30], [88, -170, -44, 170], [0, 16, -164, 16], [72, -86, -36, 86], [0, 72, -212, 72], [-179, 0, 358, 55], [536, -172, 0, 86], [-285, 0, 570, 19], [219, -88, 0, 44], [-548, -6, -548, 0], [0, -28, 283, -28], [12, 229, -6, -229], [493, 172, 0, -86], [-240, 0, 480, 35], [538, -84, -538, 168], [0, 6, 165, 6], [100, 0, -200, 82], [640, -41, -320, 41], [329, -12, -329, 24], [-261, 169, -261, 0], [-382, 0, 764, -162], [-256, 216, 0, -108], [872, 32, -436, -32], [0, -7, 270, -7], [176, 24, 0, -12], [-34, 320, 0, -160], [52, 0, -104, -120], [-92, 0, 184, 148], [-166, 191, 166, -382], [0, 181, 76, 181], [-42, -166, -42, 0], [-468, 180, -468, 0], [448, -90, 0, 45], [147, -175, 147, 0], [-54, -157, -54, 0], [-1028, 150, 514, -150], [-650, 84, 650, -168], [425, -308, 0, 154], [0, -104, 516, -104], [0, -139, 218, -139], [255, 0, -510, -169], [340, -342, 0, 171], [-213, 340, 0, -170], [-240, 266, 120, -266], [0, 108, 190, 108], [84, -66, -42, 66], [666, -19, -333, 19], [-600, -200, 0, 100], [256, -201, 256, 0], [570, 60, -570, -120], [-345, 40, 345, -80], [194, -237, -97, 237], [-626, 0, 1252, 195], [-790, 131, 790, -262], [-39, 88, 0, -44], [298, 193, -149, -193], [-288, -108, 144, 108], [-99, 337, -99, 0], [214, 0, -428, -241], [78, 0, -156, 10], [523, 132, -523, -264], [0, -248, -305, -248], [0, -32, -138, -32], [284, 180, 284, 0], [-1211, -16, 1211, 32], [-446, 130, -446, 0], [-231, -355, -231, 0], [-659, 236, 0, -118], [528, -24, 528, 0], [168, 448, 168, 0], [0, 177, -310, 177]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_76_g_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_76_3_g_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_76_3_g_b(:prec:=4)
    chi := MakeCharacter_76_g();
    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_76_3_g_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_76_3_g_b( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_76_g();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<3,R![49, -42, 5, 6, 1]>],Snew);
    return Vf;
end function;