15 from __future__
import division
16 from __future__
import print_function
19 VERSION =
'numbernone --- 2010 March 16'
31 ou None si x ou y == None
33 Pre: x: Number ou None
36 Result: Number ou None
39 assert isinstance(x, numbers.Number)
or (x ==
None), x
40 assert isinstance(y, numbers.Number)
or (y ==
None), y
42 return (x + y
if (x !=
None)
and (y !=
None)
49 ou None si x ou y == None ou y == 0
51 Pre: x: Number ou None
54 Result: Number ou None
57 assert isinstance(x, numbers.Number)
or (x ==
None), x
58 assert isinstance(y, numbers.Number)
or (y ==
None), y
60 return (x / y
if (x !=
None)
and (y !=
None)
and (y != 0)
66 """Renvoie divmod(x, y)
67 ou None si x ou y == None ou y == 0
72 Result: (Real ou None, Real ou None)
75 assert isinstance(x, numbers.Real)
or (x ==
None), x
76 assert isinstance(y, numbers.Real)
or (y ==
None), y
78 return (x.__divmod__(y)
if (x !=
None)
and (y !=
None)
and (y != 0)
84 """Renvoie la kème puissance factorielle descendante de x
85 == x * (x - 1) * (x - 2) * ... * (x - k + 1)
88 Pre: x: Number ou None
91 Result: Number ou None
94 assert isinstance(x, numbers.Number)
or (x ==
None), x
95 assert isinstance(k, numbers.Integral)
or (k ==
None), k
97 if (x !=
None)
and (k !=
None):
115 ou None si x == None ou 0
117 Pre: x: Number ou None
119 Result: Number ou None
122 assert isinstance(x, numbers.Number)
or (x ==
None), x
124 return (1/x
if (x !=
None)
and (x != 0)
131 ou None si x ou y == None ou y == 0
133 Pre: x: Number ou None
136 Result: Number ou None
139 assert isinstance(x, numbers.Number)
or (x ==
None), x
140 assert isinstance(y, numbers.Number)
or (y ==
None), y
142 return (
mod(x, y)
if (x !=
None)
and (y !=
None)
and (y != 0)
149 ou None si x ou y == None
151 Pre: x: Number ou None
154 Result: Number ou None
157 assert isinstance(x, numbers.Number)
or (x ==
None), x
158 assert isinstance(y, numbers.Number)
or (y ==
None), y
160 return (x*y
if (x !=
None)
and (y !=
None)
169 Pre: x: Number ou None
171 Result: Number ou None
174 assert isinstance(x, numbers.Number)
or (x ==
None), x
176 return (-x
if x !=
None
182 """Renvoie la kème puissance factorielle montante de x
183 == x * (x + 1) * (x + 2) * ... * (x + k - 1)
184 ou None si non défini
186 Pre: x: Number ou None
189 Result: Number ou None
192 assert isinstance(x, numbers.Number)
or (x ==
None), x
193 assert isinstance(k, numbers.Integral)
or (k ==
None), k
195 if (x !=
None)
and (k !=
None):
213 ou None si x ou y == None
215 Pre: x: Number ou None
218 Result: Number ou None
221 assert isinstance(x, numbers.Number)
or (x ==
None), x
222 assert isinstance(y, numbers.Number)
or (y ==
None), y
224 return (x - y
if (x !=
None)
and (y !=
None)
232 if __name__ ==
'__main__':
242 debug.test_begin(VERSION, __debug__)
244 print(
'add()...', end=
''); sys.stdout.flush()
246 print(
'ok'); sys.stdout.flush()
249 print(
'div()...', end=
''); sys.stdout.flush()
251 print(
'ok'); sys.stdout.flush()
254 print(
'divmod()...', end=
''); sys.stdout.flush()
258 print(
'ok'); sys.stdout.flush()
261 print(
'falling_factorial_pow()...', end=
''); sys.stdout.flush()
263 for n
in range(1000):
276 for k
in range(1, 100):
278 for k
in range(1, 20):
279 for n
in range(k, min(100, int(pow(bit32.MERSENNE32, 1/k)) + 3)):
281 == math.factorial(n)//math.factorial(n - k), \
282 (n, k, math.factorial(n + k - 1)//math.factorial(n - 1),
285 print(
'ok'); sys.stdout.flush()
288 print(
'inv()...', end=
''); sys.stdout.flush()
290 print(
'ok'); sys.stdout.flush()
293 print(
'mod()...', end=
''); sys.stdout.flush()
295 print(
'ok'); sys.stdout.flush()
298 print(
'mul()...', end=
''); sys.stdout.flush()
300 print(
'ok'); sys.stdout.flush()
303 print(
'neg()...', end=
''); sys.stdout.flush()
305 print(
'ok'); sys.stdout.flush()
308 print(
'rising_factorial_pow()...', end=
''); sys.stdout.flush()
310 for n
in range(2000):
321 for k
in range(1, 20):
323 for n
in range(1, min(100, int(pow(bit32.MERSENNE32, 1/k) - k + 4))):
325 == math.factorial(n + k - 1)//math.factorial(n - 1), \
326 (n, math.factorial(n + k - 1)//math.factorial(n - 1),
329 print(
'ok'); sys.stdout.flush()
332 print(
'sub()...', end=
''); sys.stdout.flush()
334 print(
'ok'); sys.stdout.flush()