/-
Copyright © 2021 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison, Shing Tak Lam

! This file was ported from Lean 3 source module topology.continuous_function.ordered
! leanprover-community/mathlib commit 3dadefa3f544b1db6214777fe47910739b54c66a
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
import Mathbin.Topology.Algebra.Order.ProjIcc
import Mathbin.Topology.Algebra.Order.Group
import Mathbin.Topology.ContinuousFunction.Basic

/-!
# Bundled continuous maps into orders, with order-compatible topology

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

-/

variable {α : Type _} {β : Type _} {γ : Type _}

variable [TopologicalSpace α] [TopologicalSpace β] [TopologicalSpace γ]

namespace ContinuousMap

section

variable [LinearOrderedAddCommGroup β] [OrderTopology β]

#print ContinuousMap.abs /-
/-- The pointwise absolute value of a continuous function as a continuous function. -/
def abs (f : C(α, β)) : C(α, β) where toFun x := |f x|
#align continuous_map.abs ContinuousMap.abs
-/

-- see Note [lower instance priority]
instance (priority := 100) : Abs C(α, β) :=
  ⟨fun f => abs f⟩

/- warning: continuous_map.abs_apply -> ContinuousMap.abs_apply is a dubious translation:
lean 3 declaration is
  forall {α : Type.{u1}} {β : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} α] [_inst_2 : TopologicalSpace.{u2} β] [_inst_4 : LinearOrderedAddCommGroup.{u2} β] [_inst_5 : OrderTopology.{u2} β _inst_2 (PartialOrder.toPreorder.{u2} β (OrderedAddCommGroup.toPartialOrder.{u2} β (LinearOrderedAddCommGroup.toOrderedAddCommGroup.{u2} β _inst_4)))] (f : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (x : α), Eq.{succ u2} β (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (fun (_x : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) => α -> β) (ContinuousMap.hasCoeToFun.{u1, u2} α β _inst_1 _inst_2) (Abs.abs.{max u1 u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (ContinuousMap.hasAbs.{u1, u2} α β _inst_1 _inst_2 _inst_4 _inst_5) f) x) (Abs.abs.{u2} β (Neg.toHasAbs.{u2} β (SubNegMonoid.toHasNeg.{u2} β (AddGroup.toSubNegMonoid.{u2} β (AddCommGroup.toAddGroup.{u2} β (OrderedAddCommGroup.toAddCommGroup.{u2} β (LinearOrderedAddCommGroup.toOrderedAddCommGroup.{u2} β _inst_4))))) (SemilatticeSup.toHasSup.{u2} β (Lattice.toSemilatticeSup.{u2} β (LinearOrder.toLattice.{u2} β (LinearOrderedAddCommGroup.toLinearOrder.{u2} β _inst_4))))) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (fun (_x : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) => α -> β) (ContinuousMap.hasCoeToFun.{u1, u2} α β _inst_1 _inst_2) f x))
but is expected to have type
  forall {α : Type.{u2}} {β : Type.{u1}} [_inst_1 : TopologicalSpace.{u2} α] [_inst_2 : TopologicalSpace.{u1} β] [_inst_4 : LinearOrderedAddCommGroup.{u1} β] [_inst_5 : OrderTopology.{u1} β _inst_2 (PartialOrder.toPreorder.{u1} β (OrderedAddCommGroup.toPartialOrder.{u1} β (LinearOrderedAddCommGroup.toOrderedAddCommGroup.{u1} β _inst_4)))] (f : ContinuousMap.{u2, u1} α β _inst_1 _inst_2) (x : α), Eq.{succ u1} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) x) (FunLike.coe.{max (succ u2) (succ u1), succ u2, succ u1} (ContinuousMap.{u2, u1} α β _inst_1 _inst_2) α (fun (_x : α) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) _x) (ContinuousMapClass.toFunLike.{max u2 u1, u2, u1} (ContinuousMap.{u2, u1} α β _inst_1 _inst_2) α β _inst_1 _inst_2 (ContinuousMap.instContinuousMapClassContinuousMap.{u2, u1} α β _inst_1 _inst_2)) (Abs.abs.{max u2 u1} (ContinuousMap.{u2, u1} α β _inst_1 _inst_2) (ContinuousMap.instAbsContinuousMap.{u2, u1} α β _inst_1 _inst_2 _inst_4 _inst_5) f) x) (Abs.abs.{u1} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) x) (Neg.toHasAbs.{u1} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) x) (NegZeroClass.toNeg.{u1} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) x) (SubNegZeroMonoid.toNegZeroClass.{u1} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) x) (SubtractionMonoid.toSubNegZeroMonoid.{u1} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) x) (SubtractionCommMonoid.toSubtractionMonoid.{u1} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) x) (AddCommGroup.toDivisionAddCommMonoid.{u1} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) x) (OrderedAddCommGroup.toAddCommGroup.{u1} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) x) (LinearOrderedAddCommGroup.toOrderedAddCommGroup.{u1} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) x) _inst_4))))))) (SemilatticeSup.toSup.{u1} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) x) (Lattice.toSemilatticeSup.{u1} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) x) (DistribLattice.toLattice.{u1} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) x) (instDistribLattice.{u1} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) x) (LinearOrderedAddCommGroup.toLinearOrder.{u1} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) x) _inst_4)))))) (FunLike.coe.{max (succ u2) (succ u1), succ u2, succ u1} (ContinuousMap.{u2, u1} α β _inst_1 _inst_2) α (fun (_x : α) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) _x) (ContinuousMapClass.toFunLike.{max u2 u1, u2, u1} (ContinuousMap.{u2, u1} α β _inst_1 _inst_2) α β _inst_1 _inst_2 (ContinuousMap.instContinuousMapClassContinuousMap.{u2, u1} α β _inst_1 _inst_2)) f x))
Case conversion may be inaccurate. Consider using '#align continuous_map.abs_apply ContinuousMap.abs_applyₓ'. -/
@[simp]
theorem abs_apply (f : C(α, β)) (x : α) : (|f|) x = |f x| :=
  rfl
#align continuous_map.abs_apply ContinuousMap.abs_apply

end

/-!
We now set up the partial order and lattice structure (given by pointwise min and max)
on continuous functions.
-/

section Lattice

#print ContinuousMap.partialOrder /-
instance partialOrder [PartialOrder β] : PartialOrder C(α, β) :=
  PartialOrder.lift (fun f => f.toFun) (by tidy)
#align continuous_map.partial_order ContinuousMap.partialOrder
-/

/- warning: continuous_map.le_def -> ContinuousMap.le_def is a dubious translation:
lean 3 declaration is
  forall {α : Type.{u1}} {β : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} α] [_inst_2 : TopologicalSpace.{u2} β] [_inst_4 : PartialOrder.{u2} β] {f : ContinuousMap.{u1, u2} α β _inst_1 _inst_2} {g : ContinuousMap.{u1, u2} α β _inst_1 _inst_2}, Iff (LE.le.{max u1 u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (Preorder.toLE.{max u1 u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (PartialOrder.toPreorder.{max u1 u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (ContinuousMap.partialOrder.{u1, u2} α β _inst_1 _inst_2 _inst_4))) f g) (forall (a : α), LE.le.{u2} β (Preorder.toLE.{u2} β (PartialOrder.toPreorder.{u2} β _inst_4)) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (fun (_x : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) => α -> β) (ContinuousMap.hasCoeToFun.{u1, u2} α β _inst_1 _inst_2) f a) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (fun (_x : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) => α -> β) (ContinuousMap.hasCoeToFun.{u1, u2} α β _inst_1 _inst_2) g a))
but is expected to have type
  forall {α : Type.{u1}} {β : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} α] [_inst_2 : TopologicalSpace.{u2} β] [_inst_4 : PartialOrder.{u2} β] {f : ContinuousMap.{u1, u2} α β _inst_1 _inst_2} {g : ContinuousMap.{u1, u2} α β _inst_1 _inst_2}, Iff (LE.le.{max u1 u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (Preorder.toLE.{max u1 u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (PartialOrder.toPreorder.{max u1 u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (ContinuousMap.partialOrder.{u1, u2} α β _inst_1 _inst_2 _inst_4))) f g) (forall (a : α), LE.le.{u2} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) a) (Preorder.toLE.{u2} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) a) (PartialOrder.toPreorder.{u2} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) a) _inst_4)) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α (fun (_x : α) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α β _inst_1 _inst_2 (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} α β _inst_1 _inst_2)) f a) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α (fun (_x : α) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α β _inst_1 _inst_2 (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} α β _inst_1 _inst_2)) g a))
Case conversion may be inaccurate. Consider using '#align continuous_map.le_def ContinuousMap.le_defₓ'. -/
theorem le_def [PartialOrder β] {f g : C(α, β)} : f ≤ g ↔ ∀ a, f a ≤ g a :=
  Pi.le_def
#align continuous_map.le_def ContinuousMap.le_def

/- warning: continuous_map.lt_def -> ContinuousMap.lt_def is a dubious translation:
lean 3 declaration is
  forall {α : Type.{u1}} {β : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} α] [_inst_2 : TopologicalSpace.{u2} β] [_inst_4 : PartialOrder.{u2} β] {f : ContinuousMap.{u1, u2} α β _inst_1 _inst_2} {g : ContinuousMap.{u1, u2} α β _inst_1 _inst_2}, Iff (LT.lt.{max u1 u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (Preorder.toLT.{max u1 u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (PartialOrder.toPreorder.{max u1 u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (ContinuousMap.partialOrder.{u1, u2} α β _inst_1 _inst_2 _inst_4))) f g) (And (forall (a : α), LE.le.{u2} β (Preorder.toLE.{u2} β (PartialOrder.toPreorder.{u2} β _inst_4)) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (fun (_x : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) => α -> β) (ContinuousMap.hasCoeToFun.{u1, u2} α β _inst_1 _inst_2) f a) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (fun (_x : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) => α -> β) (ContinuousMap.hasCoeToFun.{u1, u2} α β _inst_1 _inst_2) g a)) (Exists.{succ u1} α (fun (a : α) => LT.lt.{u2} β (Preorder.toLT.{u2} β (PartialOrder.toPreorder.{u2} β _inst_4)) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (fun (_x : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) => α -> β) (ContinuousMap.hasCoeToFun.{u1, u2} α β _inst_1 _inst_2) f a) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (fun (_x : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) => α -> β) (ContinuousMap.hasCoeToFun.{u1, u2} α β _inst_1 _inst_2) g a))))
but is expected to have type
  forall {α : Type.{u1}} {β : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} α] [_inst_2 : TopologicalSpace.{u2} β] [_inst_4 : PartialOrder.{u2} β] {f : ContinuousMap.{u1, u2} α β _inst_1 _inst_2} {g : ContinuousMap.{u1, u2} α β _inst_1 _inst_2}, Iff (LT.lt.{max u1 u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (Preorder.toLT.{max u1 u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (PartialOrder.toPreorder.{max u1 u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (ContinuousMap.partialOrder.{u1, u2} α β _inst_1 _inst_2 _inst_4))) f g) (And (forall (a : α), LE.le.{u2} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) a) (Preorder.toLE.{u2} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) a) (PartialOrder.toPreorder.{u2} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) a) _inst_4)) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α (fun (_x : α) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α β _inst_1 _inst_2 (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} α β _inst_1 _inst_2)) f a) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α (fun (_x : α) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α β _inst_1 _inst_2 (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} α β _inst_1 _inst_2)) g a)) (Exists.{succ u1} α (fun (a : α) => LT.lt.{u2} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) a) (Preorder.toLT.{u2} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) a) (PartialOrder.toPreorder.{u2} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) a) _inst_4)) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α (fun (_x : α) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α β _inst_1 _inst_2 (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} α β _inst_1 _inst_2)) f a) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α (fun (_x : α) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α β _inst_1 _inst_2 (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} α β _inst_1 _inst_2)) g a))))
