
// Make newform 380.3.e.a in Magma, downloaded from the LMFDB on 25 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_380_e();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_380_e_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_380_3_e_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_380_3_e_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 := [55600, 0, 170640, 0, 83244, 0, 15924, 0, 1445, 0, 62, 0, 1];
        Kf := NumberField(Polynomial([elt : elt in poly]));
        AssignNames(~Kf, ["nu"]);
    end if;
    Rf_num := [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 13285720, 0, 10898236, 0, 2290126, 0, 184075, 0, 5868, 0, 59], [0, -14157280, 0, -13082536, 0, -3571816, 0, -373210, 0, -15993, 0, -239], [0, -10740520, 0, -8665084, 0, -2594164, 0, -344590, 0, -20007, 0, -401], [0, -417160, 0, -1502992, 0, -650992, 0, -95740, 0, -5661, 0, -113], [-417160, 0, -1502992, 0, -650992, 0, -95740, 0, -5661, 0, -113, 0], [-46360, 0, -1465912, 0, -650992, 0, -95740, 0, -5661, 0, -113, 0], [1849460, 0, 3463424, 0, 1462904, 0, 228185, 0, 14382, 0, 301, 0], [0, -139060, 0, -1484452, 0, -650992, 0, -95740, 0, -5661, 0, -113], [-1392200, 0, -4123544, 0, -1890134, 0, -291230, 0, -17757, 0, -361, 0], [3524896, 0, 9148096, 0, 3578728, 0, 495898, 0, 28107, 0, 545, 0]];
    Rf_basisdens := [1, 1, 407880, 407880, 203940, 37080, 37080, 37080, 67980, 18540, 67980, 81576];
    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_380_e();"
function MakeCharacter_380_e()
    N := 380;
    order := 2;
    char_gens := [191, 77, 21];
    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_380_e_Hecke();"
