     
     public var cyclicDecomposition: [Permutation<n>] {
         return rawCyclicDecomposition.map{ Permutation<n>(cyclic: $0) }
+    }
+    
+    public func asMatrix() -> Matrix<IntegerNumber, n, n> {
+        return asMatrix(type: IntegerNumber.self)
+    }
+    
+    public func asMatrix<R: Ring>(type: R.Type) -> Matrix<R, n, n> {
+        let comps = (0 ..< degree).map{ i in (i, self[i], R.identity) }
+        return Matrix<R, n, n>(rows: degree, cols: degree, components: comps)
     }
     
     public static var allElements: [Permutation<n>] {

    }
    
    internal init(cyclic: [Int]) {
        self.init({ cyclic.index(of: $0).flatMap({ i in cyclic[(i + 1) % cyclic.count]}) ?? $0 })
    }
    
    public init(_ gen: ((Int) -> Int)) {
        let elements = (0 ..< n.intValue).map(gen)
        self.init(elements: elements)
    }
    

import Foundation

public struct Permutation<n: _Int>: Group, FiniteSetType {
    
    public let degree: Int
    fileprivate var elements: [Int] //
    
    private init(elements: [Int]) {
        assert(n.self == Dynamic.self || n.intValue == elements.count)
        let degree = elements.count
        
        assert({
            let set = Set(elements)
            let (num, min, max) = (degree, set.min(), set.max())
            return (set.count == num) && (min == 0) && (max == num - 1)
        }())
        
        self.degree = degree
        self.elements = elements
    }
    
    public init(_ dict: [Int: Int]) {
        self.init(generator: { dict[$0] ?? $0 })
    }
    
    public init(cyclic: Int...) {
