(******************************************************************* This file was generated automatically by the Mathematica front end. It contains Initialization cells from a Notebook file, which typically will have the same name as this file except ending in ".nb" instead of ".m". This file is intended to be loaded into the Mathematica kernel using the package loading commands Get or Needs. Doing so is equivalent to using the Evaluate Initialization Cells menu command in the front end. DO NOT EDIT THIS FILE. This entire file is regenerated automatically each time the parent Notebook file is saved in the Mathematica front end. Any changes you make to this file will be overwritten. ***********************************************************************) (* TContinuumMechanics version 2.1 is a Mathematica package that needs the \ package Tensorial 4.0 *) (* Author: Jean-Fran\[CCedilla]ois Gouyet *) (* jean-francois.gouyet@aliceadsl.fr *) (* This software package and its accompanying documentation are provided \ without guarantee of support or maintenance *) (* Mathematica is a registered trademark of Wolfram Research, Inc. *) BeginPackage["TContinuumMechanics21`TContinuumMechanics`",{"Graphics`Colors`", "TensorCalculus4`Tensorial`"}] HoldFactor::usage="HoldFactor[term][expr] allows a formula presentation of expr in which a given term in expr is put in factor in an HoldForm to prevent unexpected simplification."; PartialSumHold::usage="PartialSumHold[baseindex, newindices][expr] will expand dummy summations of a tensor expression into components that have one or more baseindex and unexpanded remainders, as PartialSum does. But now it will act on HoldForms in such a way that this HoldForm be preserved."; ToFlavorD::usage="ToFlavorD[toflavor, fromflavor][expr] will convert expressions containg covariant derivatives in hold forms, HoldCovariantD[Tensors,{...}] in expr to the specified (toflavor) flavor of indices from fromflavor. fromflavor is an optional argument with the value Automatic. Black corresponds to indices with default flavor."; HoldCovariantD::usage="HoldCovariantD[expr, i] represents the unexpanded covariant derivative of expr with respect to the index i.\n HoldCovariantD[expr,{i,j,...}] represents the covariant unexpanded derivative with respect to the list of indices. \n Symbols are considered constants."; HoldCovariantD2d::usage="HoldCovariantD2d[expr, i] represents the 2-dimensional unexpanded covariant derivative of expr with respect to the index i.\n HoldCovariantD2d[expr,{i,j,...}] represents the 2-dimensional covariant unexpanded derivative with respect to the list of indices. \n Symbols are considered constants."; HoldContravariantD::usage="HoldContravariantD[tensor, i] represents the unexpanded contravariant derivative of the tensor with respect to the index i.\n HoldContravariantD[tensor,{i,j,...}] represents the contravariant unexpanded derivative with respect to the list of indices. \n Symbols are considered constants."; HoldContravariantD2d::usage="HoldContravariantD2d[tensor, i] represents the 2-dimensional unexpanded contravariant derivative of the tensor with respect to the index i.\n HoldContravariantD2d[tensor,{i,j,...}] represents the 2-dimensional contravariant unexpanded derivative with repect to the list of indices. \n Symbols are considered constants."; BasisChange::usage= "BasisChange[\[Beta],toflavor][Tensor[T,list1,list2]] allows to perform the change via the transformation \[Beta], of an arbitrary tensor T in an initial flavor,to the final flavor 'toflavor'."; BasisDerivation::usage= "BasisDerivation[m][{\[DoubleStruckE],i},j][expr] expresses the partial derivative with respect to index j, of a basis vector Tensor[\[DoubleStruckE],{Void},{i}] present in expr, into a combination of basis vectors. The coefficients are Christoffel symbols; m is a dummy index. The parameters are defined in labels ={x, \[Delta], g, \[CapitalGamma]}. This function includes the assignement to zero of the covariant derivative of basis vectors. BasisDerivation[h,m][{\[DoubleStruckE],i},{j,k}][expr] do the same kind of expansion for second partial derivatives. It includes the assignement to zero of the covariant derivatives of basis vectors."; StandardDownIndices::usage= "StandardDownIndices[g][expr] rewrites all the tensors in expr with only down indices, with the introduction of the metric tensor g. This allows to have a standard writing of expr. It is particularly convenient when the basis is orthonormal (g is the identity matrix, and in this case many authors do not even introduce upper indices)."; SymmetricStandardOrder::usage= "SymmetricStandardOrder[x][expr] allows to order vertical couples {red@i,Void}, ... of indices, irrespective of their flavor, in a symmetric tensor x present in expr. Upper indices are ordered first in alphabetic order on the left, then lower indices. It has some common behaviour with SymmetrizeSlots to which it is complementary.It also orders symmetric tensors containing covariant derivatives. SymmetricStandardOrder[x,{ind}][expr] orders the first 'ind' symmetrical indices. SymmetricStandardOrder[x,{ind1,ind2}][expr] orders the symmetrical indices between columns 'ind1' and 'ind2'."; AntiSymmetricStandardOrder::usage= "AntiSymmetricStandardOrder[x][expr] allows to order vertical couples {red@i,Void}, ... of indices, irrespective of their flavor, in an antisymmetric tensor x present in expr. Upper indices are ordered first in alphabetic order on the left, then lower indices. It has some common behaviour with SymmetrizeSlots to which it is complementary.It also orders antisymmetric tensors containing covariant derivatives. AntiSymmetricStandardOrder[x,{ind}][expr] orders the first 'ind' antisymmetrical indices. AntiSymmetricStandardOrder[x,{ind1,ind2}][expr] orders the antisymmetrical indices between columns 'ind1' and 'ind2'."; MetricSimplifyD::usage= "MetricSimplifyD[g][expr] will raise, lower or replace indices in product terms involving g and covariant or contravariant derivatives of tensors in expr using g as the label for a metric tensor. This is possible because covariant and contravariant derivatives commute with g."; UpDownSwapD::usage= "UpDownSwapD[dummyindex][term] will swap the up-down positions of the dummy index involving covariant or contravariant derivatives in the term consisting of simple tensor products."; RaiseIndexD::usage="RaiseIndexD[i,j][tensor] will raise the lower index i in covariant derivatives and rename it j.\nRaiseIndex[i,j][expr] will raise the index in all Tensors in the expr."; LowerIndexD::usage="LowerIndexD[i,j][tensor] will lower the upper index i in contravariant derivatives and rename it j.\nLowerIndex[i,j][expr] will lower the index in all Tensors in the expr."; KroneckerAbsorbD::usage= "KroneckerAbsorbD[\[Delta]][expr]\!\(\* StyleBox[\(\\\ \* StyleBox[\" \",\nFontWeight->\"Bold\"]\)]\)\!\(\* StyleBox[\"will\",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\" \",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\"perform\",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\" \",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\"inside\",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\" \",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\"HoldForms\",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\" \",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\"of\",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\" \",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\"covariant\",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\" \",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\"derivatives\",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\",\",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\" \",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\"all\",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\" \",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\"replacement\",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\" \",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\"operations\",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\" \",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\"of\",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\" \",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\"first\",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\" \",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\"order\",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\" \",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\"mixed\",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\" \",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\"tensors\",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\" \",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\"with\",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\" \",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\"labels\",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\" \",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\"\[Delta]\",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\",\",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\" \",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\"assumed\",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\" \",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\"to\",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\" \",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\"be\",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\" \",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\"Kronecker\",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\" \",\nFontWeight->\"Bold\"]\)\!\(\* StyleBox[\"deltas\",\nFontWeight->\"Bold\"]\)."; PartialSumD::usage= "PartialSumD[i,j][expr] will expand the dummy indices of a tensor expression containing derivatives, into components that have one or more baseindex indices i and an unexpanded remainder j. Symbolic indices are replaced with newindices."; MetricRuleD::usage= "MetricRuleD[x,g][expr] rewrites covariant derivatives of basis coordinates x in expr, into the (mixed) metric tensor g, and simplify its value to 1 if the derivation is on the same coordinate and to 0 otherwise. The result is left non evaluated if an index of g is literal."; Kronecker::usage= "Kronecker[\[Delta]][expr] gives the Kronecker delta \[Delta] in expr, equal to 1 if the indices with the same flavor are equal, and 0 otherwise."; ChristoffeluSymbol::usage= "ChristoffeluSymbol[\[DoubleStruckE],\[CapitalGamma],k][expr] expressed the partial derivatives PartialD[Tensor[\[DoubleStruckE],{Void},{i}],j] of basis vectors '\[DoubleStruckE]' on the basis using '\[CapitalGamma]'-noted Christoffel symbols with up indices; k is the dummy index of Einstein summation. We have chosen here to order the symmetrical Christoffel indices."; ChristoffeldSymbol::usage= "ChristoffeldSymbol[\[DoubleStruckE],\[CapitalGamma],k][expr] expressed the partial derivatives PartialD[Tensor[\[DoubleStruckE],{Void},{i}],j] of basis vectors '\[DoubleStruckE]' on the basis using '\[CapitalGamma]'-noted Christoffel symbols with down indices; k is the dummy index of Einstein summation. We have chosen here to order the symmetrical Christoffel indices."; LeviCivitaOrder::usage= "LeviCivitaOrder[e][expr] orders the indices in the Levi-Civita symbol 'e', taking into account the signature of of the permutation, and assign to zero its covariant derivatives."; FullLeviCivitaExpand::usage= "FullLeviCivitaExpand[e,g][expr] fully expand in expr product of pairs of Levi Civita tensors with label e in terms of combinaison of products of metric tensors g."; \!\(\(LeviCivitaSimplify::usage = \[IndentingNewLine]\*"\"\\"";\)\) CrossProductExpansion::usage= "CrossProductExpansion[BasisVectors,e][expr] expands three dimensional CrossProducts and Triple Scalar Products of Basis Vectors appearing in expr, into Levi-Civita tensors noted 'e'."; MetricTripleProduct::usage= "MetricTripleProduct[basis,metric,LeviCivita][expr] express any scalar triple products into combination of the components using Levi-Civita and metric tensors. Must not be confused with \!\(\* StyleBox[\"ScalarTripleProduct\",\nFontWeight->\"Bold\"]\) defined in the package Calculus`VectorAnalysis`."; EvaluateCrossProducts::usage= "EvaluateCrossProducts[\[DoubleStruckE],g,e,h][expr] evaluates the cross products in expr. \[DoubleStruckE] designates the basis used, e is the Levi-Civita symbol, g the metric tensor, and h a dummy index (not present in expr)."; VolumeSquare::usage= "VolumeSquare[flavor@g][expr] calculates the square (noted flavor@g) of the elementary volume associated with the metric tensor in the flavor basis. Its is evaluated when TensorValueRules[g] has been previously defined."; SymbolSpaceDimension::usage= "SymbolSpaceDimension[\[DoubleStruckE]] gives the dimension of the space in which \[DoubleStruckE] is a basis symbol."; SetContravariantDisplay::usage= "SetContravariantDisplay[\"SemicolonMode\"|\"DelMode\"] will set the display form of unexpanded contravariant derivatives.\nSemicolonMode: a semicolon followed by indices\nDelMode: a \!\(\* StyleBox[\"\[Del]\",\nFontSize->14]\) with superscript indices."; SetContravariantD2display::usage= "SetContravariantD2display[\"AlternativeMode\"|\"DelMode\"] will set the display form of unexpanded contravariant derivatives.\nAlternativeMode: an Alternative (\!\(\* StyleBox[\"|\",\n\"MR\"]\)) followed by indices\nDelMode: a \!\(\* StyleBox[\"\[Del]\",\nFontSize->14]\) with superscript indices."; ContravariantD::usage="ContravariantD[tensor, i] represents the contravariant derivative of the tensor with respect to the index i.\n ContravariantD[tensor,{i,j,...}] represents the contravariant derivative with respect to the list of indices. \n Symbols are considered constants."; ContravariantD2d::usage="ContravariantD2d[tensor, i] represents the 2-dimensional contravariant derivative of the tensor with respect to the index i.\n ContravariantD2d[tensor,{i,j,...}] represents the 2-dimensional contravariant derivative with respect to the list of indices. \n Symbols are considered constants."; ReleaseHoldD::usage= "ReleaseHoldD[expr] expands the contravariant derivatives of previously unexpanded terms using an UnnestTensor operation."; CovariantDSimplify::usage= "CovariantDSimplify[\[DoubleStruckE],g,e][expr] assign the value zero to the covariant and contravariant derivatives of the basis vectors, the metric tensor g and the Levi-Civita tensor e. CovariantDSimplify[g][expr] assign the value zero to the covariant or contravariant derivatives of the metric tensor g. CovariantDSimplify[g,1][expr] commutes the covariant or contravariant derivatives with the metric tensor."; CovariantDOrdering::usage= "CovariantDOrdering[expr] orders the indices of covariant derivation in expr, in a standard order. This is only possible in spaces with zero Gaussian curvature, or for second order derivatives of scalar tensors."; ExpandCovariantD2d::usage= "ExpandCovariantD2d[{x,\[Delta],g,\[CapitalGamma]},a,permissive:False][expr] will expand first order covariant derivatives of tensors using x as the label for the coordinate positions,\[Delta] as the label for the Kronecker,g as the label for the metric tensor and \[CapitalGamma] as the lavel for Christoffel symbols.The introduced dummy index will be a. ExpandCovariantD[{x,\[Delta],g,\[CapitalGamma]},{a,b,...},permissive:False][expr] expands higher order covariant derivatives using the list of dummy indices."; CovariantD2d::usage="CovariantD2d[tensor, i] represents the 2-dimensional covariant derivative of the tensor with respect to the index i.\n CovariantD2d[tensor,{i,j,...}] represents the 2-dimensional covariant derivative with repect to the list of indices. \n Symbols are considered constants."; TensorComponentsD::usage= "TensorComponentsD[expr] simplifies in expr the derivation of a tensor component by another component of the same tensor (the components must of course be independent)."; PartialDToDif::usage= "PartialDToDif[expr] rewrite the partial derivatives in their expanded form present in expr, into the partial derivatives with respect to the index of the coordinates."; DifToPartialD::usage= "DifToPartialD[labels][expr] rewrite the partial derivatives with respect to coordinates indices present in , into the partial derivatives in their expanded form parametrized by labels."; PartialDOrdering::usage= "PartialDOrdering[expr] orders the indices of partial derivation in expr, in a standard order."; DifToCov::usage= "DifToCov[\[CapitalGamma],m][{u,i},j][expr] expresses the partial derivative with respect to index j, of a tensor u present in expr, into a combination of covariant derivative and components of u. The coefficients contain Christoffel symbols \[CapitalGamma] with m as a dummy index. DifToCov[\[CapitalGamma],m,h][{u,i},{j,k}][expr] do the same kind of expansion for second partial derivatives."; PartialDSimplify::usage= "PartialDSimplify[expr] is used in nested partial derivatives to put outside the partial derivatives the factor which do not depend on the coordinate of derivation (see Chapter :Application_Grad_Div_Curl)."; TGrad::usage= "TGrad[\[DoubleStruckE],flavor@i][f] writes the gradient of a scalar tensor f, in the basis \[DoubleStruckE] with a defined flavor, and the dummy index i."; TDiv::usage= "TDiv[\[DoubleStruckE],flavor@i][vector] writes the divergence of a vector field, in the basis \[DoubleStruckE] with a defined flavor, and the dummy index i."; TCurl::usage= "TCurl[\[DoubleStruckE],flavor/@{i,j,k},e][vector] writes the curl of a vector field, in the basis \[DoubleStruckE] with a defined flavor, the dummy indices{i,j,k}, and the Levi-Civita symbol e."; TLaplacian::usage= "TLaplacian[\[DoubleStruckE],flavor@i][f] writes the laplacian of a scalar tensor f, in the basis \[DoubleStruckE] with a defined flavor, and the dummy index i."; LaplaceOp::usage= "LaplaceOp[\[CapitalDelta]][expr] writes all the laplacians in expr, using a \[CapitalDelta] notation."; \!\(\(FunctionalD::usage = \[IndentingNewLine]\*"\"\\"";\)\) (* we have chosen the black flavor as the canonical orthonormal basis *) DeclareIndexFlavor[{black,Identity}] ToFlavor[flavor_]:=ToFlavor[flavor,black] black[flavor_[i_]]:=flavor[i]/;IndexFlavorQ[flavor] Tensor[t_,{u__},{v__}]:= Tensor[t,black/@{u},black/@{v}]/; MemberQ[Head/@({u}/.Void\[Rule]_),Symbol] || MemberQ[Head/@({v}/.Void\[Rule]_),Symbol] || MemberQ[Head/@({u}/.Void\[Rule]_),Integer] || MemberQ[Head/@({v}/.Void\[Rule]_),Integer] black@Void:=Void PartialD[Tensor[t___],w_]:=PartialD[Tensor[t],black@w]/;Head@w ===Symbol PartialD[Tensor[t___],{w__}]:= PartialD[Tensor[t],black/@{w}]/;MemberQ[Head/@{w},Symbol] CovariantD[t_,w_]:=CovariantD[t,black[w]]/;Head@w===Symbol CovariantD[t_,{w__}]:=CovariantD[t,black/@{w}]/;MemberQ[Head/@{w},Symbol] ContravariantD[t_,w_]:=ContravariantD[t,black[w]]/;Head@w===Symbol ContravariantD[t_,{w__}]:= ContravariantD[t,black/@{w}]/;MemberQ[Head/@{w},Symbol] Unprotect[ReleaseHold]; ReleaseHold[expr_/;FreeQ[expr,HoldCovariantD2d]\[Equal]False]:= expr/.HoldCovariantD2d\[Rule]CovariantD2d Protect[ReleaseHold]; CovariantD[PartialD[Tensor[f_],i_],j_]:=CovariantD[Tensor[f],{i,j}] CovariantD[PartialD[Tensor[f_],i_],{j__}]:=CovariantD[Tensor[f],{i,j}] CovariantD[PartialD[Tensor[f_],{i_}],{j__}]:=CovariantD[Tensor[f],{i,j}] CovariantD[expr_,{}]:=expr HoldCovariantD[expr_,{}]:=expr HoldContravariantD[expr_,{}]:=expr HoldContravariantD[Tensor[t_,{u__},{v__}],{i_}]:= HoldContravariantD[Tensor[t,{u},{v}],i] HoldContravariantD[Tensor[t_],{i_}]:=HoldContravariantD[Tensor[t],i] HoldContravariantD[t_Symbol,i_]:=0 ToFlavor[flavor2_,flavor1_][HoldContravariantD[Tensor[t_,{u__},{v__}],w_]]:= HoldContravariantD[Tensor[t,{u},{v}]//ToFlavor[flavor2,flavor1], If[Head@w===List,flavor2/@(w/.flavor1\[Rule]Identity), flavor2@(w/.flavor1\[Rule]Identity)]] ToFlavor[flavor2_,flavor1_][ HoldContravariantD[a__ Tensor[t_,{u__},{v__}],w_]]:= HoldContravariantD[a Tensor[t,{u},{v}]//ToFlavor[flavor2,flavor1], If[Head@w===List,flavor2/@(w/.flavor1\[Rule]Identity), flavor2@(w/.flavor1\[Rule]Identity)]] ToFlavor[flavor2_,flavor1_][Tensor[t_,{u__},{v__}] a_HoldContravariantD]:= ToFlavor[flavor2,flavor1][Tensor[t,{u},{v}]]ToFlavor[flavor2,flavor1][a] ToFlavor[flavor2_,flavor1_][a$_HoldContravariantD b$_HoldContravariantD]:= ToFlavor[flavor2,flavor1][a$]ToFlavor[flavor2,flavor1][b$] ToFlavor[flavor2_,flavor1_][ Tensor[t_,{u__},{v__}]a$_HoldContravariantD b$_HoldContravariantD]:= ToFlavor[flavor2,flavor1][Tensor[t,{u},{v}]]ToFlavor[flavor2,flavor1][ a$]ToFlavor[flavor2,flavor1][b$] ToFlavor[flavor2_,flavor1_][a$_HoldContravariantD b$_Times]:= ToFlavor[flavor2,flavor1][a$]ToFlavor[flavor2,flavor1][b$] ToFlavor[flavor2_,flavor1_][a$_+b$_]:= ToFlavor[flavor2,flavor1][a$]+ToFlavor[flavor2,flavor1][b$] Begin["`Private`"] Tensor[x_Integer]:=x Tensor[x_Rational]:=x Tensor[x_Real]:=x Tensor[x_Complex]:=x Tensor[t_,{},{}]:=Tensor[t] HoldFactor[term_][expr_]:=HoldForm[term]Apart[expr/term] HoldCovariantD[expr_,i_]:=HoldOp[CovariantD][CovariantD[expr,i]] ToFlavorD[flavor2_,flavor1_][expr_]:=TFlvD[flavor2,flavor1]/@expr ToFlavorD[flavor2_,flavor1_][expr_]:= FixedPoint[TFlvD[flavor2,flavor1],expr,5] ToFlavorD[flavor_]:=ToFlavorD[flavor,black] TFlvD[flavor2_,flavor1_][expr_]:= expr/.HoldContravariantD2d[term_,w_]\[RuleDelayed] HoldContravariantD2d[term//ToFlavor[flavor2,flavor1], flavor2@RawIndex@w]/.HoldContravariantD[term_, w_]\[RuleDelayed]HoldContravariantD[ term//ToFlavor[flavor2,flavor1], If[Head[w]=!=List,flavor2@RawIndex@RawIndex@w, flavor2/@RawIndex/@RawIndex/@w]]/.HoldCovariantD2d[term_, w_]\[RuleDelayed]HoldCovariantD2d[term//ToFlavor[flavor2,flavor1], flavor2@RawIndex@w]/.HoldCovariantD[term_,w_]\[RuleDelayed] HoldCovariantD[term//ToFlavor[flavor2,flavor1], If[Head[w]=!=List,flavor2@RawIndex@w, flavor2/@RawIndex/@w]]/.expr\[RuleDelayed] ToFlavor[flavor2,flavor1][expr]/; FreeQ[expr,HoldCovariantD[i_,j_]]|| FreeQ[expr,HoldCovariantD2d[i_,j_]] PartialSumHold[i_,j_][expr_]:= If[Length[expr]=!=1,PartialSumTemp[i,j]/@expr,PartialSumTemp[i,j][expr]] PartialSumTemp[i_,j_][expr_]:= Module[{resu,test,rul}, If[FreeQ[expr,HoldForm],PartialSum[i,j][expr], test=(expr/.HoldForm\[Rule]Identity//First// ParseTermIndices)\[LeftDoubleBracket]1\[RightDoubleBracket]; If[Length[test]=!=Length[j],resu=PartialSum[i,j][expr];Goto[end]]; rul={Thread[test\[Rule]i],Thread[test\[Rule]j]};Off[Part::"pspec"]; val0[1]=Table[Clear[u\[Section]]; rul\[LeftDoubleBracket]u\[Section][i\[Section]], i\[Section]\[RightDoubleBracket],{i\[Section],Length[j]}]; Do[val0[j\[Section]+1]= Table[#,{u\[Section][j\[Section]],2}]&[ val0[j\[Section]]],{j\[Section],Length[j]}];On[Part::"pspec"]; resu=Apply[Plus,Flatten[PartialSum[i,j][expr]/.val0[Length[j]+1]]]; Clear[val0];Label[end];resu] ] BasisChange[\[Beta]_,toflavor_][Tensor[T_,list1_,list2_]]:= Module[{ii}, Tensor[T,list1,list2]Product[ If[list2[[ii]]===Void, Tensor[\[Beta], toflavor[#]&/@{list2[[ii]],list1[[ii]]},{list1[[ii]], list2[[ii]]}], Tensor[\[Beta],{list2[[ii]],list1[[ii]]}, toflavor[#]&/@{list1[[ii]],list2[[ii]]}]],{ii, Length[list1]}]]/.{toflavor[Void]->Void, toflavor[f_[i_]]->toflavor[i]} BasisChange[\[Beta]_,toflavor_][ff_[x_]]:= ff[BasisChange[\[Beta],toflavor][x]] BasisChange[\[Beta]_,toflavor_][ff_[x_,y_]]:= ff[BasisChange[\[Beta],toflavor][x],y] BasisChange[\[Beta]_,toflavor_][x_+y_]:= BasisChange[\[Beta],toflavor][x]+BasisChange[\[Beta],toflavor][y] BasisChange[\[Beta]_,toflavor_][a_. x_Tensor]:= a BasisChange[\[Beta],toflavor][x] BasisDerivation[\[CapitalGamma]_,m_][{\[DoubleStruckE]_,i_},j_][expr_]:= expr/.{PartialD[Tensor[\[DoubleStruckE],{Void},{i}],j]\[Rule] Tensor[\[DoubleStruckE],{Void},{m}]* Tensor[\[CapitalGamma],{m,Void,Void},{Void,j,i}], PartialD[Tensor[\[DoubleStruckE],{i},{Void}], j]\[Rule]-(Tensor[\[DoubleStruckE],{m},{Void}]* Tensor[\[CapitalGamma],{i,Void,Void},{Void,j,m}]), CovariantD[Tensor[\[DoubleStruckE],{Void},{i}],j]\[RuleDelayed]0, CovariantD[Tensor[\[DoubleStruckE],{i},{Void}],j]\[RuleDelayed]0} BasisDerivation[\[CapitalGamma]_,h_,m_][{\[DoubleStruckE]_,i_},{j_,k_}][ expr_]:=expr/.{PartialD[Tensor[\[DoubleStruckE],{Void},{i}],{j,k}]\[Rule] Tensor[\[DoubleStruckE],{Void},{h}]*(Tensor[\[CapitalGamma],{h,Void, Void},{Void,k,m}]* Tensor[\[CapitalGamma],{m,Void,Void},{Void,j,i}]+ PartialD[Tensor[\[CapitalGamma],{h,Void,Void},{Void,j,i}],k]), PartialD[Tensor[\[DoubleStruckE],{i},{Void}],{j,k}]\[Rule] Tensor[\[DoubleStruckE],{h},{Void}]*(Tensor[\[CapitalGamma],{i,Void, Void},{Void,j,m}]* Tensor[\[CapitalGamma],{m,Void,Void},{Void,k,h}]- PartialD[Tensor[\[CapitalGamma],{i,Void,Void},{Void,j,h}],k]), CovariantD[Tensor[\[DoubleStruckE],{Void},{i}],{j,__}]\[RuleDelayed]0, CovariantD[Tensor[\[DoubleStruckE],{i},{Void}],{j,__}]\[RuleDelayed]0} StandardDownIndices[g_][expr_]:= expr/.Tensor[x_,ups_,downs_]\[RuleDelayed] Module[{ii,coeffg,indices,updowns1,RawIndexupdowns1,updowns2, siteCov},{siteCov= Table[{ii},{ii, Length[ups]-Length[Position[{ups,downs},Cov[_]]]+1, Length[ups]}]; updowns1=({ups,downs}/.{Cov\[Rule]Identity}//Transpose); RawIndexupdowns1=(Table[ RawIndex/@(updowns1[[ii]]),{ii,Length[updowns1]}]); updowns2={};coeffg=1; Do[Module[{i$}, If[Position[RawIndexupdowns1,Void]\[LeftDoubleBracket]ii, 2\[RightDoubleBracket]\[Equal]1, updowns2= Append[updowns2, updowns1\[LeftDoubleBracket] ii\[RightDoubleBracket]],(If[ Head[updowns1\[LeftDoubleBracket]ii, 1\[RightDoubleBracket]]=== Symbol,(Flvr=Identity),(Flvr= Head[updowns1\[LeftDoubleBracket]ii, 1\[RightDoubleBracket]] )]; coeffg=coeffg Tensor[ g,{updowns1\[LeftDoubleBracket]ii, 1\[RightDoubleBracket],Flvr@i$},{Void,Void}]; updowns2=Append[updowns2,{Void,Flvr@i$}])]],{ii, Length[updowns1]}]; indices=Transpose[ MapAt[Cov,updowns2, siteCov]/.{Cov@{i_,j_}\[Rule]{Cov@i,Cov@j}}/.{Cov@ Void\[Rule]Void}]; coeffg Tensor[x, indices\[LeftDoubleBracket]1\[RightDoubleBracket], indices[[2]]]}]\[LeftDoubleBracket]1\[RightDoubleBracket]/.\ Module[{j}, HoldContravariantD[t_,i_]\[RuleDelayed] HoldCovariantD[t,j]Tensor[g,{i,j},{Void,Void}]] SymmetricStandardOrder[x_][expr_]:= Module[{cov, cov2d,pos,pos1,U, term},(CovNotation[cov][ Cov2dNotation[cov2d][ expr/.Tensor[ t__/;(FreeQ[{t},Tensor]\[Equal]False)]\[RuleDelayed] TensorTemp[t]]]//SymmetricStandardOrderTemp[x])/.Tensor[ t_,{u__},{v__}]\[RuleDelayed] If[(pos1=Position[{{u},{v}}//Transpose,cov@_])==={}, Tensor[t,{u},{v}],{(pos=pos1//Transpose), term=Tensor[t, U=Delete[{u}, List/@pos\[LeftDoubleBracket]1\[RightDoubleBracket]]\ ,Delete[{v},List/@pos\[LeftDoubleBracket]1\[RightDoubleBracket]]], Do[If[pos\[LeftDoubleBracket]2, ii\[RightDoubleBracket]\[Equal]2, term=CovariantD[ term,{v}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]], term=HoldContravariantD[ term,{u}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]]],{ii, Length[pos\[LeftDoubleBracket]2\[RightDoubleBracket]]}], term/.cov\[Rule] Identity}\[LeftDoubleBracket]4\[RightDoubleBracket]]/.\ Tensor[t_,{u__},{v__}]\[RuleDelayed] If[(pos1=Position[{{u},{v}}//Transpose,cov2d@_])==={}, Tensor[t,{u},{v}],{(pos=pos1//Transpose), term=Tensor[t, U=Delete[{u}, List/@pos\[LeftDoubleBracket]1\[RightDoubleBracket]], Delete[{v}, List/@pos\[LeftDoubleBracket]1\[RightDoubleBracket]]], Do[If[pos\[LeftDoubleBracket]2, ii\[RightDoubleBracket]\[Equal]2, term=CovariantD2d[ term,{v}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]], term=ContravariantD2d[ term,{u}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]]],{ii, Length[pos\[LeftDoubleBracket]2\[RightDoubleBracket]]}], term/.cov2d\[Rule] Identity}\[LeftDoubleBracket]4\[RightDoubleBracket]]/.\ TensorTemp\[Rule]Tensor ] SymmetricStandardOrderTemp[x_][expr_]:= expr/.Tensor[x,ups_,downs_]\[RuleDelayed] Module[{indices,updowns1,RawIndexupdowns1,updowns2, RawIndexupdowns2},{updowns1=({ups, downs}/.{Void\[Rule]black@\[Sharp][\[Sharp]]}// Transpose); RawIndexupdowns1=(Table[ RawIndex/@(updowns1\[LeftDoubleBracket] ii\[RightDoubleBracket]),{ii,Length[updowns1]}]); RawIndexupdowns2=Sort[RawIndexupdowns1]; Off[RawIndex::"notindex"]; updowns2= Permutations[updowns1]\[LeftDoubleBracket] Position[RawIndex//@Permutations[updowns1], RawIndexupdowns2]\[LeftDoubleBracket]1, 1\[RightDoubleBracket] \[RightDoubleBracket]; On[RawIndex::"notindex"]; indices=Transpose[ updowns2]/.{black@\[Sharp][\[Sharp]]\[Rule]Void}; Tensor[x,indices[[1]], indices\[LeftDoubleBracket]2\[RightDoubleBracket]]}]\ \[LeftDoubleBracket]1\[RightDoubleBracket] SymmetricStandardOrder[x_,{ind0_}][expr_]:= Module[{cov,cov2d,pos,pos1,U, term},(CovNotation[cov][ Cov2dNotation[cov2d][ expr/.Tensor[ t__/;(FreeQ[{t},Tensor]\[Equal]False)]\[RuleDelayed] TensorTemp[t]]]// SymmetricStandardOrderTemp[x,{ind0}])/.Tensor[ t_,{u__},{v__}]\[RuleDelayed] If[(pos1=Position[{{u},{v}}//Transpose,cov@_])==={}, Tensor[t,{u},{v}],{(pos=pos1//Transpose), term=Tensor[t, U=Delete[{u}, List/@pos\[LeftDoubleBracket]1\[RightDoubleBracket]]\ ,Delete[{v},List/@pos\[LeftDoubleBracket]1\[RightDoubleBracket]]], Do[If[pos\[LeftDoubleBracket]2, ii\[RightDoubleBracket]\[Equal]2, term=CovariantD[ term,{v}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]], term=HoldContravariantD[ term,{u}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]]],{ii, Length[pos\[LeftDoubleBracket]2\[RightDoubleBracket]]}], term/.cov\[Rule] Identity}\[LeftDoubleBracket]4\[RightDoubleBracket]]/.\ Tensor[t_,{u__},{v__}]\[RuleDelayed] If[(pos1=Position[{{u},{v}}//Transpose,cov2d@_])==={}, Tensor[t,{u},{v}],{(pos=pos1//Transpose), term=Tensor[t, U=Delete[{u}, List/@pos\[LeftDoubleBracket]1\[RightDoubleBracket]], Delete[{v}, List/@pos\[LeftDoubleBracket]1\[RightDoubleBracket]]], Do[If[pos\[LeftDoubleBracket]2, ii\[RightDoubleBracket]\[Equal]2, term=CovariantD2d[ term,{v}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]], term=ContravariantD2d[ term,{u}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]]],{ii, Length[pos\[LeftDoubleBracket]2\[RightDoubleBracket]]}], term/.cov2d\[Rule] Identity}\[LeftDoubleBracket]4\[RightDoubleBracket]]/.\ TensorTemp\[Rule]Tensor ] SymmetricStandardOrderTemp[x_,{ind0_}][expr_]:= expr/.Tensor[x,ups_,downs_]\[RuleDelayed] If[Length[ups]\[GreaterEqual]ind0, Module[{indices,updowns1,RawIndexupdowns1,updowns2, RawIndexupdowns2},{updowns1=({ups, downs}/.{Void\[Rule]black@\[Sharp][\[Sharp]]}// Transpose); RawIndexupdowns1=(Table[ RawIndex/@(updowns1\[LeftDoubleBracket] ii\[RightDoubleBracket]),{ii,Length[updowns1]}]); RawIndexupdowns2=(Flatten[{Sort[Take[RawIndexupdowns1,ind0]], Take[RawIndexupdowns1,{ind0+1,Length[updowns1]}]},1]); Off[RawIndex::"notindex"]; updowns2= Permutations[updowns1]\[LeftDoubleBracket] Position[RawIndex//@Permutations[updowns1], RawIndexupdowns2]\[LeftDoubleBracket]1, 1\[RightDoubleBracket] \[RightDoubleBracket]; On[RawIndex::"notindex"]; indices=Transpose[ updowns2]/.{black@\[Sharp][\[Sharp]]\[Rule]Void}; Tensor[x,indices\[LeftDoubleBracket]1\[RightDoubleBracket], indices\[LeftDoubleBracket]2\[RightDoubleBracket]]}]\ \[LeftDoubleBracket]1\[RightDoubleBracket],Tensor[x,ups,downs]] SymmetricStandardOrder[x_,{ind1_,ind2_}][expr_]:= Module[{cov,pos,pos1,U, term},(CovNotation[cov][ expr/.Tensor[ t__/;(FreeQ[{t},Tensor]\[Equal]False)]\[RuleDelayed] TensorTemp[t]]// SymmetricStandardOrderTemp[x,{ind1,ind2}])/.Tensor[ t_,{u__},{v__}]\[RuleDelayed] If[(pos1=Position[{{u},{v}}//Transpose,cov@_])==={}, Tensor[t,{u},{v}],{(pos=pos1//Transpose), term=Tensor[t, U=Delete[{u}, List/@pos\[LeftDoubleBracket]1\[RightDoubleBracket]], Delete[{v}, List/@pos\[LeftDoubleBracket]1\[RightDoubleBracket]]], Do[If[pos\[LeftDoubleBracket]2, ii\[RightDoubleBracket]\[Equal]2, term=CovariantD[ term,{v}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]], term=HoldContravariantD[ term,{u}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]]],{ii, Length[pos\[LeftDoubleBracket]2\[RightDoubleBracket]]}], term/.cov\[Rule] Identity}\[LeftDoubleBracket]4\[RightDoubleBracket]]/.\ TensorTemp\[Rule]Tensor ] SymmetricStandardOrderTemp[x_,{ind1_,ind2_}][expr_]:= expr/.Tensor[x,ups_,downs_]\[RuleDelayed] If[Length[ups]\[GreaterEqual]ind2, Module[{indices,updowns1,RawIndexupdowns1,updowns2, RawIndexupdowns2},{updowns1=({ups, downs}/.{Void\[Rule]black@\[Sharp][\[Sharp]]}// Transpose); RawIndexupdowns1=(Table[ RawIndex/@(updowns1\[LeftDoubleBracket] ii\[RightDoubleBracket]),{ii,Length[updowns1]}]); RawIndexupdowns2=(Flatten[{Take[RawIndexupdowns1,ind1-1], Sort[Take[RawIndexupdowns1,{ind1,ind2}]], Take[RawIndexupdowns1,{ind2+1,Length[updowns1]}]},1]); Off[RawIndex::"notindex"]; updowns2= Permutations[updowns1]\[LeftDoubleBracket] Position[RawIndex//@Permutations[updowns1], RawIndexupdowns2]\[LeftDoubleBracket]1, 1\[RightDoubleBracket] \[RightDoubleBracket]; On[RawIndex::"notindex"]; indices=Transpose[ updowns2]/.{black@\[Sharp][\[Sharp]]\[Rule]Void}; Tensor[x,indices\[LeftDoubleBracket]1\[RightDoubleBracket], indices\[LeftDoubleBracket]2\[RightDoubleBracket]]}]\ \[LeftDoubleBracket]1\[RightDoubleBracket],Tensor[x,ups,downs]] AntiSymmetricStandardOrder[x_][expr_]:= Module[{cov,cov2d,pos,pos1,U, term},(CovNotation[cov][ Cov2dNotation[cov2d][ expr/.Tensor[ t__/;(FreeQ[{t},Tensor]\[Equal]False)]\[RuleDelayed] TensorTemp[t]]]// AntiSymmetricStandardOrderTemp[x])/.Tensor[ t_,{u__},{v__}]\[RuleDelayed] If[(pos1=Position[{{u},{v}}//Transpose,cov@_])==={}, Tensor[t,{u},{v}],{(pos=pos1//Transpose), term=If[Length[pos1]\[Equal]Length[{u}],Tensor[t], Tensor[t, U=Delete[{u}, List/@pos\[LeftDoubleBracket]1\ \[RightDoubleBracket]], Delete[{v}, List/@pos\[LeftDoubleBracket]1\[RightDoubleBracket]]\ ]],Do[If[pos\[LeftDoubleBracket]2,ii\[RightDoubleBracket]\[Equal]2, term=CovariantD[ term,{v}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]], term=HoldContravariantD[ term,{u}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]]],{ii, Length[pos\[LeftDoubleBracket]2\[RightDoubleBracket]]}], term/.cov\[Rule] Identity}\[LeftDoubleBracket]4\[RightDoubleBracket]]/.\ Tensor[t_,{u__},{v__}]\[RuleDelayed] If[(pos1=Position[{{u},{v}}//Transpose,cov2d@_])==={}, Tensor[t,{u},{v}],{(pos=pos1//Transpose), term=Tensor[t, U=Delete[{u}, List/@pos\[LeftDoubleBracket]1\[RightDoubleBracket]], Delete[{v}, List/@pos\[LeftDoubleBracket]1\[RightDoubleBracket]]], Do[If[pos\[LeftDoubleBracket]2, ii\[RightDoubleBracket]\[Equal]2, term=CovariantD2d[ term,{v}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]], term=ContravariantD2d[ term,{u}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]]],{ii, Length[pos\[LeftDoubleBracket]2\[RightDoubleBracket]]}], term/.cov2d\[Rule] Identity}\[LeftDoubleBracket]4\[RightDoubleBracket]]/.\ TensorTemp\[Rule]Tensor ] AntiSymmetricStandardOrderTemp[x_][expr_]:= expr/.Tensor[x,ups_,downs_]\[RuleDelayed] Module[{ii,indices,updowns1,RawIndexupdowns1,updowns2, RawIndexupdowns2},{updowns1=({ups,downs}//Transpose); RawIndexupdowns1=(Table[ RawIndex/@(updowns1[[ii]]),{ii,Length[updowns1]}]); RawIndexupdowns2=Sort[RawIndexupdowns1]; Off[RawIndex::"notindex"]; updowns2= Permutations[updowns1][[ Position[RawIndex//@Permutations[updowns1], RawIndexupdowns2][[1,1]] ]];On[RawIndex::"notindex"]; indices=Transpose[updowns2]; Signature[RawIndexupdowns1]Tensor[x, indices\[LeftDoubleBracket]1\[RightDoubleBracket], indices\[LeftDoubleBracket]2\[RightDoubleBracket]]}]\ \[LeftDoubleBracket]1\[RightDoubleBracket] AntiSymmetricStandardOrder[x_,{ind0_}][expr_]:= Module[{cov,cov2d,pos,pos1,U, term},(CovNotation[cov][ Cov2dNotation[cov2d][ expr/.Tensor[ t__/;(FreeQ[{t},Tensor]\[Equal]False)]\[RuleDelayed] TensorTemp[t]]]// AntiSymmetricStandardOrderTemp[x,{ind0}])/.Tensor[ t_,{u__},{v__}]\[RuleDelayed] If[(pos1=Position[{{u},{v}}//Transpose,cov@_])==={}, Tensor[t,{u},{v}],{(pos=pos1//Transpose), term=Tensor[t, U=Delete[{u}, List/@pos\[LeftDoubleBracket]1\[RightDoubleBracket]]\ ,Delete[{v},List/@pos\[LeftDoubleBracket]1\[RightDoubleBracket]]], Do[If[pos\[LeftDoubleBracket]2, ii\[RightDoubleBracket]\[Equal]2, term=CovariantD[ term,{v}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]], term=HoldContravariantD[ term,{u}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]]],{ii, Length[pos\[LeftDoubleBracket]2\[RightDoubleBracket]]}], term/.cov\[Rule] Identity}\[LeftDoubleBracket]4\[RightDoubleBracket]]/.\ Tensor[t_,{u__},{v__}]\[RuleDelayed] If[(pos1=Position[{{u},{v}}//Transpose,cov2d@_])==={}, Tensor[t,{u},{v}],{(pos=pos1//Transpose), term=Tensor[t, U=Delete[{u}, List/@pos\[LeftDoubleBracket]1\[RightDoubleBracket]], Delete[{v}, List/@pos\[LeftDoubleBracket]1\[RightDoubleBracket]]], Do[If[pos\[LeftDoubleBracket]2, ii\[RightDoubleBracket]\[Equal]2, term=CovariantD2d[ term,{v}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]], term=ContravariantD2d[ term,{u}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]]],{ii, Length[pos\[LeftDoubleBracket]2\[RightDoubleBracket]]}], term/.cov2d\[Rule] Identity}\[LeftDoubleBracket]4\[RightDoubleBracket]]/.\ TensorTemp\[Rule]Tensor ] AntiSymmetricStandardOrderTemp[x_,{ind0_}][expr_]:= expr/.Tensor[x,ups_,downs_]\[RuleDelayed] If[Length[ups]\[GreaterEqual]ind0, Module[{indices,updowns1,RawIndexupdowns1,updowns2, RawIndexupdowns2},{updowns1=({ups, downs}/.{Void\[Rule]black@\[Sharp][\[Sharp]]}// Transpose); RawIndexupdowns1=(Table[ RawIndex/@(updowns1\[LeftDoubleBracket] ii\[RightDoubleBracket]),{ii,Length[updowns1]}]); RawIndexupdowns2=(Flatten[{Sort[Take[RawIndexupdowns1,ind0]], Take[RawIndexupdowns1,{ind0+1,Length[updowns1]}]},1]); Off[RawIndex::"notindex"]; updowns2= Permutations[updowns1]\[LeftDoubleBracket] Position[RawIndex//@Permutations[updowns1], RawIndexupdowns2]\[LeftDoubleBracket]1, 1\[RightDoubleBracket] \[RightDoubleBracket]; On[RawIndex::"notindex"]; indices=Transpose[ updowns2]/.{black@\[Sharp][\[Sharp]]\[Rule]Void}; Signature[Take[RawIndexupdowns1,ind0]]Tensor[x, indices\[LeftDoubleBracket]1\[RightDoubleBracket], indices\[LeftDoubleBracket]2\[RightDoubleBracket]]}]\ \[LeftDoubleBracket]1\[RightDoubleBracket],Tensor[x,ups,downs]] AntiSymmetricStandardOrder[x_,{ind1_,ind2_}][expr_]:= Module[{cov,cov2d,pos,pos1,U, term},(CovNotation[cov][ Cov2dNotation[cov2d][ expr/.Tensor[ t__/;(FreeQ[{t},Tensor]\[Equal]False)]\[RuleDelayed] TensorTemp[t]]]// AntiSymmetricStandardOrderTemp[x,{ind1,ind2}])/.Tensor[ t_,{u__},{v__}]\[RuleDelayed] If[(pos1=Position[{{u},{v}}//Transpose,cov@_])==={}, Tensor[t,{u},{v}],{(pos=pos1//Transpose), term=If[Length[pos1]\[Equal]Length[{u}],Tensor[t], Tensor[t, U=Delete[{u}, List/@pos\[LeftDoubleBracket]1\ \[RightDoubleBracket]], Delete[{v}, List/@pos\[LeftDoubleBracket]1\[RightDoubleBracket]]\ ]],Do[If[pos\[LeftDoubleBracket]2,ii\[RightDoubleBracket]\[Equal]2, term=CovariantD[ term,{v}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]], term=HoldContravariantD[ term,{u}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]]],{ii, Length[pos\[LeftDoubleBracket]2\[RightDoubleBracket]]}], term/.cov\[Rule] Identity}\[LeftDoubleBracket]4\[RightDoubleBracket]]/.\ Tensor[t_,{u__},{v__}]\[RuleDelayed] If[(pos1=Position[{{u},{v}}//Transpose,cov2d@_])==={}, Tensor[t,{u},{v}],{(pos=pos1//Transpose), term=Tensor[t, U=Delete[{u}, List/@pos\[LeftDoubleBracket]1\[RightDoubleBracket]], Delete[{v}, List/@pos\[LeftDoubleBracket]1\[RightDoubleBracket]]], Do[If[pos\[LeftDoubleBracket]2, ii\[RightDoubleBracket]\[Equal]2, term=CovariantD2d[ term,{v}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]], term=ContravariantD2d[ term,{u}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]]],{ii, Length[pos\[LeftDoubleBracket]2\[RightDoubleBracket]]}], term/.cov2d\[Rule] Identity}\[LeftDoubleBracket]4\[RightDoubleBracket]]/.\ TensorTemp\[Rule]Tensor ] AntiSymmetricStandardOrder[x_,{ind1_,ind2_}][expr_]:= expr/.Tensor[x,ups_,downs_]\[RuleDelayed] If[Length[ups]\[GreaterEqual]ind2, Module[{ii,indices,updowns1,RawIndexupdowns1,updowns2, RawIndexupdowns2},{updowns1=({ups,downs}//Transpose); RawIndexupdowns1=(Table[ RawIndex/@(updowns1\[LeftDoubleBracket] ii\[RightDoubleBracket]),{ii,Length[updowns1]}]); RawIndexupdowns2=(Flatten[{Take[RawIndexupdowns1,ind1-1], Sort[Take[RawIndexupdowns1,{ind1,ind2}]], Take[RawIndexupdowns1,{ind2+1,Length[updowns1]}]},1]); Off[RawIndex::"notindex"]; updowns2= Permutations[updowns1]\[LeftDoubleBracket] Position[RawIndex//@Permutations[updowns1], RawIndexupdowns2]\[LeftDoubleBracket]1, 1\[RightDoubleBracket] \[RightDoubleBracket]; On[RawIndex::"notindex"]; indices=Transpose[updowns2]; Signature[Take[RawIndexupdowns1,{ind1,ind2}]]Tensor[x, indices\[LeftDoubleBracket]1\[RightDoubleBracket], indices\[LeftDoubleBracket]2\[RightDoubleBracket]]}]\ \[LeftDoubleBracket]1\[RightDoubleBracket],Tensor[x,ups,downs]] MetricSimplifyD[g_][expr_]:= Module[{cov,cov2d,pos,pos1,U, term},((MetricSimplify[g][ Cov2dNotation[cov2d][ CovNotation[cov][ expr//CovariantDSimplify[g]]]]/.Tensor[ g,{u__},{v__}]\[RuleDelayed](flavor:= Head@First[{u,v}/.Void\[Rule]{}// Flatten];(Tensor[ g,{u},{v}]/.flavor@i_\[Rule]flavor@cov@i))// MetricSimplify[g])/.Tensor[ g,{u__},{v__}]\[RuleDelayed](flavor:= Head@First[{u,v}/.Void\[Rule]{}//Flatten];(Tensor[ g,{u},{v}]/.flavor@cov@i_\[Rule] flavor@i))/.Tensor[ g,{u__},{v__}]\[RuleDelayed](flavor:= Head@First[{u,v}/.Void\[Rule]{}//Flatten];(Tensor[ g,{u},{v}]/.flavor@i_\[Rule]flavor@cov2d@i))// MetricSimplify[g])/.Tensor[ g,{u__},{v__}]\[RuleDelayed](flavor:= Head@First[{u,v}/.Void\[Rule]{}//Flatten];(Tensor[ g,{u},{v}]/.flavor@cov2d@i_\[Rule]flavor@i))/.Tensor[ t_,{u__},{v__}]\[RuleDelayed] If[(pos1=Position[{{u},{v}}//Transpose,cov@_])==={}, Tensor[t,{u},{v}],{(pos=pos1//Transpose), term=Tensor[t, U=Delete[{u}, List/@pos\[LeftDoubleBracket]1\[RightDoubleBracket]], Delete[{v}, List/@pos\[LeftDoubleBracket]1\[RightDoubleBracket]]], Do[If[pos\[LeftDoubleBracket]2, ii\[RightDoubleBracket]\[Equal]2, term=CovariantD[ term,{v}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]], term=HoldContravariantD[ term,{u}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]]],{ii, Length[pos\[LeftDoubleBracket]2\[RightDoubleBracket]]}], term/.cov\[Rule] Identity}\[LeftDoubleBracket]4\[RightDoubleBracket]]/.\ Tensor[t_,{u__},{v__}]\[RuleDelayed] If[(pos1=Position[{{u},{v}}//Transpose,cov2d@_])==={}, Tensor[t,{u},{v}],{(pos=pos1//Transpose), term=Tensor[t, U=Delete[{u}, List/@pos\[LeftDoubleBracket]1\[RightDoubleBracket]], Delete[{v}, List/@pos\[LeftDoubleBracket]1\[RightDoubleBracket]]], Do[If[pos\[LeftDoubleBracket]2,ii\[RightDoubleBracket]\[Equal]2, term=CovariantD2d[ term,{v}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]], term=ContravariantD2d[ term,{u}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]]],{ii, Length[pos\[LeftDoubleBracket]2\[RightDoubleBracket]]}], term/.cov2d\[Rule] Identity}\[LeftDoubleBracket]4\[RightDoubleBracket]] ] MetricSimplifyD[g_][expr_HoldForm]:= expr//EvaluateAtPattern[ expr/. HoldForm[CovariantD[t_,w_]]\[RuleDelayed]t,\[Infinity], MetricSimplify[g]] reduct[i_,j_][expr_]:=expr/.j\[Rule]i UpDownSwapD[i_][expr_]:=Module[{j},reduct[i,j][UpDownSwapD[i,j][expr]]] UpDownSwapD[i_,j_][expr_]:= If[Head[i]=!=List, If[i===j,Print[ "Warning : the two indices must be different"],(expr// RaiseIndexD[i,j]//LowerIndexD[i,j])]] UpDownSwapD[{i__}][expr_]:= Fold[funct,expr,{i}]//.{funct[term_,j_]\[RuleDelayed]UpDownSwapD[j][term]} RaiseIndexD[i_,j_][expr_]:= If[FreeQ[expr,CovariantD]&&FreeQ[expr,CovariantD2d],RaiseIndex[i,j][expr], RaiseInD[i,j][expr]] RaiseInD[i_,j_][expr_]:= Module[{cov,cov2d,pos,pos1,term, U},(CovNotation[cov][Cov2dNotation[cov2d][expr]]// RaiseIndex[i,j])/.Tensor[t_,{u__},{v__}]\[RuleDelayed] If[(pos1=Position[{{u},{v}}//Transpose,cov@_])==={}, Tensor[t,{u},{v}],{(pos=pos1//Transpose), term=If[Length[pos1]\[Equal]Length[{u}],Tensor[t], Tensor[t, U=Delete[{u}, List/@pos\[LeftDoubleBracket]1\[RightDoubleBracket]]\ ,Delete[{v},List/@pos\[LeftDoubleBracket]1\[RightDoubleBracket]]]], Do[If[pos\[LeftDoubleBracket]2, ii\[RightDoubleBracket]\[Equal]2, term=CovariantD[ term,{v}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]], term=HoldContravariantD[ term,{u}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]]],{ii, Length[pos\[LeftDoubleBracket]2\[RightDoubleBracket]]}], term/.cov\[Rule] Identity}\[LeftDoubleBracket]4\[RightDoubleBracket]]/.\ Tensor[t_,{u__},{v__}]\[RuleDelayed] If[(pos1=Position[{{u},{v}}//Transpose,cov2d@_])==={}, Tensor[t,{u},{v}],{(pos=pos1//Transpose), term=If[Length[pos1]\[Equal]Length[{u}],Tensor[t], Tensor[t, U=Delete[{u}, List/@pos\[LeftDoubleBracket]1\[RightDoubleBracket]], Delete[{v}, List/@pos\[LeftDoubleBracket]1\[RightDoubleBracket]]]], Do[If[pos\[LeftDoubleBracket]2,ii\[RightDoubleBracket]\[Equal]2, term=CovariantD2d[ term,{v}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]], term=ContravariantD2d[ term,{u}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]]],{ii, Length[pos\[LeftDoubleBracket]2\[RightDoubleBracket]]}], term/.cov2d\[Rule] Identity}\[LeftDoubleBracket]4\[RightDoubleBracket]]] LowerIndexD[i_,j_][expr_]:= If[FreeQ[expr,HoldContravariantD]&&FreeQ[expr,HoldContravariantD2d], LowerIndex[i,j][expr],LowerInD[i,j][expr]] LowerInD[i_,j_][expr_]:= Module[{cov,cov2d,pos,pos1,term, U},(CovNotation[cov][Cov2dNotation[cov2d][expr]]// LowerIndex[RawIndex@i,RawIndex@j])/.Tensor[ t_,{u__},{v__}]\[RuleDelayed] If[(pos1=Position[{{u},{v}}//Transpose,cov@_])==={}, Tensor[t,{u},{v}],{(pos=pos1//Transpose), term=If[Length[pos1]\[Equal]Length[{u}],Tensor[t], Tensor[t, U=Delete[{u}, List/@pos\[LeftDoubleBracket]1\[RightDoubleBracket]]\ ,Delete[{v},List/@pos\[LeftDoubleBracket]1\[RightDoubleBracket]]]], Do[If[pos\[LeftDoubleBracket]2, ii\[RightDoubleBracket]\[Equal]2, term=CovariantD[ term,{v}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]], term=HoldContravariantD[ term,{u}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]]],{ii, Length[pos\[LeftDoubleBracket]2\[RightDoubleBracket]]}], term/.cov\[Rule] Identity}\[LeftDoubleBracket]4\[RightDoubleBracket]]/.\ Tensor[t_,{u__},{v__}]\[RuleDelayed] If[(pos1=Position[{{u},{v}}//Transpose,cov2d@_])==={}, Tensor[t,{u},{v}],{(pos=pos1//Transpose), term=If[Length[pos1]\[Equal]Length[{u}],Tensor[t], Tensor[t, U=Delete[{u}, List/@pos\[LeftDoubleBracket]1\[RightDoubleBracket]], Delete[{v}, List/@pos\[LeftDoubleBracket]1\[RightDoubleBracket]]]], Do[If[pos\[LeftDoubleBracket]2,ii\[RightDoubleBracket]\[Equal]2, term=CovariantD2d[ term,{v}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]], term=ContravariantD2d[ term,{u}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]]],{ii, Length[pos\[LeftDoubleBracket]2\[RightDoubleBracket]]}], term/.cov2d\[Rule] Identity}\[LeftDoubleBracket]4\[RightDoubleBracket]]] KroneckerAbsorbD[\[Delta]_][expr_]:=FixedPoint[Map[KAD[\[Delta]],#]&,expr] KroneckerAbsorbD[\[Delta]_][expr_]:=KAD[\[Delta]][expr] KAD[\[Delta]_][ HoldForm[CovariantD[t_,i_]]Tensor[\[Delta]_,{i_,Void},{Void,j_}]]:= HoldOp[CovariantD][CovariantD[t,j]] KAD[\[Delta]_][ HoldForm[CovariantD[t_,i_]]Tensor[\[Delta]_,{Void,i_},{j_,Void}]]:= HoldOp[CovariantD][CovariantD[t,j]] KAD[\[Delta]_][ HoldForm[CovariantD2d[t_,i_]]Tensor[\[Delta]_,{i_,Void},{Void,j_}]]:= HoldOp[CovariantD][CovariantD2d[t,j]] KAD[\[Delta]_][ HoldForm[CovariantD2d[t_,i_]]Tensor[\[Delta]_,{Void,i_},{j_,Void}]]:= HoldOp[CovariantD][CovariantD2d[t,j]] KAD[\[Delta]_][ HoldContravariantD[t_,i_]Tensor[\[Delta]_,{j_,Void},{Void,i_}]]:= HoldContravariantD[t,j] KAD[\[Delta]_][ HoldContravariantD[t_,i_]Tensor[\[Delta]_,{Void,j_},{i_,Void}]]:= HoldContravariantD[t,j] KAD[\[Delta]_][ HoldContravariantD2d[t_,i_]Tensor[\[Delta]_,{j_,Void},{Void,i_}]]:= HoldContravariantD2d[t,j] KAD[\[Delta]_][ HoldContravariantD2d[t_,i_]Tensor[\[Delta]_,{Void,j_},{i_,Void}]]:= HoldContravariantD2d[t,j] KAD[\[Delta]_][ HoldForm[CovariantD[t_,i_]]Tensor[\[Delta]_,{u_,Void},{Void,v_}]]:= HoldOp[CovariantD][ CovariantD[ KroneckerAbsorb[\[Delta]][t Tensor[\[Delta],{u,Void},{Void,v}]],i]] KAD[\[Delta]_][ HoldForm[CovariantD[t_,i_]]Tensor[\[Delta]_,{Void,v_},{u_,Void}]]:= HoldOp[CovariantD][ CovariantD[ KroneckerAbsorb[\[Delta]][t Tensor[\[Delta],{Void,v},{u,Void}]],i]] KAD[\[Delta]_][HoldCovariantD2d[t_,i_]Tensor[\[Delta]_,{u_,Void},{Void,v_}]]:= HoldCovariantD2d[ KroneckerAbsorb[\[Delta]][t Tensor[\[Delta],{u,Void},{Void,v}]],i] KAD[\[Delta]_][HoldCovariantD2d[t_,i_]Tensor[\[Delta]_,{Void,v_},{u_,Void}]]:= HoldCovariantD2d[ KroneckerAbsorb[\[Delta]][t Tensor[\[Delta],{Void,v},{u,Void}]],i] KAD[\[Delta]_][ HoldContravariantD[t_,i_]Tensor[\[Delta]_,{u_,Void},{Void,v_}]]:= HoldContravariantD[ KroneckerAbsorb[\[Delta]][t Tensor[\[Delta],{u,Void},{Void,v}]],i] KAD[\[Delta]_][ HoldContravariantD[t_,i_]Tensor[\[Delta]_,{Void,v_},{u_,Void}]]:= HoldContravariantD[ KroneckerAbsorb[\[Delta]][t Tensor[\[Delta],{Void,v},{u,Void}]],i] KAD[\[Delta]_][ HoldContravariantD2d[t_,i_]Tensor[\[Delta]_,{u_,Void},{Void,v_}]]:= HoldContravariantD2d[ KroneckerAbsorb[\[Delta]][t Tensor[\[Delta],{u,Void},{Void,v}]],i] KAD[\[Delta]_][ HoldContravariantD2d[t_,i_]Tensor[\[Delta]_,{Void,v_},{u_,Void}]]:= HoldContravariantD2d[ KroneckerAbsorb[\[Delta]][t Tensor[\[Delta],{Void,v},{u,Void}]],i] KAD[\[Delta]_][expr_]:=KroneckerAbsorb[\[Delta]][expr] PartialSumD[i_,j_][term_]:= Module[{ind1,ind2,r1,resu}, If[(ind1=ParseTermIndices[ term]\[LeftDoubleBracket]1\[RightDoubleBracket])=!={}, ind2:=Table[i0[n],{n,Length[ind1]}]; r1:=Thread/@ Table[Rule[ ind2\[LeftDoubleBracket]ii\[RightDoubleBracket],{i, j\[LeftDoubleBracket]ii\[RightDoubleBracket]}],{ii, Length[ind1]}];Off[Part::"pspec",ReplaceAll::"reps"];resu= (FuncSum[ Prepend[Table[{ia[kk],2},{kk,Length[ind1]}], term//IndexChange[{ind1,ind2}//Transpose]/.Table[ r1\[LeftDoubleBracket]jj, ia[jj]\[RightDoubleBracket],{jj, Length[ind1]}]]]/.FuncSum[{x__}]\[RuleDelayed]Sum[x]); On[Part::"pspec",ReplaceAll::"reps"];resu,term]] MetricRuleD[x_,g_][ expr_]:=(expr/.CovariantD[Tensor[x,{i_},{Void}],j_]\[RuleDelayed] If[Head[i]===Head[j] && BaseIndexQ[i]&& BaseIndexQ[j], Tensor[g,{i,Void},{Void,j}], CovariantD[Tensor[x,{i},{Void}],j]])/.Tensor[ g,{i_,Void},{Void,i_}]\[RuleDelayed]1/.Tensor[ g,{i_,Void},{Void,j_}]\[RuleDelayed]0 Kronecker[\[Delta]_][expr_]:= expr/.Tensor[\[Delta],{i_,Void},{Void,j_}]/;(BaseIndexQ[i]&& BaseIndexQ[j])\[RuleDelayed] If[Head[i]===Head[j],KroneckerDelta[RawIndex[i],RawIndex[j]], Tensor[\[Delta],{i,Void},{Void,j}]]/.Tensor[\[Delta],{Void,i_},{j_, Void}]/;(BaseIndexQ[i]&&BaseIndexQ[j])\[RuleDelayed] If[Head[i]===Head[j],KroneckerDelta[RawIndex[i],RawIndex[j]], Tensor[\[Delta],{Void,i},{j,Void}]] CovNotation[cov_][expr_]:=Module[{ind},expr//. {CovariantD[Tensor[t_], w_]\[RuleDelayed](flavor:=Head@First[{w}//Flatten]; Tensor[t,({Table[Void,{ind,Length[{w}//Flatten]}]}// Flatten),({flavor/@(ReplaceAll[#,Rule[flavor,cov]]&@ Flatten[{w}])}//Flatten)]), CovariantD[ Tensor[t_],{w1_,w2__}]\[RuleDelayed](flavor:= Head@First[{w1}//Flatten]; Tensor[t,({Table[Void,{ind,Length[{w1,w2}//Flatten]}]}// Flatten),({flavor/@(ReplaceAll[#,Rule[flavor,cov]]&@ Flatten[{w1,w2}])}//Flatten)]), CovariantD[Tensor[t_,{u__},{v__}], w_]\[RuleDelayed](flavor:=Head@First[{w}//Flatten]; Tensor[t,({u,Table[Void,{ind,Length[{w}//Flatten]}]}// Flatten),({v, flavor/@(ReplaceAll[#,Rule[flavor,cov]]&@Flatten[{w}])}// Flatten)]), HoldContravariantD[Tensor[t_], w_]\[RuleDelayed](flavor:=Head@First[{w}//Flatten]; Tensor[t,({flavor/@(ReplaceAll[#,Rule[flavor,cov]]&@ Flatten[{w}])}// Flatten),({Table[Void,{ind,Length[{w}//Flatten]}]}// Flatten)]), HoldContravariantD[Tensor[t_,{u__},{v__}], w_]\[RuleDelayed](flavor:=Head@First[{w}//Flatten]; Tensor[t,({u, flavor/@(ReplaceAll[#,Rule[flavor,cov]]&@Flatten[{w}])}// Flatten),({v,Table[Void,{ind,Length[{w}//Flatten]}]}// Flatten)])} ] Cov2dNotation[cov_][expr_]:=Module[{ind},expr//. {CovariantD2d[Tensor[t_], w_]\[RuleDelayed](flavor:=Head@First[{w}//Flatten]; Tensor[t,({Table[Void,{ind,Length[{w}//Flatten]}]}// Flatten),({flavor/@(ReplaceAll[#,Rule[flavor,cov]]&@ Flatten[{w}])}//Flatten)]), CovariantD2d[ Tensor[t_],{w1_,w2__}]\[RuleDelayed](flavor:= Head@First[{w1}//Flatten]; Tensor[t,({Table[Void,{ind,Length[{w1,w2}//Flatten]}]}// Flatten),({flavor/@(ReplaceAll[#,Rule[flavor,cov]]&@ Flatten[{w1,w2}])}//Flatten)]), CovariantD2d[Tensor[t_,{u__},{v__}], w_]\[RuleDelayed](flavor:=Head@First[{w}//Flatten]; Tensor[t,({u,Table[Void,{ind,Length[{w}//Flatten]}]}// Flatten),({v, flavor/@(ReplaceAll[#,Rule[flavor,cov]]&@Flatten[{w}])}// Flatten)]), ContravariantD2d[Tensor[t_], w_]\[RuleDelayed](flavor:=Head@First[{w}//Flatten]; Tensor[t,({flavor/@(ReplaceAll[#,Rule[flavor,cov]]&@ Flatten[{w}])}// Flatten),({Table[Void,{ind,Length[{w}//Flatten]}]}// Flatten)]), ContravariantD2d[Tensor[t_,{u__},{v__}], w_]\[RuleDelayed](flavor:=Head@First[{w}//Flatten]; Tensor[t,({u, flavor/@(ReplaceAll[#,Rule[flavor,cov]]&@Flatten[{w}])}// Flatten),({v,Table[Void,{ind,Length[{w}//Flatten]}]}// Flatten)])} ] ChristoffeluSymbol[\[DoubleStruckE]_,\[CapitalGamma]_,k_][expr_]:= expr/.{PartialD[Tensor[\[DoubleStruckE],{Void},{i_}],j_]\[RuleDelayed] If[Head[i]===Symbol, Tensor[\[DoubleStruckE],{Void},{k}]Tensor[\[CapitalGamma],{k,Void, Void},{Void,i,j}], Tensor[\[DoubleStruckE],{Void},{Head[i]@ k}]Tensor[\[CapitalGamma],{Head[i]@k,Void,Void},{Void,i, j}]],PartialD[Tensor[\[DoubleStruckE],{i_},{Void}], j_]\[RuleDelayed]If[ Head[i]=== Symbol,-Tensor[\[DoubleStruckE],{k},{Void}]Tensor[\ \[CapitalGamma],{i,Void,Void},{Void,j, k}],-Tensor[\[DoubleStruckE],{Head[i]@ k},{Void}]Tensor[\[CapitalGamma],{i,Void,Void},{Void,j, Head[i]@k}]]}; ChristoffeldSymbol[\[DoubleStruckE]_,\[CapitalGamma]_,k_][expr_]:= expr/.{PartialD[Tensor[\[DoubleStruckE],{Void},{i_}],j_]\[RuleDelayed] If[Head[i]===Symbol, Tensor[\[DoubleStruckE],{k},{Void}]Tensor[\[CapitalGamma],{Void, Void,Void},{k,i,j}], Tensor[\[DoubleStruckE],{Head[i]@ k},{Void}]Tensor[\[CapitalGamma],{Void,Void, Void},{Head[i]@k,i,j}]]}; LeviCivitaOrder[e_][expr_]:= expr/.{Tensor[e,{i_,j_,k_},{Void,Void,Void}]:> Signature[{i,j,k}]Tensor[e,Sort[{i,j,k}],{Void,Void,Void}], Tensor[e,{Void,Void,Void},{i_,j_,k_}]:> Signature[{i,j,k}]Tensor[e,{Void,Void,Void},Sort[{i,j,k}]], Tensor[e,{i_,j_,k_,Void},{Void,Void,Void,Cov[h_]}]\[RuleDelayed]0, Tensor[e,{Void,Void,Void,Void},{i_,j_,k_,Cov[h_]}]\[RuleDelayed]0, Tensor[e,{i_,j_,k_,Void,__},{Void,Void,Void, Cov[h_],__}]\[RuleDelayed]0, Tensor[e,{Void,Void,Void,Void,__},{i_,j_,k_, Cov[h_],__}]\[RuleDelayed]0}/.{Tensor[e,{i_,j_},{Void,Void}]:> Signature[{i,j}]Tensor[e,Sort[{i,j}],{Void,Void}], Tensor[e,{Void,Void},{i_,j_}]:> Signature[{i,j}]Tensor[e,{Void,Void},Sort[{i,j}]], Tensor[e,{i_,j_,Void},{Void,Void,Cov[h_]}]\[RuleDelayed]0, Tensor[e,{Void,Void,Void},{i_,j_,Cov[h_]}]\[RuleDelayed]0, Tensor[e,{i_,j_,Void,__},{Void,Void,Cov[h_],__}]\[RuleDelayed]0, Tensor[e,{Void,Void,Void,__},{i_,j_,Cov[h_],__}]\[RuleDelayed]0} FullLeviCivitaExpand[e_,g_][expr_]:= expr//.Module[{w$,i$,j$,perm2,sign2,perm2Up,perm2Down}, Tensor[e,ups1_,downs1_]Tensor[e,ups2_,downs2_]\[RuleDelayed] If[Length[ups1]==Length[ups2],(perm2:=Permutations[ups2+w$ downs2]; sign0:=Signature[ups2+w$ downs2];sign2:=Signature/@perm2; perm2Up:=perm2/.w$\[Rule]0; perm2Down:=perm2-perm2Up/.w$\[Rule]1; sign0 Sum[ sign2[[j$]]Product[ Tensor[ g,{ups1[[i$]],perm2Up[[j$,i$]]},{downs1[[i$]], perm2Down[[j$,i$]]}],{i$,Length[ups1]}],{j$, Length[perm2]}]//MetricSimplify[g]//Simplify)]] LeviCivitaSimplify[e_,\[Epsilon]_][g_,flavor_][expr_]:= expr/.Tensor[e,list1_,list2_]\[RuleDelayed] If[list1===Table[Void,{ii,Length[list1]}], Tensor[g,{Void},{flavor[g]}]*Tensor[\[Epsilon],list1,list2], If[list2===Table[Void,{ii,Length[list2]}], Tensor[g,{flavor[g]},{Void}]*Tensor[\[Epsilon],list1,list2], Print["Error ! Base Indices? "]]]/.{CovariantD[ Tensor[\[Epsilon],{i_,j_,k_},{Void,Void, Void}],{m_,___}]\[RuleDelayed]If[Head[i]\[Equal]Head[m],0], PartialD[ Tensor[\[Epsilon],{i_,j_,k_},{Void,Void, Void}],{m_,___}]\[RuleDelayed]If[Head[i]\[Equal]Head[m],0], CovariantD[ Tensor[\[Epsilon],{Void,Void,Void},{i_,j_, k_}],{m_,___}]\[RuleDelayed]If[Head[i]\[Equal]Head[m],0], PartialD[ Tensor[\[Epsilon],{Void,Void,Void},{i_,j_, k_}],{m_,___}]\[RuleDelayed] If[Head[i]\[Equal]Head[m],0]}/.{Tensor[ g,{Void},{flavor[g]}]\[RuleDelayed]Sqrt[Tensor[flavor[g]]], Tensor[g,{flavor[g]},{Void}]\[RuleDelayed]1/Sqrt[Tensor[flavor[g]]], PartialD[Tensor[g,{Void},{flavor[g]}], flavor[m_]]\[Rule](1/(2*Sqrt[Tensor[flavor[g]]]))* PartialD[Tensor[flavor[g]],flavor[m]], PartialD[Tensor[g,{flavor[g]},{Void}], flavor[m_]]\[Rule]((-(1/2))*PartialD[Tensor[flavor[g]],flavor[m]])/ Tensor[flavor[g]]^(3/2)} LeviCivitaSimplify[e_,\[Epsilon]_][g_][expr_]:= LeviCivitaSimplify[e,\[Epsilon]][g,black][expr] CrossProductExpansion[\[DoubleStruckE]_,e_,h_][expr_]:=expr/. {Tensor[\[DoubleStruckE],{i_},{Void}]\[Cross] Tensor[\[DoubleStruckE],{j_},{Void}].Tensor[\[DoubleStruckE],{k_\ },{Void}]\[RuleDelayed]Tensor[e,{i,j,k},{Void,Void,Void}], Tensor[\[DoubleStruckE],{i_},{Void}]\[Cross] Tensor[\[DoubleStruckE],{j_},{Void}].Tensor[\[DoubleStruckE],{\ Void},{k_}]\[RuleDelayed]Tensor[e,{i,j,Void},{Void,Void,k}], Tensor[\[DoubleStruckE],{i_},{Void}]\[Cross] Tensor[\[DoubleStruckE],{Void},{j_}].Tensor[\[DoubleStruckE],{k_\ },{Void}]\[RuleDelayed]Tensor[e,{i,Void,k},{Void,j,Void}], Tensor[\[DoubleStruckE],{i_},{Void}]\[Cross] Tensor[\[DoubleStruckE],{Void},{j_}].Tensor[\[DoubleStruckE],{\ Void},{k_}]\[RuleDelayed]Tensor[e,{i,Void,Void},{Void,j,k}], Tensor[\[DoubleStruckE],{Void},{i_}]\[Cross] Tensor[\[DoubleStruckE],{j_},{Void}].Tensor[\[DoubleStruckE],{\ Void},{k_}]\[RuleDelayed]Tensor[e,{Void,j,Void},{i,Void,k}], Tensor[\[DoubleStruckE],{Void},{i_}]\[Cross] Tensor[\[DoubleStruckE],{j_},{Void}].Tensor[\[DoubleStruckE],{k_\ },{Void}]\[RuleDelayed]Tensor[e,{Void,j,k},{i,Void,Void}], Tensor[\[DoubleStruckE],{Void},{i_}]\[Cross] Tensor[\[DoubleStruckE],{Void},{j_}].Tensor[\[DoubleStruckE],{k_\ },{Void}]\[RuleDelayed]Tensor[e,{Void,Void,k},{i,j,Void}], Tensor[\[DoubleStruckE],{Void},{i_}]\[Cross] Tensor[\[DoubleStruckE],{Void},{j_}].Tensor[\[DoubleStruckE],{\ Void},{k_}]\[RuleDelayed]Tensor[e,{Void,Void,Void},{i,j,k}], Tensor[\[DoubleStruckE],{Void},{i_}]\[Cross] Tensor[\[DoubleStruckE],{j_},{Void}]\[RuleDelayed] If[Head[i]=!=Symbol , If[Head[i]===Head[j], Tensor[e,{Void,j,Void},{i,Void, Head[i][h]}] Tensor[\[DoubleStruckE],{Head[i][h]},{Void}], Print[Head[i],"Error : not in the same flavor"]], Tensor[e,{Void,j,Void},{i,Void, h}] Tensor[\[DoubleStruckE],{h},{Void}]], Tensor[\[DoubleStruckE],{i_},{Void}]\[Cross] Tensor[\[DoubleStruckE],{Void},{j_}]\[RuleDelayed] If[Head[i]=!=Symbol, If[Head[i]===Head[j], Tensor[e,{i,Void,Head[i][h]},{Void,j, Void}] Tensor[\[DoubleStruckE],{Void},{Head[i][h]}], Print[Head[i],"Error : not in the same flavor"]], Tensor[e,{i,Void,h},{Void,j, Void}] Tensor[\[DoubleStruckE],{Void},{h}]], Tensor[\[DoubleStruckE],{Void},{i_}]\[Cross]Tensor[\[DoubleStruckE],{\ Void},{j_}]\[RuleDelayed]If[Head[i]=!=Symbol, If[Head[i]===Head[j], Tensor[e,{Void,Void,Void},{i,j, Head[i][h]}] Tensor[\[DoubleStruckE],{Head[i][h]},{Void}], Print[Head[i],"Error : not in the same flavor"]], Tensor[e,{Void,Void,Void},{i,j, h}] Tensor[\[DoubleStruckE],{h},{Void}]], Tensor[\[DoubleStruckE],{i_},{Void}]\[Cross]Tensor[\[DoubleStruckE],{\ j_},{Void}]\[RuleDelayed]If[Head[i]=!=Symbol, If[Head[i]===Head[j], Tensor[e,{i,j,Head[i][h]},{Void,Void, Void}] Tensor[\[DoubleStruckE],{Void},{Head[i][h]}], Print[Head[i],"Error : not in the same flavor"]], Tensor[e,{i,j,h},{Void,Void, Void}] Tensor[\[DoubleStruckE],{Void},{h}]]}/.{Tensor[ e,{i_,j_,k_},{Void,Void, Void}]\[RuleDelayed]0/;((i==j) || (j==k) || (k==i)), Tensor[e,{Void,Void,Void},{i_,j_, k_}]\[RuleDelayed]0/;((i==j) || (j==k) || (k==i))} MetricTripleProduct[basis_,metric_,LeviCivita_,k_][expr_]:=(Print["\!\(\* StyleBox[\"Warning\",\nFontColor->RGBColor[0, 0, 1]]\) : be sure that index '", k,"' does not appear in ",expr ]; expr//LinearBreakout[Cross][Tensor[basis,{_},{Void}], Tensor[basis,{Void},{_}]])// CrossProductExpansion[basis,LeviCivita,k]// LinearBreakout[Dot][Tensor[basis,{_},{Void}], Tensor[basis,{Void},{_}]]//EvaluateDotProducts[basis,metric,False]// MetricSimplify[metric] EvaluateCrossProducts[\[DoubleStruckE]_,e_,g_,h_][ expr_]:=(expr// LinearBreakout[Cross][Tensor[\[DoubleStruckE],{_},{Void}], Tensor[\[DoubleStruckE],{Void},{_}]]// CrossProductExpansion[\[DoubleStruckE],e,h]// FullLeviCivitaExpand[e,g]// MetricSimplify[g])/.{Tensor[g,{i_,Void},{Void,i_}]\[RuleDelayed]NDim, Tensor[g,{Void,i_},{i_,Void}]\[RuleDelayed]NDim} VolumeSquare[flavor_@g_][expr_]:= expr/.Tensor[flavor@g]\[RuleDelayed]( Det[Tensor[g,{Void,Void},{flavor@i,flavor@j}]// ArrayExpansion[flavor@i,flavor@j]]/.TensorValueRules[g]) VolumeSquare[g_][expr_]:= expr/.Tensor[ g]\[RuleDelayed] (Det[ Tensor[g,{Void,Void},{i,j}]// ArrayExpansion[i,j]]/.TensorValueRules[g]) SetContravariantDisplay[mode:"SemicolonMode"|"DelMode"]:= Switch[mode, "SemicolonMode",MakeBoxes[HoldContravariantD[t_,indices_], form:StandardForm|TraditionalForm]:= Module[{windx=Flatten[{indices}]}, If[MatchQ[t, Tensor[_,_,_]|Tensor[f_Symbol]|CovariantD[__]], InterpretationBox[#1,#2,Editable\[Rule]False]&@@{SuperscriptBox[ MakeBoxes[t,form], RowBox[{CovSym,RowBox@(MakeBoxes[#,form]&/@windx)}]], HoldContravariantD[t,indices]}, InterpretationBox[#1,#2,Editable\[Rule]False]&@@{SuperscriptBox[ RowBox[{"(",MakeBoxes[t,form],")"}], RowBox[{CovSym,RowBox@(MakeBoxes[#,form]&/@windx)}]], HoldContravariantD[t,indices]}]], "DelMode", MakeBoxes[HoldContravariantD[t_,indices_], form:StandardForm|TraditionalForm]:= Module[{windx=Flatten[{indices}]}, Switch[t, Tensor[_,_,_]|Tensor[Tensor[_Symbol]]|Tensor[_Symbol|_Tensor]| HoldContravariantD[__]|CovariantD[__], InterpretationBox[#1,#2, Editable\[Rule] False]&@@{RowBox[{SuperscriptBox["\[Del]", RowBox@(MakeBoxes[#,form]&/@windx)],MakeBoxes[t,form]}], HoldContravariantD[t,indices]}, _, InterpretationBox[#1,#2, Editable\[Rule] False]&@@{RowBox[{SuperscriptBox["\[Del]", RowBox@(MakeBoxes[#,form]&/@windx)], RowBox[{"(",MakeBoxes[t,form],")"}]}], HoldContravariantD[t,indices]}]]] HoldContravariantD[HoldContravariantD[Tensor[t_],i_],j_]:= HoldContravariantD[Tensor[t],{i,j}] HoldContravariantD[HoldContravariantD[Tensor[t_,{u__},{v__}],{i__}],j_]:= HoldContravariantD[Tensor[t,{u},{v}],{i,j}] HoldContravariantD[HoldContravariantD[Tensor[t_],i_],{j__}]:= HoldContravariantD[Tensor[t],{i,j}] HoldContravariantD[HoldContravariantD[Tensor[t_,{u__},{v__}],i_],j_]:= HoldContravariantD[Tensor[t,{u},{v}],{i,j}] HoldContravariantD[HoldContravariantD[Tensor[t_],{i__}],j_]:= HoldContravariantD[Tensor[t],{i,j}] HoldContravariantD[HoldContravariantD[Tensor[t_,{u__},{v__}],{i__}],j_]:= HoldContravariantD[Tensor[t,{u},{v}],{i,j}] HoldContravariantD[HoldContravariantD[CovariantD[Tensor[t__],k_],i_],j_]:= HoldContravariantD[CovariantD[Tensor[t],k],{i,j}] HoldContravariantD[ HoldContravariantD[CovariantD[Tensor[t_,{u__},{v__}],k_],i_],j_]:= HoldContravariantD[CovariantD[Tensor[t,{u},{v}],k],{i,j}] HoldContravariantD[HoldContravariantD[CovariantD[Tensor[t_],k_],i_],{j__}]:= HoldContravariantD[CovariantD[Tensor[t],k],{i,j}] HoldContravariantD[ HoldContravariantD[CovariantD[Tensor[t_,{u__},{v__}],k_],i_],{j__}]:= HoldContravariantD[CovariantD[Tensor[t,{u},{v}],k],{i,j}] HoldContravariantD[HoldContravariantD[CovariantD[Tensor[t_],k_],{i__}],j_]:= HoldContravariantD[CovariantD[Tensor[t],k],{i,j}] HoldContravariantD[ HoldContravariantD[CovariantD[Tensor[t_,{u__},{v__}],k_],{i__}],j_]:= HoldContravariantD[CovariantD[Tensor[t,{u},{v}],k],{i,j}] HoldContravariantD[HoldContravariantD[CovariantD[Tensor[t_],{k__}],i_],j_]:= HoldContravariantD[CovariantD[Tensor[t],{k}],{i,j}] HoldContravariantD[ HoldContravariantD[CovariantD[Tensor[t_,{u__},{v__}],{k__}],i_],j_]:= HoldContravariantD[CovariantD[Tensor[t,{u},{v}],{k}],{i,j}] HoldContravariantD[HoldContravariantD[CovariantD[Tensor[t_],{k__}],i_],{j__}]:= HoldContravariantD[CovariantD[Tensor[t],{k}],{i,j}] HoldContravariantD[ HoldContravariantD[CovariantD[Tensor[t_,{u__},{v__}],{k__}],i_],{j__}]:= HoldContravariantD[CovariantD[Tensor[t,{u},{v}],{k}],{i,j}] HoldContravariantD[HoldContravariantD[CovariantD[Tensor[t_],{k__}],{i__}],j_]:= HoldContravariantD[CovariantD[Tensor[t],{k}],{i,j}] HoldContravariantD[ HoldContravariantD[CovariantD[Tensor[t_,{u__},{v__}],{k__}],{i__}],j_]:= HoldContravariantD[CovariantD[Tensor[t,{u},{v}],{k}],{i,j}] HoldContravariantD[HoldContravariantD[Tensor[t_],{i_,j__}],{k__}]:= HoldContravariantD[Tensor[t],{i,j,k}] HoldContravariantD[HoldContravariantD[Tensor[t_,{u__},{v__}],{i_,j__}],{k__}]:= HoldContravariantD[Tensor[t,{u},{v}],{i,j,k}] HoldContravariantD[HoldContravariantD[Tensor[t__],{i_,j__}],k_]:= HoldContravariantD[Tensor[t],{i,j,k}] HoldContravariantD[HoldContravariantD[Tensor[t_,{u__},{v__}],{i_,j__}],k_]:= HoldContravariantD[Tensor[t,{u},{v}],{i,j,k}] SetContravariantD2display[mode:"SemicolonMode"|"DelMode"]:= Switch[mode, "SemicolonMode",MakeBoxes[HoldContravariantD2d[t_,indices_], form:StandardForm|TraditionalForm]:= Module[{windx=Flatten[{indices}]}, If[MatchQ[t, Tensor[_,_,_]|Tensor[f_Symbol]|CovariantD[__]], InterpretationBox[#1,#2,Editable\[Rule]False]&@@{SuperscriptBox[ MakeBoxes[t,form], RowBox[{CovSym,RowBox@(MakeBoxes[#,form]&/@windx)}]], HoldContravariantD2d[t,indices]}, InterpretationBox[#1,#2,Editable\[Rule]False]&@@{SuperscriptBox[ RowBox[{"(",MakeBoxes[t,form],")"}], RowBox[{CovSym,RowBox@(MakeBoxes[#,form]&/@windx)}]], HoldContravariantD2d[t,indices]}]], "DelMode", MakeBoxes[HoldContravariantD2d[t_,indices_], form:StandardForm|TraditionalForm]:= Module[{windx=Flatten[{indices}]}, Switch[t, Tensor[_,_,_]|Tensor[Tensor[_Symbol]]|Tensor[_Symbol|_Tensor]| HoldContravariantD2d[__]|CovariantD[__], InterpretationBox[#1,#2, Editable\[Rule] False]&@@{RowBox[{SuperscriptBox["\[Del]", RowBox@(MakeBoxes[#,form]&/@windx)],MakeBoxes[t,form]}], HoldContravariantD2d[t,indices]}, _, InterpretationBox[#1,#2, Editable\[Rule] False]&@@{RowBox[{SuperscriptBox["\[Del]", RowBox@(MakeBoxes[#,form]&/@windx)], RowBox[{"(",MakeBoxes[t,form],")"}]}], HoldContravariantD2d[t,indices]}]]] HoldContravariantD2d[HoldContravariantD2d[Tensor[t_],i_],j_]:= HoldContravariantD2d[Tensor[t],{i,j}] HoldContravariantD2d[HoldContravariantD2d[Tensor[t_,{u__},{v__}],{i__}],j_]:= HoldContravariantD2d[Tensor[t,{u},{v}],{i,j}] HoldContravariantD2d[HoldContravariantD2d[Tensor[t_],i_],{j__}]:= HoldContravariantD2d[Tensor[t],{i,j}] HoldContravariantD2d[HoldContravariantD2d[Tensor[t_,{u__},{v__}],i_],j_]:= HoldContravariantD2d[Tensor[t,{u},{v}],{i,j}] HoldContravariantD2d[HoldContravariantD2d[Tensor[t_],{i__}],j_]:= HoldContravariantD2d[Tensor[t],{i,j}] HoldContravariantD2d[HoldContravariantD2d[Tensor[t_,{u__},{v__}],{i__}],j_]:= HoldContravariantD2d[Tensor[t,{u},{v}],{i,j}] HoldContravariantD2d[HoldContravariantD2d[CovariantD[Tensor[t__],k_],i_],j_]:= HoldContravariantD2d[CovariantD[Tensor[t],k],{i,j}] HoldContravariantD2d[ HoldContravariantD2d[CovariantD[Tensor[t_,{u__},{v__}],k_],i_],j_]:= HoldContravariantD2d[CovariantD[Tensor[t,{u},{v}],k],{i,j}] HoldContravariantD2d[ HoldContravariantD2d[CovariantD[Tensor[t_],k_],i_],{j__}]:= HoldContravariantD2d[CovariantD[Tensor[t],k],{i,j}] HoldContravariantD2d[ HoldContravariantD2d[CovariantD[Tensor[t_,{u__},{v__}],k_],i_],{j__}]:= HoldContravariantD2d[CovariantD[Tensor[t,{u},{v}],k],{i,j}] HoldContravariantD2d[HoldContravariantD2d[CovariantD[Tensor[t_],k_],{i__}], j_]:=HoldContravariantD2d[CovariantD[Tensor[t],k],{i,j}] HoldContravariantD2d[ HoldContravariantD2d[CovariantD[Tensor[t_,{u__},{v__}],k_],{i__}],j_]:= HoldContravariantD2d[CovariantD[Tensor[t,{u},{v}],k],{i,j}] HoldContravariantD2d[HoldContravariantD2d[CovariantD[Tensor[t_],{k__}],i_], j_]:=HoldContravariantD2d[CovariantD[Tensor[t],{k}],{i,j}] HoldContravariantD2d[ HoldContravariantD2d[CovariantD[Tensor[t_,{u__},{v__}],{k__}],i_],j_]:= HoldContravariantD2d[CovariantD[Tensor[t,{u},{v}],{k}],{i,j}] HoldContravariantD2d[ HoldContravariantD2d[CovariantD[Tensor[t_],{k__}],i_],{j__}]:= HoldContravariantD2d[CovariantD[Tensor[t],{k}],{i,j}] HoldContravariantD2d[ HoldContravariantD2d[CovariantD[Tensor[t_,{u__},{v__}],{k__}],i_],{j__}]:= HoldContravariantD2d[CovariantD[Tensor[t,{u},{v}],{k}],{i,j}] HoldContravariantD2d[HoldContravariantD2d[CovariantD[Tensor[t_],{k__}],{i__}], j_]:=HoldContravariantD2d[CovariantD[Tensor[t],{k}],{i,j}] HoldContravariantD2d[ HoldContravariantD2d[CovariantD[Tensor[t_,{u__},{v__}],{k__}],{i__}],j_]:= HoldContravariantD2d[CovariantD[Tensor[t,{u},{v}],{k}],{i,j}] HoldContravariantD2d[HoldContravariantD2d[Tensor[t_],{i_,j__}],{k__}]:= HoldContravariantD2d[Tensor[t],{i,j,k}] HoldContravariantD2d[ HoldContravariantD2d[Tensor[t_,{u__},{v__}],{i_,j__}],{k__}]:= HoldContravariantD2d[Tensor[t,{u},{v}],{i,j,k}] HoldContravariantD2d[HoldContravariantD2d[Tensor[t__],{i_,j__}],k_]:= HoldContravariantD2d[Tensor[t],{i,j,k}] HoldContravariantD2d[HoldContravariantD2d[Tensor[t_,{u__},{v__}],{i_,j__}], k_]:=HoldContravariantD2d[Tensor[t,{u},{v}],{i,j,k}] ReleaseHoldD[expr_]:=(SetScalarSingleCovariantD[True]; SetScalarSingleCovariantD[ False];(((expr//UnnestTensor//ReleaseHold)/.{CovariantD\[RuleDelayed] CovariantDTemp, HoldContravariantD\[RuleDelayed] CovariantD}/.{CovariantDTemp\[RuleDelayed]CovariantD, CovariantD\[RuleDelayed] HoldContravariantD})/.{HoldContravariantD2d\[RuleDelayed] CovariantD, CovariantD\[RuleDelayed] CovariantDTemp}/.{CovariantDTemp\[RuleDelayed]CovariantD, CovariantD\[RuleDelayed]HoldContravariantD2d})) ContravariantD[term_,i_]:=ReleaseHoldD[HoldContravariantD[term,i]] ContravariantD2d[term_,i_]:=ReleaseHoldD[HoldContravariantD2d[term,i]] CovariantDSimplify[\[DoubleStruckE]_,g_,e_][ expr_]:=(If[SymbolSpaceDimension[\[DoubleStruckE]]=!=NDim,Print["\!\(\* StyleBox[\"CovariantDSimplify\",\nFontColor->RGBColor[0, 0, 1]]\) warning : the present dimension is NDim = ",NDim, ": check if the basis or the metric tensor are correct!"]]; expr/.{CovariantD[Tensor[\[DoubleStruckE],i_,j_],k_]\[RuleDelayed]0, CovariantD[Tensor[g,i_,j_],k_]\[RuleDelayed]0, CovariantD[Tensor[e,i_,j_],k_]\[RuleDelayed]0, HoldContravariantD[Tensor[\[DoubleStruckE],i_,j_], k_]\[RuleDelayed]0, HoldContravariantD[Tensor[g,i_,j_],k_]\[RuleDelayed]0, HoldContravariantD[Tensor[e,i_,j_], k_]\[RuleDelayed]0}/.{CovariantD2d[ Tensor[\[DoubleStruckE],i_,j_],k_]\[RuleDelayed]0, CovariantD2d[Tensor[g,i_,j_],k_]\[RuleDelayed]0, CovariantD2d[Tensor[e,i_,j_],k_]\[RuleDelayed]0, ContravariantD2d[Tensor[\[DoubleStruckE],i_,j_],k_]\[RuleDelayed]0, ContravariantD2d[Tensor[g,i_,j_],k_]\[RuleDelayed]0, ContravariantD2d[Tensor[e,i_,j_],k_]\[RuleDelayed]0}) CovariantDSimplify[g_][expr_]:= expr/.{CovariantD[Tensor[g,i_,j_],k_]\[RuleDelayed]0, CovariantD2d[Tensor[g,i_,j_],k_]\[RuleDelayed]0, HoldContravariantD[Tensor[g,i_,j_],k_]\[RuleDelayed]0, HoldContravariantD2d[Tensor[g,i_,j_],k_]\[RuleDelayed]0} CovariantDSimplify[g_,1][expr_]:= If[SymbolSpaceDimension[g]=!= 2,(expr/.{HoldCovariantD[t__,w_]Tensor[g,{u__},{v__}]\[RuleDelayed] HoldCovariantD[t Tensor[g,{u},{v}],w], HoldContravariantD[t__,w_]Tensor[g,{u__},{v__}]\[RuleDelayed] HoldContravariantD[t Tensor[g,{u},{v}], w]}),(expr/.{HoldCovariantD2d[t__,w_]Tensor[ g,{u__},{v__}]\[RuleDelayed] HoldCovariantD2d[t Tensor[g,{u},{v}],w], HoldContravariantD2d[t__,w_]Tensor[g,{u__},{v__}]\[RuleDelayed] HoldContravariantD2d[t Tensor[g,{u},{v}],w]})] CovariantDOrdering[ expr_]:=(If[ Position[expr,CovariantD[Tensor[t_, {u___}, {v___}],{i___}]]=!={}, Print["We can use \!\(\* StyleBox[\"CovariantDOrdering\",\nFontWeight->\"Bold\",\nFontColor->RGBColor[0, 0, 1]]\) if the space has a zero Gaussian curvature !"]]; expr//.{CovariantD[Tensor[T_],{i_,j__}]\[RuleDelayed] CovariantD[Tensor[T],Sort[{i,j}//Flatten]], CovariantD[Tensor[t_, {u___}, {v___}],{i___}]\[RuleDelayed] CovariantD[Tensor[t, {u}, {v}],Sort[{i}//Flatten]], CovariantD[HoldContravariantD[Tensor[T_],h_],{i___}]\[RuleDelayed] CovariantD[HoldContravariantD[Tensor[T],h],Sort[{i}//Flatten]], CovariantD[ HoldContravariantD[Tensor[t_, {u___}, {v___}], h_],{i___}]\[RuleDelayed] CovariantD[HoldContravariantD[Tensor[t, {u}, {v}],h], Sort[{i}//Flatten]], CovariantD[ HoldContravariantD[Tensor[T_],{h__}],{i___}]\[RuleDelayed] CovariantD[HoldContravariantD[Tensor[T],{h}],Sort[{i}//Flatten]], CovariantD[ HoldContravariantD[ Tensor[t_, {u___}, {v___}],{h__}],{i___}]\[RuleDelayed] CovariantD[HoldContravariantD[Tensor[t, {u}, {v}],{h}], Sort[{i}//Flatten]] }) ExpandCovariantD2d[{x_,\[Delta]_,g_,\[CapitalGamma]_},a_][expr_]:= If[SymbolSpaceDimension[\[CapitalGamma]]\[Equal]2 && SymbolSpaceDimension[g]\[Equal]2, ExpandCovariantD[{x,\[Delta],g,\[CapitalGamma]},a][ expr/.{HoldCovariantD2d\[RuleDelayed]CovariantD, CovariantD\[RuleDelayed] HoldCovariantD}]/.{HoldCovariantD\[RuleDelayed]CovariantD, CovariantD\[RuleDelayed]HoldCovariantD2d},expr] ExpandCovariantD2d[{x_,\[Delta]_,g_,\[CapitalGamma]_},a_,TrueFalse_][expr_]:= If[SymbolSpaceDimension[\[CapitalGamma]]\[Equal]2 && SymbolSpaceDimension[g]\[Equal]2, ExpandCovariantD[{x,\[Delta],g,\[CapitalGamma]},a,TrueFalse][ expr/.{HoldCovariantD2d\[RuleDelayed]CovariantD, CovariantD\[RuleDelayed] HoldCovariantD}]/.{HoldCovariantD\[RuleDelayed]CovariantD, CovariantD\[RuleDelayed]HoldCovariantD2d},expr] CovariantD2d[T_,k__]:= CovariantD[ T/.{HoldCovariantD2d\[Rule]CovariantD,CovariantD\[Rule]HoldCovariantD}, k]/.{CovariantD\[Rule]HoldCovariantD2d,HoldCovariantD\[Rule]CovariantD} CovariantD2d[T_,{\[Rho]_,\[Sigma]__}]:= CovariantD2d[CovariantD2d[T,\[Rho]],{\[Sigma]}] MakeBoxes[HoldCovariantD2d[t_,indices_],form:StandardForm|TraditionalForm]:= Module[{windx=Flatten[{indices}]}, If[MatchQ[t, Tensor[_,_,_]|Tensor[f_Symbol]], InterpretationBox[#1,#2,Editable\[Rule]False]&@@{SubscriptBox[ MakeBoxes[t,form],RowBox[{"|\!\(\* StyleBox[\" \",\nFontSize->2]\)",RowBox@(MakeBoxes[#,form]&/@windx)}]],HoldCovariantD2d[t,indices]}, InterpretationBox[#1,#2,Editable\[Rule]False]&@@{SubscriptBox[ RowBox[{"(",MakeBoxes[t,form],")"}],RowBox[{"|\!\(\* StyleBox[\" \",\nFontSize->2]\)",RowBox@(MakeBoxes[#,form]&/@windx)}]],HoldCovariantD2d[t,indices]}]] ContravariantD2d[T_,k__]:= HoldContravariantD[ T/.{HoldContravariantD2d\[Rule]HoldContravariantD, HoldContravariantD\[Rule]HoldContravariant\[Section]D}, k]/.{HoldContravariantD\[Rule]HoldContravariantD2d, HoldContravariant\[Section]D\[Rule]HoldContravariantD} ContravariantD2d[T_,{\[Rho]_,\[Sigma]__}]:= ContravariantD2d[ContravariantD2d[T,\[Rho]],{\[Sigma]}] MakeBoxes[HoldContravariantD2d[t_,indices_], form:StandardForm|TraditionalForm]:= Module[{windx=Flatten[{indices}]}, If[MatchQ[t, Tensor[_,_,_]|Tensor[f_Symbol]], InterpretationBox[#1,#2,Editable\[Rule]False]&@@{SuperscriptBox[ MakeBoxes[t,form],RowBox[{"|\!\(\* StyleBox[\" \",\nFontSize->2]\)",RowBox@(MakeBoxes[#,form]&/@windx)}]],HoldContravariantD2d[t,indices]}, InterpretationBox[#1,#2,Editable\[Rule]False]&@@{SuperscriptBox[ RowBox[{"(",MakeBoxes[t,form],")"}],RowBox[{"|\!\(\* StyleBox[\" \",\nFontSize->2]\)",RowBox@(MakeBoxes[#,form]&/@windx)}]],HoldContravariantD2d[t,indices]}]] TensorComponentsD[g_][expr_]:= expr/.{PartialD[Tensor[t_,{ups1__},{downs1__}], Tensor[t_,{ups2__},{downs2__}]]\[RuleDelayed] If[Length[{ups1}]\[Equal]Length[{ups2}]&& Length[{downs1}]\[Equal]Length[{downs2}], Product[Tensor[g,{{ups1}[[i$]],{downs2}[[i$]]},{Void,Void}],{i$, Length[{ups1}]}] Product[ Tensor[g,{{ups1}[[i$]],Void},{Void,{ups2}[[i$]]}],{i$, Length[{ups1}]}]* Product[Tensor[ g,{{downs2}[[i$]],Void},{Void,{downs1}[[i$]]}],{i$, Length[{ups1}]}]Product[ Tensor[g,{Void,Void},{{ups2}[[i$]],{downs1}[[i$]]}],{i$, Length[{ups1}]}]/.{Tensor[g,{i_,Void},{Void,Void}]\[Rule]1, Tensor[g,{Void,i_},{Void,Void}]\[Rule]1, Tensor[g,{Void,Void},{i_,Void}]\[Rule]1, Tensor[g,{Void,Void},{Void,i_}]\[Rule]1},0], PartialD[{x_,\[Delta]_,g,\[CapitalGamma]_}][ Tensor[t_,{ups1__},{downs1__}], Tensor[t_,{ups2__},{downs2__}]]\[RuleDelayed] If[Length[{ups1}]\[Equal]Length[{ups2}]&& Length[{downs1}]\[Equal]Length[{downs2}], Product[Tensor[g,{{ups1}[[i$]],{downs2}[[i$]]},{Void,Void}],{i$, Length[{ups1}]}]Product[ Tensor[g,{{ups1}[[i$]],Void},{Void,{ups2}[[i$]]}],{i$, Length[{ups1}]}]* Product[Tensor[ g,{{downs2}[[i$]],Void},{Void,{downs1}[[i$]]}],{i$, Length[{ups1}]}]Product[ Tensor[g,{Void,Void},{{ups2}[[i$]],{downs1}[[i$]]}],{i$, Length[{ups1}]}]/.{Tensor[g,{i_,Void},{Void,Void}]\[Rule]1, Tensor[g,{Void,i_},{Void,Void}]\[Rule]1, Tensor[g,{Void,Void},{i_,Void}]\[Rule]1, Tensor[g,{Void,Void},{Void,i_}]\[Rule]1},0]} PartialDToDif[expr_]:= expr//.PartialD[{x_,\[Delta]_,g_,\[CapitalGamma]_}][Tensor[t__], i_]\[RuleDelayed]PartialD[ Tensor[t],(i/.Tensor[x,{j_},{Void}]\[Rule]j)] DifToPartialD[{x_,\[Delta]_,g_,\[CapitalGamma]_}][expr_]:= Module[{PD}, expr/.PartialD\[Rule]PD/.PD[y_,var_List]\[RuleDelayed] PartialD[{x,\[Delta],g,\[CapitalGamma]}][y, Tensor[x,{#},{Void}]&/@var]/.PD[y_,var_]\[RuleDelayed] PartialD[{x,\[Delta],g,\[CapitalGamma]}][y,Tensor[x,{var},{Void}]]] PartialDOrdering[expr_]:=expr//.{ PartialD[Tensor[T_],{i___}]\[RuleDelayed] PartialD[Tensor[T],Sort[{i}//Flatten]], PartialD[Tensor[t_, {u___}, {v___}],{i___}]\[RuleDelayed] PartialD[Tensor[t, {u}, {v}],Sort[{i}//Flatten]] } DifToCov[\[CapitalGamma]_,m_][{u_,i_},j_][expr_]:= expr/.{PartialD[Tensor[u,{i},{Void}],j]\[RuleDelayed] CovariantD[Tensor[u,{i},{Void}],j]- Tensor[u,{m},{Void}]Tensor[\[CapitalGamma],{i,Void,Void},{Void,j, m}],PartialD[Tensor[u,{Void},{i}],j]\[RuleDelayed] CovariantD[Tensor[u,{Void},{i}],j]+ Tensor[u,{Void},{m}]Tensor[\[CapitalGamma],{m,Void,Void},{Void,i, j}]} DifToCov[\[CapitalGamma]_,m_,h_][{u_,i_},{j_,k_}][expr_]:= expr/.{PartialD[Tensor[u,{Void},{i}],{j,k}]\[Rule] CovariantD[Tensor[u,{Void},{i}],{j,k}]+ CovariantD[Tensor[u,{Void},{h}],j]* Tensor[\[CapitalGamma],{h,Void,Void},{Void,i,k}]+ CovariantD[Tensor[u,{Void},{i}],h]* Tensor[\[CapitalGamma],{h,Void,Void},{Void,j,k}]+ CovariantD[Tensor[u,{Void},{m}],k]* Tensor[\[CapitalGamma],{m,Void,Void},{Void,i,j}]+ Tensor[u,{Void},{h}]* Tensor[\[CapitalGamma],{h,Void,Void},{Void,k,m}]* Tensor[\[CapitalGamma],{m,Void,Void},{Void,i,j}]+ Tensor[u,{Void},{m}]* PartialD[Tensor[\[CapitalGamma],{m,Void,Void},{Void,i,j}],k], PartialD[Tensor[u,{i},{Void}],{j,k}]\[Rule] CovariantD[Tensor[u,{i},{Void}],{j,k}]+ CovariantD[Tensor[u,{i},{Void}],h]* Tensor[\[CapitalGamma],{h,Void,Void},{Void,j,k}]- CovariantD[Tensor[u,{h},{Void}],j]* Tensor[\[CapitalGamma],{i,Void,Void},{Void,h,k}]- CovariantD[Tensor[u,{m},{Void}],k]* Tensor[\[CapitalGamma],{i,Void,Void},{Void,j,m}]+ Tensor[u,{h},{Void}]* Tensor[\[CapitalGamma],{i,Void,Void},{Void,j,m}]* Tensor[\[CapitalGamma],{m,Void,Void},{Void,h,k}]- Tensor[u,{m},{Void}]* PartialD[Tensor[\[CapitalGamma],{i,Void,Void},{Void,j,m}],k]} PartialDSimplify[expr_]:= Module[{pos,tab}, expr/.PartialD[u_][Tensor[v_], w_]\[RuleDelayed](tab= Flatten[{(v/.Times[uu_,vv__]\[Rule]{uu,vv})}];(pos=(Position[ Xor[FreeQ[#,w],FreeQ[#,Tensor[#,{i_},{Void}]&@@w]]&/@tab, True])); PartialD[u][Tensor[Apply[Times,Delete[tab,pos]]],w]If[ pos\[Equal]{},1, Product[ tab\[LeftDoubleBracket]pos\[LeftDoubleBracket] i\[RightDoubleBracket]\[RightDoubleBracket],{i, Length[pos]}]\[LeftDoubleBracket]1\[RightDoubleBracket]]\ )/.PartialD[u_][Tensor[v_,{},{}], w_]\[RuleDelayed](tab= Flatten[{(v/.Times[uu_,vv__]\[Rule]{uu,vv})}];(pos=(Position[ Xor[FreeQ[#,w],FreeQ[#,Tensor[#,{i_},{Void}]&@@w]]&/@tab, True])); PartialD[u][Tensor[Apply[Times,Delete[tab,pos]]],w]If[pos\[Equal]{}, 1,Product[ tab\[LeftDoubleBracket]pos\[LeftDoubleBracket] i\[RightDoubleBracket]\[RightDoubleBracket],{i, Length[pos]}]\[LeftDoubleBracket]1\[RightDoubleBracket]])] TGrad[\[DoubleStruckE]_,flavor_@i_][f_]:= Module[{i$}, CovariantD[f, flavor@i$]Tensor[\[DoubleStruckE],{flavor@i$},{Void}]/.i$\[Rule]i] TGrad[\[DoubleStruckE]_,i_][f_]:= If[Head@i\[Equal]Symbol, Module[{i$}, CovariantD[f,i$]Tensor[\[DoubleStruckE],{i$},{Void}]/.i$\[Rule]i]] TDiv[\[DoubleStruckE]_,g_,flavor_@i_][vector_]:= Module[{i$}, CovariantD[ vector.Tensor[\[DoubleStruckE],{flavor@i$},{Void}]// EvaluateDotProducts[\[DoubleStruckE],g],flavor@i$]/.i$\[Rule]i] TDiv[\[DoubleStruckE]_,g_,i_][vector_]:= If[Head@i\[Equal]Symbol, Module[{i$}, CovariantD[ vector.Tensor[\[DoubleStruckE],{i$},{Void}]// EvaluateDotProducts[\[DoubleStruckE],g],i$]/.i$\[Rule]i]] TCurl[\[DoubleStruckE]_,g_,flavor_/@{i_,j_,k_},e_,metricsimplify_:True][ vector_]:=Module[{i\[Section],j\[Section],k\[Section]}, CovariantD[ vector.Tensor[\[DoubleStruckE],{Void},{flavor@j\[Section]}]// EvaluateDotProducts[\[DoubleStruckE],g,metricsimplify], flavor@i\[Section]]Tensor[\[DoubleStruckE],{Void},{flavor@ k\[Section]}]Tensor[ e,{flavor@i\[Section],flavor@j\[Section],flavor@k\[Section]},{Void, Void,Void}]/.{i\[Section]\[Rule]i,j\[Section]\[Rule]j, k\[Section]\[Rule]k}] TCurl[\[DoubleStruckE]_,g_,{i_,j_,k_},e_,metricsimplify_:True][vector_]:= If[Head@i \[Equal]Symbol&&Head@j\[Equal]Symbol &&Head@k\[Equal]Symbol, Module[{i\[Section],j\[Section],k\[Section]}, CovariantD[ vector.Tensor[\[DoubleStruckE],{Void},{j\[Section]}]// EvaluateDotProducts[\[DoubleStruckE],g,metricsimplify], i\[Section]]Tensor[\[DoubleStruckE],{Void},{k\[Section]}]Tensor[ e,{i\[Section],j\[Section],k\[Section]},{Void,Void, Void}]/.{i\[Section]\[Rule]i,j\[Section]\[Rule]j, k\[Section]\[Rule]k}]] TLaplacian[\[DoubleStruckE]_,g_,i_,j_][f_]:= TDiv[\[DoubleStruckE],g,i][TGrad[\[DoubleStruckE],j][f]]//Expand// CovariantDSimplify[\[DoubleStruckE],g,e] TLaplacian[\[DoubleStruckE]_,g_,i_][f_]:= Module[{a}, TLaplacian[\[DoubleStruckE],g,i,Head[i]@a][f]//MetricSimplifyD[g]] LaplaceOp[\[CapitalDelta]_][expr_]:= expr//.{CovariantD[HoldContravariantD[Tensor[t_,{u__},{v__}],{i_,j___}],{i_, k___}]\[RuleDelayed] CovariantD[ HoldContravariantD[ Tensor[\[CapitalDelta][ t],{u},{v}],{j}],{k}], CovariantD[ HoldContravariantD[ Tensor[t_,{u__},{v__}],{j___, i_}],{k___,i_}]\[RuleDelayed] CovariantD[ HoldContravariantD[ Tensor[\[CapitalDelta][ t],{u},{v}],{j}],{k}]}/.{CovariantD[ HoldContravariantD[ Tensor[t_],{i_,j___}],{i_, k___}]\[RuleDelayed] CovariantD[ HoldContravariantD[ Tensor[\[CapitalDelta][t]],{j}],{k}], CovariantD[ HoldContravariantD[ Tensor[t_],{j___,i_}],{k___, i_}]\[RuleDelayed] CovariantD[ HoldContravariantD[ Tensor[\[CapitalDelta][ t]],{j}],{k}]}/.{CovariantD[ HoldContravariantD[ Tensor[t_,{u__},{v__}],{i_, j___}],{i_}]\[RuleDelayed] HoldContravariantD[ Tensor[\[CapitalDelta][t],{u},{v}],{j}], CovariantD[ HoldContravariantD[ Tensor[t_,{u__},{v__}],{i_}],{k___, i_}]\[RuleDelayed]CovariantD[ Tensor[\[CapitalDelta][ t],{u},{v}],{k}]}/.{CovariantD[ HoldContravariantD[ Tensor[t_],{i_,j___}],{i_}]\[RuleDelayed] HoldContravariantD[ Tensor[\[CapitalDelta][t]],{j}], CovariantD[ HoldContravariantD[Tensor[t_],{i_}],{k___, i_}]\[RuleDelayed]CovariantD[ Tensor[\[CapitalDelta][ t]],{k}]}/.{CovariantD[ HoldContravariantD[ Tensor[ t_,{u__},{v__}],{i_}],{i_}]\[RuleDelayed] Tensor[\[CapitalDelta][ t],{u},{v}]}/.{CovariantD[ HoldContravariantD[ Tensor[t_],{i_}],{i_}]\[RuleDelayed] Tensor[\[CapitalDelta][t]]}/.{CovariantD[ HoldContravariantD[ CovariantD[Tensor[t_,{u__},{v__}],w_],i_], i_]\[RuleDelayed]\[CapitalDelta][ CovariantD[Tensor[t,{u},{v}],{w}]]}/.{CovariantD[ HoldContravariantD[ HoldContravariantD[Tensor[t_,{u__},{v__}],w_],i_], i_]\[RuleDelayed]\[CapitalDelta][ HoldContravariantD[ Tensor[t,{u},{v}],{w}]]}/.{HoldContravariantD[ CovariantD[Tensor[t_,{u__},{v__}],{i_,j___}],{i_, k___}]\[RuleDelayed] HoldContravariantD[ CovariantD[ Tensor[\[CapitalDelta][t],{u},{v}],{j}],{k}], HoldContravariantD[ CovariantD[Tensor[t_,{u__},{v__}],{j___,i_}],{k___, i_}]\[RuleDelayed]HoldContravariantD[ CovariantD[ Tensor[\[CapitalDelta][ t],{u},{v}],{j}],{k}]}/.{HoldContravariantD[ CovariantD[Tensor[t_],{i_,j___}],{i_, k___}]\[RuleDelayed]HoldContravariantD[ CovariantD[Tensor[\[CapitalDelta][t]],{j}],{k}], HoldContravariantD[ CovariantD[Tensor[t_],{j___,i_}],{k___, i_}]\[RuleDelayed]HoldContravariantD[ CovariantD[ Tensor[\[CapitalDelta][ t]],{j}],{k}]}/.{HoldContravariantD[ CovariantD[ Tensor[t_,{u__},{v__}],{i_, j___}],{i_}]\[RuleDelayed]CovariantD[ Tensor[\[CapitalDelta][t],{u},{v}],{j}], HoldContravariantD[ CovariantD[Tensor[t_,{u__},{v__}],{i_}],{k___, i_}]\[RuleDelayed]HoldContravariantD[ Tensor[\[CapitalDelta][ t],{u},{v}],{k}]}/.{HoldContravariantD[ CovariantD[ Tensor[t_],{i_,j___}],{i_}]\[RuleDelayed]CovariantD[ Tensor[\[CapitalDelta][t]],{j}], HoldContravariantD[ CovariantD[Tensor[t_],{i_}],{k___, i_}]\[RuleDelayed]HoldContravariantD[ Tensor[\[CapitalDelta][t]],{k}]}/.{HoldContravariantD[ CovariantD[ Tensor[t_,{u__},{v__}],{i_}],{i_}]\[RuleDelayed]Tensor[\ \[CapitalDelta][t],{u},{v}]}/.{HoldContravariantD[ CovariantD[ Tensor[t_],{i_}],{i_}]\[RuleDelayed]Tensor[\[CapitalDelta][ t]]}/.{HoldContravariantD[ CovariantD[CovariantD[Tensor[t_,{u__},{v__}],w_],i_], i_]\[RuleDelayed]\[CapitalDelta][ HoldContravariantD[Tensor[t,{u},{v}],{w}]]}/.{HoldContravariantD[ CovariantD[HoldContravariantD[Tensor[t_,{u__},{v__}],w_],i_], i_]\[RuleDelayed]\[CapitalDelta][ HoldContravariantD[Tensor[t,{u},{v}],{w}]]} FunctionalD[g_,flv_][L_,f_]:=FunctionalD[g,flv,r$,s$][L,f] FunctionalD[g_,flv_,r$_,s$_][L_,f_]:=Module[{cov,cov2d,pos,pos1,term,U}, (black[Tensor[t__]]:=Tensor[t]; ((CovariantD[L//CovNotation[cov]//Cov2dNotation[cov2d],f$]/.f$\[Rule] f/.ruleDFunct[g])- CovariantD[(CovariantD[ L//CovNotation[cov]//Cov2dNotation[cov2d], f$]/.f$\[RuleDelayed](CovariantD[f,flv@r$]// CovNotation[cov]// Cov2dNotation[cov2d])/.ruleDFunct[g]),flv@r$]+ CovariantD[(CovariantD[ L//CovNotation[cov]//Cov2dNotation[cov2d], f$]/.f$\[RuleDelayed](CovariantD[f,{flv@r$,flv@s$}]// CovNotation[cov]// Cov2dNotation[cov2d])/.ruleDFunct[g]),{flv@r$, flv@s$}])//MetricSimplify[g]//CovariantDSimplify[g]) /.Tensor[t_,{u__},{v__}]\[RuleDelayed] If[(pos1=Position[{{u},{v}}//Transpose,cov@_])==={}, Tensor[t,{u},{v}],{(pos=pos1//Transpose), term=If[Length[pos1]\[Equal]Length[{u}],Tensor[t], Tensor[t, U=Delete[{u}, List/@pos\[LeftDoubleBracket]1\ \[RightDoubleBracket]], Delete[{v}, List/@pos\[LeftDoubleBracket]1\[RightDoubleBracket]]\ ]],Do[If[pos\[LeftDoubleBracket]2,ii\[RightDoubleBracket]\[Equal]2, term=CovariantD[ term,{v}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]], term=HoldContravariantD[ term,{u}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]]],{ii, Length[pos\[LeftDoubleBracket]2\[RightDoubleBracket]]}], term/.cov\[Rule] Identity}\[LeftDoubleBracket]4\[RightDoubleBracket]]/.\ Tensor[t_,{u__},{v__}]\[RuleDelayed] If[(pos1=Position[{{u},{v}}//Transpose,cov2d@_])==={}, Tensor[t,{u},{v}],{(pos=pos1//Transpose), term=If[Length[pos1]\[Equal]Length[{u}],Tensor[t], Tensor[t, U=Delete[{u}, List/@pos\[LeftDoubleBracket]1\[RightDoubleBracket]]\ ,Delete[{v},List/@pos\[LeftDoubleBracket]1\[RightDoubleBracket]]]], Do[If[pos\[LeftDoubleBracket]2, ii\[RightDoubleBracket]\[Equal]2, term=CovariantD2d[ term,{v}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]], term=ContravariantD2d[ term,{u}\[LeftDoubleBracket] ii+Length[U]\[RightDoubleBracket]]],{ii, Length[pos\[LeftDoubleBracket]2\[RightDoubleBracket]]}], term/.cov2d\[Rule] Identity}\[LeftDoubleBracket]4\[RightDoubleBracket]]] ruleDFunct[ g_]:=(CovariantD[Tensor[TN_,{i$__},{j$__}], Tensor[TD_,{k$__},{l$__}]]\[RuleDelayed](If[ TN===TD && Length[{i$}]\[Equal]Length[{k$}], Module[{gNum,gDen, g$},({gNum= StandardDownIndices[g$][ Tensor[ TN,{i$},{j$}]]/.(Tensor[T_,{__},down__]/; T=!=g$)\[RuleDelayed]Num[down], gDen=StandardDownIndices[g$][ Tensor[ TD,{k$},{l$}]]/.(Tensor[T_,{__},down__]/; T=!=g$)\[RuleDelayed]Den[down]}; gNum (gDen/.Tensor[g$,{i__},{j__}]\[RuleDelayed]Tensor[ g$,{j},{i}])/.Num[ij_]Den[ kl_]\[RuleDelayed]Product[ Tensor[ g$,{kl\[LeftDoubleBracket]ind\[RightDoubleBracket], Void},{Void, ij\[LeftDoubleBracket]ind\[RightDoubleBracket]}],{\ ind,Length[{i$}]}]/.Tensor[g$,{Cov[m$_],Void},{Void,Cov[n$_]}]\[Rule]Tensor[ g$,{m$,Void},{Void,n$}])/.{g$\[Rule]g}],0])) End[] EndPackage[] SetContravariantDisplay["SemicolonMode"] SetContravariantD2display["AlternativesMode"] TContinuumMechanics21`TContinuumMechanics`Private`CovSym=";"; \ TContinuumMechanics21`TContinuumMechanics`Private`DifSym=","; SymbolSpaceDimension[\[DoubleStruckE]_]=NDim;