Analytical derivaties for nominal model, probably should be moved to cpp for better speed