3
(include-book "cat-def")
4
(local (include-book "setbitn-proofs"))
7
(declare (xargs :guard t))
12
(declare (xargs :guard (integerp k)))
18
(declare (xargs :guard (and (natp x)
21
(mbe :logic (bits x n n)
22
:exec (if (evenp (ash x (- n))) 0 1)))
24
(defund setbits (x w i j y)
25
(declare (xargs :guard (and (natp x)
34
(mbe :logic (cat (bits x (1- w) (1+ i))
36
(cat (bits y (+ i (- j)) 0)
41
:exec (cond ((int= j 0)
42
(cond ((int= (1+ i) w)
43
(bits y (+ i (- j)) 0))
45
(cat (bits x (1- w) (1+ i))
47
(bits y (+ i (- j)) 0)
50
(cat (bits y (+ i (- j)) 0)
55
(cat (bits x (1- w) (1+ i))
57
(cat (bits y (+ i (- j)) 0)
63
(defund setbitn (x w n y)
64
(declare (xargs :guard (and (natp x)
73
(defthm setbitn-nonnegative-integer-type
74
(and (integerp (setbitn x w n y))
75
(<= 0 (setbitn x w n y)))
76
:rule-classes (:type-prescription))
78
;this rule is no better than setbits-nonnegative-integer-type and might be worse:
79
(in-theory (disable (:type-prescription setbitn)))
82
(natp (setbitn x w n y)))
84
;add setbitn-bvecp-simple?
87
(implies (and (<= w k)
88
(case-split (integerp k)))
89
(bvecp (setbitn x w n y) k)))
91
(defthm setbitn-rewrite
92
(implies (syntaxp (quotep n))
93
(equal (setbitn x w n y)
94
(setbits x w n n y))))
98
(implies (and (case-split (bvecp y 1))
102
(case-split (<= 0 k))
103
(case-split (integerp w))
104
(case-split (integerp n))
106
(case-split (integerp k))
108
(equal (bitn (setbitn x w n y) k)
113
(defthm setbitn-setbitn
114
(implies (and (case-split (<= 0 n))
116
(case-split (integerp w))
117
(case-split (integerp n))
119
(equal (setbitn (setbitn x w n y) w n y2)
120
(setbitn x w n y2))))
122
(defthm setbitn-does-nothing
123
(implies (and (case-split (<= 0 n))
125
(case-split (integerp w))
126
(case-split (integerp n))
128
(equal (setbitn x w n (bitn x n))