Un arbre de Bernoulli à 3 niveaux

bernoulli3.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 à trois niveaux
%------------------------------------------------------------------------

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

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

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

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]];


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 1
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 1
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]]);


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


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