function MakeCharacter_380_e_Hecke(Kf)
    N := 380;
    order := 2;
    char_gens := [191, 77, 21];
    char_values := [[1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [-1, 0, 0, 0, 0, 0, 0, 0, 0, 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 := 3;
    raw_aps := [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0], [-1, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, -1], [-2, 0, 0, 0, 0, 0, 0, 1, -1, 0, 0, -1], [0, -1, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, -1, 2, -1, 0, 0, 1], [2, -1, -1, 0, 0, 0, 0, 0, 1, 0, 1, 0], [1, 0, 0, 0, 0, 0, 3, 2, -2, 0, -2, -1], [0, 1, -2, -2, -1, 0, 0, 0, 0, 1, 0, 0], [0, 1, 0, 1, -1, 1, 0, 0, 0, 0, 0, 0], [0, -2, 0, -2, -1, 2, 0, 0, 0, 1, 0, 0], [0, -3, 0, 1, 1, 1, 0, 0, 0, 2, 0, 0], [-15, 0, 0, 0, 0, 0, 2, 2, 1, 0, -2, 2], [-7, 0, 0, 0, 0, 0, -2, 2, 5, 0, 0, 0], [0, 1, 0, 4, 0, -2, 0, 0, 0, 2, 0, 0], [0, 0, -2, -1, 0, 5, 0, 0, 0, -1, 0, 0], [12, 0, 0, 0, 0, 0, 6, 1, -1, 0, -4, 1], [0, -1, 4, 2, -1, 0, 0, 0, 0, -2, 0, 0], [0, 11, 0, -1, -5, -1, 0, 0, 0, -4, 0, 0], [-14, 0, 0, 0, 0, 0, -5, 0, 3, 0, -2, -5], [0, -5, 0, 3, 1, 5, 0, 0, 0, -4, 0, 0], [-19, 0, 0, 0, 0, 0, 14, -6, -3, 0, -2, -8], [0, 8, -4, 0, 0, -10, 0, 0, 0, 0, 0, 0], [0, 16, 4, 0, 1, 8, 0, 0, 0, -3, 0, 0], [0, 0, 0, 0, 0, 0, -4, 5, -11, 0, -4, -9], [0, 2, 0, 0, 2, -12, 0, 0, 0, -5, 0, 0], [0, -1, 8, 4, 7, 6, 0, 0, 0, 0, 0, 0], [0, -4, -2, 3, 4, -5, 0, 0, 0, -1, 0, 0], [0, -6, 0, 2, -2, 14, 0, 0, 0, -3, 0, 0], [0, 16, 8, 2, 1, -10, 0, 0, 0, -5, 0, 0], [14, 0, 0, 0, 0, 0, -38, -8, 6, 0, 12, 14], [36, 0, 0, 0, 0, 0, 1, -8, 15, 0, 8, 5], [-14, 0, 0, 0, 0, 0, -34, -13, 3, 0, -2, 9], [-26, 0, 0, 0, 0, 0, -38, 23, -9, 0, -10, 9], [0, 2, 0, 0, 10, 16, 0, 0, 0, -4, 0, 0], [-24, 0, 0, 0, 0, 0, 36, -6, 8, 0, 8, 2], [-43, 0, 0, 0, 0, 0, -16, -8, 5, 0, 2, 6], [0, -4, 8, -4, -7, -18, 0, 0, 0, -1, 0, 0], [0, -6, -4, 2, 2, 20, 0, 0, 0, 7, 0, 0], [0, 3, -2, 3, 5, -23, 0, 0, 0, 2, 0, 0], [0, 26, -2, 4, 6, 8, 0, 0, 0, 0, 0, 0], [-6, 0, 0, 0, 0, 0, 25, 6, -5, 0, 14, -11], [0, 10, 0, -6, 1, -2, 0, 0, 0, -5, 0, 0], [-40, 0, 0, 0, 0, 0, 22, 26, 6, 0, 2, -2], [-4, 0, 0, 0, 0, 0, 27, -10, -13, 0, -14, -25], [0, -31, -2, -12, -9, 20, 0, 0, 0, -7, 0, 0], [0, 4, -4, 6, -1, 2, 0, 0, 0, -3, 0, 0], [0, 19, 8, 6, -13, 24, 0, 0, 0, 2, 0, 0], [-22, 0, 0, 0, 0, 0, 36, 19, 1, 0, -18, 7], [54, 0, 0, 0, 0, 0, 42, 10, -12, 0, 6, 20], [-104, 0, 0, 0, 0, 0, -17, 34, 3, 0, -16, -5], [0, 3, -4, 3, -3, -27, 0, 0, 0, -4, 0, 0], [100, 0, 0, 0, 0, 0, 20, -4, 14, 0, 8, 10], [0, -52, 4, 2, -7, 12, 0, 0, 0, 5, 0, 0], [49, 0, 0, 0, 0, 0, -72, 18, -41, 0, -2, -26], [0, -35, -6, -3, -5, 3, 0, 0, 0, 12, 0, 0], [48, 0, 0, 0, 0, 0, 65, -5, -20, 0, 10, -6], [108, 0, 0, 0, 0, 0, 32, -22, -16, 0, 0, -2], [0, 47, -4, 1, 11, -7, 0, 0, 0, 4, 0, 0], [19, 0, 0, 0, 0, 0, -90, 20, -19, 0, -6, 14], [0, 9, -4, -4, -4, -2, 0, 0, 0, 10, 0, 0], [0, -80, 12, 16, 8, 18, 0, 0, 0, 5, 0, 0], [92, 0, 0, 0, 0, 0, 47, 7, 10, 0, 10, -8], [68, 0, 0, 0, 0, 0, -67, -40, 27, 0, 8, 45], [0, -15, -8, -10, 1, -14, 0, 0, 0, 14, 0, 0], [0, -53, -2, -12, -13, -28, 0, 0, 0, -1, 0, 0], [0, -32, 4, 10, 12, -10, 0, 0, 0, -15, 0, 0], [23, 0, 0, 0, 0, 0, 100, -6, -7, 0, -4, 2], [110, 0, 0, 0, 0, 0, 30, -32, 14, 0, 14, 58], [-42, 0, 0, 0, 0, 0, 15, -2, 13, 0, -16, 13], [14, 0, 0, 0, 0, 0, -41, -19, 18, 0, 2, -30], [-175, 0, 0, 0, 0, 0, -124, 30, -1, 0, -14, -22], [0, -37, 24, 10, 18, 8, 0, 0, 0, 2, 0, 0], [0, 9, -2, -22, -23, 22, 0, 0, 0, -19, 0, 0], [0, -28, -12, 6, -8, 18, 0, 0, 0, -1, 0, 0], [-24, 0, 0, 0, 0, 0, -30, -24, 8, 0, 30, -44], [26, 0, 0, 0, 0, 0, -102, -20, 18, 0, -14, 34], [0, -96, 4, 20, 6, -6, 0, 0, 0, -2, 0, 0], [0, -53, 8, -5, 19, 23, 0, 0, 0, -16, 0, 0], [-86, 0, 0, 0, 0, 0, 68, 12, 4, 0, 34, 26], [0, 94, -6, 3, 6, -13, 0, 0, 0, -21, 0, 0], [0, -10, 16, 6, -6, 32, 0, 0, 0, -8, 0, 0], [0, 34, 24, 0, 14, 16, 0, 0, 0, -25, 0, 0], [0, 51, 8, -3, 15, -27, 0, 0, 0, 8, 0, 0], [155, 0, 0, 0, 0, 0, -44, -20, -17, 0, -42, -34], [0, 75, 12, -1, 5, -7, 0, 0, 0, -22, 0, 0], [-120, 0, 0, 0, 0, 0, 123, -58, 31, 0, -14, 1], [-96, 0, 0, 0, 0, 0, 128, 16, 22, 0, 2, 46], [11, 0, 0, 0, 0, 0, 96, -28, -29, 0, 10, -52], [49, 0, 0, 0, 0, 0, 12, -2, -1, 0, -30, -8], [170, 0, 0, 0, 0, 0, 74, 31, -13, 0, -18, 49], [0, -2, -16, -24, -10, -22, 0, 0, 0, -13, 0, 0], [-8, 0, 0, 0, 0, 0, -110, -20, 32, 0, 12, -44], [76, 0, 0, 0, 0, 0, 102, 11, 21, 0, 28, 15], [-273, 0, 0, 0, 0, 0, -109, 10, -24, 0, -2, 59], [0, -54, 10, -8, -6, 24, 0, 0, 0, 14, 0, 0], [0, -118, 0, -4, 6, 60, 0, 0, 0, -10, 0, 0], [0, -33, 16, 40, 22, -12, 0, 0, 0, 14, 0, 0], [152, 0, 0, 0, 0, 0, -186, 13, 7, 0, -4, 37], [0, -82, -12, 6, 11, -26, 0, 0, 0, 13, 0, 0], [88, 0, 0, 0, 0, 0, -118, 18, -58, 0, -56, 8], [0, -36, -24, 0, -17, -24, 0, 0, 0, 15, 0, 0], [0, 45, 8, 9, 37, -17, 0, 0, 0, 18, 0, 0], [-218, 0, 0, 0, 0, 0, 240, 29, -5, 0, -12, 3], [-34, 0, 0, 0, 0, 0, 103, 20, -41, 0, -12, -17], [-105, 0, 0, 0, 0, 0, -196, 14, -23, 0, 28, -20], [-316, 0, 0, 0, 0, 0, 44, -12, 6, 0, 0, -56], [0, -85, 24, 13, -35, 1, 0, 0, 0, -4, 0, 0], [0, 29, -28, -23, 17, -15, 0, 0, 0, -10, 0, 0], [0, 18, -12, 18, 30, -4, 0, 0, 0, 33, 0, 0], [338, 0, 0, 0, 0, 0, 218, -34, 68, 0, 44, 14], [-116, 0, 0, 0, 0, 0, -96, 38, 16, 0, -36, 10], [144, 0, 0, 0, 0, 0, 34, 47, -71, 0, -4, -57], [176, 0, 0, 0, 0, 0, 130, -7, 43, 0, 6, -45], [0, 241, 0, 3, 15, -13, 0, 0, 0, -4, 0, 0], [247, 0, 0, 0, 0, 0, -90, 62, -25, 0, -40, 20], [31, 0, 0, 0, 0, 0, 177, 6, -38, 0, 20, -19], [-48, 0, 0, 0, 0, 0, 206, 54, -10, 0, -10, 0], [0, 106, 14, 31, -6, 77, 0, 0, 0, 1, 0, 0], [0, 104, -30, -19, -22, 33, 0, 0, 0, 15, 0, 0], [0, 52, 40, 36, -4, 94, 0, 0, 0, -13, 0, 0], [0, -109, -8, 34, -4, -32, 0, 0, 0, 20, 0, 0], [0, 50, -20, -10, 17, -14, 0, 0, 0, -17, 0, 0], [76, 0, 0, 0, 0, 0, -60, 105, -39, 0, 14, 9], [-98, 0, 0, 0, 0, 0, -96, -7, -21, 0, 38, -79], [-102, 0, 0, 0, 0, 0, -176, 72, -36, 0, -34, 4], [-42, 0, 0, 0, 0, 0, -123, -3, 16, 0, -22, -12], [-111, 0, 0, 0, 0, 0, 51, 56, -56, 0, 2, 9], [-202, 0, 0, 0, 0, 0, 66, 24, -54, 0, 56, 6], [138, 0, 0, 0, 0, 0, -186, 4, -14, 0, 40, -20], [0, 86, -28, -14, 5, -80, 0, 0, 0, -15, 0, 0], [0, 242, -16, 0, -24, -10, 0, 0, 0, 18, 0, 0], [-308, 0, 0, 0, 0, 0, -42, 38, -46, 0, -68, -104], [232, 0, 0, 0, 0, 0, -9, -37, 22, 0, 56, 22], [80, 0, 0, 0, 0, 0, -67, -7, 30, 0, -64, -18], [0, 3, 12, 10, -41, 62, 0, 0, 0, -14, 0, 0], [0, 143, -40, -46, -44, 22, 0, 0, 0, 10, 0, 0], [0, 129, -28, -6, 10, -52, 0, 0, 0, 18, 0, 0], [-68, 0, 0, 0, 0, 0, 19, -90, 95, 0, 0, 49], [0, -178, 30, 21, 46, 103, 0, 0, 0, 17, 0, 0], [554, 0, 0, 0, 0, 0, -64, 40, -64, 0, 16, -12], [363, 0, 0, 0, 0, 0, -237, -16, 6, 0, 26, -43], [0, -149, 36, 20, 36, -16, 0, 0, 0, -44, 0, 0], [0, 78, -10, -15, -44, -43, 0, 0, 0, 7, 0, 0], [0, -99, 40, 31, 37, -7, 0, 0, 0, -34, 0, 0], [96, 0, 0, 0, 0, 0, -32, -54, 12, 0, 30, -26], [0, 164, 20, 22, -3, -74, 0, 0, 0, 19, 0, 0], [62, 0, 0, 0, 0, 0, 28, -8, 52, 0, 26, 74], [0, -12, -44, -6, 11, 16, 0, 0, 0, -21, 0, 0], [0, -125, -32, -8, 0, -46, 0, 0, 0, 10, 0, 0], [186, 0, 0, 0, 0, 0, 190, -79, 93, 0, 38, 27], [-407, 0, 0, 0, 0, 0, -90, 26, 33, 0, 6, -44], [0, 56, 20, -46, 20, 78, 0, 0, 0, -23, 0, 0], [0, -239, 12, -2, -27, 44, 0, 0, 0, -16, 0, 0], [0, -58, 36, -22, -44, 10, 0, 0, 0, -46, 0, 0], [-392, 0, 0, 0, 0, 0, -159, 58, -51, 0, 12, -35], [-256, 0, 0, 0, 0, 0, -55, 62, -87, 0, -28, 7], [-100, 0, 0, 0, 0, 0, -229, -76, 69, 0, 58, 79], [0, 209, 14, 2, -21, 76, 0, 0, 0, 15, 0, 0], [13, 0, 0, 0, 0, 0, -252, 40, 53, 0, 24, 96], [0, 70, -4, 20, 17, -110, 0, 0, 0, -33, 0, 0], [143, 0, 0, 0, 0, 0, 106, -74, -41, 0, -52, -148], [0, -123, 34, 5, 33, -77, 0, 0, 0, -44, 0, 0], [0, 254, 20, -22, -26, 46, 0, 0, 0, -17, 0, 0], [0, -110, -28, 24, 34, 38, 0, 0, 0, -19, 0, 0], [0, 188, 16, 56, 18, -26, 0, 0, 0, 20, 0, 0], [480, 0, 0, 0, 0, 0, -86, 20, -112, 0, -14, -120]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_380_e_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


// To make the newform (type ModFrm), type "MakeNewformModFrm_380_3_e_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_380_3_e_a(:prec:=12)
    chi := MakeCharacter_380_e();
    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_380_3_e_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_380_3_e_a( : sign := -1)
    R<x> := PolynomialRing(Rationals());
    chi := MakeCharacter_380_e();
    // SetVerbose("ModularSymbols", true);
    Snew := NewSubspace(CuspidalSubspace(ModularSymbols(chi,3,sign)));
    Vf := Kernel([],Snew);
    return Vf;
end function;