Module:Rational: Difference between revisions

Plumtree (talk | contribs)
m Safer parsing
Plumtree (talk | contribs)
m find_S_expression() improved
Line 164: Line 164:
end
end
-- is it triangle-particular or ultraparticular?
-- is it Sk^2 * S(k+1) or Sk * S(k+1)^2?
for _, k in ipairs(superparticular_indices) do
for _, k in ipairs(superparticular_indices) do
local r1 = superparticular_ratios[k]
local r1 = superparticular_ratios[k]
local r2 = superparticular_ratios[k + 1]
local r2 = superparticular_ratios[k + 1]
if r1 and r2 then
if r1 and r2 then
if p.eq(a, p.mul(r1, r2)) then
if p.eq(a, p.mul(p.pow(r1, 2), r2)) then
table.insert(expressions, 'S' .. k .. ' × S' .. (k + 1))
table.insert(expressions, 'S' .. k .. '<sup>2</sup> × S' .. (k + 1))
end
end
if p.eq(a, p.div(r1, r2)) then
if p.eq(a, p.div(r1, p.pow(r2, 2))) then
table.insert(expressions, 'S' .. k .. ' / S' .. (k + 1))
table.insert(expressions, 'S' .. k .. ' * S' .. (k + 1) .. '<sup>2</sup>')
end
end
end
end
Line 186: Line 186:
if p.eq(a, p.mul(r1, p.mul(r2, r3))) then
if p.eq(a, p.mul(r1, p.mul(r2, r3))) then
table.insert(expressions, 'S' .. (k - 1) .. ' × S' .. k .. ' × S' .. (k + 1))
table.insert(expressions, 'S' .. (k - 1) .. ' × S' .. k .. ' × S' .. (k + 1))
end
end
end
-- is it semiparticular?
for _, k in ipairs(superparticular_indices) do
local r1 = superparticular_ratios[k]
local r2 = superparticular_ratios[k + 2]
if r1 and r2 then
if p.eq(a, p.div(r1, r2)) then
table.insert(expressions, 'S' .. k .. ' / S' .. (k + 2))
end
end
end
end
Line 207: Line 196:
local r2 = superparticular_ratios[k2]
local r2 = superparticular_ratios[k2]
if k1 <= k2 and p.eq(a, p.mul(r1, r2)) then
if k1 <= k2 and p.eq(a, p.mul(r1, r2)) then
-- check for duplicates
table.insert(expressions, 'S' .. k1 .. ' × S' .. k2)
local expr = 'S' .. k1 .. ' × S' .. k2
local dup = false
for _, expr2 in ipairs(expressions) do
if expr == expr2 then
dup = true
break
end
end
if not dup then
table.insert(expressions, expr)
end
end
end
if k1 <= k2 and p.eq(a, p.div(r1, r2)) then
if k1 <= k2 and p.eq(a, p.div(r1, r2)) then
-- check for duplicates
table.insert(expressions, 'S' .. k1 .. ' / S' .. k2)
local expr = 'S' .. k1 .. ' / S' .. k2
local dup = false
for _, expr2 in ipairs(expressions) do
if expr == expr2 then
dup = true
break
end
end
if not dup then
table.insert(expressions, expr)
end
end
end
end
end