Ask Your Question
0

(Update) How to change/set variables?

asked 2019-06-25 18:45:38 +0100

sum8tion gravatar image

I asked a simplified version of this question, and got an answer here:

https://ask.sagemath.org/question/469...

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.<x,y,z,X,Y,Z> = 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[0], F[1], F[2]], [F[3], F[4], F[5]], [F[6], F[7], F[8]]])
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.

edit retag flag offensive close merge delete

Comments

1

Updating the original forms is pointless. What you want to do is a substitution in the components of CH.

rburing gravatar imagerburing ( 2019-06-25 21:06:04 +0100 )edit
1

Also note the variables g[(i,j,k)] are not functions of x, so the differential forms have constant coefficients in this frame. That means "compute with symbolic coefficients first, substitute later" doesn't work (in this way) if you're doing any computations involving derivatives. There seem to be no derivatives here though, so I guess it's fine.

rburing gravatar imagerburing ( 2019-06-25 21:29:44 +0100 )edit

2 Answers

Sort by ยป oldest newest most voted
1

answered 2019-06-25 21:44:03 +0100

rburing gravatar image

updated 2019-06-25 21:55:02 +0100

Here's how you can do substitution into the coefficients of a differential form, in a simple example:

sage: M = Manifold(2, 'M')
sage: U = M.open_subset('U')
sage: c_xy.<x,y> = U.chart()
sage: eU = c_xy.frame()
sage: f = M.diff_form(2)
sage: var('a,b')
sage: f[eU, 0, 1] = a+b
sage: f.display(eU)
(a + b) dx/\dy
sage: f[eU, 0, 1] = f[eU, 0, 1].expr().subs({a : x^2, b : y^2})
sage: f.display(eU)
(x^2 + y^2) dx/\dy
edit flag offensive delete link more
1

answered 2019-06-27 15:08:41 +0100

eric_g gravatar image

Once, CH has been computed, changing the values of the forms f[i] has no effect on CH, because they have gone from the expression of CH, which is made only in terms of the symbolic variables g_*, as pointed out by @rburing 's comment 1. What you want to do is a substitution in CH. As stressed in @rburing 's comment 2, substitution of symbolic variables will not work if the computation involves any derivative. You must use instead symbolic functions. Here is an example:

sage: M = Manifold(3, 'M')
sage: X.<x,y,z> = M.chart()
sage: f = M.diff_form(2)
sage: f[0,1] = function('F')(x,y,z)   # an unspecified function of (x,y,z)
sage: f[1,2] = function('G')(x,y,z)
sage: f.display()
F(x, y, z) dx/\dy + G(x, y, z) dy/\dz
sage: df = f.exterior_derivative()
sage: df.display()
(d(F)/dz + d(G)/dx) dx/\dy/\dz
sage: F0(x,y,z) = x*y*z   # a callable symbolic expression
sage: G0(x,y,z) = x^2
sage: df[0,1,2] = df[0,1,2].expr().substitute_function(F, F0)  # NB: substitute_function, not subs
sage: df[0,1,2] = df[0,1,2].expr().substitute_function(G, G0)
sage: df.display()
(x*y + 2*x) dx/\dy/\dz
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2019-06-25 18:45:38 +0100

Seen: 1,187 times

Last updated: Jun 27 '19