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.checkinfinite(n) local num = "" if (n == "inf") then num = "∞" else num = n end return num end

function p.comb(n) local combs = { "pilin" -- unused , "tiling" , "honeycomb" } local result = p.prefix(n) .. "comb" if (n < 4) 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

local symb_length = 1 for v, k in ipairs(args) do   if (v > symb_length) then symb_length = v   end end local rank = symb_length + 1

if (rank == 1) then link = "dyad" elseif (rank == 2) then local n = args[1] -- If the denominator is zero ignore it   if (string.gmatch(args[1], "%d+/1$") ~= nil) then n = string.gmatch(args[1], "%d+") end link = n .. "-gon" if (args[1] == "inf") then link = "apeirogon" end elseif (rank == 3) then link = "order-" .. p.checkinfinite(args[2]) .. " " .. p.gonal(args[1]) .. " tiling" if (args[1] == "2") then link = "hosohedron" end if (args[2] == "2") then link = "dihedron" end -- 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 (rank == 4) then if (args[2] == "3") then link = "order-" .. p.checkinfinite(args[3]) .. " " .. p.gonal(args[1]) .. " tiling honeycomb" end

if (args[1] == "3") then if (args[2] == "3") then link = "order-" .. p.checkinfinite(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-" .. p.checkinfinite(args[3]) .. " octahedral honeycomb" if (args[3] == "3") then link = "24-cell" end elseif (args[2] == "5") then link = "order-" .. p.checkinfinite(args[3]) .. " icosahedral honeycomb" elseif (args[2] == "6") then link = "order-" .. p.checkinfinite(args[3]) .. " triangular tiling honeycomb" end elseif (args[1] == "4") then if (args[2] == "3") then link = "order-" .. p.checkinfinite(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-" .. p.checkinfinite(args[3]) .. " square tiling honeycomb" end elseif (args[1] == "5") then if (args[2] == "3") then link = "order-" .. p.checkinfinite(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 == symb_length)) is_hypercomb = is_hypercomb and (k == "3" or (v == symb_length or (k == "4" and v == 1))) end if is_simplex then link = rank .. "-simplex" elseif is_cube then link = rank .. "-cube" elseif is_orthoplex then link = rank .. "-orthoplex" elseif is_hypercomb then local cubics = { "pointic"    -- unused , "dyadic"     -- unused , "square"     -- unused , "cubic"      -- unused , "tesseractic" , "pentaractic" , "hexaractic" , "heptaractic" , "octaractic" , "enneractic" , "dekeractic" , "hendekeractic" , "dodekeractic" , "tridekeractic" , "tetradekeractic" , "pentadekeractic" , "hexadekeractic" }     if (cubics[rank] == nil) then link = cubics[rank] .. " " .. p.comb(rank - 1) elseif (rank < 31) then link = p.prefix(rank - 1) .. "ractic " .. p.comb(rank - 1) end if (args[symb_length] ~= "4") then link = "order-" .. p.checkinfinite(args[symb_length]) .. " " .. link end end if (rank == 5) then if (args[1] == "3" and args[2] == "3" and args[3] == "4") then link = "order-" .. p.checkinfinite(args[4]) .. " hexadecachoric tetracomb" elseif (args[1] == "3" and args[2] == "4" and args[3] == "3") then link = "order-" .. p.checkinfinite(args[4]) .. " icositetrachoric tetracomb " end elseif (rank == 6) then if (args[1] == "3" and args[2] == "3" and args[3] == "3" and args[4] == "4") then link = "order-" .. p.checkinfinite(args[5]) .. " triacontaditeric pentacomb" end end end if (p.hemi(args)) then link = "hemi-" .. link end if (p.petrial(args)) then link = "Petrial " .. link end return link end

function p._symbol(args) local math = "{" local divider = "" for v, k in ipairs(args) do   if (v ~= '') then if (k == "inf") then math = math .. divider .. "&infin;" else math = math .. divider .. k     end divider = "," end end math = math .. "}" if (p.hemi(args)) then math = math .. "/2" end if (p.petrial(args)) then math = math .. "&pi;" end return math end

function p.petrial(args) local aliases = { "pi" , "pet" , "petrial" } local petrial = false for k, v in ipairs(aliases) do   petrial = petrial or (args[v] ~= nil and string.lower(args[v]) == "yes") end return petrial end

function p.hemi(args) local aliases = { "hemi" } local hemi = false for k, v in ipairs(aliases) do   hemi = hemi or (args[v] ~= nil and string.lower(args[v]) == "yes") end return hemi end

-- Used when calling from other Lua modules. function p._SchLink(args) local prespan = "" local postspan = " " local body = prespan .. p._symbol(args) .. postspan if (args["text"] ~= nil and string.lower(args["text"]) == "yes") then body = p._pagename(args) end if (args["link"] == nil or string.lower(args["link"]) ~= "no") then body = "" .. body .. "" end return body end

return p