Section Product.
Record PSyntax (L: RTLanguage): Type := mkPSyntax {
pIndex: Type;
pIsEmpty: pIndex + {pIndex -> False};
pState: Type;
pComponents: pIndex -> Syntax L;
pIsShared: forall i, DynamicState L (pComponents i) = pState
}.
Definition pPredicate (L: RTLanguage) (sys: PSyntax L) := { i : pIndex L sys & MdlPredicate L (pComponents L sys i)}.
(* product with shared state *)
Definition PLanguage (L: RTLanguage): RTLanguage :=
mkRTLanguage
(PSyntax L)
(pState L)
(fun mdl => TTSIndexedProduct (pState L mdl) (pIndex L mdl)
(fun i => match pIsShared L mdl i in (_ = y) return TTS y with
eq_refl => Semantic L (pComponents L mdl i)
end))
(pPredicate L)
(fun mdl => trProd _ _ _ _
(fun i pi => match pIsShared L mdl i as e in (_ = y) return
(LP (Predicate y
match e in (_ = y0) return (TTS y0) with
| eq_refl => Semantic L (pComponents L mdl i)
end))
with
| eq_refl => MdlPredicateDefinition L (pComponents L mdl i) pi
end)).
Inductive Empty: Type :=.
Record isSharedTransfo l1 l2 tr: Prop := isSharedTransfoPrf {
sameState:  forall mdl i j,
DynamicState l2 (Tmodel l1 l2 tr (pComponents l1 mdl i)) =
DynamicState l2 (Tmodel l1 l2 tr (pComponents l1 mdl j));
sameMState: forall mdl i j,
mState _ _  (Tl1l2 _ _ tr (pComponents l1 mdl i)) =
mState _ _  (Tl1l2 _ _ tr (pComponents l1 mdl j));
sameM12: forall mdl i j,
Tl1l2 _ _ tr (pComponents l1 mdl i) =
match sym_eq (sameState mdl i j) in _=y return mapping _ y with
eq_refl => match sym_eq (pIsShared l1 mdl i) in _=x return mapping x _ with
eq_refl => match pIsShared l1 mdl j in _=x return mapping x _ with
eq_refl => Tl1l2 _ _ tr (pComponents l1 mdl j)
end
end
end;
sameM21: forall mdl i j,
Tl2l1 l1 l2 tr (pComponents l1 mdl i) =
match
sym_eq (sameState mdl i j) in (_ = y)
return (mapping y (DynamicState l1 (pComponents l1 mdl i)))
with eq_refl =>
match
sym_eq (pIsShared l1 mdl i) in (_ = y)
return
(mapping (DynamicState l2 (Tmodel l1 l2 tr (pComponents l1 mdl j))) y)
with
| eq_refl =>
match
pIsShared l1 mdl j in (_ = y)
return
(mapping
(DynamicState l2 (Tmodel l1 l2 tr (pComponents l1 mdl j))) y)
with
| eq_refl => Tl2l1 l1 l2 tr (pComponents l1 mdl j)
end
end
end
}.
Definition PTransfoSyntax l1 l2 tr (h: isSharedTransfo l1 l2 tr) mdl :=
mkPSyntax l2 (pIndex l1 mdl)
(pIsEmpty l1 mdl)
(match pIsEmpty l1 mdl return Type with
inleft i => DynamicState l2 (Tmodel l1 l2 tr (pComponents l1 mdl i))
|inright h => pState l1 mdl
end)
(fun i => Tmodel l1 l2 tr (pComponents l1 mdl i))
(fun i => match pIsEmpty l1 mdl as y return
(DynamicState l2 (Tmodel l1 l2 tr (pComponents l1 mdl i)) =
match y with
| inleft i0 =>
DynamicState l2 (Tmodel l1 l2 tr (pComponents l1 mdl i0))
| inright _ => pState l1 mdl
end)
with
inleft j => sameState l1 l2 tr h mdl i j
| inright h => match h i with end
end).
Definition compSemantic l mdl i :=
match pIsShared l mdl i in (_=y) return TTS y with
eq_refl => Semantic l (pComponents l mdl i)
end.
Definition compSemanticEq l mdl i s (e: DynamicState l (pComponents l mdl i) = s) :=
match e in (_=y) return TTS y with
eq_refl => Semantic l (pComponents l mdl i)
end.
Definition Pmap12 l1 l2 tr (h: isSharedTransfo l1 l2 tr) (mdl : PSyntax l1) :=
match
pIsEmpty l1 mdl as s
return
(mapping (pState l1 mdl)
match s with
| inleft i => DynamicState l2 (Tmodel l1 l2 tr (pComponents l1 mdl i))
| inright _ => pState l1 mdl
end)
with
| inleft p =>
match
pIsShared l1 mdl p in (_ = y)
return
(mapping y (DynamicState l2 (Tmodel l1 l2 tr (pComponents l1 mdl p))))
with
| eq_refl => Tl1l2 l1 l2 tr (pComponents l1 mdl p)
end
| inright _ =>
mkMapping (pState l1 mdl) (pState l1 mdl) Unit
(fun _ : pState l1 mdl => unit)
(fun (_ : Unit) (_ : pState l1 mdl) => unit)
(fun (_ : Unit) (_ : pState l1 mdl) (_ : Time) => unit)
(fun (_ : Unit) (X : pState l1 mdl) => X)
end.
Definition Pmap21 l1 l2 tr (h : isSharedTransfo l1 l2 tr) mdl :=
match
pIsEmpty l1 mdl as s
return
(mapping
match s with
| inleft i => DynamicState l2 (Tmodel l1 l2 tr (pComponents l1 mdl i))
| inright _ => pState l1 mdl
end (pState l1 mdl))
with
| inleft p =>
match
pIsShared l1 mdl p in (_ = y)
return
(mapping (DynamicState l2 (Tmodel l1 l2 tr (pComponents l1 mdl p))) y)
with
| eq_refl => Tl2l1 l1 l2 tr (pComponents l1 mdl p)
end
| inright _ =>
mkMapping (pState l1 mdl) (pState l1 mdl) Unit
(fun _ : pState l1 mdl => unit)
(fun (_ : Unit) (_ : pState l1 mdl) => unit)
(fun (_ : Unit) (_ : pState l1 mdl) (_ : Time) => unit)
(fun (_ : Unit) (X : pState l1 mdl) => X)
end.
Definition PTpred l1 l2 tr (h : isSharedTransfo l1 l2 tr) mdl (pp : pPredicate l1 mdl):
LP (MdlPredicate (PLanguage l2) (PTransfoSyntax l1 l2 tr h mdl)) :=
match pIsEmpty l1 mdl with
| inleft _ =>
let (x, p) := pp in
addIndex (pIndex l1 mdl) (fun i => MdlPredicate l2 (Tmodel l1 l2 tr (pComponents l1 mdl i))) x
(LPTransfo (Tpred l1 l2 tr (pComponents l1 mdl x))
(LPPred (MdlPredicate l1 (pComponents l1 mdl x)) p))
| inright f => match f (projT1 pp) with end
end.
admit.
Qed.
admit.
Qed.
admit.
Qed.
admit.
Qed.
admit.
Qed.
admit.
Qed.

Lemma LPTransfo_trans:
forall Pred1 Pred2 Pred3 (tr1: Pred1 -> LP Pred2) (tr2: Pred2 -> LP Pred3) f,
LPTransfo tr2 (LPTransfo tr1 f) = LPTransfo (fun x => LPTransfo tr2 (tr1 x)) f.