Module:Rational: Difference between revisions
m is_square_superparticular() implemented |
m as_subgroup_ket() implemented, as_ket() implementation improved for 1/1 |
||
Line 1,114: | Line 1,114: | ||
local n, m = p.as_pair(a) | local n, m = p.as_pair(a) | ||
return n / m | return n / m | ||
end | |||
-- return a rational number in subgroup ket notation | |||
function p.as_subgroup_ket(a, frame) | |||
if type(a) == 'number' then | |||
a = p.new(a) | |||
end | |||
if a.nan or a.inf or a.zero or a.sign < 0 then | |||
return 'n/a' | |||
end | |||
local factors = {} | |||
for factor, power in pairs(a) do | |||
if type(factor) == 'number' then | |||
table.insert(factors, factor) | |||
end | |||
end | |||
table.sort(factors) | |||
local subgroup = '1' | |||
if not p.eq(a, 1) then | |||
subgroup = table.concat(factors, '.') | |||
end | |||
local powers = {} | |||
for i, factor in ipairs(factors) do | |||
table.insert(powers, a[factor]) | |||
end | |||
local template_arg = '0' | |||
if not p.eq(a, 1) then | |||
template_arg = table.concat(powers, ' ') | |||
end | |||
return subgroup .. ' ' .. frame:expandTemplate{ | |||
title = 'Monzo', | |||
args = {template_arg} | |||
} | |||
end | end | ||
Line 1,170: | Line 1,205: | ||
end | end | ||
end | end | ||
end | |||
if #template_arg == 0 then | |||
template_arg = '0' | |||
end | end | ||
s = s .. frame:expandTemplate{ | s = s .. frame:expandTemplate{ |