[metapost] ! MetaPost capacity exceeded

Steve MC Han hmc0907 at yahoo.com
Sun Feb 8 02:17:15 CET 2009


Hi Karl, 
 
Thank you for your response.
 
It's just a simple recursion drawing. 
 
numeric n, m, x,y,z,aa,bb;
picture h, h[], g, g[];
path p,p[];
pair a,a[],b,b[];
 
beginfig(1)
n:=8;
u:=.6cm;
for i=0 upto n-1:
a[i]:=u*dir(360*i/n);
endfor;
p0:=a[0] for i:=1 upto n-1: --a[i] endfor --cycle;
a:=u*dir(360/n) shifted a1;
y:=arclength ((0,0)--a);
y:=1.2y;

def froct(expr m)=
 if m=0:
   fill p0 scaled ((y+u)/u) withcolor red;
 else:
  fill p0 withcolor red;
  h0:=currentpicture;
  currentpicture:=nullpicture;
   for j=1 upto m:
   for i=0 upto n-1:
    b[i]:=y*dir(360*i/n);
    draw h0 shifted b[i];
   endfor;
   h:=currentpicture;
   currentpicture:=nullpicture;
   h0:=h scaled (u/(y+u));
   endfor;
   draw h;
  fi; 
enddef;
 
froct(1);
h1:=currentpicture;
currentpicture:=nullpicture;

froct(2);
h2:=currentpicture;
currentpicture:=nullpicture;
froct(4);
h3:=currentpicture;
currentpicture:=nullpicture;
draw h1;
draw h2 shifted (8u,0);
draw h3 shifted (16u,0);  
endfig;
end
 

If you change froct(5) in picture 3, then the capacity is exceeded 800000 already, which is strange because 8^5 is only 32768, even though the growth is exponential, it will exceed any memory capacity with a few more iteration, I admit.
 
I don't know anything about what you described below, because I am a novice in programming and computer. 
 
 
Another strange thing for me is at the beginning of the definition of a function,
 
def froct(expr m)=
 if m=0:
   fill p0 scaled ((y+u)/u) withcolor red;
 else:
  fill p0 withcolor red;
  h0:=currentpicture;
  currentpicture:=nullpicture;
 
these two highlighted sentences look redundant, so I pull them outside of function froct such as:
 
  fill p0 withcolor red;
  h0:=currentpicture;
  currentpicture:=nullpicture;
 
def froct(expr m)=
 if m=0:
   draw h0 scaled ((y+u)/u);
 else:
  draw h0;
 
 
this looks more efficient to me, but in this case, it cannot even perform 4 iterations. So, obviously, it is less efficient than the original one.
 
I am just a beginner of programming (this is basically my first), I would appreciate it very much if any experts can give some insight.
 
 
Thanks,
Steve
 


--- On Sat, 2/7/09, Karl Berry <karl at freefriends.org> wrote:

From: Karl Berry <karl at freefriends.org>
Subject: Re: [metapost] ! MetaPost capacity exceeded
To: hmc0907 at yahoo.com, metapost at tug.org
Date: Saturday, February 7, 2009, 3:37 PM

    > If you want your change to affect only metapost, add or change
    > main_memory.mpost only

I'm curious what kind of graph you are generating that the current
main_memory is insufficient for!  My knee-jerk reaction to such reports
is always to just increase the defaults, since if you're running into
it, probably others are too.  It's not just an infinite recursion or
some such?

    texlive ...and therefore I am uncertain what the 'best' command is.

Er, well, it all depends on what one wants to do :).  It's already done,
but for the record ...

As you already mentioned, fmtutil generates stuff per-user; fmtutils-sys
generates it for the "system" install.  In this case, I gather there
was
no permission to write in the system dirs.

As for the options, here are the principal ones:
  --all                      recreate all format files
  --missing                  create all missing format files
  --refresh                  recreate only existing format files
  --byfmt formatname         (re)create format for `formatname'

So,  fmtutil --byfmt mpost  would have been my first suggestion, 
since it didn't seem desired to remake the tex or metafont formats here.

Happy formatting,
karl



      
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://tug.org/pipermail/metapost/attachments/20090207/7587ae64/attachment.html 


More information about the metapost mailing list