* Mandelbrot renderer
@ 2005-11-23 1:50 Jon Harrop
2005-11-23 8:00 ` [Caml-list] " David Baelde
0 siblings, 1 reply; 6+ messages in thread
From: Jon Harrop @ 2005-11-23 1:50 UTC (permalink / raw)
To: caml-list
Following Oliver's objections regarding the lack of serious software written
in OCaml (e.g. web servers), I have written a very serious Mandelbrot
renderer. The program is 35 lines of OCaml and renders using OpenGL. This
page breaks it down and describes how it works:
http://www.ffconsultancy.com/free/fractal
I've written a simple, recursive C++ version as well. It weighs in at 45 lines
but only 6% more bytes. If you specialise the complex-number arithmetic in
the OCaml:
let rec mandelbrot i cx cy zx zy =
if i = 63 || zx *. zx +. zy *. zy > 4. then i else
let zx = zx *. zx -. zy *. zy and zy = 2. *. zx *. zy in
mandelbrot (i+1) cx cy (zx +. cx) (zy +. cy)
then, with only -O3, the C++ is actually significantly slower. The performance
of the C++ improves considerably with -ffast-math so that it is slightly
faster. The performance of the C++ can be further improved by using an
imperative style. This is on both AMD64 and x86.
--
Dr Jon D Harrop, Flying Frog Consultancy Ltd.
Objective CAML for Scientists
http://www.ffconsultancy.com/products/ocaml_for_scientists
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Mandelbrot renderer
2005-11-23 1:50 Mandelbrot renderer Jon Harrop
@ 2005-11-23 8:00 ` David Baelde
2005-11-23 10:10 ` Yaron Minsky
2005-11-24 14:43 ` Chris Campbell
0 siblings, 2 replies; 6+ messages in thread
From: David Baelde @ 2005-11-23 8:00 UTC (permalink / raw)
To: caml-list
2005/11/23, Jon Harrop <jon@ffconsultancy.com>:
> Following Oliver's objections regarding the lack of serious software written
> in OCaml (e.g. web servers), I have written a very serious Mandelbrot
> renderer. The program is 35 lines of OCaml and renders using OpenGL. This
> page breaks it down and describes how it works:
Nice job, but I don't think it has something to do with Olivier's
remarks. Serious software written in OCaml exists (Astrée, Coq, ..),
no one doubts that. What lacks is mainstream serious software, and it
makes OCaml not so visible.
People don't realize OCaml is a general purpose language: I was once
told on an IRC chan: "OCaml ? I only know one software written in
OCaml..." Also, people learn to write many fun real-world application
in C, but only "boring" scientific stuff in OCaml (when they're taught
OCaml). That's the kind of problems which was adressed.
Cheers.
--
David
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Mandelbrot renderer
2005-11-23 8:00 ` [Caml-list] " David Baelde
@ 2005-11-23 10:10 ` Yaron Minsky
2005-11-23 14:58 ` Christophe Raffalli
2005-11-24 14:43 ` Chris Campbell
1 sibling, 1 reply; 6+ messages in thread
From: Yaron Minsky @ 2005-11-23 10:10 UTC (permalink / raw)
To: david.baelde; +Cc: caml-list
[-- Attachment #1: Type: text/plain, Size: 1553 bytes --]
On 11/23/05, David Baelde <david.baelde@gmail.com> wrote:
>
> 2005/11/23, Jon Harrop <jon@ffconsultancy.com>:
> > Following Oliver's objections regarding the lack of serious software
> written
> > in OCaml (e.g. web servers), I have written a very serious Mandelbrot
> > renderer. The program is 35 lines of OCaml and renders using OpenGL.
> This
> > page breaks it down and describes how it works:
>
> Nice job, but I don't think it has something to do with Olivier's
> remarks. Serious software written in OCaml exists (Astrée, Coq, ..),
> no one doubts that. What lacks is mainstream serious software, and it
> makes OCaml not so visible.
I rather suspect that Jon was making a joke here....
People don't realize OCaml is a general purpose language: I was once
> told on an IRC chan: "OCaml ? I only know one software written in
> OCaml..." Also, people learn to write many fun real-world application
> in C, but only "boring" scientific stuff in OCaml (when they're taught
> OCaml). That's the kind of problems which was adressed.
I think this really is a problem, although there are a few exceptions
(mldonkey and unison come to mind.) But the lack of applications is not, I
think, for lack of suitability of the language. The company where I work
(quick hiring plug: http://janestcapital.com/ocaml.html) has had quite a bit
of luck building rather interesting and practical trading and financial
applications in OCaml, but those are all for internal use, so it doesn't
help much for OCaml's visibility.
y
[-- Attachment #2: Type: text/html, Size: 2153 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Mandelbrot renderer
2005-11-23 10:10 ` Yaron Minsky
@ 2005-11-23 14:58 ` Christophe Raffalli
0 siblings, 0 replies; 6+ messages in thread
From: Christophe Raffalli @ 2005-11-23 14:58 UTC (permalink / raw)
To: Yaron Minsky; +Cc: david.baelde, caml-list
> I think this really is a problem, although there are a few exceptions
> (mldonkey and unison come to mind.) But the lack of applications is
> not, I think, for lack of suitability of the language. The company
> where I work (quick hiring plug: http://janestcapital.com/ocaml.html)
> has had quite a bit of luck building rather interesting and practical
> trading and financial applications in OCaml, but those are all for
> internal use, so it doesn't help much for OCaml's visibility.
>
And what about python or java ?
I do not use a single python program and I only use one java program
which is cgoban and one ocaml program which is unison (if I do not count
the programs I am using for my research, because my research is related
to type system so this is biased).
So, for me, ocaml is more visible that python and equally visible than
ocaml ...
I think this kind of visivility needs time.
This is for my desktop computer ... however, on my V800 portable phone,
java is very visible (all my games are in java there). May be ocaml
software for pdas and phones are the way to make ocaml visible ;-)
And as I said in another post, I really would like an OCaml sudoko
GENERATOR (not a solver) on my portable phone, I almost finished all the
grids I have in the demo of a java commercial program I found on
getjar.com, so this now is urgent :-)
--
Christophe Raffalli
Université de Savoie
Batiment Le Chablais, bureau 21
73376 Le Bourget-du-Lac Cedex
tél: (33) 4 79 75 81 03
fax: (33) 4 79 75 87 42
mail: Christophe.Raffalli@univ-savoie.fr
www: http://www.lama.univ-savoie.fr/~RAFFALLI
---------------------------------------------
IMPORTANT: this mail is signed using PGP/MIME
At least Enigmail/Mozilla, mutt or evolution
can check this signature. The public key is
stored on www.keyserver.net
---------------------------------------------
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Mandelbrot renderer
2005-11-23 8:00 ` [Caml-list] " David Baelde
2005-11-23 10:10 ` Yaron Minsky
@ 2005-11-24 14:43 ` Chris Campbell
1 sibling, 0 replies; 6+ messages in thread
From: Chris Campbell @ 2005-11-24 14:43 UTC (permalink / raw)
To: david.baelde; +Cc: caml-list
On 23/11/05, David Baelde <david.baelde@gmail.com> wrote:
> People don't realize OCaml is a general purpose language: I was once
> told on an IRC chan: "OCaml ? I only know one software written in
> OCaml..." Also, people learn to write many fun real-world application
> in C, but only "boring" scientific stuff in OCaml (when they're taught
> OCaml). That's the kind of problems which was adressed.
Here's an idea for an application. How real world it is I'm not sure.
A good podcast client for Linux with support for Bittorrent. I tried
a few at the weekend and basically they all suck to varying degrees of
suckiness. Usually it's the UI that prevents you from doing anything
because you can't fathom how to work it and the help that's there
isn't more than a HTML-ised About box.
Hierachical viewing of casts, queueing of downloads, all the podcasty
stuff you need. ITunes is great, once you figure out how to add a
cast it's easy. It has two issues a) I have to be in Windows (don't
have a mac yet) and b) downloading big casts like the SICP lectures is
a pain (too great to miss tho'); ITunes doesn't seem to allow queueing
yet (couldn't find it). Oh and it strains the server because they
aren't Bittorrent hosted casts.
Podcasts + Bittorrent isn't a new idea, but it's a good one. Why have
the server do all the work, when clients can lighten your load? If
you're a popular podcaster your bandwidth costs are going to be high.
Irrespective of bt support a good client is needed. Have it handle
ITMS pod links so I can write a ffox extension to call it on those
links, and an intuitive gui and it's a contender.
Just a thought,
Chris
p.s. if anyone knows of a good one already pls let me know. So far
the best I've found is a command line app.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [Caml-list] Mandelbrot renderer
@ 2005-11-24 2:38 Simon
0 siblings, 0 replies; 6+ messages in thread
From: Simon @ 2005-11-24 2:38 UTC (permalink / raw)
To: christophe.raffalli; +Cc: caml-list
> And as I said in another post, I really would like an OCaml sudoko GENERATOR
(not a solver) on my portable phone, I almost finished all the grids I have in
the demo of a java commercial program I found on getjar.com, so this now is
urgent :-)
This won't work on your phone, but it will generate a wide range of sudoku
puzzles, all of them will most likely be near to impossible. It works by
shuffling a sudoku puzzle I took from Tuesday's paper and coded in after I
removed a few unneeded numbers, then applying a permutation to the numbers. Not
the most complex, but it should produce a very large range of puzzles, although
probably not every single possible least-complex puzzle. Yes, it's long for its
simplicity, all in imperative style and it won't work on your phone :(.
---
Random.self_init()
let m = [|
[| 9; 4; 0; 0; 0; 7; 0; 0; 0 |];
[| 0; 6; 0; 0; 0; 0; 0; 1; 0 |];
[| 0; 0; 8; 0; 0; 1; 0; 5; 3 |];
[| 3; 0; 7; 0; 0; 0; 0; 6; 0 |];
[| 0; 0; 0; 0; 2; 0; 0; 0; 0 |];
[| 0; 5; 0; 0; 0; 0; 0; 3; 7 |];
[| 0; 9; 0; 8; 0; 0; 1; 0; 0 |];
[| 0; 1; 0; 0; 0; 0; 0; 8; 0 |];
[| 0; 0; 0; 4; 0; 0; 0; 0; 9 |]
|]
let swap_row board rowA rowB =
let t = board.(rowA) in
let _ = board.(rowA) <- board.(rowB) in
board.(rowB) <- t
let swap_col board colA colB =
for i = 0 to 8 do
let t = board.(i).(colA) in
let _ = board.(i).(colA) <- board.(i).(colB) in
board.(i).(colB) <- t
done
let shuffle_rows board =
for i = 0 to 2 do
for j = 0 to 2 do
swap_row board (i * 3 + j) (i * 3 + (Random.int 3))
done
done
let shuffle_cols board =
for i = 0 to 2 do
for j = 0 to 2 do
swap_col board (i * 3 + j) (i * 3 + (Random.int 3))
done
done
(* shuffle the 3x3 squares in their rows *)
let shuffle_square_rows board =
let swap_square_row a b =
for i = 0 to 2 do
swap_row board (a + i) (b + i)
done
in
for i = 0 to 2 do
swap_square_row (i * 3) (Random.int 3 * 3)
done
(* shuffle the 3x3 squares in their columns *)
let shuffle_square_cols board =
let swap_square_col a b =
for i = 0 to 2 do
swap_col board (a + i) (b + i)
done
in
for i = 0 to 2 do
swap_square_col (i * 3) (Random.int 3 * 3)
done
let shuffle board =
shuffle_rows board;
shuffle_cols board;
shuffle_square_rows board;
shuffle_square_cols board
(* swap the numbers around *)
let permutation board =
let arr = Array.init 10 (fun i -> i) in
(* really crappy way of making a permutation *)
for i = 0 to 999 do
swap_row arr (i mod 9 + 1) (Random.int 9 + 1)
done;
for i = 0 to 8 do
let row = board.(i) in
for j = 0 to 8 do
row.(j) <- arr.(row.(j))
done
done
let () =
shuffle m;
permutation m;
Array.iter (fun r -> Array.iter (print_int) r; print_newline()) m
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2005-11-24 14:43 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-11-23 1:50 Mandelbrot renderer Jon Harrop
2005-11-23 8:00 ` [Caml-list] " David Baelde
2005-11-23 10:10 ` Yaron Minsky
2005-11-23 14:58 ` Christophe Raffalli
2005-11-24 14:43 ` Chris Campbell
2005-11-24 2:38 Simon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox