forked from uds-psl/coq-library-undecidability
-
Notifications
You must be signed in to change notification settings - Fork 0
/
PCP.v
91 lines (68 loc) · 2.68 KB
/
PCP.v
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
Require Import Undecidability.Shared.Prelim.
(** ** Traditional Definition *)
Definition symbol := nat.
Definition string X := list X.
Definition card X : Type := string X * string X.
Definition stack X := list (card X).
Definition SRS := stack nat.
Definition BSRS := stack bool.
Notation "x / y" := (x,y).
Fixpoint tau1 (X : Type) (A : stack X) : string X :=
match A with
| [] => []
| (x / y) :: A => x ++ tau1 A
end.
Fixpoint tau2 X (A : stack X) : string X :=
match A with
| [] => []
| (x / y) :: A => y ++ tau2 A
end.
Definition PCP P := exists A : SRS, A <<= P /\ A <> [] /\ tau1 A = tau2 A.
(** ** Inductive Definition *)
Inductive derivable (X : Type) (R : stack X) : string X -> string X -> Prop :=
| der_sing x y : x/y el R -> derivable R x y
| der_cons x y u v : x/y el R -> derivable R u v -> derivable R (x ++ u) (y ++ v).
Lemma derivable_BPCP X (P : stack X) u v :
derivable P u v -> exists A, A <<= P /\ A <> nil /\ tau1 A = u /\ tau2 A = v.
Proof.
induction 1 as [ | ? ? ? ? ? ? (A & ? & ? & ? & ?)].
- exists [x/y]. repeat split; cbn; simpl_list; eauto. congruence.
- subst. exists (x/y :: A). repeat split. eauto. congruence.
Qed.
Lemma BPCP_derivable X (P : stack X) u v : (exists A, A <<= P /\ A <> nil /\ tau1 A = u /\ tau2 A = v) -> derivable P u v.
Proof.
intros (A & ? & ? & ? & ?). subst.
revert H. pattern A. revert A H0. eapply list_ind_ne; cbn; intros; destruct x as (x,y).
- simpl_list. eauto using derivable.
- eauto using derivable.
Qed.
(** ** Binary PCP *)
Definition BPCP P := exists A : BSRS, A <<= P /\ A <> [] /\ tau1 A = tau2 A.
(** ** Binary Post correspondence problem with indices *)
Section itau.
Variable P : BSRS.
Fixpoint itau1 (A : list nat) : string bool :=
match A with
| [] => []
| i :: A => fst (nth i P ( [] / [] )) ++ itau1 A
end.
Fixpoint itau2 (A : list nat) : string bool :=
match A with
| [] => []
| i :: A => snd (nth i P ( [] / [] )) ++ itau2 A
end.
Fact itau1_app A B : itau1 (A++B) = itau1 A ++ itau1 B.
Proof. induction A; simpl; auto; rewrite app_ass; simpl; f_equal; auto. Qed.
Fact itau2_app A B : itau2 (A++B) = itau2 A ++ itau2 B.
Proof. induction A; simpl; auto; rewrite app_ass; simpl; f_equal; auto. Qed.
End itau.
Definition iBPCP (P : BSRS) :=
exists A : list nat, (forall a, a el A -> a < length P) /\ A <> [] /\ itau1 P A = itau2 P A.
Inductive BPCP' P : Prop := cBPCP u (_ : @derivable bool P u u).
Hint Constructors BPCP'.
Lemma BPCP_BPCP' P : BPCP P <-> BPCP' P.
Proof.
split.
- intros (? & ? & ? & ?). econstructor. eapply BPCP_derivable. eauto.
- intros []. edestruct (derivable_BPCP H) as (? & ? & ? & ? & ?). subst. exists x. eauto.
Qed.