α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
⊢ WF (Imp.filterMap f m)
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
⊢ WF (Imp.filterMap f m)
have H1 (l n acc) : filterMap.go f acc l n =
    (((g₁ l).reverse ++ acc.toList).toAssocList, ⟨n.1 + (g₁ l).length⟩) := by
  induction l generalizing n acc with simp [filterMap.go, *]
  | cons a b l => match f a b with
    | none => rfl
    | some c => simp; rw [Nat.add_right_comm]; rfl
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
⊢ WF (Imp.filterMap f m)
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
⊢ WF (Imp.filterMap f m)
let g l := (g₁ l).reverse.toAssocList
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type ?u.115430 → Type ?u.115430 := StateT (ULift Nat) Id
⊢ WF (Imp.filterMap f m)
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
⊢ WF (Imp.filterMap f m)
let M := StateT (ULift Nat) Id
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
H2 :
  ∀ (l : List (AssocList α β)) (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) l n =
      (List.map g l, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g l)) })
H3 :
  ∀ (l : List (α × β)),
    List.Sublist
      (List.map (fun a => a.fst)
        (List.filterMap
          (fun x =>
            match x with
            | (a, b) => Option.map (fun x => (a, x)) (f a b))
          l))
      (List.map (fun x => x.fst) l)
⊢ ∀ (bk : List (AssocList α γ)) (sz : Nat) (h : 0 < List.length bk),
    Array.mapM (filterMap.go f AssocList.nil) m.buckets.val { down := 0 } = ({ data := bk }, { down := sz }) →
      WF { size := sz, buckets := { val := { data := bk }, property := h } }
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
H2 :
  ∀ (l : List (AssocList α β)) (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) l n =
      (List.map g l, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g l)) })
H3 :
  ∀ (l : List (α × β)),
    List.Sublist
      (List.map (fun a => a.fst)
        (List.filterMap
          (fun x =>
            match x with
            | (a, b) => Option.map (fun x => (a, x)) (f a b))
          l))
      (List.map (fun x => x.fst) l)
⊢ WF (Imp.filterMap f m)
suffices ∀ bk sz (h : 0 < bk.length),
  m.buckets.val.mapM (m := M) (filterMap.go f .nil) ⟨0⟩ = (⟨bk⟩, ⟨sz⟩) →
  WF ⟨sz, ⟨bk⟩, h⟩ from this _ _ _ rfl
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
H2 :
  ∀ (l : List (AssocList α β)) (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) l n =
      (List.map g l, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g l)) })
H3 :
  ∀ (l : List (α × β)),
    List.Sublist
      (List.map (fun a => a.fst)
        (List.filterMap
          (fun x =>
            match x with
            | (a, b) => Option.map (fun x => (a, x)) (f a b))
          l))
      (List.map (fun x => x.fst) l)
⊢ ∀ (bk : List (AssocList α γ)) (sz : Nat) (h : 0 < List.length bk),
    pure
          {
            data :=
              List.map
                (fun l =>
                  List.toAssocList
                    (List.reverse
                      (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                        (AssocList.toList l))))
                m.buckets.val.data }
          {
            down :=
              Nat.sum
                (List.map
                  ((fun x => List.length (AssocList.toList x)) ∘ fun l =>
                    List.toAssocList
                      (List.reverse
                        (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                          (AssocList.toList l))))
                  m.buckets.val.data) } =
        ({ data := bk }, { down := sz }) →
      WF { size := sz, buckets := { val := { data := bk }, property := h } }
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
H2 :
  ∀ (l : List (AssocList α β)) (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) l n =
      (List.map g l, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g l)) })
H3 :
  ∀ (l : List (α × β)),
    List.Sublist
      (List.map (fun a => a.fst)
        (List.filterMap
          (fun x =>
            match x with
            | (a, b) => Option.map (fun x => (a, x)) (f a b))
          l))
      (List.map (fun x => x.fst) l)
⊢ ∀ (bk : List (AssocList α γ)) (sz : Nat) (h : 0 < List.length bk),
    Array.mapM (filterMap.go f AssocList.nil) m.buckets.val { down := 0 } = ({ data := bk }, { down := sz }) →
      WF { size := sz, buckets := { val := { data := bk }, property := h } }
simp [Array.mapM_eq_mapM_data, bind, StateT.bind, H2]
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
H2 :
  ∀ (l : List (AssocList α β)) (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) l n =
      (List.map g l, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g l)) })
H3 :
  ∀ (l : List (α × β)),
    List.Sublist
      (List.map (fun a => a.fst)
        (List.filterMap
          (fun x =>
            match x with
            | (a, b) => Option.map (fun x => (a, x)) (f a b))
          l))
      (List.map (fun x => x.fst) l)
bk : List (AssocList α γ)
sz : Nat
h : 0 < List.length bk
e' :
  pure
      {
        data :=
          List.map
            (fun l =>
              List.toAssocList
                (List.reverse
                  (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                    (AssocList.toList l))))
            m.buckets.val.data }
      {
        down :=
          Nat.sum
            (List.map
              ((fun x => List.length (AssocList.toList x)) ∘ fun l =>
                List.toAssocList
                  (List.reverse
                    (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                      (AssocList.toList l))))
              m.buckets.val.data) } =
    ({ data := bk }, { down := sz })
⊢ WF { size := sz, buckets := { val := { data := bk }, property := h } }
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
H2 :
  ∀ (l : List (AssocList α β)) (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) l n =
      (List.map g l, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g l)) })
H3 :
  ∀ (l : List (α × β)),
    List.Sublist
      (List.map (fun a => a.fst)
        (List.filterMap
          (fun x =>
            match x with
            | (a, b) => Option.map (fun x => (a, x)) (f a b))
          l))
      (List.map (fun x => x.fst) l)
⊢ ∀ (bk : List (AssocList α γ)) (sz : Nat) (h : 0 < List.length bk),
    pure
          {
            data :=
              List.map
                (fun l =>
                  List.toAssocList
                    (List.reverse
                      (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                        (AssocList.toList l))))
                m.buckets.val.data }
          {
            down :=
              Nat.sum
                (List.map
                  ((fun x => List.length (AssocList.toList x)) ∘ fun l =>
                    List.toAssocList
                      (List.reverse
                        (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                          (AssocList.toList l))))
                  m.buckets.val.data) } =
        ({ data := bk }, { down := sz }) →
      WF { size := sz, buckets := { val := { data := bk }, property := h } }
