File tree Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Expand file tree Collapse file tree 1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change @@ -1312,6 +1312,34 @@ theorem umod_eq {x y : BitVec n} :
1312
1312
theorem toNat_umod {x y : BitVec n} :
1313
1313
(x.umod y).toNat = x.toNat % y.toNat := rfl
1314
1314
1315
+ /-! ### sdiv -/
1316
+
1317
+ /-- Equation theorem for `sdiv` in terms of `udiv` -/
1318
+ theorem sdiv_eq (x y : BitVec w) : x.sdiv y =
1319
+ match x.msb, y.msb with
1320
+ | false , false => udiv x y
1321
+ | false , true => - (x.udiv (- y))
1322
+ | true , false => - ((- x).udiv y)
1323
+ | true , true => (- x).udiv (- y) := by
1324
+ rw [BitVec.sdiv]
1325
+ rcases x.msb <;> rcases y.msb <;> simp [BitVec.sdiv]
1326
+
1327
+ /-! ### smod -/
1328
+
1329
+ /-- Equation theorem for `smod` in terms of `umod` -/
1330
+ theorem smod_eq (x y : BitVec w) : x.smod y =
1331
+ match x.msb, y.msb with
1332
+ | false , false => x.umod y
1333
+ | false , true =>
1334
+ let u := x.umod (- y)
1335
+ (if u = 0 #w then u else u + y)
1336
+ | true , false =>
1337
+ let u := umod (.neg x) y
1338
+ (if u = 0 #w then u else y - u)
1339
+ | true , true => - ((- x).umod (- y)) := by
1340
+ simp [BitVec.smod]
1341
+ rcases x.msb <;> rcases y.msb <;> simp
1342
+
1315
1343
/-! ### signExtend -/
1316
1344
1317
1345
/-- Equation theorem for `Int.sub` when both arguments are `Int.ofNat` -/
You can’t perform that action at this time.
0 commit comments