Library prosa.analysis.facts.behavior.service


(* ----------------------------------[ coqtop ]---------------------------------

Welcome to Coq 8.11.2 (June 2020)

----------------------------------------------------------------------------- *)


Require Export prosa.util.all.
Require Export prosa.behavior.all.
Require Export prosa.model.processor.platform_properties.
Require Export prosa.analysis.definitions.schedule_prefix.

Service

In this file, we establish basic facts about the service received by jobs.
To begin with, we provide some simple but handy rewriting rules for [service] and [service_during].
Section Composition.

Consider any job type and any processor state.
  Context {Job: JobType}.
  Context {PState: Type}.
  Context `{ProcessorState Job PState}.

For any given schedule...
  Variable sched: schedule PState.

...and any given job...
  Variable j: Job.

...we establish a number of useful rewriting rules that decompose the service received during an interval into smaller intervals.
As a trivial base case, no job receives any service during an empty interval.
  Lemma service_during_geq:
     t1 t2,
      t1 t2 service_during sched j t1 t2 = 0.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 631)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  ============================
  forall t1 t2 : nat, t2 <= t1 -> service_during sched j t1 t2 = 0

----------------------------------------------------------------------------- *)


  Proof.
    movet1 t2 t1t2.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 634)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : nat
  t1t2 : t2 <= t1
  ============================
  service_during sched j t1 t2 = 0

----------------------------------------------------------------------------- *)


    rewrite /service_during big_geq //.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


  Qed.

Equally trivially, no job has received service prior to time zero.
  Corollary service0:
    service sched j 0 = 0.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 637)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  ============================
  service sched j 0 = 0

----------------------------------------------------------------------------- *)


  Proof.
    rewrite /service service_during_geq //.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


  Qed.

Trivially, an interval consisting of one time unit is equivalent to [service_at].
  Lemma service_during_instant:
     t,
      service_during sched j t t.+1 = service_at sched j t.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 647)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  ============================
  forall t : instant,
  service_during sched j t (succn t) = service_at sched j t

----------------------------------------------------------------------------- *)


  Proof.
    movet.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 648)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t : instant
  ============================
  service_during sched j t (succn t) = service_at sched j t

----------------------------------------------------------------------------- *)


     by rewrite /service_during big_nat_recr ?big_geq //.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


  Qed.

Next, we observe that we can look at the service received during an interval [t1, t3) as the sum of the service during [t1, t2) and [t2, t3) for any t2 \in [t1, t3]. (The "_cat" suffix denotes the concatenation of the two intervals.)
  Lemma service_during_cat:
     t1 t2 t3,
      t1 t2 t3
      (service_during sched j t1 t2) + (service_during sched j t2 t3)
      = service_during sched j t1 t3.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 662)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  ============================
  forall t1 t2 t3 : nat,
  t1 <= t2 <= t3 ->
  service_during sched j t1 t2 + service_during sched j t2 t3 =
  service_during sched j t1 t3

----------------------------------------------------------------------------- *)


  Proof.
    movet1 t2 t3 /andP [t1t2 t2t3].

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 705)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2, t3 : nat
  t1t2 : t1 <= t2
  t2t3 : t2 <= t3
  ============================
  service_during sched j t1 t2 + service_during sched j t2 t3 =
  service_during sched j t1 t3

----------------------------------------------------------------------------- *)


      by rewrite /service_during -big_cat_nat /=.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


  Qed.

Since [service] is just a special case of [service_during], the same holds for [service].
  Lemma service_cat:
     t1 t2,
      t1 t2
      (service sched j t1) + (service_during sched j t1 t2)
      = service sched j t2.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 676)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  ============================
  forall t1 t2 : nat,
  t1 <= t2 ->
  service sched j t1 + service_during sched j t1 t2 = service sched j t2

----------------------------------------------------------------------------- *)


  Proof.
    movet1 t2 t1t2.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 679)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : nat
  t1t2 : t1 <= t2
  ============================
  service sched j t1 + service_during sched j t1 t2 = service sched j t2

----------------------------------------------------------------------------- *)


    rewrite /service service_during_cat //.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


  Qed.

As a special case, we observe that the service during an interval can be decomposed into the first instant and the rest of the interval.
  Lemma service_during_first_plus_later:
     t1 t2,
      t1 < t2
      (service_at sched j t1) + (service_during sched j t1.+1 t2)
      = service_during sched j t1 t2.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 690)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  ============================
  forall t1 t2 : nat,
  t1 < t2 ->
  service_at sched j t1 + service_during sched j (succn t1) t2 =
  service_during sched j t1 t2

----------------------------------------------------------------------------- *)


  Proof.
    movet1 t2 t1t2.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 693)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : nat
  t1t2 : t1 < t2
  ============================
  service_at sched j t1 + service_during sched j (succn t1) t2 =
  service_during sched j t1 t2

----------------------------------------------------------------------------- *)


    have TIMES: t1 t1.+1 t2 by rewrite /(_ && _) ifT //.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 713)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : nat
  t1t2 : t1 < t2
  TIMES : t1 <= succn t1 <= t2
  ============================
  service_at sched j t1 + service_during sched j (succn t1) t2 =
  service_during sched j t1 t2

----------------------------------------------------------------------------- *)


    have SPLIT := service_during_cat t1 t1.+1 t2 TIMES.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 718)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : nat
  t1t2 : t1 < t2
  TIMES : t1 <= succn t1 <= t2
  SPLIT : service_during sched j t1 (succn t1) +
          service_during sched j (succn t1) t2 = service_during sched j t1 t2
  ============================
  service_at sched j t1 + service_during sched j (succn t1) t2 =
  service_during sched j t1 t2

----------------------------------------------------------------------------- *)


      by rewrite -service_during_instant //.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


  Qed.

Symmetrically, we have the same for the end of the interval.
  Lemma service_during_last_plus_before:
     t1 t2,
      t1 t2
      (service_during sched j t1 t2) + (service_at sched j t2)
      = service_during sched j t1 t2.+1.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 704)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  ============================
  forall t1 t2 : nat,
  t1 <= t2 ->
  service_during sched j t1 t2 + service_at sched j t2 =
  service_during sched j t1 (succn t2)

----------------------------------------------------------------------------- *)


  Proof.
    movet1 t2 t1t2.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 707)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : nat
  t1t2 : t1 <= t2
  ============================
  service_during sched j t1 t2 + service_at sched j t2 =
  service_during sched j t1 (succn t2)

----------------------------------------------------------------------------- *)


    rewrite -(service_during_cat t1 t2 t2.+1); last by rewrite /(_ && _) ifT //.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 710)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : nat
  t1t2 : t1 <= t2
  ============================
  service_during sched j t1 t2 + service_at sched j t2 =
  service_during sched j t1 t2 + service_during sched j t2 (succn t2)

----------------------------------------------------------------------------- *)


    rewrite service_during_instant //.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


  Qed.

And hence also for [service].
  Corollary service_last_plus_before:
     t,
      (service sched j t) + (service_at sched j t)
      = service sched j t.+1.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 717)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  ============================
  forall t : instant,
  service sched j t + service_at sched j t = service sched j (succn t)

----------------------------------------------------------------------------- *)


  Proof.
    movet.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 718)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t : instant
  ============================
  service sched j t + service_at sched j t = service sched j (succn t)

----------------------------------------------------------------------------- *)


    rewrite /service.
(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 725)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t : instant
  ============================
  service_during sched j 0 t + service_at sched j t =
  service_during sched j 0 (succn t)

----------------------------------------------------------------------------- *)


rewrite -service_during_last_plus_before //.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


  Qed.

Finally, we deconstruct the service received during an interval [t1, t3)
into the service at a midpoint t2 and the service in the intervals before and after.
  Lemma service_split_at_point:
     t1 t2 t3,
      t1 t2 < t3
      (service_during sched j t1 t2) + (service_at sched j t2) + (service_during sched j t2.+1 t3)
      = service_during sched j t1 t3.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 735)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  ============================
  forall t1 t2 t3 : nat,
  t1 <= t2 < t3 ->
  service_during sched j t1 t2 + service_at sched j t2 +
  service_during sched j (succn t2) t3 = service_during sched j t1 t3

----------------------------------------------------------------------------- *)


  Proof.
    movet1 t2 t3 /andP [t1t2 t2t3].

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 778)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2, t3 : nat
  t1t2 : t1 <= t2
  t2t3 : t2 < t3
  ============================
  service_during sched j t1 t2 + service_at sched j t2 +
  service_during sched j (succn t2) t3 = service_during sched j t1 t3

----------------------------------------------------------------------------- *)


    rewrite -addnA service_during_first_plus_later// service_during_cat// /(_ && _) ifT//.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 858)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2, t3 : nat
  t1t2 : t1 <= t2
  t2t3 : t2 < t3
  ============================
  t2 <= t3

----------------------------------------------------------------------------- *)


      by exact: ltnW.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


  Qed.

End Composition.

As a common special case, we establish facts about schedules in which a job receives either 1 or 0 service units at all times.
Section UnitService.

Consider any job type and any processor state.
  Context {Job: JobType}.
  Context {PState: Type}.
  Context `{ProcessorState Job PState}.

Let's consider a unit-service model...
...and a given schedule.
  Variable sched: schedule PState.

Let [j] be any job that is to be scheduled.
  Variable j: Job.

First, we prove that the instantaneous service cannot be greater than 1, ...
  Lemma service_at_most_one:
     t, service_at sched j t 1.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 630)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  H_unit_service : unit_service_proc_model PState
  sched : schedule PState
  j : Job
  ============================
  forall t : instant, service_at sched j t <= 1

