Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupport News Sign UpSign In
| Download
Project: numeros
Views: 53
2^123+1
10633823966279326983230456482242756609
a=2^123+1 factor(a)
3^2 * 83 * 739 * 165313 * 8831418697 * 13194317913029593
gcd(2016,1952)
32
def fi(num): tito=0 #contador rosita=[] for ii in range(num): if gcd(ii,num)==1: tito=tito+1 rosita.append(ii) return tito
fi(65)
48
5//6
0
26//3
8
26%3
2
float(26/3)
8.666666666666666
26/2==13/1
True
q=25/3 type(q)
<type 'sage.rings.rational.Rational'>
def mcd(aa,bb): while bb>0: rr=aa%bb aa=bb bb=rr print aa, bb return aa
mcd(32,18)
18 14 14 4 4 2 2 0 2
mcd(32,18)
18 14 14 4 4 2 2 0 2
mcd(18, 32)
32 18 18 14 14 4 4 2 2 0 2
mcd(1952,3)
3 2 2 1 1 0 1
mcd(fibonacci(7),fibonacci(8))
21 13 13 8 8 5 5 3 3 2 2 1 1 0 1
mcd(1952,2016)
2016 1952 1952 64 64 32 32 0 32
n=74037563479561712828046796097429573142593188889231289084936232 63897276503402826627689199641962511784399589433050212758537011 89680982867331732731089309005525051168770632990723963807867100 86096962537934650563796359
63897276503402826627689199641962511784399589433050212758537011 89680982867331732731089309005525051168770632990723963807867100 86096962537934650563796359
n.str(2)
'10111000010010110111010100011000001001011000100001111110000010110001111111101110101100011111001100110011000011000101001011010011000010101111101110101011001111010101111010011011011001001000100000000000101000'
len(n.str(2))
206
p = 2^32582657 - 1
p.ndigits()
9808358
plot(prime_pi, 1,1000, rgbcolor=(0,0,1))
T=Integers(21)
list(T)
[0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20]
euler_phi(1952)==fi(1952)
True
euler_phi(1952)
960
fi(1952)
960 [1, 3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23, 25, 27, 29, 31, 33, 35, 37, 39, 41, 43, 45, 47, 49, 51, 53, 55, 57, 59, 63, 65, 67, 69, 71, 73, 75, 77, 79, 81, 83, 85, 87, 89, 91, 93, 95, 97, 99, 101, 103, 105, 107, 109, 111, 113, 115, 117, 119, 121, 123, 125, 127, 129, 131, 133, 135, 137, 139, 141, 143, 145, 147, 149, 151, 153, 155, 157, 159, 161, 163, 165, 167, 169, 171, 173, 175, 177, 179, 181, 185, 187, 189, 191, 193, 195, 197, 199, 201, 203, 205, 207, 209, 211, 213, 215, 217, 219, 221, 223, 225, 227, 229, 231, 233, 235, 237, 239, 241, 243, 245, 247, 249, 251, 253, 255, 257, 259, 261, 263, 265, 267, 269, 271, 273, 275, 277, 279, 281, 283, 285, 287, 289, 291, 293, 295, 297, 299, 301, 303, 307, 309, 311, 313, 315, 317, 319, 321, 323, 325, 327, 329, 331, 333, 335, 337, 339, 341, 343, 345, 347, 349, 351, 353, 355, 357, 359, 361, 363, 365, 367, 369, 371, 373, 375, 377, 379, 381, 383, 385, 387, 389, 391, 393, 395, 397, 399, 401, 403, 405, 407, 409, 411, 413, 415, 417, 419, 421, 423, 425, 429, 431, 433, 435, 437, 439, 441, 443, 445, 447, 449, 451, 453, 455, 457, 459, 461, 463, 465, 467, 469, 471, 473, 475, 477, 479, 481, 483, 485, 487, 489, 491, 493, 495, 497, 499, 501, 503, 505, 507, 509, 511, 513, 515, 517, 519, 521, 523, 525, 527, 529, 531, 533, 535, 537, 539, 541, 543, 545, 547, 551, 553, 555, 557, 559, 561, 563, 565, 567, 569, 571, 573, 575, 577, 579, 581, 583, 585, 587, 589, 591, 593, 595, 597, 599, 601, 603, 605, 607, 609, 611, 613, 615, 617, 619, 621, 623, 625, 627, 629, 631, 633, 635, 637, 639, 641, 643, 645, 647, 649, 651, 653, 655, 657, 659, 661, 663, 665, 667, 669, 673, 675, 677, 679, 681, 683, 685, 687, 689, 691, 693, 695, 697, 699, 701, 703, 705, 707, 709, 711, 713, 715, 717, 719, 721, 723, 725, 727, 729, 731, 733, 735, 737, 739, 741, 743, 745, 747, 749, 751, 753, 755, 757, 759, 761, 763, 765, 767, 769, 771, 773, 775, 777, 779, 781, 783, 785, 787, 789, 791, 795, 797, 799, 801, 803, 805, 807, 809, 811, 813, 815, 817, 819, 821, 823, 825, 827, 829, 831, 833, 835, 837, 839, 841, 843, 845, 847, 849, 851, 853, 855, 857, 859, 861, 863, 865, 867, 869, 871, 873, 875, 877, 879, 881, 883, 885, 887, 889, 891, 893, 895, 897, 899, 901, 903, 905, 907, 909, 911, 913, 917, 919, 921, 923, 925, 927, 929, 931, 933, 935, 937, 939, 941, 943, 945, 947, 949, 951, 953, 955, 957, 959, 961, 963, 965, 967, 969, 971, 973, 975, 977, 979, 981, 983, 985, 987, 989, 991, 993, 995, 997, 999, 1001, 1003, 1005, 1007, 1009, 1011, 1013, 1015, 1017, 1019, 1021, 1023, 1025, 1027, 1029, 1031, 1033, 1035, 1039, 1041, 1043, 1045, 1047, 1049, 1051, 1053, 1055, 1057, 1059, 1061, 1063, 1065, 1067, 1069, 1071, 1073, 1075, 1077, 1079, 1081, 1083, 1085, 1087, 1089, 1091, 1093, 1095, 1097, 1099, 1101, 1103, 1105, 1107, 1109, 1111, 1113, 1115, 1117, 1119, 1121, 1123, 1125, 1127, 1129, 1131, 1133, 1135, 1137, 1139, 1141, 1143, 1145, 1147, 1149, 1151, 1153, 1155, 1157, 1161, 1163, 1165, 1167, 1169, 1171, 1173, 1175, 1177, 1179, 1181, 1183, 1185, 1187, 1189, 1191, 1193, 1195, 1197, 1199, 1201, 1203, 1205, 1207, 1209, 1211, 1213, 1215, 1217, 1219, 1221, 1223, 1225, 1227, 1229, 1231, 1233, 1235, 1237, 1239, 1241, 1243, 1245, 1247, 1249, 1251, 1253, 1255, 1257, 1259, 1261, 1263, 1265, 1267, 1269, 1271, 1273, 1275, 1277, 1279, 1283, 1285, 1287, 1289, 1291, 1293, 1295, 1297, 1299, 1301, 1303, 1305, 1307, 1309, 1311, 1313, 1315, 1317, 1319, 1321, 1323, 1325, 1327, 1329, 1331, 1333, 1335, 1337, 1339, 1341, 1343, 1345, 1347, 1349, 1351, 1353, 1355, 1357, 1359, 1361, 1363, 1365, 1367, 1369, 1371, 1373, 1375, 1377, 1379, 1381, 1383, 1385, 1387, 1389, 1391, 1393, 1395, 1397, 1399, 1401, 1405, 1407, 1409, 1411, 1413, 1415, 1417, 1419, 1421, 1423, 1425, 1427, 1429, 1431, 1433, 1435, 1437, 1439, 1441, 1443, 1445, 1447, 1449, 1451, 1453, 1455, 1457, 1459, 1461, 1463, 1465, 1467, 1469, 1471, 1473, 1475, 1477, 1479, 1481, 1483, 1485, 1487, 1489, 1491, 1493, 1495, 1497, 1499, 1501, 1503, 1505, 1507, 1509, 1511, 1513, 1515, 1517, 1519, 1521, 1523, 1527, 1529, 1531, 1533, 1535, 1537, 1539, 1541, 1543, 1545, 1547, 1549, 1551, 1553, 1555, 1557, 1559, 1561, 1563, 1565, 1567, 1569, 1571, 1573, 1575, 1577, 1579, 1581, 1583, 1585, 1587, 1589, 1591, 1593, 1595, 1597, 1599, 1601, 1603, 1605, 1607, 1609, 1611, 1613, 1615, 1617, 1619, 1621, 1623, 1625, 1627, 1629, 1631, 1633, 1635, 1637, 1639, 1641, 1643, 1645, 1649, 1651, 1653, 1655, 1657, 1659, 1661, 1663, 1665, 1667, 1669, 1671, 1673, 1675, 1677, 1679, 1681, 1683, 1685, 1687, 1689, 1691, 1693, 1695, 1697, 1699, 1701, 1703, 1705, 1707, 1709, 1711, 1713, 1715, 1717, 1719, 1721, 1723, 1725, 1727, 1729, 1731, 1733, 1735, 1737, 1739, 1741, 1743, 1745, 1747, 1749, 1751, 1753, 1755, 1757, 1759, 1761, 1763, 1765, 1767, 1771, 1773, 1775, 1777, 1779, 1781, 1783, 1785, 1787, 1789, 1791, 1793, 1795, 1797, 1799, 1801, 1803, 1805, 1807, 1809, 1811, 1813, 1815, 1817, 1819, 1821, 1823, 1825, 1827, 1829, 1831, 1833, 1835, 1837, 1839, 1841, 1843, 1845, 1847, 1849, 1851, 1853, 1855, 1857, 1859, 1861, 1863, 1865, 1867, 1869, 1871, 1873, 1875, 1877, 1879, 1881, 1883, 1885, 1887, 1889, 1893, 1895, 1897, 1899, 1901, 1903, 1905, 1907, 1909, 1911, 1913, 1915, 1917, 1919, 1921, 1923, 1925, 1927, 1929, 1931, 1933, 1935, 1937, 1939, 1941, 1943, 1945, 1947, 1949, 1951]
Error in lines 1-1 Traceback (most recent call last): File "/projects/sage/sage-6.10/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 947, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> TypeError: 'NoneType' object has no attribute '__getitem__'
a=625 type(a)
<type 'sage.rings.integer.Integer'>
a.abs()
625
def mcd(a,b): if a==b: return a if a<b: return mcd(b,a) if a>b: return mcd(a-b,b)
mcd(18,19)
1
def MCD(a,b,alfa,beta,delta,gama): print a,b,alfa,beta,delta,gama if a==b: return [a,alfa,beta] if a<b: return MCD(b,a,delta,gama,alfa,beta) if a>b: return MCD(a-b,b,alfa-delta,beta-gama,delta,gama)
MCD(18,15,1,0,0,1)
18 15 1 0 0 1 3 15 1 -1 0 1 15 3 0 1 1 -1 12 3 -1 2 1 -1 9 3 -2 3 1 -1 6 3 -3 4 1 -1 3 3 -4 5 1 -1 [3, -4, 5]
MCD(21,34,1,0,0,1)
21 34 1 0 1 0 34 21 0 1 0 1 13 21 0 0 0 1 21 13 1 0 0 0 8 13 1 0 0 0 13 8 0 0 0 1 5 8 0 -1 0 1 8 5 1 0 -1 0 3 5 2 0 -1 0 5 3 0 -1 0 2 2 3 0 -3 0 2 3 2 2 0 -3 0 1 2 5 0 -3 0 2 1 0 -3 0 5 1 1 0 -8 0 5 1
MCD(34,21,0,1,0,1)
34 21 0 1 1 0 13 21 -1 1 1 0 21 13 0 1 1 -1 8 13 -1 2 1 -1 13 8 -1 1 2 -1 5 8 -3 2 2 -1 8 5 -1 2 2 -3 3 5 -3 5 2 -3 5 3 -3 2 5 -3 2 3 -8 5 5 -3 3 2 -3 5 5 -8 1 2 -8 13 5 -8 2 1 -8 5 13 -8 1 1 -21 13 13 -8 1
MCD(34,21,1,0,0,1)
[1, -8, 0]
def smcd(a,b): return MCD(a,b,1,0,0,1)
smcd(25,15)
25 15 1 0 0 1 10 15 1 -1 0 1 15 10 0 1 1 -1 5 10 -1 2 1 -1 10 5 1 -1 -1 2 5 5 2 -3 -1 2 [5, 2, -3]
25.gcd(18)
1
A=Set([i for i in range(-18,18)]) B=Set([i for i in range(-25,25)]) tu=[ 18*x+35*y for (x,y) in A.cartesian_product(B)]
print tu
[0, 35, 70, 105, 140, 175, 210, 245, 280, 315, 350, 385, 420, 455, 490, 525, 560, 595, 630, 665, 700, 735, 770, 805, 840, -70, -875, -840, -805, -770, -735, -700, -665, -630, -595, -560, -525, -490, -455, -420, -385, -350, -315, -280, -245, -210, -175, -140, -105, -35, 18, 53, 88, 123, 158, 193, 228, 263, 298, 333, 368, 403, 438, 473, 508, 543, 578, 613, 648, 683, 718, 753, 788, 823, 858, -52, -857, -822, -787, -752, -717, -682, -647, -612, -577, -542, -507, -472, -437, -402, -367, -332, -297, -262, -227, -192, -157, -122, -87, -17, 36, 71, 106, 141, 176, 211, 246, 281, 316, 351, 386, 421, 456, 491, 526, 561, 596, 631, 666, 701, 736, 771, 806, 841, 876, -34, -839, -804, -769, -734, -699, -664, -629, -594, -559, -524, -489, -454, -419, -384, -349, -314, -279, -244, -209, -174, -139, -104, -69, 1, 54, 89, 124, 159, 194, 229, 264, 299, 334, 369, 404, 439, 474, 509, 544, 579, 614, 649, 684, 719, 754, 789, 824, 859, 894, -16, -821, -786, -751, -716, -681, -646, -611, -576, -541, -506, -471, -436, -401, -366, -331, -296, -261, -226, -191, -156, -121, -86, -51, 19, 72, 107, 142, 177, 212, 247, 282, 317, 352, 387, 422, 457, 492, 527, 562, 597, 632, 667, 702, 737, 772, 807, 842, 877, 912, 2, -803, -768, -733, -698, -663, -628, -593, -558, -523, -488, -453, -418, -383, -348, -313, -278, -243, -208, -173, -138, -103, -68, -33, 37, 90, 125, 160, 195, 230, 265, 300, 335, 370, 405, 440, 475, 510, 545, 580, 615, 650, 685, 720, 755, 790, 825, 860, 895, 930, 20, -785, -750, -715, -680, -645, -610, -575, -540, -505, -470, -435, -400, -365, -330, -295, -260, -225, -190, -155, -120, -85, -50, -15, 55, 108, 143, 178, 213, 248, 283, 318, 353, 388, 423, 458, 493, 528, 563, 598, 633, 668, 703, 738, 773, 808, 843, 878, 913, 948, 38, -767, -732, -697, -662, -627, -592, -557, -522, -487, -452, -417, -382, -347, -312, -277, -242, -207, -172, -137, -102, -67, -32, 3, 73, 126, 161, 196, 231, 266, 301, 336, 371, 406, 441, 476, 511, 546, 581, 616, 651, 686, 721, 756, 791, 826, 861, 896, 931, 966, 56, -749, -714, -679, -644, -609, -574, -539, -504, -469, -434, -399, -364, -329, -294, -259, -224, -189, -154, -119, -84, -49, -14, 21, 91, 144, 179, 214, 249, 284, 319, 354, 389, 424, 459, 494, 529, 564, 599, 634, 669, 704, 739, 774, 809, 844, 879, 914, 949, 984, 74, -731, -696, -661, -626, -591, -556, -521, -486, -451, -416, -381, -346, -311, -276, -241, -206, -171, -136, -101, -66, -31, 4, 39, 109, 162, 197, 232, 267, 302, 337, 372, 407, 442, 477, 512, 547, 582, 617, 652, 687, 722, 757, 792, 827, 862, 897, 932, 967, 1002, 92, -713, -678, -643, -608, -573, -538, -503, -468, -433, -398, -363, -328, -293, -258, -223, -188, -153, -118, -83, -48, -13, 22, 57, 127, 180, 215, 250, 285, 320, 355, 390, 425, 460, 495, 530, 565, 600, 635, 670, 705, 740, 775, 810, 845, 880, 915, 950, 985, 1020, 110, -695, -660, -625, -590, -555, -520, -485, -450, -415, -380, -345, -310, -275, -240, -205, -170, -135, -100, -65, -30, 5, 40, 75, 145, 198, 233, 268, 303, 338, 373, 408, 443, 478, 513, 548, 583, 618, 653, 688, 723, 758, 793, 828, 863, 898, 933, 968, 1003, 1038, 128, -677, -642, -607, -572, -537, -502, -467, -432, -397, -362, -327, -292, -257, -222, -187, -152, -117, -82, -47, -12, 23, 58, 93, 163, 216, 251, 286, 321, 356, 391, 426, 461, 496, 531, 566, 601, 636, 671, 706, 741, 776, 811, 846, 881, 916, 951, 986, 1021, 1056, 146, -659, -624, -589, -554, -519, -484, -449, -414, -379, -344, -309, -274, -239, -204, -169, -134, -99, -64, -29, 6, 41, 76, 111, 181, 234, 269, 304, 339, 374, 409, 444, 479, 514, 549, 584, 619, 654, 689, 724, 759, 794, 829, 864, 899, 934, 969, 1004, 1039, 1074, 164, -641, -606, -571, -536, -501, -466, -431, -396, -361, -326, -291, -256, -221, -186, -151, -116, -81, -46, -11, 24, 59, 94, 129, 199, 252, 287, 322, 357, 392, 427, 462, 497, 532, 567, 602, 637, 672, 707, 742, 777, 812, 847, 882, 917, 952, 987, 1022, 1057, 1092, 182, -623, -588, -553, -518, -483, -448, -413, -378, -343, -308, -273, -238, -203, -168, -133, -98, -63, -28, 7, 42, 77, 112, 147, 217, 270, 305, 340, 375, 410, 445, 480, 515, 550, 585, 620, 655, 690, 725, 760, 795, 830, 865, 900, 935, 970, 1005, 1040, 1075, 1110, 200, -605, -570, -535, -500, -465, -430, -395, -360, -325, -290, -255, -220, -185, -150, -115, -80, -45, -10, 25, 60, 95, 130, 165, 235, 288, 323, 358, 393, 428, 463, 498, 533, 568, 603, 638, 673, 708, 743, 778, 813, 848, 883, 918, 953, 988, 1023, 1058, 1093, 1128, 218, -587, -552, -517, -482, -447, -412, -377, -342, -307, -272, -237, -202, -167, -132, -97, -62, -27, 8, 43, 78, 113, 148, 183, 253, 306, 341, 376, 411, 446, 481, 516, 551, 586, 621, 656, 691, 726, 761, 796, 831, 866, 901, 936, 971, 1006, 1041, 1076, 1111, 1146, 236, -569, -534, -499, -464, -429, -394, -359, -324, -289, -254, -219, -184, -149, -114, -79, -44, -9, 26, 61, 96, 131, 166, 201, 271, -18, 17, 52, 87, 122, 157, 192, 227, 262, 297, 332, 367, 402, 437, 472, 507, 542, 577, 612, 647, 682, 717, 752, 787, 822, -88, -893, -858, -823, -788, -753, -718, -683, -648, -613, -578, -543, -508, -473, -438, -403, -368, -333, -298, -263, -228, -193, -158, -123, -53, -324, -289, -254, -219, -184, -149, -114, -79, -44, -9, 26, 61, 96, 131, 166, 201, 236, 271, 306, 341, 376, 411, 446, 481, 516, -394, -1199, -1164, -1129, -1094, -1059, -1024, -989, -954, -919, -884, -849, -814, -779, -744, -709, -674, -639, -604, -569, -534, -499, -464, -429, -359, -306, -271, -236, -201, -166, -131, -96, -61, -26, 9, 44, 79, 114, 149, 184, 219, 254, 289, 324, 359, 394, 429, 464, 499, 534, -376, -1181, -1146, -1111, -1076, -1041, -1006, -971, -936, -901, -866, -831, -796, -761, -726, -691, -656, -621, -586, -551, -516, -481, -446, -411, -341, -288, -253, -218, -183, -148, -113, -78, -43, -8, 27, 62, 97, 132, 167, 202, 237, 272, 307, 342, 377, 412, 447, 482, 517, 552, -358, -1163, -1128, -1093, -1058, -1023, -988, -953, -918, -883, -848, -813, -778, -743, -708, -673, -638, -603, -568, -533, -498, -463, -428, -393, -323, -270, -235, -200, -165, -130, -95, -60, -25, 10, 45, 80, 115, 150, 185, 220, 255, 290, 325, 360, 395, 430, 465, 500, 535, 570, -340, -1145, -1110, -1075, -1040, -1005, -970, -935, -900, -865, -830, -795, -760, -725, -690, -655, -620, -585, -550, -515, -480, -445, -410, -375, -305, -252, -217, -182, -147, -112, -77, -42, -7, 28, 63, 98, 133, 168, 203, 238, 273, 308, 343, 378, 413, 448, 483, 518, 553, 588, -322, -1127, -1092, -1057, -1022, -987, -952, -917, -882, -847, -812, -777, -742, -707, -672, -637, -602, -567, -532, -497, -462, -427, -392, -357, -287, -234, -199, -164, -129, -94, -59, -24, 11, 46, 81, 116, 151, 186, 221, 256, 291, 326, 361, 396, 431, 466, 501, 536, 571, 606, -304, -1109, -1074, -1039, -1004, -969, -934, -899, -864, -829, -794, -759, -724, -689, -654, -619, -584, -549, -514, -479, -444, -409, -374, -339, -269, -216, -181, -146, -111, -76, -41, -6, 29, 64, 99, 134, 169, 204, 239, 274, 309, 344, 379, 414, 449, 484, 519, 554, 589, 624, -286, -1091, -1056, -1021, -986, -951, -916, -881, -846, -811, -776, -741, -706, -671, -636, -601, -566, -531, -496, -461, -426, -391, -356, -321, -251, -198, -163, -128, -93, -58, -23, 12, 47, 82, 117, 152, 187, 222, 257, 292, 327, 362, 397, 432, 467, 502, 537, 572, 607, 642, -268, -1073, -1038, -1003, -968, -933, -898, -863, -828, -793, -758, -723, -688, -653, -618, -583, -548, -513, -478, -443, -408, -373, -338, -303, -233, -180, -145, -110, -75, -40, -5, 30, 65, 100, 135, 170, 205, 240, 275, 310, 345, 380, 415, 450, 485, 520, 555, 590, 625, 660, -250, -1055, -1020, -985, -950, -915, -880, -845, -810, -775, -740, -705, -670, -635, -600, -565, -530, -495, -460, -425, -390, -355, -320, -285, -215, -162, -127, -92, -57, -22, 13, 48, 83, 118, 153, 188, 223, 258, 293, 328, 363, 398, 433, 468, 503, 538, 573, 608, 643, 678, -232, -1037, -1002, -967, -932, -897, -862, -827, -792, -757, -722, -687, -652, -617, -582, -547, -512, -477, -442, -407, -372, -337, -302, -267, -197, -144, -109, -74, -39, -4, 31, 66, 101, 136, 171, 206, 241, 276, 311, 346, 381, 416, 451, 486, 521, 556, 591, 626, 661, 696, -214, -1019, -984, -949, -914, -879, -844, -809, -774, -739, -704, -669, -634, -599, -564, -529, -494, -459, -424, -389, -354, -319, -284, -249, -179, -126, -91, -56, -21, 14, 49, 84, 119, 154, 189, 224, 259, 294, 329, 364, 399, 434, 469, 504, 539, 574, 609, 644, 679, 714, -196, -1001, -966, -931, -896, -861, -826, -791, -756, -721, -686, -651, -616, -581, -546, -511, -476, -441, -406, -371, -336, -301, -266, -231, -161, -108, -73, -38, -3, 32, 67, 102, 137, 172, 207, 242, 277, 312, 347, 382, 417, 452, 487, 522, 557, 592, 627, 662, 697, 732, -178, -983, -948, -913, -878, -843, -808, -773, -738, -703, -668, -633, -598, -563, -528, -493, -458, -423, -388, -353, -318, -283, -248, -213, -143, -90, -55, -20, 15, 50, 85, 120, 155, 190, 225, 260, 295, 330, 365, 400, 435, 470, 505, 540, 575, 610, 645, 680, 715, 750, -160, -965, -930, -895, -860, -825, -790, -755, -720, -685, -650, -615, -580, -545, -510, -475, -440, -405, -370, -335, -300, -265, -230, -195, -125, -72, -37, -2, 33, 68, 103, 138, 173, 208, 243, 278, 313, 348, 383, 418, 453, 488, 523, 558, 593, 628, 663, 698, 733, 768, -142, -947, -912, -877, -842, -807, -772, -737, -702, -667, -632, -597, -562, -527, -492, -457, -422, -387, -352, -317, -282, -247, -212, -177, -107, -54, -19, 16, 51, 86, 121, 156, 191, 226, 261, 296, 331, 366, 401, 436, 471, 506, 541, 576, 611, 646, 681, 716, 751, 786, -124, -929, -894, -859, -824, -789, -754, -719, -684, -649, -614, -579, -544, -509, -474, -439, -404, -369, -334, -299, -264, -229, -194, -159, -89, -36, -1, 34, 69, 104, 139, 174, 209, 244, 279, 314, 349, 384, 419, 454, 489, 524, 559, 594, 629, 664, 699, 734, 769, 804, -106, -911, -876, -841, -806, -771, -736, -701, -666, -631, -596, -561, -526, -491, -456, -421, -386, -351, -316, -281, -246, -211, -176, -141, -71]
min(tu)
-1199
tuyo=[ii for ii in tu if ii>0]
print tuyo
[35, 70, 105, 140, 175, 210, 245, 280, 315, 350, 385, 420, 455, 490, 525, 560, 595, 630, 665, 700, 735, 770, 805, 840, 18, 53, 88, 123, 158, 193, 228, 263, 298, 333, 368, 403, 438, 473, 508, 543, 578, 613, 648, 683, 718, 753, 788, 823, 858, 36, 71, 106, 141, 176, 211, 246, 281, 316, 351, 386, 421, 456, 491, 526, 561, 596, 631, 666, 701, 736, 771, 806, 841, 876, 1, 54, 89, 124, 159, 194, 229, 264, 299, 334, 369, 404, 439, 474, 509, 544, 579, 614, 649, 684, 719, 754, 789, 824, 859, 894, 19, 72, 107, 142, 177, 212, 247, 282, 317, 352, 387, 422, 457, 492, 527, 562, 597, 632, 667, 702, 737, 772, 807, 842, 877, 912, 2, 37, 90, 125, 160, 195, 230, 265, 300, 335, 370, 405, 440, 475, 510, 545, 580, 615, 650, 685, 720, 755, 790, 825, 860, 895, 930, 20, 55, 108, 143, 178, 213, 248, 283, 318, 353, 388, 423, 458, 493, 528, 563, 598, 633, 668, 703, 738, 773, 808, 843, 878, 913, 948, 38, 3, 73, 126, 161, 196, 231, 266, 301, 336, 371, 406, 441, 476, 511, 546, 581, 616, 651, 686, 721, 756, 791, 826, 861, 896, 931, 966, 56, 21, 91, 144, 179, 214, 249, 284, 319, 354, 389, 424, 459, 494, 529, 564, 599, 634, 669, 704, 739, 774, 809, 844, 879, 914, 949, 984, 74, 4, 39, 109, 162, 197, 232, 267, 302, 337, 372, 407, 442, 477, 512, 547, 582, 617, 652, 687, 722, 757, 792, 827, 862, 897, 932, 967, 1002, 92, 22, 57, 127, 180, 215, 250, 285, 320, 355, 390, 425, 460, 495, 530, 565, 600, 635, 670, 705, 740, 775, 810, 845, 880, 915, 950, 985, 1020, 110, 5, 40, 75, 145, 198, 233, 268, 303, 338, 373, 408, 443, 478, 513, 548, 583, 618, 653, 688, 723, 758, 793, 828, 863, 898, 933, 968, 1003, 1038, 128, 23, 58, 93, 163, 216, 251, 286, 321, 356, 391, 426, 461, 496, 531, 566, 601, 636, 671, 706, 741, 776, 811, 846, 881, 916, 951, 986, 1021, 1056, 146, 6, 41, 76, 111, 181, 234, 269, 304, 339, 374, 409, 444, 479, 514, 549, 584, 619, 654, 689, 724, 759, 794, 829, 864, 899, 934, 969, 1004, 1039, 1074, 164, 24, 59, 94, 129, 199, 252, 287, 322, 357, 392, 427, 462, 497, 532, 567, 602, 637, 672, 707, 742, 777, 812, 847, 882, 917, 952, 987, 1022, 1057, 1092, 182, 7, 42, 77, 112, 147, 217, 270, 305, 340, 375, 410, 445, 480, 515, 550, 585, 620, 655, 690, 725, 760, 795, 830, 865, 900, 935, 970, 1005, 1040, 1075, 1110, 200, 25, 60, 95, 130, 165, 235, 288, 323, 358, 393, 428, 463, 498, 533, 568, 603, 638, 673, 708, 743, 778, 813, 848, 883, 918, 953, 988, 1023, 1058, 1093, 1128, 218, 8, 43, 78, 113, 148, 183, 253, 306, 341, 376, 411, 446, 481, 516, 551, 586, 621, 656, 691, 726, 761, 796, 831, 866, 901, 936, 971, 1006, 1041, 1076, 1111, 1146, 236, 26, 61, 96, 131, 166, 201, 271, 17, 52, 87, 122, 157, 192, 227, 262, 297, 332, 367, 402, 437, 472, 507, 542, 577, 612, 647, 682, 717, 752, 787, 822, 26, 61, 96, 131, 166, 201, 236, 271, 306, 341, 376, 411, 446, 481, 516, 9, 44, 79, 114, 149, 184, 219, 254, 289, 324, 359, 394, 429, 464, 499, 534, 27, 62, 97, 132, 167, 202, 237, 272, 307, 342, 377, 412, 447, 482, 517, 552, 10, 45, 80, 115, 150, 185, 220, 255, 290, 325, 360, 395, 430, 465, 500, 535, 570, 28, 63, 98, 133, 168, 203, 238, 273, 308, 343, 378, 413, 448, 483, 518, 553, 588, 11, 46, 81, 116, 151, 186, 221, 256, 291, 326, 361, 396, 431, 466, 501, 536, 571, 606, 29, 64, 99, 134, 169, 204, 239, 274, 309, 344, 379, 414, 449, 484, 519, 554, 589, 624, 12, 47, 82, 117, 152, 187, 222, 257, 292, 327, 362, 397, 432, 467, 502, 537, 572, 607, 642, 30, 65, 100, 135, 170, 205, 240, 275, 310, 345, 380, 415, 450, 485, 520, 555, 590, 625, 660, 13, 48, 83, 118, 153, 188, 223, 258, 293, 328, 363, 398, 433, 468, 503, 538, 573, 608, 643, 678, 31, 66, 101, 136, 171, 206, 241, 276, 311, 346, 381, 416, 451, 486, 521, 556, 591, 626, 661, 696, 14, 49, 84, 119, 154, 189, 224, 259, 294, 329, 364, 399, 434, 469, 504, 539, 574, 609, 644, 679, 714, 32, 67, 102, 137, 172, 207, 242, 277, 312, 347, 382, 417, 452, 487, 522, 557, 592, 627, 662, 697, 732, 15, 50, 85, 120, 155, 190, 225, 260, 295, 330, 365, 400, 435, 470, 505, 540, 575, 610, 645, 680, 715, 750, 33, 68, 103, 138, 173, 208, 243, 278, 313, 348, 383, 418, 453, 488, 523, 558, 593, 628, 663, 698, 733, 768, 16, 51, 86, 121, 156, 191, 226, 261, 296, 331, 366, 401, 436, 471, 506, 541, 576, 611, 646, 681, 716, 751, 786, 34, 69, 104, 139, 174, 209, 244, 279, 314, 349, 384, 419, 454, 489, 524, 559, 594, 629, 664, 699, 734, 769, 804]
min(tuyo)
1
def bruto(a,b): A=Set([i for i in range(-a,a)]) B=Set([i for i in range(-b,b)]) tu=[ a*y+b*x for (x,y) in A.cartesian_product(B)] tuyo=[ii for ii in tu if ii>0] return min(tuyo)
bruto(1452,16)
4
bruto(255,423)
3
bruto(36,512)
4
smcd(512,36)
512 36 1 0 0 1 476 36 1 -1 0 1 440 36 1 -2 0 1 404 36 1 -3 0 1 368 36 1 -4 0 1 332 36 1 -5 0 1 296 36 1 -6 0 1 260 36 1 -7 0 1 224 36 1 -8 0 1 188 36 1 -9 0 1 152 36 1 -10 0 1 116 36 1 -11 0 1 80 36 1 -12 0 1 44 36 1 -13 0 1 8 36 1 -14 0 1 36 8 0 1 1 -14 28 8 -1 15 1 -14 20 8 -2 29 1 -14 12 8 -3 43 1 -14 4 8 -4 57 1 -14 8 4 1 -14 -4 57 4 4 5 -71 -4 57 [4, 5, -71]
-71*36+5*512
4
a=1952 print a.divisors()
a.divisors()
[1, 2, 4, 8, 16, 32, 61, 122, 244, 488, 976, 1952]
sigma(a)
3906
def sdpr(a): return sigma(a)-a
sdpr(1952)
1954
sdpr(1996)
1504
sdpr(26)
16
sdpr(28)
28
def merss(uva): rola=[] for gg in range(uva): tutica=2^gg-1 if tutica.is_prime(): rola.append(tutica) return rola
merss(20)
[3, 7, 31, 127, 8191, 131071, 524287]
len(merss(20))
20
merss(40)
[3, 7, 31, 127, 8191, 131071, 524287, 2147483647]
def amigos(a,b): if sdpr(a)==b and sdpr(b)==a: return True else: return False
amigos(220,284)
True
amigos(542,345)
False
AA=Set([i for i in range(1,500)]) migotes=[(x,y) for (x,y) in AA.cartesian_product(AA) if x>y and amigos(x,y)]
print migotes
[(284, 220)]
amigos(57,87)
False
a=sqrt(16) type(a)
<type 'sage.rings.integer.Integer'>
a.is_integer()
True
def sumcu(a): #decide si a es suma de cuadrados ra=sqrt(a) for ii in range(1,ra): dudi=a-ii^2 duda=sqrt(dudi) if duda.is_integer(): return True break return False
sumcu(17)
True
for ii in range(2,100): if sumcu(ii): print ii #print aa
4 5 9 10 13 16 17 18 20 25 26 29 32 34 36 37 40 41 45 49 50 52 53 58 61 64 65 68 72 73 74 80 81 82 85 89 90 97 98
465.is_prime()
False
for ii in prime_range(100): if sumcu(ii): print ii
5 13 17 29 37 41 53 61 73 89 97
prime_range(100)
[2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]
def trip(a): A=Set([i for i in range(1,a)]) cp=Set([(k,j) for (k,j) in A.cartesian_product(A) if (k*k + j*j==(a*a)) and k<j]) return cp def triplas(n,i): if i<n: print i, trip(i) return triplas(n,i+1)
triplas(100,0)
0 {} 1 {} 2 {} 3 {} 4 {} 5 {(3, 4)} 6 {} 7 {} 8 {} 9 {} 10 {(6, 8)} 11 {} 12 {} 13 {(5, 12)} 14 {} 15 {(9, 12)} 16 {} 17 {(8, 15)} 18 {} 19 {} 20 {(12, 16)} 21 {} 22 {} 23 {} 24 {} 25 {(15, 20), (7, 24)} 26 {(10, 24)} 27 {} 28 {} 29 {(20, 21)} 30 {(18, 24)} 31 {} 32 {} 33 {} 34 {(16, 30)} 35 {(21, 28)} 36 {} 37 {(12, 35)} 38 {} 39 {(15, 36)} 40 {(24, 32)} 41 {(9, 40)} 42 {} 43 {} 44 {} 45 {(27, 36)} 46 {} 47 {} 48 {} 49 {} 50 {(14, 48), (30, 40)} 51 {(24, 45)} 52 {(20, 48)} 53 {(28, 45)} 54 {} 55 {(33, 44)} 56 {} 57 {} 58 {(40, 42)} 59 {} 60 {(36, 48)} 61 {(11, 60)} 62 {} 63 {} 64 {} 65 {(39, 52), (33, 56), (16, 63), (25, 60)} 66 {} 67 {} 68 {(32, 60)} 69 {} 70 {(42, 56)} 71 {} 72 {} 73 {(48, 55)} 74 {(24, 70)} 75 {(45, 60), (21, 72)} 76 {} 77 {} 78 {(30, 72)} 79 {} 80 {(48, 64)} 81 {} 82 {(18, 80)} 83 {} 84 {} 85 {(36, 77), (13, 84), (51, 68), (40, 75)} 86 {} 87 {(60, 63)} 88 {} 89 {(39, 80)} 90 {(54, 72)} 91 {(35, 84)} 92 {} 93 {} 94 {} 95 {(57, 76)} 96 {} 97 {(65, 72)} 98 {} 99 {}
trip(89)
{(39, 80)}
89^2==39^2+80^2
True
for ii in range(11): tutu=ii^2 print ii,sumcu(tutu)
0 False 1 False 2 False 3 False 4 False 5 True 6 False 7 False 8 False 9 False 10 True
sumcu(9)
False
def trip(a): A=Set([i for i in range(1,a)]) cp=Set([(k,j) for (k,j) in A.cartesian_product(A) if (k*k + j*j==(a*a)) and k<j]) return cp def triplas(n,i): if i<n: print i, trip(i) return triplas(n,i+1) def triplos(n): qq=0 # total de triplas for ii in range(n): mm=trip(ii).cardinality() print ii, mm qq=qq+mm print qq
triplos(100)
0 0 1 0 2 0 3 0 4 0 5 1 6 0 7 0 8 0 9 0 10 1 11 0 12 0 13 1 14 0 15 1 16 0 17 1 18 0 19 0 20 1 21 0 22 0 23 0 24 0 25 2 26 1 27 0 28 0 29 1 30 1 31 0 32 0 33 0 34 1 35 1 36 0 37 1 38 0 39 1 40 1 41 1 42 0 43 0 44 0 45 1 46 0 47 0 48 0 49 0 50 2 51 1 52 1 53 1 54 0 55 1 56 0 57 0 58 1 59 0 60 1 61 1 62 0 63 0 64 0 65 4 66 0 67 0 68 1 69 0 70 1 71 0 72 0 73 1 74 1 75 2 76 0 77 0 78 1 79 0 80 1 81 0 82 1 83 0 84 0 85 4 86 0 87 1 88 0 89 1 90 1 91 1 92 0 93 0 94 0 95 1 96 0 97 1 98 0 99 0 50
def tropa(a): A=Set([i for i in range(1,a)]) rrr=[(k,j) for (k,j) in A.cartesian_product(A) if k<j and gcd(k,j)==1] return rrr def tripas(a): Ququ=[ (j^2+k^2,j^2-k^2,2*j^2*k^2) for (k,j) in tropa(a)] return Ququ
tropa(10)
[(1, 2), (1, 3), (1, 4), (1, 5), (1, 6), (1, 7), (1, 8), (1, 9), (2, 3), (2, 5), (2, 7), (2, 9), (3, 4), (3, 5), (3, 7), (3, 8), (4, 5), (4, 7), (4, 9), (5, 6), (5, 7), (5, 8), (5, 9), (6, 7), (7, 8), (7, 9), (8, 9)]
tripas(10)
[(5, 3, 8), (10, 8, 18), (17, 15, 32), (26, 24, 50), (37, 35, 72), (50, 48, 98), (65, 63, 128), (82, 80, 162), (13, 5, 72), (29, 21, 200), (53, 45, 392), (85, 77, 648), (25, 7, 288), (34, 16, 450), (58, 40, 882), (73, 55, 1152), (41, 9, 800), (65, 33, 1568), (97, 65, 2592), (61, 11, 1800), (74, 24, 2450), (89, 39, 3200), (106, 56, 4050), (85, 13, 3528), (113, 15, 6272), (130, 32, 7938), (145, 17, 10368)]
def trepas(n): Mirta=Set(tripas(n)) return Mirta.cardinality()
trepas(100)
3003
for ik in range(100): print ik, trepas(ik)
0 0 1 0 2 0 3 1 4 3 5 5 6 9 7 11 8 17 9 21 10 27 11 31 12 41 13 45 14 57 15 63 16 71 17 79 18 95 19 101 20 119 21 127 22 139 23 149 24 171 25 179 26 199 27 211 28 229 29 241 30 269 31 277 32 307 33 323 34 343 35 359 36 383 37 395 38 431 39 449 40 473 41 489 42 529 43 541 44 583 45 603 46 627 47 649 48 695 49 711 50 753 51 773 52 805 53 829 54 881 55 899 56 939 57 963 58 999 59 1027 60 1085 61 1101 62 1161 63 1191 64 1227 65 1259 66 1307 67 1327 68 1393 69 1425 70 1469 71 1493 72 1563 73 1587 74 1659 75 1695 76 1735 77 1771 78 1831 79 1855 80 1933 81 1965 82 2019 83 2059 84 2141 85 2165 86 2229 87 2271 88 2327 89 2367 90 2455 91 2479 92 2551 93 2595 94 2655 95 2701 96 2773 97 2805 98 2901 99 2943
tica=[ii for ii in range(5) if ii.is_prime()]
Error in lines 1-1 Traceback (most recent call last): File "/projects/sage/sage-7.3/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 976, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> AttributeError: 'int' object has no attribute 'is_prime'
print tica
[0, 1, 2, 3, 4]
def mers(k): merse=[] for ii in range(k): tuyo=2^ii-1 if tuyo.is_prime(): merse.append(tuyo) return merse
mers(13)
[3, 7, 31, 127]
len(mers(10))
4
len(mers(130))
12
divisors(1997)
[1, 1997]
divisors(1952)
[1, 2, 4, 8, 16, 32, 61, 122, 244, 488, 976, 1952]
def tao(n): # suma de divsores sumam=0 for kaka in divisors(n): sumam=sumam+kaka return sumam
tao(10)
18
def perfektos(nono): mono=tao(nono)-nono if mono==nono: return True else: return False
perfektos(64t)
False
random_matrix?
/ext/sage/sage-8.0/local/lib/python2.7/site-packages/urllib3/contrib/pyopenssl.py:46: DeprecationWarning: OpenSSL.rand is deprecated - you should use os.urandom instead import OpenSSL.SSL
File: /ext/sage/sage-8.0/local/lib/python2.7/site-packages/sage/matrix/special.py Signature : random_matrix(ring, nrows, ncols=None, algorithm='randomize', *args, **kwds) Docstring : This function is available as random_matrix(...) and matrix.random(...). Return a random matrix with entries in a specified ring, and possibly with additional properties. INPUT: * "ring" - base ring for entries of the matrix * "nrows" - Integer; number of rows * "ncols" - (default: "None"); number of columns; if "None" defaults to "nrows" * "algorithm" - (default: "randomize"); determines what properties the matrix will have. See examples below for possible additional arguments. * "randomize" - create a matrix of random elements from the base ring, possibly controlling the density of non-zero entries. * "echelon_form" - creates a matrix in echelon form * "echelonizable" - creates a matrix that has a predictable echelon form * "subspaces" - creates a matrix whose four subspaces, when explored, have reasonably sized, integral valued, entries. * "unimodular" - creates a matrix of determinant 1. * "diagonalizable" - creates a diagonalizable matrix whose eigenvectors, if computed by hand, will have only integer entries. * "*args, **kwds" - arguments and keywords to describe additional properties. See more detailed documentation below. Warning: Matrices generated are not uniformly distributed. For unimodular matrices over finite field this function does not even generate all of them: for example "Matrix.random(GF(3), 2, algorithm='unimodular')" never generates "[[2,0],[0,2]]". This function is made for teaching purposes. Warning: An upper bound on the absolute value of the entries may be set when the "algorithm" is "echelonizable" or "unimodular". In these cases it is possible for this constructor to fail with a "ValueError". If you *must* have this routine return successfully, do not set "upper_bound". This behavior can be partially controlled by a "max_tries" keyword. Note: When constructing matrices with random entries and no additional properties (i.e. when "algorithm='randomize'"), most of the randomness is controlled by the "random_element" method for elements of the base ring of the matrix, so the documentation of that method may be relevant or useful. EXAMPLES: Random integer matrices. With no arguments, the majority of the entries are zero, -1, and 1, and rarely "large." sage: random_matrix(ZZ, 5, 5) [ -8 2 0 0 1] [ -1 2 1 -95 -1] [ -2 -12 0 0 1] [ -1 1 -1 -2 -1] [ 4 -4 -6 5 0] The "distribution" keyword set to "uniform" will limit values between -2 and 2. sage: random_matrix(ZZ, 5, 5, distribution='uniform') [ 1 0 -2 1 1] [ 1 0 0 0 2] [-1 -2 0 2 -2] [-1 -1 1 1 2] [ 0 -2 -1 0 0] The "x" and "y" keywords can be used to distribute entries uniformly. When both are used "x" is the minimum and "y" is one greater than the maximum. sage: random_matrix(ZZ, 4, 8, x=70, y=100) [81 82 70 81 78 71 79 94] [80 98 89 87 91 94 94 77] [86 89 85 92 95 94 72 89] [78 80 89 82 94 72 90 92] sage: random_matrix(ZZ, 3, 7, x=-5, y=5) [-3 3 1 -5 3 1 2] [ 3 3 0 3 -5 -2 1] [ 0 -2 -2 2 -3 -4 -2] If only "x" is given, then it is used as the upper bound of a range starting at 0. sage: random_matrix(ZZ, 5, 5, x=25) [20 16 8 3 8] [ 8 2 2 14 5] [18 18 10 20 11] [19 16 17 15 7] [ 0 24 3 17 24] To control the number of nonzero entries, use the "density" keyword at a value strictly below the default of 1.0. The "density" keyword is used to compute the number of entries that will be nonzero, but the same entry may be selected more than once. So the value provided will be an upper bound for the density of the created matrix. Note that for a square matrix it is only necessary to set a single dimension. sage: random_matrix(ZZ, 5, x=-10, y=10, density=0.75) [-6 1 0 0 0] [ 9 0 0 4 1] [-6 0 0 -8 0] [ 0 4 0 6 0] [ 1 -9 0 0 -8] sage: random_matrix(ZZ, 5, x=20, y=30, density=0.75) [ 0 28 0 27 0] [25 28 20 0 0] [ 0 21 0 21 0] [ 0 28 22 0 0] [ 0 0 0 26 24] For a matrix with low density it may be advisable to insist on a sparse representation, as this representation is not selected automatically. sage: A=random_matrix(ZZ, 5, 5) sage: A.is_sparse() False sage: A=random_matrix(ZZ, 5, 5, sparse=True) sage: A.is_sparse() True sage: random_matrix(ZZ, 5, 5, density=0.3, sparse=True) [ 4 0 0 0 -1] [ 0 0 0 0 -7] [ 0 0 2 0 0] [ 0 0 1 0 -4] [ 0 0 0 0 0] For algorithm testing you might want to control the number of bits, say 10,000 entries, each limited to 16 bits. sage: A = random_matrix(ZZ, 100, 100, x=2^16); A 100 x 100 dense matrix over Integer Ring (use the '.str()' method to see the entries) Random rational matrices. Now "num_bound" and "den_bound" control the generation of random elements, by specifying limits on the absolute value of numerators and denominators (respectively). Entries will be positive and negative (map the absolute value function through the entries to get all positive values). If either the numerator or denominator bound (or both) is not used, then the values default to the distribution for "ZZ" described above. sage: random_matrix(QQ, 2, 8, num_bound=20, den_bound=4) [ -1/2 6 13 -12 -2/3 -1/4 5 5] [ -9/2 5/3 19 15/2 19/2 20/3 -13/4 0] sage: random_matrix(QQ, 4, density = 0.5, sparse=True) [ 0 71 0 -1/2] [ 0 0 0 0] [31/85 0 -31/2 0] [ 1 -1/4 0 0] sage: A = random_matrix(QQ, 3, 10, num_bound = 99, den_bound = 99) sage: positives = list(map(abs, A.list())) sage: matrix(QQ, 3, 10, positives) [61/18 47/41 1/22 1/2 75/68 6/7 1 1/2 72/41 7/3] [33/13 9/2 40/21 45/46 17/22 1 70/79 97/71 7/24 12/5] [ 13/8 8/25 1/3 61/14 92/45 4/85 3/38 95/16 82/71 1/5] sage: random_matrix(QQ, 4, 10, den_bound = 10) [ -1 0 1/8 1/6 2/9 -1/6 1/5 -1/8 1/5 -1/5] [ 1/9 1/5 -1 2/9 1/4 -1/7 1/8 -1/9 0 2] [ 2/3 2 1/8 -2 0 0 -2 2 0 -1/2] [ 0 2 1 -2/3 0 0 1/6 0 -1/3 -2/9] Random matrices over other rings. Several classes of matrices have specialized "randomize()" methods. You can locate these with the Sage command: search_def('randomize') The default implementation of "randomize()" relies on the "random_element()" method for the base ring. The "density" and "sparse" keywords behave as described above. Since we have a different randomisation when using the optional meataxe package, we have to make sure that we use the default implementation in this test: sage: K.<a>=FiniteField(3^2) sage: from sage.matrix.matrix_generic_dense import Matrix_generic_dense sage: MS = MatrixSpace(K, 2, 5) sage: MS._MatrixSpace__matrix_class = Matrix_generic_dense sage: random_matrix(K, 2, 5) [ 1 a 1 2*a + 1 2] [ 2*a a + 2 0 2 1] sage: random_matrix(RR, 3, 4, density=0.66) [ 0.000000000000000 -0.806696574554030 -0.693915509972359 0.000000000000000] [ 0.629781664418083 0.000000000000000 -0.833709843116637 0.000000000000000] [ 0.922346867410064 0.000000000000000 0.000000000000000 -0.940316454178921] sage: A = random_matrix(ComplexField(32), 3, density=0.8, sparse=True); A [ 0.000000000 0.399739209 + 0.909948633*I 0.000000000] [-0.361911424 - 0.455087671*I -0.687810605 + 0.460619713*I 0.625520058 - 0.360952012*I] [ 0.000000000 0.000000000 -0.162196416 - 0.193242896*I] sage: A.is_sparse() True Random matrices in echelon form. The "algorithm='echelon_form'" keyword, along with a requested number of non-zero rows ("num_pivots") will return a random matrix in echelon form. When the base ring is "QQ" the result has integer entries. Other exact rings may be also specified. sage: A=random_matrix(QQ, 4, 8, algorithm='echelon_form', num_pivots=3); A # random [ 1 -5 0 -2 0 1 1 -2] [ 0 0 1 -5 0 -3 -1 0] [ 0 0 0 0 1 2 -2 1] [ 0 0 0 0 0 0 0 0] sage: A.base_ring() Rational Field sage: (A.nrows(), A.ncols()) (4, 8) sage: A in sage.matrix.matrix_space.MatrixSpace(ZZ, 4, 8) True sage: A.rank() 3 sage: A==A.rref() True For more, see the documentation of the "random_rref_matrix()" function. In the notebook or at the Sage command-line, first execute the following to make this further documentation available: from sage.matrix.constructor import random_rref_matrix Random matrices with predictable echelon forms. The "algorithm='echelonizable'" keyword, along with a requested rank ("rank") and optional size control ("upper_bound") will return a random matrix in echelon form. When the base ring is "ZZ" or "QQ" the result has integer entries, whose magnitudes can be limited by the value of "upper_bound", and the echelon form of the matrix also has integer entries. Other exact rings may be also specified, but there is no notion of controlling the size. Square matrices of full rank generated by this function always have determinant one, and can be constructed with the "unimodular" keyword. sage: A=random_matrix(QQ, 4, 8, algorithm='echelonizable', rank=3, upper_bound=60); A # random sage: A.base_ring() Rational Field sage: (A.nrows(), A.ncols()) (4, 8) sage: A in sage.matrix.matrix_space.MatrixSpace(ZZ, 4, 8) True sage: A.rank() 3 sage: all([abs(x)<60 for x in A.list()]) True sage: A.rref() in sage.matrix.matrix_space.MatrixSpace(ZZ, 4, 8) True For more, see the documentation of the "random_echelonizable_matrix()" function. In the notebook or at the Sage command-line, first execute the following to make this further documentation available: from sage.matrix.constructor import random_echelonizable_matrix Random diagonalizable matrices. The "algorithm='diagonalizable'" keyword, along with a requested matrix size ("size") and optional lists of eigenvalues ("eigenvalues") and the corresponding eigenspace dimensions ("dimensions") will return a random diagonalizable matrix. When the eigenvalues and dimensions are not specified the result will have randomly generated values for both that fit with the designated size. sage: A=random_matrix(QQ, 5, algorithm='diagonalizable', eigenvalues=[2,3,-1], dimensions=[1,2,2]); A # random sage: all([x in ZZ for x in (A-(2*identity_matrix(5))).rref().list()]) True sage: all([x in ZZ for x in (A-(3*identity_matrix(5))).rref().list()]) True sage: all([x in ZZ for x in (A-(-1*identity_matrix(5))).rref().list()]) True sage: A.jordan_form() [ 2| 0| 0| 0| 0] [--+--+--+--+--] [ 0| 3| 0| 0| 0] [--+--+--+--+--] [ 0| 0| 3| 0| 0] [--+--+--+--+--] [ 0| 0| 0|-1| 0] [--+--+--+--+--] [ 0| 0| 0| 0|-1] For more, see the documentation of the "random_diagonalizable_matrix()" function. In the notebook or at the Sage command-line, first execute the following to make this further documentation available: from sage.matrix.constructor import random_diagonalizable_matrix Random matrices with predictable subspaces. The "algorithm='subspaces'" keyword, along with an optional rank ("rank") will return a matrix whose natural basis vectors for its four fundamental subspaces, if computed as described in the documentation of the "random_subspaces_matrix()" contain only integer entries. If "rank", is not set, the rank of the matrix will be generated randomly. sage: B=random_matrix(QQ, 5, 6, algorithm='subspaces', rank=3); B #random sage: B_expanded=B.augment(identity_matrix(5)).rref() sage: (B.nrows(), B.ncols()) (5, 6) sage: all([x in ZZ for x in B_expanded.list()]) True sage: C=B_expanded.submatrix(0,0,B.nrows()-B.nullity(),B.ncols()) sage: L=B_expanded.submatrix(B.nrows()-B.nullity(),B.ncols()) sage: B.right_kernel()==C.right_kernel() True sage: B.row_space()==C.row_space() True sage: B.column_space()==L.right_kernel() True sage: B.left_kernel()==L.row_space() True For more, see the documentation of the "random_subspaces_matrix()" function. In the notebook or at the Sage command-line, first execute the following to make this further documentation available: from sage.matrix.constructor import random_subspaces_matrix Random unimodular matrices. The "algorithm='unimodular'" keyword, along with an optional entry size control ("upper_bound") will return a matrix of determinant 1. When the base ring is "ZZ" or "QQ" the result has integer entries, whose magnitudes can be limited by the value of "upper_bound". sage: C=random_matrix(QQ, 5, algorithm='unimodular', upper_bound=70); C # random sage: det(C) 1 sage: C.base_ring() Rational Field sage: (C.nrows(), C.ncols()) (5, 5) sage: all([abs(x)<70 for x in C.list()]) True For more, see the documentation of the "random_unimodular_matrix()" function. In the notebook or at the Sage command-line, first execute the following to make this further documentation available: from sage.matrix.constructor import random_unimodular_matrix AUTHOR: * William Stein (2007-02-06) * Rob Beezer (2010-08-25) Documentation, code to allow additional types of output