Package word16-bytes: Basic theory of 16-bit words as pairs of bytes

Information

nameword16-bytes
version1.2
description Basic theory of 16-bit words as pairs of bytes
authorJoe Hurd <joe@gilith.com>
licenseMIT
show Data.Bool
Data.List
Data.Word16
Number.Numeral

Files

Defined Constants

Theorems

b.
    fromNatural (Data.Byte.toNatural b) =
    Bits.toWord (Data.Byte.Bits.fromWord b)

w.
    Data.Byte.fromNatural (toNatural w) =
    Data.Byte.Bits.toWord (Bits.fromWord w)

w. b0 b1. w = fromBytes b0 b1

b0 b1.
    Bits.toWord (Data.Byte.Bits.fromWord b1 @ Data.Byte.Bits.fromWord b0) =
    fromBytes b0 b1

w. b0 b1. w = fromBytes b0 b1 toBytes w = Data.Pair., b0 b1

b1 b2.
    fromBytes b1 b2 =
    or (shiftLeft (fromNatural (Data.Byte.toNatural b1)) 8)
      (fromNatural (Data.Byte.toNatural b2))

w.
    Data.Pair., (Data.Byte.Bits.toWord (drop 8 (Bits.fromWord w)))
      (Data.Byte.Bits.toWord (take 8 (Bits.fromWord w))) = toBytes w

w.
    toBytes w =
    Data.Pair., (Data.Byte.fromNatural (toNatural (shiftRight w 8)))
      (Data.Byte.fromNatural (toNatural (and w (fromNatural 255))))

Input Type Operators

Input Constants

Assumptions

T

x. x = x

n. Number.Natural.≤ 0 n

n. Number.Natural.≤ n n

F p. p

x. Function.id x = x

t. t ¬t

(¬) = λp. p F

() = λP. P ((select) P)

a. x. x = a

t. (x. t) t

t. (x. t) t

t. (λx. t x) = t

() = λP. P = λx. T

x. x = x T

w. Data.Byte.Bits.toWord (Data.Byte.Bits.fromWord w) = w

w. length (Data.Byte.Bits.fromWord w) = Data.Byte.width

w. Bits.toWord (Bits.fromWord w) = w

w. length (Bits.fromWord w) = width

n. ¬(Number.Natural.suc n = 0)

n. Number.Natural.- n n = 0

Data.Byte.modulus = Number.Natural.exp 2 Data.Byte.width

Data.Byte.width = 8

modulus = Number.Natural.exp 2 width

n. bit0 n = Number.Natural.+ n n

n. Number.Natural.mod n 1 = 0

x. (select y. y = x) = x

m n. Number.Natural.≤ m (Number.Natural.+ m n)

m n. Number.Natural.≤ n (Number.Natural.+ m n)

width = 16

() = λp q. p q p

t. (t T) (t F)

m. Number.Natural.suc m = Number.Natural.+ m 1

n. bit1 n = Number.Natural.suc (Number.Natural.+ n n)

x.
    Data.Byte.toNatural (Data.Byte.fromNatural x) =
    Number.Natural.mod x Data.Byte.modulus

x. toNatural (fromNatural x) = Number.Natural.mod x modulus

x. Data.Pair., (Data.Pair.fst x) (Data.Pair.snd x) = x

x y. Data.Pair.fst (Data.Pair., x y) = x

x y. Data.Pair.snd (Data.Pair., x y) = y

(¬T F) (¬F T)

x y. x = y y = x

t1 t2. t1 t2 t2 t1

m n. m = n Number.Natural.≤ m n

m n. Number.Natural.< m n Number.Natural.≤ m n

m n. Number.Natural.< m n Number.Natural.≤ n m

m n. Number.Natural.≤ m n Number.Natural.≤ n m

m n. Number.Natural.- m (Number.Natural.+ m n) = 0

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

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

n. Number.Natural.* 2 n = Number.Natural.+ n n

m n. ¬(Number.Natural.< m n Number.Natural.≤ n m)

m n. ¬(Number.Natural.≤ m n Number.Natural.< n m)

m n. ¬Number.Natural.< m n Number.Natural.≤ n m

m n. ¬Number.Natural.≤ m n Number.Natural.< n m

m n. Number.Natural.< m (Number.Natural.suc n) Number.Natural.≤ m n

m n. Number.Natural.≤ (Number.Natural.suc m) n Number.Natural.< m n

m. m = 0 n. m = Number.Natural.suc n

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

P. ¬(x. P x) x. ¬P x

P. ¬(x. P x) x. ¬P x

() = λP. q. (x. P x q) q

w1 w2. Data.Byte.Bits.fromWord w1 = Data.Byte.Bits.fromWord w2 w1 = w2

w1 w2. Bits.fromWord w1 = Bits.fromWord w2 w1 = w2