intro bk sz h e'
case refl
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
H2 :
  ∀ (l : List (AssocList α β)) (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) l n =
      (List.map g l, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g l)) })
H3 :
  ∀ (l : List (α × β)),
    List.Sublist
      (List.map (fun a => a.fst)
        (List.filterMap
          (fun x =>
            match x with
            | (a, b) => Option.map (fun x => (a, x)) (f a b))
          l))
      (List.map (fun x => x.fst) l)
h :
  0 <
    List.length
      (List.map
        (fun l =>
          List.toAssocList
            (List.reverse
              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))))
        m.buckets.val.data)
⊢ WF
    {
      size :=
        Nat.sum
          (List.map
            ((fun x => List.length (AssocList.toList x)) ∘ fun l =>
              List.toAssocList
                (List.reverse
                  (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                    (AssocList.toList l))))
            m.buckets.val.data),
      buckets :=
        {
          val :=
            {
              data :=
                List.map
                  (fun l =>
                    List.toAssocList
                      (List.reverse
                        (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                          (AssocList.toList l))))
                  m.buckets.val.data },
          property := h } }
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
H2 :
  ∀ (l : List (AssocList α β)) (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) l n =
      (List.map g l, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g l)) })
H3 :
  ∀ (l : List (α × β)),
    List.Sublist
      (List.map (fun a => a.fst)
        (List.filterMap
          (fun x =>
            match x with
            | (a, b) => Option.map (fun x => (a, x)) (f a b))
          l))
      (List.map (fun x => x.fst) l)
bk : List (AssocList α γ)
sz : Nat
h : 0 < List.length bk
e' :
  pure
      {
        data :=
          List.map
            (fun l =>
              List.toAssocList
                (List.reverse
                  (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                    (AssocList.toList l))))
            m.buckets.val.data }
      {
        down :=
          Nat.sum
            (List.map
              ((fun x => List.length (AssocList.toList x)) ∘ fun l =>
                List.toAssocList
                  (List.reverse
                    (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                      (AssocList.toList l))))
              m.buckets.val.data) } =
    ({ data := bk }, { down := sz })
⊢ WF { size := sz, buckets := { val := { data := bk }, property := h } }
cases e'
case refl.refine_1
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
H2 :
  ∀ (l : List (AssocList α β)) (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) l n =
      (List.map g l, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g l)) })
H3 :
  ∀ (l : List (α × β)),
    List.Sublist
      (List.map (fun a => a.fst)
        (List.filterMap
          (fun x =>
            match x with
            | (a, b) => Option.map (fun x => (a, x)) (f a b))
          l))
      (List.map (fun x => x.fst) l)
h :
  0 <
    List.length
      (List.map
        (fun l =>
          List.toAssocList
            (List.reverse
              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))))
        m.buckets.val.data)
⊢ ∀ [inst : LawfulHashable α] [inst : PartialEquivBEq α] (bucket : AssocList α γ),
    bucket ∈
        {
                size :=
                  Nat.sum
                    (List.map
                      ((fun x => List.length (AssocList.toList x)) ∘ fun l =>
                        List.toAssocList
                          (List.reverse
                            (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                              (AssocList.toList l))))
                      m.buckets.val.data),
                buckets :=
                  {
                    val :=
                      {
                        data :=
                          List.map
                            (fun l =>
                              List.toAssocList
                                (List.reverse
                                  (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                                    (AssocList.toList l))))
                            m.buckets.val.data },
                    property := h } }.buckets.val.data →
      List.Pairwise (fun a b => ¬(a.fst == b.fst) = true) (AssocList.toList bucket)

case refl.refine_2
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
H2 :
  ∀ (l : List (AssocList α β)) (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) l n =
      (List.map g l, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g l)) })
H3 :
  ∀ (l : List (α × β)),
    List.Sublist
      (List.map (fun a => a.fst)
        (List.filterMap
          (fun x =>
            match x with
            | (a, b) => Option.map (fun x => (a, x)) (f a b))
          l))
      (List.map (fun x => x.fst) l)
h✝ :
  0 <
    List.length
      (List.map
        (fun l =>
          List.toAssocList
            (List.reverse
              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))))
        m.buckets.val.data)
i : Nat
h :
  i <
    Array.size
      {
            size :=
              Nat.sum
                (List.map
                  ((fun x => List.length (AssocList.toList x)) ∘ fun l =>
                    List.toAssocList
                      (List.reverse
                        (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                          (AssocList.toList l))))
                  m.buckets.val.data),
            buckets :=
              {
                val :=
                  {
                    data :=
                      List.map
                        (fun l =>
                          List.toAssocList
                            (List.reverse
                              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                                (AssocList.toList l))))
                        m.buckets.val.data },
                property := h✝ } }.buckets.val
⊢ AssocList.All
    (fun k x =>
      USize.toNat
          (UInt64.toUSize (hash k) %
            Array.size
              {
                    size :=
                      Nat.sum
                        (List.map
                          ((fun x => List.length (AssocList.toList x)) ∘ fun l =>
                            List.toAssocList
                              (List.reverse
                                (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                                  (AssocList.toList l))))
                          m.buckets.val.data),
                    buckets :=
                      {
                        val :=
                          {
                            data :=
                              List.map
                                (fun l =>
                                  List.toAssocList
                                    (List.reverse
                                      (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                                        (AssocList.toList l))))
                                m.buckets.val.data },
                        property := h✝ } }.buckets.val) =
        i)
    {
            size :=
              Nat.sum
                (List.map
                  ((fun x => List.length (AssocList.toList x)) ∘ fun l =>
                    List.toAssocList
                      (List.reverse
                        (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                          (AssocList.toList l))))
                  m.buckets.val.data),
            buckets :=
              {
                val :=
                  {
                    data :=
                      List.map
                        (fun l =>
                          List.toAssocList
                            (List.reverse
                              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                                (AssocList.toList l))))
                        m.buckets.val.data },
                property := h✝ } }.buckets.val[i]
case refl
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
H2 :
  ∀ (l : List (AssocList α β)) (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) l n =
      (List.map g l, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g l)) })
H3 :
  ∀ (l : List (α × β)),
    List.Sublist
      (List.map (fun a => a.fst)
        (List.filterMap
          (fun x =>
            match x with
            | (a, b) => Option.map (fun x => (a, x)) (f a b))
          l))
      (List.map (fun x => x.fst) l)
