
// Make newform 1200.4.f.t in Magma, downloaded from the LMFDB on 23 April 2024.
// To make the character of type GrpDrchElt, type "MakeCharacter_1200_f();"
// To make the character of type GrpDrchElt with Codomain the HeckeField, type "MakeCharacter_1200_f_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_1200_4_f_t();".
// 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_1200_4_f_t();".
// 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];
        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_1200_f();"
function MakeCharacter_1200_f()
    N := 1200;
    order := 2;
    char_gens := [751, 901, 401, 577];
    v := [2, 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_1200_f_Hecke();"
function MakeCharacter_1200_f_Hecke(Kf)
    N := 1200;
    order := 2;
    char_gens := [751, 901, 401, 577];
    char_values := [[1, 0], [1, 0], [1, 0], [-1, 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 := 4;
    raw_aps := [[0, 0], [0, 3], [0, 0], [0, 20], [56, 0], [0, -86], [0, 106], [4, 0], [0, -136], [206, 0], [152, 0], [0, -282], [-246, 0], [0, -412], [0, 40], [0, -126], [56, 0], [-2, 0], [0, -388], [672, 0], [0, 1170], [408, 0], [0, -668], [-66, 0], [0, 926], [-198, 0], [0, 1532], [0, -444], [-62, 0], [0, 414], [0, -996], [264, 0], [0, -2278], [1812, 0], [1534, 0], [3016, 0], [0, 1814], [0, 1844], [0, 3768], [0, 938], [3968, 0], [-3514, 0], [1480, 0], [0, -2774], [0, 3806], [-856, 0], [-3020, 0], [0, 1684], [0, 2004], [5042, 0], [0, -3090], [2136, 0], [98, 0], [5040, 0], [0, 1986], [0, -1416], [6670, 0], [-48, 0], [0, -6938], [-1694, 0], [0, 6364], [0, -3134], [0, -236], [-3776, 0], [0, -7918], [0, -4362], [-7980, 0], [0, 8294], [0, -964], [-8670, 0], [0, -2314], [-1896, 0], [0, 1484], [0, 12370], [5620, 0], [0, -5880], [-2082, 0], [0, 1742], [-3270, 0], [6134, 0], [-10392, 0], [-12690, 0], [7408, 0], [0, -5062], [-7160, 0], [0, -17100], [-8634, 0], [0, -2986], [-2406, 0], [0, 14316], [0, -292], [14056, 0], [0, -11204], [-4608, 0], [2468, 0], [0, -12192], [-1714, 0], [-18014, 0], [0, 16748], [-14018, 0], [0, -412], [0, -18218], [0, -23524], [-23330, 0], [13124, 0], [0, -11714], [0, -17628], [0, -2802], [-2664, 0], [23962, 0], [0, 11940], [0, 16794], [0, 20706], [10724, 0], [5744, 0], [27906, 0], [0, -20556], [0, -10224], [0, -12982], [-1512, 0], [16710, 0], [0, 7962], [0, -12226], [0, 8748], [7324, 0], [-21934, 0], [10690, 0], [13792, 0], [0, -24004], [0, 8562], [-13836, 0], [0, 22224], [-11544, 0], [0, 3814], [-25662, 0], [-30658, 0], [0, -30894], [0, 21596], [0, 8646], [-24954, 0], [-40004, 0], [16570, 0], [0, 4388], [0, 14364], [21170, 0], [10664, 0], [0, -3190], [0, -20814], [-18988, 0], [0, -11664], [0, 8246], [22890, 0], [0, -33548], [0, -32264], [0, 51228], [2144, 0], [33584, 0], [3590, 0], [0, 21686], [-5174, 0], [0, 35524], [0, -16122], [0, 19188], [38464, 0], [0, 43930], [0, -17328], [18160, 0], [0, 9102], [-14306, 0], [0, -5710], [-56056, 0], [-12170, 0], [4360, 0], [0, 8450], [31400, 0], [31806, 0], [60428, 0], [21170, 0], [0, -2668], [62474, 0], [0, 8756], [8952, 0], [0, -25558], [0, 5018], [0, -23864], [-33698, 0], [0, -36170], [0, 2308], [-64490, 0], [63080, 0], [0, 18314], [0, 36276], [-380, 0], [-49318, 0], [0, 46108], [0, 76454], [51666, 0], [0, 7578], [0, 10066], [0, -29552], [77238, 0], [63992, 0], [0, 29374], [59694, 0], [23160, 0], [0, 37318], [20104, 0], [0, 29084], [40398, 0], [2356, 0], [0, 47414], [22322, 0], [0, -31604], [0, 40044], [16672, 0], [-74262, 0], [0, 58780], [-37702, 0], [0, 12432], [0, -62438], [-13330, 0], [-84680, 0], [92318, 0], [0, -25284], [0, -67380], [-28990, 0], [0, 6662], [-4768, 0], [0, -101524], [-105272, 0], [0, 54442], [21852, 0], [12400, 0], [-68030, 0], [0, 26940], [0, -94608], [41070, 0], [0, 52530], [-94040, 0], [-38160, 0], [0, -66772], [-52252, 0], [0, 41588], [-42094, 0], [0, 56534], [96800, 0], [0, 94828], [-80240, 0], [23548, 0], [0, 106528], [0, -94386], [21250, 0], [0, -48024], [-56810, 0], [0, 8762], [10968, 0], [-35242, 0], [0, -2412], [0, -82866], [0, -117906], [0, 110324], [0, -83020], [-31518, 0], [0, 54722], [0, -82622], [-93836, 0], [-56602, 0], [28026, 0], [0, 45708], [0, -99614], [-29530, 0], [0, -9164], [0, -2814], [-30040, 0], [0, -31322], [0, 17932], [0, 134956], [-111758, 0], [133370, 0], [-120216, 0], [0, 50400], [-31656, 0], [0, -101776], [-63698, 0], [0, 57004], [127064, 0], [0, -29230], [0, -22674], [-67704, 0], [4062, 0], [-38726, 0], [0, 121884], [0, 69726], [-125928, 0], [0, -159134], [31926, 0], [-66680, 0], [0, 139602], [-27848, 0], [0, -25212], [0, -52638], [0, -90954], [-69280, 0]];
    aps := ConvertToHeckeField(raw_aps);
    chi := MakeCharacter_1200_f_Hecke(Universe(aps));
    return ExtendMultiplicatively(weight, aps, chi);
end function;


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