Path: blob/master/src/sage/modular/arithgroup/farey.hpp
8820 views
//1// farey.hpp2// FareySymbol3//4//*************************************************************************5// Copyright (C) 2011 Hartmut Monien <[email protected]>6//7// Distributed under the terms of the GNU General Public License (GPL)8//9// This code is distributed in the hope that it will be useful,10// but WITHOUT ANY WARRANTY; without even the implied warranty of11// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU12// General Public License for more details.13//14// The full text of the GPL is available at:15//16// http://www.gnu.org/licenses/17//*************************************************************************181920#ifndef FAREY_SYMBOL_HPP_21#define FAREY_SYMBOL_HPP_2223#include <iostream>24#include <vector>25#include <string>2627#include <Python.h>28#include <gmpxx.h>29#include "sl2z.hpp"3031//--- pure virtual base class for helper class for membership test --------3233class is_element_group {34public:35virtual bool is_member(const SL2Z&) const = 0;36};3738class is_element_Gamma0 : public is_element_group {39const int p;40public:41is_element_Gamma0(int p_) : p(p_) {42}43bool is_member(const SL2Z& V) const {44return (V.c() % p == 0);45}46};4748class is_element_Gamma1 : public is_element_group {49const int p;50public:51is_element_Gamma1(int p_) : p(p_) {52}53bool is_member(const SL2Z& V) const {54return ((V.a()-1) % p == 0 &&55V.c() % p == 0 &&56(V.d()-1) % p == 0);57}58};5960class is_element_Gamma : public is_element_group {61const int p;62public:63is_element_Gamma(int p_) : p(p_) {64}65bool is_member(const SL2Z& V) const {66return ((V.a()-1) % p == 0 &&67V.b() % p == 0 &&68V.c() % p == 0 &&69(V.d()-1) % p == 0);70}71};7273class is_element_GammaH : public is_element_group {74const int p;75std::vector<long> H;76public:77is_element_GammaH(int p_, PyObject*);78~is_element_GammaH();79bool is_member(const SL2Z&) const;80};8182class is_element_general : public is_element_group {83protected:84PyObject* group;85PyObject* method;86public:87is_element_general(PyObject*);88virtual ~is_element_general();89bool is_member(const SL2Z&) const;90};9192class FareySymbol {93protected:94enum PAIRING { EVEN=-2, ODD=-3, NO=0, FREE=1 };95size_t pairing_max;96std::vector<int> pairing;97std::vector<int> cusp_classes;98std::vector<mpz_class> a, b;99std::vector<mpq_class> x;100std::vector<SL2Z> coset;101std::vector<SL2Z> generators;102std::vector<mpq_class> cusps;103std::vector<mpq_class> cusp_widths;104std::vector<SL2Z> reductions;105bool even;106std::vector<bool> pairing_in_group; // For membership test:107//Is the i-th pairing matrix in the group?108size_t rank_pi() const;109long side_index(const mpz_class& a0, const mpz_class& b0,110const mpz_class& a1, const mpz_class& b1) const;111void LLT_algorithm(const SL2Z& M, std::vector<int>& p, SL2Z& beta) const;112void dump(std::ostream& os) const;113std::vector<SL2Z> init_reductions() const;114private:115void add_term(const int, const mpq_class&);116void check_pair(const is_element_group*, const int);117size_t paired_side(const std::vector<int>& p, const size_t i) const;118SL2Z pairing_matrix(const std::vector<int>&, const size_t i) const;119void init_pairing(const is_element_group*);120std::vector<SL2Z> init_generators(const is_element_group*) const;121std::vector<SL2Z> init_coset_reps() const;122std::vector<int> init_cusp_classes() const;123std::vector<mpq_class> init_cusps() const;124std::vector<mpq_class> init_cusp_widths() const;125SL2Z pairing_matrix(const size_t) const;126SL2Z pairing_matrix_in_group(const size_t) const;127std::vector<bool> init_sl2z_lift(const is_element_group*) const;128public:129FareySymbol();130FareySymbol(std::istream& is);131FareySymbol(PyObject*);132FareySymbol(PyObject*, const is_element_group*);133~FareySymbol();134const size_t size() const;135size_t nu2() const;136size_t nu3() const;137size_t index() const;138size_t number_of_cusps() const;139size_t level() const;140size_t genus() const;141SL2Z reduce_to_fraction(const mpq_class& q) const;142SL2Z reduce_to_elementary_cusp(const mpq_class& q) const;143size_t cusp_class(const mpq_class& q) const;144bool is_element(const SL2Z& M) const;145friend std::ostream& operator<<(std::ostream&, const FareySymbol&);146friend std::istream& operator>>(std::istream&, FareySymbol&);147//--- communication with sage -------------------------------------------148PyObject* is_element(const mpz_t, const mpz_t, const mpz_t, const mpz_t) const;149PyObject* get_transformation_to_cusp(const mpz_t, const mpz_t) const;150PyObject* get_cusps() const;151PyObject* get_cusp_widths() const;152size_t get_cusp_class(const mpz_t, const mpz_t) const;153PyObject* get_fractions() const;154PyObject* get_coset() const;155PyObject* get_generators() const;156PyObject* get_pairings() const;157PyObject* get_paired_sides() const;158PyObject* get_pairing_matrices() const;159PyObject* dumps() const;160};161162#endif // FAREY_SYMBOL_HPP_163164165