Commit 3ca32732 authored by Martin Mareš's avatar Martin Mareš
Browse files

Merge branch 'fs-succinct'

parents 1743b5ed 7d2c9375
......@@ -17,7 +17,8 @@ CHAPTERS= \
06-hash \
07-geom \
08-string \
vk-dynamic
vk-dynamic \
fs-succinct
chapters:
for ch in $(CHAPTERS) ; do $(MAKE) -C $$ch pics ; done
......
TOP=..
PICS=sole sole_boxes sole_hilevel mixer composition mixer_chain mixer_tree tree_shapes
include ../Makerules
sole.pdf:: succinct_common.asy
sole_boxes.pdf:: succinct_common.asy
sole_hilevel.pdf:: succinct_common.asy
mixer_chain.pdf:: succinct_common.asy
mixer_tree.pdf:: succinct_common.asy
tree_shapes.pdf:: succinct_common.asy
//import ads;
//import flowchart;
//draw(roundrectangle("f", (0,0)));
//draw(roundrectangle("g", (1,-1)));
//draw(roundrectangle("h", (-1,-2)));
object f1 = draw("$g_1$", roundbox, (0,0), xmargin=0.5, ymargin=0.5);
object f2 = draw("$g_2$", roundbox, (1cm,-1cm), xmargin=0.5, ymargin=0.5);
object f3 = draw("$g_3$", roundbox, (-1cm,-1.5cm), xmargin=0.5, ymargin=0.5);
// XXX this does not work when setting unitsize
draw(point(f1, SE) -- point(f2, NW), Arrow);
draw(point(f1, SW) -- point(f3, NE), Arrow);
draw(point(f2, W) -- point(f3, E), Arrow);
draw(roundbox(bbox(), xmargin=0.35cm));
draw(point(f2, S) -- (xpart(point(f2, S)), -2.5cm), Arrow);
draw(point(f3, S) -- (xpart(point(f3, S)), -2.5cm), Arrow);
draw((xpart(point(f1, N)), 1cm) -- point(f1, N), Arrow);
label("$g$", (xpart(min(currentpicture)), ypart(max(currentpicture))) + (0.25cm, -0.25cm));
import succinct_common;
real r = 1.5;
real dist=2;
mixer(0,0,r);
draw((-dist,0)--(-r,0), e_arrow);
draw((r,0)--(dist,0), e_arrow);
draw((0,-r)--(0,-dist), e_arrow);
draw((0,dist)--(0,r), e_arrow);
label((0, dist), "\vbox{\hbox{$x\in[X]$}\hbox{\eightrm (input)}}", N);
label((-dist, 0), "\vbox{\hbox{$y\in[Y]$}\hbox{\eightrm (carry in)}}", W);
label((dist, 0), "\vbox{\hbox{$s\in[S]$}\hbox{\eightrm (carry out)}}", E);
label((0, -dist), "\vbox{\hbox{$m\in[2^M]$}\hbox{\eightrm (output)}}", S);
label((0, 0), "$c\in [C]$");
import succinct_common;
real mixgrid = 2.5;
int nmixers = 5;
for (int i = 0; i < nmixers; ++i) {
real x = mixgrid * i;
if (i == 3) {
label((x,0), "$\cdots$");
} else {
draw((x, 1.25) -- (x, 0.5), e_arrow);
label((x, 1.25), "$X$", N);
mixer(x, 0);
draw((x, -0.5) -- (x, -1.25), e_arrow);
label((x, -1.25), (i == 4) ? "$2^{M_n}$" : "$2^{M_"+((string)(i+1))+"}$", S);
}
}
string[] alphas = {"", "Y_1", "Y_2", "Y_3", "Y_{N-1}", "Y_N"};
for (int i = 1; i < nmixers; ++i) {
carry_arrow((mixgrid * (i-1), 0), (mixgrid*i, 0), alphas[i]);
}
pair endb = (mixgrid * (nmixers-1), 0) + (0.5,0);
draw(endb -- endb + (0.5,0) {E} .. {S} endb + (1.5,-1) -- endb + (1.5,-1.25), e_arrow);
label(endb + (1.5,-1.25), "$2^{M_{n+1}}$", S);
import succinct_common;
pair C = (0,0);
PENTAMIXER_R = 0.75;
pentamixer(C);
pm_arrow(C, A_IN, 1, lbl="\vbox{\hbox{$x\in[X]$}\hbox{\eightrm (input)}}");
pm_arrow(C, A_CIN1, 1, lbl="\vbox{\hbox{$y\in[Y]$}\hbox{\eightrm (carry in 1)}}");
pm_arrow(C, A_CIN2, 1, lbl="\vbox{\hbox{$z\in[Z]$}\hbox{\eightrm (carry in 2)}}");
pm_arrow(C, A_OUT, 1, out=true, lbl="\vbox{\hbox{$m\in[2^M]$}\hbox{\eightrm (output)}}");
pm_arrow(C, A_COUT, 1, out=true, lbl="\vbox{\hbox{$s\in[S]$}\hbox{\eightrm (carry out)}}");
PENTAMIXER_R = 0.5;
pair m1 = (5, -1);
pair m2 = (9, -1);
pair m3 = (7, 1.5);
pair mix[] = {m1, m2, m3};
pentamixer(m1);
pentamixer(m2);
pentamixer(m3);
draw(pm_dir(m1, A_COUT)--pm_dir(m3, A_CIN1), e_arrow);
draw(pm_dir(m2, A_COUT)--pm_dir(m3, A_CIN2), e_arrow);
for (int i = 0; i < 3; ++i) {
pm_arrow(mix[i], A_IN, 0.5, lbl="in");
pm_arrow(mix[i], A_OUT, 0.5, out=true, lbl="out");
}
for (int i = 0; i < 2; ++i) {
pm_arrow(mix[i], A_CIN1, 0.5, "$\vdots$");
pm_arrow(mix[i], A_CIN2, 0.5, "$\vdots$");
}
pm_arrow(m3, A_COUT, 0.5, out=true, "$\vdots$");
import succinct_common;
blocks(0 ... concat(array(6,"B"), new string[] {"...", "B", "EOF"}));
thruarrows(0,0,6);
thruarrows(0,7,2);
blocks(1 ... concat(array(6, "B+1"), array(1, "..."), array(2, "B+1")) );
mixarrows(1,0,6);
mixarrow(1, 7);
block(1, 9, "0");
blocks(2, "B", "B+3", "B-3", "B+6", "B-6", "B+9", "...", "B-i","B+j", "B-j");
thruarrow(2, 0);
mixarrows(2, 1, 6);
mixarrow(2, 8);
thruarrow(1, 9);
blocks(3 ... concat(array(6,"B"), array(1, "..."), array(3, "B")));
passlabel(0, "Add EOF");
passlabel(1, "Pass 1");
passlabel(2, "Pass 2");
import succinct_common;
void fillbox(int col, pen pen) {
path p = (
(col*blockwidth, -rowheight-blockheight)
-- ((col+2)*blockwidth, -rowheight-blockheight)
-- ((col+2)*blockwidth, -2*rowheight)
-- ((col+1)*blockwidth, -2*rowheight)
-- ((col+1)*blockwidth, -3*rowheight)
-- ((col-1)*blockwidth, -3*rowheight)
-- ((col-1)*blockwidth, -2*rowheight-blockheight)
-- ((col)*blockwidth, -2*rowheight-blockheight)
-- cycle
);
fill(p, pen);
draw(p, thick);
}
fillbox(2, 0.5*white);
fillbox(4, 0.75*white);
fillbox(6, 0.5*white);
//blocks(0 ... concat(array(8,"B"), new string[] {"..."}));
//thruarrows(0,0,6);
blocks(1 ... concat(array(8, "B+1"), array(1, "...")) );
mixarrows(1,0,8);
blocks(2, "B", "B+3", "B-3", "B+6", "B-6", "B+9", "B-9", "...");
thruarrow(2, 0);
mixarrows(2, 1, 6);
blocks(3 ... concat(array(7,"B"), array(1, "...")));
import succinct_common;
real mixgrid = 2.5;
int nmixers = 3;
for (int i = 0; i < nmixers; ++i) {
real x = mixgrid * i;
draw((x, 1.25) -- (x, 0.5), e_arrow);
label((x, 1.25), "$(B+1)^2$", N);
mixer(x, 0);
draw((x, -0.5) -- (x, -1.25), e_arrow);
label((x, -1.25), "$B^2$", S);
}
string[] alphas = {"B+3", "B+6", "B+9", "B+12"};
for (int i = 0; i < nmixers+1; ++i) {
carry_arrow((mixgrid * (i-1), 0), (mixgrid*i, 0), alphas[i]);
}
This diff is collapsed.
import ads;
real blockwidth = 1;
real blockheight = 0.5;
real arrowheight = 1;
real rowheight = blockheight + arrowheight;
void mixarrow(int row, int col) {
real x = col * blockwidth;
real y = -row * rowheight - blockheight;
path arr1 = (x + blockwidth/2, y) {S} .. {S} (x + blockwidth, y - arrowheight / 2) {S} .. {S} (x + 1.5*blockwidth, y - arrowheight);
path arr2 = reflect((x + blockwidth, 0), (x+blockwidth, 1)) * arr1;
draw(arr1, Arrow);
draw(arr2, Arrow);
}
void thruarrow(int row, int col) {
real x = col * blockwidth;
real y = -row * rowheight - blockheight;
draw((x+blockwidth/2, y)--(x+blockwidth/2, y-arrowheight), Arrow);
}
void block(int row, int col, string alphabet) {
real xbase = col * blockwidth;
real ybase = -row * rowheight;
if (alphabet == "...") {
label("$\cdots$", (xbase+blockwidth/2, ybase-blockheight/2), (0,0));
} else {
if (alphabet != "EOF" && alphabet != "0")
draw((xbase,ybase)--(xbase+blockwidth, ybase)--(xbase+blockwidth, ybase-blockheight)--(xbase, ybase-blockheight)--cycle);
label("$"+alphabet+"$", (xbase+blockwidth/2, ybase-blockheight/2), (0,0));
}
}
void blocks(int row ... string alphabets[]) {
for (int i = 0; i < alphabets.length; ++i) {
block(row, i, alphabets[i]);
}
}
void thruarrows(int row, int col, int cnt) {
for (int i = 0; i < cnt; ++i)
thruarrow(row, col+i);
}
void mixarrows(int row, int col, int cnt) {
for (int i = 0; i < cnt; i += 2)
mixarrow(row, col+i);
}
void passlabel(int row, string lbl) {
label("{\it " + lbl + "}", (-1, -row*rowheight-blockheight - arrowheight/2), W);
}
void mixer(real x, real y, real r=0.5) {
draw((x-r,y-r) -- (x+r,y-r)--(x+r, y+r) -- (x-r, y+r) -- cycle, halfthick);
draw( (x,y+r) {S} .. {E} (x+r,y), 0.5*white);
draw( (x,y+r) -- (x,y-r), 0.5*white);
draw( (x-r,y) {E} .. {S} (x,y-r), 0.5*white);
}
real PENTAMIXER_R = 1;
pair pm_dir(pair c, int angle, real r=PENTAMIXER_R) {
return shift(c)*scale(r)*dir(angle);
}
int A_IN = 180, A_OUT=0, A_COUT=90, A_CIN1=240, A_CIN2=300;
void pentamixer(pair c, real r=PENTAMIXER_R) {
path unitcircle=E..N..W..S..cycle;
pair d(int angle) {
return pm_dir(c, angle, r);
}
draw(shift(c)*scale(r)*unitcircle);
draw( d(A_IN)--d(A_OUT), 0.5*white);
draw( d(A_IN){E}..{N}d(A_COUT), 0.5*white);
draw( d(A_CIN1){dir(60)}..{E}d(A_OUT), 0.5*white);
draw( d(A_CIN2){dir(120)}..{E}d(A_OUT), 0.5*white);
}
void pm_arrow(pair c, int angle, real length, bool out=false, real r=PENTAMIXER_R, string lbl="") {
pair p1 = pm_dir(c, angle, r);
pair p2 = pm_dir(c, angle, r+length);
if (out)
draw(p1--p2, e_arrow);
else
draw(p2--p1, e_arrow);
if (lbl != "")
label(lbl, p2, dir(angle));
}
void carry_arrow(pair mix1, pair mix2, string alphabet) {
draw(mix1 + (0.5,0) -- mix2 - (0.5, 0), e_arrow);
label((mix1+mix2)/2, "$"+alphabet+"$", N);
}
import succinct_common;
draw((-3,-2) -- (3,-2), 0.3*white);
draw((-3.2,-4)--(-3.2,-2), Arrows);
label((-3.2, -3), "$h$", W);
draw((3.2,-3.5)--(3.2,-2), Arrows);
label((3.2, -2.75), "$h-1$", E);
void subtree(path p) {
filldraw(p, 0.65*white);
}
subtree((-1.75, -4)--(-0.75,-4)--(-1.25,-2)--cycle);
subtree((-0.5, -4)--(0,-4)--(0,-3.5)--(0.5,-3.5)--(0,-2)--cycle);
subtree((1.75, -3.5)--(0.75,-3.5)--(1.25,-2)--cycle);
label((-1.25, -3), "A");
label((-0, -3), "B");
label((1.25, -3), "C");
draw((-3, -4) -- (0,-4) -- (0,-3.5) -- (3,-3.5) -- (0, 0) -- cycle, halfthick);
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment