     var elements: [Generator : CoeffRing] { get }
     static func wrap(_ a: Generator) -> Self
     static func combine<n>(basis: [Generator], vector: ColVector<n, CoeffRing>) -> Self
-    func factorize(by: [Generator]) -> [CoeffRing]
+    func factorize(by: [Generator]) -> DVector<CoeffRing>
 }
 
 public struct FreeModule<A: FreeModuleGenerator, R: Ring>: FreeModuleType {

    public func asMatrix(from: [X.Generator], to: [Y.Generator]) -> DMatrix<CoeffRing> {
        let comps = from.enumerated().flatMap { (j, a) -> [MatrixComponent<CoeffRing>] in
            let w = self.applied(to: .wrap(a))
            return w.factorize(by: to).enumerated().compactMap { (i, a) in
                a != .zero ? (i, j, a) : nil
            }
        }
        return DMatrix(size: (to.count, from.count), components: comps, zerosExcluded: true)
    }

        return elements.keys.sorted().toArray()
    }
    
    public func factorize(by basis: [A]) -> DVector<R> {
        let indexer = basis.indexer()
        let comps = elements.compactMap { (a, r) -> MatrixComponent<R>? in
            indexer(a).map{ i in (i, 0, r) }
        }
        return DVector<R>(size: (basis.count, 1), components: comps, zerosExcluded: true)
    }
    
    public var isSingle: Bool {
