Canonical interval_eqType := Eval hnf in EqType (interval T) interval_eqMixin.
End IntervalEq.
Section IntervalPo.
Variable R : numDomainType.
Definition pred_of_itv (i : interval R) : pred R :=
[pred x | let: Interval l u := i in
match l with
| BOpen_if b lb => lb <= x ?< if b
| BInfty => true
end &&
match u with
| BOpen_if b ub => x <= ub ?< if b
| BInfty => true
end].
Canonical Structure itvPredType := Eval hnf in mkPredType pred_of_itv.
(* we compute a set of rewrite rules associated to an interval *)
Definition itv_rewrite (i : interval R) x : Type :=
let: Interval l u := i in
(match l with
| BClose a => (a <= x) * (x < a = false)
| BOpen a => (a <= x) * (a < x) * (x <= a = false) * (x < a = false)
| BInfty => forall x : R, x == x
end *
match u with
| BClose b => (x <= b) * (b < x = false)
| BOpen b => (x <= b) * (x < b) * (b <= x = false) * (b < x = false)
| BInfty => forall x : R, x == x
end *
match l, u with
| BClose a, BClose b =>
(a <= b) * (b < a = false) * (a \in `[a, b]) * (b \in `[a, b])
| BClose a, BOpen b =>
(a <= b) * (a < b) * (b <= a = false) * (b < a = false)
* (a \in `[a, b]) * (a \in `[a, b[)* (b \in `[a, b]) * (b \in `]a, b])
| BOpen a, BClose b =>
(a <= b) * (a < b) * (b <= a = false) * (b < a = false)
* (a \in `[a, b]) * (a \in `[a, b[)* (b \in `[a, b]) * (b \in `]a, b])
| BOpen a, BOpen b =>
(a <= b) * (a < b) * (b <= a = false) * (b < a = false)
* (a \in `[a, b]) * (a \in `[a, b[)* (b \in `[a, b]) * (b \in `]a, b])
| _, _ => forall x : R, x == x
end)%type.
Definition itv_decompose (i : interval R) x : Prop :=
let: Interval l u := i in
((match l with
| BOpen_if b lb => (lb <= x ?< if b) : Prop
| BInfty => True
end : Prop) *
(match u with
| BOpen_if b ub => (x <= ub ?< if b) : Prop
| BInfty => True
end : Prop))%type.

(* Specifications: *)
Lemma itv_dec : forall (x : R) (i : interval R),
reflect (itv_decompose i x) (x \in i).
Lemma le_boundr_trans : transitive le_boundr.
Lemma le_boundl_bb x b1 b2 :
le_boundl (BOpen_if b1 x) (BOpen_if b2 x) = (b1 ==> b2).
Lemma boundl_in_itv : forall ba xa b,
xa \in Interval (BOpen_if ba xa) b =
if ba then false else le_boundr (BClose xa) b.