Definition nthCP {T:Type} {m:nat} (n : nat) (cp : cartesianPower T m) (Default : T) := nth (n-1) (CPToList cp) Default.

(* Specifications: *)
Lemma CPToListOK {T:Type} {n:nat} : forall (cp : cartesianPower T (S (S n))), CPToList cp = cons (headCP cp) (CPToList (tailCP cp)).
Lemma CPLHdTlOK {T:Type} {n:nat} : forall (cp : cartesianPower T (S (S n))), CPToList cp = ((headCP cp) :: nil) ++ CPToList (tailCP cp).
Lemma consTailOK {T:Type} {n:nat} : forall (cp : cartesianPower T (S n)) t, CPToList (consTailCP cp t) = CPToList cp ++ t :: nil.
Lemma InNth {T:Type} {n:nat} : forall (cp : cartesianPower T n) (t Default : T), InCP t cp -> (exists id, id >= 1 /\ id <= n /\ t = nthCP id cp Default).
Lemma nthFirst {T:Type} {n:nat} : forall (cp : cartesianPower T (S n)) (t Default : T), t = nthCP 1 cp Default -> t = headCP cp.
Lemma lengthOfCPToList {T:Type} {n:nat} : forall (cp : cartesianPower T n), n = length (CPToList cp).
Lemma lastTailOK {T:Type} {n:nat} : forall (cp : cartesianPower T (S (S n))), lastCP cp = lastCP (tailCP cp).
Lemma consTailCPLast {T:Type} {n:nat} : forall (cp : cartesianPower T (S n)) t, lastCP (consTailCP cp t) = t.
Lemma nthLast {T:Type} {n:nat} : forall (cp : cartesianPower T (S n)) (Default : T), lastCP cp = nthCP (S n) cp Default.
Lemma nthCircPerm1 {T:Type} {n:nat} : forall (cp : cartesianPower T (S (S n))) (t Default : T), t = nthCP 1 cp Default -> t = nthCP (S (S n)) (consTailCP (tailCP cp) (headCP cp)) Default.
Lemma nthCircPerm1Eq {T:Type} {n:nat} : forall (cp : cartesianPower T (S (S n))) (Default : T), nthCP 1 cp Default = nthCP (S (S n)) (consTailCP (tailCP cp) (headCP cp)) Default.
Lemma nthCircPerm2 {T:Type} {n:nat} : forall (cp : cartesianPower T (S (S n))) (t Default : T) id, t = nthCP (S (S id)) cp Default -> id <= n -> t = nthCP (S id) (consTailCP (tailCP cp) (headCP cp)) Default.
Lemma nthCircPerm2Eq {T:Type} {n:nat} : forall (cp : cartesianPower T (S (S n))) (Default : T) id, id <= n -> nthCP (S (S id)) cp Default = nthCP (S id) (consTailCP (tailCP cp) (headCP cp)) Default.
Lemma nthCPTlOK {T:Type} {m:nat} : forall (cp : cartesianPower T (S (S m))) (Default : T) n, nthCP (S n) (tailCP cp) Default = nthCP (S (S n)) cp Default.
Lemma nthEqOK {T:Type} {m:nat} : forall (cp1 cp2 : cartesianPower T (S m)) (Default : T), (forall n, nthCP n cp1 Default = nthCP n cp2 Default) -> cp1 = cp2.
Lemma consTailPerm {T:Type} {n:nat} : forall (cp : cartesianPower T (S (S n))), Permutation.Permutation (CPToList cp) (CPToList (consTailCP (tailCP cp) (headCP cp))).