Initial tensor indices at 0

Some time ago, I wrote a package to calculate the tensor in General Relativity. To make it accessible to others, it should be slightly modified.

There are functions, for example, Christoffel for calculating the Christoffel symbol:

Christoffel[g_, xx_] := Block[{ig, res, n}, n = 4; ig = Simplify[Inverse[g]]; res = Table[(1/2)*Sum[ig[[i,s]]*(-D[g[[j,k]], xx[[s]]] + D[g[[j,s]], xx[[k]]] + D[g[[s,k]], xx[[j]]]), {s, 1, n}], {i, 1, n}, {j, 1, n}, {k, 1, n}]; res ] 

where g and xx are the metric tensor and coordinates, respectively, which I determine in the Mathematica session after loading the package in a simple way, for example, for the anzatz for static spherically symmetric space-time: metric This way is associated with disadvantages, since the ranges of indices are {1, 2, 3, 4} , while the usual practice in relativistic physics suggests putting {0, 1, 2, 3} , where 0 denotes the time coordinate, and {1, 2, 3} denote space-like ones. To talk about the problem, define a table where indexes start at 0, i.e.

 V = Table[i - j, {i, 0, 3}, {j, 0, 3}] {{0, -1, -2, -3}, {1, 0, -1, -2}, {2, 1, 0, -1}, {3, 2, 1, 0}} 

but when I evaluate V[[0, 0]] I get Symbol - chapter V,
and for V[[1, 2]] I get -1 , as it should be.

My questions:

  • How can I override V so that I can evaluate the component "table" [0, 0] ?
  • What would be the most convenient way to introduce the matrix g with its indices starting at 0?
  • Since I have to refuse to use Part to access the components of the tensor 0,0 how to introduce freedom of choice into the range of index ranges of other objects, such as Christoffel (for example, the default index is {0, 1, 2, 3} or if one prefers - {1, 2, 3, 4} )?

Although these questions seem trivial at a glance, any comprehensive answers are welcome. Anyone who uses the package should not be bothered by its subtleties of mathematica.

+4
source share
2 answers

(1) Indexing a Mathematica list with Part ([[]] in a more general notation) starts at 1. Point 0 is the head of the expression.

(2) You can define a β€œfunction” that takes the indices you need and adds 1 to each.

 xx = {t, x, \[Theta], \[Phi]}; g = {{-E^(2*\[Nu][x]), 0, 0, 0}, {0, E^(2*\[Lambda][x]), 0, 0}, {0, 0, x^2, 0}, {0, 0, 0, x^2*Sin[\[Theta]]^2}}; gg[indices___] := g[[Sequence @@ ({indices} + 1)]] 

Examples:

 In[121]:= gg[0] Out[121]= {-E^(2*\[Nu][x]), 0, 0, 0} In[123]:= gg[2, 2] Out[123]= x^2 

(3) See (2) for a possible approach. See (1) to understand that PART is NOT a direct path.

Daniel Lichtblau

+6
source

I do not intend to be trivial or frivolous with regard to your concern, but it is difficult for me to understand the significance of your dilemma. Mathematica or, more specifically, Part indexes from one, and it's just the way it is. I am tempted to say, for example, use. V[[n+1]] , but I must assume that you have already considered this.


Pointer 0 reserved for the head of the expression. Although this is far from the standard, the flexibility of Mathematica syntax actually allows this design:

 V = 0[-1, -2, -3][{1, 0, -1, -2}, {2, 1, 0, -1}, {3, 2, 1, 0}]; V[[0,2]] 
  -2 

This works because the chapters themselves contain your data. It is impractical, but presented for academic interest.


In the specific answer to your first question and explanation of the trick above, you should be familiar with the heads of Mathematica. Each expression conceptually has a head. In the expression a + b head is Plus . In {1, 2, 3} this is a List . You can see them using FullForm . Other types also have conceptual chapters, even if they are not specified in FullForm . You can define them using Head . For instance:

 Head /@ {"abc", 1, Pi, 3.14, 1/2} 
  {String, Integer, Symbol, Real, Rational} 

Syntax Part [[0, 0]] queries the head of the head. In the case of your array, which is a list of lists, the head of List is the head of the List Symbol , which determines its type.


In answer to your second question, I would define a new Part function that indexes from scratch.

 myPart[x_, spec__] := Part[x, ##] & @@ ({spec} /. n_Integer :> n + 1) V = {{1, 2, 3}, {4, 5, 6}, {7, 8, 9}}; myPart[V, 0, 0] 
  1 

This also works with Span :

 myPart[V, All, 0 ;; 1] 
  {{1, 2}, {4, 5}, {7, 8}} 
+10
source

Source: https://habr.com/ru/post/1380671/


All Articles