jlouis has quit [Read error: 110 (Connection timed out)]
<mwc>
so I was thinking about how Ocaml doesn't seem to have a lot of libraries (compared to say Java, Perl, Python)
<mwc>
which may be a reason why it's not more widely used
<mwc>
this was discussed here a few nights ago or so
<mwc>
is it maybe that the library structure of ocaml isn't amenable to extension? Would it be more useful if Ocaml 4.0 featured a new standard library that was more extensible
<mwc>
say the IO classes used by Extlib/Netlib/Camomille
<mwc>
thoughts?
<psnively>
I hear that a lot, and honestly, I don't find it to be an issue.
<psnively>
Having said that, it'd be nice to have something more closely approximating, e.g. SML's Standard Basis in its structure.
<psnively>
But lack of libraries hasn't stopped me from using OCaml successfully for my purposes.
evn_ has joined #ocaml
m3ga has quit [Read error: 113 (No route to host)]
evn_ has quit []
psnively has quit []
goalieca has joined #ocaml
<Ramzi>
yay. i just helped someone with ocaml. i'm paying it forward
<Ramzi>
he's all like, I have m and n as ints, and I'm going to pass it to a function that uses the ^ operator on m and n. what's the deal.
<Ramzi>
and i'm like. ocaml thinks m and n are strings, and he's like, but they're ints.
<thelema>
Ramzi:good job.
<thelema>
mwc:interested in helping me extend ocaml's stdlib?
ulfdoz has quit [brown.freenode.net irc.freenode.net]
yminsky has quit [brown.freenode.net irc.freenode.net]
bzzbzz has quit [brown.freenode.net irc.freenode.net]
szell has quit [brown.freenode.net irc.freenode.net]
netx has quit [brown.freenode.net irc.freenode.net]
seafood has quit [brown.freenode.net irc.freenode.net]
Dazhbog has quit [brown.freenode.net irc.freenode.net]
Naked has quit [brown.freenode.net irc.freenode.net]
qwr has quit [brown.freenode.net irc.freenode.net]
flux has quit [brown.freenode.net irc.freenode.net]
TSC` has quit [brown.freenode.net irc.freenode.net]
authentic has quit [brown.freenode.net irc.freenode.net]
coucou747 has quit [brown.freenode.net irc.freenode.net]
l_a_m has quit [brown.freenode.net irc.freenode.net]
donny has quit [brown.freenode.net irc.freenode.net]
svenl has quit [brown.freenode.net irc.freenode.net]
dwmw2_gone has quit [brown.freenode.net irc.freenode.net]
Ugarte has quit [brown.freenode.net irc.freenode.net]
guyzmo has quit [brown.freenode.net irc.freenode.net]
shortcircuit has quit [brown.freenode.net irc.freenode.net]
<Ramzi>
that should give the number of primes less than 10,000 right?
<thelema>
Ramzi: I think the problem was to find the 10,001th prime, no?
<Ramzi>
nvm, i think i caught my mistake. i'm on 187
<Ramzi>
it's easy but i wanted to do the whole problem in codepad without breaking out an ide
* thelema
is working backwards from 188 too
<Ramzi>
hah, yeah, right. that's what i'm doing...
<Ramzi>
wanna do 187 together?
<thelema>
187 seems pretty straightforward - for each int 1--10^8, factor it, and count the factors
<Ramzi>
no no no no that's terrible
<thelema>
generating numbers by multiplying pairs of factors seems a poor way of doing things.
<Ramzi>
factoring is an expensive process.
<thelema>
well, maybe not...
<thelema>
yeah, but 10^8 isn't that big. And factoring isn't that expensive on smaller numbers.
<Ramzi>
so we can approximate the number of primes less than 10^8
<Ramzi>
about 1085
<Ramzi>
according to the prime counting function.
<thelema>
alternate algorithm: for each prime <10^4 (sqrt 10^8), count all multiples of it, except for larger-prime mulitples.
<Ramzi>
so now, the number of pairs you can check is... 1085/2 * (1085+1)
<Ramzi>
Or about 500,000 pairs
<Ramzi>
So 5*10^5 checks is a lot faster than 1*10^8 checks
<Ramzi>
hmm...
<thelema>
what are you checking?
<Ramzi>
i'm reading your alternate algo
<Ramzi>
but i just finished explaining why your first algo was bad
<Ramzi>
this alternate algo was what i had in mind with the c code i pasted
<thelema>
my first algorithm is inefficient, but don't forget how cheap CPU time is.
<Ramzi>
you see that i already had 10^4 in mind
<Ramzi>
i almost want you to code your first way to see how long it takes
* thelema
can and will.
<Ramzi>
wait, let's reason
<Ramzi>
you're going to do 10^8 factorings.
<Ramzi>
If factoring is constant, let's say it takes 1 microsecond.
<thelema>
100 seconds.
<Ramzi>
So your code will take 10^2 seconds. hmm, eh
<Ramzi>
i still suspect it'd take longer.
<Ramzi>
i wonder what the average number of divisors from 2 to 10,000 is
<Ramzi>
no, i mean, 10^8 is
<thelema>
could be calculated pretty easily
<Ramzi>
if it's like 5, then your 100 seconds turns into 500 seconds really fast.
<Ramzi>
you can't calculate the average number of divisors without first doing factoring anyway! lol, we don't want to have to solve the problem in order to solve the problem.
<Ramzi>
that is, it will take you as long to find the average number of divisors as it will to factor from 2 to 10^8 in the first place.
* thelema
is just fine factoring every number 2--10^8
<Ramzi>
alright. code it and tell me how long it takes
* thelema
breaks stack with a non-tail-recursive generator for 1..n
* thelema
realizes that a for loop works well.
<thelema>
1 min 7 seconds for ... 1.1 million factorizations. (including a bunch of file IO to write their factorizations to a file.)
<thelema>
ick, and way too little buffering - flushing stdout each time I write a factor.
<thelema>
(and this is bytecode even)
<thelema>
still about the same - 55 sec for about 1.1 million factorizations
<Ramzi>
why do the io stuff
palomer_ has joined #ocaml
<thelema>
1)because that's what my program did before, 2) so I can keep track of how far it got pretty easily.
<Ramzi>
but it's not going to give you an accurate estimation of the time
<thelema>
I can drop it, and just count, but if I'm going to do that, I might as well handicap the factorization by having it stop once it hits the second factor, and print something special if it's done.
<thelema>
s/print something special/return true/
<Ramzi>
i just coded a solution in ruby which gave me the same wrong answer as my c solution
<thelema>
Ramzi: just counting primes 1..10000?
<Ramzi>
no
<Ramzi>
then taking each pair and checking if their product is less
<Ramzi>
it gives the right answer for < 30, which is the one they use in the problem description
<Ramzi>
do you know ruby?
<thelema>
not well. it's not sufficient to count only those combinations - what about 2 * 10001?
<thelema>
(assuming 100001 is prime)
<Ramzi>
hmm...
<Ramzi>
why did you propose 10^4 then, in your alternate algo?
<thelema>
once both factors >10^4, you're done.
<Ramzi>
yeah, but as you just mention, one factor can be > 10^4
<Ramzi>
so you have to generate all primes less than (10^8)/2
<thelema>
and then for the first p, count how many primes are less than 10^8/p
<thelema>
and do so for each p up to 10^4
<thelema>
how many primes between p and 10^8/p
<Ramzi>
that doesn't have an elegant summing formula.
<Ramzi>
and this is breaking my idea of doing the whole thing in codepad.
<thelema>
Make an array with 10^8 elements, x -> # of primes less than x. then counting primes cones down to subtracting the values at two indices.
<thelema>
err, 10^8/2
<Ramzi>
what're you working on?
hsuh has quit [Remote closed the connection]
<thelema>
stopping factorizing at 2 factors.
adu has joined #ocaml
palomer has quit [Read error: 110 (Connection timed out)]
<Ramzi>
do you know mathematica?
<thelema>
Iused to - it's been forever since I've used it.
<Ramzi>
do you know how to make a list and push elements onto it?
<thelema>
Ramzi: in mathematica? sorry.
<Ramzi>
i've gone through C, ruby, and mathematica. i think it's time for java
<Ramzi>
i really like the collections framework of java
<thelema>
I admit it's well made.
<Ramzi>
although mathematica had cool stuff like PrimeQ[] and Divisors[]
<Ramzi>
I couldn't figure out how to make a damn array
<Ramzi>
I feel if I learned mathematica it would be the best for a lot of these project euler problems.
<thelema>
1.1 million 2-composites counted
<thelema>
1.4 million in 2:36
<Ramzi>
you know PE has a rule that code shouldn't take more than a minute to run
<thelema>
yeah, I guess this is cheating a bit.
adu has left #ocaml []
<thelema>
I'll get to work on the counting primes.
zkincaid has left #ocaml []
<Ramzi>
alright, it's clear we need a better algo
<Ramzi>
if you produce all the primes less than (10^8)/2, that's around 800k primes
<Ramzi>
and then to check the pairs is the sum from 1 to 800k.
|Catch22| has quit []
<thelema>
got it!
<thelema>
with my counting primes algorithm.
<Ramzi>
huh wha
<Ramzi>
what was the algo again
<thelema>
for each prime factor 1..10000, I even know how many 2-composites have that as a factor.
<thelema>
step 1: sieve of erasthenes 1..10^8
<thelema>
step 2: rewrite that array with counts of how many primes < i
<thelema>
step 3: count prime combinations using that array.
<thelema>
maybe the first two steps could get combined, but that'd only save iterating over the first 10,000 elements of the array - I imagine running the counts all the way out takes the most time.
<thelema>
nope, 31 cpu seconds to sieve, 9.2 cpu seconds to gen the counts, and 0.024 seconds to count prime pairs.
<Ramzi>
so you sieve on 1E8, which does not take long. Then you count the number of primes <=i for all i. Wait a minute, doesn't the count take 10^8 operations?
<Ramzi>
at least
<thelema>
the sieve takes much more than 10^8 operations.
<Ramzi>
that is, for 10^8 numbers, you need to count how many primes are less than it.
<Ramzi>
so if "count()" is 1 unit of time, you have to do that 10^8 times
<Ramzi>
that is, make 10^8 memory writes
<thelema>
let c = ref 0 in
<thelema>
for i = 2 to upto-1 do
<thelema>
if arr.(i) != 0 then incr c;
<thelema>
arr.(i) <- !c;
<thelema>
done;
<Ramzi>
how they hell can you do 10^8 memory writes in 7s?
<thelema>
actually, my processor did 10^8 memory writes in .488 seconds - 7s was bytecode
<Ramzi>
if you have an array of 10^8 integers, this is 100mb of RAM provided you used 1 byte ints
<thelema>
no, these are standard ocaml ints - 64 bits = 8 bytes on my machine.
<Ramzi>
do you have 800mb of RAM?
<thelema>
I have 2GB
<thelema>
and it seems ocaml is happy taking a big chunk of it.
<thelema>
well, you only have a 32-bit processor...
<thelema>
you could get away with 1/2 the size of the array.
<thelema>
the max index used by the counting bit is only 50000000
<thelema>
only 4 indices > 10,000,000 get checked.
<Ramzi>
hmm...
<Ramzi>
so first, i know there are no primes greater than 10^8/2
<Ramzi>
so this cuts my mem usage in half
<Ramzi>
but how would i know that only 4 indices > 10,000 checked
<Ramzi>
you meant 10,000, i assume
<Ramzi>
or not.
<thelema>
no, I meant 10 million - only 2, 3, 5, and 7 need to do lookups on values > 10 million
<thelema>
p: 2 d: 50000000 count: 3001134
<thelema>
p: 3 d: 33333333 count: 2050942
<thelema>
p: 5 d: 20000000 count: 1270605
<thelema>
p: 7 d: 14285714 count: 927429
<thelema>
p: 11 d: 9090909 count: 608109
<Ramzi>
so this is more of a "research solution"
<Ramzi>
if i paid close attention, i'd realize i could cut the array by a factor of 10
<thelema>
it's a fat-ram solution. I believe mathematica has some faster way of calculating # primes < p -- I don't know what that method is.
<Ramzi>
if i had an array of only 10m
<Ramzi>
how would I get the counts
<Ramzi>
for 50000000, 3333333,
<thelema>
that I don't know.
<Ramzi>
how many 2-comps have 2 as a factor...
<Ramzi>
counting again would take too long?
<Ramzi>
i feel like there should be a simple way that i'm not seeing. but as it stands your solution requires 200mb ram
<Ramzi>
and i'm really surprised you can do that many mem writes that fast
<thelema>
200 million writes/second @ 1.6GHz = 8 cycles per write. not bad.
<thelema>
sustained.
<Ramzi>
well, congratulations.
<thelema>
yay ocaml. I'll take a look at the asm to see how it did it.
<Ramzi>
i wonder if there's a better way
<Ramzi>
thelema: my school has release tests for code
<Ramzi>
i'm failing one of the test, and it could refer to any of 4 functions
<thelema>
okay, what's the test?
<Ramzi>
i'm pretty sure the 4 are right and i tested them exhaustively.
<Ramzi>
i don't know. it doesn't say anything more than, "a test on one of the four functions failed"
<thelema>
okay, paste the 4
<Ramzi>
this is where Smerdyakov's proof checking would come in handy
<thelema>
only if your program description could unambiguously be turned into an exact description of what's needed (which is usually equivalent to writing the program right)
<Ramzi>
thelema: i'm actually a little uncomfortable posting full solutions in here. what if someone else from the class is here
<thelema>
unlikely, but fair enough.
<Ramzi>
this is why i asked if you had aim earlier
<Ramzi>
sent
<thelema>
itob 0 should be [false], no?
<Ramzi>
(You may assume the argument to itob is positive.)
<Ramzi>
you think that's it? lol. i can't check until tomorrow around 7:30ish
<thelema>
that's the first thing I found.
<Ramzi>
i bet you that's it.
<Ramzi>
man, i remember thinking that too, as i was writing.
<thelema>
you know you can do match x,y with (true::xt),(true,yt) -> blah
<Ramzi>
i said, "i'll fix it later." then i forgot
<thelema>
instead of testing the heads
<Ramzi>
hmm
<Ramzi>
yeah that'd clean up a bit
<Ramzi>
i think the itob problem is it.
<Ramzi>
thank you friend. it's quite late.
<thelema>
'nite
<Ramzi>
i guess i'll talk to you tomorrow.
<Ramzi>
goodnight.
evn_ has joined #ocaml
evn_ has quit []
alexyk has joined #ocaml
coucou747 has quit ["bye ca veut dire tchao en anglais"]
schme has joined #ocaml
Linktim has joined #ocaml
ygrek has joined #ocaml
goalieca has quit [Remote closed the connection]
<alexyk>
is there a way in ocamlto repeat a string N times, a la "o"^(" la"*2) => "o la la" ?
thelema has quit [Read error: 110 (Connection timed out)]
<tsuyoshi>
I think you'll have to write that function yourself
Morphous has joined #ocaml
<tsuyoshi>
rwmjones: I figured out how to store zero-length arrays.. just sent a patch
<tsuyoshi>
mmalloc is pretty crufty code.. I wonder if you could replace it with some other malloc
goalieca has joined #ocaml
Amorphous has quit [Read error: 110 (Connection timed out)]
Tetsuo has quit [brown.freenode.net irc.freenode.net]
TSC has quit [brown.freenode.net irc.freenode.net]
Ugarte has quit [brown.freenode.net irc.freenode.net]
shortcircuit has quit [brown.freenode.net irc.freenode.net]
l_a_m has quit [brown.freenode.net irc.freenode.net]
authentic has quit [brown.freenode.net irc.freenode.net]
donny has quit [brown.freenode.net irc.freenode.net]
guyzmo has quit [brown.freenode.net irc.freenode.net]
dwmw2_gone has quit [brown.freenode.net irc.freenode.net]
svenl has quit [brown.freenode.net irc.freenode.net]
qwr has quit [brown.freenode.net irc.freenode.net]
flux has quit [brown.freenode.net irc.freenode.net]
Naked has quit [brown.freenode.net irc.freenode.net]
Tetsuo has joined #ocaml
svenl has joined #ocaml
Ugarte has joined #ocaml
dwmw2_gone has joined #ocaml
guyzmo has joined #ocaml
shortcircuit has joined #ocaml
donny has joined #ocaml
l_a_m has joined #ocaml
authentic has joined #ocaml
TSC has joined #ocaml
flux has joined #ocaml
qwr has joined #ocaml
Naked has joined #ocaml
<bluestorm>
qwr: it's a shame that the reddit ocaml-related post getting comments are the least interesting ones :p
<bluestorm>
(troll's appeal)
LordMetroid has quit ["Leaving"]
yminsky has quit []
fremo has quit [Connection timed out]
Tetsuo has quit [brown.freenode.net irc.freenode.net]
TSC has quit [brown.freenode.net irc.freenode.net]
Ugarte has quit [brown.freenode.net irc.freenode.net]
shortcircuit has quit [brown.freenode.net irc.freenode.net]
l_a_m has quit [brown.freenode.net irc.freenode.net]
authentic has quit [brown.freenode.net irc.freenode.net]
donny has quit [brown.freenode.net irc.freenode.net]
guyzmo has quit [brown.freenode.net irc.freenode.net]
dwmw2_gone has quit [brown.freenode.net irc.freenode.net]
svenl has quit [brown.freenode.net irc.freenode.net]
qwr has quit [brown.freenode.net irc.freenode.net]
flux has quit [brown.freenode.net irc.freenode.net]
Naked has quit [brown.freenode.net irc.freenode.net]
Tetsuo has joined #ocaml
svenl has joined #ocaml
Ugarte has joined #ocaml
dwmw2_gone has joined #ocaml
guyzmo has joined #ocaml
shortcircuit has joined #ocaml
donny has joined #ocaml
l_a_m has joined #ocaml
authentic has joined #ocaml
TSC has joined #ocaml
flux has joined #ocaml
qwr has joined #ocaml
Naked has joined #ocaml
Tetsuo has quit [brown.freenode.net irc.freenode.net]
TSC has quit [brown.freenode.net irc.freenode.net]
Ugarte has quit [brown.freenode.net irc.freenode.net]
shortcircuit has quit [brown.freenode.net irc.freenode.net]
l_a_m has quit [brown.freenode.net irc.freenode.net]
authentic has quit [brown.freenode.net irc.freenode.net]
donny has quit [brown.freenode.net irc.freenode.net]
guyzmo has quit [brown.freenode.net irc.freenode.net]
dwmw2_gone has quit [brown.freenode.net irc.freenode.net]
svenl has quit [brown.freenode.net irc.freenode.net]
qwr has quit [brown.freenode.net irc.freenode.net]
flux has quit [brown.freenode.net irc.freenode.net]
Naked has quit [brown.freenode.net irc.freenode.net]
Tetsuo has joined #ocaml
svenl has joined #ocaml
Ugarte has joined #ocaml
dwmw2_gone has joined #ocaml
guyzmo has joined #ocaml
shortcircuit has joined #ocaml
donny has joined #ocaml
l_a_m has joined #ocaml
authentic has joined #ocaml
TSC has joined #ocaml
flux has joined #ocaml
qwr has joined #ocaml
Naked has joined #ocaml
Tetsuo has quit [brown.freenode.net irc.freenode.net]
TSC has quit [brown.freenode.net irc.freenode.net]
Ugarte has quit [brown.freenode.net irc.freenode.net]
shortcircuit has quit [brown.freenode.net irc.freenode.net]
l_a_m has quit [brown.freenode.net irc.freenode.net]
authentic has quit [brown.freenode.net irc.freenode.net]
donny has quit [brown.freenode.net irc.freenode.net]
guyzmo has quit [brown.freenode.net irc.freenode.net]
dwmw2_gone has quit [brown.freenode.net irc.freenode.net]
svenl has quit [brown.freenode.net irc.freenode.net]
qwr has quit [brown.freenode.net irc.freenode.net]
flux has quit [brown.freenode.net irc.freenode.net]
Naked has quit [brown.freenode.net irc.freenode.net]
Tetsuo has joined #ocaml
svenl has joined #ocaml
Ugarte has joined #ocaml
dwmw2_gone has joined #ocaml
guyzmo has joined #ocaml
shortcircuit has joined #ocaml
donny has joined #ocaml
l_a_m has joined #ocaml
authentic has joined #ocaml
TSC has joined #ocaml
flux has joined #ocaml
qwr has joined #ocaml
Naked has joined #ocaml
Tetsuo has quit [brown.freenode.net irc.freenode.net]
TSC has quit [brown.freenode.net irc.freenode.net]
Ugarte has quit [brown.freenode.net irc.freenode.net]
shortcircuit has quit [brown.freenode.net irc.freenode.net]
l_a_m has quit [brown.freenode.net irc.freenode.net]
authentic has quit [brown.freenode.net irc.freenode.net]
donny has quit [brown.freenode.net irc.freenode.net]
guyzmo has quit [brown.freenode.net irc.freenode.net]
dwmw2_gone has quit [brown.freenode.net irc.freenode.net]
svenl has quit [brown.freenode.net irc.freenode.net]
Tetsuo has joined #ocaml
TSC has joined #ocaml
authentic has joined #ocaml
l_a_m has joined #ocaml
donny has joined #ocaml
shortcircuit has joined #ocaml
guyzmo has joined #ocaml
dwmw2_gone has joined #ocaml
Ugarte has joined #ocaml
svenl has joined #ocaml
Tetsuo has quit [brown.freenode.net irc.freenode.net]
TSC has quit [brown.freenode.net irc.freenode.net]
l_a_m has quit [brown.freenode.net irc.freenode.net]
dwmw2_gone has quit [brown.freenode.net irc.freenode.net]
svenl has quit [brown.freenode.net irc.freenode.net]
Ugarte has quit [brown.freenode.net irc.freenode.net]
authentic has quit [brown.freenode.net irc.freenode.net]
donny has quit [brown.freenode.net irc.freenode.net]
guyzmo has quit [brown.freenode.net irc.freenode.net]
shortcircuit has quit [brown.freenode.net irc.freenode.net]
qwr has quit [brown.freenode.net irc.freenode.net]
flux has quit [brown.freenode.net irc.freenode.net]
Naked has quit [brown.freenode.net irc.freenode.net]
svenl has joined #ocaml
Ugarte has joined #ocaml
dwmw2_gone has joined #ocaml
guyzmo has joined #ocaml
shortcircuit has joined #ocaml
donny has joined #ocaml
l_a_m has joined #ocaml
authentic has joined #ocaml
TSC has joined #ocaml
Tetsuo has joined #ocaml
flux has joined #ocaml
qwr has joined #ocaml
Naked has joined #ocaml
Tetsuo has quit [brown.freenode.net irc.freenode.net]
TSC has quit [brown.freenode.net irc.freenode.net]
Ugarte has quit [brown.freenode.net irc.freenode.net]
shortcircuit has quit [brown.freenode.net irc.freenode.net]
l_a_m has quit [brown.freenode.net irc.freenode.net]
authentic has quit [brown.freenode.net irc.freenode.net]
donny has quit [brown.freenode.net irc.freenode.net]
guyzmo has quit [brown.freenode.net irc.freenode.net]
dwmw2_gone has quit [brown.freenode.net irc.freenode.net]
svenl has quit [brown.freenode.net irc.freenode.net]
qwr has quit [brown.freenode.net irc.freenode.net]
flux has quit [brown.freenode.net irc.freenode.net]
Naked has quit [brown.freenode.net irc.freenode.net]
svenl has joined #ocaml
Ugarte has joined #ocaml
dwmw2_gone has joined #ocaml
guyzmo has joined #ocaml
shortcircuit has joined #ocaml
donny has joined #ocaml
l_a_m has joined #ocaml
authentic has joined #ocaml
TSC has joined #ocaml
Tetsuo has joined #ocaml
flux has joined #ocaml
qwr has joined #ocaml
Naked has joined #ocaml
gene9 has joined #ocaml
jlouis has joined #ocaml
Axioplase has joined #ocaml
seafood_ has joined #ocaml
gene9 has quit ["Leaving"]
<bluestorm>
palomer_: now that you've rewritten your code, and that everybody (ie. reddit :-') is aware of it, do you intend to release it somewhat ?
Coin has joined #ocaml
<Coin>
Hi everybody. I used to program a few years ago in caml-light and I am lost with ocaml; How do I include a source file (.ml) from the interpreter ?
<flux>
#use
<flux>
however, it will undoubtedly be useful to read the documentation ;)
<Coin>
thks flux ! I try ....
seafood_ has quit []
<bluestorm>
Coin: if you can read french, i've written a camlp4/ocaml syntax comparison on some forum
<Coin>
bluestorm, yes I can. It would be useful to me. Where can I find it ?