Bodigrim / arithmoi

Number theory: primes, arithmetic functions, modular computations, special sequences
http://hackage.haskell.org/package/arithmoi
MIT License
147 stars 40 forks source link

Draft of CubicSymbol #194

Closed federico-bongiorno closed 4 years ago

federico-bongiorno commented 4 years ago

This draft pull request is addressing Step 1 of the issue #155 (Cubic reciprocity law) To be addressed:

Bodigrim commented 4 years ago

Could you please rebase your branch atop of master? I pushed some improvements to M.NT.Q.EisensteinIntegers. I switched getPrimaryDecomposition to return CubicSymbol and do not experience any significant slowdown.

@@ -96,8 +96,7 @@ cubicReciprocity alpha beta = cubicSymbolHelper beta alpha
 extractPrimaryContributions :: EisensteinInteger -> EisensteinInteger -> (EisensteinInteger, EisensteinInteger, CubicSymbol)
 extractPrimaryContributions alpha beta = (gamma, delta, newSymbol)
   where
-    newSymbol = stimes contribution Omega
-    contribution = j*m - i*m -i*n
+    newSymbol = stimes (j * m) Omega <> stimes (- m - n) i
     m :+ n = A.quot (delta - 1) 3
     (i, gamma) = getPrimaryDecomposition alphaThreeFree
     (_, delta) = getPrimaryDecomposition beta
@@ -111,12 +110,12 @@ extractPrimaryContributions alpha beta = (gamma, delta, newSymbol)
 -- Eisenstein number @factor@ such that @(1 + ω)^powerUnit * e = 1 + 3*factor@.
 -- Note that L.findIndex cannot return Nothing. This happens only if @e@ is not
 -- coprime with 3. This cannot happen since @U.splitOff@ is called just before.
-getPrimaryDecomposition :: EisensteinInteger -> (Integer, EisensteinInteger)
+getPrimaryDecomposition :: EisensteinInteger -> (CubicSymbol, EisensteinInteger)
 -- This is the case where a common factor between @alpha@ and @beta@ is detected.
 -- In this instance @cubicReciprocity@ will return @Zero@.
 -- Strictly speaking, this is not a primary decomposition.
-getPrimaryDecomposition 0 = (0, 0)
-getPrimaryDecomposition e = (toInteger powerUnit, factor)
+getPrimaryDecomposition 0 = (Zero, 0)
+getPrimaryDecomposition e = (stimes powerUnit Omega, factor)
   where
     factor = unit * e
     unit = (1 + ω)^powerUnit
Bodigrim commented 4 years ago

Looks great! Please write haddock comments to the exported enitities and ensure that they are correctly rendered (stack haddock). You can use LaTeX (https://haskell-haddock.readthedocs.io/en/latest/markup.html#mathematics-latex).

Bodigrim commented 4 years ago

Merged, thanks for your efforts!