Module:Rational: Difference between revisions

Plumtree (talk | contribs)
m Bugfix
Weil height should be logarithmic. +Wilson height
Line 1,086: Line 1,086:
end
end


-- determine max complexity
-- determine log2 max complexity
function p.weil_height(a)
function p.weil_height(a)
if type(a) == 'number' then
if type(a) == 'number' then
Line 1,094: Line 1,094:
return nil
return nil
end
end
local n, m = p.as_pair(a)
local h = p.tenney_height (a)
return math.max(n, m)
for factor, power in pairs(a) do
if type(factor) == 'number' then
h = h + math.abs (power * math.log (factor) / math.log(2))
end
end
return h
end
 
-- determine sopfr complexity
function p.wilson_height(a)
if type(a) == 'number' then
a = p.new(a)
end
if a.nan or a.inf or a.zero then
return nil
end
local h = 0
for factor, power in pairs(a) do
if type(factor) == 'number' then
h = h + math.abs(power) * factor
end
end
return h
end
end