Un arbre de Bernoulli à 4 niveaux

bernoulli4.jpg

Voici son code :

input geometriesyr16.mp ;

%%%%%%%%%%%%%%%%%%
%%
%%Ne pas oublier : export TEX=latex
%%
%%%%%%%%%%%%%%%%%

vardef TEX primary s =
  write "verbatimtex"   to "mptextmp.mp";
  write "%&latex" to  "mptextmp.mp";
  write "\documentclass{article}"  to "mptextmp.mp";
  write "\usepackage{aeguill}" to "mptextmp.mp";
  write "\usepackage[frenchb]{babel}" to "mptextmp.mp";
  write "\usepackage{amsmath}" to "mptextmp.mp";
  write "\usepackage{amsfonts}" to "mptextmp.mp";
  write "\begin{document}"  to "mptextmp.mp";
  write "etex"    to "mptextmp.mp";
  write "btex " & s & " etex" to "mptextmp.mp";
  write EOF to "mptextmp.mp";
  scantokens "input mptextmp"
enddef;

%------------------------------------------------------------------------
% Arbre de Bernoulli à quatre niveaux
%------------------------------------------------------------------------

u:=1cm;
figure (-8u,-17u,10u,8u);
pair S,T[],U[],V[],W[];

numeric dx,dh,cr;
dx:=3;
dh:=1;
cr:=0.1;

for i:=1 upto 16:
  W[i]:=(3*dx*u,-i*dh*u);
endfor

V[1]:= 0.5[W[1],W[2]] shifted(-dx*u,0);
V[2]:= 0.5[W[3],W[4]] shifted(-dx*u,0);
V[3]:= 0.5[W[5],W[6]] shifted(-dx*u,0);
V[4]:= 0.5[W[7],W[8]] shifted(-dx*u,0);
V[5]:= 0.5[W[9],W[10]] shifted(-dx*u,0);
V[6]:= 0.5[W[11],W[12]] shifted(-dx*u,0);
V[7]:= 0.5[W[13],W[14]] shifted(-dx*u,0);
V[8]:= 0.5[W[15],W[16]] shifted(-dx*u,0);


U[1]:= 0.5[V[1],V[2]] shifted(-dx*u,0);
U[2]:= 0.5[V[3],V[4]] shifted(-dx*u,0);
U[3]:= 0.5[V[5],V[6]] shifted(-dx*u,0);
U[4]:= 0.5[V[7],V[8]] shifted(-dx*u,0);

T[1]:= 0.5[U[1],U[2]] shifted(-dx*u,0);
T[2]:= 0.5[U[3],U[4]] shifted(-dx*u,0);

S:= 0.5[T[1],T[2]] shifted(-dx*u,0);

draw cr[S,T[1]]--(1-cr)[S,T[1]];
draw cr[S,T[2]]--(1-cr)[S,T[2]];
draw cr[T[1],U[1]]--(1-cr)[T[1],U[1]];
draw cr[T[1],U[2]]--(1-cr)[T[1],U[2]];
draw cr[T[2],U[3]]--(1-cr)[T[2],U[3]];
draw cr[T[2],U[4]]--(1-cr)[T[2],U[4]];
draw cr[U[1],V[1]]--(1-cr)[U[1],V[1]];
draw cr[U[1],V[2]]--(1-cr)[U[1],V[2]];
draw cr[U[2],V[3]]--(1-cr)[U[2],V[3]];
draw cr[U[2],V[4]]--(1-cr)[U[2],V[4]];
draw cr[U[3],V[5]]--(1-cr)[U[3],V[5]];
draw cr[U[3],V[6]]--(1-cr)[U[3],V[6]];
draw cr[U[4],V[7]]--(1-cr)[U[4],V[7]];
draw cr[U[4],V[8]]--(1-cr)[U[4],V[8]];
draw cr[V[1],W[1]]--(1-cr)[V[1],W[1]];
draw cr[V[1],W[2]]--(1-cr)[V[1],W[2]];
draw cr[V[2],W[3]]--(1-cr)[V[2],W[3]];
draw cr[V[2],W[4]]--(1-cr)[V[2],W[4]];
draw cr[V[3],W[5]]--(1-cr)[V[3],W[5]];
draw cr[V[3],W[6]]--(1-cr)[V[3],W[6]];
draw cr[V[4],W[7]]--(1-cr)[V[4],W[7]];
draw cr[V[4],W[8]]--(1-cr)[V[4],W[8]];
draw cr[V[5],W[9]]--(1-cr)[V[5],W[9]];
draw cr[V[5],W[10]]--(1-cr)[V[5],W[10]];
draw cr[V[6],W[11]]--(1-cr)[V[6],W[11]];
draw cr[V[6],W[12]]--(1-cr)[V[6],W[12]];
draw cr[V[7],W[13]]--(1-cr)[V[7],W[13]];
draw cr[V[7],W[14]]--(1-cr)[V[7],W[14]];
draw cr[V[8],W[15]]--(1-cr)[V[8],W[15]];
draw cr[V[8],W[16]]--(1-cr)[V[8],W[16]];