----------------------------------------------------------------------------- *)


  Proof.
      by movet; rewrite /service_at.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


  Qed.

...which implies that the cumulative service received by job [j] in any interval of length delta is at most delta.
  Lemma cumulative_service_le_delta:
     t delta,
      service_during sched j t (t + delta) delta.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 636)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  H_unit_service : unit_service_proc_model PState
  sched : schedule PState
  j : Job
  ============================
  forall (t : instant) (delta : nat),
  service_during sched j t (t + delta) <= delta

----------------------------------------------------------------------------- *)


  Proof.
    unfold service_during; intros t delta.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 640)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  H_unit_service : unit_service_proc_model PState
  sched : schedule PState
  j : Job
  t : instant
  delta : nat
  ============================
  \sum_(t <= t0 < t + delta) service_at sched j t0 <= delta

----------------------------------------------------------------------------- *)


    apply leq_trans with (n := \sum_(t t0 < t + delta) 1);
      last by rewrite sum_of_ones.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 645)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  H_unit_service : unit_service_proc_model PState
  sched : schedule PState
  j : Job
  t : instant
  delta : nat
  ============================
  \sum_(t <= t0 < t + delta) service_at sched j t0 <=
  \sum_(t <= t0 < t + delta) 1

----------------------------------------------------------------------------- *)


    by apply: leq_sumt' _; apply: service_at_most_one.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


  Qed.

  Section ServiceIsAStepFunction.

We show that the service received by any job [j] is a step function.
    Lemma service_is_a_step_function:
      is_step_function (service sched j).

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 640)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  H_unit_service : unit_service_proc_model PState
  sched : schedule PState
  j : Job
  ============================
  is_step_function (service sched j)

----------------------------------------------------------------------------- *)


    Proof.
      rewrite /is_step_functiont.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 642)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  H_unit_service : unit_service_proc_model PState
  sched : schedule PState
  j : Job
  t : nat
  ============================
  service sched j (t + 1) <= service sched j t + 1

----------------------------------------------------------------------------- *)


      rewrite addn1 -service_last_plus_before leq_add2l.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 661)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  H_unit_service : unit_service_proc_model PState
  sched : schedule PState
  j : Job
  t : nat
  ============================
  service_at sched j t <= 1

----------------------------------------------------------------------------- *)


      apply service_at_most_one.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


    Qed.

Next, consider any time [t]...
    Variable t: instant.

...and let [s0] be any value less than the service received by job [j] by time [t].
    Variable s0: duration.
    Hypothesis H_less_than_s: s0 < service sched j t.

Then, we show that there exists an earlier time [t0] where job [j] had [s0] units of service.
    Corollary exists_intermediate_service:
       t0,
        t0 < t
        service sched j t0 = s0.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 651)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  H_unit_service : unit_service_proc_model PState
  sched : schedule PState
  j : Job
  t : instant
  s0 : duration
  H_less_than_s : s0 < service sched j t
  ============================
  exists t0 : nat, t0 < t /\ service sched j t0 = s0

----------------------------------------------------------------------------- *)


    Proof.
      feed (exists_intermediate_point (service sched j));
        [by apply service_is_a_step_function | intros EX].

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 661)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  H_unit_service : unit_service_proc_model PState
  sched : schedule PState
  j : Job
  t : instant
  s0 : duration
  H_less_than_s : s0 < service sched j t
  EX : forall x1 x2 : nat,
       x1 <= x2 ->
       forall y : nat,
       service sched j x1 <= y < service sched j x2 ->
       exists x_mid : nat, x1 <= x_mid < x2 /\ service sched j x_mid = y
  ============================
  exists t0 : nat, t0 < t /\ service sched j t0 = s0

----------------------------------------------------------------------------- *)


      feed (EX 0 t); first by done.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 667)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  H_unit_service : unit_service_proc_model PState
  sched : schedule PState
  j : Job
  t : instant
  s0 : duration
  H_less_than_s : s0 < service sched j t
  EX : forall y : nat,
       service sched j 0 <= y < service sched j t ->
       exists x_mid : nat, 0 <= x_mid < t /\ service sched j x_mid = y
  ============================
  exists t0 : nat, t0 < t /\ service sched j t0 = s0

----------------------------------------------------------------------------- *)


      feed (EX s0);
        first by rewrite /service /service_during big_geq //.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 673)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  H_unit_service : unit_service_proc_model PState
  sched : schedule PState
  j : Job
  t : instant
  s0 : duration
  H_less_than_s : s0 < service sched j t
  EX : exists x_mid : nat, 0 <= x_mid < t /\ service sched j x_mid = s0
  ============================
  exists t0 : nat, t0 < t /\ service sched j t0 = s0

----------------------------------------------------------------------------- *)


        by move: EX ⇒ /= [x_mid EX]; x_mid.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


    Qed.
  End ServiceIsAStepFunction.

End UnitService.

We establish a basic fact about the monotonicity of service.
Section Monotonicity.

Consider any job type and any processor model.
  Context {Job: JobType}.
  Context {PState: Type}.
  Context `{ProcessorState Job PState}.

Consider any given schedule...
  Variable sched: schedule PState.

...and a given job that is to be scheduled.
  Variable j: Job.

We observe that the amount of service received is monotonic by definition.
  Lemma service_monotonic:
     t1 t2,
      t1 t2
      service sched j t1 service sched j t2.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 632)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  ============================
  forall t1 t2 : nat, t1 <= t2 -> service sched j t1 <= service sched j t2

----------------------------------------------------------------------------- *)


  Proof.
    movet1 t2 let1t2.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 635)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : nat
  let1t2 : t1 <= t2
  ============================
  service sched j t1 <= service sched j t2

----------------------------------------------------------------------------- *)


      by rewrite -(service_cat sched j t1 t2 let1t2); apply: leq_addr.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


  Qed.

End Monotonicity.

Consider any job type and any processor model.
Section RelationToScheduled.

  Context {Job: JobType}.
  Context {PState: Type}.
  Context `{ProcessorState Job PState}.

Consider any given schedule...
  Variable sched: schedule PState.

...and a given job that is to be scheduled.
  Variable j: Job.

We observe that a job that isn't scheduled cannot possibly receive service.
  Lemma not_scheduled_implies_no_service:
     t,
      ~~ scheduled_at sched j t service_at sched j t = 0.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 633)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  ============================
  forall t : instant, ~~ scheduled_at sched j t -> service_at sched j t = 0

----------------------------------------------------------------------------- *)


  Proof.
    rewrite /service_at /scheduled_at.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 647)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  ============================
  forall t : instant,
  ~~ scheduled_in j (sched t) -> service_in j (sched t) = 0

----------------------------------------------------------------------------- *)


    movet NOT_SCHED.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 649)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t : instant
  NOT_SCHED : ~~ scheduled_in j (sched t)
  ============================
  service_in j (sched t) = 0

----------------------------------------------------------------------------- *)


    rewrite service_implies_scheduled //.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


  Qed.

Conversely, if a job receives service, then it must be scheduled.
  Lemma service_at_implies_scheduled_at:
     t,
      service_at sched j t > 0 scheduled_at sched j t.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 641)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  ============================
  forall t : instant, 0 < service_at sched j t -> scheduled_at sched j t

----------------------------------------------------------------------------- *)


  Proof.
    movet.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 642)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t : instant
  ============================
  0 < service_at sched j t -> scheduled_at sched j t

----------------------------------------------------------------------------- *)


    destruct (scheduled_at sched j t) eqn:SCHEDULED; first trivial.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 658)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t : instant
  SCHEDULED : scheduled_at sched j t = false
  ============================
  0 < service_at sched j t -> false

----------------------------------------------------------------------------- *)


    rewrite not_scheduled_implies_no_service // negbT //.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


  Qed.

Thus, if the cumulative amount of service changes, then it must be scheduled, too.
  Lemma service_delta_implies_scheduled:
     t,
      service sched j t < service sched j t.+1 scheduled_at sched j t.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 652)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  ============================
  forall t : instant,
  service sched j t < service sched j (succn t) -> scheduled_at sched j t

----------------------------------------------------------------------------- *)


  Proof.
    movet.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 653)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t : instant
  ============================
  service sched j t < service sched j (succn t) -> scheduled_at sched j t

----------------------------------------------------------------------------- *)


    rewrite -service_last_plus_before -{1}(addn0 (service sched j t)) ltn_add2l.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 677)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t : instant
  ============================
  0 < service_at sched j t -> scheduled_at sched j t

----------------------------------------------------------------------------- *)


    apply: service_at_implies_scheduled_at.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


  Qed.

We observe that a job receives cumulative service during some interval iff it receives services at some specific time in the interval.
  Lemma service_during_service_at:
     t1 t2,
      service_during sched j t1 t2 > 0
      
       t,
        t1 t < t2
        service_at sched j t > 0.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 663)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  ============================
  forall t1 t2 : instant,
  0 < service_during sched j t1 t2 <->
  (exists t : nat, t1 <= t < t2 /\ 0 < service_at sched j t)

----------------------------------------------------------------------------- *)


  Proof.
    split.

(* ----------------------------------[ coqtop ]---------------------------------

2 subgoals (ID 667)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  ============================
  0 < service_during sched j t1 t2 ->
  exists t : nat, t1 <= t < t2 /\ 0 < service_at sched j t

subgoal 2 (ID 668) is:
 (exists t : nat, t1 <= t < t2 /\ 0 < service_at sched j t) ->
 0 < service_during sched j t1 t2

----------------------------------------------------------------------------- *)


    {

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 667)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  ============================
  0 < service_during sched j t1 t2 ->
  exists t : nat, t1 <= t < t2 /\ 0 < service_at sched j t

