blob: 1e17b5747ab05a14ccc965f13bf08a7aac9999a7 (
plain)
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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
|
%%
%% This is file `binomexp.sty',
%% generated with the docstrip utility.
%%
%% The original source files were:
%%
%% binomexp.dtx (with options: `package')
%% This is a generated file.
%% Copyright (C) 2006 by David Roderick
%% This file may be distributed and/or modified under the
%% conditions of the LaTeX Project Public License, either
%% version 1.2 of this license or (at your option) any later
%% version. The latest version of this license is in:
%% http://www.latex-project.org/lppl.txt
%% and version 1.2 or later is part of all distributions of
%% LaTeX version 1999/12/01 or later.
\NeedsTeXFormat{LaTeX2e}[2005/12/01]
\ProvidesPackage{binomexp}
[2007/01/07 v1.0 My first attempt]
%% \CharacterTable
%% {Upper-case \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%% Lower-case \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%% Digits \0\1\2\3\4\5\6\7\8\9
%% Exclamation \! Double quote \" Hash (number) \#
%% Dollar \$ Percent \% Ampersand \&
%% Acute accent \' Left paren \( Right paren \)
%% Asterisk \* Plus \+ Comma \,
%% Minus \- Point \. Solidus \/
%% Colon \: Semicolon \; Less than \<
%% Equals \= Greater than \> Question mark \?
%% Commercial at \@ Left bracket \[ Backslash \\
%% Right bracket \] Circumflex \^ Underscore \_
%% Grave accent \` Left brace \{ Vertical bar \|
%% Right brace \} Tilde \~}
%%
\RequirePackage{calc,ifthen}
\newcommand\binomexp@replicate[2]{%
\ifnum#1>\z@ \expandafter\@firstofone
\else
\expandafter\@gobble
\fi
{#2\expandafter\binomexp@replicate\expandafter{\number\numexpr#1-1\relax}{#2}}%
}
\newcommand{\binomexp@call}[1]{\rule[-0.125cm]{0mm}{0.5cm}\mbox{$#1$}}
\newcounter{binomexp@up}
\newcommand{\binomexp@up}{\number\value{binomexp@up}
\addtocounter{binomexp@up}{1}}
\newcounter{binomexp@down}
\newcommand{\binomexp@down}{\number\value{binomexp@down}
\addtocounter{binomexp@down}{-1}}
\newcounter{binomexp@columns}
\newcounter{binomexp@power}
\newcounter{binomexp@pascalstart}
\newcounter{binomexp@pascalstop}
\newcounter{binomexp@emptytimes}
\newcounter{binomexp@variable1}
\newcounter{binomexp@variable2}
\newcounter{binomexp@answervar}
\newcounter{binomexp@sub}
\protect\newcommand*{\binomexp@printpascal}{
\addtocounter{binomexp@power}{1}
\expandafter\edef\csname
binomexp@morten\roman{binomexp@power}exporti\endcsname{1}
\setcounter{binomexp@sub}{2}
\setcounter{binomexp@variable1}{\numexpr\number\value{binomexp@power}+1\relax}
\whiledo{\number\numexpr\number\value{binomexp@power}+1\relax>
\value{binomexp@sub}}{
\setcounter{binomexp@variable1}{\numexpr\number\value{binomexp@sub}-1\relax}
\setcounter{binomexp@variable2}{\value{binomexp@sub}}
\setcounter{binomexp@answervar}{\number\numexpr\csname
binomexp@x\roman{binomexp@variable1}\endcsname\relax+\number\numexpr\csname
binomexp@x\roman{binomexp@variable2}\endcsname\relax}
\expandafter\edef\csname binomexp@y\roman{binomexp@sub}\endcsname
{\number\value{binomexp@answervar}}\relax
\addtocounter{binomexp@sub}{1}
}
\setcounter{binomexp@sub}{2}
\whiledo{\numexpr\number\value{binomexp@power}+1\relax>\value{binomexp@sub}}{
\setcounter{binomexp@answervar}{\number\numexpr\csname
binomexp@y\roman{binomexp@sub}\endcsname\relax}
\expandafter\edef\csname binomexp@x\roman{binomexp@sub}\endcsname
{\number\value{binomexp@answervar}}
\expandafter\edef\csname
binomexp@morten\roman{binomexp@power}export\roman{binomexp@sub}\endcsname
{\number\value{binomexp@answervar}}
\addtocounter{binomexp@sub}{1}
}
\setcounter{binomexp@variable1}
{\numexpr\number\value{binomexp@power}+1\relax}
\expandafter\edef\csname
binomexp@x\roman{binomexp@variable1}\endcsname{1}
\expandafter\edef\csname
binomexp@morten\roman{binomexp@power}export\roman{binomexp@variable1}\endcsname{1}
}
\newcommand*\binomexp@putpascal[6]{\par
\expandafter\edef\csname binomexp@xi\endcsname{1}
\expandafter\edef\csname binomexp@mortenexporti\endcsname{1}
\setcounter{binomexp@power}{0}
\setcounter{binomexp@pascalstart}{#1}
\setcounter{binomexp@pascalstop}{#2+1}
\setcounter{binomexp@emptytimes}{\value{binomexp@pascalstop}}
\whiledo{\value{binomexp@emptytimes}>1}{
\binomexp@printpascal \addtocounter{binomexp@emptytimes}{-1}
}
\setcounter{binomexp@columns}
{\numexpr\number\value{binomexp@pascalstop}+2\relax}
\begin{math} \begin{array}{@{}|c|*{\value{binomexp@columns}}{|c}|@{}}
\whiledo{\value{binomexp@pascalstart}<
\numexpr\number\value{binomexp@pascalstop}-1\relax}{
\setcounter{binomexp@up}{0}
\setcounter{binomexp@down}{\value{binomexp@pascalstart}}
\binomexp@call{(#3+#4)^{\number\numexpr\number\value{binomexp@pascalstart}\relax}}
\binomexp@replicate{\numexpr\number\value{binomexp@pascalstart}+1\relax}
{&\binomexp@call{\csname
binomexp@morten\romannumeral\numexpr\value{binomexp@pascalstart}\relax
export\romannumeral\numexpr\value{binomexp@up}+1\relax\endcsname
#5^{\binomexp@down} #6^{\binomexp@up}}}\\
\addtocounter{binomexp@pascalstart}{1}
}
\setcounter{binomexp@up}{0}
\setcounter{binomexp@down}{\value{binomexp@pascalstart}}
\binomexp@call{(#3+#4)^{\number\numexpr\number\value{binomexp@pascalstart}\relax}}
\binomexp@replicate{\numexpr\number\value{binomexp@pascalstart}+1\relax}
{&\binomexp@call{\csname
binomexp@morten\romannumeral\numexpr\value{binomexp@pascalstart}\relax
export\romannumeral\numexpr\value{binomexp@up}+1\relax\endcsname
#5^{\binomexp@down} #6^{\binomexp@up}}}
\end{array} \end{math}
}
\newcommand{\binomexp@proof}[2]{
\[ 7!=7\cdot6\cdot5\cdot4\cdot3\cdot2\cdot1 \hspace*{5em}
{#1 \choose #2} = \frac{#1!}{(#1-#2)!\cdot #2!}=
\frac{#1!}{(#1-#2)!\cdot(#1-(#1-#2))!}={#1 \choose #1-#2}
\]
\begin{eqnarray*} {#1 - 1 \choose #2 - 1} + {#1 - 1 \choose #2}
&=& \frac{(#1 - 1)!}{(#2 - 1)!\cdot[(#1 - 1) - (#2 - 1)]!} +
\frac{(#1 - 1)!}{#2!\cdot[(#1 - 1) - #2)]!}\\
&=& (#1 - 1)!\cdot\left(\frac{1}{(#2 - 1)!\cdot(#1 - #2)!} +
\frac{1}{#2!\cdot[(#1 - #2) - 1)]!}\right) \\
&=& (#1 - 1)! \cdot\frac{#2 + (#1 - #2)}{#2! (#1 - #2)!} \\
&=& \frac{#1!}{#2!(#1 - #2)!} = {#1 \choose #2}
\end{eqnarray*}
\[ \frac{#2}{#2!\cdot(#1-#2)!} = \frac{1}{(#2-1)!\cdot(#1-#2)!}
\hspace*{5em} \mbox{because} \hspace*{5em} \\
\frac{6}{6!\cdot(#1-#2)!} = \frac{1}{5!\cdot(#1-#2)!} \]
\begin{eqnarray*}
(#2 + 1)\cdot {#1 + 1 \choose #2 + 1} &=& (#2 + 1)\cdot
\frac{(#1 + 1)!}{((#2 + 1)!\cdot ((#1 + 1) - (#2 + 1))!}\\
&=& (#2 + 1)\cdot \frac{(#1 + 1)!}{(#2 + 1)!\cdot (#1 - #2)!}\\
&=& (#1 + 1)\cdot \frac{#1!}{#2!\cdot (#1 - #2)!} = (#1 + 1)\cdot
{#1 \choose #2}\\
\end{eqnarray*}
}
\endinput
%%
%% End of file `binomexp.sty'.
|