# Define a differential form recursively

I have the following code:

n=3;
x = list(var('x_%d' % i) for i in (1..2*n));
U = CoordinatePatch(x);
F = DifferentialForms(U);
w = DifferentialForm(F,2);
for j in range(2*n-1):
for k in range(2*n-1):
w[j,k]=j+k;
w;


It's supposed to define a differential form whose (j,k)th member is j+k, but this code just returns the 0 differential form. I've tried many variations using for, while, etc., but none seem to work. I suspect it's because a differential form is stored as a dictionary, but since I'm a beginner in Sage, I have no idea what to do. Any help is appreciated.

edit retag close merge delete

Sort by ยป oldest newest most voted

I seem to get something reasonable here, not the zero form.

??????????????????????????????????????????????????????????????????????
? Sage Version 5.12, Release Date: 2013-10-07                        ?
? Type "notebook()" for the browser-based notebook interface.        ?
? Type "help()" for help.                                            ?
??????????????????????????????????????????????????????????????????????
sage: n=3;
sage: x = list(var('x_%d' % i) for i in (1..2*n));
sage: U = CoordinatePatch(x);
sage: F = DifferentialForms(U);
sage: w = DifferentialForm(F,2);
sage:   for j in range(2*n-1):
....:          for k in range(2*n-1):
....:                 w[j,k]=j+k;
....:
sage: w
-1*dx_1/\dx_2 + -3*dx_2/\dx_3 + 0*dx_1/\dx_1 + 0*dx_4/\dx_4 + 0*dx_3/\dx_3 + 0*dx_5/\dx_5 + -5*dx_2/\dx_5 + -2*dx_1/\dx_3 + -4*dx_2/\dx_4 + -5*dx_3/\dx_4 + -4*dx_1/\dx_5 + -6*dx_3/\dx_5 + -3*dx_1/\dx_4 + -7*dx_4/\dx_5 + 0*dx_2/\dx_2


I will point out that perhaps you are using 1-based counting, but Python starts counting at 0. Is this what you are looking for?

sage: for j in range(2*n-1):
....:     for k in range(2*n-1):
....:         w[j,k] = j+1+k+1
....:
sage: w
-3*dx_1/\dx_2 + -5*dx_2/\dx_3 + 0*dx_1/\dx_1 + 0*dx_4/\dx_4 + 0*dx_3/\dx_3 + 0*dx_5/\dx_5 + -7*dx_2/\dx_5 + -4*dx_1/\dx_3 + -6*dx_2/\dx_4 + -7*dx_3/\dx_4 + -6*dx_1/\dx_5 + -8*dx_3/\dx_5 + -5*dx_1/\dx_4 + -9*dx_4/\dx_5 + 0*dx_2/\dx_2


I don't know whether the negatives are what you want or not, nor why the necessarily zero differentials are even included, but I've never used this functionality before, so you will have to peruse the documentation for technical points like this.

more