Permutations and Combinations

Description

The following Sage interact computes

(1)
\begin{align} _n P_r = \frac{n!}{(n - r)!} \quad \text{and} \quad _n C_r = \frac{n!}{r!(n - r)!}. \end{align}

The default values are $n = 5$ and $r = 2$.

Sage Cell

Code

@interact
def _(n = input_box(default=5), r=input_box(default=2)):
    P = factorial(n)/factorial(n - r)
    C = P/factorial(r)
    pretty_print(html(r"$n = %s$" %n))
    pretty_print(html(r"$r = %s$" %latex(r)))
    pretty_print(html(r"${}_n P_r  = %s$" % latex(P)))
    pretty_print(html(r"${}_n C_r  = %s$" %latex(C)))

Options

None

Tags

Primary Tags: interacts, combinatorics

Secondary Tags: permutations, combinations

Related Cells

None

Attribute

Permalink:

Author: T. Judson

Date: 21 Jul 2017 08:20

Submitted by: Tom Judson

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License