Ask Your Question
0

Substituting symbolic expressions for mixed differential forms.

asked 2019-08-05 17:29:55 +0200

sum8tion gravatar image

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?

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
1

answered 2019-08-05 23:22:45 +0200

rburing gravatar image

There is a problem with your approach because the $c_i$ commute while $D_i$ anticommute.

After your definition of D, you can use noncommutative polynomials instead:

A = FreeAlgebra(SR, 2, names='c_')
c = A.gens()
exp = 0
for i in range(q):
    for j in range(q):
        exp = exp + c[i]*c[j]
print exp
print exp.subs({c[i] : D[i] for i in range(q)}).display(eU)

Output:

c_0^2 + c_0*c_1 + c_1*c_0 + c_1^2
[0] + [0] + [0] + [0] + [0]

The result is zero due to anticommutativity.

edit flag offensive delete link more

Comments

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?

sum8tion gravatar imagesum8tion ( 2019-08-06 16:53:48 +0200 )edit

You can do something like this:

indices = [(i,j) for i in range(q) for j in range(q)]
c_names = ['c_{}_{}'.format(i,j) for (i,j) in indices]
A = FreeAlgebra(SR, names=c_names)
c = dict(zip(indices, A.gens()))

Then c[0,0] is the generator c_0_0 of A.

rburing gravatar imagerburing ( 2019-08-06 17:03:16 +0200 )edit

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-08-05 17:29:55 +0200

Seen: 348 times

Last updated: Aug 05 '19