Module:JI ratio finder: Difference between revisions

Ganaram inukshuk (talk | contribs)
Added filtering by equave-complement int-limit
Ganaram inukshuk (talk | contribs)
Removed functions pertaining to complement-agnostic tenney height; superseded by nefth functions
Line 3: Line 3:
local rat = require('Module:Rational')
local rat = require('Module:Rational')
local p = {}
local p = {}
-- Finds the Tenney height of a ratio, regardless of inversion; also called
-- complement-agnostic tenney height (CATH). Equave complement depends on what
-- the equivalence interval is (default is 2/1).
-- Given a ratio and its equave complement, the CATH is the smaller of the two
-- ratios' Tenney heights.
function p.complement_agnostic_tenney_height(ratio, equave)
local ratio = ratio or rat.new(81, 64)
local equave = equave or rat.new(2)
local comp = p.equave_complement(ratio, equave)
return math.min(rat.tenney_height(ratio), rat.tenney_height(comp))
end


-- Finds the Tenney height of a ratio that ignores equave factors.
-- Finds the Tenney height of a ratio that ignores equave factors.
-- If the equave is 2/1, then this is equivalent to no-2's Tenney Height.
-- If the equave is 2/1, then this is equivalent to no-2's Tenney Height.
-- This is an attempt at generalizing no-2's Tenney height for nonoctave
-- This is an attempt at generalizing no-2's Tenney height for nonoctave
-- equaves, such as 3/1 or 3/2.
-- equaves, such as 3/1 or 3/2, which would be no-2's and no-2's-or-3's.
function p.no_equave_factors_tenney_height(ratio, equave)
function p.no_equave_factors_tenney_height(ratio, equave)
local ratio = ratio or rat.new(81, 64)
local ratio = ratio or rat.new(81, 64)
Line 63: Line 51:
-- Ratios found this way will range from 0 cents to the given cent value.
-- Ratios found this way will range from 0 cents to the given cent value.
-- These ratios should then be filtered as needed.
-- These ratios should then be filtered as needed.
function p.find_candidate_ratios(cents, int_limit, prime_limit)
function p.find_candidate_ratios_within_prime_limit(cents, int_limit, prime_limit)
local cents = cents or 1902
local cents = cents or 1200
local int_limit = int_limit or 99
local int_limit = int_limit or 99
local prime_limit = prime_limit or 97
local prime_limit = prime_limit or 97
Line 213: Line 201:
function p.filter_ratios_by_subgroup(ratios, subgroup)
function p.filter_ratios_by_subgroup(ratios, subgroup)
local ratios = ratios or { rat.new(1), rat.new(5, 4), rat.new(81, 64), rat.new(9, 7) }
local ratios = ratios or { rat.new(1), rat.new(5, 4), rat.new(81, 64), rat.new(9, 7) }
local subgroup = subgroup or { 2, 3, 5 }
local subgroup = subgroup or { 2, 3, 7 }
local candidate_ratios = p.filter_ratios_by_prime_limit(ratios, subgroup[#subgroup])
local candidate_ratios = p.filter_ratios_by_prime_limit(ratios, subgroup[#subgroup])
Line 238: Line 226:
for i = 1, #ratios do
for i = 1, #ratios do
if rat.tenney_height(ratios[i]) <= tenney_height then
if rat.tenney_height(ratios[i]) <= tenney_height then
table.insert(filtered_ratios, ratios[i])
end
end
return filtered_ratios
end
-- Filters ratios by complement-agnostic Tenney height
-- Filters ratios where lg(numerator) + lg(denominator) does not exceed the
-- given height, where lg is log-base-2
-- If the equave complement of that ratio has a lower Tenney height, the ratio
-- is kept instead.
function p.filter_ratios_by_complement_agnostic_tenney_height(ratios, tenney_height, equave)
local ratios = ratios or { rat.new(5, 4), rat.new(81, 64), rat.new(9, 7) }
local tenney_height = tenney_height or 5.0
local equave = equave or rat.new(2)
local filtered_ratios = {}
for i = 1, #ratios do
if p.complement_agnostic_tenney_height(ratios[i], equave) <= tenney_height then
table.insert(filtered_ratios, ratios[i])
table.insert(filtered_ratios, ratios[i])
end
end
Line 267: Line 235:
-- Filters ratios by no-equave-factors Tenney height
-- Filters ratios by no-equave-factors Tenney height
-- Filters ratios where lg(numerator) + lg(denominator) does not exceed the
-- Filters ratios where lg(numerator) + lg(denominator) does not exceed the
-- given height, where lg is log-base-2
-- given height, where lg is log-base-2. If the equave is 2/1, this is the same
-- If the equave complement of that ratio has a lower Tenney height, the ratio
-- as no-2's tenney height.
-- is kept instead.
-- EG, assuming 2/1 equave, 3/2 and 4/3 have the same tenney height of lg(3).
function p.filter_ratios_by_no_equave_factors_tenney_height(ratios, tenney_height, equave)
function p.filter_ratios_by_no_equave_factors_tenney_height(ratios, tenney_height, equave)
local ratios = ratios or { rat.new(5, 4), rat.new(81, 64), rat.new(9, 7) }
local ratios = ratios or { rat.new(5, 4), rat.new(81, 64), rat.new(9, 7) }