rewrite Formula

* More robust, works under py2/3
* Faster because weights are calculated lazily (they are a @property)