# Simple tensor manipulation in Maple or Mathematica

1. Feb 11, 2007

### nrqed

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 $\eta_{\alpha \beta} q^\beta$ must be replaced by $q_\alpha$ . Or that $\eta_{\mu \nu} \eta^{\mu \alpha}$ must be replaced by $\eta^\alpha_\nu$ or that $\eta_{\mu \nu} \eta^{\mu \nu} = 4$ 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

2. Feb 11, 2007

### shoehorn

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 $\eta_{\mu\nu}=\textrm{diag}(-1,1,1,1)$ and then calculate $\eta_\mu^{\phantom{\mu}\mu}$ by passing the following code to it:

Code (Text):

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

The first command defines an object called tracenu to be equal to $\eta_{\mu\nu}\eta^{\mu\nu}$ 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. Feb 11, 2007

### nrqed

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
$$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$$
you get the idea. Grtensor will give me this result in that form?

Thanks again

4. Feb 12, 2007

### pervect

Staff Emeritus
5. Feb 12, 2007

### George Jones

Staff Emeritus
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 this.

6. Feb 12, 2007

### nrqed

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.
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: Feb 12, 2007
7. Feb 12, 2007

### nrqed

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

8. Feb 12, 2007

### pervect

Staff Emeritus
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. Feb 12, 2007

### shoehorn

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 (Text):
"/Users/***/Documents/grii/lib/"
bit with a path that points to your grtensor lib folder. Similarly, replace

Code (Text):
"/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 (Text):
grtw();
and you're away. I don't use Windows so don't ask me about the corresponding procedure there.

#### Attached Files:

• ###### mapleinit.txt
File size:
567 bytes
Views:
90
10. Feb 12, 2007

### nrqed

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).

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: Feb 12, 2007
11. Feb 13, 2007

### nrqed

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 $$g^{\mu \nu} q^2 p \cdot k + q^\mu q^\nu k^2 + \ldots$$ as opposed to having a very long expression containing the components of all the four vectors, namely something like $$q_0 k_1^2 + q_0 k_2^2 + \ldots$$. 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 $q_0 k_1 p_1 p_0 + \ldots$ actually represent $q \cdpot k p^2 + q \cdot p k \cdot q$)

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. Sep 17, 2007

### kpeeters

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 (Text):
{\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 (Text):
\eta_{\alpha\beta} q^{\beta};
@eliminate_metric!(%);
which gives
$$q_{\alpha};$$

Code (Text):
\eta_{\mu \nu} \eta^{\mu \alpha};
@eliminate_metric!(%);
which gives
$$\eta_{\nu}^{\alpha};$$

Code (Text):
\eta_{\mu \nu} \eta^{\mu \nu};
@eliminate_metric!(%);
@eliminate_kr!(%);
which gives
$$4;$$;

Cadabra runs on Linux and Mac OS X. Hope this helps.
{"extraction_info": {"found_math": true, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 1, "mathjax_display_tex": 1, "mathjax_asciimath": 1, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0, "math_score": 0.6625782251358032, "perplexity": 1342.1055192121405}, "config": {"markdown_headings": true, "markdown_code": true, "boilerplate_config": {"ratio_threshold": 0.18, "absolute_threshold": 10, "end_threshold": 15, "enable": true}, "remove_buttons": true, "remove_image_figures": true, "remove_link_clusters": true, "table_config": {"min_rows": 2, "min_cols": 3, "format": "plain"}, "remove_chinese": true, "remove_edit_buttons": true, "extract_latex": true}, "warc_path": "s3://commoncrawl/crawl-data/CC-MAIN-2016-44/segments/1476988720380.80/warc/CC-MAIN-20161020183840-00430-ip-10-171-6-4.ec2.internal.warc.gz"}