Select Git revision
agent.cpython-311.pyc
weil.cpp 1.53 KiB
/* SPDX-License-Identifier: GPL-3.0-or-later */
#include <cstdlib>
#include <iostream>
#include "common.hpp"
#include "sl2z.hpp"
int
print_help(bool error)
{
const char* s = "Usage:\n"
"\tweil <command> [arguments]\n"
"\n"
"Commands:\n"
" SL2Z-split <a> <b> <c> <d> split the matrix [a b; c d] of SL2Z into generators";
(error ? std::cerr : std::cout) << s << std::endl;
return error ? EXIT_FAILURE : EXIT_SUCCESS;
}
int
sl2z_split(int argc, const char** argv)
{
if (argc != 4) {
return print_help(true);
}
mpz_class a;
mpz_class b;
mpz_class c;
mpz_class d;
try {
a = argv[0];
b = argv[1];
c = argv[2];
d = argv[3];
} catch (const std::exception& e) {
std::cerr << "not all rational numbers:"
<< " `" << argv[0] << "',"
<< " `" << argv[1] << "',"
<< " `" << argv[2] << "',"
<< " `" << argv[3] << "'" << std::endl;
return print_help(true);
}
weil::SL2Z m;
m << a, b, c, d;
auto split = weil::split_into_generators(m);
if (!split) {
std::cerr << "Not in SL2Z:\n" << m << std::endl;
return EXIT_FAILURE;
}
for (auto&& [r1, r2] : *split) {
std::cout << ((r1 == weil::SL2ZGenerator::T) ? "T" : "S") << "^{" << r2 << "} ";
}
std::cout << std::endl;
return EXIT_SUCCESS;
}
int
main(int argc, const char** argv)
{
if (argc < 2) {
return print_help(true);
}
if (strcmp("--help", argv[1]) == 0 || strcmp("-h", argv[1]) == 0) {
return print_help(false);
}
if (strcmp("SL2Z-split", argv[1]) == 0) {
return sl2z_split(argc - 2, argv + 2);
}
return print_help(true);
}