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

Percentage Accurate: 99.7% → 99.7%
Time: 10.6s
Alternatives: 8
Speedup: 1.0×

Specification

?
\[\begin{array}{l} \\ \frac{x}{1 + \sqrt{x + 1}} \end{array} \]
(FPCore (x) :precision binary64 (/ x (+ 1.0 (sqrt (+ x 1.0)))))
double code(double x) {
	return x / (1.0 + sqrt((x + 1.0)));
}
real(8) function code(x)
    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]
\begin{array}{l}

\\
\frac{x}{1 + \sqrt{x + 1}}
\end{array}

Sampling outcomes in binary64 precision:

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?

\[\begin{array}{l} \\ \frac{x}{1 + \sqrt{x + 1}} \end{array} \]
(FPCore (x) :precision binary64 (/ x (+ 1.0 (sqrt (+ x 1.0)))))
double code(double x) {
	return x / (1.0 + sqrt((x + 1.0)));
}
real(8) function code(x)
    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]
\begin{array}{l}

\\
\frac{x}{1 + \sqrt{x + 1}}
\end{array}

Alternative 1: 99.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \frac{x}{1 + \sqrt{x + 1}} \end{array} \]
(FPCore (x) :precision binary64 (/ x (+ 1.0 (sqrt (+ x 1.0)))))
double code(double x) {
	return x / (1.0 + sqrt((x + 1.0)));
}
real(8) function code(x)
    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]
\begin{array}{l}

\\
\frac{x}{1 + \sqrt{x + 1}}
\end{array}
Derivation
  1. Initial program 99.8%

    \[\frac{x}{1 + \sqrt{x + 1}} \]
  2. Add Preprocessing
  3. Add Preprocessing

Alternative 2: 99.1% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := -0.125 + x \cdot 0.0625\\ t_1 := x \cdot t\_0\\ \mathbf{if}\;x \leq 3:\\ \;\;\;\;\frac{x}{\frac{x}{2} + \frac{1}{\frac{t\_0 \cdot \left(x \cdot x\right) + -2}{\left(x \cdot x\right) \cdot \left(t\_1 \cdot t\_1\right) + -4}}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{x} + -1\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (+ -0.125 (* x 0.0625))) (t_1 (* x t_0)))
   (if (<= x 3.0)
     (/
      x
      (+
       (/ x 2.0)
       (/ 1.0 (/ (+ (* t_0 (* x x)) -2.0) (+ (* (* x x) (* t_1 t_1)) -4.0)))))
     (+ (sqrt x) -1.0))))