m n. Number.Natural.< m n Number.Natural.div m n = 0

m n. Number.Natural.suc m = Number.Natural.suc n m = n

m n. Number.Natural.+ m n = m n = 0

m n. Number.Natural.- m n = 0 Number.Natural.≤ m n

n. Number.Natural.odd n Number.Natural.mod n 2 = 1

m n.
    Number.Natural.even (Number.Natural.* m n)
    Number.Natural.even m Number.Natural.even n

m n.
    Number.Natural.even (Number.Natural.+ m n) Number.Natural.even m
    Number.Natural.even n

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

P. (p. P p) p1 p2. P (Data.Pair., p1 p2)

m n. Number.Natural.≤ m n d. n = Number.Natural.+ m d

f g. f = g x. f x = g x

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

(Number.Natural.even 0 T)
  n. Number.Natural.even (Number.Natural.suc n) ¬Number.Natural.even n

(Number.Natural.odd 0 F)
  n. Number.Natural.odd (Number.Natural.suc n) ¬Number.Natural.odd n

w1 w2.
    and w1 w2 =
    Bits.toWord (zipWith () (Bits.fromWord w1) (Bits.fromWord w2))

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

m n. Number.Natural.≤ m n Number.Natural.< m n m = n

m n.
    Number.Natural.odd (Number.Natural.+ m n)
    ¬(Number.Natural.odd m Number.Natural.odd n)

m n. Number.Natural.≤ m n Number.Natural.≤ n m m = n

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

m n.
    Number.Natural.< m n
    d. n = Number.Natural.+ m (Number.Natural.suc d)

P Q. P (x. Q x) x. P Q x

P Q. P (x. Q x) x. P Q x

P Q. (x. P x Q) (x. P x) Q

P Q. (x. P x) Q x. P x Q

P Q. (x. P x) Q x. P x Q

P Q. (x. P x) Q x. P x Q

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

p q r. p q r p q r

m n p.
    Number.Natural.* m (Number.Natural.* n p) =
    Number.Natural.* (Number.Natural.* m n) p

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

m n p. Number.Natural.+ m n = Number.Natural.+ m p n = p

m n p.
    Number.Natural.≤ (Number.Natural.+ m n) (Number.Natural.+ m p)
    Number.Natural.≤ n p

m n p.
    Number.Natural.≤ (Number.Natural.+ m p) (Number.Natural.+ n p)
    Number.Natural.≤ m n

m n p.
    Number.Natural.- (Number.Natural.+ m n) (Number.Natural.+ m p) =
    Number.Natural.- n p

m n p.
    Number.Natural.< m n Number.Natural.≤ n p Number.Natural.< m p

m n p.
    Number.Natural.≤ m n Number.Natural.≤ n p Number.Natural.≤ m p

n.
    Bits.toWord
      (Number.Natural.odd n ::
       Bits.fromWord (fromNatural (Number.Natural.div n 2))) =
    fromNatural n

P. (x. y. P x y) y. x. P x (y x)

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

w n.
    Data.Byte.bit w n
    Number.Natural.odd
      (Number.Natural.div (Data.Byte.toNatural w) (Number.Natural.exp 2 n))

w n.
    bit w n
    Number.Natural.odd
      (Number.Natural.div (toNatural w) (Number.Natural.exp 2 n))

m n. Number.Natural.* m n = 0 m = 0 n = 0

m n. Number.Natural.+ m n = 0 m = 0 n = 0

length [] = 0 h t. length (h :: t) = Number.Natural.suc (length t)

P. P 0 (n. P n P (Number.Natural.suc n)) n. P n

(t. ¬¬t t) (¬T F) (¬F T)

m n. Number.Natural.exp m n = 0 m = 0 ¬(n = 0)

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

m n p.
    Number.Natural.* m (Number.Natural.- n p) =
    Number.Natural.- (Number.Natural.* m n) (Number.Natural.* m p)

m n p.
    Number.Natural.exp m (Number.Natural.+ n p) =
    Number.Natural.* (Number.Natural.exp m n) (Number.Natural.exp m p)

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

m n p.
    Number.Natural.* (Number.Natural.- m n) p =
    Number.Natural.- (Number.Natural.* m p) (Number.Natural.* n p)

P Q. (x. P x Q x) (x. P x) x. Q x

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

P Q. (x. P x) (x. Q x) x. P x Q x

e f. fn. fn 0 = e n. fn (Number.Natural.suc n) = f (fn n) n

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

w1 w2.
    (i.
       Number.Natural.< i Data.Byte.width
       (Data.Byte.bit w1 i Data.Byte.bit w2 i)) w1 = w2

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

m n p. Number.Natural.* m n = Number.Natural.* m p m = 0 n = p

