function r = trap_adapt1 ( f, a, b, tol )

m = 0.5 * (a+b);
Tam = trap_single( f, a, m);
Tmb = trap_single( f, m, b);
Tab = trap_single( f, a, b);

E = abs(Tam+Tmb-Tab) / 3.0;

if E < tol 
    r = Tam+Tmb;
else
    r = trap_adapt1(f,a,m,tol/2)+trap_adapt1(f,m,b,tol/2);
end
