Physlib.Relativity.Tensors.Elab
53 declarations
Syntax Category for Tensor Indices
#quotA syntax category `indexExpr` for the indices of tensor expressions.
Syntax Category for Tensor Expression Indices
#indexExprA Lean syntax category `indexExpr` for representing the indices of tensor expressions.
Syntax for Basic Tensor Index Expression
#indexExpr_This defines the syntax rule specifying that a basic index expression is represented by an identifier.
Syntax for Numeric Tensor Index Expression
#indexExpr__1This defines the syntax rule specifying that an index expression can be a numeric literal, which is used to evaluate the tensor.
Syntax for Jiggled Tensor Index
#indexExprτ(_)This defines the syntax rule for the notation (where is an identifier) as an index expression, which is used to describe the jiggle of a tensor index.
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.
Numerical index expression check
#indexExprIsNumA boolean function that evaluates to `true` if the given syntax object `stx` represents a numerical index in a tensor expression, and `false` otherwise.
Evaluated bracket index expression check
#indexExprIsBracketEvalA 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.
Extract natural number from numeric index syntax
#indexToNumThis 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.
Extract Identifier from Tensor Index Syntax
#indexToIdentThis 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 from syntax patterns such as a plain , , or . If the provided syntax does not match any of these supported identifier expressions, it throws an error.
Matching positions of identical tensor indices
#indexPosEqThis function takes two pairs and , where represents the syntax of a tensor index expression (such as or ) and 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 (), it returns the pair of positions . Otherwise, it returns `none`. This logic is typically used during tensor elaboration to identify pairs of matching indices that should be contracted.
Check if Tensor Index Syntax is Dual
#indexToDualA 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 , indicating that the index is to be dualed, and false otherwise.
Adjusted Evaluation Positions
#evalAdjustPosA function that maps a list of natural numbers to a new list , where . 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.
Adjusted evaluation positions and values for numeric tensor indices
#getEvalPosGiven a list of tensor index expressions , let be the subsequence of consisting of numeric literals, where denotes the original position (0-indexed) of the expression in . Let be the numerical value of the expression . This function returns a list of pairs , where is the "adjusted position" defined as . 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 , the function identifies numeric values at positions (value ) and (value ), and returns the pairs .
Adjusted positions and terms of bracketed evaluation indices
#getEvalBracketPosGiven a list of tensor index expressions , the function identifies all indices of the form (referred to as bracketed evaluation indices). For each such index occurring at an original position in the list, it extracts the term and calculates an adjusted position . This adjusted position is defined as , where is the number of preceding indices in the list that are also bracketed evaluation indices. The function returns a list of pairs containing these adjusted positions and their corresponding terms.
Pairs of contracted index positions in a tensor expression
#getContrPosGiven a list of tensor index expressions , let be the sublist consisting of all symbolic indices, formed by removing numerical indices (e.g., ) and bracketed evaluation indices (e.g., ). This function identifies pairs of positions in such that and the index symbol at position is identical to the index symbol at position , corresponding to a contraction under the Einstein summation convention. The function returns a list of these position pairs . It also verifies that no position appears in more than one pair, ensuring that each index symbol appears at most twice in ; if an index symbol appears more than twice, the function throws an error.
Free indices of a tensor expression
#withoutContrEvalGiven a list of tensor index expressions , 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).
List to Pairs of Natural Numbers
#toPairsThe function maps a list of natural numbers to a list of pairs of natural numbers by grouping consecutive elements of together. Specifically, it transforms a list into . If the length of is odd, the last element of the list is paired with to form the final pair .
Contraction List Adjustment
#contrListAdjustThe function maps a list of pairs of natural numbers 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.
Permutation of index lists and
#getPermutationGiven two lists of tensor index expressions and , where each expression represents an identifier (such as or ), this function computes the permutation that transforms into . Specifically, it returns a list of natural numbers such that the -th element of corresponds to the -th element of . The computation is performed within the `TermElabM` monad.
String to term
#stringToTermA function that constructs a term expression corresponding to a given string once parsed within the term elaboration monad.
Syntax term for the permutation of index lists
#getPermutationTermGiven two lists of tensor index expressions and , this function identifies the permutation that maps the elements of to those of . It returns a Lean syntax term representing an array literal , where each is the natural number index in corresponding to the -th element in . 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.
Tensor Expression Quotation Parser
#quotDefines the quotation parser description for the syntax category `tensorExpr`, which is used for parsing tensor expressions.
Tensor Expression Syntax Category
#tensorExprDefines the syntax category `tensorExpr` for parsing tensor expressions.
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.
Tensor Expression Equality Syntax
#tensorExpr_=_Defines the parsing syntax for the equality of two tensor expressions, denoted by `=`.
Tensor Expression Tensor Product Syntax
#tensorExpr_⊗_Defines the parsing syntax for the tensor product of two tensor expressions, denoted by .
Tensor Expression Addition Syntax
#tensorExpr_+_Defines the parsing syntax for the addition of two tensor expressions, denoted by .
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.
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 `•ₜ`.
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 `•ₐ`.
Negation Syntax for Tensor Expressions
#tensorExpr-_This is a parser descriptor defining the syntax for the negation of a tensor expression, using the notation `-`.
Exact Number of Indices of a Tensor Syntax
#getNumIndicesExactFor a given syntax `stx` representing a tensor of the form `S.F.obj (OverColor.mk c)`, this function evaluates and returns the exact number of indices associated with . The result is a natural number returned within the `TermElabM` monad.
Extraction of All Indices from Tensor Syntax
#getAllIndicesFor 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 , it returns the list containing all the `indexExpr` elements.
Extraction of Uncontracted and Unevaluated Indices from Tensor Product Syntax
#getProdIndicesThe 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., , it returns all uncontracted and unevaluated indices, such as . 2. For a tensor product, e.g., , it returns all unevaluated indices which are not contracted in either tensor, such as . 3. For nested tensor products, e.g., , it evaluates the indices recursively, such as .
Extraction of Remaining Indices from Tensor Expression Syntax
#getIndicesFullThe 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. gives 2. gives 3. gives 4. gives
Extraction of Indices from the Left Summand in Tensor Addition
#getIndicesLeftThe function `getIndicesLeft` evaluates the syntax `stx` of a tensor addition expression, typically of the form . It extracts and returns the list of uncontracted and unevaluated indices of the left-hand summand by calling `getIndicesFull`. If the provided syntax does not match an addition pattern, the function throws an error.
Extraction of indices from the RHS of a tensor addition
#getIndicesRightGiven a syntax object representing the sum of two tensor expressions , this function extracts the list of free indices associated with the right-hand summand . The function specifically processes the syntax tree to isolate and then identifies all unique identifier indices that remain after any internal contractions or constant evaluations have been performed within that expression.
Free indices of the left-hand side of a tensor equation
#getIndicesLeftEqThe function `getIndicesLeftEq` takes a syntax term representing a tensor equality of the form and returns a list of the free indices associated with the left-hand side expression . These free indices are the identifiers that remain after all internal contractions and evaluations within the expression have been performed.
Extraction of Free Indices from the Right-Hand Side of
#getIndicesRightEqGiven a syntax object representing a tensor equality of the form , this function extracts the list of free indices from the right-hand side expression . These free indices are those that remain after all internal contractions and evaluations within 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.
Node term map
#nodeTermMapFor a syntax term representing a tensor of type `S.F.obj (OverColor.mk c)`, this function returns the syntax term corresponding to the tensor node of .
Evaluation term map for tensor trees
#evalTermMapGiven a list of pairs and a term corresponding to a tensor tree, this function returns a new term by recursively applying the evaluation operation to for each pair in . Here, is the position of the index to be evaluated, and is the value it is evaluated to.
Evaluation Bracket Term Map for Tensor Trees
#evalTermBracketMapGiven a list of pairs and a syntax term corresponding to a tensor tree, this function returns a new syntax term by recursively applying the evaluation operation to for each pair in . Here, is the position of the index to be evaluated, and is the term it is evaluated to from the bracket syntax. For example, if and is a tensor tree, the result represents the term `TensorTree.eval 1 ν (TensorTree.eval 1 μ T)`.
Contraction term map for tensor expressions
#contrTermMapThe function `contrTermMap` generates a syntax term representing the repeated contraction of a tensor term . Given a natural number , a list of pairs of indices , and a term (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 for each pair in the adjusted list.
Syntax for product of tensors
#prodTermMapA function that constructs the syntax associated with the product of tensors. It maps two syntax terms and to the term representing their product, typically denoted as .
Syntax for tensor negation
#negTermMapA function that constructs the syntax associated with the negation of tensors. It maps a syntax term to the term representing its negation .
Syntax for Tensor Scalar Multiplication
#smulTermMapA function that constructs the syntax associated with the scalar multiplication of tensors. It maps a syntax term representing a scalar and a syntax term representing a tensor to the syntax term representing their scalar multiplication .
Syntax for Tensor Group Action
#actionTermMapA function that constructs the syntax associated with the group action of tensors. It maps a syntax term representing a group element and a syntax term representing a tensor to the syntax term representing the group action of on .
Term Map for Tensor Tree Addition
#addTermMapThe function takes a permutation term and two tensor tree terms and , and constructs the syntax term representing the addition of and the permutation of by , effectively computing . 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.
Syntax for Equality of Tensor Trees
#equalTermMapThis function constructs the syntax for an equality of tensor trees. Given syntax terms , , and , it returns the syntax term representing the equality , where acts as a permutation on the indices of .
Tensor Expression Syntax to Tensor Tree Term
#syntaxFullThe function `syntaxFull` takes a syntax `stx` corresponding to a tensor expression and turns it into a term corresponding to a tensor tree.
Elaboration of Tensor Expression Syntax to Tensor Tree `Expr`
#elaborateTensorNodeGiven a syntax input `stx` representing a tensor expression (for instance, ), 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.
Tensor Expression Syntax
#tensorExprSyntaxThe syntax `{E}ᵀ` denotes the tensor tree corresponding to the tensor expression .
