Module:Rational: Difference between revisions

Two of the functions are not working properly, mark with todo
This used to work. Restore the old code with better documentation
Line 552: Line 552:
end
end


-- determine whether a rational number represents a harmonic
-- determine whether a rational number represents a harmonic.
-- TODO: rework. doesn't correctly check reduced harmonics.
-- reduced: check for reduced harmonic instead.  
function p.is_harmonic(a, reduced, large)
function p.is_harmonic(a, reduced, large)
if type(a) == "number" then
if type(a) == "number" then
Line 563: Line 563:
for factor, power in pairs(a) do
for factor, power in pairs(a) do
if type(factor) == "number" then
if type(factor) == "number" then
if power < 0 then
if factor == 2 and reduced then
-- pass (ignore factors of 2 for reduced harmonic check)
elseif power < 0 then
return false
return false
end
end
end
end
end
end
if reduced then -- for reduced harmonics, a false will have been returned before reaching here
if reduced then
return p.is_reduced(a, 2, large)
return p.is_reduced(a, 2, large)
end
end
Line 574: Line 576:
end
end


-- determine whether a rational number represents a subharmonic
-- determine whether a rational number represents a subharmonic.
-- TODO: rework. doesn't correctly check reduced subharmonics.
-- reduced: check for reduced subharmonic instead.  
function p.is_subharmonic(a, reduced, large)
function p.is_subharmonic(a, reduced, large)
if type(a) == "number" then
if type(a) == "number" then
Line 585: Line 587:
for factor, power in pairs(a) do
for factor, power in pairs(a) do
if type(factor) == "number" then
if type(factor) == "number" then
if power > 0 then
if factor == 2 and reduced then
-- pass (ignore factors of 2 for reduced subharmonic check)
elseif power < 0 then
return false
return false
end
end
end
end
end
end
if reduced then -- for reduced subharmonics, a false will have been returned before reaching here
if reduced then
return p.is_reduced(a, 2, large)
return p.is_reduced(a, 2, large)
end
end