Metric Tensor and Derivatives of Basis Vectors.


class galgebra.metric.Metric(basis, *, g=None, coords=None, X=None, norm=False, debug=False, gsym=None, sig='e', Isq='-')[source]

Metric specification


metric tensor

Type:sympy matrix[,]

inverse of metric tensor

Type:sympy matrix[,]

normalized diagonal metric tensor

Type:list of sympy numbers

coordinate variables

Type:list[] of sympy symbols

True if basis is orthogonal


True if connection is non-zero


basis vector symbols

Type:list[] of non-commutative sympy variables

reciprocal basis vector symbols

Type:list[] of non-commutative sympy variables

dimension of vector space/manifold


list of basis indices


derivatives of basis functions. Two dimensional list. First entry is differentiating coordiate. Second entry is basis vector. Quantities are linear combinations of basis vector symbols.


Signature of metric (p,q) where n = p+q. If metric tensor is numerical and orthogonal it is calculated. Otherwise the following inputs are used:

Input Signature Type
"e" (n,0) Euclidean
"m+" (n-1,1) Minkowski (One negative square)
"m-" (1,n-1) Minkowski (One positive square)
p (p,n-p) General (integer not string input)
Type:Tuple[int, int]

String for symbolic metric determinant. If self.gsym = ‘g’ then det(g) is sympy scalar function of coordinates with name ‘det(g)’. Useful for complex non-orthogonal coordinate systems or for calculations with general metric.

  • basis – string specification
  • g – metric tensor
  • coords – manifold/vector space coordinate list/tuple (sympy symbols)
  • X – vector manifold function
  • norm – True to normalize basis vectors
  • debug – True to print out debugging information
  • gsym – String s to use "det("+s+")" function in reciprocal basis
  • sig – Signature of metric, default is (n,0) a Euclidean metric
  • Isq – Sign of square of pseudo-scalar, default is ‘-‘

mode = 1 Christoffel symbols of the first kind mode = 2 Christoffel symbols of the second kind

Isq = None

Sign of I**2, only needed if I**2 not a number

detg = None

Determinant of g

static dot_orthogonal(V1, V2, g=None)[source]

Returns the dot product of two vectors in an orthogonal coordinate system. V1 and V2 are lists of sympy expressions. g is a list of constants that gives the signature of the vector space to allow for non-euclidian vector spaces.

This function is only used to form the dot product of vectors in the embedding space of a vector manifold or in the case where the basis vectors are explicitly defined by vector fields in the embedding space.

A g of None is for a Euclidian embedding space.

g_adj = None

Adjugate of g

g_inv = None

Inverse of g


rows of metric tensor are separated by “,” and elements of each row separated by ” “. If the input is a single row it is assummed that the metric tensor is diagonal.

Output is a square matrix.

galgebra.metric.collect(A, nc_list)[source]
  • A – a linear combination of noncommutative symbols with scalar expressions as coefficients
  • nc_list – noncommutative symbols in A to combine

A sum of the terms containing the noncommutative symbols in nc_list such that no elements of nc_list appear more than once in the sum. All coefficients of a given element of nc_list are combined into a single coefficient.

Return type:



If expression is product of even powers then every power is divided by two and the product is returned. If some terms in product are not even powers the sqrt of the absolute value of the expression is returned. If the expression is a number the sqrt of the absolute value of the number is returned.

galgebra.metric.symbols_list(s, indices=None, sub=True, commutative=False)[source]

Convert a string to a list of symbols.

If galgebra.printer.Eprint is enabled, the symbol names will contain ANSI escape sequences.

  • s (str) –

    Specification. If indices is specified, then this is just a prefix. If indices is not specified then this is a string of one of the forms:

    • prefix + "*" + index_1 + "|" + index_2 + "|" + ... + index_n
    • prefix + "*" + n_indices
    • name_1 + "," + name_2 + "," + ... + name_n
    • name_1 + " " + name_2 + " " + ... + name_n
  • indices (list, optional) – List of indices to append to the prefix.
  • sub (bool) – If true, mark as subscript separating prefix and suffix with _, else mark as superscript using __.
  • commutative (bool) – Passed on to sympy.Symbol.


Return type:

list of sympy.Symbol


Names can be comma or space separated:

>>> symbols_list('a,b,c')
[a, b, c]
>>> symbols_list('a b c')
[a, b, c]

Mixing commas and spaces gives surprising results:

>>> symbols_list('a b,c')
[a b, c]

Subscripts will be converted to superscripts if requested:

>>> symbols_list('a_1 a_2', sub=False)
[a__1, a__2]
>>> symbols_list('a__1 a__2', sub=False)
[a___1, a___2]

But not vice versa:

>>> symbols_list('a__1 a__2', sub=True)
[a__1, a__2]

Asterisk can be used for repetition:

>>> symbols_list('a*b|c|d')
[a_b, a_c, a_d]
>>> symbols_list('a*3')
[a_0, a_1, a_2]
>>> symbols_list('a*3')
[a_0, a_1, a_2]

Or the indices argument:

>>> symbols_list('a', [2, 4, 6])
[a_2, a_4, a_6]
>>> symbols_list('a', [2, 4, 6], sub=False)
[a__2, a__4, a__6]

See also

a similar function builtin to sympy