Skip to content

Commit 16bdd6a

Browse files
author
Kasper Peeters
committed
Introduce a 'tie' operator '~' to join lists.
1 parent be7ecac commit 16bdd6a

File tree

6 files changed

+38
-1
lines changed

6 files changed

+38
-1
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 9)
4-
set(CADABRA_VERSION_TWEAK 3)
4+
set(CADABRA_VERSION_TWEAK 4)
55
set(COPYRIGHT_YEARS "2001-2022")
66
math(EXPR SYSTEM_BITS "${CMAKE_SIZEOF_VOID_P} * 8")
77
find_program(GIT git PATHS ${GIT_DIR})

core/Cleanup.cc

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@ namespace cadabra {
4848
changed = changed || res;
4949
if(*it->name=="\\comma") res = cleanup_comma(kernel, tr, it);
5050
changed = changed || res;
51+
if(*it->name=="\\tie") res = cleanup_tie(kernel, tr, it);
52+
changed = changed || res;
5153
if(*it->name=="\\components") res = cleanup_components(kernel, tr, it);
5254
changed = changed || res;
5355

@@ -871,6 +873,29 @@ namespace cadabra {
871873
else return false;
872874
}
873875

876+
bool cleanup_tie(const Kernel& k, Ex& tr, Ex::iterator& it)
877+
{
878+
// Are all siblings lists?
879+
Ex::sibling_iterator sib = tr.begin(it);
880+
while(sib!=tr.end(it)) {
881+
if(*sib->name!="\\comma")
882+
return false;
883+
++sib;
884+
}
885+
886+
// All siblings are lists. Join them together into one
887+
// long list.
888+
it->name = name_set.insert("\\comma").first;
889+
sib=tr.begin(it);
890+
while(sib!=tr.end(it)) {
891+
auto nxt = sib;
892+
++nxt;
893+
tr.flatten_and_erase(sib);
894+
sib=nxt;
895+
}
896+
return true;
897+
}
898+
874899
void cleanup_dispatch_deep(const Kernel& k, Ex& tr, dispatcher_t dispatch)
875900
{
876901
Ex::iterator top=tr.begin();

core/Cleanup.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@ namespace cadabra {
7777
bool cleanup_kronecker(const Kernel& k, Ex&, Ex::iterator& it);
7878
bool cleanup_exterior_derivative(const Kernel& k, Ex&, Ex::iterator& it);
7979
bool cleanup_comma(const Kernel&k, Ex&, Ex::iterator& it);
80+
bool cleanup_tie(const Kernel&k, Ex&, Ex::iterator& it);
8081

8182
/// Given a node with a non-unit multiplier, push this multiplier
8283
/// down the tree if the node is not allowed to have a non-unit

tests/programming.cdb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -283,3 +283,11 @@ def test13():
283283
print("Test 13 passed")
284284

285285
test13()
286+
287+
def test14():
288+
__cdbkernel__ = create_scope()
289+
ex:={A,B} ~ {C,D};
290+
assert(ex==${A,B,C,D}$)
291+
print("Test 14 passed")
292+
293+
test14()

web2/cadabra2/.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@
1111
algo_toc.html
1212
prop_toc.html
1313
packages_toc.html
14+
source/the_cadabra_book.pdf

web2/cadabra2/source/changelog.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@ <h3>github master (2.3.9)</h3>
2828
<li>Fix for Python 3.10.x.</li>
2929
<li>Fix for automatic cleanup of <tt>Diagonal</tt> objects.</li>
3030
<li>Fix crash with tab-completion.</li>
31+
<li>Make '+' operator add lists component-wise, and introduce the
32+
tie operator '~' to join lists.</li>
3133
</ul>
3234

3335
<a name="2.3.8"></a>

0 commit comments

Comments
 (0)