h :
  0 <
    List.length
      (List.map
        (fun l =>
          List.toAssocList
            (List.reverse
              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))))
        m.buckets.val.data)
⊢ WF
    {
      size :=
        Nat.sum
          (List.map
            ((fun x => List.length (AssocList.toList x)) ∘ fun l =>
              List.toAssocList
                (List.reverse
                  (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                    (AssocList.toList l))))
            m.buckets.val.data),
      buckets :=
        {
          val :=
            {
              data :=
                List.map
                  (fun l =>
                    List.toAssocList
                      (List.reverse
                        (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                          (AssocList.toList l))))
                  m.buckets.val.data },
          property := h } }
refine .mk (by simp [Bucket.size]) ⟨?_, fun i h => ?_⟩
no goals
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
l : AssocList α β
n : ULift Nat
acc : AssocList α γ
⊢ filterMap.go f acc l n =
    (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
induction l generalizing n acc with simp [filterMap.go, *]
| cons a b l => match f a b with
  | none => rfl
  | some c => simp; rw [Nat.add_right_comm]; rfl
no goals
case cons
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
a : α
b : β
l : AssocList α β
tail_ih✝ :
  ∀ (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
n : ULift Nat
acc : AssocList α γ
⊢ (match f a b with
    | none =>
      (List.toAssocList
          (List.reverse
              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)) ++
            AssocList.toList acc),
        {
          down :=
            n.down +
              List.length
                (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)) })
    | some c =>
      (List.toAssocList
          (List.reverse
              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)) ++
            (a, c) :: AssocList.toList acc),
        {
          down :=
            n.down + 1 +
              List.length
                (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                  (AssocList.toList l)) })) =
    (List.toAssocList
        (List.reverse
            (match Option.map (fun x => (a, x)) (f a b) with
            | none =>
              List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
            | some b =>
              b ::
                List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)) ++
          AssocList.toList acc),
      {
        down :=
          n.down +
            List.length
              (match Option.map (fun x => (a, x)) (f a b) with
              | none =>
                List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
              | some b =>
                b ::
                  List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                    (AssocList.toList l)) })
match f a b with
| none => rfl
| some c => simp; rw [Nat.add_right_comm]; rfl
no goals
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
a : α
b : β
l : AssocList α β
tail_ih✝ :
  ∀ (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
n : ULift Nat
acc : AssocList α γ
⊢ (match none with
    | none =>
      (List.toAssocList
          (List.reverse
              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)) ++
            AssocList.toList acc),
        {
          down :=
            n.down +
              List.length
                (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)) })
    | some c =>
      (List.toAssocList
          (List.reverse
              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)) ++
            (a, c) :: AssocList.toList acc),
        {
          down :=
            n.down + 1 +
              List.length
                (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                  (AssocList.toList l)) })) =
    (List.toAssocList
        (List.reverse
            (match Option.map (fun x => (a, x)) none with
            | none =>
              List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
            | some b =>
              b ::
                List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)) ++
          AssocList.toList acc),
      {
        down :=
          n.down +
            List.length
              (match Option.map (fun x => (a, x)) none with
              | none =>
                List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
              | some b =>
                b ::
                  List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                    (AssocList.toList l)) })
rfl
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
a : α
b : β
l : AssocList α β
tail_ih✝ :
  ∀ (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
n : ULift Nat
acc : AssocList α γ
c : γ
⊢ {
      down :=
        n.down + 1 +
          List.length
            (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)) } =
    {
      down :=
        n.down +
          Nat.succ
            (List.length
              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))) }
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
a : α
b : β
l : AssocList α β
tail_ih✝ :
  ∀ (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
n : ULift Nat
acc : AssocList α γ
c : γ
⊢ (match some c with
    | none =>
      (List.toAssocList
          (List.reverse
              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)) ++
            AssocList.toList acc),
        {
          down :=
            n.down +
              List.length
                (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)) })
    | some c =>
      (List.toAssocList
          (List.reverse
              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)) ++
            (a, c) :: AssocList.toList acc),
        {
          down :=
            n.down + 1 +
              List.length
                (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                  (AssocList.toList l)) })) =
    (List.toAssocList
        (List.reverse
            (match Option.map (fun x => (a, x)) (some c) with
            | none =>
              List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
            | some b =>
              b ::
                List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)) ++
          AssocList.toList acc),
      {
        down :=
          n.down +
            List.length
              (match Option.map (fun x => (a, x)) (some c) with
              | none =>
                List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
              | some b =>
                b ::
                  List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                    (AssocList.toList l)) })
simp
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
a : α
b : β
l : AssocList α β
tail_ih✝ :
  ∀ (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
n : ULift Nat
acc : AssocList α γ
c : γ
⊢ {
      down :=
        n.down +
            List.length
              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)) +
          1 } =
    {
      down :=
        n.down +
          Nat.succ
            (List.length
              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))) }
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
a : α
b : β
l : AssocList α β
tail_ih✝ :
  ∀ (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
n : ULift Nat
acc : AssocList α γ
c : γ
⊢ {
      down :=
        n.down + 1 +
          List.length
            (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)) } =
    {
      down :=
        n.down +
          Nat.succ
            (List.length
              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))) }
rw [Nat.add_right_comm]
no goals
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
a : α
b : β
l : AssocList α β
tail_ih✝ :
  ∀ (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
n : ULift Nat
acc : AssocList α γ
c : γ
⊢ {
      down :=
        n.down +
            List.length
              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)) +
          1 } =
    {
      down :=
        n.down +
          Nat.succ
            (List.length
              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))) }
rfl
no goals
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
l : List (AssocList α β)
n : ULift Nat
⊢ List.mapM (filterMap.go f AssocList.nil) l n =
    (List.map g l, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g l)) })
induction l generalizing n with
| nil => rfl
| cons l L IH => simp [bind, StateT.bind, IH, H1, Nat.add_assoc]; rfl
no goals
case nil
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
n : ULift Nat
⊢ List.mapM (filterMap.go f AssocList.nil) [] n =
    (List.map g [], { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g [])) })
rfl
case cons
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
l : AssocList α β
L : List (AssocList α β)
IH :
  ∀ (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) L n =
      (List.map g L, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g L)) })
