Skip to content

Commit 007a769

Browse files
author
Dominic Price
committed
Merge branch 'master' into domdev
2 parents 4b60ea3 + 9598e70 commit 007a769

File tree

8 files changed

+188
-8
lines changed

8 files changed

+188
-8
lines changed

cmake/version.cmake

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
set(CADABRA_VERSION_MAJOR 2)
22
set(CADABRA_VERSION_MINOR 3)
33
set(CADABRA_VERSION_PATCH 7)
4-
set(CADABRA_VERSION_TWEAK 3)
4+
set(CADABRA_VERSION_TWEAK 4)
55
set(COPYRIGHT_YEARS "2001-2021")
66
math(EXPR SYSTEM_BITS "${CMAKE_SIZEOF_VOID_P} * 8")
77
find_program(GIT git PATHS ${GIT_DIR})

core/algorithms/slot_asym.cnb

Lines changed: 123 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,123 @@
1+
{
2+
"cell_id": 15939251759909380531,
3+
"cells": [
4+
{
5+
"cell_id": 9909884154184314133,
6+
"cell_origin": "client",
7+
"cell_type": "latex",
8+
"cells": [
9+
{
10+
"cell_id": 11121169234497922857,
11+
"cell_origin": "client",
12+
"cell_type": "latex_view",
13+
"source": "\\algorithm{slot_asym}{Anti-symmetrise or symmetrise an expression in indicated index slots}\n\nAnti-symmetrise or symmetrise (depending on the \\verb|antisymmetric| flag) a product or tensor in the indicated indices,\nwhere the indices are given as slot positions. This complements the \\algo{asym} algorithm, which instead takes the\nindex names over which to (anti-)symmetrise."
14+
}
15+
],
16+
"hidden": true,
17+
"source": "\\algorithm{slot_asym}{Anti-symmetrise or symmetrise an expression in indicated index slots}\n\nAnti-symmetrise or symmetrise (depending on the \\verb|antisymmetric| flag) a product or tensor in the indicated indices,\nwhere the indices are given as slot positions. This complements the \\algo{asym} algorithm, which instead takes the\nindex names over which to (anti-)symmetrise."
18+
},
19+
{
20+
"cell_id": 1631820596417225138,
21+
"cell_origin": "client",
22+
"cell_type": "input",
23+
"cells": [
24+
{
25+
"cell_id": 7595867900720961056,
26+
"cell_origin": "server",
27+
"cell_type": "latex_view",
28+
"cells": [
29+
{
30+
"cell_id": 13265193798604235312,
31+
"cell_origin": "server",
32+
"cell_type": "input_form",
33+
"source": "A_{m n} B_{p q}"
34+
}
35+
],
36+
"source": "\\begin{dmath*}{}A_{m n} B_{p q}\\end{dmath*}"
37+
}
38+
],
39+
"source": "ex:=A_{m n} B_{p q};"
40+
},
41+
{
42+
"cell_id": 15329301797986921853,
43+
"cell_origin": "client",
44+
"cell_type": "input",
45+
"cells": [
46+
{
47+
"cell_id": 6618699822479866787,
48+
"cell_origin": "server",
49+
"cell_type": "latex_view",
50+
"cells": [
51+
{
52+
"cell_id": 4925730957034195862,
53+
"cell_origin": "server",
54+
"cell_type": "input_form",
55+
"source": " 1/2 A_{m n} B_{p q} - 1/2 A_{m p} B_{n q}"
56+
}
57+
],
58+
"source": "\\begin{dmath*}{}\\frac{1}{2}A_{m n} B_{p q} - \\frac{1}{2}A_{m p} B_{n q}\\end{dmath*}"
59+
}
60+
],
61+
"source": "slot_asym(_, [1,2]);"
62+
},
63+
{
64+
"cell_id": 2136548790978716924,
65+
"cell_origin": "client",
66+
"cell_type": "latex",
67+
"cells": [
68+
{
69+
"cell_id": 9595072634954805885,
70+
"cell_origin": "client",
71+
"cell_type": "latex_view",
72+
"source": "If you want to \\emph{symmetrise} in the indicated objects instead, use the \\verb|antisymmetric=False| flag:"
73+
}
74+
],
75+
"hidden": true,
76+
"source": "If you want to \\emph{symmetrise} in the indicated objects instead, use the \\verb|antisymmetric=False| flag:"
77+
},
78+
{
79+
"cell_id": 341154554226938963,
80+
"cell_origin": "client",
81+
"cell_type": "input",
82+
"cells": [
83+
{
84+
"cell_id": 10010981841376155594,
85+
"cell_origin": "server",
86+
"cell_type": "latex_view",
87+
"cells": [
88+
{
89+
"cell_id": 1454030977596719820,
90+
"cell_origin": "server",
91+
"cell_type": "input_form",
92+
"source": "A_{m n} B_{p q}"
93+
}
94+
],
95+
"source": "\\begin{dmath*}{}A_{m n} B_{p q}\\end{dmath*}"
96+
},
97+
{
98+
"cell_id": 13362812056189562810,
99+
"cell_origin": "server",
100+
"cell_type": "latex_view",
101+
"cells": [
102+
{
103+
"cell_id": 6588625381382353233,
104+
"cell_origin": "server",
105+
"cell_type": "input_form",
106+
"source": " 1/2 A_{m n} B_{p q} + 1/2 A_{m p} B_{n q}"
107+
}
108+
],
109+
"source": "\\begin{dmath*}{}\\frac{1}{2}A_{m n} B_{p q}+\\frac{1}{2}A_{m p} B_{n q}\\end{dmath*}"
110+
}
111+
],
112+
"source": "ex:=A_{m n} B_{p q};\nslot_asym(_, [1,2], antisymmetric=False);"
113+
},
114+
{
115+
"cell_id": 5279739485549689433,
116+
"cell_origin": "client",
117+
"cell_type": "input",
118+
"source": ""
119+
}
120+
],
121+
"description": "Cadabra JSON notebook format",
122+
"version": 1.0
123+
}

