2016-04-26 17:20:05 +02:00
|
|
|
/*
|
2012-10-08 16:28:28 +02:00
|
|
|
Copyright (C) 2012 Fredrik Johansson
|
|
|
|
|
2016-04-26 17:20:05 +02:00
|
|
|
This file is part of Arb.
|
|
|
|
|
|
|
|
Arb is free software: you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU Lesser General Public License (LGPL) as published
|
|
|
|
by the Free Software Foundation; either version 2.1 of the License, or
|
|
|
|
(at your option) any later version. See <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
2012-10-08 16:28:28 +02:00
|
|
|
|
2013-01-23 15:54:38 +01:00
|
|
|
#include <math.h>
|
2016-03-03 15:42:23 +01:00
|
|
|
#include "flint/double_extras.h"
|
2013-01-23 15:54:38 +01:00
|
|
|
#include "hypgeom.h"
|
2012-10-08 16:28:28 +02:00
|
|
|
|
2013-01-23 15:54:38 +01:00
|
|
|
#define LOG2 0.69314718055994530942
|
|
|
|
#define EXP1 2.7182818284590452354
|
|
|
|
|
|
|
|
static __inline__ double d_root(double x, int r)
|
2012-10-08 16:28:28 +02:00
|
|
|
{
|
2013-01-23 15:54:38 +01:00
|
|
|
if (r == 1)
|
|
|
|
return x;
|
|
|
|
if (r == 2)
|
|
|
|
return sqrt(x);
|
|
|
|
return pow(x, 1. / r);
|
2012-10-08 16:28:28 +02:00
|
|
|
}
|
|
|
|
|
2015-11-10 13:41:43 +00:00
|
|
|
slong
|
2015-11-05 18:05:23 +00:00
|
|
|
hypgeom_estimate_terms(const mag_t z, int r, slong prec)
|
2012-10-08 16:28:28 +02:00
|
|
|
{
|
2013-01-23 15:54:38 +01:00
|
|
|
double y, t;
|
|
|
|
|
2014-06-12 20:23:36 +02:00
|
|
|
t = mag_get_d(z);
|
2013-01-23 15:54:38 +01:00
|
|
|
|
|
|
|
if (t == 0)
|
|
|
|
return 1;
|
|
|
|
|
|
|
|
if (r == 0)
|
|
|
|
{
|
|
|
|
if (t >= 1)
|
|
|
|
{
|
2015-11-06 16:17:27 +00:00
|
|
|
flint_printf("z must be smaller than 1\n");
|
2017-02-28 16:50:03 +01:00
|
|
|
flint_abort();
|
2013-01-23 15:54:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
y = (log(1-t) - prec * LOG2) / log(t) + 1;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
y = (prec * LOG2) / (d_root(t, r) * EXP1 * r);
|
|
|
|
y = (prec * LOG2) / (r * d_lambertw(y)) + 1;
|
|
|
|
}
|
|
|
|
|
2015-11-10 13:31:16 +00:00
|
|
|
if (y >= WORD_MAX / 2)
|
2013-01-23 15:54:38 +01:00
|
|
|
{
|
2015-11-06 16:17:27 +00:00
|
|
|
flint_printf("error: series will converge too slowly\n");
|
2017-02-28 16:50:03 +01:00
|
|
|
flint_abort();
|
2013-01-23 15:54:38 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return y;
|
2012-10-08 16:28:28 +02:00
|
|
|
}
|
2013-01-23 15:54:38 +01:00
|
|
|
|