n : ULift Nat
⊢ pure
      (List.toAssocList
          (List.reverse
            (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))) ::
        List.map
          (fun l =>
            List.toAssocList
              (List.reverse
                (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))))
          L)
      {
        down :=
          n.down +
            (List.length
                (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)) +
              Nat.sum
                (List.map
                  ((fun x => List.length (AssocList.toList x)) ∘ fun l =>
                    List.toAssocList
                      (List.reverse
                        (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                          (AssocList.toList l))))
                  L)) } =
    (List.toAssocList
          (List.reverse
            (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))) ::
        List.map
          (fun l =>
            List.toAssocList
              (List.reverse
                (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))))
          L,
      {
        down :=
          n.down +
            (List.length
                (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)) +
              Nat.sum
                (List.map
                  ((fun x => List.length (AssocList.toList x)) ∘ fun l =>
                    List.toAssocList
                      (List.reverse
                        (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                          (AssocList.toList l))))
                  L)) })
case cons
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
l : AssocList α β
L : List (AssocList α β)
IH :
  ∀ (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) L n =
      (List.map g L, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g L)) })
n : ULift Nat
⊢ List.mapM (filterMap.go f AssocList.nil) (l :: L) n =
    (List.map g (l :: L),
      { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g (l :: L))) })
simp [bind, StateT.bind, IH, H1, Nat.add_assoc]
no goals
case cons
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
l : AssocList α β
L : List (AssocList α β)
IH :
  ∀ (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) L n =
      (List.map g L, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g L)) })
n : ULift Nat
⊢ pure
      (List.toAssocList
          (List.reverse
            (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))) ::
        List.map
          (fun l =>
            List.toAssocList
              (List.reverse
                (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))))
          L)
      {
        down :=
          n.down +
            (List.length
                (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)) +
              Nat.sum
                (List.map
                  ((fun x => List.length (AssocList.toList x)) ∘ fun l =>
                    List.toAssocList
                      (List.reverse
                        (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                          (AssocList.toList l))))
                  L)) } =
    (List.toAssocList
          (List.reverse
            (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))) ::
        List.map
          (fun l =>
            List.toAssocList
              (List.reverse
                (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))))
          L,
      {
        down :=
          n.down +
            (List.length
                (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)) +
              Nat.sum
                (List.map
                  ((fun x => List.length (AssocList.toList x)) ∘ fun l =>
                    List.toAssocList
                      (List.reverse
                        (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                          (AssocList.toList l))))
                  L)) })
rfl
no goals
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
H2 :
  ∀ (l : List (AssocList α β)) (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) l n =
      (List.map g l, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g l)) })
l : List (α × β)
⊢ List.Sublist
    (List.map (fun a => a.fst)
      (List.filterMap
        (fun x =>
          match x with
          | (a, b) => Option.map (fun x => (a, x)) (f a b))
        l))
    (List.map (fun x => x.fst) l)
induction l with
| nil => exact .slnil
| cons a l ih =>
  simp; exact match f a.1 a.2 with
  | none => .cons _ ih
  | some b => .cons₂ _ ih
no goals
case nil
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
H2 :
  ∀ (l : List (AssocList α β)) (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) l n =
      (List.map g l, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g l)) })
⊢ List.Sublist
    (List.map (fun a => a.fst)
      (List.filterMap
        (fun x =>
          match x with
          | (a, b) => Option.map (fun x => (a, x)) (f a b))
        []))
    (List.map (fun x => x.fst) [])
exact .slnil
case cons
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
H2 :
  ∀ (l : List (AssocList α β)) (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) l n =
      (List.map g l, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g l)) })
a : α × β
l : List (α × β)
ih :
  List.Sublist
    (List.map (fun a => a.fst)
      (List.filterMap
        (fun x =>
          match x with
          | (a, b) => Option.map (fun x => (a, x)) (f a b))
        l))
    (List.map (fun x => x.fst) l)
⊢ List.Sublist
    (List.map (fun a => a.fst)
      (match Option.map (fun x => (a.fst, x)) (f a.fst a.snd) with
      | none => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) l
      | some b => b :: List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) l))
    (a.fst :: List.map (fun x => x.fst) l)
case cons
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
H2 :
  ∀ (l : List (AssocList α β)) (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) l n =
      (List.map g l, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g l)) })
a : α × β
l : List (α × β)
ih :
  List.Sublist
    (List.map (fun a => a.fst)
      (List.filterMap
        (fun x =>
          match x with
          | (a, b) => Option.map (fun x => (a, x)) (f a b))
        l))
    (List.map (fun x => x.fst) l)
⊢ List.Sublist
    (List.map (fun a => a.fst)
      (List.filterMap
        (fun x =>
          match x with
          | (a, b) => Option.map (fun x => (a, x)) (f a b))
        (a :: l)))
    (List.map (fun x => x.fst) (a :: l))
simp
no goals
case cons
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
H2 :
  ∀ (l : List (AssocList α β)) (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) l n =
      (List.map g l, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g l)) })
a : α × β
l : List (α × β)
ih :
  List.Sublist
    (List.map (fun a => a.fst)
      (List.filterMap
        (fun x =>
          match x with
          | (a, b) => Option.map (fun x => (a, x)) (f a b))
        l))
    (List.map (fun x => x.fst) l)
⊢ List.Sublist
    (List.map (fun a => a.fst)
      (match Option.map (fun x => (a.fst, x)) (f a.fst a.snd) with
      | none => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) l
      | some b => b :: List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) l))
    (a.fst :: List.map (fun x => x.fst) l)
exact match f a.1 a.2 with
| none => .cons _ ih
| some b => .cons₂ _ ih
no goals
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
H2 :
  ∀ (l : List (AssocList α β)) (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) l n =
      (List.map g l, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g l)) })
H3 :
  ∀ (l : List (α × β)),
    List.Sublist
      (List.map (fun a => a.fst)
        (List.filterMap
          (fun x =>
            match x with
            | (a, b) => Option.map (fun x => (a, x)) (f a b))
          l))
      (List.map (fun x => x.fst) l)
h :
  0 <
    List.length
      (List.map
        (fun l =>
          List.toAssocList
            (List.reverse
              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))))
        m.buckets.val.data)
⊢ {
        size :=
          Nat.sum
            (List.map
              ((fun x => List.length (AssocList.toList x)) ∘ fun l =>
                List.toAssocList
                  (List.reverse
                    (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                      (AssocList.toList l))))
              m.buckets.val.data),
        buckets :=
          {
            val :=
              {
                data :=
                  List.map
                    (fun l =>
                      List.toAssocList
                        (List.reverse
                          (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                            (AssocList.toList l))))
                    m.buckets.val.data },
            property := h } }.size =
    Bucket.size
      {
          size :=
            Nat.sum
              (List.map
                ((fun x => List.length (AssocList.toList x)) ∘ fun l =>
                  List.toAssocList
                    (List.reverse
                      (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                        (AssocList.toList l))))
                m.buckets.val.data),
          buckets :=
            {
              val :=
                {
                  data :=
                    List.map
                      (fun l =>
                        List.toAssocList
                          (List.reverse
                            (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                              (AssocList.toList l))))
                      m.buckets.val.data },
              property := h } }.buckets
simp [Bucket.size]
case refl.refine_1
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
H2 :
  ∀ (l : List (AssocList α β)) (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) l n =
      (List.map g l, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g l)) })
H3 :
  ∀ (l : List (α × β)),
    List.Sublist
      (List.map (fun a => a.fst)
        (List.filterMap
          (fun x =>
            match x with
            | (a, b) => Option.map (fun x => (a, x)) (f a b))
          l))
      (List.map (fun x => x.fst) l)
h :
  0 <
    List.length
      (List.map
        (fun l =>
          List.toAssocList
            (List.reverse
              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))))
        m.buckets.val.data)
⊢ ∀ [inst : LawfulHashable α] [inst : PartialEquivBEq α] (j : AssocList α β),
    j ∈ m.buckets.val.data →
      List.Pairwise (fun a b => ¬(a.fst == b.fst) = true)
        (List.reverse
          (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList j)))
case refl.refine_1
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
H2 :
  ∀ (l : List (AssocList α β)) (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) l n =
      (List.map g l, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g l)) })
H3 :
  ∀ (l : List (α × β)),
    List.Sublist
      (List.map (fun a => a.fst)
        (List.filterMap
          (fun x =>
            match x with
            | (a, b) => Option.map (fun x => (a, x)) (f a b))
          l))
      (List.map (fun x => x.fst) l)
h :
  0 <
    List.length
      (List.map
        (fun l =>
          List.toAssocList
            (List.reverse
              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))))
        m.buckets.val.data)
⊢ ∀ [inst : LawfulHashable α] [inst : PartialEquivBEq α] (bucket : AssocList α γ),
    bucket ∈
        {
                size :=
                  Nat.sum
                    (List.map
                      ((fun x => List.length (AssocList.toList x)) ∘ fun l =>
                        List.toAssocList
                          (List.reverse
                            (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                              (AssocList.toList l))))
                      m.buckets.val.data),
                buckets :=
                  {
                    val :=
                      {
                        data :=
                          List.map
                            (fun l =>
                              List.toAssocList
                                (List.reverse
                                  (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                                    (AssocList.toList l))))
                            m.buckets.val.data },
                    property := h } }.buckets.val.data →
      List.Pairwise (fun a b => ¬(a.fst == b.fst) = true) (AssocList.toList bucket)
simp only [List.forall_mem_map_iff, List.toAssocList_toList]
case refl.refine_1
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝³ : BEq α
inst✝² : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
H2 :
  ∀ (l : List (AssocList α β)) (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) l n =
      (List.map g l, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g l)) })
H3 :
  ∀ (l : List (α × β)),
    List.Sublist
      (List.map (fun a => a.fst)
        (List.filterMap
          (fun x =>
            match x with
            | (a, b) => Option.map (fun x => (a, x)) (f a b))
          l))
      (List.map (fun x => x.fst) l)
h✝ :
  0 <
    List.length
      (List.map
        (fun l =>
          List.toAssocList
            (List.reverse
              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))))
        m.buckets.val.data)
inst✝¹ : LawfulHashable α
inst✝ : PartialEquivBEq α
l : AssocList α β
h : l ∈ m.buckets.val.data
⊢ List.Pairwise (fun a b => ¬(a.fst == b.fst) = true)
    (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))
case refl.refine_1
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
H2 :
  ∀ (l : List (AssocList α β)) (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) l n =
      (List.map g l, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g l)) })
H3 :
  ∀ (l : List (α × β)),
    List.Sublist
      (List.map (fun a => a.fst)
        (List.filterMap
          (fun x =>
            match x with
            | (a, b) => Option.map (fun x => (a, x)) (f a b))
          l))
      (List.map (fun x => x.fst) l)
h :
  0 <
    List.length
      (List.map
        (fun l =>
          List.toAssocList
            (List.reverse
              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))))
        m.buckets.val.data)
⊢ ∀ [inst : LawfulHashable α] [inst : PartialEquivBEq α] (j : AssocList α β),
    j ∈ m.buckets.val.data →
      List.Pairwise (fun a b => ¬(a.fst == b.fst) = true)
        (List.reverse
          (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList j)))
refine fun l h => (List.pairwise_reverse.2 ?_).imp (mt PartialEquivBEq.symm)
case refl.refine_1
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝³ : BEq α
inst✝² : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
H2 :
  ∀ (l : List (AssocList α β)) (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) l n =
      (List.map g l, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g l)) })
H3 :
  ∀ (l : List (α × β)),
    List.Sublist
      (List.map (fun a => a.fst)
        (List.filterMap
          (fun x =>
            match x with
            | (a, b) => Option.map (fun x => (a, x)) (f a b))
          l))
      (List.map (fun x => x.fst) l)
h✝ :
  0 <
    List.length
      (List.map
        (fun l =>
          List.toAssocList
            (List.reverse
              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))))
        m.buckets.val.data)
inst✝¹ : LawfulHashable α
inst✝ : PartialEquivBEq α
l : AssocList α β
h : l ∈ m.buckets.val.data
this : List.Pairwise (fun a b => ¬(a.fst == b.fst) = true) (AssocList.toList l)
⊢ List.Pairwise (fun a b => ¬(a.fst == b.fst) = true)
    (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))
case refl.refine_1
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝³ : BEq α
inst✝² : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
H2 :
  ∀ (l : List (AssocList α β)) (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) l n =
      (List.map g l, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g l)) })
H3 :
  ∀ (l : List (α × β)),
    List.Sublist
      (List.map (fun a => a.fst)
        (List.filterMap
          (fun x =>
            match x with
            | (a, b) => Option.map (fun x => (a, x)) (f a b))
          l))
      (List.map (fun x => x.fst) l)
h✝ :
  0 <
    List.length
      (List.map
        (fun l =>
          List.toAssocList
            (List.reverse
              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))))
        m.buckets.val.data)