core/algorithms/sym.cc

Lines changed: 45 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@ using namespace cadabra;
66
// #define DEBUG 1
77

88
sym::sym(const Kernel& k, Ex& tr, const std::vector<unsigned int>& slots, bool s)
9-
: Algorithm(k, tr), sign(s), argloc_2_treeloc(slots)
9+
: Algorithm(k, tr), sign(s), slotloc(slots)
1010
{
11+
#ifdef DEBUG
12+
std::cerr << "sym::sym: initialised with slot positions." << std::endl;
13+
#endif
1114
}
1215

1316
sym::sym(const Kernel& k, Ex& tr, Ex& objs, bool s)
@@ -26,24 +29,54 @@ bool sym::can_apply(iterator it)
2629
prod_wrap_single_term(it);
2730
bool located=false;
2831
if(objects.size()>0) {
32+
#ifdef DEBUG
33+
std::cerr << "sym::can_apply: finding objects" << std::endl;
34+
#endif
2935
argloc_2_treeloc.clear();
3036
located=locate_object_set(objects, tr.begin(it), tr.end(it), argloc_2_treeloc);
3137
}
3238
else {
39+
#ifdef DEBUG
40+
std::cerr << "sym::can_apply: collecting objects" << std::endl;
41+
#endif
3342
objects.set_head(str_node("\\comma"));
34-
for(size_t i=0; i<argloc_2_treeloc.size(); ++i) {
43+
argloc_2_treeloc.clear();
44+
argloc_2_treeloc.resize(slotloc.size(), 0);
45+
for(size_t i=0; i<slotloc.size(); ++i) {
3546
auto ind=begin_index(it);
36-
ind+=argloc_2_treeloc[i];
37-
// FIXME: verify that indices are not out-of-range.
38-
objects.append_child(Ex::iterator(ind));
47+
ind+=slotloc[i];
48+
if(tr.is_valid(ind)==false) {
49+
throw ArgumentException("Expression does not have at least "+std::to_string(slotloc[i]+1)+" indices.");
50+
}
51+
#ifdef DEBUG
52+
std::cerr << "sym::can_apply: adding " << ind << std::endl;
53+
#endif
54+
objects.append_child(objects.begin(), Ex::iterator(ind));
55+
56+
// Convert the index-index to iterator-index (the former says how many times
57+
// an IndexIterator should be incremented, the latter says how many times a
58+
// generic Iterator should be incremented).
59+
iterator steps=tr.begin(it);
60+
while(steps!=iterator(ind)) {
61+
++steps;
62+
++argloc_2_treeloc[i];
63+
}
3964
}
65+
located=true;
4066
}
4167
prod_unwrap_single_term(it);
68+
#ifdef DEBUG
69+
std::cerr << "sym::can_apply: ready to go: " << located << std::endl;
70+
#endif
4271
return located;
4372
}
4473

