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
Copy file name to clipboardExpand all lines: src/Math-Numerical/Integer.extension.st
+30-48Lines changed: 30 additions & 48 deletions
Original file line number
Diff line number
Diff line change
@@ -1,59 +1,41 @@
1
1
Extension { #name : #Integer }
2
2
3
3
{ #category : #'*Math-Numerical' }
4
-
Integer>> findNK [
5
-
" Reverse binomial coefficient. Answer a <Collection> with all n and k such that n take: k = self. Elements in the answered Collection should be read as paired. Each pair represents (n,k) in the binomial coefficient formula.
6
-
See https://math.stackexchange.com/a/103385/205 for details. "
ifFalse: [^selferror:'Attempt to compute the Gamma function of a non-positive integer'].
7
+
^ (self-1) factorial.
30
8
]
31
9
32
10
{ #category : #'*Math-Numerical' }
33
-
Integer>>firstOver: c [
34
-
" Binary search to find smallest value of n for which n ** self >= c "
35
-
| nlohimid |
36
-
37
-
n :=1.
38
-
[ (n **self) < c ] whileTrue: [ n := n *2 ].
39
-
lo :=1.
40
-
hi := n.
41
-
[ (hi - lo) >1 ] whileTrue: [
42
-
mid := lo + ((hi - lo) /2) ceiling.
43
-
(mid **self) < c
44
-
ifTrue: [ lo := mid ]
45
-
ifFalse: [ hi := mid ] ].
46
-
[ (hi **self) >= c ] assert.
47
-
[ ((hi -1) **self) < c ] assert.
48
-
^ hi
11
+
Integer>> inverseBinomialCoefficient [
49
12
50
-
]
13
+
" Reverse binomial coefficient. Answer a <Collection> with all n and k such that n take: k = self. Elements in the answered Collection should be read as paired. Each pair represents (n,k) in the binomial coefficient formula.
14
+
See https://math.stackexchange.com/a/103385/205 for details. "
51
15
52
-
{ #category : #'*Math-Numerical' }
53
-
Integer>> gamma [
54
-
self>0
55
-
ifFalse: [^selferror:'Attempt to compute the Gamma function of a non-positive integer'].
0 commit comments