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
2424namespace 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,
0 commit comments