Here are some ways we defined n! using just Python:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
It's good to understand how these definitions work.
If you understand a little programming, you will be able to use Sage much more effectively.
However, Sage also has stuff like ! built in:
|
|
Same for _nP_r and _nC_r.
Here are some ways we expressed them using pure Python:
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
However, Sage already contains a function binomial that returns a binomial coefficient:
|
|
We can easily tell Sage that we'd like to substitute C for binomial:
|
|
|
|
And now we can define P in terms of C using the fact that _nP_r = _nC_r \cdot r! :
|
|
|
|
|
|
|
|
|
|
Here's another cool way to create Pascal's triangle using pure Python:
|
|
|
|
Sage also has the functions Permutations and Combinations that are worth exploring:
|
|
|
|
|
|
|
|
|
|
|
|
[[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [2, 1], [2, 3], [2, 4], [2, 5], [2, 6], [3, 1], [3, 2], [3, 4], [3, 5], [3, 6], [4, 1], [4, 2], [4, 3], [4, 5], [4, 6], [5, 1], [5, 2], [5, 3], [5, 4], [5, 6], [6, 1], [6, 2], [6, 3], [6, 4], [6, 5]] [[1, 2], [1, 3], [1, 4], [1, 5], [1, 6], [2, 1], [2, 3], [2, 4], [2, 5], [2, 6], [3, 1], [3, 2], [3, 4], [3, 5], [3, 6], [4, 1], [4, 2], [4, 3], [4, 5], [4, 6], [5, 1], [5, 2], [5, 3], [5, 4], [5, 6], [6, 1], [6, 2], [6, 3], [6, 4], [6, 5]] |
30 30 |
[3, 4, 5, 6, 7, 3, 5, 6, 7, 8, 4, 5, 7, 8, 9, 5, 6, 7, 9, 10, 6, 7, 8, 9, 11, 7, 8, 9, 10, 11] [3, 4, 5, 6, 7, 3, 5, 6, 7, 8, 4, 5, 7, 8, 9, 5, 6, 7, 9, 10, 6, 7, 8, 9, 11, 7, 8, 9, 10, 11] |
|
|