 : infimum ( seq -- n ) dup first [ min ] reduce ;
 : supremum ( seq -- n ) dup first [ max ] reduce ;
 
+: flip ( matrix -- newmatrix )
+    dup empty? [
+        dup [ length ] map infimum
+        [ <column> dup like ] curry* map
+    ] unless ;
+
 : sequence-hashcode ( n seq -- x )
     0 -rot [
         hashcode* >fixnum swap 31 fixnum*fast fixnum+fast

C: <column> column

M: column virtual-seq column-seq ;
M: column virtual@ dup column-col -rot column-seq nth ;
M: column length column-seq length ;

INSTANCE: column virtual-sequence


: all-eq? ( seq -- ? ) [ eq? ] monotonic? ;

: exchange ( m n seq -- )
    pick over bounds-check 2drop 2dup bounds-check 2drop
    exchange-unsafe ;
