(* Getting the canceling factor for fortho *)
Fixpoint fget n : (vect n) -> (vect n) -> K :=
match n return vect n -> vect n -> K with
| O => fun x1 x2 => 0%f
| S n1 =>
fun x1 x2 =>
let (x11, x12) := x1 in
let (x21, x22) := x2 in
if x12 ?= 0 then (('C[x11])^-1 * 'C[x21])%f else fget n1 x12 x22
end.

(* Specifications: *)
Lemma fget_scal n k x1 x2 : fget n x1 (k .* x2) = (k *  fget n x1 x2)%f.
Lemma fortho_fget n x1 x2 : x1 <> 0 -> hom n 1 x1 -> hom n 1 x2 ->
fortho n x1 (x2 + (-(1) * fget n x1 x2)%f .* x1).
Lemma joinl_addmult n (f: vect n -> vect n -> K) x l :
hom n 1 x -> (forall i, In i l -> hom n 1 i) ->
x ∨ joinl n l = x ∨ joinl n (map (fun y => (y + (f x y) .* x)) l).
Lemma mprod_hom n k l1 l2 :
(forall i, In i l2 -> hom n k i) -> hom n k (l1 *X* l2).