added code for semi-ring