Numeric.Log:$clog1p from log-domain-0.10.2.1, B

Percentage Accurate: 99.7% → 99.7%
Time: 2.5s
Alternatives: 8
Speedup: 0.4×

Specification

?
\[\frac{x}{1 + \sqrt{x + 1}} \]
(FPCore (x)
  :precision binary64
  :pre TRUE
  (/ x (+ 1.0 (sqrt (+ x 1.0)))))
double code(double x) {
	return x / (1.0 + sqrt((x + 1.0)));
}
real(8) function code(x)
use fmin_fmax_functions
    real(8), intent (in) :: x
    code = x / (1.0d0 + sqrt((x + 1.0d0)))
end function
public static double code(double x) {
	return x / (1.0 + Math.sqrt((x + 1.0)));
}
def code(x):
	return x / (1.0 + math.sqrt((x + 1.0)))
function code(x)
	return Float64(x / Float64(1.0 + sqrt(Float64(x + 1.0))))
end
function tmp = code(x)
	tmp = x / (1.0 + sqrt((x + 1.0)));
end
code[x_] := N[(x / N[(1.0 + N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
f(x):
	x in [-inf, +inf]
code: THEORY
BEGIN
f(x: real): real =
	x / ((1) + (sqrt((x + (1)))))
END code
\frac{x}{1 + \sqrt{x + 1}}

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 8 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 99.7% accurate, 1.0× speedup?

\[\frac{x}{1 + \sqrt{x + 1}} \]
(FPCore (x)
  :precision binary64
  :pre TRUE
  (/ x (+ 1.0 (sqrt (+ x 1.0)))))
double code(double x) {
	return x / (1.0 + sqrt((x + 1.0)));
}
real(8) function code(x)
use fmin_fmax_functions
    real(8), intent (in) :: x
    code = x / (1.0d0 + sqrt((x + 1.0d0)))
end function
public static double code(double x) {
	return x / (1.0 + Math.sqrt((x + 1.0)));
}
def code(x):
	return x / (1.0 + math.sqrt((x + 1.0)))
function code(x)
	return Float64(x / Float64(1.0 + sqrt(Float64(x + 1.0))))
end
function tmp = code(x)
	tmp = x / (1.0 + sqrt((x + 1.0)));
end
code[x_] := N[(x / N[(1.0 + N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
f(x):
	x in [-inf, +inf]
code: THEORY
BEGIN
f(x: real): real =
	x / ((1) + (sqrt((x + (1)))))
END code
\frac{x}{1 + \sqrt{x + 1}}

Alternative 1: 99.7% accurate, 0.4× speedup?

\[\begin{array}{l} \mathbf{if}\;\frac{x}{1 + \sqrt{x + 1}} \leq 5 \cdot 10^{-6}:\\ \;\;\;\;\mathsf{fma}\left(-0.125, x \cdot x, 0.5 \cdot x\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{1 + x} + -1\\ \end{array} \]
(FPCore (x)
  :precision binary64
  :pre TRUE
  (if (<= (/ x (+ 1.0 (sqrt (+ x 1.0)))) 5e-6)
  (fma -0.125 (* x x) (* 0.5 x))
  (+ (sqrt (+ 1.0 x)) -1.0)))
double code(double x) {
	double tmp;
	if ((x / (1.0 + sqrt((x + 1.0)))) <= 5e-6) {
		tmp = fma(-0.125, (x * x), (0.5 * x));
	} else {
		tmp = sqrt((1.0 + x)) + -1.0;
	}
	return tmp;
}
function code(x)
	tmp = 0.0
	if (Float64(x / Float64(1.0 + sqrt(Float64(x + 1.0)))) <= 5e-6)
		tmp = fma(-0.125, Float64(x * x), Float64(0.5 * x));
	else
		tmp = Float64(sqrt(Float64(1.0 + x)) + -1.0);
	end
	return tmp
end
code[x_] := If[LessEqual[N[(x / N[(1.0 + N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e-6], N[(-0.125 * N[(x * x), $MachinePrecision] + N[(0.5 * x), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] + -1.0), $MachinePrecision]]
f(x):
	x in [-inf, +inf]
code: THEORY
BEGIN
f(x: real): real =
	LET tmp = IF ((x / ((1) + (sqrt((x + (1)))))) <= (50000000000000004090152695701565477293115691281855106353759765625e-70)) THEN (((-125e-3) * (x * x)) + ((5e-1) * x)) ELSE ((sqrt(((1) + x))) + (-1)) ENDIF IN
	tmp
END code
\begin{array}{l}
\mathbf{if}\;\frac{x}{1 + \sqrt{x + 1}} \leq 5 \cdot 10^{-6}:\\
\;\;\;\;\mathsf{fma}\left(-0.125, x \cdot x, 0.5 \cdot x\right)\\

\mathbf{else}:\\
\;\;\;\;\sqrt{1 + x} + -1\\


\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) < 5.0000000000000004e-6

    1. Initial program 99.7%

      \[\frac{x}{1 + \sqrt{x + 1}} \]
    2. Taylor expanded in x around 0

      \[\leadsto x \cdot \left(\frac{1}{2} + \frac{-1}{8} \cdot x\right) \]
    3. Step-by-step derivation
      1. Applied rewrites65.8%

        \[\leadsto x \cdot \left(0.5 + -0.125 \cdot x\right) \]
      2. Step-by-step derivation
        1. Applied rewrites65.8%

          \[\leadsto \mathsf{fma}\left(-0.125, x \cdot x, 0.5 \cdot x\right) \]

        if 5.0000000000000004e-6 < (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64)))))

        1. Initial program 99.7%

          \[\frac{x}{1 + \sqrt{x + 1}} \]
        2. Step-by-step derivation
          1. Applied rewrites99.7%

            \[\leadsto x \cdot \frac{1}{\sqrt{1 + x} + 1} \]
          2. Step-by-step derivation
            1. Applied rewrites39.3%

              \[\leadsto \sqrt{1 + x} + -1 \]
          3. Recombined 2 regimes into one program.
          4. Add Preprocessing

          Alternative 2: 99.6% accurate, 0.5× speedup?

          \[\begin{array}{l} \mathbf{if}\;\frac{x}{1 + \sqrt{x + 1}} \leq 5 \cdot 10^{-6}:\\ \;\;\;\;\frac{x}{\mathsf{fma}\left(0.5, x, 2\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{1 + x} + -1\\ \end{array} \]
          (FPCore (x)
            :precision binary64
            :pre TRUE
            (if (<= (/ x (+ 1.0 (sqrt (+ x 1.0)))) 5e-6)
            (/ x (fma 0.5 x 2.0))
            (+ (sqrt (+ 1.0 x)) -1.0)))
          double code(double x) {
          	double tmp;
          	if ((x / (1.0 + sqrt((x + 1.0)))) <= 5e-6) {
          		tmp = x / fma(0.5, x, 2.0);
          	} else {
          		tmp = sqrt((1.0 + x)) + -1.0;
          	}
          	return tmp;
          }
          
          function code(x)
          	tmp = 0.0
          	if (Float64(x / Float64(1.0 + sqrt(Float64(x + 1.0)))) <= 5e-6)
          		tmp = Float64(x / fma(0.5, x, 2.0));
          	else
          		tmp = Float64(sqrt(Float64(1.0 + x)) + -1.0);
          	end
          	return tmp
          end
          
          code[x_] := If[LessEqual[N[(x / N[(1.0 + N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e-6], N[(x / N[(0.5 * x + 2.0), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] + -1.0), $MachinePrecision]]
          
          f(x):
          	x in [-inf, +inf]
          code: THEORY
          BEGIN
          f(x: real): real =
          	LET tmp = IF ((x / ((1) + (sqrt((x + (1)))))) <= (50000000000000004090152695701565477293115691281855106353759765625e-70)) THEN (x / (((5e-1) * x) + (2))) ELSE ((sqrt(((1) + x))) + (-1)) ENDIF IN
          	tmp
          END code
          \begin{array}{l}
          \mathbf{if}\;\frac{x}{1 + \sqrt{x + 1}} \leq 5 \cdot 10^{-6}:\\
          \;\;\;\;\frac{x}{\mathsf{fma}\left(0.5, x, 2\right)}\\
          
          \mathbf{else}:\\
          \;\;\;\;\sqrt{1 + x} + -1\\
          
          
          \end{array}
          
          Derivation
          1. Split input into 2 regimes
          2. if (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) < 5.0000000000000004e-6

            1. Initial program 99.7%

              \[\frac{x}{1 + \sqrt{x + 1}} \]
            2. Taylor expanded in x around 0

              \[\leadsto \frac{x}{2 + \frac{1}{2} \cdot x} \]
            3. Step-by-step derivation
              1. Applied rewrites67.9%

                \[\leadsto \frac{x}{2 + 0.5 \cdot x} \]
              2. Step-by-step derivation
                1. Applied rewrites67.9%

                  \[\leadsto \frac{x}{\mathsf{fma}\left(0.5, x, 2\right)} \]

                if 5.0000000000000004e-6 < (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64)))))

                1. Initial program 99.7%

                  \[\frac{x}{1 + \sqrt{x + 1}} \]
                2. Step-by-step derivation
                  1. Applied rewrites99.7%

                    \[\leadsto x \cdot \frac{1}{\sqrt{1 + x} + 1} \]
                  2. Step-by-step derivation
                    1. Applied rewrites39.3%

                      \[\leadsto \sqrt{1 + x} + -1 \]
                  3. Recombined 2 regimes into one program.
                  4. Add Preprocessing

                  Alternative 3: 99.5% accurate, 0.5× speedup?

                  \[\begin{array}{l} \mathbf{if}\;\frac{x}{1 + \sqrt{x + 1}} \leq 5 \cdot 10^{-6}:\\ \;\;\;\;x \cdot \mathsf{fma}\left(-0.125, x, 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{1 + x} + -1\\ \end{array} \]
                  (FPCore (x)
                    :precision binary64
                    :pre TRUE
                    (if (<= (/ x (+ 1.0 (sqrt (+ x 1.0)))) 5e-6)
                    (* x (fma -0.125 x 0.5))
                    (+ (sqrt (+ 1.0 x)) -1.0)))
                  double code(double x) {
                  	double tmp;
                  	if ((x / (1.0 + sqrt((x + 1.0)))) <= 5e-6) {
                  		tmp = x * fma(-0.125, x, 0.5);
                  	} else {
                  		tmp = sqrt((1.0 + x)) + -1.0;
                  	}
                  	return tmp;
                  }
                  
                  function code(x)
                  	tmp = 0.0
                  	if (Float64(x / Float64(1.0 + sqrt(Float64(x + 1.0)))) <= 5e-6)
                  		tmp = Float64(x * fma(-0.125, x, 0.5));
                  	else
                  		tmp = Float64(sqrt(Float64(1.0 + x)) + -1.0);
                  	end
                  	return tmp
                  end
                  
                  code[x_] := If[LessEqual[N[(x / N[(1.0 + N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e-6], N[(x * N[(-0.125 * x + 0.5), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] + -1.0), $MachinePrecision]]
                  
                  f(x):
                  	x in [-inf, +inf]
                  code: THEORY
                  BEGIN
                  f(x: real): real =
                  	LET tmp = IF ((x / ((1) + (sqrt((x + (1)))))) <= (50000000000000004090152695701565477293115691281855106353759765625e-70)) THEN (x * (((-125e-3) * x) + (5e-1))) ELSE ((sqrt(((1) + x))) + (-1)) ENDIF IN
                  	tmp
                  END code
                  \begin{array}{l}
                  \mathbf{if}\;\frac{x}{1 + \sqrt{x + 1}} \leq 5 \cdot 10^{-6}:\\
                  \;\;\;\;x \cdot \mathsf{fma}\left(-0.125, x, 0.5\right)\\
                  
                  \mathbf{else}:\\
                  \;\;\;\;\sqrt{1 + x} + -1\\
                  
                  
                  \end{array}
                  
                  Derivation
                  1. Split input into 2 regimes
                  2. if (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) < 5.0000000000000004e-6

                    1. Initial program 99.7%

                      \[\frac{x}{1 + \sqrt{x + 1}} \]
                    2. Taylor expanded in x around 0

                      \[\leadsto x \cdot \left(\frac{1}{2} + \frac{-1}{8} \cdot x\right) \]
                    3. Step-by-step derivation
                      1. Applied rewrites65.8%

                        \[\leadsto x \cdot \left(0.5 + -0.125 \cdot x\right) \]
                      2. Step-by-step derivation
                        1. Applied rewrites65.8%

                          \[\leadsto x \cdot \mathsf{fma}\left(-0.125, x, 0.5\right) \]

                        if 5.0000000000000004e-6 < (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64)))))

                        1. Initial program 99.7%

                          \[\frac{x}{1 + \sqrt{x + 1}} \]
                        2. Step-by-step derivation
                          1. Applied rewrites99.7%

                            \[\leadsto x \cdot \frac{1}{\sqrt{1 + x} + 1} \]
                          2. Step-by-step derivation
                            1. Applied rewrites39.3%

                              \[\leadsto \sqrt{1 + x} + -1 \]
                          3. Recombined 2 regimes into one program.
                          4. Add Preprocessing

                          Alternative 4: 99.0% accurate, 0.5× speedup?

                          \[\begin{array}{l} \mathbf{if}\;\frac{x}{1 + \sqrt{x + 1}} \leq 10^{-12}:\\ \;\;\;\;0.5 \cdot x\\ \mathbf{else}:\\ \;\;\;\;\sqrt{1 + x} + -1\\ \end{array} \]
                          (FPCore (x)
                            :precision binary64
                            :pre TRUE
                            (if (<= (/ x (+ 1.0 (sqrt (+ x 1.0)))) 1e-12)
                            (* 0.5 x)
                            (+ (sqrt (+ 1.0 x)) -1.0)))
                          double code(double x) {
                          	double tmp;
                          	if ((x / (1.0 + sqrt((x + 1.0)))) <= 1e-12) {
                          		tmp = 0.5 * x;
                          	} else {
                          		tmp = sqrt((1.0 + x)) + -1.0;
                          	}
                          	return tmp;
                          }
                          
                          real(8) function code(x)
                          use fmin_fmax_functions
                              real(8), intent (in) :: x
                              real(8) :: tmp
                              if ((x / (1.0d0 + sqrt((x + 1.0d0)))) <= 1d-12) then
                                  tmp = 0.5d0 * x
                              else
                                  tmp = sqrt((1.0d0 + x)) + (-1.0d0)
                              end if
                              code = tmp
                          end function
                          
                          public static double code(double x) {
                          	double tmp;
                          	if ((x / (1.0 + Math.sqrt((x + 1.0)))) <= 1e-12) {
                          		tmp = 0.5 * x;
                          	} else {
                          		tmp = Math.sqrt((1.0 + x)) + -1.0;
                          	}
                          	return tmp;
                          }
                          
                          def code(x):
                          	tmp = 0
                          	if (x / (1.0 + math.sqrt((x + 1.0)))) <= 1e-12:
                          		tmp = 0.5 * x
                          	else:
                          		tmp = math.sqrt((1.0 + x)) + -1.0
                          	return tmp
                          
                          function code(x)
                          	tmp = 0.0
                          	if (Float64(x / Float64(1.0 + sqrt(Float64(x + 1.0)))) <= 1e-12)
                          		tmp = Float64(0.5 * x);
                          	else
                          		tmp = Float64(sqrt(Float64(1.0 + x)) + -1.0);
                          	end
                          	return tmp
                          end
                          
                          function tmp_2 = code(x)
                          	tmp = 0.0;
                          	if ((x / (1.0 + sqrt((x + 1.0)))) <= 1e-12)
                          		tmp = 0.5 * x;
                          	else
                          		tmp = sqrt((1.0 + x)) + -1.0;
                          	end
                          	tmp_2 = tmp;
                          end
                          
                          code[x_] := If[LessEqual[N[(x / N[(1.0 + N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 1e-12], N[(0.5 * x), $MachinePrecision], N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] + -1.0), $MachinePrecision]]
                          
                          f(x):
                          	x in [-inf, +inf]
                          code: THEORY
                          BEGIN
                          f(x: real): real =
                          	LET tmp = IF ((x / ((1) + (sqrt((x + (1)))))) <= (99999999999999997988664762925561536725284350612952266601496376097202301025390625e-92)) THEN ((5e-1) * x) ELSE ((sqrt(((1) + x))) + (-1)) ENDIF IN
                          	tmp
                          END code
                          \begin{array}{l}
                          \mathbf{if}\;\frac{x}{1 + \sqrt{x + 1}} \leq 10^{-12}:\\
                          \;\;\;\;0.5 \cdot x\\
                          
                          \mathbf{else}:\\
                          \;\;\;\;\sqrt{1 + x} + -1\\
                          
                          
                          \end{array}
                          
                          Derivation
                          1. Split input into 2 regimes
                          2. if (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) < 9.9999999999999998e-13

                            1. Initial program 99.7%

                              \[\frac{x}{1 + \sqrt{x + 1}} \]
                            2. Taylor expanded in x around 0

                              \[\leadsto \frac{1}{2} \cdot x \]
                            3. Step-by-step derivation
                              1. Applied rewrites67.3%

                                \[\leadsto 0.5 \cdot x \]

                              if 9.9999999999999998e-13 < (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64)))))

                              1. Initial program 99.7%

                                \[\frac{x}{1 + \sqrt{x + 1}} \]
                              2. Step-by-step derivation
                                1. Applied rewrites99.7%

                                  \[\leadsto x \cdot \frac{1}{\sqrt{1 + x} + 1} \]
                                2. Step-by-step derivation
                                  1. Applied rewrites39.3%

                                    \[\leadsto \sqrt{1 + x} + -1 \]
                                3. Recombined 2 regimes into one program.
                                4. Add Preprocessing

                                Alternative 5: 97.3% accurate, 0.6× speedup?

                                \[\begin{array}{l} \mathbf{if}\;\frac{x}{1 + \sqrt{x + 1}} \leq 0.05:\\ \;\;\;\;0.5 \cdot x\\ \mathbf{else}:\\ \;\;\;\;\sqrt{x}\\ \end{array} \]
                                (FPCore (x)
                                  :precision binary64
                                  :pre TRUE
                                  (if (<= (/ x (+ 1.0 (sqrt (+ x 1.0)))) 0.05) (* 0.5 x) (sqrt x)))
                                double code(double x) {
                                	double tmp;
                                	if ((x / (1.0 + sqrt((x + 1.0)))) <= 0.05) {
                                		tmp = 0.5 * x;
                                	} else {
                                		tmp = sqrt(x);
                                	}
                                	return tmp;
                                }
                                
                                real(8) function code(x)
                                use fmin_fmax_functions
                                    real(8), intent (in) :: x
                                    real(8) :: tmp
                                    if ((x / (1.0d0 + sqrt((x + 1.0d0)))) <= 0.05d0) then
                                        tmp = 0.5d0 * x
                                    else
                                        tmp = sqrt(x)
                                    end if
                                    code = tmp
                                end function
                                
                                public static double code(double x) {
                                	double tmp;
                                	if ((x / (1.0 + Math.sqrt((x + 1.0)))) <= 0.05) {
                                		tmp = 0.5 * x;
                                	} else {
                                		tmp = Math.sqrt(x);
                                	}
                                	return tmp;
                                }
                                
                                def code(x):
                                	tmp = 0
                                	if (x / (1.0 + math.sqrt((x + 1.0)))) <= 0.05:
                                		tmp = 0.5 * x
                                	else:
                                		tmp = math.sqrt(x)
                                	return tmp
                                
                                function code(x)
                                	tmp = 0.0
                                	if (Float64(x / Float64(1.0 + sqrt(Float64(x + 1.0)))) <= 0.05)
                                		tmp = Float64(0.5 * x);
                                	else
                                		tmp = sqrt(x);
                                	end
                                	return tmp
                                end
                                
                                function tmp_2 = code(x)
                                	tmp = 0.0;
                                	if ((x / (1.0 + sqrt((x + 1.0)))) <= 0.05)
                                		tmp = 0.5 * x;
                                	else
                                		tmp = sqrt(x);
                                	end
                                	tmp_2 = tmp;
                                end
                                
                                code[x_] := If[LessEqual[N[(x / N[(1.0 + N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.05], N[(0.5 * x), $MachinePrecision], N[Sqrt[x], $MachinePrecision]]
                                
                                f(x):
                                	x in [-inf, +inf]
                                code: THEORY
                                BEGIN
                                f(x: real): real =
                                	LET tmp = IF ((x / ((1) + (sqrt((x + (1)))))) <= (5000000000000000277555756156289135105907917022705078125e-56)) THEN ((5e-1) * x) ELSE (sqrt(x)) ENDIF IN
                                	tmp
                                END code
                                \begin{array}{l}
                                \mathbf{if}\;\frac{x}{1 + \sqrt{x + 1}} \leq 0.05:\\
                                \;\;\;\;0.5 \cdot x\\
                                
                                \mathbf{else}:\\
                                \;\;\;\;\sqrt{x}\\
                                
                                
                                \end{array}
                                
                                Derivation
                                1. Split input into 2 regimes
                                2. if (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) < 0.050000000000000003

                                  1. Initial program 99.7%

                                    \[\frac{x}{1 + \sqrt{x + 1}} \]
                                  2. Taylor expanded in x around 0

                                    \[\leadsto \frac{1}{2} \cdot x \]
                                  3. Step-by-step derivation
                                    1. Applied rewrites67.3%

                                      \[\leadsto 0.5 \cdot x \]

                                    if 0.050000000000000003 < (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64)))))

                                    1. Initial program 99.7%

                                      \[\frac{x}{1 + \sqrt{x + 1}} \]
                                    2. Taylor expanded in x around inf

                                      \[\leadsto \frac{1}{\sqrt{\frac{1}{x}}} \]
                                    3. Step-by-step derivation
                                      1. Applied rewrites34.5%

                                        \[\leadsto \frac{1}{\sqrt{\frac{1}{x}}} \]
                                      2. Step-by-step derivation
                                        1. Applied rewrites34.6%

                                          \[\leadsto \sqrt{x} \]
                                      3. Recombined 2 regimes into one program.
                                      4. Add Preprocessing

                                      Alternative 6: 36.7% accurate, 0.7× speedup?

                                      \[\begin{array}{l} \mathbf{if}\;\frac{x}{1 + \sqrt{x + 1}} \leq 4 \cdot 10^{-210}:\\ \;\;\;\;\sqrt{0}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{x}\\ \end{array} \]
                                      (FPCore (x)
                                        :precision binary64
                                        :pre TRUE
                                        (if (<= (/ x (+ 1.0 (sqrt (+ x 1.0)))) 4e-210) (sqrt 0.0) (sqrt x)))
                                      double code(double x) {
                                      	double tmp;
                                      	if ((x / (1.0 + sqrt((x + 1.0)))) <= 4e-210) {
                                      		tmp = sqrt(0.0);
                                      	} else {
                                      		tmp = sqrt(x);
                                      	}
                                      	return tmp;
                                      }
                                      
                                      real(8) function code(x)
                                      use fmin_fmax_functions
                                          real(8), intent (in) :: x
                                          real(8) :: tmp
                                          if ((x / (1.0d0 + sqrt((x + 1.0d0)))) <= 4d-210) then
                                              tmp = sqrt(0.0d0)
                                          else
                                              tmp = sqrt(x)
                                          end if
                                          code = tmp
                                      end function
                                      
                                      public static double code(double x) {
                                      	double tmp;
                                      	if ((x / (1.0 + Math.sqrt((x + 1.0)))) <= 4e-210) {
                                      		tmp = Math.sqrt(0.0);
                                      	} else {
                                      		tmp = Math.sqrt(x);
                                      	}
                                      	return tmp;
                                      }
                                      
                                      def code(x):
                                      	tmp = 0
                                      	if (x / (1.0 + math.sqrt((x + 1.0)))) <= 4e-210:
                                      		tmp = math.sqrt(0.0)
                                      	else:
                                      		tmp = math.sqrt(x)
                                      	return tmp
                                      
                                      function code(x)
                                      	tmp = 0.0
                                      	if (Float64(x / Float64(1.0 + sqrt(Float64(x + 1.0)))) <= 4e-210)
                                      		tmp = sqrt(0.0);
                                      	else
                                      		tmp = sqrt(x);
                                      	end
                                      	return tmp
                                      end
                                      
                                      function tmp_2 = code(x)
                                      	tmp = 0.0;
                                      	if ((x / (1.0 + sqrt((x + 1.0)))) <= 4e-210)
                                      		tmp = sqrt(0.0);
                                      	else
                                      		tmp = sqrt(x);
                                      	end
                                      	tmp_2 = tmp;
                                      end
                                      
                                      code[x_] := If[LessEqual[N[(x / N[(1.0 + N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 4e-210], N[Sqrt[0.0], $MachinePrecision], N[Sqrt[x], $MachinePrecision]]
                                      
                                      f(x):
                                      	x in [-inf, +inf]
                                      code: THEORY
                                      BEGIN
                                      f(x: real): real =
                                      	LET tmp = IF ((x / ((1) + (sqrt((x + (1)))))) <= (40000000000000001754955922235892998006218353004534480350476593552086812312828762824609665667893470382148702525598865546093318435031640624626745900808864392768698828487063690213161547567176664403997963093444535205751393006391340634994537348728463689202749036892606246670413469482542891968475704029388092629395892275133681299899143423556785033464480203676385451229669899140176458712009917313966594515003167803012359338524600134372869624583143557517732978270358050059486718115895288627009090148714358370352073279718752019107341766357421875e-745)) THEN (sqrt((0))) ELSE (sqrt(x)) ENDIF IN
                                      	tmp
                                      END code
                                      \begin{array}{l}
                                      \mathbf{if}\;\frac{x}{1 + \sqrt{x + 1}} \leq 4 \cdot 10^{-210}:\\
                                      \;\;\;\;\sqrt{0}\\
                                      
                                      \mathbf{else}:\\
                                      \;\;\;\;\sqrt{x}\\
                                      
                                      
                                      \end{array}
                                      
                                      Derivation
                                      1. Split input into 2 regimes
                                      2. if (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64))))) < 4.0000000000000002e-210

                                        1. Initial program 99.7%

                                          \[\frac{x}{1 + \sqrt{x + 1}} \]
                                        2. Taylor expanded in x around inf

                                          \[\leadsto \frac{1}{\sqrt{\frac{1}{x}}} \]
                                        3. Step-by-step derivation
                                          1. Applied rewrites34.5%

                                            \[\leadsto \frac{1}{\sqrt{\frac{1}{x}}} \]
                                          2. Step-by-step derivation
                                            1. Applied rewrites34.6%

                                              \[\leadsto \sqrt{x} \]
                                            2. Taylor expanded in undef-var around zero

                                              \[\leadsto \sqrt{0} \]
                                            3. Step-by-step derivation
                                              1. Applied rewrites4.5%

                                                \[\leadsto \sqrt{0} \]

                                              if 4.0000000000000002e-210 < (/.f64 x (+.f64 #s(literal 1 binary64) (sqrt.f64 (+.f64 x #s(literal 1 binary64)))))

                                              1. Initial program 99.7%

                                                \[\frac{x}{1 + \sqrt{x + 1}} \]
                                              2. Taylor expanded in x around inf

                                                \[\leadsto \frac{1}{\sqrt{\frac{1}{x}}} \]
                                              3. Step-by-step derivation
                                                1. Applied rewrites34.5%

                                                  \[\leadsto \frac{1}{\sqrt{\frac{1}{x}}} \]
                                                2. Step-by-step derivation
                                                  1. Applied rewrites34.6%

                                                    \[\leadsto \sqrt{x} \]
                                                3. Recombined 2 regimes into one program.
                                                4. Add Preprocessing

                                                Alternative 7: 34.6% accurate, 4.0× speedup?

                                                \[\sqrt{x} \]
                                                (FPCore (x)
                                                  :precision binary64
                                                  :pre TRUE
                                                  (sqrt x))
                                                double code(double x) {
                                                	return sqrt(x);
                                                }
                                                
                                                real(8) function code(x)
                                                use fmin_fmax_functions
                                                    real(8), intent (in) :: x
                                                    code = sqrt(x)
                                                end function
                                                
                                                public static double code(double x) {
                                                	return Math.sqrt(x);
                                                }
                                                
                                                def code(x):
                                                	return math.sqrt(x)
                                                
                                                function code(x)
                                                	return sqrt(x)
                                                end
                                                
                                                function tmp = code(x)
                                                	tmp = sqrt(x);
                                                end
                                                
                                                code[x_] := N[Sqrt[x], $MachinePrecision]
                                                
                                                f(x):
                                                	x in [-inf, +inf]
                                                code: THEORY
                                                BEGIN
                                                f(x: real): real =
                                                	sqrt(x)
                                                END code
                                                \sqrt{x}
                                                
                                                Derivation
                                                1. Initial program 99.7%

                                                  \[\frac{x}{1 + \sqrt{x + 1}} \]
                                                2. Taylor expanded in x around inf

                                                  \[\leadsto \frac{1}{\sqrt{\frac{1}{x}}} \]
                                                3. Step-by-step derivation
                                                  1. Applied rewrites34.5%

                                                    \[\leadsto \frac{1}{\sqrt{\frac{1}{x}}} \]
                                                  2. Step-by-step derivation
                                                    1. Applied rewrites34.6%

                                                      \[\leadsto \sqrt{x} \]
                                                    2. Add Preprocessing

                                                    Reproduce

                                                    ?
                                                    herbie shell --seed 2026092 
                                                    (FPCore (x)
                                                      :name "Numeric.Log:$clog1p from log-domain-0.10.2.1, B"
                                                      :precision binary64
                                                      (/ x (+ 1.0 (sqrt (+ x 1.0)))))