double code(double x) {
	double t_0 = -0.125 + (x * 0.0625);
	double t_1 = x * t_0;
	double tmp;
	if (x <= 3.0) {
		tmp = x / ((x / 2.0) + (1.0 / (((t_0 * (x * x)) + -2.0) / (((x * x) * (t_1 * t_1)) + -4.0))));
	} else {
		tmp = sqrt(x) + -1.0;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = (-0.125d0) + (x * 0.0625d0)
    t_1 = x * t_0
    if (x <= 3.0d0) then
        tmp = x / ((x / 2.0d0) + (1.0d0 / (((t_0 * (x * x)) + (-2.0d0)) / (((x * x) * (t_1 * t_1)) + (-4.0d0)))))
    else
        tmp = sqrt(x) + (-1.0d0)
    end if
    code = tmp
end function
public static double code(double x) {
	double t_0 = -0.125 + (x * 0.0625);
	double t_1 = x * t_0;
	double tmp;
	if (x <= 3.0) {
		tmp = x / ((x / 2.0) + (1.0 / (((t_0 * (x * x)) + -2.0) / (((x * x) * (t_1 * t_1)) + -4.0))));
	} else {
		tmp = Math.sqrt(x) + -1.0;
	}
	return tmp;
}
def code(x):
	t_0 = -0.125 + (x * 0.0625)
	t_1 = x * t_0
	tmp = 0
	if x <= 3.0:
		tmp = x / ((x / 2.0) + (1.0 / (((t_0 * (x * x)) + -2.0) / (((x * x) * (t_1 * t_1)) + -4.0))))
	else:
		tmp = math.sqrt(x) + -1.0
	return tmp
function code(x)
	t_0 = Float64(-0.125 + Float64(x * 0.0625))
	t_1 = Float64(x * t_0)
	tmp = 0.0
	if (x <= 3.0)
		tmp = Float64(x / Float64(Float64(x / 2.0) + Float64(1.0 / Float64(Float64(Float64(t_0 * Float64(x * x)) + -2.0) / Float64(Float64(Float64(x * x) * Float64(t_1 * t_1)) + -4.0)))));
	else
		tmp = Float64(sqrt(x) + -1.0);
	end
	return tmp
end
function tmp_2 = code(x)
	t_0 = -0.125 + (x * 0.0625);
	t_1 = x * t_0;
	tmp = 0.0;
	if (x <= 3.0)
		tmp = x / ((x / 2.0) + (1.0 / (((t_0 * (x * x)) + -2.0) / (((x * x) * (t_1 * t_1)) + -4.0))));
	else
		tmp = sqrt(x) + -1.0;
	end
	tmp_2 = tmp;
end
code[x_] := Block[{t$95$0 = N[(-0.125 + N[(x * 0.0625), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x * t$95$0), $MachinePrecision]}, If[LessEqual[x, 3.0], N[(x / N[(N[(x / 2.0), $MachinePrecision] + N[(1.0 / N[(N[(N[(t$95$0 * N[(x * x), $MachinePrecision]), $MachinePrecision] + -2.0), $MachinePrecision] / N[(N[(N[(x * x), $MachinePrecision] * N[(t$95$1 * t$95$1), $MachinePrecision]), $MachinePrecision] + -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Sqrt[x], $MachinePrecision] + -1.0), $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := -0.125 + x \cdot 0.0625\\
t_1 := x \cdot t\_0\\
\mathbf{if}\;x \leq 3:\\
\;\;\;\;\frac{x}{\frac{x}{2} + \frac{1}{\frac{t\_0 \cdot \left(x \cdot x\right) + -2}{\left(x \cdot x\right) \cdot \left(t\_1 \cdot t\_1\right) + -4}}}\\

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


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 3

    1. Initial program 100.0%

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

      \[\leadsto \mathsf{/.f64}\left(x, \color{blue}{\left(2 + x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{16} \cdot x - \frac{1}{8}\right)\right)\right)}\right) \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(x, \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{16} \cdot x - \frac{1}{8}\right)\right) + \color{blue}{2}\right)\right) \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{16} \cdot x - \frac{1}{8}\right)\right)\right), \color{blue}{2}\right)\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \left(\frac{1}{2} + x \cdot \left(\frac{1}{16} \cdot x - \frac{1}{8}\right)\right)\right), 2\right)\right) \]
      4. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \left(x \cdot \left(\frac{1}{16} \cdot x - \frac{1}{8}\right)\right)\right)\right), 2\right)\right) \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \left(\frac{1}{16} \cdot x - \frac{1}{8}\right)\right)\right)\right), 2\right)\right) \]
      6. sub-negN/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \left(\frac{1}{16} \cdot x + \left(\mathsf{neg}\left(\frac{1}{8}\right)\right)\right)\right)\right)\right), 2\right)\right) \]
      7. metadata-evalN/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \left(\frac{1}{16} \cdot x + \frac{-1}{8}\right)\right)\right)\right), 2\right)\right) \]
      8. +-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \left(\frac{-1}{8} + \frac{1}{16} \cdot x\right)\right)\right)\right), 2\right)\right) \]
      9. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{-1}{8}, \left(\frac{1}{16} \cdot x\right)\right)\right)\right)\right), 2\right)\right) \]
      10. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{-1}{8}, \left(x \cdot \frac{1}{16}\right)\right)\right)\right)\right), 2\right)\right) \]
      11. *-lowering-*.f6499.2%

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{-1}{8}, \mathsf{*.f64}\left(x, \frac{1}{16}\right)\right)\right)\right)\right), 2\right)\right) \]
    5. Simplified99.2%

      \[\leadsto \frac{x}{\color{blue}{x \cdot \left(0.5 + x \cdot \left(-0.125 + x \cdot 0.0625\right)\right) + 2}} \]
    6. Step-by-step derivation
      1. distribute-rgt-inN/A

        \[\leadsto \mathsf{/.f64}\left(x, \left(\left(\frac{1}{2} \cdot x + \left(x \cdot \left(\frac{-1}{8} + x \cdot \frac{1}{16}\right)\right) \cdot x\right) + 2\right)\right) \]
      2. associate-+l+N/A

        \[\leadsto \mathsf{/.f64}\left(x, \left(\frac{1}{2} \cdot x + \color{blue}{\left(\left(x \cdot \left(\frac{-1}{8} + x \cdot \frac{1}{16}\right)\right) \cdot x + 2\right)}\right)\right) \]
      3. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\left(\frac{1}{2} \cdot x\right), \color{blue}{\left(\left(x \cdot \left(\frac{-1}{8} + x \cdot \frac{1}{16}\right)\right) \cdot x + 2\right)}\right)\right) \]
      4. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\left(x \cdot \frac{1}{2}\right), \left(\color{blue}{\left(x \cdot \left(\frac{-1}{8} + x \cdot \frac{1}{16}\right)\right) \cdot x} + 2\right)\right)\right) \]
      5. metadata-evalN/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\left(x \cdot \frac{1}{2}\right), \left(\left(x \cdot \left(\frac{-1}{8} + x \cdot \frac{1}{16}\right)\right) \cdot \color{blue}{x} + 2\right)\right)\right) \]
      6. div-invN/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\left(\frac{x}{2}\right), \left(\color{blue}{\left(x \cdot \left(\frac{-1}{8} + x \cdot \frac{1}{16}\right)\right) \cdot x} + 2\right)\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \left(\color{blue}{\left(x \cdot \left(\frac{-1}{8} + x \cdot \frac{1}{16}\right)\right) \cdot x} + 2\right)\right)\right) \]
      8. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{+.f64}\left(\left(\left(x \cdot \left(\frac{-1}{8} + x \cdot \frac{1}{16}\right)\right) \cdot x\right), \color{blue}{2}\right)\right)\right) \]
      9. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{+.f64}\left(\left(\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot x\right) \cdot x\right), 2\right)\right)\right) \]
      10. associate-*l*N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{+.f64}\left(\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right), 2\right)\right)\right) \]
      11. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right), \left(x \cdot x\right)\right), 2\right)\right)\right) \]
      12. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{+.f64}\left(\frac{-1}{8}, \left(x \cdot \frac{1}{16}\right)\right), \left(x \cdot x\right)\right), 2\right)\right)\right) \]
      13. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{+.f64}\left(\frac{-1}{8}, \mathsf{*.f64}\left(x, \frac{1}{16}\right)\right), \left(x \cdot x\right)\right), 2\right)\right)\right) \]
      14. *-lowering-*.f6499.2%

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{+.f64}\left(\frac{-1}{8}, \mathsf{*.f64}\left(x, \frac{1}{16}\right)\right), \mathsf{*.f64}\left(x, x\right)\right), 2\right)\right)\right) \]
    7. Applied egg-rr99.2%

      \[\leadsto \frac{x}{\color{blue}{\frac{x}{2} + \left(\left(-0.125 + x \cdot 0.0625\right) \cdot \left(x \cdot x\right) + 2\right)}} \]
    8. Step-by-step derivation
      1. flip-+N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \left(\frac{\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right) \cdot \left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right) - 2 \cdot 2}{\color{blue}{\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right) - 2}}\right)\right)\right) \]
      2. clear-numN/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \left(\frac{1}{\color{blue}{\frac{\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right) - 2}{\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right) \cdot \left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right) - 2 \cdot 2}}}\right)\right)\right) \]
      3. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right) - 2}{\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right) \cdot \left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right) - 2 \cdot 2}\right)}\right)\right)\right) \]
      4. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right) - 2\right), \color{blue}{\left(\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right) \cdot \left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right) - 2 \cdot 2\right)}\right)\right)\right)\right) \]
      5. sub-negN/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right) + \left(\mathsf{neg}\left(2\right)\right)\right), \left(\color{blue}{\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right) \cdot \left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right)} - 2 \cdot 2\right)\right)\right)\right)\right) \]
      6. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right), \left(\mathsf{neg}\left(2\right)\right)\right), \left(\color{blue}{\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right) \cdot \left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right)} - 2 \cdot 2\right)\right)\right)\right)\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right), \left(x \cdot x\right)\right), \left(\mathsf{neg}\left(2\right)\right)\right), \left(\color{blue}{\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right)} \cdot \left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right) - 2 \cdot 2\right)\right)\right)\right)\right) \]
      8. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{+.f64}\left(\frac{-1}{8}, \left(x \cdot \frac{1}{16}\right)\right), \left(x \cdot x\right)\right), \left(\mathsf{neg}\left(2\right)\right)\right), \left(\left(\color{blue}{\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right)} \cdot \left(x \cdot x\right)\right) \cdot \left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right) - 2 \cdot 2\right)\right)\right)\right)\right) \]
      9. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{+.f64}\left(\frac{-1}{8}, \mathsf{*.f64}\left(x, \frac{1}{16}\right)\right), \left(x \cdot x\right)\right), \left(\mathsf{neg}\left(2\right)\right)\right), \left(\left(\left(\frac{-1}{8} + \color{blue}{x \cdot \frac{1}{16}}\right) \cdot \left(x \cdot x\right)\right) \cdot \left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right) - 2 \cdot 2\right)\right)\right)\right)\right) \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{+.f64}\left(\frac{-1}{8}, \mathsf{*.f64}\left(x, \frac{1}{16}\right)\right), \mathsf{*.f64}\left(x, x\right)\right), \left(\mathsf{neg}\left(2\right)\right)\right), \left(\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \color{blue}{\left(x \cdot x\right)}\right) \cdot \left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right) - 2 \cdot 2\right)\right)\right)\right)\right) \]
      11. metadata-evalN/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{+.f64}\left(\frac{-1}{8}, \mathsf{*.f64}\left(x, \frac{1}{16}\right)\right), \mathsf{*.f64}\left(x, x\right)\right), -2\right), \left(\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right) \cdot \color{blue}{\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right)} - 2 \cdot 2\right)\right)\right)\right)\right) \]
      12. metadata-evalN/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{+.f64}\left(\frac{-1}{8}, \mathsf{*.f64}\left(x, \frac{1}{16}\right)\right), \mathsf{*.f64}\left(x, x\right)\right), -2\right), \left(\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right) \cdot \left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right) - 4\right)\right)\right)\right)\right) \]
    9. Applied egg-rr99.2%

      \[\leadsto \frac{x}{\frac{x}{2} + \color{blue}{\frac{1}{\frac{\left(-0.125 + x \cdot 0.0625\right) \cdot \left(x \cdot x\right) + -2}{\left(x \cdot x\right) \cdot \left(\left(x \cdot \left(-0.125 + x \cdot 0.0625\right)\right) \cdot \left(x \cdot \left(-0.125 + x \cdot 0.0625\right)\right)\right) + -4}}}} \]

    if 3 < x

    1. Initial program 99.3%

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

      \[\leadsto \color{blue}{\sqrt{x} - 1} \]
    4. Step-by-step derivation
      1. sub-negN/A

        \[\leadsto \sqrt{x} + \color{blue}{\left(\mathsf{neg}\left(1\right)\right)} \]
      2. metadata-evalN/A

        \[\leadsto \sqrt{x} + -1 \]
      3. +-lowering-+.f64N/A

        \[\leadsto \mathsf{+.f64}\left(\left(\sqrt{x}\right), \color{blue}{-1}\right) \]
      4. sqrt-lowering-sqrt.f6497.8%

        \[\leadsto \mathsf{+.f64}\left(\mathsf{sqrt.f64}\left(x\right), -1\right) \]
    5. Simplified97.8%

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