----------------------------------------------------------------------------- *)


      moveNONZERO.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 669)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  NONZERO : 0 < service_during sched j t1 t2
  ============================
  exists t : nat, t1 <= t < t2 /\ 0 < service_at sched j t

----------------------------------------------------------------------------- *)


      case (boolP([ t: 'I_t2,
                      (t t1) && (service_at sched j t > 0)])) ⇒ [EX | ALL].

(* ----------------------------------[ coqtop ]---------------------------------

2 subgoals (ID 682)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  NONZERO : 0 < service_during sched j t1 t2
  EX : ~~
       FiniteQuant.quant0b (T:=ordinal_finType t2)
         (fun t : 'I_t2 =>
          FiniteQuant.ex (T:=ordinal_finType t2)
            (, (t1 <= t) && (0 < service_at sched j t)) t)
  ============================
  exists t : nat, t1 <= t < t2 /\ 0 < service_at sched j t

subgoal 2 (ID 683) is:
 exists t : nat, t1 <= t < t2 /\ 0 < service_at sched j t

----------------------------------------------------------------------------- *)


      - move: EX ⇒ /existsP [x /andP [GE SERV]].

(* ----------------------------------[ coqtop ]---------------------------------

2 subgoals (ID 763)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  NONZERO : 0 < service_during sched j t1 t2
  x : ordinal_finType t2
  GE : t1 <= x
  SERV : 0 < service_at sched j x
  ============================
  exists t : nat, t1 <= t < t2 /\ 0 < service_at sched j t

subgoal 2 (ID 683) is:
 exists t : nat, t1 <= t < t2 /\ 0 < service_at sched j t

----------------------------------------------------------------------------- *)


         x; split ⇒ //.

(* ----------------------------------[ coqtop ]---------------------------------

2 subgoals (ID 767)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  NONZERO : 0 < service_during sched j t1 t2
  x : ordinal_finType t2
  GE : t1 <= x
  SERV : 0 < service_at sched j x
  ============================
  t1 <= x < t2

subgoal 2 (ID 683) is:
 exists t : nat, t1 <= t < t2 /\ 0 < service_at sched j t

----------------------------------------------------------------------------- *)


        apply /andP; by split.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 683)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  NONZERO : 0 < service_during sched j t1 t2
  ALL : ~~
        ~~
        FiniteQuant.quant0b (T:=ordinal_finType t2)
          (fun t : 'I_t2 =>
           FiniteQuant.ex (T:=ordinal_finType t2)
             (, (t1 <= t) && (0 < service_at sched j t)) t)
  ============================
  exists t : nat, t1 <= t < t2 /\ 0 < service_at sched j t

----------------------------------------------------------------------------- *)


      - rewrite negb_exists in ALL; move: ALL ⇒ /forallP ALL.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 869)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  NONZERO : 0 < service_during sched j t1 t2
  ALL : forall x : ordinal_finType t2,
        ~~ ((t1 <= x) && (0 < service_at sched j x))
  ============================
  exists t : nat, t1 <= t < t2 /\ 0 < service_at sched j t

----------------------------------------------------------------------------- *)


        rewrite /service_during big_nat_cond in NONZERO.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 901)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  ALL : forall x : ordinal_finType t2,
        ~~ ((t1 <= x) && (0 < service_at sched j x))
  NONZERO : 0 <
            \sum_(t1 <= i < t2 | (t1 <= i < t2) && true) service_at sched j i
  ============================
  exists t : nat, t1 <= t < t2 /\ 0 < service_at sched j t

----------------------------------------------------------------------------- *)


        rewrite big1 ?ltn0 // in NONZEROi.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 988)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  ALL : forall x : ordinal_finType t2,
        ~~ ((t1 <= x) && (0 < service_at sched j x))
  i : nat
  ============================
  (t1 <= i < t2) && true -> service_at sched j i = 0

----------------------------------------------------------------------------- *)


        rewrite andbT; move ⇒ /andP [GT LT].

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 1033)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  ALL : forall x : ordinal_finType t2,
        ~~ ((t1 <= x) && (0 < service_at sched j x))
  i : nat
  GT : t1 <= i
  LT : i < t2
  ============================
  service_at sched j i = 0

----------------------------------------------------------------------------- *)


        specialize (ALL (Ordinal LT)); simpl in ALL.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 1038)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  i : nat
  LT : i < t2
  ALL : ~~ ((t1 <= i) && (0 < service_at sched j i))
  GT : t1 <= i
  ============================
  service_at sched j i = 0

----------------------------------------------------------------------------- *)


        rewrite GT andTb -eqn0Ngt in ALL.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 1066)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  i : nat
  LT : i < t2
  GT : t1 <= i
  ALL : service_at sched j i == 0
  ============================
  service_at sched j i = 0

----------------------------------------------------------------------------- *)


        apply /eqP ⇒ //.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 668)

subgoal 1 (ID 668) is:
 (exists t : nat, t1 <= t < t2 /\ 0 < service_at sched j t) ->
 0 < service_during sched j t1 t2

----------------------------------------------------------------------------- *)


    }

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 668)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  ============================
  (exists t : nat, t1 <= t < t2 /\ 0 < service_at sched j t) ->
  0 < service_during sched j t1 t2

----------------------------------------------------------------------------- *)


    {

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 668)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  ============================
  (exists t : nat, t1 <= t < t2 /\ 0 < service_at sched j t) ->
  0 < service_during sched j t1 t2

----------------------------------------------------------------------------- *)


      move⇒ [t [TT SERVICE]].

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 1142)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  t : nat
  TT : t1 <= t < t2
  SERVICE : 0 < service_at sched j t
  ============================
  0 < service_during sched j t1 t2

----------------------------------------------------------------------------- *)


      case (boolP (0 < service_during sched j t1 t2)) ⇒ // NZ.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 1176)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  t : nat
  TT : t1 <= t < t2
  SERVICE : 0 < service_at sched j t
  NZ : ~~ (0 < service_during sched j t1 t2)
  ============================
  0 < service_during sched j t1 t2

----------------------------------------------------------------------------- *)


      exfalso.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 1177)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  t : nat
  TT : t1 <= t < t2
  SERVICE : 0 < service_at sched j t
  NZ : ~~ (0 < service_during sched j t1 t2)
  ============================
  False

----------------------------------------------------------------------------- *)


      rewrite -eqn0Ngt in NZ.
(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 1198)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  t : nat
  TT : t1 <= t < t2
  SERVICE : 0 < service_at sched j t
  NZ : service_during sched j t1 t2 == 0
  ============================
  False

----------------------------------------------------------------------------- *)


move/eqP: NZ.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 1227)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  t : nat
  TT : t1 <= t < t2
  SERVICE : 0 < service_at sched j t
  ============================
  service_during sched j t1 t2 = 0 -> False

----------------------------------------------------------------------------- *)


      rewrite big_nat_eq0IS_ZERO.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 1253)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  t : nat
  TT : t1 <= t < t2
  SERVICE : 0 < service_at sched j t
  IS_ZERO : forall i : nat, t1 <= i < t2 -> service_at sched j i = 0
  ============================
  False

----------------------------------------------------------------------------- *)


      have NO_SERVICE := IS_ZERO t TT.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 1258)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  t : nat
  TT : t1 <= t < t2
  SERVICE : 0 < service_at sched j t
  IS_ZERO : forall i : nat, t1 <= i < t2 -> service_at sched j i = 0
  NO_SERVICE : service_at sched j t = 0
  ============================
  False

----------------------------------------------------------------------------- *)


      apply lt0n_neq0 in SERVICE.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 1259)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  t : nat
  TT : t1 <= t < t2
  SERVICE : service_at sched j t != 0
  IS_ZERO : forall i : nat, t1 <= i < t2 -> service_at sched j i = 0
  NO_SERVICE : service_at sched j t = 0
  ============================
  False

----------------------------------------------------------------------------- *)


        by move/neqP in SERVICE; contradiction.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


    }

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


  Qed.

Thus, any job that receives some service during an interval must be scheduled at some point during the interval...
  Corollary cumulative_service_implies_scheduled:
     t1 t2,
      service_during sched j t1 t2 > 0
       t,
        t1 t < t2
        scheduled_at sched j t.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 674)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  ============================
  forall t1 t2 : instant,
  0 < service_during sched j t1 t2 ->
  exists t : nat, t1 <= t < t2 /\ scheduled_at sched j t

----------------------------------------------------------------------------- *)


  Proof.
    movet1 t2.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 676)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  ============================
  0 < service_during sched j t1 t2 ->
  exists t : nat, t1 <= t < t2 /\ scheduled_at sched j t

----------------------------------------------------------------------------- *)


    rewrite service_during_service_at.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 701)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  ============================
  (exists t : nat, t1 <= t < t2 /\ 0 < service_at sched j t) ->
  exists t : nat, t1 <= t < t2 /\ scheduled_at sched j t

----------------------------------------------------------------------------- *)


    move⇒ [t' [TIMES SERVICED]].

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 722)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  t' : nat
  TIMES : t1 <= t' < t2
  SERVICED : 0 < service_at sched j t'
  ============================
  exists t : nat, t1 <= t < t2 /\ scheduled_at sched j t