Case conversion may be inaccurate. Consider using '#align continuous_map.lt_def ContinuousMap.lt_defₓ'. -/
theorem lt_def [PartialOrder β] {f g : C(α, β)} : f < g ↔ (∀ a, f a ≤ g a) ∧ ∃ a, f a < g a :=
  Pi.lt_def
#align continuous_map.lt_def ContinuousMap.lt_def

#print ContinuousMap.sup /-
instance sup [LinearOrder β] [OrderClosedTopology β] : Sup C(α, β)
    where sup f g := { toFun := fun a => max (f a) (g a) }
#align continuous_map.has_sup ContinuousMap.sup
-/

/- warning: continuous_map.sup_coe -> ContinuousMap.sup_coe is a dubious translation:
lean 3 declaration is
  forall {α : Type.{u1}} {β : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} α] [_inst_2 : TopologicalSpace.{u2} β] [_inst_4 : LinearOrder.{u2} β] [_inst_5 : OrderClosedTopology.{u2} β _inst_2 (PartialOrder.toPreorder.{u2} β (SemilatticeInf.toPartialOrder.{u2} β (Lattice.toSemilatticeInf.{u2} β (LinearOrder.toLattice.{u2} β _inst_4))))] (f : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (g : ContinuousMap.{u1, u2} α β _inst_1 _inst_2), Eq.{max (succ u1) (succ u2)} ((fun (_x : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) => α -> β) (Sup.sup.{max u1 u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (ContinuousMap.sup.{u1, u2} α β _inst_1 _inst_2 _inst_4 _inst_5) f g)) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (fun (_x : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) => α -> β) (ContinuousMap.hasCoeToFun.{u1, u2} α β _inst_1 _inst_2) (Sup.sup.{max u1 u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (ContinuousMap.sup.{u1, u2} α β _inst_1 _inst_2 _inst_4 _inst_5) f g)) (Sup.sup.{max u1 u2} (α -> β) (Pi.hasSup.{u1, u2} α (fun (ᾰ : α) => β) (fun (i : α) => SemilatticeSup.toHasSup.{u2} β (Lattice.toSemilatticeSup.{u2} β (LinearOrder.toLattice.{u2} β _inst_4)))) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (fun (_x : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) => α -> β) (ContinuousMap.hasCoeToFun.{u1, u2} α β _inst_1 _inst_2) f) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (fun (_x : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) => α -> β) (ContinuousMap.hasCoeToFun.{u1, u2} α β _inst_1 _inst_2) g))
but is expected to have type
  forall {α : Type.{u1}} {β : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} α] [_inst_2 : TopologicalSpace.{u2} β] [_inst_4 : LinearOrder.{u2} β] [_inst_5 : OrderClosedTopology.{u2} β _inst_2 (PartialOrder.toPreorder.{u2} β (SemilatticeInf.toPartialOrder.{u2} β (Lattice.toSemilatticeInf.{u2} β (DistribLattice.toLattice.{u2} β (instDistribLattice.{u2} β _inst_4)))))] (f : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (g : ContinuousMap.{u1, u2} α β _inst_1 _inst_2), Eq.{max (succ u1) (succ u2)} (forall (a : α), (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) a) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α (fun (_x : α) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α β _inst_1 _inst_2 (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} α β _inst_1 _inst_2)) (Sup.sup.{max u1 u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (ContinuousMap.sup.{u1, u2} α β _inst_1 _inst_2 _inst_4 _inst_5) f g)) (Sup.sup.{max u1 u2} (α -> β) (Pi.instSupForAll.{u1, u2} α (fun (ᾰ : α) => β) (fun (i : α) => SemilatticeSup.toSup.{u2} β (Lattice.toSemilatticeSup.{u2} β (DistribLattice.toLattice.{u2} β (instDistribLattice.{u2} β _inst_4))))) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α (fun (_x : α) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α β _inst_1 _inst_2 (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} α β _inst_1 _inst_2)) f) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α (fun (_x : α) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α β _inst_1 _inst_2 (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} α β _inst_1 _inst_2)) g))
Case conversion may be inaccurate. Consider using '#align continuous_map.sup_coe ContinuousMap.sup_coeₓ'. -/
@[simp, norm_cast]
theorem sup_coe [LinearOrder β] [OrderClosedTopology β] (f g : C(α, β)) :
    ((f ⊔ g : C(α, β)) : α → β) = (f ⊔ g : α → β) :=
  rfl
#align continuous_map.sup_coe ContinuousMap.sup_coe

/- warning: continuous_map.sup_apply -> ContinuousMap.sup_apply is a dubious translation:
lean 3 declaration is
  forall {α : Type.{u1}} {β : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} α] [_inst_2 : TopologicalSpace.{u2} β] [_inst_4 : LinearOrder.{u2} β] [_inst_5 : OrderClosedTopology.{u2} β _inst_2 (PartialOrder.toPreorder.{u2} β (SemilatticeInf.toPartialOrder.{u2} β (Lattice.toSemilatticeInf.{u2} β (LinearOrder.toLattice.{u2} β _inst_4))))] (f : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (g : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (a : α), Eq.{succ u2} β (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (fun (_x : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) => α -> β) (ContinuousMap.hasCoeToFun.{u1, u2} α β _inst_1 _inst_2) (Sup.sup.{max u1 u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (ContinuousMap.sup.{u1, u2} α β _inst_1 _inst_2 _inst_4 _inst_5) f g) a) (LinearOrder.max.{u2} β _inst_4 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (fun (_x : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) => α -> β) (ContinuousMap.hasCoeToFun.{u1, u2} α β _inst_1 _inst_2) f a) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (fun (_x : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) => α -> β) (ContinuousMap.hasCoeToFun.{u1, u2} α β _inst_1 _inst_2) g a))
but is expected to have type
  forall {α : Type.{u1}} {β : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} α] [_inst_2 : TopologicalSpace.{u2} β] [_inst_4 : LinearOrder.{u2} β] [_inst_5 : OrderClosedTopology.{u2} β _inst_2 (PartialOrder.toPreorder.{u2} β (SemilatticeInf.toPartialOrder.{u2} β (Lattice.toSemilatticeInf.{u2} β (DistribLattice.toLattice.{u2} β (instDistribLattice.{u2} β _inst_4)))))] (f : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (g : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (a : α), Eq.{succ u2} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) a) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α (fun (_x : α) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α β _inst_1 _inst_2 (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} α β _inst_1 _inst_2)) (Sup.sup.{max u1 u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (ContinuousMap.sup.{u1, u2} α β _inst_1 _inst_2 _inst_4 _inst_5) f g) a) (Max.max.{u2} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) a) (LinearOrder.toMax.{u2} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) a) _inst_4) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α (fun (_x : α) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α β _inst_1 _inst_2 (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} α β _inst_1 _inst_2)) f a) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α (fun (_x : α) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α β _inst_1 _inst_2 (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} α β _inst_1 _inst_2)) g a))
Case conversion may be inaccurate. Consider using '#align continuous_map.sup_apply ContinuousMap.sup_applyₓ'. -/
@[simp]
theorem sup_apply [LinearOrder β] [OrderClosedTopology β] (f g : C(α, β)) (a : α) :
    (f ⊔ g) a = max (f a) (g a) :=
  rfl
#align continuous_map.sup_apply ContinuousMap.sup_apply

instance [LinearOrder β] [OrderClosedTopology β] : SemilatticeSup C(α, β) :=
  { ContinuousMap.partialOrder,
    ContinuousMap.sup with
    le_sup_left := fun f g => le_def.mpr (by simp [le_refl])
    le_sup_right := fun f g => le_def.mpr (by simp [le_refl])
    sup_le := fun f₁ f₂ g w₁ w₂ => le_def.mpr fun a => by simp [le_def.mp w₁ a, le_def.mp w₂ a] }

#print ContinuousMap.inf /-
instance inf [LinearOrder β] [OrderClosedTopology β] : Inf C(α, β)
    where inf f g := { toFun := fun a => min (f a) (g a) }
#align continuous_map.has_inf ContinuousMap.inf
-/

/- warning: continuous_map.inf_coe -> ContinuousMap.inf_coe is a dubious translation:
lean 3 declaration is
  forall {α : Type.{u1}} {β : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} α] [_inst_2 : TopologicalSpace.{u2} β] [_inst_4 : LinearOrder.{u2} β] [_inst_5 : OrderClosedTopology.{u2} β _inst_2 (PartialOrder.toPreorder.{u2} β (SemilatticeInf.toPartialOrder.{u2} β (Lattice.toSemilatticeInf.{u2} β (LinearOrder.toLattice.{u2} β _inst_4))))] (f : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (g : ContinuousMap.{u1, u2} α β _inst_1 _inst_2), Eq.{max (succ u1) (succ u2)} ((fun (_x : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) => α -> β) (Inf.inf.{max u1 u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (ContinuousMap.inf.{u1, u2} α β _inst_1 _inst_2 _inst_4 _inst_5) f g)) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (fun (_x : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) => α -> β) (ContinuousMap.hasCoeToFun.{u1, u2} α β _inst_1 _inst_2) (Inf.inf.{max u1 u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (ContinuousMap.inf.{u1, u2} α β _inst_1 _inst_2 _inst_4 _inst_5) f g)) (Inf.inf.{max u1 u2} (α -> β) (Pi.hasInf.{u1, u2} α (fun (ᾰ : α) => β) (fun (i : α) => SemilatticeInf.toHasInf.{u2} β (Lattice.toSemilatticeInf.{u2} β (LinearOrder.toLattice.{u2} β _inst_4)))) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (fun (_x : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) => α -> β) (ContinuousMap.hasCoeToFun.{u1, u2} α β _inst_1 _inst_2) f) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (fun (_x : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) => α -> β) (ContinuousMap.hasCoeToFun.{u1, u2} α β _inst_1 _inst_2) g))
but is expected to have type
  forall {α : Type.{u1}} {β : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} α] [_inst_2 : TopologicalSpace.{u2} β] [_inst_4 : LinearOrder.{u2} β] [_inst_5 : OrderClosedTopology.{u2} β _inst_2 (PartialOrder.toPreorder.{u2} β (SemilatticeInf.toPartialOrder.{u2} β (Lattice.toSemilatticeInf.{u2} β (DistribLattice.toLattice.{u2} β (instDistribLattice.{u2} β _inst_4)))))] (f : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (g : ContinuousMap.{u1, u2} α β _inst_1 _inst_2), Eq.{max (succ u1) (succ u2)} (forall (a : α), (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) a) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α (fun (_x : α) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α β _inst_1 _inst_2 (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} α β _inst_1 _inst_2)) (Inf.inf.{max u1 u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (ContinuousMap.inf.{u1, u2} α β _inst_1 _inst_2 _inst_4 _inst_5) f g)) (Inf.inf.{max u1 u2} (α -> β) (Pi.instInfForAll.{u1, u2} α (fun (ᾰ : α) => β) (fun (i : α) => Lattice.toInf.{u2} β (DistribLattice.toLattice.{u2} β (instDistribLattice.{u2} β _inst_4)))) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α (fun (_x : α) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α β _inst_1 _inst_2 (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} α β _inst_1 _inst_2)) f) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α (fun (_x : α) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α β _inst_1 _inst_2 (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} α β _inst_1 _inst_2)) g))
Case conversion may be inaccurate. Consider using '#align continuous_map.inf_coe ContinuousMap.inf_coeₓ'. -/
@[simp, norm_cast]
theorem inf_coe [LinearOrder β] [OrderClosedTopology β] (f g : C(α, β)) :
    ((f ⊓ g : C(α, β)) : α → β) = (f ⊓ g : α → β) :=
  rfl
#align continuous_map.inf_coe ContinuousMap.inf_coe

