
// Make newform 6900.2.a.r in Magma, downloaded from the LMFDB on 28 January 2025.
// To make the character of type GrpDrchElt, type "MakeCharacter_6900_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_6900_2_a_r();".
// 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_6900_2_a_r();".
// 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 := [-6, 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_6900_a();"
function MakeCharacter_6900_a()
    N := 6900;
    order := 1;
    char_gens := [3451, 4601, 277, 1201];
    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_6900_a_Hecke(Kf)
    return MakeCharacter_6900_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, 0], [0, 0], [-1, 0], [-2, -1], [0, -1], [1, 1], [0, 3], [-1, 0], [-7, -1], [3, -2], [5, 2], [-3, 1], [-2, 4], [0, -3], [3, -3], [-9, 1], [-2, 1], [1, -4], [-5, 3], [0, 3], [-4, -4], [13, 1], [-8, 2], [0, -2], [-9, -3], [2, -2], [-9, 3], [-16, -1], [3, 5], [-6, 5], [0, 0], [-4, -6], [-1, -4], [-8, 1], [6, -4], [-11, 0], [-2, -8], [-12, -1], [0, -4], [10, 0], [0, -2], [0, -7], [-4, 2], [6, 2], [10, 6], [25, 0], [-14, 0], [-12, 4], [-8, -6], [-4, -8], [1, 9], [-8, 9], [-18, 0], [-8, -5], [-7, -3], [3, -5], [11, 2], [10, 4], [-10, -3], [1, 2], [-5, 9], [8, -5], [4, 8], [19, 6], [-20, 3], [11, -4], [-14, 4], [-4, 10], [-9, 10], [-8, -1], [-12, -1], [-25, 2], [-20, -4], [4, -4], [-9, 5], [10, 10], [28, -4], [18, 2], [5, -6], [-26, -3], [0, 3], [-12, 10], [15, 4], [-10, -6], [20, -1], [-7, -13], [3, -10], [2, 6], [0, -3], [15, 7], [-4, -11], [6, 13], [-9, 5], [17, -4], [-1, -7], [16, -6], [2, -5], [20, 4], [8, -10], [12, -4], [-29, -3], [25, -3], [-6, 6], [-6, 1], [4, -4], [10, -12], [12, 5], [0, -10], [-7, -12], [-10, -9], [-14, 0], [-25, -7], [-36, 4], [14, 9], [-2, -1], [1, -10], [-18, 3], [2, 3], [-6, 11], [30, 6], [30, -1], [1, 3], [-24, 9], [10, 8], [-24, 3], [-26, -3], [3, 3], [13, -2], [-3, 12], [27, -8], [44, -4], [28, 7], [5, 6], [-25, 7], [-18, -7], [-6, -2], [13, 14], [-35, -1], [39, -1], [-23, -4], [20, 10], [-8, -4], [1, -21], [-17, 6], [-2, 0], [10, -2], [-6, 8], [-3, -8], [-6, 14], [-10, -6], [-32, 5], [30, 5], [-18, -6], [45, 0], [24, -8], [16, 4], [-3, 13], [12, -10], [-28, -1], [28, 6], [-14, 8], [14, -3], [-40, -2], [15, 3], [9, -7], [1, -8], [32, 2], [-8, -12], [-36, -1], [-32, 8], [41, 8], [-6, -4], [-1, 2], [56, 0], [-12, -7], [14, 6], [5, 5], [3, -8], [-12, -15], [20, 7], [36, -9], [-26, -10], [-6, 9], [1, 1], [18, -15], [4, -5], [35, 0], [-13, 14], [39, 7], [-44, -5], [-14, 4], [-36, 1], [17, -17], [14, -8], [-11, -5], [0, -3], [8, -6], [-6, -12], [-18, -8], [40, 9], [26, 8], [20, -7], [-16, -17], [40, -7], [18, -10], [-34, -1], [-6, -5], [29, -7], [50, 0], [-18, -6], [10, -2], [-10, 22], [-26, 0], [-45, -9], [-18, -15], [-30, 2], [-31, 1], [21, -7], [-10, 9], [55, -6], [6, -2], [9, 17], [7, 0], [-2, 11], [-1, 10], [-6, -2], [33, 13], [28, -4], [-17, 17], [-28, -1], [0, 25], [26, -6], [17, 11], [5, -18], [-30, 4], [-14, -9], [-30, 8], [23, -13], [-3, -19], [9, 23], [15, -10], [6, 26], [40, -6], [52, 4], [-8, -6], [-22, 9], [6, -7], [46, -10], [17, -9], [60, 2], [-54, 4], [15, 5], [-6, 22], [-18, 17], [-21, -19], [-2, 13], [24, 4], [14, -19], [6, -12], [43, -14], [49, -1], [1, -22], [61, -2], [40, -2], [14, 13], [-12, 19], [-14, 4], [13, 6], [-36, -12], [11, -12], [1, -6], [-11, 6], [10, 24], [42, -3], [20, -1], [12, -5], [-17, 8], [-18, -21], [16, 19], [-22, -16], [14, -5], [56, 10], [-52, 0], [-20, -23], [-39, 3], [-65, 6], [30, -4], [14, 14], [38, 14], [-18, 2], [31, -1], [28, 14], [-20, 7], [10, 9], [8, 8], [-56, 9], [-18, 15], [-3, 13], [34, 4], [-31, -6], [-23, -15], [-20, -26], [68, 5], [-8, -32], [-18, -1], [30, -1], [-18, 12], [32, 3], [-2, -15], [-8, -16], [18, -19], [-68, 1], [-4, -20], [-9, 3], [-22, 5], [27, -9], [45, -11], [47, -16], [-52, 10], [10, 3], [3, -2], [-42, -4], [26, 0], [27, -3], [10, 19], [18, -9], [-12, 11], [-60, 8], [-21, -11], [3, 10], [-42, 11], [37, -2], [6, 3], [-20, 20], [-20, -8], [-42, 6], [10, 14], [12, 6], [77, -2], [-22, 22], [34, 12], [-54, -10], [-74, -3], [-19, 21], [15, 7], [-9, 6], [-4, 23], [42, 8], [-17, 31], [-79, 2], [-58, 7], [27, -25], [19, 4], [-10, 1], [58, 4], [-30, 11], [18, -24], [10, -23], [26, 10], [5, 8], [-27, -7], [-6, 6], [-16, 14], [-74, -6], [-46, 10], [-16, 1], [61, -2], [20, 12], [29, 9], [-1, 4], [-54, 8], [-24, 18], [-16, 12], [40, -3], [-13, -17], [-70, -10], [-49, -12], [-16, 18], [10, -2], [-2, 30], [42, 2], [-36, -8], [62, -15], [72, 6], [6, -28], [45, -22], [-26, 3], [-25, -14], [-47, -1], [32, 13], [-10, -14], [15, 15], [-10, -7], [54, -9], [-57, -8], [-46, -14], [24, -10], [-24, 20], [-39, -23], [-13, -12], [34, 8], [-87, 0], [-33, -17], [23, 3], [-7, -10], [3, -4], [-38, 6], [18, 16], [4, 0], [2, 23], [-42, -15], [-20, 8], [28, -6], [-79, 0], [58, -8], [-8, -14], [-34, -9], [41, 11], [-16, 14], [26, -11], [20, 10], [-54, 5], [40, -16], [10, 35], [4, -36], [-76, 6], [-81, -7], [22, -2], [-47, 7]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_6900_a_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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