----------------------------------------------------------------------------- *)


     t'; split ⇒ //.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 727)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  t' : nat
  TIMES : t1 <= t' < t2
  SERVICED : 0 < service_at sched j t'
  ============================
  scheduled_at sched j t'

----------------------------------------------------------------------------- *)


    by apply: service_at_implies_scheduled_at.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


 Qed.

...which implies that any job with positive cumulative service must have been scheduled at some point.
  Corollary positive_service_implies_scheduled_before:
     t,
      service sched j t > 0 t', (t' < t scheduled_at sched j t').

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 684)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  ============================
  forall t : instant,
  0 < service sched j t -> exists t' : nat, t' < t /\ scheduled_at sched j t'

----------------------------------------------------------------------------- *)


  Proof.
    movet2.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 685)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t2 : instant
  ============================
  0 < service sched j t2 ->
  exists t' : nat, t' < t2 /\ scheduled_at sched j t'

----------------------------------------------------------------------------- *)


    rewrite /serviceNONZERO.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 693)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t2 : instant
  NONZERO : 0 < service_during sched j 0 t2
  ============================
  exists t' : nat, t' < t2 /\ scheduled_at sched j t'

----------------------------------------------------------------------------- *)


    have EX_SCHED := cumulative_service_implies_scheduled 0 t2 NONZERO.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 698)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t2 : instant
  NONZERO : 0 < service_during sched j 0 t2
  EX_SCHED : exists t : nat, 0 <= t < t2 /\ scheduled_at sched j t
  ============================
  exists t' : nat, t' < t2 /\ scheduled_at sched j t'

----------------------------------------------------------------------------- *)


    by move: EX_SCHED ⇒ [t [TIMES SCHED_AT]]; t; split.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


  Qed.

If we can assume that a scheduled job always receives service, we can further prove the converse.
  Section GuaranteedService.

Assume [j] always receives some positive service.
In other words, not being scheduled is equivalent to receiving zero service.
    Lemma no_service_not_scheduled:
       t,
        ~~ scheduled_at sched j t service_at sched j t = 0.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 696)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H_scheduled_implies_serviced : ideal_progress_proc_model PState
  ============================
  forall t : instant, ~~ scheduled_at sched j t <-> service_at sched j t = 0

----------------------------------------------------------------------------- *)


    Proof.
      movet.
(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 697)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H_scheduled_implies_serviced : ideal_progress_proc_model PState
  t : instant
  ============================
  ~~ scheduled_at sched j t <-> service_at sched j t = 0

----------------------------------------------------------------------------- *)


rewrite /scheduled_at /service_at.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 711)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H_scheduled_implies_serviced : ideal_progress_proc_model PState
  t : instant
  ============================
  ~~ scheduled_in j (sched t) <-> service_in j (sched t) = 0

----------------------------------------------------------------------------- *)


      split ⇒ [NOT_SCHED | NO_SERVICE].

(* ----------------------------------[ coqtop ]---------------------------------

2 subgoals (ID 715)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H_scheduled_implies_serviced : ideal_progress_proc_model PState
  t : instant
  NOT_SCHED : ~~ scheduled_in j (sched t)
  ============================
  service_in j (sched t) = 0

subgoal 2 (ID 716) is:
 ~~ scheduled_in j (sched t)

----------------------------------------------------------------------------- *)


      - by rewrite service_implies_scheduled //.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 716)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H_scheduled_implies_serviced : ideal_progress_proc_model PState
  t : instant
  NO_SERVICE : service_in j (sched t) = 0
  ============================
  ~~ scheduled_in j (sched t)

----------------------------------------------------------------------------- *)


      - apply (contra (H_scheduled_implies_serviced j (sched t))).

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 731)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H_scheduled_implies_serviced : ideal_progress_proc_model PState
  t : instant
  NO_SERVICE : service_in j (sched t) = 0
  ============================
  ~~ (0 < service_in j (sched t))

----------------------------------------------------------------------------- *)


        by rewrite -eqn0Ngt; apply /eqP ⇒ //.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


    Qed.

Then, if a job does not receive any service during an interval, it is not scheduled.
    Lemma no_service_during_implies_not_scheduled:
       t1 t2,
        service_during sched j t1 t2 = 0
         t,
          t1 t < t2 ~~ scheduled_at sched j t.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 708)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H_scheduled_implies_serviced : ideal_progress_proc_model PState
  ============================
  forall t1 t2 : instant,
  service_during sched j t1 t2 = 0 ->
  forall t : nat, t1 <= t < t2 -> ~~ scheduled_at sched j t

----------------------------------------------------------------------------- *)


    Proof.
      movet1 t2 ZERO_SUM t /andP [GT_t1 LT_t2].

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 752)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H_scheduled_implies_serviced : ideal_progress_proc_model PState
  t1, t2 : instant
  ZERO_SUM : service_during sched j t1 t2 = 0
  t : nat
  GT_t1 : t1 <= t
  LT_t2 : t < t2
  ============================
  ~~ scheduled_at sched j t

----------------------------------------------------------------------------- *)


      rewrite no_service_not_scheduled.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 762)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H_scheduled_implies_serviced : ideal_progress_proc_model PState
  t1, t2 : instant
  ZERO_SUM : service_during sched j t1 t2 = 0
  t : nat
  GT_t1 : t1 <= t
  LT_t2 : t < t2
  ============================
  service_at sched j t = 0

----------------------------------------------------------------------------- *)


      move: ZERO_SUM.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 764)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H_scheduled_implies_serviced : ideal_progress_proc_model PState
  t1, t2 : instant
  t : nat
  GT_t1 : t1 <= t
  LT_t2 : t < t2
  ============================
  service_during sched j t1 t2 = 0 -> service_at sched j t = 0

----------------------------------------------------------------------------- *)


      rewrite /service_during big_nat_eq0IS_ZERO.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 799)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H_scheduled_implies_serviced : ideal_progress_proc_model PState
  t1, t2 : instant
  t : nat
  GT_t1 : t1 <= t
  LT_t2 : t < t2
  IS_ZERO : forall i : nat, t1 <= i < t2 -> service_at sched j i = 0
  ============================
  service_at sched j t = 0

----------------------------------------------------------------------------- *)


      by apply (IS_ZERO t); apply /andP; split ⇒ //.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


    Qed.

Conversely, if a job is not scheduled during an interval, then it does not receive any service in that interval
    Lemma not_scheduled_during_implies_zero_service:
       t1 t2,
        ( t, t1 t < t2 ~~ scheduled_at sched j t)
        service_during sched j t1 t2 = 0.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 720)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H_scheduled_implies_serviced : ideal_progress_proc_model PState
  ============================
  forall t1 t2 : nat,
  (forall t : nat, t1 <= t < t2 -> ~~ scheduled_at sched j t) ->
  service_during sched j t1 t2 = 0

----------------------------------------------------------------------------- *)


    Proof.
      intros t1 t2 NSCHED.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 723)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H_scheduled_implies_serviced : ideal_progress_proc_model PState
  t1, t2 : nat
  NSCHED : forall t : nat, t1 <= t < t2 -> ~~ scheduled_at sched j t
  ============================
  service_during sched j t1 t2 = 0

----------------------------------------------------------------------------- *)


      apply big_nat_eq0; movet NEQ.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 729)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H_scheduled_implies_serviced : ideal_progress_proc_model PState
  t1, t2 : nat
  NSCHED : forall t : nat, t1 <= t < t2 -> ~~ scheduled_at sched j t
  t : nat
  NEQ : t1 <= t < t2
  ============================
  service_at sched j t = 0

----------------------------------------------------------------------------- *)


      by apply no_service_not_scheduled, NSCHED.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


    Qed.

If a job is scheduled at some point in an interval, it receives positive cumulative service during the interval...
    Lemma scheduled_implies_cumulative_service:
       t1 t2,
        ( t,
            t1 t < t2
            scheduled_at sched j t)
        service_during sched j t1 t2 > 0.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 731)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H_scheduled_implies_serviced : ideal_progress_proc_model PState
  ============================
  forall t1 t2 : nat,
  (exists t : nat, t1 <= t < t2 /\ scheduled_at sched j t) ->
  0 < service_during sched j t1 t2

----------------------------------------------------------------------------- *)


    Proof.
      movet1 t2 [t' [TIMES SCHED]].

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 754)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H_scheduled_implies_serviced : ideal_progress_proc_model PState
  t1, t2, t' : nat
  TIMES : t1 <= t' < t2
  SCHED : scheduled_at sched j t'
  ============================
  0 < service_during sched j t1 t2

----------------------------------------------------------------------------- *)


      rewrite service_during_service_at.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 765)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H_scheduled_implies_serviced : ideal_progress_proc_model PState
  t1, t2, t' : nat
  TIMES : t1 <= t' < t2
  SCHED : scheduled_at sched j t'
  ============================
  exists t : nat, t1 <= t < t2 /\ 0 < service_at sched j t

----------------------------------------------------------------------------- *)


       t'; split ⇒ //.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 770)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H_scheduled_implies_serviced : ideal_progress_proc_model PState
  t1, t2, t' : nat
  TIMES : t1 <= t' < t2
  SCHED : scheduled_at sched j t'
  ============================
  0 < service_at sched j t'

----------------------------------------------------------------------------- *)


      move: SCHED.
(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 794)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H_scheduled_implies_serviced : ideal_progress_proc_model PState
  t1, t2, t' : nat
  TIMES : t1 <= t' < t2
  ============================
  scheduled_at sched j t' -> 0 < service_at sched j t'

----------------------------------------------------------------------------- *)


