{-# LANGUAGE Safe #-}
{-# LANGUAGE GADTSyntax #-}
{-# LANGUAGE ViewPatterns #-}
{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE DeriveGeneric #-}
{-# OPTIONS_GHC -fno-warn-type-defaults #-}
module Algebra.Geometric.Cl3
(
Cl3(..),
bar, dag,
lsv,
toR, toV3, toBV, toI,
toPV, toH, toC,
toBPV, toODD, toTPV,
toAPS,
showOctave,
reduce, tol,
randR, rangeR,
randV3, rangeV3,
randBV, rangeBV,
randI, rangeI,
randPV, rangePV,
randH, rangeH,
randC, rangeC,
randBPV, rangeBPV,
randODD, rangeODD,
randTPV, rangeTPV,
randAPS, rangeAPS,
randUnitV3,
randProjector,
randNilpotent,
eigvals, hasNilpotent,
spectraldcmp, project
) where
import Data.Data (Typeable, Data)
import GHC.Generics (Generic)
import Foreign.Storable (Storable, sizeOf, alignment, peek, poke)
import Foreign.Ptr (Ptr, plusPtr, castPtr)
import System.Random (RandomGen, Random, randomR, random)
data Cl3 where
R :: !Double -> Cl3
V3 :: !Double -> !Double -> !Double -> Cl3
BV :: !Double -> !Double -> !Double -> Cl3
I :: !Double -> Cl3
PV :: !Double -> !Double -> !Double -> !Double -> Cl3
H :: !Double -> !Double -> !Double -> !Double -> Cl3
C :: !Double -> !Double -> Cl3
BPV :: !Double -> !Double -> !Double -> !Double -> !Double -> !Double -> Cl3
ODD :: !Double -> !Double -> !Double -> !Double -> Cl3
TPV :: !Double -> !Double -> !Double -> !Double -> Cl3
APS :: !Double -> !Double -> !Double -> !Double -> !Double -> !Double -> !Double -> !Double -> Cl3
deriving (Show, Read, Typeable, Data, Generic)
showOctave :: Cl3 -> String
showOctave (R a0) = show a0 ++ "*e0"
showOctave (V3 a1 a2 a3) = show a1 ++ "*e1 + " ++ show a2 ++ "*e2 + " ++ show a3 ++ "*e3"
showOctave (BV a23 a31 a12) = show a23 ++ "i*e1 + " ++ show a31 ++ "i*e2 + " ++ show a12 ++ "i*e3"
showOctave (I a123) = show a123 ++ "i*e0"
showOctave (PV a0 a1 a2 a3) = show a0 ++ "*e0 + " ++ show a1 ++ "*e1 + " ++ show a2 ++ "*e2 + " ++ show a3 ++ "*e3"
showOctave (H a0 a23 a31 a12) = show a0 ++ "*e0 + " ++ show a23 ++ "i*e1 + " ++ show a31 ++ "i*e2 + " ++ show a12 ++ "i*e3"
showOctave (C a0 a123) = show a0 ++ "*e0 + " ++ show a123 ++ "i*e0"
showOctave (BPV a1 a2 a3 a23 a31 a12) = show a1 ++ "*e1 + " ++ show a2 ++ "*e2 + " ++ show a3 ++ "*e3 + " ++
show a23 ++ "i*e1 + " ++ show a31 ++ "i*e2 + " ++ show a12 ++ "i*e3"
showOctave (ODD a1 a2 a3 a123) = show a1 ++ "*e1 + " ++ show a2 ++ "*e2 + " ++ show a3 ++ "*e3 + " ++ show a123 ++ "i*e0"
showOctave (TPV a23 a31 a12 a123) = show a23 ++ "i*e1 + " ++ show a31 ++ "i*e2 + " ++ show a12 ++ "i*e3 + " ++ show a123 ++ "i*e0"
showOctave (APS a0 a1 a2 a3 a23 a31 a12 a123) = show a0 ++ "*e0 + " ++ show a1 ++ "*e1 + " ++ show a2 ++ "*e2 + " ++ show a3 ++ "*e3 + " ++
show a23 ++ "i*e1 + " ++ show a31 ++ "i*e2 + " ++ show a12 ++ "i*e3 + " ++ show a123 ++ "i*e0"
instance Eq Cl3 where
(R a0) == (R b0) = a0 == b0
(R a0) == (V3 b1 b2 b3) = a0 == 0 && b1 == 0 && b2 == 0 && b3 == 0
(R a0) == (BV b23 b31 b12) = a0 == 0 && b23 == 0 && b31 == 0 && b12 == 0
(R a0) == (I b123) = a0 == 0 && b123 == 0
(R a0) == (PV b0 b1 b2 b3) = a0 == b0 && b1 == 0 && b2 == 0 && b3 == 0
(R a0) == (H b0 b23 b31 b12) = a0 == b0 && b23 == 0 && b31 == 0 && b12 == 0
(R a0) == (C b0 b123) = a0 == b0 && b123 == 0
(R a0) == (BPV b1 b2 b3 b23 b31 b12) = a0 == 0 && b1 == 0 && b2 == 0 && b3 == 0 && b23 == 0 && b31 == 0 && b12 == 0
(R a0) == (ODD b1 b2 b3 b123) = a0 == 0 && b1 == 0 && b2 == 0 && b3 == 0 && b123 == 0
(R a0) == (TPV b23 b31 b12 b123) = a0 == 0 && b23 == 0 && b31 == 0 && b12 == 0 && b123 == 0
(R a0) == (APS b0 b1 b2 b3 b23 b31 b12 b123) = a0 == b0 && b1 == 0 && b2 == 0 && b3 == 0 && b23 == 0 && b31 == 0 && b12 == 0 && b123 == 0
(V3 a1 a2 a3) == (R b0) = a1 == 0 && a2 == 0 && a3 == 0 && b0 == 0
(BV a23 a31 a12) == (R b0) = a23 == 0 && a31 == 0 && a12 == 0 && b0 == 0
(I a123) == (R b0) = a123 == 0 && b0 == 0
(PV a0 a1 a2 a3) == (R b0) = a0 == b0 && a1 == 0 && a2 == 0 && a3 == 0
(H a0 a23 a31 a12) == (R b0) = a0 == b0 && a23 == 0 && a31 == 0 && a12 == 0
(C a0 a123) == (R b0) = a0 == b0 && a123 == 0
(BPV a1 a2 a3 a23 a31 a12) == (R b0) = a1 == 0 && a2 == 0 && a3 == 0 && a23 == 0 && a31 == 0 && a12 == 0 && b0 == 0
(ODD a1 a2 a3 a123) == (R b0) = a1 == 0 && a2 == 0 && a3 == 0 && a123 == 0 && b0 == 0
(TPV a23 a31 a12 a123) == (R b0) = a23 == 0 && a31 == 0 && a12 == 0 && a123 == 0 && b0 == 0
(APS a0 a1 a2 a3 a23 a31 a12 a123) == (R b0) = a0 == b0 && a1 == 0 && a2 == 0 && a3 == 0 && a23 == 0 && a31 == 0 && a12 == 0 && a123 == 0
(V3 a1 a2 a3) == (V3 b1 b2 b3) = a1 == b1 && a2 == b2 && a3 == b3
(V3 a1 a2 a3) == (BV b23 b31 b12) = a1 == 0 && a2 == 0 && a3 == 0 && b23 == 0 && b31 == 0 && b12 == 0
(V3 a1 a2 a3) == (I b123) = a1 == 0 && a2 == 0 && a3 == 0 && b123 == 0
(V3 a1 a2 a3) == (PV b0 b1 b2 b3) = a1 == b1 && a2 == b2 && a3 == b3 && b0 == 0
(V3 a1 a2 a3) == (H b0 b23 b31 b12) = a1 == 0 && a2 == 0 && a3 == 0 && b0 == 0 && b23 == 0 && b31 == 0 && b12 == 0
(V3 a1 a2 a3) == (C b0 b123) = a1 == 0 && a2 == 0 && a3 == 0 && b0 == 0 && b123 == 0
(V3 a1 a2 a3) == (BPV b1 b2 b3 b23 b31 b12) = a1 == b1 && a2 == b2 && a3 == b3 && b23 == 0 && b31 == 0 && b12 == 0
(V3 a1 a2 a3) == (ODD b1 b2 b3 b123) = a1 == b1 && a2 == b2 && a3 == b3 && b123 == 0
(V3 a1 a2 a3) == (TPV b23 b31 b12 b123) = a1 == 0 && a2 == 0 && a3 == 0 && b23 == 0 && b31 == 0 && b12 == 0 && b123 == 0
(V3 a1 a2 a3) == (APS b0 b1 b2 b3 b23 b31 b12 b123) = a1 == b1 && a2 == b2 && a3 == b3 && b0 == 0 && b23 == 0 && b31 == 0 && b12 == 0 && b123 == 0
(BV a23 a31 a12) == (V3 b1 b2 b3) = a23 == 0 && a31 == 0 && a12 == 0 && b1 == 0 && b2 == 0 && b3 == 0
(I a123) == (V3 b1 b2 b3) = a123 == 0 && b1 == 0 && b2 == 0 && b3 == 0
(PV a0 a1 a2 a3) == (V3 b1 b2 b3) = a0 == 0 && a1 == b1 && a2 == b2 && a3 == b3
(H a0 a23 a31 a12) == (V3 b1 b2 b3) = a0 == 0 && a23 == 0 && a31 == 0 && a12 == 0 && b1 == 0 && b2 == 0 && b3 == 0
(C a0 a123) == (V3 b1 b2 b3) = a0 == 0 && a123 == 0 && b1 == 0 && b2 == 0 && b3 == 0
(BPV a1 a2 a3 a23 a31 a12) == (V3 b1 b2 b3) = a1 == b1 && a2 == b2 && a3 == b3 && a23 == 0 && a31 == 0 && a12 == 0
(ODD a1 a2 a3 a123) == (V3 b1 b2 b3) = a1 == b1 && a2 == b2 && a3 == b3 && a123 == 0
(TPV a23 a31 a12 a123) == (V3 b1 b2 b3) = b1 == 0 && b2 == 0 && b3 == 0 && a23 == 0 && a31 == 0 && a12 == 0 && a123 == 0
(APS a0 a1 a2 a3 a23 a31 a12 a123) == (V3 b1 b2 b3) = a0 == 0 && a1 == b1 && a2 == b2 && a3 == b3 && a23 == 0 && a31 == 0 && a12 == 0 && a123 == 0
(BV a23 a31 a12) == (BV b23 b31 b12) = a23 == b23 && a31 == b31 && a12 == b12
(BV a23 a31 a12) == (I b123) = a23 == 0 && a31 == 0 && a12 == 0 && b123 == 0
(BV a23 a31 a12) == (PV b0 b1 b2 b3) = a23 == 0 && a31 == 0 && a12 == 0 && b0 == 0 && b1 == 0 && b2 == 0 && b3 == 0
(BV a23 a31 a12) == (H b0 b23 b31 b12) = a23 == b23 && a31 == b31 && a12 == b12 && b0 == 0
(BV a23 a31 a12) == (C b0 b123) = a23 == 0 && a31 == 0 && a12 == 0 && b0 == 0 && b123 == 0
(BV a23 a31 a12) == (BPV b1 b2 b3 b23 b31 b12) = a23 == b23 && a31 == b31 && a12 == b12 && b1 == 0 && b2 == 0 && b3 == 0
(BV a23 a31 a12) == (ODD b1 b2 b3 b123) = a23 == 0 && a31 == 0 && a12 == 0 && b1 == 0 && b2 == 0 && b3 == 0 && b123 == 0
(BV a23 a31 a12) == (TPV b23 b31 b12 b123) = a23 == b23 && a31 == b31 && a12 == b12 && b123 == 0
(BV a23 a31 a12) == (APS b0 b1 b2 b3 b23 b31 b12 b123) = a23 == b23 && a31 == b31 && a12 == b12 && b0 == 0 && b1 == 0 && b2 == 0 && b3 == 0 && b123 == 0
(I a123) == (BV b23 b31 b12) = a123 == 0 && b23 == 0 && b31 == 0 && b12 == 0
(PV a0 a1 a2 a3) == (BV b23 b31 b12) = a0 == 0 && a1 == 0 && a2 == 0 && a3 == 0 && b23 == 0 && b31 == 0 && b12 == 0
(H a0 a23 a31 a12) == (BV b23 b31 b12) = a0 == 0 && a23 == b23 && a31 == b31 && a12 == b12
(C a0 a123) == (BV b23 b31 b12) = a0 == 0 && a123 == 0 && b23 == 0 && b31 == 0 && b12 == 0
(BPV a1 a2 a3 a23 a31 a12) == (BV b23 b31 b12) = a1 == 0 && a2 == 0 && a3 == 0 && a23 == b23 && a31 == b31 && a12 == b12
(ODD a1 a2 a3 a123) == (BV b23 b31 b12) = a1 == 0 && a2 == 0 && a3 == 0 && a123 == 0 && b23 == 0 && b31 == 0 && b12 == 0
(TPV a23 a31 a12 a123) == (BV b23 b31 b12) = a23 == b23 && a31 == b31 && a12 == b12 && a123 == 0
(APS a0 a1 a2 a3 a23 a31 a12 a123) == (BV b23 b31 b12) = a0 == 0 && a1 == 0 && a2 == 0 && a3 == 0 && a23 == b23 && a31 == b31 && a12 == b12 && a123 == 0
(I a123) == (I b123) = a123 == b123
(I a123) == (PV b0 b1 b2 b3) = a123 == 0 && b0 == 0 && b1 == 0 && b2 == 0 && b3 == 0
(I a123) == (H b0 b23 b31 b12) = a123 == 0 && b0 == 0 && b23 == 0 && b31 == 0 && b12 == 0
(I a123) == (C b0 b123) = a123 == b123 && b0 == 0
(I a123) == (BPV b1 b2 b3 b23 b31 b12) = a123 == 0 && b1 == 0 && b2 == 0 && b3 == 0 && b23 == 0 && b31 == 0 && b12 == 0
(I a123) == (ODD b1 b2 b3 b123) = a123 == b123 && b1 == 0 && b2 == 0 && b3 == 0
(I a123) == (TPV b23 b31 b12 b123) = a123 == b123 && b23 == 0 && b31 == 0 && b12 == 0
(I a123) == (APS b0 b1 b2 b3 b23 b31 b12 b123) = a123 == b123 && b0 == 0 && b1 == 0 && b2 == 0 && b3 == 0 && b23 == 0 && b31 == 0 && b12 == 0
(PV a0 a1 a2 a3) == (I b123) = b123 == 0 && a0 == 0 && a1 == 0 && a2 == 0 && a3 == 0
(H a0 a23 a31 a12) == (I b123) = b123 == 0 && a0 == 0 && a23 == 0 && a31 == 0 && a12 == 0
(C a0 a123) == (I b123) = a123 == b123 && a0 == 0
(BPV a1 a2 a3 a23 a31 a12) == (I b123) = b123 == 0 && a1 == 0 && a2 == 0 && a3 == 0 && a23 == 0 && a31 == 0 && a12 == 0
(ODD a1 a2 a3 a123) == (I b123) = a123 == b123 && a1 == 0 && a2 == 0 && a3 == 0
(TPV a23 a31 a12 a123) == (I b123) = a123 == b123 && a23 == 0 && a31 == 0 && a12 == 0
(APS a0 a1 a2 a3 a23 a31 a12 a123) == (I b123) = a123 == b123 && a0 == 0 && a1 == 0 && a2 == 0 && a3 == 0 && a23 == 0 && a31 == 0 && a12 == 0
(PV a0 a1 a2 a3) == (PV b0 b1 b2 b3) = a0 == b0 && a1 == b1 && a2 == b2 && a3 == b3
(PV a0 a1 a2 a3) == (H b0 b23 b31 b12) = a0 == b0 && a1 == 0 && a2 == 0 && a3 == 0 && b23 == 0 && b31 == 0 && b12 == 0
(PV a0 a1 a2 a3) == (C b0 b123) = a0 == b0 && a1 == 0 && a2 == 0 && a3 == 0 && b123 == 0
(PV a0 a1 a2 a3) == (BPV b1 b2 b3 b23 b31 b12) = a0 == 0 && a1 == b1 && a2 == b2 && a3 == b3 && b23 == 0 && b31 == 0 && b12 == 0
(PV a0 a1 a2 a3) == (ODD b1 b2 b3 b123) = a0 == 0 && a1 == b1 && a2 == b2 && a3 == b3 && b123 == 0
(PV a0 a1 a2 a3) == (TPV b23 b31 b12 b123) = a0 == 0 && a1 == 0 && a2 == 0 && a3 == 0 && b23 == 0 && b31 == 0 && b12 == 0 && b123 == 0
(PV a0 a1 a2 a3) == (APS b0 b1 b2 b3 b23 b31 b12 b123) = a0 == b0 && a1 == b1 && a2 == b2 && a3 == b3 && b23 == 0 && b31 == 0 && b12 == 0 && b123 == 0
(H a0 a23 a31 a12) == (PV b0 b1 b2 b3) = a0 == b0 && a23 == 0 && a31 == 0 && a12 == 0 && b1 == 0 && b2 == 0 && b3 == 0
(C a0 a123) == (PV b0 b1 b2 b3) = a0 == b0 && a123 == 0 && b1 == 0 && b2 == 0 && b3 == 0
(BPV a1 a2 a3 a23 a31 a12) == (PV b0 b1 b2 b3) = a1 == b1 && a2 == b2 && a3 == b3 && a23 == 0 && a31 == 0 && a12 == 0 && b0 == 0
(ODD a1 a2 a3 a123) == (PV b0 b1 b2 b3) = a1 == b1 && a2 == b2 && a3 == b3 && a123 == 0 && b0 == 0
(TPV a23 a31 a12 a123) == (PV b0 b1 b2 b3) = a23 == 0 && a31 == 0 && a12 == 0 && b0 == 0 && a123 == 0 && b1 == 0 && b2 == 0 && b3 == 0
(APS a0 a1 a2 a3 a23 a31 a12 a123) == (PV b0 b1 b2 b3) = a0 == b0 && a1 == b1 && a2 == b2 && a3 == b3 && a23 == 0 && a31 == 0 && a12 == 0 && a123 == 0
(H a0 a23 a31 a12) == (H b0 b23 b31 b12) = a0 == b0 && a23 == b23 && a31 == b31 && a12 == b12
(H a0 a23 a31 a12) == (C b0 b123) = a0 == b0 && a23 == 0 && a31 == 0 && a12 == 0 && b123 == 0
(H a0 a23 a31 a12) == (BPV b1 b2 b3 b23 b31 b12) = a0 == 0 && a23 == b23 && a31 == b31 && a12 == b12 && b1 == 0 && b2 == 0 && b3 == 0
(H a0 a23 a31 a12) == (ODD b1 b2 b3 b123) = a0 == 0 && b1 == 0 && b2 == 0 && b3 == 0 && a23 == 0 && a31 == 0 && a12 == 0 && b123 == 0
(H a0 a23 a31 a12) == (TPV b23 b31 b12 b123) = a0 == 0 && a23 == b23 && a31 == b31 && a12 == b12 && b123 == 0
(H a0 a23 a31 a12) == (APS b0 b1 b2 b3 b23 b31 b12 b123) = a0 == b0 && a23 == b23 && a31 == b31 && a12 == b12 && b1 == 0 && b2 == 0 && b3 == 0 && b123 == 0
(C a0 a123) == (H b0 b23 b31 b12) = a0 == b0 && a123 == 0 && b23 == 0 && b31 == 0 && b12 == 0
(BPV a1 a2 a3 a23 a31 a12) == (H b0 b23 b31 b12) = a1 == 0 && a2 == 0 && a3 == 0 && a23 == b23 && a31 == b31 && a12 == b12 && b0 == 0
(ODD a1 a2 a3 a123) == (H b0 b23 b31 b12) = a1 == 0 && a2 == 0 && a3 == 0 && a123 == 0 && b23 == 0 && b31 == 0 && b12 == 0 && b0 == 0
(TPV a23 a31 a12 a123) == (H b0 b23 b31 b12) = a23 == b23 && a31 == b31 && a12 == b12 && b0 == 0 && a123 == 0
(APS a0 a1 a2 a3 a23 a31 a12 a123) == (H b0 b23 b31 b12) = a0 == b0 && a1 == 0 && a2 == 0 && a3 == 0 && a23 == b23 && a31 == b31 && a12 == b12 && a123 == 0
(C a0 a123) == (C b0 b123) = a0 == b0 && a123 == b123
(C a0 a123) == (BPV b1 b2 b3 b23 b31 b12) = a0 == 0 && a123 == 0 && b1 == 0 && b2 == 0 && b3 == 0 && b23 == 0 && b31 == 0 && b12 == 0
(C a0 a123) == (ODD b1 b2 b3 b123) = a0 == 0 && a123 == b123 && b1 == 0 && b2 == 0 && b3 == 0
(C a0 a123) == (TPV b23 b31 b12 b123) = a0 == 0 && a123 == b123 && b23 == 0 && b31 == 0 && b12 == 0
(C a0 a123) == (APS b0 b1 b2 b3 b23 b31 b12 b123) = a0 == b0 && a123 == b123 && b1 == 0 && b2 == 0 && b3 == 0 && b23 == 0 && b31 == 0 && b12 == 0
(BPV a1 a2 a3 a23 a31 a12) == (C b0 b123) = a1 == 0 && a2 == 0 && a3 == 0 && a23 == 0 && a31 == 0 && a12 == 0 && b0 == 0 && b123 == 0
(ODD a1 a2 a3 a123) == (C b0 b123) = b0 == 0 && a123 == b123 && a1 == 0 && a2 == 0 && a3 == 0
(TPV a23 a31 a12 a123) == (C b0 b123) = b0 == 0 && a123 == b123 && a23 == 0 && a31 == 0 && a12 == 0
(APS a0 a1 a2 a3 a23 a31 a12 a123) == (C b0 b123) = a0 == b0 && a123 == b123 && a1 == 0 && a2 == 0 && a3 == 0 && a23 == 0 && a31 == 0 && a12 == 0
(BPV a1 a2 a3 a23 a31 a12) == (BPV b1 b2 b3 b23 b31 b12) = a1 == b1 && a2 == b2 && a3 == b3 && a23 == b23 && a31 == b31 && a12 == b12
(BPV a1 a2 a3 a23 a31 a12) == (ODD b1 b2 b3 b123) = a1 == b1 && a2 == b2 && a3 == b3 && b123 == 0 && a23 == 0 && a31 == 0 && a12 == 0
(BPV a1 a2 a3 a23 a31 a12) == (TPV b23 b31 b12 b123) = a23 == b23 && a31 == b31 && a12 == b12 && b123 == 0 && a1 == 0 && a2 == 0 && a3 == 0
(BPV a1 a2 a3 a23 a31 a12) == (APS b0 b1 b2 b3 b23 b31 b12 b123) = a1 == b1 && a2 == b2 && a3 == b3 && a23 == b23 && a31 == b31 && a12 == b12
&& b0 == 0 && b123 == 0
(ODD a1 a2 a3 a123) == (BPV b1 b2 b3 b23 b31 b12) = a1 == b1 && a2 == b2 && a3 == b3 && a123 == 0 && b23 == 0 && b31 == 0 && b12 == 0
(TPV a23 a31 a12 a123) == (BPV b1 b2 b3 b23 b31 b12) = a23 == b23 && a31 == b31 && a12 == b12 && a123 == 0 && b1 == 0 && b2 == 0 && b3 == 0
(APS a0 a1 a2 a3 a23 a31 a12 a123) == (BPV b1 b2 b3 b23 b31 b12) = a0 == 0 && a1 == b1 && a2 == b2 && a3 == b3 && a23 == b23 && a31 == b31
&& a12 == b12 && a123 == 0
(ODD a1 a2 a3 a123) == (ODD b1 b2 b3 b123) = a1 == b1 && a2 == b2 && a3 == b3 && a123 == b123
(ODD a1 a2 a3 a123) == (TPV b23 b31 b12 b123) = a123 == b123 && a1 == 0 && a2 == 0 && a3 == 0 && b23 == 0 && b31 == 0 && b12 == 0
(ODD a1 a2 a3 a123) == (APS b0 b1 b2 b3 b23 b31 b12 b123) = a1 == b1 && a2 == b2 && a3 == b3 && a123 == b123 && b0 == 0 && b23 == 0 && b31 == 0 && b12 == 0
(TPV a23 a31 a12 a123) == (ODD b1 b2 b3 b123) = a123 == b123 && b1 == 0 && b2 == 0 && b3 == 0 && a23 == 0 && a31 == 0 && a12 == 0
(APS a0 a1 a2 a3 a23 a31 a12 a123) == (ODD b1 b2 b3 b123) = a1 == b1 && a2 == b2 && a3 == b3 && a123 == b123 && a0 == 0 && a23 == 0 && a31 == 0 && a12 == 0
(TPV a23 a31 a12 a123) == (TPV b23 b31 b12 b123) = a23 == b23 && a31 == b31 && a12 == b12 && a123 == b123
(TPV a23 a31 a12 a123) == (APS b0 b1 b2 b3 b23 b31 b12 b123) = a23 == b23 && a31 == b31 && a12 == b12 && a123 == b123
&& b0 == 0 && b1 == 0 && b2 == 0 && b3 == 0
(APS a0 a1 a2 a3 a23 a31 a12 a123) == (TPV b23 b31 b12 b123) = a23 == b23 && a31 == b31 && a12 == b12 && a123 == b123
&& a0 == 0 && a1 == 0 && a2 == 0 && a3 == 0
(APS a0 a1 a2 a3 a23 a31 a12 a123) == (APS b0 b1 b2 b3 b23 b31 b12 b123) = a0 == b0 && a1 == b1 && a2 == b2 && a3 == b3 && a23 == b23
&& a31 == b31 && a12 == b12 && a123 == b123
instance Ord Cl3 where
compare (R a0) (R b0) = compare a0 b0
compare cliffor1 cliffor2 =
let (R a0) = abs cliffor1
(R b0) = abs cliffor2
in case compare a0 b0 of
EQ -> let (R a0') = lsv cliffor1
(R b0') = lsv cliffor2
in compare a0' b0'
LT -> LT
GT -> GT
instance Num Cl3 where
(R a0) + (R b0) = R (a0 + b0)
(R a0) + (V3 b1 b2 b3) = PV a0 b1 b2 b3
(R a0) + (BV b23 b31 b12) = H a0 b23 b31 b12
(R a0) + (I b123) = C a0 b123
(R a0) + (PV b0 b1 b2 b3) = PV (a0 + b0) b1 b2 b3
(R a0) + (H b0 b23 b31 b12) = H (a0 + b0) b23 b31 b12
(R a0) + (C b0 b123) = C (a0 + b0) b123
(R a0) + (BPV b1 b2 b3 b23 b31 b12) = APS a0 b1 b2 b3 b23 b31 b12 0
(R a0) + (ODD b1 b2 b3 b123) = APS a0 b1 b2 b3 0 0 0 b123
(R a0) + (TPV b23 b31 b12 b123) = APS a0 0 0 0 b23 b31 b12 b123
(R a0) + (APS b0 b1 b2 b3 b23 b31 b12 b123) = APS (a0 + b0) b1 b2 b3 b23 b31 b12 b123
(V3 a1 a2 a3) + (R b0) = PV b0 a1 a2 a3
(BV a23 a31 a12) + (R b0) = H b0 a23 a31 a12
(I a123) + (R b0) = C b0 a123
(PV a0 a1 a2 a3) + (R b0) = PV (a0 + b0) a1 a2 a3
(H a0 a23 a31 a12) + (R b0) = H (a0 + b0) a23 a31 a12
(C a0 a123) + (R b0) = C (a0 + b0) a123
(BPV a1 a2 a3 a23 a31 a12) + (R b0) = APS b0 a1 a2 a3 a23 a31 a12 0
(ODD a1 a2 a3 a123) + (R b0) = APS b0 a1 a2 a3 0 0 0 a123
(TPV a23 a31 a12 a123) + (R b0) = APS b0 0 0 0 a23 a31 a12 a123
(APS a0 a1 a2 a3 a23 a31 a12 a123) + (R b0) = APS (a0 + b0) a1 a2 a3 a23 a31 a12 a123
(V3 a1 a2 a3) + (V3 b1 b2 b3) = V3 (a1 + b1) (a2 + b2) (a3 + b3)
(V3 a1 a2 a3) + (BV b23 b31 b12) = BPV a1 a2 a3 b23 b31 b12
(V3 a1 a2 a3) + (I b123) = ODD a1 a2 a3 b123
(V3 a1 a2 a3) + (PV b0 b1 b2 b3) = PV b0 (a1 + b1) (a2 + b2) (a3 + b3)
(V3 a1 a2 a3) + (H b0 b23 b31 b12) = APS b0 a1 a2 a3 b23 b31 b12 0
(V3 a1 a2 a3) + (C b0 b123) = APS b0 a1 a2 a3 0 0 0 b123
(V3 a1 a2 a3) + (BPV b1 b2 b3 b23 b31 b12) = BPV (a1 + b1) (a2 + b2) (a3 + b3) b23 b31 b12
(V3 a1 a2 a3) + (ODD b1 b2 b3 b123) = ODD (a1 + b1) (a2 + b2) (a3 + b3) b123
(V3 a1 a2 a3) + (TPV b23 b31 b12 b123) = APS 0 a1 a2 a3 b23 b31 b12 b123
(V3 a1 a2 a3) + (APS b0 b1 b2 b3 b23 b31 b12 b123) = APS b0 (a1 + b1) (a2 + b2) (a3 + b3) b23 b31 b12 b123
(BV a23 a31 a12) + (V3 b1 b2 b3) = BPV b1 b2 b3 a23 a31 a12
(I a123) + (V3 b1 b2 b3) = ODD b1 b2 b3 a123
(PV a0 a1 a2 a3) + (V3 b1 b2 b3) = PV a0 (a1 + b1) (a2 + b2) (a3 + b3)
(H a0 a23 a31 a12) + (V3 b1 b2 b3) = APS a0 b1 b2 b3 a23 a31 a12 0
(C a0 a123) + (V3 b1 b2 b3) = APS a0 b1 b2 b3 0 0 0 a123
(BPV a1 a2 a3 a23 a31 a12) + (V3 b1 b2 b3) = BPV (a1 + b1) (a2 + b2) (a3 + b3) a23 a31 a12
(ODD a1 a2 a3 a123) + (V3 b1 b2 b3) = ODD (a1 + b1) (a2 + b2) (a3 + b3) a123
(TPV a23 a31 a12 a123) + (V3 b1 b2 b3) = APS 0 b1 b2 b3 a23 a31 a12 a123
(APS a0 a1 a2 a3 a23 a31 a12 a123) + (V3 b1 b2 b3) = APS a0 (a1 + b1) (a2 + b2) (a3 + b3) a23 a31 a12 a123
(BV a23 a31 a12) + (BV b23 b31 b12) = BV (a23 + b23) (a31 + b31) (a12 + b12)
(BV a23 a31 a12) + (I b123) = TPV a23 a31 a12 b123
(BV a23 a31 a12) + (PV b0 b1 b2 b3) = APS b0 b1 b2 b3 a23 a31 a12 0
(BV a23 a31 a12) + (H b0 b23 b31 b12) = H b0 (a23 + b23) (a31 + b31) (a12 + b12)
(BV a23 a31 a12) + (C b0 b123) = APS b0 0 0 0 a23 a31 a12 b123
(BV a23 a31 a12) + (BPV b1 b2 b3 b23 b31 b12) = BPV b1 b2 b3 (a23 + b23) (a31 + b31) (a12 + b12)
(BV a23 a31 a12) + (ODD b1 b2 b3 b123) = APS 0 b1 b2 b3 a23 a31 a12 b123
(BV a23 a31 a12) + (TPV b23 b31 b12 b123) = TPV (a23 + b23) (a31 + b31) (a12 + b12) b123
(BV a23 a31 a12) + (APS b0 b1 b2 b3 b23 b31 b12 b123) = APS b0 b1 b2 b3 (a23 + b23) (a31 + b31) (a12 + b12) b123
(I a123) + (BV b23 b31 b12) = TPV b23 b31 b12 a123
(PV a0 a1 a2 a3) + (BV b23 b31 b12) = APS a0 a1 a2 a3 b23 b31 b12 0
(H a0 a23 a31 a12) + (BV b23 b31 b12) = H a0 (a23 + b23) (a31 + b31) (a12 + b12)
(C a0 a123) + (BV b23 b31 b12) = APS a0 0 0 0 b23 b31 b12 a123
(BPV a1 a2 a3 a23 a31 a12) + (BV b23 b31 b12) = BPV a1 a2 a3 (a23 + b23) (a31 + b31) (a12 + b12)
(ODD a1 a2 a3 a123) + (BV b23 b31 b12) = APS 0 a1 a2 a3 b23 b31 b12 a123
(TPV a23 a31 a12 a123) + (BV b23 b31 b12) = TPV (a23 + b23) (a31 + b31) (a12 + b12) a123
(APS a0 a1 a2 a3 a23 a31 a12 a123) + (BV b23 b31 b12) = APS a0 a1 a2 a3 (a23 + b23) (a31 + b31) (a12 + b12) a123
(I a123) + (I b123) = I (a123 + b123)
(I a123) + (PV b0 b1 b2 b3) = APS b0 b1 b2 b3 0 0 0 a123
(I a123) + (H b0 b23 b31 b12) = APS b0 0 0 0 b23 b31 b12 a123
(I a123) + (C b0 b123) = C b0 (a123 + b123)
(I a123) + (BPV b1 b2 b3 b23 b31 b12) = APS 0 b1 b2 b3 b23 b31 b12 a123
(I a123) + (ODD b1 b2 b3 b123) = ODD b1 b2 b3 (a123 + b123)
(I a123) + (TPV b23 b31 b12 b123) = TPV b23 b31 b12 (a123 + b123)
(I a123) + (APS b0 b1 b2 b3 b23 b31 b12 b123) = APS b0 b1 b2 b3 b23 b31 b12 (a123 + b123)
(PV a0 a1 a2 a3) + (I b123) = APS a0 a1 a2 a3 0 0 0 b123
(H a0 a23 a31 a12) + (I b123) = APS a0 0 0 0 a23 a31 a12 b123
(C a0 a123) + (I b123) = C a0 (a123 + b123)
(BPV a1 a2 a3 a23 a31 a12) + (I b123) = APS 0 a1 a2 a3 a23 a31 a12 b123
(ODD a1 a2 a3 a123) + (I b123) = ODD a1 a2 a3 (a123 + b123)
(TPV a23 a31 a12 a123) + (I b123) = TPV a23 a31 a12 (a123 + b123)
(APS a0 a1 a2 a3 a23 a31 a12 a123) + (I b123) = APS a0 a1 a2 a3 a23 a31 a12 (a123 + b123)
(PV a0 a1 a2 a3) + (PV b0 b1 b2 b3) = PV (a0 + b0) (a1 + b1) (a2 + b2) (a3 + b3)
(PV a0 a1 a2 a3) + (H b0 b23 b31 b12) = APS (a0 + b0) a1 a2 a3 b23 b31 b12 0
(PV a0 a1 a2 a3) + (C b0 b123) = APS (a0 + b0) a1 a2 a3 0 0 0 b123
(PV a0 a1 a2 a3) + (BPV b1 b2 b3 b23 b31 b12) = APS a0 (a1 + b1) (a2 + b2) (a3 + b3) b23 b31 b12 0
(PV a0 a1 a2 a3) + (ODD b1 b2 b3 b123) = APS a0 (a1 + b1) (a2 + b2) (a3 + b3) 0 0 0 b123
(PV a0 a1 a2 a3) + (TPV b23 b31 b12 b123) = APS a0 a1 a2 a3 b23 b31 b12 b123
(PV a0 a1 a2 a3) + (APS b0 b1 b2 b3 b23 b31 b12 b123) = APS (a0 + b0) (a1 + b1) (a2 + b2) (a3 + b3) b23 b31 b12 b123
(H a0 a23 a31 a12) + (PV b0 b1 b2 b3) = APS (a0 + b0) b1 b2 b3 a23 a31 a12 0
(C a0 a123) + (PV b0 b1 b2 b3) = APS (a0 + b0) b1 b2 b3 0 0 0 a123
(BPV a1 a2 a3 a23 a31 a12) + (PV b0 b1 b2 b3) = APS b0 (a1 + b1) (a2 + b2) (a3 + b3) a23 a31 a12 0
(ODD a1 a2 a3 a123) + (PV b0 b1 b2 b3) = APS b0 (a1 + b1) (a2 + b2) (a3 + b3) 0 0 0 a123
(TPV a23 a31 a12 a123) + (PV b0 b1 b2 b3) = APS b0 b1 b2 b3 a23 a31 a12 a123
(APS a0 a1 a2 a3 a23 a31 a12 a123) + (PV b0 b1 b2 b3) = APS (a0 + b0) (a1 + b1) (a2 + b2) (a3 + b3) a23 a31 a12 a123
(H a0 a23 a31 a12) + (H b0 b23 b31 b12) = H (a0 + b0) (a23 + b23) (a31 + b31) (a12 + b12)
(H a0 a23 a31 a12) + (C b0 b123) = APS (a0 + b0) 0 0 0 a23 a31 a12 b123
(H a0 a23 a31 a12) + (BPV b1 b2 b3 b23 b31 b12) = APS a0 b1 b2 b3 (a23 + b23) (a31 + b31) (a12 + b12) 0
(H a0 a23 a31 a12) + (ODD b1 b2 b3 b123) = APS a0 b1 b2 b3 a23 a31 a12 b123
(H a0 a23 a31 a12) + (TPV b23 b31 b12 b123) = APS a0 0 0 0 (a23 + b23) (a31 + b31) (a12 + b12) b123
(H a0 a23 a31 a12) + (APS b0 b1 b2 b3 b23 b31 b12 b123) = APS (a0 + b0) b1 b2 b3 (a23 + b23) (a31 + b31) (a12 + b12) b123
(C a0 a123) + (H b0 b23 b31 b12) = APS (a0 + b0) 0 0 0 b23 b31 b12 a123
(BPV a1 a2 a3 a23 a31 a12) + (H b0 b23 b31 b12) = APS b0 a1 a2 a3 (a23 + b23) (a31 + b31) (a12 + b12) 0
(ODD a1 a2 a3 a123) + (H b0 b23 b31 b12) = APS b0 a1 a2 a3 b23 b31 b12 a123
(TPV a23 a31 a12 a123) + (H b0 b23 b31 b12) = APS b0 0 0 0 (a23 + b23) (a31 + b31) (a12 + b12) a123
(APS a0 a1 a2 a3 a23 a31 a12 a123) + (H b0 b23 b31 b12) = APS (a0 + b0) a1 a2 a3 (a23 + b23) (a31 + b31) (a12 + b12) a123
(C a0 a123) + (C b0 b123) = C (a0 + b0) (a123 + b123)
(C a0 a123) + (BPV b1 b2 b3 b23 b31 b12) = APS a0 b1 b2 b3 b23 b31 b12 a123
(C a0 a123) + (ODD b1 b2 b3 b123) = APS a0 b1 b2 b3 0 0 0 (a123 + b123)
(C a0 a123) + (TPV b23 b31 b12 b123) = APS a0 0 0 0 b23 b31 b12 (a123 + b123)
(C a0 a123) + (APS b0 b1 b2 b3 b23 b31 b12 b123) = APS (a0 + b0) b1 b2 b3 b23 b31 b12 (a123 + b123)
(BPV a1 a2 a3 a23 a31 a12) + (C b0 b123) = APS b0 a1 a2 a3 a23 a31 a12 b123
(ODD a1 a2 a3 a123) + (C b0 b123) = APS b0 a1 a2 a3 0 0 0 (a123 + b123)
(TPV a23 a31 a12 a123) + (C b0 b123) = APS b0 0 0 0 a23 a31 a12 (a123 + b123)
(APS a0 a1 a2 a3 a23 a31 a12 a123) + (C b0 b123) = APS (a0 + b0) a1 a2 a3 a23 a31 a12 (a123 + b123)
(BPV a1 a2 a3 a23 a31 a12) + (BPV b1 b2 b3 b23 b31 b12) = BPV (a1 + b1) (a2 + b2) (a3 + b3) (a23 + b23) (a31 + b31) (a12 + b12)
(BPV a1 a2 a3 a23 a31 a12) + (ODD b1 b2 b3 b123) = APS 0 (a1 + b1) (a2 + b2) (a3 + b3) a23 a31 a12 b123
(BPV a1 a2 a3 a23 a31 a12) + (TPV b23 b31 b12 b123) = APS 0 a1 a2 a3 (a23 + b23) (a31 + b31) (a12 + b12) b123
(BPV a1 a2 a3 a23 a31 a12) + (APS b0 b1 b2 b3 b23 b31 b12 b123) = APS b0 (a1 + b1) (a2 + b2) (a3 + b3) (a23 + b23) (a31 + b31) (a12 + b12) b123
(ODD a1 a2 a3 a123) + (BPV b1 b2 b3 b23 b31 b12) = APS 0 (a1 + b1) (a2 + b2) (a3 + b3) b23 b31 b12 a123
(TPV a23 a31 a12 a123) + (BPV b1 b2 b3 b23 b31 b12) = APS 0 b1 b2 b3 (a23 + b23) (a31 + b31) (a12 + b12) a123
(APS a0 a1 a2 a3 a23 a31 a12 a123) + (BPV b1 b2 b3 b23 b31 b12) = APS a0 (a1 + b1) (a2 + b2) (a3 + b3) (a23 + b23) (a31 + b31) (a12 + b12) a123
(ODD a1 a2 a3 a123) + (ODD b1 b2 b3 b123) = ODD (a1 + b1) (a2 + b2) (a3 + b3) (a123 + b123)
(ODD a1 a2 a3 a123) + (TPV b23 b31 b12 b123) = APS 0 a1 a2 a3 b23 b31 b12 (a123 + b123)
(ODD a1 a2 a3 a123) + (APS b0 b1 b2 b3 b23 b31 b12 b123) = APS b0 (a1 + b1) (a2 + b2) (a3 + b3) b23 b31 b12 (a123 + b123)
(TPV a23 a31 a12 a123) + (ODD b1 b2 b3 b123) = APS 0 b1 b2 b3 a23 a31 a12 (a123 + b123)
(APS a0 a1 a2 a3 a23 a31 a12 a123) + (ODD b1 b2 b3 b123) = APS a0 (a1 + b1) (a2 + b2) (a3 + b3) a23 a31 a12 (a123 + b123)
(TPV a23 a31 a12 a123) + (TPV b23 b31 b12 b123) = TPV (a23 + b23) (a31 + b31) (a12 + b12) (a123 + b123)
(TPV a23 a31 a12 a123) + (APS b0 b1 b2 b3 b23 b31 b12 b123) = APS b0 b1 b2 b3 (a23 + b23) (a31 + b31) (a12 + b12) (a123 + b123)
(APS a0 a1 a2 a3 a23 a31 a12 a123) + (TPV b23 b31 b12 b123) = APS a0 a1 a2 a3 (a23 + b23) (a31 + b31) (a12 + b12) (a123 + b123)
(APS a0 a1 a2 a3 a23 a31 a12 a123) + (APS b0 b1 b2 b3 b23 b31 b12 b123) = APS (a0 + b0)
(a1 + b1) (a2 + b2) (a3 + b3)
(a23 + b23) (a31 + b31) (a12 + b12)
(a123 + b123)
(R a0) * (R b0) = R (a0*b0)
(R a0) * (V3 b1 b2 b3) = V3 (a0*b1) (a0*b2) (a0*b3)
(R a0) * (BV b23 b31 b12) = BV (a0*b23) (a0*b31) (a0*b12)
(R a0) * (I b123) = I (a0*b123)
(R a0) * (PV b0 b1 b2 b3) = PV (a0*b0)
(a0*b1) (a0*b2) (a0*b3)
(R a0) * (H b0 b23 b31 b12) = H (a0*b0)
(a0*b23) (a0*b31) (a0*b12)
(R a0) * (C b0 b123) = C (a0*b0)
(a0*b123)
(R a0) * (BPV b1 b2 b3 b23 b31 b12) = BPV (a0*b1) (a0*b2) (a0*b3)
(a0*b23) (a0*b31) (a0*b12)
(R a0) * (ODD b1 b2 b3 b123) = ODD (a0*b1) (a0*b2) (a0*b3)
(a0*b123)
(R a0) * (TPV b23 b31 b12 b123) = TPV (a0*b23) (a0*b31) (a0*b12)
(a0*b123)
(R a0) * (APS b0 b1 b2 b3 b23 b31 b12 b123) = APS (a0*b0)
(a0*b1) (a0*b2) (a0*b3)
(a0*b23) (a0*b31) (a0*b12)
(a0*b123)
(V3 a1 a2 a3) * (R b0) = V3 (a1*b0) (a2*b0) (a3*b0)
(BV a23 a31 a12) * (R b0) = BV (a23*b0) (a31*b0) (a12*b0)
(I a123) * (R b0) = I (a123*b0)
(PV a0 a1 a2 a3) * (R b0) = PV (a0*b0)
(a1*b0) (a2*b0) (a3*b0)
(H a0 a23 a31 a12) * (R b0) = H (a0*b0)
(a23*b0) (a31*b0) (a12*b0)
(C a0 a123) * (R b0) = C (a0*b0)
(a123*b0)
(BPV a1 a2 a3 a23 a31 a12) * (R b0) = BPV (a1*b0) (a2*b0) (a3*b0)
(a23*b0) (a31*b0) (a12*b0)
(ODD a1 a2 a3 a123) * (R b0) = ODD (a1*b0) (a2*b0) (a3*b0)
(a123*b0)
(TPV a23 a31 a12 a123) * (R b0) = TPV (a23*b0) (a31*b0) (a12*b0)
(a123*b0)
(APS a0 a1 a2 a3 a23 a31 a12 a123) * (R b0) = APS (a0*b0)
(a1*b0) (a2*b0) (a3*b0)
(a23*b0) (a31*b0) (a12*b0)
(a123*b0)
(V3 a1 a2 a3) * (V3 b1 b2 b3) = H (a1*b1 + a2*b2 + a3*b3)
(a2*b3 - a3*b2) (a3*b1 - a1*b3) (a1*b2 - a2*b1)
(V3 a1 a2 a3) * (BV b23 b31 b12) = ODD (a3*b31 - a2*b12) (a1*b12 - a3*b23) (a2*b23 - a1*b31)
(a1*b23 + a2*b31 + a3*b12)
(V3 a1 a2 a3) * (I b123) = BV (a1*b123) (a2*b123) (a3*b123)
(V3 a1 a2 a3) * (PV b0 b1 b2 b3) = APS (a1*b1 + a2*b2 + a3*b3)
(a1*b0) (a2*b0) (a3*b0)
(a2*b3 - a3*b2) (a3*b1 - a1*b3) (a1*b2 - a2*b1)
0
(V3 a1 a2 a3) * (H b0 b23 b31 b12) = ODD (a1*b0 - a2*b12 + a3*b31) (a2*b0 + a1*b12 - a3*b23) (a3*b0 - a1*b31 + a2*b23)
(a1*b23 + a2*b31 + a3*b12)
(V3 a1 a2 a3) * (C b0 b123) = BPV (a1*b0) (a2*b0) (a3*b0)
(a1*b123) (a2*b123) (a3*b123)
(V3 a1 a2 a3) * (BPV b1 b2 b3 b23 b31 b12) = APS (a1*b1 + a2*b2 + a3*b3)
(a3*b31 - a2*b12) (a1*b12 - a3*b23) (a2*b23 - a1*b31)
(a2*b3 - a3*b2) (a3*b1 - a1*b3) (a1*b2 - a2*b1)
(a1*b23 + a2*b31 + a3*b12)
(V3 a1 a2 a3) * (ODD b1 b2 b3 b123) = H (a1*b1 + a2*b2 + a3*b3)
(a1*b123 + a2*b3 - a3*b2) (a2*b123 - a1*b3 + a3*b1) (a3*b123 + a1*b2 - a2*b1)
(V3 a1 a2 a3) * (TPV b23 b31 b12 b123) = APS 0
(a3*b31 - a2*b12) (a1*b12 - a3*b23) (a2*b23 - a1*b31)
(a1*b123) (a2*b123) (a3*b123)
(a1*b23 + a2*b31 + a3*b12)
(V3 a1 a2 a3) * (APS b0 b1 b2 b3 b23 b31 b12 b123) = APS (a1*b1 + a2*b2 + a3*b3)
(a1*b0 - a2*b12 + a3*b31) (a2*b0 + a1*b12 - a3*b23) (a3*b0 - a1*b31 + a2*b23)
(a1*b123 + a2*b3 - a3*b2) (a3*b1 - a1*b3 + a2*b123) (a1*b2 - a2*b1 + a3*b123)
(a1*b23 + a2*b31 + a3*b12)
(BV a23 a31 a12) * (V3 b1 b2 b3) = ODD (a12*b2 - a31*b3) (a23*b3 - a12*b1) (a31*b1 - a23*b2)
(a23*b1 + a31*b2 + a12*b3)
(I a123) * (V3 b1 b2 b3) = BV (a123*b1) (a123*b2) (a123*b3)
(PV a0 a1 a2 a3) * (V3 b1 b2 b3) = APS (a1*b1 + a2*b2 + a3*b3)
(a0*b1) (a0*b2) (a0*b3)
(a2*b3 - a3*b2) (a3*b1 - a1*b3) (a1*b2 - a2*b1)
0
(H a0 a23 a31 a12) * (V3 b1 b2 b3) = ODD (a0*b1 + a12*b2 - a31*b3) (a0*b2 - a12*b1 + a23*b3) (a0*b3 + a31*b1 - a23*b2)
(a23*b1 + a31*b2 + a12*b3)
(C a0 a123) * (V3 b1 b2 b3) = BPV (a0*b1) (a0*b2) (a0*b3)
(a123*b1) (a123*b2) (a123*b3)
(BPV a1 a2 a3 a23 a31 a12) * (V3 b1 b2 b3) = APS (a1*b1 + a2*b2 + a3*b3)
(a12*b2 - a31*b3) (a23*b3 - a12*b1) (a31*b1 - a23*b2)
(a2*b3 - a3*b2) (a3*b1 - a1*b3) (a1*b2 - a2*b1)
(a23*b1 + a31*b2 + a12*b3)
(ODD a1 a2 a3 a123) * (V3 b1 b2 b3) = H (a1*b1 + a2*b2 + a3*b3)
(a123*b1 + a2*b3 - a3*b2) (a123*b2 - a1*b3 + a3*b1) (a123*b3 + a1*b2 - a2*b1)
(TPV a23 a31 a12 a123) * (V3 b1 b2 b3) = APS 0
(a12*b2 - a31*b3) (a23*b3 - a12*b1) (a31*b1 - a23*b2)
(a123*b1) (a123*b2) (a123*b3)
(a23*b1 + a31*b2 + a12*b3)
(APS a0 a1 a2 a3 a23 a31 a12 a123) * (V3 b1 b2 b3) = APS (a1*b1 + a2*b2 + a3*b3)
(a0*b1 + a12*b2 - a31*b3) (a0*b2 - a12*b1 + a23*b3) (a0*b3 + a31*b1 - a23*b2)
(a123*b1 + a2*b3 - a3*b2) (a3*b1 - a1*b3 + a123*b2) (a1*b2 - a2*b1 + a123*b3)
(a23*b1 + a31*b2 + a12*b3)
(BV a23 a31 a12) * (BV b23 b31 b12) = H (negate $ a23*b23 + a31*b31 + a12*b12)
(a12*b31 - a31*b12) (a23*b12 - a12*b23) (a31*b23 - a23*b31)
(BV a23 a31 a12) * (I b123) = V3 (negate $ a23*b123) (negate $ a31*b123) (negate $ a12*b123)
(BV a23 a31 a12) * (PV b0 b1 b2 b3) = APS 0
(a12*b2 - a31*b3) (a23*b3 - a12*b1) (a31*b1 - a23*b2)
(a23*b0) (a31*b0) (a12*b0)
(a23*b1 + a31*b2 + a12*b3)
(BV a23 a31 a12) * (H b0 b23 b31 b12) = H (negate $ a23*b23 + a31*b31 + a12*b12)
(a23*b0 - a31*b12 + a12*b31) (a31*b0 + a23*b12 - a12*b23) (a12*b0 - a23*b31 + a31*b23)
(BV a23 a31 a12) * (C b0 b123) = BPV (negate $ a23*b123) (negate $ a31*b123) (negate $ a12*b123)
(a23*b0) (a31*b0) (a12*b0)
(BV a23 a31 a12) * (BPV b1 b2 b3 b23 b31 b12) = APS (negate $ a23*b23 + a31*b31 + a12*b12)
(a12*b2 - a31*b3) (a23*b3 - a12*b1) (a31*b1 - a23*b2)
(a12*b31 - a31*b12) (a23*b12 - a12*b23) (a31*b23 - a23*b31)
(a23*b1 + a31*b2 + a12*b3)
(BV a23 a31 a12) * (ODD b1 b2 b3 b123) = ODD (a12*b2 - a31*b3 - a23*b123) (a23*b3 - a12*b1 - a31*b123) (a31*b1 - a23*b2 - a12*b123)
(a23*b1 + a31*b2 + a12*b3)
(BV a23 a31 a12) * (TPV b23 b31 b12 b123) = APS (negate $ a23*b23 + a31*b31 + a12*b12)
(negate $ a23*b123) (negate $ a31*b123) (negate $ a12*b123)
(a12*b31 - a31*b12) (a23*b12 - a12*b23) (a31*b23 - a23*b31)
0
(BV a23 a31 a12) * (APS b0 b1 b2 b3 b23 b31 b12 b123) = APS (negate $ a23*b23 + a31*b31 + a12*b12)
(a12*b2 - a31*b3 - a23*b123) (a23*b3 - a31*b123 - a12*b1) (a31*b1 - a23*b2 - a12*b123)
(a23*b0 - a31*b12 + a12*b31) (a31*b0 + a23*b12 - a12*b23) (a12*b0 - a23*b31 + a31*b23)
(a23*b1 + a31*b2 + a12*b3)
(I a123) * (BV b23 b31 b12) = V3 (negate $ a123*b23) (negate $ a123*b31) (negate $ a123*b12)
(PV a0 a1 a2 a3) * (BV b23 b31 b12) = APS 0
(a3*b31 - a2*b12) (a1*b12 - a3*b23) (a2*b23 - a1*b31)
(a0*b23) (a0*b31) (a0*b12)
(a1*b23 + a2*b31 + a3*b12)
(H a0 a23 a31 a12) * (BV b23 b31 b12) = H (negate $ a23*b23 + a31*b31 + a12*b12)
(a0*b23 - a31*b12 + a12*b31) (a0*b31 + a23*b12 - a12*b23) (a0*b12 - a23*b31 + a31*b23)
(C a0 a123) * (BV b23 b31 b12) = BPV (negate $ a123*b23) (negate $ a123*b31) (negate $ a123*b12)
(a0*b23) (a0*b31) (a0*b12)
(BPV a1 a2 a3 a23 a31 a12) * (BV b23 b31 b12) = APS (negate $ a23*b23 + a31*b31 + a12*b12)
(a3*b31 - a2*b12) (a1*b12 - a3*b23) (a2*b23 - a1*b31)
(a12*b31 - a31*b12) (a23*b12 - a12*b23) (a31*b23 - a23*b31)
(a1*b23 + a2*b31 + a3*b12)
(ODD a1 a2 a3 a123) * (BV b23 b31 b12) = ODD (negate $ a123*b23 + a2*b12 - a3*b31)
(negate $ a123*b31 - a1*b12 + a3*b23)
(negate $ a123*b12 + a1*b31 - a2*b23)
(a1*b23 + a2*b31 + a3*b12)
(TPV a23 a31 a12 a123) * (BV b23 b31 b12) = APS (negate $ a23*b23 + a31*b31 + a12*b12)
(negate $ a123*b23) (negate $ a123*b31) (negate $ a123*b12)
(negate $ a31*b12 - a12*b31) (negate $ a12*b23 - a23*b12) (negate $ a23*b31 - a31*b23)
0
(APS a0 a1 a2 a3 a23 a31 a12 a123) * (BV b23 b31 b12) = APS (negate $ a23*b23 + a31*b31 + a12*b12)
(a3*b31 - a123*b23 - a2*b12) (a1*b12 - a3*b23 - a123*b31) (a2*b23 - a123*b12 - a1*b31)
(a0*b23 - a31*b12 + a12*b31) (a0*b31 + a23*b12 - a12*b23) (a0*b12 - a23*b31 + a31*b23)
(a1*b23 + a2*b31 + a3*b12)
(I a123) * (I b123) = R (negate $ a123*b123)
(I a123) * (PV b0 b1 b2 b3) = TPV (a123*b1) (a123*b2) (a123*b3)
(a123*b0)
(I a123) * (H b0 b23 b31 b12) = ODD (negate $ a123*b23) (negate $ a123*b31) (negate $ a123*b12)
(a123*b0)
(I a123) * (C b0 b123) = C (negate $ a123*b123)
(a123*b0)
(I a123) * (BPV b1 b2 b3 b23 b31 b12) = BPV (negate $ a123*b23) (negate $ a123*b31) (negate $ a123*b12)
(a123*b1) (a123*b2) (a123*b3)
(I a123) * (ODD b1 b2 b3 b123) = H (negate $ a123*b123)
(a123*b1) (a123*b2) (a123*b3)
(I a123) * (TPV b23 b31 b12 b123) = PV (negate $ a123*b123)
(negate $ a123*b23) (negate $ a123*b31) (negate $ a123*b12)
(I a123) * (APS b0 b1 b2 b3 b23 b31 b12 b123) = APS (negate $ a123*b123)
(negate $ a123*b23) (negate $ a123*b31) (negate $ a123*b12)
(a123*b1) (a123*b2) (a123*b3)
(a123*b0)
(PV a0 a1 a2 a3) * (I b123) = TPV (a1*b123) (a2*b123) (a3*b123)
(a0*b123)
(H a0 a23 a31 a12) * (I b123) = ODD (negate $ a23*b123) (negate $ a31*b123) (negate $ a12*b123)
(a0*b123)
(C a0 a123) * (I b123) = C (negate $ a123*b123)
(a0*b123)
(BPV a1 a2 a3 a23 a31 a12) * (I b123) = BPV (negate $ a23*b123) (negate $ a31*b123) (negate $ a12*b123)
(a1*b123) (a2*b123) (a3*b123)
(ODD a1 a2 a3 a123) * (I b123) = H (negate $ a123*b123)
(a1*b123) (a2*b123) (a3*b123)
(TPV a23 a31 a12 a123) * (I b123) = PV (negate $ a123*b123)
(negate $ a23*b123) (negate $ a31*b123) (negate $ a12*b123)
(APS a0 a1 a2 a3 a23 a31 a12 a123) * (I b123) = APS (negate $ a123*b123)
(negate $ a23*b123) (negate $ a31*b123) (negate $ a12*b123)
(a1*b123) (a2*b123) (a3*b123)
(a0*b123)
(PV a0 a1 a2 a3) * (PV b0 b1 b2 b3) = APS (a0*b0 + a1*b1 + a2*b2 + a3*b3)
(a0*b1 + a1*b0) (a0*b2 + a2*b0) (a0*b3 + a3*b0)
(a2*b3 - a3*b2) (a3*b1 - a1*b3) (a1*b2 - a2*b1)
0
(PV a0 a1 a2 a3) * (H b0 b23 b31 b12) = APS (a0*b0)
(a1*b0 - a2*b12 + a3*b31) (a2*b0 + a1*b12 - a3*b23) (a3*b0 - a1*b31 + a2*b23)
(a0*b23) (a0*b31) (a0*b12)
(a1*b23 + a2*b31 + a3*b12)
(PV a0 a1 a2 a3) * (C b0 b123) = APS (a0*b0)
(a1*b0) (a2*b0) (a3*b0)
(a1*b123) (a2*b123) (a3*b123)
(a0*b123)
(PV a0 a1 a2 a3) * (BPV b1 b2 b3 b23 b31 b12) = APS (a1*b1 + a2*b2 + a3*b3)
(a0*b1 - a2*b12 + a3*b31) (a0*b2 + a1*b12 - a3*b23) (a0*b3 - a1*b31 + a2*b23)
(a0*b23 + a2*b3 - a3*b2) (a0*b31 - a1*b3 + a3*b1) (a0*b12 + a1*b2 - a2*b1)
(a1*b23 + a2*b31 + a3*b12)
(PV a0 a1 a2 a3) * (ODD b1 b2 b3 b123) = APS (a1*b1 + a2*b2 + a3*b3)
(a0*b1) (a0*b2) (a0*b3)
(a1*b123 + a2*b3 - a3*b2) (a2*b123 - a1*b3 + a3*b1) (a3*b123 + a1*b2 - a2*b1)
(a0*b123)
(PV a0 a1 a2 a3) * (TPV b23 b31 b12 b123) = APS 0
(a3*b31 - a2*b12) (a1*b12 - a3*b23) (a2*b23 - a1*b31)
(a0*b23 + a1*b123) (a0*b31 + a2*b123) (a0*b12 + a3*b123)
(a0*b123 + a1*b23 + a2*b31 + a3*b12)
(PV a0 a1 a2 a3) * (APS b0 b1 b2 b3 b23 b31 b12 b123) = APS (a0*b0 + a1*b1 + a2*b2 + a3*b3)
(a0*b1 + a1*b0 - a2*b12 + a3*b31)
(a0*b2 + a2*b0 + a1*b12 - a3*b23)
(a0*b3 + a3*b0 - a1*b31 + a2*b23)
(a0*b23 + a1*b123 + a2*b3 - a3*b2)
(a0*b31 - a1*b3 + a3*b1 + a2*b123)
(a0*b12 + a1*b2 - a2*b1 + a3*b123)
(a0*b123 + a1*b23 + a2*b31 + a3*b12)
(H a0 a23 a31 a12) * (PV b0 b1 b2 b3) = APS (a0*b0)
(a0*b1 + a12*b2 - a31*b3) (a0*b2 - a12*b1 + a23*b3) (a0*b3 + a31*b1 - a23*b2)
(a23*b0) (a31*b0) (a12*b0)
(a23*b1 + a31*b2 + a12*b3)
(C a0 a123) * (PV b0 b1 b2 b3) = APS (a0*b0)
(a0*b1) (a0*b2) (a0*b3)
(a123*b1) (a123*b2) (a123*b3)
(a123*b0)
(BPV a1 a2 a3 a23 a31 a12) * (PV b0 b1 b2 b3) = APS (a1*b1 + a2*b2 + a3*b3)
(a1*b0 + a12*b2 - a31*b3) (a2*b0 - a12*b1 + a23*b3) (a3*b0 + a31*b1 - a23*b2)
(a23*b0 + a2*b3 - a3*b2) (a31*b0 - a1*b3 + a3*b1) (a12*b0 + a1*b2 - a2*b1)
(a23*b1 + a31*b2 + a12*b3)
(ODD a1 a2 a3 a123) * (PV b0 b1 b2 b3) = APS (a1*b1 + a2*b2 + a3*b3)
(a1*b0) (a2*b0) (a3*b0)
(a123*b1 + a2*b3 - a3*b2)
(a123*b2 - a1*b3 + a3*b1)
(a123*b3 + a1*b2 - a2*b1)
(a123*b0)
(TPV a23 a31 a12 a123) * (PV b0 b1 b2 b3) = APS 0
(a12*b2 - a31*b3) (a23*b3 - a12*b1) (a31*b1 - a23*b2)
(a23*b0 + a123*b1) (a31*b0 + a123*b2) (a12*b0 + a123*b3)
(a123*b0 + a23*b1 + a31*b2 + a12*b3)
(APS a0 a1 a2 a3 a23 a31 a12 a123) * (PV b0 b1 b2 b3) = APS (a0*b0 + a1*b1 + a2*b2 + a3*b3)
(a0*b1 + a1*b0 + a12*b2 - a31*b3)
(a0*b2 + a2*b0 - a12*b1 + a23*b3)
(a0*b3 + a3*b0 + a31*b1 - a23*b2)
(a23*b0 + a123*b1 + a2*b3 - a3*b2)
(a31*b0 - a1*b3 + a3*b1 + a123*b2)
(a12*b0 + a1*b2 - a2*b1 + a123*b3)
(a123*b0 + a23*b1 + a31*b2 + a12*b3)
(H a0 a23 a31 a12) * (H b0 b23 b31 b12) = H (a0*b0 - a23*b23 - a31*b31 - a12*b12)
(a0*b23 + a23*b0 - a31*b12 + a12*b31)
(a0*b31 + a31*b0 + a23*b12 - a12*b23)
(a0*b12 + a12*b0 - a23*b31 + a31*b23)
(H a0 a23 a31 a12) * (C b0 b123) = APS (a0*b0)
(negate $ a23*b123) (negate $ a31*b123) (negate $ a12*b123)
(a23*b0) (a31*b0) (a12*b0)
(a0*b123)
(H a0 a23 a31 a12) * (BPV b1 b2 b3 b23 b31 b12) = APS (negate $ a23*b23 + a31*b31 + a12*b12)
(a0*b1 + a12*b2 - a31*b3) (a0*b2 - a12*b1 + a23*b3) (a0*b3 + a31*b1 - a23*b2)
(a0*b23 - a31*b12 + a12*b31) (a0*b31 + a23*b12 - a12*b23) (a0*b12 - a23*b31 + a31*b23)
(a23*b1 + a31*b2 + a12*b3)
(H a0 a23 a31 a12) * (ODD b1 b2 b3 b123) = ODD (a0*b1 + a12*b2 - a31*b3 - a23*b123)
(a0*b2 - a12*b1 + a23*b3 - a31*b123)
(a0*b3 + a31*b1 - a23*b2 - a12*b123)
(a0*b123 + a23*b1 + a31*b2 + a12*b3)
(H a0 a23 a31 a12) * (TPV b23 b31 b12 b123) = APS (negate $ a23*b23 + a31*b31 + a12*b12)
(negate $ a23*b123) (negate $ a31*b123) (negate $ a12*b123)
(a0*b23 - a31*b12 + a12*b31) (a0*b31 + a23*b12 - a12*b23) (a0*b12 - a23*b31 + a31*b23)
(a0*b123)
(H a0 a23 a31 a12) * (APS b0 b1 b2 b3 b23 b31 b12 b123) = APS (a0*b0 - a23*b23 - a31*b31 - a12*b12)
(a0*b1 + a12*b2 - a31*b3 - a23*b123)
(a0*b2 - a12*b1 + a23*b3 - a31*b123)
(a0*b3 + a31*b1 - a23*b2 - a12*b123)
(a0*b23 + a23*b0 - a31*b12 + a12*b31)
(a0*b31 + a31*b0 + a23*b12 - a12*b23)
(a0*b12 + a12*b0 - a23*b31 + a31*b23)
(a0*b123 + a23*b1 + a31*b2 + a12*b3)
(C a0 a123) * (H b0 b23 b31 b12) = APS (a0*b0)
(negate $ a123*b23) (negate $ a123*b31) (negate $ a123*b12)
(a0*b23) (a0*b31) (a0*b12)
(a123*b0)
(BPV a1 a2 a3 a23 a31 a12) * (H b0 b23 b31 b12) = APS (negate $ a23*b23 + a31*b31 + a12*b12)
(a1*b0 - a2*b12 + a3*b31) (a2*b0 + a1*b12 - a3*b23) (a3*b0 - a1*b31 + a2*b23)
(a23*b0 - a31*b12 + a12*b31) (a31*b0 + a23*b12 - a12*b23) (a12*b0 - a23*b31 + a31*b23)
(a1*b23 + a2*b31 + a3*b12)
(ODD a1 a2 a3 a123) * (H b0 b23 b31 b12) = ODD (a1*b0 - a2*b12 + a3*b31 - a123*b23)
(a2*b0 + a1*b12 - a3*b23 - a123*b31)
(a3*b0 - a1*b31 + a2*b23 - a123*b12)
(a123*b0 + a1*b23 + a2*b31 + a3*b12)
(TPV a23 a31 a12 a123) * (H b0 b23 b31 b12) = APS (negate $ a23*b23 + a31*b31 + a12*b12)
(negate $ a123*b23) (negate $ a123*b31) (negate $ a123*b12)
(a23*b0 - a31*b12 + a12*b31) (a31*b0 + a23*b12 - a12*b23) (a12*b0 - a23*b31 + a31*b23)
(a123*b0)
(APS a0 a1 a2 a3 a23 a31 a12 a123) * (H b0 b23 b31 b12) = APS (a0*b0 - a23*b23 - a31*b31 - a12*b12)
(a1*b0 - a2*b12 + a3*b31 - a123*b23)
(a2*b0 + a1*b12 - a3*b23 - a123*b31)
(a3*b0 - a1*b31 + a2*b23 - a123*b12)
(a0*b23 + a23*b0 - a31*b12 + a12*b31)
(a0*b31 + a31*b0 + a23*b12 - a12*b23)
(a0*b12 + a12*b0 - a23*b31 + a31*b23)
(a123*b0 + a1*b23 + a2*b31 + a3*b12)
(C a0 a123) * (C b0 b123) = C (a0*b0 - a123*b123)
(a0*b123 + a123*b0)
(C a0 a123) * (BPV b1 b2 b3 b23 b31 b12) = BPV (a0*b1 - a123*b23) (a0*b2 - a123*b31) (a0*b3 - a123*b12)
(a0*b23 + a123*b1) (a0*b31 + a123*b2) (a0*b12 + a123*b3)
(C a0 a123) * (ODD b1 b2 b3 b123) = APS (negate $ a123*b123)
(a0*b1) (a0*b2) (a0*b3)
(a123*b1) (a123*b2) (a123*b3)
(a0*b123)
(C a0 a123) * (TPV b23 b31 b12 b123) = APS (negate $ a123*b123)
(negate $ a123*b23) (negate $ a123*b31) (negate $ a123*b12)
(a0*b23) (a0*b31) (a0*b12)
(a0*b123)
(C a0 a123) * (APS b0 b1 b2 b3 b23 b31 b12 b123) = APS (a0*b0 - a123*b123)
(a0*b1 - a123*b23) (a0*b2 - a123*b31) (a0*b3 - a123*b12)
(a0*b23 + a123*b1) (a0*b31 + a123*b2) (a0*b12 + a123*b3)
(a0*b123 + a123*b0)
(BPV a1 a2 a3 a23 a31 a12) * (C b0 b123) = BPV (a1*b0 - a23*b123) (a2*b0 - a31*b123) (a3*b0 - a12*b123)
(a23*b0 + a1*b123) (a31*b0 + a2*b123) (a12*b0 + a3*b123)
(ODD a1 a2 a3 a123) * (C b0 b123) = APS (negate $ a123*b123)
(a1*b0) (a2*b0) (a3*b0)
(a1*b123) (a2*b123) (a3*b123)
(a123*b0)
(TPV a23 a31 a12 a123) * (C b0 b123) = APS (negate $ a123*b123)
(negate $ a23*b123) (negate $ a31*b123) (negate $ a12*b123)
(a23*b0) (a31*b0) (a12*b0)
(a123*b0)
(APS a0 a1 a2 a3 a23 a31 a12 a123) * (C b0 b123) = APS (a0*b0 - a123*b123)
(a1*b0 - a23*b123) (a2*b0 - a31*b123) (a3*b0 - a12*b123)
(a23*b0 + a1*b123) (a31*b0 + a2*b123) (a12*b0 + a3*b123)
(a0*b123 + a123*b0)
(BPV a1 a2 a3 a23 a31 a12) * (BPV b1 b2 b3 b23 b31 b12) = APS (a1*b1 + a2*b2 + a3*b3 - a23*b23 - a31*b31 - a12*b12)
(a12*b2 - a2*b12 + a3*b31 - a31*b3)
(a1*b12 - a12*b1 - a3*b23 + a23*b3)
(a31*b1 - a1*b31 + a2*b23 - a23*b2)
(a2*b3 - a3*b2 - a31*b12 + a12*b31)
(a3*b1 - a1*b3 + a23*b12 - a12*b23)
(a1*b2 - a2*b1 - a23*b31 + a31*b23)
(a1*b23 + a23*b1 + a2*b31 + a31*b2 + a3*b12 + a12*b3)
(BPV a1 a2 a3 a23 a31 a12) * (ODD b1 b2 b3 b123) = APS (a1*b1 + a2*b2 + a3*b3)
(a12*b2 - a31*b3 - a23*b123) (a23*b3 - a12*b1 - a31*b123) (a31*b1 - a23*b2 - a12*b123)
(a1*b123 + a2*b3 - a3*b2) (a2*b123 - a1*b3 + a3*b1) (a3*b123 + a1*b2 - a2*b1)
(a23*b1 + a31*b2 + a12*b3)
(BPV a1 a2 a3 a23 a31 a12) * (TPV b23 b31 b12 b123) = APS (negate $ a23*b23 + a31*b31 + a12*b12)
(a3*b31 - a2*b12 - a23*b123) (a1*b12 - a3*b23 - a31*b123) (a2*b23 - a1*b31 - a12*b123)
(a1*b123 - a31*b12 + a12*b31) (a2*b123 + a23*b12 - a12*b23) (a3*b123 - a23*b31 + a31*b23)
(a1*b23 + a2*b31 + a3*b12)
(BPV a1 a2 a3 a23 a31 a12) * (APS b0 b1 b2 b3 b23 b31 b12 b123) = APS (a1*b1 + a2*b2 + a3*b3 - a23*b23 - a31*b31 - a12*b12)
(a1*b0 - a2*b12 + a12*b2 + a3*b31 - a31*b3 - a23*b123)
(a2*b0 + a1*b12 - a12*b1 - a3*b23 + a23*b3 - a31*b123)
(a3*b0 - a1*b31 + a31*b1 + a2*b23 - a23*b2 - a12*b123)
(a23*b0 + a1*b123 + a2*b3 - a3*b2 - a31*b12 + a12*b31)
(a31*b0 - a1*b3 + a3*b1 + a2*b123 + a23*b12 - a12*b23)
(a12*b0 + a1*b2 - a2*b1 + a3*b123 - a23*b31 + a31*b23)
(a1*b23 + a23*b1 + a2*b31 + a31*b2 + a3*b12 + a12*b3)
(ODD a1 a2 a3 a123) * (BPV b1 b2 b3 b23 b31 b12) = APS (a1*b1 + a2*b2 + a3*b3)
(a3*b31 - a2*b12 - a123*b23) (a1*b12 - a3*b23 - a123*b31) (a2*b23 - a1*b31 - a123*b12)
(a123*b1 + a2*b3 - a3*b2) (a123*b2 - a1*b3 + a3*b1) (a123*b3 + a1*b2 - a2*b1)
(a1*b23 + a2*b31 + a3*b12)
(TPV a23 a31 a12 a123) * (BPV b1 b2 b3 b23 b31 b12) = APS (negate $ a23*b23 + a31*b31 + a12*b12)
(a12*b2 - a31*b3 - a123*b23) (a23*b3 - a12*b1 - a123*b31) (a31*b1 - a23*b2 - a123*b12)
(a123*b1 - a31*b12 + a12*b31) (a123*b2 + a23*b12 - a12*b23) (a123*b3 - a23*b31 + a31*b23)
(a23*b1 + a31*b2 + a12*b3)
(APS a0 a1 a2 a3 a23 a31 a12 a123) * (BPV b1 b2 b3 b23 b31 b12) = APS (a1*b1 + a2*b2 + a3*b3 - a23*b23 - a31*b31 - a12*b12)
(a0*b1 - a2*b12 + a12*b2 + a3*b31 - a31*b3 - a123*b23)
(a0*b2 + a1*b12 - a12*b1 - a3*b23 + a23*b3 - a123*b31)
(a0*b3 - a1*b31 + a31*b1 + a2*b23 - a23*b2 - a123*b12)
(a0*b23 + a123*b1 + a2*b3 - a3*b2 - a31*b12 + a12*b31)
(a0*b31 - a1*b3 + a3*b1 + a123*b2 + a23*b12 - a12*b23)
(a0*b12 + a1*b2 - a2*b1 + a123*b3 - a23*b31 + a31*b23)
(a1*b23 + a23*b1 + a2*b31 + a31*b2 + a3*b12 + a12*b3)
(ODD a1 a2 a3 a123) * (ODD b1 b2 b3 b123) = H (a1*b1 + a2*b2 + a3*b3 - a123*b123)
(a1*b123 + a123*b1 + a2*b3 - a3*b2)
(a2*b123 + a123*b2 - a1*b3 + a3*b1)
(a3*b123 + a123*b3 + a1*b2 - a2*b1)
(ODD a1 a2 a3 a123) * (TPV b23 b31 b12 b123) = APS (negate $ a123*b123)
(a3*b31 - a2*b12 - a123*b23) (a1*b12 - a3*b23 - a123*b31) (a2*b23 - a1*b31 - a123*b12)
(a1*b123) (a2*b123) (a3*b123)
(a1*b23 + a2*b31 + a3*b12)
(ODD a1 a2 a3 a123) * (APS b0 b1 b2 b3 b23 b31 b12 b123) = APS (a1*b1 + a2*b2 + a3*b3 - a123*b123)
(a1*b0 - a2*b12 + a3*b31 - a123*b23)
(a2*b0 + a1*b12 - a3*b23 - a123*b31)
(a3*b0 - a1*b31 + a2*b23 - a123*b12)
(a1*b123 + a123*b1 + a2*b3 - a3*b2)
(a2*b123 + a123*b2 - a1*b3 + a3*b1)
(a3*b123 + a123*b3 + a1*b2 - a2*b1)
(a123*b0 + a1*b23 + a2*b31 + a3*b12)
(TPV a23 a31 a12 a123) * (ODD b1 b2 b3 b123) = APS (negate $ a123*b123)
(a12*b2 - a31*b3 - a23*b123) (a23*b3 - a12*b1 - a31*b123) (a31*b1 - a23*b2 - a12*b123)
(a123*b1) (a123*b2) (a123*b3)
(a23*b1 + a31*b2 + a12*b3)
(APS a0 a1 a2 a3 a23 a31 a12 a123) * (ODD b1 b2 b3 b123) = APS (a1*b1 + a2*b2 + a3*b3 - a123*b123)
(a0*b1 + a12*b2 - a31*b3 - a23*b123)
(a0*b2 - a12*b1 + a23*b3 - a31*b123)
(a0*b3 + a31*b1 - a23*b2 - a12*b123)
(a1*b123 + a123*b1 + a2*b3 - a3*b2)
(a2*b123 + a123*b2 - a1*b3 + a3*b1)
(a3*b123 + a123*b3 + a1*b2 - a2*b1)
(a0*b123 + a23*b1 + a31*b2 + a12*b3)
(TPV a23 a31 a12 a123) * (TPV b23 b31 b12 b123) = APS (negate $ a23*b23 + a31*b31 + a12*b12 + a123*b123)
(negate $ a23*b123 + a123*b23) (negate $ a31*b123 + a123*b31) (negate $ a12*b123 + a123*b12)
(a12*b31 - a31*b12) (a23*b12 - a12*b23) (a31*b23 - a23*b31)
0
(TPV a23 a31 a12 a123) * (APS b0 b1 b2 b3 b23 b31 b12 b123) = APS (negate $ a23*b23 + a31*b31 + a12*b12 + a123*b123)
(a12*b2 - a31*b3 - a23*b123 - a123*b23)
(a23*b3 - a12*b1 - a31*b123 - a123*b31)
(a31*b1 - a23*b2 - a12*b123 - a123*b12)
(a23*b0 + a123*b1 - a31*b12 + a12*b31)
(a31*b0 + a123*b2 + a23*b12 - a12*b23)
(a12*b0 + a123*b3 - a23*b31 + a31*b23)
(a123*b0 + a23*b1 + a31*b2 + a12*b3)
(APS a0 a1 a2 a3 a23 a31 a12 a123) * (TPV b23 b31 b12 b123) = APS (negate $ a23*b23 + a31*b31 + a12*b12 + a123*b123)
(a3*b31 - a2*b12 - a23*b123 - a123*b23)
(a1*b12 - a3*b23 - a31*b123 - a123*b31)
(a2*b23 - a1*b31 - a12*b123 - a123*b12)
(a0*b23 + a1*b123 - a31*b12 + a12*b31)
(a0*b31 + a2*b123 + a23*b12 - a12*b23)
(a0*b12 + a3*b123 - a23*b31 + a31*b23)
(a0*b123 + a1*b23 + a2*b31 + a3*b12)
(APS a0 a1 a2 a3 a23 a31 a12 a123) * (APS b0 b1 b2 b3 b23 b31 b12 b123) = APS (a0*b0 + a1*b1 + a2*b2 + a3*b3 - a23*b23 - a31*b31 - a12*b12 - a123*b123)
(a0*b1 + a1*b0 - a2*b12 + a12*b2 + a3*b31 - a31*b3 - a23*b123 - a123*b23)
(a0*b2 + a2*b0 + a1*b12 - a12*b1 - a3*b23 + a23*b3 - a31*b123 - a123*b31)
(a0*b3 + a3*b0 - a1*b31 + a31*b1 + a2*b23 - a23*b2 - a12*b123 - a123*b12)
(a0*b23 + a23*b0 + a1*b123 + a123*b1 + a2*b3 - a3*b2 - a31*b12 + a12*b31)
(a0*b31 + a31*b0 - a1*b3 + a3*b1 + a2*b123 + a123*b2 + a23*b12 - a12*b23)
(a0*b12 + a12*b0 + a1*b2 - a2*b1 + a3*b123 + a123*b3 - a23*b31 + a31*b23)
(a0*b123 + a123*b0 + a1*b23 + a23*b1 + a2*b31 + a31*b2 + a3*b12 + a12*b3)
abs (R a0) = R (abs a0)
abs (V3 a1 a2 a3) = R (sqrt (a1^2 + a2^2 + a3^2))
abs (BV a23 a31 a12) = R (sqrt (a23^2 + a31^2 + a12^2))
abs (I a123) = R (abs a123)
abs (PV a0 a1 a2 a3) = R (sqrt (a0^2 + a1^2 + a2^2 + a3^2 + 2 * abs a0 * sqrt (a1^2 + a2^2 + a3^2)))
abs (H a0 a23 a31 a12) = R (sqrt (a0^2 + a23^2 + a31^2 + a12^2))
abs (C a0 a123) = R (sqrt (a0^2 + a123^2))
abs (BPV a1 a2 a3 a23 a31 a12) = R (sqrt (a1^2 + a23^2 + a2^2 + a31^2 + a3^2 + a12^2 +
2 * sqrt ((a1*a31 - a2*a23)^2 + (a1*a12 - a3*a23)^2 + (a2*a12 - a3*a31)^2)))
abs (ODD a1 a2 a3 a123) = R (sqrt (a1^2 + a2^2 + a3^2 + a123^2))
abs (TPV a23 a31 a12 a123) = R (sqrt (a23^2 + a31^2 + a12^2 + a123^2 + 2 * abs a123 * sqrt (a23^2 + a31^2 + a12^2)))
abs (APS a0 a1 a2 a3 a23 a31 a12 a123) = R (sqrt (a0^2 + a1^2 + a2^2 + a3^2 + a23^2 + a31^2 + a12^2 + a123^2 +
2 * sqrt ((a0*a1 + a123*a23)^2 + (a0*a2 + a123*a31)^2 + (a0*a3 + a123*a12)^2 +
(a2*a12 - a3*a31)^2 + (a3*a23 - a1*a12)^2 + (a1*a31 - a2*a23)^2)))
signum cliffor
| abs cliffor == 0 = 0
| otherwise =
let (R mag) = abs cliffor
in cliffor * R (recip mag)
fromInteger int = R (fromInteger int)
negate (R a0) = R (negate a0)
negate (V3 a1 a2 a3) = V3 (negate a1) (negate a2) (negate a3)
negate (BV a23 a31 a12) = BV (negate a23) (negate a31) (negate a12)
negate (I a123) = I (negate a123)
negate (PV a0 a1 a2 a3) = PV (negate a0)
(negate a1) (negate a2) (negate a3)
negate (H a0 a23 a31 a12) = H (negate a0)
(negate a23) (negate a31) (negate a12)
negate (C a0 a123) = C (negate a0)
(negate a123)
negate (BPV a1 a2 a3 a23 a31 a12) = BPV (negate a1) (negate a2) (negate a3)
(negate a23) (negate a31) (negate a12)
negate (ODD a1 a2 a3 a123) = ODD (negate a1) (negate a2) (negate a3)
(negate a123)
negate (TPV a23 a31 a12 a123) = TPV (negate a23) (negate a31) (negate a12)
(negate a123)
negate (APS a0 a1 a2 a3 a23 a31 a12 a123) = APS (negate a0)
(negate a1) (negate a2) (negate a3)
(negate a23) (negate a31) (negate a12)
(negate a123)
instance Fractional Cl3 where
recip (R a0) = R (recip a0)
recip v@(V3 a1 a2 a3) =
let (R mag) = abs v
sqmag = mag * mag :: Double
in V3 (a1 / sqmag) (a2 / sqmag) (a3 / sqmag)
recip bv@(BV a23 a31 a12) =
let (R mag) = abs bv
sqmag = mag * mag :: Double
in BV (negate $ a23 / sqmag) (negate $ a31 / sqmag) (negate $ a12 / sqmag)
recip i@(I a123) =
let (R mag) = abs i
sqmag = mag * mag :: Double
in I (negate $! a123 / sqmag)
recip pv@PV{} =
let mag = toR $! pv * bar pv
in recip mag * bar pv
recip h@(H a0 a23 a31 a12) =
let (R mag) = abs h
sqmag = mag * mag :: Double
in H (a0 / sqmag) (negate $! a23 / sqmag) (negate $! a31 / sqmag) (negate $! a12 / sqmag)
recip z@(C a0 a123) =
let (R mag) = abs z
sqmag = mag * mag :: Double
in C (a0 / sqmag) (negate $ a123 / sqmag)
recip bpv@BPV{} = reduce $! spectraldcmp recip recip' bpv
recip od@(ODD a1 a2 a3 a123) =
let (R mag) = abs od
sqmag = mag * mag :: Double
in ODD (a1 / sqmag) (a2 / sqmag) (a3 / sqmag) (negate $ a123 / sqmag)
recip tpv@TPV{} =
let mag = toR $! tpv * bar tpv
in recip mag * bar tpv
recip aps@APS{} = reduce $! spectraldcmp recip recip' aps
fromRational rat = R (fromRational rat)
instance Floating Cl3 where
pi = R pi
exp (R a0) = R (exp a0)
exp (I a123) = C (cos a123) (sin a123)
exp (C a0 a123) =
let expa0 = exp a0
in C (expa0 * cos a123) (expa0 * sin a123)
exp cliffor = reduce $! spectraldcmp exp exp' cliffor
log (R a0) | a0 >= 0 = R (log a0)
| otherwise = C (log (negate a0)) pi
log (I a123) = C (log (abs a123)) (signum a123 * (pi/2))
log (C a0 a123) = C (log (sqrt (a0^2 + a123^2))) (atan2 a123 a0)
log cliffor = reduce $! spectraldcmp log log' cliffor
sqrt (R a0) | a0 >= 0 = R (sqrt a0)
| otherwise = I (sqrt $ negate a0)
sqrt (I a123) = C u (if a123 < 0 then -v else v)
where v = if u < tol' then 0 else abs a123 / (2 * u)
u = sqrt (abs a123 / 2)
sqrt (C a0 a123) = C u (if a123 < 0 then -v else v)
where (u,v) = if a0 < 0 then (v',u') else (u',v')
v' = if u' < tol' then 0 else abs a123 / (u'*2)
u' = sqrt ((sqrt (a0^2 + a123^2) + abs a0) / 2)
sqrt cliffor = reduce $! spectraldcmp sqrt sqrt' cliffor
sin (R a0) = R (sin a0)
sin (I a123) = I (sinh a123)
sin (C a0 a123) = C (sin a0 * cosh a123) (cos a0 * sinh a123)
sin cliffor = reduce $! spectraldcmp sin sin' cliffor
cos (R a0) = R (cos a0)
cos (I a123) = R (cosh a123)
cos (C a0 a123) = C (cos a0 * cosh a123) (negate $ sin a0 * sinh a123)
cos cliffor = reduce $! spectraldcmp cos cos' cliffor
tan (R a0) = R (tan a0)
tan (I a123) = I (tanh a123)
tan (C a0 a123) = C (sinx*coshy) (cosx*sinhy) / C (cosx*coshy) (negate $ sinx*sinhy)
where sinx = sin a0
cosx = cos a0
sinhy = sinh a123
coshy = cosh a123
tan cliffor = reduce $! spectraldcmp tan tan' cliffor
asin (R a0) = if (-1) <= a0 && a0 <= 1 then R (asin a0) else asin $ C a0 0
asin (I a123) = I (asinh a123)
asin (C a0 a123) = C a123' (-a0')
where (C a0' a123') = toC $ log (C (-a123) a0 + sqrt (1 - C a0 a123 * C a0 a123))
asin cliffor = reduce $! spectraldcmp asin asin' cliffor
acos (R a0) = if (-1) <= a0 && a0 <= 1 then R (acos a0) else acos $ C a0 0
acos (I a123) = C (pi/2) (negate $ asinh a123)
acos (C a0 a123) = C a123'' (-a0'')
where (C a0'' a123'') = log (C a0 a123 + C (-a123') a0')
(C a0' a123') = sqrt (1 - C a0 a123 * C a0 a123)
acos cliffor = reduce $! spectraldcmp acos acos' cliffor
atan (R a0) = R (atan a0)
atan (I a123) = C a123' (-a0')
where (C a0' a123') = toC.log $ ( R (1-a123) / sqrt (R (1 - a123^2)))
atan (C a0 a123) = C a123' (-a0')
where (C a0' a123') = toC $ log (C (1-a123) a0 / sqrt (1 + C a0 a123 * C a0 a123))
atan cliffor = reduce $! spectraldcmp atan atan' cliffor
sinh (R a0) = R (sinh a0)
sinh (I a123) = I (sin a123)
sinh (C a0 a123) = C (cos a123 * sinh a0) (sin a123 * cosh a0)
sinh cliffor = reduce $! spectraldcmp sinh sinh' cliffor
cosh (R a0) = R (cosh a0)
cosh (I a123) = R (cos a123)
cosh (C a0 a123) = C (cos a123 * cosh a0) (sin a123 * sinh a0)
cosh cliffor = reduce $! spectraldcmp cosh cosh' cliffor
tanh (R a0) = R (tanh a0)
tanh (I a123) = I (tan a123)
tanh (C a0 a123) = C (cosy*sinhx) (siny*coshx) / C (cosy*coshx) (siny*sinhx)
where siny = sin a123
cosy = cos a123
sinhx = sinh a0
coshx = cosh a0
tanh cliffor = reduce $! spectraldcmp tanh tanh' cliffor
asinh (R a0) = R (asinh a0)
asinh (I a123) = log (I a123 + sqrt (R (1 - a123^2)))
asinh (C a0 a123) = log (C a0 a123 + sqrt (1 + C a0 a123 * C a0 a123))
asinh cliffor = reduce $! spectraldcmp asinh asinh' cliffor
acosh (R a0) = log (R a0 + sqrt(R a0 - 1) * sqrt(R a0 + 1))
acosh (I a123) = log (I a123 + sqrt(I a123 - 1) * sqrt(I a123 + 1))
acosh (C a0 a123) = log (C a0 a123 + sqrt(C a0 a123 - 1) * sqrt(C a0 a123 + 1))
acosh cliffor = reduce $! spectraldcmp acosh acosh' cliffor
atanh (R a0) = 0.5 * log (1 + R a0) - 0.5 * log (1 - R a0)
atanh (I a123) = 0.5 * log (1 + I a123) - 0.5 * log (1 - I a123)
atanh (C a0 a123) = 0.5 * log (1 + C a0 a123) - 0.5 * log (1 - C a0 a123)
atanh cliffor = reduce $! spectraldcmp atanh atanh' cliffor
lsv :: Cl3 -> Cl3
lsv (R a0) = R (abs a0)
lsv (V3 a1 a2 a3) = R (sqrt (a1^2 + a2^2 + a3^2))
lsv (BV a23 a31 a12) = R (sqrt (a23^2 + a31^2 + a12^2))
lsv (I a123) = R (abs a123)
lsv (PV a0 a1 a2 a3) = R (sqrt (a0^2 + a1^2 + a2^2 + a3^2 -
2 * abs a0 * sqrt (a1^2 + a2^2 + a3^2)))
lsv (H a0 a23 a31 a12) = R (sqrt (a0^2 + a23^2 + a31^2 + a12^2))
lsv (C a0 a123) = R (sqrt (a0^2 + a123^2))
lsv (BPV a1 a2 a3 a23 a31 a12) = R (sqrt (a1^2 + a23^2 + a2^2 + a31^2 + a3^2 + a12^2 -
2 * sqrt ((a1*a31 - a2*a23)^2 + (a1*a12 - a3*a23)^2 + (a2*a12 - a3*a31)^2)))
lsv (ODD a1 a2 a3 a123) = R (sqrt (a1^2 + a2^2 + a3^2 + a123^2))
lsv (TPV a23 a31 a12 a123) = R (sqrt (a23^2 + a31^2 + a12^2 + a123^2 - (abs a123 + abs a123) * sqrt (a23^2 + a31^2 + a12^2)))
lsv (APS a0 a1 a2 a3 a23 a31 a12 a123) = R (sqrt (a0^2 + a1^2 + a2^2 + a3^2 + a23^2 + a31^2 + a12^2 + a123^2 -
2 * sqrt ((a0*a1 + a123*a23)^2 + (a0*a2 + a123*a31)^2 + (a0*a3 + a123*a12)^2 +
(a2*a12 - a3*a31)^2 + (a3*a23 - a1*a12)^2 + (a1*a31 - a2*a23)^2)))
spectraldcmp :: (Cl3 -> Cl3) -> (Cl3 -> Cl3) -> Cl3 -> Cl3
spectraldcmp fun _ (reduce -> r@R{}) = fun r
spectraldcmp fun _ (reduce -> v@V3{}) = spectraldcmpSpecial toR fun v
spectraldcmp fun _ (reduce -> bv@BV{}) = spectraldcmpSpecial toI fun bv
spectraldcmp fun _ (reduce -> i@I{}) = fun i
spectraldcmp fun _ (reduce -> pv@PV{}) = spectraldcmpSpecial toR fun pv
spectraldcmp fun _ (reduce -> h@H{}) = spectraldcmpSpecial toC fun h
spectraldcmp fun _ (reduce -> c@C{}) = fun c
spectraldcmp fun fun' (reduce -> bpv@BPV{})
| hasNilpotent bpv = jordan fun fun' bpv
| isColinear bpv = spectraldcmpSpecial toC fun bpv
| otherwise =
let (v,d,v_bar) = boost2colinear bpv
in v * spectraldcmpSpecial toC fun d * v_bar
spectraldcmp fun _ (reduce -> od@ODD{}) = spectraldcmpSpecial toC fun od
spectraldcmp fun _ (reduce -> tpv@TPV{}) = spectraldcmpSpecial toI fun tpv
spectraldcmp fun fun' (reduce -> aps@APS{})
| hasNilpotent aps = jordan fun fun' aps
| isColinear aps = spectraldcmpSpecial toC fun aps
| otherwise =
let (v,d,v_bar) = boost2colinear aps
in v * spectraldcmpSpecial toC fun d * v_bar
spectraldcmp _ _ _ = error "Major problems with 'spectraldcmp' or 'reduce'"
jordan :: (Cl3 -> Cl3) -> (Cl3 -> Cl3) -> Cl3 -> Cl3
jordan fun fun' cliffor =
let eigs = toC cliffor
in fun eigs + fun' eigs * toBPV cliffor
spectraldcmpSpecial :: (Cl3 -> Cl3) -> (Cl3 -> Cl3) -> Cl3 -> Cl3
spectraldcmpSpecial toSpecial function cliffor =
let (p,p_bar,eig1,eig2) = projEigs toSpecial cliffor
in function eig1 * p + function eig2 * p_bar
eigvals :: Cl3 -> (Cl3,Cl3)
eigvals (reduce -> r@R{}) = (r,r)
eigvals (reduce -> v@V3{}) = eigvalsSpecial toR v
eigvals (reduce -> bv@BV{}) = eigvalsSpecial toI bv
eigvals (reduce -> i@I{}) = (i,i)
eigvals (reduce -> pv@PV{}) = eigvalsSpecial toR pv
eigvals (reduce -> h@H{}) = eigvalsSpecial toC h
eigvals (reduce -> c@C{}) = (c,c)
eigvals (reduce -> bpv@BPV{})
| hasNilpotent bpv = (0,0)
| isColinear bpv = eigvalsSpecial toC bpv
| otherwise =
let (_,d,_) = boost2colinear bpv
in eigvalsSpecial toC d
eigvals (reduce -> od@ODD{}) = eigvalsSpecial toC od
eigvals (reduce -> tpv@TPV{}) = eigvalsSpecial toI tpv
eigvals (reduce -> aps@APS{})
| hasNilpotent aps = (toC aps,toC aps)
| isColinear aps = eigvalsSpecial toC aps
| otherwise =
let (_,d,_) = boost2colinear aps
in eigvalsSpecial toC d
eigvals _ = error "Major issues with 'eigvals' or 'reduce'"
eigvalsSpecial :: (Cl3 -> Cl3) -> Cl3 -> (Cl3,Cl3)
eigvalsSpecial toSpecial cliffor =
let (_,_,eig1,eig2) = projEigs toSpecial cliffor
in (eig1,eig2)
project :: Cl3 -> Cl3
project (reduce -> R{}) = PV 0.5 0 0 0.5
project (reduce -> v@V3{}) = 0.5 * (1 + signum v)
project (reduce -> bv@BV{}) = 0.5 * (1 + signum (toV3 $ mI * toBV bv))
project (reduce -> I{}) = PV 0.5 0 0 0.5
project (reduce -> pv@PV{}) = 0.5 * (1 + signum (toV3 pv))
project (reduce -> h@H{}) = 0.5 * (1 + signum (toV3 $ mI * toBV h))
project (reduce -> C{}) = PV 0.5 0 0 0.5
project (reduce -> bpv@BPV{})
| abs (toV3 bpv + toV3 (mI * toBV bpv)) <= tol = 0.5 * (1 + signum (toV3 bpv))
| otherwise = 0.5 * (1 + signum (toV3 bpv + toV3 (mI * toBV bpv)))
project (reduce -> od@ODD{}) = 0.5 * (1 + signum (toV3 od))
project (reduce -> tpv@TPV{}) = 0.5 * (1 + signum (toV3 $ mI * toBV tpv))
project (reduce -> aps@APS{}) = project.toBPV $ aps
project (reduce -> _) = error "Error: Got some serious issues with 'project' and/or 'reduce'. Please Fix."
boost2colinear :: Cl3 -> (Cl3, Cl3, Cl3)
boost2colinear cliffor =
let v = toV3 cliffor
bv = toV3 $ mI * toBV cliffor
sum_direction = signum $ v + bv
orthogonal_direction = signum.toV3 $ mI * toBV (v * bv)
other_direction = signum.toV3 $ mI * toBV (sum_direction * orthogonal_direction)
(C a1 a23) = toC $ other_direction * cliffor
(C a3 a12) = toC $ sum_direction * cliffor
sum_sq = a1^2 + a3^2 + a23^2 + a12^2
numerator = 2 * (a1 * a12 - a3 * a23)
tanh4eta = numerator / sum_sq
_4eta = atanh tanh4eta
eta = _4eta / 4
boost = exp (R eta * orthogonal_direction)
boost_bar = bar boost
d = boost_bar * cliffor * boost
in (boost, d, boost_bar)
isColinear :: Cl3 -> Bool
isColinear cliffor = abs (toV3 cliffor) /= 0 && abs (mI * toBV cliffor) /= 0 &&
abs (toBV $ signum (toV3 cliffor) * signum (mI * toBV cliffor)) <= tol
hasNilpotent :: Cl3 -> Bool
hasNilpotent cliffor = abs (toV3 cliffor) /= 0 && abs (mI * toBV cliffor) /= 0 &&
abs (toR $ signum (toV3 cliffor) * signum (mI * toBV cliffor)) <= tol &&
abs (abs (toV3 cliffor) - abs (toBV cliffor)) <= tol
projEigs :: (Cl3 -> Cl3) -> Cl3 -> (Cl3,Cl3,Cl3,Cl3)
projEigs toSpecial cliffor =
let p = project cliffor
p_bar = bar p
eig1 = 2 * (toSpecial $! p * cliffor * p)
eig2 = 2 * (toSpecial $! p_bar * cliffor * p_bar)
in (p,p_bar,eig1,eig2)
reduce :: Cl3 -> Cl3
reduce r@R{} = r
reduce v@V3{}
| abs v <= tol = R 0
| otherwise = v
reduce bv@BV{}
| abs bv <= tol = R 0
| otherwise = bv
reduce i@I{}
| abs i <= tol = R 0
| otherwise = i
reduce pv@PV{}
| abs pv <= tol = R 0
| abs (toR pv) <= tol = toV3 pv
| abs (toV3 pv) <= tol = toR pv
| otherwise = pv
reduce h@H{}
| abs h <= tol = R 0
| abs (toR h) <= tol = toBV h
| abs (toBV h) <= tol = toR h
| otherwise = h
reduce c@C{}
| abs c <= tol = R 0
| abs (toR c) <= tol = toI c
| abs (toI c) <= tol = toR c
| otherwise = c
reduce bpv@BPV{}
| abs bpv <= tol = R 0
| abs (toV3 bpv) <= tol = toBV bpv
| abs (toBV bpv) <= tol = toV3 bpv
| otherwise = bpv
reduce od@ODD{}
| abs od <= tol = R 0
| abs (toV3 od) <= tol = toI od
| abs (toI od) <= tol = toV3 od
| otherwise = od
reduce tpv@TPV{}
| abs tpv <= tol = R 0
| abs (toBV tpv) <= tol = toI tpv
| abs (toI tpv) <= tol = toBV tpv
| otherwise = tpv
reduce aps@APS{}
| abs aps <= tol = R 0
| abs (toC aps) <= tol = reduce (toBPV aps)
| abs (toBPV aps) <= tol = reduce (toC aps)
| abs (toH aps) <= tol = reduce (toODD aps)
| abs (toODD aps) <= tol = reduce (toH aps)
| abs (toPV aps) <= tol = reduce (toTPV aps)
| abs (toTPV aps) <= tol = reduce (toPV aps)
| otherwise = aps
mI :: Cl3
mI = I (-1)
tol :: Cl3
tol = R $ 128 * 1.1102230246251565e-16
tol' :: Double
tol' = 128 * 1.1102230246251565e-16
bar :: Cl3 -> Cl3
bar (R a0) = R a0
bar (V3 a1 a2 a3) = V3 (negate a1) (negate a2) (negate a3)
bar (BV a23 a31 a12) = BV (negate a23) (negate a31) (negate a12)
bar (I a123) = I a123
bar (PV a0 a1 a2 a3) = PV a0 (negate a1) (negate a2) (negate a3)
bar (H a0 a23 a31 a12) = H a0 (negate a23) (negate a31) (negate a12)
bar (C a0 a123) = C a0 a123
bar (BPV a1 a2 a3 a23 a31 a12) = BPV (negate a1) (negate a2) (negate a3) (negate a23) (negate a31) (negate a12)
bar (ODD a1 a2 a3 a123) = ODD (negate a1) (negate a2) (negate a3) a123
bar (TPV a23 a31 a12 a123) = TPV (negate a23) (negate a31) (negate a12) a123
bar (APS a0 a1 a2 a3 a23 a31 a12 a123) = APS a0 (negate a1) (negate a2) (negate a3) (negate a23) (negate a31) (negate a12) a123
dag :: Cl3 -> Cl3
dag (R a0) = R a0
dag (V3 a1 a2 a3) = V3 a1 a2 a3
dag (BV a23 a31 a12) = BV (negate a23) (negate a31) (negate a12)
dag (I a123) = I (negate a123)
dag (PV a0 a1 a2 a3) = PV a0 a1 a2 a3
dag (H a0 a23 a31 a12) = H a0 (negate a23) (negate a31) (negate a12)
dag (C a0 a123) = C a0 (negate a123)
dag (BPV a1 a2 a3 a23 a31 a12) = BPV a1 a2 a3 (negate a23) (negate a31) (negate a12)
dag (ODD a1 a2 a3 a123) = ODD a1 a2 a3 (negate a123)
dag (TPV a23 a31 a12 a123) = TPV (negate a23) (negate a31) (negate a12) (negate a123)
dag (APS a0 a1 a2 a3 a23 a31 a12 a123) = APS a0 a1 a2 a3 (negate a23) (negate a31) (negate a12) (negate a123)
toR :: Cl3 -> Cl3
toR (R a0) = R a0
toR V3{} = R 0
toR BV{} = R 0
toR I{} = R 0
toR (PV a0 _ _ _) = R a0
toR (H a0 _ _ _) = R a0
toR (C a0 _) = R a0
toR BPV{} = R 0
toR ODD{} = R 0
toR TPV{} = R 0
toR (APS a0 _ _ _ _ _ _ _) = R a0
toV3 :: Cl3 -> Cl3
toV3 R{} = V3 0 0 0
toV3 (V3 a1 a2 a3) = V3 a1 a2 a3
toV3 BV{} = V3 0 0 0
toV3 I{} = V3 0 0 0
toV3 (PV _ a1 a2 a3) = V3 a1 a2 a3
toV3 H{} = V3 0 0 0
toV3 C{} = V3 0 0 0
toV3 (BPV a1 a2 a3 _ _ _) = V3 a1 a2 a3
toV3 (ODD a1 a2 a3 _) = V3 a1 a2 a3
toV3 TPV{} = V3 0 0 0
toV3 (APS _ a1 a2 a3 _ _ _ _) = V3 a1 a2 a3
toBV :: Cl3 -> Cl3
toBV R{} = BV 0 0 0
toBV V3{} = BV 0 0 0
toBV (BV a23 a31 a12) = BV a23 a31 a12
toBV I{} = BV 0 0 0
toBV PV{} = BV 0 0 0
toBV (H _ a23 a31 a12) = BV a23 a31 a12
toBV C{} = BV 0 0 0
toBV (BPV _ _ _ a23 a31 a12) = BV a23 a31 a12
toBV ODD{} = BV 0 0 0
toBV (TPV a23 a31 a12 _) = BV a23 a31 a12
toBV (APS _ _ _ _ a23 a31 a12 _) = BV a23 a31 a12
toI :: Cl3 -> Cl3
toI R{} = I 0
toI V3{} = I 0
toI BV{} = I 0
toI (I a123) = I a123
toI PV{} = I 0
toI H{} = I 0
toI (C _ a123) = I a123
toI BPV{} = I 0
toI (ODD _ _ _ a123) = I a123
toI (TPV _ _ _ a123) = I a123
toI (APS _ _ _ _ _ _ _ a123) = I a123
toPV :: Cl3 -> Cl3
toPV (R a0) = PV a0 0 0 0
toPV (V3 a1 a2 a3) = PV 0 a1 a2 a3
toPV BV{} = PV 0 0 0 0
toPV I{} = PV 0 0 0 0
toPV (PV a0 a1 a2 a3) = PV a0 a1 a2 a3
toPV (H a0 _ _ _) = PV a0 0 0 0
toPV (C a0 _) = PV a0 0 0 0
toPV (BPV a1 a2 a3 _ _ _) = PV 0 a1 a2 a3
toPV (ODD a1 a2 a3 _) = PV a1 a2 a3 0
toPV TPV{} = PV 0 0 0 0
toPV (APS a0 a1 a2 a3 _ _ _ _) = PV a0 a1 a2 a3
toH :: Cl3 -> Cl3
toH (R a0) = H a0 0 0 0
toH V3{} = H 0 0 0 0
toH (BV a23 a31 a12) = H 0 a23 a31 a12
toH (I _) = H 0 0 0 0
toH (PV a0 _ _ _) = H a0 0 0 0
toH (H a0 a23 a31 a12) = H a0 a23 a31 a12
toH (C a0 _) = H a0 0 0 0
toH (BPV _ _ _ a23 a31 a12) = H 0 a23 a31 a12
toH ODD{} = H 0 0 0 0
toH (TPV a23 a31 a12 _) = H 0 a23 a31 a12
toH (APS a0 _ _ _ a23 a31 a12 _) = H a0 a23 a31 a12
toC :: Cl3 -> Cl3
toC (R a0) = C a0 0
toC V3{} = C 0 0
toC BV{} = C 0 0
toC (I a123) = C 0 a123
toC (PV a0 _ _ _) = C a0 0
toC (H a0 _ _ _) = C a0 0
toC (C a0 a123) = C a0 a123
toC BPV{} = C 0 0
toC (ODD _ _ _ a123) = C 0 a123
toC (TPV _ _ _ a123) = C 0 a123
toC (APS a0 _ _ _ _ _ _ a123) = C a0 a123
toBPV :: Cl3 -> Cl3
toBPV R{} = BPV 0 0 0 0 0 0
toBPV (V3 a1 a2 a3) = BPV a1 a2 a3 0 0 0
toBPV (BV a23 a31 a12) = BPV 0 0 0 a23 a31 a12
toBPV I{} = BPV 0 0 0 0 0 0
toBPV (PV _ a1 a2 a3) = BPV a1 a2 a3 0 0 0
toBPV (H _ a23 a31 a12) = BPV 0 0 0 a23 a31 a12
toBPV C{} = BPV 0 0 0 0 0 0
toBPV (BPV a1 a2 a3 a23 a31 a12) = BPV a1 a2 a3 a23 a31 a12
toBPV (ODD a1 a2 a3 _) = BPV a1 a2 a3 0 0 0
toBPV (TPV a23 a31 a12 _) = BPV 0 0 0 a23 a31 a12
toBPV (APS _ a1 a2 a3 a23 a31 a12 _) = BPV a1 a2 a3 a23 a31 a12
toODD :: Cl3 -> Cl3
toODD R{} = ODD 0 0 0 0
toODD (V3 a1 a2 a3) = ODD a1 a2 a3 0
toODD BV{} = ODD 0 0 0 0
toODD (I a123) = ODD 0 0 0 a123
toODD (PV _ a1 a2 a3) = ODD a1 a2 a3 0
toODD H{} = ODD 0 0 0 0
toODD (C _ a123) = ODD 0 0 0 a123
toODD (BPV a1 a2 a3 _ _ _) = ODD a1 a2 a3 0
toODD (ODD a1 a2 a3 a123) = ODD a1 a2 a3 a123
toODD (TPV _ _ _ a123) = ODD 0 0 0 a123
toODD (APS _ a1 a2 a3 _ _ _ a123) = ODD a1 a2 a3 a123
toTPV :: Cl3 -> Cl3
toTPV R{} = TPV 0 0 0 0
toTPV V3{} = TPV 0 0 0 0
toTPV (BV a23 a31 a12) = TPV a23 a31 a12 0
toTPV (I a123) = TPV 0 0 0 a123
toTPV PV{} = TPV 0 0 0 0
toTPV (H _ a23 a31 a12) = TPV a23 a31 a12 0
toTPV (C _ a123) = TPV 0 0 0 a123
toTPV (BPV _ _ _ a23 a31 a12) = TPV a23 a31 a12 0
toTPV (ODD _ _ _ a123) = TPV 0 0 0 a123
toTPV (TPV a23 a31 a12 a123) = TPV a23 a31 a12 a123
toTPV (APS _ _ _ _ a23 a31 a12 a123) = TPV a23 a31 a12 a123
toAPS :: Cl3 -> Cl3
toAPS (R a0) = APS a0 0 0 0 0 0 0 0
toAPS (V3 a1 a2 a3) = APS 0 a1 a2 a3 0 0 0 0
toAPS (BV a23 a31 a12) = APS 0 0 0 0 a23 a31 a12 0
toAPS (I a123) = APS 0 0 0 0 0 0 0 a123
toAPS (PV a0 a1 a2 a3) = APS a0 a1 a2 a3 0 0 0 0
toAPS (H a0 a23 a31 a12) = APS a0 0 0 0 a23 a31 a12 0
toAPS (C a0 a123) = APS a0 0 0 0 0 0 0 a123
toAPS (BPV a1 a2 a3 a23 a31 a12) = APS 0 a1 a2 a3 a23 a31 a12 0
toAPS (ODD a1 a2 a3 a123) = APS 0 a1 a2 a3 0 0 0 a123
toAPS (TPV a23 a31 a12 a123) = APS 0 0 0 0 a23 a31 a12 a123
toAPS (APS a0 a1 a2 a3 a23 a31 a12 a123) = APS a0 a1 a2 a3 a23 a31 a12 a123
recip' :: Cl3 -> Cl3
recip' x = negate.recip $ x * x
exp' :: Cl3 -> Cl3
exp' = exp
log' :: Cl3 -> Cl3
log' = recip
sqrt' :: Cl3 -> Cl3
sqrt' x = 0.5 * recip (sqrt x)
sin' :: Cl3 -> Cl3
sin' = cos
cos' :: Cl3 -> Cl3
cos' = negate.sin
tan' :: Cl3 -> Cl3
tan' x = recip (cos x) * recip (cos x)
asin' :: Cl3 -> Cl3
asin' x = recip.sqrt $ 1 - (x * x)
acos' :: Cl3 -> Cl3
acos' x = negate.recip.sqrt $ 1 - (x * x)
atan' :: Cl3 -> Cl3
atan' x = recip $ 1 + (x * x)
sinh' :: Cl3 -> Cl3
sinh' = cosh
cosh' :: Cl3 -> Cl3
cosh' = sinh
tanh' :: Cl3 -> Cl3
tanh' x = recip (cosh x) * recip (cosh x)
asinh' :: Cl3 -> Cl3
asinh' x = recip.sqrt $ (x * x) + 1
acosh' :: Cl3 -> Cl3
acosh' x = recip $ sqrt (x - 1) * sqrt (x + 1)
atanh' :: Cl3 -> Cl3
atanh' x = recip $ 1 - (x * x)
instance Storable Cl3 where
sizeOf _ = 8 * sizeOf (undefined :: Double)
alignment _ = sizeOf (undefined :: Double)
peek ptr = do
a0 <- peek (offset 0)
a1 <- peek (offset 1)
a2 <- peek (offset 2)
a3 <- peek (offset 3)
a23 <- peek (offset 4)
a31 <- peek (offset 5)
a12 <- peek (offset 6)
a123 <- peek (offset 7)
return $ APS a0 a1 a2 a3 a23 a31 a12 a123
where
offset i = (castPtr ptr :: Ptr Double) `plusPtr` (i*8)
poke ptr (toAPS -> APS a0 a1 a2 a3 a23 a31 a12 a123) = do
poke (offset 0) a0
poke (offset 1) a1
poke (offset 2) a2
poke (offset 3) a3
poke (offset 4) a23
poke (offset 5) a31
poke (offset 6) a12
poke (offset 7) a123
where
offset i = (castPtr ptr :: Ptr Double) `plusPtr` (i*8)
poke _ _ = error "Serious Issues with poke in Cl3.Storable"
instance Random Cl3 where
randomR (minAbs,maxAbs) g =
case randomR (fromEnum (minBound :: ConCl3), fromEnum (maxBound :: ConCl3)) g of
(r, g') -> case toEnum r of
ConR -> rangeR (minAbs,maxAbs) g'
ConV3 -> rangeV3 (minAbs,maxAbs) g'
ConBV -> rangeBV (minAbs,maxAbs) g'
ConI -> rangeI (minAbs,maxAbs) g'
ConPV -> rangePV (minAbs,maxAbs) g'
ConH -> rangeH (minAbs,maxAbs) g'
ConC -> rangeC (minAbs,maxAbs) g'
ConBPV -> rangeBPV (minAbs,maxAbs) g'
ConODD -> rangeODD (minAbs,maxAbs) g'
ConTPV -> rangeTPV (minAbs,maxAbs) g'
ConAPS -> rangeAPS (minAbs,maxAbs) g'
random = randomR (0,1)
data ConCl3 = ConR
| ConV3
| ConBV
| ConI
| ConPV
| ConH
| ConC
| ConBPV
| ConODD
| ConTPV
| ConAPS
deriving (Bounded, Enum)
randR :: RandomGen g => g -> (Cl3, g)
randR = rangeR (0,1)
rangeR :: RandomGen g => (Cl3, Cl3) -> g -> (Cl3, g)
rangeR = scalarHelper R
randV3 :: RandomGen g => g -> (Cl3, g)
randV3 = rangeV3 (0,1)
rangeV3 :: RandomGen g => (Cl3, Cl3) -> g -> (Cl3, g)
rangeV3 = vectorHelper V3
randBV :: RandomGen g => g -> (Cl3, g)
randBV = rangeBV (0,1)
rangeBV :: RandomGen g => (Cl3, Cl3) -> g -> (Cl3, g)
rangeBV = vectorHelper BV
randI :: RandomGen g => g -> (Cl3, g)
randI = rangeI (0,1)
rangeI :: RandomGen g => (Cl3, Cl3) -> g -> (Cl3, g)
rangeI = scalarHelper I
randPV :: RandomGen g => g -> (Cl3, g)
randPV = rangePV (0,1)
rangePV :: RandomGen g => (Cl3, Cl3) -> g -> (Cl3, g)
rangePV (lo, hi) g =
let (r, g') = rangeR (lo, hi) g
(v3, g'') = rangeV3 (lo, hi) g'
in (r + v3, g'')
randH :: RandomGen g => g -> (Cl3, g)
randH = rangeH (0,1)
rangeH :: RandomGen g => (Cl3, Cl3) -> g -> (Cl3, g)
rangeH (lo, hi) g =
let (r, g') = rangeR (lo, hi) g
(bv, g'') = rangeBV (lo, hi) g'
in (r + bv, g'')
randC :: RandomGen g => g -> (Cl3, g)
randC = rangeC (0,1)
rangeC :: RandomGen g => (Cl3, Cl3) -> g -> (Cl3, g)
rangeC (lo, hi) g =
let (r, g') = rangeR (lo, hi) g
(i, g'') = rangeI (lo, hi) g'
in (r + i, g'')
randBPV :: RandomGen g => g -> (Cl3, g)
randBPV = rangeBPV (0,1)
rangeBPV :: RandomGen g => (Cl3, Cl3) -> g -> (Cl3, g)
rangeBPV (lo, hi) g =
let (v3, g') = rangeV3 (lo, hi) g
(bv, g'') = rangeBV (lo, hi) g'
in (v3 + bv, g'')
randODD :: RandomGen g => g -> (Cl3, g)
randODD = rangeODD (0,1)
rangeODD :: RandomGen g => (Cl3, Cl3) -> g -> (Cl3, g)
rangeODD (lo, hi) g =
let (v3, g') = rangeV3 (lo, hi) g
(i, g'') = rangeI (lo, hi) g'
in (v3 + i, g'')
randTPV :: RandomGen g => g -> (Cl3, g)
randTPV = rangeTPV (0,1)
rangeTPV :: RandomGen g => (Cl3, Cl3) -> g -> (Cl3, g)
rangeTPV (lo, hi) g =
let (bv, g') = rangeBV (lo, hi) g
(i, g'') = rangeI (lo, hi) g'
in (bv + i, g'')
randAPS :: RandomGen g => g -> (Cl3, g)
randAPS = rangeAPS (0,1)
rangeAPS :: RandomGen g => (Cl3, Cl3) -> g -> (Cl3, g)
rangeAPS (lo, hi) g =
let (pv, g') = rangePV (lo, hi) g
(tpv, g'') = rangeTPV (lo, hi) g'
in (pv + tpv, g'')
randUnitV3 :: RandomGen g => g -> (Cl3, g)
randUnitV3 g =
let (theta, g') = randomR (0,pi) g
(phi, g'') = randomR (0,2*pi) g'
in (V3 (sin theta * cos phi) (sin theta * sin phi) (cos theta), g'')
randProjector :: RandomGen g => g -> (Cl3, g)
randProjector g =
let (v3, g') = randUnitV3 g
in (0.5 + 0.5 * v3, g')
randNilpotent :: RandomGen g => g -> (Cl3, g)
randNilpotent g =
let (p, g') = randProjector g
(v, g'') = randUnitV3 g'
vnormal = signum $ I (-1) * toBV ( toV3 p * v)
in (toBPV $ vnormal * p, g'')
magHelper :: RandomGen g => (Cl3, Cl3) -> g -> (Double, g)
magHelper (lo, hi) g =
let R lo' = abs lo
R hi' = abs hi
in randomR (lo', hi') g
scalarHelper :: RandomGen g => (Double -> Cl3) -> (Cl3, Cl3) -> g -> (Cl3, g)
scalarHelper con rng g =
let (mag, g') = magHelper rng g
(sign, g'') = random g'
in if sign
then (con mag, g'')
else (con (negate mag), g'')
vectorHelper :: RandomGen g => (Double -> Double -> Double -> Cl3) -> (Cl3, Cl3) -> g -> (Cl3, g)
vectorHelper con rng g =
let (mag, g') = magHelper rng g
(theta, g'') = randomR (0,pi) g'
(phi, g''') = randomR (0,2*pi) g''
in (con (mag * sin theta * cos phi) (mag * sin theta * sin phi) (mag * cos theta), g''')