(* This function will be only call with first vector is hom 1 *)
Fixpoint factor n: (vect n) -> (vect n) -> vect n :=
match n return vect n -> vect n -> vect n with
| O => fun x1 x2 => (x2 * x1^-1)%f
| S n1 =>
fun x1 x2 =>
let (x11, x12) := x1 in
let (x21, x22) := x2 in
if x12 ?= 0 then
(* if x<> 0 then x11 <> 0 *)
((0: vect n1), ('C[x11]^-1).* x21: vect n1) else
let x32 := factor n1 x12 x22 in
(* We have x12 ∨ x32 = x22 *)
(* let x31 such that x12 /\ x31 = x11 ∨ x32 - x21                            *)
(* (x11,x12) /\ (x31,x32) = (x11 /\ x32 - x12 /\ x31, x12 /\ x32) (x21, x22) *)
(factor n1 x12 (add n1 (('C[x11]) .* x32: vect n1) (scal n1 (-(1))%f  x21: vect n1))
, x32)
end.

Lemma factor_hom0E n x1 x2 : x1 <> 0 ->  hom n 1 x1 -> hom n 0 x2 ->
factor n x1 (x1 ∨ x2) = x2.