PhyslibSearch

Physlib.Relativity.Tensors.Elab

53 declarations

definition

Syntax Category for Tensor Indices

#quot

A syntax category `indexExpr` for the indices of tensor expressions.

definition

Syntax Category for Tensor Expression Indices

#indexExpr

A Lean syntax category `indexExpr` for representing the indices of tensor expressions.

definition

Syntax for Basic Tensor Index Expression

#indexExpr_

This defines the syntax rule specifying that a basic index expression is represented by an identifier.

definition

Syntax for Numeric Tensor Index Expression

#indexExpr__1

This defines the syntax rule specifying that an index expression can be a numeric literal, which is used to evaluate the tensor.

definition

Syntax for Jiggled Tensor Index

#indexExprτ(_)

This defines the syntax rule for the notation τ(x)\tau(x) (where xx is an identifier) as an index expression, which is used to describe the jiggle of a tensor index.

definition

Syntax for Tensor Index Evaluation

#indexExpr[_]

The syntax notation `[x]`, where `x` is an identifier, is defined as an index expression. It provides a notation to describe the evaluation of a tensor index.

definition

Numerical index expression check

#indexExprIsNum

A boolean function that evaluates to `true` if the given syntax object `stx` represents a numerical index in a tensor expression, and `false` otherwise.

definition

Evaluated bracket index expression check

#indexExprIsBracketEval

A boolean function that evaluates to `true` if the given syntax object `stx` represents an evaluated bracket index in a tensor expression, such as `[μ]`, and `false` otherwise.

definition

Extract natural number from numeric index syntax

#indexToNum

This function takes a syntax object representing a tensor index expression and extracts the underlying natural number if the index is a numeric literal. If the provided syntax does not represent a natural number, it throws an error.

definition

Extract Identifier from Tensor Index Syntax

#indexToIdent

This function takes a syntax object representing a tensor index expression and extracts the corresponding identifier when the index is not a numeric literal. Specifically, it can extract the identifier aa from syntax patterns such as a plain aa, τ(a)\tau(a), or [a][a]. If the provided syntax does not match any of these supported identifier expressions, it throws an error.

definition

Matching positions (pa,pb)(p_a, p_b) of identical tensor indices

#indexPosEq

This function takes two pairs a=(sa,pa)a = (s_a, p_a) and b=(sb,pb)b = (s_b, p_b), where ss represents the syntax of a tensor index expression (such as μ\mu or τ(μ)\tau(\mu)) and pNp \in \mathbb{N} represents its position. The function extracts the identifiers from both syntax objects; if the identifiers are identical and the position of the first index is strictly less than the position of the second (pa<pbp_a < p_b), it returns the pair of positions (pa,pb)(p_a, p_b). Otherwise, it returns `none`. This logic is typically used during tensor elaboration to identify pairs of matching indices that should be contracted.

definition

Check if Tensor Index Syntax is Dual

#indexToDual

A function that maps a syntax object representing a tensor index expression to a boolean value. It evaluates to true if the index is of the form τ(i)\tau(i), indicating that the index is to be dualed, and false otherwise.

definition

Adjusted Evaluation Positions

#evalAdjustPos

A function that maps a list of natural numbers (x1,,xn)(x_1, \dots, x_n) to a new list (y1,,yn)(y_1, \dots, y_n), where yi=xi{j<ixj<xi}y_i = x_i - |\{ j < i \mid x_j < x_i \}|. It adjusts the sequence by subtracting from each natural number the number of preceding elements in the list that are strictly less than itself. This is used to form a list of pairs which can be used for evaluating indices.

definition

Adjusted evaluation positions and values (p,v)(p, v) for numeric tensor indices

#getEvalPos

Given a list of tensor index expressions LL, let (ei1,ei2,,eik)(e_{i_1}, e_{i_2}, \dots, e_{i_k}) be the subsequence of LL consisting of numeric literals, where iji_j denotes the original position (0-indexed) of the expression in LL. Let vjv_j be the numerical value of the expression eije_{i_j}. This function returns a list of pairs ((p1,v1),(p2,v2),,(pk,vk))((p_1, v_1), (p_2, v_2), \dots, (p_k, v_k)), where pjp_j is the "adjusted position" defined as pj=ij(j1)p_j = i_j - (j - 1). This adjusted position represents the index of the numerical value in the list if all preceding numerical indices were sequentially removed. For example, given the index list [α,3,β,2,γ][\alpha, 3, \beta, 2, \gamma], the function identifies numeric values at positions i1=1i_1=1 (value v1=3v_1=3) and i2=3i_2=3 (value v2=2v_2=2), and returns the pairs [(1,3),(2,2)][(1, 3), (2, 2)].

definition

Adjusted positions and terms of bracketed evaluation indices [x][x]

#getEvalBracketPos

Given a list of tensor index expressions I=(e0,e1,,en)I = (e_0, e_1, \dots, e_n), the function identifies all indices of the form [x][x] (referred to as bracketed evaluation indices). For each such index occurring at an original position ii in the list, it extracts the term xx and calculates an adjusted position ii'. This adjusted position is defined as i=iki' = i - k, where kk is the number of preceding indices in the list II that are also bracketed evaluation indices. The function returns a list of pairs (i,x)(i', x) containing these adjusted positions and their corresponding terms.

definition

Pairs of contracted index positions (a,b)(a, b) in a tensor expression

#getContrPos

Given a list of tensor index expressions II, let II' be the sublist consisting of all symbolic indices, formed by removing numerical indices (e.g., 33) and bracketed evaluation indices (e.g., [x][x]). This function identifies pairs of positions (a,b)(a, b) in II' such that a<ba < b and the index symbol at position aa is identical to the index symbol at position bb, corresponding to a contraction under the Einstein summation convention. The function returns a list of these position pairs [(a1,b1),(a2,b2),][(a_1, b_1), (a_2, b_2), \dots]. It also verifies that no position appears in more than one pair, ensuring that each index symbol appears at most twice in II'; if an index symbol appears more than twice, the function throws an error.

definition

Free indices of a tensor expression

#withoutContrEval

Given a list of tensor index expressions II, the function `withoutContrEval` returns the sublist consisting of the "free" indices. This is achieved by first removing all numerical indices (which denote evaluation at a specific coordinate) and then removing any index that appears more than once in the remaining list (which denotes a contraction according to the Einstein summation convention).

definition

List to Pairs of Natural Numbers

#toPairs

The function maps a list of natural numbers ll to a list of pairs of natural numbers by grouping consecutive elements of ll together. Specifically, it transforms a list [x1,x2,x3,x4,][x_1, x_2, x_3, x_4, \dots] into [(x1,x2),(x3,x4),][(x_1, x_2), (x_3, x_4), \dots]. If the length of ll is odd, the last element xx of the list is paired with 00 to form the final pair (x,0)(x, 0).

definition

Contraction List Adjustment

#contrListAdjust

The function maps a list of pairs of natural numbers ll to a new list of pairs of natural numbers. It adjusts the list by subtracting from each natural number the number of elements before it in the list which are strictly less than itself. This is used to form a list of pairs which can be used for contracting tensor indices.

definition

Permutation of index lists l1l_1 and l2l_2

#getPermutation

Given two lists of tensor index expressions l1l_1 and l2l_2, where each expression represents an identifier (such as μ\mu or ν\nu), this function computes the permutation that transforms l1l_1 into l2l_2. Specifically, it returns a list of natural numbers [p0,p1,,pn][p_0, p_1, \dots, p_n] such that the ii-th element of l2l_2 corresponds to the pip_i-th element of l1l_1. The computation is performed within the `TermElabM` monad.

definition

String to term

#stringToTerm

A function that constructs a term expression corresponding to a given string once parsed within the term elaboration monad.

definition

Syntax term for the permutation of index lists l1l2l_1 \to l_2

#getPermutationTerm

Given two lists of tensor index expressions l1l_1 and l2l_2, this function identifies the permutation that maps the elements of l1l_1 to those of l2l_2. It returns a Lean syntax term representing an array literal ![p0,p1,,pn]![p_0, p_1, \dots, p_n], where each pip_i is the natural number index in l1l_1 corresponding to the ii-th element in l2l_2. This term is typically used to construct equivalence mappings for tensor indices (such as `finMapToEquiv`) during the elaboration of tensor expressions. The function operates within the `TermElabM` monad.

definition

Tensor Expression Quotation Parser

#quot

Defines the quotation parser description for the syntax category `tensorExpr`, which is used for parsing tensor expressions.

definition

Tensor Expression Syntax Category

#tensorExpr

Defines the syntax category `tensorExpr` for parsing tensor expressions.

definition

Tensor Node Syntax

#tensorExpr_|__

Defines the parsing syntax for a tensor node, consisting of a tensor term followed by a vertical bar `|` and a sequence of index expressions.

definition

Tensor Expression Equality Syntax

#tensorExpr_=_

Defines the parsing syntax for the equality of two tensor expressions, denoted by `=`.

definition

Tensor Expression Tensor Product Syntax

#tensorExpr_⊗_

Defines the parsing syntax for the tensor product of two tensor expressions, denoted by \otimes.

definition

Tensor Expression Addition Syntax

#tensorExpr_+_

Defines the parsing syntax for the addition of two tensor expressions, denoted by ++.

definition

Parentheses Syntax for Tensor Expressions

#tensorExpr(_)

This is a parser descriptor defining the syntax for using parentheses `(...)` in tensor expressions. It allows brackets to be used to group subexpressions within a tensor expression.

definition

Scalar Multiplication Syntax for Tensor Expressions

#tensorExpr_•ₜ_

This is a parser descriptor defining the syntax for the scalar multiplication of a tensor expression, using the notation `•ₜ`.

definition

Group Action Syntax for Tensor Expressions

#tensorExpr_•ₐ_

This is a parser descriptor defining the syntax for the group action on tensor expressions, using the notation `•ₐ`.

definition

Negation Syntax for Tensor Expressions

#tensorExpr-_

This is a parser descriptor defining the syntax for the negation of a tensor expression, using the notation `-`.

definition

Exact Number of Indices of a Tensor Syntax

#getNumIndicesExact

For a given syntax `stx` representing a tensor TT of the form `S.F.obj (OverColor.mk c)`, this function evaluates and returns the exact number of indices associated with TT. The result is a natural number returned within the `TermElabM` monad.

definition

Extraction of All Indices from Tensor Syntax

#getAllIndices

For a given syntax `stx` representing a tensor expression, this function evaluates and returns a list of all its index expressions within the `TermElabM` monad. For instance, given a syntax of the form Tαβ2βT \mid \alpha \, \beta \, 2 \, \beta, it returns the list [α,β,2,β][\alpha, \beta, 2, \beta] containing all the `indexExpr` elements.

definition

Extraction of Uncontracted and Unevaluated Indices from Tensor Product Syntax

#getProdIndices

The function `getProdIndices` evaluates the syntax `stx` of a tensor expression and returns a list of all uncontracted and unevaluated indices. Specifically, it operates on the syntax as follows: 1. For a single tensor expression, e.g., Tαβ2βT \mid \alpha \beta 2 \beta, it returns all uncontracted and unevaluated indices, such as [α][\alpha]. 2. For a tensor product, e.g., T1αβ2βT2αγδδT_1 \mid \alpha \beta 2 \beta \otimes T_2 \mid \alpha \gamma \delta \delta, it returns all unevaluated indices which are not contracted in either tensor, such as [α,α,γ][\alpha, \alpha, \gamma]. 3. For nested tensor products, e.g., (T1αβ2βT2αγδδ)T3γ(T_1 \mid \alpha \beta 2 \beta \otimes T_2 \mid \alpha \gamma \delta \delta) \otimes T_3 \mid \gamma, it evaluates the indices recursively, such as [γ,γ][\gamma, \gamma].

definition

Extraction of Remaining Indices from Tensor Expression Syntax

#getIndicesFull

The function `getIndicesFull` evaluates the syntax `stx` of a tensor expression and returns a list of the remaining indices after contraction and evaluation. Thus, every index in the output is an identifier and there are no duplicates. Examples of its operation are as follows: 1. Tαβ2βT \mid \alpha \beta 2 \beta gives [α][\alpha] 2. T1αβ2βT2αγδδT_1 \mid \alpha \beta 2 \beta \otimes T_2 \mid \alpha \gamma \delta \delta gives [γ][\gamma] 3. (T1αβ2βT2αγδδ)T3γ(T_1 \mid \alpha \beta 2 \beta \otimes T_2 \mid \alpha \gamma \delta \delta) \otimes T_3 \mid \gamma gives [][] 4. T1αβ2β+T2α4δδT_1 \mid \alpha \beta 2 \beta + T_2 \mid \alpha 4 \delta \delta gives [α][\alpha]

definition

Extraction of Indices from the Left Summand in Tensor Addition

#getIndicesLeft

The function `getIndicesLeft` evaluates the syntax `stx` of a tensor addition expression, typically of the form A+BA + B. It extracts and returns the list of uncontracted and unevaluated indices of the left-hand summand AA by calling `getIndicesFull`. If the provided syntax does not match an addition pattern, the function throws an error.

definition

Extraction of indices from the RHS of a tensor addition

#getIndicesRight

Given a syntax object representing the sum of two tensor expressions A+BA + B, this function extracts the list of free indices associated with the right-hand summand BB. The function specifically processes the syntax tree to isolate BB and then identifies all unique identifier indices that remain after any internal contractions or constant evaluations have been performed within that expression.

definition

Free indices of the left-hand side of a tensor equation A=BA = B

#getIndicesLeftEq

The function `getIndicesLeftEq` takes a syntax term representing a tensor equality of the form A=BA = B and returns a list of the free indices associated with the left-hand side expression AA. These free indices are the identifiers that remain after all internal contractions and evaluations within the expression AA have been performed.

definition

Extraction of Free Indices from the Right-Hand Side of T1=T2T_1 = T_2

#getIndicesRightEq

Given a syntax object representing a tensor equality of the form T1=T2T_1 = T_2, this function extracts the list of free indices from the right-hand side expression T2T_2. These free indices are those that remain after all internal contractions and evaluations within T2T_2 have been performed (as determined by the `getIndicesFull` function). If the provided syntax does not match the pattern of an equality, the function returns an error.

definition

Node term map

#nodeTermMap

For a syntax term TT representing a tensor of type `S.F.obj (OverColor.mk c)`, this function returns the syntax term corresponding to the tensor node of TT.

definition

Evaluation term map for tensor trees

#evalTermMap

Given a list ll of pairs (a,b)N×N(a, b) \in \mathbb{N} \times \mathbb{N} and a term TT corresponding to a tensor tree, this function returns a new term by recursively applying the evaluation operation to TT for each pair in ll. Here, aa is the position of the index to be evaluated, and bb is the value it is evaluated to.

definition

Evaluation Bracket Term Map for Tensor Trees

#evalTermBracketMap

Given a list ll of pairs (a,b)N×Term(a, b) \in \mathbb{N} \times \text{Term} and a syntax term TT corresponding to a tensor tree, this function returns a new syntax term by recursively applying the evaluation operation to TT for each pair in ll. Here, aa is the position of the index to be evaluated, and bb is the term it is evaluated to from the bracket syntax. For example, if l=[(1,μ),(1,ν)]l = [(1, \mu), (1, \nu)] and TT is a tensor tree, the result represents the term `TensorTree.eval 1 ν (TensorTree.eval 1 μ T)`.

definition

Contraction term map for tensor expressions

#contrTermMap

The function `contrTermMap` generates a syntax term representing the repeated contraction of a tensor term TT. Given a natural number nn, a list of pairs of indices l=[(i1,j1),(i2,j2),]l = [(i_1, j_1), (i_2, j_2), \dots], and a term TT (representing a tensor tree), the function first adjusts the indices using `contrListAdjust` to account for the reduction in the number of available indices after each successive contraction. It then constructs a new term by iteratively applying the contraction operator `Tensor.contrT` to TT for each pair in the adjusted list.

definition

Syntax for product of tensors

#prodTermMap

A function that constructs the syntax associated with the product of tensors. It maps two syntax terms T1T_1 and T2T_2 to the term representing their product, typically denoted as T1T2T_1 \otimes T_2.

definition

Syntax for tensor negation

#negTermMap

A function that constructs the syntax associated with the negation of tensors. It maps a syntax term T1T_1 to the term representing its negation T1-T_1.

definition

Syntax for Tensor Scalar Multiplication

#smulTermMap

A function that constructs the syntax associated with the scalar multiplication of tensors. It maps a syntax term cc representing a scalar and a syntax term TT representing a tensor to the syntax term representing their scalar multiplication cTc \cdot T.

definition

Syntax for Tensor Group Action

#actionTermMap

A function that constructs the syntax associated with the group action of tensors. It maps a syntax term cc representing a group element and a syntax term TT representing a tensor to the syntax term representing the group action of cc on TT.

definition

Term Map for Tensor Tree Addition

#addTermMap

The function takes a permutation term PP and two tensor tree terms T1T_1 and T2T_2, and constructs the syntax term representing the addition of T1T_1 and the permutation of T2T_2 by PP, effectively computing T1+P(T2)T_1 + P(T_2). It is used to elaborate the syntax for an addition of tensor trees where the indices of the second tensor are permuted to match the first.

definition

Syntax for Equality of Tensor Trees

#equalTermMap

This function constructs the syntax for an equality of tensor trees. Given syntax terms PP, T1T_1, and T2T_2, it returns the syntax term representing the equality T1=P(T2)T_1 = P(T_2), where PP acts as a permutation on the indices of T2T_2.

definition

Tensor Expression Syntax to Tensor Tree Term

#syntaxFull

The function `syntaxFull` takes a syntax `stx` corresponding to a tensor expression and turns it into a term corresponding to a tensor tree.

definition

Elaboration of Tensor Expression Syntax to Tensor Tree `Expr`

#elaborateTensorNode

Given a syntax input `stx` representing a tensor expression (for instance, {Tμν}T\{T \mid \mu \nu\}^T), this function elaborates it into a Lean expression `Expr` that represents the underlying tensor tree structure. This process transforms the high-level index notation into a formal representation of tensor operations such as contractions, permutations, and products.

definition

Tensor Expression Syntax

#tensorExprSyntax

The syntax `{E}ᵀ` denotes the tensor tree corresponding to the tensor expression EE.