m n p.
    Number.Natural.≤ (Number.Natural.* m n) (Number.Natural.* m p)
    m = 0 Number.Natural.≤ n p

l n.
    Data.Byte.bit (Data.Byte.Bits.toWord l) n
    Number.Natural.< n Data.Byte.width Number.Natural.< n (length l)
    nth n l

l n.
    bit (Bits.toWord l) n
    Number.Natural.< n width Number.Natural.< n (length l) nth n l

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

(x. replicate 0 x = [])
  n x. replicate (Number.Natural.suc n) x = x :: replicate n x

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

x y a b. Data.Pair., x y = Data.Pair., a b x = a y = b

m n p q.
    Number.Natural.< m p Number.Natural.< n q
    Number.Natural.< (Number.Natural.+ m n) (Number.Natural.+ p q)

m n p q.
    Number.Natural.≤ m p Number.Natural.≤ n q
    Number.Natural.≤ (Number.Natural.+ m n) (Number.Natural.+ p q)

l.
    Data.Byte.Bits.fromWord (Data.Byte.Bits.toWord l) =
    if Number.Natural.≤ (length l) Data.Byte.width then
      l @ replicate (Number.Natural.- Data.Byte.width (length l)) F
    else take Data.Byte.width l

l.
    Bits.fromWord (Bits.toWord l) =
    if Number.Natural.≤ (length l) width then
      l @ replicate (Number.Natural.- width (length l)) F
    else take width l

(m. Number.Natural.exp m 0 = 1)
  m n.
    Number.Natural.exp m (Number.Natural.suc n) =
    Number.Natural.* m (Number.Natural.exp m n)

(l. drop 0 l = l)
  n h t. drop (Number.Natural.suc n) (h :: t) = drop n t

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

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

t1 t2. (¬(t1 t2) ¬t1 ¬t2) (¬(t1 t2) ¬t1 ¬t2)

(l. take 0 l = [])
  n h t. take (Number.Natural.suc n) (h :: t) = h :: take n t

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

(m. Number.Natural.≤ m 0 m = 0)
  m n.
    Number.Natural.≤ m (Number.Natural.suc n)
    m = Number.Natural.suc n Number.Natural.≤ m n

t. ((T t) t) ((t T) t) ((F t) ¬t) ((t F) ¬t)

m n q r.
    m = Number.Natural.+ (Number.Natural.* q n) r Number.Natural.< r n
    Number.Natural.div m n = q Number.Natural.mod m n = r

Bits.toWord [] = fromNatural 0
  h t.
    Bits.toWord (h :: t) =
    if h then shiftLeft (Bits.toWord t) 1 + fromNatural 1
    else shiftLeft (Bits.toWord t) 1

t. (T t t) (t T t) (F t F) (t F F) (t t t)

t. (T t T) (t T T) (F t t) (t F t) (t t t)

t. (T t t) (t T T) (F t T) (t t T) (t F ¬t)

x m n.
    Number.Natural.≤ (Number.Natural.exp x m) (Number.Natural.exp x n)
    if x = 0 then m = 0 n = 0 else x = 1 Number.Natural.≤ m n

(f. zipWith f [] [] = [])
  f h1 h2 t1 t2.
    zipWith f (h1 :: t1) (h2 :: t2) = f h1 h2 :: zipWith f t1 t2

b.
    x0 x1 x2 x3 x4 x5 x6 x7.
      b =
      Data.Byte.Bits.toWord
        (x0 :: x1 :: x2 :: x3 :: x4 :: x5 :: x6 :: x7 :: [])

m n p.
    Number.Natural.* m n = Number.Natural.* n m
    Number.Natural.* (Number.Natural.* m n) p =
    Number.Natural.* m (Number.Natural.* n p)
    Number.Natural.* m (Number.Natural.* n p) =
    Number.Natural.* n (Number.Natural.* m p)

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

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

(n. Number.Natural.+ 0 n = n) (m. Number.Natural.+ m 0 = m)
  (m n.
     Number.Natural.+ (Number.Natural.suc m) n =
     Number.Natural.suc (Number.Natural.+ m n))
  m n.
    Number.Natural.+ m (Number.Natural.suc n) =
    Number.Natural.suc (Number.Natural.+ m n)

p q r.
    (p q q p) ((p q) r p q r) (p q r q p r)
    (p p p) (p p q p q)

(n. Number.Natural.* 0 n = 0) (m. Number.Natural.* m 0 = 0)
  (n. Number.Natural.* 1 n = n) (m. Number.Natural.* m 1 = m)
  (m n.
     Number.Natural.* (Number.Natural.suc m) n =
     Number.Natural.+ (Number.Natural.* m n) n)
  m n.
    Number.Natural.* m (Number.Natural.suc n) =
    Number.Natural.+ m (Number.Natural.* m n)

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