Trace semantics
From Stdlib Require Import List.
From Stdlib Require Import Streams.
Import ListNotations.
From Stdlib Require Import Equalities.
From Stdlib Require Import Ensembles.
From AISAV Require Import Utils.
From AISAV Require Import Order.
From AISAV Require Import Sequence.
Transition system
A transition system have states. In our case, it will be control point * memory state, but let keep it general.
Then, it has of course transitions, that is, a function to pass from one state to another.
Here, we force it to be deterministic.
Traces
- Finite traces, the simplest one. They provide everything we need to reason on "value" semantics, that is, which values may output an execution of a program. However, they are not powerfull enough to prove things about termination, and more generally, about liveness properties, as we will see later.
- Potentially infinite traces, lifting up this limitation.
- It would remain one more general semantics, on set of set of traces instead of traces as we do here. This would allow us to reason about properties such as determinism. We won't cover it here, but it's not very different from what we see here.
Module Type TraceDefinitions
(Ty : Typ) (State : HasEqb Ty)
(Import Transitions : TransitionSystem Ty State).
(Ty : Typ) (State : HasEqb Ty)
(Import Transitions : TransitionSystem Ty State).
A trace may be a generic type, for instance a list, a streams,
or even a cumulation of both.
However, you should provide some basic operations on these traces.
For instance,
their length and how to build a trace from a state and another trace.
The empty trace is often usefull
In the same ways, we can see transitions as traces of length 2
A very useful operation is junction.
Junction concatenate two traces iff their end and being resp. match,
removing the first element of the second trace.
We can extend these definitions to sets of traces.
Module Type TraceSetSig
(Ty : Typ) (State : HasEqb Ty)
(Import Transitions : TransitionSystem Ty State)
(Import TraceDef : TraceDefinitions Ty State Transitions).
Parameter concat_set: (trace → Prop) → (trace → Prop) → (trace → Prop).
Parameter junction_set: (trace → Prop) → (trace → Prop) → (trace → Prop).
Parameter cpow : (trace → Prop) → nat → (trace → Prop).
Parameter jpow : (trace → Prop) → nat → (trace → Prop).
Parameter Valid : trace → Prop.
End TraceSetSig.
(Ty : Typ) (State : HasEqb Ty)
(Import Transitions : TransitionSystem Ty State)
(Import TraceDef : TraceDefinitions Ty State Transitions).
Parameter concat_set: (trace → Prop) → (trace → Prop) → (trace → Prop).
Parameter junction_set: (trace → Prop) → (trace → Prop) → (trace → Prop).
Parameter cpow : (trace → Prop) → nat → (trace → Prop).
Parameter jpow : (trace → Prop) → nat → (trace → Prop).
Parameter Valid : trace → Prop.
End TraceSetSig.
Note that you should include it after definitions of Trace, and before any other definitions,
if you want to include it in your module.
Module TraceSet
(Ty : Typ) (State : HasEqb Ty)
(Import Transitions : TransitionSystem Ty State)
(Import TraceDef : TraceDefinitions Ty State Transitions)
<: TraceSetSig Ty State Transitions TraceDef.
(Ty : Typ) (State : HasEqb Ty)
(Import Transitions : TransitionSystem Ty State)
(Import TraceDef : TraceDefinitions Ty State Transitions)
<: TraceSetSig Ty State Transitions TraceDef.
We can extend these definitions to sets of traces.
Definition concat_set := set_from_op concat.
Definition junction_set := set_from_op junction.
Definition cpow := generic_pow concat_set (fun x ⇒ x = epsilon).
Definition jpow := generic_pow junction_set Sigma.
Notation " t1 '^j' t2" := (junction_set t1 t2)
(at level 40, left associativity).
Definition junction_set := set_from_op junction.
Definition cpow := generic_pow concat_set (fun x ⇒ x = epsilon).
Definition jpow := generic_pow junction_set Sigma.
Notation " t1 '^j' t2" := (junction_set t1 t2)
(at level 40, left associativity).
We say that a trace sigma is valid if it respect the transition relation.
That is, forall i, transition sigma_i sigma(i+1).
TODO Put it in a module dedicated to semantics.
Inductive ValidT : trace → Prop :=
| ValidEmpty : ValidT epsilon
| ValidSucc (x y : state) (t : trace) :
transition x y → ValidT (cons x (cons y t)).
Definition Valid := ValidT.
End TraceSet.
Module Type TraceSig
(Ty : Typ) (State : HasEqb Ty)
(Transitions : TransitionSystem Ty State) :=
TraceDefinitions Ty State Transitions
<+ TraceSetSig Ty State Transitions.
| ValidEmpty : ValidT epsilon
| ValidSucc (x y : state) (t : trace) :
transition x y → ValidT (cons x (cons y t)).
Definition Valid := ValidT.
End TraceSet.
Module Type TraceSig
(Ty : Typ) (State : HasEqb Ty)
(Transitions : TransitionSystem Ty State) :=
TraceDefinitions Ty State Transitions
<+ TraceSetSig Ty State Transitions.
In addition, we want to work on semantics.
Let define a module type listing all the requirement
to consider something to be a semantic.
First of all, a semantic should output something.
Most of the time, it will be a set of states or traces.
Then, in order to apply the theorems we previously saw,
we need to provide a partial order structure on this output type.
In the idea, a set of output "lower" than another as its semantics included
in it (by the way, inclusion is a valid order,
but you may not always want to use it, as we will see for MaximalTraces).
For concrete semantics, we will almost always require it to be a complete lattice,
since it can help quite a lot with some proofs.
But for generality sake, let restrains ourself to partial orders.
Parameter r : Relation t.
Axiom t_pre_order : PreOrder r.
Axiom t_partial_order :
@PartialOrder t eq _ r t_pre_order.
Axiom t_pre_order : PreOrder r.
Axiom t_partial_order :
@PartialOrder t eq _ r t_pre_order.
Then, the semantic of a program is just an output element.
Pay attention to give it sense !
And finally, we require the ability to
express this semantics in a least fixpoint form.
This will allow us to use theorems from order theory.
LFP semantics and this semantics form are the same.
Axiom lfp_semantics :
∀ lfp,
@LFP' _ _ _ _ t_partial_order F lfp
↔ semantics = lfp.
End SemanticSig.
∀ lfp,
@LFP' _ _ _ _ t_partial_order F lfp
↔ semantics = lfp.
End SemanticSig.
This give us a very general trace semantic formulation.
Module Type TraceSemanticSig
(Ty : Typ) (State : HasEqb Ty)
(Transitions : TransitionSystem Ty State) :=
TraceSig Ty State Transitions
<+ SemanticSig.
(Ty : Typ) (State : HasEqb Ty)
(Transitions : TransitionSystem Ty State) :=
TraceSig Ty State Transitions
<+ SemanticSig.
Prefix Trace Semantics
Module ListTrace
(Ty : Typ) (State : HasEqb Ty)
(Import Transitions : TransitionSystem Ty State).
Definition trace : Type := list state.
Definition length : trace → nat := @List.length state .
Definition cons := @List.cons state.
Definition epsilon : trace := nil.
Definition Sigma (t : trace) : Prop := length t = 1.
Definition to_traces (S : state → Prop) : trace → Prop :=
fun t ⇒ match t with [x] ⇒ S x | _ ⇒ False end.
Definition trace_transitions : trace → Prop :=
fun t ⇒ match t with [x; y] ⇒ transition x y | _ ⇒ False end.
(Ty : Typ) (State : HasEqb Ty)
(Import Transitions : TransitionSystem Ty State).
Definition trace : Type := list state.
Definition length : trace → nat := @List.length state .
Definition cons := @List.cons state.
Definition epsilon : trace := nil.
Definition Sigma (t : trace) : Prop := length t = 1.
Definition to_traces (S : state → Prop) : trace → Prop :=
fun t ⇒ match t with [x] ⇒ S x | _ ⇒ False end.
Definition trace_transitions : trace → Prop :=
fun t ⇒ match t with [x; y] ⇒ transition x y | _ ⇒ False end.
For convenience, let call transitions in trace form tau.
Notation tau := trace_transitions.
Definition concat (t1 t2 : trace) : trace := t1 ++ t2.
Definition junction (t1 t2 : trace) : trace :=
match t2 with
| [] ⇒ []
| x::t2s ⇒
match last_error_list t1 with
| SomeSeq y ⇒ if State.eqb x y then concat t1 t2s
else []
| _ ⇒ []
end
end.
End ListTrace.
Module FiniteTraceOp
(Ty : Typ) (State : HasEqb Ty)
(Import Transitions : TransitionSystem Ty State).
Include ListTrace Ty State Transitions.
Include TraceSet Ty State Transitions.
Definition begin_initial (t : trace) : Prop :=
match t with
| [] ⇒ False
| x::_ ⇒ Transitions.initial x
end.
Definition end_final (t : trace) : Prop :=
match last_error_list t with
| NoneSeq | NonfiniteSeq ⇒ False
| SomeSeq x ⇒ Transitions.final x
end.
End FiniteTraceOp.
Definition concat (t1 t2 : trace) : trace := t1 ++ t2.
Definition junction (t1 t2 : trace) : trace :=
match t2 with
| [] ⇒ []
| x::t2s ⇒
match last_error_list t1 with
| SomeSeq y ⇒ if State.eqb x y then concat t1 t2s
else []
| _ ⇒ []
end
end.
End ListTrace.
Module FiniteTraceOp
(Ty : Typ) (State : HasEqb Ty)
(Import Transitions : TransitionSystem Ty State).
Include ListTrace Ty State Transitions.
Include TraceSet Ty State Transitions.
Definition begin_initial (t : trace) : Prop :=
match t with
| [] ⇒ False
| x::_ ⇒ Transitions.initial x
end.
Definition end_final (t : trace) : Prop :=
match last_error_list t with
| NoneSeq | NonfiniteSeq ⇒ False
| SomeSeq x ⇒ Transitions.final x
end.
End FiniteTraceOp.
Now, we can define prefix trace semantics.
Module PrefixTrace
(Ty : Typ) (State : HasEqb Ty)
(Import Transitions : TransitionSystem Ty State)
<: TraceSemanticSig Ty State Transitions.
Include FiniteTraceOp Ty State Transitions.
(Ty : Typ) (State : HasEqb Ty)
(Import Transitions : TransitionSystem Ty State)
<: TraceSemanticSig Ty State Transitions.
Include FiniteTraceOp Ty State Transitions.
Basically, we define this semantics as the valid finite traces begining in an initial state.
Definition t := trace → Prop.
Definition r : Relation t := Included trace.
Instance t_pre_order : PreOrder r.
Admitted.
Instance t_partial_order : PartialOrder eq r.
Admitted.
Definition semantics : t :=
fun (t : trace) ⇒ Valid t ∧ begin_initial t.
Definition r : Relation t := Included trace.
Instance t_pre_order : PreOrder r.
Admitted.
Instance t_partial_order : PartialOrder eq r.
Admitted.
Definition semantics : t :=
fun (t : trace) ⇒ Valid t ∧ begin_initial t.
As we saw, we want to express this semantics in a least fixpoint form.
This would allow us to use theorems from order theory.
LFP semantics and "intuitive" semantics are the same.
We can define prefix of a trace.
And the closure of a set of traces by prefix.
Definition prefix_closure (T : trace → Prop) : trace → Prop :=
fun u ⇒ ∃ t : trace, T t ∧ is_prefix u t.
fun u ⇒ ∃ t : trace, T t ∧ is_prefix u t.
Then we can show that our semantic is closed by prefix.
This closeness is one of the main limitation of this semantics :
It means that one can't prove liveness properties such as termination with it.
For this, we will need maximal trace semantics.
In addition, as we saw, the use of set of traces instead of set of set of traces is also limiting :
we can't prove that our executions are deterministic for instance.
Forward Reachability Semantics
Module ForwardReachability
(Ty : Typ) (State : HasEqb Ty)
(Import Transitions : TransitionSystem Ty State)
<: TraceSemanticSig Ty State Transitions.
(Ty : Typ) (State : HasEqb Ty)
(Import Transitions : TransitionSystem Ty State)
<: TraceSemanticSig Ty State Transitions.
We need to construct traces in exactly the same way
as for prefix trace semantics.
We need them to define the intuitive semantics,
but they won't be needed anymore in the fixpoint formulation.
We define forward reachability semantics as the states reachable from initials states of the transition system,
in respect with transitions of the system.
Definition t := state → Prop.
Definition r : Relation t := Included state.
Instance t_pre_order : PreOrder r.
Admitted.
Instance t_partial_order : PartialOrder eq r.
Admitted.
Definition semantics : t :=
fun (s : state) ⇒ ∃ t,
Valid t ∧ begin_initial t ∧ last_error_list t = SomeSeq s.
Definition r : Relation t := Included state.
Instance t_pre_order : PreOrder r.
Admitted.
Instance t_partial_order : PartialOrder eq r.
Admitted.
Definition semantics : t :=
fun (s : state) ⇒ ∃ t,
Valid t ∧ begin_initial t ∧ last_error_list t = SomeSeq s.
Once again, we can express semantics in a least fixpoint form.
But to do so, we first need to define a "post" function.
That is, a function which, given a set of states,
return the following states.
Definition post (S : t) : t :=
fun s' : state ⇒
∃ s : state, S s ∧ transition s s'.
Definition F (T : t) : t :=
union Transitions.initial (post T).
Theorem lfp_semantics :
∀ lfp, LFP' F lfp ↔ semantics = lfp.
End ForwardReachability.
fun s' : state ⇒
∃ s : state, S s ∧ transition s s'.
Definition F (T : t) : t :=
union Transitions.initial (post T).
Theorem lfp_semantics :
∀ lfp, LFP' F lfp ↔ semantics = lfp.
End ForwardReachability.
Link between prefix traces and forward reachability
Module GalloisEmbeddingPrefixForward
(Ty : Typ) (State : HasEqb Ty)
(Import Transitions : TransitionSystem Ty State).
Module FR := ForwardReachability Ty State Transitions.
Module PT := PrefixTrace Ty State Transitions.
(Ty : Typ) (State : HasEqb Ty)
(Import Transitions : TransitionSystem Ty State).
Module FR := ForwardReachability Ty State Transitions.
Module PT := PrefixTrace Ty State Transitions.
We import both module because we want to use gamma connection notations easily.
TODO it gives a warning, put notation in a separate module.
We abstract simply by taking the last state of the traces.
And we concretize by taking all the traces ending in forward reachability semantics.
Definition gamma := fun S ⇒
(fun t : trace ⇒
match last_error_list t with
| SomeSeq s ⇒ S s
| _ ⇒ False end).
Theorem link_prefix_forward :
alpha a<<->c gamma.
End GalloisEmbeddingPrefixForward.
(fun t : trace ⇒
match last_error_list t with
| SomeSeq s ⇒ S s
| _ ⇒ False end).
Theorem link_prefix_forward :
alpha a<<->c gamma.
End GalloisEmbeddingPrefixForward.
Suffix trace semantics
Module SuffixTrace
(Ty : Typ) (State : HasEqb Ty)
(Import Transitions : TransitionSystem Ty State)
<: TraceSemanticSig Ty State Transitions.
Include FiniteTraceOp Ty State Transitions.
(Ty : Typ) (State : HasEqb Ty)
(Import Transitions : TransitionSystem Ty State)
<: TraceSemanticSig Ty State Transitions.
Include FiniteTraceOp Ty State Transitions.
Basically, we define this semantics as the valid finite traces ending in a final state.
Definition t := trace → Prop.
Definition r : Relation t := Included trace.
Instance t_pre_order : PreOrder r.
Admitted.
Instance t_partial_order : PartialOrder eq r.
Admitted.
Definition semantics : t :=
fun (t : trace) ⇒ Valid t ∧ end_final t.
Definition r : Relation t := Included trace.
Instance t_pre_order : PreOrder r.
Admitted.
Instance t_partial_order : PartialOrder eq r.
Admitted.
Definition semantics : t :=
fun (t : trace) ⇒ Valid t ∧ end_final t.
As we saw, we want to express this semantics in a least fixpoint form.
This will allow us to use theorems from order theory.
LFP semantics and this semantics form are the same.
We can define suffix of a trace.
And the closure of a set of traces by suffix.
Definition suffix_closure (T : trace → Prop) : trace → Prop :=
fun u ⇒ ∃ t : trace, T t ∧ is_suffix u t.
fun u ⇒ ∃ t : trace, T t ∧ is_suffix u t.
Then we can show that our semantic is closed by suffix.
Backward State Co-Reachability Semantics
Module BackwardCoReachability
(Ty : Typ) (State : HasEqb Ty)
(Import Transitions : TransitionSystem Ty State)
<: TraceSemanticSig Ty State Transitions.
Include FiniteTraceOp Ty State Transitions.
(Ty : Typ) (State : HasEqb Ty)
(Import Transitions : TransitionSystem Ty State)
<: TraceSemanticSig Ty State Transitions.
Include FiniteTraceOp Ty State Transitions.
We define backward co reachability semantics as the states reachable from final states of the transition system,
in respect with the reverse transitions of the system.
Definition t := state → Prop.
Definition r : Relation t := Included state.
Instance t_pre_order : PreOrder r.
Admitted.
Instance t_partial_order : PartialOrder eq r.
Admitted.
Definition semantics : t :=
fun (s : state) ⇒ ∃ t,
Valid t ∧ end_final t ∧ List.hd_error t = Some s.
Definition r : Relation t := Included state.
Instance t_pre_order : PreOrder r.
Admitted.
Instance t_partial_order : PartialOrder eq r.
Admitted.
Definition semantics : t :=
fun (s : state) ⇒ ∃ t,
Valid t ∧ end_final t ∧ List.hd_error t = Some s.
Here, instead of a "post" function, we need a "pre" function.
That is, a function which, given a set of states,
return the preceding states.
If we see post as a function of the transitions, pre can be seen as
post of the reverse transition relation.
Hence, compared to the post definition, we just swap s and s'.
Definition pre (S : t) : t :=
fun s : state ⇒
∃ s' : state, S s ∧ transition s s'.
Definition F (T : t) : t :=
union Transitions.final (pre T).
Theorem lfp_semantics :
∀ lfp, LFP' F lfp ↔ semantics = lfp.
End BackwardCoReachability.
fun s : state ⇒
∃ s' : state, S s ∧ transition s s'.
Definition F (T : t) : t :=
union Transitions.final (pre T).
Theorem lfp_semantics :
∀ lfp, LFP' F lfp ↔ semantics = lfp.
End BackwardCoReachability.
Link between suffix traces and backward co reachability
Module GalloisEmbeddingSuffixBackward
(Ty : Typ) (State : HasEqb Ty)
(Import Transitions : TransitionSystem Ty State).
Module BCR := BackwardCoReachability Ty State Transitions.
Module ST := SuffixTrace Ty State Transitions.
Import BCR.
Import ST.
(Ty : Typ) (State : HasEqb Ty)
(Import Transitions : TransitionSystem Ty State).
Module BCR := BackwardCoReachability Ty State Transitions.
Module ST := SuffixTrace Ty State Transitions.
Import BCR.
Import ST.
We abstract simply by taking the fist state of the traces.
Definition alpha := fun T ⇒
(fun s : state ⇒
∃ t, T t ∧ match t with [] ⇒ False | x::_ ⇒ x = s end).
(fun s : state ⇒
∃ t, T t ∧ match t with [] ⇒ False | x::_ ⇒ x = s end).
And we concretize by taking all the traces beginning in backward co reachability semantics.
Definition gamma := fun S ⇒
(fun t : trace ⇒
match t with
| s::_ ⇒ S s
| _ ⇒ False end).
Theorem link_suffix_backward :
alpha a<<->c gamma.
End GalloisEmbeddingSuffixBackward.
(fun t : trace ⇒
match t with
| s::_ ⇒ S s
| _ ⇒ False end).
Theorem link_suffix_backward :
alpha a<<->c gamma.
End GalloisEmbeddingSuffixBackward.
Partial finite trace semantics
Module PartialFiniteTrace
(Ty : Typ) (State : HasEqb Ty)
(Import Transitions : TransitionSystem Ty State)
<: TraceSemanticSig Ty State Transitions.
Include FiniteTraceOp Ty State Transitions.
(Ty : Typ) (State : HasEqb Ty)
(Import Transitions : TransitionSystem Ty State)
<: TraceSemanticSig Ty State Transitions.
Include FiniteTraceOp Ty State Transitions.
Basically, we define this semantics as the valid finite traces.
Definition t := trace → Prop.
Parameter r : Relation t.
Instance t_pre_order : PreOrder r.
Admitted.
Instance t_partial_order : PartialOrder eq r.
Admitted.
Definition semantics : t :=
fun (t : trace) ⇒ Valid t.
Parameter r : Relation t.
Instance t_pre_order : PreOrder r.
Admitted.
Instance t_partial_order : PartialOrder eq r.
Admitted.
Definition semantics : t :=
fun (t : trace) ⇒ Valid t.
As we saw, we want to express this semantics in a least fixpoint form.
This will allow us to use theorems from order theory.
LFP semantics and this semantics form are the same.
Link between partial finite traces and prefix traces
Module GalloisEmbeddingPartialPrefix
(Ty : Typ) (State : HasEqb Ty)
(Import Transitions : TransitionSystem Ty State).
Module PT := PrefixTrace Ty State Transitions.
Module PFT := PartialFiniteTrace Ty State Transitions.
Import PT.
Import PFT.
(Ty : Typ) (State : HasEqb Ty)
(Import Transitions : TransitionSystem Ty State).
Module PT := PrefixTrace Ty State Transitions.
Module PFT := PartialFiniteTrace Ty State Transitions.
Import PT.
Import PFT.
For abstracting into prefix traces, we keep only traces beginning in an initial state.
For concretizing into partial traces, we add all traces not beginning in an initial state.
Definition gamma := fun T ⇒
union T
(fun t : trace ⇒
match t with
| x::_ ⇒ ¬ initial x
| _ ⇒ True end).
Theorem link_partial_prefix :
alpha a↔c gamma.
End GalloisEmbeddingPartialPrefix.
union T
(fun t : trace ⇒
match t with
| x::_ ⇒ ¬ initial x
| _ ⇒ True end).
Theorem link_partial_prefix :
alpha a↔c gamma.
End GalloisEmbeddingPartialPrefix.
Link between partial finite traces and suffix traces
Module GalloisEmbeddingPartialSuffix
(Ty : Typ) (State : HasEqb Ty)
(Import Transitions : TransitionSystem Ty State).
Module ST := SuffixTrace Ty State Transitions.
Module PFT := PartialFiniteTrace Ty State Transitions.
Import ST.
Import PFT.
(Ty : Typ) (State : HasEqb Ty)
(Import Transitions : TransitionSystem Ty State).
Module ST := SuffixTrace Ty State Transitions.
Module PFT := PartialFiniteTrace Ty State Transitions.
Import ST.
Import PFT.
For abstracting into suffix traces, this time we keep only traces ending in final state.
Definition alpha := fun T ⇒
(fun t ⇒
T t ∧ match last_error_list t with SomeSeq s ⇒ final s | _ ⇒ False end).
(fun t ⇒
T t ∧ match last_error_list t with SomeSeq s ⇒ final s | _ ⇒ False end).
For concretizing into partial traces, we add all traces not ending in a final state.
Definition gamma := fun T ⇒
union T (fun t : trace ⇒
match last_error_list t with
| SomeSeq s ⇒ ¬ final s
| _ ⇒ True end).
Theorem link_partial_suffix :
alpha a↔c gamma.
End GalloisEmbeddingPartialSuffix.
union T (fun t : trace ⇒
match last_error_list t with
| SomeSeq s ⇒ ¬ final s
| _ ⇒ True end).
Theorem link_partial_suffix :
alpha a↔c gamma.
End GalloisEmbeddingPartialSuffix.
Partial Trace Semantics
We can generalize these finite traces as finite/infinite traces. We will see that one can see finite semantics as abstraction of finite/infinite one.
Module PartialTrace
(Ty : Typ) (State : HasEqb Ty)
(Import Transitions : TransitionSystem Ty State)
<: TraceSig Ty State Transitions.
(Ty : Typ) (State : HasEqb Ty)
(Import Transitions : TransitionSystem Ty State)
<: TraceSig Ty State Transitions.
In this semantic, we will need to use sequences of states (that is,
finite or infinite sequences, which we represent here as list resp.
streams here).
Hence, we need to change a bit functions operating on traces.
TODO : use ordinals
Definition length (t : trace) : nat :=
match t with
| Finite t ⇒ List.length t
| Infinite t ⇒ 0
end.
Definition cons := @ConsSeq state.
Definition epsilon : trace := Finite nil.
Definition Sigma (t : trace) : Prop := length t = 1.
Definition to_traces (S : state → Prop) : trace → Prop :=
fun t ⇒ match t with Finite [x] ⇒ S x | _ ⇒ False end.
Definition trace_transitions : trace → Prop :=
fun t ⇒ match t with Finite [x; y] ⇒ transition x y | _ ⇒ False end.
Definition concat (t1 t2 : trace) : trace :=
match t1, t2 with
| Finite l1, Finite l2 ⇒ Finite (l1 ++ l2)
| Finite l, Infinite s ⇒ Infinite (stream_concat l s)
| Infinite s, _ ⇒ Infinite s
end.
Definition junction (t1 t2 : trace) : trace :=
match t2 with
| Finite [] ⇒ Finite []
| Finite (x::t2s) ⇒
match last_error t1 with
| NoneSeq ⇒ Finite []
| SomeSeq y ⇒ if State.eqb x y then concat t1 (Finite t2s)
else Finite []
| NonfiniteSeq ⇒ t1
end
| Infinite (Cons x t2s) ⇒
match last_error t1 with
| NoneSeq ⇒ Finite []
| SomeSeq y ⇒ if State.eqb x y then concat t1 (Infinite t2s)
else Finite []
| NonfiniteSeq ⇒ t1
end
end.
match t with
| Finite t ⇒ List.length t
| Infinite t ⇒ 0
end.
Definition cons := @ConsSeq state.
Definition epsilon : trace := Finite nil.
Definition Sigma (t : trace) : Prop := length t = 1.
Definition to_traces (S : state → Prop) : trace → Prop :=
fun t ⇒ match t with Finite [x] ⇒ S x | _ ⇒ False end.
Definition trace_transitions : trace → Prop :=
fun t ⇒ match t with Finite [x; y] ⇒ transition x y | _ ⇒ False end.
Definition concat (t1 t2 : trace) : trace :=
match t1, t2 with
| Finite l1, Finite l2 ⇒ Finite (l1 ++ l2)
| Finite l, Infinite s ⇒ Infinite (stream_concat l s)
| Infinite s, _ ⇒ Infinite s
end.
Definition junction (t1 t2 : trace) : trace :=
match t2 with
| Finite [] ⇒ Finite []
| Finite (x::t2s) ⇒
match last_error t1 with
| NoneSeq ⇒ Finite []
| SomeSeq y ⇒ if State.eqb x y then concat t1 (Finite t2s)
else Finite []
| NonfiniteSeq ⇒ t1
end
| Infinite (Cons x t2s) ⇒
match last_error t1 with
| NoneSeq ⇒ Finite []
| SomeSeq y ⇒ if State.eqb x y then concat t1 (Infinite t2s)
else Finite []
| NonfiniteSeq ⇒ t1
end
end.
For this semantics, inclusion no longer suffices as a partial order.
Indeed, one can see this semantics as the union of finite and infinite traces.
For finite traces, everything works as for finite partial traces,
and the inclusion order works well.
For infinite traces however,
one can see the semantics as a greatest fixpoint on inclusion.
To go back to least fixpoint, one has to use the corresponding co order.
The nice thing is that these two orders operate on two conceptually
different sets.
Thus we can combine them into one order on finite/infinite trace,
which will give us back our least fixpoint semantics.
Parameter r : Relation (trace → Prop).
Instance set_traces_pre_order : PreOrder r.
Admitted.
Instance set_traces_partial_order : PartialOrder eq r.
Admitted.
Include TraceSet Ty State Transitions.
End PartialTrace.
Instance set_traces_pre_order : PreOrder r.
Admitted.
Instance set_traces_partial_order : PartialOrder eq r.
Admitted.
Include TraceSet Ty State Transitions.
End PartialTrace.
Maximal Trace Semantics
Module MaximalTrace
(Ty : Typ) (State : HasEqb Ty)
(Import Transitions : TransitionSystem Ty State)
<: TraceSig Ty State Transitions.
Definition trace : Type := Sequence state.
Definition length (t : trace) : nat :=
match t with
| Finite t ⇒ List.length t
| Infinite t ⇒ 0
end.
Definition cons := @ConsSeq state.
Definition epsilon : trace := Finite nil.
Definition Sigma (t : trace) : Prop := length t = 1.
Definition to_traces (S : state → Prop) : trace → Prop :=
fun t ⇒ match t with Finite [x] ⇒ S x | _ ⇒ False end.
Definition trace_transitions : trace → Prop :=
fun t ⇒ match t with Finite [x; y] ⇒ transition x y | _ ⇒ False end.
Definition concat (t1 t2 : trace) : trace :=
match t1, t2 with
| Finite l1, Finite l2 ⇒ Finite (l1 ++ l2)
| Finite l, Infinite s ⇒ Infinite (stream_concat l s)
| Infinite s, _ ⇒ Infinite s
end.
Definition junction (t1 t2 : trace) : trace :=
match t2 with
| Finite [] ⇒ Finite []
| Finite (x::t2s) ⇒
match last_error t1 with
| NoneSeq ⇒ Finite []
| SomeSeq y ⇒ if State.eqb x y then concat t1 (Finite t2s)
else Finite []
| NonfiniteSeq ⇒ t1
end
| Infinite (Cons x t2s) ⇒
match last_error t1 with
| NoneSeq ⇒ Finite []
| SomeSeq y ⇒ if State.eqb x y then concat t1 (Infinite t2s)
else Finite []
| NonfiniteSeq ⇒ t1
end
end.
Parameter r : Relation (trace → Prop).
Instance set_traces_pre_order : PreOrder r.
Admitted.
Instance set_traces_partial_order : PartialOrder eq r.
Admitted.
Include TraceSet Ty State Transitions.
End MaximalTrace.
(Ty : Typ) (State : HasEqb Ty)
(Import Transitions : TransitionSystem Ty State)
<: TraceSig Ty State Transitions.
Definition trace : Type := Sequence state.
Definition length (t : trace) : nat :=
match t with
| Finite t ⇒ List.length t
| Infinite t ⇒ 0
end.
Definition cons := @ConsSeq state.
Definition epsilon : trace := Finite nil.
Definition Sigma (t : trace) : Prop := length t = 1.
Definition to_traces (S : state → Prop) : trace → Prop :=
fun t ⇒ match t with Finite [x] ⇒ S x | _ ⇒ False end.
Definition trace_transitions : trace → Prop :=
fun t ⇒ match t with Finite [x; y] ⇒ transition x y | _ ⇒ False end.
Definition concat (t1 t2 : trace) : trace :=
match t1, t2 with
| Finite l1, Finite l2 ⇒ Finite (l1 ++ l2)
| Finite l, Infinite s ⇒ Infinite (stream_concat l s)
| Infinite s, _ ⇒ Infinite s
end.
Definition junction (t1 t2 : trace) : trace :=
match t2 with
| Finite [] ⇒ Finite []
| Finite (x::t2s) ⇒
match last_error t1 with
| NoneSeq ⇒ Finite []
| SomeSeq y ⇒ if State.eqb x y then concat t1 (Finite t2s)
else Finite []
| NonfiniteSeq ⇒ t1
end
| Infinite (Cons x t2s) ⇒
match last_error t1 with
| NoneSeq ⇒ Finite []
| SomeSeq y ⇒ if State.eqb x y then concat t1 (Infinite t2s)
else Finite []
| NonfiniteSeq ⇒ t1
end
end.
Parameter r : Relation (trace → Prop).
Instance set_traces_pre_order : PreOrder r.
Admitted.
Instance set_traces_partial_order : PartialOrder eq r.
Admitted.
Include TraceSet Ty State Transitions.
End MaximalTrace.