Does PrintAs work on indices?

124 views
Skip to first unread message

Ahmed YOUSSEF

unread,
Aug 3, 2010, 2:54:43 PM8/3/10
to xa...@googlegroups.com
Dear all,

I just wanted to know if I can use the command PrintAs to modify how indices are printed. For instance is it possible to get some primed indices:

Input: metric[ap,bp]

and to get the

Output: g^{a',b'}


Best regards

Ahmed YOUSSEF

magma

unread,
Aug 3, 2010, 5:52:44 PM8/3/10
to xAct Tensor Computer Algebra
It does not seem that it is possible to have primed indices in xAct.
You can differentiate different bases using coloured indices, but not
primed indices.
But better wait someone else's confirmation on this.

TB

unread,
Aug 3, 2010, 5:58:43 PM8/3/10
to xAct Tensor Computer Algebra
Hi!
You can indeed use PrintAs to modify how indices are displayed.

Try the following:

{PrintAs[ap]^="a'",PrintAs[bp]^="b'"};

Regards
Thomas

Barry Wardell

unread,
Aug 3, 2010, 6:19:38 PM8/3/10
to xa...@googlegroups.com
On 03/08/2010 23:58, TB wrote:
> Hi!
> You can indeed use PrintAs to modify how indices are displayed.
>
> Try the following:
>
> {PrintAs[ap]^="a'",PrintAs[bp]^="b'"};

Also, rather than having to setup the PrintAs for each index separately,
you can set it up for all indices in the vbundle TangentMp with
something like the following, which takes the first letter from the
index name and appends an ' to it:

Map[(PrintAs[#] ^= StringTake[ToString[#], {1}] <> "'") &,
Flatten[IndicesOfVBundle[TangentMp]]]

magma

unread,
Aug 4, 2010, 6:14:43 AM8/4/10
to xAct Tensor Computer Algebra
This is an interesting feature of xAct, which perhaps should receive
more emphasis in the documentation.
In xAct however, objects like T[a,b] and T[ap,bp] cannot represent the
same tensor in 2 different bases, as is usually found in the
literature using the traditional component notation.
Indeed in xAct (which uses the abstract index notation), T[a,b] and
T[ap,bp] represent geometric objects (since they have abstract
indices) and they should better reside in 2 different tangent bundles
and manifolds.

JMM

unread,
Aug 4, 2010, 6:48:21 AM8/4/10
to xAct Tensor Computer Algebra
Hi,

Formatting indices as desired is important in Tensor Computer Algebra
and xAct is quite flexible in this respect. However, as Alessandro
says, the formatting has nothing to do with the (mathematical) type of
index. We always must know whether we are dealing with abstract
indices, or basis indices, or directional indices, or label indices,
etc, because the system reacts to them in different ways. But the
formatting is essentially free. xAct uses some default formattings
(like the colored basis indices), but this is just a default choice
and can be always changed. Let me explain this.

xAct works by declaring types of symbols. This is the job of the
DefTensor, DefCovD, DefBasis, ... commands. These commands have a
PrintAs option which allow you to tell the FrontEnd how the declared
symbol must be printed. (It is like a shortcut to Mathematica's
Format.). For indices the function is DefAbstractIndex, which declares
symbols as abstract indices. Users do not call this function directly,
and do it via DefManifold or DefVBundle. However it is possible to
choose how to format indices by setting the proper option in advance.
Imagine you want to add primes:

SetOptions[ DefAbstractIndex, PrintAs :> (StringJoint[ ToString[#],
"'"]&) ]

Then all indices you define later will have a primed formatting. As
has been already said, you can change the formatting of individual
indices (in general of individual symbols) by changing the upvalue of
the symbol for PrintAs:

PrintAs[ a ] ^= "a2"

Note that the right hand side must be a string.

All this is for symbols only. How can we format other (non-symbolic)
types of indices? We need to interact with the function IndexForm.
This function controls everything related to individual index
formatting. I use this frequently for example to color label indices.
It would take me too much to explain how it works in general. Anyway,
for those of you with enough Mathematica knowledge to change its
behaviour, it is much better to go to xTensor.m / xTensor.nb and read
the code. Be careful because if this function fails then the output
might be completely corrupted. Feel free to ask if you find problems
or don't know how to achieve a particular formatting.

Cheers,
Jose.

magma

unread,
Aug 4, 2010, 8:33:38 AM8/4/10
to xAct Tensor Computer Algebra
Jose,
I am interested in the following setting:
Abstract indices: black ,unprimed (just the normal ones)
Basis1 indices: Red, unprimed (just the normal ones)
Basis2 indices: Red, primed

In other words; can I differentiate 2 bases NOT with color, but with
primes (or other diacritic)?
I suppose the answer is yes.
Could you please show us how? (if it is not too time-consuming)

This might be a useful general setting if one wants to more closely
emulate printed results written in the component notation, where
different bases/charts are printed in the same color (black), but have
different diacritics (ex. unprimed,primed,double-primed, etc. )

JMM

unread,
Aug 4, 2010, 8:54:25 AM8/4/10
to xAct Tensor Computer Algebra
Declare the manifold and its bases:

DefManifold[M, 4, {a, b, c, d, e}]

DefBasis[B1, TangentM, {0, 1, 2, 3}]

DefBasis[B2, TangentM, {0, 1, 2, 3}]

Now you modify IndexForm as follows:

Unprotect[IndexForm];
IndexForm[{ind_Integer, B2}] :=
ColorString[StringJoin[CIndexForm[ind, B2], "'"], BasisColor[B2]]
IndexForm[{ind_, B2}] :=
ColorString[StringJoin[IndexForm[ind], "'"], BasisColor[B2]]
Protect[IndexForm];

Finally, if you define

DefTensor[ T[a, b, c], M ]

you can do for instance:

T[a, {b, B1}, {c, B2}]

T[1, {2, B1}, {3, B2}]

IndexForm sends a message complaining about the index 1. This is
because I have made IndexForm to complain on improper indices.

Cheers,
Jose.

Ahmed YOUSSEF

unread,
Aug 4, 2010, 2:37:47 PM8/4/10
to magma, xAct Tensor Computer Algebra
Dear all,
Thank you for your answers. I can now add these primed indices. By the way, Thank you Jose for this wonderful package.
Best regards,
Ahmed

Ahmed YOUSSEF
ayous...@gmail.com

magma

unread,
Aug 5, 2010, 6:21:35 AM8/5/10
to xAct Tensor Computer Algebra
I have the pleasure to inform this xActive community that primed and
double-primed index formatting has been incorporated into the latest
version of xPrint, due out very very soon.
Completing this task is now as easy as selecting from a
RadioButtonBar.
Stay tuned for the next release of xPrint

Ali Seraj

unread,
Oct 23, 2021, 3:45:51 AM10/23/21
to xAct Tensor Computer Algebra
Dear all,

I am trying to put parentheses around my Label indices to distinguish it from coordinate indices.
Reading this conversation, I was not able to figure out how to do this explicitly. For example I have
DefTensor[E[-LI@a, b], M4]

and I would like it to appear as E_{(a)}^b

Thanks in advance.
Ali

Thomas Bäckdahl

unread,
Oct 23, 2021, 6:14:20 AM10/23/21
to xa...@googlegroups.com
Hi!

In general indices are printed using IndexForm instead of PrintAs.
However, there is an exception. Label indices are printed using PrintAs applied to the symbol(s) in LI.
So for instance you could try
DefTensor[ET[-LI@a, b], M4, PrintAs -> "E"]
PrintAs[MyLabela] ^= "(a)"
ET[-LI@MyLabela, b]

(I used ET instead of E because E is a reserved symbol in Mathematica.)

If you always want label indices to be displayed with a parenthesis you could try
IndexForm[LI[x_]] ^:= "(" <> ToString[x] <> ")";
or
IndexForm[LI[x_]] ^:= "(" <> PrintAs[x] <> ")";
or something similar.

Regards
Thomas
--
You received this message because you are subscribed to the Google Groups "xAct Tensor Computer Algebra" group.
To unsubscribe from this group and stop receiving emails from it, send an email to xact+uns...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/xact/477c5f47-fb07-43b9-a811-5a7f3965ca79n%40googlegroups.com.

Ali Seraj

unread,
Oct 24, 2021, 5:02:42 AM10/24/21
to xAct Tensor Computer Algebra
Dear Thomas,

Thanks a lot for your reply. Now I understand the structure, and it works very well.

Best,
Ali

Reply all
Reply to author
Forward
0 new messages