rewrite /scheduled_at /service_at.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 808)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H_scheduled_implies_serviced : ideal_progress_proc_model PState
  t1, t2, t' : nat
  TIMES : t1 <= t' < t2
  ============================
  scheduled_in j (sched t') -> 0 < service_in j (sched t')

----------------------------------------------------------------------------- *)


        by apply (H_scheduled_implies_serviced j (sched t')).

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


    Qed.

...which again applies to total service, too.
    Corollary scheduled_implies_nonzero_service:
       t,
        ( t',
            t' < t
            scheduled_at sched j t')
        service sched j t > 0.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 741)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H_scheduled_implies_serviced : ideal_progress_proc_model PState
  ============================
  forall t : nat,
  (exists t' : nat, t' < t /\ scheduled_at sched j t') ->
  0 < service sched j t

----------------------------------------------------------------------------- *)


    Proof.
      movet [t' [TT SCHED]].

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 763)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H_scheduled_implies_serviced : ideal_progress_proc_model PState
  t, t' : nat
  TT : t' < t
  SCHED : scheduled_at sched j t'
  ============================
  0 < service sched j t

----------------------------------------------------------------------------- *)


      rewrite /service.
(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 770)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H_scheduled_implies_serviced : ideal_progress_proc_model PState
  t, t' : nat
  TT : t' < t
  SCHED : scheduled_at sched j t'
  ============================
  0 < service_during sched j 0 t

----------------------------------------------------------------------------- *)


apply scheduled_implies_cumulative_service.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 771)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H_scheduled_implies_serviced : ideal_progress_proc_model PState
  t, t' : nat
  TT : t' < t
  SCHED : scheduled_at sched j t'
  ============================
  exists t0 : nat, 0 <= t0 < t /\ scheduled_at sched j t0

----------------------------------------------------------------------------- *)


       t'; split ⇒ //.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


    Qed.

  End GuaranteedService.

