Module:ET: Difference between revisions

Plumtree (talk | contribs)
mNo edit summary
These all looked too dumb tbh
 
(44 intermediate revisions by 7 users not shown)
Line 1: Line 1:
local rat = require('Module:Rational')
local rat = require("Module:Rational")
local seq = require('Module:Sequence')
local seq = require("Module:Sequence")
local p = {}
local p = {}


local common_suffix = {
local common_suffix = {
['3/2'] = 'f',
["3/2"] = "f",
['2'] = 'o',
["2"] = "o",
['2/1'] = 'o',
["2/1"] = "o",
['3'] = 't',
["3"] = "t",
['3/1'] = 't',
["3/1"] = "t",
}
}
local common_ratio = {
local common_ratio = {
['f'] = rat.new(3, 2),
["f"] = rat.new(3, 2),
['o'] = 2,
["o"] = 2,
['t'] = 3
["t"] = 3,
["ϕ"] = (1 + math.sqrt(5)) / 2,
["n"] = math.exp(1),
["π"] = math.pi
}
}


Line 24: Line 28:
local equave_ratio = rat.as_ratio(equave)
local equave_ratio = rat.as_ratio(equave)
equave_ratio = equave_ratio:lower()
equave_ratio = equave_ratio:lower()
suffix = size .. 'ed'
suffix = "ed"
if common_suffix[equave_ratio] then
if common_suffix[equave_ratio] then
suffix = suffix .. common_suffix[equave_ratio]
suffix = suffix .. common_suffix[equave_ratio]
Line 38: Line 42:
-- parse a ET structure
-- parse a ET structure
function p.parse(unparsed)
function p.parse(unparsed)
local size, suffix, equave = unparsed:match('^(%d+)([Ee][Dd](.+))$')
local size, suffix, equave = unparsed:match("^(%d+%.*%d*)([Ee][Dd](.+))$")
-- local size, suffix, equave = unparsed:match("^(%d+%.*%d*)([Cc]?[Ee][Dd]?[Tt]?(.*))$")
if equave == nil then
if equave == nil then
return nil
return nil
Line 62: Line 67:
end
end
return rat.as_float(et.equave) ^ (steps / et.size)
return rat.as_float(et.equave) ^ (steps / et.size)
end
function p.backslash_display(et, steps)
if et.size == 0 then
return 1
end
return steps .. p.backslash_modifier(et)
end
function p.backslash_modifier(et)
if not rat.eq(et.equave, 2) then
return "\\" .. et.size .. et.suffix
end
return "\\" .. et.size
end
end


Line 71: Line 90:
steps = steps or 1
steps = steps or 1
return 1200 * steps / et.size * math.log(rat.as_float(et.equave)) / math.log(2)
return 1200 * steps / et.size * math.log(rat.as_float(et.equave)) / math.log(2)
end
-- convert steps to hekts
function p.hekts(et, steps)
if et.size == 0 then
return 0
end
steps = steps or 1
return 1300 * steps / et.size * math.log(rat.as_float(et.equave)) / math.log(3)
end
end


Line 89: Line 117:
return math.floor(exact + 0.5)
return math.floor(exact + 0.5)
end
end
end
-- whether this ET tempers out the provided rational number
function p.tempers_out(et, ratio)
local t = 0
for factor, power in pairs(ratio) do
if type(factor) == "number" then
t = t + power * p.approximate(et, factor)
end
end
return t == 0
end
end


Line 95: Line 134:
et.highly_composite = et.highly_composite or rat.is_highly_composite(et.size)
et.highly_composite = et.highly_composite or rat.is_highly_composite(et.size)
return et.highly_composite
return et.highly_composite
end
function p.is_highly_melodic(et)
et.highly_composite = et.highly_composite or rat.is_highly_composite(et.size)
et.superabundant = et.superabundant or rat.is_superabundant(et.size)
return et.highly_composite or et.superabundant
end
-- describe why
function p.why_highly_melodic(et, debug_mode)
et.highly_composite = et.highly_composite or rat.is_highly_composite(et.size)
et.superabundant = et.superabundant or rat.is_superabundant(et.size)
if et.highly_composite and et.superabundant then
if debug_mode then
return 'highly composite, superabundant'
else
return 'highly composite,<br>superabundant'
end
elseif et.highly_composite then
return 'highly composite'
elseif et.superabundant then
return 'superabundant'
else
return 'no'
end
end
end


