Simple tensor manipulation in Maple or Mathematica

In summary: I don't know how to make it work.In summary, the person is trying to do simple tensor contraction in Maple or Mathematica and would like to know how to do substitutions like replacing eta_{\alpha \beta} q^\beta by q_\alpha . They say that all of the calculations can be done with the grtensor package in Maple, but for the final result they need to use grtensor with an appropriate metric.
  • #1
nrqed
Science Advisor
Homework Helper
Gold Member
3,766
297
I know that this might not be the best forum for the question but I am sure people here can help.

I want to do some simple tensor contraction using Maple or Mathematica. The calculation is simple but extremely long. All I want is to teach Maple/Mathematica to do tensor contraction without using explicit 4x4 matrices or four-vectors. For example, I want Maple/Mathematica to recognize that [itex] \eta_{\alpha \beta} q^\beta [/itex] must be replaced by [itex] q_\alpha [/itex] . Or that [itex] \eta_{\mu \nu} \eta^{\mu \alpha} [/itex] must be replaced by [itex] \eta^\alpha_\nu [/itex] or that [itex] \eta_{\mu \nu} \eta^{\mu \nu} = 4 [/itex] and so on.

The calculation involves hundreds of terms (it is in the context of linearized GR quantized as an effective field theory).

I would highly appreciate if someone could tell me how to tell Maple/Mathematica to do certain substitutions like this.

Patrick
 
Physics news on Phys.org
  • #2
nrqed said:
I know that this might not be the best forum for the question but I am sure people here can help.

I want to do some simple tensor contraction using Maple or Mathematica. The calculation is simple but extremely long. All I want is to teach Maple/Mathematica to do tensor contraction without using explicit 4x4 matrices or four-vectors. For example, I want Maple/Mathematica to recognize that [itex] \eta_{\alpha \beta} q^\beta [/itex] must be replaced by [itex] q_\alpha [/itex] . Or that [itex] \eta_{\mu \nu} \eta^{\mu \alpha} [/itex] must be replaced by [itex] \eta^\alpha_\nu [/itex] or that [itex] \eta_{\mu \nu} \eta^{\mu \nu} = 4 [/itex] and so on.

The calculation involves hundreds of terms (it is in the context of linearized GR quantized as an effective field theory).

I would highly appreciate if someone could tell me how to tell Maple/Mathematica to do certain substitutions like this.

Patrick

If you use the grtensor package in Maple all of these calculations are trivial. For example, you can simply load the Minkowski metric into grtensor so that [itex]\eta_{\mu\nu}=\textrm{diag}(-1,1,1,1)[/itex] and then calculate [itex]\eta_\mu^{\phantom{\mu}\mu}[/itex] by passing the following code to it:

Code:
grdef(`tracenu := g{a b}*g{^a ^b}`);
grcalcd(tracenu);

The first command defines an object called tracenu to be equal to [itex]\eta_{\mu\nu}\eta^{\mu\nu}[/itex] while the second calculates its value and displays the result (hence the command `grcalcd`). Reading through the grtensor manual will tell you how to do the rest.
 
  • #3
shoehorn said:
If you use the grtensor package in Maple all of these calculations are trivial. For example, you can simply load the Minkowski metric into grtensor so that [itex]\eta_{\mu\nu}=\textrm{diag}(-1,1,1,1)[/itex] and then calculate [itex]\eta_\mu^{\phantom{\mu}\mu}[/itex] by passing the following code to it:

Code:
grdef(`tracenu := g{a b}*g{^a ^b}`);
grcalcd(tracenu);

The first command defines an object called tracenu to be equal to [itex]\eta_{\mu\nu}\eta^{\mu\nu}[/itex] while the second calculates its value and displays the result (hence the command `grcalcd`). Reading through the grtensor manual will tell you how to do the rest.


Thank you for your reply, it is greatly appreciated.

I have actually been trying to download an executable of GRTensorII from that very site but every time I click on the link, the browser redirects me to a page that can't be loaded. Could anyone double check this?

Just to be clear, what I have is is the contraction of a large number of terms (something like 80 terms) containing products of four vectors and flat metrics with another large number of similar terms. The final result will be a rank two tensors so it will have the form
[tex]c_1 \eta^{\mu \nu} q^2 + c_2 \eta^{\mu \nu} k \cdot q p \cdot p' + c_3 q^\mu q^\nu k \cdot p + \dots [/tex]
you get the idea. Grtensor will give me this result in that form?

Thanks again
 
  • #4
Probably you didn't click on the link named software. The main page uses frames, but the download link appears to be at