Furthermore, if we know that jobs are not released early, then we can narrow the interval during which they must have been scheduled.
  Section AfterArrival.

    Context `{JobArrival Job}.

Assume that jobs must arrive to execute.
    Hypothesis H_jobs_must_arrive:
      jobs_must_arrive_to_execute sched.

We prove that any job with positive cumulative service at time [t] must have been scheduled some time since its arrival and before time [t].
    Lemma positive_service_implies_scheduled_since_arrival:
       t,
        service sched j t > 0
         t', (job_arrival j t' < t scheduled_at sched j t').

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 700)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H0 : JobArrival Job
  H_jobs_must_arrive : jobs_must_arrive_to_execute sched
  ============================
  forall t : instant,
  0 < service sched j t ->
  exists t' : nat, job_arrival j <= t' < t /\ scheduled_at sched j t'

----------------------------------------------------------------------------- *)


    Proof.
      movet SERVICE.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 702)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H0 : JobArrival Job
  H_jobs_must_arrive : jobs_must_arrive_to_execute sched
  t : instant
  SERVICE : 0 < service sched j t
  ============================
  exists t' : nat, job_arrival j <= t' < t /\ scheduled_at sched j t'

----------------------------------------------------------------------------- *)


      have EX_SCHED := positive_service_implies_scheduled_before t SERVICE.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 707)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H0 : JobArrival Job
  H_jobs_must_arrive : jobs_must_arrive_to_execute sched
  t : instant
  SERVICE : 0 < service sched j t
  EX_SCHED : exists t' : nat, t' < t /\ scheduled_at sched j t'
  ============================
  exists t' : nat, job_arrival j <= t' < t /\ scheduled_at sched j t'

----------------------------------------------------------------------------- *)


      inversion EX_SCHED as [t'' [TIMES SCHED_AT]].

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 720)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H0 : JobArrival Job
  H_jobs_must_arrive : jobs_must_arrive_to_execute sched
  t : instant
  SERVICE : 0 < service sched j t
  EX_SCHED : exists t' : nat, t' < t /\ scheduled_at sched j t'
  t'' : nat
  TIMES : t'' < t
  SCHED_AT : scheduled_at sched j t''
  ============================
  exists t' : nat, job_arrival j <= t' < t /\ scheduled_at sched j t'

----------------------------------------------------------------------------- *)


       t''; split; last by assumption.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 724)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H0 : JobArrival Job
  H_jobs_must_arrive : jobs_must_arrive_to_execute sched
  t : instant
  SERVICE : 0 < service sched j t
  EX_SCHED : exists t' : nat, t' < t /\ scheduled_at sched j t'
  t'' : nat
  TIMES : t'' < t
  SCHED_AT : scheduled_at sched j t''
  ============================
  job_arrival j <= t'' < t

----------------------------------------------------------------------------- *)


      rewrite /(_ && _) ifT //.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 742)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H0 : JobArrival Job
  H_jobs_must_arrive : jobs_must_arrive_to_execute sched
  t : instant
  SERVICE : 0 < service sched j t
  EX_SCHED : exists t' : nat, t' < t /\ scheduled_at sched j t'
  t'' : nat
  TIMES : t'' < t
  SCHED_AT : scheduled_at sched j t''
  ============================
  job_arrival j <= t''

----------------------------------------------------------------------------- *)


      move: H_jobs_must_arrive.
(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 765)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H0 : JobArrival Job
  H_jobs_must_arrive : jobs_must_arrive_to_execute sched
  t : instant
  SERVICE : 0 < service sched j t
  EX_SCHED : exists t' : nat, t' < t /\ scheduled_at sched j t'
  t'' : nat
  TIMES : t'' < t
  SCHED_AT : scheduled_at sched j t''
  ============================
  jobs_must_arrive_to_execute sched -> job_arrival j <= t''

----------------------------------------------------------------------------- *)


rewrite /jobs_must_arrive_to_execute /has_arrivedARR.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 778)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H0 : JobArrival Job
  H_jobs_must_arrive : jobs_must_arrive_to_execute sched
  t : instant
  SERVICE : 0 < service sched j t
  EX_SCHED : exists t' : nat, t' < t /\ scheduled_at sched j t'
  t'' : nat
  TIMES : t'' < t
  SCHED_AT : scheduled_at sched j t''
  ARR : forall (j : Job) (t : instant),
        scheduled_at sched j t -> job_arrival j <= t
  ============================
  job_arrival j <= t''

----------------------------------------------------------------------------- *)


        by apply: ARR; exact.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


    Qed.

    Lemma not_scheduled_before_arrival:
       t, t < job_arrival j ~~ scheduled_at sched j t.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 707)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H0 : JobArrival Job
  H_jobs_must_arrive : jobs_must_arrive_to_execute sched
  ============================
  forall t : nat, t < job_arrival j -> ~~ scheduled_at sched j t

----------------------------------------------------------------------------- *)


    Proof.
      movet EARLY.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 709)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H0 : JobArrival Job
  H_jobs_must_arrive : jobs_must_arrive_to_execute sched
  t : nat
  EARLY : t < job_arrival j
  ============================
  ~~ scheduled_at sched j t

----------------------------------------------------------------------------- *)


      apply: (contra (H_jobs_must_arrive j t)).

(* ----------------------------------[ coqtop ]---------------------------------

1 focused subgoal
(shelved: 1) (ID 720)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H0 : JobArrival Job
  H_jobs_must_arrive : jobs_must_arrive_to_execute sched
  t : nat
  EARLY : t < job_arrival j
  ============================
  ~~ has_arrived j t

----------------------------------------------------------------------------- *)


      rewrite /has_arrived -ltnNge //.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


   Qed.

We show that job [j] does not receive service at any time [t] prior to its arrival.
    Lemma service_before_job_arrival_zero:
       t,
        t < job_arrival j
        service_at sched j t = 0.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 716)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H0 : JobArrival Job
  H_jobs_must_arrive : jobs_must_arrive_to_execute sched
  ============================
  forall t : nat, t < job_arrival j -> service_at sched j t = 0

----------------------------------------------------------------------------- *)


    Proof.
      movet NOT_ARR.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 718)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H0 : JobArrival Job
  H_jobs_must_arrive : jobs_must_arrive_to_execute sched
  t : nat
  NOT_ARR : t < job_arrival j
  ============================
  service_at sched j t = 0

----------------------------------------------------------------------------- *)


      rewrite not_scheduled_implies_no_service // not_scheduled_before_arrival //.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


    Qed.

Note that the same property applies to the cumulative service.
    Lemma cumulative_service_before_job_arrival_zero :
       t1 t2 : instant,
        t2 job_arrival j
        service_during sched j t1 t2 = 0.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 724)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H0 : JobArrival Job
  H_jobs_must_arrive : jobs_must_arrive_to_execute sched
  ============================
  forall t1 t2 : instant,
  t2 <= job_arrival j -> service_during sched j t1 t2 = 0

----------------------------------------------------------------------------- *)


    Proof.
      movet1 t2 EARLY.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 727)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H0 : JobArrival Job
  H_jobs_must_arrive : jobs_must_arrive_to_execute sched
  t1, t2 : instant
  EARLY : t2 <= job_arrival j
  ============================
  service_during sched j t1 t2 = 0

----------------------------------------------------------------------------- *)


      rewrite /service_during.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 734)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H0 : JobArrival Job
  H_jobs_must_arrive : jobs_must_arrive_to_execute sched
  t1, t2 : instant
  EARLY : t2 <= job_arrival j
  ============================
  \sum_(t1 <= t < t2) service_at sched j t = 0

----------------------------------------------------------------------------- *)


      have ZERO_SUM: \sum_(t1 t < t2) service_at sched j t = \sum_(t1 t < t2) 0;
        last by rewrite ZERO_SUM sum0.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 748)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H0 : JobArrival Job
  H_jobs_must_arrive : jobs_must_arrive_to_execute sched
  t1, t2 : instant
  EARLY : t2 <= job_arrival j
  ============================
  \sum_(t1 <= t < t2) service_at sched j t = \sum_(t1 <= t < t2) 0

----------------------------------------------------------------------------- *)


      rewrite big_nat_cond [in RHS]big_nat_cond.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 782)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H0 : JobArrival Job
  H_jobs_must_arrive : jobs_must_arrive_to_execute sched
  t1, t2 : instant
  EARLY : t2 <= job_arrival j
  ============================
  \sum_(t1 <= i < t2 | (t1 <= i < t2) && true) service_at sched j i =
  \sum_(t1 <= i < t2 | (t1 <= i < t2) && true) 0

----------------------------------------------------------------------------- *)


      apply: eq_bigri /andP [TIMES _].
(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 875)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H0 : JobArrival Job
  H_jobs_must_arrive : jobs_must_arrive_to_execute sched
  t1, t2 : instant
  EARLY : t2 <= job_arrival j
  i : nat
  TIMES : t1 <= i < t2
  ============================
  service_at sched j i = 0

----------------------------------------------------------------------------- *)


move: TIMES ⇒ /andP [le_t1_i lt_i_t2].

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 917)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H0 : JobArrival Job
  H_jobs_must_arrive : jobs_must_arrive_to_execute sched
  t1, t2 : instant
  EARLY : t2 <= job_arrival j
  i : nat
  le_t1_i : t1 <= i
  lt_i_t2 : i < t2
  ============================
  service_at sched j i = 0

----------------------------------------------------------------------------- *)


      apply (service_before_job_arrival_zero i).

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 918)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H0 : JobArrival Job
  H_jobs_must_arrive : jobs_must_arrive_to_execute sched
  t1, t2 : instant
  EARLY : t2 <= job_arrival j
  i : nat
  le_t1_i : t1 <= i
  lt_i_t2 : i < t2
  ============================
  i < job_arrival j

----------------------------------------------------------------------------- *)


        by apply leq_trans with (n := t2); auto.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


    Qed.

Hence, one can ignore the service received by a job before its arrival time...
    Lemma ignore_service_before_arrival:
       t1 t2,
        t1 job_arrival j
        t2 job_arrival j
        service_during sched j t1 t2 = service_during sched j (job_arrival j) t2.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 741)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H0 : JobArrival Job
  H_jobs_must_arrive : jobs_must_arrive_to_execute sched
  ============================
  forall t1 t2 : nat,
  t1 <= job_arrival j ->
  job_arrival j <= t2 ->
  service_during sched j t1 t2 = service_during sched j (job_arrival j) t2

----------------------------------------------------------------------------- *)


    Proof.
      movet1 t2 le_t1 le_t2.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 745)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H0 : JobArrival Job
  H_jobs_must_arrive : jobs_must_arrive_to_execute sched
  t1, t2 : nat
  le_t1 : t1 <= job_arrival j
  le_t2 : job_arrival j <= t2
  ============================
  service_during sched j t1 t2 = service_during sched j (job_arrival j) t2

----------------------------------------------------------------------------- *)


      rewrite -(service_during_cat sched j t1 (job_arrival j) t2).

(* ----------------------------------[ coqtop ]---------------------------------

2 subgoals (ID 758)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H0 : JobArrival Job
  H_jobs_must_arrive : jobs_must_arrive_to_execute sched
  t1, t2 : nat
  le_t1 : t1 <= job_arrival j
  le_t2 : job_arrival j <= t2
  ============================
  service_during sched j t1 (job_arrival j) +
  service_during sched j (job_arrival j) t2 =
  service_during sched j (job_arrival j) t2

subgoal 2 (ID 759) is:
 t1 <= job_arrival j <= t2

----------------------------------------------------------------------------- *)


      rewrite cumulative_service_before_job_arrival_zero //.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 759)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H0 : JobArrival Job
  H_jobs_must_arrive : jobs_must_arrive_to_execute sched
  t1, t2 : nat
  le_t1 : t1 <= job_arrival j
  le_t2 : job_arrival j <= t2
  ============================
  t1 <= job_arrival j <= t2

----------------------------------------------------------------------------- *)


        by apply/andP; split; exact.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


    Qed.

... which we can also state in terms of cumulative service.
    Corollary no_service_before_arrival:
       t,
        t job_arrival j service sched j t = 0.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 750)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H0 : JobArrival Job
  H_jobs_must_arrive : jobs_must_arrive_to_execute sched
  ============================
  forall t : nat, t <= job_arrival j -> service sched j t = 0

----------------------------------------------------------------------------- *)


    Proof.
      movet EARLY.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 752)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  H0 : JobArrival Job
  H_jobs_must_arrive : jobs_must_arrive_to_execute sched
  t : nat
  EARLY : t <= job_arrival j
  ============================
  service sched j t = 0

----------------------------------------------------------------------------- *)


      rewrite /service cumulative_service_before_job_arrival_zero //.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


    Qed.

  End AfterArrival.

In this section, we prove some lemmas about time instants with same service.
  Section TimesWithSameService.

Consider any time instants [t1] and [t2]...
    Variable t1 t2: instant.

...where [t1] is no later than [t2]...
    Hypothesis H_t1_le_t2: t1 t2.

...and where job [j] has received the same amount of service.
    Hypothesis H_same_service: service sched j t1 = service sched j t2.

First, we observe that this means that the job receives no service during [t1, t2)...
    Lemma constant_service_implies_no_service_during:
      service_during sched j t1 t2 = 0.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 698)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  H_t1_le_t2 : t1 <= t2
  H_same_service : service sched j t1 = service sched j t2
  ============================
  service_during sched j t1 t2 = 0

----------------------------------------------------------------------------- *)


    Proof.
      move: H_same_service.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 699)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  H_t1_le_t2 : t1 <= t2
  H_same_service : service sched j t1 = service sched j t2
  ============================
  service sched j t1 = service sched j t2 -> service_during sched j t1 t2 = 0

----------------------------------------------------------------------------- *)


      rewrite -(service_cat sched j t1 t2) // -[service sched j t1 in LHS]addn0 ⇒ /eqP.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 806)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  H_t1_le_t2 : t1 <= t2
  H_same_service : service sched j t1 = service sched j t2
  ============================
  service sched j t1 + 0 == service sched j t1 + service_during sched j t1 t2 ->
  service_during sched j t1 t2 = 0

----------------------------------------------------------------------------- *)


      by rewrite eqn_add2l ⇒ /eqP //.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


    Qed.

...which of course implies that it does not receive service at any point, either.
    Lemma constant_service_implies_not_scheduled:
       t,
        t1 t < t2 service_at sched j t = 0.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 705)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  H_t1_le_t2 : t1 <= t2
  H_same_service : service sched j t1 = service sched j t2
  ============================
  forall t : nat, t1 <= t < t2 -> service_at sched j t = 0

----------------------------------------------------------------------------- *)


    Proof.
      movet /andP [GE_t1 LT_t2].

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 746)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  H_t1_le_t2 : t1 <= t2
  H_same_service : service sched j t1 = service sched j t2
  t : nat
  GE_t1 : t1 <= t
  LT_t2 : t < t2
  ============================
  service_at sched j t = 0

----------------------------------------------------------------------------- *)


      move: constant_service_implies_no_service_during.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 747)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  H_t1_le_t2 : t1 <= t2
  H_same_service : service sched j t1 = service sched j t2
  t : nat
  GE_t1 : t1 <= t
  LT_t2 : t < t2
  ============================
  service_during sched j t1 t2 = 0 -> service_at sched j t = 0

----------------------------------------------------------------------------- *)


      rewrite /service_during big_nat_eq0IS_ZERO.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 782)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  H_t1_le_t2 : t1 <= t2
  H_same_service : service sched j t1 = service sched j t2
  t : nat
  GE_t1 : t1 <= t
  LT_t2 : t < t2
  IS_ZERO : forall i : nat, t1 <= i < t2 -> service_at sched j i = 0
  ============================
  service_at sched j t = 0

----------------------------------------------------------------------------- *)


      apply IS_ZERO.
(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 783)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  H_t1_le_t2 : t1 <= t2
  H_same_service : service sched j t1 = service sched j t2
  t : nat
  GE_t1 : t1 <= t
  LT_t2 : t < t2
  IS_ZERO : forall i : nat, t1 <= i < t2 -> service_at sched j i = 0
  ============================
  t1 <= t < t2

----------------------------------------------------------------------------- *)


apply /andP; split ⇒ //.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


    Qed.

We show that job [j] receives service at some point [t < t1] iff [j] receives service at some point [t' < t2].
    Lemma same_service_implies_serviced_at_earlier_times:
      [ t: 'I_t1, service_at sched j t > 0] =
      [ t': 'I_t2, service_at sched j t' > 0].

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 722)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  H_t1_le_t2 : t1 <= t2
  H_same_service : service sched j t1 = service sched j t2
  ============================
  ~~
  FiniteQuant.quant0b (T:=ordinal_finType t1)
    (fun t : 'I_t1 =>
     FiniteQuant.ex (T:=ordinal_finType t1) (, 0 < service_at sched j t) t) =
  ~~
  FiniteQuant.quant0b (T:=ordinal_finType t2)
    (fun t' : 'I_t2 =>
     FiniteQuant.ex (T:=ordinal_finType t2) (, 0 < service_at sched j t') t')

----------------------------------------------------------------------------- *)


    Proof.
      apply /idP/idP ⇒ /existsP [t SERVICED].

(* ----------------------------------[ coqtop ]---------------------------------

2 subgoals (ID 833)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  H_t1_le_t2 : t1 <= t2
  H_same_service : service sched j t1 = service sched j t2
  t : ordinal_finType t1
  SERVICED : 0 < service_at sched j t
  ============================
  ~~
  FiniteQuant.quant0b (T:=ordinal_finType t2)
    (fun t' : 'I_t2 =>
     FiniteQuant.ex (T:=ordinal_finType t2) (, 0 < service_at sched j t') t')

subgoal 2 (ID 834) is:
 ~~
 FiniteQuant.quant0b (T:=ordinal_finType t1)
   (fun t0 : 'I_t1 =>
    FiniteQuant.ex (T:=ordinal_finType t1) (, 0 < service_at sched j t0) t0)

----------------------------------------------------------------------------- *)


      {

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 833)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  H_t1_le_t2 : t1 <= t2
  H_same_service : service sched j t1 = service sched j t2
  t : ordinal_finType t1
  SERVICED : 0 < service_at sched j t
  ============================
  ~~
  FiniteQuant.quant0b (T:=ordinal_finType t2)
    (fun t' : 'I_t2 =>
     FiniteQuant.ex (T:=ordinal_finType t2) (, 0 < service_at sched j t') t')

----------------------------------------------------------------------------- *)


        have LE: t < t2
          by apply: (leq_trans _ H_t1_le_t2) ⇒ //.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 848)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  H_t1_le_t2 : t1 <= t2
  H_same_service : service sched j t1 = service sched j t2
  t : ordinal_finType t1
  SERVICED : 0 < service_at sched j t
  LE : t < t2
  ============================
  ~~
  FiniteQuant.quant0b (T:=ordinal_finType t2)
    (fun t' : 'I_t2 =>
     FiniteQuant.ex (T:=ordinal_finType t2) (, 0 < service_at sched j t') t')

----------------------------------------------------------------------------- *)


        by apply /existsP; (Ordinal LE).

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 834)

subgoal 1 (ID 834) is:
 ~~
 FiniteQuant.quant0b (T:=ordinal_finType t1)
   (fun t0 : 'I_t1 =>
    FiniteQuant.ex (T:=ordinal_finType t1) (, 0 < service_at sched j t0) t0)

----------------------------------------------------------------------------- *)


      }

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 834)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  H_t1_le_t2 : t1 <= t2
  H_same_service : service sched j t1 = service sched j t2
  t : ordinal_finType t2
  SERVICED : 0 < service_at sched j t
  ============================
  ~~
  FiniteQuant.quant0b (T:=ordinal_finType t1)
    (fun t0 : 'I_t1 =>
     FiniteQuant.ex (T:=ordinal_finType t1) (, 0 < service_at sched j t0) t0)

----------------------------------------------------------------------------- *)


      {

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 834)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  H_t1_le_t2 : t1 <= t2
  H_same_service : service sched j t1 = service sched j t2
  t : ordinal_finType t2
  SERVICED : 0 < service_at sched j t
  ============================
  ~~
  FiniteQuant.quant0b (T:=ordinal_finType t1)
    (fun t0 : 'I_t1 =>
     FiniteQuant.ex (T:=ordinal_finType t1) (, 0 < service_at sched j t0) t0)

----------------------------------------------------------------------------- *)


        case (boolP (t < t1)) ⇒ LE.

(* ----------------------------------[ coqtop ]---------------------------------

2 subgoals (ID 882)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  H_t1_le_t2 : t1 <= t2
  H_same_service : service sched j t1 = service sched j t2
  t : ordinal_finType t2
  SERVICED : 0 < service_at sched j t
  LE : t < t1
  ============================
  ~~
  FiniteQuant.quant0b (T:=ordinal_finType t1)
    (fun t0 : 'I_t1 =>
     FiniteQuant.ex (T:=ordinal_finType t1) (, 0 < service_at sched j t0) t0)

subgoal 2 (ID 883) is:
 ~~
 FiniteQuant.quant0b (T:=ordinal_finType t1)
   (fun t0 : 'I_t1 =>
    FiniteQuant.ex (T:=ordinal_finType t1) (, 0 < service_at sched j t0) t0)

----------------------------------------------------------------------------- *)


        - by apply /existsP; (Ordinal LE).

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 883)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  H_t1_le_t2 : t1 <= t2
  H_same_service : service sched j t1 = service sched j t2
  t : ordinal_finType t2
  SERVICED : 0 < service_at sched j t
  LE : ~~ (t < t1)
  ============================
  ~~
  FiniteQuant.quant0b (T:=ordinal_finType t1)
    (fun t0 : 'I_t1 =>
     FiniteQuant.ex (T:=ordinal_finType t1) (, 0 < service_at sched j t0) t0)

----------------------------------------------------------------------------- *)


        - exfalso.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 912)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  H_t1_le_t2 : t1 <= t2
  H_same_service : service sched j t1 = service sched j t2
  t : ordinal_finType t2
  SERVICED : 0 < service_at sched j t
  LE : ~~ (t < t1)
  ============================
  False

----------------------------------------------------------------------------- *)


          have TIMES: t1 t < t2
            by apply /andP; split ⇒ //; rewrite leqNgt //.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 968)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  H_t1_le_t2 : t1 <= t2
  H_same_service : service sched j t1 = service sched j t2
  t : ordinal_finType t2
  SERVICED : 0 < service_at sched j t
  LE : ~~ (t < t1)
  TIMES : t1 <= t < t2
  ============================
  False

----------------------------------------------------------------------------- *)


          have NO_SERVICE := constant_service_implies_not_scheduled t TIMES.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 973)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  H_t1_le_t2 : t1 <= t2
  H_same_service : service sched j t1 = service sched j t2
  t : ordinal_finType t2
  SERVICED : 0 < service_at sched j t
  LE : ~~ (t < t1)
  TIMES : t1 <= t < t2
  NO_SERVICE : service_at sched j t = 0
  ============================
  False

----------------------------------------------------------------------------- *)


          by rewrite NO_SERVICE in SERVICED.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


      }

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


    Qed.

Then, under the assumption that scheduled jobs receives service, we can translate this into a claim about scheduled_at.
Assume [j] always receives some positive service.
We show that job [j] is scheduled at some point [t < t1] iff [j] is scheduled at some point [t' < t2].
    Lemma same_service_implies_scheduled_at_earlier_times:
      [ t: 'I_t1, scheduled_at sched j t] =
      [ t': 'I_t2, scheduled_at sched j t'].

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 741)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  H_t1_le_t2 : t1 <= t2
  H_same_service : service sched j t1 = service sched j t2
  H_scheduled_implies_serviced : ideal_progress_proc_model PState
  ============================
  ~~
  FiniteQuant.quant0b (T:=ordinal_finType t1)
    (fun t : 'I_t1 =>
     FiniteQuant.ex (T:=ordinal_finType t1) (, scheduled_at sched j t) t) =
  ~~
  FiniteQuant.quant0b (T:=ordinal_finType t2)
    (fun t' : 'I_t2 =>
     FiniteQuant.ex (T:=ordinal_finType t2) (, scheduled_at sched j t') t')

----------------------------------------------------------------------------- *)


    Proof.
      have CONV: B, [ b: 'I_B, scheduled_at sched j b]
                           = [ b: 'I_B, service_at sched j b > 0].

(* ----------------------------------[ coqtop ]---------------------------------

2 subgoals (ID 759)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  H_t1_le_t2 : t1 <= t2
  H_same_service : service sched j t1 = service sched j t2
  H_scheduled_implies_serviced : ideal_progress_proc_model PState
  ============================
  forall B : nat,
  ~~
  FiniteQuant.quant0b (T:=ordinal_finType B)
    (fun b : 'I_B =>
     FiniteQuant.ex (T:=ordinal_finType B) (, scheduled_at sched j b) b) =
  ~~
  FiniteQuant.quant0b (T:=ordinal_finType B)
    (fun b : 'I_B =>
     FiniteQuant.ex (T:=ordinal_finType B) (, 0 < service_at sched j b) b)

subgoal 2 (ID 761) is:
 ~~
 FiniteQuant.quant0b (T:=ordinal_finType t1)
   (fun t : 'I_t1 =>
    FiniteQuant.ex (T:=ordinal_finType t1) (, scheduled_at sched j t) t) =
 ~~
 FiniteQuant.quant0b (T:=ordinal_finType t2)
   (fun t' : 'I_t2 =>
    FiniteQuant.ex (T:=ordinal_finType t2) (, scheduled_at sched j t') t')

----------------------------------------------------------------------------- *)


      {

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 759)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  H_t1_le_t2 : t1 <= t2
  H_same_service : service sched j t1 = service sched j t2
  H_scheduled_implies_serviced : ideal_progress_proc_model PState
  ============================
  forall B : nat,
  ~~
  FiniteQuant.quant0b (T:=ordinal_finType B)
    (fun b : 'I_B =>
     FiniteQuant.ex (T:=ordinal_finType B) (, scheduled_at sched j b) b) =
  ~~
  FiniteQuant.quant0b (T:=ordinal_finType B)
    (fun b : 'I_B =>
     FiniteQuant.ex (T:=ordinal_finType B) (, 0 < service_at sched j b) b)

----------------------------------------------------------------------------- *)


        moveB.
(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 762)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  H_t1_le_t2 : t1 <= t2
  H_same_service : service sched j t1 = service sched j t2
  H_scheduled_implies_serviced : ideal_progress_proc_model PState
  B : nat
  ============================
  ~~
  FiniteQuant.quant0b (T:=ordinal_finType B)
    (fun b : 'I_B =>
     FiniteQuant.ex (T:=ordinal_finType B) (, scheduled_at sched j b) b) =
  ~~
  FiniteQuant.quant0b (T:=ordinal_finType B)
    (fun b : 'I_B =>
     FiniteQuant.ex (T:=ordinal_finType B) (, 0 < service_at sched j b) b)

----------------------------------------------------------------------------- *)


apply/idP/idP ⇒ /existsP [b P]; apply /existsP; b.

(* ----------------------------------[ coqtop ]---------------------------------

2 subgoals (ID 924)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  H_t1_le_t2 : t1 <= t2
  H_same_service : service sched j t1 = service sched j t2
  H_scheduled_implies_serviced : ideal_progress_proc_model PState
  B : nat
  b : ordinal_finType B
  P : scheduled_at sched j b
  ============================
  0 < service_at sched j b

subgoal 2 (ID 926) is:
 scheduled_at sched j b

----------------------------------------------------------------------------- *)


        - by move: P; rewrite /scheduled_at /service_at;
            apply (H_scheduled_implies_serviced j (sched b)).

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 926)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  H_t1_le_t2 : t1 <= t2
  H_same_service : service sched j t1 = service sched j t2
  H_scheduled_implies_serviced : ideal_progress_proc_model PState
  B : nat
  b : ordinal_finType B
  P : 0 < service_at sched j b
  ============================
  scheduled_at sched j b

----------------------------------------------------------------------------- *)


        - by apply service_at_implies_scheduled_at.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 761)

subgoal 1 (ID 761) is:
 ~~
 FiniteQuant.quant0b (T:=ordinal_finType t1)
   (fun t : 'I_t1 =>
    FiniteQuant.ex (T:=ordinal_finType t1) (, scheduled_at sched j t) t) =
 ~~
 FiniteQuant.quant0b (T:=ordinal_finType t2)
   (fun t' : 'I_t2 =>
    FiniteQuant.ex (T:=ordinal_finType t2) (, scheduled_at sched j t') t')

----------------------------------------------------------------------------- *)


      }

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 761)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  H_t1_le_t2 : t1 <= t2
  H_same_service : service sched j t1 = service sched j t2
  H_scheduled_implies_serviced : ideal_progress_proc_model PState
  CONV : forall B : nat,
         ~~
         FiniteQuant.quant0b (T:=ordinal_finType B)
           (fun b : 'I_B =>
            FiniteQuant.ex (T:=ordinal_finType B) 
              (, scheduled_at sched j b) b) =
         ~~
         FiniteQuant.quant0b (T:=ordinal_finType B)
           (fun b : 'I_B =>
            FiniteQuant.ex (T:=ordinal_finType B)
              (, 0 < service_at sched j b) b)
  ============================
  ~~
  FiniteQuant.quant0b (T:=ordinal_finType t1)
    (fun t : 'I_t1 =>
     FiniteQuant.ex (T:=ordinal_finType t1) (, scheduled_at sched j t) t) =
  ~~
  FiniteQuant.quant0b (T:=ordinal_finType t2)
    (fun t' : 'I_t2 =>
     FiniteQuant.ex (T:=ordinal_finType t2) (, scheduled_at sched j t') t')

----------------------------------------------------------------------------- *)


      rewrite !CONV.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 949)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched : schedule PState
  j : Job
  t1, t2 : instant
  H_t1_le_t2 : t1 <= t2
  H_same_service : service sched j t1 = service sched j t2
  H_scheduled_implies_serviced : ideal_progress_proc_model PState
  CONV : forall B : nat,
         ~~
         FiniteQuant.quant0b (T:=ordinal_finType B)
           (fun b : 'I_B =>
            FiniteQuant.ex (T:=ordinal_finType B) 
              (, scheduled_at sched j b) b) =
         ~~
         FiniteQuant.quant0b (T:=ordinal_finType B)
           (fun b : 'I_B =>
            FiniteQuant.ex (T:=ordinal_finType B)
              (, 0 < service_at sched j b) b)
  ============================
  ~~
  FiniteQuant.quant0b (T:=ordinal_finType t1)
    (fun b : 'I_t1 =>
     FiniteQuant.ex (T:=ordinal_finType t1) (, 0 < service_at sched j b) b) =
  ~~
  FiniteQuant.quant0b (T:=ordinal_finType t2)
    (fun b : 'I_t2 =>
     FiniteQuant.ex (T:=ordinal_finType t2) (, 0 < service_at sched j b) b)

----------------------------------------------------------------------------- *)


      apply same_service_implies_serviced_at_earlier_times.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


    Qed.
  End TimesWithSameService.

End RelationToScheduled.

Section ServiceInTwoSchedules.

Consider any job type and any processor model.
  Context {Job: JobType}.
  Context {PState: Type}.
  Context `{ProcessorState Job PState}.