/- warning: continuous_map.inf_apply -> ContinuousMap.inf_apply is a dubious translation:
lean 3 declaration is
  forall {α : Type.{u1}} {β : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} α] [_inst_2 : TopologicalSpace.{u2} β] [_inst_4 : LinearOrder.{u2} β] [_inst_5 : OrderClosedTopology.{u2} β _inst_2 (PartialOrder.toPreorder.{u2} β (SemilatticeInf.toPartialOrder.{u2} β (Lattice.toSemilatticeInf.{u2} β (LinearOrder.toLattice.{u2} β _inst_4))))] (f : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (g : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (a : α), Eq.{succ u2} β (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (fun (_x : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) => α -> β) (ContinuousMap.hasCoeToFun.{u1, u2} α β _inst_1 _inst_2) (Inf.inf.{max u1 u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (ContinuousMap.inf.{u1, u2} α β _inst_1 _inst_2 _inst_4 _inst_5) f g) a) (LinearOrder.min.{u2} β _inst_4 (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (fun (_x : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) => α -> β) (ContinuousMap.hasCoeToFun.{u1, u2} α β _inst_1 _inst_2) f a) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (fun (_x : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) => α -> β) (ContinuousMap.hasCoeToFun.{u1, u2} α β _inst_1 _inst_2) g a))
but is expected to have type
  forall {α : Type.{u1}} {β : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} α] [_inst_2 : TopologicalSpace.{u2} β] [_inst_4 : LinearOrder.{u2} β] [_inst_5 : OrderClosedTopology.{u2} β _inst_2 (PartialOrder.toPreorder.{u2} β (SemilatticeInf.toPartialOrder.{u2} β (Lattice.toSemilatticeInf.{u2} β (DistribLattice.toLattice.{u2} β (instDistribLattice.{u2} β _inst_4)))))] (f : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (g : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (a : α), Eq.{succ u2} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) a) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α (fun (_x : α) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α β _inst_1 _inst_2 (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} α β _inst_1 _inst_2)) (Inf.inf.{max u1 u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (ContinuousMap.inf.{u1, u2} α β _inst_1 _inst_2 _inst_4 _inst_5) f g) a) (Min.min.{u2} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) a) (LinearOrder.toMin.{u2} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) a) _inst_4) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α (fun (_x : α) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α β _inst_1 _inst_2 (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} α β _inst_1 _inst_2)) f a) (FunLike.coe.{max (succ u1) (succ u2), succ u1, succ u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α (fun (_x : α) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) _x) (ContinuousMapClass.toFunLike.{max u1 u2, u1, u2} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) α β _inst_1 _inst_2 (ContinuousMap.instContinuousMapClassContinuousMap.{u1, u2} α β _inst_1 _inst_2)) g a))
Case conversion may be inaccurate. Consider using '#align continuous_map.inf_apply ContinuousMap.inf_applyₓ'. -/
@[simp]
theorem inf_apply [LinearOrder β] [OrderClosedTopology β] (f g : C(α, β)) (a : α) :
    (f ⊓ g) a = min (f a) (g a) :=
  rfl
#align continuous_map.inf_apply ContinuousMap.inf_apply

instance [LinearOrder β] [OrderClosedTopology β] : SemilatticeInf C(α, β) :=
  { ContinuousMap.partialOrder,
    ContinuousMap.inf with
    inf_le_left := fun f g => le_def.mpr (by simp [le_refl])
    inf_le_right := fun f g => le_def.mpr (by simp [le_refl])
    le_inf := fun f₁ f₂ g w₁ w₂ => le_def.mpr fun a => by simp [le_def.mp w₁ a, le_def.mp w₂ a] }

instance [LinearOrder β] [OrderClosedTopology β] : Lattice C(α, β) :=
  { ContinuousMap.semilatticeInf, ContinuousMap.semilatticeSup with }

-- TODO transfer this lattice structure to `bounded_continuous_function`
section Sup'

variable [LinearOrder γ] [OrderClosedTopology γ]

/- warning: continuous_map.sup'_apply -> ContinuousMap.sup'_apply is a dubious translation:
lean 3 declaration is
  forall {β : Type.{u1}} {γ : Type.{u2}} [_inst_2 : TopologicalSpace.{u1} β] [_inst_3 : TopologicalSpace.{u2} γ] [_inst_4 : LinearOrder.{u2} γ] [_inst_5 : OrderClosedTopology.{u2} γ _inst_3 (PartialOrder.toPreorder.{u2} γ (SemilatticeInf.toPartialOrder.{u2} γ (Lattice.toSemilatticeInf.{u2} γ (LinearOrder.toLattice.{u2} γ _inst_4))))] {ι : Type.{u3}} {s : Finset.{u3} ι} (H : Finset.Nonempty.{u3} ι s) (f : ι -> (ContinuousMap.{u1, u2} β γ _inst_2 _inst_3)) (b : β), Eq.{succ u2} γ (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} β γ _inst_2 _inst_3) (fun (_x : ContinuousMap.{u1, u2} β γ _inst_2 _inst_3) => β -> γ) (ContinuousMap.hasCoeToFun.{u1, u2} β γ _inst_2 _inst_3) (Finset.sup'.{max u1 u2, u3} (ContinuousMap.{u1, u2} β γ _inst_2 _inst_3) ι (ContinuousMap.semilatticeSup.{u1, u2} β γ _inst_2 _inst_3 _inst_4 _inst_5) s H f) b) (Finset.sup'.{u2, u3} γ ι (Lattice.toSemilatticeSup.{u2} γ (LinearOrder.toLattice.{u2} γ _inst_4)) s H (fun (a : ι) => coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} β γ _inst_2 _inst_3) (fun (_x : ContinuousMap.{u1, u2} β γ _inst_2 _inst_3) => β -> γ) (ContinuousMap.hasCoeToFun.{u1, u2} β γ _inst_2 _inst_3) (f a) b))
but is expected to have type
  forall {β : Type.{u2}} {γ : Type.{u1}} [_inst_2 : TopologicalSpace.{u2} β] [_inst_3 : TopologicalSpace.{u1} γ] [_inst_4 : LinearOrder.{u1} γ] [_inst_5 : OrderClosedTopology.{u1} γ _inst_3 (PartialOrder.toPreorder.{u1} γ (SemilatticeInf.toPartialOrder.{u1} γ (Lattice.toSemilatticeInf.{u1} γ (DistribLattice.toLattice.{u1} γ (instDistribLattice.{u1} γ _inst_4)))))] {ι : Type.{u3}} {s : Finset.{u3} ι} (H : Finset.Nonempty.{u3} ι s) (f : ι -> (ContinuousMap.{u2, u1} β γ _inst_2 _inst_3)) (b : β), Eq.{succ u1} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : β) => γ) b) (FunLike.coe.{max (succ u2) (succ u1), succ u2, succ u1} (ContinuousMap.{u2, u1} β γ _inst_2 _inst_3) β (fun (_x : β) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : β) => γ) _x) (ContinuousMapClass.toFunLike.{max u2 u1, u2, u1} (ContinuousMap.{u2, u1} β γ _inst_2 _inst_3) β γ _inst_2 _inst_3 (ContinuousMap.instContinuousMapClassContinuousMap.{u2, u1} β γ _inst_2 _inst_3)) (Finset.sup'.{max u2 u1, u3} (ContinuousMap.{u2, u1} β γ _inst_2 _inst_3) ι (ContinuousMap.semilatticeSup.{u2, u1} β γ _inst_2 _inst_3 _inst_4 _inst_5) s H f) b) (Finset.sup'.{u1, u3} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : β) => γ) b) ι (Lattice.toSemilatticeSup.{u1} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : β) => γ) b) (DistribLattice.toLattice.{u1} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : β) => γ) b) (instDistribLattice.{u1} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : β) => γ) b) _inst_4))) s H (fun (a : ι) => FunLike.coe.{max (succ u2) (succ u1), succ u2, succ u1} (ContinuousMap.{u2, u1} β γ _inst_2 _inst_3) β (fun (_x : β) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : β) => γ) _x) (ContinuousMapClass.toFunLike.{max u2 u1, u2, u1} (ContinuousMap.{u2, u1} β γ _inst_2 _inst_3) β γ _inst_2 _inst_3 (ContinuousMap.instContinuousMapClassContinuousMap.{u2, u1} β γ _inst_2 _inst_3)) (f a) b))
Case conversion may be inaccurate. Consider using '#align continuous_map.sup'_apply ContinuousMap.sup'_applyₓ'. -/
theorem sup'_apply {ι : Type _} {s : Finset ι} (H : s.Nonempty) (f : ι → C(β, γ)) (b : β) :
    s.sup' H f b = s.sup' H fun a => f a b :=
  Finset.comp_sup'_eq_sup'_comp H (fun f : C(β, γ) => f b) fun i j => rfl
#align continuous_map.sup'_apply ContinuousMap.sup'_apply

/- warning: continuous_map.sup'_coe -> ContinuousMap.sup'_coe is a dubious translation:
lean 3 declaration is
  forall {β : Type.{u1}} {γ : Type.{u2}} [_inst_2 : TopologicalSpace.{u1} β] [_inst_3 : TopologicalSpace.{u2} γ] [_inst_4 : LinearOrder.{u2} γ] [_inst_5 : OrderClosedTopology.{u2} γ _inst_3 (PartialOrder.toPreorder.{u2} γ (SemilatticeInf.toPartialOrder.{u2} γ (Lattice.toSemilatticeInf.{u2} γ (LinearOrder.toLattice.{u2} γ _inst_4))))] {ι : Type.{u3}} {s : Finset.{u3} ι} (H : Finset.Nonempty.{u3} ι s) (f : ι -> (ContinuousMap.{u1, u2} β γ _inst_2 _inst_3)), Eq.{max (succ u1) (succ u2)} ((fun (_x : ContinuousMap.{u1, u2} β γ _inst_2 _inst_3) => β -> γ) (Finset.sup'.{max u1 u2, u3} (ContinuousMap.{u1, u2} β γ _inst_2 _inst_3) ι (ContinuousMap.semilatticeSup.{u1, u2} β γ _inst_2 _inst_3 _inst_4 _inst_5) s H f)) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} β γ _inst_2 _inst_3) (fun (_x : ContinuousMap.{u1, u2} β γ _inst_2 _inst_3) => β -> γ) (ContinuousMap.hasCoeToFun.{u1, u2} β γ _inst_2 _inst_3) (Finset.sup'.{max u1 u2, u3} (ContinuousMap.{u1, u2} β γ _inst_2 _inst_3) ι (ContinuousMap.semilatticeSup.{u1, u2} β γ _inst_2 _inst_3 _inst_4 _inst_5) s H f)) (Finset.sup'.{max u1 u2, u3} ((fun (_x : ContinuousMap.{u1, u2} β γ _inst_2 _inst_3) => β -> γ) (Finset.sup'.{max u1 u2, u3} (ContinuousMap.{u1, u2} β γ _inst_2 _inst_3) ι (ContinuousMap.semilatticeSup.{u1, u2} β γ _inst_2 _inst_3 _inst_4 _inst_5) s H f)) ι (Pi.semilatticeSup.{u1, u2} β (fun (ᾰ : β) => γ) (fun (i : β) => Lattice.toSemilatticeSup.{u2} γ (LinearOrder.toLattice.{u2} γ _inst_4))) s H (fun (a : ι) => coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} β γ _inst_2 _inst_3) (fun (_x : ContinuousMap.{u1, u2} β γ _inst_2 _inst_3) => β -> γ) (ContinuousMap.hasCoeToFun.{u1, u2} β γ _inst_2 _inst_3) (f a)))
