Package word16-bytes: 16-bit word to byte pair conversions

Information

nameword16-bytes
version1.77
description16-bit word to byte pair conversions
authorJoe Leslie-Hurd <joe@gilith.com>
licenseMIT
requiresbool
byte
list
natural
pair
word16-bits
word16-def
showData.Bool
Data.Byte
Data.Byte.Bits
Data.List
Data.Pair
Data.Word16
Data.Word16.Bits
Number.Natural

Files

Defined Constants

Theorems

b. fromNatural (toNatural b) = toWord (fromByte b)

w. fromNatural (toNatural w) = toByte (fromWord w)

w. b0 b1. w = fromBytes b0 b1

b0 b1. toWord (fromByte b0 @ fromByte b1) = fromBytes b0 b1

w. b0 b1. w = fromBytes b0 b1 toBytes w = (b0, b1)

w.
    toBytes w =
    (fromNatural (toNatural w), fromNatural (toNatural (shiftRight w 8)))

b0 b1.
    fromBytes b0 b1 =
    or (fromNatural (toNatural b0))
      (shiftLeft (fromNatural (toNatural b1)) 8)

w.
    (toByte (take 8 (fromWord w)), toByte (drop 8 (fromWord w))) =
    toBytes w

Input Type Operators

Input Constants

Assumptions

¬odd 0

¬

¬

length [] = 0

bit0 0 = 0

x. x = x

n. 0 n

p. p

t. t ¬t

(¬) = λp. p

t. (x. t) t

t. (λx. t x) = t

() = λp. p = λx.

x. replicate x 0 = []

t. ¬¬t t

t. ( t) t

t. (t ) t

t. t

t. t t

t. t

t. t t

t. t t t

t. t

t. t t

t. t

t. t t

t. t

t. t t

t. t

w. toByte (fromByte w) = w

w. length (fromByte w) = width

w. toWord (fromWord w) = w

w. length (fromWord w) = width

n. ¬(suc n = 0)

n. 0 + n = n

m. m + 0 = m

l. [] @ l = l

l. drop 0 l = l

l. take 0 l = []

modulus = 2 width

width = 8

modulus = 2 width

t. ( t) ¬t

t. (t ) ¬t

t. t ¬t

n. bit1 n = suc (bit0 n)

m. m 0 = 1

n. n mod 1 = 0

f. zipWith f [] [] = []

width = 16

() = λp q. p q p

t. (t ) (t )

n. even (suc n) ¬even n

m. m 0 m = 0

n. toNatural (fromNatural n) = n mod modulus

n. toNatural (fromNatural n) = n mod modulus

xy. (fst xy, snd xy) = xy

t1 t2. (if then t1 else t2) = t2

t1 t2. (if then t1 else t2) = t1

x y. fst (x, y) = x

x y. snd (x, y) = y

n. bit0 (suc n) = suc (suc (bit0 n))

x y. x = y y = x

t1 t2. t1 t2 t2 t1

m n. m + n = n + m

m n. m n n m

m n. m + n - m = n

m n. m + n - n = m

n. 2 * n = n + n

h t. length (h :: t) = suc (length t)

m n. ¬(m < n n m)

m n. ¬(m n n < m)

m n. ¬(m < n) n m

m n. ¬(m n) n < m

m n. suc m n m < n

m. m = 0 n. m = suc n

() = λp q. (λf. f p q) = λf. f

p. ¬(x. p x) x. ¬p x

() = λp. q. (x. p x q) q

w1 w2. fromByte w1 = fromByte w2 w1 = w2

w1 w2. fromWord w1 = fromWord w2 w1 = w2

m n. m < n m div n = 0

m n. m + suc n = suc (m + n)

m n. suc m + n = suc (m + n)

m n. suc m = suc n m = n

n. odd n n mod 2 = 1

x n. replicate x (suc n) = x :: replicate x n

m n. even (m * n) even m even n

m n. even (m + n) even m even n

m n. m suc n = m * m n

m n. ¬(n = 0) m mod n < n

m n. m n d. n = m + d

() = λp q. r. (p r) (q r) r

w1 w2. or w1 w2 = toWord (zipWith () (fromWord w1) (fromWord w2))

m n. m n m < n m = n

m n. n m n + (m - n) = m

m n. m n n m m = n

l n. shiftLeft (toWord l) n = toWord (replicate n @ l)

p q. p (x. q x) x. p q x

x y z. x = y y = z x = z

t1 t2 t3. (t1 t2) t3 t1 t2 t3

t1 t2 t3. (t1 t2) t3 t1 t2 t3

m n p. m + (n + p) = m + n + p

m n p. m < n n p m < p

l h t. (h :: t) @ l = h :: t @ l

w n. bit w n odd (toNatural w div 2 n)

w n. bit w n odd (toNatural w div 2 n)

m n. m suc n m = suc n m n

m n. m * n = 0 m = 0 n = 0

p. p 0 (n. p n p (suc n)) n. p n

m n. m n = 0 m = 0 ¬(n = 0)

m n p. m (n + p) = m n * m p

p q. (x. p x q x) (x. p x) x. q x

p q. (x. p x) (x. q x) x. p x q x

m n. ¬(n = 0) (m div n) * n + m mod n = m

w1 w2. (i. i < width (bit w1 i bit w2 i)) w1 = w2

w1 w2. (i. i < width (bit w1 i bit w2 i)) w1 = w2

n h t. n length t drop (suc n) (h :: t) = drop n t

m n p. m * n = m * p m = 0 n = p

m n p. m * n m * p m = 0 n p

l n. bit (toByte l) n n < width n < length l nth l n

l n. bit (toWord l) n n < width n < length l nth l n

m n p. m * n < m * p ¬(m = 0) n < p

h1 h2 t1 t2. h1 :: t1 = h2 :: t2 h1 = h2 t1 = t2

x y a b. (x, y) = (a, b) x = a y = b

n h t. n length t take (suc n) (h :: t) = h :: take n t

l.
    fromByte (toByte l) =
    if length l width then l @ replicate (width - length l)
    else take width l

l.
    fromWord (toWord l) =
    if length l width then l @ replicate (width - length l)
    else take width l

m n p. ¬(n * p = 0) m mod n * p mod n = m mod n

m n p. ¬(n * p = 0) m div n mod p = m mod n * p div n

f h1 h2 t1 t2.
    length t1 = length t2
    zipWith f (h1 :: t1) (h2 :: t2) = f h1 h2 :: zipWith f t1 t2

x m n. x m x n if x = 0 then m = 0 n = 0 else x = 1 m n

b.
    x0 x1 x2 x3 x4 x5 x6 x7.
      b = toByte (x0 :: x1 :: x2 :: x3 :: x4 :: x5 :: x6 :: x7 :: [])

l n.
    shiftRight (toWord l) n =
    if length l width then
      if length l n then toWord [] else toWord (drop n l)
    else if width n then toWord []
    else toWord (drop n (take width l))

w.
    x0 x1 x2 x3 x4 x5 x6 x7 x8 x9 x10 x11 x12 x13 x14 x15.
      w =
      toWord
        (x0 :: x1 :: x2 :: x3 :: x4 :: x5 :: x6 :: x7 :: x8 :: x9 :: x10 ::
         x11 :: x12 :: x13 :: x14 :: x15 :: [])