style(library/data/bv): Use syntax for dite

This commit is contained in:
Joe Hendrix 2015-12-01 09:20:32 -08:00 committed by Leonardo de Moura
parent 3574ad1f11
commit 719a78d541

View file

@ -38,36 +38,36 @@ section shift
-- shift left -- shift left
definition bv_shl {n:} : bv n → → bv n definition bv_shl {n:} : bv n → → bv n
| x i := | x i :=
dite (i ≤ n) if le : i ≤ n then
(λle, let r := dropn i x ++ replicate ff in
let r := dropn i x ++ replicate ff in let eq := calc (n-i) + i = n : nat.sub_add_cancel le in
let eq := calc (n-i) + i = n : nat.sub_add_cancel le in bv_cong eq r
bv_cong eq r) else
(λp, bv_zero n) bv_zero n
-- unsigned shift right -- unsigned shift right
definition bv_ushr {n:} : bv n → → bv n definition bv_ushr {n:} : bv n → → bv n
| x i := | x i :=
dite (i ≤ n) if le : i ≤ n then
(λle, let y : bv (n-i) := @firstn _ _ (n - i) (sub_le n i) x in
let y : bv (n-i) := @firstn _ _ (n - i) (sub_le n i) x in let eq := calc (i+(n-i)) = (n - i) + i : add.comm
let eq := calc (i+(n-i)) = (n - i) + i : add.comm ... = n : nat.sub_add_cancel le in
... = n : nat.sub_add_cancel le in bv_cong eq (replicate ff ++ y)
bv_cong eq (replicate ff ++ y)) else
(λgt, bv_zero n) bv_zero n
-- signed shift right -- signed shift right
definition bv_sshr {m:} : bv (succ m) → → bv (succ m) definition bv_sshr {m:} : bv (succ m) → → bv (succ m)
| x i := | x i :=
let n := succ m in let n := succ m in
dite (i ≤ n) if le : i ≤ n then
(λle, let z : bv i := replicate (head x) in
let z : bv i := replicate (head x) in let y : bv (n-i) := @firstn _ _ (n - i) (sub_le n i) x in
let y : bv (n-i) := @firstn _ _ (n - i) (sub_le n i) x in let eq := calc (i+(n-i)) = (n-i) + i : add.comm
let eq := calc (i+(n-i)) = (n-i) + i : add.comm ... = n : nat.sub_add_cancel le in
... = n : nat.sub_add_cancel le in bv_cong eq (z ++ y)
bv_cong eq (z ++ y)) else
(λgt, bv_zero n) bv_zero n
end shift end shift
@ -137,8 +137,8 @@ section arith
definition bv_slt : bv (succ n) → bv (succ n) → bool := λx y, definition bv_slt : bv (succ n) → bv (succ n) → bool := λx y,
cond (head x) cond (head x)
(cond (head y) (cond (head y)
(bv_ult (tail x) (tail y)) -- both negative (bv_ult (tail x) (tail y)) -- both negative
tt) -- x is negative and y is not tt) -- x is negative and y is not
(cond (head y) (cond (head y)
ff -- y is negative and x is not ff -- y is negative and x is not
(bv_ult (tail x) (tail y))) -- both positive (bv_ult (tail x) (tail y))) -- both positive