but is expected to have type
  forall {β : Type.{u2}} {γ : Type.{u1}} [_inst_2 : TopologicalSpace.{u2} β] [_inst_3 : TopologicalSpace.{u1} γ] [_inst_4 : LinearOrder.{u1} γ] [_inst_5 : OrderClosedTopology.{u1} γ _inst_3 (PartialOrder.toPreorder.{u1} γ (SemilatticeInf.toPartialOrder.{u1} γ (Lattice.toSemilatticeInf.{u1} γ (DistribLattice.toLattice.{u1} γ (instDistribLattice.{u1} γ _inst_4)))))] {ι : Type.{u3}} {s : Finset.{u3} ι} (H : Finset.Nonempty.{u3} ι s) (f : ι -> (ContinuousMap.{u2, u1} β γ _inst_2 _inst_3)), Eq.{max (succ u2) (succ u1)} (forall (a : β), (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : β) => γ) a) (FunLike.coe.{max (succ u2) (succ u1), succ u2, succ u1} (ContinuousMap.{u2, u1} β γ _inst_2 _inst_3) β (fun (_x : β) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : β) => γ) _x) (ContinuousMapClass.toFunLike.{max u2 u1, u2, u1} (ContinuousMap.{u2, u1} β γ _inst_2 _inst_3) β γ _inst_2 _inst_3 (ContinuousMap.instContinuousMapClassContinuousMap.{u2, u1} β γ _inst_2 _inst_3)) (Finset.sup'.{max u2 u1, u3} (ContinuousMap.{u2, u1} β γ _inst_2 _inst_3) ι (ContinuousMap.semilatticeSup.{u2, u1} β γ _inst_2 _inst_3 _inst_4 _inst_5) s H f)) (Finset.sup'.{max u2 u1, u3} (forall (a : β), (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : β) => γ) a) ι (Pi.semilatticeSup.{u2, u1} β (fun (ᾰ : β) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : β) => γ) ᾰ) (fun (i : β) => Lattice.toSemilatticeSup.{u1} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : β) => γ) i) (DistribLattice.toLattice.{u1} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : β) => γ) i) (instDistribLattice.{u1} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : β) => γ) i) _inst_4)))) s H (fun (a : ι) => FunLike.coe.{max (succ u2) (succ u1), succ u2, succ u1} (ContinuousMap.{u2, u1} β γ _inst_2 _inst_3) β (fun (_x : β) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : β) => γ) _x) (ContinuousMapClass.toFunLike.{max u2 u1, u2, u1} (ContinuousMap.{u2, u1} β γ _inst_2 _inst_3) β γ _inst_2 _inst_3 (ContinuousMap.instContinuousMapClassContinuousMap.{u2, u1} β γ _inst_2 _inst_3)) (f a)))
Case conversion may be inaccurate. Consider using '#align continuous_map.sup'_coe ContinuousMap.sup'_coeₓ'. -/
@[simp, norm_cast]
theorem sup'_coe {ι : Type _} {s : Finset ι} (H : s.Nonempty) (f : ι → C(β, γ)) :
    ((s.sup' H f : C(β, γ)) : ι → β) = s.sup' H fun a => (f a : β → γ) :=
  by
  ext
  simp [sup'_apply]
#align continuous_map.sup'_coe ContinuousMap.sup'_coe

end Sup'

section Inf'

variable [LinearOrder γ] [OrderClosedTopology γ]

/- warning: continuous_map.inf'_apply -> ContinuousMap.inf'_apply is a dubious translation:
lean 3 declaration is
  forall {β : Type.{u1}} {γ : Type.{u2}} [_inst_2 : TopologicalSpace.{u1} β] [_inst_3 : TopologicalSpace.{u2} γ] [_inst_4 : LinearOrder.{u2} γ] [_inst_5 : OrderClosedTopology.{u2} γ _inst_3 (PartialOrder.toPreorder.{u2} γ (SemilatticeInf.toPartialOrder.{u2} γ (Lattice.toSemilatticeInf.{u2} γ (LinearOrder.toLattice.{u2} γ _inst_4))))] {ι : Type.{u3}} {s : Finset.{u3} ι} (H : Finset.Nonempty.{u3} ι s) (f : ι -> (ContinuousMap.{u1, u2} β γ _inst_2 _inst_3)) (b : β), Eq.{succ u2} γ (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} β γ _inst_2 _inst_3) (fun (_x : ContinuousMap.{u1, u2} β γ _inst_2 _inst_3) => β -> γ) (ContinuousMap.hasCoeToFun.{u1, u2} β γ _inst_2 _inst_3) (Finset.inf'.{max u1 u2, u3} (ContinuousMap.{u1, u2} β γ _inst_2 _inst_3) ι (ContinuousMap.semilatticeInf.{u1, u2} β γ _inst_2 _inst_3 _inst_4 _inst_5) s H f) b) (Finset.inf'.{u2, u3} γ ι (Lattice.toSemilatticeInf.{u2} γ (LinearOrder.toLattice.{u2} γ _inst_4)) s H (fun (a : ι) => coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} β γ _inst_2 _inst_3) (fun (_x : ContinuousMap.{u1, u2} β γ _inst_2 _inst_3) => β -> γ) (ContinuousMap.hasCoeToFun.{u1, u2} β γ _inst_2 _inst_3) (f a) b))
but is expected to have type
  forall {β : Type.{u2}} {γ : Type.{u1}} [_inst_2 : TopologicalSpace.{u2} β] [_inst_3 : TopologicalSpace.{u1} γ] [_inst_4 : LinearOrder.{u1} γ] [_inst_5 : OrderClosedTopology.{u1} γ _inst_3 (PartialOrder.toPreorder.{u1} γ (SemilatticeInf.toPartialOrder.{u1} γ (Lattice.toSemilatticeInf.{u1} γ (DistribLattice.toLattice.{u1} γ (instDistribLattice.{u1} γ _inst_4)))))] {ι : Type.{u3}} {s : Finset.{u3} ι} (H : Finset.Nonempty.{u3} ι s) (f : ι -> (ContinuousMap.{u2, u1} β γ _inst_2 _inst_3)) (b : β), Eq.{succ u1} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : β) => γ) b) (FunLike.coe.{max (succ u2) (succ u1), succ u2, succ u1} (ContinuousMap.{u2, u1} β γ _inst_2 _inst_3) β (fun (_x : β) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : β) => γ) _x) (ContinuousMapClass.toFunLike.{max u2 u1, u2, u1} (ContinuousMap.{u2, u1} β γ _inst_2 _inst_3) β γ _inst_2 _inst_3 (ContinuousMap.instContinuousMapClassContinuousMap.{u2, u1} β γ _inst_2 _inst_3)) (Finset.inf'.{max u2 u1, u3} (ContinuousMap.{u2, u1} β γ _inst_2 _inst_3) ι (ContinuousMap.semilatticeInf.{u2, u1} β γ _inst_2 _inst_3 _inst_4 _inst_5) s H f) b) (Finset.inf'.{u1, u3} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : β) => γ) b) ι (Lattice.toSemilatticeInf.{u1} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : β) => γ) b) (DistribLattice.toLattice.{u1} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : β) => γ) b) (instDistribLattice.{u1} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : β) => γ) b) _inst_4))) s H (fun (a : ι) => FunLike.coe.{max (succ u2) (succ u1), succ u2, succ u1} (ContinuousMap.{u2, u1} β γ _inst_2 _inst_3) β (fun (_x : β) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : β) => γ) _x) (ContinuousMapClass.toFunLike.{max u2 u1, u2, u1} (ContinuousMap.{u2, u1} β γ _inst_2 _inst_3) β γ _inst_2 _inst_3 (ContinuousMap.instContinuousMapClassContinuousMap.{u2, u1} β γ _inst_2 _inst_3)) (f a) b))
Case conversion may be inaccurate. Consider using '#align continuous_map.inf'_apply ContinuousMap.inf'_applyₓ'. -/
theorem inf'_apply {ι : Type _} {s : Finset ι} (H : s.Nonempty) (f : ι → C(β, γ)) (b : β) :
    s.inf' H f b = s.inf' H fun a => f a b :=
  @sup'_apply _ γᵒᵈ _ _ _ _ _ _ H f b
#align continuous_map.inf'_apply ContinuousMap.inf'_apply

/- warning: continuous_map.inf'_coe -> ContinuousMap.inf'_coe is a dubious translation:
lean 3 declaration is
  forall {β : Type.{u1}} {γ : Type.{u2}} [_inst_2 : TopologicalSpace.{u1} β] [_inst_3 : TopologicalSpace.{u2} γ] [_inst_4 : LinearOrder.{u2} γ] [_inst_5 : OrderClosedTopology.{u2} γ _inst_3 (PartialOrder.toPreorder.{u2} γ (SemilatticeInf.toPartialOrder.{u2} γ (Lattice.toSemilatticeInf.{u2} γ (LinearOrder.toLattice.{u2} γ _inst_4))))] {ι : Type.{u3}} {s : Finset.{u3} ι} (H : Finset.Nonempty.{u3} ι s) (f : ι -> (ContinuousMap.{u1, u2} β γ _inst_2 _inst_3)), Eq.{max (succ u1) (succ u2)} ((fun (_x : ContinuousMap.{u1, u2} β γ _inst_2 _inst_3) => β -> γ) (Finset.inf'.{max u1 u2, u3} (ContinuousMap.{u1, u2} β γ _inst_2 _inst_3) ι (ContinuousMap.semilatticeInf.{u1, u2} β γ _inst_2 _inst_3 _inst_4 _inst_5) s H f)) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} β γ _inst_2 _inst_3) (fun (_x : ContinuousMap.{u1, u2} β γ _inst_2 _inst_3) => β -> γ) (ContinuousMap.hasCoeToFun.{u1, u2} β γ _inst_2 _inst_3) (Finset.inf'.{max u1 u2, u3} (ContinuousMap.{u1, u2} β γ _inst_2 _inst_3) ι (ContinuousMap.semilatticeInf.{u1, u2} β γ _inst_2 _inst_3 _inst_4 _inst_5) s H f)) (Finset.inf'.{max u1 u2, u3} ((fun (_x : ContinuousMap.{u1, u2} β γ _inst_2 _inst_3) => β -> γ) (Finset.inf'.{max u1 u2, u3} (ContinuousMap.{u1, u2} β γ _inst_2 _inst_3) ι (ContinuousMap.semilatticeInf.{u1, u2} β γ _inst_2 _inst_3 _inst_4 _inst_5) s H f)) ι (Pi.semilatticeInf.{u1, u2} β (fun (ᾰ : β) => γ) (fun (i : β) => Lattice.toSemilatticeInf.{u2} γ (LinearOrder.toLattice.{u2} γ _inst_4))) s H (fun (a : ι) => coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} β γ _inst_2 _inst_3) (fun (_x : ContinuousMap.{u1, u2} β γ _inst_2 _inst_3) => β -> γ) (ContinuousMap.hasCoeToFun.{u1, u2} β γ _inst_2 _inst_3) (f a)))
but is expected to have type
  forall {β : Type.{u2}} {γ : Type.{u1}} [_inst_2 : TopologicalSpace.{u2} β] [_inst_3 : TopologicalSpace.{u1} γ] [_inst_4 : LinearOrder.{u1} γ] [_inst_5 : OrderClosedTopology.{u1} γ _inst_3 (PartialOrder.toPreorder.{u1} γ (SemilatticeInf.toPartialOrder.{u1} γ (Lattice.toSemilatticeInf.{u1} γ (DistribLattice.toLattice.{u1} γ (instDistribLattice.{u1} γ _inst_4)))))] {ι : Type.{u3}} {s : Finset.{u3} ι} (H : Finset.Nonempty.{u3} ι s) (f : ι -> (ContinuousMap.{u2, u1} β γ _inst_2 _inst_3)), Eq.{max (succ u2) (succ u1)} (forall (a : β), (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : β) => γ) a) (FunLike.coe.{max (succ u2) (succ u1), succ u2, succ u1} (ContinuousMap.{u2, u1} β γ _inst_2 _inst_3) β (fun (_x : β) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : β) => γ) _x) (ContinuousMapClass.toFunLike.{max u2 u1, u2, u1} (ContinuousMap.{u2, u1} β γ _inst_2 _inst_3) β γ _inst_2 _inst_3 (ContinuousMap.instContinuousMapClassContinuousMap.{u2, u1} β γ _inst_2 _inst_3)) (Finset.inf'.{max u2 u1, u3} (ContinuousMap.{u2, u1} β γ _inst_2 _inst_3) ι (ContinuousMap.semilatticeInf.{u2, u1} β γ _inst_2 _inst_3 _inst_4 _inst_5) s H f)) (Finset.inf'.{max u2 u1, u3} (forall (a : β), (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : β) => γ) a) ι (Pi.semilatticeInf.{u2, u1} β (fun (ᾰ : β) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : β) => γ) ᾰ) (fun (i : β) => Lattice.toSemilatticeInf.{u1} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : β) => γ) i) (DistribLattice.toLattice.{u1} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : β) => γ) i) (instDistribLattice.{u1} ((fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : β) => γ) i) _inst_4)))) s H (fun (a : ι) => FunLike.coe.{max (succ u2) (succ u1), succ u2, succ u1} (ContinuousMap.{u2, u1} β γ _inst_2 _inst_3) β (fun (_x : β) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : β) => γ) _x) (ContinuousMapClass.toFunLike.{max u2 u1, u2, u1} (ContinuousMap.{u2, u1} β γ _inst_2 _inst_3) β γ _inst_2 _inst_3 (ContinuousMap.instContinuousMapClassContinuousMap.{u2, u1} β γ _inst_2 _inst_3)) (f a)))
