Module:JI ratios: Difference between revisions

Ganaram inukshuk (talk | contribs)
m testing with smaller default int limit
Ganaram inukshuk (talk | contribs)
re-add ratio filtering
Line 40: Line 40:
-- - Removing ratios that exceed a max Tenney height.
-- - Removing ratios that exceed a max Tenney height.
-- - Removing ratios whose complement would exceed a max Tenney height.
-- - Removing ratios whose complement would exceed a max Tenney height.
 
function p.filter_ratios(ratios, equave, tenney_height, complements_only)
-- TODO: combine into one filter function
--local tenney_height    = tenney_height or 1/0 -- Default Tenney height is +infinity
 
--local complements_only = complements_only or false -- Default is to allow ratios, regardless of whether their complement would be excluded
--[[
 
local filtered_ratios = {}
-- Remove ratios whose complements exceed the int limit and Tenney height.
for i = 1, #ratios do
-- If filtering based on Tenney height is not needed, then Tenney height is set
local complement = rat.mul(rat.inv(ratios[i]), equave)
-- to infinity instead, which should be done by the calling function.
local ratio_th  = rat.tenney_height(ratios[i])
function p.filter_ratios_by_complements(ratios, equave, fine_search_args)
local compl_th  = rat.tenney_height(complement)
if fine_search_args["Complements Only"] then
local filtered_ratios = {}
-- Are the ratios within the Tenney height?
for i = 1, #ratios do
local ratio_within_th = ratio_th <= tenney_height
local complement = rat.mul(rat.inv(ratios[i]), equave)
local compl_within_th = compl_th <= tenney_height
if rat.int_limit(complement) <= fine_search_args["Int Limit"] and rat.tenney_height(complement) <= fine_search_args["Tenney Height"] then
if complements_only then
-- Only include ratios if its complement is also included.
if ratio_within_th and compl_within_th then
table.insert(filtered_ratios, ratios[i])
end
else
-- Include ratios regardless of whether its complement is included.
if ratio_within_th then
table.insert(filtered_ratios, ratios[i])
table.insert(filtered_ratios, ratios[i])
end
end
end
return filtered_ratios
else
return ratios
end
end
-- Remove ratios that exceed the Tenney height. This does nothing if the Tenney
-- height is infinity.
function p.filter_ratios_by_tenney_height(ratios, equave, fine_search_args)
local filtered_ratios = {}
for i = 1, #ratios do
if rat.tenney_height(ratios[i]) <= (fine_search_args["Tenney Height"] or math.huge) then
table.insert(filtered_ratios, ratios[i])
end
end
end
end
return filtered_ratios
return filtered_ratios
end
end
]]--


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
Line 322: Line 315:
prime_limit = args["Prime Limit"]
prime_limit = args["Prime Limit"]
subgroup    = args["Subgroup"]
subgroup    = args["Subgroup"]
-- Filtering args
complements_only = args["Complements Only"] or false -- Default is to include all ratios
tenney_height    = args["Tenney Height"]    or 1/0 -- Default Tenney height is infinity
local ratios = {}
local ratios = {}
Line 331: Line 328:
ratios = p.search_by_int_limit(equave, int_limit)
ratios = p.search_by_int_limit(equave, int_limit)
end
end
-- Filter ratios
ratios = p.filter_ratios(ratios, equave, tenney_height, complements_only)
return ratios
return ratios
Line 380: Line 380:


function p.tester()
function p.tester()
return p.ratios_as_string(p._ji_ratios(p.parse_args("Int Limit: 30; Equave: 3/1")))
return p.ratios_as_string(p._ji_ratios(p.parse_args("Int Limit: 16; Equave: 3/1; Complements Only: 0")))
end
end