Module:Limits: Difference between revisions
mNo edit summary |
m Minor optimisation |
||
Line 47: | Line 47: | ||
end | end | ||
end | end | ||
local ratios_ordered = {} | |||
for a_key, a in pairs(ratios) do | for a_key, a in pairs(ratios) do | ||
table.insert(ratios_ordered, a) | |||
end | |||
for i, a in ipairs(ratios_ordered) do | |||
local a_approx = approximate(a) | local a_approx = approximate(a) | ||
for | for j, b in ipairs(ratios_ordered) do | ||
local b_approx = approximate(b) | if i <= j then | ||
local b_approx = approximate(b) | |||
local c = rat.mul(a, b) | |||
local c_approx = approximate(c) | |||
c = p.canonical(c, equave) | |||
local c_key = rat.as_ratio(c) | |||
if ratios[c_key] then | |||
if c_approx ~= a_approx + b_approx then | |||
return false | |||
end | |||
end | end | ||
end | end | ||
Line 67: | Line 73: | ||
end | end | ||
function p.consistency_limit(size, equave, distinct) | function p.consistency_limit(size, equave, distinct, max_n) | ||
max_n = max_n or 1/0 | |||
equave = equave or 2 | equave = equave or 2 | ||
distinct = distinct or false | distinct = distinct or false | ||
Line 83: | Line 90: | ||
last_n = n | last_n = n | ||
n = n + 1 | n = n + 1 | ||
end | |||
if n > max_n then | |||
break | |||
end | end | ||
end | end | ||
return | return last_n | ||
end | end | ||
return p | return p |