Case conversion may be inaccurate. Consider using '#align continuous_map.inf'_coe ContinuousMap.inf'_coeₓ'. -/
@[simp, norm_cast]
theorem inf'_coe {ι : Type _} {s : Finset ι} (H : s.Nonempty) (f : ι → C(β, γ)) :
    ((s.inf' H f : C(β, γ)) : ι → β) = s.inf' H fun a => (f a : β → γ) :=
  @sup'_coe _ γᵒᵈ _ _ _ _ _ _ H f
#align continuous_map.inf'_coe ContinuousMap.inf'_coe

end Inf'

end Lattice

section Extend

variable [LinearOrder α] [OrderTopology α] {a b : α} (h : a ≤ b)

#print ContinuousMap.IccExtend /-
/-- Extend a continuous function `f : C(set.Icc a b, β)` to a function `f : C(α, β)`.
-/
def IccExtend (f : C(Set.Icc a b, β)) : C(α, β) :=
  ⟨Set.IccExtend h f⟩
#align continuous_map.Icc_extend ContinuousMap.IccExtend
-/

/- warning: continuous_map.coe_Icc_extend -> ContinuousMap.coe_IccExtend is a dubious translation:
lean 3 declaration is
  forall {α : Type.{u1}} {β : Type.{u2}} [_inst_1 : TopologicalSpace.{u1} α] [_inst_2 : TopologicalSpace.{u2} β] [_inst_4 : LinearOrder.{u1} α] [_inst_5 : OrderTopology.{u1} α _inst_1 (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_4))))] {a : α} {b : α} (h : LE.le.{u1} α (Preorder.toLE.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_4))))) a b) (f : ContinuousMap.{u1, u2} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} α) Type.{u1} (Set.hasCoeToSort.{u1} α) (Set.Icc.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_4)))) a b)) β (Subtype.topologicalSpace.{u1} α (fun (x : α) => Membership.Mem.{u1, u1} α (Set.{u1} α) (Set.hasMem.{u1} α) x (Set.Icc.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_4)))) a b)) _inst_1) _inst_2), Eq.{max (succ u1) (succ u2)} ((fun (_x : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) => α -> β) (ContinuousMap.IccExtend.{u1, u2} α β _inst_1 _inst_2 _inst_4 _inst_5 a b h f)) (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} α β _inst_1 _inst_2) (fun (_x : ContinuousMap.{u1, u2} α β _inst_1 _inst_2) => α -> β) (ContinuousMap.hasCoeToFun.{u1, u2} α β _inst_1 _inst_2) (ContinuousMap.IccExtend.{u1, u2} α β _inst_1 _inst_2 _inst_4 _inst_5 a b h f)) (Set.IccExtend.{u1, u2} α β _inst_4 a b h (coeFn.{max (succ u1) (succ u2), max (succ u1) (succ u2)} (ContinuousMap.{u1, u2} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} α) Type.{u1} (Set.hasCoeToSort.{u1} α) (Set.Icc.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_4)))) a b)) β (Subtype.topologicalSpace.{u1} α (fun (x : α) => Membership.Mem.{u1, u1} α (Set.{u1} α) (Set.hasMem.{u1} α) x (Set.Icc.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_4)))) a b)) _inst_1) _inst_2) (fun (_x : ContinuousMap.{u1, u2} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} α) Type.{u1} (Set.hasCoeToSort.{u1} α) (Set.Icc.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_4)))) a b)) β (Subtype.topologicalSpace.{u1} α (fun (x : α) => Membership.Mem.{u1, u1} α (Set.{u1} α) (Set.hasMem.{u1} α) x (Set.Icc.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_4)))) a b)) _inst_1) _inst_2) => (coeSort.{succ u1, succ (succ u1)} (Set.{u1} α) Type.{u1} (Set.hasCoeToSort.{u1} α) (Set.Icc.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_4)))) a b)) -> β) (ContinuousMap.hasCoeToFun.{u1, u2} (coeSort.{succ u1, succ (succ u1)} (Set.{u1} α) Type.{u1} (Set.hasCoeToSort.{u1} α) (Set.Icc.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_4)))) a b)) β (Subtype.topologicalSpace.{u1} α (fun (x : α) => Membership.Mem.{u1, u1} α (Set.{u1} α) (Set.hasMem.{u1} α) x (Set.Icc.{u1} α (PartialOrder.toPreorder.{u1} α (SemilatticeInf.toPartialOrder.{u1} α (Lattice.toSemilatticeInf.{u1} α (LinearOrder.toLattice.{u1} α _inst_4)))) a b)) _inst_1) _inst_2) f))
but is expected to have type
  forall {α : Type.{u2}} {β : Type.{u1}} [_inst_1 : TopologicalSpace.{u2} α] [_inst_2 : TopologicalSpace.{u1} β] [_inst_4 : LinearOrder.{u2} α] [_inst_5 : OrderTopology.{u2} α _inst_1 (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_4)))))] {a : α} {b : α} (h : LE.le.{u2} α (Preorder.toLE.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_4)))))) a b) (f : ContinuousMap.{u2, u1} (Set.Elem.{u2} α (Set.Icc.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_4))))) a b)) β (instTopologicalSpaceSubtype.{u2} α (fun (x : α) => Membership.mem.{u2, u2} α (Set.{u2} α) (Set.instMembershipSet.{u2} α) x (Set.Icc.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_4))))) a b)) _inst_1) _inst_2), Eq.{max (succ u2) (succ u1)} (forall (a : α), (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) a) (FunLike.coe.{max (succ u2) (succ u1), succ u2, succ u1} (ContinuousMap.{u2, u1} α β _inst_1 _inst_2) α (fun (_x : α) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : α) => β) _x) (ContinuousMapClass.toFunLike.{max u2 u1, u2, u1} (ContinuousMap.{u2, u1} α β _inst_1 _inst_2) α β _inst_1 _inst_2 (ContinuousMap.instContinuousMapClassContinuousMap.{u2, u1} α β _inst_1 _inst_2)) (ContinuousMap.IccExtend.{u2, u1} α β _inst_1 _inst_2 _inst_4 _inst_5 a b h f)) (Set.IccExtend.{u2, u1} α β _inst_4 a b h (FunLike.coe.{max (succ u2) (succ u1), succ u2, succ u1} (ContinuousMap.{u2, u1} (Set.Elem.{u2} α (Set.Icc.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_4))))) a b)) β (instTopologicalSpaceSubtype.{u2} α (fun (x : α) => Membership.mem.{u2, u2} α (Set.{u2} α) (Set.instMembershipSet.{u2} α) x (Set.Icc.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_4))))) a b)) _inst_1) _inst_2) (Set.Elem.{u2} α (Set.Icc.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_4))))) a b)) (fun (_x : Set.Elem.{u2} α (Set.Icc.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_4))))) a b)) => (fun (x._@.Mathlib.Topology.ContinuousFunction.Basic._hyg.699 : Set.Elem.{u2} α (Set.Icc.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_4))))) a b)) => β) _x) (ContinuousMapClass.toFunLike.{max u2 u1, u2, u1} (ContinuousMap.{u2, u1} (Set.Elem.{u2} α (Set.Icc.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_4))))) a b)) β (instTopologicalSpaceSubtype.{u2} α (fun (x : α) => Membership.mem.{u2, u2} α (Set.{u2} α) (Set.instMembershipSet.{u2} α) x (Set.Icc.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_4))))) a b)) _inst_1) _inst_2) (Set.Elem.{u2} α (Set.Icc.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_4))))) a b)) β (instTopologicalSpaceSubtype.{u2} α (fun (x : α) => Membership.mem.{u2, u2} α (Set.{u2} α) (Set.instMembershipSet.{u2} α) x (Set.Icc.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_4))))) a b)) _inst_1) _inst_2 (ContinuousMap.instContinuousMapClassContinuousMap.{u2, u1} (Set.Elem.{u2} α (Set.Icc.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_4))))) a b)) β (instTopologicalSpaceSubtype.{u2} α (fun (x : α) => Membership.mem.{u2, u2} α (Set.{u2} α) (Set.instMembershipSet.{u2} α) x (Set.Icc.{u2} α (PartialOrder.toPreorder.{u2} α (SemilatticeInf.toPartialOrder.{u2} α (Lattice.toSemilatticeInf.{u2} α (DistribLattice.toLattice.{u2} α (instDistribLattice.{u2} α _inst_4))))) a b)) _inst_1) _inst_2)) f))
Case conversion may be inaccurate. Consider using '#align continuous_map.coe_Icc_extend ContinuousMap.coe_IccExtendₓ'. -/
@[simp]
theorem coe_IccExtend (f : C(Set.Icc a b, β)) :
    ((IccExtend h f : C(α, β)) : α → β) = Set.IccExtend h f :=
  rfl
#align continuous_map.coe_Icc_extend ContinuousMap.coe_IccExtend

end Extend

end ContinuousMap


import algebra
import tactic.linarith

import config.defs

variables {α : Type*} [linear_order α] {C : config α}

namespace config

namespace cap

@[simp] protected theorem nil : C.cap [] :=
  by rw config.cap; tauto

@[simp] protected theorem singleton (a : α) : C.cap [a] :=
  by rw config.cap; simp

@[simp] protected theorem pair {a b : α} : C.cap [a, b] ↔ a < b :=
  by rw config.cap; simp; tauto

@[simp] protected theorem cons3 {a b c : α} {l : list α} :
  C.cap (a :: b :: c :: l) ↔
  a < b ∧ C.cap3 a b c ∧ C.cap (b :: c :: l) :=
by repeat {rw config.cap}; simp; tauto

@[simp] protected theorem append_cons3 {a b c : α} {l1 l2 : list α} :
  C.cap (l1 ++ a :: b :: c :: l2) ↔
    C.cap (l1 ++ [a, b]) ∧ C.cap3 a b c ∧ C.cap (b :: c :: l2) :=
begin
  induction l1 with d l1,
  {simp [config.cap]; tauto},
  cases l1 with e l1,
  {simp [config.cap]; tauto},
  cases l1 with f l1,
  {simp [config.cap]; tauto},
  simp, simp at l1_ih, rw l1_ih, tauto,
end

protected theorem init {l : list α} (h : C.cap l) : C.cap l.init :=
begin
  induction l with a l,
  {simp [config.cap]; tauto},
  cases l with b l,
  {simp [config.cap]; tauto},
  cases l with c l,
  {simp [config.cap, list.init] at *},
  cases l with d l,
  {simp [config.cap, list.init] at *, tauto},
  simp [list.init] at *, tauto,
end

