Warning: this is an htmlized version!
The original is here, and
the conversion rules are here.
#!/usr/bin/env lua51
-- canvas3.lua
-- Eduardo Ochs, 2011jan17
-- This file: (find-angg "LUA/canvas3.lua")
--    http://angg.twu.net/LUA/canvas3.lua
--    http://angg.twu.net/LUA/canvas3.lua.html
-- See: (find-angg "LUA/canvas2.lua")
--      (find-LATEX "2011ebl-abs.tex")



-- «.string»		(to "string")
-- «.string-tests»	(to "string-tests")
-- «.table»		(to "table")
-- «.table-tests»	(to "table-tests")
-- «.Class»		(to "Class")
-- «.Canvas»		(to "Canvas")
-- «.Canvas-tests»	(to "Canvas-tests")
-- «.binstrings»	(to "binstrings")
-- «.binstrings-test»	(to "binstrings-test")
-- «.Dag-functions»	(to "Dag-functions")
-- «.Dag»		(to "Dag")
-- «.Dag-tests»		(to "Dag-tests")
-- «.ZDag-functions»	(to "ZDag-functions")
-- «.ZDag»		(to "ZDag")
-- «.ZDag-predef»	(to "ZDag-predef")
-- «.ZDag-tests»	(to "ZDag-tests")
-- «.simpledef»		(to "simpledef")
-- «.complexdef»	(to "complexdef")
-- «.complexdef-tests»	(to "complexdef-tests")
-- «.Scale»		(to "Scale")
-- «.Scale-tests»	(to "Scale-tests")
-- «.Changes»		(to "Changes")
-- «.defpictureFrom»	(to "defpictureFrom")
-- «.lguill-diagram»	(to "lguill-diagram")

-- «.2011ebl-defs»	(to "2011ebl-defs")
-- «.sfc-defs»		(to "sfc-defs")

-- (find-es "lua5" "setvbuf")
io.stdout:setvbuf("no")  -- sync errors


