The number of $3$-sets chosen from a $10$-set, ${10 \choose 3}$.
The coefficients of an expansion of $(a+b)^n$.
All of the coefficients.
A Python dictionary, indexed by powers of the two variables in the expansion.
Tote up all of these binomial coefficients, to get $2^{10}$. (Size of the power set, or the result of setting $a=1$ and $b=1$).
Actual subsets of size 3 from a $10$-set; one way to understand a binomial coefficient.
sub
is a generator
. We can list the possibilities.
We can iterate over sub
.
$C_n = \frac{1}{n+1}{2n \choose n} = \frac{(2n)!}{(n+1)!\,n!}$
In honor of Eric Temple Bell.
Number of partitions of a set into disjoint non-empty sets.
Stirling numbers come in two flavors, first
and second
, or cycle
and subset
. We'll demonstrate the first.
The number of permutations on $n$ symbols (in cycle notation) having exactly $k$ cycles, $\left\{n\atop k\right\}$.
Now we get the trivial cycles. List length is what we want.
Collect all permutations with 3 cycles.
How many?
Sage was born of necessity to do number theory.
Factor 50-digit number ($\approx$166 bits).
Euler $\phi$ function. (totient
function.)
Integers less than $100$ and relatively prime to $100$. (Note the srange
function to generate Sage integers.)
Fact: $\displaystyle\sum_{d\mid n}\,\phi(d) = n$
Proof: Group the fractions, $\displaystyle\frac{i}{n}$, $0\leq i\leq n-1$, by denominators once written in reduced terms.
You need to declare symbolic variables (except x
comes pre-defined). That done, summations simplify as expected.
We'll recognize this result if we factor.
Arbitrarily complicated polynomials as summands can be simplified.
We can convert this symbolic expression to a callable function.
And call it --- thus making $n$ concrete.
Straightforward to plot a discrete function, we will plot using an expression.
Numbers of certain objects can sometimes be counted by recurrence relations. We would like closed-form expressions for terms of sequences defined this way.
Perrin Sequence:
$p(0) = 3$; $p(1) = 0$; $p(2)=2$
$p(n) = p(n-2) + p(n-3)$
Looks like the Fibonacci sequence, but skips back
two terms, not one.
Compute by hand: $3, 0, 2, 3, 2, 5, 5, 7, 10, 12, 17, \dots$
This is in Sloane's Online Encyclopedia of Integer Sequences as sequence number A001608.
A brute-force approach with a Python function. Impractical above about $n=50$.
Fact: If $q$ is prime, then $q$ divides $p(q)$.
(First composite number that behaves this way is $521^2$.)
Generating function: $f(x)=\displaystyle\sum_{i=0}^\infty\,p_i\,x^i$
Theory gives easy computation for Perrin sequence, denominator comes from recurrence relation, numerator is simple polynomial multiplication. $$f(x) = \frac{3-x^2}{1-x^2-x^3}$$
We can expand $f$ as a Taylor series.
Partial Fractions can simplify a rational generating function.
$a(0)=7$; $a(1)=41$; $a(2)=204$
$a(n) = 7a(n-1) - 12a(n-2) + 10a(n-3)$
Generating function --- the rational function:
Check $h(3)$:
Create partial fraction decomposition and examine the pieces:
SymPy is a pure Python package included in Sage, but not integrated with Sage.
http://docs.sympy.org/dev/modules/solvers/solvers.html#recurrence-equtions (sic)
Import pieces of the SymPy library.
Define the recurrence as an expression in $a(\cdot)$ that equals zero.
And solve:
DEMONSTRATION: Modifying Sage source code.
catalan_number()
SAGE_ROOT/devel/sage/sage/combinat/combinat.py
print "Hello, UVic!"
to def catalan_number():
./sage -b
at SAGE_ROOT
./sage
at SAGE_ROOT
./sage -t SAGE_ROOT/devel/sage/sage/combinat/
This worksheet available at: http://buzzard.ups.edu/talks.html