Module:JI ratio finder: Difference between revisions

Ganaram inukshuk (talk | contribs)
Added no-equave-factors-tenney-height
Ganaram inukshuk (talk | contribs)
Added NEFTH filtering
Line 24: Line 24:
local equave = equave or rat.new(2)
local equave = equave or rat.new(2)
local ratio_copy = rat.copy(ratio)
for key, value in pairs(equave) do
for key, value in pairs(equave) do
if tonumber(key) ~= nil and ratio[key] ~= nil then
if tonumber(key) ~= nil and ratio_copy[key] ~= nil then
ratio[key] = 0
ratio_copy[key] = 0
end
end
end
end
return rat.tenney_height(ratio)
return rat.tenney_height(ratio_copy)
end
end


Line 243: Line 244:
for i = 1, #ratios do
for i = 1, #ratios do
if p.complement_agnostic_tenney_height(ratios[i], equave) <= tenney_height then
if p.complement_agnostic_tenney_height(ratios[i], equave) <= tenney_height then
table.insert(filtered_ratios, ratios[i])
end
end
return filtered_ratios
end
-- Filters ratios by no-equave-factors Tenney height
-- Filters ratios where lg(numerator) + lg(denominator) does not exceed the
-- given height, where lg is log-base-2
-- If the equave complement of that ratio has a lower Tenney height, the ratio
-- is kept instead.
function p.filter_ratios_by_no_equave_factors_tenney_height(ratios, tenney_height, equave)
local ratios = ratios or { rat.new(5, 4), rat.new(81, 64), rat.new(9, 7) }
local tenney_height = tenney_height or 5.0
local equave = equave or rat.new(2)
local filtered_ratios = {}
for i = 1, #ratios do
if p.no_equave_factors_tenney_height(ratios[i], equave) <= tenney_height then
table.insert(filtered_ratios, ratios[i])
table.insert(filtered_ratios, ratios[i])
end
end