Module:JI ratios: Difference between revisions
mNo edit summary |
comment out filter functions, to be merged into one filter function; remove redundant/unneeded functions/calls |
||
| Line 27: | Line 27: | ||
-- - Tenney height is used for further filtering of ratios, and is considered | -- - Tenney height is used for further filtering of ratios, and is considered | ||
-- optional. If omitted, tenney height defaults to infinity. | -- optional. If omitted, tenney height defaults to infinity. | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
| Line 38: | Line 32: | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
-- Filter | -- Filter function removes certain ratios that don't meet some requirement. | ||
-- Filters currently include: | -- Filters currently include: | ||
-- - Removing ratios that exceed a max Tenney height. | -- - Removing ratios that exceed a max Tenney height. | ||
-- - Removing ratios whose complement would exceed a max Tenney height. | -- - Removing ratios whose complement would exceed a max Tenney height. | ||
-- TODO: combine into one filter function | |||
--[[ | |||
-- Remove ratios whose complements exceed the int limit and Tenney height. | -- Remove ratios whose complements exceed the int limit and Tenney height. | ||
| Line 72: | Line 70: | ||
return filtered_ratios | return filtered_ratios | ||
end | end | ||
]]-- | |||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
| Line 77: | Line 77: | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
-- Int | -- Int limit search finds ratios from 1/1 to an equave | ||
function p.search_by_int_limit(equave, int_limit) | |||
function p. | local equave = equave or rat.new(2,1) -- Defualt equave is 2/1. | ||
local equave = equave or rat.new(2,1) | local int_limit = int_limit or 50 -- Default is 50 | ||
-- | |||
local init_ratios = {{1,1}, {1,0}} | local init_ratios = {{1,1}, {1,0}} | ||
local ratios = med.find_only_mediants_by_int_limit(init_ratios, | local ratios = med.find_only_mediants_by_int_limit(init_ratios, int_limit) | ||
-- Convert to ratios that Module:Rational can work with | -- Convert to ratios that Module:Rational can work with | ||
| Line 100: | Line 99: | ||
-- Filter out ratios that exceed the int limit. | -- Filter out ratios that exceed the int limit. | ||
-- Then filter out ratios if their equave complement would be filtered out. | -- Then filter out ratios if their equave complement would be filtered out. | ||
ratios = p.filter_ratios_by_tenney_height(ratios, equave, fine_search_args) | --ratios = p.filter_ratios_by_tenney_height(ratios, equave, fine_search_args) | ||
ratios = p.filter_ratios_by_complements(ratios, equave, fine_search_args) | --ratios = p.filter_ratios_by_complements(ratios, equave, fine_search_args) | ||
return ratios | return ratios | ||
| Line 116: | Line 115: | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
function p.search_by_prime_limit( | function p.search_by_prime_limit(equave, int_limit, prime_limit) | ||
local equave = equave or rat.new(2,1) -- Defualt equave is 2/1. | |||
local equave = equave or rat.new(2,1) | local int_limit = int_limit or 50 -- Default is 50 | ||
--local | local prime_limit = prime_limit or 5 -- Default is 5-prime-limit | ||
-- | -- Convert prime limit into an equivalent subgroup (EG, 7-limit becomes | ||
-- 2.3.5.7) so that it can be passed into the subgroup search function. | |||
local primes = {} | local primes = {} | ||
for i = 2, prime_limit do | for i = 2, prime_limit do | ||
| Line 136: | Line 136: | ||
end | end | ||
return p.search_by_subgroup(equave, int_limit, primes) | |||
return p.search_by_subgroup( | |||
end | end | ||
| Line 145: | Line 143: | ||
-------------------------------------------------------------------------------- | -------------------------------------------------------------------------------- | ||
function p.search_by_subgroup(subgroup | function p.search_by_subgroup(equave, int_limit, subgroup) | ||
local subgroup = subgroup or {rat.new(2), rat.new(3), rat.new(7)} | local equave = equave or rat.new(2,1) -- Defualt equave is 2/1. | ||
local int_limit = int_limit or 50 -- Default is 50 | |||
-- | local subgroup = subgroup or {rat.new(2), rat.new(3), rat.new(7)} -- Default is 2.3.7 subgroup | ||
-- Search for ratios within int limit within subgroup by multiplication. | -- Search for ratios within int limit within subgroup by multiplication. | ||
| Line 181: | Line 174: | ||
-- Then filter out ratios if their equave complement would be filtered out. | -- Then filter out ratios if their equave complement would be filtered out. | ||
table.sort(ratios, rat.lt) | table.sort(ratios, rat.lt) | ||
return ratios | return ratios | ||
| Line 231: | Line 222: | ||
end | end | ||
return found | return found | ||
end | end | ||
| Line 326: | Line 261: | ||
-- Function callable by other modules | -- Function callable by other modules | ||
-- Search hierarchy is as follows: | |||
-- - Search by subgroup (includes non-integer and rational elements) | |||
-- - Then search by prime limit | |||
-- - Then search by odd limit (to be implemented) | |||
-- - Then search by int limit | |||
function p._ji_ratios(args) | function p._ji_ratios(args) | ||
-- Args for ease of access | |||
equave = args["Equave"] | |||
int_limit = args["Int Limit"] | |||
odd_limit = args["Odd Limit"] | |||
prime_limit = args["Prime Limit"] | |||
subgroup = args["Subgroup"] | |||
local ratios = {} | |||
if search_args["Subgroup"] ~= nil then | |||
ratios = p.search_by_subgroup(equave, int_limit, subgroup) | |||
elseif search_args["Prime Limit"] ~= nil then | |||
ratios = p.search_by_prime_limit(equave, int_limit, prime_limit) | |||
elseif search_args["Int Limit"] ~= nil then | |||
ratios = p.search_by_int_limit(equave, int_limit) | |||
end | |||
return ratios | |||
end | end | ||
-- Invokable function; for templates | -- Invokable function; for templates | ||
-- Ratios are returned as a comma-delimited list | |||
function p.ji_ratios(frame) | function p.ji_ratios(frame) | ||
args = getArgs(frame) | args = getArgs(frame) | ||
args["Equave"] = rat.parse(args["Equave"]) | -- Preprocess equave | ||
-- Ratios are searched from 1/1 to some equave (default 2/1), so an equave | |||
-- must be passed in. | |||
args["Equave"] = args["Equave"] ~= nil and rat.parse(args["Equave"]) or rat.new(2,1) | |||
-- Preprocess int limit | |||
-- Ratios are searched up to some int limit (default 50), so an int limit | |||
-- must be passed in. | |||
args["Int Limit"] = args["Int Limit"] ~= nil and tonumber(args["Int Limit"]) or 50 | |||
-- Preprocess Tenney height | |||
if args["Tenney Height"] ~= nil then | if args["Tenney Height"] ~= nil then | ||
args["Tenney Height"] = tonumber(args["Tenney Height"]) | args["Tenney Height"] = tonumber(args["Tenney Height"]) | ||
end | end | ||
-- Preprocess prime limit | |||
if args["Prime Limit"] ~= nil then | if args["Prime Limit"] ~= nil then | ||
args["Prime Limit"] = tonumber(args["Prime Limit"]) | args["Prime Limit"] = tonumber(args["Prime Limit"]) | ||
end | end | ||
-- Preprocess subgroup | |||
if args["Subgroup"] ~= nil then | if args["Subgroup"] ~= nil then | ||
local subgroup_elements = tip.parse_numeric_pairs(args["Subgroup"], ".", "/", true) | local subgroup_elements = tip.parse_numeric_pairs(args["Subgroup"], ".", "/", true) | ||
| Line 361: | Line 324: | ||
end | end | ||
-- Find and return ratios | |||
ratios = p. | ratios = p._ji_ratios(args) | ||
return p.ratios_as_string(ratios) | return p.ratios_as_string(ratios) | ||
end | end | ||