/-
Copyright (c) 2017 Johannes Hölzl. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Johannes Hölzl, Mario Carneiro, Yury Kudryashov

! This file was ported from Lean 3 source module topology.algebra.order.extend_from
! leanprover-community/mathlib commit 3e32bc908f617039c74c06ea9a897e30c30803c2
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
import Mathbin.Topology.Order.Basic
import Mathbin.Topology.ExtendFrom

/-!
# Lemmas about `extend_from` in an order topology.

> THIS FILE IS SYNCHRONIZED WITH MATHLIB4.
> Any changes to this file require a corresponding PR to mathlib4.
-/

open Filter Set TopologicalSpace

open Topology Classical

universe u v

variable {α : Type u} {β : Type v}

/- warning: continuous_on_Icc_extend_from_Ioo -> continuousOn_Icc_extendFrom_Ioo is a dubious translation:
lean 3 declaration is
  forall {α : Type.{u1}} {β : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} α] [_inst_2 : LinearOrder.{u1} α] [_inst_3 : DenselyOrdered.{u1} α (Preorder.toLT.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_2)))))] [_inst_4 : OrderTopology.{u1} α _inst_1 (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_2))))] [_inst_5 : TopologicalSpace.{u2} β] [_inst_6 : RegularSpace.{u2} β _inst_5] {f : α -> β} {a : α} {b : α} {la : β} {lb : β}, (Ne.{succ u1} α a b) -> (ContinuousOn.{u1, u2} α β _inst_1 _inst_5 f (Set.Ioo.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_2)))) a b)) -> (Filter.Tendsto.{u1, u2} α β f (nhdsWithin.{u1} α _inst_1 a (Set.Ioi.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_2)))) a)) (nhds.{u2} β _inst_5 la)) -> (Filter.Tendsto.{u1, u2} α β f (nhdsWithin.{u1} α _inst_1 b (Set.Iio.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_2)))) b)) (nhds.{u2} β _inst_5 lb)) -> (ContinuousOn.{u1, u2} α β _inst_1 _inst_5 (extendFrom.{u1, u2} α β _inst_1 _inst_5 (Set.Ioo.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_2)))) a b) f) (Set.Icc.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_2)))) a b))
but is expected to have type
  forall {α : Type.{u2}} {β : Type.{u1}} [_inst_1 : TopologicalSpace.{u2} α] [_inst_2 : LinearOrder.{u2} α] [_inst_3 : DenselyOrdered.{u2} α (Preorder.toLT.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_2))))))] [_inst_4 : OrderTopology.{u2} α _inst_1 (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_2)))))] [_inst_5 : TopologicalSpace.{u1} β] [_inst_6 : RegularSpace.{u1} β _inst_5] {f : α -> β} {a : α} {b : α} {la : β} {lb : β}, (Ne.{succ u2} α a b) -> (ContinuousOn.{u2, u1} α β _inst_1 _inst_5 f (Set.Ioo.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_2))))) a b)) -> (Filter.Tendsto.{u2, u1} α β f (nhdsWithin.{u2} α _inst_1 a (Set.Ioi.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_2))))) a)) (nhds.{u1} β _inst_5 la)) -> (Filter.Tendsto.{u2, u1} α β f (nhdsWithin.{u2} α _inst_1 b (Set.Iio.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_2))))) b)) (nhds.{u1} β _inst_5 lb)) -> (ContinuousOn.{u2, u1} α β _inst_1 _inst_5 (extendFrom.{u2, u1} α β _inst_1 _inst_5 (Set.Ioo.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_2))))) a b) f) (Set.Icc.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_2))))) a b))
Case conversion may be inaccurate. Consider using '#align continuous_on_Icc_extend_from_Ioo continuousOn_Icc_extendFrom_Iooₓ'. -/
theorem continuousOn_Icc_extendFrom_Ioo [TopologicalSpace α] [LinearOrder α] [DenselyOrdered α]
    [OrderTopology α] [TopologicalSpace β] [RegularSpace β] {f : α → β} {a b : α} {la lb : β}
    (hab : a ≠ b) (hf : ContinuousOn f (Ioo a b)) (ha : Tendsto f (𝓝[>] a) (𝓝 la))
    (hb : Tendsto f (𝓝[<] b) (𝓝 lb)) : ContinuousOn (extendFrom (Ioo a b) f) (Icc a b) :=
  by
  apply continuousOn_extendFrom
  · rw [closure_Ioo hab]
  · intro x x_in
    rcases eq_endpoints_or_mem_Ioo_of_mem_Icc x_in with (rfl | rfl | h)
    · exact ⟨la, ha.mono_left <| nhdsWithin_mono _ Ioo_subset_Ioi_self⟩
    · exact ⟨lb, hb.mono_left <| nhdsWithin_mono _ Ioo_subset_Iio_self⟩
    · use f x, hf x h
#align continuous_on_Icc_extend_from_Ioo continuousOn_Icc_extendFrom_Ioo

/- warning: eq_lim_at_left_extend_from_Ioo -> eq_lim_at_left_extendFrom_Ioo is a dubious translation:
lean 3 declaration is
  forall {α : Type.{u1}} {β : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} α] [_inst_2 : LinearOrder.{u1} α] [_inst_3 : DenselyOrdered.{u1} α (Preorder.toLT.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_2)))))] [_inst_4 : OrderTopology.{u1} α _inst_1 (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_2))))] [_inst_5 : TopologicalSpace.{u2} β] [_inst_6 : T2Space.{u2} β _inst_5] {f : α -> β} {a : α} {b : α} {la : β}, (LT.lt.{u1} α (Preorder.toLT.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_2))))) a b) -> (Filter.Tendsto.{u1, u2} α β f (nhdsWithin.{u1} α _inst_1 a (Set.Ioi.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_2)))) a)) (nhds.{u2} β _inst_5 la)) -> (Eq.{succ u2} β (extendFrom.{u1, u2} α β _inst_1 _inst_5 (Set.Ioo.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_2)))) a b) f a) la)
but is expected to have type
  forall {α : Type.{u2}} {β : Type.{u1}} [_inst_1 : TopologicalSpace.{u2} α] [_inst_2 : LinearOrder.{u2} α] [_inst_3 : DenselyOrdered.{u2} α (Preorder.toLT.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_2))))))] [_inst_4 : OrderTopology.{u2} α _inst_1 (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_2)))))] [_inst_5 : TopologicalSpace.{u1} β] [_inst_6 : T2Space.{u1} β _inst_5] {f : α -> β} {a : α} {b : α} {la : β}, (LT.lt.{u2} α (Preorder.toLT.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_2)))))) a b) -> (Filter.Tendsto.{u2, u1} α β f (nhdsWithin.{u2} α _inst_1 a (Set.Ioi.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_2))))) a)) (nhds.{u1} β _inst_5 la)) -> (Eq.{succ u1} β (extendFrom.{u2, u1} α β _inst_1 _inst_5 (Set.Ioo.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_2))))) a b) f a) la)
Case conversion may be inaccurate. Consider using '#align eq_lim_at_left_extend_from_Ioo eq_lim_at_left_extendFrom_Iooₓ'. -/
theorem eq_lim_at_left_extendFrom_Ioo [TopologicalSpace α] [LinearOrder α] [DenselyOrdered α]
    [OrderTopology α] [TopologicalSpace β] [T2Space β] {f : α → β} {a b : α} {la : β} (hab : a < b)
    (ha : Tendsto f (𝓝[>] a) (𝓝 la)) : extendFrom (Ioo a b) f a = la :=
  by
  apply extendFrom_eq
  · rw [closure_Ioo hab.ne]
    simp only [le_of_lt hab, left_mem_Icc, right_mem_Icc]
  · simpa [hab]
#align eq_lim_at_left_extend_from_Ioo eq_lim_at_left_extendFrom_Ioo

/- warning: eq_lim_at_right_extend_from_Ioo -> eq_lim_at_right_extendFrom_Ioo is a dubious translation:
lean 3 declaration is
  forall {α : Type.{u1}} {β : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} α] [_inst_2 : LinearOrder.{u1} α] [_inst_3 : DenselyOrdered.{u1} α (Preorder.toLT.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_2)))))] [_inst_4 : OrderTopology.{u1} α _inst_1 (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_2))))] [_inst_5 : TopologicalSpace.{u2} β] [_inst_6 : T2Space.{u2} β _inst_5] {f : α -> β} {a : α} {b : α} {lb : β}, (LT.lt.{u1} α (Preorder.toLT.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_2))))) a b) -> (Filter.Tendsto.{u1, u2} α β f (nhdsWithin.{u1} α _inst_1 b (Set.Iio.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_2)))) b)) (nhds.{u2} β _inst_5 lb)) -> (Eq.{succ u2} β (extendFrom.{u1, u2} α β _inst_1 _inst_5 (Set.Ioo.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_2)))) a b) f b) lb)
