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

Percentage Accurate: 99.7% → 99.8%
Time: 10.2s
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.8% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;x \leq 0.0015:\\ \;\;\;\;\frac{x}{\left(2 + \frac{x}{2}\right) + x \cdot \left(x \cdot \left(-0.125 + x \cdot 0.0625\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;{\left(x + 1\right)}^{0.5} + -1\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= x 0.0015)
   (/ x (+ (+ 2.0 (/ x 2.0)) (* x (* x (+ -0.125 (* x 0.0625))))))
   (+ (pow (+ x 1.0) 0.5) -1.0)))
double code(double x) {
	double tmp;
	if (x <= 0.0015) {
		tmp = x / ((2.0 + (x / 2.0)) + (x * (x * (-0.125 + (x * 0.0625)))));
	} else {
		tmp = pow((x + 1.0), 0.5) + -1.0;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: tmp
    if (x <= 0.0015d0) then
        tmp = x / ((2.0d0 + (x / 2.0d0)) + (x * (x * ((-0.125d0) + (x * 0.0625d0)))))
    else
        tmp = ((x + 1.0d0) ** 0.5d0) + (-1.0d0)
    end if
    code = tmp
end function
public static double code(double x) {
	double tmp;
	if (x <= 0.0015) {
		tmp = x / ((2.0 + (x / 2.0)) + (x * (x * (-0.125 + (x * 0.0625)))));
	} else {
		tmp = Math.pow((x + 1.0), 0.5) + -1.0;
	}
	return tmp;
}
def code(x):
	tmp = 0
	if x <= 0.0015:
		tmp = x / ((2.0 + (x / 2.0)) + (x * (x * (-0.125 + (x * 0.0625)))))
	else:
		tmp = math.pow((x + 1.0), 0.5) + -1.0
	return tmp
function code(x)
	tmp = 0.0
	if (x <= 0.0015)
		tmp = Float64(x / Float64(Float64(2.0 + Float64(x / 2.0)) + Float64(x * Float64(x * Float64(-0.125 + Float64(x * 0.0625))))));
	else
		tmp = Float64((Float64(x + 1.0) ^ 0.5) + -1.0);
	end
	return tmp
end
function tmp_2 = code(x)
	tmp = 0.0;
	if (x <= 0.0015)
		tmp = x / ((2.0 + (x / 2.0)) + (x * (x * (-0.125 + (x * 0.0625)))));
	else
		tmp = ((x + 1.0) ^ 0.5) + -1.0;
	end
	tmp_2 = tmp;
end
code[x_] := If[LessEqual[x, 0.0015], N[(x / N[(N[(2.0 + N[(x / 2.0), $MachinePrecision]), $MachinePrecision] + N[(x * N[(x * N[(-0.125 + N[(x * 0.0625), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(x + 1.0), $MachinePrecision], 0.5], $MachinePrecision] + -1.0), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.0015:\\
\;\;\;\;\frac{x}{\left(2 + \frac{x}{2}\right) + x \cdot \left(x \cdot \left(-0.125 + x \cdot 0.0625\right)\right)}\\

\mathbf{else}:\\
\;\;\;\;{\left(x + 1\right)}^{0.5} + -1\\


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

    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.8%

        \[\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.8%

      \[\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. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 0.0015 < x

    1. Initial program 99.3%

      \[\frac{x}{1 + \sqrt{x + 1}} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. frac-2negN/A

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

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

        \[\leadsto \frac{\left(1 - 1\right) - x}{\mathsf{neg}\left(\left(\color{blue}{1} + \sqrt{x + 1}\right)\right)} \]
      4. associate--r+N/A

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

        \[\leadsto \frac{1 \cdot 1 - \left(1 + x\right)}{\mathsf{neg}\left(\left(\color{blue}{1} + \sqrt{x + 1}\right)\right)} \]
      6. +-commutativeN/A

        \[\leadsto \frac{1 \cdot 1 - \left(x + 1\right)}{\mathsf{neg}\left(\left(1 + \color{blue}{\sqrt{x + 1}}\right)\right)} \]
      7. rem-square-sqrtN/A

        \[\leadsto \frac{1 \cdot 1 - \sqrt{x + 1} \cdot \sqrt{x + 1}}{\mathsf{neg}\left(\left(1 + \color{blue}{\sqrt{x + 1}}\right)\right)} \]
      8. distribute-neg-frac2N/A

        \[\leadsto \mathsf{neg}\left(\frac{1 \cdot 1 - \sqrt{x + 1} \cdot \sqrt{x + 1}}{1 + \sqrt{x + 1}}\right) \]
      9. flip--N/A

        \[\leadsto \mathsf{neg}\left(\left(1 - \sqrt{x + 1}\right)\right) \]
      10. neg-lowering-neg.f64N/A

        \[\leadsto \mathsf{neg.f64}\left(\left(1 - \sqrt{x + 1}\right)\right) \]
      11. --lowering--.f64N/A

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{\_.f64}\left(1, \left(\sqrt{x + 1}\right)\right)\right) \]
      12. pow1/2N/A

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{\_.f64}\left(1, \left({\left(x + 1\right)}^{\frac{1}{2}}\right)\right)\right) \]
      13. pow-lowering-pow.f64N/A

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{\_.f64}\left(1, \mathsf{pow.f64}\left(\left(x + 1\right), \frac{1}{2}\right)\right)\right) \]
      14. +-lowering-+.f64100.0%

        \[\leadsto \mathsf{neg.f64}\left(\mathsf{\_.f64}\left(1, \mathsf{pow.f64}\left(\mathsf{+.f64}\left(x, 1\right), \frac{1}{2}\right)\right)\right) \]
    4. Applied egg-rr100.0%

      \[\leadsto \color{blue}{-\left(1 - {\left(x + 1\right)}^{0.5}\right)} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.8%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 0.0015:\\ \;\;\;\;\frac{x}{\left(2 + \frac{x}{2}\right) + x \cdot \left(x \cdot \left(-0.125 + x \cdot 0.0625\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;{\left(x + 1\right)}^{0.5} + -1\\ \end{array} \]
  5. Add Preprocessing

Alternative 2: 99.0% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq 3:\\
\;\;\;\;\frac{x}{\left(2 + \frac{x}{2}\right) + x \cdot \left(x \cdot \left(-0.125 + x \cdot 0.0625\right)\right)}\\

\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.5%

        \[\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.5%

      \[\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. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    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.f6499.8%

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

      \[\leadsto \color{blue}{\sqrt{x} + -1} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.6%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 3:\\ \;\;\;\;\frac{x}{\left(2 + \frac{x}{2}\right) + x \cdot \left(x \cdot \left(-0.125 + x \cdot 0.0625\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{x} + -1\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 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.7%

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

Alternative 4: 98.3% accurate, 1.0× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq 3.6:\\
\;\;\;\;\frac{x}{\left(2 + \frac{x}{2}\right) + x \cdot \left(x \cdot \left(-0.125 + x \cdot 0.0625\right)\right)}\\

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


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

    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.5%

        \[\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.5%

      \[\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. +-commutativeN/A

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

    if 3.60000000000000009 < 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.f6498.5%

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

      \[\leadsto \color{blue}{\sqrt{x}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification99.1%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 3.6:\\ \;\;\;\;\frac{x}{\left(2 + \frac{x}{2}\right) + x \cdot \left(x \cdot \left(-0.125 + x \cdot 0.0625\right)\right)}\\ \mathbf{else}:\\ \;\;\;\;\sqrt{x}\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 68.1% 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.7%

    \[\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-*.f6466.5%

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

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

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

Alternative 6: 67.9% 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.7%

    \[\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-*.f6466.5%

      \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, x\right), 2\right)\right) \]
  5. Simplified66.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. +-lowering-+.f64N/A

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

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

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

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

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

    \[\leadsto \color{blue}{\frac{1}{\frac{\frac{x}{2} + 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-/.f6466.3%

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

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

Alternative 7: 67.3% 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.7%

    \[\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. Simplified65.6%

      \[\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.7%

      \[\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-*.f6466.5%

        \[\leadsto \mathsf{/.f64}\left(x, \mathsf{+.f64}\left(\mathsf{*.f64}\left(\frac{1}{2}, x\right), 2\right)\right) \]
    5. Simplified66.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.7%

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

      Reproduce

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