
P<x> := PolynomialRing(Integers());

N1 := NumberField(x^3 + 2);

time M1 := MaximalOrder(N1 : Al := "Montes");
IntegralBasis(N1 : Al := "Montes");
IntegralBasis(N1 : Al := "Montes", HNF := true);
time D7 := Decomposition(N1, 7 : Al := "Montes");
time D3 := Decomposition(M1, 3 : Al := "Montes");

for I in D3 do
    assert OMRepresentation(ideal<M1 | a, b where a, b := TwoElement(I[1])>) eq OMRepresentation(I[1]);
end for;

time Valuation(N1.1, D7[1][1]);
time Valuation(N1.1, D3[1][1]);
time Valuation(Random(N1, 3), D7[1][1]);
time Valuation(Random(N1, 2), D3[1][1]);

N2 := NumberField(x^5 + 3);

time M2 := MaximalOrder(N2 : Al := "Montes");
IntegralBasis(N2 : Al := "Montes");
IntegralBasis(N2 : Al := "Montes", HNF);
time D7 := Decomposition(N2, 7 : Al := "Montes");
time D3 := Decomposition(M2, 3 : Al := "Montes");

for I in D3 do
    assert OMRepresentation(ideal<M2 | a, b where a, b := TwoElement(I[1])>) eq OMRepresentation(I[1]);
end for;

time Valuation(N2.1, D7[1][1]);
time Valuation(N2.1, D3[1][1]);
time Valuation(Random(N2, 3), D7[1][1]);
time Valuation(Random(N2, 2), D3[1][1]);

N3 := NumberField(4*x^7 + 55);

//Montes will give errors here due to non monic polynomials.
try
time M3 := MaximalOrder(N3 : Al := "Montes");
catch e
     "Caught non Montes case";
    time M3 := MaximalOrder(N3 : Al := "Auto");
end try;
try
IntegralBasis(N3 : Al := "Montes");
catch e
     "Caught non Montes case";
IntegralBasis(N3);
end try;
try
IntegralBasis(N3 : HNF);
catch e
     "Caught non Montes case";
end try;
try
time D7 := Decomposition(N3, 7 : Al := "Montes");
catch e
     "Caught non Montes case";
    time D7 := Decomposition(N3, 7);
end try;
try
time D3 := Decomposition(M3, 3 : Al := "Montes");
catch e
     "Caught non Montes case";
    time D3 := Decomposition(M3, 3);
end try;

time Valuation(N3.1, D7[1][1]);
time Valuation(N3.1, D3[1][1]);
time Valuation(Random(N3, 3), D7[1][1]);
time Valuation(Random(N3, 2), D3[1][1]);


P<x> := PolynomialRing(Rationals());

N1 := NumberField(x^3 + 2);

time M1 := MaximalOrder(N1 : Al := "Montes");
IntegralBasis(N1 : Al := "Montes");
IntegralBasis(N1 : Al := "Montes", HNF);
time _ := Decomposition(N1, 7 : Al := "Montes");
time D3 := Decomposition(M1, 3 : Al := "Montes");

for I in D3 do
    assert OMRepresentation(ideal<M1 | a, b where a, b := TwoElement(I[1])>) eq OMRepresentation(I[1]);
end for;

N2 := NumberField(x^5 + 1/3);

try
time M2 := MaximalOrder(N2 : Al := "Montes");
catch e
     "Caught non Montes case";
	time M2 := MaximalOrder(N2);
end try;
try
IntegralBasis(N2 : Al := "Montes");
catch e
     "Caught non Montes case";
    IntegralBasis(N2);
end try;
try
time _ := Decomposition(N2, 7 : Al := "Montes");
catch e
     "Caught non Montes case";
end try;
try
time _ := Decomposition(M2, 3 : Al := "Montes");
catch e
     "Caught non Montes case";
end try;

N3 := NumberField(4*x^7 + 55);

//Montes will give errors here due to non monic polynomials.
try
time M3 := MaximalOrder(N3 : Al := "Montes");
catch e
     "Caught non Montes case";
    time M3 := MaximalOrder(N3 : Al := "Auto");
