Module:Rational: Difference between revisions
ArrowHead294 (talk | contribs) mNo edit summary |
Unify the format for S-expressions |
||
| (One intermediate revision by the same user not shown) | |||
| Line 174: | Line 174: | ||
end | end | ||
-- is it Sk*S(k+1) or Sk/S(k+1) or 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] | ||
| Line 180: | Line 180: | ||
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(r1, r2)) then | ||
table.insert(expressions, "S" .. k .. " | table.insert(expressions, "S" .. k .. "⋅S" .. (k + 1)) | ||
end | end | ||
if p.eq(a, p.div(r1, r2)) then | if p.eq(a, p.div(r1, r2)) then | ||
table.insert(expressions, "S" .. k .. " / S" .. (k + 1)) | table.insert(expressions, "S" .. k .. "/S" .. (k + 1)) | ||
end | 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> | table.insert(expressions, "S" .. k .. "<sup>2</sup>⋅S" .. (k + 1)) | ||
end | end | ||
if p.eq(a, p.mul(r1, p.pow(r2, 2))) then | if p.eq(a, p.mul(r1, p.pow(r2, 2))) then | ||
table.insert(expressions, "S" .. k .. " | table.insert(expressions, "S" .. k .. "⋅S" .. (k + 1) .. "<sup>2</sup>") | ||
end | end | ||
end | end | ||
end | end | ||
-- is it Sk/S(k+2)? | -- is it Sk/S(k + 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] | ||
| Line 200: | Line 200: | ||
if r1 and r2 then | if r1 and r2 then | ||
if p.eq(a, p.div(r1, r2)) then | if p.eq(a, p.div(r1, r2)) then | ||
table.insert(expressions, "S" .. k .. " / S" .. (k + 2)) | table.insert(expressions, "S" .. k .. "/S" .. (k + 2)) | ||
end | end | ||
end | end | ||
end | end | ||
-- is it S(k-1)*Sk*S(k+1)? | -- 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 212: | Line 212: | ||
if r1 and r2 and r3 then | if r1 and r2 and r3 then | ||
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) .. " | table.insert(expressions, "S" .. (k - 1) .. "⋅S" .. k .. "⋅S" .. (k + 1)) | ||
end | end | ||
end | end | ||
| Line 1,086: | Line 1,086: | ||
-- FJS representation of a rational number | -- FJS representation of a rational number | ||
-- | -- NOTE: incorrect for prime 127 and possibly other rare cases | ||
-- TODO: | -- TODO: identify the exact problem and fix it | ||
function p.as_FJS(a) | function p.as_FJS(a) | ||
if type(a) == "number" then | if type(a) == "number" then | ||