         ipairs (map vector indices (rest indices))
         spins (fn [D] (for [[i j] ipairs] (or (v ds i j D) 0)))
         step (fn step [xs emap n]
-               (if-let [[Di i D] (first xs)]
+               (if-let [[i D] (first xs)]
                  (if (nil? D)
                    (recur (rest xs) emap n)
-                   (let [[Ei E] (sort [(emap Di) (or (emap D) n)])
+                   (let [Di (s ds i D)
+                         [Ei E] (sort [(emap Di) (or (emap D) n)])
                          head (if (= i :root) [-1 E] [(imap i) Ei E])
                          xs (rest xs)]
                      (if (not= E n)

        :else (recur (walk ds E j i))))))

(defn orbit-loopless? [ds indices D]
  (empty? (for [[D i] (traversal ds indices [D])
                :when (and (not= i :root) (or (nil? D) (= D (s ds i D))))]
            D)))

(defn curvature


(defn orbit-reps
  ([ds indices seeds]
    (for [[i D] (traversal ds indices seeds) :when (= :root i)] D))
  ([ds indices]
    (orbit-reps ds indices (elements ds))))

(defn orbit-elements [ds indices seed]
  (distinct (for [[i D] (traversal ds indices [seed])] D)))

(defn connected? [ds]
  (> 2 (count (orbit-reps ds (indices ds)))))

(defn partial-orientation [ds]
  (loop [ori {}
         [[i D] & xs] (traversal ds (indices ds) (elements ds))]
    (cond (nil? i) ori
          (or (nil? D) (ori D)) (recur ori xs)
          :else (recur (assoc ori D
                              (if (= :root i) 1 (- (ori (s ds i D))))) xs))))

(defn loopless? [ds]
  (every? (fn [[i D]] (not= D (s ds i D)))
