Module:Temperament data: Difference between revisions
CompactStar (talk | contribs) No edit summary |
CompactStar (talk | contribs) No edit summary |
||
| Line 1: | Line 1: | ||
local rat = require('Module:Rational') | local rat = require('Module:Rational') | ||
local p = {} | local p = {} | ||
-- Utility / matrix functions | |||
local function gcd(a,b) | |||
if type(a) == "number" and type(b) == "number" and | |||
a == math.floor(a) and b == math.floor(b) then | |||
if b == 0 then | |||
return a | |||
else | |||
return gcd(b, a % b) -- tail recursion | |||
end | |||
else | |||
error("Invalid argument to gcd (" .. tostring(a) .. "," .. | |||
tostring(b) .. ")", 2) | |||
end | |||
end | |||
local function matadd(a, b) | local function matadd(a, b) | ||
| Line 62: | Line 77: | ||
end | end | ||
end | end | ||
xn = scalarmatmul(a, 0. | xn = scalarmatmul(a, 0.000001) | ||
for i = 1, 30 do | for i = 1, 30 do | ||
| Line 86: | Line 101: | ||
end | end | ||
-- Actual temperament-related functions start here | |||
-- Generator list (e.g. 2/1, 3/2 for meantone) is needed so you can input irregular mappings like {{5,8,12},{7,11,16}} for meantone | |||
-- and still have the outputted generators be ~2/1 and ~3/2 | |||
-- (this will be important later so people using the template can just input an ET list instead of having to figure out the mapping) | |||
-- Generators are passed as monzos in the specified subgroup here | |||
function p.get_te_generator(subgroup, mapping, gens) | |||
local w = {} | local w = {} | ||
for i = 1, #subgroup do | for i = 1, #subgroup do | ||
| Line 105: | Line 127: | ||
local vw = matmul(mapping, w) | local vw = matmul(mapping, w) | ||
local g = matmul(jw, pseudoinv(vw)) | local g = matmul(jw, pseudoinv(vw)) | ||
local mapping_cols = #mapping[1] | |||
local tempered_subgroup = {} | |||
for i = 1, #subgroup do | |||
tempered_subgroup[i] = 0 | |||
for j = 1, #mapping do | |||
tempered_subgroup[i] = tempered_subgroup[i] + g[1][j] * mapping[j][i] | |||
end | end | ||
end | end | ||
return | return tempered_subgroup | ||
end | end | ||
return p | return p | ||