-- determine whether ET's size could be within one of zeta function-related sequences
-- determine whether ET's size could be within one of zeta function-related sequences
function p.is_zeta(et)
function p.is_zeta(et)
return seq.contains(seq.zeta_peak, et.size) ~= false
return seq.contains(seq.zeta_peak, et.size)
or seq.contains(seq.integral_zeta, et.size) ~= false
or seq.contains(seq.zeta_peak_integer, et.size)
or seq.contains(seq.zeta_gap, et.size) ~= false
or seq.contains(seq.zeta_integral, et.size)
or seq.contains(seq.zeta_gap, et.size)
end
end


-- describe why
-- describe why
function p.why_zeta(et, debug_mode)
function p.why_zeta(et)
local zeta_peak = seq.contains(seq.zeta_peak, et.size)
local zeta_peak = seq.contains(seq.zeta_peak, et.size)
local integral_zeta = seq.contains(seq.integral_zeta, et.size)
local zeta_peak_integer = seq.contains(seq.zeta_peak_integer, et.size)
local zeta_integral = seq.contains(seq.zeta_integral, et.size)
local zeta_gap = seq.contains(seq.zeta_gap, et.size)
local zeta_gap = seq.contains(seq.zeta_gap, et.size)
local z = "The Riemann zeta function and tuning#Zeta EDO lists"
 
local markers = {}
local markers = {}
if zeta_peak then
if zeta_peak then
if debug_mode then
table.insert(markers, string.format("[[%s|Zeta peak]]", z))
table.insert(markers, '[[The Riemann zeta function and tuning#Peak EDOs|zeta peak]]')
else
table.insert(markers, 'peak')
end
elseif zeta_peak == nil then
elseif zeta_peak == nil then
if debug_mode then
table.insert(markers, string.format("[[%s|Zeta peak?]]", z))
table.insert(markers, '[[The Riemann zeta function and tuning#Peak EDOs|zeta peak?]]')
end
else
 
table.insert(markers, 'peak?')
if zeta_peak_integer then
end
table.insert(markers, string.format("[[%s|Zeta peak integer]]", z))
elseif zeta_peak_integer == nil then
table.insert(markers, string.format("[[%s|Zeta peak integer?]]", z))
end
end
if integral_zeta then
 
if debug_mode then
if zeta_integral then
table.insert(markers, '[[The Riemann zeta function and tuning#Integral of Zeta EDOs|integral of zeta]]')
table.insert(markers, string.format("[[%s|Zeta integral]]", z))
else
elseif zeta_integral == nil then
table.insert(markers, 'integral')
table.insert(markers, string.format("[[%s|Zeta integral?]]", z))
end
elseif integral_zeta == nil then
if debug_mode then
table.insert(markers, '[[The Riemann zeta function and tuning#Integral of Zeta EDOs|integral of zeta?]]')
else
table.insert(markers, 'integral?')
end
end
end
if zeta_gap then
if zeta_gap then
if debug_mode then
table.insert(markers, string.format("[[%s|Zeta gap]]", z))
table.insert(markers, '[[The Riemann zeta function and tuning#Zeta Gap EDOs|zeta gap]]')
else
table.insert(markers, 'gap')
end
elseif zeta_gap == nil then
elseif zeta_gap == nil then
if debug_mode then
table.insert(markers, string.format("[[%s|Zeta gap?]]", z))
table.insert(markers, '[[The Riemann zeta function and tuning#Zeta Gap EDOs|zeta gap?]]')
else
table.insert(markers, 'gap?')
end
end
end
return table.concat(markers, ', ')
 
return table.concat(markers, "<br />")
end
end


return p
return p