string a,na,pa,pna;
a:="$A$";
na:="$\overline{A}$";
pa:="$\frac{1}{3}$";
pna:="$\frac{2}{3}$";

%----------- premier niveau
label(TEX a,T[1]);
label.ulft(TEX pa,0.6[S,T[1]]);

label(TEX na,T[2]);
label.llft(TEX pna,0.6[S,T[2]]);

%----------- deuxième niveau supérieur
label(TEX a,U[1]);
label.ulft(TEX pa,0.6[T[1],U[1]]);

label(TEX na,U[2]);
label.llft(TEX pna,0.6[T[1],U[2]]);

%----------- deuxième niveau inférieur
label(TEX a,U[3]);
label.ulft(TEX pa,0.6[T[2],U[3]]);

label(TEX na,U[4]);
label.llft(TEX pna,0.6[T[2],U[4]]);

%----------- troisième niveau part 1
label(TEX a,V[1]);
label.ulft(TEX pa,0.6[U[1],V[1]]);

label(TEX na,V[2]);
label.llft(TEX pna,0.6[U[1],V[2]]);

%----------- troisième niveau part 2
label(TEX a,V[3]);
label.ulft(TEX pa,0.6[U[2],V[3]]);

label(TEX na,V[4]);
label.llft(TEX pna,0.6[U[2],V[4]]);

%----------- troisième niveau part 3
label(TEX a,V[5]);
label.ulft(TEX pa,0.6[U[3],V[5]]);

label(TEX na,V[6]);
label.llft(TEX pna,0.6[U[3],V[6]]);

%----------- troisième niveau part 4
label(TEX a,V[7]);
label.ulft(TEX pa,0.6[U[4],V[7]]);

label(TEX na,V[8]);
label.llft(TEX pna,0.6[U[4],V[8]]);

%----------- quatrième niveau part 1
label(TEX a,W[1]);
label.ulft(TEX pa,0.6[V[1],W[1]]);

label(TEX na,W[2]);
label.llft(TEX pna,0.6[V[1],W[2]]);

%----------- quatrième niveau part 2
label(TEX a,W[3]);
label.ulft(TEX pa,0.6[V[2],W[3]]);

label(TEX na,W[4]);
label.llft(TEX pna,0.6[V[2],W[4]]);

%----------- quatrième niveau part 3
label(TEX a,W[5]);
label.ulft(TEX pa,0.6[V[3],W[5]]);

label(TEX na,W[6]);
label.llft(TEX pna,0.6[V[3],W[6]]);

%----------- quatrième niveau part 4
label(TEX a,W[7]);
label.ulft(TEX pa,0.6[V[4],W[7]]);

label(TEX na,W[8]);
label.llft(TEX pna,0.6[V[4],W[8]]);

%----------- quatrième niveau part 5
label(TEX a,W[9]);
label.ulft(TEX pa,0.6[V[5],W[9]]);

label(TEX na,W[10]);
label.llft(TEX pna,0.6[V[5],W[10]]);

%----------- quatrième niveau part 6
label(TEX a,W[11]);
label.ulft(TEX pa,0.6[V[6],W[11]]);

label(TEX na,W[12]);
label.llft(TEX pna,0.6[V[6],W[12]]);

%----------- quatrième niveau part 7
label(TEX a,W[13]);
label.ulft(TEX pa,0.6[V[7],W[13]]);

label(TEX na,W[14]);
label.llft(TEX pna,0.6[V[7],W[14]]);

%----------- quatrième niveau part 8
label(TEX a,W[15]);
label.ulft(TEX pa,0.6[V[8],W[15]]);

label(TEX na,W[16]);
label.llft(TEX pna,0.6[V[8],W[16]]);

fin;
 %-----------------------------------------------------------------------


%-----------------------------------------------------------------------
end ;