Alternative 3: 98.4% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := -0.125 + x \cdot 0.0625\\ t_1 := x \cdot t\_0\\ \mathbf{if}\;x \leq 3.7:\\ \;\;\;\;\frac{x}{\frac{x}{2} + \frac{1}{\frac{t\_0 \cdot \left(x \cdot x\right) + -2}{\left(x \cdot x\right) \cdot \left(t\_1 \cdot t\_1\right) + -4}}}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (+ -0.125 (* x 0.0625))) (t_1 (* x t_0)))
   (if (<= x 3.7)
     (/
      x
      (+
       (/ x 2.0)
       (/ 1.0 (/ (+ (* t_0 (* x x)) -2.0) (+ (* (* x x) (* t_1 t_1)) -4.0)))))
     (sqrt x))))
double code(double x) {
	double t_0 = -0.125 + (x * 0.0625);
	double t_1 = x * t_0;
	double tmp;
	if (x <= 3.7) {
		tmp = x / ((x / 2.0) + (1.0 / (((t_0 * (x * x)) + -2.0) / (((x * x) * (t_1 * t_1)) + -4.0))));
	} else {
		tmp = sqrt(x);
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: t_0
    real(8) :: t_1
    real(8) :: tmp
    t_0 = (-0.125d0) + (x * 0.0625d0)
    t_1 = x * t_0
    if (x <= 3.7d0) then
        tmp = x / ((x / 2.0d0) + (1.0d0 / (((t_0 * (x * x)) + (-2.0d0)) / (((x * x) * (t_1 * t_1)) + (-4.0d0)))))
    else
        tmp = sqrt(x)
    end if
    code = tmp
end function
public static double code(double x) {
	double t_0 = -0.125 + (x * 0.0625);
	double t_1 = x * t_0;
	double tmp;
	if (x <= 3.7) {
		tmp = x / ((x / 2.0) + (1.0 / (((t_0 * (x * x)) + -2.0) / (((x * x) * (t_1 * t_1)) + -4.0))));
	} else {
		tmp = Math.sqrt(x);
	}
	return tmp;
}
def code(x):
	t_0 = -0.125 + (x * 0.0625)
	t_1 = x * t_0
	tmp = 0
	if x <= 3.7:
		tmp = x / ((x / 2.0) + (1.0 / (((t_0 * (x * x)) + -2.0) / (((x * x) * (t_1 * t_1)) + -4.0))))
	else:
		tmp = math.sqrt(x)
	return tmp
function code(x)
	t_0 = Float64(-0.125 + Float64(x * 0.0625))
	t_1 = Float64(x * t_0)
	tmp = 0.0
	if (x <= 3.7)
		tmp = Float64(x / Float64(Float64(x / 2.0) + Float64(1.0 / Float64(Float64(Float64(t_0 * Float64(x * x)) + -2.0) / Float64(Float64(Float64(x * x) * Float64(t_1 * t_1)) + -4.0)))));
	else
		tmp = sqrt(x);
	end
	return tmp
end
function tmp_2 = code(x)
	t_0 = -0.125 + (x * 0.0625);
	t_1 = x * t_0;
	tmp = 0.0;
	if (x <= 3.7)
		tmp = x / ((x / 2.0) + (1.0 / (((t_0 * (x * x)) + -2.0) / (((x * x) * (t_1 * t_1)) + -4.0))));
	else
		tmp = sqrt(x);
	end
	tmp_2 = tmp;
end
code[x_] := Block[{t$95$0 = N[(-0.125 + N[(x * 0.0625), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$1 = N[(x * t$95$0), $MachinePrecision]}, If[LessEqual[x, 3.7], N[(x / N[(N[(x / 2.0), $MachinePrecision] + N[(1.0 / N[(N[(N[(t$95$0 * N[(x * x), $MachinePrecision]), $MachinePrecision] + -2.0), $MachinePrecision] / N[(N[(N[(x * x), $MachinePrecision] * N[(t$95$1 * t$95$1), $MachinePrecision]), $MachinePrecision] + -4.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[Sqrt[x], $MachinePrecision]]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := -0.125 + x \cdot 0.0625\\
t_1 := x \cdot t\_0\\
\mathbf{if}\;x \leq 3.7:\\
\;\;\;\;\frac{x}{\frac{x}{2} + \frac{1}{\frac{t\_0 \cdot \left(x \cdot x\right) + -2}{\left(x \cdot x\right) \cdot \left(t\_1 \cdot t\_1\right) + -4}}}\\

\mathbf{else}:\\
\;\;\;\;\sqrt{x}\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if x < 3.7000000000000002

    1. Initial program 100.0%

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

      \[\leadsto \mathsf{/.f64}\left(x, \color{blue}{\left(2 + x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{16} \cdot x - \frac{1}{8}\right)\right)\right)}\right) \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(x, \left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{16} \cdot x - \frac{1}{8}\right)\right) + \color{blue}{2}\right)\right) \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\left(x \cdot \left(\frac{1}{2} + x \cdot \left(\frac{1}{16} \cdot x - \frac{1}{8}\right)\right)\right), \color{blue}{2}\right)\right) \]
      3. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \left(\frac{1}{2} + x \cdot \left(\frac{1}{16} \cdot x - \frac{1}{8}\right)\right)\right), 2\right)\right) \]
      4. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \left(x \cdot \left(\frac{1}{16} \cdot x - \frac{1}{8}\right)\right)\right)\right), 2\right)\right) \]
      5. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \left(\frac{1}{16} \cdot x - \frac{1}{8}\right)\right)\right)\right), 2\right)\right) \]
      6. sub-negN/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \left(\frac{1}{16} \cdot x + \left(\mathsf{neg}\left(\frac{1}{8}\right)\right)\right)\right)\right)\right), 2\right)\right) \]
      7. metadata-evalN/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \left(\frac{1}{16} \cdot x + \frac{-1}{8}\right)\right)\right)\right), 2\right)\right) \]
      8. +-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \left(\frac{-1}{8} + \frac{1}{16} \cdot x\right)\right)\right)\right), 2\right)\right) \]
      9. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{-1}{8}, \left(\frac{1}{16} \cdot x\right)\right)\right)\right)\right), 2\right)\right) \]
      10. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{-1}{8}, \left(x \cdot \frac{1}{16}\right)\right)\right)\right)\right), 2\right)\right) \]
      11. *-lowering-*.f6499.2%

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{*.f64}\left(x, \mathsf{+.f64}\left(\frac{-1}{8}, \mathsf{*.f64}\left(x, \frac{1}{16}\right)\right)\right)\right)\right), 2\right)\right) \]
    5. Simplified99.2%

      \[\leadsto \frac{x}{\color{blue}{x \cdot \left(0.5 + x \cdot \left(-0.125 + x \cdot 0.0625\right)\right) + 2}} \]
    6. Step-by-step derivation
      1. distribute-rgt-inN/A

        \[\leadsto \mathsf{/.f64}\left(x, \left(\left(\frac{1}{2} \cdot x + \left(x \cdot \left(\frac{-1}{8} + x \cdot \frac{1}{16}\right)\right) \cdot x\right) + 2\right)\right) \]
      2. associate-+l+N/A

        \[\leadsto \mathsf{/.f64}\left(x, \left(\frac{1}{2} \cdot x + \color{blue}{\left(\left(x \cdot \left(\frac{-1}{8} + x \cdot \frac{1}{16}\right)\right) \cdot x + 2\right)}\right)\right) \]
      3. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\left(\frac{1}{2} \cdot x\right), \color{blue}{\left(\left(x \cdot \left(\frac{-1}{8} + x \cdot \frac{1}{16}\right)\right) \cdot x + 2\right)}\right)\right) \]
      4. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\left(x \cdot \frac{1}{2}\right), \left(\color{blue}{\left(x \cdot \left(\frac{-1}{8} + x \cdot \frac{1}{16}\right)\right) \cdot x} + 2\right)\right)\right) \]
      5. metadata-evalN/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\left(x \cdot \frac{1}{2}\right), \left(\left(x \cdot \left(\frac{-1}{8} + x \cdot \frac{1}{16}\right)\right) \cdot \color{blue}{x} + 2\right)\right)\right) \]
      6. div-invN/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\left(\frac{x}{2}\right), \left(\color{blue}{\left(x \cdot \left(\frac{-1}{8} + x \cdot \frac{1}{16}\right)\right) \cdot x} + 2\right)\right)\right) \]
      7. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \left(\color{blue}{\left(x \cdot \left(\frac{-1}{8} + x \cdot \frac{1}{16}\right)\right) \cdot x} + 2\right)\right)\right) \]
      8. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{+.f64}\left(\left(\left(x \cdot \left(\frac{-1}{8} + x \cdot \frac{1}{16}\right)\right) \cdot x\right), \color{blue}{2}\right)\right)\right) \]
      9. *-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{+.f64}\left(\left(\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot x\right) \cdot x\right), 2\right)\right)\right) \]
      10. associate-*l*N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{+.f64}\left(\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right), 2\right)\right)\right) \]
      11. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right), \left(x \cdot x\right)\right), 2\right)\right)\right) \]
      12. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{+.f64}\left(\frac{-1}{8}, \left(x \cdot \frac{1}{16}\right)\right), \left(x \cdot x\right)\right), 2\right)\right)\right) \]
      13. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{+.f64}\left(\frac{-1}{8}, \mathsf{*.f64}\left(x, \frac{1}{16}\right)\right), \left(x \cdot x\right)\right), 2\right)\right)\right) \]
      14. *-lowering-*.f6499.2%

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{+.f64}\left(\frac{-1}{8}, \mathsf{*.f64}\left(x, \frac{1}{16}\right)\right), \mathsf{*.f64}\left(x, x\right)\right), 2\right)\right)\right) \]
    7. Applied egg-rr99.2%

      \[\leadsto \frac{x}{\color{blue}{\frac{x}{2} + \left(\left(-0.125 + x \cdot 0.0625\right) \cdot \left(x \cdot x\right) + 2\right)}} \]
    8. Step-by-step derivation
      1. flip-+N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \left(\frac{\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right) \cdot \left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right) - 2 \cdot 2}{\color{blue}{\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right) - 2}}\right)\right)\right) \]
      2. clear-numN/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \left(\frac{1}{\color{blue}{\frac{\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right) - 2}{\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right) \cdot \left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right) - 2 \cdot 2}}}\right)\right)\right) \]
      3. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right) - 2}{\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right) \cdot \left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right) - 2 \cdot 2}\right)}\right)\right)\right) \]
      4. /-lowering-/.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right) - 2\right), \color{blue}{\left(\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right) \cdot \left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right) - 2 \cdot 2\right)}\right)\right)\right)\right) \]
      5. sub-negN/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right) + \left(\mathsf{neg}\left(2\right)\right)\right), \left(\color{blue}{\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right) \cdot \left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right)} - 2 \cdot 2\right)\right)\right)\right)\right) \]
      6. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right), \left(\mathsf{neg}\left(2\right)\right)\right), \left(\color{blue}{\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right) \cdot \left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right)} - 2 \cdot 2\right)\right)\right)\right)\right) \]
      7. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right), \left(x \cdot x\right)\right), \left(\mathsf{neg}\left(2\right)\right)\right), \left(\color{blue}{\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right)} \cdot \left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right) - 2 \cdot 2\right)\right)\right)\right)\right) \]
      8. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{+.f64}\left(\frac{-1}{8}, \left(x \cdot \frac{1}{16}\right)\right), \left(x \cdot x\right)\right), \left(\mathsf{neg}\left(2\right)\right)\right), \left(\left(\color{blue}{\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right)} \cdot \left(x \cdot x\right)\right) \cdot \left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right) - 2 \cdot 2\right)\right)\right)\right)\right) \]
      9. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{+.f64}\left(\frac{-1}{8}, \mathsf{*.f64}\left(x, \frac{1}{16}\right)\right), \left(x \cdot x\right)\right), \left(\mathsf{neg}\left(2\right)\right)\right), \left(\left(\left(\frac{-1}{8} + \color{blue}{x \cdot \frac{1}{16}}\right) \cdot \left(x \cdot x\right)\right) \cdot \left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right) - 2 \cdot 2\right)\right)\right)\right)\right) \]
      10. *-lowering-*.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{+.f64}\left(\frac{-1}{8}, \mathsf{*.f64}\left(x, \frac{1}{16}\right)\right), \mathsf{*.f64}\left(x, x\right)\right), \left(\mathsf{neg}\left(2\right)\right)\right), \left(\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \color{blue}{\left(x \cdot x\right)}\right) \cdot \left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right) - 2 \cdot 2\right)\right)\right)\right)\right) \]
      11. metadata-evalN/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{+.f64}\left(\frac{-1}{8}, \mathsf{*.f64}\left(x, \frac{1}{16}\right)\right), \mathsf{*.f64}\left(x, x\right)\right), -2\right), \left(\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right) \cdot \color{blue}{\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right)} - 2 \cdot 2\right)\right)\right)\right)\right) \]
      12. metadata-evalN/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{/.f64}\left(x, 2\right), \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(\mathsf{*.f64}\left(\mathsf{+.f64}\left(\frac{-1}{8}, \mathsf{*.f64}\left(x, \frac{1}{16}\right)\right), \mathsf{*.f64}\left(x, x\right)\right), -2\right), \left(\left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right) \cdot \left(\left(\frac{-1}{8} + x \cdot \frac{1}{16}\right) \cdot \left(x \cdot x\right)\right) - 4\right)\right)\right)\right)\right) \]
    9. Applied egg-rr99.2%

      \[\leadsto \frac{x}{\frac{x}{2} + \color{blue}{\frac{1}{\frac{\left(-0.125 + x \cdot 0.0625\right) \cdot \left(x \cdot x\right) + -2}{\left(x \cdot x\right) \cdot \left(\left(x \cdot \left(-0.125 + x \cdot 0.0625\right)\right) \cdot \left(x \cdot \left(-0.125 + x \cdot 0.0625\right)\right)\right) + -4}}}} \]

    if 3.7000000000000002 < x

    1. Initial program 99.3%

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

      \[\leadsto \color{blue}{\sqrt{x}} \]
    4. Step-by-step derivation
      1. sqrt-lowering-sqrt.f6496.0%

        \[\leadsto \mathsf{sqrt.f64}\left(x\right) \]
    5. Simplified96.0%

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

