Changeset 7485:c3c8fc4a0411
- Timestamp:
- 11/27/07 06:43:17 (5 years ago)
- Branch:
- default
- File:
-
- 1 edited
-
sage/combinat/combinat.py (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
sage/combinat/combinat.py
r7409 r7485 193 193 194 194 from sage.interfaces.all import gap, maxima 195 from sage.rings.all import QQ, RR, ZZ 195 from sage.rings.all import QQ, RR, ZZ, RealField 196 196 from sage.rings.arith import binomial 197 197 from sage.misc.sage_eval import sage_eval … … 2536 2536 """ 2537 2537 return sage_eval(maxima.eval("bernpoly(x,%s)"%n), {'x':x}) 2538 2539 2540 def rencontres_number(n, k): 2541 r""" 2542 Returns the Rencontres number D(n,k), the number of permutations of 2543 {1, 2,..., n} with k fixed points. 2544 2545 EXAMPLES: 2546 Because 312 and 231 are the two permutations of {1, 2, 3} with 0 2547 fixed points, we have: 2548 2549 sage: rencontres_number(3,0) 2550 2 2551 2552 More examples: 2553 sage: rencontres_number(6,1) 2554 264 2555 2556 2557 REFERENCES: 2558 http://en.wikipedia.org/wiki/Rencontres_number 2559 2560 Sequence A008290 in the OEIS. 2561 2562 AUTHORS: 2563 -- Dan Drake, 2007-11-27: post to sage-devel 2564 -- William Stein, 2007-11-27: referee and clean up for inclusion in sage 2565 """ 2566 F = factorial(n - k) 2567 # Sufficient precision needed to guarantee the correct result (this is overkill somewhat) 2568 R = RealField(10*F.bits() + 53) 2569 e = R(1).exp() 2570 if (n - k) % 2 == 0: 2571 return binomial(n, k) * (F/e).ceil() 2572 else: 2573 return binomial(n, k) * (F/e).floor() 2574
Note: See TracChangeset
for help on using the changeset viewer.
