SkullCoder

Coq NP C-3

May 14th, 2019
194
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Variable X:Type. (*Prozesses*)
  2. Variable A:Type. (*Transitions*)
  3.  
  4. Definition transition := X -> A -> X -> Prop.
  5.  
  6.  
  7. Fixpoint tvtrace (f:transition) (p:X) xs tv :=
  8.   match xs with
  9.     nil => forall a, In a tv <-> exists q, f p a q
  10.   | (a::xr) => exists q, f p a q /\ tvtrace f q xr tv
  11.   end.
  12.  
  13. Definition tveq f p q := forall xs tv, tvtrace f p xs tv <-> tvtrace f q xs tv.
  14.  
  15. Lemma tvrefl: forall f s, tveq f s s.
  16. Proof.
  17.   intros f s xs tv. tauto.
  18. Qed.
  19.  
  20. Lemma tvsym: forall f s t, tveq f s t -> tveq f t s.
  21. Proof.
  22.   intros f s t H xs tv.
  23.   specialize (H xs tv).
  24.   tauto.
  25. Qed.
  26.  
  27. Lemma tvtrans: forall f s t u, tveq f s t -> tveq f t u -> tveq f s u.
  28. Proof.
  29.   intros f s t u H F xs tv.
  30.   specialize (H xs tv).
  31.   specialize (F xs tv).
  32.   tauto.
  33. Qed.
  34.  
  35. Fixpoint termtrace (f:transition) (p:X) xs :=
  36.   match xs with
  37.     nil => ~ exists a q, f p a q
  38.   | (a::xr) => exists q, f p a q /\ termtrace f q xr
  39.   end.
  40.  
  41. Definition ttraceeq f p q := forall xs, termtrace f p xs <-> termtrace f q xs.
  42.  
  43. Lemma tvToTermTrace: forall f s xs, tvtrace f s xs nil <-> termtrace f s xs.
  44. Proof.
  45.   intros f s xs.
  46.   revert s.
  47.   induction xs.
  48.   - intros s. split.
  49.     + intros H. intros (a&q&G).
  50.       apply (H a). exists q. exact G.
  51.     + intros H x.
  52.       split.
  53.       * intros [].
  54.       * intros (q&F).
  55.         apply H. exists x. now exists q.
  56.   - intros s. split.
  57.     + intros (q&H1&H2).
  58.       cbn. exists q. split;trivial.
  59.       now apply IHxs.
  60.     + intros (q&H1&H2).
  61.       exists q. split.
  62.       * exact H1.
  63.       * now apply IHxs.
  64. Qed.
  65.  
  66.  
  67. Goal forall f s t, tveq f s t -> ttraceeq f s t.
  68. Proof.
  69.   intros f s t H xs.
  70.   specialize (H xs nil).
  71.   split;intros F;apply tvToTermTrace;apply H;apply tvToTermTrace;exact F.
  72. Qed.
  73.  
  74. Variable bisim : transition -> X -> X -> Prop.
  75. Variable bisimDef : forall f p q, bisim f p q <->
  76.   (forall a p2, f p a p2 -> exists q2, f q a q2 /\ bisim f p2 q2) /\
  77.   (forall a q2, f q a q2 -> exists p2, f p a p2 /\ bisim f p2 q2).
  78.  
  79. (* Alternatively, bisim can be defined over bisimulation for a set with this property
  80. and bisimiliarity as existence of the set and (p,q) in the set, this is equivalent
  81. but not as nice for proves *)
  82.  
  83. Goal forall f p q, bisim f p q -> tveq f p q.
  84. Proof.
  85.   intros f p q H t.
  86.   revert p q H.
  87.   induction t.
  88.   - intros p q H tv.
  89.     split;intros F.
  90.     + apply bisimDef in H as [H1 H2].
  91.       cbn in *.
  92.       intros a.
  93.       split.
  94.       * intros G.
  95.         specialize (F a).
  96.         destruct F as [F1 F2].
  97.         destruct (F1 G) as [p' F].
  98.        destruct (H1 a p' F) as [q' [H _]].
  99.        exists q'. exact H.
  100.       * specialize (F a). destruct F as [F1 F2].
  101.         intros [q2 F]. apply F2.
  102.         destruct (H2 a q2 F) as [p2 [H _]].
  103.         exists p2. exact H.
  104.     + apply bisimDef in H as [H1 H2].
  105.       cbn in *.
  106.       intros a.
  107.       split.
  108.       * intros G.
  109.         specialize (F a).
  110.         destruct F as [F1 F2].
  111.         destruct (F1 G) as [q' F].
  112.        destruct (H2 a q' F) as [p' [H _]].
  113.        exists p'. exact H.
  114.       * specialize (F a). destruct F as [F1 F2].
  115.         intros [p2 F]. apply F2.
  116.         destruct (H1 a p2 F) as [q2 [H _]].
  117.         exists q2. exact H.
  118.   - intros p q H tv. split.
  119.     + intros (p2&F1&F2);cbn.
  120.       apply bisimDef in H as [H1 H2].
  121.       specialize (H1 a p2 F1).
  122.       destruct H1 as (q2&H11&H12).
  123.       exists q2.
  124.       specialize (IHt p2 q2 H12).
  125.       split;try assumption.
  126.       now apply IHt.
  127.     + intros (q2&F1&F2);cbn.
  128.       apply bisimDef in H as [H1 H2].
  129.       specialize (H2 a q2 F1).
  130.       destruct H2 as (p2&H11&H12).
  131.       exists p2.
  132.       specialize (IHt p2 q2 H12).
  133.       split;try assumption.
  134.       now apply IHt.
  135. Qed.
  136.  
  137.  
  138.  
  139.  
  140.  
  141.  
  142. fun bisimulation where
  143. <bisimulation f b = (
  144.         (forall (p,q) : b. forall a p2. f p a p2 --> (exists q2. f q a q2 /\ (p2,q2) : b)) /\
  145.         (forall (p,q) : b. forall a q2. f q a q2 --> (exists p2. f p a p2 /\ (p2,q2) : b)))>
  146.  
  147. fun bisimilar where
  148. <bisimilar f p q = (exists b. bisimulation f b /\ (p,q) : b)>
  149.  
  150. fun isTermTrace where
  151. <isTermTrace f p []     = (not (exists a q. f p a q))> |
  152. <isTermTrace f p (a#xr) = (exists q. f p a q /\ isTermTrace f q xr)>
  153.  
  154. fun termEq where
  155. <termEq f p q = (forall xs. isTermTrace f p xs <--> isTermTrace f q xs)>
  156.  
  157. fun isTVTrace where
  158. <isTVTrace f p [] tv = (forall a. a : tv <--> (exists q. f p a q))> |
  159. <isTVTrace f p (a#xr) tv = (exists q. f p a q /\ isTVTrace f q xr tv)>
  160.  
  161. fun tvEq where
  162. <tvEq f p q = (forall xs tv. isTVTrace f p xs tv = isTVTrace f q xs tv)>
  163.  
  164. lemma tvrefl : <tvEq f s s>
  165.   by simp
  166.  
  167. lemma tvsym : <tvEq f s t = tvEq f t s>
  168.   by auto
  169.  
  170. lemma tvtrans : <tvEq f s t /\ tvEq f t u --> tvEq f s u>
  171.   by auto
  172.  
  173. lemma tvToTerm : <isTVTrace f p xs (set []) <--> isTermTrace f p xs>
  174.   apply (induction xs arbitrary: p)
  175.   by auto
  176.  
  177. lemma tvTrace : <tvEq f p q --> termEq f p q>
  178.   apply (auto simp add: tvToTerm)
  179.   apply (auto simp flip: tvToTerm)
  180.   done
Advertisement
Add Comment
Please, Sign In to add comment