Alternative 4: 68.3% accurate, 11.9× speedup?

\[\begin{array}{l} \\ x \cdot \frac{1}{2 + \frac{x}{2}} \end{array} \]
(FPCore (x) :precision binary64 (* x (/ 1.0 (+ 2.0 (/ x 2.0)))))
double code(double x) {
	return x * (1.0 / (2.0 + (x / 2.0)));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = x * (1.0d0 / (2.0d0 + (x / 2.0d0)))
end function
public static double code(double x) {
	return x * (1.0 / (2.0 + (x / 2.0)));
}
def code(x):
	return x * (1.0 / (2.0 + (x / 2.0)))
function code(x)
	return Float64(x * Float64(1.0 / Float64(2.0 + Float64(x / 2.0))))
end
function tmp = code(x)
	tmp = x * (1.0 / (2.0 + (x / 2.0)));
end
code[x_] := N[(x * N[(1.0 / N[(2.0 + N[(x / 2.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
x \cdot \frac{1}{2 + \frac{x}{2}}
\end{array}
Derivation
  1. Initial program 99.8%

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

    \[\leadsto \mathsf{/.f64}\left(x, \color{blue}{\left(2 + \frac{1}{2} \cdot x\right)}\right) \]
  4. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(x, \left(\frac{1}{2} \cdot x + \color{blue}{2}\right)\right) \]
    2. +-lowering-+.f64N/A

      \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\left(\frac{1}{2} \cdot x\right), \color{blue}{2}\right)\right) \]
    3. *-lowering-*.f6471.5%

      \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, x\right), 2\right)\right) \]
  5. Simplified71.5%

    \[\leadsto \frac{x}{\color{blue}{0.5 \cdot x + 2}} \]
  6. Step-by-step derivation
    1. clear-numN/A

      \[\leadsto \frac{1}{\color{blue}{\frac{\frac{1}{2} \cdot x + 2}{x}}} \]
    2. associate-/r/N/A

      \[\leadsto \frac{1}{\frac{1}{2} \cdot x + 2} \cdot \color{blue}{x} \]
    3. *-lowering-*.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\left(\frac{1}{\frac{1}{2} \cdot x + 2}\right), \color{blue}{x}\right) \]
    4. /-lowering-/.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(1, \left(\frac{1}{2} \cdot x + 2\right)\right), x\right) \]
    5. +-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(1, \left(2 + \frac{1}{2} \cdot x\right)\right), x\right) \]
    6. +-lowering-+.f64N/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(1, \mathsf{+.f64}\left(2, \left(\frac{1}{2} \cdot x\right)\right)\right), x\right) \]
    7. *-commutativeN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(1, \mathsf{+.f64}\left(2, \left(x \cdot \frac{1}{2}\right)\right)\right), x\right) \]
    8. metadata-evalN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(1, \mathsf{+.f64}\left(2, \left(x \cdot \frac{1}{2}\right)\right)\right), x\right) \]
    9. div-invN/A

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(1, \mathsf{+.f64}\left(2, \left(\frac{x}{2}\right)\right)\right), x\right) \]
    10. /-lowering-/.f6471.5%

      \[\leadsto \mathsf{*.f64}\left(\mathsf{/.f64}\left(1, \mathsf{+.f64}\left(2, \mathsf{/.f64}\left(x, 2\right)\right)\right), x\right) \]
  7. Applied egg-rr71.5%

    \[\leadsto \color{blue}{\frac{1}{2 + \frac{x}{2}} \cdot x} \]
  8. Final simplification71.5%

    \[\leadsto x \cdot \frac{1}{2 + \frac{x}{2}} \]
  9. Add Preprocessing