end try;
try
IntegralBasis(N3 : Al := "Montes");
catch e
     "Caught non Montes case";
    IntegralBasis(N3);
end try;
try
time _ := Decomposition(N3, 7 : Al := "Montes");
catch e
     "Caught non Montes case";
end try;
try
time _ := Decomposition(M3, 3 : Al := "Montes");
catch e
     "Caught non Montes case";
end try;


P<t> := PolynomialRing(Rationals());

P<t> := PolynomialRing(GF(101));
_<x> := PolynomialRing(P);
_<y> := PolynomialRing(FieldOfFractions(P));

F1 := FunctionField(x^3 + t^2);
F11 := FunctionField(y^3 + t^2);

IntegralBasis(F1);
time M1 := MaximalOrderFinite(F1 : Al := "Montes");
time _ := Decomposition(F1, Zeros(t^2/t+7)[1] : Al := "Montes");
time D3 := Decomposition(M1, t+3 : Al := "Montes");

for I in D3 do
    assert OMRepresentation(ideal<M1 | a, b where a, b := TwoElement(I)>) eq OMRepresentation(I);
end for;

IntegralBasis(F11 : Al := "Montes");
time M11 := MaximalOrderFinite(F11 : Al := "Montes");
time _ := Decomposition(F1, Zeros(t^2/t+7)[1] : Al := "Montes");
time D3 := Decomposition(M11, t+3 : Al := "Montes");

for I in D3 do
    assert OMRepresentation(ideal<M11 | a, b where a, b := TwoElement(I)>) eq OMRepresentation(I);
end for;

try
time MI1 := MaximalOrderInfinite(F1 : Al := "Montes");
catch e
    "Caught non Montes case";
end try;

try
time MI1 := MaximalOrderInfinite(F1);
time _ := Decomposition(MI1, CoefficientRing(MI1)!(1/t) : Al := "Montes");
catch e
    "Caught non Montes case";
end try;

try
time _ := Decomposition(F11, Zeros(1/t)[1] : Al := "Montes");
catch e
    "Caught non Montes case";
end try;

try
time MI11 := MaximalOrderInfinite(F11 : Al := "Montes");
catch e
    "Caught non Montes case";
end try;

try
time MI11 := MaximalOrderInfinite(F11);
time _ := Decomposition(MI11, CoefficientRing(MI11)!(1/t) : Al := "Montes");
catch e
    "Caught non Montes case";
end try;

try
time _ := Decomposition(F11, Zeros(1/t)[1] : Al := "Montes");
catch e
    "Caught non Montes case";
end try;

time Genus(F1 : Al := "Montes");
time Genus(F11 : Al := "Montes");

F2 := FunctionField(x^5 + t^3);
F22 := FunctionField(y^5 + t^3);

IntegralBasis(F2 : Al := "Montes", HNF := false);
time M2 := MaximalOrderFinite(F2 : Al := "Montes");
time _ := Decomposition(F2, Zeros(t^2/t+7)[1] : Al := "Montes");
time d23 := Decomposition(M2, t+3 : Al := "Montes");

for I in d23 do
    assert OMRepresentation(ideal<M2 | a, b where a, b := TwoElement(I)>) eq OMRepresentation(I);
end for;