ftp://grtensor.phy.queensu.ca/pub/grtensor/179/Grtii6.exe

Anyway, give it a try, and see if it works.
 
  • #5
nrqed said:
I have actually been trying to download an executable of GRTensorII from that very site but every time I click on the link, the browser redirects me to a page that can't be loaded. Could anyone double check this?

I downloaded GRTensorII on Saturday. It took me some time to get it working, as the readme file is out of date and gives incorrect instructions. If you are using Maple 8 (or higher?), try http://grtensor.phy.queensu.ca/mapleini.txt" .
 
Last edited by a moderator:
  • #6
pervect said:
Probably you didn't click on the link named software.
Thanks for your reply. I did click on software and got a page with a list of executables to download. But it's when I click on one of the executable files to download that my browser (IE) tells me that it can't open the page.
The main page uses frames, but the download link appears to be at

ftp://grtensor.phy.queensu.ca/pub/grtensor/179/Grtii6.exe

Anyway, give it a try, and see if it works.
This is exactly one of the executable files I tried to download. But when I click on your link, Iget the same problem: my browser tells me it can't open the page! You do get a page opening up when you click on this link??

UPDATE: I tried with Mozilla and still can't get the executable files. The browser tells me "Connexion to grtensor.phy.queensu.ca refused" or something to that effect. I am not behind a firewall or anything that could cause any problem. I would like to know if others can access the executable file. Thanks
 
Last edited:
  • #7
George Jones said:
I downloaded GRTensorII on Saturday. It took me some time to get it working, as the readme file is out of date and gives incorrect instructions. If you are using Maple 8 (or higher?), try http://grtensor.phy.queensu.ca/mapleini.txt" .

Thanks George, that's very helpful.
What executable file did you download?? And from where? If you click on the link provided by pervect, do you get a page opening up? Is that the executable file you downloaded?

Thanks again
 
Last edited by a moderator:
  • #8
I just clicked on the above link - my browser said:

"You have chosen to open GRTii6.exe
which is a Application
from: ftp://grtensor.phy.queensu.ca

Would you like to save this file?
"

I even get a file when I click on "yes". The link is using a ftp protocol, so if you want to get more error messages, you might have to hunt around to get a true ftp client. If you really want to do some snooping, telnet to grtensor.phy.queensu.ca with port 21 (the ftp port) that might give you some diagnostic messages (about failed connections). You'll probably find it too painful to attempt to use telnet to actually download anything though. (If you get a connection this way, try a true ftp client or try to debug your browser).

I'll agree with George about the documentation being outdated. I never did find out how to get initialization working automatically, I wind up manually sourcing a script similar to George's. But that's a problem for after you get the software.
 
  • #9
For what it's worth, I have no difficulty downloading from the grtensor site either. Also, I've attached a copy of my mapleinit file - it may be of help to somebody. I'm running OS X, so if you're a Linux user, simply replace the

Code:
"/Users/***/Documents/grii/lib/"

bit with a path that points to your grtensor lib folder. Similarly, replace

Code:
"/Users/***/Documents/grii/metrics/"

with a path that points to your metrics folder. Rename the file as .mapleinit and put it in your home directory. Then when you start up maple all you need to type is

Code:
grtw();

and you're away. I don't use Windows so don't ask me about the corresponding procedure there.
 

Attachments

  • mapleinit.txt
    567 bytes · Views: 530
  • #10
pervect said:
I just clicked on the above link - my browser said:

"You have chosen to open GRTii6.exe
which is a Application
from: ftp://grtensor.phy.queensu.ca

Would you like to save this file?
"

I even get a file when I click on "yes". The link is using a ftp protocol, so if you want to get more error messages, you might have to hunt around to get a true ftp client. If you really want to do some snooping, telnet to grtensor.phy.queensu.ca with port 21 (the ftp port) that might give you some diagnostic messages (about failed connections). You'll probably find it too painful to attempt to use telnet to actually download anything though. (If you get a connection this way, try a true ftp client or try to debug your browser).

Thanks for checking this out.
I finally managed to get the file, it worked fine at school! (I have no idea what was wrong with my home computer).


I'll agree with George about the documentation being outdated. I never did find out how to get initialization working automatically, I wind up manually sourcing a script similar to George's. But that's a problem for after you get the software.

EDIT: SUCCESS! I finally got it to work.
Thanks for everybody's help (Thanks George for the file, which I used)

Stay tuned, as I will probably have questions about how to use it.



Patrick
 
Last edited:
  • #11
