The main reason for speed difference is that big integer calculation in
Haskell is based on the GNU Multiple Precision Arithmetic Library
(/GMP/), much faster than J's extended precision number calculation.
Op 2-9-2015 om 02:32 schreef Jon Hough:
In this talk https://www.youtube.com/watch?v=ap
Thanks for the feedback, everyone!
Next time I do one of these, I'll post the script before I film it.
I didn't know about (or remember?) the volutions article.
I just threw the code together in a couple minutes, and thought it would
make a fun video for J outsiders.
On Tue, Sep 1, 2015 at 3:11
But of course, J is GPL'd now, so it's now legal to use GMP in J.
Someone's still going to need to do the integration work, of course...
(And it may very well be that that will expose some difficult corner cases.)
--
Raul
On Wed, Sep 2, 2015 at 3:50 AM, aai wrote:
> The main reason for speed
Essays
http://www.jsoftware.com/jwiki/Essays/Fibonacci%20Sequence
Fibonacci numbers by matrix product:
A=:2 2$1 1 1 2
mp=:+/ .*
mp~A
2 3
3 5
mp~^:4 x:A
1346269 2178309
2178309 3524578
Then multiply specific matrices to find a particular Fibonacci number.
From Wolfram Alpha the en
Yes, the Jwiki verb f7 using a binary power method is fast
and quite compact. (My own version, twice as slow as f7 for
some reason, has two current 2x2 matrices, so presumably
needs to store 8 extended integers at a time; the final
number is about 2^33 (!), so even 8 such integers will
u
In Julia (from my console):
julia> fib(n) = ([big(1) 1; 1 0]^n)[1,2]
fib (generic function with 1 method)
julia> @time x=fib(475000);
elapsed time: 1.389054075 seconds (120836244 bytes allocated, 2.44% gc time)
julia>
Julia implements BigInt using GMP so it is really fast. It trades
space for
Oh I missed f7. I think I gave up after f4, assuming the ones after that were
mathematical curiosities and notsuitable for big numbers. f7 is pretty fast. I
got 8.3 seconds on my Ubuntu (32-bit) PC.
> Date: Wed, 2 Sep 2015 15:56:33 +0100
> From: mike_liz@tiscali.co.uk
> To: programm...@jsof
On Wed, Sep 2, 2015 at 10:56 AM, Mike Day wrote:
> The Haskell implementation must be really tight, though.
> Rademacher talks about lazy evaluation, but his function
> _appears_ to employ a list of all prior Fibonacci numbers
> to produce the required element. I suppose the zip and
> tail func
part of J8 is openssl libeay on windows, and I believe its either also
distributed or presumed on other platforms. It includes a BN library. As a
start,
I need some help with the code below. after loading (windows 64 j802),
a =. dec2bn 1231231144 NB. looks ok.
┌──┬───┬──┐
│10
Here's another one that mimics the zip/tail from the talk
fib=: [: {. [: _2&{. [: ([: +/"1 [: (}: ,. }.) 1,1,]) / [: i. 1&-
Slow though:
timespacex 'fib 1000'
0.0179245 59648
timespacex 'fib 1'
0.638343 919808
I killed it after an hour running 475000
You can play with it with t
On Wed, Sep 2, 2015 at 1:17 PM, 'Pascal Jasmin' via Programming
> sslp =: IFWIN pick '';'D:\OpenSSL-Win64\bin\'
I don't have that directory on any of my machines.
This probably belongs in some other thread, also?
Thanks,
--
Raul
-
Actually, the tacit version seems to be faster for relatively small
arguments. First allow me to rewrite fib1
fib2 and your expression as verbs working with extended precision and
producing the yth Fibonacci number:
fib1 =:1x"_`(($:@:<:) + ($:@:-&2))@.(2&<)M.
fib2 =: 3 : 0
x1 =. x:1
x2 =. x
Even without the rep. squaring in J of f7a the Haskell version is ~ 33x
faster in the GHCi interpreter. If you want to check it yourself I'll
e-mail you the Haskell code (to avoid remarks of Raul).
Op 2-9-2015 om 20:03 schreef Jose Mario Quintana:
Actually, the tacit version seems to be faster
J does seem very awfully slow in executing, e.g., fib3 475000. On my iMac, that
gives a timing of over 38 seconds.
By contrast -- and to the extent that the timers involved can reasonably be
compared -- on the same system, running the Wolfram Language looping definition
fib[n_] := Module[{f
I've had a look at forsub this afternoon. I've cribbed Raul's
pre-factoring by
the matrix-diagonal, but otherwise they're my own ideas. Nothing out of
the ordinary, but fairly concise. "J-like"? - perhaps.
NB. these both assume that #x = #y
NB. Thunderbird will probably spoil the appeara
rethreading, to address Raul's comment, the first line in old thread was
harmless and reassigned following it, but removed here.
part of J8 is openssl libeay on windows, and I believe its either also
distributed or presumed on other platforms. It includes a BN library. As a
start,
I need so
On Wed, Sep 2, 2015 at 3:17 PM, Mike Day wrote:
> nicely concise. I feel there's a closed form hiding in there
> somewhere, to replace the explicit loop, but haven't found
> it yet!
baksub looks like it could be done using u/\. but forsub would have to
be some sort of u/&|.\ expression.
--
Ra
On Wed, Sep 2, 2015 at 3:28 PM, 'Pascal Jasmin' via Programming
wrote:
> I don't really know what gets returned yet, but what is worrysome is that
> repeated calls return slightly different values.
This crashes J
bn2dec a
So it's wrong, and if you get a result at all you shouldn't be
surpris
Some additional timings on my machine and comparison to MIcroJ
In J:
fib3=. ({: @:(({: , +/)@:]^:(2-~[))&1 1x) NB. For y >: 3!
6!:2 'fib3 475000'
60.7922
NB. fib test
fibtest =: 3 : 0
x1 =. 1x
x2 =. 1x
c =. 0
while. c < (y-2) do.
tmp =. x1
x1 =. x2
x2 =. tmp
That is a big factor but perhaps it is not quite a surprise to some members
of this forum. Yes, I would like to see the Haskell version please; thanks
in advance.
It seems that if one wants to play with "arbitrary precision arithmetic,
operating on signed integers, rational numbers, and floating-
GMP has some (I think minor) performance improvements over openssl BN, but
openssl is already being distributed with J. Doesn't that seem like a
reasonable candidate?
- Original Message -
From: Jose Mario Quintana
To: Programming forum
Cc:
Sent: Wednesday, September 2, 2015 4:53 PM
> > BN_dec2bn (called above) actually has a pointer to pointer first argument
> > (**BIGNUM). Is there something special I have to do in the function
> > signature, or when calling? I'm pretending its just a pointer.
> Pointer to a pointer means you need to put the pointer somewhere and
get
Pace Raul, I'll post this here as it compares a J verb's speed with
yet another Haskell fib function, and is arguably relevant to thoughts
about efficient implementations of exact integer calculations in
our language of choice. I don't really want to learn Haskell
Google easily leads to a
I think most of your prototypes are incorrect. Since BIGNUM is opaque and
you only have to deal with BIGNUM* so that you can use x for all BIGNUM*,
consequently *x for BIGNUM**, also int is i in both 32 and 64-bìt.
revise your prototypes and try something similar to
NB. BIGNUM *BN_new(void);
vbn=.
I don't follow the J list as much as I should, but noticed Joe's
examination of his portfolio holdings. I've been fooling around with
futures data, and had need for some interest rates and have the
beginnings of a useful verb for querying quandl. The only thing you need
to set is the apitoken.
thank you Bill, things are working will post results later.
- Original Message -
From: bill lam
To: Programming forum
Cc:
Sent: Wednesday, September 2, 2015 7:51 PM
Subject: Re: [Jprogramming] BigNum library from openssl
I think most of your prototypes are incorrect. Since BIGNUM is o
26 matches
Mail list logo