-- Basic functions.
-- «string»  (to ".string")
--
string.trim = function (str)
    local nspaces = string.reverse(str):match("[ \t]*()") - 1
    return string.sub(str, 1, #str - nspaces)
  end
string.adjustto = function (str, len)
    str = string.sub(str, 1, len)
    if #str < len then str = str .. string.rep(" ", len - #str) end
    return str
  end
string.replace = function (str, other, pos)
    local left = string.sub(str, 1, pos - 1)
    if #left < pos - 1 then left = left .. string.rep(" ", pos - #left - 1) end
    local right = string.sub(str, pos + #other)
    return left .. other .. right
  end
string.tocanvas = function (str, initialy)
    local T = {}
    for i,li in ipairs(splitlines(str)) do  
      table.replace1(T, li, 1, i+(initialy or 1)-1)  -- below
    end
    return T
  end

-- «string-tests»  (to ".string-tests")
assert(string.trim("abcd  ") == "abcd")
assert(string.trim("abcde") == "abcde")
assert(string.adjustto("abcdef", 4) == "abcd")
assert(string.adjustto("abcdef", 8) == "abcdef  ")
assert(string.replace("abcdef", "CD", 3) == "abCDef")
assert(string.replace("ab",     "CD", 3) == "abCD")
assert(string.replace("a",      "CD", 3) == "a CD")


-- «table»  (to ".table")
--
table.transpose = function (T)
    local TT = {}
    for k,v in pairs(T) do TT[v] = k end
    return TT
  end
table.swaps = function (T, swaps)
    if swaps then
      for _,ab in ipairs(swaps) do
        local a, b = ab[1], ab[2]
        T[a], T[b] = T[b], T[a]
      end
    end
    return T
  end
table.size = function (T)
    for i=1,10000000 do if T[i] == nil then return i-1 end end
  end
table.negsize = function (T)
    if not T[1] then return nil end
    for i=1,-10000000,-1 do if T[i] == nil then return i+1 end end
  end
table.assert = function (T, n, filler)
    if n >= 1 then 
      for i=1,n do T[i] = T[i] or filler end
    else
      for i=1,n,-1 do T[i] = T[i] or filler end
    end
  end
table.replace1 = function (T, str, x, y)
    table.assert(T, y, "")
    T[y] = string.replace(T[y], str, x)
    return T
  end
table.replacemany = function (T, otherT, x, y)
    for i=table.negsize(otherT),table.size(otherT) do
       table.replace1(T, otherT[i], x, i+(y or 1)-1)
    end
    return T
  end

canvastostring = function (T)
    return table.concat(T, "\n", table.negsize(T), table.size(T))
  end


-- Tests for the basic functions.

-- «table-tests»  (to ".table-tests")
assert(table.concat(table.transpose({on=1, tw=2, th=3}), " ") == "on tw th")
assert(table.concat(table.swaps({10, 20, 30, 40}, {{3, 4}})) == "10204030")

A = {[-5]=-50, [-3]=-30, [-2]=-20, [-1]=-10, [0]=0, 10, 20, 30, 40, 50, nil, 70}
assert(table.negsize(A) == -3)
assert(table.size(A)    ==  5)

strA = "-1\n0\n1\n2"
strB = "a\nb\nc"
assert(strA:tocanvas(-1)[-1] == "-1")
assert(canvastostring(strA:tocanvas(-1)) == strA)

CA = strA:tocanvas(-1)
CB = strB:tocanvas(0)
assert(canvastostring(table.replacemany(CA, CB, 3, 1)) == "-1\n0 a\n1 b\n2 c")
CA = strA:tocanvas(-1)
CB = strB:tocanvas(0)
assert(canvastostring(table.replacemany(CA, CB, 2, -1)) == " a\n-b\n0c\n1\n2")





-- «Class»  (to ".Class")
-- (find-blogme4 "eoo.lua")
Class = {
    type   = "Class",
    __call = function (class, o) return setmetatable(o, class) end,
  }
setmetatable(Class, Class)
otype = function (o)
    local mt = getmetatable(o)
    return mt and mt.type or type(o)
  end


-- «Canvas»  (to ".Canvas")
Canvas = Class {
  type    = "Canvas",
  __index = {
    miny = function (C) return table.negsize(C) end,
    maxy = function (C) return table.size(C) end,
    width = function (C)
        local w = 0
        for y=C:miny(),C:maxy() do w = math.max(w, #C[y]) end
        return w
      end,
    tostring = function (C) return canvastostring(C) end,
    draw = function (C, obj, x, y)
        if type(obj) == "string" then table.replace1(C, obj, x, y)
        elseif type(obj) == "table" then table.replacemany(C, obj, x, y)
        end
        return C
      end
  },
}
CanvasFrom = function (str, initialy)
    return Canvas(string.tocanvas(str, initialy))
  end


-- «Canvas-tests»  (to ".Canvas-tests")
C = Canvas {[0]="0", "1", "2"}
assert(C:tostring() == "0\n1\n2")
assert(C:miny() == 0)
assert(C:maxy() == 2)
CA, CB = CanvasFrom("0\n1\n2", 0), CanvasFrom("a\nb\nc", 1)
CA, CB = CanvasFrom("0\n1\n2", 0), CanvasFrom("a\nb\nc", 1)
CC     = CA:draw(CB, 4, 1)
assert(CC:tostring() == "0\n1  a\n2  b\n   c")
assert(CC:width()    == 4)



-- «binstrings»  (to ".binstrings")
binstrings_ = {}
binstrings_[1] = {"0", "1"}
binstrings = function (n)
    for m=#binstrings_+1,n do
      binstrings_[m] = {}       -- calculate binstrings_[m]
      for _,v in ipairs(binstrings_[m-1]) do
        table.insert(binstrings_[m], v.."0")
        table.insert(binstrings_[m], v.."1")
      end
    end
    return binstrings_[n]
  end

-- «binstrings-test»  (to ".binstrings-test")
assert(binstrings(6)[63] == "111110")





-- «Dag-functions»  (to ".Dag-functions")
interior = function (short, arrows)
    local T = split(short, ".")
    for i=#arrows,1,-1 do
      local src, tgt = arrows[i][1], arrows[i][2]
      -- if (not T[src]) or (not T[tgt]) then
      --   PP("Too short!", short, arrows)
      -- end
      if T[src] > T[tgt] then T[src] = T[tgt] end
    end
    return table.concat(T, "")
  end
cointerior = function (short, arrows)
    local T = split(short, ".")
    for i=1,#arrows do
      local src, tgt = arrows[i][1], arrows[i][2]
      if (not T[src]) or (not T[tgt]) then
        PP("Too short!", short, arrows)
      end
      if T[src] > T[tgt] then T[tgt] = T[src] end
    end
    return table.concat(T, "")
  end
opensetsfor = function (n, arrows)
    local opensets = {}
    for _,short in ipairs(binstrings(n)) do
      if short == interior(short, arrows) then
        table.insert(opensets, short)
      end
    end
    return opensets
  end
singleton = function (len, i)
    return ("0"):rep(i-1) .. "1" .. ("0"):rep(len-i)
  end
representablesfor = function (n, arrows)
    local T = {}
    for i=1,n do table.insert(T, cointerior(singleton(n, i), arrows)) end
    return T
  end
essentialize = function (short, arrows)  -- experimental (2011jan24), slow
    local n = #short
    local shortT     = split(short, ".")
    local essential  = ("0"):rep(n)
    local essentialT = split(essential, ".")
    local generated  = essential   -- == cointerior(essential)
    local generatedT = split(generated, ".")
    for i=1,n do
      if shortT[i] == "1" and generatedT[i] == "0" then
        essentialT[i] = "1"
        essential     = table.concat(essentialT, "")
        generated     = cointerior(essential, arrows)
        generatedT    = split(generated, ".")
        -- if short == generated then return essential end
      end
    end
    return essential
  end

-- «Dag»  (to ".Dag")
Dag = Class {
  type    = "Dag",
  __index = {
    interior   = function (dag, short) return interior  (short, dag.arrows) end,
    cointerior = function (dag, short) return cointerior(short, dag.arrows) end,
    representable = function (dag, i)
        return dag:cointerior(singleton(dag.n, i))
      end,
    essentialize = function (dag, short)
        return essentialize(short, dag.arrows)
      end,
  },
}
Dags = {}
NewDag = function (name, n, arrows)
    local opensets = opensetsfor(n, arrows)
    local representables = representablesfor(n, arrows)
    Dags[name] = Dag {name=name, n=n, arrows=arrows,
        opensets=opensets, representables=representables}
    return Dags[name]
  end

-- «Dag-tests»  (to ".Dag-tests")
NewDag("Vee", 3, {{1, 3}, {2, 3}})
assert(table.concat(Dags["Vee"].opensets, " ") == "000 001 011 101 111")
assert(table.concat(Dags["Vee"].representables, " ") == "101 011 001")






-- «ZDag-functions»  (to ".ZDag-functions")
-- A "shape" is a string made of digits, newlines, and spaces.
-- A "short" is a string made of "0"s and "1"s.
-- For example:
-- reh_shape = " 1\n"  ..
--             "2 3\n" ..
--             "4"
-- and "0101" is a short that represents an open set on Reh
-- in a compact form.

cton = function (c) return tonumber(c, 36) end
intoshape = function (shape, short)
    local f = function (c) return short:sub(cton(c), cton(c)) end
    return (shape:gsub("(%w)", f))
  end
shapetoarrows = function (shape)
    local lines = splitlines(shape)
    local arrows = {}
    local registerbpm = function (v1, v2)
        if v1 and v2 then table.insert(arrows, {v1, v2}) end
      end
    for y=1,#lines-1 do
      for x=1,#lines[y] do
        local c  = cton(lines[y  ]:sub(x,   x  ))
        local sw = cton(lines[y+1]:sub(x-1, x-1))
        local s  = cton(lines[y+1]:sub(x,   x  ))
        local se = cton(lines[y+1]:sub(x+1, x+1))
        registerbpm(c, sw)    -- is southwest a black pawn's move?
        registerbpm(c, s)     -- is south     a black pawn's move?
        registerbpm(c, se)    -- is southeast a black pawn's move?
      end
    end
    return arrows
  end
shapetocoords = function (shape)
    local lines = splitlines(shape)
    local coords = {}
    for y=1,#lines do
      for x=1,#lines[y] do
        local c  = cton(lines[y]:sub(x, x))
	if c then coords[c] = {x, y} end
      end
    end
    return coords
  end

-- «ZDag»  (to ".ZDag")
-- I will abbreviate "$\Z^2$-DAG" to "ZDag".
ZDag = Class {
  type    = "ZDag",
  __index = {
    ify = function (zdag, short) return intoshape(zdag.shape, short) end,
    interior   = function (zd, short) return interior  (short, zd.arrows) end,
    cointerior = function (zd, short) return cointerior(short, zd.arrows) end,
    representable = function (dag, i)
        return dag:cointerior(singleton(dag.n, i))
      end,
    essentialize = function (dag, short)
        return essentialize(short, dag.arrows)
      end,
  },
}
ZDags = {}
NewZDag = function (name, shape, lower, noopensets)
    shape = shape:gsub("|", "\n")
    shape = shape:gsub("%.", " ")
    local coords = shapetocoords(shape)
    local arrows = shapetoarrows(shape)
    local canvas = CanvasFrom(shape, 1)
    local width, height = canvas:width(), #canvas
    -- Only the fields name, n, arrows, opensets are from Dags...
    -- In Dags the n is given as a parameter, here it is calculated.
    local n = #coords   -- number of vertices
    local opensets = (not noopensets) and opensetsfor(n, arrows)
    local representables = representablesfor(n, arrows)
    ZDags[name] = ZDag {name=name, n=n, arrows=arrows,
      opensets=opensets, representables=representables,
      shape=shape, coords=coords, arrows=arrows, width=width, height=height,
      lower=lower}  -- "lower" is used by defpicture
    _G[name] = ZDags[name]
    return ZDags[name]
  end

-- «ZDag-predef»  (to ".ZDag-predef")
-- Some "predefined" zdags.
NewZDag("Vee",    "1.2|.3.", 0)
NewZDag("Lambda", ".1.|2.3", 0)
NewZDag("Reh",    ".1.|2.3|4", 0)
NewZDag("Kite",   ".1.|2.3|.4.|.5.", 1)
NewZDag("Wdot",   "1.2.3.|.4.5.6", 0)
NewZDag("WdotP",  "1...2...3..|..4...5...6", 0)
NewZDag("Guill",      ".1.2|3.4.|.5.6", 1)
NewZDag("GuillPrime", "..1|.2.3|..4.5|.6.7|8.9|.A.B|..C", 3, "noopensets")
NewZDag("Rect",    "1.2.3.4|5.6.7.8|9.A.B.C|D.E.F.G", 1, "noopensets")
NewZDag("Lozenge", "...1|..2.3|.4.5.6|7.8.9.A|.B.C.D|..E.F|...G", 3, "noopens")

NewZDag("Hthree", "1.2.3", 0)

-- «ZDag-tests»  (to ".ZDag-tests")
assert(table.concat(Vee.opensets, " ") == "000 001 011 101 111")
assert(Kite:ify("abcde") == " a \nb c\n d \n e ")
assert(#Reh.opensets == 7)
assert(Reh.opensets[5] == "0101")
assert(Reh:interior("0110") == "0010")
assert(Reh:cointerior("0110") == "0111")




-- «simpledef»  (to ".simpledef")
simpledef = function (name, nargs, body)
    local ha, han
    ha  = function (myn) return format("#%d", myn) end
    han = function (np)  return mapconcat(ha, seq(1, np)) end
    return format("\\def\\%s%s{%%\n%s}", name, han(nargs), body)
  end
simplega = function (myn) return format("#%d", myn) end

-- «complexdef»  (to ".complexdef")
complexdef = function (name, nargs, body)
    local ha, han, sa, saf, san, na, bg, da, dal
    ha  = function (hn)      return format("#%d", hn) end
    han = function (np)      return mapconcat(ha, seq(1, np)) end
    sa  = function (myn, hn) return format("\\sa{%d}{#%d}", myn, hn) end
    saf = function (n)
        return function (hn) return sa(5*n + hn, hn) end
      end
    san = function (n, np)   return mapconcat(saf(n), seq(1, np)) end
    na  = function (n)       return format("\\%s%s", name, ("@"):rep(n)) end
    bg  = function (n)       return n==0 and "\\begingroup" or "" end
    da = function (n)
        return format("\\def%s%s{%s%%\n", na(n), han(5), bg(n))
            .. format("  %s%s}\n",        san(n, 5), na(n + 1))
      end
    dal = function (n, np)
        return format("\\def%s%s{%%\n", na(n), han(np))
            .. format("  %s%%\n",       san(n, np))
            .. body
            .. "  \\endgroup}\n"
      end
    local T = {}
    local np = nargs
    tinsert(T, "\\makeatletter\n")  -- hacky
    for n=0,10000 do                -- hacky
      if np > 5
      then tinsert(T, da(n)); np = np - 5
      else tinsert(T, dal(n, np)); break
      end
    end
    tinsert(T, "\\makeatother\n")   -- hacky
    return table.concat(T, "")
  end
complexga = function (myn) return format("\\ga{%d}", myn) end

nargstodefga = function (nargs)
    if nargs <= 9 then
      return simpledef, simplega
    else
      return complexdef, complexga
    end
  end

--[[
-- «complexdef-tests»  (to ".complexdef-tests")
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
ee_dofile "canvas3.lua"
= simpledef ("nam",   9, "% body\n")
= complexdef("name", 10, "%body\n")
--]]




-- «Scale»  (to ".Scale")
Scale = Class {
  type    = "Scale",
  __index = {
    -- Defaults for a thin Zdag:
    sx =   6,     x0 = 1,
    sy = -12,  -- y0 = zdag.height,
    w0 =   2,     h0 = 0,
    xadj = 0,     yadj = 0,
    -- Methods:
    xytopxpy = function (s, x, y)
      return s.sx * (x - s.x0) + s.xadj, s.sy * (y - s.y0) + s.yadj end,
    whtopwph = function (s, w, h) return s.sx * w + s.w0, -s.sy * h + s.h0 end,
    put = function (s, x, y, mathbody)
        local px, py = s:xytopxpy(x, y)
        return format("    \\dagput(%3d,%3d){$%s$}\n", px, py, mathbody)
      end,
    puts = function (s, coords, ga)
        local T = {}
        for i,xy in ipairs(coords) do
          table.insert(T, s:put(xy[1], xy[2], ga(i)))
        end
        return table.concat(T)
      end,
    arrowxybody = function (s, coords, arrow)
        local src, tgt = arrow[1], arrow[2]
        local srcx, srcy = coords[src][1], coords[src][2]
        local tgtx, tgty = coords[tgt][1], coords[tgt][2]
        local x, y = (srcx + tgtx)/2, (srcy + tgty)/2
        local dx = tgtx - srcx
        local possiblebodies = {
          [-1] = "\\swarrow",
           [0] = "\\downarrow",
           [1] = "\\searrow",
        }
        local body = possiblebodies[dx]
        return x, y, body
      end,
    putarrows = function (s, zdag)
        local T = {}
        for i,arrow in ipairs(zdag.arrows) do
          table.insert(T, s:put(s:arrowxybody(zdag.coords, arrow)))
        end
        return table.concat(T)
      end,
    body = function (s, zdag, ga)
       return s:puts(zdag.coords, ga)
              .. (s.drawarrows and s:putarrows(zdag) or "")
      end,
    -- bodyandarrows = function (s, zdag, ga)
    --    return s:puts(zdag.coords, ga) .. s:putarrows(zdag)
    --   end,
    dagpicture = function (s, body)
        local plower = -s.sy * (s.lower or 0)
        local pw, ph = s:whtopwph(s.w, s.h)
        return format("  \\dagpicture(%d,%d)(-4,0)[%d]{\n%s  }%%\n",
                      pw, ph, plower, body)
      end,
    picture = function (s, zdag, ga)
        return s:dagpicture(s:body(zdag, ga))
      end,
    defpicture = function (s, zdag, name)
        local nargs = zdag.n
        local def, ga = nargstodefga(nargs)
        local body = s:picture(zdag, ga)
        return def(name, nargs, body) .. "%\n"
      end,
  },
}


-- «Scale-tests»  (to ".Scale-tests")
-- Obsolete, deleted...
--[[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
ee_dofile "canvas3.lua"
--]]



-- «Changes»  (to ".Changes")
Changes = Class {
  type    = "Changes",
  __index = {
  },
}
Thin   = Changes {sx=6,  w0=2}
Wide   = Changes {sx=12, w0=-4}
Medium = Changes {sx=6, sy=8, w0=0}



-- «defpictureFrom»  (to ".defpictureFrom")
defs_ = {}
ScaleFrom = function (zdag, changes, lower)
    changes = changes or {}
    changes.lower = lower or changes.lower or zdag.lower or 0
    local s = {y0=zdag.height, w=zdag.width, h=zdag.height}
    for k,v in pairs(changes) do s[k] = v end
    return Scale(s)
  end
defpictureFrom = function (prefix, zdag, changes, lower)
    local def = ScaleFrom(zdag, changes, lower)
              :defpicture(zdag, prefix..zdag.name)
    table.insert(defs_, def)
    return def
  end
withsaandga = function (body)
    return [[
\edrxcolors              % Temporary?
\def\bhbox{\bicolorhbox} % Temporary?
% (find-es "tex" "more-than-9-args")
\def\sa#1#2{\expandafter\def\csname myarg#1\endcsname{#2}}
\def\ga#1{\csname myarg#1\endcsname}
\makeatletter
]] .. body .. [[
\makeatother
]]
  end
defs = function () return withsaandga(table.concat(defs_)) end



ebl_defs = function ()
    header = [===[
      % Generated by: (find-angg "LUA/canvas3.lua"  "2011ebl-defs")
    ]===]
    -- (find-LATEX "2011ebl-abs.tex" "geometric-discr" "dagWdot")
    -- (find-LATEX "2011ebl-abs.tex" "geometric-epi"   "dagRft")
    -- (find-LATEX "2011ebl-abs.tex" "geometric-monic" "Dee")
    NewZDag("Vee",     "1.2|.3", 0.5)
    NewZDag("Wdot",    "1.2.3.|.4.5.6", 0.5)
    NewZDag("WdotT",   "1.2.3.||.4.5.6", 1)
    NewZDag("WdotP",   "1...2...3..|..4...5...6", 0.5)
    NewZDag("Rft",     "1.2.3.4|5.6.7.8", 0.5)   -- rectangle, four by two
    NewZDag("Rfo",     "1.2.3.4", 0)             -- rectangle, four by one
    NewZDag("Dee",     "1.|.2|3.|.4|5.", 2)
    NewZDag("DeeWide", ".1..|2.3.|.4.5|6.7.|.8..", 2)
    -- (find-angg "LUA/canvas3.lua" "Changes")
    Smash        = Changes {sx=12, sy=-6, w0=-4, h0=6}
    Smash        = Changes {sx=10, sy=-6, w0=-4, h0=6}
    defpictureFrom("dag",   Vee)
    defpictureFrom("dag",   Wdot)
    defpictureFrom("dag",   WdotT)
    defpictureFrom("dag",   WdotP)
    defpictureFrom("dag",   Rft)
    defpictureFrom("dag",   Rfo)
    defpictureFrom("smash", Dee,     Smash)
    defpictureFrom("smash", DeeWide, Smash)
    --
    Proportional = Changes {sx=12, sy=-12, w0=-4, h0=6}
    defpictureFrom("proportional",  Vee, Proportional)
    --
    Huge = Changes {sx=40, sy=-40, drawarrows=true, xadj=10}
    Huge = Changes {sx=40, sy=-40, drawarrows=true, xadj=10, yadj=10}
    Huge = Changes {sx=40, sy=-40, drawarrows=true,
                    xadj=12, yadj=10, h0=-10, w0=-8}
    Big  = Changes {sx=30, sy=-35, drawarrows=true, h0=-18, w0=-22}
    defpictureFrom("dag",  Guill)
    defpictureFrom("dag",  GuillPrime)
    defpictureFrom("huge", GuillPrime, Huge)
    defpictureFrom("big" , Kite,       Big)
    defpictureFrom("big" , Guill,      Big)
    --
    NewZDag("O", ".1.|2.3|4.5|.6.", 1.5)
    defpictureFrom("dag" , O)
    --
    NewZDag("LozengeThree", "..1|.2.3|4.5.6|.7.8|..9", 2, "noopensets")
    NewZDag("Cube",         ".1.|234|567|.8.",       1.5, "noopensets")
    NewZDag("VV",     "1.2|3.4", 0.5)
    NewZDag("Hthree", "1.2.3", 0)
    NewZDag("Hthree", "123", 0)
    table.remove(Cube.arrows, 7)
    defpictureFrom("big" , Cube,         Big, 1.5)
    defpictureFrom("big" , LozengeThree, Big, 2)
    defpictureFrom("big" , VV,           Big, 0.5)
    defpictureFrom("big" , Hthree,       Big, 0)
    defpictureFrom("dag" , VV,           Proportional, 0)
    defpictureFrom("dag" , Hthree,       Proportional, -0.5)
    --
    NewZDag("TwoOne",      "1..|2.3", 0)
    NewZDag("TwoOnePrime", ".1|2.3|.4.5|..6", 1.5)
    defpictureFrom("dag" , TwoOne,       Proportional, 0) 
    defpictureFrom("dag" , TwoOnePrime,  Proportional, 1.5) 
    --
    defpictureFrom("big" , Vee,          Big)
    NewZDag("KitePrime", ".1.|.2.|3.4|.5.|.6.|.7.", 2)
    defpictureFrom("dag" ,  KitePrime)
    Huge4 = Changes {sx=55, sy=-55, drawarrows=true,
                     xadj=12, yadj=10, h0=-10, w0=-8}
    Huge4 = Changes {sx=60, sy=-60, drawarrows=true,
                     xadj=12, yadj=10, h0=-10, w0=-8}
    Huge4 = Changes {sx=60, sy=-87, drawarrows=true,
                     xadj=12, yadj=10, h0=-10, w0=-8}
    defpictureFrom("huge" , KitePrime,   Huge4)
  end




--[[
-- «2011ebl-defs»  (to ".2011ebl-defs")
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
ee_dofile "canvas3.lua"
ebl_defs()
writefile("/tmp/mydags.tex", header .. defs())
* (find-sh0 "cp -v /tmp/mydags.tex ~/LATEX/2011ebl-defs.tex")
-- (find-sh0 "cp -v /tmp/mydags.tex ~/LATEX/2011ebl-defs.tex")
-- (find-fline "/tmp/mydags.tex" "smashDeeWide")
-- (find-angg "LATEX/2011ebl-defs.tex" "smashDeeWide")

-- defpictureFrom("dag" , VV,     Proportional)
-- defpictureFrom("dag" , Hthree, Proportional)
--
-- NewZDag("LozengeFour",  "...1|..2.3|.4.5.6|7.8.9.A|.B.C.D|..E.F|...G", 3, "noopens")
--
-- defs()



-- «sfc-defs» (to ".sfc-defs")
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
ee_dofile "canvas3.lua"
ebl_defs()
writefile("~/sheavesforchildren/sfc-defs.tex", header .. defs())





PP(Guill)
PP(GuillPrime)


-- writefile("/tmp/mydags.tex", defs())
--  (find-fline "/tmp/mydags.tex" "smashDeeWide")
--   \dagpicture(44,36)(-4,0)[12]{

= defs()
writefile("/tmp/mydags.tex", defs())

guillord = {12, 11,10, 8,9, 7,5, 6,4, 3,2, 1}
isrepresentable = table.transpose(Guill.representables)
PP(isrepresentable)
for _,i in ipairs(guillord) do
  local short = Guill.opensets[i]
  local isrep = isrepresentable[short]
  if isrep then
    printf(" {(\\dagGuill %s)} %% %d\n", Guill.opensets[i], i)
  else
    printf("  {\\dagGuill %s}  %% %d\n", Guill.opensets[i], i)
  end
end

for _,i in ipairs(guillord) do
  local short = Guill.opensets[i]
  printf("  {\\dagGuill %s}  %% %d\n", Guill:essentialize(short), i)
end






%*
% (eedn4a-bounded)
\input /tmp/mydags.tex  % (find-fline "/tmp/mydags.tex" "smashDeeWide")

% \def\smashDeeWide#1#2#3#4#5#6#7#8{%
%   \dagpicture(44,36)(-4,0)[12]{

% foo \bhbox{$\dagDeeWide 12345678$}
bar \bhbox{$\smashDee     13478$}
to  \bhbox{$\smashDeeWide 12345678$}
to  \bhbox{$\left(\smashDeeWide 12345678\right)$}
to  \bhbox{$\left(\smashDeeWide 12345678\right)$}



\def\int  {{\mathsf{int}}}
\def\und  {{\mathsf{und}}}
\def\discr{{\mathsf{discr}}}
\def\antidiscr{{\mathsf{ad}}}
\def\coint{{\mathsf{coint}}}
\def\bbC{\mathbb{C}}
\def\bbD{\mathbb{D}}
\def\bbE{\mathbb{E}}
\def\bbF{\mathbb{F}}
\def\bbW{\mathbb{W}}

The ``anti-discretization'' map, $a:\dagWdotP****** \to
\dagWdot******$, is continuous, and it induces a map
$\und:\Opens(\dagWdot******) \to \Opens(\dagWdotP******) =
\Pts(\dagWdotP******)$

% (find-LATEXfile "2010diags.tex" "diagram 3-pi")
% (find-dn4 "experimental.lua" "thereplusxy")

% $\W 123456$ foo $\WW 123456$

\def\G#1#2#3#4#5#6{\textstyle \dagGuill{#1}{#2}{#3}{#4}{#5}{#6}}
\def\G#1#2#3#4#5#6{a \hbox{a$a\dagGuill{#1}{#2}{#3}{#4}{#5}{#6}$}}
\def\G#1#2#3#4#5#6{\dagGuill{#1}{#2}{#3}{#4}{#5}{#6}}

\par Foo \bhbox{$\dagGuill 123456$} bar
\par Foo \bhbox{$\dagGuillPrime 123456789abc$} bar
\par $\dagGuill 123456$
     $\to$
\bhbox{$\hugeGuillPrime
  {\G 111111}  % 12
 {(\G 101111)} % 11
  {\G 011111}  % 10
  {\G 001111}  % 8
 {(\G 010111)} % 9
  {\G 001011}  % 7
 {(\G 000111)} % 5
 {(\G 001010)} % 6
  {\G 000011}  % 4
 {(\G 000010)} % 3
 {(\G 000001)} % 2
  {\G 000000}  % 1
$}
  $\to$
\bhbox{$\hugeGuillPrime
  {\dagGuill 110000}  % 12
  {\dagGuill 100000}  % 11
  {\dagGuill 011000}  % 10
  {\dagGuill 001100}  % 8
  {\dagGuill 010000}  % 9
  {\dagGuill 001001}  % 7
  {\dagGuill 000100}  % 5
  {\dagGuill 001000}  % 6
  {\dagGuill 000011}  % 4
  {\dagGuill 000010}  % 3
  {\dagGuill 000001}  % 2
  {\dagGuill 000000}  % 1
$}


a \bhbox{$\bigKite abcde$}

%*
% (eedn4a-bounded)
\input /tmp/mydags.tex

Foo \bhbox{$\dagRect 0123 4567 89AB CDEF$} bar

\par Foo \bhbox{$\thinLozenge 0 12 345 6789 abc de f$} bar
\par Foo \bhbox{$\wideLozenge 0 12 345 6789 abc de f$} bar
\par Foo \bhbox{$\smalLozenge 0 12 345 6789 abc de f$} bar
\par Foo \bhbox{$\smalLozenge · ·· *·· 6789 abc de f$} bar
\par Foo \bhbox{$\smalLozenge * ** *** **** *** ** *$} bar
\par Foo \bhbox{$\mediLozenge * ** *** **** *** ** *$} bar
\par Foo \bhbox{$\wideLozenge * ** *** **** *** ** *$} bar
\par Foo \bhbox{$\thinKite 12345$} bar
\par Foo \bhbox{$\mediKite 12345$} bar
\par Foo \bhbox{$\wideKite 12345$} bar

%*


defpictureFrom("thin",   Kite, Thin)
defpictureFrom("wide",   Kite, Wide)
defpictureFrom("medi",   Kite, Medium)

defpictureFrom("wide", Lozenge, Wide)
defpictureFrom("smal", Lozenge, {sx=6, sy=-6})
defpictureFrom("medi", Lozenge, {sx=8, sy=-8})
defpictureFrom("medi", Kite,    {sx=8, sy=-8})


defpictureFrom("dag", Rect)
defpictureFrom("thin", Lozenge)
defpictureFrom("wide", Lozenge, {sx=12, w0=-4})
defpictureFrom("smal", Lozenge, {sx=6, sy=-6})
defpictureFrom("medi", Lozenge, {sx=8, sy=-8})
-- defpictureFrom("medi", Kite,    {sx=8, sy=-8})
= defs()
writefile("/tmp/mydags.tex", defs())






~/LUA/canvas3.lua --defthinpicture dagLos '...1|..2.3|.4.5.6|7.8.9.A|.B.C.D|..E.F|...G' 3

defs_ = {}
defpictureFrom("thin", Kite)
defpictureFrom("wide", Kite, {sx=12})
= defs()

scale = ThinScaleFrom(Vee, 0)
PP(scale)
= scale:puts(Vee.coords, simplega)
= scale:picture(Vee.coords, simplega)
= scale:defpicture(Vee, "dagVee")




--]]






if arg and arg[1] == "--defthinpicture" then
  print(defthinpicture(arg[2], arg[3], tonumber(arg[4])))
end

--[[
* (eepitch-shell)
* (eepitch-kill)
* (eepitch-shell)
~/LUA/canvas3.lua --defthinpicture dagRect '1.2.3.4|5.6.7.8|9.A.B.C|D.E.F.G' 1
~/LUA/canvas3.lua --defthinpicture dagLos '...1|..2.3|.4.5.6|7.8.9.A|.B.C.D|..E.F|...G' 3





--]]









--[[


name = "foo"
body = "% body\n"

--]]







--[[
* (eepitch-lua51)
* (eepitch-kill)
* (eepitch-lua51)
ee_dofile "canvas3.lua"
PP(binstrings_)

PP(Kite)
--]]



--[[
-- (find-luamanualw3m "#5.4.1")

Próximas operações:
and, or, imp, not
uparrow

priming
tres representacoes para uma topologia de LT:
  só pelos tops,
  pelos tops e pelos bottoms,
  pelos losangos


%*
% (eedn4a-bounded)
% (find-sh0 "cd ~/LATEX/ && dvips  -D 600 -P pk -o tmp.ps tmp.dvi")
% (find-sh0 "cd ~/LATEX/ && dvired -D 600 -P pk -o tmp.ps tmp.dvi")
% (find-pspage "~/LATEX/tmp.ps")

\def\C{\mathbb{C}}
\def\D{\mathbb{D}}
\def\V{\mathbb{V}}

Let $\C=(C_0,R)$ and $\D=(D_0,S)$ be DAGs (not necessarily
$\Z^2$-DAGs). We will say that a map $f:C_0 \to D_0$ is a {\sl
faithful inclusion} of $\C$ into $\D$ when for all $\aa,\bbİC_0$ we
have $\aa R^* \bb$ iff $f(\aa) S^* f(\bb)$. Equivalently, $f$
preserves all the ``dependency relations'' between vertices of $\C$,
and the topology on $\C$ can be recovered from the topology on $\D$ by
applying $f^{-1}$. So, for example, the maps $g$ and $h$ pictured in
[fig maps] are faithful inclusions, but the map $s$ is not --- because
0011 is an open set but 0011 is not.

{\myttchars
\footnotesize
\begin{verbatim}
           1                        1
     g    2 34            2 3  h   2 34      1 2  s   1 2  
345  ->   5 6      and    5 6  ->  5 6       3 4  ->   3 4
           7                        7
\end{verbatim}
}

We will write $\C \sqsubseteq \D$ for ``there exists a faithful
inclusion $f:\C \to \D$'' (or: ``$\C$ is faithfully contained in
$\D$).

The following facts are easy to check, and will be stated without
proof.

Fact 1. Every faithful inclusion $f:\C \to \D$ induces a faithful
inclusion $f':\C' \to \D'$.

Fact 2. If $*** \sqsubseteq \D$ then $\D'$ cannot be a $\Z^2$-DAG --
because

{\myttchars
\footnotesize
\begin{verbatim}
  *
 /|\
* * *
|X X|  \sqsubseteq \D' .
* * *
 \|/
  *
\end{verbatim}
}

Fact 3. If Square $\sqsubseteq \D$ then

{\myttchars
\footnotesize
\begin{verbatim}
  *
 * *
* * * \subseteq \D',
 * *
  *
\end{verbatim}
}

and so $*** \sqsubseteq \D'$, and $\D''$ cannot be a $\Z^2$-DAG.

Let's call a DAG $\D$ {\sl thin} when $*** \not\sqsubseteq \D$ and
Square $\not\sqsubseteq \D$.

$\downarrow \swarrow \searrow$


%*
   23
 1 4
  5


We say that a map 

--]]


--[[
-- «lguill-diagram»  (to ".lguill-diagram")
Topology for Lguill (as Lguill_prime):
                         1 1
                        1 1  = R1vR2
                         1 1
                
                     1 0     0 1
              R1 = (1 1 )   1 1  = R2vR3
                     1 1     1 1
                
                         0 0     0 1
                R3vR4 = 1 1    (0 1 ) = R2
                         1 1     1 1
                
 1 2                 0 0     0 0
3 4   -->   R3vR6 = 1 0    (0 1 ) = R4
 5 6                 1 1     1 1
                
                 0 0     0 0
          R3 = (1 0 )   0 0  = R5vR6
                 1 0     1 1
                
                     0 0     0 0
              R5 = (0 0 )  (0 0 ) = R6
                     1 0     0 1
                
                         0 0
                        0 0  = _|_
                         0 0
--]]






-- arrowstostring = function (arrows)
--     return table.concat(map(table.concat, arrows), " ")
--   end
-- weightof = function (short)         -- count the "1"s
--     return #(string.gsub(short, "[^1]", ""))
--   end




















-- Local Variables:
-- coding:  raw-text-unix
-- modes:   (fundamental-mode lua-mode)
-- End: