
// Make newform 1144.2.a.g in Magma, downloaded from the LMFDB on 06 June 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1144_a();"
// To make the coeffs of the qexp of the newform in the Hecke field type "qexpCoeffs();"
// To make the newform (type ModFrm), type "MakeNewformModFrm_1144_2_a_g();".
// 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_1144_2_a_g();".
// 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_1144_a();"
function MakeCharacter_1144_a()
    N := 1144;
    order := 1;
    char_gens := [287, 573, 937, 353];
    v := [1, 1, 1, 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;

function MakeCharacter_1144_a_Hecke(Kf)
    return MakeCharacter_1144_a();
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 := 2;
    raw_aps := [[0, 0], [-1, -1], [-2, 2], [2, -3], [1, 0], [1, 0], [-2, 4], [3, -3], [-4, 3], [-2, 0], [-6, 2], [4, -4], [-10, 1], [-6, 4], [2, 2], [-1, 5], [-2, -2], [-6, 0], [-6, -4], [-10, -2], [-11, 1], [-12, 4], [10, 3], [4, -14], [-14, 8], [2, -6], [4, -11], [-16, 4], [7, -1], [7, 1], [4, 4], [10, -2], [-16, 6], [0, 4], [6, -1], [4, -8], [12, 3], [0, 2], [15, -7], [10, -14], [0, 4], [-13, 9], [11, -17], [-2, -5], [-9, 15], [1, 5], [-12, 8], [-10, 4], [3, 13], [22, -4], [-12, 2], [-11, 11], [2, 11], [-8, 3], [16, -3], [12, -16], [12, -3], [-5, 13], [12, -22], [-11, -11], [-14, -8], [-14, 0], [-8, 16], [9, -15], [20, -11], [-2, -18], [10, -12], [12, -6], [4, -12], [-18, 13], [10, -18], [26, -13], [-23, -3], [26, 2], [-4, -14], [14, -6], [-7, 23], [-4, 8], [-34, -2], [10, 4], [-12, -5], [2, 16], [-14, -3], [7, 1], [2, 8], [-16, -5], [-24, 6], [-3, -15], [25, -11], [-22, 28], [-16, 28], [16, 0], [-2, 0], [-8, 2], [-18, 26], [2, 16], [20, 0], [-20, 11], [-16, 32], [-2, -7], [2, -8], [-38, -1], [12, -34], [8, 18], [0, 20], [-4, -20], [-16, 18], [-6, -1], [11, 15], [-14, 6], [32, -6], [17, 13], [2, -20], [8, -22], [-16, 14], [-8, 3], [24, -14], [-3, 21], [22, -24], [-2, -10], [-12, -8], [46, -6], [-28, 8], [26, -10], [-44, 0], [-40, 0], [18, -26], [0, 16], [28, -3], [14, 9], [-6, -13], [-24, 44], [-13, 3], [40, -7], [-2, 15], [-14, 31], [-6, -16], [-6, -21], [14, -4], [-12, 38], [42, -1], [2, 12], [-20, 23], [-23, -9], [4, 31], [-22, 0], [37, -31], [18, -16], [15, -5], [-4, -2], [27, 15], [-1, 33], [23, -45], [0, -6], [16, -33], [-32, 3], [-34, -8], [34, -38], [26, -30], [13, -35], [-6, 0], [-4, 22], [7, 5], [25, 9], [-16, 8], [12, -26], [-21, -17], [10, -24], [-30, 45], [38, -12], [-14, 13], [8, 0], [20, 12], [22, -40], [24, -21], [44, 9], [-2, 25], [0, -20], [10, 32], [-6, 40], [-22, 26], [32, 2], [41, -17], [46, -24], [16, -40], [16, 31], [6, 26], [-44, 4], [51, -9], [-45, 29], [36, -9], [-6, 21], [-7, -35], [-8, -8], [-14, 4], [-47, 15], [-31, 45], [-13, 41], [-10, 16], [-10, 38], [10, -24], [-20, -4], [28, 12], [46, -30], [32, -32], [-27, 35], [-24, 22], [-48, 34], [17, 1], [-52, 20], [-8, 20], [-14, -24], [-16, -16], [-14, 6], [-30, -25], [-4, 0], [42, -6], [-4, 18], [-16, 54], [8, -10], [26, -38], [24, -36], [8, -12], [-50, -8], [2, 24], [-46, 36], [48, -15], [-40, -16], [28, -52], [-9, -19], [17, 23], [0, 0], [-15, 7], [-12, -6], [8, -40], [-5, -31], [-36, 42], [19, -9], [1, -7], [24, -15], [12, 26], [8, 22], [28, 28], [-32, 32], [15, -25], [50, -18], [-20, -16], [-44, 16], [11, -51], [32, -8], [-50, 12], [-39, 17], [-30, 58], [24, -33], [-6, 30], [-57, 21], [4, 7], [-46, 33], [52, 1], [-42, 23], [-22, -4], [16, 12], [6, 1], [-32, 40], [40, -46], [-15, 41], [-2, 12], [-26, 2], [-44, 24], [28, 0], [-40, -5], [10, 4], [-56, 20], [2, -8], [-16, -30], [-28, -2], [32, -42], [58, -39], [2, 23], [18, -30], [-46, 34], [-14, 24], [4, -2], [-26, -17], [14, 11], [27, -9], [1, 11], [-2, 13], [50, -4], [-4, 18], [16, 9], [44, -16], [7, 11], [-15, 11], [30, 20], [-24, -14], [-68, 5], [11, 17], [38, -8], [41, -25], [16, 20], [-30, 33], [-36, 20], [-53, -21], [-20, -25], [-84, 6], [-16, 13], [32, -39], [-52, 28], [-64, 10], [-6, -36], [-32, 4], [-40, 0], [52, 5], [62, -29], [-12, -22], [-70, 14], [-10, 45], [4, -32], [20, 8], [-6, -38], [42, 30], [-30, -26], [48, 18], [-42, 36], [-68, 15], [-38, 4], [0, -22], [-30, -4], [-74, 6], [46, -36], [-69, 5], [-12, 32], [2, -9], [-18, -9], [46, -6], [-48, 28], [18, -4], [-56, 56], [-62, 8], [-38, 60], [18, -44], [-29, 47], [-68, 16], [-22, -30], [10, -8], [9, -13], [-24, -36], [-11, -49], [35, 25], [-6, 57], [6, -38], [72, -8], [-34, 12], [-6, 18], [14, 26], [-40, 48], [44, -28], [18, 8], [30, 18], [-18, 15], [-22, -36], [20, -48], [-10, -45], [-28, 13], [3, 45], [-26, 13], [35, -27], [42, -34], [40, -29], [33, -35], [-18, -39], [60, -64], [38, 34], [13, 11], [-34, 78], [8, 24], [6, -20], [-42, 36], [-34, -38], [-12, 54], [80, 8], [20, 16], [-34, -35], [39, 5], [20, 8], [-60, 66], [-45, -7], [72, 8], [8, 13], [-36, -28], [28, -12], [-40, 0], [-40, 53], [12, -58], [-54, -28], [51, -31], [-6, 52], [24, -4], [-70, 27], [14, -33], [-24, 17], [-13, 17], [44, 2], [-31, -39], [-32, -8], [28, -12], [2, 27], [8, -58], [30, -12], [-58, -26], [-2, 44], [33, -35], [40, 6], [52, -46], [-32, -27], [-63, 43], [-48, 92], [-18, 32], [-42, 48], [8, -27], [-18, -11], [40, -14], [-54, -6], [20, -22], [-68, 40], [-60, 29], [6, -24], [74, -18], [-40, 30]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1144_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_1144_2_a_g();".
// 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_1144_2_a_g(:prec:=2)
    chi := MakeCharacter_1144_a();
    f_vec := qexpCoeffs();
    Kf := Universe(f_vec);
    // SetVerbose("ModularForms", true);
    // SetVerbose("ModularSymbols", true);
    S := CuspidalSubspace(ModularForms(chi, 2));
    S := BaseChange(S, Kf);
    maxprec := NextPrime(2999) - 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_1144_2_a_g();".
// 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_1144_2_a_g( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_1144_a();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,2,sign)));
    Vf := Kernel([<3,R![1, 3, 1]>,<5,R![-4, 2, 1]>,<7,R![-11, -1, 1]>,<17,R![-20, 0, 1]>],Snew);
    return Vf;
end function;