2023-05-15 14:00:01 +00:00
|
|
|
|
import Common.Finset
|
|
|
|
|
import Common.Geometry.Rectangle.Orthogonal
|
|
|
|
|
import Common.List.Basic
|
2023-07-25 13:28:00 +00:00
|
|
|
|
import Common.List.NonEmpty
|
2023-05-15 01:32:18 +00:00
|
|
|
|
|
|
|
|
|
/-! # Common.Geometry.StepFunction
|
|
|
|
|
|
|
|
|
|
Characterization of step functions.
|
|
|
|
|
-/
|
|
|
|
|
|
|
|
|
|
namespace Geometry
|
|
|
|
|
|
2023-07-25 13:28:00 +00:00
|
|
|
|
/--
|
|
|
|
|
An interval defines a range of values, characterized by a "left" value and a
|
|
|
|
|
"right" value. We require these values to be distinct; we do not support the
|
|
|
|
|
notion of an empty interval.
|
|
|
|
|
-/
|
|
|
|
|
structure Interval (α : Type _) [LT α] where
|
|
|
|
|
left : α
|
|
|
|
|
right : α
|
|
|
|
|
h : left < right
|
|
|
|
|
|
|
|
|
|
namespace Interval
|
|
|
|
|
|
|
|
|
|
/--
|
|
|
|
|
Computes the size of the interval.
|
|
|
|
|
-/
|
|
|
|
|
def size [LT α] [Sub α] (i : Interval α) : α := i.right - i.left
|
|
|
|
|
|
|
|
|
|
/--
|
|
|
|
|
Computes the midpoint of the interval.
|
|
|
|
|
-/
|
|
|
|
|
def midpoint [LT α] [Add α] [HDiv α ℝ α] (i : Interval α) : α :=
|
|
|
|
|
(i.left + i.right) / (2 : ℝ)
|
|
|
|
|
|
|
|
|
|
/--
|
|
|
|
|
Convert an `Interval` into a `Set.Ico`.
|
|
|
|
|
-/
|
|
|
|
|
def toIco [Preorder α] (i : Interval α) : Set α := Set.Ico i.left i.right
|
|
|
|
|
|
|
|
|
|
/--
|
|
|
|
|
Convert an `Interval` into a `Set.Ioc`.
|
|
|
|
|
-/
|
|
|
|
|
def toIoc [Preorder α] (i : Interval α) : Set α := Set.Ioc i.left i.right
|
|
|
|
|
|
|
|
|
|
/--
|
|
|
|
|
Convert an `Interval` into a `Set.Icc`.
|
|
|
|
|
-/
|
|
|
|
|
def toIcc [Preorder α] (i : Interval α) : Set α := Set.Icc i.left i.right
|
|
|
|
|
|
|
|
|
|
/--
|
|
|
|
|
Convert an `Interval` into a `Set.Ioo`.
|
|
|
|
|
-/
|
|
|
|
|
def toIoo [Preorder α] (i : Interval α) : Set α := Set.Ioo i.left i.right
|
|
|
|
|
|
|
|
|
|
end Interval
|
2023-05-15 01:32:18 +00:00
|
|
|
|
|
|
|
|
|
/--
|
|
|
|
|
A function `f`, whose domain is a closed interval `[a, b]`, is a `StepFunction`
|
2023-07-25 13:28:00 +00:00
|
|
|
|
if there exists a partition `P = {x₀, x₁, …, xₙ}` of `[a, b]` such that `f` is
|
2023-05-15 01:32:18 +00:00
|
|
|
|
constant on each open subinterval of `P`.
|
2023-05-15 14:00:01 +00:00
|
|
|
|
|
|
|
|
|
Instead of maintaining a function from `[a, b]` to `ℝ`, we instead maintain a
|
2023-07-25 13:28:00 +00:00
|
|
|
|
function that maps each partition index to some constant value.
|
2023-05-15 01:32:18 +00:00
|
|
|
|
-/
|
|
|
|
|
structure StepFunction where
|
2023-07-25 13:28:00 +00:00
|
|
|
|
ivls : List.NonEmpty (Interval ℝ)
|
|
|
|
|
connected : ∀ I ∈ ivls.toList.pairwise (·.right = ·.left), I
|
|
|
|
|
toFun : Fin ivls.length → ℝ
|
2023-05-15 01:32:18 +00:00
|
|
|
|
|
|
|
|
|
namespace StepFunction
|
|
|
|
|
|
|
|
|
|
/--
|
2023-05-15 14:00:01 +00:00
|
|
|
|
The ordinate set of the `StepFunction`.
|
2023-05-15 01:32:18 +00:00
|
|
|
|
-/
|
2023-05-15 14:00:01 +00:00
|
|
|
|
def toSet (sf : StepFunction) : Set Point :=
|
2023-07-25 13:28:00 +00:00
|
|
|
|
⋃ i ∈ Finset.finRange sf.ivls.length,
|
|
|
|
|
let I := sf.ivls[i]
|
2023-05-15 14:00:01 +00:00
|
|
|
|
Rectangle.Orthogonal.toSet
|
2023-05-15 20:07:42 +00:00
|
|
|
|
⟨
|
|
|
|
|
{
|
|
|
|
|
tl := ⟨I.left, sf.toFun i⟩,
|
|
|
|
|
bl := ⟨I.left, 0⟩,
|
|
|
|
|
br := ⟨I.right, 0⟩,
|
|
|
|
|
has_right_angle := sorry
|
|
|
|
|
},
|
|
|
|
|
by simp
|
|
|
|
|
⟩
|
2023-05-15 01:32:18 +00:00
|
|
|
|
|
|
|
|
|
end StepFunction
|
|
|
|
|
|
|
|
|
|
end Geometry
|