Consider any two given schedules...
  Variable sched1 sched2: schedule PState.

Given an interval in which the schedules provide the same service to a job at each instant, we can prove that the cumulative service received during the interval has to be the same.
Consider two time instants...
    Variable t1 t2 : instant.

...and a given job that is to be scheduled.
    Variable j: Job.

Assume that, in any instant between [t1] and [t2] the service provided to [j] from the two schedules is the same.
    Hypothesis H_sched1_sched2_same_service_at:
       t, t1 t < t2
           service_at sched1 j t = service_at sched2 j t.

It follows that the service provided during [t1] and [t2] is also the same.
    Lemma same_service_during:
      service_during sched1 j t1 t2 = service_during sched2 j t1 t2.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 641)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched1, sched2 : schedule PState
  t1, t2 : instant
  j : Job
  H_sched1_sched2_same_service_at : forall t : nat,
                                    t1 <= t < t2 ->
                                    service_at sched1 j t =
                                    service_at sched2 j t
  ============================
  service_during sched1 j t1 t2 = service_during sched2 j t1 t2

----------------------------------------------------------------------------- *)


    Proof.
      rewrite /service_during.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 648)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched1, sched2 : schedule PState
  t1, t2 : instant
  j : Job
  H_sched1_sched2_same_service_at : forall t : nat,
                                    t1 <= t < t2 ->
                                    service_at sched1 j t =
                                    service_at sched2 j t
  ============================
  \sum_(t1 <= t < t2) service_at sched1 j t =
  \sum_(t1 <= t < t2) service_at sched2 j t

