Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

REAL WORLD SCHEME DETECTED

Name: Anonymous 2010-11-15 5:04

http://nand.net/~demaria/comphum.html

million.txt - Ever wonder what 21000000 equals? Thanks to the power of scheme, you can see what this absurdly big number equals (warning, its(sic) approximately 300,000 digits long and thus makes this a rather large text file of 300K).

Name: Anonymous 2010-11-15 5:34

>Approximate running time: 6 hours 30 minutes
>4/8/98

ha-ha. oh wow.

Name: Anonymous 2010-11-15 5:40

It's probably the SICP version of expt anyway.

Name: Anonymous 2010-11-15 5:43

U MENA HASKAL

Name: Anonymous 2010-11-15 7:54

wow. one line of "real" code. impressive.

Name: Anonymous 2010-11-15 13:47

`>implying i can't just do that in my head using simple math tricks and magnets

Name: Anonymous 2010-11-15 13:50

That's a little line of code for a scheme, one giant leap for toy languages.

Name: Anonymous 2010-11-15 20:43

Scheming Scheme-writing Schemers

Name: Anonymous 2010-11-16 1:10

The problem is simple enough if you imagine the number in base 2, you don't even need a computer for this.

SBCL also handles this rather fast:

CL-USER> (time (expt 2 1000000))
Evaluation took:
  0.000 seconds of real time
  0.000000 seconds of total run time (0.000000 user, 0.000000 system)
  100.00% CPU
  954 processor cycles
  0 bytes consed
 
9900656...(omitted due to size)

While I haven't checked why this is so, I believe it might be because (expt constant constant) gets inlined by the compiler... Upon checked (seconds later) with a disassembler, it seems I was right, the number is indeed inlined at compile-time, and compile-time itself was very fast - this is probably not very surprising because 2**x is just a bignum shift (as optimized by the compiler), and the only time-consuming part would be printing the number in base 10 (as opposed to its internal byte representation).


CL-USER> (lambda () (expt 2 1000000))
; disassembly for (LAMBDA ())
; 23EBBD56:       8B1528BDEB23     MOV EDX, [#x23EBBD28]      ; 9900656229295898250697923616...(omitted due to size)
;       5C:       8BE5             MOV ESP, EBP
;       5E:       F8               CLC
;       5F:       5D               POP EBP
;       60:       C3               RET

The actual partitioning of the runtime vs compile-time costs:

CL-USER> (time (compile nil '(lambda () (expt 2 1000000))))
Evaluation took:
  0.000 seconds of real time
  0.000000 seconds of total run time (0.000000 user, 0.000000 system)
  100.00% CPU
  1 lambda converted
  4,308,273 processor cycles
  282,400 bytes consed
 
#<FUNCTION (LAMBDA ()) {248A0695}>
NIL
NIL

CL-USER> (time (progn (funcall #<FUNCTION (LAMBDA ()) {248A0695}>) nil))
Evaluation took:
  0.000 seconds of real time
  0.000000 seconds of total run time (0.000000 user, 0.000000 system)
  100.00% CPU
  1,305 processor cycles
  0 bytes consed

As you can see, the cost of actually generating the code (and included bignum) and returning it are small as expected. What about the cost of printing it to base 10?


CL-USER> (time (print (funcall #<FUNCTION (LAMBDA ()) {248A0695}>) (make-broadcast-stream)))

Evaluation took:
  6.359 seconds of real time
  6.359375 seconds of total run time (6.359375 user, 0.000000 system)
  100.00% CPU
  15,285,317,868 processor cycles
  6,585,920 bytes consed
 
990065622929589825069792361630190325073362424178...

Obviously a bit more costly. Emacs itself also takes a bit to display the number as it is being sent through SLIME.

Name: Anonymous 2010-11-16 15:05

>>9
More of this.

Name: Anonymous 2010-11-16 15:53

$ python timeit.py -n 1 '2 ** 1000000'
1 loops, best of 3: 0 usec per loop

$ python timeit.py -n 1 -r 1 'print 2 ** 1000000'
...
1 loops, best of 1: 36.2 sec per loop

Name: Anonymous 2010-11-16 16:00

>>11
Out of curiosity, how long does it take to print it in hexadecimal?

Name: Anonymous 2010-11-16 16:33

>>12
$ python timeit.py -n 1 'print hex(2 ** 1000000)'
...000L
1 loops, best of 3: 62.2 msec per loop

Name: Anonymous 2010-11-16 17:18

Here comes Haskal!


% cat anus.hs
main = print $ 2 ^ 1000000
% ghc --make anus.hs
[1 of 1] Compiling Main             ( anus.hs, anus.o )
Linking anus ...
% time ./anus > anus.txt
./anus > anus.txt  0.32s user 0.01s system 99% cpu 0.335 total

Name: Anonymous 2010-11-16 17:50

$ perl -d:DProf -Mbignum -e 'print 2**100000'
<some heug ass number>

$ dprofpp tmon.out
Total Elapsed Time =  18.8014 Seconds
  User+System Time =  17.5614 Seconds
Exclusive Times
%Time ExclSec CumulS #Calls sec/call Csec/c  Name
 98.6   17.33 17.330     22   0.7877 0.7877  Math::BigInt::Calc::_mul_use_div
 0.68   0.120  0.183      1   0.1196 0.1834  bignum::import
 0.23   0.040  0.048      7   0.0057 0.0069  Math::BigInt::FastCalc::BEGIN
 0.11   0.020  0.020      1   0.0200 0.0200  Math::BigInt::Calc::_str
 0.06   0.010  0.010      1   0.0100 0.0099  overload::BEGIN
 0.06   0.010  0.010      6   0.0017 0.0016  Exporter::as_heavy
 0.06   0.010  0.202      1   0.0098 0.2023  main::BEGIN
 0.06   0.010  0.009     12   0.0008 0.0008  Math::BigInt::Calc::BEGIN
 0.06   0.010  0.010     42   0.0002 0.0002  strict::bits
 0.00       - -0.000      1        -      -  Math::BigInt::FastCalc::_is_zero
 0.00       - -0.000      1        -      -  Math::BigInt::round
 0.00       - -0.000      1        -      -  Math::BigInt::_register_callback
 0.00       - -0.000      1        -      -  Math::BigInt::modify
 0.00       - -0.000      1        -      -  version::(bool
 0.00       - -0.000      1        -      -  version::(cmp

Name: Anonymous 2010-11-16 17:52

oh mis-read it...2^1000000 not the 2^100000 I had
well fuck me running

Name: Anonymous 2010-11-17 1:23

>>1
I already know it looks like, a 1 with 100000 zeros after it.

Name: Anonymous 2010-11-17 1:54

>>15

Really now... in ruby I get 16.108s, and part of that is spent writing to the hard drive (I had it written to a file, not printed to the screen). Your processor must suck.

Name: Ruby on !FailsRenrQ 2010-11-17 1:59

>>18
Try with Ruby on Fails

Name: Anonymous 2010-11-17 2:02

>>19

I know Ruby, I do not know Rails.

Also, can someone give me an estimate of the size of factorial(1000000)?

Name: Anonymous 2010-11-17 2:15

>>20
1.7 MB of ram and still computing.

Name: >>21 2010-11-17 2:40

1.9 MB, I gave up.

Name: Anonymous 2010-11-17 5:24

>>20
It's around 1000000!

Name: Anonymous 2010-11-17 5:59

>>20
Each multiplication adds about 5.5 digits on average (you'd think it's more like 3, but note that there are 9 times more 6-digit numbers in the 1M range than all other combined).

So somewhere between 5 and 6 millions decimal digits.

Name: Anonymous 2010-11-17 6:04

>>20
forget it, it's NP-complete

Name: Anonymous 2010-11-17 6:10

>>20
it's over INT_MAX.

Name: Anonymous 2010-11-17 7:27

>>20
it's over INT_MAXOVER 9000

Name: Anonymous 2010-11-17 7:27

It's over INT_MAAAAAAAAAAAAAAAAAAAAAAAAX!!

Name: Anonymous 2010-11-17 7:37

*grabs scouter*

Name: Anonymous 2010-11-17 11:23

>>29
That wasn't my scouter. But you can still grab it.

Name: Anonymous 2010-11-17 17:56

You can do that in VB.NET too. Just write a class that re-implements the basic math operators with string-representations of numbers. Then calculate 2^1000000. You can even create the numbers with a factory, so that if the number can fit within 32 bits, only a regular number is created.
<>

Name: Anonymous 2010-11-17 19:18

Prelude> let a = 2^1000000
(0.02 secs, 4284884 bytes)
Prelude> a
<a lot of numbers>
(2.94 secs, 440502500 bytes)

:3~

Name: Anonymous 2010-11-18 1:53

Prelude> let a = 2^1000000
*** Exception: stack overflow

Name: Anonymous 2010-11-18 4:51

Prelude> let a = 2^1000000
I shalln't.

Name: Anonymous 2010-11-18 7:47

>>34
I prefer using the contraction, shan't.

Name: Anonymous 2010-11-18 8:07

>>35
I hope you contract a painful disease that has a side effect of making you realise how to use the comma.

Name: Anonymous 2010-11-18 9:25

>>36
*coma

Name: Anonymous 2010-11-18 9:50

>>36
( ≖‿≖)

Name: Anonymous 2010-11-18 10:02

>>36

Do you type won't as willn't?

Name: Anonymous 2010-11-18 11:35

>>39
I don't and I shan't

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List