Module:Mediants: Difference between revisions
Changed filter functions to be two-param, where the first param is a table that has both the mediant and depth; may momentarily break dependent modules |
Filter functions -> Search functions, since filtering should suggest finer control over what ratios are allowed, which cannot be done with search functions which limit how far to look for ratios; may potentially break dependent templates |
||
| Line 6: | Line 6: | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
------------------------------- | ------------------------------- SEARCH FUNCTIONS ------------------------------- | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
-- | -- Search functions determine whether a mediant meets a specific criteria for | ||
-- being added to a set of mediants, be it based on something about the mediant, | -- being added to a set of mediants, be it based on something about the mediant, | ||
-- its search depth, or both. | -- its search depth, or both. | ||
-- NOTE: some search criteria, such as prime limit, are considered unsuitable, | |||
-- since mediants not within a prime limit are used to find ratios within a | |||
-- prime limit, it will likely prevent desired ratios from being found at all. | |||
-- For this reason, these functions are meant for broad search, and finer | |||
-- filtering must be done afterwards. | |||
-- A | -- A search function has two params: a table containing the mediant and the | ||
-- depth it was found at, and a search param (which can be a table of search | |||
-- params, for finer control). | |||
-- Int limit | -- Int limit search determines whether a ratio is within an int limit. Does not | ||
-- use depth. | -- use depth. | ||
function p. | function p.int_limit_search(mediant_data, int_limit) | ||
local mediant = mediant_data["mediant"] | local mediant = mediant_data["mediant"] | ||
return math.max(mediant[1], mediant[2]) <= int_limit | return math.max(mediant[1], mediant[2]) <= int_limit | ||
end | end | ||
-- Depth | -- Depth search determines whether a ratio is within a target depth. Does not | ||
-- use the mediant itself. | -- use the mediant itself. | ||
function p. | function p.depth_search(mediant_data, search_depth) | ||
local depth = mediant_data["depth"] | local depth = mediant_data["depth"] | ||
return depth <= search_depth | return depth <= search_depth | ||
end | end | ||
-- Tenney height | -- Tenney height search determines whether a ratio is within a target Tenney | ||
-- height. Does not use depth. | -- height. Does not use depth. | ||
function p. | function p.tenney_height_search(mediant_data, tenney_height) | ||
local mediant = mediant_data["mediant"] | local mediant = mediant_data["mediant"] | ||
return math.log(mediant[1] * mediant[2]) / math.log(2) <= tenney_height | return math.log(mediant[1] * mediant[2]) / math.log(2) <= tenney_height | ||
| Line 48: | Line 54: | ||
-- Find mediants by filter, where the filter function and its args are passed in | -- Find mediants by filter, where the filter function and its args are passed in | ||
-- as part of the function call. | -- as part of the function call. | ||
function p. | function p.find_mediants_by_search_func(init_ratios, search_func, search_args) | ||
local init_ratios = init_ratios or {{1,1}, {1,0}} | local init_ratios = init_ratios or {{1,1}, {1,0}} | ||
| Line 76: | Line 82: | ||
local mediant_data = { ["mediant"] = mediant, ["depth"] = new_depth } | local mediant_data = { ["mediant"] = mediant, ["depth"] = new_depth } | ||
if | if search_func(mediant_data, search_args) then | ||
table.insert(new_ratios, mediant) | table.insert(new_ratios, mediant) | ||
table.insert(new_depths, new_depth) | table.insert(new_depths, new_depth) | ||
| Line 93: | Line 99: | ||
-- Find mediants by filter, where the filter function and its args are passed in | -- Find mediants by filter, where the filter function and its args are passed in | ||
-- as part of the function call. Only returns mediants, not depths. | -- as part of the function call. Only returns mediants, not depths. | ||
function p. | function p.find_only_mediants_by_search_func(init_ratios, search_func, search_args) | ||
local init_ratios = init_ratios or {{1,1}, {1,0}} | local init_ratios = init_ratios or {{1,1}, {1,0}} | ||
local ratios, depths | local ratios, depths | ||
ratios, depths = p. | ratios, depths = p.find_mediants_by_search_func(init_ratios, search_func, search_args) | ||
return ratios | return ratios | ||
end | end | ||
| Line 116: | Line 122: | ||
local ratios, depths | local ratios, depths | ||
ratios, depths = p. | ratios, depths = p.find_mediants_by_search_func(init_ratios, p.depth_search, depth) | ||
return ratios, depths | return ratios, depths | ||
| Line 128: | Line 134: | ||
local ratios, depths | local ratios, depths | ||
ratios, depths = p. | ratios, depths = p.find_mediants_by_search_func(init_ratios, p.depth_search, depth) | ||
return ratios | return ratios | ||
| Line 138: | Line 144: | ||
function p.tester() | function p.tester() | ||
local func = p. | local func = p.int_limit_search | ||
local ratios, depths = p. | local ratios, depths = p.find_mediants_by_search_func({{1,1}, {1,0}}, func, 50) | ||
ratios = p.find_mediants({{1,1}, {1,0}}, | --ratios, depths = p.find_mediants({{1,1}, {1,0}}, 7) | ||
local generators = {} | local generators = {} | ||
for i = 1, #ratios do | for i = 1, #ratios do | ||
| Line 148: | Line 154: | ||
local gcd = utils._gcd(ratios[i][1], ratios[i][2]) | local gcd = utils._gcd(ratios[i][1], ratios[i][2]) | ||
local edo = (ratios[i][1] * 5 + ratios[i][2] * 2)/gcd | local edo = (ratios[i][1] * 5 + ratios[i][2] * 2)/gcd | ||
local new_string = string.format("%s:%s\t%sedo\t%.3f", ratios[i][1]/gcd, ratios[i][2]/gcd, edo, gen) | --local new_string = string.format("%s:%s\t%s\t%sedo\t%.3f", ratios[i][1]/gcd, ratios[i][2]/gcd, depths[i], edo, gen) | ||
local new_string = string.format("%s/%s\t%s", ratios[i][1]/gcd, ratios[i][2]/gcd, depths[i]) | |||
table.insert(generators, new_string) | table.insert(generators, new_string) | ||
end | end | ||