Definition sequential_trace {state: Type} (tr: trace state) : Prop :=
forall k s ms s' ms',
tr k = Some (s, ms) ->
tr (S k) = Some (s' , ms') ->
ms = Terminating s'.
Definition sound_trace {state: Type} (R: state -> MetaState state -> Prop) (tr: trace state) : Prop :=
forall k s ms,
tr k = Some (s, ms) ->
R s ms.

(* Specifications: *)
Lemma sound_trace_and {state: Type}: forall R1 R2 (tr: trace state),
sound_trace (fun s ms => R1 s ms /\ R2 s ms) tr <->
sound_trace R1 tr /\ sound_trace R2 tr.
Lemma trace_app_sequential1 {state: Type}: forall (tr1 tr2: trace state),
sequential_trace (stream_app tr1 tr2) ->
sequential_trace tr1.
Lemma trace_app_sequential2 {state: Type}: forall (tr1 tr2: trace state),
is_fin_stream tr1 ->
sequential_trace (stream_app tr1 tr2) ->
sequential_trace tr2.
Lemma trace_app_sound1 {state: Type}: forall R (tr1 tr2: trace state),
sound_trace R (stream_app tr1 tr2) ->
sound_trace R tr1.
Lemma trace_app_sound2 {state: Type}: forall R (tr1 tr2: trace state),
is_fin_stream tr1 ->
sound_trace R (stream_app tr1 tr2) ->
sound_trace R tr2.