[racket] a function for a generalization of permutations for floats without going to +inf.0?
Thanks that fixed it!
On Jan 25, 2015, at 8:34 PM, Neil Toronto <neil.toronto at gmail.com> wrote:
> You can compute in log space using `log-gamma`:
>
> (define (my-permutations* n k)
> (exp (- (log-gamma (+ n 1)) (log-gamma (+ (- n k) 1)))))
>
> I wouldn't trust the last four digits or so of large results, but that may be accurate enough for what you're doing.
>
> If not, look at "math/private/flonum/flonum-factorial.rkt". I'm pretty sure you can just copy the code, remove the integer checks, and have something that works. (Test it, though.) Error should be <= 3 ulps if you do that.
>
> Neil ⊥
>
> On 01/24/2015 01:18 PM, Alexander D. Knauth wrote:
>> Is there a way to define a function for a generalization of permutations for flonums using gamma?
>> This doesn’t work because if n is >=171 and k is a float it just returns +inf.0:
>> #lang racket
>> (require math/special-functions)
>> (define (my-factorial x) (gamma (+ x 1)))
>> (define (my-permutations n k) (/ (my-factorial n) (my-factorial (- n k))))
>>
>> Is there a better way to do this without it returning +inf.0, or is there a library function anywhere that does this?
>>
>>
>>
>> ____________________
>> Racket Users list:
>> http://lists.racket-lang.org/users
>>
>
> ____________________
> Racket Users list:
> http://lists.racket-lang.org/users