home *** CD-ROM | disk | FTP | other *** search
/ Photo CD Demo 1 / Demo.bin / graphtal / examples / sqrt.lsy < prev    next >
Text File  |  1992-10-30  |  526b  |  35 lines

  1. /*
  2.  * L-system for square root computation.
  3.  *
  4.  * No graphical output is generated, so use
  5.  * the following command line:
  6.  *
  7.  * graphtal -p -d no sqrt.lsys
  8.  *
  9.  */
  10.  
  11. lsystem SQRT;
  12.  
  13.  
  14. table Iteration
  15. {
  16.   const epsilon = 0.00001;
  17.  
  18.   Sqrt(r) -> Sqrt(5,1,r,0);
  19.  
  20.   Sqrt(Xnew, Xold, r, n) 
  21.     : abs(Xnew-Xold)/abs(Xold) >= epsilon
  22.     -> Sqrt(0.5*(Xnew+r/Xnew), Xnew, r, n+1);
  23. };
  24.  
  25. table Result
  26. {
  27.   Sqrt(Xnew, Xold,r,n)->Resultat(Xnew) IterationsUsed(n);
  28. };
  29.  
  30. attributes {
  31.   axiom Sqrt(2);
  32.   derivation Iteration(infinity), Result;
  33. };
  34.  
  35.