Module:Schlafli link

-- Module to turn a list of parameters into a Schläfli symbol with a link to the appropriate page local p = {}

-- Used to call from #invoke. function p.SchLink(frame) local pframe = frame:getParent local args = pframe.args return p._SchLink(args) end

function p.prefix(n) local prefixes = { "hen" , "do" , "tri" , "tetra" , "penta" , "hexa" , "hepta" , "octa" , "ennea" , "deca" } local prefix = "" if (n == 0) then prefix = "null" elseif (n == 1) then prefix = "mono" elseif (n == 2) then prefix = "di" elseif (n < 11) then prefix = prefixes[n] elseif (n < 20) then prefix = prefixes[n - 10] .. "deca" elseif (n == 20) then prefix = "icosa" elseif (n < 30) then prefix = prefixes[n - 20] .. "icosa" else prefix = "apeiro" end return prefix end

function p.gonal(n) local adjective = "" if (n == "3") then adjective = "triangular" elseif (n == "4") then adjective = "square" elseif (n == "inf") then adjective = "apeirogonal" elseif (tonumber(n) ~= nil) then adjective = p.prefix(tonumber(n)) .. "gonal" else -- Bootleg parsing. local frac = string.gmatch(n, "%d+") local numer = tonumber(frac) local denom = frac if (numer ~= nil) then if (numer < 7) then adjective = p.prefix(numer) .. "grammal" else adjective = denom .. "-" .. p.prefix(numer) .. "grammal" end end end return adjective end

function p.comb(n) local combs = { "wawa"     -- unused , "piwin"    -- unused , "tiling" , "honeycomb" } local result = p.prefix(n) .. "comb" if (n < 5) then result = combs[n] end return result end

function p._pagename(args) local link = "" -- Default to the ASCII CDD when nothing else works. Some of these redirect to the correct page. local coxsymb = "x" for v, k in ipairs(args) do   coxsymb = coxsymb .. k .. "o" end link = coxsymb

if (#args == 0) then link = "dyad" elseif (#args == 1) then link = args[1] .. "-gon" elseif (#args == 2) then link = "order-" .. args[2] .. " " .. p.gonal(args[1]) .. " tiling" -- Special cases for named regulars if (args[1] == "3") then if (args[2] == "3") then link = "tetrahedron" elseif (args[2] == "4") then link = "octahedron" elseif (args[2] == "5") then link = "icosahedron" elseif (args[2] == "6") then link = "triangular tiling" elseif (args[2] == "5/2") then link = "great icosahedron" end elseif (args[1] == "4") then if (args[2] == "3") then link = "cube" elseif (args[2] == "4") then link = "square tiling" end elseif (args[1] == "5") then if (args[2] == "3") then link = "dodecahedron" elseif (args[2] == "5/2") then link = "great dodecahedron" end elseif (args[1] == "5/2") then if (args[2] == "3") then link = "great stellated dodecahedron" elseif (args[2] == "5") then link = "small stellated dodecahedron" end elseif (args[1] == "6") then if (args[2] == "3") then link = "hexagonal tiling" end end elseif (#args == 3) then if (args[2] == "3") then link = "order-" .. args[3] .. " " .. p.gonal(args[1]) .. " tiling honeycomb" end

if (args[1] == "3") then if (args[2] == "3") then link = "order-" .. args[3] .. " tetrahedral honeycomb" if (args[3] == "3") then link = "pentachoron" elseif (args[3] == "4") then link = "16-cell" elseif (args[3] == "5") then link = "600-cell" end elseif (args[2] == "4") then link = "order-" .. args[3] .. " octahedral honeycomb" if (args[3] == "3") then link = "24-cell" end elseif (args[2] == "5") then link = "order-" .. args[3] .. " icosahedral honeycomb" elseif (args[2] == "6") then link = "order-" .. args[3] .. " triangular tiling honeycomb" end elseif (args[1] == "4") then if (args[2] == "3") then link = "order-" .. args[3] .. " cubic honeycomb" if (args[3] == "3") then link = "tesseract" elseif (args[3] == "4") then link = "cubic honeycomb" end elseif (args[2] == "4") then link = "order-" .. args[3] .. " square tiling honeycomb" end elseif (args[1] == "5") then if (args[2] == "3") then link = "order-" .. args[3] .. " dodecahedral honeycomb" if (args[3] == "3") then link = "120-cell" end end end -- Dimensions 5 and up are complete up to convex regular polytopes. -- Dimensions 5 to 29 are complete up to hypercombs. else -- Check for platonic solids local is_simplex = true local is_cube = true local is_orthoplex = true local is_hypercomb = true for v, k in ipairs(args) do     is_simplex = is_simplex and (k == "3") is_cube = is_cube and (k == "3" or (k == "4" and v == 1)) is_orthoplex = is_orthoplex and (k == "3" or (k == "4" and v == #args)) is_hypercomb = is_hypercomb and (k == "3" or (v == #args or (k == "4" and v == 1))) end if is_simplex then link = #args + 1 .. "-simplex" elseif is_cube then link = #args + 1 .. "-cube" elseif is_orthoplex then link = #args + 1 .. "-orthoplex" elseif is_hypercomb then local cubics = { "dyadic"     -- unused , "square"     -- unused , "cubic"      -- unused , "tessaractic" -- unused , "pentaractic" , "hexaractic" , "heptaractic" , "octaractic" , "enneractic" }     if (#args < 9) then link = prefixes[#args] .. " " .. p.comb(#args) elseif (#args < 30) then link = p.prefix(#args) .. "ractic " .. p.comb(#args) end if (args[#args] ~= "4") then link = "order-" .. args[#args] .. " " .. link end end if (#args == 4) then if (args[1] == "3" and args[2] == "3" and args[3] == "4") then link = "order-" .. args[4] .. " hexadecachoric tetracomb" elseif (args[1] == "3" and args[2] == "4" and args[3] == "3") then link = "order-" .. args[4] .. " icositetrachoric tetracomb " elseif (args[1] == "4" and args[2] == "3" and args[3] == "3") then link = "order-" .. args[4] .. " tesseractic tetracomb" end end end if (string.lower(args["pi"]) == "yes") then link = "Petrial " .. link end return link end

-- Used when calling from other Lua modules. function p._SchLink(args) local math = "\\{" local divider = "" for v, k in ipairs(args) do   if (v ~= '') then math = math .. divider .. k     divider = "," end end math = math .. "\\}" if (string.lower(args["pi"]) == "yes") then math = math .. "^{\\pi}" end local body = "$" .. math .. "$" return body end

return p