private static double goldenSelectionSearch ( double l , double r , double off , DoubleUnaryOperator f ) {
  final double g = ( 1 + Math . sqrt ( 5 ) ) / 2 ;
  double a = ( l * g + r ) / ( 1 + g ) , fa = f . applyAsDouble ( a ) ;
  double b = ( l + r * g ) / ( 1 + g ) , fb = f . applyAsDouble ( b ) ;
  while ( l + off < r ) {
    if ( fa <= fb ) {
      r = b ;
      b = a ;
      fb = fa ;
      a = ( l * g + r ) / ( 1 + g ) ;
      fa = f . applyAsDouble ( a ) ;
    }
    else {
      l = a ;
      a = b ;
      fa = fb ;
      b = ( l + r * g ) / ( 1 + g ) ;
      fb = f . applyAsDouble ( b ) ;
    }
  }
  return ( a + b ) / 2 ;
}

private static double goldenSelectionSearch ( double l , double r , double off , DoubleUnaryOperator f ) { final double g = ( 1 + Math . sqrt ( 5 ) ) / 2 ; double a = ( l * g + r ) / ( 1 + g ) , fa = f . applyAsDouble ( a ) ; double b = ( l + r * g ) / ( 1 + g ) , fb = f . applyAsDouble ( b ) ; while ( l + off < r ) { if ( fa <= fb ) { r = b ; b = a ; fb = fa ; a = ( l * g + r ) / ( 1 + g ) ; fa = f . applyAsDouble ( a ) ; } else { l = a ; a = b ; fa = fb ; b = ( l + r * g ) / ( 1 + g ) ; fb = f . applyAsDouble ( b ) ; } } return ( a + b ) / 2 ; }
(method_declaration (modifiers) type: (floating_point_type) name: (identifier) parameters: (formal_parameters (formal_parameter type: (floating_point_type) name: (identifier)) (formal_parameter type: (floating_point_type) name: (identifier)) (formal_parameter type: (floating_point_type) name: (identifier)) (formal_parameter type: (type_identifier) name: (identifier))) body: (block (local_variable_declaration (modifiers) type: (floating_point_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (parenthesized_expression (binary_expression left: (decimal_integer_literal) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (decimal_integer_literal))))) right: (decimal_integer_literal)))) (local_variable_declaration type: (floating_point_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (identifier))) right: (parenthesized_expression (binary_expression left: (decimal_integer_literal) right: (identifier))))) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) (local_variable_declaration type: (floating_point_type) declarator: (variable_declarator name: (identifier) value: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (identifier)))) right: (parenthesized_expression (binary_expression left: (decimal_integer_literal) right: (identifier))))) declarator: (variable_declarator name: (identifier) value: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))) (while_statement condition: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (identifier))) body: (block (if_statement condition: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) consequence: (block (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (parenthesized_expression (binary_expression left: (binary_expression left: (identifier) right: (identifier)) right: (identifier))) right: (parenthesized_expression (binary_expression left: (decimal_integer_literal) right: (identifier)))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier)))))) alternative: (block (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (identifier))) (expression_statement (assignment_expression left: (identifier) right: (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (binary_expression left: (identifier) right: (identifier)))) right: (parenthesized_expression (binary_expression left: (decimal_integer_literal) right: (identifier)))))) (expression_statement (assignment_expression left: (identifier) right: (method_invocation object: (identifier) name: (identifier) arguments: (argument_list (identifier))))))))) (return_statement (binary_expression left: (parenthesized_expression (binary_expression left: (identifier) right: (identifier))) right: (decimal_integer_literal)))))