(* Orthogonalité for factorisation, i.e. condition for factorisation to be idempotent *)
Fixpoint fortho n : (vect n) -> (vect n) -> bool :=
match n return vect n -> vect n -> bool with
| O => fun x1 x2 => false
| S n1 =>
fun x1 x2 =>
let (x11, x12) := x1 in
let (x21, x22) := x2 in
if x12 ?= 0 then x21 ?= 0 else  fortho n1 x12 x21 && fortho n1 x12 x22
end.

(* Specifications: *)
Lemma fortho0 n : 0 < n -> fortho n 0 0.
Lemma fortho_refl n x : fortho n x x -> x = 0.
Lemma forthok n k1 k2 (v: vect n) : v <> 0 -> hom n k1.+1 v -> fortho n v [k2].
Lemma fortho_scal n k v1 v2 : fortho n v1 v2 -> fortho n v1 (k .* v2).
Lemma fortho_add n v1 v2 v3 :
fortho n v1 v2 -> fortho n v1 v3 -> fortho n v1 (v2 + v3).
Lemma fortho_conj n b v1 v2 : fortho n v1 v2 -> fortho n v1 (v2 ^_ b).
Lemma fortho_join n v1 v2 v3 :
fortho n v1 v2 -> fortho n v1 v3 -> fortho n v1 (v2 ∨ v3).
Lemma fortho_joinl n k v l : v <> 0 -> hom n k.+1 v ->
(forall v1, In v1 l -> fortho n v v1) -> fortho n v (joinl n l).
(* Here we are *)
Lemma factor_ortho n x1 x2 : x1 <> 0 -> hom n 1 x1 ->
fortho n x1 x2 -> factor n x1 (x1 ∨ x2) = x2.