From 6f2e7e90d5678ccf84fc2e21f5b9aed87d9963a6 Mon Sep 17 00:00:00 2001 From: Zeno Rogue Date: Sun, 5 Jul 2020 00:53:02 +0200 Subject: [PATCH] expansion analyzer now can use libgmp for better analysis --- expansion.cpp | 123 ++++++++++++++++++++++++++++++++++++++------------ hprint.cpp | 6 +++ sysconfig.h | 8 ++++ util.cpp | 9 ++++ 4 files changed, 116 insertions(+), 30 deletions(-) diff --git a/expansion.cpp b/expansion.cpp index b18e0eae..642dd70c 100644 --- a/expansion.cpp +++ b/expansion.cpp @@ -30,7 +30,11 @@ struct expansion_analyzer { vector > children; int rootid, diskid; int coefficients_known; + #if CAP_GMP + vector coef; + #else vector coef; + #endif int valid_from, tested_to; ld growth; @@ -189,36 +193,61 @@ bignum& expansion_analyzer::get_descendants(int level, int type) { bool expansion_analyzer::verify(int id) { if(id < isize(coef)) return false; + #if CAP_GMP + mpq_class res = 0; + for(int t=0; t= bignum::BASE) return 0; - ld matrix[100][128]; + println(hlog, "try ", v, ", ", step); + int more = reg3::in_rule() ? 1 : 5; + #if CAP_GMP == 0 + if(get_descendants(step+v+v+more).approx_int() >= bignum::BASE) return 0; + typedef ld val; + const val unit = 1; + #else + typedef mpq_class val; + const val unit = 1; + #endif + val matrix[100][128]; for(int i=0; i= bignum::BASE2) break; + #endif if(!verify(tested_to)) return 2; tested_to++; } @@ -247,7 +283,7 @@ void expansion_analyzer::find_coefficients() { if(coefficients_known) return; if(!N) preliminary_grouping(), reduce_grouping(); for(int v=1; v<25; v++) - for(int step=0; step<1000; step++) { + for(int step=0; step<3 * v; step++) { int val = valid(v, step); if(val == 0) break; if(val == 3) { coefficients_known = 2; return; } @@ -584,6 +620,29 @@ const int scrollspeed = 100; bool not_only_descendants = false; +#if CAP_GMP +string produce_coef_formula(vector coef) { +#else +string produce_coef_formula(vector coef) { +#endif + string fmt = "a(d+" + its(isize(coef)) + ") = "; + bool first = true; + for(int i=0; i 1) fmt += " + " + its(coef[i]); + else if(coef[i] < -1) fmt += " - " + its(-coef[i]); + fmt += "a(d"; + if(i != isize(coef) - 1) + fmt += "+" + its(isize(coef) - 1 - i); + fmt += ")"; + first = false; + } + return fmt; + } + void expansion_analyzer::view_distances_dialog() { static int lastticks; if(scrolling_distances && !bounded) { @@ -617,6 +676,7 @@ void expansion_analyzer::view_distances_dialog() { celllister cl(cwt.at, bounded ? maxlen-1 : gamerange(), 100000, NULL); for(cell *c: cl.lst) if((not_only_descendants || is_descendant(c)) && curr_dist(c) < maxlen) qty[curr_dist(c)]++; } + #if !CAP_GMP if(sizes_known() && !not_only_descendants) { find_coefficients(); if(gamerange()+1 >= valid_from && coefficients_known == 2) { @@ -626,6 +686,7 @@ void expansion_analyzer::view_distances_dialog() { } } } + #endif } dialog::addBreak(100 - 100 * scrolltime / scrollspeed); @@ -645,21 +706,7 @@ void expansion_analyzer::view_distances_dialog() { find_coefficients(); if(coefficients_known == 2) { - string fmt = "a(d+" + its(isize(coef)) + ") = "; - bool first = true; - for(int i=0; i 1) fmt += " + " + its(coef[i]); - else if(coef[i] < -1) fmt += " - " + its(-coef[i]); - fmt += "a(d"; - if(i != isize(coef) - 1) - fmt += "+" + its(isize(coef) - 1 - i); - fmt += ")"; - first = false; - } + string fmt = produce_coef_formula(coef); fmt += " (d>" + its(valid_from-1) + ")"; dialog::addHelp(fmt); } @@ -705,14 +752,15 @@ void compute_coefficients() { start_game(); printf(" sizes:"); - for(int i=0; i<10; i++) printf(" %d", expansion.get_descendants(i).approx_int()); + for(int i=0; i string lalign(int len, T... t) { diff --git a/sysconfig.h b/sysconfig.h index e81cc648..ec4060f9 100644 --- a/sysconfig.h +++ b/sysconfig.h @@ -75,6 +75,10 @@ #define CAP_ZLIB 1 #endif +#ifndef CAP_GMP +#define CAP_GMP 0 +#endif + #define CAP_FRAMELIMIT (!ISMOBWEB) #if ISMOBILE @@ -458,6 +462,10 @@ typedef unsigned GLuint; #include #endif +#if CAP_GMP +#include +#endif + #if CAP_THREAD #if OLD_MINGW #include "mingw.thread.h" diff --git a/util.cpp b/util.cpp index c7eae10d..5f6748ee 100644 --- a/util.cpp +++ b/util.cpp @@ -507,6 +507,15 @@ struct bignum { return digits[0] + digits[1] * (long long) BASE; } + #if CAP_GMP + mpq_class as_mpq() const { + string s = get_str(999999); + string t; + for(char c: s) if(c != ' ') t += c; + return mpq_class(t); + } + #endif + friend inline bignum operator +(bignum a, const bignum& b) { a.addmul(b, 1); return a; } friend inline bignum operator -(bignum a, const bignum& b) { a.addmul(b, -1); return a; } };