Module:Interval table: Difference between revisions

m Style
This get_"monzo" is no different from rat.new
Line 4: Line 4:
local ud = require("Module:Ups and downs notation")
local ud = require("Module:Ups and downs notation")
local ET = require("Module:ET")
local ET = require("Module:ET")
-- TODO:
-- Store rationals with rat.new.
-- Find prime limits with rat.max_prime.


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,
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,
  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}
  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
local function get_limit(n, d)
local result = 2
local monzo = get_monzo(n, d)
for k, _ in pairs(monzo) do
if k > result then
result = k
end
end
return result
end


--  Gets mapping of a monzo in a val
--  Gets mapping of a monzo in a val
Line 59: Line 28:
(i / j) >= 1
(i / j) >= 1
and (i / j) <= max_size
and (i / j) <= max_size
and get_limit(i, j) <= prime_limit
and rat.max_prime(rat.new (i, j)) <= prime_limit
and not utils.table_contains(ratio_strings, t)
and not utils.table_contains(ratio_strings, t)
then
then
Line 113: Line 82:
[43] = ET.approximate(et, 43),
[43] = ET.approximate(et, 43),
[47] = ET.approximate(et, 47),
[47] = ET.approximate(et, 47),
}
} -- NOTE: indices are prime numbers


local t_head = '{| class="wikitable center-1 right-2"\n'
local t_head = '{| class="wikitable center-1 right-2"\n'
Line 175: Line 144:
-- 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(get_monzo(ratios_list[j][1], ratios_list[j][2]), patent_val)
local t = mapping(rat.new(ratios_list[j][1], ratios_list[j][2]), patent_val)
if
if
t == i
t == i