    -- Copyright (c) 2008-2015, David Amos. All rights reserved.

    module Math.Projects.ChevalleyGroup.Classical where

    import Prelude hiding ( (*>) )

    import Math.Algebra.Field.Base
    import Math.Algebra.Field.Extension hiding ( (<+>), (<*>) )
    import Math.Algebra.LinearAlgebra

    import Math.Algebra.Group.PermutationGroup
    import Math.Algebra.Group.SchreierSims as SS

    import Math.Combinatorics.FiniteGeometry

    numPtsAG :: b -> a -> a
    numPtsAG n :: b
    n q :: a
    q = a
    qa -> b -> a
    forall a b. (Num a, Integral b) => a -> b -> a
    ^b
    n

    numPtsPG :: b -> a -> a
    numPtsPG n :: b
    n q :: a
    q = (a
    qa -> b -> a
    forall a b. (Num a, Integral b) => a -> b -> a
    ^(b
    nb -> b -> b
    forall a. Num a => a -> a -> a
    +1)a -> a -> a
    forall a. Num a => a -> a -> a
    -1) a -> a -> a
    forall a. Integral a => a -> a -> a
    `div` (a
    qa -> a -> a
    forall a. Num a => a -> a -> a
    -1)

    -- LINEAR GROUPS

    -- |The special linear group SL(n,Fq), generated by elementary transvections, returned as matrices

    sl :: FiniteField k => Int -> [k] -> [[[k]]]
    sl :: Int -> [k] -> [[[k]]]
    sl n :: Int
    n fq :: [k]
    fq = [Int -> (Int, Int) -> k -> [[k]]
    forall b a.
    (Enum b, Eq b, Num b, Num a) =>
    b -> (b, b) -> a -> [[a]]
    elemTransvection Int
    n (Int
    r,Int
    c) k
    l | Int
    r <- [1..Int
    n], Int
    c <- [1..Int
    n], Int
    r Int -> Int -> Bool
    forall a. Eq a => a -> a -> Bool
    /= Int
    c, k
    l <- [k]
    fq']
        where fq' :: [k]
    fq' = k -> [k]
    forall fq. FiniteField fq => fq -> [fq]
    basisFq k
    forall a. HasCallStack => a
    undefined -- tail fq

        -- Carter p68 - x_r(t1) x_r(t2) == x_r(t1+t2) - this is true in general, not just in this case

    elemTransvection :: b -> (b, b) -> a -> [[a]]
    elemTransvection n :: b
    n (r :: b
    r,c :: b
    c) l :: a
    l = b -> (b -> b -> a) -> [[a]]
    forall t a. (Num t, Enum t) => t -> (t -> t -> a) -> [[a]]
    fMatrix b
    n (\i :: b
    i j :: b
    j -> if b
    i b -> b -> Bool
    forall a. Eq a => a -> a -> Bool
    == b
    j then 1 else if (b
    i,b
    j) (b, b) -> (b, b) -> Bool
    forall a. Eq a => a -> a -> Bool
    == (b
    r,b
    c) then a
    l else 0)

    -- |The projective special linear group PSL(n,Fq) == A(n,Fq) == SL(n,Fq)/Z,

    -- returned as permutations of the points of PG(n-1,Fq).

    -- This is a finite simple group provided n>2 or q>3.

    l :: (FiniteField k, Ord k) => Int -> [k] -> [Permutation [k]]
    l :: Int -> [k] -> [Permutation [k]]
    l n :: Int
    n fq :: [k]
    fq = [[([k], [k])] -> Permutation [k]
    forall a. Ord a => [(a, a)] -> Permutation a
    fromPairs ([([k], [k])] -> Permutation [k])
    -> [([k], [k])] -> Permutation [k]
    forall a b. (a -> b) -> a -> b
    $ [([k]
    p, [k] -> [k]
    forall a. (Eq a, Fractional a) => [a] -> [a]
    pnf ([k]
    p [k] -> [[k]] -> [k]
    forall a. Num a => [a] -> [[a]] -> [a]
    <*>> [[k]]
    m)) | [k]
    p <- [[k]]
    ps] | [[k]]
    m <- Int -> [k] -> [[[k]]]
    forall k. FiniteField k => Int -> [k] -> [[[k]]]
    sl Int
    n [k]
    fq]
        where ps :: [[k]]
    ps = Int -> [k] -> [[k]]
    forall a. Num a => Int -> [a] -> [[a]]
    ptsPG (Int
    nInt -> Int -> Int
    forall a. Num a => a -> a -> a
    -1) [k]
    fq

    orderL :: a -> a -> a
    orderL n :: a
    n q :: a
    q = ( a
    qa -> a -> a
    forall a b. (Num a, Integral b) => a -> b -> a
    ^(a
    na -> a -> a
    forall a. Num a => a -> a -> a
    *(a
    na -> a -> a
    forall a. Num a => a -> a -> a
    -1) a -> a -> a
    forall a. Integral a => a -> a -> a
    `div` 2) a -> a -> a
    forall a. Num a => a -> a -> a
    * [a] -> a
    forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
    product [ a
    qa -> a -> a
    forall a b. (Num a, Integral b) => a -> b -> a
    ^a
    ia -> a -> a
    forall a. Num a => a -> a -> a
    -1 | a
    i <- [a
    n,a
    na -> a -> a
    forall a. Num a => a -> a -> a
    -1..2] ] )
                  a -> a -> a
    forall a. Integral a => a -> a -> a
    `div` a -> a -> a
    forall a. Integral a => a -> a -> a
    gcd (a
    qa -> a -> a
    forall a. Num a => a -> a -> a
    -1) a
    n

    -- SYMPLECTIC GROUPS

    -- Carter p186 and 181-3

    -- |The symplectic group Sp(2n,Fq), returned as matrices

    sp2 :: FiniteField k => Int -> [k] -> [[[k]]]
    sp2 :: Int -> [k] -> [[[k]]]
    sp2 n :: Int
    n fq :: [k]
    fq =
        [[[k]]
    _I [[k]] -> [[k]] -> [[k]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<+>> k
    t k -> [[k]] -> [[k]]
    forall a. Num a => a -> [[a]] -> [[a]]
    *>> (Int -> Int -> [[k]]
    forall a. Num a => Int -> Int -> [[a]]
    e Int
    i Int
    j [[k]] -> [[k]] -> [[k]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<->> Int -> Int -> [[k]]
    forall a. Num a => Int -> Int -> [[a]]
    e (-Int
    j) (-Int
    i)) | Int
    i <- [1..Int
    n], Int
    j <- [Int
    iInt -> Int -> Int
    forall a. Num a => a -> a -> a
    +1..Int
    n], k
    t <- [k]
    fq' ] [[[k]]] -> [[[k]]] -> [[[k]]]
    forall a. [a] -> [a] -> [a]
    ++
        [[[k]]
    _I [[k]] -> [[k]] -> [[k]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<->> k
    t k -> [[k]] -> [[k]]
    forall a. Num a => a -> [[a]] -> [[a]]
    *>> (Int -> Int -> [[k]]
    forall a. Num a => Int -> Int -> [[a]]
    e (-Int
    i) (-Int
    j) [[k]] -> [[k]] -> [[k]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<->> Int -> Int -> [[k]]
    forall a. Num a => Int -> Int -> [[a]]
    e Int
    j Int
    i) | Int
    i <- [1..Int
    n], Int
    j <- [Int
    iInt -> Int -> Int
    forall a. Num a => a -> a -> a
    +1..Int
    n], k
    t <- [k]
    fq' ] [[[k]]] -> [[[k]]] -> [[[k]]]
    forall a. [a] -> [a] -> [a]
    ++
        [[[k]]
    _I [[k]] -> [[k]] -> [[k]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<+>> k
    t k -> [[k]] -> [[k]]
    forall a. Num a => a -> [[a]] -> [[a]]
    *>> (Int -> Int -> [[k]]
    forall a. Num a => Int -> Int -> [[a]]
    e Int
    i (-Int
    j) [[k]] -> [[k]] -> [[k]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<+>> Int -> Int -> [[k]]
    forall a. Num a => Int -> Int -> [[a]]
    e Int
    j (-Int
    i)) | Int
    i <- [1..Int
    n], Int
    j <- [Int
    iInt -> Int -> Int
    forall a. Num a => a -> a -> a
    +1..Int
    n], k
    t <- [k]
    fq' ] [[[k]]] -> [[[k]]] -> [[[k]]]
    forall a. [a] -> [a] -> [a]
    ++
        [[[k]]
    _I [[k]] -> [[k]] -> [[k]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<+>> k
    t k -> [[k]] -> [[k]]
    forall a. Num a => a -> [[a]] -> [[a]]
    *>> (Int -> Int -> [[k]]
    forall a. Num a => Int -> Int -> [[a]]
    e (-Int
    i) Int
    j [[k]] -> [[k]] -> [[k]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<+>> Int -> Int -> [[k]]
    forall a. Num a => Int -> Int -> [[a]]
    e (-Int
    j) Int
    i) | Int
    i <- [1..Int
    n], Int
    j <- [Int
    iInt -> Int -> Int
    forall a. Num a => a -> a -> a
    +1..Int
    n], k
    t <- [k]
    fq' ] [[[k]]] -> [[[k]]] -> [[[k]]]
    forall a. [a] -> [a] -> [a]
    ++ -- Carter expresses this slightly differently

        [[[k]]
    _I [[k]] -> [[k]] -> [[k]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<+>> k
    t k -> [[k]] -> [[k]]
    forall a. Num a => a -> [[a]] -> [[a]]
    *>> Int -> Int -> [[k]]
    forall a. Num a => Int -> Int -> [[a]]
    e Int
    i (-Int
    i) | Int
    i <- [1..Int
    n], k
    t <- [k]
    fq' ] [[[k]]] -> [[[k]]] -> [[[k]]]
    forall a. [a] -> [a] -> [a]
    ++
        [[[k]]
    _I [[k]] -> [[k]] -> [[k]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<+>> k
    t k -> [[k]] -> [[k]]
    forall a. Num a => a -> [[a]] -> [[a]]
    *>> Int -> Int -> [[k]]
    forall a. Num a => Int -> Int -> [[a]]
    e (-Int
    i) Int
    i | Int
    i <- [1..Int
    n], k
    t <- [k]
    fq' ]
        where
            fq' :: [k]
    fq' = k -> [k]
    forall fq. FiniteField fq => fq -> [fq]
    basisFq k
    forall a. HasCallStack => a
    undefined -- tail fq -- multiplicative group

            _I :: [[k]]
    _I = Int -> [[k]]
    forall a. Num a => Int -> [[a]]
    idMx (2Int -> Int -> Int
    forall a. Num a => a -> a -> a
    *Int
    n)
            e :: Int -> Int -> [[a]]
    e i :: Int
    i j :: Int
    j = Int -> Int -> [[a]]
    forall a. Num a => Int -> Int -> [[a]]
    e' (if Int
    i Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    > 0 then Int
    i else Int
    nInt -> Int -> Int
    forall a. Num a => a -> a -> a
    -Int
    i) (if Int
    j Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    > 0 then Int
    j else Int
    nInt -> Int -> Int
    forall a. Num a => a -> a -> a
    -Int
    j)
            e' :: Int -> Int -> [[a]]
    e' i :: Int
    i j :: Int
    j = Int -> (Int -> Int -> a) -> [[a]]
    forall t a. (Num t, Enum t) => t -> (t -> t -> a) -> [[a]]
    fMatrix (2Int -> Int -> Int
    forall a. Num a => a -> a -> a
    *Int
    n) (\k :: Int
    k l :: Int
    l -> if (Int
    k,Int
    l) (Int, Int) -> (Int, Int) -> Bool
    forall a. Eq a => a -> a -> Bool
    == (Int
    i,Int
    j) then 1 else 0)

    -- |The projective symplectic group PSp(2n,Fq) == Cn(Fq) == Sp(2n,Fq)/Z,

    -- returned as permutations of the points of PG(2n-1,Fq).

    -- This is a finite simple group for n>1, except for PSp(4,F2).

    s2 :: (FiniteField k, Ord k) => Int -> [k] -> [Permutation [k]]
    s2 :: Int -> [k] -> [Permutation [k]]
    s2 n :: Int
    n fq :: [k]
    fq = [[([k], [k])] -> Permutation [k]
    forall a. Ord a => [(a, a)] -> Permutation a
    fromPairs ([([k], [k])] -> Permutation [k])
    -> [([k], [k])] -> Permutation [k]
    forall a b. (a -> b) -> a -> b
    $ [([k]
    p, [k] -> [k]
    forall a. (Eq a, Fractional a) => [a] -> [a]
    pnf ([k]
    p [k] -> [[k]] -> [k]
    forall a. Num a => [a] -> [[a]] -> [a]
    <*>> [[k]]
    m)) | [k]
    p <- [[k]]
    ps] | [[k]]
    m <- Int -> [k] -> [[[k]]]
    forall k. FiniteField k => Int -> [k] -> [[[k]]]
    sp2 Int
    n [k]
    fq]
        where ps :: [[k]]
    ps = Int -> [k] -> [[k]]
    forall a. Num a => Int -> [a] -> [[a]]
    ptsPG (2Int -> Int -> Int
    forall a. Num a => a -> a -> a
    *Int
    nInt -> Int -> Int
    forall a. Num a => a -> a -> a
    -1) [k]
    fq

    s :: Int -> [k] -> [Permutation [k]]
    s n :: Int
    n fq :: [k]
    fq | Int -> Bool
    forall a. Integral a => a -> Bool
    even Int
    n = Int -> [k] -> [Permutation [k]]
    forall k. (FiniteField k, Ord k) => Int -> [k] -> [Permutation [k]]
    s2 (Int
    n Int -> Int -> Int
    forall a. Integral a => a -> a -> a
    `div` 2) [k]
    fq

    orderS2 :: b -> a -> a
    orderS2 n :: b
    n q :: a
    q = (a
    qa -> b -> a
    forall a b. (Num a, Integral b) => a -> b -> a
    ^b
    nb -> Integer -> b
    forall a b. (Num a, Integral b) => a -> b -> a
    ^2 a -> a -> a
    forall a. Num a => a -> a -> a
    * [a] -> a
    forall (t :: * -> *) a. (Foldable t, Num a) => t a -> a
    product [ a
    qa -> b -> a
    forall a b. (Num a, Integral b) => a -> b -> a
    ^b
    ia -> a -> a
    forall a. Num a => a -> a -> a
    -1 | b
    i <- [2b -> b -> b
    forall a. Num a => a -> a -> a
    *b
    n,2b -> b -> b
    forall a. Num a => a -> a -> a
    *b
    nb -> b -> b
    forall a. Num a => a -> a -> a
    -2..2] ]) a -> a -> a
    forall a. Integral a => a -> a -> a
    `div` a -> a -> a
    forall a. Integral a => a -> a -> a
    gcd (a
    qa -> a -> a
    forall a. Num a => a -> a -> a
    -1) 2

    orderS :: b -> a -> a
    orderS n :: b
    n q :: a
    q | b -> Bool
    forall a. Integral a => a -> Bool
    even b
    n = b -> a -> a
    forall a b. (Integral a, Integral b) => b -> a -> a
    orderS2 (b
    n b -> b -> b
    forall a. Integral a => a -> a -> a
    `div` 2) a
    q

    -- ORTHOGONAL GROUPS

    -- Carter p185 and 178-9

    -- Omega2n(q) - commutator subgroup of O2n(q)

    omegaeven :: Int -> p -> [[[a]]]
    omegaeven n :: Int
    n fq :: p
    fq =
        [[[a]]
    _I [[a]] -> [[a]] -> [[a]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<+>> a
    t a -> [[a]] -> [[a]]
    forall a. Num a => a -> [[a]] -> [[a]]
    *>> (Int -> Int -> [[a]]
    forall a. Num a => Int -> Int -> [[a]]
    e Int
    i Int
    j [[a]] -> [[a]] -> [[a]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<->> Int -> Int -> [[a]]
    forall a. Num a => Int -> Int -> [[a]]
    e (-Int
    j) (-Int
    i)) | Int
    i <- [1..Int
    n], Int
    j <- [Int
    iInt -> Int -> Int
    forall a. Num a => a -> a -> a
    +1..Int
    n], a
    t <- [a]
    fq' ] [[[a]]] -> [[[a]]] -> [[[a]]]
    forall a. [a] -> [a] -> [a]
    ++
        [[[a]]
    _I [[a]] -> [[a]] -> [[a]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<->> a
    t a -> [[a]] -> [[a]]
    forall a. Num a => a -> [[a]] -> [[a]]
    *>> (Int -> Int -> [[a]]
    forall a. Num a => Int -> Int -> [[a]]
    e (-Int
    i) (-Int
    j) [[a]] -> [[a]] -> [[a]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<->> Int -> Int -> [[a]]
    forall a. Num a => Int -> Int -> [[a]]
    e Int
    j Int
    i) | Int
    i <- [1..Int
    n], Int
    j <- [Int
    iInt -> Int -> Int
    forall a. Num a => a -> a -> a
    +1..Int
    n], a
    t <- [a]
    fq' ] [[[a]]] -> [[[a]]] -> [[[a]]]
    forall a. [a] -> [a] -> [a]
    ++
        [[[a]]
    _I [[a]] -> [[a]] -> [[a]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<+>> a
    t a -> [[a]] -> [[a]]
    forall a. Num a => a -> [[a]] -> [[a]]
    *>> (Int -> Int -> [[a]]
    forall a. Num a => Int -> Int -> [[a]]
    e Int
    i (-Int
    j) [[a]] -> [[a]] -> [[a]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<->> Int -> Int -> [[a]]
    forall a. Num a => Int -> Int -> [[a]]
    e Int
    j (-Int
    i)) | Int
    i <- [1..Int
    n], Int
    j <- [Int
    iInt -> Int -> Int
    forall a. Num a => a -> a -> a
    +1..Int
    n], a
    t <- [a]
    fq' ] [[[a]]] -> [[[a]]] -> [[[a]]]
    forall a. [a] -> [a] -> [a]
    ++
        [[[a]]
    _I [[a]] -> [[a]] -> [[a]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<->> a
    t a -> [[a]] -> [[a]]
    forall a. Num a => a -> [[a]] -> [[a]]
    *>> (Int -> Int -> [[a]]
    forall a. Num a => Int -> Int -> [[a]]
    e (-Int
    i) Int
    j [[a]] -> [[a]] -> [[a]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<->> Int -> Int -> [[a]]
    forall a. Num a => Int -> Int -> [[a]]
    e (-Int
    j) Int
    i) | Int
    i <- [1..Int
    n], Int
    j <- [Int
    iInt -> Int -> Int
    forall a. Num a => a -> a -> a
    +1..Int
    n], a
    t <- [a]
    fq' ]
        where
            fq' :: [a]
    fq' = a -> [a]
    forall fq. FiniteField fq => fq -> [fq]
    basisFq a
    forall a. HasCallStack => a
    undefined -- tail fq -- multiplicative group

            _I :: [[a]]
    _I = Int -> [[a]]
    forall a. Num a => Int -> [[a]]
    idMx (2Int -> Int -> Int
    forall a. Num a => a -> a -> a
    *Int
    n)
            e :: Int -> Int -> [[a]]
    e i :: Int
    i j :: Int
    j = Int -> Int -> [[a]]
    forall a. Num a => Int -> Int -> [[a]]
    e' (if Int
    i Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    > 0 then Int
    i else Int
    nInt -> Int -> Int
    forall a. Num a => a -> a -> a
    -Int
    i) (if Int
    j Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    > 0 then Int
    j else Int
    nInt -> Int -> Int
    forall a. Num a => a -> a -> a
    -Int
    j)
            e' :: Int -> Int -> [[a]]
    e' i :: Int
    i j :: Int
    j = Int -> (Int -> Int -> a) -> [[a]]
    forall t a. (Num t, Enum t) => t -> (t -> t -> a) -> [[a]]
    fMatrix (2Int -> Int -> Int
    forall a. Num a => a -> a -> a
    *Int
    n) (\k :: Int
    k l :: Int
    l -> if (Int
    k,Int
    l) (Int, Int) -> (Int, Int) -> Bool
    forall a. Eq a => a -> a -> Bool
    == (Int
    i,Int
    j) then 1 else 0)

    -- O+2n(Fq)  Artin/Conway notation (Atlas, pxii)

    -- Dn(Fq)    Chevalley group

    d :: Int -> [a] -> [Permutation [a]]
    d n :: Int
    n fq :: [a]
    fq = [[([a], [a])] -> Permutation [a]
    forall a. Ord a => [(a, a)] -> Permutation a
    fromPairs ([([a], [a])] -> Permutation [a])
    -> [([a], [a])] -> Permutation [a]
    forall a b. (a -> b) -> a -> b
    $ [([a]
    p, [a] -> [a]
    forall a. (Eq a, Fractional a) => [a] -> [a]
    pnf ([a]
    p [a] -> [[a]] -> [a]
    forall a. Num a => [a] -> [[a]] -> [a]
    <*>> [[a]]
    m)) | [a]
    p <- [[a]]
    ps] | [[a]]
    m <- Int -> [a] -> [[[a]]]
    forall a p. FiniteField a => Int -> p -> [[[a]]]
    omegaeven Int
    n [a]
    fq]
        where ps :: [[a]]
    ps = Int -> [a] -> [[a]]
    forall a. Num a => Int -> [a] -> [[a]]
    ptsPG (2Int -> Int -> Int
    forall a. Num a => a -> a -> a
    *Int
    nInt -> Int -> Int
    forall a. Num a => a -> a -> a
    -1) [a]
    fq

    -- Carter p186-8

    -- Omega2n+1(q)

    omegaodd :: Int -> t a -> [[[a]]]
    omegaodd n :: Int
    n fq :: t a
    fq
        | t a -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    char t a
    fq Int -> Int -> Bool
    forall a. Eq a => a -> a -> Bool
    /= 2 =
            [[[a]]
    _I [[a]] -> [[a]] -> [[a]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<+>> a
    t a -> [[a]] -> [[a]]
    forall a. Num a => a -> [[a]] -> [[a]]
    *>> (Int -> Int -> [[a]]
    forall a. Num a => Int -> Int -> [[a]]
    e Int
    i Int
    j [[a]] -> [[a]] -> [[a]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<->> Int -> Int -> [[a]]
    forall a. Num a => Int -> Int -> [[a]]
    e (-Int
    j) (-Int
    i)) | Int
    i <- [1..Int
    n], Int
    j <- [Int
    iInt -> Int -> Int
    forall a. Num a => a -> a -> a
    +1..Int
    n], a
    t <- [a]
    fq' ] [[[a]]] -> [[[a]]] -> [[[a]]]
    forall a. [a] -> [a] -> [a]
    ++
            [[[a]]
    _I [[a]] -> [[a]] -> [[a]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<->> a
    t a -> [[a]] -> [[a]]
    forall a. Num a => a -> [[a]] -> [[a]]
    *>> (Int -> Int -> [[a]]
    forall a. Num a => Int -> Int -> [[a]]
    e (-Int
    i) (-Int
    j) [[a]] -> [[a]] -> [[a]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<->> Int -> Int -> [[a]]
    forall a. Num a => Int -> Int -> [[a]]
    e Int
    j Int
    i) | Int
    i <- [1..Int
    n], Int
    j <- [Int
    iInt -> Int -> Int
    forall a. Num a => a -> a -> a
    +1..Int
    n], a
    t <- [a]
    fq' ] [[[a]]] -> [[[a]]] -> [[[a]]]
    forall a. [a] -> [a] -> [a]
    ++
            [[[a]]
    _I [[a]] -> [[a]] -> [[a]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<+>> a
    t a -> [[a]] -> [[a]]
    forall a. Num a => a -> [[a]] -> [[a]]
    *>> (Int -> Int -> [[a]]
    forall a. Num a => Int -> Int -> [[a]]
    e Int
    i (-Int
    j) [[a]] -> [[a]] -> [[a]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<->> Int -> Int -> [[a]]
    forall a. Num a => Int -> Int -> [[a]]
    e Int
    j (-Int
    i)) | Int
    i <- [1..Int
    n], Int
    j <- [Int
    iInt -> Int -> Int
    forall a. Num a => a -> a -> a
    +1..Int
    n], a
    t <- [a]
    fq' ] [[[a]]] -> [[[a]]] -> [[[a]]]
    forall a. [a] -> [a] -> [a]
    ++
            [[[a]]
    _I [[a]] -> [[a]] -> [[a]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<->> a
    t a -> [[a]] -> [[a]]
    forall a. Num a => a -> [[a]] -> [[a]]
    *>> (Int -> Int -> [[a]]
    forall a. Num a => Int -> Int -> [[a]]
    e (-Int
    i) Int
    j [[a]] -> [[a]] -> [[a]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<->> Int -> Int -> [[a]]
    forall a. Num a => Int -> Int -> [[a]]
    e (-Int
    j) Int
    i) | Int
    i <- [1..Int
    n], Int
    j <- [Int
    iInt -> Int -> Int
    forall a. Num a => a -> a -> a
    +1..Int
    n], a
    t <- [a]
    fq' ] [[[a]]] -> [[[a]]] -> [[[a]]]
    forall a. [a] -> [a] -> [a]
    ++
            [[[a]]
    _I [[a]] -> [[a]] -> [[a]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<+>> a
    t a -> [[a]] -> [[a]]
    forall a. Num a => a -> [[a]] -> [[a]]
    *>> (2 a -> [[a]] -> [[a]]
    forall a. Num a => a -> [[a]] -> [[a]]
    *>> Int -> Int -> [[a]]
    forall a. Num a => Int -> Int -> [[a]]
    e Int
    i 0 [[a]] -> [[a]] -> [[a]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<->> Int -> Int -> [[a]]
    forall a. Num a => Int -> Int -> [[a]]
    e 0 (-Int
    i)) [[a]] -> [[a]] -> [[a]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<->> (a
    ta -> Integer -> a
    forall a b. (Num a, Integral b) => a -> b -> a
    ^2) a -> [[a]] -> [[a]]
    forall a. Num a => a -> [[a]] -> [[a]]
    *>> Int -> Int -> [[a]]
    forall a. Num a => Int -> Int -> [[a]]
    e Int
    i (-Int
    i) | Int
    i <- [1..Int
    n], a
    t <- [a]
    fq' ] [[[a]]] -> [[[a]]] -> [[[a]]]
    forall a. [a] -> [a] -> [a]
    ++
            [[[a]]
    _I [[a]] -> [[a]] -> [[a]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<->> a
    t a -> [[a]] -> [[a]]
    forall a. Num a => a -> [[a]] -> [[a]]
    *>> (2 a -> [[a]] -> [[a]]
    forall a. Num a => a -> [[a]] -> [[a]]
    *>> Int -> Int -> [[a]]
    forall a. Num a => Int -> Int -> [[a]]
    e (-Int
    i) 0 [[a]] -> [[a]] -> [[a]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<->> Int -> Int -> [[a]]
    forall a. Num a => Int -> Int -> [[a]]
    e 0 Int
    i) [[a]] -> [[a]] -> [[a]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<->> (a
    ta -> Integer -> a
    forall a b. (Num a, Integral b) => a -> b -> a
    ^2) a -> [[a]] -> [[a]]
    forall a. Num a => a -> [[a]] -> [[a]]
    *>> Int -> Int -> [[a]]
    forall a. Num a => Int -> Int -> [[a]]
    e (-Int
    i) Int
    i | Int
    i <- [1..Int
    n], a
    t <- [a]
    fq' ]
        | t a -> Int
    forall (t :: * -> *) a. Foldable t => t a -> Int
    char t a
    fq Int -> Int -> Bool
    forall a. Eq a => a -> a -> Bool
    == 2 =
            [[[a]]
    _I [[a]] -> [[a]] -> [[a]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<+>> a
    t a -> [[a]] -> [[a]]
    forall a. Num a => a -> [[a]] -> [[a]]
    *>> (Int -> Int -> [[a]]
    forall a. Num a => Int -> Int -> [[a]]
    e Int
    i Int
    j [[a]] -> [[a]] -> [[a]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<->> Int -> Int -> [[a]]
    forall a. Num a => Int -> Int -> [[a]]
    e (-Int
    j) (-Int
    i)) | Int
    i <- [1..Int
    n], Int
    j <- [Int
    iInt -> Int -> Int
    forall a. Num a => a -> a -> a
    +1..Int
    n], a
    t <- [a]
    fq' ] [[[a]]] -> [[[a]]] -> [[[a]]]
    forall a. [a] -> [a] -> [a]
    ++
            [[[a]]
    _I [[a]] -> [[a]] -> [[a]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<->> a
    t a -> [[a]] -> [[a]]
    forall a. Num a => a -> [[a]] -> [[a]]
    *>> (Int -> Int -> [[a]]
    forall a. Num a => Int -> Int -> [[a]]
    e (-Int
    i) (-Int
    j) [[a]] -> [[a]] -> [[a]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<->> Int -> Int -> [[a]]
    forall a. Num a => Int -> Int -> [[a]]
    e Int
    j Int
    i) | Int
    i <- [1..Int
    n], Int
    j <- [Int
    iInt -> Int -> Int
    forall a. Num a => a -> a -> a
    +1..Int
    n], a
    t <- [a]
    fq' ] [[[a]]] -> [[[a]]] -> [[[a]]]
    forall a. [a] -> [a] -> [a]
    ++
            [[[a]]
    _I [[a]] -> [[a]] -> [[a]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<+>> a
    t a -> [[a]] -> [[a]]
    forall a. Num a => a -> [[a]] -> [[a]]
    *>> (Int -> Int -> [[a]]
    forall a. Num a => Int -> Int -> [[a]]
    e Int
    i (-Int
    j) [[a]] -> [[a]] -> [[a]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<->> Int -> Int -> [[a]]
    forall a. Num a => Int -> Int -> [[a]]
    e Int
    j (-Int
    i)) | Int
    i <- [1..Int
    n], Int
    j <- [Int
    iInt -> Int -> Int
    forall a. Num a => a -> a -> a
    +1..Int
    n], a
    t <- [a]
    fq' ] [[[a]]] -> [[[a]]] -> [[[a]]]
    forall a. [a] -> [a] -> [a]
    ++ -- !! Carter has a + in place of a - here

            [[[a]]
    _I [[a]] -> [[a]] -> [[a]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<->> a
    t a -> [[a]] -> [[a]]
    forall a. Num a => a -> [[a]] -> [[a]]
    *>> (Int -> Int -> [[a]]
    forall a. Num a => Int -> Int -> [[a]]
    e (-Int
    i) Int
    j [[a]] -> [[a]] -> [[a]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<->> Int -> Int -> [[a]]
    forall a. Num a => Int -> Int -> [[a]]
    e (-Int
    j) Int
    i) | Int
    i <- [1..Int
    n], Int
    j <- [Int
    iInt -> Int -> Int
    forall a. Num a => a -> a -> a
    +1..Int
    n], a
    t <- [a]
    fq' ] [[[a]]] -> [[[a]]] -> [[[a]]]
    forall a. [a] -> [a] -> [a]
    ++
            [[[a]]
    _I [[a]] -> [[a]] -> [[a]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<+>> (a
    ta -> Integer -> a
    forall a b. (Num a, Integral b) => a -> b -> a
    ^2) a -> [[a]] -> [[a]]
    forall a. Num a => a -> [[a]] -> [[a]]
    *>> Int -> Int -> [[a]]
    forall a. Num a => Int -> Int -> [[a]]
    e Int
    i (-Int
    i) | Int
    i <- [1..Int
    n], a
    t <- [a]
    fq' ] [[[a]]] -> [[[a]]] -> [[[a]]]
    forall a. [a] -> [a] -> [a]
    ++
            [[[a]]
    _I [[a]] -> [[a]] -> [[a]]
    forall a. Num a => [[a]] -> [[a]] -> [[a]]
    <<+>> (a
    ta -> Integer -> a
    forall a b. (Num a, Integral b) => a -> b -> a
    ^2) a -> [[a]] -> [[a]]
    forall a. Num a => a -> [[a]] -> [[a]]
    *>> Int -> Int -> [[a]]
    forall a. Num a => Int -> Int -> [[a]]
    e (-Int
    i) Int
    i | Int
    i <- [1..Int
    n], a
    t <- [a]
    fq' ]
        where
            fq' :: [a]
    fq' = a -> [a]
    forall fq. FiniteField fq => fq -> [fq]
    basisFq a
    forall a. HasCallStack => a
    undefined -- tail fq -- multiplicative group

            _I :: [[a]]
    _I = Int -> [[a]]
    forall a. Num a => Int -> [[a]]
    idMx (2Int -> Int -> Int
    forall a. Num a => a -> a -> a
    *Int
    nInt -> Int -> Int
    forall a. Num a => a -> a -> a
    +1)
            e :: Int -> Int -> [[a]]
    e i :: Int
    i j :: Int
    j = Int -> Int -> [[a]]
    forall a. Num a => Int -> Int -> [[a]]
    e' (if Int
    i Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    >= 0 then Int
    i else Int
    nInt -> Int -> Int
    forall a. Num a => a -> a -> a
    -Int
    i) (if Int
    j Int -> Int -> Bool
    forall a. Ord a => a -> a -> Bool
    >= 0 then Int
    j else Int
    nInt -> Int -> Int
    forall a. Num a => a -> a -> a
    -Int
    j)
            e' :: Int -> Int -> [[a]]
    e' i :: Int
    i j :: Int
    j = Int -> (Int -> Int -> a) -> [[a]]
    forall t a. (Num t, Enum t) => t -> (t -> t -> a) -> [[a]]
    fMatrix' (2Int -> Int -> Int
    forall a. Num a => a -> a -> a
    *Int
    nInt -> Int -> Int
    forall a. Num a => a -> a -> a
    +1) (\k :: Int
    k l :: Int
    l -> if (Int
    k,Int
    l) (Int, Int) -> (Int, Int) -> Bool
    forall a. Eq a => a -> a -> Bool
    == (Int
    i,Int
    j) then 1 else 0)

    -- O2n+1(Fq)  Artin/Conway notation

    -- Bn(Fq)     Chevalley group

    b :: Int -> [a] -> [Permutation [a]]
    b n :: Int
    n fq :: [a]
    fq = [[([a], [a])] -> Permutation [a]
    forall a. Ord a => [(a, a)] -> Permutation a
    fromPairs ([([a], [a])] -> Permutation [a])
    -> [([a], [a])] -> Permutation [a]
    forall a b. (a -> b) -> a -> b
    $ [([a]
    p, [a] -> [a]
    forall a. (Eq a, Fractional a) => [a] -> [a]
    pnf ([a]
    p [a] -> [[a]] -> [a]
    forall a. Num a => [a] -> [[a]] -> [a]
    <*>> [[a]]
    m)) | [a]
    p <- [[a]]
    ps] | [[a]]
    m <- Int -> [a] -> [[[a]]]
    forall (t :: * -> *) a a.
    (Foldable t, FiniteField a) =>
    Int -> t a -> [[[a]]]
    omegaodd Int
    n [a]
    fq]
        where ps :: [[a]]
    ps = Int -> [a] -> [[a]]
    forall a. Num a => Int -> [a] -> [[a]]
    ptsPG (2Int -> Int -> Int
    forall a. Num a => a -> a -> a
    *Int
    n) [a]
    fq

    o :: Int -> [a] -> [Permutation [a]]
    o n :: Int
    n fq :: [a]
    fq | Int -> Bool
    forall a. Integral a => a -> Bool
    even Int
    n = Int -> [a] -> [Permutation [a]]
    forall k. (FiniteField k, Ord k) => Int -> [k] -> [Permutation [k]]
    d (Int
    n Int -> Int -> Int
    forall a. Integral a => a -> a -> a
    `div` 2) [a]
    fq
           | Int -> Bool
    forall a. Integral a => a -> Bool
    odd  Int
    n = Int -> [a] -> [Permutation [a]]
    forall k. (FiniteField k, Ord k) => Int -> [k] -> [Permutation [k]]
    b (Int
    n Int -> Int -> Int
    forall a. Integral a => a -> a -> a
    `div` 2) [a]
    fq

    -- The orthogonal groups aren't transitive on PG(n-1,Fq),

    -- so the above permutation representation actually splits into smaller representations on the orbits

    -- eg map length $ orbits $ o 7 f3 -> [364,378,351]

    -- which is the first three permutation representations listed at http://brauer.maths.qmul.ac.uk/Atlas/v3/clas/O73/

    -- UNITARY GROUPS

    -- The unitary group U(n+1,q) is the twisted Chevalley group 2An(q)