Digital representation of semigroups and groups