2020-08-04 11:09:30 -0500 received badge ● Notable Question (source) 2020-07-11 04:58:42 -0500 received badge ● Notable Question (source) 2020-07-10 14:02:22 -0500 asked a question Why doesn't '==' or '!=' work for mixed forms? I have the following setup M = Manifold((4), 'M', field='complex') U = M.open_subset('U') x = U.chart(names=tuple('x_%d' % i for i in range(4))) eU = x.frame() Form0 = M.mixed_form(comp=([0,0,0,0,0])) Form1 = M.mixed_form(comp=([1,0,0,0,0]))  Clearly Form0 and Form1 are distinct mixed forms of M, but when I run if Form0 != Form1: print('Not Equal') else: print('Equal')  I get 'Equal' as the output, what's going wrong? 2020-06-09 23:36:45 -0500 asked a question Can a loop be made to skip an iteration if the run time exceeds a certain amount? I apologize if this is a little abstract, but is it possible to create some sort of "for" or "while" loop that will pass to the next iterate if the computation for that specific iterate takes too long? For example, it could be something along the lines of, for some function/procedure F(n)  we have for n in range(100): print(F(n))  but if for some n in the range, the computation of F(n) takes more than say, 1 minute CPU time, I want it to either just skip to computing F(n+1) and/or print "-1" in place of F(n). So let's say F(0), F(1), and F(2) all take less than half a second to compute they print just fine, so then n gets set to n=3, and F(3) starts running, but let's say it runs for over a minute, I want it to be that the loop outputs "-1" (or something) and then moves on to computing F(4). UPDATE: I'd also like to be able, if possible, to print out run times. So that the output would be something like (F(1), time(1)) (F(2), time(2)) (F(3), times(3)) ...  etc., where time(n) is the amount of time it took to compute F(n). 2020-06-03 09:22:54 -0500 commented question Are there fast(er) ways to compute inverses of Hermitian matrices? @mwageringel It's a little convoluted, by the symbolic variables I have set up are supposed to represent complex numbers, and part of the indexing reflects conjugation. Under this identification the matrices h[i] can be seen as Hermitian matrices. If you'd really like I can explain the details, but I don't think they're relevant to the question at hand. 2020-06-03 09:19:49 -0500 commented question Are there fast(er) ways to compute inverses of Hermitian matrices? @Frederic are computations in polynomial rings that much faster? I was under the impression they worked the same as symbolic rings. I tried rewriting the code using a polynomial ring, but it seemed to make no difference in the run time when q=4, and certainly q=5 still isn't feasible. 2020-05-30 00:51:15 -0500 asked a question Are there fast(er) ways to compute inverses of Hermitian matrices? I'm dealing with some Hermitian matrices valued in symbolic expressions. I need to be able to compute inverses of these matrices, but they seem to get big pretty fast. That is it would nice to be able to do this in a reasonable amount of time with 10x10 matrices at least, and hopefully larger than that. I'm currently running a cell where the inverses of 2 10x10 matrices are being computed, and it's taken well over 10 minutes. Are there ways to exploit the fact that these matrices are Hermitian to compute the inverses faster, and/or are there better ways to compute inverses of symbolic matrices than the standard .inverse()?? EDIT: I originally avoided an example, because their construction is somewhat convoluted as you'll see below. First we have two variables which for which I want to run the larger program for various choices thereof. p = 1, q= 5 X = {(i): var("X_{}".format(i), latex_name="X_{}") for i in range(2*p*q)} e = {(i,j,k): var("e_{}{}{}".format(i,j,k), latex_name="e_{{{}{}{}}}".format(i,j,k)) for i in range(2) for j in range(q) for k in range((p+q))}  The following creates a list L such that L[i] is the collection of lists of length i whose elements are integers between 0 and q-1 in strictly increasing order. This is used throughout the larger program. L = [[[]]] LL = [] for i in range(q): LL.append([i]) L.append(LL) if q>=2: for k in range(2,q+1): LLL = [] for i in range(binomial(q, k-1)): for j in range(q): if L[k-1][i][len(L[k-1][i])-1]=p: prod += (e[(0, i, l)]*e[(0, j, l)]) HE[i,j] = prod h = {(i): var("h_{}".format(i)) for i in range(q+1)} for i in range(q+1): h[i] = matrix(SR, binomial(q, i), binomial(q, i)) h[0,0] = 1 for i in range(1, q+1): for z in L[i]: for w in L[i]: h[i][L[i].index(z), L[i].index(w)] = HE[z, w].det()  Finally, we come to the inverse matrices I would like to compute. It is absolutely necessary that I have these inverse matrices. hinv = {(i): var("hinv_{}".format(i)) for i in range(q+1)} for i in range(q+1): hinv[i] = h[i].inverse()  2020-04-26 04:58:25 -0500 received badge ● Popular Question (source) 2019-12-05 05:29:01 -0500 received badge ● Popular Question (source) 2019-08-22 09:13:05 -0500 asked a question Setting the components of a differential form systematically. Suppose for some p and q we have a manifold Sage: p=1 Sage: q=2 Sage: M = Manifold((2*p*q), 'M', field='complex') Sage: U = M.open_subset('U') Sage: x = U.chart(names=tuple('x_%d' % i for i in range(2*p*q))) Sage: eU = x.frame()  and some differential forms Sage: d = {(i): var("d_{}".format(i)) for i in range(2*p*q)} Sage: for i in range(2*p*q): Sage: d[i] = M.diff_form(i)  I want to construct and/or inspect components of these differential forms in a systematic way, which is to say I want to be able to iterate over the components. So for example, one way in which I've tried to do this is to create lists. For example, if we let Sage: R = [eU, 0, 1]  I would want to say Sage: dR = 1  but this gives me a syntax error. I've also tried something like Sage: S = [0, 1] Sage: d[eU, :]S = 1  but again I get a syntax error. 2019-08-19 11:10:02 -0500 received badge ● Commentator 2019-08-19 11:10:02 -0500 commented answer Defining manifolds in a systematic way. Hey, is there a way to do this in such a way that the coordinates have multiple indices, like x[(i,j,k)]? 2019-08-06 09:53:48 -0500 commented answer Substituting symbolic expressions for mixed differential forms. Thanks, this seems to do the trick. I'm just wondering though, how can I have it so that the c's are indexed by two numbers? 2019-08-05 10:29:55 -0500 asked a question Substituting symbolic expressions for mixed differential forms. I'm doing some computations with matrices differential forms, and the run times are extremely long. So in an attempt to keep run times down, I'm attempting to do matrix computations with symbolic terms, and then later replacing them with the mixed forms I want. However, there's the coercion from mixed forms into the symbolic ring, and this is presenting a problem for me. As a toy example of what I'm trying to do, I have the set up (say) Sage: p=1 Sage: q=2 Sage: M = Manifold((2*p*q), 'M', field='complex') Sage: U = M.open_subset('U') Sage: x = U.chart(names=tuple('x_%d' % i for i in range(2*p*q))) Sage: eU = x.frame() Sage: d = [M.diff_form(1) for i in range(q)] Sage: for i in range(q): Sage: d[i][i] = x[i] Sage: D = [M.mixed_form(comp=([0, d[i], 0, 0, 0])) for i in range(q)] Sage: c = {(i): var("c_{}".format(i)) for i in range(q)} Sage: exp = 0 Sage: for i in range(q): Sage: for j in range(q): Sage: exp = exp + c[i]*c[j]  Now, in my actual project I will have many of these variables, so it's not feasible to manually type them into one substitution at once, so I need to do it with a for loop, so I try Sage: for i in range(q): Sage: exp.subs({c[i] : D[i]})  But this is where I get the coercion error. As mentioned, the actual computations I'm dealing with involve large matrices of mixed forms, and the run times would be WAY shorter if I can do it all in symbolic matrices, and then transfer the expressions I get out (which come from taking a trace). How might I be able to achieve this? 2019-07-29 03:48:48 -0500 received badge ● Great Question (source) 2019-07-26 16:31:17 -0500 asked a question Is there any way to have a cell tell you how long it took to run in the Jupyter notebook? The question is basically all in the title. I'm working on a project in the Jupyter and notebook, and I have some cells that have longer run times. Sometimes I let these run, and come back to check on them later, however it would be nice to know exactly what duration those cells ran for. 2019-07-19 20:56:46 -0500 asked a question Why does .remove() seem to take every element out of a list? I've found that if I define a list Sage: list1 = [1,2,3]  and then try to remove an element Sage: list2 = list1.remove(2)  but then Sage: print(list2)  returns None  2019-07-10 13:06:16 -0500 commented answer Defining manifolds in a systematic way. Oh, I just tried it again and it worked, must have made a typo the first time, thanks. 2019-07-10 12:06:07 -0500 commented answer Defining manifolds in a systematic way. How do I define a frame then? My naive attempt in analogy to the usual situation, Sage: eU = x.frame()  but this doesn't work. 2019-07-10 11:35:45 -0500 asked a question Defining manifolds in a systematic way. I'm working on writing an algorithm that does some specific computations with manifolds. I would like to be able to simply enter 2 numbers "p" and "q" which determine the manifold's dimension p*q, and have the algorithm run right from there. This requires having Sage set up the manifold right from those two numbers. I'm having trouble at the level of defining the chart. Below I begin a naive attempt. Sage: p=1 Sage: q=2 Sage: M = Manifold((2*p*q), 'M', field='complex') Sage: U = M.open_subset('U') Sage: x = list(var('x_%d' %i) for i in range((2*p*q)))  Everything works fine up to this point. Now, I need to define variables for a chart for this manifold. I would like to do something like Sage: c. = U.chart()  where I'm using the variables I've defined as my coordinates. However, Sage doesn't allow me to do this. Furthermore, even if I could, I'm not sure how I would set this up so I didn't have to type in the variables by hand, because I want to set it up so I just have to feed Sage p and q, and let it build the manifold on its own. 2019-07-03 13:23:28 -0500 marked best answer How to create/use matrices valued in differential forms? First, for context, I am working with holomorphic Hermitian vector bundles, and I need to compute the connection and curvature matrices, and compute some representatives for Chern classes and the Chern form. Ultimately I want to have a matrix which is valued in differential forms, and when I multiply matrices, I want the component-wise multiplication to be the wedge product of forms. When I naively try to build a matrix of forms 'by hand', or when I pre-define my matrix space to be valued in the module of differential forms, I get an error telling me that the space of differential forms is a not a ring. For example, import sys import mpmath sys.modules['sympy.mpmath'] = mpmath M = Manifold(2, 'M', field='complex') U = M.open_subset('U') c_xy. = U.chart() e_xy = c_xy.frame() a = M.diff_form(2, name='a') a.parent() eU = c_xy.frame() a.degree() a[eU,0,1] = x*y^2 + 2*x a.display(eU) A = matrix([[a, a], [a, a]])  prints out Module Omega^2(M) of 2-forms on the 2-dimensional complex manifold M 2 a = (x*y^2 + 2*x) dx/\dy  and raises a type error: TypeError: base_ring (=Module Omega^2(M) of 2-forms on the 2-dimensional complex manifold M) must be a ring  2019-06-30 14:33:07 -0500 received badge ● Citizen Patrol (source) 2019-06-25 11:46:40 -0500 edited question How to change/set variables? I created a list of formal variables that I want to work with under addition, multiplication etc. in the following way: g = list(var('g_%d' % i) for i in rang(4))  Specifically I'm working with differential forms M = Manifold(4, 'M', field='complex') U = M.open_subset('U') c_xyXY=U.chart() eU = c_xyXY.frame() d = [[M.diff_form(2, name='d_{}{}'.format(j, i)) for i in range(2)] for j in range(2)] d [eU, 2, 0] = g d [eU, 3, 0] = g d [eU, 2, 1] = g d [eU, 3, 1] = g  I then want to set the variables to something specific like g = x^2  but when I try to display this I get d.display(eU) d_00 = -g_0dx/\dX  What I want is d_00 = -x^2dx/\dX  EDIT: The question as originally asked has been sufficiently answered by eric_g below. However I'm still having difficulty with a more complicated version of the same set-up, which I present here: https://ask.sagemath.org/question/469... 2019-06-25 11:45:38 -0500 asked a question (Update) How to change/set variables? I asked a simplified version of this question, and got an answer here: However I'm still having difficulty with a more complicated version of the same set-up, which I present here. Essentially I want to take a trace of an exponential of a matrix valued in forms. When I try running it with the forms I want, the run time takes far too long, certainly over an hour on my laptop. However, it's much shorter if I use forms with symbolic coefficients. What follows below is my attempt at computing the forms I want with symbols first, and then trying to set the coefficients at the end. To start, I have sage: M = Manifold(6, 'M', field='complex') sage: U = M.open_subset('U') sage: c_xyzXYZ. = U.chart() sage: eU = c_xyzXYZ.frame() sage: var('x,y,z,X,Y,Z')  I create some symbolic differential forms in the following way, sage: g = {(i, j, k): var("g_{}{}{}".format(i, j, k), latex_name="g_{{{}{}{}}}".format(i, sage:... j, k)) for i in range(9) for j in range[3, 4, 5] for k in range(3)} sage: f = [M.diff_form(2, name='f_{}'.format(i)) for i in range(9)] sage: for i in range(9): sage: for j in [3, 4, 5]: sage: for k in range(3): sage: f[i][eU, j, k] = g[(i, j, k)] sage: F = [M.mixed_form(comp=[0, 0, f[i], 0, 0, 0, 0]) for i in range(9)]  Now I create a matrix valued in differential forms (I'm running the current beta version), define an identity matrix of mixed forms, define an exponential function (the usual .exp() for matrices doesn't seem to work when the matrix is valued in mixed forms) sage: FF = Matrix([[F, F, F], [F, F, F], [F, F, F]]) sage: G = FF.apply_map(lambda f: (I/2*pi)*f) sage: I_00 = M.mixed_form(comp=[1, 0, 0, 0, 0, 0, 0]) sage: I_01 = M.mixed_form(comp=[0, 0, 0, 0, 0, 0, 0]) Id = matrix([[I_00, I_01, I_01], [I_01, I_00, I_01], [I_01, I_01, I_00]]) sage: EXP = lambda f: Id+f+(f^2).apply_map(lambda g: (1/2)*g) sage: ...+(f^3).apply_map(lambda g: (1/6)*g) sage: ...+(f^4).apply_map(lambda g: (1/24)*g) sage: ...+(f^5).apply_map(lambda g: (1/120)*g) sage: ...+(f^6).apply_map(lambda g: (1/720)*g)  Finally I compute the trace of the exponential of the matrix G, sage: E = EXP(G) sage: CH = E.trace()  Now if one trys to display CH in the frame eU, after about 10 minutes, this will print out some massive mixed form with coefficients being the g[(i, j, k)]. I now want to change the components of these forms to explicit forms. For simplicity of the example, lets just assume I want them all to be x^2. sage: for i in range(9): sage: for j in [3, 4, 5]: sage: for k in range(3): sage: g[(i, j, k)] = x^2  Than I update the forms as suggested in the answer to my original question, sage: for i in range(9): sage: for j in [3, 4, 5]: sage: for k in range(3): sage: f[i][eU, j, k] = g[(i, j, k)]  If you trying displaying any f, it's clear that this has worked. However, when I try to write sage: CH.display(eU)  all the components are still in terms of g_{}{}{}, they have not been changed to x^2. Is there some way to do this without having to run the computation of CH again? The whole point of this convoluted example was to avoid doing this computation with the functions I'm actually interested in, and only set them at the end.