# Tag Info

33

General remarks In General Relativity we work in a 4-dimentional Lorentzian manifold i.e. there is a metric tensor $g$ of signature $(+,-,-,-)$ or $(-,+,+,+)$. Theses signatures are mathematically equivalent and we choose the latter because of certain quite formal aspects even though there are some physically relevant reasons for choosing the former one. In ...

28

I am somewhat reluctant to offer this as an answer since it is inherently difficult to comprehensively address questions on undocumented functionality. Nonetheless, the following observations do constitute partial answers to points raised in the question and are likely to be of value to anyone trying to write practical compiled code using Bags. However, ...

13

About your question regarding the definition of the type of local variables in Compile, Compile has an optional third argument that allows you do this in the same manner you specify arguments. It helps the compiler solve some type ambiguity issues sometimes as by default a local variable is considered a Real number. This can be the case if a local variable ...

13

You could do this: Outer[List, B, #] & /@ A

12

Mathematica 9 contains some functionality for working with symbolic tensors. Here's a list of packages in no particular order, that may have some functionality for working with symbolic tensors. TensoriaCalc - intended for basic calculations in general relativity, but not finished (calculates only Christoffel symbols, Riemann and Ricci tensor). Parallel ...

12

Since you're working with vectors, just let Mathematica know that these are vectors. Some other systems (MATLAB and its relatives in particular) have the limitation that they can only work with matrices, forcing you to distinguish between row vector and column vectors and keep transposing. This is not necessary nor convenient in Mathematica. In[1]:= ...

11

Did you know about the second argument of Total, which lets you sum up element at a certain level, which in practice means along a certain dimensions? For example, if you want to keep levels 1 and 2, and sum up along level 3, you can use Total[data, {3}] (* ==> {{10, 22, 34}, {50, 62, 74}} *) Or sum up along dimension 1: Total[data, {1}] (* ==> ...

11

Some errors corrected and a few tricks Using memoization, "Precomputing" the solutions by using Reduce once instead of NSolve each time, Rewriting the functions in a compact and more understandable way, Reducing the overall calcs needed, Using NonlinearModelFit with Method -> {"NMinimize", Method -> "NelderMead"} for efficiency Reduced the ...

10

On this wikipedia page you find a collection of Tensor software and Mathematica has the biggest section. The package Ricci, which username acl pointed out in his answer is there, and I personally have used xAct. It looks like this And yes, as you suggest in your question, for smaller computation in specific dimensions you can also work in components ...

10

This one might be a starter to calculate the tensors. partialDer[T_, vars_] := D[T, #] & /@ vars // Simplify christoffelSymbols[metric_, coord_] := Module[{dg = partialDer[metric, coord], inverse = Simplify[Inverse[metric]]}, inverse.(Transpose[dg, {2, 1, 3}] + Transpose[dg, {3, 2, 1}] - dg)/ 2 // Simplify] curvTensor[christ_, var_] := ...

10

Please compare Map[findpointsC[data, #] &, data]; // AbsoluteTiming (* {3.567939, Null} *) and findpointsC[data, data] ; // AbsoluteTiming (* {0.841954, Null} *) And of course is Map[findpointsC[data, #] &, data] == findpointsC[data, data] (* True *) The explanation is simple: You typed RuntimeAttributes->{Listable} and Parallelization ...

9

I stumbled upon this question via Google. Thanks for using my TensoriaCalc package! My response is probably too late, but I believe the problem you cited Symbol Tensor is Protected. Symbol TensorType is Protected. Symbol TensorName is Protected. is because you loaded TensoriaCalc more than once in the same kernel session. When writing the ...

9

If we transpose the indices of $v$ and $w$ so that $v'_{abe} = v_{aeb}$ and $w'_{ecd} = w_{ced}$, then we can compute $u = v' \cdot w'$: u === Transpose[v, {1, 3, 2}] . Transpose[w, {2, 1, 3}] (* True *) We can use a similar trick to compute $q$ if we reorder $v_{dea} \to v''_{ade}$, except that this time the $d$ and $e$ indices in $v_{ade}''$ and ...

9

This limitation exists, and as far as I can see we have to live with it for now. It does indeed make it impractical to use Parallel operations inside functions---the functions won't work in parallel kernels. I recommend you parallelize at the top level unless you have a specific reason to do it at lower levels. The longer the a "unit calculation" that is ...

9

Thank you for your interest. I would strongly recommend against trying to modify SymbolicTensorsCoordinateChartDataDumpmappingInfo. It is a very low level function and any changes you make are unlikely to work. There are two sets of operations commonly needed with alternate coordinate systems. One is calculus in the coordinate system - Grad, Div, Curl ...

8

Here are a couple of possibilities. MapThread[Riffle[{#1}, {#2}] &, {aA, bB}, 2] (* Out[64]= {{{a[0, 0], b[0, 0]}, {a[1, 0], b[1, 0]}}, {{a[0, 1], b[0, 1]}, {a[1, 1], b[1, 1]}}} *) Transpose[ArrayFlatten[{aA, bB}], {3, 1, 2}] (* Out[72]= {{{a[0, 0], b[0, 0]}, {a[1, 0], b[1, 0]}}, {{a[0, 1], b[0, 1]}, {a[1, 1], b[1, 1]}}} *) Another that I ...

8

Is this faster? CoefficientArrays[identity, basis][[2]] // MatrixForm $\left( \begin{array}{cccccc} 1 & 0 & 1 & 0 & 0 & -1 \\ 0 & 1 & 1 & 0 & 0 & 0 \\ -1 & 0 & 0 & 1 & -1 & 0 \end{array} \right)$ Responding to Jens' elegant answer it should be noted that performance of CoefficientArrays is ...

8

Another possibility is Distribute soln = Distribute[{B, #}, List] & /@ A And soln == (Flatten[#, 1] & /@ (Outer[List, B, #] & /@ A)) == Flatten[Outer[List, B, A], {{2}, {1, 3}, {4}}] => True Edit Yet another possibility is Tuples (A little surprising to my mind that this one works) Tuples[{B, #}] & /@ A And (Tuples[{B, #}] ...

8

Higher-order SVD (in sense of Tucker decomposition) of the matrix $M$ with dimensions $d_1\times d_2\times\cdots\times d_n$ is $$M_{i_1,i_2,\dots,i_N} = \sum_{j_1} \sum_{j_2}\cdots \sum_{j_N} s_{j_1,j_2,\dots,j_N} u^{(1)}_{i_1,j_1} u^{(2)}_{i_2,j_2} \dots u^{(N)}_{i_N,j_N},$$ where $s$ is the core tensor and $u^{(i)}$ is the orthogonal matrix. The matrix ...

8

Depends on what dimension your final matrix is supposed to have. When I should make a guess, I would say you want this TensorProduct[IdentityMatrix[2], IdentityMatrix[2]] // ArrayFlatten

7

In Mathematica version 9, you can do these kinds of things much more naturally. Here are the two quantities that you wanted: u = TensorContract[TensorProduct[v, w], {2, 5}]; q = TensorContract[TensorProduct[v, w], {{1, 4}, {2, 5}}]; The contraction is performed on the tensor product in which the first three indices belong to the factor v and the last ...

7

The symbol $\epsilon$ is called the Levi-Civita tensor, it is usually written in terms of its components $\epsilon_{i j k}$. Having defined two vectors (i.e. first order contravariant tensors): a = { a1, a2, a3}; b = { b1, b2, b3}; we have to build up a tensor product of two vectors and Levi-Civita tensor, i.e. we get a new tensor of valence $(3,2)$ ...

7

Good question; the notion of a tensorial (covariant) derivative is something that is missing in Mathematica AFAIK. I can think of two ways to proceed: Option 1 One way is to overload the TensorRank, TensorDimensions, and TensorSymmetry functions for patterns that have head CD: CD /: TensorRank[CD[tensor_]] := TensorRank[tensor] + 1 CD /: ...

6

Since the sum goes over the last index of $e$ and the first index of $A$, it is directly done by using Dot: dim = 5; e = Array[\[ScriptE], Table[dim, {dim}]]; a = Array[\[ScriptA], Table[dim, {2}]]; c = e.a; Here I defined the arrays with the appropriate dimensions but suppressed the output because it's too long for five dimensions. Another ...

6

There are a few packages in Mathsource already available they are http://library.wolfram.com/infocenter/MathSource/8329/ and http://library.wolfram.com/infocenter/MathSource/4781/ for the basics both programs do the same thing but the first one has more functionality.

6

Here's a fairly simple way of doing it (ignore the front end's syntax warning): Function[, {##}, Listable][A, B] (* {{{a[0, 0], b[0, 0]}, {a[1, 0], b[1, 0]}}, {{a[0, 1], b[0, 1]}, {a[1, 1], b[1, 1]}}} *)

6

Infix is only an output form. You most probably want the expression which you'd get when typing v1 ⊗ v2 into Mathematica, which is entered with either \[CircleTimes] or Escc*Esc. As you can see by typing v1 ⊗ v2 //FullForm, this is CircleTimes[v1, v2]. The same is true for longer chains of ⊗, i.e. v1 ⊗ v2 ⊗ … ⊗ vn has the internal form CircleTimes[v1, v2, ...

6

Mathematica does not yet support tensor calculus and notation natively, but there are numerous 3rd party packages which address this issue very well. This is a list of the packages I am more familiar with: xAct suite: free (GPL license), most powerful, created by relativists, actively supported. Disclosure: I contributed to the suite by creating the ...

6

Assuming $\mu$ and $\nu$ also run from 1 to 4 (which they have to, otherwise your expression doesn't make sense), you can simply take a cue from this Q&A and write TensorContract[ TensorProduct[LeviCivitaTensor[4], a, b, c], {{2, 5}, {3, 6}, {4, 7}} ] // Normal { -a4 b3 c2 + a3 b4 c2 + a4 b2 c3 - a2 b4 c3 - a3 b2 c4 + a2 b3 c4, a4 b3 c1 - a3 ...

5

I may be misunderstanding what you need, however consider this. If you have an structure of nested lists such as your data, then summing across the deepest list is easily accomplished using Map[Total,data,{-2}]. So, as long as you want to remove dimensions from "the back" you are good to go. And if we need to remove for example the second dimension, then you ...

Only top voted, non community-wiki answers of a minimum length are eligible