modularized internal numerics using C for probbility and linalg.