Module:JI ratios: Difference between revisions
Implement new new subgroup-search; only finds products so far |
m some bugfixes, new helper function |
||
| Line 179: | Line 179: | ||
local index_counter = 1 | local index_counter = 1 | ||
while index_counter <= #products do | while index_counter <= #products do | ||
local new_products = p. | local new_products = p.multiply_ratio_by_subgroup_elements(products[index_counter], subgroup, int_limit) | ||
p.merge_ratio_tables_without_duplicates(products, new_products) | |||
index_counter = index_counter + 1 | index_counter = index_counter + 1 | ||
| Line 194: | Line 190: | ||
-- Use the products found to find all ratios between 1 and the equave | -- Use the products found to find all ratios between 1 and the equave | ||
local ratios = {} | local ratios = { rat.new(1) } | ||
for i = 1, #products do | for i = 1, #products do | ||
end | end | ||
| Line 204: | Line 200: | ||
end | end | ||
function p. | function p.multiply_ratio_by_subgroup_elements(ratio, subgroup, int_limit) | ||
local new_products = {} | local new_products = {} | ||
for i = 1, #subgroup do | for i = 1, #subgroup do | ||
local product = rat.mul(ratio, subgroup[i]) | local product = rat.mul(ratio, subgroup[i]) | ||
if rat.int_limit(product) <= int_limit and not p.find_ratio_in_table(new_products, product) then | if rat.int_limit(product) <= int_limit and not p.find_ratio_in_table(new_products, product) then | ||
table.insert(new_products, product) | table.insert(new_products, product) | ||
end | end | ||
end | end | ||
return new_products | return new_products | ||
end | end | ||
function p. | function p.divide_ratio_by_subgroup_elements(ratio, subgroup, int_limit) | ||
local new_quotients = {} | local new_quotients = {} | ||
for i = 1, #subgroup do | for i = 1, #subgroup do | ||
local quotient = rat.div(ratio, subgroup[i]) | local quotient = rat.div(ratio, subgroup[i]) | ||
if rat.int_limit(quotient) <= int_limit and not p.find_ratio_in_table(new_quotients, quotient) then | if rat.int_limit(quotient) <= int_limit and not p.find_ratio_in_table(new_quotients, quotient) then | ||
table.insert(new_quotients, | table.insert(new_quotients, quotient) | ||
end | end | ||
end | end | ||
return new_quotients | return new_quotients | ||
end | end | ||
-- Does not return anything; entries in source are added to destination. | |||
function p.merge_ratio_tables_without_duplicates(dest_table, source_table) | |||
for i = 1, #source_table do | |||
if not p.find_ratio_in_table(dest_table, source_table[i]) then | |||
table.insert(dest_table, source_table[i]) | |||
end | |||
end | |||
end | |||
-- Checks whether a ratio was already in a table | |||
function p.find_ratio_in_table(table_, ratio) | function p.find_ratio_in_table(table_, ratio) | ||
local found = false | local found = false | ||
| Line 240: | Line 240: | ||
end | end | ||
end | end | ||
return found | return found | ||
end | end | ||
| Line 527: | Line 526: | ||
local texts = {} | local texts = {} | ||
for i = 1, #ratios do | for i = 1, #ratios do | ||
local text = p. | local text = p.ratios_as_string(ratios[i], add_links, delimiter) | ||
table.insert(texts, text) | table.insert(texts, text) | ||
end | end | ||
| Line 539: | Line 538: | ||
--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. | return p.divide_ratio_by_subgroup_elements(rat.new(9,5), {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 | ||