protected theorem tail {l : list α} (h : C.cap l) : C.cap l.tail :=
begin
  induction l with a l,
  {simp [config.cap]; tauto},
  cases l with b l,
  {simp [config.cap]; tauto},
  cases l with c l,
  {simp [config.cap] at *},
  cases l with d l,
  {simp [config.cap] at *, tauto},
  simp [list.init] at *, tauto,
end

end cap

namespace ncap

protected theorem init {n : ℕ} {l : list α} (h : C.ncap (n+1) l) : C.ncap n l.init :=
begin
  cases l with a l,
  { simp [config.ncap, config.cap] at h, cases h },
  simp [config.ncap] at *, cases h with hc hl,
  split, exact hc.init, assumption,
end

protected theorem tail {n : ℕ} {l : list α} (h : C.ncap (n+1) l) : C.ncap n l.tail :=
begin
  cases l with a l,
  { simp [config.ncap, config.cap] at h, cases h },
  simp [config.ncap] at *, cases h with hc hl,
  split, exact hc.tail, assumption,
end

end ncap

namespace cup

@[simp] protected theorem nil : C.cup [] :=
  by rw config.cup; tauto

@[simp] protected theorem singleton (a : α) : C.cup [a] :=
  by rw config.cup; simp

@[simp] protected theorem pair {a b : α} : C.cup [a, b] ↔ a < b :=
  by rw config.cup; simp; tauto

@[simp] protected theorem cons3 {a b c : α} {l : list α} :
  C.cup (a :: b :: c :: l) ↔
  a < b ∧ C.cup3 a b c ∧ C.cup (b :: c :: l) :=
by repeat {rw config.cup}; simp; tauto

@[simp] protected theorem append_cons3 {a b c : α} {l1 l2 : list α} :
  C.cup (l1 ++ a :: b :: c :: l2) ↔
    C.cup (l1 ++ [a, b]) ∧ C.cup3 a b c ∧ C.cup (b :: c :: l2) :=
begin
  induction l1 with d l1,
  {simp [config.cup]; tauto},
  cases l1 with e l1,
  {simp [config.cup]; tauto},
  cases l1 with f l1,
  {simp [config.cup]; tauto},
  simp, simp at l1_ih, rw l1_ih, tauto,
end

protected theorem init {l : list α} (h : C.cup l) : C.cup l.init :=
  ⟨h.left.init, h.right.init⟩

protected theorem take {l : list α} (h : C.cup l) (n : ℕ) : C.cup (l.take n) :=
  ⟨h.left.take n, h.right.take n⟩

protected theorem drop {l : list α} (h : C.cup l) (n : ℕ) : C.cup (l.drop n) :=
  ⟨h.left.drop n, h.right.drop n⟩

protected theorem tail {l : list α} (h : C.cup l) : C.cup l.tail :=
  ⟨h.left.tail, h.right.tail⟩

theorem head'_lt_last'
  {l : list α} (l_cup : C.cup l) (p q : α)
  (hl : 2 ≤ l.length) (hp : p ∈ l.head') (hq : q ∈ l.last') : p < q :=
begin
  cases l with p l,
  {simp at hp, exfalso, tauto},
  simp at hp, subst hp,
  have l_nnil : l ≠ [] := by
    intro h; subst h; simp at hl; exact nat.lt_asymm hl hl,
  rcases list.take_last l_nnil with ⟨q, l', eq_l⟩,
  rw eq_l at hq, simp at hq, subst hq,
  rw [config.cup, eq_l] at l_cup,
  cases l_cup with l_sorted _,
  rw list.chain'_iff_pairwise at l_sorted, simp at l_sorted,
  have h' := l_sorted.left q, tauto,
end

end cup

namespace ncup

@[simp] protected theorem nil : C.ncup 0 [] :=
  by rw [config.ncup, config.cup]; tauto

@[simp] protected theorem singleton (a : α) : C.ncup 1 [a] :=
  by rw [config.ncup, config.cup]; simp

@[simp] protected theorem pair {a b : α} : C.ncup 2 [a, b] ↔ a < b :=
  by rw [config.ncup, config.cup]; simp; tauto

@[simp] protected theorem cons3 {n : ℕ} {a b c : α} {l : list α} :
  C.ncup (n + 1) (a :: b :: c :: l) ↔
  a < b ∧ C.cup3 a b c ∧ C.ncup n (b :: c :: l) :=
by repeat {rw [config.ncup, config.cup]}; simp; tauto

protected theorem init {n : ℕ} {l : list α}
  (h : C.ncup (n+1) l) : C.ncup n l.init :=
begin
  cases l with a l,
  { simp [config.ncup, config.cup] at h, cases h },
  simp [config.ncup] at *, cases h with hc hl,
  split, exact hc.init, assumption,
end

