You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
prop_floorSum_negate_a (QC.NonNegative (QC.Small n)) (QC.Positive m) a b =
24
-
let does_not_overflow = (\t ->toInteger (minBound::Int64) <= t && t <=toInteger (maxBound::Int64)) (toInteger b +toInteger a * (toInteger n -1))
25
-
in does_not_overflow QC.==> floorSum n m (- a) (b + a * (n -1)) QC.=== floorSum n m a b
26
-
27
19
-- floorSum n m a b
28
20
-- n: non-negative, m: positive
29
21
floorSum::Int64->Int64->Int64->Int64->Int64
@@ -33,53 +25,34 @@ floorSum 0 m a b = 0
33
25
floorSum n 1 a b = a * comb2 n + n * b
34
26
floorSum n m a b
35
27
| a <0= floorSum n m (- a) (b + a * (n -1))
36
-
{-
28
+
{-
37
29
| a >= m || a < 0 = case a `divMod` m of
38
30
(q, a') -> q * comb2 n + floorSum n m a' b
39
31
-}
40
32
|let m2 = m `quot`2
41
33
, abs a > m2 =case (a + m2) `divMod` m of
42
-
(q, a') ->
43
-
q * comb2 n + floorSum n m (a' - m2) b
34
+
(q, a') -> q * comb2 n + floorSum n m (a' - m2) b
44
35
| b >= m || b <0=case b `divMod` m of
45
36
(q, b') -> q * n + floorSum n m a b'
46
37
| n > m =case n `quotRem` m of
47
38
(q, n') -> (q * n - comb2 (q +1) * m) * a + q * floorSum m m a b + floorSum n' m a b
48
-
--| n < 100 = fromInteger $ floorSum_naive n m a b
49
-
-- in -- fromInteger $ floorSum_naive n m a b
50
-
-- - n * t - floorSum t (- a) (- m) (- b - m) + floorSum t (- a) (- m) (b - m)
51
-
|otherwise=-- 0 < a < m, 0 <= b < m, 0 < n <= m
52
-
-- 0 < a < m
53
-
-- sum [ fromIntegral $ length [ i | i <- [0..n-1], floor ((toInteger a * toInteger i + toInteger b) % toInteger m) >= k ] | k <- [1..(floor $ (toInteger a * (toInteger n - 1) + toInteger b) % toInteger m)] ]
54
-
-- sum [ fromIntegral $ length [ i | i <- [0..n-1], i >= - floor ((- toInteger m * toInteger k + toInteger b) % toInteger a) ] | k <- [1..(floor $ (toInteger a * (toInteger n - 1) + toInteger b) % toInteger m)] ]
55
-
-- sum [ n - max 0 (- floor ((- toInteger m * toInteger k + toInteger b - toInteger m) % toInteger a)) | k <- [0..(floor $ (toInteger a * (toInteger n - 1) + toInteger b) % toInteger m) - 1] ]
39
+
|otherwise=
40
+
-- 0 < a < m, 0 <= b < m, 0 < n <= m
56
41
let t =floor ((toInteger a * (toInteger n -1) +toInteger b) %toInteger m)
57
42
in n * t + floorSum t a (- m) (b - m)
58
-
-- ceilSum (ceiling $ (a * (n - 1) + b) % m) a m (m - b)
0 commit comments