
// Make newform 7.4.c.a in Magma, downloaded from the LMFDB on 17 December 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_7_c();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_7_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_7_4_c_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_7_4_c_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, -1, 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_7_c();"
function MakeCharacter_7_c()
    N := 7;
    order := 3;
    char_gens := [3];
    v := [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_7_c_Hecke();"
function MakeCharacter_7_c_Hecke( : Kf := false)
    N := 7;
    order := 3;
    char_gens := [3];
    char_values := [[-1, 1]];
    assert UnitGenerators(DirichletGroup(N)) eq char_gens;
    values := ConvertToHeckeField(char_values : pass_field := ISA(Type(Kf), Fld), 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 := 4;
    raw_aps := [[-2, 2], [0, -7], [-7, 7], [21, -14], [0, 5], [-14, 0], [0, 21], [-49, 49], [159, -159], [58, 0], [0, -147], [-219, 219], [350, 0], [-124, 0], [-525, 525], [0, -303], [0, 105], [413, -413], [0, -415], [-432, 0], [0, 1113], [103, -103], [1092, 0], [329, -329], [-882, 0], [0, -1379], [679, -679], [-457, 457], [0, 1125], [-1538, 0], [72, 0], [-2149, 2149], [0, 1125], [252, 0], [201, -201], [0, -1619], [0, -679], [467, -467], [1204, 0], [2821, -2821], [0, 3253], [1582, 0], [-2557, 2557], [0, 397], [2914, 0], [0, -3339], [1780, 0], [-1400, 0], [0, 2205], [-287, 287], [-4587, 4587], [1668, 0], [0, 3409], [-4760, 0], [805, -805], [0, 257], [0, -3591], [-1393, 1393], [0, -415], [-4954, 0], [0, 4277], [7742, 0], [-7364, 0], [0, -9975], [4753, -4753], [3477, -3477], [-3341, 3341], [7366, 0], [0, -7415], [-3878, 0], [0, -1267], [-4685, 4685], [0, 4641], [8797, -8797], [13680, 0], [-9765, 9765], [0, -1731], [-10983, 10983], [-6603, 6603], [0, -10955], [6636, 0], [-16630, 0], [0, -4923], [8974, 0], [4179, -4179], [12927, -12927], [-2826, 0], [-8479, 8479], [9338, 0], [-4016, 0], [5859, -5859], [0, -6503], [0, 16049], [8864, 0], [10211, -10211], [-1680, 0], [9457, -9457], [0, 18081], [-20377, 20377], [6193, -6193], [-18464, 0], [0, 9413], [0, -3199], [-21583, 21583], [0, -20267], [0, -13951], [-20972, 0], [189, -189], [0, 10281], [-6090, 0], [-4949, 4949], [0, 15797], [-9378, 0], [0, 24353], [-12640, 0], [0, 1041], [9548, 0], [0, 3241], [8853, -8853], [7044, 0], [0, 12089], [982, 0], [30513, -30513], [0, -11475], [28315, -28315], [10614, 0], [-10299, 10299], [-32529, 32529], [29456, 0], [-27867, 27867], [0, -19539], [1248, 0], [-28093, 28093], [35954, 0], [861, -861], [24710, 0], [0, -16499], [0, -16471], [-36470, 0], [0, -35751], [-16492, 0], [41473, -41473], [0, 25065], [9732, 0], [0, -27755], [21112, 0], [-21238, 0], [0, 35609], [-2177, 2177], [32247, -32247], [-27631, 27631], [24402, 0], [-19612, 0], [-2261, 2261], [0, 23833], [31824, 0], [16819, -16819], [-1799, 1799], [14154, 0], [0, -12047], [24379, -24379], [-52330, 0], [-12416, 0], [-36813, 36813], [0, -34995], [0, 14301], [0, 2665], [0, -24871]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_7_c_Hecke( : Kf := Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_7_4_c_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_7_4_c_a(:prec:=2)
    chi := MakeCharacter_7_c();
    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_7_4_c_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_7_4_c_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_7_c();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,4,sign)));
    Vf := Kernel([],Snew);
    return Vf;
end function;