WIP: co-de bruijn #12
1 changed files with 8 additions and 8 deletions
|
@ -101,7 +101,7 @@ floorHalf k = case half k of
|
|||
|||
|
||||
||| take all the bits of `subj` that are set in `mask`, and squish them down
|
||||
||| towards the lsb
|
||||
export
|
||||
public export
|
||||
select : (mask, subj : Nat) -> Nat
|
||||
select mask subj = go 1 (halfRec mask) subj 0 where
|
||||
go : forall mask. Nat -> HalfRec mask -> Nat -> Nat -> Nat
|
||||
|
@ -115,7 +115,7 @@ select mask subj = go 1 (halfRec mask) subj 0 where
|
|||
||| and place them where mask's set bits are
|
||||
|||
|
||||
||| left inverse of select if mask .|. subj = mask
|
||||
export
|
||||
public export
|
||||
spread : (mask, subj : Nat) -> Nat
|
||||
spread mask subj = go 1 (halfRec mask) subj 0 where
|
||||
go : forall mask. Nat -> HalfRec mask -> Nat -> Nat -> Nat
|
||||
|
@ -153,7 +153,7 @@ bitwiseRec m n = go (halfRec m) (halfRec n) where
|
|||
go (HalfRecOdd m mr) (HalfRecEven n nr) = Bw10 m n $ go mr nr
|
||||
go (HalfRecOdd m mr) (HalfRecOdd n nr) = Bw11 m n $ go mr nr
|
||||
|
||||
export
|
||||
public export
|
||||
bitwise : (Bool -> Bool -> Bool) -> Nat -> Nat -> Nat
|
||||
bitwise f m n = go 1 (bitwiseRec m n) 0 where
|
||||
one : Bool -> Bool -> Nat -> Nat -> Nat
|
||||
|
@ -165,7 +165,7 @@ bitwise f m n = go 1 (bitwiseRec m n) 0 where
|
|||
go bit (Bw10 m n rec) res = go (bit + bit) rec $ one True False bit res
|
||||
go bit (Bw11 m n rec) res = go (bit + bit) rec $ one True True bit res
|
||||
|
||||
export
|
||||
public export
|
||||
(.&.) : Nat -> Nat -> Nat
|
||||
(.&.) = bitwise $ \p, q => p && q
|
||||
|
||||
|
@ -173,7 +173,7 @@ private %foreign "scheme:blodwen-and"
|
|||
primAnd : Nat -> Nat -> Nat
|
||||
%transform "NatExtra.(.&.)" NatExtra.(.&.) m n = primAnd m n
|
||||
|
||||
export
|
||||
public export
|
||||
(.|.) : Nat -> Nat -> Nat
|
||||
(.|.) = bitwise $ \p, q => p || q
|
||||
|
||||
|
@ -181,7 +181,7 @@ private %foreign "scheme:blodwen-or"
|
|||
primOr : Nat -> Nat -> Nat
|
||||
%transform "NatExtra.(.|.)" NatExtra.(.|.) m n = primOr m n
|
||||
|
||||
export
|
||||
public export
|
||||
xor : Nat -> Nat -> Nat
|
||||
xor = bitwise (/=)
|
||||
|
||||
|
@ -190,7 +190,7 @@ primXor : Nat -> Nat -> Nat
|
|||
%transform "NatExtra.xor" NatExtra.xor m n = primXor m n
|
||||
|
||||
|
||||
export
|
||||
public export
|
||||
shiftL : Nat -> Nat -> Nat
|
||||
shiftL n 0 = n
|
||||
shiftL n (S i) = shiftL (n + n) i
|
||||
|
@ -199,7 +199,7 @@ private %foreign "scheme:blodwen-shl"
|
|||
primShiftL : Nat -> Nat -> Nat
|
||||
%transform "NatExtra.shiftL" NatExtra.shiftL n i = primShiftL n i
|
||||
|
||||
export
|
||||
public export
|
||||
shiftR : Nat -> Nat -> Nat
|
||||
shiftR n 0 = n
|
||||
shiftR n (S i) = shiftL (floorHalf n) i
|
||||
|
|
Loading…
Reference in a new issue