Additional-mtwist-notes.html 3.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. <html lang="en">
  2. <head>
  3. <title>Additional mtwist notes - avram - a virtual machine code interpreter</title>
  4. <meta http-equiv="Content-Type" content="text/html">
  5. <meta name="description" content="avram - a virtual machine code interpreter">
  6. <meta name="generator" content="makeinfo 4.13">
  7. <link title="Top" rel="start" href="index.html#Top">
  8. <link rel="up" href="mtwist.html#mtwist" title="mtwist">
  9. <link rel="prev" href="mtwist-exceptions.html#mtwist-exceptions" title="mtwist exceptions">
  10. <link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
  11. <meta http-equiv="Content-Style-Type" content="text/css">
  12. <style type="text/css"><!--
  13. pre.display { font-family:inherit }
  14. pre.format { font-family:inherit }
  15. pre.smalldisplay { font-family:inherit; font-size:smaller }
  16. pre.smallformat { font-family:inherit; font-size:smaller }
  17. pre.smallexample { font-size:smaller }
  18. pre.smalllisp { font-size:smaller }
  19. span.sc { font-variant:small-caps }
  20. span.roman { font-family:serif; font-weight:normal; }
  21. span.sansserif { font-family:sans-serif; font-weight:normal; }
  22. --></style>
  23. </head>
  24. <body>
  25. <div class="node">
  26. <a name="Additional-mtwist-notes"></a>
  27. <p>
  28. Previous:&nbsp;<a rel="previous" accesskey="p" href="mtwist-exceptions.html#mtwist-exceptions">mtwist exceptions</a>,
  29. Up:&nbsp;<a rel="up" accesskey="u" href="mtwist.html#mtwist">mtwist</a>
  30. <hr>
  31. </div>
  32. <h4 class="subsection">D.12.3 Additional <code>mtwist</code> notes</h4>
  33. <p>Although the <code>mtwist</code> library is &ldquo;external&rdquo;, it requires no
  34. special configuration on the host because the uniform variate
  35. generator in the form developed by its original authors is short and
  36. elegant enough to be packaged easily within the <code>avram</code>
  37. distribution. All further embellishments are home grown despite the
  38. advice at the end of <a href="Implementing-new-library-functions.html#Implementing-new-library-functions">Implementing new library functions</a>.
  39. <p>The <code>u_path</code> function is intended to allow sampling from a large
  40. population in logarithmic time when it is stored in a balanced tree. A
  41. left-heavy tree should be constructed initially with the data items
  42. all at the same level. Thereafter, a result returned by <code>u_path</code>
  43. with the appropriate dimensions can be used as an index into the tree
  44. for fast retrieval by the virtual machine's <code>field</code> combinator
  45. (<a href="Field.html#Field">Field</a>).
  46. <p>The last three functions, <code>u_enum</code>, <code>w_disc</code>, and
  47. <code>w_enum</code> use an inversion method with a binary search. The first
  48. draw from a given list will take a time asymptotically proportional to
  49. the length of the list, but subsequent draws from the same list are
  50. considerably faster due to a persistent cache maintained transparently
  51. by <code>avram</code>. For lists whose length is up to 2^16, the time
  52. required for a subsequent draw consists mainly of constant overhead
  53. with a small logarithmic component in the length of the list. For
  54. longer lists, the time ramps up linearly by a small factor.
  55. <p>Information allowing fast draws from up to sixteen lists can be cached
  56. simultaneously. If an application uses more than sixteen, the cached
  57. data are replaced in first-in first-out order. The size of the cache
  58. and the maximum list length for logarithmic time access can be
  59. adjusted easily by redefining constants in <samp><span class="file">mtwist.c</span></samp> under the
  60. <code>avram</code> source tree, but will require recompilation.
  61. </body></html>