[metapost] memory problem

Boguslaw Jackowski bop at bop.com.pl
Fri May 5 17:22:20 CEST 2006

Taco Hoekwater:
> I have to look this up to be sure, but I strongly suspect that what
> happens is this: for each new equation, metapost runs through the
> complete list of variables to see if its status has changed thanks
> to the new equation. If you have a lot of 'not known' variables,
> this process can become very slow.

Stephan Hennig:
> Taco, thanks for your reply! Your idea sounds plausible. Since equation
> solving is /the/ feature of MetaPost such a fundamental performance leak
> would be very annoying. Remember, I'm just drawing a couple of boxes. :(

I cannot say that Taco is not right, but I remember that I tested
systems of linear equations with thousands unknowns. The precision
of the solution was not striking, but the computing didn't lasted
exceedingly long.

The following program solves the system of 1000 equations with 1000 unknowns:

   m:=1000; y1=1; for i:=2 upto m: y[i]:=-y[i-1]; endfor;
   for i:=1 upto m:
     if (i mod 100)=0: message decimal i; fi % tic
     for j:=1 upto m: if i=j: x[j] else: (1/abs(j-i))*x[j] fi + endfor 0=
     for j:=1 upto m: if i=j: y[j] else: (1/abs(j-i))*y[j] fi + endfor 0;
   showvariable x;

It takes a few minutes to find the solution both for the elder MP
(from the pre-Taco era ;-) and for MP 0.901.

Is it possible that Stephan's task requires more than 1000 unknowns?
Or I haven't caught the problem?

Cheers -- Jacko

BOP s. c.
ul. Bora-Komorowskiego 24, 80-377 Gdansk, Poland
tel. (+48 58) 553 46 59,  fax (+48 58) 511 03 81
bop at bop.com.pl, http://www.bop.com.pl

More information about the metapost mailing list