MOS scale: Difference between revisions
Wikispaces>genewardsmith **Imported revision 143380977 - Original comment: ** |
Wikispaces>genewardsmith **Imported revision 143392329 - Original comment: ** |
||
| Line 1: | Line 1: | ||
<h2>IMPORTED REVISION FROM WIKISPACES</h2> | <h2>IMPORTED REVISION FROM WIKISPACES</h2> | ||
This is an imported revision from Wikispaces. The revision metadata is included below for reference:<br> | This is an imported revision from Wikispaces. The revision metadata is included below for reference:<br> | ||
: This revision was by author [[User:genewardsmith|genewardsmith]] and made on <tt>2010-05-20 | : This revision was by author [[User:genewardsmith|genewardsmith]] and made on <tt>2010-05-20 02:37:21 UTC</tt>.<br> | ||
: The original revision id was <tt> | : The original revision id was <tt>143392329</tt>.<br> | ||
: The revision comment was: <tt></tt><br> | : The revision comment was: <tt></tt><br> | ||
The revision contents are below, presented both in the original Wikispaces Wikitext format, and in HTML exactly as Wikispaces rendered it.<br> | The revision contents are below, presented both in the original Wikispaces Wikitext format, and in HTML exactly as Wikispaces rendered it.<br> | ||
| Line 128: | Line 128: | ||
==Algorithms== | ==Algorithms== | ||
Below is some Maple code for various mathematical routines having to do with MOS. If you have access to Maple, you can of course copy and run these programs. Even if you do not, since Maple code makes better pseudocode than most languages or computer algebra packages afford, it can be used as pseudocode. For that purpose, it will be helpful to know that "modp(x, n)" means reducing x mod the integer n to 0, 1, ..., n-1 not only when x is an integer, but also when it is a rational number with denominator prime to n. In that case, p/q mod n = r means p = qr mod n. | Below is some Maple code for various mathematical routines having to do with MOS. If you have access to Maple, you can of course copy and run these programs. Even if you do not, since Maple code makes better pseudocode than most languages or computer algebra packages afford, it can be used as pseudocode. For that purpose, it will be helpful to know that "modp(x, n)" means reducing x mod the integer n to 0, 1, ..., n-1 not only when x is an integer, but also when it is a rational number with denominator prime to n. In that case, p/q mod n = r means p = qr mod n. | ||
log2 := proc(x) | |||
# logarithm base 2 | |||
evalf(ln(x)/ln(2)) end: | |||
nextfarey := proc(q, n) | nextfarey := proc(q, n) | ||
| Line 208: | Line 212: | ||
if q > u[1]/u[2] then RETURN((numer(q)+denom(q))/(u[1]+u[2])) fi; | if q > u[1]/u[2] then RETURN((numer(q)+denom(q))/(u[1]+u[2])) fi; | ||
(u[1]+u[2]-numer(q)-denom(q))/(u[1]+u[2]) end: | (u[1]+u[2]-numer(q)-denom(q))/(u[1]+u[2]) end: | ||
Lsgen := proc(g, n) | |||
# given generator g and scale size n determines large-small steps | |||
local q, u, w; | |||
q := round(n*g)/n; | |||
w := n/denom(q); | |||
u := fareypair(q); | |||
if g<u[1] or g>u[2] or g=q then RETURN('false') fi; | |||
if g<q then RETURN([w*denom(u[1]), w*denom(u[2])]) fi; | |||
[w*denom(u[2]), w*denom(u[1])] end: | |||
revlist := proc(l) | |||
# reverse of list | |||
local i, v, e; | |||
e := nops(l); | |||
for i from 1 to e do | |||
v[i] := l[e-i+1] od; | |||
convert(convert(v,array),list) end: | |||
invcon := proc(l) | |||
# inverse continued fraction | |||
local d, i, h, k; | |||
h[-2] := 0; | |||
h[-1] := 1; | |||
k[-2] := 1; | |||
k[-1] := 0; | |||
for i from 0 to nops(l)-1 do | |||
h[i] := l[i+1]*h[i-1] + h[i-2]; | |||
k[i] := l[i+1]*k[i-1] + k[i-2]; | |||
d[i+1] := h[i]/k[i] od; | |||
convert(convert(d, array), list) end: | |||
quest := proc(x) | |||
# Minkowski ? function | |||
local i, j, d, l, s, t; | |||
l := convert(x, confrac); | |||
d := nops(l); | |||
s := l[1]; | |||
for i from 2 to d do | |||
t := 1; | |||
for j from 2 to i do | |||
t := t - l[j] od; | |||
s := s + (-1)^i * 2^t od; | |||
if type(x, float) then s := evalf(s) fi; | |||
s end: | |||
box := proc(x) | |||
# inverse ? function | |||
local d, e, i, n, w, y; | |||
if type(x, integer) then RETURN(x) fi; | |||
y := x-floor(x); | |||
if y = 1/8 then RETURN(floor(x)+1/4) fi; | |||
w := round(log2(10)*Digits)-5; | |||
n := round(2^w * y); | |||
i :=0; | |||
while n>0 do | |||
i := i+1; | |||
if modp(n,2)=0 then | |||
d[i] := padic[ordp](n, 2); | |||
n := n/2^d[i]; | |||
else | |||
d[i] := padic[ordp](n+1, 2); | |||
n := (n-2^d[i]+1)/2^d[i] fi od; | |||
e := convert(convert(d, array), list); | |||
e := subsop(1=NULL,e); | |||
w := ceil(-log2(y)); | |||
e := [op(e), w]; | |||
e := [op(e), floor(x)]; | |||
e := revlist(e); | |||
n := invcon(e); | |||
w := n[nops(n)]; | |||
if type(x, rational) and modp(denom(x), 2)=0 then RETURN(w) fi; | |||
evalf(w) end: | |||
==[[MOSDiagrams]]== </pre></div> | ==[[MOSDiagrams]]== </pre></div> | ||
| Line 560: | Line 637: | ||
<!-- ws:start:WikiTextHeadingRule:18:&lt;h2&gt; --><h2 id="toc9"><a name="MOS scales-Algorithms"></a><!-- ws:end:WikiTextHeadingRule:18 -->Algorithms</h2> | <!-- ws:start:WikiTextHeadingRule:18:&lt;h2&gt; --><h2 id="toc9"><a name="MOS scales-Algorithms"></a><!-- ws:end:WikiTextHeadingRule:18 -->Algorithms</h2> | ||
Below is some Maple code for various mathematical routines having to do with MOS. If you have access to Maple, you can of course copy and run these programs. Even if you do not, since Maple code makes better pseudocode than most languages or computer algebra packages afford, it can be used as pseudocode. For that purpose, it will be helpful to know that &quot;modp(x, n)&quot; means reducing x mod the integer n to 0, 1, ..., n-1 not only when x is an integer, but also when it is a rational number with denominator prime to n. In that case, p/q mod n = r means p = qr mod n.<br /> | Below is some Maple code for various mathematical routines having to do with MOS. If you have access to Maple, you can of course copy and run these programs. Even if you do not, since Maple code makes better pseudocode than most languages or computer algebra packages afford, it can be used as pseudocode. For that purpose, it will be helpful to know that &quot;modp(x, n)&quot; means reducing x mod the integer n to 0, 1, ..., n-1 not only when x is an integer, but also when it is a rational number with denominator prime to n. In that case, p/q mod n = r means p = qr mod n.<br /> | ||
<br /> | |||
log2 := proc(x)<br /> | |||
<ol><li>logarithm base 2</li></ol>evalf(ln(x)/ln(2)) end:<br /> | |||
<br /> | <br /> | ||
nextfarey := proc(q, n)<br /> | nextfarey := proc(q, n)<br /> | ||
| Line 640: | Line 720: | ||
if q &gt; u[1]/u[2] then RETURN((numer(q)+denom(q))/(u[1]+u[2])) fi;<br /> | if q &gt; u[1]/u[2] then RETURN((numer(q)+denom(q))/(u[1]+u[2])) fi;<br /> | ||
(u[1]+u[2]-numer(q)-denom(q))/(u[1]+u[2]) end:<br /> | (u[1]+u[2]-numer(q)-denom(q))/(u[1]+u[2]) end:<br /> | ||
<br /> | |||
Lsgen := proc(g, n)<br /> | |||
<ol><li>given generator g and scale size n determines large-small steps</li></ol>local q, u, w;<br /> | |||
q := round(n*g)/n;<br /> | |||
w := n/denom(q);<br /> | |||
u := fareypair(q);<br /> | |||
if g&lt;u[1] or g&gt;u[2] or g=q then RETURN('false') fi;<br /> | |||
if g&lt;q then RETURN([w*denom(u[1]), w*denom(u[2])]) fi;<br /> | |||
[w*denom(u[2]), w*denom(u[1])] end:<br /> | |||
<br /> | |||
revlist := proc(l)<br /> | |||
<ol><li>reverse of list</li></ol>local i, v, e;<br /> | |||
e := nops(l);<br /> | |||
for i from 1 to e do<br /> | |||
v[i] := l[e-i+1] od;<br /> | |||
convert(convert(v,array),list) end:<br /> | |||
<br /> | |||
invcon := proc(l)<br /> | |||
<ol><li>inverse continued fraction</li></ol>local d, i, h, k;<br /> | |||
h[-2] := 0;<br /> | |||
h[-1] := 1;<br /> | |||
k[-2] := 1;<br /> | |||
k[-1] := 0;<br /> | |||
for i from 0 to nops(l)-1 do<br /> | |||
h[i] := l[i+1]*h[i-1] + h[i-2];<br /> | |||
k[i] := l[i+1]*k[i-1] + k[i-2];<br /> | |||
d[i+1] := h[i]/k[i] od;<br /> | |||
convert(convert(d, array), list) end:<br /> | |||
<br /> | |||
quest := proc(x)<br /> | |||
<ol><li>Minkowski ? function</li></ol>local i, j, d, l, s, t;<br /> | |||
l := convert(x, confrac);<br /> | |||
d := nops(l);<br /> | |||
s := l[1];<br /> | |||
for i from 2 to d do<br /> | |||
t := 1;<br /> | |||
for j from 2 to i do<br /> | |||
t := t - l[j] od;<br /> | |||
s := s + (-1)^i * 2^t od;<br /> | |||
if type(x, float) then s := evalf(s) fi;<br /> | |||
s end:<br /> | |||
<br /> | |||
box := proc(x)<br /> | |||
<ol><li>inverse ? function</li></ol>local d, e, i, n, w, y;<br /> | |||
if type(x, integer) then RETURN(x) fi;<br /> | |||
y := x-floor(x);<br /> | |||
if y = 1/8 then RETURN(floor(x)+1/4) fi;<br /> | |||
w := round(log2(10)*Digits)-5;<br /> | |||
n := round(2^w * y);<br /> | |||
i :=0;<br /> | |||
while n&gt;0 do<br /> | |||
i := i+1;<br /> | |||
if modp(n,2)=0 then<br /> | |||
d[i] := padic[ordp](n, 2);<br /> | |||
n := n/2^d[i];<br /> | |||
else<br /> | |||
d[i] := padic[ordp](n+1, 2);<br /> | |||
n := (n-2^d[i]+1)/2^d[i] fi od;<br /> | |||
e := convert(convert(d, array), list);<br /> | |||
e := subsop(1=NULL,e);<br /> | |||
w := ceil(-log2(y));<br /> | |||
e := [op(e), w];<br /> | |||
e := [op(e), floor(x)];<br /> | |||
e := revlist(e); <br /> | |||
n := invcon(e);<br /> | |||
w := n[nops(n)];<br /> | |||
if type(x, rational) and modp(denom(x), 2)=0 then RETURN(w) fi;<br /> | |||
evalf(w) end:<br /> | |||
<br /> | <br /> | ||
<!-- ws:start:WikiTextHeadingRule:20:&lt;h2&gt; --><h2 id="toc10"><a name="MOS scales-MOSDiagrams"></a><!-- ws:end:WikiTextHeadingRule:20 --><a class="wiki_link" href="/MOSDiagrams">MOSDiagrams</a></h2> | <!-- ws:start:WikiTextHeadingRule:20:&lt;h2&gt; --><h2 id="toc10"><a name="MOS scales-MOSDiagrams"></a><!-- ws:end:WikiTextHeadingRule:20 --><a class="wiki_link" href="/MOSDiagrams">MOSDiagrams</a></h2> | ||
</body></html></pre></div> | </body></html></pre></div> | ||