Module:Rational: Difference between revisions

Plumtree (talk | contribs)
m Minor optimisations for addition
Plumtree (talk | contribs)
m Misc functions
Line 251: Line 251:
end
end
return true
return true
end
-- find max prime in ket notation
function p.max_prime(a)
if a.nan or a.inf or a.zero then
return nil
end
local max_factor = 0
for factor, power in pairs(a) do
if type(factor) == 'number' then
if factor > max_factor then
max_factor = factor
end
end
end
return max_factor
end
-- determine whether the rational number is +- p/q, where p, q are primes OR 1
function p.is_prime_ratio(a)
if a.nan or a.inf or a.zero then
return false
end
local n_factors = 0
local m_factors = 0
for factor, power in pairs(a) do
if type(factor) == 'number' then
if power > 0 then
n_factors = n_factors + 1
else
m_factors = m_factors + 1
end
end
end
return n_factors <= 1 and m_factors <= 1
end
end