1 /*
2 
3 cm_common.h - header file for the cm_common library
4 
5 Copyright (C) 2009, 2010, 2012, 2015, 2016 Andreas Enge
6 
7 This file is part of CM.
8 
9 CM is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the
11 Free Software Foundation; either version 3 of the license, or (at your
12 option) any later version.
13 
14 CM is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 for more details.
18 
19 You should have received a copy of the GNU General Public License along
20 with CM; see the file COPYING. If not, write to the Free Software
21 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
22 */
23 
24 #ifndef __CM_COMMON_H
25 #define __CM_COMMON_H
26 
27 #include <sys/times.h>
28 #include <stdbool.h>
29 #include <zlib.h>
30 #include "cm_arith.h"
31 #include "mpfrcx.h"
32 
33 
34 #define CM_MODPOL_J           'j'
35 #define CM_MODPOL_DOUBLEETA   'd'
36 #define CM_MODPOL_SIMPLEETA   's'
37 #define CM_MODPOL_MULTIETA    'm'
38 #define CM_MODPOL_WEBER       'w'
39 #define CM_MODPOL_WEBERSQUARE '2'
40 #define CM_MODPOL_U           'u'
41 #define CM_MODPOL_ATKIN       'a'
42 #define CM_MODPOL_W35         '5'
43 #define CM_MODPOL_W39         '3'
44 #define CM_MODPOL_GAMMA2      'g'
45 #define CM_MODPOL_ATKIN47     '4'
46 #define CM_MODPOL_ATKIN59     'A'
47 #define CM_MODPOL_ATKIN71     '7'
48 #define CM_MODPOL_RAMANUJAN   'r'
49 #define CM_MODPOL_MULTI30     '0'
50 #define CM_MODPOL_MULTI42     'x'
51 #define CM_MODPOL_MULTI70     'y'
52 #define CM_MODPOL_MULTI78     '8'
53 
54 
55 typedef struct {
56    struct tms time_old;
57    double     elapsed;
58 } __cm_timer_struct;
59 typedef __cm_timer_struct cm_timer [1];
60 
61 typedef struct {
62    long int a, b, c, d;
63 } cm_matrix_t;
64 
65 typedef struct {
66    long int **chain;
67       /* data structure for holding addition chains                          */
68       /* entry 0: the value of the exponent; chain [0][0] must be 0 and      */
69       /*                                     chain [1][0] must be 1          */
70       /* entry 1: the rule for obtaining this exponent, with the following   */
71       /*          meaning:                                                   */
72       /*          1: 2*i1                                                    */
73       /*          2: i1 + i2                                                 */
74       /*          3: 2*i1 + i2                                             */
75       /* entries 2 to 3: the indices i1 and i2 yielding this exponent        */
76       /* entry 4: the coefficient with which the term contributes to the     */
77       /*          function (0 if it is only used as an auxiliary term)       */
78    int length;
79       /* the number of terms actually computed for the addition chain */
80 } cm_qdev_t;
81 
82 typedef struct {
83    fprec_t prec;
84    ctype zeta48inv;
85    ftype pi;
86    ctype log_zeta24;
87    ctype twopii;
88    ctype zeta24 [24];
89    ftype sqrt2;
90    cm_qdev_t eta;
91 } cm_modular_t;
92 
93 
94 #if defined (__cplusplus)
95 extern "C" {
96 #endif
97 
98 /* functions for measuring the passing time */
99 extern void cm_timer_start (cm_timer clock);
100 extern void cm_timer_stop (cm_timer clock);
101 extern double cm_timer_get (cm_timer clock);
102 
103 /* generic functions for opening files */
104 extern bool cm_file_open_write (FILE **f, char *filename);
105 extern bool cm_file_open_read (FILE **f, char *filename);
106 extern void cm_file_close (FILE *f);
107 extern void cm_file_gzopen_write (gzFile *f, char *filename);
108 extern void cm_file_gzopen_read (gzFile *f, char *filename);
109 extern void cm_file_gzclose (gzFile f);
110 
111 /* different functions for number theoretic computations */
112 extern int cm_nt_is_prime (mpz_t a);
113 extern int cm_nt_is_prime_l (const unsigned long int prime);
114 extern unsigned long int cm_nt_next_prime (const unsigned long int n);
115 extern long int cm_nt_gcd (long int a, long int b);
116 extern long int cm_nt_gcdext (long int *u, long int *v, long int a,
117    long int b);
118 extern int cm_nt_kronecker (long int a, long int b);
119 extern long int cm_nt_sqrt (const unsigned long int n);
120 extern void cm_nt_factor (long int d, unsigned long int *factors,
121    unsigned int *exponents);
122 
123 extern void cm_nt_mpz_tonelli_z (mpz_t root, mpz_t a, mpz_t p);
124 extern void cm_nt_mpz_tonelli (mpz_t root, const long int a, mpz_t p);
125 
126 extern void cm_nt_elliptic_curve_multiply (mpz_t P_x, mpz_t P_y, bool *P_infty,
127    mpz_t m, mpz_t a, mpz_t p);
128 extern void cm_nt_elliptic_curve_random (mpz_t P_x, mpz_t P_y,
129    mpz_t cofactor, mpz_t a, mpz_t b, mpz_t p);
130 
131 extern bool cm_nt_fget_z (mpz_t out, ftype in);
132 
133 /* functions for evaluating modular functions */
134 extern void cm_modular_fundamental_domain (cptr z);
135 extern void cm_modular_init (cm_modular_t *m, fprec_t prec);
136 extern void cm_modular_clear (cm_modular_t *m);
137 extern int cm_modular_eta_transform (long int *e, ctype czplusd, ctype z,
138    cm_matrix_t M);
139 extern void cm_modular_eta_series (cm_modular_t m, ctype rop, ctype q_24);
140 extern void cm_modular_eta_eval (cm_modular_t m, ctype rop, ctype op);
141 extern void cm_modular_eta_eval_fr (cm_modular_t m, ftype rop, ftype op);
142 extern void cm_modular_atkinhecke_eval (cm_modular_t m, ctype rop, ctype op,
143    unsigned long int l, unsigned long int r);
144 extern void cm_modular_atkinhecke_level_eval (cm_modular_t m, ctype rop,
145    ctype op, unsigned long int l);
146 
147 /* functions for evaluating modular functions using the AGM */
148 extern void cm_fem_eta_eval (cm_modular_t m, ctype rop, ctype op);
149 
150 /* functions reading modular polynomials */
151 extern mpz_t* cm_modpol_read_specialised_mod (int* n, int level, char type,
152    mpz_t p, mpz_t x, const char * datadir);
153 extern void cm_modpol_print_pari (int level, char type, const char* datadir);
154 extern void cm_modpol_print_magma (int level, char type, const char* datadir);
155 
156 #if defined (__cplusplus)
157 }
158 #endif
159 #endif /* ifndef __CM_COMMON_H */
160