Main:bigenough3 from C

Percentage Accurate: 51.7% → 99.7%
Time: 9.1s
Alternatives: 6
Speedup: 1.9×

Specification

?
\[\begin{array}{l} \\ \sqrt{x + 1} - \sqrt{x} \end{array} \]
(FPCore (x) :precision binary64 (- (sqrt (+ x 1.0)) (sqrt x)))
double code(double x) {
	return sqrt((x + 1.0)) - sqrt(x);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = sqrt((x + 1.0d0)) - sqrt(x)
end function
public static double code(double x) {
	return Math.sqrt((x + 1.0)) - Math.sqrt(x);
}
def code(x):
	return math.sqrt((x + 1.0)) - math.sqrt(x)
function code(x)
	return Float64(sqrt(Float64(x + 1.0)) - sqrt(x))
end
function tmp = code(x)
	tmp = sqrt((x + 1.0)) - sqrt(x);
end
code[x_] := N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

\\
\sqrt{x + 1} - \sqrt{x}
\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 6 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: 51.7% accurate, 1.0× speedup?

\[\begin{array}{l} \\ \sqrt{x + 1} - \sqrt{x} \end{array} \]
(FPCore (x) :precision binary64 (- (sqrt (+ x 1.0)) (sqrt x)))
double code(double x) {
	return sqrt((x + 1.0)) - sqrt(x);
}
real(8) function code(x)
    real(8), intent (in) :: x
    code = sqrt((x + 1.0d0)) - sqrt(x)
end function
public static double code(double x) {
	return Math.sqrt((x + 1.0)) - Math.sqrt(x);
}
def code(x):
	return math.sqrt((x + 1.0)) - math.sqrt(x)
function code(x)
	return Float64(sqrt(Float64(x + 1.0)) - sqrt(x))
end
function tmp = code(x)
	tmp = sqrt((x + 1.0)) - sqrt(x);
end
code[x_] := N[(N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}

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

Alternative 1: 99.7% accurate, 1.0× speedup?

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

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

    \[\sqrt{x + 1} - \sqrt{x} \]
  2. Add Preprocessing
  3. Step-by-step derivation
    1. flip--57.2%

      \[\leadsto \color{blue}{\frac{\sqrt{x + 1} \cdot \sqrt{x + 1} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{x + 1} + \sqrt{x}}} \]
    2. div-inv57.2%

      \[\leadsto \color{blue}{\left(\sqrt{x + 1} \cdot \sqrt{x + 1} - \sqrt{x} \cdot \sqrt{x}\right) \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}}} \]
    3. add-sqr-sqrt57.5%

      \[\leadsto \left(\color{blue}{\left(x + 1\right)} - \sqrt{x} \cdot \sqrt{x}\right) \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}} \]
    4. add-sqr-sqrt58.2%

      \[\leadsto \left(\left(x + 1\right) - \color{blue}{x}\right) \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}} \]
    5. associate--l+58.3%

      \[\leadsto \color{blue}{\left(x + \left(1 - x\right)\right)} \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}} \]
  4. Applied egg-rr58.3%

    \[\leadsto \color{blue}{\left(x + \left(1 - x\right)\right) \cdot \frac{1}{\sqrt{x + 1} + \sqrt{x}}} \]
  5. Step-by-step derivation
    1. associate-*r/58.3%

      \[\leadsto \color{blue}{\frac{\left(x + \left(1 - x\right)\right) \cdot 1}{\sqrt{x + 1} + \sqrt{x}}} \]
    2. *-rgt-identity58.3%

      \[\leadsto \frac{\color{blue}{x + \left(1 - x\right)}}{\sqrt{x + 1} + \sqrt{x}} \]
    3. +-commutative58.3%

      \[\leadsto \frac{\color{blue}{\left(1 - x\right) + x}}{\sqrt{x + 1} + \sqrt{x}} \]
    4. associate-+l-99.7%

      \[\leadsto \frac{\color{blue}{1 - \left(x - x\right)}}{\sqrt{x + 1} + \sqrt{x}} \]
    5. +-inverses99.7%

      \[\leadsto \frac{1 - \color{blue}{0}}{\sqrt{x + 1} + \sqrt{x}} \]
    6. metadata-eval99.7%

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

      \[\leadsto \frac{1}{\sqrt{\color{blue}{1 + x}} + \sqrt{x}} \]
  6. Simplified99.7%

    \[\leadsto \color{blue}{\frac{1}{\sqrt{1 + x} + \sqrt{x}}} \]
  7. Final simplification99.7%

    \[\leadsto \frac{1}{\sqrt{1 + x} + \sqrt{x}} \]
  8. Add Preprocessing

Alternative 2: 99.5% accurate, 0.5× speedup?

\[\begin{array}{l} \\ \begin{array}{l} t_0 := \sqrt{1 + x} - \sqrt{x}\\ \mathbf{if}\;t\_0 \leq 4 \cdot 10^{-5}:\\ \;\;\;\;0.5 \cdot {x}^{-0.5}\\ \mathbf{else}:\\ \;\;\;\;t\_0\\ \end{array} \end{array} \]
(FPCore (x)
 :precision binary64
 (let* ((t_0 (- (sqrt (+ 1.0 x)) (sqrt x))))
   (if (<= t_0 4e-5) (* 0.5 (pow x -0.5)) t_0)))
double code(double x) {
	double t_0 = sqrt((1.0 + x)) - sqrt(x);
	double tmp;
	if (t_0 <= 4e-5) {
		tmp = 0.5 * pow(x, -0.5);
	} else {
		tmp = t_0;
	}
	return tmp;
}
real(8) function code(x)
    real(8), intent (in) :: x
    real(8) :: t_0
    real(8) :: tmp
    t_0 = sqrt((1.0d0 + x)) - sqrt(x)
    if (t_0 <= 4d-5) then
        tmp = 0.5d0 * (x ** (-0.5d0))
    else
        tmp = t_0
    end if
    code = tmp
end function
public static double code(double x) {
	double t_0 = Math.sqrt((1.0 + x)) - Math.sqrt(x);
	double tmp;
	if (t_0 <= 4e-5) {
		tmp = 0.5 * Math.pow(x, -0.5);
	} else {
		tmp = t_0;
	}
	return tmp;
}
def code(x):
	t_0 = math.sqrt((1.0 + x)) - math.sqrt(x)
	tmp = 0
	if t_0 <= 4e-5:
		tmp = 0.5 * math.pow(x, -0.5)
	else:
		tmp = t_0
	return tmp
function code(x)
	t_0 = Float64(sqrt(Float64(1.0 + x)) - sqrt(x))
	tmp = 0.0
	if (t_0 <= 4e-5)
		tmp = Float64(0.5 * (x ^ -0.5));
	else
		tmp = t_0;
	end
	return tmp
end
function tmp_2 = code(x)
	t_0 = sqrt((1.0 + x)) - sqrt(x);
	tmp = 0.0;
	if (t_0 <= 4e-5)
		tmp = 0.5 * (x ^ -0.5);
	else
		tmp = t_0;
	end
	tmp_2 = tmp;
end
code[x_] := Block[{t$95$0 = N[(N[Sqrt[N[(1.0 + x), $MachinePrecision]], $MachinePrecision] - N[Sqrt[x], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[t$95$0, 4e-5], N[(0.5 * N[Power[x, -0.5], $MachinePrecision]), $MachinePrecision], t$95$0]]
\begin{array}{l}

\\
\begin{array}{l}
t_0 := \sqrt{1 + x} - \sqrt{x}\\
\mathbf{if}\;t\_0 \leq 4 \cdot 10^{-5}:\\
\;\;\;\;0.5 \cdot {x}^{-0.5}\\

\mathbf{else}:\\
\;\;\;\;t\_0\\


\end{array}
\end{array}
Derivation
  1. Split input into 2 regimes
  2. if (-.f64 (sqrt.f64 (+.f64 x 1)) (sqrt.f64 x)) < 4.00000000000000033e-5

    1. Initial program 5.4%

      \[\sqrt{x + 1} - \sqrt{x} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. expm1-log1p-u5.4%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{x + 1} - \sqrt{x}\right)\right)} \]
    4. Applied egg-rr5.4%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{x + 1} - \sqrt{x}\right)\right)} \]
    5. Step-by-step derivation
      1. expm1-log1p-u5.4%

        \[\leadsto \color{blue}{\sqrt{x + 1} - \sqrt{x}} \]
      2. +-commutative5.4%

        \[\leadsto \sqrt{\color{blue}{1 + x}} - \sqrt{x} \]
      3. flip--6.0%

        \[\leadsto \color{blue}{\frac{\sqrt{1 + x} \cdot \sqrt{1 + x} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{1 + x} + \sqrt{x}}} \]
      4. flip3-+6.0%

        \[\leadsto \frac{\sqrt{1 + x} \cdot \sqrt{1 + x} - \sqrt{x} \cdot \sqrt{x}}{\color{blue}{\frac{{\left(\sqrt{1 + x}\right)}^{3} + {\left(\sqrt{x}\right)}^{3}}{\sqrt{1 + x} \cdot \sqrt{1 + x} + \left(\sqrt{x} \cdot \sqrt{x} - \sqrt{1 + x} \cdot \sqrt{x}\right)}}} \]
      5. associate-/r/6.0%

        \[\leadsto \color{blue}{\frac{\sqrt{1 + x} \cdot \sqrt{1 + x} - \sqrt{x} \cdot \sqrt{x}}{{\left(\sqrt{1 + x}\right)}^{3} + {\left(\sqrt{x}\right)}^{3}} \cdot \left(\sqrt{1 + x} \cdot \sqrt{1 + x} + \left(\sqrt{x} \cdot \sqrt{x} - \sqrt{1 + x} \cdot \sqrt{x}\right)\right)} \]
    6. Applied egg-rr5.8%

      \[\leadsto \color{blue}{\frac{x + \left(1 - x\right)}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right)} \]
    7. Step-by-step derivation
      1. +-commutative5.8%

        \[\leadsto \frac{\color{blue}{\left(1 - x\right) + x}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right) \]
      2. associate-+l-46.4%

        \[\leadsto \frac{\color{blue}{1 - \left(x - x\right)}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right) \]
      3. +-inverses46.4%

        \[\leadsto \frac{1 - \color{blue}{0}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right) \]
      4. metadata-eval46.4%

        \[\leadsto \frac{\color{blue}{1}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right) \]
      5. associate-*l/46.4%

        \[\leadsto \color{blue}{\frac{1 \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right)}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}}} \]
      6. *-lft-identity46.4%

        \[\leadsto \frac{\color{blue}{\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \]
      7. associate-+l+46.4%

        \[\leadsto \frac{\color{blue}{\left(x + \left(1 + x\right)\right)} - \sqrt{\left(x + 1\right) \cdot x}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \]
      8. *-commutative46.4%

        \[\leadsto \frac{\left(x + \left(1 + x\right)\right) - \sqrt{\color{blue}{x \cdot \left(x + 1\right)}}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \]
      9. +-commutative46.4%

        \[\leadsto \frac{\left(x + \left(1 + x\right)\right) - \sqrt{x \cdot \color{blue}{\left(1 + x\right)}}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \]
      10. +-commutative46.4%

        \[\leadsto \frac{\left(x + \left(1 + x\right)\right) - \sqrt{x \cdot \left(1 + x\right)}}{{\color{blue}{\left(1 + x\right)}}^{1.5} + {x}^{1.5}} \]
    8. Simplified46.4%

      \[\leadsto \color{blue}{\frac{\left(x + \left(1 + x\right)\right) - \sqrt{x \cdot \left(1 + x\right)}}{{\left(1 + x\right)}^{1.5} + {x}^{1.5}}} \]
    9. Taylor expanded in x around inf 61.8%

      \[\leadsto \frac{\color{blue}{0.5 + \left(x + 0.125 \cdot \frac{1}{x}\right)}}{{\left(1 + x\right)}^{1.5} + {x}^{1.5}} \]
    10. Step-by-step derivation
      1. associate-+r+61.8%

        \[\leadsto \frac{\color{blue}{\left(0.5 + x\right) + 0.125 \cdot \frac{1}{x}}}{{\left(1 + x\right)}^{1.5} + {x}^{1.5}} \]
      2. +-commutative61.8%

        \[\leadsto \frac{\color{blue}{\left(x + 0.5\right)} + 0.125 \cdot \frac{1}{x}}{{\left(1 + x\right)}^{1.5} + {x}^{1.5}} \]
      3. associate-*r/61.8%

        \[\leadsto \frac{\left(x + 0.5\right) + \color{blue}{\frac{0.125 \cdot 1}{x}}}{{\left(1 + x\right)}^{1.5} + {x}^{1.5}} \]
      4. metadata-eval61.8%

        \[\leadsto \frac{\left(x + 0.5\right) + \frac{\color{blue}{0.125}}{x}}{{\left(1 + x\right)}^{1.5} + {x}^{1.5}} \]
    11. Simplified61.8%

      \[\leadsto \frac{\color{blue}{\left(x + 0.5\right) + \frac{0.125}{x}}}{{\left(1 + x\right)}^{1.5} + {x}^{1.5}} \]
    12. Taylor expanded in x around inf 99.2%

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{\frac{1}{x}}} \]
    13. Step-by-step derivation
      1. unpow-199.2%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{{x}^{-1}}} \]
      2. sqr-pow99.3%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{{x}^{\left(\frac{-1}{2}\right)} \cdot {x}^{\left(\frac{-1}{2}\right)}}} \]
      3. metadata-eval99.3%

        \[\leadsto 0.5 \cdot \sqrt{{x}^{\color{blue}{-0.5}} \cdot {x}^{\left(\frac{-1}{2}\right)}} \]
      4. metadata-eval99.3%

        \[\leadsto 0.5 \cdot \sqrt{{x}^{-0.5} \cdot {x}^{\color{blue}{-0.5}}} \]
      5. rem-sqrt-square99.3%

        \[\leadsto 0.5 \cdot \color{blue}{\left|{x}^{-0.5}\right|} \]
      6. rem-square-sqrt98.5%

        \[\leadsto 0.5 \cdot \left|\color{blue}{\sqrt{{x}^{-0.5}} \cdot \sqrt{{x}^{-0.5}}}\right| \]
      7. fabs-sqr98.5%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\sqrt{{x}^{-0.5}} \cdot \sqrt{{x}^{-0.5}}\right)} \]
      8. rem-square-sqrt99.3%

        \[\leadsto 0.5 \cdot \color{blue}{{x}^{-0.5}} \]
    14. Simplified99.3%

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

    if 4.00000000000000033e-5 < (-.f64 (sqrt.f64 (+.f64 x 1)) (sqrt.f64 x))

    1. Initial program 99.4%

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

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

Alternative 3: 96.8% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.38:\\
\;\;\;\;\frac{1}{1 + \left(1 + \left({x}^{1.5} + -1\right)\right)}\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot {x}^{-0.5}\\


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

    1. Initial program 99.9%

      \[\sqrt{x + 1} - \sqrt{x} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. expm1-log1p-u99.9%

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

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{x + 1} - \sqrt{x}\right)\right)} \]
    5. Step-by-step derivation
      1. expm1-log1p-u99.9%

        \[\leadsto \color{blue}{\sqrt{x + 1} - \sqrt{x}} \]
      2. +-commutative99.9%

        \[\leadsto \sqrt{\color{blue}{1 + x}} - \sqrt{x} \]
      3. flip--99.9%

        \[\leadsto \color{blue}{\frac{\sqrt{1 + x} \cdot \sqrt{1 + x} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{1 + x} + \sqrt{x}}} \]
      4. flip3-+99.8%

        \[\leadsto \frac{\sqrt{1 + x} \cdot \sqrt{1 + x} - \sqrt{x} \cdot \sqrt{x}}{\color{blue}{\frac{{\left(\sqrt{1 + x}\right)}^{3} + {\left(\sqrt{x}\right)}^{3}}{\sqrt{1 + x} \cdot \sqrt{1 + x} + \left(\sqrt{x} \cdot \sqrt{x} - \sqrt{1 + x} \cdot \sqrt{x}\right)}}} \]
      5. associate-/r/99.9%

        \[\leadsto \color{blue}{\frac{\sqrt{1 + x} \cdot \sqrt{1 + x} - \sqrt{x} \cdot \sqrt{x}}{{\left(\sqrt{1 + x}\right)}^{3} + {\left(\sqrt{x}\right)}^{3}} \cdot \left(\sqrt{1 + x} \cdot \sqrt{1 + x} + \left(\sqrt{x} \cdot \sqrt{x} - \sqrt{1 + x} \cdot \sqrt{x}\right)\right)} \]
    6. Applied egg-rr99.9%

      \[\leadsto \color{blue}{\frac{x + \left(1 - x\right)}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right)} \]
    7. Step-by-step derivation
      1. +-commutative99.9%

        \[\leadsto \frac{\color{blue}{\left(1 - x\right) + x}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right) \]
      2. associate-+l-99.9%

        \[\leadsto \frac{\color{blue}{1 - \left(x - x\right)}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right) \]
      3. +-inverses99.9%

        \[\leadsto \frac{1 - \color{blue}{0}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right) \]
      4. metadata-eval99.9%

        \[\leadsto \frac{\color{blue}{1}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right) \]
      5. associate-*l/99.9%

        \[\leadsto \color{blue}{\frac{1 \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right)}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}}} \]
      6. *-lft-identity99.9%

        \[\leadsto \frac{\color{blue}{\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \]
      7. associate-+l+99.9%

        \[\leadsto \frac{\color{blue}{\left(x + \left(1 + x\right)\right)} - \sqrt{\left(x + 1\right) \cdot x}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \]
      8. *-commutative99.9%

        \[\leadsto \frac{\left(x + \left(1 + x\right)\right) - \sqrt{\color{blue}{x \cdot \left(x + 1\right)}}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \]
      9. +-commutative99.9%

        \[\leadsto \frac{\left(x + \left(1 + x\right)\right) - \sqrt{x \cdot \color{blue}{\left(1 + x\right)}}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \]
      10. +-commutative99.9%

        \[\leadsto \frac{\left(x + \left(1 + x\right)\right) - \sqrt{x \cdot \left(1 + x\right)}}{{\color{blue}{\left(1 + x\right)}}^{1.5} + {x}^{1.5}} \]
    8. Simplified99.9%

      \[\leadsto \color{blue}{\frac{\left(x + \left(1 + x\right)\right) - \sqrt{x \cdot \left(1 + x\right)}}{{\left(1 + x\right)}^{1.5} + {x}^{1.5}}} \]
    9. Taylor expanded in x around 0 94.6%

      \[\leadsto \color{blue}{\frac{1}{1 + {x}^{1.5}}} \]
    10. Step-by-step derivation
      1. expm1-log1p-u94.6%

        \[\leadsto \frac{1}{1 + \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left({x}^{1.5}\right)\right)}} \]
      2. log1p-define94.6%

        \[\leadsto \frac{1}{1 + \mathsf{expm1}\left(\color{blue}{\log \left(1 + {x}^{1.5}\right)}\right)} \]
      3. expm1-undefine94.6%

        \[\leadsto \frac{1}{1 + \color{blue}{\left(e^{\log \left(1 + {x}^{1.5}\right)} - 1\right)}} \]
      4. add-exp-log94.6%

        \[\leadsto \frac{1}{1 + \left(\color{blue}{\left(1 + {x}^{1.5}\right)} - 1\right)} \]
    11. Applied egg-rr94.6%

      \[\leadsto \frac{1}{1 + \color{blue}{\left(\left(1 + {x}^{1.5}\right) - 1\right)}} \]
    12. Step-by-step derivation
      1. associate--l+94.6%

        \[\leadsto \frac{1}{1 + \color{blue}{\left(1 + \left({x}^{1.5} - 1\right)\right)}} \]
    13. Simplified94.6%

      \[\leadsto \frac{1}{1 + \color{blue}{\left(1 + \left({x}^{1.5} - 1\right)\right)}} \]

    if 0.38 < x

    1. Initial program 8.7%

      \[\sqrt{x + 1} - \sqrt{x} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. expm1-log1p-u8.7%

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

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{x + 1} - \sqrt{x}\right)\right)} \]
    5. Step-by-step derivation
      1. expm1-log1p-u8.7%

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

        \[\leadsto \sqrt{\color{blue}{1 + x}} - \sqrt{x} \]
      3. flip--9.7%

        \[\leadsto \color{blue}{\frac{\sqrt{1 + x} \cdot \sqrt{1 + x} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{1 + x} + \sqrt{x}}} \]
      4. flip3-+9.7%

        \[\leadsto \frac{\sqrt{1 + x} \cdot \sqrt{1 + x} - \sqrt{x} \cdot \sqrt{x}}{\color{blue}{\frac{{\left(\sqrt{1 + x}\right)}^{3} + {\left(\sqrt{x}\right)}^{3}}{\sqrt{1 + x} \cdot \sqrt{1 + x} + \left(\sqrt{x} \cdot \sqrt{x} - \sqrt{1 + x} \cdot \sqrt{x}\right)}}} \]
      5. associate-/r/9.7%

        \[\leadsto \color{blue}{\frac{\sqrt{1 + x} \cdot \sqrt{1 + x} - \sqrt{x} \cdot \sqrt{x}}{{\left(\sqrt{1 + x}\right)}^{3} + {\left(\sqrt{x}\right)}^{3}} \cdot \left(\sqrt{1 + x} \cdot \sqrt{1 + x} + \left(\sqrt{x} \cdot \sqrt{x} - \sqrt{1 + x} \cdot \sqrt{x}\right)\right)} \]
    6. Applied egg-rr9.7%

      \[\leadsto \color{blue}{\frac{x + \left(1 - x\right)}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right)} \]
    7. Step-by-step derivation
      1. +-commutative9.7%

        \[\leadsto \frac{\color{blue}{\left(1 - x\right) + x}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right) \]
      2. associate-+l-48.6%

        \[\leadsto \frac{\color{blue}{1 - \left(x - x\right)}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right) \]
      3. +-inverses48.6%

        \[\leadsto \frac{1 - \color{blue}{0}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right) \]
      4. metadata-eval48.6%

        \[\leadsto \frac{\color{blue}{1}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right) \]
      5. associate-*l/48.6%

        \[\leadsto \color{blue}{\frac{1 \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right)}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}}} \]
      6. *-lft-identity48.6%

        \[\leadsto \frac{\color{blue}{\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \]
      7. associate-+l+48.6%

        \[\leadsto \frac{\color{blue}{\left(x + \left(1 + x\right)\right)} - \sqrt{\left(x + 1\right) \cdot x}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \]
      8. *-commutative48.6%

        \[\leadsto \frac{\left(x + \left(1 + x\right)\right) - \sqrt{\color{blue}{x \cdot \left(x + 1\right)}}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \]
      9. +-commutative48.6%

        \[\leadsto \frac{\left(x + \left(1 + x\right)\right) - \sqrt{x \cdot \color{blue}{\left(1 + x\right)}}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \]
      10. +-commutative48.6%

        \[\leadsto \frac{\left(x + \left(1 + x\right)\right) - \sqrt{x \cdot \left(1 + x\right)}}{{\color{blue}{\left(1 + x\right)}}^{1.5} + {x}^{1.5}} \]
    8. Simplified48.6%

      \[\leadsto \color{blue}{\frac{\left(x + \left(1 + x\right)\right) - \sqrt{x \cdot \left(1 + x\right)}}{{\left(1 + x\right)}^{1.5} + {x}^{1.5}}} \]
    9. Taylor expanded in x around inf 62.0%

      \[\leadsto \frac{\color{blue}{0.5 + \left(x + 0.125 \cdot \frac{1}{x}\right)}}{{\left(1 + x\right)}^{1.5} + {x}^{1.5}} \]
    10. Step-by-step derivation
      1. associate-+r+62.0%

        \[\leadsto \frac{\color{blue}{\left(0.5 + x\right) + 0.125 \cdot \frac{1}{x}}}{{\left(1 + x\right)}^{1.5} + {x}^{1.5}} \]
      2. +-commutative62.0%

        \[\leadsto \frac{\color{blue}{\left(x + 0.5\right)} + 0.125 \cdot \frac{1}{x}}{{\left(1 + x\right)}^{1.5} + {x}^{1.5}} \]
      3. associate-*r/62.0%

        \[\leadsto \frac{\left(x + 0.5\right) + \color{blue}{\frac{0.125 \cdot 1}{x}}}{{\left(1 + x\right)}^{1.5} + {x}^{1.5}} \]
      4. metadata-eval62.0%

        \[\leadsto \frac{\left(x + 0.5\right) + \frac{\color{blue}{0.125}}{x}}{{\left(1 + x\right)}^{1.5} + {x}^{1.5}} \]
    11. Simplified62.0%

      \[\leadsto \frac{\color{blue}{\left(x + 0.5\right) + \frac{0.125}{x}}}{{\left(1 + x\right)}^{1.5} + {x}^{1.5}} \]
    12. Taylor expanded in x around inf 96.7%

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{\frac{1}{x}}} \]
    13. Step-by-step derivation
      1. unpow-196.7%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{{x}^{-1}}} \]
      2. sqr-pow96.8%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{{x}^{\left(\frac{-1}{2}\right)} \cdot {x}^{\left(\frac{-1}{2}\right)}}} \]
      3. metadata-eval96.8%

        \[\leadsto 0.5 \cdot \sqrt{{x}^{\color{blue}{-0.5}} \cdot {x}^{\left(\frac{-1}{2}\right)}} \]
      4. metadata-eval96.8%

        \[\leadsto 0.5 \cdot \sqrt{{x}^{-0.5} \cdot {x}^{\color{blue}{-0.5}}} \]
      5. rem-sqrt-square96.8%

        \[\leadsto 0.5 \cdot \color{blue}{\left|{x}^{-0.5}\right|} \]
      6. rem-square-sqrt96.1%

        \[\leadsto 0.5 \cdot \left|\color{blue}{\sqrt{{x}^{-0.5}} \cdot \sqrt{{x}^{-0.5}}}\right| \]
      7. fabs-sqr96.1%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\sqrt{{x}^{-0.5}} \cdot \sqrt{{x}^{-0.5}}\right)} \]
      8. rem-square-sqrt96.8%

        \[\leadsto 0.5 \cdot \color{blue}{{x}^{-0.5}} \]
    14. Simplified96.8%

      \[\leadsto \color{blue}{0.5 \cdot {x}^{-0.5}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification95.7%

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

Alternative 4: 96.8% accurate, 1.8× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.38:\\
\;\;\;\;\frac{1}{1 + {x}^{1.5}}\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot {x}^{-0.5}\\


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

    1. Initial program 99.9%

      \[\sqrt{x + 1} - \sqrt{x} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. expm1-log1p-u99.9%

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

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{x + 1} - \sqrt{x}\right)\right)} \]
    5. Step-by-step derivation
      1. expm1-log1p-u99.9%

        \[\leadsto \color{blue}{\sqrt{x + 1} - \sqrt{x}} \]
      2. +-commutative99.9%

        \[\leadsto \sqrt{\color{blue}{1 + x}} - \sqrt{x} \]
      3. flip--99.9%

        \[\leadsto \color{blue}{\frac{\sqrt{1 + x} \cdot \sqrt{1 + x} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{1 + x} + \sqrt{x}}} \]
      4. flip3-+99.8%

        \[\leadsto \frac{\sqrt{1 + x} \cdot \sqrt{1 + x} - \sqrt{x} \cdot \sqrt{x}}{\color{blue}{\frac{{\left(\sqrt{1 + x}\right)}^{3} + {\left(\sqrt{x}\right)}^{3}}{\sqrt{1 + x} \cdot \sqrt{1 + x} + \left(\sqrt{x} \cdot \sqrt{x} - \sqrt{1 + x} \cdot \sqrt{x}\right)}}} \]
      5. associate-/r/99.9%

        \[\leadsto \color{blue}{\frac{\sqrt{1 + x} \cdot \sqrt{1 + x} - \sqrt{x} \cdot \sqrt{x}}{{\left(\sqrt{1 + x}\right)}^{3} + {\left(\sqrt{x}\right)}^{3}} \cdot \left(\sqrt{1 + x} \cdot \sqrt{1 + x} + \left(\sqrt{x} \cdot \sqrt{x} - \sqrt{1 + x} \cdot \sqrt{x}\right)\right)} \]
    6. Applied egg-rr99.9%

      \[\leadsto \color{blue}{\frac{x + \left(1 - x\right)}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right)} \]
    7. Step-by-step derivation
      1. +-commutative99.9%

        \[\leadsto \frac{\color{blue}{\left(1 - x\right) + x}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right) \]
      2. associate-+l-99.9%

        \[\leadsto \frac{\color{blue}{1 - \left(x - x\right)}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right) \]
      3. +-inverses99.9%

        \[\leadsto \frac{1 - \color{blue}{0}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right) \]
      4. metadata-eval99.9%

        \[\leadsto \frac{\color{blue}{1}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right) \]
      5. associate-*l/99.9%

        \[\leadsto \color{blue}{\frac{1 \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right)}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}}} \]
      6. *-lft-identity99.9%

        \[\leadsto \frac{\color{blue}{\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \]
      7. associate-+l+99.9%

        \[\leadsto \frac{\color{blue}{\left(x + \left(1 + x\right)\right)} - \sqrt{\left(x + 1\right) \cdot x}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \]
      8. *-commutative99.9%

        \[\leadsto \frac{\left(x + \left(1 + x\right)\right) - \sqrt{\color{blue}{x \cdot \left(x + 1\right)}}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \]
      9. +-commutative99.9%

        \[\leadsto \frac{\left(x + \left(1 + x\right)\right) - \sqrt{x \cdot \color{blue}{\left(1 + x\right)}}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \]
      10. +-commutative99.9%

        \[\leadsto \frac{\left(x + \left(1 + x\right)\right) - \sqrt{x \cdot \left(1 + x\right)}}{{\color{blue}{\left(1 + x\right)}}^{1.5} + {x}^{1.5}} \]
    8. Simplified99.9%

      \[\leadsto \color{blue}{\frac{\left(x + \left(1 + x\right)\right) - \sqrt{x \cdot \left(1 + x\right)}}{{\left(1 + x\right)}^{1.5} + {x}^{1.5}}} \]
    9. Taylor expanded in x around 0 94.6%

      \[\leadsto \color{blue}{\frac{1}{1 + {x}^{1.5}}} \]

    if 0.38 < x

    1. Initial program 8.7%

      \[\sqrt{x + 1} - \sqrt{x} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. expm1-log1p-u8.7%

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

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{x + 1} - \sqrt{x}\right)\right)} \]
    5. Step-by-step derivation
      1. expm1-log1p-u8.7%

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

        \[\leadsto \sqrt{\color{blue}{1 + x}} - \sqrt{x} \]
      3. flip--9.7%

        \[\leadsto \color{blue}{\frac{\sqrt{1 + x} \cdot \sqrt{1 + x} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{1 + x} + \sqrt{x}}} \]
      4. flip3-+9.7%

        \[\leadsto \frac{\sqrt{1 + x} \cdot \sqrt{1 + x} - \sqrt{x} \cdot \sqrt{x}}{\color{blue}{\frac{{\left(\sqrt{1 + x}\right)}^{3} + {\left(\sqrt{x}\right)}^{3}}{\sqrt{1 + x} \cdot \sqrt{1 + x} + \left(\sqrt{x} \cdot \sqrt{x} - \sqrt{1 + x} \cdot \sqrt{x}\right)}}} \]
      5. associate-/r/9.7%

        \[\leadsto \color{blue}{\frac{\sqrt{1 + x} \cdot \sqrt{1 + x} - \sqrt{x} \cdot \sqrt{x}}{{\left(\sqrt{1 + x}\right)}^{3} + {\left(\sqrt{x}\right)}^{3}} \cdot \left(\sqrt{1 + x} \cdot \sqrt{1 + x} + \left(\sqrt{x} \cdot \sqrt{x} - \sqrt{1 + x} \cdot \sqrt{x}\right)\right)} \]
    6. Applied egg-rr9.7%

      \[\leadsto \color{blue}{\frac{x + \left(1 - x\right)}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right)} \]
    7. Step-by-step derivation
      1. +-commutative9.7%

        \[\leadsto \frac{\color{blue}{\left(1 - x\right) + x}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right) \]
      2. associate-+l-48.6%

        \[\leadsto \frac{\color{blue}{1 - \left(x - x\right)}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right) \]
      3. +-inverses48.6%

        \[\leadsto \frac{1 - \color{blue}{0}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right) \]
      4. metadata-eval48.6%

        \[\leadsto \frac{\color{blue}{1}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right) \]
      5. associate-*l/48.6%

        \[\leadsto \color{blue}{\frac{1 \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right)}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}}} \]
      6. *-lft-identity48.6%

        \[\leadsto \frac{\color{blue}{\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \]
      7. associate-+l+48.6%

        \[\leadsto \frac{\color{blue}{\left(x + \left(1 + x\right)\right)} - \sqrt{\left(x + 1\right) \cdot x}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \]
      8. *-commutative48.6%

        \[\leadsto \frac{\left(x + \left(1 + x\right)\right) - \sqrt{\color{blue}{x \cdot \left(x + 1\right)}}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \]
      9. +-commutative48.6%

        \[\leadsto \frac{\left(x + \left(1 + x\right)\right) - \sqrt{x \cdot \color{blue}{\left(1 + x\right)}}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \]
      10. +-commutative48.6%

        \[\leadsto \frac{\left(x + \left(1 + x\right)\right) - \sqrt{x \cdot \left(1 + x\right)}}{{\color{blue}{\left(1 + x\right)}}^{1.5} + {x}^{1.5}} \]
    8. Simplified48.6%

      \[\leadsto \color{blue}{\frac{\left(x + \left(1 + x\right)\right) - \sqrt{x \cdot \left(1 + x\right)}}{{\left(1 + x\right)}^{1.5} + {x}^{1.5}}} \]
    9. Taylor expanded in x around inf 62.0%

      \[\leadsto \frac{\color{blue}{0.5 + \left(x + 0.125 \cdot \frac{1}{x}\right)}}{{\left(1 + x\right)}^{1.5} + {x}^{1.5}} \]
    10. Step-by-step derivation
      1. associate-+r+62.0%

        \[\leadsto \frac{\color{blue}{\left(0.5 + x\right) + 0.125 \cdot \frac{1}{x}}}{{\left(1 + x\right)}^{1.5} + {x}^{1.5}} \]
      2. +-commutative62.0%

        \[\leadsto \frac{\color{blue}{\left(x + 0.5\right)} + 0.125 \cdot \frac{1}{x}}{{\left(1 + x\right)}^{1.5} + {x}^{1.5}} \]
      3. associate-*r/62.0%

        \[\leadsto \frac{\left(x + 0.5\right) + \color{blue}{\frac{0.125 \cdot 1}{x}}}{{\left(1 + x\right)}^{1.5} + {x}^{1.5}} \]
      4. metadata-eval62.0%

        \[\leadsto \frac{\left(x + 0.5\right) + \frac{\color{blue}{0.125}}{x}}{{\left(1 + x\right)}^{1.5} + {x}^{1.5}} \]
    11. Simplified62.0%

      \[\leadsto \frac{\color{blue}{\left(x + 0.5\right) + \frac{0.125}{x}}}{{\left(1 + x\right)}^{1.5} + {x}^{1.5}} \]
    12. Taylor expanded in x around inf 96.7%

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{\frac{1}{x}}} \]
    13. Step-by-step derivation
      1. unpow-196.7%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{{x}^{-1}}} \]
      2. sqr-pow96.8%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{{x}^{\left(\frac{-1}{2}\right)} \cdot {x}^{\left(\frac{-1}{2}\right)}}} \]
      3. metadata-eval96.8%

        \[\leadsto 0.5 \cdot \sqrt{{x}^{\color{blue}{-0.5}} \cdot {x}^{\left(\frac{-1}{2}\right)}} \]
      4. metadata-eval96.8%

        \[\leadsto 0.5 \cdot \sqrt{{x}^{-0.5} \cdot {x}^{\color{blue}{-0.5}}} \]
      5. rem-sqrt-square96.8%

        \[\leadsto 0.5 \cdot \color{blue}{\left|{x}^{-0.5}\right|} \]
      6. rem-square-sqrt96.1%

        \[\leadsto 0.5 \cdot \left|\color{blue}{\sqrt{{x}^{-0.5}} \cdot \sqrt{{x}^{-0.5}}}\right| \]
      7. fabs-sqr96.1%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\sqrt{{x}^{-0.5}} \cdot \sqrt{{x}^{-0.5}}\right)} \]
      8. rem-square-sqrt96.8%

        \[\leadsto 0.5 \cdot \color{blue}{{x}^{-0.5}} \]
    14. Simplified96.8%

      \[\leadsto \color{blue}{0.5 \cdot {x}^{-0.5}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification95.7%

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

Alternative 5: 96.8% accurate, 1.9× speedup?

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

\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.25:\\
\;\;\;\;1\\

\mathbf{else}:\\
\;\;\;\;0.5 \cdot {x}^{-0.5}\\


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

    1. Initial program 99.9%

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

      \[\leadsto \color{blue}{1} \]

    if 0.25 < x

    1. Initial program 9.5%

      \[\sqrt{x + 1} - \sqrt{x} \]
    2. Add Preprocessing
    3. Step-by-step derivation
      1. expm1-log1p-u9.5%

        \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{x + 1} - \sqrt{x}\right)\right)} \]
    4. Applied egg-rr9.5%

      \[\leadsto \color{blue}{\mathsf{expm1}\left(\mathsf{log1p}\left(\sqrt{x + 1} - \sqrt{x}\right)\right)} \]
    5. Step-by-step derivation
      1. expm1-log1p-u9.5%

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

        \[\leadsto \sqrt{\color{blue}{1 + x}} - \sqrt{x} \]
      3. flip--10.4%

        \[\leadsto \color{blue}{\frac{\sqrt{1 + x} \cdot \sqrt{1 + x} - \sqrt{x} \cdot \sqrt{x}}{\sqrt{1 + x} + \sqrt{x}}} \]
      4. flip3-+10.4%

        \[\leadsto \frac{\sqrt{1 + x} \cdot \sqrt{1 + x} - \sqrt{x} \cdot \sqrt{x}}{\color{blue}{\frac{{\left(\sqrt{1 + x}\right)}^{3} + {\left(\sqrt{x}\right)}^{3}}{\sqrt{1 + x} \cdot \sqrt{1 + x} + \left(\sqrt{x} \cdot \sqrt{x} - \sqrt{1 + x} \cdot \sqrt{x}\right)}}} \]
      5. associate-/r/10.4%

        \[\leadsto \color{blue}{\frac{\sqrt{1 + x} \cdot \sqrt{1 + x} - \sqrt{x} \cdot \sqrt{x}}{{\left(\sqrt{1 + x}\right)}^{3} + {\left(\sqrt{x}\right)}^{3}} \cdot \left(\sqrt{1 + x} \cdot \sqrt{1 + x} + \left(\sqrt{x} \cdot \sqrt{x} - \sqrt{1 + x} \cdot \sqrt{x}\right)\right)} \]
    6. Applied egg-rr10.4%

      \[\leadsto \color{blue}{\frac{x + \left(1 - x\right)}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right)} \]
    7. Step-by-step derivation
      1. +-commutative10.4%

        \[\leadsto \frac{\color{blue}{\left(1 - x\right) + x}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right) \]
      2. associate-+l-49.0%

        \[\leadsto \frac{\color{blue}{1 - \left(x - x\right)}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right) \]
      3. +-inverses49.0%

        \[\leadsto \frac{1 - \color{blue}{0}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right) \]
      4. metadata-eval49.0%

        \[\leadsto \frac{\color{blue}{1}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right) \]
      5. associate-*l/49.1%

        \[\leadsto \color{blue}{\frac{1 \cdot \left(\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}\right)}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}}} \]
      6. *-lft-identity49.1%

        \[\leadsto \frac{\color{blue}{\left(\left(x + 1\right) + x\right) - \sqrt{\left(x + 1\right) \cdot x}}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \]
      7. associate-+l+49.1%

        \[\leadsto \frac{\color{blue}{\left(x + \left(1 + x\right)\right)} - \sqrt{\left(x + 1\right) \cdot x}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \]
      8. *-commutative49.1%

        \[\leadsto \frac{\left(x + \left(1 + x\right)\right) - \sqrt{\color{blue}{x \cdot \left(x + 1\right)}}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \]
      9. +-commutative49.1%

        \[\leadsto \frac{\left(x + \left(1 + x\right)\right) - \sqrt{x \cdot \color{blue}{\left(1 + x\right)}}}{{\left(x + 1\right)}^{1.5} + {x}^{1.5}} \]
      10. +-commutative49.1%

        \[\leadsto \frac{\left(x + \left(1 + x\right)\right) - \sqrt{x \cdot \left(1 + x\right)}}{{\color{blue}{\left(1 + x\right)}}^{1.5} + {x}^{1.5}} \]
    8. Simplified49.1%

      \[\leadsto \color{blue}{\frac{\left(x + \left(1 + x\right)\right) - \sqrt{x \cdot \left(1 + x\right)}}{{\left(1 + x\right)}^{1.5} + {x}^{1.5}}} \]
    9. Taylor expanded in x around inf 61.7%

      \[\leadsto \frac{\color{blue}{0.5 + \left(x + 0.125 \cdot \frac{1}{x}\right)}}{{\left(1 + x\right)}^{1.5} + {x}^{1.5}} \]
    10. Step-by-step derivation
      1. associate-+r+61.7%

        \[\leadsto \frac{\color{blue}{\left(0.5 + x\right) + 0.125 \cdot \frac{1}{x}}}{{\left(1 + x\right)}^{1.5} + {x}^{1.5}} \]
      2. +-commutative61.7%

        \[\leadsto \frac{\color{blue}{\left(x + 0.5\right)} + 0.125 \cdot \frac{1}{x}}{{\left(1 + x\right)}^{1.5} + {x}^{1.5}} \]
      3. associate-*r/61.7%

        \[\leadsto \frac{\left(x + 0.5\right) + \color{blue}{\frac{0.125 \cdot 1}{x}}}{{\left(1 + x\right)}^{1.5} + {x}^{1.5}} \]
      4. metadata-eval61.7%

        \[\leadsto \frac{\left(x + 0.5\right) + \frac{\color{blue}{0.125}}{x}}{{\left(1 + x\right)}^{1.5} + {x}^{1.5}} \]
    11. Simplified61.7%

      \[\leadsto \frac{\color{blue}{\left(x + 0.5\right) + \frac{0.125}{x}}}{{\left(1 + x\right)}^{1.5} + {x}^{1.5}} \]
    12. Taylor expanded in x around inf 96.0%

      \[\leadsto \color{blue}{0.5 \cdot \sqrt{\frac{1}{x}}} \]
    13. Step-by-step derivation
      1. unpow-196.0%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{{x}^{-1}}} \]
      2. sqr-pow96.2%

        \[\leadsto 0.5 \cdot \sqrt{\color{blue}{{x}^{\left(\frac{-1}{2}\right)} \cdot {x}^{\left(\frac{-1}{2}\right)}}} \]
      3. metadata-eval96.2%

        \[\leadsto 0.5 \cdot \sqrt{{x}^{\color{blue}{-0.5}} \cdot {x}^{\left(\frac{-1}{2}\right)}} \]
      4. metadata-eval96.2%

        \[\leadsto 0.5 \cdot \sqrt{{x}^{-0.5} \cdot {x}^{\color{blue}{-0.5}}} \]
      5. rem-sqrt-square96.2%

        \[\leadsto 0.5 \cdot \color{blue}{\left|{x}^{-0.5}\right|} \]
      6. rem-square-sqrt95.4%

        \[\leadsto 0.5 \cdot \left|\color{blue}{\sqrt{{x}^{-0.5}} \cdot \sqrt{{x}^{-0.5}}}\right| \]
      7. fabs-sqr95.4%

        \[\leadsto 0.5 \cdot \color{blue}{\left(\sqrt{{x}^{-0.5}} \cdot \sqrt{{x}^{-0.5}}\right)} \]
      8. rem-square-sqrt96.2%

        \[\leadsto 0.5 \cdot \color{blue}{{x}^{-0.5}} \]
    14. Simplified96.2%

      \[\leadsto \color{blue}{0.5 \cdot {x}^{-0.5}} \]
  3. Recombined 2 regimes into one program.
  4. Final simplification95.7%

    \[\leadsto \begin{array}{l} \mathbf{if}\;x \leq 0.25:\\ \;\;\;\;1\\ \mathbf{else}:\\ \;\;\;\;0.5 \cdot {x}^{-0.5}\\ \end{array} \]
  5. Add Preprocessing

Alternative 6: 49.6% accurate, 205.0× speedup?

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

\\
1
\end{array}
Derivation
  1. Initial program 56.8%

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

    \[\leadsto \color{blue}{1} \]
  4. Final simplification53.2%

    \[\leadsto 1 \]
  5. Add Preprocessing

Developer target: 99.7% accurate, 1.0× speedup?

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

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

Reproduce

?
herbie shell --seed 2024034 
(FPCore (x)
  :name "Main:bigenough3 from C"
  :precision binary64

  :herbie-target
  (/ 1.0 (+ (sqrt (+ x 1.0)) (sqrt x)))

  (- (sqrt (+ x 1.0)) (sqrt x)))