Hmm... except this doesn't work for values less than 1. And that relates back to my error in thinking - I was talking in terms of ! and Roger gave me an answer in that form. But I it's lngamma which needs to support positive values - so for ! the values can be between _1 and 0.
:/ -- Raul On Fri, Jul 3, 2015 at 1:44 AM, Raul Miller <[email protected]> wrote: > Just so I can find this easily, next time I am searching for it - yes, > you are right. > > Here's a properly labeled and implemented lngamma: > > lngamma=: ^.@!@(1 | ]) + +/@:^.@(1 + 1&| + i.@<.)@<: > > Thanks, > > -- > Raul > > On Wed, Jun 10, 2015 at 5:43 PM, Jose Mario Quintana > <[email protected]> wrote: >> I would rather name lngamma as lnfactorial since, >> >> ^lngamma("0) 0 1 2 3 4 5 >> 1 1 2 6 24 120 >> >> Be that as it may, Roger’s approach is very neat as opposed to, >> >> LogFact=. ^.@:!`((((2 %~ ^. o. 2) + (-&0.5 * ^.) + -@:] + %@:(12&*)) + >> %@:(360 * ^&3) + %@:(1260 * ^&5))@:>:)@.(170&<)"0 >> >> 55 Wrap 'LogFact' >> ^.@:!`(((0.91893853320467267 + (-&0.5 * ^.) + -@:] + %@ >> :(12&*)) + %@:(360 * ^&3) + %@:(1260 * ^&5))@:>:)@.(170 >> &<)"0 >> >> However, I could not resist comparing their performance, >> >> (lngamma -: LogFact) 1111.1 >> 1 >> >> st=. (, */&.:>@:(1 2&{))@:(] ; 7!:2@:] ; 6!:2) >> >> 111 st&> 'lngamma 1111.1' ; 'LogFact 1111.1' >> ┌────────────────┬─────┬──────────┬─────────┐ >> │lngamma 1111.1│34944│3.61106e_5│1.26185 │ >> ├────────────────┼─────┼──────────┼─────────┤ >> │LogFact 1111.1│2944 │1.3729e_5 │0.0404183│ >> └────────────────┴─────┴──────────┴─────────┘ >> 111 st&> 'lngamma 11111.1' ; 'LogFact 11111.1' >> ┌────────────────┬──────┬───────────┬─────────┐ >> │lngamma 11111.1│264320│0.000197226│52.1308 │ >> ├────────────────┼──────┼───────────┼─────────┤ >> │LogFact 11111.1│2944 │5.70576e_6 │0.0167978│ >> └────────────────┴──────┴───────────┴─────────┘ >> 111 st&> 'lngamma 111111.1' ; 'LogFact 111111.1' >> ┌────────────────┬───────┬──────────┬─────────┐ >> │lngamma 111111.1│2099328│0.00184993│3883.61 │ >> ├────────────────┼───────┼──────────┼─────────┤ >> │LogFact 111111.1│2944 │5.92946e_6│0.0174563│ >> └────────────────┴───────┴──────────┴─────────┘ >> >> Nevertheless, I favor neatness over performance when posting to Rosetta >> Code. >> >> >> >> On Wed, Jun 10, 2015 at 10:24 AM, Raul Miller <[email protected]> wrote: >> >>> Ohh, that is really nice. >>> >>> Or, converted to tacit: >>> >>> lngamma=: ^.@!@(1 | ]) + +/@:^.@(1 + 1&| + i.@<.) >>> >>> Thanks! >>> >>> -- >>> Raul >>> >>> >>> On Wed, Jun 10, 2015 at 10:15 AM, Roger Hui <[email protected]> >>> wrote: >>> > For non-negative real x, !x can be computed as (!1|x)**/(1+1|x)+i.<.x, >>> > therefore ^.x is ^. of the long expression, which is >>> > (^.!1|x)++/^.(1+1|x)+i.<.x . For example: >>> > >>> > x=: 4.75 >>> > !x >>> > 78.7845 >>> > (!1|x)**/(1+1|x)+i.<.x >>> > 78.7845 >>> > >>> > ^.!x >>> > 4.36672 >>> > (^.!1|x)++/^.(1+1|x)+i.<.x >>> > 4.36672 >>> > >>> > x=: 140.23 >>> > ^.!x >>> > 556.358 >>> > (^.!1|x)++/^.(1+1|x)+i.<.x >>> > 556.358 >>> > >>> > Works for non-negative integers: >>> > >>> > x=: 10 >>> > ^.!x >>> > 15.1044 >>> > (^.!1|x)++/^.(1+1|x)+i.<.x >>> > 15.1044 >>> > >>> > x=: 0 >>> > ^.!x >>> > 0 >>> > (^.!1|x)++/^.(1+1|x)+i.<.x >>> > 0 >>> > >>> > >>> > >>> > On Wed, Jun 10, 2015 at 6:36 AM, Raul Miller <[email protected]> >>> wrote: >>> > >>> >> Yes. >>> >> >>> >> Motivation is this rosettacode task: >>> >> http://rosettacode.org/wiki/Calculate_P-Value >>> >> >>> >> Thanks, >>> >> >>> >> -- >>> >> Raul >>> >> >>> >> On Wed, Jun 10, 2015 at 9:25 AM, Roger Hui <[email protected]> >>> >> wrote: >>> >> > Can the argument be other than positive integers? >>> >> > >>> >> > On Wed, Jun 10, 2015 at 6:22 AM, Raul Miller <[email protected]> >>> >> wrote: >>> >> > >>> >> >> Does anyone have an implementation of ^.@! which will work for >>> >> >> moderately large values (like 1000)? >>> >> >> >>> >> >> Thanks, >>> >> >> >>> >> >> -- >>> >> >> Raul >>> >> >> >>> ---------------------------------------------------------------------- >>> >> >> For information about J forums see >>> http://www.jsoftware.com/forums.htm >>> >> >> >>> >> > ---------------------------------------------------------------------- >>> >> > For information about J forums see >>> http://www.jsoftware.com/forums.htm >>> >> ---------------------------------------------------------------------- >>> >> For information about J forums see http://www.jsoftware.com/forums.htm >>> >> >>> > ---------------------------------------------------------------------- >>> > For information about J forums see http://www.jsoftware.com/forums.htm >>> ---------------------------------------------------------------------- >>> For information about J forums see http://www.jsoftware.com/forums.htm >>> >> ---------------------------------------------------------------------- >> For information about J forums see http://www.jsoftware.com/forums.htm ---------------------------------------------------------------------- For information about J forums see http://www.jsoftware.com/forums.htm