but is expected to have type
  forall {α : Type.{u2}} {β : Type.{u1}} [_inst_1 : TopologicalSpace.{u2} α] [_inst_2 : LinearOrder.{u2} α] [_inst_3 : DenselyOrdered.{u2} α (Preorder.toLT.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_2))))))] [_inst_4 : OrderTopology.{u2} α _inst_1 (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_2)))))] [_inst_5 : TopologicalSpace.{u1} β] [_inst_6 : T2Space.{u1} β _inst_5] {f : α -> β} {a : α} {b : α} {lb : β}, (LT.lt.{u2} α (Preorder.toLT.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_2)))))) a b) -> (Filter.Tendsto.{u2, u1} α β f (nhdsWithin.{u2} α _inst_1 b (Set.Iio.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_2))))) b)) (nhds.{u1} β _inst_5 lb)) -> (Eq.{succ u1} β (extendFrom.{u2, u1} α β _inst_1 _inst_5 (Set.Ioo.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_2))))) a b) f b) lb)
Case conversion may be inaccurate. Consider using '#align eq_lim_at_right_extend_from_Ioo eq_lim_at_right_extendFrom_Iooₓ'. -/
theorem eq_lim_at_right_extendFrom_Ioo [TopologicalSpace α] [LinearOrder α] [DenselyOrdered α]
    [OrderTopology α] [TopologicalSpace β] [T2Space β] {f : α → β} {a b : α} {lb : β} (hab : a < b)
    (hb : Tendsto f (𝓝[<] b) (𝓝 lb)) : extendFrom (Ioo a b) f b = lb :=
  by
  apply extendFrom_eq
  · rw [closure_Ioo hab.ne]
    simp only [le_of_lt hab, left_mem_Icc, right_mem_Icc]
  · simpa [hab]
#align eq_lim_at_right_extend_from_Ioo eq_lim_at_right_extendFrom_Ioo

/- warning: continuous_on_Ico_extend_from_Ioo -> continuousOn_Ico_extendFrom_Ioo is a dubious translation:
lean 3 declaration is
  forall {α : Type.{u1}} {β : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} α] [_inst_2 : LinearOrder.{u1} α] [_inst_3 : DenselyOrdered.{u1} α (Preorder.toLT.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_2)))))] [_inst_4 : OrderTopology.{u1} α _inst_1 (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_2))))] [_inst_5 : TopologicalSpace.{u2} β] [_inst_6 : RegularSpace.{u2} β _inst_5] {f : α -> β} {a : α} {b : α} {la : β}, (LT.lt.{u1} α (Preorder.toLT.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_2))))) a b) -> (ContinuousOn.{u1, u2} α β _inst_1 _inst_5 f (Set.Ioo.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_2)))) a b)) -> (Filter.Tendsto.{u1, u2} α β f (nhdsWithin.{u1} α _inst_1 a (Set.Ioi.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_2)))) a)) (nhds.{u2} β _inst_5 la)) -> (ContinuousOn.{u1, u2} α β _inst_1 _inst_5 (extendFrom.{u1, u2} α β _inst_1 _inst_5 (Set.Ioo.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_2)))) a b) f) (Set.Ico.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_2)))) a b))
but is expected to have type
  forall {α : Type.{u2}} {β : Type.{u1}} [_inst_1 : TopologicalSpace.{u2} α] [_inst_2 : LinearOrder.{u2} α] [_inst_3 : DenselyOrdered.{u2} α (Preorder.toLT.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_2))))))] [_inst_4 : OrderTopology.{u2} α _inst_1 (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_2)))))] [_inst_5 : TopologicalSpace.{u1} β] [_inst_6 : RegularSpace.{u1} β _inst_5] {f : α -> β} {a : α} {b : α} {la : β}, (LT.lt.{u2} α (Preorder.toLT.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_2)))))) a b) -> (ContinuousOn.{u2, u1} α β _inst_1 _inst_5 f (Set.Ioo.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_2))))) a b)) -> (Filter.Tendsto.{u2, u1} α β f (nhdsWithin.{u2} α _inst_1 a (Set.Ioi.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_2))))) a)) (nhds.{u1} β _inst_5 la)) -> (ContinuousOn.{u2, u1} α β _inst_1 _inst_5 (extendFrom.{u2, u1} α β _inst_1 _inst_5 (Set.Ioo.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_2))))) a b) f) (Set.Ico.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_2))))) a b))
