lean4-htt/old_tests/tests/lean/run/mk_byte.lean
2018-04-10 12:56:55 -07:00

40 lines
1.2 KiB
Text
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import data.vector namespace Ex
universe u
-- def vector (α : Type u) (n : ) := { l : list α // l.length = n }
namespace vector
variables {α : Type u} {n : }
@[pattern] def cons : α → vector α n → vector α (nat.succ n)
| a ⟨ v, h ⟩ := ⟨ a::v, congr_arg nat.succ h ⟩
def to_list' (v : vector α n) : list α := v.1
def drop (i : ) : vector α n → vector α (n - i)
| ⟨l, p⟩ := ⟨ list.drop i l, by simp * ⟩
protected axiom eq {n : } : ∀ (a1 a2 : vector α n), to_list' a1 = to_list' a2 → a1 = a2
@[simp] axiom to_list'_cons (a : α) (v : vector α n) : to_list' (cons a v) = list.cons a (to_list' v)
@[simp] axiom to_list'_drop {n m : } (v : vector α m) : to_list' (drop n v) = list.drop n (to_list' v)
end vector
open Ex.vector
@[reducible] def bitvec (n : ) := vector bool n
def byte_type := bitvec 8
-- A byte is formed from concatenating two bits and a 6-bit field.
def mk_byte (a b : bool) (l : bitvec 6) : byte_type := cons a (cons b l)
-- Get the third component
def get_data (byte : byte_type) : bitvec 6 := vector.drop 2 byte
lemma get_data_mk_byte {a b : bool} {l : bitvec 6} : get_data (mk_byte a b l) = l :=
begin
apply vector.eq,
unfold mk_byte,
unfold get_data,
simp
end
end Ex