lean4-htt/tests/lean/run/mk_byte.lean
Leonardo de Moura 19ee270c60 refactor(library): remove vector and bitvec from init
Reason: vector in in init folder was introducing an overload (`::`) for
all Lean users. The workaround (use `local infix ::`) was
counterintuitive.

We currently have no special support for bitvectors in the code
generator. Thus, there is no need to have vector and bitvec in the init
folder right now. Moreover, the new parser and elaborator (issue #1674) should
provide better ways of managing overloaded symbols.
2017-08-16 13:40:50 -07:00

41 lines
1.3 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 [to_list'_drop],
simp [to_list'_cons]
end
end Ex