Skip to content
Snippets Groups Projects
Verified Commit 4f538655 authored by Herbers, Maik's avatar Herbers, Maik
Browse files

weil: SL2Z-split: Take matrix as file.

* src/weil.cpp (print_help): Update help message.
(sl2z_split): Move after `read_square_mpz_matrix', take a file
containing the matrix as argument instead of the individual
coefficients.
parent 1c9d73ce
Branches
Tags
No related merge requests found
...@@ -35,7 +35,7 @@ print_help(bool error) ...@@ -35,7 +35,7 @@ print_help(bool error)
" respect to the smith basis\n" " respect to the smith basis\n"
" DS-get-orbits <gram> <aut> compute the orbits in the discriminant form associated to the gram\n" " DS-get-orbits <gram> <aut> compute the orbits in the discriminant form associated to the gram\n"
" matrix `gram' under the action induced by the automorphisms in `aut'\n" " matrix `gram' under the action induced by the automorphisms in `aut'\n"
" SL2Z-split <a> <b> <c> <d> split the matrix [a b; c d] of SL2Z into generators\n" " SL2Z-split <m> split the matrix `m' in SL2Z into generators\n"
" VV-Theta-Series [options] <file> <prec> compute the vector valued theta series associated to the\n" " VV-Theta-Series [options] <file> <prec> compute the vector valued theta series associated to the\n"
" lattice with gram matrix in `file' up to precision `prec'\n" " lattice with gram matrix in `file' up to precision `prec'\n"
" Transformation-Matrix <file> <aut> <M> compute the transformation matrix (up to a root of unity and a square root)\n" " Transformation-Matrix <file> <aut> <M> compute the transformation matrix (up to a root of unity and a square root)\n"
...@@ -57,40 +57,65 @@ print_help(bool error) ...@@ -57,40 +57,65 @@ print_help(bool error)
return error ? EXIT_FAILURE : EXIT_SUCCESS; return error ? EXIT_FAILURE : EXIT_SUCCESS;
} }
int static std::optional<weil::mpz_matrix>
sl2z_split(int argc, const char** argv, weil::IOFormat style) read_square_mpz_matrix(const char* file)
{ {
if (argc != 4) {
return print_help(true); std::vector<mpz_class> v;
std::ifstream in{ file };
if (!in.is_open()) {
std::cerr << "failed to open file `" << file << "'" << std::endl;
return std::nullopt;
} }
mpz_class a; mpz_class n;
mpz_class b; while (in >> n) {
mpz_class c; v.push_back(n);
mpz_class d; }
try {
a = argv[0]; if (!in.eof()) {
b = argv[1]; std::cerr << "failed to parse" << std::endl;
c = argv[2]; return std::nullopt;
d = argv[3]; }
} catch (const std::exception& e) {
std::cerr << "not all rational numbers:" auto dimension{ static_cast<uint64_t>(std::sqrt(v.size())) };
<< " `" << argv[0] << "',"
<< " `" << argv[1] << "'," if (dimension * dimension != v.size()) {
<< " `" << argv[2] << "'," std::cerr << "not a square matrix" << std::endl;
<< " `" << argv[3] << "'" << std::endl; return std::nullopt;
return print_help(true); }
weil::mpz_matrix m{ dimension, dimension };
for (uint64_t i = 0; i < dimension; i++) {
for (uint64_t j = 0; j < dimension; j++) {
m(i, j) = v[i * dimension + j];
}
}
return m;
} }
weil::SL2Z m; int
m << a, b, c, d; sl2z_split(int argc, const char** argv, weil::IOFormat style)
{
if (argc != 1) {
return print_help(true);
}
auto split = weil::split_into_generators(m); auto m{ read_square_mpz_matrix(argv[0]) };
if (!split) { if (!m) {
std::cerr << "Not in SL2Z:\n" << m << std::endl; return EXIT_FAILURE;
} else if (m->cols() != 2 ||
m->rows() != 2 ||
(*m)(0, 0) * (*m)(1, 1) - (*m)(0, 1) * (*m)(1, 0) != 1_mpz) {
std::cerr << "Not in SL2Z:\n" << *m << std::endl;
return EXIT_FAILURE; return EXIT_FAILURE;
} }
// As we already checked above, this will always contain a value
auto split = weil::split_into_generators(*m);
const char* exp_prefix = ""; const char* exp_prefix = "";
const char* exp_suffix = ""; const char* exp_suffix = "";
const char* sep = ""; const char* sep = "";
...@@ -116,7 +141,7 @@ sl2z_split(int argc, const char** argv, weil::IOFormat style) ...@@ -116,7 +141,7 @@ sl2z_split(int argc, const char** argv, weil::IOFormat style)
} }
bool first{ true }; bool first{ true };
for (auto&& [r1, r2] : *split) { for (auto&& [r1, r2] : split.value()) {
if (first) { if (first) {
first = false; first = false;
} else { } else {
...@@ -131,45 +156,6 @@ sl2z_split(int argc, const char** argv, weil::IOFormat style) ...@@ -131,45 +156,6 @@ sl2z_split(int argc, const char** argv, weil::IOFormat style)
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }
static std::optional<weil::mpz_matrix>
read_square_mpz_matrix(const char* file)
{
std::vector<mpz_class> v;
std::ifstream in{ file };
if (!in.is_open()) {
std::cerr << "failed to open file `" << file << "'" << std::endl;
return std::nullopt;
}
mpz_class n;
while (in >> n) {
v.push_back(n);
}
if (!in.eof()) {
std::cerr << "failed to parse" << std::endl;
return std::nullopt;
}
auto dimension{ static_cast<uint64_t>(std::sqrt(v.size())) };
if (dimension * dimension != v.size()) {
std::cerr << "not a square matrix" << std::endl;
return std::nullopt;
}
weil::mpz_matrix m{ dimension, dimension };
for (uint64_t i = 0; i < dimension; i++) {
for (uint64_t j = 0; j < dimension; j++) {
m(i, j) = v[i * dimension + j];
}
}
return m;
}
int int
ds_c_action_common(int argc, const char** argv, weil::IOFormat style, auto f) ds_c_action_common(int argc, const char** argv, weil::IOFormat style, auto f)
{ {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment