Module:Mediants: Difference between revisions
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 |
Removed tenney height search (for now); comments/todo |
||
| Line 4: | Line 4: | ||
-- Module for finding mediants, either by search depth or by search function. | -- Module for finding mediants, either by search depth or by search function. | ||
-- TODO: Add int-limit search | |||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
| Line 19: | Line 21: | ||
-- A search function has two params: a table containing the mediant and the | -- A search function has two params: a table containing the mediant and the | ||
-- depth it was found at, and a search param | -- depth it was found at, and a search param. | ||
-- | -- Mediant data, the first param, is of the form: | ||
-- { ["mediant"] = { p, q }, ["depth"] = d }, where, p, q, d are integers. | |||
-- The search params can be a single numeric value, or a table of values for | |||
-- finer control. | |||
-- Int limit search determines whether a ratio is within an int limit. Does not | -- Int limit search determines whether a ratio is within an int limit. Does not | ||
-- use depth. | -- use depth. Meant for use with searching for JI ratios. | ||
function p.int_limit_search(mediant_data, int_limit) | function p.int_limit_search(mediant_data, int_limit) | ||
local mediant = mediant_data["mediant"] | local mediant = mediant_data["mediant"] | ||
| Line 30: | Line 35: | ||
-- Depth search determines whether a ratio is within a target depth. Does not | -- Depth search determines whether a ratio is within a target depth. Does not | ||
-- use the mediant itself. | -- use the mediant itself. Meant for use with searching for step ratios. | ||
function p.depth_search(mediant_data, search_depth) | 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 | ||
| Line 113: | Line 111: | ||
-- Depth-based search finds mediants by building a tree of mediants up to a | -- Depth-based search finds mediants by building a tree of mediants up to a | ||
-- specified depth. This is made a standalone function under the reasoning that | -- specified depth. This is made a standalone function under the reasoning that | ||
-- | -- it's a common enough operation. | ||
-- Find mediants by depth, how many times mediants are found in a set of ratios. | -- Find mediants by depth, how many times mediants are found in a set of ratios. | ||
| Line 138: | Line 135: | ||
return ratios | return ratios | ||
end | end | ||
-------------------------------------------------------------------------------- | |||
---------------------- INT-LIMIT-BASED SEARCH FUNCTION ------------------------- | |||
-------------------------------------------------------------------------------- | |||
-- Int limit search finds mediants up to an integer limit, not permitting ratios | |||
-- whose numerator or denominator exceeds the int limit. This is made a stand- | |||
-- alone function under the reasoning that it's a common enough operation. | |||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||