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

import

parents
Branches dev_jou_fsa
Tags
No related merge requests found
---
BasedOnStyle: Mozilla
UseTab: Always
---
Language: Cpp
Standard: Latest
IndentWidth: 8
IndentCaseLabels: false
NamespaceIndentation: All
ColumnLimit: 120
BreakBeforeBraces: Linux
BreakInheritanceList: BeforeComma
AlwaysBreakAfterReturnType: AllDefinitions
AllowShortCaseLabelsOnASingleLine: true
AlignConsecutiveMacros: true
AllowShortEnumsOnASingleLine: false
BreakBeforeConceptDeclarations: true
...
(authorizations
(version 0)
(("D5BA 4708 FA7D 0AFD 9C0E 6556 ECD7 F82F 5327 404C" ; signing subkey
(name "Maik Herbers"))))
Makefile 0 → 100644
# SPDX-License-Identifier: GPL-3.0-or-later
.SUFFIXES:
progname = weil
libname = libweil
soname = $(libname).so.0
lib_interface = common sl2z
lib_objs = sl2z
prog_objs = weil
pkg-config-deps = gmpxx eigen3
DESTDIR =
PREFIX = /usr/local
BINDIR = $(DESTDIR)$(PREFIX)/bin
LIBDIR = $(DESTDIR)$(PREFIX)/lib
INCLUDEDIR = $(DESTDIR)$(PREFIX)/include
CXX = g++
LD = $(CXX)
CXXFLAGS = -pipe -std=c++20 -Wall -Wextra -Wpedantic -Wshadow -g -O2 -fPIC \
$(shell pkg-config --cflags-only-other $(pkg-config-deps))
CPPFLAGS = -iquote include \
$(shell pkg-config --cflags-only-I $(pkg-config-deps))
LDFLAGS = -Llib $(LDFLAGS_EXTRA) \
$(shell pkg-config --libs-only-L --libs-only-other $(pkg-config-deps))
LDLIBS = -lweil \
$(shell pkg-config --libs-only-l $(pkg-config-deps))
.PHONY: all
all: setup compile
.PHONY: setup
setup: build lib out
out build lib:
mkdir -p $@
.PHONY: clean
clean: $(addprefix clean/,build lib out)
clean/%:
@printf '\tCLEAN\t%s\n' $*
@$(RM) -- $(wildcard $*/*)
compile: $(addprefix out/,$(progname)) \
$(addprefix lib/,$(soname) \
$(libname).a)
build/%.o: src/%.cpp
@printf '\tCXX\t%s\n' build/$*.o
@$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $^
out/$(progname): .EXTRA_PREREQS = lib/$(soname)
out/$(progname): $(patsubst %,build/%.o,$(prog_objs))
@printf '\tLD\t%s\n' $@
@$(LD) $(LDFLAGS) $^ $(LDLIBS) -o $@
lib/$(soname): $(patsubst %,build/%.o,$(lib_objs))
@printf '\tLD\t%s\n' $@
@$(LD) -Wl,-soname,$(soname) -shared -o $@ $^
@ln -sf $(soname) lib/$(libname).so
lib/$(libname).a: $(patsubst %,build/%.o,$(lib_objs))
@printf '\tAR\t%s\n' $@
@$(AR) rcs $@ $^
install-header/%:
@printf '\tINSTALL\t%s\n' $*
@install -Dm644 include/$* $(INCLUDEDIR)/weil/$*
.PHONY: install
install: $(patsubst %,install-header/%.hpp,$(lib_interface))
@printf '\tINSTALL\t%s\n' $(progname)
@install -Dm755 out/$(progname) $(BINDIR)/$(progname)
@printf '\tINSTALL\t%s\n' $(soname)
@install -Dm755 lib/$(soname) $(LIBDIR)/$(soname)
@ln -s $(LIBDIR)/$(soname) $(LIBDIR)/$(libname).so
@printf '\tINSTALL\t%s\n' $(libname).a
@install -Dm644 lib/$(libname).a $(LIBDIR)/$(libname).a
guix.scm 0 → 100644
;;; SPDX-License-Identifier: GPL-3.0-or-later
(use-modules (gnu packages algebra)
(gnu packages commencement)
(gnu packages multiprecision)
(gnu packages pkg-config)
(guix build-system gnu)
(guix gexp)
(guix licenses)
(guix utils)
(guix packages)
(ice-9 popen)
(ice-9 rdelim))
(define weil
(let*
((%source-dir (dirname (current-filename)))
(cmd (string-append "git -C " %source-dir " describe --always"))
(port (open-pipe cmd OPEN_READ))
(%git-version (read-line port))
(select? (lambda (name _)
(not (string=? name
(string-append %source-dir "/.git"))))))
(close port)
(package
(name "weil")
(version %git-version)
(source (local-file %source-dir
#:recursive? #t
#:select? select?))
(build-system gnu-build-system)
(arguments
(list #:tests? #f
#:make-flags #~(list (string-append "DESTDIR=" #$output)
"PREFIX="
(string-append "CC=" #$(cc-for-target))
(string-append "CXX=" #$(cxx-for-target))
(string-append "LDFLAGS_EXTRA=-Wl,-rpath," #$output "/lib"))
#:phases #~(modify-phases %standard-phases
(delete 'configure))))
(inputs (list eigen gmp pkg-config))
(synopsis "Computing with the Weil-Representation of lattices")
(description synopsis)
(home-page (string-append "file://" %source-dir))
(license gpl3+))))
(package-with-c-toolchain weil `(("toolchain" ,gcc-toolchain-12)))
/* SPDX-License-Identifier: GPL-3.0-or-later */
#pragma once
#include <Eigen/Eigen>
#include <gmpxx.h>
namespace weil
{
using mpz_vector = Eigen::Matrix<mpz_class, Eigen::Dynamic, 1>;
}
/* SPDX-License-Identifier: GPL-3.0-or-later */
#pragma once
#include <optional>
#include <vector>
#include "common.hpp"
namespace weil
{
using SL2Z = Eigen::Matrix<mpz_class, 2, 2>;
enum class SL2ZGenerator {
T,
S,
};
/*
* Returns the sequence of matrices `T' and `S' with corresponding powers
* that have product `m_'.
* While interating the forward, the matrices have to be multiplied on
* the right side.
*/
std::optional<std::vector<std::pair<SL2ZGenerator, mpz_class>>> split_into_generators(const SL2Z& m);
}
/* SPDX-License-Identifier: GPL-3.0-or-later */
#include "sl2z.hpp"
namespace weil
{
std::optional<std::vector<std::pair<SL2ZGenerator, mpz_class>>>
split_into_generators(const SL2Z& m_)
{
// See Diamond--Shurman "A First Course in Modular Forms", Exercise 1.1.1
SL2Z S;
// clang-format off
S << 0, -1,
1, 0;
// clang-format on
SL2Z m{ m_ };
bool invertible;
mpz_class det;
// we need to check the determinant, as gmp will happily round integers
m_.computeInverseAndDetWithCheck(m, det, invertible);
if (abs(det) != 1) {
return std::nullopt;
}
std::vector<std::pair<SL2ZGenerator, mpz_class>> split;
while (m(1, 0) != 0) {
mpz_class n = -m(1, 1) / m(1, 0);
if (2 * abs(n * m(1, 0) + m(1, 1)) > abs(m(1, 0))) {
// correct?
if (n < 0) {
n--;
} else {
n++;
}
}
// clang-format off
m << m(0, 0), n * m(0, 0) + m(0, 1),
m(1, 0), n * m(1, 0) + m(1, 1);
// clang-format on
if (n != 0) {
split.push_back({ SL2ZGenerator::T, n });
}
m *= S;
split.push_back({ SL2ZGenerator::S, 1 });
}
if (m(1, 1) == -1) {
m *= S * S;
split.push_back({ SL2ZGenerator::S, 2 });
}
mpz_class n = -m(0, 1);
if (n != 0) {
split.push_back({ SL2ZGenerator::T, n });
}
return split;
}
}
/* 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);
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment