From 0c8eb9cdba9cc54415fc4f808f71f1e3e2323e85 Mon Sep 17 00:00:00 2001
From: Jeroen Demeyer <jdemeyer@cage.ugent.be>
Date: Mon, 26 Feb 2018 14:43:08 +0100
Subject: [PATCH] Add Sage interface

---
 sage.cpp | 55 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 sage.h   | 22 ++++++++++++++++++++++
 2 files changed, 77 insertions(+)
 create mode 100644 sage.cpp
 create mode 100644 sage.h

diff --git a/sage.cpp b/sage.cpp
new file mode 100644
index 0000000..503654d
--- /dev/null
+++ b/sage.cpp
@@ -0,0 +1,55 @@
+/*
+  Coxeter version 3.0 Copyright (C) 2009 Mike Hansen
+*/
+
+#include "sage.h"
+
+namespace sage {
+
+  void interval(List<CoxWord>& list, CoxGroup& W, const CoxWord& g, const CoxWord& h)
+
+  /*
+     Return a list of the elements in the Bruhat interval between g and h.
+     Note that this assumes that g and h are in order.
+   */
+  {
+    if (not W.inOrder(g,h)) {
+      return;
+    }
+
+    W.extendContext(h);
+
+    CoxNbr x = W.contextNumber(g);
+    CoxNbr y = W.contextNumber(h);
+
+    BitMap b(W.contextSize());
+    W.extractClosure(b,y);
+
+    BitMap::ReverseIterator b_rend = b.rend();
+    List<CoxNbr> res(0);
+
+    for (BitMap::ReverseIterator i = b.rbegin(); i != b_rend; ++i)
+      if (not W.inOrder(x,*i)) {
+        BitMap bi(W.contextSize());
+        W.extractClosure(bi,*i);
+        CoxNbr z = *i; // andnot will invalidate iterator
+        b.andnot(bi);
+        b.setBit(z);   // otherwise the decrement will not be correct
+      } else
+        res.append(*i);
+
+    schubert::NFCompare nfc(W.schubert(),W.ordering());
+    Permutation a(res.size());
+    sortI(res,nfc,a);
+
+    list.setSize(0);
+    for (size_t j = 0; j < res.size(); ++j) {
+      CoxWord w(0);
+      W.schubert().append(w, res[a[j]]);
+      list.append(w);
+    }
+
+    return;
+  }
+
+}
diff --git a/sage.h b/sage.h
new file mode 100644
index 0000000..fed0a7a
--- /dev/null
+++ b/sage.h
@@ -0,0 +1,22 @@
+/*
+  Coxeter version 3.0 Copyright (C) 2009 Mike Hansen
+*/
+
+#ifndef SAGE_H /* guard against multiple inclusions */
+#define SAGE_H
+
+#include "globals.h"
+#include "coxgroup.h"
+#include "coxtypes.h"
+#include "schubert.h"
+#include "list.h"
+
+namespace sage {
+  using namespace coxeter;
+  using namespace coxtypes;
+  using namespace list;
+
+  void interval(List<CoxWord>& result, CoxGroup& W, const CoxWord& g, const CoxWord& h);
+}
+
+#endif