Case conversion may be inaccurate. Consider using '#align continuous_on_Ico_extend_from_Ioo continuousOn_Ico_extendFrom_Iooₓ'. -/
theorem continuousOn_Ico_extendFrom_Ioo [TopologicalSpace α] [LinearOrder α] [DenselyOrdered α]
    [OrderTopology α] [TopologicalSpace β] [RegularSpace β] {f : α → β} {a b : α} {la : β}
    (hab : a < b) (hf : ContinuousOn f (Ioo a b)) (ha : Tendsto f (𝓝[>] a) (𝓝 la)) :
    ContinuousOn (extendFrom (Ioo a b) f) (Ico a b) :=
  by
  apply continuousOn_extendFrom
  · rw [closure_Ioo hab.ne]
    exact Ico_subset_Icc_self
  · intro x x_in
    rcases eq_left_or_mem_Ioo_of_mem_Ico x_in with (rfl | h)
    · use la
      simpa [hab]
    · use f x, hf x h
#align continuous_on_Ico_extend_from_Ioo continuousOn_Ico_extendFrom_Ioo

/- warning: continuous_on_Ioc_extend_from_Ioo -> continuousOn_Ioc_extendFrom_Ioo is a dubious translation:
lean 3 declaration is
  forall {α : Type.{u1}} {β : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} α] [_inst_2 : LinearOrder.{u1} α] [_inst_3 : DenselyOrdered.{u1} α (Preorder.toLT.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_2)))))] [_inst_4 : OrderTopology.{u1} α _inst_1 (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_2))))] [_inst_5 : TopologicalSpace.{u2} β] [_inst_6 : RegularSpace.{u2} β _inst_5] {f : α -> β} {a : α} {b : α} {lb : β}, (LT.lt.{u1} α (Preorder.toLT.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_2))))) a b) -> (ContinuousOn.{u1, u2} α β _inst_1 _inst_5 f (Set.Ioo.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_2)))) a b)) -> (Filter.Tendsto.{u1, u2} α β f (nhdsWithin.{u1} α _inst_1 b (Set.Iio.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_2)))) b)) (nhds.{u2} β _inst_5 lb)) -> (ContinuousOn.{u1, u2} α β _inst_1 _inst_5 (extendFrom.{u1, u2} α β _inst_1 _inst_5 (Set.Ioo.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_2)))) a b) f) (Set.Ioc.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_2)))) a b))
but is expected to have type
  forall {α : Type.{u2}} {β : Type.{u1}} [_inst_1 : TopologicalSpace.{u2} α] [_inst_2 : LinearOrder.{u2} α] [_inst_3 : DenselyOrdered.{u2} α (Preorder.toLT.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_2))))))] [_inst_4 : OrderTopology.{u2} α _inst_1 (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_2)))))] [_inst_5 : TopologicalSpace.{u1} β] [_inst_6 : RegularSpace.{u1} β _inst_5] {f : α -> β} {a : α} {b : α} {lb : β}, (LT.lt.{u2} α (Preorder.toLT.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_2)))))) a b) -> (ContinuousOn.{u2, u1} α β _inst_1 _inst_5 f (Set.Ioo.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_2))))) a b)) -> (Filter.Tendsto.{u2, u1} α β f (nhdsWithin.{u2} α _inst_1 b (Set.Iio.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_2))))) b)) (nhds.{u1} β _inst_5 lb)) -> (ContinuousOn.{u2, u1} α β _inst_1 _inst_5 (extendFrom.{u2, u1} α β _inst_1 _inst_5 (Set.Ioo.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_2))))) a b) f) (Set.Ioc.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_2))))) a b))
