Module:JI ratios: Difference between revisions
No edit summary |
Implement new new subgroup-search; only finds products so far |
||
| Line 156: | Line 156: | ||
return within_equave and within_int_limit and within_tenney_height | return within_equave and within_int_limit and within_tenney_height | ||
end | |||
-------------------------------------------------------------------------------- | |||
---------------- WORK-IN-PROGERSS SUBGROUP-BASED SEARCH FUNCTION --------------- | |||
-------------------------------------------------------------------------------- | |||
-- WORK-IN-PROGRESS!! | |||
function p.search_by_subgroup_new(subgroup, equave, fine_search_args) | |||
local subgroup = {rat.new(2), rat.new(5), rat.new(7,6), rat.new(11,6)} | |||
local equave = rat.new(2,1) | |||
local fine_search_args = p.preprocess_fine_search_args(fine_search_args) | |||
-- 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 products = { rat.new(1) } | |||
-- Perform breadth-first-search to find all ratios greater than 1 within | |||
-- the int limit. | |||
local index_counter = 1 | |||
while index_counter <= #products do | |||
local new_products = p.multiply_ratio_by_subgroup_members(products[index_counter], subgroup, int_limit) | |||
for i = 1, #new_products do | |||
if not p.find_ratio_in_table(products, new_products[i]) then | |||
table.insert(products, new_products[i]) | |||
end | |||
end | |||
index_counter = index_counter + 1 | |||
end | |||
-- Sort | |||
table.sort(products, rat.lt) | |||
-- Use the products found to find all ratios between 1 and the equave | |||
local ratios = {} | |||
for i = 1, #products do | |||
end | |||
-- Return as a string for testing purposes | |||
return p.ratios_as_string(products) | |||
end | |||
function p.multiply_ratio_by_subgroup_members(ratio, subgroup, int_limit) | |||
local new_products = {} | |||
for i = 1, #subgroup do | |||
local product = rat.mul(ratio, subgroup[i]) | |||
local product_as_float = rat.as_float(product) | |||
if rat.int_limit(product) <= int_limit and not p.find_ratio_in_table(new_products, product) then | |||
table.insert(new_products, product) | |||
end | |||
end | |||
return new_products | |||
end | |||
function p.divide_ratio_by_subgroup_members(ratio, subgroup, int_limit) | |||
local new_quotients = {} | |||
for i = 1, #subgroup do | |||
local quotient = rat.div(ratio, subgroup[i]) | |||
local quotient_as_float = rat.as_float(quotient) | |||
if rat.int_limit(quotient) <= int_limit and not p.find_ratio_in_table(new_quotients, quotient) then | |||
table.insert(new_quotients, product) | |||
end | |||
end | |||
return new_quotients | |||
end | |||
function p.find_ratio_in_table(table_, ratio) | |||
local found = false | |||
for i = 1, #table_ do | |||
if rat.as_float(table_[i]) == rat.as_float(ratio) then | |||
found = true | |||
break | |||
end | |||
end | |||
return found | |||
end | end | ||
| Line 451: | Line 537: | ||
local equave = rat.new(2,1) | local equave = rat.new(2,1) | ||
local fine_search_args = p.parse_search_args("Subgroup: 2.5.9.21; Int Limit: 30; Complements Only: 1; Tenney Height: 100000000") | local fine_search_args = p.parse_search_args("Subgroup: 2.5.9.21; Int Limit: 30; Complements Only: 1; Tenney Height: 100000000") | ||
return p.ratios_as_string(p.search_by_args_within_equave(equave, fine_search_args)) | --return p.ratios_as_string(p.search_by_args_within_equave(equave, fine_search_args)) | ||
return p.multiply_ratio_by_subgroup_members(rat.new(1), {rat.new(2), rat.new(3), rat.new(7)}, 50) | |||
--return p.ratio_within_search({16,13}, equave, fine_search_args) and p.ratio_within_search({8,13}, equave, fine_search_args) | --return p.ratio_within_search({16,13}, equave, fine_search_args) and p.ratio_within_search({8,13}, equave, fine_search_args) | ||
end | end | ||
return p | return p | ||