Skip to content

Commit 37cdbdd

Browse files
committed
Fix handling of auto-declare names ('A#'); these were not matched correctly to numbered names ('A18').
1 parent 636a232 commit 37cdbdd

File tree

3 files changed

+45
-2
lines changed

3 files changed

+45
-2
lines changed

core/Compare.cc

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
#include "properties/SortOrder.hh"
1919

2020
// In order to enable/disable debug output, also flip the swith in 'report' below.
21-
//#define DEBUG(ln) ln
21+
// #define DEBUG(ln) ln
2222
#define DEBUG(ln)
2323

2424
namespace cadabra {
@@ -60,6 +60,7 @@ namespace cadabra {
6060
else return -mult;
6161
}
6262

63+
DEBUG( std::cerr << "auto? " << one->is_autodeclare_wildcard() << ", " << two->is_numbered_symbol() << std::endl; );
6364
if( (one->is_autodeclare_wildcard() && two->is_numbered_symbol()) ||
6465
(two->is_autodeclare_wildcard() && one->is_numbered_symbol()) ) {
6566
if( one->name_only() != two->name_only() ) {
@@ -71,6 +72,8 @@ namespace cadabra {
7172
if(*one->name < *two->name) return mult;
7273
else return -mult;
7374
}
75+
76+
DEBUG( std::cerr << "match despite difference: " << *one->name << " and " << *two->name << std::endl; );
7477
}
7578

7679
// Compare parent relations.
@@ -855,7 +858,7 @@ namespace cadabra {
855858
}
856859
}
857860

858-
if(one->name==two->name) {
861+
if(name_match_with_autodeclare(one, two)) {
859862
if(nobrackets || (one->multiplier == two->multiplier) ) {
860863
if(ignore_parent_rel || one->fl.parent_rel==two->fl.parent_rel) return report( match_t::node_match );
861864
report( (one->fl.parent_rel < two->fl.parent_rel)
@@ -865,6 +868,10 @@ namespace cadabra {
865868
if(*one->multiplier < *two->multiplier) return report(match_t::no_match_less);
866869
else return report(match_t::no_match_greater);
867870
}
871+
else if( ((one->is_autodeclare_wildcard() && two->is_numbered_symbol()) ||
872+
(two->is_autodeclare_wildcard() && one->is_numbered_symbol()) ) && one->name_only()==two->name_only() ) {
873+
return report(match_t::node_match);
874+
}
868875
else {
869876
if( *one->name < *two->name ) return report(match_t::no_match_less);
870877
else return report(match_t::no_match_greater);
@@ -876,6 +883,16 @@ namespace cadabra {
876883
return report(match_t::no_match_less);
877884
}
878885

886+
bool Ex_comparator::name_match_with_autodeclare(Ex::sibling_iterator one, Ex::sibling_iterator two) const
887+
{
888+
if(one->name==two->name) return true;
889+
if((one->is_autodeclare_wildcard() && two->is_numbered_symbol()) ||
890+
(two->is_autodeclare_wildcard() && one->is_numbered_symbol()) ) {
891+
if( one->name_only()==two->name_only() )
892+
return true;
893+
}
894+
return false;
895+
}
879896

880897
Ex_comparator::match_t Ex_comparator::match_subproduct(const Ex& tr,
881898
Ex::sibling_iterator lhs,

core/Compare.hh

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -368,6 +368,10 @@ namespace cadabra {
368368
std::string tab() const;
369369
match_t report(match_t r) const;
370370

371+
/// Match the `name` elements of a node, but take into account that
372+
/// one of them can be an autodeclare name `XXX#`.
373+
bool name_match_with_autodeclare(Ex::sibling_iterator one, Ex::sibling_iterator two) const;
374+
371375
static int offset;
372376
};
373377

tests/basic.cdb

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -343,3 +343,25 @@ def test38():
343343

344344
test38()
345345

346+
def test39():
347+
__cdbkernel__=create_scope()
348+
A#_{a b c}::AntiSymmetric;
349+
tst:=A1_{a b c} + A1_{a c b};
350+
canonicalise(_)
351+
assert(tst==0)
352+
print("Test 39 passed")
353+
354+
test39()
355+
356+
def test40():
357+
__cdbkernel__=create_scope()
358+
{a,b,c,d,e,f,g,h}::Indices(position=independent);
359+
T#^{a b c}_{e f}::TableauSymmetry(shape={1,1}, indices={3,4});
360+
ex:=T1^{a b c}_{e f} T2^{e f g}_{h i} - T1^{a b c}_{e f} T2^{f e g}_{h i};
361+
canonicalise(ex)
362+
tst:=2 T1^{a b c}_{e f} T2^{e f g}_{h i} - @(ex);
363+
assert(tst==0)
364+
print("Test 40 passed")
365+
366+
test40()
367+

0 commit comments

Comments
 (0)