# Job Arrival Sequence in the Sporadic Model

... and any type of jobs associated with these tasks.

Consider any unique arrival sequence with consistent arrivals, ...

Consider any two jobs from the arrival sequence that stem from task tsk.
Variable j1 j2 : Job.
Hypothesis H_j1_from_arrival_sequence: arrives_in arr_seq j1.
Hypothesis H_j2_from_arrival_sequence: arrives_in arr_seq j2.

We show that a sporadic task with valid min inter-arrival time cannot have more than one job arriving at any time.
( j,
size (task_arrivals_at_job_arrival arr_seq j) > 1
False.
Proof.
move ⇒ [j [SIZE_G [PERIODIC VALID_TMIA]]].
specialize (exists_two (task_arrivals_at_job_arrival arr_seq j)) ⇒ EXISTS_TWO.
move : H_valid_arrival_sequence ⇒ [CONSISTENT UNIQ].
destruct EXISTS_TWO as [a [b [NEQ [A_IN B_IN]]]]; [by done | by apply filter_uniq | ].
rewrite mem_filter in A_IN; rewrite mem_filter in B_IN.
move: A_IN B_IN ⇒ /andP [/eqP TSKA ARRA] /andP [/eqP TSKB ARRB].
move: (ARRA); move: (ARRB); rewrite /arrivals_atA_IN B_IN.
apply in_arrseq_implies_arrives in A_IN; apply in_arrseq_implies_arrives in B_IN.
have EQ_ARR_A : (job_arrival a = job_arrival j) by rt_eauto.
have EQ_ARR_B : (job_arrival b = job_arrival j) by rt_eauto.
try ( apply uneq_job_uneq_arr with (arr_seq0 := arr_seq) (tsk0 := job_task j) in NEQ ⇒ // ) ||
apply uneq_job_uneq_arr with (arr_seq := arr_seq) (tsk := job_task j) in NEQ ⇒ //.
by rewrite EQ_ARR_A EQ_ARR_B in NEQ.
Qed.

We show that no jobs of the task tsk other than j1 arrive at the same time as j1, and thus the task arrivals at job arrival j1 consists only of job j1.
Proof.
set (task_arrivals_at_job_arrival arr_seq j1) as seq in ×.
have J_IN_FILTER : (j1 \in seq) by apply arrives_in_task_arrivals_at; rt_auto.
have SIZE_CASE : size seq = 0 size seq = 1 size seq > 1
by intros; now destruct (size seq) as [ | [ | ]]; try auto.
move: SIZE_CASE ⇒ [Z|[ONE|GTONE]].
- apply size0nil in Z.
by rewrite Z in J_IN_FILTER.
- repeat (destruct seq; try by done).
rewrite mem_seq1 in J_IN_FILTER; move : J_IN_FILTER ⇒ /eqP J1_S.
by rewrite J1_S.
- exfalso.
j1.
by repeat split ⇒ //; try rewrite H_j1_task.
Qed.

We show that no jobs of the task tsk other than j1 arrive at the same time as j1, and thus the task arrivals at job arrival j1 consists only of job j1.
Lemma only_j_at_job_arrival_j:
t,
job_arrival j1 = t
task_arrivals_at arr_seq tsk t = [::j1].
Proof.
intros t ARR.
rewrite -ARR.
Qed.

We show that a job j1 is the first job that arrives in task arrivals at job_arrival j1 by showing that the index of job j1 in task_arrivals_at_job_arrival arr_seq j1 is 0.
index j1 (task_arrivals_at_job_arrival arr_seq j1) = 0.
Proof.
Qed.

We observe that for any job j the arrival time of prev_job j is strictly less than the arrival time of j in context of periodic tasks.
Lemma prev_job_arr_lt:
job_index arr_seq j1 > 0
job_arrival (prev_job arr_seq j1) < job_arrival j1.
Proof.
intros IND.
have PREV_ARR_LTE : job_arrival (prev_job arr_seq j1) job_arrival j1 by apply prev_job_arr_lte ⇒ //.
rewrite ltn_neqAle; apply /andP.
split ⇒ //; apply /eqP.
try ( apply uneq_job_uneq_arr with (arr_seq0 := arr_seq) (tsk0 := job_task j1) ⇒ //; try by rewrite H_j1_task ) ||
apply uneq_job_uneq_arr with (arr_seq := arr_seq) (tsk := job_task j1) ⇒ //; try by rewrite H_j1_task.
- by apply prev_job_arr.
- intro EQ.
have SM_IND: job_index arr_seq j1 - 1 = job_index arr_seq j1 by rewrite -prev_job_index // EQ.
by lia.
Qed.

We show that task arrivals at job_arrival j1 is the same as task arrivals that arrive between job_arrival j1 and job_arrival j1 + 1.
We show that the task arrivals up to the previous job j1 concatenated with the sequence ::j1 (the sequence containing only the job j1) is same as task arrivals up to job_arrival j1.
Lemma prev_job_cat:
job_index arr_seq j1 > 0