Ticket #1290 (closed enhancement: fixed)
[with patch] add computationg of Rencontres numbers to Sage
| Reported by: | was | Owned by: | mhansen |
|---|---|---|---|
| Priority: | major | Milestone: | sage-2.8.15 |
| Component: | combinatorics | Keywords: | |
| Cc: | sage-combinat | Work issues: | |
| Report Upstream: | Reviewers: | ||
| Authors: | Merged in: | ||
| Dependencies: | Stopgaps: |
Description
Dan Drake posted this on sage-devel, and I reformatted it into a proper patch.
I rewrote the patch to avoid using any symbolic computation (e.g., maxima) for speed and to be correct when the input/output is very large.
Attachments
Change History
comment:1 Changed 6 years ago by jsp
See my alternative on the mailing list sage-devel: derangements = rencontres
def derangements(n, k):
if n == 0 and k == 0:
return 1
if n == 1 and k == 0:
return 0
if k == 0:
lst = [(-1)^r * binomial(n, r) * (n-r)^r * (n-r-1)^(n-r) for r in range(n)]
return sum(lst)
else:
return binomial(n, k) * derangements(n-k, 0)
Someone should check the implications!? Eventually translate it into Cython, etcetera.
Note: See
TracTickets for help on using
tickets.

