Module:Limits: Difference between revisions

Plumtree (talk | contribs)
Consistency limits optimisation
Plumtree (talk | contribs)
m Temporarily reverting the edit
Tag: Undo
Line 2: Line 2:
local p = {}
local p = {}


p.rat = rat
-- multiply the ratio by a power of `equave` so that it lies within [1; equave)
function p.canonical(a, equave)
equave = equave or 2
if type(a) == 'number' then
a = rat.new(a)
end
local b = rat.copy(a)
while rat.lt(b, 1) do
b = rat.mul(b, equave)
end
while rat.geq(b, equave) do
b = rat.div(b, equave)
end
return b
end


-- compute all positive ratios n/m with n and m <= q modulo powers of equave
-- compute all positive ratios n/m with n and m <= q modulo powers of equave
Line 11: Line 25:
for m = 1, q, 2 do
for m = 1, q, 2 do
local a = rat.new(n, m)
local a = rat.new(n, m)
a = rat.modulo_mul(a, equave)
a = p.canonical(a, equave)
local key = rat.as_ratio(a)
local key = rat.as_ratio(a)
ratios[key] = a
ratios[key] = a
Line 50: Line 64:
local c_approx = approximate(c)
local c_approx = approximate(c)
c = rat.modulo_mul(c, equave)
c = p.canonical(c, equave)
local c_key = rat.as_ratio(c)
local c_key = rat.as_ratio(c)
if ratios[c_key] then
if ratios[c_key] then