Generalized factor dealing from Double to Semiring.

close #6