Search code examples
symbolic-mathtensorsage

Can I create "abstract" tensors in Sagemath?


I would like to, for example, take the exterior derivative of a one-form without specifying the coefficients. For example, if I have a one form

a = fdz + gdx + hdy

how can I calculate da in terms of f_x, f_y, etc. without telling Sage exactly what f,g, and h are?

I have tried looking in both differential forms and tensors sections of the Sage website but I didn't find anything.


Solution

  • Apparently this is somewhat possible, but maybe of limited (current utility).

    sage: U = Manifold(3, 'U')
    sage: X.<x,y,z> = U.chart()
    sage: f = U.diff_form(2, 'f')
    sage: f
    2-form f on the 3-dimensional differentiable manifold U
    sage: f.exterior_derivative()
    3-form df on the 3-dimensional differentiable manifold U
    

    So at least there are abstract ones. But

    sage: f.components()
    ...
    ValueError: no basis could be found for computing the components in the Coordinate frame (U, (d/dx,d/dy,d/dz))
    

    However, I think one can get around this by defining an abstract function of three variables. No guarantees on whether this is 100% accurate, because the relationship of the "chart" variables to the other symbolic variables out there is not clear to me - I have not used SageManifolds much.

    sage: pbi = function('pbi', nargs=3)(x,y,z); pbi
    pbi(x, y, z)
    sage: type(pbi)
    <type 'sage.symbolic.expression.Expression'>
    sage: f[0,1]=pbi
    sage: f
    2-form f on the 3-dimensional differentiable manifold U
    sage: f.components()
    Fully antisymmetric 2-indices components w.r.t. Coordinate frame (U, (d/dx,d/dy,d/dz))
    sage: f.display()
    f = pbi(x, y, z) dx/\dy
    sage: f.exterior_derivative()
    3-form df on the 3-dimensional differentiable manifold U
    sage: f.exterior_derivative().components()
    Fully antisymmetric 3-indices components w.r.t. Coordinate frame (U, (d/dx,d/dy,d/dz))
    sage: f.exterior_derivative().display()
    df = d(pbi)/dz dx/\dy/\dz
    sage: f[1,2]=pbi^2
    sage: f.exterior_derivative().display()
    df = (2*pbi(x, y, z)*d(pbi)/dx + d(pbi)/dz) dx/\dy/\dz
    

    If these calculations are what you would expect, then I guess you can use them. A quick surface glance says that at least the +/- seems correct.

    sage: g = U.diff_form(1, 'g')
    sage: g[:] = (pbi,pbi^2,pbi^3)
    sage: g.display()
    g = pbi(x, y, z) dx + pbi(x, y, z)^2 dy + pbi(x, y, z)^3 dz
    sage: g.exterior_derivative().display()
    dg = (2*pbi(x, y, z)*d(pbi)/dx - d(pbi)/dy) dx/\dy + (3*pbi(x, y, z)^2*d(pbi)/dx - d(pbi)/dz) dx/\dz + (3*pbi(x, y, z)^2*d(pbi)/dy - 2*pbi(x, y, z)*d(pbi)/dz) dy/\dz
    

    See here (but only the manifold version, the other is deprecated) for a lot more examples overall, in addition to the documentation you have already mentioned.