diff --git a/Package.resolved b/Package.resolved index f023a454..ae347fa3 100644 --- a/Package.resolved +++ b/Package.resolved @@ -1,13 +1,13 @@ { - "originHash" : "97a30c267f45840228fa0cbec6f6118fe33a73655d21926935400d86da3d5b87", + "originHash" : "00f869e23177fe695dd8283cb0093109907f008463129cf1e765a22549e2a3cb", "pins" : [ { "identity" : "hdrhistogram-swift", "kind" : "remoteSourceControl", "location" : "https://github.com/HdrHistogram/hdrhistogram-swift", "state" : { - "revision" : "a69fa24d7b70421870cafa86340ece900489e17e", - "version" : "0.1.2" + "revision" : "93a1618c8aa20f6a521a9da656a3e0591889e9dc", + "version" : "0.1.3" } }, { @@ -15,8 +15,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/ordo-one/package-benchmark", "state" : { - "revision" : "51fffb6bc58bcbaca9c1954e6e52b56f3c9c2d54", - "version" : "1.27.4" + "revision" : "ec06262cf296aaa4bd40ed654ccdf9a87fe1879f", + "version" : "1.29.2" } }, { @@ -33,8 +33,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-algorithms", "state" : { - "revision" : "f6919dfc309e7f1b56224378b11e28bab5bccc42", - "version" : "1.2.0" + "revision" : "87e50f483c54e6efd60e885f7f5aa946cee68023", + "version" : "1.2.1" } }, { @@ -51,8 +51,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-asn1.git", "state" : { - "revision" : "7faebca1ea4f9aaf0cda1cef7c43aecd2311ddf6", - "version" : "1.3.0" + "revision" : "ae33e5941bb88d88538d0a6b19ca0b01e6c76dcf", + "version" : "1.3.1" } }, { @@ -69,8 +69,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-crypto.git", "state" : { - "revision" : "ff0f781cf7c6a22d52957e50b104f5768b50c779", - "version" : "3.10.0" + "revision" : "45305d32cfb830faebcaa9a7aea66ad342637518", + "version" : "3.11.1" } }, { @@ -105,8 +105,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-numerics", "state" : { - "revision" : "0a5bc04095a675662cf24757cc0640aa2204253b", - "version" : "1.0.2" + "revision" : "e0ec0f5f3af6f3e4d5e7a19d2af26b481acb6ba8", + "version" : "1.0.3" } }, { @@ -114,8 +114,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-protobuf", "state" : { - "revision" : "ebc7251dd5b37f627c93698e4374084d98409633", - "version" : "1.28.2" + "revision" : "d72aed98f8253ec1aa9ea1141e28150f408cf17f", + "version" : "1.29.0" } }, { @@ -123,8 +123,8 @@ "kind" : "remoteSourceControl", "location" : "https://github.com/apple/swift-system", "state" : { - "revision" : "c8a44d836fe7913603e246acab7c528c2e780168", - "version" : "1.4.0" + "revision" : "a34201439c74b53f0fd71ef11741af7e7caf01e1", + "version" : "1.4.2" } }, { diff --git a/Sources/TestUtilities/TestUtilities.swift b/Sources/TestUtilities/TestUtilities.swift index dfde285a..90f122ab 100644 --- a/Sources/TestUtilities/TestUtilities.swift +++ b/Sources/TestUtilities/TestUtilities.swift @@ -151,20 +151,31 @@ extension TestUtils { return perm(n: n, k: k) / mult(1...k) } - /// Returns the expected number of bins with "count" balls, assuming - /// a total of "num_balls" balls each assigned to a uniform random bin - /// among "num_bins" bins. + /// Count the expected number of bins with a target count, assuming balls each assigned to a uniform random bin. + /// - Parameters: + /// - binCount: Number of bins. + /// - ballCount: Number of balls. + /// - count: Target number of balls in a bin. + /// - Returns: the expected number of bins with `count` balls. package static func expectedBallsInBinsCount(binCount: Int, ballCount: Int, count: Int) -> Double { // Pr(ballCount in first bin == count) let n = ballCount let k = count let p = 1 / Double(binCount) - let q = 1.0 - p let binomialCoefficient = binomialCoefficient(n: n, k: k) + + func binomialPow(_ base: Double, _ exponent: Double) -> Double { + // 0^0 set to be 1 + if base.isZero, exponent.isZero { + 1.0 + } else { + Double.pow(base, exponent) + } + } + // Probability mass function of binomial distribution - let probabilityOfExactlyCountBallsInFirstBin = binomialCoefficient * Double.pow(p, Double(k)) * Double.pow( - q, - Double(n - k)) + let scalingFactor = binomialPow(p, Double(k)) * binomialPow(1.0 - p, Double(n - k)) + let probabilityOfExactlyCountBallsInFirstBin = binomialCoefficient * scalingFactor // Linearity of expectation return Double(binCount) * probabilityOfExactlyCountBallsInFirstBin } diff --git a/swift-homomorphic-encryption-protobuf b/swift-homomorphic-encryption-protobuf index e043f0dc..e2fcb506 160000 --- a/swift-homomorphic-encryption-protobuf +++ b/swift-homomorphic-encryption-protobuf @@ -1 +1 @@ -Subproject commit e043f0dc6f223be5a48930f38d39a10bb5e6e5f9 +Subproject commit e2fcb506442719d00b11914ebe6e85779c5b5b4c