any triagle rotation group with rationals

This commit is contained in:
Florian Stecker 2020-07-27 11:57:02 -04:00
parent b7c7d7245c
commit 33cd762253
2 changed files with 125 additions and 58 deletions

View File

@ -6,7 +6,7 @@
//#define MAX_ELEMENTS 2800000
//#define MAX_ELEMENTS 720000
#define MAX_ELEMENTS 14000
#define MAX_ELEMENTS 3000
//#define DRAW_PICTURE 1
void continued_fraction_approximation(mpq_t out, double in, int level)
@ -57,39 +57,99 @@ void quartic(mpq_t out, mpq_t in, int a, int b, int c, int d, int e)
mpq_clear(tmp);
}
void initialize_triangle_generators(mat_workspace *ws, mat *gen, mpq_t s, mpq_t t)
void initialize_triangle_generators(mat_workspace *ws, mat *gen, mpq_t s, mpq_t q)
{
mpq_set_ui(*mat_ref(gen[0], 0, 0), 0, 1);
mpq_set_ui(*mat_ref(gen[0], 0, 1), 0, 1);
mpq_set_ui(*mat_ref(gen[0], 0, 2), 1, 1);
mpq_set_ui(*mat_ref(gen[0], 1, 0), 1, 1);
mpq_set_ui(*mat_ref(gen[0], 1, 1), 0, 1);
mpq_set_ui(*mat_ref(gen[0], 1, 2), 0, 1);
mpq_set_ui(*mat_ref(gen[0], 2, 0), 0, 1);
mpq_set_ui(*mat_ref(gen[0], 2, 1), 1, 1);
mpq_set_ui(*mat_ref(gen[0], 2, 2), 0, 1);
mat r1,r2,r3;
mpq_t rho1, rho2, rho3;
mpq_t b1,c1,a2,c2,a3,b3;
mpq_t sinv;
mpq_set_ui(*mat_ref(gen[1], 0, 0), 1, 1);
mpq_set_ui(*mat_ref(gen[1], 1, 0), 0, 1);
mpq_set_ui(*mat_ref(gen[1], 2, 0), 0, 1);
quartic(*mat_ref(gen[1], 0, 1), t, 0, 0, 1, -1, 2);
quartic(*mat_ref(gen[1], 1, 1), t, 0, 0, -1, 2, -2);
quartic(*mat_ref(gen[1], 2, 1), t, 0, 0, 1, -3, 3);
quartic(*mat_ref(gen[1], 0, 2), t, 0, 0, 1, 0, 3);
quartic(*mat_ref(gen[1], 1, 2), t, 0, 0, -1, 1, -1);
quartic(*mat_ref(gen[1], 2, 2), t, 0, 0, 1, -2, 1);
mpq_inits(sinv,rho1,rho2,rho3,b1,c1,a2,c2,a3,b3,NULL);
mat_init(r1, 3);
mat_init(r2, 3);
mat_init(r3, 3);
mat_pseudoinverse(ws, gen[3], gen[0]); // p^{-1}
mat_pseudoinverse(ws, gen[4], gen[1]); // q^{-1}
mat_multiply(ws, gen[2], gen[4], gen[3]); // r = q^{-1}p^{-1}
mpq_set_ui(sinv, 1, 1);
mpq_div(sinv, sinv, s);
quartic(rho1, s, 0, 0, 1, -1, 1);
quartic(rho2, s, 0, 0, 1, -1, 1);
quartic(rho3, s, 0, 0, 1, 0, 1);
mpq_mul(c1, rho2, q);
mpq_mul(a2, rho3, q);
mpq_mul(b3, rho1, q);
mpq_set_ui(b1, 1, 1);
mpq_set_ui(c2, 1, 1);
mpq_set_ui(a3, 1, 1);
mpq_div(b1, b1, q);
mpq_div(c2, c2, q);
mpq_div(a3, a3, q);
// actually, we want minus everything
mat_zero(r1);
mat_zero(r2);
mat_zero(r3);
mpq_set_si(*mat_ref(r1, 0, 0), -1, 1);
mpq_set_si(*mat_ref(r1, 1, 1), 1, 1);
mpq_set_si(*mat_ref(r1, 2, 2), 1, 1);
mpq_set_si(*mat_ref(r2, 0, 0), 1, 1);
mpq_set_si(*mat_ref(r2, 1, 1), -1, 1);
mpq_set_si(*mat_ref(r2, 2, 2), 1, 1);
mpq_set_si(*mat_ref(r3, 0, 0), 1, 1);
mpq_set_si(*mat_ref(r3, 1, 1), 1, 1);
mpq_set_si(*mat_ref(r3, 2, 2), -1, 1);
mpq_set(*mat_ref(r1, 1, 0), b1);
mpq_set(*mat_ref(r1, 2, 0), c1);
mpq_set(*mat_ref(r2, 0, 1), a2);
mpq_set(*mat_ref(r2, 2, 1), c2);
mpq_set(*mat_ref(r3, 0, 2), a3);
mpq_set(*mat_ref(r3, 1, 2), b3);
mat_zero(gen[0]);
mat_zero(gen[1]);
mat_zero(gen[2]);
mpq_set_ui(*mat_ref(gen[0], 0, 0), 1, 1);
mat_set(gen[0], 1, 1, sinv);
mat_set(gen[0], 2, 2, s);
mat_set(gen[1], 0, 0, s);
mpq_set_ui(*mat_ref(gen[1], 1, 1), 1, 1);
mat_set(gen[1], 2, 2, sinv);
mat_set(gen[2], 0, 0, sinv);
mat_set(gen[2], 1, 1, s);
mpq_set_ui(*mat_ref(gen[2], 2, 2), 1, 1);
mat_multiply(ws, gen[0], r2, gen[0]);
mat_multiply(ws, gen[0], gen[0], r3);
mat_multiply(ws, gen[1], r3, gen[1]);
mat_multiply(ws, gen[1], gen[1], r1);
mat_multiply(ws, gen[2], r1, gen[2]);
mat_multiply(ws, gen[2], gen[2], r2);
mat_pseudoinverse(ws, gen[3], gen[0]);
mat_pseudoinverse(ws, gen[4], gen[1]);
mat_pseudoinverse(ws, gen[5], gen[2]);
// mat_print(gen[0]);
// mat_print(gen[1]);
// mat_print(gen[2]);
// mat_print(gen[3]);
// mat_print(gen[4]);
// mat_print(gen[5]);
/*
mat_print(r1);
mat_print(r2);
mat_print(r3);
mat_print(gen[0]);
mat_print(gen[1]);
mat_print(gen[2]);
mat_print(gen[3]);
mat_print(gen[4]);
mat_print(gen[5]);
*/
mpq_clears(sinv,rho1,rho2,rho3,b1,c1,a2,c2,a3,b3,NULL);
mat_clear(r1);
mat_clear(r2);
mat_clear(r3);
}
char *print_word(groupelement_t *g, char *str)
@ -154,7 +214,7 @@ void enumerate(groupelement_t *group, mat *matrices, mpq_t s, mpq_t t)
mat_workspace_clear(ws);
}
void output_invariants(groupelement_t *group, mat *matrices, mpq_t s, mpq_t t)
void output_invariants(groupelement_t *group, mat *matrices, mpq_t s, mpq_t q)
{
mpq_t tr, trinv;
char buf[100];
@ -206,35 +266,46 @@ double max_slope(groupelement_t *group, mat *matrices, mpq_t s, mpq_t t, int *in
int main(int argc, char *argv[])
{
mpq_t s, t, tmp;
mpz_t accuracy;
double t_;
mpq_t s, q, t, tmp;
double sapprox, tapprox, qapprox, tqfactor;
mat *matrices;
groupelement_t *group;
int index;
mpq_inits(s, t, tmp, NULL);
mpz_init(accuracy);
mpq_inits(s, q, t, tmp, NULL);
group = malloc(MAX_ELEMENTS*sizeof(groupelement_t));
matrices = malloc(MAX_ELEMENTS*sizeof(mat));
for(int i = 0; i < MAX_ELEMENTS; i++)
mat_init(matrices[i], 3);
// mpq_set_str(t, argv[1], 10);
mpz_set_ui(accuracy, 100);
for(int i = 0; ; i++) {
mpq_set(t, tmp);
continued_fraction_approximation(tmp, atof(argv[1]), i);
if(mpz_cmp(mpq_numref(tmp),accuracy) > 0 && mpz_cmp(mpq_denref(tmp),accuracy) > 0)
break;
}
mpq_canonicalize(t);
gmp_fprintf(stdout, "\"t = %Qd = %.3f\"\n", mpq_get_d(t), t);
int acc = 100;
if(argc > 2 && strcmp(argv[2],"p") == 0) {
gmp_fprintf(stdout, "%Qd\n", t);
return 0;
sapprox = atof(argv[1]);
tapprox = atof(argv[2]);
tqfactor = pow((sapprox*sapprox-sapprox+1)*(sapprox*sapprox-sapprox+1)*(sapprox*sapprox+1), 1/6.0);
qapprox = tapprox/tqfactor;
for(int i = 0; ; i++) {
continued_fraction_approximation(tmp, sapprox, i);
// gmp_fprintf(stdout, "%Qd\n", tmp);
if(fabs(mpq_get_d(t)-sapprox) < 1e-10 || (mpz_cmpabs_ui(mpq_numref(tmp),acc) > 0 && mpz_cmpabs_ui(mpq_denref(tmp),acc) > 0))
break;
mpq_set(s, tmp);
}
mpq_canonicalize(s);
for(int i = 0; ; i++) {
continued_fraction_approximation(tmp, qapprox, i);
// gmp_fprintf(stdout, "%Qd\n", tmp);
if(fabs(mpq_get_d(t)-qapprox) < 1e-10 || (mpz_cmpabs_ui(mpq_numref(tmp),acc) > 0 && mpz_cmpabs_ui(mpq_denref(tmp),acc) > 0))
break;
mpq_set(q, tmp);
}
mpq_canonicalize(q);
tqfactor = pow((mpq_get_d(s)*mpq_get_d(s)-mpq_get_d(s)+1)*(mpq_get_d(s)*mpq_get_d(s)-mpq_get_d(s)+1)*(mpq_get_d(s)*mpq_get_d(s)+1), 1/6.0);
gmp_fprintf(stdout, "\"s = %Qd = %.3f, q = %Qd, t = %.3f\"\n", s, mpq_get_d(s), q, mpq_get_d(q)*tqfactor);
generate_triangle_group(group, MAX_ELEMENTS, 3, 3, 4);
@ -242,15 +313,14 @@ int main(int argc, char *argv[])
// mpq_set_ui(t,100+i,100);
// mpq_canonicalize(t);
enumerate(group, matrices, s, t);
enumerate(group, matrices, s, q);
//printf("%f %f\n", mpq_get_d(t), max_slope(group, matrices, s, t, &index));
output_invariants(group, matrices, s, t);
output_invariants(group, matrices, s, q);
// }
for(int i = 0; i < MAX_ELEMENTS; i++)
mat_clear(matrices[i]);
free(matrices);
free(group);
mpq_clears(s, t, tmp, NULL);
mpz_clear(accuracy);
mpq_clears(s, q, t, tmp, NULL);
}

View File

@ -1,10 +1,7 @@
if(!exists("logt")) logt = log(7)
if(!exists("logs")) logs = log(1.0)
if(!exists("logt")) logt = log(1.78)
if(!exists("logs")) logs = log(0.5)
file = sprintf("< ./singular_values %f", exp(logt))
#title = sprintf("s = %f, t = %f", exp(logs), exp(logt))
title = sprintf("t = %.3f", exp(logt))
# print title
file = sprintf("< ./singular_values %f %f", exp(logs), exp(logt))
set zeroaxis
set samples 1000