1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 922 923 924 925 926 927 928 929 930 931 932 933 934 935 936 937 938 939 940 941 942 943 944 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 961 962 963 964 965 966 967 968 969 970 971 972 973 974 975 976 977 978 979 980 981 982 983 984 985 986 987 988 989 990 991 992 993 994 995 996 997 998 999 1000 1001 1002 1003 1004 1005 1006 1007 1008 1009 1010 1011 1012 1013 1014 1015 1016 1017 1018 1019 1020 1021 1022 1023 1024 1025 1026 1027 1028 1029 1030 1031 1032 1033 1034 1035 1036 1037 1038 1039 1040 1041 1042 1043 1044 1045 1046 1047 1048 1049 1050 1051 1052 1053 1054 1055 1056 1057 1058 1059 1060 1061 1062 1063 1064 1065 1066 1067 1068 1069 1070 1071 1072 1073 1074 1075 1076 1077 1078 1079 1080 1081 1082 1083 1084 1085 1086 1087 1088 1089 1090 1091 1092 1093 1094 1095 1096 1097 1098 1099 1100 1101 1102 1103 1104 1105 1106 1107 1108 1109 1110 1111 1112 1113 1114 1115 1116 1117 1118 1119 1120 1121 1122 1123 1124 1125 1126 1127 1128 1129 1130 1131 1132 1133 1134 1135 1136 1137 1138 1139 1140 1141 1142 1143 1144 1145 1146 1147 1148 1149 1150 1151 1152 1153 1154 1155 1156 1157 1158 1159 1160 1161 1162 1163 1164 1165 1166 1167 1168 1169 1170 1171 1172 1173 1174 1175 1176 1177 1178 1179 1180 1181 1182 1183 1184 1185 1186 1187 1188 1189 1190 1191 1192 1193 1194 1195 1196 1197 1198 1199 1200 1201 1202 1203 1204 1205 1206 1207 1208 1209 1210 1211 1212 1213 1214 1215 1216 1217 1218 1219 1220 1221 1222 1223 1224 1225 1226 1227 1228 1229 1230 1231 1232 1233 1234 1235 1236 1237 1238 1239 1240 1241 1242 1243 1244 1245 1246 1247 1248 1249 1250 1251 1252 1253 1254 1255 1256 1257 1258 1259 1260 1261 1262 1263 1264 1265 1266 1267 1268 1269 1270 1271 1272 1273 1274 1275 1276 1277 1278 1279 1280 1281 1282 1283 1284 1285 1286 1287 1288 1289 1290 1291 1292 1293 1294 1295 1296 1297 1298 1299 1300 1301 1302 1303 1304 1305 1306 1307 1308 1309 1310 1311 1312 1313 1314 1315 1316 1317 1318 1319 1320 1321 1322 1323 1324 1325 1326 1327 1328 1329 1330 1331 1332 1333 1334 1335 1336 1337 1338 1339 1340 1341 1342 1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 1355 1356 1357 1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 1369 1370 1371 1372 1373 1374 1375 1376 1377 1378 1379 1380 1381 1382 1383 1384 1385 1386 1387 1388 1389 1390 1391 1392 1393 1394 1395 1396 1397 1398 1399 1400 1401 1402 1403 1404 1405 1406 1407 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519
|
/*
Copyright (C) 2010 Juan Arias de Reyna
Copyright (C) 2019 D.H.J. Polymath
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/>.
*/
#include "acb_dirichlet.h"
#include "arb_calc.h"
/*
* For a detailed explanation of the algorithm implemented in this file, see:
*
* J. Arias de Reyna, "Programs for Riemann's zeta function", (J. A. J. van
* Vonderen, Ed.) Leven met getallen : liber amicorum ter gelegenheid van de
* pensionering van Herman te Riele, CWI (2012) 102-112,
* https://ir.cwi.nl/pub/19724
*/
/*
* These constants define the largest n such that for every k <= n
* the kth zero of the Hardy Z function is governed by Gram's law
* or by Rosser's rule respectively.
*/
static const slong GRAMS_LAW_MAX = 126;
static const slong ROSSERS_RULE_MAX = 13999526;
/*
* This structure describes a node of a doubly linked list.
* Each node represents a height t at which the Hardy Z-function
* Z(t) has been evaluated.
*
* As it relates to this data structure, the big picture of the algorithm
* to isolate the nth zero is roughly:
*
* 1) Initialize a two-node list consisting of the two points
* predicted by Gram's law to surround the nth zero.
* 2) Append and prepend as many additional Gram points as are indicated
* by the theory behind Turing's method, and occasionally insert points
* between existing points for the purpose of certifying blocks of intervals
* as 'good'.
* 3) Repeatedly insert new points into the list, interleaving existing points,
* until the number of sign changes indicated by theory is observed.
* This is where the algorithm would enter an infinite loop if it encountered
* a counterexample to the Riemann hypothesis.
* 4) Traverse the list until we find the pair of adjacent nodes with opposite
* signs of Z(t) that corresponds to the nth zero; the t heights of the
* two nodes define the endpoints of an isolating interval.
* 5) Delete the list.
*/
typedef struct _zz_node_struct
{
arf_struct t; /* height t where v = Z(t) is evaluated */
arb_struct v; /* Z(t) */
fmpz *gram; /* Gram point index or NULL if not a Gram point */
slong prec; /* precision of evaluation of v */
struct _zz_node_struct *prev;
struct _zz_node_struct *next;
}
zz_node_struct;
typedef zz_node_struct zz_node_t[1];
typedef zz_node_struct * zz_node_ptr;
typedef const zz_node_struct * zz_node_srcptr;
static int
zz_node_is_gram_node(const zz_node_t p)
{
return p->gram != NULL;
}
static int
zz_node_sgn(const zz_node_t p)
{
int s = arb_sgn_nonzero(&p->v);
if (!s)
{
flint_printf("unexpectedly imprecise evaluation of Z(t)\n");
flint_abort();
}
return s;
}
/* Good Gram points are Gram points where sgn(Z(g(n)))*(-1)^n > 0. */
static int
zz_node_is_good_gram_node(const zz_node_t p)
{
if (zz_node_is_gram_node(p))
{
int s = zz_node_sgn(p);
if ((s > 0 && fmpz_is_even(p->gram)) ||
(s < 0 && fmpz_is_odd(p->gram)))
{
return 1;
}
}
return 0;
}
static void
zz_node_init(zz_node_t p)
{
arf_init(&p->t);
arb_init(&p->v);
arb_indeterminate(&p->v);
p->prec = 0;
p->gram = NULL;
p->prev = NULL;
p->next = NULL;
}
static void
zz_node_clear(zz_node_t p)
{
arf_clear(&p->t);
arb_clear(&p->v);
if (p->gram)
{
fmpz_clear(p->gram);
flint_free(p->gram);
}
p->prec = 0;
p->gram = NULL;
p->prev = NULL;
p->next = NULL;
}
/*
* The node p represents the evaluation of the Hardy Z-function
* at a point t with some precision. This function re-evaluates
* the Hardy Z-function at t with greater precision, and it also
* guarantees that the precision is high enough to determine the
* sign of Z(t).
*/
static int
zz_node_refine(zz_node_t p)
{
slong default_prec = arf_bits(&p->t) + 8;
if (p->prec < default_prec)
{
p->prec = default_prec;
}
else
{
p->prec *= 2;
}
return _acb_dirichlet_definite_hardy_z(&p->v, &p->t, &p->prec);
}
/*
* Create a node representing an evaluation of the Hardy Z-function
* at arbitrary point t. Upon creation the sign of Z(t) will
* be known with certainty.
*/
static zz_node_ptr
create_non_gram_node(const arf_t t)
{
zz_node_ptr p = flint_malloc(sizeof(zz_node_struct));
zz_node_init(p);
arf_set(&p->t, t);
zz_node_refine(p);
return p;
}
/*
* Create a node representing an evaluation of the Hardy Z-function
* at the nth Gram point g(n). Upon creation a floating point number t will be
* assigned to this node, with the property that there are no zeros of the
* Hardy Z-function between t and the actual value of g(n).
* The sign of Z(t) will also be known with certainty.
*/
static zz_node_ptr
create_gram_node(const fmpz_t n)
{
zz_node_ptr p;
arb_t t, v;
acb_t z;
slong prec = fmpz_bits(n) + 8;
arb_init(t);
arb_init(v);
acb_init(z);
while (1)
{
/* Computing the Gram point to higher precision improves performance
significantly. The likely explanation (not verified) is that
when evaluating the Z-function at an inexact ball using the
Riemann-Siegel formula, error propagation uses a bound for Z'
that is far from tight. The extra precision compensates
for this lack of tightness. */
acb_dirichlet_gram_point(t, n, NULL, NULL, prec + fmpz_bits(n));
acb_set_arb(z, t);
acb_dirichlet_hardy_z(z, z, NULL, NULL, 1, prec);
acb_get_real(v, z);
if (!arb_contains_zero(v))
{
break;
}
prec *= 2;
}
p = flint_malloc(sizeof(zz_node_struct));
zz_node_init(p);
p->gram = flint_malloc(sizeof(fmpz));
fmpz_init(p->gram);
/* t contains g(n) and does not contain a zero of the Z function */
fmpz_set(p->gram, n);
arf_set(&p->t, arb_midref(t));
arb_set(&p->v, v);
p->prec = prec;
arb_clear(t);
arb_clear(v);
acb_clear(z);
return p;
}
/*
* Count the number of Gram intervals between the Gram point
* represented by node a and the Gram point represented by node b.
* Traversing the linked list is not necessary because the Gram indices
* of nodes a and b can be accessed directly.
*/
static slong
count_gram_intervals(zz_node_srcptr a, zz_node_srcptr b)
{
slong out = 0;
if (!a || !b)
{
flint_printf("a and b must be non-NULL\n");
flint_abort();
}
if (!zz_node_is_good_gram_node(a) || !zz_node_is_good_gram_node(b))
{
flint_printf("both nodes must be good Gram points\n");
flint_abort();
}
else
{
fmpz_t m;
fmpz_init(m);
fmpz_sub(m, b->gram, a->gram);
out = fmpz_get_si(m);
fmpz_clear(m);
}
return out;
}
/*
* Count the observed number of sign changes of Z(t) by traversing
* a linked list of evaluated points from node a to node b.
*/
static slong
count_sign_changes(zz_node_srcptr a, zz_node_srcptr b)
{
zz_node_srcptr p, q;
slong n = 0;
if (!a || !b)
{
flint_printf("a and b must be non-NULL\n");
flint_abort();
}
p = a;
q = a->next;
while (p != b)
{
if (!q)
{
flint_printf("prematurely reached end of list\n");
flint_abort();
}
if (zz_node_sgn(p) != zz_node_sgn(q))
{
n++;
}
p = q;
q = q->next;
}
return n;
}
/*
* Modify a linked list that ends with node p,
* by appending nodes representing Gram points.
* Continue until a 'good' Gram point is found.
*/
static zz_node_ptr
extend_to_next_good_gram_node(zz_node_t p)
{
fmpz_t n;
zz_node_ptr q, r;
fmpz_init(n);
if (!zz_node_is_gram_node(p))
{
flint_printf("expected to begin at a gram point\n");
flint_abort();
}
if (p->next)
{
flint_printf("expected to extend from the end of a list\n");
flint_abort();
}
fmpz_set(n, p->gram);
q = p;
while (1)
{
fmpz_add_ui(n, n, 1);
r = create_gram_node(n);
q->next = r;
r->prev = q;
q = r;
r = NULL;
if (zz_node_is_good_gram_node(q))
{
break;
}
}
fmpz_clear(n);
return q;
}
/*
* Modify a linked list that begins with node p,
* by prepending nodes representing Gram points.
* Continue until a 'good' Gram point is found.
*/
static zz_node_ptr
extend_to_prev_good_gram_node(zz_node_t p)
{
fmpz_t n;
zz_node_ptr q, r;
fmpz_init(n);
if (!zz_node_is_gram_node(p))
{
flint_printf("expected to begin at a gram point\n");
flint_abort();
}
if (p->prev)
{
flint_printf("expected to extend from the start of a list\n");
flint_abort();
}
fmpz_set(n, p->gram);
q = p;
while (1)
{
fmpz_sub_ui(n, n, 1);
r = create_gram_node(n);
q->prev = r;
r->next = q;
q = r;
r = NULL;
if (zz_node_is_good_gram_node(q))
{
break;
}
}
fmpz_clear(n);
return q;
}
/*
* TODO: This is probably redundant.
* Can arb_get_lbound_arf ever give a negative arf given a nonnegative arb?
* If the answer is no, and it's probably no, then this function
* can be deleted.
*/
static void
_arb_get_lbound_arf_nonnegative(arf_t res, const arb_t x, slong prec)
{
arb_get_lbound_arf(res, x, prec);
if (arf_cmp_si(res, 0) < 0)
{
arf_zero(res);
}
}
/*
* res = (x1*w1 + x2*w2) / (w1 + w2)
* Undefined if weights are not nonnegative.
* If w1 and w2 are zero, the resulting interval contains x1 and x2.
*/
static void
_weighted_arithmetic_mean(arb_t res, const arf_t x1, const arf_t x2,
const arb_t w1, const arb_t w2, slong prec)
{
if (!arb_is_nonnegative(w1) || !arb_is_nonnegative(w2))
{
arb_indeterminate(res);
}
else if (arb_is_zero(w1) && arb_is_zero(w2))
{
arb_set_interval_arf(res, x1, x2, prec);
}
else if (arb_is_zero(w1))
{
arb_set_arf(res, x2);
}
else if (arb_is_zero(w2))
{
arb_set_arf(res, x1);
}
else if (arb_is_exact(w1) && arb_is_exact(w2))
{
arb_t a, b;
arb_init(a);
arb_init(b);
arb_mul_arf(a, w1, x1, prec);
arb_addmul_arf(a, w2, x2, prec);
arb_add(b, w1, w2, prec);
arb_div(res, a, b, prec);
arb_clear(a);
arb_clear(b);
}
else
{
arb_t a, b, r1, r2;
arb_init(a);
arb_init(b);
arb_init(r1);
arb_init(r2);
arb_zero(a);
arb_zero(b);
_arb_get_lbound_arf_nonnegative(arb_midref(a), w1, prec);
arb_get_ubound_arf(arb_midref(b), w2, prec);
_weighted_arithmetic_mean(r1, x1, x2, a, b, prec);
arb_zero(a);
arb_zero(b);
arb_get_ubound_arf(arb_midref(a), w1, prec);
_arb_get_lbound_arf_nonnegative(arb_midref(b), w2, prec);
_weighted_arithmetic_mean(r2, x1, x2, a, b, prec);
arb_union(res, r1, r2, prec);
arb_clear(a);
arb_clear(b);
arb_clear(r1);
arb_clear(r2);
}
}
/*
* Split the interval (t1, t2) into the intervals (t1, out) and (out, t2)
* in an attempt to increase the number of observed sign changes of Z(t)
* between endpoints.
* v1 and v2 are the Hardy Z-function values at t1 and t2 respectively.
* sign1 and sign2 are the signs of v1 and v2 respectively.
*/
static void
split_interval(arb_t out,
const arf_t t1, const arb_t v1, slong sign1,
const arf_t t2, const arb_t v2, slong sign2, slong prec)
{
if (sign1 == sign2)
{
/*
* out = (sqrt(v2/v1)*t1 + t2) / (sqrt(v2/v1) + 1)
* We have f(t1)=v1, f(t2)=v2 where v1 and v2 have the same sign,
* and we want to guess t between t1 and t2 so that f(t)
* has the opposite sign. Try the vertex of a parabola that would touch
* f(t)=0 between t1 and t2 and would pass through (t1,v1) and (t2,v2).
*/
arb_t w1, w2;
arb_init(w1);
arb_init(w2);
arb_abs(w1, v2); /* w1, v2 is deliberate */
arb_sqrt(w1, w1, prec);
arb_abs(w2, v1); /* w2, v1 is deliberate */
arb_sqrt(w2, w2, prec);
_weighted_arithmetic_mean(out, t1, t2, w1, w2, prec);
arb_clear(w1);
arb_clear(w2);
}
else
{
/*
* out = (t1 + t2) / 2
* There is already one sign change in this interval.
* To find additional sign changes we would need to evaluate
* at least two more points in the interval,
* so begin by just splitting the interval in half at the midpoint.
*/
arb_set_arf(out, t1);
arb_add_arf(out, out, t2, prec);
arb_mul_2exp_si(out, out, -1);
}
}
/*
* Add a new node between each pair of existing nodes in the linked list
* of evaluated values of t, within the sublist demarcated by nodes a and b.
*/
static void
intercalate(zz_node_t a, zz_node_t b)
{
arb_t t;
zz_node_ptr q, r, mid_node;
if (a == NULL || b == NULL)
{
flint_printf("a and b must be non-NULL\n");
flint_abort();
}
if (!zz_node_is_good_gram_node(a) || !zz_node_is_good_gram_node(b))
{
flint_printf("a and b must represent good Gram points\n");
flint_abort();
}
if (a == b) return;
arb_init(t);
q = a;
r = a->next;
while (q != b)
{
if (!r)
{
flint_printf("prematurely reached end of list\n");
flint_abort();
}
while (1)
{
split_interval(t,
&q->t, &q->v, zz_node_sgn(q),
&r->t, &r->v, zz_node_sgn(r),
FLINT_MIN(q->prec, r->prec));
if (!arb_contains_arf(t, &q->t) && !arb_contains_arf(t, &r->t))
{
break;
}
zz_node_refine((q->prec < r->prec) ? q : r);
}
mid_node = create_non_gram_node(arb_midref(t));
q->next = mid_node;
mid_node->prev = q;
mid_node->next = r;
r->prev = mid_node;
q = r;
r = r->next;
}
arb_clear(t);
}
/*
* Virtually trim k Gram/Rosser blocks from the head and from the tail
* of the sublist (a, b). The resulting sublist is (*A, *B).
* No nodes or connections between nodes are modified, added, or deleted.
*/
static void
trim(zz_node_ptr *A, zz_node_ptr *B,
zz_node_ptr a, zz_node_ptr b, slong k)
{
slong n;
for (n = 0; n < k; n++)
{
a = a->next;
while (!zz_node_is_good_gram_node(a))
{
a = a->next;
}
b = b->prev;
while (!zz_node_is_good_gram_node(b))
{
b = b->prev;
}
}
*A = a;
*B = b;
}
/*
* Given a linked sublist beginning at U and ending at V defining function
* evaluations at points that fully separate zeros of Z(t) in the vicinity
* of the nth zero, traverse the list until the nth zero is found.
* Continue traversing the list until len consecutive isolating intervals
* have been found, or until the end of the sublist is reached.
* Return the number of isolated zeros found, starting at the nth zero.
*/
static slong
count_up_separated_zeros(arf_interval_ptr res,
zz_node_srcptr U, zz_node_srcptr V, const fmpz_t n, slong len)
{
if (len <= 0)
{
return 0;
}
else if (fmpz_sgn(n) < 1)
{
flint_printf("nonpositive indices of zeros are not supported\n");
flint_abort();
}
else if (U == NULL || V == NULL)
{
flint_printf("U and V must not be NULL\n");
flint_abort();
}
if (!zz_node_is_good_gram_node(U) || !zz_node_is_good_gram_node(V))
{
flint_printf("U and V must be good Gram points\n");
flint_abort();
}
else
{
slong i = 0;
zz_node_srcptr p = U;
fmpz_t N, k;
fmpz_init(N);
fmpz_init(k);
fmpz_add_ui(N, p->gram, 1);
fmpz_set(k, n);
while (p != V)
{
if (!p->next)
{
flint_printf("prematurely reached end of list\n");
flint_abort();
}
if (zz_node_sgn(p) != zz_node_sgn(p->next))
{
fmpz_add_ui(N, N, 1);
if (fmpz_equal(N, k))
{
arf_set(&res[i].a, &p->t);
arf_set(&res[i].b, &p->next->t);
fmpz_add_ui(k, k, 1);
i++;
if (i == len)
break;
}
}
p = p->next;
}
fmpz_clear(k);
return i;
}
return 0;
}
/*
* Find one 'superblock' below n and one 'superblock' above n.
* The term 'superblock' in this context means a stretch of
* enough consecutive 'good' Rosser/Gram blocks to meet the Turing method bound.
* The output *psb is the number of blocks in the superblock.
* The output nodes *pu and *pv are the first node of the first superblock
* and the last node of the second superblock respectively.
*/
static void
turing_search_near(zz_node_ptr *pu, zz_node_ptr *pv, slong *psb, const fmpz_t n)
{
zz_node_ptr u, v;
slong i;
slong zn; /* target number of sign changes */
slong sb; /* the number of padding blocks required by Turing's method */
slong cgb; /* the number of consecutive good blocks */
const slong loopcount = 4;
fmpz_t k;
fmpz_init(k);
fmpz_sub_ui(k, n, 2);
u = create_gram_node(k);
fmpz_sub_ui(k, n, 1);
v = create_gram_node(k);
u->next = v;
v->prev = u;
if (!zz_node_is_good_gram_node(u))
u = extend_to_prev_good_gram_node(u);
if (!zz_node_is_good_gram_node(v))
v = extend_to_next_good_gram_node(v);
/*
* Extend the search to greater heights t.
*
* Continue adding Gram points until the number of consecutive
* 'good' Gram/Rosser blocks reaches the Turing method bound.
*/
sb = 0;
cgb = 0;
while (1)
{
zz_node_ptr nv;
nv = extend_to_next_good_gram_node(v);
zn = count_gram_intervals(v, nv);
for (i = 0; i < loopcount && count_sign_changes(v, nv) < zn; i++)
{
intercalate(v, nv);
}
if (count_sign_changes(v, nv) >= zn)
{
cgb++;
if (cgb > sb)
{
sb = cgb;
if (acb_dirichlet_turing_method_bound(nv->gram) <= sb)
{
v = nv;
break;
}
}
}
else
{
cgb = 0;
}
v = nv;
}
/* Extend the search to smaller heights t. */
cgb = 0;
while (1)
{
zz_node_ptr pu;
pu = extend_to_prev_good_gram_node(u);
zn = count_gram_intervals(pu, u);
for (i = 0; i < loopcount && count_sign_changes(pu, u) < zn; i++)
{
intercalate(pu, u);
}
if (count_sign_changes(pu, u) >= zn)
{
cgb++;
if (cgb == sb)
{
u = pu;
break;
}
}
else
{
cgb = 0;
}
u = pu;
}
*pu = u;
*pv = v;
*psb = sb;
fmpz_clear(k);
}
/*
* Find one 'double superblock' beginning below the point represented
* by node u, and find one 'double superblock' ending above the point
* represented by node v. The term 'double superblock' in this context
* means a stretch of twice as many consecutive 'good' Rosser/Gram blocks
* as would meet the Turing method bound.
* The output nodes *pu and *pv are the first node of the first double
* superblock and the last node of the second double superblock respectively.
* The output integer *psb reports one half of the number
* of blocks in the double superblock.
* The parameter initial_cgb is the number of consecutive good blocks
* above and below the points represented by nodes u and v respectively.
*/
static void
turing_search_far(zz_node_ptr *pu, zz_node_ptr *pv, slong *psb,
zz_node_ptr u, zz_node_ptr v, slong initial_cgb)
{
slong i;
slong zn; /* target number of sign changes */
slong sb; /* the number of padding blocks required by Turing's method */
slong cgb; /* the number of consecutive good blocks */
const slong loopcount = 4;
/*
* Extend the search to greater heights t.
*
* Continue adding Gram points until the number of consecutive
* 'good' Gram/Rosser blocks is twice the number required by
* the Turing method bound.
*/
sb = 0;
cgb = initial_cgb;
while (1)
{
zz_node_ptr nv;
nv = extend_to_next_good_gram_node(v);
zn = count_gram_intervals(v, nv);
for (i = 0; i < loopcount && count_sign_changes(v, nv) < zn; i++)
{
intercalate(v, nv);
}
if (count_sign_changes(v, nv) >= zn)
{
cgb++;
if (cgb % 2 == 0 && sb < cgb / 2)
{
sb = cgb / 2;
if (acb_dirichlet_turing_method_bound(nv->gram) <= sb)
{
v = nv;
break;
}
}
}
else
{
cgb = 0;
}
v = nv;
}
/* Extend the search to smaller heights t. */
cgb = initial_cgb;
while (1)
{
zz_node_ptr pu;
pu = extend_to_prev_good_gram_node(u);
zn = count_gram_intervals(pu, u);
for (i = 0; i < loopcount && count_sign_changes(pu, u) < zn; i++)
{
intercalate(pu, u);
}
if (count_sign_changes(pu, u) >= zn)
{
cgb++;
if (cgb == sb*2)
{
u = pu;
break;
}
}
else
{
cgb = 0;
}
u = pu;
}
*pu = u;
*pv = v;
*psb = sb;
}
/*
* Used for both zero isolation and for N(t).
* n is the index of a Hardy Z-function zero of interest.
* *pu and *pv are the first and last node of an output list.
* *pU and *pV are the first and last nodes of a sublist with
* fully separated zeros, within the *pu -- *pv list.
*/
static void
_separated_turing_list(zz_node_ptr *pU, zz_node_ptr *pV,
zz_node_ptr *pu, zz_node_ptr *pv, const fmpz_t n)
{
zz_node_ptr U, V, u, v;
slong i;
slong sb_near; /* Turing method bound for near search */
slong sb_far; /* Turing method bound for far search */
slong zn; /* target number of sign changes */
slong variations; /* observed number of sign changes */
const slong loopcount = 4;
/*
* The loopcount controls how hard we try to find zeros in Gram/Rosser
* blocks. If the loopcount is too high then when Rosser's rule is violated
* we will spend too much time searching for zeros that don't exist.
* If the loopcount is too low then we will miss some 'good' blocks,
* causing the search to be extended unnecessarily far from the initial
* guess before eventually making another pass in which loopcount
* is effectively infinite.
*/
if (fmpz_cmp_si(n, 2) < 0)
{
flint_printf("invalid n: "); fmpz_print(n); flint_printf("\n");
flint_abort();
}
turing_search_near(&u, &v, &sb_near, n);
trim(&U, &V, u, v, sb_near);
zn = count_gram_intervals(U, V);
for (i = 0; i < loopcount && count_sign_changes(U, V) < zn; i++)
{
intercalate(U, V);
}
variations = count_sign_changes(U, V);
if (variations > zn)
{
flint_printf("unexpected number of sign changes\n");
flint_abort();
}
else if (variations < zn)
{
zz_node_ptr r = U;
zz_node_ptr s = V;
turing_search_far(&u, &v, &sb_far, u, v, sb_near);
trim(&U, &V, u, v, 2*sb_far);
zn = count_gram_intervals(U, V);
for (i = 0; i < loopcount && count_sign_changes(U, V) < zn; i++)
{
intercalate(U, r);
intercalate(s, V);
}
variations = count_sign_changes(U, V);
if (variations > zn)
{
flint_printf("unexpected number of sign changes\n");
flint_abort();
}
else if (variations < zn)
{
trim(&U, &V, u, v, sb_far);
zn = count_gram_intervals(U, V);
while (count_sign_changes(U, V) < zn)
{
intercalate(U, V);
}
if (count_sign_changes(U, V) != zn)
{
flint_printf("unexpected number of sign changes\n");
flint_abort();
}
}
}
*pu = u;
*pv = v;
*pU = U;
*pV = V;
}
/*
* Used for both zero isolation and for N(t).
* n is the index of a Hardy Z-function zero of interest.
* *pu and *pv are the first and last node of an output list
* with fully separated zeros.
*/
static void
_separated_rosser_list(zz_node_ptr *pu, zz_node_ptr *pv, const fmpz_t n)
{
fmpz_t k;
zz_node_ptr u, v;
if (fmpz_cmp_si(n, 1) < 0 || fmpz_cmp_si(n, ROSSERS_RULE_MAX) > 0)
{
flint_printf("invalid n: "); fmpz_print(n); flint_printf("\n");
flint_abort();
}
fmpz_init(k);
fmpz_sub_ui(k, n, 2);
u = create_gram_node(k);
fmpz_sub_ui(k, n, 1);
v = create_gram_node(k);
u->next = v;
v->prev = u;
if (!zz_node_is_good_gram_node(u))
u = extend_to_prev_good_gram_node(u);
if (!zz_node_is_good_gram_node(v))
v = extend_to_next_good_gram_node(v);
while (count_sign_changes(u, v) != count_gram_intervals(u, v))
{
intercalate(u, v);
}
*pu = u;
*pv = v;
fmpz_clear(k);
}
/*
* Used for both zero isolation and for N(t).
* n is the index of a Hardy Z-function zero of interest.
* *pu and *pv are the first and last node of an output list
* with fully separated zeros.
*/
static void
_separated_gram_list(zz_node_ptr *pu, zz_node_ptr *pv, const fmpz_t n)
{
fmpz_t k;
zz_node_ptr u, v;
if (fmpz_cmp_si(n, 1) < 0 || fmpz_cmp_si(n, GRAMS_LAW_MAX) > 0)
{
flint_printf("invalid n: "); fmpz_print(n); flint_printf("\n");
flint_abort();
}
fmpz_init(k);
fmpz_sub_ui(k, n, 2);
u = create_gram_node(k);
fmpz_sub_ui(k, n, 1);
v = create_gram_node(k);
u->next = v;
v->prev = u;
*pu = u;
*pv = v;
fmpz_clear(k);
}
/*
* Get a list of points that fully separate zeros of Z.
* Used for both zero isolation and for N(t).
* n is the index of a Hardy Z-function zero of interest.
* *pu and *pv are the first and last node of an output list.
* *pU and *pV are the first and last nodes of a sublist with
* fully separated zeros, within the *pu -- *pv list.
*/
static void
_separated_list(zz_node_ptr *pU, zz_node_ptr *pV,
zz_node_ptr *pu, zz_node_ptr *pv, const fmpz_t n)
{
zz_node_ptr U, V, u, v;
if (fmpz_cmp_si(n, GRAMS_LAW_MAX) <= 0)
{
_separated_gram_list(&u, &v, n);
U = u;
V = v;
}
else if (fmpz_cmp_si(n, ROSSERS_RULE_MAX) <= 0)
{
_separated_rosser_list(&u, &v, n);
U = u;
V = v;
}
else
{
_separated_turing_list(&U, &V, &u, &v, n);
}
if (U == NULL || V == NULL)
{
flint_printf("U and V must not be NULL\n");
flint_abort();
}
if (!zz_node_is_good_gram_node(U) || !zz_node_is_good_gram_node(V))
{
flint_printf("U and V must be good Gram points\n");
flint_abort();
}
if (U == V)
{
flint_printf("the list must include at least one interval\n");
flint_abort();
}
*pU = U;
*pV = V;
*pu = u;
*pv = v;
}
/*
* Isolate up to len zeros, starting from the nth zero.
* Return the number of isolated zeros.
*/
static slong
_isolate_hardy_z_zeros(arf_interval_ptr res, const fmpz_t n, slong len)
{
zz_node_ptr U, V, u, v;
slong count;
_separated_list(&U, &V, &u, &v, n);
count = count_up_separated_zeros(res, U, V, n, len);
while (u)
{
v = u;
u = u->next;
zz_node_clear(v);
flint_free(v);
}
return count;
}
/* Isolate len zeros, starting from the nth zero. */
void
acb_dirichlet_isolate_hardy_z_zeros(arf_interval_ptr res, const fmpz_t n, slong len)
{
if (len <= 0)
{
return;
}
else if (fmpz_sgn(n) < 1)
{
flint_printf("nonpositive indices of zeros are not supported\n");
flint_abort();
}
else
{
slong c = 0;
fmpz_t k;
fmpz_init(k);
while (c < len)
{
fmpz_add_si(k, n, c);
c += _isolate_hardy_z_zeros(res + c, k, len - c);
}
fmpz_clear(k);
}
}
void
acb_dirichlet_isolate_hardy_z_zero(arf_t a, arf_t b, const fmpz_t n)
{
if (fmpz_sgn(n) < 1)
{
flint_printf("nonpositive indices of zeros are not supported\n");
flint_abort();
}
else
{
arf_interval_t r;
arf_interval_init(r);
_isolate_hardy_z_zeros(r, n, 1);
arf_set(a, &r->a);
arf_set(b, &r->b);
arf_interval_clear(r);
}
}
static void
count_up(arf_t a, arf_t b, zz_node_srcptr U, zz_node_srcptr V, const fmpz_t n)
{
arf_interval_t r;
arf_interval_init(r);
count_up_separated_zeros(r, U, V, n, 1);
arf_set(a, &r->a);
arf_set(b, &r->b);
arf_interval_clear(r);
}
void
_acb_dirichlet_isolate_turing_hardy_z_zero(arf_t a, arf_t b, const fmpz_t n)
{
zz_node_ptr U, V, u, v;
_separated_turing_list(&U, &V, &u, &v, n);
count_up(a, b, U, V, n);
while (u)
{
v = u;
u = u->next;
zz_node_clear(v);
flint_free(v);
}
}
void
_acb_dirichlet_isolate_rosser_hardy_z_zero(arf_t a, arf_t b, const fmpz_t n)
{
zz_node_ptr u, v;
_separated_rosser_list(&u, &v, n);
count_up(a, b, u, v, n);
while (u)
{
v = u;
u = u->next;
zz_node_clear(v);
flint_free(v);
}
}
void
_acb_dirichlet_isolate_gram_hardy_z_zero(arf_t a, arf_t b, const fmpz_t n)
{
zz_node_ptr u, v;
_separated_gram_list(&u, &v, n);
count_up(a, b, u, v, n);
while (u)
{
v = u;
u = u->next;
zz_node_clear(v);
flint_free(v);
}
}
static void
_acb_set_arf(acb_t res, const arf_t t)
{
acb_zero(res);
arb_set_arf(acb_realref(res), t);
}
/*
* Find the index of the largest Gram point less than t.
* Requires t > 10.
*/
static void
gram_index(fmpz_t res, const arf_t t)
{
if (arf_cmp_si(t, 10) < 0)
{
flint_printf("gram_index requires t > 10\n");
flint_abort();
}
else
{
acb_t z;
slong prec = arf_abs_bound_lt_2exp_si(t) + 8;
acb_init(z);
while (1)
{
_acb_set_arf(z, t);
acb_dirichlet_hardy_theta(z, z, NULL, NULL, 1, prec);
arb_const_pi(acb_imagref(z), prec);
arb_div(acb_realref(z), acb_realref(z), acb_imagref(z), prec);
arb_floor(acb_realref(z), acb_realref(z), prec);
if (arb_get_unique_fmpz(res, acb_realref(z)))
{
break;
}
prec *= 2;
}
acb_clear(z);
}
}
/*
* Compute nzeros(t) for up to len values of t
* and return the number computed. p must be in increasing order,
* and all entries must be greater than 10.
*/
static slong
_exact_zeta_multi_nzeros(fmpz *res, arf_srcptr points, slong len)
{
zz_node_ptr U, V, u, v, p;
arb_t x;
fmpz_t n, N;
slong i;
arf_srcptr t;
int s;
slong prec;
arb_init(x);
fmpz_init(n);
fmpz_init(N);
/*
* The first point is located between two Gram points. Find the unique n
* such that the nth zero is also predicted to be located between these
* Gram points.
*/
gram_index(n, points);
fmpz_add_ui(n, n, 2);
/* Get a list of points that fully separate zeros of Z. */
_separated_list(&U, &V, &u, &v, n);
p = U;
fmpz_add_ui(N, U->gram, 1);
/*
* It's possible that one or more points are located between
* the first Gram point and the arf_t representative of that Gram point.
*/
for (i = 0, t = points; i < len && arf_cmp(t, &p->t) <= 0; i++, t++)
{
fmpz_set(res + i, N);
}
while (i < len && p != V)
{
if (!p->next)
{
flint_printf("prematurely reached the end of the list\n");
flint_abort();
}
if (zz_node_sgn(p) != zz_node_sgn(p->next))
{
while (i < len && arf_cmp(t, &p->next->t) <= 0)
{
prec = arf_abs_bound_lt_2exp_si(t) + 8;
s = _acb_dirichlet_definite_hardy_z(x, t, &prec);
if (zz_node_sgn(p->next) == s)
{
fmpz_add_ui(res + i, N, 1);
}
else
{
fmpz_set(res + i, N);
}
t++;
i++;
}
fmpz_add_ui(N, N, 1);
}
p = p->next;
}
/*
* It's possible that the first point in the array is located between
* the last Gram point and the arf_t representative of that Gram point.
*/
if (i == 0)
{
fmpz_set(res, N);
i++;
}
while (u)
{
v = u;
u = u->next;
zz_node_clear(v);
flint_free(v);
}
arb_clear(x);
fmpz_clear(n);
fmpz_clear(N);
return i;
}
/*
* Compute nzeros for len values of t. The array p must be in increasing order.
*/
static void
exact_zeta_multi_nzeros(fmpz *res, arf_srcptr p, slong len)
{
slong i, c;
arf_srcptr q;
if (len <= 0)
{
return;
}
for (i = 0, q = p; i < len - 1; i++, q++)
{
if (arf_cmp(q, p) > 0)
{
flint_printf("p must be in increasing order\n");
flint_abort();
}
}
c = 0;
while (c < len)
{
if (arf_cmp_si(p + c, 14) < 0)
{
fmpz_zero(res + c);
c++;
}
else
{
c += _exact_zeta_multi_nzeros(res + c, p + c, len - c);
}
}
}
void
_acb_dirichlet_exact_zeta_nzeros(fmpz_t res, const arf_t t)
{
exact_zeta_multi_nzeros(res, t, 1);
}
void
acb_dirichlet_hardy_z_zeros(arb_ptr res, const fmpz_t n, slong len, slong prec)
{
if (len <= 0)
{
return;
}
else if (fmpz_sgn(n) < 1)
{
flint_printf("nonpositive indices of zeros are not supported\n");
flint_abort();
}
else
{
slong i;
arf_interval_ptr p = _arf_interval_vec_init(len);
acb_dirichlet_isolate_hardy_z_zeros(p, n, len);
for (i = 0; i < len; i++)
{
_acb_dirichlet_refine_hardy_z_zero(res + i, &p[i].a, &p[i].b, prec);
}
_arf_interval_vec_clear(p, len);
}
}
static void
_arb_set_interval_fmpz(arb_t res, const fmpz_t a, const fmpz_t b)
{
fmpz_t n;
fmpz_init(n);
fmpz_add(n, a, b);
arf_set_fmpz(arb_midref(res), n);
fmpz_sub(n, b, a);
mag_set_fmpz(arb_radref(res), n);
arb_mul_2exp_si(res, res, -1);
fmpz_clear(n);
}
void
acb_dirichlet_zeta_nzeros(arb_t res, const arb_t t, slong prec)
{
if (arb_is_exact(t))
{
fmpz_t n;
fmpz_init(n);
_acb_dirichlet_exact_zeta_nzeros(n, arb_midref(t));
arb_set_fmpz(res, n);
fmpz_clear(n);
}
else
{
arf_struct b[2];
fmpz n[2];
arf_init(b);
arf_init(b + 1);
fmpz_init(n);
fmpz_init(n + 1);
arb_get_lbound_arf(b, t, prec);
arb_get_ubound_arf(b + 1, t, prec);
exact_zeta_multi_nzeros(n, b, 2);
_arb_set_interval_fmpz(res, n, n + 1);
arf_clear(b);
arf_clear(b + 1);
fmpz_clear(n);
fmpz_clear(n + 1);
}
arb_set_round(res, res, prec);
}
void
acb_dirichlet_zeta_nzeros_gram(fmpz_t res, const fmpz_t n)
{
zz_node_ptr U, V, u, v, p;
fmpz_t k, N;
if (fmpz_cmp_si(n, -1) < 0)
{
flint_printf("n must be >= -1\n");
flint_abort();
}
fmpz_init(k);
fmpz_init(N);
/*
* Get a list of points that fully separate zeros of Z.
* The kth zero is expected to be between the k-2 and the k-1 gram points.
*/
fmpz_add_ui(k, n, 2);
_separated_list(&U, &V, &u, &v, k);
p = U;
fmpz_add_ui(N, U->gram, 1);
fmpz_set_si(res, -1);
while (1)
{
if (p == NULL)
{
flint_printf("prematurely reached the end of the list\n");
flint_abort();
}
if (zz_node_is_gram_node(p) && fmpz_equal(n, p->gram))
{
fmpz_set(res, N);
break;
}
if (zz_node_sgn(p) != zz_node_sgn(p->next))
{
fmpz_add_ui(N, N, 1);
}
if (p == V)
{
break;
}
p = p->next;
}
if (fmpz_sgn(res) < 0)
{
flint_printf("failed to find the gram point\n");
flint_abort();
}
while (u)
{
v = u;
u = u->next;
zz_node_clear(v);
flint_free(v);
}
fmpz_clear(k);
fmpz_clear(N);
}
|