Case conversion may be inaccurate. Consider using '#align continuous_on_Ioc_extend_from_Ioo continuousOn_Ioc_extendFrom_Iooₓ'. -/
theorem continuousOn_Ioc_extendFrom_Ioo [TopologicalSpace α] [LinearOrder α] [DenselyOrdered α]
    [OrderTopology α] [TopologicalSpace β] [RegularSpace β] {f : α → β} {a b : α} {lb : β}
    (hab : a < b) (hf : ContinuousOn f (Ioo a b)) (hb : Tendsto f (𝓝[<] b) (𝓝 lb)) :
    ContinuousOn (extendFrom (Ioo a b) f) (Ioc a b) :=
  by
  have := @continuousOn_Ico_extendFrom_Ioo αᵒᵈ _ _ _ _ _ _ _ f _ _ _ hab
  erw [dual_Ico, dual_Ioi, dual_Ioo] at this
  exact this hf hb
#align continuous_on_Ioc_extend_from_Ioo continuousOn_Ioc_extendFrom_Ioo


import tactic.induction
import data.nat.parity
import data.int.interval
import data.set.finite
import data.list
import data.finset
import set_theory.cardinal.basic

noncomputable theory
open_locale classical

@[reducible]
def snoc {α : Type*} (xs : list α) (x : α) : list α :=
xs ++ [x]

lemma snoc_eq_snoc_iff {α : Type*} {xs ys : list α} {x y : α} :
  snoc xs x = snoc ys y ↔ xs = ys ∧ x = y :=
begin
  split; intro h,
  { simp_rw [list.append_eq_append_iff] at h, cases h; rcases h with ⟨zs, h₁, h₂⟩;
    { have h₃ := congr_arg list.length h₂, simp at h₃,
      rw list.length_eq_zero at h₃, cases h₃, simp at h₁ h₂,
      exact ⟨h₁.symm, h₂⟩ <|> exact ⟨h₁, h₂.symm⟩ }},
  { rw [h.1, h.2] },
end

lemma length_snoc {α : Type*} {xs : list α} {x : α} :
  (snoc xs x).length = xs.length.succ :=
by { rw [list.length_append], refl }

lemma length_lt_length_append_cons {α : Type*} {xs ys : list α} {y : α} :
  xs.length < (xs ++ y :: ys).length :=
begin
  rw [list.length_append, list.length_cons], change _ + 0 < _,
  rw add_lt_add_iff_left, exact (list.length ys).succ_pos,
end

lemma length_lt_length_append_snoc {α : Type*} {xs ys : list α} {y : α} :
  xs.length < (xs ++ snoc ys y).length :=
begin
  rw [list.length_append, length_snoc], change _ + 0 < _,
  rw add_lt_add_iff_left, exact (list.length ys).succ_pos,
end

lemma length_lt_length_snoc {α : Type*} {xs : list α} {x : α} :
  xs.length < (snoc xs x).length :=
length_lt_length_append_cons

lemma length_lt_length_snoc₂ {α : Type*} {xs : list α} {x y : α} :
  xs.length < (snoc (snoc xs x) y).length :=
by { transitivity (snoc xs x).length; exact length_lt_length_snoc }

lemma exi_ge_of_set_inf {P : ℕ → Prop} {n : ℕ}
  (h : {n : ℕ | P n}.infinite) : ∃ (k : ℕ), n ≤ k ∧ P k :=
begin
  obtain ⟨k, h₁, h₂⟩ := h.exists_nat_lt n,
  exact ⟨k, nat.le_of_lt h₂, h₁⟩,
end

lemma exi_set_infinite_of_forall_exi_P {α β : Type} {P : α → β → Prop}
  (h₁ : (set.univ : set α).infinite)
  (h₂ : (set.univ : set β).finite)
  (h₃ : ∀ (a : α), ∃ (b : β), P a b) :
  ∃ (b : β), {a : α | P a b}.infinite :=
begin
  by_contra' h₄, simp_rw set.not_infinite at h₄,
  have h₅ : {a : α | ∃ (b : β), P a b}.finite,
  { convert_to (⋃ (b : β), {a : α | P a b}).finite, { ext a, simp, },
    convert_to (⋃ (b : β) (h : b ∈ set.univ), {a : α | P a b}).finite,
    { congr, ext b a, simp, intros, apply set.mem_univ },
    apply set.finite.bUnion h₂, intros, apply h₄ },
  replace h₅ : (set.univ : set α).finite,
  { convert h₅, ext a, simp, exact h₃ a },
  contradiction,
end

