forward function

Forward algorithm with homogeneous transition probability matrix