Alternative 5: 68.3% accurate, 15.3× speedup?

\[\begin{array}{l} \\ \frac{x}{2 + x \cdot 0.5} \end{array} \]
(FPCore (x) :precision binary64 (/ x (+ 2.0 (* x 0.5))))
double code(double x) {
	return x / (2.0 + (x * 0.5));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = x / (2.0d0 + (x * 0.5d0))
end function
public static double code(double x) {
	return x / (2.0 + (x * 0.5));
}
def code(x):
	return x / (2.0 + (x * 0.5))
function code(x)
	return Float64(x / Float64(2.0 + Float64(x * 0.5)))
end
function tmp = code(x)
	tmp = x / (2.0 + (x * 0.5));
end
code[x_] := N[(x / N[(2.0 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{x}{2 + x \cdot 0.5}
\end{array}
Derivation
  1. Initial program 99.8%

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

    \[\leadsto \mathsf{/.f64}\left(x, \color{blue}{\left(2 + \frac{1}{2} \cdot x\right)}\right) \]
  4. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(x, \left(\frac{1}{2} \cdot x + \color{blue}{2}\right)\right) \]
    2. +-lowering-+.f64N/A

      \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\left(\frac{1}{2} \cdot x\right), \color{blue}{2}\right)\right) \]
    3. *-lowering-*.f6471.5%

      \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, x\right), 2\right)\right) \]
  5. Simplified71.5%

    \[\leadsto \frac{x}{\color{blue}{0.5 \cdot x + 2}} \]
  6. Final simplification71.5%

    \[\leadsto \frac{x}{2 + x \cdot 0.5} \]
  7. Add Preprocessing

