-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathfactorial.html
More file actions
87 lines (77 loc) · 4.44 KB
/
Copy pathfactorial.html
File metadata and controls
87 lines (77 loc) · 4.44 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/template.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>VPython Help</title>
<!-- InstanceEndEditable -->
<!-- InstanceBeginEditable name="head" -->
<link href="VisualRef.css" rel="stylesheet" type="text/css" />
<!-- InstanceEndEditable -->
<script type="text/javascript">
<!--
function MM_jumpMenu(targ,selObj,restore){ //v3.0
eval(targ+".location='"+selObj.options[selObj.selectedIndex].value+"'");
if (restore) selObj.selectedIndex=0;
}
//-->
</script>
<link href="VPythonDocs/VisualRef.css" rel="stylesheet" type="text/css" />
</head>
<body>
<table width="800" border="0" cellpadding="1" cellspacing="0">
<!--DWLayoutDefaultTable-->
<tr>
<td width="10" valign="top" bgcolor="#FFFFFF"><!--DWLayoutEmptyCell--> </td>
<td width="10" height="272" valign="top" bgcolor="#DDDDDD"><p> </p> </td>
<td width="173" valign="top" bgcolor="#DDDDDD"><p class="Normal"><a href="index.html">Home</a></p>
<p class="Normal">If you're new to Python <br />
and VPython: <a href="VisualIntro.html">Introduction</a></p>
<p class="Normal">A VPython <a href="VPython_Intro.pdf" target="_blank">tutorial</a></p>
<p class="Normal"><a href="primitives.html">Pictures</a> of 3D objects</p>
<p><select id="menu1" onchange="jumpMenu(this)"></select></p>
<p><select id="menu2" onchange="jumpMenu(this)"></select></p>
<p><select id="menu3" onchange="jumpMenu(this)"></select></p>
<p class="Normal"><a href="new_features.html">What's new</a></p>
<p class="Normal"><a href="http://vpython.org" target="_blank">Classic VPython web site</a><br />
<a href="license.txt" target="_blank">VPython license</a><br />
<a href="http://www.python.org" target="_blank">Python web site</a> <br /></p></td>
<td width="21" valign="top" bgcolor="#FFFFFF"><!--DWLayoutEmptyCell--> </td>
<td width="586" rowspan="2" valign="top"><!-- InstanceBeginEditable name="content" -->
<div>
<h1 class="Heading-1"> <font color="#0000A0">The factorial and combin Functions</font></h1>
</div>
<div>
<div>
<p class="program"> print(factorial(4)) # gives 24 <br />
print(combin(10,2)) # gives 45 </p>
<p class="Normal"><span class="program">The factorial function factorial(N)
is N!; 4! is (4)(3)(2)(1) = 24, and 0! is defined to be 1.<br />
The combin function is combin(a,b) = a!/(b!*(a-b)!)</span>.</p>
<p class="Normal">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 <span class="attribute">factorial(5)</span> =
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). </p>
<p class="Normal">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 <span class="attribute">combin(5,2)</span> = 5!/(3!*2!) = 10.</p>
<p class="Normal">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, <span class="attribute">combin(5,2)</span> = 5!/(3!*2!)
= (5*4)/(2*1) = (2.5*4) = 10, and we didn't have to evaluate any of the factorials fully.</p>
</div>
</div>
<div> </div>
<!-- InstanceEndEditable --></td>
</tr>
<tr>
<td height="16" colspan="4"></td>
</tr>
</table>
</body>
<script type="text/javascript" language="javascript" src="navigation.js"></script>
<!-- InstanceEnd --></html>