Module:Uniform map: Difference between revisions

m Fixing more bugs...
m Changes in local variable definitions and such, hopefully fixing stuff along the way
Line 3: Line 3:
local p = {}
local p = {}


primes = {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}
p.primes = {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}
map = {0, 0, 0}
p.lower = {0, 0 ,0}  -- List of smallest sizes that match a map for each prime
lower = {0, 0 ,0}  -- List of smallest sizes that match a map for each prime
p.upper = {0, 0, 0}  -- List of largest sizes that match a map for each prime
upper = {0, 0, 0}  -- List of largest sizes that match a map for each prime
p.pbi = 0            -- Index of the prime that defines the boundary
pbi = 0            -- Index of the prime that defines the boundary
maptable = {}      -- Table of uniform maps with boundaries and wart notation


-- Find the minimum size that corresponds to a given map
-- Find the minimum size that corresponds to a given map
function lowerbound(map)
function p.lowerbound(map)
local lowermax
for i=1, #map do
for i=1, #map do
lower[i] = (map[i]-1/2)/u._log(primes[i])
p.lower[i] = (map[i]-1/2)/u._log(p.primes[i])
lowermax = math.max(unpack(lower))
lowermax = math.max(unpack(p.lower))
end
end
return math.max(0, lowermax)
return math.max(0, lowermax)
Line 20: Line 19:


-- Find the maximum size that corresponds to a given map
-- Find the maximum size that corresponds to a given map
function upperbound(map)
function p.upperbound(map)
local uppermin
for i=1, #map do
for i=1, #map do
upper[i] = (map[i]+1/2)/u._log(primes[i])
p.upper[i] = (map[i]+1/2)/u._log(p.primes[i])
uppermin = math.min(unpack(upper))
uppermin = math.min(unpack(p.upper))
pbi = u.index_of(upper, uppermin)
pbi = u.index_of(p.upper, uppermin)
end
end
return math.max(0, uppermin)
return math.max(0, uppermin)
end
end
lb = lowerbound(map)  -- Minimum size for the current map
ub = upperbound(map)  -- Maximum size for the current map


-- Find the p-limit just intonation point (JIP) corresponding to a given size
-- Find the p-limit just intonation point (JIP) corresponding to a given size
function JIP(size, p)
function p.JIP(size, prime)
JIP_table = {}
local JIP_table = {}
for i=1, u.index_of(primes, p) do
for i=1, u.index_of(p.primes, prime) do
JIP_table[i] = size*u._log(primes[i])
JIP_table[i] = size*u._log(primes[i])
end
end
Line 42: Line 39:


-- Find the p-limit simple map corresponding to a given size
-- Find the p-limit simple map corresponding to a given size
function simple_map(size, p)
function p.simple_map(size, prime)
simple_map_table = {}
local simple_map_table = {}
for i=1, u.index_of(primes, p) do
for i=1, u.index_of(primes, prime) do
simple_map_table[i] = u._round_dec(size*u._log(primes[i]))
simple_map_table[i] = u._round_dec(size*u._log(primes[i]))
end
end
Line 51: Line 48:


-- Find the wart notation corresponding to a given map
-- Find the wart notation corresponding to a given map
function wart(map)
function p.wart(map)
edo = map[1]
local edo = map[1]
simple_map_edo = simple_map(edo, primes[#map])
local simple_map_edo = p.simple_map(edo, primes[#map])
JIP_edo = JIP(edo, primes[#map])
local JIP_edo = p.JIP(edo, primes[#map])
warts = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}
local warts = {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z'}
wart_notation = edo
local wart_notation = edo
for i=2, #map do
for i=2, #map do
-- direction is 1 if current harmonic mapped flatter than just, otherwise 0
-- direction is 1 if current harmonic mapped flatter than just, otherwise 0
direction = math.ceil(JIP_edo[i]-simple_map_edo[i])
local direction = math.ceil(JIP_edo[i]-simple_map_edo[i])
difference = map[i]-simple_map_edo[i]
local difference = map[i]-simple_map_edo[i]
if difference ~= 0 then
if difference ~= 0 then
number_warts = (2*math.abs(difference)+(u.signum((-1)^direction*difference)-1)/2)
number_warts = (2*math.abs(difference)+(u.signum((-1)^direction*difference)-1)/2)
Line 71: Line 68:
end
end


-- Generate table of p-limit uniform maps between min and max, for use with print_table
-- Generate table of p-limit uniform maps between min and max, for use with print_table (but could potentially be used standalone for raw data with headers)
function make_table(p, min, max)
function p.make_table(prime, min, max)
maptable = {}                         -- Reset table
local map = {}
for i=1, u.index_of(primes, p) do
local maptable = {}                     -- Table of uniform maps with boundaries and wart notation
for i=1, u.index_of(primes, prime) do
map[i] = 0                        -- Reset to p-limit null map
map[i] = 0                        -- Reset to p-limit null map
lower[i] = 0
p.lower[i] = 0
upper[i] = 0
p.upper[i] = 0
end
end
map = simple_map(min, p)              -- Set p-limit map for minimum size
map = p.simple_map(min, prime)              -- Set p-limit map for minimum size
lb = lowerbound(map)                   -- Update minimum size for new map
local lb = lowerbound(map) -- Minimum size for the current map
ub = upperbound(map)                   -- Update maximum size for new map
local ub = upperbound(map) -- Maximum size for the current map
row = {'Min. size', 'Max. size', '[[Wart notation]]'}
local row = {'Min. size', 'Max. size', '[[Wart notation]]'}
for i=1, #map do
for i=1, #map do
table.insert(row, primes[i])
table.insert(row, p.primes[i])
end
end
table.insert(maptable, row)
table.insert(maptable, row)
while lb < max do
while lb < max do
row = {string.format("%.4f", lb), string.format("%.4f", ub), wart(map)}
row = {string.format("%.4f", lb), string.format("%.4f", ub), p.wart(map)}
for j=1, #map do
for j=1, #map do
table.insert(row, map[j])
table.insert(row, map[j])
Line 122: Line 120:
end
end
wikitable = wikitable .. '\n| {{map|'
wikitable = wikitable .. '\n| {{map|'
for j=1, #map do
for j=4, #luatable do
wikitable = wikitable .. ' ' .. luatable[i][j+3]
wikitable = wikitable .. ' ' .. luatable[i][j]
end
end
wikitable = wikitable .. '}}'
wikitable = wikitable .. '}}'