<?xml version="1.0" encoding="UTF-8" standalone="no"?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /> <title>GENfarey</title> <link rel="stylesheet" href="csound.css" type="text/css" /> <meta name="generator" content="DocBook XSL Stylesheets V1.75.2" /> <link rel="home" href="index.html" title="The Canonical Csound Reference Manual" /> <link rel="up" href="ScoregensTop.html" title="Score Statements and GEN Routines" /> <link rel="prev" href="GENsone.html" title="GENsone" /> <link rel="next" href="UtilityTop.html" title="The Utility Programs" /> </head> <body> <div class="navheader"> <table width="100%" summary="Navigation header"> <tr> <th colspan="3" align="center">GENfarey</th> </tr> <tr> <td width="20%" align="left"><a accesskey="p" href="GENsone.html">Prev</a> </td> <th width="60%" align="center">Score Statements and GEN Routines</th> <td width="20%" align="right"> <a accesskey="n" href="UtilityTop.html">Next</a></td> </tr> </table> <hr /> </div> <div class="refentry" title="GENfarey"> <a id="GENfarey"></a> <div class="titlepage"></div> <a id="IndexGENfarey" class="indexterm"></a> <div class="refnamediv"> <h2> <span class="refentrytitle">GENfarey</span> </h2> <p>"farey" — Fills a table with the Farey Sequence F<sub>n</sub> of the integer n. </p> </div> <div class="refsect1" title="Description"> <a id="id3750860"></a> <h2>Description</h2> <p> A Farey Sequence F<sub>n</sub> of order n is a list of fractions in their lowest terms between 0 and 1 and in ascending order. Their denominators do not exceed n. This means a fraction a/b belongs to F<sub>n</sub> if 0 ≤ a ≤ b ≤ n. The numerator and denominator of each fraction are always coprime. 0 and 1 are included in F<sub>n</sub> as the fractions 0/1 and 1/1. For example F<sub>5</sub> = {0/1, 1/5, 1/4, 1/3, 2/5, 1/2, 3/5, 2/3, 3/4, 4/5, 1/1} Some properties of the Farey Sequence: </p> <div class="itemizedlist"> <ul class="itemizedlist" type="disc"> <li class="listitem"> If a/b and c/d are two successive terms of F<sub>n</sub>, then bc - ad = 1. </li> <li class="listitem"> If a/b, c/d, e/f are three successive terms of F<sub>n</sub>, then: c/d = (a+e) / (b+f). In this case c/d is called the mediant fraction between a/b and e/f. </li> <li class="listitem"> If n > 1, then no two successive terms ofF<sub>n</sub> have the same denominator. </li> </ul> </div> <p> </p> <p> The length of any Farey Sequence F<sub>n</sub> is determined by |F<sub>n</sub>| = 1 + SUM over n (phi(m)) where phi(m) is Euler's totient function, which gives the number of integers ≤ m that are coprime to m. </p> <p> Some values for the length of F<sub>n</sub> given n: </p> <div class="informaltable"> <table border="1"> <colgroup> <col /> <col /> </colgroup> <thead> <tr> <th>n</th> <th>F<sub>n</sub></th> </tr> </thead> <tbody> <tr> <td>1</td> <td>2</td> </tr> <tr> <td>2</td> <td>3</td> </tr> <tr> <td>3</td> <td>5</td> </tr> <tr> <td>4</td> <td>7</td> </tr> <tr> <td>5</td> <td>11</td> </tr> <tr> <td>6</td> <td>13</td> </tr> <tr> <td>7</td> <td>19</td> </tr> <tr> <td>8</td> <td>23</td> </tr> <tr> <td>9</td> <td>29</td> </tr> <tr> <td>10</td> <td>33</td> </tr> <tr> <td>11</td> <td>43</td> </tr> <tr> <td>12</td> <td>47</td> </tr> <tr> <td>13</td> <td>59</td> </tr> <tr> <td>14</td> <td>65</td> </tr> <tr> <td>15</td> <td>73</td> </tr> <tr> <td>16</td> <td>81</td> </tr> <tr> <td>17</td> <td>97</td> </tr> <tr> <td>18</td> <td>103</td> </tr> <tr> <td>19</td> <td>121</td> </tr> <tr> <td>20</td> <td>129</td> </tr> </tbody> </table> </div> <p> </p> </div> <div class="refsect1" title="Syntax"> <a id="id3752031"></a> <h2>Syntax</h2> <pre class="synopsis"><span class="command"><strong>f</strong></span> # time size "farey" fareynum mode</pre> </div> <div class="refsect1" title="Initialization"> <a id="id3752048"></a> <h2>Initialization</h2> <p> <span class="emphasis"><em>size</em></span> -- number of points in the table. Must be a power of 2 or power-of-2 plus 1 (see <a class="link" href="f.html" title="f Statement (or Function Table Statement)"><em class="citetitle">f statement</em></a>). </p> <p> <span class="emphasis"><em>fareynum</em></span> -- the integer n for generating Farey Sequence F<sub>n</sub> </p> <p> <span class="emphasis"><em>mode</em></span> -- integer to trigger a specific output to be written into the table: </p> <div class="itemizedlist"> <ul class="itemizedlist" type="disc"> <li class="listitem"> <p>0 -- outputs floating point numbers representing the elements of F<sub>n</sub>.</p> </li> <li class="listitem"> <p> 1 -- outputs delta values of successive elements of F<sub>n</sub>, useful for generating note durations for example.</p> </li> <li class="listitem"> <p> 2 -- outputs only the denominators of the integer ratios, useful for indexing other tables or instruments for example.</p> </li> <li class="listitem"> <p> 3 -- same as mode 2 but with normalised output.</p> </li> <li class="listitem"> <p> 4 -- same as mode 0 but with 1 added to each number, useful for generating tables for tuning opcodes, for example <span class="emphasis"><em>cps2pch</em></span>. </p> </li> </ul> </div> <p> </p> </div> <div class="refsect1" title="Examples"> <a id="id3752145"></a> <h2>Examples</h2> <p> </p> <div class="informalexample"><pre class="programlisting"> <span class="stamnt">f</span>1 0 -23 "farey" 8 0</pre> Generates generates Farey Sequence F<sub>8</sub>. The table contains all 23 elements of F<sub>8</sub> as floating point numbers. <pre class="programlisting"> <span class="stamnt">f</span>1 0 -18 "farey" 7 1</pre> This generates Farey Sequence F<sub>7</sub>. The table contains 18 delta values of F<sub>7</sub>, i.e. the difference between r<sub>i+1</sub> - r<sub>i</sub>, where r is the ith element of F<sub>n</sub>. <pre class="programlisting"> <span class="stamnt">f</span>1 0 -43 "farey" 11 2</pre> This generates Farey Sequence F<sub>11</sub>. The table contains the denominators of all 43 fractions in F<sub>11</sub>. <pre class="programlisting"> <span class="stamnt">f</span>1 0 -43 "farey" 11 3</pre> This generates Farey Sequence F<sub>11</sub>. The table contains the denominators of all 43 fractions in F<sub>11</sub>, each of those divided by 11, i.e. normalised. <pre class="programlisting"> <span class="stamnt">f</span>1 0 -18 "farey" 7 4</pre> This generates Farey Sequence F<sub>7</sub>. The table contains all fractions of F<sub>7</sub>, same as mode 0, but this time '1' is added to each table element. </div> <p> </p> <p> </p> <div class="example"> <a id="id3752273"></a> <p class="title"> <b>Example 753. A simple example of the GENfarey routine.</b> </p> <div class="example-contents"> <p> See the sections <a class="link" href="UsingRealTime.html" title="Real-Time Audio"><em class="citetitle">Real-time Audio</em></a> and <a class="link" href="CommandFlags.html" title="Csound command line"><em class="citetitle">Command Line Flags</em></a> for more information on using command line flags. </p> <pre class="programlisting"> <span class="csdtag"><CsoundSynthesizer></span> <span class="csdtag"><CsOptions></span> <span class="csdtag"></CsOptions></span> <span class="csdtag"><CsInstruments></span> <span class="ohdr">sr</span><span class="op">=</span>44100 <span class="ohdr">ksmps</span><span class="op">=</span>10 <span class="ohdr">nchnls</span><span class="op">=</span>1 <span class="oblock">instr</span> 4 kndx <span class="opc">init</span> 0 <span class="comment">; read out elements of F_8 one by one and print to file</span> <span class="octrl">if</span> (kndx <span class="op"><</span> 23) then kelem <span class="opc">tab</span> kndx, 1 <span class="opc">fprintks</span> "farey8table.txt", "<span class="op">%</span>2.6f\\n", kelem kndx <span class="op">=</span> kndx<span class="op">+</span>1 <span class="octrl">endif</span> <span class="oblock">endin</span> <span class="csdtag"></CsInstruments></span> <span class="csdtag"><CsScore></span> <span class="comment">; initialise integer for Farey Sequence F_8</span> <span class="stamnt">f</span>1 0 -23 "<span class="stamnt">f</span>arey" 8 0 <span class="comment">; if mode=0 then the table stores all elements of the Farey Sequence</span> <span class="comment">; as fractions in the range [0,1]</span> <span class="stamnt">i</span>4 0 1 <span class="stamnt">e</span> <span class="csdtag"></CsScore></span> <span class="csdtag"></CsoundSynthesizer></span> </pre> </div> </div> <p><br class="example-break" /> </p> </div> <div class="refsect1" title="Credits"> <a id="id3752311"></a> <h2>Credits</h2> <p> </p> <table border="0" summary="Simple list" class="simplelist"> <tr> <td>Author: Georg Boenn</td> </tr> <tr> <td>University of Glamorgan</td> </tr> <tr> <td>2010</td> </tr> </table> <p> </p> <p>New in Csound version 5.13</p> </div> </div> <div class="navfooter"> <hr /> <table width="100%" summary="Navigation footer"> <tr> <td width="40%" align="left"><a accesskey="p" href="GENsone.html">Prev</a> </td> <td width="20%" align="center"> <a accesskey="u" href="ScoregensTop.html">Up</a> </td> <td width="40%" align="right"> <a accesskey="n" href="UtilityTop.html">Next</a></td> </tr> <tr> <td width="40%" align="left" valign="top">GENsone </td> <td width="20%" align="center"> <a accesskey="h" href="index.html">Home</a> </td> <td width="40%" align="right" valign="top"> The Utility Programs</td> </tr> </table> </div> </body> </html>