Module:JI ratios: Difference between revisions
Rename functions; combine tenney height and int limit (plus complements-only, a new unimplemented search arg) into a table of search args; will momentarily break dependent templates |
Add complements-only option |
||
| Line 44: | Line 44: | ||
["Int Limit"] = int_limit | ["Int Limit"] = int_limit | ||
} | } | ||
end | |||
function p.complement_within_int_limit(ratio, equave, int_limit) | |||
local ratio = rat.new(ratio[2], ratio[1]) | |||
local complement = rat.mul(ratio, equave) | |||
local a, b = rat.as_pair(complement) | |||
return math.max(a, b) <= int_limit | |||
end | end | ||
| Line 63: | Line 71: | ||
["Equave"] = equave, | ["Equave"] = equave, | ||
["Int Limit"] = fine_search_args["Int Limit"], | ["Int Limit"] = fine_search_args["Int Limit"], | ||
["Tenney Height"] = fine_search_args["Tenney Height"] | ["Tenney Height"] = fine_search_args["Tenney Height"], | ||
["Complements Only"] = fine_search_args["Complements Only"] | |||
} | } | ||
local ratios = med.find_only_mediants_by_search_func(init_ratios, search_func, search_args) | local ratios = med.find_only_mediants_by_search_func(init_ratios, search_func, search_args) | ||
| Line 92: | Line 101: | ||
local int_limit = search_args["Int Limit"] | local int_limit = search_args["Int Limit"] | ||
local tenney_height = search_args["Tenney Height"] | local tenney_height = search_args["Tenney Height"] | ||
local comps_only = search_args["Complements Only"] | |||
local equave_as_float = rat.as_float(equave) | local equave_as_float = rat.as_float(equave) | ||
| Line 97: | Line 107: | ||
local mediant_th = math.log(mediant[1] * mediant[2]) / math.log(2) | local mediant_th = math.log(mediant[1] * mediant[2]) / math.log(2) | ||
local within_int_limit = math.max(mediant[1], mediant[2]) <= int_limit | |||
local within_equave = rat_1_as_float < equave_as_float | |||
local within_tenney_height = mediant_th <= tenney_height | |||
local comp_within_int_limit = p.complement_within_int_limit(mediant, equave, int_limit) or not comps_only | |||
return within_int_limit and within_equave and within_tenney_height and comp_within_int_limit | |||
end | end | ||
| Line 123: | Line 138: | ||
local int_limit = fine_search_args["Int Limit"] | local int_limit = fine_search_args["Int Limit"] | ||
local tenney_height = fine_search_args["Tenney Height"] | local tenney_height = fine_search_args["Tenney Height"] | ||
local comps_only = fine_search_args["Complements Only"] | |||
-- Find all possible products given the factors in the subgroup. | -- Find all possible products given the factors in the subgroup. | ||
| Line 175: | Line 191: | ||
local within_equave = numerator / denominator <= equave_as_float | local within_equave = numerator / denominator <= equave_as_float | ||
local within_tenney_height = math.log(numerator * denominator) / math.log(2) <= tenney_height | local within_tenney_height = math.log(numerator * denominator) / math.log(2) <= tenney_height | ||
if within_equave and within_tenney_height then | local comp_within_int_limit = p.complement_within_int_limit(mediant, equave, int_limit) or not comps_only | ||
if within_equave and within_tenney_height and comp_within_int_limit then | |||
table.insert(ratios, {numerator, denominator}) | table.insert(ratios, {numerator, denominator}) | ||
else | else | ||
| Line 382: | Line 399: | ||
function p.tester() | function p.tester() | ||
local equave = rat.new(2,1) | |||
local fine_search_args = { | |||
local fine_search_args = {[" | ["Int Limit"] = 20, | ||
["Tenney Height"] = 1/0, | |||
return p.ratios_as_text(p. | ["Complements Only"] = false | ||
} | |||
return p.ratios_as_text(p.search_within_equave(equave, fine_search_args)) | |||
end | end | ||
return p | return p | ||