Showing posts with label math. Show all posts
Showing posts with label math. Show all posts

Tuesday, April 6, 2010

ISO9660 Size Estimating

When I was coming up with the format for the backup disks I decided on a flat directory of numbered files because it was simple and usually worked well. Also it made each block addressable by the underlying operating system, externalizing some complexity, and allowed for media defects to have the least amount of impact, allowing for many partially burned disks to still be useful.

The first thought I had for filling the disks was to estimate the image size based on just the total size of the files being put on the disk, this worked well except where there were large numbers of small files (on the order of 100k files).

total = \sum{\lceil\frac{size}{2048}\rceil}2048

For a while I used this estimator with a pad factor based on the number of files, which worked fairly well but sometimes needed adjustment.

Last June I did some research and found the ISO9660 Filesystem specifications, and wrote up a better estimator for my specific case.
  • All files are 8.3 format.
  • There are no extended formats
  • All the files are in the root directory
The resulting estimator for image size in 2 KiB blocks is
174 + \lfloor\frac{count}{42}\rfloor + \sum{\lceil\frac{size}{2048}\rceil}
where the 174 is the disk overhead including padding, super blocks, and path tables; count is the number of file names on the disk, and size is the size of each file. This can be calculated incrementally with just two variables, a count and the sum of sizes so far.

This estimator came out to be right on every time.

Some day I may even use the ECMA-119 Standard (which got approved as the ISO9660 standard) to directly write a disk image instead of populating a directory and using mkisofs to make the image, but I have more important things to do before that.

Here is that same estimator as a PERL code example, calculating 1000 instances of a 2048 byte file.
#!/usr/bin/perl -w
use strict;
use POSIX;

sub sum {
    my $out = 0;
    for(@_) {
        $out += $_;
    }
    return $out;
}

my @sizes = ( 2048 ) x 1000;
my $file_count = @sizes;

my $data_size = sum(map { ceil($_ / 2048) } @sizes);
my $dir_size = floor( $file_count / 42 ) + 1;
my $overhead = 173;

my $size = $overhead + $dir_size + $data_size;

$\ = "\n";
print $size;

Friday, April 2, 2010

reversing log

I was tutoring, and one particular type of problem came up as difficult, solving for a variable in a log.

2 = \log x
To solve this, first exponent both sides on 10, which will reverse the log. The hard part seems to be here.
10^2 = 10^{\log x}
and simplify (10^{\log x} = x).
100 = x

To make is harder, multiply the x by a constant inside the log.
2 = \log 2x
put both sides as exponents of 10
10^2 = 10^{\log 2x}
simplify
100 = 2x
divide both sides by 2
\frac{100}{2} = \frac{2x}{2}
simplify
50 = x

and this time add something to the x inside the log
2 = \log\left( 2x + 1 \right)
put both as exponents of 10
10^2 = 10^{\log\left( 2x + 1 \right)}
simplify
100 = 2x + 1
subtract 1 from both sides
100 - 1 = 2x + 1 - 1
simplify
99 = 2x
divide both sides by two
\frac{99}{2} = \frac{2x}{2}
simplify
\frac{99}{2} = x

what can I do to make it harder? Two layers of log? two layers of logs of different bases? that should be plenty hard.

2 = \ln\log x
The \ln x is the outside log, so it needs to be dealt with first, make both sides exponents of e
e^2 = e^{\ln\log x}
simplify
e^2 = \log x
make both sides exponents of 10
10^{e^2} = 10^{\log x}
simplify
10^{e^2} = x

And now for one that looks a bit scary, the log is in an exponent.
2 = e^{\log x}
First there is the e^x to deal with, so take the natural logarithm of both sides.
\ln 2 = \ln e^{\log x}
simplify
\ln 2 = \log x
and put both sides on an exponent of 10, as in the previous solutions
10^{\ln 2} = 10^{\log x}
simplify
10^{\ln 2} = x

It is all a matter of removing one layer at a time to get to the thing being solved for.

all good?

Thursday, April 1, 2010

revealing the algebraic falacy, 2 != 1

Previously I used only basic algebraic manipulation I showed that 2 = 1, which is also false, now I am going to show where it went wrong, by doing the same steps as before, using the same forms as before.

a = b

Substitute b for a in the entire rest of the article, since they are the same.

b = b

we can do whatever we want to an equation as long as we do the same thing to both sides, so first add b

b + b = b + b

partially simplify

2b = b + b

subtract 2b

2b - 2b = b + b - 2b

partially group like terms

2b - 2b = b + (1-2)b

simplify

2b - 2b = b + (-1)b

adding a negative number is the same as subtracting

2b - 2b = b - b

factor out (b - b)

2(b - b) = 1(b - b)

divide by (b - b), which is also known as zero.

\frac{2(b - b)}{b - b} = \frac{1(b - b)}{b - b}

re-factor to isolate the one, now we have zero over zero, anything can happen

2\left(\frac{b - b}{b-b}\right) = 1\left(\frac{b - b}{b-b}\right)

reduce the one, and we are just not allowed to get here

2(1) = 1(1)

simplify

2 = 1

Division by zero is not allowed, and zero over zero is just undefined.

Sunday, March 28, 2010

algebraic fallacy, 2 = 1

Using only basic algebraic manipulation, and trying to not skip any steps, I am going show that 2 = 1 .

a = b

we can do whatever we want to an equation as long as we do the same thing to both sides, so first add a

a + a = b + a

simplify

2a = b + a

subtract 2b

2a - 2b = a + b - 2b

group like terms

2a - 2b = a + (1-2)b

simplify

2a - 2b = a + (-1)b

adding a negative number is the same as subtracting

2a - 2b = a - b

factor out (a - b)

2(a - b) = 1(a - b)

divide by (a - b)

\frac{2(a - b)}{a-b} = \frac{1(a - b)}{a-b}

re-factor to isolate the one

2\left(\frac{a - b}{a-b}\right) = 1\left(\frac{a - b}{a-b}\right)

reduce the one

2(1) = 1(1)

simplify

2 = 1

where did it go wrong? The answer will be given in a later post.

My class was given this puzzle in high school one day, and I was not the first one to see the mistake, but it was quite memorable.

Saturday, March 27, 2010

identifying multiples of 9 (nine)

I was given a simple method to identify multiples of 9 in grade school.

Given a number, it is a series of digits d_1d_2d_3...d_n.

Add up all the digits \sum_{i=1}^nd_i.

If the resulting number is a multiple of nine (repeat the process if it has more than one digit), or is nine, then the original number is a multiple of nine.

For example, take 81, it is the digits 8 and 1, add the digits, 8 + 1, the result is 9, therefore 81 is a multiple of 9.

For another example, take 123456, it is the digits 1, 2, 3, 4, 5, and 6, add the digits, 1 + 2 + 3 + 4 + 5 + 6, the result is 21, which is multiple digits, add the digits, 2 + 1, the result is 3, therefore 123456 is not a multiple of 9.