Module:JI ratios: Difference between revisions

Ganaram inukshuk (talk | contribs)
Rename/reorganize functions; add prime-limit search by reusing subgroup-search code
Ganaram inukshuk (talk | contribs)
Int-limit search now removes ratios that exceed the equave
Line 100: Line 100:
int_limit = math.max(0, math.min(INT_LIMIT_MAX, int_limit))
int_limit = math.max(0, math.min(INT_LIMIT_MAX, int_limit))
local init_ratios = {{1,1}, {2,1}}
local init_ratios = {{1,1}, {1,0} }
local search_func = p.int_limit_mediant_search
local search_func = p.int_limit_mediant_search
local search_args = { ["equave"] = equave, ["int_limit"] = int_limit, ["tenney_height"] = tenney_height }
local search_args = { ["equave"] = equave, ["int_limit"] = int_limit, ["tenney_height"] = tenney_height }
Line 108: Line 108:
for i = 1, #ratios do
for i = 1, #ratios do
ratios[i] = rat.new(ratios[i][1], ratios[i][2])
ratios[i] = rat.new(ratios[i][1], ratios[i][2])
end
-- Remove ratios that exceed the equave.
-- Note that mediant search results in sorted ratios, so remove them from
-- the end until there's no more to remove.
while rat.gt(ratios[#ratios], equave) do
table.remove(ratios, #ratios)
end
end
Line 270: Line 277:
if params["Int Limit"] ~= nil then
if params["Int Limit"] ~= nil then
ratios = p.search_by_int_limit(params["Int Limit"], max_cents)
ratios = p.search_by_int_limit(params["Int Limit"], max_cents)
end
if params["Prime Limit"] ~= nil then
ratios = p.filter_by_prime_limit(ratios, params["Prime Limit"])
end
end
Line 316: Line 319:
---------------------------- RATIO FILTER FUNCTIONS ----------------------------
---------------------------- RATIO FILTER FUNCTIONS ----------------------------
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------
-- Ratio filter functions are, for the most part, no longer needed.


-- Filter ratios by Tenney height.
-- Filter ratios by Tenney height.
Line 343: Line 348:
end
end
return filtered_ratios
return filtered_ratios
end
-- Filter ratios by (prime) subgroup. EG: 2.3.5.7
function p.filter_by_subgroup(ratios, subgroup)
end
-- Filter ratios by rational/nonprime subgroup. EG, 2.7/2.11/2, or 2.5.7.9
-- Does not support irrational subgroups.
function p.filter_by_nonprime_subgroup(ratios, subgroup)
end
end


Line 439: Line 433:
function p.tester()
function p.tester()


local ratios = p.search_by_prime_limit_within_equave()
local ratios = p.search_by_int_limit_within_equave(30, rat.new(4000,2999))
return p.ratios_as_text(ratios)
return p.ratios_as_text(ratios)