// ternery search (for shita-ni-totsu)
{
	double x = ~min~;
	double w = ~max~;
	for(int i=0; i<~iteration~; ++i) // or, while( w-x > ~eps~ ) be careful for precision!
	{
		double y = 2*x/3 + w/3;
		double z = x/3 + 2*w/3;
		double fx = f(x);
		double fy = f(y);
		double fz = f(z);
		double fw = f(w);
		if( fx < fy )      w = y;
		else if( fz > fw ) x = z;
		else if( fy < fz ) w = z;
		else               x = y;
	}
}
