/usr/include/Lfunction/Lfind_zeros.h is in liblfunction-dev 1.23+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 1561 1562 1563 1564 1565 1566 1567 1568 1569 1570 1571 1572 1573 1574 1575 1576 1577 1578 1579 1580 1581 1582 1583 1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 1598 1599 1600 1601 1602 1603 1604 1605 1606 1607 1608 1609 1610 1611 1612 1613 1614 1615 1616 1617 1618 1619 1620 1621 1622 1623 1624 1625 1626 1627 1628 1629 1630 1631 1632 1633 1634 1635 1636 1637 1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 | /*
Copyright (C) 2001,2002,2003,2004 Michael Rubinstein
This file is part of the L-function package L.
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
Check the License for details. You should have received a copy of it, along
with the package; see the file 'COPYING'. If not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
//use Brent's method to locate a zero given a sign change.
//see the wikipedia article: http://en.wikipedia.org/wiki/Brent's_method
template <class ttype>
Double L_function <ttype>::
zeros_zoom_brent(Double L1, Double L2, Double u, Double v)
{
Double a=u,b=v,L_a=L1,L_b=L2,c,L_c,L_s,d;
bool my_flag=true;
bool s_bound;
Double tmp,tmp2;
Double s,x,y,z;
//Double tol=tolerance2*sqrt(v*v+1);
if(my_norm(L_a)<my_norm(L_b)){
tmp=a;a=b;b=tmp;
tmp=L_a;L_a=L_b;L_b=tmp;
}
c=a; L_c=L_a;
do{
//cout << a << " " << b << " " << L_a <<" " << L_b << endl;
x=L_a-L_b; y=L_a-L_c; z=L_b-L_c;
if(y!=0&&z!=0){
s=a*L_b*L_c/(x*y)-b*L_a*L_c/(x*z)+c*L_a*L_b/(y*z); //inverse quad interpolation
//cout << "quad " << s << endl;
}
else{
s=b-L_b*(b-a)/(L_b-L_a); //secant rule
//cout << "secant " << s << endl;
}
if(a<b){
tmp=(3*a+b)/4;tmp2=b;
}
else{
tmp2=(3*a+b)/4;tmp=b;
}
if ((s<tmp||s>tmp2) || (my_flag &&my_norm(s-b)>= my_norm(b-c) / 2) || (!my_flag && my_norm(s-b)>=my_norm(c-d)/2)){
s=(a+b)/2; my_flag=true;
//cout << "midpoint " << s << endl;
}
else my_flag=false;
L_s= real(this->value(.5+I*s,0,"rotated pure"));
d=c;
c=b; L_c=L_b;
if (L_a*L_s<0){
b=s;L_b=L_s;
}
else{
a=s;
L_a=L_s;
}
if(my_norm(L_a)< my_norm(L_b)){
tmp=a;a=b;b=tmp;
tmp=L_a;L_a=L_b;L_b=tmp;
}
}while(abs(L_b)>tolerance3 && abs((b-a)/(abs(b)+1))>tolerance2);
// sqrt(v*v+1) is only good for zeta. Other L-functions have more
// precision loss.
//if(abs(L_b)>tol*100)
// cout << "Mofu. Big zero " << b << " " <<L_b<<endl;
return(b);
}
template <class ttype>
void L_function <ttype>::
find_zeros(Double t1, Double t2, Double step_size, const char* filename, const char* message_stamp)
{
Double t,x,y;
Double u,v,tmp2;
Long count2=0;
Double previous_zero=t1;
fstream file;
if(my_verbose>2) cout << "entering find_zeros" << endl;
if(!strcmp(filename,"cout"))
{
cout << setprecision(DIGITS3);
}
else
{
file.open(filename, ios::out|ios::app);
file << setprecision(DIGITS3);
}
t=t1; u=t;
x=real(this->value(.5+I*t,0,"rotated pure"));
if(my_verbose>1)
cout << "look for sign change " << t << " " << x << endl;
do{
t=t+step_size;
y=real(this->value(.5+I*t,0,"rotated pure"));
if(my_verbose>1)
cout << "look for sign change " << t << " " << y << endl;
v=t;
if(sn(x)!=sn(y)) //if sign change is found...divide and conquer
//until the difference is small.
{
tmp2=zeros_zoom_brent(x,y,u,v);
count2++;
int tmp_DIGITS = Int(DIGITS3+log(abs(tmp2)+2)/2.3)+1;
if(!strcmp(filename,"cout"))
{
//cout << tmp2 << endl;
cout << message_stamp << " ";
if(tmp_DIGITS<DIGITS)
cout << setprecision(tmp_DIGITS);
else
cout << setprecision(DIGITS);
cout << tmp2 << " ";
cout << setprecision(DIGITS3);
if(t1>0)
cout << this->N((tmp2+previous_zero)/2)/2 -N(t1)/2-(count2-1.) << endl;
else
cout << this->N((tmp2+previous_zero)/2)/2 -(count2-1.) << endl;
previous_zero=tmp2;
}
else
{
//file << tmp2 << endl;
file << message_stamp << " ";
if(tmp_DIGITS<DIGITS)
file << setprecision(tmp_DIGITS);
else
file << setprecision(DIGITS);
file << tmp2 << " ";
file << setprecision(DIGITS3);
if(t1>0)
file << this->N((tmp2+previous_zero)/2)/2 -N(t1)/2-(count2-1.) << endl;
else
file << this->N((tmp2+previous_zero)/2)/2-(count2-1.) << endl;
previous_zero=tmp2;
}
}
u=t;
x=y;
}while((t1<t&&t<t2)||(t2<t&&t<t1));
if(strcmp(filename,"cout")) file.close();
}
//The following function is the same as above function. The only difference is that it
//puts the result in the vector result which is passed by reference
template <class ttype>
void L_function <ttype>::
find_zeros_v(Double t1, Double t2, Double step_size, vector<Double> &result)
{
Double t,x,y;
Double u,v,tmp2;
Long count2=0;
Double previous_zero=t1;
t=t1; u=t;
x=real(this->value(.5+I*t,0,"rotated pure"));
do{
t=t+step_size;
y=real(this->value(.5+I*t,0,"rotated pure"));
v=t;
if(sn(x)!=sn(y)) //if sign change is found...divide and conquer
//until the difference is small.
{
tmp2=zeros_zoom_brent(x,y,u,v);
count2++;
result.push_back( tmp2);
previous_zero=tmp2;
}
u=t;
x=y;
}while((t1<t&&t<t2)||(t2<t&&t<t1));
}
//find zeros using gram points and Rosser's rule. Not used by package.
template <class ttype>
void L_function <ttype>::
find_zeros_via_gram(Double t1, Long count,Double max_refine,const char* filename, const char* message_stamp){
if(my_verbose>2) cout << "entering find_zeros_via_gram" << endl;
//find_zeros_elaborate(t1,count,max_refine);
Long m,n;
Double r,x;
int i,j,k;
int gram_sign; // sign of (-1)^n L(gram_pt_n)
// compute 100 gram points, check gram's law, and partition into blocks (we might
// need to stop before the 100th gram point).
Double gram_pt[100][2];// 0 stores the gram point, 1 stores the corresponding L-value
x=initialize_gram(t1);
gram_pt[0][0]=x;
gram_pt[0][1]=real(this->value(.5+I*x,0,"rotated pure"));
for(m=1;m<=99;m++){
x=next_gram(x);
gram_pt[m][0]=x;
gram_pt[m][1]=real(this->value(.5+I*x,0,"rotated pure"));
//cout << m << " " << gram_pt[m][1]*pow(-1.,1.*m) << endl;
}
r=1;m=n=0;
for(i=0;i<=99;i++){
if(r*gram_pt[i][1]>0)m++; else n++;
r=-r;
}
if(m>65) gram_sign=1;
else if(n>65) gram_sign=-1;
else{
cout << "Possible violation of Gram's law" << endl;
for(i=0;i<=99;i++)
cout << i<< " " <<gram_pt[i][0] << " " << gram_pt[i][1]*pow(-1.,i) << " " <<
gram_pt[i][1]*real(this->value(.5-I*gram_pt[i][0],0,"rotated pure"))<< endl;
exit(1);
}
int number_blocks=0; //number of gram blocks
int gram_block[100][3]; //0 stores the start index, 1 the stop index,
//2 the number of sign changes in the block.
i=0; r=gram_sign;
do{
if(r*gram_pt[i][1]>0){
j=i;
do{
j++; r=-r;
}while(r*gram_pt[j][1]<0&&j<99);
if(r*gram_pt[j][1]>0){
if(j-i>3){ cout<<"is a long block\n";
for(int ii=i;ii<=j;ii++)
cout << ii<< " " <<gram_pt[ii][0] << " " << gram_pt[ii][1]*pow(-1.,ii) << endl;
}
number_blocks++;
gram_block[number_blocks][0]=i;
gram_block[number_blocks][1]=j;
gram_block[number_blocks][2]=0;
}
i=j;
}
else{i++;r=-r;}
}while(i<99);
// check which blocks are good. If any are bad, search in neighboring blocks.
//if, in the end, any of the front 6 blocks, say, are still bad or if gram_pt_1 > t1
//then look for the zeros in [t1,gram_pt_1): count how many there ought to be
//using arg principle, then search for them. Actually, we should use the arg principle
//to count how many zeros there ought to be from t1 to the first point from where the
//gram point search kicks in successfully.
//if all zeros are found dump the first 50, say and repeat the gram block search
//using the next 50 gram points.
/*
int i; Double tmp,tmp2;
Complex L_1;
Double y;
Double global_average=0;
x=.1;i=0;
do{
L_1=this->value(x+I*(t1-0.65444));
//L_1=this->value(x+I*(t1-.1));
if(L_1!=0) y=imag(log(L_1));
if(i>0){
tmp2=y-tmp;
if(tmp2>5)tmp2=tmp2-2*Pi;
if(tmp2<-5)tmp2=tmp2+2*Pi;
global_average=global_average+tmp2;
//cout << "global average: " <<x<<" "<< y << " " <<tmp << " " <<global_average/(2*Pi) << endl;
}
tmp=y;
x=x+.01;
i++;
}while(x<=.9);
Double t2=t1-0.65444;
//Double t2=t1-0.1;
do{
t2=t2+.01;
L_1=this->value(x+I*t2);
if(L_1!=0) y=imag(log(L_1));
tmp2=y-tmp;
if(tmp2>5)tmp2=tmp2-2*Pi;
if(tmp2<-5)tmp2=tmp2+2*Pi;
global_average=global_average+tmp2;
//cout << "global average: " <<x<<" "<< y << " " <<tmp << " " <<global_average/(2*Pi) << endl;
tmp=y;
}while(t2<=1);
do{
x=x-.01;
L_1=this->value(x+I*t2);
if(L_1!=0) y=imag(log(L_1));
tmp2=y-tmp;
if(tmp2>5)tmp2=tmp2-2*Pi;
if(tmp2<-5)tmp2=tmp2+2*Pi;
global_average=global_average+tmp2;
//cout << "global average: " <<x<<" "<< y << " " <<tmp << " " <<global_average/(2*Pi) << endl;
tmp=y;
}while(x>.1);
do{
t2=t2-.01;
L_1=this->value(x+I*t2);
if(L_1!=0) y=imag(log(L_1));
tmp2=y-tmp;
if(tmp2>5)tmp2=tmp2-2*Pi;
if(tmp2<-5)tmp2=tmp2+2*Pi;
global_average=global_average+tmp2;
//cout << "global average: " <<x<<" "<< y << " " <<tmp << " " <<global_average/(2*Pi) << endl;
tmp=y;
}while(t2>t1-0.65444);
//}while(t2>t1-.1);
global_average=global_average/(2*Pi);
cout <<"hihih " << global_average<<endl;
*/
}
template <class ttype>
int L_function <ttype>::
compute_rank(bool print_rank){
Complex w,z;
Double x,y,h1,h2,tmp_h,tmp_x;
int r;
z=this->value(.5);
x=abs(z);
if(x>.00001){
if(print_rank) cout << "analytic rank equals "<< 0 << endl;
return 0;
}
h2=.00001;
y=abs(this->value(.5+h2));
if(y>1.e-9){
x=abs(this->value(.5+1.01*h2));
r = Int(rint(abs(log(x)-log(y))/log(1.01)));
if(print_rank) cout << "analytic rank equals "<< r << endl;
return r;
}
h2=.001;
y=abs(this->value(.5+h2));
if(y>1.e-9){
x=abs(this->value(.5+1.01*h2));
r = Int(rint(abs(log(x)-log(y))/log(1.01)));
if(print_rank) cout << "analytic rank equals "<< r << endl;
return r;
}
h1=.001;
do{
h2=h1;
h1=h1*5;
x=abs(this->value(.5+h1));
//cout << x << " multiply by 5, at " << h1<<endl;
}while(x<1.e-9&&h1<2);
if(x>1.e-8){
do{
do{
tmp_h=h1;
h1=(h1+h2)/2;
x=abs(this->value(.5+h1));
//cout << x << " divide and conquer, at " << h1<<endl;
}while(x>1.e-8);
if(x<1.e-9)
{
h2=h1;
h1=tmp_h;
}
}while(x<1.e-9);
}
//y=abs(this->value(.5+h2));
y=x;
x=abs(this->value(.5+1.01*h1));
//cout << h1<< " " << x << " " << y << " "<<(log(x)-log(y))/log(1.01)<<endl;
r = Int(rint(abs(log(x)-log(y))/log(1.01)));
if(print_rank) cout << "analytic rank equals "<< r << endl;
return (r);
}
template <class ttype>
void L_function <ttype>::
verify_rank(int rank){
int analytic_rank=compute_rank();
if(rank!=analytic_rank)
cout<< "given rank "<<rank<< " is different than computed analytic rank "<<
analytic_rank <<endl;
//else
//cout<< "given rank "<<rank<< " equals analytic rank"<<endl;
}
//elaborate zero finder keeps an array of zeros and goes back to find missing zeros
//if they are detected via N(T) comparison.
//Finds zeros of L(1/2+It) or of L(1/2+It)*L(1/2-It) (choice is specified by bool do_negative)
//Latter must be used if the L-function has complex coefficients.
template <class ttype>
void L_function <ttype>::
find_zeros_via_N(Long count,bool do_negative,Double max_refine, int rank, bool test_explicit_formula, const char* filename, const char* message_stamp)
{
Double t,x,y;
Double u,v,tmp=0;
Long count2=0; //counts how many zeros have been printed
Double count_all=0; //counts how many zeros have been found
Double previous_zero=0;
Double step_size,refined_step_size;
fstream file;
int i,j;
Double zeros_S[100][3]; // stores list of consecutive zeros: S[n][0]
// corresponding S(T) value: S[n][1]
// and the sign of the zero (+1 or -1) S[n][2]
//int degree; //degree of the L-function
Double *xxx_zeros; //for sending to the explicit formula test
int xxx_number_zeros; //number of zeros to store for the explicit formula
//if self dual, we also send the -gammas (if gamma != 0).
//If not self dual (i.e. if do_negative)
//we are already computing zeros above and below
int xxx_number_zeros_test; //number of zeros to use in the explicit formula (eventually equals xxx_number_zeros)
int xxx_count=0; //used to count the number of zeros in the xxx_zeros array, mod the size of the array
int xxx_current_zero=0; //the zero in the xxx_zeros array on which to center the
bool xxx_half_full=false; //once xxx_zeros is half full start doing the explicit formula test
bool xxx_full=false; //to keep track of when the array is completely full
double xxx_T=1,xxx_local_density; // used to determine how many zeros to store for the explicit formula
Complex *xxx_log_diff_coeffs; //stores Dirichlet coefficients of the logarithmic derivative
do{
xxx_T=xxx_T*1.3;
}while(N(xxx_T)<2*count+100); //the 2 because in the self dual case we only count half the zeros with |t|<T.
//No big deal. The desity
xxx_local_density=(N(xxx_T+1)-N(xxx_T))/2; //N(T) counts zeros in |t|<T, so the length of the interval in question is 2
//double theta=0;
//for(j=1;j<=a;j++)
//{
//theta = theta+gamma[j];
//}
//degree=(int)(2*theta);
xxx_number_zeros = 2*(int)(20+2*DIGITS/xxx_local_density);
//if(!do_negative) xxx_number_zeros=xxx_number_zeros*2;
//we might, at some point in the future have to make this size dynamic if I find that I'm not using enough zeros in the explicit formula test
//or we might instead make xxx_A bigger and take more coefficients of the logarithmic derivative (right now I'm, taking 150)
if(my_verbose>0) cout << "Initializing xxx_zeros array to contain " << xxx_number_zeros << " zeros" << endl;
xxx_zeros = new Double[xxx_number_zeros];
for(i=0;i<xxx_number_zeros;i++) xxx_zeros[i] = 0;
int xxx_flag=0; //explicit formula test flag. Equals 1 on fail of the explicit formula.
Double xxx_A =2.3/DIGITS; //the A to use in phi(gamma)= exp(-A (gamma-x_0)^2)
if(test_explicit_formula){
xxx_log_diff_coeffs = new Complex[151];
dirichlet_coeffs_log_diff(150, xxx_log_diff_coeffs);
}
int ii; //counts number of local zeros
int i1,i2; //used for looping through blocks for missing zeros
Double local_average;
int found_missing=0; //number missing zeros found
int to_find=0; //number of missing zeros to find
Double x2,y2,u2,v2,tmp2,tmp3,tmp4; //used to search for missing zeros
Double x3,x3_c,u3;
Double x_c=1,y_c=1,x2_c=1,y2_c=1; //used to search for zeros below the real axis
int number_insert; //1 or 2 according to whether we find zeros below and/or above real axis
bool also_do_end_pt; //when looking for missing zeros between found zeros,
//we need to do one last sign check step in the case
//that we are simultaneously looking for zeros of the
//conjugate as well.
int analytic_rank; //order of vanishing at the critical point
for(i=0;i<=99;i++)
for(j=0;j<=2;j++)
zeros_S[i][j]=0;
if(my_verbose>2)
cout << "entering find_zeros_via_N to look for " << count << " zeros" << endl;
if(!strcmp(filename,"cout"))
{
cout << setprecision(DIGITS3);
}
else
{
file.open(filename, ios::out|ios::app);
file << setprecision(DIGITS3);
}
//count multiplicity of zero at 0, then start slightly higher.
//doesn't matter if I miss a zero inbetween, since this
//will then be detected by N(T) comparison and searched for.
ii=0; //will be used to count zeros in the zeros_S array
if(rank>=0) analytic_rank=rank;
else analytic_rank=this->compute_rank();
if(analytic_rank>0){
count_all=count_all+analytic_rank;
if(!do_negative) count_all=count_all*.5;
ii=analytic_rank;
for(i=1;i<=ii;i++){
zeros_S[i][0]=0;
zeros_S[i][1]=0;
zeros_S[i][2]=1;
}
}
if(analytic_rank==0) t=0;
else t=exp(log(.00001)/analytic_rank); //ad hoc method that will eventually fail
u=t;
x=real(this->value(.5+I*t,0,"rotated pure"));
if(do_negative) x_c=real(this->value(.5-I*t,0,"rotated pure"));
if(my_verbose>1)
cout << "look for sign change " << t << " " << x << endl;
do{
step_size=.6/(this->N(t+22)-this->N(t+21)); //i.e. increment by .6 the average
//the choice of .6 was determined experimentally
//XXXXXXXXX might need to adapt the shift for case where the imag part
//of the lambda's can be large XXXXXXXXXXX
if(do_negative) step_size=step_size/2;
t=t+step_size;
y=real(this->value(.5+I*t,0,"rotated pure"));
if(do_negative) y_c=real(this->value(.5-I*t,0,"rotated pure"));
if(my_verbose>1)
cout << "look for sign change " << t << " " << y << " " << y_c<<endl;
v=t;
if(sn(x)!=sn(y)) //if sign change is found...zoom in
{
tmp=zeros_zoom_brent(x,y,u,v);
count_all++; ii++;
zeros_S[ii][0]=tmp;
zeros_S[ii][2]=1;
if(do_negative)zeros_S[ii][1]=this->N((tmp+previous_zero)/2) -(count_all-1);
else zeros_S[ii][1]=this->N((tmp+previous_zero)/2)/2 -(count_all-1);
}
if(sn(x_c)!=sn(y_c)) //if sign change is found...zoom in
{
tmp=-zeros_zoom_brent(y_c,x_c,-v,-u);
count_all++; ii++;
zeros_S[ii][0]=tmp;
zeros_S[ii][2]=-1;
if(zeros_S[ii][0]<zeros_S[ii-1][0]){
tmp2=zeros_S[ii-1][0];
zeros_S[ii-1][0]= zeros_S[ii][0];
zeros_S[ii][0]= tmp2;
tmp2=zeros_S[ii-1][2];
zeros_S[ii-1][2]= zeros_S[ii][2];
zeros_S[ii][2]= tmp2;
tmp2=zeros_S[ii-1][1];
zeros_S[ii-1][1]= this->N((zeros_S[ii-1][0]+previous_zero)/2) -(count_all-2);
}
zeros_S[ii][1]=this->N((tmp+zeros_S[ii-1][0])/2)-(count_all-1);
}
if(ii>15){
local_average=0;
for(i=ii;i>=ii-15;i--) local_average=local_average+zeros_S[i][1]/16;
if(local_average>.7) to_find=1;
if(local_average>1.5) to_find=Int(local_average+.5);
if(to_find>0){
if(my_verbose>1)
cout << "missing zeros detected "<<endl;
refined_step_size=step_size/2;
i1=ii-7; i2=i1;
found_missing=0;
do{
if(i2>ii-1+found_missing)i2=ii-1+found_missing;
if(i1<1&&count2>0)i1=1; if(i1<1&&count2==0)i1=0;
for(i=i1;i<=i2;i++){
u2=zeros_S[i][0];
if(do_negative){
if(zeros_S[i][2]>0){
x2=real(this->value(.5+I*(u2+refined_step_size),0,"rotated pure"));
x2_c=real(this->value(.5-I*u2,0,"rotated pure"));
}
else{
x2=real(this->value(.5+I*u2,0,"rotated pure"));
x2_c=real(this->value(.5-I*(u2+refined_step_size),0,"rotated pure"));
}
}
else{
u2=zeros_S[i][0]+.5*refined_step_size;
x2=real(this->value(.5+I*u2,0,"rotated pure"));
}
also_do_end_pt=false;
do{
v2=u2+refined_step_size;
if(v2<zeros_S[i+1][0])
{
also_do_end_pt=true;
y2=real(this->value(.5+I*v2,0,"rotated pure"));
if(do_negative) y2_c=real(this->value(.5-I*v2,0,"rotated pure"));
x3=y2;x3_c=y2_c;u3=v2;
if(sn(x2)!=sn(y2)||sn(x2_c)!=sn(y2_c)) //if sign change is found...divide and conquer
//until the difference is small.
{
number_insert=0;
if(sn(x2)!=sn(y2)){
tmp2=zeros_zoom_brent(x2,y2,u2,v2);
found_missing++;i2=i2+1;
count_all++;
number_insert++;
}
if(sn(x2_c)!=sn(y2_c)){
tmp3=-zeros_zoom_brent(y2_c,x2_c,-v2,-u2);
if(sn(x2)!=sn(y2)&&tmp2>tmp3){tmp4=tmp2;tmp2=tmp3;tmp3=tmp4;}
found_missing++;i2=i2+1;
count_all++;
number_insert++;
}
for(j=ii+found_missing;j>=i+1+number_insert;j--){
zeros_S[j][0]=zeros_S[j-number_insert][0];
zeros_S[j][2]=zeros_S[j-number_insert][2];
zeros_S[j][1]=zeros_S[j-number_insert][1]-number_insert;
}
if(number_insert==1&&sn(x2)!=sn(y2)){
zeros_S[i+1][0]=tmp2;
zeros_S[i+1][2]=1;
zeros_S[i+1][1]=zeros_S[i+2][1]-1; //not strictly correct, but close enough
//XXXXXXXXXXXXX do this more precisely.don't be lazy!
}
else if(number_insert==1&&sn(x2_c)!=sn(y2_c)){
zeros_S[i+1][0]=tmp3;
zeros_S[i+1][2]=-1;
zeros_S[i+1][1]=zeros_S[i+2][1]-1; //not strictly correct, but close enough
//XXXXXXXXXXXXX do this more precisely.don't be lazy!
}
else{
zeros_S[i+2][0]=tmp3;
zeros_S[i+2][2]=-1;
zeros_S[i+2][1]=zeros_S[i+3][1]-1; //not strictly correct, but close enough
zeros_S[i+1][0]=tmp2;
zeros_S[i+1][2]=1;
zeros_S[i+1][1]=zeros_S[i+2][1]-1; //not strictly correct, but close enough
}
i=i-2*number_insert;if(i<1)i=1;
}
//x3=x2;x3_c=x2_c;u3=u2;
x2=y2;x2_c=y2_c;u2=v2;
}
}while(v2<zeros_S[i+1][0]);
//in the do_negative case, there is one final sign change check needed
if(also_do_end_pt&&found_missing==0&&do_negative&&zeros_S[i+1][2]>0){
v2=zeros_S[i+1][0];
y2_c=real(this->value(.5-I*v2,0,"rotated pure"));
if(sn(x3_c)!=sn(y2_c))
{
tmp3=-zeros_zoom_brent(y2_c,x3_c,-v2,-u3);
found_missing++;i2=i2+1;
count_all++;
for(j=ii+found_missing;j>=i+2;j--){
zeros_S[j][0]=zeros_S[j-1][0];
zeros_S[j][2]=zeros_S[j-1][2];
zeros_S[j][1]=zeros_S[j-1][1]-1;
}
zeros_S[i+1][0]=tmp3;
zeros_S[i+1][2]=-1;
zeros_S[i+1][1]=zeros_S[i+2][1]-1;
i=i-2;if(i<1)i=1;
}
} //if(do_negative&&zeros_S[i+1][2]>0)
else if(also_do_end_pt&&found_missing==0&&do_negative&&zeros_S[i+1][2]<0){
v2=zeros_S[i+1][0];
y2=real(this->value(.5+I*v2,0,"rotated pure"));
if(sn(x3)!=sn(y2))
{
tmp2=zeros_zoom_brent(x3,y2,u3,v2);
found_missing++;i2=i2+1;
count_all++;
for(j=ii+found_missing;j>=i+2;j--){
zeros_S[j][0]=zeros_S[j-1][0];
zeros_S[j][1]=zeros_S[j-1][1]-1;
zeros_S[j][2]=zeros_S[j-1][2];
}
zeros_S[i+1][0]=tmp2;
zeros_S[i+1][2]=1;
zeros_S[i+1][1]=zeros_S[i+2][1]-1;
i=i-2;if(i<1)i=1;
}
}
}//for i
refined_step_size=refined_step_size/2;
i2=i2+2;i1=i1-2;
if(refined_step_size/step_size< .1){i2=i2+1;i1=i1-8;}
}while(found_missing<to_find && refined_step_size > step_size/max_refine);
to_find=0;
if(refined_step_size <= step_size/max_refine){
int tmp_DIGITS = Int(DIGITS3+log(zeros_S[i][0]+2)/2.3)+1;
if(!strcmp(filename,"cout"))
{
if(tmp_DIGITS<DIGITS)
cout << setprecision(tmp_DIGITS);
else
cout << setprecision(DIGITS);
cout<<"missing zeros detected." << endl;
cout<<"failed to find using refined step sizes of " << refined_step_size << endl;
for(i=1;i<=ii+found_missing;i++)
cout << zeros_S[i][0]*zeros_S[i][2] << " " << zeros_S[i][1]<< endl;
}
else{
if(tmp_DIGITS<DIGITS)
file << setprecision(tmp_DIGITS);
else
file << setprecision(DIGITS);
file<<"missing zeros detected." << endl;
file<<"failed to find using refined step sizes of " << refined_step_size << endl;
for(i=1;i<=ii+found_missing;i++)
file << zeros_S[i][0]*zeros_S[i][2] << " " << zeros_S[i][1]<< endl;
}
file.close();
exit(1);
}
}
}
ii=ii+found_missing; found_missing=0;
//dump up to 10 zeros, checking explicit formula
ii=ii+found_missing; found_missing=0;
if(ii>=50){
i=1;
do{
int tmp_DIGITS = Int(DIGITS3+log(zeros_S[i][0]+2)/2.3)+1;
if(!strcmp(filename,"cout"))
{
cout << message_stamp << " ";
if(tmp_DIGITS<DIGITS)
cout << setprecision(tmp_DIGITS);
else
cout << setprecision(DIGITS);
cout << setprecision(Int(DIGITS3+log(zeros_S[i][0]+2)/2.3));
cout << zeros_S[i][0]*zeros_S[i][2];
if(test_explicit_formula){
if(!xxx_half_full&&xxx_count<xxx_number_zeros/2){ //initially fill up half of the xxx_zeros array
xxx_zeros[xxx_count]=zeros_S[i][0]*zeros_S[i][2];
xxx_count++;
if(!do_negative&&xxx_count>analytic_rank){ //the latter because we don't want to double count zeros at s=1/2
xxx_zeros[xxx_count]=-zeros_S[i][0]*zeros_S[i][2];
xxx_count++;
}
}
else{ //array is half full so now proceed to do explicit formula test, and then place a new zero or pair of zeros
//wrapping around to the front end of the array if needed.
xxx_half_full=true; //is now half full
//might only do this every, say, tenth zero
if(xxx_count<2) xxx_full=true; //i.e. if xxx_count has wrapped around to the beginning of the array
if(!xxx_full) xxx_number_zeros_test=xxx_count; else xxx_number_zeros_test=xxx_number_zeros;
if(!xxx_full||count2%10==0) //run the test on the first few zeros and then every tenth zero
xxx_flag = this->test_explicit_formula(xxx_A,xxx_zeros[xxx_current_zero], xxx_zeros,xxx_number_zeros_test,xxx_log_diff_coeffs,150);
if(xxx_flag==1){
cout << "WARNING: FAILURE OF THE EXPLICIT FORMULA. DUMPING ZEROS AND QUITTING." << endl;
for(i=1;i<=50;i++)
cout << zeros_S[i][0]*zeros_S[i][2] << " " << zeros_S[i][1]<< endl;
exit(1);
}
//place another zero in the list
xxx_current_zero=(xxx_current_zero+1)%xxx_number_zeros;
xxx_zeros[xxx_count]=zeros_S[i][0]*zeros_S[i][2];
xxx_count=(xxx_count+1)%xxx_number_zeros;
if(!do_negative){ //and it's negative if self dual
xxx_zeros[xxx_count]=-zeros_S[i][0]*zeros_S[i][2];
xxx_count=(xxx_count+1)%xxx_number_zeros;
xxx_current_zero=(xxx_current_zero+1)%xxx_number_zeros;
}
}
}
if(my_verbose==-1) cout << " " << setprecision(6) << zeros_S[i][1]; //XXXXXXXXXXXXXX added for debugging purposes
if(i>1&&my_verbose==-1&&abs(zeros_S[i-1][0]-zeros_S[i][0])< exp(-2.3*(DIGITS3-3))) cout <<
"XXXXXXXXX close zeros detected XXXXXXX " << i << " " << zeros_S[i-1][0] << " " << zeros_S[i][0];
cout<<endl;
}
else
{
file << message_stamp << " ";
if(tmp_DIGITS<DIGITS)
file << setprecision(tmp_DIGITS);
else
file << setprecision(DIGITS);
file << setprecision(Int(DIGITS3+log(zeros_S[i][0]+2)/2.3));
file << zeros_S[i][0]*zeros_S[i][2] << endl;
}
i++; count2++;
}while(i<=10&&count2<count);
/*
//check that the explicit formula is satisfied using a test function that picks out local zeros.
//test function is exp(-A(x-x_0)^2) where , here, we set A=2.3/Digits x_0 = current_zero
//We basically want to detect anomalies as we spit out zeros one at a time.
if(do_negative){
for(i=1;i<=50;i++) xxx_zeros[i-1]=zeros_S[i][0]*zeros_S[i][2];
//xxx_A = 2.3*DIGITS3/my_norm(xxx_zeros[49]-xxx_zeros[0]);
xxx_flag = this->test_explicit_formula(xxx_A,xxx_zeros[0], xxx_zeros,50);
}
if(xxx_flag==1){
cout << "WARNING: FAILURE OF THE EXPLICIT FORMULA. DUMPING ZEROS AND QUITTING." << endl;
for(i=1;i<=50;i++)
cout << zeros_S[i][0]*zeros_S[i][2] << " " << zeros_S[i][1]<< endl;
exit(1);
}
*/
for(i=11;i<=ii;i++){
zeros_S[i-10][0]=zeros_S[i][0];
zeros_S[i-10][2]=zeros_S[i][2];
zeros_S[i-10][1]=zeros_S[i][1];
}
if(!strcmp(filename,"cout")) cout << setprecision(DIGITS3);
else file << setprecision(DIGITS3);
ii=ii-10;
}
//}
previous_zero=tmp;
u=t;
x=y;
x_c=y_c;
}while(count2<count);
if(strcmp(filename,"cout")) file.close();
delete [] xxx_zeros;
}
//elaborate zero finder keeps an array of zeros and goes back to find missing zeros
//if they are detected via N(T) comparison.
//Finds zeros of L(1/2+It) or of L(1/2+It)*L(1/2-It) (choice is specified by bool do_negative)
//Latter must be used if the L-function has complex coefficients.
//THIS IS THE SAME FUNCTION as above. test_explicit_formula is still taken as input although
//all code for it is removed. It is present to be used in future.
template <class ttype> void L_function <ttype>::find_zeros_via_N_v(Long count,bool do_negative,Double max_refine, int rank, bool test_explicit_formula, vector<Double> &result)
{
Double t,x,y;
Double u,v,tmp=0;
Long count2=0; //counts how many zeros have been printed
Double count_all=0; //counts how many zeros have been found
Double previous_zero=0;
Double step_size,refined_step_size;
int i,j;
Double zeros_S[100][3]; // stores list of consecutive zeros: S[n][0]
// corresponding S(T) value: S[n][1]
// and the sign of the zero (+1 or -1) S[n][2]
//int degree; //degree of the L-function
Double *xxx_zeros; //for sending to the explicit formula test
int xxx_number_zeros; //number of zeros to store for the explicit formula
//if self dual, we also send the -gammas (if gamma != 0).
//If not self dual (i.e. if do_negative)
//we are already computing zeros above and below
int xxx_number_zeros_test; //number of zeros to use in the explicit formula (eventually equals xxx_number_zeros)
int xxx_count=0; //used to count the number of zeros in the xxx_zeros array, mod the size of the array
int xxx_current_zero=0; //the zero in the xxx_zeros array on which to center the
bool xxx_half_full=false; //once xxx_zeros is half full start doing the explicit formula test
bool xxx_full=false; //to keep track of when the array is completely full
double xxx_T=1,xxx_local_density; // used to determine how many zeros to store for the explicit formula
Complex *xxx_log_diff_coeffs; //stores Dirichlet coefficients of the logarithmic derivative
do{
xxx_T=xxx_T*1.3;
}while(N(xxx_T)<2*count+100); //the 2 because in the self dual case we only count half the zeros with |t|<T.
//No big deal. The desity
xxx_local_density=(N(xxx_T+1)-N(xxx_T))/2; //N(T) counts zeros in |t|<T, so the length of the interval in question is 2
//double theta=0;
//for(j=1;j<=a;j++)
//{
//theta = theta+gamma[j];
//}
//degree=(int)(2*theta);
xxx_number_zeros = 2*(int)(20+2*DIGITS/xxx_local_density);
//if(!do_negative) xxx_number_zeros=xxx_number_zeros*2;
//we might, at some point in the future have to make this size dynamic if I find that I'm not using enough zeros in the explicit formula test
//or we might instead make xxx_A bigger and take more coefficients of the logarithmic derivative (right now I'm, taking 150)
if(my_verbose>0) cout << "Initializing xxx_zeros array to contain " << xxx_number_zeros << " zeros" << endl;
xxx_zeros = new Double[xxx_number_zeros];
for(i=0;i<xxx_number_zeros;i++) xxx_zeros[i] = 0;
int xxx_flag=0; //explicit formula test flag. Equals 1 on fail of the explicit formula.
Double xxx_A =2.3/DIGITS; //the A to use in phi(gamma)= exp(-A (gamma-x_0)^2)
if(test_explicit_formula){
xxx_log_diff_coeffs = new Complex[151];
dirichlet_coeffs_log_diff(150, xxx_log_diff_coeffs);
}
int ii; //counts number of local zeros
int i1,i2; //used for looping through blocks for missing zeros
Double local_average;
int found_missing=0; //number missing zeros found
int to_find=0; //number of missing zeros to find
Double x2,y2,u2,v2,tmp2,tmp3,tmp4; //used to search for missing zeros
Double x3,x3_c,u3;
Double x_c=1,y_c=1,x2_c=1,y2_c=1; //used to search for zeros below the real axis
int number_insert; //1 or 2 according to whether we find zeros below and/or above real axis
bool also_do_end_pt; //when looking for missing zeros between found zeros,
//we need to do one last sign check step in the case
//that we are simultaneously looking for zeros of the
//conjugate as well.
int analytic_rank; //order of vanishing at the critical point
for(i=0;i<=99;i++)
for(j=0;j<=2;j++)
zeros_S[i][j]=0;
if(my_verbose>2)
cout << "entering find_zeros_via_N to look for " << count << " zeros" << endl;
//count multiplicity of zero at 0, then start slightly higher.
//doesn't matter if I miss a zero inbetween, since this
//will then be detected by N(T) comparison and searched for.
ii=0; //will be used to count zeros in the zeros_S array
if(rank>=0) analytic_rank=rank;
else analytic_rank=this->compute_rank();
if(analytic_rank>0){
count_all=count_all+analytic_rank;
if(!do_negative) count_all=count_all*.5;
ii=analytic_rank;
for(i=1;i<=ii;i++){
zeros_S[i][0]=0;
zeros_S[i][1]=0;
zeros_S[i][2]=1;
}
}
if(analytic_rank==0) t=0;
else t=exp(log(.00001)/analytic_rank); //ad hoc method that will eventually fail
u=t;
x=real(this->value(.5+I*t,0,"rotated pure"));
if(do_negative) x_c=real(this->value(.5-I*t,0,"rotated pure"));
if(my_verbose>1)
cout << "look for sign change " << t << " " << x << endl;
do{
step_size=.6/(this->N(t+22)-this->N(t+21)); //i.e. increment by .6 the average
//the choice of .6 was determined experimentally
//XXXXXXXXX might need to adapt the shift for case where the imag part
//of the lambda's can be large XXXXXXXXXXX
if(do_negative) step_size=step_size/2;
t=t+step_size;
y=real(this->value(.5+I*t,0,"rotated pure"));
if(do_negative) y_c=real(this->value(.5-I*t,0,"rotated pure"));
if(my_verbose>1)
cout << "look for sign change " << t << " " << y << " " << y_c<<endl;
v=t;
if(sn(x)!=sn(y)) //if sign change is found...zoom in
{
tmp=zeros_zoom_brent(x,y,u,v);
count_all++; ii++;
zeros_S[ii][0]=tmp;
zeros_S[ii][2]=1;
if(do_negative)zeros_S[ii][1]=this->N((tmp+previous_zero)/2) -(count_all-1);
else zeros_S[ii][1]=this->N((tmp+previous_zero)/2)/2 -(count_all-1);
}
if(sn(x_c)!=sn(y_c)) //if sign change is found...zoom in
{
tmp=-zeros_zoom_brent(y_c,x_c,-v,-u);
count_all++; ii++;
zeros_S[ii][0]=tmp;
zeros_S[ii][2]=-1;
if(zeros_S[ii][0]<zeros_S[ii-1][0]){
tmp2=zeros_S[ii-1][0];
zeros_S[ii-1][0]= zeros_S[ii][0];
zeros_S[ii][0]= tmp2;
tmp2=zeros_S[ii-1][2];
zeros_S[ii-1][2]= zeros_S[ii][2];
zeros_S[ii][2]= tmp2;
tmp2=zeros_S[ii-1][1];
zeros_S[ii-1][1]= this->N((zeros_S[ii-1][0]+previous_zero)/2) -(count_all-2);
}
zeros_S[ii][1]=this->N((tmp+zeros_S[ii-1][0])/2)-(count_all-1);
}
if(ii>15){
local_average=0;
for(i=ii;i>=ii-15;i--) local_average=local_average+zeros_S[i][1]/16;
if(local_average>.7) to_find=1;
if(local_average>1.5) to_find=Int(local_average+.5);
if(to_find>0){
if(my_verbose>1)
cout << "missing zeros detected "<<endl;
refined_step_size=step_size/2;
i1=ii-7; i2=i1;
found_missing=0;
do{
if(i2>ii-1+found_missing)i2=ii-1+found_missing;
if(i1<1&&count2>0)i1=1; if(i1<1&&count2==0)i1=0;
for(i=i1;i<=i2;i++){
u2=zeros_S[i][0];
if(do_negative){
if(zeros_S[i][2]>0){
x2=real(this->value(.5+I*(u2+refined_step_size),0,"rotated pure"));
x2_c=real(this->value(.5-I*u2,0,"rotated pure"));
}
else{
x2=real(this->value(.5+I*u2,0,"rotated pure"));
x2_c=real(this->value(.5-I*(u2+refined_step_size),0,"rotated pure"));
}
}
else{
u2=zeros_S[i][0]+.5*refined_step_size;
x2=real(this->value(.5+I*u2,0,"rotated pure"));
}
also_do_end_pt=false;
do{
v2=u2+refined_step_size;
if(v2<zeros_S[i+1][0])
{
also_do_end_pt=true;
y2=real(this->value(.5+I*v2,0,"rotated pure"));
if(do_negative) y2_c=real(this->value(.5-I*v2,0,"rotated pure"));
x3=y2;x3_c=y2_c;u3=v2;
if(sn(x2)!=sn(y2)||sn(x2_c)!=sn(y2_c)) //if sign change is found...divide and conquer
//until the difference is small.
{
number_insert=0;
if(sn(x2)!=sn(y2)){
tmp2=zeros_zoom_brent(x2,y2,u2,v2);
found_missing++;i2=i2+1;
count_all++;
number_insert++;
}
if(sn(x2_c)!=sn(y2_c)){
tmp3=-zeros_zoom_brent(y2_c,x2_c,-v2,-u2);
if(sn(x2)!=sn(y2)&&tmp2>tmp3){tmp4=tmp2;tmp2=tmp3;tmp3=tmp4;}
found_missing++;i2=i2+1;
count_all++;
number_insert++;
}
for(j=ii+found_missing;j>=i+1+number_insert;j--){
zeros_S[j][0]=zeros_S[j-number_insert][0];
zeros_S[j][2]=zeros_S[j-number_insert][2];
zeros_S[j][1]=zeros_S[j-number_insert][1]-number_insert;
}
if(number_insert==1&&sn(x2)!=sn(y2)){
zeros_S[i+1][0]=tmp2;
zeros_S[i+1][2]=1;
zeros_S[i+1][1]=zeros_S[i+2][1]-1; //not strictly correct, but close enough
//XXXXXXXXXXXXX do this more precisely.don't be lazy!
}
else if(number_insert==1&&sn(x2_c)!=sn(y2_c)){
zeros_S[i+1][0]=tmp3;
zeros_S[i+1][2]=-1;
zeros_S[i+1][1]=zeros_S[i+2][1]-1; //not strictly correct, but close enough
//XXXXXXXXXXXXX do this more precisely.don't be lazy!
}
else{
zeros_S[i+2][0]=tmp3;
zeros_S[i+2][2]=-1;
zeros_S[i+2][1]=zeros_S[i+3][1]-1; //not strictly correct, but close enough
zeros_S[i+1][0]=tmp2;
zeros_S[i+1][2]=1;
zeros_S[i+1][1]=zeros_S[i+2][1]-1; //not strictly correct, but close enough
}
i=i-2*number_insert;if(i<1)i=1;
}
//x3=x2;x3_c=x2_c;u3=u2;
x2=y2;x2_c=y2_c;u2=v2;
}
}while(v2<zeros_S[i+1][0]);
//in the do_negative case, there is one final sign change check needed
if(also_do_end_pt&&found_missing==0&&do_negative&&zeros_S[i+1][2]>0){
v2=zeros_S[i+1][0];
y2_c=real(this->value(.5-I*v2,0,"rotated pure"));
if(sn(x3_c)!=sn(y2_c))
{
tmp3=-zeros_zoom_brent(y2_c,x3_c,-v2,-u3);
found_missing++;i2=i2+1;
count_all++;
for(j=ii+found_missing;j>=i+2;j--){
zeros_S[j][0]=zeros_S[j-1][0];
zeros_S[j][2]=zeros_S[j-1][2];
zeros_S[j][1]=zeros_S[j-1][1]-1;
}
zeros_S[i+1][0]=tmp3;
zeros_S[i+1][2]=-1;
zeros_S[i+1][1]=zeros_S[i+2][1]-1;
i=i-2;if(i<1)i=1;
}
} //if(do_negative&&zeros_S[i+1][2]>0)
else if(also_do_end_pt&&found_missing==0&&do_negative&&zeros_S[i+1][2]<0){
v2=zeros_S[i+1][0];
y2=real(this->value(.5+I*v2,0,"rotated pure"));
if(sn(x3)!=sn(y2))
{
tmp2=zeros_zoom_brent(x3,y2,u3,v2);
found_missing++;i2=i2+1;
count_all++;
for(j=ii+found_missing;j>=i+2;j--){
zeros_S[j][0]=zeros_S[j-1][0];
zeros_S[j][1]=zeros_S[j-1][1]-1;
zeros_S[j][2]=zeros_S[j-1][2];
}
zeros_S[i+1][0]=tmp2;
zeros_S[i+1][2]=1;
zeros_S[i+1][1]=zeros_S[i+2][1]-1;
i=i-2;if(i<1)i=1;
}
}
}//for i
refined_step_size=refined_step_size/2;
i2=i2+2;i1=i1-2;
if(refined_step_size/step_size< .1){i2=i2+1;i1=i1-8;}
}while(found_missing<to_find && refined_step_size > step_size/max_refine);
to_find=0;
if(refined_step_size <= step_size/max_refine){
cout<<"missing zeros detected." << endl;
cout<<"failed to find using refined step sizes of " << refined_step_size << endl;
for(i=1;i<=ii+found_missing;i++)
result.push_back( zeros_S[i][0]*zeros_S[i][2]);
return;
}
}
}
ii=ii+found_missing; found_missing=0;
//dump up to 10 zeros, checking explicit formula
ii=ii+found_missing; found_missing=0;
if(ii>=50){
i=1;
do{
int tmp_DIGITS = Int(DIGITS3+log(zeros_S[i][0]+2)/2.3)+1;
result.push_back( zeros_S[i][0]*zeros_S[i][2]);
i++; count2++;
}while(i<=10&&count2<count);
for(i=11;i<=ii;i++){
zeros_S[i-10][0]=zeros_S[i][0];
zeros_S[i-10][2]=zeros_S[i][2];
zeros_S[i-10][1]=zeros_S[i][1];
}
ii=ii-10;
}
previous_zero=tmp;
u=t;
x=y;
x_c=y_c;
}while(count2<count);
delete [] xxx_zeros;
}
//elaborate zero finder keeps an array of zeros and goes back to find missing zeros
//if they are detected via N(T) comparison.
template <class ttype>
void L_function <ttype>::
find_zeros_elaborate(Double t1, Long count,Double max_refine, const char* filename, const char* message_stamp)
{
if(my_verbose>2)
cout << "entering find_zeros_elaborate to look for " << count << " zeros" << endl;
Double t,x,y;
Double r;
Double u,v,L_u,L_v,tmp;
Long count2=0; //counts how many zeros have been printed
Long count_all=0; //counts how many zeros have been found
Double previous_zero=t1;
Double step_size,refined_step_size;
fstream file;
int i,j;
Double zeros_S[100][2]; // stores list of consecutive zeros and S(T) data
int ii; //counts number of local zeros
int i1,i2; //used for looping through blocks for missing zeros
Double average_S;
Double global_average, local_average;
int number_big_S; //count how many S(T)'s are suspiciously large
int found_missing=0; //number missing zeros found
int to_find=0; //number of missing zeros to find
Double x2,y2,u2,v2,tmp2; //used to search for missing zeros
Double sum_S=0; //sum of the S(T)'s.
for(i=0;i<=99;i++)
for(j=0;j<=1;j++)
zeros_S[i][j]=0;
zeros_S[0][0]=t1;
if(!strcmp(filename,"cout"))
{
cout << setprecision(DIGITS3);
}
else
{
file.open(filename, ios::out|ios::app);
file << setprecision(DIGITS3);
}
global_average=0;
/*
Complex L_1;
x=.1;i=0;
do{
L_1=this->value(x+I*(t1+.0001));
if(L_1!=0) y=imag(log(L_1));
if(i>0){
tmp2=y-tmp;
if(tmp2>5)tmp2=tmp2-2*Pi;
if(tmp2<-5)tmp2=tmp2+2*Pi;
global_average=global_average+tmp2;
cout << "global average: " <<x<<" "<< y << " " <<tmp << " " <<global_average/(2*Pi) << endl;
}
tmp=y;
x=x+.01;
i++;
}while(x<=.9);
global_average=-global_average/(2*Pi);
cout <<"hihih " << global_average<<endl;
*/
//XXXXXXXXXXXXXXXXXx should I start slightly earlier
t=t1; u=t;
x=real(this->value(.5+I*t,0,"rotated pure"));
if(my_verbose>1)
cout << "look for sign change " << t << " " << x << endl;
Double g=0;
for(i=1;i<=this->a;i++)g=g+gamma[i];
ii=0; //will be used to count zeros in the zeros_S array
do{
//step_size=.5/(this->N(t+2)/2-N(t+1)/2); //i.e. increment by half the average
//the local density
if(count_all<7)
step_size=g*log((this->Q)*abs(t)/(2*Pi)+4)/(2*Pi*40);
else
step_size=g*log((this->Q)*abs(t)/(2*Pi)+4)/(2*Pi*2);
//i.e. increment by half the average
//XXXXXX I need to take degree into account for the t aspect,
//i.e. the sum of the gammas.
t=t+step_size;
y=real(this->value(.5+I*t,0,"rotated pure"));
if(my_verbose>1)
cout << "look for sign change " << t << " " << y << endl;
v=t;
if(sn(x)!=sn(y)) //if sign change is found...divide and conquer
//until the difference is small.
{
tmp=zeros_zoom_brent(x,y,u,v);
//cout << "catching zero: " << tmp << endl;
count_all++; ii++;
zeros_S[ii][0]=tmp;
//XXXX should not be discontinous
if(t1>0)
zeros_S[ii][1]=this->N((tmp+previous_zero)/2)/2 -N(t1)/2-(count_all-1);
else
zeros_S[ii][1]=this->N((tmp+previous_zero)/2)/2 -(count_all-1);
//zeros_S[ii][1]=this->N((tmp+previous_zero)/2)/2 -N(t1)/2-(count_all-1);
//if(ii>=20){
//count the number of big S(T)'s. If small then print the first
//10 zeros (but not more than count in total).
//Otherwise go back to look for missing zeros
//searching with step sizes which are half as big. look for
//a few consecutive blocks where S(T) is large, and look for missing
//zeros in a neighborhood of the transition. If none are found
//halve the step size and search again. Do this a few times. If still
//missing then search all i blocks with very small steps.
//If still not found then print a message and keep going.
//average_S=0;
//for(i=1;i<=ii;i++) average_S=average_S+zeros_S[i][1]/ii;
if(ii==7) for(i=ii;i>=ii-6;i--) global_average=global_average+zeros_S[i][1]/7;
if(ii>6){
local_average=0;
for(i=ii;i>=ii-6;i--) local_average=local_average+zeros_S[i][1]/7;
if(local_average-global_average>.7) to_find=1;
if(local_average-global_average>1.5) to_find=Int(local_average-global_average+.5);
if(to_find>0){
//cout << "will try to find " << to_find << " zeros" << endl;
//cout <<"local vs global "<< local_average << " " << global_average << endl;
refined_step_size=step_size/2;
i1=ii-7; i2=i1;
//for(i=1;i<=ii;i++) cout << "missing zeros detected: " << zeros_S[i][0] << " " << zeros_S[i][1]<< endl;
found_missing=0;
do{
if(i2>ii-1+found_missing)i2=ii-1+found_missing;
if(i1<1&&count2>0)i1=1; if(i1<1&&count2==0)i1=0;
for(i=i1;i<=i2;i++){
//search for missing zeros in block i with refined_step_size
//each time a zero is found update all relevant info
//cout << "searching block " << i << " stepsize " << refined_step_size << endl;
u2=zeros_S[i][0]+refined_step_size/2;
x2=real(this->value(.5+I*u2,0,"rotated pure"));
do{
v2=u2+refined_step_size;
//cout <<"u2 v2: " << u2 << " " <<v2 << endl;
if(v2<zeros_S[i+1][0])
{
y2=real(this->value(.5+I*v2,0,"rotated pure"));
if(sn(x2)!=sn(y2)) //if sign change is found...divide and conquer
//until the difference is small.
{
//cout <<"zoom in on: " << u2 << " " <<v2 << endl;
tmp2=zeros_zoom_brent(x2,y2,u2,v2);
//cout << " catching missing zero: " << tmp2 << endl;
found_missing++;i2=i2+1;
//cout << "found a missing zero: " << tmp2 << " "<<endl;
count_all++;
for(j=ii+found_missing;j>=i+2;j--){
zeros_S[j][0]=zeros_S[j-1][0];
zeros_S[j][1]=zeros_S[j-1][1]-1;
}
zeros_S[i+1][0]=tmp2;
zeros_S[i+1][1]=zeros_S[i+2][1]-1; //not strictly correct, but close enough
i=i-2;if(i<1)i=1;
//cout << "well blow my lips off: "<< zeros_S[i+1][0] << " " << zeros_S[i+1][1]<<endl;
//cout << "well blow my lips off: "<< zeros_S[i+2][0] << " " << zeros_S[i+1][1]<<endl;
}
x2=y2;u2=v2;
}
}while(v2<zeros_S[i+1][0]);
}
refined_step_size=refined_step_size/2;
i2=i2+2;i1=i1-2;
if(refined_step_size/step_size< .1){i2=i2+1;i1=i1-8;}
}while(found_missing<to_find && refined_step_size > step_size/max_refine);
to_find=0;
if(refined_step_size <= step_size/max_refine){
if(!strcmp(filename,"cout"))
{
cout<<"missing zeros detected." << endl;
cout<<"failed to find using refined step sizes of " << refined_step_size << endl;
for(i=1;i<=ii+found_missing;i++)
cout << zeros_S[i][0] << " " << zeros_S[i][1]<< endl;
}
else{
file<<"missing zeros detected." << endl;
file<<"failed to find using refined step sizes of " << refined_step_size << endl;
for(i=1;i<=ii+found_missing;i++)
file << zeros_S[i][0] << " " << zeros_S[i][1]<< endl;
}
file.close();
exit(1);
}
}
}
ii=ii+found_missing; found_missing=0;
number_big_S=0;
for(i=1;i<=ii;i++) if(zeros_S[i][1]>.9+global_average)number_big_S=number_big_S+1;
if(number_big_S>17) //i.e. if missing zero detected
{
//cout << "missing zero detected" << endl;
//for(i=1;i<=ii;i++)
//cout << i << " : " <<zeros_S[i][0] << " " << zeros_S[i][1]<< endl;
refined_step_size=step_size/2;
i=ii;
//find transition zone
do{
i--;
}while(zeros_S[i][1]>1&&i>=1);
i1=i; i2=i;
found_missing=0;
do{
if(i2>ii-1+found_missing)i2=ii-1+found_missing;
if(i1<1&&count2>0)i1=1; if(i1<1&&count2==0)i1=0;
for(i=i1;i<=i2;i++){
//search for missing zeros in block i with refined_step_size
//each time a zero is found update all relevant info
//cout << "searching block " << i << " stepsize " << refined_step_size << endl;
u2=zeros_S[i][0]+refined_step_size/2;
x2=real(this->value(.5+I*u2,0,"rotated pure"));
do{
v2=u2+refined_step_size;
//cout <<"u2 v2: " << u2 << " " <<v2 << endl;
if(v2<zeros_S[i+1][0])
{
y2=real(this->value(.5+I*v2,0,"rotated pure"));
if(sn(x2)!=sn(y2)) //if sign change is found...divide and conquer
//until the difference is small.
{
//cout <<"zoom in on: " << u2 << " " <<v2 << endl;
tmp2=zeros_zoom_brent(x2,y2,u2,v2);
//cout << " catching missing zero: " << tmp2 << endl;
found_missing++;i2=i2+1;
//cout << "found a missing zero: " << tmp2 << " "<<endl;
count_all++;
for(j=ii+found_missing;j>=i+2;j--){
zeros_S[j][0]=zeros_S[j-1][0];
zeros_S[j][1]=zeros_S[j-1][1]-1;
}
zeros_S[i+1][0]=tmp2;
zeros_S[i+1][1]=zeros_S[i+2][1]-1; //not strictly correct, but close enough
i=i-2;if(i<1)i=1;
//cout << "well blow my lips off: "<< zeros_S[i+1][0] << " " << zeros_S[i+1][1]<<endl;
//cout << "well blow my lips off: "<< zeros_S[i+2][0] << " " << zeros_S[i+1][1]<<endl;
}
x2=y2;u2=v2;
}
}while(v2<zeros_S[i+1][0]);
}
//average_S=0;
//for(i=1;i<=ii+found_missing;i++) average_S=average_S+zeros_S[i][1]/ii;
number_big_S=0;
for(i=1;i<=ii+found_missing;i++) if(zeros_S[i][1]>.9+global_average)number_big_S=number_big_S+1;
refined_step_size=refined_step_size/2;
i2=i2+2;i1=i1-3;
if(refined_step_size/step_size< .24){i2=i2+1;i1=i1-8;}
}while(number_big_S>17 && refined_step_size > step_size/max_refine);
if(refined_step_size <= step_size/max_refine){
if(!strcmp(filename,"cout"))
{
cout<<"missing zeros detected." << endl;
cout<<"failed to find using refined step sizes of " << refined_step_size << endl;
for(i=1;i<=ii+found_missing;i++)
cout << zeros_S[i][0] << " " << zeros_S[i][1]<< endl;
}
else{
file<<"missing zeros detected." << endl;
file<<"failed to find using refined step sizes of " << refined_step_size << endl;
for(i=1;i<=ii+found_missing;i++)
file << zeros_S[i][0] << " " << zeros_S[i][1]<< endl;
}
file.close();
exit(1);
}
}
//dump up to 10 zeros
ii=ii+found_missing; found_missing=0;
if(ii>=50){
i=1;
do{
if(!strcmp(filename,"cout"))
{
sum_S=sum_S+zeros_S[i][1];
cout << message_stamp << " ";
cout << setprecision(DIGITS3);
cout << zeros_S[i][0] << " ";
cout << setprecision(4) << zeros_S[i][1]<<" " << sum_S/(count2+1.)<< " "<<global_average<<" ";
cout << real(this->value(.5+I*zeros_S[i][0],0,"rotated pure")) << endl;
//cout << zeros_S[i][0] << endl;
}
else
{
file << message_stamp << " ";
//file << zeros_S[i][0] << " " << zeros_S[i][1]<< endl;
file << zeros_S[i][0] << endl;
}
i++; count2++;
}while(i<=10&&count2<count);
for(i=11;i<=ii;i++){
zeros_S[i-10][0]=zeros_S[i][0];
zeros_S[i-10][1]=zeros_S[i][1];
//cout << "buffered: " <<zeros_S[i-10][0] << " " << zeros_S[i-10][1]<< endl;
}
if(!strcmp(filename,"cout")) cout << setprecision(DIGITS3);
else file << setprecision(DIGITS3);
ii=ii-10;
}
//}
previous_zero=tmp;
}
u=t;
x=y;
}while(count2<count);
if(strcmp(filename,"cout")) file.close();
}
|