Module:JI ratios: Difference between revisions

Ganaram inukshuk (talk | contribs)
m betterer wording for footnote
Ganaram inukshuk (talk | contribs)
Added complement-only search (does not work for int-limit-only search): ratios are only added based on whether its equave complement is also added
Line 46: Line 46:
end
end


function p.complement_within_int_limit(ratio, equave, int_limit)
function p.ratio_within_search(ratio, equave, fine_search_args)
local ratio = rat.new(ratio[2], ratio[1])
local complement = rat.mul(rat.new(ratio[2], ratio[1]), equave)
local complement = rat.mul(ratio, equave)
local a, b = rat.as_pair(complement)
local a, b = rat.as_pair(complement)
return math.max(a, b) <= int_limit
-- Ratio, complement, and equave as float
local ratio_as_float = ratio[1] / ratio[2]
local equave_as_float = rat.as_float(equave)
-- Fine search params for ease of access
local int_limit = fine_search_args["Int Limit"]
local tenney_height = fine_search_args["Tenney Height"]
local comps_only = fine_search_args["Complements Only"]
local ratio_within_int_limit = math.max(ratio[1], ratio[2]) <= int_limit
local ratio_within_tenney_height = math.log(ratio[1] * ratio[2]) / math.log(2) <= tenney_height
local ratio_within_equave = ratio_as_float <= equave_as_float
local ratio_within_search = ratio_within_int_limit and ratio_within_tenney_height and ratio_within_equave
local comp_within_search = true
if comps_only then
-- A ratio's complement will be necessarily less than or equal to the
-- equave, so no need to check if it's within the equave.
local comp_within_int_limit = math.max(a, b) <= int_limit
local comp_within_tenney_height = math.log(a * b) / math.log(2) <= tenney_height
comp_within_search = comp_within_int_limit and comp_within_tenney_height
end
return ratio_within_search and comp_within_search
end
end


Line 99: Line 121:
local ratio_1  = mediant_data["ratio_1"]
local ratio_1  = mediant_data["ratio_1"]
local equave        = search_args["Equave"]
local equave        = search_args["Equave"]
local int_limit    = search_args["Int Limit"]
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 107: Line 126:
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
-- When the ratio is added, is ratio 1 within the equave? If so, add the
-- new ratio.
local within_equave = rat_1_as_float < equave_as_float
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
-- Is the mediant within the int limit and tenney height?
local within_int_limit = math.max(mediant[1], mediant[2]) <= search_args["Int Limit"]
local within_tenney_height = mediant_th <= search_args["Tenney Height"]
return within_equave and within_int_limit and within_tenney_height
end
end


Line 190: Line 212:
if gcd == 1 then
if gcd == 1 then
local ratio = {numerator, denominator}
local ratio = {numerator, denominator}
local within_equave = numerator / denominator <= equave_as_float
local within_tenney_height = math.log(numerator * denominator) / math.log(2) <= tenney_height
local comp_within_int_limit = p.complement_within_int_limit(ratio, equave, int_limit) or not comps_only
if within_equave and within_tenney_height then
if p.ratio_within_search(ratio, equave, fine_search_args) then
table.insert(ratios, ratio)
table.insert(ratios, ratio)
else
else
Line 403: Line 422:
local equave = rat.new(2,1)
local equave = rat.new(2,1)
local fine_search_args = {
local fine_search_args = {
["Int Limit"]        = 20,
["Int Limit"]        = 27,
["Tenney Height"]    = 1/0,
["Tenney Height"]    = 1/0,
["Complements Only"] = false
["Complements Only"] = true
}
}
return p.ratios_as_text(p.search_within_equave(equave, fine_search_args))
return p.ratios_as_text(p.search_by_prime_limit_within_equave(7, equave, fine_search_args))
--return p.ratio_within_search({9,8}, equave, fine_search_args)
end
end


return p
return p