module Music.Theory.Z.Tto where
import Data.List
import Data.Maybe
import qualified Text.Parsec as P
import qualified Music.Theory.Parse as Parse
import Music.Theory.Z
data Tto t = Tto {forall t. Tto t -> t
tto_T :: t,forall t. Tto t -> t
tto_M :: t,forall t. Tto t -> Bool
tto_I :: Bool}
deriving (Tto t -> Tto t -> Bool
forall t. Eq t => Tto t -> Tto t -> Bool
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Tto t -> Tto t -> Bool
$c/= :: forall t. Eq t => Tto t -> Tto t -> Bool
== :: Tto t -> Tto t -> Bool
$c== :: forall t. Eq t => Tto t -> Tto t -> Bool
Eq,Int -> Tto t -> ShowS
forall t. Show t => Int -> Tto t -> ShowS
forall t. Show t => [Tto t] -> ShowS
forall t. Show t => Tto t -> String
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Tto t] -> ShowS
$cshowList :: forall t. Show t => [Tto t] -> ShowS
show :: Tto t -> String
$cshow :: forall t. Show t => Tto t -> String
showsPrec :: Int -> Tto t -> ShowS
$cshowsPrec :: forall t. Show t => Int -> Tto t -> ShowS
Show)
tto_identity :: Num t => Tto t
tto_identity :: forall t. Num t => Tto t
tto_identity = forall t. t -> t -> Bool -> Tto t
Tto t
0 t
1 Bool
False
tto_pp :: (Show t,Num t,Eq t) => Tto t -> String
tto_pp :: forall t. (Show t, Num t, Eq t) => Tto t -> String
tto_pp (Tto t
t t
m Bool
i) =
forall (t :: * -> *) a. Foldable t => t [a] -> [a]
concat [Char
'T' forall a. a -> [a] -> [a]
: forall a. Show a => a -> String
show t
t
,if t
m forall a. Eq a => a -> a -> Bool
== t
1 then String
"" else if t
m forall a. Eq a => a -> a -> Bool
== t
5 then String
"M" else forall a. HasCallStack => String -> a
error String
"tto_pp: M?"
,if Bool
i then String
"I" else String
""]
p_tto :: Integral t => t -> Parse.P (Tto t)
p_tto :: forall t. Integral t => t -> P (Tto t)
p_tto t
m_mul = do
Char
_ <- forall s (m :: * -> *) u.
Stream s m Char =>
Char -> ParsecT s u m Char
P.char Char
'T'
t
t <- forall i. Integral i => P i
Parse.parse_int
Bool
m <- Char -> P Bool
Parse.is_char Char
'M'
Bool
i <- Char -> P Bool
Parse.is_char Char
'I'
forall s (m :: * -> *) t u.
(Stream s m t, Show t) =>
ParsecT s u m ()
P.eof
forall (m :: * -> *) a. Monad m => a -> m a
return (forall t. t -> t -> Bool -> Tto t
Tto t
t (if Bool
m then t
m_mul else t
1) Bool
i)
tto_parse :: Integral i => i -> String -> Tto i
tto_parse :: forall i. Integral i => i -> String -> Tto i
tto_parse i
m = forall a c b. (a -> c) -> (b -> c) -> Either a b -> c
either (\ParseError
e -> forall a. HasCallStack => String -> a
error (String
"tto_parse failed\n" forall a. [a] -> [a] -> [a]
++ forall a. Show a => a -> String
show ParseError
e)) forall a. a -> a
id forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall s t a.
Stream s Identity t =>
Parsec s () a -> String -> s -> Either ParseError a
P.parse (forall t. Integral t => t -> P (Tto t)
p_tto i
m) String
""
tto_M_set :: Integral t => t -> Tto t -> Tto t
tto_M_set :: forall t. Integral t => t -> Tto t -> Tto t
tto_M_set t
m (Tto t
t t
_ Bool
i) = forall t. t -> t -> Bool -> Tto t
Tto t
t t
m Bool
i
z_tto_univ :: Integral t => t -> Z t -> [Tto t]
z_tto_univ :: forall t. Integral t => t -> Z t -> [Tto t]
z_tto_univ t
m_mul Z t
z = [forall t. t -> t -> Bool -> Tto t
Tto t
t t
m Bool
i | t
m <- [t
1,t
m_mul], Bool
i <- [Bool
False,Bool
True], t
t <- forall i. Integral i => Z i -> [i]
z_univ Z t
z]
z_tto_f :: Integral t => Z t -> Tto t -> (t -> t)
z_tto_f :: forall t. Integral t => Z t -> Tto t -> t -> t
z_tto_f Z t
z (Tto t
t t
m Bool
i) =
let i_f :: t -> t
i_f = if Bool
i then forall i. Integral i => Z i -> i -> i
z_negate Z t
z else forall a. a -> a
id
m_f :: t -> t
m_f = if t
m forall a. Eq a => a -> a -> Bool
== t
1 then forall a. a -> a
id else forall i. Integral i => Z i -> i -> i -> i
z_mul Z t
z t
m
t_f :: t -> t
t_f = if t
t forall a. Ord a => a -> a -> Bool
> t
0 then forall i. Integral i => Z i -> i -> i -> i
z_add Z t
z t
t else forall a. a -> a
id
in t -> t
t_f forall b c a. (b -> c) -> (a -> b) -> a -> c
. t -> t
m_f forall b c a. (b -> c) -> (a -> b) -> a -> c
. t -> t
i_f
z_tto_apply :: Integral t => Z t -> Tto t -> [t] -> [t]
z_tto_apply :: forall t. Integral t => Z t -> Tto t -> [t] -> [t]
z_tto_apply Z t
z Tto t
o = forall a. Eq a => [a] -> [a]
nub forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Ord a => [a] -> [a]
sort forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map (forall t. Integral t => Z t -> Tto t -> t -> t
z_tto_f Z t
z Tto t
o)
z_tto_rel :: (Ord t,Integral t) => t -> Z t -> [t] -> [t] -> [Tto t]
z_tto_rel :: forall t. (Ord t, Integral t) => t -> Z t -> [t] -> [t] -> [Tto t]
z_tto_rel t
m Z t
z [t]
x [t]
y =
let f :: Tto t -> Maybe (Tto t)
f Tto t
o = if forall t. Integral t => Z t -> Tto t -> [t] -> [t]
z_tto_apply Z t
z Tto t
o [t]
x forall a. Eq a => a -> a -> Bool
== [t]
y then forall a. a -> Maybe a
Just Tto t
o else forall a. Maybe a
Nothing
in forall a b. (a -> Maybe b) -> [a] -> [b]
mapMaybe Tto t -> Maybe (Tto t)
f (forall t. Integral t => t -> Z t -> [Tto t]
z_tto_univ t
m Z t
z)
z_pcset :: (Integral t,Ord t) => Z t -> [t] -> [t]
z_pcset :: forall t. (Integral t, Ord t) => Z t -> [t] -> [t]
z_pcset Z t
z = forall a. Eq a => [a] -> [a]
nub forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Ord a => [a] -> [a]
sort forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map (forall i. Integral i => Z i -> i -> i
z_mod Z t
z)
z_tto_tn :: Integral i => Z i -> i -> [i] -> [i]
z_tto_tn :: forall i. Integral i => Z i -> i -> [i] -> [i]
z_tto_tn Z i
z i
n = forall a. Ord a => [a] -> [a]
sort forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map (forall i. Integral i => Z i -> i -> i -> i
z_add Z i
z i
n)
z_tto_invert :: Integral i => Z i -> i -> [i] -> [i]
z_tto_invert :: forall i. Integral i => Z i -> i -> [i] -> [i]
z_tto_invert Z i
z i
n = forall a. Ord a => [a] -> [a]
sort forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map (\i
p -> forall i. Integral i => Z i -> i -> i -> i
z_sub Z i
z i
n (forall i. Integral i => Z i -> i -> i -> i
z_sub Z i
z i
p i
n))
z_tto_tni :: Integral i => Z i -> i -> [i] -> [i]
z_tto_tni :: forall i. Integral i => Z i -> i -> [i] -> [i]
z_tto_tni Z i
z i
n = forall i. Integral i => Z i -> i -> [i] -> [i]
z_tto_tn Z i
z i
n forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall i. Integral i => Z i -> i -> [i] -> [i]
z_tto_invert Z i
z i
0
z_tto_mn :: Integral i => Z i -> i -> [i] -> [i]
z_tto_mn :: forall i. Integral i => Z i -> i -> [i] -> [i]
z_tto_mn Z i
z i
n = forall a. Ord a => [a] -> [a]
sort forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a b. (a -> b) -> [a] -> [b]
map (forall i. Integral i => Z i -> i -> i -> i
z_mul Z i
z i
n)
z_tto_m5 :: Integral i => Z i -> [i] -> [i]
z_tto_m5 :: forall i. Integral i => Z i -> [i] -> [i]
z_tto_m5 Z i
z = forall i. Integral i => Z i -> i -> [i] -> [i]
z_tto_mn Z i
z i
5
z_tto_t_related_seq :: Integral i => Z i -> [i] -> [[i]]
z_tto_t_related_seq :: forall i. Integral i => Z i -> [i] -> [[i]]
z_tto_t_related_seq Z i
z [i]
p = forall a b. (a -> b) -> [a] -> [b]
map (\i
q -> forall i. Integral i => Z i -> i -> [i] -> [i]
z_tto_tn Z i
z i
q [i]
p) [i
0..i
11]
z_tto_t_related :: Integral i => Z i -> [i] -> [[i]]
z_tto_t_related :: forall i. Integral i => Z i -> [i] -> [[i]]
z_tto_t_related Z i
z = forall a. Eq a => [a] -> [a]
nub forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall i. Integral i => Z i -> [i] -> [[i]]
z_tto_t_related_seq Z i
z
z_tto_ti_related_seq :: Integral i => Z i -> [i] -> [[i]]
z_tto_ti_related_seq :: forall i. Integral i => Z i -> [i] -> [[i]]
z_tto_ti_related_seq Z i
z [i]
p = forall i. Integral i => Z i -> [i] -> [[i]]
z_tto_t_related Z i
z [i]
p forall a. [a] -> [a] -> [a]
++ forall i. Integral i => Z i -> [i] -> [[i]]
z_tto_t_related Z i
z (forall i. Integral i => Z i -> i -> [i] -> [i]
z_tto_invert Z i
z i
0 [i]
p)
z_tto_ti_related :: Integral i => Z i -> [i] -> [[i]]
z_tto_ti_related :: forall i. Integral i => Z i -> [i] -> [[i]]
z_tto_ti_related Z i
z = forall a. Eq a => [a] -> [a]
nub forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall i. Integral i => Z i -> [i] -> [[i]]
z_tto_ti_related_seq Z i
z