1
0
mirror of https://github.com/golang/go synced 2024-11-06 08:16:11 -07:00

math/big: remove underscores from Binomial docs

Change-Id: I7605bcbbaa64bb4273ad458a157b1c6011467973
Reviewed-on: https://go-review.googlesource.com/c/go/+/447915
Run-TryBot: Ian Lance Taylor <iant@google.com>
Reviewed-by: Robert Griesemer <gri@google.com>
Reviewed-by: Ian Lance Taylor <iant@google.com>
Auto-Submit: Ian Lance Taylor <iant@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
This commit is contained in:
Eric Lagergren 2022-11-03 23:13:37 -07:00 committed by Gopher Robot
parent e6f662d7b0
commit 9860faa512

View File

@ -206,13 +206,13 @@ func (z *Int) MulRange(a, b int64) *Int {
} }
// Binomial sets z to the binomial coefficient C(n, k) and returns z. // Binomial sets z to the binomial coefficient C(n, k) and returns z.
func (z *Int) Binomial(n_, k_ int64) *Int { func (z *Int) Binomial(n, k int64) *Int {
if k_ > n_ { if k > n {
return z.SetInt64(0) return z.SetInt64(0)
} }
// reduce the number of multiplications by reducing k // reduce the number of multiplications by reducing k
if k_ > n_-k_ { if k > n-k {
k_ = n_ - k_ // C(n, k) == C(n, n-k) k = n - k // C(n, k) == C(n, n-k)
} }
// C(n, k) == n * (n-1) * ... * (n-k+1) / k * (k-1) * ... * 1 // C(n, k) == n * (n-1) * ... * (n-k+1) / k * (k-1) * ... * 1
// == n * (n-1) * ... * (n-k+1) / 1 * (1+1) * ... * k // == n * (n-1) * ... * (n-k+1) / 1 * (1+1) * ... * k
@ -235,12 +235,12 @@ func (z *Int) Binomial(n_, k_ int64) *Int {
// i++ // i++
// z /= i // z /= i
// } // }
var n, k, i, t Int var N, K, i, t Int
n.SetInt64(n_) N.SetInt64(n)
k.SetInt64(k_) K.SetInt64(k)
z.Set(intOne) z.Set(intOne)
for i.Cmp(&k) < 0 { for i.Cmp(&K) < 0 {
z.Mul(z, t.Sub(&n, &i)) z.Mul(z, t.Sub(&N, &i))
i.Add(&i, intOne) i.Add(&i, intOne)
z.Quo(z, &i) z.Quo(z, &i)
} }