----------------------------------------------------------------------------- *)


      apply eq_big_nat.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 649)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched1, sched2 : schedule PState
  t1, t2 : instant
  j : Job
  H_sched1_sched2_same_service_at : forall t : nat,
                                    t1 <= t < t2 ->
                                    service_at sched1 j t =
                                    service_at sched2 j t
  ============================
  forall i : nat,
  t1 <= i < t2 -> service_at sched1 j i = service_at sched2 j i

----------------------------------------------------------------------------- *)


      by apply H_sched1_sched2_same_service_at.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


    Qed.

  End ServiceDuringEquivalentInterval.

We can leverage the previous lemma to conclude that two schedules that match in a given interval will also have the same cumulative service across the interval.
  Corollary equal_prefix_implies_same_service_during:
     t1 t2,
      ( t, t1 t < t2 sched1 t = sched2 t)
       j, service_during sched1 j t1 t2 = service_during sched2 j t1 t2.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 640)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched1, sched2 : schedule PState
  ============================
  forall t1 t2 : nat,
  (forall t : nat, t1 <= t < t2 -> sched1 t = sched2 t) ->
  forall j : Job,
  service_during sched1 j t1 t2 = service_during sched2 j t1 t2

----------------------------------------------------------------------------- *)


  Proof.
    movet1 t2 SCHED_EQ j.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 644)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched1, sched2 : schedule PState
  t1, t2 : nat
  SCHED_EQ : forall t : nat, t1 <= t < t2 -> sched1 t = sched2 t
  j : Job
  ============================
  service_during sched1 j t1 t2 = service_during sched2 j t1 t2

----------------------------------------------------------------------------- *)


    apply same_service_duringt' RANGE.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 647)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched1, sched2 : schedule PState
  t1, t2 : nat
  SCHED_EQ : forall t : nat, t1 <= t < t2 -> sched1 t = sched2 t
  j : Job
  t' : nat
  RANGE : t1 <= t' < t2
  ============================
  service_at sched1 j t' = service_at sched2 j t'

----------------------------------------------------------------------------- *)


    by rewrite /service_at SCHED_EQ.

(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


  Qed.

For convenience, we restate the corollary also at the level of [service] for identical prefixes.
  Corollary identical_prefix_service:
     h,
      identical_prefix sched1 sched2 h
       j, service sched1 j h = service sched2 j h.

(* ----------------------------------[ coqtop ]---------------------------------

1 subgoal (ID 654)
  
  Job : JobType
  PState : Type
  H : ProcessorState Job PState
  sched1, sched2 : schedule PState
  ============================
  forall h : instant,
  identical_prefix sched1 sched2 h ->
  forall j : Job, service sched1 j h = service sched2 j h

----------------------------------------------------------------------------- *)


  Proof.
    moveh IDENT j; by apply equal_prefix_implies_same_service_during.
(* ----------------------------------[ coqtop ]---------------------------------

No more subgoals.

----------------------------------------------------------------------------- *)


Qed.

End ServiceInTwoSchedules.