Regression test for expand_rules bug, to_table refactoring

* Added regression test for expand_rules bug fixed yesterday

* Swapped order of list in PosNeg.expand so rules appear in ascending
  order (cosmetic; does not affect correctness)

* Refactored to_table to use simple maps/folds instead of more
  complicated recursive functions.