inst✝¹ : LawfulHashable α
inst✝ : PartialEquivBEq α
l : AssocList α β
h : l ∈ m.buckets.val.data
⊢ List.Pairwise (fun a b => ¬(a.fst == b.fst) = true)
    (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))
have := H.out.2.1 _ h
no goals
case refl.refine_1
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝³ : BEq α
inst✝² : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
H2 :
  ∀ (l : List (AssocList α β)) (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) l n =
      (List.map g l, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g l)) })
H3 :
  ∀ (l : List (α × β)),
    List.Sublist
      (List.map (fun a => a.fst)
        (List.filterMap
          (fun x =>
            match x with
            | (a, b) => Option.map (fun x => (a, x)) (f a b))
          l))
      (List.map (fun x => x.fst) l)
h✝ :
  0 <
    List.length
      (List.map
        (fun l =>
          List.toAssocList
            (List.reverse
              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))))
        m.buckets.val.data)
inst✝¹ : LawfulHashable α
inst✝ : PartialEquivBEq α
l : AssocList α β
h : l ∈ m.buckets.val.data
this : List.Pairwise (fun x x_1 => ¬(x == x_1) = true) (List.map (fun a => a.fst) (AssocList.toList l))
⊢ List.Pairwise (fun x x_1 => ¬(x == x_1) = true)
    (List.map (fun a => a.fst)
      (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)))
exact this.sublist (H3 l.toList)
case refl.refine_2
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
H2 :
  ∀ (l : List (AssocList α β)) (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) l n =
      (List.map g l, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g l)) })
H3 :
  ∀ (l : List (α × β)),
    List.Sublist
      (List.map (fun a => a.fst)
        (List.filterMap
          (fun x =>
            match x with
            | (a, b) => Option.map (fun x => (a, x)) (f a b))
          l))
      (List.map (fun x => x.fst) l)
h✝¹ :
  0 <
    List.length
      (List.map
        (fun l =>
          List.toAssocList
            (List.reverse
              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))))
        m.buckets.val.data)
i : Nat
h✝ :
  i <
    Array.size
      {
            size :=
              Nat.sum
                (List.map
                  ((fun x => List.length (AssocList.toList x)) ∘ fun l =>
                    List.toAssocList
                      (List.reverse
                        (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                          (AssocList.toList l))))
                  m.buckets.val.data),
            buckets :=
              {
                val :=
                  {
                    data :=
                      List.map
                        (fun l =>
                          List.toAssocList
                            (List.reverse
                              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                                (AssocList.toList l))))
                        m.buckets.val.data },
                property := h✝¹ } }.buckets.val
h : i < List.length m.buckets.val.data
⊢ AssocList.All (fun k x => USize.toNat (UInt64.toUSize (hash k) % List.length m.buckets.val.data) = i)
    (List.toAssocList
      (List.reverse
        (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
          (AssocList.toList
            (List.get m.buckets.val.data
              { val := i, isLt := (_ : { val := i, isLt := h✝ }.val < List.length m.buckets.val.data) })))))
case refl.refine_2
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
H2 :
  ∀ (l : List (AssocList α β)) (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) l n =
      (List.map g l, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g l)) })
H3 :
  ∀ (l : List (α × β)),
    List.Sublist
      (List.map (fun a => a.fst)
        (List.filterMap
          (fun x =>
            match x with
            | (a, b) => Option.map (fun x => (a, x)) (f a b))
          l))
      (List.map (fun x => x.fst) l)
h✝ :
  0 <
    List.length
      (List.map
        (fun l =>
          List.toAssocList
            (List.reverse
              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))))
        m.buckets.val.data)
i : Nat
h :
  i <
    Array.size
      {
            size :=
              Nat.sum
                (List.map
                  ((fun x => List.length (AssocList.toList x)) ∘ fun l =>
                    List.toAssocList
                      (List.reverse
                        (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                          (AssocList.toList l))))
                  m.buckets.val.data),
            buckets :=
              {
                val :=
                  {
                    data :=
                      List.map
                        (fun l =>
                          List.toAssocList
                            (List.reverse
                              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                                (AssocList.toList l))))
                        m.buckets.val.data },
                property := h✝ } }.buckets.val
⊢ AssocList.All
    (fun k x =>
      USize.toNat
          (UInt64.toUSize (hash k) %
            Array.size
              {
                    size :=
                      Nat.sum
                        (List.map
                          ((fun x => List.length (AssocList.toList x)) ∘ fun l =>
                            List.toAssocList
                              (List.reverse
                                (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                                  (AssocList.toList l))))
                          m.buckets.val.data),
                    buckets :=
                      {
                        val :=
                          {
                            data :=
                              List.map
                                (fun l =>
                                  List.toAssocList
                                    (List.reverse
                                      (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                                        (AssocList.toList l))))
                                m.buckets.val.data },
                        property := h✝ } }.buckets.val) =
        i)
    {
            size :=
              Nat.sum
                (List.map
                  ((fun x => List.length (AssocList.toList x)) ∘ fun l =>
                    List.toAssocList
                      (List.reverse
                        (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                          (AssocList.toList l))))
                  m.buckets.val.data),
            buckets :=
              {
                val :=
                  {
                    data :=
                      List.map
                        (fun l =>
                          List.toAssocList
                            (List.reverse
                              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                                (AssocList.toList l))))
                        m.buckets.val.data },
                property := h✝ } }.buckets.val[i]
simp [Array.getElem_eq_data_get] at h ⊢
case refl.refine_2
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
H2 :
  ∀ (l : List (AssocList α β)) (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) l n =
      (List.map g l, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g l)) })
H3 :
  ∀ (l : List (α × β)),
    List.Sublist
      (List.map (fun a => a.fst)
        (List.filterMap
          (fun x =>
            match x with
            | (a, b) => Option.map (fun x => (a, x)) (f a b))
          l))
      (List.map (fun x => x.fst) l)
h✝¹ :
  0 <
    List.length
      (List.map
        (fun l =>
          List.toAssocList
            (List.reverse
              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))))
        m.buckets.val.data)
i : Nat
h✝ :
  i <
    Array.size
      {
            size :=
              Nat.sum
                (List.map
                  ((fun x => List.length (AssocList.toList x)) ∘ fun l =>
                    List.toAssocList
                      (List.reverse
                        (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                          (AssocList.toList l))))
                  m.buckets.val.data),
            buckets :=
              {
                val :=
                  {
                    data :=
                      List.map
                        (fun l =>
                          List.toAssocList
                            (List.reverse
                              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                                (AssocList.toList l))))
                        m.buckets.val.data },
                property := h✝¹ } }.buckets.val
