Section Peq.
Load "hCoefStructure".
Load "hOrderStructure".
Load "hOrder".
Definition size := length (A:=Term A n).
Definition sizel m := match m with
| (l1, l2) => size l1 + size l2
end.
Definition lessP m1 m2 := sizel m1 < sizel m2.
Hint Unfold lessP.
red in |- *.
cut (forall (m : nat) a, sizel a < m -> Acc lessP a).
intros H' a.
apply H' with (m := S (sizel a)); auto.
intros m; elim m; clear m.
intros a H; inversion H.
intros m H' a H'0.
apply Acc_intro.
intros y H'1; apply H'.
unfold lessP in H'1.
apply lt_le_trans with (sizel a); auto with arith.
Qed.
Hint Resolve wf_lessP.
intros n1 n2 l1 l2 H' H'0; rewrite H'0; rewrite H'; auto.
Qed.
Hint Resolve pX_inj.
intros a b p q H'; inversion H'; auto.
Qed.
Hint Unfold pX.
unfold pX, pX in |- *.
intros p q a b H'; inversion H'; auto.
Qed.
split; auto.
apply olistO.
red in |- *; simpl in |- *; auto.
Qed.
intros a H; split; simpl in |- *; auto.
red in |- *; simpl in |- *; apply Relation_Operators_compat.d_one.
Qed.
Hint Resolve canonicalp1 canonical0.
Inductive eqP : list (Term A n) -> list (Term A n) -> Prop :=
| eqP0 : eqP (pO A n) (pO A n)
| eqpP1 :
forall ma mb p q,
eqTerm (A:=A) eqA (n:=n) ma mb -> eqP p q -> eqP (pX ma p) (pX mb q).
Hint Resolve eqP0 eqpP1.
red in |- *.
intros x; elim x; auto.
intros a l H; change (eqP (pX a l) (pX a l)) in |- *; apply eqpP1; auto.
Qed.
red in |- *.
intros x y H'; elim H'; auto.
intros ma mb p q H H0 H1.
apply eqpP1; auto.
apply (eqTerm_sym _ _ _ _ _ _ _ _ _ cs n); auto.
Qed.
unfold pO in |- *; intros p H'; inversion H'; auto.
Qed.
unfold pO in |- *; intros p H'; inversion H'; auto.
Qed.
intros a b p q H'; simple inversion H'; auto.
unfold pO in H0; inversion H0.
rewrite (pX_invl ma a p0 p); auto; rewrite (pX_invl mb b q0 q); auto.
Qed.
intros a b p q H'; simple inversion H'; auto.
unfold pO in H0; inversion H0.
rewrite (pX_invr p0 p ma a); auto; rewrite (pX_invr q0 q mb b); auto.
Qed.
red in |- *.
intros x; elim x; auto.
intros y z H'; inversion_clear H'.
intros H'0; inversion_clear H'0; auto.
intros a l H' y z H'0; inversion_clear H'0.
intros H4; inversion_clear H4.
change (eqP (pX a l) (pX mb0 q0)) in |- *; apply eqpP1; eauto.
apply (eqTerm_trans _ _ _ _ _ _ _ _ _ cs n) with (y := mb); auto.
Qed.
Hint Resolve eqp_refl.
Let eqTerm_imp_eqT := eqTerm_imp_eqT A eqA n.
intros a p; case p; auto.
intros a0 l H'.
apply ltP_trans with (y := pX a (pO A n)); auto.
change (ltP (A:=A) (n:=n) ltM (pX a0 l) (pX a (pO A n))) in |- *.
apply ltP_hd; auto.
apply (canonical_pX_order A A0) with (eqA := eqA) (l := l); auto.
apply ltP_tl; auto.
change (ltP (A:=A) (n:=n) ltM (pO A n) (pX a0 l)) in |- *; apply ltPO.
Qed.
intros a b p q H'; inversion_clear H'; trivial.
Qed.

Theorem ltp_eqp_comp :
forall p q r s,
ltP (A:=A) (n:=n) ltM p q ->
canonical A0 eqA ltM p ->
canonical A0 eqA ltM q -> eqP p r -> eqP q s -> ltP (A:=A) (n:=n) ltM r s.