-
Notifications
You must be signed in to change notification settings - Fork 41
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
Dirichlet characters #180
Dirichlet characters #180
Conversation
I would probably just dump its internal representation, but no strong opinion here.
Not realy. Too many layers and new newtypes make users struggle. However, you can probably define |
I would consider using overlapping instances significantly worse, since this extension can lead to incoherence. I think I'll just avoid a Show instance altogether. |
Actually I think it is possible to avoid -- | RootOfUnity m :: RootOfUnity n represents \(e^{2 \pi i m / \phi(n)}\).
newtype RootOfUnity n = RootOfUnity Integer
deriving (Eq)
instance KnownNat n => Show (RootOfUnity n) where
show (RootOfUnity m) = "e^(" ++ show (numerator r) ++ "πi/" ++ show (denominator r) ++ ")"
where
r = 2 * m % totient (natVal (Proxy :: Proxy n))
toComplex :: Floating a => SFactors Integer n -> RootOfUnity n -> Complex a
toComplex fact (RootOfUnity m) = cis (2 * pi * m / d)
where
d = runFunctionOnFactors totientA (unSFactors fact)
evaluate :: DirichletCharacter n -> MultMod n -> RootOfUnity n
evaluate = undefined (I do not mean this to be done in this branch) |
Overall a very nice code. I really appreciate the amount of work and engineering. |
This would work but it would mean RootOfUnity isn't the ideal name and we cannot represent cubic residues... I attempted a few other versions of this module which would be more typed, but they turned out to be awkward to use - you can see some attempts in my wip branch. I opted instead for a version without putting much on type level, but with tests that it all works (using validChar) instead |
24ec5bf
to
dd57b43
Compare
I've added Here's a list of improvements that can be turned into issues after merge.
data DirichletError = UnderSpecified | OverSpecified | InvalidValues
fromTable :: forall n. KnownNat n => Vector (OrZero RootOfUnity) -> Either DirichletError (DirichletCharacter n)
The following aren't directly related to characters, but they came up while working on this.
reduceMod :: forall a b. (KnownNat a, KnownNat b) => Mod (a*b) -> (Mod a, Mod b)
reduceMod (Mod n) = (fromIntegral n, fromIntegral n)
reduceMult :: forall a b. (KnownNat a, KnownNat b) => MultMod (a*b) -> (MultMod a, MultMod b)
reduceMult (MultMod n) = (MultMod a, MultMod b)
where (a,b) = reduceMod n |
Great job, thanks for your efforts and time!
I'd probably go for fromTable :: forall n. KnownNat n => (Mod n -> OrZero RootOfUnity) -> DirichletCharacter n
fromTable f = undefined such that
That's a good point.
I think there are enough helpers for a user willing to implement it himself, so this is of a low priority probably.
What exactly do you have in mind?
This could make a nice addition to https://github.com/Bodigrim/mod |
I don't think this makes much of a difference; besides
This is what I'd quickly guessed earlier, though I don't doubt something better exists chineseCoprimeList :: (Eq a, Ring a, Euclidean a) => [(a, a)] -> Maybe a
chineseCoprimeList xs = fmap fst $ foldM (\x y -> fmap (,snd x `times` snd y) (chineseCoprime x y)) (zero, one) xs |
M.NT.Moduli.Internal
module, fordiscreteLogarithmPP
andisPrimitiveRoot'
, so we can work with these internally without needing to useCyclicGroup
.Template
a while ago, but since thenSFactors
was introduced - this can be adapted to make a nicer version ofTemplate
. It's unclear ifTemplate
should have the modulus on type level though, consideringinduced
might be easier to write without that. Edit: This turned out to be a bad idea, due to the reason mentioned.isPrimitive