- abs(x), valore assoluto
- pi, 3.14159….
- asin(x), arcoseno
- acos(x), arcocoseno
- atan(x), arcotangente
- atan2(y,x), angolo la cui tangente è y/x
- exp(x), e elevato alla x
- log(x), logaritmo naturale, in base e
- con log(x)/log(10), si ottiene il logaritmo in base 10
- pow(x,y), x elevato alla y
- sqrt(x), radice quadrata
- ceil(x), round up to nearest integer
- floor(x), round down to nearest integer
- round(x), round to nearest integer
- max(x,y,z, …), the largest of x,y,z
- min(x,y,z, …), the smallest of x,y,z
- random(), pseudorandom number 0 to 1
- factorial(x), x! = x*(x-1)*(x-2)….(1)
- combin(x,y), x!/(y!*(x-y)!)
- degrees(x), conversione in gradi, di radianti
- radians(x), conversione in radianti, di gradi
print(factorial(4)) # gives 24
print(combin(10,2)) # gives 45
The factorial function factorial(N) is N!; 4! is (4)(3)(2)(1) = 24, and 0! is defined to be 1.
The combin function is combin(a,b) = a!/(b!*(a-b)!).
A major use of these functions is in calculating the number of ways of arranging a group of objects. For example, if there are 5 numbered balls in a sack, there are factorial(5) = 5! = 5*4*3*2*1 = 120 ways of taking them sequentially out of the sack (5 possibilities for the first ball, 4 for the next, and so on).
If on the other hand the 5 balls are not numbered, but 2 are green and 3 are red, of the 120 ways of picking the balls there are 2! indistinguishable ways of arranging the green balls and 3! ways of arranging the red balls, so the number of different arrangements of the balls is combin(5,2) = 5!/(3!*2!) = 10.
Logically, the combin function is just a combination of factorial functions. However, cancellations in the numerator and denominator make it possible to evaluate the combin function for values of its arguments that would overflow the factorial function, due to the limited size of floating-point numbers. For example, combin(5,2) = 5!/(3!*2!) = (5*4)/(2*1) = (2.5*4) = 10, and we didn’t have to evaluate any of the factorials fully.