h : i < List.length m.buckets.val.data
this : AssocList.All (fun k x => USize.toNat (UInt64.toUSize (hash k) % Array.size m.buckets.val) = i) m.buckets.val[i]
⊢ AssocList.All (fun k x => USize.toNat (UInt64.toUSize (hash k) % List.length m.buckets.val.data) = i)
    (List.toAssocList
      (List.reverse
        (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
          (AssocList.toList
            (List.get m.buckets.val.data
              { val := i, isLt := (_ : { val := i, isLt := h✝ }.val < List.length m.buckets.val.data) })))))
case refl.refine_2
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
H2 :
  ∀ (l : List (AssocList α β)) (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) l n =
      (List.map g l, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g l)) })
H3 :
  ∀ (l : List (α × β)),
    List.Sublist
      (List.map (fun a => a.fst)
        (List.filterMap
          (fun x =>
            match x with
            | (a, b) => Option.map (fun x => (a, x)) (f a b))
          l))
      (List.map (fun x => x.fst) l)
h✝¹ :
  0 <
    List.length
      (List.map
        (fun l =>
          List.toAssocList
            (List.reverse
              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))))
        m.buckets.val.data)
i : Nat
h✝ :
  i <
    Array.size
      {
            size :=
              Nat.sum
                (List.map
                  ((fun x => List.length (AssocList.toList x)) ∘ fun l =>
                    List.toAssocList
                      (List.reverse
                        (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                          (AssocList.toList l))))
                  m.buckets.val.data),
            buckets :=
              {
                val :=
                  {
                    data :=
                      List.map
                        (fun l =>
                          List.toAssocList
                            (List.reverse
                              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                                (AssocList.toList l))))
                        m.buckets.val.data },
                property := h✝¹ } }.buckets.val
h : i < List.length m.buckets.val.data
⊢ AssocList.All (fun k x => USize.toNat (UInt64.toUSize (hash k) % List.length m.buckets.val.data) = i)
    (List.toAssocList
      (List.reverse
        (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
          (AssocList.toList
            (List.get m.buckets.val.data
              { val := i, isLt := (_ : { val := i, isLt := h✝ }.val < List.length m.buckets.val.data) })))))
have := H.out.2.2 _ h
case refl.refine_2
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
H2 :
  ∀ (l : List (AssocList α β)) (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) l n =
      (List.map g l, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g l)) })
H3 :
  ∀ (l : List (α × β)),
    List.Sublist
      (List.map (fun a => a.fst)
        (List.filterMap
          (fun x =>
            match x with
            | (a, b) => Option.map (fun x => (a, x)) (f a b))
          l))
      (List.map (fun x => x.fst) l)
h✝¹ :
  0 <
    List.length
      (List.map
        (fun l =>
          List.toAssocList
            (List.reverse
              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))))
        m.buckets.val.data)
i : Nat
h✝ :
  i <
    Array.size
      {
            size :=
              Nat.sum
                (List.map
                  ((fun x => List.length (AssocList.toList x)) ∘ fun l =>
                    List.toAssocList
                      (List.reverse
                        (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                          (AssocList.toList l))))
                  m.buckets.val.data),
            buckets :=
              {
                val :=
                  {
                    data :=
                      List.map
                        (fun l =>
                          List.toAssocList
                            (List.reverse
                              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                                (AssocList.toList l))))
                        m.buckets.val.data },
                property := h✝¹ } }.buckets.val
h : i < List.length m.buckets.val.data
this :
  ∀ (a : α × β),
    a ∈ AssocList.toList m.buckets.val[i] → USize.toNat (UInt64.toUSize (hash a.fst) % Array.size m.buckets.val) = i
⊢ ∀ (a : α × γ) (x : α × β),
    x ∈
        AssocList.toList
          (List.get m.buckets.val.data
            { val := i, isLt := (_ : { val := i, isLt := h✝ }.val < List.length m.buckets.val.data) }) →
      ∀ (x_1 : γ),
        f x.fst x.snd = some x_1 →
          (x.fst, x_1) = a → USize.toNat (UInt64.toUSize (hash a.fst) % List.length m.buckets.val.data) = i
case refl.refine_2
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
H2 :
  ∀ (l : List (AssocList α β)) (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) l n =
      (List.map g l, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g l)) })
H3 :
  ∀ (l : List (α × β)),
    List.Sublist
      (List.map (fun a => a.fst)
        (List.filterMap
          (fun x =>
            match x with
            | (a, b) => Option.map (fun x => (a, x)) (f a b))
          l))
      (List.map (fun x => x.fst) l)
h✝¹ :
  0 <
    List.length
      (List.map
        (fun l =>
          List.toAssocList
            (List.reverse
              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))))
        m.buckets.val.data)
i : Nat
h✝ :
  i <
    Array.size
      {
            size :=
              Nat.sum
                (List.map
                  ((fun x => List.length (AssocList.toList x)) ∘ fun l =>
                    List.toAssocList
                      (List.reverse
                        (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                          (AssocList.toList l))))
                  m.buckets.val.data),
            buckets :=
              {
                val :=
                  {
                    data :=
                      List.map
                        (fun l =>
                          List.toAssocList
                            (List.reverse
                              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                                (AssocList.toList l))))
                        m.buckets.val.data },
                property := h✝¹ } }.buckets.val
h : i < List.length m.buckets.val.data
this : AssocList.All (fun k x => USize.toNat (UInt64.toUSize (hash k) % Array.size m.buckets.val) = i) m.buckets.val[i]
⊢ AssocList.All (fun k x => USize.toNat (UInt64.toUSize (hash k) % List.length m.buckets.val.data) = i)
    (List.toAssocList
      (List.reverse
        (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
          (AssocList.toList
            (List.get m.buckets.val.data
              { val := i, isLt := (_ : { val := i, isLt := h✝ }.val < List.length m.buckets.val.data) })))))
simp [AssocList.All] at this ⊢
case refl.refine_2
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
H2 :
  ∀ (l : List (AssocList α β)) (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) l n =
      (List.map g l, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g l)) })
H3 :
  ∀ (l : List (α × β)),
    List.Sublist
      (List.map (fun a => a.fst)
        (List.filterMap
          (fun x =>
            match x with
            | (a, b) => Option.map (fun x => (a, x)) (f a b))
          l))
      (List.map (fun x => x.fst) l)
