# OK to post homework # Lucy Martinez, 03-13-22, Assignment 15 read `C15.txt`: with(combinat): #----------------------Problem 1-----------------------# # Write a procedure DecDigits(a,K) that inputs a number a and outputs the LIST of its first K digits. # For example, DecDigits(Pi,6); should be [3,1,4,1,5,9] DecDigits:=proc(a,K) local L,N,S,i : L:=[]: N:=evalf(a,K): S:=convert(N,string): for i from 1 to length(S) do if S[i]<>"." then L:=[op(L),seq(parse(S[i]))]; fi: od: L: end: DecDigits(Pi,6); # [3, 1, 4, 1, 5, 9] #----------------------Problem 2-----------------------# # Read the excellent article by the late (amazing) Borwein brothers (Jonathan and Peter) and the equally amazing # Carl Dilcher (may he live a long life), and after settings Digits to at least 1000, # check out this phenomena by using the abobe procedure DecDigits to write a procedure # WrongDigits(a,b,K) # that inputs two numbers a and b and a positive integer K and outputs the list of places where their decimal # digits differ. Try: Digits:=1000: WrongDigits(Pi,NorthM(500000)): # [If it does not take too long, try: Digits:=1000: WrongDigits(Pi,NorthM(5000000)): ] # Is that sequence in the OEIS. WrongDigits:=proc(a,b,K) local A, B, L, i: A:=DecDigits(a,K): B:=DecDigits(b,K): L:=[]: # this will check at which spot they are different and will return that position for i from 1 to nops(A) do if A[i]<>B[i] then L:=[op(L),i]: fi: od: L: end: Digits:=1000: DecDigits(Pi,10); # [3, 1, 4, 1, 5, 9, 2, 6, 5, 4] DecDigits(NorthM(500000),10); # [3, 1, 4, 1, 5, 9, 0, 6, 5, 4] WrongDigits(Pi,NorthM(500000),10); # the following tells us that the place that Pi and NorthM(500000) differ is at the 7th digit # [7] Digits:=1000: WrongDigits(Pi,NorthM(5000000),1000); # [ 8, 22, 35, 48, 49, 50, 61, 62, 63, 73, 75, 77, 78, 85, 86, 87, 89, 90, 91, 98, 100, 101, # 102, 103, 105, 106, 110, 111, 112, 113, 114, 116, 117, 118, 119, 122, 123, 124, 126, 127, # 128, 129, 130, 131, 132, 133, 134, 135, 136, 137, 138, 139, 140, 141, 142, 143, 144, 145, # 146, 147, 148, 150, 151, 152, 153, 154, 155, 156, 158, 159, 160, 161, 162, 163, 164, 165, # 166, 167, 168, 169, 170, 171, 172, 173, 174, 175, 177, 178, 179, 180, 181, 182, 184, 185, # 186, 187, 188, 190, 192, 193, 194, 195, 196, 197, 198, 200, 201, 202, 203, 204, 206, 207, # 208, 209, 210, 211, 212, 213, 215, 218, 219, 220, 221, 222, 223, 224, 225, 227, 228, 229, # 230, 231, 232, 233, 234, 235, 236, 237, 238, 239, 240, 241, 242, 244, 245, 247, 248, 249, # 250, 251, 252, 253, 254, 255, 256, 257, 258, 259, 260, 261, 263, 264, 265, 266, 267, 268, # 270, 272, 273, 274, 275, 276, 277, 278, 279, 280, 282, 283, 285, 286, 287, 288, 289, 290, # 291, 292, 293, 294, 295, 296, 297, 298, 299, 300, 301, 302, 303, 304, 305, 306, 307, 308, # 310, 311, 312, 313, 314, 315, 316, 318, 319, 320, 321, 323, 324, 325, 326, 327, 328, 329, # 330, 333, 334, 335, 336, 337, 338, 339, 340, 341, 342, 343, 344, 347, 348, 349, 350, 352, # 353, 354, 355, 357, 358, 359, 360, 361, 362, 363, 364, 365, 366, 367, 368, 369, 370, 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, 398, 399, 400, 401, 402, 403, 405, 406, 408, 409, 410, 411, # 412, 413, 414, 415, 416, 417, 418, 419, 420, 421, 422, 423, 424, 425, 426, 428, 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, 475, 476, 477, 478, 479, 480, 481, 483, 484, 485, 486, 487, # 488, 489, 490, 491, 492, 493, 494, 495, 496, 498, 499, 500, 501, 502, 503, 504, 505, 506, # 511, 512, 513, 514, 517, 518, 519, 520, 521, 522, 523, 524, 525, 527, 528, 530, 531, 532, # 533, 534, 535, 536, 537, 538, 539, 540, 541, 542, 543, 544, 545, 546, 548, 549, 550, 552, # 553, 554, 555, 558, 559, 560, 561, 562, 563, 564, 565, 567, 568, 569, 570, 571, 572, 573, # 574, 576, 577, 578, 579, 580, 581, 582, 583, 585, 586, 587, 588, 589, 591, 592, 593, 594, # 595, 596, 597, 599, 600, 601, 602, 603, 604, 605, 606, 607, 608, 609, 610, 611, 612, 613, # 614, 616, 617, 618, 619, 620, 621, 622, 623, 625, 626, 627, 628, 629, 630, 631, 632, 633, # 634, 635, 636, 637, 638, 639, 640, 641, 642, 643, 644, 645, 647, 648, 649, 650, 651, 652, # 653, 654, 655, 656, 658, 659, 660, 661, 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, 729, 730, 731, 732, 733, 734, 735, 736, 737, 738, 739, 740, 741, 742, 743, 744, 745, # 747, 748, 749, 750, 751, 752, 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, 789, 790, 791, 793, 794, 795, 796, 797, 799, 800, 801, 802, 803, 804, # 805, 808, 809, 810, 811, 812, 813, 814, 815, 817, 818, 821, 822, 823, 824, 825, 826, 828, # 829, 830, 831, 833, 835, 837, 838, 839, 840, 841, 842, 843, 844, 845, 846, 847, 848, 849, # 850, 851, 852, 853, 854, 855, 856, 857, 859, 860, 861, 862, 864, 865, 866, 867, 868, 869, # 870, 871, 872, 873, 874, 876, 877, 878, 879, 880, 881, 882, 883, 884, 886, 889, 890, 891, # 893, 894, 896, 897, 898, 899, 900, 901, 902, 903, 904, 905, 906, 909, 911, 912, 913, 914, # 915, 916, 917, 918, 919, 921, 922, 923, 924, 925, 926, 927, 928, 929, 930, 931, 932, 933, # 934, 935, 936, 937, 938, 939, 940, 941, 942, 943, 945, 946, 948, 949, 950, 951, 952, 953, # 955, 956, 957, 958, 959, 960, 961, 962, 963, 965, 966, 967, 968, 969, 970, 971, 972, 974, # 975, 976, 977, 978, 979, 980, 982, 983, 984, 985, 986, 987, 990, 991, 992, 994, 995, 996, # 997, 998, 1000] #----------------------Problem 6-----------------------# # After class I added the procedures Ac(n) and PiApc(n). These use the third-order recurrence gotten by the # amazing Almkvist-Zeilberger algorithm by using the Maple command "time" # Show why, starting at a certain n, PiApc(n) is so much faster than PiAp(n). # For what values of n does PiApc(n) returns something in less than 5 seconds, while PiAp(n) is hopeless? TestTime:=proc(n) local i: for i from 1 to n do print([PiApc(i),time(PiApc(i)),PiAp(i),time(PiAp(i))]): od: end: TestTime(60); # After running this up to n=60, PiApc(n) returned something in less than 1 second while # PiAp(n) took at most 0.20 seconds #----------------------Problem 7-----------------------# # Write a procedure Jesus(n) that finds the sum of the first n terms of Jesus Guillera's beautiful series # for 128/À^2 given in his homepage (in a Ramanujan-style notation, that must be deciphered). # What is the error in Jesus(20)? Jesus:=proc(n) local i: sum( ((-1)^i) *(binomial(2*i,i)^5)*( (820*i^2+180*i+13)/2^(20*i) ) , i=0..n): end: Jesus(20); # 32704576763505998389796698872333005333688220666208571694818138548698110756336321727212652194641543631851472552368735625/2521728396569246669585858566409191283525103313309788586748690777871726193375821479130513040312634601011624191379636224 # The following is the error for Jesus(20) # (128/Pi^2)-evalf(Jesus(20)) = -1.*10^(-8)