Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft of CubicSymbol #194

Merged
merged 19 commits into from
May 2, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
27feeae
Draft of CubicSymbol
federico-bongiorno Apr 11, 2020
8c7cb1e
Edited arithmoi.cabal
federico-bongiorno Apr 11, 2020
ad0d206
Extended function to all integers and defined operations for CubicSym…
federico-bongiorno Apr 12, 2020
72ce88f
Addressed comments on pattern matching
federico-bongiorno Apr 12, 2020
d08fc9f
Changed the implementation of the cubicSymbol function and added comm…
federico-bongiorno Apr 13, 2020
d9ea713
Added modular arithmetic, imported functions and error messages.
federico-bongiorno Apr 17, 2020
a05b4b6
Corrected edge cases. Simplified code by adding cubicReciprocity func…
federico-bongiorno Apr 17, 2020
97f4270
Got rid of factoriseBadPrime, changed line spacing and updated comments.
federico-bongiorno Apr 17, 2020
03b7df7
Tidied up code
federico-bongiorno Apr 17, 2020
8ab434b
Improvements to getPrimaryDecomposition function
federico-bongiorno Apr 17, 2020
4730d19
More readable code in getPrimaryDecomposition
federico-bongiorno Apr 17, 2020
eac987b
Added test to check cubicSymbol when the denominator is prime
federico-bongiorno Apr 17, 2020
0533ff6
Minor change to cubicSymbol3 test function
federico-bongiorno Apr 17, 2020
4043c6c
Helper functions return cubic symbols rather than integers
federico-bongiorno Apr 26, 2020
20ab1b8
Added symbolToNum and exponentiation. Changed extractPrimaryContribut…
federico-bongiorno Apr 26, 2020
b00093b
Updating with master
federico-bongiorno Apr 29, 2020
88a218d
Added table lookup for getPrimaryDecomposition
federico-bongiorno Apr 29, 2020
eb9e5ee
Added Haddock comments
federico-bongiorno May 2, 2020
c4ad23b
Changed comments and avoided compiler warning
federico-bongiorno May 2, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
102 changes: 102 additions & 0 deletions Math/NumberTheory/Moduli/CubicSymbol.hs
Original file line number Diff line number Diff line change
@@ -0,0 +1,102 @@
{-# LANGUAGE LambdaCase #-}

module Math.NumberTheory.Moduli.CubicSymbol
( CubicSymbol(..)
, conj
, cubicSymbol
) where

import qualified Math.NumberTheory.Quadratic.EisensteinIntegers as E
import qualified Math.NumberTheory.Primes as P
import qualified Data.Euclidean as A
import qualified Data.Semigroup as S
import qualified Data.List as L



data CubicSymbol = Zero | Omega | OmegaSquare | One deriving (Eq)

instance S.Semigroup CubicSymbol where
(<>) = multiplication

instance Show CubicSymbol where
show = \case
Zero -> show 0
Omega -> "ω"
OmegaSquare -> "ω²"
One -> show 1
federico-bongiorno marked this conversation as resolved.
Show resolved Hide resolved


multiplication :: CubicSymbol -> CubicSymbol -> CubicSymbol
multiplication Zero _ = Zero
multiplication _ Zero = Zero
multiplication One y = y
multiplication x One = x
multiplication Omega Omega = OmegaSquare
multiplication Omega OmegaSquare = One
multiplication OmegaSquare Omega = One
multiplication OmegaSquare OmegaSquare = Omega
federico-bongiorno marked this conversation as resolved.
Show resolved Hide resolved



exponentiation :: CubicSymbol -> Integer -> CubicSymbol
exponentiation Zero _ = Zero
exponentiation One _ = One
exponentiation _ 0 = One
exponentiation Omega 1 = Omega
exponentiation Omega 2 = OmegaSquare
exponentiation OmegaSquare 1 = OmegaSquare
exponentiation OmegaSquare 2 = Omega
federico-bongiorno marked this conversation as resolved.
Show resolved Hide resolved



conj :: CubicSymbol -> CubicSymbol
conj = \case
Zero -> Zero
Omega -> OmegaSquare
OmegaSquare -> Omega
One -> One

-- Converts Eisenstein integer to CubicSymbol value.
toCubicSymbol :: E.EisensteinInteger -> CubicSymbol
toCubicSymbol = \case
0 -> Zero
0 E.:+ 1 -> Omega
(-1) E.:+ (-1) -> OmegaSquare
1 -> One
federico-bongiorno marked this conversation as resolved.
Show resolved Hide resolved




cubicSymbol :: E.EisensteinInteger -> E.EisensteinInteger -> CubicSymbol
cubicSymbol alpha n = Prelude.foldr (g) One factorisation
where factorisation = P.factorise n
federico-bongiorno marked this conversation as resolved.
Show resolved Hide resolved
g factor symbol = newSymbol <> symbol
where newSymbol = primePowerCubicSymbol alpha factor



primePowerCubicSymbol :: E.EisensteinInteger -> (P.Prime E.EisensteinInteger, Word) -> CubicSymbol
primePowerCubicSymbol alpha (primeNumber, wordExponent) = exponentiation symbol remainder
where remainder = exponent `rem` 3
exponent = Prelude.fromIntegral wordExponent
symbol = primeCubicSymbol alpha prime
prime = P.unPrime primeNumber


primeCubicSymbol :: E.EisensteinInteger -> E.EisensteinInteger -> CubicSymbol
primeCubicSymbol alpha prime
-- Check whether @prime@ satifies norm and primality conditions.
| primeNorm == 3 = error "This Eisenstein number is not coprime to 3."
-- Return 0 if @prime@ divides @alpha@
| otherwise = toCubicSymbol residue

-- A.rem returns the remainder of the Euclidean algorithm.
where primeNorm = E.norm prime
residue = Prelude.foldr (f) 1 listOfAlphas
f = \x y -> A.rem (x * y) prime
-- The function @take@ does not accept Integer values.
federico-bongiorno marked this conversation as resolved.
Show resolved Hide resolved
listOfAlphas = L.genericReplicate alphaExponent alpha
-- Exponent is defined to be 1/3*(@primeNorm@ - 1).
alphaExponent = primeNorm `div` 3

1 change: 1 addition & 0 deletions arithmoi.cabal
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ library
Math.NumberTheory.Moduli
Math.NumberTheory.Moduli.Chinese
Math.NumberTheory.Moduli.Class
Math.NumberTheory.Moduli.CubicSymbol
Math.NumberTheory.Moduli.DiscreteLogarithm
Math.NumberTheory.Moduli.Equations
Math.NumberTheory.Moduli.Jacobi
Expand Down