2021-04-09 05:38:26 +0200 marked best answer "Ratio" of two elements in a ring Suppose I have a $\mathbb{Q}$-algebra R, and I have two elements x and y in R. I happen to know that x is a scalar multiple of y. Is there a way to figure out what the scalar is? In other words, I want to identify the $\mathbb{Q}$-span of y with 1-dimensional vector space, choose an isomorphism of this vector space with $\mathbb{Q}$ (sending y to 1), and see where x goes. The general context is that R is a finite-dimensional graded $\mathbb{Q}$-algebra (given as a quotient of a polynomial ring), and the top degree piece has dimension 1. I have an isomorphism of this top degree piece with $\mathbb{Q}$ (defined by sending a certain element to 1), and I want to be able to compute what it does to other elements. An example of such a ring: let $A = \mathbb{Q}[x_1, x_2, x_3, x_4]$. Let $I_1 = (x_1x_3, x_2x_4)$. Let $I_2 = (x_1 + x_3, x_2 + x_4)$. Let $R = A/(I_1 + I_2)$. (Note that $R$ is the Stanley-Reisner ring of simplicial complex (a triangulation of the circle) modulo a linear system of parameters. So it is graded by degree, and as the simplicial complex is a circle, the degree 2 is a 1-dimensional vector space.) Let $y = x_1 x_2$, and let $x = (x_1 + x_4)(x_2 + x_3)$. Then x is a scalar multiple of y (as they are both in degree 2), and I would like to know what the scalar is. (In this case, x = 2y.) Later edit: fixed typo 2021-04-09 05:38:19 +0200 edited question "Ratio" of two elements in a ring "Ratio" of two elements in a ring Suppose I have a $\mathbb{Q}$-algebra R, and I have two elements x and y in R. I happe 2021-04-09 05:37:55 +0200 edited question "Ratio" of two elements in a ring "Ratio" of two elements in a ring Suppose I have a $\mathbb{Q}$-algebra R, and I have two elements x and y in R. I happe 2021-04-08 19:38:27 +0200 edited question "Ratio" of two elements in a ring "Ratio" of two elements in a ring Suppose I have a $\mathbb{Q}$-algebra R, and I have two elements x and y in R. I happe 2021-04-08 04:40:24 +0200 asked a question "Ratio" of two elements in a ring "Ratio" of two elements in a ring Suppose I have a $\mathbb{Q}$-algebra R, and I have two elements x and y in R. I happe 2021-04-08 03:54:01 +0200 received badge ● Popular Question (source) 2021-04-08 03:52:41 +0200 received badge ● Famous Question (source) 2021-04-06 10:34:23 +0200 received badge ● Famous Question (source) 2020-11-30 04:46:52 +0200 received badge ● Famous Question (source) 2020-01-07 18:16:16 +0200 received badge ● Notable Question (source) 2019-11-07 07:06:02 +0200 received badge ● Notable Question (source) 2019-01-02 22:08:29 +0200 received badge ● Notable Question (source) 2018-12-25 12:46:51 +0200 received badge ● Nice Question (source) 2018-12-24 17:29:23 +0200 asked a question Computing heights of large degree algebraic numbers I have an irreducible polynomial of large degree (I would like to go up to degree ~1000), and I would like to compute the height of its roots. Currently I am doing this: def irreducible_root_height(f): K. = NumberField(f) h = y.global_height() return h  This is rather slow because I have to construct the number field. Is there a way to find the height without constructing the number field? I tried to use the functionality with general algebraic numbers, but there doesn't seem to be a way to define an arbitrary root of a polynomial in QQbar. It also looks like computing the height of something in QQbar works by computing a number field, so this wouldn't be any faster. 2018-09-25 13:23:54 +0200 received badge ● Popular Question (source) 2018-07-25 23:00:44 +0200 asked a question Elements of the Stanley-Reisner ring I have a simplicial complex, and I'm trying to manipulate the Stanley-Reisner ring of that simplicial complex. This is just a quotient of a polynomial ring. The generators of the quotient ring are called (according to R.gens()) x0bar, x1bar, x2bar, x3bar. However, when I try to refer to elements of the ring in this way (for example, to create an ideal containing certain elements), I get an error. For example: sage: X = SimplicialComplex([[1,2,3], [0,2,3], [0,1,3]]) sage: R = X.stanley_reisner_ring() sage: R(x0bar)  This gives me the following error: NameError Traceback (most recent call last) in () ----> 1 R(x0bar) NameError: name 'x0bar' is not defined  2018-04-05 10:45:16 +0200 received badge ● Notable Question (source) 2018-02-02 18:15:05 +0200 received badge ● Popular Question (source) 2017-12-18 23:54:44 +0200 received badge ● Popular Question (source) 2017-08-21 05:11:49 +0200 asked a question Changing the weights in a graph Suppose I have a weighted graph G, and I want to change the weights of some of the edges. One way to do this is to output the weighted adjacency matrix, modify it, and then recreate the graph. Is there a more efficient way? 2017-08-19 00:56:20 +0200 received badge ● Popular Question (source) 2017-08-05 10:50:47 +0200 received badge ● Self-Learner (source) 2017-08-05 10:50:47 +0200 received badge ● Teacher (source) 2017-08-01 04:42:07 +0200 answered a question Paths beginning with a certain vertex I'm not sure if this is the most efficient, but I did find a way. If you want the the path to begin with (v1, v2), then you can use:  S = list(SubgraphSearch(G, graphs.PathGraph(n))) S[:] = [path for path in S if (path[0] == v1 and path[1] == v2)]  2017-08-01 00:09:40 +0200 asked a question Paths beginning with a certain vertex So I have a graph $G$ and a distinguished vertex, labeled with $0$ say. I would like to create a list of all paths of length $k$ that start with $0$. One way I see how to do this with subgraph_search is to change $0$ into a large clique (larger than the clique number of $G$) and then use subgraph_search_iterator to find all subgraphs with a large clique connected to a path of length $k-1$. However, this seems pretty inefficient. Is there a better way? 2017-06-29 20:46:35 +0200 asked a question Using the small group library in Sage notebook Is there any way to import groups from the GAP small group library into Sage notebook? I've tried importing the library using the terminal, but I haven't been able to. When I run sage -i database_gap  while running sage in the terminal, I get an invalid syntax error. I am running Mac OS X 10.12.5 When I run sage -i database_gap in the notebook, I get the following error Traceback (most recent call last): File "", line 1, in File "_sage_input_9.py", line 10, in exec compile(u'open("___code___.py","w").write("# -*- coding: utf-8 -*-\\n" + _support_.preparse_worksheet_cell(base64.b64decode("c2FnZSAtaSBkYXRhYmFzZV9nYXA="),globals())+"\\n"); execfile(os.path.abspath("___code___.py")) File "", line 1, in File "/private/var/folders/hn/_c_yl0fj0zlfwvzcy0f5138w0000gp/T/tmpEaYQvh/___code___.py", line 2 sage -i database_gap ^ SyntaxError: invalid syntax  2016-11-23 21:13:05 +0200 asked a question Evaluating characters of linear algebraic group How would I evaluate the characters on $SL_2(\mathbb{F}_q)$ on some conjugacy class (which I know one element of). I think I will have to use the port to GAP, as constructing characters of non-permutation groups doesn't seem to implemented. I could construct the character table, but that is maybe inefficient. 2016-09-26 23:01:48 +0200 asked a question Generating all elements of $SL_2(\mathbb{F}_q)$ What is the fastest way to create a set with all elements of $SL_2(\mathbb{F}_q)$ for $q$ some prime power of size about $50$? One way to do it is to find a representative for each conjugacy class and then use the ConjugacyClass method, but this seems inefficient. Is there a better way? 2016-09-04 23:25:14 +0200 commented answer Finding the maximum on an interval and find root scipy is giving me the wrong answer. Also, I am looking for the x-value of the giant spike that occurs at about 5.56, not the maximum on [0, 2pi]. (There are many local maximum around there, so find local maximum doesn't work.) 2016-09-03 21:26:33 +0200 asked a question Finding the maximum on an interval and find root I have a function f that is the truncation of the fourier transform of a sequence (i.e. f = sum( cos(a*x) for a in sequence), where sequence has 10,000 terms). I want to find the absolute maximum on an interval. The documentation suggest getting the maximum of the plot, which works. I would like to know where this maximum occurs, though. As the maximum is 3272.9689885743473, f - 3200 should have a root, but find_root doesn't find a root. I guess this is technically a bug, but not very surprising given the definition of f. My main question is, how do I find out where this maximum occurs? I can squint at the plot, but this isn't accurate enough. sequence = [3, 4, 6, 9, 10, 17, 18, 25, 30, 32, 37, 44, 45, 52, 59, 60, 71, 72, 73, 86, 87, 94, 99, 106, 107, 114, 121, 122, 134, 135, 142, 149, 156, 161, 163, 168, 175, 176, 183, 190, 197, 204, 211, 218, 225, 226, 237, 238, 245, 252, 253, 265, 266, 273, 280, 287, 288, 300, 301, 314, 315, 322, 327, 334, 335, 342, 349, 350, 362, 363, 370, 377, 384, 391, 396, 403, 404, 411, 418, 419, 431, 432, 439, 446, 453, 454, 465, 466, 473, 480, 481, 493, 494, 501, 508, 515, 516, 528, 529, 542, 543, 550, 555, 562, 563, 570, 577, 584, 591, 598, 605, 612, 619, 620, 631, 632, 639, 646, 647, 659, 660, 667, 674, 681, 682, 694, 695, 708, 709, 721, 722, 729, 736, 743, 744, 756, 757, 764, 771, 772, 784, 785, 798, 805, 812, 813, 825, 826, 833, 840, 841, 848, 853, 860, 867, 874, 875, 887, 888, 895, 902, 903, 910, 915, 922, 923, 930, 937, 944, 949, 956, 957, 964, 971, 972, 984, 985, 992, 999, 1006, 1013, 1018, 1026, 1033, 1040, 1041, 1053, 1054, 1061, 1068, 1069, 1080, 1081, 1082, 1095, 1102, 1103, 1115, 1116, 1123, 1130, 1137, 1138, 1150, 1157, 1158, 1165, 1172, 1177, 1184, 1185, 1192, 1199, 1200, 1212, 1213, 1220, 1227, 1234, 1235, 1246, 1247, 1254, 1261, 1262, 1269, 1274, 1281, 1282, 1289, 1296, 1297, 1309, 1310, 1323, 1324, 1331, 1336, 1343, 1344, 1351, 1358, 1365, 1372, 1379, 1386, 1393, 1400, 1401, 1412, 1413, 1420, 1427, 1428, 1440, 1441, 1448, 1455, 1462, 1463, 1475, 1482, 1489, 1490, 1502, 1503, 1510, 1517, 1524, 1525, 1537, 1538, 1551, 1552, 1559, 1566, 1571, 1578, 1579, 1586, 1593, 1594, 1606, 1607, 1614, 1621, 1628, 1629, 1640, 1641, 1648, 1655, 1656, 1668, 1669, 1676, 1683, 1690, 1691, 1703, 1704, 1717, 1718, 1725, 1730, 1737, 1738, 1745, 1752, 1759, 1766, 1773, 1780, 1787, 1794, 1795, 1806, 1807, 1814, 1821, 1822, 1834, 1835, 1842, 1849, 1856, 1857, 1869, 1870, 1883, 1884, 1896, 1897, 1904, 1911, 1918, 1919, 1931, 1932, 1939, 1946, 1953, 1960, 1965, 1973, 1980, 1987, 1988, 2000, 2001, 2008, 2015, 2022, 2023, 2035, 2042, 2049, 2050, 2062, 2063, 2070, 2077, 2078, 2085, 2090, 2097, 2104, 2111, 2112, 2119, 2124, 2131, 2132, 2139, 2146 ... 2016-08-30 14:47:55 +0200 commented question No speed gain with parallel? @krisman that is how @parallel is used in the documentation. It is also giving me correct results a no errors, and it seems like it would give me errors if it was that wrong. Doing computation(10^5) gives me no speedup over not using parallel, and doing computation(a) (when a is a list, but not putting the list) does it instantly, so it is not actually doing the computation (it gives me a generator object if I try to retrieve it). 2016-08-30 04:28:24 +0200 received badge ● Editor (source) 2016-08-30 04:24:53 +0200 asked a question No speed gain with parallel? I'm doing a computation that seems ripe for parallelization (I am doing almost same computation over and over again independently), but it doesn't seem to be working. Rather than going 4 times faster, it takes 4 times longer! (I have 4 cores). It is giving me (seemingly correct) results. Perhaps someone more familiar with parallel can tell me what I am doing wrong. import numpy start = time.time() zero = RDF.zero() four = RDF(4r) @parallel def computation(length): numpy.random.seed() result = 0 data = [0r]*length data[0r] = numpy.random.normal(0r,1r) for j in range(1r, length): data[j] = data[j-1r] + numpy.random.normal(0,1) for k in xrange(2r, length): a = RDF(data[k]) if a>0 and a*a > four*RDF(k)*RDF(k+1r).log().log(): result += 1r return result a = [10^8]* 4 print(sorted(list(computation(a))))  EDIT: I tried it again and the parallel version was much faster. I don't know what was happening before. 2016-08-09 23:29:29 +0200 received badge ● Nice Question (source) 2016-08-07 23:29:01 +0200 marked best answer Memory leak somewhere? My code is using massive amounts of memory (eventually), which I don't think should be the case. The memory use slowly increases until my computer runs out of memory. I tried enabling garbage collection, but that didn't help (or didn't help enough). I don't see any reason why this should use more and more memory. It takes somewhere between 5 and 10 hours for this program to use up my 16 GB of memory, but that memory user is increasing is clear quickly. import numpy trials = 5800 length = 5000 mean = 0 results = [0]*trials data = [0]*length for i in range(trials): data[0] = numpy.random.normal(0,1) for j in range(1, length): data[j] = data[j-1] + numpy.random.normal(0,1) for k in range(2, length): if data[k] > 2*sqrt(k*log(log(k+1))): results[i] += 1 mean += results[i]