Skip to content

Commit 8061fe9

Browse files
committed
Young tableau and LR improvements.
1 parent e021d67 commit 8061fe9

File tree

12 files changed

+174
-98
lines changed

12 files changed

+174
-98
lines changed

client_server/notebook.tex

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
\usepackage[scale=.8]{geometry}
77
\usepackage{setspace}
88
\usepackage{fancyhdr}
9+
\usepackage{ytableau}
910
\usepackage{listings}
1011
\usepackage[fleqn]{amsmath}
1112
\usepackage{color}
@@ -177,3 +178,4 @@
177178
\advance\accvspace by -\ytsize%
178179
\fi}\kern-\maxw}}
179180

181+
\ytableausetup{centertableaux} % smalltableaux

core/DisplayTeX.cc

Lines changed: 81 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,9 @@
77
#include "properties/LaTeXForm.hh"
88
#include "properties/Derivative.hh"
99
#include "properties/Accent.hh"
10+
#include "properties/Tableau.hh"
11+
#include "properties/FilledTableau.hh"
12+
#include "properties/TableauInherit.hh"
1013

1114
#define nbsp " "
1215
//(( parent.utf8_output?(unichar(0x00a0)):" "))
@@ -69,6 +72,8 @@ bool DisplayTeX::needs_brackets(Ex::iterator it)
6972
}
7073
}
7174

75+
if(parent=="\\oplus" && child=="\\otimes") return true;
76+
7277
if(parent=="\\pow" && (child=="\\prod" || child=="\\sum" || child=="\\oplus" || der)) return true;
7378

7479
if(parent=="\\wedge" && child=="\\prod") return true;
@@ -200,17 +205,16 @@ void DisplayTeX::print_tableau(std::ostream& str, Ex::iterator it)
200205
str << "\\, ";
201206
}
202207

203-
str << texify(*it->name);
208+
str << "\\ydiagram{";
204209
auto sib=tree.begin(it);
205-
str << "{";
206210
while(sib!=tree.end(it)) {
207-
str << "{";
208-
dispatch(str, sib);
209-
str << "}";
211+
str << *sib->multiplier;
210212
++sib;
213+
if(sib!=tree.end(it))
214+
str << ",";
211215
}
212216
str << "}";
213-
217+
214218
if(needs_brackets(it))
215219
str << "\\right)";
216220
}
@@ -226,12 +230,9 @@ void DisplayTeX::print_ftableau(std::ostream& str, Ex::iterator it)
226230
str << "\\, ";
227231
}
228232

229-
str << texify(*it->name);
233+
str << "\\ytableaushort{";
230234
auto sib=tree.begin(it);
231-
str << "{";
232235
while(sib!=tree.end(it)) {
233-
if(sib!=tree.begin(it))
234-
str << ",";
235236
if(*sib->name!="\\comma") {
236237
str << "{";
237238
dispatch(str, sib);
@@ -247,6 +248,8 @@ void DisplayTeX::print_ftableau(std::ostream& str, Ex::iterator it)
247248
}
248249
}
249250
++sib;
251+
if(sib!=tree.end(it))
252+
str << ",";
250253
}
251254
str << "}";
252255

@@ -458,26 +461,26 @@ void DisplayTeX::print_parent_rel(std::ostream& str, str_node::parent_rel_t pr,
458461

459462
void DisplayTeX::dispatch(std::ostream& str, Ex::iterator it)
460463
{
461-
if(*it->name=="\\prod") print_productlike(str, it, " ");
462-
else if(*it->name=="\\sum" || *it->name=="\\oplus") print_sumlike(str, it);
463-
else if(*it->name=="\\frac") print_fraclike(str, it);
464-
else if(*it->name=="\\comma") print_commalike(str, it);
465-
else if(*it->name=="\\arrow") print_arrowlike(str, it);
466-
else if(*it->name=="\\inner") print_dot(str, it);
467-
else if(*it->name=="\\pow") print_powlike(str, it);
468-
else if(*it->name=="\\int") print_intlike(str, it);
469-
else if(*it->name=="\\equals" || *it->name=="\\unequals") print_equalitylike(str, it);
470-
else if(*it->name=="\\commutator") print_commutator(str, it, true);
471-
else if(*it->name=="\\anticommutator") print_commutator(str, it, false);
472-
else if(*it->name=="\\components") print_components(str, it);
473-
else if(*it->name=="\\wedge") print_wedgeproduct(str, it);
474-
else if(*it->name=="\\conditional") print_conditional(str, it);
475-
else if(*it->name=="\\greater" || *it->name=="\\less") print_relation(str, it);
476-
else if(*it->name=="\\indexbracket") print_indexbracket(str, it);
477-
else if(*it->name=="\\tableau") print_tableau(str, it);
478-
else if(*it->name=="\\ftableau") print_ftableau(str, it);
479-
else if(*it->name=="\\ldots") print_dots(str, it);
480-
else print_other(str, it);
464+
if(*it->name=="\\prod") print_productlike(str, it, " ");
465+
else if(*it->name=="\\sum" || *it->name=="\\oplus") print_sumlike(str, it);
466+
else if(*it->name=="\\frac") print_fraclike(str, it);
467+
else if(*it->name=="\\comma") print_commalike(str, it);
468+
else if(*it->name=="\\arrow") print_arrowlike(str, it);
469+
else if(*it->name=="\\inner") print_dot(str, it);
470+
else if(*it->name=="\\pow") print_powlike(str, it);
471+
else if(*it->name=="\\int") print_intlike(str, it);
472+
else if(*it->name=="\\equals" || *it->name=="\\unequals") print_equalitylike(str, it);
473+
else if(*it->name=="\\commutator") print_commutator(str, it, true);
474+
else if(*it->name=="\\anticommutator") print_commutator(str, it, false);
475+
else if(*it->name=="\\components") print_components(str, it);
476+
else if(*it->name=="\\wedge") print_wedgeproduct(str, it);
477+
else if(*it->name=="\\conditional") print_conditional(str, it);
478+
else if(*it->name=="\\greater" || *it->name=="\\less") print_relation(str, it);
479+
else if(*it->name=="\\indexbracket") print_indexbracket(str, it);
480+
else if(*it->name=="\\ldots") print_dots(str, it);
481+
else if(kernel.properties.get<Tableau>(it)) print_tableau(str, it);
482+
else if(kernel.properties.get<FilledTableau>(it)) print_ftableau(str, it);
483+
else print_other(str, it);
481484
}
482485

483486
void DisplayTeX::print_commalike(std::ostream& str, Ex::iterator it)
@@ -576,6 +579,14 @@ void DisplayTeX::print_productlike(std::ostream& str, Ex::iterator it, const std
576579
str_node::bracket_t previous_bracket_=str_node::b_invalid;
577580
// bool beginning_of_group=true;
578581
Ex::sibling_iterator ch=tree.begin(it);
582+
bool prev_is_tableau=false;
583+
if(ch!=tree.end(it)) {
584+
const Tableau *tab =kernel.properties.get<Tableau>(ch);
585+
const FilledTableau *ftab=kernel.properties.get<FilledTableau>(ch);
586+
const TableauInherit *itab=kernel.properties.get<TableauInherit>(ch);
587+
if(tab || ftab || itab)
588+
prev_is_tableau=true;
589+
}
579590
while(ch!=tree.end(it)) {
580591
str_node::bracket_t current_bracket_=(*ch).fl.bracket;
581592
if(previous_bracket_!=current_bracket_) {
@@ -590,14 +601,26 @@ void DisplayTeX::print_productlike(std::ostream& str, Ex::iterator it, const std
590601
if(current_bracket_!=str_node::b_none)
591602
print_closing_bracket(str, current_bracket_, str_node::p_none);
592603
}
593-
594-
if(ch!=tree.end(it)) {
595-
if(print_star) {
596-
if(tight_star) str << inbetween;
597-
else str << " " << inbetween << " ";
604+
else {
605+
const Tableau *tab =kernel.properties.get<Tableau>(ch);
606+
const FilledTableau *ftab=kernel.properties.get<FilledTableau>(ch);
607+
const TableauInherit *itab=kernel.properties.get<TableauInherit>(ch);
608+
if(tab || ftab || itab) {
609+
if(prev_is_tableau)
610+
str << " \\otimes ";
611+
else
612+
str << " ";
613+
prev_is_tableau=true;
598614
}
599615
else {
600-
str << " ";
616+
prev_is_tableau=false;
617+
if(print_star) {
618+
if(tight_star) str << inbetween;
619+
else str << " " << inbetween << " ";
620+
}
621+
else {
622+
str << " ";
623+
}
601624
}
602625
}
603626
previous_bracket_=current_bracket_;
@@ -618,6 +641,14 @@ void DisplayTeX::print_sumlike(std::ostream& str, Ex::iterator it)
618641
unsigned int steps=0;
619642

620643
Ex::sibling_iterator ch=tree.begin(it);
644+
bool prev_is_tableau=false;
645+
if(ch!=tree.end(it)) {
646+
const Tableau *tab =kernel.properties.get<Tableau>(ch);
647+
const FilledTableau *ftab=kernel.properties.get<FilledTableau>(ch);
648+
const TableauInherit *itab=kernel.properties.get<TableauInherit>(ch);
649+
if(tab || ftab || itab)
650+
prev_is_tableau=true;
651+
}
621652
while(ch!=tree.end(it)) {
622653
// if(ch!=tree.begin(it))
623654
// str << "%\n"; // prevent LaTeX overflow.
@@ -626,8 +657,20 @@ void DisplayTeX::print_sumlike(std::ostream& str, Ex::iterator it)
626657
str << "%\n"; // prevent LaTeX overflow.
627658
}
628659
if(*ch->multiplier>=0 && ch!=tree.begin(it)) {
629-
if(*it->name=="\\sum")
630-
str << "+";
660+
if(*it->name=="\\sum") {
661+
const Tableau *tab =kernel.properties.get<Tableau>(ch);
662+
const FilledTableau *ftab=kernel.properties.get<FilledTableau>(ch);
663+
const TableauInherit *itab=kernel.properties.get<TableauInherit>(ch);
664+
if(tab || ftab || itab) {
665+
if(prev_is_tableau)
666+
str << " \\oplus ";
667+
else
668+
str << "+";
669+
prev_is_tableau=true;
670+
}
671+
else
672+
str << "+";
673+
}
631674
else
632675
str << *it->name << "{}";
633676
}

core/algorithms/distribute.cc

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ bool distribute::can_apply(iterator st)
2424

2525
sibling_iterator facs=tr.begin(st);
2626
while(facs!=tr.end(st)) {
27-
if(*(*facs).name=="\\sum")
27+
if(*(*facs).name=="\\sum" || *(*facs).name=="\\oplus")
2828
return true;
2929
// if(*st->name=="\\indexbracket" || *st->name=="\\diff") break; // only first argument is object
3030
++facs;
@@ -49,8 +49,10 @@ Algorithm::result_t distribute::apply(iterator& prod)
4949
// "facs" iterates over all child nodes of the distributable (top-level) node
5050
sibling_iterator facs=tr.begin(prod);
5151
while(facs!=tr.end(prod)) {
52-
if(*(*facs).name=="\\sum") {
52+
std::string sumname=*(*facs).name;
53+
if(sumname=="\\sum" || sumname=="\\oplus") {
5354
sibling_iterator se=rep.begin(top);
55+
rep.begin()->name=facs->name;
5456
// "se" iterates over all nodes in the replacement \sum
5557
while(se!=rep.end(top)) {
5658
if(interrupted)

core/algorithms/lr_tensor.cc

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ void lr_tensor::do_filledtableau(iterator& it)
8383
yngtab::LR_tensor(one,two,999,prod.get_back_insert_iterator());
8484

8585
Ex rep;
86-
iterator top=rep.set_head(str_node("\\oplus"));
86+
iterator top=rep.set_head(str_node("\\sum"));
8787

8888
if(singlet_rules) tabs_to_singlet_rules(prod, top);
8989
else tabs_to_tree(prod, top, tab1, even_only);
@@ -122,7 +122,7 @@ void lr_tensor::do_tableau(iterator& it)
122122
yngtab::LR_tensor(one,two,999,prod.get_back_insert_iterator());
123123

124124
Ex rep;
125-
iterator top=rep.set_head(str_node("\\oplus"));
125+
iterator top=rep.set_head(str_node("\\sum"));
126126
iterator tt;
127127
yngtab::tableaux<yngtab::tableau>::tableau_container_t::iterator tabit=prod.storage.begin();
128128
while(tabit!=prod.storage.end()) {

core/algorithms/sym.cc

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,11 @@ using namespace cadabra;
55

66
// #define DEBUG 1
77

8+
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)
10+
{
11+
}
12+
813
sym::sym(const Kernel& k, Ex& tr, Ex& objs, bool s)
914
: Algorithm(k, tr), objects(objs), sign(s)
1015
{
@@ -18,9 +23,21 @@ bool sym::can_apply(iterator it)
1823
if(!is_single_term(it))
1924
return false;
2025

21-
argloc_2_treeloc.clear();
2226
prod_wrap_single_term(it);
23-
bool located=locate_object_set(objects, tr.begin(it), tr.end(it), argloc_2_treeloc);
27+
bool located=false;
28+
if(objects.size()>0) {
29+
argloc_2_treeloc.clear();
30+
located=locate_object_set(objects, tr.begin(it), tr.end(it), argloc_2_treeloc);
31+
}
32+
else {
33+
objects.set_head(str_node("\\comma"));
34+
for(size_t i=0; i<argloc_2_treeloc.size(); ++i) {
35+
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));
39+
}
40+
}
2441
prod_unwrap_single_term(it);
2542
return located;
2643
}

core/algorithms/sym.hh

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ namespace cadabra {
99
class sym : virtual public Algorithm {
1010
public:
1111
sym(const Kernel&, Ex&, Ex&, bool sign);
12+
sym(const Kernel&, Ex&, const std::vector<unsigned int>&, bool sign);
1213

1314
virtual bool can_apply(iterator) override;
1415
virtual result_t apply(iterator& it) override;

core/properties/FilledTableau.hh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
#pragma once
22

33
#include "Props.hh"
4+
#include "properties/ImplicitIndex.hh"
45

56
namespace cadabra {
67

7-
class FilledTableau : public property {
8+
class FilledTableau : public ImplicitIndex, virtual public property {
89
public:
910
virtual ~FilledTableau() {};
1011
virtual std::string name() const override;

core/properties/Tableau.hh

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,11 @@
22
#pragma once
33

44
#include "Props.hh"
5+
#include "properties/ImplicitIndex.hh"
56

67
namespace cadabra {
78

8-
class Tableau : public property {
9+
class Tableau : public ImplicitIndex, virtual public property {
910
public:
1011
virtual ~Tableau() {};
1112
virtual std::string name() const override;

core/pythoncdb/py_algorithms.cc

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,8 @@ namespace cadabra {
121121
def_algo<rename_dummies, std::string, std::string>(m, "rename_dummies", true, false, 0, py::arg("set") = "", py::arg("to") = "");
122122
def_algo<sym, Ex, bool>(m, "sym", true, false, 0, py::arg("items"), py::arg("antisymmetric") = false);
123123
def_algo<sym, Ex, bool>(m, "asym", true, false, 0, py::arg("items"), py::arg("antisymmetric") = true);
124+
def_algo<sym, std::vector<unsigned int>, bool>(m, "slot_sym", true, false, 0, py::arg("items"), py::arg("antisymmetric") = false);
125+
def_algo<sym, std::vector<unsigned int>, bool>(m, "slot_asym", true, false, 0, py::arg("items"), py::arg("antisymmetric") = true);
124126
def_algo<factor_in, Ex>(m, "factor_in", true, false, 0, py::arg("factors"));
125127
def_algo<factor_out, Ex, bool>(m, "factor_out", true, false, 0, py::arg("factors"), py::arg("right") = false);
126128
def_algo<fierz, Ex>(m, "fierz", true, false, 0, py::arg("spinors"));

core/pythoncdb/py_kernel.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ namespace cadabra {
9191
k->inject_property(wi4, Ex_from_string("\\wedge{#}", false, k), wa4);
9292

9393
k->inject_property(new IndexInherit(), Ex_from_string("\\sum{#}", false, k), 0);
94+
k->inject_property(new TableauInherit(), Ex_from_string("\\sum{#}", false, k), 0);
9495
k->inject_property(new CommutingAsSum(), Ex_from_string("\\sum{#}", false, k), 0);
9596
k->inject_property(new DependsInherit(), Ex_from_string("\\sum{#}", false, k), 0);
9697
auto wi = new WeightInherit();

0 commit comments

Comments
 (0)