4574
Algorithm::result_t sym::apply(iterator& it)
4675
{
76+
#ifdef DEBUG
77+
std::cerr << "sym::apply: running" << std::endl;
78+
#endif
79+
4780
prod_wrap_single_term(it);
4881
result_t res=doit(it,sign);
4982
// if(res==result_t::l_applied)
@@ -58,6 +91,10 @@ Algorithm::result_t sym::doit(iterator& it, bool sign)
5891
{
5992
assert(*it->name=="\\prod");
6093

94+
#ifdef DEBUG
95+
std::cerr << "sym::doit: " << objects << std::endl;
96+
#endif
97+
6198
// Setup combinations class. First construct original and block length.
6299
sibling_iterator fst=objects.begin(objects.begin());
63100
sibling_iterator fnd=objects.end(objects.begin());
@@ -67,6 +104,9 @@ Algorithm::result_t sym::doit(iterator& it, bool sign)
67104
for(unsigned int i=0; i<argloc_2_treeloc.size(); ++i)
68105
raw_ints.original.push_back(i);
69106
while(fst!=fnd) {
107+
#ifdef DEBUG
108+
std::cerr << "sym::doit: object " << *fst->name << std::endl;
109+
#endif
70110
if(*(fst->name)=="\\comma") {
71111
if(raw_ints.block_length==0) raw_ints.block_length=tr.number_of_children(fst);
72112
else assert(raw_ints.block_length==tr.number_of_children(fst));

core/algorithms/sym.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ namespace cadabra {
1818
Ex objects;
1919
bool sign;
2020

21+
std::vector<unsigned int> slotloc;
2122
std::vector<unsigned int> argloc_2_treeloc;
2223
combin::combinations<unsigned int> raw_ints;
2324

tests/symmetry.cdb

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,3 +87,13 @@ def test08():
8787
print('Test 08 passed')
8888

8989
test08()
90+
91+
def test09():
92+
__cdbkernel__=create_scope()
93+
ex:= 1/2 A_{a b} B_{c d};
94+
slot_asym(ex, [1,2], deep=False)
95+
tst:= 1/4 A_{a b} B_{c d} - 1/4 A_{a c} B_{b d} - @(ex);
96+
assert(tst==0)
97+
print("Test 09 passed")
98+
99+
test09()

web2/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@ set(CONTRIBS
7272

7373
set(ALGOS
7474
asym
75+
slot_asym
7576
canonicalise
7677
collect_factors
7778
collect_terms

web2/cadabra2/source/changelog.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@ <h1>Change log</h1>
1818
<a name="master"></a>
1919
<h3>github master (2.3.7)</h3>
2020
<ul>
21+
<li>New algorithm <tt>slot_asym</tt> to (anti-)symmetrise objects in
22+
indices by giving index positions instead of names.</li>
23+
<li>New functionality to implement algorithms in Python (Dominic).</li>
2124
<li>Faster re-implementation of <tt>get_component</tt> using new
2225
C++ function modules (Dominic).</li>
2326
<li>New <tt>cdb.numeric.evaluate</tt>

web2/cadabra2/source/papers.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,9 +92,11 @@ <h1>Research papers citing Cadabra</h1>
9292
maintain by hand, but Google Scholar does an excellent job at it.
9393
See the
9494
<a href="http://scholar.google.com/scholar?oi=bibs&hl=en&cites=13084737546483891451">list
95-
of papers citing the Comp.Phys.Comm. paper</a> and the
95+
of papers citing the Comp.Phys.Comm. paper</a>, the
9696
<a href="http://scholar.google.com/scholar?oi=bibs&hl=en&cites=6862449820033381676">list
97-
of papers citing the hep-th paper</a>.
97+
of papers citing the hep-th paper</a> and
98+
the <a href="https://scholar.google.co.uk/scholar?cites=12816060198742513768&as_sdt=2005&sciodt=0,5&hl=en">list
99+
of papers citing the Cadabra2 paper</a>.
98100
</p>
99101

100102
{%- endblock %}

0 commit comments

Comments
 (0)