Corollary consistent_insert_rem : forall {A} (h1 h2 : hist A) a b p v (Hadds : forallb is_add h1 = true),
  consistent (h1 ++ h2) a b -> consistent (h1 ++ QRem p v :: h2) ((p, v) :: a) b.

(* Specifications: *)
Lemma interleave_In : forall {A} ls (l' : list A) x (Hinter : interleave ls l'), In x l' <-> exists l, In l ls /\ In x l.
Lemma add_first : forall {A} ls (h : hist A) a b (Hinter : interleave ls h) (Hcon : consistent h a b), exists h1 h2, interleave (map (filter is_add) ls) h1 /\ interleave (map (filter (fun a => negb (is_add a))) ls) h2 /\ consistent (h1 ++ h2) a b.
Lemma interleave_reorder : forall {A} ls1 ls2 (l l' : list A), interleave (ls1 ++ l :: ls2) l' <-> interleave (l :: ls1 ++ ls2) l'.
Lemma consistent_rems : forall {A} (h : hist A) a b (Hrems : forallb (fun x => negb (is_add x)) h = true), consistent h a b -> exists l, a = l ++ b /\ h = map (fun x => let '(p, v) := x in QRem p v) l.
Lemma interleave_map_inj : forall {A B} (f : A -> B) ls l' (Hinj : forall x y, f x = f y -> x = y), interleave (map (map f) ls) (map f l') -> interleave ls l'.
Lemma interleave_combine : forall {A B} ls1 ls2 (l1 : list A) (l2 : list B) (Hls : Forall2 (fun la lb => length la = length lb) ls1 ls2) (Hlen : length l1 = length l2), interleave (map (fun x => let '(la, lb) := x in combine la lb) (combine ls1 ls2)) (combine l1 l2) -> interleave ls1 l1 /\ interleave ls2 l2.
Lemma total_length_app : forall {A} (l1 l2 : list (list A)), total_length (l1 ++ l2) = total_length l1 + total_length l2.
Lemma Zlength_interleave : forall {A} ls (l : list A), interleave ls l -> Zlength l = total_length ls.