Posts Tagged ‘Maths’

Prime sieve

Tuesday, December 11th, 2007

Since I haven’t posted in ages, and D doesn’t get nearly enough love from anyone, have a prime sieve.

This is public domain, I suppose. It’s not very spectacular, and took maybe ten minutes to write, so whatever.

module sieve;
 
import fun;
 
long[] sieveTo(long lim)
{
    long l = 0;
    long[] o; o.length = 100;
    foreach (ref i; o) i = 2;
 
    for (long i = 2; i < lim; i++) {
        if (!o.any( (long p) { return i != 0 && i % p == 0; } )) {
            if (l >= o.length) o.extend();
            o[l++] = i;
        }
    }
 
    o.length = l;
    return o;
 
}
 
private void extend(T)(ref T[] arr)
{
    int l = arr.length;
    arr.length = arr.length * 2;
    for (int i = l+1; i < arr.length; ++i)
        arr[i] = 2;
}

the relevant part of fun.d (where I reimplement the parts of Haskell I miss :v ) is the any function:

bool any(T)(in T[] arr, bool delegate(T) p)
{
    foreach(t; arr)
        if (p(t)) return true;
    return false;
}

All in all, D is surprisingly concise, and nice, and people should use it more.

And it should have Qt bindings for it. :(

Maple

Wednesday, October 17th, 2007

After some annoyance, and coughing up £151, I now have Maple on here to play around with. And to do maths microlab exercises, of course.

As much as the weird syntax (and Swing GUI) is annoying, it’s still fun to play around with. Being able to right-click an equation and integrate, differentiate, solve, or do whatever else to it is the most wonderful thing ever.

Since I don’t really know my way around it2 I can’t really say much about it yet, but yay, new toy.

Image from Wikipedia, taken by this guy. It’s cc-by-sa.


  1. Which is of course better than having to pay about £50, but still. 

  2. There were six microlab sessions last year which took about half an hour each, and that’s the only exposure I’ve had to it. 

MimeTeX for those without CGI

Tuesday, October 16th, 2007

For some reason CGI doesn’t work on this server at all. Trying to run things just ends up with the program itself being served, rather than its output. (Yes, I have the executable bit set.) This means that MimeTeX, which is a CGI program written in C, doesn’t work at all.

Of course, this doesn’t really matter since they have a public server, http://www.forkosh.dreamhost.com/mimetex.cgi, which apparently anyone and everyone can use. Of course I feel a little guilty leeching off their site like that even if Adrað’s bandwidth is pretty negligible, so I hacked together a filter for fauxML that uses their server once and saves the result locally. I’ve put the result here so anyone on the other end of a Google search or whatever can save a few minutes’ hassle by copypasting it.

(more…)