Alternative 6: 68.1% accurate, 15.3× speedup?

\[\begin{array}{l} \\ \frac{1}{0.5 + \frac{2}{x}} \end{array} \]
(FPCore (x) :precision binary64 (/ 1.0 (+ 0.5 (/ 2.0 x))))
double code(double x) {
	return 1.0 / (0.5 + (2.0 / x));
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 1.0d0 / (0.5d0 + (2.0d0 / x))
end function
public static double code(double x) {
	return 1.0 / (0.5 + (2.0 / x));
}
def code(x):
	return 1.0 / (0.5 + (2.0 / x))
function code(x)
	return Float64(1.0 / Float64(0.5 + Float64(2.0 / x)))
end
function tmp = code(x)
	tmp = 1.0 / (0.5 + (2.0 / x));
end
code[x_] := N[(1.0 / N[(0.5 + N[(2.0 / x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\frac{1}{0.5 + \frac{2}{x}}
\end{array}
Derivation
  1. Initial program 99.8%

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

    \[\leadsto \mathsf{/.f64}\left(x, \color{blue}{\left(2 + \frac{1}{2} \cdot x\right)}\right) \]
  4. Step-by-step derivation
    1. +-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(x, \left(\frac{1}{2} \cdot x + \color{blue}{2}\right)\right) \]
    2. +-lowering-+.f64N/A

      \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\left(\frac{1}{2} \cdot x\right), \color{blue}{2}\right)\right) \]
    3. *-lowering-*.f6471.5%

      \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, x\right), 2\right)\right) \]
  5. Simplified71.5%

    \[\leadsto \frac{x}{\color{blue}{0.5 \cdot x + 2}} \]
  6. Step-by-step derivation
    1. clear-numN/A

      \[\leadsto \frac{1}{\color{blue}{\frac{\frac{1}{2} \cdot x + 2}{x}}} \]
    2. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{\frac{1}{2} \cdot x + 2}{x}\right)}\right) \]
    3. /-lowering-/.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\left(\frac{1}{2} \cdot x + 2\right), \color{blue}{x}\right)\right) \]
    4. +-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\left(2 + \frac{1}{2} \cdot x\right), x\right)\right) \]
    5. +-lowering-+.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(2, \left(\frac{1}{2} \cdot x\right)\right), x\right)\right) \]
    6. *-commutativeN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(2, \left(x \cdot \frac{1}{2}\right)\right), x\right)\right) \]
    7. metadata-evalN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(2, \left(x \cdot \frac{1}{2}\right)\right), x\right)\right) \]
    8. div-invN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(2, \left(\frac{x}{2}\right)\right), x\right)\right) \]
    9. /-lowering-/.f6471.4%

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{/.f64}\left(\mathsf{+.f64}\left(2, \mathsf{/.f64}\left(x, 2\right)\right), x\right)\right) \]
  7. Applied egg-rr71.4%

    \[\leadsto \color{blue}{\frac{1}{\frac{2 + \frac{x}{2}}{x}}} \]
  8. Taylor expanded in x around inf

    \[\leadsto \mathsf{/.f64}\left(1, \color{blue}{\left(\frac{1}{2} + 2 \cdot \frac{1}{x}\right)}\right) \]
  9. Step-by-step derivation
    1. +-lowering-+.f64N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{+.f64}\left(\frac{1}{2}, \color{blue}{\left(2 \cdot \frac{1}{x}\right)}\right)\right) \]
    2. associate-*r/N/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{+.f64}\left(\frac{1}{2}, \left(\frac{2 \cdot 1}{\color{blue}{x}}\right)\right)\right) \]
    3. metadata-evalN/A

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{+.f64}\left(\frac{1}{2}, \left(\frac{2}{x}\right)\right)\right) \]
    4. /-lowering-/.f6471.4%

      \[\leadsto \mathsf{/.f64}\left(1, \mathsf{+.f64}\left(\frac{1}{2}, \mathsf{/.f64}\left(2, \color{blue}{x}\right)\right)\right) \]
  10. Simplified71.4%

    \[\leadsto \frac{1}{\color{blue}{0.5 + \frac{2}{x}}} \]
  11. Add Preprocessing

