File: sorting.cdb

package info (click to toggle)
cadabra 1.46-6
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 5,244 kB
  • sloc: cpp: 33,188; ansic: 2,724; makefile: 329; yacc: 180; sh: 157; python: 45; lex: 38; lisp: 19
file content (65 lines) | stat: -rw-r--r-- 1,390 bytes parent folder | download | duplicates (5)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65

# Sorting can be done with or without taking into account the 
# numbers used to label dummy indices. 

A_{?}::SelfCommuting.

obj:=  A_{d3 d2 d1} A_{d7 d8 a1};
# @prodsort!(%){IgnoreNumbers};
# tst1:= A_{d7 d8 a1} A_{d3 d2 d1} - @(obj):
# @collect_terms!(%);
# @assert(tst1);

@prodsort!(obj);
tst2:= A_{d3 d2 d1} A_{d7 d8 a1} - @(obj):
@collect_terms!(%);
@assert(tst2);

# Test 2: Inheritance
@reset.
\Gamma_{#}::GammaMatrix. 
\psi::Spinor.
D_{#}::Derivative.
\bar{#}::DiracBar.
obj2:= \bar{\psi} * \Gamma_{m n p} * D_{p}{\psi};
@prodsort!(%);
tst2:= \bar{\psi} * \Gamma_{m n p} * D_{p}{\psi} - @(obj2);
@collect_terms!(%);
@assert(tst2);

# Test 3: Powers.
@reset.
{ y, y**n?, x, x**n? }::SortOrder.
obj3:= x**4 y**4;
@prodsort!(%);
tst3:= y**4 x**4 - @(obj3);
@collect_terms!(%);
@assert(tst3);

@reset.
F_{a b}::AntiSymmetric.
F1_{a b}::AntiSymmetric.
obj4:= F1_{a b}F_{c d}:
@prodsort!(%);

# Test 4: sorting by index position
#
@reset.
{a,b}::Indices(position=fixed).
{ n^a, n_a }::SortOrder.
obj4:= n_a n_b n^a;
@prodsort!(%);
tst4:= n^a n_a n_b - @(obj4);
@collect_terms!(%);
@assert(tst4);

# Note: sorting by index name is not supported; the two
# patterns in the SortOrder declaration below are identical,
# so that when n_a is searched in the list, it is matched
# against n_b and given position=0, not position=1.
#
@reset.
{ n_b, n_a }::SortOrder.
n_a n_b;
@prodsort!(%);