galgebra.metric

Metric Tensor and Derivatives of Basis Vectors.

Members

galgebra.metric.linear_expand(expr)[source]

linear_expand takes an expression that is the sum of a scalar expression and a linear combination of noncommutative terms with scalar coefficients and generates lists of coefficients and noncommutative symbols the coefficients multiply. The list of noncommutatives symbols contains the scalar 1 if there is a scalar term in the sum and also does not contain any repeated noncommutative symbols.

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

  • nc_list – noncommutative symbols in A to combine

Returns

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

sympy.Basic

galgebra.metric.square_root_of_expr(expr)[source]

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.

Parameters
  • 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.

Returns

symbols

Return type

list of sympy.Symbol

Examples

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]

A trailing comma is allowed, and required to generate lists of one element:

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

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

sympy.symbols()

a similar function builtin to sympy

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

Bases: object

Metric specification

g

metric tensor

Type

sympy matrix[,]

norm

normalized diagonal metric tensor

Type

list of sympy numbers

coords

coordinate variables

Type

list[] of sympy symbols

is_ortho

True if basis is orthogonal

Type

bool

basis

basis vector symbols

Type

list[] of non-commutative sympy variables

r_symbols

reciprocal basis vector symbols

Type

list[] of non-commutative sympy variables

n

dimension of vector space/manifold

Type

integer

n_range

list of basis indices

de

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.

Type

list[][]

sig

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]

gsym

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.

Type

str

Parameters
  • 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 ‘-‘

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.

metric_symbols_list(s=None)[source]

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.

connect_flg: bool

True if connection is non-zero

g_adj: sympy.matrices.dense.MutableDenseMatrix

Adjugate of g

Christoffel_symbols(mode=1)[source]

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

detg: sympy.core.expr.Expr

Determinant of \(g\), \(\det g\)

Isq

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

g_inv: sympy.matrices.dense.MutableDenseMatrix

Inverse of metric tensor g