In this page if u is a set of vectors then span(u) is the set of all linear combinations of vectors from u. u ⊆ span(u) and span(u) is always a subspace. u is called a spanning set for the sub-space span(u).

Orthogonal Space
(This is a newer and better method.)

We presume here that our space has an inner product: <x, y>. This is unnecessary but the code below requires it. The dual space idea allows a concept of orthogonal space without an inner product. Given a subspace X, the set of all vectors that are orthogonal to each member of X, is another subspace X. (X) = X.

Given a spanning set u for X we form a matrix M whose columns are those vectors, we compute a spanning set for X by adjoining an identity matrix to M to form a composite matrix N, finding the necessary subset of N (minspan) and then applying the rational Gram Schmidt process. The vectors of N span the entire space for the vectors in the identity matrix are already a basis for the entire space. The program minspan deletes dependent members.

(define (iden n)(if (zero? n) '() (if (= n 1) '((1)) (let ((li (iden (- n 1))))
  (cons (cons 1 (cons 0 (cdar li))) (map (lambda (x) (cons 0 x)) li))))))
(define (transpose x) (if (null? (car x)) '()
   (cons (map car x) (transpose (map cdr x)))))

(define (perp u) (let* ((n (length (car u)))(M (append u (iden n)))
   (Mr (minspan M))) (let del ((x (rgs Mr))(n (length u)))
        (if (zero? n) x (del (cdr x)(- n 1))))))

perp is wrong for
((1 0 0 0 0 0 0 0 0 0) (0 0 0 0 0 0 1 0 0 0) (0 0 1 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0 0 1) (0 0 1 0 0 0 0 0 0 0) (0 0 0 0 0 1 0 0 0 0)).
Mr is
((1 0 0 0 0 0 0 0 0 0) (0 0 0 0 0 0 1 0 0 0) (0 0 1 0 0 0 0 0 0 0) (0 0 0 0 0 0 0 0 0 1) (0 0 0 0 0 1 0 0 0 0) (0 1 0 0 0 0 0 0 0 0) (0 0 0 1 0 0 0 0 0 0) (0 0 0 0 1 0 0 0 0 0) (0 0 0 0 0 0 0 1 0 0) (0 0 0 0 0 0 0 0 1 0)) Mr should include (0 1 0 0 0 0 0 0 0 0) but it does not. Perhaps it works when input vector set is independent.
perp cannot process the null list of vectors, for it cannot learn the dimensionality of the space.

Intersection of two Spaces

Given two subspaces of a vector space find their intersection. I assume that subspaces are identified by a finite set of spanning vectors, indeed a set of independent vectors. To find the intersection of two subspaces X and Y we use the relation that (X∩Y) = span(X ∪ Y).

(define (inter u v)(let* ((U (perp u))(V (perp v))(UV (minspan (append U V))))
   (perp UV)))

(inter '((1 1 0 0)(1 -1 0 0)) '((1 0 1 0)(1 0 -1 0))) ;=> ((1 0 0 0))