# Homework 3 -- Bounded infinite sets have a limit point

Using the concept of open covers (and explicitly avoiding the
Bolzano–Weierstrass theorem), prove that every bounded infinite set has a limit
point.

**Course material.**

- Lecture 5: [open and closed sets](../index.html#lecture05) (Abbott §3.2),
  Lecture 6: [compactness](../index.html#lecture06) (Abbott §3.3).
- Formalisation: [`theories/Topology.v`](../theories/Topology.v) (open sets
  `A is _open_`, from the Waterproof library `Waterproof.Libs.Analysis.OpenAndClosed`,
  and limit points `x is a _limit point_ of A`, i.e. `is_limit_point A x`) and
  [`theories/Compactness.v`](../theories/Compactness.v) (`open_cover`,
  `has_finite_subcover`, `compact_iff_finite_subcover`).

**The idea of the proof.** Let $A$ be bounded, say $A \subseteq [-M, M]$, and
suppose $A$ has *no* limit point. Then every $c \in [-M,M]$ has a radius
$r_c > 0$ such that the ball $(c - r_c, c + r_c)$ meets $A$ at most in $c$
itself. These balls form an open cover of $[-M,M]$, so by Heine–Borel finitely
many of them already cover $[-M,M]$ — and each of them contains at most one
point of $A$. Hence $A$ is finite, a contradiction.

Notes:

- You may use the Heine–Borel theorem (Lecture 6): it appears below as the
  hypothesis `HHB` of the main theorem, in the "every open cover of $[-M,M]$ has
  a finite subcover" form. You may **not** use Bolzano–Weierstrass.
- The cover is indexed by *pairs* (centre, radius): choosing one radius per
  centre would require the axiom of choice, and carrying the radius in the index
  avoids it. The "at most one point of $A$" condition is built into the set
  `iso_ball A p` below, so that it is empty for a bad choice of radius (and the
  empty set is open).

<hint title="Import libraries (click to open/close)">

Run `dune build` once before opening this file, so that the `RUG.Analysis.*`
modules of the course library are available.

```coq
Require Import Stdlib.Reals.Reals.
Require Import Stdlib.Lists.List.
Require Import Stdlib.Logic.Classical_Pred_Type.
Require Import Stdlib.Logic.Classical_Prop.
Require Import Waterproof.Tactics.
Require Import Waterproof.Notations.Common.
Require Import Waterproof.Notations.Reals.
Require Import Waterproof.Notations.Sets.
Require Import Waterproof.Chains.
Require Import Waterproof.Automation.
Require Import Waterproof.Libs.Analysis.OpenAndClosed.
Require Import RUG.Analysis.Compactness.

Waterproof Enable Automation RealsAndIntegers.
Waterproof Enable Automation Intuition.

Open Scope R_scope.
Open Scope subset_scope.

Set Default Goal Selector "!".
Set Bullet Behavior "Waterproof Relaxed Subproofs".
```
</hint>

We call a set *infinite* if no finite list of reals exhausts it.
```coq
Definition is_infinite (A : subset ℝ) : Prop :=
  ∀ l : list ℝ, ∃ a ∈ A, ¬ In a l.
```

The sets of the cover, indexed by pairs (centre, radius).
```coq
Definition ball_index : Type := (ℝ * ℝ)%type.

Definition idx (c r : ℝ) : ball_index := pair c r.

Definition iso_ball (A : subset ℝ) (p : ball_index) : subset ℝ :=
  fun x => (0 < snd p ∧ (∀ y ∈ A, | y - fst p | < snd p → y = fst p))
           ∧ | x - fst p | < snd p.
```

## Part 1: points that are not limit points

Show that if $c$ is not a limit point of $A$, then some ball around $c$ meets
$A$ at most in $c$.

<hint title="💡 Hint (click to open/close)">
Recall that `c is a _limit point_ of A` unfolds to
`∀ ε > 0, ∃ y ∈ A, 0 < | y - c | < ε`. A proof by contradiction works well.
It can help to rewrite the quantifiers pushing the negation of the conclusion
by one quantifier at a time, and then check the definition of limit point
directly.
`Rabs_pos_lt` gives `0 < | t |` from `t ≠ 0`.
</hint>

```coq
Lemma not_limit_point_char (A : subset ℝ) (c : ℝ) :
    ¬ (c is a _limit point_ of A) →
    ∃ r > 0, ∀ y ∈ A, | y - c | < r → y = c.
Proof.
```
<input-area>
```coq

```
</input-area>
```coq
Qed.
```

## Part 2: the sets of the cover are open

Show that each `iso_ball A p` is open. (If the radius `snd p` is not a good
radius for the centre `fst p`, the set is empty, and the argument below still
works.)

**This part is optional.** The lemma is admitted, so you can use it in the main
result straight away. Come back to it once you have finished the rest: replace
`Admitted.` by your proof and end it with `Qed.`.

**Waterproof remark.** If you state an identity such as
`(x - y) + (y - fst p) = x - fst p` as `(Hid)`, then `By Hid it holds that ...`
can rewrite with it inside `| ... |`.

<hint title="💡 Hint (click to open/close)">
This is the usual "balls are open" proof (compare with `open_interval_is_open`
in `theories/Topology.v`) together with the triangle inequality `Rabs_triang`.
</hint>

```coq
Lemma iso_ball_open (A : subset ℝ) (p : ball_index) : (iso_ball A p) is _open_.
Proof.
```
<input-area>
```coq
Admitted.
```
</input-area>

The following technical fact about lists is given to you (`In` and `map` are
from the standard library of Rocq).

- A finite subcover is described by a list `l : list ball_index` of indices,
  i.e. of pairs (centre, radius).
- `In x l` means "`x` is one of the elements of the list `l`".
- `map fst l` applies `fst` to every element of `l`: it is the list of the
  *centres* of the balls in `l`.

In words, the lemma says: if `a` is not one of the centres of the balls in `l`,
and `p` is one of the balls in `l`, then `a` is not the centre of `p`. In the
main result this is what clashes with the definition of `iso_ball`, which forces
a point of `A` lying in `iso_ball A p` to be the centre `fst p`.

Its proof is written with plain Rocq tactics rather than Waterproof sentences.
You do not need to read it: just use the lemma.
```coq
Lemma not_in_map_fst (l : list ball_index) (a : ℝ) (p : ball_index)
    (Hnot : ¬ In a (map fst l)) (Hin : In p l) : a ≠ fst p.
Proof.
intro Heq.
rewrite Heq in Hnot.
apply Hnot.
apply in_map.
exact Hin.
Qed.
```

## Main result

Now put the pieces together.

**Waterproof remark.** Unpack an existential, such as the list given by
`has_finite_subcover`, with `Obtain ... according to (...)`. Apply lemmas and
`∀`-hypotheses to their arguments, e.g. `By (iso_ball_open A i) ...`: a bare
`By iso_ball_open ...` makes the check way too slow.

<hint title="💡 Hint (click to open/close)">
Argue by contradiction, so that no real number is a limit point of `A`. Then
show `open_cover (iso_ball A) [-M, M]` (Parts 1 and 2), apply `HHB`, and use
`Hinf` with the list of centres `map fst l`.
</hint>

```coq
Theorem bounded_infinite_has_limit_point (A : subset ℝ) (M : ℝ)
    (HM : ∀ a ∈ A, -M ≤ a ∧ a ≤ M)
    (Hinf : is_infinite A)
    (HHB : forall (Idx : Type) (U : Idx → (ℝ → Prop)),
             open_cover U [-M, M] → has_finite_subcover U [-M, M]) :
    ∃ x : ℝ, x is a _limit point_ of A.
Proof.
```
<input-area>
```coq

```
</input-area>
```coq
Qed.
```

## Declaration of own work

Please declare that the work above is your own work by writing `Yes.` below.
In particular, this means the proofs are typed by yourself and you could
explain them when asked.
```coq
Inductive answer : Type := Yes : answer.

Definition own_work : answer. exact
```
<input-area>
```coq

```
</input-area>
```coq
Qed.
```
