|
Warning: this is an htmlized version!
The original is here, and the conversion rules are here. |
-- This file:
-- http://anggtwu.net/LUA/Caixinhas1.lua.html
-- http://anggtwu.net/LUA/Caixinhas1.lua
-- (find-angg "LUA/Caixinhas1.lua")
-- Author: Eduardo Ochs <eduardoochs@gmail.com>
--
-- Used by: (c2m251fpa "defs-caixinhas")
Caixinhas = Class {
type = "Caixinhas",
from = function (str) return Caixinhas(split(str)) end,
from1 = function (str) return Caixinhas(split(bitrim(str), "(.)")) end,
__tostring = function (c) return c:tostring() end,
__index = {
innerfmt = "\\,%s\\,",
outerfmt = "\\ensuremath{[%s]}",
sep = ":",
plus = function (c) c = copy(c); c.sep=" + ";
c.innerfmt="%s"; c.outerfmt="\\ensuremath{%s}"
return c end,
pr = function (c) print(VTable(copy(c))); return c end,
ton = function (c) return table.concat(c) end,
tostring = function (c)
local f = function (s) return format(c.innerfmt, s) end
local g = function (s) return format(c.outerfmt, s) end
return g(mapconcat(f,c,c.sep))
end,
coefdotxk = function (c, coef, x, k, dot, simplify)
x = x or "x"
dot = dot or ""
local xk = format("%s^%s", x, k)
if simplify and k == 0 then xk = "" end
if simplify and k == 1 then xk = x end
if simplify and k == 0 then dot = "" end
return coef..dot..xk
end,
itok = function (c, i) return #c-i end,
add = function (c, x, dot, simplify, verbose)
local A = Caixinhas {}
for i=1,#c do A[i] = c:coefdotxk(c[i], x, c:itok(i), dot, simplify) end
return A
end,
cxx = function (c) return c:add(nil, nil, nil) end,
cxxs = function (c) return c:add(nil, nil, "simp") end,
cxd = function (c) return c:add("10", "·", nil) end,
cxds = function (c) return c:add("10", "·", "simp") end,
},
}
--[[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
dofile "Caixinhas1.lua"
= Caixinhas.from " a b c "
= Caixinhas.from1 " 234 "
c = Caixinhas.from1 " 234 "
= c:itok(1)
= c:itok(3)
= c:pr()
= c:pr():add():pr()
= c:pr():add("10", "·"):pr()
= c:pr():add("10", "·", "simp"):pr()
= c:pr():add(nil, nil, nil):pr()
= c:pr():add(nil, nil, "simp"):pr()
= c:ton()
= c:cxx ():pr()
= c:cxxs():pr()
= c:cxd ():pr()
= c:cxds():pr()
= c:cxds():plus():pr()
--]]