Last active
September 21, 2020 02:24
-
-
Save ConnorBaker/7c886234fabd6498b3b257beb19c5ee4 to your computer and use it in GitHub Desktop.
Find cyclic subgroups of finite order of groups with integer elements under modular multiplication
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| {-# LANGUAGE RecordWildCards #-} | |
| module Main where | |
| data Solution = Solution | |
| { remainder :: Integer | |
| , element :: Integer | |
| , power :: Integer | |
| } | |
| instance Show Solution where | |
| show Solution{..} = (show remainder) | |
| ++ " = " | |
| ++ (show element) | |
| ++ "^{" ++ (show power) ++ "}" | |
| cyclic :: (Integer -> Integer -> Integer) -- Group operation | |
| -> Integer -- Identity of the group | |
| -> Integer -- Element of group | |
| -> [Solution] | |
| cyclic op i e = map (uncurry (flip Solution e)) values | |
| where | |
| pows = iterate (\(rem, y) -> ((rem `op` e), y + 1)) (e, 1) | |
| values = takeWhileInclusive ((i /=) . fst) pows | |
| takeWhileInclusive :: (a -> Bool) -- Predicate | |
| -> [a] -- Input | |
| -> [a] -- Output | |
| takeWhileInclusive p = foldr (\ x acc -> x : if p x then acc else []) [] | |
| main :: IO () | |
| main = do | |
| putStrLn "hello world" |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated so it takes an arbitrary function for the group.
In the first version, for
U(14)you'd doNow you do