[Shootout-list] mandelbrot errors (perl, gforth, guile, ...)
Greg Buchholz
sleepingsquirrel@member.fsf.org
Fri, 25 Feb 2005 09:25:47 -0800 (PST)
--- Christophe TROESTLER <debian00@tiscali.be> wrote:
>
> Well asking for identical output on a problem known for its
> sensitivity to initial conditions is bound to fail (unless the very
> same operations are performed). On the attached picture , you will
> notice that the differences (between C and OCaml verions), seen as
> white dots, are at the "border" of the Mandelbrot set. If one
> increases the number of iterations, there are less differences but
> they do not disappear completely.
I changed line 9 from "let niter = 50" to "let niter = 51" and I got a
1 pixel difference from the other program's output for the N=400 case (at
pixel #300). I'll bet an ocaml expert (not me, this was the first ocaml
program I've ever compiled!) could fix this to produce the exact result.
(could it be that Floats instead of Doubles are used, or something
similar?)
Greg Buchholz
P.S. For others who may be interested, here's the perl program I use to
look at differences between *.pbm files
#!/usr/bin/perl -w
#
#diff_pbm: graphical diff of two *.pbm files
#
#usage: diff_pbm file1.pbm file2.pbm >diff.pbm
open ONE, $ARGV[0] or die "barf 1";
open TWO, $ARGV[1] or die "barf 2";
my $i=0;
$/=undef;
my $f1=<ONE>;
my $f2 = <TWO>;
my ($header1,$body1) = ($f1 =~ /(P4\s+\d+\s+\d+\s)(.*)/s);
my ($header2,$body2) = ($f2 =~ /(P4\s+\d+\s+\d+\s)(.*)/s);
if($header1 ne $header2)
{
die "headers don't match:\n**$header1**\n versus \n**$header2**\n";
}
if(length($body1) != length($body2))
{
die "different body lengths!\n";
}
my @b1 = split(//, $body1);
my @b2 = split(//, $body2);
my @diff;
for my $i (0..(length($body1)-1))
{
my $o1=ord($b1[$i]); my $o2=ord($b2[$i]);
my $exor = $o1 ^ $o2;
if($b1[$i] ne $b2[$i])
{
for (0..7)
{
print STDERR "different at pixel #",$i*8+(7-$_),"\n" if
($exor % 2);
$exor = int($exor/2);
}
}
push @diff, chr($o1 ^ $o2);
}
$dbody = join("", @diff);
print $header1.$dbody;
__________________________________
Do you Yahoo!?
Yahoo! Mail - Find what you need with new enhanced search.
http://info.mail.yahoo.com/mail_250