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

Percentage Accurate: 99.7% → 99.7%
Time: 10.7s
Alternatives: 10
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 10 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.7%

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

Alternative 2: 99.7% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{x + 1}\\ \mathbf{if}\;\frac{x}{1 + t\_0} \leq 4 \cdot 10^{-6}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(x, 0.0625, -0.125\right), x \cdot x, x \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0 + -1\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (sqrt (+ x 1.0))))
   (if (<= (/ x (+ 1.0 t_0)) 4e-6)
     (fma (fma x 0.0625 -0.125) (* x x) (* x 0.5))
     (+ t_0 -1.0))))
double code(double x) {
	double t_0 = sqrt((x + 1.0));
	double tmp;
	if ((x / (1.0 + t_0)) <= 4e-6) {
		tmp = fma(fma(x, 0.0625, -0.125), (x * x), (x * 0.5));
	} else {
		tmp = t_0 + -1.0;
	}
	return tmp;
}
function code(x)
	t_0 = sqrt(Float64(x + 1.0))
	tmp = 0.0
	if (Float64(x / Float64(1.0 + t_0)) <= 4e-6)
		tmp = fma(fma(x, 0.0625, -0.125), Float64(x * x), Float64(x * 0.5));
	else
		tmp = Float64(t_0 + -1.0);
	end
	return tmp
end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(x / N[(1.0 + t$95$0), $MachinePrecision]), $MachinePrecision], 4e-6], N[(N[(x * 0.0625 + -0.125), $MachinePrecision] * N[(x * x), $MachinePrecision] + N[(x * 0.5), $MachinePrecision]), $MachinePrecision], N[(t$95$0 + -1.0), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sqrt{x + 1}\\
\mathbf{if}\;\frac{x}{1 + t\_0} \leq 4 \cdot 10^{-6}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(x, 0.0625, -0.125\right), x \cdot x, x \cdot 0.5\right)\\

\mathbf{else}:\\
\;\;\;\;t\_0 + -1\\


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

    1. Initial program 100.0%

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

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

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

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

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

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

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

        \[\leadsto x \cdot \mathsf{fma}\left(x, x \cdot \frac{1}{16} + \color{blue}{\frac{-1}{8}}, \frac{1}{2}\right) \]
      7. lower-fma.f6499.6

        \[\leadsto x \cdot \mathsf{fma}\left(x, \color{blue}{\mathsf{fma}\left(x, 0.0625, -0.125\right)}, 0.5\right) \]
    5. Simplified99.6%

      \[\leadsto \color{blue}{x \cdot \mathsf{fma}\left(x, \mathsf{fma}\left(x, 0.0625, -0.125\right), 0.5\right)} \]
    6. Step-by-step derivation
      1. lift-fma.f64N/A

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

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

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

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

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

        \[\leadsto \color{blue}{\mathsf{fma}\left(\mathsf{fma}\left(x, \frac{1}{16}, \frac{-1}{8}\right), x \cdot x, \frac{1}{2} \cdot x\right)} \]
      7. lower-*.f6499.6

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(x, 0.0625, -0.125\right), \color{blue}{x \cdot x}, 0.5 \cdot x\right) \]
      8. lift-*.f64N/A

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

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(x, \frac{1}{16}, \frac{-1}{8}\right), x \cdot x, \color{blue}{x \cdot \frac{1}{2}}\right) \]
      10. lower-*.f6499.6

        \[\leadsto \mathsf{fma}\left(\mathsf{fma}\left(x, 0.0625, -0.125\right), x \cdot x, \color{blue}{x \cdot 0.5}\right) \]
    7. Applied egg-rr99.6%

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

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

    1. Initial program 99.3%

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

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

        \[\leadsto \frac{x}{1 + \color{blue}{\sqrt{x + 1}}} \]
      3. lift-+.f64N/A

        \[\leadsto \frac{x}{\color{blue}{1 + \sqrt{x + 1}}} \]
      4. frac-2negN/A

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{neg}\left(\color{blue}{\left(1 - \sqrt{x + 1}\right)}\right) \]
      17. lower-neg.f64N/A

        \[\leadsto \color{blue}{\mathsf{neg}\left(\left(1 - \sqrt{x + 1}\right)\right)} \]
      18. lower--.f6499.8

        \[\leadsto -\color{blue}{\left(1 - \sqrt{x + 1}\right)} \]
    4. Applied egg-rr99.8%

      \[\leadsto \color{blue}{-\left(1 - \sqrt{x + 1}\right)} \]
    5. Step-by-step derivation
      1. lift-+.f64N/A

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

        \[\leadsto \mathsf{neg}\left(\left(1 - \color{blue}{\sqrt{x + 1}}\right)\right) \]
      3. sub-negN/A

        \[\leadsto \mathsf{neg}\left(\color{blue}{\left(1 + \left(\mathsf{neg}\left(\sqrt{x + 1}\right)\right)\right)}\right) \]
      4. distribute-neg-inN/A

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

        \[\leadsto \color{blue}{-1} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\sqrt{x + 1}\right)\right)\right)\right) \]
      6. remove-double-negN/A

        \[\leadsto -1 + \color{blue}{\sqrt{x + 1}} \]
      7. lower-+.f6499.8

        \[\leadsto \color{blue}{-1 + \sqrt{x + 1}} \]
    6. Applied egg-rr99.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x}{1 + \sqrt{x + 1}} \leq 4 \cdot 10^{-6}:\\ \;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(x, 0.0625, -0.125\right), x \cdot x, x \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{x + 1} + -1\\ \end{array} \]
  5. Add Preprocessing

Alternative 3: 99.7% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{x + 1}\\ \mathbf{if}\;\frac{x}{1 + t\_0} \leq 4 \cdot 10^{-6}:\\ \;\;\;\;x \cdot \mathsf{fma}\left(x, \mathsf{fma}\left(x, 0.0625, -0.125\right), 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0 + -1\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (sqrt (+ x 1.0))))
   (if (<= (/ x (+ 1.0 t_0)) 4e-6)
     (* x (fma x (fma x 0.0625 -0.125) 0.5))
     (+ t_0 -1.0))))
double code(double x) {
	double t_0 = sqrt((x + 1.0));
	double tmp;
	if ((x / (1.0 + t_0)) <= 4e-6) {
		tmp = x * fma(x, fma(x, 0.0625, -0.125), 0.5);
	} else {
		tmp = t_0 + -1.0;
	}
	return tmp;
}
function code(x)
	t_0 = sqrt(Float64(x + 1.0))
	tmp = 0.0
	if (Float64(x / Float64(1.0 + t_0)) <= 4e-6)
		tmp = Float64(x * fma(x, fma(x, 0.0625, -0.125), 0.5));
	else
		tmp = Float64(t_0 + -1.0);
	end
	return tmp
end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(x / N[(1.0 + t$95$0), $MachinePrecision]), $MachinePrecision], 4e-6], N[(x * N[(x * N[(x * 0.0625 + -0.125), $MachinePrecision] + 0.5), $MachinePrecision]), $MachinePrecision], N[(t$95$0 + -1.0), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sqrt{x + 1}\\
\mathbf{if}\;\frac{x}{1 + t\_0} \leq 4 \cdot 10^{-6}:\\
\;\;\;\;x \cdot \mathsf{fma}\left(x, \mathsf{fma}\left(x, 0.0625, -0.125\right), 0.5\right)\\

\mathbf{else}:\\
\;\;\;\;t\_0 + -1\\


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

    1. Initial program 100.0%

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

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

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

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

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

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

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

        \[\leadsto x \cdot \mathsf{fma}\left(x, x \cdot \frac{1}{16} + \color{blue}{\frac{-1}{8}}, \frac{1}{2}\right) \]
      7. lower-fma.f6499.6

        \[\leadsto x \cdot \mathsf{fma}\left(x, \color{blue}{\mathsf{fma}\left(x, 0.0625, -0.125\right)}, 0.5\right) \]
    5. Simplified99.6%

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

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

    1. Initial program 99.3%

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

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

        \[\leadsto \frac{x}{1 + \color{blue}{\sqrt{x + 1}}} \]
      3. lift-+.f64N/A

        \[\leadsto \frac{x}{\color{blue}{1 + \sqrt{x + 1}}} \]
      4. frac-2negN/A

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{neg}\left(\color{blue}{\left(1 - \sqrt{x + 1}\right)}\right) \]
      17. lower-neg.f64N/A

        \[\leadsto \color{blue}{\mathsf{neg}\left(\left(1 - \sqrt{x + 1}\right)\right)} \]
      18. lower--.f6499.8

        \[\leadsto -\color{blue}{\left(1 - \sqrt{x + 1}\right)} \]
    4. Applied egg-rr99.8%

      \[\leadsto \color{blue}{-\left(1 - \sqrt{x + 1}\right)} \]
    5. Step-by-step derivation
      1. lift-+.f64N/A

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

        \[\leadsto \mathsf{neg}\left(\left(1 - \color{blue}{\sqrt{x + 1}}\right)\right) \]
      3. sub-negN/A

        \[\leadsto \mathsf{neg}\left(\color{blue}{\left(1 + \left(\mathsf{neg}\left(\sqrt{x + 1}\right)\right)\right)}\right) \]
      4. distribute-neg-inN/A

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

        \[\leadsto \color{blue}{-1} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\sqrt{x + 1}\right)\right)\right)\right) \]
      6. remove-double-negN/A

        \[\leadsto -1 + \color{blue}{\sqrt{x + 1}} \]
      7. lower-+.f6499.8

        \[\leadsto \color{blue}{-1 + \sqrt{x + 1}} \]
    6. Applied egg-rr99.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x}{1 + \sqrt{x + 1}} \leq 4 \cdot 10^{-6}:\\ \;\;\;\;x \cdot \mathsf{fma}\left(x, \mathsf{fma}\left(x, 0.0625, -0.125\right), 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{x + 1} + -1\\ \end{array} \]
  5. Add Preprocessing

Alternative 4: 99.6% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{x + 1}\\ \mathbf{if}\;\frac{x}{1 + t\_0} \leq 4 \cdot 10^{-6}:\\ \;\;\;\;\mathsf{fma}\left(x \cdot x, -0.125, x \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0 + -1\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (sqrt (+ x 1.0))))
   (if (<= (/ x (+ 1.0 t_0)) 4e-6)
     (fma (* x x) -0.125 (* x 0.5))
     (+ t_0 -1.0))))
double code(double x) {
	double t_0 = sqrt((x + 1.0));
	double tmp;
	if ((x / (1.0 + t_0)) <= 4e-6) {
		tmp = fma((x * x), -0.125, (x * 0.5));
	} else {
		tmp = t_0 + -1.0;
	}
	return tmp;
}
function code(x)
	t_0 = sqrt(Float64(x + 1.0))
	tmp = 0.0
	if (Float64(x / Float64(1.0 + t_0)) <= 4e-6)
		tmp = fma(Float64(x * x), -0.125, Float64(x * 0.5));
	else
		tmp = Float64(t_0 + -1.0);
	end
	return tmp
end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(x / N[(1.0 + t$95$0), $MachinePrecision]), $MachinePrecision], 4e-6], N[(N[(x * x), $MachinePrecision] * -0.125 + N[(x * 0.5), $MachinePrecision]), $MachinePrecision], N[(t$95$0 + -1.0), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sqrt{x + 1}\\
\mathbf{if}\;\frac{x}{1 + t\_0} \leq 4 \cdot 10^{-6}:\\
\;\;\;\;\mathsf{fma}\left(x \cdot x, -0.125, x \cdot 0.5\right)\\

\mathbf{else}:\\
\;\;\;\;t\_0 + -1\\


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

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{x \cdot \left(\frac{1}{2} + \frac{-1}{8} \cdot x\right)} \]
    4. Step-by-step derivation
      1. lower-*.f64N/A

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

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

        \[\leadsto x \cdot \left(\color{blue}{x \cdot \frac{-1}{8}} + \frac{1}{2}\right) \]
      4. lower-fma.f6499.3

        \[\leadsto x \cdot \color{blue}{\mathsf{fma}\left(x, -0.125, 0.5\right)} \]
    5. Simplified99.3%

      \[\leadsto \color{blue}{x \cdot \mathsf{fma}\left(x, -0.125, 0.5\right)} \]
    6. Step-by-step derivation
      1. distribute-lft-inN/A

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

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

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

        \[\leadsto \left(x \cdot x\right) \cdot \frac{-1}{8} + \color{blue}{\frac{1}{2} \cdot x} \]
      5. lower-fma.f64N/A

        \[\leadsto \color{blue}{\mathsf{fma}\left(x \cdot x, \frac{-1}{8}, \frac{1}{2} \cdot x\right)} \]
      6. lower-*.f6499.4

        \[\leadsto \mathsf{fma}\left(\color{blue}{x \cdot x}, -0.125, 0.5 \cdot x\right) \]
      7. lift-*.f64N/A

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

        \[\leadsto \mathsf{fma}\left(x \cdot x, \frac{-1}{8}, \color{blue}{x \cdot \frac{1}{2}}\right) \]
      9. lower-*.f6499.4

        \[\leadsto \mathsf{fma}\left(x \cdot x, -0.125, \color{blue}{x \cdot 0.5}\right) \]
    7. Applied egg-rr99.4%

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

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

    1. Initial program 99.3%

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

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

        \[\leadsto \frac{x}{1 + \color{blue}{\sqrt{x + 1}}} \]
      3. lift-+.f64N/A

        \[\leadsto \frac{x}{\color{blue}{1 + \sqrt{x + 1}}} \]
      4. frac-2negN/A

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{neg}\left(\color{blue}{\left(1 - \sqrt{x + 1}\right)}\right) \]
      17. lower-neg.f64N/A

        \[\leadsto \color{blue}{\mathsf{neg}\left(\left(1 - \sqrt{x + 1}\right)\right)} \]
      18. lower--.f6499.8

        \[\leadsto -\color{blue}{\left(1 - \sqrt{x + 1}\right)} \]
    4. Applied egg-rr99.8%

      \[\leadsto \color{blue}{-\left(1 - \sqrt{x + 1}\right)} \]
    5. Step-by-step derivation
      1. lift-+.f64N/A

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

        \[\leadsto \mathsf{neg}\left(\left(1 - \color{blue}{\sqrt{x + 1}}\right)\right) \]
      3. sub-negN/A

        \[\leadsto \mathsf{neg}\left(\color{blue}{\left(1 + \left(\mathsf{neg}\left(\sqrt{x + 1}\right)\right)\right)}\right) \]
      4. distribute-neg-inN/A

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

        \[\leadsto \color{blue}{-1} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\sqrt{x + 1}\right)\right)\right)\right) \]
      6. remove-double-negN/A

        \[\leadsto -1 + \color{blue}{\sqrt{x + 1}} \]
      7. lower-+.f6499.8

        \[\leadsto \color{blue}{-1 + \sqrt{x + 1}} \]
    6. Applied egg-rr99.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x}{1 + \sqrt{x + 1}} \leq 4 \cdot 10^{-6}:\\ \;\;\;\;\mathsf{fma}\left(x \cdot x, -0.125, x \cdot 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{x + 1} + -1\\ \end{array} \]
  5. Add Preprocessing

Alternative 5: 99.6% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{x + 1}\\ \mathbf{if}\;\frac{x}{1 + t\_0} \leq 4 \cdot 10^{-6}:\\ \;\;\;\;x \cdot \mathsf{fma}\left(x, -0.125, 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;t\_0 + -1\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (sqrt (+ x 1.0))))
   (if (<= (/ x (+ 1.0 t_0)) 4e-6) (* x (fma x -0.125 0.5)) (+ t_0 -1.0))))
double code(double x) {
	double t_0 = sqrt((x + 1.0));
	double tmp;
	if ((x / (1.0 + t_0)) <= 4e-6) {
		tmp = x * fma(x, -0.125, 0.5);
	} else {
		tmp = t_0 + -1.0;
	}
	return tmp;
}
function code(x)
	t_0 = sqrt(Float64(x + 1.0))
	tmp = 0.0
	if (Float64(x / Float64(1.0 + t_0)) <= 4e-6)
		tmp = Float64(x * fma(x, -0.125, 0.5));
	else
		tmp = Float64(t_0 + -1.0);
	end
	return tmp
end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(x / N[(1.0 + t$95$0), $MachinePrecision]), $MachinePrecision], 4e-6], N[(x * N[(x * -0.125 + 0.5), $MachinePrecision]), $MachinePrecision], N[(t$95$0 + -1.0), $MachinePrecision]]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sqrt{x + 1}\\
\mathbf{if}\;\frac{x}{1 + t\_0} \leq 4 \cdot 10^{-6}:\\
\;\;\;\;x \cdot \mathsf{fma}\left(x, -0.125, 0.5\right)\\

\mathbf{else}:\\
\;\;\;\;t\_0 + -1\\


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

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{x \cdot \left(\frac{1}{2} + \frac{-1}{8} \cdot x\right)} \]
    4. Step-by-step derivation
      1. lower-*.f64N/A

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

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

        \[\leadsto x \cdot \left(\color{blue}{x \cdot \frac{-1}{8}} + \frac{1}{2}\right) \]
      4. lower-fma.f6499.3

        \[\leadsto x \cdot \color{blue}{\mathsf{fma}\left(x, -0.125, 0.5\right)} \]
    5. Simplified99.3%

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

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

    1. Initial program 99.3%

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

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

        \[\leadsto \frac{x}{1 + \color{blue}{\sqrt{x + 1}}} \]
      3. lift-+.f64N/A

        \[\leadsto \frac{x}{\color{blue}{1 + \sqrt{x + 1}}} \]
      4. frac-2negN/A

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

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

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

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

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

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

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

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

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

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

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

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

        \[\leadsto \mathsf{neg}\left(\color{blue}{\left(1 - \sqrt{x + 1}\right)}\right) \]
      17. lower-neg.f64N/A

        \[\leadsto \color{blue}{\mathsf{neg}\left(\left(1 - \sqrt{x + 1}\right)\right)} \]
      18. lower--.f6499.8

        \[\leadsto -\color{blue}{\left(1 - \sqrt{x + 1}\right)} \]
    4. Applied egg-rr99.8%

      \[\leadsto \color{blue}{-\left(1 - \sqrt{x + 1}\right)} \]
    5. Step-by-step derivation
      1. lift-+.f64N/A

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

        \[\leadsto \mathsf{neg}\left(\left(1 - \color{blue}{\sqrt{x + 1}}\right)\right) \]
      3. sub-negN/A

        \[\leadsto \mathsf{neg}\left(\color{blue}{\left(1 + \left(\mathsf{neg}\left(\sqrt{x + 1}\right)\right)\right)}\right) \]
      4. distribute-neg-inN/A

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

        \[\leadsto \color{blue}{-1} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\sqrt{x + 1}\right)\right)\right)\right) \]
      6. remove-double-negN/A

        \[\leadsto -1 + \color{blue}{\sqrt{x + 1}} \]
      7. lower-+.f6499.8

        \[\leadsto \color{blue}{-1 + \sqrt{x + 1}} \]
    6. Applied egg-rr99.8%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x}{1 + \sqrt{x + 1}} \leq 4 \cdot 10^{-6}:\\ \;\;\;\;x \cdot \mathsf{fma}\left(x, -0.125, 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{x + 1} + -1\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 98.7% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{x}{1 + \sqrt{x + 1}} \leq 0.2:\\ \;\;\;\;x \cdot \mathsf{fma}\left(x, -0.125, 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;-1 + \sqrt{x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= (/ x (+ 1.0 (sqrt (+ x 1.0)))) 0.2)
   (* x (fma x -0.125 0.5))
   (+ -1.0 (sqrt x))))
double code(double x) {
	double tmp;
	if ((x / (1.0 + sqrt((x + 1.0)))) <= 0.2) {
		tmp = x * fma(x, -0.125, 0.5);
	} else {
		tmp = -1.0 + sqrt(x);
	}
	return tmp;
}
function code(x)
	tmp = 0.0
	if (Float64(x / Float64(1.0 + sqrt(Float64(x + 1.0)))) <= 0.2)
		tmp = Float64(x * fma(x, -0.125, 0.5));
	else
		tmp = Float64(-1.0 + sqrt(x));
	end
	return tmp
end
code[x_] := If[LessEqual[N[(x / N[(1.0 + N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.2], N[(x * N[(x * -0.125 + 0.5), $MachinePrecision]), $MachinePrecision], N[(-1.0 + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{1 + \sqrt{x + 1}} \leq 0.2:\\
\;\;\;\;x \cdot \mathsf{fma}\left(x, -0.125, 0.5\right)\\

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


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

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{x \cdot \left(\frac{1}{2} + \frac{-1}{8} \cdot x\right)} \]
    4. Step-by-step derivation
      1. lower-*.f64N/A

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

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

        \[\leadsto x \cdot \left(\color{blue}{x \cdot \frac{-1}{8}} + \frac{1}{2}\right) \]
      4. lower-fma.f6498.6

        \[\leadsto x \cdot \color{blue}{\mathsf{fma}\left(x, -0.125, 0.5\right)} \]
    5. Simplified98.6%

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

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

    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 \color{blue}{\sqrt{x} + \left(\mathsf{neg}\left(1\right)\right)} \]
      2. metadata-evalN/A

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

        \[\leadsto \color{blue}{\sqrt{x} + -1} \]
      4. lower-sqrt.f6497.7

        \[\leadsto \color{blue}{\sqrt{x}} + -1 \]
    5. Simplified97.7%

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

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

Alternative 7: 98.0% accurate, 0.6× speedup?

\[\begin{array}{l} \\ \begin{array}{l} \mathbf{if}\;\frac{x}{1 + \sqrt{x + 1}} \leq 0.2:\\ \;\;\;\;x \cdot \mathsf{fma}\left(x, -0.125, 0.5\right)\\ \mathbf{else}:\\ \;\;\;\;\sqrt{x}\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (if (<= (/ x (+ 1.0 (sqrt (+ x 1.0)))) 0.2)
   (* x (fma x -0.125 0.5))
   (sqrt x)))
double code(double x) {
	double tmp;
	if ((x / (1.0 + sqrt((x + 1.0)))) <= 0.2) {
		tmp = x * fma(x, -0.125, 0.5);
	} else {
		tmp = sqrt(x);
	}
	return tmp;
}
function code(x)
	tmp = 0.0
	if (Float64(x / Float64(1.0 + sqrt(Float64(x + 1.0)))) <= 0.2)
		tmp = Float64(x * fma(x, -0.125, 0.5));
	else
		tmp = sqrt(x);
	end
	return tmp
end
code[x_] := If[LessEqual[N[(x / N[(1.0 + N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 0.2], N[(x * N[(x * -0.125 + 0.5), $MachinePrecision]), $MachinePrecision], N[Sqrt[x], $MachinePrecision]]
\begin{array}{l}

\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{1 + \sqrt{x + 1}} \leq 0.2:\\
\;\;\;\;x \cdot \mathsf{fma}\left(x, -0.125, 0.5\right)\\

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


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

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{x \cdot \left(\frac{1}{2} + \frac{-1}{8} \cdot x\right)} \]
    4. Step-by-step derivation
      1. lower-*.f64N/A

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

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

        \[\leadsto x \cdot \left(\color{blue}{x \cdot \frac{-1}{8}} + \frac{1}{2}\right) \]
      4. lower-fma.f6498.6

        \[\leadsto x \cdot \color{blue}{\mathsf{fma}\left(x, -0.125, 0.5\right)} \]
    5. Simplified98.6%

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

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

    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. lower-sqrt.f6494.9

        \[\leadsto \color{blue}{\sqrt{x}} \]
    5. Simplified94.9%

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

Alternative 8: 97.4% accurate, 0.6× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;\frac{x}{1 + \sqrt{x + 1}} \leq 0.2:\\
\;\;\;\;x \cdot 0.5\\

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


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

    1. Initial program 100.0%

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

      \[\leadsto \color{blue}{\frac{1}{2} \cdot x} \]
    4. Step-by-step derivation
      1. lower-*.f6497.6

        \[\leadsto \color{blue}{0.5 \cdot x} \]
    5. Simplified97.6%

      \[\leadsto \color{blue}{0.5 \cdot x} \]

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

    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. lower-sqrt.f6494.9

        \[\leadsto \color{blue}{\sqrt{x}} \]
    5. Simplified94.9%

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

    \[\leadsto \begin{array}{l} \mathbf{if}\;\frac{x}{1 + \sqrt{x + 1}} \leq 0.2:\\ \;\;\;\;x \cdot 0.5\\ \mathbf{else}:\\ \;\;\;\;\sqrt{x}\\ \end{array} \]
  5. Add Preprocessing

Alternative 9: 68.2% accurate, 4.7× speedup?

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

\\
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 \color{blue}{\frac{1}{2} \cdot x} \]
  4. Step-by-step derivation
    1. lower-*.f6467.9

      \[\leadsto \color{blue}{0.5 \cdot x} \]
  5. Simplified67.9%

    \[\leadsto \color{blue}{0.5 \cdot x} \]
  6. Final simplification67.9%

    \[\leadsto x \cdot 0.5 \]
  7. Add Preprocessing

Alternative 10: 4.5% accurate, 28.0× speedup?

\[\begin{array}{l} \\ 0 \end{array} \]
(FPCore (x) :precision binary64 0.0)
double code(double x) {
	return 0.0;
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = 0.0d0
end function
public static double code(double x) {
	return 0.0;
}
def code(x):
	return 0.0
function code(x)
	return 0.0
end
function tmp = code(x)
	tmp = 0.0;
end
code[x_] := 0.0
\begin{array}{l}

\\
0
\end{array}
Derivation
  1. Initial program 99.7%

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

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

      \[\leadsto \frac{x}{1 + \color{blue}{\sqrt{x + 1}}} \]
    3. lift-+.f64N/A

      \[\leadsto \frac{x}{\color{blue}{1 + \sqrt{x + 1}}} \]
    4. frac-2negN/A

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

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

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

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

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

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

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

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

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

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

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

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

      \[\leadsto \mathsf{neg}\left(\color{blue}{\left(1 - \sqrt{x + 1}\right)}\right) \]
    17. lower-neg.f64N/A

      \[\leadsto \color{blue}{\mathsf{neg}\left(\left(1 - \sqrt{x + 1}\right)\right)} \]
    18. lower--.f6438.7

      \[\leadsto -\color{blue}{\left(1 - \sqrt{x + 1}\right)} \]
  4. Applied egg-rr38.7%

    \[\leadsto \color{blue}{-\left(1 - \sqrt{x + 1}\right)} \]
  5. Step-by-step derivation
    1. lift-+.f64N/A

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

      \[\leadsto \mathsf{neg}\left(\left(1 - \color{blue}{\sqrt{x + 1}}\right)\right) \]
    3. sub-negN/A

      \[\leadsto \mathsf{neg}\left(\color{blue}{\left(1 + \left(\mathsf{neg}\left(\sqrt{x + 1}\right)\right)\right)}\right) \]
    4. distribute-neg-inN/A

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

      \[\leadsto \color{blue}{-1} + \left(\mathsf{neg}\left(\left(\mathsf{neg}\left(\sqrt{x + 1}\right)\right)\right)\right) \]
    6. remove-double-negN/A

      \[\leadsto -1 + \color{blue}{\sqrt{x + 1}} \]
    7. lower-+.f6438.7

      \[\leadsto \color{blue}{-1 + \sqrt{x + 1}} \]
  6. Applied egg-rr38.7%

    \[\leadsto \color{blue}{-1 + \sqrt{x + 1}} \]
  7. Taylor expanded in x around 0

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

      \[\leadsto -1 + \color{blue}{1} \]
    2. Step-by-step derivation
      1. metadata-eval4.6

        \[\leadsto \color{blue}{0} \]
    3. Applied egg-rr4.6%

      \[\leadsto \color{blue}{0} \]
    4. Add Preprocessing

    Reproduce

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