internlm/Lean-Github huggingface dataset:
Theorem: Permutation.nodup_inversions
Proof state before:
case refine_2.refl
n : Nat
x : Permutation n
k : Nat
hk : k < n
ivs : Array (Inversion x)
ivs_nodup : Array.Nodup ivs
ivs_lt : ∀ (iv : Inversion x), iv ∈ ivs → ↑iv.snd < k
⊢ Array.Nodup
      (Nat.fold' k
        (fun i ivs =>
          if h : x[↑i] > x[k] then
            Array.push ivs
              { fst := Fin.castLE (_ : ↑{ val := k, isLt := hk } ≤ n) i, snd := { val := k, isLt := hk },
                lt := (_ : ↑i < ↑{ val := k, isLt := hk }), inverted := h }
          else ivs)
        ivs) ∧
    ∀ (iv : Inversion x),
      iv ∈
          Nat.fold' k
            (fun i ivs =>
              if h : x[↑i] > x[k] then
                Array.push ivs
                  { fst := Fin.castLE (_ : ↑{ val := k, isLt := hk } ≤ n) i, snd := { val := k, isLt := hk },
                    lt := (_ : ↑i < ↑{ val := k, isLt := hk }), inverted := h }
              else ivs)
            ivs →
        ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < k
Tactic:
refine Nat.fold'_induction (motive := fun l (ivs' : Array (Inversion x)) => ivs'.Nodup ∧ ∀ iv, iv ∈ ivs' → iv.snd.1 < k ∨ (iv.snd.1 = k ∧ iv.fst.1 < l)) k _ ivs ?_ ?_
Proof state after:
case refine_2.refl.refine_1
n : Nat
x : Permutation n
k : Nat
hk : k < n
ivs : Array (Inversion x)
ivs_nodup : Array.Nodup ivs
ivs_lt : ∀ (iv : Inversion x), iv ∈ ivs → ↑iv.snd < k
⊢ (fun l ivs' => Array.Nodup ivs' ∧ ∀ (iv : Inversion x), iv ∈ ivs' → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < l) 0 ivs

case refine_2.refl.refine_2
n : Nat
x : Permutation n
k : Nat
hk : k < n
ivs : Array (Inversion x)
ivs_nodup : Array.Nodup ivs
ivs_lt : ∀ (iv : Inversion x), iv ∈ ivs → ↑iv.snd < k
⊢ ∀ (i : Nat) (hi : i < k) (a : Array (Inversion x)),
    (fun l ivs' => Array.Nodup ivs' ∧ ∀ (iv : Inversion x), iv ∈ ivs' → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < l) i a →
      (fun l ivs' => Array.Nodup ivs' ∧ ∀ (iv : Inversion x), iv ∈ ivs' → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < l)
        (i + 1)
        (if h : x[↑{ val := i, isLt := hi }] > x[k] then
          Array.push a
            { fst := Fin.castLE (_ : ↑{ val := k, isLt := hk } ≤ n) { val := i, isLt := hi },
              snd := { val := k, isLt := hk }, lt := (_ : ↑{ val := i, isLt := hi } < ↑{ val := k, isLt := hk }),
              inverted := h }
        else a)
Theorem: Permutation.nodup_inversions
Proof state before:
case refine_2.refl.refine_1
n : Nat
x : Permutation n
k : Nat
hk : k < n
ivs : Array (Inversion x)
ivs_nodup : Array.Nodup ivs
ivs_lt : ∀ (iv : Inversion x), iv ∈ ivs → ↑iv.snd < k
⊢ (fun l ivs' => Array.Nodup ivs' ∧ ∀ (iv : Inversion x), iv ∈ ivs' → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < l) 0 ivs

case refine_2.refl.refine_2
n : Nat
x : Permutation n
k : Nat
hk : k < n
ivs : Array (Inversion x)
ivs_nodup : Array.Nodup ivs
ivs_lt : ∀ (iv : Inversion x), iv ∈ ivs → ↑iv.snd < k
⊢ ∀ (i : Nat) (hi : i < k) (a : Array (Inversion x)),
    (fun l ivs' => Array.Nodup ivs' ∧ ∀ (iv : Inversion x), iv ∈ ivs' → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < l) i a →
      (fun l ivs' => Array.Nodup ivs' ∧ ∀ (iv : Inversion x), iv ∈ ivs' → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < l)
        (i + 1)
        (if h : x[↑{ val := i, isLt := hi }] > x[k] then
          Array.push a
            { fst := Fin.castLE (_ : ↑{ val := k, isLt := hk } ≤ n) { val := i, isLt := hi },
              snd := { val := k, isLt := hk }, lt := (_ : ↑{ val := i, isLt := hi } < ↑{ val := k, isLt := hk }),
              inverted := h }
        else a)
Tactic:
all_goals simp
Proof state after:
case refine_2.refl.refine_1
n : Nat
x : Permutation n
k : Nat
hk : k < n
ivs : Array (Inversion x)
ivs_nodup : Array.Nodup ivs
ivs_lt : ∀ (iv : Inversion x), iv ∈ ivs → ↑iv.snd < k
⊢ Array.Nodup ivs ∧ ∀ (iv : Inversion x), iv ∈ ivs → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < 0

case refine_2.refl.refine_2
n : Nat
x : Permutation n
k : Nat
hk : k < n
ivs : Array (Inversion x)
ivs_nodup : Array.Nodup ivs
ivs_lt : ∀ (iv : Inversion x), iv ∈ ivs → ↑iv.snd < k
⊢ ∀ (i : Nat) (hi : i < k) (a : Array (Inversion x)),
    Array.Nodup a →
      (∀ (iv : Inversion x), iv ∈ a → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < i) →
        Array.Nodup
            (if h : x[i] > x[k] then
              Array.push a
                { fst := { val := i, isLt := (_ : i < n) }, snd := { val := k, isLt := hk },
                  lt := (_ : { val := i, isLt := (_ : i < n) } < { val := k, isLt := hk }),
                  inverted := (_ : x[↑{ val := i, isLt := (_ : i < n) }] > x[↑{ val := k, isLt := hk }]) }
            else a) ∧
          ∀ (iv : Inversion x),
            (iv ∈
                if h : x[i] > x[k] then
                  Array.push a
                    { fst := { val := i, isLt := (_ : i < n) }, snd := { val := k, isLt := hk },
                      lt := (_ : { val := i, isLt := (_ : i < n) } < { val := k, isLt := hk }),
                      inverted := (_ : x[↑{ val := i, isLt := (_ : i < n) }] > x[↑{ val := k, isLt := hk }]) }
                else a) →
              ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < i + 1
Theorem: Permutation.nodup_inversions
Proof state before:
case refine_2.refl.refine_1
n : Nat
x : Permutation n
k : Nat
hk : k < n
ivs : Array (Inversion x)
ivs_nodup : Array.Nodup ivs
ivs_lt : ∀ (iv : Inversion x), iv ∈ ivs → ↑iv.snd < k
⊢ Array.Nodup ivs ∧ ∀ (iv : Inversion x), iv ∈ ivs → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < 0

case refine_2.refl.refine_2
n : Nat
x : Permutation n
k : Nat
hk : k < n
ivs : Array (Inversion x)
ivs_nodup : Array.Nodup ivs
ivs_lt : ∀ (iv : Inversion x), iv ∈ ivs → ↑iv.snd < k
⊢ ∀ (i : Nat) (hi : i < k) (a : Array (Inversion x)),
    Array.Nodup a →
      (∀ (iv : Inversion x), iv ∈ a → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < i) →
        Array.Nodup
            (if h : x[i] > x[k] then
              Array.push a
                { fst := { val := i, isLt := (_ : i < n) }, snd := { val := k, isLt := hk },
                  lt := (_ : { val := i, isLt := (_ : i < n) } < { val := k, isLt := hk }),
                  inverted := (_ : x[↑{ val := i, isLt := (_ : i < n) }] > x[↑{ val := k, isLt := hk }]) }
            else a) ∧
          ∀ (iv : Inversion x),
            (iv ∈
                if h : x[i] > x[k] then
                  Array.push a
                    { fst := { val := i, isLt := (_ : i < n) }, snd := { val := k, isLt := hk },
                      lt := (_ : { val := i, isLt := (_ : i < n) } < { val := k, isLt := hk }),
                      inverted := (_ : x[↑{ val := i, isLt := (_ : i < n) }] > x[↑{ val := k, isLt := hk }]) }
                else a) →
              ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < i + 1
Tactic:
. exact And.intro ivs_nodup fun iv hiv => Or.inl <| ivs_lt iv hiv
Proof state after:
case refine_2.refl.refine_2
n : Nat
x : Permutation n
k : Nat
hk : k < n
ivs : Array (Inversion x)
ivs_nodup : Array.Nodup ivs
ivs_lt : ∀ (iv : Inversion x), iv ∈ ivs → ↑iv.snd < k
⊢ ∀ (i : Nat) (hi : i < k) (a : Array (Inversion x)),
    Array.Nodup a →
      (∀ (iv : Inversion x), iv ∈ a → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < i) →
        Array.Nodup
            (if h : x[i] > x[k] then
              Array.push a
                { fst := { val := i, isLt := (_ : i < n) }, snd := { val := k, isLt := hk },
                  lt := (_ : { val := i, isLt := (_ : i < n) } < { val := k, isLt := hk }),
                  inverted := (_ : x[↑{ val := i, isLt := (_ : i < n) }] > x[↑{ val := k, isLt := hk }]) }
            else a) ∧
          ∀ (iv : Inversion x),
            (iv ∈
                if h : x[i] > x[k] then
                  Array.push a
                    { fst := { val := i, isLt := (_ : i < n) }, snd := { val := k, isLt := hk },
                      lt := (_ : { val := i, isLt := (_ : i < n) } < { val := k, isLt := hk }),
                      inverted := (_ : x[↑{ val := i, isLt := (_ : i < n) }] > x[↑{ val := k, isLt := hk }]) }
                else a) →
              ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < i + 1
Theorem: Permutation.nodup_inversions
Proof state before:
case refine_2.refl.refine_2
n : Nat
x : Permutation n
k : Nat
hk : k < n
ivs : Array (Inversion x)
ivs_nodup : Array.Nodup ivs
ivs_lt : ∀ (iv : Inversion x), iv ∈ ivs → ↑iv.snd < k
⊢ ∀ (i : Nat) (hi : i < k) (a : Array (Inversion x)),
    Array.Nodup a →
      (∀ (iv : Inversion x), iv ∈ a → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < i) →
        Array.Nodup
            (if h : x[i] > x[k] then
              Array.push a
                { fst := { val := i, isLt := (_ : i < n) }, snd := { val := k, isLt := hk },
                  lt := (_ : { val := i, isLt := (_ : i < n) } < { val := k, isLt := hk }),
                  inverted := (_ : x[↑{ val := i, isLt := (_ : i < n) }] > x[↑{ val := k, isLt := hk }]) }
            else a) ∧
          ∀ (iv : Inversion x),
            (iv ∈
                if h : x[i] > x[k] then
                  Array.push a
                    { fst := { val := i, isLt := (_ : i < n) }, snd := { val := k, isLt := hk },
                      lt := (_ : { val := i, isLt := (_ : i < n) } < { val := k, isLt := hk }),
                      inverted := (_ : x[↑{ val := i, isLt := (_ : i < n) }] > x[↑{ val := k, isLt := hk }]) }
                else a) →
              ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < i + 1
Tactic:
. intro l hl ivs' ivs'_nodup ivs'_lt
  if hx : x[l]'(Nat.lt_trans hl hk) > x[k] then
    simp only [dif_pos hx, Array.nodup_push, Array.mem_push, ivs'_nodup, true_and]
    constructor
    . intro h
      specialize ivs'_lt _ h; dsimp at ivs'_lt
      refine ivs'_lt.elim ?_ ?_
      . exact Nat.lt_irrefl k
      . intro h; exact Nat.lt_irrefl l h.2
    . intro iv hiv
      cases hiv with
      | inl hmem =>
        refine Or.imp_right ?_ <| ivs'_lt iv hmem
        exact And.imp_right Nat.le.step
      | inr heq =>
        cases heq; dsimp
        exact Or.inr ⟨rfl, l.lt_succ_self⟩
  else
    simp only [dif_neg hx]
    apply And.intro ivs'_nodup
    intro iv hiv; specialize ivs'_lt iv hiv
    refine Or.imp_right ?_ ivs'_lt
    exact And.imp_right Nat.le.step
Proof state after:
no goals
Theorem: Permutation.nodup_inversions
Proof state before:
n : Nat
x : Permutation n
k : Nat
hk : k < n
ivs : Array (Inversion x)
ivs_nodup : Array.Nodup ivs
ivs_lt : ∀ (iv : Inversion x), iv ∈ ivs → ↑iv.snd < k
ivs' : Array (Inversion x)
hivs' :
  Nat.fold' k
      (fun i ivs =>
        if h : x[↑i] > x[k] then
          Array.push ivs
            { fst := Fin.castLE (_ : ↑{ val := k, isLt := hk } ≤ n) i, snd := { val := k, isLt := hk },
              lt := (_ : ↑i < ↑{ val := k, isLt := hk }), inverted := h }
        else ivs)
      ivs =
    ivs'
this : Array.Nodup ivs' ∧ ∀ (iv : Inversion x), iv ∈ ivs' → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < k
⊢ Array.Nodup ivs' ∧ ∀ (iv : Inversion x), iv ∈ ivs' → ↑iv.snd < k + 1
Tactic:
refine And.imp_right ?_ this
Proof state after:
n : Nat
x : Permutation n
k : Nat
hk : k < n
ivs : Array (Inversion x)
ivs_nodup : Array.Nodup ivs
ivs_lt : ∀ (iv : Inversion x), iv ∈ ivs → ↑iv.snd < k
ivs' : Array (Inversion x)
hivs' :
  Nat.fold' k
      (fun i ivs =>
        if h : x[↑i] > x[k] then
          Array.push ivs
            { fst := Fin.castLE (_ : ↑{ val := k, isLt := hk } ≤ n) i, snd := { val := k, isLt := hk },
              lt := (_ : ↑i < ↑{ val := k, isLt := hk }), inverted := h }
        else ivs)
      ivs =
    ivs'
this : Array.Nodup ivs' ∧ ∀ (iv : Inversion x), iv ∈ ivs' → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < k
⊢ (∀ (iv : Inversion x), iv ∈ ivs' → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < k) →
    ∀ (iv : Inversion x), iv ∈ ivs' → ↑iv.snd < k + 1
Theorem: Permutation.nodup_inversions
Proof state before:
n : Nat
x : Permutation n
k : Nat
hk : k < n
ivs : Array (Inversion x)
ivs_nodup : Array.Nodup ivs
ivs_lt : ∀ (iv : Inversion x), iv ∈ ivs → ↑iv.snd < k
ivs' : Array (Inversion x)
hivs' :
  Nat.fold' k
      (fun i ivs =>
        if h : x[↑i] > x[k] then
          Array.push ivs
            { fst := Fin.castLE (_ : ↑{ val := k, isLt := hk } ≤ n) i, snd := { val := k, isLt := hk },
              lt := (_ : ↑i < ↑{ val := k, isLt := hk }), inverted := h }
        else ivs)
      ivs =
    ivs'
this : Array.Nodup ivs' ∧ ∀ (iv : Inversion x), iv ∈ ivs' → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < k
⊢ (∀ (iv : Inversion x), iv ∈ ivs' → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < k) →
    ∀ (iv : Inversion x), iv ∈ ivs' → ↑iv.snd < k + 1
Tactic:
intro hivs' iv hiv
Proof state after:
n : Nat
x : Permutation n
k : Nat
hk : k < n
ivs : Array (Inversion x)
ivs_nodup : Array.Nodup ivs
ivs_lt : ∀ (iv : Inversion x), iv ∈ ivs → ↑iv.snd < k
ivs' : Array (Inversion x)
hivs'✝ :
  Nat.fold' k
      (fun i ivs =>
        if h : x[↑i] > x[k] then
          Array.push ivs
            { fst := Fin.castLE (_ : ↑{ val := k, isLt := hk } ≤ n) i, snd := { val := k, isLt := hk },
              lt := (_ : ↑i < ↑{ val := k, isLt := hk }), inverted := h }
        else ivs)
      ivs =
    ivs'
this : Array.Nodup ivs' ∧ ∀ (iv : Inversion x), iv ∈ ivs' → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < k
hivs' : ∀ (iv : Inversion x), iv ∈ ivs' → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < k
iv : Inversion x
hiv : iv ∈ ivs'
⊢ ↑iv.snd < k + 1
Theorem: Permutation.nodup_inversions
Proof state before:
n : Nat
x : Permutation n
k : Nat
hk : k < n
ivs : Array (Inversion x)
ivs_nodup : Array.Nodup ivs
ivs_lt : ∀ (iv : Inversion x), iv ∈ ivs → ↑iv.snd < k
ivs' : Array (Inversion x)
hivs'✝ :
  Nat.fold' k
      (fun i ivs =>
        if h : x[↑i] > x[k] then
          Array.push ivs
            { fst := Fin.castLE (_ : ↑{ val := k, isLt := hk } ≤ n) i, snd := { val := k, isLt := hk },
              lt := (_ : ↑i < ↑{ val := k, isLt := hk }), inverted := h }
        else ivs)
      ivs =
    ivs'
this : Array.Nodup ivs' ∧ ∀ (iv : Inversion x), iv ∈ ivs' → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < k
hivs' : ∀ (iv : Inversion x), iv ∈ ivs' → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < k
iv : Inversion x
hiv : iv ∈ ivs'
⊢ ↑iv.snd < k + 1
Tactic:
apply Nat.succ_le_succ
Proof state after:
case a
n : Nat
x : Permutation n
k : Nat
hk : k < n
ivs : Array (Inversion x)
ivs_nodup : Array.Nodup ivs
ivs_lt : ∀ (iv : Inversion x), iv ∈ ivs → ↑iv.snd < k
ivs' : Array (Inversion x)
hivs'✝ :
  Nat.fold' k
      (fun i ivs =>
        if h : x[↑i] > x[k] then
          Array.push ivs
            { fst := Fin.castLE (_ : ↑{ val := k, isLt := hk } ≤ n) i, snd := { val := k, isLt := hk },
              lt := (_ : ↑i < ↑{ val := k, isLt := hk }), inverted := h }
        else ivs)
      ivs =
    ivs'
this : Array.Nodup ivs' ∧ ∀ (iv : Inversion x), iv ∈ ivs' → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < k
hivs' : ∀ (iv : Inversion x), iv ∈ ivs' → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < k
iv : Inversion x
hiv : iv ∈ ivs'
⊢ ↑iv.snd ≤ k
Theorem: Permutation.nodup_inversions
Proof state before:
case a
n : Nat
x : Permutation n
k : Nat
hk : k < n
ivs : Array (Inversion x)
ivs_nodup : Array.Nodup ivs
ivs_lt : ∀ (iv : Inversion x), iv ∈ ivs → ↑iv.snd < k
ivs' : Array (Inversion x)
hivs'✝ :
  Nat.fold' k
      (fun i ivs =>
        if h : x[↑i] > x[k] then
          Array.push ivs
            { fst := Fin.castLE (_ : ↑{ val := k, isLt := hk } ≤ n) i, snd := { val := k, isLt := hk },
              lt := (_ : ↑i < ↑{ val := k, isLt := hk }), inverted := h }
        else ivs)
      ivs =
    ivs'
this : Array.Nodup ivs' ∧ ∀ (iv : Inversion x), iv ∈ ivs' → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < k
hivs' : ∀ (iv : Inversion x), iv ∈ ivs' → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < k
iv : Inversion x
hiv : iv ∈ ivs'
⊢ ↑iv.snd ≤ k
Tactic:
apply Nat.le_iff_lt_or_eq.mpr
Proof state after:
case a
n : Nat
x : Permutation n
k : Nat
hk : k < n
ivs : Array (Inversion x)
ivs_nodup : Array.Nodup ivs
ivs_lt : ∀ (iv : Inversion x), iv ∈ ivs → ↑iv.snd < k
ivs' : Array (Inversion x)
hivs'✝ :
  Nat.fold' k
      (fun i ivs =>
        if h : x[↑i] > x[k] then
          Array.push ivs
            { fst := Fin.castLE (_ : ↑{ val := k, isLt := hk } ≤ n) i, snd := { val := k, isLt := hk },
              lt := (_ : ↑i < ↑{ val := k, isLt := hk }), inverted := h }
        else ivs)
      ivs =
    ivs'
this : Array.Nodup ivs' ∧ ∀ (iv : Inversion x), iv ∈ ivs' → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < k
hivs' : ∀ (iv : Inversion x), iv ∈ ivs' → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < k
iv : Inversion x
hiv : iv ∈ ivs'
⊢ ↑iv.snd < k ∨ ↑iv.snd = k
Theorem: Permutation.nodup_inversions
Proof state before:
case a
n : Nat
x : Permutation n
k : Nat
hk : k < n
ivs : Array (Inversion x)
ivs_nodup : Array.Nodup ivs
ivs_lt : ∀ (iv : Inversion x), iv ∈ ivs → ↑iv.snd < k
ivs' : Array (Inversion x)
hivs'✝ :
  Nat.fold' k
      (fun i ivs =>
        if h : x[↑i] > x[k] then
          Array.push ivs
            { fst := Fin.castLE (_ : ↑{ val := k, isLt := hk } ≤ n) i, snd := { val := k, isLt := hk },
              lt := (_ : ↑i < ↑{ val := k, isLt := hk }), inverted := h }
        else ivs)
      ivs =
    ivs'
this : Array.Nodup ivs' ∧ ∀ (iv : Inversion x), iv ∈ ivs' → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < k
hivs' : ∀ (iv : Inversion x), iv ∈ ivs' → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < k
iv : Inversion x
hiv : iv ∈ ivs'
⊢ ↑iv.snd < k ∨ ↑iv.snd = k
Tactic:
exact Or.imp_right And.left (hivs' iv hiv)
Proof state after:
no goals
Theorem: Permutation.nodup_inversions
Proof state before:
case refine_2.refl.refine_2
n : Nat
x : Permutation n
k : Nat
hk : k < n
ivs : Array (Inversion x)
ivs_nodup : Array.Nodup ivs
ivs_lt : ∀ (iv : Inversion x), iv ∈ ivs → ↑iv.snd < k
⊢ ∀ (i : Nat) (hi : i < k) (a : Array (Inversion x)),
    (fun l ivs' => Array.Nodup ivs' ∧ ∀ (iv : Inversion x), iv ∈ ivs' → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < l) i a →
      (fun l ivs' => Array.Nodup ivs' ∧ ∀ (iv : Inversion x), iv ∈ ivs' → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < l)
        (i + 1)
        (if h : x[↑{ val := i, isLt := hi }] > x[k] then
          Array.push a
            { fst := Fin.castLE (_ : ↑{ val := k, isLt := hk } ≤ n) { val := i, isLt := hi },
              snd := { val := k, isLt := hk }, lt := (_ : ↑{ val := i, isLt := hi } < ↑{ val := k, isLt := hk }),
              inverted := h }
        else a)
Tactic:
simp
Proof state after:
case refine_2.refl.refine_2
n : Nat
x : Permutation n
k : Nat
hk : k < n
ivs : Array (Inversion x)
ivs_nodup : Array.Nodup ivs
ivs_lt : ∀ (iv : Inversion x), iv ∈ ivs → ↑iv.snd < k
⊢ ∀ (i : Nat) (hi : i < k) (a : Array (Inversion x)),
    Array.Nodup a →
      (∀ (iv : Inversion x), iv ∈ a → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < i) →
        Array.Nodup
            (if h : x[i] > x[k] then
              Array.push a
                { fst := { val := i, isLt := (_ : i < n) }, snd := { val := k, isLt := hk },
                  lt := (_ : { val := i, isLt := (_ : i < n) } < { val := k, isLt := hk }),
                  inverted := (_ : x[↑{ val := i, isLt := (_ : i < n) }] > x[↑{ val := k, isLt := hk }]) }
            else a) ∧
          ∀ (iv : Inversion x),
            (iv ∈
                if h : x[i] > x[k] then
                  Array.push a
                    { fst := { val := i, isLt := (_ : i < n) }, snd := { val := k, isLt := hk },
                      lt := (_ : { val := i, isLt := (_ : i < n) } < { val := k, isLt := hk }),
                      inverted := (_ : x[↑{ val := i, isLt := (_ : i < n) }] > x[↑{ val := k, isLt := hk }]) }
                else a) →
              ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < i + 1
Theorem: Permutation.nodup_inversions
Proof state before:
case refine_2.refl.refine_1
n : Nat
x : Permutation n
k : Nat
hk : k < n
ivs : Array (Inversion x)
ivs_nodup : Array.Nodup ivs
ivs_lt : ∀ (iv : Inversion x), iv ∈ ivs → ↑iv.snd < k
⊢ Array.Nodup ivs ∧ ∀ (iv : Inversion x), iv ∈ ivs → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < 0
Tactic:
exact And.intro ivs_nodup fun iv hiv => Or.inl <| ivs_lt iv hiv
Proof state after:
no goals
Theorem: Permutation.nodup_inversions
Proof state before:
case refine_2.refl.refine_2
n : Nat
x : Permutation n
k : Nat
hk : k < n
ivs : Array (Inversion x)
ivs_nodup : Array.Nodup ivs
ivs_lt : ∀ (iv : Inversion x), iv ∈ ivs → ↑iv.snd < k
⊢ ∀ (i : Nat) (hi : i < k) (a : Array (Inversion x)),
    Array.Nodup a →
      (∀ (iv : Inversion x), iv ∈ a → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < i) →
        Array.Nodup
            (if h : x[i] > x[k] then
              Array.push a
                { fst := { val := i, isLt := (_ : i < n) }, snd := { val := k, isLt := hk },
                  lt := (_ : { val := i, isLt := (_ : i < n) } < { val := k, isLt := hk }),
                  inverted := (_ : x[↑{ val := i, isLt := (_ : i < n) }] > x[↑{ val := k, isLt := hk }]) }
            else a) ∧
          ∀ (iv : Inversion x),
            (iv ∈
                if h : x[i] > x[k] then
                  Array.push a
                    { fst := { val := i, isLt := (_ : i < n) }, snd := { val := k, isLt := hk },
                      lt := (_ : { val := i, isLt := (_ : i < n) } < { val := k, isLt := hk }),
                      inverted := (_ : x[↑{ val := i, isLt := (_ : i < n) }] > x[↑{ val := k, isLt := hk }]) }
                else a) →
              ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < i + 1
Tactic:
intro l hl ivs' ivs'_nodup ivs'_lt
Proof state after:
case refine_2.refl.refine_2
n : Nat
x : Permutation n
k : Nat
hk : k < n
ivs : Array (Inversion x)
ivs_nodup : Array.Nodup ivs
ivs_lt : ∀ (iv : Inversion x), iv ∈ ivs → ↑iv.snd < k
l : Nat
hl : l < k
ivs' : Array (Inversion x)
ivs'_nodup : Array.Nodup ivs'
ivs'_lt : ∀ (iv : Inversion x), iv ∈ ivs' → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < l
⊢ Array.Nodup
      (if h : x[l] > x[k] then
        Array.push ivs'
          { fst := { val := l, isLt := (_ : l < n) }, snd := { val := k, isLt := hk },
            lt := (_ : { val := l, isLt := (_ : l < n) } < { val := k, isLt := hk }),
            inverted := (_ : x[↑{ val := l, isLt := (_ : l < n) }] > x[↑{ val := k, isLt := hk }]) }
      else ivs') ∧
    ∀ (iv : Inversion x),
      (iv ∈
          if h : x[l] > x[k] then
            Array.push ivs'
              { fst := { val := l, isLt := (_ : l < n) }, snd := { val := k, isLt := hk },
                lt := (_ : { val := l, isLt := (_ : l < n) } < { val := k, isLt := hk }),
                inverted := (_ : x[↑{ val := l, isLt := (_ : l < n) }] > x[↑{ val := k, isLt := hk }]) }
          else ivs') →
        ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < l + 1
Theorem: Permutation.nodup_inversions
Proof state before:
case refine_2.refl.refine_2
n : Nat
x : Permutation n
k : Nat
hk : k < n
ivs : Array (Inversion x)
ivs_nodup : Array.Nodup ivs
ivs_lt : ∀ (iv : Inversion x), iv ∈ ivs → ↑iv.snd < k
l : Nat
hl : l < k
ivs' : Array (Inversion x)
ivs'_nodup : Array.Nodup ivs'
ivs'_lt : ∀ (iv : Inversion x), iv ∈ ivs' → ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < l
⊢ Array.Nodup
      (if h : x[l] > x[k] then
        Array.push ivs'
          { fst := { val := l, isLt := (_ : l < n) }, snd := { val := k, isLt := hk },
            lt := (_ : { val := l, isLt := (_ : l < n) } < { val := k, isLt := hk }),
            inverted := (_ : x[↑{ val := l, isLt := (_ : l < n) }] > x[↑{ val := k, isLt := hk }]) }
      else ivs') ∧
    ∀ (iv : Inversion x),
      (iv ∈
          if h : x[l] > x[k] then
            Array.push ivs'
              { fst := { val := l, isLt := (_ : l < n) }, snd := { val := k, isLt := hk },
                lt := (_ : { val := l, isLt := (_ : l < n) } < { val := k, isLt := hk }),
                inverted := (_ : x[↑{ val := l, isLt := (_ : l < n) }] > x[↑{ val := k, isLt := hk }]) }
          else ivs') →
        ↑iv.snd < k ∨ ↑iv.snd = k ∧ ↑iv.fst < l + 1
Tactic:
if hx : x[l]'(Nat.lt_trans hl hk) > x[k] then
  simp only [dif_pos hx, Array.nodup_push, Array.mem_push, ivs'_nodup, true_and]
  constructor
  . intro h
    specialize ivs'_lt _ h; dsimp at ivs'_lt
    refine ivs'_lt.elim ?_ ?_
    . exact Nat.lt_irrefl k
    . intro h; exact Nat.lt_irrefl l h.2
  . intro iv hiv
    cases hiv with
    | inl hmem =>
      refine Or.imp_right ?_ <| ivs'_lt iv hmem
      exact And.imp_right Nat.le.step
    | inr heq =>
      cases heq; dsimp
      exact Or.inr ⟨rfl, l.lt_succ_self⟩
else
  simp only [dif_neg hx]
  apply And.intro ivs'_nodup
  intro iv hiv; specialize ivs'_lt iv hiv
  refine Or.imp_right ?_ ivs'_lt
  exact And.imp_right Nat.le.step
Proof state after:
no goals