val assoc_flip_intro (#a #b: eqtype) (l: list (a * b)) (y: b) (x: a)
    : Lemma
      (requires
        (L.noRepeats (list_map fst l) /\ L.noRepeats (list_map snd l) /\ L.assoc x l == Some y))
      (ensures (L.assoc y (list_map flip l) == Some x))
let rec assoc_flip_intro
  (#a #b: eqtype)
  (l: list (a * b))
  (y: b)
  (x: a)
: Lemma
  (requires (
    L.noRepeats (list_map fst l) /\
    L.noRepeats (list_map snd l) /\
    L.assoc x l == Some y
  ))
  (ensures (
    L.assoc y (list_map flip l) == Some x
  ))
= map_fst_flip l;
  map_snd_flip l;
  map_flip_flip l;
  assoc_flip_elim (list_map flip l) x y
val assoc_flip_intro (#a #b: eqtype) (l: list (a * b)) (y: b) (x: a)
    : Lemma
      (requires
        (L.noRepeats (list_map fst l) /\ L.noRepeats (list_map snd l) /\ L.assoc x l == Some y))
      (ensures (L.assoc y (list_map flip l) == Some x))
let rec assoc_flip_intro (#a #b: eqtype) (l: list (a * b)) (y: b) (x: a)
    : Lemma
      (requires
        (L.noRepeats (list_map fst l) /\ L.noRepeats (list_map snd l) /\ L.assoc x l == Some y))
      (ensures (L.assoc y (list_map flip l) == Some x)) =
map_fst_flip l;
map_snd_flip l;
map_flip_flip l;
assoc_flip_elim (list_map flip l) x y
LowParse.Spec.Enum.fst.checked
prims.fst.checked LowParse.Spec.Combinators.fsti.checked FStar.Pervasives.Native.fst.checked FStar.Pervasives.fsti.checked FStar.List.Tot.fst.checked FStar.Classical.fsti.checked
LowParse.Spec.Enum.fst
Prims.eqtype Prims.list FStar.Pervasives.Native.tuple2 LowParse.Spec.Enum.assoc_flip_elim LowParse.Spec.Enum.list_map LowParse.Spec.Enum.flip Prims.unit LowParse.Spec.Enum.map_flip_flip LowParse.Spec.Enum.map_snd_flip LowParse.Spec.Enum.map_fst_flip Prims.l_and Prims.b2t FStar.List.Tot.Base.noRepeats FStar.Pervasives.Native.fst FStar.Pervasives.Native.snd Prims.eq2 FStar.Pervasives.Native.option FStar.List.Tot.Base.assoc FStar.Pervasives.Native.Some Prims.squash Prims.Nil FStar.Pervasives.pattern
module LowParse.Spec.Enum
include LowParse.Spec.Combinators

module L = FStar.List.Tot

[@Norm]
let rec list_map
  (#a #b: Type)
  (f: (a -> Tot b))
  (l: list a)
: Tot (l' : list b { l' == L.map f l } )
= match l with
  | [] -> []
  | a :: q -> f a :: list_map f q

type enum (key: eqtype) (repr: eqtype) = (l: list (key * repr) {
  L.noRepeats (list_map fst l) /\
  L.noRepeats (list_map snd l)
})

[@Norm]
let rec list_mem
  (#t: eqtype)
  (x: t)
  (l: list t)
: Tot (y: bool { y == true <==> L.mem x l == true } )
= match l with
  | [] -> false
  | a :: q -> (x = a || list_mem x q)

inline_for_extraction
let enum_key (#key #repr: eqtype) (e: enum key repr) : Tot eqtype = (s: key { list_mem s (list_map fst e) } )

inline_for_extraction
let make_enum_key (#key #repr: eqtype) (e: enum key repr) (k: key) : Pure (enum_key e)
  (requires (list_mem k (list_map fst e)))
  (ensures (fun k' -> k == (k' <: key)))
= k

inline_for_extraction
let enum_repr (#key #repr: eqtype) (e: enum key repr) : Tot eqtype = (r: repr { list_mem r (list_map snd e) } )

let flip (#a #b: Type) (c: (a * b)) : Tot (b * a) = let (ca, cb) = c in (cb, ca)

let rec map_flip_flip (#a #b: Type) (l: list (a * b)) : Lemma
  (list_map flip (list_map flip l) == l)
= match l with
  | [] -> ()
  | _ :: q -> map_flip_flip q

let rec map_fst_flip (#a #b: Type) (l: list (a * b)) : Lemma
  (list_map fst (list_map flip l) == list_map snd l)
= match l with
  | [] -> ()
  | _ :: q -> map_fst_flip q

let rec map_snd_flip (#a #b: Type) (l: list (a * b)) : Lemma
  (list_map snd (list_map flip l) == list_map fst l)
= match l with
  | [] -> ()
  | _ :: q -> map_snd_flip q

let rec assoc_mem_snd
  (#a #b: eqtype)
  (l: list (a * b))
  (x: a)
  (y: b)
: Lemma
  (requires (L.assoc x l == Some y))
  (ensures (list_mem y (list_map snd l) == true))
  (decreases l)
= let ((x', y') :: l') = l in
  if x' = x
  then ()
  else assoc_mem_snd l' x y

let rec assoc_flip_elim
  (#a #b: eqtype)
  (l: list (a * b))
  (y: b)
  (x: a)
: Lemma
  (requires (
    L.noRepeats (list_map fst l) /\
    L.noRepeats (list_map snd l) /\
    L.assoc y (list_map flip l) == Some x
  ))
  (ensures (
    L.assoc x l == Some y
  ))
  (decreases l)
= let ((x', y') :: l') = l in
  if y' = y
  then ()
  else begin
    if x' = x
    then begin
      assert (list_mem x' (list_map fst l') == false);
      assoc_mem_snd (list_map flip l') y x;
      map_snd_flip l';
      assert False
    end
    else
      assoc_flip_elim l' y x
  end

let rec assoc_flip_intro
  (#a #b: eqtype)
  (l: list (a * b))
  (y: b)
  (x: a)
: Lemma
  (requires (
    L.noRepeats (list_map fst l) /\
    L.noRepeats (list_map snd l) /\
    L.assoc x l == Some y
  ))
  (ensures (
    L.assoc y (list_map flip l) == Some x
val assoc_flip_intro (#a #b: eqtype) (l: list (a * b)) (y: b) (x: a)
    : Lemma
      (requires
        (L.noRepeats (list_map fst l) /\ L.noRepeats (list_map snd l) /\ L.assoc x l == Some y))
      (ensures (L.assoc y (list_map flip l) == Some x))
l: Prims.list (a * b) -> y: b -> x: a
  -> FStar.Pervasives.Lemma
      (requires
        FStar.List.Tot.Base.noRepeats (LowParse.Spec.Enum.list_map FStar.Pervasives.Native.fst l) /\
        FStar.List.Tot.Base.noRepeats (LowParse.Spec.Enum.list_map FStar.Pervasives.Native.snd l) /\
        FStar.List.Tot.Base.assoc x l == FStar.Pervasives.Native.Some y)
      (ensures
        FStar.List.Tot.Base.assoc y (LowParse.Spec.Enum.list_map LowParse.Spec.Enum.flip l) ==
        FStar.Pervasives.Native.Some x)