Module:Mediants: Difference between revisions

Ganaram inukshuk (talk | contribs)
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
Ganaram inukshuk (talk | contribs)
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 (which can be a table of search
-- depth it was found at, and a search param.
-- params, for finer control).
-- 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
-- Tenney height search determines whether a ratio is within a target Tenney
-- height. Does not use depth.
function p.tenney_height_search(mediant_data, tenney_height)
local mediant = mediant_data["mediant"]
return math.log(mediant[1] * mediant[2]) / math.log(2) <= tenney_height
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
-- depth-based search is a common enough operation (EG, JI ratio search, tuning
-- it's a common enough operation.
-- spectrum step ratio search).


-- 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.


--------------------------------------------------------------------------------
--------------------------------------------------------------------------------