Module:Rational: Difference between revisions

Plumtree (talk | contribs)
m find_S_expression() improved
Plumtree (talk | contribs)
m find_S_expression() reworked
Line 127: Line 127:


-- attempt to identify the ratio as a simple S-expression
-- attempt to identify the ratio as a simple S-expression
-- returns a table of matched expressions
function p.find_S_expression(a)
function p.find_S_expression(a)
if type(a) == 'number' then
if type(a) == 'number' then
Line 145: Line 146:
local superparticular_ratios = {}
local superparticular_ratios = {}
for prime, k_array in pairs(seq.square_superparticulars) do
for prime, k_array in pairs(seq.square_superparticulars) do
if prime <= max_prime + 10 then
for i, k in ipairs(k_array) do
for i, k in ipairs(k_array) do
if k <= 1000 then
table.insert(superparticular_indices, k)
table.insert(superparticular_indices, k)
Line 157: Line 158:
end
end
-- is it a square superparticular?
-- is it Sk?
for _, k in ipairs(superparticular_indices) do
for _, k in ipairs(superparticular_indices) do
if p.eq(a, superparticular_ratios[k]) then
if p.eq(a, superparticular_ratios[k]) then
Line 164: Line 165:
end
end
-- is it Sk^2 * S(k+1) or Sk * S(k+1)^2?
-- is it Sk*S(k+1) or Sk/S(k+1) or 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
table.insert(expressions, 'S' .. k .. ' × S' .. (k + 1))
end
if p.eq(a, p.div(r1, r2)) then
table.insert(expressions, 'S' .. k .. ' / S' .. (k + 1))
end
if p.eq(a, p.mul(p.pow(r1, 2), r2)) then
if p.eq(a, p.mul(p.pow(r1, 2), r2)) then
table.insert(expressions, 'S' .. k .. '<sup>2</sup> × S' .. (k + 1))
table.insert(expressions, 'S' .. k .. '<sup>2</sup> × S' .. (k + 1))
end
end
if p.eq(a, p.div(r1, p.pow(r2, 2))) then
if p.eq(a, p.mul(r1, p.pow(r2, 2))) then
table.insert(expressions, 'S' .. k .. ' * S' .. (k + 1) .. '<sup>2</sup>')
table.insert(expressions, 'S' .. k .. ' * S' .. (k + 1) .. '<sup>2</sup>')
end
end
Line 178: Line 185:
end
end
-- is it 1/3-square-particular?
-- is it Sk/S(k+2)?
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
-- is it S(k-1)*Sk*S(k+1)?
for _, k in ipairs(superparticular_indices) do
for _, k in ipairs(superparticular_indices) do
local r1 = superparticular_ratios[k - 1]
local r1 = superparticular_ratios[k - 1]
Line 186: Line 204:
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 a product or a ratio of two square superparticulars?
for _, k1 in ipairs(superparticular_indices) do
local r1 = superparticular_ratios[k1]
for _, k2 in ipairs(superparticular_indices) do
local r2 = superparticular_ratios[k2]
if k1 <= k2 and p.eq(a, p.mul(r1, r2)) then
table.insert(expressions, 'S' .. k1 .. ' × S' .. k2)
end
if k1 <= k2 and p.eq(a, p.div(r1, r2)) then
table.insert(expressions, 'S' .. k1 .. ' / S' .. k2)
end
end
end
end