Library pif_theory


Require Import include.
Require Import baseTac.
Require Import Classical.
Require Import ucert.

Definition priority := int32.

Parameter taskid: Type.

Parameter State : Type.

Parameter WaitRel: taskid -> taskid -> State -> Prop.

Parameter IsWt: taskid -> State -> Prop.

Parameter IsRdy: taskid -> State -> Prop.

Parameter CurPr: taskid -> State -> option priority.

Parameter OldPr: taskid -> State -> option priority.

Parameter IsOwner: taskid -> State -> Prop.

Definition PrioLt a b := Int.ltu a b = true.
Definition PrioLe a b := (Int.ltu a b = true \/ Int.eq a b = true).

Parameter IsCur: taskid -> State -> Prop.

Parameter TaskEx: taskid -> State -> Prop.

Inductive WaitChain: taskid -> taskid -> State -> Prop :=
| waitO : forall t S, WaitRel t S -> t <> -> WaitChain t S
| waitS : forall t t´´ S,
            WaitRel t S ->
            t <> ->
            WaitChain t´´ S ->
            WaitChain t t´´ S.

Definition PI S := exists t p , WaitChain t S /\ CurPr t S = Some p /\ CurPr S = Some /\ PrioLt p.

Definition PIF S := ~ PI S.

Definition Preemptive S :=
  forall t p,
    IsCur t S ->
    CurPr t S = Some p ->
    IsRdy t S /\
    forall , <> t -> CurPr S = Some -> IsRdy S -> PrioLe p.

Definition NoDeadLock S := forall t, IsWt t S -> exists , WaitChain t S /\ IsRdy S.

Definition PrioLift S:= (forall t po p, OldPr t S = Some po -> CurPr t S = Some p -> PrioLe po p /\ ((~ IsOwner t S) -> po = p)).

Definition StatProp S:= forall t, TaskEx t S -> IsRdy t S \/ IsWt t S.

Definition AuxProps S:=
  (forall t, TaskEx t S -> exists p po, CurPr t S = Some p /\ OldPr t S = Some po) /\
  (forall t p, CurPr t S = Some p -> TaskEx t S) /\
  (forall t p, OldPr t S = Some p -> TaskEx t S) /\
  (forall t, IsRdy t S -> TaskEx t S).

Definition UPIF S:=
  forall t tc p pc,
    t <> tc ->
    IsCur tc S ->
    OldPr t S = Some p ->
    ~ IsOwner tc S ->
    IsWt t S ->
    OldPr tc S = Some pc ->
    PrioLe p pc.

Theorem rel_pif_upif:
  forall S,
    AuxProps S ->
    NoDeadLock S ->
    PrioLift S ->
    Preemptive S ->
    StatProp S ->
    PIF S ->
    UPIF S.