@@ -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 ();
0 commit comments