
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
double code(double x) {
return (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / sqrt(x)) - (1.0d0 / sqrt((x + 1.0d0)))
end function
public static double code(double x) {
return (1.0 / Math.sqrt(x)) - (1.0 / Math.sqrt((x + 1.0)));
}
def code(x): return (1.0 / math.sqrt(x)) - (1.0 / math.sqrt((x + 1.0)))
function code(x) return Float64(Float64(1.0 / sqrt(x)) - Float64(1.0 / sqrt(Float64(x + 1.0)))) end
function tmp = code(x) tmp = (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0))); end
code[x_] := N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] - N[(1.0 / N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 12 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 (- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))
double code(double x) {
return (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0)));
}
real(8) function code(x)
real(8), intent (in) :: x
code = (1.0d0 / sqrt(x)) - (1.0d0 / sqrt((x + 1.0d0)))
end function
public static double code(double x) {
return (1.0 / Math.sqrt(x)) - (1.0 / Math.sqrt((x + 1.0)));
}
def code(x): return (1.0 / math.sqrt(x)) - (1.0 / math.sqrt((x + 1.0)))
function code(x) return Float64(Float64(1.0 / sqrt(x)) - Float64(1.0 / sqrt(Float64(x + 1.0)))) end
function tmp = code(x) tmp = (1.0 / sqrt(x)) - (1.0 / sqrt((x + 1.0))); end
code[x_] := N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] - N[(1.0 / N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\sqrt{x}} - \frac{1}{\sqrt{x + 1}}
\end{array}
(FPCore (x) :precision binary64 (/ (pow x -0.5) (fma (sqrt x) (sqrt (+ x 1.0)) (+ x 1.0))))
double code(double x) {
return pow(x, -0.5) / fma(sqrt(x), sqrt((x + 1.0)), (x + 1.0));
}
function code(x) return Float64((x ^ -0.5) / fma(sqrt(x), sqrt(Float64(x + 1.0)), Float64(x + 1.0))) end
code[x_] := N[(N[Power[x, -0.5], $MachinePrecision] / N[(N[Sqrt[x], $MachinePrecision] * N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision] + N[(x + 1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{{x}^{-0.5}}{\mathsf{fma}\left(\sqrt{x}, \sqrt{x + 1}, x + 1\right)}
\end{array}
Initial program 64.0%
frac-sub64.0%
*-un-lft-identity64.0%
+-commutative64.0%
*-rgt-identity64.0%
sqrt-unprod64.0%
+-commutative64.0%
Applied egg-rr64.0%
flip--63.9%
add-sqr-sqrt64.2%
add-sqr-sqrt64.5%
Applied egg-rr64.5%
associate--l+90.1%
+-inverses90.1%
metadata-eval90.1%
+-commutative90.1%
Simplified90.1%
*-un-lft-identity90.1%
sqrt-prod99.4%
times-frac99.3%
pow1/299.3%
pow-flip99.6%
metadata-eval99.6%
Applied egg-rr99.6%
associate-/l/99.5%
associate-*r/99.6%
*-rgt-identity99.6%
distribute-rgt-in99.6%
fma-def99.6%
rem-square-sqrt99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (+ x 1.0))))
(if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 t_0)) 2e-17)
(/ (/ 1.0 (+ (sqrt x) t_0)) (+ x 0.5))
(- (pow x -0.5) (pow (+ x 1.0) -0.5)))))
double code(double x) {
double t_0 = sqrt((x + 1.0));
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / t_0)) <= 2e-17) {
tmp = (1.0 / (sqrt(x) + t_0)) / (x + 0.5);
} else {
tmp = pow(x, -0.5) - pow((x + 1.0), -0.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt((x + 1.0d0))
if (((1.0d0 / sqrt(x)) + ((-1.0d0) / t_0)) <= 2d-17) then
tmp = (1.0d0 / (sqrt(x) + t_0)) / (x + 0.5d0)
else
tmp = (x ** (-0.5d0)) - ((x + 1.0d0) ** (-0.5d0))
end if
code = tmp
end function
public static double code(double x) {
double t_0 = Math.sqrt((x + 1.0));
double tmp;
if (((1.0 / Math.sqrt(x)) + (-1.0 / t_0)) <= 2e-17) {
tmp = (1.0 / (Math.sqrt(x) + t_0)) / (x + 0.5);
} else {
tmp = Math.pow(x, -0.5) - Math.pow((x + 1.0), -0.5);
}
return tmp;
}
def code(x): t_0 = math.sqrt((x + 1.0)) tmp = 0 if ((1.0 / math.sqrt(x)) + (-1.0 / t_0)) <= 2e-17: tmp = (1.0 / (math.sqrt(x) + t_0)) / (x + 0.5) else: tmp = math.pow(x, -0.5) - math.pow((x + 1.0), -0.5) return tmp
function code(x) t_0 = sqrt(Float64(x + 1.0)) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / t_0)) <= 2e-17) tmp = Float64(Float64(1.0 / Float64(sqrt(x) + t_0)) / Float64(x + 0.5)); else tmp = Float64((x ^ -0.5) - (Float64(x + 1.0) ^ -0.5)); end return tmp end
function tmp_2 = code(x) t_0 = sqrt((x + 1.0)); tmp = 0.0; if (((1.0 / sqrt(x)) + (-1.0 / t_0)) <= 2e-17) tmp = (1.0 / (sqrt(x) + t_0)) / (x + 0.5); else tmp = (x ^ -0.5) - ((x + 1.0) ^ -0.5); end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / t$95$0), $MachinePrecision]), $MachinePrecision], 2e-17], N[(N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision] / N[(x + 0.5), $MachinePrecision]), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{x + 1}\\
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{t_0} \leq 2 \cdot 10^{-17}:\\
\;\;\;\;\frac{\frac{1}{\sqrt{x} + t_0}}{x + 0.5}\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} - {\left(x + 1\right)}^{-0.5}\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 2.00000000000000014e-17Initial program 35.1%
frac-sub35.1%
*-un-lft-identity35.1%
+-commutative35.1%
*-rgt-identity35.1%
sqrt-unprod35.1%
+-commutative35.1%
Applied egg-rr35.1%
flip--35.1%
add-sqr-sqrt35.6%
add-sqr-sqrt36.0%
Applied egg-rr36.0%
associate--l+82.4%
+-inverses82.4%
metadata-eval82.4%
+-commutative82.4%
Simplified82.4%
Taylor expanded in x around inf 99.6%
+-commutative99.6%
Simplified99.6%
if 2.00000000000000014e-17 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.4%
*-un-lft-identity99.4%
clear-num99.4%
associate-/r/99.4%
prod-diff99.4%
*-un-lft-identity99.4%
fma-neg99.4%
*-un-lft-identity99.4%
pow1/299.4%
pow-flip99.8%
metadata-eval99.8%
pow1/299.8%
pow-flip99.8%
+-commutative99.8%
metadata-eval99.8%
Applied egg-rr99.8%
+-commutative99.8%
sub-neg99.8%
fma-udef99.8%
distribute-lft1-in99.8%
metadata-eval99.8%
mul0-lft99.8%
+-commutative99.8%
associate-+r+99.8%
sub-neg99.8%
neg-sub099.8%
+-commutative99.8%
sub-neg99.8%
Simplified99.8%
Final simplification99.7%
(FPCore (x)
:precision binary64
(let* ((t_0 (sqrt (+ x 1.0))))
(if (<= (+ (/ 1.0 (sqrt x)) (/ -1.0 t_0)) 2e-17)
(/ (/ 1.0 (+ (sqrt x) t_0)) x)
(- (pow x -0.5) (pow (+ x 1.0) -0.5)))))
double code(double x) {
double t_0 = sqrt((x + 1.0));
double tmp;
if (((1.0 / sqrt(x)) + (-1.0 / t_0)) <= 2e-17) {
tmp = (1.0 / (sqrt(x) + t_0)) / x;
} else {
tmp = pow(x, -0.5) - pow((x + 1.0), -0.5);
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: t_0
real(8) :: tmp
t_0 = sqrt((x + 1.0d0))
if (((1.0d0 / sqrt(x)) + ((-1.0d0) / t_0)) <= 2d-17) then
tmp = (1.0d0 / (sqrt(x) + t_0)) / x
else
tmp = (x ** (-0.5d0)) - ((x + 1.0d0) ** (-0.5d0))
end if
code = tmp
end function
public static double code(double x) {
double t_0 = Math.sqrt((x + 1.0));
double tmp;
if (((1.0 / Math.sqrt(x)) + (-1.0 / t_0)) <= 2e-17) {
tmp = (1.0 / (Math.sqrt(x) + t_0)) / x;
} else {
tmp = Math.pow(x, -0.5) - Math.pow((x + 1.0), -0.5);
}
return tmp;
}
def code(x): t_0 = math.sqrt((x + 1.0)) tmp = 0 if ((1.0 / math.sqrt(x)) + (-1.0 / t_0)) <= 2e-17: tmp = (1.0 / (math.sqrt(x) + t_0)) / x else: tmp = math.pow(x, -0.5) - math.pow((x + 1.0), -0.5) return tmp
function code(x) t_0 = sqrt(Float64(x + 1.0)) tmp = 0.0 if (Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 / t_0)) <= 2e-17) tmp = Float64(Float64(1.0 / Float64(sqrt(x) + t_0)) / x); else tmp = Float64((x ^ -0.5) - (Float64(x + 1.0) ^ -0.5)); end return tmp end
function tmp_2 = code(x) t_0 = sqrt((x + 1.0)); tmp = 0.0; if (((1.0 / sqrt(x)) + (-1.0 / t_0)) <= 2e-17) tmp = (1.0 / (sqrt(x) + t_0)) / x; else tmp = (x ^ -0.5) - ((x + 1.0) ^ -0.5); end tmp_2 = tmp; end
code[x_] := Block[{t$95$0 = N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]}, If[LessEqual[N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-1.0 / t$95$0), $MachinePrecision]), $MachinePrecision], 2e-17], N[(N[(1.0 / N[(N[Sqrt[x], $MachinePrecision] + t$95$0), $MachinePrecision]), $MachinePrecision] / x), $MachinePrecision], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{x + 1}\\
\mathbf{if}\;\frac{1}{\sqrt{x}} + \frac{-1}{t_0} \leq 2 \cdot 10^{-17}:\\
\;\;\;\;\frac{\frac{1}{\sqrt{x} + t_0}}{x}\\
\mathbf{else}:\\
\;\;\;\;{x}^{-0.5} - {\left(x + 1\right)}^{-0.5}\\
\end{array}
\end{array}
if (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) < 2.00000000000000014e-17Initial program 35.1%
frac-sub35.1%
*-un-lft-identity35.1%
+-commutative35.1%
*-rgt-identity35.1%
sqrt-unprod35.1%
+-commutative35.1%
Applied egg-rr35.1%
flip--35.1%
add-sqr-sqrt35.6%
add-sqr-sqrt36.0%
Applied egg-rr36.0%
associate--l+82.4%
+-inverses82.4%
metadata-eval82.4%
+-commutative82.4%
Simplified82.4%
Taylor expanded in x around inf 99.4%
if 2.00000000000000014e-17 < (-.f64 (/.f64 1 (sqrt.f64 x)) (/.f64 1 (sqrt.f64 (+.f64 x 1)))) Initial program 99.4%
*-un-lft-identity99.4%
clear-num99.4%
associate-/r/99.4%
prod-diff99.4%
*-un-lft-identity99.4%
fma-neg99.4%
*-un-lft-identity99.4%
pow1/299.4%
pow-flip99.8%
metadata-eval99.8%
pow1/299.8%
pow-flip99.8%
+-commutative99.8%
metadata-eval99.8%
Applied egg-rr99.8%
+-commutative99.8%
sub-neg99.8%
fma-udef99.8%
distribute-lft1-in99.8%
metadata-eval99.8%
mul0-lft99.8%
+-commutative99.8%
associate-+r+99.8%
sub-neg99.8%
neg-sub099.8%
+-commutative99.8%
sub-neg99.8%
Simplified99.8%
Final simplification99.6%
(FPCore (x) :precision binary64 (if (<= x 59000000.0) (- (pow x -0.5) (pow (+ x 1.0) -0.5)) (/ (/ -1.0 (* x (- -1.0 x))) (* 2.0 (sqrt (/ 1.0 x))))))
double code(double x) {
double tmp;
if (x <= 59000000.0) {
tmp = pow(x, -0.5) - pow((x + 1.0), -0.5);
} else {
tmp = (-1.0 / (x * (-1.0 - x))) / (2.0 * sqrt((1.0 / x)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 59000000.0d0) then
tmp = (x ** (-0.5d0)) - ((x + 1.0d0) ** (-0.5d0))
else
tmp = ((-1.0d0) / (x * ((-1.0d0) - x))) / (2.0d0 * sqrt((1.0d0 / x)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 59000000.0) {
tmp = Math.pow(x, -0.5) - Math.pow((x + 1.0), -0.5);
} else {
tmp = (-1.0 / (x * (-1.0 - x))) / (2.0 * Math.sqrt((1.0 / x)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 59000000.0: tmp = math.pow(x, -0.5) - math.pow((x + 1.0), -0.5) else: tmp = (-1.0 / (x * (-1.0 - x))) / (2.0 * math.sqrt((1.0 / x))) return tmp
function code(x) tmp = 0.0 if (x <= 59000000.0) tmp = Float64((x ^ -0.5) - (Float64(x + 1.0) ^ -0.5)); else tmp = Float64(Float64(-1.0 / Float64(x * Float64(-1.0 - x))) / Float64(2.0 * sqrt(Float64(1.0 / x)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 59000000.0) tmp = (x ^ -0.5) - ((x + 1.0) ^ -0.5); else tmp = (-1.0 / (x * (-1.0 - x))) / (2.0 * sqrt((1.0 / x))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 59000000.0], N[(N[Power[x, -0.5], $MachinePrecision] - N[Power[N[(x + 1.0), $MachinePrecision], -0.5], $MachinePrecision]), $MachinePrecision], N[(N[(-1.0 / N[(x * N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(2.0 * N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 59000000:\\
\;\;\;\;{x}^{-0.5} - {\left(x + 1\right)}^{-0.5}\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{-1}{x \cdot \left(-1 - x\right)}}{2 \cdot \sqrt{\frac{1}{x}}}\\
\end{array}
\end{array}
if x < 5.9e7Initial program 99.4%
*-un-lft-identity99.4%
clear-num99.4%
associate-/r/99.4%
prod-diff99.4%
*-un-lft-identity99.4%
fma-neg99.4%
*-un-lft-identity99.4%
pow1/299.4%
pow-flip99.8%
metadata-eval99.8%
pow1/299.8%
pow-flip99.8%
+-commutative99.8%
metadata-eval99.8%
Applied egg-rr99.8%
+-commutative99.8%
sub-neg99.8%
fma-udef99.8%
distribute-lft1-in99.8%
metadata-eval99.8%
mul0-lft99.8%
+-commutative99.8%
associate-+r+99.8%
sub-neg99.8%
neg-sub099.8%
+-commutative99.8%
sub-neg99.8%
Simplified99.8%
if 5.9e7 < x Initial program 35.1%
flip--35.1%
frac-times18.5%
metadata-eval18.5%
add-sqr-sqrt14.7%
frac-times23.1%
metadata-eval23.1%
add-sqr-sqrt35.1%
+-commutative35.1%
pow1/235.1%
pow-flip35.1%
metadata-eval35.1%
inv-pow35.1%
sqrt-pow235.1%
+-commutative35.1%
metadata-eval35.1%
Applied egg-rr35.1%
Taylor expanded in x around inf 35.1%
frac-sub35.8%
frac-2neg35.8%
*-un-lft-identity35.8%
+-commutative35.8%
distribute-rgt-in35.8%
*-un-lft-identity35.8%
fma-def35.8%
Applied egg-rr35.8%
*-rgt-identity35.8%
associate--l+82.1%
+-inverses82.1%
metadata-eval82.1%
metadata-eval82.1%
fma-udef82.1%
unpow282.1%
+-commutative82.1%
*-rgt-identity82.1%
unpow282.1%
distribute-lft-in82.1%
distribute-rgt-neg-out82.1%
distribute-neg-in82.1%
metadata-eval82.1%
unsub-neg82.1%
Simplified82.1%
Final simplification90.1%
(FPCore (x) :precision binary64 (if (<= x 1.0) (+ (/ 1.0 (sqrt x)) (- -1.0 (* x (+ -0.5 (* x 0.375))))) (/ 1.0 (sqrt (* x (+ x 1.0))))))
double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = (1.0 / sqrt(x)) + (-1.0 - (x * (-0.5 + (x * 0.375))));
} else {
tmp = 1.0 / sqrt((x * (x + 1.0)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.0d0) then
tmp = (1.0d0 / sqrt(x)) + ((-1.0d0) - (x * ((-0.5d0) + (x * 0.375d0))))
else
tmp = 1.0d0 / sqrt((x * (x + 1.0d0)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.0) {
tmp = (1.0 / Math.sqrt(x)) + (-1.0 - (x * (-0.5 + (x * 0.375))));
} else {
tmp = 1.0 / Math.sqrt((x * (x + 1.0)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.0: tmp = (1.0 / math.sqrt(x)) + (-1.0 - (x * (-0.5 + (x * 0.375)))) else: tmp = 1.0 / math.sqrt((x * (x + 1.0))) return tmp
function code(x) tmp = 0.0 if (x <= 1.0) tmp = Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 - Float64(x * Float64(-0.5 + Float64(x * 0.375))))); else tmp = Float64(1.0 / sqrt(Float64(x * Float64(x + 1.0)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.0) tmp = (1.0 / sqrt(x)) + (-1.0 - (x * (-0.5 + (x * 0.375)))); else tmp = 1.0 / sqrt((x * (x + 1.0))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.0], N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-1.0 - N[(x * N[(-0.5 + N[(x * 0.375), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[Sqrt[N[(x * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1:\\
\;\;\;\;\frac{1}{\sqrt{x}} + \left(-1 - x \cdot \left(-0.5 + x \cdot 0.375\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sqrt{x \cdot \left(x + 1\right)}}\\
\end{array}
\end{array}
if x < 1Initial program 99.6%
Taylor expanded in x around 0 98.9%
*-commutative98.9%
*-commutative98.9%
unpow298.9%
associate-*l*98.9%
distribute-lft-out98.9%
Simplified98.9%
if 1 < x Initial program 35.9%
frac-sub35.8%
*-un-lft-identity35.8%
+-commutative35.8%
*-rgt-identity35.8%
sqrt-unprod35.8%
+-commutative35.8%
Applied egg-rr35.8%
Taylor expanded in x around 0 36.0%
Final simplification63.8%
(FPCore (x) :precision binary64 (if (<= x 0.72) (+ (/ 1.0 (sqrt x)) (- -1.0 (* x (+ -0.5 (* x 0.375))))) (/ (/ -1.0 (* x (- -1.0 x))) (* 2.0 (sqrt (/ 1.0 x))))))
double code(double x) {
double tmp;
if (x <= 0.72) {
tmp = (1.0 / sqrt(x)) + (-1.0 - (x * (-0.5 + (x * 0.375))));
} else {
tmp = (-1.0 / (x * (-1.0 - x))) / (2.0 * sqrt((1.0 / x)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.72d0) then
tmp = (1.0d0 / sqrt(x)) + ((-1.0d0) - (x * ((-0.5d0) + (x * 0.375d0))))
else
tmp = ((-1.0d0) / (x * ((-1.0d0) - x))) / (2.0d0 * sqrt((1.0d0 / x)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.72) {
tmp = (1.0 / Math.sqrt(x)) + (-1.0 - (x * (-0.5 + (x * 0.375))));
} else {
tmp = (-1.0 / (x * (-1.0 - x))) / (2.0 * Math.sqrt((1.0 / x)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.72: tmp = (1.0 / math.sqrt(x)) + (-1.0 - (x * (-0.5 + (x * 0.375)))) else: tmp = (-1.0 / (x * (-1.0 - x))) / (2.0 * math.sqrt((1.0 / x))) return tmp
function code(x) tmp = 0.0 if (x <= 0.72) tmp = Float64(Float64(1.0 / sqrt(x)) + Float64(-1.0 - Float64(x * Float64(-0.5 + Float64(x * 0.375))))); else tmp = Float64(Float64(-1.0 / Float64(x * Float64(-1.0 - x))) / Float64(2.0 * sqrt(Float64(1.0 / x)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.72) tmp = (1.0 / sqrt(x)) + (-1.0 - (x * (-0.5 + (x * 0.375)))); else tmp = (-1.0 / (x * (-1.0 - x))) / (2.0 * sqrt((1.0 / x))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.72], N[(N[(1.0 / N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(-1.0 - N[(x * N[(-0.5 + N[(x * 0.375), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(-1.0 / N[(x * N[(-1.0 - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] / N[(2.0 * N[Sqrt[N[(1.0 / x), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.72:\\
\;\;\;\;\frac{1}{\sqrt{x}} + \left(-1 - x \cdot \left(-0.5 + x \cdot 0.375\right)\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{\frac{-1}{x \cdot \left(-1 - x\right)}}{2 \cdot \sqrt{\frac{1}{x}}}\\
\end{array}
\end{array}
if x < 0.71999999999999997Initial program 99.6%
Taylor expanded in x around 0 98.9%
*-commutative98.9%
*-commutative98.9%
unpow298.9%
associate-*l*98.9%
distribute-lft-out98.9%
Simplified98.9%
if 0.71999999999999997 < x Initial program 35.9%
flip--35.8%
frac-times19.5%
metadata-eval19.5%
add-sqr-sqrt15.7%
frac-times24.0%
metadata-eval24.0%
add-sqr-sqrt35.9%
+-commutative35.9%
pow1/235.9%
pow-flip35.9%
metadata-eval35.9%
inv-pow35.9%
sqrt-pow235.9%
+-commutative35.9%
metadata-eval35.9%
Applied egg-rr35.9%
Taylor expanded in x around inf 35.1%
frac-sub35.7%
frac-2neg35.7%
*-un-lft-identity35.7%
+-commutative35.7%
distribute-rgt-in35.7%
*-un-lft-identity35.7%
fma-def35.7%
Applied egg-rr35.7%
*-rgt-identity35.7%
associate--l+81.5%
+-inverses81.5%
metadata-eval81.5%
metadata-eval81.5%
fma-udef81.5%
unpow281.5%
+-commutative81.5%
*-rgt-identity81.5%
unpow281.5%
distribute-lft-in81.5%
distribute-rgt-neg-out81.5%
distribute-neg-in81.5%
metadata-eval81.5%
unsub-neg81.5%
Simplified81.5%
Final simplification89.2%
(FPCore (x) :precision binary64 (if (<= x 1.4) (+ -1.0 (+ (pow x -0.5) (* x 0.5))) (/ 1.0 (sqrt (* x (+ x 1.0))))))
double code(double x) {
double tmp;
if (x <= 1.4) {
tmp = -1.0 + (pow(x, -0.5) + (x * 0.5));
} else {
tmp = 1.0 / sqrt((x * (x + 1.0)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 1.4d0) then
tmp = (-1.0d0) + ((x ** (-0.5d0)) + (x * 0.5d0))
else
tmp = 1.0d0 / sqrt((x * (x + 1.0d0)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 1.4) {
tmp = -1.0 + (Math.pow(x, -0.5) + (x * 0.5));
} else {
tmp = 1.0 / Math.sqrt((x * (x + 1.0)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 1.4: tmp = -1.0 + (math.pow(x, -0.5) + (x * 0.5)) else: tmp = 1.0 / math.sqrt((x * (x + 1.0))) return tmp
function code(x) tmp = 0.0 if (x <= 1.4) tmp = Float64(-1.0 + Float64((x ^ -0.5) + Float64(x * 0.5))); else tmp = Float64(1.0 / sqrt(Float64(x * Float64(x + 1.0)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 1.4) tmp = -1.0 + ((x ^ -0.5) + (x * 0.5)); else tmp = 1.0 / sqrt((x * (x + 1.0))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 1.4], N[(-1.0 + N[(N[Power[x, -0.5], $MachinePrecision] + N[(x * 0.5), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(1.0 / N[Sqrt[N[(x * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 1.4:\\
\;\;\;\;-1 + \left({x}^{-0.5} + x \cdot 0.5\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sqrt{x \cdot \left(x + 1\right)}}\\
\end{array}
\end{array}
if x < 1.3999999999999999Initial program 99.6%
*-un-lft-identity99.6%
clear-num99.6%
associate-/r/99.6%
prod-diff99.6%
*-un-lft-identity99.6%
fma-neg99.6%
*-un-lft-identity99.6%
pow1/299.6%
pow-flip100.0%
metadata-eval100.0%
pow1/2100.0%
pow-flip100.0%
+-commutative100.0%
metadata-eval100.0%
Applied egg-rr100.0%
+-commutative100.0%
sub-neg100.0%
fma-udef100.0%
distribute-lft1-in100.0%
metadata-eval100.0%
mul0-lft100.0%
+-commutative100.0%
associate-+r+100.0%
sub-neg100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 98.9%
if 1.3999999999999999 < x Initial program 35.9%
frac-sub35.8%
*-un-lft-identity35.8%
+-commutative35.8%
*-rgt-identity35.8%
sqrt-unprod35.8%
+-commutative35.8%
Applied egg-rr35.8%
Taylor expanded in x around 0 36.0%
Final simplification63.7%
(FPCore (x) :precision binary64 (if (<= x 0.68) (+ (pow x -0.5) -1.0) (/ 1.0 (sqrt (* x (+ x 1.0))))))
double code(double x) {
double tmp;
if (x <= 0.68) {
tmp = pow(x, -0.5) + -1.0;
} else {
tmp = 1.0 / sqrt((x * (x + 1.0)));
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.68d0) then
tmp = (x ** (-0.5d0)) + (-1.0d0)
else
tmp = 1.0d0 / sqrt((x * (x + 1.0d0)))
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.68) {
tmp = Math.pow(x, -0.5) + -1.0;
} else {
tmp = 1.0 / Math.sqrt((x * (x + 1.0)));
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.68: tmp = math.pow(x, -0.5) + -1.0 else: tmp = 1.0 / math.sqrt((x * (x + 1.0))) return tmp
function code(x) tmp = 0.0 if (x <= 0.68) tmp = Float64((x ^ -0.5) + -1.0); else tmp = Float64(1.0 / sqrt(Float64(x * Float64(x + 1.0)))); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.68) tmp = (x ^ -0.5) + -1.0; else tmp = 1.0 / sqrt((x * (x + 1.0))); end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.68], N[(N[Power[x, -0.5], $MachinePrecision] + -1.0), $MachinePrecision], N[(1.0 / N[Sqrt[N[(x * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.68:\\
\;\;\;\;{x}^{-0.5} + -1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{\sqrt{x \cdot \left(x + 1\right)}}\\
\end{array}
\end{array}
if x < 0.680000000000000049Initial program 99.6%
*-un-lft-identity99.6%
clear-num99.6%
associate-/r/99.6%
prod-diff99.6%
*-un-lft-identity99.6%
fma-neg99.6%
*-un-lft-identity99.6%
pow1/299.6%
pow-flip100.0%
metadata-eval100.0%
pow1/2100.0%
pow-flip100.0%
+-commutative100.0%
metadata-eval100.0%
Applied egg-rr100.0%
+-commutative100.0%
sub-neg100.0%
fma-udef100.0%
distribute-lft1-in100.0%
metadata-eval100.0%
mul0-lft100.0%
+-commutative100.0%
associate-+r+100.0%
sub-neg100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 98.2%
if 0.680000000000000049 < x Initial program 35.9%
frac-sub35.8%
*-un-lft-identity35.8%
+-commutative35.8%
*-rgt-identity35.8%
sqrt-unprod35.8%
+-commutative35.8%
Applied egg-rr35.8%
Taylor expanded in x around 0 36.0%
Final simplification63.4%
(FPCore (x) :precision binary64 (if (<= x 0.82) (+ (pow x -0.5) -1.0) (/ 1.0 x)))
double code(double x) {
double tmp;
if (x <= 0.82) {
tmp = pow(x, -0.5) + -1.0;
} else {
tmp = 1.0 / x;
}
return tmp;
}
real(8) function code(x)
real(8), intent (in) :: x
real(8) :: tmp
if (x <= 0.82d0) then
tmp = (x ** (-0.5d0)) + (-1.0d0)
else
tmp = 1.0d0 / x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if (x <= 0.82) {
tmp = Math.pow(x, -0.5) + -1.0;
} else {
tmp = 1.0 / x;
}
return tmp;
}
def code(x): tmp = 0 if x <= 0.82: tmp = math.pow(x, -0.5) + -1.0 else: tmp = 1.0 / x return tmp
function code(x) tmp = 0.0 if (x <= 0.82) tmp = Float64((x ^ -0.5) + -1.0); else tmp = Float64(1.0 / x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if (x <= 0.82) tmp = (x ^ -0.5) + -1.0; else tmp = 1.0 / x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[x, 0.82], N[(N[Power[x, -0.5], $MachinePrecision] + -1.0), $MachinePrecision], N[(1.0 / x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 0.82:\\
\;\;\;\;{x}^{-0.5} + -1\\
\mathbf{else}:\\
\;\;\;\;\frac{1}{x}\\
\end{array}
\end{array}
if x < 0.819999999999999951Initial program 99.6%
*-un-lft-identity99.6%
clear-num99.6%
associate-/r/99.6%
prod-diff99.6%
*-un-lft-identity99.6%
fma-neg99.6%
*-un-lft-identity99.6%
pow1/299.6%
pow-flip100.0%
metadata-eval100.0%
pow1/2100.0%
pow-flip100.0%
+-commutative100.0%
metadata-eval100.0%
Applied egg-rr100.0%
+-commutative100.0%
sub-neg100.0%
fma-udef100.0%
distribute-lft1-in100.0%
metadata-eval100.0%
mul0-lft100.0%
+-commutative100.0%
associate-+r+100.0%
sub-neg100.0%
neg-sub0100.0%
+-commutative100.0%
sub-neg100.0%
Simplified100.0%
Taylor expanded in x around 0 98.2%
if 0.819999999999999951 < x Initial program 35.9%
flip--35.8%
frac-times19.5%
metadata-eval19.5%
add-sqr-sqrt15.7%
frac-times24.0%
metadata-eval24.0%
add-sqr-sqrt35.9%
+-commutative35.9%
pow1/235.9%
pow-flip35.9%
metadata-eval35.9%
inv-pow35.9%
sqrt-pow235.9%
+-commutative35.9%
metadata-eval35.9%
Applied egg-rr35.9%
Taylor expanded in x around 0 7.5%
distribute-rgt-in7.5%
*-lft-identity7.5%
pow-plus7.5%
metadata-eval7.5%
Simplified7.5%
Taylor expanded in x around inf 7.5%
Final simplification47.5%
(FPCore (x) :precision binary64 (/ 1.0 (+ x (sqrt x))))
double code(double x) {
return 1.0 / (x + sqrt(x));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (x + sqrt(x))
end function
public static double code(double x) {
return 1.0 / (x + Math.sqrt(x));
}
def code(x): return 1.0 / (x + math.sqrt(x))
function code(x) return Float64(1.0 / Float64(x + sqrt(x))) end
function tmp = code(x) tmp = 1.0 / (x + sqrt(x)); end
code[x_] := N[(1.0 / N[(x + N[Sqrt[x], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x + \sqrt{x}}
\end{array}
Initial program 64.0%
flip--63.9%
frac-times54.7%
metadata-eval54.7%
add-sqr-sqrt52.7%
frac-times57.3%
metadata-eval57.3%
add-sqr-sqrt63.9%
+-commutative63.9%
pow1/263.9%
pow-flip63.9%
metadata-eval63.9%
inv-pow63.9%
sqrt-pow263.9%
+-commutative63.9%
metadata-eval63.9%
Applied egg-rr63.9%
Taylor expanded in x around 0 46.9%
+-commutative46.9%
distribute-lft-in46.9%
pow146.9%
pow-prod-up47.1%
metadata-eval47.1%
pow1/247.1%
*-rgt-identity47.1%
Applied egg-rr47.1%
Final simplification47.1%
(FPCore (x) :precision binary64 (/ 1.0 x))
double code(double x) {
return 1.0 / x;
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / x
end function
public static double code(double x) {
return 1.0 / x;
}
def code(x): return 1.0 / x
function code(x) return Float64(1.0 / x) end
function tmp = code(x) tmp = 1.0 / x; end
code[x_] := N[(1.0 / x), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{x}
\end{array}
Initial program 64.0%
flip--63.9%
frac-times54.7%
metadata-eval54.7%
add-sqr-sqrt52.7%
frac-times57.3%
metadata-eval57.3%
add-sqr-sqrt63.9%
+-commutative63.9%
pow1/263.9%
pow-flip63.9%
metadata-eval63.9%
inv-pow63.9%
sqrt-pow263.9%
+-commutative63.9%
metadata-eval63.9%
Applied egg-rr63.9%
Taylor expanded in x around 0 46.9%
distribute-rgt-in46.9%
*-lft-identity46.9%
pow-plus47.1%
metadata-eval47.1%
Simplified47.1%
Taylor expanded in x around inf 7.3%
Final simplification7.3%
(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}
Initial program 64.0%
add-cube-cbrt48.3%
associate-*l*48.3%
inv-pow48.3%
add-cube-cbrt47.7%
unpow-prod-down49.0%
prod-diff48.6%
Applied egg-rr47.9%
+-commutative47.9%
fma-udef46.9%
Simplified46.9%
Taylor expanded in x around 0 2.0%
Final simplification2.0%
(FPCore (x) :precision binary64 (/ 1.0 (+ (* (+ x 1.0) (sqrt x)) (* x (sqrt (+ x 1.0))))))
double code(double x) {
return 1.0 / (((x + 1.0) * sqrt(x)) + (x * sqrt((x + 1.0))));
}
real(8) function code(x)
real(8), intent (in) :: x
code = 1.0d0 / (((x + 1.0d0) * sqrt(x)) + (x * sqrt((x + 1.0d0))))
end function
public static double code(double x) {
return 1.0 / (((x + 1.0) * Math.sqrt(x)) + (x * Math.sqrt((x + 1.0))));
}
def code(x): return 1.0 / (((x + 1.0) * math.sqrt(x)) + (x * math.sqrt((x + 1.0))))
function code(x) return Float64(1.0 / Float64(Float64(Float64(x + 1.0) * sqrt(x)) + Float64(x * sqrt(Float64(x + 1.0))))) end
function tmp = code(x) tmp = 1.0 / (((x + 1.0) * sqrt(x)) + (x * sqrt((x + 1.0)))); end
code[x_] := N[(1.0 / N[(N[(N[(x + 1.0), $MachinePrecision] * N[Sqrt[x], $MachinePrecision]), $MachinePrecision] + N[(x * N[Sqrt[N[(x + 1.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\frac{1}{\left(x + 1\right) \cdot \sqrt{x} + x \cdot \sqrt{x + 1}}
\end{array}
herbie shell --seed 2024019
(FPCore (x)
:name "2isqrt (example 3.6)"
:precision binary64
:herbie-target
(/ 1.0 (+ (* (+ x 1.0) (sqrt x)) (* x (sqrt (+ x 1.0)))))
(- (/ 1.0 (sqrt x)) (/ 1.0 (sqrt (+ x 1.0)))))