Modulo of unsigned integer values.
This has the usual relation with division [SD: Types: Integers: Modulo], so we use rem here.
Function:
(defun uint-mod (left-operand right-operand) (declare (xargs :guard (and (uintp left-operand) (uintp right-operand)))) (declare (xargs :guard (not (equal (uint->value right-operand) 0)))) (b* ((size (uint->size left-operand)) (x (uint->value left-operand)) (y (uint->value right-operand))) (make-uint :size (uint->size left-operand) :value (loghead size (rem x y)))))
Theorem:
(defthm uintp-of-uint-mod (b* ((result (uint-mod left-operand right-operand))) (uintp result)) :rule-classes :rewrite)
Theorem:
(defthm uint-mod-of-uint-fix-left-operand (equal (uint-mod (uint-fix left-operand) right-operand) (uint-mod left-operand right-operand)))
Theorem:
(defthm uint-mod-uint-equiv-congruence-on-left-operand (implies (uint-equiv left-operand left-operand-equiv) (equal (uint-mod left-operand right-operand) (uint-mod left-operand-equiv right-operand))) :rule-classes :congruence)
Theorem:
(defthm uint-mod-of-uint-fix-right-operand (equal (uint-mod left-operand (uint-fix right-operand)) (uint-mod left-operand right-operand)))
Theorem:
(defthm uint-mod-uint-equiv-congruence-on-right-operand (implies (uint-equiv right-operand right-operand-equiv) (equal (uint-mod left-operand right-operand) (uint-mod left-operand right-operand-equiv))) :rule-classes :congruence)