[bugs:#4355] documentation for trigvalue etc
[maxima.git] / share / tensor / tracefree-code / makeQ0.mac
blobdf1e4be50605c17769c146a1022bce5cadc82c11
1 /* makeQ0: Generate trace-free decomposition of a symmetric tensor.
2  *
3  * Usage: makeQ0(N, [d, g, Q]);
4  *
5  * parameters: N: rank of the tensor to be decomposed (integer, >1)
6  *             d (optional): Number of dimensions (can be symbolic)
7  *             g (optional): Name of the metric (default: n)
8  *             Q (optional): Name of the tensor
9  *
10  * Given the rank-d contravariant tensor Q that is fully symmetric
11  * in all indices, this program defines the itensor components of Q0,
12  * its trace-free decomposition.
13  *
14  * Side effects: 1) loads itensor; 2) redefines imetric and dim,
15  * 3) defines symmetry properties for the metric and Q, 4) defines
16  * contraction properties for Q and Qa, and 5) defines the itensor
17  * components for Qa and Q0.
18  *
19  * Example:
20  *
21  * (%i1) load("makeQ0.mac");
22  * (%o1)                             makeQ0.mac
23  * (%i2) makeQ0(2,3);
24  * (%o2)                                done
25  * (%i3) ishow(Q0([],[a,b]))$
26  *                                            a b
27  *                                   a b   Q n
28  * (%t3)                            Q    - ------
29  *                                           3
30  * (%i4) makeQ0(3,n,g,T);
31  * (%o4)                                done
32  * (%i5) ishow(T0([],[a,b,c]))$
33  *                       a b  c       a  b c      a c  b
34  *                    2 g    T     2 T  g      2 g    T     a b c
35  * (%t5)           (- ---------) - --------- - --------- + T
36  *                     2 n + 4      2 n + 4     2 n + 4
37  *
38  * (c) 2021 Viktor T. Toth (https://www.vttoth.com/)
39  *
40  * This program is free software; you can redistribute it and/or
41  * modify it under the terms of the GNU General Public License as
42  * published by the Free Software Foundation; either version 2 of
43  * the License, or (at your option) any later version.
44  *
45  * This program is distributed in the hope that it will be
46  * useful, but WITHOUT ANY WARRANTY; without even the implied
47  * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR
48  * PURPOSE.  See the GNU General Public License for more details.
49  */
51 makeQ0(N,[L]):=block
53  [AI,II,I3,E,i,j,a,q,q0],
54  if not get('makeQ0,'version) then
55  (
56   put('makeQ0,'20210720,'version),
57   load(itensor)
58  ),
59  if not integerp(N) or N < 2 then
60    return("makeQ0: first argument must be an integer greater than 1!"),
61  if length(L)>2 then (q:L[3],q0:concat(L[3],"0"),a:concat(L[3],"a"))
62                 else (q:Q,q0:Q0,a:Qa),
63  if length(L)>1 then imetric(L[2]) else imetric(n),
64  if length(L)>0 then dim:L[1] else dim:'d,
65  decsym(imetric,2,0,[sym(all)],[]),
66  decsym(imetric,0,2,[],[sym(all)]),
67  defcon(a,a,a),
68  defcon(q,q,q),
69  for i from 2 thru N-2 do
70  (
71   decsym(a,i,0,[sym(all)],[]),
72   decsym(a,0,i,[],[sym(all)]),
73   decsym(q,i,0,[sym(all)],[]),
74   decsym(q,0,i,[],[sym(all)])
75  ),
76  remcomps(a),
77  AI:makelist(eval_string(concat("a",i)),i,1,N),
78  II:makelist(eval_string(concat("i",i)),i,1,N),
79  I3:makelist(eval_string(concat("i",i)),i,3,N),
80  E:makelist(0,i,0,(N+1)/2),
81  E[1]:(canform(contract(expand(kdels(II,AI)*ev(imetric)([],[i1,i2])*a([],I3))))),
82  for i thru N-1 step 2 do (
83   E[(i+3)/2]:(canform(contract(contract(expand(E[(i+1)/2]*
84               ev(imetric)([AI[i],AI[i+1]]))))))
85  ),
86  if evenp(N) then components(a([],[]),rhs(solve(q([],[])=E[N/2+1],a([],[]))[1])),
87  for i from N+(if evenp(N) then -1 else 0) thru 3 step -2 do
88   components(a([],makelist(AI[j],j,i,N)),
89              rhs(solve(q([],makelist(AI[j],j,i,N))=ev(E[(i+1)/2],a),
90                        a([],makelist(AI[j],j,i,N)))[1])),
91  components(q0([],AI),q([],AI)-ev(E[1],a))