protected theorem init_append_last {n : ℕ} {l : list α}
  (h : C.ncup (n+1) l) :
  ∃ (l' : list α) (a : α), l = l' ++ [a] ∧ C.ncup n l' :=
begin
  cases l with a l,
  { simp [config.ncup, config.cup] at h, cases h },
  have nnil : a :: l ≠ [] := by simp,
  use [(a :: l).init, (a :: l).last nnil], split,
  apply symm, exact list.init_append_last nnil,
  exact h.init,
end

protected theorem tail {n : ℕ} {l : list α}
  (h : C.ncup (n+1) l) : C.ncup n l.tail :=
begin
  cases l with a l,
  { simp [config.ncup, config.cup] at h, cases h },
  simp at *, cases h with hc hl,
  split, exact hc.tail, simp at hl, assumption,
end

protected theorem cons_head_tail {n : ℕ} {l : list α}
  (h : C.ncup (n+1) l) :
  ∃ (a : α) (l' : list α), l = a :: l' ∧ C.ncup n l' :=
begin
  cases l with a l,
  { simp [config.ncup, config.cup] at h, cases h },
  simp [config.ncup] at *, cases h with hc hl,
  use [a, l], have hc' := hc.tail, simp at hc', tauto,
end

protected theorem take_head_last {n : ℕ} {l : list α}
  (h : C.ncup (n+2) l) :
  ∃ (a : α) (l' : list α) (b : α), l = a :: l' ++ [b] ∧ C.ncup n l' :=
begin
  rcases h.cons_head_tail with ⟨a, l', eq_l, cup_l'⟩,
  rcases cup_l'.init_append_last with ⟨l'', b, eq_l', cup_l''⟩,
  use [a, l'', b], split,
  rw [eq_l, eq_l'], simp, assumption,
end

theorem take_left_with_head {n : ℕ} {l : list α} (h : C.ncup n l)
  (m : ℕ) (p : α) : 1 ≤ m → m ≤ n → p ∈ l.head' →
  ∃ (l' : list α), l' ⊆ l ∧ C.ncup m l' ∧ p ∈ l'.head' :=
begin
  intros one_le_m m_le_n l_last,
  use l.take m, refine ⟨_, _, _⟩,
  { exact list.take_subset m l },
  { refine ⟨h.left.take m, _⟩, simp, rw h.right, assumption, },
  { rw ←list.take_append_drop m l at l_last,
    rw list.head'_append_of_ne_nil at l_last, exact l_last,
    rw ←h.right at m_le_n,
    intro hnil, simp at hnil, cases hnil,
    subst hnil, simp at m_le_n, linarith,
    linarith, },
end

theorem take_right_with_last {n : ℕ} {l : list α} (h : C.ncup n l)
  (m : ℕ) (p : α) : 1 ≤ m → m ≤ n → p ∈ l.last' →
  ∃ (l' : list α), l' ⊆ l ∧ C.ncup m l' ∧ p ∈ l'.last' :=
begin
  intros one_le_m m_le_n l_last,
  use l.drop (n - m), refine ⟨_, _, _⟩,
  { exact list.drop_subset (n - m) l },
  { split, exact h.left.drop (n - m), simp, rw h.right,
    exact nat.sub_sub_self m_le_n },
  { rw ←list.take_append_drop (n - m) l at l_last,
    rw list.last'_append_of_ne_nil at l_last, exact l_last,
    rw ←h.right at m_le_n,
    intro hnil, rw [←list.reverse_eq_nil, ←h.right,
      ←list.reverse_take _ m_le_n] at hnil,
    simp at hnil, cases hnil,
    have h' := h.right, subst hnil, simp at h', subst h',
    simp at m_le_n, linarith,
    subst hnil, linarith, },
end

theorem head'_lt_last' {n : ℕ} {l : list α} (l_ncup : C.ncup (n+2) l)
  (p q : α) (hp : p ∈ l.head') (hq : q ∈ l.last') : p < q :=
begin
  cases l_ncup with l_cup l_length,
  apply l_cup.head'_lt_last' p q,
  rw l_length, exact le_add_self,
  assumption, assumption,
end

theorem head'_le_last' {n : ℕ} {l : list α} (l_ncup : C.ncup n l)
  (p q : α) (hp : p ∈ l.head') (hq : q ∈ l.last') : p ≤ q :=
begin
  have l_sorted : l.sorted (<) := begin
    rw [list.sorted, ←list.chain'_iff_pairwise],
    exact l_ncup.left.left, end,
  cases l_ncup with l_cup l_length,
  cases l with p l, simp at hp, exfalso, exact hp,
  simp at hp, subst hp,
  cases l with p' l, simp at hq, subst hq,
  rw list.last'_cons_cons at hq,
  set l' := p' :: l, clear_value l',
  simp at l_sorted,
  apply le_of_lt, apply l_sorted.left,
  exact list.mem_of_mem_last' hq,
end

end ncup

end config

theorem ncup_is_ngon {n : ℕ} {S : finset α}
  (hn : 2 ≤ n) (h : C.has_ncup n S) : C.has_ngon n S :=
begin
  rcases h with ⟨c, ⟨⟨c_cup, c_length⟩, c_in_S⟩⟩,
  have hc : c ≠ [] :=
    by cases c; subst c_length; simp at hn; tauto,
  rcases list.take_last hc with ⟨y, c, eq_c⟩, subst eq_c,
  have hc : c ≠ [] :=
    by intro h; subst c_length; subst h; simp at hn; exact nat.lt_asymm hn hn,
  rcases list.take_head hc with ⟨x, c, eq_c⟩, subst eq_c,
  clear hc hc,

  use [[x, y], x :: c ++ [y]],
  refine ⟨_, _, _⟩; try {simp; simp at c_in_S; tauto},
  rw [config.ngon, config.gon], simp,
  have hxy : x < y := begin
    apply c_cup.head'_lt_last' x y,
    simp, exact inf_eq_left.mp rfl, simp, simp,
  end,
  simp at c_length, rw c_length, split, tauto, linarith,
end

theorem has_ncap_supset {n : ℕ} {S1 S2 : finset α} (h : S1 ⊆ S2)
  (h1 : C.has_ncap n S1) : C.has_ncap n S2 :=
begin
  cases h1 with c1 h1,
  use c1, split, exact h1.left,
  intros a a_c1, exact h (h1.right a a_c1),
end

theorem has_ncup_supset {n : ℕ} {S1 S2 : finset α} (h : S1 ⊆ S2)
  (h1 : C.has_ncup n S1) : C.has_ncup n S2 :=
begin
  cases h1 with c1 h1,
  use c1, split, exact h1.left,
  intros a a_c1, exact h (h1.right a a_c1),
end

theorem has_ngon_supset {n : ℕ} {S1 S2 : finset α} (h : S1 ⊆ S2)
  (h1 : C.has_ngon n S1) : C.has_ngon n S2 :=
begin
  rcases h1 with ⟨c1, c2, ⟨gon, c1_in, c2_in⟩⟩,
  existsi [c1, c2], refine ⟨gon, _, _⟩,
  intros a a_c1, apply h, exact c1_in a a_c1,
  intros a a_c2, apply h, exact c2_in a a_c2,
end

theorem has_ncup_le {n m : ℕ} {S : finset α} (h : n ≤ m) :
  C.has_ncup m S → C.has_ncup n S :=
begin
  intro ngon,
  rcases ngon with ⟨c, ⟨⟨c_cup, c_length⟩, c_in⟩⟩,
  use (c.take n), split,
  { split, exact c_cup.take n, simp, rw c_length, exact h, },
  { intros a ha, apply c_in, exact (list.take_subset _ _ ha), }
end


import Mathlib

namespace List

variable {α} [DecidableEq α] (a : α) (as bs cs : List α)

/-!
# Count 统计元素出现次数
-/

theorem count_nil : [].count a = 0 := rfl

theorem count_cons_length : as.count a = n → (a::as).count a = n + 1 := by
  induction as <;> simp_all [List.count, List.countp]

theorem count_join : ((bs ++ cs).count a) = bs.count a + cs.count a := by
  induction bs
  . simp [List.count, List.countp]
  . rename_i inst head tail ih
    by_cases h : a = head
    <;> simp_all [h, List.count, List.countp]
    <;> simp_arith

theorem length_cons_gt_zero : (a::as).length > 0 := by
  simp [List.length]
  simp_arith

theorem length_cons_lt : as.length < (a::as).length := by
  simp [List.length, List.length_cons]

theorem replicate_count : (List.replicate n a).count a = n := by
  induction n <;> simp [List.count, List.countp, List.replicate]
  assumption

end List


/-
Copyright (c) 2019 Scott Morrison. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Scott Morrison
-/
import Mathlib.PrePort
import Mathlib.Lean3Lib.init.default
import Mathlib.topology.category.Top.open_nhds
import Mathlib.topology.sheaves.presheaf
import Mathlib.category_theory.limits.limits
import Mathlib.category_theory.limits.types
import Mathlib.PostPort

universes u v u_1

namespace Mathlib

namespace Top.presheaf

/-- Stalks are functorial with respect to morphisms of presheaves over a fixed `X`. -/
def stalk_functor (C : Type u) [category_theory.category C] [category_theory.limits.has_colimits C]
    {X : Top} (x : ↥X) : presheaf C X ⥤ C :=
  category_theory.functor.obj
      (category_theory.whiskering_left (topological_space.open_nhds xᵒᵖ)
        (topological_space.opens ↥Xᵒᵖ) C)
      (category_theory.functor.op (topological_space.open_nhds.inclusion x)) ⋙
    category_theory.limits.colim

/--
The stalk of a presheaf `F` at a point `x` is calculated as the colimit of the functor
nbhds x ⥤ opens F.X ⥤ C
-/
def stalk {C : Type u} [category_theory.category C] [category_theory.limits.has_colimits C]
    {X : Top} (ℱ : presheaf C X) (x : ↥X) : C :=
  category_theory.functor.obj (stalk_functor C x) ℱ

@[simp] theorem stalk_functor_obj {C : Type u} [category_theory.category C]
    [category_theory.limits.has_colimits C] {X : Top} (ℱ : presheaf C X) (x : ↥X) :
    category_theory.functor.obj (stalk_functor C x) ℱ = stalk ℱ x :=
  rfl

/--
The germ of a section of a presheaf over an open at a point of that open.
-/
def germ {C : Type u} [category_theory.category C] [category_theory.limits.has_colimits C] {X : Top}
    (F : presheaf C X) {U : topological_space.opens ↥X} (x : ↥U) :
    category_theory.functor.obj F (opposite.op U) ⟶ stalk F ↑x :=
  category_theory.limits.colimit.ι
    (category_theory.functor.op (topological_space.open_nhds.inclusion (subtype.val x)) ⋙ F)
    (opposite.op { val := U, property := sorry })

/-- For a `Type` valued presheaf, every point in a stalk is a germ. -/
theorem germ_exist {X : Top} (F : presheaf (Type v) X) (x : ↥X) (t : stalk F x) :
    ∃ (U : topological_space.opens ↥X),
        ∃ (m : x ∈ U),
          ∃ (s : category_theory.functor.obj F (opposite.op U)),
            germ F { val := x, property := m } s = t :=
  sorry

theorem germ_eq {X : Top} (F : presheaf (Type v) X) {U : topological_space.opens ↥X}
    {V : topological_space.opens ↥X} (x : ↥X) (mU : x ∈ U) (mV : x ∈ V)
    (s : category_theory.functor.obj F (opposite.op U))
    (t : category_theory.functor.obj F (opposite.op V))
    (h : germ F { val := x, property := mU } s = germ F { val := x, property := mV } t) :
    ∃ (W : topological_space.opens ↥X),
        ∃ (m : x ∈ W),
          ∃ (iU : W ⟶ U),
            ∃ (iV : W ⟶ V),
              category_theory.functor.map F (category_theory.has_hom.hom.op iU) s =
                category_theory.functor.map F (category_theory.has_hom.hom.op iV) t :=
  sorry

@[simp] theorem germ_res {C : Type u} [category_theory.category C]
    [category_theory.limits.has_colimits C] {X : Top} (F : presheaf C X)
    {U : topological_space.opens ↥X} {V : topological_space.opens ↥X} (i : U ⟶ V) (x : ↥U) :
    category_theory.functor.map F (category_theory.has_hom.hom.op i) ≫ germ F x =
        germ F (coe_fn i x) :=
  sorry

@[simp] theorem germ_res_apply {X : Top} (F : presheaf (Type v) X) {U : topological_space.opens ↥X}
    {V : topological_space.opens ↥X} (i : U ⟶ V) (x : ↥U)
    (f : category_theory.functor.obj F (opposite.op V)) :
    germ F x (category_theory.functor.map F (category_theory.has_hom.hom.op i) f) =
        germ F (coe_fn i x) f :=
  sorry

/-- A variant when the open sets are written in `(opens X)ᵒᵖ`. -/
@[simp] theorem germ_res_apply' {X : Top} (F : presheaf (Type v) X)
    {U : topological_space.opens ↥Xᵒᵖ} {V : topological_space.opens ↥Xᵒᵖ} (i : V ⟶ U)
    (x : ↥(opposite.unop U)) (f : category_theory.functor.obj F V) :
    germ F x (category_theory.functor.map F i f) =
        germ F (coe_fn (category_theory.has_hom.hom.unop i) x) f :=
  sorry

theorem germ_ext {X : Top} {D : Type u} [category_theory.category D]
    [category_theory.concrete_category D] [category_theory.limits.has_colimits D] (F : presheaf D X)
    {U : topological_space.opens ↥X} {V : topological_space.opens ↥X} {x : ↥X} {hxU : x ∈ U}
    {hxV : x ∈ V} (W : topological_space.opens ↥X) (hxW : x ∈ W) (iWU : W ⟶ U) (iWV : W ⟶ V)
    {sU : ↥(category_theory.functor.obj F (opposite.op U))}
    {sV : ↥(category_theory.functor.obj F (opposite.op V))}
    (ih :
      coe_fn (category_theory.functor.map F (category_theory.has_hom.hom.op iWU)) sU =
        coe_fn (category_theory.functor.map F (category_theory.has_hom.hom.op iWV)) sV) :
    coe_fn (germ F { val := x, property := hxU }) sU =
        coe_fn (germ F { val := x, property := hxV }) sV :=
  sorry

theorem stalk_hom_ext {C : Type u} [category_theory.category C]
    [category_theory.limits.has_colimits C] {X : Top} (F : presheaf C X) {x : ↥X} {Y : C}
    {f₁ : stalk F x ⟶ Y} {f₂ : stalk F x ⟶ Y}
    (ih :
      ∀ (U : topological_space.opens ↥X) (hxU : x ∈ U),
        germ F { val := x, property := hxU } ≫ f₁ = germ F { val := x, property := hxU } ≫ f₂) :
    f₁ = f₂ :=
  sorry

def stalk_pushforward (C : Type u) [category_theory.category C]
    [category_theory.limits.has_colimits C] {X : Top} {Y : Top} (f : X ⟶ Y) (ℱ : presheaf C X)
    (x : ↥X) : stalk (f _* ℱ) (coe_fn f x) ⟶ stalk ℱ x :=
  category_theory.functor.map category_theory.limits.colim
      (category_theory.whisker_right
        (category_theory.nat_trans.op
          (category_theory.iso.inv (topological_space.open_nhds.inclusion_map_iso f x)))
        ℱ) ≫
    category_theory.limits.colimit.pre
      (category_theory.functor.obj
        (category_theory.functor.obj
          (category_theory.whiskering_left (topological_space.open_nhds xᵒᵖ)
            (topological_space.opens ↥Xᵒᵖ) C)
          (category_theory.functor.op (topological_space.open_nhds.inclusion x)))
        ℱ)
      (category_theory.functor.op (topological_space.open_nhds.map f x))

-- Here are two other potential solutions, suggested by @fpvandoorn at

-- <https://github.com/leanprover-community/mathlib/pull/1018#discussion_r283978240>

-- However, I can't get the subsequent two proofs to work with either one.

-- def stalk_pushforward (f : X ⟶ Y) (ℱ : X.presheaf C) (x : X) : (f _* ℱ).stalk (f x) ⟶ ℱ.stalk x :=

-- colim.map ((functor.associator _ _ _).inv ≫

--   whisker_right (nat_trans.op (open_nhds.inclusion_map_iso f x).inv) ℱ) ≫

-- colimit.pre ((open_nhds.inclusion x).op ⋙ ℱ) (open_nhds.map f x).op

-- def stalk_pushforward (f : X ⟶ Y) (ℱ : X.presheaf C) (x : X) : (f _* ℱ).stalk (f x) ⟶ ℱ.stalk x :=

-- (colim.map (whisker_right (nat_trans.op (open_nhds.inclusion_map_iso f x).inv) ℱ) :

--   colim.obj ((open_nhds.inclusion (f x) ⋙ opens.map f).op ⋙ ℱ) ⟶ _) ≫

-- colimit.pre ((open_nhds.inclusion x).op ⋙ ℱ) (open_nhds.map f x).op

namespace stalk_pushforward

@[simp] theorem id (C : Type u) [category_theory.category C] [category_theory.limits.has_colimits C]
    {X : Top} (ℱ : presheaf C X) (x : ↥X) :
    stalk_pushforward C 𝟙 ℱ x =
        category_theory.functor.map (stalk_functor C x)
          (category_theory.iso.hom (pushforward.id ℱ)) :=
  sorry

-- This proof is sadly not at all robust:

-- having to use `erw` at all is a bad sign.

@[simp] theorem comp (C : Type u) [category_theory.category C]
    [category_theory.limits.has_colimits C] {X : Top} {Y : Top} {Z : Top} (ℱ : presheaf C X)
    (f : X ⟶ Y) (g : Y ⟶ Z) (x : ↥X) :
    stalk_pushforward C (f ≫ g) ℱ x =
        stalk_pushforward C g (f _* ℱ) (coe_fn f x) ≫ stalk_pushforward C f ℱ x :=
  sorry

end Mathlib


import filter_world.level2 --hide
open set --hide
namespace filters --hide
localized "notation `P` := principal" in filters --hide

/-
# Level 3: The bottom filter
-/

/- Lemma
There exists a bottom filter among the filters of a given set.
-/
lemma top_bottom_filters {X : Type}: ∃ (B T : filter X), ∀ (F : filter X), B ≤ F ∧ F ≤ T :=
begin
  use P ∅,
  use P univ,
  intro F,
  split,
  {
    intros A hA,
    have h_emp : (∅ : set X) ∈ P (∅ : set X),
    { rw mem_principal },
    have h_emp_A : (∅ : set X) ⊆ A,
    { exact empty_subset A },
    exact filter.sets_of_superset (P ∅) h_emp h_emp_A
  },
  {
    intros A hA,
    obtain h_uni := (univ_filter_univ A).1 hA,
    rw h_uni,
    exact filter.univ_sets F
  }

end

end filters --hide


def g (t : Nat) : Nat := match t with
  | (n+1) => match g n with
    | 0 => 0
    | m + 1 => match g (n - m) with
      | 0 => 0
      | m + 1 => g n
  | 0 => 0
termination_by' sorry
decreasing_by sorry

attribute [simp] g

#check g._eq_1
#check g._eq_2

theorem ex3 : g (n + 1) = match g n with
    | 0 => 0
    | m + 1 => match g (n - m) with
      | 0 => 0
      | m + 1 => g n := by
  conv => lhs; unfold g


/-
Copyright (c) 2021 Martin Dvorak. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Martin Dvorak, Kyle Miller, Eric Wieser

! This file was ported from Lean 3 source module linear_algebra.cross_product
! leanprover-community/mathlib commit 91288e351d51b3f0748f0a38faa7613fb0ae2ada
! Please do not edit these lines, except to modify the commit id
! if you have ported upstream changes.
-/
import Mathbin.Data.Matrix.Notation
import Mathbin.LinearAlgebra.BilinearMap
import Mathbin.LinearAlgebra.Matrix.Determinant
import Mathbin.Algebra.Lie.Basic

/-!
# Cross products

This module defines the cross product of vectors in $R^3$ for $R$ a commutative ring,
as a bilinear map.

## Main definitions

* `cross_product` is the cross product of pairs of vectors in $R^3$.

## Main results

* `triple_product_eq_det`
* `cross_dot_cross`
* `jacobi_cross`

## Notation

The locale `matrix` gives the following notation:

* `×₃` for the cross product

## Tags

crossproduct
-/

open Matrix

open Matrix

variable {R : Type _} [CommRing R]

/-- The cross product of two vectors in $R^3$ for $R$ a commutative ring. -/
def crossProduct : (Fin 3 → R) →ₗ[R] (Fin 3 → R) →ₗ[R] Fin 3 → R :=
  by
  apply
    LinearMap.mk₂ R fun a b : Fin 3 → R =>
      ![a 1 * b 2 - a 2 * b 1, a 2 * b 0 - a 0 * b 2, a 0 * b 1 - a 1 * b 0]
  · intros
    simp [vec3_add (_ : R), add_comm, add_assoc, add_left_comm, add_mul, sub_eq_add_neg]
  · intros
    simp [smul_vec3 (_ : R) (_ : R), mul_comm, mul_assoc, mul_left_comm, mul_add, sub_eq_add_neg]
  · intros
    simp [vec3_add (_ : R), add_comm, add_assoc, add_left_comm, mul_add, sub_eq_add_neg]
  · intros
    simp [smul_vec3 (_ : R) (_ : R), mul_comm, mul_assoc, mul_left_comm, mul_add, sub_eq_add_neg]
#align cross_product crossProduct

-- mathport name: cross_product
scoped[Matrix] infixl:74 " ×₃ " => crossProduct

theorem cross_apply (a b : Fin 3 → R) :
    a ×₃ b = ![a 1 * b 2 - a 2 * b 1, a 2 * b 0 - a 0 * b 2, a 0 * b 1 - a 1 * b 0] :=
  rfl
#align cross_apply cross_apply

section ProductsProperties

@[simp]
theorem cross_anticomm (v w : Fin 3 → R) : -(v ×₃ w) = w ×₃ v := by simp [cross_apply, mul_comm]
#align cross_anticomm cross_anticomm

alias cross_anticomm ← neg_cross
#align neg_cross neg_cross

@[simp]
theorem cross_anticomm' (v w : Fin 3 → R) : v ×₃ w + w ×₃ v = 0 := by
  rw [add_eq_zero_iff_eq_neg, cross_anticomm]
#align cross_anticomm' cross_anticomm'

@[simp]
theorem cross_self (v : Fin 3 → R) : v ×₃ v = 0 := by simp [cross_apply, mul_comm]
#align cross_self cross_self

/-- The cross product of two vectors is perpendicular to the first vector. -/
@[simp]
theorem dot_self_cross (v w : Fin 3 → R) : v ⬝ᵥ v ×₃ w = 0 := by
  simp [cross_apply, vec3_dot_product, mul_sub, mul_assoc, mul_left_comm]
#align dot_self_cross dot_self_cross

/-- The cross product of two vectors is perpendicular to the second vector. -/
@[simp]
theorem dot_cross_self (v w : Fin 3 → R) : w ⬝ᵥ v ×₃ w = 0 := by
  rw [← cross_anticomm, Matrix.dotProduct_neg, dot_self_cross, neg_zero]
#align dot_cross_self dot_cross_self

/-- Cyclic permutations preserve the triple product. See also `triple_product_eq_det`. -/
theorem triple_product_permutation (u v w : Fin 3 → R) : u ⬝ᵥ v ×₃ w = v ⬝ᵥ w ×₃ u :=
  by
  simp only [cross_apply, vec3_dot_product, Matrix.head_cons, Matrix.cons_vec_bit0_eq_alt0,
    Matrix.empty_vecAppend, Matrix.cons_val_one, Matrix.cons_vecAlt0, Matrix.cons_vecAppend,
    Matrix.cons_val_zero]
  ring
#align triple_product_permutation triple_product_permutation

/-- The triple product of `u`, `v`, and `w` is equal to the determinant of the matrix
    with those vectors as its rows. -/
theorem triple_product_eq_det (u v w : Fin 3 → R) : u ⬝ᵥ v ×₃ w = Matrix.det ![u, v, w] :=
  by
  simp only [vec3_dot_product, cross_apply, Matrix.det_fin_three, Matrix.head_cons,
    Matrix.cons_vec_bit0_eq_alt0, Matrix.empty_vecAlt0, Matrix.cons_vecAlt0, Matrix.vecHead_vecAlt0,
    Matrix.vecAppend_apply_zero, Matrix.empty_vecAppend, Matrix.cons_vecAppend, Matrix.cons_val',
    Matrix.cons_val_one, Matrix.cons_val_zero]
  ring
#align triple_product_eq_det triple_product_eq_det

/-- The scalar quadruple product identity, related to the Binet-Cauchy identity. -/
theorem cross_dot_cross (u v w x : Fin 3 → R) :
    u ×₃ v ⬝ᵥ w ×₃ x = u ⬝ᵥ w * v ⬝ᵥ x - u ⬝ᵥ x * v ⬝ᵥ w :=
  by
  simp only [vec3_dot_product, cross_apply, cons_vec_append, cons_vec_bit0_eq_alt0, cons_val_one,
    cons_vec_alt0, LinearMap.mk₂_apply, cons_val_zero, head_cons, empty_vec_append]
  ring_nf
#align cross_dot_cross cross_dot_cross

end ProductsProperties

section LeibnizProperties

/-- The cross product satisfies the Leibniz lie property. -/
theorem leibniz_cross (u v w : Fin 3 → R) : u ×₃ (v ×₃ w) = u ×₃ v ×₃ w + v ×₃ (u ×₃ w) :=
  by
  dsimp only [cross_apply]
  ext i
  fin_cases i <;> norm_num <;> ring
#align leibniz_cross leibniz_cross

/-- The three-dimensional vectors together with the operations + and ×₃ form a Lie ring.
    Note we do not make this an instance as a conflicting one already exists
    via `lie_ring.of_associative_ring`. -/
def Cross.lieRing : LieRing (Fin 3 → R) :=
  { Pi.addCommGroup with
    bracket := fun u v => u ×₃ v
    add_lie := LinearMap.map_add₂ _
    lie_add := fun u => LinearMap.map_add _
    lie_self := cross_self
    leibniz_lie := leibniz_cross }
#align cross.lie_ring Cross.lieRing

attribute [local instance] Cross.lieRing

theorem cross_cross (u v w : Fin 3 → R) : u ×₃ v ×₃ w = u ×₃ (v ×₃ w) - v ×₃ (u ×₃ w) :=
  lie_lie u v w
#align cross_cross cross_cross

/-- Jacobi identity: For a cross product of three vectors,
    their sum over the three even permutations is equal to the zero vector. -/
theorem jacobi_cross (u v w : Fin 3 → R) : u ×₃ (v ×₃ w) + v ×₃ (w ×₃ u) + w ×₃ (u ×₃ v) = 0 :=
  lie_jacobi u v w
#align jacobi_cross jacobi_cross

end LeibnizProperties


import tactic
import group_theory.congruence

namespace units

variables {M : Type} [monoid M]

def of : units M →* M :=
⟨coe, rfl, λ _ _, rfl⟩

variables {G : Type} [group G] (f : G →* M)

def restrict : G →* units M :=
⟨λ x, ⟨f x, f x⁻¹,
  by rw [← map_mul, _root_.mul_inv_self, map_one],
  by rw [← map_mul, _root_.inv_mul_self, map_one]⟩,
  by ext; simp, λ _ _, by ext; simp⟩

@[simp] lemma of_comp_restrict : of.comp (restrict f) = f :=
by ext; refl

@[simp] lemma of_restrict (x : G) : of (restrict f x) = f x := rfl

@[simp] lemma restrict_of : restrict of = monoid_hom.id (units M) :=
begin
  ext x,
  refl,
end

@[simp] lemma restrict_comp {H : Type*} [group H] (f : G →* M) (g : H →* G) :
  (restrict f).comp g = restrict (f.comp g) :=
begin
  ext,
  simp [restrict],
end

end units

@[derive monoid] def abelianization (M : Type) [monoid M] : Type :=
con.quotient (con_gen (λ a b : M, ∃ x y : M, a = x * y ∧ b = y * x))

namespace abelianization

variables {M : Type} [monoid M]

instance : comm_monoid (abelianization M) :=
{ mul_comm := λ a b, begin
    dsimp [abelianization] at *,
    refine con.induction_on₂ a b (λ a b, _),
    rw [← con.coe_mul, ← con.coe_mul, con.eq],
    refine con_gen.rel.of _ _ _,
    use [a, b],
    simp
  end,
  ..show monoid (abelianization M), by apply_instance }

def of : M →* abelianization M :=
by dsimp [abelianization]; exact
{ to_fun := coe,
  map_mul' := by simp,
  map_one' := by simp }

instance {G : Type} [group G] : comm_group (abelianization G) :=
{ inv := λ x, con.lift_on x (λ x, of (x⁻¹)) begin
    intros a b h, dsimp,
    induction h with x y h,
    { rcases h with ⟨x, y, rfl, rfl⟩,
      simp [mul_comm] },
    { refl },
    { simp * },
    { cc },
    { simp * }
  end,
  mul_left_inv := λ a, begin
    dsimp [abelianization, of] at *,
    refine con.induction_on a (λ a, _),
    simp
  end,
  ..show comm_monoid (abelianization G), by apply_instance }

variables {N : Type} [comm_monoid N] (f : M →* N)

def desc : abelianization M →* N :=
con.lift _ f (con.con_gen_le begin
    rintros _ _ ⟨a, b, rfl, rfl⟩,
    show f (a * b) = f (b * a),
    simp [mul_comm]
  end)

@[simp] lemma desc_comp_of : (desc f).comp of = f :=
begin
  ext,
  refl
end

@[simp] lemma desc_of (x : M) : desc f (of x) = f x := rfl

@[ext] lemma hom_ext {f g : abelianization M →* N}
  (h : f.comp of = g.comp of) : f = g :=
begin
  ext x,
  refine con.induction_on x (λ x, _),
  convert monoid_hom.congr_fun h x
end

@[simp] lemma desc_of' : desc (@of M _) = monoid_hom.id _ :=
hom_ext (by simp)

@[simp] lemma comp_desc {P : Type} [comm_monoid P] (g : N →* P) :
  g.comp (desc f) = desc (g.comp f) :=
hom_ext (by ext; simp)

end abelianization

variables {G M : Type} [group G] [comm_monoid M] (f : G →* M)
  {I J : Type} [comm_group I] [comm_group J] (i : I →* abelianization G)
  (j : units M →* J)

example : j.comp ((abelianization.desc (units.restrict f)).comp i) =
  j.comp ((units.restrict (abelianization.desc f)).comp i) :=
begin
  rw [units.restrict_comp, ← monoid_hom.comp_assoc,
    abelianization.comp_desc],

end