
// Make newform 78.3.l.a in Magma, downloaded from the LMFDB on 24 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_78_l();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_78_l_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_78_3_l_a();".
// 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_78_3_l_a();".
// 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;
    Rfbasis := [Kf.1^i : i in [0..Degree(Kf)-1]];
    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_78_l();"
function MakeCharacter_78_l()
    N := 78;
    order := 12;
    char_gens := [53, 67];
    v := [12, 11];
    // 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_78_l_Hecke();"
function MakeCharacter_78_l_Hecke(Kf)
    N := 78;
    order := 12;
    char_gens := [53, 67];
    char_values := [[1, 0, 0, 0], [0, 1, 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, -1, 1], [0, 1, 0, 1], [-4, -2, 2, 4], [0, 0, -5, 5], [-2, -8, 10, 10], [0, 13, 0, 0], [4, -12, 4, 0], [19, -19, -7, 12], [16, 18, -8, -18], [0, -10, 0, -10], [29, 5, -5, -29], [-36, 13, 23, 23], [-28, -20, 8, -8], [5, 24, 5, 0], [18, 30, 30, 18], [18, 92, 0, -46], [44, 44, -46, 2], [-36, -25, 36, 50], [-43, -31, 12, -12], [68, -68, -46, 22], [-59, 23, 23, -59], [24, 14, 0, -7], [40, -52, 52, -40], [40, -104, 64, 64], [84, -84, -13, 71], [-188, 24, 94, -24], [-55, 0, 110, 12], [0, 28, -54, 28], [96, 35, -35, -96], [66, 12, -66, -24], [240, -29, -120, 29], [-78, 152, 0, -76], [-86, -86, 82, 4], [-29, -72, 29, 144], [-8, 8, -80, -88], [-77, -60, -60, -77], [97, 48, 0, -24], [187, 187, -156, -31], [48, 132, -180, -180], [58, -168, 58, 0], [-136, 168, 68, -168], [36, 0, -72, -240], [-180, 10, 180, -20], [25, 24, -49, -49], [172, 128, -44, 44], [-12, -43, -12, 0], [0, -53, -156, -53], [-108, 7, 115, -115], [34, -34, -2, 32], [107, 132, 132, 107], [-102, 0, 204, -204], [-36, 96, -96, 36], [47, 47, -11, -36], [-72, 84, -72, 0], [-136, -192, 68, 192], [0, 76, 156, 76], [6, -98, -6, 196], [-19, -204, 223, 223], [-168, 156, -168, 0], [64, 190, 190, 64], [-72, -79, 36, 79], [138, 138, 60, -198], [281, -257, -257, 281], [126, 0, -252, 78], [-216, -386, 0, 193], [-84, 144, -144, 84], [-19, 19, -204, -223], [84, 0, -168, -493], [-216, 128, 216, -256], [-109, 277, -168, -168], [-358, -74, 284, -284], [-6, -192, -192, -6], [0, -12, 197, -12], [-132, -203, 132, 406], [197, 132, -65, 65], [148, -148, -176, -28], [-14, 0, 28, 42], [-25, -25, -168, 193], [-288, 258, 30, 30], [-408, 408, 397, -11], [0, -36, 720, -36], [253, 205, -205, -253], [244, -112, -356, 356], [-12, 217, -12, 0], [422, -324, -211, 324], [-162, 164, 0, -82], [116, 116, -178, 62], [-179, -143, 36, -36], [258, -258, 174, 432], [-36, 365, 365, -36], [-326, 0, 652, -168], [-4, 260, -256, -256], [137, -137, -137, 0], [-8, 30, 4, -30], [-29, -360, 360, 29], [480, 70, -480, -140], [-502, -164, 338, -338], [402, 284, 0, -142], [0, 60, 62, 60], [-48, -119, -119, -48], [-247, -168, 0, 84], [-240, 378, -138, -138], [266, 372, 266, 0], [-48, 390, 24, -390], [396, 0, -792, 274], [-35, 204, -204, 35], [-306, -258, 48, -48], [314, -58, -58, 314], [-258, -456, 0, 228], [0, -24, -24, -24], [-34, 468, 34, -936], [-431, -143, 288, -288], [82, -82, -92, -10], [-228, -317, -317, -228], [53, 53, 552, -605], [62, 516, 62, 0], [-372, 372, 523, 151], [-352, 18, 176, -18], [0, -482, 186, -482], [-342, -66, 342, 132], [-71, -133, 204, 204], [194, 876, -97, -876], [-474, 324, 0, -162], [-442, -442, 44, 398], [317, 48, -269, 269], [148, 0, -296, 312], [-228, -228, 251, -23], [166, 24, 166, 0], [144, 0, -288, 629], [576, 529, -529, -576], [372, -319, -53, -53], [-458, -616, -158, 158], [120, 264, -60, -264], [0, -480, 636, -480], [652, 652, -80, -572], [132, -781, -913, 913], [406, -406, 376, 782], [-552, -552, 209, 343], [272, -96, 272, 0], [0, -192, -420, -192], [-149, 271, -271, 149], [390, 126, -264, 264], [288, 828, 288, 0], [368, -400, -400, 368], [-1104, -13, 552, 13], [-4, -4, -406, 410], [336, -373, -373, 336], [304, 0, -608, -90], [-336, 1042, 0, -521], [672, -42, 42, -672], [659, -659, 169, 828], [316, -1290, -158, 1290], [-96, 0, 192, 619], [0, -108, -1098, -108], [96, -362, -48, 362], [402, -364, 0, 182], [-660, 48, 660, -96], [820, -820, -212, 608], [264, 504, 0, -252], [-874, -746, 746, 874], [220, 568, -788, -788], [-662, 60, -662, 0], [617, 576, -576, -617], [198, 546, -198, -1092], [52, 224, 172, -172], [1212, -426, -426, 1212], [0, -264, 1414, -264], [-685, 492, 685, -984]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_78_l_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_78_3_l_a();".
// 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_78_3_l_a(:prec:=4)
    chi := MakeCharacter_78_l();
    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_78_3_l_a();".
// 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_78_3_l_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_78_l();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([<5,R![144, 144, 72, 12, 1]>],Snew);
    return Vf;
end function;