Valuation(Random(F2, 3), Random(d23));
assert Valuation(SafeUniformizer(d23[#d23])^7, d23[#d23]) eq 7;

IntegralBasis(F22 : Al := "Montes", HNF := true);
time M22 := MaximalOrderFinite(F22 : Al := "Montes");
time _ := Decomposition(F22, Zeros(t^2/t+7)[1] : Al := "Montes");
time d223 := Decomposition(M22, t+3 : Al := "Montes");

/*
for I in d223 do
    assert OMRepresentation(ideal<M22 | a, b where a, b := TwoElement(I)>) eq OMRepresentation(I);
end for;
*/

Valuation(Random(F22, 3), Random(d223));
assert Valuation(SafeUniformizer(d223[#d223])^7, d223[#d223]) eq 7;

time Genus(F2 : Al := "Montes");
time Genus(F22 : Al := "Montes");

F3 := FunctionField(4*x^7 + t^55);
F33 := FunctionField(4*y^7 + t^55);

assert IsIsomorphic(F3, MonicModel(F3));
assert IsIsomorphic(F33, MonicModel(F33));

time M3 := MaximalOrderFinite(F3 : Al := "Montes");
time _ := Decomposition(F3, Zeros(t^2/t+7)[1] : Al := "Montes");
time D3 := Decomposition(M3, (t+3) : Al := "Montes");

for I in D3 do
    assert OMRepresentation(ideal<M3 | a, b where a, b := TwoElement(I)>) eq OMRepresentation(I);
end for;

time _ := Decomposition(M3, (t+3));

try
time M33 := MaximalOrderFinite(F33 : Al := "Montes");
catch e
    "Caught non Montes case";
end try;

try
time M33 := MaximalOrderFinite(F33); // : Al := "Montes");
time _ := Decomposition(M33, (t+3) : Al := "Montes");
catch e
    "Caught non Montes case";
end try;

try
time _ := Decomposition(F33, Zeros(t^2/t+7)[1] : Al := "Montes");
catch e
    "Caught non Montes case";
end try;

time Genus(F3 : Al := "Montes");
try
time Genus(F33 : Al := "Montes");
catch e
    "Caught non Montes case";
end try;

//Montes will give errors here due to non monic polynomials.
F4 := FunctionField(t^4*x^7 + t^55 + 1);
F44 := FunctionField(t^4*y^7 + t^55 + 1);

//assert IsIsomorphic(F4, 
MonicModel(F4);
//assert IsIsomorphic(F44, 
MonicModel(F44);

try
time M4 := MaximalOrderFinite(F4 : Al := "Montes");
catch e
    "Caught non Montes case";
end try;
try
time M4 := MaximalOrderFinite(F4);
time _ := Decomposition(M4, (t+3) : Al := "Montes");
catch e
    "Caught non Montes case";
end try;
try
time _ := Decomposition(F4, Zeros(t^2/t+7)[1] : Al := "Montes");
catch e
    "Caught non Montes case";
end try;

try
time M44 := MaximalOrderFinite(F44 : Al := "Montes");
catch e
    "Caught non Montes case";
end try;
try
time M44 := MaximalOrderFinite(F44);
time _ := Decomposition(M44, t+3 : Al := "Montes");
catch e
    "Caught non Montes case";
end try;
try
time _ := Decomposition(F44, Zeros(t^2/t+7)[1] : Al := "Montes");
catch e
    "Caught non Montes case";
end try;

try
time Genus(F4 : Al := "Montes");
catch e
    "Caught non Montes case";
end try;
try
time Genus(F44 : Al := "Montes");
catch e
    "Caught non Montes case";
end try;

//Montes will give errors here due to non integral polynomials.
F55 := FunctionField(y^7 + 1/t^55 + 1);

assert IsIsomorphic(F55, MonicModel(F55));

try
time M55 := MaximalOrderFinite(F55 : Al := "Montes");
catch e
    "Caught non Montes case";
end try;
try
time M55 := MaximalOrderFinite(F55);
time _ := Decomposition(M55, t+3 : Al := "Montes");
catch e
    "Caught non Montes case";
end try;
try
time _ := Decomposition(F55, Zeros(t^2/t+7)[1] : Al := "Montes");
catch e
    "Caught non Montes case";
end try;

try
time Genus(F55 : Al := "Montes");
catch e
    "Caught non Montes case";
end try;


P<t> := PolynomialRing(Rationals());
_<x> := PolynomialRing(P);
_<y> := PolynomialRing(FieldOfFractions(P));

F1 := FunctionField(x^3 + t^2);
F11 := FunctionField(y^3 + t^2);

time M1 := MaximalOrderFinite(F1 : Al := "Montes");
time _ := Decomposition(F1, Zeros(CoefficientRing(F1)!t+7)[1] : Al := "Montes");
time D3 := Decomposition(M1, t+3 : Al := "Montes");

for I in D3 do
    assert OMRepresentation(ideal<M1 | a, b where a, b := TwoElement(I)>) eq OMRepresentation(I);
end for;

time M11 := MaximalOrderFinite(F11 : Al := "Montes");
time _ := Decomposition(F11, Zeros(CoefficientRing(F1)!t+7)[1] : Al := "Montes");
time D3 := Decomposition(M11, t+3 : Al := "Montes");

for I in D3 do
    assert OMRepresentation(ideal<M11 | a, b where a, b := TwoElement(I)>) eq OMRepresentation(I);
end for;

try
time _ := Decomposition(F11, Zeros(CoefficientRing(F1)!1/t)[1] : Al := "Montes");
catch e
    "Caught non Montes case";
end try;

Genus(F1); Genus(F11);

try
time _ := Decomposition(F11, Zeros(CoefficientRing(F1)!1/t)[1] : Al := "Montes");
catch e
    "Caught non Montes case";
end try;

F2 := FunctionField(x^5 + t^3);
F22 := FunctionField(y^5 + t^3);

time M2 := MaximalOrderFinite(F2 : Al := "Montes");
time _ := Decomposition(F2, Zeros(CoefficientRing(F1)!t+7)[1] : Al := "Montes");
time D3 := Decomposition(M2, t+3 : Al := "Montes");

for I in D3 do
    assert OMRepresentation(ideal<M2 | a, b where a, b := TwoElement(I)>) eq OMRepresentation(I);
end for;

time M22 := MaximalOrderFinite(F22 : Al := "Montes");
time _ := Decomposition(F22, Zeros(CoefficientRing(F1)!t+7)[1] : Al := "Montes");
time D3 := Decomposition(M22, t+3 : Al := "Montes");

for I in D3 do
    assert OMRepresentation(ideal<M22 | a, b where a, b := TwoElement(I)>) eq OMRepresentation(I);
end for;

Genus(F2); Genus(F22);

F3 := FunctionField(4*x^7 + t^55);
F33 := FunctionField(4*y^7 + t^55);

assert IsIsomorphic(F3, MonicModel(F3));
//assert IsIsomorphic(F33, 
MonicModel(F33);

time M3 := MaximalOrderFinite(F3 : Al := "Montes");
time _ := Decomposition(F3, Zeros(CoefficientRing(F1)!t+7)[1] : Al := "Montes");
time D3 := Decomposition(M3, t+3 : Al := "Montes");

for I in D3 do
    assert OMRepresentation(ideal<M3 | a, b where a, b := TwoElement(I)>) eq OMRepresentation(I);
end for;

try
time M33 := MaximalOrderFinite(F33 : Al := "Montes");
catch e
    "Caught non Montes case";
end try;

try
time _ := Decomposition(F33, Zeros(CoefficientRing(F1)!t+7)[1] : Al := "Montes");
catch e
    "Caught non Montes case";
end try;
try
time _ := Decomposition(M33, t+3 : Al := "Montes");
catch e
    "Caught non Montes case";
end try;

//Montes will give errors here due to non monic polynomials.
F4 := FunctionField(t^4*x^7 + t^55 + 1);
F44 := FunctionField(t^4*y^7 + t^55 + 1);

//assert IsIsomorphic(F4, 
MonicModel(F4);
//assert IsIsomorphic(F44, 
MonicModel(F44);

try
time M4 := MaximalOrderFinite(F4 : Al := "Montes");
catch e
    "Caught non Montes case";
end try;
try
time _ := Decomposition(F4, Zeros(CoefficientRing(F1)!t+7)[1] : Al := "Montes");
catch e
    "Caught non Montes case";
end try;
try
time _ := Decomposition(M4, t+3 : Al := "Montes");
catch e
    "Caught non Montes case";
end try;

try
time M44 := MaximalOrderFinite(F44 : Al := "Montes");
catch e
    "Caught non Montes case";
end try;
try
time _ := Decomposition(F44, Zeros(CoefficientRing(F1)!t+7)[1] : Al := "Montes");
catch e
    "Caught non Montes case";
end try;
try
time _ := Decomposition(M44, t+3 : Al := "Montes");
catch e
    "Caught non Montes case";
end try;