shoehorn said:
If you use the grtensor package in Maple all of these calculations are trivial. For example, you can simply load the Minkowski metric into grtensor so that [itex]\eta_{\mu\nu}=\textrm{diag}(-1,1,1,1)[/itex] and then calculate [itex]\eta_\mu^{\phantom{\mu}\mu}[/itex] by passing the following code to it:

Code:
grdef(`tracenu := g{a b}*g{^a ^b}`);
grcalcd(tracenu);

The first command defines an object called tracenu to be equal to [itex]\eta_{\mu\nu}\eta^{\mu\nu}[/itex] while the second calculates its value and displays the result (hence the command `grcalcd`). Reading through the grtensor manual will tell you how to do the rest.
Thanks for that. Yes, it works as you described.

Now, what I need to do is to contract a bunch of terms containg various products of the metric and a bunch of four-momenta. Is there any way to have the final result in the form [tex] g^{\mu \nu} q^2 p \cdot k + q^\mu q^\nu k^2 + \ldots [/tex] as opposed to having a very long expression containing the components of all the four vectors, namely something like [tex] q_0 k_1^2 + q_0 k_2^2 + \ldots [/tex]. My problem is that there are 4 different four-vectors involved in my expression so it would be a mess to disentangle a very long expression containing many products of components and figuring out what expression it corresponds to (for example, figuring out that a bunch of terms [itex] q_0 k_1 p_1 p_0 + \ldots [/itex] actually represent [itex] q \cdpot k p^2 + q \cdot p k \cdot q [/itex])

I have used programs in the past that did that (programs for particle physics calculations) but I unfortunately don't have access to them anymore.

Thanks for the help
 
  • #12
Problems of the type you mention can easily be tackled with cadabra (available at
http://www.aei.mpg.de/~peekas/cadabra). For example, after input of the declarations

Code:
{\alpha,\beta,\mu,\nu}::Indices(position=fixed).
{\alpha,\beta,\mu,\nu}::Integer(0..3).
\eta_{\mu\nu}::Metric.
\eta^{\mu\nu}::InverseMetric.
{ \eta^{\mu}_{\nu}, \eta_{\nu}^{\mu} }::KroneckerDelta.

you can do the three examples with

Code:
\eta_{\alpha\beta} q^{\beta};
@eliminate_metric!(%);
which gives
[tex]q_{\alpha};[/tex]

Code:
\eta_{\mu \nu} \eta^{\mu \alpha};
@eliminate_metric!(%);
which gives
[tex]\eta_{\nu}^{\alpha};[/tex]

Code:
\eta_{\mu \nu} \eta^{\mu \nu};
@eliminate_metric!(%);
@eliminate_kr!(%);
which gives
[tex]4;[/tex];

Cadabra runs on Linux and Mac OS X. Hope this helps.
 

1. What is a tensor in Maple or Mathematica?

A tensor is a mathematical object that represents a linear transformation between vector spaces. In Maple and Mathematica, tensors are typically represented as multi-dimensional arrays of numbers.

2. How can I create a tensor in Maple or Mathematica?

To create a tensor in Maple, you can use the Tensor package by typing "with(Tensor)" in the Maple input line. Then, you can use the "Tensor" command to define a tensor with specific dimensions and components. In Mathematica, you can use the built-in function "Array" to create a tensor with specified dimensions and values.

3. How do I manipulate tensors in Maple or Mathematica?

In Maple, you can use the functions provided by the Tensor package to perform operations on tensors, such as addition, multiplication, and contraction. In Mathematica, you can use built-in functions like "Dot" and "TensorTranspose" to manipulate tensors.

4. How can I perform tensor calculus in Maple or Mathematica?

In Maple, the Tensor package also provides functions for performing tensor calculus, such as computing the covariant derivative and Christoffel symbols. In Mathematica, you can use the built-in function "TensorRank" to calculate the rank of a tensor, and then use appropriate functions for tensor calculus depending on the rank.

5. Can tensors be used for machine learning in Maple or Mathematica?

Yes, both Maple and Mathematica have packages and functions for machine learning that can handle tensors. In Maple, the Statistics package provides functions for performing regression and classification on tensors. In Mathematica, the Neural Networks package allows for building and training neural networks using tensors.

Similar threads

  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
1K
  • Special and General Relativity
Replies
8
Views
2K
  • Advanced Physics Homework Help
Replies
6
Views
1K
  • MATLAB, Maple, Mathematica, LaTeX
Replies
1
Views
2K
  • Special and General Relativity
Replies
8
Views
2K
  • Special and General Relativity
Replies
2
Views
823
  • Advanced Physics Homework Help
Replies
7
Views
898
  • Differential Geometry
Replies
3
Views
989
  • Calculus
Replies
1
Views
948
Back
Top