Skip to content

Commit eabd6cb

Browse files
committed
Fix printing of index brackets
1 parent 115f64f commit eabd6cb

File tree

3 files changed

+115
-119
lines changed

3 files changed

+115
-119
lines changed

core/DisplayTeX.cc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -679,6 +679,9 @@ void DisplayTeX::print_relation(std::ostream& str, Ex::iterator it)
679679

680680
void DisplayTeX::print_indexbracket(std::ostream& str, Ex::iterator it)
681681
{
682+
if(*it->multiplier!=1)
683+
print_multiplier(str, it);
684+
682685
auto sib=tree.begin(it);
683686
str << "\\left(";
684687
dispatch(str, sib);

doc/cadabra2_hep.tex

Lines changed: 89 additions & 83 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@
4949
%ITP-UU-06/56\\
5050
hep-th/0701238\\
5151
25 January 2007\\
52-
11 June 2016 (updated for v2)
52+
8 August 2017 (updated for v2)
5353
\end{flushright}
5454
\vskip 7ex
5555
@@ -88,7 +88,7 @@
8888
\begin{minipage}{0.95\textwidth}
8989
\noindent{\smaller\smaller This paper originally appeared in 2007. It
9090
has been updated to reflect the syntax changes introduced with
91-
Cadabra~2.0 (released in 2016), but is otherwise essentially
91+
Cadabra~2.0 (first released in 2016), but is otherwise essentially
9292
unchanged. A more in-depth discussion of the changes of the 2.x
9393
series will appear in an upcoming paper. The software itself,
9494
including source code, can be obtained from the web site
@@ -565,18 +565,18 @@ \subsection{A Riemann tensor polynomial example}
565565
canonical form with respect to mono-term symmetries,
566566
\end{cdbcom}
567567
\begin{cdbcont}
568-
@distribute!(%): @prodrule!(%):
569-
@distribute!(%): @prodrule!(%):
568+
distribute(_); product_rule(_);
569+
distribute(_); product_rule(_);
570570
571-
@prodsort!(%): @canonicalise!(%): @rename_dummies!(%):
572-
@collect_terms!(%):
571+
sort_product(_); canonicalise(_);
572+
rename_dummies(_);
573573
\end{cdbcont}
574574
\begin{cdbcom}
575575
Because the identity which we intend to prove is only supposed to hold
576576
on Einstein spaces, we set the divergence of the Weyl tensor to zero,
577577
\end{cdbcom}
578578
\begin{cdbcont}
579-
@substitute!(%)( \nabla_{i}{C_{k i l m}} -> 0 , \nabla_{i}{C_{k m l i}} -> 0 );
579+
substitute(_, $\nabla_{i}{C_{k i l m}} -> 0 , \nabla_{i}{C_{k m l i}} -> 0$ );
580580
\end{cdbcont}
581581
\begin{cdbout}
582582
\begin{aligned}
@@ -603,9 +603,7 @@ \subsection{A Riemann tensor polynomial example}
603603
expanding all tensors using their Young projectors, this becomes manifest,
604604
\end{cdbcom}
605605
\begin{cdbcont}
606-
@young_project_product!(%):
607-
@sumflatten!(%):
608-
@collect_terms!(%);
606+
young_project_product(_);
609607
\end{cdbcont}
610608
\begin{cdbout}
611609
0;
@@ -641,8 +639,8 @@ \subsection{Index ranges and subspaces, Kaluza-Klein gravity}
641639
{m, n, p}::Indices(subspace1).
642640
{a, b, c}::Indices(subspace2).
643641
644-
A_{M N} B_{N P};
645-
@split_index!(%){M, m, a};
642+
ex:= A_{M N} B_{N P};
643+
split_index(_, $M, m, a$);
646644
\end{cdbin}
647645
\begin{cdbout}
648646
A_{M m} \, B_{m P} + A_{M a}\, B_{a P}\,;
@@ -707,9 +705,10 @@ \subsection{Index ranges and subspaces, Kaluza-Klein gravity}
707705
We will want to expand the Riemann tensor in terms of the metric. The
708706
following two substitution rules do the conversion from Riemann tensor
709707
to Christoffel symbol and from Christoffel symbol to
710-
metric.\footnote{A library with common substitution rules like these
711-
is in preparation.} Index
712-
patterns like \verb|\lambda?| match both four- and three-dimensional indices.
708+
metric.\footnote{Cadabra 2.x contains a growing library of packages
709+
with expressions of this type, but we will here not rely on that
710+
library facility.} Index patterns like \verb|\lambda?| match both four- and
711+
three-dimensional indices.
713712
\end{cdbcom}
714713
\begin{cdbcont}
715714
RtoG:= R^{\lambda?}_{\mu?\nu?\kappa?} ->
@@ -730,12 +729,12 @@ \subsection{Index ranges and subspaces, Kaluza-Klein gravity}
730729
\end{cdbcom}
731730
\begin{cdbcont}
732731
todo:= g_{m1 m} R^{m1}_{4 n 4} + g_{4 m} R^{4}_{4 n 4};
733-
@substitute!(%)( @(RtoG) );
734-
@substitute!(%)( @(Gtog) );
735-
@distribute!(%);
736-
@prodrule!(%);
737-
@distribute!(%);
738-
@prodsort!(%);
732+
substitute(_, RtoG)
733+
substitute(_, Gtog)
734+
distribute(_)
735+
product_rule(_)
736+
distribute(_)
737+
sort_product(_)
739738
\end{cdbcont}
740739
\begin{cdbcom}
741740
We now split the $\mu$ index into a $m$ part and the remaining $4$
@@ -744,55 +743,55 @@ \subsection{Index ranges and subspaces, Kaluza-Klein gravity}
744743
field and write the expression in canonical form,
745744
\end{cdbcom}
746745
\begin{cdbcont}
747-
@split_index!!(%){\mu,m1,4};
748-
@canonicalise!(%):
749-
@substitute!(%)( \partial_{4}{A??} -> 0 );
750-
@substitute!(%)( \partial_{4 m?}{A??} -> 0 );
746+
split_index(_, $\mu, m1, 4$, repeat=True)
747+
substitute(_, $\partial_{4}{A??} -> 0$, repeat=True)
748+
substitute(_, $\partial_{4 m?}{A??} -> 0$, repeat=True)
749+
substitute(_, $\partial_{m? 4}{A??} -> 0$, repeat=True)
750+
canonicalise(_);
751751
\end{cdbcont}
752752
\begin{cdbcom}
753753
In the next step, we insert the metric ansatz~\eqref{e:KKansatz} and
754754
simplify the result as much as possible.
755755
\end{cdbcom}
756756
\begin{cdbcont}
757-
@substitute!(%)( g_{4 4} -> \phi ):
758-
@substitute!(%)( g_{4 m} -> \phi A_{m} ):
759-
@substitute!(%)( g_{m n} -> \phi**{-1} h_{m n} + \phi A_{m} A_{n} );
760-
@substitute!(%)( g^{4 4} -> \phi**{-1} + \phi A_{m} h^{m n} A_{n} ):
761-
@substitute!(%)( g^{4 m} -> - \phi h^{m n} A_{n} ):
762-
@substitute!(%)( g^{m n} -> \phi h^{m n} ):
763-
@distribute!(%):
764-
@prodrule!(%):
765-
@distribute!(%):
766-
@prodrule!(%);
767-
@distribute!(%);
768-
@canonicalise!(%):
769-
@substitute!!(%)( h_{m1 m2} h^{m3 m2} -> \delta_{m1}^{m3} );
770-
@eliminate_kr!(%):
757+
substitute(_, $g_{4 4} -> \phi$ )
758+
substitute(_, $g_{m 4} -> \phi A_{m}$ )
759+
substitute(_, $g_{4 m} -> \phi A_{m}$ )
760+
substitute(_, $g_{m n} -> \phi**{-1} h_{m n} + \phi A_{m} A_{n}$ )
761+
substitute(_, $g^{4 4} -> \phi**{-1} + \phi A_{m} h^{m n} A_{n}$ )
762+
substitute(_, $g^{m 4} -> - \phi h^{m n} A_{n}$ )
763+
substitute(_, $g^{4 m} -> - \phi h^{m n} A_{n}$ )
764+
substitute(_, $g^{m n} -> \phi h^{m n}$ );
771765
\end{cdbcont}
772766
\begin{cdbcom}
773767
Some derivatives have to be rewritten to a canonical form,
774768
\end{cdbcom}
775769
\begin{cdbcont}
776-
@substitute!(%)( \partial_{m}{\phi**{-1}} -> -\phi**{-2} \partial_{m}{\phi} ):
777-
@collect_factors!(%):
778-
@prodsort!(%):
779-
@substitute!(%)( \partial_{p}{h^{n m}} h_{q m} -> - \partial_{p}{h_{q m}} h^{n m} );
780-
@canonicalise!(%):
781-
@substitute!(%)( h_{m1 m2} h^{m3 m2} -> \delta_{m1}^{m3} );
782-
@eliminate_kr!(%);
770+
converge(todo):
771+
distribute(_)
772+
product_rule(_)
773+
canonicalise(_)
774+
\end{cdbcont}
775+
\begin{cdbcont}
776+
substitute(_, $\partial_{p}{h^{n m}} h_{q m} -> - \partial_{p}{h_{q m}} h^{n m}$ )
777+
collect_factors(_)
778+
sort_product(_)
779+
converge(todo):
780+
substitute(_, $h_{m1 m2} h^{m3 m2} -> \delta_{m1}^{m3}$, repeat=True )
781+
eliminate_kronecker(_)
782+
canonicalise(_)
783+
;
783784
\end{cdbcont}
784785
\begin{cdbcom}
785786
Finally, we replace the derivative of the gauge field with the field
786787
strength,
787788
\end{cdbcom}
788789
\begin{cdbcont}
789-
@substitute!(%)( \partial_{n}{A_{m}} -> 1/2*\partial_{n}{A_{m}} + 1/2*F_{n m}
790-
+ 1/2*\partial_{m}{A_{n}} ):
791-
@distribute!(%):
792-
@prodsort!(%):
793-
@canonicalise!(%):
794-
@rename_dummies!(%):
795-
@collect_terms!(%);
790+
substitute(_, $\partial_{n}{A_{m}} -> 1/2*\partial_{n}{A_{m}} + 1/2*F_{n m} + 1/2*\partial_{m}{A_{n}}$ )
791+
distribute(_)
792+
sort_product(_)
793+
canonicalise(_)
794+
rename_dummies(_);
796795
\end{cdbcont}
797796
\begin{cdbout}
798797
\begin{aligned}
@@ -835,16 +834,8 @@ \subsection{Simple gamma matrix algebra}
835834
\Gamma_{k m} \Gamma_{m s}$ in arbitrary dimensions in terms of the
836835
irreducible~$\Gamma_{kl}$ and $\delta_{kl}$ components.
837836
\toprule
838-
\begin{cdbin}
839-
::PostDefaultRules( @@prodsort!(%), @@eliminate_kr!(%),
840-
@@canonicalise!(%), @@collect_terms!(%) ).
841-
\end{cdbin}
842837
\begin{cdbcom}
843-
This single line adds some default simplification rules to the system,
844-
so that we do not have to type these by hand at every stage of the
845-
calculation.
846-
847-
We now declare the vector indices, their range, and the symbols used for
838+
We first declare the vector indices, their range, and the symbols used for
848839
gamma matrices and Kronecker deltas.
849840
\end{cdbcom}
850841
\begin{cdbcont}
@@ -859,35 +850,50 @@ \subsection{Simple gamma matrix algebra}
859850
suppressed. The notation \verb|_{#}| denotes the presence of an
860851
arbitrary number of indices.
861852
862-
Next follows the actual calculation.
853+
It is useful to let Cadabra do a bit more simplification at every step
854+
(more than the default of simply collecting equal terms). This can be
855+
achieved by re-defining the \verb|post_process| function, which gets
856+
called after every step of the computation.
857+
\end{cdbcom}
858+
\begin{cdbin}
859+
def post_process(ex):
860+
sort_product(ex)
861+
eliminate_kronecker(ex)
862+
canonicalise(ex)
863+
collect_terms(ex)
864+
\end{cdbin}
865+
\begin{cdbcom}
866+
This sorts the product, eliminate Kronecker delta's, writes indices in
867+
canonical order and then finally collects equal terms.
868+
869+
Next follows the actual computation. We write down the gamma matrix
870+
product and join gamma matrices three times,
863871
\end{cdbcom}
864872
\begin{cdbcont}
865-
\Gamma_{s r} \Gamma_{r l} \Gamma_{k m} \Gamma_{m s}:
866-
@join!(%){expand}:
867-
@join!(%){expand};
873+
ex:= \Gamma_{s r} \Gamma_{r l} \Gamma_{k m} \Gamma_{m s};
874+
for i in range(3):
875+
join_gamma(_)
876+
distribute(_)
868877
\end{cdbcont}
869878
\begin{cdbout}
870879
\label{e:gam1}
871-
(-1) ((2 \Gamma_{l r} - \Gamma_{l r} d + \delta_{l r} d - \delta_{l r}) (2 \Gamma_{k r} - \Gamma_{k r} d + \delta_{k r} - \delta_{k r} d));
880+
-18 \Gamma_{kl} d + 8 \Gamma_{kl} d d + 12 \Gamma_{kl} - 3\delta_{kl}
881+
+ 6 \delta_{kl} d - 4 \delta_{kl} d d - \Gamma_{k l} d d d +
882+
\delta_{kl} d d d
872883
\end{cdbout}
873884
\begin{cdbcont}
874-
@distribute!(%);
875-
@join!(%){expand};
876-
@distribute!(%);
877-
@factorise!(%){d};
878-
@collect_factors!(%);
885+
factor_in(_, $d$)
886+
collect_factors(_)
879887
\end{cdbcont}
880888
\begin{cdbout}
881-
\Gamma_{k l} (12 - 18 d + 8 d^2 - d^3) + \delta_{k l} ( - 3 + 6 d - 4 d^2 + d^3);
889+
\Gamma_{k l} (- 18 d + 8 d^2 + 12 - d^3) + \delta_{k l} ( - 3 + 6 d - 4 d^2 + d^3);
882890
\end{cdbout}
883891
\botrule
884-
The key ingredient here is the \verb|@join| command, which
892+
The key ingredient here is the \verb|join_gamma| algorithm, which
885893
takes two adjacent gamma matrices and expands their product in terms of
886894
a basis of fully antisymmetrised gamma matrices. In the step
887-
before~\eqref{e:gam1} the two commands join the 1st and 2nd gamma
888-
matrix, as well as the 3rd and 4th. The product is then expanded out
889-
and one final gamma join operation is performed. The last two lines
890-
combine all the $d$-dependence in overall factors.
895+
before~\eqref{e:gam1} the Python loop performs such a join three times
896+
and expands out the resulting product.
891897
892898
In the example above, the spinor indices on the gamma matrices were
893899
suppressed. The \verb|GammaMatrix| property has turned the gamma
@@ -903,14 +909,14 @@ \subsection{Simple gamma matrix algebra}
903909
{a,b,c,d#}::Indices(spinor).
904910
\Gamma_{#}::GammaMatrix(metric=\delta).
905911
(\Gamma_{m n})_{a b} (\Gamma_{n p})_{b c};
906-
@combine!(%);
912+
combine(_);
907913
\end{cdbin}
908914
\begin{cdbout}
909915
(\Gamma_{m n}\, \Gamma_{n p})_{a c};
910916
\end{cdbout}
911917
\begin{cdbcont}
912-
@join!(%){expand}:
913-
@canonicalise!(%);
918+
join_gamma(_)
919+
canonicalise(_);
914920
\end{cdbcont}
915921
\begin{cdbout}
916922
(\Gamma_{m p} \delta_{n n} - \Gamma_{m n} \delta_{n p} + \Gamma_{p n} \delta_{m n}
@@ -924,8 +930,8 @@ \subsection{Simple gamma matrix algebra}
924930
indices:
925931
\toprule
926932
\begin{cdbcont}
927-
@distribute!(%):
928-
@expand!(%);
933+
distribute(_)
934+
expand(_);
929935
\end{cdbcont}
930936
\begin{cdbout}
931937
(\Gamma_{m p})_{a c} \delta_{n n} - (\Gamma_{m n})_{a c} \delta_{n p}

0 commit comments

Comments
 (0)