Module:Interval table: Difference between revisions

This string substitution is so dumb I don't know who to blame. To fix this permanently I'm making the collapse depend on the equal division number (~row count) instead of the character count
Copypaste utils.get_monzo here
Line 8: Line 8:
-- Store rationals with rat.new.  
-- Store rationals with rat.new.  
-- Find prime limits with rat.max_prime.  
-- Find prime limits with rat.max_prime.  
-- Check if this is the only module where utils.get_monzo is used.  
 
local PRIME_LIST = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97,
  101, 103, 107, 109, 113, 127, 131, 137, 139, 149, 151, 157, 163, 167, 173, 179, 181, 191, 193, 197, 199,
  211, 223, 227, 229, 233, 239, 241, 251, 257, 263, 269, 271}
 
-- get monzo of n/d
-- e.g. for 3/2: {[2] = -1, [3] = 1}
local function get_monzo(n, d)
local n_pf = utils.prime_factorization_raw(n)
local d_pf = utils.prime_factorization_raw(d)
local result = {}
for i = 1, #PRIME_LIST do
local t = (n_pf[PRIME_LIST[i]] or 0) - (d_pf[PRIME_LIST[i]] or 0)
if t ~= 0 then
result[PRIME_LIST[i]] = t
end
end
return result
end


-- Get prime limit of n/d
-- Get prime limit of n/d
local function get_limit(n, d)
local function get_limit(n, d)
local result = 2
local result = 2
local monzo = utils.get_monzo(n, d)
local monzo = get_monzo(n, d)
for k, _ in pairs(monzo) do
for k, _ in pairs(monzo) do
if k > result then
if k > result then
Line 156: Line 174:
-- If they are mapped to the current step in the ET's patent val and <2/5 edo step error,
-- If they are mapped to the current step in the ET's patent val and <2/5 edo step error,
-- add to approximate ratios column.
-- add to approximate ratios column.
local t = mapping(utils.get_monzo(ratios_list[j][1], ratios_list[j][2]), patent_val)
local t = mapping(get_monzo(ratios_list[j][1], ratios_list[j][2]), patent_val)
if
if
t == i
t == i