Package word-bits: Word to bit-list conversions

Information

nameword-bits
version1.100
descriptionWord to bit-list conversions
authorJoe Leslie-Hurd <joe@gilith.com>
licenseMIT
checksum0d5a72eab8491e05988b7a26cca08674566f4814
requiresbase
natural-bits
word-def
showData.Bool
Data.List
Data.Word
Data.Word.Bits
Number.Natural

Files

Defined Constants

Theorems

w. normal (fromWord w)

toWord [] = 0

toNatural (toWord []) = 0

w. toWord (fromWord w) = w

w. length (fromWord w) = width

w. Bits.width (toNatural w) width

q. compare q [] [] q

w. Bits.fromList (fromWord w) = toNatural w

l. toWord l = fromNatural (Bits.fromList l)

w. fromWord w = Bits.toVector (toNatural w) width

w. Bits.bound (toNatural w) width = toNatural w

n. toNatural (fromNatural n) = Bits.bound n width

l. normal l length l = width

w. not w = toWord (map (¬) (fromWord w))

l. normal l fromWord (toWord l) = l

w n. bit w n Bits.bit (toNatural w) n

l. toNatural (toWord l) < 2 length l

w1 w2. fromWord w1 = fromWord w2 w1 = w2

w1 w2. fromWord w1 = fromWord w2 w1 = w2

w n. shiftLeft w n = fromNatural (Bits.shiftLeft (toNatural w) n)

w n. shiftRight w n = fromNatural (Bits.shiftRight (toNatural w) n)

w1 w2. and w1 w2 = fromNatural (Bits.and (toNatural w1) (toNatural w2))

w1 w2. or w1 w2 = fromNatural (Bits.or (toNatural w1) (toNatural w2))

w1 w2. compare (fromWord w1) (fromWord w2) w1 < w2

w1 w2. compare (fromWord w1) (fromWord w2) w1 w2

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

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

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

k w. bit (not w) k k < width ¬bit w k

k w1 w2. bit (and w1 w2) k bit w1 k bit w2 k

k w1 w2. bit (or w1 w2) k bit w1 k bit w2 k

q w1 w2.
    compare q (fromWord w1) (fromWord w2) if q then w1 w2 else w1 < w2

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

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

q l1 l2.
    length l1 = length l2
    (compare q l1 l2
     Bits.compare q (Bits.fromList l1) (Bits.fromList l2))

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

h t.
    toWord (h :: t) =
    if h then 1 + shiftLeft (toWord t) 1 else shiftLeft (toWord t) 1

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

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

q h1 h2 t1 t2.
    compare q (h1 :: t1) (h2 :: t2)
    compare (¬h1 h2 ¬(h1 ¬h2) q) t1 t2

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))

External Type Operators

External Constants

Assumptions

¬

¬

length [] = 0

Bits.fromList [] = 0

t. t t

n. n n

p. p

t. t ¬t

x. toNatural x < modulus

(¬) = λp. p

() = λp. p ((select) p)

t. (x. t) t

() = λp. p = λx.

x. replicate x 0 = []

t. ¬¬t t

t. t

t. t t

t. t

t. t t

t. t t

x. fromNatural (toNatural x) = x

n. ¬(suc n = 0)

n. 0 + n = n

n. n - n = 0

k. Bits.bound 0 k = 0

l. l @ [] = l

modulus = 2 width

t. ( t) ¬t

t. t ¬t

x. 0 + x = x

k. Bits.fromList (replicate k) = 0

l. take (length l) l = l

l. Bits.width (Bits.fromList l) length l

m n. m m + n

n k. Bits.bound n k n

() = λp q. p q p

t. (t ) (t )

x. toNatural x mod modulus = toNatural x

n. toNatural (fromNatural n) = n mod modulus

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

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

x n. length (replicate x n) = n

h t. head (h :: t) = h

h t. tail (h :: t) = t

n k. length (Bits.toVector n k) = k

b. fromBool b = if b then 1 else 0

l. length l = 0 l = []

x y. x = y y = x

m n. min m n = min n m

m n. m < n m n

f l. length (map f l) = length l

l. Bits.fromList l < 2 length l

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

m n. ¬(m n) n < m

n k. Bits.fromList (Bits.toVector n k) = Bits.bound n k

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

n. Bits.shiftLeft n 1 = 2 * n

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

h t. Bits.fromList (h :: t) = Bits.cons h (Bits.fromList t)

x y. x < y toNatural x < toNatural y

x y. x y toNatural x toNatural y

x y. toNatural x = toNatural y x = y

m n. suc m = suc n m = n

n k. Bits.toVector (Bits.bound n k) k = Bits.toVector n k

m n. min m n = if m n then m else n

x1 y1. fromNatural (x1 * y1) = fromNatural x1 * fromNatural y1

x1 y1. fromNatural (x1 + y1) = fromNatural x1 + fromNatural y1

n k. Bits.bound n k = n Bits.width n k

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

q n. Bits.compare q 0 n q ¬(n = 0)

n k. Bits.bound n k = n mod 2 k

m n. m n n m m = n

n l. n length l length (take n l) = n

p. (x y. p x y) y x. p x y

h t. Bits.cons h t = fromBool h + 2 * t

n k. Bits.width n k n < 2 k

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

n j k. Bits.bound (Bits.bound n j) k = Bits.bound n (min j k)

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

m n p. m n n p m p

l i. Bits.bit (Bits.fromList l) i i < length l nth l i

l1 l2.
    Bits.fromList (l1 @ l2) =
    Bits.fromList l1 + Bits.shiftLeft (Bits.fromList l2) (length l1)

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

q m n. Bits.compare q m n if q then m n else m < n

m n i. Bits.bit (Bits.and m n) i Bits.bit m i Bits.bit n i

n i k. Bits.bit (Bits.bound n k) i i < k Bits.bit n i

m n i. Bits.bit (Bits.or m n) i Bits.bit m i Bits.bit n i

n j k.
    Bits.bound (Bits.shiftLeft n k) (j + k) =
    Bits.shiftLeft (Bits.bound n j) k

n j k.
    Bits.shiftRight (Bits.bound n (j + k)) k =
    Bits.bound (Bits.shiftRight n k) j

b f x y. f (if b then x else y) = if b then f x else f y

l k.
    Bits.shiftRight (Bits.fromList l) k =
    if length l k then 0 else Bits.fromList (drop k l)

m n k.
    Bits.toVector (Bits.and m n) k =
    zipWith () (Bits.toVector m k) (Bits.toVector n k)

m n k.
    Bits.toVector (Bits.or m n) k =
    zipWith () (Bits.toVector m k) (Bits.toVector n k)

p. p [] (h t. p t p (h :: t)) l. p l

f l i. i < length l nth (map f l) i = f (nth l i)

p c x y. p (if c then x else y) (c p x) (¬c p y)

b f. fn. fn [] = b h t. fn (h :: t) = f h t (fn t)

l k.
    Bits.toVector (Bits.fromList l) k =
    if length l k then l @ replicate (k - length l) else take k l

l1 l2.
    length l1 = length l2 (i. i < length l1 nth l1 i = nth l2 i)
    l1 = l2

q h1 h2 t1 t2.
    Bits.compare q (Bits.cons h1 t1) (Bits.cons h2 t2)
    Bits.compare (¬h1 h2 ¬(h1 ¬h2) q) t1 t2