Module:JI ratios: Difference between revisions
Moar cleanup; refined subgroup-search code to implement bfs |
Found a way to use mediant search with ratios 1/1 and 1/0 to find ratios from 1/1 to arbitrary equave, without finding ratios from 1/1 to 2/1 and then multiplying by (powers of) 2; requires significant rewrites to int limit search and dependent modules; updated todo |
||
| Line 6: | Line 6: | ||
-- TODO: | -- TODO: | ||
-- Adopt mediants module | -- Adopt mediants module by using custom mediant search function | ||
-- Add tenney height to int-limit and subgroup search so filtering is done | |||
-- mid-search instead of afterwards | |||
-- Template for handling multiple entry of JI ratios into a template, and for | -- Template for handling multiple entry of JI ratios into a template, and for | ||
| Line 382: | Line 384: | ||
end | end | ||
return texts | return texts | ||
end | |||
-- Int limit search function, with an equave cutoff. | |||
-- Ratios are added by int limit as normally except when the mediant straddles | |||
-- the equave. If the equave is strictly less than the first ratio, add the | |||
-- mediant formed by it and ratio 2. This minimizes the number of ratios larger | |||
-- than the equave being added, but requires some post-search cleanup. | |||
function p.int_limit_equave_cutoff_search(mediant_data, search_args) | |||
local mediant = mediant_data["mediant"] | |||
local ratio_1 = mediant_data["ratio_1"] | |||
local equave = search_args["equave"] | |||
local int_limit = search_args["int_limit"] | |||
local equave_as_float = equave[1] / equave[2] | |||
local rat_1_as_float = ratio_1[1] / ratio_1[2] | |||
return math.max(mediant[1], mediant[2]) <= int_limit and rat_1_as_float < equave_as_float | |||
end | end | ||
| Line 401: | Line 420: | ||
local max_product = 5000 | local max_product = 5000 | ||
return p.ratios_as_text(p.search_by_subgroup(factors, max_product, {3,1})) | --return p.ratios_as_text(p.search_by_subgroup(factors, max_product, {3,1})) | ||
--return p.find_products(factors, max_product) | --return p.find_products(factors, max_product) | ||
local search_args = {} | |||
search_args["equave"] = {5,4} | |||
search_args["int_limit"] = 30 | |||
local ratios = m.find_only_mediants_by_search_func({{1,1},{1,0}}, p.int_limit_equave_cutoff_search, search_args) | |||
--local ratios = p.search_by_int_limit(30) | |||
-- Convert to ratios that Module:Rational can work with | |||
for i = 1, #ratios do | |||
ratios[i] = rat.new(ratios[i][1], ratios[i][2]) | |||
end | |||
return p.ratios_as_text(ratios) | |||
end | end | ||
return p | return p | ||