Mathematics of MOS: Difference between revisions

Spt3125 (talk | contribs)
Algorithms: reformatted code (damaged by MediaWiki import)
Spt3125 (talk | contribs)
Algorithms: code correction: > <
Line 81: Line 81:


  '''nextfarey''' := proc(q, n)
  '''nextfarey''' := proc(q, n)
  # next in row n of Farey sequence from q, 0 <= q <= 1
  # next in row n of Farey sequence from q, 0 &lt;= q &lt;= 1
  local a, b, r, s;
  local a, b, r, s;
  if q >= (n-1)/n then RETURN(1) fi;
  if q &gt;= (n-1)/n then RETURN(1) fi;
  a := numer(q);
  a := numer(q);
  b := denom(q);
  b := denom(q);
Line 91: Line 91:


  '''prevfarey''' := proc(q, n)
  '''prevfarey''' := proc(q, n)
  # previous in row n of Farey sequence from q, 0 <= q <= 1
  # previous in row n of Farey sequence from q, 0 &lt;= q &lt;= 1
  local a, b, r, s;
  local a, b, r, s;
  if q=0 then RETURN(0) fi;
  if q=0 then RETURN(0) fi;
Line 120: Line 120:
  # expansion of a convergent list to semiconvergents
  # expansion of a convergent list to semiconvergents
  local i, j, s, d;
  local i, j, s, d;
  if nops(l)<3 then RETURN(l) fi;
  if nops(l)&lt;3 then RETURN(l) fi;
  d[1] := l[1];
  d[1] := l[1];
  d[2] := l[2];
  d[2] := l[2];
Line 155: Line 155:
  if u[2]=1 then RETURN(1/(u[1]+1)) fi;
  if u[2]=1 then RETURN(1/(u[1]+1)) fi;
  r := igcd(u[1], u[2]);
  r := igcd(u[1], u[2]);
  if r>1 then RETURN(medi([u[1]/r, u[2]/r])) fi;
  if r&gt;1 then RETURN(medi([u[1]/r, u[2]/r])) fi;
  q := '''penult'''(u[1]/u[2]);
  q := '''penult'''(u[1]/u[2]);
  if q > u[1]/u[2] then RETURN((numer(q)+denom(q))/(u[1]+u[2])) fi;
  if q &gt; 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:


Line 166: Line 166:
  w := n/denom(q);
  w := n/denom(q);
  u := '''fareypair'''(q);
  u := '''fareypair'''(q);
  if g<u[1] or g>u[2] or g=q then RETURN('false') fi;
  if g&lt;u[1] or g&gt;u[2] or g=q then RETURN('false') fi;
  if g<q then RETURN([w*denom(u[1]), w*denom(u[2])]) fi;
  if g&lt;q then RETURN([w*denom(u[1]), w*denom(u[2])]) fi;
  [w*denom(u[2]), w*denom(u[1])] end:
  [w*denom(u[2]), w*denom(u[1])] end:


Line 214: Line 214:
  n := round(2^w * y);
  n := round(2^w * y);
  i :=0;
  i :=0;
  while n>0 do
  while n&gt;0 do
  i := i+1;
  i := i+1;
  if modp(n,2)=0 then
  if modp(n,2)=0 then