         Edinburgh IMP77 Compiler - Version 8.4

    1  %begin
    2  %externalroutinespec exit %alias "exit" (%integer rc)
    3  %const %string (1) snl = "
    4+ "
    5  
    6  %routine tobern2(%long %real a0, %long %real a1, %long %real a2, %long %real %name b0, %long %real %name b1, %long %real %name b2)
    7       b0 = a0
    8       b1 = a0 + a1 / 2
    9       b2 = a0 + a1 + a2
   10  %end
   11  
   12  { uses de Casteljau’s algorithm }
   13  %long %real %fn evalbern2(%long %real b0, %long %real b1, %long %real b2, %long %real t)
   14      %long %real s = 1.0 - t
   15      %long %real b01 = s * b0 + t * b1
   16      %long %real b12 = s * b1 + t * b2
   17      %result = s * b01 + t * b12
   18  %end
   19  
   20  %routine tobern3(%long %real a0, %long %real a1, %long %real a2, %long %real a3, %long %real %name b0, %long %real %name b1, %long %real %name b2, %long %real %name b3)
   21      b0 = a0
   22      b1 = a0 + a1 / 3
   23      b2 = a0 + a1 * 2/3 + a2 / 3
   24      b3 = a0 + a1 + a2 + a3
   25  %end
   26  
   27  { uses de Casteljau’s algorithm }
   28  %long %real %fn evalbern3(%long %real b0, %long %real b1, %long %real b2, %long %real b3, %long %real t)
   29      %long %real s = 1 - t
   30      %long %real b01  = s * b0  + t * b1
   31      %long %real b12  = s * b1  + t * b2
   32      %long %real b23  = s * b2  + t * b3
   33      %long %real b012 = s * b01 + t * b12
   34      %long %real b123 = s * b12 + t * b23
   35      %result = s * b012 + t * b123
   36  %end
   37  
   38  %routine bern2to3(%long %real q0, %long %real q1, %long %real q2, %long %real %name c0, %long %real %name c1, %long %real %name c2, %long %real %name c3)
   39      c0 = q0
   40      c1 = q0 / 3   + q1 * 2/3
   41      c2 = q1 * 2/3 + q2 / 3
   42      c3 = q2
   43  %end
   44  
   45  { uses Horner's rule }
   46  %long %real %fn evalmono2(%long %real a0, %long %real a1, %long %real a2, %long %real t)
   47      %result = a0 + (t * (a1 + (t * a2)))
   48  %end
   49  
   50  { uses Horner's rule }
   51  %long %real %fn evalmono3(%long %real a0, %long %real a1, %long %real a2, %long %real a3, %long %real t)
   52      %result = a0 + (t * (a1 + (t * (a2 + (t * a3)))))
   53  %end
   54  
   55      %long %real p0m, p1m, p2m, q0m, q1m, q2m, r0m, r1m, r2m, r3m
   56      %long %real p0b2, p1b2, p2b2, q0b2, q1b2, q2b2
   57      %long %real p0b3, p1b3, p2b3, p3b3, q0b3, q1b3, q2b3, q3b3, r0b3, r1b3, r2b3, r3b3
   58      %long %real pc0, pc1, pc2, pc3, qc0, qc1, qc2, qc3
   59      
   60      %long %real x, y, m
   61  
   62      p0m = 1; p1m = 0; p2m = 0
   63      q0m = 1; q1m = 2; q2m = 3
   64      r0m = 1; r1m = 2; r2m = 3; r3m = 4
   65      
   66      tobern2 (p0m, p1m, p2m, p0b2, p1b2, p2b2)
   67      tobern2 (q0m, q1m, q2m, q0b2, q1b2, q2b2)
   68      print string ("Subprogram (1) examples:".snl)
   69      print string ("  mono ( ")
   70      print fl (p0m, 4); print string (", ")
   71      print fl (p1m, 4); print string (", ")
   72      print fl (p2m, 4); print string (") --> bern ( ")
   73      print fl (p0b2, 4); print string (", ")
   74      print fl (p1b2, 4); print string (", ")
   75      print fl (p2b2, 4); print string (")".snl)
   76      print string ("  mono ( ")
   77      print fl (q0m, 4); print string (", ")
   78      print fl (q1m, 4); print string (", ")
   79      print fl (q2m, 4); print string (") --> bern ( ")
   80      print fl (q0b2, 4); print string (", ")
   81      print fl (q1b2, 4); print string (", ")
   82      print fl (q2b2, 4); print string (")".snl)
   83      
   84      print string ("Subprogram (2) examples:".snl)
   85      x = 0.25
   86      y = evalbern2 (p0b2, p1b2, p2b2, x)
   87      print string ("  p ( "); print fl (x, 4)
   88      print string (") = "); print fl (y, 4)
   89      print string ("".snl)
   90      x = 7.50
   91      y = evalbern2 (p0b2, p1b2, p2b2, x)
   92      print string ("  p ( "); print fl (x, 4)
   93      print string (") = "); print fl (y, 4)
   94      print string ("".snl)
   95      x = 0.25
   96      y = evalbern2 (q0b2, q1b2, q2b2, x)
   97      print string ("  q ( "); print fl (x, 4)
   98      print string (") = "); print fl (y, 4)
   99      print string ("".snl)
  100      x = 7.50
  101      y = evalbern2 (q0b2, q1b2, q2b2, x)
  102      print string ("  q ( "); print fl (x, 4)
  103      print string (") = "); print fl (y, 4)
  104      print string ("".snl)
  105      
  106      tobern3 (p0m, p1m, p2m, 0, p0b3, p1b3, p2b3, p3b3)
  107      tobern3 (q0m, q1m, q2m, 0, q0b3, q1b3, q2b3, q3b3)
  108      tobern3 (r0m, r1m, r2m, r3m, r0b3, r1b3, r2b3, r3b3)
  109      print string ("Subprogram (3) examples:".snl)
  110      print string ("  mono ( ")
  111      print fl (p0m, 4); print string (", ")
  112      print fl (p1m, 4); print string (", ")
  113      print fl (p2m, 4); print string (", ")
  114      print fl (0, 4); print string (") --> bern ( ")
  115      print fl (p0b3, 4); print string (", ")
  116      print fl (p1b3, 4); print string (", ")
  117      print fl (p2b3, 4); print string (", ")
  118      print fl (p3b3, 4); print string (")".snl)
  119      print string ("  mono ( ")
  120      print fl (q0m, 4); print string (", ")
  121      print fl (q1m, 4); print string (", ")
  122      print fl (q2m, 4); print string (", ")
  123      print fl (0, 4); print string (") --> bern ( ")
  124      print fl (q0b3, 4); print string (", ")
  125      print fl (q1b3, 4); print string (", ")
  126      print fl (q2b3, 4); print string (", ")
  127      print fl (q3b3, 4); print string (")".snl)
  128      print string ("  mono ( ")
  129      print fl (r0m, 4); print string (", ")
  130      print fl (r1m, 4); print string (", ")
  131      print fl (r2m, 4); print string (", ")
  132      print fl (r3m, 4); print string (") --> bern ( ")
  133      print fl (r0b3, 4); print string (", ")
  134      print fl (r1b3, 4); print string (", ")
  135      print fl (r2b3, 4); print string (", ")
  136      print fl (r3b3, 4); print string (")".snl)
  137      
  138      print string ("Subprogram (4) examples:".snl)
  139      x = 0.25
  140      y = evalbern3 (p0b3, p1b3, p2b3, p3b3, x)
  141      print string ("  p ( "); print fl (x, 4)
  142      print string (") = "); print fl (y, 4)
  143      print string ("".snl)
  144      x = 7.50
  145      y = evalbern3 (p0b3, p1b3, p2b3, p3b3, x)
  146      print string ("  p ( "); print fl (x, 4)
  147      print string (") = "); print fl (y, 4)
  148      print string ("".snl)
  149      x = 0.25
  150      y = evalbern3 (q0b3, q1b3, q2b3, q3b3, x)
  151      print string ("  q ( "); print fl (x, 4)
  152      print string (") = "); print fl (y, 4)
  153      print string ("".snl)
  154      x = 7.50
  155      y = evalbern3 (q0b3, q1b3, q2b3, q3b3, x)
  156      print string ("  q ( "); print fl (x, 4)
  157      print string (") = "); print fl (y, 4)
  158      print string ("".snl)
  159      x = 0.25
  160      y = evalbern3 (r0b3, r1b3, r2b3, r3b3, x)
  161      print string ("  r ( "); print fl (x, 4)
  162      print string (") = "); print fl (y, 4)
  163      print string ("".snl)
  164      x = 7.50
  165      y = evalbern3 (r0b3, r1b3, r2b3, r3b3, x)
  166      print string ("  r ( "); print fl (x, 4)
  167      print string (") = "); print fl (y, 4)
  168      print string ("".snl)
  169      
  170      bern2to3 (p0b2, p1b2, p2b2, pc0, pc1, pc2, pc3)
  171      bern2to3 (q0b2, q1b2, q2b2, qc0, qc1, qc2, qc3)
  172      print string ("Subprogram (5) examples:".snl)
  173      print string ("  bern ( ")
  174      print fl (p0b2, 4); print string (", ")
  175      print fl (p1b2, 4); print string (", ")
  176      print fl (p2b2, 4); print string (") --> bern ( ")
  177      print fl (pc0, 4); print string (", ")
  178      print fl (pc1, 4); print string (", ")
  179      print fl (pc2, 4); print string (", ")
  180      print fl (pc3, 4); print string (")".snl)
  181      print string ("  bern ( ")
  182      print fl (q0b2, 4); print string (", ")
  183      print fl (q1b2, 4); print string (", ")
  184      print fl (q2b2, 4); print string (") --> bern ( ")
  185      print fl (qc0, 4); print string (", ")
  186      print fl (qc1, 4); print string (", ")
  187      print fl (qc2, 4); print string (", ")
  188      print fl (qc3, 4); print string (")".snl)
  189      
  190      exit(0)
  191      
  192  %endofprogram
?M unused
?EVALMONO3 unused
?EVALMONO2 unused

  247 Statements compiled
