Fix a serious bug in the expand_rules function.

While doing a code review with Bryan, noticed that an accumulator was
being discarded, which seemed very wrong... Rewrite the code to thread
the accumulator through.

Also add some comments on what internal helper functions are doing.
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.
Whitespace
fix typo
Merge pull request #274 from frenetic-lang/expand_rules_bugfix

Fix a serious bug in the expand_rules function.