h✝¹ :
  0 <
    List.length
      (List.map
        (fun l =>
          List.toAssocList
            (List.reverse
              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))))
        m.buckets.val.data)
i : Nat
h✝ :
  i <
    Array.size
      {
            size :=
              Nat.sum
                (List.map
                  ((fun x => List.length (AssocList.toList x)) ∘ fun l =>
                    List.toAssocList
                      (List.reverse
                        (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                          (AssocList.toList l))))
                  m.buckets.val.data),
            buckets :=
              {
                val :=
                  {
                    data :=
                      List.map
                        (fun l =>
                          List.toAssocList
                            (List.reverse
                              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                                (AssocList.toList l))))
                        m.buckets.val.data },
                property := h✝¹ } }.buckets.val
h : i < List.length m.buckets.val.data
this :
  ∀ (a : α × β),
    a ∈ AssocList.toList m.buckets.val[i] → USize.toNat (UInt64.toUSize (hash a.fst) % Array.size m.buckets.val) = i
x✝¹ : α × β
h' :
  x✝¹ ∈
    AssocList.toList
      (List.get m.buckets.val.data
        { val := i, isLt := (_ : { val := i, isLt := h✝ }.val < List.length m.buckets.val.data) })
x✝ : γ
a✝ : f x✝¹.fst x✝¹.snd = some x✝
⊢ USize.toNat (UInt64.toUSize (hash (x✝¹.fst, x✝).fst) % List.length m.buckets.val.data) = i
case refl.refine_2
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
H2 :
  ∀ (l : List (AssocList α β)) (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) l n =
      (List.map g l, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g l)) })
H3 :
  ∀ (l : List (α × β)),
    List.Sublist
      (List.map (fun a => a.fst)
        (List.filterMap
          (fun x =>
            match x with
            | (a, b) => Option.map (fun x => (a, x)) (f a b))
          l))
      (List.map (fun x => x.fst) l)
h✝¹ :
  0 <
    List.length
      (List.map
        (fun l =>
          List.toAssocList
            (List.reverse
              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))))
        m.buckets.val.data)
i : Nat
h✝ :
  i <
    Array.size
      {
            size :=
              Nat.sum
                (List.map
                  ((fun x => List.length (AssocList.toList x)) ∘ fun l =>
                    List.toAssocList
                      (List.reverse
                        (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                          (AssocList.toList l))))
                  m.buckets.val.data),
            buckets :=
              {
                val :=
                  {
                    data :=
                      List.map
                        (fun l =>
                          List.toAssocList
                            (List.reverse
                              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                                (AssocList.toList l))))
                        m.buckets.val.data },
                property := h✝¹ } }.buckets.val
h : i < List.length m.buckets.val.data
this :
  ∀ (a : α × β),
    a ∈ AssocList.toList m.buckets.val[i] → USize.toNat (UInt64.toUSize (hash a.fst) % Array.size m.buckets.val) = i
⊢ ∀ (a : α × γ) (x : α × β),
    x ∈
        AssocList.toList
          (List.get m.buckets.val.data
            { val := i, isLt := (_ : { val := i, isLt := h✝ }.val < List.length m.buckets.val.data) }) →
      ∀ (x_1 : γ),
        f x.fst x.snd = some x_1 →
          (x.fst, x_1) = a → USize.toNat (UInt64.toUSize (hash a.fst) % List.length m.buckets.val.data) = i
rintro _ _ h' _ _ rfl
no goals
case refl.refine_2
α : Type u_1
β : Type u_2
γ : Type u_3
f : α → β → Option γ
inst✝¹ : BEq α
inst✝ : Hashable α
m : Imp α β
H : WF m
g₁ : AssocList α β → List (α × γ) :=
  fun l => List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l)
H1 :
  ∀ (l : AssocList α β) (n : ULift Nat) (acc : AssocList α γ),
    filterMap.go f acc l n =
      (List.toAssocList (List.reverse (g₁ l) ++ AssocList.toList acc), { down := n.down + List.length (g₁ l) })
g : AssocList α β → AssocList α γ := fun l => List.toAssocList (List.reverse (g₁ l))
M : Type (max u_3 u_1) → Type (max u_3 u_1) := StateT (ULift Nat) Id
H2 :
  ∀ (l : List (AssocList α β)) (n : ULift Nat),
    List.mapM (filterMap.go f AssocList.nil) l n =
      (List.map g l, { down := n.down + Nat.sum (List.map (fun x => List.length (AssocList.toList x)) (List.map g l)) })
H3 :
  ∀ (l : List (α × β)),
    List.Sublist
      (List.map (fun a => a.fst)
        (List.filterMap
          (fun x =>
            match x with
            | (a, b) => Option.map (fun x => (a, x)) (f a b))
          l))
      (List.map (fun x => x.fst) l)
h✝¹ :
  0 <
    List.length
      (List.map
        (fun l =>
          List.toAssocList
            (List.reverse
              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd)) (AssocList.toList l))))
        m.buckets.val.data)
i : Nat
h✝ :
  i <
    Array.size
      {
            size :=
              Nat.sum
                (List.map
                  ((fun x => List.length (AssocList.toList x)) ∘ fun l =>
                    List.toAssocList
                      (List.reverse
                        (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                          (AssocList.toList l))))
                  m.buckets.val.data),
            buckets :=
              {
                val :=
                  {
                    data :=
                      List.map
                        (fun l =>
                          List.toAssocList
                            (List.reverse
                              (List.filterMap (fun x => Option.map (fun x_1 => (x.fst, x_1)) (f x.fst x.snd))
                                (AssocList.toList l))))
                        m.buckets.val.data },
                property := h✝¹ } }.buckets.val
h : i < List.length m.buckets.val.data
this :
  ∀ (a : α × β),
    a ∈ AssocList.toList m.buckets.val[i] → USize.toNat (UInt64.toUSize (hash a.fst) % Array.size m.buckets.val) = i
x✝¹ : α × β
h' :
  x✝¹ ∈
    AssocList.toList
      (List.get m.buckets.val.data
        { val := i, isLt := (_ : { val := i, isLt := h✝ }.val < List.length m.buckets.val.data) })
x✝ : γ
a✝ : f x✝¹.fst x✝¹.snd = some x✝
⊢ USize.toNat (UInt64.toUSize (hash (x✝¹.fst, x✝).fst) % List.length m.buckets.val.data) = i
exact this _ h'