Module:No-1s limits: Difference between revisions
Dummy index (talk | contribs) mNo edit summary |
Dummy index (talk | contribs) No edit summary |
||
| (16 intermediate revisions by 2 users not shown) | |||
| Line 1: | Line 1: | ||
local p = {} | |||
local ET = require('Module:ET') | |||
local rat = require('Module:Rational') | local rat = require('Module:Rational') | ||
local | local yesno = require("Module:Yesno") | ||
-- compute all positive ratios n/m with n and m <= q modulo powers of equave | -- compute all positive ratios n/m with n and m <= q modulo powers of equave | ||
| Line 8: | Line 10: | ||
equave = equave or 2 | equave = equave or 2 | ||
local ratios = {} | local ratios = {} | ||
if rat.eq(rat.modulo_mul(rat.new(q, 1), equave), 1) then return ratios end | |||
if previous then | if previous then | ||
for n = | for n = 2, q do | ||
local a = rat.new(n, q) | if not rat.eq(rat.modulo_mul(rat.new(n, 1), equave), 1) then | ||
local a = rat.new(n, q) | |||
a = rat.modulo_mul(a, equave) | |||
local a_key = rat.as_ratio(a) | |||
local b = rat.new(q, n) | |||
b = rat.modulo_mul(b, equave) | |||
local b_key = rat.as_ratio(b) | |||
if previous[a_key] == nil then | |||
ratios[a_key] = a | |||
end | |||
if previous[b_key] == nil then | |||
ratios[b_key] = b | |||
end | |||
end | end | ||
end | end | ||
else | else | ||
for n = | for n = 2, q do | ||
for m = | if not rat.eq(rat.modulo_mul(rat.new(n, 1), equave), 1) then | ||
for m = 2, q do | |||
if not rat.eq(rat.modulo_mul(rat.new(n, 1), equave), 1) then | |||
local a = rat.new(n, m) | |||
a = rat.modulo_mul(a, equave) | |||
local key = rat.as_ratio(a) | |||
ratios[key] = a | |||
end | |||
end | |||
end | end | ||
end | end | ||
| Line 178: | Line 187: | ||
end | end | ||
function p.for_small_edos (frame) | -- find vals generate no-1s consistency intervals | ||
local | -- returns string with wart notation | ||
-- limit must meet no-1s odd-limit consistency | |||
function p.vals(et, limit) | |||
local primes = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43} | |||
local wart = 'abcdefghijklmn' | |||
local patent_val = {} | |||
local wart_dir = {} | |||
local minprime | |||
local val = {} | |||
local rets = {} | |||
for i = 1, #primes do | |||
patent_val[i] = ET.approximate(et, primes[i]) | |||
if ET.cents(et, patent_val[i]) < math.log(primes[i]) / math.log(2) * 1200 then | |||
wart_dir[i] = -1 | |||
else | |||
wart_dir[i] = 1 | |||
end | |||
end | |||
if et.equave == 2 then | |||
minprime = 3 | |||
else | |||
minprime = 2 | |||
end | |||
local previ = 1 | |||
for i = 1, #primes do | |||
local ip = primes[i] | |||
if ip > limit then break end | |||
if ip == et.equave then | |||
val[i] = patent_val[i] | |||
elseif ip == minprime then | |||
val[i] = patent_val[i] | |||
previ = i | |||
else | |||
val[i] = val[previ] + ET.approximate(et, ip / primes[previ]) | |||
previ = i | |||
end | |||
end | |||
rets[1] = '' | |||
if et.equave ~= 2 then | |||
local i = table.find(primes, et.equave) | |||
if i then | |||
rets[1] = rets[1] .. string.sub(wart, i, i) | |||
else | |||
rets[1] = rets[1] .. 'q' | |||
end | |||
end | |||
rets[1] = rets[1] .. et.size | |||
if limit < minprime * minprime then | |||
local nonpatent = false | |||
local binded = false | |||
local bias = 0 | |||
for i = 1, #val do | |||
local ip = primes[i] | |||
if ip == et.equave then | |||
elseif ip == minprime then | |||
bias = wart_dir[i] | |||
else | |||
if val[i] ~= patent_val[i] then | |||
nonpatent = true | |||
elseif wart_dir[i] ~= bias then | |||
binded = true | |||
end | |||
end | |||
end | |||
if nonpatent or not binded then | |||
rets[2] = '' .. rets[1] | |||
for i = 1, #val do | |||
local ip = primes[i] | |||
local difference = (val[i] - patent_val[i]) * wart_dir[i] | |||
if difference > 0 then | |||
rets[1] = rets[1] .. string.rep(string.sub(wart, i, i), difference * 2) | |||
elseif difference < 0 then | |||
rets[1] = rets[1] .. string.rep(string.sub(wart, i, i), -difference * 2 - 1) | |||
end | |||
end | |||
for i = 1, #val do | |||
local ip = primes[i] | |||
if ip ~= et.equave then val[i] = val[i] - bias end | |||
local difference = (val[i] - patent_val[i]) * wart_dir[i] | |||
if difference > 0 then | |||
rets[2] = rets[2] .. string.rep(string.sub(wart, i, i), difference * 2) | |||
elseif difference < 0 then | |||
rets[2] = rets[2] .. string.rep(string.sub(wart, i, i), -difference * 2 - 1) | |||
end | |||
end | |||
if bias > 0 then rets = {rets[2], rets[1]} end | |||
end | |||
else | |||
for i = 1, #val do | |||
local ip = primes[i] | |||
if ip * minprime <= limit then | |||
if val[i] ~= patent_val[i] then | |||
return '(error)' | |||
end | |||
end | |||
local difference = (val[i] - patent_val[i]) * wart_dir[i] | |||
if difference > 0 then | |||
rets[1] = rets[1] .. string.rep(string.sub(wart, i, i), difference * 2) | |||
elseif difference < 0 then | |||
rets[1] = rets[1] .. string.rep(string.sub(wart, i, i), -difference * 2 - 1) | |||
end | |||
end | |||
end | |||
return table.concat (rets, ", ") | |||
end | |||
function p.for_small_edos(frame) | |||
local liners = tonumber(frame.args['lines']) | |||
local debugg = yesno(frame.args['debug']) | |||
local t_body = {} | local t_body = {} | ||
local val = {} | local val = {} | ||
for i = 1, | |||
et = ET.parse('' .. i .. 'edo') | for i = 1, liners do | ||
limit = p.consistency_limit(et, false, 43) | local et = ET.parse('' .. i .. 'edo') | ||
t_body[i] = string.format ("|-\n| %s\n| %s", i, limit) | local limit = p.consistency_limit(et, false, 43) | ||
local vals = p.vals(et, limit) | |||
t_body[i] = string.format("|-\n| %s\n| %s\n| %s", i, limit, vals) | |||
end | end | ||
local result = "{| class=\"wikitable center-all mw-collapsible mw-collapsed\"\n" .. | |||
"|-\n" .. | "|-\n" .. | ||
"! EDO\n" .. | "! EDO\n" .. | ||
"! | "! No-1s consistency limit\n" .. | ||
table.concat (t_body, "\n") .. | "! Associated vals\n" .. | ||
table.concat(t_body, "\n") .. | |||
"\n|}" | "\n|}" | ||
if debugg == true then | |||
result = "<syntaxhighlight lang=\"wikitext\">" .. result .. "</syntaxhighlight>" | |||
end | |||
return frame:preprocess(result) | |||
end | end | ||
return p | return p | ||