Module:JI ratios: Difference between revisions

Ganaram inukshuk (talk | contribs)
m Rename functions
Ganaram inukshuk (talk | contribs)
Add subgroup and prime limit options to search-by-params
Line 49: Line 49:
local tenney_height = tenney_height or 1/0 -- Defualt tenney height is infinity.
local tenney_height = tenney_height or 1/0 -- Defualt tenney height is infinity.
int_limit = math.max(0, math.min(INT_LIMIT_MAX, int_limit))
int_limit = math.max(1, math.min(INT_LIMIT_MAX, int_limit))
local init_ratios = {{1,1}, {1,0} }
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 182: Line 182:
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


-- Int-limit-based search; finds ratios between 1/1 and an equave, within a
-- Prime-limit-based search; finds ratios between 1/1 and an equave, within a
-- prime limit. An int limit is passed in to limit the size of output, since
-- prime limit. An int limit is passed in to limit the size of output, since
-- prime limits are inifinite sets. An optional tenney height can be passed in
-- prime limits are inifinite sets. An optional tenney height can be passed in
Line 218: Line 218:
--------------------------------------------------------------------------------
--------------------------------------------------------------------------------


-- Search for ratios based on params passed in. Each param is its own
-- Search for ratios based on params passed in. Certain params have their own
-- function call. Params must be parsed first.
-- function calls.
function p.search_by_params(params, equave)
function p.search_by_params(params, equave)
local equave = equave or rat.new(2,1)
local equave = equave or rat.new(2,1)
Line 226: Line 226:
-- will default to the hardcoded default value.
-- will default to the hardcoded default value.
local ratios = {}
local ratios = {}
if params["Int Limit"] ~= nil then
if params["Prime Limit"] ~= nil and params["Int Limit"] ~= nil then
ratios = p.search_by_prime_limit_within_equave(params["Prime Limit"], equave, params["Int Limit"], params["Tenney Height"])
elseif params["Subgroup"] ~= nil and params["Int Limit"] ~= nil then
ratios = p.search_by_subgroup_within_equave(params["Subgroup"], equave, params["Int Limit"], params["Tenney Height"])
elseif params["Int Limit"] ~= nil then
ratios = p.search_within_equave(equave, params["Int Limit"], params["Tenney Height"])
ratios = p.search_within_equave(equave, params["Int Limit"], params["Tenney Height"])
end
end
Line 242: Line 246:
if parsed["Tenney Height"] ~= nil then
if parsed["Tenney Height"] ~= nil then
parsed["Tenney Height"] = tonumber(parsed["Tenney Height"])
parsed["Tenney Height"] = tonumber(parsed["Tenney Height"])
end
if parsed["Prime Limit"] ~= nil then
parsed["Prime Limit"] = tonumber(parsed["Prime Limit"])
end
if parsed["Subgroup"] ~= nil then
parsed["Subgroup"] = tip.parse_numeric_entries(parsed["Subgroup"], ".")
end
end
Line 249: Line 261:
function p.search_param_footnotes(search_params)
function p.search_param_footnotes(search_params)
local result = "Not all notable ratios may be shown, and other interpretations are possible."
local result = "Not all notable ratios may be shown, and other interpretations are possible."
local search_text = ""
if search_params["Int Limit"] ~= nil then
if search_params["Prime Limit"] ~= nil then
local tenney_height_text = string.format("Ratios shown are within the %s-integer limit", search_params["Int Limit"])
search_text = string.format("Ratios shown are within the %s-prime limit.", search_params["Prime Limit"])
local int_limit_text = search_params["Tenney Height"] ~= nil and string.format(", capped at a Tenney height of %.1f.", search_params["Tenney Height"]) or "."
elseif search_params["Subgroup"] ~= nil then
result = tenney_height_text .. ". " .. result
search_text = string.format("Ratios shown are within the %s subgroup.", table.concat(search_params["Subgroup"], "."))
elseif search_params["Int Limit"] ~= nil then
search_text = string.format("Ratios shown are within the %s-integer limit.", search_params["Int Limit"])
end
end
result = search_text .. " " .. result
return result
return result
end
end
Line 341: Line 358:
function p.tester()
function p.tester()


local primes = { 2, 3, 5, 7, 11, 13, 17, 19 }
local ratios = p.search_by_subgroup_within_equave(nil, primes, 4000, nil)
return p.ratios_as_text(ratios)
--return p.ratios_as_text(ratios)
return p.parse_search_params("Prime Limit: 19")
end
end


return p
return p