This file gives a first Lean model for the activity-selection problem from
CLRS Section 16.1. Activities are closed-open intervals over natural-number
time points, represented only by their start and finish fields. A selected
list is feasible when every earlier activity in the list finishes before every
later one starts.
Main results:
Theorem earliest_finish_minFinish: the executable selector
earliest_finish returns an activity whose finish time is minimum in the
input list.
Theorem finishSorted_head_minFinish: the head of a finish-time-sorted
nonempty activity list is the earliest-finishing available activity.
Theorem greedy_choice_minFinish_preserves_optimal_tail_feasibility: if the
greedy activity is compatible with an optimal tail solution, prepending it is
feasible.
Theorem greedy_choice_optimal_from_certificate: a certificate-based
optimality theorem for the greedy-choice step. The exchange argument is
provided as a hypothesis, keeping the theorem honest while still matching the
CLRS proof structure.
Theorem finishSorted_greedyChoiceCertificate: on a finish-time-sorted
candidate list, the CLRS exchange certificate is derived automatically.
Theorem greedySelect_cons_eq: the executable selector follows the
CLRS recursive cons-case equation: choose the first finishing activity and
recurse on the filtered compatible tail.
Theorems greedySelect_sublist and greedySelect_feasible: the
executable greedy selector always returns activities drawn from the input and
arranged feasibly.
Theorem greedySelect_maxCardinality: on a finish-time-sorted input, the
executable greedy selector has maximum cardinality among feasible sublists.
Theorem greedySelect_cons_maxCardinality: the nonempty sorted-input
recursion theorem, exposing the greedy choice plus optimal recursive
subproblem directly.
Theorem greedySelect_after_maxCardinality: the filtered compatible tail
is itself solved optimally by the same executable selector.
Theorem greedySelect_optimal_length: a direct reader-facing corollary:
every feasible sublist of a finish-time-sorted input has length at most the
greedy output.
Definition activitySelection: the CLRS-facing name for the executable
greedy selector.
Theorems activitySelection_maxCardinality and
activitySelection_cons_maxCardinality: top-level maximum-cardinality
certificates for the full input and the nonempty recursive step.
Theorems activitySelection_correct and
activitySelection_cons_correct: reader-facing correctness bundles for
the full sorted-list input and the nonempty recursive step.
Theorems greedySelect_cons_recursive_correct and
activitySelection_cons_recursive_correct: bundled nonempty recursion
theorems that expose the exact cons-case equation, optimal recursive tail,
optimal full solution, feasibility, sublist membership, and optimal-length
inequality in one statement.
Current gaps:
None for the current finite-list model. A lower-level refinement to CLRS
array/pseudocode execution and richer interval-validity assumptions remains a
future extension.
openListnamespaceCLRSnamespaceActivitySelection
Activities and feasibility
An activity is an interval with a natural-number start time and finish time.
The model intentionally does not require start ≤ finish; that assumption can
be added by clients that want to rule out degenerate input data.
Two activities are compatible when one finishes before the other starts. This
is the symmetric textbook notion used for unordered sets of selected
activities.
A list is sorted by nondecreasing finish time. On such a list, the head is the
CLRS earliest-finishing activity among the currently available activities.
The CLRS recursive greedy algorithm, parameterized by the list order supplied by
the caller. On a list sorted by finish time, the head is an earliest-finishing
available activity.
Executable recursion equation for the nonempty CLRS activity-selection case:
choose the first activity in the finish-time order and recurse on the remaining
activities compatible with that choice.
CLRS-facing wrapper around the executable recursive selector. Keeping this
name separate lets the proof expose greedySelect as the implementation
while readers cite activitySelection as the algorithm.
A one-step greedy-choice certificate. The field exchange is the CLRS
exchange argument: every feasible competitor can be converted, without losing
cardinality, into one that starts with the chosen greedy activity and then uses
only the after subproblem.
If a feasible competitor starts with first, and the greedy activity
a has minimum finish time in the sorted available list, then the
competitor's tail is available after choosing a.
On a finish-time-sorted nonempty candidate list, the textbook exchange
argument is no longer an external assumption: every feasible competitor can be
rewritten as the greedy activity followed by a feasible tail from the filtered
subproblem.
Greedy-choice feasibility. If a has minimum finish time among the
available activities and an optimal tail solution is compatible with a,
then prepending a preserves feasibility.
The minimum-finish hypothesis records the CLRS greedy choice; feasibility itself
uses only the compatibility of the chosen tail.
If the tail is maximum-cardinality for the post-greedy subproblem, then every
chosen-tail competitor has size at most the greedy choice plus that tail.
Full finite-list optimality for sorted inputs. If the candidate activities
are sorted by nondecreasing finish time, the executable greedy selector returns
a feasible sublist of maximum cardinality.
Recursive subproblem optimality. After the greedy choice from a sorted
nonempty candidate list, the executable selector is maximum-cardinality for the
filtered compatible tail.
Nonempty sorted-input recursion theorem. The CLRS greedy choice followed by
the recursively optimal compatible tail is itself maximum-cardinality for the
whole candidate list.
CLRS-facing nonempty recursion certificate: choose the first finish-sorted
activity, recursively solve its compatible tail, and obtain a
maximum-cardinality solution for the original candidate list.
Reader-facing correctness theorem for the finite sorted-list activity-selection
model: the executable greedy selector returns a feasible sublist and no
feasible sublist of the input is longer.
Reader-facing correctness theorem for the nonempty CLRS recursion step: choose
the first finish-sorted activity, solve the compatible tail recursively, and no
feasible competitor from the original nonempty list is longer.
Bundled executable recursion theorem for the sorted nonempty greedy selector.
It exposes the exact cons-case equation, the optimal recursive subproblem, the
optimal whole solution, and the reader-facing correctness facts in one place.
CLRS-facing bundled recursion theorem for activity selection. On a nonempty
finish-time-sorted input, the public algorithm chooses the head, recursively
solves the compatible tail, and the resulting executable output is feasible,
drawn from the input, and maximum-cardinality.