lemma exi_set_infinite_of_forall_exi_P_nat {α : Type} [fintype α]
  {P : ℕ → α → Prop}
  (h : ∀ (n : ℕ), ∃ (a : α), P n a) :
  ∃ (a : α), {n : ℕ | P n a}.infinite :=
begin
  fapply exi_set_infinite_of_forall_exi_P,
  { exact set.infinite_univ },
  { exact set.finite_univ },
  { exact h },
end

lemma fintype_subtype_of_set_finite {α : Type} {P : α → Prop}
  (h : {x : α | P x}.finite) : fintype {x : α // P x} :=
begin
  apply set.fintype_of_univ_finite, rw set.univ_subtype,
  apply set.finite.bUnion h, simp,
end

lemma set_finite_of_set_equiv_finite' {α β : Type} (e : α ≃ β) {P : α → Prop}
  (h : {x : α | P x}.finite) : {y : β | P (e.inv_fun y)}.finite :=
begin
  fapply set.finite_of_finite_image,
  { exact α },
  { exact e.inv_fun },
  { apply set.inj_on_of_injective,
    exact function.right_inverse.injective e.right_inv },
  { convert h, ext a, split; intro h₁,
    { rcases h₁ with ⟨b, h₁, h₂⟩, subst h₂, exact h₁ },
    { use e.to_fun a, fsplit,
      { change P _, convert h₁, exact e.left_inv a },
      { exact e.left_inv a }}},
end

lemma set_finite_of_set_equiv_finite {α β : Type} (e : α ≃ β) {P : β → Prop}
  (h : {x : α | P (e.to_fun x)}.finite) : {y : β | P y}.finite :=
begin
  replace h := set_finite_of_set_equiv_finite' e h, dsimp at h, convert h,
  funext y, congr, exact eq.symm (e.right_inv y),
end

lemma abs_le_finite {d : ℤ} : {a : ℤ | |a| ≤ d}.finite :=
by { simp_rw abs_le, apply set.finite_Icc }

lemma abs_sub_le_finite {c d : ℤ} : {a : ℤ | |a - c| ≤ d}.finite :=
begin
  fapply set.finite.of_preimage,
  { exact ℤ },
  { intro a, exact a + c },
  { simp, exact abs_le_finite },
  { intro a, use a - c, simp },
end

lemma nat_find_le_find_of_imp {P Q : ℕ → Prop}
  {hh₁ : ∃ (n : ℕ), P n}
  {hh₂ : ∃ (n : ℕ), Q n}
  (h : ∀ (n : ℕ), Q n → P n) :
  nat.find hh₁ ≤ nat.find hh₂ :=
begin
  let n := _, change n ≤ _, by_cases h₁ : Q n,
  { apply le_of_eq, symmetry, rw nat.find_eq_iff, use h₁, rintro k h₂,
    have h₃ : nat.find hh₁ = n := rfl, rw nat.find_eq_iff at h₃,
    replace h₃ := h₃.2 k h₂, contrapose! h₃, exact h _ h₃ },
  { have h₂ : ∀ (k : ℕ), Q k → n ≤ k,
    { rintro k h₂, by_contra' hh, have h₃ : nat.find hh₁ = n := rfl,
      rw nat.find_eq_iff at h₃, apply h₃.2 k hh, exact h _ h₂ },
    apply h₂, apply nat.find_spec },
end

lemma nat_Inf_le_Inf_of_subset {P Q : set ℕ}
  (h₁ : Q.nonempty)
  (h₂ : Q ⊆ P) :
  Inf P ≤ Inf Q :=
begin
  have h₃ : ∃ n, n ∈ Q,
  { cases h₁ with n h₁, use [n, h₁] },
  have h₄ : ∃ n, n ∈ P,
  { cases h₃ with n h₃, use n, apply h₂, exact h₃ },
  simp_rw Inf, split_ifs, exact nat_find_le_find_of_imp h₂,
end

lemma finset_card_insert_erase_eq {α : Type} {s : finset α} {x y : α}
  (h₁ : x ∈ s)
  (h₂ : y ∉ s) :
  (insert y (s.erase x)).card = s.card :=
begin
  replace h₂ : y ∉ s.erase x,
  { rw finset.mem_erase, tauto },
  rw [finset.card_insert_of_not_mem h₂, finset.card_erase_of_mem h₁],
  cases h₃ : s.card,
  { rw finset.card_eq_zero at h₃, subst h₃, cases h₁ },
  { refl },
end