arithmetic 1.4 → 1.5
raw patch · 3 files changed
+13/−22 lines, 3 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- arithmetic.cabal +2/−2
- src/Arithmetic/Pell.hs +5/−5
- src/Test.hs +6/−15
arithmetic.cabal view
@@ -1,5 +1,5 @@ name: arithmetic-version: 1.4+version: 1.5 category: Number Theory synopsis: Natural number arithmetic license: MIT@@ -14,7 +14,7 @@ Lucas sequences, the Williams p+1 factorization method, continued fraction representations of natural number square roots, the Jacobi symbol, the Tonelli-Shanks algorithm for finding square roots modulo a prime, and- the Chakravala method for solving Pell's equation.+ the Chakravala method for solving the Pell equation. Library build-depends:
src/Arithmetic/Pell.hs view
@@ -1,6 +1,6 @@ {- | module: Arithmetic.Pell-description: Pell's equation (a^2 = n*b^2 + 1)+description: The Pell equation a^2 = n*b^2 + 1 license: MIT maintainer: Joe Leslie-Hurd <joe@gilith.com>@@ -18,7 +18,7 @@ ------------------------------------------------------------------------------- -- Using the Chakravala method to find the fundamental solution of--- Pell's equation+-- the Pell equation -- -- a^2 = n*b^2 + 1 --@@ -39,7 +39,7 @@ b' = (a + b * m) `div` k j = case Modular.divide k (Modular.negate k a) b of Just i -> i- Nothing -> error "pell: couldn't divide"+ Nothing -> error "Pell.chakravala: couldn't divide" m = minM j k sqrtN = Quadratic.rootFloor n@@ -51,7 +51,7 @@ m_1 = m_0 + k ---------------------------------------------------------------------------------- Finding all integer solutions of Pell's equation+-- Finding all integer solutions of the Pell equation ------------------------------------------------------------------------------- solutions :: Natural -> [(Natural,Natural)]@@ -68,4 +68,4 @@ solution n = case solutions n of _ : ab : _ -> ab- _ -> error "Pell's equation a^2 = n*b^2 + 1 has no nontrivial integer solution when n is square"+ _ -> error "The Pell equation a^2 = n*b^2 + 1 has no nontrivial integer solution when n is square"
src/Test.hs view
@@ -512,21 +512,12 @@ p = Polynomial.fromCoefficients r (map (Ring.fromNatural r) ps) q = Polynomial.fromCoefficients r (map (Ring.fromNatural r) (qs ++ [1])) -propPellEquation :: Natural -> Bool-propPellEquation n =- Quadratic.isSquare n || a * a == n * b * b + 1+propPellEquation :: Natural -> Natural -> Bool+propPellEquation n ip =+ a * a == n * b * b + 1 where- (a,b) = Pell.solution n--{--np = (0 :: Natural)-ps = ([] :: [Natural])-qs = ([] :: [Natural])-n = np + 2-r = Modular.ring n-p = Polynomial.fromCoefficients r (map (Ring.fromNatural r) ps)-q = Polynomial.fromCoefficients r (map (Ring.fromNatural r) (qs ++ [1]))--}+ (a,b) = Pell.solutions n !! i+ i = fromIntegral (if Quadratic.isSquare n then 0 else ip) check :: QuickCheck.Testable prop => String -> prop -> IO () check desc prop =@@ -592,5 +583,5 @@ check "Polynomial quotient remainder" propPolynomialQuotientRemainder check "Polynomial quotient remainder monic" propPolynomialQuotientRemainderMonic- check "Pell equation solution" propPellEquation+ check "Pell equation solutions" propPellEquation return ()