Alternative 7: 67.5% accurate, 35.7× speedup?

\[\begin{array}{l} \\ \frac{x}{2} \end{array} \]
(FPCore (x) :precision binary64 (/ x 2.0))
double code(double x) {
	return x / 2.0;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = x / 2.0d0
end function
public static double code(double x) {
	return x / 2.0;
}
def code(x):
	return x / 2.0
function code(x)
	return Float64(x / 2.0)
end
function tmp = code(x)
	tmp = x / 2.0;
end
code[x_] := N[(x / 2.0), $MachinePrecision]
\begin{array}{l}

\\
\frac{x}{2}
\end{array}
Derivation
  1. Initial program 99.8%

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

    \[\leadsto \mathsf{/.f64}\left(x, \color{blue}{2}\right) \]
  4. Step-by-step derivation
    1. Simplified70.4%

      \[\leadsto \frac{x}{\color{blue}{2}} \]
    2. Add Preprocessing

    Alternative 8: 4.9% accurate, 107.0× speedup?

    \[\begin{array}{l} \\ 2 \end{array} \]
    (FPCore (x) :precision binary64 2.0)
    double code(double x) {
    	return 2.0;
    }
    
    real(8) function code(x)
        real(8), intent (in) :: x
        code = 2.0d0
    end function
    
    public static double code(double x) {
    	return 2.0;
    }
    
    def code(x):
    	return 2.0
    
    function code(x)
    	return 2.0
    end
    
    function tmp = code(x)
    	tmp = 2.0;
    end
    
    code[x_] := 2.0
    
    \begin{array}{l}
    
    \\
    2
    \end{array}
    
    Derivation
    1. Initial program 99.8%

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

      \[\leadsto \mathsf{/.f64}\left(x, \color{blue}{\left(2 + \frac{1}{2} \cdot x\right)}\right) \]
    4. Step-by-step derivation
      1. +-commutativeN/A

        \[\leadsto \mathsf{/.f64}\left(x, \left(\frac{1}{2} \cdot x + \color{blue}{2}\right)\right) \]
      2. +-lowering-+.f64N/A

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\left(\frac{1}{2} \cdot x\right), \color{blue}{2}\right)\right) \]
      3. *-lowering-*.f6471.5%

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, x\right), 2\right)\right) \]
    5. Simplified71.5%

      \[\leadsto \frac{x}{\color{blue}{0.5 \cdot x + 2}} \]
    6. Taylor expanded in x around inf

      \[\leadsto \color{blue}{2} \]
    7. Step-by-step derivation
      1. Simplified4.8%

        \[\leadsto \color{blue}{2} \]
      2. Add Preprocessing

      Reproduce

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